clients icon indicating copy to clipboard operation
clients copied to clipboard

[PS-1203] Call hasKey() to determine if vault is locked

Open kbialek opened this issue 2 years ago • 4 comments

Type of change

- [X] Bug fix
- [ ] New feature development
- [ ] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other

Objective

Fix for https://github.com/bitwarden/clients/issues/2729

I clearly admit that I do not have good understanding of this codebase. This proposal is a result of my experiments.

Code changes

  • auth.service.ts: Use hasKey() instead of hasKeyInMemory() to verify if vault is unlocked

Screenshots

Before you submit

- [ ] I have checked for **linting** errors (`npm run lint`) (required)
- [ ] I have added **unit tests** where it makes sense to do so (encouraged but not required)
- [ ] This change requires a **documentation update** (notify the documentation team)
- [ ] This change has particular **deployment requirements** (notify the DevOps team)

kbialek avatar Jul 08 '22 06:07 kbialek

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Jul 08 '22 06:07 CLAassistant

Hi @kbialek,

Unfortunately while this might solve the linked error it will introduce other issues, primarily around account switching. getAuthStatus has an optional parameter userId which is passed along to hasKeyInMemory. While hasKey just checks if the currently active account is locked.

Hinton avatar Jul 08 '22 08:07 Hinton

Hi @Hinton

Okay, I get the point. In my latest commit I've enhanced getKey() method to also accept optional userId. WDYT?

kbialek avatar Jul 09 '22 15:07 kbialek

Hey,

is there any update for this? I've looked into this issue as well, the provided implementation here also makes the workaround below obsolete, this code snippet is not required anymore and is correct due to the check with the getEverBeenUnlocked function.

https://github.com/bitwarden/clients/blob/25caeaa26f21c4d6aca74436fd82dd6eebc9d2b5/libs/common/src/services/auth.service.ts#L168-L177

Even tho the check is unrequired, without the additional check it would also match the exact behaviour already used throughout the CLI, for example when running the bw list items command.

https://github.com/bitwarden/clients/blob/25caeaa26f21c4d6aca74436fd82dd6eebc9d2b5/apps/cli/src/program.ts#L513-L522

If this implementation is used throughout the application the workaround in getKey where it also sets the symmetric key can be phased out.

https://github.com/bitwarden/clients/blob/25caeaa26f21c4d6aca74436fd82dd6eebc9d2b5/libs/common/src/services/crypto.service.ts#L96-L112

/cc @Hinton, @djsmith85

shawnfunke avatar Sep 20 '22 17:09 shawnfunke

Can we get an update on this? This broke one of my CI automation workflows.

sgallagher avatar Oct 05 '22 18:10 sgallagher

Hi,

I took a quick look at the proposed change, and it seems to completely break the desktop application.

I don't believe hasKey is the right method to determine the CLI lock status. That method checks for existence of both automatic and biometric keys stored in secure storage, which the CLI does not support.

A better way to approach this is to do some pre-precessing in some common code path (maybe exitIfLocked) to load in the BW_SESSION variable and attempt to decrypt the account key.

Hinton avatar Oct 25 '22 09:10 Hinton

@Hinton Thanks for having a look. Could you shortly explain what do you mean by that?

it seems to completely break the desktop application.

I built the desktop client locally from the latest master with the fix applied and it is working fine.

A better way to approach this is to do some pre-precessing in some common code path (maybe exitIfLocked) to load in the BW_SESSION variable and attempt to decrypt the account key.

Imo, loading BW_SESSION is not the right approach, as the session key can also be provided as a CLI argument

kbialek avatar Oct 26 '22 20:10 kbialek

Could all the reviewers and contributors have another look at the PR? This issue https://github.com/bitwarden/clients/issues/2729 is really annoying.

milkpirate avatar Jan 30 '24 21:01 milkpirate

@kbialek Thank you for your contribution

Closing this, as the issue seems to be resolved with 2024.2 as per your comment

Kind regards, Daniel

djsmith85 avatar Feb 23 '24 11:02 djsmith85