Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
fix client crypto and add sign in api
  • Loading branch information
zaach committed Dec 21, 2012
1 parent 8dbf7b5 commit c6403b4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
21 changes: 20 additions & 1 deletion client/client.js
Expand Up @@ -75,7 +75,7 @@ function authRequest(args, cb) {
nonce: args.nonce || 'unused', nonce: args.nonce || 'unused',
date: args.date || new Date() date: args.date || new Date()
}, function(err, r) { }, function(err, r) {
if (err) return cb(err); if (err) return cb(err, r);
args.headers = r; args.headers = r;
// send request with authKey as the password // send request with authKey as the password
request(args, cb); request(args, cb);
Expand Down Expand Up @@ -131,6 +131,25 @@ GombotClient.prototype = {


authRequest(args, cb); authRequest(args, cb);
}, },
signIn: function(args, cb) {
var self = this;
// compute the authKey
GombotCrypto.derive({
email: args.email,
password: args.pass
}, function(err, r) {
if (err) return cb(err);
args.key = r.authKey;

self.status(args, function (err, r) {
if (!err && r.success) {
self.authKey = r.authKey;
self.user = args.email;
}
cb(err, r);
});
});
},
storePayload: function(args, cb) { storePayload: function(args, cb) {
args = mergeArgs(args, this); args = mergeArgs(args, this);
args.method = 'put'; args.method = 'put';
Expand Down
9 changes: 3 additions & 6 deletions client/crypto.js
@@ -1,7 +1,7 @@


if (typeof sjcl === 'undefined') { if (typeof sjcl === 'undefined') {
var sjcl = require('./sjcl.js'); var sjcl = require('./sjcl.js');
var Hawk = require('hawk'); //var Hawk = require('hawk');
} }


if (typeof URLParse === 'undefined') { if (typeof URLParse === 'undefined') {
Expand Down Expand Up @@ -120,7 +120,7 @@ var GombotCrypto = (function() {
args.method = args.method.toUpperCase(); args.method = args.method.toUpperCase();


// how about if the key is poorly formated? // how about if the key is poorly formated?
//var keyBits = sjcl.codec.base64.toBits(args.key); var keyBits = sjcl.codec.base64.toBits(args.key);


var url = URLParse(args.url); var url = URLParse(args.url);
// add a port if default is in use // add a port if default is in use
Expand All @@ -130,8 +130,7 @@ var GombotCrypto = (function() {


setTimeout(function() { setTimeout(function() {
if (typeof Hawk === 'undefined') { if (typeof Hawk === 'undefined') {
//var hmac = new sjcl.misc.hmac(keyBits); var hmac = new sjcl.misc.hmac(keyBits);
var hmac = new sjcl.misc.hmac(args.key);
var body = var body =
// string representation of seconds since epoch // string representation of seconds since epoch
args.date.toString() + "\n" + args.date.toString() + "\n" +
Expand All @@ -146,7 +145,6 @@ var GombotCrypto = (function() {
// random nonce // random nonce
args.nonce + '\n'; args.nonce + '\n';


console.log('body', body);
var mac = sjcl.codec.base64.fromBits(hmac.mac(body)); var mac = sjcl.codec.base64.fromBits(hmac.mac(body));
var header = 'Hawk id="' + args.email + '", ts="' + args.date + (args.nonce ? '", ext="' + args.nonce : '') + '", mac="' + mac + '"'; var header = 'Hawk id="' + args.email + '", ts="' + args.date + (args.nonce ? '", ext="' + args.nonce : '') + '", mac="' + mac + '"';
var headers = { var headers = {
Expand All @@ -163,7 +161,6 @@ var GombotCrypto = (function() {
Authorization: Hawk.getAuthorizationHeader(credentials, args.method, args.url, url.host, url.port, args.nonce, args.date) Authorization: Hawk.getAuthorizationHeader(credentials, args.method, args.url, url.host, url.port, args.nonce, args.date)
}; };
} }
console.log(headers);


// and pass a bag of calculated authorization headers (only one) // and pass a bag of calculated authorization headers (only one)
// back to the client // back to the client
Expand Down
1 change: 0 additions & 1 deletion lib/db/json.js
Expand Up @@ -50,7 +50,6 @@ module.exports = {
return this; return this;
}, },
getPayload: function(id, cb) { getPayload: function(id, cb) {
console.error(db[id+'-payload']);
setTimeout(function() { setTimeout(function() {
cb(null, db[id + '-payload']); cb(null, db[id + '-payload']);
}, 0); }, 0);
Expand Down

0 comments on commit c6403b4

Please sign in to comment.