mirror of
https://github.com/quexten/goldwarden.git
synced 2024-11-27 11:02:46 +03:00
Implement cipherkey decryption
This commit is contained in:
parent
f7e1cae015
commit
5d1192113a
@ -76,6 +76,8 @@ type Cipher struct {
|
||||
Login *LoginCipher `json:",omitempty"`
|
||||
Notes *crypto.EncString `json:",omitempty"`
|
||||
SecureNote *SecureNoteCipher `json:",omitempty"`
|
||||
|
||||
Key *crypto.EncString `json:",omitempty"`
|
||||
}
|
||||
|
||||
type CipherType int
|
||||
@ -147,8 +149,26 @@ type SecureNoteCipher struct {
|
||||
}
|
||||
|
||||
func (cipher Cipher) GetKeyForCipher(keyring crypto.Keyring) (crypto.SymmetricEncryptionKey, error) {
|
||||
var key1 crypto.SymmetricEncryptionKey = nil
|
||||
var err error
|
||||
if cipher.OrganizationID != nil {
|
||||
return keyring.GetSymmetricKeyForOrganization(cipher.OrganizationID.String())
|
||||
key1, err = keyring.GetSymmetricKeyForOrganization(cipher.OrganizationID.String())
|
||||
} else {
|
||||
key1, err = keyring.GetAccountKey(), nil
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if cipher.Key == nil {
|
||||
return key1, nil
|
||||
} else {
|
||||
key, err := crypto.DecryptWith(*cipher.Key, key1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return crypto.MemorySymmetricEncryptionKeyFromBytes(key)
|
||||
}
|
||||
}
|
||||
return keyring.GetAccountKey(), nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user