Skip to content

Commit

Permalink
more tests for encryption methods
Browse files Browse the repository at this point in the history
  • Loading branch information
maxlaverse committed Nov 14, 2024
1 parent 48a6f9f commit a6f79aa
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 113 deletions.
58 changes: 29 additions & 29 deletions internal/bitwarden/embedded/password_manager_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,34 +109,6 @@ func (v *baseVault) deleteObjectFromStore(ctx context.Context, obj models.Object
delete(v.objectStore, objKey(obj))
}

func (v *baseVault) encryptFolder(_ context.Context, obj models.Object, secret AccountSecrets) (*webapi.Folder, error) {
encFolderName, err := encryptAsStringIfNotEmpty(obj.Name, secret.MainKey)
if err != nil {
return nil, fmt.Errorf("error encrypting folder's name: %w", err)
}

encFolder := webapi.Folder{
Id: obj.ID,
Object: obj.Object,
RevisionDate: obj.RevisionDate,
Name: encFolderName,
}

if v.verifyObjectEncryption {
objForVerification, err := decryptFolder(encFolder, secret)
if err != nil {
return nil, fmt.Errorf("error decrypting folder for verification: %w", err)
}

err = compareObjects(obj, *objForVerification)
if err != nil {
return nil, fmt.Errorf("error verifying folder after encryption: %w", err)
}
}

return &encFolder, nil
}

func (v *baseVault) objectsLoaded() bool {
return v.objectStore != nil
}
Expand Down Expand Up @@ -372,7 +344,7 @@ func decryptItemLogin(objLogin models.Login, objectKey symmetrickey.Key) (*model
}, nil
}

func encryptCollection(obj models.Object, secret AccountSecrets, verifyObjectEncryption bool) (*webapi.OrganizationCreationRequest, error) {
func encryptCollection(_ context.Context, obj models.Object, secret AccountSecrets, verifyObjectEncryption bool) (*webapi.OrganizationCreationRequest, error) {
orgKey, err := secret.GetOrganizationKey(obj.OrganizationID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -416,6 +388,34 @@ func encryptCollection(obj models.Object, secret AccountSecrets, verifyObjectEnc

}

func encryptFolder(_ context.Context, obj models.Object, secret AccountSecrets, verifyObjectEncryption bool) (*webapi.Folder, error) {
encFolderName, err := encryptAsStringIfNotEmpty(obj.Name, secret.MainKey)
if err != nil {
return nil, fmt.Errorf("error encrypting folder's name: %w", err)
}

encFolder := webapi.Folder{
Id: obj.ID,
Object: obj.Object,
RevisionDate: obj.RevisionDate,
Name: encFolderName,
}

if verifyObjectEncryption {
objForVerification, err := decryptFolder(encFolder, secret)
if err != nil {
return nil, fmt.Errorf("error decrypting folder for verification: %w", err)
}

err = compareObjects(obj, *objForVerification)
if err != nil {
return nil, fmt.Errorf("error verifying folder after encryption: %w", err)
}
}

return &encFolder, nil
}

func encryptItem(_ context.Context, obj models.Object, secret AccountSecrets, verifyObjectEncryption bool) (*models.Object, error) {
objectKey, err := getOrCreateObjectKey(obj)
if err != nil {
Expand Down
Loading

0 comments on commit a6f79aa

Please sign in to comment.