Nefario (OP)
|
|
May 23, 2011, 07:46:20 AM Last edit: May 23, 2011, 08:31:51 AM by Nefario |
|
I hate Javascript, hate it with a passion The person that solves this will get 70Bitcoins, and can (for another 120Bitcoins) continue on and develope this into an interface for GLBSE. As well as the bitcoin itself there will be major credit for this, and your name will be added to GLBSE's (soon to be created) contributors page. I am attempting to use some Javascript libraries to sign base64 encoded data with an RSA prvate key, the signature is then also encoded base64 which is sent to a server, the server verifies it with the public key, and then I do some stuff. The problem is the JavaScript lib's seem to be signing but the output is not correct. Private key is: -----BEGIN RSA PRIVATE KEY----- MIIEowIBAAKCAQEA9cbXaYIbd41nTHnMcs4KGtsc+N+k4n/yQUJSoEq2F7Tz742a ZZZU+DZCQ7T/4ZHkmTtO2tYY877ptdIn7uJwGEbh6uwqEoO4Q9kYbbMyrsFCFozh Q+Ro0goztGmqcXwn0p1K70Yay/4UbNoZUs86HgsuZyb7pLChzDoAWTp4gzLBxVq9 su9xENuYEd/5viKvwGY7EaKtWqLj4GaM7YPhINwWC+nGI+EobmeTKTxWcFj+/azw 1pv8iXNZ53mc6kVWCCNoEpqrVtV7OJ2rEQoVzfhmcA0ODMqGIg9SpsOOJLcN/8WB B8Oj/cSQuvKotrkUw+4FEHxbv6NULqm102/hcwIDAQABAoIBAB4dNPuqg28MlmGa cuCGOlq8Cjq8PFm8T5SLadBWFyWkeFcbxJU57ENVcp0VKl0bISVdTPYnUXtcIwqy K05r1ExFMx0zvpvyI7u8d+/JCya6azyUGm3VKLrDoT4zzDyHd+GogCv9LP9drGcB +iRZW8eemxrsfdzZ/5kkajKEpYt9iSRmsem2u5ylQb8eA4sfsi1lqU/3OUhf7NpG tq4UFZMCtNmDMdsH97049aqO5PswIY4odN35qHYjn9r4FdSHHY0Cy6qU84dY6Y3z 40erWs4/0yFNSrloc6rXOCiuIz9L9pOVy/ovKWz3T9+lq7/sEBo4tzixI+uNQ00m nzDyjRECgYEA+371ZGI4tSqd77ZbG+GQHJxm8P2TkGSZMeU0jieqAfyLSJkAxuXb lTWXNCkmpkbzHHUzFMkjNhg8qYfOETdHnebmypgL/1V+lYxbAhgN/guP0a7GHo1v fXSk2k+F6/sI4JGi072JF3y0jSBIH64Zy1rotksBuBqFI+onYxfZnWcCgYEA+i2p b321Wk0fjM0FYzaQPOaqFQqKpFaY3PMcioLxByYXjLl99m+iJbTe0QUq72juoNmk rJnK8vQs/1rDLO5ShMxcJ7tyOyOQosKYMBiXBELd224OQFLwxiIylWtAkZpe/Y9o IGEEz5OX7PA/b6t5OIEo98G0pGNXvMiPcm+HSBUCgYAHpuM8fKiRCoznoDrBbGmA FVokdvKocAchN4IT2S0ZBmAOg2k8o/28WncRRTdB0+LNuNsnBL+ng7FEzzb72xy4 ty/KdjnXOPizACQ8uhKi6iMkFBc/ErqTrJrfcY/3kBnDC2tS2e9z4X101cib/iYW w9tUwI961IO8hgFQyIb8fQKBgQCOg3ZyqYSmhSqE1cHM66cs2iVnSRMDXMVFkEPg 74iIDv35Ty1fNeaDXk5TeYMk0HynKnQxUoaW8du0NyrZrIVbWuLgS1peL/tTjFCP jWJxrfmd50q8/8Jiy9ZO4cLtbqfP/2JMl5fa+3PfKFiqr16lfoYs5K6XunOfegyl Hr1MpQKBgFZ84EaudGufLx1Bo0+v+FcOFfbQxEmkkyJpQwoi6Dvmh/MTe3TNegaY MBf7rm6l65ZqfBMAwRDjE/dhVwRNpd9jRzPVBVyWRZOJkd63n/ENPdIiUrFdvgIt SFNKk00LvLk4VgWBtUbK9wdk8GQHBrd1mNXnni2x0u0VWLDnW5Zs -----END RSA PRIVATE KEY----- The test data being signed is(already base64 encoded): eyJ1c2VyaWQiOiJcdTAwMGFkOTQ2ZWQ2MDFmMTNhNDZmNjU1YjUwODM4N2FmZTc2OWYzNTNiMzk1MmY3YTMzOWE4Mjc3ZTdmMTlkYTU4NGQ4XHUwMDBhIiwibm9uY2UiOjg2MTU2NjE5NTE2NX0= We're using SHA512 as the padding digest. Signature(base64 encoded) should be: AZIigvzu0G2BG/RpDz05qZZctQvzTGNOiOJzziL1+eQEU42cwp/LPOv+6DwMgDIIf2/DAHD+pe7bsxIWftlr65z1bRTYdQ+K+VA0fC6m36muny3NLsKl4hrqIVVWQsTZwbUqJcOvYaNcYMaXr05hTMKC4XAkqKNSqLBOc41k7vU8V6duYwndal7rZiWvso+cH0HxffJszLREUbamMtNBapmhXJCsn2PafQ+RyFj5VnJPYe5MIp/d86yco2q1PC2jLyySxH2kma6d1dq/yxgFiTiABT80w7/9GPlE+cNFIuclEeeYZyo+3r1R7Lgqhnr98MGC7dGjrW5BK5zSRHjgBw==
What I keep getting is: GSIoL87tBtgRv0aQ89OamWXLUL80xjTojic84i9fnkBFONnMKfyzzr/ug8DIAyCH9vwwBw/qXu27 MSFn7Za+uc9W0U2HUPivlQNHwupt+prp8tzS7CpeIa6iFVVkLE2cG1KiXDr2GjXGDGl69OYUzCgu FwJKijUqiwTnONZO71PFenbmMJ3Wpe62Ylr7KPnB9B8X3ybMy0RFG2pjLTQWqZoVyQrJ9j2n0Pkc hY+VZyT2HuTCKf3fOsnKNqtTwtoy8sksR9pJmundXav8sYBYk4gAU/NMO//Rj5RPnDRSLnJRHnmG cqPt69Uey4KoZ6/fDBgu3Ro61uQSuc0kR44A Get the function sign_and_encode(data,private_key) to return the correct output, the fuction (and all it's dependencies) can be found here http://dev.glbse.com:4567/rsa.html just view source. Time is very important, we need to move on ASAP.If needs be you can use another Javscript RSA library if the one being used is simply broken. Note:updated to remove linebreaks from the base64 endoded signature
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
|
|
The forum was founded in 2009 by Satoshi and Sirius. It replaced a
SourceForge forum.
|
|
|
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
|
|
|
de4l
Member
Offline
Activity: 82
Merit: 10
|
|
May 23, 2011, 08:18:13 AM |
|
Signature(base64 encoded) should be: AZIigvzu0G2BG/RpDz05qZZctQvzTGNOiOJzziL1+eQEU42cwp/LPOv+6DwM\ngDIIf2/DAHD+pe7bsxIWftlr65z1bRTYdQ+K+VA0fC6m36muny3NLsKl4hrq\nIVVWQsTZwbUqJcOvYaNcYMaXr05hTMKC4XAkqKNSqLBOc41k7vU8V6duYwnd\nal7rZiWvso+cH0HxffJszLREUbamMtNBapmhXJCsn2PafQ+RyFj5VnJPYe5M\nIp/d86yco2q1PC2jLyySxH2kma6d1dq/yxgFiTiABT80w7/9GPlE+cNFIucl\nEeeYZyo+3r1R7Lgqhnr98MGC7dGjrW5BK5zSRHjgBw==
I'm looking through everything but so far, this does not appear to be a valid base-64 string for me at least ps. or is the implication that this was the (RSA encoded (base-64 encoded(data)) and not (base64(rsa(base64(data))))
|
|
|
|
Nefario (OP)
|
|
May 23, 2011, 08:28:28 AM |
|
Sorry, that seems to be including linebreaks, here it is without the linebreaks(\n). AZIigvzu0G2BG/RpDz05qZZctQvzTGNOiOJzziL1+eQEU42cwp/LPOv+6DwMgDIIf2/DAHD+pe7bsxIWftlr65z1bRTYdQ+K+VA0fC6m36muny3NLsKl4hrqIVVWQsTZwbUqJcOvYaNcYMaXr05hTMKC4XAkqKNSqLBOc41k7vU8V6duYwndal7rZiWvso+cH0HxffJszLREUbamMtNBapmhXJCsn2PafQ+RyFj5VnJPYe5MIp/d86yco2q1PC2jLyySxH2kma6d1dq/yxgFiTiABT80w7/9GPlE+cNFIuclEeeYZyo+3r1R7Lgqhnr98MGC7dGjrW5BK5zSRHjgBw==
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
Jere.Jones
|
|
May 23, 2011, 08:47:45 AM |
|
What is your source for the expected output?
Jere
|
|
|
|
Nefario (OP)
|
|
May 23, 2011, 08:55:52 AM |
|
What is your source for the expected output?
Jere
I've been using ruby's interface to openssl If you've got ruby installed launch irb. require 'openssl' require 'base64'
privkey="privatekeytext" data="my data string" private_key = OpenSSL::PKey::RSA.new(privkey) b64sig=Base64.encode64(private_key.sign( OpenSSL::Digest::SHA512.new, data)) I know it works as I've been using it on glbse since before we launched.
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
Nefario (OP)
|
|
May 23, 2011, 09:04:39 AM |
|
You can actually just use the source from the page linked(it's a static page), if it works with that then it should just plain old work, so a link to a html page with all the js source in it would be fine(essentially a copy of the one I linked to).
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
weweritz
Newbie
Offline
Activity: 2
Merit: 0
|
|
May 23, 2011, 09:23:52 AM |
|
Funny thing, this. The problem is in the rsa.signString function that returns the hex value of the signature. Javascript incorrectly discards the leading zero (1922282fceed0... instead of 01922282fceed0...) and when you convert this to binary and then base64encode it, naturally, everything goes wrong. With the extra zero, the output is as specified.
|
|
|
|
Nefario (OP)
|
|
May 23, 2011, 09:28:42 AM |
|
Funny thing, this. The problem is in the rsa.signString function that returns the hex value of the signature. Javascript incorrectly discards the leading zero (1922282fceed0... instead of 01922282fceed0...) and when you convert this to binary and then base64encode it, naturally, everything goes wrong. With the extra zero, the output is as specified.
Nice, you found a bug(not my code). Do you know if a leading 0 needs to be added with all output or just this instance?
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
de4l
Member
Offline
Activity: 82
Merit: 10
|
|
May 23, 2011, 09:38:17 AM |
|
you could also just un-comment the base-64 output built into rsa.js and use that instead of the additional (lossy) conversion steps
|
|
|
|
weweritz
Newbie
Offline
Activity: 2
Merit: 0
|
|
May 23, 2011, 09:39:52 AM |
|
The hex that the stringSign function returns should be 512 characters long. If it is any shorter, prepend the number of zeroes that are missing; something along the lines while ( String( hSig ).length < 512 ) hSig = "0" + String( hSig );
should work.
|
|
|
|
mikegogulski
|
|
May 23, 2011, 09:46:04 AM |
|
I succeeded in getting "shitassfuck" as output from your test script!
|
|
|
|
Jere.Jones
|
|
May 23, 2011, 09:49:49 AM |
|
The hex that the stringSign function returns should be 512 characters long. If it is any shorter, prepend the number of zeroes that are missing; something along the lines while ( String( hSig ).length < 512 ) hSig = "0" + String( hSig );
should work. Unfortunately, that won't work because the bad version is 2 characters short. A zero on the front and a 7 on the back. There's a bug in bnToString(b) in jsbn.js that needs to be fixed. Jere
|
|
|
|
arturh
Jr. Member
Offline
Activity: 59
Merit: 10
|
|
May 23, 2011, 10:06:55 AM |
|
Add needed zeroes to s:
s = new Array(257-s.length).join("0") + s;
|
|
|
|
Nefario (OP)
|
|
May 23, 2011, 10:18:01 AM |
|
I succeeded in getting "shitassfuck" as output from your test script! Thats more than the stated requirements
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
Jere.Jones
|
|
May 23, 2011, 10:20:35 AM |
|
Here you go: Replace your jsbn.js with the one located at http://jere.us/jsbn.zip and you'll be good to go. It properly fixes the bnToString so that it outputs full hex bytes instead of skipping the first 4 bits when there isn't data for them. Jere
|
|
|
|
Jere.Jones
|
|
May 23, 2011, 10:42:27 AM |
|
I just put up an improved version. You probably want to download it again. The previous version had issues with IE. This one works correctly in IE although doing RSA in IE is annoying. http://jere.us/jsbn.zipJere
|
|
|
|
Nefario (OP)
|
|
May 23, 2011, 10:42:51 AM |
|
I succeeded in getting "shitassfuck" as output from your test script! So to actually test if the whole thing properly works you would change to sendData("account/balance",{}); And the result from the server should be the balance(base64 encoded) if it works, otherwise it's a base64 encoded error(probably bad signature).
|
PGP key id at pgp.mit.edu 0xA68F4B7C To get help and support for GLBSE please email support@glbse.com
|
|
|
|
mikegogulski
|
|
May 23, 2011, 10:48:31 AM |
|
I succeeded in getting "shitassfuck" as output from your test script! So to actually test if the whole thing properly works you would change to sendData("account/balance",{}); And the result from the server should be the balance(base64 encoded) if it works, otherwise it's a base64 encoded error(probably bad signature). ... and here I kinda liked the "shitassfuck" API
|
|
|
|
|
|