1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-01 21:32:17 -05:00

added unique id to rsa signature

This commit is contained in:
Tankred Hase 2013-05-15 14:14:08 +02:00
parent 838fc0396f
commit 0e4c09ebdf
5 changed files with 15 additions and 9 deletions

View File

@ -6,6 +6,7 @@
importScripts('../app-config.js'); importScripts('../app-config.js');
importScripts('./crypto-batch.js'); importScripts('./crypto-batch.js');
importScripts('./aes-cbc.js'); importScripts('./aes-cbc.js');
importScripts('./util.js');
importScripts('./rsa.js'); importScripts('./rsa.js');
/** /**
@ -18,7 +19,8 @@
output = null, output = null,
aes = new app.crypto.AesCBC(forge), aes = new app.crypto.AesCBC(forge),
rsa = new app.crypto.RSA(forge), rsa = new app.crypto.RSA(forge),
batch = new app.crypto.CryptoBatch(aes, rsa); util = new app.crypto.Util(),
batch = new app.crypto.CryptoBatch(aes, rsa, util);
// pass RSA keys to module // pass RSA keys to module
rsa.init(i.pubkeyPem, i.privkeyPem); rsa.init(i.pubkeyPem, i.privkeyPem);

View File

@ -1,7 +1,7 @@
/** /**
* Crypto batch library for processing large sets of data * Crypto batch library for processing large sets of data
*/ */
var CryptoBatch = function(aes, rsa) { var CryptoBatch = function(aes, rsa, util) {
'use strict'; 'use strict';
/** /**
@ -56,7 +56,7 @@ var CryptoBatch = function(aes, rsa) {
encryptedList.forEach(function(i) { encryptedList.forEach(function(i) {
// process new values // process new values
i.encryptedKey = rsa.encrypt(i.key); i.encryptedKey = rsa.encrypt(i.key);
i.signature = rsa.sign([i.iv, i.encryptedKey, i.ciphertext]); i.signature = rsa.sign([i.iv, util.str2Base64(i.id), i.encryptedKey, i.ciphertext]);
// delete old ones // delete old ones
delete i.key; delete i.key;
}); });
@ -75,7 +75,7 @@ var CryptoBatch = function(aes, rsa) {
// decrypt keys for user // decrypt keys for user
encryptedList.forEach(function(i) { encryptedList.forEach(function(i) {
// verify signature // verify signature
if (!rsa.verify([i.iv, i.encryptedKey, i.ciphertext], i.signature)) { if (!rsa.verify([i.iv, util.str2Base64(i.id), i.encryptedKey, i.ciphertext], i.signature)) {
throw new Error('Verifying RSA signature failed!'); throw new Error('Verifying RSA signature failed!');
} }
// precoess new values // precoess new values

View File

@ -242,7 +242,7 @@ app.crypto.Crypto = function(window, util) {
}); });
} else { } else {
var batch = new app.crypto.CryptoBatch(aes, rsa); var batch = new app.crypto.CryptoBatch(aes, rsa, util);
var encryptedList = batch.encryptListForUser(envelopes); var encryptedList = batch.encryptListForUser(envelopes);
callback(null, encryptedList); callback(null, encryptedList);
} }
@ -265,7 +265,7 @@ app.crypto.Crypto = function(window, util) {
}); });
} else { } else {
var batch = new app.crypto.CryptoBatch(aes, rsa); var batch = new app.crypto.CryptoBatch(aes, rsa, util);
var decryptedList = batch.decryptListForUser(list); var decryptedList = batch.decryptListForUser(list);
callback(null, decryptedList); callback(null, decryptedList);
} }

View File

@ -174,8 +174,10 @@ var Util = function(window, uuid, crypt) {
this.str2Base64 = function(str) { this.str2Base64 = function(str) {
if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
return new Buffer(str, 'binary').toString('base64'); return new Buffer(str, 'binary').toString('base64');
} else { } else if (typeof window !== 'undefined' && window.btoa) {
return window.btoa(str); return window.btoa(str);
} else {
return forge.util.encode64(str);
} }
}; };
@ -185,8 +187,10 @@ var Util = function(window, uuid, crypt) {
this.base642Str = function(str) { this.base642Str = function(str) {
if (typeof module !== 'undefined' && module.exports) { if (typeof module !== 'undefined' && module.exports) {
return new Buffer(str, 'base64').toString('binary'); return new Buffer(str, 'base64').toString('binary');
} else { } else if (typeof window !== 'undefined' && window.atob) {
return window.atob(str); return window.atob(str);
} else {
return forge.util.decode64(str);
} }
}; };

View File

@ -9,7 +9,7 @@ var TestData = function() {
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
mail = new app.model.Email({ mail = new app.model.Email({
id: i, id: i + '',
from: 'john@from.com', from: 'john@from.com',
to: ['jack@to.com'], to: ['jack@to.com'],
subject: 'Important stuff ' + i, subject: 'Important stuff ' + i,