refactor: fully working E2EE

small issue to fix. when full response is received it replaces the text with the text from the DB. and then the decryption is not yet implement.
This commit is contained in:
Ruben Talstra 2025-02-15 23:04:26 +01:00
parent 18d019d8b3
commit 94d32906f1
No known key found for this signature in database
GPG key ID: 2A5A7174A60F3BEA
11 changed files with 343 additions and 189 deletions

View file

@ -167,17 +167,20 @@ const updateUserEncryptionController = async (req, res) => {
try {
const { encryptionPublicKey, encryptedPrivateKey, encryptionSalt, encryptionIV } = req.body;
// Validate required parameters
if (!encryptionPublicKey || !encryptedPrivateKey || !encryptionSalt || !encryptionIV) {
// Allow disabling encryption by passing null for all fields.
const allNull = encryptionPublicKey === null && encryptedPrivateKey === null && encryptionSalt === null && encryptionIV === null;
const allPresent = encryptionPublicKey && encryptedPrivateKey && encryptionSalt && encryptionIV;
if (!allNull && !allPresent) {
return res.status(400).json({ message: 'Missing encryption parameters.' });
}
// Use the helper function to update the user.
// Update the user record with the provided encryption parameters (or null to disable)
const updatedUser = await updateUser(req.user.id, {
encryptionPublicKey,
encryptedPrivateKey,
encryptionSalt,
encryptionIV,
encryptionPublicKey: encryptionPublicKey || null,
encryptedPrivateKey: encryptedPrivateKey || null,
encryptionSalt: encryptionSalt || null,
encryptionIV: encryptionIV || null,
});
if (!updatedUser) {