Skip to content

Commit

Permalink
MOSIP-37581 : added caSignedCertTimeOfUpload, caSignedCertExpiryDateT…
Browse files Browse the repository at this point in the history
…ime fields (#1010)

* MOSIP-37581 : added caSignedCertTimeOfUpload, caSignedCertExpiryDateTime fields

Signed-off-by: sudeep <[email protected]>

* MOSIP-37581 : added caSignedCertTimeOfUpload, caSignedCertExpiryDateTime fields

Signed-off-by: sudeep <[email protected]>

* MOSIP-37581 : added caSignedCertTimeOfUpload, caSignedCertExpiryDateTime fields

Signed-off-by: sudeep <[email protected]>

---------

Signed-off-by: sudeep <[email protected]>
  • Loading branch information
Sudeep7353 authored Dec 2, 2024
1 parent 0d6fa2a commit e39e37e
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import io.mosip.pms.common.response.dto.ResponseWrapperV2;
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.JsonParseException;
Expand Down Expand Up @@ -88,7 +88,7 @@ public interface FtpChipDetailService {

public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId);

public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertificate(String ftmId);
public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getOriginalFtmCertificate(String ftmId);

public ResponseWrapperV2<PageResponseV2Dto<FtmDetailSummaryDto>> getPartnersFtmChipDetails(String sortFieldName, String sortType, int pageNo, int pageSize, FtmChipFilterDto filterDto);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
import io.mosip.pms.device.authdevice.repository.FtmDetailsSummaryRepository;
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.constant.PartnerConstants;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto;
import io.mosip.pms.partner.util.MultiPartnerUtil;
import io.mosip.pms.partner.util.PartnerHelper;
import io.mosip.pms.partner.util.PartnerUtil;
Expand Down Expand Up @@ -600,8 +599,8 @@ public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(String ftmId) {
}

@Override
public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertificate(String ftmId) {
ResponseWrapperV2<OriginalCertDownloadResponseDto> responseWrapper = new ResponseWrapperV2<>();
public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getOriginalFtmCertificate(String ftmId) {
ResponseWrapperV2<FtmCertificateDownloadResponseDto> responseWrapper = new ResponseWrapperV2<>();
try {
String userId = getUserId();
List<Partner> partnerList = partnerRepository.findByUserId(userId);
Expand Down Expand Up @@ -634,9 +633,9 @@ public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertific
}

// Download only if the FTM is approved or pending_approval status.
OriginalCertDownloadResponseDto responseObject = null;
responseObject = partnerHelper.getCertificate(ftm.getCertificateAlias(), "pmp.partner.original.certificate.get.rest.uri", OriginalCertDownloadResponseDto.class);
partnerHelper.populateCertificateExpiryState(responseObject);
FtmCertificateDownloadResponseDto responseObject = null;
responseObject = partnerHelper.getCertificate(ftm.getCertificateAlias(), "pmp.partner.original.certificate.get.rest.uri", FtmCertificateDownloadResponseDto.class);
partnerHelper.populateFtmCertificateExpiryState(responseObject);
responseWrapper.setResponse(responseObject);
} catch (PartnerServiceException ex) {
LOGGER.info("sessionId", "idType", "id", "In getOriginalFtmCertificate method of FTPChipDetailServiceImpl - " + ex.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.request.dto.*;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto;
import io.mosip.pms.partner.util.PartnerHelper;
import io.mosip.pms.partner.util.RequestValidator;
import io.swagger.v3.oas.annotations.Parameter;
Expand Down Expand Up @@ -270,7 +270,7 @@ public ResponseWrapperV2<FtmDetailResponseDto> deactivateFtm(@RequestBody @Valid
@io.swagger.v3.oas.annotations.responses.ApiResponses(value = {@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "200", description = "OK"),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "401", description = "Unauthorized", content = @Content(schema = @Schema(hidden = true))),
@io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "403", description = "Forbidden", content = @Content(schema = @Schema(hidden = true)))})
public ResponseWrapperV2<OriginalCertDownloadResponseDto> getOriginalFtmCertificate(
public ResponseWrapperV2<FtmCertificateDownloadResponseDto> getOriginalFtmCertificate(
@ApiParam("To download original FTM certificate.") @PathVariable("ftmId") @NotNull String ftmId) throws JsonParseException, JsonMappingException, JsonProcessingException, IOException, CertificateException {
return ftpChipDetaillService.getOriginalFtmCertificate(ftmId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.mosip.pms.partner.response.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.time.LocalDateTime;

@Data
public class FtmCertificateDownloadResponseDto {
/**
* CA Signed Partner Certificate Data.
*/
@Schema(description = "Data for the CA (Certificate Authority) signed partner certificate", example = "MIICIjANBgkqhkiG9w0BAQEFA...") // Example value should be a realistic but truncated certificate string
private String caSignedCertificateData;

@Schema(description = "DateTime when the CA certificate was uploaded", example = "2024-07-15T10:00:00Z")
private LocalDateTime caSignedCertTimeOfUpload;

@Schema(description = "DateTime when the CA certificate will get expired", example = "2024-07-15T10:00:00Z")
private LocalDateTime caSignedCertExpiryDateTime;

@Schema(description = "Indicates whether the CA signed certificate is expired (true if expired, false otherwise)", example = "false")
private Boolean isCaSignedCertificateExpired;

/**
* MOSIP Signed Partner Certificate Data.
*/
@Schema(description = "Data for the MOSIP signed partner certificate", example = "MIICIjANBgkqhkiG9w0BAQEFA...") // Example value should be a realistic but truncated certificate string
private String mosipSignedCertificateData;

@Schema(description = "DateTime when the mosip certificate was uploaded", example = "2024-07-15T10:00:00Z")
private LocalDateTime mosipSignedCertTimeOfUpload;

@Schema(description = "DateTime when the mosip certificate will get expired", example = "2024-07-15T10:00:00Z")
private LocalDateTime mosipSignedCertExpiryDateTime;

@Schema(description = "Indicates whether the MOSIP signed certificate is expired (true if expired, false otherwise)", example = "true")
private Boolean isMosipSignedCertificateExpired;
/**
* Response timestamp.
*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.mosip.pms.partner.constant.ErrorCode;
import io.mosip.pms.partner.constant.PartnerConstants;
import io.mosip.pms.partner.exception.PartnerServiceException;
import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
Expand Down Expand Up @@ -201,6 +202,29 @@ public void populateCertificateExpiryState(OriginalCertDownloadResponseDto origi
}
}

public void populateFtmCertificateExpiryState(FtmCertificateDownloadResponseDto ftmCertificateDownloadResponseDto) {
ftmCertificateDownloadResponseDto.setIsMosipSignedCertificateExpired(false);
ftmCertificateDownloadResponseDto.setIsCaSignedCertificateExpired(false);

X509Certificate decodedMosipSignedCert = MultiPartnerUtil.decodeCertificateData(ftmCertificateDownloadResponseDto.getMosipSignedCertificateData());
ftmCertificateDownloadResponseDto.setMosipSignedCertExpiryDateTime(decodedMosipSignedCert.getNotAfter().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime());
ftmCertificateDownloadResponseDto.setMosipSignedCertTimeOfUpload(decodedMosipSignedCert.getNotBefore().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime());
// Check mosip signed certificate expiry date
if (isCertificateExpired(decodedMosipSignedCert)) {
ftmCertificateDownloadResponseDto.setMosipSignedCertificateData("");
ftmCertificateDownloadResponseDto.setIsMosipSignedCertificateExpired(true);
}

X509Certificate decodedCaSignedCert = MultiPartnerUtil.decodeCertificateData(ftmCertificateDownloadResponseDto.getCaSignedCertificateData());
ftmCertificateDownloadResponseDto.setCaSignedCertExpiryDateTime(decodedMosipSignedCert.getNotAfter().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime());
ftmCertificateDownloadResponseDto.setCaSignedCertTimeOfUpload(decodedMosipSignedCert.getNotBefore().toInstant().atZone(ZoneId.of("UTC")).toLocalDateTime());
// Check ca signed partner certificate expiry date
if (isCertificateExpired(decodedCaSignedCert)) {
ftmCertificateDownloadResponseDto.setCaSignedCertificateData("");
ftmCertificateDownloadResponseDto.setIsCaSignedCertificateExpired(true);
}
}

public boolean isCertificateExpired(X509Certificate cert) {
// Get the current date and time in UTC
LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("UTC"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import io.mosip.pms.device.dto.FtmChipFilterDto;
import io.mosip.pms.device.request.dto.*;
import io.mosip.pms.device.response.dto.*;
import io.mosip.pms.partner.response.dto.OriginalCertDownloadResponseDto;
import io.mosip.pms.partner.response.dto.FtmCertificateDownloadResponseDto;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -401,9 +401,9 @@ public void deactivateFtmTest() throws Exception {
@Test
@WithMockUser(roles = {"FTM_PROVIDER"})
public void getOriginalFtmCertificateTest() throws Exception {
ResponseWrapperV2<OriginalCertDownloadResponseDto> responseWrapper = new ResponseWrapperV2<>();
OriginalCertDownloadResponseDto originalCertDownloadResponseDto = new OriginalCertDownloadResponseDto();
responseWrapper.setResponse(originalCertDownloadResponseDto);
ResponseWrapperV2<FtmCertificateDownloadResponseDto> responseWrapper = new ResponseWrapperV2<>();
FtmCertificateDownloadResponseDto ftmCertificateDownloadResponseDto = new FtmCertificateDownloadResponseDto();
responseWrapper.setResponse(ftmCertificateDownloadResponseDto);
Mockito.when(ftpChipDetaillService.getOriginalFtmCertificate(Mockito.any())).thenReturn(responseWrapper);
mockMvc.perform(MockMvcRequestBuilders.get("/ftpchipdetail/1234/original-ftm-certificate")).andExpect(MockMvcResultMatchers.status().isOk());
}
Expand Down

0 comments on commit e39e37e

Please sign in to comment.