Fetch Streams ponyfill on demand in lightweight build

This commit is contained in:
Daniel Huigens 2021-03-25 16:55:45 +01:00
parent 940ebba54f
commit 18ec54bf4b
34 changed files with 359 additions and 272 deletions

View File

@ -173,7 +173,7 @@ Encryption will use the algorithm specified in config.preferredSymmetricAlgorith
```js ```js
(async () => { (async () => {
const message = openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])); const message = await openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01]));
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message, // input as Message object message, // input as Message object
passwords: ['secret stuff'], // multiple passwords possible passwords: ['secret stuff'], // multiple passwords possible
@ -216,7 +216,7 @@ const openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via w
await privateKey.decrypt(passphrase); await privateKey.decrypt(passphrase);
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText('Hello, World!'), // input as Message object message: await openpgp.Message.fromText('Hello, World!'), // input as Message object
publicKeys: publicKey, // for encryption publicKeys: publicKey, // for encryption
privateKeys: privateKey // for signing (optional) privateKeys: privateKey // for signing (optional)
}); });
@ -257,7 +257,7 @@ Encrypt with multiple public keys:
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored }); const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase) await privateKey.decrypt(passphrase)
const message = openpgp.Message.fromText(message); const message = await openpgp.Message.fromText(message);
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message:, // input as Message object message:, // input as Message object
publicKeys, // for encryption publicKeys, // for encryption
@ -274,7 +274,7 @@ It's possible to change that behaviour by enabling compression through the confi
```js ```js
(async () => { (async () => {
const message = openpgp.Message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])); // or .fromText('string') const message = await openpgp.Message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])); // or .fromText('string')
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message, message,
passwords: ['secret stuff'], // multiple passwords possible passwords: ['secret stuff'], // multiple passwords possible
@ -306,7 +306,7 @@ Where the value can be any of:
} }
}); });
const message = openpgp.Message.fromBinary(readableStream); const message = await openpgp.Message.fromBinary(readableStream);
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message, // input as Message object message, // input as Message object
passwords: ['secret stuff'], // multiple passwords possible passwords: ['secret stuff'], // multiple passwords possible
@ -361,7 +361,7 @@ its [Reader class](https://openpgpjs.org/web-stream-tools/Reader.html).
}); });
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(readableStream), // input as Message object message: await openpgp.Message.fromText(readableStream), // input as Message object
publicKeys: publicKey, // for encryption publicKeys: publicKey, // for encryption
privateKeys: privateKey // for signing (optional) privateKeys: privateKey // for signing (optional)
}); });
@ -457,7 +457,7 @@ Using the private key:
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored }); const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase); await privateKey.decrypt(passphrase);
const unsignedMessage = openpgp.CleartextMessage.fromText('Hello, World!'); const unsignedMessage = await openpgp.CleartextMessage.fromText('Hello, World!');
const cleartextMessage = await openpgp.sign({ const cleartextMessage = await openpgp.sign({
message: unsignedMessage, // CleartextMessage or Message object message: unsignedMessage, // CleartextMessage or Message object
privateKeys: privateKey // for signing privateKeys: privateKey // for signing
@ -497,7 +497,7 @@ Using the private key:
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored }); const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase); await privateKey.decrypt(passphrase);
const cleartextMessage = openpgp.CleartextMessage.fromText('Hello, World!'); const cleartextMessage = await openpgp.CleartextMessage.fromText('Hello, World!');
const detachedSignature = await openpgp.sign({ const detachedSignature = await openpgp.sign({
message: cleartextMessage, // CleartextMessage or Message object message: cleartextMessage, // CleartextMessage or Message object
privateKeys: privateKey, // for signing privateKeys: privateKey, // for signing
@ -544,7 +544,7 @@ Using the private key:
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored }); const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt(passphrase); await privateKey.decrypt(passphrase);
const message = openpgp.Message.fromBinary(readableStream); // or .fromText(readableStream: ReadableStream<String>) const message = await openpgp.Message.fromBinary(readableStream); // or .fromText(readableStream: ReadableStream<String>)
const signatureArmored = await openpgp.sign({ const signatureArmored = await openpgp.sign({
message, message,
privateKeys: privateKey // for signing privateKeys: privateKey // for signing

6
package-lock.json generated
View File

@ -261,9 +261,9 @@
"dev": true "dev": true
}, },
"@openpgp/web-stream-tools": { "@openpgp/web-stream-tools": {
"version": "0.0.2", "version": "0.0.3",
"resolved": "https://registry.npmjs.org/@openpgp/web-stream-tools/-/web-stream-tools-0.0.2.tgz", "resolved": "https://registry.npmjs.org/@openpgp/web-stream-tools/-/web-stream-tools-0.0.3.tgz",
"integrity": "sha512-6RDYscGNmPEB/blocMH6bbyu4x0SXZKVHe1n1jHTonGyDJSMhPub99G+zFzRfXVjWamim2mXUPa7gfyK3tKJ7g==", "integrity": "sha512-AEcTCwFZSl6LMpFdDbOX1fv+9GwHpkF3h3DZagdFLPNE2yqx6ol6Rb/OnuMiKnpoGm09smCmNb+gHpcqp3Oz0Q==",
"dev": true, "dev": true,
"requires": { "requires": {
"@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.5", "@mattiasbuelens/web-streams-adapter": "0.1.0-alpha.5",

View File

@ -58,7 +58,7 @@
"@openpgp/pako": "^1.0.11", "@openpgp/pako": "^1.0.11",
"@openpgp/seek-bzip": "^1.0.5-git", "@openpgp/seek-bzip": "^1.0.5-git",
"@openpgp/tweetnacl": "^1.0.3", "@openpgp/tweetnacl": "^1.0.3",
"@openpgp/web-stream-tools": "0.0.2", "@openpgp/web-stream-tools": "0.0.3",
"@rollup/plugin-commonjs": "^11.1.0", "@rollup/plugin-commonjs": "^11.1.0",
"@rollup/plugin-node-resolve": "^7.1.3", "@rollup/plugin-node-resolve": "^7.1.3",
"@rollup/plugin-replace": "^2.3.2", "@rollup/plugin-replace": "^2.3.2",

View File

@ -124,8 +124,9 @@ export class CleartextMessage {
* Creates a new CleartextMessage object from text * Creates a new CleartextMessage object from text
* @param {String} text * @param {String} text
* @static * @static
* @async
*/ */
static fromText(text) { static async fromText(text) {
return new CleartextMessage(text); return new CleartextMessage(text);
} }
} }

View File

@ -12,7 +12,7 @@ import sha224 from 'hash.js/lib/hash/sha/224';
import sha384 from 'hash.js/lib/hash/sha/384'; import sha384 from 'hash.js/lib/hash/sha/384';
import sha512 from 'hash.js/lib/hash/sha/512'; import sha512 from 'hash.js/lib/hash/sha/512';
import { ripemd160 } from 'hash.js/lib/hash/ripemd'; import { ripemd160 } from 'hash.js/lib/hash/ripemd';
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import md5 from './md5'; import md5 from './md5';
import util from '../../util'; import util from '../../util';
import defaultConfig from '../../config'; import defaultConfig from '../../config';

View File

@ -24,7 +24,7 @@
import { AES_CFB } from '@openpgp/asmcrypto.js/dist_es8/aes/cfb'; import { AES_CFB } from '@openpgp/asmcrypto.js/dist_es8/aes/cfb';
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import * as cipher from '../cipher'; import * as cipher from '../cipher';
import util from '../../util'; import util from '../../util';

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import * as base64 from './base64.js'; import * as base64 from './base64.js';
import enums from '../enums.js'; import enums from '../enums.js';
import util from '../util'; import util from '../util';

View File

@ -16,7 +16,7 @@
* @private * @private
*/ */
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import util from '../util'; import util from '../util';
const Buffer = util.getNodeBuffer(); const Buffer = util.getNodeBuffer();

View File

@ -21,7 +21,8 @@ export { CleartextMessage, readCleartextMessage } from './cleartext';
export * from './packet'; export * from './packet';
export { default as stream } from '@openpgp/web-stream-tools'; import * as streamMod from '@openpgp/web-stream-tools'; // eslint-disable-line
export const stream = streamMod;
export * from './encoding/armor'; export * from './encoding/armor';

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import { armor, unarmor } from './encoding/armor'; import { armor, unarmor } from './encoding/armor';
import KeyID from './type/keyid'; import KeyID from './type/keyid';
import defaultConfig from './config'; import defaultConfig from './config';
@ -653,9 +653,13 @@ export class Message {
* @param {'utf8'|'binary'|'text'|'mime'} [type='utf8'] - Data packet type * @param {'utf8'|'binary'|'text'|'mime'} [type='utf8'] - Data packet type
* @returns {Message} New message object. * @returns {Message} New message object.
* @static * @static
* @async
*/ */
static fromText(text, filename, date = new Date(), type = 'utf8') { static async fromText(text, filename, date = new Date(), type = 'utf8') {
const streamType = util.isStream(text); const streamType = util.isStream(text);
if (streamType) {
await stream.loadStreamsPonyfill();
}
if (streamType === 'node') { if (streamType === 'node') {
text = stream.nodeToWeb(text); text = stream.nodeToWeb(text);
} }
@ -680,12 +684,16 @@ export class Message {
* @param {'utf8'|'binary'|'text'|'mime'} [type='binary'] - Data packet type * @param {'utf8'|'binary'|'text'|'mime'} [type='binary'] - Data packet type
* @returns {Message} New message object. * @returns {Message} New message object.
* @static * @static
* @async
*/ */
static fromBinary(bytes, filename, date = new Date(), type = 'binary') { static async fromBinary(bytes, filename, date = new Date(), type = 'binary') {
const streamType = util.isStream(bytes); const streamType = util.isStream(bytes);
if (!util.isUint8Array(bytes) && !streamType) { if (!util.isUint8Array(bytes) && !streamType) {
throw new Error('Data must be in the form of a Uint8Array or Stream'); throw new Error('Data must be in the form of a Uint8Array or Stream');
} }
if (streamType) {
await stream.loadStreamsPonyfill();
}
if (streamType === 'node') { if (streamType === 'node') {
bytes = stream.nodeToWeb(bytes); bytes = stream.nodeToWeb(bytes);
} }
@ -856,6 +864,9 @@ export async function readMessage({ armoredMessage, binaryMessage, config }) {
throw new Error('readMessage: must pass options object containing `armoredMessage` or `binaryMessage`'); throw new Error('readMessage: must pass options object containing `armoredMessage` or `binaryMessage`');
} }
const streamType = util.isStream(input); const streamType = util.isStream(input);
if (streamType) {
await stream.loadStreamsPonyfill();
}
if (streamType === 'node') { if (streamType === 'node') {
input = stream.nodeToWeb(input); input = stream.nodeToWeb(input);
} }

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter'; import { createReadableStreamWrapper } from '@mattiasbuelens/web-streams-adapter';
import { Message } from './message'; import { Message } from './message';
import { CleartextMessage } from './cleartext'; import { CleartextMessage } from './cleartext';

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums'; import enums from '../enums';
import util from '../util'; import util from '../util';

View File

@ -19,7 +19,7 @@ import { Deflate } from '@openpgp/pako/lib/deflate';
import { Inflate } from '@openpgp/pako/lib/inflate'; import { Inflate } from '@openpgp/pako/lib/inflate';
import { Z_SYNC_FLUSH, Z_FINISH } from '@openpgp/pako/lib/zlib/constants'; import { Z_SYNC_FLUSH, Z_FINISH } from '@openpgp/pako/lib/zlib/constants';
import { decode as BunzipDecode } from '@openpgp/seek-bzip'; import { decode as BunzipDecode } from '@openpgp/seek-bzip';
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import enums from '../enums'; import enums from '../enums';
import util from '../util'; import util from '../util';
import defaultConfig from '../config'; import defaultConfig from '../config';
@ -146,13 +146,19 @@ function uncompressed(data) {
return data; return data;
} }
function node_zlib(func, options = {}) { function node_zlib(func, create, options = {}) {
return function (data) { return function (data) {
const webStream = stream.nodeToWeb(stream.webToNode(data).pipe(func(options))); if (!util.isStream(data) || stream.isArrayStream(data)) {
if (stream.isStream(data) === 'array') { return stream.fromAsync(() => stream.readToEnd(data).then(data => {
return stream.fromAsync(() => stream.readToEnd(webStream)); return new Promise((resolve, reject) => {
func(data, options, (err, result) => {
if (err) return reject(err);
resolve(result);
});
});
}));
} }
return webStream; return stream.nodeToWeb(stream.webToNode(data).pipe(create(options)));
}; };
} }
@ -180,8 +186,8 @@ function bzip2(func) {
} }
const compress_fns = nodeZlib ? { const compress_fns = nodeZlib ? {
zip: /*#__PURE__*/ (compressed, level) => node_zlib(nodeZlib.createDeflateRaw, { level })(compressed), zip: /*#__PURE__*/ (compressed, level) => node_zlib(nodeZlib.deflateRaw, nodeZlib.createDeflateRaw, { level })(compressed),
zlib: /*#__PURE__*/ (compressed, level) => node_zlib(nodeZlib.createDeflate, { level })(compressed) zlib: /*#__PURE__*/ (compressed, level) => node_zlib(nodeZlib.deflate, nodeZlib.createDeflate, { level })(compressed)
} : { } : {
zip: /*#__PURE__*/ (compressed, level) => pako_zlib(Deflate, { raw: true, level })(compressed), zip: /*#__PURE__*/ (compressed, level) => pako_zlib(Deflate, { raw: true, level })(compressed),
zlib: /*#__PURE__*/ (compressed, level) => pako_zlib(Deflate, { level })(compressed) zlib: /*#__PURE__*/ (compressed, level) => pako_zlib(Deflate, { level })(compressed)
@ -189,8 +195,8 @@ const compress_fns = nodeZlib ? {
const decompress_fns = nodeZlib ? { const decompress_fns = nodeZlib ? {
uncompressed: uncompressed, uncompressed: uncompressed,
zip: /*#__PURE__*/ node_zlib(nodeZlib.createInflateRaw), zip: /*#__PURE__*/ node_zlib(nodeZlib.inflateRaw, nodeZlib.createInflateRaw),
zlib: /*#__PURE__*/ node_zlib(nodeZlib.createInflate), zlib: /*#__PURE__*/ node_zlib(nodeZlib.inflate, nodeZlib.createInflate),
bzip2: /*#__PURE__*/ bzip2(BunzipDecode) bzip2: /*#__PURE__*/ bzip2(BunzipDecode)
} : { } : {
uncompressed: uncompressed, uncompressed: uncompressed,

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import enums from '../enums'; import enums from '../enums';
import util from '../util'; import util from '../util';

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import SignaturePacket from './signature'; import SignaturePacket from './signature';
import KeyID from '../type/keyid'; import KeyID from '../type/keyid';
import enums from '../enums'; import enums from '../enums';

View File

@ -23,7 +23,7 @@
* @private * @private
*/ */
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import enums from '../enums'; import enums from '../enums';
import util from '../util'; import util from '../util';

View File

@ -1,4 +1,4 @@
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import { import {
readPackets, supportsStreaming, readPackets, supportsStreaming,
writeTag, writeHeader, writeTag, writeHeader,

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import { readSimpleLength, writeSimpleLength } from './packet'; import { readSimpleLength, writeSimpleLength } from './packet';
import KeyID from '../type/keyid.js'; import KeyID from '../type/keyid.js';
import crypto from '../crypto'; import crypto from '../crypto';

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums'; import enums from '../enums';
import util from '../util'; import util from '../util';

View File

@ -15,7 +15,7 @@
// License along with this library; if not, write to the Free Software // License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import crypto from '../crypto'; import crypto from '../crypto';
import enums from '../enums'; import enums from '../enums';
import util from '../util'; import util from '../util';

View File

@ -23,7 +23,7 @@
* @private * @private
*/ */
import stream from '@openpgp/web-stream-tools'; import * as stream from '@openpgp/web-stream-tools';
import { getBigInteger } from './biginteger'; import { getBigInteger } from './biginteger';
const debugMode = globalThis.process && globalThis.process.env.NODE_ENV === 'development'; const debugMode = globalThis.process && globalThis.process.env.NODE_ENV === 'development';

View File

@ -210,7 +210,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
}); });
it('Sign message', async function () { it('Sign message', async function () {
const romeoPrivate = await load_priv_key('romeo'); const romeoPrivate = await load_priv_key('romeo');
const signed = await openpgp.sign({ privateKeys: [romeoPrivate], message: openpgp.CleartextMessage.fromText(data.romeo.message) }); const signed = await openpgp.sign({ privateKeys: [romeoPrivate], message: await openpgp.CleartextMessage.fromText(data.romeo.message) });
const romeoPublic = await load_pub_key('romeo'); const romeoPublic = await load_pub_key('romeo');
const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed });
const result = await openpgp.verify({ publicKeys: [romeoPublic], message: msg }); const result = await openpgp.verify({ publicKeys: [romeoPublic], message: msg });
@ -260,7 +260,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
it('Encrypt and sign message', async function () { it('Encrypt and sign message', async function () {
const romeoPrivate = await load_priv_key('romeo'); const romeoPrivate = await load_priv_key('romeo');
const julietPublic = await load_pub_key('juliet'); const julietPublic = await load_pub_key('juliet');
const encrypted = await openpgp.encrypt({ publicKeys: [julietPublic], privateKeys: [romeoPrivate], message: openpgp.Message.fromText(data.romeo.message) }); const encrypted = await openpgp.encrypt({ publicKeys: [julietPublic], privateKeys: [romeoPrivate], message: await openpgp.Message.fromText(data.romeo.message) });
const message = await openpgp.readMessage({ armoredMessage: encrypted }); const message = await openpgp.readMessage({ armoredMessage: encrypted });
const romeoPublic = await load_pub_key('romeo'); const romeoPublic = await load_pub_key('romeo');
@ -290,21 +290,21 @@ function omnibus() {
const bye = secondKey.key; const bye = secondKey.key;
const pubBye = bye.toPublic(); const pubBye = bye.toPublic();
const cleartextMessage = await openpgp.sign({ message: openpgp.CleartextMessage.fromText(testData), privateKeys: hi }); const cleartextMessage = await openpgp.sign({ message: await openpgp.CleartextMessage.fromText(testData), privateKeys: hi });
await openpgp.verify({ await openpgp.verify({
message: await openpgp.readCleartextMessage({ cleartextMessage }), message: await openpgp.readCleartextMessage({ cleartextMessage }),
publicKeys: pubHi publicKeys: pubHi
}).then(output => expect(output.signatures[0].valid).to.be.true); }).then(output => expect(output.signatures[0].valid).to.be.true);
// Verifying detached signature // Verifying detached signature
await openpgp.verify({ await openpgp.verify({
message: openpgp.Message.fromText(util.removeTrailingSpaces(testData)), message: await openpgp.Message.fromText(util.removeTrailingSpaces(testData)),
publicKeys: pubHi, publicKeys: pubHi,
signature: (await openpgp.readCleartextMessage({ cleartextMessage })).signature signature: (await openpgp.readCleartextMessage({ cleartextMessage })).signature
}).then(output => expect(output.signatures[0].valid).to.be.true); }).then(output => expect(output.signatures[0].valid).to.be.true);
// Encrypting and signing // Encrypting and signing
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(testData2), message: await openpgp.Message.fromText(testData2),
publicKeys: [pubBye], publicKeys: [pubBye],
privateKeys: [hi] privateKeys: [hi]
}); });

View File

@ -149,7 +149,7 @@ module.exports = () => describe('Custom configuration', function() {
try { try {
const passwords = ['12345678']; const passwords = ['12345678'];
const message = openpgp.Message.fromText("test"); const message = await openpgp.Message.fromText("test");
const armored = await openpgp.encrypt({ message, passwords }); const armored = await openpgp.encrypt({ message, passwords });
const encrypted = await openpgp.readMessage({ armoredMessage: armored }); const encrypted = await openpgp.readMessage({ armoredMessage: armored });
@ -225,7 +225,7 @@ module.exports = () => describe('Custom configuration', function() {
const { privateKeyArmored } = await openpgp.generateKey({ userIDs }); const { privateKeyArmored } = await openpgp.generateKey({ userIDs });
const key = await openpgp.readKey({ armoredKey: privateKeyArmored }); const key = await openpgp.readKey({ armoredKey: privateKeyArmored });
const message = openpgp.Message.fromText("test"); const message = await openpgp.Message.fromText("test");
const opt = { const opt = {
message, message,
privateKeys: key, privateKeys: key,
@ -235,7 +235,7 @@ module.exports = () => describe('Custom configuration', function() {
opt.detached = true; opt.detached = true;
await expect(openpgp.sign(opt)).to.be.rejectedWith(/Insecure hash algorithm/); await expect(openpgp.sign(opt)).to.be.rejectedWith(/Insecure hash algorithm/);
const clearText = openpgp.CleartextMessage.fromText("test"); const clearText = await openpgp.CleartextMessage.fromText("test");
const opt2 = { const opt2 = {
message: clearText, message: clearText,
privateKeys: key, privateKeys: key,
@ -255,7 +255,7 @@ module.exports = () => describe('Custom configuration', function() {
const config = { rejectMessageHashAlgorithms: new Set([openpgp.enums.hash.sha256, openpgp.enums.hash.sha512]) }; const config = { rejectMessageHashAlgorithms: new Set([openpgp.enums.hash.sha256, openpgp.enums.hash.sha512]) };
const message = openpgp.Message.fromText("test"); const message = await openpgp.Message.fromText("test");
const signed = await openpgp.sign({ message, privateKeys: key }); const signed = await openpgp.sign({ message, privateKeys: key });
const opt = { const opt = {
message: await openpgp.readMessage({ armoredMessage: signed }), message: await openpgp.readMessage({ armoredMessage: signed }),
@ -274,7 +274,7 @@ module.exports = () => describe('Custom configuration', function() {
const { signatures: [sig2] } = await openpgp.verify(opt2); const { signatures: [sig2] } = await openpgp.verify(opt2);
await expect(sig2.error).to.match(/Insecure message hash algorithm/); await expect(sig2.error).to.match(/Insecure message hash algorithm/);
const cleartext = openpgp.CleartextMessage.fromText("test"); const cleartext = await openpgp.CleartextMessage.fromText("test");
const signedCleartext = await openpgp.sign({ message: cleartext, privateKeys: key }); const signedCleartext = await openpgp.sign({ message: cleartext, privateKeys: key });
const opt3 = { const opt3 = {
message: await openpgp.readCleartextMessage({ cleartextMessage: signedCleartext }), message: await openpgp.readCleartextMessage({ cleartextMessage: signedCleartext }),

View File

@ -20,21 +20,21 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
const bye = secondKey.key; const bye = secondKey.key;
const pubBye = bye.toPublic(); const pubBye = bye.toPublic();
const cleartextMessage = await openpgp.sign({ message: openpgp.CleartextMessage.fromText(testData), privateKeys: hi }); const cleartextMessage = await openpgp.sign({ message: await openpgp.CleartextMessage.fromText(testData), privateKeys: hi });
await openpgp.verify({ await openpgp.verify({
message: await openpgp.readCleartextMessage({ cleartextMessage }), message: await openpgp.readCleartextMessage({ cleartextMessage }),
publicKeys: pubHi publicKeys: pubHi
}).then(output => expect(output.signatures[0].valid).to.be.true); }).then(output => expect(output.signatures[0].valid).to.be.true);
// Verifying detached signature // Verifying detached signature
await openpgp.verify({ await openpgp.verify({
message: openpgp.Message.fromText(util.removeTrailingSpaces(testData)), message: await openpgp.Message.fromText(util.removeTrailingSpaces(testData)),
publicKeys: pubHi, publicKeys: pubHi,
signature: (await openpgp.readCleartextMessage({ cleartextMessage })).signature signature: (await openpgp.readCleartextMessage({ cleartextMessage })).signature
}).then(output => expect(output.signatures[0].valid).to.be.true); }).then(output => expect(output.signatures[0].valid).to.be.true);
// Encrypting and signing // Encrypting and signing
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(testData2), message: await openpgp.Message.fromText(testData2),
publicKeys: [pubBye], publicKeys: [pubBye],
privateKeys: [hi] privateKeys: [hi]
}); });
@ -56,7 +56,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
const testData = input.createSomeMessage(); const testData = input.createSomeMessage();
const options = { userIDs: { name: "Hi", email: "hi@hel.lo" }, curve: "p256" }; const options = { userIDs: { name: "Hi", email: "hi@hel.lo" }, curve: "p256" };
const firstKey = await openpgp.generateKey(options); const firstKey = await openpgp.generateKey(options);
const signature = await openpgp.sign({ message: openpgp.CleartextMessage.fromText(testData), privateKeys: firstKey.key }); const signature = await openpgp.sign({ message: await openpgp.CleartextMessage.fromText(testData), privateKeys: firstKey.key });
const msg = await openpgp.readCleartextMessage({ cleartextMessage: signature }); const msg = await openpgp.readCleartextMessage({ cleartextMessage: signature });
const result = await openpgp.verify({ message: msg, publicKeys: firstKey.key.toPublic() }); const result = await openpgp.verify({ message: msg, publicKeys: firstKey.key.toPublic() });
expect(result.signatures[0].valid).to.be.true; expect(result.signatures[0].valid).to.be.true;
@ -69,7 +69,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
options = { userIDs: { name: "Bye", email: "bye@good.bye" }, curve: "p256" }; options = { userIDs: { name: "Bye", email: "bye@good.bye" }, curve: "p256" };
const secondKey = await openpgp.generateKey(options); const secondKey = await openpgp.generateKey(options);
const encrypted = await openpgp.encrypt( const encrypted = await openpgp.encrypt(
{ message: openpgp.Message.fromText(testData), { message: await openpgp.Message.fromText(testData),
publicKeys: [secondKey.key.toPublic()], publicKeys: [secondKey.key.toPublic()],
privateKeys: [firstKey.key] } privateKeys: [firstKey.key] }
); );

View File

@ -184,7 +184,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
}); });
it('Sign message', async function () { it('Sign message', async function () {
const romeoPrivate = await load_priv_key('romeo'); const romeoPrivate = await load_priv_key('romeo');
const signed = await openpgp.sign({ privateKeys: [romeoPrivate], message: openpgp.CleartextMessage.fromText(data.romeo.message) }); const signed = await openpgp.sign({ privateKeys: [romeoPrivate], message: await openpgp.CleartextMessage.fromText(data.romeo.message) });
const romeoPublic = await load_pub_key('romeo'); const romeoPublic = await load_pub_key('romeo');
const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed });
const result = await openpgp.verify({ publicKeys: [romeoPublic], message: msg }); const result = await openpgp.verify({ publicKeys: [romeoPublic], message: msg });
@ -208,7 +208,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
it('Encrypt and sign message', async function () { it('Encrypt and sign message', async function () {
const romeoPrivate = await load_priv_key('romeo'); const romeoPrivate = await load_priv_key('romeo');
const julietPublic = await load_pub_key('juliet'); const julietPublic = await load_pub_key('juliet');
const encrypted = await openpgp.encrypt({ publicKeys: [julietPublic], privateKeys: [romeoPrivate], message: openpgp.Message.fromText(data.romeo.message) }); const encrypted = await openpgp.encrypt({ publicKeys: [julietPublic], privateKeys: [romeoPrivate], message: await openpgp.Message.fromText(data.romeo.message) });
const message = await openpgp.readMessage({ armoredMessage: encrypted }); const message = await openpgp.readMessage({ armoredMessage: encrypted });
const romeoPublic = await load_pub_key('romeo'); const romeoPublic = await load_pub_key('romeo');

View File

@ -2166,7 +2166,7 @@ function versionSpecificTests() {
const opt = { userIDs: { name: 'test', email: 'a@b.com' }, passphrase: '123' }; const opt = { userIDs: { name: 'test', email: 'a@b.com' }, passphrase: '123' };
const { key } = await openpgp.generateKey(opt); const { key } = await openpgp.generateKey(opt);
return openpgp.encrypt({ return openpgp.encrypt({
message: openpgp.Message.fromText('hello'), message: await openpgp.Message.fromText('hello'),
publicKeys: key publicKeys: key
}).then(async armoredMessage => openpgp.decrypt({ }).then(async armoredMessage => openpgp.decrypt({
message: await openpgp.readMessage({ armoredMessage }), message: await openpgp.readMessage({ armoredMessage }),
@ -2581,12 +2581,12 @@ function versionSpecificTests() {
const userID = { name: 'test', email: 'a@b.com' }; const userID = { name: 'test', email: 'a@b.com' };
const key = await openpgp.readKey({ armoredKey: key_without_subkey }); const key = await openpgp.readKey({ armoredKey: key_without_subkey });
const opt = { privateKey: key, userIDs: [userID] }; const opt = { privateKey: key, userIDs: [userID] };
return openpgp.reformatKey(opt).then(function(newKey) { return openpgp.reformatKey(opt).then(async function(newKey) {
newKey = newKey.key; newKey = newKey.key;
expect(newKey.users.length).to.equal(1); expect(newKey.users.length).to.equal(1);
expect(newKey.users[0].userID.userID).to.equal('test <a@b.com>'); expect(newKey.users[0].userID.userID).to.equal('test <a@b.com>');
expect(newKey.isDecrypted()).to.be.true; expect(newKey.isDecrypted()).to.be.true;
return openpgp.sign({ message: openpgp.CleartextMessage.fromText('hello'), privateKeys: newKey, armor: true }).then(async function(signed) { return openpgp.sign({ message: await openpgp.CleartextMessage.fromText('hello'), privateKeys: newKey, armor: true }).then(async function(signed) {
return openpgp.verify( return openpgp.verify(
{ message: await openpgp.readCleartextMessage({ cleartextMessage: signed }), publicKeys: newKey.toPublic() } { message: await openpgp.readCleartextMessage({ cleartextMessage: signed }), publicKeys: newKey.toPublic() }
).then(async function(verified) { ).then(async function(verified) {
@ -2628,9 +2628,9 @@ function versionSpecificTests() {
key = key.key; key = key.key;
opt.privateKey = key; opt.privateKey = key;
opt.userIDs = userID2; opt.userIDs = userID2;
return openpgp.reformatKey(opt).then(function(newKey) { return openpgp.reformatKey(opt).then(async function(newKey) {
newKey = newKey.key; newKey = newKey.key;
return openpgp.encrypt({ message: openpgp.Message.fromText('hello'), publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true }).then(async function(encrypted) { return openpgp.encrypt({ message: await openpgp.Message.fromText('hello'), publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true }).then(async function(encrypted) {
return openpgp.decrypt({ message: await openpgp.readMessage({ armoredMessage: encrypted }), privateKeys: newKey, publicKeys: newKey.toPublic() }).then(function(decrypted) { return openpgp.decrypt({ message: await openpgp.readMessage({ armoredMessage: encrypted }), privateKeys: newKey, publicKeys: newKey.toPublic() }).then(function(decrypted) {
expect(decrypted.data).to.equal('hello'); expect(decrypted.data).to.equal('hello');
expect(decrypted.signatures[0].valid).to.be.true; expect(decrypted.signatures[0].valid).to.be.true;
@ -3016,7 +3016,7 @@ module.exports = () => describe('Key', function() {
expect(key.primaryKey.isDummy()).to.be.false; expect(key.primaryKey.isDummy()).to.be.false;
key.primaryKey.makeDummy(); key.primaryKey.makeDummy();
expect(key.primaryKey.isDummy()).to.be.true; expect(key.primaryKey.isDummy()).to.be.true;
await expect(openpgp.sign({ message: openpgp.Message.fromText('test'), privateKeys: [key], config: { minRSABits: 1024 } })).to.be.fulfilled; await expect(openpgp.sign({ message: await openpgp.Message.fromText('test'), privateKeys: [key], config: { minRSABits: 1024 } })).to.be.fulfilled;
}); });
it('makeDummy() - should work for encrypted keys', async function() { it('makeDummy() - should work for encrypted keys', async function() {
@ -3423,10 +3423,10 @@ VYGdb3eNlV8CfoEC
expect(sessionKey.algorithm).to.equal('aes128'); expect(sessionKey.algorithm).to.equal('aes128');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
await openpgp.encrypt({ await openpgp.encrypt({
message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIDs: { name: 'Test User', email: 'b@c.com' }, armor: false, config message: await openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIDs: { name: 'Test User', email: 'b@c.com' }, armor: false, config
}); });
await expect(openpgp.encrypt({ await expect(openpgp.encrypt({
message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIDs: { name: 'Test User', email: 'c@c.com' }, armor: false, config message: await openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIDs: { name: 'Test User', email: 'c@c.com' }, armor: false, config
})).to.be.rejectedWith('Could not find user that matches that user ID'); })).to.be.rejectedWith('Could not find user that matches that user ID');
}); });
@ -3435,7 +3435,7 @@ VYGdb3eNlV8CfoEC
expect(publicKey.users.length).to.equal(0); expect(publicKey.users.length).to.equal(0);
const privateKey = await openpgp.readKey({ armoredKey: uidlessKey }); const privateKey = await openpgp.readKey({ armoredKey: uidlessKey });
await privateKey.decrypt('correct horse battery staple'); await privateKey.decrypt('correct horse battery staple');
await expect(openpgp.encrypt({ message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false })).to.be.rejectedWith('Could not find primary user'); await expect(openpgp.encrypt({ message: await openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false })).to.be.rejectedWith('Could not find primary user');
}); });
it('Sign - specific user', async function() { it('Sign - specific user', async function() {
@ -3453,17 +3453,17 @@ VYGdb3eNlV8CfoEC
privateKey.users[1].selfCertifications[0].preferredHashAlgorithms = [openpgp.enums.hash.sha512]; privateKey.users[1].selfCertifications[0].preferredHashAlgorithms = [openpgp.enums.hash.sha512];
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromText('hello'), privateKeys: privateKey, fromUserIDs: { name: 'Test McTestington', email: 'test@example.com' }, armor: false, config message: await openpgp.Message.fromText('hello'), privateKeys: privateKey, fromUserIDs: { name: 'Test McTestington', email: 'test@example.com' }, armor: false, config
}); });
const signature = await openpgp.readMessage({ binaryMessage: signed }); const signature = await openpgp.readMessage({ binaryMessage: signed });
expect(signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512); expect(signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText('hello'), passwords: 'test', privateKeys: privateKey, fromUserIDs: { name: 'Test McTestington', email: 'test@example.com' }, armor: false, config message: await openpgp.Message.fromText('hello'), passwords: 'test', privateKeys: privateKey, fromUserIDs: { name: 'Test McTestington', email: 'test@example.com' }, armor: false, config
}); });
const { signatures } = await openpgp.decrypt({ message: await openpgp.readMessage({ binaryMessage: encrypted }), passwords: 'test' }); const { signatures } = await openpgp.decrypt({ message: await openpgp.readMessage({ binaryMessage: encrypted }), passwords: 'test' });
expect(signatures[0].signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512); expect(signatures[0].signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
await expect(openpgp.encrypt({ await expect(openpgp.encrypt({
message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIDs: { name: 'Not Test McTestington', email: 'test@example.com' }, armor: false, config message: await openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIDs: { name: 'Not Test McTestington', email: 'test@example.com' }, armor: false, config
})).to.be.rejectedWith('Could not find user that matches that user ID'); })).to.be.rejectedWith('Could not find user that matches that user ID');
}); });
@ -3499,7 +3499,7 @@ VYGdb3eNlV8CfoEC
it('Reject encryption with revoked primary user', async function() { it('Reject encryption with revoked primary user', async function() {
const key = await openpgp.readKey({ armoredKey: pub_revoked_subkeys }); const key = await openpgp.readKey({ armoredKey: pub_revoked_subkeys });
return openpgp.encrypt({ publicKeys: [key], message: openpgp.Message.fromText('random data') }).then(() => { return openpgp.encrypt({ publicKeys: [key], message: await openpgp.Message.fromText('random data') }).then(() => {
throw new Error('encryptSessionKey should not encrypt with revoked public key'); throw new Error('encryptSessionKey should not encrypt with revoked public key');
}).catch(function(error) { }).catch(function(error) {
expect(error.message).to.equal('Error encrypting message: Primary user is revoked'); expect(error.message).to.equal('Error encrypting message: Primary user is revoked');
@ -3510,7 +3510,7 @@ VYGdb3eNlV8CfoEC
const key = await openpgp.readKey({ armoredKey: pub_revoked_subkeys }); const key = await openpgp.readKey({ armoredKey: pub_revoked_subkeys });
key.revocationSignatures = []; key.revocationSignatures = [];
key.users[0].revocationSignatures = []; key.users[0].revocationSignatures = [];
return openpgp.encrypt({ publicKeys: [key], message: openpgp.Message.fromText('random data'), date: new Date(1386842743000) }).then(() => { return openpgp.encrypt({ publicKeys: [key], message: await openpgp.Message.fromText('random data'), date: new Date(1386842743000) }).then(() => {
throw new Error('encryptSessionKey should not encrypt with revoked public key'); throw new Error('encryptSessionKey should not encrypt with revoked public key');
}).catch(function(error) { }).catch(function(error) {
expect(error.message).to.equal('Error encrypting message: Could not find valid encryption key packet in key ' + key.getKeyID().toHex() + ': Subkey is revoked'); expect(error.message).to.equal('Error encrypting message: Could not find valid encryption key packet in key ' + key.getKeyID().toHex() + ': Subkey is revoked');
@ -3519,7 +3519,7 @@ VYGdb3eNlV8CfoEC
it('Reject encryption with key revoked with appended revocation cert', async function() { it('Reject encryption with key revoked with appended revocation cert', async function() {
const key = await openpgp.readKey({ armoredKey: pub_revoked_with_cert }); const key = await openpgp.readKey({ armoredKey: pub_revoked_with_cert });
return openpgp.encrypt({ publicKeys: [key], message: openpgp.Message.fromText('random data') }).then(() => { return openpgp.encrypt({ publicKeys: [key], message: await openpgp.Message.fromText('random data') }).then(() => {
throw new Error('encryptSessionKey should not encrypt with revoked public key'); throw new Error('encryptSessionKey should not encrypt with revoked public key');
}).catch(function(error) { }).catch(function(error) {
expect(error.message).to.equal('Error encrypting message: Primary key is revoked'); expect(error.message).to.equal('Error encrypting message: Primary key is revoked');
@ -3734,7 +3734,7 @@ VYGdb3eNlV8CfoEC
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('eddsa'); expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('eddsa');
await subKey.verify(newPrivateKey.primaryKey); await subKey.verify(newPrivateKey.primaryKey);
expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey); expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey);
const signed = await openpgp.sign({ message: openpgp.Message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false }); const signed = await openpgp.sign({ message: await openpgp.Message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false });
const message = await openpgp.readMessage({ binaryMessage: signed }); const message = await openpgp.readMessage({ binaryMessage: signed });
const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] }); const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] });
expect(signatures).to.exist; expect(signatures).to.exist;
@ -3756,7 +3756,7 @@ VYGdb3eNlV8CfoEC
const publicKey = newPrivateKey.toPublic(); const publicKey = newPrivateKey.toPublic();
await subKey.verify(newPrivateKey.primaryKey); await subKey.verify(newPrivateKey.primaryKey);
expect(await newPrivateKey.getEncryptionKey()).to.be.equal(subKey); expect(await newPrivateKey.getEncryptionKey()).to.be.equal(subKey);
const encrypted = await openpgp.encrypt({ message: openpgp.Message.fromText(vData), publicKeys: publicKey, armor:false }); const encrypted = await openpgp.encrypt({ message: await openpgp.Message.fromText(vData), publicKeys: publicKey, armor:false });
expect(encrypted).to.be.exist; expect(encrypted).to.be.exist;
const message = await openpgp.readMessage({ binaryMessage: encrypted }); const message = await openpgp.readMessage({ binaryMessage: encrypted });
const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey); const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
@ -3780,7 +3780,7 @@ VYGdb3eNlV8CfoEC
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('rsaEncryptSign'); expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('rsaEncryptSign');
await subKey.verify(newPrivateKey.primaryKey); await subKey.verify(newPrivateKey.primaryKey);
expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey); expect(await newPrivateKey.getSigningKey()).to.be.equal(subKey);
const signed = await openpgp.sign({ message: openpgp.Message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false }); const signed = await openpgp.sign({ message: await openpgp.Message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false });
const message = await openpgp.readMessage({ binaryMessage: signed }); const message = await openpgp.readMessage({ binaryMessage: signed });
const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] }); const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] });
expect(signatures).to.exist; expect(signatures).to.exist;
@ -3800,7 +3800,7 @@ VYGdb3eNlV8CfoEC
const publicKey = newPrivateKey.toPublic(); const publicKey = newPrivateKey.toPublic();
const vData = 'the data to encrypted!'; const vData = 'the data to encrypted!';
expect(await newPrivateKey.getEncryptionKey()).to.be.equal(subKey); expect(await newPrivateKey.getEncryptionKey()).to.be.equal(subKey);
const encrypted = await openpgp.encrypt({ message: openpgp.Message.fromText(vData), publicKeys: publicKey, armor:false }); const encrypted = await openpgp.encrypt({ message: await openpgp.Message.fromText(vData), publicKeys: publicKey, armor:false });
expect(encrypted).to.be.exist; expect(encrypted).to.be.exist;
const message = await openpgp.readMessage({ binaryMessage: encrypted }); const message = await openpgp.readMessage({ binaryMessage: encrypted });
const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey); const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);

View File

@ -864,14 +864,14 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const commentStringVal = openpgp.config.commentString; const commentStringVal = openpgp.config.commentString;
try { try {
const encryptedDefault = await openpgp.encrypt({ publicKeys:publicKey, message:openpgp.Message.fromText(plaintext) }); const encryptedDefault = await openpgp.encrypt({ publicKeys:publicKey, message:await openpgp.Message.fromText(plaintext) });
expect(encryptedDefault).to.exist; expect(encryptedDefault).to.exist;
expect(encryptedDefault).not.to.match(/^Version:/); expect(encryptedDefault).not.to.match(/^Version:/);
expect(encryptedDefault).not.to.match(/^Comment:/); expect(encryptedDefault).not.to.match(/^Comment:/);
openpgp.config.showComment = true; openpgp.config.showComment = true;
openpgp.config.commentString = 'different'; openpgp.config.commentString = 'different';
const encryptedWithComment = await openpgp.encrypt({ publicKeys:publicKey, message:openpgp.Message.fromText(plaintext) }); const encryptedWithComment = await openpgp.encrypt({ publicKeys:publicKey, message:await openpgp.Message.fromText(plaintext) });
expect(encryptedWithComment).to.exist; expect(encryptedWithComment).to.exist;
expect(encryptedWithComment).not.to.match(/^Version:/); expect(encryptedWithComment).not.to.match(/^Version:/);
expect(encryptedWithComment).to.match(/Comment: different/); expect(encryptedWithComment).to.match(/Comment: different/);
@ -1019,7 +1019,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('Calling decrypt with not decrypted key leads to exception', async function() { it('Calling decrypt with not decrypted key leads to exception', async function() {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}; };
const decOpt = { const decOpt = {
@ -1147,7 +1147,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with pgp key pair', async function () { it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with pgp key pair', async function () {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}); });
const decryptedSessionKeys = await openpgp.decryptSessionKeys({ const decryptedSessionKeys = await openpgp.decryptSessionKeys({
@ -1164,7 +1164,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with pgp key pair -- trailing spaces', async function () { it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with pgp key pair -- trailing spaces', async function () {
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t '; const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}); });
const decryptedSessionKeys = await openpgp.decryptSessionKeys({ const decryptedSessionKeys = await openpgp.decryptSessionKeys({
@ -1180,7 +1180,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with password', async function () { it('roundtrip workflow: encrypt, decryptSessionKeys, decrypt with password', async function () {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: password1 passwords: password1
}); });
const decryptedSessionKeys = await openpgp.decryptSessionKeys({ const decryptedSessionKeys = await openpgp.decryptSessionKeys({
@ -1196,7 +1196,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('roundtrip workflow: encrypt with multiple passwords, decryptSessionKeys, decrypt with multiple passwords', async function () { it('roundtrip workflow: encrypt with multiple passwords, decryptSessionKeys, decrypt with multiple passwords', async function () {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: [password1, password2] passwords: [password1, password2]
}); });
const decryptedSessionKeys = await openpgp.decryptSessionKeys({ const decryptedSessionKeys = await openpgp.decryptSessionKeys({
@ -1212,7 +1212,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('roundtrip workflow: encrypt twice with one password, decryptSessionKeys, only one session key', async function () { it('roundtrip workflow: encrypt twice with one password, decryptSessionKeys, only one session key', async function () {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: [password1, password1] passwords: [password1, password1]
}); });
const decryptedSessionKeys = await openpgp.decryptSessionKeys({ const decryptedSessionKeys = await openpgp.decryptSessionKeys({
@ -1250,9 +1250,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
privateKey = decryptedPrivateKey; privateKey = decryptedPrivateKey;
}); });
it('should encrypt then decrypt', function () { it('should encrypt then decrypt', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}; };
const decOpt = { const decOpt = {
@ -1274,7 +1274,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
await privKeyDE.decrypt(passphrase); await privKeyDE.decrypt(passphrase);
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}; };
const decOpt = { const decOpt = {
@ -1291,9 +1291,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt then decrypt with wildcard', function () { it('should encrypt then decrypt with wildcard', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
wildcard: true wildcard: true
}; };
@ -1316,7 +1316,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
await privKeyDE.decrypt(passphrase); await privKeyDE.decrypt(passphrase);
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
wildcard: true wildcard: true
}; };
@ -1339,7 +1339,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
publicKeys: publicKey publicKeys: publicKey
}); });
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
sessionKey sessionKey
}); });
expect(encrypted).to.match(/^-----BEGIN PGP MESSAGE/); expect(encrypted).to.match(/^-----BEGIN PGP MESSAGE/);
@ -1358,7 +1358,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
algorithm: 'aes256' algorithm: 'aes256'
}; };
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
sessionKey: sessionKey, sessionKey: sessionKey,
publicKeys: publicKey publicKeys: publicKey
}; };
@ -1381,7 +1381,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
algorithm: 'aes128' algorithm: 'aes128'
}; };
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
sessionKey: sessionKey, sessionKey: sessionKey,
publicKeys: publicKey publicKeys: publicKey
}; };
@ -1398,9 +1398,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt/sign and decrypt/verify', function () { it('should encrypt/sign and decrypt/verify', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1421,9 +1421,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt/sign and decrypt/verify (no AEAD support)', function () { it('should encrypt/sign and decrypt/verify (no AEAD support)', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKeyNoAEAD, publicKeys: publicKeyNoAEAD,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1454,7 +1454,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const newPrivateKey = await openpgp.readKey({ armoredKey: newKey.privateKeyArmored }); const newPrivateKey = await openpgp.readKey({ armoredKey: newKey.privateKeyArmored });
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: newPublicKey, publicKeys: newPublicKey,
privateKeys: newPrivateKey privateKeys: newPrivateKey
}; };
@ -1484,11 +1484,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const newPrivateKey = await openpgp.readKey({ armoredKey: newKey.privateKeyArmored }); const newPrivateKey = await openpgp.readKey({ armoredKey: newKey.privateKeyArmored });
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: newPublicKey publicKeys: newPublicKey
}); });
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
privateKeys: newPrivateKey, privateKeys: newPrivateKey,
detached: true detached: true
}); });
@ -1507,9 +1507,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
expect(decrypted.signatures[0].signature.packets.length).to.equal(1); expect(decrypted.signatures[0].signature.packets.length).to.equal(1);
}); });
it('should encrypt/sign and decrypt/verify with null string input', function () { it('should encrypt/sign and decrypt/verify with null string input', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(''), message: await openpgp.Message.fromText(''),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1531,11 +1531,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should encrypt/sign and decrypt/verify with detached signatures', async function () { it('should encrypt/sign and decrypt/verify with detached signatures', async function () {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}); });
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
privateKeys: privateKey, privateKeys: privateKey,
detached: true detached: true
}); });
@ -1565,13 +1565,13 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const pubKeyDE = await openpgp.readKey({ armoredKey: pub_key_de }); const pubKeyDE = await openpgp.readKey({ armoredKey: pub_key_de });
const signOpt = { const signOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
privateKeys: privKeyDE, privateKeys: privKeyDE,
detached: true detached: true
}; };
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1606,13 +1606,13 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to encrypt and decrypt/verify with detached signature as input for encryption with wrong public key', async function () { it('should fail to encrypt and decrypt/verify with detached signature as input for encryption with wrong public key', async function () {
const signOpt = { const signOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
privateKeys: privateKey, privateKeys: privateKey,
detached: true detached: true
}; };
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}; };
@ -1639,7 +1639,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to verify decrypted data with wrong public pgp key', async function () { it('should fail to verify decrypted data with wrong public pgp key', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1662,7 +1662,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to verify decrypted null string with wrong public pgp key', async function () { it('should fail to verify decrypted null string with wrong public pgp key', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(''), message: await openpgp.Message.fromText(''),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1685,7 +1685,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should successfully decrypt signed message without public keys to verify', async function () { it('should successfully decrypt signed message without public keys to verify', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}; };
@ -1707,11 +1707,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to verify decrypted data with wrong public pgp key with detached signatures', async function () { it('should fail to verify decrypted data with wrong public pgp key with detached signatures', async function () {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey publicKeys: publicKey
}); });
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
privateKeys: privateKey, privateKeys: privateKey,
detached: true detached: true
}); });
@ -1740,7 +1740,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const pubKeyDE = await openpgp.readKey({ armoredKey: pub_key_de }); const pubKeyDE = await openpgp.readKey({ armoredKey: pub_key_de });
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: [privateKey, privKeyDE] privateKeys: [privateKey, privKeyDE]
}; };
@ -1773,7 +1773,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to decrypt modified message', async function() { it('should fail to decrypt modified message', async function() {
const { privateKeyArmored } = await openpgp.generateKey({ curve: 'curve25519', userIDs: [{ email: 'test@email.com' }] }); const { privateKeyArmored } = await openpgp.generateKey({ curve: 'curve25519', userIDs: [{ email: 'test@email.com' }] });
const key = await openpgp.readKey({ armoredKey: privateKeyArmored }); const key = await openpgp.readKey({ armoredKey: privateKeyArmored });
const data = await openpgp.encrypt({ message: openpgp.Message.fromBinary(new Uint8Array(500)), publicKeys: [key.toPublic()] }); const data = await openpgp.encrypt({ message: await openpgp.Message.fromBinary(new Uint8Array(500)), publicKeys: [key.toPublic()] });
let badSumEncrypted = data.replace(/\n=[a-zA-Z0-9/+]{4}/, '\n=aaaa'); let badSumEncrypted = data.replace(/\n=[a-zA-Z0-9/+]{4}/, '\n=aaaa');
if (badSumEncrypted === data) { // checksum was already =aaaa if (badSumEncrypted === data) { // checksum was already =aaaa
badSumEncrypted = data.replace(/\n=[a-zA-Z0-9/+]{4}/, '\n=bbbb'); badSumEncrypted = data.replace(/\n=[a-zA-Z0-9/+]{4}/, '\n=bbbb');
@ -1826,7 +1826,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to decrypt unarmored message with garbage data appended', async function() { it('should fail to decrypt unarmored message with garbage data appended', async function() {
const { key } = await openpgp.generateKey({ userIDs: {} }); const { key } = await openpgp.generateKey({ userIDs: {} });
const message = await openpgp.encrypt({ message: openpgp.Message.fromText('test'), publicKeys: key, privateKeys: key, armor: false }); const message = await openpgp.encrypt({ message: await openpgp.Message.fromText('test'), publicKeys: key, privateKeys: key, armor: false });
const encrypted = util.concat([message, new Uint8Array([11])]); const encrypted = util.concat([message, new Uint8Array([11])]);
await expect((async () => { await expect((async () => {
await openpgp.decrypt({ message: await openpgp.readMessage({ binaryMessage: encrypted }), privateKeys: key, publicKeys: key }); await openpgp.decrypt({ message: await openpgp.readMessage({ binaryMessage: encrypted }), privateKeys: key, publicKeys: key });
@ -1848,7 +1848,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
await openpgp.encrypt({ await openpgp.encrypt({
publicKeys: pubKeyDE, publicKeys: pubKeyDE,
privateKeys: privKeyDE, privateKeys: privKeyDE,
message: openpgp.Message.fromText(plaintext) message: await openpgp.Message.fromText(plaintext)
}).then(async function (encrypted) { }).then(async function (encrypted) {
return openpgp.decrypt({ return openpgp.decrypt({
privateKeys: privKeyDE, privateKeys: privKeyDE,
@ -1937,9 +1937,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
describe('AES encrypt, decrypt', function() { describe('AES encrypt, decrypt', function() {
it('should encrypt and decrypt with one password', function () { it('should encrypt and decrypt with one password', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: password1 passwords: password1
}; };
const decOpt = { const decOpt = {
@ -1954,9 +1954,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt and decrypt with two passwords', function () { it('should encrypt and decrypt with two passwords', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: [password1, password2] passwords: [password1, password2]
}; };
const decOpt = { const decOpt = {
@ -1971,9 +1971,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt and decrypt with password and not ascii armor', function () { it('should encrypt and decrypt with password and not ascii armor', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: password1, passwords: password1,
armor: false armor: false
}; };
@ -1989,9 +1989,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt and decrypt with binary data', function () { it('should encrypt and decrypt with binary data', async function () {
const encOpt = { const encOpt = {
message: openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])), message: await openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01])),
passwords: password1, passwords: password1,
armor: false armor: false
}; };
@ -2011,9 +2011,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
describe('Encrypt, decrypt with compression', function() { describe('Encrypt, decrypt with compression', function() {
withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) { withCompression(function (modifyCompressionEncryptOptions, verifyCompressionDecrypted) {
it('should encrypt and decrypt with one password', function () { it('should encrypt and decrypt with one password', async function () {
const encOpt = modifyCompressionEncryptOptions({ const encOpt = modifyCompressionEncryptOptions({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
passwords: password1 passwords: password1
}); });
const decOpt = { const decOpt = {
@ -2046,7 +2046,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
} }
}); });
const encrypted = await openpgp.encrypt(modifyCompressionEncryptOptions({ const encrypted = await openpgp.encrypt(modifyCompressionEncryptOptions({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
})); }));
expect(openpgp.stream.isStream(encrypted)).to.equal(useNativeStream ? 'web' : 'ponyfill'); expect(openpgp.stream.isStream(encrypted)).to.equal(useNativeStream ? 'web' : 'ponyfill');
@ -2087,8 +2087,8 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
privateKey = decryptedPrivateKey; privateKey = decryptedPrivateKey;
}); });
it('should sign and verify cleartext message', function () { it('should sign and verify cleartext message', async function () {
const message = openpgp.CleartextMessage.fromText(plaintext); const message = await openpgp.CleartextMessage.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: privateKey privateKeys: privateKey
@ -2117,7 +2117,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const privKeyDE = await openpgp.readKey({ armoredKey: priv_key_de }); const privKeyDE = await openpgp.readKey({ armoredKey: priv_key_de });
await privKeyDE.decrypt(passphrase); await privKeyDE.decrypt(passphrase);
const message = openpgp.CleartextMessage.fromText(plaintext); const message = await openpgp.CleartextMessage.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: [privateKey, privKeyDE] privateKeys: [privateKey, privKeyDE]
@ -2146,8 +2146,8 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
} }
}); });
it('should sign and verify data with detached signatures', function () { it('should sign and verify data with detached signatures', async function () {
const message = openpgp.Message.fromText(plaintext); const message = await openpgp.Message.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: privateKey, privateKeys: privateKey,
@ -2170,7 +2170,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
it('should sign and fail to verify cleartext message with wrong public pgp key', async function () { it('should sign and fail to verify cleartext message with wrong public pgp key', async function () {
const message = openpgp.CleartextMessage.fromText(plaintext); const message = await openpgp.CleartextMessage.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: privateKey privateKeys: privateKey
@ -2192,7 +2192,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
it('should sign and fail to verify data with wrong public pgp key with detached signature', async function () { it('should sign and fail to verify data with wrong public pgp key with detached signature', async function () {
const message = openpgp.Message.fromText(plaintext); const message = await openpgp.Message.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: privateKey, privateKeys: privateKey,
@ -2215,8 +2215,8 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign and verify data and not armor', function () { it('should sign and verify data and not armor', async function () {
const message = openpgp.Message.fromText(plaintext); const message = await openpgp.Message.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: privateKey, privateKeys: privateKey,
@ -2237,9 +2237,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign and verify data and not armor with detached signatures', function () { it('should sign and verify data and not armor with detached signatures', async function () {
const start = util.normalizeDate(); const start = util.normalizeDate();
const message = openpgp.Message.fromText(plaintext); const message = await openpgp.Message.fromText(plaintext);
const signOpt = { const signOpt = {
message, message,
privateKeys: privateKey, privateKeys: privateKey,
@ -2264,8 +2264,8 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign and verify data with a date in the past', function () { it('should sign and verify data with a date in the past', async function () {
const message = openpgp.Message.fromText(plaintext); const message = await openpgp.Message.fromText(plaintext);
const past = new Date(2000); const past = new Date(2000);
const signOpt = { const signOpt = {
message, message,
@ -2302,11 +2302,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign and verify binary data with a date in the future', function () { it('should sign and verify binary data with a date in the future', async function () {
const future = new Date(2040, 5, 5, 5, 5, 5, 0); const future = new Date(2040, 5, 5, 5, 5, 5, 0);
const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]); const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]);
const signOpt = { const signOpt = {
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privateKey_2038_2045, privateKeys: privateKey_2038_2045,
detached: true, detached: true,
date: future, date: future,
@ -2318,7 +2318,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
format: 'binary' format: 'binary'
}; };
return openpgp.sign(signOpt).then(async function (signed) { return openpgp.sign(signOpt).then(async function (signed) {
verifyOpt.message = openpgp.Message.fromBinary(data); verifyOpt.message = await openpgp.Message.fromBinary(data);
verifyOpt.signature = await openpgp.readSignature({ binarySignature: signed }); verifyOpt.signature = await openpgp.readSignature({ binarySignature: signed });
return openpgp.verify(verifyOpt); return openpgp.verify(verifyOpt);
}).then(async function (verified) { }).then(async function (verified) {
@ -2331,10 +2331,10 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign and verify binary data without one-pass signature', function () { it('should sign and verify binary data without one-pass signature', async function () {
const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]); const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]);
const signOpt = { const signOpt = {
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privateKey, privateKeys: privateKey,
armor: false armor: false
}; };
@ -2359,10 +2359,10 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should streaming sign and verify binary data without one-pass signature', function () { it('should streaming sign and verify binary data without one-pass signature', async function () {
const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]); const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]);
const signOpt = { const signOpt = {
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privateKey, privateKeys: privateKey,
armor: false, armor: false,
streaming: 'web' streaming: 'web'
@ -2392,10 +2392,10 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt and decrypt data with a date in the future', function () { it('should encrypt and decrypt data with a date in the future', async function () {
const future = new Date(2040, 5, 5, 5, 5, 5, 0); const future = new Date(2040, 5, 5, 5, 5, 5, 0);
const encryptOpt = { const encryptOpt = {
message: openpgp.Message.fromText(plaintext, undefined, future), message: await openpgp.Message.fromText(plaintext, undefined, future),
publicKeys: publicKey_2038_2045, publicKeys: publicKey_2038_2045,
date: future, date: future,
armor: false armor: false
@ -2412,11 +2412,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should encrypt and decrypt binary data with a date in the past', function () { it('should encrypt and decrypt binary data with a date in the past', async function () {
const past = new Date(2005, 5, 5, 5, 5, 5, 0); const past = new Date(2005, 5, 5, 5, 5, 5, 0);
const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]); const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]);
const encryptOpt = { const encryptOpt = {
message: openpgp.Message.fromBinary(data, undefined, past), message: await openpgp.Message.fromBinary(data, undefined, past),
publicKeys: publicKey_2000_2008, publicKeys: publicKey_2000_2008,
date: past, date: past,
armor: false armor: false
@ -2433,10 +2433,10 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign, encrypt and decrypt, verify data with a date in the past', function () { it('should sign, encrypt and decrypt, verify data with a date in the past', async function () {
const past = new Date(2005, 5, 5, 5, 5, 5, 0); const past = new Date(2005, 5, 5, 5, 5, 5, 0);
const encryptOpt = { const encryptOpt = {
message: openpgp.Message.fromText(plaintext, undefined, past), message: await openpgp.Message.fromText(plaintext, undefined, past),
publicKeys: publicKey_2000_2008, publicKeys: publicKey_2000_2008,
privateKeys: privateKey_2000_2008, privateKeys: privateKey_2000_2008,
date: past, date: past,
@ -2460,11 +2460,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign, encrypt and decrypt, verify binary data with a date in the future', function () { it('should sign, encrypt and decrypt, verify binary data with a date in the future', async function () {
const future = new Date(2040, 5, 5, 5, 5, 5, 0); const future = new Date(2040, 5, 5, 5, 5, 5, 0);
const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]); const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]);
const encryptOpt = { const encryptOpt = {
message: openpgp.Message.fromBinary(data, undefined, future), message: await openpgp.Message.fromBinary(data, undefined, future),
publicKeys: publicKey_2038_2045, publicKeys: publicKey_2038_2045,
privateKeys: privateKey_2038_2045, privateKeys: privateKey_2038_2045,
date: future, date: future,
@ -2489,11 +2489,11 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
}); });
}); });
it('should sign, encrypt and decrypt, verify mime data with a date in the future', function () { it('should sign, encrypt and decrypt, verify mime data with a date in the future', async function () {
const future = new Date(2040, 5, 5, 5, 5, 5, 0); const future = new Date(2040, 5, 5, 5, 5, 5, 0);
const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]); const data = new Uint8Array([3, 14, 15, 92, 65, 35, 59]);
const encryptOpt = { const encryptOpt = {
message: openpgp.Message.fromBinary(data, undefined, future, 'mime'), message: await openpgp.Message.fromBinary(data, undefined, future, 'mime'),
publicKeys: publicKey_2038_2045, publicKeys: publicKey_2038_2045,
privateKeys: privateKey_2038_2045, privateKeys: privateKey_2038_2045,
date: future, date: future,
@ -2521,9 +2521,9 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
it('should fail to encrypt with revoked key', function() { it('should fail to encrypt with revoked key', function() {
return openpgp.revokeKey({ return openpgp.revokeKey({
key: privateKey key: privateKey
}).then(function(revKey) { }).then(async function(revKey) {
return openpgp.encrypt({ return openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: revKey.publicKey publicKeys: revKey.publicKey
}).then(function() { }).then(function() {
throw new Error('Should not encrypt with revoked key'); throw new Error('Should not encrypt with revoked key');
@ -2537,10 +2537,10 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const pubKeyDE = await openpgp.readKey({ armoredKey: pub_key_de }); const pubKeyDE = await openpgp.readKey({ armoredKey: pub_key_de });
const privKeyDE = await openpgp.readKey({ armoredKey: priv_key_de }); const privKeyDE = await openpgp.readKey({ armoredKey: priv_key_de });
await privKeyDE.decrypt(passphrase); await privKeyDE.decrypt(passphrase);
return privKeyDE.subKeys[0].revoke(privKeyDE.primaryKey).then(function(revSubKey) { return privKeyDE.subKeys[0].revoke(privKeyDE.primaryKey).then(async function(revSubKey) {
pubKeyDE.subKeys[0] = revSubKey; pubKeyDE.subKeys[0] = revSubKey;
return openpgp.encrypt({ return openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: pubKeyDE, publicKeys: pubKeyDE,
config: { rejectPublicKeyAlgorithms: new Set() } config: { rejectPublicKeyAlgorithms: new Set() }
}).then(function() { }).then(function() {
@ -2556,7 +2556,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
const privKeyDE = await openpgp.readKey({ armoredKey: priv_key_de }); const privKeyDE = await openpgp.readKey({ armoredKey: priv_key_de });
await privKeyDE.decrypt(passphrase); await privKeyDE.decrypt(passphrase);
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: pubKeyDE, publicKeys: pubKeyDE,
config: { rejectPublicKeyAlgorithms: new Set() } config: { rejectPublicKeyAlgorithms: new Set() }
}); });
@ -2578,7 +2578,7 @@ module.exports = () => describe('OpenPGP.js public api tests', function() {
// validation will not check the decryption subkey and will succeed // validation will not check the decryption subkey and will succeed
await privKeyDE.decrypt(passphrase); await privKeyDE.decrypt(passphrase);
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(plaintext), message: await openpgp.Message.fromText(plaintext),
publicKeys: pubKeyDE, publicKeys: pubKeyDE,
config: { rejectPublicKeyAlgorithms: new Set() } config: { rejectPublicKeyAlgorithms: new Set() }
}); });
@ -2690,7 +2690,7 @@ amnR6g==
}); });
it('should normalize newlines in encrypted text message', async function() { it('should normalize newlines in encrypted text message', async function() {
const message = openpgp.Message.fromText('"BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\r\nUID:123\r\nDTSTART:20191211T121212Z\r\nDTEND:20191212T121212Z\r\nEND:VEVENT\nEND:VCALENDAR"'); const message = await openpgp.Message.fromText('"BEGIN:VCALENDAR\nVERSION:2.0\nBEGIN:VEVENT\r\nUID:123\r\nDTSTART:20191211T121212Z\r\nDTEND:20191212T121212Z\r\nEND:VEVENT\nEND:VCALENDAR"');
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
passwords: 'test', passwords: 'test',
message message
@ -2710,7 +2710,7 @@ amnR6g==
it(`sign/verify with ${curve}`, async function() { it(`sign/verify with ${curve}`, async function() {
const plaintext = 'short message'; const plaintext = 'short message';
const key = (await openpgp.generateKey({ curve, userIDs: { name: 'Alice', email: 'info@alice.com' } })).key; const key = (await openpgp.generateKey({ curve, userIDs: { name: 'Alice', email: 'info@alice.com' } })).key;
const signed = await openpgp.sign({ privateKeys:[key], message: openpgp.CleartextMessage.fromText(plaintext) }); const signed = await openpgp.sign({ privateKeys:[key], message: await openpgp.CleartextMessage.fromText(plaintext) });
const verified = await openpgp.verify({ publicKeys:[key], message: await openpgp.readCleartextMessage({ cleartextMessage: signed }) }); const verified = await openpgp.verify({ publicKeys:[key], message: await openpgp.readCleartextMessage({ cleartextMessage: signed }) });
expect(verified.signatures[0].valid).to.be.true; expect(verified.signatures[0].valid).to.be.true;
}); });
@ -2823,9 +2823,9 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ==
describe('Errors', function() { describe('Errors', function() {
it('Error message should contain the original error message', function() { it('Error message should contain the original error message', async function() {
return openpgp.encrypt({ return openpgp.encrypt({
message: openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])), message: await openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])),
passwords: null passwords: null
}).then(function() { }).then(function() {
throw new Error('Error expected.'); throw new Error('Error expected.');
@ -2858,7 +2858,7 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ==
for (let i = 0; i < encryptionKeyIDs.length; i++) { for (let i = 0; i < encryptionKeyIDs.length; i++) {
m = await openpgp.readMessage({ m = await openpgp.readMessage({
armoredMessage: await openpgp.encrypt({ armoredMessage: await openpgp.encrypt({
message: openpgp.Message.fromText("Hello World\n"), message: await openpgp.Message.fromText("Hello World\n"),
publicKeys: primaryKey, publicKeys: primaryKey,
encryptionKeyIDs: [encryptionKeyIDs[i]] encryptionKeyIDs: [encryptionKeyIDs[i]]
}) })
@ -2876,7 +2876,7 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ==
for (let i = 0; i < signingKeyIDs.length; i++) { for (let i = 0; i < signingKeyIDs.length; i++) {
s = await openpgp.readSignature({ s = await openpgp.readSignature({
armoredSignature: await openpgp.sign({ armoredSignature: await openpgp.sign({
message: openpgp.Message.fromText("Hello World\n"), message: await openpgp.Message.fromText("Hello World\n"),
privateKeys: primaryKey, privateKeys: primaryKey,
signingKeyIDs: [signingKeyIDs[i]], signingKeyIDs: [signingKeyIDs[i]],
detached: true detached: true
@ -2890,7 +2890,7 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ==
it('Encrypt and sign with specific encryption/signing key ids', async function () { it('Encrypt and sign with specific encryption/signing key ids', async function () {
const primaryKey = await getPrimaryKey(); const primaryKey = await getPrimaryKey();
const plaintextMessage = openpgp.Message.fromText("Hello World\n"); const plaintextMessage = await openpgp.Message.fromText("Hello World\n");
const checkEncryptedPackets = (encryptionKeyIDs, pKESKList) => { const checkEncryptedPackets = (encryptionKeyIDs, pKESKList) => {
pKESKList.forEach(({ publicKeyID }, i) => { pKESKList.forEach(({ publicKeyID }, i) => {

View File

@ -753,7 +753,7 @@ module.exports = () => describe("Packet", function() {
await Promise.all([ await Promise.all([
signature.verify(keyPacket, openpgp.enums.signature.binary, literal), signature.verify(keyPacket, openpgp.enums.signature.binary, literal),
openpgp.stream.pipe(literal.getBytes(), new openpgp.stream.WritableStream()) openpgp.stream.readToEnd(literal.getBytes())
]); ]);
}); });
}); });
@ -911,7 +911,7 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+
await Promise.all([ await Promise.all([
signed2[1].verify(key, openpgp.enums.signature.text, signed2[0]), signed2[1].verify(key, openpgp.enums.signature.text, signed2[0]),
openpgp.stream.pipe(signed2[0].getBytes(), new openpgp.stream.WritableStream()) openpgp.stream.readToEnd(signed2[0].getBytes())
]); ]);
}); });
}); });

View File

@ -882,7 +882,7 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
expect(msg.signatures[0].valid).to.be.true; expect(msg.signatures[0].valid).to.be.true;
expect(msg.signatures[0].signature.packets.length).to.equal(1); expect(msg.signatures[0].signature.packets.length).to.equal(1);
await expect(openpgp.sign({ await expect(openpgp.sign({
message: openpgp.Message.fromText('test'), privateKeys: [priv_key_gnupg_ext], config: { rejectPublicKeyAlgorithms: new Set() } message: await openpgp.Message.fromText('test'), privateKeys: [priv_key_gnupg_ext], config: { rejectPublicKeyAlgorithms: new Set() }
})).to.eventually.be.rejectedWith(/Cannot sign with a gnu-dummy key/); })).to.eventually.be.rejectedWith(/Cannot sign with a gnu-dummy key/);
await expect(openpgp.reformatKey({ userIDs: { name: 'test' }, privateKey: priv_key_gnupg_ext })).to.eventually.be.rejectedWith(/Cannot reformat a gnu-dummy primary key/); await expect(openpgp.reformatKey({ userIDs: { name: 'test' }, privateKey: priv_key_gnupg_ext })).to.eventually.be.rejectedWith(/Cannot reformat a gnu-dummy primary key/);
await expect(openpgp.reformatKey({ userIDs: { name: 'test' }, privateKey: priv_key_gnupg_ext_2, passphrase: 'test' })).to.eventually.be.rejectedWith(/Cannot reformat a gnu-dummy primary key/); await expect(openpgp.reformatKey({ userIDs: { name: 'test' }, privateKey: priv_key_gnupg_ext_2, passphrase: 'test' })).to.eventually.be.rejectedWith(/Cannot reformat a gnu-dummy primary key/);
@ -898,7 +898,7 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
it('Supports signing with GnuPG stripped-key extension', async function() { it('Supports signing with GnuPG stripped-key extension', async function() {
const priv_key_gnupg_ext = await openpgp.readKey({ armoredKey: flowcrypt_stripped_key }); const priv_key_gnupg_ext = await openpgp.readKey({ armoredKey: flowcrypt_stripped_key });
await priv_key_gnupg_ext.decrypt('FlowCrypt'); await priv_key_gnupg_ext.decrypt('FlowCrypt');
const sig = await openpgp.sign({ message: openpgp.Message.fromText('test'), privateKeys: [priv_key_gnupg_ext], date: new Date('2018-12-17T03:24:00') }); const sig = await openpgp.sign({ message: await openpgp.Message.fromText('test'), privateKeys: [priv_key_gnupg_ext], date: new Date('2018-12-17T03:24:00') });
expect(sig).to.match(/-----END PGP MESSAGE-----\n$/); expect(sig).to.match(/-----END PGP MESSAGE-----\n$/);
}); });
@ -939,7 +939,7 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
const sMsg = await openpgp.readMessage({ armoredMessage: signedArmor }); const sMsg = await openpgp.readMessage({ armoredMessage: signedArmor });
const pub_key = await openpgp.readKey({ armoredKey: pub_key_arm2 }); const pub_key = await openpgp.readKey({ armoredKey: pub_key_arm2 });
const verified = await sMsg.verify([pub_key]); const verified = await sMsg.verify([pub_key]);
openpgp.stream.pipe(sMsg.getLiteralData(), new openpgp.stream.WritableStream()); openpgp.stream.readToEnd(sMsg.getLiteralData());
expect(verified).to.exist; expect(verified).to.exist;
expect(verified).to.have.length(1); expect(verified).to.have.length(1);
expect(await verified[0].verified).to.be.true; expect(await verified[0].verified).to.be.true;
@ -1083,7 +1083,7 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
it('Verify latin-1 signed message', async function() { it('Verify latin-1 signed message', async function() {
const latin1Binary = util.hexToUint8Array('48e46c6cf62057e86c74'); const latin1Binary = util.hexToUint8Array('48e46c6cf62057e86c74');
const message = openpgp.Message.fromBinary(latin1Binary); const message = await openpgp.Message.fromBinary(latin1Binary);
message.appendSignature(`-----BEGIN PGP SIGNATURE----- message.appendSignature(`-----BEGIN PGP SIGNATURE-----
@ -1201,12 +1201,25 @@ yYDnCgA=
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t '; const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
const message = await openpgp.readMessage({ const message = await openpgp.readMessage({
armoredMessage: new openpgp.stream.ReadableStream({ armoredMessage: globalThis.ReadableStream ? new globalThis.ReadableStream({
async pull(controller) { async pull(controller) {
await new Promise(setTimeout); await new Promise(setTimeout);
controller.enqueue(armoredMessage.shift()); controller.enqueue(armoredMessage.shift());
if (!armoredMessage.length) controller.close(); if (!armoredMessage.length) controller.close();
} }
}) : new (require('stream').Readable)({
encoding: 'utf8',
async read() {
while (true) {
await new Promise(setTimeout);
if (!msg_armor.length) {
return this.push(null);
}
if (!this.push(msg_armor.shift())) {
break;
}
}
}
}) })
}); });
const pubKey = await openpgp.readKey({ armoredKey: pub_key_arm2 }); const pubKey = await openpgp.readKey({ armoredKey: pub_key_arm2 });
@ -1309,7 +1322,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.CleartextMessage.fromText(plaintext), config }).then(async function(signed) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.CleartextMessage.fromText(plaintext), config }).then(async function(signed) {
const message = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const message = await openpgp.readCleartextMessage({ cleartextMessage: signed });
return openpgp.verify({ publicKeys:[pubKey], message, config }); return openpgp.verify({ publicKeys:[pubKey], message, config });
@ -1329,7 +1342,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.CleartextMessage.fromText(plaintext), config }).then(async function(signed) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.CleartextMessage.fromText(plaintext), config }).then(async function(signed) {
const message = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const message = await openpgp.readCleartextMessage({ cleartextMessage: signed });
return openpgp.verify({ publicKeys:[pubKey], message, config }); return openpgp.verify({ publicKeys:[pubKey], message, config });
@ -1349,7 +1362,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.CleartextMessage.fromText(plaintext), config }).then(async function(signed) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.CleartextMessage.fromText(plaintext), config }).then(async function(signed) {
const message = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const message = await openpgp.readCleartextMessage({ cleartextMessage: signed });
return openpgp.verify({ publicKeys:[pubKey], message, config }); return openpgp.verify({ publicKeys:[pubKey], message, config });
@ -1369,7 +1382,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromBinary(plaintext), config }).then(async function(signed) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.Message.fromBinary(plaintext), config }).then(async function(signed) {
const message = await openpgp.readMessage({ armoredMessage: signed }); const message = await openpgp.readMessage({ armoredMessage: signed });
return openpgp.verify({ publicKeys:[pubKey], message, format: 'binary', config }); return openpgp.verify({ publicKeys:[pubKey], message, format: 'binary', config });
@ -1389,7 +1402,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromBinary(plaintext), armor:false, config }).then(async function(signed) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.Message.fromBinary(plaintext), armor:false, config }).then(async function(signed) {
const message = await openpgp.readMessage({ binaryMessage: signed }); const message = await openpgp.readMessage({ binaryMessage: signed });
return openpgp.verify({ publicKeys:[pubKey], message, format: 'binary', config }); return openpgp.verify({ publicKeys:[pubKey], message, format: 'binary', config });
@ -1409,9 +1422,9 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromText(plaintext), detached: true, config }).then(async function(armoredSignature) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.Message.fromText(plaintext), detached: true, config }).then(async function(armoredSignature) {
const signature = await openpgp.readSignature({ armoredSignature }); const signature = await openpgp.readSignature({ armoredSignature });
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.Message.fromBinary(util.encodeUTF8(plaintext)), signature, config }); return openpgp.verify({ publicKeys:[pubKey], message: await openpgp.Message.fromBinary(util.encodeUTF8(plaintext)), signature, config });
}).then(function({ data, signatures }) { }).then(function({ data, signatures }) {
expect(data).to.equal(plaintext); expect(data).to.equal(plaintext);
expect(signatures).to.have.length(1); expect(signatures).to.have.length(1);
@ -1428,9 +1441,9 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message:openpgp.Message.fromBinary(binaryPlaintext), detached: true, config }).then(async function(armoredSignature) { return openpgp.sign({ privateKeys:[privKey], message:await openpgp.Message.fromBinary(binaryPlaintext), detached: true, config }).then(async function(armoredSignature) {
const signature = await openpgp.readSignature({ armoredSignature }); const signature = await openpgp.readSignature({ armoredSignature });
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.Message.fromText(plaintext), signature, config }); return openpgp.verify({ publicKeys:[pubKey], message: await openpgp.Message.fromText(plaintext), signature, config });
}).then(function({ data, signatures }) { }).then(function({ data, signatures }) {
expect(data).to.equal(plaintext); expect(data).to.equal(plaintext);
expect(signatures).to.have.length(1); expect(signatures).to.have.length(1);
@ -1446,9 +1459,9 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
await privKey.decrypt('hello world'); await privKey.decrypt('hello world');
const config = { minRSABits: 1024 }; const config = { minRSABits: 1024 };
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromText(plaintext), detached: true, config }).then(async function(armoredSignature) { return openpgp.sign({ privateKeys:[privKey], message: await openpgp.Message.fromText(plaintext), detached: true, config }).then(async function(armoredSignature) {
const signature = await openpgp.readSignature({ armoredSignature }); const signature = await openpgp.readSignature({ armoredSignature });
return openpgp.encrypt({ message: openpgp.Message.fromBinary(util.encodeUTF8(plaintext)), publicKeys: [pubKey], signature, config }); return openpgp.encrypt({ message: await openpgp.Message.fromBinary(util.encodeUTF8(plaintext)), publicKeys: [pubKey], signature, config });
}).then(async armoredMessage => { }).then(async armoredMessage => {
const message = await openpgp.readMessage({ armoredMessage }); const message = await openpgp.readMessage({ armoredMessage });
@ -1565,7 +1578,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
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 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 publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored }); const publicKey = await openpgp.readKey({ armoredKey: publicKeyArmored });
const message = openpgp.Message.fromText(content); const message = await openpgp.Message.fromText(content);
await message.appendSignature(detachedSig); await message.appendSignature(detachedSig);
const { data, signatures } = await openpgp.verify({ publicKeys:[publicKey], message, config: { minRSABits: 1024 } }); const { data, signatures } = await openpgp.verify({ publicKeys:[publicKey], message, config: { minRSABits: 1024 } });
expect(data).to.equal(content); expect(data).to.equal(content);
@ -1576,7 +1589,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
}); });
it('Detached signature signing and verification', async function() { it('Detached signature signing and verification', async function() {
const message = openpgp.Message.fromText('hello'); const message = await openpgp.Message.fromText('hello');
const pubKey2 = await openpgp.readKey({ armoredKey: pub_key_arm2 }); const pubKey2 = await openpgp.readKey({ armoredKey: pub_key_arm2 });
const privKey2 = await openpgp.readKey({ armoredKey: priv_key_arm2 }); const privKey2 = await openpgp.readKey({ armoredKey: priv_key_arm2 });
await privKey2.decrypt('hello world'); await privKey2.decrypt('hello world');
@ -1593,9 +1606,9 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
it('Sign message with key without password', function() { it('Sign message with key without password', function() {
const opt = { userIDs: { name:'test', email:'a@b.com' }, passphrase: null }; const opt = { userIDs: { name:'test', email:'a@b.com' }, passphrase: null };
return openpgp.generateKey(opt).then(function(gen) { return openpgp.generateKey(opt).then(async function(gen) {
const key = gen.key; const key = gen.key;
const message = openpgp.Message.fromText('hello world'); const message = await openpgp.Message.fromText('hello world');
return message.sign([key]); return message.sign([key]);
}); });
}); });

View File

@ -1,5 +1,4 @@
/* eslint-disable max-lines */ /* eslint-disable max-lines */
/* globals tryTests: true */
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..'); const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..');
const random = require('../../src/crypto/random'); const random = require('../../src/crypto/random');
@ -16,6 +15,7 @@ const { stream } = openpgp;
const useNativeStream = (() => { try { new global.ReadableStream(); return true; } catch (e) { return false; } })(); // eslint-disable-line no-new const useNativeStream = (() => { try { new global.ReadableStream(); return true; } catch (e) { return false; } })(); // eslint-disable-line no-new
const ReadableStream = useNativeStream ? global.ReadableStream : openpgp.stream.ReadableStream; const ReadableStream = useNativeStream ? global.ReadableStream : openpgp.stream.ReadableStream;
const NodeReadableStream = useNativeStream ? undefined : require('stream').Readable;
const pub_key = [ const pub_key = [
'-----BEGIN PGP PUBLIC KEY BLOCK-----', '-----BEGIN PGP PUBLIC KEY BLOCK-----',
@ -182,15 +182,21 @@ let dataArrived;
function tests() { function tests() {
it('Encrypt small message', async function() { it('Encrypt small message', async function() {
dataArrived(); // Do not wait until data arrived. dataArrived(); // Do not wait until data arrived.
const data = new ReadableStream({ const data = ReadableStream ? new ReadableStream({
async start(controller) { start(controller) {
controller.enqueue(util.stringToUint8Array('hello ')); controller.enqueue(util.stringToUint8Array('hello '));
controller.enqueue(util.stringToUint8Array('world')); controller.enqueue(util.stringToUint8Array('world'));
controller.close(); controller.close();
} }
}) : new NodeReadableStream({
read() {
this.push(util.stringToUint8Array('hello '));
this.push(util.stringToUint8Array('world'));
this.push(null);
}
}); });
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
}); });
const msgAsciiArmored = await openpgp.stream.readToEnd(encrypted); const msgAsciiArmored = await openpgp.stream.readToEnd(encrypted);
@ -204,7 +210,7 @@ function tests() {
it('Encrypt larger message', async function() { it('Encrypt larger message', async function() {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
}); });
const reader = openpgp.stream.getReader(encrypted); const reader = openpgp.stream.getReader(encrypted);
@ -223,7 +229,7 @@ function tests() {
it('Input stream should be canceled when canceling encrypted stream', async function() { it('Input stream should be canceled when canceling encrypted stream', async function() {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
}); });
const reader = openpgp.stream.getReader(encrypted); const reader = openpgp.stream.getReader(encrypted);
@ -236,7 +242,7 @@ function tests() {
it('Sign: Input stream should be canceled when canceling encrypted stream', async function() { it('Sign: Input stream should be canceled when canceling encrypted stream', async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
@ -252,7 +258,7 @@ function tests() {
const aeadProtectValue = openpgp.config.aeadProtect; const aeadProtectValue = openpgp.config.aeadProtect;
openpgp.config.aeadProtect = false; openpgp.config.aeadProtect = false;
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'], passwords: ['test'],
armor: false armor: false
}); });
@ -280,7 +286,7 @@ function tests() {
openpgp.config.allowUnauthenticatedStream = true; openpgp.config.allowUnauthenticatedStream = true;
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'], passwords: ['test'],
armor: false armor: false
}); });
@ -310,7 +316,7 @@ function tests() {
openpgp.config.allowUnauthenticatedStream = true; openpgp.config.allowUnauthenticatedStream = true;
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
publicKeys: pubKey, publicKeys: pubKey,
privateKeys: privKey, privateKeys: privKey,
armor: false, armor: false,
@ -343,7 +349,7 @@ function tests() {
await priv.decrypt(xPass); await priv.decrypt(xPass);
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
publicKeys: pub, publicKeys: pub,
privateKeys: priv, privateKeys: priv,
armor: false armor: false
@ -375,7 +381,7 @@ function tests() {
await priv.decrypt(brainpoolPass); await priv.decrypt(brainpoolPass);
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
publicKeys: pub, publicKeys: pub,
privateKeys: priv, privateKeys: priv,
armor: false armor: false
@ -406,7 +412,7 @@ function tests() {
openpgp.config.allowUnauthenticatedStream = true; openpgp.config.allowUnauthenticatedStream = true;
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data, 'msg.bin'), message: await openpgp.Message.fromBinary(data, 'msg.bin'),
passwords: ['test'] passwords: ['test']
}); });
expect(openpgp.stream.isStream(encrypted)).to.equal(expectedType); expect(openpgp.stream.isStream(encrypted)).to.equal(expectedType);
@ -443,7 +449,7 @@ function tests() {
openpgp.config.allowUnauthenticatedStream = true; openpgp.config.allowUnauthenticatedStream = true;
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
publicKeys: pubKey, publicKeys: pubKey,
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
@ -481,7 +487,7 @@ function tests() {
openpgp.config.allowUnauthenticatedStream = true; openpgp.config.allowUnauthenticatedStream = true;
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
publicKeys: pubKey, publicKeys: pubKey,
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
@ -516,7 +522,7 @@ function tests() {
it('Sign/verify: Detect armor checksum error', async function() { it('Sign/verify: Detect armor checksum error', async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
@ -572,7 +578,7 @@ function tests() {
it('Sign/verify: Input stream should be canceled when canceling verified stream', async function() { it('Sign/verify: Input stream should be canceled when canceling verified stream', async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
@ -598,7 +604,7 @@ function tests() {
it("Don't pull entire input stream when we're not pulling encrypted stream", async function() { it("Don't pull entire input stream when we're not pulling encrypted stream", async function() {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
}); });
expect(openpgp.stream.isStream(encrypted)).to.equal(expectedType); expect(openpgp.stream.isStream(encrypted)).to.equal(expectedType);
@ -612,7 +618,7 @@ function tests() {
it("Sign: Don't pull entire input stream when we're not pulling signed stream", async function() { it("Sign: Don't pull entire input stream when we're not pulling signed stream", async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
@ -627,7 +633,7 @@ function tests() {
it("Sign/verify: Don't pull entire input stream when we're not pulling verified stream", async function() { it("Sign/verify: Don't pull entire input stream when we're not pulling verified stream", async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
@ -643,20 +649,26 @@ function tests() {
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]); expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
dataArrived(); dataArrived();
await new Promise(resolve => setTimeout(resolve, 3000)); await new Promise(resolve => setTimeout(resolve, 3000));
expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 100); expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 250);
}); });
it('Detached sign small message', async function() { it('Detached sign small message', async function() {
dataArrived(); // Do not wait until data arrived. dataArrived(); // Do not wait until data arrived.
const data = new ReadableStream({ const data = ReadableStream ? new ReadableStream({
async start(controller) { start(controller) {
controller.enqueue(util.stringToUint8Array('hello ')); controller.enqueue(util.stringToUint8Array('hello '));
controller.enqueue(util.stringToUint8Array('world')); controller.enqueue(util.stringToUint8Array('world'));
controller.close(); controller.close();
} }
}) : new NodeReadableStream({
read() {
this.push(util.stringToUint8Array('hello '));
this.push(util.stringToUint8Array('world'));
this.push(null);
}
}); });
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
detached: true, detached: true,
streaming: expectedType, streaming: expectedType,
@ -668,7 +680,7 @@ function tests() {
const verified = await openpgp.verify({ const verified = await openpgp.verify({
signature, signature,
publicKeys: pubKey, publicKeys: pubKey,
message: openpgp.Message.fromText('hello world'), message: await openpgp.Message.fromText('hello world'),
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
expect(verified.data).to.equal('hello world'); expect(verified.data).to.equal('hello world');
@ -678,15 +690,21 @@ function tests() {
it('Detached sign small message (not streaming)', async function() { it('Detached sign small message (not streaming)', async function() {
dataArrived(); // Do not wait until data arrived. dataArrived(); // Do not wait until data arrived.
const data = new ReadableStream({ const data = ReadableStream ? new ReadableStream({
async start(controller) { start(controller) {
controller.enqueue(util.stringToUint8Array('hello ')); controller.enqueue(util.stringToUint8Array('hello '));
controller.enqueue(util.stringToUint8Array('world')); controller.enqueue(util.stringToUint8Array('world'));
controller.close(); controller.close();
} }
}) : new NodeReadableStream({
read() {
this.push(util.stringToUint8Array('hello '));
this.push(util.stringToUint8Array('world'));
this.push(null);
}
}); });
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
detached: true, detached: true,
streaming: false, streaming: false,
@ -698,7 +716,7 @@ function tests() {
const verified = await openpgp.verify({ const verified = await openpgp.verify({
signature, signature,
publicKeys: pubKey, publicKeys: pubKey,
message: openpgp.Message.fromText('hello world'), message: await openpgp.Message.fromText('hello world'),
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
}); });
expect(verified.data).to.equal('hello world'); expect(verified.data).to.equal('hello world');
@ -708,18 +726,24 @@ function tests() {
it('Detached sign small message using brainpool curve keys', async function() { it('Detached sign small message using brainpool curve keys', async function() {
dataArrived(); // Do not wait until data arrived. dataArrived(); // Do not wait until data arrived.
const data = new ReadableStream({ const data = ReadableStream ? new ReadableStream({
async start(controller) { start(controller) {
controller.enqueue(util.stringToUint8Array('hello ')); controller.enqueue(util.stringToUint8Array('hello '));
controller.enqueue(util.stringToUint8Array('world')); controller.enqueue(util.stringToUint8Array('world'));
controller.close(); controller.close();
} }
}) : new NodeReadableStream({
read() {
this.push(util.stringToUint8Array('hello '));
this.push(util.stringToUint8Array('world'));
this.push(null);
}
}); });
const priv = await openpgp.readKey({ armoredKey: brainpoolPriv }); const priv = await openpgp.readKey({ armoredKey: brainpoolPriv });
const pub = await openpgp.readKey({ armoredKey: brainpoolPub }); const pub = await openpgp.readKey({ armoredKey: brainpoolPub });
await priv.decrypt(brainpoolPass); await priv.decrypt(brainpoolPass);
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: priv, privateKeys: priv,
detached: true, detached: true,
streaming: expectedType streaming: expectedType
@ -730,7 +754,7 @@ function tests() {
const verified = await openpgp.verify({ const verified = await openpgp.verify({
signature, signature,
publicKeys: pub, publicKeys: pub,
message: openpgp.Message.fromText('hello world') message: await openpgp.Message.fromText('hello world')
}); });
expect(verified.data).to.equal('hello world'); expect(verified.data).to.equal('hello world');
expect(verified.signatures).to.exist.and.have.length(1); expect(verified.signatures).to.exist.and.have.length(1);
@ -739,18 +763,24 @@ function tests() {
it('Detached sign small message using x25519 curve keys', async function() { it('Detached sign small message using x25519 curve keys', async function() {
dataArrived(); // Do not wait until data arrived. dataArrived(); // Do not wait until data arrived.
const data = new ReadableStream({ const data = ReadableStream ? new ReadableStream({
async start(controller) { async start(controller) {
controller.enqueue(util.stringToUint8Array('hello ')); controller.enqueue(util.stringToUint8Array('hello '));
controller.enqueue(util.stringToUint8Array('world')); controller.enqueue(util.stringToUint8Array('world'));
controller.close(); controller.close();
} }
}) : new NodeReadableStream({
read() {
this.push(util.stringToUint8Array('hello '));
this.push(util.stringToUint8Array('world'));
this.push(null);
}
}); });
const priv = await openpgp.readKey({ armoredKey: xPriv }); const priv = await openpgp.readKey({ armoredKey: xPriv });
const pub = await openpgp.readKey({ armoredKey: xPub }); const pub = await openpgp.readKey({ armoredKey: xPub });
await priv.decrypt(xPass); await priv.decrypt(xPass);
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: priv, privateKeys: priv,
detached: true, detached: true,
streaming: expectedType streaming: expectedType
@ -761,7 +791,7 @@ function tests() {
const verified = await openpgp.verify({ const verified = await openpgp.verify({
signature, signature,
publicKeys: pub, publicKeys: pub,
message: openpgp.Message.fromText('hello world') message: await openpgp.Message.fromText('hello world')
}); });
expect(verified.data).to.equal('hello world'); expect(verified.data).to.equal('hello world');
expect(verified.signatures).to.exist.and.have.length(1); expect(verified.signatures).to.exist.and.have.length(1);
@ -770,7 +800,7 @@ function tests() {
it("Detached sign is expected to pull entire input stream when we're not pulling signed stream", async function() { it("Detached sign is expected to pull entire input stream when we're not pulling signed stream", async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
detached: true, detached: true,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
@ -780,12 +810,12 @@ function tests() {
expect((await reader.readBytes(30)).toString('utf8')).to.equal('-----BEGIN PGP SIGNATURE-----\n'); expect((await reader.readBytes(30)).toString('utf8')).to.equal('-----BEGIN PGP SIGNATURE-----\n');
dataArrived(); dataArrived();
await new Promise(resolve => setTimeout(resolve, 3000)); await new Promise(resolve => setTimeout(resolve, 3000));
expect(i).to.be.greaterThan(100); expect(i).to.equal(expectedType === 'web' ? 100 : 500);
}); });
it('Detached sign: Input stream should be canceled when canceling signed stream', async function() { it('Detached sign: Input stream should be canceled when canceling signed stream', async function() {
const signed = await openpgp.sign({ const signed = await openpgp.sign({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
privateKeys: privKey, privateKeys: privKey,
detached: true, detached: true,
config: { minRSABits: 1024 } config: { minRSABits: 1024 }
@ -816,7 +846,7 @@ function tests() {
it('Encrypt and decrypt larger message roundtrip (AEAD)', async function() { it('Encrypt and decrypt larger message roundtrip (AEAD)', async function() {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'], passwords: ['test'],
armor: false armor: false
}); });
@ -840,7 +870,7 @@ function tests() {
const plaintext = []; const plaintext = [];
let i = 0; let i = 0;
const data = new ReadableStream({ const data = ReadableStream ? new ReadableStream({
async pull(controller) { async pull(controller) {
await new Promise(resolve => setTimeout(resolve, 10)); await new Promise(resolve => setTimeout(resolve, 10));
if (i++ < 10) { if (i++ < 10) {
@ -851,9 +881,23 @@ function tests() {
controller.close(); controller.close();
} }
} }
}) : new NodeReadableStream({
encoding: 'utf8',
async read() {
while (true) {
await new Promise(resolve => setTimeout(resolve, 10));
if (i++ < 10) {
const randomData = input.createSomeMessage();
plaintext.push(randomData);
if (!this.push(randomData)) break;
} else {
return this.push(null);
}
}
}
}); });
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(data), message: await openpgp.Message.fromText(data),
streaming: expectedType, streaming: expectedType,
passwords: ['test'] passwords: ['test']
}); });
@ -883,7 +927,7 @@ function tests() {
} }
try { try {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
}); });
expect(openpgp.stream.isStream(encrypted)).to.equal(expectedType); expect(openpgp.stream.isStream(encrypted)).to.equal(expectedType);
@ -898,7 +942,7 @@ function tests() {
expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]); expect(await reader.readBytes(1024)).to.deep.equal(plaintext[0]);
dataArrived(); dataArrived();
await new Promise(resolve => setTimeout(resolve, 3000)); await new Promise(resolve => setTimeout(resolve, 3000));
expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 100); expect(i).to.be.lessThan(expectedType === 'web' ? 50 : 300);
} finally { } finally {
if (util.detectNode()) { if (util.detectNode()) {
coresStub.restore(); coresStub.restore();
@ -910,7 +954,7 @@ function tests() {
it('Input stream should be canceled when canceling decrypted stream (AEAD)', async function() { it('Input stream should be canceled when canceling decrypted stream (AEAD)', async function() {
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'] passwords: ['test']
}); });
@ -926,6 +970,7 @@ function tests() {
dataArrived(); dataArrived();
reader.releaseLock(); reader.releaseLock();
await openpgp.stream.cancel(decrypted.data, new Error('canceled by test')); await openpgp.stream.cancel(decrypted.data, new Error('canceled by test'));
await new Promise(setTimeout);
expect(canceled).to.be.true; expect(canceled).to.be.true;
}); });
}); });
@ -949,10 +994,11 @@ module.exports = () => describe('Streaming', function() {
plaintext = []; plaintext = [];
i = 0; i = 0;
canceled = false; canceled = false;
data = new ReadableStream({ data = ReadableStream ? new ReadableStream({
async pull(controller) { async pull(controller) {
await new Promise(setTimeout); await new Promise(setTimeout);
if (test === currentTest && i++ < 100) { if (test === currentTest && i < (expectedType === 'web' ? 100 : 500)) {
i++;
if (i === 4) await dataArrivedPromise; if (i === 4) await dataArrivedPromise;
const randomBytes = await random.getRandomBytes(1024); const randomBytes = await random.getRandomBytes(1024);
controller.enqueue(randomBytes); controller.enqueue(randomBytes);
@ -964,23 +1010,32 @@ module.exports = () => describe('Streaming', function() {
cancel() { cancel() {
canceled = true; canceled = true;
} }
}, new ByteLengthQueuingStrategy({
highWaterMark: 1024
})) : new NodeReadableStream({
highWaterMark: 1024,
async read() {
while (true) {
await new Promise(setTimeout);
if (test === currentTest && i < (expectedType === 'web' ? 100 : 500)) {
i++;
if (i === 4) await dataArrivedPromise;
const randomBytes = await random.getRandomBytes(1024);
plaintext.push(randomBytes);
if (!this.push(randomBytes)) break;
} else {
return this.push(null);
}
}
},
destroy() {
canceled = true;
}
}); });
expectedType = ReadableStream ? 'web' : 'node';
}); });
tryTests('WhatWG Streams', tests, { tests();
if: true,
beforeEach: function() {
expectedType = useNativeStream ? 'web' : 'ponyfill';
}
});
tryTests('Node Streams', tests, {
if: util.detectNode(),
beforeEach: function() {
data = openpgp.stream.webToNode(data);
expectedType = 'node';
}
});
if (util.detectNode()) { if (util.detectNode()) {
const fs = require('fs'); const fs = require('fs');
@ -990,7 +1045,7 @@ module.exports = () => describe('Streaming', function() {
const plaintext = fs.readFileSync(__filename.replace('streaming.js', 'openpgp.js'), 'utf8'); // eslint-disable-line no-sync const plaintext = fs.readFileSync(__filename.replace('streaming.js', 'openpgp.js'), 'utf8'); // eslint-disable-line no-sync
const data = fs.createReadStream(__filename.replace('streaming.js', 'openpgp.js'), { encoding: 'utf8' }); const data = fs.createReadStream(__filename.replace('streaming.js', 'openpgp.js'), { encoding: 'utf8' });
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromText(data), message: await openpgp.Message.fromText(data),
passwords: ['test'] passwords: ['test']
}); });
expect(openpgp.stream.isStream(encrypted)).to.equal('node'); expect(openpgp.stream.isStream(encrypted)).to.equal('node');
@ -1009,7 +1064,7 @@ module.exports = () => describe('Streaming', function() {
const plaintext = fs.readFileSync(__filename.replace('streaming.js', 'openpgp.js')); // eslint-disable-line no-sync const plaintext = fs.readFileSync(__filename.replace('streaming.js', 'openpgp.js')); // eslint-disable-line no-sync
const data = fs.createReadStream(__filename.replace('streaming.js', 'openpgp.js')); const data = fs.createReadStream(__filename.replace('streaming.js', 'openpgp.js'));
const encrypted = await openpgp.encrypt({ const encrypted = await openpgp.encrypt({
message: openpgp.Message.fromBinary(data), message: await openpgp.Message.fromBinary(data),
passwords: ['test'], passwords: ['test'],
armor: false armor: false
}); });

View File

@ -174,7 +174,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
const name = 'light'; const name = 'light';
const randomData = input.createSomeMessage(); const randomData = input.createSomeMessage();
const priv = await load_priv_key(name); const priv = await load_priv_key(name);
const signed = await openpgp.sign({ privateKeys: [priv], message: openpgp.CleartextMessage.fromText(randomData) }); const signed = await openpgp.sign({ privateKeys: [priv], message: await openpgp.CleartextMessage.fromText(randomData) });
const pub = await load_pub_key(name); const pub = await load_pub_key(name);
const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed });
const result = await openpgp.verify({ publicKeys: [pub], message: msg }); const result = await openpgp.verify({ publicKeys: [pub], message: msg });
@ -201,7 +201,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
const nightPublic = await load_pub_key('night'); const nightPublic = await load_pub_key('night');
const lightPrivate = await load_priv_key('light'); const lightPrivate = await load_priv_key('light');
const randomData = input.createSomeMessage(); const randomData = input.createSomeMessage();
const encrypted = await openpgp.encrypt({ publicKeys: [nightPublic], privateKeys: [lightPrivate], message: openpgp.Message.fromText(randomData) }); const encrypted = await openpgp.encrypt({ publicKeys: [nightPublic], privateKeys: [lightPrivate], message: await openpgp.Message.fromText(randomData) });
const message = await openpgp.readMessage({ armoredMessage: encrypted }); const message = await openpgp.readMessage({ armoredMessage: encrypted });
const lightPublic = await load_pub_key('light'); const lightPublic = await load_pub_key('light');
@ -447,7 +447,7 @@ function omnibus() {
}), }),
// Signing message // Signing message
openpgp.sign( openpgp.sign(
{ message: openpgp.CleartextMessage.fromText('Hi, this is me, Hi!'), privateKeys: hi } { message: await openpgp.CleartextMessage.fromText('Hi, this is me, Hi!'), privateKeys: hi }
).then(async signed => { ).then(async signed => {
const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed }); const msg = await openpgp.readCleartextMessage({ cleartextMessage: signed });
// Verifying signed message // Verifying signed message
@ -457,7 +457,7 @@ function omnibus() {
).then(output => expect(output.signatures[0].valid).to.be.true), ).then(output => expect(output.signatures[0].valid).to.be.true),
// Verifying detached signature // Verifying detached signature
openpgp.verify({ openpgp.verify({
message: openpgp.Message.fromText('Hi, this is me, Hi!'), message: await openpgp.Message.fromText('Hi, this is me, Hi!'),
publicKeys: hi.toPublic(), publicKeys: hi.toPublic(),
signature: msg.signature signature: msg.signature
}).then(output => expect(output.signatures[0].valid).to.be.true) }).then(output => expect(output.signatures[0].valid).to.be.true)
@ -466,7 +466,7 @@ function omnibus() {
// Encrypting and signing // Encrypting and signing
openpgp.encrypt( openpgp.encrypt(
{ {
message: openpgp.Message.fromText('Hi, Hi wrote this but only Bye can read it!'), message: await openpgp.Message.fromText('Hi, Hi wrote this but only Bye can read it!'),
publicKeys: [bye.toPublic()], publicKeys: [bye.toPublic()],
privateKeys: [hi] privateKeys: [hi]
} }

View File

@ -58,7 +58,7 @@ async function makeKeyValid() {
async function encryptFails(k) { async function encryptFails(k) {
try { try {
await openpgp.encrypt({ await openpgp.encrypt({
message: message.fromText('Hello', 'hello.txt'), message: await Message.fromText('Hello', 'hello.txt'),
publicKeys: k publicKeys: k
}); });
return false; return false;

View File

@ -25,7 +25,7 @@ import { expect } from 'chai';
// Encrypt text message (armored) // Encrypt text message (armored)
const text = 'hello'; const text = 'hello';
const textMessage = Message.fromText('hello'); const textMessage = await Message.fromText('hello');
const encryptedArmor: string = await encrypt({ publicKeys, message: textMessage }); const encryptedArmor: string = await encrypt({ publicKeys, message: textMessage });
expect(encryptedArmor).to.include('-----BEGIN PGP MESSAGE-----'); expect(encryptedArmor).to.include('-----BEGIN PGP MESSAGE-----');
@ -33,7 +33,7 @@ import { expect } from 'chai';
const binary = new Uint8Array(2); const binary = new Uint8Array(2);
binary[0] = 1; binary[0] = 1;
binary[1] = 2; binary[1] = 2;
const binaryMessage = Message.fromBinary(binary); const binaryMessage = await Message.fromBinary(binary);
const encryptedBinary: Uint8Array = await encrypt({ publicKeys, message: binaryMessage, armor: false }); const encryptedBinary: Uint8Array = await encrypt({ publicKeys, message: binaryMessage, armor: false });
expect(encryptedBinary).to.be.instanceOf(Uint8Array); expect(encryptedBinary).to.be.instanceOf(Uint8Array);
@ -54,7 +54,7 @@ import { expect } from 'chai';
expect(encryptedMessage).to.be.instanceOf(Message); expect(encryptedMessage).to.be.instanceOf(Message);
// Sign cleartext message (armored) // Sign cleartext message (armored)
const cleartextMessage = CleartextMessage.fromText('hello'); const cleartextMessage = await CleartextMessage.fromText('hello');
const clearSignedArmor = await sign({ privateKeys, message: cleartextMessage }); const clearSignedArmor = await sign({ privateKeys, message: cleartextMessage });
expect(clearSignedArmor).to.include('-----BEGIN PGP SIGNED MESSAGE-----'); expect(clearSignedArmor).to.include('-----BEGIN PGP SIGNED MESSAGE-----');
@ -80,12 +80,12 @@ import { expect } from 'chai';
// // Detached - sign cleartext message (armored) // // Detached - sign cleartext message (armored)
// import { Message, sign } from 'openpgp'; // import { Message, sign } from 'openpgp';
// const message = Message.fromText(util.removeTrailingSpaces(text)); // const message = await Message.fromText(util.removeTrailingSpaces(text));
// const signed = await sign({ privateKeys, message, detached: true }); // const signed = await sign({ privateKeys, message, detached: true });
// console.log(signed); // String // console.log(signed); // String
// // Detached - sign binary message (unarmored) // // Detached - sign binary message (unarmored)
// const message = Message.fromText(text); // const message = await Message.fromText(text);
// const signed = await sign({ privateKeys, message, detached: true, armor: false }); // const signed = await sign({ privateKeys, message, detached: true, armor: false });
// console.log(signed); // Uint8Array // console.log(signed); // Uint8Array
@ -99,7 +99,7 @@ import { expect } from 'chai';
// // Streaming - encrypt text message on Node.js (armored) // // Streaming - encrypt text message on Node.js (armored)
// const data = fs.createReadStream(filename, { encoding: 'utf8' }); // const data = fs.createReadStream(filename, { encoding: 'utf8' });
// const message = Message.fromText(data); // const message = await Message.fromText(data);
// const encrypted = await encrypt({ publicKeys, message }); // const encrypted = await encrypt({ publicKeys, message });
// encrypted.on('data', chunk => { // encrypted.on('data', chunk => {
// console.log(chunk); // String // console.log(chunk); // String
@ -107,7 +107,7 @@ import { expect } from 'chai';
// // Streaming - encrypt binary message on Node.js (unarmored) // // Streaming - encrypt binary message on Node.js (unarmored)
// const data = fs.createReadStream(filename); // const data = fs.createReadStream(filename);
// const message = Message.fromBinary(data); // const message = await Message.fromBinary(data);
// const encrypted = await encrypt({ publicKeys, message, armor: false }); // const encrypted = await encrypt({ publicKeys, message, armor: false });
// encrypted.pipe(targetStream); // encrypted.pipe(targetStream);

View File

@ -48,7 +48,7 @@ onmessage = async function({ data: { action, message }, ports: [port] }) {
const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored }); const privateKey = await openpgp.readKey({ armoredKey: privateKeyArmored });
await privateKey.decrypt('test'); await privateKey.decrypt('test');
const data = await openpgp.encrypt({ const data = await openpgp.encrypt({
message: openpgp.Message.fromText(message), message: await openpgp.Message.fromText(message),
publicKeys: publicKey, publicKeys: publicKey,
privateKeys: privateKey privateKeys: privateKey
}); });