Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add encryption information (#341)
Leendert de Borst9e24442d845f
diff --git a/ENCRYPTION.md b/ENCRYPTION.mdindex e877befab..83612f4f8 100644--- a/ENCRYPTION.md+++ b/ENCRYPTION.md@@ -1,13 +1,92 @@-# Encryption-This document describes the encryption used in AliasVault.+# ENCRYPTION.md+This document describes the encryption algorithms used by AliasVault in order to keep its user data secure.-## SRP-The application uses the Secure Remote Password (SRP) protocol for authentication. The SRP protocol is a password-authenticated key agreement protocol. This means that the client and server can authenticate each other using a password, without sending the password over the network.+## Overview+AliasVault is built with a [zero-knowledge architecture](https://en.wikipedia.org/wiki/Zero-knowledge_service) and uses a combination of encryption algorithms to protect the users data which are stored in vaults.++The basic premise is that the master password chosen by the user upon registration forms the basis for all encryption+and decryption operations. This master password is never transmitted over the network and only resides on the client.+All data is encrypted at rest and in transit. This ensures that even if the AliasVault servers are compromised,+the user's data remains secure.++## Encryption algorithms+The following encryption algorithms are used by AliasVault:++- [SRP](#srp)+- [Argon2id](#argon2id)+- [AES-GCM](#aes-gcm)+- [RSA-OAEP](#rsa-oaep)++### SRP+The Secure Remote Password (SRP) protocol is used for authenticating a user with the AliasVault server during login.+The SRP protocol is a password-authenticated key exchange protocol (PAKE). This means that the client and server can+authenticate each other using a password, without sending the password itself over the network.++With the use of SRP the master password never leaves the client. The client sends a verifier to the server,+which is a value derived from the master password. The server uses this verifier to authenticate the client without+having ever seen the actual master password.++For more information see the [SRP protocol](https://en.wikipedia.org/wiki/Secure_Remote_Password_protocol) information on Wikipedia.++### Argon2id+To derive a key from the master password, AliasVault uses the Argon2id key derivation function. Argon2id is a memory-hard+key derivation function which allows for controlling the execution time, memory required and degree of parallelism.+This makes it resilient against brute-force attacks and makes it one of the best choices for deriving keys from passwords.++AliasVault uses Argon2id with the following default parameters:+- Degree of parallelism: 1+- Memory size: 19456 KB+- Iterations: 2++More information about Argon2id can be found on the [Argon2](https://en.wikipedia.org/wiki/Argon2) Wikipedia page.++### AES-256-GCM+All user's vault data is fully encrypted on the client using the AES-256-GCM encryption algorithm, which stands for+*Advanced Encryption Standard with 256-bit key in Galois/Counter Mode*. The key for encryption is derived from the+master password by using the Argon2Id algorithm. AliasVault implements AES-GCM with the following specifications:++- Key Size: 256 bits+- Uses the Web Crypto API's SubtleCrypto interface for secure cryptographic operations+- Generates a random 12-byte (96-bit) IV (initialization vector) for each encryption operation+- Performs all encryption/decryption operations entirely in the browser++#### The encryption process works as follows:+- A unique IV is generated for each encryption operation+- The users vault data is encrypted using AES-GCM with the derived key and IV+- The IV is prepended to the ciphertext++More information about AES-GCM can be found on the [AES-GCM](https://en.wikipedia.org/wiki/Galois/Counter_Mode) Wikipedia page.++### RSA-OAEP+To secure email communications, AliasVault uses RSA-OAEP (RSA with Optimal Asymmetric Encryption Padding). This asymmetric+encryption system allows AliasVault to store emails on the server in encrypted state which can only be read by the+intended recipient. AliasVault implements RSA-OAEP with the following specifications:+- Algorithm: RSA-OAEP with SHA-256 hash+- Key Size: 2048-bit modulus+- Key Format: JWK (JSON Web Key)+- Padding: OAEP (Optimal Asymmetric Encryption Padding)++#### Email Security Flow+1. Key Generation: When a user creates a vault, a RSA key pair is generated:+ - A private key that remains in the encrypted user's vault and is never transmitted+ - A public key that is sent to the server++2. Email Reception Process: When an email arrives at the AliasVault email server:+ - The server encrypts the email content using the recipient's public key+ - The encrypted email is stored in the server's database+ - The original email content is never stored or logged++3. Email Retrieval Process:+ - When a user accesses their emails, the encrypted content is retrieved from the server+ - The client-side application decrypts the email using the user's private key that is stored in their vault+ - Decryption occurs entirely in the browser, maintaining end-to-end encryption++This implementation ensures that:+- Emails are encrypted and secure at rest in the server database+- Only the intended recipient that holds the private key can decrypt and read their emails+- Even if the server is compromised, email contents remain encrypted and unreadable++More information about RSA-OAEP can be found on the [RSA-OAEP](https://en.wikipedia.org/wiki/Optimal_asymmetric_encryption_padding) Wikipedia page.-With the use of SRP the master password never leaves the client. The client sends a verifier to the server, which is a value derived from the master password. The server uses this verifier to authenticate the client. With this the server can authenticate the client without having ever seen the actual master password.-## Argon2id-The application uses the Argon2id key derivation function to derive a key from the master password. Argon2id is a memory-hard function, which makes it difficult to perform large-scale custom hardware attacks. This makes it a good choice for password hashing.-## AES-AES-256 IV is used to encrypt the data. The data is encrypted with a key derived from the master password using Argon2id. The Initialization Vector (IV) is generated randomly for each encryption.diff --git a/src/AliasVault.Client/wwwroot/js/crypto.js b/src/AliasVault.Client/wwwroot/js/crypto.jsindex 11712a5aa..01a5b8593 100644--- a/src/AliasVault.Client/wwwroot/js/crypto.js+++ b/src/AliasVault.Client/wwwroot/js/crypto.js@@ -7,7 +7,10 @@ window.cryptoInterop = {const key = await window.crypto.subtle.importKey("raw",Uint8Array.from(atob(base64Key), c => c.charCodeAt(0)),- { name: "AES-GCM" },+ {+ name: "AES-GCM",+ length: 256,+ },false,["encrypt"]);@@ -36,7 +39,10 @@ window.cryptoInterop = {const key = await window.crypto.subtle.importKey("raw",Uint8Array.from(atob(base64Key), c => c.charCodeAt(0)),- { name: "AES-GCM" },+ {+ name: "AES-GCM",+ length: 256,+ },false,["decrypt"]);diff --git a/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs b/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.csindex 11bda9e82..06ee378c5 100644--- a/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs+++ b/src/Services/AliasVault.SmtpService/Handlers/DatabaseMessageStore.cs@@ -87,7 +87,7 @@ public class DatabaseMessageStore(ILogger<DatabaseMessageStore> logger, Config c}}- /// <summary>+ /// <summary>/// Load the email message from the buffer./// </summary>/// <param name="buffer">Buffer which contains the email contents.</param>diff --git a/src/Utilities/Cryptography/AliasVault.Cryptography.Server/Encryption.cs b/src/Utilities/Cryptography/AliasVault.Cryptography.Server/Encryption.csindex 873d4a086..d3ca7946f 100644--- a/src/Utilities/Cryptography/AliasVault.Cryptography.Server/Encryption.cs+++ b/src/Utilities/Cryptography/AliasVault.Cryptography.Server/Encryption.cs@@ -56,15 +56,14 @@ public static class Encryption/// <returns>The encrypted symmetric key as a base64-encoded string.</returns>public static byte[] DecryptSymmetricKeyWithRsa(string ciphertext, string privateKey){- using (var rsa = RSA.Create())- {- ImportPrivateKey(rsa, privateKey);- rsa.KeySize = 2048;- var rsaParams = RSAEncryptionPadding.OaepSHA256;+ using var rsa = RSA.Create();- byte[] cipherBytes = Convert.FromBase64String(ciphertext);- return rsa.Decrypt(cipherBytes, rsaParams);- }+ ImportPrivateKey(rsa, privateKey);+ rsa.KeySize = 2048;+ var rsaParams = RSAEncryptionPadding.OaepSHA256;++ byte[] cipherBytes = Convert.FromBase64String(ciphertext);+ return rsa.Decrypt(cipherBytes, rsaParams);}/// <summary>