diff --git a/Gruntfile.js b/Gruntfile.js index 9a2a8ee..2b4b8b1 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -51,6 +51,7 @@ module.exports = function(grunt) { qunit: { all: { options: { + timeout: 20000, urls: [ 'http://localhost:<%= connect.test.options.port %>/test/unit/index.html', 'http://localhost:<%= connect.test.options.port %>/test/integration/index.html' diff --git a/src/js/crypto/aes-batch-worker.js b/src/js/crypto/aes-batch-worker.js index 81b0a16..c90e332 100644 --- a/src/js/crypto/aes-batch-worker.js +++ b/src/js/crypto/aes-batch-worker.js @@ -2,36 +2,41 @@ 'use strict'; // import web worker dependencies - importScripts('../../lib/forge/forge.rsa.bundle.js'); - importScripts('../app-config.js'); - importScripts('./crypto-batch.js'); - importScripts('./aes-cbc.js'); + importScripts('../../lib/require.js'); /** * In the web worker thread context, 'this' and 'self' can be used as a global * variable namespace similar to the 'window' object in the main thread */ self.onmessage = function(e) { + // fetch dependencies via require.js + require(['../../require-config'], function() { + require.config({ + baseUrl: '../../lib' + }); - var i = e.data, - output = null, - aes = new cryptoLib.AesCBC(forge), - batch = new cryptoLib.CryptoBatch(aes); + require(['cryptoLib/crypto-batch'], function(batch) { - if (i.type === 'encrypt' && i.list) { - // start encryption - output = batch.encryptList(i.list); + var i = e.data, + output = null; - } else if (i.type === 'decrypt' && i.list) { - // start decryption - output = batch.decryptList(i.list); + if (i.type === 'encrypt' && i.list) { + // start encryption + output = batch.encryptList(i.list); - } else { - throw 'Not all arguments for web worker crypto are defined!'; - } + } else if (i.type === 'decrypt' && i.list) { + // start decryption + output = batch.decryptList(i.list); - // pass output back to main thread - self.postMessage(output); + } else { + throw 'Not all arguments for web worker crypto are defined!'; + } + + // pass output back to main thread + self.postMessage(output); + + }); + }); }; }()); \ No newline at end of file diff --git a/src/js/crypto/aes-worker.js b/src/js/crypto/aes-worker.js index eee4597..b0153dc 100644 --- a/src/js/crypto/aes-worker.js +++ b/src/js/crypto/aes-worker.js @@ -2,34 +2,41 @@ 'use strict'; // import web worker dependencies - importScripts('../../lib/forge/forge.rsa.bundle.js'); - importScripts('../app-config.js'); - importScripts('./aes-cbc.js'); + importScripts('../../lib/require.js'); /** * In the web worker thread context, 'this' and 'self' can be used as a global * variable namespace similar to the 'window' object in the main thread */ self.onmessage = function(e) { + // fetch dependencies via require.js + require(['../../require-config'], function() { + require.config({ + baseUrl: '../../lib' + }); - var i = e.data, - output = null, - aes = new cryptoLib.AesCBC(forge); + require(['cryptoLib/aes-cbc'], function(aes) { - if (i.type === 'encrypt' && i.plaintext && i.key && i.iv) { - // start encryption - output = aes.encrypt(i.plaintext, i.key, i.iv); + var i = e.data, + output = null; - } else if (i.type === 'decrypt' && i.ciphertext && i.key && i.iv) { - // start decryption - output = aes.decrypt(i.ciphertext, i.key, i.iv); + if (i.type === 'encrypt' && i.plaintext && i.key && i.iv) { + // start encryption + output = aes.encrypt(i.plaintext, i.key, i.iv); - } else { - throw 'Not all arguments for web worker crypto are defined!'; - } + } else if (i.type === 'decrypt' && i.ciphertext && i.key && i.iv) { + // start decryption + output = aes.decrypt(i.ciphertext, i.key, i.iv); - // pass output back to main thread - self.postMessage(output); + } else { + throw 'Not all arguments for web worker crypto are defined!'; + } + + // pass output back to main thread + self.postMessage(output); + + }); + }); }; }()); \ No newline at end of file diff --git a/src/js/crypto/crypto-batch-worker.js b/src/js/crypto/crypto-batch-worker.js index b30460b..87ded59 100644 --- a/src/js/crypto/crypto-batch-worker.js +++ b/src/js/crypto/crypto-batch-worker.js @@ -2,41 +2,41 @@ 'use strict'; // import web worker dependencies - importScripts('../../lib/underscore-1.4.4.min.js'); - importScripts('../../lib/forge/forge.rsa.bundle.js'); - importScripts('../app-config.js'); - importScripts('./crypto-batch.js'); - importScripts('./aes-cbc.js'); - importScripts('./util.js'); - importScripts('./rsa.js'); + importScripts('../../lib/require.js'); /** * In the web worker thread context, 'this' and 'self' can be used as a global * variable namespace similar to the 'window' object in the main thread */ self.onmessage = function(e) { + // fetch dependencies via require.js + require(['../../require-config'], function() { + require.config({ + baseUrl: '../../lib' + }); - var i = e.data, - output = null, - aes = new cryptoLib.AesCBC(forge), - rsa = new cryptoLib.RSA(forge), - util = new cryptoLib.Util(), - batch = new cryptoLib.CryptoBatch(aes, rsa, util, _); + require(['cryptoLib/crypto-batch'], function(batch) { - if (i.type === 'encrypt' && i.receiverPubkeys && i.senderPrivkey && i.list) { - // start encryption - output = batch.encryptListForUser(i.list, i.receiverPubkeys, i.senderPrivkey); + var i = e.data, + output = null; - } else if (i.type === 'decrypt' && i.senderPubkeys && i.receiverPrivkey && i.list) { - // start decryption - output = batch.decryptListForUser(i.list, i.senderPubkeys, i.receiverPrivkey); + if (i.type === 'encrypt' && i.receiverPubkeys && i.senderPrivkey && i.list) { + // start encryption + output = batch.encryptListForUser(i.list, i.receiverPubkeys, i.senderPrivkey); - } else { - throw 'Not all arguments for web worker crypto are defined!'; - } + } else if (i.type === 'decrypt' && i.senderPubkeys && i.receiverPrivkey && i.list) { + // start decryption + output = batch.decryptListForUser(i.list, i.senderPubkeys, i.receiverPrivkey); - // pass output back to main thread - self.postMessage(output); + } else { + throw 'Not all arguments for web worker crypto are defined!'; + } + + // pass output back to main thread + self.postMessage(output); + + }); + }); }; }()); \ No newline at end of file diff --git a/src/js/crypto/crypto.js b/src/js/crypto/crypto.js index 48f6b9f..840f273 100644 --- a/src/js/crypto/crypto.js +++ b/src/js/crypto/crypto.js @@ -2,7 +2,9 @@ * High level crypto api that invokes native crypto (if available) and * gracefully degrades to JS crypto (if unavailable) */ -define(['cryptoLib/util', 'cryptoLib/aes-cbc', 'cryptoLib/rsa', 'cryptoLib/crypto-batch', 'js/crypto/pbkdf2'], function(util, aes, rsa, cryptoBatch, pbkdf2) { +define(['cryptoLib/util', 'cryptoLib/aes-cbc', 'cryptoLib/rsa', 'cryptoLib/crypto-batch', + 'js/crypto/pbkdf2' +], function(util, aes, rsa, cryptoBatch, pbkdf2) { 'use strict'; var self = {}; diff --git a/src/js/crypto/pbkdf2-worker.js b/src/js/crypto/pbkdf2-worker.js index 37765d8..d5f4908 100644 --- a/src/js/crypto/pbkdf2-worker.js +++ b/src/js/crypto/pbkdf2-worker.js @@ -2,30 +2,37 @@ 'use strict'; // import web worker dependencies - importScripts('../../lib/forge/forge.rsa.bundle.js'); - importScripts('../app-config.js'); - importScripts('./pbkdf2.js'); + importScripts('../../lib/require.js'); /** * In the web worker thread context, 'this' and 'self' can be used as a global * variable namespace similar to the 'window' object in the main thread */ self.onmessage = function(e) { + // fetch dependencies via require.js + require(['../../require-config'], function() { + require.config({ + baseUrl: '../../lib' + }); - var i = e.data, - key = null; + require(['js/crypto/pbkdf2'], function(pbkdf2) { - if (i.password && i.keySize) { - // start deriving key - var pbkdf2 = new app.crypto.PBKDF2(); - key = pbkdf2.getKey(i.password, i.keySize); + var i = e.data, + key = null; - } else { - throw 'Not all arguments for web worker crypto are defined!'; - } + if (i.password && i.keySize) { + // start deriving key + key = pbkdf2.getKey(i.password, i.keySize); - // pass output back to main thread - self.postMessage(key); + } else { + throw 'Not all arguments for web worker crypto are defined!'; + } + + // pass output back to main thread + self.postMessage(key); + + }); + }); }; }()); \ No newline at end of file diff --git a/test/unit/main.js b/test/unit/main.js index 4e298ab..5b32cad 100644 --- a/test/unit/main.js +++ b/test/unit/main.js @@ -13,7 +13,6 @@ require(['../../src/require-config'], function() { window.Worker = undefined; app.config.workerPath = '../../src/js'; - app.config.cloudUrl = 'http://localhost:8888'; startTests(); });