Merge pull request #733 from wiktor-k/fix-primary-uid
Fix Key#getPrimaryUser on keys without valid UIDs
This commit is contained in:
commit
8865103e17
|
@ -494,15 +494,16 @@ Key.prototype.getPrimaryUser = async function(date=new Date(), userId={}) {
|
||||||
const users = this.users.map(function(user, index) {
|
const users = this.users.map(function(user, index) {
|
||||||
const selfCertification = getLatestSignature(user.selfCertifications, date);
|
const selfCertification = getLatestSignature(user.selfCertifications, date);
|
||||||
return { index, user, selfCertification };
|
return { index, user, selfCertification };
|
||||||
}).filter(({ user }) => {
|
}).filter(({ user, selfCertification }) => {
|
||||||
return user.userId && (
|
return user.userId && selfCertification && (
|
||||||
(userId.name === undefined || user.userId.name === userId.name) &&
|
(userId.name === undefined || user.userId.name === userId.name) &&
|
||||||
(userId.email === undefined || user.userId.email === userId.email) &&
|
(userId.email === undefined || user.userId.email === userId.email) &&
|
||||||
(userId.comment === undefined || user.userId.comment === userId.comment)
|
(userId.comment === undefined || user.userId.comment === userId.comment)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
if (!users.length) {
|
if (!users.length) {
|
||||||
if (userId) {
|
if (userId.name !== undefined || userId.email !== undefined ||
|
||||||
|
userId.comment !== undefined) {
|
||||||
throw new Error('Could not find user that matches that user ID');
|
throw new Error('Could not find user that matches that user ID');
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -1469,6 +1469,25 @@ const mergeKey2 = '-----BEGIN PGP PUBLIC KEY BLOCK-----\n' +
|
||||||
expect(primUser.selfCertification).to.be.an.instanceof(openpgp.packet.Signature);
|
expect(primUser.selfCertification).to.be.an.instanceof(openpgp.packet.Signature);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('getPrimaryUser() should return null if no UIDs are bound', async function() {
|
||||||
|
const keyWithoundBoundUid = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||||
|
|
||||||
|
xVgEWxpFkRYJKwYBBAHaRw8BAQdAYjjZLkp4qG7KAqJeVQlxQT6uCPq6rylV02nC
|
||||||
|
c6D/a8YAAP0YtS4UeLzeJGSgjGTlvSd3TWEsjxdGyzwfHCOejXMRbg2+zSFVbmJv
|
||||||
|
dW5kIFVJRCA8dW5ib3VuZEBleGFtcGxlLm9yZz7HXQRbGkWREgorBgEEAZdVAQUB
|
||||||
|
AQdAfxbFuoNlm5KfoqaWICETfMljzVTDAtiSM0TYSHzGAz8DAQoJAAD/cuu7bxUE
|
||||||
|
goBAhIyVH+pmvWpuDJbfu1Vaj5KiQxsKxJgP/MJ+BBgWCgAwApsMBYJbGkWRBYkB
|
||||||
|
3+IAFqEE30YL4fxJBMTm8ONLPOiTkVxEIS8JkDzok5FcRCEvAABb+gEAnQb/rMLO
|
||||||
|
Vz/bMCJoAShgybW1r6kRWejybzIjFSLnx/YA/iLZeo5UNdlXRJco+15RbFiNSAbw
|
||||||
|
VYGdb3eNlV8CfoEC
|
||||||
|
=FYbP
|
||||||
|
-----END PGP PRIVATE KEY BLOCK-----
|
||||||
|
`;
|
||||||
|
const key = openpgp.key.readArmored(keyWithoundBoundUid).keys[0];
|
||||||
|
const primUser = await key.getPrimaryUser();
|
||||||
|
expect(primUser).to.be.null;
|
||||||
|
});
|
||||||
|
|
||||||
it('Generated key is not unlocked by default', function() {
|
it('Generated key is not unlocked by default', function() {
|
||||||
const opt = {numBits: 512, userIds: 'test <a@b.com>', passphrase: '123'};
|
const opt = {numBits: 512, userIds: 'test <a@b.com>', passphrase: '123'};
|
||||||
if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys
|
||||||
|
|
Loading…
Reference in New Issue
Block a user