Skip to content

Commit

Permalink
Merge pull request #257 from quexten/feature/cipherkey-encryption
Browse files Browse the repository at this point in the history
Implement cipherkey decryption
  • Loading branch information
quexten authored Jul 19, 2024
2 parents fa4b735 + 5d11921 commit 3c3c549
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions cli/agent/bitwarden/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 3c3c549

Please sign in to comment.