Skip to content

Commit

Permalink
Abstracted the error message thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj committed May 5, 2022
1 parent 645b40a commit 9d471d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions lib/src/main/java/com/auth0/jwt/algorithms/ECDSAAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,23 @@ void validateSignatureStructure(byte[] joseSignature, ECPublicKey publicKey) thr
}

if (isAllZeros(joseSignature)) {
throw new SignatureException("Invalid Signature: All Zeros.");
throw new SignatureException("Invalid signature format.");
}

// get R
byte[] rBytes = new byte[ecNumberSize];
System.arraycopy(joseSignature, 0, rBytes, 0, ecNumberSize);
BigInteger r = new BigInteger(1, rBytes);
if(isAllZeros(rBytes)) {
throw new SignatureException("Invalid Signature: All Zeros for R value.");
throw new SignatureException("Invalid signature format.");
}

// get S
byte[] sBytes = new byte[ecNumberSize];
System.arraycopy(joseSignature, ecNumberSize, sBytes, 0, ecNumberSize);
BigInteger s = new BigInteger(1, sBytes);
if(isAllZeros(sBytes)) {
throw new SignatureException("Invalid Signature: All Zeros for S value.");
throw new SignatureException("Invalid signature format.");
}

//moved this check from JOSEToDER method
Expand All @@ -192,11 +192,11 @@ void validateSignatureStructure(byte[] joseSignature, ECPublicKey publicKey) thr

// R and S must be less than N
if (order.compareTo(r) < 1) {
throw new SignatureException("The difference between R value and order should be greater than one.");
throw new SignatureException("Invalid signature format.");
}

if (order.compareTo(s) < 1){
throw new SignatureException("The difference between S value and order should be greater than one.");
throw new SignatureException("Invalid signature format.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ public void emptyECDSA256SignatureShouldFailTokenVerification() throws Exception
@Test
public void signatureWithAllZerosShouldFail() throws Exception {
exception.expect(SignatureException.class);
exception.expectMessage("Invalid Signature: All Zeros.");
exception.expectMessage("Invalid signature format.");

ECPublicKey pubKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");

Expand All @@ -1382,7 +1382,7 @@ public void signatureWithAllZerosShouldFail() throws Exception {
@Test
public void signatureWithRZeroShouldFail() throws Exception {
exception.expect(SignatureException.class);
exception.expectMessage("Invalid Signature: All Zeros for R value.");
exception.expectMessage("Invalid signature format.");

ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
ECPrivateKey privateKey = (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_256, "EC");
Expand All @@ -1408,7 +1408,7 @@ public void signatureWithRZeroShouldFail() throws Exception {
@Test
public void signatureWithSZeroShouldFail() throws Exception {
exception.expect(SignatureException.class);
exception.expectMessage("Invalid Signature: All Zeros for S value.");
exception.expectMessage("Invalid signature format.");

ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
ECPrivateKey privateKey = (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_256, "EC");
Expand All @@ -1434,7 +1434,7 @@ public void signatureWithSZeroShouldFail() throws Exception {
@Test
public void signatureWithRValueNotLessThanOrderShouldFail() throws Exception {
exception.expect(SignatureException.class);
exception.expectMessage("The difference between R value and order should be greater than one.");
exception.expectMessage("Invalid signature format.");

ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
ECPrivateKey privateKey = (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_256, "EC");
Expand All @@ -1452,7 +1452,7 @@ public void signatureWithRValueNotLessThanOrderShouldFail() throws Exception {
@Test
public void signatureWithSValueNotLessThanOrderShouldFail() throws Exception {
exception.expect(SignatureException.class);
exception.expectMessage("The difference between S value and order should be greater than one.");
exception.expectMessage("Invalid signature format.");

ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
ECPrivateKey privateKey = (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_256, "EC");
Expand Down

0 comments on commit 9d471d2

Please sign in to comment.