我正在用 Node.js 编写自己的 DKIM 实现,但在让我的 DKIM 通过时遇到问题。
这是我的邮件正文:
dGVzdA==\r\n
这是正文哈希(sha256):
STFhz2ITzV8iSPWgLK0kfUa69jvk327MHRw2ZpGDvWE=
这是我的 dkim 标头哈希输入:
来自:test@test.test.org\r\ndkim-signature:v=1;a=rsa-sha256;c=relaxed;s=wo8vy2th;d=test.test.org;h=来自;bh=STFhz2ITzV8iSPWgLK0kfUa69jvk327MHRw2ZpGDvWE= ;b=
然后我使用以下代码签名:
crypto.createSign('rsa-sha256').update(headerHash).sign({key: processItem.sharedData.dkim_private_key, passphrase: dkimDomainKeyPassphrase}, 'base64');
然而,在抵达时我得到 dkim=fail。我的 DNS _domainkey 确实解析正确。
请注意,对于此示例,我仅使用 From: 标头来尝试查找问题。实际上,我将使用所有推荐的标题。
编辑:这是失败的原始电子邮件来源:
Delivered-To: wyatt5@ethereal.email
Return-Path: <test@test2.cybermancy.org>
Authentication-Results: mx.ethereal.email; spf=permerror smtp.mailfrom=test2.cybermancy.org; dkim=fail header.i=@test2.cybermancy.org
Received-SPF: PermError (mx.ethereal.email: domain of test2.cybermancy.org does not designate 67.205.181.191 as permitted sender) receiver=mx.ethereal.email; identity=mailfrom; client-ip=67.205.181.191; helo=mta.postagent.io; envelope-from=<test@test2.cybermancy.org>
Received-SPF: None (mx.ethereal.email: domain of mta.postagent.io does not designate 67.205.181.191 as permitted sender) receiver=mx.ethereal.email; identity=helo; client-ip=67.205.181.191; helo=mta.postagent.io; envelope-from=<test@test2.cybermancy.org>
Received: from mta.postagent.io ([67.205.181.191])
by mx.ethereal.email (Haraka/2.8.23) with ESMTP id A08331BF-93B5-41C1-ADBA-B7B0F9DEF1CF.1
envelope-from <test@test2.cybermancy.org>;
Fri, 17 Jan 2020 14:18:12 +0100
Message-ID: <23e18f92-e6f3-4fab-bfa3-649584bec5b4+1579267090958@mta.postagent.io>
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; s=wo8vy2th;
h=mime-version:from:to:date:subject;
d=test2.cybermancy.org;
bh=STFhz2ITzV8iSPWgLK0kfUa69jvk327MHRw2ZpGDvWE=;
b=RH/CNjqKlOcLEuwT8zCEo2k0UyDDAlCfsEVkPBU83pbNNDNxVMUVDQmHsxjPUw/GLm0osY948u1YhUIC8clAfUdaaVQqHfWXDmuk24t+uaeHLwQu/dTRuLJfFjO+lXlnx4VFNxQHj3kBAWJ6/aNhO5kq3QI7u7uGWtGf+4pZzg8=
To: wyatt5@ethereal.email
From: test@test2.cybermancy.org
Subject: test subject
Date: Fri, 17 Jan 2020 13:18:10 +0000
X-report-abuse: Please forward a copy of this message, including all headers, to abuse@test.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: base64
dGVzdA==
注意:我已经尝试过折叠和不折叠的签名值。对于这个例子,我没有折叠它。
这是我的标头哈希输入:
mime-version:1.0\\r\\nfrom:test@test2.cybermancy.org\r\nto:wyatt5@ethereal.email\r\ndate:Fri, 17 Jan 2020 13:18:10 +0000\r\nsubject:test subject\r\ndkim-signature:v=1;a=rsa-sha256;c=relaxed;s=wo8vy2th;d=test2.cybermancy.org;h=mime-version:from:to:date:subject;bh=STFhz2ITzV8iSPWgLK0kfUa69jvk327MHRw2ZpGDvWE=;b=
DKIM 选择器:wo8vy2th DKIM 公钥,位于 wo8vy2th._domainkey.test2.cybermancy.org
k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC7V0yupUNowYt7ciprmmn3s2sQkQA8cI7LVywrTwAOAS1RMAAcPRGIO0By/XHlh8uTMf0Kw+GscrHRz90TUJpRdDx9lCKCwUE6taWVsdsgUPmpJ1AxHDCrmbadFdjsc0hNTCt8niNsmph8qiV/6T6Qjtt/4piVlxKxzLPIJn976QIDAQAB
编辑2:
这是我用 JSON.stringify() 打印的私钥:
"-----BEGIN ENCRYPTED PRIVATE KEY-----\nMIIC3TBXBgkqhkiG9w0BBQ0wSjApBgkqhkiG9w0BBQwwHAQ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