Skip to content

Commit 6623c1c

Browse files
authored
Merge pull request #1492 from Hirobreak/reencrypt
Reencrypting Email
2 parents f2d4879 + ee5f1ed commit 6623c1c

File tree

9 files changed

+104
-45
lines changed

9 files changed

+104
-45
lines changed

electron_app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
"electron-notarize": "^0.1.1"
151151
},
152152
"dependencies": {
153-
"@criptext/api": "^0.17.0",
153+
"@criptext/api": "^0.17.1",
154154
"@criptext/data-transfer-client": "^0.1.1",
155155
"@criptext/electron-better-ipc": "^0.7.0-rc1-0.2",
156156
"@criptext/electron-push-receiver": "^2.1.3",

electron_app/src/clientManager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,14 @@ const postUser = async params => {
538538
return await client.postUser(params);
539539
};
540540

541+
const reencryptEmail = async ({ recipientId, metadataKey, eventid }) => {
542+
const client = await createClient({ recipientId });
543+
const res = await client.reencryptEmail({ metadataKey, eventid });
544+
return res.status === 200
545+
? res
546+
: await checkExpiredSession(res, resendConfirmationEmail, recipientId);
547+
};
548+
541549
const registerDomain = async ({ domain, recipientId }) => {
542550
const client = await createClient({ recipientId });
543551
const res = await client.registerDomain(domain);
@@ -805,6 +813,7 @@ module.exports = {
805813
postPeerEvent,
806814
pushPeerEvents,
807815
postUser,
816+
reencryptEmail,
808817
registerDomain,
809818
removeAvatar,
810819
removeDevice,

electron_app/src/ipc/client.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ ipc.answerRenderer('client-post-peer-event', params => {
162162
return clientManager.postPeerEvent(data);
163163
});
164164

165+
ipc.answerRenderer('client-reencrypt-email', params => {
166+
const data = params.recipientId
167+
? params
168+
: { ...params, recipientId: myAccount.recipientId };
169+
return clientManager.reencryptEmail(data);
170+
});
171+
165172
ipc.answerRenderer('client-register-domain', domain => {
166173
const data = { domain, recipientId: myAccount.recipientId };
167174
return clientManager.registerDomain(data);

electron_app/yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@
115115
lodash "^4.2.0"
116116
to-fast-properties "^2.0.0"
117117

118-
"@criptext/api@^0.17.0":
119-
version "0.17.0"
120-
resolved "https://registry.yarnpkg.com/@criptext/api/-/api-0.17.0.tgz#7bc102b7c2afd6d971ee3b51c27e20e145cb8c99"
121-
integrity sha512-w7jxkzxlKqM371wyXrO8YUkgph8RhU5IxYdMmL9L0hx0tdbLAko8DHjHlub7yO2OmStEOUyk7k/RqBfEawlntA==
118+
"@criptext/api@^0.17.1":
119+
version "0.17.1"
120+
resolved "https://registry.yarnpkg.com/@criptext/api/-/api-0.17.1.tgz#63e7f3cfc4c5d8fa10e0859c7017fb3acf0bc84c"
121+
integrity sha512-UWWU3eOR/a5lB7Od0mYUKUUPZ2EypAyFtc1Ps3Dcv7DJh1v4EZCcK1X69KonoSbqNjo0ymqYoCt2SaL8KaEENw==
122122
dependencies:
123123
superagent "^3.8.2"
124124

email_mailbox/src/components/SettingAccountWrapper.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ class SettingAccountWrapper extends Component {
150150
},
151151
changeRecoveryEmailPopupParams: {
152152
isDisabledSubmitButton: true,
153+
recoveryEmailConfirmed: props.recoveryEmailConfirmed,
153154
recoveryEmailInput: {
154155
name: 'recoveryEmailInput',
155156
type: 'text',
@@ -470,6 +471,8 @@ class SettingAccountWrapper extends Component {
470471
newState = {
471472
changeRecoveryEmailPopupParams: {
472473
isDisabledSubmitButton: true,
474+
recoveryEmailConfirmed: this.state.recoveryEmailParams
475+
.recoveryEmailConfirmed,
473476
recoveryEmailInput: {
474477
name: 'recoveryEmailInput',
475478
type: 'text',
@@ -1405,6 +1408,10 @@ class SettingAccountWrapper extends Component {
14051408
recoveryEmailParams: {
14061409
recoveryEmail: recoveryEmail,
14071410
recoveryEmailConfirmed: false
1411+
},
1412+
changeRecoveryEmailPopupParams: {
1413+
...this.state.changeRecoveryEmailPopupParams,
1414+
recoveryEmailConfirmed: false
14081415
}
14091416
});
14101417
};
@@ -1414,6 +1421,10 @@ class SettingAccountWrapper extends Component {
14141421
recoveryEmailParams: {
14151422
...this.state.recoveryEmailParams,
14161423
recoveryEmailConfirmed: true
1424+
},
1425+
changeRecoveryEmailPopupParams: {
1426+
...this.state.changeRecoveryEmailPopupParams,
1427+
recoveryEmailConfirmed: true
14171428
}
14181429
});
14191430
};

email_mailbox/src/components/SettingsPopup.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ const SettingsPopup = props => {
103103
recoveryEmailPopupInputPassword={
104104
props.changeRecoveryEmailPopupParams.recoveryEmailPasswordInput
105105
}
106+
recoveryEmailConfirmed={
107+
props.changeRecoveryEmailPopupParams.recoveryEmailConfirmed
108+
}
106109
theme={'dark'}
107110
/>
108111
);

email_mailbox/src/libs/signal.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ const decryptEmail = async ({
6262
throw new Error(ALICE_ERROR);
6363
} else if (res.status === 500) {
6464
const aliceError = await res.text();
65-
throw new Error(`${CONTENT_UNENCRYPTED} - ${aliceError}`);
65+
return {
66+
signalError: new Error(`${CONTENT_UNENCRYPTED} - ${aliceError}`)
67+
};
6668
} else if (res.status === 409) {
67-
throw new Error(DUPLICATE_MESSAGE);
69+
return {
70+
signalError: new Error(DUPLICATE_MESSAGE)
71+
};
6872
} else if (res.status !== 200) {
6973
throw new Error(ALICE_ERROR);
7074
}

email_mailbox/src/utils/electronEventInterface.js

Lines changed: 59 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import {
4141
getLabelByUuid,
4242
logoutApp,
4343
openFilledComposerWindow,
44+
reencryptEmail,
4445
reportContentUnencrypted,
4546
reportContentUnencryptedBob,
4647
restartConnection,
@@ -63,7 +64,8 @@ import {
6364
updateDeviceType,
6465
initAutoBackupMonitor,
6566
updateAccountDefaultAddress,
66-
createOrUpdateContact
67+
createOrUpdateContact,
68+
reportUncaughtError
6769
} from './ipc';
6870
import {
6971
checkEmailIsTo,
@@ -132,6 +134,8 @@ let profileHasChanged = false;
132134
let newEmailNotificationList = [];
133135
let deleteDataIntervalId = null;
134136

137+
const FATAL_ERROR = 1;
138+
135139
const stopGettingEvents = () => {
136140
isGettingEvents = false;
137141
emitter.emit(Event.STOP_LOAD_SYNC, {});
@@ -615,7 +619,8 @@ const formEmailIfNotExists = async params => {
615619
isSpam,
616620
recipients,
617621
guestEncryption,
618-
external
622+
external,
623+
rowid
619624
} = params;
620625

621626
const labelIds = [];
@@ -624,11 +629,7 @@ const formEmailIfNotExists = async params => {
624629
myFileKeys;
625630

626631
try {
627-
const {
628-
decryptedBody,
629-
decryptedHeaders,
630-
decryptedFileKeys
631-
} = await signal.decryptEmail({
632+
const decryptResult = await signal.decryptEmail({
632633
accountRecipientId,
633634
optionalToken,
634635
bodyKey: metadataKey,
@@ -637,37 +638,56 @@ const formEmailIfNotExists = async params => {
637638
messageType,
638639
fileKeys: fileKeys || (fileKey ? [fileKey] : null)
639640
});
640-
body = cleanEmailBody(decryptedBody);
641-
headers = decryptedHeaders;
642-
myFileKeys = decryptedFileKeys
643-
? decryptedFileKeys.map(fileKey => {
644-
const fileKeySplit = fileKey.split(':');
645-
return {
646-
key: fileKeySplit[0],
647-
iv: fileKeySplit[1]
648-
};
649-
})
650-
: null;
651-
} catch (e) {
652-
if (
653-
e.message === signal.ALICE_ERROR ||
654-
e.message === signal.CONTENT_NOT_AVAILABLE ||
655-
e instanceof TypeError
656-
) {
657-
return {
658-
error: 1
659-
};
660-
} else if (e.message === signal.DUPLICATE_MESSAGE) {
661-
return {
662-
error: 2
663-
};
664-
}
665-
body = 'Content unencrypted';
666-
if (external) {
667-
reportContentUnencryptedBob(e.stack);
641+
if (decryptResult.signalError) {
642+
if (external) {
643+
const reencryptRes = await reencryptEmail({
644+
metadataKey,
645+
eventid: rowid,
646+
recipientId: accountRecipientId
647+
});
648+
if (!reencryptRes) return { error: FATAL_ERROR };
649+
650+
switch (reencryptRes.status) {
651+
case 200:
652+
return {
653+
error: FATAL_ERROR
654+
};
655+
case 429:
656+
reportContentUnencryptedBob(decryptResult.signalError);
657+
break;
658+
default:
659+
return {
660+
error: FATAL_ERROR
661+
};
662+
}
663+
body = 'Content unencrypted';
664+
} else {
665+
reportContentUnencrypted(decryptResult.signalError);
666+
body = 'Content unencrypted';
667+
}
668668
} else {
669-
reportContentUnencrypted(e.stack);
669+
const {
670+
decryptedBody,
671+
decryptedHeaders,
672+
decryptedFileKeys
673+
} = decryptResult;
674+
body = cleanEmailBody(decryptedBody);
675+
headers = decryptedHeaders;
676+
myFileKeys = decryptedFileKeys
677+
? decryptedFileKeys.map(fileKey => {
678+
const fileKeySplit = fileKey.split(':');
679+
return {
680+
key: fileKeySplit[0],
681+
iv: fileKeySplit[1]
682+
};
683+
})
684+
: null;
670685
}
686+
} catch (e) {
687+
reportUncaughtError(e.stack);
688+
return {
689+
error: FATAL_ERROR
690+
};
671691
}
672692

673693
if (!fileKeys && fileKey) {
@@ -881,7 +901,8 @@ const handleNewMessageEvent = async (
881901
isSpam,
882902
recipients,
883903
guestEncryption,
884-
external
904+
external,
905+
rowid
885906
})
886907
: await formEmailIfExists({
887908
accountId,
@@ -894,7 +915,7 @@ const handleNewMessageEvent = async (
894915

895916
if (error) {
896917
return {
897-
rowid: error === 1 ? null : rowid
918+
rowid: error === FATAL_ERROR ? null : rowid
898919
};
899920
}
900921

email_mailbox/src/utils/ipc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,10 @@ export const postPeerEvent = async params => {
226226
return await ipc.callMain('client-post-peer-event', params);
227227
};
228228

229+
export const reencryptEmail = async params => {
230+
return await ipc.callMain('client-reencrypt-email', params);
231+
};
232+
229233
export const registerDomain = async domain => {
230234
return await ipc.callMain('client-register-domain', domain);
231235
};

0 commit comments

Comments
 (0)