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."));
}
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);
}
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, "");
}
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."));
}
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."));
}
Aggregations