Search in sources :

Example 1 with X25519Decrypter

use of com.nimbusds.jose.crypto.X25519Decrypter in project gravitee-access-management by gravitee-io.

the class JWEEdwardCurveTest method encryptIdToken.

@Test
public void encryptIdToken() {
    try {
        final OctetKeyPair jwk = new OctetKeyPairGenerator(Curve.X25519).generate();
        OKPKey key = new OKPKey();
        key.setKid("okpEnc");
        key.setUse("enc");
        key.setCrv(jwk.getCurve().getName());
        key.setX(jwk.getX().toString());
        Client client = new Client();
        client.setIdTokenEncryptedResponseAlg(alg);
        client.setIdTokenEncryptedResponseEnc(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 -> {
            try {
                JWEObject jwe = JWEObject.parse((String) jweString);
                jwe.decrypt(new X25519Decrypter(jwk));
                return "JWT".equals(jwe.getPayload().toString());
            } catch (JOSEException e) {
                fail(e.getMessage());
            }
            return false;
        });
    } catch (JOSEException e) {
        fail(e.getMessage());
    }
}
Also used : X25519Decrypter(com.nimbusds.jose.crypto.X25519Decrypter) OctetKeyPair(com.nimbusds.jose.jwk.OctetKeyPair) JWEObject(com.nimbusds.jose.JWEObject) JWKSet(io.gravitee.am.model.oidc.JWKSet) Client(io.gravitee.am.model.oidc.Client) JOSEException(com.nimbusds.jose.JOSEException) OKPKey(io.gravitee.am.model.jose.OKPKey) TestObserver(io.reactivex.observers.TestObserver) OctetKeyPairGenerator(com.nimbusds.jose.jwk.gen.OctetKeyPairGenerator) Test(org.junit.Test)

Example 2 with X25519Decrypter

use of com.nimbusds.jose.crypto.X25519Decrypter in project gravitee-access-management by gravitee-io.

the class JWEEdwardCurveTest method encryptUserinfo.

@Test
public void encryptUserinfo() {
    try {
        final OctetKeyPair jwk = new OctetKeyPairGenerator(Curve.X25519).generate();
        OKPKey key = new OKPKey();
        key.setKid("okpEnc");
        key.setUse("enc");
        key.setCrv(jwk.getCurve().getName());
        key.setX(jwk.getX().toString());
        Client client = new Client();
        client.setUserinfoEncryptedResponseAlg(alg);
        client.setUserinfoEncryptedResponseEnc(enc);
        when(jwkService.getKeys(client)).thenReturn(Maybe.just(new JWKSet()));
        when(jwkService.filter(any(), any())).thenReturn(Maybe.just(key));
        TestObserver testObserver = jweService.encryptUserinfo("JWT", client).test();
        testObserver.assertNoErrors();
        testObserver.assertComplete();
        testObserver.assertValue(jweString -> {
            try {
                JWEObject jwe = JWEObject.parse((String) jweString);
                jwe.decrypt(new X25519Decrypter(jwk));
                return "JWT".equals(jwe.getPayload().toString());
            } catch (JOSEException e) {
                fail(e.getMessage());
            }
            return false;
        });
    } catch (JOSEException e) {
        fail(e.getMessage());
    }
}
Also used : X25519Decrypter(com.nimbusds.jose.crypto.X25519Decrypter) OctetKeyPair(com.nimbusds.jose.jwk.OctetKeyPair) JWEObject(com.nimbusds.jose.JWEObject) JWKSet(io.gravitee.am.model.oidc.JWKSet) Client(io.gravitee.am.model.oidc.Client) JOSEException(com.nimbusds.jose.JOSEException) OKPKey(io.gravitee.am.model.jose.OKPKey) TestObserver(io.reactivex.observers.TestObserver) OctetKeyPairGenerator(com.nimbusds.jose.jwk.gen.OctetKeyPairGenerator) Test(org.junit.Test)

Aggregations

JOSEException (com.nimbusds.jose.JOSEException)2 JWEObject (com.nimbusds.jose.JWEObject)2 X25519Decrypter (com.nimbusds.jose.crypto.X25519Decrypter)2 OctetKeyPair (com.nimbusds.jose.jwk.OctetKeyPair)2 OctetKeyPairGenerator (com.nimbusds.jose.jwk.gen.OctetKeyPairGenerator)2 OKPKey (io.gravitee.am.model.jose.OKPKey)2 Client (io.gravitee.am.model.oidc.Client)2 JWKSet (io.gravitee.am.model.oidc.JWKSet)2 TestObserver (io.reactivex.observers.TestObserver)2 Test (org.junit.Test)2