如何手动验证 DKIM body 哈希?
How to validate DKIM body hash manually?
这是一封自动转发的电子邮件。
我正在尝试根据 rfc5322 验证 bh 字段。
但是收到的 sha256 哈希值与这个值不匹配。
邮件 body 是:转发邮件
有什么建议可以正确验证 bh= 字段吗?
我已经包含了一些示例 header 字段数据。请也解释一下(轻松的)规范程序
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1516798995;
s=jan2017; d=headsup.co.in; i=sender@headsup.co.in;
h=Date:From:To:Message-Id:Subject:MIME-Version:Content-Type; l=627;
bh=ODw8icD/S+4UGcXgR4ocNpxXDh4PolWtd1IUXjh0AUs=;
b=G2vTZ+uQ+krw49l+4aMnaeZjUvAJXPPRA8bvOhs3XZNbd2Ng+odB/F5PI3tRpdhr
C0CJA5KPv4VncP2V1PjNdkgKLjs1eTzLSaqmPjhhQDc8mWQRT0rzcPP3V9v6BeXF987
54Zns/QWtR+RbSacFXvUjyBEOlaWUVAmaVcqw5S8=
//Message: for forwarded mail
//Example Data
Date: Wed, 24 Jan 2018 18:33:08 +0530
From: sender <sender@headsup.co.in>
To: "receiver" <receiver@gmail.com>
Message-Id: <1612843d10d.d305604a24030.1212846966506749871@headsup.co.in>
Subject: Test Arc Seal
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_76205_1329960269.1516798988558"
X-Priority: Medium
//Cannonicalization code (relaxed)
package canonicalization;
import java.io.IOException;
public class Canonicalization {
public String canonicalizeHeader(String name, String value) {
name = name.trim().toLowerCase();
value = value.replaceAll("\s+", " ").trim();
return name + ":" + value;
}
public String canonicalizeBody(String body) {
if (body == null || "".equals(body)) {
return "\r\n";
}
body = body.replaceAll("[ \t\x0B\f]+", " ");
body = body.replaceAll(" \r\n", "\r\n");
// The body must end with \r\n
if (!body.endsWith("\r\n")) {
return body + "\r\n";
}
// Remove trailing empty lines ...
while (body.endsWith("\r\n\r\n")) {
body = body.substring(0, body.length() - 2);
}
return body;
}
public static void main(String[] args) {
Canonicalization obj=new Canonicalization();
System.out.println(obj.canonicalizeHeader("Date"," Wed, 24 Jan 2018 18:33:08 +0530"));
System.out.println(obj.canonicalizeHeader("From"," sender <sender@headsup.co.in>"));
System.out.println(obj.canonicalizeHeader("To"," \"receiver\" <receiver@gmail.com>"));
System.out.println(obj.canonicalizeBody("for forwarded mail"));
}
}
您没有提供任何代码来说明您如何尝试验证正文哈希,但很可能您错误地规范了提供给哈希函数的输入。
该代码适用于以纯文本格式发送的电子邮件(内容类型:text/plain;)
但默认情况下,电子邮件以富文本格式发送(内容类型:multipart/alternative;),因此正文哈希值不匹配
这是一封自动转发的电子邮件。 我正在尝试根据 rfc5322 验证 bh 字段。 但是收到的 sha256 哈希值与这个值不匹配。 邮件 body 是:转发邮件 有什么建议可以正确验证 bh= 字段吗? 我已经包含了一些示例 header 字段数据。请也解释一下(轻松的)规范程序
DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1516798995;
s=jan2017; d=headsup.co.in; i=sender@headsup.co.in;
h=Date:From:To:Message-Id:Subject:MIME-Version:Content-Type; l=627;
bh=ODw8icD/S+4UGcXgR4ocNpxXDh4PolWtd1IUXjh0AUs=;
b=G2vTZ+uQ+krw49l+4aMnaeZjUvAJXPPRA8bvOhs3XZNbd2Ng+odB/F5PI3tRpdhr
C0CJA5KPv4VncP2V1PjNdkgKLjs1eTzLSaqmPjhhQDc8mWQRT0rzcPP3V9v6BeXF987
54Zns/QWtR+RbSacFXvUjyBEOlaWUVAmaVcqw5S8=
//Message: for forwarded mail
//Example Data
Date: Wed, 24 Jan 2018 18:33:08 +0530
From: sender <sender@headsup.co.in>
To: "receiver" <receiver@gmail.com>
Message-Id: <1612843d10d.d305604a24030.1212846966506749871@headsup.co.in>
Subject: Test Arc Seal
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_76205_1329960269.1516798988558"
X-Priority: Medium
//Cannonicalization code (relaxed)
package canonicalization;
import java.io.IOException;
public class Canonicalization {
public String canonicalizeHeader(String name, String value) {
name = name.trim().toLowerCase();
value = value.replaceAll("\s+", " ").trim();
return name + ":" + value;
}
public String canonicalizeBody(String body) {
if (body == null || "".equals(body)) {
return "\r\n";
}
body = body.replaceAll("[ \t\x0B\f]+", " ");
body = body.replaceAll(" \r\n", "\r\n");
// The body must end with \r\n
if (!body.endsWith("\r\n")) {
return body + "\r\n";
}
// Remove trailing empty lines ...
while (body.endsWith("\r\n\r\n")) {
body = body.substring(0, body.length() - 2);
}
return body;
}
public static void main(String[] args) {
Canonicalization obj=new Canonicalization();
System.out.println(obj.canonicalizeHeader("Date"," Wed, 24 Jan 2018 18:33:08 +0530"));
System.out.println(obj.canonicalizeHeader("From"," sender <sender@headsup.co.in>"));
System.out.println(obj.canonicalizeHeader("To"," \"receiver\" <receiver@gmail.com>"));
System.out.println(obj.canonicalizeBody("for forwarded mail"));
}
}
您没有提供任何代码来说明您如何尝试验证正文哈希,但很可能您错误地规范了提供给哈希函数的输入。
该代码适用于以纯文本格式发送的电子邮件(内容类型:text/plain;)
但默认情况下,电子邮件以富文本格式发送(内容类型:multipart/alternative;),因此正文哈希值不匹配