diff --git a/services/identity/Cargo.lock b/services/identity/Cargo.lock --- a/services/identity/Cargo.lock +++ b/services/identity/Cargo.lock @@ -869,6 +869,7 @@ "log", "opaque-ke", "rand 0.8.5", + "serde", "tonic", "wasm-bindgen", ] @@ -1756,6 +1757,7 @@ dependencies = [ "derive_more", "prost", + "serde", "tonic", "tonic-build", "tracing", @@ -3566,18 +3568,18 @@ [[package]] name = "serde" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63261df402c67811e9ac6def069e4786148c4563f4b50fd4bf30aa370d626b02" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.195" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46fe8f8603d81ba86327b23a2e9cdf49e1255fb94a4c5f297f6ee0547178ea2c" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote 1.0.35", diff --git a/services/identity/src/client_service.rs b/services/identity/src/client_service.rs --- a/services/identity/src/client_service.rs +++ b/services/identity/src/client_service.rs @@ -7,6 +7,7 @@ use comm_opaque2::grpc::protocol_error_to_grpc_status; use moka::future::Cache; use rand::rngs::OsRng; +use serde::{Deserialize, Serialize}; use siwe::eip55; use tonic::Response; use tracing::{debug, error, warn}; @@ -48,33 +49,33 @@ IdentityClientService, IdentityClientServiceServer, }; -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub enum WorkflowInProgress { Registration(Box), Login(Box), Update(UpdateState), } -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct UserRegistrationInfo { pub username: String, pub flattened_device_key_upload: FlattenedDeviceKeyUpload, pub user_id: Option, } -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct UserLoginInfo { pub user_id: String, pub flattened_device_key_upload: FlattenedDeviceKeyUpload, pub opaque_server_login: comm_opaque2::server::Login, } -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct UpdateState { pub user_id: String, } -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct FlattenedDeviceKeyUpload { pub device_id_key: String, pub key_payload: String, diff --git a/services/identity/src/constants.rs b/services/identity/src/constants.rs --- a/services/identity/src/constants.rs +++ b/services/identity/src/constants.rs @@ -71,6 +71,11 @@ pub const NONCE_TABLE_EXPIRATION_TIME_UNIX_ATTRIBUTE: &str = "expirationTimeUnix"; +pub const WORKFLOWS_IN_PROGRESS_TABLE: &str = "identity-workflows-in-progress"; +pub const WORKFLOWS_IN_PROGRESS_PARTITION_KEY: &str = "id"; +pub const WORKFLOWS_IN_PROGRESS_TABLE_EXPIRATION_TIME_UNIX_ATTRIBUTE: &str = + "expirationTimeUnix"; + // Usernames reserved because they exist in Ashoat's keyserver already pub const RESERVED_USERNAMES_TABLE: &str = "identity-reserved-usernames"; pub const RESERVED_USERNAMES_TABLE_PARTITION_KEY: &str = "username"; @@ -151,6 +156,10 @@ pub const NONCE_LENGTH: usize = 17; pub const NONCE_TTL_DURATION: i64 = 120; // seconds +// Workflows in progress + +pub const WORKFLOWS_IN_PROGRESS_TTL_DURATION: i64 = 120; // seconds + // Identity pub const DEFAULT_IDENTITY_ENDPOINT: &str = "http://localhost:50054"; diff --git a/shared/comm-opaque2/Cargo.lock b/shared/comm-opaque2/Cargo.lock --- a/shared/comm-opaque2/Cargo.lock +++ b/shared/comm-opaque2/Cargo.lock @@ -87,6 +87,7 @@ "log", "opaque-ke", "rand", + "serde", "tonic", "wasm-bindgen", ] @@ -158,7 +159,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -189,7 +190,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -407,7 +408,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -430,18 +431,18 @@ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.26" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4424af4bf778aae2051a77b60283332f386554255d722233d09fbfc7e30da2fc" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -491,22 +492,22 @@ [[package]] name = "serde" -version = "1.0.156" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.156" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.50", ] [[package]] @@ -537,6 +538,17 @@ "unicode-ident", ] +[[package]] +name = "syn" +version = "2.0.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "synstructure" version = "0.12.6" @@ -545,7 +557,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "unicode-xid", ] @@ -623,7 +635,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] @@ -705,7 +717,7 @@ "once_cell", "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-shared", ] @@ -727,7 +739,7 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -821,6 +833,6 @@ dependencies = [ "proc-macro2", "quote", - "syn", + "syn 1.0.109", "synstructure", ] diff --git a/shared/comm-opaque2/Cargo.toml b/shared/comm-opaque2/Cargo.toml --- a/shared/comm-opaque2/Cargo.toml +++ b/shared/comm-opaque2/Cargo.toml @@ -10,3 +10,4 @@ rand = "0.8" tonic = { version = "0.9.1", default-features = false } wasm-bindgen = "0.2" +serde = { version = "1.0.197", features = ["derive"] } diff --git a/shared/comm-opaque2/src/server/login.rs b/shared/comm-opaque2/src/server/login.rs --- a/shared/comm-opaque2/src/server/login.rs +++ b/shared/comm-opaque2/src/server/login.rs @@ -4,12 +4,14 @@ ServerLoginStartParameters, ServerSetup, }; use rand::rngs::OsRng; +use serde::{Deserialize, Serialize}; use crate::Cipher; -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct Login { state: Option>, + #[serde(skip)] rng: OsRng, pub session_key: Option>, } diff --git a/shared/grpc_clients/Cargo.lock b/shared/grpc_clients/Cargo.lock --- a/shared/grpc_clients/Cargo.lock +++ b/shared/grpc_clients/Cargo.lock @@ -51,7 +51,7 @@ dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", ] [[package]] @@ -62,7 +62,7 @@ dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", ] [[package]] @@ -302,6 +302,7 @@ dependencies = [ "derive_more", "prost", + "serde", "tonic", "tonic-build", "tracing", @@ -584,7 +585,7 @@ dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", ] [[package]] @@ -617,9 +618,9 @@ [[package]] name = "proc-macro2" -version = "1.0.66" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18fb31db3f9bddb2ea821cde30a9f70117e3f119938b5ee630b7403aa6e2ead9" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ "unicode-ident", ] @@ -680,9 +681,9 @@ [[package]] name = "quote" -version = "1.0.32" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f3b39ccfb720540debaa0164757101c08ecb8d326b15358ce76a62c7e85965" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] @@ -878,9 +879,23 @@ [[package]] name = "serde" -version = "1.0.183" +version = "1.0.197" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.197" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ac8da02677876d532745a130fc9d8e6edfa81a269b107c5b00829b91d8eb3c" +checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.50", +] [[package]] name = "sharded-slab" @@ -945,9 +960,9 @@ [[package]] name = "syn" -version = "2.0.28" +version = "2.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04361975b3f5e348b2189d8dc55bc942f278b2d482a6a0365de5bdd62d351567" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" dependencies = [ "proc-macro2", "quote", @@ -1017,7 +1032,7 @@ dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", ] [[package]] @@ -1152,7 +1167,7 @@ dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", ] [[package]] @@ -1254,7 +1269,7 @@ "once_cell", "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", "wasm-bindgen-shared", ] @@ -1276,7 +1291,7 @@ dependencies = [ "proc-macro2", "quote", - "syn 2.0.28", + "syn 2.0.50", "wasm-bindgen-backend", "wasm-bindgen-shared", ] diff --git a/shared/grpc_clients/Cargo.toml b/shared/grpc_clients/Cargo.toml --- a/shared/grpc_clients/Cargo.toml +++ b/shared/grpc_clients/Cargo.toml @@ -9,6 +9,7 @@ tonic = { version = "0.9.1", features = ["tls-webpki-roots"] } tracing = "0.1" tracing-subscriber = { version = "0.3.16", features = ["env-filter"] } +serde = { version = "1.0.197", features = ["derive"] } [build-dependencies] tonic-build = "0.9.1" diff --git a/shared/grpc_clients/src/identity/device.rs b/shared/grpc_clients/src/identity/device.rs --- a/shared/grpc_clients/src/identity/device.rs +++ b/shared/grpc_clients/src/identity/device.rs @@ -3,6 +3,8 @@ use crate::error::Error; pub use crate::identity::protos::unauth::DeviceType; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; + impl TryFrom for DeviceType { type Error = crate::error::Error; @@ -32,6 +34,41 @@ } } +impl Serialize for DeviceType { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let value = match self { + DeviceType::Keyserver => 0, + DeviceType::Web => 1, + DeviceType::Ios => 2, + DeviceType::Android => 3, + DeviceType::Windows => 4, + DeviceType::MacOs => 5, + }; + serializer.serialize_i32(value) + } +} + +impl<'de> Deserialize<'de> for DeviceType { + fn deserialize(deserializer: D) -> Result + where + D: Deserializer<'de>, + { + let value = i32::deserialize(deserializer)?; + match value { + 0 => Ok(DeviceType::Keyserver), + 1 => Ok(DeviceType::Web), + 2 => Ok(DeviceType::Ios), + 3 => Ok(DeviceType::Android), + 4 => Ok(DeviceType::Windows), + 5 => Ok(DeviceType::MacOs), + _ => Err(serde::de::Error::custom("Invalid DeviceType value")), + } + } +} + #[cfg(test)] mod device_tests { use super::*;