Search in sources :

Example 71 with Jwe

use of io.jans.as.model.jwe.Jwe in project jans by JanssenProject.

the class EncodeClaimsInStateParameter method encodeClaimsInStateParameterAlgA128KWEncA128GCM.

@Parameters({ "userId", "userSecret", "redirectUris", "redirectUri", "sectorIdentifierUri" })
@Test
public void encodeClaimsInStateParameterAlgA128KWEncA128GCM(final String userId, final String userSecret, final String redirectUris, final String redirectUri, final String sectorIdentifierUri) throws Exception {
    showTitle("encodeClaimsInStateParameterAlgA128KWEncA128GCM");
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN);
    // 1. Register client
    RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "jans test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setResponseTypes(responseTypes);
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    RegisterResponse registerResponse = registerClient.exec();
    showClient(registerClient);
    assertRegisterResponseOk(registerResponse, 201, true);
    String clientId = registerResponse.getClientId();
    String clientSecret = registerResponse.getClientSecret();
    // 2. Request authorization
    List<String> scopes = Arrays.asList("openid", "profile", "address", "email");
    String nonce = UUID.randomUUID().toString();
    String rfp = UUID.randomUUID().toString();
    String jti = UUID.randomUUID().toString();
    JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.A128KW, BlockEncryptionAlgorithm.A128GCM, clientSecret);
    jwtState.setRfp(rfp);
    jwtState.setJti(jti);
    jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
    String encodedState = jwtState.getEncodedJwt();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
    authorizationRequest.setState(encodedState);
    AuthorizationResponse authorizationResponse = authenticateResourceOwnerAndGrantAccess(authorizationEndpoint, authorizationRequest, userId, userSecret);
    assertAuthorizationResponse(authorizationResponse, responseTypes, true);
    String state = authorizationResponse.getState();
    // 3. Decrypt state
    Jwe jwe = Jwe.parse(state, null, clientSecret.getBytes());
    assertNotNull(jwe.getClaims().getClaimAsString(RFP));
    assertNotNull(jwe.getClaims().getClaimAsString(JTI));
    assertNotNull(jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS));
    JSONObject addClaims = jwe.getClaims().getClaimAsJSON(ADDITIONAL_CLAIMS);
    assertEquals(addClaims.getString("first_name"), "Javier");
    assertEquals(addClaims.getString("last_name"), "Rojas");
    assertEquals(addClaims.getInt("age"), 34);
    assertNotNull(addClaims.getJSONArray("more"));
    assertEquals(addClaims.getJSONArray("more").length(), 2);
}
Also used : RegisterRequest(io.jans.as.client.RegisterRequest) RegisterResponse(io.jans.as.client.RegisterResponse) AuthorizationRequest(io.jans.as.client.AuthorizationRequest) JSONObject(org.json.JSONObject) RegisterClient(io.jans.as.client.RegisterClient) Jwe(io.jans.as.model.jwe.Jwe) JwtState(io.jans.as.client.model.JwtState) ResponseType(io.jans.as.model.common.ResponseType) AuthorizationResponse(io.jans.as.client.AuthorizationResponse) Asserter.assertAuthorizationResponse(io.jans.as.client.client.Asserter.assertAuthorizationResponse) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(io.jans.as.client.BaseTest)

Example 72 with Jwe

use of io.jans.as.model.jwe.Jwe in project jans by JanssenProject.

the class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest method ensureRequestObjectWithInvalidSignatureFails.

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// Enable FAPI to run this test!
@Test(enabled = false)
public void ensureRequestObjectWithInvalidSignatureFails(final String redirectUri, final String redirectUris, final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
    showTitle("ensureRequestObjectWithinvalidSignatureFails");
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
    List<GrantType> GrantTypes = Arrays.asList(GrantType.AUTHORIZATION_CODE);
    // 1. Dynamic Client Registration
    RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, GrantTypes, sectorIdentifierUri, clientJwksUri, SignatureAlgorithm.PS256, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM);
    String clientId = registerResponse.getClientId();
    // 2. Request authorization
    List<String> scope = Arrays.asList("openid", "profile", "address", "email");
    String state = UUID.randomUUID().toString();
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope, redirectUri, null);
    AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.PS256, cryptoProvider1);
    jwsAuthorizationRequest.setKeyId(signingKeyId);
    // Added bad aud to request object claims
    jwsAuthorizationRequest.setAud("https://www.other1.example.com/");
    jwsAuthorizationRequest.setRedirectUri(redirectUri);
    jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
    jwsAuthorizationRequest.setState(state);
    // FAPI: nonce param is required
    jwsAuthorizationRequest.setNonce(nonce);
    // FAPI: require the request object to
    jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
    // contain an exp claim that has a
    // lifetime of no longer than 60 minutes
    // after the nbf claim
    // FAPI: require the request object to
    jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
    // contain an exp claim that has a
    // lifetime of no longer than 60
    // minutes after the nbf claim
    Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());
    JwkClient jwkClient = new JwkClient(jwksUri);
    JwkResponse jwkResponse = jwkClient.exec();
    String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
    assertNotNull(serverKeyId);
    JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
    AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
    JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.PS256, cryptoProvider2);
    jweAuthorizationRequest.setKeyId(serverKeyId);
    jweAuthorizationRequest.setNestedPayload(authJws);
    jweAuthorizationRequest.setKeyId(signingKeyId);
    jweAuthorizationRequest.setResponseMode(ResponseMode.JWT);
    jweAuthorizationRequest.setState(state);
    jweAuthorizationRequest.setScopes(scope);
    jweAuthorizationRequest.setResponseTypes(responseTypes);
    jweAuthorizationRequest.setRedirectUri(redirectUri);
    // FAPI: nonce param is required
    jweAuthorizationRequest.setNonce(nonce);
    // FAPI: require the request object to
    jweAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
    // contain an exp claim that has a
    // lifetime of no longer than 60 minutes
    // after the nbf claim
    // Added invalid exp value to request
    jweAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
    // object which is 70 minutes in the
    // future
    String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);
    authorizationRequest.setRequest(authJwe + "wrongSignature");
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setRequest(authorizationRequest);
    AuthorizationResponse authorizationResponse = authorizeClient.exec();
    showClient(authorizeClient);
    assertNotNull(authorizationResponse.getResponse());
    Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
    assertJweResponse(response);
    assertEquals(response.getClaims().getClaimAsString("error"), "invalid_request_object");
    // Clear private key to do not affect to other tests
    privateKey = null;
}
Also used : JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwt(io.jans.as.model.jwt.Jwt) GrantType(io.jans.as.model.common.GrantType) AuthorizeErrorResponseType(io.jans.as.model.authorize.AuthorizeErrorResponseType) ResponseType(io.jans.as.model.common.ResponseType) JSONObject(org.json.JSONObject) JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwe(io.jans.as.model.jwe.Jwe) AuthCryptoProvider(io.jans.as.model.crypto.AuthCryptoProvider) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 73 with Jwe

use of io.jans.as.model.jwe.Jwe in project jans by JanssenProject.

the class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest method ensureSignedRequestObjectWithRS256Fails.

@Parameters({ "audience", "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "RS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// Enable FAPI to run this test!
@Test(enabled = false)
public void ensureSignedRequestObjectWithRS256Fails(final String audience, final String redirectUri, final String redirectUris, final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
    showTitle("ensureSignedRequestObjectWithRS256Fails");
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
    // 1. Dynamic Client Registration
    RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, sectorIdentifierUri, clientJwksUri, SignatureAlgorithm.RS256, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM);
    String clientId = registerResponse.getClientId();
    // 2. Request authorization
    List<String> scope = Arrays.asList("openid", "profile", "address", "email");
    String state = UUID.randomUUID().toString();
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope, redirectUri, null);
    AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    // RS256 Request Object is not permitted by the FAPI-RW specification.
    JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.RS256, cryptoProvider1);
    jwsAuthorizationRequest.setKeyId(signingKeyId);
    jwsAuthorizationRequest.setAud(audience);
    jwsAuthorizationRequest.setIss(clientId);
    jwsAuthorizationRequest.setScopes(scope);
    jwsAuthorizationRequest.setResponseTypes(responseTypes);
    jwsAuthorizationRequest.setRedirectUri(redirectUri);
    jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
    jwsAuthorizationRequest.setClientId(clientId);
    jwsAuthorizationRequest.setState(state);
    // FAPI: nonce param is required
    jwsAuthorizationRequest.setNonce(nonce);
    // FAPI: require the request object to contain an exp claim that has a lifetime of no longer than 60 minutes after the nbf claim
    jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
    // FAPI: require the request object to contain an exp claim that has a lifetime of no longer than 60 minutes after the nbf claim
    jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
    Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());
    JwkClient jwkClient = new JwkClient(jwksUri);
    JwkResponse jwkResponse = jwkClient.exec();
    String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
    assertNotNull(serverKeyId);
    JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
    AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
    JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM, cryptoProvider2);
    jweAuthorizationRequest.setKeyId(serverKeyId);
    jweAuthorizationRequest.setNestedPayload(authJws);
    String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);
    authorizationRequest.setRequest(authJwe);
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setRequest(authorizationRequest);
    AuthorizationResponse authorizationResponse = authorizeClient.exec();
    showClient(authorizeClient);
    assertNotNull(authorizationResponse.getResponse());
    Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
    assertJweResponse(response);
    // Clear private key to do not affect to other tests
    privateKey = null;
}
Also used : JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwt(io.jans.as.model.jwt.Jwt) AuthorizeErrorResponseType(io.jans.as.model.authorize.AuthorizeErrorResponseType) ResponseType(io.jans.as.model.common.ResponseType) JSONObject(org.json.JSONObject) JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwe(io.jans.as.model.jwe.Jwe) AuthCryptoProvider(io.jans.as.model.crypto.AuthCryptoProvider) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 74 with Jwe

use of io.jans.as.model.jwe.Jwe in project jans by JanssenProject.

the class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest method ensureRequestObjectWithoutEncryptionFails.

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// Enable FAPI to run this test!
@Test(enabled = false)
public void ensureRequestObjectWithoutEncryptionFails(final String redirectUri, final String redirectUris, final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
    showTitle("ensureRequestObjectWithoutEncryptionFails");
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
    List<GrantType> GrantTypes = Arrays.asList(GrantType.AUTHORIZATION_CODE);
    // 1. Dynamic Client Registration
    RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, GrantTypes, sectorIdentifierUri, clientJwksUri, SignatureAlgorithm.PS256, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM);
    String clientId = registerResponse.getClientId();
    // 2. Request authorization
    List<String> scope = Arrays.asList("openid", "profile", "address", "email");
    String state = UUID.randomUUID().toString();
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope, redirectUri, null);
    AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.PS256, cryptoProvider1);
    jwsAuthorizationRequest.setKeyId(signingKeyId);
    // Added bad aud to request object claims
    jwsAuthorizationRequest.setAud("https://www.other1.example.com/");
    jwsAuthorizationRequest.setRedirectUri(redirectUri);
    jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
    jwsAuthorizationRequest.setState(state);
    // FAPI: nonce param is required
    jwsAuthorizationRequest.setNonce(nonce);
    // FAPI: require the request object to
    jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
    // contain an exp claim that has a
    // lifetime of no longer than 60 minutes
    // after the nbf claim
    // FAPI: require the request object to
    jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
    // contain an exp claim that has a
    // lifetime of no longer than 60
    // minutes after the nbf claim
    Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());
    JwkClient jwkClient = new JwkClient(jwksUri);
    JwkResponse jwkResponse = jwkClient.exec();
    String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
    assertNotNull(serverKeyId);
    JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
    AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
    JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.PS256, cryptoProvider2);
    jweAuthorizationRequest.setKeyId(serverKeyId);
    jweAuthorizationRequest.setNestedPayload(authJws);
    jweAuthorizationRequest.setKeyId(signingKeyId);
    jweAuthorizationRequest.setResponseMode(ResponseMode.JWT);
    jweAuthorizationRequest.setState(state);
    jweAuthorizationRequest.setScopes(scope);
    jweAuthorizationRequest.setResponseTypes(responseTypes);
    jweAuthorizationRequest.setRedirectUri(redirectUri);
    // FAPI: nonce param is required
    jweAuthorizationRequest.setNonce(nonce);
    // FAPI: require the request object to
    jweAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
    // contain an exp claim that has a
    // lifetime of no longer than 60 minutes
    // after the nbf claim
    // Added invalid exp value to request
    jweAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 3600);
    // object which is 70 minutes in the
    // future
    String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);
    authorizationRequest.setRequest(authJwe);
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setRequest(authorizationRequest);
    AuthorizationResponse authorizationResponse = authorizeClient.exec();
    showClient(authorizeClient);
    assertNotNull(authorizationResponse.getResponse());
    Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
    assertJweResponse(response);
    assertEquals(response.getClaims().getClaimAsString("error"), "invalid_request_object");
    // Clear private key to do not affect to other tests
    privateKey = null;
}
Also used : JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwt(io.jans.as.model.jwt.Jwt) GrantType(io.jans.as.model.common.GrantType) AuthorizeErrorResponseType(io.jans.as.model.authorize.AuthorizeErrorResponseType) ResponseType(io.jans.as.model.common.ResponseType) JSONObject(org.json.JSONObject) JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwe(io.jans.as.model.jwe.Jwe) AuthCryptoProvider(io.jans.as.model.crypto.AuthCryptoProvider) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 75 with Jwe

use of io.jans.as.model.jwe.Jwe in project jans by JanssenProject.

the class AuthorizationResponseModeJwtResponseTypeCodeSignedEncryptedHttpTest method ensureRequestObjectWithExpOver60Fails.

@Parameters({ "redirectUri", "redirectUris", "clientJwksUri", "RSA_OAEP_keyId", "PS256_keyId", "dnName", "keyStoreFile", "keyStoreSecret", "sectorIdentifierUri" })
// Enable FAPI to run this test!
@Test(enabled = false)
public void ensureRequestObjectWithExpOver60Fails(final String redirectUri, final String redirectUris, final String clientJwksUri, final String encryptionKeyId, final String signingKeyId, final String dnName, final String keyStoreFile, final String keyStoreSecret, final String sectorIdentifierUri) throws Exception {
    showTitle("ensureRequestObjectWithExpOver60Fails");
    List<ResponseType> responseTypes = Arrays.asList(ResponseType.CODE);
    // 1. Dynamic Client Registration
    RegisterResponse registerResponse = registerClient(redirectUris, responseTypes, sectorIdentifierUri, clientJwksUri, SignatureAlgorithm.PS256, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM);
    String clientId = registerResponse.getClientId();
    // 2. Request authorization
    List<String> scope = Arrays.asList("openid", "profile", "address", "email");
    String state = UUID.randomUUID().toString();
    String nonce = UUID.randomUUID().toString();
    AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scope, redirectUri, null);
    AuthCryptoProvider cryptoProvider1 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    JwtAuthorizationRequest jwsAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.PS256, cryptoProvider1);
    jwsAuthorizationRequest.setKeyId(signingKeyId);
    jwsAuthorizationRequest.setRedirectUri(redirectUri);
    jwsAuthorizationRequest.setResponseMode(ResponseMode.JWT);
    jwsAuthorizationRequest.setState(state);
    // FAPI: nonce param is required
    jwsAuthorizationRequest.setNonce(nonce);
    // FAPI: require the request object to contain an exp claim that has a lifetime of no longer than 60 minutes after the nbf claim
    jwsAuthorizationRequest.setNbf((int) Instant.now().getEpochSecond());
    // Added invalid exp value to request object which is 70 minutes in the future
    jwsAuthorizationRequest.setExp(jwsAuthorizationRequest.getNbf() + 4200);
    Jwt authJws = Jwt.parse(jwsAuthorizationRequest.getEncodedJwt());
    JwkClient jwkClient = new JwkClient(jwksUri);
    JwkResponse jwkResponse = jwkClient.exec();
    String serverKeyId = jwkResponse.getKeyId(Algorithm.RSA_OAEP);
    assertNotNull(serverKeyId);
    JSONObject jwks = JwtUtil.getJSONWebKeys(jwksUri);
    AuthCryptoProvider cryptoProvider2 = new AuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    privateKey = cryptoProvider2.getPrivateKey(encryptionKeyId);
    JwtAuthorizationRequest jweAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM, cryptoProvider2);
    jweAuthorizationRequest.setKeyId(serverKeyId);
    jweAuthorizationRequest.setNestedPayload(authJws);
    String authJwe = jweAuthorizationRequest.getEncodedJwt(jwks);
    authorizationRequest.setRequest(authJwe);
    AuthorizeClient authorizeClient = new AuthorizeClient(authorizationEndpoint);
    authorizeClient.setRequest(authorizationRequest);
    AuthorizationResponse authorizationResponse = authorizeClient.exec();
    showClient(authorizeClient);
    assertNotNull(authorizationResponse.getResponse());
    Jwe response = Jwe.parse(authorizationResponse.getResponse(), privateKey, null);
    assertJweResponse(response);
    assertEquals(response.getClaims().getClaimAsString("error"), "invalid_request_object");
    // Clear private key to do not affect to other tests
    privateKey = null;
}
Also used : JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwt(io.jans.as.model.jwt.Jwt) AuthorizeErrorResponseType(io.jans.as.model.authorize.AuthorizeErrorResponseType) ResponseType(io.jans.as.model.common.ResponseType) JSONObject(org.json.JSONObject) JwtAuthorizationRequest(io.jans.as.client.model.authorize.JwtAuthorizationRequest) Jwe(io.jans.as.model.jwe.Jwe) AuthCryptoProvider(io.jans.as.model.crypto.AuthCryptoProvider) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Aggregations

Jwe (io.jans.as.model.jwe.Jwe)83 Parameters (org.testng.annotations.Parameters)70 Test (org.testng.annotations.Test)68 ResponseType (io.jans.as.model.common.ResponseType)62 BaseTest (io.jans.as.client.BaseTest)51 RegisterClient (io.jans.as.client.RegisterClient)51 RegisterRequest (io.jans.as.client.RegisterRequest)51 RegisterResponse (io.jans.as.client.RegisterResponse)51 AuthCryptoProvider (io.jans.as.model.crypto.AuthCryptoProvider)50 AuthorizationRequest (io.jans.as.client.AuthorizationRequest)46 AuthorizationResponse (io.jans.as.client.AuthorizationResponse)46 JSONObject (org.json.JSONObject)40 AuthorizeClient (io.jans.as.client.AuthorizeClient)36 JwtAuthorizationRequest (io.jans.as.client.model.authorize.JwtAuthorizationRequest)36 PrivateKey (java.security.PrivateKey)35 UserInfoClient (io.jans.as.client.UserInfoClient)20 UserInfoResponse (io.jans.as.client.UserInfoResponse)20 Jwt (io.jans.as.model.jwt.Jwt)20 AuthorizeErrorResponseType (io.jans.as.model.authorize.AuthorizeErrorResponseType)16 UserInfoRequest (io.jans.as.client.UserInfoRequest)15