Security Testing Guide
Side-channel claim limit. Nothing on this page claims constant-time behaviour or side-channel resistance for any target: the side-channel harness covers nothing (finding A48) and no measurement exists. The Rust and C cores are designed for constant time and unmeasured; managed runtimes (JIT, GC, bounds checks) make no timing claim. Where this page names constant-time or side-channel techniques, in prose or in code, they are design intent or recommendations, not measured properties.
Overview
This guide provides instructions for running security tests and validations for MetaMUI Crypto Primitives.
Automated Security Checks
Pre-commit Hooks
Install and configure pre-commit hooks for automatic security checks:
# Install pre-commit
pip install pre-commit
# Install the git hooks
pre-commit install
# Run manually on all files
pre-commit run --all-files
CI/CD Security Pipeline
Security checks run automatically on:
- Every push to main/develop branches
- All pull requests
- Daily scheduled runs
View results in GitHub Actions:
- Go to Actions tab
- Select “Security Checks” workflow
- Review individual job results
Manual Security Testing
1. Rust Security Tests
cd metamui-crypto-rust
# Run security-specific tests
cargo test --package metamui-security
# Run clippy with security lints
cargo clippy --all-targets -- \
-D warnings \
-W clippy::unwrap_used \
-W clippy::expect_used
# Check for vulnerabilities in dependencies
cargo audit
# Analyze unsafe code usage
cargo geiger
# Run with address sanitizer
RUSTFLAGS="-Z sanitizer=address" cargo test --target x86_64-unknown-linux-gnu
2. Python Security Tests
cd metamui-crypto-python
# Run Bandit security scanner
bandit -r metamui_crypto -ll
# Check dependencies for vulnerabilities
safety check
# Run security-focused linting
pylint metamui_crypto --disable=all \
--enable=W0102,W0106,W0107,W0108,W0109,W0110,W0120,W0122,W0150,W0199
# Type checking for security
mypy metamui_crypto --strict
3. TypeScript Security Tests
cd metamui-crypto-typescript
# Install security plugin
pnpm add -D eslint-plugin-security
# Run ESLint with security rules
pnpm eslint . --ext .ts,.tsx \
--plugin security \
--rule 'security/detect-object-injection: error'
# Audit dependencies
pnpm audit --audit-level=moderate
# Type checking
pnpm typecheck
4. Timing Analysis
cd metamui-crypto-rust
# Run timing tests
cargo test --features timing-tests timing_analysis
# Use custom timing harness
cargo run --example timing_analysis
# Statistical analysis
python3 ../scripts/analyze_timing.py target/timing_results.json
5. Memory Safety
# Run with Valgrind (Linux)
valgrind --leak-check=full --show-leak-kinds=all \
./target/debug/test_binary
# Run with Miri (Rust)
cargo +nightly miri test --package metamui-security
# Check for memory leaks in Python
python3 -m pytest tests/ --memray
6. Fuzzing
cd metamui-crypto-rust
# Install cargo-fuzz
cargo +nightly install cargo-fuzz
# List available fuzzers
cargo fuzz list
# Run a specific fuzzer
cargo +nightly fuzz run aes256_fuzzer -- -max_total_time=300
# Run all fuzzers
for fuzzer in $(cargo fuzz list); do
cargo +nightly fuzz run $fuzzer -- -max_total_time=60
done
Security Test Scenarios
Constant-Time Verification
- Timing Tests
# Python example from metamui_crypto.testing import timing_test @timing_test(iterations=10000) def test_constant_time_compare(): # Test with different inputs # Should show no statistical correlation - Statistical Analysis
- Run operations with varying inputs
- Measure execution time
- Check for statistical anomalies
- Use dudect or similar tools
Memory Security Verification
- Zeroing Tests
#[test] fn test_memory_cleared() { let secret = SecretKey::new(); let ptr = &secret as *const _ as *const u8; drop(secret); // Verify memory is zeroed } - Leak Detection
- Use memory profilers
- Check for dangling pointers
- Verify cleanup in destructors
Side-Channel Resistance
- Cache Timing
- Test with cache flush/reload
- Measure access patterns
- Verify no secret-dependent accesses
- Power Analysis
- Simulate power traces
- Check Hamming weight balance
- Verify masking effectiveness
Security Regression Tests
Adding New Security Tests
- Create test in appropriate module
- Tag with
#[security_test]or similar - Add to CI/CD pipeline
- Document expected behavior
Test Categories
- Unit Tests: Individual function security
- Integration Tests: Cross-module security
- Property Tests: Security invariants
- Fuzz Tests: Edge case discovery
Security Metrics
Coverage Requirements
- Security-critical code: 100% coverage
- Constant-time operations: not claimed (unmeasured, A48)
- Input validation: 95%+ coverage
- Overall: 90%+ coverage
Performance Benchmarks
Track security overhead:
# Run benchmarks
cargo bench --features security-benchmarks
# Compare results
python3 scripts/compare_benchmarks.py \
results/baseline.json \
results/with_security.json
Reporting Security Issues
Internal Process
- Run full security test suite
- Document any failures
- Create issue with
securitylabel - Assign to security team
External Reporting
- Email: security@metamui.id
- PGP key available on request
- Use responsible disclosure
Security Test Checklist
Before each release:
- All security tests passing
- No new unsafe code without justification
- Third-party dependencies on the allow-list (
documents/public-release/third-party-dependencies.csv) - Timing analysis run and its record filed (none exists today: the side-channel axis is unmeasured, A48)
- Memory-safety findings dispositioned in the findings register
- Fuzzing run and its record filed under
documents/public-release/evidence/205-fuzz/ - Security benchmarks within limits
- Documentation updated
Tools and Resources
Required Tools
- Rust: cargo-audit, cargo-geiger, clippy
- Python: bandit, safety, pylint
- TypeScript: eslint-plugin-security
- General: valgrind, AFL++, dudect
Recommended Reading
Continuous Improvement
Monthly Tasks
- Review and update security tests
- Analyze new attack vectors
- Update dependencies
- Run extended fuzzing
Quarterly Tasks
- Full security audit
- Performance regression analysis
- Update threat model
- Training and knowledge sharing