Phil Marlowe ([EMAIL PROTECTED]) wrote:

> I'd like a quick and easy method of deriving the CHK key for a document, 
> other than reading the nodes' response to a successful insert.

The Java is nearly indecipherable to me.  But it's got something to do
with an SHA-1 digest, and a base-64 encoding, and the number 0x0302.

freenet/src/freenet/crypt/SHA1.java gives us some sample test strings
and their SHA-1 digests.  So let's start with:

jekyll$ echo -n abc | openssl dgst -sha1 
a9993e364706816aba3e25717850c26c9cd0d89d

That matches the first test string listed in the SHA1.java source code.
So far so good.  This is a 40-digit hex number, which is 160 bits of
information.

Now let's insert this key into Freenet:

jekyll:~$ echo -n abc >abc
jekyll:~$ CLASSPATH=~freenet/freenet-ext.jar:~freenet/freenet.jar java 
freenet.client.cli.Main put --htl 0 CHK@ <abc
LALA: 
State PREPARED reached.
State REQUESTING reached.
Transfer of 26 bytes started.
23 bytes transferred.
Transfer ended with 26 bytes moved.
Insert URI -
freenet:CHK@YzHLBuNS4cxy8vi82SbA9rb7BBsKAwI,dliOt6Q1Ih0eILULih-bmQ
The insert has been accepted; waiting up to 56 seconds for the StoreData
State DONE reached.
Document metadata:

Version
Revision=1
End

So the question now becomes: how do we convert
"a9993e364706816aba3e25717850c26c9cd0d89d" into
"CHK@YzHLBuNS4cxy8vi82SbA9rb7BBsKAwI,dliOt6Q1Ih0eILULih-bmQ"?

The next clue apparently comes from a comment at the top of the source
file freenet/src/freenet/client/FreenetURI.java; it says:

 * freenet:[KeyType@]RoutingKey[,CryptoKey][,n1=v1,n2=v2,...][/docname][//metastring]

So apparently, our CHK is actually constructed of the following pieces:

 KeyType: CHK
 RoutingKey: YzHLBuNS4cxy8vi82SbA9rb7BBsKAwI
 CryptoKey: dliOt6Q1Ih0eILULih-bmQ

client/FreenetURI.java also says:

 * RoutingKey is the modified Base64 encoded key value.
 * CryptoKey is the modified Base64 encoded decryption key.

So apparently one should be able to base64-decode the RoutingKey and get
something that contains, possibly among other things, the 160-bit SHA-1
digest.

Unfortunately, this is where I hit a brick wall.  I get this far:

jekyll$ perl -e 'use MIME::Base64; print 
decode_base64("YzHLBuNS4cxy8vi82SbA9rb7BBsKAwI");' | hex
0x00000000: 63 31 cb 06 e3 52 e1 cc - 72 f2 f8 bc d9 26 c0 f6 c1.F.R��r����&��
0x00000010: b6 fb 04 1b 0a 03 02    -                         ��D[JCB

I see the magic number "0302" which I also saw in keys/CHK.java -- so that
seems like a good sign.  But I don't see "a9 99 93" anywhere in there.

So apparently I suck both as a Java interpreter and as a reverse
engineer. :(  But maybe someone else can pick it up from here.  Or maybe
somewhere out there in the strange world of Freenet there's actual
human-readable documentation which is a tiny bit more verbose than
<http://freenetproject.org/cgi-bin/twiki/view/Glossary/Keys> is.

> My reasons are convoluted, but they have to do with an attempt to come up 
> with a utility to insert large sites.  Right now fcpputsite is very 
> perfectionist.  It  will only write a mapfile if every single page has 
> inserted successfully *in this run*.  I think that's too much to ask.  I'm 
> thinking along the lines of a daemon, that keeps trying to insert documents 
> of a very large non-DBR site.  If the index.html and mapfile get out there, 
> then the site is partly useable, and that's better than nothing.  The rest 
> of the site will presumably make it out there eventually.

I will personally worship you if you make a usable fcptools.  Hell,
I might even attempt to *use* it again!

-- 
Greg Wooledge                  |   "Truth belongs to everybody."
[EMAIL PROTECTED]              |    - The Red Hot Chili Peppers
http://wooledge.org/~greg/     |

Attachment: msg03118/pgp00000.pgp
Description: PGP signature

Reply via email to