use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSABouncyCastleProviderTests method shouldFailECDSA256VerificationWhenProvidedPublicKeyIsNull.
@Test
public void shouldFailECDSA256VerificationWhenProvidedPublicKeyIsNull() {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA256withECDSA");
exception.expectCause(isA(IllegalStateException.class));
exception.expectCause(hasMessage(is("The given Public Key is null.")));
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
when(provider.getPublicKeyById("my-key-id")).thenReturn(null);
String jwt = "eyJhbGciOiJFUzI1NiIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.D_oU4CB0ZEsxHOjcWnmS3ZJvlTzm6WcGFx-HASxnvcB2Xu2WjI-axqXH9xKq45aPBDs330JpRhJmqBSc2K8MXQ";
Algorithm algorithm = Algorithm.ECDSA256(provider);
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class AlgorithmTest method shouldThrowECDSA512InstanceWithNullKeyProvider.
@Test
public void shouldThrowECDSA512InstanceWithNullKeyProvider() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("The Key Provider cannot be null.");
ECDSAKeyProvider provider = null;
Algorithm.ECDSA512(provider);
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldThrowOnSignWhenTheSignatureIsNotPrepared.
@Test
public void shouldThrowOnSignWhenTheSignatureIsNotPrepared() throws Exception {
exception.expect(SignatureGenerationException.class);
exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: some-algorithm");
exception.expectCause(isA(SignatureException.class));
CryptoHelper crypto = mock(CryptoHelper.class);
when(crypto.createSignatureFor(anyString(), any(PrivateKey.class), any(byte[].class), any(byte[].class))).thenThrow(SignatureException.class);
ECPublicKey publicKey = mock(ECPublicKey.class);
ECPrivateKey privateKey = mock(ECPrivateKey.class);
ECDSAKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey);
Algorithm algorithm = new ECDSAAlgorithm(crypto, "some-alg", "some-algorithm", 32, provider);
algorithm.sign(ES256HeaderBytes, new byte[0]);
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldThrowOnVerifyWhenSignatureAlgorithmDoesNotExists.
@Test
public void shouldThrowOnVerifyWhenSignatureAlgorithmDoesNotExists() throws Exception {
exception.expect(SignatureVerificationException.class);
exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: some-alg");
exception.expectCause(isA(NoSuchAlgorithmException.class));
CryptoHelper crypto = mock(CryptoHelper.class);
when(crypto.verifySignatureFor(anyString(), any(PublicKey.class), any(String.class), any(String.class), any(byte[].class))).thenThrow(NoSuchAlgorithmException.class);
ECPublicKey publicKey = mock(ECPublicKey.class);
when(publicKey.getParams()).thenReturn(mock(ECParameterSpec.class));
byte[] a = new byte[64];
Arrays.fill(a, Byte.MAX_VALUE);
when(publicKey.getParams().getOrder()).thenReturn(new BigInteger(a));
ECPrivateKey privateKey = mock(ECPrivateKey.class);
ECDSAKeyProvider provider = ECDSAAlgorithm.providerForKeys(publicKey, privateKey);
Algorithm algorithm = new ECDSAAlgorithm(crypto, "some-alg", "some-algorithm", 32, provider);
String jwt = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
algorithm.verify(JWT.decode(jwt));
}
use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.
the class ECDSAAlgorithmTest method shouldFailOnECDSA256SigningWithDeprecatedMethodWhenProvidedPrivateKeyIsNull.
/**
* Test deprecated signing method error handling.
*
* @see {@linkplain #shouldFailOnECDSA256SigningWhenProvidedPrivateKeyIsNull}
* @throws Exception expected exception
*/
@Test
public void shouldFailOnECDSA256SigningWithDeprecatedMethodWhenProvidedPrivateKeyIsNull() {
exception.expect(SignatureGenerationException.class);
exception.expectMessage("The Token's Signature couldn't be generated when signing using the Algorithm: SHA256withECDSA");
exception.expectCause(isA(IllegalStateException.class));
exception.expectCause(hasMessage(is("The given Private Key is null.")));
ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
when(provider.getPrivateKey()).thenReturn(null);
Algorithm algorithm = Algorithm.ECDSA256(provider);
algorithm.sign(new byte[0]);
}
Aggregations