Export key, message, signature, cleartext functions and classes directly
Instead of as modules. Replace *.read with read*, *.readArmored with readArmored*, etc. Replace cleartext.readArmored with readArmoredCleartextMessage. Replace message.fromText with Message.fromText, etc.
This commit is contained in:
parent
3a75eadaa0
commit
f276e1ef51
82
README.md
82
README.md
|
@ -148,16 +148,16 @@ Encryption will use the algorithm specified in config.encryptionCipher (defaults
|
|||
```js
|
||||
(async () => {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])), // input as Message object
|
||||
message: openpgp.Message.fromBinary(new Uint8Array([0x01, 0x01, 0x01])), // input as Message object
|
||||
passwords: ['secret stuff'], // multiple passwords possible
|
||||
armor: false // don't ASCII armor (for Uint8Array output)
|
||||
});
|
||||
console.log(encrypted); // Uint8Array
|
||||
|
||||
const { data: decrypted } = await openpgp.decrypt({
|
||||
message: await openpgp.message.read(encrypted), // parse encrypted bytes
|
||||
passwords: ['secret stuff'], // decrypt with password
|
||||
format: 'binary' // output as Uint8Array
|
||||
message: await openpgp.readMessage(encrypted), // parse encrypted bytes
|
||||
passwords: ['secret stuff'], // decrypt with password
|
||||
format: 'binary' // output as Uint8Array
|
||||
});
|
||||
console.log(decrypted); // Uint8Array([0x01, 0x01, 0x01])
|
||||
})();
|
||||
|
@ -180,19 +180,19 @@ const openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via w
|
|||
-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
|
||||
const passphrase = `yourPassphrase`; // what the private key is encrypted with
|
||||
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt(passphrase);
|
||||
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText('Hello, World!'), // input as Message object
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored), // for encryption
|
||||
privateKeys: privateKey // for signing (optional)
|
||||
message: openpgp.Message.fromText('Hello, World!'), // input as Message object
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored), // for encryption
|
||||
privateKeys: privateKey // for signing (optional)
|
||||
});
|
||||
console.log(encrypted); // '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
||||
const { data: decrypted } = await openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(encrypted), // parse armored message
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored), // for verification (optional)
|
||||
privateKeys: privateKey // for decryption
|
||||
message: await openpgp.readArmoredMessage(encrypted), // parse armored message
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored), // for verification (optional)
|
||||
privateKeys: privateKey // for decryption
|
||||
});
|
||||
console.log(decrypted); // 'Hello, World!'
|
||||
})();
|
||||
|
@ -216,13 +216,13 @@ Encrypt with multiple public keys:
|
|||
const passphrase = `yourPassphrase`; // what the private key is encrypted with
|
||||
const message = 'Hello, World!';
|
||||
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt(passphrase)
|
||||
|
||||
const publicKeys = await Promise.all(publicKeysArmored.map(openpgp.key.readArmored));
|
||||
const publicKeys = await Promise.all(publicKeysArmored.map(openpgp.readArmoredKey));
|
||||
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText(message), // input as Message object
|
||||
message: openpgp.Message.fromText(message), // input as Message object
|
||||
publicKeys, // for encryption
|
||||
privateKeys: [privateKey] // for signing (optional)
|
||||
});
|
||||
|
@ -239,7 +239,7 @@ Either set the `compression` parameter in the options object when calling `encry
|
|||
```js
|
||||
(async () => {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])), // or .fromText('string')
|
||||
message: openpgp.Message.fromBinary(new Uint8Array([0x01, 0x02, 0x03])), // or .fromText('string')
|
||||
passwords: ['secret stuff'], // multiple passwords possible
|
||||
compression: openpgp.enums.compression.zip // compress the data with zip
|
||||
});
|
||||
|
@ -269,7 +269,7 @@ Where the value can be any of:
|
|||
});
|
||||
|
||||
const { message } = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(readableStream), // input as Message object
|
||||
message: openpgp.Message.fromBinary(readableStream), // input as Message object
|
||||
passwords: ['secret stuff'], // multiple passwords possible
|
||||
armor: false // don't ASCII armor (for Uint8Array output)
|
||||
});
|
||||
|
@ -309,7 +309,7 @@ its [Reader class](https://openpgpjs.org/web-stream-tools/Reader.html).
|
|||
-----END PGP PRIVATE KEY BLOCK-----`; // Encrypted private key
|
||||
const passphrase = `yourPassphrase`; // Password that private key is encrypted with
|
||||
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt(passphrase);
|
||||
|
||||
const readableStream = new openpgp.stream.ReadableStream({
|
||||
|
@ -320,16 +320,16 @@ its [Reader class](https://openpgpjs.org/web-stream-tools/Reader.html).
|
|||
});
|
||||
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText(readableStream), // input as Message object
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored), // for encryption
|
||||
privateKeys: privateKey // for signing (optional)
|
||||
message: openpgp.Message.fromText(readableStream), // input as Message object
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored), // for encryption
|
||||
privateKeys: privateKey // for signing (optional)
|
||||
});
|
||||
console.log(encrypted); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
||||
|
||||
const decrypted = await openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(encrypted), // parse armored message
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored), // for verification (optional)
|
||||
privateKeys: privateKey // for decryption
|
||||
message: await openpgp.readArmoredMessage(encrypted), // parse armored message
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored), // for verification (optional)
|
||||
privateKeys: privateKey // for decryption
|
||||
});
|
||||
const plaintext = await openpgp.stream.readToEnd(decrypted.data);
|
||||
console.log(plaintext); // 'Hello, World!'
|
||||
|
@ -378,7 +378,7 @@ Using a revocation certificate:
|
|||
```js
|
||||
(async () => {
|
||||
const { publicKeyArmored: revokedKeyArmored } = await openpgp.revokeKey({
|
||||
key: await openpgp.key.readArmored(publicKeyArmored),
|
||||
key: await openpgp.readArmoredKey(publicKeyArmored),
|
||||
revocationCertificate
|
||||
});
|
||||
console.log(revokedKeyArmored); // '-----BEGIN PGP PUBLIC KEY BLOCK ... '
|
||||
|
@ -389,7 +389,7 @@ Using the private key:
|
|||
```js
|
||||
(async () => {
|
||||
const { publicKeyArmored, publicKey } = await openpgp.revokeKey({
|
||||
key: await openpgp.key.readArmored(privateKeyArmored)
|
||||
key: await openpgp.readArmoredKey(privateKeyArmored)
|
||||
});
|
||||
})();
|
||||
```
|
||||
|
@ -403,7 +403,7 @@ Using the private key:
|
|||
let publicKeyArmored = await hkp.lookup({
|
||||
query: 'alice@example.com'
|
||||
});
|
||||
let publicKey = await openpgp.key.readArmored(publicKeyArmored);
|
||||
let publicKey = await openpgp.readArmoredKey(publicKeyArmored);
|
||||
})();
|
||||
```
|
||||
|
||||
|
@ -433,18 +433,18 @@ Using the private key:
|
|||
-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
|
||||
const passphrase = `yourPassphrase`; // what the private key is encrypted with
|
||||
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt(passphrase);
|
||||
|
||||
const cleartext = await openpgp.sign({
|
||||
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
|
||||
privateKeys: privateKey // for signing
|
||||
message: openpgp.CleartextMessage.fromText('Hello, World!'), // CleartextMessage or Message object
|
||||
privateKeys: privateKey // for signing
|
||||
});
|
||||
console.log(cleartext); // '-----BEGIN PGP SIGNED MESSAGE ... END PGP SIGNATURE-----'
|
||||
|
||||
const verified = await openpgp.verify({
|
||||
message: await openpgp.cleartext.readArmored(cleartext), // parse armored message
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored) // for verification
|
||||
message: await openpgp.readArmoredCleartextMessage(cleartext), // parse armored message
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored) // for verification
|
||||
});
|
||||
const { valid } = verified.signatures[0];
|
||||
if (valid) {
|
||||
|
@ -467,20 +467,20 @@ Using the private key:
|
|||
-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
|
||||
const passphrase = `yourPassphrase`; // what the private key is encrypted with
|
||||
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt(passphrase);
|
||||
|
||||
const { signature: detachedSignature } = await openpgp.sign({
|
||||
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
|
||||
privateKeys: privateKey , // for signing
|
||||
message: openpgp.CleartextMessage.fromText('Hello, World!'), // CleartextMessage or Message object
|
||||
privateKeys: privateKey, // for signing
|
||||
detached: true
|
||||
});
|
||||
console.log(detachedSignature);
|
||||
|
||||
const verified = await openpgp.verify({
|
||||
message: openpgp.cleartext.fromText('Hello, World!'), // CleartextMessage or Message object
|
||||
signature: await openpgp.signature.readArmored(detachedSignature), // parse detached signature
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored) // for verification
|
||||
message: openpgp.CleartextMessage.fromText('Hello, World!'), // CleartextMessage or Message object
|
||||
signature: await openpgp.readArmoredSignature(detachedSignature), // parse detached signature
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored) // for verification
|
||||
});
|
||||
const { valid } = verified.signatures[0];
|
||||
if (valid) {
|
||||
|
@ -510,18 +510,18 @@ Using the private key:
|
|||
-----END PGP PRIVATE KEY BLOCK-----`; // encrypted private key
|
||||
const passphrase = `yourPassphrase`; // what the private key is encrypted with
|
||||
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt(passphrase);
|
||||
|
||||
const signatureArmored = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(readableStream), // or .fromText(readableStream: ReadableStream<String>)
|
||||
message: openpgp.Message.fromBinary(readableStream), // or .fromText(readableStream: ReadableStream<String>)
|
||||
privateKeys: privateKey // for signing
|
||||
});
|
||||
console.log(signatureArmored); // ReadableStream containing '-----BEGIN PGP MESSAGE ... END PGP MESSAGE-----'
|
||||
|
||||
const verified = await openpgp.verify({
|
||||
message: await openpgp.message.readArmored(signatureArmored), // parse armored signature
|
||||
publicKeys: await openpgp.key.readArmored(publicKeyArmored) // for verification
|
||||
message: await openpgp.readArmoredMessage(signatureArmored), // parse armored signature
|
||||
publicKeys: await openpgp.readArmoredKey(publicKeyArmored) // for verification
|
||||
});
|
||||
|
||||
await openpgp.stream.readToEnd(verified.data);
|
||||
|
|
|
@ -142,6 +142,15 @@ export class CleartextMessage {
|
|||
};
|
||||
return armor.encode(enums.armor.signed, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CleartextMessage object from text
|
||||
* @param {String} text
|
||||
* @static
|
||||
*/
|
||||
static fromText(text) {
|
||||
return new CleartextMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -152,7 +161,7 @@ export class CleartextMessage {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function readArmored(armoredText) {
|
||||
export async function readArmoredCleartextMessage(armoredText) {
|
||||
const input = await armor.decode(armoredText);
|
||||
if (input.type !== enums.armor.signed) {
|
||||
throw new Error('No cleartext signed message.');
|
||||
|
@ -209,12 +218,3 @@ function verifyHeaders(headers, packetlist) {
|
|||
throw new Error('Hash algorithm mismatch in armor header and signature');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new CleartextMessage object from text
|
||||
* @param {String} text
|
||||
* @static
|
||||
*/
|
||||
export function fromText(text) {
|
||||
return new CleartextMessage(text);
|
||||
}
|
||||
|
|
15
src/index.js
15
src/index.js
|
@ -17,29 +17,28 @@ export {
|
|||
* @see module:key
|
||||
* @name module:openpgp.key
|
||||
*/
|
||||
import * as keyMod from './key';
|
||||
export const key = keyMod;
|
||||
export * from './key';
|
||||
|
||||
/**
|
||||
* @see module:signature
|
||||
* @name module:openpgp.signature
|
||||
*/
|
||||
import * as signatureMod from './signature';
|
||||
export const signature = signatureMod;
|
||||
export * from './signature';
|
||||
|
||||
/**
|
||||
* @see module:message
|
||||
* @name module:openpgp.message
|
||||
*/
|
||||
import * as messageMod from './message';
|
||||
export const message = messageMod;
|
||||
export {
|
||||
readMessage, readArmoredMessage,
|
||||
Message
|
||||
} from './message';
|
||||
|
||||
/**
|
||||
* @see module:cleartext
|
||||
* @name module:openpgp.cleartext
|
||||
*/
|
||||
import * as cleartextMod from './cleartext';
|
||||
export const cleartext = cleartextMod;
|
||||
export * from './cleartext';
|
||||
|
||||
/**
|
||||
* @see module:util
|
||||
|
|
|
@ -269,7 +269,7 @@ async function wrapKeyObject(secretKeyPacket, secretSubkeyPackets, options) {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function read(data) {
|
||||
export async function readKey(data) {
|
||||
const packetlist = new PacketList();
|
||||
await packetlist.read(data, helper.allowedKeyPackets);
|
||||
return new Key(packetlist);
|
||||
|
@ -282,12 +282,12 @@ export async function read(data) {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function readArmored(armoredKey) {
|
||||
export async function readArmoredKey(armoredKey) {
|
||||
const input = await armor.decode(armoredKey);
|
||||
if (!(input.type === enums.armor.publicKey || input.type === enums.armor.privateKey)) {
|
||||
throw new Error('Armored text not of type key');
|
||||
}
|
||||
return read(input.data);
|
||||
return readKey(input.data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -297,7 +297,7 @@ export async function readArmored(armoredKey) {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function readAll(data) {
|
||||
export async function readKeys(data) {
|
||||
const keys = [];
|
||||
const packetlist = new PacketList();
|
||||
await packetlist.read(data, helper.allowedKeyPackets);
|
||||
|
@ -320,10 +320,10 @@ export async function readAll(data) {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function readAllArmored(armoredKey) {
|
||||
export async function readArmoredKeys(armoredKey) {
|
||||
const input = await armor.decode(armoredKey);
|
||||
if (!(input.type === enums.armor.publicKey || input.type === enums.armor.privateKey)) {
|
||||
throw new Error('Armored text not of type key');
|
||||
}
|
||||
return readAll(input.data);
|
||||
return readKeys(input.data);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
read, readArmored,
|
||||
readAll, readAllArmored,
|
||||
readKey, readArmoredKey,
|
||||
readKeys, readArmoredKeys,
|
||||
generate,
|
||||
reformat
|
||||
} from './factory';
|
||||
|
@ -20,8 +20,8 @@ import {
|
|||
import Key from './key.js';
|
||||
|
||||
export {
|
||||
read, readArmored,
|
||||
readAll, readAllArmored,
|
||||
readKey, readArmoredKey,
|
||||
readKeys, readArmoredKeys,
|
||||
generate,
|
||||
reformat,
|
||||
getPreferredAlgo,
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* @module keyring/keyring
|
||||
*/
|
||||
|
||||
import { readAllArmored } from '../key';
|
||||
import { readArmoredKeys } from '../key';
|
||||
import LocalStore from './localstore';
|
||||
|
||||
/**
|
||||
|
@ -80,7 +80,7 @@ class KeyArray {
|
|||
* @async
|
||||
*/
|
||||
async importKey(armored) {
|
||||
const imported = await readAllArmored(armored);
|
||||
const imported = await readArmoredKeys(armored);
|
||||
for (let i = 0; i < imported.length; i++) {
|
||||
const key = imported[i];
|
||||
// check if key already in key array
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
import stream from 'web-stream-tools';
|
||||
import config from '../config';
|
||||
import { readArmored } from '../key';
|
||||
import { readArmoredKey } from '../key';
|
||||
|
||||
/**
|
||||
* The class that deals with storage of the keyring.
|
||||
|
@ -97,7 +97,7 @@ async function loadKeys(storage, itemname) {
|
|||
if (armoredKeys !== null && armoredKeys.length !== 0) {
|
||||
let key;
|
||||
for (let i = 0; i < armoredKeys.length; i++) {
|
||||
key = await readArmored(armoredKeys[i]);
|
||||
key = await readArmoredKey(armoredKeys[i]);
|
||||
keys.push(key);
|
||||
}
|
||||
}
|
||||
|
|
120
src/message.js
120
src/message.js
|
@ -625,6 +625,63 @@ export class Message {
|
|||
armor() {
|
||||
return armor.encode(enums.armor.message, this.write());
|
||||
}
|
||||
|
||||
/**
|
||||
* creates new message object from text
|
||||
* @param {String | ReadableStream<String>} text
|
||||
* @param {String} filename (optional)
|
||||
* @param {Date} date (optional)
|
||||
* @param {utf8|binary|text|mime} type (optional) data packet type
|
||||
* @returns {module:message.Message} new message object
|
||||
* @static
|
||||
*/
|
||||
static fromText(text, filename, date = new Date(), type = 'utf8') {
|
||||
const streamType = util.isStream(text);
|
||||
if (streamType === 'node') {
|
||||
text = stream.nodeToWeb(text);
|
||||
}
|
||||
const literalDataPacket = new LiteralDataPacket(date);
|
||||
// text will be converted to UTF8
|
||||
literalDataPacket.setText(text, type);
|
||||
if (filename !== undefined) {
|
||||
literalDataPacket.setFilename(filename);
|
||||
}
|
||||
const literalDataPacketlist = new PacketList();
|
||||
literalDataPacketlist.push(literalDataPacket);
|
||||
const message = new Message(literalDataPacketlist);
|
||||
message.fromStream = streamType;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates new message object from binary data
|
||||
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes
|
||||
* @param {String} filename (optional)
|
||||
* @param {Date} date (optional)
|
||||
* @param {utf8|binary|text|mime} type (optional) data packet type
|
||||
* @returns {module:message.Message} new message object
|
||||
* @static
|
||||
*/
|
||||
static fromBinary(bytes, filename, date = new Date(), type = 'binary') {
|
||||
const streamType = util.isStream(bytes);
|
||||
if (!util.isUint8Array(bytes) && !streamType) {
|
||||
throw new Error('Data must be in the form of a Uint8Array or Stream');
|
||||
}
|
||||
if (streamType === 'node') {
|
||||
bytes = stream.nodeToWeb(bytes);
|
||||
}
|
||||
|
||||
const literalDataPacket = new LiteralDataPacket(date);
|
||||
literalDataPacket.setBytes(bytes, type);
|
||||
if (filename !== undefined) {
|
||||
literalDataPacket.setFilename(filename);
|
||||
}
|
||||
const literalDataPacketlist = new PacketList();
|
||||
literalDataPacketlist.push(literalDataPacket);
|
||||
const message = new Message(literalDataPacketlist);
|
||||
message.fromStream = streamType;
|
||||
return message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -752,7 +809,7 @@ export async function createVerificationObjects(signatureList, literalDataList,
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function readArmored(armoredText) {
|
||||
export async function readArmoredMessage(armoredText) {
|
||||
//TODO how do we want to handle bad text? Exception throwing
|
||||
//TODO don't accept non-message armored texts
|
||||
const streamType = util.isStream(armoredText);
|
||||
|
@ -760,7 +817,7 @@ export async function readArmored(armoredText) {
|
|||
armoredText = stream.nodeToWeb(armoredText);
|
||||
}
|
||||
const input = await armor.decode(armoredText);
|
||||
return read(input.data, streamType);
|
||||
return readMessage(input.data, streamType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -771,7 +828,7 @@ export async function readArmored(armoredText) {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function read(input, fromStream = util.isStream(input)) {
|
||||
export async function readMessage(input, fromStream = util.isStream(input)) {
|
||||
const streamType = util.isStream(input);
|
||||
if (streamType === 'node') {
|
||||
input = stream.nodeToWeb(input);
|
||||
|
@ -792,60 +849,3 @@ export async function read(input, fromStream = util.isStream(input)) {
|
|||
message.fromStream = fromStream;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates new message object from text
|
||||
* @param {String | ReadableStream<String>} text
|
||||
* @param {String} filename (optional)
|
||||
* @param {Date} date (optional)
|
||||
* @param {utf8|binary|text|mime} type (optional) data packet type
|
||||
* @returns {module:message.Message} new message object
|
||||
* @static
|
||||
*/
|
||||
export function fromText(text, filename, date = new Date(), type = 'utf8') {
|
||||
const streamType = util.isStream(text);
|
||||
if (streamType === 'node') {
|
||||
text = stream.nodeToWeb(text);
|
||||
}
|
||||
const literalDataPacket = new LiteralDataPacket(date);
|
||||
// text will be converted to UTF8
|
||||
literalDataPacket.setText(text, type);
|
||||
if (filename !== undefined) {
|
||||
literalDataPacket.setFilename(filename);
|
||||
}
|
||||
const literalDataPacketlist = new PacketList();
|
||||
literalDataPacketlist.push(literalDataPacket);
|
||||
const message = new Message(literalDataPacketlist);
|
||||
message.fromStream = streamType;
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates new message object from binary data
|
||||
* @param {Uint8Array | ReadableStream<Uint8Array>} bytes
|
||||
* @param {String} filename (optional)
|
||||
* @param {Date} date (optional)
|
||||
* @param {utf8|binary|text|mime} type (optional) data packet type
|
||||
* @returns {module:message.Message} new message object
|
||||
* @static
|
||||
*/
|
||||
export function fromBinary(bytes, filename, date = new Date(), type = 'binary') {
|
||||
const streamType = util.isStream(bytes);
|
||||
if (!util.isUint8Array(bytes) && !streamType) {
|
||||
throw new Error('Data must be in the form of a Uint8Array or Stream');
|
||||
}
|
||||
if (streamType === 'node') {
|
||||
bytes = stream.nodeToWeb(bytes);
|
||||
}
|
||||
|
||||
const literalDataPacket = new LiteralDataPacket(date);
|
||||
literalDataPacket.setBytes(bytes, type);
|
||||
if (filename !== undefined) {
|
||||
literalDataPacket.setFilename(filename);
|
||||
}
|
||||
const literalDataPacketlist = new PacketList();
|
||||
literalDataPacketlist.push(literalDataPacket);
|
||||
const message = new Message(literalDataPacketlist);
|
||||
message.fromStream = streamType;
|
||||
return message;
|
||||
}
|
||||
|
|
|
@ -211,7 +211,7 @@ export function encryptKey({ privateKey, passphrase }) {
|
|||
/**
|
||||
* Encrypts message text/data with public keys, passwords or both at once. At least either public keys or passwords
|
||||
* must be specified. If private keys are specified, those will be used to sign the message.
|
||||
* @param {Message} message message to be encrypted as created by openpgp.message.fromText or openpgp.message.fromBinary
|
||||
* @param {Message} message message to be encrypted as created by openpgp.Message.fromText or openpgp.Message.fromBinary
|
||||
* @param {Key|Array<Key>} publicKeys (optional) array of keys or single key, used to encrypt the message
|
||||
* @param {Key|Array<Key>} privateKeys (optional) private keys for signing. If omitted message will not be signed
|
||||
* @param {String|Array<String>} passwords (optional) array of passwords or a single password to encrypt the message
|
||||
|
|
|
@ -61,9 +61,9 @@ export class Signature {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function readArmored(armoredText) {
|
||||
export async function readArmoredSignature(armoredText) {
|
||||
const input = await armor.decode(armoredText);
|
||||
return read(input.data);
|
||||
return readSignature(input.data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,7 +73,7 @@ export async function readArmored(armoredText) {
|
|||
* @async
|
||||
* @static
|
||||
*/
|
||||
export async function read(input) {
|
||||
export async function readSignature(input) {
|
||||
const packetlist = new PacketList();
|
||||
await packetlist.read(input, { SignaturePacket });
|
||||
return new Signature(packetlist);
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
import util from './util';
|
||||
import crypto from './crypto';
|
||||
import * as keyMod from './key';
|
||||
import { readKeys } from './key';
|
||||
|
||||
class WKD {
|
||||
/**
|
||||
|
@ -78,7 +78,7 @@ class WKD {
|
|||
if (options.rawBytes) {
|
||||
return rawBytes;
|
||||
}
|
||||
return keyMod.readAll(rawBytes);
|
||||
return readKeys(rawBytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -263,7 +263,7 @@ module.exports = () => {
|
|||
describe('DSA parameter validation', function() {
|
||||
let dsaKey;
|
||||
before(async () => {
|
||||
dsaKey = await openpgp.key.readArmored(armoredDSAKey);
|
||||
dsaKey = await openpgp.readArmoredKey(armoredDSAKey);
|
||||
});
|
||||
|
||||
it('DSA params should be valid', async function() {
|
||||
|
@ -300,7 +300,7 @@ module.exports = () => {
|
|||
describe('ElGamal parameter validation', function() {
|
||||
let egKey;
|
||||
before(async () => {
|
||||
egKey = (await openpgp.key.readArmored(armoredElGamalKey)).subKeys[0];
|
||||
egKey = (await openpgp.readArmoredKey(armoredElGamalKey)).subKeys[0];
|
||||
});
|
||||
|
||||
it('params should be valid', async function() {
|
||||
|
|
|
@ -28,55 +28,55 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
|
||||
it('Parse cleartext signed message', async function () {
|
||||
let msg = getArmor(['Hash: SHA1']);
|
||||
msg = await openpgp.cleartext.readArmored(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage);
|
||||
msg = await openpgp.readArmoredCleartextMessage(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.CleartextMessage);
|
||||
});
|
||||
|
||||
it('Exception if mismatch in armor header and signature', async function () {
|
||||
let msg = getArmor(['Hash: SHA256']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Hash algorithm mismatch in armor header and signature/);
|
||||
});
|
||||
|
||||
it('Exception if no header and non-MD5 signature', async function () {
|
||||
let msg = getArmor(null);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /If no "Hash" header in cleartext signed message, then only MD5 signatures allowed/);
|
||||
});
|
||||
|
||||
it('Exception if unknown hash algorithm', async function () {
|
||||
let msg = getArmor(['Hash: LAV750']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Unknown hash algorithm in armor header/);
|
||||
});
|
||||
|
||||
it('Multiple hash values', async function () {
|
||||
let msg = getArmor(['Hash: SHA1, SHA256']);
|
||||
msg = await openpgp.cleartext.readArmored(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage);
|
||||
msg = await openpgp.readArmoredCleartextMessage(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.CleartextMessage);
|
||||
});
|
||||
|
||||
it('Multiple hash header lines', async function () {
|
||||
let msg = getArmor(['Hash: SHA1', 'Hash: SHA256']);
|
||||
msg = await openpgp.cleartext.readArmored(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage);
|
||||
msg = await openpgp.readArmoredCleartextMessage(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.CleartextMessage);
|
||||
});
|
||||
|
||||
it('Non-hash header line throws exception', async function () {
|
||||
let msg = getArmor(['Hash: SHA1', 'Comment: could be anything']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Only "Hash" header allowed in cleartext signed message/);
|
||||
});
|
||||
|
||||
it('Multiple wrong hash values', async function () {
|
||||
let msg = getArmor(['Hash: SHA512, SHA256']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Hash algorithm mismatch in armor header and signature/);
|
||||
});
|
||||
|
||||
it('Multiple wrong hash values', async function () {
|
||||
let msg = getArmor(['Hash: SHA512, SHA256']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Hash algorithm mismatch in armor header and signature/);
|
||||
});
|
||||
|
||||
|
@ -96,33 +96,33 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
'=e/eA',
|
||||
'-----END PGP SIGNATURE-----'].join('\n');
|
||||
|
||||
msg = await openpgp.cleartext.readArmored(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.cleartext.CleartextMessage);
|
||||
msg = await openpgp.readArmoredCleartextMessage(msg);
|
||||
expect(msg).to.be.an.instanceof(openpgp.CleartextMessage);
|
||||
});
|
||||
|
||||
it('Exception if improperly formatted armor header - plaintext section', async function () {
|
||||
let msg = getArmor(['Hash:SHA256']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Improperly formatted armor header/);
|
||||
msg = getArmor(['Ha sh: SHA256']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Only "Hash" header allowed in cleartext signed message/);
|
||||
msg = getArmor(['Hash SHA256']);
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Improperly formatted armor header/);
|
||||
});
|
||||
|
||||
it('Exception if improperly formatted armor header - signature section', async function () {
|
||||
await Promise.all(['Space : trailing', 'Space :switched', ': empty', 'none', 'Space:missing'].map(async function (invalidHeader) {
|
||||
await expect(openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], [invalidHeader]))).to.be.rejectedWith(Error, /Improperly formatted armor header/);
|
||||
await expect(openpgp.readArmoredCleartextMessage(getArmor(['Hash: SHA1'], [invalidHeader]))).to.be.rejectedWith(Error, /Improperly formatted armor header/);
|
||||
}));
|
||||
});
|
||||
|
||||
it('Ignore unknown armor header - signature section', async function () {
|
||||
const validHeaders = ['Version: BCPG C# v1.7.4114.6375', 'Independent Reserve Pty. Ltd. 2017: 1.0.0.0'];
|
||||
expect(await openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], validHeaders))).to.be.an.instanceof(openpgp.cleartext.CleartextMessage);
|
||||
expect(await openpgp.readArmoredCleartextMessage(getArmor(['Hash: SHA1'], validHeaders))).to.be.an.instanceof(openpgp.CleartextMessage);
|
||||
await Promise.all(['A: Hello', 'Ab: 1.2.3', 'Abcd: #!/yah', 'Acd 123 5.6.$.8: Hello', '_: Hello', '*: Hello', '* & ## ?? ()(): Hello', '( ): Weird'].map(async function (validHeader) {
|
||||
expect(await openpgp.cleartext.readArmored(getArmor(['Hash: SHA1'], [validHeader]))).to.be.an.instanceof(openpgp.cleartext.CleartextMessage);
|
||||
expect(await openpgp.readArmoredCleartextMessage(getArmor(['Hash: SHA1'], [validHeader]))).to.be.an.instanceof(openpgp.CleartextMessage);
|
||||
}));
|
||||
});
|
||||
|
||||
|
@ -141,7 +141,7 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
'=e/eA',
|
||||
'-----END PGP SIGNNATURE-----'].join('\n');
|
||||
|
||||
msg = openpgp.cleartext.readArmored(msg);
|
||||
msg = openpgp.readArmoredCleartextMessage(msg);
|
||||
await expect(msg).to.be.rejectedWith(Error, /Unknown ASCII armor type/);
|
||||
});
|
||||
|
||||
|
@ -167,11 +167,11 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
||||
|
||||
// try with default config
|
||||
await expect(openpgp.key.readArmored(privKey)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
await expect(openpgp.readArmoredKey(privKey)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
|
||||
// try opposite config
|
||||
openpgp.config.checksumRequired = !openpgp.config.checksumRequired;
|
||||
await expect(openpgp.key.readArmored(privKey)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
await expect(openpgp.readArmoredKey(privKey)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
|
||||
// back to default
|
||||
openpgp.config.checksumRequired = !openpgp.config.checksumRequired;
|
||||
|
@ -199,11 +199,11 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
'-----END PGP PRIVATE KEY BLOCK-----'].join('\n');
|
||||
|
||||
// try with default config
|
||||
await openpgp.key.readArmored(privKey);
|
||||
await openpgp.readArmoredKey(privKey);
|
||||
|
||||
// try opposite config
|
||||
openpgp.config.checksumRequired = !openpgp.config.checksumRequired;
|
||||
await openpgp.key.readArmored(privKey);
|
||||
await openpgp.readArmoredKey(privKey);
|
||||
|
||||
// back to default
|
||||
openpgp.config.checksumRequired = !openpgp.config.checksumRequired;
|
||||
|
@ -231,17 +231,17 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
|
||||
// try with default config
|
||||
if (openpgp.config.checksumRequired) {
|
||||
await expect(openpgp.key.readArmored(privKeyNoCheckSum)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
await expect(openpgp.readArmoredKey(privKeyNoCheckSum)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
} else {
|
||||
await openpgp.key.readArmored(privKeyNoCheckSum);
|
||||
await openpgp.readArmoredKey(privKeyNoCheckSum);
|
||||
}
|
||||
|
||||
// try opposite config
|
||||
openpgp.config.checksumRequired = !openpgp.config.checksumRequired;
|
||||
if (openpgp.config.checksumRequired) {
|
||||
await expect(openpgp.key.readArmored(privKeyNoCheckSum)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
await expect(openpgp.readArmoredKey(privKeyNoCheckSum)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
} else {
|
||||
await openpgp.key.readArmored(privKeyNoCheckSum);
|
||||
await openpgp.readArmoredKey(privKeyNoCheckSum);
|
||||
}
|
||||
|
||||
// back to default
|
||||
|
@ -271,17 +271,17 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
|
||||
// try with default config
|
||||
if (openpgp.config.checksumRequired) {
|
||||
await expect(openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
await expect(openpgp.readArmoredKey(privKeyNoCheckSumWithTrailingNewline)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
} else {
|
||||
await openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline);
|
||||
await openpgp.readArmoredKey(privKeyNoCheckSumWithTrailingNewline);
|
||||
}
|
||||
|
||||
// try opposite config
|
||||
openpgp.config.checksumRequired = !openpgp.config.checksumRequired;
|
||||
if (openpgp.config.checksumRequired) {
|
||||
await expect(openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
await expect(openpgp.readArmoredKey(privKeyNoCheckSumWithTrailingNewline)).to.be.rejectedWith(/Ascii armor integrity check on message failed/);
|
||||
} else {
|
||||
await openpgp.key.readArmored(privKeyNoCheckSumWithTrailingNewline);
|
||||
await openpgp.readArmoredKey(privKeyNoCheckSumWithTrailingNewline);
|
||||
}
|
||||
|
||||
// back to default
|
||||
|
@ -310,13 +310,13 @@ module.exports = () => describe("ASCII armor", function() {
|
|||
'-----END PGP PRIVATE KEY BLOCK-----',
|
||||
''].join('\t \r\n');
|
||||
|
||||
const result = await openpgp.key.readArmored(privKey);
|
||||
expect(result).to.be.an.instanceof(openpgp.key.Key);
|
||||
const result = await openpgp.readArmoredKey(privKey);
|
||||
expect(result).to.be.an.instanceof(openpgp.Key);
|
||||
});
|
||||
|
||||
it('Do not filter blank lines after header', async function () {
|
||||
let msg = getArmor(['Hash: SHA1', '']);
|
||||
msg = await openpgp.cleartext.readArmored(msg);
|
||||
msg = await openpgp.readArmoredCleartextMessage(msg);
|
||||
expect(msg.text).to.equal('\r\nsign this');
|
||||
});
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
if (data[name].pub_key) {
|
||||
return data[name].pub_key;
|
||||
}
|
||||
const pub = await openpgp.key.readArmored(data[name].pub);
|
||||
const pub = await openpgp.readArmoredKey(data[name].pub);
|
||||
expect(pub.getKeyId().toHex()).to.equal(data[name].id);
|
||||
data[name].pub_key = pub;
|
||||
return pub;
|
||||
|
@ -181,7 +181,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
if (data[name].priv_key) {
|
||||
return data[name].priv_key;
|
||||
}
|
||||
const pk = await openpgp.key.readArmored(data[name].priv);
|
||||
const pk = await openpgp.readArmoredKey(data[name].priv);
|
||||
expect(pk).to.exist;
|
||||
expect(pk.getKeyId().toHex()).to.equal(data[name].id);
|
||||
await pk.decrypt(data[name].pass);
|
||||
|
@ -199,7 +199,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
});
|
||||
it('Verify clear signed message', async function () {
|
||||
const pub = await load_pub_key('juliet');
|
||||
const msg = await openpgp.cleartext.readArmored(data.juliet.message_signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(data.juliet.message_signed);
|
||||
return openpgp.verify({publicKeys: [pub], message: msg}).then(function(result) {
|
||||
expect(result).to.exist;
|
||||
expect(result.data).to.equal(data.juliet.message);
|
||||
|
@ -209,9 +209,9 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
});
|
||||
it('Sign message', async function () {
|
||||
const romeoPrivate = await load_priv_key('romeo');
|
||||
const signed = await openpgp.sign({privateKeys: [romeoPrivate], message: openpgp.cleartext.fromText(data.romeo.message)});
|
||||
const signed = await openpgp.sign({privateKeys: [romeoPrivate], message: openpgp.CleartextMessage.fromText(data.romeo.message)});
|
||||
const romeoPublic = await load_pub_key('romeo');
|
||||
const msg = await openpgp.cleartext.readArmored(signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
const result = await openpgp.verify({publicKeys: [romeoPublic], message: msg});
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -222,7 +222,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
it('Decrypt and verify message', async function () {
|
||||
const juliet = await load_pub_key('juliet');
|
||||
const romeo = await load_priv_key('romeo');
|
||||
const msg = await openpgp.message.readArmored(data.romeo.message_encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(data.romeo.message_encrypted);
|
||||
const result = await openpgp.decrypt({ privateKeys: romeo, publicKeys: [juliet], message: msg });
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -233,7 +233,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
it('Decrypt and verify message with leading zero in hash', async function () {
|
||||
const juliet = await load_priv_key('juliet');
|
||||
const romeo = await load_pub_key('romeo');
|
||||
const msg = await openpgp.message.readArmored(data.romeo.message_encrypted_with_leading_zero_in_hash);
|
||||
const msg = await openpgp.readArmoredMessage(data.romeo.message_encrypted_with_leading_zero_in_hash);
|
||||
const result = await openpgp.decrypt({privateKeys: juliet, publicKeys: [romeo], message: msg});
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -247,7 +247,7 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
openpgp.config.useNative = false;
|
||||
const juliet = await load_priv_key('juliet');
|
||||
const romeo = await load_pub_key('romeo');
|
||||
const msg = await openpgp.message.readArmored(data.romeo. message_encrypted_with_leading_zero_in_hash_signed_by_elliptic_with_old_implementation);
|
||||
const msg = await openpgp.readArmoredMessage(data.romeo. message_encrypted_with_leading_zero_in_hash_signed_by_elliptic_with_old_implementation);
|
||||
const result = await openpgp.decrypt({privateKeys: juliet, publicKeys: [romeo], message: msg});
|
||||
openpgp.config.useNative = useNative;
|
||||
expect(result).to.exist;
|
||||
|
@ -259,9 +259,9 @@ EJ4QcD/oQ6x1M/8X/iKQCtxZP8RnlrbH7ExkNON5s5g=
|
|||
it('Encrypt and sign message', async function () {
|
||||
const romeoPrivate = await load_priv_key('romeo');
|
||||
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: openpgp.Message.fromText(data.romeo.message)});
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const romeoPublic = await load_pub_key('romeo');
|
||||
const julietPrivate = await load_priv_key('juliet');
|
||||
const result = await openpgp.decrypt({privateKeys: julietPrivate, publicKeys: [romeoPublic], message: message});
|
||||
|
@ -294,9 +294,9 @@ function omnibus() {
|
|||
return Promise.all([
|
||||
// Signing message
|
||||
openpgp.sign(
|
||||
{ message: openpgp.cleartext.fromText(testData), privateKeys: hi }
|
||||
{ message: openpgp.CleartextMessage.fromText(testData), privateKeys: hi }
|
||||
).then(async signed => {
|
||||
const msg = await openpgp.cleartext.readArmored(signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
// Verifying signed message
|
||||
return Promise.all([
|
||||
openpgp.verify(
|
||||
|
@ -305,9 +305,9 @@ function omnibus() {
|
|||
// Verifying detached signature
|
||||
openpgp.verify(
|
||||
{
|
||||
message: openpgp.cleartext.fromText(testData),
|
||||
message: openpgp.CleartextMessage.fromText(testData),
|
||||
publicKeys: pubHi,
|
||||
signature: await openpgp.signature.readArmored(signed)
|
||||
signature: await openpgp.readArmoredSignature(signed)
|
||||
}
|
||||
).then(output => expect(output.signatures[0].valid).to.be.true)
|
||||
]);
|
||||
|
@ -315,12 +315,12 @@ function omnibus() {
|
|||
// Encrypting and signing
|
||||
openpgp.encrypt(
|
||||
{
|
||||
message: openpgp.message.fromText(testData2),
|
||||
message: openpgp.Message.fromText(testData2),
|
||||
publicKeys: [pubBye],
|
||||
privateKeys: [hi]
|
||||
}
|
||||
).then(async encrypted => {
|
||||
const msg = await openpgp.message.readArmored(encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(encrypted);
|
||||
// Decrypting and verifying
|
||||
return openpgp.decrypt(
|
||||
{
|
||||
|
|
|
@ -44,7 +44,7 @@ module.exports = () => describe('Decrypt and decompress message tests', function
|
|||
|
||||
function runTest(key, test) {
|
||||
it(`Decrypts message compressed with ${key}`, async function () {
|
||||
const message = await openpgp.message.readArmored(test.input);
|
||||
const message = await openpgp.readArmoredMessage(test.input);
|
||||
const options = {
|
||||
passwords: password,
|
||||
message
|
||||
|
|
|
@ -27,9 +27,9 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
|
|||
// Signing message
|
||||
|
||||
openpgp.sign(
|
||||
{ message: openpgp.cleartext.fromText(testData), privateKeys: hi }
|
||||
{ message: openpgp.CleartextMessage.fromText(testData), privateKeys: hi }
|
||||
).then(async signed => {
|
||||
const msg = await openpgp.cleartext.readArmored(signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
// Verifying signed message
|
||||
return Promise.all([
|
||||
openpgp.verify(
|
||||
|
@ -37,19 +37,19 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
|
|||
).then(output => expect(output.signatures[0].valid).to.be.true),
|
||||
// Verifying detached signature
|
||||
openpgp.verify(
|
||||
{ message: openpgp.cleartext.fromText(testData),
|
||||
{ message: openpgp.CleartextMessage.fromText(testData),
|
||||
publicKeys: pubHi,
|
||||
signature: await openpgp.signature.readArmored(signed) }
|
||||
signature: await openpgp.readArmoredSignature(signed) }
|
||||
).then(output => expect(output.signatures[0].valid).to.be.true)
|
||||
]);
|
||||
}),
|
||||
// Encrypting and signing
|
||||
openpgp.encrypt(
|
||||
{ message: openpgp.message.fromText(testData2),
|
||||
{ message: openpgp.Message.fromText(testData2),
|
||||
publicKeys: [pubBye],
|
||||
privateKeys: [hi] }
|
||||
).then(async encrypted => {
|
||||
const msg = await openpgp.message.readArmored(encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(encrypted);
|
||||
// Decrypting and verifying
|
||||
return openpgp.decrypt(
|
||||
{ message: msg,
|
||||
|
@ -72,8 +72,8 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
|
|||
const testData = input.createSomeMessage();
|
||||
let options = { userIds: {name: "Hi", email: "hi@hel.lo"}, curve: "p256" };
|
||||
const firstKey = await openpgp.generateKey(options);
|
||||
const signature = await openpgp.sign({ message: openpgp.cleartext.fromText(testData), privateKeys: firstKey.key });
|
||||
const msg = await openpgp.cleartext.readArmored(signature);
|
||||
const signature = await openpgp.sign({ message: openpgp.CleartextMessage.fromText(testData), privateKeys: firstKey.key });
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signature);
|
||||
const result = await openpgp.verify({ message: msg, publicKeys: firstKey.key.toPublic()});
|
||||
expect(result.signatures[0].valid).to.be.true;
|
||||
});
|
||||
|
@ -85,11 +85,11 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38
|
|||
options = { userIds: { name: "Bye", email: "bye@good.bye" }, curve: "p256" };
|
||||
const secondKey = await openpgp.generateKey(options);
|
||||
const encrypted = await openpgp.encrypt(
|
||||
{ message: openpgp.message.fromText(testData),
|
||||
{ message: openpgp.Message.fromText(testData),
|
||||
publicKeys: [secondKey.key.toPublic()],
|
||||
privateKeys: [firstKey.key] }
|
||||
);
|
||||
const msg = await openpgp.message.readArmored(encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(encrypted);
|
||||
const result = await openpgp.decrypt(
|
||||
{ message: msg,
|
||||
privateKeys: secondKey.key,
|
||||
|
|
|
@ -141,7 +141,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
|
|||
if (data[name].pub_key) {
|
||||
return data[name].pub_key;
|
||||
}
|
||||
const pub = await openpgp.key.readArmored(data[name].pub);
|
||||
const pub = await openpgp.readArmoredKey(data[name].pub);
|
||||
expect(pub).to.exist;
|
||||
expect(pub.getKeyId().toHex()).to.equal(data[name].id);
|
||||
data[name].pub_key = pub;
|
||||
|
@ -151,7 +151,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
|
|||
if (data[name].priv_key) {
|
||||
return data[name].priv_key;
|
||||
}
|
||||
const pk = await openpgp.key.readArmored(data[name].priv);
|
||||
const pk = await openpgp.readArmoredKey(data[name].priv);
|
||||
expect(pk).to.exist;
|
||||
expect(pk.getKeyId().toHex()).to.equal(data[name].id);
|
||||
await pk.decrypt(data[name].pass);
|
||||
|
@ -175,7 +175,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
|
|||
});
|
||||
it('Verify clear signed message', async function () {
|
||||
const pub = await load_pub_key('juliet');
|
||||
const msg = await openpgp.cleartext.readArmored(data.juliet.message_signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(data.juliet.message_signed);
|
||||
return openpgp.verify({publicKeys: [pub], message: msg}).then(function(result) {
|
||||
expect(result).to.exist;
|
||||
expect(result.data).to.equal(data.juliet.message);
|
||||
|
@ -185,9 +185,9 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
|
|||
});
|
||||
it('Sign message', async function () {
|
||||
const romeoPrivate = await load_priv_key('romeo');
|
||||
const signed = await openpgp.sign({privateKeys: [romeoPrivate], message: openpgp.cleartext.fromText(data.romeo.message)});
|
||||
const signed = await openpgp.sign({privateKeys: [romeoPrivate], message: openpgp.CleartextMessage.fromText(data.romeo.message)});
|
||||
const romeoPublic = await load_pub_key('romeo');
|
||||
const msg = await openpgp.cleartext.readArmored(signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
const result = await openpgp.verify({publicKeys: [romeoPublic], message: msg});
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -198,7 +198,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
|
|||
it('Decrypt and verify message', async function () {
|
||||
const juliet = await load_pub_key('juliet');
|
||||
const romeo = await load_priv_key('romeo');
|
||||
const msg = await openpgp.message.readArmored(data.juliet.message_encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(data.juliet.message_encrypted);
|
||||
const result = await openpgp.decrypt({privateKeys: romeo, publicKeys: [juliet], message: msg});
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -209,9 +209,9 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve
|
|||
it('Encrypt and sign message', async function () {
|
||||
const romeoPrivate = await load_priv_key('romeo');
|
||||
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: openpgp.Message.fromText(data.romeo.message)});
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const romeoPublic = await load_pub_key('romeo');
|
||||
const julietPrivate = await load_priv_key('juliet');
|
||||
const result = await openpgp.decrypt({privateKeys: julietPrivate, publicKeys: [romeoPublic], message: message});
|
||||
|
|
|
@ -2052,7 +2052,7 @@ function versionSpecificTests() {
|
|||
const opt = { userIds: 'test <a@b.com>', passphrase: 'hello' };
|
||||
return openpgp.generateKey(opt).then(async function(key) {
|
||||
testPref(key.key);
|
||||
testPref(await openpgp.key.readArmored(key.publicKeyArmored));
|
||||
testPref(await openpgp.readArmoredKey(key.publicKeyArmored));
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -2098,7 +2098,7 @@ function versionSpecificTests() {
|
|||
try {
|
||||
const key = await openpgp.generateKey(opt);
|
||||
testPref(key.key);
|
||||
testPref(await openpgp.key.readArmored(key.publicKeyArmored));
|
||||
testPref(await openpgp.readArmoredKey(key.publicKeyArmored));
|
||||
} finally {
|
||||
openpgp.config.encryptionCipher = encryptionCipherVal;
|
||||
openpgp.config.preferHashAlgorithm = preferHashAlgorithmVal;
|
||||
|
@ -2112,7 +2112,7 @@ function versionSpecificTests() {
|
|||
let key;
|
||||
return openpgp.generateKey(opt).then(function(newKey) {
|
||||
key = newKey.key;
|
||||
return openpgp.message.fromText('hello').encrypt([key]);
|
||||
return openpgp.Message.fromText('hello').encrypt([key]);
|
||||
}).then(function(msg) {
|
||||
return msg.decrypt([key]);
|
||||
}).catch(function(err) {
|
||||
|
@ -2252,7 +2252,7 @@ function versionSpecificTests() {
|
|||
const userId = 'test <a@b.com>';
|
||||
const opt = { userIds: [userId], passphrase: '123', subkeys:[{}, { sign: true }] };
|
||||
return openpgp.generateKey(opt).then(async function({ privateKeyArmored }) {
|
||||
const key = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const key = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
expect(key.users.length).to.equal(1);
|
||||
expect(key.users[0].userId.userid).to.equal(userId);
|
||||
expect(key.users[0].selfCertifications[0].isPrimaryUserID).to.be.true;
|
||||
|
@ -2271,7 +2271,7 @@ function versionSpecificTests() {
|
|||
await key.decrypt('123');
|
||||
return openpgp.reformatKey({ privateKey: key, userIds: [userId] });
|
||||
}).then(async function({ privateKeyArmored }) {
|
||||
const key = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const key = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
expect(key.users.length).to.equal(1);
|
||||
expect(key.users[0].userId.userid).to.equal(userId);
|
||||
expect(key.users[0].selfCertifications[0].isPrimaryUserID).to.be.true;
|
||||
|
@ -2340,8 +2340,8 @@ function versionSpecificTests() {
|
|||
});
|
||||
|
||||
it('Sign and verify key - primary user', async function() {
|
||||
let publicKey = await openpgp.key.readArmored(pub_sig_test);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
let publicKey = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
publicKey = await publicKey.signPrimaryUser([privateKey]);
|
||||
const signatures = await publicKey.verifyPrimaryUser([privateKey]);
|
||||
|
@ -2355,9 +2355,9 @@ function versionSpecificTests() {
|
|||
});
|
||||
|
||||
it('Sign key and verify with wrong key - primary user', async function() {
|
||||
let publicKey = await openpgp.key.readArmored(pub_sig_test);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const wrongKey = await openpgp.key.readArmored(wrong_key);
|
||||
let publicKey = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
const wrongKey = await openpgp.readArmoredKey(wrong_key);
|
||||
await privateKey.decrypt('hello world');
|
||||
publicKey = await publicKey.signPrimaryUser([privateKey]);
|
||||
const signatures = await publicKey.verifyPrimaryUser([wrongKey]);
|
||||
|
@ -2371,8 +2371,8 @@ function versionSpecificTests() {
|
|||
});
|
||||
|
||||
it('Sign and verify key - all users', async function() {
|
||||
let publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
let publicKey = await openpgp.readArmoredKey(multi_uid_key);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
publicKey = await publicKey.signAllUsers([privateKey]);
|
||||
const signatures = await publicKey.verifyAllUsers([privateKey]);
|
||||
|
@ -2394,9 +2394,9 @@ function versionSpecificTests() {
|
|||
});
|
||||
|
||||
it('Sign key and verify with wrong key - all users', async function() {
|
||||
let publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const wrongKey = await openpgp.key.readArmored(wrong_key);
|
||||
let publicKey = await openpgp.readArmoredKey(multi_uid_key);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
const wrongKey = await openpgp.readArmoredKey(wrong_key);
|
||||
await privateKey.decrypt('hello world');
|
||||
publicKey = await publicKey.signAllUsers([privateKey]);
|
||||
const signatures = await publicKey.verifyAllUsers([wrongKey]);
|
||||
|
@ -2439,7 +2439,7 @@ function versionSpecificTests() {
|
|||
|
||||
it('Reformat key with no subkey with passphrase', async function() {
|
||||
const userId = 'test1 <a@b.com>';
|
||||
const key = await openpgp.key.readArmored(key_without_subkey);
|
||||
const key = await openpgp.readArmoredKey(key_without_subkey);
|
||||
const opt = { privateKey: key, userIds: [userId], passphrase: "test" };
|
||||
return openpgp.reformatKey(opt).then(function(newKey) {
|
||||
newKey = newKey.key;
|
||||
|
@ -2473,16 +2473,16 @@ function versionSpecificTests() {
|
|||
|
||||
it('Reformat key with no subkey without passphrase', async function() {
|
||||
const userId = 'test1 <a@b.com>';
|
||||
const key = await openpgp.key.readArmored(key_without_subkey);
|
||||
const key = await openpgp.readArmoredKey(key_without_subkey);
|
||||
const opt = { privateKey: key, userIds: [userId] };
|
||||
return openpgp.reformatKey(opt).then(function(newKey) {
|
||||
newKey = newKey.key;
|
||||
expect(newKey.users.length).to.equal(1);
|
||||
expect(newKey.users[0].userId.userid).to.equal(userId);
|
||||
expect(newKey.isDecrypted()).to.be.true;
|
||||
return openpgp.sign({ message: openpgp.cleartext.fromText('hello'), privateKeys: newKey, armor: true }).then(async function(signed) {
|
||||
return openpgp.sign({ message: openpgp.CleartextMessage.fromText('hello'), privateKeys: newKey, armor: true }).then(async function(signed) {
|
||||
return openpgp.verify(
|
||||
{ message: await openpgp.cleartext.readArmored(signed), publicKeys: newKey.toPublic() }
|
||||
{ message: await openpgp.readArmoredCleartextMessage(signed), publicKeys: newKey.toPublic() }
|
||||
).then(async function(verified) {
|
||||
expect(verified.signatures[0].valid).to.be.true;
|
||||
const newSigningKey = await newKey.getSigningKey();
|
||||
|
@ -2524,8 +2524,8 @@ function versionSpecificTests() {
|
|||
opt.userIds = userId2;
|
||||
return openpgp.reformatKey(opt).then(function(newKey) {
|
||||
newKey = newKey.key;
|
||||
return openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true }).then(async function(encrypted) {
|
||||
return openpgp.decrypt({ message: await openpgp.message.readArmored(encrypted), privateKeys: newKey, publicKeys: newKey.toPublic() }).then(function(decrypted) {
|
||||
return openpgp.encrypt({ message: openpgp.Message.fromText('hello'), publicKeys: newKey.toPublic(), privateKeys: newKey, armor: true }).then(async function(encrypted) {
|
||||
return openpgp.decrypt({ message: await openpgp.readArmoredMessage(encrypted), privateKeys: newKey, publicKeys: newKey.toPublic() }).then(function(decrypted) {
|
||||
expect(decrypted.data).to.equal('hello');
|
||||
expect(decrypted.signatures[0].valid).to.be.true;
|
||||
});
|
||||
|
@ -2576,7 +2576,7 @@ function versionSpecificTests() {
|
|||
// uid emma.goldman@example.net
|
||||
// ssb cv25519 2019-03-20 [E]
|
||||
// E4557C2B02FFBF4B04F87401EC336AF7133D0F85BE7FD09BAEFD9CAEB8C93965
|
||||
const key = await openpgp.key.readArmored(v5_sample_key);
|
||||
const key = await openpgp.readArmoredKey(v5_sample_key);
|
||||
expect(key.primaryKey.getFingerprint()).to.equal('19347bc9872464025f99df3ec2e0000ed9884892e1f7b3ea4c94009159569b54');
|
||||
expect(key.subKeys[0].getFingerprint()).to.equal('e4557c2b02ffbf4b04f87401ec336af7133d0f85be7fd09baefd9caeb8c93965');
|
||||
await key.verifyPrimaryKey();
|
||||
|
@ -2641,14 +2641,14 @@ module.exports = () => describe('Key', function() {
|
|||
|
||||
it('Parsing armored text with RSA key and ECC subkey', async function() {
|
||||
openpgp.config.tolerant = true;
|
||||
const pubKeys = await openpgp.key.readAllArmored(rsa_ecc_pub);
|
||||
const pubKeys = await openpgp.readArmoredKeys(rsa_ecc_pub);
|
||||
expect(pubKeys).to.exist;
|
||||
expect(pubKeys).to.have.length(1);
|
||||
expect(pubKeys[0].getKeyId().toHex()).to.equal('b8e4105cc9dedc77');
|
||||
});
|
||||
|
||||
it('Parsing armored text with two keys', async function() {
|
||||
const pubKeys = await openpgp.key.readAllArmored(twoKeys);
|
||||
const pubKeys = await openpgp.readArmoredKeys(twoKeys);
|
||||
expect(pubKeys).to.exist;
|
||||
expect(pubKeys).to.have.length(2);
|
||||
expect(pubKeys[0].getKeyId().toHex()).to.equal('4a63613a4d6e4094');
|
||||
|
@ -2656,12 +2656,12 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Parsing armored key with an authorized revocation key in a User ID self-signature', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(key_with_authorized_revocation_key);
|
||||
const pubKey = await openpgp.readArmoredKey(key_with_authorized_revocation_key);
|
||||
await expect(pubKey.getPrimaryUser()).to.be.rejectedWith('This key is intended to be revoked with an authorized key, which OpenPGP.js does not support.');
|
||||
});
|
||||
|
||||
it('Parsing armored key with an authorized revocation key in a direct-key signature', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(key_with_authorized_revocation_key_in_separate_sig);
|
||||
const pubKey = await openpgp.readArmoredKey(key_with_authorized_revocation_key_in_separate_sig);
|
||||
const primaryUser = await pubKey.getPrimaryUser();
|
||||
expect(primaryUser).to.exist;
|
||||
});
|
||||
|
@ -2682,7 +2682,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Testing key ID and fingerprint for V4 keys', async function() {
|
||||
const pubKeysV4 = await openpgp.key.readAllArmored(twoKeys);
|
||||
const pubKeysV4 = await openpgp.readArmoredKeys(twoKeys);
|
||||
expect(pubKeysV4).to.exist;
|
||||
expect(pubKeysV4).to.have.length(2);
|
||||
|
||||
|
@ -2694,14 +2694,14 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Create new key ID with fromId()', async function() {
|
||||
const [pubKeyV4] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const [pubKeyV4] = await openpgp.readArmoredKeys(twoKeys);
|
||||
const keyId = pubKeyV4.getKeyId();
|
||||
const newKeyId = keyId.constructor.fromId(keyId.toHex());
|
||||
expect(newKeyId.toHex()).to.equal(keyId.toHex());
|
||||
});
|
||||
|
||||
it('Testing key method getSubkeys', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_sig_test);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_sig_test);
|
||||
expect(pubKey).to.exist;
|
||||
|
||||
const packetlist = new openpgp.PacketList();
|
||||
|
@ -2716,12 +2716,12 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Verify status of revoked primary key', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_revoked_subkeys);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_revoked_subkeys);
|
||||
await expect(pubKey.verifyPrimaryKey()).to.be.rejectedWith('Primary key is revoked');
|
||||
});
|
||||
|
||||
it('Verify status of revoked subkey', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_sig_test);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_sig_test);
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey.subKeys).to.exist;
|
||||
expect(pubKey.subKeys).to.have.length(2);
|
||||
|
@ -2732,13 +2732,13 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Verify status of key with non-self revocation signature', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(key_with_revoked_third_party_cert);
|
||||
const pubKey = await openpgp.readArmoredKey(key_with_revoked_third_party_cert);
|
||||
const [selfCertification] = await pubKey.verifyPrimaryUser();
|
||||
const publicSigningKey = await pubKey.getSigningKey();
|
||||
expect(selfCertification.keyid.toHex()).to.equal(publicSigningKey.getKeyId().toHex());
|
||||
expect(selfCertification.valid).to.be.true;
|
||||
|
||||
const certifyingKey = await openpgp.key.readArmored(certifying_key);
|
||||
const certifyingKey = await openpgp.readArmoredKey(certifying_key);
|
||||
const certifyingSigningKey = await certifyingKey.getSigningKey();
|
||||
const signatures = await pubKey.verifyPrimaryUser([certifyingKey]);
|
||||
expect(signatures.length).to.equal(2);
|
||||
|
@ -2752,7 +2752,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Verify certificate of key with future creation date', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(key_created_2030);
|
||||
const pubKey = await openpgp.readArmoredKey(key_created_2030);
|
||||
const user = pubKey.users[0];
|
||||
await user.verifyCertificate(pubKey.primaryKey, user.selfCertifications[0], [pubKey], pubKey.primaryKey.created);
|
||||
const verifyAllResult = await user.verifyAllCertifications(pubKey.primaryKey, [pubKey], pubKey.primaryKey.created);
|
||||
|
@ -2761,7 +2761,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Evaluate key flags to find valid encryption key packet', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_sig_test);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_sig_test);
|
||||
// remove subkeys
|
||||
pubKey.subKeys = [];
|
||||
// primary key has only key flags for signing
|
||||
|
@ -2770,17 +2770,17 @@ module.exports = () => describe('Key', function() {
|
|||
|
||||
it('should not decrypt using a sign-only RSA key, unless explicitly configured', async function () {
|
||||
const allowSigningKeyDecryption = openpgp.config.allowInsecureDecryptionWithSigningKeys;
|
||||
const key = await openpgp.key.readArmored(rsaSignOnly);
|
||||
const key = await openpgp.readArmoredKey(rsaSignOnly);
|
||||
try {
|
||||
openpgp.config.allowInsecureDecryptionWithSigningKeys = false;
|
||||
await expect(openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(encryptedRsaSignOnly),
|
||||
message: await openpgp.readArmoredMessage(encryptedRsaSignOnly),
|
||||
privateKeys: key
|
||||
})).to.be.rejectedWith(/Session key decryption failed/);
|
||||
|
||||
openpgp.config.allowInsecureDecryptionWithSigningKeys = true;
|
||||
await expect(openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(encryptedRsaSignOnly),
|
||||
message: await openpgp.readArmoredMessage(encryptedRsaSignOnly),
|
||||
privateKeys: key
|
||||
})).to.be.fulfilled;
|
||||
} finally {
|
||||
|
@ -2789,33 +2789,33 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Method getExpirationTime V4 Key', async function() {
|
||||
const [, pubKey] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const [, pubKey] = await openpgp.readArmoredKeys(twoKeys);
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.Key);
|
||||
const expirationTime = await pubKey.getExpirationTime();
|
||||
expect(expirationTime.toISOString()).to.be.equal('2018-11-26T10:58:29.000Z');
|
||||
});
|
||||
|
||||
it('Method getExpirationTime expired V4 Key', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(expiredKey);
|
||||
const pubKey = await openpgp.readArmoredKey(expiredKey);
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.Key);
|
||||
const expirationTime = await pubKey.getExpirationTime();
|
||||
expect(expirationTime.toISOString()).to.be.equal('1970-01-01T00:22:18.000Z');
|
||||
});
|
||||
|
||||
it('Method getExpirationTime V4 SubKey', async function() {
|
||||
const [, pubKey] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const [, pubKey] = await openpgp.readArmoredKeys(twoKeys);
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.Key);
|
||||
const expirationTime = await pubKey.subKeys[0].getExpirationTime(pubKey.primaryKey);
|
||||
expect(expirationTime.toISOString()).to.be.equal('2018-11-26T10:58:29.000Z');
|
||||
});
|
||||
|
||||
it('Method getExpirationTime V4 Key with capabilities', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(priv_key_2000_2008);
|
||||
const pubKey = await openpgp.readArmoredKey(priv_key_2000_2008);
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.Key);
|
||||
pubKey.users[0].selfCertifications[0].keyFlags = [1];
|
||||
const expirationTime = await pubKey.getExpirationTime();
|
||||
expect(expirationTime).to.equal(Infinity);
|
||||
|
@ -2824,9 +2824,9 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('Method getExpirationTime V4 Key with capabilities - capable primary key', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(priv_key_2000_2008);
|
||||
const pubKey = await openpgp.readArmoredKey(priv_key_2000_2008);
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.key.Key);
|
||||
expect(pubKey).to.be.an.instanceof(openpgp.Key);
|
||||
const expirationTime = await pubKey.getExpirationTime();
|
||||
expect(expirationTime).to.equal(Infinity);
|
||||
const encryptExpirationTime = await pubKey.getExpirationTime('encrypt_sign');
|
||||
|
@ -2834,12 +2834,12 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it("decrypt() - throw if key parameters don't correspond", async function() {
|
||||
const key = await openpgp.key.readArmored(mismatchingKeyParams);
|
||||
const key = await openpgp.readArmoredKey(mismatchingKeyParams);
|
||||
await expect(key.decrypt('userpass')).to.be.rejectedWith('Key is invalid');
|
||||
});
|
||||
|
||||
it("decrypt(keyId) - throw if key parameters don't correspond", async function() {
|
||||
const key = await openpgp.key.readArmored(mismatchingKeyParams);
|
||||
const key = await openpgp.readArmoredKey(mismatchingKeyParams);
|
||||
const subKeyId = key.subKeys[0].getKeyId();
|
||||
await expect(key.decrypt('userpass', subKeyId)).to.be.rejectedWith('Key is invalid');
|
||||
});
|
||||
|
@ -2850,34 +2850,34 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it("validate() - throw if all-gnu-dummy key", async function() {
|
||||
const key = await openpgp.key.readArmored(gnuDummyKey);
|
||||
const key = await openpgp.readArmoredKey(gnuDummyKey);
|
||||
await expect(key.validate()).to.be.rejectedWith('Cannot validate an all-gnu-dummy key');
|
||||
});
|
||||
|
||||
it("validate() - gnu-dummy primary key with signing subkey", async function() {
|
||||
const key = await openpgp.key.readArmored(gnuDummyKeySigningSubkey);
|
||||
const key = await openpgp.readArmoredKey(gnuDummyKeySigningSubkey);
|
||||
await expect(key.validate()).to.not.be.rejected;
|
||||
});
|
||||
|
||||
it("validate() - gnu-dummy primary key with encryption subkey", async function() {
|
||||
const key = await openpgp.key.readArmored(dsaGnuDummyKeyWithElGamalSubkey);
|
||||
const key = await openpgp.readArmoredKey(dsaGnuDummyKeyWithElGamalSubkey);
|
||||
await expect(key.validate()).to.not.be.rejected;
|
||||
});
|
||||
|
||||
it("validate() - curve ed25519 (eddsa) cannot be used for ecdsa", async function() {
|
||||
const key = await openpgp.key.readArmored(eddsaKeyAsEcdsa);
|
||||
const key = await openpgp.readArmoredKey(eddsaKeyAsEcdsa);
|
||||
await expect(key.validate()).to.be.rejectedWith('Key is invalid');
|
||||
});
|
||||
|
||||
it('makeDummy() - the converted key can be parsed', async function() {
|
||||
const { key: key } = await openpgp.generateKey({ userIds: 'dummy <dummy@alice.com>' });
|
||||
const { key } = await openpgp.generateKey({ userIds: 'dummy <dummy@alice.com>' });
|
||||
key.primaryKey.makeDummy();
|
||||
const parsedKeys = await openpgp.key.readArmored(key.armor());
|
||||
const parsedKeys = await openpgp.readArmoredKey(key.armor());
|
||||
expect(parsedKeys).to.not.be.empty;
|
||||
});
|
||||
|
||||
it('makeDummy() - the converted key can be encrypted and decrypted', async function() {
|
||||
const { key: key } = await openpgp.generateKey({ userIds: 'dummy <dummy@alice.com>' });
|
||||
const { key } = await openpgp.generateKey({ userIds: 'dummy <dummy@alice.com>' });
|
||||
const passphrase = 'passphrase';
|
||||
key.primaryKey.makeDummy();
|
||||
expect(key.isDecrypted()).to.be.true;
|
||||
|
@ -2888,7 +2888,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('makeDummy() - the converted key is valid but can no longer sign', async function() {
|
||||
const key = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const key = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await key.decrypt('hello world');
|
||||
expect(key.primaryKey.isDummy()).to.be.false;
|
||||
key.primaryKey.makeDummy();
|
||||
|
@ -2898,23 +2898,23 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('makeDummy() - subkeys of the converted key can still sign', async function() {
|
||||
const key = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const key = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await key.decrypt('hello world');
|
||||
expect(key.primaryKey.isDummy()).to.be.false;
|
||||
key.primaryKey.makeDummy();
|
||||
expect(key.primaryKey.isDummy()).to.be.true;
|
||||
await expect(openpgp.sign({ message: openpgp.message.fromText('test'), privateKeys: [key] })).to.be.fulfilled;
|
||||
await expect(openpgp.sign({ message: openpgp.Message.fromText('test'), privateKeys: [key] })).to.be.fulfilled;
|
||||
});
|
||||
|
||||
it('clearPrivateParams() - check that private key can no longer be used', async function() {
|
||||
const key = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const key = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await key.decrypt('hello world');
|
||||
await key.clearPrivateParams();
|
||||
await expect(key.validate()).to.be.rejectedWith('Key is not decrypted');
|
||||
});
|
||||
|
||||
it('clearPrivateParams() - detect that private key parameters were removed', async function() {
|
||||
const key = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const key = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await key.decrypt('hello world');
|
||||
const signingKeyPacket = key.subKeys[0].keyPacket;
|
||||
const privateParams = signingKeyPacket.privateParams;
|
||||
|
@ -2927,7 +2927,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('clearPrivateParams() - detect that private key parameters were zeroed out', async function() {
|
||||
const key = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const key = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await key.decrypt('hello world');
|
||||
const signingKeyPacket = key.subKeys[0].keyPacket;
|
||||
const privateParams = {};
|
||||
|
@ -2943,15 +2943,15 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - throw error if fingerprints not equal', async function() {
|
||||
const keys = await openpgp.key.readAllArmored(twoKeys);
|
||||
const keys = await openpgp.readArmoredKeys(twoKeys);
|
||||
await expect(keys[0].update.bind(
|
||||
keys[0], keys[1]
|
||||
)()).to.be.rejectedWith('Key update method: fingerprints of keys not equal');
|
||||
});
|
||||
|
||||
it('update() - merge revocation signatures', async function() {
|
||||
const source = await openpgp.key.readArmored(pub_revoked_subkeys);
|
||||
const dest = await openpgp.key.readArmored(pub_revoked_subkeys);
|
||||
const source = await openpgp.readArmoredKey(pub_revoked_subkeys);
|
||||
const dest = await openpgp.readArmoredKey(pub_revoked_subkeys);
|
||||
expect(source.revocationSignatures).to.exist;
|
||||
dest.revocationSignatures = [];
|
||||
return dest.update(source).then(() => {
|
||||
|
@ -2960,8 +2960,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge user', async function() {
|
||||
const source = await openpgp.key.readArmored(pub_sig_test);
|
||||
const dest = await openpgp.key.readArmored(pub_sig_test);
|
||||
const source = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const dest = await openpgp.readArmoredKey(pub_sig_test);
|
||||
expect(source.users[1]).to.exist;
|
||||
dest.users.pop();
|
||||
return dest.update(source).then(() => {
|
||||
|
@ -2971,8 +2971,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge user - other and certification revocation signatures', async function() {
|
||||
const source = await openpgp.key.readArmored(pub_sig_test);
|
||||
const dest = await openpgp.key.readArmored(pub_sig_test);
|
||||
const source = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const dest = await openpgp.readArmoredKey(pub_sig_test);
|
||||
expect(source.users[1].otherCertifications).to.exist;
|
||||
expect(source.users[1].revocationSignatures).to.exist;
|
||||
dest.users[1].otherCertifications = [];
|
||||
|
@ -2986,8 +2986,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge subkey', async function() {
|
||||
const source = await openpgp.key.readArmored(pub_sig_test);
|
||||
const dest = await openpgp.key.readArmored(pub_sig_test);
|
||||
const source = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const dest = await openpgp.readArmoredKey(pub_sig_test);
|
||||
expect(source.subKeys[1]).to.exist;
|
||||
dest.subKeys.pop();
|
||||
return dest.update(source).then(() => {
|
||||
|
@ -2999,8 +2999,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge subkey - revocation signature', async function() {
|
||||
const source = await openpgp.key.readArmored(pub_sig_test);
|
||||
const dest = await openpgp.key.readArmored(pub_sig_test);
|
||||
const source = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const dest = await openpgp.readArmoredKey(pub_sig_test);
|
||||
expect(source.subKeys[0].revocationSignatures).to.exist;
|
||||
dest.subKeys[0].revocationSignatures = [];
|
||||
return dest.update(source).then(() => {
|
||||
|
@ -3010,8 +3010,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge private key into public key', async function() {
|
||||
const source = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const [dest] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const source = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
const [dest] = await openpgp.readArmoredKeys(twoKeys);
|
||||
expect(dest.isPublic()).to.be.true;
|
||||
return dest.update(source).then(() => {
|
||||
expect(dest.isPrivate()).to.be.true;
|
||||
|
@ -3030,8 +3030,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge private key into public key - no subkeys', async function() {
|
||||
const source = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const [dest] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const source = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
const [dest] = await openpgp.readArmoredKeys(twoKeys);
|
||||
source.subKeys = [];
|
||||
dest.subKeys = [];
|
||||
expect(dest.isPublic()).to.be.true;
|
||||
|
@ -3049,8 +3049,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge private key into public key - mismatch throws error', async function() {
|
||||
const source = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const [dest] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const source = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
const [dest] = await openpgp.readArmoredKeys(twoKeys);
|
||||
source.subKeys = [];
|
||||
expect(dest.subKeys).to.exist;
|
||||
expect(dest.isPublic()).to.be.true;
|
||||
|
@ -3059,8 +3059,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge subkey binding signatures', async function() {
|
||||
const source = await openpgp.key.readArmored(pgp_desktop_pub);
|
||||
const dest = await openpgp.key.readArmored(pgp_desktop_priv);
|
||||
const source = await openpgp.readArmoredKey(pgp_desktop_pub);
|
||||
const dest = await openpgp.readArmoredKey(pgp_desktop_priv);
|
||||
expect(source.subKeys[0].bindingSignatures[0]).to.exist;
|
||||
await source.subKeys[0].verify(source.primaryKey);
|
||||
expect(dest.subKeys[0].bindingSignatures[0]).to.not.exist;
|
||||
|
@ -3070,8 +3070,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('update() - merge multiple subkey binding signatures', async function() {
|
||||
const source = await openpgp.key.readArmored(multipleBindingSignatures);
|
||||
const dest = await openpgp.key.readArmored(multipleBindingSignatures);
|
||||
const source = await openpgp.readArmoredKey(multipleBindingSignatures);
|
||||
const dest = await openpgp.readArmoredKey(multipleBindingSignatures);
|
||||
// remove last subkey binding signature of destination subkey
|
||||
dest.subKeys[0].bindingSignatures.length = 1;
|
||||
expect((await source.subKeys[0].getExpirationTime(source.primaryKey)).toISOString()).to.equal('2015-10-18T07:41:30.000Z');
|
||||
|
@ -3084,7 +3084,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('revoke() - primary key', async function() {
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
await privKey.revoke({
|
||||
|
@ -3102,8 +3102,8 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('revoke() - subkey', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
const subKey = pubKey.subKeys[0];
|
||||
|
@ -3121,15 +3121,15 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('applyRevocationCertificate() should produce the same revoked key as GnuPG', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm4);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm4);
|
||||
|
||||
return pubKey.applyRevocationCertificate(revocation_certificate_arm4).then(async revKey => {
|
||||
expect(revKey.armor()).to.equal((await openpgp.key.readArmored(revoked_key_arm4)).armor());
|
||||
expect(revKey.armor()).to.equal((await openpgp.readArmoredKey(revoked_key_arm4)).armor());
|
||||
});
|
||||
});
|
||||
|
||||
it('getRevocationCertificate() should produce the same revocation certificate as GnuPG', async function() {
|
||||
const revKey = await openpgp.key.readArmored(revoked_key_arm4);
|
||||
const revKey = await openpgp.readArmoredKey(revoked_key_arm4);
|
||||
const revocationCertificate = await revKey.getRevocationCertificate();
|
||||
|
||||
const input = await openpgp.armor.decode(revocation_certificate_arm4);
|
||||
|
@ -3141,7 +3141,7 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it('getRevocationCertificate() should have an appropriate comment', async function() {
|
||||
const revKey = await openpgp.key.readArmored(revoked_key_arm4);
|
||||
const revKey = await openpgp.readArmoredKey(revoked_key_arm4);
|
||||
const revocationCertificate = await revKey.getRevocationCertificate();
|
||||
|
||||
expect(revocationCertificate).to.match(/Comment: This is a revocation certificate/);
|
||||
|
@ -3149,44 +3149,44 @@ module.exports = () => describe('Key', function() {
|
|||
});
|
||||
|
||||
it("getPreferredAlgo('symmetric') - one key - AES256", async function() {
|
||||
const [key1] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const prefAlgo = await openpgp.key.getPreferredAlgo('symmetric', [key1]);
|
||||
const [key1] = await openpgp.readArmoredKeys(twoKeys);
|
||||
const prefAlgo = await openpgp.getPreferredAlgo('symmetric', [key1]);
|
||||
expect(prefAlgo).to.equal(openpgp.enums.symmetric.aes256);
|
||||
});
|
||||
|
||||
it("getPreferredAlgo('symmetric') - two key - AES192", async function() {
|
||||
const keys = await openpgp.key.readAllArmored(twoKeys);
|
||||
const keys = await openpgp.readArmoredKeys(twoKeys);
|
||||
const key1 = keys[0];
|
||||
const key2 = keys[1];
|
||||
const primaryUser = await key2.getPrimaryUser();
|
||||
primaryUser.selfCertification.preferredSymmetricAlgorithms = [6,8,3];
|
||||
const prefAlgo = await openpgp.key.getPreferredAlgo('symmetric', [key1, key2]);
|
||||
const prefAlgo = await openpgp.getPreferredAlgo('symmetric', [key1, key2]);
|
||||
expect(prefAlgo).to.equal(openpgp.enums.symmetric.aes192);
|
||||
});
|
||||
|
||||
it("getPreferredAlgo('symmetric') - two key - one without pref", async function() {
|
||||
const keys = await openpgp.key.readAllArmored(twoKeys);
|
||||
const keys = await openpgp.readArmoredKeys(twoKeys);
|
||||
const key1 = keys[0];
|
||||
const key2 = keys[1];
|
||||
const primaryUser = await key2.getPrimaryUser();
|
||||
primaryUser.selfCertification.preferredSymmetricAlgorithms = null;
|
||||
const prefAlgo = await openpgp.key.getPreferredAlgo('symmetric', [key1, key2]);
|
||||
const prefAlgo = await openpgp.getPreferredAlgo('symmetric', [key1, key2]);
|
||||
expect(prefAlgo).to.equal(openpgp.enums.symmetric.aes128);
|
||||
});
|
||||
|
||||
it("getPreferredAlgo('aead') - one key - OCB", async function() {
|
||||
const [key1] = await openpgp.key.readAllArmored(twoKeys);
|
||||
const [key1] = await openpgp.readArmoredKeys(twoKeys);
|
||||
const primaryUser = await key1.getPrimaryUser();
|
||||
primaryUser.selfCertification.features = [7]; // Monkey-patch AEAD feature flag
|
||||
primaryUser.selfCertification.preferredAeadAlgorithms = [2,1];
|
||||
const prefAlgo = await openpgp.key.getPreferredAlgo('aead', [key1]);
|
||||
const prefAlgo = await openpgp.getPreferredAlgo('aead', [key1]);
|
||||
expect(prefAlgo).to.equal(openpgp.enums.aead.ocb);
|
||||
const supported = await openpgp.key.isAeadSupported([key1]);
|
||||
const supported = await openpgp.isAeadSupported([key1]);
|
||||
expect(supported).to.be.true;
|
||||
});
|
||||
|
||||
it("getPreferredAlgo('aead') - two key - one without pref", async function() {
|
||||
const keys = await openpgp.key.readAllArmored(twoKeys);
|
||||
const keys = await openpgp.readArmoredKeys(twoKeys);
|
||||
const key1 = keys[0];
|
||||
const key2 = keys[1];
|
||||
const primaryUser = await key1.getPrimaryUser();
|
||||
|
@ -3194,33 +3194,33 @@ module.exports = () => describe('Key', function() {
|
|||
primaryUser.selfCertification.preferredAeadAlgorithms = [2,1];
|
||||
const primaryUser2 = await key2.getPrimaryUser();
|
||||
primaryUser2.selfCertification.features = [7]; // Monkey-patch AEAD feature flag
|
||||
const prefAlgo = await openpgp.key.getPreferredAlgo('aead', [key1, key2]);
|
||||
const prefAlgo = await openpgp.getPreferredAlgo('aead', [key1, key2]);
|
||||
expect(prefAlgo).to.equal(openpgp.enums.aead.eax);
|
||||
const supported = await openpgp.key.isAeadSupported([key1, key2]);
|
||||
const supported = await openpgp.isAeadSupported([key1, key2]);
|
||||
expect(supported).to.be.true;
|
||||
});
|
||||
|
||||
it("getPreferredAlgo('aead') - two key - one with no support", async function() {
|
||||
const keys = await openpgp.key.readAllArmored(twoKeys);
|
||||
const keys = await openpgp.readArmoredKeys(twoKeys);
|
||||
const key1 = keys[0];
|
||||
const key2 = keys[1];
|
||||
const primaryUser = await key1.getPrimaryUser();
|
||||
primaryUser.selfCertification.features = [7]; // Monkey-patch AEAD feature flag
|
||||
primaryUser.selfCertification.preferredAeadAlgorithms = [2,1];
|
||||
const prefAlgo = await openpgp.key.getPreferredAlgo('aead', [key1, key2]);
|
||||
const prefAlgo = await openpgp.getPreferredAlgo('aead', [key1, key2]);
|
||||
expect(prefAlgo).to.equal(openpgp.enums.aead.eax);
|
||||
const supported = await openpgp.key.isAeadSupported([key1, key2]);
|
||||
const supported = await openpgp.isAeadSupported([key1, key2]);
|
||||
expect(supported).to.be.false;
|
||||
});
|
||||
|
||||
it('User attribute packet read & write', async function() {
|
||||
const key = await openpgp.key.readArmored(user_attr_key);
|
||||
const key2 = await openpgp.key.readArmored(key.armor());
|
||||
const key = await openpgp.readArmoredKey(user_attr_key);
|
||||
const key2 = await openpgp.readArmoredKey(key.armor());
|
||||
expect(key.users[1].userAttribute).eql(key2.users[1].userAttribute);
|
||||
});
|
||||
|
||||
it('getPrimaryUser()', async function() {
|
||||
const key = await openpgp.key.readArmored(pub_sig_test);
|
||||
const key = await openpgp.readArmoredKey(pub_sig_test);
|
||||
const primUser = await key.getPrimaryUser();
|
||||
expect(primUser).to.exist;
|
||||
expect(primUser.user.userId.userid).to.equal('Signature Test <signature@test.com>');
|
||||
|
@ -3243,13 +3243,13 @@ Vz/bMCJoAShgybW1r6kRWejybzIjFSLnx/YA/iLZeo5UNdlXRJco+15RbFiNSAbw
|
|||
VYGdb3eNlV8CfoEC
|
||||
=FYbP
|
||||
-----END PGP PRIVATE KEY BLOCK-----`;
|
||||
const key = await openpgp.key.readArmored(keyWithoutUserID);
|
||||
const key = await openpgp.readArmoredKey(keyWithoutUserID);
|
||||
await expect(key.getPrimaryUser()).to.be.rejectedWith('Could not find valid self-signature in key 3ce893915c44212f');
|
||||
});
|
||||
|
||||
it('Generate session key - latest created user', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const publicKey = await openpgp.readArmoredKey(multi_uid_key);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
// Set second user to prefer aes128. We should select this user by default, since it was created later.
|
||||
publicKey.users[1].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128];
|
||||
|
@ -3258,8 +3258,8 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('Generate session key - primary user', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const publicKey = await openpgp.readArmoredKey(multi_uid_key);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
// Set first user to primary. We should select this user by default.
|
||||
publicKey.users[0].selfCertifications[0].isPrimaryUserID = true;
|
||||
|
@ -3270,8 +3270,8 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('Generate session key - specific user', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const publicKey = await openpgp.readArmoredKey(multi_uid_key);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
// Set first user to primary. We won't select this user, this is to test that.
|
||||
publicKey.users[0].selfCertifications[0].isPrimaryUserID = true;
|
||||
|
@ -3279,23 +3279,23 @@ VYGdb3eNlV8CfoEC
|
|||
publicKey.users[1].selfCertifications[0].preferredSymmetricAlgorithms = [openpgp.enums.symmetric.aes128];
|
||||
const sessionKey = await openpgp.generateSessionKey({ publicKeys: publicKey, toUserIds: { name: 'Test User', email: 'b@c.com' } });
|
||||
expect(sessionKey.algorithm).to.equal('aes128');
|
||||
await openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'b@c.com' }, armor: false });
|
||||
await expect(openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'c@c.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
||||
await openpgp.encrypt({ message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'b@c.com' }, armor: false });
|
||||
await expect(openpgp.encrypt({ message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, toUserIds: { name: 'Test User', email: 'c@c.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
||||
});
|
||||
|
||||
it('Fails to encrypt to User ID-less key', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(uidlessKey);
|
||||
const publicKey = await openpgp.readArmoredKey(uidlessKey);
|
||||
expect(publicKey.users.length).to.equal(0);
|
||||
const privateKey = await openpgp.key.readArmored(uidlessKey);
|
||||
const privateKey = await openpgp.readArmoredKey(uidlessKey);
|
||||
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: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, armor: false })).to.be.rejectedWith('Could not find primary user');
|
||||
});
|
||||
|
||||
it('Sign - specific user', async function() {
|
||||
const publicKey = await openpgp.key.readArmored(multi_uid_key);
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const publicKey = await openpgp.readArmoredKey(multi_uid_key);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const privateKeyClone = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKeyClone = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
// Duplicate user
|
||||
privateKey.users.push(privateKeyClone.users[0]);
|
||||
// Set first user to primary. We won't select this user, this is to test that.
|
||||
|
@ -3304,48 +3304,48 @@ VYGdb3eNlV8CfoEC
|
|||
privateKey.users[0].userId.parse('Test User <b@c.com>');
|
||||
// Set second user to prefer aes128. We will select this user.
|
||||
privateKey.users[1].selfCertifications[0].preferredHashAlgorithms = [openpgp.enums.hash.sha512];
|
||||
const signed = await openpgp.sign({ message: openpgp.message.fromText('hello'), privateKeys: privateKey, fromUserIds: { name: 'Test McTestington', email: 'test@example.com' }, armor: false });
|
||||
const signature = await openpgp.message.read(signed);
|
||||
const signed = await openpgp.sign({ message: openpgp.Message.fromText('hello'), privateKeys: privateKey, fromUserIds: { name: 'Test McTestington', email: 'test@example.com' }, armor: false });
|
||||
const signature = await openpgp.readMessage(signed);
|
||||
expect(signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
|
||||
const encrypted = await openpgp.encrypt({ message: openpgp.message.fromText('hello'), passwords: 'test', privateKeys: privateKey, fromUserIds: { name: 'Test McTestington', email: 'test@example.com' }, armor: false });
|
||||
const { signatures } = await openpgp.decrypt({ message: await openpgp.message.read(encrypted), passwords: 'test' });
|
||||
const encrypted = await openpgp.encrypt({ message: openpgp.Message.fromText('hello'), passwords: 'test', privateKeys: privateKey, fromUserIds: { name: 'Test McTestington', email: 'test@example.com' }, armor: false });
|
||||
const { signatures } = await openpgp.decrypt({ message: await openpgp.readMessage(encrypted), passwords: 'test' });
|
||||
expect(signatures[0].signature.packets[0].hashAlgorithm).to.equal(openpgp.enums.hash.sha512);
|
||||
await expect(openpgp.encrypt({ message: openpgp.message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIds: { name: 'Not Test McTestington', email: 'test@example.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
||||
await expect(openpgp.encrypt({ message: openpgp.Message.fromText('hello'), publicKeys: publicKey, privateKeys: privateKey, fromUserIds: { name: 'Not Test McTestington', email: 'test@example.com' }, armor: false })).to.be.rejectedWith('Could not find user that matches that user ID');
|
||||
});
|
||||
|
||||
it('Find a valid subkey binding signature among many invalid ones', async function() {
|
||||
const key = await openpgp.key.readArmored(valid_binding_sig_among_many_expired_sigs_pub);
|
||||
const key = await openpgp.readArmoredKey(valid_binding_sig_among_many_expired_sigs_pub);
|
||||
expect(await key.getEncryptionKey()).to.not.be.null;
|
||||
});
|
||||
|
||||
it('Selects the most recent subkey binding signature', async function() {
|
||||
const key = await openpgp.key.readArmored(multipleBindingSignatures);
|
||||
const key = await openpgp.readArmoredKey(multipleBindingSignatures);
|
||||
expect((await key.subKeys[0].getExpirationTime(key.primaryKey)).toISOString()).to.equal('2015-10-18T07:41:30.000Z');
|
||||
});
|
||||
|
||||
it('Selects the most recent non-expired subkey binding signature', async function() {
|
||||
const key = await openpgp.key.readArmored(multipleBindingSignatures);
|
||||
const key = await openpgp.readArmoredKey(multipleBindingSignatures);
|
||||
key.subKeys[0].bindingSignatures[1].signatureNeverExpires = false;
|
||||
key.subKeys[0].bindingSignatures[1].signatureExpirationTime = 0;
|
||||
expect((await key.subKeys[0].getExpirationTime(key.primaryKey)).toISOString()).to.equal('2018-09-07T06:03:37.000Z');
|
||||
});
|
||||
|
||||
it('Selects the most recent valid subkey binding signature', async function() {
|
||||
const key = await openpgp.key.readArmored(multipleBindingSignatures);
|
||||
const key = await openpgp.readArmoredKey(multipleBindingSignatures);
|
||||
key.subKeys[0].bindingSignatures[1].signatureData[0]++;
|
||||
expect((await key.subKeys[0].getExpirationTime(key.primaryKey)).toISOString()).to.equal('2018-09-07T06:03:37.000Z');
|
||||
});
|
||||
|
||||
it('Handles a key with no valid subkey binding signatures gracefully', async function() {
|
||||
const key = await openpgp.key.readArmored(multipleBindingSignatures);
|
||||
const key = await openpgp.readArmoredKey(multipleBindingSignatures);
|
||||
key.subKeys[0].bindingSignatures[0].signatureData[0]++;
|
||||
key.subKeys[0].bindingSignatures[1].signatureData[0]++;
|
||||
expect(await key.subKeys[0].getExpirationTime(key.primaryKey)).to.be.null;
|
||||
});
|
||||
|
||||
it('Reject encryption with revoked primary user', async function() {
|
||||
const key = await openpgp.key.readArmored(pub_revoked_subkeys);
|
||||
return openpgp.encrypt({ publicKeys: [key], message: openpgp.message.fromText('random data') }).then(() => {
|
||||
const key = await openpgp.readArmoredKey(pub_revoked_subkeys);
|
||||
return openpgp.encrypt({ publicKeys: [key], message: openpgp.Message.fromText('random data') }).then(() => {
|
||||
throw new Error('encryptSessionKey should not encrypt with revoked public key');
|
||||
}).catch(function(error) {
|
||||
expect(error.message).to.equal('Error encrypting message: Primary user is revoked');
|
||||
|
@ -3353,10 +3353,10 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('Reject encryption with revoked subkey', async function() {
|
||||
const key = await openpgp.key.readArmored(pub_revoked_subkeys);
|
||||
const key = await openpgp.readArmoredKey(pub_revoked_subkeys);
|
||||
key.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: openpgp.Message.fromText('random data'), date: new Date(1386842743000) }).then(() => {
|
||||
throw new Error('encryptSessionKey should not encrypt with revoked public key');
|
||||
}).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');
|
||||
|
@ -3364,8 +3364,8 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('Reject encryption with key revoked with appended revocation cert', async function() {
|
||||
const key = await openpgp.key.readArmored(pub_revoked_with_cert);
|
||||
return openpgp.encrypt({ publicKeys: [key], message: openpgp.message.fromText('random data') }).then(() => {
|
||||
const key = await openpgp.readArmoredKey(pub_revoked_with_cert);
|
||||
return openpgp.encrypt({ publicKeys: [key], message: openpgp.Message.fromText('random data') }).then(() => {
|
||||
throw new Error('encryptSessionKey should not encrypt with revoked public key');
|
||||
}).catch(function(error) {
|
||||
expect(error.message).to.equal('Error encrypting message: Primary key is revoked');
|
||||
|
@ -3373,8 +3373,8 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('Merge key with another key with non-ID user attributes', async function() {
|
||||
const key = await openpgp.key.readArmored(mergeKey1);
|
||||
const updateKey = await openpgp.key.readArmored(mergeKey2);
|
||||
const key = await openpgp.readArmoredKey(mergeKey1);
|
||||
const updateKey = await openpgp.readArmoredKey(mergeKey2);
|
||||
expect(key).to.exist;
|
||||
expect(updateKey).to.exist;
|
||||
expect(key.users).to.have.length(1);
|
||||
|
@ -3389,7 +3389,7 @@ VYGdb3eNlV8CfoEC
|
|||
it("Should throw when trying to encrypt a key that's already encrypted", async function() {
|
||||
await expect((async function() {
|
||||
const { privateKeyArmored } = await openpgp.generateKey({ userIds: [{ email: 'hello@user.com' }], passphrase: 'pass' });
|
||||
const k = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const k = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await k.decrypt('pass');
|
||||
await k.encrypt('pass');
|
||||
await k.encrypt('pass');
|
||||
|
@ -3404,12 +3404,12 @@ VYGdb3eNlV8CfoEC
|
|||
rsaOpt = { rsaBits: rsaBits };
|
||||
}
|
||||
it('create and add a new rsa subkey to stored rsa key', async function() {
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const total = privateKey.subKeys.length;
|
||||
let newPrivateKey = await privateKey.addSubkey(rsaOpt);
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
expect(subKey).to.exist;
|
||||
expect(newPrivateKey.subKeys.length).to.be.equal(total + 1);
|
||||
|
@ -3422,21 +3422,21 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('should throw when trying to encrypt a subkey separately from key', async function() {
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const opt = { rsaBits: rsaBits, passphrase: 'subkey passphrase' };
|
||||
await expect(privateKey.addSubkey(opt)).to.be.rejectedWith('Subkey could not be encrypted here, please encrypt whole key');
|
||||
});
|
||||
|
||||
it('encrypt and decrypt key with added subkey', async function() {
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const total = privateKey.subKeys.length;
|
||||
let newPrivateKey = await privateKey.addSubkey(rsaOpt);
|
||||
newPrivateKey = await openpgp.key.readArmored(newPrivateKey.armor());
|
||||
newPrivateKey = await openpgp.readArmoredKey(newPrivateKey.armor());
|
||||
await newPrivateKey.encrypt('12345678');
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
const importedPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
const importedPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
await importedPrivateKey.decrypt('12345678');
|
||||
const subKey = importedPrivateKey.subKeys[total];
|
||||
expect(subKey).to.exist;
|
||||
|
@ -3454,7 +3454,7 @@ VYGdb3eNlV8CfoEC
|
|||
const subKey1 = newPrivateKey.subKeys[total];
|
||||
await newPrivateKey.encrypt('12345678');
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
await newPrivateKey.decrypt('12345678');
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
expect(subKey.isDecrypted()).to.be.true;
|
||||
|
@ -3469,13 +3469,13 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('create and add a new ec subkey to a rsa key', async function() {
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const total = privateKey.subKeys.length;
|
||||
const opt2 = { curve: 'curve25519' };
|
||||
let newPrivateKey = await privateKey.addSubkey(opt2);
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
expect(subKey).to.exist;
|
||||
expect(newPrivateKey.subKeys.length).to.be.equal(total + 1);
|
||||
|
@ -3492,7 +3492,7 @@ VYGdb3eNlV8CfoEC
|
|||
const opt2 = { sign: true };
|
||||
let newPrivateKey = await privateKey.addSubkey(opt2);
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
const subkeyOid = subKey.keyPacket.publicParams.oid;
|
||||
const pkOid = newPrivateKey.primaryKey.publicParams.oid;
|
||||
|
@ -3500,8 +3500,8 @@ VYGdb3eNlV8CfoEC
|
|||
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('eddsa');
|
||||
await subKey.verify(newPrivateKey.primaryKey);
|
||||
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 message = await openpgp.message.read(signed);
|
||||
const signed = await openpgp.sign({ message: openpgp.Message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false });
|
||||
const message = await openpgp.readMessage(signed);
|
||||
const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] });
|
||||
expect(signatures).to.exist;
|
||||
expect(signatures.length).to.be.equal(1);
|
||||
|
@ -3517,14 +3517,14 @@ VYGdb3eNlV8CfoEC
|
|||
const total = privateKey.subKeys.length;
|
||||
let newPrivateKey = await privateKey.addSubkey();
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
const publicKey = newPrivateKey.toPublic();
|
||||
await subKey.verify(newPrivateKey.primaryKey);
|
||||
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: openpgp.Message.fromText(vData), publicKeys: publicKey, armor:false });
|
||||
expect(encrypted).to.be.exist;
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
|
||||
expect(pkSessionKeys).to.exist;
|
||||
expect(pkSessionKeys.length).to.be.equal(1);
|
||||
|
@ -3535,19 +3535,19 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('sign/verify data with the new subkey correctly using rsa', async function() {
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const total = privateKey.subKeys.length;
|
||||
const opt2 = { sign: true, rsaBits: rsaBits };
|
||||
let newPrivateKey = await privateKey.addSubkey(opt2);
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
expect(subKey.getAlgorithmInfo().algorithm).to.be.equal('rsaEncryptSign');
|
||||
await subKey.verify(newPrivateKey.primaryKey);
|
||||
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 message = await openpgp.message.read(signed);
|
||||
const signed = await openpgp.sign({ message: openpgp.Message.fromText('the data to signed'), privateKeys: newPrivateKey, armor:false });
|
||||
const message = await openpgp.readMessage(signed);
|
||||
const { signatures } = await openpgp.verify({ message, publicKeys: [newPrivateKey.toPublic()] });
|
||||
expect(signatures).to.exist;
|
||||
expect(signatures.length).to.be.equal(1);
|
||||
|
@ -3556,19 +3556,19 @@ VYGdb3eNlV8CfoEC
|
|||
});
|
||||
|
||||
it('encrypt/decrypt data with the new subkey correctly using rsa', async function() {
|
||||
const privateKey = await openpgp.key.readArmored(priv_key_rsa);
|
||||
const privateKey = await openpgp.readArmoredKey(priv_key_rsa);
|
||||
await privateKey.decrypt('hello world');
|
||||
const total = privateKey.subKeys.length;
|
||||
let newPrivateKey = await privateKey.addSubkey(rsaOpt);
|
||||
const armoredKey = newPrivateKey.armor();
|
||||
newPrivateKey = await openpgp.key.readArmored(armoredKey);
|
||||
newPrivateKey = await openpgp.readArmoredKey(armoredKey);
|
||||
const subKey = newPrivateKey.subKeys[total];
|
||||
const publicKey = newPrivateKey.toPublic();
|
||||
const vData = 'the data to encrypted!';
|
||||
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: openpgp.Message.fromText(vData), publicKeys: publicKey, armor:false });
|
||||
expect(encrypted).to.be.exist;
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const pkSessionKeys = message.packets.filterByTag(openpgp.enums.packet.publicKeyEncryptedSessionKey);
|
||||
expect(pkSessionKeys).to.exist;
|
||||
expect(pkSessionKeys.length).to.be.equal(1);
|
||||
|
|
|
@ -135,7 +135,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('publicKeys.getForId() - valid id', function() {
|
||||
const key = keyring.publicKeys.getForId(keyId);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId);
|
||||
});
|
||||
|
||||
|
@ -146,7 +146,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('privateKeys.getForId() - valid id', function() {
|
||||
const key = keyring.privateKeys.getForId(keyId);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId);
|
||||
});
|
||||
|
||||
|
@ -157,7 +157,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('publicKeys.getForId() - deep, including subkeys - subkey id', function() {
|
||||
const key = keyring.publicKeys.getForId(subkeyId2, true);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId2);
|
||||
});
|
||||
|
||||
|
@ -179,7 +179,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('publicKeys.getForId() - valid fingerprint', function() {
|
||||
const key = keyring.publicKeys.getForId(keyFingerP2);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId2);
|
||||
});
|
||||
|
||||
|
@ -190,7 +190,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('publicKeys.getForId() - deep, including subkeys - subkey fingerprint', function() {
|
||||
const key = keyring.publicKeys.getForId(subkeyFingerP2, true);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId2);
|
||||
});
|
||||
|
||||
|
@ -250,7 +250,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('publicKeys.removeForId() - valid id', function() {
|
||||
const key = keyring.publicKeys.removeForId(keyId);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId);
|
||||
expect(keyring.publicKeys.keys).to.exist.and.have.length(1);
|
||||
});
|
||||
|
@ -263,7 +263,7 @@ module.exports = () => describe("Keyring", async function() {
|
|||
|
||||
it('publicKeys.removeForId() - valid fingerprint', function() {
|
||||
const key = keyring.publicKeys.removeForId(keyFingerP2);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.key.Key);
|
||||
expect(key).to.exist.and.be.an.instanceof(openpgp.Key);
|
||||
expect(key.getKeyId().toHex()).equals(keyId2);
|
||||
expect(keyring.publicKeys.keys).to.be.empty;
|
||||
});
|
||||
|
@ -273,14 +273,14 @@ module.exports = () => describe("Keyring", async function() {
|
|||
const localstore2 = new openpgp.Keyring.localstore('my-custom-prefix-');
|
||||
const localstore3 = new openpgp.Keyring.localstore();
|
||||
await localstore3.storePublic([]);
|
||||
const key = await openpgp.key.readArmored(pubkey);
|
||||
const key = await openpgp.readArmoredKey(pubkey);
|
||||
await localstore1.storePublic([key]);
|
||||
expect((await localstore2.loadPublic())[0].getKeyId().equals(key.getKeyId())).to.be.true;
|
||||
expect(await localstore3.loadPublic()).to.have.length(0);
|
||||
});
|
||||
|
||||
it('emptying keyring and storing removes keys', async function() {
|
||||
const key = await openpgp.key.readArmored(pubkey);
|
||||
const key = await openpgp.readArmoredKey(pubkey);
|
||||
|
||||
const localstore = new openpgp.Keyring.localstore('remove-prefix-');
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -78,7 +78,7 @@ module.exports = () => describe("Packet", function() {
|
|||
|
||||
await enc.encrypt(algo, key);
|
||||
|
||||
const msg2 = new openpgp.message.Message();
|
||||
const msg2 = new openpgp.Message();
|
||||
await msg2.packets.read(message.write(), { SymmetricallyEncryptedDataPacket: openpgp.SymmetricallyEncryptedDataPacket });
|
||||
msg2.packets[0].ignoreMdcError = true;
|
||||
const dec = await msg2.decrypt(null, null, [{ algorithm: algo, data: key }]);
|
||||
|
@ -771,7 +771,7 @@ kePFjAnu9cpynKXu3usf8+FuBw2zLsg1Id1n7ttxoAte416KjBN9lFBt8mcu
|
|||
=wEIR
|
||||
-----END PGP SIGNATURE-----`;
|
||||
|
||||
const signature = await openpgp.signature.readArmored(armored_sig);
|
||||
const signature = await openpgp.readArmoredSignature(armored_sig);
|
||||
|
||||
expect(signature.packets[0].signersUserId).to.equal('test-wkd@metacode.biz');
|
||||
});
|
||||
|
@ -810,7 +810,7 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+
|
|||
=et/d
|
||||
-----END PGP PUBLIC KEY BLOCK-----`;
|
||||
|
||||
const key = await openpgp.key.readArmored(pubkey);
|
||||
const key = await openpgp.readArmoredKey(pubkey);
|
||||
|
||||
const { notations, rawNotations } = key.users[0].selfCertifications[0];
|
||||
|
||||
|
|
|
@ -844,9 +844,9 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
|
|||
const { rejectMessageHashAlgorithms } = openpgp.config;
|
||||
Object.assign(openpgp.config, { rejectMessageHashAlgorithms: new Set([openpgp.enums.hash.md5, openpgp.enums.hash.ripemd]) });
|
||||
try {
|
||||
const priv_key = await openpgp.key.readArmored(priv_key_arm1);
|
||||
const pub_key = await openpgp.key.readArmored(pub_key_arm1);
|
||||
const msg = await openpgp.message.readArmored(msg_arm1);
|
||||
const priv_key = await openpgp.readArmoredKey(priv_key_arm1);
|
||||
const pub_key = await openpgp.readArmoredKey(pub_key_arm1);
|
||||
const msg = await openpgp.readArmoredMessage(msg_arm1);
|
||||
await priv_key.decrypt("abcd");
|
||||
const decrypted = await openpgp.decrypt({ privateKeys: priv_key, publicKeys:[pub_key], message:msg });
|
||||
expect(decrypted.data).to.exist;
|
||||
|
@ -863,10 +863,10 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
|
|||
try {
|
||||
// exercises the GnuPG s2k type 1001 extension:
|
||||
// the secrets on the primary key have been stripped.
|
||||
const priv_key_gnupg_ext = await openpgp.key.readArmored(priv_key_arm1_stripped);
|
||||
const priv_key_gnupg_ext_2 = await openpgp.key.readArmored(priv_key_arm1_stripped);
|
||||
const pub_key = await openpgp.key.readArmored(pub_key_arm1);
|
||||
const message = await openpgp.message.readArmored(msg_arm1);
|
||||
const priv_key_gnupg_ext = await openpgp.readArmoredKey(priv_key_arm1_stripped);
|
||||
const priv_key_gnupg_ext_2 = await openpgp.readArmoredKey(priv_key_arm1_stripped);
|
||||
const pub_key = await openpgp.readArmoredKey(pub_key_arm1);
|
||||
const message = await openpgp.readArmoredMessage(msg_arm1);
|
||||
const primaryKey_packet = priv_key_gnupg_ext.primaryKey.write();
|
||||
expect(priv_key_gnupg_ext.isDecrypted()).to.be.false;
|
||||
await priv_key_gnupg_ext.decrypt("abcd");
|
||||
|
@ -877,7 +877,7 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
|
|||
expect(msg.signatures).to.have.length(1);
|
||||
expect(msg.signatures[0].valid).to.be.true;
|
||||
expect(msg.signatures[0].signature.packets.length).to.equal(1);
|
||||
await expect(openpgp.sign({ message: openpgp.message.fromText('test'), privateKeys: [priv_key_gnupg_ext] })).to.eventually.be.rejectedWith(/Missing key parameters/);
|
||||
await expect(openpgp.sign({ message: openpgp.Message.fromText('test'), privateKeys: [priv_key_gnupg_ext] })).to.eventually.be.rejectedWith(/Missing key parameters/);
|
||||
await expect(openpgp.reformatKey({ userIds: { name: 'test' }, privateKey: priv_key_gnupg_ext })).to.eventually.be.rejectedWith(/Missing key parameters/);
|
||||
await expect(openpgp.reformatKey({ userIds: { name: 'test' }, privateKey: priv_key_gnupg_ext_2, passphrase: 'test' })).to.eventually.be.rejectedWith(/Missing key parameters/);
|
||||
await priv_key_gnupg_ext.encrypt("abcd");
|
||||
|
@ -890,14 +890,14 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
|
|||
});
|
||||
|
||||
it('Supports signing with GnuPG stripped-key extension', async function() {
|
||||
const priv_key_gnupg_ext = await openpgp.key.readArmored(flowcrypt_stripped_key);
|
||||
const priv_key_gnupg_ext = await openpgp.readArmoredKey(flowcrypt_stripped_key);
|
||||
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: openpgp.Message.fromText('test'), privateKeys: [priv_key_gnupg_ext], date: new Date('2018-12-17T03:24:00') });
|
||||
expect(sig).to.match(/-----END PGP MESSAGE-----\r\n$/);
|
||||
});
|
||||
|
||||
it('Supports non-human-readable notations', async function() {
|
||||
const { packets: [signature] } = await openpgp.message.readArmored(signature_with_non_human_readable_notations);
|
||||
const { packets: [signature] } = await openpgp.readArmoredMessage(signature_with_non_human_readable_notations);
|
||||
// There are no human-readable notations so `notations` property does not
|
||||
// expose the `test@key.com` notation.
|
||||
expect(Object.keys(signature.notations).length).to.equal(0);
|
||||
|
@ -914,7 +914,7 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw==
|
|||
it('Checks for critical bit in non-human-readable notations', async function() {
|
||||
try {
|
||||
openpgp.config.tolerant = false;
|
||||
await openpgp.message.readArmored(`-----BEGIN PGP SIGNATURE-----
|
||||
await openpgp.readArmoredMessage(`-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
wsEfBAABCABJBYJfKDH0K5QAAAAAAB0ABXVua25vd25AdGVzdHMuc2VxdW9pYS1w
|
||||
Z3Aub3JndmFsdWUWIQTRpm4aI7GCyZgPeIz7/MgqAV5zMAAKCRD7/MgqAV5zMLBK
|
||||
|
@ -929,7 +929,7 @@ IYs+aFmldMg4p1t1Ab/bRHbBxIlzhtbNE6IyOfc17mgOcjQzVJBc/EaxD7S3KjU2
|
|||
bwM=
|
||||
=0x2S
|
||||
-----END PGP SIGNATURE-----`);
|
||||
throw new Error('openpgp.message.readArmored should throw but it did not.');
|
||||
throw new Error('openpgp.readArmoredMessage should throw but it did not.');
|
||||
} catch (e) {
|
||||
expect(e.message).to.equal('Unknown critical notation: unknown@tests.sequoia-pgp.org');
|
||||
} finally {
|
||||
|
@ -953,8 +953,8 @@ bwM=
|
|||
'=VH8F',
|
||||
'-----END PGP MESSAGE-----'].join('\n');
|
||||
|
||||
const sMsg = await openpgp.message.readArmored(signedArmor);
|
||||
const pub_key = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const sMsg = await openpgp.readArmoredMessage(signedArmor);
|
||||
const pub_key = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const verified = await sMsg.verify([pub_key]);
|
||||
openpgp.stream.pipe(sMsg.getLiteralData(), new openpgp.stream.WritableStream());
|
||||
expect(verified).to.exist;
|
||||
|
@ -984,9 +984,9 @@ bwM=
|
|||
'-----END PGP MESSAGE-----'].join('\n');
|
||||
|
||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||
const esMsg = await openpgp.message.readArmored(msg_armor);
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const esMsg = await openpgp.readArmoredMessage(msg_armor);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
|
||||
await Promise.all(esMsg.getEncryptionKeyIds().map(keyId => privKey.decrypt('hello world', keyId)));
|
||||
|
||||
|
@ -1019,9 +1019,9 @@ bwM=
|
|||
'-----END PGP MESSAGE-----'].join('\n');
|
||||
|
||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||
const sMsg = await openpgp.message.readArmored(msg_armor);
|
||||
const pubKey2 = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const pubKey3 = await openpgp.key.readArmored(pub_key_arm3);
|
||||
const sMsg = await openpgp.readArmoredMessage(msg_armor);
|
||||
const pubKey2 = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const pubKey3 = await openpgp.readArmoredKey(pub_key_arm3);
|
||||
|
||||
const keyids = sMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1043,8 +1043,8 @@ bwM=
|
|||
let testFailed = true;
|
||||
try {
|
||||
openpgp.config.tolerant = false;
|
||||
const sMsg = await openpgp.message.readArmored(signature_with_critical_notation);
|
||||
const pub_key = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const sMsg = await openpgp.readArmoredMessage(signature_with_critical_notation);
|
||||
const pub_key = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const verified = await sMsg.verify([pub_key]);
|
||||
await verified[0].verified;
|
||||
testFailed = false;
|
||||
|
@ -1061,8 +1061,8 @@ bwM=
|
|||
openpgp.config.tolerant = false;
|
||||
openpgp.config.knownNotations.push('test@example.com');
|
||||
try {
|
||||
const sMsg = await openpgp.message.readArmored(signature_with_critical_notation);
|
||||
const pub_key = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const sMsg = await openpgp.readArmoredMessage(signature_with_critical_notation);
|
||||
const pub_key = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const verified = await sMsg.verify([pub_key]);
|
||||
openpgp.stream.pipe(sMsg.getLiteralData(), new openpgp.stream.WritableStream());
|
||||
expect(await verified[0].verified).to.be.true;
|
||||
|
@ -1097,9 +1097,9 @@ bwM=
|
|||
'-----END PGP SIGNATURE-----'].join('\n');
|
||||
|
||||
const plaintext = 'short message\nnext line\n한국어/조선말';
|
||||
const csMsg = await openpgp.cleartext.readArmored(msg_armor);
|
||||
const pubKey2 = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const pubKey3 = await openpgp.key.readArmored(pub_key_arm3);
|
||||
const csMsg = await openpgp.readArmoredCleartextMessage(msg_armor);
|
||||
const pubKey2 = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const pubKey3 = await openpgp.readArmoredKey(pub_key_arm3);
|
||||
|
||||
const keyids = csMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1119,7 +1119,7 @@ bwM=
|
|||
|
||||
it('Verify latin-1 signed message', async function() {
|
||||
const latin1Binary = openpgp.util.hexToUint8Array('48e46c6cf62057e86c74');
|
||||
const message = openpgp.message.fromBinary(latin1Binary);
|
||||
const message = openpgp.Message.fromBinary(latin1Binary);
|
||||
|
||||
message.appendSignature(`-----BEGIN PGP SIGNATURE-----
|
||||
|
||||
|
@ -1138,7 +1138,7 @@ PAAeuQTUrcJdZeJ86eQ9cCUB216HCwSKOWTQRzL+hBWKXij4WD4=
|
|||
=ZEFm
|
||||
-----END PGP SIGNATURE-----`);
|
||||
|
||||
const pubKey = await openpgp.key.readArmored(pub_latin1_msg);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_latin1_msg);
|
||||
|
||||
return message.verify([pubKey]).then(async verifiedSig => {
|
||||
expect(await openpgp.stream.readToEnd(message.getLiteralData())).to.equal(latin1Binary);
|
||||
|
@ -1175,8 +1175,8 @@ zmuVOdNuWQqxT9Sqa84=
|
|||
-----END PGP SIGNATURE-----`;
|
||||
|
||||
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
|
||||
const csMsg = await openpgp.cleartext.readArmored(msg_armor);
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const csMsg = await openpgp.readArmoredCleartextMessage(msg_armor);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
|
||||
const keyids = csMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1209,8 +1209,8 @@ yYDnCgA=
|
|||
-----END PGP MESSAGE-----`;
|
||||
|
||||
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
|
||||
const sMsg = await openpgp.message.readArmored(msg_armor);
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const sMsg = await openpgp.readArmoredMessage(msg_armor);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
|
||||
const keyids = sMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1240,14 +1240,14 @@ yYDnCgA=
|
|||
-----END PGP MESSAGE-----`.split('');
|
||||
|
||||
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
|
||||
const sMsg = await openpgp.message.readArmored(new openpgp.stream.ReadableStream({
|
||||
const sMsg = await openpgp.readArmoredMessage(new openpgp.stream.ReadableStream({
|
||||
async pull(controller) {
|
||||
await new Promise(setTimeout);
|
||||
controller.enqueue(msg_armor.shift());
|
||||
if (!msg_armor.length) controller.close();
|
||||
}
|
||||
}));
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
|
||||
const keyids = sMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1279,8 +1279,8 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
-----END PGP MESSAGE-----`;
|
||||
|
||||
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
|
||||
const sMsg = await openpgp.message.readArmored(msg_armor);
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const sMsg = await openpgp.readArmoredMessage(msg_armor);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
|
||||
const keyids = sMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1306,14 +1306,14 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
-----END PGP MESSAGE-----`.split('');
|
||||
|
||||
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
|
||||
const sMsg = await openpgp.message.readArmored(new openpgp.stream.ReadableStream({
|
||||
const sMsg = await openpgp.readArmoredMessage(new openpgp.stream.ReadableStream({
|
||||
async pull(controller) {
|
||||
await new Promise(setTimeout);
|
||||
controller.enqueue(msg_armor.shift());
|
||||
if (!msg_armor.length) controller.close();
|
||||
}
|
||||
}));
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
|
||||
const keyids = sMsg.getSigningKeyIds();
|
||||
|
||||
|
@ -1345,13 +1345,13 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Sign text with openpgp.sign and verify with openpgp.verify leads to same string cleartext and valid signatures', async function() {
|
||||
const plaintext = 'short message\nnext line \n한국어/조선말';
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.cleartext.fromText(plaintext) }).then(async function(signed) {
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.CleartextMessage.fromText(plaintext) }).then(async function(signed) {
|
||||
|
||||
const csMsg = await openpgp.cleartext.readArmored(signed);
|
||||
const csMsg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:csMsg });
|
||||
|
||||
}).then(function(cleartextSig) {
|
||||
|
@ -1365,13 +1365,13 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Sign text with openpgp.sign and verify with openpgp.verify leads to same string cleartext and valid signatures -- escape armored message', async function() {
|
||||
const plaintext = pub_key_arm2;
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.cleartext.fromText(plaintext) }).then(async function(signed) {
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.CleartextMessage.fromText(plaintext) }).then(async function(signed) {
|
||||
|
||||
const csMsg = await openpgp.cleartext.readArmored(signed);
|
||||
const csMsg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:csMsg });
|
||||
|
||||
}).then(function(cleartextSig) {
|
||||
|
@ -1385,13 +1385,13 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Sign text with openpgp.sign and verify with openpgp.verify leads to same string cleartext and valid signatures -- trailing spaces', async function() {
|
||||
const plaintext = 'space: \nspace and tab: \t\nno trailing space\n \ntab:\t\ntab and space:\t ';
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.cleartext.fromText(plaintext) }).then(async function(signed) {
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.CleartextMessage.fromText(plaintext) }).then(async function(signed) {
|
||||
|
||||
const csMsg = await openpgp.cleartext.readArmored(signed);
|
||||
const csMsg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:csMsg });
|
||||
|
||||
}).then(function(cleartextSig) {
|
||||
|
@ -1405,13 +1405,13 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Sign text with openpgp.sign and verify with openpgp.verify leads to same bytes cleartext and valid signatures - armored', async function() {
|
||||
const plaintext = openpgp.util.strToUint8Array('short message\nnext line \n한국어/조선말');
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromBinary(plaintext) }).then(async function(signed) {
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromBinary(plaintext) }).then(async function(signed) {
|
||||
|
||||
const csMsg = await openpgp.message.readArmored(signed);
|
||||
const csMsg = await openpgp.readArmoredMessage(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:csMsg, format: 'binary' });
|
||||
|
||||
}).then(async function(cleartextSig) {
|
||||
|
@ -1425,13 +1425,13 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Sign text with openpgp.sign and verify with openpgp.verify leads to same bytes cleartext and valid signatures - not armored', async function() {
|
||||
const plaintext = openpgp.util.strToUint8Array('short message\nnext line \n한국어/조선말');
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromBinary(plaintext), armor:false }).then(async function(signed) {
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromBinary(plaintext), armor:false }).then(async function(signed) {
|
||||
|
||||
const csMsg = await openpgp.message.read(signed);
|
||||
const csMsg = await openpgp.readMessage(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:csMsg, format: 'binary' });
|
||||
|
||||
}).then(function(cleartextSig) {
|
||||
|
@ -1445,12 +1445,12 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Should verify cleartext message correctly when using a detached cleartext signature and binary literal data', async function () {
|
||||
const plaintext = 'short message\nnext line \n한국어/조선말';
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromText(plaintext), detached: true}).then(async function(signed) {
|
||||
const signature = await openpgp.signature.readArmored(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromBinary(openpgp.util.encodeUtf8(plaintext)), signature: signature });
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromText(plaintext), detached: true}).then(async function(signed) {
|
||||
const signature = await openpgp.readArmoredSignature(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.Message.fromBinary(openpgp.util.encodeUtf8(plaintext)), signature: signature });
|
||||
}).then(function(cleartextSig) {
|
||||
expect(cleartextSig).to.exist;
|
||||
expect(cleartextSig.signatures).to.have.length(1);
|
||||
|
@ -1462,12 +1462,12 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
it('Should verify cleartext message correctly when using a detached binary signature and text literal data', async function () {
|
||||
const plaintext = 'short message\nnext line \n한국어/조선말';
|
||||
const plaintextArray = openpgp.util.encodeUtf8(plaintext);
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey.decrypt('hello world');
|
||||
return openpgp.sign({ privateKeys:[privKey], message:openpgp.message.fromBinary(plaintextArray), detached: true}).then(async function(signed) {
|
||||
const signature = await openpgp.signature.readArmored(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.message.fromText(plaintext), signature: signature });
|
||||
return openpgp.sign({ privateKeys:[privKey], message:openpgp.Message.fromBinary(plaintextArray), detached: true}).then(async function(signed) {
|
||||
const signature = await openpgp.readArmoredSignature(signed);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message: openpgp.Message.fromText(plaintext), signature: signature });
|
||||
}).then(function(cleartextSig) {
|
||||
expect(cleartextSig).to.exist;
|
||||
expect(cleartextSig.signatures).to.have.length(1);
|
||||
|
@ -1478,14 +1478,14 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
it('Should verify encrypted cleartext message correctly when encrypting binary literal data with a canonical text signature', async function () {
|
||||
const plaintext = 'short message\nnext line \n한국어/조선말';
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await Promise.all([privKey.primaryKey.decrypt('hello world'), privKey.subKeys[0].keyPacket.decrypt('hello world')]);
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.message.fromText(plaintext), detached: true}).then(async function(signed) {
|
||||
const signature = await openpgp.signature.readArmored(signed);
|
||||
return openpgp.encrypt({ message: openpgp.message.fromBinary(openpgp.util.encodeUtf8(plaintext)), publicKeys: [pubKey], signature })
|
||||
return openpgp.sign({ privateKeys:[privKey], message: openpgp.Message.fromText(plaintext), detached: true}).then(async function(signed) {
|
||||
const signature = await openpgp.readArmoredSignature(signed);
|
||||
return openpgp.encrypt({ message: openpgp.Message.fromBinary(openpgp.util.encodeUtf8(plaintext)), publicKeys: [pubKey], signature })
|
||||
}).then(async data => {
|
||||
const csMsg = await openpgp.message.readArmored(data);
|
||||
const csMsg = await openpgp.readArmoredMessage(data);
|
||||
return openpgp.decrypt({ message: csMsg, privateKeys: [ privKey ], publicKeys: [ pubKey ] });
|
||||
}).then(function(cleartextSig) {
|
||||
expect(cleartextSig).to.exist;
|
||||
|
@ -1496,8 +1496,8 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
});
|
||||
|
||||
it('Verify test with expired verification public key', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_expired);
|
||||
const message = await openpgp.message.readArmored(msg_sig_expired);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_expired);
|
||||
const message = await openpgp.readArmoredMessage(msg_sig_expired);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:message }).then(function(verified) {
|
||||
expect(verified).to.exist;
|
||||
expect(verified.signatures).to.have.length(1);
|
||||
|
@ -1507,8 +1507,8 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
});
|
||||
|
||||
it('Verify test with expired verification public key and disable expiration checks using null date', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_expired);
|
||||
const message = await openpgp.message.readArmored(msg_sig_expired);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_expired);
|
||||
const message = await openpgp.readArmoredMessage(msg_sig_expired);
|
||||
return openpgp.verify({ publicKeys:[pubKey], message:message, date: null }).then(function(verified) {
|
||||
expect(verified).to.exist;
|
||||
expect(verified.signatures).to.have.length(1);
|
||||
|
@ -1519,7 +1519,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
// TODO add test with multiple revocation signatures
|
||||
it('Verify primary key revocation signatures', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_revoked);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_revoked);
|
||||
await expect(pubKey.revocationSignatures[0].verify(
|
||||
pubKey.primaryKey, openpgp.enums.signature.keyRevocation, {key: pubKey.primaryKey}
|
||||
)).to.eventually.be.true;
|
||||
|
@ -1527,14 +1527,14 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
|
||||
// TODO add test with multiple revocation signatures
|
||||
it('Verify subkey revocation signatures', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_revoked);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_revoked);
|
||||
await expect(pubKey.subKeys[0].revocationSignatures[0].verify(
|
||||
pubKey.primaryKey, openpgp.enums.signature.subkeyRevocation, {key: pubKey.primaryKey, bind: pubKey.subKeys[0].keyPacket}
|
||||
)).to.eventually.be.true;
|
||||
});
|
||||
|
||||
it('Verify key expiration date', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_revoked);
|
||||
const pubKey = await openpgp.readArmoredKey(pub_revoked);
|
||||
|
||||
expect(pubKey).to.exist;
|
||||
expect(pubKey.users[0].selfCertifications[0].keyNeverExpires).to.be.false;
|
||||
|
@ -1542,15 +1542,15 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
});
|
||||
|
||||
it('Write unhashed subpackets', async function() {
|
||||
let pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
let pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
expect(pubKey.users[0].selfCertifications).to.exist;
|
||||
pubKey = await openpgp.key.readArmored(pubKey.armor());
|
||||
pubKey = await openpgp.readArmoredKey(pubKey.armor());
|
||||
expect(pubKey.users[0].selfCertifications).to.exist;
|
||||
});
|
||||
|
||||
it('Write V4 signatures', async function() {
|
||||
const pubKey = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const pubKey2 = await openpgp.key.readArmored(pubKey.armor());
|
||||
const pubKey = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const pubKey2 = await openpgp.readArmoredKey(pubKey.armor());
|
||||
expect(pubKey2).to.exist;
|
||||
expect(pubKey.users[0].selfCertifications).to.eql(pubKey2.users[0].selfCertifications);
|
||||
});
|
||||
|
@ -1592,10 +1592,10 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
''].join('\r\n');
|
||||
|
||||
const publicKeyArmored = '-----BEGIN PGP PUBLIC KEY BLOCK-----\r\nVersion: OpenPGP.js v.1.20131116\r\nComment: Whiteout Mail - https://whiteout.io\r\n\r\nxsBNBFKODs4BB/9iOF4THsjQMY+WEpT7ShgKxj4bHzRRaQkqczS4nZvP0U3g\r\nqeqCnbpagyeKXA+bhWFQW4GmXtgAoeD5PXs6AZYrw3tWNxLKu2Oe6Tp9K/XI\r\nxTMQ2wl4qZKDXHvuPsJ7cmgaWqpPyXtxA4zHHS3WrkI/6VzHAcI/y6x4szSB\r\nKgSuhI3hjh3s7TybUC1U6AfoQGx/S7e3WwlCOrK8GTClirN/2mCPRC5wuIft\r\nnkoMfA6jK8d2OPrJ63shy5cgwHOjQg/xuk46dNS7tkvGmbaa+X0PgqSKB+Hf\r\nYPPNS/ylg911DH9qa8BqYU2QpNh9jUKXSF+HbaOM+plWkCSAL7czV+R3ABEB\r\nAAHNLVdoaXRlb3V0IFVzZXIgPHNhZmV3aXRobWUudGVzdHVzZXJAZ21haWwu\r\nY29tPsLAXAQQAQgAEAUCUo4O2gkQ1/uT/N+/wjwAAN2cB/9gFRmAfvEQ2qz+\r\nWubmT2EsSSnjPMxzG4uyykFoa+TaZCWo2Xa2tQghmU103kEkQb1OEjRjpgwJ\r\nYX9Kghnl8DByM686L5AXnRyHP78qRJCLXSXl0AGicboUDp5sovaa4rswQceH\r\nvcdWgZ/mgHTRoiQeJddy9k+H6MPFiyFaVcFwegVsmpc+dCcC8yT+qh8ZIbyG\r\nRJU60PmKKN7LUusP+8DbSv39zCGJCBlVVKyA4MzdF5uM+sqTdXbKzOrT5DGd\r\nCZaox4s+w16Sq1rHzZKFWfQPfKLDB9pyA0ufCVRA3AF6BUi7G3ZqhZiHNhMP\r\nNvE45V/hS1PbZcfPVoUjE2qc1Ix1\r\n=7Wpe\r\n-----END PGP PUBLIC KEY BLOCK-----';
|
||||
const publicKey = await openpgp.key.readArmored(publicKeyArmored);
|
||||
const publicKey = await openpgp.readArmoredKey(publicKeyArmored);
|
||||
|
||||
// Text
|
||||
const msg = openpgp.message.fromText(content);
|
||||
const msg = openpgp.Message.fromText(content);
|
||||
await msg.appendSignature(detachedSig);
|
||||
return msg.verify([publicKey]).then(async result => {
|
||||
openpgp.stream.pipe(msg.getLiteralData(), new openpgp.stream.WritableStream());
|
||||
|
@ -1604,9 +1604,9 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
});
|
||||
|
||||
it('Detached signature signing and verification', async function() {
|
||||
const msg = openpgp.message.fromText('hello');
|
||||
const pubKey2 = await openpgp.key.readArmored(pub_key_arm2);
|
||||
const privKey2 = await openpgp.key.readArmored(priv_key_arm2);
|
||||
const msg = openpgp.Message.fromText('hello');
|
||||
const pubKey2 = await openpgp.readArmoredKey(pub_key_arm2);
|
||||
const privKey2 = await openpgp.readArmoredKey(priv_key_arm2);
|
||||
await privKey2.decrypt('hello world');
|
||||
|
||||
const opt = {rsaBits: 512, userIds: { name:'test', email:'a@b.com' }, passphrase: null};
|
||||
|
@ -1626,7 +1626,7 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
const opt = {userIds: { name:'test', email:'a@b.com' }, passphrase: null};
|
||||
return openpgp.generateKey(opt).then(function(gen) {
|
||||
const key = gen.key;
|
||||
let message = openpgp.message.fromText('hello world');
|
||||
let message = openpgp.Message.fromText('hello world');
|
||||
message = message.sign([key]);
|
||||
expect(message).to.exist;
|
||||
});
|
||||
|
@ -1660,8 +1660,8 @@ hkJiXopCSWKSlQInL1devkJJUWJmTmZeugJYlpdLAagQJM0JpsCqIQZwKgAA
|
|||
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||
].join('\n');
|
||||
|
||||
const signedKey = await openpgp.key.readArmored(signedArmor);
|
||||
const signerKey = await openpgp.key.readArmored(priv_key_arm1);
|
||||
const signedKey = await openpgp.readArmoredKey(signedArmor);
|
||||
const signerKey = await openpgp.readArmoredKey(priv_key_arm1);
|
||||
return signedKey.verifyPrimaryUser([signerKey]).then(signatures => {
|
||||
expect(signatures[0].valid).to.be.null;
|
||||
expect(signatures[0].keyid.toHex()).to.equal(signedKey.getKeyId().toHex());
|
||||
|
@ -1695,7 +1695,7 @@ iTuGu4fEU1UligAXSrZmCdE=
|
|||
=VK6I
|
||||
-----END PGP PUBLIC KEY BLOCK-----`;
|
||||
|
||||
const key = await openpgp.key.readArmored(armoredKeyWithPhoto);
|
||||
const key = await openpgp.readArmoredKey(armoredKeyWithPhoto);
|
||||
for (const user of key.users) {
|
||||
await user.verify(key.primaryKey);
|
||||
}
|
||||
|
|
|
@ -176,11 +176,11 @@ function tests() {
|
|||
}
|
||||
});
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
});
|
||||
const msgAsciiArmored = await openpgp.stream.readToEnd(encrypted);
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.readArmoredMessage(msgAsciiArmored);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message
|
||||
|
@ -190,7 +190,7 @@ function tests() {
|
|||
|
||||
it('Encrypt larger message', async function() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
});
|
||||
const reader = openpgp.stream.getReader(encrypted);
|
||||
|
@ -198,7 +198,7 @@ function tests() {
|
|||
dataArrived();
|
||||
reader.releaseLock();
|
||||
const msgAsciiArmored = await openpgp.stream.readToEnd(encrypted);
|
||||
const message = await openpgp.message.readArmored(msgAsciiArmored);
|
||||
const message = await openpgp.readArmoredMessage(msgAsciiArmored);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
|
@ -209,7 +209,7 @@ function tests() {
|
|||
|
||||
it('Input stream should be canceled when canceling encrypted stream', async function() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
});
|
||||
const reader = openpgp.stream.getReader(encrypted);
|
||||
|
@ -222,7 +222,7 @@ function tests() {
|
|||
|
||||
it('Sign: Input stream should be canceled when canceling encrypted stream', async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
const reader = openpgp.stream.getReader(signed);
|
||||
|
@ -237,13 +237,13 @@ function tests() {
|
|||
let aeadProtectValue = openpgp.config.aeadProtect;
|
||||
openpgp.config.aeadProtect = false;
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
setTimeout(dataArrived, 3000); // Do not wait until data arrived, but wait a bit to check that it doesn't arrive early.
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
|
@ -265,13 +265,13 @@ function tests() {
|
|||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
|
@ -295,14 +295,14 @@ function tests() {
|
|||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey,
|
||||
|
@ -322,19 +322,19 @@ function tests() {
|
|||
it('Encrypt and decrypt larger message roundtrip using curve x25519 (allowUnauthenticatedStream=true)', async function() {
|
||||
let allowUnauthenticatedStreamValue = openpgp.config.allowUnauthenticatedStream;
|
||||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
const priv = await openpgp.key.readArmored(xPriv);
|
||||
const pub = await openpgp.key.readArmored(xPub);
|
||||
const priv = await openpgp.readArmoredKey(xPriv);
|
||||
const pub = await openpgp.readArmoredKey(xPub);
|
||||
await priv.decrypt(xPass);
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
publicKeys: pub,
|
||||
privateKeys: priv,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
publicKeys: pub,
|
||||
privateKeys: priv,
|
||||
|
@ -354,19 +354,19 @@ function tests() {
|
|||
it('Encrypt and decrypt larger message roundtrip using curve brainpool (allowUnauthenticatedStream=true)', async function() {
|
||||
let allowUnauthenticatedStreamValue = openpgp.config.allowUnauthenticatedStream;
|
||||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
const priv = await openpgp.key.readArmored(brainpoolPriv);
|
||||
const pub = await openpgp.key.readArmored(brainpoolPub);
|
||||
const priv = await openpgp.readArmoredKey(brainpoolPriv);
|
||||
const pub = await openpgp.readArmoredKey(brainpoolPub);
|
||||
await priv.decrypt(brainpoolPass);
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
publicKeys: pub,
|
||||
privateKeys: priv,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
publicKeys: pub,
|
||||
privateKeys: priv,
|
||||
|
@ -390,12 +390,12 @@ function tests() {
|
|||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(encrypted, value => {
|
||||
const message = await openpgp.readArmoredMessage(openpgp.stream.transform(encrypted, value => {
|
||||
value += '';
|
||||
if (value === '=' || value.length === 6) return; // Remove checksum
|
||||
const newlineIndex = value.indexOf('\r\n', 500);
|
||||
|
@ -425,13 +425,13 @@ function tests() {
|
|||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(encrypted, value => {
|
||||
const message = await openpgp.readArmoredMessage(openpgp.stream.transform(encrypted, value => {
|
||||
value += '';
|
||||
const newlineIndex = value.indexOf('\r\n', 500);
|
||||
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
||||
|
@ -460,13 +460,13 @@ function tests() {
|
|||
openpgp.config.allowUnauthenticatedStream = true;
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
publicKeys: pubKey,
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(encrypted, value => {
|
||||
const message = await openpgp.readArmoredMessage(openpgp.stream.transform(encrypted, value => {
|
||||
value += '';
|
||||
const newlineIndex = value.indexOf('\r\n', 500);
|
||||
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
||||
|
@ -492,12 +492,12 @@ function tests() {
|
|||
|
||||
it('Sign/verify: Detect armor checksum error', async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.readArmored(openpgp.stream.transform(signed, value => {
|
||||
const message = await openpgp.readArmoredMessage(openpgp.stream.transform(signed, value => {
|
||||
value += '';
|
||||
const newlineIndex = value.indexOf('\r\n', 500);
|
||||
if (value.length > 1000) return value.slice(0, newlineIndex - 1) + (value[newlineIndex - 1] === 'a' ? 'b' : 'a') + value.slice(newlineIndex);
|
||||
|
@ -519,13 +519,13 @@ function tests() {
|
|||
|
||||
it('Encrypt and decrypt larger message roundtrip (AEAD)', async function() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
|
@ -557,13 +557,13 @@ function tests() {
|
|||
}
|
||||
});
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText(data),
|
||||
message: openpgp.Message.fromText(data),
|
||||
streaming: expectedType,
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message
|
||||
|
@ -605,11 +605,11 @@ function tests() {
|
|||
|
||||
it('Input stream should be canceled when canceling decrypted stream (AEAD)', async function() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
});
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
|
@ -626,12 +626,12 @@ function tests() {
|
|||
|
||||
it('Sign/verify: Input stream should be canceled when canceling verified stream', async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
|
||||
const message = await openpgp.message.readArmored(signed);
|
||||
const message = await openpgp.readArmoredMessage(signed);
|
||||
const verified = await openpgp.verify({
|
||||
publicKeys: pubKey,
|
||||
message,
|
||||
|
@ -650,7 +650,7 @@ function tests() {
|
|||
|
||||
it("Don't pull entire input stream when we're not pulling encrypted stream", async function() {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
|
@ -664,7 +664,7 @@ function tests() {
|
|||
|
||||
it("Sign: Don't pull entire input stream when we're not pulling signed stream", async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
|
@ -681,11 +681,11 @@ function tests() {
|
|||
coresStub.returns(1);
|
||||
try {
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal(expectedType);
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
|
@ -704,11 +704,11 @@ function tests() {
|
|||
|
||||
it("Sign/verify: Don't pull entire input stream when we're not pulling verified stream", async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
const message = await openpgp.message.readArmored(signed);
|
||||
const message = await openpgp.readArmoredMessage(signed);
|
||||
const verified = await openpgp.verify({
|
||||
publicKeys: pubKey,
|
||||
message,
|
||||
|
@ -732,18 +732,18 @@ function tests() {
|
|||
}
|
||||
});
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey,
|
||||
detached: true,
|
||||
streaming: expectedType
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
const signature = await openpgp.readArmoredMessage(sigArmored);
|
||||
const verified = await openpgp.verify({
|
||||
signature,
|
||||
publicKeys: pubKey,
|
||||
message: openpgp.message.fromText('hello world')
|
||||
message: openpgp.Message.fromText('hello world')
|
||||
});
|
||||
expect(verified.data).to.equal('hello world');
|
||||
expect(verified.signatures).to.exist.and.have.length(1);
|
||||
|
@ -760,18 +760,18 @@ function tests() {
|
|||
}
|
||||
});
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey,
|
||||
detached: true,
|
||||
streaming: false,
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(signed)).to.be.false;
|
||||
const signature = await openpgp.message.read(signed);
|
||||
const signature = await openpgp.readMessage(signed);
|
||||
const verified = await openpgp.verify({
|
||||
signature,
|
||||
publicKeys: pubKey,
|
||||
message: openpgp.message.fromText('hello world')
|
||||
message: openpgp.Message.fromText('hello world')
|
||||
});
|
||||
expect(verified.data).to.equal('hello world');
|
||||
expect(verified.signatures).to.exist.and.have.length(1);
|
||||
|
@ -787,22 +787,22 @@ function tests() {
|
|||
controller.close();
|
||||
}
|
||||
});
|
||||
const priv = await openpgp.key.readArmored(brainpoolPriv);
|
||||
const pub = await openpgp.key.readArmored(brainpoolPub);
|
||||
const priv = await openpgp.readArmoredKey(brainpoolPriv);
|
||||
const pub = await openpgp.readArmoredKey(brainpoolPub);
|
||||
await priv.decrypt(brainpoolPass);
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: priv,
|
||||
detached: true,
|
||||
streaming: expectedType
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
const signature = await openpgp.readArmoredMessage(sigArmored);
|
||||
const verified = await openpgp.verify({
|
||||
signature,
|
||||
publicKeys: pub,
|
||||
message: openpgp.message.fromText('hello world')
|
||||
message: openpgp.Message.fromText('hello world')
|
||||
});
|
||||
expect(verified.data).to.equal('hello world');
|
||||
expect(verified.signatures).to.exist.and.have.length(1);
|
||||
|
@ -818,22 +818,22 @@ function tests() {
|
|||
controller.close();
|
||||
}
|
||||
});
|
||||
const priv = await openpgp.key.readArmored(xPriv);
|
||||
const pub = await openpgp.key.readArmored(xPub);
|
||||
const priv = await openpgp.readArmoredKey(xPriv);
|
||||
const pub = await openpgp.readArmoredKey(xPub);
|
||||
await priv.decrypt(xPass);
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: priv,
|
||||
detached: true,
|
||||
streaming: expectedType
|
||||
});
|
||||
expect(util.isStream(signed)).to.equal(expectedType);
|
||||
const sigArmored = await openpgp.stream.readToEnd(signed);
|
||||
const signature = await openpgp.message.readArmored(sigArmored);
|
||||
const signature = await openpgp.readArmoredMessage(sigArmored);
|
||||
const verified = await openpgp.verify({
|
||||
signature,
|
||||
publicKeys: pub,
|
||||
message: openpgp.message.fromText('hello world')
|
||||
message: openpgp.Message.fromText('hello world')
|
||||
});
|
||||
expect(verified.data).to.equal('hello world');
|
||||
expect(verified.signatures).to.exist.and.have.length(1);
|
||||
|
@ -842,7 +842,7 @@ function tests() {
|
|||
|
||||
it("Detached sign is expected to pull entire input stream when we're not pulling signed stream", async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey,
|
||||
detached: true
|
||||
});
|
||||
|
@ -856,7 +856,7 @@ function tests() {
|
|||
|
||||
it('Detached sign: Input stream should be canceled when canceling signed stream', async function() {
|
||||
const signed = await openpgp.sign({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
privateKeys: privKey,
|
||||
detached: true
|
||||
});
|
||||
|
@ -877,8 +877,8 @@ module.exports = () => describe('Streaming', function() {
|
|||
before(async function() {
|
||||
openpgp.config.aeadChunkSizeByte = 4;
|
||||
|
||||
pubKey = await openpgp.key.readArmored(pub_key);
|
||||
privKey = await openpgp.key.readArmored(priv_key);
|
||||
pubKey = await openpgp.readArmoredKey(pub_key);
|
||||
privKey = await openpgp.readArmoredKey(priv_key);
|
||||
await privKey.decrypt(passphrase);
|
||||
});
|
||||
|
||||
|
@ -936,12 +936,12 @@ module.exports = () => describe('Streaming', function() {
|
|||
const plaintext = fs.readFileSync(__filename.replace('streaming.js', 'openpgp.js'), 'utf8');
|
||||
const data = fs.createReadStream(__filename.replace('streaming.js', 'openpgp.js'), { encoding: 'utf8' });
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText(data),
|
||||
message: openpgp.Message.fromText(data),
|
||||
passwords: ['test']
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal('node');
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message
|
||||
|
@ -955,13 +955,13 @@ module.exports = () => describe('Streaming', function() {
|
|||
const plaintext = fs.readFileSync(__filename.replace('streaming.js', 'openpgp.js'));
|
||||
const data = fs.createReadStream(__filename.replace('streaming.js', 'openpgp.js'));
|
||||
const encrypted = await openpgp.encrypt({
|
||||
message: openpgp.message.fromBinary(data),
|
||||
message: openpgp.Message.fromBinary(data),
|
||||
passwords: ['test'],
|
||||
armor: false
|
||||
});
|
||||
expect(util.isStream(encrypted)).to.equal('node');
|
||||
|
||||
const message = await openpgp.message.read(encrypted);
|
||||
const message = await openpgp.readMessage(encrypted);
|
||||
const decrypted = await openpgp.decrypt({
|
||||
passwords: ['test'],
|
||||
message,
|
||||
|
|
|
@ -122,7 +122,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
if (data[name].pub_key) {
|
||||
return data[name].pub_key;
|
||||
}
|
||||
const pub = await openpgp.key.readArmored(data[name].pub);
|
||||
const pub = await openpgp.readArmoredKey(data[name].pub);
|
||||
expect(pub).to.exist;
|
||||
expect(pub.getKeyId().toHex()).to.equal(data[name].id);
|
||||
data[name].pub_key = pub;
|
||||
|
@ -133,7 +133,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
if (data[name].priv_key) {
|
||||
return data[name].priv_key;
|
||||
}
|
||||
const pk = await openpgp.key.readArmored(data[name].priv);
|
||||
const pk = await openpgp.readArmoredKey(data[name].priv);
|
||||
expect(pk).to.exist;
|
||||
expect(pk.getKeyId().toHex()).to.equal(data[name].id);
|
||||
await pk.decrypt(data[name].pass);
|
||||
|
@ -157,7 +157,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
it('Verify clear signed message', async function () {
|
||||
const name = 'light';
|
||||
const pub = await load_pub_key(name);
|
||||
const msg = await openpgp.cleartext.readArmored(data[name].message_signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(data[name].message_signed);
|
||||
return openpgp.verify({ publicKeys: [pub], message: msg }).then(function(result) {
|
||||
expect(result).to.exist;
|
||||
expect(result.data).to.equal(data[name].message);
|
||||
|
@ -170,9 +170,9 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
const name = 'light';
|
||||
const randomData = input.createSomeMessage();
|
||||
const priv = await load_priv_key(name);
|
||||
const signed = await openpgp.sign({ privateKeys: [priv], message: openpgp.cleartext.fromText(randomData)});
|
||||
const signed = await openpgp.sign({ privateKeys: [priv], message: openpgp.CleartextMessage.fromText(randomData)});
|
||||
const pub = await load_pub_key(name);
|
||||
const msg = await openpgp.cleartext.readArmored(signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
const result = await openpgp.verify({ publicKeys: [pub], message: msg});
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -184,7 +184,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
it('Decrypt and verify message', async function () {
|
||||
const light = await load_pub_key('light');
|
||||
const night = await load_priv_key('night');
|
||||
const msg = await openpgp.message.readArmored(data.night.message_encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(data.night.message_encrypted);
|
||||
const result = await openpgp.decrypt({ privateKeys: night, publicKeys: [light], message: msg });
|
||||
|
||||
expect(result).to.exist;
|
||||
|
@ -197,9 +197,9 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
const nightPublic = await load_pub_key('night');
|
||||
const lightPrivate = await load_priv_key('light');
|
||||
const randomData = input.createSomeMessage();
|
||||
const encrypted = await openpgp.encrypt({ publicKeys: [nightPublic], privateKeys: [lightPrivate], message: openpgp.message.fromText(randomData) });
|
||||
const encrypted = await openpgp.encrypt({ publicKeys: [nightPublic], privateKeys: [lightPrivate], message: openpgp.Message.fromText(randomData) });
|
||||
|
||||
const message = await openpgp.message.readArmored(encrypted);
|
||||
const message = await openpgp.readArmoredMessage(encrypted);
|
||||
const lightPublic = await load_pub_key('light');
|
||||
const nightPrivate = await load_priv_key('night');
|
||||
const result = await openpgp.decrypt({ privateKeys: nightPrivate, publicKeys: [lightPublic], message: message });
|
||||
|
@ -390,7 +390,7 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr
|
|||
'=xeG/',
|
||||
'-----END PGP PUBLIC KEY BLOCK-----'
|
||||
].join('\n');
|
||||
const hi = await openpgp.key.readArmored(pubKey);
|
||||
const hi = await openpgp.readArmoredKey(pubKey);
|
||||
const results = await hi.getPrimaryUser();
|
||||
// console.log(results);
|
||||
expect(results).to.exist;
|
||||
|
@ -466,9 +466,9 @@ function omnibus() {
|
|||
}),
|
||||
// Signing message
|
||||
openpgp.sign(
|
||||
{ message: openpgp.cleartext.fromText('Hi, this is me, Hi!'), privateKeys: hi }
|
||||
{ message: openpgp.CleartextMessage.fromText('Hi, this is me, Hi!'), privateKeys: hi }
|
||||
).then(async signed => {
|
||||
const msg = await openpgp.cleartext.readArmored(signed);
|
||||
const msg = await openpgp.readArmoredCleartextMessage(signed);
|
||||
// Verifying signed message
|
||||
return Promise.all([
|
||||
openpgp.verify(
|
||||
|
@ -477,9 +477,9 @@ function omnibus() {
|
|||
// Verifying detached signature
|
||||
openpgp.verify(
|
||||
{
|
||||
message: openpgp.message.fromText('Hi, this is me, Hi!'),
|
||||
message: openpgp.Message.fromText('Hi, this is me, Hi!'),
|
||||
publicKeys: hi.toPublic(),
|
||||
signature: await openpgp.signature.readArmored(signed)
|
||||
signature: await openpgp.readArmoredSignature(signed)
|
||||
}
|
||||
).then(output => expect(output.signatures[0].valid).to.be.true)
|
||||
]);
|
||||
|
@ -487,12 +487,12 @@ function omnibus() {
|
|||
// Encrypting and signing
|
||||
openpgp.encrypt(
|
||||
{
|
||||
message: openpgp.message.fromText('Hi, Hi wrote this but only Bye can read it!'),
|
||||
message: openpgp.Message.fromText('Hi, Hi wrote this but only Bye can read it!'),
|
||||
publicKeys: [bye.toPublic()],
|
||||
privateKeys: [hi]
|
||||
}
|
||||
).then(async encrypted => {
|
||||
const msg = await openpgp.message.readArmored(encrypted);
|
||||
const msg = await openpgp.readArmoredMessage(encrypted);
|
||||
// Decrypting and verifying
|
||||
return openpgp.decrypt(
|
||||
{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..');
|
||||
|
||||
const { key, cleartext, util, SignaturePacket } = openpgp;
|
||||
const { readArmoredKey, readArmoredCleartextMessage, util, SignaturePacket } = openpgp;
|
||||
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-as-promised'));
|
||||
|
@ -67,7 +67,7 @@ fhGyl7nA7UCwgsqf7ZPBhRg=
|
|||
=nbjQ
|
||||
-----END PGP SIGNATURE-----`;
|
||||
async function getOtherPubKey() {
|
||||
return await key.readArmored(OTHERPUBKEY);
|
||||
return await readArmoredKey(OTHERPUBKEY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +84,7 @@ jhAfE9q2ElqlaAvZZYw=`);
|
|||
async function fakeSignature() {
|
||||
// read the template and modify the text to
|
||||
// invalidate the signature.
|
||||
let fake = await cleartext.readArmored(
|
||||
let fake = await readArmoredCleartextMessage(
|
||||
ORIGINAL.replace(
|
||||
'You owe me',
|
||||
'I owe you'));
|
||||
|
@ -98,7 +98,7 @@ async function fakeSignature() {
|
|||
const faked_armored = await fake.armor();
|
||||
// re-read the message to eliminate any
|
||||
// behaviour due to cached values.
|
||||
fake = await cleartext.readArmored(faked_armored);
|
||||
fake = await readArmoredCleartextMessage(faked_armored);
|
||||
// faked message now verifies correctly
|
||||
const res = await openpgp.verify({
|
||||
message: fake,
|
||||
|
|
|
@ -43,7 +43,7 @@ EnxUPL95HuMKoVkf4w==
|
|||
-----END PGP PRIVATE KEY BLOCK-----`;
|
||||
|
||||
module.exports = () => it('Does not accept message encrypted with algo not mentioned in preferred algorithms', async function() {
|
||||
const message = await openpgp.message.readArmored(messageArmor);
|
||||
const privKey = await openpgp.key.readArmored(privateKeyArmor);
|
||||
const message = await openpgp.readArmoredMessage(messageArmor);
|
||||
const privKey = await openpgp.readArmoredKey(privateKeyArmor);
|
||||
await expect(openpgp.decrypt({ message, privateKeys: [privKey] })).to.be.rejectedWith('A non-preferred symmetric algorithm was used.');
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..');
|
||||
|
||||
const { key, cleartext, enums, PacketList, SignaturePacket } = openpgp;
|
||||
const { readArmoredKey, generate, Key, readArmoredCleartextMessage, CleartextMessage, enums, PacketList, SignaturePacket } = openpgp;
|
||||
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-as-promised'));
|
||||
|
@ -8,7 +8,7 @@ chai.use(require('chai-as-promised'));
|
|||
const expect = chai.expect;
|
||||
|
||||
async function generateTestData() {
|
||||
const victimPrivKey = await key.generate({
|
||||
const victimPrivKey = await generate({
|
||||
userIds: ['Victim <victim@example.com>'],
|
||||
rsaBits: openpgp.util.getWebCryptoAll() ? 2048 : 1024,
|
||||
subkeys: [{
|
||||
|
@ -17,7 +17,7 @@ async function generateTestData() {
|
|||
});
|
||||
victimPrivKey.revocationSignatures = [];
|
||||
|
||||
const attackerPrivKey = await key.generate({
|
||||
const attackerPrivKey = await generate({
|
||||
userIds: ['Attacker <attacker@example.com>'],
|
||||
rsaBits: openpgp.util.getWebCryptoAll() ? 2048 : 1024,
|
||||
subkeys: [],
|
||||
|
@ -25,7 +25,7 @@ async function generateTestData() {
|
|||
});
|
||||
attackerPrivKey.revocationSignatures = [];
|
||||
const signed = await openpgp.sign({
|
||||
message: await cleartext.fromText('I am batman'),
|
||||
message: await CleartextMessage.fromText('I am batman'),
|
||||
privateKeys: victimPrivKey,
|
||||
streaming: false,
|
||||
armor: true
|
||||
|
@ -62,10 +62,10 @@ async function testSubkeyTrust() {
|
|||
pktPubVictim[3], // victim subkey
|
||||
fakeBindingSignature // faked key binding
|
||||
]);
|
||||
let fakeKey = new key.Key(newList);
|
||||
fakeKey = await key.readArmored(await fakeKey.toPublic().armor());
|
||||
let fakeKey = new Key(newList);
|
||||
fakeKey = await readArmoredKey(await fakeKey.toPublic().armor());
|
||||
const verifyAttackerIsBatman = await openpgp.verify({
|
||||
message: (await cleartext.readArmored(signed)),
|
||||
message: (await readArmoredCleartextMessage(signed)),
|
||||
publicKeys: fakeKey,
|
||||
streaming: false
|
||||
});
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp : require('../..');
|
||||
|
||||
const { key, message, enums, PacketList, SignaturePacket } = openpgp;
|
||||
const { readArmoredKey, Key, message, enums, PacketList, SignaturePacket } = openpgp;
|
||||
|
||||
const chai = require('chai');
|
||||
chai.use(require('chai-as-promised'));
|
||||
|
@ -49,7 +49,7 @@ Dc2vwS83Aja9iWrIEg==
|
|||
-----END PGP PRIVATE KEY BLOCK-----`;
|
||||
|
||||
async function getInvalidKey() {
|
||||
return await key.readArmored(INVALID_KEY);
|
||||
return await readArmoredKey(INVALID_KEY);
|
||||
}
|
||||
async function makeKeyValid() {
|
||||
/**
|
||||
|
@ -82,10 +82,10 @@ async function makeKeyValid() {
|
|||
// reconstruct the modified key
|
||||
const newlist = new PacketList();
|
||||
newlist.concat([pubkey, puser, pusersig]);
|
||||
let modifiedkey = new key.Key(newlist);
|
||||
let modifiedkey = new Key(newlist);
|
||||
// re-read the message to eliminate any
|
||||
// behaviour due to cached values.
|
||||
modifiedkey = await key.readArmored(await modifiedkey.armor());
|
||||
modifiedkey = await readArmoredKey(await modifiedkey.armor());
|
||||
|
||||
expect(await encryptFails(invalidkey)).to.be.true;
|
||||
expect(await encryptFails(modifiedkey)).to.be.true;
|
||||
|
|
|
@ -42,11 +42,11 @@ onmessage = async function({ data: { action, message }, ports: [port] }) {
|
|||
let result;
|
||||
switch (action) {
|
||||
case 'encrypt': {
|
||||
const publicKey = await openpgp.key.readArmored(publicKeyArmored);
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const publicKey = await openpgp.readArmoredKey(publicKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt('test');
|
||||
const data = await openpgp.encrypt({
|
||||
message: openpgp.message.fromText(message),
|
||||
message: openpgp.Message.fromText(message),
|
||||
publicKeys: publicKey,
|
||||
privateKeys: privateKey
|
||||
});
|
||||
|
@ -54,11 +54,11 @@ onmessage = async function({ data: { action, message }, ports: [port] }) {
|
|||
break;
|
||||
}
|
||||
case 'decrypt': {
|
||||
const publicKey = await openpgp.key.readArmored(publicKeyArmored);
|
||||
const privateKey = await openpgp.key.readArmored(privateKeyArmored);
|
||||
const publicKey = await openpgp.readArmoredKey(publicKeyArmored);
|
||||
const privateKey = await openpgp.readArmoredKey(privateKeyArmored);
|
||||
await privateKey.decrypt('test');
|
||||
const { data, signatures } = await openpgp.decrypt({
|
||||
message: await openpgp.message.readArmored(message),
|
||||
message: await openpgp.readArmoredMessage(message),
|
||||
publicKeys: publicKey,
|
||||
privateKeys: privateKey
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user