mirror of
https://github.com/moparisthebest/mail
synced 2025-02-07 10:30:18 -05:00
fix and cleanup encrypted message parsing
This commit is contained in:
parent
a0ae4e6742
commit
dc7feaa80a
@ -34,7 +34,12 @@ define([], function() {
|
|||||||
* Strings are maintained here
|
* Strings are maintained here
|
||||||
*/
|
*/
|
||||||
app.string = {
|
app.string = {
|
||||||
signature: 'Sent securely from whiteout mail'
|
subject: '[whiteout] Encrypted message',
|
||||||
|
message: 'this is a private conversation. To read my encrypted message below, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/whiteout-mail/jjgghafhamholjigjoghcfcekhkonijg',
|
||||||
|
cryptPrefix: '-----BEGIN ENCRYPTED MESSAGE-----',
|
||||||
|
cryptSuffix: '-----END ENCRYPTED MESSAGE-----',
|
||||||
|
signature: 'Sent securely from whiteout mail',
|
||||||
|
webSite: 'http://whiteout.io'
|
||||||
};
|
};
|
||||||
|
|
||||||
return app;
|
return app;
|
||||||
|
@ -5,13 +5,8 @@ define(function(require) {
|
|||||||
util = require('cryptoLib/util'),
|
util = require('cryptoLib/util'),
|
||||||
crypto = require('js/crypto/crypto'),
|
crypto = require('js/crypto/crypto'),
|
||||||
jsonDB = require('js/dao/lawnchair-dao'),
|
jsonDB = require('js/dao/lawnchair-dao'),
|
||||||
devicestorage = require('js/dao/devicestorage-dao');
|
devicestorage = require('js/dao/devicestorage-dao'),
|
||||||
|
str = require('js/app-config').string;
|
||||||
var SUBJECT = '[whiteout] Encrypted message',
|
|
||||||
MESSAGE = 'this is a private conversation. To read my encrypted message below, simply install Whiteout Mail for Chrome. The app is really easy to use and automatically encrypts sent emails, so that only the two of us can read them: https://chrome.google.com/webstore/detail/whiteout-mail/jjgghafhamholjigjoghcfcekhkonijg\n\n\n',
|
|
||||||
PREFIX = '-----BEGIN ENCRYPTED MESSAGE-----\n',
|
|
||||||
SUFFIX = '\n-----END ENCRYPTED MESSAGE-----',
|
|
||||||
SIGNATURE = '\n\n\nSent securely from whiteout mail\nhttp://whiteout.io\n\n';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A high-level Data-Access Api for handling Email synchronization
|
* A high-level Data-Access Api for handling Email synchronization
|
||||||
@ -256,6 +251,12 @@ define(function(require) {
|
|||||||
function frameEncryptedMessage(email, ct) {
|
function frameEncryptedMessage(email, ct) {
|
||||||
var to, greeting, ctBase64;
|
var to, greeting, ctBase64;
|
||||||
|
|
||||||
|
var SUBJECT = str.subject,
|
||||||
|
MESSAGE = str.message + '\n\n\n',
|
||||||
|
PREFIX = str.cryptPrefix + '\n',
|
||||||
|
SUFFIX = '\n' + str.cryptSuffix,
|
||||||
|
SIGNATURE = '\n\n\n' + str.signature + '\n' + str.webSite + '\n\n';
|
||||||
|
|
||||||
// get first name of recipient
|
// get first name of recipient
|
||||||
to = (email.to[0].name || email.to[0].address).split('@')[0].split('.')[0].split(' ')[0];
|
to = (email.to[0].name || email.to[0].address).split('@')[0].split('.')[0].split(' ')[0];
|
||||||
greeting = 'Hi ' + to + ',\n\n';
|
greeting = 'Hi ' + to + ',\n\n';
|
||||||
@ -350,7 +351,7 @@ define(function(require) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// decrypt Message body
|
// decrypt Message body
|
||||||
if (message.body.indexOf(PREFIX) !== -1 && message.body.indexOf(SUFFIX) !== -1) {
|
if (message.body.indexOf(str.cryptPrefix) !== -1 && message.body.indexOf(str.cryptSuffix) !== -1) {
|
||||||
decryptBody(message, function(err, ptMessage) {
|
decryptBody(message, function(err, ptMessage) {
|
||||||
message = ptMessage;
|
message = ptMessage;
|
||||||
// return decrypted message
|
// return decrypted message
|
||||||
@ -366,12 +367,16 @@ define(function(require) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function decryptBody(email, callback) {
|
function decryptBody(email, callback) {
|
||||||
var ctMessageBase64, ctMessage, pubkeyIds;
|
var ctMessageBase64, ctMessageJson, ctMessage, pubkeyIds;
|
||||||
|
|
||||||
// parse email body for encrypted message block
|
// parse email body for encrypted message block
|
||||||
try {
|
try {
|
||||||
ctMessageBase64 = email.body.split(PREFIX)[1].split(SUFFIX)[0];
|
// get base64 encoded message block
|
||||||
ctMessage = JSON.parse(atob(ctMessageBase64));
|
ctMessageBase64 = email.body.split(str.cryptPrefix)[1].split(str.cryptSuffix)[0].trim();
|
||||||
|
// decode bae64
|
||||||
|
ctMessageJson = atob(ctMessageBase64);
|
||||||
|
// parse json string to get ciphertext object
|
||||||
|
ctMessage = JSON.parse(ctMessageJson);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
callback({
|
callback({
|
||||||
errMsg: 'Error parsing encrypted message block!'
|
errMsg: 'Error parsing encrypted message block!'
|
||||||
|
Loading…
Reference in New Issue
Block a user