node-http-dh-crypto
v0.0.2
Published
secure data passing between http servers
Downloads
3
Readme
node-http-dh-crypto
How it works
- CLIENT generates diffie-hellman key and requests SERVER with the public key.
- SERVER generates diffie-hellman key and calculates cipher key using CLIENT's public key.
- SERVER returns its public key and
id
to CLIENT. - CLIENT calculates cipher key with SERVER's public key. Both SERVER and CLIENT shares temporary key for ciphers.
- CLIENT requests its
id
, and a cipher text encrypting the pre-exchanged password and the message. - SERVER deciphers the cipher text and verify the password.
- If password is correct, SERVER tosses the message to next middleware chain.
Examples
Client
var dhCrypto = require('node-http-dh-crypto');
var bodyParser = require('body-parser');
var dhCryptoClient = dhCrypto.createClient({
password: 'the_cake_is_a_lie!',
host: 'http://localhost:3001',
establishPath: '/establish',
establishMethod: 'POST'
});
app.get('/ping', function (req, res) {
dhCryptoClient.request({
path: '/ping',
method: 'post',
form: {
ping: 416
}
})
.then(function (response) {
console.log(response);
});
});
Server
var dhCrypto = require('node-http-dh-crypto');
var bodyParser = require('body-parser');
var dhCryptoServer = dhCrypto.createServer({
password: 'the_cake_is_a_lie!',
ttl: 120,
});
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/establish', dhCryptoServer.authentication());
app.post('/ping', dhCryptoServer.verification(), function (req, res) {
res.json({
pong: req.body.ping
});
});
The client will be responded { pong: 416 }
.
License
Licensed MIT, Copyright (c) 2015 OPENKNOWL Inc.