Make sure we don't send public keys encrypted

This commit is contained in:
Jiiks 2018-08-14 10:44:57 +03:00
parent 8d6cdafc23
commit b1f0a4247a
2 changed files with 1 additions and 18 deletions

View File

@ -141,6 +141,7 @@ export default new class E2EE extends BuiltinModule {
// We already sent our key
if (!this.ecdhStorage.hasOwnProperty(channelId)) {
const publicKeyMessage = `\`\`\`\n-----BEGIN PUBLIC KEY-----\n${this.createKeyExchange(channelId)}\n-----END PUBLIC KEY-----\n\`\`\``;
if (this.encryptNewMessages) this.encryptNewMessages = false;
WebpackModules.getModuleByName('DraftActions').saveDraft(channelId, publicKeyMessage);
}
const secret = this.computeSecret(channelId, key);

View File

@ -30,7 +30,6 @@
<div v-close-popover @click="showUploadDialog" v-if="!error"><MiImagePlus size="16" v-tooltip="'Upload Encrypted Image'" /></div>
<!-- Using these icons for now -->
<div v-close-popover @click="generatePublicKey" v-if="DiscordApi.currentChannel.type === 'DM'"><MiPencil size="16" v-tooltip="'Generate Public Key'" /></div>
<div v-close-popover @click="receivePublicKey" v-if="DiscordApi.currentChannel.type === 'DM' && E2EE.ecdhStorage[DiscordApi.currentChannel.id]"><MiRefresh size="16" v-tooltip="'Receive Public Key'" /></div>
</template>
</v-popover>
<div class="bd-taDivider"></div>
@ -97,23 +96,6 @@
const publicKeyMessage = `\`\`\`\n-----BEGIN PUBLIC KEY-----\n${keyExchange}\n-----END PUBLIC KEY-----\n\`\`\``;
WebpackModules.getModuleByName('DraftActions').saveDraft(DiscordApi.currentChannel.id, publicKeyMessage);
Toasts.info('Key exhange started. Expires in 30 seconds');
},
receivePublicKey() {
try {
const dmChannelID = DiscordApi.currentChannel.id;
const chatInput = document.getElementsByClassName('da-textArea')[0];
const otherPublicKey = chatInput.value;
const secret = E2EE.computeSecret(dmChannelID, otherPublicKey);
E2EE.setKey(dmChannelID, secret);
chatInput.value = "";
const evt = { currentTarget: chatInput };
chatInput[Object.keys(chatInput).find(k => k.startsWith('__reactEventHandlers'))].onChange.call(chatInput, evt);
Toasts.success("Encryption key has been set for this DM channel.");
this.$forceUpdate();
} catch (e) {
Toasts.error("Invalid public key. Please set up a new key exchange.");
console.error(e);
}
}
},
mounted() {