freedom-pgp-e2e
Advanced tools
Comparing version 0.6.4 to 0.6.5
/*globals freedom, console, e2e, exports, ArrayBuffer, Uint8Array, Uint16Array, DataView*/ | ||
/*jslint indent:2*/ | ||
if (typeof Promise === 'undefined' && typeof ES6Promise !== 'undefined') { | ||
// Polyfill for karma unit tests | ||
Promise = ES6Promise.Promise; | ||
var useWebCrypto = false; | ||
if (typeof navigator !== 'undefined' && navigator && navigator.userAgent && | ||
navigator.userAgent.indexOf('Chrome') !== -1) { | ||
// Enable WebCrypto acceleration, on Chrome platforms only. | ||
// This should work on Firefox too, but it doesn't: | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1264771 | ||
e2e.scheme.EncryptionScheme.WEBCRYPTO_ALGORITHMS = 'ECDH'; | ||
e2e.scheme.SignatureScheme.WEBCRYPTO_ALGORITHMS = 'ECDSA'; | ||
useWebCrypto = true; | ||
} | ||
@@ -69,8 +75,9 @@ | ||
}).then(function() { | ||
if (e2e.async.Result.getValue( | ||
scope.pgpContext.searchPrivateKey(scope.pgpUser)).length === 0) { | ||
return scope.pgpContext.searchPrivateKey(scope.pgpUser); | ||
}).then(function(privateKeys) { | ||
if (privateKeys.length === 0) { | ||
var username = scope.pgpUser.slice(0, userid.lastIndexOf('<')).trim(); | ||
var email = scope.pgpUser.slice(userid.lastIndexOf('<') + 1, -1); | ||
// console.log("Generating key for " + scope.pgpUser); | ||
scope.generateKey(username, email); | ||
return scope.generateKey(username, email); | ||
} | ||
@@ -101,7 +108,12 @@ });//.bind(this)); // TODO: switch back to using this once jasmine works | ||
}).then(function() { | ||
if (e2e.async.Result.getValue( | ||
scope.pgpContext.searchPrivateKey(userid)).length === 0 || | ||
e2e.async.Result.getValue( | ||
scope.pgpContext.searchPublicKey(userid)).length === 0) { | ||
return Promise.reject(Error('Keypair does not match provided userid')); | ||
return scope.pgpContext.searchPrivateKey(userid); | ||
}).then(function(privateKeys) { | ||
if (privateKeys.length === 0) { | ||
return Promise.reject( | ||
Error('Private key does not match provided userid')); | ||
} | ||
return scope.pgpContext.searchPublicKey(userid); | ||
}).then(function(publicKeys) { | ||
if (publicKeys.length === 0) { | ||
return Promise.reject(Error('Public key does not match provided userid')); | ||
} else if (!userid.match(/^[^<]*\s?<[^>]*>$/)) { | ||
@@ -121,14 +133,15 @@ return Promise.reject(Error('Invalid userid, expected: "name <email>"')); | ||
// removeHeader is an optional parameter that removes PGP header and newlines | ||
var keyResult = e2e.async.Result.getValue( | ||
this.pgpContext.searchPublicKey(this.pgpUser)); | ||
var serialized = keyResult[0].serialized; | ||
var key = e2e.openpgp.asciiArmor.encode('PUBLIC KEY BLOCK', serialized); | ||
if (removeHeader) { | ||
// If optional removeHeader is true, then remove the PGP head/foot lines | ||
key = key.split('\r\n').slice(3, key.split('\r\n').length - 2).join(''); | ||
} | ||
return Promise.resolve({ | ||
'key': key, | ||
'fingerprint': keyResult[0].key.fingerprintHex, | ||
'words': hex2words(keyResult[0].key.fingerprintHex) | ||
return this.pgpContext.searchPublicKey(this.pgpUser).then( | ||
function(keyResult) { | ||
var serialized = keyResult[0].serialized; | ||
var key = e2e.openpgp.asciiArmor.encode('PUBLIC KEY BLOCK', serialized); | ||
if (removeHeader) { | ||
// If optional removeHeader is true, then remove the PGP head/foot lines | ||
key = key.split('\r\n').slice(3, key.split('\r\n').length - 2).join(''); | ||
} | ||
return { | ||
'key': key, | ||
'fingerprint': keyResult[0].key.fingerprintHex, | ||
'words': hex2words(keyResult[0].key.fingerprintHex) | ||
}; | ||
}); | ||
@@ -166,10 +179,9 @@ }; | ||
}).then(function(keys) { | ||
var signKey; | ||
var signKeysPromise = Promise.resolve([null]); | ||
if (sign) { | ||
signKey = e2e.async.Result.getValue( | ||
pgp.searchPrivateKey(user))[0]; | ||
} else { | ||
signKey = null; | ||
signKeysPromise = pgp.searchPrivateKey(user); | ||
} | ||
return pgp.encryptSign(buf2array(data), [], keys, [], signKey); | ||
return signKeysPromise.then(function(signKeys) { | ||
return pgp.encryptSign(buf2array(data), [], keys, [], signKeys[0]); | ||
}); | ||
}).then(array2buf); | ||
@@ -235,15 +247,16 @@ }; | ||
var privKey = keyRing.searchKey(this.pgpUser, e2e.openpgp.KeyRing.Type.PRIVATE); | ||
var localPrivKey = keyRing.getKeyBlock(privKey[0].toKeyObject()); | ||
var cipher = localPrivKey.keyPacket.cipher; | ||
return keyRing.getKeyBlock(privKey[0].toKeyObject()) | ||
.then(function(localPrivKey) { | ||
var cipher = localPrivKey.keyPacket.cipher; | ||
// The curve data in both cases are simple arrays of numbers, so | ||
// this works pretty well. | ||
if (cipher.cipher_.key.curve.toString() != | ||
parsedPubkey.keyPacket.cipher.key.curve.toString()) { | ||
return Promise.reject(new Error('Keys have different curves.')); | ||
} | ||
var wrap = cipher.getWrappedCipher(); | ||
var bobResult = ecdh.bob(pubkey, wrap.key.privKey); | ||
return Promise.resolve(array2buf(bobResult.secret)); | ||
// The curve data in both cases are simple arrays of numbers, so | ||
// this works pretty well. | ||
if (cipher.cipher_.key.curve.toString() != | ||
parsedPubkey.keyPacket.cipher.key.curve.toString()) { | ||
throw new Error('Keys have different curves.'); | ||
} | ||
var wrap = cipher.getWrappedCipher(); | ||
var bobResult = ecdh.bob(pubkey, wrap.key.privKey); | ||
return array2buf(bobResult.secret); | ||
}); | ||
} catch (e) { | ||
@@ -262,3 +275,5 @@ console.log("ERROR: " + JSON.stringify(e)); | ||
var expiration = Date.now() / 1000 + (3600 * 24 * 365); | ||
return pgp.generateKey('ECDSA', 256, 'ECDH', 256, name, '', email, expiration) | ||
var location = useWebCrypto ? 'WEB_CRYPTO' : 'JAVASCRIPT'; | ||
return pgp.generateKey('ECDSA', 256, 'ECDH', 256, name, '', email, expiration, | ||
location) | ||
.then(function (keys) { | ||
@@ -265,0 +280,0 @@ if (keys.length !== 2) { |
@@ -14,3 +14,2 @@ /** | ||
require('jit-grunt')(grunt, { | ||
jasmine_node: 'grunt-jasmine-node2', | ||
'npm-publish': 'grunt-npm' | ||
@@ -114,4 +113,4 @@ }); | ||
jasmine_node: { | ||
integration: ['spec/integration/'] | ||
jasmine_nodejs: { | ||
integration: { specs: ['spec/integration/**']} | ||
}, | ||
@@ -194,3 +193,3 @@ | ||
'jasmine_chromeapp', | ||
'jasmine_node', | ||
'jasmine_nodejs', | ||
'jasmine_firefoxaddon' | ||
@@ -200,3 +199,3 @@ ]); | ||
'build', | ||
'jasmine_node' | ||
'jasmine_nodejs' | ||
]); | ||
@@ -203,0 +202,0 @@ grunt.registerTask('release', function(arg) { |
{ | ||
"name": "freedom-pgp-e2e", | ||
"description": "Library to provide freedom API wrapper of end-to-end library", | ||
"version": "0.6.4", | ||
"version": "0.6.5", | ||
"contributors": [ | ||
@@ -14,3 +14,3 @@ "Aaron Gallant <ag@cs.washington.edu>" | ||
"devDependencies": { | ||
"e2e": "^0.0.7", | ||
"e2e": "^0.0.8", | ||
"es6-promise": "^3.1.2", | ||
@@ -29,4 +29,4 @@ "freedom": "^0.6.29", | ||
"grunt-jasmine-chromeapp": "^1.9.0", | ||
"grunt-jasmine-firefoxaddon": "^0.3.5", | ||
"grunt-jasmine-node2": "^0.4.0", | ||
"grunt-jasmine-firefoxaddon": "^0.3.6", | ||
"grunt-jasmine-nodejs": "^1.5.2", | ||
"grunt-karma": "^0.12.2", | ||
@@ -33,0 +33,0 @@ "grunt-npm": "^0.0.2", |
@@ -445,6 +445,4 @@ /*globals describe, beforeEach, require, expect, it*/ | ||
e2eImp.setup('', '<user-0@example.com>').then( | ||
function () { | ||
return e2eImp.importKeypair('', '<user-1@example.com>', secondPrivKeyStr); | ||
}).then(function() { | ||
e2eImp.importKeypair('', '<user-1@example.com>', secondPrivKeyStr) | ||
.then(function() { | ||
return e2eImp.ecdhBob('P_256', publicKeyStr); | ||
@@ -451,0 +449,0 @@ }).then(function(secret) { |
@@ -18,3 +18,3 @@ /*globals freedom,Uint8Array,ArrayBuffer*/ | ||
this.dispatch('print', 'Starting encryption test! Clearing past key...'); | ||
e2e.clear().then(function() { | ||
return e2e.clear().then(function() { | ||
return e2e.setup('secret passphrase', 'Joe Test <joetest@example.com>'); | ||
@@ -57,3 +57,3 @@ }).then( | ||
this.dispatch('print', 'Starting keypair import test!'); | ||
e2e.importKeypair('', '<quantsword@gmail.com>', privateKeyStr).then( | ||
return e2e.importKeypair('', '<quantsword@gmail.com>', privateKeyStr).then( | ||
function() { | ||
@@ -101,2 +101,2 @@ this.dispatch('print', 'Imported keypair...'); | ||
freedom().provideSynchronous(e2edemo); | ||
freedom().providePromises(e2edemo); |
/*globals freedom, console, e2e, exports, ArrayBuffer, Uint8Array, Uint16Array, DataView*/ | ||
/*jslint indent:2*/ | ||
if (typeof Promise === 'undefined' && typeof ES6Promise !== 'undefined') { | ||
// Polyfill for karma unit tests | ||
Promise = ES6Promise.Promise; | ||
var useWebCrypto = false; | ||
if (typeof navigator !== 'undefined' && navigator && navigator.userAgent && | ||
navigator.userAgent.indexOf('Chrome') !== -1) { | ||
// Enable WebCrypto acceleration, on Chrome platforms only. | ||
// This should work on Firefox too, but it doesn't: | ||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1264771 | ||
e2e.scheme.EncryptionScheme.WEBCRYPTO_ALGORITHMS = 'ECDH'; | ||
e2e.scheme.SignatureScheme.WEBCRYPTO_ALGORITHMS = 'ECDSA'; | ||
useWebCrypto = true; | ||
} | ||
@@ -69,8 +75,9 @@ | ||
}).then(function() { | ||
if (e2e.async.Result.getValue( | ||
scope.pgpContext.searchPrivateKey(scope.pgpUser)).length === 0) { | ||
return scope.pgpContext.searchPrivateKey(scope.pgpUser); | ||
}).then(function(privateKeys) { | ||
if (privateKeys.length === 0) { | ||
var username = scope.pgpUser.slice(0, userid.lastIndexOf('<')).trim(); | ||
var email = scope.pgpUser.slice(userid.lastIndexOf('<') + 1, -1); | ||
// console.log("Generating key for " + scope.pgpUser); | ||
scope.generateKey(username, email); | ||
return scope.generateKey(username, email); | ||
} | ||
@@ -101,7 +108,12 @@ });//.bind(this)); // TODO: switch back to using this once jasmine works | ||
}).then(function() { | ||
if (e2e.async.Result.getValue( | ||
scope.pgpContext.searchPrivateKey(userid)).length === 0 || | ||
e2e.async.Result.getValue( | ||
scope.pgpContext.searchPublicKey(userid)).length === 0) { | ||
return Promise.reject(Error('Keypair does not match provided userid')); | ||
return scope.pgpContext.searchPrivateKey(userid); | ||
}).then(function(privateKeys) { | ||
if (privateKeys.length === 0) { | ||
return Promise.reject( | ||
Error('Private key does not match provided userid')); | ||
} | ||
return scope.pgpContext.searchPublicKey(userid); | ||
}).then(function(publicKeys) { | ||
if (publicKeys.length === 0) { | ||
return Promise.reject(Error('Public key does not match provided userid')); | ||
} else if (!userid.match(/^[^<]*\s?<[^>]*>$/)) { | ||
@@ -121,14 +133,15 @@ return Promise.reject(Error('Invalid userid, expected: "name <email>"')); | ||
// removeHeader is an optional parameter that removes PGP header and newlines | ||
var keyResult = e2e.async.Result.getValue( | ||
this.pgpContext.searchPublicKey(this.pgpUser)); | ||
var serialized = keyResult[0].serialized; | ||
var key = e2e.openpgp.asciiArmor.encode('PUBLIC KEY BLOCK', serialized); | ||
if (removeHeader) { | ||
// If optional removeHeader is true, then remove the PGP head/foot lines | ||
key = key.split('\r\n').slice(3, key.split('\r\n').length - 2).join(''); | ||
} | ||
return Promise.resolve({ | ||
'key': key, | ||
'fingerprint': keyResult[0].key.fingerprintHex, | ||
'words': hex2words(keyResult[0].key.fingerprintHex) | ||
return this.pgpContext.searchPublicKey(this.pgpUser).then( | ||
function(keyResult) { | ||
var serialized = keyResult[0].serialized; | ||
var key = e2e.openpgp.asciiArmor.encode('PUBLIC KEY BLOCK', serialized); | ||
if (removeHeader) { | ||
// If optional removeHeader is true, then remove the PGP head/foot lines | ||
key = key.split('\r\n').slice(3, key.split('\r\n').length - 2).join(''); | ||
} | ||
return { | ||
'key': key, | ||
'fingerprint': keyResult[0].key.fingerprintHex, | ||
'words': hex2words(keyResult[0].key.fingerprintHex) | ||
}; | ||
}); | ||
@@ -166,10 +179,9 @@ }; | ||
}).then(function(keys) { | ||
var signKey; | ||
var signKeysPromise = Promise.resolve([null]); | ||
if (sign) { | ||
signKey = e2e.async.Result.getValue( | ||
pgp.searchPrivateKey(user))[0]; | ||
} else { | ||
signKey = null; | ||
signKeysPromise = pgp.searchPrivateKey(user); | ||
} | ||
return pgp.encryptSign(buf2array(data), [], keys, [], signKey); | ||
return signKeysPromise.then(function(signKeys) { | ||
return pgp.encryptSign(buf2array(data), [], keys, [], signKeys[0]); | ||
}); | ||
}).then(array2buf); | ||
@@ -235,15 +247,16 @@ }; | ||
var privKey = keyRing.searchKey(this.pgpUser, e2e.openpgp.KeyRing.Type.PRIVATE); | ||
var localPrivKey = keyRing.getKeyBlock(privKey[0].toKeyObject()); | ||
var cipher = localPrivKey.keyPacket.cipher; | ||
return keyRing.getKeyBlock(privKey[0].toKeyObject()) | ||
.then(function(localPrivKey) { | ||
var cipher = localPrivKey.keyPacket.cipher; | ||
// The curve data in both cases are simple arrays of numbers, so | ||
// this works pretty well. | ||
if (cipher.cipher_.key.curve.toString() != | ||
parsedPubkey.keyPacket.cipher.key.curve.toString()) { | ||
return Promise.reject(new Error('Keys have different curves.')); | ||
} | ||
var wrap = cipher.getWrappedCipher(); | ||
var bobResult = ecdh.bob(pubkey, wrap.key.privKey); | ||
return Promise.resolve(array2buf(bobResult.secret)); | ||
// The curve data in both cases are simple arrays of numbers, so | ||
// this works pretty well. | ||
if (cipher.cipher_.key.curve.toString() != | ||
parsedPubkey.keyPacket.cipher.key.curve.toString()) { | ||
throw new Error('Keys have different curves.'); | ||
} | ||
var wrap = cipher.getWrappedCipher(); | ||
var bobResult = ecdh.bob(pubkey, wrap.key.privKey); | ||
return array2buf(bobResult.secret); | ||
}); | ||
} catch (e) { | ||
@@ -262,3 +275,5 @@ console.log("ERROR: " + JSON.stringify(e)); | ||
var expiration = Date.now() / 1000 + (3600 * 24 * 365); | ||
return pgp.generateKey('ECDSA', 256, 'ECDH', 256, name, '', email, expiration) | ||
var location = useWebCrypto ? 'WEB_CRYPTO' : 'JAVASCRIPT'; | ||
return pgp.generateKey('ECDSA', 256, 'ECDH', 256, name, '', email, expiration, | ||
location) | ||
.then(function (keys) { | ||
@@ -265,0 +280,0 @@ if (keys.length !== 2) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2247207
16214