Fix signatures of messages with leading/trailing whitespace

This commit is contained in:
Daniel Huigens 2018-06-27 15:53:32 +02:00
parent 160b03451f
commit 95413cc6ed
3 changed files with 14 additions and 14 deletions

View File

@ -220,13 +220,13 @@ function dearmor(input) {
while (true) {
if (resolved) await writer.ready;
try {
let line = await reader.readLine();
if (line === undefined) {
const lineUntrimmed = await reader.readLine();
if (lineUntrimmed === undefined) {
throw new Error('Misformed armored text');
}
// remove trailing whitespace at end of lines
// remove leading whitespace for compat with older versions of OpenPGP.js
line = line.trim();
const line = lineUntrimmed.trim();
if (!type) {
if (reSplit.test(line)) {
type = getType(line);
@ -248,7 +248,7 @@ function dearmor(input) {
} else if (!textDone && type === 2) {
if (!reSplit.test(line)) {
// Reverse dash-escaping for msg
text.push(line.replace(/^- /, ''));
text.push(util.removeTrailingSpaces(lineUntrimmed.replace(/^- /, '').replace(/[\r\n]+$/, '')));
} else {
text = text.join('\r\n');
textDone = true;

View File

@ -1550,7 +1550,7 @@ describe('OpenPGP.js public api tests', function() {
verifyOpt.message = await openpgp.cleartext.readArmored(signed.data);
return openpgp.verify(verifyOpt);
}).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;
const signingKey = await privateKey.keys[0].getSigningKey();
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);
}).then(async function (verified) {
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;
signingKey = await privateKey.keys[0].getSigningKey();
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);
return openpgp.verify(verifyOpt);
}).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;
const signingKey = await privateKey.keys[0].getSigningKey();
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);
return openpgp.verify(verifyOpt);
}).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;
const signingKey = await privateKey.keys[0].getSigningKey();
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);
return openpgp.verify(verifyOpt);
}).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;
const signingKey = await privateKey.keys[0].getSigningKey();
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;
return openpgp.verify(verifyOpt);
}).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;
const signingKey = await privateKey.keys[0].getSigningKey();
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;
return openpgp.verify(verifyOpt);
}).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.gte(+start);
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);
return openpgp.verify(verifyOpt).then(function (verified) {
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(signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, past))
.to.be.not.null;
@ -1725,7 +1725,7 @@ describe('OpenPGP.js public api tests', function() {
return openpgp.verify(verifyOpt);
}).then(function (verified) {
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(signOpt.privateKeys[0].getSigningKey(verified.signatures[0].keyid, null))
.to.be.not.null;

View File

@ -9,7 +9,7 @@ function createSomeMessage(){
arr.push(String.fromCharCode(
Math.floor(Math.random() * 10174) + 1));
}
return arr.join('');
return arr.join('').replace(/\r/g, '\n');
}
module.exports = {