Merge pull request #257 from quexten/feature/cipherkey-encryption

Implement cipherkey decryption
This commit is contained in:
Bernd Schoolmann 2024-07-20 00:37:32 +02:00 committed by GitHub
commit 3c3c54906a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 22 additions and 2 deletions

View File

@ -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
}