寻找PHP的逐步域密钥签名创建指南

时间:2013-04-29 23:34:08

标签: php rsa pem dkim domainkeys

所以,我已经失去了一些睡眠,我已经在网上搜索过,我已经找到了库,解释等等,但我还没有找到一个分步指南来创建一个要添加的域密钥签名到电子邮件标题,以签署从PHP程序发送的经过身份验证的电子邮件。实际上,我已经找到了一些说明,但似乎总是缺少一步!

阅读Jeff Atwood的"So You'd Like to Send Some Email (Through Code)"帮助了我很多,并且实际上告诉了我所有这些签名方法。到目前为止,我有:

  • 使用openVPN和以下openssl命令创建公钥/私钥对

    1. openssl genrsa -out rsa.private 1024 -

    2. openssl rsa -in rsa.private -out rsa.public -pubout -outform PEM

  • 添加了必要的TXT DNS记录(全局策略和公共base64密钥)

  • 在电子邮件标题中添加(似乎是)必要的参数

但是,使用Port25的身份验证报告会返回:

DomainKeys check details:
----------------------------------------------------------
Result:         fail (bad signature)
ID(s) verified: header.From=truth@truthuniversal.com
DNS record(s):
    truthuniversal._domainkey.truthuniversal.com. 86400 IN TXT "k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdxr0auyWOszMhdPW0LR3/Duf3t6XcvlwTpYuoS1lzCuT35voqcEhctCh2dTzq2RAXOrinbG8HuTg/IBde3GWaRwBMSQRJ/ZwiNZHomMfqnZEhC9MT+J9OAEbm5TdwZ0HcIOKGBGi0fZvhYs5kw34mk0cwO7AacgSInDf+QjOE+QIDAQAB"

您可以在那里看到使用该键的TXT记录。

这是使用openssl命令生成的公钥 - 文件rsa.public:

-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdxr0auyWOszMhdPW0LR3/Duf3
t6XcvlwTpYuoS1lzCuT35voqcEhctCh2dTzq2RAXOrinbG8HuTg/IBde3GWaRwBM
SQRJ/ZwiNZHomMfqnZEhC9MT+J9OAEbm5TdwZ0HcIOKGBGi0fZvhYs5kw34mk0cw
O7AacgSInDf+QjOE+QIDAQAB
-----END PUBLIC KEY-----

在PHP中,我正在以这种方式构建标题:

  $pkey="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdxr0auyWOszMhdPW0LR3/Duf3t6XcvlwTpYuoS1lzCuT35voqcEhctCh2dTzq2RAXOrinbG8HuTg/IBde3GWaRwBMSQRJ/ZwiNZHomMfqnZEhC9MT+J9OAEbm5TdwZ0HcIOKGBGi0fZvhYs5kw34mk0cwO7AacgSInDf+QjOE+QIDAQAB";

    $dkeysig = "DomainKey-Signature: a=rsa-sha1;
     s=truthuniversal;d=truthuniversal.com;c=simple;q=dns;b=$pkey;" 

    $newLine = "\r\n";

    //Construct Headers  
    $headers = "MIME-Version: 1.0" . $newLine;  
    $headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine; 
    $headers .= "$dkeysig" . $newLine;

当我检查收到的消息的标题时,它看起来是这样的:

  

DomainKey-Signature:a = rsa-sha1; S = truthuniversal; d = truthuniversal.com; C =简单; Q = DNS; B = MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDdxr0auyWOszMhdPW0LR3 / Duf3t6XcvlwTpYuoS1lzCuT35voqcEhctCh2dTzq2RAXOrinbG8HuTg / IBde3GWaRwBMSQRJ / ZwiNZHomMfqnZEhC9MT + J9OAEbm5TdwZ0HcIOKGBGi0fZvhYs5kw34mk0cwO7AacgSInDf + QjOE + QIDAQAB;

我错过了什么?

还有另一步吗?

0 个答案:

没有答案