mirror of https://github.com/jwtk/jjwt.git
Similar to issue #68 (https://github.com/jwtk/jjwt/issues/68), EC keys on Android do not implement ECPrivateKey. This changes the check in EllipticCurveSigner.java to use the same test as was used to solve issue #68 for RSA keys.
This commit is contained in:
parent
8a6f588e81
commit
2b8ad0c05a
|
@ -19,6 +19,7 @@ import java.security.InvalidKeyException;
|
|||
import java.security.Key;
|
||||
import java.security.PrivateKey;
|
||||
import java.security.Signature;
|
||||
import java.security.interfaces.ECKey;
|
||||
import java.security.interfaces.ECPrivateKey;
|
||||
|
||||
import io.jsonwebtoken.JwtException;
|
||||
|
@ -29,9 +30,9 @@ public class EllipticCurveSigner extends EllipticCurveProvider implements Signer
|
|||
|
||||
public EllipticCurveSigner(SignatureAlgorithm alg, Key key) {
|
||||
super(alg, key);
|
||||
if (!(key instanceof ECPrivateKey)) {
|
||||
String msg = "Elliptic Curve signatures must be computed using an ECPrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an ECPrivateKey.";
|
||||
if (!(key instanceof PrivateKey && key instanceof ECKey)) {
|
||||
String msg = "Elliptic Curve signatures must be computed using an EC PrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an EC PrivateKey.";
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ class EllipticCurveSignerTest {
|
|||
new EllipticCurveSigner(SignatureAlgorithm.ES256, key);
|
||||
fail('EllipticCurveSigner should reject non ECPrivateKey instances.')
|
||||
} catch (IllegalArgumentException expected) {
|
||||
assertEquals expected.message, "Elliptic Curve signatures must be computed using an ECPrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an ECPrivateKey.";
|
||||
assertEquals expected.message, "Elliptic Curve signatures must be computed using an EC PrivateKey. The specified key of " +
|
||||
"type " + key.getClass().getName() + " is not an EC PrivateKey.";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue