Page MenuHomePhabricator

D11467.diff
No OneTemporary

D11467.diff

diff --git a/services/commtest/Cargo.lock b/services/commtest/Cargo.lock
--- a/services/commtest/Cargo.lock
+++ b/services/commtest/Cargo.lock
@@ -171,7 +171,7 @@
"serde",
"serde-wasm-bindgen",
"serde_json",
- "sha2",
+ "sha2 0.10.7",
"tokio",
"tokio-tungstenite 0.20.1",
"tokio-tungstenite-wasm",
@@ -235,6 +235,15 @@
"digest 0.10.7",
]
+[[package]]
+name = "block-buffer"
+version = "0.9.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4"
+dependencies = [
+ "generic-array",
+]
+
[[package]]
name = "block-buffer"
version = "0.10.4"
@@ -308,10 +317,10 @@
"derive_more",
"hex",
"once_cell",
- "rand",
+ "rand 0.8.5",
"serde",
"serde_json",
- "sha2",
+ "sha2 0.10.7",
"tokio",
"tracing",
"uuid",
@@ -324,7 +333,7 @@
"argon2",
"log",
"opaque-ke",
- "rand",
+ "rand 0.8.5",
"serde",
"tonic 0.9.2",
"wasm-bindgen",
@@ -336,21 +345,23 @@
dependencies = [
"async-stream",
"backup_client",
+ "base64 0.21.3",
"bytesize",
"comm-lib",
"comm-opaque2",
"derive_more",
+ "ed25519-dalek",
"futures-util",
"grpc_clients",
"hex",
"lazy_static",
"num_cpus",
"prost",
- "rand",
+ "rand 0.7.3",
"reqwest",
"serde",
"serde_json",
- "sha2",
+ "sha2 0.10.7",
"tokio",
"tokio-tungstenite 0.18.0",
"tonic 0.8.3",
@@ -410,7 +421,7 @@
checksum = "ef2b4b23cddf68b89b8f8069890e8c270d54e2d5fe1b143820234805e4cb17ef"
dependencies = [
"generic-array",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
"zeroize",
]
@@ -425,6 +436,19 @@
"typenum",
]
+[[package]]
+name = "curve25519-dalek"
+version = "3.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61"
+dependencies = [
+ "byteorder",
+ "digest 0.9.0",
+ "rand_core 0.5.1",
+ "subtle",
+ "zeroize",
+]
+
[[package]]
name = "curve25519-dalek"
version = "4.0.0-pre.1"
@@ -433,7 +457,7 @@
dependencies = [
"byteorder",
"digest 0.9.0",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
"zeroize",
]
@@ -492,7 +516,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
- "block-buffer",
+ "block-buffer 0.10.4",
"crypto-common",
"subtle",
]
@@ -508,6 +532,29 @@
"syn 2.0.48",
]
+[[package]]
+name = "ed25519"
+version = "1.5.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91cff35c70bba8a626e3185d8cd48cc11b5437e1a5bcd15b9b5fa3c64b6dfee7"
+dependencies = [
+ "signature",
+]
+
+[[package]]
+name = "ed25519-dalek"
+version = "1.0.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d"
+dependencies = [
+ "curve25519-dalek 3.2.0",
+ "ed25519",
+ "rand 0.7.3",
+ "serde",
+ "sha2 0.9.9",
+ "zeroize",
+]
+
[[package]]
name = "either"
version = "1.9.0"
@@ -527,7 +574,7 @@
"ff",
"generic-array",
"group",
- "rand_core",
+ "rand_core 0.6.4",
"sec1",
"subtle",
"zeroize",
@@ -581,7 +628,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d013fc25338cc558c5c2cfbad646908fb23591e2404481826742b651c9af7160"
dependencies = [
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
]
@@ -693,6 +740,17 @@
"version_check",
]
+[[package]]
+name = "getrandom"
+version = "0.1.16"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce"
+dependencies = [
+ "cfg-if",
+ "libc",
+ "wasi 0.9.0+wasi-snapshot-preview1",
+]
+
[[package]]
name = "getrandom"
version = "0.2.10"
@@ -702,7 +760,7 @@
"cfg-if",
"js-sys",
"libc",
- "wasi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen",
]
@@ -719,7 +777,7 @@
checksum = "5dfbfb3a6cfbd390d5c9564ab283a0349b9b9fcd46a706c1eb10e0db70bfbac7"
dependencies = [
"ff",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
]
@@ -1046,7 +1104,7 @@
checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2"
dependencies = [
"libc",
- "wasi",
+ "wasi 0.11.0+wasi-snapshot-preview1",
"windows-sys",
]
@@ -1118,6 +1176,12 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"
+[[package]]
+name = "opaque-debug"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381"
+
[[package]]
name = "opaque-ke"
version = "2.0.0"
@@ -1125,7 +1189,7 @@
checksum = "76d410412d23781909d90c3900c5783e830586765f2277bccc78167da8af81a5"
dependencies = [
"argon2",
- "curve25519-dalek",
+ "curve25519-dalek 4.0.0-pre.1",
"derive-where",
"digest 0.10.7",
"displaydoc",
@@ -1133,7 +1197,7 @@
"generic-array",
"hkdf",
"hmac",
- "rand",
+ "rand 0.8.5",
"serde",
"subtle",
"voprf",
@@ -1197,7 +1261,7 @@
checksum = "7676374caaee8a325c9e7a2ae557f216c5563a171d6997b0ef8a65af35147700"
dependencies = [
"base64ct",
- "rand_core",
+ "rand_core 0.6.4",
"subtle",
]
@@ -1343,6 +1407,19 @@
"proc-macro2",
]
+[[package]]
+name = "rand"
+version = "0.7.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
+dependencies = [
+ "getrandom 0.1.16",
+ "libc",
+ "rand_chacha 0.2.2",
+ "rand_core 0.5.1",
+ "rand_hc",
+]
+
[[package]]
name = "rand"
version = "0.8.5"
@@ -1350,8 +1427,18 @@
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
- "rand_chacha",
- "rand_core",
+ "rand_chacha 0.3.1",
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "rand_chacha"
+version = "0.2.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
+dependencies = [
+ "ppv-lite86",
+ "rand_core 0.5.1",
]
[[package]]
@@ -1361,7 +1448,16 @@
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
- "rand_core",
+ "rand_core 0.6.4",
+]
+
+[[package]]
+name = "rand_core"
+version = "0.5.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
+dependencies = [
+ "getrandom 0.1.16",
]
[[package]]
@@ -1370,7 +1466,16 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
- "getrandom",
+ "getrandom 0.2.10",
+]
+
+[[package]]
+name = "rand_hc"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
+dependencies = [
+ "rand_core 0.5.1",
]
[[package]]
@@ -1688,6 +1793,19 @@
"digest 0.10.7",
]
+[[package]]
+name = "sha2"
+version = "0.9.9"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800"
+dependencies = [
+ "block-buffer 0.9.0",
+ "cfg-if",
+ "cpufeatures",
+ "digest 0.9.0",
+ "opaque-debug",
+]
+
[[package]]
name = "sha2"
version = "0.10.7"
@@ -1708,6 +1826,12 @@
"lazy_static",
]
+[[package]]
+name = "signature"
+version = "1.6.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c"
+
[[package]]
name = "slab"
version = "0.4.9"
@@ -2069,7 +2193,7 @@
"indexmap 1.9.3",
"pin-project",
"pin-project-lite",
- "rand",
+ "rand 0.8.5",
"slab",
"tokio",
"tokio-util",
@@ -2180,7 +2304,7 @@
"http",
"httparse",
"log",
- "rand",
+ "rand 0.8.5",
"sha1",
"thiserror",
"url",
@@ -2200,7 +2324,7 @@
"httparse",
"log",
"native-tls",
- "rand",
+ "rand 0.8.5",
"sha1",
"thiserror",
"url",
@@ -2281,7 +2405,7 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d"
dependencies = [
- "getrandom",
+ "getrandom 0.2.10",
"wasm-bindgen",
]
@@ -2309,15 +2433,15 @@
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "081acbe8fcf05d5e8e2aad8ef3d40e02eddeaec07c75a9770d862a0fc0874322"
dependencies = [
- "curve25519-dalek",
+ "curve25519-dalek 4.0.0-pre.1",
"derive-where",
"digest 0.10.7",
"displaydoc",
"elliptic-curve",
"generic-array",
- "rand_core",
+ "rand_core 0.6.4",
"serde",
- "sha2",
+ "sha2 0.10.7",
"subtle",
"zeroize",
]
@@ -2331,6 +2455,12 @@
"try-lock",
]
+[[package]]
+name = "wasi"
+version = "0.9.0+wasi-snapshot-preview1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
+
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
diff --git a/services/commtest/Cargo.toml b/services/commtest/Cargo.toml
--- a/services/commtest/Cargo.toml
+++ b/services/commtest/Cargo.toml
@@ -8,6 +8,8 @@
comm-opaque2 = { path = "../../shared/comm-opaque2" }
grpc_clients = { path = "../../shared/grpc_clients" }
backup_client = { path = "../../shared/backup_client" }
+base64 = "0.21.2"
+ed25519-dalek = "1"
tonic = "0.8"
tokio = { version = "1.24", features = ["macros", "rt-multi-thread"] }
prost = "0.11"
@@ -23,7 +25,7 @@
url = "2.3.1"
futures-util = "0.3.28"
serde_json = "1.0.96"
-rand = "0.8.5"
+rand = "0.7.3"
reqwest = { version = "0.11", features = ["json", "multipart", "stream"] }
serde = "1.0"
comm-lib = { path = "../../shared/comm-lib" }
diff --git a/services/commtest/src/identity/mod.rs b/services/commtest/src/identity/mod.rs
--- a/services/commtest/src/identity/mod.rs
+++ b/services/commtest/src/identity/mod.rs
@@ -1,2 +1,68 @@
+use base64::Engine;
+use ed25519_dalek::{ed25519::signature::SignerMut, Keypair, Signature};
+use rand::rngs::OsRng;
+use serde_json::json;
+
+use self::olm_account_infos::{
+ ClientPublicKeys, IdentityPublicKeys, DEFAULT_CLIENT_KEYS,
+};
+
pub mod device;
pub mod olm_account_infos;
+
+pub struct SigningCapableAccount {
+ signing_key: Keypair,
+}
+
+impl SigningCapableAccount {
+ pub fn new() -> Self {
+ let mut rng = OsRng {};
+ let signing_key = Keypair::generate(&mut rng);
+ Self { signing_key }
+ }
+
+ /// returns device public keys, required for device key upload
+ pub fn public_keys(&self) -> ClientPublicKeys {
+ let default = DEFAULT_CLIENT_KEYS.clone();
+ let signing_public_key = self.signing_key.public.to_bytes();
+ let ed25519 = base64::engine::general_purpose::STANDARD_NO_PAD
+ .encode(signing_public_key);
+
+ ClientPublicKeys {
+ primary_identity_public_keys: IdentityPublicKeys {
+ ed25519,
+ ..default.primary_identity_public_keys
+ },
+ ..default
+ }
+ }
+
+ /// signs message, returns signature
+ pub fn sign_message(&mut self, message: &str) -> String {
+ let signature: Signature = self.signing_key.sign(message.as_bytes());
+ base64::engine::general_purpose::STANDARD_NO_PAD
+ .encode(signature.to_bytes())
+ }
+
+ /// returns value for challenge_response gRPC field
+ pub fn sign_nonce(&mut self, nonce: String) -> String {
+ let message = json!({
+ "nonce": nonce
+ });
+ let message_str =
+ serde_json::to_string(&message).expect("message stringify failed");
+ let message_signature = self.sign_message(&message_str);
+
+ let response = json!({
+ "message": message_str,
+ "signature": message_signature,
+ });
+ serde_json::to_string(&response).expect("response stringify failed")
+ }
+}
+
+impl Default for SigningCapableAccount {
+ fn default() -> Self {
+ Self::new()
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 2:34 PM (17 h, 49 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2688039
Default Alt Text
D11467.diff (11 KB)

Event Timeline