Skip to content

Harden private key handling to prevent potential leaks#10

Merged
barrydeen merged 1 commit intomainfrom
security/private-key-hardening
Feb 19, 2026
Merged

Harden private key handling to prevent potential leaks#10
barrydeen merged 1 commit intomainfrom
security/private-key-hardening

Conversation

@barrydeen
Copy link
Copy Markdown
Owner

Summary

  • Disable Android backup (allowBackup="false") to prevent EncryptedSharedPreferences from being extracted via adb backup or Auto Backup
  • Harden Keypair class — redact privkey from toString(), derive hashCode() from pubkey only, add wipe() method
  • Add ByteArray.wipe() extension and use it to zero throwaway keys and conversation keys after use in NIP-17 gift wrap creation
  • Clear nsec on disposeDisposableEffect nulls out the revealed nsec string when the KeysScreen composable leaves composition
  • Sensitive clipboard flag — mark private key clipboard data as sensitive on API 33+ to hide it from clipboard previews
  • Secure LruCache eviction — override entryRemoved() on conversation key cache to zero evicted byte arrays

Test plan

  • Build and run on device/emulator
  • Login with nsec — verify key stored, app functional
  • Reveal key on KeysScreen — verify biometric prompt, nsec displayed, cleared on back navigation
  • Send/receive DMs — verify NIP-17 encryption still works after wipe() calls
  • Verify adb backup produces empty/no backup
  • Check logcat during all operations for any key leakage

🤖 Generated with Claude Code

- Disable Android backup to prevent EncryptedSharedPreferences extraction
- Redact privkey from Keypair toString(), use pubkey for hashCode()
- Add ByteArray.wipe() extension and use it to zero throwaway keys in NIP-17
- Clear nsec from Compose state on dispose to minimize memory exposure
- Mark clipboard as sensitive on API 33+ when copying private key
- Zero conversation keys on LruCache eviction in DmRepository
@barrydeen barrydeen merged commit d65cc16 into main Feb 19, 2026
@barrydeen barrydeen deleted the security/private-key-hardening branch March 4, 2026 01:29
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.

1 participant