diff --git a/src/key.js b/src/key.js index a54e61ed..7c8d7293 100644 --- a/src/key.js +++ b/src/key.js @@ -153,7 +153,7 @@ Key.prototype.toPacketlist = function() { Key.prototype.getSubkeyPackets = function(keyId=null) { const packets = new packet.List(); this.subKeys.forEach(subKey => { - if (!keyId || subKey.subKey.getKeyId().equals(keyId)) { + if (!keyId || subKey.subKey.getKeyId().equals(keyId, true)) { packets.push(subKey.subKey); } }); @@ -168,7 +168,7 @@ Key.prototype.getSubkeyPackets = function(keyId=null) { */ Key.prototype.getKeyPackets = function(keyId=null) { const packets = new packet.List(); - if (!keyId || this.primaryKey.getKeyId().equals(keyId)) { + if (!keyId || this.primaryKey.getKeyId().equals(keyId, true)) { packets.push(this.primaryKey); } packets.concat(this.getSubkeyPackets(keyId)); @@ -288,7 +288,7 @@ Key.prototype.getSigningKeyPacket = function (keyId=null, date=new Date()) { } } } - // TODO throw descriptive error + // TODO how to throw descriptive error? return null; }; @@ -334,7 +334,7 @@ Key.prototype.getEncryptionKeyPacket = function(keyId, date=new Date()) { isValidEncryptionKeyPacket(this.primaryKey, primaryUser.selfCertificate, date)) { return this.primaryKey; } - // TODO throw descriptive error + // TODO how to throw descriptive error? return null; }; @@ -1064,9 +1064,10 @@ SubKey.prototype.update = async function(subKey, primaryKey) { } for (let i = 0; i < that.bindingSignatures.length; i++) { if (that.bindingSignatures[i].issuerKeyId.equals(srcBindSig.issuerKeyId)) { - // TODO check which one is more recent - that.bindingSignatures[i] = srcBindSig; - return false; + if (srcBindSig.created < that.bindingSignatures[i].created) { + that.bindingSignatures[i] = srcBindSig; + return false; + } } } return true; @@ -1378,7 +1379,6 @@ async function isDataRevoked(primaryKey, dataToVerify, revocations, signature, k return false; })); // TODO further verify that this is the signature that should be revoked - // In particular, if signature.issuerKeyId is a wildcard, any revocation signature will revoke it if (signature) { signature.revoked = revocationKeyIds.some(keyId => keyId.equals(signature.issuerKeyId)) ? true : signature.revoked; diff --git a/src/message.js b/src/message.js index 6293859f..adb0cc70 100644 --- a/src/message.js +++ b/src/message.js @@ -536,12 +536,13 @@ Message.prototype.verifyDetached = function(signature, keys, date=new Date()) { /** * Create list of objects containing signer's keyid and validity of signature - * @param {Array} signatureList array of signature packets - * @param {Array} literalDataList array of literal data packets - * @param {Array} keys array of keys to verify signatures - * @param {Date} date Verify the signature against the given date, i.e. check signature creation time < date < expiration time + * @param {Array} signatureList array of signature packets + * @param {Array} literalDataList array of literal data packets + * @param {Array} keys array of keys to verify signatures + * @param {Date} date Verify the signature against the given date, + * i.e. check signature creation time < date < expiration time * @returns {Promise>} list of signer's keyid and validity of signature + * valid: Boolean}>>} list of signer's keyid and validity of signature */ export async function createVerificationObjects(signatureList, literalDataList, keys, date=new Date()) { return Promise.all(signatureList.map(async function(signature) { diff --git a/src/type/keyid.js b/src/type/keyid.js index 16fd3324..392d821f 100644 --- a/src/type/keyid.js +++ b/src/type/keyid.js @@ -52,9 +52,13 @@ Keyid.prototype.toHex = function() { return util.str_to_hex(this.bytes); }; -Keyid.prototype.equals = function(keyid) { - // Note: checks if keyid is a wildcard, but doesn't check "this". - return keyid.isWildcard() || this.bytes === keyid.bytes; +/** + * Checks equality of Key ID's + * @param {Keyid} keyid + * @param {Boolean} matchWildcard Indicates whether to check if either keyid is a wildcard + */ +Keyid.prototype.equals = function(keyid, matchWildcard=false) { + return (matchWildcard && (keyid.isWildcard() || this.isWildcard())) || this.bytes === keyid.bytes; }; Keyid.prototype.isNull = function() {