Add date and algorithm for some PGP verify ops

This commit is contained in:
toby 2017-03-15 16:16:13 -04:00
parent bc4d7e86e3
commit d2e41b7d4b
2 changed files with 36 additions and 11 deletions

View file

@ -199,11 +199,16 @@ var PGP = {
return reject("Could not read encrypted message: " + err); return reject("Could not read encrypted message: " + err);
} }
var packetContainingAlgorithms = message.packets.filterByTag(
openpgp.enums.packet.publicKeyEncryptedSessionKey
)[0];
var verification = { var verification = {
verified: false, verified: false,
pkAlgorithm: packetContainingAlgorithms.publicKeyAlgorithm,
sessionAlgorithm: packetContainingAlgorithms.sessionKeyAlgorithm,
author: publicKeys[0].users[0].userId.userid, author: publicKeys[0].users[0].userId.userid,
recipient: privateKeys[0].users[0].userId.userid, recipient: privateKeys[0].users[0].userId.userid,
date: "",
keyID: "", keyID: "",
message: "", message: "",
}; };
@ -224,9 +229,11 @@ var PGP = {
"Verified: " + verification.verified, "Verified: " + verification.verified,
"Key ID: " + verification.keyID, "Key ID: " + verification.keyID,
"Encrypted for: " + verification.recipient, "Encrypted for: " + verification.recipient,
"Signed on: " + verification.date,
"Signed by: " + verification.author, "Signed by: " + verification.author,
"Signed with: ", "Signed with: " +
verification.pkAlgorithm +
"/" +
verification.sessionAlgorithm,
"\n", "\n",
decrypted.data, decrypted.data,
].join("\n")); ].join("\n"));
@ -333,17 +340,22 @@ var PGP = {
return reject("Could not read armoured signature or message: " + err); return reject("Could not read armoured signature or message: " + err);
} }
var packetContainingSignature = message.packets.filterByTag(
openpgp.enums.packet.signature
)[0];
var verification = { var verification = {
verified: false, verified: false,
pkAlgorithm: publicKeys[0].primaryKey.algorithm,
author: publicKeys[0].users[0].userId.userid, author: publicKeys[0].users[0].userId.userid,
date: "", date: packetContainingSignature.created,
keyID: "", keyID: "",
message: "", message: "",
}; };
Promise.resolve(message.verify(publicKeys)) Promise.resolve(message.verify(publicKeys))
.then(function(signatures) { .then(function(signatures) {
if (signatures && signatures.length) { if (signatures && signatures.length) {
verification.verified = !!signatures[0].valid; verification.verified = !!signatures[0].valid;
verification.keyID = signatures[0].keyid.toHex(); verification.keyID = signatures[0].keyid.toHex();
@ -354,7 +366,7 @@ var PGP = {
"Key ID: " + verification.keyID, "Key ID: " + verification.keyID,
"Signed on: " + verification.date, "Signed on: " + verification.date,
"Signed by: " + verification.author, "Signed by: " + verification.author,
"Signed with: ", "Signed with: " + verification.pkAlgorithm,
"\n", "\n",
input, input,
].join("\n")); ].join("\n"));
@ -433,10 +445,15 @@ var PGP = {
return reject("Could not read input message: " + err); return reject("Could not read input message: " + err);
} }
var packetContainingSignature = message.packets.filterByTag(
openpgp.enums.packet.signature
)[0];
var verification = { var verification = {
verified: false, verified: false,
pkAlgorithm: publicKeys[0].primaryKey.algorithm,
author: publicKeys[0].users[0].userId.userid, author: publicKeys[0].users[0].userId.userid,
date: "", date: packetContainingSignature.created,
keyID: "", keyID: "",
message: message.text, message: message.text,
}; };
@ -458,7 +475,7 @@ var PGP = {
"Key ID: " + verification.keyID, "Key ID: " + verification.keyID,
"Signed on: " + verification.date, "Signed on: " + verification.date,
"Signed by: " + verification.author, "Signed by: " + verification.author,
"Signed with: ", "Signed with: " + verification.pkAlgorithm,
"\n", "\n",
verification.message, verification.message,
].join("\n")); ].join("\n"));

View file

@ -304,9 +304,8 @@ TestRegister.addTests([{
"Verified: true", "Verified: true",
"Key ID: " + alice.keyID, "Key ID: " + alice.keyID,
"Encrypted for: " + bob.name, "Encrypted for: " + bob.name,
"Signed on: ",
"Signed by: " + alice.name, "Signed by: " + alice.name,
"Signed with: ", "Signed with: rsa_encrypt_sign/aes256",
"\n", "\n",
input, input,
].join("\n"), ].join("\n"),
@ -338,9 +337,8 @@ TestRegister.addTests([{
expectedOutput: [ expectedOutput: [
"Verified: true", "Verified: true",
"Key ID: " + keyPair.keyID, "Key ID: " + keyPair.keyID,
"Signed on: ",
"Signed by: " + keyPair.name, "Signed by: " + keyPair.name,
"Signed with: ", "Signed with: rsa_encrypt_sign",
"\n", "\n",
input, input,
].join("\n"), ].join("\n"),
@ -353,6 +351,16 @@ TestRegister.addTests([{
op: "Verify PGP Cleartext", op: "Verify PGP Cleartext",
args: [keyPair.pub], args: [keyPair.pub],
}, },
{
op: "Find / Replace",
args: [
{option: "Regex", string: "Signed on: .*\r?\n"},
"",
true,
false,
false,
],
},
], ],
}; };
}) })