use of com.nimbusds.jose.JWSVerifier in project OpenConext-oidcng by OpenConext.
the class AbstractIntegrationTest method verifySignedJWT.
protected JWTClaimsSet verifySignedJWT(String token, int port) throws MalformedURLException, JOSEException, ParseException {
JWKSource keySource = new RemoteJWKSet(new URL("http://localhost:" + port + "/oidc/certs"));
List<JWK> list = keySource.get(new JWKSelector(new JWKMatcher.Builder().build()), null);
SignedJWT signedJWT = SignedJWT.parse(token);
RSAKey rsaKey = (RSAKey) list.stream().filter(jwk -> jwk.getKeyID().equals(signedJWT.getHeader().getKeyID())).findAny().get();
assertFalse(rsaKey.isPrivate());
JWSVerifier verifier = new RSASSAVerifier(rsaKey);
boolean verified = signedJWT.verify(verifier);
assertTrue(verified);
return signedJWT.getJWTClaimsSet();
}
use of com.nimbusds.jose.JWSVerifier in project java-sdk by hyperwallet.
the class HyperwalletEncryption method decrypt.
public String decrypt(String body) throws ParseException, IOException, JOSEException {
JWK privateKeyToDecrypt = getKeyByAlgorithm(loadKeySet(clientPrivateKeySetLocation), encryptionAlgorithm);
JWK publicKeyToSign = getKeyByAlgorithm(loadKeySet(hyperwalletKeySetLocation), signAlgorithm);
JWEDecrypter jweDecrypter = getJWEDecrypter(privateKeyToDecrypt);
JWSVerifier jwsVerifier = getJWSVerifier(publicKeyToSign);
JWEObject jweObject = JWEObject.parse(body);
jweObject.decrypt(jweDecrypter);
JWSObject jwsObject = jweObject.getPayload().toJWSObject();
verifySignatureExpirationDate(jwsObject.getHeader().getCustomParam(EXPIRATION));
boolean verifyStatus = jwsObject.verify(jwsVerifier);
if (!verifyStatus) {
throw new HyperwalletException("JWS signature is incorrect");
}
return jwsObject.getPayload().toString();
}
use of com.nimbusds.jose.JWSVerifier in project di-ipv-cri-uk-passport-back by alphagov.
the class DcsCryptographyServiceTest method shouldPreparePayloadForDcsRequest.
@Test
void shouldPreparePayloadForDcsRequest() throws JOSEException, InvalidKeySpecException, NoSuchAlgorithmException, CertificateException, ParseException, JsonProcessingException {
when(configurationService.getPassportCriSigningKey()).thenReturn(getSigningPrivateKey());
when(configurationService.makeThumbprints()).thenReturn(new Thumbprints(SHA_1_THUMBPRINT, SHA_256_THUMBPRINT));
when(configurationService.getDcsEncryptionCert()).thenReturn(getEncryptionCertificate());
PassportAttributes passportAttributes = new PassportAttributes("PASSPORT_NUMBER", "SURNAME", List.of("FORENAMES"), LocalDate.now(), LocalDate.now());
JWSObject preparedPayload = underTest.preparePayload(passportAttributes);
JWSVerifier verifier = new RSASSAVerifier((RSAPublicKey) getSigningPublicKey(getSigningPrivateKey()));
JWEObject encryptedContents = JWEObject.parse(preparedPayload.getPayload().toString());
RSADecrypter rsaDecrypter = new RSADecrypter(getEncryptionPrivateKey());
encryptedContents.decrypt(rsaDecrypter);
JWSObject decryptedPassportDetails = JWSObject.parse(encryptedContents.getPayload().toString());
assertTrue(decryptedPassportDetails.verify(verifier));
String expected = objectMapper.writeValueAsString(passportAttributes);
assertEquals(expected, decryptedPassportDetails.getPayload().toString());
}
Aggregations