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:52:15 UTC

(tooling-agents) branch main updated: ASVS audit: 11.3.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 04fd461  ASVS audit: 11.3.2.md (redacted) [source: apache/steve/v3 @ d0aa7e9]
04fd461 is described below

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

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

diff --git a/ASVS/reports/steve/v3/d0aa7e9/all/11.3.2.md b/ASVS/reports/steve/v3/d0aa7e9/all/11.3.2.md
new file mode 100644
index 0000000..f47fec6
--- /dev/null
+++ b/ASVS/reports/steve/v3/d0aa7e9/all/11.3.2.md
@@ -0,0 +1,156 @@
+# Security Audit Report: ASVS 11.3.2
+
+## Executive Summary
+
+| Field | Value |
+|-------|-------|
+| **Repository** | apache/steve/v3 |
+| **Audit Date** | May 05, 2026 |
+| **Auditor** | Tooling Agents (bundled-pass mode) |
+| **ASVS Requirement** | ASVS 11.3.2 |
+| **Files Analyzed** | 5 relevant / 49 total |
+| **Files Skipped** | 12 |
+
+**Requirement description:** Verify that only approved ciphers and modes such as AES with GCM are used.
+
+### Findings Overview
+
+| Severity | Count |
+|----------|-------|
+| 🔴 Critical | 0 |
+| 🟠 High | 0 |
+| 🟡 Medium | 1 |
+| 🟢 Low | 0 |
+
+---
+
+## ASVS-11.3.2: Approved Ciphers and Modes
+
+### Findings for 11.3.2
+
+### [MEDIUM]
+
+**Finding ID:** ASVS-1132-MED-001
+
+**File:** `v3/steve/crypto.py`, functions `create_vote()` and `decrypt_votestring()`, lines 72-82
+
+**Vulnerable Code:**
+```python
+def _b64_vote_key(vote_token: bytes, salt: bytes) -> bytes:
+    "Key-stretch the vote_token. (ref: PBKDF)"
+
+    ### 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',
+    )
+    vote_key = keymaker.derive(vote_token)
+    return base64.urlsafe_b64encode(vote_key)
+
+
+def create_vote(vote_token: bytes, salt: bytes, votestring: str) -> bytes:
+    "Encrypt VOTESTRING using the VOTE_TOKEN and SALT."
+
+    b64key = _b64_vote_key(vote_token, salt)
+    f = cryptography.fernet.Fernet(b64key)
+    return f.encrypt(votestring.encode())
+```
+
+**Data Flow:** `vote_token` → HKDF → 32-byte key → base64 → Fernet (AES-128-CBC + HMAC-SHA256) instead of the intended XChaCha20-Poly1305
+
+**Impact:** The code explicitly acknowledges it should be using XChaCha20-Poly1305 (an AEAD cipher) but is currently using Fernet (AES-128-CBC + HMAC-SHA256). While Fernet is a secure authenticated encryption construction, it is not a native AEAD mode. Modern ASVS standards prefer purpose-built AEAD ciphers (AES-GCM, ChaCha20-Poly1305, XChaCha20-Poly1305) which provide authenticated encryption in a single primitive with formal security proofs.
+
+Key concerns:
+- AES-CBC is a legacy mode that requires careful composition with MAC
+- Fernet's AES-128 provides only 128 bits of security vs the 256-bit key being derived (waste of key material)
+- The HKDF `info` parameter says `b'xchacha20_key'` but the key is used for Fernet — this mismatch indicates incomplete migration
+- The 32-byte HKDF output is base64-encoded and fed to Fernet, which internally splits it into 16 bytes signing + 16 bytes encryption (AES-128), not using the full 256 bits
+
+**Remediation:**
+```python
+from cryptography.hazmat.primitives.ciphers.aead import ChaCha20Poly1305
+import os
+
+def _vote_key(vote_token: bytes, salt: bytes) -> bytes:
+    "Derive encryption key from vote_token."
+    keymaker = hkdf.HKDF(
+        algorithm=hashes.SHA256(),
+        length=32,  # 32-byte key for ChaCha20-Poly1305
+        salt=salt,
+        info=b'chacha20_poly1305_key',
+    )
+    return keymaker.derive(vote_token)
+
+
+def create_vote(vote_token: bytes, salt: bytes, votestring: str) -> bytes:
+    "Encrypt VOTESTRING using ChaCha20-Poly1305 AEAD."
+    key = _vote_key(vote_token, salt)
+    nonce = os.urandom(12)  # 96-bit nonce for ChaCha20-Poly1305
+    aead = ChaCha20Poly1305(key)
+    ciphertext = aead.encrypt(nonce, votestring.encode(), None)
+    return nonce + ciphertext  # prepend nonce for decryption
+
+
+def decrypt_votestring(vote_token: bytes, salt: bytes, ciphertext: bytes) -> str:
+    "Decrypt using ChaCha20-Poly1305 AEAD."
+    key = _vote_key(vote_token, salt)
+    nonce = ciphertext[:12]
+    ct = ciphertext[12:]
+    aead = ChaCha20Poly1305(key)
+    return aead.decrypt(nonce, ct, None).decode()
+```
+
+---
+
+### Security Controls Inventory for 11.3.2
+
+| Control | Location | Cipher/Mode | Status |
+|---------|----------|-------------|--------|
+| Vote encryption | `crypto.py:create_vote()` | Fernet (AES-128-CBC + HMAC-SHA256) | ⚠️ Authenticated but not AEAD |
+| Vote decryption | `crypto.py:decrypt_votestring()` | Fernet | ⚠️ Same |
+| Key derivation | `crypto.py:_b64_vote_key()` | HKDF-SHA256 | ✅ Approved KDF |
+| Password hashing | `crypto.py:_hash()` | Argon2 | ✅ Approved |
+| Fast hashing | `crypto.py:gen_opened_key()` | BLAKE2b | ✅ Approved |
+
+### Positive Patterns for 11.3.2
+
+1. **AES cipher usage**: The underlying cipher (AES) is an approved NIST standard.
+2. **HKDF for key derivation**: Uses HKDF (RFC 5869) with SHA-256, which is NIST-approved.
+3. **Argon2 for password/secret hashing**: Industry-standard memory-hard function.
+4. **BLAKE2b for fast hashing**: An approved hash function (RFC 7693).
+5. **Planned migration**: Code comments indicate awareness that XChaCha20-Poly1305 is the target cipher, showing intent to move to a modern AEAD.
+
+---
+
+
+
+## Cross-cutting Architecture Observations
+
+1. **Cryptographic key hierarchy is well-designed**: The system uses a layered key derivation approach: Election data → BLAKE2b → Argon2 → `opened_key` → per-voter tokens → per-vote encryption keys. This provides good key separation and ensures that compromise of one vote doesn't compromise others.
+
+2. **Incomplete migration from Fernet to AEAD**: The codebase is in a transitional state, as evidenced by the `### still using Fernet now, but will switch soon` comment and the `info=b'xchacha20_key'` parameter. The HKDF derives 32 bytes intended for XChaCha20-Poly1305 but actually feeds it to Fernet which only uses 16 bytes for AES-128. This means the full key material isn't utilized.
+
+3. **Security margin inconsistency**: The system uses strong 256-bit outputs from Argon2 and HKDF but then feeds them into Fernet which only provides 128-bit encryption security (AES-128). The 40-bit IDs (`create_id()`) are the weakest link in the entropy chain.
+
+4. **Side-channel considerations partially addressed**: The use of `secrets` module throughout is excellent. However, Argon2d and non-constant-time comparison in `is_tampered()` show that side-channel resistance wasn't uniformly applied.
+
+5. **Fernet's timestamp exposure**: Fernet tokens include a plaintext timestamp of when encryption occurred. In a voting system, this could leak information about when a specific vote was cast, potentially de-anonymizing voters if combined with server access logs.
+
+## Cross-cutting Recommendations
+
+### Immediate (Before Next Release)
+1. **Fix `is_tampered()` to use `hmac.compare_digest()`** — Simple one-line fix that eliminates the timing oracle (ASVS-1124-HIGH-001).
+2. **Switch from Argon2d to Argon2id** — Change `Type.D` to `Type.ID` in `_hash()` to gain side-channel resistance (ASVS-1124-MED-001).
+3. **Add error handling around `decrypt_votestring()`** — Wrap in try/except to prevent DoS via corrupted votes (ASVS-1125-MED-001).
+
+### Short-term (Next Development Cycle)
+4. **Complete migration to XChaCha20-Poly1305** — Replace Fernet with a proper AEAD cipher as already planned. This addresses ASVS 11.3.2 and eliminates the key material waste (ASVS-1132-MED-001).
+5. **Increase `create_id()` entropy to at least 128 bits** — Use `secrets.token_hex(16)` for 32-character hex IDs, updating schema constraints accordingly (ASVS-1123-MED-001).
+
+### Long-term (Architecture)
+6. **Implement a unified cryptographic abstraction layer** — Create a single module interface for all crypto operations with versioning, allowing cipher agility without code changes throughout the application.
+7. **Add integration tests for timing resistance** — Automated tests that verify constant-time behavior of security-critical comparisons.
+8. **Consider removing Fernet timestamp from vote tokens** — Or migrate to a scheme that doesn't embed plaintext metadata in ciphertext.
+        
\ 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