revert-70aa11f8
geethkokila 9 years ago
commit f4b2a9ca3a

@ -52,9 +52,9 @@ import org.jscep.transaction.Nonce;
import org.jscep.transaction.TransactionId; import org.jscep.transaction.TransactionId;
import org.wso2.carbon.certificate.mgt.core.dto.CAStatus; import org.wso2.carbon.certificate.mgt.core.dto.CAStatus;
import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse;
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import org.wso2.carbon.certificate.mgt.core.util.CommonUtil; import org.wso2.carbon.certificate.mgt.core.util.CommonUtil;
import org.wso2.carbon.certificate.mgt.core.util.ConfigurationUtil;
import javax.security.auth.x500.X500Principal; import javax.security.auth.x500.X500Principal;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -292,9 +292,21 @@ public class CertificateGenerator {
Date validityBeginDate = commonUtil.getValidityStartDate(); Date validityBeginDate = commonUtil.getValidityStartDate();
Date validityEndDate = commonUtil.getValidityEndDate(); Date validityEndDate = commonUtil.getValidityEndDate();
X500Name certSubject = request.getSubject();
if (certSubject == null) {
certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
} else {
org.bouncycastle.asn1.x500.RDN[] rdn = certSubject.getRDNs();
if (rdn == null || rdn.length == 0) {
certSubject = new X500Name(ConfigurationUtil.DEFAULT_PRINCIPAL);
}
}
X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder( X509v3CertificateBuilder certificateBuilder = new X509v3CertificateBuilder(
new X500Name(issueSubject), BigInteger.valueOf(System.currentTimeMillis()), new X500Name(issueSubject), BigInteger.valueOf(System.currentTimeMillis()),
validityBeginDate, validityEndDate, request.getSubject(), request.getSubjectPublicKeyInfo()); validityBeginDate, validityEndDate, certSubject, request.getSubjectPublicKeyInfo());
ContentSigner sigGen; ContentSigner sigGen;
X509Certificate issuedCert; X509Certificate issuedCert;
@ -461,6 +473,8 @@ public class CertificateGenerator {
KeyStoreReader keyStoreReader = new KeyStoreReader(); KeyStoreReader keyStoreReader = new KeyStoreReader();
KeyStore keyStore = keyStoreReader.loadCertificateKeyStore(); KeyStore keyStore = keyStoreReader.loadCertificateKeyStore();
keyStore.setCertificateEntry(certificate.getSerialNumber().toString(), certificate); keyStore.setCertificateEntry(certificate.getSerialNumber().toString(), certificate);
keyStoreReader.saveCertificateKeyStore(keyStore);
} catch (KeyStoreException e) { } catch (KeyStoreException e) {
String errorMsg = "KeySKeyStoreException occurred when saving the generated certificate"; String errorMsg = "KeySKeyStoreException occurred when saving the generated certificate";
log.error(errorMsg, e); log.error(errorMsg, e);

@ -24,6 +24,7 @@ import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.security.KeyStore; import java.security.KeyStore;
@ -62,7 +63,7 @@ public class KeyStoreReader {
log.error(errorMsg, e); log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) { } catch (CertificateException e) {
String errorMsg = "Certificate expired when loading KeyStore"; String errorMsg = "CertificateException when loading KeyStore";
log.error(errorMsg, e); log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e); throw new KeystoreException(errorMsg, e);
} catch (IOException e) { } catch (IOException e) {
@ -82,11 +83,59 @@ public class KeyStoreReader {
return keystore; return keystore;
} }
private synchronized void saveKeyStore(KeyStore keyStore, String configEntryKeyStorePath,
String configEntryKeyStorePassword) throws KeystoreException {
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(
ConfigurationUtil.getConfigEntry(configEntryKeyStorePath));
keyStore.store(outputStream, ConfigurationUtil.getConfigEntry(configEntryKeyStorePassword).toCharArray());
outputStream.close();
} catch (KeyStoreException e) {
String errorMsg = "KeyStore issue occurred when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (FileNotFoundException e) {
String errorMsg = "KeyStore file not found when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (NoSuchAlgorithmException e) {
String errorMsg = "Algorithm not found when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (CertificateException e) {
String errorMsg = "CertificateException when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} catch (IOException e) {
String errorMsg = "Input output issue occurred when loading KeyStore";
log.error(errorMsg, e);
throw new KeystoreException(errorMsg, e);
} finally {
try {
if (outputStream != null) {
outputStream.close();
}
} catch (IOException e) {
log.error("Error closing KeyStore output stream", e);
}
}
}
KeyStore loadCertificateKeyStore() throws KeystoreException { KeyStore loadCertificateKeyStore() throws KeystoreException {
return loadKeyStore(ConfigurationUtil.CERTIFICATE_KEYSTORE, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE, return loadKeyStore(ConfigurationUtil.CERTIFICATE_KEYSTORE, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE,
ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD); ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD);
} }
void saveCertificateKeyStore(KeyStore keyStore) throws KeystoreException {
saveKeyStore(keyStore, ConfigurationUtil.PATH_CERTIFICATE_KEYSTORE,
ConfigurationUtil.CERTIFICATE_KEYSTORE_PASSWORD);
}
public Certificate getCACertificate() throws KeystoreException { public Certificate getCACertificate() throws KeystoreException {
KeyStore keystore = loadCertificateKeyStore(); KeyStore keystore = loadCertificateKeyStore();

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext; import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementServiceImpl;
/** /**
@ -38,7 +39,7 @@ public class CertificateManagementServiceComponent {
} }
BundleContext bundleContext = componentContext.getBundleContext(); BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(CertificateManagementServiceImpl.class.getName(), bundleContext.registerService(CertificateManagementService.class.getName(),
CertificateManagementServiceImpl.getInstance(), null); CertificateManagementServiceImpl.getInstance(), null);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {

Loading…
Cancel
Save