Add Signature#getSigningKeyIDs method to get Issuer Key IDs from a Signature (#1331)
This commit is contained in:
parent
619d02d78c
commit
a9252c6649
1
openpgp.d.ts
vendored
1
openpgp.d.ts
vendored
|
@ -114,6 +114,7 @@ export class Signature {
|
||||||
constructor(packetlist: PacketList<SignaturePacket>);
|
constructor(packetlist: PacketList<SignaturePacket>);
|
||||||
public write(): MaybeStream<Uint8Array>;
|
public write(): MaybeStream<Uint8Array>;
|
||||||
public armor(config?: Config): string;
|
public armor(config?: Config): string;
|
||||||
|
public getSigningKeyIDs(): Array<KeyID>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface VerificationResult {
|
interface VerificationResult {
|
||||||
|
|
|
@ -51,6 +51,19 @@ export class Signature {
|
||||||
armor(config = defaultConfig) {
|
armor(config = defaultConfig) {
|
||||||
return armor(enums.armor.signature, this.write(), undefined, undefined, undefined, config);
|
return armor(enums.armor.signature, this.write(), undefined, undefined, undefined, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of KeyIDs of all of the issuers who created this signature
|
||||||
|
* @returns {Array<KeyID>} The Key IDs of the signing keys
|
||||||
|
*/
|
||||||
|
getSigningKeyIDs() {
|
||||||
|
const keyIDs = [];
|
||||||
|
const signatureList = this.packets.filterByTag(enums.packet.signature);
|
||||||
|
signatureList.forEach(function(packet) {
|
||||||
|
keyIDs.push(packet.issuerKeyID);
|
||||||
|
});
|
||||||
|
return keyIDs;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -650,6 +650,30 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
|
||||||
-----END PGP SIGNATURE-----
|
-----END PGP SIGNATURE-----
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
it("Retrieve the issuer Key ID of a signature", async function () {
|
||||||
|
const { privateKeyArmored, publicKeyArmored } = await openpgp.generateKey({
|
||||||
|
type: "ecc", // Type of the key, defaults to ECC
|
||||||
|
curve: "curve25519", // ECC curve name, defaults to curve25519
|
||||||
|
userIDs: [{ name: "name", email: "test@email.com" }], // you can pass multiple user IDs
|
||||||
|
passphrase: "password" // protects the private key
|
||||||
|
});
|
||||||
|
|
||||||
|
const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
|
||||||
|
const privateKey = await openpgp.decryptKey({
|
||||||
|
privateKey: await openpgp.readKey({ armoredKey: privateKeyArmored }),
|
||||||
|
passphrase: "password"
|
||||||
|
});
|
||||||
|
const message = await openpgp.createMessage({ text: "test" });
|
||||||
|
const armoredSignature = await openpgp.sign({
|
||||||
|
message,
|
||||||
|
signingKeys: privateKey,
|
||||||
|
detached: true
|
||||||
|
});
|
||||||
|
const signature = await openpgp.readSignature({ armoredSignature });
|
||||||
|
expect(signature.getSigningKeyIDs).to.exist;
|
||||||
|
expect(signature.getSigningKeyIDs().map(x => x.toHex())).to.include(publicKey.getKeyID().toHex());
|
||||||
|
});
|
||||||
|
|
||||||
it('Throws when reading a signature missing the creation time', async function () {
|
it('Throws when reading a signature missing the creation time', async function () {
|
||||||
const armoredSignature = `-----BEGIN PGP SIGNATURE-----
|
const armoredSignature = `-----BEGIN PGP SIGNATURE-----
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user