Subject: RE: Literal packets and canonicalization

From: "Hasnain Mujtaba" <[email-masked]>
Date: Thu, 6 May 2004 16:27:49 -0400

Thank you for the answer David. If, as the RFC states, we canoncialize
the data before storing it in the literal packet, then the
implementation is tampering with the file before performing the
operation, say encryption. When I use GPG to encrypt and decrypt a text
file, the checksums of the source text file and the decrypted file are
the same. So, the file in not being canonicalized prior to encryption?

-----Original Message-----
From: [email-masked]
[mailto:[email-masked]] On Behalf Of David Shaw
Sent: Thursday, May 06, 2004 3:56 PM
To: [email-masked]
Subject: Re: Literal packets and canonicalization

On Thu, May 06, 2004 at 03:10:17PM -0400, Hasnain Mujtaba wrote:
> 
> Hello,
> 
> I was reading section "5.9. Literal Data Packet" of RFC2440 and I had
a
> question: What are the concequences of not canonicalizing text data
> before storing it in a literal packet and using the literal packet to
> form either an encrypted packet or signature packet? 

The file should decrypt properly, and (at least in PGP and GnuPG)
signatures should verify properly regardless of the canonicalization.

> What if the sender marks all literal data as binary 'b', even if the
> literal data is text?   

The bad thing that will happen is that recipients on platforms that
have a different text line ending convention than the sender will see
somewhat mangled text in the output.

For example: Macs generally end lines with CR.  Unix machines
generally end lines with LF.  Sending data from one to the other
without the benefit of canonicalization results in one very long
"line" with occasional CRs or LFs in there.  Some text editor/viewer
programs do heuristics to detect and fix this problem, but it's
generally better to canonicalize which lets the OpenPGP program handle
it automatically.

David

---

From: David Shaw <[email-masked]>
Date: Thu, 6 May 2004 16:49:02 -0400

On Thu, May 06, 2004 at 04:27:49PM -0400, Hasnain Mujtaba wrote:
> operation, say encryption.

"Tampering" is perhaps a little strong.  The canonicalization is part
of the standard, so while it may be tampering, it's legal
tampering. ;)

> When I use GPG to encrypt and decrypt a text file, the checksums of
> the source text file and the decrypted file are the same. So, the
> file in not being canonicalized prior to encryption?

Maybe, maybe not.  If you are encrypting and decrypting that text file
on the same platform, then you would expect to end up with the same
file since the data is canonicalized on the way in, and
decanonicalized on the way out.

Alternately, if you specified the text file as binary, then no
canonicalization is done.

GnuPG uses the "--textmode" switch to turn on canonicalization.  PGP
has a checkbox for it named something like "Input is text".

David