🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #63296

Re: Content-SHA1-Tree

#63296
From: Kjetil Torgrim Homme
Date: Sun, 19 Jan 2003 00:38
291 lines
14213 bytes
[Curt Welch]:
>
>   Kjetil Torgrim Homme <kjetilho@haey.ifi.uio.no> wrote:
>   > I thought I'd try my hand at writing a specification of
>   > Content-SHA1-Tree, but before foisting it on the MIME people, I guess
>   > it's best that people here (at least Curt) has a look at it and sees
>   > that it is right.
>   
>   The first issue is the name.  I'm not sure what it should
>   be. SHA1-Tree implies to me that it's either just the hash value
>   of the content, or it's the entire tree of hash values.  But the
>   xBin-Siganture header is not a hash value of the content of the
>   article, it's hash values of all the data from the full file which
>   is not included in this article.
>   
>   MIME supports some digital signature standards doesn't it?  What
>   type of MIME headers are used to hold signature data?  Is it a
>   Content-? header?

they use a multipart with two content-types, application/pkcs7-mime
and application/pkcs7-signature.

>   I'm thinking you need something like Content-Xbin-Signature:
>   instead of trying to think of it as a "generic" hash system which
>   is what happens when you use "SHA1-Tree".

perhaps, but SHA1-Tree is more descriptive (and not strictly wrong)
than Xbin-Signature.  SHA1-Tree sounds more sexy, Xbin-Signature
sounds like something cooked up in a bedroom.  perhaps
"SHA1-Signature"?  or "Tree-Signature"?  not a big issue for me,
though.

>   I put the full-file hash in the Signature: header not because it
>   was needed there, but because the full hash was not included in
>   the Message-ID.  If we were to put the full hash in the
>   Message-ID, then you wouldn't want the full hash to be included in
>   the Signature data.

right, but that's not an option, since you can have multiple parts
(files) in a MIME message.  each part could have its own signature.

>   In the MIME way of things, if you needed the full hash in the
>   headers I would expect it to show up either in a different header,
>   (Content-Full-File-XBin-Hash:) or show up at a named paramater in
>   some other header?

why?  I think it fits naturally as the first hash in the signature
data.  another header makes the parser more complex.

>   Full-File-Details: size=NNN; hash=XXX
>   
>   ???

the header name must begin with "Content-".  MIME is both very strict
and very lenient about this, since it will accept any unknown
Content-Header, but disallow any NonContent-Header.

>   > Content-SHA1-Tree contains the hashes needed to verify a fragment.  In
>   > the above example, the header of the first fragment is:
>   >
>   >   Content-SHA1-Tree: id-hash hash4 hash5678
>   
>   Is the format of having data separated by spaces consistent with
>   the way MIME likes to do things?

yeah, I think so.

>   > The first hash in the list is always the identifying hash, but
>   > notice that there is nothing to identify hash4 as hash4.  This
>   > must be deduced from the total size of the file and which blocks
>   > are included in the fragment.
>   
>   Which points out that to understand this header, you must have
>   that other data.  I think that pretty much means you need to
>   define how that would be done in Mime Headers as well and you
>   won't be able to get this header defined as a standard without
>   also defining those headers.

that's why I'm pushing for extending Content-Disposition with this
data in comp.mail.mime.  so far, I've had little success, people want
to do Content-Type: application/fragment, which I think is a horrible
layering violation (this was Jeremy's suggestion as well, a year ago).
it's interesting to note that there is no requirement to have an
approved RFC to register a new parameter for Content-Disposition, it
suffices to present a description for its semantics to IANA.  it's
more important to convince Chris Morse than the MIME crowd, if you
know what I'm saying.

>   I doubt that defining a Message-ID format to include this data
>   could every become a MIME standard.  It's just too "wrong".

definitely.

>   What is the correct content-type for a segment of a jpg file?

there is no mechanism for it.

>   > Given that information, the above tree can be constructed, and
>   > it is easy to spot which hashes are needed.  The order of the
>   > hashes is from the root and up, left to right, depth first.
>   
>   I would leave the "up" vs "down" vs "right" vs "left" issues out
>   of that and just say: "depth first low to high".
>   
>   You could also simply say, "low to high".

noted.

>   > For completeness, here are the headers for fragment 2 and 3:
>   >
>   >   Content-SHA1-Tree: id-hash hash12 hash3 hash78
>   >   Content-SHA1-Tree: id-hash hash1234 hash56
>   
>   Ah, I see, I first though you got that wrong because when you said
>   "fragment 2" I was thinking block 2.  It could be clearer:

noted.

>   > Each hash is a 160-bit number presented in BASE64.  It will
>   > generally require 27 characters to encode, but with many leading
>   > zero bits, it can be less.
>   
>   I encoded it not as a 160 bit number but as 20 bytes in straight
>   MIME BASE64, which means you chop it into 6 bit chunks left to
>   right instead of right to left and you do not remove leading
>   zeros.

do you think that is superior?

>   The numbers (but not the hash) in the Message-ID I encoded as base64
>   numbers. (i.e. right to left with leading zeros removed).

that's why I chose to represent the hash the same way, the code must
have a function to transform a number into BASE64, anyway.  the
question is: is it better to require the implementation to have _one_
generalised function than to require it to have _two_ functions which
are slightly easier to implement?

oh!  we need to specify whether the numbers are encoded as little- or
big-endian.  little-endian is a tiny bit easier to code, just do:

  while number > 0
    output number AND 111111b
    number SHIFT RIGHT 6

big-endian needs buffering to reverse the order of the octets.
intuitively, as a Westerner, I'd expect the numbers to be big-endian.

>   > When used with large files, the number of hashes can become
>   > quite large.  It is suggested that the header is folded on
>   > whitespace to keep line length down.
>   
>   What does MIME say about header lengths?  Anything?

RFC 2047 says:

   While there is no limit to the length of a multiple-line header
   field, each line of a header field that contains one or more
   'encoded-word's is limited to 76 characters.

we don't use encoded-words, so we're actually free to do what we like
within the bounds of the transmitting protocol (SMTP or NNTP).

>   > The size of a block must be constant across implementations.  The
>   > chosen value is 22500 octets.
>   
>   I'e had second thoughts about that which I hope to post here at
>   some points.

well, it is easy to change this number during discussion.

>   For now, my argument of being uuencode compatible and the lack of
>   any real need to be power of two based is valid.  But down the
>   road, I see servers optimized to store these blocks, and at that
>   point, power-of-two sized junks would be justified.  So maybe it
>   does make sense to try and make it a power-of-two based hash block
>   size now.  The question then becomes, how much problem will this
>   cause for uuencode posts????

you've still convinced me that the overhead for the non-power-of-two
is down in the noise.  500 line blocks is also friendly to uuencode
users.  MIME users don't do multipart posts, so they probably don't
have any feel for how many lines a post should be chopped into.  (76
BASE64 digits gives a block size of 394.7 lines :-)

>   > did I miss anything an implementer needs to know?  can the
>   > presentation be improved (of course it can!  please help! :-)
>   
>   Your post is good.  But the complex problem is that you are
>   starting to define how it will all fit into MIME.  I don't think
>   you can get away with defining only this one header now.

right, there are three pieces to the puzzle:

  the signature
  the fragment information
  the Message-ID convention

MIME will not care about that last one.  it's just an optimisation
hack for news.

>   If you could, then we could use that as the standard X-Bin header
>   even for non-MIME posts.  And that seems like it would be wise. So
>   looking into this future seems worth the time.

uuencoded posts can use the MIME headers, but shouldn't include
"MIME-Version: 1.0" unless the document is well-formed.  (it can be,
but it is not common to do that -- why bother when BASE64 is more
efficient anyway?)

>   But MIME just doesn't currently support the concept of a
>   file-segment.  You can transport them in MIME of course as generic
>   application/octect-stream data chunks, but then that approach
>   would encourage you to put the file informaion and the signature
>   information into the data instead of in the MIME headers.  i.e.,
>   either "what you are trasporting" is hidden to the MIME
>   application (the application/octet-stream" approach, or the "what
>   you are transporting" is "known" to the mime application, in which
>   case the signature and other full-file information needs to be in
>   the MIME headers.

yeah.  I detest that approach.

>   So, for it do be done correctly in MIME, it needs to be defined at
>   the MIME header level, like you are tying to do here.  But to be
>   compatible with all other MIME aware clients which have allready
>   been writen without any support for the idea of a "file segment",
>   it's going to be a bit complex to figure out the best way to
>   shoe-horn this very basic concept into a standard (and all the
>   existing applications) which were never meant to support it.

any new feature needs new code to support it.  by adding the fragment
information to Content-Disposition, old clients will simply store or
present the fragment as if it was the complete file.  the user can
piece them together himself if he elects to save to disk.  the icky
point is preview, since the fragment will lack the headers of the
complete file.  a quality implementation will of course handle bogus
data without incident and tell the user that the decode failed.  a bad
implementation may crash, it's even conceivable you can smash its
stack.  but a malcious user could have sent that fragment as if it was
a complete file anyway, so it doesn't impact the security
considerations.

>   I'm sure this can be done, and it's probably not even that hard,
>   but I do suspect it's a lot of work and I suspect that trying to
>   define one header like Content-SHA1-Tree without addressing the
>   entire problem would be the wrong approach.

I try to address the entire problem, but I also try to keep separate
issues separate.  fragmentation is useful even without a signature to
verify its integrity.  similarily, Content-SHA1-Tree can be used on a
file posted in a single article (it will contain only the root hash),
although in that case most people would choose to use the existing
Content-MD5 instead.  but the mechanisms are orthogonal.

>   My thought is that it would be better to leave MIME out of the
>   problem intentionally for now, and create something that's custom
>   designed to solve the problems of Usenet.

let me here what you think needs be different.

>   Then, later, if the standard catches on for Usenet, the MIME guys
>   might be motivated to attack the general problem of the correct
>   way to support "file-segments" in MIME messages.  Once that was
>   done, and if it was done correctly so it could support xBin
>   messages, then Usenet could evolve to correctly labeling all the
>   xBin articles with the correct MIME headers as well.

yEnc and uuencode makes such a mess of even basic things like
filenames -- it would be benificial to allow Content-Type and
Content-Disposition to override their cruft.  but a
Content-Disposition containing only "offset=NNNN; total-size=NNNN"
would be sufficient of course.

>   It would be good if we could take a stab like you have done to see
>   what the header "should" look like to fit in MIME.  If a later
>   version of MIME could use the same header, it would of course make
>   the conversion to MIME easier later.  But it just always seems
>   that the standards that come later are always forced to change
>   something anyhow and that the odds of picking something know that
>   will work later with MIME are very small....

we can do this in MIME today[1].  neither Content-X nor parameters for
Content-Disposition require concensus in the working groups.

[1] well, in a week's time, it will probably take some time to
percolate to the top of IANA's stack of pending registrations.
-- 
Kjetil T.			|  read and make up your own mind
				|  http://www.cactus48.com/truth.html
Technical Details
Message-ID: <1ru1g6j7o4.fsf@fjorir.ifi.uio.no>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!freenix!deine.net!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail
References: <1r3co0fjr2.fsf@vingodur.ifi.uio.no> <20030118143342.130$IV@newsreader.com>

Show Full Headers
Complete Article Headers
Message-ID: <1ru1g6j7o4.fsf@fjorir.ifi.uio.no>
Subject: Re: Content-SHA1-Tree
Date: Sun, 19 Jan 2003 00:38:03 +0000
From: Kjetil Torgrim Homme <kjetilho@haey.ifi.uio.no>
References: <1r3co0fjr2.fsf@vingodur.ifi.uio.no> <20030118143342.130$IV@newsreader.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!newsmi-us.news.garr.it!NewsITBone-GARR!news.mailgate.org!newsfeed.icl.net!newsfeed.fjserv.net!proxad.net!freenix!deine.net!uio.no!nntp.uio.no!ifi.uio.no!not-for-mail
Newsgroups: news.software.nntp
Organization: Dept. of Informatics, Univ. of Oslo, Norway
Lines: 290
NNTP-Posting-Host: fjorir.ifi.uio.no
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Trace: maud.ifi.uio.no 1042936684 16205 129.240.65.204 (19 Jan 2003 00:38:04 GMT)
X-Complaints-To: abuse@ifi.uio.no
NNTP-Posting-Date: 19 Jan 2003 00:38:04 GMT
User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7