Permalink
Browse files

fix client crypto and add sign in api

  • Loading branch information...
1 parent 8dbf7b5 commit c6403b4604434bac10cb5986cf0daa58f7a0c259 @zaach zaach committed Dec 21, 2012
Showing with 23 additions and 8 deletions.
  1. +20 −1 client/client.js
  2. +3 −6 client/crypto.js
  3. +0 −1 lib/db/json.js
View
@@ -75,7 +75,7 @@ function authRequest(args, cb) {
nonce: args.nonce || 'unused',
date: args.date || new Date()
}, function(err, r) {
- if (err) return cb(err);
+ if (err) return cb(err, r);
args.headers = r;
// send request with authKey as the password
request(args, cb);
@@ -131,6 +131,25 @@ GombotClient.prototype = {
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) {
args = mergeArgs(args, this);
args.method = 'put';
View
@@ -1,7 +1,7 @@
if (typeof sjcl === 'undefined') {
var sjcl = require('./sjcl.js');
- var Hawk = require('hawk');
+ //var Hawk = require('hawk');
}
if (typeof URLParse === 'undefined') {
@@ -120,7 +120,7 @@ var GombotCrypto = (function() {
args.method = args.method.toUpperCase();
// 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);
// add a port if default is in use
@@ -130,8 +130,7 @@ var GombotCrypto = (function() {
setTimeout(function() {
if (typeof Hawk === 'undefined') {
- //var hmac = new sjcl.misc.hmac(keyBits);
- var hmac = new sjcl.misc.hmac(args.key);
+ var hmac = new sjcl.misc.hmac(keyBits);
var body =
// string representation of seconds since epoch
args.date.toString() + "\n" +
@@ -146,7 +145,6 @@ var GombotCrypto = (function() {
// random nonce
args.nonce + '\n';
- console.log('body', 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 headers = {
@@ -163,7 +161,6 @@ var GombotCrypto = (function() {
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)
// back to the client
View
@@ -50,7 +50,6 @@ module.exports = {
return this;
},
getPayload: function(id, cb) {
- console.error(db[id+'-payload']);
setTimeout(function() {
cb(null, db[id + '-payload']);
}, 0);

0 comments on commit c6403b4

Please sign in to comment.