Search in sources :

Example 1 with CertDataDetail

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

the class KeyStoreManagementServiceImpl method getPublicCertificate.

@Override
public Map<String, X509Certificate> getPublicCertificate(String tenantDomain) throws KeyStoreManagementException {
    Map<String, X509Certificate> certData = new HashMap<>();
    KeyStoreData keyStoreInfo = getKeystoreData(tenantDomain, getKeyStoreName(tenantDomain));
    CertData key = keyStoreInfo.getKey();
    certData.put(key.getAlias(), ((CertDataDetail) key).getCertificate());
    return certData;
}
Also used : CertData(org.wso2.carbon.security.keystore.service.CertData) HashMap(java.util.HashMap) KeyStoreData(org.wso2.carbon.security.keystore.service.KeyStoreData) X509Certificate(java.security.cert.X509Certificate)

Example 2 with CertDataDetail

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

the class KeyStoreManagementServiceImpl method getKeyStoreCertificate.

@Override
public X509Certificate getKeyStoreCertificate(String tenantDomain, String alias) throws KeyStoreManagementException {
    if (StringUtils.isEmpty(alias)) {
        throw handleClientException(ERROR_CODE_EMPTY_ALIAS, null);
    }
    KeyStoreData keyStoreInfo = getKeystoreData(tenantDomain, getKeyStoreName(tenantDomain));
    CertData key = keyStoreInfo.getKey();
    if (key != null && StringUtils.equals(key.getAlias(), alias)) {
        return ((CertDataDetail) key).getCertificate();
    }
    CertData[] certDataArray = keyStoreInfo.getCerts();
    for (CertData certData : certDataArray) {
        String aliasFromKeyStore = certData.getAlias();
        if (StringUtils.equals(aliasFromKeyStore, alias)) {
            return ((CertDataDetail) certData).getCertificate();
        }
    }
    return null;
}
Also used : CertData(org.wso2.carbon.security.keystore.service.CertData) CertDataDetail(org.wso2.carbon.security.keystore.service.CertDataDetail) KeyStoreData(org.wso2.carbon.security.keystore.service.KeyStoreData)

Example 3 with CertDataDetail

use of org.wso2.carbon.security.keystore.service.CertDataDetail 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)

Aggregations

CertData (org.wso2.carbon.security.keystore.service.CertData)3 CertDataDetail (org.wso2.carbon.security.keystore.service.CertDataDetail)2 KeyStoreData (org.wso2.carbon.security.keystore.service.KeyStoreData)2 X509Certificate (java.security.cert.X509Certificate)1 HashMap (java.util.HashMap)1 PaginatedCertData (org.wso2.carbon.security.keystore.service.PaginatedCertData)1