Search in sources :

Example 6 with CertData

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

the class KeyStoreManagementServiceImpl method getAliasList.

private List<String> getAliasList(KeyStoreData keyStoreData) {
    List<String> aliasList = new ArrayList<>();
    CertData key = keyStoreData.getKey();
    if (key != null && key.getAlias() != null) {
        aliasList.add(key.getAlias());
    }
    CertData[] certDataArray = keyStoreData.getCerts();
    for (CertData certData : certDataArray) {
        String alias = certData.getAlias();
        if (alias != null) {
            aliasList.add(alias);
        }
    }
    return aliasList;
}
Also used : CertData(org.wso2.carbon.security.keystore.service.CertData) ArrayList(java.util.ArrayList)

Example 7 with CertData

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

the class IdentityApplicationManagementUtil method fillCertData.

/**
 * @param cert
 * @param formatter
 * @return
 * @throws CertificateEncodingException
 */
private static CertData fillCertData(X509Certificate cert, Format formatter) throws CertificateEncodingException {
    CertData certData = new CertData();
    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()));
    return certData;
}
Also used : CertData(org.wso2.carbon.identity.application.common.model.CertData)

Example 8 with CertData

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

the class IdentityApplicationManagementUtil method getCertDataArray.

/**
 * Generate CertData array
 *
 * @param certificateInfo array of certificate info
 * @return CertData array
 * @throws CertificateException
 */
public static List<CertData> getCertDataArray(CertificateInfo[] certificateInfo) throws CertificateException {
    if (ArrayUtils.isNotEmpty(certificateInfo)) {
        List<CertData> certDataList = new ArrayList<>();
        HashMap<CertData, String> certDataMap = new HashMap<>();
        int i = 0;
        for (CertificateInfo certificateInfoVal : certificateInfo) {
            String certVal = certificateInfoVal.getCertValue();
            CertData certData = createCertData(certVal);
            certDataList.add(certData);
            certDataMap.put(certData, certVal);
            i++;
        }
        setCertDataMap(certDataMap);
        return certDataList;
    } else {
        String errorMsg = "Certificate info array is empty";
        if (log.isDebugEnabled()) {
            log.debug(errorMsg);
        }
        throw new IllegalArgumentException(errorMsg);
    }
}
Also used : CertData(org.wso2.carbon.identity.application.common.model.CertData) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) CertificateInfo(org.wso2.carbon.identity.application.common.model.CertificateInfo)

Example 9 with CertData

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

the class Util method doFilter.

public static CertData[] doFilter(String filter, CertData[] certDataSet) {
    if (certDataSet == null || certDataSet.length == 0) {
        return new CertData[0];
    }
    String regPattern = filter.replace("*", ".*");
    List<CertData> list = new ArrayList<>();
    for (CertData cert : certDataSet) {
        if (cert != null && cert.getAlias().toLowerCase().matches(regPattern.toLowerCase())) {
            list.add(cert);
        }
    }
    return list.toArray(new CertData[list.size()]);
}
Also used : CertData(org.wso2.carbon.security.mgt.stub.keystore.xsd.CertData) ArrayList(java.util.ArrayList)

Example 10 with CertData

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

the class KeyStoreAdmin method doPaging.

/**
 * This method is used internally to do the pagination purposes.
 *
 * @param pageNumber  page Number
 * @param certDataSet set of keyStoreData
 * @return PaginatedPolicySetDTO object containing the number of pages and the set of policies
 * that reside in the given page.
 */
private PaginatedCertData doPaging(int pageNumber, CertData[] certDataSet) {
    PaginatedCertData paginatedCertData = new PaginatedCertData();
    if (certDataSet.length == 0) {
        paginatedCertData.setCertDataSet(new CertData[0]);
        return paginatedCertData;
    }
    int itemsPerPageInt = SecurityConstants.ITEMS_PER_PAGE;
    int numberOfPages = (int) Math.ceil((double) certDataSet.length / itemsPerPageInt);
    if (pageNumber > numberOfPages - 1) {
        pageNumber = numberOfPages - 1;
    }
    int startIndex = pageNumber * itemsPerPageInt;
    int endIndex = (pageNumber + SecurityConstants.CACHING_PAGE_SIZE) * itemsPerPageInt;
    CertData[] returnedCertDataSet = new CertData[itemsPerPageInt * SecurityConstants.CACHING_PAGE_SIZE];
    for (int i = startIndex, j = 0; i < endIndex && i < certDataSet.length; i++, j++) {
        returnedCertDataSet[j] = certDataSet[i];
    }
    paginatedCertData.setCertDataSet(returnedCertDataSet);
    paginatedCertData.setNumberOfPages(numberOfPages);
    return paginatedCertData;
}
Also used : PaginatedCertData(org.wso2.carbon.security.keystore.service.PaginatedCertData) PaginatedCertData(org.wso2.carbon.security.keystore.service.PaginatedCertData) CertData(org.wso2.carbon.security.keystore.service.CertData)

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