use of uk.gov.di.ipv.cri.passport.library.domain.DcsResponse in project di-ipv-cri-uk-passport-back by alphagov.
the class JwtHelperTest method shouldCreateValidSignedJWT.
@Test
void shouldCreateValidSignedJWT() throws JOSEException, ParseException, InvalidKeySpecException, NoSuchAlgorithmException, JsonProcessingException {
ECDSASigner ecSigner = new ECDSASigner(getPrivateKey());
VerifiableCredential verifiableCredential = new VerifiableCredential(new CredentialSubject(new Name(List.of(new NameParts(GIVEN_NAME, NamePartType.GIVEN_NAME.getName(), VALID_FROM, VALID_UNTIL))), PASSPORT_NUMBER, new BirthDate(BIRTH_DATE), LocalDate.parse(EXPIRY_DATE).toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), new DcsResponse()), Collections.singletonList(new Evidence()));
JWTClaimsSet testClaimsSet = new JWTClaimsSet.Builder().claim("sub", "test-subject").claim("iss", "test-issuer").claim("nbf", Instant.now().getEpochSecond()).claim("vc", verifiableCredential).claim("exp", Instant.now().plusSeconds(100000).getEpochSecond()).build();
SignedJWT signedJWT = JwtHelper.createSignedJwtFromClaimSet(testClaimsSet, ecSigner);
JWTClaimsSet generatedClaims = signedJWT.getJWTClaimsSet();
assertTrue(signedJWT.verify(new ECDSAVerifier(ECKey.parse(EC_PUBLIC_JWK_1))));
JsonNode claimsSet = objectMapper.readTree(generatedClaims.toString());
JsonNode vcNode = claimsSet.get("vc");
JsonNode credentialSubjectNode = vcNode.get("credentialSubject");
JsonNode nameNode = credentialSubjectNode.get("name");
assertEquals(GIVEN_NAME, nameNode.get("nameParts").get(0).get("value").asText());
assertEquals(NamePartType.GIVEN_NAME.getName(), nameNode.get("nameParts").get(0).get("type").asText());
assertEquals(VALID_FROM, nameNode.get("nameParts").get(0).get("validFrom").asText());
assertEquals(VALID_UNTIL, nameNode.get("nameParts").get(0).get("validUntil").asText());
assertEquals(BIRTH_DATE, credentialSubjectNode.get("birthDate").get("value").asText());
assertEquals(EXPIRY_DATE, credentialSubjectNode.get("expiryDate").asText());
}
use of uk.gov.di.ipv.cri.passport.library.domain.DcsResponse in project di-ipv-cri-uk-passport-back by alphagov.
the class DateStorePassportCheckIT method createPassportCheckDao.
private PassportCheckDao createPassportCheckDao() {
String resourceId = UUID.randomUUID().toString();
DcsResponse dcsResponse = new DcsResponse(UUID.randomUUID().toString(), UUID.randomUUID().toString(), false, true, null);
PassportAttributes passportAttributes = new PassportAttributes("passport-number", "surname", List.of("family-name"), LocalDate.of(1900, 1, 1), LocalDate.of(2025, 2, 2));
passportAttributes.setDcsResponse(dcsResponse);
Evidence evidence = new Evidence(5, 5);
createdItemIds.add(resourceId);
return new PassportCheckDao(resourceId, passportAttributes, evidence, "test-user-id");
}
use of uk.gov.di.ipv.cri.passport.library.domain.DcsResponse in project di-ipv-cri-uk-passport-back by alphagov.
the class VerifiableCredentialTest method shouldConvertPassportCheckDaoToPassportCredentialIssuerResponse.
@Test
void shouldConvertPassportCheckDaoToPassportCredentialIssuerResponse() {
PassportAttributes attributes = new PassportAttributes(PASSPORT_NUMBER, FAMILY_NAME, GIVEN_NAMES, DATE_OF_BIRTH, EXPIRY_DATE);
Evidence evidence = new Evidence(4, 4);
attributes.setDcsResponse(new DcsResponse(UUID.randomUUID().toString(), UUID.randomUUID().toString(), true, false, Collections.emptyList()));
PassportCheckDao passportCheckDao = new PassportCheckDao(RESOURCE_ID, attributes, evidence, "test-user-id");
VerifiableCredential verifiableCredential = VerifiableCredential.fromPassportCheckDao(passportCheckDao);
assertEquals(FAMILY_NAME, verifiableCredential.getCredentialSubject().getName().getNameParts().get(1).getValue());
assertEquals(GIVEN_NAMES.get(0), verifiableCredential.getCredentialSubject().getName().getNameParts().get(0).getValue());
assertEquals(PASSPORT_NUMBER, verifiableCredential.getCredentialSubject().getPassportNumber());
assertEquals(DATE_OF_BIRTH.toString(), verifiableCredential.getCredentialSubject().getBirthDate().getValue());
assertEquals(EXPIRY_DATE.toString(), verifiableCredential.getCredentialSubject().getExpiryDate());
assertEquals(passportCheckDao.getAttributes().getRequestId().toString(), verifiableCredential.getCredentialSubject().getRequestId());
assertEquals(passportCheckDao.getAttributes().getCorrelationId().toString(), verifiableCredential.getCredentialSubject().getCorrelationId());
assertEquals(passportCheckDao.getAttributes().getDcsResponse(), verifiableCredential.getCredentialSubject().getDcsResponse());
}
use of uk.gov.di.ipv.cri.passport.library.domain.DcsResponse in project di-ipv-cri-uk-passport-back by alphagov.
the class StubDcsHandler method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
try {
DcsResponse incomingPayload = verifyAndDecryptAndVerify(input.getBody());
DcsResponse dcsResponse = new DcsResponse(incomingPayload.getCorrelationId(), incomingPayload.getRequestId(), false, true, null);
LOGGER.info("Generated DCS response with correlationId: {} and requestId: {}", dcsResponse.getCorrelationId(), dcsResponse.getRequestId());
return ApiGatewayResponseGenerator.proxyJoseResponse(HttpStatus.SC_OK, signAndEncryptAndSign(dcsResponse));
} catch (StubDcsException e) {
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, e);
}
}
use of uk.gov.di.ipv.cri.passport.library.domain.DcsResponse in project di-ipv-cri-uk-passport-back by alphagov.
the class AuthorizationCodeHandler method handleRequest.
@Override
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent input, Context context) {
Map<String, List<String>> queryStringParameters = getQueryStringParametersAsMap(input);
String userId = RequestHelper.getHeaderByKey(input.getHeaders(), "user_id");
try {
var validationResult = authRequestValidator.validateRequest(queryStringParameters, userId);
if (validationResult.isPresent()) {
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, validationResult.get());
}
AuthenticationRequest authenticationRequest = AuthenticationRequest.parse(queryStringParameters);
PassportAttributes passportAttributes = parsePassportFormRequest(input.getBody());
JWSObject preparedDcsPayload = preparePayload(passportAttributes);
DcsSignedEncryptedResponse dcsResponse = doPassportCheck(preparedDcsPayload);
auditService.sendAuditEvent(AuditEventTypes.PASSPORT_REQUEST_SENT_TO_DCS);
DcsResponse unwrappedDcsResponse = unwrapDcsResponse(dcsResponse);
passportAttributes.setDcsResponse(unwrappedDcsResponse);
validateDcsResponse(unwrappedDcsResponse);
PassportCheckDao passportCheckDao = new PassportCheckDao(UUID.randomUUID().toString(), passportAttributes, generateGpg45Score(unwrappedDcsResponse), userId);
passportService.persistDcsResponse(passportCheckDao);
AuthorizationCode authorizationCode = authorizationCodeService.generateAuthorizationCode();
authorizationCodeService.persistAuthorizationCode(authorizationCode.getValue(), passportCheckDao.getResourceId(), authenticationRequest.getRedirectionURI().toString());
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_OK, Map.of(AUTHORIZATION_CODE, authorizationCode));
} catch (HttpResponseExceptionWithErrorBody e) {
return ApiGatewayResponseGenerator.proxyJsonResponse(e.getStatusCode(), e.getErrorBody());
} catch (ParseException e) {
LOGGER.error("Authentication request could not be parsed", e);
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.FAILED_TO_PARSE_OAUTH_QUERY_STRING_PARAMETERS);
} catch (SqsException e) {
LOGGER.error("Failed to send audit event to SQS queue because: {}", e.getMessage());
return ApiGatewayResponseGenerator.proxyJsonResponse(HttpStatus.SC_BAD_REQUEST, ErrorResponse.FAILED_TO_SEND_AUDIT_MESSAGE_TO_SQS_QUEUE);
}
}
Aggregations