Skip to content
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4859bf3
Added blog post on .env security issues and Polykey solution
xrissoula Mar 6, 2025
3dc020b
Fixed formatting for .env article
xrissoula Mar 6, 2025
127e44b
Removed incorrect .env article
xrissoula Mar 6, 2025
8d22a7b
Add Root Keypair Generation article
xrissoula Mar 6, 2025
e0c0f80
Remove outdated .env article
xrissoula Mar 6, 2025
ba3113c
Update Root Keypair Generation article with correct frontmatter
xrissoula Mar 6, 2025
71721f0
feat: more syntax and styling fixes for document
xrissoula Mar 7, 2025
3218c27
feat: even more syntax and styling fixes for document
xrissoula Mar 7, 2025
fbe548a
Add full keypair generation flowchart for review
xrissoula Mar 7, 2025
e119540
Added key generation SVGs, linked images in root keypair doc, and rem…
xrissoula Mar 10, 2025
5079b6d
Fixed image embedding in root keypair generation doc
xrissoula Mar 10, 2025
a0b449b
Added Polykey Node IDs documentation (cleaned up)
xrissoula Mar 10, 2025
4f89889
Updated Polykey Node IDs documentation
xrissoula Mar 10, 2025
cb1dae0
Fixed YAML format in Polykey Node IDs doc
xrissoula Mar 10, 2025
ca8d448
Fixed YAML front matter formatting in both documentation files
xrissoula Mar 10, 2025
88f8562
Fixed Polykey Node IDs file tracking issue
xrissoula Mar 10, 2025
a47107d
Removed incorrectly placed root keypair generation document
xrissoula Mar 10, 2025
1ccc1a2
Removed incorrectly included images from Node ID PR
xrissoula Mar 10, 2025
6905b8b
Re-added polykey-node-ids document for tracking
xrissoula Mar 10, 2025
8e9d04c
Removed incorrectly added file: polykey-node-ids
xrissoula Mar 10, 2025
7775c3c
Add Symmetric Data Encapsulation Scheme (DES) document
xrissoula Mar 10, 2025
bf014ed
Added content to DES.md
xrissoula Mar 10, 2025
d48c355
Removed incorrectly added polykey-node-ids.md
xrissoula Mar 10, 2025
a0d5d3a
Removed unintended .gitignore modifications from PR #124
xrissoula Mar 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions docs/reference/DES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
title: 'Symmetric Data Encapsulation Scheme (DES)'
date: 2025-03-10
author: 'Christina'
tags: ['cryptography', 'security', 'symmetric-encryption', 'database-encryption', 'libsodium']
---
# Symmetric Data Encapsulation Scheme (DES)

Polykey’s state is completely stored in the database. This means everything critical to the system's function—keys, metadata, and configurations—is written to disk. To ensure the security and integrity of this data, we encrypt the database using a **32-byte Data Encryption Key (DB Key)** and the **XChaCha20-Poly1305-IETF** symmetric encryption algorithm, provided by **libsodium**.

## Why We Use Symmetric Encryption

Encryption is non-negotiable for a system like Polykey, where data security is a core priority. Symmetric encryption is used for:

- **Confidentiality** - Ensuring database contents are only accessible to the rightful owner.
- **Integrity** - Preventing unauthorized tampering by detecting any modifications.
- **Performance** - Symmetric encryption is significantly faster than asymmetric encryption for large datasets.

## Database Encryption Key (DB Key)

### **How the DB Key Works**
The DB Key is a **randomly generated 32-byte key** that encrypts all database content. This key is stored on disk, but never in plaintext—it is always encrypted before being written to storage.

The DB Key is used to encrypt and decrypt the entire database, meaning that without it, **all data in the system is inaccessible**.

### **Why the DB Key is Not Derived from the Root Key**
A common approach in cryptographic systems is to derive all keys from a single root key. However, this is not how Polykey manages database encryption. The DB Key is independent from the root key for the following reasons:

1. **Key Rotation & Flexibility**
If the root key were used to derive the DB Key, changing the root key would require re-encrypting the entire database. This would be a **catastrophic** operation in terms of efficiency and usability. Instead, by keeping the DB Key separate, the database can remain encrypted even when the root key is changed.

2. **Minimizing Attack Surfaces**
If an attacker compromises the root key, they still cannot access the database contents without the DB Key. This adds an extra layer of security.

3. **Persistence Across Keypair Changes**
In Polykey, root keypairs can be swapped out periodically for security reasons (like how passwords should be rotated). By decoupling the DB Key, the database encryption remains stable across key rotations.

## Encryption Algorithm: XChaCha20-Poly1305-IETF

Polykey uses **XChaCha20-Poly1305-IETF**, a widely respected symmetric encryption scheme known for its:

- **256-bit key size** - Strong encryption without performance tradeoffs.
- **192-bit nonce** - Ensures nonce reuse attacks are virtually impossible.
- **Authenticated encryption** - Includes integrity checks, so any unauthorized modifications are detected.

### **Why XChaCha20-Poly1305?**
1. **Nonce Misuse Resistance**
Unlike AES-GCM, which has strict nonce reuse requirements, XChaCha20 allows for random nonce generation with no risk of catastrophic failures.

2. **High Performance**
Stream ciphers like XChaCha20 are significantly faster than block ciphers like AES in many scenarios, making them well-suited for encrypting large datasets.

3. **Compatibility with Libsodium**
Libsodium is a battle-tested cryptographic library that provides a simple and secure implementation of XChaCha20-Poly1305, reducing the risk of implementation errors.

## Key Rotation & Secure Storage

### **Key Rotation Strategy**
Regular key rotation is a fundamental security practice. However, since re-encrypting an entire database is computationally expensive, Polykey manages key rotations in a way that minimizes disruption:

1. **The DB Key is swapped periodically** - This reduces long-term key exposure.
2. **New keys are securely generated and encrypted using KEM (Key Encapsulation Mechanism)** - This ensures a smooth transition without exposing old encrypted data.
3. **Polykey handles the transition automatically** - Users do not need to worry about database re-encryption when keypairs are rotated.

### **How the DB Key is Stored**
The DB Key is **never stored in plaintext**. Instead, it is encrypted and saved as a **JWE (JSON Web Encryption) file**. This file is securely managed to ensure that only authorized nodes can decrypt and use it.

## Security Considerations

- **Loss of the DB Key = Complete Data Loss**
If the encrypted DB Key is lost, **all data within Polykey is permanently inaccessible**. Users must ensure backups are properly managed.

- **Frequent Key Rotation is Good Practice**
Regularly rotating the DB Key prevents long-term exposure and mitigates risks from potential future cryptographic weaknesses.

- **Secure Backup Management is Critical**
Since Polykey does not store plaintext recovery keys, **users must securely back up their 24-word recovery code** to ensure they can regain access if needed.

## Conclusion

The **Symmetric Data Encapsulation Scheme (DES)** is a critical component of Polykey's security model. By leveraging XChaCha20-Poly1305-IETF for high-speed encryption and ensuring the **DB Key remains independent from the root key**, Polykey maintains a **balance between security, performance, and usability**.

---