Privacy-first password manager with built-in email aliasing. Fully encrypted and self-hostable.
Add security architecture documentation and diagrams (#341)
Leendert de Borst32bb4502d628
diff --git a/.gitignore b/.gitignoreindex fd788b467..87b3c8b5e 100644--- a/.gitignore+++ b/.gitignore@@ -374,14 +374,21 @@ FodyWeavers.xsd# Codebuddy Rider plugin.codebuddy-# AliasVault specific+# -------------------+# AliasVault specifics+# -------------------# index.html is generated by the build process from index.template.html and therefore should be ignoredsrc/AliasVault.Client/wwwroot/index.html+# appsettings.Development.json is generated by the build process from appsettings.Development.template.json and therefore should be ignoredsrc/AliasVault.Client/wwwroot/appsettings.Development.json+# appsettings.Development.json is added manually if needed, it should not be committed.src/Tests/AliasVault.E2ETests/appsettings.Development.json# .env is generated by install.sh and therefore should be ignored.env+# Draw.io diagram temp files+*.drawio.bkp+diff --git a/docs/architecture.md b/docs/architecture.mddeleted file mode 100644index 33b329e8a..000000000--- a/docs/architecture.md+++ /dev/null@@ -1,11 +0,0 @@-# AliasVault architecture outline--TODO: create architecture outline document. Below are areas-to include.--## Document how SRP works:-- Zero-knowledge architecture-- Users master password is converted to byte[] via Argon2Id algorithm.- - The user master password is used for both SRP (passwordless server authentication) and for symmetrically encrypting the vault.-- SRP salt and verifier are stored on server in Vaults table (before this was stored in users table). This is done because- in case a vault is restored to a previous version the users login is also changed back to that previous version.diff --git a/docs/diagrams/README.md b/docs/diagrams/README.mdnew file mode 100644index 000000000..c805ffba4--- /dev/null+++ b/docs/diagrams/README.md@@ -0,0 +1,30 @@+# Diagrams++This folder contains architecture and flow diagrams for AliasVault in various formats.++## Draw.io Diagrams (.drawio)+Files with `.drawio` extension are created with Draw.io (also known as diagrams.net), an open-source diagramming tool.++### How to Open/Edit Draw.io Files+1. Web Interface (Cloud)+ - Visit [diagrams.net](https://app.diagrams.net/)+ - Open source code available at [github.com/jgraph/drawio](https://github.com/jgraph/drawio)++2. Desktop Applications (Offline)+ - Available for Windows, macOS, and Linux+ - Download from [github.com/jgraph/drawio-desktop/releases](https://github.com/jgraph/drawio-desktop/releases)+ - Open source code available at [github.com/jgraph/drawio-desktop](https://github.com/jgraph/drawio-desktop)++3. VS Code Extension+ - Install the [Draw.io Integration](https://marketplace.visualstudio.com/items?itemName=hediet.vscode-drawio) extension+ - Edit diagrams directly within VS Code+ - Source code at [github.com/hediet/vscode-drawio](https://github.com/hediet/vscode-drawio)++## Mermaid Diagrams (.mmd)+Files with `.mmd` extension are [Mermaid](https://mermaid.js.org/) format diagrams. These are text-based diagram definitions that can be rendered by various tools.++### Editors & Tools for Mermaid+- [Mermaid Live Editor](https://github.com/mermaid-js/mermaid-live-editor) - Web-based editor with live preview+- [VS Code Mermaid Extension](https://github.com/mermaid-js/vscode-mermaid) - Preview and edit Mermaid diagrams directly in VS Code+- [Obsidian Mermaid Plugin](https://github.com/jobindj/obsidian-mermaid) - If you use Obsidian for documentation+- [GitLab](https://docs.gitlab.com/ee/user/markdown.html#mermaid) and [GitHub](https://github.blog/2022-02-14-include-diagrams-markdown-files-mermaid/) both render Mermaid diagrams natively in markdowndiff --git a/docs/diagrams/aliasvault-security-architecture.drawio b/docs/diagrams/aliasvault-security-architecture.drawionew file mode 100644index 000000000..7db3e63ae--- /dev/null+++ b/docs/diagrams/aliasvault-security-architecture.drawio@@ -0,0 +1,77 @@+<mxfile host="Electron" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/24.7.17 Chrome/128.0.6613.36 Electron/32.0.1 Safari/537.36" version="24.7.17">+ <diagram name="Page-1" id="ykhTdbPCDOXpVAqZYsCj">+ <mxGraphModel dx="743" dy="666" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="1654" pageHeight="1169" math="0" shadow="0">+ <root>+ <mxCell id="0" />+ <mxCell id="1" parent="0" />+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-1" value="Legend" style="shape=table;startSize=30;container=1;collapsible=0;childLayout=tableLayout;fontSize=16;align=left;verticalAlign=top;fillColor=#0050ef;strokeColor=#001DBC;fontColor=#ffffff;fontStyle=1;spacingLeft=6;spacing=0;resizable=0;" vertex="1" parent="1">+ <mxGeometry x="40" y="940" width="180" height="180" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-2" value="" style="shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;strokeColor=inherit;top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=12;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-1">+ <mxGeometry y="30" width="180" height="30" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-3" value="Cryptographic Operations" style="shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;strokeColor=#432D57;overflow=hidden;fillColor=#76608a;top=0;left=0;bottom=0;right=0;pointerEvents=1;fontSize=12;align=left;fontColor=#ffffff;spacingLeft=10;spacingRight=4;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-2">+ <mxGeometry width="180" height="30" as="geometry">+ <mxRectangle width="180" height="30" as="alternateBounds" />+ </mxGeometry>+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-4" value="" style="shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;strokeColor=#10739e;top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=#b1ddf0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=12;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-1">+ <mxGeometry y="60" width="180" height="30" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-5" value="Storage Elements" style="shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;strokeColor=#006EAF;overflow=hidden;fillColor=#1ba1e2;top=0;left=0;bottom=0;right=0;pointerEvents=1;fontSize=12;align=left;spacingLeft=10;spacingRight=4;fontColor=#ffffff;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-4">+ <mxGeometry width="180" height="30" as="geometry">+ <mxRectangle width="180" height="30" as="alternateBounds" />+ </mxGeometry>+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-6" value="" style="shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;strokeColor=#B09500;top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=#e3c800;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=12;fontColor=#000000;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-1">+ <mxGeometry y="90" width="180" height="30" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-7" value="Keys and Sensitive Data" style="shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;strokeColor=#B09500;overflow=hidden;fillColor=#e3c800;top=0;left=0;bottom=0;right=0;pointerEvents=1;fontSize=12;align=left;fontColor=#000000;spacingLeft=10;spacingRight=4;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-6">+ <mxGeometry width="180" height="30" as="geometry">+ <mxRectangle width="180" height="30" as="alternateBounds" />+ </mxGeometry>+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-10" value="" style="shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;strokeColor=inherit;top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=12;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-1">+ <mxGeometry y="120" width="180" height="30" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-11" value="Authentication Steps" style="shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;strokeColor=#2D7600;overflow=hidden;fillColor=#60a917;top=0;left=0;bottom=0;right=0;pointerEvents=1;fontSize=12;align=left;spacingLeft=10;spacingRight=4;fontColor=#ffffff;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-10">+ <mxGeometry width="180" height="30" as="geometry">+ <mxRectangle width="180" height="30" as="alternateBounds" />+ </mxGeometry>+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-12" value="" style="shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;strokeColor=inherit;top=0;left=0;bottom=0;right=0;collapsible=0;dropTarget=0;fillColor=none;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;fontSize=12;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-1">+ <mxGeometry y="150" width="180" height="30" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-13" value="Email Processing Flow" style="shape=partialRectangle;html=1;whiteSpace=wrap;connectable=0;strokeColor=#A50040;overflow=hidden;fillColor=#d80073;top=0;left=0;bottom=0;right=0;pointerEvents=1;fontSize=12;align=left;fontColor=#ffffff;spacingLeft=10;spacingRight=4;" vertex="1" parent="6F2B19X3ZkVbRV3rCgbW-12">+ <mxGeometry width="180" height="30" as="geometry">+ <mxRectangle width="180" height="30" as="alternateBounds" />+ </mxGeometry>+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-15" value="Client (Local Only Operations)" style="rounded=0;whiteSpace=wrap;html=1;verticalAlign=top;" vertex="1" parent="1">+ <mxGeometry x="40" y="40" width="610" height="450" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-16" value="Master Password <br>(never leaves client)" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;fillColor=#e3c800;fontColor=#000000;strokeColor=#B09500;" vertex="1" parent="1">+ <mxGeometry x="80" y="90" width="150" height="60" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-20" value="Argon2Id" style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;fillColor=#76608a;fontColor=#ffffff;strokeColor=#432D57;" vertex="1" parent="1">+ <mxGeometry x="100" y="200" width="110" height="40" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-22" value="" style="endArrow=classic;html=1;rounded=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;" edge="1" parent="1" source="6F2B19X3ZkVbRV3rCgbW-16" target="6F2B19X3ZkVbRV3rCgbW-20">+ <mxGeometry width="50" height="50" relative="1" as="geometry">+ <mxPoint x="340" y="260" as="sourcePoint" />+ <mxPoint x="390" y="210" as="targetPoint" />+ </mxGeometry>+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-23" value="Derived Key" style="shape=parallelogram;perimeter=parallelogramPerimeter;whiteSpace=wrap;html=1;fixedSize=1;fillColor=#e3c800;fontColor=#000000;strokeColor=#B09500;" vertex="1" parent="1">+ <mxGeometry x="80" y="290" width="150" height="60" as="geometry" />+ </mxCell>+ <mxCell id="6F2B19X3ZkVbRV3rCgbW-24" value="" style="endArrow=classic;html=1;rounded=0;exitX=0.5;exitY=1;exitDx=0;exitDy=0;entryX=0.5;entryY=0;entryDx=0;entryDy=0;" edge="1" parent="1" source="6F2B19X3ZkVbRV3rCgbW-20" target="6F2B19X3ZkVbRV3rCgbW-23">+ <mxGeometry width="50" height="50" relative="1" as="geometry">+ <mxPoint x="340" y="260" as="sourcePoint" />+ <mxPoint x="390" y="210" as="targetPoint" />+ </mxGeometry>+ </mxCell>+ </root>+ </mxGraphModel>+ </diagram>+</mxfile>diff --git a/docs/diagrams/security-architecture.mmd b/docs/diagrams/security-architecture.mmdnew file mode 100644index 000000000..2b2f35ad8--- /dev/null+++ b/docs/diagrams/security-architecture.mmd@@ -0,0 +1,118 @@+%%{ init: { 'flowchart': { 'curve': 'basis' } } }%%+graph TB+ %% Legend+ subgraph Legend["Legend"]+ L_CRYPTO["Cryptographic Operations"]+ L_STORAGE["Storage Elements"]+ L_KEY["Keys and Sensitive Data"]+ L_PROCESS["Process Steps"]+ L_AUTH["Authentication Steps"]+ L_FLOW["Email Processing Flow"]+ end++ subgraph Client["Client (Local Only Operations)"]+ direction TB+ MP[/"Master Password\n(never leaves client)"/]++ subgraph KD["1. Key Derivation"]+ A2["Argon2id"]+ DK[/"Derived Key"/]+ MP --> A2+ A2 --> DK+ DK --> |"used for vault\nencryption/decryption"| AES+ DK --> |"used for authentication"| SRP_C+ end++ subgraph VE["3. Vault Operations"]+ AES["AES256-GCM"]+ VAULT["Encrypted Vault Contents"]+ AES --> |"encrypt/decrypt"| VAULT+ end++ subgraph KP["4. Email Key Management"]+ RSA["RSA/OAEP Key Generation"]+ PRK[/"Private Key\n(stored in vault)"/]+ PBK[/"Public Key"/]+ RSA --> |"generates pair"| PRK+ RSA --> |"generates pair"| PBK+ end++ subgraph ED["5. Email Decryption"]+ PRK --> |"decrypt symmetric key"| SK[/"Symmetric Key\n(AES256)"/]+ SK --> |"decrypt email"| DC["Decrypted Email"]+ end+ end++ subgraph Server["Server"]+ direction TB++ subgraph AUTH["Authentication Flow"]+ SRP_S["SRP Verification"]+ subgraph FA["2FA (Optional)"]+ TOTP["Time-based OTP"]+ GA["Google Authenticator\nor Compatible App"]+ VERIFY["Verify OTP Code"]+ GA --> |"generate code"| TOTP+ TOTP --> |"user enters"| VERIFY+ end+ JWT["Issue JWT Token"]+ SRP_S --> FA+ FA --> |"if 2FA enabled"| JWT+ SRP_S --> |"if 2FA disabled"| JWT+ end++ subgraph VS["Vault Storage"]+ EV["Encrypted Vault Data"]+ end++ subgraph ES["Email System"]+ EC["Email Claims"]+ PKS["Public Key Store"]++ subgraph EP["Email Processing"]+ CHECK{"Valid\nEmail Claim?"}+ REJECT["Reject Email"]+ ESK[/"Generate Random\nSymmetric Key"/]+ EE["Encrypt Email\nContent"]+ ESP["Encrypt Symmetric Key\nwith Public Key"]+ EST["Store Encrypted Email\n& Encrypted Sym Key"]++ CHECK --> |"No"| REJECT+ CHECK --> |"Yes"| ESK+ ESK --> EE+ ESK --> ESP+ EE --> EST+ ESP --> EST+ end+ end+ end++ %% Client-Server Interactions+ SRP_C["SRP Client"] <--> |"SRP Authentication"| SRP_S+ AES <--> |"encrypted vault transfer"| EV+ PBK --> |"register"| PKS+ EST --> |"retrieve encrypted\nemail & sym key"| ED++ %% Styling+ classDef process fill:#ddd,stroke:#333,stroke-width:2px+ classDef storage fill:#b7e3fc,stroke:#333,stroke-width:2px+ classDef key fill:#fef08a,stroke:#333,stroke-width:2px+ classDef crypto fill:#e9d5ff,stroke:#333,stroke-width:2px+ classDef auth fill:#86efac,stroke:#333,stroke-width:2px+ classDef flow fill:#fca5a5,stroke:#333,stroke-width:2px++ %% Apply styles to legend+ class L_CRYPTO crypto+ class L_STORAGE storage+ class L_KEY key+ class L_PROCESS process+ class L_AUTH auth+ class L_FLOW flow++ %% Apply styles to elements+ class A2,SRP_C,SRP_S,RSA,AES crypto+ class EV,EST storage+ class MP,DK,PRK,PBK,SK,ESK key+ class KD,VE,KP,ED process+ class SRP_S,FA,JWT,TOTP,VERIFY auth+ class CHECK,EP flowdiff --git a/docs/security-architecture.md b/docs/security-architecture.mdnew file mode 100644index 000000000..46b5900a9--- /dev/null+++ b/docs/security-architecture.md@@ -0,0 +1,64 @@+# Security Architecture++AliasVault implements a zero-knowledge architecture where sensitive user data and passwords never leave the client device in unencrypted form. Below is a detailed explanation of how the system secures user data and communications.++## Key Components and Process Flow++### 1. Key Derivation+- When a user enters their master password, it remains strictly on the client device+- The master password is processed through Argon2id (a memory-hard key derivation function) locally+- The derived key serves two purposes:+ - Authentication with the server through the SRP protocol+ - Local encryption/decryption of vault contents using AES-256-GCM++### 2. Authentication Process+1. SRP (Secure Remote Password) Authentication+ - Enables secure password-based authentication without transmitting the password+ - Client and server perform a cryptographic handshake to verify identity++2. Two-Factor Authentication (Optional)+ - If enabled, requires an additional verification step after successful SRP authentication+ - Uses Time-based One-Time Password (TOTP) protocol+ - Compatible with standard authenticator apps (e.g., Google Authenticator)+ - Server only issues the final JWT access token after successful 2FA verification++### 3. Vault Operations+- All vault contents are encrypted/decrypted locally using AES-256-GCM+- The encryption key is derived from the user's master password+- Only encrypted data is ever transmitted to or stored on the server+- The server never has access to the unencrypted vault contents++### 4. Email System Security++#### Key Generation and Storage+1. RSA key pair is generated locally on the client+2. Private key is stored in the encrypted vault+3. Public key is sent to the server and associated with email claim(s)++#### Email Reception Process+1. When an email is received, the server:+ - Verifies if the recipient has a valid email claim+ - If no valid claim exists, the email is rejected+ - If valid, generates a random 256-bit symmetric key+ - Encrypts the email content using this symmetric key+ - Encrypts the symmetric key using the recipient's public key+ - Stores both the encrypted email and encrypted symmetric key++#### Email Retrieval Process+1. Client retrieves encrypted email and encrypted symmetric key from server+2. Client uses private key from vault to decrypt the symmetric key+3. Client uses decrypted symmetric key to decrypt the email contents+4. All decryption occurs locally on the client device++> Note: The use of a symmetric key for email content encryption and asymmetric encryption for the symmetric key (hybrid encryption) is implemented due to RSA's limitations on encryption string length and for better performance.++## Security Benefits+- Zero-knowledge architecture ensures user data privacy+- Master password never leaves the client device+- All sensitive operations (key derivation, encryption/decryption) happen locally+- Server stores only encrypted data+- Multi-layer encryption for emails provides secure communication+- Optional 2FA adds an additional security layer+- Use of established cryptographic standards (Argon2id, AES-256-GCM, RSA/OAEP)++This security architecture ensures that even if the server is compromised, user data remains secure as all sensitive operations and keys remain strictly on the client side.