change representation of public key in db to hex string + create room

This commit is contained in:
2025-02-21 19:16:50 +01:00
parent da4f74b60c
commit 4d68e7a9f7
11 changed files with 239 additions and 90 deletions

View File

@@ -1,5 +1,6 @@
const crypto = require('crypto');
const database = require("../db");
const stringutils = require("../stringutils");
const authentication = require("../authentication");
const socket = require('../socket').default;
@@ -10,9 +11,9 @@ const accountController = {
if (!sharedSecret || !publicKey) {
return res.status(400).json({ error: "Missing sharedSecret or publicKey" });
}
console.log('Received data:', { sharedSecret, publicKey });
if (authentication.checkSharedSecret(sharedSecret)) {
database.addUser(publicKey);
let pubkey = stringutils.pemToHex(publicKey)
database.addUser(pubkey);
} else {
return res.status(400).json({ error: "Wrong sharedSecret" });
}

View File

@@ -1 +1,20 @@
const database = require("../db");
const stringutils = require("../stringutils");
const chatController = {
add: async (req, res) => {
try {
const { pubkey } = req.body;
if (!pubkey) {
return res.status(400).json({ error: "Missing publicKey" });
}
await database.createRoom(req.session.publicKey, stringutils.pemToHex(pubkey));
return res.status(201).json({ message: "Room created successfully." });
} catch (error) {
console.error("Error creating the room:", error);
return res.status(500).json({ error: "Failed to create the room" });
}
},
}
module.exports = chatController;

View File

@@ -1,39 +1,13 @@
const path = require('path');
const stringutils = require("../stringutils");
const mainController = {
root: (req, res) => {
let pubKey = req.session.publicKey;
console.log(pubKey);
let isLoggedIn = typeof pubKey !== 'undefined';
let pubKeyHex = req.session.publicKey;
let isLoggedIn = typeof pubKeyHex !== 'undefined';
let pubKey = isLoggedIn ? stringutils.hexToPem(pubKeyHex).replaceAll('\n','') : null;
res.render('index', {isLoggedIn, pubKey});
},
// style: (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/style.css'));
// },
// script: (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/script.js'));
// },
// ecc: (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/ecc.js'));
// },
// ecdh: (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/ecdh.js'));
// },
// popups: (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/popups.js'));
// },
// chat : (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/chat.js'));
// },
// register : (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/register.js'));
// },
// pubkey : (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/pubkey.js'));
// },
// registertext : (req, res) => {
// res.sendFile(path.resolve(__dirname + '/../public/registertext.js'));
// }
}
};
module.exports = mainController;