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