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 30687 on demand template extraction #1202

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 @@ -88,6 +88,7 @@ public class OTPManager {
/** The logger. */
private static Logger logger = IdaLogger.getLogger(OTPManager.class);


/**
* Generate OTP with information of {@link MediaType } and OTP generation
* time-out.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,12 +513,13 @@ public Tuple3<String, String, String> encryptData(byte[] data, String partnerCer
return Tuples.of(CryptoUtil.encodeBase64Url(encryptedData.getT1()), CryptoUtil.encodeBase64Url(encryptedData.getT2()), digestAsPlainText(certificateThumbprint));
}

public byte[] asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate)
public String asymmetricEncryption(byte[] dataToEncrypt, String partnerCertificate)
throws IdAuthenticationBusinessException {
X509Certificate x509Certificate = getX509Certificate(partnerCertificate);
PublicKey publicKey = x509Certificate.getPublicKey();
byte[] encryptedData = cryptoCore.asymmetricEncrypt(publicKey, dataToEncrypt);
return encryptedData;
mosipLogger.info("AssymetricEncrypted data -- Start" + encryptedData+ " End--AssymetricEncrypted data" );
return CryptoUtil.encodeBase64Url(encryptedData);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.mosip.authentication.common.service.transaction.manager.IdAuthSecurityManager;
import io.mosip.authentication.core.constant.IdAuthCommonConstants;
import io.mosip.authentication.core.exception.IdAuthenticationBusinessException;
import io.mosip.authentication.core.indauth.dto.BaseAuthResponseDTO;
import io.mosip.authentication.core.indauth.dto.BaseRequestDTO;
import io.mosip.authentication.core.logger.IdaLogger;
import io.mosip.authentication.core.partner.dto.PartnerDTO;
Expand Down Expand Up @@ -110,17 +111,17 @@ public void publishEvent(EventModel eventModel) {
webSubHelper.publishEvent(onDemadTemplateExtractionTopic, eventModel);
}

public void notify(BaseRequestDTO baserequestdto, String headerSignature, Optional<PartnerDTO> partner,
public void notify(BaseRequestDTO baserequestdto, String apiresponsedate, String headerSignature, Optional<PartnerDTO> partner,
IdAuthenticationBusinessException e, Map<String, Object> metadata) {
try {
sendEvents(baserequestdto, headerSignature, partner, e, metadata);
sendEvents(baserequestdto,apiresponsedate, headerSignature, partner, e, metadata);
} catch (Exception exception) {
logger.error(IdRepoSecurityManager.getUser(), "On demand template extraction", "notify",
exception.getMessage());
}
}

private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, Optional<PartnerDTO> partner,
private void sendEvents(BaseRequestDTO baserequestdto, String apiresponsedate, String headerSignature, Optional<PartnerDTO> partner,
IdAuthenticationBusinessException e, Map<String, Object> metadata) {
logger.info("Inside sendEvents ondemand extraction");
logger.info("Inside partner data to get certificate for ondemand extraction encryption");
Expand All @@ -131,7 +132,7 @@ private void sendEvents(BaseRequestDTO baserequestdto, String headerSignature, O
Map<String, Object> eventData = new HashMap<>();
eventData.put(ERROR_CODE, e.getErrorCode());
eventData.put(ERROR_MESSAGE, e.getErrorText());
eventData.put(REQUESTDATETIME, DateUtils.formatToISOString(DateUtils.getUTCCurrentDateTime()));
eventData.put(REQUESTDATETIME, apiresponsedate);
eventData.put(INDIVIDUAL_ID,
encryptIndividualId(baserequestdto.getIndividualId(), partnerDataCert.get().getCertificateData()));
eventData.put(AUTH_PARTNER_ID, partner.get().getPartnerId());
Expand All @@ -158,7 +159,7 @@ private EventModel createEventModel(String topic, Map<String, Object> eventData)
return model;
}

private byte[] encryptIndividualId(String id, String partnerCertificate) {
private String encryptIndividualId(String id, String partnerCertificate) {
try {
logger.info("Inside the method of encryptIndividualId using partner certificate ");
return securityManager.asymmetricEncryption(id.getBytes(), partnerCertificate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt
if(request instanceof ObjectWithMetadata) {
ObjectWithMetadata requestWithMetadata = (ObjectWithMetadata) request;

OtpResponseDTO otpResponseDTO=null;
boolean isPartnerReq = true;
Optional<PartnerDTO> partner = partnerService.getPartner(partnerId, otpRequestDto.getMetadata());
AuthTransactionBuilder authTxnBuilder = authTransactionHelper
Expand All @@ -142,7 +143,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt
otpRequestDto.setIndividualIdType(idType);
otpRequestValidator.validateIdvId(otpRequestDto.getIndividualId(), idType, errors, IdAuthCommonConstants.IDV_ID);
DataValidationUtil.validate(errors);
OtpResponseDTO otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata);
otpResponseDTO = otpService.generateOtp(otpRequestDto, partnerId, requestWithMetadata);
logger.info(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(), GENERATE_OTP,
otpResponseDTO.getResponseTime());

Expand All @@ -161,7 +162,7 @@ public OtpResponseDTO generateOTP(@Valid @RequestBody OtpRequestDTO otpRequestDt
} catch (IdAuthenticationBusinessException e) {
logger.error(IdAuthCommonConstants.SESSION_ID, e.getClass().toString(), e.getErrorCode(), e.getErrorText());
if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) {
ondemandTemplateEventPublisher.notify(otpRequestDto, request.getHeader("signature"), partner, e,
ondemandTemplateEventPublisher.notify(otpRequestDto, otpResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e,
otpRequestDto.getMetadata());
}
auditHelper.audit(AuditModules.OTP_REQUEST, AuditEvents.OTP_TRIGGER_REQUEST_RESPONSE , otpRequestDto.getTransactionID(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques

if(request instanceof ObjectWithMetadata) {
ObjectWithMetadata requestWithMetadata = (ObjectWithMetadata) request;

AuthResponseDTO authResponsedto = null;
boolean isAuth = true;
Optional<PartnerDTO> partner = partnerService.getPartner(partnerId, authrequestdto.getMetadata());
AuthTransactionBuilder authTxnBuilder = authTransactionHelper
Expand All @@ -146,7 +146,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques
authRequestValidator.validateDeviceDetails(authrequestdto, errors);
}
DataValidationUtil.validate(errors);
AuthResponseDTO authResponsedto = authFacade.authenticateIndividual(authrequestdto, true, partnerId,
authResponsedto = authFacade.authenticateIndividual(authrequestdto, true, partnerId,
partnerApiKey, IdAuthCommonConstants.CONSUME_VID_DEFAULT, requestWithMetadata);
// Note: Auditing of success or failure status of each authentication (but not
// the exception) is handled in respective authentication invocations in the facade
Expand All @@ -163,7 +163,7 @@ public AuthResponseDTO authenticateIndividual(@Validated @RequestBody AuthReques
mosipLogger.error(IdAuthCommonConstants.SESSION_ID, this.getClass().getSimpleName(),
"authenticateApplication", e.getErrorCode() + " : " + e.getErrorText());
if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) {
ondemandTemplateEventPublisher.notify(authrequestdto, request.getHeader("signature"), partner, e,
ondemandTemplateEventPublisher.notify(authrequestdto, authResponsedto.getResponseTime(), request.getHeader("signature"), partner, e,
authrequestdto.getMetadata());
}
auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.AUTH_REQUEST_RESPONSE, authrequestdto, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO
throws IdAuthenticationBusinessException, IdAuthenticationAppException, IdAuthenticationDaoException {
if(request instanceof ObjectWithMetadata) {
ObjectWithMetadata requestWrapperWithMetadata = (ObjectWithMetadata) request;


AuthResponseDTO authResponseDTO= null;
boolean isAuth = true;
Optional<PartnerDTO> partner = partnerService.getPartner(partnerId, ekycAuthRequestDTO.getMetadata());
AuthTransactionBuilder authTxnBuilder = authTransactionHelper
Expand All @@ -175,7 +176,7 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO
}
DataValidationUtil.validate(errors);
boolean externalAuthRequest = true;
AuthResponseDTO authResponseDTO = kycFacade.authenticateIndividual(ekycAuthRequestDTO, externalAuthRequest,
authResponseDTO = kycFacade.authenticateIndividual(ekycAuthRequestDTO, externalAuthRequest,
partnerId, partnerApiKey, requestWrapperWithMetadata);
EKycAuthResponseDTO kycAuthResponseDTO = new EKycAuthResponseDTO();
Map<String, Object> metadata = requestWrapperWithMetadata.getMetadata();
Expand All @@ -199,7 +200,7 @@ public EKycAuthResponseDTO processKyc(@Validated @RequestBody EkycAuthRequestDTO
e.getErrorTexts().isEmpty() ? "" : e.getErrorText());

if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) {
ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO, request.getHeader("signature"), partner,
ondemandTemplateEventPublisher.notify(ekycAuthRequestDTO,authResponseDTO.getResponseTime(), request.getHeader("signature"), partner,
e, ekycAuthRequestDTO.getMetadata());
}
auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.EKYC_REQUEST_RESPONSE, ekycAuthRequestDTO, e);
Expand Down Expand Up @@ -246,7 +247,7 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD
Optional<PartnerDTO> partner = partnerService.getPartner(partnerId, authRequestDTO.getMetadata());
AuthTransactionBuilder authTxnBuilder = authTransactionHelper
.createAndSetAuthTxnBuilderMetadataToRequest(authRequestDTO, !isAuth, partner);

KycAuthResponseDTO kycAuthResponseDTO = new KycAuthResponseDTO();
try {
String idType = Objects.nonNull(authRequestDTO.getIndividualIdType()) ? authRequestDTO.getIndividualIdType()
: idTypeUtil.getIdType(authRequestDTO.getIndividualId()).getType();
Expand All @@ -259,7 +260,6 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD
boolean externalAuthRequest = true;
AuthResponseDTO authResponseDTO = kycFacade.authenticateIndividual(authRequestDTO, externalAuthRequest, partnerId,
oidcClientId, requestWrapperWithMetadata, IdAuthCommonConstants.KYC_AUTH_CONSUME_VID_DEFAULT);
KycAuthResponseDTO kycAuthResponseDTO = new KycAuthResponseDTO();
Map<String, Object> metadata = requestWrapperWithMetadata.getMetadata();
if (authResponseDTO != null &&
metadata != null &&
Expand All @@ -281,7 +281,7 @@ public KycAuthResponseDTO processKycAuth(@Validated @RequestBody KycAuthRequestD
e.getErrorTexts().isEmpty() ? "" : e.getErrorText());

if (IdAuthenticationErrorConstants.ID_NOT_AVAILABLE.getErrorCode().equals(e.getErrorCode())) {
ondemandTemplateEventPublisher.notify(authRequestDTO, request.getHeader("signature"), partner, e,
ondemandTemplateEventPublisher.notify(authRequestDTO, kycAuthResponseDTO.getResponseTime(), request.getHeader("signature"), partner, e,
authRequestDTO.getMetadata());
}
auditHelper.auditExceptionForAuthRequestedModules(AuditEvents.KYC_REQUEST_RESPONSE, authRequestDTO, e);
Expand Down
Loading