Merge pull request #257 from quexten/feature/cipherkey-encryption
Implement cipherkey decryption
This commit is contained in:
commit
3c3c54906a
|
@ -76,6 +76,8 @@ type Cipher struct {
|
||||||
Login *LoginCipher `json:",omitempty"`
|
Login *LoginCipher `json:",omitempty"`
|
||||||
Notes *crypto.EncString `json:",omitempty"`
|
Notes *crypto.EncString `json:",omitempty"`
|
||||||
SecureNote *SecureNoteCipher `json:",omitempty"`
|
SecureNote *SecureNoteCipher `json:",omitempty"`
|
||||||
|
|
||||||
|
Key *crypto.EncString `json:",omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CipherType int
|
type CipherType int
|
||||||
|
@ -147,8 +149,26 @@ type SecureNoteCipher struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cipher Cipher) GetKeyForCipher(keyring crypto.Keyring) (crypto.SymmetricEncryptionKey, error) {
|
func (cipher Cipher) GetKeyForCipher(keyring crypto.Keyring) (crypto.SymmetricEncryptionKey, error) {
|
||||||
|
var key1 crypto.SymmetricEncryptionKey = nil
|
||||||
|
var err error
|
||||||
if cipher.OrganizationID != nil {
|
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