feat(demo): add backend security controls - #55
Conversation
…network-notes' into feature/network-migration-demo-security
There was a problem hiding this comment.
Pull request overview
Adds demo-facing security controls for both MultipeerConnectivity and Network.framework backends, while keeping the demo’s connection-behavior selection independent. This fits the project’s “demo as a validated reference implementation” role by surfacing existing backend security modes and documenting their real trust boundaries (encryption vs authentication) without changing the public library API.
Changes:
- Introduces strict Base64 (no whitespace) TLS-PSK validation with a 32+ decoded-byte minimum and a test-key generator backed by
SecRandomCopyBytes. - Updates the demo UI to select backend-specific security modes, validate TLS-PSK inputs before Start, and avoid exposing key material in logs/status/accessibility.
- Expands documentation to describe demo security behavior and explicitly states that Multipeer and Network backends are not wire-compatible (interop remains report-only).
Reviewed changes
Copilot reviewed 10 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| Sources/PeerNetworkPSKConfiguration.swift | Maps validated Base64 PSK input into .preSharedKey network security configuration. |
| Sources/PeerNetworkPSKBase64.swift | Adds strict Base64 decode/length validation and in-memory test key generation. |
| PeerConnectivityTests/PeerNetworkPSKBase64Tests.swift | Adds focused unit tests for strict PSK validation, fail-closed mapping, and key generation success/failure. |
| PeerConnectivityDemo/ViewController.swift | Adds backend-specific security UI, PSK entry/generation, validation gating for Start, and updated status/log messaging. |
| PeerConnectivityDemo/README.md | Documents demo security modes, PSK handling/validation, and debug-only launch argument behavior. |
| README.md | Updates top-level demo instructions to include backend-specific security and non-interop note. |
| NetworkBackendGuide.md | Updates demo section to include security modes, strict PSK validation, and debug argument. |
| DemoSecurityAndInteroperabilityPlan.md | Adds plan/ADR-style doc for demo security UI and backend interoperability assessment (report-only). |
| PeerConnectivityDemo.xcodeproj/project.pbxproj | Adds new PSK helper sources to the demo target build. |
| PeerConnectivity.xcodeproj/project.pbxproj | Adds new PSK helper sources + tests to the library project build. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
Superseded by consolidated PR #56. No commits were discarded; this branch is preserved as a recovery and reference point. Addressed review findings were replied to and resolved before consolidation. |
Summary
SecRandomCopyBytesand surface generation failures.DemoSecurityAndInteroperabilityPlan.md; interoperability remains report-only because the backends use incompatible discovery, transport, framing, identity, invitation, and security protocols.Security behavior
.unauthenticated.PCNetworkPSKBase64is DEBUG-only and uses the same strict validator. Process arguments are documented as unsuitable for production secrets.Verification
swift test— 161 tests passed.xcodebuild test -project PeerConnectivity.xcodeproj -scheme PeerConnectivity -destination 'platform=iOS Simulator,name=iPhone 16,OS=18.3.1' -configuration Debug— 161 tests passed.Screenshots
Limitations