Skip to content

Commit

Permalink
Merge pull request #77 from solun-pm/dev
Browse files Browse the repository at this point in the history
Added better client side message and file pwd encryption
  • Loading branch information
DanielWTE authored Jun 22, 2023
2 parents ebbbff3 + d115dac commit dd1bc48
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 64 deletions.
10 changes: 4 additions & 6 deletions app/file/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { generateAES, generateID, generatePassword, encryptTransfer } from 'solun-general-package';
import { generateAES, generateID, generatePassword, encryptTransfer, hashPassword } from 'solun-general-package';

import { useState, useEffect } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
Expand Down Expand Up @@ -112,17 +112,15 @@ function UploadFile() {
const password = target.password.value;
const endToEndEncryption = target.endToEndEncryption.checked;

let tmpEncryptPwd = '' as any;
if(password !== '') {
tmpEncryptPwd = await encryptTransfer(password);
}
const passwordSet = password !== "";
const encrypted_password = passwordSet ? await hashPassword(password) : null;


if (files.length > 0) {
const formData = new FormData();
formData.append('file', files[0]);
formData.append('bruteforceSafe', bruteforceSafe.toString());
formData.append('password', tmpEncryptPwd);
formData.append('password', encrypted_password);
formData.append('endToEndEncryption', endToEndEncryption.toString());
formData.append('autoDeletion', target.autoDeletion.value);

Expand Down
7 changes: 5 additions & 2 deletions app/msg/[...data]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useRouter } from "next/navigation";
import toast, { Toaster } from 'react-hot-toast';
import Header from '@/components/header'
import Footer from '@/components/footer'
import { decrypt } from 'solun-general-package';

function ViewMessage({ params }: { params: { data: string[] } }) {

Expand Down Expand Up @@ -82,9 +83,11 @@ function ViewMessage({ params }: { params: { data: string[] } }) {
});
const result = await res.json();
if (!res.ok) {
setError(result.message);
toast.error(result.message);
} else {
setMessage(result.message);
const serect_key = result.secret || secretKey;
const decryptedMessage = await decrypt(result.message, serect_key);
setMessage(decryptedMessage);
setShowMessage(true);

await deleteMessage(id);
Expand Down
99 changes: 52 additions & 47 deletions app/msg/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { encryptTransfer, generateAES, generateID, generatePassword } from 'solun-general-package';
import { generateAES, generateID, generatePassword, encrypt, hashPassword } from 'solun-general-package';

import { useState, useEffect } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
Expand Down Expand Up @@ -80,57 +80,62 @@ function CreateMessage() {
handlePasswordChange({target: {value: generatedPassword}});
};

const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const target = e.target as typeof e.target & {
message: { value: string };
bruteforceSafe: { checked: boolean };
password: { value: string };
endToEndEncryption: { checked: boolean };
};
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
const target = e.target as typeof e.target & {
message: { value: string };
bruteforceSafe: { checked: boolean };
password: { value: string };
endToEndEncryption: { checked: boolean };
};

// Set Button disabled and add loading animation and text "Creating Message"
const submitButton = document.getElementById('submit') as HTMLButtonElement;
const message = target.message.value;
const submitButton = document.getElementById('submit') as HTMLButtonElement;
const message_text = target.message.value;

if(message === '') {
toast.error('Please enter a message');
} else {
submitButton.disabled = true;
submitButton.innerHTML = '<div class="flex items-center"><svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg><span class="text-white">Creating</span></div>';
const bruteforceSafe = target.bruteforceSafe.checked;
const password = target.password.value;
const endToEndEncryption = target.endToEndEncryption.checked;
if(message_text === '') {
toast.error('Please enter a message');
} else {
submitButton.disabled = true;
submitButton.innerHTML = '<div class="flex items-center"><svg class="animate-spin -ml-1 mr-3 h-5 w-5 text-white" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"></circle><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg><span class="text-white">Creating</span></div>';

const bruteforceSafe = target.bruteforceSafe.checked;
const password = target.password.value;
const endToEndEncryption = target.endToEndEncryption.checked;

const mid = await generateID(bruteforceSafe);
const secret_key = await generateAES();
const encrypted_message = await encrypt(message_text, secret_key as string);

const passwordSet = password !== "";
const encrypted_password = passwordSet ? await hashPassword(password) : null;

const tmpEncryptMsg = await encryptTransfer(message);
let tmpEncryptPwd = '' as any;
if(password !== '') {
tmpEncryptPwd = await encryptTransfer(password);
}
const dbSecretKey = endToEndEncryption ? null : secret_key;

const data = {
tmpEncryptMsg,
bruteforceSafe,
tmpEncryptPwd,
endToEndEncryption
};
const res = await fetch(process.env.NEXT_PUBLIC_API_DOMAIN + '/message/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
})
const result = await res.json();
if(!res.ok) {
toast.error('There was an error creating your message');
submitButton.disabled = false;
submitButton.innerHTML = 'Create';
} else {
setMessageCreated(true);
setMessageLink(result.link);
}
const data = {
mid,
encrypted_message,
dbSecretKey,
encrypted_password
};

const res = await fetch(process.env.NEXT_PUBLIC_API_DOMAIN + '/message/create', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data),
})

const result = await res.json();
if(!res.ok) {
toast.error('There was an error creating your message');
submitButton.disabled = false;
submitButton.innerHTML = 'Create';
} else {
setMessageCreated(true);
setMessageLink(result.link);
}
}
};

return (
Expand Down
16 changes: 8 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solun",
"version": "0.1.1",
"version": "0.1.2",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down

0 comments on commit dd1bc48

Please sign in to comment.