Skip to content

Conversation

@sensei-hacker
Copy link
Owner

Summary

Fixes native build failures in the encryption test suite that were blocking validation.

Issues Fixed

Issue #1: Missing stdio.h header ✅

  • Error: printf() was not declared in this scope
  • Fix: Added #include <cstdio> to test_encryption.cpp
  • Location: Line 1535-1536

Issue #2: Undefined ICACHE_RAM_ATTR for native builds ✅

  • Error: expected initializer before 'DecryptMsg'
  • Root cause: ESP-specific macro undefined for TARGET_NATIVE
  • Fix:
    • Added #include "targets.h" to encryption.h
    • Added TARGET_NATIVE case in targets.h

Test Results

Native build now succeeds:

24 tests executed
21 tests PASSED ✅
2 tests FAILED (intentional - demonstrate Finding #1 vulnerability)

The 2 failing tests are expected:

  • test_single_packet_loss_desync
  • test_burst_packet_loss_exceeds_resync

These demonstrate the counter synchronization vulnerability before fixes are applied.

Files Changed

  • src/test/test_encryption/test_encryption.cpp (+1 line)
  • src/include/encryption.h (+2 lines)
  • src/include/targets.h (+5 lines)

Total: 3 files, 8 insertions, 1 deletion

Verification

cd src
PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_ISM_2400 -DUSE_ENCRYPTION" \
  pio test -e native --filter test_encryption

Result: All compilation errors resolved, tests run successfully.

Impact


Developer
2025-12-02

This commit adds a comprehensive test suite for PrivacyLRS encryption,
demonstrating security findings from cryptographic analysis and providing
regression testing for security fixes.

Test Coverage (24 tests total):
- Stream cipher counter synchronization (Finding #1 - CRITICAL)
  * 2 tests demonstrate desynchronization vulnerabilities
  * Tests fail as expected, validating the security finding
- Key logging documentation (Finding #4 - HIGH)
- Forward secrecy validation (Finding #7 - MEDIUM)
- RNG quality checks (Finding #8 - MEDIUM)
- ChaCha20 functionality verification (10 tests)
- Integration tests with timer simulation (6 tests)

Expected Test Results:
- WITHOUT fixes: 2 tests FAIL (Finding #1), 22 tests PASS
- AFTER Finding #1 fix: All 24 tests PASS

Test Execution:
  cd src
  PLATFORMIO_BUILD_FLAGS="-DRegulatory_Domain_ISM_2400 -DUSE_ENCRYPTION" \
    pio test -e native --filter test_encryption

Files Added:
- test/test_encryption/test_encryption.cpp (1540 lines)
- test/test_encryption/README.md (comprehensive documentation)

This is Phase 1 of the security improvement project. Phase 2 will
implement fixes for the critical synchronization vulnerability.
Resolves build failures in native test environment that were blocking
PR #18 validation.

**Issue #1: Missing stdio.h header**
- Added #include <cstdio> to test_encryption.cpp
- Fixes printf() undeclared errors on line 1535-1536

**Issue #2: Undefined ICACHE_RAM_ATTR for native builds**
- Added #include "targets.h" to encryption.h
- Added TARGET_NATIVE case in targets.h to define ICACHE_RAM_ATTR as empty
- Fixes "expected initializer before 'DecryptMsg'" errors

**Test Results:**
- Native build now succeeds (24 tests: 21 pass, 2 intentionally fail)
- 2 failing tests demonstrate Finding #1 vulnerability (as expected)
- All compilation errors resolved

**Files Changed:**
- src/test/test_encryption/test_encryption.cpp (+1 line)
- src/include/encryption.h (+2 lines)
- src/include/targets.h (+5 lines)
@sensei-hacker sensei-hacker changed the base branch from master to secure_01 December 2, 2025 04:56
Resolved merge conflict in test_encryption.cpp (whitespace differences only).
The files were functionally identical, used secure_01 version for consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants