diff --git a/app/file/page.tsx b/app/file/page.tsx
index 758fc76..3b6a03f 100644
--- a/app/file/page.tsx
+++ b/app/file/page.tsx
@@ -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'
@@ -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);
diff --git a/app/msg/[...data]/page.tsx b/app/msg/[...data]/page.tsx
index a914509..5c4e380 100644
--- a/app/msg/[...data]/page.tsx
+++ b/app/msg/[...data]/page.tsx
@@ -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[] } }) {
@@ -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);
diff --git a/app/msg/page.tsx b/app/msg/page.tsx
index 682a94d..7898b63 100644
--- a/app/msg/page.tsx
+++ b/app/msg/page.tsx
@@ -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'
@@ -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 = '
';
- 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 = '';
+
+ 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 (
diff --git a/package-lock.json b/package-lock.json
index a2cabb1..0125a1d 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "solun",
- "version": "0.1.1",
+ "version": "0.1.2",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "solun",
- "version": "0.1.1",
+ "version": "0.1.2",
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.4.0",
"@fortawesome/free-solid-svg-icons": "^6.4.0",
@@ -5002,9 +5002,9 @@
}
},
"node_modules/solun-general-package": {
- "version": "1.0.19",
- "resolved": "https://registry.npmjs.org/solun-general-package/-/solun-general-package-1.0.19.tgz",
- "integrity": "sha512-HRGQ6Jio4W6K/Q1p5n8oENJuIQH7TCtiakbZKAInGD8ZVu8HAqRd+dvokrb47+xmp43nSqHl4LezqX0ZUmGwGA==",
+ "version": "1.0.20",
+ "resolved": "https://registry.npmjs.org/solun-general-package/-/solun-general-package-1.0.20.tgz",
+ "integrity": "sha512-vWazoTOjMujaaQsRlszJqUqaljF43O2d6KQ1o5ZJtiSTDNp0e7F/4eoamdF/BZiZogqa2xZGDnQcASua2pfZqQ==",
"dependencies": {
"bcryptjs": "^2.4.3",
"cross-fetch": "^3.1.6",
@@ -5014,9 +5014,9 @@
}
},
"node_modules/solun-server-encryption-package": {
- "version": "1.0.5",
- "resolved": "https://registry.npmjs.org/solun-server-encryption-package/-/solun-server-encryption-package-1.0.5.tgz",
- "integrity": "sha512-TP99P+s99cWNyGCKPeM0R2/LeehqOCm1GXRuH7arImj9FZgxxPOPzCR6ko1j0wRt+cmhRRLVTH8SQVl3Z3DuGg==",
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/solun-server-encryption-package/-/solun-server-encryption-package-1.0.6.tgz",
+ "integrity": "sha512-1wGj/Jlid2k5txnDSGQSF0Sdw8jp84QlcwdnEDQ9KbS2RCCekv6+Hu5CX2+mnW2CRzreSS/txUKbqlhjIcgjqQ==",
"dependencies": {
"bcryptjs": "^2.4.3",
"cross-fetch": "^3.1.6",
diff --git a/package.json b/package.json
index 991d0ba..88294e9 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "solun",
- "version": "0.1.1",
+ "version": "0.1.2",
"private": true,
"scripts": {
"dev": "next dev",