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;
}
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);
}
}
Aggregations