使用PGP/MIME签署多部分电子邮件

5
我正在尝试使用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,但似乎不适用于multipart/alternative内容。

请在这里帮助我,以便我可以完成此操作。

1个回答

3

我发现我需要将所有的换行符转换为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--

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


1
作为补充,您还应该从每行中删除尾随的空格,因为某些邮件传输可能会在传输过程中这样做。 - jstedfast

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接