use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.
the class CertificateMappingUtil method fromCertificateInformationToDTO.
/**
* To convert Instance of {@link CertificateInformationDTO} to {@link CertificateInfoDTO};
*
* @param certificateInformationDTO Instance of {@link CertificateInformationDTO}
* @return converted instance of {@link CertificateInfoDTO}.
*/
public static CertificateInfoDTO fromCertificateInformationToDTO(CertificateInformationDTO certificateInformationDTO) {
CertificateValidityDTO certificateValidityDTO = new CertificateValidityDTO();
certificateValidityDTO.setFrom(certificateInformationDTO.getFrom());
certificateValidityDTO.setTo(certificateInformationDTO.getTo());
CertificateInfoDTO certificateInfoDTO = new CertificateInfoDTO();
certificateInfoDTO.setValidity(certificateValidityDTO);
certificateInfoDTO.setStatus(certificateInformationDTO.getStatus());
certificateInfoDTO.setSubject(certificateInformationDTO.getSubject());
certificateInfoDTO.setVersion(certificateInformationDTO.getVersion());
return certificateInfoDTO;
}
use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.
the class CertificateMgtUtils method getCertificateInformation.
/**
* Method to get the information of the certificate.
*
* @param alias : Alias of the certificate which information should be retrieved
* @return : The details of the certificate as a MAP.
*/
public synchronized CertificateInformationDTO getCertificateInformation(String alias) throws CertificateManagementException {
CertificateInformationDTO certificateInformation = new CertificateInformationDTO();
File trustStoreFile = new File(trustStoreLocation);
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream localTrustStoreStream = new FileInputStream(trustStoreFile)) {
trustStore.load(localTrustStoreStream, trustStorePassword);
}
if (trustStore.containsAlias(alias)) {
X509Certificate certificate = (X509Certificate) trustStore.getCertificate(alias);
certificateInformation = getCertificateMetaData(certificate);
}
} catch (IOException e) {
throw new CertificateManagementException("Error wile loading the keystore.", e);
} catch (CertificateException e) {
throw new CertificateManagementException("Error loading the keystore from the stream.", e);
} catch (NoSuchAlgorithmException e) {
throw new CertificateManagementException("Could not find the algorithm to load the certificate.", e);
} catch (KeyStoreException e) {
throw new CertificateManagementException("Error reading certificate contents.", e);
}
return certificateInformation;
}
use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.
the class CertificateMgtUtils method getCertificateInfo.
/**
* To get the certificate information from base64 encoded certificate.
*
* @param base64EncodedCertificate Base 64 encoded certificate.
* @return Certificate information.
*/
public CertificateInformationDTO getCertificateInfo(String base64EncodedCertificate) {
CertificateInformationDTO certificateInformationDTO = null;
try {
byte[] cert = (Base64.decodeBase64(base64EncodedCertificate.getBytes(StandardCharsets.UTF_8)));
InputStream serverCert = new ByteArrayInputStream(cert);
if (serverCert.available() == 0) {
log.error("Provided certificate is empty for getting certificate information. Hence please provide a " + "non-empty certificate to overcome this issue.");
}
CertificateFactory cf = CertificateFactory.getInstance(certificateType);
while (serverCert.available() > 0) {
Certificate certificate = cf.generateCertificate(serverCert);
certificateInformationDTO = getCertificateMetaData((X509Certificate) certificate);
}
} catch (IOException | CertificateException e) {
log.error("Error while getting the certificate information from the certificate", e);
}
return certificateInformationDTO;
}
use of org.wso2.carbon.apimgt.api.dto.CertificateInformationDTO in project carbon-apimgt by wso2.
the class CertificateMgtUtils method getCertificateMetaData.
/**
* To get the certificate meta data information such as version expiry data
*
* @param certificate Relevant certificate to get certificate meta data information.
* @return Certificate meta data information.
*/
private CertificateInformationDTO getCertificateMetaData(X509Certificate certificate) {
CertificateInformationDTO certificateInformation = new CertificateInformationDTO();
certificateInformation.setStatus(certificate.getNotAfter().getTime() > System.currentTimeMillis() ? "Active" : "Expired");
certificateInformation.setFrom(certificate.getNotBefore().toString());
certificateInformation.setTo(certificate.getNotAfter().toString());
certificateInformation.setSubject(certificate.getSubjectDN().toString());
certificateInformation.setVersion(String.valueOf(certificate.getVersion()));
return certificateInformation;
}
Aggregations