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
/*
* Be VERY careful about changing this file. It is used in both the browser JS package and in the node.js encryption server
* Just because your changes work in the browser does not mean they work in the encryption server!
*/
if (typeof module !== 'undefined' && module.exports) {
// node.js
/* eslint { "no-global-assign": "off", "import/no-extraneous-dependencies": "off", "import/no-unresolved": "off", "global-require" : "off" } */
btoa = require('btoa');
atob = require('atob');
Promise = require('es6-promise').Promise;
openpgp = require('openpgp');
} else {
// Browser
openpgp.config.integrity_protect = true;
/*
* The safari tab seems to crash sometimes when using a webworker. This is a bug that was filed to Apple.
* But until Apple fixes this bug we can turn off the webworker to prevent this from happening.
* As soon as Apple fixes their bug we should use the webworker again, as it can causes the browser to hang
* when the user has a lot of addresses/public keys.
*/
const browsers = ['Safari', 'Mobile Safari'];
if(!_.contains(browsers, $.ua.browser.name)) {
openpgp.initWorker({path: 'openpgp.worker.min.js'});
}
}
openpgp.config.integrity_protect = true;
openpgp.config.use_native = true;
const openpgp = require('openpgp'); // use as CommonJS, AMD, ES6 module or via window.openpgp
openpgp.config.aead_protect = true; // activate fast AES-GCM mode (not yet OpenPGP standard)
/**
* Gets ASCII armored clearsign message and returns object
* {
* text - text from the message
* valid - verification status
* error - error occured during verification
* }
*/
function loadSignedText(keyText, armoredText) {
return Promise.resolve().then(()=>{
let options = {
message: openpgp.cleartext.readArmored(armoredText), // parse armored message
publicKeys: openpgp.key.readArmored(keyText).keys // for verification
};
return openpgp.verify(options).then((verified)=>{
import * as openpgp from 'openpgp'
openpgp.config.aead_protect = false
openpgp.config.prefer_hash_algorithm = 2 // SHA1
var hkp = new openpgp.HKP('https://pgp.mit.edu')
var hkp2 = new openpgp.HKP('http://keys.gnupg.net')
var keyring = new openpgp.Keyring()
// Print a key
function printKey () {
const keyid = printKeyid(this.primaryKey.getKeyId())
const userid = printUser(this.getPrimaryUser().user)
return keyid + ' ' + userid
}
// openpgp.key.toString = printKey
function printKeyid (keyid) {
return keyid.toHex()
}
function(cb_) {
common.log.out('[auto_updater] Verifying: ' + tmp + '.tar.gz...');
try {
/* Get keys from keyring */
/* The keyring is stored in openpgp.store/openpgp-public-keys, we */
/* explicitly specify the path here. */
pgp.config.node_store =
path.resolve(__dirname, '..', 'openpgp.store');
var keyring = new pgp.Keyring(),
keys = keyring.getAllKeys();
if(keys.length <= 0) {
return cb_(common.err('Unexpected keyring size',
'auto_updater:invalid_keyring'));
}
}
catch(err) {
return cb_(err);
}
/* Make sure that all the keys in the keyring are valid. At a later */
/* point we may want to allow invalid keys so long as the update is */
/* not signed with these. */
import * as openpgp from 'openpgp'
openpgp.config.aead_protect = false
openpgp.config.prefer_hash_algorithm = 2 // SHA1
var hkp = new openpgp.HKP('https://pgp.mit.edu')
var hkp2 = new openpgp.HKP('http://keys.gnupg.net')
var keyring = new openpgp.Keyring()
// Print a key
function printKey () {
const keyid = printKeyid(this.primaryKey.getKeyId())
const userid = printUser(this.getPrimaryUser().user)
return keyid + ' ' + userid
}
// openpgp.key.toString = printKey
function printKeyid (keyid) {
return keyid.toHex()
}
// openpgp.Keyid.prototype.toString = openpgp.Keyid.prototype.toHex
const openpgp = require('openpgp')
const inquirer = require('inquirer')
openpgp.config.show_comment = false
openpgp.config.show_version = false
async function generate(name, passphrase) {
const key = await openpgp.generateKey({
userIds: [{ name, email: `${name.toLowerCase()}@example.com` }],
curve: 'ed25519',
passphrase
})
console.log('Public key:')
console.log(key.publicKeyArmored)
console.log('\nPrivate key:')
console.log(key.privateKeyArmored)
console.log('Public key:')
console.log(JSON.stringify(key.publicKeyArmored).replace(/\\r/g, ''))
console.log('\nPrivate key:')
const openpgp = require('openpgp')
const inquirer = require('inquirer')
openpgp.config.show_comment = false
openpgp.config.show_version = false
async function generate(name, passphrase) {
const key = await openpgp.generateKey({
userIds: [{ name, email: `${name.toLowerCase()}@example.com` }],
curve: 'ed25519',
passphrase
})
console.log('Public key:')
console.log(key.publicKeyArmored)
console.log('\nPrivate key:')
console.log(key.privateKeyArmored)
console.log('Public key:')
console.log(JSON.stringify(key.publicKeyArmored).replace(/\\r/g, ''))
console.log('\nPrivate key:')
console.log(JSON.stringify(key.privateKeyArmored).replace(/\\r/g, ''))
function configOpenPgp() {
openpgp.config.show_version = openpgp.config.show_comment = false;
}