dsfew215211 2011-10-25 14:56
浏览 512
已采纳

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

I'm trying to sign a mail using PGP in php. I could bring the boundaries and headers to work correctly but the mail signature isn't valid (as Thunderbirds Enigmail states).

My question here is what part is to sign and what is to take attention to while doing it.

At the moment the source of the generated mail looks like this (Text and signature replaced by placeholders to keep it easy to read):

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--

Currently the lines starting with a & are used to generate the signature. Line breaks are just new lines (PHP_EOL).

I tried following RFC2015 but this seems not to apply for multipart/alternative conent.

Please help me out here so I can get this finished.

  • 写回答

1条回答 默认 最新

  • duanbei1709 2011-10-26 14:35
    关注

    I found out myself...

    First of all I needed to convert all line breaks to CRLF like the RFCs state. Then I needed to think of the whole multipart/alternative inclusive its headers as the message to sign. So it should have been:

    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--
    

    Where the lines starting with & are the ones to be signed.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看