-
Notifications
You must be signed in to change notification settings - Fork 10
Add-userid-to-encryption-methods #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The API changes would require an dwell time for the server to populate the userId field in Identity success responses. However, these API endpoints are not yet used by the SDK.
This is not the owning entity of the key, but the user that is unlocked that triggered the request
Great job, no security vulnerabilities found in this Pull Request |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #278 +/- ##
==========================================
+ Coverage 69.83% 69.93% +0.10%
==========================================
Files 213 214 +1
Lines 16809 16989 +180
==========================================
+ Hits 11738 11882 +144
- Misses 5071 5107 +36 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
UserId must either be optional or pulled from the auth token. Since the auth token is meant to be opaque to the client, I'm making user id optional. Cipher decryption will fail if it is not included, though.
49dcf86
to
2f18679
Compare
108a702
to
276a6cc
Compare
If we want this, we'll have to parse the auth token
276a6cc
to
edf8961
Compare
pub fn set_user_id(&self, user_id: Uuid) { | ||
*self.user_id.write().expect("RwLock is not poisoned") = Some(user_id); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue?: it seems odd to have a public function that changes the user_id
without any additional context required. I feel like the user_id
should only ever change when the client is initialized and possibly never again after that. Maybe there's some edge case where we'd want a client without Crypto but tied to a user? If that is the case then I think this function should instead be called something like init_user_id()
and only allow itself to be called once. However, it's probably more likely that we'll split up the client into user and non-user scoped clients and then just require the user_id
on creation.
Either way, I think we should remove the ability to change the user_id
. My opinion is that it should be bundled into the initialize_user_crypto
functions below, but I'm not married to that solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I agree, separate user-bound and non-user bounds clients would allow us to require user id during construction and enforce no changes to it, until we have those we can use a OnceLock
to ensure the ID is only initialized once:
pub(crate) user_id: OnceLock<Uuid>,
pub fn init_user_id(&self, user_id: Uuid) -> Result<(), UserIdAlreadySetError> {
self.user_id
.set(user_id)
.map_err(|_| UserIdAlreadySetError)
}
pub fn get_user_id(&self) -> Option<Uuid> {
self.user_id.get().map(|x| *x)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There definitely are user-bound, but not crypto-inited clients -- that's a locked SDK.
The thought was, that I only need the UserId
during encryption (for now) and I'm not 100% familiar with our current usages and I wanted to minimize the impact of the breaking change.
I can certainly revise. I agree it makes sense to init userId only once -- that's an easy change -- Actually making the pure, environment-bound, and user-bound client contexts feel out of scope here, though. Do you agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes splitting them up is way out of scope, we're gonna be working on that with Auth if I remember correctly. I was just thinking ahead a little, I could've been a little clearer there :) I think OnceLock
that Dani suggested is a perfectly sound solution until we eventually start splitting stuff
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is done (468bcda), but there is an unfortunate side effect that crypto initialization can now error with a userId already set.
This will have to be updated once the clients are split, but for now is in line with the expectation that UserId is sent into crypto initialization. Once I implemented it, I got to thinking that for the same reasons it makes sense to error should multiple init_user_crypto
requests be sent into a single client, so hopefully this can just morph into a CryptoAlreadyInitialized
error or some such.
3413a56
to
0d0b707
Compare
0d0b707
to
468bcda
Compare
|
This commit updates several functions to accept an `encryptedFor` parameter, which specifies the user ID for whom the cipher is encrypted. This property is used by the server to verify the cipher is encrypted by the correct user. If verification fails the server responds with an appropriate error message. This change affects the following: - `toEncryptedNetworkCipher` and `toEncryptedNetworkCipherResponse` extension functions for `Cipher` now require an `encryptedFor` parameter. - `CipherJsonRequest` and `SyncResponseJson.Cipher` now include an `encryptedFor` field. - SDK functions like `encryptCipher` and `decryptFile` have been updated to align with these changes. Additionally, this update includes the following SDK related changes: - Adding the `encryptedFor` related logic (bitwarden/sdk-internal#278) - Update in protocol and objects naming to have ``{foo}Client[Protocol]`` instead of `Client{foo}[Protocol]` (bitwarden/sdk-internal#224) - Update attachments decryption to use `AttachmentView` instead of `Attachment` (bitwarden/sdk-internal#255)
This commit updates several functions to accept an `encryptedFor` parameter, which specifies the user ID for whom the cipher is encrypted. This property is used by the server to verify the cipher is encrypted by the correct user. If verification fails the server responds with an appropriate error message. This change affects the following: - `toEncryptedNetworkCipher` and `toEncryptedNetworkCipherResponse` extension functions for `Cipher` now require an `encryptedFor` parameter. - `CipherJsonRequest` and `SyncResponseJson.Cipher` now include an `encryptedFor` field. - SDK functions like `encryptCipher` and `decryptFile` have been updated to align with these changes. Additionally, this update includes the following SDK related changes: - Adding the `encryptedFor` related logic (bitwarden/sdk-internal#278) - Update in protocol and objects naming to have ``{foo}Client[Protocol]`` instead of `Client{foo}[Protocol]` (bitwarden/sdk-internal#224) - Update attachments decryption to use `AttachmentView` instead of `Attachment` (bitwarden/sdk-internal#255)
This commit updates several functions to accept an `encryptedFor` parameter, which specifies the user ID for whom the cipher is encrypted. This property is used by the server to verify the cipher is encrypted by the correct user. If verification fails the server responds with an appropriate error message. This change affects the following: - `toEncryptedNetworkCipher` and `toEncryptedNetworkCipherResponse` extension functions for `Cipher` now require an `encryptedFor` parameter. - `CipherJsonRequest` and `SyncResponseJson.Cipher` now include an `encryptedFor` field. - SDK functions like `encryptCipher` and `decryptFile` have been updated to align with these changes. Additionally, this update includes the following SDK related changes: - Adding the `encryptedFor` related logic (bitwarden/sdk-internal#278) - Update in protocol and objects naming to have ``{foo}Client[Protocol]`` instead of `Client{foo}[Protocol]` (bitwarden/sdk-internal#224) - Update attachments decryption to use `AttachmentView` instead of `Attachment` (bitwarden/sdk-internal#255)
This commit updates several functions to accept an `encryptedFor` parameter, which specifies the user ID for whom the cipher is encrypted. This property is used by the server to verify the cipher is encrypted by the correct user. If verification fails the server responds with an appropriate error message. This change affects the following: - `toEncryptedNetworkCipher` and `toEncryptedNetworkCipherResponse` extension functions for `Cipher` now require an `encryptedFor` parameter. - `CipherJsonRequest` and `SyncResponseJson.Cipher` now include an `encryptedFor` field. - SDK functions like `encryptCipher` and `decryptFile` have been updated to align with these changes. Additionally, this update includes the following SDK related changes: - Adding the `encryptedFor` related logic (bitwarden/sdk-internal#278) - Update in protocol and objects naming to have ``{foo}Client[Protocol]`` instead of `Client{foo}[Protocol]` (bitwarden/sdk-internal#224) - Update attachments decryption to use `AttachmentView` instead of `Attachment` (bitwarden/sdk-internal#255)
This commit updates several functions to accept an `encryptedFor` parameter, which specifies the user ID for whom the cipher is encrypted. This property is used by the server to verify the cipher is encrypted by the correct user. If verification fails the server responds with an appropriate error message. This change affects the following: - `toEncryptedNetworkCipher` and `toEncryptedNetworkCipherResponse` extension functions for `Cipher` now require an `encryptedFor` parameter. - `CipherJsonRequest` and `SyncResponseJson.Cipher` now include an `encryptedFor` field. - SDK functions like `encryptCipher` and `decryptFile` have been updated to align with these changes. Additionally, this update includes the following SDK related changes: - Adding the `encryptedFor` related logic (bitwarden/sdk-internal#278) - Update in protocol and objects naming to have ``{foo}Client[Protocol]`` instead of `Client{foo}[Protocol]` (bitwarden/sdk-internal#224) - Update attachments decryption to use `AttachmentView` instead of `Attachment` (bitwarden/sdk-internal#255)
This commit updates several functions to accept an `encryptedFor` parameter, which specifies the user ID for whom the cipher is encrypted. This property is used by the server to verify the cipher is encrypted by the correct user. If verification fails the server responds with an appropriate error message. This change affects the following: - `toEncryptedNetworkCipher` and `toEncryptedNetworkCipherResponse` extension functions for `Cipher` now require an `encryptedFor` parameter. - `CipherJsonRequest` and `SyncResponseJson.Cipher` now include an `encryptedFor` field. - SDK functions like `encryptCipher` and `decryptFile` have been updated to align with these changes. Additionally, this update includes the following SDK related changes: - Adding the `encryptedFor` related logic (bitwarden/sdk-internal#278) - Update in protocol and objects naming to have ``{foo}Client[Protocol]`` instead of `Client{foo}[Protocol]` (bitwarden/sdk-internal#224) - Update attachments decryption to use `AttachmentView` instead of `Attachment` (bitwarden/sdk-internal#255)
This is not the owning entity of the key, but the user that is unlocked that triggered the request
🎟️ Tracking
📔 Objective
⏰ Reminders before review
team
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmedissue and could potentially benefit from discussion
:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes