Skip to content

Commit 9d471d2

Browse files
committed
Abstracted the error message thrown
1 parent 645b40a commit 9d471d2

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,23 +158,23 @@ void validateSignatureStructure(byte[] joseSignature, ECPublicKey publicKey) thr
158158
}
159159

160160
if (isAllZeros(joseSignature)) {
161-
throw new SignatureException("Invalid Signature: All Zeros.");
161+
throw new SignatureException("Invalid signature format.");
162162
}
163163

164164
// get R
165165
byte[] rBytes = new byte[ecNumberSize];
166166
System.arraycopy(joseSignature, 0, rBytes, 0, ecNumberSize);
167167
BigInteger r = new BigInteger(1, rBytes);
168168
if(isAllZeros(rBytes)) {
169-
throw new SignatureException("Invalid Signature: All Zeros for R value.");
169+
throw new SignatureException("Invalid signature format.");
170170
}
171171

172172
// get S
173173
byte[] sBytes = new byte[ecNumberSize];
174174
System.arraycopy(joseSignature, ecNumberSize, sBytes, 0, ecNumberSize);
175175
BigInteger s = new BigInteger(1, sBytes);
176176
if(isAllZeros(sBytes)) {
177-
throw new SignatureException("Invalid Signature: All Zeros for S value.");
177+
throw new SignatureException("Invalid signature format.");
178178
}
179179

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

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

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

lib/src/test/java/com/auth0/jwt/algorithms/ECDSAAlgorithmTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ public void emptyECDSA256SignatureShouldFailTokenVerification() throws Exception
13701370
@Test
13711371
public void signatureWithAllZerosShouldFail() throws Exception {
13721372
exception.expect(SignatureException.class);
1373-
exception.expectMessage("Invalid Signature: All Zeros.");
1373+
exception.expectMessage("Invalid signature format.");
13741374

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

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

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

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

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

14571457
ECPublicKey publicKey = (ECPublicKey) readPublicKeyFromFile(PUBLIC_KEY_FILE_256, "EC");
14581458
ECPrivateKey privateKey = (ECPrivateKey) readPrivateKeyFromFile(PRIVATE_KEY_FILE_256, "EC");

0 commit comments

Comments
 (0)