Created
August 3, 2015 17:46
-
-
Save melvincarvalho/daff42c04f645fd14772 to your computer and use it in GitHub Desktop.
sign a nonce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env node | |
| var forge = require('node-forge'); | |
| var sshprivkey = require('./sshprivkey.js'); | |
| var sshpubkey = require('./sshpubkey.js'); | |
| sshprivkey('./id_rsa.1', function(err, ret) { | |
| if(err) { | |
| console.error(err); | |
| } | |
| var nonce = 'MTQzODYxNzUyNnwzWjZkYm5nREE2aUFRRDJuQlVfbmY5bGdqcUdqVkRkRWlPVEhEcVdJVjdrTEpMeWYtNzVQRXBLZVJyaVBVTmdHTU9CaTV2aF9YMDhLa1FMWFIxNVFLU1JHYUw5NXzvvu7exS2PKlT13aosgSpau6T0A_CPtDyTKzboN8Hjlw=='; | |
| console.log(nonce); | |
| var source = 'https://public.databox.me/Public/acltest'; | |
| var username = 'http://gitpay.org/melvincarvalho#this'; | |
| var cipher = source + username + nonce; | |
| var md = forge.md.sha1.create(); | |
| md.update(cipher, 'utf8'); | |
| var sig = forge.util.encode64(ret.private.sign( md )); | |
| console.log("curl -H 'Authorization: WebID-RSA source=\""+ source +"\", username=\""+ username +"\", nonce=\""+ nonce +"\", sig=\""+ sig +"\"' https://public.databox.me/Public/acltest"); | |
| sshpubkey('./id_rsa.1.pub', function(err, ret) { | |
| if(err) { | |
| console.error(err); | |
| } | |
| //var md = forge.md.sha1.create(); | |
| //md.update(sig, 'utf8'); | |
| console.log(sig); | |
| var verified = ret.public.verify(md.digest().bytes(), forge.util.decode64(sig)); | |
| console.log(verified); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment