Files
HostKeeper/internal/models/models.go
T
swanadiva 611b794fc7 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
2026-06-25 13:28:46 +07:00

89 lines
2.9 KiB
Go

package models
import (
"time"
)
// Host represents an SSH host connection configuration
type Host struct {
ID string `json:"id"`
Name string `json:"name"`
Hostname string `json:"hostname"`
Port int `json:"port"`
Username string `json:"username"`
Auth AuthConfig `json:"auth"`
Group string `json:"group,omitempty"`
Tags []string `json:"tags,omitempty"`
Notes string `json:"notes,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
LastUsedAt *time.Time `json:"last_used_at,omitempty"`
}
// AuthConfig represents authentication configuration
type AuthConfig struct {
Type string `json:"type"` // "password", "key", "both"
Password string `json:"password,omitempty"`
KeyID string `json:"key_id,omitempty"` // Reference to KeyPair ID
}
// KeyPair represents an SSH key pair
type KeyPair struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"` // "rsa", "ed25519", "ecdsa"
PrivateKey string `json:"private_key"`
PublicKey string `json:"public_key,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// Snippet represents a command snippet
type Snippet struct {
ID string `json:"id"`
Name string `json:"name"`
Command string `json:"command"`
Description string `json:"description,omitempty"`
Tags []string `json:"tags,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// AppConfig represents the application configuration
type AppConfig struct {
Version string `json:"version"`
DefaultPort int `json:"default_port"`
ConnectionTimeout int `json:"connection_timeout"` // in seconds
Theme string `json:"theme"`
Editor string `json:"editor"`
AutoSync bool `json:"auto_sync"`
SyncProvider string `json:"sync_provider,omitempty"`
// Security
EncryptionEnabled bool `json:"encryption_enabled"`
PasswordHash string `json:"password_hash,omitempty"` // SHA-256 hash for verification
KnownHostsFile string `json:"known_hosts_file,omitempty"`
}
// KnownHost represents a verified host key
type KnownHost struct {
Hostname string `json:"hostname"`
Port int `json:"port"`
KeyType string `json:"key_type"` // "ssh-rsa", "ssh-ed25519", etc.
KeyHash string `json:"key_hash"` // Base64-encoded host key
AddedAt time.Time `json:"added_at"`
}
// DefaultConfig returns the default application configuration
func DefaultConfig() *AppConfig {
return &AppConfig{
Version: "1.0.0",
DefaultPort: 22,
ConnectionTimeout: 30,
Theme: "dark",
Editor: "vim",
AutoSync: false,
EncryptionEnabled: false,
}
}