Skip to content

Commit 2adaaa4

Browse files
committed
check if the received signature has JOSE or DER format
1 parent 72704dd commit 2adaaa4

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

lib/src/main/java/com/auth0/jwtdecodejava/algorithms/ECDSAAlgorithm.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void verify(String[] jwtParts) throws SignatureVerificationException {
3131
s.initVerify(publicKey);
3232
s.update(content.getBytes());
3333
byte[] signature = Base64.decodeBase64(jwtParts[2]);
34-
if (isJOSESignature(signature)) {
34+
if (!isDERSignature(signature)) {
3535
signature = JOSEToDER(signature);
3636
}
3737
boolean valid = s.verify(signature);
@@ -43,9 +43,10 @@ public void verify(String[] jwtParts) throws SignatureVerificationException {
4343
}
4444
}
4545

46-
private boolean isJOSESignature(byte[] signature) {
47-
//TODO: Check if the signature has JOSE format.
48-
return true;
46+
private boolean isDERSignature(byte[] signature) {
47+
// DER Structure: http://crypto.stackexchange.com/a/1797
48+
// Should begin with 0x30 and have exactly the expected length
49+
return signature[0] == 0x30 && signature.length == ecNumberSize * 2;
4950
}
5051

5152
private byte[] JOSEToDER(byte[] joseSignature) throws SignatureException {

0 commit comments

Comments
 (0)