Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Bugfixing

  • Loading branch information...
commit 8f0dd8e2c4cad80568e86929b97b55e531c11695 1 parent 42fe0a3
@cdauth authored
View
3  bufferedStream.js
@@ -39,6 +39,9 @@ module.exports = function(stream) {
stream.on("end", function() {
endData();
});
+ stream.on("error", function(err) {
+ endData(err);
+ });
}
function checkRead() {
View
44 fifo.js
@@ -39,7 +39,7 @@ Fifo.prototype = {
* Adds all the values from the items array. items is an array of arrays, and each array in it is an array of arguments to pass to the next()
* callback function.
*/
- _addAllMulti : function(items) {
+ _addAllMultiple : function(items) {
this.__items = this.__items.concat(items);
this.__check();
},
@@ -90,6 +90,36 @@ Fifo.prototype = {
}
});
}
+ },
+
+ toArraySingle : function(callback) {
+ var ret = [ ];
+ this.forEachSeries(function() {
+ var args = utils.toProperArray(arguments);
+ var next = args.pop();
+ ret.push(args[0]);
+ next();
+ }, function(err) {
+ if(err)
+ callback(err);
+ else
+ callback(null, ret);
+ });
+ },
+
+ toArrayMultiple : function(callback) {
+ var ret = [ ];
+ this.forEachSeries(function() {
+ var args = utils.toProperArray(arguments);
+ var next = args.pop();
+ ret.push(args);
+ next();
+ }, function(err) {
+ if(err)
+ callback(err);
+ else
+ callback(null, ret);
+ });
}
};
@@ -106,6 +136,10 @@ utils.extend(ArraySingle.prototype, {
callback(true);
else
callback(null, this.__array[this.__i++]);
+ },
+
+ toArraySingle : function(callback) {
+ callback(null, [ ].concat(this.__array));
}
});
@@ -123,6 +157,12 @@ utils.extend(ArrayMultiple.prototype, {
else
callback.apply(null, [ null ].concat(items));
});
+ },
+
+ toArraySingle : Fifo.prototype.toArraySingle,
+
+ toArrayMultiple : function(callback) {
+ callback(null, this.__array);
}
});
@@ -171,7 +211,7 @@ utils.extend(Grep.prototype, {
if(err)
callback(err);
else if(doAdd)
- callback(null, [ null ].concat(args));
+ callback.apply(null, [ null ].concat(args));
else
this.next(callback);
}) ]));
View
46 keyring.js
@@ -1,6 +1,9 @@
var utils = require("./utils");
var signing = require("./signing");
var consts = require("./consts");
+var packets = require("./packets");
+var packetContent = require("./packetContent");
+var Fifo = require("./fifo");
var Filter = require("./keyringFilters");
var async = require("async");
@@ -170,10 +173,7 @@ Keyring.prototype = {
if(err)
callback(err);
else
- {
this._addKeySignature(keyId, signatureInfo, callback);
- callback();
- }
}), false);
}
}));
@@ -236,10 +236,7 @@ Keyring.prototype = {
if(err)
callback(err);
else
- {
this._addSubkeySignature(keyId, subkeyId, signatureInfo, callback);
- callback();
- }
}));
}
}));
@@ -302,10 +299,7 @@ Keyring.prototype = {
if(err)
callback(err);
else
- {
this._addIdentitySignature(keyId, identityId, signatureInfo, callback);
- callback();
- }
}));
}
}));
@@ -368,10 +362,7 @@ Keyring.prototype = {
if(err)
callback(err);
else
- {
this._addAttributeSignature(keyId, attributeId, signatureInfo, callback);
- callback();
- }
}));
}
}));
@@ -434,7 +425,7 @@ Keyring.prototype = {
var lastAttributeImported = null;
packets.splitPackets(keyData).forEachSeries(function(tag, header, body, next) {
- getPacketInfo(tag, body, function(err, info) {
+ packetContent.getPacketInfo(tag, body, function(err, info) {
if(err)
return callback(err);
@@ -627,16 +618,14 @@ function _filter(list, filter) {
});
}
-function _strip(list, fieldList) {
+function _strip(item, fieldList) {
if(fieldList == null)
- return list;
+ return item;
- return Fifo.map(list, function(item, callback) {
- var newItem = { };
- for(var i in fieldList)
- newItem[i] = item[i];
- callback(null, newItem);
- });
+ var newItem = { };
+ for(var i=0; i<fieldList.length; i++)
+ newItem[fieldList[i]] = item[fieldList[i]];
+ return newItem;
}
function _add(existsFunc, addFunc, removeFunc, funcs, callback) {
@@ -765,7 +754,7 @@ function _subkeySignatureVerified(keyring, keyId, subkeyId, signatureInfo, callb
// Check 3a, 3b
if(signatureInfo.sigtype == consts.SIG.SUBKEY_REVOK)
- checks.push(async.apply(_checkSubkeyRevocationStatus, keyring, keyId, subkeyId));
+ checks.push(async.apply(_checkSubkeyRevocationStatus, keyring, keyId, subkeyId, false));
// Check 5b
if(signatureInfo.sigtype == consts.SIG.SUBKEY && signatureInfo.hashedSubPackets[consts.SIGSUBPKT.KEY_EXPIRE])
@@ -800,6 +789,7 @@ function _verifySignaturesByKey(keyring, keyId, callback) {
keyring.getKeySignatureListByIssuer(keyId, { verified: false }).forEachSeries(function(sig, next2) {
async.waterfall([
function(next3) {
+ console.log(sig);
keyring.getKeySignature(sig.keyId, sig.signatureId, next3, [ "issuer", "security" ]);
},
function(signatureInfo, next3) {
@@ -895,7 +885,7 @@ function _verifySignaturesByKey(keyring, keyId, callback) {
], callback);
}
-function _checkKeyRevocationStatus(keyring, keyId, callback, remove) {
+function _checkKeyRevocationStatus(keyring, keyId, remove, callback) {
keyring.getKeySignatures(keyId, { sigtype: consts.SIG.KEY_REVOK, verified: true }).forEachSeries(function(signatureInfo, next) {
async.waterfall([
function(next) {
@@ -920,7 +910,7 @@ function _checkKeyRevocationStatus(keyring, keyId, callback, remove) {
}, callback);
}
-function _checkSubkeyRevocationStatus(keyring, keyId, subkeyId, callback) {
+function _checkSubkeyRevocationStatus(keyring, keyId, subkeyId, remove, callback) {
keyring.getSubkeySignatures(keyId, subkeyId, { sigtype: consts.SIG.SUBKEY_REVOK, verified: true }).forEachSeries(function(signatureInfo, next) {
async.waterfall([
function(next) {
@@ -998,7 +988,7 @@ function _isAuthorisedRevoker(keyring, keyId, issuerId, callback) {
}
// Check 4: Find verified revocation signatures on the specified key and its sub-objects and revoke all earlier signatures by the same issuer on the same object
-function _checkSignatureRevocationStatus(keyring, keyId, callback, remove) {
+function _checkSignatureRevocationStatus(keyring, keyId, remove, callback) {
async.series([
function(next) {
if(remove)
@@ -1054,7 +1044,7 @@ function _resetSignatureRevocationStatus(keyring, keyId, callback) {
}, next);
},
function(next) {
- keyring.getIdentityList(keyId, function(identityId, next) {
+ keyring.getIdentityList(keyId).forEachSeries(function(identityId, next) {
keyring.getIdentitySignatures(keyId, identityId, { sigtype: [ consts.SIG.CERT_0, consts.SIG.CERT_1, consts.SIG.CERT_2, consts.SIG.CERT_3 ] }, [ "id", "revoked" ]).forEachSeries(function(signatureInfo, next) {
if(signatureInfo.revoked)
keyring._updateIdentitySignature(keyId, identityId, signatureInfo.id, { revoked: null }, next);
@@ -1064,7 +1054,7 @@ function _resetSignatureRevocationStatus(keyring, keyId, callback) {
}, next);
},
function(next) {
- keyring.getAttributeList(keyId, function(attributeId, next) {
+ keyring.getAttributeList(keyId).forEachSeries(function(attributeId, next) {
keyring.getAttributeSignatures(keyId, attributeId, { sigtype: [ consts.SIG.CERT_0, consts.SIG.CERT_1, consts.SIG.CERT_2, consts.SIG.CERT_3 ] }, [ "id", "revoked" ]).forEachSeries(function(signatureInfo, next) {
if(signatureInfo.revoked)
keyring._updateAttributeSignature(keyId, attributeId, signatureInfo.id, { revoked: null }, next);
@@ -1115,6 +1105,8 @@ function _checkSelfSignatures(keyring, keyId, callback) {
checkExpire(signatureInfo, next);
}
+ var filter = { verified: true, issuer: keyId, sigtype: [ consts.SIG.KEY, consts.SIG.CERT_0, consts.SIG.CERT_1, consts.SIG.CERT_2, consts.SIG.CERT_3 ] };
+
async.series([
function(next) {
keyring.getKeySignatures(keyId, filter, [ "hashedSubPackets", "date" ]).forEachSeries(checkExpire, next);
View
67 keyringFile.js
@@ -5,6 +5,7 @@ var fs = require("fs");
var BufferedStream = require("./bufferedStream");
var consts = require("./consts");
var utils = require("./utils");
+var async = require("async");
function getStreamKeyring(stream, callback) {
var ret = new _KeyringStream(stream);
@@ -16,9 +17,22 @@ function getStreamKeyring(stream, callback) {
});
}
-function getFileKeyring(fname, callback) {
+function getFileKeyring(fname, callback, create) {
var ret = new _KeyringFile(fname);
- ret.revertChanges(function(err) {
+ async.waterfall([
+ function(next) {
+ if(create)
+ fs.exists(fname, function(exists) { next(null, exists); });
+ else
+ next(null, true);
+ },
+ function(doRead, next) {
+ if(doRead)
+ ret.revertChanges(next);
+ else
+ next();
+ }
+ ], function(err) {
if(err)
callback(err);
else
@@ -36,7 +50,7 @@ util.inherits(_KeyringStream, Keyring);
utils.extend(_KeyringStream.prototype, {
getKeyList : function(filter) {
- return Keyring._filter(_getList(this._keys), filter);
+ return _getList(filter, this._keys);
},
keyExists : function(id, callback) {
@@ -60,7 +74,7 @@ utils.extend(_KeyringStream.prototype, {
},
getSubkeyList : function(keyId, filter) {
- return Keyring._filter(_getList(this._subkeys, keyId), filter);
+ return _getList(filter, this._subkeys, keyId);
},
subkeyExists : function(keyId, id, callback) {
@@ -68,11 +82,11 @@ utils.extend(_KeyringStream.prototype, {
},
getSubkey : function(keyId, id, callback, fields) {
- _get(callback, fields, this._subkeys, keyId);
+ _get(callback, fields, this._subkeys, keyId, id);
},
_addSubkey : function(keyId, subkeyInfo, callback) {
- _add(callback, subkeyInfo, this._subkeys);
+ _add(callback, subkeyInfo, this._subkeys, keyId);
},
_updateSubkey : function(keyId, id, fields, callback) {
@@ -96,7 +110,7 @@ utils.extend(_KeyringStream.prototype, {
},
getIdentityList : function(keyId, filter) {
- return Keyring._filter(_getList(this._identities, keyId), filter);
+ return _getList(filter, this._identities, keyId);
},
identityExists : function(keyId, id, callback) {
@@ -104,7 +118,7 @@ utils.extend(_KeyringStream.prototype, {
},
getIdentity : function(keyId, id, callback, fields) {
- _get(callback, fields, this._identities, keyId);
+ _get(callback, fields, this._identities, keyId, id);
},
_addIdentity : function(keyId, identityInfo, callback) {
@@ -120,7 +134,7 @@ utils.extend(_KeyringStream.prototype, {
},
getAttributeList : function(keyId, filter) {
- return Keyring._filter(_getList(this._attributes, keyId), filter);
+ return _getList(filter, this._attributes, keyId);
},
attributeExists : function(keyId, id, callback) {
@@ -128,7 +142,7 @@ utils.extend(_KeyringStream.prototype, {
},
getAttribute : function(keyId, id, callback, fields) {
- _get(callback, fields, this._attributes, keyId);
+ _get(callback, fields, this._attributes, keyId, id);
},
_addAttribute : function(keyId, attributeInfo, callback) {
@@ -144,11 +158,7 @@ utils.extend(_KeyringStream.prototype, {
},
getKeySignatureList : function(keyId, filter) {
- return Keyring._filter(_getList(this._keySignatures, keyId), filter);
- },
-
- getKeySignatureListByIssuer : function(issuerId, filter) {
- return Keyring._filter(_getList(this._keySignatures));
+ return _getList(filter, this._keySignatures, keyId);
},
keySignatureExists : function(keyId, id, callback) {
@@ -156,7 +166,7 @@ utils.extend(_KeyringStream.prototype, {
},
getKeySignature : function(keyId, id, callback, fields) {
- _get(callback, fields, this._keySignatures, keyId);
+ _get(callback, fields, this._keySignatures, keyId, id);
},
_addKeySignature : function(keyId, signatureInfo, callback) {
@@ -172,7 +182,7 @@ utils.extend(_KeyringStream.prototype, {
},
getSubkeySignatureList : function(keyId, subkeyId, filter) {
- return Keyring._filter(_getList(this._subkeySignatures, keyId));
+ return _getList(filter, this._subkeySignatures, keyId, subkeyId);
},
subkeySignatureExists : function(keyId, subkeyId, id, callback) {
@@ -180,7 +190,7 @@ utils.extend(_KeyringStream.prototype, {
},
getSubkeySignature : function(keyId, subkeyId, id, callback, fields) {
- _get(callback, fields, this._subkeySignatures, keyId, subkeyId);
+ _get(callback, fields, this._subkeySignatures, keyId, subkeyId, id);
},
_addSubkeySignature : function(keyId, subkeyId, signatureInfo, callback) {
@@ -196,7 +206,7 @@ utils.extend(_KeyringStream.prototype, {
},
getIdentitySignatureList : function(keyId, identityId, filter) {
- return Keyring._filter(_getList(this._identitySignatures, keyId), filter);
+ return _getList(filter, this._identitySignatures, keyId, identityId);
},
identitySignatureExists : function(keyId, identityId, id, callback) {
@@ -204,7 +214,7 @@ utils.extend(_KeyringStream.prototype, {
},
getIdentitySignature : function(keyId, identityId, id, callback, fields) {
- _get(callback, fields, this._identitySignatures, keyId, identityId);
+ _get(callback, fields, this._identitySignatures, keyId, identityId, id);
},
_addIdentitySignature : function(keyId, identityId, signatureInfo, callback) {
@@ -220,11 +230,11 @@ utils.extend(_KeyringStream.prototype, {
},
getAttributeSignatureList : function(keyId, attributeId, filter) {
- return Keyring._filter(_getList(this._attributeSignatures, keyId), filter);
+ return _getList(filter, this._attributeSignatures, keyId, attributeId);
},
attributeSignatureExists : function(keyId, attributeId, id, callback) {
- _get(callback, this._attributeSignatures, keyId, attributeId);
+ _get(callback, this._attributeSignatures, keyId, attributeId, id);
},
getAttributeSignature : function(keyId, attributeId, id, callback, fields) {
@@ -282,7 +292,7 @@ utils.extend(_KeyringFile.prototype, {
revertChanges : function(callback) {
this._clear();
- this._importKeys(fs.createReadStream(this._filename), callback);
+ this.importKeys(fs.createReadStream(this._filename), callback);
}
});
@@ -300,10 +310,17 @@ function _getItem(obj, args, make) {
return obj;
}
-function _getList(obj, idx) {
+function _getList(filter, obj, idx) {
obj = _getItem(obj, utils.toProperArray(arguments).slice(2));
- return Fifo.fromArraySingle(Object.keys(obj));
+ var fifo = new Fifo();
+ for(var i in obj)
+ fifo._add(obj[i]);
+ fifo._end();
+
+ return Fifo.map(Keyring._filter(fifo, filter), function(item, callback) {
+ callback(null, item.id);
+ });
}
function _exists(callback, obj, idx) {
View
11 keyringFilters.js
@@ -1,7 +1,5 @@
var util = require("util");
-module.exports = Filter;
-
var Filter = function() { };
@@ -97,12 +95,12 @@ function _valueFilter(check) {
this.__value = _normaliseFilterValue(value);
};
+ util.inherits(ret, Filter);
+
ret.prototype.check = function(checkValue) {
return check(this.__value, _normaliseFilterValue(checkValue));
};
- util.inherits(ret, Filter);
-
return ret;
}
@@ -118,4 +116,7 @@ function _inheritFilter(getFilter) {
};
return ret;
-}
+}
+
+
+module.exports = Filter;
View
18 packets.js
@@ -19,10 +19,9 @@ function getHeaderInfo(data, callback)
data.read(1, function(err, data1) {
if(err)
- {
- err.NOFIRSTBYTE = true;
callback(err);
- }
+ else if(data1.length == 0)
+ callback(true);
else
{
var header = data1;
@@ -77,7 +76,7 @@ function getHeaderInfo(data, callback)
}
}
}
- });
+ }, false);
}
function generateHeader(tag, packetLength, newFormat)
@@ -151,13 +150,10 @@ function splitPackets(data) {
function readPacket() {
getHeaderInfo(data, function(err, tag, packetLength, header, newFormat) {
- if(err)
- {
- if(!err.NOFIRSTBYTE) // If NOFIRSTBYTE is true, we have reached the end of the stream
- ret._end(err);
- else
- ret._end();
- }
+ if(err === true)
+ ret._end();
+ else if(err)
+ ret._end(err);
else
{
if(packetLength < 0) // Partial body length
View
9 signing.js
@@ -10,7 +10,7 @@ var async = require("async");
function verifySignature(keyring, callback) {
utils.getTempFilename(function(err, fname) {
if(err) { callback(err); return; }
-
+
fs.open(fname, "w", 0600, function(err, fd) {
if(err) { callback(err); return; }
@@ -26,11 +26,11 @@ function verifySignature(keyring, callback) {
stdout = stdout.toString("utf8");
var success = !!(stdout.match(/^(sig|rev):!:/m) && !stdout.match(/^(sig|rev):[^!]/m));
-
+
fs.unlink(fname, function(err) {
if(err)
console.log("Error removing temporary file "+fname+".", err);
-
+
callback(null, success);
});
});
@@ -84,12 +84,15 @@ function verifyXYSignature(keyring, keyId, signatureInfo, callback, getSubObject
return next(err);
buffers.push(packets.generatePacket(subObjectType, subInfo.binary));
+ next();
});
}
], function(err) {
if(err)
return callback(err);
+ buffers.push(packets.generatePacket(consts.PKT.SIGNATURE, signatureInfo.binary));
+
verifySignature(Buffer.concat(buffers), function(err, verified) {
if(verified)
{
View
18 utils.js
@@ -8,7 +8,7 @@ function getTempFilename(callback)
var cb = function(err) {
if(err) { callback(err); return; }
- var fname = config.tmpDir+"/"+(new Date()).getTime();
+ var fname = config.tmpDir+"/"+Math.floor(Math.random()*(new Date()).getTime());
fs.exists(fname, function(exists) {
if(exists)
cb();
@@ -77,11 +77,23 @@ function extend(obj1, obj2) {
}
}
return obj1;
-};
+}
+
+function callback(func) {
+ var run = false;
+ return function() {
+ if(run)
+ throw new Error("Run twice");
+
+ run = true;
+ func.apply(this, arguments);
+ };
+}
exports.getTempFilename = getTempFilename;
exports.hash = hash;
exports.toProperArray = toProperArray;
exports.indexOf = indexOf;
exports.proxy = proxy;
-exports.extend = extend;
+exports.extend = extend;
+exports.callback = callback;
Please sign in to comment.
Something went wrong with that request. Please try again.