Search in sources :

Example 16 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class RedirectUriTest method getQueryString_withEncriptionAlgorithmRSAAndSignatureAlgorithm_responseEncoded.

@Test
public void getQueryString_withEncriptionAlgorithmRSAAndSignatureAlgorithm_responseEncoded() throws UnsupportedEncodingException, CryptoProviderException, NoSuchAlgorithmException, InvalidKeySpecException {
    RedirectUri redirectUri = getRedirectUriTemplateGetQueryString(ResponseMode.JWT, KeyEncryptionAlgorithm.RSA1_5, BlockEncryptionAlgorithm.A256GCM, SignatureAlgorithm.HS256);
    AbstractCryptoProvider cryptoProvider = mock(AbstractCryptoProvider.class);
    when(cryptoProvider.getPublicKey(anyString(), any(), any())).thenReturn(getRSAPublicKey());
    when(cryptoProvider.sign(anyString(), anyString(), anyString(), any())).thenReturn("12345");
    redirectUri.setCryptoProvider(cryptoProvider);
    redirectUri.setNestedKeyId("nestedKey123");
    redirectUri.setNestedSharedSecret("nested_shared_secret");
    String queryResult = redirectUri.getQueryString();
    System.out.println(queryResult);
    assertNoEmptyQueryString(queryResult, RESPONSE, 1);
    assertTrue(queryResult.startsWith("response=eyJjdHkiOiJqd3QiLCJ0eXAiOiJqd3QiLCJlbmMiOiJBMjU2R0NNIiwiYWxnIjoiUlNBMV81In0."));
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 17 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class RedirectUriTest method toString_withResponseModeJwtAndresponseTypeToken_validURLFragmentString.

@Test
public void toString_withResponseModeJwtAndresponseTypeToken_validURLFragmentString() throws CryptoProviderException {
    String valTestCase = "http://redirecturl.com/#response=eyJraWQiOiJrZXkxMjMiLCJ0eXAiOiJqd3QiLCJhbGciOiJSUzI1NiJ9.eyJleHAiOiIxNjQ0MjcwNDczMzAxIiwiZXhwaXJlc19pbiI6IjE2NDQyNzA0NzMzMDEiLCJjbGllbnRfaWQiOiIxMjMifQ.12345";
    List<ResponseType> typeList = new ArrayList<>();
    typeList.add(ResponseType.TOKEN);
    RedirectUri redirectUri = new RedirectUri("http://redirecturl.com/", typeList, ResponseMode.JWT);
    redirectUri.addResponseParameter(CLIENT_ID, "123");
    redirectUri.addResponseParameter(EXPIRES_IN, "1644270473301");
    redirectUri.setKeyId("key123");
    redirectUri.setSharedSecret("shared_secret");
    redirectUri.setNestedSharedSecret("nested_shared_secret");
    AbstractCryptoProvider cryptoProvider = mock(AbstractCryptoProvider.class);
    when(cryptoProvider.sign(anyString(), anyString(), anyString(), any(SignatureAlgorithm.class))).thenReturn("12345");
    redirectUri.setCryptoProvider(cryptoProvider);
    assertEquals(redirectUri.toString(), valTestCase);
}
Also used : ArrayList(java.util.ArrayList) AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) SignatureAlgorithm(io.jans.as.model.crypto.signature.SignatureAlgorithm) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResponseType(io.jans.as.model.common.ResponseType) Test(org.testng.annotations.Test)

Example 18 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class RedirectUriTest method getQueryString_withEncriptionAlgorithm128PublicKeyInvalid_responseEmptyThrowInvalid.

@Test
public void getQueryString_withEncriptionAlgorithm128PublicKeyInvalid_responseEmptyThrowInvalid() throws CryptoProviderException {
    RedirectUri redirectUri = getRedirectUriTemplateGetQueryString(ResponseMode.JWT, KeyEncryptionAlgorithm.RSA1_5, BlockEncryptionAlgorithm.A256GCM, null);
    AbstractCryptoProvider cryptoProvider = mock(AbstractCryptoProvider.class);
    when(cryptoProvider.getPublicKey(anyString(), any(), any())).thenReturn(null);
    redirectUri.setCryptoProvider(cryptoProvider);
    String queryResult = redirectUri.getQueryString();
    System.out.println(queryResult);
    assertEquals(queryResult, "");
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 19 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class RedirectUriTest method getQueryString_withEncriptionAlgorithm128KWAndSignatureAlgorithm_responseEncoded.

@Test
public void getQueryString_withEncriptionAlgorithm128KWAndSignatureAlgorithm_responseEncoded() throws UnsupportedEncodingException, CryptoProviderException {
    RedirectUri redirectUri = getRedirectUriTemplateGetQueryString(ResponseMode.JWT, KeyEncryptionAlgorithm.A128KW, BlockEncryptionAlgorithm.A128GCM, SignatureAlgorithm.HS256);
    AbstractCryptoProvider cryptoProvider = mock(AbstractCryptoProvider.class);
    when(cryptoProvider.sign(anyString(), anyString(), anyString(), any(SignatureAlgorithm.class))).thenReturn("12345");
    redirectUri.setCryptoProvider(cryptoProvider);
    redirectUri.setNestedKeyId("nestedKey123");
    redirectUri.setNestedSharedSecret("nested_shared_secret");
    redirectUri.setSharedSymmetricKey("0123456789012345".getBytes());
    redirectUri.addResponseParameter(EXPIRES_IN, "1644270473301");
    String queryResult = redirectUri.getQueryString();
    System.out.println(queryResult);
    assertNoEmptyQueryString(queryResult, RESPONSE, 1);
    assertTrue(queryResult.startsWith("response=eyJjdHkiOiJqd3QiLCJ0eXAiOiJqd3QiLCJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiQTEyOEtXIn0."));
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) SignatureAlgorithm(io.jans.as.model.crypto.signature.SignatureAlgorithm) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Example 20 with AbstractCryptoProvider

use of io.jans.as.model.crypto.AbstractCryptoProvider in project jans by JanssenProject.

the class RedirectUriTest method getQueryString_noEncriptionAlgorithmNoSignatureAlgorithm_responseEncoded.

@Test
public void getQueryString_noEncriptionAlgorithmNoSignatureAlgorithm_responseEncoded() throws UnsupportedEncodingException, CryptoProviderException {
    RedirectUri redirectUri = getRedirectUriTemplateGetQueryString(ResponseMode.JWT, null, null, null);
    AbstractCryptoProvider cryptoProvider = mock(AbstractCryptoProvider.class);
    when(cryptoProvider.sign(anyString(), anyString(), anyString(), any(SignatureAlgorithm.class))).thenReturn("12345");
    redirectUri.setCryptoProvider(cryptoProvider);
    String queryResult = redirectUri.getQueryString();
    System.out.println(queryResult);
    assertNoEmptyQueryString(queryResult, RESPONSE, 1);
    assertTrue(queryResult.startsWith("response=eyJraWQiOiJrZXkxMjMiLCJ0eXAiOiJqd3QiLCJhbGciOiJSUzI1NiJ9."));
}
Also used : AbstractCryptoProvider(io.jans.as.model.crypto.AbstractCryptoProvider) SignatureAlgorithm(io.jans.as.model.crypto.signature.SignatureAlgorithm) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.testng.annotations.Test)

Aggregations

AbstractCryptoProvider (io.jans.as.model.crypto.AbstractCryptoProvider)23 Test (org.testng.annotations.Test)17 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)10 ResponseType (io.jans.as.model.common.ResponseType)7 BaseTest (io.jans.as.client.BaseTest)6 SignatureAlgorithm (io.jans.as.model.crypto.signature.SignatureAlgorithm)6 Jwt (io.jans.as.model.jwt.Jwt)6 AuthorizationRequest (io.jans.as.client.AuthorizationRequest)5 AuthorizationResponse (io.jans.as.client.AuthorizationResponse)5 RegisterClient (io.jans.as.client.RegisterClient)5 RegisterRequest (io.jans.as.client.RegisterRequest)5 RegisterResponse (io.jans.as.client.RegisterResponse)5 Parameters (org.testng.annotations.Parameters)5 UserInfoClient (io.jans.as.client.UserInfoClient)4 UserInfoResponse (io.jans.as.client.UserInfoResponse)4 Claim (io.jans.as.client.model.authorize.Claim)4 JwtAuthorizationRequest (io.jans.as.client.model.authorize.JwtAuthorizationRequest)4 PlainTextSignature (io.jans.as.model.jws.PlainTextSignature)3 ArrayList (java.util.ArrayList)3 JSONObject (org.json.JSONObject)3