Daniel Danopia wrote:
Here’s the Base64 of my .cert file (I have a .key and .cert):
Hmm, a PEM would have been much safer. Anyway I’ve attempted to
reconstruct the base64. When I do and then decode it to binary I get 940
bytes, with SHA1
cf0d16a0dde94fec3814d21a7c6daed6c17fd9cd. It does seem to parse:
I presume “prehash” is what the Java had before hashing, and if I’ve
decoded your base64 correctly, that has 942 bytes, with SHA1
50251d690f2a9e15e029080bc3324ba16dd40ce6
So I would attempt to build pkipath like this:
c = OpenSSL::X509::Certificate.new(File.read(“tst.cert”))
=> #<OpenSSL::X509::Certificate subject=/C=US/ST=New
Jersey/L=Landisville/O=Danopia/OU=Google
Wave/CN=danopia.net/[email protected], issuer=/C=US/ST=New
Jersey/L=Landisville/O=Danopia/OU=Google
Wave/CN=danopia.net/[email protected],
serial=13989293735443484870, not_before=Sat Oct 17 21:42:51 UTC 2009,
not_after=Sun Oct 17 21:42:51 UTC 2010>
pkipath = OpenSSL::ASN1::Sequence.new([c]).to_der
This gives me 944 bytes.
Now I can suggest a couple of tools to debug this. A low-level one is
hexdump -C tst.cert >tst.cert.hd
which shows what you found before: differences starting at pos 0x17e
(382)
$ diff -u prehash.hd cert2.hd
— prehash.hd 2009-10-22 08:28:29.000000000 +0100
+++ cert2.hd 2009-10-22 08:28:34.000000000 +0100
@@ -21,40 +21,40 @@
00000140 65 20 57 61 76 65 31 14 30 12 06 03 55 04 03 13 |e
Wave1.0…U…|
00000150 0b 64 61 6e 6f 70 69 61 2e 6e 65 74 31 1d 30 1b
|.danopia.net1.0.|
00000160 06 09 2a 86 48 86 f7 0d 01 09 01 16 0e 6d 65 40
|….H…me@|
-00000170 64 61 6e 6f 70 69 61 2e 6e 65 74 30 81 9f 33 41
|danopia.net0…3A|
-00000180 82 4a a1 92 21 bd c3 40 40 40 41 40 00 e0 63 40
|.J…!..@@@A@…c@|
…
+00000170 64 61 6e 6f 70 69 61 2e 6e 65 74 30 81 9f 30 0d
|danopia.net0…0.|
+00000180 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 81 8d
|….H…|
Notice also that in cert2.hd at offset 0270…0300 you can see the
details of the signing certificate, whilst this appears to be garbage in
prehash.hd
A more useful tool is:
openssl asn1parse -inform der -in tst.cert >tst.cert.txt
This decodes your original certificate and my cert2, but it fails
entirely on the ‘prehash’:
$ openssl asn1parse -inform der -in prehash >prehash.txt
10767:error:0D07209B:asn1 encoding routines:ASN1_get_object:too
long:asn1_lib.c:142:
So whatever is in your ‘prehash’, it’s not valid ASN.1
This suggests to me that perhaps the file was corrupted on its way out
from Java (a text/binary problem??) Perhaps you could print the prehash
size from within the Java?
Also, I’ve just remembered that the final output of the Java is some
sort of hash of this string. Can you replicate this in Ruby to confirm
that the extracted prehash is accurate? Can you post the hash and the
algorithm used, just for sanity checking?
Regards,
Brian.