Search in sources :

Example 1 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSAAlgorithmTest method shouldPassECDSA256KVerificationWithProvidedPublicKey.

@Test
public void shouldPassECDSA256KVerificationWithProvidedPublicKey() throws Exception {
    ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_256K, "EC");
    when(provider.getPublicKeyById("my-key-id")).thenReturn((ECPublicKey) publicKey);
    Algorithm algorithm = Algorithm.ECDSA256K(provider);
    algorithm.verify(JWT.decode(ES256K_JWT));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ECPublicKey(java.security.interfaces.ECPublicKey) Test(org.junit.Test)

Example 2 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests method shouldPassECDSA256KVerificationWithProvidedPublicKey.

@Test
public void shouldPassECDSA256KVerificationWithProvidedPublicKey() throws Exception {
    ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_256K, "EC");
    when(provider.getPublicKeyById("my-key-id")).thenReturn((ECPublicKey) publicKey);
    Algorithm algorithm = Algorithm.ECDSA256K(provider);
    algorithm.verify(JWT.decode(ES256K_JWT));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ECPublicKey(java.security.interfaces.ECPublicKey) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Example 3 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests method shouldFailECDSA256KVerificationWhenProvidedPublicKeyIsNull.

@Test
public void shouldFailECDSA256KVerificationWhenProvidedPublicKeyIsNull() throws Exception {
    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);
    Algorithm algorithm = Algorithm.ECDSA256K(provider);
    algorithm.verify(JWT.decode(ES256K_JWT));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Example 4 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests method shouldPassECDSA384VerificationWithProvidedPublicKey.

@Test
public void shouldPassECDSA384VerificationWithProvidedPublicKey() throws Exception {
    ECDSAKeyProvider provider = mock(ECDSAKeyProvider.class);
    PublicKey publicKey = readPublicKeyFromFile(PUBLIC_KEY_FILE_384, "EC");
    when(provider.getPublicKeyById("my-key-id")).thenReturn((ECPublicKey) publicKey);
    String jwt = "eyJhbGciOiJFUzM4NCIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.9kjGuFTPx3ylfpqL0eY9H7TGmPepjQOBKI8UPoEvby6N7dDLF5HxLohosNxxFymNT7LzpeSgOPAB0wJEwG2Nl2ukgdUOpZOf492wog_i5ZcZmAykd3g1QH7onrzd69GU";
    Algorithm algorithm = Algorithm.ECDSA384(provider);
    algorithm.verify(JWT.decode(jwt));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ECPublicKey(java.security.interfaces.ECPublicKey) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Example 5 with ECDSAKeyProvider

use of com.auth0.jwt.interfaces.ECDSAKeyProvider in project java-jwt by auth0.

the class ECDSABouncyCastleProviderTests method shouldFailECDSA512VerificationWhenProvidedPublicKeyIsNull.

@Test
public void shouldFailECDSA512VerificationWhenProvidedPublicKeyIsNull() {
    exception.expect(SignatureVerificationException.class);
    exception.expectMessage("The Token's Signature resulted invalid when verified using the Algorithm: SHA512withECDSA");
    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 = "eyJhbGciOiJFUzUxMiIsImtpZCI6Im15LWtleS1pZCJ9.eyJpc3MiOiJhdXRoMCJ9.AGxEwbsYa2bQ7Y7DAcTQnVD8PmLSlhJ20jg2OfdyPnqdXI8SgBaG6lGciq3_pofFhs1HEoFoJ33Jcluha24oMHIvAfwu8qbv_Wq3L2eI9Q0L0p6ul8Pd_BS8adRa2PgLc36xXGcRc7ID5YH-CYaQfsTp5YIaF0Po3h0QyCoQ6ZiYQkqm";
    Algorithm algorithm = Algorithm.ECDSA512(provider);
    algorithm.verify(JWT.decode(jwt));
}
Also used : ECDSAKeyProvider(com.auth0.jwt.interfaces.ECDSAKeyProvider) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ECDSAAlgorithmTest(com.auth0.jwt.algorithms.ECDSAAlgorithmTest) Test(org.junit.Test)

Aggregations

ECDSAKeyProvider (com.auth0.jwt.interfaces.ECDSAKeyProvider)58 Test (org.junit.Test)58 ECPublicKey (java.security.interfaces.ECPublicKey)30 ECPrivateKey (java.security.interfaces.ECPrivateKey)26 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)26 ECDSAAlgorithmTest (com.auth0.jwt.algorithms.ECDSAAlgorithmTest)23 BigInteger (java.math.BigInteger)6 ECParameterSpec (java.security.spec.ECParameterSpec)6