diff --git a/openpgp.d.ts b/openpgp.d.ts index a80ad02d..e8b6f6c9 100644 --- a/openpgp.d.ts +++ b/openpgp.d.ts @@ -44,6 +44,7 @@ export class Key { public getEncryptionKey(keyid?: Keyid, date?: Date | null, userId?: UserID): Promise; public getSigningKey(keyid?: Keyid, date?: Date | null, userId?: UserID): Promise; public getKeys(keyId?: Keyid): (Key | SubKey)[]; + public getSubkeys(keyId?: Keyid): SubKey[]; public isDecrypted(): boolean; public getFingerprint(): string; public getCreationTime(): Date; @@ -56,7 +57,7 @@ export class SubKey { public keyPacket: SecretSubkeyPacket | PublicSubkeyPacket; public bindingSignatures: SignaturePacket[]; public revocationSignatures: SignaturePacket[]; - public verify(primaryKey: PublicKeyPacket | SecretKeyPacket): Promise; + public verify(primaryKey: PublicKeyPacket | SecretKeyPacket): Promise; public isDecrypted(): boolean; public getFingerprint(): string; public getCreationTime(): Date; @@ -337,7 +338,7 @@ declare abstract class BasePacket { * - A Subkey Packet cannot always be used when a Primary Key Packet is expected (and vice versa). */ declare abstract class BasePublicKeyPacket extends BasePacket { - public algorithm: enums.publicKey; + public algorithm: enums.publicKeyNames; public created: Date; public version: number; public getAlgorithmInfo(): AlgorithmInfo; @@ -417,8 +418,11 @@ export class OnePassSignaturePacket extends BasePacket { } export class UserIDPacket extends BasePacket { - public tag: enums.packet.userID; - public userid: string; + public readonly tag: enums.packet.userID; + public readonly name: string; + public readonly comment: string; + public readonly email: string; + public readonly userid: string; static fromObject(userId: UserID): UserIDPacket; } @@ -635,6 +639,7 @@ declare class Keyid { bytes: string; equals(keyid: Keyid, matchWildcard?: boolean): boolean; toHex(): string; + static fromId(hex: string): Keyid; } interface DecryptMessageResult { diff --git a/src/key/subkey.js b/src/key/subkey.js index 3ef62fa2..7b31bd3c 100644 --- a/src/key/subkey.js +++ b/src/key/subkey.js @@ -68,6 +68,7 @@ class SubKey { * @param {SecretKeyPacket| * PublicKeyPacket} primaryKey The primary key packet * @param {Date} date Use the given date instead of the current time + * @returns {Promise} * @throws {Error} if the subkey is invalid. * @async */ @@ -83,6 +84,7 @@ class SubKey { if (helper.isDataExpired(this.keyPacket, bindingSignature, date)) { throw new Error('Subkey is expired'); } + return bindingSignature; } /** diff --git a/test/general/key.js b/test/general/key.js index 6deb1286..d0e4d69d 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -3758,4 +3758,15 @@ VYGdb3eNlV8CfoEC }); }); + it('Subkey.verify returns the latest valid signature', async function () { + const { key: encryptionKey } = await openpgp.generateKey({ userIds: { name: "purple" } }); + const encryptionKeySignature = await encryptionKey.getSubkeys()[0].verify(encryptionKey); + expect(encryptionKeySignature instanceof openpgp.SignaturePacket).to.be.true; + expect(encryptionKeySignature.keyFlags[0] & openpgp.enums.keyFlags.encryptCommunication).to.be.equals(openpgp.enums.keyFlags.encryptCommunication); + expect(encryptionKeySignature.keyFlags[0] & openpgp.enums.keyFlags.encryptStorage).to.be.equals(openpgp.enums.keyFlags.encryptStorage); + const { key: signingKey } = await openpgp.generateKey({ userIds: { name: "purple" }, subkeys: [{ sign: true }] }); + const signingKeySignature = await signingKey.getSubkeys()[0].verify(signingKey); + expect(signingKeySignature instanceof openpgp.SignaturePacket).to.be.true; + expect(signingKeySignature.keyFlags[0] & openpgp.enums.keyFlags.signData).to.be.equals(openpgp.enums.keyFlags.signData); + }); });