use of io.gravitee.am.model.jose.RSAKey in project gravitee-access-management by gravitee-io.
the class DynamicClientRegistrationResponseTest method convert.
@Test
public void convert() {
RSAKey rsaKey = new RSAKey();
rsaKey.setKty("RSA");
rsaKey.setKid("kidRSA");
rsaKey.setUse("enc");
rsaKey.setE("exponent");
rsaKey.setN("modulus");
ECKey ecKey = new ECKey();
ecKey.setKty("EC");
ecKey.setKid("kidEC");
ecKey.setUse("enc");
ecKey.setCrv("P-256");
ecKey.setX("vBT2JhFHd62Jcf4yyBzSV9NuDBNBssR1zlmnHelgZcs");
ecKey.setY("up8E8b3TjeKS2v2GCH23UJP0bak0La77lkQ7_n4djqE");
OKPKey okpKey = new OKPKey();
okpKey.setKty("OKP");
okpKey.setKid("kidOKP");
okpKey.setCrv("Ed25519");
okpKey.setX("vBNW8f19leF79U4U6NrDDQaK_i5kL0iMKghB39AUT2I");
OCTKey octKey = new OCTKey();
octKey.setKty("oct");
octKey.setKid("kidOCT");
octKey.setK("FdFYFzERwC2uCBB46pZQi4GG85LujR8obt-KWRBICVQ");
JWKSet jwkSet = new JWKSet();
jwkSet.setKeys(Arrays.asList(rsaKey, ecKey, okpKey, octKey));
Client client = new Client();
client.setClientId("clientId");
client.setClientName("clientName");
client.setJwks(jwkSet);
DynamicClientRegistrationResponse response = DynamicClientRegistrationResponse.fromClient(client);
assertNotNull("expecting response", response);
assertEquals(response.getClientId(), "clientId");
assertEquals(response.getClientName(), "clientName");
assertTrue(response.getJwks().getKeys().size() == 4);
}
use of io.gravitee.am.model.jose.RSAKey in project gravitee-access-management by gravitee-io.
the class JWKServiceTest method testFilter_RSA_weakKey.
@Test
public void testFilter_RSA_weakKey() {
// key size is <2048 bits
RSAKey rsaEnc = new RSAKey();
rsaEnc.setKty("RSA");
rsaEnc.setKid("rsaEnc");
rsaEnc.setUse("enc");
rsaEnc.setN("nRuv8E_c8aLRlyMz4h2SKWKHkzmDO49TVXppes1IqRdFACg_7cEhKfV5-jiNVxH3nKFGcHw6IG3qCJe_-pEJhnTbIdYS98UJmVZuudD_7lH5JgVhaV3ZwY6aQIMsoE5YhMyi55jbHPS-GqSIGonlVlgpHX_VjxKtj-u_-824xZU");
RSAKey rsaSig = new RSAKey();
rsaSig.setKty("RSA");
rsaSig.setKid("rsaSig");
rsaSig.setUse("sig");
JWKSet rsaSet = new JWKSet();
rsaSet.setKeys(Arrays.asList(rsaEnc, rsaSig));
TestObserver testObserver = jwkService.filter(rsaSet, JWKFilter.RSA_KEY_ENCRYPTION()).test();
testObserver.assertNoErrors();
testObserver.assertComplete();
testObserver.assertResult();
}
use of io.gravitee.am.model.jose.RSAKey in project gravitee-access-management by gravitee-io.
the class JWSServiceTest method testVerifier_RSA_invalid.
@Test(expected = IllegalArgumentException.class)
public void testVerifier_RSA_invalid() {
RSAKey key = new RSAKey();
key.setKty("RSA");
key.setKid(KID);
key.setE(Base64.getUrlEncoder().encodeToString("exponent".getBytes()));
key.setN(Base64.getUrlEncoder().encodeToString("modulus".getBytes()));
jwsService.verifier(key);
}
use of io.gravitee.am.model.jose.RSAKey in project gravitee-access-management by gravitee-io.
the class JWSServiceTest method testValidSignature_RSA.
@Test
public void testValidSignature_RSA() throws NoSuchAlgorithmException, JOSEException {
// Generate RSA key
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(2048);
KeyPair rsaKey = kpg.generateKeyPair();
RSAPublicKey publicKey = (RSAPublicKey) rsaKey.getPublic();
RSAKey key = new RSAKey();
key.setKty("RSA");
key.setKid(KID);
key.setE(Base64.getUrlEncoder().encodeToString(publicKey.getPublicExponent().toByteArray()));
key.setN(Base64.getUrlEncoder().encodeToString(publicKey.getModulus().toByteArray()));
// Sign JWT with RSA algorithm
SignedJWT signedJWT = new SignedJWT(new JWSHeader.Builder(JWSAlgorithm.RS256).keyID(KID).build(), new JWTClaimsSet.Builder().expirationTime(Date.from(Instant.now().plus(1, ChronoUnit.DAYS))).build());
signedJWT.sign(new RSASSASigner((RSAPrivateKey) rsaKey.getPrivate()));
assertTrue("Should be ok", jwsService.isValidSignature(signedJWT, key));
}
use of io.gravitee.am.model.jose.RSAKey in project gravitee-access-management by gravitee-io.
the class ProviderJWKSetEndpointHandlerTest method shouldInvokeJWKSetEndpoint.
@Test
public void shouldInvokeJWKSetEndpoint() throws Exception {
JWK jwk = new RSAKey();
jwk.setKty("RSA");
jwk.setKid("my-test-key");
JWKSet jwkSet = new JWKSet();
jwkSet.setKeys(Collections.singletonList(jwk));
when(jwkService.getKeys()).thenReturn(Single.just(jwkSet));
testRequest(HttpMethod.GET, "/.well-known/jwks.json", HttpStatusCode.OK_200, "OK", "{\n" + " \"keys\" : [ {\n" + " \"kty\" : \"RSA\",\n" + " \"kid\" : \"my-test-key\"\n" + " } ]\n" + "}");
}
Aggregations