use of io.gravitee.am.model.jose.OCTKey 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.OCTKey in project gravitee-access-management by gravitee-io.
the class JWKServiceTest method testFilter_AES_no_128_keys.
@Test
public void testFilter_AES_no_128_keys() {
OCTKey oct192 = new OCTKey();
oct192.setKty("oct");
oct192.setKid("octEnc192");
oct192.setUse("enc");
// 192bits (24 bytes)
oct192.setK("G9jUYv3b0-0wZWCGxAnIUH6gI0kjeXj4");
OCTKey oct256 = new OCTKey();
oct256.setKty("oct");
oct256.setKid("octEnc256");
oct256.setUse("enc");
// 256bits (32 bytes)
oct256.setK("RlrxxWClnDX_dpa47lvC29vBiB-ZDCg-b8n70Ugefyo");
OCTKey octSig = new OCTKey();
octSig.setKty("oct");
octSig.setKid("octSig");
octSig.setUse("sig");
JWKSet jwkSet = new JWKSet();
jwkSet.setKeys(Arrays.asList(oct192, oct256, octSig));
TestObserver testObserver = jwkService.filter(jwkSet, JWKFilter.OCT_KEY_ENCRYPTION(JWEAlgorithm.A128KW)).test();
testObserver.assertNoErrors();
testObserver.assertComplete();
testObserver.assertResult();
testObserver = jwkService.filter(jwkSet, JWKFilter.OCT_KEY_ENCRYPTION(JWEAlgorithm.A128GCMKW)).test();
testObserver.assertNoErrors();
testObserver.assertComplete();
testObserver.assertResult();
}
use of io.gravitee.am.model.jose.OCTKey in project gravitee-access-management by gravitee-io.
the class JWSServiceTest method testVerifier_OCT_invalid.
@Test(expected = IllegalArgumentException.class)
public void testVerifier_OCT_invalid() {
OCTKey key = new OCTKey();
key.setKty("oct");
key.setKid(KID);
key.setK("too_short");
jwsService.verifier(key);
}
use of io.gravitee.am.model.jose.OCTKey in project gravitee-access-management by gravitee-io.
the class JWEAesTest method encryptIdToken.
@Test
public void encryptIdToken() {
try {
int keySize = 128;
if (alg.startsWith("A192")) {
keySize = 192;
} else if (alg.startsWith("A256")) {
keySize = 256;
}
// Generate a secret AES key with 128 bits
KeyGenerator gen = KeyGenerator.getInstance("AES");
gen.init(keySize);
SecretKey aesKey = gen.generateKey();
// Convert to JWK format
OctetSequenceKey jwk = new OctetSequenceKey.Builder(aesKey).build();
OCTKey key = new OCTKey();
key.setKid("octEnc");
key.setUse("enc");
key.setK(jwk.getKeyValue().toString());
Client client = new Client();
client.setIdTokenEncryptedResponseAlg(this.alg);
client.setIdTokenEncryptedResponseEnc(this.enc);
when(jwkService.getKeys(client)).thenReturn(Maybe.just(new JWKSet()));
when(jwkService.filter(any(), any())).thenReturn(Maybe.just(key));
TestObserver testObserver = jweService.encryptIdToken("JWT", client).test();
testObserver.assertNoErrors();
testObserver.assertComplete();
testObserver.assertValue(jweString -> {
JWEObject jwe = JWEObject.parse((String) jweString);
jwe.decrypt(new AESDecrypter(jwk));
return "JWT".equals(jwe.getPayload().toString());
});
} catch (NoSuchAlgorithmException e) {
fail(e.getMessage());
}
}
use of io.gravitee.am.model.jose.OCTKey in project gravitee-access-management by gravitee-io.
the class JWEDirectTest method encryptIdToken_wronkKeySize.
@Test
public void encryptIdToken_wronkKeySize() {
byte[] secretKey = new byte[(EncryptionMethod.parse(this.enc).cekBitLength() / 8) - 8];
new SecureRandom().nextBytes(secretKey);
// Convert to JWK format
OctetSequenceKey jwk = new OctetSequenceKey.Builder(secretKey).build();
OCTKey key = new OCTKey();
key.setKid("octEnc");
key.setUse("enc");
key.setK(jwk.getKeyValue().toString());
Client client = new Client();
client.setIdTokenEncryptedResponseAlg("dir");
client.setIdTokenEncryptedResponseEnc(this.enc);
when(jwkService.getKeys(client)).thenReturn(Maybe.just(new JWKSet()));
when(jwkService.filter(any(), any())).thenReturn(Maybe.just(key));
TestObserver testObserver = jweService.encryptIdToken("JWT", client).test();
testObserver.assertError(ServerErrorException.class);
testObserver.assertNotComplete();
}
Aggregations