Skip to content

Commit

Permalink
Fix warnings (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hinton authored Jul 17, 2023
1 parent 23c20df commit 3e32a4d
Show file tree
Hide file tree
Showing 11 changed files with 106 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build-rust-crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ jobs:
with:
command: build
args: ${{ matrix.features }} -p ${{ matrix.package }} --release
env:
RUSTFLAGS: "-D warnings"

- name: Build Internal
if: ${{ matrix.package == 'bitwarden' }}
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: build
args: ${{ matrix.features }} -p ${{ matrix.package }} --features internal --release
env:
RUSTFLAGS: "-D warnings"

release-dry-run:
name: Release dry-run
Expand Down
6 changes: 1 addition & 5 deletions .github/workflows/rust-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ jobs:
- name: Cache cargo registry
uses: Swatinem/rust-cache@dd05243424bd5c0e585e4b55eb2d7615cdd32f1f # v2.5.1

- name: Build
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: build

- name: Test
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: test
args: --all-features

wasm:
name: WASM
Expand Down
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.

9 changes: 8 additions & 1 deletion crates/bitwarden/src/auth/api/request/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
mod access_token_request;
#[cfg(feature = "internal")]
mod api_token_request;
#[cfg(feature = "internal")]
mod password_token_request;
#[cfg(feature = "internal")]
mod renew_token_request;

pub(crate) use access_token_request::*;
#[cfg(feature = "internal")]
pub(crate) use api_token_request::*;
use base64::Engine;
#[cfg(feature = "internal")]
pub(crate) use password_token_request::*;
#[cfg(feature = "internal")]
pub(crate) use renew_token_request::*;

use base64::Engine;

use crate::{
auth::api::response::{parse_identity_response, IdentityTokenResponse},
client::ApiConfigurations,
Expand Down
37 changes: 25 additions & 12 deletions crates/bitwarden/src/auth/commands/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,15 @@ use std::{
};

use base64::Engine;
use bitwarden_api_identity::{
apis::accounts_api::accounts_prelogin_post,
models::{PreloginRequestModel, PreloginResponseModel},
};
use log::{debug, info};

use crate::{
auth::{
api::{
request::{AccessTokenRequest, ApiTokenRequest, PasswordTokenRequest},
response::IdentityTokenResponse,
},
request::{AccessTokenLoginRequest, ApiKeyLoginRequest, PasswordLoginRequest},
response::{ApiKeyLoginResponse, PasswordLoginResponse},
api::{request::AccessTokenRequest, response::IdentityTokenResponse},
request::AccessTokenLoginRequest,
response::ApiKeyLoginResponse,
},
client::{
access_token::AccessToken,
auth_settings::AuthSettings,
encryption_settings::{decrypt, SymmetricCryptoKey},
Client, LoginMethod,
},
Expand All @@ -30,6 +21,23 @@ use crate::{
util::{decode_token, BASE64_ENGINE},
};

#[cfg(feature = "internal")]
use {
crate::{
auth::{
api::request::{ApiTokenRequest, PasswordTokenRequest},
request::{ApiKeyLoginRequest, PasswordLoginRequest},
response::PasswordLoginResponse,
},
client::auth_settings::AuthSettings,
},
bitwarden_api_identity::{
apis::accounts_api::accounts_prelogin_post,
models::{PreloginRequestModel, PreloginResponseModel},
},
log::{debug, info},
};

#[cfg(feature = "internal")]
pub(crate) async fn password_login(
client: &mut Client,
Expand Down Expand Up @@ -155,6 +163,7 @@ pub(crate) async fn access_token_login(
ApiKeyLoginResponse::process_response(response)
}

#[cfg(feature = "internal")]
async fn determine_password_hash(
client: &mut Client,
email: &str,
Expand All @@ -168,12 +177,14 @@ async fn determine_password_hash(
Ok(password_hash)
}

#[cfg(feature = "internal")]
async fn request_prelogin(client: &mut Client, email: String) -> Result<PreloginResponseModel> {
let request_model = PreloginRequestModel::new(email);
let config = client.get_api_configurations().await;
Ok(accounts_prelogin_post(&config.identity, Some(request_model)).await?)
}

#[cfg(feature = "internal")]
async fn request_identity_tokens(
client: &mut Client,
input: &PasswordLoginRequest,
Expand Down Expand Up @@ -215,6 +226,7 @@ pub(crate) async fn renew_token(client: &mut Client) -> Result<()> {
}

let res = match login_method {
#[cfg(feature = "internal")]
LoginMethod::Username { client_id } => {
let refresh = client
.refresh_token
Expand All @@ -228,6 +240,7 @@ pub(crate) async fn renew_token(client: &mut Client) -> Result<()> {
.send(&client.__api_configurations)
.await?
}
#[cfg(feature = "internal")]
LoginMethod::ApiKey {
client_id,
client_secret,
Expand Down
41 changes: 25 additions & 16 deletions crates/bitwarden/src/client/client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::time::{Duration, Instant};

use log::debug;
use reqwest::header::{self};
use uuid::Uuid;

Expand All @@ -11,24 +10,28 @@ use crate::{
response::ApiKeyLoginResponse,
},
client::{
auth_settings::AuthSettings,
client_settings::{ClientSettings, DeviceType},
encryption_settings::{EncryptionSettings, SymmetricCryptoKey},
},
crypto::CipherString,
error::{Error, Result},
error::Result,
};
#[cfg(feature = "internal")]
use crate::{
auth::{
commands::{api_key_login, password_login},
request::{ApiKeyLoginRequest, PasswordLoginRequest},
response::PasswordLoginResponse,
},
platform::{
generate_fingerprint, get_user_api_key, sync, FingerprintRequest,
SecretVerificationRequest, SyncRequest, SyncResponse, UserApiKeyResponse,
use {
crate::{
auth::{
commands::{api_key_login, password_login},
request::{ApiKeyLoginRequest, PasswordLoginRequest},
response::PasswordLoginResponse,
},
client::auth_settings::AuthSettings,
crypto::CipherString,
error::Error,
platform::{
generate_fingerprint, get_user_api_key, sync, FingerprintRequest,
SecretVerificationRequest, SyncRequest, SyncResponse, UserApiKeyResponse,
},
},
log::debug,
};

#[derive(Debug)]
Expand All @@ -40,9 +43,9 @@ pub(crate) struct ApiConfigurations {

#[derive(Debug, Clone)]
pub(crate) enum LoginMethod {
Username {
client_id: String,
},
#[cfg(feature = "internal")]
Username { client_id: String },
#[cfg(feature = "internal")]
ApiKey {
client_id: String,
client_secret: String,
Expand All @@ -66,6 +69,7 @@ pub struct Client {
#[doc(hidden)]
pub(crate) __api_configurations: ApiConfigurations,

#[cfg(feature = "internal")]
auth_settings: Option<AuthSettings>,

encryption_settings: Option<EncryptionSettings>,
Expand Down Expand Up @@ -112,6 +116,7 @@ impl Client {
api,
device_type: settings.device_type,
},
#[cfg(feature = "internal")]
auth_settings: None,
encryption_settings: None,
}
Expand Down Expand Up @@ -160,6 +165,7 @@ impl Client {
get_user_api_key(self, input).await
}

#[cfg(feature = "internal")]
pub(crate) fn get_auth_settings(&self) -> &Option<AuthSettings> {
&self.auth_settings
}
Expand All @@ -177,6 +183,7 @@ impl Client {
&self.encryption_settings
}

#[cfg(feature = "internal")]
pub(crate) fn set_auth_settings(&mut self, auth_settings: AuthSettings) {
debug! {"setting auth settings: {:#?}", auth_settings}
self.auth_settings = Some(auth_settings);
Expand All @@ -201,10 +208,12 @@ impl Client {
renew_token(self).await
}

#[cfg(feature = "internal")]
pub fn is_authed(&self) -> bool {
self.token.is_some() || self.auth_settings.is_some()
}

#[cfg(feature = "internal")]
pub(crate) fn initialize_user_crypto(
&mut self,
password: &str,
Expand Down
10 changes: 8 additions & 2 deletions crates/bitwarden/src/client/encryption_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ use aes::cipher::{
use base64::Engine;
use hmac::Mac;
use rand::RngCore;
use rsa::{pkcs8::DecodePrivateKey, Oaep, RsaPrivateKey};
use rsa::RsaPrivateKey;
use uuid::Uuid;

use crate::{
client::auth_settings::AuthSettings,
crypto::{CipherString, PbkdfSha256Hmac, PBKDF_SHA256_HMAC_OUT_SIZE},
error::{CryptoError, Error, Result},
util::BASE64_ENGINE,
};

#[cfg(feature = "internal")]
use {
crate::client::auth_settings::AuthSettings,
rsa::{pkcs8::DecodePrivateKey, Oaep},
};

pub struct SymmetricCryptoKey {
pub key: GenericArray<u8, U32>,
pub mac_key: Option<GenericArray<u8, U32>>,
Expand Down Expand Up @@ -94,6 +99,7 @@ impl std::fmt::Debug for EncryptionSettings {
}

impl EncryptionSettings {
#[cfg(feature = "internal")]
pub(crate) fn new(
auth: &AuthSettings,
password: &str,
Expand Down
1 change: 1 addition & 0 deletions crates/bitwarden/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pub(crate) use client::*;
pub(crate) mod access_token;
#[cfg(feature = "internal")]
pub(crate) mod auth_settings;
mod client;
pub mod client_settings;
Expand Down
Loading

0 comments on commit 3e32a4d

Please sign in to comment.