Use underscore instead of camelcase in config
zeroCopy —> zero_copy useNative —> use_native Remove unnecessary tests from build
This commit is contained in:
parent
72c8bf5ea7
commit
843fba0d40
|
@ -19,7 +19,7 @@ OpenPGP.js [ via the `window.crypto.subtle` api, this will be used. Under node.js the native [crypto module](https://nodejs.org/api/crypto.html#crypto_crypto) is used. This can be deactivated by setting `openpgp.config.useNative = false`.
|
* If the user's browser supports [native WebCrypto](http://caniuse.com/#feat=cryptography) via the `window.crypto.subtle` api, this will be used. Under node.js the native [crypto module](https://nodejs.org/api/crypto.html#crypto_crypto) is used. This can be deactivated by setting `openpgp.config.use_native = false`.
|
||||||
|
|
||||||
* The library implements the [IETF proposal](https://tools.ietf.org/html/draft-ford-openpgp-format-00) for authenticated encryption using native AES-GCM provided by WebCrypto/Node. This makes symmetric encryption about 30x faster on supported platforms (with hardware acceleration). Since the specification has not been finalized and other OpenPGP implementations like GnuPG have not adopted it yet, the feature is currently hidden behind a flag. You can activate it by setting `openpgp.config.aead_protect = true`.
|
* The library implements the [IETF proposal](https://tools.ietf.org/html/draft-ford-openpgp-format-00) for authenticated encryption using native AES-GCM provided by WebCrypto/Node. This makes symmetric encryption about 30x faster on supported platforms (with hardware acceleration). Since the specification has not been finalized and other OpenPGP implementations like GnuPG have not adopted it yet, the feature is currently hidden behind a flag. You can activate it by setting `openpgp.config.aead_protect = true`.
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,8 @@ export default {
|
||||||
integrity_protect: true, // use integrity protection for symmetric encryption
|
integrity_protect: true, // use integrity protection for symmetric encryption
|
||||||
ignore_mdc_error: false, // fail on decrypt if message is not integrity protected
|
ignore_mdc_error: false, // fail on decrypt if message is not integrity protected
|
||||||
rsa_blinding: true,
|
rsa_blinding: true,
|
||||||
useNative: true, // use native node.js crypto and Web Crypto apis (if available)
|
use_native: true, // use native node.js crypto and Web Crypto apis (if available)
|
||||||
zeroCopy: false, // use transferable objects between the Web Worker and main thread
|
zero_copy: false, // use transferable objects between the Web Worker and main thread
|
||||||
debug: false,
|
debug: false,
|
||||||
show_version: true,
|
show_version: true,
|
||||||
show_comment: true,
|
show_comment: true,
|
||||||
|
|
|
@ -46,9 +46,9 @@ export function encrypt(cipher, plaintext, key, iv) {
|
||||||
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webCrypto && config.useNative && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
||||||
return webEncrypt(plaintext, key, iv);
|
return webEncrypt(plaintext, key, iv);
|
||||||
} else if (nodeCrypto && config.useNative) { // Node crypto library
|
} else if (nodeCrypto && config.use_native) { // Node crypto library
|
||||||
return nodeEncrypt(plaintext, key, iv) ;
|
return nodeEncrypt(plaintext, key, iv) ;
|
||||||
} else { // asm.js fallback
|
} else { // asm.js fallback
|
||||||
return Promise.resolve(asmCrypto.AES_GCM.encrypt(plaintext, key, iv));
|
return Promise.resolve(asmCrypto.AES_GCM.encrypt(plaintext, key, iv));
|
||||||
|
@ -68,9 +68,9 @@ export function decrypt(cipher, ciphertext, key, iv) {
|
||||||
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
return Promise.reject(new Error('GCM mode supports only AES cipher'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (webCrypto && config.useNative && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
if (webCrypto && config.use_native && key.length !== 24) { // WebCrypto (no 192 bit support) see: https://www.chromium.org/blink/webcrypto#TOC-AES-support
|
||||||
return webDecrypt(ciphertext, key, iv);
|
return webDecrypt(ciphertext, key, iv);
|
||||||
} else if (nodeCrypto && config.useNative) { // Node crypto library
|
} else if (nodeCrypto && config.use_native) { // Node crypto library
|
||||||
return nodeDecrypt(ciphertext, key, iv);
|
return nodeDecrypt(ciphertext, key, iv);
|
||||||
} else { // asm.js fallback
|
} else { // asm.js fallback
|
||||||
return Promise.resolve(asmCrypto.AES_GCM.decrypt(ciphertext, key, iv));
|
return Promise.resolve(asmCrypto.AES_GCM.decrypt(ciphertext, key, iv));
|
||||||
|
|
|
@ -95,7 +95,7 @@ SymEncryptedIntegrityProtected.prototype.encrypt = function (sessionKeyAlgorithm
|
||||||
if(sessionKeyAlgorithm.substr(0,3) === 'aes') { // AES optimizations. Native code for node, asmCrypto for browser.
|
if(sessionKeyAlgorithm.substr(0,3) === 'aes') { // AES optimizations. Native code for node, asmCrypto for browser.
|
||||||
var blockSize = crypto.cipher[sessionKeyAlgorithm].blockSize;
|
var blockSize = crypto.cipher[sessionKeyAlgorithm].blockSize;
|
||||||
|
|
||||||
if(nodeCrypto) { // Node crypto library. Only loaded if config.useNative === true
|
if(nodeCrypto) { // Node crypto library. Only loaded if config.use_native === true
|
||||||
var cipherObj = new nodeCrypto.createCipheriv('aes-' + sessionKeyAlgorithm.substr(3,3) + '-cfb',
|
var cipherObj = new nodeCrypto.createCipheriv('aes-' + sessionKeyAlgorithm.substr(3,3) + '-cfb',
|
||||||
new Buffer(key), new Buffer(new Uint8Array(blockSize)));
|
new Buffer(key), new Buffer(new Uint8Array(blockSize)));
|
||||||
this.encrypted = new Uint8Array(cipherObj.update(new Buffer(util.concatUint8Array([prefix, tohash]))));
|
this.encrypted = new Uint8Array(cipherObj.update(new Buffer(util.concatUint8Array([prefix, tohash]))));
|
||||||
|
@ -127,7 +127,7 @@ SymEncryptedIntegrityProtected.prototype.decrypt = function (sessionKeyAlgorithm
|
||||||
if(sessionKeyAlgorithm.substr(0,3) === 'aes') { // AES optimizations. Native code for node, asmCrypto for browser.
|
if(sessionKeyAlgorithm.substr(0,3) === 'aes') { // AES optimizations. Native code for node, asmCrypto for browser.
|
||||||
var blockSize = crypto.cipher[sessionKeyAlgorithm].blockSize;
|
var blockSize = crypto.cipher[sessionKeyAlgorithm].blockSize;
|
||||||
|
|
||||||
if(nodeCrypto) { // Node crypto library. Only loaded if config.useNative === true
|
if(nodeCrypto) { // Node crypto library. Only loaded if config.use_native === true
|
||||||
var decipherObj = new nodeCrypto.createDecipheriv('aes-' + sessionKeyAlgorithm.substr(3,3) + '-cfb',
|
var decipherObj = new nodeCrypto.createDecipheriv('aes-' + sessionKeyAlgorithm.substr(3,3) + '-cfb',
|
||||||
new Buffer(key), new Buffer(new Uint8Array(blockSize)));
|
new Buffer(key), new Buffer(new Uint8Array(blockSize)));
|
||||||
decrypted = new Uint8Array(decipherObj.update(new Buffer(this.encrypted)));
|
decrypted = new Uint8Array(decipherObj.update(new Buffer(this.encrypted)));
|
||||||
|
|
14
src/util.js
14
src/util.js
|
@ -61,7 +61,7 @@ export default {
|
||||||
* @return {Array<ArrayBuffer>} an array of binary data to be passed
|
* @return {Array<ArrayBuffer>} an array of binary data to be passed
|
||||||
*/
|
*/
|
||||||
getTransferables: function(obj) {
|
getTransferables: function(obj) {
|
||||||
if (config.zeroCopy && Object.prototype.isPrototypeOf(obj)) {
|
if (config.zero_copy && Object.prototype.isPrototypeOf(obj)) {
|
||||||
const transferables = [];
|
const transferables = [];
|
||||||
this.collectBuffers(obj, transferables);
|
this.collectBuffers(obj, transferables);
|
||||||
return transferables.length ? transferables : undefined;
|
return transferables.length ? transferables : undefined;
|
||||||
|
@ -452,11 +452,11 @@ export default {
|
||||||
/**
|
/**
|
||||||
* Get native Web Cryptography api, only the current version of the spec.
|
* Get native Web Cryptography api, only the current version of the spec.
|
||||||
* The default configuration is to use the api when available. But it can
|
* The default configuration is to use the api when available. But it can
|
||||||
* be deactivated with config.useNative
|
* be deactivated with config.use_native
|
||||||
* @return {Object} The SubtleCrypto api or 'undefined'
|
* @return {Object} The SubtleCrypto api or 'undefined'
|
||||||
*/
|
*/
|
||||||
getWebCrypto: function() {
|
getWebCrypto: function() {
|
||||||
if (!config.useNative) {
|
if (!config.use_native) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -467,11 +467,11 @@ export default {
|
||||||
* Get native Web Cryptography api for all browsers, including legacy
|
* Get native Web Cryptography api for all browsers, including legacy
|
||||||
* implementations of the spec e.g IE11 and Safari 8/9. The default
|
* implementations of the spec e.g IE11 and Safari 8/9. The default
|
||||||
* configuration is to use the api when available. But it can be deactivated
|
* configuration is to use the api when available. But it can be deactivated
|
||||||
* with config.useNative
|
* with config.use_native
|
||||||
* @return {Object} The SubtleCrypto api or 'undefined'
|
* @return {Object} The SubtleCrypto api or 'undefined'
|
||||||
*/
|
*/
|
||||||
getWebCryptoAll: function() {
|
getWebCryptoAll: function() {
|
||||||
if (!config.useNative) {
|
if (!config.use_native) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -528,11 +528,11 @@ export default {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get native Node.js crypto api. The default configuration is to use
|
* Get native Node.js crypto api. The default configuration is to use
|
||||||
* the api when available. But it can also be deactivated with config.useNative
|
* the api when available. But it can also be deactivated with config.use_native
|
||||||
* @return {Object} The crypto module or 'undefined'
|
* @return {Object} The crypto module or 'undefined'
|
||||||
*/
|
*/
|
||||||
getNodeCrypto: function() {
|
getNodeCrypto: function() {
|
||||||
if (!this.detectNode() || !config.useNative) {
|
if (!this.detectNode() || !config.use_native) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -328,26 +328,26 @@ describe('API functional testing', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Symmetric AES-GCM (native)', function() {
|
describe('Symmetric AES-GCM (native)', function() {
|
||||||
var useNativeVal;
|
var use_nativeVal;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
useNativeVal = openpgp.config.useNative;
|
use_nativeVal = openpgp.config.use_native;
|
||||||
openpgp.config.useNative = true;
|
openpgp.config.use_native = true;
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
openpgp.config.useNative = useNativeVal;
|
openpgp.config.use_native = use_nativeVal;
|
||||||
});
|
});
|
||||||
|
|
||||||
testAESGCM("12345678901234567890123456789012345678901234567890");
|
testAESGCM("12345678901234567890123456789012345678901234567890");
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Symmetric AES-GCM (asm.js fallback)', function() {
|
describe('Symmetric AES-GCM (asm.js fallback)', function() {
|
||||||
var useNativeVal;
|
var use_nativeVal;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
useNativeVal = openpgp.config.useNative;
|
use_nativeVal = openpgp.config.use_native;
|
||||||
openpgp.config.useNative = false;
|
openpgp.config.use_native = false;
|
||||||
});
|
});
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
openpgp.config.useNative = useNativeVal;
|
openpgp.config.use_native = use_nativeVal;
|
||||||
});
|
});
|
||||||
|
|
||||||
testAESGCM("12345678901234567890123456789012345678901234567890");
|
testAESGCM("12345678901234567890123456789012345678901234567890");
|
||||||
|
|
|
@ -342,19 +342,19 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('generateKey - integration tests', function() {
|
describe('generateKey - integration tests', function() {
|
||||||
var useNativeVal;
|
var use_nativeVal;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
useNativeVal = openpgp.config.useNative;
|
use_nativeVal = openpgp.config.use_native;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
openpgp.config.useNative = useNativeVal;
|
openpgp.config.use_native = use_nativeVal;
|
||||||
openpgp.destroyWorker();
|
openpgp.destroyWorker();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work in JS (without worker)', function(done) {
|
it('should work in JS (without worker)', function(done) {
|
||||||
openpgp.config.useNative = false;
|
openpgp.config.use_native = false;
|
||||||
openpgp.destroyWorker();
|
openpgp.destroyWorker();
|
||||||
var opt = {
|
var opt = {
|
||||||
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
||||||
|
@ -370,7 +370,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work in JS (with worker)', function(done) {
|
it('should work in JS (with worker)', function(done) {
|
||||||
openpgp.config.useNative = false;
|
openpgp.config.use_native = false;
|
||||||
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||||
var opt = {
|
var opt = {
|
||||||
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
||||||
|
@ -386,7 +386,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should work in with native crypto', function(done) {
|
it('should work in with native crypto', function(done) {
|
||||||
openpgp.config.useNative = true;
|
openpgp.config.use_native = true;
|
||||||
var opt = {
|
var opt = {
|
||||||
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
userIds: [{ name: 'Test User', email: 'text@example.com' }],
|
||||||
numBits: 512
|
numBits: 512
|
||||||
|
@ -403,7 +403,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('encrypt, decrypt, sign, verify - integration tests', function() {
|
describe('encrypt, decrypt, sign, verify - integration tests', function() {
|
||||||
var privateKey, publicKey, zeroCopyVal, useNativeVal, aead_protectVal;
|
var privateKey, publicKey, zero_copyVal, use_nativeVal, aead_protectVal;
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
publicKey = openpgp.key.readArmored(pub_key);
|
publicKey = openpgp.key.readArmored(pub_key);
|
||||||
|
@ -412,14 +412,14 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
privateKey = openpgp.key.readArmored(priv_key);
|
privateKey = openpgp.key.readArmored(priv_key);
|
||||||
expect(privateKey.keys).to.have.length(1);
|
expect(privateKey.keys).to.have.length(1);
|
||||||
expect(privateKey.err).to.not.exist;
|
expect(privateKey.err).to.not.exist;
|
||||||
zeroCopyVal = openpgp.config.zeroCopy;
|
zero_copyVal = openpgp.config.zero_copy;
|
||||||
useNativeVal = openpgp.config.useNative;
|
use_nativeVal = openpgp.config.use_native;
|
||||||
aead_protectVal = openpgp.config.aead_protect;
|
aead_protectVal = openpgp.config.aead_protect;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
openpgp.config.zeroCopy = zeroCopyVal;
|
openpgp.config.zero_copy = zero_copyVal;
|
||||||
openpgp.config.useNative = useNativeVal;
|
openpgp.config.use_native = use_nativeVal;
|
||||||
openpgp.config.aead_protect = aead_protectVal;
|
openpgp.config.aead_protect = aead_protectVal;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
tryTests('CFB mode (asm.js)', tests, {
|
tryTests('CFB mode (asm.js)', tests, {
|
||||||
if: true,
|
if: true,
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
openpgp.config.useNative = false;
|
openpgp.config.use_native = true;
|
||||||
openpgp.config.aead_protect = false;
|
openpgp.config.aead_protect = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -445,7 +445,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
openpgp.initWorker({ path:'../dist/openpgp.worker.js' });
|
||||||
},
|
},
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
openpgp.config.useNative = false;
|
openpgp.config.use_native = true;
|
||||||
openpgp.config.aead_protect = false;
|
openpgp.config.aead_protect = false;
|
||||||
},
|
},
|
||||||
after: function() {
|
after: function() {
|
||||||
|
@ -453,18 +453,10 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tryTests('GCM mode (asm.js)', tests, {
|
|
||||||
if: true,
|
|
||||||
beforeEach: function() {
|
|
||||||
openpgp.config.useNative = false;
|
|
||||||
openpgp.config.aead_protect = true;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
tryTests('GCM mode (native)', tests, {
|
tryTests('GCM mode (native)', tests, {
|
||||||
if: openpgp.util.getWebCrypto() || openpgp.util.getNodeCrypto(),
|
if: openpgp.util.getWebCrypto() || openpgp.util.getNodeCrypto(),
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
openpgp.config.useNative = true;
|
openpgp.config.use_native = true;
|
||||||
openpgp.config.aead_protect = true;
|
openpgp.config.aead_protect = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -893,7 +885,7 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encrypt and decrypt with binary data and transferable objects', function(done) {
|
it('should encrypt and decrypt with binary data and transferable objects', function(done) {
|
||||||
openpgp.config.zeroCopy = true; // activate transferable objects
|
openpgp.config.zero_copy = true; // activate transferable objects
|
||||||
var encOpt = {
|
var encOpt = {
|
||||||
data: new Uint8Array([0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01]),
|
data: new Uint8Array([0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01]),
|
||||||
passwords: password1,
|
passwords: password1,
|
||||||
|
|
|
@ -145,7 +145,7 @@ describe('Util unit tests', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getTransferables', function() {
|
describe('getTransferables', function() {
|
||||||
var zeroCopyVal,
|
var zero_copyVal,
|
||||||
buf1 = new Uint8Array(1),
|
buf1 = new Uint8Array(1),
|
||||||
buf2 = new Uint8Array(1),
|
buf2 = new Uint8Array(1),
|
||||||
obj = {
|
obj = {
|
||||||
|
@ -157,16 +157,16 @@ describe('Util unit tests', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
zeroCopyVal = openpgp.config.zeroCopy;
|
zero_copyVal = openpgp.config.zero_copy;
|
||||||
openpgp.config.zeroCopy = true;
|
openpgp.config.zero_copy = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(function() {
|
afterEach(function() {
|
||||||
openpgp.config.zeroCopy = zeroCopyVal;
|
openpgp.config.zero_copy = zero_copyVal;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return undefined when zeroCopy is false', function() {
|
it('should return undefined when zero_copy is false', function() {
|
||||||
openpgp.config.zeroCopy = false;
|
openpgp.config.zero_copy = false;
|
||||||
expect(openpgp.util.getTransferables(obj)).to.be.undefined;
|
expect(openpgp.util.getTransferables(obj)).to.be.undefined;
|
||||||
});
|
});
|
||||||
it('should return undefined for no input', function() {
|
it('should return undefined for no input', function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user