mirror of
https://github.com/moparisthebest/mail
synced 2025-01-30 22:50:17 -05:00
minor fixes to email dao and crypto
This commit is contained in:
parent
afe8c1329b
commit
0cb5214b94
@ -15,9 +15,18 @@ app.crypto.Crypto = function(window, util) {
|
||||
this.init = function(args, callback) {
|
||||
var self = this;
|
||||
|
||||
// valdiate input
|
||||
if (!args.emailAddress || !args.keySize || !args.rsaKeySize) {
|
||||
callback({
|
||||
errMsg: 'Crypto init failed. Not all args set!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
this.emailAddress = args.emailAddress;
|
||||
this.keySize = args.keySize;
|
||||
this.ivSize = args.keySize;
|
||||
this.rsaKeySize = args.rsaKeySize;
|
||||
|
||||
// derive PBKDF2 from password in web worker thread
|
||||
this.deriveKey(args.password, args.keySize, function(pbkdf2) {
|
||||
@ -40,7 +49,7 @@ app.crypto.Crypto = function(window, util) {
|
||||
|
||||
function generateKeypair(keyStore, storageId, pbkdf2) {
|
||||
// generate RSA keypair in web worker
|
||||
rsa.generateKeypair(rsa_test.keySize, function(err) {
|
||||
rsa.generateKeypair(self.rsaKeySize, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
return;
|
||||
@ -56,8 +65,8 @@ app.crypto.Crypto = function(window, util) {
|
||||
var newStoredKeypair = {
|
||||
_id: keypair._id,
|
||||
userId: args.emailAddress,
|
||||
encryptedKeys: encryptedKeys,
|
||||
keyIV: iv
|
||||
encryptedKey: encryptedKeys,
|
||||
iv: iv
|
||||
};
|
||||
keyStore.persist(storageId, newStoredKeypair);
|
||||
|
||||
@ -69,7 +78,7 @@ app.crypto.Crypto = function(window, util) {
|
||||
var keypairJson, keypair;
|
||||
// try to decrypt with pbkdf2
|
||||
try {
|
||||
keypairJson = aes.decrypt(storedKeypair.encryptedKeys, pbkdf2, storedKeypair.keyIV);
|
||||
keypairJson = aes.decrypt(storedKeypair.encryptedKey, pbkdf2, storedKeypair.iv);
|
||||
keypair = JSON.parse(keypairJson);
|
||||
} catch (ex) {
|
||||
callback({
|
||||
|
@ -2,7 +2,7 @@
|
||||
* A high-level Data-Access Api for handling Email synchronization
|
||||
* between the cloud service and the device's local storage
|
||||
*/
|
||||
app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage) {
|
||||
app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage, util) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
@ -30,7 +30,8 @@ app.dao.EmailDAO = function(_, crypto, devicestorage, cloudstorage) {
|
||||
crypto.init({
|
||||
emailAddress: account.get('emailAddress'),
|
||||
password: password,
|
||||
keySize: account.get('symKeySize')
|
||||
keySize: account.get('symKeySize'),
|
||||
rsaKeySize: account.get('asymKeySize')
|
||||
}, function(err) {
|
||||
if (err) {
|
||||
callback(err);
|
||||
|
@ -7,6 +7,7 @@
|
||||
emailAddress: null,
|
||||
symKeySize: null,
|
||||
symIvSize: null,
|
||||
ssymKeySize: null,
|
||||
folders: null
|
||||
},
|
||||
|
||||
|
@ -4,7 +4,8 @@ var crypto_test = {
|
||||
user: 'crypto_test@example.com',
|
||||
password: 'Password',
|
||||
keySize: 128,
|
||||
ivSize: 128
|
||||
ivSize: 128,
|
||||
rsaKeySize: 1024
|
||||
};
|
||||
|
||||
asyncTest("Init", 2, function() {
|
||||
@ -16,7 +17,8 @@ asyncTest("Init", 2, function() {
|
||||
crypto_test.crypto.init({
|
||||
emailAddress: crypto_test.user,
|
||||
password: crypto_test.password,
|
||||
keySize: crypto_test.keySize
|
||||
keySize: crypto_test.keySize,
|
||||
rsaKeySize: crypto_test.rsaKeySize
|
||||
}, function(err) {
|
||||
ok(!err, 'Init crypto');
|
||||
|
||||
|
@ -4,7 +4,8 @@ var emaildao_test = {
|
||||
user: 'test@atlasdev.onmicrosoft.com',
|
||||
password: 'Xoza76645',
|
||||
keySize: 128,
|
||||
ivSize: 128
|
||||
ivSize: 128,
|
||||
rsaKeySize: 1024
|
||||
};
|
||||
|
||||
asyncTest("Init", 3, function() {
|
||||
@ -22,7 +23,7 @@ asyncTest("Init", 3, function() {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
emaildao_test.emailDao = new app.dao.EmailDAO(_, emaildao_test.crypto, emaildao_test.storage, cloudstorageStub);
|
||||
emaildao_test.emailDao = new app.dao.EmailDAO(_, emaildao_test.crypto, emaildao_test.storage, cloudstorageStub, util);
|
||||
|
||||
// generate test data
|
||||
emaildao_test.list = new TestData().getEmailCollection(100);
|
||||
@ -30,7 +31,8 @@ asyncTest("Init", 3, function() {
|
||||
var account = new app.model.Account({
|
||||
emailAddress: emaildao_test.user,
|
||||
symKeySize: emaildao_test.keySize,
|
||||
symIvSize: emaildao_test.ivSize
|
||||
symIvSize: emaildao_test.ivSize,
|
||||
asymKeySize: emaildao_test.rsaKeySize
|
||||
});
|
||||
|
||||
emaildao_test.emailDao.init(account, emaildao_test.password, function(err) {
|
||||
|
Loading…
Reference in New Issue
Block a user