Add support for new ssh key cipher type

This commit is contained in:
Bernd Schoolmann 2024-11-06 01:39:34 +01:00
parent eae9246310
commit dd063cc768
No known key found for this signature in database
3 changed files with 33 additions and 1 deletions

View File

@ -76,7 +76,8 @@ type Cipher struct {
Login *LoginCipher `json:"login,omitempty"` Login *LoginCipher `json:"login,omitempty"`
Notes *crypto.EncString `json:"notes,omitempty"` Notes *crypto.EncString `json:"notes,omitempty"`
SecureNote *SecureNoteCipher `json:"secureNote,omitempty"` SecureNote *SecureNoteCipher `json:"secureNote,omitempty"`
SSHKey *SSHKeyCipher `json:"sshKey,omitempty"`
Key *crypto.EncString `json:"key,omitempty"` Key *crypto.EncString `json:"key,omitempty"`
} }
@ -88,8 +89,15 @@ const (
CipherCard = 3 CipherCard = 3
CipherIdentity = 4 CipherIdentity = 4
CipherNote = 2 CipherNote = 2
CipherSSHKey = 5
) )
type SSHKeyCipher struct {
PrivateKey crypto.EncString `json:"privateKey"`
PublicKey crypto.EncString `json:"publicKey"`
KeyFingerprint crypto.EncString `json:"keyFingerprint"`
}
type Card struct { type Card struct {
CardholderName crypto.EncString `json:"cardholderName"` CardholderName crypto.EncString `json:"cardholderName"`
Brand crypto.EncString `json:"brand"` Brand crypto.EncString `json:"brand"`

View File

@ -59,6 +59,8 @@ func DoFullSync(ctx context.Context, vault *vault.Vault, config *config.Config,
vault.AddOrUpdateLogin(cipher) vault.AddOrUpdateLogin(cipher)
case models.CipherNote: case models.CipherNote:
vault.AddOrUpdateSecureNote(cipher) vault.AddOrUpdateSecureNote(cipher)
case models.CipherSSHKey:
vault.AddOrUpdateSSHKey(cipher)
} }
} }

View File

@ -19,6 +19,7 @@ type Vault struct {
Keyring *crypto.Keyring Keyring *crypto.Keyring
logins map[string]models.Cipher logins map[string]models.Cipher
secureNotes map[string]models.Cipher secureNotes map[string]models.Cipher
sshKeys map[string]models.Cipher
sshKeyNoteIDs []string sshKeyNoteIDs []string
envCredentials map[string]string envCredentials map[string]string
lastSynced int64 lastSynced int64
@ -31,6 +32,7 @@ func NewVault(keyring *crypto.Keyring) *Vault {
Keyring: keyring, Keyring: keyring,
logins: make(map[string]models.Cipher), logins: make(map[string]models.Cipher),
secureNotes: make(map[string]models.Cipher), secureNotes: make(map[string]models.Cipher),
sshKeys: make(map[string]models.Cipher),
sshKeyNoteIDs: make([]string, 0), sshKeyNoteIDs: make([]string, 0),
envCredentials: make(map[string]string), envCredentials: make(map[string]string),
lastSynced: 0, lastSynced: 0,
@ -92,6 +94,12 @@ func (vault *Vault) AddOrUpdateSecureNote(cipher models.Cipher) {
vault.unlockMutex() vault.unlockMutex()
} }
func (vault *Vault) AddOrUpdateSSHKey(cipher models.Cipher) {
vault.lockMutex()
vault.sshKeys[cipher.ID.String()] = cipher
vault.unlockMutex()
}
func (vault *Vault) isEnv(cipher models.Cipher) (string, bool) { func (vault *Vault) isEnv(cipher models.Cipher) (string, bool) {
if cipher.Type != models.CipherNote { if cipher.Type != models.CipherNote {
return "", false return "", false
@ -258,6 +266,20 @@ func (vault *Vault) GetSSHKeys() []SSHKey {
PublicKey: string(publicKey), PublicKey: string(publicKey),
}) })
} }
for id, _ := range vault.sshKeys {
key, _ := vault.sshKeys[id].GetKeyForCipher(*vault.Keyring)
privKey, _ := crypto.DecryptWith(vault.sshKeys[id].SSHKey.PrivateKey, key)
pubKey, _ := crypto.DecryptWith(vault.sshKeys[id].SSHKey.PublicKey, key)
name, _ := crypto.DecryptWith(vault.sshKeys[id].Name, key)
sshKeys = append(sshKeys, SSHKey{
Name: string(name),
Key: string(privKey),
PublicKey: string(pubKey),
})
}
return sshKeys return sshKeys
} }