feat: Phase 2 Security Enhancement

- pkg/crypto: AES-256-GCM encryption with PBKDF2 key derivation
  - 100k iterations, 16-byte salt, SHA-256
  - Encrypt/Decrypt/IsEncrypted/HashPassword
- Storage layer encryption:
  - JSONStorage.SetPassword() enables transparent encrypt/decrypt
  - readJSON auto-decrypts, replace* auto-encrypts
- pkg/knownhosts: TOFU host key verification
  - Verify/Add/Remove host keys
  - HostKeyCallback for SSH config
- SSH client security:
  - SetHostKeyCallback() replaces InsecureIgnoreHostKey()
  - SetPassphraseCallback() for encrypted private keys
  - getKeySigner() tries passphrase on encrypted keys
- Models: AppConfig gains EncryptionEnabled, PasswordHash, KnownHostsFile
This commit is contained in:
swanadiva
2026-06-25 13:28:46 +07:00
parent a1cd3d5dc0
commit 611b794fc7
7 changed files with 445 additions and 8 deletions
+32
View File
@@ -116,3 +116,35 @@
- Initial MVP release, all core features functional
- Encrypted storage planned for future release
- Interactive shell in Go SSH direct mode not yet available
## Phase 2 — Security Enhancement
### AES-256-GCM Encryption
- New `pkg/crypto/crypto.go`: AES-256-GCM encrypt/decrypt with PBKDF2 key derivation
- 100,000 iterations, 16-byte salt, SHA-256 key derivation
- `Encrypt(plaintext, password)` → base64(salt + nonce + ciphertext)
- `Decrypt(encoded, password)` → plaintext
- `IsEncrypted(data)` checks if data looks like encrypted content
### Storage Layer Encryption
- `JSONStorage` now has `password` field for master encryption key
- `SetPassword()`, `GetPassword()`, `IsEncrypted()` methods
- `readJSON()` auto-decrypts if password is set and data is encrypted
- `replaceHosts/KeyPairs/Snippets()` auto-encrypt before writing
- All existing CRUD operations transparently encrypt/decrypt
### Known Hosts Verification
- New `pkg/knownhosts/knownhosts.go`: TOFU (Trust-On-First-Use) model
- `KnownHosts` manages `known_hosts` file (JSON format)
- `Verify()` checks if host key matches stored key
- `HostKeyCallback()` returns `cryptossh.HostKeyCallback` for SSH config
- Warns on key mismatch (potential MITM attack)
### SSH Client Security
- `Client` now supports `hostKeyCallback` and `passphraseCallback`
- `SetHostKeyCallback()` — replaces `InsecureIgnoreHostKey()`
- `SetPassphraseCallback()` — prompts for passphrase on encrypted keys
- `getKeySigner()` tries passphrase callback if key is encrypted
### Models Updated
- `AppConfig`: added `EncryptionEnabled`, `PasswordHash`, `KnownHostsFile`