Raised key size and added creategroup button

This commit is contained in:
Inbestigator 2024-03-02 03:17:57 -08:00
parent f2c9f59f7a
commit 0ed92fdc17
2 changed files with 18 additions and 5 deletions

View file

@ -26,7 +26,6 @@ import { Message } from "discord-types/general";
const MessageCreator = findByPropsLazy("createBotMessage"); const MessageCreator = findByPropsLazy("createBotMessage");
const CloudUtils = findByPropsLazy("CloudUpload"); const CloudUtils = findByPropsLazy("CloudUpload");
import { getCurrentChannel } from "@utils/discord"; import { getCurrentChannel } from "@utils/discord";
import forge from 'node-forge';
let enabled; let enabled;
let setEnabled; let setEnabled;
@ -83,7 +82,17 @@ const ChatBarIcon: ChatBarButton = ({ isMainChat }) => {
if (await DataStore.get('encryptcordGroup') == false) { if (await DataStore.get('encryptcordGroup') == false) {
await startGroup("", { channel: { id: getCurrentChannel().id } }); await startGroup("", { channel: { id: getCurrentChannel().id } });
} else if (getCurrentChannel().id !== groupChannel) { } else if (getCurrentChannel().id !== groupChannel) {
sendBotMessage(getCurrentChannel().id, { content: `You must be in <#${groupChannel}> to send an encrypted message!`, author: { username: "false" } }); sendBotMessage(getCurrentChannel().id, {
content: `You are already in an encrypted group in <#${groupChannel}>.\n> Would you like to create a new one?`, components: [{
type: 1,
components: [{
type: 2,
style: 3,
label: 'Yes',
custom_id: 'createGroup'
}]
}]
});
return; return;
} }
setEnabled(!enabled); setEnabled(!enabled);
@ -136,7 +145,7 @@ export default definePlugin({
], ],
async joinGroup(interaction) { async joinGroup(interaction) {
const sender = await UserUtils.getUser(interaction.application_id).catch(() => null); const sender = await UserUtils.getUser(interaction.application_id).catch(() => null);
if (!sender || sender.bot == true) return; if (!sender || (sender.bot == true && sender.id != "1")) return;
if (interaction.data.component_type != 2) return; if (interaction.data.component_type != 2) return;
switch (interaction.data.custom_id) { switch (interaction.data.custom_id) {
case "acceptGroup": case "acceptGroup":
@ -158,6 +167,10 @@ export default definePlugin({
mlDeleted: true mlDeleted: true
}); });
break; break;
case "createGroup":
await leave("", { channel: { id: interaction.channel_id } });
await startGroup("", { channel: { id: interaction.channel_id } });
break;
default: default:
return; return;
} }

View file

@ -2,7 +2,7 @@ export const generateKeys = async () => {
const keyPair = await crypto.subtle.generateKey( const keyPair = await crypto.subtle.generateKey(
{ {
name: "RSA-OAEP", name: "RSA-OAEP",
modulusLength: 2048, modulusLength: 4096,
publicExponent: new Uint8Array([1, 0, 1]), publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256", hash: "SHA-256",
}, },
@ -19,7 +19,7 @@ export const generateKeys = async () => {
export const encryptData = async (pemPublicKey, data) => { export const encryptData = async (pemPublicKey, data) => {
const publicKey = await importPemPublicKey(pemPublicKey); const publicKey = await importPemPublicKey(pemPublicKey);
const chunkSize = 190; const chunkSize = 446;
const encryptedChunks: any[] = []; const encryptedChunks: any[] = [];
const encoder = new TextEncoder(); const encoder = new TextEncoder();