From e69d8b24fc373342fadf6acd4602ca63105992d1 Mon Sep 17 00:00:00 2001 From: Daniel Huigens Date: Wed, 29 Jun 2022 20:09:30 +0200 Subject: [PATCH] Fix armor error handling (#1541) Fix unhandled promise rejections when parsing armor with malformed footers. --- package-lock.json | 6 +++--- package.json | 2 +- test/general/armor.js | 11 +++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index d1c658ca..501e767c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -267,9 +267,9 @@ "dev": true }, "@openpgp/web-stream-tools": { - "version": "0.0.10", - "resolved": "https://registry.npmjs.org/@openpgp/web-stream-tools/-/web-stream-tools-0.0.10.tgz", - "integrity": "sha512-1ONZADML0fb0RJR5UiGYPnRf9VaYBYUBc1gF9jyq57sHkr58cp5/BQHS+ivrqbRw21Sb70FKTssmJbRe71V+kw==", + "version": "0.0.11", + "resolved": "https://registry.npmjs.org/@openpgp/web-stream-tools/-/web-stream-tools-0.0.11.tgz", + "integrity": "sha512-52NMPRmlXIVajd5dhpDNsG7WJRCdlcS1wXY03OGH1rxm7p6i3QzJvTVyKEAcW0T9KojvLKakV2uTICceELqSMw==", "dev": true, "requires": { "@mattiasbuelens/web-streams-adapter": "~0.1.0", diff --git a/package.json b/package.json index a624c25b..50062939 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "@openpgp/pako": "^1.0.12", "@openpgp/seek-bzip": "^1.0.5-git", "@openpgp/tweetnacl": "^1.0.3", - "@openpgp/web-stream-tools": "^0.0.10", + "@openpgp/web-stream-tools": "^0.0.11", "@rollup/plugin-commonjs": "^11.1.0", "@rollup/plugin-node-resolve": "^7.1.3", "@rollup/plugin-replace": "^2.3.2", diff --git a/test/general/armor.js b/test/general/armor.js index 18eb9a68..c7958546 100644 --- a/test/general/armor.js +++ b/test/general/armor.js @@ -119,6 +119,17 @@ module.exports = () => describe('ASCII armor', function() { })); }); + it('Exception if improperly formatted armor footer', async function () { + await expect(openpgp.readCleartextMessage({ cleartextMessage: [ + '-----BEGIN PGP SIGNED MESSAGE-----', + 'Hash: SHA256', + '', + '-----BEGIN PGP SIGNATURE-----', + '', + '-----OOPS' + ].join('\n') })).to.be.rejectedWith(Error, /Misformed armored text/); + }); + it('Ignore unknown armor header - signature section', async function () { const validHeaders = ['Version: BCPG C# v1.7.4114.6375', 'Independent Reserve Pty. Ltd. 2017: 1.0.0.0']; expect(await openpgp.readCleartextMessage({ cleartextMessage: getArmor(['Hash: SHA1'], validHeaders) })).to.be.an.instanceof(openpgp.CleartextMessage);