Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Sohandey committed Oct 6, 2023
2 parents b11fbc0 + 8db8e4b commit d022085
Show file tree
Hide file tree
Showing 12 changed files with 1,119 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import javax.crypto.NoSuchPaddingException;
import javax.xml.bind.DatatypeConverter;

import io.mosip.testrig.authentication.demo.service.dto.*;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.bouncycastle.operator.OperatorCreationException;
Expand All @@ -62,12 +63,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
Expand All @@ -90,9 +86,6 @@
import io.mosip.kernel.core.util.DateUtils;
import io.mosip.kernel.core.util.HMACUtils2;
import io.mosip.testrig.authentication.demo.service.controller.Encrypt.SplittedEncryptedData;
import io.mosip.testrig.authentication.demo.service.dto.CertificateChainResponseDto;
import io.mosip.testrig.authentication.demo.service.dto.EncryptionRequestDto;
import io.mosip.testrig.authentication.demo.service.dto.EncryptionResponseDto;
import io.mosip.testrig.authentication.demo.service.helper.CertificateTypes;
import io.mosip.testrig.authentication.demo.service.helper.KeyMgrUtil;
import io.mosip.testrig.authentication.demo.service.helper.PartnerTypes;
Expand Down Expand Up @@ -177,6 +170,8 @@ public class AuthRequestController {

private static final String IDA_KYC_EXCHANGE_REQUEST_TEMPLATE = "ida.kycExchangeRequest.template";

private static final String IDA_VCI_EXCHANGE_REQUEST_TEMPLATE = "ida.vciExchangeRequest.template";

private static final String ID = "id";

private static final String CLASSPATH = "classpath";
Expand Down Expand Up @@ -574,6 +569,68 @@ public ResponseEntity<String> createKycExchangeRequest(@RequestParam(name = ID,
String.format(IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorMessage(), IDENTITY));
}
}

@PostMapping(path = "/create-vci-exchange-request", consumes = MediaType.APPLICATION_JSON_VALUE, produces = {
MediaType.APPLICATION_JSON_VALUE })
public ResponseEntity<String> createVciExchangeRequest(@RequestParam(name = ID, required = true) @Nullable String id,
@RequestParam(name = ID_TYPE, required = false) @Nullable String idType,
@RequestParam(name = "Authtype", required = false) @Nullable String reqAuth,
@RequestParam(name = TRANSACTION_ID, required = false) @Nullable String transactionId,
@RequestParam(name = "requestTime", required = false) @Nullable String requestTime,
@RequestParam(name = "vcFormat", required = false) @Nullable String vcFormat,
@RequestParam(name = "credSubjectId", required = false)@Nullable String credSubjectId,
@RequestParam(name = "vcAuthToken", required = false)@Nullable String vcAuthToken,
@RequestParam(name = "keyFileNameByPartnerName", required = false)boolean keyFileNameByPartnerName,
@RequestParam(name = "partnerName", required = false)@Nullable String partnerName,
@RequestBody Map<String, Object> request,
@RequestParam(name = "certsDir", required = false) String certsDir,
@RequestParam(name = "moduleName", required = false) String moduleName) throws Exception {
String authRequestTemplate = environment.getProperty(IDA_VCI_EXCHANGE_REQUEST_TEMPLATE);
Map<String, Object> reqValues = new HashMap<>();

if (requestTime == null) {
requestTime = DateUtils.getUTCCurrentDateTimeString(environment.getProperty("datetime.pattern"));
}

reqValues.put(ID, id);
reqValues.put("individualIdType", idType == null || idType.trim().length() == 0 ? IdType.UIN.toString() : idType);
reqValues.put(AUTH_TYPE, reqAuth);
reqValues.put(TIMESTAMP, requestTime);
reqValues.put(TXN, transactionId == null ? "1234567890" : transactionId);
reqValues.put(VER, environment.getProperty(IDA_API_VERSION));
reqValues.put("vcFormat", vcFormat);
reqValues.put("credSubjectId", credSubjectId);
reqValues.put("vcAuthToken", vcAuthToken);

StringWriter writer = new StringWriter();
InputStream templateValue;
if (request != null && request.size() > 0) {
templateValue = templateManager
.merge(new ByteArrayInputStream(authRequestTemplate.getBytes(StandardCharsets.UTF_8)), reqValues);

if (templateValue != null) {
IOUtils.copy(templateValue, writer, StandardCharsets.UTF_8);
String res = writer.toString();
ObjectNode response = mapper.readValue(res.getBytes(), ObjectNode.class);

HttpHeaders httpHeaders = new HttpHeaders();
String responseStr = response.toString();

String rpSignature = signRequest(PartnerTypes.MISP, partnerName, keyFileNameByPartnerName, responseStr, certsDir, moduleName);
httpHeaders.add("signature", rpSignature);
return new ResponseEntity<>(responseStr, httpHeaders, HttpStatus.OK);
} else {
throw new IdAuthenticationBusinessException(
IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorCode(), String.format(
IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorMessage(), TEMPLATE));
}
} else {
throw new IdAuthenticationBusinessException(
IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorCode(),
String.format(IdAuthenticationErrorConstants.MISSING_INPUT_PARAMETER.getErrorMessage(), IDENTITY));
}
}


/**
* this method is used to create the auth request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ida-demo.api.version=v1
server.port = 8082
ida.authRequest.template={"consentObtained":true,"id":"mosip.identity.$authType","individualId":"$id","keyIndex":"string","request":"$encRequest","requestHMAC":"$encHmac","requestSessionKey":"$encSessionKey","requestTime":"$timestamp","transactionID":"$txn","version":"$ver","domainUri":"$domainUri","env":"$env","specVersion":"1.0","thumbprint":"$thumbprint"}
ida.kycExchangeRequest.template={"consentObtained":["true"],"locales":["eng"],"id":"mosip.identity.$authType","individualId":"$id","individualIdType":"$individualIdType","kycToken":"$kycToken","respType":"$respType","metadata":"$request","requestTime":"$timestamp","transactionID":"$txn","version":"$ver"}
ida.vciExchangeRequest.template={"consentObtained":["true"],"locales":["eng"],"id":"mosip.identity.$authType","individualId":"$id","individualIdType":"$individualIdType","kycToken":"$kycToken","respType":"$respType","metadata":"$request","requestTime":"$timestamp","transactionID":"$txn","version":"$ver","vcAuthToken":"$vcAuthToken","credSubjectId":"$credSubjectId","vcAuthToken":"$vcAuthToken","vcFormat":"$vcFormat"}
otpRequestTemplate={\
"id": "$reqId",\
"individualId": "$id",\
Expand Down Expand Up @@ -64,7 +65,7 @@ ida.api.version=1.0
javax.persistence.jdbc.driver=org.postgresql.Driver
javax.persistence.jdbc.url=jdbc:postgresql://localhost:5432/ida_db
javax.persistence.jdbc.user=postgres
javax.persistence.jdbc.password=admin
javax.persistence.jdbc.password=postgres


# ********* Hibernate Properties ***********
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"encodedHash": "{{encodedHash}}",
"requestTime": "{{requestTime}}",
"request": {
"transactionId": "{{transactionId}}",
"individualId": "{{individualId}}",
"challengeList" : [
{
"authFactorType" : "{{authFactorType}}",
"challenge" : "{{challenge}}",
"format": "alpha-numeric"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
AuthenticateUserVCIVidNegTC:
ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen1_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen1_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen1_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen1_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen1_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'

ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen2_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen2_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen2_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen2_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen2_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'

ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen3_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen3_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen3_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen3_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen3_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'

ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen4_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen4_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen4_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen4_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen4_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'

ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen5_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen5_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen5_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen5_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen5_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'

ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen6_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen6_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen6_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen6_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen6_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'

ESignet_AuthenticateUserVCI_Vid_Otp_NegAuthCodeScen7_Valid_Smoke:
endPoint: /v1/esignet/authorization/authenticate
role: resident
restMethod: post
checkErrorsOnlyInResponse: true
validityCheckRequired: true
inputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCI
outputTemplate: esignet/VCIVidNegTC/AuthenticateUserVCI/AuthenticateUserVCIResultResult
input: '{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen7_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen7_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"authFactorType" : "OTP",
"challenge" : "$ID:AddIdentity_Valid_Params_VCI_Vid_Inv_Scen_smoke_Pos_EMAIL$",
"sendOtp":{
"encodedHash": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen7_Valid_Smoke_sid_encodedResp$",
"requestTime": "$TIMESTAMP$",
"transactionId": "$ID:OAuthDetailsRequest_VCI_Vid_NegAuthCodeScen7_Valid_Smoke_sid_transactionId$",
"individualId": "$ID:Generate_Perpetual_VID_VCI_Invalid_Scen_Smoke_sid_vid$",
"otpChannels": [{channel: "email"},{channel: "phone"}],
"sendOtpReqTemplate": "esignet/SendOtp/SendOtp",
"sendOtpEndPoint": "/v1/esignet/authorization/send-otp"
}
}'
output: '{
"sendOtpResp":{
"maskedMobile": "XXXXXX3210",
"sendOtpResTemplate":"esignet/SendOtp/SendOtpResult",
"maskedEmail": "$IGNORE$"
}
}'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Loading

0 comments on commit d022085

Please sign in to comment.