Search in sources :

Example 11 with CertData

use of org.wso2.carbon.security.keystore.service.CertData in project carbon-identity-framework by wso2.

the class KeyStoreAdmin method fillCertData.

private CertData fillCertData(X509Certificate cert, String alise, Format formatter) throws CertificateEncodingException {
    CertData certData = null;
    if (includeCert) {
        certData = new CertDataDetail();
    } else {
        certData = new CertData();
    }
    certData.setAlias(alise);
    certData.setSubjectDN(cert.getSubjectDN().getName());
    certData.setIssuerDN(cert.getIssuerDN().getName());
    certData.setSerialNumber(cert.getSerialNumber());
    certData.setVersion(cert.getVersion());
    certData.setNotAfter(formatter.format(cert.getNotAfter()));
    certData.setNotBefore(formatter.format(cert.getNotBefore()));
    certData.setPublicKey(Base64.encode(cert.getPublicKey().getEncoded()));
    if (includeCert) {
        ((CertDataDetail) certData).setCertificate(cert);
    }
    return certData;
}
Also used : PaginatedCertData(org.wso2.carbon.security.keystore.service.PaginatedCertData) CertData(org.wso2.carbon.security.keystore.service.CertData) CertDataDetail(org.wso2.carbon.security.keystore.service.CertDataDetail)

Example 12 with CertData

use of org.wso2.carbon.security.keystore.service.CertData in project carbon-identity-framework by wso2.

the class KeyStoreAdmin method importCertToStore.

public String importCertToStore(String certData, String keyStoreName) throws SecurityConfigException {
    String alias = null;
    try {
        if (keyStoreName == null) {
            throw new SecurityConfigException("Key Store name can't be null");
        }
        KeyStore ks = getKeyStore(keyStoreName);
        X509Certificate cert = extractCertificate(certData);
        if (ks.getCertificateAlias(cert) != null) {
            // adding it twice
            return null;
        }
        alias = cert.getSubjectDN().getName();
        ks.setCertificateEntry(alias, cert);
        updateKeyStore(keyStoreName, ks);
        if (isTrustStore(keyStoreName)) {
            System.setProperty(IdentityUtil.PROP_TRUST_STORE_UPDATE_REQUIRED, "true");
        }
        return alias;
    } catch (SecurityConfigException e) {
        throw e;
    } catch (Exception e) {
        String msg = "Error when importing cert to keyStore";
        log.error(msg, e);
        throw new SecurityConfigException(msg);
    }
}
Also used : SecurityConfigException(org.wso2.carbon.security.SecurityConfigException) KeyStore(java.security.KeyStore) X509Certificate(java.security.cert.X509Certificate) KeyStoreException(java.security.KeyStoreException) SecurityConfigException(org.wso2.carbon.security.SecurityConfigException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Aggregations

CertData (org.wso2.carbon.security.keystore.service.CertData)7 X509Certificate (java.security.cert.X509Certificate)5 ArrayList (java.util.ArrayList)5 CertificateException (java.security.cert.CertificateException)4 SecurityConfigException (org.wso2.carbon.security.SecurityConfigException)4 PaginatedCertData (org.wso2.carbon.security.keystore.service.PaginatedCertData)4 IOException (java.io.IOException)3 KeyStore (java.security.KeyStore)3 KeyStoreException (java.security.KeyStoreException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)3 KeyStoreData (org.wso2.carbon.security.keystore.service.KeyStoreData)3 Format (java.text.Format)2 SimpleDateFormat (java.text.SimpleDateFormat)2 HashMap (java.util.HashMap)2 ServerConfiguration (org.wso2.carbon.base.ServerConfiguration)2 CryptoUtil (org.wso2.carbon.core.util.CryptoUtil)2 KeyStoreManager (org.wso2.carbon.core.util.KeyStoreManager)2 CertData (org.wso2.carbon.identity.application.common.model.CertData)2