This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-jdkim.git
commit 7e382bb3a99cff9ab94620d025a8bd6cb635febd
Author: Emerson Pinter <[email protected]>
AuthorDate: Thu Mar 20 17:28:54 2025 -0300
Pass SignatureRecord to PermFailException
---
.../java/org/apache/james/jdkim/DKIMSigner.java | 6 ++---
.../java/org/apache/james/jdkim/DKIMVerifier.java | 26 +++++++++++-----------
.../apache/james/jdkim/impl/BodyHasherImpl.java | 6 ++---
3 files changed, 19 insertions(+), 19 deletions(-)
diff --git a/main/src/main/java/org/apache/james/jdkim/DKIMSigner.java b/main/src/main/java/org/apache/james/jdkim/DKIMSigner.java
index bee8fdf..1a91c1e 100644
--- a/main/src/main/java/org/apache/james/jdkim/DKIMSigner.java
+++ b/main/src/main/java/org/apache/james/jdkim/DKIMSigner.java
@@ -121,12 +121,12 @@ public class DKIMSigner extends DKIMCommon {
return "DKIM-Signature:" + bhj.getSignatureRecord().toString();
} catch (InvalidKeyException e) {
- throw new PermFailException("Invalid key: " + e.getMessage(), e);
+ throw new PermFailException("Invalid key: " + e.getMessage(), bhj.getSignatureRecord(), e);
} catch (NoSuchAlgorithmException e) {
- throw new PermFailException("Unknown algorythm: " + e.getMessage(),
+ throw new PermFailException("Unknown algorythm: " + e.getMessage(), bhj.getSignatureRecord(),
e);
} catch (SignatureException e) {
- throw new PermFailException("Signing exception: " + e.getMessage(),
+ throw new PermFailException("Signing exception: " + e.getMessage(), bhj.getSignatureRecord(),
e);
}
}
diff --git a/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java b/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java
index 2648a5e..2b1966d 100644
--- a/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java
+++ b/main/src/main/java/org/apache/james/jdkim/DKIMVerifier.java
@@ -246,13 +246,13 @@ public class DKIMVerifier extends DKIMCommon {
if (pos > 0) {
String v = signatureField.substring(pos + 1, signatureField
.length());
- SignatureRecord signatureRecord;
+ SignatureRecord signatureRecord = null;
try {
signatureRecord = newSignatureRecord(v);
// validate
signatureRecord.validate();
} catch (IllegalStateException e) {
- throw new PermFailException("Invalid signature record: " + e.getMessage(), e);
+ throw new PermFailException("Invalid signature record: " + e.getMessage(), signatureRecord, e);
}
// Specification say we MAY refuse to verify the signature.
@@ -261,22 +261,22 @@ public class DKIMVerifier extends DKIMCommon {
long elapsed = (System.currentTimeMillis() / 1000 - signedTime);
if (elapsed < -3600 * 24 * 365 * 3) {
throw new PermFailException("Signature date is more than "
- + -elapsed / (3600 * 24 * 365) + " years in the future.");
+ + -elapsed / (3600 * 24 * 365) + " years in the future.", signatureRecord);
} else if (elapsed < -3600 * 24 * 30 * 3) {
throw new PermFailException("Signature date is more than "
- + -elapsed / (3600 * 24 * 30) + " months in the future.");
+ + -elapsed / (3600 * 24 * 30) + " months in the future.", signatureRecord);
} else if (elapsed < -3600 * 24 * 3) {
throw new PermFailException("Signature date is more than "
- + -elapsed / (3600 * 24) + " days in the future.");
+ + -elapsed / (3600 * 24) + " days in the future.", signatureRecord);
} else if (elapsed < -3600 * 3) {
throw new PermFailException("Signature date is more than "
- + -elapsed / 3600 + " hours in the future.");
+ + -elapsed / 3600 + " hours in the future.", signatureRecord);
} else if (elapsed < -60 * 3) {
throw new PermFailException("Signature date is more than "
- + -elapsed / 60 + " minutes in the future.");
+ + -elapsed / 60 + " minutes in the future.", signatureRecord);
} else if (elapsed < 0) {
throw new PermFailException("Signature date is "
- + elapsed + " seconds in the future.");
+ + elapsed + " seconds in the future.", signatureRecord);
}
}
@@ -403,7 +403,7 @@ public class DKIMVerifier extends DKIMCommon {
.put(
"DKIM-Signature:" + bhj.getSignatureRecord().toString(),
new PermFailException(
- "Computed bodyhash is different from the expected one"));
+ "Computed bodyhash is different from the expected one", bhj.getSignatureRecord()));
} else {
verifiedSignatures.add(bhj.getSignatureRecord());
}
@@ -475,7 +475,7 @@ public class DKIMVerifier extends DKIMCommon {
try {
publicKey = key.getPublicKey();
} catch (IllegalStateException e) {
- throw new PermFailException("Invalid Public Key: " + e.getMessage(), e);
+ throw new PermFailException("Invalid Public Key: " + e.getMessage(), sign, e);
}
signature.initVerify(publicKey);
@@ -484,11 +484,11 @@ public class DKIMVerifier extends DKIMCommon {
if (!signature.verify(decoded))
throw new PermFailException("Header signature does not verify", sign);
} catch (InvalidKeyException e) {
- throw new PermFailException(e.getMessage(), e);
+ throw new PermFailException(e.getMessage(), sign, e);
} catch (NoSuchAlgorithmException e) {
- throw new PermFailException(e.getMessage(), e);
+ throw new PermFailException(e.getMessage(), sign, e);
} catch (SignatureException e) {
- throw new PermFailException(e.getMessage(), e);
+ throw new PermFailException(e.getMessage(), sign, e);
}
}
diff --git a/main/src/main/java/org/apache/james/jdkim/impl/BodyHasherImpl.java b/main/src/main/java/org/apache/james/jdkim/impl/BodyHasherImpl.java
index ef8577d..e180991 100644
--- a/main/src/main/java/org/apache/james/jdkim/impl/BodyHasherImpl.java
+++ b/main/src/main/java/org/apache/james/jdkim/impl/BodyHasherImpl.java
@@ -45,13 +45,13 @@ public class BodyHasherImpl implements BodyHasher {
md = MessageDigest.getInstance(sign.getHashAlgo().toString());
} catch (NoSuchAlgorithmException e) {
throw new PermFailException("Unsupported algorythm: "
- + sign.getHashAlgo(), e);
+ + sign.getHashAlgo(), sign, e);
}
try {
sign.validate();
} catch (IllegalStateException e) {
- throw new PermFailException("Invalid signature template", e);
+ throw new PermFailException("Invalid signature template", sign, e);
}
int limit = sign.getBodyHashLimit();
@@ -65,7 +65,7 @@ public class BodyHasherImpl implements BodyHasher {
.getBodyCanonicalisationMethod())) {
throw new PermFailException(
"Unsupported body canonicalization method: "
- + sign.getBodyCanonicalisationMethod());
+ + sign.getBodyCanonicalisationMethod(), sign);
}
DigestOutputStream dout = new DigestOutputStream(md);
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.