if (identifer == null) {
if (LOG.isDebugEnabled()) {
LOG.debug("No SubjectDN is specified");
}
throw new XKMSException(XKMSException.FAILURE, "NoSubjectDN");
}
PublicKey public1 = pkb.getKeyValue();
PrivateKey private1 = null;
// if a public key is not provided we need to generate both the
// public key and private key
if (public1 == null) {
KeyPair keypair = XKMSKeyUtil.generateRSAKeyPair();
public1 = keypair.getPublic();
private1 = keypair.getPrivate();
}
// calculating the start and expiery dates.
ValidityInterval validityInterval = pkb.getValidityInterval();
Date[] adjustedInterval;
if (validityInterval != null) {
adjustedInterval = getAdjustedValidityInterval(validityInterval
.getNotBefore(), validityInterval.getOnOrAfter());
} else {
adjustedInterval = getAdjustedValidityInterval((Date) null,
(Date) null);
}
long serialNum = nextSerialNumber();
String aliase = createAlias(serialNum);
BigInteger serialNumber = BigInteger.valueOf(serialNum);
X509Certificate cert;
List keyUsage = pkb.getKeyUsage();
if (keyUsage == null
|| keyUsage.isEmpty()
|| (keyUsage.size() == 1 && keyUsage
.contains(KeyUsage.EXCHANGE))) {
cert = XKMSKeyUtil.getX509Certificate(identifer, serialNumber,
adjustedInterval[0], adjustedInterval[1], public1,
cacert, cakey);
} else {
cert = XKMSKeyUtil.getX509Certificate(identifer, serialNumber,
adjustedInterval[0], adjustedInterval[1], keyUsage
.contains(KeyUsage.SIGNATURE), keyUsage
.contains(KeyUsage.ENCRYPTION), public1,
cacert, cakey);
}
try {
keystore.setCertificateEntry(aliase, cert);
if (LOG.isDebugEnabled()) {
LOG
.debug("Adding the newly constructed X509Certificate to the keystore - \n "
+ cert);
}
if (private1 != null) {
Certificate[] chain = new Certificate[] { cert };
keystore.setKeyEntry(aliase, private1,
getPrivateKeyPassword(), chain);
if (LOG.isDebugEnabled()) {
LOG
.debug("Added the newly construct Private Key to the keystore - \n"
+ private1);
}
}
if (saveKeystore) {
saveKeystore();
}
} catch (KeyStoreException e) {
LOG.error("Adding the certificate to keystore failed", e);
throw new XKMSException(e);
}
RegisterResult result = XKMSUtil.createRegisterResult();
buildResultType(request, result, aliase, keystore);
return result;