prioritize signing with subkeys when possible

This commit is contained in:
Sanjana Rajan
2018-05-09 12:23:35 -07:00
parent 4926667cf9
commit 6efcce1069
2 changed files with 11 additions and 11 deletions

View File

@@ -287,11 +287,6 @@ function isValidSigningKeyPacket(keyPacket, signature, date=new Date()) {
Key.prototype.getSigningKeyPacket = async function (keyId=null, date=new Date(), userId={}) {
const primaryKey = this.primaryKey;
if (await this.verifyPrimaryKey(date, userId) === enums.keyStatus.valid) {
const primaryUser = await this.getPrimaryUser(date, userId);
if (primaryUser && (!keyId || primaryKey.getKeyId().equals(keyId)) &&
isValidSigningKeyPacket(primaryKey, primaryUser.selfCertification, date)) {
return primaryKey;
}
for (let i = 0; i < this.subKeys.length; i++) {
if (!keyId || this.subKeys[i].subKey.getKeyId().equals(keyId)) {
// eslint-disable-next-line no-await-in-loop
@@ -303,6 +298,11 @@ Key.prototype.getSigningKeyPacket = async function (keyId=null, date=new Date(),
}
}
}
const primaryUser = await this.getPrimaryUser(date, userId);
if (primaryUser && (!keyId || primaryKey.getKeyId().equals(keyId)) &&
isValidSigningKeyPacket(primaryKey, primaryUser.selfCertification, date)) {
return primaryKey;
}
}
return null;
};