带自定义邮件标头的DKIM?

时间:2014-05-06 13:29:14

标签: php email phpmailer dkim custom-headers

我非常成功地使用PHPMailer从我的网站发送SPF / DKIM电子邮件。成功地,因为它的垃圾邮件评级几乎为零。

但是,我想在签名中添加一个自定义邮件标题,以确保其值的真实性。

  1. 可以这样做吗?
  2. 这可以用PHPMailer完成吗?
  3. 如果是:怎么样?
  4. 插图:

    假设我有一个自定义字段X-app-originalSender

    当我查看外发电子邮件的来源时,我看到了

    Delivered-To: example@internet.com
    Received: by 10.10.10.10 with SMTP id v7csp230623wjf;
            Tue, 6 May 2014 05:20:04 -0700 (PDT)
    X-Received: by 10.10.10.10 with SMTP id v2mr38890846oer.37.1399378803091;
            Tue, 06 May 2014 05:20:03 -0700 (PDT)
    Return-Path: <mister+caf_=example=internet.com@example.com>
    Received: from mail-oa0-x22e.gogol.com (mail-oa0-x22e.gogol.com [2607:f8b0:4003:c02::22e])
            by mx.gogol.com with ESMTPS id vj5si8402166obb.10.10.10.10.05.20.02
            for <example@internet.com>
            (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
            Tue, 06 May 2014 05:20:03 -0700 (PDT)
    Received-SPF: none (gogol.com: mister+caf_=example=internet.com@example.com does not designate permitted sender hosts) client-ip=2607:f8b0:4003:c02::22e;
    Authentication-Results: mx.gogol.com;
           spf=neutral (gogol.com: mister+caf_=example=internet.com@example.com does not designate permitted sender hosts) smtp.mail=mister+caf_=example=internet.com@example.com;
           dkim=pass header.i=@website.com
    Received: by mail-oa0-x22e.gogol.com with SMTP id i4so9294020oah.19
            for <example@internet.com>; Tue, 06 May 2014 05:20:02 -0700 (PDT)
    X-gogol-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
            d=1e100.net; s=20130820;
            h=x-gm-message-state:delivered-to:to:subject:dkim-signature:date:from
             :reply-to:message-id:mime-version:content-type;
            bh=ObNkr4SNFALRke4Aa0VT3bZmEq19ZIWHnngz5uCPG3U=;
            b=hbiSE6cEr+FEAIGUCqsCfNOQq9SYsYZ9fa4lC333uWyUY9x6srMgwHeOa28IoKxD31
             76LnRKfqc3YZBqMFKJ37plvyVXdaRsPCwLdYrNNMxmvNVVb5siC8r6Frx6v2QCBPcPEQ
             U+c6Qn/Rl9dHYHD9GCoC346DWkC8CcAF/MG6oipVcf9kojwfuYR/UgzpjmVMKcueUpEy
             nHKKGmfVT9RcqHgPMsOj1/W8/k/drKRUk2QlzLH8anR6foeWqjNtyUmHYxo/Qc6eKoxh
             Zua23/rTAgb/1SF4yalyeaeTa9xWO07bHeDwgknvg7QuYBSjDt+7iIXngkZXVYaSNAEJ
             xZIw==
    X-Gm-Message-State: ALoCoQmfamLXlJ4EXccj5awNP/G2qU/uIZcjuLJKrB+5YOVHQsc1ARYlMw6wxCDTCchbQnufkN4N
    X-Received: by 10.10.10.10 with SMTP id my9mr1885484obb.61.1399378802595;
            Tue, 06 May 2014 05:20:02 -0700 (PDT)
    X-Forwarded-To: example@internet.com
    X-Forwarded-For: mister@example.com example@internet.com
    Delivered-To: mister@example.com
    Received: by 10.10.10.10 with SMTP id hd5csp216265obb;
            Tue, 6 May 2014 05:20:01 -0700 (PDT)
    X-Received: by 10.10.10.10 with SMTP id a49mr10690110eei.46.1399378800211;
            Tue, 06 May 2014 05:20:00 -0700 (PDT)
    Return-Path: <server@website.com>
    Received: from rembrandt.net.de (rembrandt.net.de. [10.10.10.10])
            by mx.gogol.com with ESMTPS id n46si13234148eeo.10.10.10.10.05.19.59
            for <mister@example.com>
            (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
            Tue, 06 May 2014 05:20:00 -0700 (PDT)
    Received-SPF: pass (gogol.com: domain of server@website.com designates 10.10.10.10 as permitted sender) client-ip=10.10.10.10;
    Received: (qmail 29290 invoked by uid 10269); 6 May 2014 14:19:59 +0200
    To: mister@example.com
    Subject: Whatever
    X-app-originalSender: Roger Rabbit
    X-PHP-Originating-Script: 10269:class.phpmailer.php
    DKIM-Signature: v=1; a=rsa-sha1; q=dns/txt; l=937; s=website;
      t=1399378799; c=relaxed/simple;
      h=From:To:Subject;
      d=website.com;
      z=From:=20"website.com=20Warning"=20<server@website.com>
      |To:=20mister@example.com
      |Subject:=20Whatever;
      bh=Yvxg9fVS37EmFVuVWzUji3Wry5Q=;
      b=JmNeGJsvhhC5s/rTLfXPSBte2NfYCPLNiNrNi4/bbjcdKvPNt/LvySGOpD+4hIAxsjwGtknsz7CMDOhcmJLPK/FHge18q+Dw1j0chtRehIZUdEHKcHDU5n2X2/x+ja+EohtfNFwCfjm3Zyfjf+cDyvsKUrf8l6mtWqK9oWpjyrg=
    Date: Tue, 6 May 2014 14:19:59 +0200
    From: "website.com Warning" <server@website.com>
    Reply-To: "website.com Warnung" <server@website.com>
    Message-ID: <59052014140619-L73ESg5cau@website.com>
    X-Priority: 3
    X-Mailer: website.com platform (https://website.com)
    MIME-Version: 1.0
    Content-Type: multipart/alternative;
    

    我最感兴趣的是 h=From:To:Subject; 这一行,我假设必须有一种方法可以将自定义字段添加到其中。

    如何?

    DKIM规范

    来自http://dkim.org/specs/draft-allman-dkim-base-01.html#rfc.section.3.5

      

    签名标题字段(纯文本,但请参阅说明;必需)。以冒号分隔的列表&gt;头字段名称,用于标识呈现给签名算法的头字段。该字段必须按照提交给签名算法的顺序包含标题字段的完整列表。字段MAY包含签名时不存在的头字段的名称;不存在的头字段对签名计算没有贡献(即,它们被视为空输入,包括头字段名称,分隔冒号,头字段值和任何CRLF终止符),并且在验证不存在的头时字段必须以相同的方式处理。该字段不得包含正在创建或验证的DKIM-Signature标头字段。折叠空格(FWS)可以包含在冒号分隔符的任一侧。必须以不区分大小写的方式将标题字段名称与实际标题字段名称进行比较。   ABNF:   sig-h-tag =“h =” FWS hdr-name 0 (* FWS“:”* FWS hdr-name)   hdr-name = field-name   信息说明:通过“签名”实际不存在的标题字段,签名者可以在验证之前阻止插入这些标题字段。但是,由于发送者不可能知道将来可能创建哪些头字段,并且某些MUA可能呈现嵌入消息内的头字段(例如,作为消息/ rfc822内容类型),因此该解决方案的安全性是不是全部。   信息性说明:排除头字段名称和冒号以及不存在的头字段的头字段值可防止攻击者插入具有空值的实际头字段。

1 个答案:

答案 0 :(得分:0)

您是正确的,可以在DKIM签名中包含任意标头,但PHPMailer不提供这样做的方法。 DKIM_Add方法是有趣的位发生的地方,你可以在那里看到h=From:To:Subject;是硬编码的。可能最简单的方法是继承PHPMailer并重写此函数以包含额外的标题。