reuse createVerificationObjects for cleartext
This commit is contained in:
parent
2ffd81553d
commit
38a11d7aaf
|
@ -29,6 +29,7 @@ import armor from './encoding/armor';
|
||||||
import enums from './enums';
|
import enums from './enums';
|
||||||
import packet from './packet';
|
import packet from './packet';
|
||||||
import { Signature } from './signature';
|
import { Signature } from './signature';
|
||||||
|
import { createVerificationObjects } from './message';
|
||||||
import { getPreferredHashAlgo } from './key';
|
import { getPreferredHashAlgo } from './key';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,6 +83,7 @@ CleartextMessage.prototype.signDetached = async function(privateKeys) {
|
||||||
const packetlist = new packet.List();
|
const packetlist = new packet.List();
|
||||||
const literalDataPacket = new packet.Literal();
|
const literalDataPacket = new packet.Literal();
|
||||||
literalDataPacket.setText(this.text);
|
literalDataPacket.setText(this.text);
|
||||||
|
|
||||||
await Promise.all(privateKeys.map(async function(privateKey) {
|
await Promise.all(privateKeys.map(async function(privateKey) {
|
||||||
if (privateKey.isPublic()) {
|
if (privateKey.isPublic()) {
|
||||||
throw new Error('Need private key for signing');
|
throw new Error('Need private key for signing');
|
||||||
|
@ -127,28 +129,7 @@ CleartextMessage.prototype.verifyDetached = function(signature, keys) {
|
||||||
const literalDataPacket = new packet.Literal();
|
const literalDataPacket = new packet.Literal();
|
||||||
// we assume that cleartext signature is generated based on UTF8 cleartext
|
// we assume that cleartext signature is generated based on UTF8 cleartext
|
||||||
literalDataPacket.setText(this.text);
|
literalDataPacket.setText(this.text);
|
||||||
return Promise.all(signatureList.map(async function(signature) {
|
return createVerificationObjects(signatureList, [literalDataPacket], keys);
|
||||||
let keyPacket = null;
|
|
||||||
await Promise.all(keys.map(async function(key) {
|
|
||||||
await key.verifyPrimaryUser();
|
|
||||||
// Look for the unique key packet that matches issuerKeyId of signature
|
|
||||||
const result = key.getSigningKeyPacket(signature.issuerKeyId, config.verify_expired_keys);
|
|
||||||
if (result) {
|
|
||||||
keyPacket = result;
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
const verifiedSig = {
|
|
||||||
keyid: signature.issuerKeyId,
|
|
||||||
valid: keyPacket ? await signature.verify(keyPacket, literalDataPacket) : null
|
|
||||||
};
|
|
||||||
|
|
||||||
const packetlist = new packet.List();
|
|
||||||
packetlist.push(signature);
|
|
||||||
verifiedSig.signature = new Signature(packetlist);
|
|
||||||
|
|
||||||
return verifiedSig;
|
|
||||||
}));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -540,7 +540,7 @@ Message.prototype.verifyDetached = function(signature, keys) {
|
||||||
* @param {Array<module:key~Key>} keys array of keys to verify signatures
|
* @param {Array<module:key~Key>} keys array of keys to verify signatures
|
||||||
* @return {Array<({keyid: module:type/keyid, valid: Boolean})>} list of signer's keyid and validity of signature
|
* @return {Array<({keyid: module:type/keyid, valid: Boolean})>} list of signer's keyid and validity of signature
|
||||||
*/
|
*/
|
||||||
async function createVerificationObjects(signatureList, literalDataList, keys) {
|
export async function createVerificationObjects(signatureList, literalDataList, keys) {
|
||||||
return Promise.all(signatureList.map(async function(signature) {
|
return Promise.all(signatureList.map(async function(signature) {
|
||||||
let keyPacket = null;
|
let keyPacket = null;
|
||||||
await Promise.all(keys.map(async function(key) {
|
await Promise.all(keys.map(async function(key) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user