Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOSIP-35605] [MOSIP-32865] added new API to get the CA Signed Partner Certificate. #313

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,6 @@ private void purgeKeyAliasCache(String applicationId, String referenceId) {
LOGGER.info(KeymanagerConstant.SESSIONID, applicationId, referenceId,
"Purging from Cache because new key generated or new certificate uploaded." +
"AppId & RefId: " + appIdRefIdKey);
keyAliasCache.expireAt(appIdRefIdKey, Expiry.NOW);
keyAliasCache.expireAt(appIdRefIdKey, Expiry.NOW);
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ public class AuthorizedRolesDTO {

private List<String> postverifycertificatetrust;

private List<String> getgetpartnersignedcertificatepartnercertid;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.mosip.kernel.partnercertservice.dto;

import java.time.LocalDateTime;

import lombok.Data;

/**
* DTO class for download of partner CA Signed certificate & MOSIP Signed Certificate response.
*
* @author Mahammed Taheer
* @since 1.2.0x
*
*/
@Data
public class PartnerSignedCertDownloadResponseDto {

/**
* Partner Certificate Data.
*/
private String caSignedCertificateData;

/**
* Partner Certificate Data.
*/
private String mosipSignedCertificateData;

/**
* Response timestamp.
*/
private LocalDateTime timestamp;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import io.mosip.kernel.partnercertservice.dto.PartnerCertDownloadResponeDto;
import io.mosip.kernel.partnercertservice.dto.PartnerCertificateRequestDto;
import io.mosip.kernel.partnercertservice.dto.PartnerCertificateResponseDto;
import io.mosip.kernel.partnercertservice.dto.PartnerSignedCertDownloadResponseDto;
import io.mosip.kernel.partnercertservice.exception.PartnerCertManagerException;
import io.mosip.kernel.partnercertservice.helper.PartnerCertManagerDBHelper;
import io.mosip.kernel.partnercertservice.service.spi.PartnerCertificateManagerService;
Expand Down Expand Up @@ -552,23 +553,7 @@ public PartnerCertDownloadResponeDto getPartnerCertificate(PartnerCertDownloadRe
PartnerCertManagerConstants.EMPTY, "Get Partner Certificate Request.");

String partnetCertId = certDownloadRequestDto.getPartnerCertId();

if (!PartnerCertificateManagerUtil.isValidCertificateID(partnetCertId)) {
LOGGER.error(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.UPLOAD_PARTNER_CERT,
PartnerCertManagerConstants.EMPTY,
"Invalid Certificate ID provided to get the partner certificate.");
throw new PartnerCertManagerException(
PartnerCertManagerErrorConstants.INVALID_CERTIFICATE_ID.getErrorCode(),
PartnerCertManagerErrorConstants.INVALID_CERTIFICATE_ID.getErrorMessage());
}
PartnerCertificateStore partnerCertStore = certDBHelper.getPartnerCert(partnetCertId);
if (Objects.isNull(partnerCertStore)) {
LOGGER.error(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.UPLOAD_PARTNER_CERT,
PartnerCertManagerConstants.EMPTY, "Partner Certificate not found for the provided ID.");
throw new PartnerCertManagerException(
PartnerCertManagerErrorConstants.PARTNER_CERT_ID_NOT_FOUND.getErrorCode(),
PartnerCertManagerErrorConstants.PARTNER_CERT_ID_NOT_FOUND.getErrorMessage());
}
PartnerCertificateStore partnerCertStore = getPartnerCertificate(partnetCertId);

PartnerCertDownloadResponeDto responseDto = new PartnerCertDownloadResponeDto();
responseDto.setCertificateData(partnerCertStore.getSignedCertData());
Expand Down Expand Up @@ -613,4 +598,47 @@ private void purgeCache(String partnerDomain) {
caCertTrustStore.expireAt(partnerDomain, Expiry.NOW);
}
}

@Override
public PartnerSignedCertDownloadResponseDto getPartnerSignedCertificate(PartnerCertDownloadRequestDto certDownloadRequestDto) {

LOGGER.info(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.GET_PARTNER_CERT,
PartnerCertManagerConstants.EMPTY, "Get Partner CA Signed Certificate & " +
"Mosip Signed Certificate Request.");

String partnetCertId = certDownloadRequestDto.getPartnerCertId();
PartnerCertificateStore partnerCertStore = getPartnerCertificate(partnetCertId);

PartnerSignedCertDownloadResponseDto responseDto = new PartnerSignedCertDownloadResponseDto();
responseDto.setMosipSignedCertificateData(partnerCertStore.getSignedCertData());
responseDto.setCaSignedCertificateData(partnerCertStore.getCertData());
responseDto.setTimestamp(DateUtils.getUTCCurrentDateTime());
LOGGER.info(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.GET_PARTNER_CERT,
PartnerCertManagerConstants.EMPTY, "Get Partner CA Signed Certificate & " +
"Mosip Signed Certificate Request. - Completed");
return responseDto;
}

private PartnerCertificateStore getPartnerCertificate(String partnetCertId) {
LOGGER.info(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.GET_PARTNER_CERT, PartnerCertManagerConstants.EMPTY,
"Request to get Certificate for partnerId: " + partnetCertId);

if (!PartnerCertificateManagerUtil.isValidCertificateID(partnetCertId)) {
LOGGER.error(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.UPLOAD_PARTNER_CERT,
PartnerCertManagerConstants.EMPTY,
"Invalid Certificate ID provided to get the partner certificate.");
throw new PartnerCertManagerException(
PartnerCertManagerErrorConstants.INVALID_CERTIFICATE_ID.getErrorCode(),
PartnerCertManagerErrorConstants.INVALID_CERTIFICATE_ID.getErrorMessage());
}
PartnerCertificateStore partnerCertStore = certDBHelper.getPartnerCert(partnetCertId);
if (Objects.isNull(partnerCertStore)) {
LOGGER.error(PartnerCertManagerConstants.SESSIONID, PartnerCertManagerConstants.UPLOAD_PARTNER_CERT,
PartnerCertManagerConstants.EMPTY, "Partner Certificate not found for the provided ID.");
throw new PartnerCertManagerException(
PartnerCertManagerErrorConstants.PARTNER_CERT_ID_NOT_FOUND.getErrorCode(),
PartnerCertManagerErrorConstants.PARTNER_CERT_ID_NOT_FOUND.getErrorMessage());
}
return partnerCertStore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.mosip.kernel.partnercertservice.dto.PartnerCertDownloadResponeDto;
import io.mosip.kernel.partnercertservice.dto.PartnerCertificateRequestDto;
import io.mosip.kernel.partnercertservice.dto.PartnerCertificateResponseDto;
import io.mosip.kernel.partnercertservice.dto.PartnerSignedCertDownloadResponseDto;

/**
* This interface provides the methods for Partner Certificate Management Service.
Expand Down Expand Up @@ -59,4 +60,12 @@ public interface PartnerCertificateManagerService {
* @return void
*/
public void purgeTrustStoreCache(String partnerDomain);

/**
* Function to Download Partner CA Signed certificates & MOSIP CA Signed Certificate.
*
* @param PartnerCertDownloadRequestDto certDownloadRequestDto
* @return {@link PartnerCertDownloadResponeDto} instance
*/
public PartnerSignedCertDownloadResponseDto getPartnerSignedCertificate(PartnerCertDownloadRequestDto certDownloadRequestDto);
}
Loading