Article View: news.software.nntp
Article #63287Re: Content-SHA1-Tree
From: Curt Welch
Date: Sat, 18 Jan 2003 19:33
Date: Sat, 18 Jan 2003 19:33
275 lines
14209 bytes
14209 bytes
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?
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".
"Content-full-file-SHA1-22500-Tree:" would be type type of header which
would hold the full-file hash for the data which this segement came from.
> ----- begins -----
> Content-SHA1-Tree is a header which is used to verify the correct
> transfer of a file. It differs from most other hashes in that it can
> verify individual fragments of a file, with only the information
> included in this header and the fragment itself.
>
> The basic principle is to create an identifying hash which builds on a
> tree of hashes. The file is split into blocks and the data in each
> block is hashed, using SHA1 as the hashing algorithm.
>
> +--------+--------+--------+--------+-- - - --+--------+
> | block1 | block2 | block3 | block4 | | block8 |
> +--------+--------+--------+--------+-- - - --+--------+
> | | | | |
> v v v v v
> hash1 hash2 hash3 hash4 ... hash8
>
> Each hashN is a 160 bits value. Concatenate hash1 and hash2, and run
> SHA1 on those 320 bits. Let's call the resulting hash value hash12.
> Do the same for hash3 and hash4, etc. Now move up a level, and run
> SHA1 on the concatenation of hash12 and hash34, etc. Finally,
> concatenate hash1234 and hash5678, run SHA1 on it. The result is the
> hash used to identify the file.
>
> hash1 hash2 hash3 hash4 hash5 hash6 hash7 hash8
> | | | | | | | |
> +---+---+ +---+---+ +---+---+ +---+---+
> | | | |
> hash12 hash34 hash56 hash78
> | | | |
> +-------+-------+ +-------+-------+
> | |
> hash1234 hash5678
> | |
> +---------------+---------------+
> |
> identifying hash
>
> If we have all the data and the identifying hash, it is easy to verify
> that the hash matches. If we only have some of the data (and the
> identifying hash),
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.
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?
Full-File-Details: size=NNN; hash=XXX
???
> we need either more data, or more hashes. Let's
> say the file in question was split in three, with the first fragment
> containing three blocks. It is easy to calculate hash1, hash2, hash3
> and hash12 from the data, but then we're stuck. To continue the
> calculation, we need hash4. Now we can calculate hash34 and hash1234.
> If we're supplied with hash5678 as well, the identifying hash can be
> verified. Hence, the first fragment only needs the hashes hash4 and
> hash5678 to verify that the first three blocks are a genuine part of
> the complete file.
>
> To complete the example: Fragment 2, containing blocks 4, 5 and 6,
> needs hashes hash12, hash3 and hash78. The last fragment needs hashes
> hash1234 and hash56.
>
> In order to fool this algorithm into verifying false data, you would
> have to find a (false) value for hash5678, which, when hashed with the
> hash1234 calculated from the false data, gives the identifying hash as
> its answer. SHA1 is considered a cryptographically secure hash, that
> is, there is no known way to create data which produces a given hash.
> With current technology, this requires a brute force attack in a 160
> bits namespace, and there isn't even any guarantee that the wanted
> value can be found.
>
> 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?
> 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.
In xBin, we are talking about craming all that data in the Message-ID. No
one would every do that for a "real" standard designed from the ground up
to put this data in the headers. We are talking about doing this only
because of the evolutionary needs of Usenet. Putting it in the Message-Id
will make the system work very well for all existing news servers.
I doubt that defining a Message-ID format to include this data could every
become a MIME standard. It's just too "wrong". But it would fit in MIME
as other types of headers.
MIME has no support for the notion of a "file segment". It could be added,
but it's going to get very complex and effect the "meaning" of many of the
current MIME headers.
What is the correct content-type for a segment of a jpg file? Is it
image/jpg or is it something like:
Content-Type: application/octet-stream; file-content=image/jpg;
Or, if you were going to redfeine MIME from the ground up to support this
correctly, should be:
Content-Type: file-segment/image/jpg
Or should it be:
Content-Type: file/segment
File-Content-Type: image/jpg
These are all complex issues that have to be figured out to correctly
support xBin-like file segments in MIME and until you think about and find
the best answers to all these issues, knowing the correct answer to how to
create a Content-Xbin-Signature: header is going to be very hard.
> 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".
> The total size of the file and the offset of the fragment into the
> complete file is information which must be available from other
> headers, e.g., Content-Disposition.
>
> 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:
For completeness, here is the header for fragment 2 which containes
blocks 4, 5 and 6:
Content-SHA1-Tree: id-hash hash12 hash3 hash78
And fragment 3, which containes blocks 7 and 8:
Content-SHA1-Tree: id-hash hash1234 hash56
> 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.
The numbers (but not the hash) in the Message-ID I encoded as base64
numbers. (i.e. right to left with leading zeros removed).
> 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?
> 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.
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????
> The last block may be less than that,
> but there is no need to zero-pad the data (it will actually give the
> wrong result if you do), SHA1 accepts blocks of data of arbitrary
> size.
>
> ----- ends -----
>
> 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. 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.
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.
xBin is very much the idea that the newsreader application "knows" what it
is transporting instead of using an external application (like winrar/par)
to deal with the data after it's extracted by the newsreader. So, all this
stuff belongs in the headers. 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.
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.
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. 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.
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....
--
Curt Welch http://CurtWelch.Com/
curt@kcwc.com Webmaster for http://NewsReader.Com/
Technical Details
Message-ID:
<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!news.uchicago.edu!yellow.newsread.com!netaxs.com!newsread.com!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mailReferences:
<1r3co0fjr2.fsf@vingodur.ifi.uio.no>Show Full Headers
Complete Article Headers
Message-ID: <20030118143342.130$IV@newsreader.com>
Subject: Re: Content-SHA1-Tree
Date: Sat, 18 Jan 2003 19:33:42 +0000
From: curt@kcwc.com (Curt Welch)
References: <1r3co0fjr2.fsf@vingodur.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!news.uchicago.edu!yellow.newsread.com!netaxs.com!newsread.com!feed1.newsreader.com!newsreader.com!news2.newsreader.com!ellis.newsreader.com!not-for-mail
Organization: NewsReader.Com
Newsgroups: news.software.nntp
X-Trace: NewsReader.Com AL6pAqq1-UCzNp9fl2EoZPyGmE=,9BoRh.J,sRh2haM2T.V3c
X-Face: "p}G*1KH{+F7EYGKLb>ogDguabZ+%,?^epeFB!nzu`)`$=QcvL1KF6<0GH!Tbc!Sqo[|tV5
%IW48mQf3K=Ci&gZ7]]aazx@]Y-nq!r5{yH/#,?@lDdUDvOfByB2hVW0.@OM%{l/{cT'{w
X-Url: http://CurtWelch.Com/
User-Agent: NewsReader.Com
Lines: 274