Search in sources :

Example 16 with JwtState

use of org.gluu.oxauth.client.model.JwtState in project oxAuth by GluuFederation.

the class EncodeClaimsInStateParameter method jwtStateAlgA128KWEncA128GCMTest.

@Test
public void jwtStateAlgA128KWEncA128GCMTest() throws Exception {
    showTitle("jwtStateAlgA128KWEncA128GCMTest");
    String sharedKey = "shared_key";
    String rfp = UUID.randomUUID().toString();
    String jti = UUID.randomUUID().toString();
    JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.A128KW, BlockEncryptionAlgorithm.A128GCM, sharedKey);
    jwtState.setRfp(rfp);
    jwtState.setJti(jti);
    jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
    String encodedState = jwtState.getEncodedJwt();
    assertNotNull(encodedState);
    System.out.println("Encrypted JWE State: " + encodedState);
    Jwe jwe = Jwe.parse(encodedState, null, sharedKey.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 : JSONObject(org.json.JSONObject) Jwe(org.gluu.oxauth.model.jwe.Jwe) JwtState(org.gluu.oxauth.client.model.JwtState) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 17 with JwtState

use of org.gluu.oxauth.client.model.JwtState in project oxAuth by GluuFederation.

the class EncodeClaimsInStateParameter method jwtStatePS512Test.

@Parameters({ "keyStoreFile", "keyStoreSecret", "dnName", "PS512_keyId" })
@Test
public void jwtStatePS512Test(final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId) throws Exception {
    showTitle("jwtStatePS512Test");
    OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    String rfp = UUID.randomUUID().toString();
    String jti = UUID.randomUUID().toString();
    JwtState jwtState = new JwtState(SignatureAlgorithm.PS512, cryptoProvider);
    jwtState.setKeyId(keyId);
    jwtState.setRfp(rfp);
    jwtState.setJti(jti);
    jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
    String encodedState = jwtState.getEncodedJwt();
    assertNotNull(encodedState);
    System.out.println("Signed JWS State: " + encodedState);
    Jwt jwt = Jwt.parse(encodedState);
    boolean validJwt = cryptoProvider.verifySignature(jwt.getSigningInput(), jwt.getEncodedSignature(), keyId, null, null, SignatureAlgorithm.PS512);
    assertTrue(validJwt);
}
Also used : OxAuthCryptoProvider(org.gluu.oxauth.model.crypto.OxAuthCryptoProvider) JSONObject(org.json.JSONObject) Jwt(org.gluu.oxauth.model.jwt.Jwt) JwtState(org.gluu.oxauth.client.model.JwtState) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 18 with JwtState

use of org.gluu.oxauth.client.model.JwtState in project oxAuth by GluuFederation.

the class EncodeClaimsInStateParameter method jwtStateAlgRSAOAEPEncA256GCMTest.

@Parameters({ "keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId", "clientJwksUri" })
@Test
public void jwtStateAlgRSAOAEPEncA256GCMTest(final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId, final String clientJwksUri) throws Exception {
    showTitle("jwtStateAlgRSAOAEPEncA256GCMTest");
    JSONObject jwks = JwtUtil.getJSONWebKeys(clientJwksUri);
    OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    String rfp = UUID.randomUUID().toString();
    String jti = UUID.randomUUID().toString();
    JwtState jwtState = new JwtState(KeyEncryptionAlgorithm.RSA_OAEP, BlockEncryptionAlgorithm.A256GCM, cryptoProvider);
    jwtState.setKeyId(keyId);
    jwtState.setRfp(rfp);
    jwtState.setJti(jti);
    jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
    String encodedState = jwtState.getEncodedJwt(jwks);
    assertNotNull(encodedState);
    System.out.println("Encrypted JWE State: " + encodedState);
    PrivateKey privateKey = cryptoProvider.getPrivateKey(keyId);
    Jwe jwe = Jwe.parse(encodedState, privateKey, null);
    assertNotNull(jwe.getClaims().getClaimAsString(KID));
    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 : OxAuthCryptoProvider(org.gluu.oxauth.model.crypto.OxAuthCryptoProvider) PrivateKey(java.security.PrivateKey) JSONObject(org.json.JSONObject) Jwe(org.gluu.oxauth.model.jwe.Jwe) JwtState(org.gluu.oxauth.client.model.JwtState) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 19 with JwtState

use of org.gluu.oxauth.client.model.JwtState in project oxAuth by GluuFederation.

the class EncodeClaimsInStateParameter method jwtStateES384Test.

@Parameters({ "keyStoreFile", "keyStoreSecret", "dnName", "ES384_keyId" })
@Test
public void jwtStateES384Test(final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId) throws Exception {
    showTitle("jwtStateES384Test");
    OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    String rfp = UUID.randomUUID().toString();
    String jti = UUID.randomUUID().toString();
    JwtState jwtState = new JwtState(SignatureAlgorithm.ES384, cryptoProvider);
    jwtState.setKeyId(keyId);
    jwtState.setRfp(rfp);
    jwtState.setJti(jti);
    jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
    String encodedState = jwtState.getEncodedJwt();
    assertNotNull(encodedState);
    System.out.println("Signed JWS State: " + encodedState);
    Jwt jwt = Jwt.parse(encodedState);
    boolean validJwt = cryptoProvider.verifySignature(jwt.getSigningInput(), jwt.getEncodedSignature(), keyId, null, null, SignatureAlgorithm.ES384);
    assertTrue(validJwt);
}
Also used : OxAuthCryptoProvider(org.gluu.oxauth.model.crypto.OxAuthCryptoProvider) JSONObject(org.json.JSONObject) Jwt(org.gluu.oxauth.model.jwt.Jwt) JwtState(org.gluu.oxauth.client.model.JwtState) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 20 with JwtState

use of org.gluu.oxauth.client.model.JwtState in project oxAuth by GluuFederation.

the class EncodeClaimsInStateParameter method jwtStateRS256Test.

@Parameters({ "keyStoreFile", "keyStoreSecret", "dnName", "RS256_keyId" })
@Test
public void jwtStateRS256Test(final String keyStoreFile, final String keyStoreSecret, final String dnName, final String keyId) throws Exception {
    showTitle("jwtStateRS256Test");
    OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider(keyStoreFile, keyStoreSecret, dnName);
    String rfp = UUID.randomUUID().toString();
    String jti = UUID.randomUUID().toString();
    JwtState jwtState = new JwtState(SignatureAlgorithm.RS256, cryptoProvider);
    jwtState.setKeyId(keyId);
    jwtState.setRfp(rfp);
    jwtState.setJti(jti);
    jwtState.setAdditionalClaims(new JSONObject(additionalClaims));
    String encodedState = jwtState.getEncodedJwt();
    assertNotNull(encodedState);
    System.out.println("Signed JWS State: " + encodedState);
    Jwt jwt = Jwt.parse(encodedState);
    boolean validJwt = cryptoProvider.verifySignature(jwt.getSigningInput(), jwt.getEncodedSignature(), keyId, null, null, SignatureAlgorithm.RS256);
    assertTrue(validJwt);
}
Also used : OxAuthCryptoProvider(org.gluu.oxauth.model.crypto.OxAuthCryptoProvider) JSONObject(org.json.JSONObject) Jwt(org.gluu.oxauth.model.jwt.Jwt) JwtState(org.gluu.oxauth.client.model.JwtState) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Aggregations

BaseTest (org.gluu.oxauth.BaseTest)35 JwtState (org.gluu.oxauth.client.model.JwtState)35 JSONObject (org.json.JSONObject)35 Test (org.testng.annotations.Test)35 OxAuthCryptoProvider (org.gluu.oxauth.model.crypto.OxAuthCryptoProvider)30 Parameters (org.testng.annotations.Parameters)29 Jwt (org.gluu.oxauth.model.jwt.Jwt)25 AuthorizationRequest (org.gluu.oxauth.client.AuthorizationRequest)17 AuthorizationResponse (org.gluu.oxauth.client.AuthorizationResponse)17 RegisterClient (org.gluu.oxauth.client.RegisterClient)17 RegisterRequest (org.gluu.oxauth.client.RegisterRequest)17 RegisterResponse (org.gluu.oxauth.client.RegisterResponse)17 ResponseType (org.gluu.oxauth.model.common.ResponseType)17 Jwe (org.gluu.oxauth.model.jwe.Jwe)10 PrivateKey (java.security.PrivateKey)6 AbstractCryptoProvider (org.gluu.oxauth.model.crypto.AbstractCryptoProvider)1