Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions bitwarden_license/bitwarden-sm/src/projects/create.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bitwarden_api_api::models::ProjectCreateRequestModel;
use bitwarden_core::{key_management::SymmetricKeyId, Client};
use bitwarden_core::{key_management::SymmetricKeyId, Client, OrganizationId};
use bitwarden_crypto::Encryptable;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -27,7 +27,7 @@
input.validate()?;

let key_store = client.internal.get_key_store();
let key = SymmetricKeyId::Organization(input.organization_id);
let key = SymmetricKeyId::Organization(OrganizationId::new(input.organization_id));

Check warning on line 30 in bitwarden_license/bitwarden-sm/src/projects/create.rs

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bitwarden-sm/src/projects/create.rs#L30

Added line #L30 was not covered by tests

let project = Some(ProjectCreateRequestModel {
name: input
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bitwarden_api_api::models::ProjectResponseModel;
use bitwarden_core::{
key_management::{KeyIds, SymmetricKeyId},
require,
require, OrganizationId,
};
use bitwarden_crypto::{Decryptable, EncString, KeyStoreContext};
use chrono::{DateTime, Utc};
Expand All @@ -27,7 +27,7 @@
ctx: &mut KeyStoreContext<KeyIds>,
) -> Result<Self, SecretsManagerError> {
let organization_id = require!(response.organization_id);
let key = SymmetricKeyId::Organization(organization_id);
let key = SymmetricKeyId::Organization(OrganizationId::new(organization_id));

Check warning on line 30 in bitwarden_license/bitwarden-sm/src/projects/project_response.rs

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bitwarden-sm/src/projects/project_response.rs#L30

Added line #L30 was not covered by tests

let name = require!(response.name)
.parse::<EncString>()?
Expand Down
4 changes: 2 additions & 2 deletions bitwarden_license/bitwarden-sm/src/projects/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bitwarden_api_api::models::ProjectUpdateRequestModel;
use bitwarden_core::{key_management::SymmetricKeyId, Client};
use bitwarden_core::{key_management::SymmetricKeyId, Client, OrganizationId};
use bitwarden_crypto::Encryptable;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -29,7 +29,7 @@
input.validate()?;

let key_store = client.internal.get_key_store();
let key = SymmetricKeyId::Organization(input.organization_id);
let key = SymmetricKeyId::Organization(OrganizationId::new(input.organization_id));

Check warning on line 32 in bitwarden_license/bitwarden-sm/src/projects/update.rs

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bitwarden-sm/src/projects/update.rs#L32

Added line #L32 was not covered by tests

let project = Some(ProjectUpdateRequestModel {
name: input
Expand Down
4 changes: 2 additions & 2 deletions bitwarden_license/bitwarden-sm/src/secrets/create.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bitwarden_api_api::models::SecretCreateRequestModel;
use bitwarden_core::{key_management::SymmetricKeyId, Client};
use bitwarden_core::{key_management::SymmetricKeyId, Client, OrganizationId};
use bitwarden_crypto::Encryptable;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -35,7 +35,7 @@
input.validate()?;

let key_store = client.internal.get_key_store();
let key = SymmetricKeyId::Organization(input.organization_id);
let key = SymmetricKeyId::Organization(OrganizationId::new(input.organization_id));

Check warning on line 38 in bitwarden_license/bitwarden-sm/src/secrets/create.rs

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bitwarden-sm/src/secrets/create.rs#L38

Added line #L38 was not covered by tests

let secret = {
let mut ctx = key_store.context();
Expand Down
4 changes: 2 additions & 2 deletions bitwarden_license/bitwarden-sm/src/secrets/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use bitwarden_api_api::models::{
use bitwarden_core::{
client::Client,
key_management::{KeyIds, SymmetricKeyId},
require,
require, OrganizationId,
};
use bitwarden_crypto::{Decryptable, EncString, KeyStoreContext};
use schemars::JsonSchema;
Expand Down Expand Up @@ -96,7 +96,7 @@ impl SecretIdentifierResponse {
ctx: &mut KeyStoreContext<KeyIds>,
) -> Result<SecretIdentifierResponse, SecretsManagerError> {
let organization_id = require!(response.organization_id);
let enc_key = SymmetricKeyId::Organization(organization_id);
let enc_key = SymmetricKeyId::Organization(OrganizationId::new(organization_id));

let key = require!(response.key)
.parse::<EncString>()?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use bitwarden_api_api::models::{
};
use bitwarden_core::{
key_management::{KeyIds, SymmetricKeyId},
require,
require, OrganizationId,
};
use bitwarden_crypto::{Decryptable, EncString, KeyStoreContext};
use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -51,7 +51,7 @@ impl SecretResponse {
ctx: &mut KeyStoreContext<KeyIds>,
) -> Result<SecretResponse, SecretsManagerError> {
let organization_id = require!(response.organization_id);
let enc_key = SymmetricKeyId::Organization(organization_id);
let enc_key = SymmetricKeyId::Organization(OrganizationId::new(organization_id));

let key = require!(response.key)
.parse::<EncString>()?
Expand Down
4 changes: 2 additions & 2 deletions bitwarden_license/bitwarden-sm/src/secrets/update.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bitwarden_api_api::models::SecretUpdateRequestModel;
use bitwarden_core::{key_management::SymmetricKeyId, Client};
use bitwarden_core::{key_management::SymmetricKeyId, Client, OrganizationId};
use bitwarden_crypto::Encryptable;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -34,7 +34,7 @@
input.validate()?;

let key_store = client.internal.get_key_store();
let key = SymmetricKeyId::Organization(input.organization_id);
let key = SymmetricKeyId::Organization(OrganizationId::new(input.organization_id));

Check warning on line 37 in bitwarden_license/bitwarden-sm/src/secrets/update.rs

View check run for this annotation

Codecov / codecov/patch

bitwarden_license/bitwarden-sm/src/secrets/update.rs#L37

Added line #L37 was not covered by tests

let secret = {
let mut ctx = key_store.context();
Expand Down
3 changes: 2 additions & 1 deletion crates/bitwarden-core/src/auth/auth_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ mod tests {
use crate::{
key_management::SymmetricKeyId,
mobile::crypto::{AuthRequestMethod, InitUserCryptoMethod, InitUserCryptoRequest},
UserId,
};

#[test]
Expand Down Expand Up @@ -243,7 +244,7 @@ mod tests {
new_device
.crypto()
.initialize_user_crypto(InitUserCryptoRequest {
user_id: Some(uuid::Uuid::new_v4()),
user_id: Some(UserId::new_v4()),
kdf_params: kdf,
email: email.to_owned(),
private_key: private_key.to_owned(),
Expand Down
7 changes: 3 additions & 4 deletions crates/bitwarden-core/src/auth/login/access_token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use chrono::Utc;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::LoginError;
use crate::{
Expand All @@ -17,7 +16,7 @@
client::{LoginMethod, ServiceAccountLoginMethod},
require,
secrets_manager::state::{self, ClientState},
Client,
Client, OrganizationId,
};

pub(crate) async fn login_access_token(
Expand Down Expand Up @@ -118,7 +117,7 @@
client: &Client,
state_file: &Path,
access_token: &AccessToken,
) -> Result<Uuid, LoginError> {
) -> Result<OrganizationId, LoginError> {

Check warning on line 120 in crates/bitwarden-core/src/auth/login/access_token.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/auth/login/access_token.rs#L120

Added line #L120 was not covered by tests
let client_state = state::get(state_file, access_token)?;

let token: JwtToken = client_state.token.parse()?;
Expand All @@ -127,7 +126,7 @@
let time_till_expiration = (token.exp as i64) - Utc::now().timestamp();

if time_till_expiration > 0 {
let organization_id: Uuid = organization_id
let organization_id: OrganizationId = organization_id

Check warning on line 129 in crates/bitwarden-core/src/auth/login/access_token.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/auth/login/access_token.rs#L129

Added line #L129 was not covered by tests
.parse()
.map_err(|_| LoginError::InvalidOrganizationId)?;
let encryption_key = SymmetricCryptoKey::try_from(client_state.encryption_key)?;
Expand Down
7 changes: 4 additions & 3 deletions crates/bitwarden-core/src/client/encryption_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ use bitwarden_crypto::{AsymmetricCryptoKey, KeyStore, SymmetricCryptoKey};
use bitwarden_crypto::{EncString, UnsignedSharedKey};
use bitwarden_error::bitwarden_error;
use thiserror::Error;
use uuid::Uuid;

#[cfg(any(feature = "secrets", feature = "internal"))]
use crate::OrganizationId;
use crate::{
error::UserIdAlreadySetError,
key_management::{AsymmetricKeyId, KeyIds, SymmetricKeyId},
Expand Down Expand Up @@ -85,7 +86,7 @@ impl EncryptionSettings {
/// This is used only for logging in Secrets Manager with an access token
#[cfg(feature = "secrets")]
pub(crate) fn new_single_org_key(
organization_id: Uuid,
organization_id: OrganizationId,
key: SymmetricCryptoKey,
store: &KeyStore<KeyIds>,
) {
Expand All @@ -99,7 +100,7 @@ impl EncryptionSettings {

#[cfg(feature = "internal")]
pub(crate) fn set_org_keys(
org_enc_keys: Vec<(Uuid, UnsignedSharedKey)>,
org_enc_keys: Vec<(OrganizationId, UnsignedSharedKey)>,
store: &KeyStore<KeyIds>,
) -> Result<(), EncryptionSettingsError> {
let mut ctx = store.context_mut();
Expand Down
16 changes: 8 additions & 8 deletions crates/bitwarden-core/src/client/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#[cfg(feature = "internal")]
use bitwarden_crypto::{EncString, Kdf, MasterKey, PinKey, UnsignedSharedKey};
use chrono::Utc;
use uuid::Uuid;

#[cfg(feature = "secrets")]
use super::login_method::ServiceAccountLoginMethod;
Expand All @@ -15,13 +14,14 @@
client::{encryption_settings::EncryptionSettings, login_method::LoginMethod},
error::UserIdAlreadySetError,
key_management::KeyIds,
DeviceType,
DeviceType, UserId,
};
#[cfg(feature = "internal")]
use crate::{
client::encryption_settings::EncryptionSettingsError,
client::{flags::Flags, login_method::UserLoginMethod},
error::NotAuthenticatedError,
OrganizationId,
};

#[derive(Debug, Clone)]
Expand All @@ -45,7 +45,7 @@

#[derive(Debug)]
pub struct InternalClient {
pub(crate) user_id: OnceLock<Uuid>,
pub(crate) user_id: OnceLock<UserId>,
pub(crate) tokens: RwLock<Tokens>,
pub(crate) login_method: RwLock<Option<Arc<LoginMethod>>>,

Expand Down Expand Up @@ -83,7 +83,7 @@
.clone()
}

pub fn get_access_token_organization(&self) -> Option<Uuid> {
pub fn get_access_token_organization(&self) -> Option<OrganizationId> {

Check warning on line 86 in crates/bitwarden-core/src/client/internal.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/client/internal.rs#L86

Added line #L86 was not covered by tests
match self
.login_method
.read()
Expand Down Expand Up @@ -174,11 +174,11 @@
&self.key_store
}

pub fn init_user_id(&self, user_id: Uuid) -> Result<(), UserIdAlreadySetError> {
pub fn init_user_id(&self, user_id: UserId) -> Result<(), UserIdAlreadySetError> {
self.user_id.set(user_id).map_err(|_| UserIdAlreadySetError)
}

pub fn get_user_id(&self) -> Option<Uuid> {
pub fn get_user_id(&self) -> Option<UserId> {
self.user_id.get().copied()
}

Expand Down Expand Up @@ -220,7 +220,7 @@
#[cfg(feature = "secrets")]
pub(crate) fn initialize_crypto_single_org_key(
&self,
organization_id: Uuid,
organization_id: OrganizationId,
key: SymmetricCryptoKey,
) {
EncryptionSettings::new_single_org_key(organization_id, key, &self.key_store);
Expand All @@ -229,7 +229,7 @@
#[cfg(feature = "internal")]
pub fn initialize_org_crypto(
&self,
org_keys: Vec<(Uuid, UnsignedSharedKey)>,
org_keys: Vec<(OrganizationId, UnsignedSharedKey)>,
) -> Result<(), EncryptionSettingsError> {
EncryptionSettings::set_org_keys(org_keys, &self.key_store)
}
Expand Down
6 changes: 2 additions & 4 deletions crates/bitwarden-core/src/client/login_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
use std::path::PathBuf;

use bitwarden_crypto::Kdf;
#[cfg(feature = "secrets")]
use uuid::Uuid;

#[cfg(feature = "secrets")]
use crate::auth::AccessToken;
use crate::{auth::AccessToken, OrganizationId};

#[derive(Debug)]
pub(crate) enum LoginMethod {
Expand Down Expand Up @@ -40,7 +38,7 @@ pub(crate) enum UserLoginMethod {
pub(crate) enum ServiceAccountLoginMethod {
AccessToken {
access_token: AccessToken,
organization_id: Uuid,
organization_id: OrganizationId,
state_file: Option<PathBuf>,
},
}
6 changes: 3 additions & 3 deletions crates/bitwarden-core/src/client/test_accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
initialize_org_crypto, initialize_user_crypto, InitOrgCryptoRequest, InitUserCryptoMethod,
InitUserCryptoRequest,
},
Client,
Client, UserId,
};

impl Client {
Expand Down Expand Up @@ -117,7 +117,7 @@
pub fn test_bitwarden_com_account() -> TestAccount {
TestAccount {
user: InitUserCryptoRequest {
user_id: Some(uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8")),
user_id: Some(UserId::new(uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8"))),
kdf_params: Kdf::PBKDF2 {
iterations: 600_000.try_into().unwrap(),
},
Expand Down Expand Up @@ -175,7 +175,7 @@
pub fn test_legacy_user_key_account() -> TestAccount {
TestAccount {
user: InitUserCryptoRequest {
user_id: Some(uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8")),
user_id: Some(UserId::new(uuid::uuid!("060000fb-0922-4dd3-b170-6e15cb5df8c8"))),

Check warning on line 178 in crates/bitwarden-core/src/client/test_accounts.rs

View check run for this annotation

Codecov / codecov/patch

crates/bitwarden-core/src/client/test_accounts.rs#L178

Added line #L178 was not covered by tests
kdf_params: Kdf::PBKDF2 {
iterations: 600_000.try_into().unwrap(),
},
Expand Down
5 changes: 3 additions & 2 deletions crates/bitwarden-core/src/ids.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use bitwarden_uuid::uuid;
use bitwarden_uuid::uuid_newtype;

uuid!(pub OrganizationId);
uuid_newtype!(pub OrganizationId);
uuid_newtype!(pub UserId);
6 changes: 4 additions & 2 deletions crates/bitwarden-core/src/key_management/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
//! [Encryptable](bitwarden_crypto::Encryptable) and [Decryptable](bitwarden_crypto::Encryptable).
use bitwarden_crypto::{key_ids, KeyStore, SymmetricCryptoKey};

use crate::OrganizationId;

key_ids! {
#[symmetric]
pub enum SymmetricKeyId {
Master,
User,
Organization(uuid::Uuid),
Organization(OrganizationId),
#[local]
Local(&'static str),
}
Expand Down Expand Up @@ -50,7 +52,7 @@ pub fn create_test_crypto_with_user_key(key: SymmetricCryptoKey) -> KeyStore<Key
/// it in their own tests.
pub fn create_test_crypto_with_user_and_org_key(
key: SymmetricCryptoKey,
org_id: uuid::Uuid,
org_id: OrganizationId,
org_key: SymmetricCryptoKey,
) -> KeyStore<KeyIds> {
let store = KeyStore::default();
Expand Down
Loading
Loading