Skip to content

Commit a512712

Browse files
committed
Merge branch 'main' of github.com:bitwarden/sdk-internal into arch/more-uuids
# Conflicts: # crates/bitwarden-core/src/key_management/crypto.rs
2 parents 053de35 + c9bd7f9 commit a512712

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+3213
-454
lines changed

.github/CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
crates/bitwarden-vault/** @bitwarden/team-vault-dev @bitwarden/team-platform-dev
1111

12+
# Temporarily owned by multiple teams
13+
/crates/bitwarden-crypto/ @bitwarden/team-platform-dev @bitwarden/dept-architecture @bitwarden/team-key-management-dev
14+
1215
# BRE for publish workflow changes
1316
.github/workflows/publish-*.yml @bitwarden/dept-bre
1417
.github/workflows/release-rust-crates.yml @bitwarden/dept-bre

.github/workflows/lint.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches: ["main"]
77
pull_request:
88

9+
permissions: {}
10+
911
env:
1012
CARGO_TERM_COLOR: always
1113

@@ -15,6 +17,10 @@ jobs:
1517

1618
runs-on: ubuntu-24.04
1719

20+
permissions:
21+
contents: read
22+
security-events: write
23+
1824
steps:
1925
- name: Checkout
2026
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
@@ -54,7 +60,7 @@ jobs:
5460
run: cargo install clippy-sarif sarif-fmt --locked --git https://github.com/psastras/sarif-rs.git --rev 11c33a53f6ffeaed736856b86fb6b7b09fabdfd8
5561

5662
- name: Cargo clippy-sarif
57-
run: cargo clippy --all-features --tests --message-format=json |
63+
run: cargo clippy --all-features --all-targets --message-format=json |
5864
clippy-sarif | tee clippy_result.sarif | sarif-fmt
5965
env:
6066
RUSTFLAGS: "-D warnings"
@@ -70,7 +76,7 @@ jobs:
7076
# status code of the command is caught and reported as failed in GitHub.
7177
# This should be cached from the previous step and should be fast.
7278
- name: Cargo clippy
73-
run: cargo clippy --all-features --tests
79+
run: cargo clippy --all-features --all-targets
7480
env:
7581
RUSTFLAGS: "-D warnings"
7682

Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ export RUSTFLAGS="-D warnings"
144144
145145
cargo +nightly fmt --check
146146
cargo +nightly udeps --workspace --all-features
147-
cargo clippy --all-features --tests
147+
cargo clippy --all-features --all-targets
148148
cargo sort --workspace --check
149149
npm run lint
150150
```

crates/bitwarden-core/src/auth/auth_request.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use base64::{engine::general_purpose::STANDARD, Engine};
22
use bitwarden_crypto::{
33
fingerprint, generate_random_alphanumeric, AsymmetricCryptoKey, AsymmetricPublicCryptoKey,
4-
CryptoError, UnsignedSharedKey,
4+
CryptoError, PublicKeyEncryptionAlgorithm, UnsignedSharedKey,
55
};
66
#[cfg(feature = "internal")]
77
use bitwarden_crypto::{EncString, SymmetricCryptoKey};
@@ -31,11 +31,9 @@ pub struct AuthRequestResponse {
3131
/// to another device. Where the user confirms the validity by confirming the fingerprint. The user
3232
/// key is then encrypted using the public key and returned to the initiating device.
3333
pub(crate) fn new_auth_request(email: &str) -> Result<AuthRequestResponse, CryptoError> {
34-
let mut rng = rand::thread_rng();
34+
let key = AsymmetricCryptoKey::make(PublicKeyEncryptionAlgorithm::RsaOaepSha1);
3535

36-
let key = AsymmetricCryptoKey::generate(&mut rng);
37-
38-
let spki = key.to_public_der()?;
36+
let spki = key.to_public_key().to_der()?;
3937

4038
let fingerprint = fingerprint(email, &spki)?;
4139
let b64 = STANDARD.encode(&spki);
@@ -124,7 +122,7 @@ fn test_auth_request() {
124122

125123
let encrypted = UnsignedSharedKey::encapsulate_key_unsigned(
126124
&SymmetricCryptoKey::try_from(secret.clone()).unwrap(),
127-
&private_key,
125+
&private_key.to_public_key(),
128126
)
129127
.unwrap();
130128

@@ -165,7 +163,7 @@ mod tests {
165163
let private_key ="2.yN7l00BOlUE0Sb0M//Q53w==|EwKG/BduQRQ33Izqc/ogoBROIoI5dmgrxSo82sgzgAMIBt3A2FZ9vPRMY+GWT85JiqytDitGR3TqwnFUBhKUpRRAq4x7rA6A1arHrFp5Tp1p21O3SfjtvB3quiOKbqWk6ZaU1Np9HwqwAecddFcB0YyBEiRX3VwF2pgpAdiPbSMuvo2qIgyob0CUoC/h4Bz1be7Qa7B0Xw9/fMKkB1LpOm925lzqosyMQM62YpMGkjMsbZz0uPopu32fxzDWSPr+kekNNyLt9InGhTpxLmq1go/pXR2uw5dfpXc5yuta7DB0EGBwnQ8Vl5HPdDooqOTD9I1jE0mRyuBpWTTI3FRnu3JUh3rIyGBJhUmHqGZvw2CKdqHCIrQeQkkEYqOeJRJVdBjhv5KGJifqT3BFRwX/YFJIChAQpebNQKXe/0kPivWokHWwXlDB7S7mBZzhaAPidZvnuIhalE2qmTypDwHy22FyqV58T8MGGMchcASDi/QXI6kcdpJzPXSeU9o+NC68QDlOIrMVxKFeE7w7PvVmAaxEo0YwmuAzzKy9QpdlK0aab/xEi8V4iXj4hGepqAvHkXIQd+r3FNeiLfllkb61p6WTjr5urcmDQMR94/wYoilpG5OlybHdbhsYHvIzYoLrC7fzl630gcO6t4nM24vdB6Ymg9BVpEgKRAxSbE62Tqacxqnz9AcmgItb48NiR/He3n3ydGjPYuKk/ihZMgEwAEZvSlNxYONSbYrIGDtOY+8Nbt6KiH3l06wjZW8tcmFeVlWv+tWotnTY9IqlAfvNVTjtsobqtQnvsiDjdEVtNy/s2ci5TH+NdZluca2OVEr91Wayxh70kpM6ib4UGbfdmGgCo74gtKvKSJU0rTHakQ5L9JlaSDD5FamBRyI0qfL43Ad9qOUZ8DaffDCyuaVyuqk7cz9HwmEmvWU3VQ+5t06n/5kRDXttcw8w+3qClEEdGo1KeENcnXCB32dQe3tDTFpuAIMLqwXs6FhpawfZ5kPYvLPczGWaqftIs/RXJ/EltGc0ugw2dmTLpoQhCqrcKEBDoYVk0LDZKsnzitOGdi9mOWse7Se8798ib1UsHFUjGzISEt6upestxOeupSTOh0v4+AjXbDzRUyogHww3V+Bqg71bkcMxtB+WM+pn1XNbVTyl9NR040nhP7KEf6e9ruXAtmrBC2ah5cFEpLIot77VFZ9ilLuitSz+7T8n1yAh1IEG6xxXxninAZIzi2qGbH69O5RSpOJuJTv17zTLJQIIc781JwQ2TTwTGnx5wZLbffhCasowJKd2EVcyMJyhz6ru0PvXWJ4hUdkARJs3Xu8dus9a86N8Xk6aAPzBDqzYb1vyFIfBxP0oO8xFHgd30Cgmz8UrSE3qeWRrF8ftrI6xQnFjHBGWD/JWSvd6YMcQED0aVuQkuNW9ST/DzQThPzRfPUoiL10yAmV7Ytu4fR3x2sF0Yfi87YhHFuCMpV/DsqxmUizyiJuD938eRcH8hzR/VO53Qo3UIsqOLcyXtTv6THjSlTopQ+JOLOnHm1w8dzYbLN44OG44rRsbihMUQp+wUZ6bsI8rrOnm9WErzkbQFbrfAINdoCiNa6cimYIjvvnMTaFWNymqY1vZxGztQiMiHiHYwTfwHTXrb9j0uPM=|09J28iXv9oWzYtzK2LBT6Yht4IT4MijEkk0fwFdrVQ4=".parse().unwrap();
166164
client
167165
.internal
168-
.initialize_user_crypto_master_key(master_key, user_key, private_key)
166+
.initialize_user_crypto_master_key(master_key, user_key, private_key, None)
169167
.unwrap();
170168

171169
let public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvyLRDUwXB4BfQ507D4meFPmwn5zwy3IqTPJO4plrrhnclWahXa240BzyFW9gHgYu+Jrgms5xBfRTBMcEsqqNm7+JpB6C1B6yvnik0DpJgWQw1rwvy4SUYidpR/AWbQi47n/hvnmzI/sQxGddVfvWu1iTKOlf5blbKYAXnUE5DZBGnrWfacNXwRRdtP06tFB0LwDgw+91CeLSJ9py6dm1qX5JIxoO8StJOQl65goLCdrTWlox+0Jh4xFUfCkb+s3px+OhSCzJbvG/hlrSRcUz5GnwlCEyF3v5lfUtV96MJD+78d8pmH6CfFAp2wxKRAbGdk+JccJYO6y6oIXd3Fm7twIDAQAB";
@@ -232,7 +230,7 @@ mod tests {
232230

233231
existing_device
234232
.internal
235-
.initialize_user_crypto_master_key(master_key, user_key, private_key.clone())
233+
.initialize_user_crypto_master_key(master_key, user_key, private_key.clone(), None)
236234
.unwrap();
237235

238236
// Initialize a new device which will request to be logged in
@@ -250,6 +248,7 @@ mod tests {
250248
kdf_params: kdf,
251249
email: email.to_owned(),
252250
private_key,
251+
signing_key: None,
253252
method: InitUserCryptoMethod::AuthRequest {
254253
request_private_key: auth_req.private_key,
255254
method: AuthRequestMethod::UserKey {

crates/bitwarden-core/src/auth/login/api_key.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ pub(crate) async fn login_api_key(
5151
let user_key: EncString = require!(r.key.as_deref()).parse()?;
5252
let private_key: EncString = require!(r.private_key.as_deref()).parse()?;
5353

54-
client
55-
.internal
56-
.initialize_user_crypto_master_key(master_key, user_key, private_key)?;
54+
client.internal.initialize_user_crypto_master_key(
55+
master_key,
56+
user_key,
57+
private_key,
58+
None,
59+
)?;
5760
}
5861

5962
Ok(ApiKeyLoginResponse::process_response(response))

crates/bitwarden-core/src/auth/login/auth_request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub(crate) async fn complete_auth_request(
120120
kdf_params: kdf,
121121
email: auth_req.email,
122122
private_key: require!(r.private_key).parse()?,
123+
signing_key: None,
123124
method: InitUserCryptoMethod::AuthRequest {
124125
request_private_key: auth_req.private_key,
125126
method,

crates/bitwarden-core/src/auth/login/password.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,12 @@ pub(crate) async fn login_password(
5050
let user_key: EncString = require!(r.key.as_deref()).parse()?;
5151
let private_key: EncString = require!(r.private_key.as_deref()).parse()?;
5252

53-
client
54-
.internal
55-
.initialize_user_crypto_master_key(master_key, user_key, private_key)?;
53+
client.internal.initialize_user_crypto_master_key(
54+
master_key,
55+
user_key,
56+
private_key,
57+
None,
58+
)?;
5659
}
5760

5861
Ok(PasswordLoginResponse::process_response(response))

crates/bitwarden-core/src/auth/password/validate.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,12 @@ mod tests {
140140

141141
client
142142
.internal
143-
.initialize_user_crypto_master_key(master_key, user_key.parse().unwrap(), private_key)
143+
.initialize_user_crypto_master_key(
144+
master_key,
145+
user_key.parse().unwrap(),
146+
private_key,
147+
None,
148+
)
144149
.unwrap();
145150

146151
let result =
@@ -183,7 +188,12 @@ mod tests {
183188

184189
client
185190
.internal
186-
.initialize_user_crypto_master_key(master_key, user_key.parse().unwrap(), private_key)
191+
.initialize_user_crypto_master_key(
192+
master_key,
193+
user_key.parse().unwrap(),
194+
private_key,
195+
None,
196+
)
187197
.unwrap();
188198

189199
let result =

crates/bitwarden-core/src/auth/pin.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ mod tests {
7575

7676
client
7777
.internal
78-
.initialize_user_crypto_master_key(master_key, user_key.parse().unwrap(), private_key)
78+
.initialize_user_crypto_master_key(
79+
master_key,
80+
user_key.parse().unwrap(),
81+
private_key,
82+
None,
83+
)
7984
.unwrap();
8085

8186
client

0 commit comments

Comments
 (0)