mirror of
https://github.com/gchq/CyberChef.git
synced 2024-11-17 09:28:31 +01:00
Merge pull request #2 from artemisbot/features/add-pgp-kbpgp
Promisified generation of key pair
This commit is contained in:
commit
5a5ce1101b
4 changed files with 152 additions and 40 deletions
141
package-lock.json
generated
141
package-lock.json
generated
|
@ -1065,6 +1065,11 @@
|
||||||
"integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=",
|
"integrity": "sha1-eRQg1/VR7qKJdFOop3ZT+WYG1nw=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"bn": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/bn/-/bn-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-oVOCXmsessLbdyYUmwR6B84KO7M="
|
||||||
|
},
|
||||||
"bn.js": {
|
"bn.js": {
|
||||||
"version": "4.11.8",
|
"version": "4.11.8",
|
||||||
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
"resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
|
||||||
|
@ -1284,6 +1289,11 @@
|
||||||
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=",
|
"integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"bzip-deflate": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/bzip-deflate/-/bzip-deflate-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-sC2wB+83vrzCk4Skssb08PTHlsk="
|
||||||
|
},
|
||||||
"caller-path": {
|
"caller-path": {
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/caller-path/-/caller-path-0.1.0.tgz",
|
||||||
|
@ -2041,8 +2051,7 @@
|
||||||
"deep-equal": {
|
"deep-equal": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.0.1.tgz",
|
||||||
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU=",
|
"integrity": "sha1-9dJgKStmDghO/0zbyfCK0yR0SLU="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"deep-extend": {
|
"deep-extend": {
|
||||||
"version": "0.4.2",
|
"version": "0.4.2",
|
||||||
|
@ -2437,8 +2446,15 @@
|
||||||
"es6-promise": {
|
"es6-promise": {
|
||||||
"version": "4.0.5",
|
"version": "4.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-4.0.5.tgz",
|
||||||
"integrity": "sha1-eILzCt3lskDM+n99eMVIMwlRrkI=",
|
"integrity": "sha1-eILzCt3lskDM+n99eMVIMwlRrkI="
|
||||||
"dev": true
|
},
|
||||||
|
"es6-promisify": {
|
||||||
|
"version": "5.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/es6-promisify/-/es6-promisify-5.0.0.tgz",
|
||||||
|
"integrity": "sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=",
|
||||||
|
"requires": {
|
||||||
|
"es6-promise": "4.0.5"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"es6-set": {
|
"es6-set": {
|
||||||
"version": "0.1.5",
|
"version": "0.1.5",
|
||||||
|
@ -4061,6 +4077,24 @@
|
||||||
"integrity": "sha1-P5E2XKvmC3ftDruiS0VOPgnZWoI=",
|
"integrity": "sha1-P5E2XKvmC3ftDruiS0VOPgnZWoI=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"iced-error": {
|
||||||
|
"version": "0.0.12",
|
||||||
|
"resolved": "https://registry.npmjs.org/iced-error/-/iced-error-0.0.12.tgz",
|
||||||
|
"integrity": "sha1-4KhhRigXzwzpdLE/ymEtOg1dEL4="
|
||||||
|
},
|
||||||
|
"iced-lock": {
|
||||||
|
"version": "1.1.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/iced-lock/-/iced-lock-1.1.0.tgz",
|
||||||
|
"integrity": "sha1-YRbvHKs6zW5rEIk7snumIv0/3nI=",
|
||||||
|
"requires": {
|
||||||
|
"iced-runtime": "1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"iced-runtime": {
|
||||||
|
"version": "1.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/iced-runtime/-/iced-runtime-1.0.3.tgz",
|
||||||
|
"integrity": "sha1-LU9PuZmreqVDCxk8d6f85BGDGc4="
|
||||||
|
},
|
||||||
"iconv-lite": {
|
"iconv-lite": {
|
||||||
"version": "0.4.19",
|
"version": "0.4.19",
|
||||||
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
|
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz",
|
||||||
|
@ -4877,12 +4911,69 @@
|
||||||
"resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-8.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-8.0.4.tgz",
|
||||||
"integrity": "sha1-P3uCOIRPEmtJanVW7J9LUR+V+GE="
|
"integrity": "sha1-P3uCOIRPEmtJanVW7J9LUR+V+GE="
|
||||||
},
|
},
|
||||||
|
"kbpgp": {
|
||||||
|
"version": "2.0.76",
|
||||||
|
"resolved": "https://registry.npmjs.org/kbpgp/-/kbpgp-2.0.76.tgz",
|
||||||
|
"integrity": "sha1-qKtufM8279812BNdfJb/bpSLMAI=",
|
||||||
|
"requires": {
|
||||||
|
"bn": "1.0.1",
|
||||||
|
"bzip-deflate": "1.0.0",
|
||||||
|
"deep-equal": "1.0.1",
|
||||||
|
"iced-error": "0.0.12",
|
||||||
|
"iced-lock": "1.1.0",
|
||||||
|
"iced-runtime": "1.0.3",
|
||||||
|
"keybase-ecurve": "1.0.0",
|
||||||
|
"keybase-nacl": "1.0.10",
|
||||||
|
"minimist": "1.2.0",
|
||||||
|
"pgp-utils": "0.0.34",
|
||||||
|
"purepack": "1.0.4",
|
||||||
|
"triplesec": "3.0.26",
|
||||||
|
"tweetnacl": "0.13.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"minimist": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
|
||||||
|
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ="
|
||||||
|
},
|
||||||
|
"tweetnacl": {
|
||||||
|
"version": "0.13.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.13.3.tgz",
|
||||||
|
"integrity": "sha1-1ii1bzvMPVrnS6nUwacE3vWrS1Y="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"kew": {
|
"kew": {
|
||||||
"version": "0.7.0",
|
"version": "0.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/kew/-/kew-0.7.0.tgz",
|
||||||
"integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=",
|
"integrity": "sha1-edk9LTM2PW/dKXCzNdkUGtWR15s=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"keybase-ecurve": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/keybase-ecurve/-/keybase-ecurve-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-xrxyrdpGA/0xhP7n6ZaU7Y/WmtI=",
|
||||||
|
"requires": {
|
||||||
|
"bn": "1.0.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"keybase-nacl": {
|
||||||
|
"version": "1.0.10",
|
||||||
|
"resolved": "https://registry.npmjs.org/keybase-nacl/-/keybase-nacl-1.0.10.tgz",
|
||||||
|
"integrity": "sha1-OGWDHpSBUWSI33y9mJRn6VDYeos=",
|
||||||
|
"requires": {
|
||||||
|
"iced-runtime": "1.0.3",
|
||||||
|
"tweetnacl": "0.13.3",
|
||||||
|
"uint64be": "1.0.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"tweetnacl": {
|
||||||
|
"version": "0.13.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.13.3.tgz",
|
||||||
|
"integrity": "sha1-1ii1bzvMPVrnS6nUwacE3vWrS1Y="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"kind-of": {
|
"kind-of": {
|
||||||
"version": "3.2.2",
|
"version": "3.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/kind-of/-/kind-of-3.2.2.tgz",
|
||||||
|
@ -5312,6 +5403,14 @@
|
||||||
"moment": "2.18.1"
|
"moment": "2.18.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"more-entropy": {
|
||||||
|
"version": "0.0.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/more-entropy/-/more-entropy-0.0.7.tgz",
|
||||||
|
"integrity": "sha1-Z7/G96hvJvvDeqyD/UbYjGHRCbU=",
|
||||||
|
"requires": {
|
||||||
|
"iced-runtime": "1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ms": {
|
"ms": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||||
|
@ -5840,6 +5939,15 @@
|
||||||
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
|
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"pgp-utils": {
|
||||||
|
"version": "0.0.34",
|
||||||
|
"resolved": "https://registry.npmjs.org/pgp-utils/-/pgp-utils-0.0.34.tgz",
|
||||||
|
"integrity": "sha1-2E9J98GTteC5QV9cxcKmle15DCM=",
|
||||||
|
"requires": {
|
||||||
|
"iced-error": "0.0.12",
|
||||||
|
"iced-runtime": "1.0.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"phantomjs-prebuilt": {
|
"phantomjs-prebuilt": {
|
||||||
"version": "2.1.15",
|
"version": "2.1.15",
|
||||||
"resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.15.tgz",
|
"resolved": "https://registry.npmjs.org/phantomjs-prebuilt/-/phantomjs-prebuilt-2.1.15.tgz",
|
||||||
|
@ -6870,8 +6978,7 @@
|
||||||
"progress": {
|
"progress": {
|
||||||
"version": "1.1.8",
|
"version": "1.1.8",
|
||||||
"resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz",
|
"resolved": "https://registry.npmjs.org/progress/-/progress-1.1.8.tgz",
|
||||||
"integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74=",
|
"integrity": "sha1-4mDHj2Fhzdmw5WzD4Khd4Xx6V74="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"promise": {
|
"promise": {
|
||||||
"version": "7.3.1",
|
"version": "7.3.1",
|
||||||
|
@ -6945,6 +7052,11 @@
|
||||||
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=",
|
"integrity": "sha1-wNWmOycYgArY4esPpSachN1BhF4=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"purepack": {
|
||||||
|
"version": "1.0.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/purepack/-/purepack-1.0.4.tgz",
|
||||||
|
"integrity": "sha1-CGKC/ZOShfWGZLqam7oxzbFlzNI="
|
||||||
|
},
|
||||||
"q": {
|
"q": {
|
||||||
"version": "1.5.0",
|
"version": "1.5.0",
|
||||||
"resolved": "https://registry.npmjs.org/q/-/q-1.5.0.tgz",
|
"resolved": "https://registry.npmjs.org/q/-/q-1.5.0.tgz",
|
||||||
|
@ -8245,6 +8357,18 @@
|
||||||
"integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=",
|
"integrity": "sha1-yy4SAwZ+DI3h9hQJS5/kVwTqYAM=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"triplesec": {
|
||||||
|
"version": "3.0.26",
|
||||||
|
"resolved": "https://registry.npmjs.org/triplesec/-/triplesec-3.0.26.tgz",
|
||||||
|
"integrity": "sha1-3/K7R1ikIzcuc5o5fYmR8Fl9CsE=",
|
||||||
|
"requires": {
|
||||||
|
"iced-error": "0.0.12",
|
||||||
|
"iced-lock": "1.1.0",
|
||||||
|
"iced-runtime": "1.0.3",
|
||||||
|
"more-entropy": "0.0.7",
|
||||||
|
"progress": "1.1.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tryit": {
|
"tryit": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/tryit/-/tryit-1.0.3.tgz",
|
||||||
|
@ -8356,6 +8480,11 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"uint64be": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/uint64be/-/uint64be-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-H3FUIC8qG4rzU4cd2mUb80zpPpU="
|
||||||
|
},
|
||||||
"underscore": {
|
"underscore": {
|
||||||
"version": "1.7.0",
|
"version": "1.7.0",
|
||||||
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
|
"resolved": "https://registry.npmjs.org/underscore/-/underscore-1.7.0.tgz",
|
||||||
|
|
|
@ -74,6 +74,7 @@
|
||||||
"crypto-api": "^0.7.5",
|
"crypto-api": "^0.7.5",
|
||||||
"crypto-js": "^3.1.9-1",
|
"crypto-js": "^3.1.9-1",
|
||||||
"diff": "^3.3.1",
|
"diff": "^3.3.1",
|
||||||
|
"es6-promisify": "^5.0.0",
|
||||||
"escodegen": "^1.9.0",
|
"escodegen": "^1.9.0",
|
||||||
"esmangle": "^1.0.1",
|
"esmangle": "^1.0.1",
|
||||||
"esprima": "^4.0.0",
|
"esprima": "^4.0.0",
|
||||||
|
|
|
@ -3848,6 +3848,7 @@ const OperationConfig = {
|
||||||
},
|
},
|
||||||
"Generate PGP Key Pair": {
|
"Generate PGP Key Pair": {
|
||||||
module: "PGP",
|
module: "PGP",
|
||||||
|
manualBake: true,
|
||||||
description: "",
|
description: "",
|
||||||
inputType: "string",
|
inputType: "string",
|
||||||
outputType: "string",
|
outputType: "string",
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import * as kbpgp from "kbpgp";
|
import * as kbpgp from "kbpgp";
|
||||||
|
import promisify from "es6-promisify";
|
||||||
|
|
||||||
const ECC_SIZES = ["256", "384"];
|
const ECC_SIZES = ["256", "384"];
|
||||||
const RSA_SIZES = ["1024", "2048", "4096"];
|
const RSA_SIZES = ["1024", "2048", "4096"];
|
||||||
|
@ -116,41 +117,21 @@ const PGP = {
|
||||||
expire_in: 86400 * 365 * 2 // eslint-disable-line camelcase
|
expire_in: 86400 * 365 * 2 // eslint-disable-line camelcase
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
return new Promise(async (resolve, reject) => {
|
||||||
return new Promise((resolve, reject) => {
|
try {
|
||||||
kbpgp.KeyManager.generate(keyGenerationOptions, (genErr, unsignedKey) => {
|
const unsignedKey = await promisify(kbpgp.KeyManager.generate)(keyGenerationOptions);
|
||||||
if (genErr) {
|
await promisify(unsignedKey.sign, unsignedKey)({});
|
||||||
return reject(`Error from kbpgp whilst generating key: ${genErr}`);
|
let signedKey = unsignedKey;
|
||||||
}
|
let privateKeyExportOptions = {};
|
||||||
|
if (password) privateKeyExportOptions.passphrase = password;
|
||||||
unsignedKey.sign({}, signErr => {
|
const privateKey = await promisify(signedKey.export_pgp_private, signedKey)(privateKeyExportOptions);
|
||||||
let signedKey = unsignedKey;
|
const publicKey = await promisify(signedKey.export_pgp_public, signedKey)({});
|
||||||
if (signErr) {
|
resolve(privateKey + "\n" + publicKey);
|
||||||
return reject(`Error from kbpgp whilst signing the generated key: ${signErr}`);
|
} catch (err) {
|
||||||
}
|
reject(`Error from kbpgp whilst generating key pair: ${err}`);
|
||||||
|
}
|
||||||
let privateKeyExportOptions = {};
|
|
||||||
if (password) privateKeyExportOptions.passphrase = password;
|
|
||||||
|
|
||||||
signedKey.export_pgp_private(privateKeyExportOptions, (privateExportErr, privateKey) => {
|
|
||||||
if (privateExportErr) {
|
|
||||||
return reject(`Error from kbpgp whilst exporting the private part of the signed key: ${privateExportErr}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
signedKey.export_pgp_public({}, (publicExportErr, publicKey) => {
|
|
||||||
if (publicExportErr) {
|
|
||||||
return reject(`Error from kbpgp whilst exporting the public part of the signed key: ${publicExportErr}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolve(privateKey + "\n" + publicKey);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default PGP;
|
export default PGP;
|
||||||
|
|
Loading…
Reference in a new issue