diff --git a/README.md b/README.md index 92bbfb61..708aa9e6 100644 --- a/README.md +++ b/README.md @@ -149,13 +149,13 @@ const privkey = `-----BEGIN PGP PRIVATE KEY BLOCK----- const passphrase = `yourPassphrase` //what the privKey is encrypted with const encryptDecryptFunction = async() => { - const privKeyObj = openpgp.key.readArmored(privkey).keys[0] + const privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0] await privKeyObj.decrypt(passphrase) const options = { - data: 'Hello, World!', // input as String (or Uint8Array) - publicKeys: openpgp.key.readArmored(pubkey).keys, // for encryption - privateKeys: [privKeyObj] // for signing (optional) + data: 'Hello, World!', // input as String (or Uint8Array) + publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for encryption + privateKeys: [privKeyObj] // for signing (optional) } openpgp.encrypt(options).then(ciphertext => { @@ -164,9 +164,9 @@ const encryptDecryptFunction = async() => { }) .then(encrypted => { const options = { - message: openpgp.message.readArmored(encrypted), // parse armored message - publicKeys: openpgp.key.readArmored(pubkey).keys, // for verification (optional) - privateKeys: [privKeyObj] // for decryption + message: await openpgp.message.readArmored(encrypted), // parse armored message + publicKeys: (await openpgp.key.readArmored(pubkey)).keys, // for verification (optional) + privateKeys: [privKeyObj] // for decryption } openpgp.decrypt(options).then(plaintext => { @@ -277,7 +277,7 @@ var options = { }; hkp.lookup(options).then(function(key) { - var pubkey = openpgp.key.readArmored(key); + var pubkey = await openpgp.key.readArmored(key); }); ``` @@ -300,7 +300,7 @@ var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----' var privkey = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----'; //encrypted private key var passphrase = 'secret passphrase'; //what the privKey is encrypted with -var privKeyObj = openpgp.key.readArmored(privkey).keys[0]; +var privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]; await privKeyObj.decrypt(passphrase); ``` @@ -317,8 +317,8 @@ openpgp.sign(options).then(function(signed) { ```js options = { - message: openpgp.cleartext.readArmored(cleartext), // parse armored message - publicKeys: openpgp.key.readArmored(pubkey).keys // for verification + message: await openpgp.cleartext.readArmored(cleartext), // parse armored message + publicKeys: (await openpgp.key.readArmored(pubkey)).keys // for verification }; openpgp.verify(options).then(function(verified) { @@ -338,7 +338,7 @@ var pubkey = '-----BEGIN PGP PUBLIC KEY BLOCK ... END PGP PUBLIC KEY BLOCK-----' var privkey = '-----BEGIN PGP PRIVATE KEY BLOCK ... END PGP PRIVATE KEY BLOCK-----'; //encrypted private key var passphrase = 'secret passphrase'; //what the privKey is encrypted with -var privKeyObj = openpgp.key.readArmored(privkey).keys[0]; +var privKeyObj = (await openpgp.key.readArmored(privkey)).keys[0]; await privKeyObj.decrypt(passphrase); ``` @@ -357,9 +357,9 @@ openpgp.sign(options).then(function(signed) { ```js options = { - message: openpgp.message.fromText('Hello, World!'), // input as Message object - signature: openpgp.signature.readArmored(detachedSig), // parse detached signature - publicKeys: openpgp.key.readArmored(pubkey).keys // for verification + message: openpgp.message.fromText('Hello, World!'), // input as Message object + signature: await openpgp.signature.readArmored(detachedSig), // parse detached signature + publicKeys: (await openpgp.key.readArmored(pubkey)).keys // for verification }; openpgp.verify(options).then(function(verified) { diff --git a/src/cleartext.js b/src/cleartext.js index 2872cc96..56b5a272 100644 --- a/src/cleartext.js +++ b/src/cleartext.js @@ -151,13 +151,13 @@ CleartextMessage.prototype.armor = function() { * @returns {module:cleartext.CleartextMessage} new cleartext message object * @static */ -export function readArmored(armoredText) { - const input = armor.decode(armoredText); +export async function readArmored(armoredText) { + const input = await armor.decode(armoredText); if (input.type !== enums.armor.signed) { throw new Error('No cleartext signed message.'); } const packetlist = new packet.List(); - packetlist.read(input.data); + await packetlist.read(input.data); verifyHeaders(input.headers, packetlist); const signature = new Signature(packetlist); return new CleartextMessage(input.text, signature); diff --git a/src/crypto/signature.js b/src/crypto/signature.js index 41866c4e..7549c98d 100644 --- a/src/crypto/signature.js +++ b/src/crypto/signature.js @@ -29,6 +29,7 @@ export default { * @async */ verify: async function(algo, hash_algo, msg_MPIs, pub_MPIs, data) { + data = await data.readToEnd(); switch (algo) { case enums.publicKey.rsa_encrypt_sign: case enums.publicKey.rsa_encrypt: @@ -82,6 +83,7 @@ export default { * @async */ sign: async function(algo, hash_algo, key_params, data) { + data = await data.readToEnd(); switch (algo) { case enums.publicKey.rsa_encrypt_sign: case enums.publicKey.rsa_encrypt: diff --git a/src/encoding/armor.js b/src/encoding/armor.js index 4622af7c..5b95d9af 100644 --- a/src/encoding/armor.js +++ b/src/encoding/armor.js @@ -269,7 +269,10 @@ function splitChecksum(text) { * an attribute "data" containing the bytes and "type" for the ASCII armor type * @static */ -function dearmorStream(text) { +function dearmor(text) { + if (util.isString(text)) { + text = util.str_to_Uint8Array(text); + } return new Promise(async (resolve, reject) => { const reSplit = /^-----[^-]+-----$/; const reEmptyLine = /^[ \f\r\t\u00a0\u2000-\u200a\u202f\u205f\u3000]*$/; @@ -348,7 +351,7 @@ function dearmorStream(text) { * an attribute "data" containing the bytes and "type" for the ASCII armor type * @static */ -function dearmor(text) { +/*function dearmor(text) { const reSplit = /^-----[^-]+-----$\n/m; // trim string and remove trailing whitespace at end of lines @@ -409,7 +412,7 @@ function dearmor(text) { verifyHeaders(result.headers); return result; -} +}*/ /** @@ -491,6 +494,5 @@ function armor(messagetype, body, partindex, parttotal, customComment) { export default { encode: armor, - decode: dearmor, - decodeStream: dearmorStream + decode: dearmor }; diff --git a/src/key.js b/src/key.js index d51c87eb..e4da1ce1 100644 --- a/src/key.js +++ b/src/key.js @@ -694,9 +694,9 @@ Key.prototype.getRevocationCertificate = function() { * @return {module:key~Key} new revoked key */ Key.prototype.applyRevocationCertificate = async function(revocationCertificate) { - const input = armor.decode(revocationCertificate); + const input = await armor.decode(revocationCertificate); const packetlist = new packet.List(); - packetlist.read(input.data); + await packetlist.read(input.data); const revocationSignature = packetlist.findPacket(enums.packet.signature); if (!revocationSignature || revocationSignature.signatureType !== enums.signature.key_revocation) { throw new Error('Could not find revocation signature packet'); @@ -1192,12 +1192,12 @@ SubKey.prototype.revoke = async function(primaryKey, { * err: (Array|null)}} result object with key and error arrays * @static */ -export function read(data) { +export async function read(data) { const result = {}; result.keys = []; try { const packetlist = new packet.List(); - packetlist.read(data); + await packetlist.read(data); const keyIndex = packetlist.indexOfTag(enums.packet.publicKey, enums.packet.secretKey); if (keyIndex.length === 0) { throw new Error('No key packet found'); @@ -1226,9 +1226,9 @@ export function read(data) { * err: (Array|null)}} result object with key and error arrays * @static */ -export function readArmored(armoredText) { +export async function readArmored(armoredText) { try { - const input = armor.decode(armoredText); + const input = await armor.decode(armoredText); if (!(input.type === enums.armor.public_key || input.type === enums.armor.private_key)) { throw new Error('Armored text not of type key'); } diff --git a/src/keyring/keyring.js b/src/keyring/keyring.js index d71c021b..adedca8f 100644 --- a/src/keyring/keyring.js +++ b/src/keyring/keyring.js @@ -27,22 +27,29 @@ import LocalStore from './localstore'; /** * Initialization routine for the keyring. - * This method reads the keyring from HTML5 local storage and initializes this instance. * @constructor * @param {keyring/localstore} [storeHandler] class implementing loadPublic(), loadPrivate(), storePublic(), and storePrivate() methods */ function Keyring(storeHandler) { this.storeHandler = storeHandler || new LocalStore(); - this.publicKeys = new KeyArray(this.storeHandler.loadPublic()); - this.privateKeys = new KeyArray(this.storeHandler.loadPrivate()); } +/** + * Calls the storeHandler to load the keys + */ +Keyring.prototype.load = async function () { + this.publicKeys = new KeyArray(await this.storeHandler.loadPublic()); + this.privateKeys = new KeyArray(await this.storeHandler.loadPrivate()); +}; + /** * Calls the storeHandler to save the keys */ -Keyring.prototype.store = function () { - this.storeHandler.storePublic(this.publicKeys.keys); - this.storeHandler.storePrivate(this.privateKeys.keys); +Keyring.prototype.store = async function () { + await Promise.all([ + this.storeHandler.storePublic(this.publicKeys.keys), + this.storeHandler.storePrivate(this.privateKeys.keys) + ]); }; /** @@ -178,7 +185,7 @@ KeyArray.prototype.getForId = function (keyId, deep) { * @async */ KeyArray.prototype.importKey = async function (armored) { - const imported = readArmored(armored); + const imported = await readArmored(armored); for (let i = 0; i < imported.keys.length; i++) { const key = imported.keys[i]; // check if key already in key array diff --git a/src/keyring/localstore.js b/src/keyring/localstore.js index 15212a33..a984ece2 100644 --- a/src/keyring/localstore.js +++ b/src/keyring/localstore.js @@ -19,12 +19,14 @@ * @fileoverview Provides the LocalStore class * @requires config * @requires key + * @requires stream * @requires util * @module keyring/localstore */ import config from '../config'; import { readArmored } from '../key'; +import stream from '../stream'; import util from '../util'; /** @@ -54,7 +56,7 @@ LocalStore.prototype.privateKeysItem = 'private-keys'; * Load the public keys from HTML5 local storage. * @returns {Array} array of keys retrieved from localstore */ -LocalStore.prototype.loadPublic = function () { +LocalStore.prototype.loadPublic = async function () { return loadKeys(this.storage, this.publicKeysItem); }; @@ -62,17 +64,17 @@ LocalStore.prototype.loadPublic = function () { * Load the private keys from HTML5 local storage. * @returns {Array} array of keys retrieved from localstore */ -LocalStore.prototype.loadPrivate = function () { +LocalStore.prototype.loadPrivate = async function () { return loadKeys(this.storage, this.privateKeysItem); }; -function loadKeys(storage, itemname) { +async function loadKeys(storage, itemname) { const armoredKeys = JSON.parse(storage.getItem(itemname)); const keys = []; if (armoredKeys !== null && armoredKeys.length !== 0) { let key; for (let i = 0; i < armoredKeys.length; i++) { - key = readArmored(armoredKeys[i]); + key = await readArmored(armoredKeys[i]); if (!key.err) { keys.push(key.keys[0]); } else { @@ -88,8 +90,8 @@ function loadKeys(storage, itemname) { * The key array gets stringified using JSON * @param {Array} keys array of keys to save in localstore */ -LocalStore.prototype.storePublic = function (keys) { - storeKeys(this.storage, this.publicKeysItem, keys); +LocalStore.prototype.storePublic = async function (keys) { + await storeKeys(this.storage, this.publicKeysItem, keys); }; /** @@ -97,16 +99,13 @@ LocalStore.prototype.storePublic = function (keys) { * The key array gets stringified using JSON * @param {Array} keys array of keys to save in localstore */ -LocalStore.prototype.storePrivate = function (keys) { - storeKeys(this.storage, this.privateKeysItem, keys); +LocalStore.prototype.storePrivate = async function (keys) { + await storeKeys(this.storage, this.privateKeysItem, keys); }; -function storeKeys(storage, itemname, keys) { - const armoredKeys = []; +async function storeKeys(storage, itemname, keys) { if (keys.length) { - for (let i = 0; i < keys.length; i++) { - armoredKeys.push(keys[i].armor()); - } + const armoredKeys = await Promise.all(keys.map(key => stream.readToEnd(key.armor()))); storage.setItem(itemname, JSON.stringify(armoredKeys)); } else { storage.removeItem(itemname); diff --git a/src/message.js b/src/message.js index 39d3c3ab..074fe5a5 100644 --- a/src/message.js +++ b/src/message.js @@ -607,8 +607,8 @@ Message.prototype.unwrapCompressed = function() { * Append signature to unencrypted message object * @param {String|Uint8Array} detachedSignature The detached ASCII-armored or Uint8Array PGP signature */ -Message.prototype.appendSignature = function(detachedSignature) { - this.packets.read(util.isUint8Array(detachedSignature) ? detachedSignature : armor.decode(detachedSignature).data); +Message.prototype.appendSignature = async function(detachedSignature) { + await this.packets.read(util.isUint8Array(detachedSignature) ? detachedSignature : (await armor.decode(detachedSignature)).data); }; /** @@ -625,53 +625,28 @@ Message.prototype.armor = function() { * @returns {module:message.Message} new message object * @static */ -async function readArmoredStream(armoredText) { - const input = await armor.decodeStream(armoredText); - return readStream(input.data); -} - -/** - * reads an OpenPGP armored message and returns a message object - * @param {String} armoredText text to be parsed - * @returns {module:message.Message} new message object - * @static - */ -export function readArmored(armoredText) { - if (util.isStream(armoredText)) { - return readArmoredStream(armoredText); - } +export async function readArmored(armoredText) { //TODO how do we want to handle bad text? Exception throwing //TODO don't accept non-message armored texts - const input = armor.decode(armoredText).data; - return read(input); + const input = await armor.decode(armoredText); + return read(input.data, util.isStream(armoredText)); } /** * reads an OpenPGP message as byte array and returns a message object - * @param {Uint8Array} input binary message + * @param {Uint8Array} input binary message + * @param {Boolean} fromStream whether the message was created from a Stream * @returns {Message} new message object * @static */ -async function readStream(input) { +export async function read(input, fromStream) { const packetlist = new packet.List(); - await packetlist.readStream(input); + await packetlist.read(input); const message = new Message(packetlist); - message.fromStream = true; + message.fromStream = fromStream; return message; } -/** - * reads an OpenPGP message as byte array and returns a message object - * @param {Uint8Array} input binary message - * @returns {Message} new message object - * @static - */ -export function read(input) { - const packetlist = new packet.List(); - packetlist.read(input); - return new Message(packetlist); -} - /** * creates new message object from text * @param {String} text diff --git a/src/packet/compressed.js b/src/packet/compressed.js index b6b46190..9acc53b0 100644 --- a/src/packet/compressed.js +++ b/src/packet/compressed.js @@ -67,14 +67,14 @@ function Compressed() { * Parsing function for the packet. * @param {String} bytes Payload of a tag 8 packet */ -Compressed.prototype.read = function (bytes) { +Compressed.prototype.read = async function (bytes) { // One octet that gives the algorithm used to compress the packet. this.algorithm = enums.read(enums.compression, bytes[0]); // Compressed data, which makes up the remainder of the packet. this.compressed = bytes.subarray(1, bytes.length); - this.decompress(); + await this.decompress(); }; @@ -95,13 +95,13 @@ Compressed.prototype.write = function () { * Decompression method for decompressing the compressed data * read by read_packet */ -Compressed.prototype.decompress = function () { +Compressed.prototype.decompress = async function () { if (!decompress_fns[this.algorithm]) { throw new Error("Compression algorithm unknown :" + this.algorithm); } - this.packets.read(decompress_fns[this.algorithm](this.compressed)); + await this.packets.read(decompress_fns[this.algorithm](this.compressed)); }; /** diff --git a/src/packet/packet.js b/src/packet/packet.js index aa48af68..bd2ebbe3 100644 --- a/src/packet/packet.js +++ b/src/packet/packet.js @@ -118,7 +118,7 @@ export default { * @param {integer} len Length of the input from position on * @returns {Object} Returns a parsed module:packet/packet */ - readStream: function(reader) { + read: function(reader) { return new Promise(async (resolve, reject) => { const peekedBytes = await reader.peekBytes(2); // some sanity checks @@ -252,148 +252,5 @@ export default { } } }); - }, - - /** - * Generic static Packet Parser function - * - * @param {String} input Input stream as string - * @param {integer} position Position to start parsing - * @param {integer} len Length of the input from position on - * @returns {Object} Returns a parsed module:packet/packet - */ - read: function(input, position, len) { - // some sanity checks - if (input === null || input.length <= position || input.subarray(position, input.length).length < 2 || (input[position] & - 0x80) === 0) { - throw new Error("Error during parsing. This message / key probably does not conform to a valid OpenPGP format."); - } - let mypos = position; - let tag = -1; - let format = -1; - let packet_length; - - format = 0; // 0 = old format; 1 = new format - if ((input[mypos] & 0x40) !== 0) { - format = 1; - } - - let packet_length_type; - if (format) { - // new format header - tag = input[mypos] & 0x3F; // bit 5-0 - } else { - // old format header - tag = (input[mypos] & 0x3F) >> 2; // bit 5-2 - packet_length_type = input[mypos] & 0x03; // bit 1-0 - } - - // header octet parsing done - mypos++; - - let bodydata = null; - - // used for partial body lengths - let real_packet_length = -1; - if (!format) { - // 4.2.1. Old Format Packet Lengths - switch (packet_length_type) { - case 0: - // The packet has a one-octet length. The header is 2 octets - // long. - packet_length = input[mypos++]; - break; - case 1: - // The packet has a two-octet length. The header is 3 octets - // long. - packet_length = (input[mypos++] << 8) | input[mypos++]; - break; - case 2: - // The packet has a four-octet length. The header is 5 - // octets long. - packet_length = (input[mypos++] << 24) | (input[mypos++] << 16) | (input[mypos++] << - 8) | input[mypos++]; - break; - default: - // 3 - The packet is of indeterminate length. The header is 1 - // octet long, and the implementation must determine how long - // the packet is. If the packet is in a file, this means that - // the packet extends until the end of the file. In general, - // an implementation SHOULD NOT use indeterminate-length - // packets except where the end of the data will be clear - // from the context, and even then it is better to use a - // definite length, or a new format header. The new format - // headers described below have a mechanism for precisely - // encoding data of indeterminate length. - packet_length = len; - break; - } - } else { // 4.2.2. New Format Packet Lengths - // 4.2.2.1. One-Octet Lengths - if (input[mypos] < 192) { - packet_length = input[mypos++]; - // 4.2.2.2. Two-Octet Lengths - } else if (input[mypos] >= 192 && input[mypos] < 224) { - packet_length = ((input[mypos++] - 192) << 8) + (input[mypos++]) + 192; - // 4.2.2.4. Partial Body Lengths - } else if (input[mypos] > 223 && input[mypos] < 255) { - packet_length = 1 << (input[mypos++] & 0x1F); - // EEEK, we're reading the full data here... - let mypos2 = mypos + packet_length; - bodydata = [input.subarray(mypos, mypos + packet_length)]; - let tmplen; - while (true) { - if (input[mypos2] < 192) { - tmplen = input[mypos2++]; - packet_length += tmplen; - bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); - mypos2 += tmplen; - break; - } else if (input[mypos2] >= 192 && input[mypos2] < 224) { - tmplen = ((input[mypos2++] - 192) << 8) + (input[mypos2++]) + 192; - packet_length += tmplen; - bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); - mypos2 += tmplen; - break; - } else if (input[mypos2] > 223 && input[mypos2] < 255) { - tmplen = 1 << (input[mypos2++] & 0x1F); - packet_length += tmplen; - bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); - mypos2 += tmplen; - } else { - mypos2++; - tmplen = (input[mypos2++] << 24) | (input[mypos2++] << 16) | (input[mypos2++] << 8) | input[mypos2++]; - bodydata.push(input.subarray(mypos2, mypos2 + tmplen)); - packet_length += tmplen; - mypos2 += tmplen; - break; - } - } - real_packet_length = mypos2 - mypos; - // 4.2.2.3. Five-Octet Lengths - } else { - mypos++; - packet_length = (input[mypos++] << 24) | (input[mypos++] << 16) | (input[mypos++] << - 8) | input[mypos++]; - } - } - - // if there was'nt a partial body length: use the specified - // packet_length - if (real_packet_length === -1) { - real_packet_length = packet_length; - } - - if (bodydata === null) { - bodydata = input.subarray(mypos, mypos + real_packet_length); - } else if (bodydata instanceof Array) { - bodydata = util.concatUint8Array(bodydata); - } - - return { - tag: tag, - packet: bodydata, - offset: mypos + real_packet_length - }; } }; diff --git a/src/packet/packetlist.js b/src/packet/packetlist.js index d589d67e..314c07ae 100644 --- a/src/packet/packetlist.js +++ b/src/packet/packetlist.js @@ -33,10 +33,10 @@ function List() { * Reads a stream of binary data and interprents it as a list of packets. * @param {Uint8Array} A Uint8Array of bytes. */ -List.prototype.readStream = async function (bytes) { +List.prototype.read = async function (bytes) { const reader = bytes.getReader(); while (true) { - const parsed = await packetParser.readStream(reader); + const parsed = await packetParser.read(reader); let pushed = false; try { @@ -44,11 +44,7 @@ List.prototype.readStream = async function (bytes) { const packet = packets.newPacketFromTag(tag); this.push(packet); pushed = true; - if (packet.readStream) { - await packet.readStream(parsed.packet); - } else { - await packet.read(parsed.packet); - } + await packet.read(parsed.packet); if (parsed.done) { break; } @@ -67,39 +63,6 @@ List.prototype.readStream = async function (bytes) { } }; -/** - * Reads a stream of binary data and interprents it as a list of packets. - * @param {Uint8Array} A Uint8Array of bytes. - */ -List.prototype.read = function (bytes) { - let i = 0; - - while (i < bytes.length) { - const parsed = packetParser.read(bytes, i, bytes.length - i); - i = parsed.offset; - - let pushed = false; - try { - const tag = enums.read(enums.packet, parsed.tag); - const packet = packets.newPacketFromTag(tag); - this.push(packet); - 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; - } - util.print_debug_error(e); - if (pushed) { - this.pop(); // drop unsupported packet - } - } - } -}; - /** * Creates a binary representation of openpgp objects contained within the * class instance. diff --git a/src/packet/sym_encrypted_aead_protected.js b/src/packet/sym_encrypted_aead_protected.js index 41190bbd..34f2a2c4 100644 --- a/src/packet/sym_encrypted_aead_protected.js +++ b/src/packet/sym_encrypted_aead_protected.js @@ -97,10 +97,10 @@ SymEncryptedAEADProtected.prototype.decrypt = async function (sessionKeyAlgorith if (config.aead_protect_version === 4) { const data = this.encrypted.subarray(0, -mode.tagLength); const authTag = this.encrypted.subarray(-mode.tagLength); - this.packets.read(await this.crypt('decrypt', key, data, authTag)); + await this.packets.read(await this.crypt('decrypt', key, data, authTag)); } else { this.cipherAlgo = enums.write(enums.symmetric, sessionKeyAlgorithm); - this.packets.read(await this.crypt('decrypt', key, this.encrypted)); + await this.packets.read(await this.crypt('decrypt', key, this.encrypted)); } return true; }; diff --git a/src/packet/sym_encrypted_integrity_protected.js b/src/packet/sym_encrypted_integrity_protected.js index 67e542d0..9fcc58d4 100644 --- a/src/packet/sym_encrypted_integrity_protected.js +++ b/src/packet/sym_encrypted_integrity_protected.js @@ -135,7 +135,7 @@ SymEncryptedIntegrityProtected.prototype.decrypt = async function (sessionKeyAlg if (this.hash !== mdc) { throw new Error('Modification detected.'); } else { - await this.packets.readStream(bytesClone.subarray(0, -2)); + await this.packets.read(bytesClone.subarray(0, -2)); } return true; diff --git a/src/packet/symmetrically_encrypted.js b/src/packet/symmetrically_encrypted.js index f4858d94..2c993d9a 100644 --- a/src/packet/symmetrically_encrypted.js +++ b/src/packet/symmetrically_encrypted.js @@ -81,7 +81,7 @@ SymmetricallyEncrypted.prototype.decrypt = async function (sessionKeyAlgorithm, if (!this.ignore_mdc_error) { throw new Error('Decryption failed due to missing MDC.'); } - this.packets.read(decrypted); + await this.packets.read(decrypted); return true; }; diff --git a/src/signature.js b/src/signature.js index cc72a5e4..473b3490 100644 --- a/src/signature.js +++ b/src/signature.js @@ -53,9 +53,9 @@ Signature.prototype.armor = function() { * @returns {Signature} new signature object * @static */ -export function readArmored(armoredText) { - const input = armor.decode(armoredText).data; - return read(input); +export async function readArmored(armoredText) { + const input = await armor.decode(armoredText); + return read(input.data); } /** @@ -64,8 +64,8 @@ export function readArmored(armoredText) { * @returns {Signature} new signature object * @static */ -export function read(input) { +export async function read(input) { const packetlist = new packet.List(); - packetlist.read(input); + await packetlist.read(input); return new Signature(packetlist); } diff --git a/test/general/armor.js b/test/general/armor.js index 03d814fd..518292ff 100644 --- a/test/general/armor.js +++ b/test/general/armor.js @@ -26,61 +26,61 @@ describe("ASCII armor", function() { ).join('\n'); } - it('Parse cleartext signed message', function () { + it('Parse cleartext signed message', async function () { let msg = getArmor(['Hash: SHA1']); - msg = openpgp.cleartext.readArmored(msg); + msg = await openpgp.cleartext.readArmored(msg); expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); }); - it('Exception if mismatch in armor header and signature', function () { + it('Exception if mismatch in armor header and signature', async function () { let msg = getArmor(['Hash: SHA256']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Hash algorithm mismatch in armor header and signature/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Hash algorithm mismatch in armor header and signature/); }); - it('Exception if no header and non-MD5 signature', function () { + it('Exception if no header and non-MD5 signature', async function () { let msg = getArmor(null); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /If no "Hash" header in cleartext signed message, then only MD5 signatures allowed/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /If no "Hash" header in cleartext signed message, then only MD5 signatures allowed/); }); - it('Exception if unknown hash algorithm', function () { + it('Exception if unknown hash algorithm', async function () { let msg = getArmor(['Hash: LAV750']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Unknown hash algorithm in armor header/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Unknown hash algorithm in armor header/); }); - it('Multiple hash values', function () { + it('Multiple hash values', async function () { let msg = getArmor(['Hash: SHA1, SHA256']); - msg = openpgp.cleartext.readArmored(msg); + msg = await openpgp.cleartext.readArmored(msg); expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); }); - it('Multiple hash header lines', function () { + it('Multiple hash header lines', async function () { let msg = getArmor(['Hash: SHA1', 'Hash: SHA256']); - msg = openpgp.cleartext.readArmored(msg); + msg = await openpgp.cleartext.readArmored(msg); expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); }); - it('Non-hash header line throws exception', function () { + it('Non-hash header line throws exception', async function () { let msg = getArmor(['Hash: SHA1', 'Comment: could be anything']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Only "Hash" header allowed in cleartext signed message/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Only "Hash" header allowed in cleartext signed message/); }); - it('Multiple wrong hash values', function () { + it('Multiple wrong hash values', async function () { let msg = getArmor(['Hash: SHA512, SHA256']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Hash algorithm mismatch in armor header and signature/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Hash algorithm mismatch in armor header and signature/); }); - it('Multiple wrong hash values', function () { + it('Multiple wrong hash values', async function () { let msg = getArmor(['Hash: SHA512, SHA256']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Hash algorithm mismatch in armor header and signature/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Hash algorithm mismatch in armor header and signature/); }); - it('Filter whitespace in blank line', function () { + it('Filter whitespace in blank line', async function () { let msg = ['-----BEGIN PGP SIGNED MESSAGE-----', 'Hash: SHA1', @@ -96,37 +96,37 @@ describe("ASCII armor", function() { '=e/eA', '-----END PGP SIGNATURE-----'].join('\n'); - msg = openpgp.cleartext.readArmored(msg); + msg = await openpgp.cleartext.readArmored(msg); expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); }); - it('Exception if improperly formatted armor header - plaintext section', function () { + it('Exception if improperly formatted armor header - plaintext section', async function () { let msg = getArmor(['Hash:SHA256']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Improperly formatted armor header/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Improperly formatted armor header/); msg = getArmor(['Ha sh: SHA256']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Only "Hash" header allowed in cleartext signed message/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Only "Hash" header allowed in cleartext signed message/); msg = getArmor(['Hash SHA256']); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Improperly formatted armor header/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Improperly formatted armor header/); }); it('Exception if improperly formatted armor header - signature section', function () { [' Space: leading', 'Space : trailing', 'Space :switched', ': empty', 'none', 'Space:missing'].forEach(function (invalidHeader) { - expect(openpgp.cleartext.readArmored.bind(null, getArmor(['Hash: SHA1'], [invalidHeader]))).to.throw(Error, /Improperly formatted armor header/); + expect(openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], [invalidHeader]))).to.be.rejectedWith(Error, /Improperly formatted armor header/); }); }); - it('Ignore unknown armor header - signature section', function () { + 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(openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], validHeaders))).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); - ['A: Hello', 'Ab: 1.2.3', 'Abcd: #!/yah', 'Acd 123 5.6.$.8: Hello', '_: Hello', '*: Hello', '* & ## ?? ()(): Hello', '( ): Weird'].forEach(function (validHeader) { - expect(openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], [validHeader]))).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); + expect(await openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], validHeaders))).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); + ['A: Hello', 'Ab: 1.2.3', 'Abcd: #!/yah', 'Acd 123 5.6.$.8: Hello', '_: Hello', '*: Hello', '* & ## ?? ()(): Hello', '( ): Weird'].forEach(async function (validHeader) { + expect(await openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], [validHeader]))).to.be.an.instanceof(openpgp.cleartext.CleartextMessage); }); }); - it('Exception if wrong armor header type', function () { + it('Exception if wrong armor header type', async function () { let msg = ['-----BEGIN PGP SIGNED MESSAGE\u2010\u2010\u2010\u2010\u2010\nHash:SHA1\n\nIs this properly-----', '', @@ -141,11 +141,11 @@ describe("ASCII armor", function() { '=e/eA', '-----END PGP SIGNNATURE-----'].join('\n'); - msg = openpgp.cleartext.readArmored.bind(null, msg); - expect(msg).to.throw(Error, /Unknown ASCII armor type/); + msg = openpgp.cleartext.readArmored(msg); + await expect(msg).to.be.rejectedWith(Error, /Unknown ASCII armor type/); }); - it('Armor checksum validation - mismatch', function () { + it('Armor checksum validation - mismatch', async function () { const privKey = ['-----BEGIN PGP PRIVATE KEY BLOCK-----', 'Version: OpenPGP.js v0.3.0', @@ -167,13 +167,13 @@ describe("ASCII armor", function() { '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); // try with default config - const result_1 = openpgp.key.readArmored(privKey); + const result_1 = await openpgp.key.readArmored(privKey); expect(result_1.err).to.exist; expect(result_1.err[0].message).to.match(/Ascii armor integrity check on message failed/); // try opposite config openpgp.config.checksum_required = !openpgp.config.checksum_required; - const result_2 = openpgp.key.readArmored(privKey); + const result_2 = await openpgp.key.readArmored(privKey); expect(result_2.err).to.exist; expect(result_2.err[0].message).to.match(/Ascii armor integrity check on message failed/); @@ -181,7 +181,7 @@ describe("ASCII armor", function() { openpgp.config.checksum_required = !openpgp.config.checksum_required; }); - it('Armor checksum validation - valid', function () { + it('Armor checksum validation - valid', async function () { const privKey = ['-----BEGIN PGP PRIVATE KEY BLOCK-----', 'Version: OpenPGP.js v0.3.0', @@ -203,19 +203,19 @@ describe("ASCII armor", function() { '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); // try with default config - const result_1 = openpgp.key.readArmored(privKey); + const result_1 = await openpgp.key.readArmored(privKey); expect(result_1.err).to.not.exist; // try opposite config openpgp.config.checksum_required = !openpgp.config.checksum_required; - const result_2 = openpgp.key.readArmored(privKey); + const result_2 = await openpgp.key.readArmored(privKey); expect(result_2.err).to.not.exist; // back to default openpgp.config.checksum_required = !openpgp.config.checksum_required; }); - it('Armor checksum validation - missing', function () { + it('Armor checksum validation - missing', async function () { const privKeyNoCheckSum = ['-----BEGIN PGP PRIVATE KEY BLOCK-----', 'Version: OpenPGP.js v0.3.0', @@ -236,7 +236,7 @@ describe("ASCII armor", function() { '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); // try with default config - const result_1 = openpgp.key.readArmored(privKeyNoCheckSum); + const result_1 = await openpgp.key.readArmored(privKeyNoCheckSum); if(openpgp.config.checksum_required) { expect(result_1.err).to.exist; expect(result_1.err[0].message).to.match(/Ascii armor integrity check on message failed/); @@ -246,7 +246,7 @@ describe("ASCII armor", function() { // try opposite config openpgp.config.checksum_required = !openpgp.config.checksum_required; - const result_2 = openpgp.key.readArmored(privKeyNoCheckSum); + const result_2 = await openpgp.key.readArmored(privKeyNoCheckSum); if(openpgp.config.checksum_required) { expect(result_2.err).to.exist; expect(result_2.err[0].message).to.match(/Ascii armor integrity check on message failed/); @@ -258,7 +258,7 @@ describe("ASCII armor", function() { openpgp.config.checksum_required = !openpgp.config.checksum_required; }); - it('Armor checksum validation - missing - trailing newline', function () { + it('Armor checksum validation - missing - trailing newline', async function () { const privKeyNoCheckSumWithTrailingNewline = ['-----BEGIN PGP PRIVATE KEY BLOCK-----', 'Version: OpenPGP.js v0.3.0', @@ -280,7 +280,7 @@ describe("ASCII armor", function() { ''].join('\n'); // try with default config - const result_1 = openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline); + const result_1 = await openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline); if(openpgp.config.checksum_required) { expect(result_1.err).to.exist; expect(result_1.err[0].message).to.match(/Ascii armor integrity check on message failed/); @@ -290,7 +290,7 @@ describe("ASCII armor", function() { // try opposite config openpgp.config.checksum_required = !openpgp.config.checksum_required; - const result_2 = openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline); + const result_2 = await openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline); if(openpgp.config.checksum_required) { expect(result_2.err).to.exist; expect(result_2.err[0].message).to.match(/Ascii armor integrity check on message failed/); @@ -302,7 +302,7 @@ describe("ASCII armor", function() { openpgp.config.checksum_required = !openpgp.config.checksum_required; }); - it('Accept header with trailing whitespace', function () { + it('Accept header with trailing whitespace', async function () { const privKey = ['-----BEGIN PGP PRIVATE KEY BLOCK-----\t \r', 'Version: OpenPGP.js v0.3.0', @@ -323,14 +323,14 @@ describe("ASCII armor", function() { '=wJNM', '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); - const result = openpgp.key.readArmored(privKey); + const result = await openpgp.key.readArmored(privKey); expect(result.err).to.not.exist; expect(result.keys[0]).to.be.an.instanceof(openpgp.key.Key); }); - it('Do not filter blank lines after header', function () { + it('Do not filter blank lines after header', async function () { let msg = getArmor(['Hash: SHA1', '']); - msg = openpgp.cleartext.readArmored(msg); + msg = await openpgp.cleartext.readArmored(msg); expect(msg.text).to.equal('\r\nsign this'); }); diff --git a/test/general/brainpool.js b/test/general/brainpool.js index fa088841..d81aee24 100644 --- a/test/general/brainpool.js +++ b/test/general/brainpool.js @@ -127,11 +127,11 @@ describe('Brainpool Cryptography', function () { ].join('\n') } }; - function load_pub_key(name) { + async function load_pub_key(name) { if (data[name].pub_key) { return data[name].pub_key; } - const pub = openpgp.key.readArmored(data[name].pub); + const pub = await openpgp.key.readArmored(data[name].pub); expect(pub).to.exist; expect(pub.err).to.not.exist; expect(pub.keys).to.have.length(1); @@ -143,7 +143,7 @@ describe('Brainpool Cryptography', function () { if (data[name].priv_key) { return data[name].priv_key; } - const pk = openpgp.key.readArmored(data[name].priv); + const pk = await openpgp.key.readArmored(data[name].priv); expect(pk).to.exist; expect(pk.err).to.not.exist; expect(pk.keys).to.have.length(1); @@ -152,19 +152,18 @@ describe('Brainpool Cryptography', function () { data[name].priv_key = pk.keys[0]; return data[name].priv_key; } - it('Load public key', function (done) { - load_pub_key('romeo'); - load_pub_key('juliet'); - done(); + it('Load public key', async function () { + await load_pub_key('romeo'); + await load_pub_key('juliet'); }); it('Load private key', async function () { await load_priv_key('romeo'); await load_priv_key('juliet'); return true; }); - it('Verify clear signed message', function () { - const pub = load_pub_key('juliet'); - const msg = openpgp.cleartext.readArmored(data.juliet.message_signed); + it('Verify clear signed message', async function () { + const pub = await load_pub_key('juliet'); + const msg = await openpgp.cleartext.readArmored(data.juliet.message_signed); return openpgp.verify({publicKeys: [pub], message: msg}).then(function(result) { expect(result).to.exist; expect(result.data).to.equal(data.juliet.message); @@ -175,8 +174,8 @@ describe('Brainpool Cryptography', function () { it('Sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); const signed = await openpgp.sign({privateKeys: [romeoPrivate], data: data.romeo.message}); - const romeoPublic = load_pub_key('romeo'); - const msg = openpgp.cleartext.readArmored(signed.data); + const romeoPublic = await load_pub_key('romeo'); + const msg = await openpgp.cleartext.readArmored(signed.data); const result = await openpgp.verify({publicKeys: [romeoPublic], message: msg}); expect(result).to.exist; @@ -185,9 +184,9 @@ describe('Brainpool Cryptography', function () { expect(result.signatures[0].valid).to.be.true; }); it('Decrypt and verify message', async function () { - const juliet = load_pub_key('juliet'); + const juliet = await load_pub_key('juliet'); const romeo = await load_priv_key('romeo'); - const msg = openpgp.message.readArmored(data.romeo.message_encrypted); + const msg = await openpgp.message.readArmored(data.romeo.message_encrypted); const result = await openpgp.decrypt({privateKeys: romeo, publicKeys: [juliet], message: msg}); expect(result).to.exist; @@ -197,11 +196,11 @@ describe('Brainpool Cryptography', function () { }); it('Encrypt and sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); - const julietPublic = load_pub_key('juliet'); + const julietPublic = await load_pub_key('juliet'); const encrypted = await openpgp.encrypt({publicKeys: [julietPublic], privateKeys: [romeoPrivate], data: data.romeo.message}); - const message = openpgp.message.readArmored(encrypted.data); - const romeoPublic = load_pub_key('romeo'); + const message = await openpgp.message.readArmored(encrypted.data); + const romeoPublic = await load_pub_key('romeo'); const julietPrivate = await load_priv_key('juliet'); const result = await openpgp.decrypt({privateKeys: julietPrivate, publicKeys: [romeoPublic], message: message}); @@ -229,8 +228,8 @@ describe('Brainpool Cryptography', function () { // Signing message openpgp.sign( { data: testData, privateKeys: hi } - ).then(signed => { - const msg = openpgp.cleartext.readArmored(signed.data); + ).then(async signed => { + const msg = await openpgp.cleartext.readArmored(signed.data); // Verifying signed message return Promise.all([ openpgp.verify( @@ -240,7 +239,7 @@ describe('Brainpool Cryptography', function () { openpgp.verify( { message: openpgp.message.fromText(testData), publicKeys: pubHi, - signature: openpgp.signature.readArmored(signed.data) } + signature: await openpgp.signature.readArmored(signed.data) } ).then(output => expect(output.signatures[0].valid).to.be.true) ]); }), @@ -249,8 +248,8 @@ describe('Brainpool Cryptography', function () { { data: testData2, publicKeys: [pubBye], privateKeys: [hi] } - ).then(encrypted => { - const msg = openpgp.message.readArmored(encrypted.data); + ).then(async encrypted => { + const msg = await openpgp.message.readArmored(encrypted.data); // Decrypting and verifying return openpgp.decrypt( { message: msg, diff --git a/test/general/decompression.js b/test/general/decompression.js index afbc642a..af0ce61f 100644 --- a/test/general/decompression.js +++ b/test/general/decompression.js @@ -43,8 +43,8 @@ Xg== describe('Decrypt and decompress message tests', function () { function runTest(key, test) { - it(`Decrypts message compressed with ${key}`, function () { - const message = openpgp.message.readArmored(test.input); + it(`Decrypts message compressed with ${key}`, async function () { + const message = await openpgp.message.readArmored(test.input); const options = { passwords: password, message diff --git a/test/general/ecc_nist.js b/test/general/ecc_nist.js index b83e6527..4e65ddc5 100644 --- a/test/general/ecc_nist.js +++ b/test/general/ecc_nist.js @@ -133,11 +133,11 @@ describe('Elliptic Curve Cryptography', function () { ].join('\n') } }; - function load_pub_key(name) { + async function load_pub_key(name) { if (data[name].pub_key) { return data[name].pub_key; } - const pub = openpgp.key.readArmored(data[name].pub); + const pub = await openpgp.key.readArmored(data[name].pub); expect(pub).to.exist; expect(pub.err).to.not.exist; expect(pub.keys).to.have.length(1); @@ -149,7 +149,7 @@ describe('Elliptic Curve Cryptography', function () { if (data[name].priv_key) { return data[name].priv_key; } - const pk = openpgp.key.readArmored(data[name].priv); + const pk = await openpgp.key.readArmored(data[name].priv); expect(pk).to.exist; expect(pk.err).to.not.exist; expect(pk.keys).to.have.length(1); @@ -158,25 +158,24 @@ describe('Elliptic Curve Cryptography', function () { data[name].priv_key = pk.keys[0]; return data[name].priv_key; } - it('Load public key', function (done) { - const romeoPublic = load_pub_key('romeo'); + it('Load public key', async function () { + const romeoPublic = await load_pub_key('romeo'); expect(romeoPublic.users[0].userId.name).to.equal('Romeo Montague'); expect(romeoPublic.users[0].userId.email).to.equal('romeo@example.net'); expect(romeoPublic.users[0].userId.comment).to.equal('secp256k1'); - const julietPublic = load_pub_key('juliet'); + const julietPublic = await load_pub_key('juliet'); expect(julietPublic.users[0].userId.name).to.equal('Juliet Capulet'); expect(julietPublic.users[0].userId.email).to.equal('juliet@example.net'); expect(julietPublic.users[0].userId.comment).to.equal('secp256k1'); - done(); }); it('Load private key', async function () { await load_priv_key('romeo'); await load_priv_key('juliet'); return true; }); - it('Verify clear signed message', function () { - const pub = load_pub_key('juliet'); - const msg = openpgp.cleartext.readArmored(data.juliet.message_signed); + it('Verify clear signed message', async function () { + const pub = await load_pub_key('juliet'); + const msg = await openpgp.cleartext.readArmored(data.juliet.message_signed); return openpgp.verify({publicKeys: [pub], message: msg}).then(function(result) { expect(result).to.exist; expect(result.data).to.equal(data.juliet.message); @@ -187,8 +186,8 @@ describe('Elliptic Curve Cryptography', function () { it('Sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); const signed = await openpgp.sign({privateKeys: [romeoPrivate], data: data.romeo.message}); - const romeoPublic = load_pub_key('romeo'); - const msg = openpgp.cleartext.readArmored(signed.data); + const romeoPublic = await load_pub_key('romeo'); + const msg = await openpgp.cleartext.readArmored(signed.data); const result = await openpgp.verify({publicKeys: [romeoPublic], message: msg}); expect(result).to.exist; @@ -197,9 +196,9 @@ describe('Elliptic Curve Cryptography', function () { expect(result.signatures[0].valid).to.be.true; }); it('Decrypt and verify message', async function () { - const juliet = load_pub_key('juliet'); + const juliet = await load_pub_key('juliet'); const romeo = await load_priv_key('romeo'); - const msg = openpgp.message.readArmored(data.juliet.message_encrypted); + const msg = await openpgp.message.readArmored(data.juliet.message_encrypted); const result = await openpgp.decrypt({privateKeys: romeo, publicKeys: [juliet], message: msg}); expect(result).to.exist; @@ -209,11 +208,11 @@ describe('Elliptic Curve Cryptography', function () { }); it('Encrypt and sign message', async function () { const romeoPrivate = await load_priv_key('romeo'); - const julietPublic = load_pub_key('juliet'); + const julietPublic = await load_pub_key('juliet'); const encrypted = await openpgp.encrypt({publicKeys: [julietPublic], privateKeys: [romeoPrivate], data: data.romeo.message}); - const message = openpgp.message.readArmored(encrypted.data); - const romeoPublic = load_pub_key('romeo'); + const message = await openpgp.message.readArmored(encrypted.data); + const romeoPublic = await load_pub_key('romeo'); const julietPrivate = await load_priv_key('juliet'); const result = await openpgp.decrypt({privateKeys: julietPrivate, publicKeys: [romeoPublic], message: message}); @@ -256,8 +255,8 @@ describe('Elliptic Curve Cryptography', function () { openpgp.sign( { data: testData, privateKeys: hi } - ).then(signed => { - const msg = openpgp.cleartext.readArmored(signed.data); + ).then(async signed => { + const msg = await openpgp.cleartext.readArmored(signed.data); // Verifying signed message return Promise.all([ openpgp.verify( @@ -267,7 +266,7 @@ describe('Elliptic Curve Cryptography', function () { openpgp.verify( { message: openpgp.message.fromText(testData), publicKeys: pubHi, - signature: openpgp.signature.readArmored(signed.data) } + signature: await openpgp.signature.readArmored(signed.data) } ).then(output => expect(output.signatures[0].valid).to.be.true) ]); }), @@ -276,8 +275,8 @@ describe('Elliptic Curve Cryptography', function () { { data: testData2, publicKeys: [pubBye], privateKeys: [hi] } - ).then(encrypted => { - const msg = openpgp.message.readArmored(encrypted.data); + ).then(async encrypted => { + const msg = await openpgp.message.readArmored(encrypted.data); // Decrypting and verifying return openpgp.decrypt( { message: msg, diff --git a/test/general/key.js b/test/general/key.js index 5e412006..88b7e97f 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -860,14 +860,13 @@ zoGJ6s48HcP591pN93uAitCcYcinY2ZslmdiCXw+zbeoX4spNrV4T4CYxBjNQdIa '-----END PGP PRIVATE 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', async function() { openpgp.config.tolerant = true; - const pubKeys = openpgp.key.readArmored(rsa_ecc_pub); + const pubKeys = await openpgp.key.readArmored(rsa_ecc_pub); expect(pubKeys).to.exist; expect(pubKeys.err).to.not.exist; expect(pubKeys.keys).to.have.length(1); expect(pubKeys.keys[0].getKeyId().toHex()).to.equal('b8e4105cc9dedc77'); - done(); }); const multi_uid_key = @@ -1305,17 +1304,16 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= -----END PGP PRIVATE KEY BLOCK-----`; - it('Parsing armored text with two keys', function(done) { - const pubKeys = openpgp.key.readArmored(twoKeys); + it('Parsing armored text with two keys', async function() { + const pubKeys = await openpgp.key.readArmored(twoKeys); expect(pubKeys).to.exist; expect(pubKeys.err).to.not.exist; expect(pubKeys.keys).to.have.length(2); expect(pubKeys.keys[0].getKeyId().toHex()).to.equal('4a63613a4d6e4094'); expect(pubKeys.keys[1].getKeyId().toHex()).to.equal('dbf223e870534df4'); - done(); }); - it('Parsing V5 public key packet', function() { + it('Parsing V5 public key packet', async function() { // Manually modified from https://gitlab.com/openpgp-wg/rfc4880bis/blob/00b2092/back.mkd#sample-eddsa-key let packetBytes = openpgp.util.hex_to_Uint8Array(` 98 37 05 53 f3 5f 0b 16 00 00 00 2d 09 2b 06 01 04 01 da 47 @@ -1325,13 +1323,13 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= `.replace(/\s+/g, '')); let packetlist = new openpgp.packet.List(); - packetlist.read(packetBytes); + await packetlist.read(packetBytes); let key = packetlist[0]; expect(key).to.exist; }); - it('Testing key ID and fingerprint for V3 and V4 keys', function(done) { - const pubKeysV4 = openpgp.key.readArmored(twoKeys); + it('Testing key ID and fingerprint for V3 and V4 keys', async function() { + const pubKeysV4 = await openpgp.key.readArmored(twoKeys); expect(pubKeysV4).to.exist; expect(pubKeysV4.err).to.not.exist; expect(pubKeysV4.keys).to.have.length(2); @@ -1339,7 +1337,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= const pubKeyV4 = pubKeysV4.keys[0]; expect(pubKeyV4).to.exist; - const pubKeysV3 = openpgp.key.readArmored(pub_v3); + const pubKeysV3 = await openpgp.key.readArmored(pub_v3); expect(pubKeysV3).to.exist; expect(pubKeysV3.err).to.not.exist; @@ -1352,18 +1350,17 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= expect(pubKeyV4.getFingerprint()).to.equal('f470e50dcb1ad5f1e64e08644a63613a4d6e4094'); expect(pubKeyV3.getKeyId().toHex()).to.equal('e5b7a014a237ba9d'); expect(pubKeyV3.getFingerprint()).to.equal('a44fcee620436a443bc4913640ab3e49'); - done(); }); - it('Create new key ID with fromId()', function() { - const pubKeyV4 = openpgp.key.readArmored(twoKeys).keys[0]; + it('Create new key ID with fromId()', async function() { + const pubKeyV4 = (await openpgp.key.readArmored(twoKeys)).keys[0]; const keyId = pubKeyV4.getKeyId(); const newKeyId = keyId.constructor.fromId(keyId.toHex()); expect(newKeyId.toHex()).to.equal(keyId.toHex()); }); - it('Testing key method getSubkeys', function(done) { - const pubKeys = openpgp.key.readArmored(pub_sig_test); + it('Testing key method getSubkeys', async function() { + const pubKeys = await openpgp.key.readArmored(pub_sig_test); expect(pubKeys).to.exist; expect(pubKeys.err).to.not.exist; @@ -1374,23 +1371,22 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= const packetlist = new openpgp.packet.List(); - packetlist.read(openpgp.armor.decode(pub_sig_test).data); + await packetlist.read((await openpgp.armor.decode(pub_sig_test)).data); const subkeys = pubKey.getSubkeys(); expect(subkeys).to.exist; expect(subkeys).to.have.length(2); expect(subkeys[0].getKeyId().equals(packetlist[8].getKeyId())).to.be.true; expect(subkeys[1].getKeyId().equals(packetlist[11].getKeyId())).to.be.true; - done(); }); - it('Verify status of revoked primary key', function(done) { - const pubKey = openpgp.key.readArmored(pub_revoked_subkeys).keys[0]; - expect(pubKey.verifyPrimaryKey()).to.eventually.equal(openpgp.enums.keyStatus.revoked).notify(done); + it('Verify status of revoked primary key', async function() { + const pubKey = (await openpgp.key.readArmored(pub_revoked_subkeys)).keys[0]; + expect(pubKey.verifyPrimaryKey()).to.eventually.equal(openpgp.enums.keyStatus.revoked); }); - it('Verify status of revoked subkey', function(done) { - const pubKeys = openpgp.key.readArmored(pub_sig_test); + it('Verify status of revoked subkey', async function() { + const pubKeys = await openpgp.key.readArmored(pub_sig_test); expect(pubKeys).to.exist; expect(pubKeys.err).to.not.exist; expect(pubKeys.keys).to.have.length(1); @@ -1400,13 +1396,13 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= expect(pubKey.subKeys).to.exist; expect(pubKey.subKeys).to.have.length(2); - expect(pubKey.subKeys[0].verify( + await expect(pubKey.subKeys[0].verify( pubKey.primaryKey - )).to.eventually.equal(openpgp.enums.keyStatus.revoked).notify(done); + )).to.eventually.equal(openpgp.enums.keyStatus.revoked); }); it('Evaluate key flags to find valid encryption key packet', async function() { - const pubKeys = openpgp.key.readArmored(pub_sig_test); + const pubKeys = await openpgp.key.readArmored(pub_sig_test); expect(pubKeys).to.exist; expect(pubKeys.err).to.not.exist; expect(pubKeys.keys).to.have.length(1); @@ -1420,7 +1416,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it('Method getExpirationTime V4 Key', async function() { - const pubKey = openpgp.key.readArmored(twoKeys).keys[1]; + const pubKey = (await openpgp.key.readArmored(twoKeys)).keys[1]; expect(pubKey).to.exist; expect(pubKey).to.be.an.instanceof(openpgp.key.Key); const expirationTime = await pubKey.getExpirationTime(); @@ -1428,7 +1424,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it('Method getExpirationTime expired V4 Key', async function() { - const pubKey = openpgp.key.readArmored(expiredKey).keys[0]; + const pubKey = (await openpgp.key.readArmored(expiredKey)).keys[0]; expect(pubKey).to.exist; expect(pubKey).to.be.an.instanceof(openpgp.key.Key); const expirationTime = await pubKey.getExpirationTime(); @@ -1436,7 +1432,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it('Method getExpirationTime V4 SubKey', async function() { - const pubKey = openpgp.key.readArmored(twoKeys).keys[1]; + const pubKey = (await openpgp.key.readArmored(twoKeys)).keys[1]; expect(pubKey).to.exist; expect(pubKey).to.be.an.instanceof(openpgp.key.Key); const expirationTime = await pubKey.subKeys[0].getExpirationTime(); @@ -1444,7 +1440,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it('Method getExpirationTime V4 Key with capabilities', async function() { - const pubKey = openpgp.key.readArmored(priv_key_2000_2008).keys[0]; + const pubKey = (await openpgp.key.readArmored(priv_key_2000_2008)).keys[0]; expect(pubKey).to.exist; expect(pubKey).to.be.an.instanceof(openpgp.key.Key); const expirationTime = await pubKey.getExpirationTime(); @@ -1453,27 +1449,26 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= expect(encryptExpirationTime.toISOString()).to.equal('2008-02-12T17:12:08.000Z'); }); - it('update() - throw error if fingerprints not equal', function(done) { - const keys = openpgp.key.readArmored(twoKeys).keys; - expect(keys[0].update.bind( + it('update() - throw error if fingerprints not equal', async function() { + const keys = (await openpgp.key.readArmored(twoKeys)).keys; + await expect(keys[0].update.bind( keys[0], keys[1] - )()).to.be.rejectedWith('Key update method: fingerprints of keys not equal').notify(done); + )()).to.be.rejectedWith('Key update method: fingerprints of keys not equal'); }); - it('update() - merge revocation signatures', function(done) { - const source = openpgp.key.readArmored(pub_revoked_subkeys).keys[0]; - const dest = openpgp.key.readArmored(pub_revoked_subkeys).keys[0]; + it('update() - merge revocation signatures', async function() { + const source = (await openpgp.key.readArmored(pub_revoked_subkeys)).keys[0]; + const dest = (await openpgp.key.readArmored(pub_revoked_subkeys)).keys[0]; expect(source.revocationSignatures).to.exist; dest.revocationSignatures = []; - dest.update(source).then(() => { + return dest.update(source).then(() => { expect(dest.revocationSignatures[0]).to.exist.and.be.an.instanceof(openpgp.packet.Signature); - done(); }); }); - it('update() - merge user', function() { - const source = openpgp.key.readArmored(pub_sig_test).keys[0]; - const dest = openpgp.key.readArmored(pub_sig_test).keys[0]; + it('update() - merge user', async function() { + const source = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; + const dest = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; expect(source.users[1]).to.exist; dest.users.pop(); return dest.update(source).then(() => { @@ -1482,39 +1477,37 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); }); - it('update() - merge user - other and certification revocation signatures', function(done) { - const source = openpgp.key.readArmored(pub_sig_test).keys[0]; - const dest = openpgp.key.readArmored(pub_sig_test).keys[0]; + it('update() - merge user - other and certification revocation signatures', async function() { + const source = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; + const dest = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; expect(source.users[1].otherCertifications).to.exist; expect(source.users[1].revocationSignatures).to.exist; dest.users[1].otherCertifications = []; dest.users[1].revocationSignatures.pop(); - dest.update(source).then(() => { + return dest.update(source).then(() => { expect(dest.users[1].otherCertifications).to.exist.and.to.have.length(1); expect(dest.users[1].otherCertifications[0].signature).to.equal(source.users[1].otherCertifications[0].signature); expect(dest.users[1].revocationSignatures).to.exist.and.to.have.length(2); expect(dest.users[1].revocationSignatures[1].signature).to.equal(source.users[1].revocationSignatures[1].signature); - done(); }); }); - it('update() - merge subkey', function(done) { - const source = openpgp.key.readArmored(pub_sig_test).keys[0]; - const dest = openpgp.key.readArmored(pub_sig_test).keys[0]; + it('update() - merge subkey', async function() { + const source = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; + const dest = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; expect(source.subKeys[1]).to.exist; dest.subKeys.pop(); - dest.update(source).then(() => { + return dest.update(source).then(() => { expect(dest.subKeys[1]).to.exist; expect( dest.subKeys[1].getKeyId().toHex() ).to.equal(source.subKeys[1].getKeyId().toHex()); - done(); }); }); - it('update() - merge subkey - revocation signature', function() { - const source = openpgp.key.readArmored(pub_sig_test).keys[0]; - const dest = openpgp.key.readArmored(pub_sig_test).keys[0]; + it('update() - merge subkey - revocation signature', async function() { + const source = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; + const dest = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; expect(source.subKeys[0].revocationSignatures).to.exist; dest.subKeys[0].revocationSignatures = []; return dest.update(source).then(() => { @@ -1523,9 +1516,9 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); }); - it('update() - merge private key into public key', function() { - const source = openpgp.key.readArmored(priv_key_rsa).keys[0]; - const dest = openpgp.key.readArmored(twoKeys).keys[0]; + it('update() - merge private key into public key', async function() { + const source = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; + const dest = (await openpgp.key.readArmored(twoKeys)).keys[0]; expect(dest.isPublic()).to.be.true; return dest.update(source).then(() => { expect(dest.isPrivate()).to.be.true; @@ -1543,9 +1536,9 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); }); - it('update() - merge private key into public key - no subkeys', function() { - const source = openpgp.key.readArmored(priv_key_rsa).keys[0]; - const dest = openpgp.key.readArmored(twoKeys).keys[0]; + it('update() - merge private key into public key - no subkeys', async function() { + const source = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; + const dest = (await openpgp.key.readArmored(twoKeys)).keys[0]; source.subKeys = []; dest.subKeys = []; expect(dest.isPublic()).to.be.true; @@ -1562,19 +1555,19 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); }); - it('update() - merge private key into public key - mismatch throws error', function(done) { - const source = openpgp.key.readArmored(priv_key_rsa).keys[0]; - const dest = openpgp.key.readArmored(twoKeys).keys[0]; + it('update() - merge private key into public key - mismatch throws error', async function() { + const source = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; + const dest = (await openpgp.key.readArmored(twoKeys)).keys[0]; source.subKeys = []; expect(dest.subKeys).to.exist; expect(dest.isPublic()).to.be.true; - expect(dest.update.bind(dest, source)()) - .to.be.rejectedWith('Cannot update public key with private key if subkey mismatch').notify(done); + await expect(dest.update.bind(dest, source)()) + .to.be.rejectedWith('Cannot update public key with private key if subkey mismatch'); }); it('update() - merge subkey binding signatures', async function() { - const source = openpgp.key.readArmored(pgp_desktop_pub).keys[0]; - const dest = openpgp.key.readArmored(pgp_desktop_priv).keys[0]; + const source = (await openpgp.key.readArmored(pgp_desktop_pub)).keys[0]; + const dest = (await openpgp.key.readArmored(pgp_desktop_priv)).keys[0]; expect(source.subKeys[0].bindingSignatures[0]).to.exist; await expect(source.subKeys[0].verify(source.primaryKey)) .to.eventually.equal(openpgp.enums.keyStatus.valid); @@ -1587,7 +1580,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it('revoke() - primary key', async function() { - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); await privKey.revoke({ @@ -1605,8 +1598,8 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it('revoke() - subkey', async function() { - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); const subKey = pubKey.subKeys[0]; @@ -1623,28 +1616,28 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); }); - it('applyRevocationCertificate() should produce the same revoked key as GnuPG', function() { - const pubKey = openpgp.key.readArmored(pub_key_arm4).keys[0]; + it('applyRevocationCertificate() should produce the same revoked key as GnuPG', async function() { + const pubKey = (await openpgp.key.readArmored(pub_key_arm4)).keys[0]; - return pubKey.applyRevocationCertificate(revocation_certificate_arm4).then(revKey => { - expect(revKey.armor()).to.equal(openpgp.key.readArmored(revoked_key_arm4).keys[0].armor()); + return pubKey.applyRevocationCertificate(revocation_certificate_arm4).then(async revKey => { + expect(revKey.armor()).to.equal((await openpgp.key.readArmored(revoked_key_arm4)).keys[0].armor()); }); }); - it('getRevocationCertificate() should produce the same revocation certificate as GnuPG', function() { - const revKey = openpgp.key.readArmored(revoked_key_arm4).keys[0]; + it('getRevocationCertificate() should produce the same revocation certificate as GnuPG', async function() { + const revKey = (await openpgp.key.readArmored(revoked_key_arm4)).keys[0]; const revocationCertificate = revKey.getRevocationCertificate(); - const input = openpgp.armor.decode(revocation_certificate_arm4); + const input = await openpgp.armor.decode(revocation_certificate_arm4); const packetlist = new openpgp.packet.List(); - packetlist.read(input.data); + await packetlist.read(input.data); const armored = openpgp.armor.encode(openpgp.enums.armor.public_key, packetlist.write()); expect(revocationCertificate.replace(/^Comment: .*$\r\n/mg, '')).to.equal(armored.replace(/^Comment: .*$\r\n/mg, '')); }); - it('getRevocationCertificate() should have an appropriate comment', function() { - const revKey = openpgp.key.readArmored(revoked_key_arm4).keys[0]; + it('getRevocationCertificate() should have an appropriate comment', async function() { + const revKey = (await openpgp.key.readArmored(revoked_key_arm4)).keys[0]; const revocationCertificate = revKey.getRevocationCertificate(); expect(revocationCertificate).to.match(/Comment: This is a revocation certificate/); @@ -1652,13 +1645,13 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it("getPreferredAlgo('symmetric') - one key - AES256", async function() { - const key1 = openpgp.key.readArmored(twoKeys).keys[0]; + const key1 = (await openpgp.key.readArmored(twoKeys)).keys[0]; const prefAlgo = await openpgp.key.getPreferredAlgo('symmetric', [key1]); expect(prefAlgo).to.equal(openpgp.enums.symmetric.aes256); }); it("getPreferredAlgo('symmetric') - two key - AES128", async function() { - const keys = openpgp.key.readArmored(twoKeys).keys; + const keys = (await openpgp.key.readArmored(twoKeys)).keys; const key1 = keys[0]; const key2 = keys[1]; const primaryUser = await key2.getPrimaryUser(); @@ -1668,7 +1661,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it("getPreferredAlgo('symmetric') - two key - one without pref", async function() { - const keys = openpgp.key.readArmored(twoKeys).keys; + const keys = (await openpgp.key.readArmored(twoKeys)).keys; const key1 = keys[0]; const key2 = keys[1]; const primaryUser = await key2.getPrimaryUser(); @@ -1678,7 +1671,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it("getPreferredAlgo('aead') - one key - OCB", async function() { - const key1 = openpgp.key.readArmored(twoKeys).keys[0]; + const key1 = (await openpgp.key.readArmored(twoKeys)).keys[0]; const primaryUser = await key1.getPrimaryUser(); primaryUser.selfCertification.features = [7]; // Monkey-patch AEAD feature flag primaryUser.selfCertification.preferredAeadAlgorithms = [2,1]; @@ -1689,7 +1682,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it("getPreferredAlgo('aead') - two key - one without pref", async function() { - const keys = openpgp.key.readArmored(twoKeys).keys; + const keys = (await openpgp.key.readArmored(twoKeys)).keys; const key1 = keys[0]; const key2 = keys[1]; const primaryUser = await key1.getPrimaryUser(); @@ -1704,7 +1697,7 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= }); it("getPreferredAlgo('aead') - two key - one with no support", async function() { - const keys = openpgp.key.readArmored(twoKeys).keys; + const keys = (await openpgp.key.readArmored(twoKeys)).keys; const key1 = keys[0]; const key2 = keys[1]; const primaryUser = await key1.getPrimaryUser(); @@ -1740,18 +1733,18 @@ t/ia1kMpSEiOVLlX5dfHZzhR3WNtBqU= if (openpgp.util.getWebCryptoAll()) { opt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys return openpgp.generateKey(opt).then(function(key) { testPref(key.key); - testPref(openpgp.key.readArmored(key.publicKeyArmored).keys[0]); + testPref((await openpgp.key.readArmored(key.publicKeyArmored)).keys[0]); }); }); - it('User attribute packet read & write', function() { - const key = openpgp.key.readArmored(user_attr_key).keys[0]; - const key2 = openpgp.key.readArmored(key.armor()).keys[0]; + it('User attribute packet read & write', async function() { + const key = (await openpgp.key.readArmored(user_attr_key)).keys[0]; + const key2 = (await openpgp.key.readArmored(key.armor())).keys[0]; expect(key.users[1].userAttribute).eql(key2.users[1].userAttribute); }); it('getPrimaryUser()', async function() { - const key = openpgp.key.readArmored(pub_sig_test).keys[0]; + const key = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; const primUser = await key.getPrimaryUser(); expect(primUser).to.exist; expect(primUser.user.userId.userid).to.equal('Signature Test '); @@ -1774,7 +1767,7 @@ Vz/bMCJoAShgybW1r6kRWejybzIjFSLnx/YA/iLZeo5UNdlXRJco+15RbFiNSAbw VYGdb3eNlV8CfoEC =FYbP -----END PGP PRIVATE KEY BLOCK-----`; - const key = openpgp.key.readArmored(keyWithoutUserID).keys[0]; + const key = (await openpgp.key.readArmored(keyWithoutUserID)).keys[0]; const primUser = await key.getPrimaryUser(); expect(primUser).to.be.null; }); @@ -1922,8 +1915,8 @@ VYGdb3eNlV8CfoEC }); it('Sign and verify key - primary user', async function() { - let publicKey = openpgp.key.readArmored(pub_sig_test).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; + let publicKey = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; await privateKey.decrypt('hello world'); publicKey = await publicKey.signPrimaryUser([privateKey]); const signatures = await publicKey.verifyPrimaryUser([privateKey]); @@ -1937,9 +1930,9 @@ VYGdb3eNlV8CfoEC }); it('Sign key and verify with wrong key - primary user', async function() { - let publicKey = openpgp.key.readArmored(pub_sig_test).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; - const wrongKey = openpgp.key.readArmored(wrong_key).keys[0]; + let publicKey = (await openpgp.key.readArmored(pub_sig_test)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; + const wrongKey = (await openpgp.key.readArmored(wrong_key)).keys[0]; await privateKey.decrypt('hello world'); publicKey = await publicKey.signPrimaryUser([privateKey]); const signatures = await publicKey.verifyPrimaryUser([wrongKey]); @@ -1953,8 +1946,8 @@ VYGdb3eNlV8CfoEC }); it('Sign and verify key - all users', async function() { - let publicKey = openpgp.key.readArmored(multi_uid_key).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; + let publicKey = (await openpgp.key.readArmored(multi_uid_key)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; await privateKey.decrypt('hello world'); publicKey = await publicKey.signAllUsers([privateKey]); const signatures = await publicKey.verifyAllUsers([privateKey]); @@ -1976,9 +1969,9 @@ VYGdb3eNlV8CfoEC }); it('Sign key and verify with wrong key - all users', async function() { - let publicKey = openpgp.key.readArmored(multi_uid_key).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; - const wrongKey = openpgp.key.readArmored(wrong_key).keys[0]; + let publicKey = (await openpgp.key.readArmored(multi_uid_key)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; + const wrongKey = (await openpgp.key.readArmored(wrong_key)).keys[0]; await privateKey.decrypt('hello world'); publicKey = await publicKey.signAllUsers([privateKey]); const signatures = await publicKey.verifyAllUsers([wrongKey]); @@ -2000,8 +1993,8 @@ VYGdb3eNlV8CfoEC }); it('Encrypt - latest created user', async function() { - let publicKey = openpgp.key.readArmored(multi_uid_key).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; + let publicKey = (await openpgp.key.readArmored(multi_uid_key)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; await privateKey.decrypt('hello world'); // Set second user to prefer aes128. We should select this user by default, since it was created later. publicKey.users[1].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128]; @@ -2010,8 +2003,8 @@ VYGdb3eNlV8CfoEC }); it('Encrypt - primary user', async function() { - let publicKey = openpgp.key.readArmored(multi_uid_key).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; + let publicKey = (await openpgp.key.readArmored(multi_uid_key)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; await privateKey.decrypt('hello world'); // Set first user to primary. We should select this user by default. publicKey.users[0].selfCertifications[0].isPrimaryUserID = true; @@ -2022,8 +2015,8 @@ VYGdb3eNlV8CfoEC }); it('Encrypt - specific user', async function() { - let publicKey = openpgp.key.readArmored(multi_uid_key).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; + let publicKey = (await openpgp.key.readArmored(multi_uid_key)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; await privateKey.decrypt('hello world'); // Set first user to primary. We won't select this user, this is to test that. publicKey.users[0].selfCertifications[0].isPrimaryUserID = true; @@ -2035,10 +2028,10 @@ VYGdb3eNlV8CfoEC }); it('Sign - specific user', async function() { - let publicKey = openpgp.key.readArmored(multi_uid_key).keys[0]; - const privateKey = openpgp.key.readArmored(priv_key_rsa).keys[0]; + let publicKey = (await openpgp.key.readArmored(multi_uid_key)).keys[0]; + const privateKey = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; await privateKey.decrypt('hello world'); - const privateKeyClone = openpgp.key.readArmored(priv_key_rsa).keys[0]; + const privateKeyClone = (await openpgp.key.readArmored(priv_key_rsa)).keys[0]; // Duplicate user privateKey.users.push(privateKeyClone.users[0]); // Set first user to primary. We won't select this user, this is to test that. @@ -2075,9 +2068,9 @@ VYGdb3eNlV8CfoEC }); }); - it('Reformat key with no subkey with passphrase', function() { + it('Reformat key with no subkey with passphrase', async function() { const userId = 'test1 '; - const keys = openpgp.key.readArmored(key_without_subkey).keys; + const keys = (await openpgp.key.readArmored(key_without_subkey)).keys; const opt = {privateKey: keys[0], userIds: [userId], passphrase: "test"}; return openpgp.reformatKey(opt).then(function(newKey) { newKey = newKey.key; @@ -2109,18 +2102,18 @@ VYGdb3eNlV8CfoEC }); }); - it('Reformat key with no subkey without passphrase', function() { + it('Reformat key with no subkey without passphrase', async function() { const userId = 'test1 '; - const keys = openpgp.key.readArmored(key_without_subkey).keys; + const keys = (await openpgp.key.readArmored(key_without_subkey)).keys; const opt = {privateKey: keys[0], userIds: [userId]}; return openpgp.reformatKey(opt).then(function(newKey) { newKey = newKey.key; expect(newKey.users.length).to.equal(1); expect(newKey.users[0].userId.userid).to.equal(userId); expect(newKey.isDecrypted()).to.be.true; - return openpgp.sign({data: 'hello', privateKeys: newKey, armor: true}).then(function(signed) { + return openpgp.sign({data: 'hello', privateKeys: newKey, armor: true}).then(async function(signed) { return openpgp.verify( - {message: openpgp.cleartext.readArmored(signed.data), publicKeys: newKey.toPublic()} + {message: await openpgp.cleartext.readArmored(signed.data), publicKeys: newKey.toPublic()} ).then(async function(verified) { expect(verified.signatures[0].valid).to.be.true; const newSigningKey = await newKey.getSigningKey(); @@ -2164,8 +2157,8 @@ VYGdb3eNlV8CfoEC opt.userIds = userId2; return openpgp.reformatKey(opt).then(function(newKey) { newKey = newKey.key; - return openpgp.encrypt({data: 'hello', publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true}).then(function(encrypted) { - return openpgp.decrypt({message: openpgp.message.readArmored(encrypted.data), privateKeys: newKey, publicKeys: newKey.toPublic()}).then(function(decrypted) { + return openpgp.encrypt({data: 'hello', publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true}).then(async function(encrypted) { + return openpgp.decrypt({message: await openpgp.message.readArmored(encrypted.data), privateKeys: newKey, publicKeys: newKey.toPublic()}).then(function(decrypted) { expect(decrypted.data).to.equal('hello'); expect(decrypted.signatures[0].valid).to.be.true; }); @@ -2187,17 +2180,17 @@ VYGdb3eNlV8CfoEC }); it('Find a valid subkey binding signature among many invalid ones', async function() { - const key = openpgp.key.readArmored(valid_binding_sig_among_many_expired_sigs_pub).keys[0]; + const key = (await openpgp.key.readArmored(valid_binding_sig_among_many_expired_sigs_pub)).keys[0]; expect(await key.getEncryptionKey()).to.not.be.null; }); it('Selects the most recent subkey binding signature', async function() { - const key = openpgp.key.readArmored(multipleBindingSignatures).keys[0]; + const key = (await openpgp.key.readArmored(multipleBindingSignatures)).keys[0]; expect(key.subKeys[0].getExpirationTime().toISOString()).to.equal('2015-10-18T07:41:30.000Z'); }); - it('Reject encryption with revoked subkey', function() { - const key = openpgp.key.readArmored(pub_revoked_subkeys).keys[0]; + it('Reject encryption with revoked subkey', async function() { + const key = (await openpgp.key.readArmored(pub_revoked_subkeys)).keys[0]; return openpgp.encrypt({publicKeys: [key], data: 'random data'}).then(() => { throw new Error('encryptSessionKey should not encrypt with revoked public key'); }).catch(function(error) { @@ -2205,8 +2198,8 @@ VYGdb3eNlV8CfoEC }); }); - it('Reject encryption with key revoked with appended revocation cert', function() { - const key = openpgp.key.readArmored(pub_revoked_with_cert).keys[0]; + it('Reject encryption with key revoked with appended revocation cert', async function() { + const key = (await openpgp.key.readArmored(pub_revoked_with_cert)).keys[0]; return openpgp.encrypt({publicKeys: [key], data: 'random data'}).then(() => { throw new Error('encryptSessionKey should not encrypt with revoked public key'); }).catch(function(error) { @@ -2245,18 +2238,17 @@ VYGdb3eNlV8CfoEC }); }); - it('Merge key with another key with non-ID user attributes', function(done) { - const key = openpgp.key.readArmored(mergeKey1).keys[0]; - const updateKey = openpgp.key.readArmored(mergeKey2).keys[0]; + it('Merge key with another key with non-ID user attributes', async function() { + const key = (await openpgp.key.readArmored(mergeKey1)).keys[0]; + const updateKey = (await openpgp.key.readArmored(mergeKey2)).keys[0]; expect(key).to.exist; expect(updateKey).to.exist; expect(key.users).to.have.length(1); - key.update(updateKey).then(() => { + return key.update(updateKey).then(() => { expect(key.getFingerprint()).to.equal( updateKey.getFingerprint()); expect(key.users).to.have.length(2); expect(key.users[1].userId).to.be.null; - done(); }); }); } diff --git a/test/general/keyring.js b/test/general/keyring.js index 41ca05af..f8eb4e9f 100644 --- a/test/general/keyring.js +++ b/test/general/keyring.js @@ -3,9 +3,10 @@ const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp const chai = require('chai'); const { expect } = chai; + const keyring = new openpgp.Keyring(); -describe("Keyring", function() { +describe("Keyring", async function() { const user = 'whiteout.test@t-online.de'; const passphrase = 'asdf'; const keySize = 512; @@ -105,13 +106,14 @@ describe("Keyring", function() { '=4jat', '-----END PGP PUBLIC KEY BLOCK-----'].join('\n'); - it('Import key pair', function() { + it('Import key pair', async function() { + await keyring.load(); // clear any keys already in the keychain keyring.clear(); - keyring.store(); - keyring.publicKeys.importKey(pubkey); - keyring.publicKeys.importKey(pubkey2); - keyring.privateKeys.importKey(privkey); + await keyring.store(); + await keyring.publicKeys.importKey(pubkey); + await keyring.publicKeys.importKey(pubkey2); + await keyring.privateKeys.importKey(privkey); }); it('getKeysForId() - unknown id', function() { @@ -202,8 +204,8 @@ describe("Keyring", function() { expect(keys).to.exist.and.have.length(1); }); - it('publicKeys.getForAddress() - valid address, plain email user id', function() { - keyring.publicKeys.importKey(pubkey3); + it('publicKeys.getForAddress() - valid address, plain email user id', async function() { + await keyring.publicKeys.importKey(pubkey3); const keys = keyring.publicKeys.getForAddress(user3); keyring.removeKeysForId(keyFingerP3); expect(keys).to.exist.and.have.length(1); @@ -229,12 +231,13 @@ describe("Keyring", function() { expect(key).to.exist.and.have.length(1); }); - it('store keys in localstorage', function(){ - keyring.store(); + it('store keys in localstorage', async function(){ + await keyring.store(); }); - it('after loading from localstorage: getKeysForKeyId() - valid id', function() { + it('after loading from localstorage: getKeysForKeyId() - valid id', async function() { const keyring = new openpgp.Keyring(); + await keyring.load(); const keys = keyring.getKeysForId(keyId); // we expect public and private key expect(keys).to.exist.and.have.length(2); @@ -265,36 +268,36 @@ describe("Keyring", function() { expect(keyring.publicKeys.keys).to.be.empty; }); - it('customize localstorage itemname', function() { + it('customize localstorage itemname', async function() { const localstore1 = new openpgp.Keyring.localstore('my-custom-prefix-'); const localstore2 = new openpgp.Keyring.localstore('my-custom-prefix-'); const localstore3 = new openpgp.Keyring.localstore(); - localstore3.storePublic([]); - const key = openpgp.key.readArmored(pubkey).keys[0]; - localstore1.storePublic([key]); - expect(localstore2.loadPublic()[0].getKeyId().equals(key.getKeyId())).to.be.true; - expect(localstore3.loadPublic()).to.have.length(0); + await localstore3.storePublic([]); + const key = (await openpgp.key.readArmored(pubkey)).keys[0]; + await localstore1.storePublic([key]); + expect((await localstore2.loadPublic())[0].getKeyId().equals(key.getKeyId())).to.be.true; + expect(await localstore3.loadPublic()).to.have.length(0); }); - it('emptying keyring and storing removes keys', function() { - const key = openpgp.key.readArmored(pubkey).keys[0]; + it('emptying keyring and storing removes keys', async function() { + const key = (await openpgp.key.readArmored(pubkey)).keys[0]; const localstore = new openpgp.Keyring.localstore('remove-prefix-'); - localstore.storePublic([]); + await localstore.storePublic([]); expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.null; - localstore.storePublic([key]); + await localstore.storePublic([key]); expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.not.null; - localstore.storePublic([]); + await localstore.storePublic([]); expect(localstore.storage.getItem('remove-prefix-public-keys')).to.be.null; }); - it('removeKeysForId() - unknown id', function() { - keyring.publicKeys.importKey(pubkey); - keyring.publicKeys.importKey(pubkey2); - keyring.privateKeys.importKey(privkey); + it('removeKeysForId() - unknown id', async function() { + await keyring.publicKeys.importKey(pubkey); + await keyring.publicKeys.importKey(pubkey2); + await keyring.privateKeys.importKey(privkey); expect(keyring.publicKeys.keys).to.have.length(2); expect(keyring.privateKeys.keys).to.have.length(1); const keys = keyring.removeKeysForId('01234567890123456'); @@ -310,10 +313,10 @@ describe("Keyring", function() { expect(keyring.privateKeys.keys).to.have.length(0); }); - it('removeKeysForId() - unknown fingerprint', function() { - keyring.publicKeys.importKey(pubkey); - keyring.publicKeys.importKey(pubkey2); - keyring.privateKeys.importKey(privkey); + it('removeKeysForId() - unknown fingerprint', async function() { + await keyring.publicKeys.importKey(pubkey); + await keyring.publicKeys.importKey(pubkey2); + await keyring.privateKeys.importKey(privkey); expect(keyring.publicKeys.keys).to.have.length(2); expect(keyring.privateKeys.keys).to.have.length(1); const keys = keyring.removeKeysForId('71130e8383bef9526e062600d5e9f93acbbc7275'); diff --git a/test/general/openpgp.js b/test/general/openpgp.js index 668e7eee..ad891411 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -617,23 +617,23 @@ describe('OpenPGP.js public api tests', function() { let aead_modeVal; let aead_chunk_size_byteVal; - beforeEach(function(done) { - publicKey = openpgp.key.readArmored(pub_key); + beforeEach(async function() { + publicKey = await openpgp.key.readArmored(pub_key); expect(publicKey.keys).to.have.length(1); expect(publicKey.err).to.not.exist; - publicKeyNoAEAD = openpgp.key.readArmored(pub_key); - privateKey = openpgp.key.readArmored(priv_key); + publicKeyNoAEAD = await openpgp.key.readArmored(pub_key); + privateKey = await openpgp.key.readArmored(priv_key); expect(privateKey.keys).to.have.length(1); expect(privateKey.err).to.not.exist; - privateKey_2000_2008 = openpgp.key.readArmored(priv_key_2000_2008); + privateKey_2000_2008 = await openpgp.key.readArmored(priv_key_2000_2008); expect(privateKey_2000_2008.keys).to.have.length(1); expect(privateKey_2000_2008.err).to.not.exist; publicKey_2000_2008 = { keys: [ privateKey_2000_2008.keys[0].toPublic() ] }; - privateKey_2038_2045 = openpgp.key.readArmored(priv_key_2038_2045); + privateKey_2038_2045 = await openpgp.key.readArmored(priv_key_2038_2045); expect(privateKey_2038_2045.keys).to.have.length(1); expect(privateKey_2038_2045.err).to.not.exist; publicKey_2038_2045 = { keys: [ privateKey_2038_2045.keys[0].toPublic() ] }; - privateKey_1337 = openpgp.key.readArmored(priv_key_expires_1337); + privateKey_1337 = await openpgp.key.readArmored(priv_key_expires_1337); expect(privateKey_1337.keys).to.have.length(1); expect(privateKey_1337.err).to.not.exist; publicKey_1337 = { keys: [ privateKey_1337.keys[0].toPublic() ] }; @@ -643,7 +643,6 @@ describe('OpenPGP.js public api tests', function() { aead_protect_versionVal = openpgp.config.aead_protect_version; aead_modeVal = openpgp.config.aead_mode; aead_chunk_size_byteVal = openpgp.config.aead_chunk_size_byte; - done(); }); afterEach(function() { @@ -786,8 +785,8 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys[0] }; - return openpgp.encrypt(encOpt).then(function(encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function(encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).catch(function(error) { expect(error.message).to.match(/not decrypted/); @@ -858,15 +857,15 @@ describe('OpenPGP.js public api tests', function() { return openpgp.encrypt({ data: plaintext, publicKeys: publicKey.keys - }).then(function (encrypted) { + }).then(async function (encrypted) { msgAsciiArmored = encrypted.data; return openpgp.decryptSessionKeys({ - message: openpgp.message.readArmored(msgAsciiArmored), + message: await openpgp.message.readArmored(msgAsciiArmored), privateKeys: privateKey.keys[0] }); - }).then(function (decryptedSessionKeys) { - const message = openpgp.message.readArmored(msgAsciiArmored); + }).then(async function (decryptedSessionKeys) { + const message = await openpgp.message.readArmored(msgAsciiArmored); return openpgp.decrypt({ sessionKeys: decryptedSessionKeys[0], message @@ -882,15 +881,15 @@ describe('OpenPGP.js public api tests', function() { return openpgp.encrypt({ data: plaintext, publicKeys: publicKey.keys - }).then(function (encrypted) { + }).then(async function (encrypted) { msgAsciiArmored = encrypted.data; return openpgp.decryptSessionKeys({ - message: openpgp.message.readArmored(msgAsciiArmored), + message: await openpgp.message.readArmored(msgAsciiArmored), privateKeys: privateKey.keys[0] }); - }).then(function (decryptedSessionKeys) { - const message = openpgp.message.readArmored(msgAsciiArmored); + }).then(async function (decryptedSessionKeys) { + const message = await openpgp.message.readArmored(msgAsciiArmored); return openpgp.decrypt({ sessionKeys: decryptedSessionKeys[0], message @@ -905,17 +904,17 @@ describe('OpenPGP.js public api tests', function() { return openpgp.encrypt({ data: plaintext, passwords: password1 - }).then(function (encrypted) { + }).then(async function (encrypted) { msgAsciiArmored = encrypted.data; return openpgp.decryptSessionKeys({ - message: openpgp.message.readArmored(msgAsciiArmored), + message: await openpgp.message.readArmored(msgAsciiArmored), passwords: password1 }); - }).then(function (decryptedSessionKeys) { + }).then(async function (decryptedSessionKeys) { return openpgp.decrypt({ sessionKeys: decryptedSessionKeys[0], - message: openpgp.message.readArmored(msgAsciiArmored) + message: await openpgp.message.readArmored(msgAsciiArmored) }); }).then(function (decrypted) { @@ -928,17 +927,17 @@ describe('OpenPGP.js public api tests', function() { return openpgp.encrypt({ data: plaintext, passwords: [password1, password2] - }).then(function (encrypted) { + }).then(async function (encrypted) { msgAsciiArmored = encrypted.data; return openpgp.decryptSessionKeys({ - message: openpgp.message.readArmored(msgAsciiArmored), + message: await openpgp.message.readArmored(msgAsciiArmored), passwords: [password1, password2] }); - }).then(function (decryptedSessionKeys) { + }).then(async function (decryptedSessionKeys) { return openpgp.decrypt({ sessionKeys: decryptedSessionKeys, - message: openpgp.message.readArmored(msgAsciiArmored) + message: await openpgp.message.readArmored(msgAsciiArmored) }); }).then(function (decrypted) { @@ -951,17 +950,17 @@ describe('OpenPGP.js public api tests', function() { return openpgp.encrypt({ data: plaintext, passwords: [password1, password1] - }).then(function (encrypted) { + }).then(async function (encrypted) { msgAsciiArmored = encrypted.data; return openpgp.decryptSessionKeys({ - message: openpgp.message.readArmored(msgAsciiArmored), + message: await openpgp.message.readArmored(msgAsciiArmored), passwords: password1 }); - }).then(function (decryptedSessionKeys) { + }).then(async function (decryptedSessionKeys) { expect(decryptedSessionKeys.length).to.equal(1); return openpgp.decrypt({ sessionKeys: decryptedSessionKeys, - message: openpgp.message.readArmored(msgAsciiArmored) + message: await openpgp.message.readArmored(msgAsciiArmored) }); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -995,9 +994,9 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); - decOpt.message = openpgp.message.readArmored(encrypted.data); + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1007,7 +1006,7 @@ describe('OpenPGP.js public api tests', function() { }); it('should encrypt then decrypt with multiple private keys', async function () { - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); const encOpt = { @@ -1017,9 +1016,9 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: [privKeyDE, privateKey.keys[0]] }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); - decOpt.message = openpgp.message.readArmored(encrypted.data); + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1037,9 +1036,9 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); - decOpt.message = openpgp.message.readArmored(encrypted.data); + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1049,7 +1048,7 @@ describe('OpenPGP.js public api tests', function() { }); it('should encrypt then decrypt with wildcard with multiple private keys', async function () { - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); const encOpt = { @@ -1060,9 +1059,9 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: [privKeyDE, privateKey.keys[0]] }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); - decOpt.message = openpgp.message.readArmored(encrypted.data); + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1078,11 +1077,11 @@ describe('OpenPGP.js public api tests', function() { returnSessionKey: true }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); const decOpt = { sessionKeys: encrypted.sessionKey, - message: openpgp.message.readArmored(encrypted.data) + message: await openpgp.message.readArmored(encrypted.data) }; return openpgp.decrypt(decOpt); }).then(function (decrypted) { @@ -1105,9 +1104,9 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { sessionKeys: sessionKey }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); - decOpt.message = openpgp.message.readArmored(encrypted.data); + decOpt.message = await openpgp.message.readArmored(encrypted.data); expect(!!decOpt.message.packets.findPacket(openpgp.enums.packet.symEncryptedAEADProtected)).to.equal(openpgp.config.aead_protect && openpgp.config.aead_protect_version !== 4); return openpgp.decrypt(decOpt); }).then(function (decrypted) { @@ -1128,9 +1127,9 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys[0] }; - return openpgp.encrypt(encOpt).then(function (encrypted) { + return openpgp.encrypt(encOpt).then(async function (encrypted) { expect(encrypted.data).to.match(/^-----BEGIN PGP MESSAGE/); - decOpt.message = openpgp.message.readArmored(encrypted.data); + decOpt.message = await openpgp.message.readArmored(encrypted.data); expect(!!decOpt.message.packets.findPacket(openpgp.enums.packet.symEncryptedAEADProtected)).to.equal(openpgp.config.aead_protect && openpgp.config.aead_protect_version !== 4); return openpgp.decrypt(decOpt); }).then(function (decrypted) { @@ -1148,8 +1147,8 @@ describe('OpenPGP.js public api tests', function() { privateKeys: privateKey.keys[0], publicKeys: publicKey.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); expect(!!decOpt.message.packets.findPacket(openpgp.enums.packet.symEncryptedAEADProtected)).to.equal(openpgp.config.aead_protect); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { @@ -1171,8 +1170,8 @@ describe('OpenPGP.js public api tests', function() { privateKeys: privateKey.keys[0], publicKeys: publicKeyNoAEAD.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); expect(!!decOpt.message.packets.findPacket(openpgp.enums.packet.symEncryptedAEADProtected)).to.equal(openpgp.config.aead_protect && openpgp.config.aead_protect_version !== 4); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { @@ -1191,9 +1190,9 @@ describe('OpenPGP.js public api tests', function() { }; if (openpgp.util.getWebCryptoAll()) { genOpt.numBits = 2048; } // webkit webcrypto accepts minimum 2048 bit keys - return openpgp.generateKey(genOpt).then(function(newKey) { - const newPublicKey = openpgp.key.readArmored(newKey.publicKeyArmored); - const newPrivateKey = openpgp.key.readArmored(newKey.privateKeyArmored); + return openpgp.generateKey(genOpt).then(async function(newKey) { + const newPublicKey = await openpgp.key.readArmored(newKey.publicKeyArmored); + const newPrivateKey = await openpgp.key.readArmored(newKey.privateKeyArmored); const encOpt = { data: plaintext, @@ -1204,8 +1203,8 @@ describe('OpenPGP.js public api tests', function() { privateKeys: newPrivateKey.keys[0], publicKeys: newPublicKey.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); expect(!!decOpt.message.packets.findPacket(openpgp.enums.packet.symEncryptedAEADProtected)).to.equal(openpgp.config.aead_protect); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { @@ -1228,8 +1227,8 @@ describe('OpenPGP.js public api tests', function() { privateKeys: privateKey.keys[0], publicKeys: publicKey.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(''); @@ -1251,9 +1250,9 @@ describe('OpenPGP.js public api tests', function() { privateKeys: privateKey.keys[0], publicKeys: publicKey.keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); - decOpt.signature = openpgp.signature.readArmored(encrypted.signature); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); + decOpt.signature = await openpgp.signature.readArmored(encrypted.signature); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1282,12 +1281,12 @@ describe('OpenPGP.js public api tests', function() { publicKeys: publicKey.keys[0] }; - return openpgp.sign(signOpt).then(function (signed) { - encOpt.signature = openpgp.signature.readArmored(signed.signature); + return openpgp.sign(signOpt).then(async function (signed) { + encOpt.signature = await openpgp.signature.readArmored(signed.signature); return openpgp.encrypt(encOpt); - }).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); - decOpt.signature = openpgp.signature.readArmored(encrypted.signature); + }).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); + decOpt.signature = await openpgp.signature.readArmored(encrypted.signature); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1299,10 +1298,10 @@ describe('OpenPGP.js public api tests', function() { }); it('should encrypt and decrypt/verify with detached signature as input and detached flag not set for encryption', async function () { - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); - const pubKeyDE = openpgp.key.readArmored(pub_key_de).keys[0]; + const pubKeyDE = (await openpgp.key.readArmored(pub_key_de)).keys[0]; const signOpt = { data: plaintext, @@ -1321,11 +1320,11 @@ describe('OpenPGP.js public api tests', function() { publicKeys: [publicKey.keys[0], pubKeyDE] }; - return openpgp.sign(signOpt).then(function (signed) { - encOpt.signature = openpgp.signature.readArmored(signed.signature); + return openpgp.sign(signOpt).then(async function (signed) { + encOpt.signature = await openpgp.signature.readArmored(signed.signature); return openpgp.encrypt(encOpt); - }).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + }).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { let signingKey; @@ -1341,7 +1340,7 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should fail to encrypt and decrypt/verify with detached signature input and detached flag set for encryption with wrong public key', function () { + it('should fail to encrypt and decrypt/verify with detached signature input and detached flag set for encryption with wrong public key', async function () { const signOpt = { data: plaintext, privateKeys: privateKey.keys, @@ -1356,15 +1355,15 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys[0], - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.sign(signOpt).then(function (signed) { - encOpt.signature = openpgp.signature.readArmored(signed.signature); + return openpgp.sign(signOpt).then(async function (signed) { + encOpt.signature = await openpgp.signature.readArmored(signed.signature); return openpgp.encrypt(encOpt); - }).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); - decOpt.signature = openpgp.signature.readArmored(encrypted.signature); + }).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); + decOpt.signature = await openpgp.signature.readArmored(encrypted.signature); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1375,7 +1374,7 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should fail to encrypt and decrypt/verify with detached signature as input and detached flag not set for encryption with wrong public key', function () { + it('should fail to encrypt and decrypt/verify with detached signature as input and detached flag not set for encryption with wrong public key', async function () { const signOpt = { data: plaintext, privateKeys: privateKey.keys, @@ -1389,14 +1388,14 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys[0], - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.sign(signOpt).then(function (signed) { - encOpt.signature = openpgp.signature.readArmored(signed.signature); + return openpgp.sign(signOpt).then(async function (signed) { + encOpt.signature = await openpgp.signature.readArmored(signed.signature); return openpgp.encrypt(encOpt); - }).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + }).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1407,7 +1406,7 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should fail to verify decrypted data with wrong public pgp key', function () { + it('should fail to verify decrypted data with wrong public pgp key', async function () { const encOpt = { data: plaintext, publicKeys: publicKey.keys, @@ -1415,10 +1414,10 @@ describe('OpenPGP.js public api tests', function() { }; const decOpt = { privateKeys: privateKey.keys[0], - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1429,7 +1428,7 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should fail to verify decrypted null string with wrong public pgp key', function () { + it('should fail to verify decrypted null string with wrong public pgp key', async function () { const encOpt = { data: '', publicKeys: publicKey.keys, @@ -1437,10 +1436,10 @@ describe('OpenPGP.js public api tests', function() { }; const decOpt = { privateKeys: privateKey.keys[0], - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(''); @@ -1451,7 +1450,7 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should successfully decrypt signed message without public keys to verify', function () { + it('should successfully decrypt signed message without public keys to verify', async function () { const encOpt = { data: plaintext, publicKeys: publicKey.keys, @@ -1460,8 +1459,8 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { privateKeys: privateKey.keys[0] }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1472,7 +1471,7 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should fail to verify decrypted data with wrong public pgp key with detached signatures', function () { + it('should fail to verify decrypted data with wrong public pgp key with detached signatures', async function () { const encOpt = { data: plaintext, publicKeys: publicKey.keys, @@ -1481,11 +1480,11 @@ describe('OpenPGP.js public api tests', function() { }; const decOpt = { privateKeys: privateKey.keys[0], - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); - decOpt.signature = openpgp.signature.readArmored(encrypted.signature); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); + decOpt.signature = await openpgp.signature.readArmored(encrypted.signature); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -1497,10 +1496,10 @@ describe('OpenPGP.js public api tests', function() { }); it('should encrypt and decrypt/verify both signatures when signed with two private keys', async function () { - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); - const pubKeyDE = openpgp.key.readArmored(pub_key_de).keys[0]; + const pubKeyDE = (await openpgp.key.readArmored(pub_key_de)).keys[0]; const encOpt = { data: plaintext, @@ -1513,8 +1512,8 @@ describe('OpenPGP.js public api tests', function() { publicKeys: [publicKey.keys[0], pubKeyDE] }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(async function (decrypted) { let signingKey; @@ -1538,9 +1537,9 @@ describe('OpenPGP.js public api tests', function() { const verifyOpt = { publicKeys: publicKey.keys }; - return openpgp.sign(signOpt).then(function (signed) { + return openpgp.sign(signOpt).then(async function (signed) { expect(signed.data).to.match(/-----BEGIN PGP SIGNED MESSAGE-----/); - verifyOpt.message = openpgp.cleartext.readArmored(signed.data); + verifyOpt.message = await openpgp.cleartext.readArmored(signed.data); return openpgp.verify(verifyOpt); }).then(async function (verified) { expect(verified.data).to.equal(plaintext); @@ -1552,7 +1551,7 @@ describe('OpenPGP.js public api tests', function() { }); it('should sign and verify cleartext data with multiple private keys', async function () { - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); const signOpt = { @@ -1562,9 +1561,9 @@ describe('OpenPGP.js public api tests', function() { const verifyOpt = { publicKeys: [publicKey.keys[0], privKeyDE.toPublic()] }; - return openpgp.sign(signOpt).then(function (signed) { + return openpgp.sign(signOpt).then(async function (signed) { expect(signed.data).to.match(/-----BEGIN PGP SIGNED MESSAGE-----/); - verifyOpt.message = openpgp.cleartext.readArmored(signed.data); + verifyOpt.message = await openpgp.cleartext.readArmored(signed.data); return openpgp.verify(verifyOpt); }).then(async function (verified) { let signingKey; @@ -1589,9 +1588,9 @@ describe('OpenPGP.js public api tests', function() { const verifyOpt = { publicKeys: publicKey.keys }; - return openpgp.sign(signOpt).then(function (signed) { + return openpgp.sign(signOpt).then(async function (signed) { verifyOpt.message = new openpgp.cleartext.CleartextMessage(plaintext); - verifyOpt.signature = openpgp.signature.readArmored(signed.signature); + verifyOpt.signature = await openpgp.signature.readArmored(signed.signature); return openpgp.verify(verifyOpt); }).then(async function (verified) { expect(verified.data).to.equal(plaintext); @@ -1602,16 +1601,16 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should sign and fail to verify cleartext data with wrong public pgp key', function () { + it('should sign and fail to verify cleartext data with wrong public pgp key', async function () { const signOpt = { data: plaintext, privateKeys: privateKey.keys }; const verifyOpt = { - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.sign(signOpt).then(function (signed) { - verifyOpt.message = openpgp.cleartext.readArmored(signed.data); + return openpgp.sign(signOpt).then(async function (signed) { + verifyOpt.message = await openpgp.cleartext.readArmored(signed.data); return openpgp.verify(verifyOpt); }).then(async function (verified) { expect(verified.data).to.equal(plaintext); @@ -1622,18 +1621,18 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should sign and fail to verify cleartext data with wrong public pgp key with detached signature', function () { + it('should sign and fail to verify cleartext data with wrong public pgp key with detached signature', async function () { const signOpt = { data: plaintext, privateKeys: privateKey.keys, detached: true }; const verifyOpt = { - publicKeys: openpgp.key.readArmored(wrong_pubkey).keys + publicKeys: (await openpgp.key.readArmored(wrong_pubkey)).keys }; - return openpgp.sign(signOpt).then(function (signed) { + return openpgp.sign(signOpt).then(async function (signed) { verifyOpt.message = new openpgp.cleartext.CleartextMessage(plaintext); - verifyOpt.signature = openpgp.signature.readArmored(signed.signature); + verifyOpt.signature = await openpgp.signature.readArmored(signed.signature); return openpgp.verify(verifyOpt); }).then(async function (verified) { expect(verified.data).to.equal(plaintext); @@ -1907,8 +1906,8 @@ describe('OpenPGP.js public api tests', function() { }); it('should fail to encrypt with revoked subkey', async function() { - const pubKeyDE = openpgp.key.readArmored(pub_key_de).keys[0]; - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const pubKeyDE = (await openpgp.key.readArmored(pub_key_de)).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); return privKeyDE.subKeys[0].revoke(privKeyDE.primaryKey).then(function(revSubKey) { pubKeyDE.subKeys[0] = revSubKey; @@ -1927,19 +1926,19 @@ describe('OpenPGP.js public api tests', function() { describe('ELG / DSA encrypt, decrypt, sign, verify', function() { it('round trip test', async function () { - const pubKeyDE = openpgp.key.readArmored(pub_key_de).keys[0]; - const privKeyDE = openpgp.key.readArmored(priv_key_de).keys[0]; + const pubKeyDE = (await openpgp.key.readArmored(pub_key_de)).keys[0]; + const privKeyDE = (await openpgp.key.readArmored(priv_key_de)).keys[0]; await privKeyDE.decrypt(passphrase); pubKeyDE.users[0].selfCertifications[0].features = [7]; // Monkey-patch AEAD feature flag return openpgp.encrypt({ publicKeys: pubKeyDE, privateKeys: privKeyDE, data: plaintext - }).then(function (encrypted) { + }).then(async function (encrypted) { return openpgp.decrypt({ privateKeys: privKeyDE, publicKeys: pubKeyDE, - message: openpgp.message.readArmored(encrypted.data) + message: await openpgp.message.readArmored(encrypted.data) }); }).then(async function (decrypted) { expect(decrypted.data).to.exist; @@ -2005,9 +2004,9 @@ describe('OpenPGP.js public api tests', function() { '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); it('Decrypt message', async function() { - const privKey = openpgp.key.readArmored(priv_key).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key)).keys[0]; await privKey.decrypt('1234'); - const message = openpgp.message.readArmored(pgp_msg); + const message = await openpgp.message.readArmored(pgp_msg); return openpgp.decrypt({ privateKeys:privKey, message:message }).then(function(decrypted) { expect(decrypted.data).to.equal('hello 3des\n'); @@ -2026,8 +2025,8 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { passwords: password1 }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -2043,8 +2042,8 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { passwords: password2 }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); @@ -2052,10 +2051,10 @@ describe('OpenPGP.js public api tests', function() { }); }); - it('should decrypt with two passwords message which GPG fails on', function () { + it('should decrypt with two passwords message which GPG fails on', async function () { const decOpt = { - message: openpgp.message.readArmored(twoPasswordGPGFail), + message: await openpgp.message.readArmored(twoPasswordGPGFail), passwords: password2 }; return openpgp.decrypt(decOpt).then(function (decrypted) { @@ -2116,8 +2115,8 @@ describe('OpenPGP.js public api tests', function() { const decOpt = { passwords: password1 }; - return openpgp.encrypt(encOpt).then(function (encrypted) { - decOpt.message = openpgp.message.readArmored(encrypted.data); + return openpgp.encrypt(encOpt).then(async function (encrypted) { + decOpt.message = await openpgp.message.readArmored(encrypted.data); return openpgp.decrypt(decOpt); }).then(function (decrypted) { expect(decrypted.data).to.equal(plaintext); diff --git a/test/general/packet.js b/test/general/packet.js index 193e40c2..367cc213 100644 --- a/test/general/packet.js +++ b/test/general/packet.js @@ -8,7 +8,11 @@ const { expect } = chai; const input = require('./testInputs.js'); function stringify(array) { - if(!Uint8Array.prototype.isPrototypeOf(array)) { + if (openpgp.util.isStream(array)) { + return array.readToEnd().then(stringify); + } + + if (!openpgp.util.isUint8Array(array)) { throw new Error('Data must be in the form of a Uint8Array'); } @@ -74,11 +78,11 @@ describe("Packet", function() { await enc.encrypt(algo, key); const msg2 = new openpgp.packet.List(); - msg2.read(message.write()); + await msg2.read(message.write()); msg2[0].ignore_mdc_error = true; await msg2[0].decrypt(algo, key); - expect(stringify(msg2[0].packets[0].data)).to.equal(stringify(literal.data)); + expect(await stringify(msg2[0].packets[0].data)).to.equal(stringify(literal.data)); }); it('Symmetrically encrypted packet - MDC error for modern cipher', async function() { @@ -98,7 +102,7 @@ describe("Packet", function() { await enc.encrypt(algo, key); const msg2 = new openpgp.packet.List(); - msg2.read(message.write()); + await msg2.read(message.write()); await expect(msg2[0].decrypt(algo, key)).to.eventually.be.rejectedWith('Decryption failed due to missing MDC.'); }); @@ -117,11 +121,11 @@ describe("Packet", function() { await enc.encrypt(algo, key); const msg2 = new openpgp.packet.List(); - msg2.read(msg.write()); + await msg2.read(msg.write()); await msg2[0].decrypt(algo, key); - expect(stringify(msg2[0].packets[0].data)).to.equal(stringify(literal.data)); + expect(await stringify(msg2[0].packets[0].data)).to.equal(stringify(literal.data)); }); it('Sym. encrypted AEAD protected packet', function() { @@ -138,8 +142,8 @@ describe("Packet", function() { const msg2 = new openpgp.packet.List(); - return enc.encrypt(algo, key).then(function() { - msg2.read(msg.write()); + return enc.encrypt(algo, key).then(async function() { + await msg2.read(msg.write()); return msg2[0].decrypt(algo, key); }).then(function() { expect(msg2[0].packets[0].data).to.deep.equal(literal.data); @@ -166,8 +170,8 @@ describe("Packet", function() { const msg2 = new openpgp.packet.List(); - return enc.encrypt(algo, key).then(function() { - msg2.read(msg.write()); + return enc.encrypt(algo, key).then(async function() { + await msg2.read(msg.write()); return msg2[0].decrypt(algo, key); }).then(function() { expect(msg2[0].packets[0].data).to.deep.equal(literal.data); @@ -213,10 +217,10 @@ describe("Packet", function() { let randomBytesStub = stub(openpgp.crypto.random, 'getRandomBytes'); randomBytesStub.returns(resolves(iv)); - return enc.encrypt(algo, key).then(function() { + return enc.encrypt(algo, key).then(async function() { const data = msg.write(); expect(data).to.deep.equal(packetBytes); - msg2.read(data); + await msg2.read(data); return msg2[0].decrypt(algo, key); }).then(function() { expect(msg2[0].packets[0].data).to.deep.equal(literal.data); @@ -238,10 +242,10 @@ describe("Packet", function() { '=VZ0/\n' + '-----END PGP MESSAGE-----'; - const msgbytes = openpgp.armor.decode(msg).data; + const msgbytes = (await openpgp.armor.decode(msg)).data; const parsed = new openpgp.packet.List(); - parsed.read(msgbytes); + await parsed.read(msgbytes); return parsed[0].decrypt('test').then(() => { const key = parsed[0].sessionKey; @@ -274,11 +278,11 @@ describe("Packet", function() { enc.publicKeyAlgorithm = 'rsa_encrypt'; enc.sessionKeyAlgorithm = 'aes256'; enc.publicKeyId.bytes = '12345678'; - return enc.encrypt({ params: mpi, getFingerprintBytes() {} }).then(() => { + return enc.encrypt({ params: mpi, getFingerprintBytes() {} }).then(async () => { msg.push(enc); - msg2.read(msg.write()); + await msg2.read(msg.write()); return msg2[0].decrypt({ params: mpi, getFingerprintBytes() {} }).then(() => { @@ -289,7 +293,7 @@ describe("Packet", function() { }); }); - it('Secret key packet (reading, unencrypted)', function() { + it('Secret key packet (reading, unencrypted)', async function() { const armored_key = '-----BEGIN PGP PRIVATE KEY BLOCK-----\n' + 'Version: GnuPG v2.0.19 (GNU/Linux)\n' + @@ -313,7 +317,7 @@ describe("Packet", function() { '-----END PGP PRIVATE KEY BLOCK-----'; let key = new openpgp.packet.List(); - key.read(openpgp.armor.decode(armored_key).data); + await key.read((await openpgp.armor.decode(armored_key)).data); key = key[0]; const enc = new openpgp.packet.PublicKeyEncryptedSessionKey(); @@ -331,7 +335,7 @@ describe("Packet", function() { }); }); - it('Public key encrypted packet (reading, GPG)', function() { + it('Public key encrypted packet (reading, GPG)', async function() { const armored_key = '-----BEGIN PGP PRIVATE KEY BLOCK-----\n' + 'Version: GnuPG v2.0.19 (GNU/Linux)\n' + @@ -380,11 +384,11 @@ describe("Packet", function() { '-----END PGP MESSAGE-----'; let key = new openpgp.packet.List(); - key.read(openpgp.armor.decode(armored_key).data); + await key.read((await openpgp.armor.decode(armored_key)).data); key = key[3]; const msg = new openpgp.packet.List(); - msg.read(openpgp.armor.decode(armored_msg).data); + await msg.read((await openpgp.armor.decode(armored_msg)).data); return msg[0].decrypt(key).then(async () => { await msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey); @@ -418,13 +422,13 @@ describe("Packet", function() { await enc.encrypt(algo, key); const msg2 = new openpgp.packet.List(); - msg2.read(msg.write()); + await msg2.read(msg.write()); await msg2[0].decrypt(passphrase); const key2 = msg2[0].sessionKey; await msg2[1].decrypt(msg2[0].sessionKeyAlgorithm, key2); - expect(stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); + expect(await stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); }); it('Sym. encrypted session key reading/writing (draft04)', async function() { @@ -456,13 +460,13 @@ describe("Packet", function() { await enc.encrypt(algo, key); const msg2 = new openpgp.packet.List(); - msg2.read(msg.write()); + await msg2.read(msg.write()); await msg2[0].decrypt(passphrase); const key2 = msg2[0].sessionKey; await msg2[1].decrypt(msg2[0].sessionKeyAlgorithm, key2); - expect(stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); + expect(await stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); } finally { openpgp.config.aead_protect = aead_protectVal; openpgp.config.aead_protect_version = aead_protect_versionVal; @@ -531,13 +535,13 @@ describe("Packet", function() { expect(data).to.deep.equal(packetBytes); const msg2 = new openpgp.packet.List(); - msg2.read(data); + await msg2.read(data); await msg2[0].decrypt(passphrase); const key2 = msg2[0].sessionKey; await msg2[1].decrypt(msg2[0].sessionKeyAlgorithm, key2); - expect(stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); + expect(await stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); } finally { openpgp.config.aead_protect = aead_protectVal; openpgp.config.aead_protect_version = aead_protect_versionVal; @@ -610,13 +614,13 @@ describe("Packet", function() { expect(data).to.deep.equal(packetBytes); const msg2 = new openpgp.packet.List(); - msg2.read(data); + await msg2.read(data); await msg2[0].decrypt(passphrase); const key2 = msg2[0].sessionKey; await msg2[1].decrypt(msg2[0].sessionKeyAlgorithm, key2); - expect(stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); + expect(await stringify(msg2[1].packets[0].data)).to.equal(stringify(literal.data)); } finally { openpgp.config.aead_protect = aead_protectVal; openpgp.config.aead_protect_version = aead_protect_versionVal; @@ -640,12 +644,12 @@ describe("Packet", function() { '-----END PGP MESSAGE-----'; let key = new openpgp.packet.List(); - key.read(openpgp.armor.decode(armored_key).data); + await key.read((await openpgp.armor.decode(armored_key)).data); key = key[3]; await key.decrypt('test'); const msg = new openpgp.packet.List(); - msg.read(openpgp.armor.decode(armored_msg).data); + await msg.read((await openpgp.armor.decode(armored_msg)).data); return msg[0].decrypt(key).then(async () => { await msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey); @@ -656,9 +660,9 @@ describe("Packet", function() { }); }); - it('Secret key reading with signature verification.', function() { + it('Secret key reading with signature verification.', async function() { const key = new openpgp.packet.List(); - key.read(openpgp.armor.decode(armored_key).data); + await key.read((await openpgp.armor.decode(armored_key)).data); return Promise.all([ expect(key[2].verify(key[0], { @@ -691,11 +695,11 @@ describe("Packet", function() { '-----END PGP MESSAGE-----'; const key = new openpgp.packet.List(); - key.read(openpgp.armor.decode(armored_key).data); + await key.read((await openpgp.armor.decode(armored_key)).data); await key[3].decrypt('test'); const msg = new openpgp.packet.List(); - msg.read(openpgp.armor.decode(armored_msg).data); + await msg.read((await openpgp.armor.decode(armored_msg)).data); return msg[0].decrypt(key[3]).then(async () => { await msg[1].decrypt(msg[0].sessionKeyAlgorithm, msg[0].sessionKey); @@ -747,7 +751,7 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu const raw = key.write(); const key2 = new openpgp.packet.List(); - key2.read(raw); + await key2.read(raw); await key2[0].decrypt('hello'); expect(key[0].params.toString()).to.equal(key2[0].params.toString()); @@ -779,7 +783,7 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu const raw = key.write(); const key2 = new openpgp.packet.List(); - key2.read(raw); + await key2.read(raw); await key2[0].decrypt('hello'); expect(key[0].params.toString()).to.equal(key2[0].params.toString()); @@ -823,7 +827,7 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu const raw = signed.write(); const signed2 = new openpgp.packet.List(); - signed2.read(raw); + await signed2.read(raw); await expect(signed2[1].verify(key, signed2[0])).to.eventually.be.true; }); diff --git a/test/general/signature.js b/test/general/signature.js index 0a6131d2..d58c2d05 100644 --- a/test/general/signature.js +++ b/test/general/signature.js @@ -325,9 +325,9 @@ describe("Signature", function() { '-----END PGP MESSAGE-----'].join('\n'); it('Testing signature checking on CAST5-enciphered message', async function() { - const priv_key = openpgp.key.readArmored(priv_key_arm1).keys[0]; - const pub_key = openpgp.key.readArmored(pub_key_arm1).keys[0]; - const msg = openpgp.message.readArmored(msg_arm1); + const priv_key = (await openpgp.key.readArmored(priv_key_arm1)).keys[0]; + const pub_key = (await openpgp.key.readArmored(pub_key_arm1)).keys[0]; + const msg = await openpgp.message.readArmored(msg_arm1); await priv_key.decrypt("abcd"); return openpgp.decrypt({ privateKeys: priv_key, publicKeys:[pub_key], message:msg }).then(function(decrypted) { expect(decrypted.data).to.exist; @@ -339,7 +339,7 @@ describe("Signature", function() { it('Testing GnuPG stripped-key extensions', async function() { // exercises the GnuPG s2k type 1001 extension: // the secrets on the primary key have been stripped. - const priv_key_gnupg_ext = openpgp.key.readArmored( + const priv_key_gnupg_ext = (await openpgp.key.readArmored( ['-----BEGIN PGP PRIVATE KEY BLOCK-----', 'Version: GnuPG v1.4.11 (GNU/Linux)', '', @@ -365,9 +365,9 @@ describe("Signature", function() { 'nrMCGwwACgkQESeUA8sWnvhBswCfdXjznvHCc73/6/MhWcv3dbeTT/wAoLyiZg8+', 'iY3UT9QkV9d0sMgyLkug', '=GQsY', - '-----END PGP PRIVATE KEY BLOCK-----'].join("\n")).keys[0]; - const pub_key = openpgp.key.readArmored(pub_key_arm1).keys[0]; - const msg = openpgp.message.readArmored(msg_arm1); + '-----END PGP PRIVATE KEY BLOCK-----'].join("\n"))).keys[0]; + const pub_key = (await openpgp.key.readArmored(pub_key_arm1)).keys[0]; + const msg = await openpgp.message.readArmored(msg_arm1); await priv_key_gnupg_ext.subKeys[0].keyPacket.decrypt("abcd"); return msg.decrypt([priv_key_gnupg_ext]).then(function(msg) { @@ -380,7 +380,7 @@ describe("Signature", function() { }); }); - it('Verify V4 signature. Hash: SHA1. PK: RSA. Signature Type: 0x00 (binary document)', function() { + it('Verify V4 signature. Hash: SHA1. PK: RSA. Signature Type: 0x00 (binary document)', async function() { const signedArmor = ['-----BEGIN PGP MESSAGE-----', 'Version: GnuPG v2.0.19 (GNU/Linux)', @@ -393,8 +393,8 @@ describe("Signature", function() { '=VH8F', '-----END PGP MESSAGE-----'].join('\n'); - const sMsg = openpgp.message.readArmored(signedArmor); - const pub_key = openpgp.key.readArmored(pub_key_arm2).keys[0]; + const sMsg = await openpgp.message.readArmored(signedArmor); + const pub_key = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; return sMsg.verify([pub_key]).then(verified => { expect(verified).to.exist; expect(verified).to.have.length(1); @@ -403,7 +403,7 @@ describe("Signature", function() { }); }); - it('Verify V3 signature. Hash: MD5. PK: RSA. Signature Type: 0x01 (text document)', function() { + it('Verify V3 signature. Hash: MD5. PK: RSA. Signature Type: 0x01 (text document)', async function() { const signedArmor = ['-----BEGIN PGP MESSAGE-----', 'Version: GnuPG v2.0.19 (GNU/Linux)', @@ -416,8 +416,8 @@ describe("Signature", function() { '=pa6B', '-----END PGP MESSAGE-----'].join('\n'); - const sMsg = openpgp.message.readArmored(signedArmor); - const pub_key = openpgp.key.readArmored(pub_key_arm2).keys[0]; + const sMsg = await openpgp.message.readArmored(signedArmor); + const pub_key = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; return sMsg.verify([pub_key]).then(verified => { expect(verified).to.exist; expect(verified).to.have.length(1); @@ -444,9 +444,9 @@ describe("Signature", function() { '-----END PGP MESSAGE-----'].join('\n'); const plaintext = 'short message\nnext line\n한국어/조선말'; - const esMsg = openpgp.message.readArmored(msg_armor); - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const esMsg = await openpgp.message.readArmored(msg_armor); + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await Promise.all(esMsg.getEncryptionKeyIds().map(keyId => privKey.decrypt('hello world', keyId))); @@ -478,9 +478,9 @@ describe("Signature", function() { '-----END PGP MESSAGE-----'].join('\n'); const plaintext = 'short message\nnext line\n한국어/조선말\n\n'; - const esMsg = openpgp.message.readArmored(msg_armor); - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const esMsg = await openpgp.message.readArmored(msg_armor); + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await Promise.all(esMsg.getEncryptionKeyIds().map(keyId => privKey.decrypt('hello world', keyId))); @@ -494,7 +494,7 @@ describe("Signature", function() { }); - it('Verify signed message with two one pass signatures', function() { + it('Verify signed message with two one pass signatures', async function() { const msg_armor = ['-----BEGIN PGP MESSAGE-----', 'Version: GnuPG v2.0.19 (GNU/Linux)', @@ -514,9 +514,9 @@ describe("Signature", function() { '-----END PGP MESSAGE-----'].join('\n'); const plaintext = 'short message\nnext line\n한국어/조선말'; - const sMsg = openpgp.message.readArmored(msg_armor); - const pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const pubKey3 = openpgp.key.readArmored(pub_key_arm3).keys[0]; + const sMsg = await openpgp.message.readArmored(msg_armor); + const pubKey2 = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const pubKey3 = (await openpgp.key.readArmored(pub_key_arm3)).keys[0]; const keyids = sMsg.getSigningKeyIds(); @@ -535,7 +535,7 @@ describe("Signature", function() { }); }); - it('Verify cleartext signed message with two signatures with openpgp.verify', function() { + it('Verify cleartext signed message with two signatures with openpgp.verify', async function() { const msg_armor = ['-----BEGIN PGP SIGNED MESSAGE-----', 'Hash: SHA256', @@ -560,9 +560,9 @@ describe("Signature", function() { '-----END PGP SIGNATURE-----'].join('\n'); const plaintext = 'short message\nnext line\n한국어/조선말'; - const csMsg = openpgp.cleartext.readArmored(msg_armor); - const pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const pubKey3 = openpgp.key.readArmored(pub_key_arm3).keys[0]; + const csMsg = await openpgp.cleartext.readArmored(msg_armor); + const pubKey2 = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const pubKey3 = (await openpgp.key.readArmored(pub_key_arm3)).keys[0]; const keyids = csMsg.getSigningKeyIds(); @@ -580,7 +580,7 @@ describe("Signature", function() { }); }); - it('Verify cleartext signed message with trailing spaces from GPG', function() { + it('Verify cleartext signed message with trailing spaces from GPG', async function() { const msg_armor = `-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 @@ -602,8 +602,8 @@ zmuVOdNuWQqxT9Sqa84= -----END PGP SIGNATURE-----`; const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t '; - const csMsg = openpgp.cleartext.readArmored(msg_armor); - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; + const csMsg = await openpgp.cleartext.readArmored(msg_armor); + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; const keyids = csMsg.getSigningKeyIds(); @@ -618,7 +618,7 @@ zmuVOdNuWQqxT9Sqa84= }); }); - it('Verify signed message with trailing spaces from GPG', function() { + it('Verify signed message with trailing spaces from GPG', async function() { const msg_armor = `-----BEGIN PGP MESSAGE----- Version: GnuPG v1 @@ -633,8 +633,8 @@ yYDnCgA= -----END PGP MESSAGE-----`; const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t '; - const sMsg = openpgp.message.readArmored(msg_armor); - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; + const sMsg = await openpgp.message.readArmored(msg_armor); + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; const keyids = sMsg.getSigningKeyIds(); @@ -651,13 +651,13 @@ yYDnCgA= it('Sign text with openpgp.sign and verify with openpgp.verify leads to same string cleartext and valid signatures', async function() { const plaintext = 'short message\nnext line\n한국어/조선말'; - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); - return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(function(signed) { + return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(async function(signed) { - const csMsg = openpgp.cleartext.readArmored(signed.data); + const csMsg = await openpgp.cleartext.readArmored(signed.data); return openpgp.verify({ publicKeys:[pubKey], message:csMsg }); }).then(function(cleartextSig) { @@ -671,13 +671,13 @@ yYDnCgA= it('Sign text with openpgp.sign and verify with openpgp.verify leads to same string cleartext and valid signatures -- escape armored message', async function() { const plaintext = pub_key_arm2; - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); - return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(function(signed) { + return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(async function(signed) { - const csMsg = openpgp.cleartext.readArmored(signed.data); + const csMsg = await openpgp.cleartext.readArmored(signed.data); return openpgp.verify({ publicKeys:[pubKey], message:csMsg }); }).then(function(cleartextSig) { @@ -691,13 +691,13 @@ yYDnCgA= it('Sign text with openpgp.sign and verify with openpgp.verify leads to same string cleartext and valid signatures -- trailing spaces', async function() { const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t '; - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); - return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(function(signed) { + return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(async function(signed) { - const csMsg = openpgp.cleartext.readArmored(signed.data); + const csMsg = await openpgp.cleartext.readArmored(signed.data); return openpgp.verify({ publicKeys:[pubKey], message:csMsg }); }).then(function(cleartextSig) { @@ -711,13 +711,13 @@ yYDnCgA= it('Sign text with openpgp.sign and verify with openpgp.verify leads to same bytes cleartext and valid signatures - armored', async function() { const plaintext = openpgp.util.str_to_Uint8Array('short message\nnext line\n한국어/조선말'); - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); - return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(function(signed) { + return openpgp.sign({ privateKeys:[privKey], data:plaintext }).then(async function(signed) { - const csMsg = openpgp.message.readArmored(signed.data); + const csMsg = await openpgp.message.readArmored(signed.data); return openpgp.verify({ publicKeys:[pubKey], message:csMsg }); }).then(function(cleartextSig) { @@ -731,8 +731,8 @@ yYDnCgA= it('Sign text with openpgp.sign and verify with openpgp.verify leads to same bytes cleartext and valid signatures - not armored', async function() { const plaintext = openpgp.util.str_to_Uint8Array('short message\nnext line\n한국어/조선말'); - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); return openpgp.sign({ privateKeys:[privKey], data:plaintext, armor:false }).then(function(signed) { @@ -751,11 +751,11 @@ yYDnCgA= it('Should verify cleartext message correctly when using a detached cleartext signature and binary literal data', async function () { const plaintext = 'short message\nnext line\n한국어/조선말'; - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey.decrypt('hello world'); - return openpgp.sign({ privateKeys:[privKey], data:plaintext, detached: true}).then(function(signed) { - const signature = openpgp.signature.readArmored(signed.signature); + return openpgp.sign({ privateKeys:[privKey], data:plaintext, detached: true}).then(async function(signed) { + const signature = await openpgp.signature.readArmored(signed.signature); return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromBinary(openpgp.util.str_to_Uint8Array(openpgp.util.encode_utf8(plaintext))), signature: signature }); }).then(function(cleartextSig) { expect(cleartextSig).to.exist; @@ -784,14 +784,14 @@ yYDnCgA= it('Should verify encrypted cleartext message correctly when encrypting binary literal data with a canonical text signature', async function () { const plaintext = 'short message\nnext line\n한국어/조선말'; - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await Promise.all([privKey.primaryKey.decrypt('hello world'), privKey.subKeys[0].keyPacket.decrypt('hello world')]); - return openpgp.sign({ privateKeys:[privKey], data: plaintext, detached: true}).then(function(signed) { - const signature = openpgp.signature.readArmored(signed.signature); + return openpgp.sign({ privateKeys:[privKey], data: plaintext, detached: true}).then(async function(signed) { + const signature = await openpgp.signature.readArmored(signed.signature); return openpgp.encrypt({ data: openpgp.util.str_to_Uint8Array(openpgp.util.encode_utf8(plaintext)), publicKeys: [pubKey], signature }) - }).then(({ data }) => { - const csMsg = openpgp.message.readArmored(data); + }).then(async ({ data }) => { + const csMsg = await openpgp.message.readArmored(data); return openpgp.decrypt({ message: csMsg, privateKeys: [ privKey ], publicKeys: [ pubKey ] }); }).then(function(cleartextSig) { expect(cleartextSig).to.exist; @@ -801,9 +801,9 @@ yYDnCgA= }); }); - it('Verify test with expired verification public key', function() { - const pubKey = openpgp.key.readArmored(pub_expired).keys[0]; - const message = openpgp.message.readArmored(msg_sig_expired); + it('Verify test with expired verification public key', async function() { + const pubKey = (await openpgp.key.readArmored(pub_expired)).keys[0]; + const message = await openpgp.message.readArmored(msg_sig_expired); return openpgp.verify({ publicKeys:[pubKey], message:message }).then(function(verified) { expect(verified).to.exist; expect(verified.signatures).to.have.length(1); @@ -813,9 +813,9 @@ yYDnCgA= }); - it('Verify test with expired verification public key and disable expiration checks using null date', function() { - const pubKey = openpgp.key.readArmored(pub_expired).keys[0]; - const message = openpgp.message.readArmored(msg_sig_expired); + it('Verify test with expired verification public key and disable expiration checks using null date', async function() { + const pubKey = (await openpgp.key.readArmored(pub_expired)).keys[0]; + const message = await openpgp.message.readArmored(msg_sig_expired); return openpgp.verify({ publicKeys:[pubKey], message:message, date: null }).then(function(verified) { expect(verified).to.exist; expect(verified.signatures).to.have.length(1); @@ -825,9 +825,9 @@ yYDnCgA= }); - it('Verify test with expired verification public key', function() { - const pubKey = openpgp.key.readArmored(pub_expired).keys[0]; - const message = openpgp.message.readArmored(msg_sig_expired); + it('Verify test with expired verification public key', async function() { + const pubKey = (await openpgp.key.readArmored(pub_expired)).keys[0]; + const message = await openpgp.message.readArmored(msg_sig_expired); return openpgp.verify({ publicKeys:[pubKey], message:message }).then(function(verified) { expect(verified).to.exist; expect(verified.signatures).to.have.length(1); @@ -837,9 +837,9 @@ yYDnCgA= }); - it('Verify test with expired verification public key and disable expiration checks using null date', function() { - const pubKey = openpgp.key.readArmored(pub_expired).keys[0]; - const message = openpgp.message.readArmored(msg_sig_expired); + it('Verify test with expired verification public key and disable expiration checks using null date', async function() { + const pubKey = (await openpgp.key.readArmored(pub_expired)).keys[0]; + const message = await openpgp.message.readArmored(msg_sig_expired); return openpgp.verify({ publicKeys:[pubKey], message:message, date: null }).then(function(verified) { expect(verified).to.exist; expect(verified.signatures).to.have.length(1); @@ -850,57 +850,56 @@ yYDnCgA= }); // TODO add test with multiple revocation signatures - it('Verify primary key revocation signatures', function(done) { - const pubKey = openpgp.key.readArmored(pub_revoked).keys[0]; - expect(pubKey.revocationSignatures[0].verify( + it('Verify primary key revocation signatures', async function() { + const pubKey = (await openpgp.key.readArmored(pub_revoked)).keys[0]; + await expect(pubKey.revocationSignatures[0].verify( pubKey.primaryKey, {key: pubKey.primaryKey} - )).to.eventually.be.true.notify(done); + )).to.eventually.be.true; }); // TODO add test with multiple revocation signatures - it('Verify subkey revocation signatures', function(done) { - const pubKey = openpgp.key.readArmored(pub_revoked).keys[0]; - expect(pubKey.subKeys[0].revocationSignatures[0].verify( + it('Verify subkey revocation signatures', async function() { + const pubKey = (await openpgp.key.readArmored(pub_revoked)).keys[0]; + await expect(pubKey.subKeys[0].revocationSignatures[0].verify( pubKey.primaryKey, {key: pubKey.primaryKey, bind: pubKey.subKeys[0].keyPacket} - )).to.eventually.be.true.notify(done); + )).to.eventually.be.true; }); - it('Verify key expiration date', function(done) { - const pubKey = openpgp.key.readArmored(pub_revoked).keys[0]; + it('Verify key expiration date', async function() { + const pubKey = (await openpgp.key.readArmored(pub_revoked)).keys[0]; expect(pubKey).to.exist; expect(pubKey.users[0].selfCertifications[0].keyNeverExpires).to.be.false; expect(pubKey.users[0].selfCertifications[0].keyExpirationTime).to.equal(5*365*24*60*60); - done(); }); - it('Verify V3 certification signature', function(done) { - const pubKey = openpgp.key.readArmored(pub_v3).keys[0]; - expect(pubKey.users[0].selfCertifications[0].verify(pubKey.primaryKey, {key: pubKey.primaryKey, userId: pubKey.users[0].userId})).to.eventually.be.true.notify(done); + it('Verify V3 certification signature', async function() { + const pubKey = (await openpgp.key.readArmored(pub_v3)).keys[0]; + await expect(pubKey.users[0].selfCertifications[0].verify(pubKey.primaryKey, {key: pubKey.primaryKey, userId: pubKey.users[0].userId})).to.eventually.be.true; }); - it('Write unhashed subpackets', function() { - let pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; + it('Write unhashed subpackets', async function() { + let pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; expect(pubKey.users[0].selfCertifications).to.exist; - pubKey = openpgp.key.readArmored(pubKey.armor()).keys[0]; + pubKey = (await openpgp.key.readArmored(pubKey.armor())).keys[0]; expect(pubKey.users[0].selfCertifications).to.exist; }); - it('Write V3 signatures', function() { - const pubKey = openpgp.key.readArmored(pub_v3).keys[0]; - const pubKey2 = openpgp.key.readArmored(pubKey.armor()).keys[0]; + it('Write V3 signatures', async function() { + const pubKey = (await openpgp.key.readArmored(pub_v3)).keys[0]; + const pubKey2 = (await openpgp.key.readArmored(pubKey.armor())).keys[0]; expect(pubKey2).to.exist; expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications); }); - it('Write V4 signatures', function() { - const pubKey = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const pubKey2 = openpgp.key.readArmored(pubKey.armor()).keys[0]; + it('Write V4 signatures', async function() { + const pubKey = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const pubKey2 = (await openpgp.key.readArmored(pubKey.armor())).keys[0]; expect(pubKey2).to.exist; expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications); }); - it('Verify a detached signature using appendSignature', function() { + it('Verify a detached signature using appendSignature', async function() { const detachedSig = ['-----BEGIN PGP SIGNATURE-----', 'Version: GnuPG v1.4.13 (Darwin)', 'Comment: GPGTools - https://gpgtools.org', @@ -937,11 +936,11 @@ yYDnCgA= ''].join('\r\n'); const publicKeyArmored = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nVersion: OpenPGP.js v.1.20131116\r\nComment: Whiteout Mail - https://whiteout.io\r\n\r\nxsBNBFKODs4BB/9iOF4THsjQMY+WEpT7ShgKxj4bHzRRaQkqczS4nZvP0U3g\r\nqeqCnbpagyeKXA+bhWFQW4GmXtgAoeD5PXs6AZYrw3tWNxLKu2Oe6Tp9K/XI\r\nxTMQ2wl4qZKDXHvuPsJ7cmgaWqpPyXtxA4zHHS3WrkI/6VzHAcI/y6x4szSB\r\nKgSuhI3hjh3s7TybUC1U6AfoQGx/S7e3WwlCOrK8GTClirN/2mCPRC5wuIft\r\nnkoMfA6jK8d2OPrJ63shy5cgwHOjQg/xuk46dNS7tkvGmbaa+X0PgqSKB+Hf\r\nYPPNS/ylg911DH9qa8BqYU2QpNh9jUKXSF+HbaOM+plWkCSAL7czV+R3ABEB\r\nAAHNLVdoaXRlb3V0IFVzZXIgPHNhZmV3aXRobWUudGVzdHVzZXJAZ21haWwu\r\nY29tPsLAXAQQAQgAEAUCUo4O2gkQ1/uT/N+/wjwAAN2cB/9gFRmAfvEQ2qz+\r\nWubmT2EsSSnjPMxzG4uyykFoa+TaZCWo2Xa2tQghmU103kEkQb1OEjRjpgwJ\r\nYX9Kghnl8DByM686L5AXnRyHP78qRJCLXSXl0AGicboUDp5sovaa4rswQceH\r\nvcdWgZ/mgHTRoiQeJddy9k+H6MPFiyFaVcFwegVsmpc+dCcC8yT+qh8ZIbyG\r\nRJU60PmKKN7LUusP+8DbSv39zCGJCBlVVKyA4MzdF5uM+sqTdXbKzOrT5DGd\r\nCZaox4s+w16Sq1rHzZKFWfQPfKLDB9pyA0ufCVRA3AF6BUi7G3ZqhZiHNhMP\r\nNvE45V/hS1PbZcfPVoUjE2qc1Ix1\r\n=7Wpe\r\n-----END PGP PUBLIC KEY BLOCK-----'; - const publicKeys = openpgp.key.readArmored(publicKeyArmored).keys; + const publicKeys = (await openpgp.key.readArmored(publicKeyArmored)).keys; // Text const msg = openpgp.message.fromText(content); - msg.appendSignature(detachedSig); + await msg.appendSignature(detachedSig); return msg.verify(publicKeys).then(result => { expect(result[0].valid).to.be.true; }); @@ -949,8 +948,8 @@ yYDnCgA= it('Detached signature signing and verification', async function() { const msg = openpgp.message.fromText('hello'); - const pubKey2 = openpgp.key.readArmored(pub_key_arm2).keys[0]; - const privKey2 = openpgp.key.readArmored(priv_key_arm2).keys[0]; + const pubKey2 = (await openpgp.key.readArmored(pub_key_arm2)).keys[0]; + const privKey2 = (await openpgp.key.readArmored(priv_key_arm2)).keys[0]; await privKey2.decrypt('hello world'); const opt = {numBits: 512, userIds: { name:'test', email:'a@b.com' }, passphrase: null}; @@ -977,7 +976,7 @@ yYDnCgA= }); }); - it('Verify signed key', function() { + it('Verify signed key', async function() { const signedArmor = [ '-----BEGIN PGP PUBLIC KEY BLOCK-----', 'Version: GnuPG v1', @@ -1005,8 +1004,8 @@ yYDnCgA= '-----END PGP PUBLIC KEY BLOCK-----' ].join('\n'); - const signedKey = openpgp.key.readArmored(signedArmor).keys[0]; - const signerKey = openpgp.key.readArmored(priv_key_arm1).keys[0]; + const signedKey = (await openpgp.key.readArmored(signedArmor)).keys[0]; + const signerKey = (await openpgp.key.readArmored(priv_key_arm1)).keys[0]; return signedKey.verifyPrimaryUser([signerKey]).then(signatures => { expect(signatures[0].valid).to.be.null; expect(signatures[0].keyid.toHex()).to.equal(signedKey.getKeyId().toHex()); @@ -1040,7 +1039,7 @@ iTuGu4fEU1UligAXSrZmCdE= =VK6I -----END PGP PUBLIC KEY BLOCK-----`; - const key = openpgp.key.readArmored(armoredKeyWithPhoto).keys[0]; + const key = (await openpgp.key.readArmored(armoredKeyWithPhoto)).keys[0]; for (const user of key.users) { expect(await user.verify(key.primaryKey)).to.equal(openpgp.enums.keyStatus.valid); } diff --git a/test/general/streaming.js b/test/general/streaming.js index 2dfb62c7..782692a6 100644 --- a/test/general/streaming.js +++ b/test/general/streaming.js @@ -22,7 +22,7 @@ describe('Streaming', function() { passwords: ['test'], }); const msgAsciiArmored = util.Uint8Array_to_str(await encrypted.data.readToEnd()); - const message = openpgp.message.readArmored(msgAsciiArmored); + const message = await openpgp.message.readArmored(msgAsciiArmored); const decrypted = await openpgp.decrypt({ passwords: ['test'], message @@ -49,7 +49,7 @@ describe('Streaming', function() { passwords: ['test'], }); const msgAsciiArmored = util.Uint8Array_to_str(await encrypted.data.readToEnd()); - const message = openpgp.message.readArmored(msgAsciiArmored); + const message = await openpgp.message.readArmored(msgAsciiArmored); const decrypted = await openpgp.decrypt({ passwords: ['test'], message, diff --git a/test/general/x25519.js b/test/general/x25519.js index 1ee36bc5..93bea465 100644 --- a/test/general/x25519.js +++ b/test/general/x25519.js @@ -116,11 +116,11 @@ describe('X25519 Cryptography', function () { } }; - function load_pub_key(name) { + async function load_pub_key(name) { if (data[name].pub_key) { return data[name].pub_key; } - const pub = openpgp.key.readArmored(data[name].pub); + const pub = await openpgp.key.readArmored(data[name].pub); expect(pub).to.exist; expect(pub.err).to.not.exist; expect(pub.keys).to.have.length(1); @@ -133,7 +133,7 @@ describe('X25519 Cryptography', function () { if (data[name].priv_key) { return data[name].priv_key; } - const pk = openpgp.key.readArmored(data[name].priv); + const pk = await openpgp.key.readArmored(data[name].priv); expect(pk).to.exist; expect(pk.err).to.not.exist; expect(pk.keys).to.have.length(1); @@ -143,10 +143,9 @@ describe('X25519 Cryptography', function () { return data[name].priv_key; } - it('Load public key', function (done) { - load_pub_key('light'); - load_pub_key('night'); - done(); + it('Load public key', async function () { + await load_pub_key('light'); + await load_pub_key('night'); }); // This test is slow because the keys are generated by GPG2, which @@ -157,10 +156,10 @@ describe('X25519 Cryptography', function () { return true; }); - it('Verify clear signed message', function () { + it('Verify clear signed message', async function () { const name = 'light'; - const pub = load_pub_key(name); - const msg = openpgp.cleartext.readArmored(data[name].message_signed); + const pub = await load_pub_key(name); + const msg = await openpgp.cleartext.readArmored(data[name].message_signed); return openpgp.verify({ publicKeys: [pub], message: msg }).then(function(result) { expect(result).to.exist; expect(result.data).to.equal(data[name].message); @@ -174,8 +173,8 @@ describe('X25519 Cryptography', function () { const randomData = input.createSomeMessage(); const priv = await load_priv_key(name); const signed = await openpgp.sign({ privateKeys: [priv], data: randomData}); - const pub = load_pub_key(name); - const msg = openpgp.cleartext.readArmored(signed.data); + const pub = await load_pub_key(name); + const msg = await openpgp.cleartext.readArmored(signed.data); const result = await openpgp.verify({ publicKeys: [pub], message: msg}); expect(result).to.exist; @@ -185,9 +184,9 @@ describe('X25519 Cryptography', function () { }); it('Decrypt and verify message', async function () { - const light = load_pub_key('light'); + const light = await load_pub_key('light'); const night = await load_priv_key('night'); - const msg = openpgp.message.readArmored(data.night.message_encrypted); + const msg = await openpgp.message.readArmored(data.night.message_encrypted); const result = await openpgp.decrypt({ privateKeys: night, publicKeys: [light], message: msg }); expect(result).to.exist; @@ -197,13 +196,13 @@ describe('X25519 Cryptography', function () { }); it('Encrypt and sign message', async function () { - const nightPublic = load_pub_key('night'); + const nightPublic = await load_pub_key('night'); const lightPrivate = await load_priv_key('light'); const randomData = input.createSomeMessage(); const encrypted = await openpgp.encrypt({ publicKeys: [nightPublic], privateKeys: [lightPrivate], data: randomData }); - const message = openpgp.message.readArmored(encrypted.data); - const lightPublic = load_pub_key('light'); + const message = await openpgp.message.readArmored(encrypted.data); + const lightPublic = await load_pub_key('light'); const nightPrivate = await load_priv_key('night'); const result = await openpgp.decrypt({ privateKeys: nightPrivate, publicKeys: [lightPublic], message: message }); @@ -276,8 +275,8 @@ describe('X25519 Cryptography', function () { // Signing message openpgp.sign( { data: 'Hi, this is me, Hi!', privateKeys: hi } - ).then(signed => { - const msg = openpgp.cleartext.readArmored(signed.data); + ).then(async signed => { + const msg = await openpgp.cleartext.readArmored(signed.data); // Verifying signed message return Promise.all([ openpgp.verify( @@ -287,7 +286,7 @@ describe('X25519 Cryptography', function () { openpgp.verify( { message: openpgp.message.fromText('Hi, this is me, Hi!'), publicKeys: hi.toPublic(), - signature: openpgp.signature.readArmored(signed.data) } + signature: await openpgp.signature.readArmored(signed.data) } ).then(output => expect(output.signatures[0].valid).to.be.true) ]); }), @@ -296,8 +295,8 @@ describe('X25519 Cryptography', function () { { data: 'Hi, Hi wrote this but only Bye can read it!', publicKeys: [bye.toPublic()], privateKeys: [hi] } - ).then(encrypted => { - const msg = openpgp.message.readArmored(encrypted.data); + ).then(async encrypted => { + const msg = await openpgp.message.readArmored(encrypted.data); // Decrypting and verifying return openpgp.decrypt( { message: msg, @@ -533,7 +532,7 @@ describe('X25519 Cryptography', function () { 'Gbm1oe83ZB+0aSp5m34YkpHQNb80y8PGFy7nIexiAA==', '=xeG/', '-----END PGP PUBLIC KEY BLOCK-----'].join('\n'); - const hi = openpgp.key.readArmored(pubKey).keys[0]; + const hi = (await openpgp.key.readArmored(pubKey)).keys[0]; const results = hi.getPrimaryUser(); expect(results).to.exist; expect(results.user).to.exist; diff --git a/test/serviceworker.js b/test/serviceworker.js new file mode 100644 index 00000000..157fd0f5 --- /dev/null +++ b/test/serviceworker.js @@ -0,0 +1,47 @@ + + + + +// addEventListener('fetch', event => { +// console.log(event); +// const url = new URL(event.request.url); +// console.log(url); +// if (url.pathname === '/test/somedata') { +// let plaintext = []; +// let i = 0; +// let canceled = false; +// const data = new ReadableStream({ +// /*start(_controller) { +// controller = _controller; +// },*/ +// async pull(controller) { +// await new Promise(resolve => setTimeout(resolve, 1000)); +// console.log(i); +// if (i++ < 10) { +// let randomBytes = new Uint8Array(1000); +// randomBytes.fill(i); +// controller.enqueue(randomBytes); +// plaintext.push(randomBytes); +// } else { +// controller.close(); +// } +// }, +// cancel() { +// console.log('canceled!'); +// } +// }); + + +// const response = new Response(data, { +// headers: { +// 'Content-Type': 'application/octet-stream; charset=utf-8', +// 'Content-Disposition': 'Content-Disposition: attachment; filename=data.bin;' +// } +// }); + +// event.respondWith(response); +// } + +// }); + + \ No newline at end of file diff --git a/test/worker/async_proxy.js b/test/worker/async_proxy.js index 6c6d1c0b..f0324b8e 100644 --- a/test/worker/async_proxy.js +++ b/test/worker/async_proxy.js @@ -36,9 +36,9 @@ let pubKey; tryTests('Async Proxy', tests, { if: typeof window !== 'undefined' && window.Worker, - before: function() { + before: async function() { openpgp.initWorker({ path:'../dist/openpgp.worker.js' }); - pubKey = openpgp.key.readArmored(pub_key).keys[0]; + pubKey = (await openpgp.key.readArmored(pub_key)).keys[0]; }, after: function() { openpgp.destroyWorker();