Fix linting in PGP operations
This commit is contained in:
parent
60c8da7bbb
commit
dcd8f98e8c
@ -23,23 +23,23 @@ const PGP = {
|
|||||||
* @returns {Integer}
|
* @returns {Integer}
|
||||||
*/
|
*/
|
||||||
validateKeySize(keySize, keyType) {
|
validateKeySize(keySize, keyType) {
|
||||||
if (KEY_SIZES.indexOf(keySize) < 0) {
|
if (KEY_SIZES.indexOf(keySize) < 0) {
|
||||||
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(KEY_SIZES)}`;
|
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(KEY_SIZES)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keyType === "ecc") {
|
if (keyType === "ecc") {
|
||||||
if (ECC_SIZES.indexOf(keySize) >= 0) {
|
if (ECC_SIZES.indexOf(keySize) >= 0) {
|
||||||
return parseInt(keySize, 10);
|
return parseInt(keySize, 10);
|
||||||
} else {
|
} else {
|
||||||
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(ECC_SIZES)} for ECC`;
|
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(ECC_SIZES)} for ECC`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (RSA_SIZES.indexOf(keySize) >= 0) {
|
if (RSA_SIZES.indexOf(keySize) >= 0) {
|
||||||
return parseInt(keySize, 10);
|
return parseInt(keySize, 10);
|
||||||
} else {
|
} else {
|
||||||
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(RSA_SIZES)} for RSA`;
|
throw `Invalid key size ${keySize}, must be in ${JSON.stringify(RSA_SIZES)} for RSA`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,13 +48,13 @@ const PGP = {
|
|||||||
* @returns {Integer}
|
* @returns {Integer}
|
||||||
*/
|
*/
|
||||||
getSubkeySize(keySize) {
|
getSubkeySize(keySize) {
|
||||||
return {
|
return {
|
||||||
1024: 1024,
|
1024: 1024,
|
||||||
2048: 1024,
|
2048: 1024,
|
||||||
4096: 2048,
|
4096: 2048,
|
||||||
256: 256,
|
256: 256,
|
||||||
384: 256,
|
384: 256,
|
||||||
}[keySize]
|
}[keySize];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ const PGP = {
|
|||||||
*/
|
*/
|
||||||
validateKeyType(keyType) {
|
validateKeyType(keyType) {
|
||||||
if (KEY_TYPES.indexOf(keyType) >= 0) return keyType.toLowerCase();
|
if (KEY_TYPES.indexOf(keyType) >= 0) return keyType.toLowerCase();
|
||||||
throw `Invalid key type ${keyType}, must be in ${JSON.stringify(KEY_TYPES)}`;
|
throw `Invalid key type ${keyType}, must be in ${JSON.stringify(KEY_TYPES)}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -79,76 +79,76 @@ const PGP = {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
runGenerateKeyPair(input, args) {
|
runGenerateKeyPair(input, args) {
|
||||||
let keyType = args[0],
|
let keyType = args[0],
|
||||||
keySize = args[1],
|
keySize = args[1],
|
||||||
password = args[2],
|
password = args[2],
|
||||||
name = args[3],
|
name = args[3],
|
||||||
email = args[4];
|
email = args[4];
|
||||||
|
|
||||||
keyType = PGP.validateKeyType(keyType);
|
keyType = PGP.validateKeyType(keyType);
|
||||||
keySize = PGP.validateKeySize(keySize, keyType);
|
keySize = PGP.validateKeySize(keySize, keyType);
|
||||||
|
|
||||||
let userIdentifier = "";
|
let userIdentifier = "";
|
||||||
if (name) userIdentifier += name;
|
if (name) userIdentifier += name;
|
||||||
if (email) userIdentifier += ` <${email}>`;
|
if (email) userIdentifier += ` <${email}>`;
|
||||||
|
|
||||||
let flags = kbpgp.const.openpgp.certify_keys;
|
let flags = kbpgp.const.openpgp.certify_keys;
|
||||||
flags = flags | kbpgp.const.openpgp.sign_data;
|
flags = flags | kbpgp.const.openpgp.sign_data;
|
||||||
flags = flags | kbpgp.const.openpgp.auth;
|
flags = flags | kbpgp.const.openpgp.auth;
|
||||||
flags = flags | kbpgp.const.openpgp.encrypt_comm;
|
flags = flags | kbpgp.const.openpgp.encrypt_comm;
|
||||||
flags = flags | kbpgp.const.openpgp.encrypt_storage;
|
flags = flags | kbpgp.const.openpgp.encrypt_storage;
|
||||||
|
|
||||||
let keyGenerationOptions = {
|
let keyGenerationOptions = {
|
||||||
userid: userIdentifier,
|
userid: userIdentifier,
|
||||||
ecc: keyType === "ecc",
|
ecc: keyType === "ecc",
|
||||||
primary: {
|
primary: {
|
||||||
nbits: keySize,
|
nbits: keySize,
|
||||||
flags: flags,
|
flags: flags,
|
||||||
expire_in: 0
|
expire_in: 0 // eslint-disable-line camelcase
|
||||||
},
|
},
|
||||||
subkeys: [{
|
subkeys: [{
|
||||||
nbits: PGP.getSubkeySize(keySize),
|
nbits: PGP.getSubkeySize(keySize),
|
||||||
flags: kbpgp.const.openpgp.sign_data,
|
flags: kbpgp.const.openpgp.sign_data,
|
||||||
expire_in: 86400 * 365 * 8 // 8 years from kbpgp defaults
|
expire_in: 86400 * 365 * 8 // eslint-disable-line camelcase
|
||||||
}, {
|
}, {
|
||||||
nbits: PGP.getSubkeySize(keySize),
|
nbits: PGP.getSubkeySize(keySize),
|
||||||
flags: kbpgp.const.openpgp.encrypt_comm | kbpgp.const.openpgp.encrypt_storage,
|
flags: kbpgp.const.openpgp.encrypt_comm | kbpgp.const.openpgp.encrypt_storage,
|
||||||
expire_in: 86400 * 365 * 2 // 2 years from kbpgp defaults
|
expire_in: 86400 * 365 * 2 // eslint-disable-line camelcase
|
||||||
}],
|
}],
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
kbpgp.KeyManager.generate(keyGenerationOptions, (genErr, unsignedKey) => {
|
kbpgp.KeyManager.generate(keyGenerationOptions, (genErr, unsignedKey) => {
|
||||||
if (genErr) {
|
if (genErr) {
|
||||||
return reject(`Error from kbpgp whilst generating key: ${genErr}`);
|
return reject(`Error from kbpgp whilst generating key: ${genErr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsignedKey.sign({}, signErr => {
|
unsignedKey.sign({}, signErr => {
|
||||||
let signedKey = unsignedKey;
|
let signedKey = unsignedKey;
|
||||||
if (signErr) {
|
if (signErr) {
|
||||||
return reject(`Error from kbpgp whilst signing the generated key: ${signErr}`);
|
return reject(`Error from kbpgp whilst signing the generated key: ${signErr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
let privateKeyExportOptions = {};
|
let privateKeyExportOptions = {};
|
||||||
if (password) privateKeyExportOptions.passphrase = password;
|
if (password) privateKeyExportOptions.passphrase = password;
|
||||||
|
|
||||||
signedKey.export_pgp_private(privateKeyExportOptions, (privateExportErr, privateKey) => {
|
signedKey.export_pgp_private(privateKeyExportOptions, (privateExportErr, privateKey) => {
|
||||||
if (privateExportErr) {
|
if (privateExportErr) {
|
||||||
return reject(`Error from kbpgp whilst exporting the private part of the signed key: ${privateExportErr}`);
|
return reject(`Error from kbpgp whilst exporting the private part of the signed key: ${privateExportErr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
signedKey.export_pgp_public({}, (publicExportErr, publicKey) => {
|
signedKey.export_pgp_public({}, (publicExportErr, publicKey) => {
|
||||||
if (publicExportErr) {
|
if (publicExportErr) {
|
||||||
return reject(`Error from kbpgp whilst exporting the public part of the signed key: ${publicExportErr}`);
|
return reject(`Error from kbpgp whilst exporting the public part of the signed key: ${publicExportErr}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return resolve(privateKey + "\n" + publicKey);
|
return resolve(privateKey + "\n" + publicKey);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
})
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user