Return subkey binding signature in SubKey#verify (#1250)
Also, update TypeScript definitions.
This commit is contained in:
parent
ca248ba1a8
commit
2000388a80
13
openpgp.d.ts
vendored
13
openpgp.d.ts
vendored
|
@ -44,6 +44,7 @@ export class Key {
|
|||
public getEncryptionKey(keyid?: Keyid, date?: Date | null, userId?: UserID): Promise<Key | SubKey>;
|
||||
public getSigningKey(keyid?: Keyid, date?: Date | null, userId?: UserID): Promise<Key | SubKey>;
|
||||
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<enums.keyStatus>;
|
||||
public verify(primaryKey: PublicKeyPacket | SecretKeyPacket): Promise<SignaturePacket>;
|
||||
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 {
|
||||
|
|
|
@ -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<SignaturePacket>}
|
||||
* @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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user