Name: js-handler/node_modules/restify/node_modules/http-signature/README.md
| 1: | # node-http-signature |
| 2: | |
| 3: | node-http-signature is a node.js library that has client and server components |
| 4: | for Joyent's [HTTP Signature Scheme](http_signing.md). |
| 5: | |
| 6: | ## Usage |
| 7: | |
| 8: | Note the example below signs a request with the same key/cert used to start an |
| 9: | HTTP server. This is almost certainly not what you actaully want, but is just |
| 10: | used to illustrate the API calls; you will need to provide your own key |
| 11: | management in addition to this library. |
| 12: | |
| 13: | ### Client |
| 14: | |
| 15: | var fs = require('fs'); |
| 16: | var https = require('https'); |
| 17: | var httpSignature = require('http-signature'); |
| 18: | |
| 19: | var key = fs.readFileSync('./key.pem', 'ascii'); |
| 20: | |
| 21: | var options = { |
| 22: | host: 'localhost', |
| 23: | port: 8443, |
| 24: | path: '/', |
| 25: | method: 'GET', |
| 26: | headers: {} |
| 27: | }; |
| 28: | |
| 29: | // Adds a 'Date' header in, signs it, and adds the |
| 30: | // 'Authorization' header in. |
| 31: | var req = https.request(options, function(res) { |
| 32: | console.log(res.statusCode); |
| 33: | }); |
| 34: | |
| 35: | |
| 36: | httpSignature.sign(req, { |
| 37: | key: key, |
| 38: | keyId: './cert.pem' |
| 39: | }); |
| 40: | |
| 41: | req.end(); |
| 42: | |
| 43: | ### Server |
| 44: | |
| 45: | var fs = require('fs'); |
| 46: | var https = require('https'); |
| 47: | var httpSignature = require('http-signature'); |
| 48: | |
| 49: | var options = { |
| 50: | key: fs.readFileSync('./key.pem'), |
| 51: | cert: fs.readFileSync('./cert.pem') |
| 52: | }; |
| 53: | |
| 54: | https.createServer(options, function (req, res) { |
| 55: | var rc = 200; |
| 56: | var parsed = httpSignature.parseRequest(req); |
| 57: | var pub = fs.readFileSync(parsed.keyId, 'ascii'); |
| 58: | if (!httpSignature.verifySignature(parsed, pub)) |
| 59: | rc = 401; |
| 60: | |
| 61: | res.writeHead(rc); |
| 62: | res.end(); |
| 63: | }).listen(8443); |
| 64: | |
| 65: | ## Installation |
| 66: | |
| 67: | npm install http-signature |
| 68: | |
| 69: | ## License |
| 70: | |
| 71: | MIT. |
| 72: | |
| 73: | ## Bugs |
| 74: | |
| 75: | See <https://github.com/joyent/node-http-signature/issues>. |
