Allow parsing keys without User IDs (#1146)
This commit is contained in:
parent
8d67af729a
commit
fe2949f16d
|
@ -63,8 +63,8 @@ class Key {
|
|||
this.users = [];
|
||||
this.subKeys = [];
|
||||
this.packetlist2structure(packetlist);
|
||||
if (!this.keyPacket || !this.users.length) {
|
||||
throw new Error('Invalid key: need at least key and user ID packet');
|
||||
if (!this.keyPacket) {
|
||||
throw new Error('Invalid key: need at least key packet');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -545,11 +545,6 @@ class Key {
|
|||
if (await this.isRevoked(null, null, date)) {
|
||||
throw new Error('Primary key is revoked');
|
||||
}
|
||||
// check for at least one self signature. Self signature of user ID not mandatory
|
||||
// See {@link https://tools.ietf.org/html/rfc4880#section-11.1}
|
||||
if (!this.users.some(user => user.userId && user.selfCertifications.length)) {
|
||||
throw new Error('No self-certifications');
|
||||
}
|
||||
// check for valid, unrevoked, unexpired self signature
|
||||
const { selfCertification } = await this.getPrimaryUser(date, userId);
|
||||
// check for expiration time
|
||||
|
|
|
@ -1916,6 +1916,60 @@ vqBGKJzmO5q3cECw
|
|||
=X9kJ
|
||||
-----END PGP PRIVATE KEY BLOCK-----`;
|
||||
|
||||
const uidlessKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
xcMFBF8/lc8BCACwwWWyNdfZ9Qjz8zc4sFGNfHXITscT7WCMuXgC2BbFwiSD
|
||||
52+Z6fIKaaMFP07MOy8g3PsrW8rrM6j9ew4fh6Kr6taD5JtZfWEWxSnmfl8T
|
||||
MqbfcGklJZDyqbSlRBHh53ea4fZe/wCiaL2qhME9Pa7M+w/AiCT1LuXUBiKp
|
||||
oCLVn1PFf760vdsz5CD+kpzBIZ45P6zZxnR/P6zLsKjr5nERlIDZ1gWtctx9
|
||||
9ZEEVBrgnEE4dBIT1W/M/XbEwsKn1HGOyTBvzeEfM863uW0V9HKmjilbMF2P
|
||||
fJ583t1HzuhA7IewcgX/VGC4QKMnukUpRhJQPlcVFSy0zjD9zQYIh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CHJDAujY5yTxuXDdzMmxYahsg6vx/fbXZVwm2RFpxCzI6pV
|
||||
E/YWhOFMknNHVpiqvQ91Y7nOJlHQAe9RmsGcxng0bwsE1J277JozUr5PNXA9
|
||||
ZDPVG7/3nHnUnNwnXupHAsiYW4aN/uFUXg5CoArXvj2SHjWQSBMwWDQK9jC5
|
||||
YVzi15D9Jt3xYDXpDbSEf8N+d8C31Jx3QedDi/ei5xs/9CJ+DqbBxRUW04jj
|
||||
r8mew9pM2+gpDS5DoNLSBJ1vn3OIRLnCudmSJBHs3NMh85qF07bc1+sAozpZ
|
||||
vM7CwF8EGAEIAAkFAl8/lc8CGwwACgkQKBMN0dHENohRNAf/Z5G5pySJe4tk
|
||||
G1pGQOLjZms08e1KGQlbRtZR8WN2ySCe3Pyla/R3KQRJBQS6V926GKnvsOZC
|
||||
3CWVKHDcn1Rx2uV3GH8VWOHfT+EjQI7zCoQAppVEX4uJ4BCxP5Z9CgSxL8zH
|
||||
31AHwLEtCqDfeZf8dttihfafyAUFKCCrN5R6cP2AtUlRDE1XRdTJ8zRk4mRX
|
||||
81r0vXC1Xfs1zBy3YnDIJVJcEro9v7yOn/5WBtQT/jnBvJZ/gBieolgXUrRb
|
||||
V5PJ0lZPFfMdYjjYR+i7j3+/j59kd1Wuz+6I572J+j4lWlPIvGk2V+rzzHqK
|
||||
CciXuhqnLwoVF5/uXMYffVtfl/OU+w==
|
||||
=EqcV
|
||||
-----END PGP PRIVATE KEY BLOCK-----`;
|
||||
|
||||
const rsaSignOnly = `-----BEGIN PGP PRIVATE KEY BLOCK-----
|
||||
|
||||
|
@ -3214,6 +3268,14 @@ VYGdb3eNlV8CfoEC
|
|||
await expect(openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'c@c.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
||||
});
|
||||
|
||||
it('Fails to encrypt to User ID-less key', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(uidlessKey);
|
||||
expect(publicKey.users.length).to.equal(0);
|
||||
const privateKey = await openpgp.key.readArmored(uidlessKey);
|
||||
await privateKey.decrypt('correct horse battery staple');
|
||||
await expect(openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false })).to.be.rejectedWith('Could not find primary user');
|
||||
});
|
||||
|
||||
it('Sign - specific user', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
|
|
Loading…
Reference in New Issue
Block a user