diff --git a/.eslintrc.js b/.eslintrc.js index 06d0c803..7227d416 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -72,7 +72,7 @@ module.exports = { } ], "capitalized-comments": "off", - "class-methods-use-this": "error", + "class-methods-use-this": "off", "comma-dangle": [ "error", "never" ], "comma-spacing": "off", "comma-style": [ @@ -278,7 +278,7 @@ module.exports = { "prefer-spread": "off", "prefer-template": "off", "quote-props": "off", - "quotes": "off", + "quotes": ["error", "single", { "avoidEscape": true }], "require-await": "error", "require-jsdoc": "off", "semi-spacing": [ diff --git a/rollup.config.js b/rollup.config.js index 6d836410..6e1b5104 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -5,7 +5,7 @@ import { builtinModules } from 'module'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import replace from '@rollup/plugin-replace'; -import { terser } from "rollup-plugin-terser"; +import { terser } from 'rollup-plugin-terser'; import pkg from './package.json'; @@ -16,7 +16,7 @@ const banner = `${new Date().toISOString().split('T')[0]} - ` + `this is LGPL licensed code, see LICENSE/our website ${pkg.homepage} for more information. */`; -const intro = `const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};`; +const intro = "const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};"; const terserOptions = { ecma: 2017, diff --git a/src/biginteger/native.interface.js b/src/biginteger/native.interface.js index c27ba240..a524006c 100644 --- a/src/biginteger/native.interface.js +++ b/src/biginteger/native.interface.js @@ -155,9 +155,9 @@ export default class BigInteger { * @returns {BigInteger} this ** e mod n. */ modExp(e, n) { - if (n.isZero()) throw Error("Modulo cannot be zero"); + if (n.isZero()) throw Error('Modulo cannot be zero'); if (n.isOne()) return new BigInteger(0); - if (e.isNegative()) throw Error("Unsopported negative exponent"); + if (e.isNegative()) throw Error('Unsopported negative exponent'); let exp = e.value; let x = this.value; diff --git a/src/config/config.js b/src/config/config.js index 1ee56f8b..25c878d4 100644 --- a/src/config/config.js +++ b/src/config/config.js @@ -154,12 +154,12 @@ export default { * @memberof module:config * @property {String} versionString A version string to be included in armored messages */ - versionString: "OpenPGP.js VERSION", + versionString: 'OpenPGP.js VERSION', /** * @memberof module:config * @property {String} commentString A comment string to be included in armored messages */ - commentString: "https://openpgpjs.org", + commentString: 'https://openpgpjs.org', /** * Max userID string length (used for parsing) @@ -173,7 +173,7 @@ export default { * @memberof module:config * @property {Array} knownNotations */ - knownNotations: ["preferred-email-encoding@pgp.com", "pka-address@gnupg.org"], + knownNotations: ['preferred-email-encoding@pgp.com', 'pka-address@gnupg.org'], /** * @memberof module:config * @property {Boolean} useIndutnyElliptic Whether to use the indutny/elliptic library. When false, certain curves will not be supported. diff --git a/src/crypto/aes_kw.js b/src/crypto/aes_kw.js index 40bdceac..d9bbbb3e 100644 --- a/src/crypto/aes_kw.js +++ b/src/crypto/aes_kw.js @@ -33,7 +33,7 @@ import util from '../util'; * @returns {Uint8Array} */ export function wrap(key, data) { - const aes = new cipher["aes" + (key.length * 8)](key); + const aes = new cipher['aes' + (key.length * 8)](key); const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]); const P = unpack(data); let A = IV; @@ -73,7 +73,7 @@ export function wrap(key, data) { * @throws {Error} */ export function unwrap(key, data) { - const aes = new cipher["aes" + (key.length * 8)](key); + const aes = new cipher['aes' + (key.length * 8)](key); const IV = new Uint32Array([0xA6A6A6A6, 0xA6A6A6A6]); const C = unpack(data); let A = C.subarray(0, 2); @@ -102,7 +102,7 @@ export function unwrap(key, data) { if (A[0] === IV[0] && A[1] === IV[1]) { return pack(R); } - throw new Error("Key Data Integrity failed"); + throw new Error('Key Data Integrity failed'); } function createArrayBuffer(data) { diff --git a/src/crypto/cipher/des.js b/src/crypto/cipher/des.js index 8a2038c7..72436eb8 100644 --- a/src/crypto/cipher/des.js +++ b/src/crypto/cipher/des.js @@ -384,7 +384,7 @@ function desAddPadding(message, padding) { let pad; if (padding === 2 && (padLength < 8)) { //pad the message with spaces - pad = " ".charCodeAt(0); + pad = ' '.charCodeAt(0); } else if (padding === 1) { //PKCS7 padding pad = padLength; } else if (!padding && (padLength < 8)) { //pad the message out with null bytes @@ -410,7 +410,7 @@ function desRemovePadding(message, padding) { let padLength = null; let pad; if (padding === 2) { // space padded - pad = " ".charCodeAt(0); + pad = ' '.charCodeAt(0); } else if (padding === 1) { // PKCS7 padLength = message[message.length - 1]; } else if (!padding) { // null padding diff --git a/src/crypto/cipher/twofish.js b/src/crypto/cipher/twofish.js index bf1dee55..09ded60c 100644 --- a/src/crypto/cipher/twofish.js +++ b/src/crypto/cipher/twofish.js @@ -318,7 +318,7 @@ function createTwofish() { } return { - name: "twofish", + name: 'twofish', blocksize: 128 / 8, open: tfsInit, close: tfsClose, diff --git a/src/crypto/public_key/dsa.js b/src/crypto/public_key/dsa.js index be4f5567..7fa69649 100644 --- a/src/crypto/public_key/dsa.js +++ b/src/crypto/public_key/dsa.js @@ -113,13 +113,13 @@ export async function verify(hashAlgo, r, s, hashed, g, p, q, y) { if (r.lte(zero) || r.gte(q) || s.lte(zero) || s.gte(q)) { - util.printDebug("invalid DSA Signature"); + util.printDebug('invalid DSA Signature'); return false; } const h = new BigInteger(hashed.subarray(0, q.byteLength())).imod(q); const w = s.modInv(q); // s**-1 mod q if (w.isZero()) { - util.printDebug("invalid DSA Signature"); + util.printDebug('invalid DSA Signature'); return false; } diff --git a/src/crypto/public_key/elliptic/curves.js b/src/crypto/public_key/elliptic/curves.js index 2759661c..02db72b5 100644 --- a/src/crypto/public_key/elliptic/curves.js +++ b/src/crypto/public_key/elliptic/curves.js @@ -175,7 +175,7 @@ class Curve { try { return await webGenKeyPair(this.name); } catch (err) { - util.printDebugError("Browser did not support generating ec key " + err.message); + util.printDebugError('Browser did not support generating ec key ' + err.message); break; } case 'node': @@ -299,10 +299,10 @@ export { async function webGenKeyPair(name) { // Note: keys generated with ECDSA and ECDH are structurally equivalent - const webCryptoKey = await webCrypto.generateKey({ name: "ECDSA", namedCurve: webCurves[name] }, true, ["sign", "verify"]); + const webCryptoKey = await webCrypto.generateKey({ name: 'ECDSA', namedCurve: webCurves[name] }, true, ['sign', 'verify']); - const privateKey = await webCrypto.exportKey("jwk", webCryptoKey.privateKey); - const publicKey = await webCrypto.exportKey("jwk", webCryptoKey.publicKey); + const privateKey = await webCrypto.exportKey('jwk', webCryptoKey.privateKey); + const publicKey = await webCrypto.exportKey('jwk', webCryptoKey.publicKey); return { publicKey: jwkToRawPublic(publicKey), @@ -354,7 +354,7 @@ function rawPublicToJWK(payloadSize, name, publicKey) { const bufY = publicKey.slice(len + 1, len * 2 + 1); // https://www.rfc-editor.org/rfc/rfc7518.txt const jwk = { - kty: "EC", + kty: 'EC', crv: name, x: uint8ArrayToB64(bufX, true), y: uint8ArrayToB64(bufY, true), diff --git a/src/crypto/public_key/elliptic/ecdh.js b/src/crypto/public_key/elliptic/ecdh.js index 0839338b..d09f52df 100644 --- a/src/crypto/public_key/elliptic/ecdh.js +++ b/src/crypto/public_key/elliptic/ecdh.js @@ -54,7 +54,7 @@ function buildEcdhParam(public_algo, oid, kdfParams, fingerprint) { oid.write(), new Uint8Array([public_algo]), kdfParams.write(), - util.stringToUint8Array("Anonymous Sender "), + util.stringToUint8Array('Anonymous Sender '), fingerprint.subarray(0, 20) ]); } @@ -219,21 +219,21 @@ export async function decrypt(oid, kdfParams, V, C, Q, d, fingerprint) { async function webPrivateEphemeralKey(curve, V, Q, d) { const recipient = privateToJWK(curve.payloadSize, curve.web.web, Q, d); let privateKey = webCrypto.importKey( - "jwk", + 'jwk', recipient, { - name: "ECDH", + name: 'ECDH', namedCurve: curve.web.web }, true, - ["deriveKey", "deriveBits"] + ['deriveKey', 'deriveBits'] ); const jwk = rawPublicToJWK(curve.payloadSize, curve.web.web, V); let sender = webCrypto.importKey( - "jwk", + 'jwk', jwk, { - name: "ECDH", + name: 'ECDH', namedCurve: curve.web.web }, true, @@ -242,7 +242,7 @@ async function webPrivateEphemeralKey(curve, V, Q, d) { [privateKey, sender] = await Promise.all([privateKey, sender]); let S = webCrypto.deriveBits( { - name: "ECDH", + name: 'ECDH', namedCurve: curve.web.web, public: sender }, @@ -250,7 +250,7 @@ async function webPrivateEphemeralKey(curve, V, Q, d) { curve.web.sharedSize ); let secret = webCrypto.exportKey( - "jwk", + 'jwk', privateKey ); [S, secret] = await Promise.all([S, secret]); @@ -271,17 +271,17 @@ async function webPublicEphemeralKey(curve, Q) { const jwk = rawPublicToJWK(curve.payloadSize, curve.web.web, Q); let keyPair = webCrypto.generateKey( { - name: "ECDH", + name: 'ECDH', namedCurve: curve.web.web }, true, - ["deriveKey", "deriveBits"] + ['deriveKey', 'deriveBits'] ); let recipient = webCrypto.importKey( - "jwk", + 'jwk', jwk, { - name: "ECDH", + name: 'ECDH', namedCurve: curve.web.web }, false, @@ -290,7 +290,7 @@ async function webPublicEphemeralKey(curve, Q) { [keyPair, recipient] = await Promise.all([keyPair, recipient]); let s = webCrypto.deriveBits( { - name: "ECDH", + name: 'ECDH', namedCurve: curve.web.web, public: recipient }, @@ -298,7 +298,7 @@ async function webPublicEphemeralKey(curve, Q) { curve.web.sharedSize ); let p = webCrypto.exportKey( - "jwk", + 'jwk', keyPair.publicKey ); [s, p] = await Promise.all([s, p]); diff --git a/src/crypto/public_key/elliptic/ecdsa.js b/src/crypto/public_key/elliptic/ecdsa.js index 40d2572a..a4a396b0 100644 --- a/src/crypto/public_key/elliptic/ecdsa.js +++ b/src/crypto/public_key/elliptic/ecdsa.js @@ -62,7 +62,7 @@ export async function sign(oid, hashAlgo, message, publicKey, privateKey, hashed if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) { throw err; } - util.printDebugError("Browser did not support signing: " + err.message); + util.printDebugError('Browser did not support signing: ' + err.message); } break; } @@ -105,7 +105,7 @@ export async function verify(oid, hashAlgo, signature, message, publicKey, hashe if (curve.name !== 'p521' && (err.name === 'DataError' || err.name === 'OperationError')) { throw err; } - util.printDebugError("Browser did not support verifying: " + err.message); + util.printDebugError('Browser did not support verifying: ' + err.message); } break; case 'node': @@ -178,22 +178,22 @@ async function webSign(curve, hashAlgo, message, keyPair) { const len = curve.payloadSize; const jwk = privateToJWK(curve.payloadSize, webCurves[curve.name], keyPair.publicKey, keyPair.privateKey); const key = await webCrypto.importKey( - "jwk", + 'jwk', jwk, { - "name": "ECDSA", - "namedCurve": webCurves[curve.name], - "hash": { name: enums.read(enums.webHash, curve.hash) } + 'name': 'ECDSA', + 'namedCurve': webCurves[curve.name], + 'hash': { name: enums.read(enums.webHash, curve.hash) } }, false, - ["sign"] + ['sign'] ); const signature = new Uint8Array(await webCrypto.sign( { - "name": 'ECDSA', - "namedCurve": webCurves[curve.name], - "hash": { name: enums.read(enums.webHash, hashAlgo) } + 'name': 'ECDSA', + 'namedCurve': webCurves[curve.name], + 'hash': { name: enums.read(enums.webHash, hashAlgo) } }, key, message @@ -208,24 +208,24 @@ async function webSign(curve, hashAlgo, message, keyPair) { async function webVerify(curve, hashAlgo, { r, s }, message, publicKey) { const jwk = rawPublicToJWK(curve.payloadSize, webCurves[curve.name], publicKey); const key = await webCrypto.importKey( - "jwk", + 'jwk', jwk, { - "name": "ECDSA", - "namedCurve": webCurves[curve.name], - "hash": { name: enums.read(enums.webHash, curve.hash) } + 'name': 'ECDSA', + 'namedCurve': webCurves[curve.name], + 'hash': { name: enums.read(enums.webHash, curve.hash) } }, false, - ["verify"] + ['verify'] ); const signature = util.concatUint8Array([r, s]).buffer; return webCrypto.verify( { - "name": 'ECDSA', - "namedCurve": webCurves[curve.name], - "hash": { name: enums.read(enums.webHash, hashAlgo) } + 'name': 'ECDSA', + 'namedCurve': webCurves[curve.name], + 'hash': { name: enums.read(enums.webHash, hashAlgo) } }, key, signature, diff --git a/src/crypto/public_key/rsa.js b/src/crypto/public_key/rsa.js index 3a8eae93..72f2fe83 100644 --- a/src/crypto/public_key/rsa.js +++ b/src/crypto/public_key/rsa.js @@ -318,12 +318,12 @@ async function webSign(hashName, data, n, e, d, p, q, u) { */ const jwk = await privateToJWK(n, e, d, p, q, u); const algo = { - name: "RSASSA-PKCS1-v1_5", + name: 'RSASSA-PKCS1-v1_5', hash: { name: hashName } }; - const key = await webCrypto.importKey("jwk", jwk, algo, false, ["sign"]); + const key = await webCrypto.importKey('jwk', jwk, algo, false, ['sign']); // add hash field for ms edge support - return new Uint8Array(await webCrypto.sign({ "name": "RSASSA-PKCS1-v1_5", "hash": hashName }, key, data)); + return new Uint8Array(await webCrypto.sign({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, data)); } async function nodeSign(hashAlgo, data, n, e, d, p, q, u) { @@ -374,12 +374,12 @@ async function bnVerify(hashAlgo, s, n, e, hashed) { async function webVerify(hashName, data, s, n, e) { const jwk = publicToJWK(n, e); - const key = await webCrypto.importKey("jwk", jwk, { - name: "RSASSA-PKCS1-v1_5", + const key = await webCrypto.importKey('jwk', jwk, { + name: 'RSASSA-PKCS1-v1_5', hash: { name: hashName } - }, false, ["verify"]); + }, false, ['verify']); // add hash field for ms edge support - return webCrypto.verify({ "name": "RSASSA-PKCS1-v1_5", "hash": hashName }, key, s, data); + return webCrypto.verify({ 'name': 'RSASSA-PKCS1-v1_5', 'hash': hashName }, key, s, data); } async function nodeVerify(hashAlgo, data, s, n, e) { diff --git a/src/encoding/armor.js b/src/encoding/armor.js index 32a48da5..edf8a05f 100644 --- a/src/encoding/armor.js +++ b/src/encoding/armor.js @@ -93,15 +93,15 @@ function getType(text) { * @private */ function addheader(customComment, config) { - let result = ""; + let result = ''; if (config.showVersion) { - result += "Version: " + config.versionString + '\n'; + result += 'Version: ' + config.versionString + '\n'; } if (config.showComment) { - result += "Comment: " + config.commentString + '\n'; + result += 'Comment: ' + config.commentString + '\n'; } if (customComment) { - result += "Comment: " + customComment + '\n'; + result += 'Comment: ' + customComment + '\n'; } result += '\n'; return result; @@ -207,9 +207,9 @@ function verifyHeaders(headers) { */ function splitChecksum(text) { let body = text; - let checksum = ""; + let checksum = ''; - const lastEquals = text.lastIndexOf("="); + const lastEquals = text.lastIndexOf('='); if (lastEquals >= 0 && lastEquals !== text.length - 1) { // '=' as the last char means no checksum body = text.slice(0, lastEquals); @@ -371,56 +371,56 @@ export function armor(messageType, body, partIndex, partTotal, customComment, co const result = []; switch (messageType) { case enums.armor.multipartSection: - result.push("-----BEGIN PGP MESSAGE, PART " + partIndex + "/" + partTotal + "-----\n"); + result.push('-----BEGIN PGP MESSAGE, PART ' + partIndex + '/' + partTotal + '-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP MESSAGE, PART " + partIndex + "/" + partTotal + "-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP MESSAGE, PART ' + partIndex + '/' + partTotal + '-----\n'); break; case enums.armor.multipartLast: - result.push("-----BEGIN PGP MESSAGE, PART " + partIndex + "-----\n"); + result.push('-----BEGIN PGP MESSAGE, PART ' + partIndex + '-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP MESSAGE, PART " + partIndex + "-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP MESSAGE, PART ' + partIndex + '-----\n'); break; case enums.armor.signed: - result.push("\n-----BEGIN PGP SIGNED MESSAGE-----\n"); - result.push("Hash: " + hash + "\n\n"); - result.push(text.replace(/^-/mg, "- -")); - result.push("\n-----BEGIN PGP SIGNATURE-----\n"); + result.push('\n-----BEGIN PGP SIGNED MESSAGE-----\n'); + result.push('Hash: ' + hash + '\n\n'); + result.push(text.replace(/^-/mg, '- -')); + result.push('\n-----BEGIN PGP SIGNATURE-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP SIGNATURE-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP SIGNATURE-----\n'); break; case enums.armor.message: - result.push("-----BEGIN PGP MESSAGE-----\n"); + result.push('-----BEGIN PGP MESSAGE-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP MESSAGE-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP MESSAGE-----\n'); break; case enums.armor.publicKey: - result.push("-----BEGIN PGP PUBLIC KEY BLOCK-----\n"); + result.push('-----BEGIN PGP PUBLIC KEY BLOCK-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP PUBLIC KEY BLOCK-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP PUBLIC KEY BLOCK-----\n'); break; case enums.armor.privateKey: - result.push("-----BEGIN PGP PRIVATE KEY BLOCK-----\n"); + result.push('-----BEGIN PGP PRIVATE KEY BLOCK-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP PRIVATE KEY BLOCK-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP PRIVATE KEY BLOCK-----\n'); break; case enums.armor.signature: - result.push("-----BEGIN PGP SIGNATURE-----\n"); + result.push('-----BEGIN PGP SIGNATURE-----\n'); result.push(addheader(customComment, config)); result.push(base64.encode(body)); - result.push("=", getCheckSum(bodyClone)); - result.push("-----END PGP SIGNATURE-----\n"); + result.push('=', getCheckSum(bodyClone)); + result.push('-----END PGP SIGNATURE-----\n'); break; } diff --git a/src/enums.js b/src/enums.js index 7b8f74eb..16c31601 100644 --- a/src/enums.js +++ b/src/enums.js @@ -13,70 +13,70 @@ export default { */ curve: { /** NIST P-256 Curve */ - "p256": "p256", - "P-256": "p256", - "secp256r1": "p256", - "prime256v1": "p256", - "1.2.840.10045.3.1.7": "p256", - "2a8648ce3d030107": "p256", - "2A8648CE3D030107": "p256", + 'p256': 'p256', + 'P-256': 'p256', + 'secp256r1': 'p256', + 'prime256v1': 'p256', + '1.2.840.10045.3.1.7': 'p256', + '2a8648ce3d030107': 'p256', + '2A8648CE3D030107': 'p256', /** NIST P-384 Curve */ - "p384": "p384", - "P-384": "p384", - "secp384r1": "p384", - "1.3.132.0.34": "p384", - "2b81040022": "p384", - "2B81040022": "p384", + 'p384': 'p384', + 'P-384': 'p384', + 'secp384r1': 'p384', + '1.3.132.0.34': 'p384', + '2b81040022': 'p384', + '2B81040022': 'p384', /** NIST P-521 Curve */ - "p521": "p521", - "P-521": "p521", - "secp521r1": "p521", - "1.3.132.0.35": "p521", - "2b81040023": "p521", - "2B81040023": "p521", + 'p521': 'p521', + 'P-521': 'p521', + 'secp521r1': 'p521', + '1.3.132.0.35': 'p521', + '2b81040023': 'p521', + '2B81040023': 'p521', /** SECG SECP256k1 Curve */ - "secp256k1": "secp256k1", - "1.3.132.0.10": "secp256k1", - "2b8104000a": "secp256k1", - "2B8104000A": "secp256k1", + 'secp256k1': 'secp256k1', + '1.3.132.0.10': 'secp256k1', + '2b8104000a': 'secp256k1', + '2B8104000A': 'secp256k1', /** Ed25519 */ - "ED25519": "ed25519", - "ed25519": "ed25519", - "Ed25519": "ed25519", - "1.3.6.1.4.1.11591.15.1": "ed25519", - "2b06010401da470f01": "ed25519", - "2B06010401DA470F01": "ed25519", + 'ED25519': 'ed25519', + 'ed25519': 'ed25519', + 'Ed25519': 'ed25519', + '1.3.6.1.4.1.11591.15.1': 'ed25519', + '2b06010401da470f01': 'ed25519', + '2B06010401DA470F01': 'ed25519', /** Curve25519 */ - "X25519": "curve25519", - "cv25519": "curve25519", - "curve25519": "curve25519", - "Curve25519": "curve25519", - "1.3.6.1.4.1.3029.1.5.1": "curve25519", - "2b060104019755010501": "curve25519", - "2B060104019755010501": "curve25519", + 'X25519': 'curve25519', + 'cv25519': 'curve25519', + 'curve25519': 'curve25519', + 'Curve25519': 'curve25519', + '1.3.6.1.4.1.3029.1.5.1': 'curve25519', + '2b060104019755010501': 'curve25519', + '2B060104019755010501': 'curve25519', /** BrainpoolP256r1 Curve */ - "brainpoolP256r1": "brainpoolP256r1", - "1.3.36.3.3.2.8.1.1.7": "brainpoolP256r1", - "2b2403030208010107": "brainpoolP256r1", - "2B2403030208010107": "brainpoolP256r1", + 'brainpoolP256r1': 'brainpoolP256r1', + '1.3.36.3.3.2.8.1.1.7': 'brainpoolP256r1', + '2b2403030208010107': 'brainpoolP256r1', + '2B2403030208010107': 'brainpoolP256r1', /** BrainpoolP384r1 Curve */ - "brainpoolP384r1": "brainpoolP384r1", - "1.3.36.3.3.2.8.1.1.11": "brainpoolP384r1", - "2b240303020801010b": "brainpoolP384r1", - "2B240303020801010B": "brainpoolP384r1", + 'brainpoolP384r1': 'brainpoolP384r1', + '1.3.36.3.3.2.8.1.1.11': 'brainpoolP384r1', + '2b240303020801010b': 'brainpoolP384r1', + '2B240303020801010B': 'brainpoolP384r1', /** BrainpoolP512r1 Curve */ - "brainpoolP512r1": "brainpoolP512r1", - "1.3.36.3.3.2.8.1.1.13": "brainpoolP512r1", - "2b240303020801010d": "brainpoolP512r1", - "2B240303020801010D": "brainpoolP512r1" + 'brainpoolP512r1': 'brainpoolP512r1', + '1.3.36.3.3.2.8.1.1.13': 'brainpoolP512r1', + '2b240303020801010d': 'brainpoolP512r1', + '2B240303020801010D': 'brainpoolP512r1' }, /** A string to key specifier type diff --git a/src/key/private_key.js b/src/key/private_key.js index e7d1bd49..3264b8f1 100644 --- a/src/key/private_key.js +++ b/src/key/private_key.js @@ -28,7 +28,6 @@ class PrivateKey extends PublicKey { * Returns true if this is a private key * @returns {Boolean} */ - // eslint-disable-next-line class-methods-use-this isPrivate() { return true; } @@ -123,7 +122,7 @@ class PrivateKey extends PublicKey { */ async validate(config = defaultConfig) { if (!this.isPrivate()) { - throw new Error("Cannot validate a public key"); + throw new Error('Cannot validate a public key'); } let signingKeyPacket; @@ -147,7 +146,7 @@ class PrivateKey extends PublicKey { const keys = this.getKeys(); const allDummies = keys.map(key => key.keyPacket.isDummy()).every(Boolean); if (allDummies) { - throw new Error("Cannot validate an all-gnu-dummy key"); + throw new Error('Cannot validate an all-gnu-dummy key'); } return Promise.all(keys.map(async key => key.keyPacket.validate())); @@ -213,17 +212,17 @@ class PrivateKey extends PublicKey { async addSubkey(options = {}) { const config = { ...defaultConfig, ...options.config }; if (options.passphrase) { - throw new Error("Subkey could not be encrypted here, please encrypt whole key"); + throw new Error('Subkey could not be encrypted here, please encrypt whole key'); } if (options.rsaBits < config.minRSABits) { throw new Error(`rsaBits should be at least ${config.minRSABits}, got: ${options.rsaBits}`); } const secretKeyPacket = this.keyPacket; if (secretKeyPacket.isDummy()) { - throw new Error("Cannot add subkey to gnu-dummy primary key"); + throw new Error('Cannot add subkey to gnu-dummy primary key'); } if (!secretKeyPacket.isDecrypted()) { - throw new Error("Key is not decrypted"); + throw new Error('Key is not decrypted'); } const defaultOptions = secretKeyPacket.getAlgorithmInfo(); defaultOptions.type = defaultOptions.curve ? 'ecc' : 'rsa'; // DSA keys default to RSA diff --git a/src/key/public_key.js b/src/key/public_key.js index c2c10fe2..66eac924 100644 --- a/src/key/public_key.js +++ b/src/key/public_key.js @@ -1,4 +1,3 @@ -/* eslint-disable class-methods-use-this */ // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either @@ -44,7 +43,6 @@ class PublicKey extends Key { * Returns true if this is a private key * @returns {false} */ - // eslint-disable-next-line class-methods-use-this isPrivate() { return false; } diff --git a/src/openpgp.js b/src/openpgp.js index 43984911..2bf90cfe 100644 --- a/src/openpgp.js +++ b/src/openpgp.js @@ -51,13 +51,13 @@ import util from './util'; * @async * @static */ -export async function generateKey({ userIDs = [], passphrase = "", type = "ecc", rsaBits = 4096, curve = "curve25519", keyExpirationTime = 0, date = new Date(), subkeys = [{}], format = 'armor', config }) { +export async function generateKey({ userIDs = [], passphrase = '', type = 'ecc', rsaBits = 4096, curve = 'curve25519', keyExpirationTime = 0, date = new Date(), subkeys = [{}], format = 'armor', config }) { config = { ...defaultConfig, ...config }; userIDs = toArray(userIDs); if (userIDs.length === 0) { throw new Error('UserIDs are required for key generation'); } - if (type === "rsa" && rsaBits < config.minRSABits) { + if (type === 'rsa' && rsaBits < config.minRSABits) { throw new Error(`rsaBits should be at least ${config.minRSABits}, got: ${rsaBits}`); } const options = { userIDs, passphrase, type, rsaBits, curve, keyExpirationTime, date, subkeys }; @@ -90,7 +90,7 @@ export async function generateKey({ userIDs = [], passphrase = "", type = "ecc", * @async * @static */ -export async function reformatKey({ privateKey, userIDs = [], passphrase = "", keyExpirationTime = 0, date, format = 'armor', config }) { +export async function reformatKey({ privateKey, userIDs = [], passphrase = '', keyExpirationTime = 0, date, format = 'armor', config }) { config = { ...defaultConfig, ...config }; userIDs = toArray(userIDs); if (userIDs.length === 0) { @@ -161,7 +161,7 @@ export async function revokeKey({ key, revocationCertificate, reasonForRevocatio export async function decryptKey({ privateKey, passphrase, config }) { config = { ...defaultConfig, ...config }; if (!privateKey.isPrivate()) { - throw new Error("Cannot decrypt a public key"); + throw new Error('Cannot decrypt a public key'); } const clonedPrivateKey = privateKey.clone(true); const passphrases = util.isArray(passphrase) ? passphrase : [passphrase]; @@ -193,14 +193,14 @@ export async function decryptKey({ privateKey, passphrase, config }) { export async function encryptKey({ privateKey, passphrase, config }) { config = { ...defaultConfig, ...config }; if (!privateKey.isPrivate()) { - throw new Error("Cannot encrypt a public key"); + throw new Error('Cannot encrypt a public key'); } const clonedPrivateKey = privateKey.clone(true); const keys = clonedPrivateKey.getKeys(); const passphrases = util.isArray(passphrase) ? passphrase : new Array(keys.length).fill(passphrase); if (passphrases.length !== keys.length) { - throw new Error("Invalid number of passphrases given for key encryption"); + throw new Error('Invalid number of passphrases given for key encryption'); } try { @@ -253,8 +253,8 @@ export async function encrypt({ message, encryptionKeys, signingKeys, passwords, if (rest.detached) { throw new Error("The `detached` option has been removed from openpgp.encrypt, separately call openpgp.sign instead. Don't forget to remove the `privateKeys` option as well."); } - if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.encrypt, pass `encryptionKeys` instead"); - if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.encrypt, pass `signingKeys` instead"); + if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.encrypt, pass `encryptionKeys` instead'); + if (rest.privateKeys) throw new Error('The `privateKeys` option has been removed from openpgp.encrypt, pass `signingKeys` instead'); if (!signingKeys) { signingKeys = []; @@ -311,8 +311,8 @@ export async function encrypt({ message, encryptionKeys, signingKeys, passwords, export async function decrypt({ message, decryptionKeys, passwords, sessionKeys, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config, ...rest }) { config = { ...defaultConfig, ...config }; checkMessage(message); verificationKeys = toArray(verificationKeys); decryptionKeys = toArray(decryptionKeys); passwords = toArray(passwords); sessionKeys = toArray(sessionKeys); - if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.decrypt, pass `decryptionKeys` instead"); - if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.decrypt, pass `verificationKeys` instead"); + if (rest.privateKeys) throw new Error('The `privateKeys` option has been removed from openpgp.decrypt, pass `decryptionKeys` instead'); + if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.decrypt, pass `verificationKeys` instead'); try { const decrypted = await message.decrypt(decryptionKeys, passwords, sessionKeys, date, config); @@ -373,7 +373,7 @@ export async function decrypt({ message, decryptionKeys, passwords, sessionKeys, export async function sign({ message, signingKeys, armor = true, detached = false, signingKeyIDs = [], date = new Date(), signingUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; checkCleartextOrMessage(message); - if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.sign, pass `signingKeys` instead"); + if (rest.privateKeys) throw new Error('The `privateKeys` option has been removed from openpgp.sign, pass `signingKeys` instead'); if (message instanceof CleartextMessage && !armor) throw new Error("Can't sign non-armored cleartext message"); if (message instanceof CleartextMessage && detached) throw new Error("Can't detach-sign a cleartext message"); @@ -433,7 +433,7 @@ export async function sign({ message, signingKeys, armor = true, detached = fals export async function verify({ message, verificationKeys, expectSigned = false, format = 'utf8', signature = null, date = new Date(), config, ...rest }) { config = { ...defaultConfig, ...config }; checkCleartextOrMessage(message); - if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.verify, pass `verificationKeys` instead"); + if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.verify, pass `verificationKeys` instead'); if (message instanceof CleartextMessage && format === 'binary') throw new Error("Can't return cleartext message data as binary"); if (message instanceof CleartextMessage && signature) throw new Error("Can't verify detached cleartext signature"); @@ -488,7 +488,7 @@ export async function verify({ message, verificationKeys, expectSigned = false, export async function generateSessionKey({ encryptionKeys, date = new Date(), encryptionUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; encryptionKeys = toArray(encryptionKeys); encryptionUserIDs = toArray(encryptionUserIDs); - if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.generateSessionKey, pass `encryptionKeys` instead"); + if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.generateSessionKey, pass `encryptionKeys` instead'); try { const sessionKeys = await Message.generateSessionKey(encryptionKeys, date, encryptionUserIDs, config); @@ -520,7 +520,7 @@ export async function generateSessionKey({ encryptionKeys, date = new Date(), en export async function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryptionKeys, passwords, armor = true, wildcard = false, encryptionKeyIDs = [], date = new Date(), encryptionUserIDs = [], config, ...rest }) { config = { ...defaultConfig, ...config }; checkBinary(data); checkString(algorithm, 'algorithm'); encryptionKeys = toArray(encryptionKeys); passwords = toArray(passwords); encryptionKeyIDs = toArray(encryptionKeyIDs); encryptionUserIDs = toArray(encryptionUserIDs); - if (rest.publicKeys) throw new Error("The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead"); + if (rest.publicKeys) throw new Error('The `publicKeys` option has been removed from openpgp.encryptSessionKey, pass `encryptionKeys` instead'); try { const message = await Message.encryptSessionKey(data, algorithm, aeadAlgorithm, encryptionKeys, passwords, wildcard, encryptionKeyIDs, date, encryptionUserIDs, config); @@ -548,7 +548,7 @@ export async function encryptSessionKey({ data, algorithm, aeadAlgorithm, encryp export async function decryptSessionKeys({ message, decryptionKeys, passwords, date = new Date(), config, ...rest }) { config = { ...defaultConfig, ...config }; checkMessage(message); decryptionKeys = toArray(decryptionKeys); passwords = toArray(passwords); - if (rest.privateKeys) throw new Error("The `privateKeys` option has been removed from openpgp.decryptSessionKeys, pass `decryptionKeys` instead"); + if (rest.privateKeys) throw new Error('The `privateKeys` option has been removed from openpgp.decryptSessionKeys, pass `decryptionKeys` instead'); try { const sessionKeys = await message.decryptSessionKeys(decryptionKeys, passwords, date, config); diff --git a/src/packet/marker.js b/src/packet/marker.js index 1ee18fbf..6d7c1d15 100644 --- a/src/packet/marker.js +++ b/src/packet/marker.js @@ -15,8 +15,6 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -/* eslint class-methods-use-this: ["error", { "exceptMethods": ["read"] }] */ - import enums from '../enums'; /** @@ -55,7 +53,6 @@ class MarkerPacket { return false; } - // eslint-disable-next-line class-methods-use-this write() { return new Uint8Array([0x50, 0x47, 0x50]); } diff --git a/src/packet/packet.js b/src/packet/packet.js index 1a083a7f..1bf2e144 100644 --- a/src/packet/packet.js +++ b/src/packet/packet.js @@ -125,7 +125,7 @@ export async function readPackets(input, callback) { const peekedBytes = await reader.peekBytes(2); // some sanity checks if (!peekedBytes || peekedBytes.length < 2 || (peekedBytes[0] & 0x80) === 0) { - throw new Error("Error during parsing. This message / key probably does not conform to a valid OpenPGP format."); + throw new Error('Error during parsing. This message / key probably does not conform to a valid OpenPGP format.'); } const headerByte = await reader.readByte(); let tag = -1; diff --git a/src/packet/public_key.js b/src/packet/public_key.js index 141eb95c..7c273e6e 100644 --- a/src/packet/public_key.js +++ b/src/packet/public_key.js @@ -15,8 +15,6 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -/* eslint class-methods-use-this: ["error", { "exceptMethods": ["isDecrypted"] }] */ - import KeyID from '../type/keyid'; import defaultConfig from '../config'; import crypto from '../crypto'; diff --git a/src/packet/trust.js b/src/packet/trust.js index a315af1c..99c92718 100644 --- a/src/packet/trust.js +++ b/src/packet/trust.js @@ -1,5 +1,3 @@ -/* eslint class-methods-use-this: ["error", { "exceptMethods": ["read"] }] */ - import enums from '../enums'; import { UnsupportedError } from './packet'; @@ -31,7 +29,6 @@ class TrustPacket { throw new UnsupportedError('Trust packets are not supported'); } - // eslint-disable-next-line class-methods-use-this write() { throw new UnsupportedError('Trust packets are not supported'); } diff --git a/src/type/s2k.js b/src/type/s2k.js index f41d8677..9fcf5655 100644 --- a/src/type/s2k.js +++ b/src/type/s2k.js @@ -88,22 +88,22 @@ class S2K { break; case 'gnu': - if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === "GNU") { + if (util.uint8ArrayToString(bytes.subarray(i, i + 3)) === 'GNU') { i += 3; // GNU const gnuExtType = 1000 + bytes[i++]; if (gnuExtType === 1001) { this.type = 'gnu-dummy'; // GnuPG extension mode 1001 -- don't write secret key at all } else { - throw new Error("Unknown s2k gnu protection mode."); + throw new Error('Unknown s2k gnu protection mode.'); } } else { - throw new Error("Unknown s2k type."); + throw new Error('Unknown s2k type.'); } break; default: - throw new Error("Unknown s2k type."); + throw new Error('Unknown s2k type.'); } return i; @@ -131,9 +131,9 @@ class S2K { arr.push(new Uint8Array([this.c])); break; case 'gnu': - throw new Error("GNU s2k type not supported."); + throw new Error('GNU s2k type not supported.'); default: - throw new Error("Unknown s2k type."); + throw new Error('Unknown s2k type.'); } return util.concatUint8Array(arr); @@ -176,9 +176,9 @@ class S2K { break; } case 'gnu': - throw new Error("GNU s2k type not supported."); + throw new Error('GNU s2k type not supported.'); default: - throw new Error("Unknown s2k type."); + throw new Error('Unknown s2k type.'); } const result = await crypto.hash.digest(algorithm, toHash); arr.push(result); diff --git a/src/util.js b/src/util.js index a810851f..29407f27 100644 --- a/src/util.js +++ b/src/util.js @@ -154,9 +154,9 @@ const util = { while (c < e) { h = bytes[c++].toString(16); while (h.length < 2) { - h = "0" + h; + h = '0' + h; } - r.push("" + h); + r.push('' + h); } return r.join(''); }, diff --git a/test/crypto/aes_kw.js b/test/crypto/aes_kw.js index 5e519617..71da6699 100644 --- a/test/crypto/aes_kw.js +++ b/test/crypto/aes_kw.js @@ -6,49 +6,49 @@ const expect = require('chai').expect; module.exports = () => describe('AES Key Wrap and Unwrap', function () { const test_vectors = [ [ - "128 bits of Key Data with a 128-bit KEK", - "000102030405060708090A0B0C0D0E0F", - "00112233445566778899AABBCCDDEEFF", - "1FA68B0A8112B447 AEF34BD8FB5A7B82 9D3E862371D2CFE5" + '128 bits of Key Data with a 128-bit KEK', + '000102030405060708090A0B0C0D0E0F', + '00112233445566778899AABBCCDDEEFF', + '1FA68B0A8112B447 AEF34BD8FB5A7B82 9D3E862371D2CFE5' ], [ - "128 bits of Key Data with a 192-bit KEK", - "000102030405060708090A0B0C0D0E0F1011121314151617", - "00112233445566778899AABBCCDDEEFF", - "96778B25AE6CA435 F92B5B97C050AED2 468AB8A17AD84E5D" + '128 bits of Key Data with a 192-bit KEK', + '000102030405060708090A0B0C0D0E0F1011121314151617', + '00112233445566778899AABBCCDDEEFF', + '96778B25AE6CA435 F92B5B97C050AED2 468AB8A17AD84E5D' ], [ - "128 bits of Key Data with a 256-bit KEK", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "00112233445566778899AABBCCDDEEFF", - "64E8C3F9CE0F5BA2 63E9777905818A2A 93C8191E7D6E8AE7" + '128 bits of Key Data with a 256-bit KEK', + '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F', + '00112233445566778899AABBCCDDEEFF', + '64E8C3F9CE0F5BA2 63E9777905818A2A 93C8191E7D6E8AE7' ], [ - "192 bits of Key Data with a 192-bit KEK", - "000102030405060708090A0B0C0D0E0F1011121314151617", - "00112233445566778899AABBCCDDEEFF0001020304050607", - "031D33264E15D332 68F24EC260743EDC E1C6C7DDEE725A93 6BA814915C6762D2" + '192 bits of Key Data with a 192-bit KEK', + '000102030405060708090A0B0C0D0E0F1011121314151617', + '00112233445566778899AABBCCDDEEFF0001020304050607', + '031D33264E15D332 68F24EC260743EDC E1C6C7DDEE725A93 6BA814915C6762D2' ], [ - "192 bits of Key Data with a 256-bit KEK", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "00112233445566778899AABBCCDDEEFF0001020304050607", - "A8F9BC1612C68B3F F6E6F4FBE30E71E4 769C8B80A32CB895 8CD5D17D6B254DA1" + '192 bits of Key Data with a 256-bit KEK', + '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F', + '00112233445566778899AABBCCDDEEFF0001020304050607', + 'A8F9BC1612C68B3F F6E6F4FBE30E71E4 769C8B80A32CB895 8CD5D17D6B254DA1' ], [ - "256 bits of Key Data with a 256-bit KEK", - "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F", - "00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F", - "28C9F404C4B810F4 CBCCB35CFB87F826 3F5786E2D80ED326 CBC7F0E71A99F43B FB988B9B7A02DD21" + '256 bits of Key Data with a 256-bit KEK', + '000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F', + '00112233445566778899AABBCCDDEEFF000102030405060708090A0B0C0D0E0F', + '28C9F404C4B810F4 CBCCB35CFB87F826 3F5786E2D80ED326 CBC7F0E71A99F43B FB988B9B7A02DD21' ] ]; test_vectors.forEach(function(test) { it(test[0], function(done) { const kek = util.hexToUint8Array(test[1]); - const input = test[2].replace(/\s/g, ""); + const input = test[2].replace(/\s/g, ''); const input_bin = util.uint8ArrayToString(util.hexToUint8Array(input)); - const output = test[3].replace(/\s/g, ""); + const output = test[3].replace(/\s/g, ''); const output_bin = util.uint8ArrayToString(util.hexToUint8Array(output)); expect(util.uint8ArrayToHex(aesKW.wrap(kek, input_bin)).toUpperCase()).to.equal(output); expect(util.uint8ArrayToHex(aesKW.unwrap(kek, output_bin)).toUpperCase()).to.equal(input); diff --git a/test/crypto/crypto.js b/test/crypto/crypto.js index a9190dee..5668ead4 100644 --- a/test/crypto/crypto.js +++ b/test/crypto/crypto.js @@ -207,7 +207,7 @@ module.exports = () => describe('API functional testing', function() { const elGamalPublicParams = crypto.parsePublicKeyParams(algoElGamal, elGamalPublicKeyMaterial).publicParams; const elGamalPrivateParams = crypto.parsePrivateKeyParams(algoElGamal, elGamalPrivateKeyMaterial).privateParams; - const data = util.stringToUint8Array("foobar"); + const data = util.stringToUint8Array('foobar'); describe('Sign and verify', function () { it('RSA', async function () { @@ -247,11 +247,11 @@ module.exports = () => describe('API functional testing', function() { expect(text).to.equal(plaintext); })); } - it("Symmetric with OpenPGP CFB", async function () { - await testCFB("hello"); - await testCFB("1234567"); - await testCFB("foobarfoobar1234567890"); - await testCFB("12345678901234567890123456789012345678901234567890"); + it('Symmetric with OpenPGP CFB', async function () { + await testCFB('hello'); + await testCFB('1234567'); + await testCFB('foobarfoobar1234567890'); + await testCFB('12345678901234567890123456789012345678901234567890'); }); it('Asymmetric using RSA with eme_pkcs1 padding', async function () { diff --git a/test/crypto/eax.js b/test/crypto/eax.js index be9934b3..d137ac02 100644 --- a/test/crypto/eax.js +++ b/test/crypto/eax.js @@ -16,74 +16,74 @@ function testAESEAX() { const vectors = [ // From http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf ... { - msg: "", - key: "233952DEE4D5ED5F9B9C6D6FF80FF478", - nonce: "62EC67F9C3A4A407FCB2A8C49031A8B3", - header: "6BFB914FD07EAE6B", - ct: "E037830E8389F27B025A2D6527E79D01" + msg: '', + key: '233952DEE4D5ED5F9B9C6D6FF80FF478', + nonce: '62EC67F9C3A4A407FCB2A8C49031A8B3', + header: '6BFB914FD07EAE6B', + ct: 'E037830E8389F27B025A2D6527E79D01' }, { - msg: "F7FB", - key: "91945D3F4DCBEE0BF45EF52255F095A4", - nonce: "BECAF043B0A23D843194BA972C66DEBD", - header: "FA3BFD4806EB53FA", - ct: "19DD5C4C9331049D0BDAB0277408F67967E5" + msg: 'F7FB', + key: '91945D3F4DCBEE0BF45EF52255F095A4', + nonce: 'BECAF043B0A23D843194BA972C66DEBD', + header: 'FA3BFD4806EB53FA', + ct: '19DD5C4C9331049D0BDAB0277408F67967E5' }, { - msg: "1A47CB4933", - key: "01F74AD64077F2E704C0F60ADA3DD523", - nonce: "70C3DB4F0D26368400A10ED05D2BFF5E", - header: "234A3463C1264AC6", - ct: "D851D5BAE03A59F238A23E39199DC9266626C40F80" + msg: '1A47CB4933', + key: '01F74AD64077F2E704C0F60ADA3DD523', + nonce: '70C3DB4F0D26368400A10ED05D2BFF5E', + header: '234A3463C1264AC6', + ct: 'D851D5BAE03A59F238A23E39199DC9266626C40F80' }, { - msg: "481C9E39B1", - key: "D07CF6CBB7F313BDDE66B727AFD3C5E8", - nonce: "8408DFFF3C1A2B1292DC199E46B7D617", - header: "33CCE2EABFF5A79D", - ct: "632A9D131AD4C168A4225D8E1FF755939974A7BEDE" + msg: '481C9E39B1', + key: 'D07CF6CBB7F313BDDE66B727AFD3C5E8', + nonce: '8408DFFF3C1A2B1292DC199E46B7D617', + header: '33CCE2EABFF5A79D', + ct: '632A9D131AD4C168A4225D8E1FF755939974A7BEDE' }, { - msg: "40D0C07DA5E4", - key: "35B6D0580005BBC12B0587124557D2C2", - nonce: "FDB6B06676EEDC5C61D74276E1F8E816", - header: "AEB96EAEBE2970E9", - ct: "071DFE16C675CB0677E536F73AFE6A14B74EE49844DD" + msg: '40D0C07DA5E4', + key: '35B6D0580005BBC12B0587124557D2C2', + nonce: 'FDB6B06676EEDC5C61D74276E1F8E816', + header: 'AEB96EAEBE2970E9', + ct: '071DFE16C675CB0677E536F73AFE6A14B74EE49844DD' }, { - msg: "4DE3B35C3FC039245BD1FB7D", - key: "BD8E6E11475E60B268784C38C62FEB22", - nonce: "6EAC5C93072D8E8513F750935E46DA1B", - header: "D4482D1CA78DCE0F", - ct: "835BB4F15D743E350E728414ABB8644FD6CCB86947C5E10590210A4F" + msg: '4DE3B35C3FC039245BD1FB7D', + key: 'BD8E6E11475E60B268784C38C62FEB22', + nonce: '6EAC5C93072D8E8513F750935E46DA1B', + header: 'D4482D1CA78DCE0F', + ct: '835BB4F15D743E350E728414ABB8644FD6CCB86947C5E10590210A4F' }, { - msg: "8B0A79306C9CE7ED99DAE4F87F8DD61636", - key: "7C77D6E813BED5AC98BAA417477A2E7D", - nonce: "1A8C98DCD73D38393B2BF1569DEEFC19", - header: "65D2017990D62528", - ct: "02083E3979DA014812F59F11D52630DA30137327D10649B0AA6E1C181DB617D7F2" + msg: '8B0A79306C9CE7ED99DAE4F87F8DD61636', + key: '7C77D6E813BED5AC98BAA417477A2E7D', + nonce: '1A8C98DCD73D38393B2BF1569DEEFC19', + header: '65D2017990D62528', + ct: '02083E3979DA014812F59F11D52630DA30137327D10649B0AA6E1C181DB617D7F2' }, { - msg: "1BDA122BCE8A8DBAF1877D962B8592DD2D56", - key: "5FFF20CAFAB119CA2FC73549E20F5B0D", - nonce: "DDE59B97D722156D4D9AFF2BC7559826", - header: "54B9F04E6A09189A", - ct: "2EC47B2C4954A489AFC7BA4897EDCDAE8CC33B60450599BD02C96382902AEF7F832A" + msg: '1BDA122BCE8A8DBAF1877D962B8592DD2D56', + key: '5FFF20CAFAB119CA2FC73549E20F5B0D', + nonce: 'DDE59B97D722156D4D9AFF2BC7559826', + header: '54B9F04E6A09189A', + ct: '2EC47B2C4954A489AFC7BA4897EDCDAE8CC33B60450599BD02C96382902AEF7F832A' }, { - msg: "6CF36720872B8513F6EAB1A8A44438D5EF11", - key: "A4A4782BCFFD3EC5E7EF6D8C34A56123", - nonce: "B781FCF2F75FA5A8DE97A9CA48E522EC", - header: "899A175897561D7E", - ct: "0DE18FD0FDD91E7AF19F1D8EE8733938B1E8E7F6D2231618102FDB7FE55FF1991700" + msg: '6CF36720872B8513F6EAB1A8A44438D5EF11', + key: 'A4A4782BCFFD3EC5E7EF6D8C34A56123', + nonce: 'B781FCF2F75FA5A8DE97A9CA48E522EC', + header: '899A175897561D7E', + ct: '0DE18FD0FDD91E7AF19F1D8EE8733938B1E8E7F6D2231618102FDB7FE55FF1991700' }, { - msg: "CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7", - key: "8395FCF1E95BEBD697BD010BC766AAC3", - nonce: "22E7ADD93CFC6393C57EC0B3C17D6B44", - header: "126735FCC320D25A", - ct: "CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E" + msg: 'CA40D7446E545FFAED3BD12A740A659FFBBB3CEAB7', + key: '8395FCF1E95BEBD697BD010BC766AAC3', + nonce: '22E7ADD93CFC6393C57EC0B3C17D6B44', + header: '126735FCC320D25A', + ct: 'CB8920F87A6C75CFF39627B56E3ED197C552D295A7CFC46AFC253B4652B1AF3795B124AB6E' } ]; @@ -133,8 +133,8 @@ module.exports = () => describe('Symmetric AES-EAX', function() { const disableNative = () => { enableNative(); // stubbed functions return undefined - getWebCryptoStub = sinonSandbox.stub(util, "getWebCrypto"); - getNodeCryptoStub = sinonSandbox.stub(util, "getNodeCrypto"); + getWebCryptoStub = sinonSandbox.stub(util, 'getWebCrypto'); + getNodeCryptoStub = sinonSandbox.stub(util, 'getNodeCrypto'); }; const enableNative = () => { getWebCryptoStub && getWebCryptoStub.restore(); diff --git a/test/crypto/ecdh.js b/test/crypto/ecdh.js index 82444cea..af06c374 100644 --- a/test/crypto/ecdh.js +++ b/test/crypto/ecdh.js @@ -206,8 +206,8 @@ module.exports = () => describe('ECDH key exchange @lightweight', function () { const disableNative = () => { enableNative(); // stubbed functions return undefined - getWebCryptoStub = sinonSandbox.stub(util, "getWebCrypto"); - getNodeCryptoStub = sinonSandbox.stub(util, "getNodeCrypto"); + getWebCryptoStub = sinonSandbox.stub(util, 'getWebCrypto'); + getNodeCryptoStub = sinonSandbox.stub(util, 'getNodeCrypto'); }; const enableNative = () => { getWebCryptoStub && getWebCryptoStub.restore(); diff --git a/test/crypto/elliptic.js b/test/crypto/elliptic.js index e6b16cae..c9cd4072 100644 --- a/test/crypto/elliptic.js +++ b/test/crypto/elliptic.js @@ -115,8 +115,8 @@ module.exports = () => describe('Elliptic Curve Cryptography @lightweight', func const disableNative = () => { enableNative(); // stubbed functions return undefined - getWebCryptoStub = sinonSandbox.stub(util, "getWebCrypto"); - getNodeCryptoStub = sinonSandbox.stub(util, "getNodeCrypto"); + getWebCryptoStub = sinonSandbox.stub(util, 'getWebCrypto'); + getNodeCryptoStub = sinonSandbox.stub(util, 'getNodeCrypto'); }; const enableNative = () => { getWebCryptoStub && getWebCryptoStub.restore(); @@ -169,7 +169,7 @@ module.exports = () => describe('Elliptic Curve Cryptography @lightweight', func 'invalid oid', 8, [], [], [], [] )).to.be.rejectedWith(Error, /Not valid curve/), expect(verify_signature( - "\x00", 8, [], [], [], [] + '\x00', 8, [], [], [], [] )).to.be.rejectedWith(Error, /Not valid curve/) ]); }); diff --git a/test/crypto/gcm.js b/test/crypto/gcm.js index 474a5229..57aa83f4 100644 --- a/test/crypto/gcm.js +++ b/test/crypto/gcm.js @@ -25,8 +25,8 @@ module.exports = () => describe('Symmetric AES-GCM (experimental)', function() { const disableNative = () => { enableNative(); // stubbed functions return undefined - getWebCryptoStub = sinonSandbox.stub(util, "getWebCrypto"); - getNodeCryptoStub = sinonSandbox.stub(util, "getNodeCrypto"); + getWebCryptoStub = sinonSandbox.stub(util, 'getWebCrypto'); + getNodeCryptoStub = sinonSandbox.stub(util, 'getNodeCrypto'); }; const enableNative = () => { getWebCryptoStub && getWebCryptoStub.restore(); @@ -73,14 +73,14 @@ module.exports = () => describe('Symmetric AES-GCM (experimental)', function() { } describe('Symmetric AES-GCM (native)', function() { - testAESGCM("12345678901234567890123456789012345678901234567890", true, true); + testAESGCM('12345678901234567890123456789012345678901234567890', true, true); }); describe('Symmetric AES-GCM (asm.js fallback)', function() { - testAESGCM("12345678901234567890123456789012345678901234567890", false, false); + testAESGCM('12345678901234567890123456789012345678901234567890', false, false); }); describe('Symmetric AES-GCM (native encrypt, asm.js decrypt)', function() { - testAESGCM("12345678901234567890123456789012345678901234567890", true, false); + testAESGCM('12345678901234567890123456789012345678901234567890', true, false); }); }); diff --git a/test/crypto/hash/ripemd.js b/test/crypto/hash/ripemd.js index c301e025..475618fb 100644 --- a/test/crypto/hash/ripemd.js +++ b/test/crypto/hash/ripemd.js @@ -5,7 +5,7 @@ const chai = require('chai'); const { expect } = chai; -module.exports = () => it("RIPE-MD 160 bits with test vectors from https://homes.esat.kuleuven.be/~bosselae/ripemd160.html", async function() { +module.exports = () => it('RIPE-MD 160 bits with test vectors from https://homes.esat.kuleuven.be/~bosselae/ripemd160.html', async function() { expect(util.uint8ArrayToHex(await rmdString(util.stringToUint8Array('')), 'RMDstring("") = 9c1185a5c5e9fc54612808977ee8f548b2258d31')).to.equal('9c1185a5c5e9fc54612808977ee8f548b2258d31'); expect(util.uint8ArrayToHex(await rmdString(util.stringToUint8Array('a')), 'RMDstring("a") = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe')).to.equal('0bdc9d2d256b3ee9daae347be6f4dc835a467ffe'); expect(util.uint8ArrayToHex(await rmdString(util.stringToUint8Array('abc')), 'RMDstring("abc") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc')).to.equal('8eb208f7e05d987a9b044a8e98c6b087f15a0bfc'); diff --git a/test/crypto/rsa.js b/test/crypto/rsa.js index 0de65b9c..4f4a5d55 100644 --- a/test/crypto/rsa.js +++ b/test/crypto/rsa.js @@ -28,8 +28,8 @@ module.exports = () => describe('basic RSA cryptography', function () { const disableNative = () => { enableNative(); // stubbed functions return undefined - getWebCryptoStub = sinonSandbox.stub(util, "getWebCrypto"); - getNodeCryptoStub = sinonSandbox.stub(util, "getNodeCrypto"); + getWebCryptoStub = sinonSandbox.stub(util, 'getWebCrypto'); + getNodeCryptoStub = sinonSandbox.stub(util, 'getNodeCrypto'); }; const enableNative = () => { getWebCryptoStub && getWebCryptoStub.restore(); diff --git a/test/general/armor.js b/test/general/armor.js index 557e17b2..a20a9ebb 100644 --- a/test/general/armor.js +++ b/test/general/armor.js @@ -4,7 +4,7 @@ const chai = require('chai'); const { expect } = chai; -module.exports = () => describe("ASCII armor", function() { +module.exports = () => describe('ASCII armor', function() { function getArmor(headers, signatureHeaders) { return ['-----BEGIN PGP SIGNED MESSAGE-----'] diff --git a/test/general/brainpool.js b/test/general/brainpool.js index cdc2a106..4468fcab 100644 --- a/test/general/brainpool.js +++ b/test/general/brainpool.js @@ -285,8 +285,8 @@ function omnibus() { const testData = input.createSomeMessage(); const testData2 = input.createSomeMessage(); - const { privateKey: hi, publicKey: pubHi } = await openpgp.generateKey({ userIDs: { name: "Hi", email: "hi@hel.lo" }, curve: "brainpoolP256r1", format: 'object' }); - const { privateKey: bye, publicKey: pubBye } = await openpgp.generateKey({ userIDs: { name: "Bye", email: "bye@good.bye" }, curve: "brainpoolP256r1", format: 'object' }); + const { privateKey: hi, publicKey: pubHi } = await openpgp.generateKey({ userIDs: { name: 'Hi', email: 'hi@hel.lo' }, curve: 'brainpoolP256r1', format: 'object' }); + const { privateKey: bye, publicKey: pubBye } = await openpgp.generateKey({ userIDs: { name: 'Bye', email: 'bye@good.bye' }, curve: 'brainpoolP256r1', format: 'object' }); const cleartextMessage = await openpgp.sign({ message: await openpgp.createCleartextMessage({ text: testData }), signingKeys: hi }); await openpgp.verify({ diff --git a/test/general/config.js b/test/general/config.js index b65b30dc..9d487614 100644 --- a/test/general/config.js +++ b/test/general/config.js @@ -4,7 +4,7 @@ const openpgp = typeof window !== 'undefined' && window.openpgp ? window.openpgp module.exports = () => describe('Custom configuration', function() { it('openpgp.readMessage', async function() { - const armoredMessage = await openpgp.encrypt({ message: await openpgp.createMessage({ text:"hello world" }), passwords: 'password' }); + const armoredMessage = await openpgp.encrypt({ message: await openpgp.createMessage({ text:'hello world' }), passwords: 'password' }); const message = await openpgp.readMessage({ armoredMessage }); message.packets.findPacket(openpgp.SymEncryptedSessionKeyPacket.tag).version = 1; // unsupported SKESK version @@ -201,7 +201,7 @@ vAFM3jjrAQDgJPXsv8PqCrLGDuMa/2r6SgzYd03aw/xt1WM6hgUvhQD+J54Z try { const passwords = ['12345678']; - const message = await openpgp.createMessage({ text: "test" }); + const message = await openpgp.createMessage({ text: 'test' }); const armored = await openpgp.encrypt({ message, passwords }); const encrypted = await openpgp.readMessage({ armoredMessage: armored }); @@ -223,7 +223,7 @@ vAFM3jjrAQDgJPXsv8PqCrLGDuMa/2r6SgzYd03aw/xt1WM6hgUvhQD+J54Z expect(encData2.constructor.tag).to.equal(openpgp.enums.packet.aeadEncryptedData); const { packets: [compressed] } = await encrypted2.decrypt(null, passwords, null, encrypted2.fromStream, openpgp.config); expect(compressed.constructor.tag).to.equal(openpgp.enums.packet.compressedData); - expect(compressed.algorithm).to.equal("zip"); + expect(compressed.algorithm).to.equal('zip'); const userIDs = { name: 'Test User', email: 'text2@example.com' }; const { privateKey: key } = await openpgp.generateKey({ userIDs, format: 'object' }); @@ -276,7 +276,7 @@ vAFM3jjrAQDgJPXsv8PqCrLGDuMa/2r6SgzYd03aw/xt1WM6hgUvhQD+J54Z const userIDs = { name: 'Test User', email: 'text2@example.com' }; const { privateKey: key } = await openpgp.generateKey({ userIDs, format: 'object' }); - const message = await openpgp.createMessage({ text: "test" }); + const message = await openpgp.createMessage({ text: 'test' }); const opt = { message, signingKeys: key, @@ -286,7 +286,7 @@ vAFM3jjrAQDgJPXsv8PqCrLGDuMa/2r6SgzYd03aw/xt1WM6hgUvhQD+J54Z opt.detached = true; await expect(openpgp.sign(opt)).to.be.rejectedWith(/Insecure hash algorithm/); - const clearText = await openpgp.createCleartextMessage({ text: "test" }); + const clearText = await openpgp.createCleartextMessage({ text: 'test' }); const opt2 = { message: clearText, signingKeys: key, @@ -305,7 +305,7 @@ vAFM3jjrAQDgJPXsv8PqCrLGDuMa/2r6SgzYd03aw/xt1WM6hgUvhQD+J54Z const config = { rejectMessageHashAlgorithms: new Set([openpgp.enums.hash.sha256, openpgp.enums.hash.sha512]) }; - const message = await openpgp.createMessage({ text: "test" }); + const message = await openpgp.createMessage({ text: 'test' }); const signed = await openpgp.sign({ message, signingKeys: key }); const opt = { message: await openpgp.readMessage({ armoredMessage: signed }), @@ -324,7 +324,7 @@ vAFM3jjrAQDgJPXsv8PqCrLGDuMa/2r6SgzYd03aw/xt1WM6hgUvhQD+J54Z const { signatures: [sig2] } = await openpgp.verify(opt2); await expect(sig2.error).to.match(/Insecure message hash algorithm/); - const cleartext = await openpgp.createCleartextMessage({ text: "test" }); + const cleartext = await openpgp.createCleartextMessage({ text: 'test' }); const signedCleartext = await openpgp.sign({ message: cleartext, signingKeys: key }); const opt3 = { message: await openpgp.readCleartextMessage({ cleartextMessage: signedCleartext }), diff --git a/test/general/ecc_nist.js b/test/general/ecc_nist.js index b1575f55..0090e9f2 100644 --- a/test/general/ecc_nist.js +++ b/test/general/ecc_nist.js @@ -13,8 +13,8 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38 const testData = input.createSomeMessage(); const testData2 = input.createSomeMessage(); - const { privateKey: hi, publicKey: pubHi } = await openpgp.generateKey({ userIDs: { name: "Hi", email: "hi@hel.lo" }, curve: "p256", format: 'object' }); - const { privateKey: bye, publicKey: pubBye } = await openpgp.generateKey({ userIDs: { name: "Bye", email: "bye@good.bye" }, curve: "p256", format: 'object' }); + const { privateKey: hi, publicKey: pubHi } = await openpgp.generateKey({ userIDs: { name: 'Hi', email: 'hi@hel.lo' }, curve: 'p256', format: 'object' }); + const { privateKey: bye, publicKey: pubBye } = await openpgp.generateKey({ userIDs: { name: 'Bye', email: 'bye@good.bye' }, curve: 'p256', format: 'object' }); const cleartextMessage = await openpgp.sign({ message: await openpgp.createCleartextMessage({ text: testData }), signingKeys: hi }); await openpgp.verify({ @@ -50,7 +50,7 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38 it('Sign message', async function () { const testData = input.createSomeMessage(); - const options = { userIDs: { name: "Hi", email: "hi@hel.lo" }, curve: "p256", format: 'object' }; + const options = { userIDs: { name: 'Hi', email: 'hi@hel.lo' }, curve: 'p256', format: 'object' }; const { privateKey, publicKey } = await openpgp.generateKey(options); const signature = await openpgp.sign({ message: await openpgp.createCleartextMessage({ text: testData }), signingKeys: privateKey }); const msg = await openpgp.readCleartextMessage({ cleartextMessage: signature }); @@ -60,9 +60,9 @@ module.exports = () => describe('Elliptic Curve Cryptography for NIST P-256,P-38 it('Encrypt and sign message', async function () { const testData = input.createSomeMessage(); - let options = { userIDs: { name: "Hi", email: "hi@hel.lo" }, curve: "p256", format: 'object' }; + let options = { userIDs: { name: 'Hi', email: 'hi@hel.lo' }, curve: 'p256', format: 'object' }; const firstKey = await openpgp.generateKey(options); - options = { userIDs: { name: "Bye", email: "bye@good.bye" }, curve: "p256", format: 'object' }; + options = { userIDs: { name: 'Bye', email: 'bye@good.bye' }, curve: 'p256', format: 'object' }; const secondKey = await openpgp.generateKey(options); const encrypted = await openpgp.encrypt({ message: await openpgp.createMessage({ text: testData }), diff --git a/test/general/ecc_secp256k1.js b/test/general/ecc_secp256k1.js index 7a67af66..db585d1e 100644 --- a/test/general/ecc_secp256k1.js +++ b/test/general/ecc_secp256k1.js @@ -224,9 +224,9 @@ module.exports = () => describe('Elliptic Curve Cryptography for secp256k1 curve }); it('Generate key', function () { const options = { - userIDs: { name: "Hamlet (secp256k1)", email: "hamlet@example.net" }, - curve: "secp256k1", - passphrase: "ophelia", + userIDs: { name: 'Hamlet (secp256k1)', email: 'hamlet@example.net' }, + curve: 'secp256k1', + passphrase: 'ophelia', format: 'object' }; return openpgp.generateKey(options).then(function ({ privateKey, publicKey }) { diff --git a/test/general/key.js b/test/general/key.js index 6fdeb12e..4126148d 100644 --- a/test/general/key.js +++ b/test/general/key.js @@ -2558,7 +2558,7 @@ function versionSpecificTests() { it('Reformat and encrypt key with no subkey', async function() { const userID = { name: 'test', email: 'a@b.com' }; const key = await openpgp.readKey({ armoredKey: key_without_subkey }); - const opt = { privateKey: key, userIDs: [userID], passphrase: "test", format: 'object' }; + const opt = { privateKey: key, userIDs: [userID], passphrase: 'test', format: 'object' }; return openpgp.reformatKey(opt).then(function({ privateKey: newKey }) { expect(newKey.users.length).to.equal(1); expect(newKey.users[0].userID.userID).to.equal('test '); @@ -2939,27 +2939,27 @@ module.exports = () => describe('Key', function() { await expect(key.validate()).to.not.be.rejected; }); - it("validate() - throw if all-gnu-dummy key", async function() { + it('validate() - throw if all-gnu-dummy key', async function() { const key = await openpgp.readKey({ armoredKey: 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() { + it('validate() - gnu-dummy primary key with signing subkey', async function() { const key = await openpgp.readKey({ armoredKey: gnuDummyKeySigningSubkey }); await expect(key.validate()).to.not.be.rejected; }); - it("validate() - gnu-dummy primary key with encryption subkey", async function() { + it('validate() - gnu-dummy primary key with encryption subkey', async function() { const key = await openpgp.readKey({ armoredKey: dsaGnuDummyKeyWithElGamalSubkey }); await expect(key.validate()).to.not.be.rejected; }); - it("validate() - curve ed25519 (eddsa) cannot be used for ecdsa", async function() { + it('validate() - curve ed25519 (eddsa) cannot be used for ecdsa', async function() { const key = await openpgp.readKey({ armoredKey: eddsaKeyAsEcdsa }); await expect(key.validate()).to.be.rejectedWith('Key is invalid'); }); - it("isDecrypted() - should reflect whether all (sub)keys are encrypted", async function() { + it('isDecrypted() - should reflect whether all (sub)keys are encrypted', async function() { const passphrase = '12345678'; const { privateKey: key } = await openpgp.generateKey({ userIDs: {}, curve: 'ed25519', passphrase, format: 'object' }); expect(key.isDecrypted()).to.be.false; @@ -2967,14 +2967,14 @@ module.exports = () => describe('Key', function() { expect(key.isDecrypted()).to.be.true; }); - it("isDecrypted() - gnu-dummy primary key", async function() { + it('isDecrypted() - gnu-dummy primary key', async function() { const key = await openpgp.readKey({ armoredKey: gnuDummyKeySigningSubkey }); expect(key.isDecrypted()).to.be.true; const encryptedKey = await openpgp.encryptKey({ privateKey: key, passphrase: '12345678' }); expect(encryptedKey.isDecrypted()).to.be.false; }); - it("isDecrypted() - all-gnu-dummy key", async function() { + it('isDecrypted() - all-gnu-dummy key', async function() { const key = await openpgp.readKey({ armoredKey: gnuDummyKey }); expect(key.isDecrypted()).to.be.false; }); @@ -3606,7 +3606,7 @@ VYGdb3eNlV8CfoEC const opt = { type: 'rsa', rsaBits, userIDs: [userID], format: 'object', subkeys: [] }; const { privateKey: key } = await openpgp.generateKey(opt); expect(key.subkeys).to.have.length(0); - key.getAlgorithmInfo().algorithm = "rsaSign"; + key.getAlgorithmInfo().algorithm = 'rsaSign'; const newKey = await key.addSubkey(); expect(newKey.subkeys[0].getAlgorithmInfo().algorithm).to.equal('rsaEncryptSign'); }); @@ -3854,13 +3854,13 @@ VYGdb3eNlV8CfoEC }); it('Subkey.verify returns the latest valid signature', async function () { - const { privateKey: encryptionKey } = await openpgp.generateKey({ userIDs: { name: "purple" }, format: 'object' }); + const { privateKey: encryptionKey } = await openpgp.generateKey({ userIDs: { name: 'purple' }, format: 'object' }); const encryptionKeySignature = await encryptionKey.getSubkeys()[0].verify(); expect(encryptionKeySignature instanceof openpgp.SignaturePacket).to.be.true; expect(encryptionKeySignature.keyFlags[0] & openpgp.enums.keyFlags.encryptCommunication).to.be.equals(openpgp.enums.keyFlags.encryptCommunication); expect(encryptionKeySignature.keyFlags[0] & openpgp.enums.keyFlags.encryptStorage).to.be.equals(openpgp.enums.keyFlags.encryptStorage); - const { privateKey: signingKey } = await openpgp.generateKey({ userIDs: { name: "purple" }, format: 'object', subkeys: [{ sign: true }] }); + const { privateKey: signingKey } = await openpgp.generateKey({ userIDs: { name: 'purple' }, format: 'object', subkeys: [{ sign: true }] }); const signingKeySignature = await signingKey.getSubkeys()[0].verify(); expect(signingKeySignature instanceof openpgp.SignaturePacket).to.be.true; expect(signingKeySignature.keyFlags[0] & openpgp.enums.keyFlags.signData).to.be.equals(openpgp.enums.keyFlags.signData); diff --git a/test/general/openpgp.js b/test/general/openpgp.js index ef146e7e..8203c0fe 100644 --- a/test/general/openpgp.js +++ b/test/general/openpgp.js @@ -2272,7 +2272,7 @@ aOU= try { openpgp.config.rejectPublicKeyAlgorithms = new Set(); - const plaintext = "  \t┍ͤ޵၂༫዇◧˘˻ᙑ᎚⏴ំந⛑nٓኵΉⅶ⋋ŵ⋲΂ͽᣏ₅ᄶɼ┋⌔û᬴Ƚᔡᧅ≃ṱἆ⃷݂૿ӌ᰹෇ٹჵ⛇໶⛌  \t\n한국어/조선말"; + const plaintext = '  \t┍ͤ޵၂༫዇◧˘˻ᙑ᎚⏴ំந⛑nٓኵΉⅶ⋋ŵ⋲΂ͽᣏ₅ᄶɼ┋⌔û᬴Ƚᔡᧅ≃ṱἆ⃷݂૿ӌ᰹෇ٹჵ⛇໶⛌  \t\n한국어/조선말'; const privKeyDE = await openpgp.decryptKey({ privateKey: await openpgp.readKey({ armoredKey: priv_key_de }), @@ -2500,7 +2500,7 @@ aOU= badSumEncrypted = data.replace(/\n=[a-zA-Z0-9/+]{4}/, '\n=bbbb'); } if (badSumEncrypted === data) { - throw new Error("Was not able to successfully modify checksum"); + throw new Error('Was not able to successfully modify checksum'); } const badBodyEncrypted = data.replace(/\n=([a-zA-Z0-9/+]{4})/, 'aaa\n=$1'); await stream.loadStreamsPonyfill(); @@ -2602,7 +2602,7 @@ aOU= }); }); - describe("3DES decrypt", function() { + describe('3DES decrypt', function() { const pgp_msg = [ '-----BEGIN PGP MESSAGE-----', 'Version: GnuPG/MacGPG2 v2.0.19 (Darwin)', @@ -3599,14 +3599,14 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ== describe('Specific encryption/signing key testing', async function () { const encryptionKeyIDs = [ - keyIDType.fromID("87EAE0977B2185EA"), - keyIDType.fromID("F94F9B34AF93FA14"), - keyIDType.fromID("08F7D4C7C59545C0") + keyIDType.fromID('87EAE0977B2185EA'), + keyIDType.fromID('F94F9B34AF93FA14'), + keyIDType.fromID('08F7D4C7C59545C0') ]; const signingKeyIDs = [ - keyIDType.fromID("663277AF60400638"), - keyIDType.fromID("BBE14491E6EE6366"), - keyIDType.fromID("3E0F20F1A71D6DFD") + keyIDType.fromID('663277AF60400638'), + keyIDType.fromID('BBE14491E6EE6366'), + keyIDType.fromID('3E0F20F1A71D6DFD') ]; const getPrimaryKey = async () => openpgp.readKey({ armoredKey: multipleEncryptionAndSigningSubkeys @@ -3619,7 +3619,7 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ== for (let i = 0; i < encryptionKeyIDs.length; i++) { m = await openpgp.readMessage({ armoredMessage: await openpgp.encrypt({ - message: await openpgp.createMessage({ text: "Hello World\n" }), + message: await openpgp.createMessage({ text: 'Hello World\n' }), encryptionKeys: primaryKey, encryptionKeyIDs: [encryptionKeyIDs[i]] }) @@ -3637,7 +3637,7 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ== for (let i = 0; i < signingKeyIDs.length; i++) { s = await openpgp.readSignature({ armoredSignature: await openpgp.sign({ - message: await openpgp.createMessage({ text: "Hello World\n" }), + message: await openpgp.createMessage({ text: 'Hello World\n' }), signingKeys: primaryKey, signingKeyIDs: [signingKeyIDs[i]], detached: true @@ -3651,7 +3651,7 @@ bsZgJWVlAa5eil6J9ePX2xbo1vVAkLQdzE9+1jL+l7PRIZuVBQ== it('Encrypt and sign with specific encryption/signing key ids', async function () { const primaryKey = await getPrimaryKey(); - const plaintextMessage = await openpgp.createMessage({ text: "Hello World\n" }); + const plaintextMessage = await openpgp.createMessage({ text: 'Hello World\n' }); const checkEncryptedPackets = (encryptionKeyIDs, pKESKList) => { pKESKList.forEach(({ publicKeyID }, i) => { diff --git a/test/general/packet.js b/test/general/packet.js index dfc64e13..e9458e27 100644 --- a/test/general/packet.js +++ b/test/general/packet.js @@ -29,7 +29,7 @@ function stringify(array) { return result.join(''); } -module.exports = () => describe("Packet", function() { +module.exports = () => describe('Packet', function() { const allAllowedPackets = util.constructAllowedPackets([...Object.values(openpgp).filter(packetClass => !!packetClass.tag)]); const armored_key = @@ -531,10 +531,10 @@ module.exports = () => describe("Packet", function() { openpgp.config.aeadChunkSizeByte = 14; openpgp.config.s2kIterationCountByte = 0x90; - const salt = util.hexToUint8Array(`cd5a9f70fbe0bc65`); - const sessionKey = util.hexToUint8Array(`86 f1 ef b8 69 52 32 9f 24 ac d3 bf d0 e5 34 6d`.replace(/\s+/g, '')); - const sessionIV = util.hexToUint8Array(`bc 66 9e 34 e5 00 dc ae dc 5b 32 aa 2d ab 02 35`.replace(/\s+/g, '')); - const dataIV = util.hexToUint8Array(`b7 32 37 9f 73 c4 92 8d e2 5f ac fe 65 17 ec 10`.replace(/\s+/g, '')); + const salt = util.hexToUint8Array('cd5a9f70fbe0bc65'); + const sessionKey = util.hexToUint8Array('86 f1 ef b8 69 52 32 9f 24 ac d3 bf d0 e5 34 6d'.replace(/\s+/g, '')); + const sessionIV = util.hexToUint8Array('bc 66 9e 34 e5 00 dc ae dc 5b 32 aa 2d ab 02 35'.replace(/\s+/g, '')); + const dataIV = util.hexToUint8Array('b7 32 37 9f 73 c4 92 8d e2 5f ac fe 65 17 ec 10'.replace(/\s+/g, '')); const randomBytesStub = stub(nodeCrypto, 'randomBytes'); randomBytesStub.onCall(0).returns(salt); @@ -608,10 +608,10 @@ module.exports = () => describe("Packet", function() { openpgp.config.aeadChunkSizeByte = 14; openpgp.config.s2kIterationCountByte = 0x90; - const salt = util.hexToUint8Array(`9f0b7da3e5ea6477`); - const sessionKey = util.hexToUint8Array(`d1 f0 1b a3 0e 13 0a a7 d2 58 2c 16 e0 50 ae 44`.replace(/\s+/g, '')); - const sessionIV = util.hexToUint8Array(`99 e3 26 e5 40 0a 90 93 6c ef b4 e8 eb a0 8c`.replace(/\s+/g, '')); - const dataIV = util.hexToUint8Array(`5e d2 bc 1e 47 0a be 8f 1d 64 4c 7a 6c 8a 56`.replace(/\s+/g, '')); + const salt = util.hexToUint8Array('9f0b7da3e5ea6477'); + const sessionKey = util.hexToUint8Array('d1 f0 1b a3 0e 13 0a a7 d2 58 2c 16 e0 50 ae 44'.replace(/\s+/g, '')); + const sessionIV = util.hexToUint8Array('99 e3 26 e5 40 0a 90 93 6c ef b4 e8 eb a0 8c'.replace(/\s+/g, '')); + const dataIV = util.hexToUint8Array('5e d2 bc 1e 47 0a be 8f 1d 64 4c 7a 6c 8a 56'.replace(/\s+/g, '')); const randomBytesStub = stub(nodeCrypto, 'randomBytes'); randomBytesStub.onCall(0).returns(salt); @@ -840,7 +840,7 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+ const secretKeyPacket = new openpgp.SecretKeyPacket(); secretKeyPacket.privateParams = privateParams; secretKeyPacket.publicParams = publicParams; - secretKeyPacket.algorithm = "rsaSign"; + secretKeyPacket.algorithm = 'rsaSign'; secretKeyPacket.isEncrypted = false; await secretKeyPacket.encrypt('hello', { ...openpgp.config, aeadProtect: true }); expect(secretKeyPacket.s2kUsage).to.equal(253); @@ -864,7 +864,7 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+ packet.privateParams = { key: new Uint8Array([1, 2, 3]) }; packet.publicParams = { pubKey: new Uint8Array([4, 5, 6]) }; - packet.algorithm = "rsaSign"; + packet.algorithm = 'rsaSign'; packet.isEncrypted = false; packet.s2kUsage = 0; @@ -896,7 +896,7 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+ const secretKeyPacket = new openpgp.SecretKeyPacket(); secretKeyPacket.privateParams = privateParams; secretKeyPacket.publicParams = publicParams; - secretKeyPacket.algorithm = "rsaSign"; + secretKeyPacket.algorithm = 'rsaSign'; secretKeyPacket.isEncrypted = false; await secretKeyPacket.encrypt('hello', { ...openpgp.config, aeadProtect: false }); expect(secretKeyPacket.s2kUsage).to.equal(254); @@ -917,7 +917,7 @@ V+HOQJQxXJkVRYa3QrFUehiMzTeqqMdgC6ZqJy7+ key.publicParams = publicParams; key.privateParams = privateParams; - key.algorithm = "rsaSign"; + key.algorithm = 'rsaSign'; await key.computeFingerprintAndKeyID(); const signed = new openpgp.PacketList(); diff --git a/test/general/signature.js b/test/general/signature.js index 1cb52989..1c6cdfb3 100644 --- a/test/general/signature.js +++ b/test/general/signature.js @@ -11,7 +11,7 @@ chai.use(require('chai-as-promised')); const expect = chai.expect; -module.exports = () => describe("Signature", function() { +module.exports = () => describe('Signature', function() { const priv_key_arm1 = ['-----BEGIN PGP PRIVATE KEY BLOCK-----', 'Version: GnuPG v1.4.11 (GNU/Linux)', @@ -39,7 +39,7 @@ module.exports = () => describe("Signature", function() { 'AgAJBQJREZ6zAhsMAAoJEBEnlAPLFp74QbMAn3V4857xwnO9/+vzIVnL93W3k0/8', 'AKC8omYPPomN1E/UJFfXdLDIMi5LoA==', '=LSrW', - '-----END PGP PRIVATE KEY BLOCK-----'].join("\n"); + '-----END PGP PRIVATE KEY BLOCK-----'].join('\n'); const pub_key_arm1 = ['-----BEGIN PGP PUBLIC KEY BLOCK-----', @@ -58,7 +58,7 @@ module.exports = () => describe("Signature", function() { 'HgECF4AACgkQikDlZK/UvLSspgCfcNaOpTg1W2ucR1JwBbBGvaERfuMAnRgt3/rs', 'EplqEakMckCtikEnpxYe', '=b2Ln', - '-----END PGP PUBLIC KEY BLOCK-----'].join("\n"); + '-----END PGP PUBLIC KEY BLOCK-----'].join('\n'); const msg_arm1 = ['-----BEGIN PGP MESSAGE-----', @@ -75,7 +75,7 @@ module.exports = () => describe("Signature", function() { '0Dqnp0yfefrkjQ0nuvubgB6Rv89mHpnvuJfFJRInpg4lrHwLvRwdpN2HDozFHcKK', 'aOU=', '=4iGt', - '-----END PGP MESSAGE-----'].join("\n"); + '-----END PGP MESSAGE-----'].join('\n'); const priv_key_arm2 = ['-----BEGIN PGP PRIVATE KEY BLOCK-----', @@ -693,13 +693,13 @@ hUhMKMuiM3pRwdIyDOItkUWQmjEEw7/XmhgInkXsCw== -----END PGP SIGNATURE----- `; - it("Retrieve the issuer Key ID of a signature", async function () { + it('Retrieve the issuer Key ID of a signature', async function () { const publicKey = await openpgp.readKey({ armoredKey: pub_key_arm2 }); const privateKey = await openpgp.decryptKey({ privateKey: await openpgp.readKey({ armoredKey: priv_key_arm2 }), passphrase: 'hello world' }); - const message = await openpgp.createMessage({ text: "test" }); + const message = await openpgp.createMessage({ text: 'test' }); const armoredSignature = await openpgp.sign({ message, signingKeys: privateKey, diff --git a/test/general/util.js b/test/general/util.js index 2d73f4fc..e9305699 100644 --- a/test/general/util.js +++ b/test/general/util.js @@ -141,7 +141,7 @@ module.exports = () => describe('Util unit tests', function() { }); }); - describe("Misc.", function() { + describe('Misc.', function() { it('util.readNumber should not overflow until full range of uint32', function () { const ints = [2 ** 20, 2 ** 25, 2 ** 30, 2 ** 32 - 1]; for (let i = 0; i < ints.length; i++) { diff --git a/test/general/x25519.js b/test/general/x25519.js index 7db45f35..0dd2c2de 100644 --- a/test/general/x25519.js +++ b/test/general/x25519.js @@ -381,8 +381,8 @@ module.exports = () => (openpgp.config.ci ? describe.skip : describe)('X25519 Cr function omnibus() { it('Omnibus Ed25519/Curve25519 Test', function() { const options = { - userIDs: { name: "Hi", email: "hi@hel.lo" }, - curve: "ed25519", + userIDs: { name: 'Hi', email: 'hi@hel.lo' }, + curve: 'ed25519', format: 'object' }; return openpgp.generateKey(options).then(async function({ privateKey, publicKey }) { @@ -409,8 +409,8 @@ function omnibus() { await user.verifyCertificate(certificate, [hi.toPublic()], undefined, openpgp.config); const options = { - userIDs: { name: "Bye", email: "bye@good.bye" }, - curve: "curve25519", + userIDs: { name: 'Bye', email: 'bye@good.bye' }, + curve: 'curve25519', format: 'object' }; diff --git a/test/security/message_signature_bypass.js b/test/security/message_signature_bypass.js index 854721f2..395aab96 100644 --- a/test/security/message_signature_bypass.js +++ b/test/security/message_signature_bypass.js @@ -74,7 +74,7 @@ async function getOtherPubKey() { /** * The "standalone" signature signed by the victim. */ -const STANDALONE_PKT = util.hexToUint8Array(`04020108001005025bab730a091055208b2d18ace3ce000059da0800b823eceba1bae016afa584bc67ef931dde167fe683bea58761dac31abaaf223afa4cd41fe609b06f7809f2e01ae8792e08591419e591d652d7580af3b7cdfa27e63dd4838fc7ec2aa485757d6c1c6c33bf305cb8fb7eaa1b47ac00825b08a20606a320e988733294957e03012064b61c74a3d41bfebddd4fdd739ab9e220ae48d32a9edf8ff5aec1e13807fc76cd84b9bba914926a14e6f5aacb0c584fa306b4d11280ff107e6aeee9f68c419c7084dc5504990aa7e31d3e042fa745fdb9ae8207fbc15fc440b5df148252e9c65cccaf3a5d6d6919a5c12912ef41761afde4561ca70696bba37452b32584684fa2d50e4f138e101f13dab6125aa5680bd9658c`); +const STANDALONE_PKT = util.hexToUint8Array('04020108001005025bab730a091055208b2d18ace3ce000059da0800b823eceba1bae016afa584bc67ef931dde167fe683bea58761dac31abaaf223afa4cd41fe609b06f7809f2e01ae8792e08591419e591d652d7580af3b7cdfa27e63dd4838fc7ec2aa485757d6c1c6c33bf305cb8fb7eaa1b47ac00825b08a20606a320e988733294957e03012064b61c74a3d41bfebddd4fdd739ab9e220ae48d32a9edf8ff5aec1e13807fc76cd84b9bba914926a14e6f5aacb0c584fa306b4d11280ff107e6aeee9f68c419c7084dc5504990aa7e31d3e042fa745fdb9ae8207fbc15fc440b5df148252e9c65cccaf3a5d6d6919a5c12912ef41761afde4561ca70696bba37452b32584684fa2d50e4f138e101f13dab6125aa5680bd9658c'); async function fakeSignature() { // read the template and modify the text to // invalidate the signature.