Secure key exchange for DMs.
This commit is contained in:
parent
c122457565
commit
7e41fe73e7
|
@ -62,6 +62,16 @@ export default new class E2EE extends BuiltinModule {
|
||||||
return haveKey.value.value;
|
return haveKey.value.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setKey(channelId, key) {
|
||||||
|
const items = Settings.getSetting('security', 'e2eedb', 'e2ekvps').items;
|
||||||
|
const index = items.findIndex(kvp => kvp.value.key === channelId);
|
||||||
|
if (index > -1) {
|
||||||
|
items[index].value = {key: channelId, value: key};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Settings.getSetting('security', 'e2eedb', 'e2ekvps').addItem({ value: { key: channelId, value: key } });
|
||||||
|
}
|
||||||
|
|
||||||
async enabled(e) {
|
async enabled(e) {
|
||||||
this.patchDispatcher();
|
this.patchDispatcher();
|
||||||
this.patchMessageContent();
|
this.patchMessageContent();
|
||||||
|
@ -79,7 +89,7 @@ export default new class E2EE extends BuiltinModule {
|
||||||
|
|
||||||
const key = this.getKey(event.message.channel_id);
|
const key = this.getKey(event.message.channel_id);
|
||||||
if (!key) return; // We don't have a key for this channel
|
if (!key) return; // We don't have a key for this channel
|
||||||
|
|
||||||
if (typeof event.message.content !== 'string') return; // Ignore any non string content
|
if (typeof event.message.content !== 'string') return; // Ignore any non string content
|
||||||
if (!event.message.content.startsWith('$:')) return; // Not an encrypted string
|
if (!event.message.content.startsWith('$:')) return; // Not an encrypted string
|
||||||
let decrypt;
|
let decrypt;
|
||||||
|
@ -91,10 +101,10 @@ export default new class E2EE extends BuiltinModule {
|
||||||
const Permissions = WebpackModules.getModuleByName('GuildPermissions');
|
const Permissions = WebpackModules.getModuleByName('GuildPermissions');
|
||||||
const DiscordConstants = WebpackModules.getModuleByName('DiscordConstants');
|
const DiscordConstants = WebpackModules.getModuleByName('DiscordConstants');
|
||||||
const currentChannel = DiscordApi.Channel.fromId(event.message.channel_id).discordObject;
|
const currentChannel = DiscordApi.Channel.fromId(event.message.channel_id).discordObject;
|
||||||
|
|
||||||
// Create a generic message object to parse mentions with
|
// Create a generic message object to parse mentions with
|
||||||
const parsed = MessageParser.parse(currentChannel, decrypt).content;
|
const parsed = MessageParser.parse(currentChannel, decrypt).content;
|
||||||
|
|
||||||
if (userMentionPattern.test(parsed))
|
if (userMentionPattern.test(parsed))
|
||||||
event.message.mentions = parsed.match(userMentionPattern).map(m => {return {id: m.replace(/[^0-9]/g, '')}});
|
event.message.mentions = parsed.match(userMentionPattern).map(m => {return {id: m.replace(/[^0-9]/g, '')}});
|
||||||
if (roleMentionPattern.test(parsed))
|
if (roleMentionPattern.test(parsed))
|
||||||
|
@ -122,7 +132,7 @@ export default new class E2EE extends BuiltinModule {
|
||||||
const Permissions = WebpackModules.getModuleByName('GuildPermissions');
|
const Permissions = WebpackModules.getModuleByName('GuildPermissions');
|
||||||
const DiscordConstants = WebpackModules.getModuleByName('DiscordConstants');
|
const DiscordConstants = WebpackModules.getModuleByName('DiscordConstants');
|
||||||
const currentChannel = DiscordApi.Channel.fromId(component.props.message.channel_id).discordObject;
|
const currentChannel = DiscordApi.Channel.fromId(component.props.message.channel_id).discordObject;
|
||||||
|
|
||||||
if (typeof component.props.message.content !== 'string') return; // Ignore any non string content
|
if (typeof component.props.message.content !== 'string') return; // Ignore any non string content
|
||||||
if (!component.props.message.content.startsWith('$:')) return; // Not an encrypted string
|
if (!component.props.message.content.startsWith('$:')) return; // Not an encrypted string
|
||||||
let decrypt;
|
let decrypt;
|
||||||
|
|
|
@ -37,23 +37,31 @@
|
||||||
import { MiLock } from '../ui/components/common/MaterialIcon';
|
import { MiLock } from '../ui/components/common/MaterialIcon';
|
||||||
import contextMenu from 'vue-context-menu';
|
import contextMenu from 'vue-context-menu';
|
||||||
import { clipboard } from 'electron';
|
import { clipboard } from 'electron';
|
||||||
|
import { Toasts } from 'ui';
|
||||||
|
|
||||||
function generatePublicKey() {
|
function generatePublicKey() {
|
||||||
const userID = location.pathname.split("/")[3];
|
const dmChannelID = location.pathname.split("/")[3];
|
||||||
const publicKeyMessage = `My public key is: \`${E2EE.createKeyExchange(userID)}\`. Please give me your public key if you haven't done so and add my public key by pasting it in the chat textbox, right clicking the lock icon, and selecting \`Receive Public Key\`.`;
|
const publicKeyMessage = `My public key is: \`${E2EE.createKeyExchange(dmChannelID)}\`. Please give me your public key if you haven't done so and add my public key by pasting it in the chat textbox, right clicking the lock icon, and selecting \`Receive Public Key\`.`;
|
||||||
const chatInput = document.getElementsByClassName('da-textArea')[0];
|
const chatInput = document.getElementsByClassName('da-textArea')[0];
|
||||||
chatInput.value = publicKeyMessage;
|
chatInput.value = publicKeyMessage;
|
||||||
chatInput._valueTracker.setValue(publicKeyMessage);
|
const evt = { currentTarget: chatInput };
|
||||||
chatInput[Object.keys(chatInput).find(k => k.startsWith('__reactInternalInstance'))].memoizedProps.value = publicKeyMessage;
|
chatInput[Object.keys(chatInput).find(k => k.startsWith('__reactEventHandlers'))].onChange.call(chatInput, evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
function computeSharedSecret() {
|
function computeSharedSecret() {
|
||||||
try {
|
try {
|
||||||
const userID = location.pathname.split("/")[3];
|
const dmChannelID = location.pathname.split("/")[3];
|
||||||
const otherPublicKey = document.getElementsByClassName("da-textArea")[0].value;
|
const chatInput = document.getElementsByClassName('da-textArea')[0];
|
||||||
const secret = E2EE.computeSecret(userID, otherPublicKey);
|
const otherPublicKey = chatInput.value;
|
||||||
clipboard.writeText(secret);
|
const secret = E2EE.computeSecret(dmChannelID, otherPublicKey);
|
||||||
} catch (e) {}
|
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.");
|
||||||
|
} catch (e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
|
@ -53,7 +53,8 @@
|
||||||
.bd-e2eeLockContextMenuOption {
|
.bd-e2eeLockContextMenuOption {
|
||||||
background: #23272A;
|
background: #23272A;
|
||||||
color: #99AAB5;
|
color: #99AAB5;
|
||||||
padding: 5px 5px;
|
padding: 8px 8px;
|
||||||
|
font-weight: 500;
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
|
|
Loading…
Reference in New Issue