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/04/21 07:36:11 UTC

(tooling-agents) branch main updated: ASVS L1 audit: 11.4.1 (vote_encryption_storage)

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 f44e177  ASVS L1 audit: 11.4.1 (vote_encryption_storage)
f44e177 is described below

commit f44e1778be9f1312d8df460603ffaef438d42138
Author: ASF Tooling Team <ro...@apache.org>
AuthorDate: Tue Apr 21 09:36:06 2026 +0200

    ASVS L1 audit: 11.4.1 (vote_encryption_storage)
---
 .../d0aa7e9/vote_encryption_storage/11.4.1.md      | 199 +++++++++++++++++++++
 1 file changed, 199 insertions(+)

diff --git a/repos/apache/ASVS/reports/steve/d0aa7e9/vote_encryption_storage/11.4.1.md b/repos/apache/ASVS/reports/steve/d0aa7e9/vote_encryption_storage/11.4.1.md
new file mode 100644
index 0000000..e317f5a
--- /dev/null
+++ b/repos/apache/ASVS/reports/steve/d0aa7e9/vote_encryption_storage/11.4.1.md
@@ -0,0 +1,199 @@
+# ASVS 11.4.1 Security Audit Report: Hash Function Usage
+
+## Executive Summary
+
+**Audit Metadata**
+- **Repository:** apache/steve
+- **Audit Date:** Apr 21, 2026
+- **Auditor:** Tooling Agents
+- **ASVS Requirement:** 11.4.1 — Verify that only approved hash functions are used for general cryptographic use cases, including digital signatures, HMAC, KDF, and random bit generation. Disallowed hash functions, such as MD5, must not be used for any cryptographic purpose.
+  - **Level:** 1
+  - **Section:** Hashing and Hash-based Functions
+  - **Chapter:** Cryptography
+- **Files Analyzed:** 4 relevant out of 4 total, 0 skipped
+
+**Finding Summary**
+
+| Severity | Count | Description |
+|----------|-------|-------------|
+| 🔴 Critical | 0 | No disallowed hash functions in use |
+| 🟠 High | 0 | - |
+| 🟡 Medium | 0 | - |
+| 🔵 Low | 0 | - |
+| **Total** | **0** | **ASVS 11.4.1 Compliance: PASS** |
+
+**Key Results:** After thorough analysis of all cryptographic hash function usage across the codebase, **no findings** were identified for ASVS 11.4.1. No disallowed hash functions (MD5, SHA-1, etc.) are used anywhere in the codebase. All cryptographic operations use approved hash function families (BLAKE2b, SHA-256, Argon2).
+
+---
+
+## Security Controls Inventory
+
+### Hash Functions Used in Production Code
+
+| Hash Function | Location | Use Case | Approved? | Coverage |
+|---------------|----------|----------|-----------|----------|
+| BLAKE2b | `crypto.py:45` (`gen_opened_key`) | Pre-hashing election data before Argon2 | ✅ Yes | Complete |
+| SHA-256 (via HKDF) | `crypto.py:60-66` (`_b64_vote_key`) | Key stretching for vote encryption | ✅ Yes | Complete |
+| SHA-256 (via Fernet HMAC) | `crypto.py:72-74` (`create_vote`) | HMAC authentication of ciphertexts | ✅ Yes | Complete |
+| Argon2 | `crypto.py:86-95` (`_hash`) | KDF for opened_key and vote_token generation | ✅ Yes | Complete |
+
+### Coverage Analysis — All Entry Points Using Hash Functions
+
+| Entry Point | Function Call Chain | Hash Function Applied | Verified |
+|-------------|---------------------|----------------------|----------|
+| Election opening | `Election.open()` → `gen_opened_key()` → `blake2b()` + `_hash()` | BLAKE2b + Argon2 | ✅ |
+| Tamper detection | `Election.is_tampered()` → `gen_opened_key()` → `blake2b()` + `_hash()` | BLAKE2b + Argon2 | ✅ |
+| Vote submission | `Election.add_vote()` → `gen_vote_token()` → `_hash()` | Argon2 | ✅ |
+| Vote submission (encrypt) | `Election.add_vote()` → `create_vote()` → `_b64_vote_key()` → `HKDF` | SHA-256 | ✅ |
+| Vote tallying (token) | `Election.tally_issue()` → `gen_vote_token()` → `_hash()` | Argon2 | ✅ |
+| Vote tallying (decrypt) | `Election.tally_issue()` → `decrypt_votestring()` → `_b64_vote_key()` → `HKDF` | SHA-256 | ✅ |
+| Vote status check | `Election.has_voted_upon()` → `gen_vote_token()` → `_hash()` | Argon2 | ✅ |
+
+**Coverage Status:** ✅ Complete — No gaps identified. Every entry point that should use an approved hash function does so.
+
+---
+
+## Critical File Review
+
+### `v3/steve/crypto.py` — Central Cryptographic Module
+
+| Line(s) | Function | Hash Algorithm | Purpose | Status |
+|---------|----------|----------------|---------|--------|
+| 35-37 | `gen_salt()` | N/A (CSPRNG) | Salt generation via `secrets.token_bytes` | ✅ Approved |
+| 40-49 | `gen_opened_key()` | BLAKE2b + Argon2 | Election integrity key | ✅ Approved |
+| 52-55 | `gen_vote_token()` | Argon2 | Per-voter-issue token | ✅ Approved |
+| 57-68 | `_b64_vote_key()` | HKDF-SHA256 | Vote encryption key derivation | ✅ Approved |
+| 71-75 | `create_vote()` | Fernet (AES-128-CBC + HMAC-SHA256) | Vote encryption | ✅ Approved |
+| 78-83 | `decrypt_votestring()` | Fernet (AES-128-CBC + HMAC-SHA256) | Vote decryption | ✅ Approved |
+| 86-95 | `_hash()` | Argon2 (Type.D) | Core KDF primitive | ✅ Approved family |
+| 115-117 | `create_id()` | N/A (CSPRNG) | ID generation via `secrets.token_hex` | ✅ Approved |
+
+### `v3/steve/election.py` — Election Logic (Consumer of crypto.py)
+
+| Line(s) | Method | Crypto Delegation | Hash Functions Used | Verified |
+|---------|--------|-------------------|---------------------|----------|
+| N/A | `open()` | `crypto.gen_salt()`, `crypto.gen_opened_key()` | BLAKE2b, Argon2 | ✅ |
+| N/A | `add_salts()` | `crypto.gen_salt()` | N/A (CSPRNG only) | ✅ |
+| N/A | `add_vote()` | `crypto.gen_vote_token()`, `crypto.create_vote()` | Argon2, SHA-256 | ✅ |
+| N/A | `tally_issue()` | `crypto.gen_vote_token()`, `crypto.decrypt_votestring()` | Argon2, SHA-256 | ✅ |
+| N/A | `has_voted_upon()` | `crypto.gen_vote_token()` | Argon2 | ✅ |
+| N/A | `is_tampered()` | `crypto.gen_opened_key()` | BLAKE2b, Argon2 | ✅ |
+| N/A | `create()` / `add_issue()` | `crypto.create_id()` | N/A (CSPRNG only) | ✅ |
+
+---
+
+## Findings
+
+**No findings identified.** All cryptographic hash function usage complies with ASVS 11.4.1 requirements.
+
+---
+
+## Positive Security Patterns
+
+### 1. **Exclusive Use of Approved Hash Functions**
+The codebase does not import or use MD5, SHA-1, or any other deprecated hash function. The only `hashlib` usage is for BLAKE2b (line 3 of `crypto.py`: `import hashlib  # for blake2b`).
+
+### 2. **Approved HMAC Construction**
+HMAC is handled internally by Fernet using HMAC-SHA256 — no custom HMAC implementations with weak hash functions.
+
+### 3. **Robust KDF Chain**
+The key derivation hierarchy uses strong primitives throughout:
+- **Argon2** for computationally-expensive derivation (opened_key, vote_token)
+- **HKDF-SHA256** for fast key stretching from already-strong keying material (vote_key)
+
+### 4. **Cryptographic Randomness**
+All random generation uses Python's `secrets` module (`token_bytes`, `token_hex`, `randbelow`) — no use of the insecure `random` module for cryptographic purposes.
+
+### 5. **BLAKE2b for Pre-hashing**
+Using BLAKE2b to reduce large inputs before Argon2 is a sound design choice. BLAKE2b is standardized in RFC 7693 and is Argon2's internal primitive.
+
+### 6. **Centralized Hash Function Management**
+All Argon2 operations go through a single `_hash()` function at `crypto.py:86-95`, making it easy to audit and update hash parameters system-wide.
+
+---
+
+## Architecture Observations
+
+### Key Derivation Hierarchy (All Approved Functions)
+
+```
+Election Data
+    │
+    ├── BLAKE2b (pre-hash to 64 bytes)
+    │       │
+    │       └── Argon2 + election.salt → opened_key (32 bytes)
+    │               │
+    │               └── Argon2 + mayvote.salt → vote_token (32 bytes)
+    │                       │
+    │                       └── HKDF-SHA256 + mayvote.salt → vote_key (32 bytes)
+    │                               │
+    │                               └── Fernet (AES-128-CBC + HMAC-SHA256)
+    │                                       │
+    │                                       └── Encrypted Vote (ciphertext)
+```
+
+**Analysis:** Every node in this chain uses an approved hash function or KDF. The architecture demonstrates defense-in-depth with multiple layers of cryptographic protection.
+
+### Notable Design Decision: Argon2 Variant Selection
+
+The production `_hash()` function at `crypto.py:93` uses `argon2.low_level.Type.D` (Argon2d), while the benchmark function at `crypto.py:140` uses `argon2.low_level.Type.ID` (Argon2id). 
+
+**Context:** RFC 9106 and OWASP recommend Argon2id as the default choice. Argon2d is resistant to GPU attacks but vulnerable to side-channel timing attacks. In a server-side deployment where co-located attackers are unlikely, this is mitigated but still inconsistent with best practice.
+
+**Assessment:** This does not constitute a finding under ASVS 11.4.1 because Argon2d remains within the Argon2 approved family and the side-channel attack vector requires local process access. However, it represents a deviation from current best practices.
+
+---
+
+## Recommendations Summary
+
+### Immediate Actions
+None required — ASVS 11.4.1 compliance achieved.
+
+### Short-term Improvements (Optional)
+1. **Update Argon2 Variant:** Change `crypto.py:93` from `type=argon2.low_level.Type.D` to `type=argon2.low_level.Type.ID` to align with RFC 9106 recommendations and eliminate the inconsistency with the benchmark function. This provides additional protection against side-channel attacks in shared hosting environments.
+
+### Long-term Enhancements (Optional)
+1. **Update HKDF Info Parameter:** Update the HKDF `info` parameter from `b'xchacha20_key'` to `b'fernet_key'` to accurately reflect the current encryption scheme, or defer until the planned XChaCha20-Poly1305 migration occurs.
+
+2. **Document Hash Function Selection:** Add inline documentation explaining the rationale for each hash function choice to assist future security audits and cryptographic reviews.
+
+---
+
+## Appendix: Files Analyzed
+
+<details>
+<summary>Click to expand file list (4 files)</summary>
+
+1. **`v3/schema.sql`** (relevance: 10)
+   - Database schema definition
+   - Reviewed for hash function storage requirements
+
+2. **`v3/server/config.yaml.example`** (relevance: 10)
+   - Configuration template
+   - Reviewed for hash function configuration options
+
+3. **`v3/steve/crypto.py`** (relevance: 10)
+   - Central cryptographic module
+   - Contains all hash function implementations
+   - Lines reviewed: 3, 35-37, 40-49, 52-55, 57-68, 71-75, 78-83, 86-95, 115-117, 140
+
+4. **`v3/steve/election.py`** (relevance: 10)
+   - Election business logic
+   - Consumer of cryptographic functions
+   - All methods delegating to crypto.py reviewed
+
+</details>
+
+---
+
+## Conclusion
+
+**ASVS 11.4.1 Compliance Status: ✅ PASS**
+
+The apache/steve codebase demonstrates exemplary compliance with ASVS 11.4.1 requirements. The codebase exclusively uses approved hash functions (BLAKE2b, SHA-256 via HKDF and Fernet, Argon2) for all cryptographic operations. No disallowed hash functions (MD5, SHA-1, etc.) are present in the code. 
+
+The cryptographic module is well-centralized in `crypto.py`, making hash function usage auditable and maintainable. The key derivation hierarchy is properly constructed with appropriate primitives for each use case. All random generation uses cryptographically secure sources.
+
+While the Argon2 variant selection (Type.D vs. Type.ID) represents a minor deviation from current best practices, it does not constitute a compliance violation as Argon2d remains within the approved Argon2 family.
+
+**No critical, high, medium, or low severity findings were identified.**
\ 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