Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions components/fxa-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[package]
name = "fxa-client"
edition = "2021"
edition = "2024"
version = "0.1.0"
authors = ["Edouard Oger <[email protected]>"]
license = "MPL-2.0"
exclude = ["/android", "/ios"]

Expand Down
6 changes: 3 additions & 3 deletions components/fxa-client/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ impl FirefoxAccount {
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct DeviceConfig {
pub name: String,
pub device_type: sync15::DeviceType,
pub device_type: DeviceType,
pub capabilities: Vec<DeviceCapability>,
}

Expand All @@ -207,7 +207,7 @@ pub struct DeviceConfig {
pub struct LocalDevice {
pub id: String,
pub display_name: String,
pub device_type: sync15::DeviceType,
pub device_type: DeviceType,
pub capabilities: Vec<DeviceCapability>,
pub push_subscription: Option<DevicePushSubscription>,
pub push_endpoint_expired: bool,
Expand All @@ -222,7 +222,7 @@ pub struct LocalDevice {
pub struct Device {
pub id: String,
pub display_name: String,
pub device_type: sync15::DeviceType,
pub device_type: DeviceType,
pub capabilities: Vec<DeviceCapability>,
pub push_subscription: Option<DevicePushSubscription>,
pub push_endpoint_expired: bool,
Expand Down
18 changes: 11 additions & 7 deletions components/fxa-client/src/internal/close_tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ use std::mem;
use payload_support::Fit;

use super::{
FirefoxAccount,
commands::{
IncomingDeviceCommand, PrivateCommandKeys,
close_tabs::{self, CloseTabsPayload},
decrypt_command, encrypt_command, IncomingDeviceCommand, PrivateCommandKeys,
decrypt_command, encrypt_command,
},
device::COMMAND_MAX_PAYLOAD_SIZE,
http_client::GetDeviceResponse,
scopes, telemetry, FirefoxAccount,
scopes, telemetry,
};
use crate::{warn, CloseTabsResult, Error, Result};
use crate::{CloseTabsResult, Error, Result, warn};

impl FirefoxAccount {
pub fn close_tabs<T>(&mut self, target_device_id: &str, urls: Vec<T>) -> Result<CloseTabsResult>
Expand Down Expand Up @@ -119,7 +121,9 @@ impl FirefoxAccount {
Ok(IncomingDeviceCommand::TabsClosed { sender, payload })
}
Err(e) => {
warn!("Could not decrypt Close Remote Tabs payload. Diagnosing then resetting the Close Tabs keys.");
warn!(
"Could not decrypt Close Remote Tabs payload. Diagnosing then resetting the Close Tabs keys."
);
self.clear_close_tabs_keys();
self.reregister_current_capabilities()?;
Err(e)
Expand Down Expand Up @@ -168,11 +172,11 @@ mod tests {
use serde_json::json;

use crate::{
ScopedKey,
internal::{
commands::PublicCommandKeys, config::Config, http_client::MockFxAClient,
oauth::RefreshToken, util, CachedResponse, FirefoxAccount,
CachedResponse, FirefoxAccount, commands::PublicCommandKeys, config::Config,
http_client::MockFxAClient, oauth::RefreshToken, util,
},
ScopedKey,
};

/// An RAII helper that overrides the maximum command payload size
Expand Down
4 changes: 2 additions & 2 deletions components/fxa-client/src/internal/commands/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

// All commands share the same structs for their crypto-keys.

use serde::{de::DeserializeOwned, Deserialize, Serialize};
use serde::{Deserialize, Serialize, de::DeserializeOwned};

use super::super::device::Device;
use super::super::scopes;
use crate::{Error, Result, ScopedKey};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
use rc_crypto::ece::{self, EcKeyComponents};
use sync15::{EncryptedPayload, KeyBundle};

Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub use close_tabs::CloseTabsPayload;
pub use send_tab::SendTabPayload;

pub(crate) use keys::{
decrypt_command, encrypt_command, get_public_keys, PrivateCommandKeys, PublicCommandKeys,
PrivateCommandKeys, PublicCommandKeys, decrypt_command, encrypt_command, get_public_keys,
};

use super::device::Device;
Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::http_client;
use crate::{internal::util, FxaConfig, Result};
use crate::{FxaConfig, Result, internal::util};
use serde_derive::{Deserialize, Serialize};
use std::{cell::RefCell, sync::Arc};
use url::Url;
Expand Down
9 changes: 5 additions & 4 deletions components/fxa-client/src/internal/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ use std::{

pub use super::http_client::{GetDeviceResponse as Device, PushSubscription};
use super::{
CachedResponse, FirefoxAccount,
commands::{self, IncomingDeviceCommand, PrivateCommandKeys, PublicCommandKeys},
http_client::{
DeviceUpdateRequest, DeviceUpdateRequestBuilder, PendingCommand, UpdateDeviceResponse,
},
scopes, telemetry, util, CachedResponse, FirefoxAccount,
scopes, telemetry, util,
};
use crate::{info, warn, DeviceCapability, Error, LocalDevice, Result};
use crate::{DeviceCapability, Error, LocalDevice, Result, info, warn};
use sync15::DeviceType;

// An devices response is considered fresh for `DEVICES_FRESHNESS_THRESHOLD` ms.
Expand Down Expand Up @@ -434,10 +435,10 @@ impl TryFrom<Device> for crate::Device {
#[cfg(test)]
mod tests {
use super::*;
use crate::ScopedKey;
use crate::internal::Config;
use crate::internal::http_client::*;
use crate::internal::oauth::RefreshToken;
use crate::internal::Config;
use crate::ScopedKey;
use mockall::predicate::always;
use mockall::predicate::eq;
use nss::ensure_initialized;
Expand Down
12 changes: 9 additions & 3 deletions components/fxa-client/src/internal/http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
};
use sync15::DeviceType;
use url::Url;
use viaduct::{header_names, status_codes, Method, Request, Response};
use viaduct::{Method, Request, Response, header_names, status_codes};

const HAWK_HKDF_SALT: [u8; 32] = [0b0; 32];
const HAWK_KEY_LENGTH: usize = 32;
Expand Down Expand Up @@ -987,14 +987,20 @@ mod tests {
code_verifier: "bobo".to_owned(),
ttl: None,
};
assert_eq!("{\"grant_type\":\"authorization_code\",\"client_id\":\"bar\",\"code\":\"foo\",\"code_verifier\":\"bobo\"}", serde_json::to_string(&using_code).unwrap());
assert_eq!(
"{\"grant_type\":\"authorization_code\",\"client_id\":\"bar\",\"code\":\"foo\",\"code_verifier\":\"bobo\"}",
serde_json::to_string(&using_code).unwrap()
);
let using_code = OAauthTokenRequest::UsingRefreshToken {
client_id: "bar".to_owned(),
refresh_token: "foo".to_owned(),
scope: Some("bobo".to_owned()),
ttl: Some(123),
};
assert_eq!("{\"grant_type\":\"refresh_token\",\"client_id\":\"bar\",\"refresh_token\":\"foo\",\"scope\":\"bobo\",\"ttl\":123}", serde_json::to_string(&using_code).unwrap());
assert_eq!(
"{\"grant_type\":\"refresh_token\",\"client_id\":\"bar\",\"refresh_token\":\"foo\",\"scope\":\"bobo\",\"ttl\":123}",
serde_json::to_string(&using_code).unwrap()
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use self::{
config::Config,
oauth::{AuthCircuitBreaker, OAuthFlow, OAUTH_WEBCHANNEL_REDIRECT},
oauth::{AuthCircuitBreaker, OAUTH_WEBCHANNEL_REDIRECT, OAuthFlow},
state_manager::StateManager,
state_persistence::PersistedState,
telemetry::FxaTelemetry,
Expand Down
19 changes: 13 additions & 6 deletions components/fxa-client/src/internal/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
pub mod attached_clients;
use super::scopes;
use super::{
FirefoxAccount,
http_client::{
AuthorizationRequestParameters, IntrospectResponse as IntrospectInfo, OAuthTokenResponse,
},
scoped_keys::ScopedKeysFlow,
util, FirefoxAccount,
util,
};
use crate::auth::UserData;
use crate::{warn, AuthorizationParameters, Error, FxaServer, Result, ScopedKey};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use crate::{AuthorizationParameters, Error, FxaServer, Result, ScopedKey, warn};
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
use jwcrypto::{EncryptionAlgorithm, EncryptionParameters};
use rate_limiter::RateLimiter;
use rc_crypto::digest;
Expand Down Expand Up @@ -350,7 +351,11 @@ impl FirefoxAccount {
"fxaclient-scoped-key",
"Sync scope granted, but no sync scoped key (scope granted: {}, key scopes: {})",
resp.scope,
scoped_keys.keys().map(|s| s.as_ref()).collect::<Vec<&str>>().join(", ")
scoped_keys
.keys()
.map(|s| s.as_ref())
.collect::<Vec<&str>>()
.join(", ")
);
}
scoped_keys
Expand Down Expand Up @@ -591,7 +596,7 @@ impl From<IntrospectInfo> for crate::AuthorizationInfo {

#[cfg(test)]
mod tests {
use super::super::{http_client::*, Config};
use super::super::{Config, http_client::*};
use super::*;
use mockall::predicate::always;
use mockall::predicate::eq;
Expand Down Expand Up @@ -965,7 +970,9 @@ mod tests {
assert_eq!(code, 400);
assert_eq!(errno, 163); // Requested scopes not allowed
} else {
panic!("Should return an error from the server specifying that the requested scopes are not allowed");
panic!(
"Should return an error from the server specifying that the requested scopes are not allowed"
);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

pub use super::super::http_client::GetAttachedClientResponse as AttachedClient;
use super::super::{util, CachedResponse, FirefoxAccount};
use super::super::{CachedResponse, FirefoxAccount, util};
use crate::{Error, Result};

// An attached clients response is considered fresh for `ATTACHED_CLIENTS_FRESHNESS_THRESHOLD` ms.
Expand Down
4 changes: 2 additions & 2 deletions components/fxa-client/src/internal/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

pub use super::http_client::ProfileResponse as Profile;
use super::{scopes, util, CachedResponse, FirefoxAccount};
use super::{CachedResponse, FirefoxAccount, scopes, util};
use crate::{Error, Result};

// A cached profile response is considered fresh for `PROFILE_FRESHNESS_THRESHOLD` ms.
Expand Down Expand Up @@ -86,9 +86,9 @@ impl FirefoxAccount {
mod tests {
use super::*;
use crate::internal::{
Config,
http_client::*,
oauth::{AccessTokenInfo, RefreshToken},
Config,
};
use mockall::predicate::always;
use mockall::predicate::eq;
Expand Down
6 changes: 3 additions & 3 deletions components/fxa-client/src/internal/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::convert::TryInto;

use super::FirefoxAccount;
use crate::{info, AccountEvent, Error, Result};
use crate::{AccountEvent, Error, Result, info};
use serde_derive::Deserialize;

impl FirefoxAccount {
Expand Down Expand Up @@ -138,11 +138,11 @@ pub struct AccountDestroyedPushPayload {
#[cfg(test)]
mod tests {
use super::*;
use crate::internal::CachedResponse;
use crate::internal::Config;
use crate::internal::http_client::IntrospectResponse;
use crate::internal::http_client::MockFxAClient;
use crate::internal::oauth::RefreshToken;
use crate::internal::CachedResponse;
use crate::internal::Config;
use mockall::predicate::always;
use mockall::predicate::eq;
use std::sync::Arc;
Expand Down
7 changes: 5 additions & 2 deletions components/fxa-client/src/internal/scoped_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
use jwcrypto::{self, DecryptionParameters, Jwk};
use rc_crypto::{agreement, agreement::EphemeralKeyPair};

Expand Down Expand Up @@ -103,6 +103,9 @@ mod tests {

let jwe = "eyJhbGciOiJFQ0RILUVTIiwia2lkIjoiNFBKTTl5dGVGeUtsb21ILWd2UUtyWGZ0a0N3ak9HNHRfTmpYVXhLM1VqSSIsImVwayI6eyJrdHkiOiJFQyIsImNydiI6IlAtMjU2IiwieCI6IlB3eG9Na1RjSVZ2TFlKWU4wM2R0Y3o2TEJrR0FHaU1hZWlNQ3lTZXEzb2MiLCJ5IjoiLUYtTllRRDZwNUdSQ2ZoYm1hN3NvNkhxdExhVlNub012S0pFcjFBeWlaSSJ9LCJlbmMiOiJBMjU2R0NNIn0..b9FPhjjpmAmo_rP8.ur9jTry21Y2trvtcanSFmAtiRfF6s6qqyg6ruRal7PCwa7PxDzAuMN6DZW5BiK8UREOH08-FyRcIgdDOm5Zq8KwVAn56PGfcH30aNDGQNkA_mpfjx5Tj2z8kI6ryLWew4PGZb-PsL1g-_eyXhktq7dAhetjNYttKwSREWQFokv7N3nJGpukBqnwL1ost-MjDXlINZLVJKAiMHDcu-q7Epitwid2c2JVGOSCJjbZ4-zbxVmZ4o9xhFb2lbvdiaMygH6bPlrjEK99uT6XKtaIZmyDwftbD6G3x4On-CqA2TNL6ILRaJMtmyX--ctL0IrngUIHg_F0Wz94v.zBD8NACkUcZTPLH0tceGnA";
let keys = flow.decrypt_keys_jwe(jwe).unwrap();
assert_eq!(keys, "{\"https://identity.mozilla.com/apps/oldsync\":{\"kty\":\"oct\",\"scope\":\"https://identity.mozilla.com/apps/oldsync\",\"k\":\"8ek1VNk4sjrNP0DhGC4crzQtwmpoR64zHuFMHb4Tw-exR70Z2SSIfMSrJDTLEZid9lD05-hbA3n2Q4Esjlu1tA\",\"kid\":\"1526414944666-zgTjf5oXmPmBjxwXWFsDWg\"}}");
assert_eq!(
keys,
"{\"https://identity.mozilla.com/apps/oldsync\":{\"kty\":\"oct\",\"scope\":\"https://identity.mozilla.com/apps/oldsync\",\"k\":\"8ek1VNk4sjrNP0DhGC4crzQtwmpoR64zHuFMHb4Tw-exR70Z2SSIfMSrJDTLEZid9lD05-hbA3n2Q4Esjlu1tA\",\"kid\":\"1526414944666-zgTjf5oXmPmBjxwXWFsDWg\"}}"
);
}
}
12 changes: 7 additions & 5 deletions components/fxa-client/src/internal/send_tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::{
FirefoxAccount,
commands::{
decrypt_command, encrypt_command, get_public_keys,
send_tab::{self, SendTabPayload},
IncomingDeviceCommand, PrivateCommandKeys as PrivateSendTabKeys,
PublicCommandKeys as PublicSendTabKeys,
PublicCommandKeys as PublicSendTabKeys, decrypt_command, encrypt_command, get_public_keys,
send_tab::{self, SendTabPayload},
},
http_client::GetDeviceResponse,
scopes, telemetry, FirefoxAccount,
scopes, telemetry,
};
use crate::{Error, Result};

Expand Down Expand Up @@ -85,7 +85,9 @@ impl FirefoxAccount {
// It also seems like it might be possible to recover - ie, one
// of the reasons is that there are key mismatches. Doesn't that
// mean the "other" key might work?
crate::warn!("Could not decrypt Send Tab payload. Diagnosing then resetting the Send Tab keys.");
crate::warn!(
"Could not decrypt Send Tab payload. Diagnosing then resetting the Send Tab keys."
);
match self.diagnose_remote_keys(send_tab_key) {
Ok(_) => {
error_support::report_error!(
Expand Down
4 changes: 2 additions & 2 deletions components/fxa-client/src/internal/state_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
use std::collections::{HashMap, HashSet};

use crate::{
DeviceCapability, FxaRustAuthState, LocalDevice, Result, ScopedKey,
internal::{
CachedResponse, Config, OAuthFlow, PersistedState,
oauth::{AccessTokenInfo, RefreshToken},
profile::Profile,
state_persistence::state_to_json,
CachedResponse, Config, OAuthFlow, PersistedState,
},
DeviceCapability, FxaRustAuthState, LocalDevice, Result, ScopedKey,
};

/// Stores and manages the current state of the FxA client
Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/state_persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ use serde_derive::*;
use std::collections::{HashMap, HashSet};

use super::{
CachedResponse, Result,
config::Config,
oauth::{AccessTokenInfo, RefreshToken},
profile::Profile,
CachedResponse, Result,
};
use crate::{DeviceCapability, LocalDevice, ScopedKey};

Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use super::{commands, FirefoxAccount};
use super::{FirefoxAccount, commands};
use crate::Result;
use serde_derive::*;
use sync_guid::Guid;
Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/internal/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::{Error, Result};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use base64::{Engine, engine::general_purpose::URL_SAFE_NO_PAD};
use rc_crypto::rand;
use std::time::{SystemTime, UNIX_EPOCH};

Expand Down
2 changes: 1 addition & 1 deletion components/fxa-client/src/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use error_support::handle_error;
use serde::{Deserialize, Serialize};

use crate::{internal, ApiResult, CloseTabsResult, Device, Error, FirefoxAccount, LocalDevice};
use crate::{ApiResult, CloseTabsResult, Device, Error, FirefoxAccount, LocalDevice, internal};

impl FirefoxAccount {
/// Set or update a push subscription endpoint for this device.
Expand Down
Loading