【问题标题】:Sign a multipart mail using PGP/MIME使用 PGP/MIME 签署多部分邮件
【发布时间】:2011-12-15 00:44:09
【问题描述】:

我正在尝试在 php 中使用 PGP 签署邮件。我可以使边界和标题正常工作,但邮件签名无效(如 Thunderbirds Enigmail 所述)。

我这里的问题是要签什么部分,签的时候要注意什么。

目前生成邮件的来源是这样的(文本和签名被占位符替换以保持易于阅读):

Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=_1b5364229a82b654fad7cf2aa969f02e"
MIME-Version: 1.0

This is a message in Mime Format.  If you see this, your mail reader does not support this format.

--=_1b5364229a82b654fad7cf2aa969f02e
Content-Type: multipart/alternative;
  boundary="=_53ba9ef8c471e6c8d72f215feaad8033"
Content-Transfer-Encoding: 7bit


--=_53ba9ef8c471e6c8d72f215feaad8033
&Content-Type: text/plain; charset=UTF-8
&Content-Transfer-Encoding: quoted-printable
&
&PLAIN TEXT CONTENT ENCODED IN QUOTED PRINTABLE
& 
&--=_53ba9ef8c471e6c8d72f215feaad8033
&Content-Type: text/html; charset=UTF-8
&Content-Transfer-Encoding: quoted-printable
& 
&HTML CONTENT ENCODED IN QUOTED PRINTABLE

--=_53ba9ef8c471e6c8d72f215feaad8033--

--=_1b5364229a82b654fad7cf2aa969f02e
Content-Type: application/pgp-signature; name="signature.asc"
Content-Disposition: attachment; filename="signature.asc"
Content-Description: OpenPGP digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

PGP SIGNATURE HERE
-----END PGP SIGNATURE-----

--=_1b5364229a82b654fad7cf2aa969f02e--

目前以 & 开头的行用于生成签名。换行符只是换行符 (PHP_EOL)。

我尝试遵循 RFC2015 但这似乎不适用于多部分/替代内容。

请帮我解决这个问题。

【问题讨论】:

    标签: php email mime signature pgp


    【解决方案1】:

    我发现自己...

    首先,我需要将所有换行符转换为 CRLF,就像 RFC 状态一样。然后我需要将整个 multipart/alternative 包括其标题视为要签名的消息。所以应该是:

    Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=_1b5364229a82b654fad7cf2aa969f02e"
    MIME-Version: 1.0
    
    This is a message in Mime Format.  If you see this, your mail reader does not support this format.
    
    --=_1b5364229a82b654fad7cf2aa969f02e
    &Content-Type: multipart/alternative;
    &  boundary="=_53ba9ef8c471e6c8d72f215feaad8033"
    &Content-Transfer-Encoding: 7bit
    &
    &
    &--=_53ba9ef8c471e6c8d72f215feaad8033
    &Content-Type: text/plain; charset=UTF-8
    &Content-Transfer-Encoding: quoted-printable
    &
    &PLAIN TEXT CONTENT ENCODED IN QUOTED PRINTABLE
    & 
    &--=_53ba9ef8c471e6c8d72f215feaad8033
    &Content-Type: text/html; charset=UTF-8
    &Content-Transfer-Encoding: quoted-printable
    & 
    &HTML CONTENT ENCODED IN QUOTED PRINTABLE
    & 
    &--=_53ba9ef8c471e6c8d72f215feaad8033--
    
    --=_1b5364229a82b654fad7cf2aa969f02e
    Content-Type: application/pgp-signature; name="signature.asc"
    Content-Disposition: attachment; filename="signature.asc"
    Content-Description: OpenPGP digital signature
    
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.11 (GNU/Linux)
    
    PGP SIGNATURE HERE
    -----END PGP SIGNATURE-----
    
    --=_1b5364229a82b654fad7cf2aa969f02e--
    

    以 & 开头的行是要签名的行。

    【讨论】:

    • 作为附录,您还应该从将要签名的每一行中去除尾随空格,因为某些邮件传输可能会在传输过程中这样做。
    猜你喜欢
    • 2021-01-11
    • 2020-06-30
    • 2012-07-17
    • 2011-06-12
    • 2015-07-12
    • 2016-10-05
    • 2019-05-01
    • 1970-01-01
    • 2021-10-18
    相关资源
    最近更新 更多