summaryrefslogtreecommitdiffstats
path: root/base/server/cms
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2016-02-19 08:42:30 +0100
committerEndi S. Dewata <edewata@redhat.com>2016-04-02 06:22:41 +0200
commit58406095925cd3d26ab8eab0c7c7e99cdddf21ea (patch)
tree2b07bdc6952c06b86b257cbb99b3f361172f5245 /base/server/cms
parent9667921a5a2489a3fccc6f4f7f7af88f60eadbd2 (diff)
downloadpki-58406095925cd3d26ab8eab0c7c7e99cdddf21ea.tar.gz
pki-58406095925cd3d26ab8eab0c7c7e99cdddf21ea.tar.xz
pki-58406095925cd3d26ab8eab0c7c7e99cdddf21ea.zip
Added mechanism to import system certs via PKCS #12 file.
The installation tool has been modified to provide an optional pki_server_pkcs12_path property to specify a PKCS #12 file containing certificate chain, system certificates, and third-party certificates needed by the subsystem being installed. If the pki_server_pkcs12_path is specified the installation tool will no longer download the certificate chain from the security domain directly, and it will no longer import the PKCS #12 containing the entire master NSS database specified in pki_clone_pkcs12_path. For backward compatibility, if the pki_server_pkcs12_path is not specified the installation tool will use the old mechanism to import the system certificates. The ConfigurationUtils.verifySystemCertificates() has been modified not to catch the exception to help troubleshooting. https://fedorahosted.org/pki/ticket/1742
Diffstat (limited to 'base/server/cms')
-rw-r--r--base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java76
-rw-r--r--base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java55
2 files changed, 63 insertions, 68 deletions
diff --git a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
index 32e10275f..ad2853d14 100644
--- a/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
+++ b/base/server/cms/src/com/netscape/cms/servlet/csadmin/ConfigurationUtils.java
@@ -252,6 +252,8 @@ public class ConfigurationUtils {
public static void importCertChain(String host, int port, String serverPath, String tag)
throws Exception {
+ CMS.debug("ConfigurationUtils.importCertChain()");
+
IConfigStore cs = CMS.getConfigStore();
ConfigCertApprovalCallback certApprovalCallback = new ConfigCertApprovalCallback();
String c = get(host, port, true, serverPath, null, certApprovalCallback);
@@ -950,44 +952,42 @@ public class ConfigurationUtils {
importKeyCert(pkeyinfo_collection, cert_collection);
}
- public static boolean isCertdbCloned() {
+ public static void verifySystemCertificates() throws Exception {
+
IConfigStore cs = CMS.getConfigStore();
- try {
- CryptoManager cm = CryptoManager.getInstance();
- String certList = cs.getString("preop.cert.list");
- String cstype = cs.getString("cs.type").toLowerCase();
- StringTokenizer st = new StringTokenizer(certList, ",");
- while (st.hasMoreTokens()) {
- String tag = st.nextToken();
- if (tag.equals("sslserver"))
- continue;
- String tokenname = cs.getString("preop.module.token", "");
- cm.getTokenByName(tokenname); // throw exception if token doesn't exist
- String name1 = "preop.master." + tag + ".nickname";
- String nickname = cs.getString(name1, "");
- if (!tokenname.equals("Internal Key Storage Token") &&
- !tokenname.equals("internal"))
- nickname = tokenname + ":" + nickname;
-
- CMS.debug("ConfigurationUtils.isCertdbCloned(): checking system certificate " + nickname);
-
- // TODO : remove this when we eliminate the extraneous nicknames
- // needed for self tests
- cs.putString(cstype + ".cert." + tag + ".nickname", nickname);
-
- X509Certificate cert = cm.findCertByNickname(nickname);
- if (cert == null) {
- CMS.debug("Missing system certificate: " + nickname);
- return false;
- }
- }
- } catch (Exception e) {
- CMS.debug(e);
- return false;
- }
+ CryptoManager cm = CryptoManager.getInstance();
+ String certList = cs.getString("preop.cert.list");
+ String cstype = cs.getString("cs.type").toLowerCase();
+ StringTokenizer st = new StringTokenizer(certList, ",");
- return true;
+ while (st.hasMoreTokens()) {
+ String tag = st.nextToken();
+ if (tag.equals("sslserver"))
+ continue;
+
+ String tokenname = cs.getString("preop.module.token", "");
+ cm.getTokenByName(tokenname); // throw exception if token doesn't exist
+
+ String name1 = "preop.master." + tag + ".nickname";
+ String nickname = cs.getString(name1, "");
+ if (!tokenname.equals("Internal Key Storage Token") &&
+ !tokenname.equals("internal"))
+ nickname = tokenname + ":" + nickname;
+
+ CMS.debug("ConfigurationUtils.verifySystemCertificates(): checking certificate " + nickname);
+
+ // TODO : remove this when we eliminate the extraneous nicknames
+ // needed for self tests
+ cs.putString(cstype + ".cert." + tag + ".nickname", nickname);
+
+ try {
+ cm.findCertByNickname(nickname);
+
+ } catch (ObjectNotFoundException e) {
+ throw new Exception("Missing system certificate: " + nickname);
+ }
+ }
}
public static void importKeyCert(
@@ -3684,10 +3684,12 @@ public class ConfigurationUtils {
String status = parser.getValue("Status");
CMS.debug("submitAdminXertRequest: status=" + status);
if (status.equals(AUTH_FAILURE)) {
- throw new EAuthException(AUTH_FAILURE);
+ throw new EAuthException("Unable to generate admin certificate: authentication failure");
+
} else if (!status.equals(SUCCESS)) {
String error = parser.getValue("Error");
- throw new IOException(error);
+ CMS.debug("Error: " + error);
+ throw new IOException("Unable to generate admin certificate: " + error);
}
IConfigStore cs = CMS.getConfigStore();
diff --git a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
index 697196a6e..f7e5a6b05 100644
--- a/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
+++ b/base/server/cms/src/org/dogtagpki/server/rest/SystemConfigService.java
@@ -662,7 +662,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
response.setAdminCert(admincerts[0]);
} catch (Exception e) {
- e.printStackTrace();
+ CMS.debug(e);
throw new PKIException("Error in creating admin user: " + e);
}
}
@@ -818,7 +818,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
cs.putInteger("preop.ca.httpsport", port);
cs.putInteger("preop.ca.httpsadminport", admin_port);
- if (!data.isClone()) {
+ if (!data.isClone() && !data.getSystemCertsImported()) {
ConfigurationUtils.importCertChain(host, admin_port, "/ca/admin/ca/getCertChain", "ca");
}
@@ -855,7 +855,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
"Clone URI does not match available subsystems: " + url);
}
- if (csType.equals("CA")) {
+ if (csType.equals("CA") && !data.getSystemCertsImported()) {
CMS.debug("SystemConfigService: import certificate chain from master");
int masterAdminPort = ConfigurationUtils.getPortFromSecurityDomain(domainXML,
masterHost, masterPort, "CA", "SecurePort", "SecureAdminPort");
@@ -867,10 +867,12 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
ConfigurationUtils.getConfigEntriesFromMaster();
if (token.equals(ConfigurationRequest.TOKEN_DEFAULT)) {
- CMS.debug("SystemConfigService: restore certificates from P12 file");
- String p12File = data.getP12File();
- String p12Pass = data.getP12Password();
- ConfigurationUtils.restoreCertsFromP12(p12File, p12Pass);
+ if (!data.getSystemCertsImported()) {
+ CMS.debug("SystemConfigService: restore certificates from P12 file");
+ String p12File = data.getP12File();
+ String p12Pass = data.getP12Password();
+ ConfigurationUtils.restoreCertsFromP12(p12File, p12Pass);
+ }
} else {
CMS.debug("SystemConfigService: import certificates from HSM and set permission");
@@ -878,15 +880,10 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
}
CMS.debug("SystemConfigService: verify certificates");
- boolean cloneReady = ConfigurationUtils.isCertdbCloned();
-
- if (!cloneReady) {
- CMS.debug("SystemConfigService: clone does not have all the certificates.");
- throw new PKIException("Clone does not have all the required certificates");
- }
+ ConfigurationUtils.verifySystemCertificates();
}
- public String configureSecurityDomain(ConfigurationRequest data) {
+ public String configureSecurityDomain(ConfigurationRequest data) throws Exception {
String domainXML = null;
@@ -932,7 +929,7 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
cs.putString("preop.cert.subsystem.profile", "subsystemCert.profile");
}
- private String logIntoSecurityDomain(ConfigurationRequest data, String securityDomainURL) {
+ private String logIntoSecurityDomain(ConfigurationRequest data, String securityDomainURL) throws Exception {
URL secdomainURL;
String host;
int port;
@@ -948,7 +945,11 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
throw new PKIException("Failed to resolve security domain URL", e);
}
- getCertChainFromSecurityDomain(host, port);
+ if (!data.getSystemCertsImported()) {
+ CMS.debug("Getting security domain cert chain");
+ ConfigurationUtils.importCertChain(host, port, "/ca/admin/ca/getCertChain", "securitydomain");
+ }
+
getInstallToken(data, host, port);
return getDomainXML(host, port);
@@ -967,16 +968,6 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
return domainXML;
}
- private void getCertChainFromSecurityDomain(String host, int port) {
- CMS.debug("Getting security domain cert chain");
- try {
- ConfigurationUtils.importCertChain(host, port, "/ca/admin/ca/getCertChain", "securitydomain");
- } catch (Exception e) {
- CMS.debug(e);
- throw new PKIException("Failed to import certificate chain from security domain master: " + e, e);
- }
- }
-
private void getInstallToken(ConfigurationRequest data, String host, int port) {
CMS.debug("Getting install token");
// log onto security domain and get token
@@ -1129,12 +1120,14 @@ public class SystemConfigService extends PKIService implements SystemConfigResou
}
if (data.getToken().equals(ConfigurationRequest.TOKEN_DEFAULT)) {
- if (data.getP12File() == null) {
- throw new BadRequestException("P12 filename not provided");
- }
+ if (!data.getSystemCertsImported()) {
+ if (data.getP12File() == null) {
+ throw new BadRequestException("P12 filename not provided");
+ }
- if (data.getP12Password() == null) {
- throw new BadRequestException("P12 password not provided");
+ if (data.getP12Password() == null) {
+ throw new BadRequestException("P12 password not provided");
+ }
}
} else {
if (data.getP12File() != null) {