You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by as...@apache.org on 2026/05/05 20:57:27 UTC

(tooling-agents) branch main updated: ASVS audit: 11.2.2.md (redacted) [source: apache/steve/v3 @ d0aa7e9]

This is an automated email from the ASF dual-hosted git repository.

asf-tooling pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-agents.git


The following commit(s) were added to refs/heads/main by this push:
     new 287ab2a  ASVS audit: 11.2.2.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
287ab2a is described below

commit 287ab2ab98c9a1041ed94e12921c6602a7d67517
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Tue May 5 22:51:51 2026 +0200

    ASVS audit: 11.2.2.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
---
 ASVS/reports/steve/v3/d0aa7e9/all/11.2.2.md | 220 ++++++++++++++++++++++++++++
 1 file changed, 220 insertions(+)

diff --git a/ASVS/reports/steve/v3/d0aa7e9/all/11.2.2.md b/ASVS/reports/steve/v3/d0aa7e9/all/11.2.2.md
new file mode 100644
index 0000000..9b80af6
--- /dev/null
+++ b/ASVS/reports/steve/v3/d0aa7e9/all/11.2.2.md
@@ -0,0 +1,220 @@
+# Security Audit Report: ASVS 11.2.2
+
+## Executive Summary
+
+| Field | Value |
+|-------|-------|
+| **Repository** | apache/steve/v3 |
+| **Audit Date** | May 05, 2026 |
+| **Auditor** | Tooling Agents (bundled-pass mode) |
+| **ASVS Requirement** | ASVS 11.2.2 |
+| **Files Analyzed** | 8 relevant / 49 total |
+| **Files Skipped** | 12 |
+
+**Requirement description:** Verify that the application is designed with crypto agility such that random number, authenticated encryption, MAC, or hashing algorithms, key lengths, rounds, ciphers and modes can be reconfigured, upgraded, or swapped at any time, to protect against cryptographic breaks. Similarly, it must also…
+
+### Findings Overview
+
+| Severity | Count |
+|----------|-------|
+| πŸ”΄ Critical | 0 |
+| 🟠 High | 1 |
+| 🟑 Medium | 0 |
+| 🟒 Low | 1 |
+
+---
+
+## ASVS-11.2.2: Crypto Agility
+
+### Findings for 11.2.2
+
+#### [HIGH]
+**Finding ID:** ASVS-1122-HIGH-001  
+**Title:** No Crypto Agility - Algorithms Hardcoded Without Abstraction or Versioning
+
+**Location:** `v3/steve/crypto.py` (entire file), `v3/schema.sql`
+
+**Vulnerable code:**
+```python
+# crypto.py - All algorithms hardcoded with no abstraction layer
+
+def gen_opened_key(edata: bytes, salt: bytes) -> bytes:
+    digest = hashlib.blake2b(edata).digest()  # Hardcoded BLAKE2b
+    return _hash(digest, salt)  # Hardcoded Argon2d
+
+def _b64_vote_key(vote_token: bytes, salt: bytes) -> bytes:
+    keymaker = hkdf.HKDF(
+        algorithm=hashes.SHA256(),  # Hardcoded SHA-256
+        length=32,
+        salt=salt,
+        info=b'xchacha20_key',  # Hardcoded info string
+    )
+    vote_key = keymaker.derive(vote_token)
+    return base64.urlsafe_b64encode(vote_key)
+
+def create_vote(vote_token: bytes, salt: bytes, votestring: str) -> bytes:
+    b64key = _b64_vote_key(vote_token, salt)
+    f = cryptography.fernet.Fernet(b64key)  # Hardcoded Fernet
+    return f.encrypt(votestring.encode())
+```
+
+```sql
+-- schema.sql - No algorithm version field stored with ciphertext
+CREATE TABLE vote (
+    vid  INTEGER PRIMARY KEY AUTOINCREMENT,
+    vote_token  BLOB NOT NULL CHECK (length(vote_token) = 32),
+    ciphertext  BLOB NOT NULL  -- No algorithm identifier
+) STRICT;
+```
+
+**Description:**  
+The application has no crypto-agility design. Specific issues:
+
+1. **No algorithm abstraction layer:** All crypto operations directly call specific implementations with hardcoded parameters. There's no configuration, registry, or strategy pattern that would allow swapping algorithms.
+
+2. **No algorithm versioning in stored data:** The `vote` table stores `ciphertext` without any algorithm identifier. When transitioning from Fernet to XChaCha20-Poly1305, there will be no way to determine which algorithm was used for existing ciphertext without external tracking.
+
+3. **No key versioning:** If keys need to be rotated or algorithms changed, there's no version field to indicate which key/algorithm generated a given ciphertext.
+
+4. **No re-encryption mechanism:** No tooling exists to decrypt existing votes with the old algorithm and re-encrypt with a new one.
+
+5. **Fixed key lengths in schema:** Database CHECK constraints enforce exact lengths (`length(vote_token) = 32`, `length(opened_key) = 32`, `length(salt) = 16`), preventing algorithm changes that require different sizes without schema migration.
+
+**Impact:** Algorithm upgrades require code changes, database schema migrations, and potential data loss. The planned Fernet β†’ XChaCha20-Poly1305 transition will require careful coordination. Future PQC migrations will be significantly more complex without agility designed in.
+
+**Remediation:**
+
+1. Add algorithm version to stored ciphertext:
+```sql
+CREATE TABLE vote (
+    vid  INTEGER PRIMARY KEY AUTOINCREMENT,
+    vote_token  BLOB NOT NULL,
+    crypto_version  INTEGER NOT NULL DEFAULT 1,  -- Algorithm version
+    ciphertext  BLOB NOT NULL
+) STRICT;
+```
+
+2. Implement a crypto abstraction layer:
+```python
+# crypto.py - Agile design example
+
+CRYPTO_VERSIONS = {
+    1: {
+        'kdf': 'argon2id',
+        'hash': 'blake2b',
+        'encrypt': 'fernet',
+        'key_stretch': 'hkdf-sha256',
+    },
+    2: {
+        'kdf': 'argon2id', 
+        'hash': 'blake2b',
+        'encrypt': 'xchacha20-poly1305',
+        'key_stretch': 'hkdf-sha256',
+    },
+}
+
+CURRENT_VERSION = 1  # Configurable
+
+def create_vote(vote_token: bytes, salt: bytes, votestring: str,
+                version: int = CURRENT_VERSION) -> tuple[int, bytes]:
+    """Returns (version, ciphertext) tuple."""
+    config = CRYPTO_VERSIONS[version]
+    # Use config to select encryption...
+    ...
+    return version, ciphertext
+
+def decrypt_votestring(vote_token: bytes, salt: bytes, 
+                       ciphertext: bytes, version: int) -> str:
+    """Decrypts using the specified version's algorithm."""
+    config = CRYPTO_VERSIONS[version]
+    ...
+```
+
+3. Provide a re-encryption utility for migration.
+
+#### [LOW]
+**Finding ID:** ASVS-1122-LOW-001  
+**Title:** Misleading HKDF Info Parameter Suggests Incomplete Migration
+
+**Location:** `v3/steve/crypto.py`, lines 63-67
+
+**Code:**
+```python
+### still using Fernet now, but will switch soon. Leaving comments.
+keymaker = hkdf.HKDF(
+    algorithm=hashes.SHA256(),
+    length=32,  # 32-byte key for XChaCha20-Poly1305
+    salt=salt,
+    info=b'xchacha20_key',  # <-- References algorithm not yet in use
+)
+```
+
+**Description:**  
+The HKDF `info` parameter is set to `b'xchacha20_key'` but the actual encryption uses Fernet (AES-128-CBC). This is a domain separation label that typically identifies the intended key usage. When the migration to XChaCha20-Poly1305 occurs, this `info` value must NOT change (or old ciphertext becomes undecryptable), creating a confusing situation where the info label is correct for new data but was technically wrong for historical data.
+
+**Impact:** Minor confusion during migration. The info parameter domain separation is inconsistent with actual use, which could lead to errors during the transition.
+
+**Remediation:** Either use a generic `info` value like `b'vote_encryption_key_v1'` or document that the current `info` value was chosen proactively for the planned migration.
+
+### Security Controls Inventory for 11.2.2
+
+| Control | Location | Status |
+|---------|----------|--------|
+| Algorithm abstraction layer | Not found | βœ— Missing |
+| Configurable algorithm selection | Not found | βœ— Missing |
+| Algorithm version stored with ciphertext | Not found | βœ— Missing |
+| Key versioning | Not found | βœ— Missing |
+| Re-encryption mechanism | Not found | βœ— Missing |
+| Schema flexibility for key sizes | `schema.sql` (hardcoded CHECK) | βœ— Rigid |
+| Migration plan documentation | `crypto.py` comment only | ⚠️ Informal |
+
+### Positive Patterns for 11.2.2
+
+- The development team explicitly acknowledges the need to transition from Fernet to XChaCha20-Poly1305 (shows awareness)
+- HKDF is used for key derivation (allows changing the underlying KDF input without changing encryption)
+- The key derivation chain (opened_key β†’ vote_token β†’ vote_key) provides layering that could support partial upgrades
+- The `info` parameter in HKDF provides domain separation, useful for future multi-algorithm support
+- Salt generation is separate from encryption, allowing independent upgrades
+
+---
+
+
+
+## Cross-cutting Architecture Observations
+
+1. **Centralized Crypto Module:** All cryptographic operations are centralized in `v3/steve/crypto.py`. This is excellent for auditability but currently lacks the abstraction needed for agility. The centralization makes future refactoring feasible.
+
+2. **Key Derivation Chain:** The system uses a well-designed multi-level key derivation: `election_data β†’ BLAKE2b β†’ Argon2 β†’ opened_key β†’ (+ pid + iid + salt) β†’ Argon2 β†’ vote_token β†’ HKDF β†’ vote_key β†’ Fernet(vote)`. This provides good key separation and limits blast radius, but the entire chain is hardcoded.
+
+3. **Documentation Gap:** The project has partial documentation (`schema.md`) but lacks formal security/crypto documentation. The existing documentation focuses on database schema rather than cryptographic design decisions.
+
+4. **Anti-Tamper Design:** The `opened_key` serves dual purposes: (1) tamper detection via `is_tampered()` and (2) vote token derivation. This coupling means the anti-tamper mechanism is tied to the same cryptographic algorithm as the voting mechanism β€” upgrading one requires upgrading both.
+
+5. **No Asymmetric Cryptography:** The system uses only symmetric primitives and key derivation. This reduces PQC urgency compared to systems using RSA/ECC, but the AES-128 effective key length under Grover's algorithm (64-bit) is a concern for long-term data confidentiality.
+
+6. **Inconsistency Between Production and Benchmark:** Production uses Argon2d while the benchmark uses Argon2id, suggesting either incomplete migration or a deliberate but undocumented choice.
+
+## Cross-cutting Recommendations
+
+### Immediate (Sprint-level)
+1. **Change Argon2d to Argon2id** in `_hash()` function (ASVS-1121-MED-001). This is a one-line change with significant security improvement. Note: this will change all derived values, so must be coordinated with any existing deployed databases.
+
+2. **Add `crypto_version` column** to the `vote` table to enable future algorithm transitions without data loss.
+
+### Short-term (1-3 months)
+3. **Create formal cryptographic inventory document** mapping all algorithms, keys, their purposes, access scopes, and protection requirements (satisfies 11.1.1, 11.1.2).
+
+4. **Implement crypto abstraction layer** in `crypto.py` with version-based algorithm selection and a configuration mechanism for algorithm parameters (satisfies 11.2.2).
+
+5. **Add cryptographic linting** to CI/CD pipeline using `semgrep` or equivalent with rules for:
+   - Flagging new crypto imports
+   - Detecting weak algorithms
+   - Ensuring CSPRNG usage (satisfies 11.1.3)
+
+### Long-term (3-12 months)
+6. **Complete Fernet β†’ XChaCha20-Poly1305 migration** with proper versioning, re-encryption tooling, and rollback capability.
+
+7. **Document PQC migration plan** assessing quantum risk for each primitive and establishing upgrade timelines, particularly upgrading to AES-256 for long-term vote confidentiality (satisfies 11.1.4).
+
+8. **Implement key lifecycle management** including maximum key age, scheduled rotation for long-lived keys, and secure key destruction after election archival (satisfies 11.1.1).
+        
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org