	      Design and implementation note of PGP/MIME

			  Kazuhiko Yamamoto
			    June 21, 1995

			     Version 0.2

Mew uses Content-Type: application/pgp which was described in
withdrawn Internet-Draft of 'draft-borenstein-pgp-mime-00.txt' by
Borenstein, Plumb, and Zimmermann. Note that this spec is very similar
to withdrawn draft-ietf-pem-mime-alternative-00.txt by Schiller though
it didn't provide format parameter.

Unlike MOSS, Mew's PGP/MIME never uses Multipart/Signed and
Multipart/Encrypted described in draft-ietf-pem-sigenc-03.txt. That's
because Mew keeps compatible with PGP before MIME. Yes, multipart
syntax is elegant but it gives up the compatibility. This is why MOSS,
which doesn't provide backward compatibility to PEM, stopped using the
word 'PEM'. But giving up the compatibility is a tragedy for PGP/MIME
since PGP is used by many many users.


(0) Terminology

CT:		Content-Type:
CTE:		Content-Transfer-Encoding:
CD:		Content-Description:
MIME Object:	Object that consists of content-header, null line, and 
		content-body. Content-header can be omitted.
		Content-header may consist of CT:, CTE:, and CD:.
		If content-header is omitted, it is treated as
		"CT: text/plain; charset=us-ascii" and "CTE: 7bit".
MIME-encode:	Base64, Quoted-Printable, 7bit, 8bit, binary[, Gzip64]
MIME-decode:	Decoding object according to CTE:
PGP-encode:	Sign, encrypt, or sign then encrypt by PGP.
PGP-decode:	Verify, decrypt, or decrypt then verify by PGP.
PGP-object:	PGP-encoded object.
Localized text: Text that contains local charset. But unlike MIME,
		charset is not given. 
Radix64:	Identical to Base64. This term is used on PGP.
7bit domain:	line-based text which contains only 7bit characters.
		CTE: 7bit, Base64(Radix64), Quoted-Printable[, Gzip64]
8bit domain:	line-based text which contains 7bit or 8bit characters.
		CTE: 8bit
binary domain:	any byte stream.
		CTE: binary


This note is written about MIME object whose content-body is PGP object.


(1) Definition of Application/PGP

MIME type name:		application
MIME subtypename:	pgp
Required parameters:	none
Optional paramters:	format
Encoding considerations:  (see below)

Content-body must be PGP object.


(1.1) Content-type: application/pgp

Content-body is a PGP object which PGP-encoded a localized text.


(1.2) Format parameter -- "text", and "mime"

Two values for format parameter are defined -- "text" and "mime".


(1.2.1) Content-type: application/pgp; format=text

This is identical to 'Content-type: application/pgp'. 


(1.2.2) Content-type: application/pgp; format=mime

Content-body is a PGP object which PGP-encoded a MIME object. 


(2) CTE: considerations

PGP objects are categorized into three types;

(a) PGP-signed --- 7bit or 8bit.
	7bit text such as ISO-2022-JP results in 7bit. (clear signature)
	8bit text such as ISO-8859-1 results in 8bit. (clear signature)
	binary object results in 7bit. (Radix64 encoded)
(b) PGP-encryped --- always 7bit. (Radix64 encoded)
(c) PGP-signed-then-encrypted --- always 7bit. (Radix64 encoded)


MIME object whose content-body is PGP object should provide CTE:
according to the PGP object's encoding. CTE: 7bit can be omitted but
the others should be provided.


(3) Canonicalization

When -t option is specified, PGP canonicalizes each line-break to
CRLF.

Following MIME objects must be passed to PGP as text.

	CT: Text/*
	CT: Multipart/*
	CT: Application/PostScript
	CT: Message/*


If these objects are in binary domain, it must be encoded to 7bit
domain. For example, if CT: Application/PostScript has binary data, it
should be encoded by quoted-printable. In order to pass Multipart to 
PGP, it must be 7bit or 8bit domain. This means that the Multipart must not
contain MIME objects in binary domain. Messages also must not include
MIME objects in binary domain.


Other MIME objects in 7bit or 8bit domain should be treated as text by
PGP.

If CTE: is binary, then it must be passed to PGP as binary.


(4) Localized text.

To keep minimum backward compatibility, if format is omitted or is
"text", PGP object is assumed to contain a localized text. It's not
always US-ASCII. It can be ISO-8859-1 or ISO-2022-JP or whatever.

	To: hiromi@foo.bar.com
	Subject: PGP signed message
	Mime-Version: 1.0
	Content-Type: application/pgp
	Content-Transfer-Encoding: 8bit
	Date: Wed, 21 Jun 1995 12:01:33 +0900
	Message-ID: <15659.803703693@challenge36.aist-nara.ac.jp>
	From: Kazuhiko Yamamoto =?ISO-2022-JP?B?GyRCOzNLXE9CSScbKEI=?= 
		<kazu@is.aist-nara.ac.jp>

	-----BEGIN PGP SIGNED MESSAGE-----

	ISO-8859-1 text is here.

	- --Kazu

	-----BEGIN PGP SIGNATURE-----
	Version: 2.6.i

	iQCVAgUBL+eLhw9kihyeT3RNAQGFPAP/WNvEx5gkqY5bdB+3r/Gs7HXRTnVy4R4m
	VzRxlNBoRvAu1AmzQw9t+zATjB2G/YjWUGNdJ73Ct5YK0JRKVEWuxQb9NPR85skF
	qF7VxKq/zeAfrNQlPYNbyl9/ErfZXfVumCdvCHEZTUKotvoimczfrVrSYA5uRF2E
	DoVU9LC3zYw=
	=Mves
	-----END PGP SIGNATURE-----

PGP-decoded text should be treated according to the local convention. 
For example, we assumed that the PGP-encoded text is ISO-2022-JP in
Japan.


(5) PGP-encode for MIME object

If you encode object whose type is other than text, it should be
converted into MIME object which consists of content-header and
content-body.

	Content-Type: Application/PostScript

	%!PS-Adobe-1.0
	%%
	%% Any PS file
	%%

Then, MIME object is PGP-encoded by PGP. Example of PGP sign is as
follows;

	Content-Type: application/pgp; format=mime

	-----BEGIN PGP SIGNED MESSAGE-----
	
	Content-Type: Application/PostScript
	
	%!PS-Adobe-1.0
	%%
	%% Any PS file
	%%

	-----BEGIN PGP SIGNATURE-----
	Version: 2.6.i
	
	iQCVAgUBL+fiyQ9kihyeT3RNAQF5BgP9FsuwLlCYjK47RSJjf1oxLi4LMsoCZ6sD
	xUiapAok1ApWJWEW3mVSiozNi48+5ANxSHewCZIsVT6xUwRwI7U66tkiWIlUCNhG
	CJl5pXjG/KgZ5xW2nAVjVeTpQS1aVe2PxXS0Z5uCzz8o4JgyBbQAaBrYZuawRgWQ
	UTg2nioG9lM=
	=CIPv
	-----END PGP SIGNATURE-----


(5) MIME object in binary domain

It's not necessary to apply MIME-encode to MIME object in binary
domain before it is encoded by PGP.


For example, 

	Content-Type: image/gif
	Content-Transfer-Encoding: Base64

	[lines which is result of base64]

is O.K. And

	Content-Type: image/gif
	Content-Transfer-Encoding: binary

	[binary stream comes here]

is also permitted. Note that CTE: MUST be specified unless the
content-body is not in 7bit domain.

Since we don't specify "-t" option for this MIME object, line break
problem occurs. So, line break of content-header must be converted to
CRLF before this object is passed to PGP.

	Content-Type: image/gif<CR><LF>
	Content-Transfer-Encoding: binary<CR><LF>
	<CR><LF>
	[binary stream comes here]


(6) PGP warning message

Where to report warning?  Yeah, it's a problem.

--
