diff --git a/src/config/config.js b/src/config/config.js index 6a070b76..fd37baba 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -44,6 +44,7 @@ export default { use_native: true, // use native node.js crypto and Web Crypto apis (if available) zero_copy: false, // use transferable objects between the Web Worker and main thread debug: false, + tolerant: true, // ignore unsupported/unrecognizable packets instead of throwing an error show_version: true, show_comment: true, versionstring: "OpenPGP.js VERSION", diff --git a/src/packet/compressed.js b/src/packet/compressed.js index e6db0134..619a87da 100644 --- a/src/packet/compressed.js +++ b/src/packet/compressed.js @@ -120,7 +120,7 @@ Compressed.prototype.decompress = function () { throw new Error('Compression algorithm BZip2 [BZ2] is not implemented.'); default: - throw new Error("Compression algorithm unknown :" + this.alogrithm); + throw new Error("Compression algorithm unknown :" + this.algorithm); } this.packets.read(decompressed); diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index 460821c2..01d5c0cd 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -15,6 +15,7 @@ import util from '../util'; import packetParser from './packet.js'; import * as packets from './all_packets.js'; import enums from '../enums.js'; +import config from '../config'; /** * @constructor @@ -44,6 +45,9 @@ Packetlist.prototype.read = function (bytes) { pushed = true; packet.read(parsed.packet); } catch(e) { + if (!config.tolerant || parsed.tag == enums.packet.symmetricallyEncrypted || parsed.tag == enums.packet.literal || parsed.tag == enums.packet.compressed) { + throw e; + } if (pushed) { this.pop(); // drop unsupported packet } diff --git a/test/general/key.js b/test/general/key.js index a04da7a4..16e0610b 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -527,7 +527,8 @@ describe('Key', function() { '=Q/kB', '-----END PGP PUBLIC KEY BLOCK-----'].join('\n'); - it('Parsing armored text with RSA key and ECC subkey', function(done) { + it('Parsing armored text with RSA key and ECC subkey in tolerant mode', function(done) { + openpgp.config.tolerant = true; var pubKeys = openpgp.key.readArmored(rsa_ecc_pub); expect(pubKeys).to.exist; expect(pubKeys.err).to.not.exist; @@ -536,6 +537,15 @@ describe('Key', function() { done(); }); + it('Parsing armored text with RSA key and ECC subkey in non-tolerant mode', function(done) { + openpgp.config.tolerant = false; + var pubKeys = openpgp.key.readArmored(rsa_ecc_pub); + expect(pubKeys).to.exist; + expect(pubKeys.err).to.exist; + done(); + }); + + var multi_uid_key = ['-----BEGIN PGP PUBLIC KEY BLOCK-----', 'Version: GnuPG v1',