Fix signatures of messages with leading/trailing whitespace
This commit is contained in:
parent
160b03451f
commit
95413cc6ed
|
@ -220,13 +220,13 @@ function dearmor(input) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (resolved) await writer.ready;
|
if (resolved) await writer.ready;
|
||||||
try {
|
try {
|
||||||
let line = await reader.readLine();
|
const lineUntrimmed = await reader.readLine();
|
||||||
if (line === undefined) {
|
if (lineUntrimmed === undefined) {
|
||||||
throw new Error('Misformed armored text');
|
throw new Error('Misformed armored text');
|
||||||
}
|
}
|
||||||
// remove trailing whitespace at end of lines
|
// remove trailing whitespace at end of lines
|
||||||
// remove leading whitespace for compat with older versions of OpenPGP.js
|
// remove leading whitespace for compat with older versions of OpenPGP.js
|
||||||
line = line.trim();
|
const line = lineUntrimmed.trim();
|
||||||
if (!type) {
|
if (!type) {
|
||||||
if (reSplit.test(line)) {
|
if (reSplit.test(line)) {
|
||||||
type = getType(line);
|
type = getType(line);
|
||||||
|
@ -248,7 +248,7 @@ function dearmor(input) {
|
||||||
} else if (!textDone && type === 2) {
|
} else if (!textDone && type === 2) {
|
||||||
if (!reSplit.test(line)) {
|
if (!reSplit.test(line)) {
|
||||||
// Reverse dash-escaping for msg
|
// Reverse dash-escaping for msg
|
||||||
text.push(line.replace(/^- /, ''));
|
text.push(util.removeTrailingSpaces(lineUntrimmed.replace(/^- /, '').replace(/[\r\n]+$/, '')));
|
||||||
} else {
|
} else {
|
||||||
text = text.join('\r\n');
|
text = text.join('\r\n');
|
||||||
textDone = true;
|
textDone = true;
|
||||||
|
|
|
@ -1550,7 +1550,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.message = await openpgp.cleartext.readArmored(signed.data);
|
verifyOpt.message = await openpgp.cleartext.readArmored(signed.data);
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||||
|
@ -1575,7 +1575,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
let signingKey;
|
let signingKey;
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
signingKey = await privateKey.keys[0].getSigningKey();
|
signingKey = await privateKey.keys[0].getSigningKey();
|
||||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||||
|
@ -1601,7 +1601,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||||
|
@ -1621,7 +1621,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.message = await openpgp.cleartext.readArmored(signed.data);
|
verifyOpt.message = await openpgp.cleartext.readArmored(signed.data);
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.null;
|
expect(verified.signatures[0].valid).to.be.null;
|
||||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||||
|
@ -1643,7 +1643,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.null;
|
expect(verified.signatures[0].valid).to.be.null;
|
||||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||||
|
@ -1664,7 +1664,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.message = signed.message;
|
verifyOpt.message = signed.message;
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
const signingKey = await privateKey.keys[0].getSigningKey();
|
const signingKey = await privateKey.keys[0].getSigningKey();
|
||||||
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
expect(verified.signatures[0].keyid.toHex()).to.equal(signingKey.getKeyId().toHex());
|
||||||
|
@ -1688,7 +1688,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.signature = signed.signature;
|
verifyOpt.signature = signed.signature;
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(async function (verified) {
|
}).then(async function (verified) {
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(+verified.signatures[0].signature.packets[0].created).to.be.lte(+openpgp.util.normalizeDate());
|
expect(+verified.signatures[0].signature.packets[0].created).to.be.lte(+openpgp.util.normalizeDate());
|
||||||
expect(+verified.signatures[0].signature.packets[0].created).to.be.gte(+start);
|
expect(+verified.signatures[0].signature.packets[0].created).to.be.gte(+start);
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
|
@ -1715,7 +1715,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
verifyOpt.signature = await openpgp.signature.readArmored(signed.signature);
|
||||||
return openpgp.verify(verifyOpt).then(function (verified) {
|
return openpgp.verify(verifyOpt).then(function (verified) {
|
||||||
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+past);
|
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+past);
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
expect(signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, past))
|
expect(signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, past))
|
||||||
.to.be.not.null;
|
.to.be.not.null;
|
||||||
|
@ -1725,7 +1725,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
return openpgp.verify(verifyOpt);
|
return openpgp.verify(verifyOpt);
|
||||||
}).then(function (verified) {
|
}).then(function (verified) {
|
||||||
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+past);
|
expect(+verified.signatures[0].signature.packets[0].created).to.equal(+past);
|
||||||
expect(verified.data).to.equal(plaintext);
|
expect(verified.data).to.equal(openpgp.util.removeTrailingSpaces(plaintext));
|
||||||
expect(verified.signatures[0].valid).to.be.true;
|
expect(verified.signatures[0].valid).to.be.true;
|
||||||
expect(signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, null))
|
expect(signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, null))
|
||||||
.to.be.not.null;
|
.to.be.not.null;
|
||||||
|
|
|
@ -9,7 +9,7 @@ function createSomeMessage(){
|
||||||
arr.push(String.fromCharCode(
|
arr.push(String.fromCharCode(
|
||||||
Math.floor(Math.random() * 10174) + 1));
|
Math.floor(Math.random() * 10174) + 1));
|
||||||
}
|
}
|
||||||
return arr.join('');
|
return arr.join('').replace(/\r/g, '\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user