Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
setup: function (fromAddr, cb) {
var crypt = autocrypt({storage: memdb({valueEncoding: 'json'})})
openpgp.initWorker({ path: 'openpgp.worker.js' }) // set the relative web worker path
openpgp.config.aead_protect = true // activate fast AES-GCM mode (not yet OpenPGP standard)
openpgp.generateKey({
userIds: [{ name: 'Jon Smith', email: fromAddr }],
numBits: 1096,
passphrase: 'super long and hard to guess'
}
).then((key) => cb(crypt, decode(key.publicKeyArmored), done)
).catch((err) => { throw err })
function done (cb) {
crypt.storage.close(cb)
}
},
decode: decode
userIds: [
{
}
],
curve: 'secp256k1',
passphrase: args.passphrase
}
// create primary key
const primaryKeyPair = await openpgp.generateKey(secOptions)
let primarySk = openpgp.key.readArmored(primaryKeyPair.privateKeyArmored)
.keys[0]
await primarySk.decrypt(args.passphrase)
// create recovery key
const recoveryKeyPair = await openpgp.generateKey(secOptions)
const recoverySk = openpgp.key.readArmored(recoveryKeyPair.privateKeyArmored)
.keys[0]
await recoverySk.decrypt(args.passphrase)
// sign primary key with recovery key
primarySk = await primarySk.signPrimaryUser([recoverySk])
// lock private keys before exporting them
await primarySk.encrypt(args.passphrase)
await recoverySk.encrypt(args.passphrase)
let transmuteDir = path.join(require('os').homedir(), '.transmute/cli-secrets')
// write private keys temporarily to secrets directory
await writeFile(path.join(transmuteDir, 'primary_sk.key'), primarySk.armor())
await writeFile(path.join(transmuteDir, 'recovery_sk.key'), recoverySk.armor())
const NewKeyPair = ( data: INewKeyPair, CallBack ) => {
const userId = {
name: data.nikeName,
email: data.email
}
const option = {
numBits: parseInt ( data.keyLength || '2048' ),
passphrase: data.password,
userIds: userId
}
openpgp.generateKey ( option ).then (( keypair: { publicKeyArmored: string, privateKeyArmored: string }) => {
const ret: keyPair = {
publicKey: keypair.publicKeyArmored,
privateKey: keypair.privateKeyArmored
}
return CallBack( null, ret )
}).catch ( err => {
// ERROR
return CallBack ( err )
})
}
static async keygen (name, email) {
const { privateKeyArmored, publicKeyArmored } = await openpgp.generateKey({
userIds: [
{
name: name,
email: email
}
]
})
keyring.publicKeys.importKey(publicKeyArmored)
keyring.privateKeys.importKey(privateKeyArmored)
// let key = openpgp.key.readArmored(privateKeyArmored).keys[0]
// key.toString = printKey
// We need to manually call this to save the keypair to localstorage
keyring.store()
}
exports.newKeyPair = (emailAddress, nickname, password, CallBack) => {
const userId = {
name: nickname,
email: emailAddress
};
const option = {
passphrase: password,
userIds: [userId],
curve: "ed25519",
aead_protect: true,
aead_protect_version: 4
};
return OpenPgp.generateKey(option).then((keypair) => {
const ret = {
publicKey: keypair.publicKeyArmored,
privateKey: keypair.privateKeyArmored
};
return CallBack(null, ret);
}).catch(err => {
// ERROR
return CallBack(err);
});
};
exports.getImapSmtpHost = function (_email) {
function generateKeysRSA(email = '', passphrase = '', numBits = 2048) {
if (passphrase.length === 0) {
return Promise.reject('Missing private key passcode');
}
const user = {
name: email,
email
};
return openpgp.generateKey({
numBits,
userIds: [user],
passphrase
});
}
export async function generateKey({ name, email = '' }, passphrase) {
const key = await openpgp.generateKey({
userIds: [{ name, email }],
numBits: 4096,
passphrase,
})
return {
name,
email,
privateKeyArmored: applyFelonyBranding(key.privateKeyArmored),
publicKeyArmored: applyFelonyBranding(key.publicKeyArmored),
}
}
function generateKey() {
configOpenPgp();
const startTime = Date.now();
const passphrase = crypto.randomBytes(64).toString();
/*
* Since we use a random passphrase on each start, the user
* isn't important, however it is required by openpgp to generate
* the key.
*/
const keyGenOptions = {
userIds: [PGP_USER],
numBits: RSA_KEYLENGTH,
passphrase,
};
debug('generating keys');
return openpgp.generateKey(keyGenOptions).then(
(key): void | Promise => {
publicKeyAscii = key.publicKeyArmored;
publicKeys = openpgp.key.readArmored(key.publicKeyArmored).keys;
privateKey = openpgp.key.readArmored(key.privateKeyArmored).keys[0];
if (!privateKey.decrypt(passphrase)) {
debug('key generation failed %o', {
durationMs: Date.now() - startTime,
});
return Promise.reject(new Error('Wrong passphrase! Could not decrypt the private key!'));
}
debug('key generation complete %o', {
durationMs: Date.now() - startTime,
});
}
);
}
export async function make(user, secret) {
const opts = {
userIds: [{ name: user }],
curve: 'brainpoolP512r1',
passphrase: secret
}
let key
try {
key = await openpgp.generateKey(opts)
} catch (e) {
throw e
}
return key
}
return (dispatch, getState) => {
const passphrase = randomWords({ exactly: 10, join: ' ' })
const options = {
userIds: [{ name:'Example Example', email:'example@example.com' }],
numBits: 2048,
passphrase: passphrase
};
openpgp.generateKey(options).then((key) => {
const privateKey = key.privateKeyArmored;
const publicKey = key.publicKeyArmored;
dispatch({
type: 'new_key',
passphrase,
privateKey,
publicKey
});
});
}
}