Page MenuHomePhabricator

D6913.diff
No OneTemporary

D6913.diff

diff --git a/keyserver/addons/rust-node-addon/src/delete_user.rs b/keyserver/addons/rust-node-addon/src/delete_user.rs
deleted file mode 100644
--- a/keyserver/addons/rust-node-addon/src/delete_user.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-use crate::identity::identity_service_client::IdentityServiceClient;
-use crate::identity::DeleteUserRequest;
-use crate::IDENTITY_SERVICE_SOCKET_ADDR;
-use napi::bindgen_prelude::{Error, Result, Status};
-use tonic::Request;
-use tracing::instrument;
-
-#[napi]
-#[instrument(skip_all)]
-pub async fn delete_user(user_id: String) -> Result<()> {
- let mut identity_client =
- IdentityServiceClient::connect(IDENTITY_SERVICE_SOCKET_ADDR.as_str())
- .await
- .map_err(|_| {
- Error::new(
- Status::GenericFailure,
- "Unable to connect to identity service".to_string(),
- )
- })?;
-
- let request = Request::new(DeleteUserRequest {
- user_id: user_id.clone(),
- });
- identity_client
- .delete_user(request)
- .await
- .map_err(|e| Error::new(Status::GenericFailure, e.to_string()))?;
-
- Ok(())
-}
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs b/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs
new file mode 100644
--- /dev/null
+++ b/keyserver/addons/rust-node-addon/src/identity_client/delete_user.rs
@@ -0,0 +1,33 @@
+use super::*;
+
+#[napi]
+#[instrument(skip_all)]
+pub async fn delete_user(user_id: String) -> Result<()> {
+ let channel = Channel::from_static(&IDENTITY_SERVICE_SOCKET_ADDR)
+ .connect()
+ .await
+ .map_err(|_| {
+ Error::new(
+ Status::GenericFailure,
+ "Unable to connect to identity service".to_string(),
+ )
+ })?;
+ let token: MetadataValue<_> = AUTH_TOKEN
+ .parse()
+ .map_err(|_| Error::from_status(Status::GenericFailure))?;
+ let mut identity_client =
+ IdentityServiceClient::with_interceptor(channel, |mut req: Request<()>| {
+ req.metadata_mut().insert("authorization", token.clone());
+ Ok(req)
+ });
+
+ let request = Request::new(DeleteUserRequest {
+ user_id: user_id.clone(),
+ });
+ identity_client
+ .delete_user(request)
+ .await
+ .map_err(|e| Error::new(Status::GenericFailure, e.to_string()))?;
+
+ Ok(())
+}
diff --git a/keyserver/addons/rust-node-addon/src/identity_client/mod.rs b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
new file mode 100644
--- /dev/null
+++ b/keyserver/addons/rust-node-addon/src/identity_client/mod.rs
@@ -0,0 +1,94 @@
+pub mod delete_user;
+pub mod register_user;
+pub mod identity {
+ tonic::include_proto!("identity");
+}
+
+use comm_opaque::Cipher;
+use identity::identity_service_client::IdentityServiceClient;
+use identity::{
+ pake_login_response::Data::AccessToken,
+ pake_login_response::Data::PakeCredentialResponse,
+ registration_request::Data::PakeCredentialFinalization as RegistrationPakeCredentialFinalization,
+ registration_request::Data::PakeRegistrationRequestAndUserId,
+ registration_request::Data::PakeRegistrationUploadAndCredentialRequest,
+ registration_response::Data::PakeLoginResponse as RegistrationPakeLoginResponse,
+ registration_response::Data::PakeRegistrationResponse, DeleteUserRequest,
+ PakeLoginResponse as PakeLoginResponseStruct,
+ PakeRegistrationRequestAndUserId as PakeRegistrationRequestAndUserIdStruct,
+ PakeRegistrationUploadAndCredentialRequest as PakeRegistrationUploadAndCredentialRequestStruct,
+ RegistrationRequest, RegistrationResponse as RegistrationResponseMessage,
+ SessionInitializationInfo,
+};
+use lazy_static::lazy_static;
+use napi::bindgen_prelude::*;
+use opaque_ke::{
+ ClientLogin, ClientLoginFinishParameters, ClientLoginStartParameters,
+ ClientLoginStartResult, ClientRegistration,
+ ClientRegistrationFinishParameters, CredentialFinalization,
+ CredentialResponse, RegistrationResponse, RegistrationUpload,
+};
+use rand::{rngs::OsRng, CryptoRng, Rng};
+use std::collections::HashMap;
+use std::env::var;
+use tokio::sync::mpsc;
+use tokio_stream::wrappers::ReceiverStream;
+use tonic::{metadata::MetadataValue, transport::Channel, Request};
+use tracing::{error, instrument};
+
+lazy_static! {
+ pub static ref IDENTITY_SERVICE_SOCKET_ADDR: String =
+ var("COMM_IDENTITY_SERVICE_SOCKET_ADDR")
+ .unwrap_or_else(|_| "https://[::1]:50051".to_string());
+ pub static ref AUTH_TOKEN: String = var("COMM_IDENTITY_SERVICE_AUTH_TOKEN")
+ .unwrap_or_else(|_| "test".to_string());
+}
+
+fn handle_unexpected_response<T: std::fmt::Debug>(message: Option<T>) -> Error {
+ error!("Received an unexpected message: {:?}", message);
+ Error::from_status(Status::GenericFailure)
+}
+
+async fn send_to_mpsc<T>(tx: mpsc::Sender<T>, request: T) -> Result<()> {
+ if let Err(e) = tx.send(request).await {
+ error!("Response was dropped: {}", e);
+ return Err(Error::from_status(Status::GenericFailure));
+ }
+ Ok(())
+}
+
+fn pake_login_start(
+ rng: &mut (impl Rng + CryptoRng),
+ password: &str,
+) -> Result<ClientLoginStartResult<Cipher>> {
+ ClientLogin::<Cipher>::start(
+ rng,
+ password.as_bytes(),
+ ClientLoginStartParameters::default(),
+ )
+ .map_err(|e| {
+ error!("Failed to start PAKE login: {}", e);
+ Error::from_status(Status::GenericFailure)
+ })
+}
+
+fn pake_login_finish(
+ credential_response_bytes: &[u8],
+ client_login: ClientLogin<Cipher>,
+) -> Result<CredentialFinalization<Cipher>> {
+ client_login
+ .finish(
+ CredentialResponse::deserialize(credential_response_bytes).map_err(
+ |e| {
+ error!("Could not deserialize credential response bytes: {}", e);
+ Error::from_status(Status::GenericFailure)
+ },
+ )?,
+ ClientLoginFinishParameters::default(),
+ )
+ .map_err(|e| {
+ error!("Failed to finish PAKE login: {}", e);
+ Error::from_status(Status::GenericFailure)
+ })
+ .map(|res| res.message)
+}
diff --git a/keyserver/addons/rust-node-addon/src/identity_client.rs b/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs
rename from keyserver/addons/rust-node-addon/src/identity_client.rs
rename to keyserver/addons/rust-node-addon/src/identity_client/register_user.rs
--- a/keyserver/addons/rust-node-addon/src/identity_client.rs
+++ b/keyserver/addons/rust-node-addon/src/identity_client/register_user.rs
@@ -1,33 +1,4 @@
-use crate::identity::identity_service_client::IdentityServiceClient;
-use crate::identity::{
- pake_login_response::Data::AccessToken,
- pake_login_response::Data::PakeCredentialResponse,
- registration_request::Data::PakeCredentialFinalization as RegistrationPakeCredentialFinalization,
- registration_request::Data::PakeRegistrationRequestAndUserId,
- registration_request::Data::PakeRegistrationUploadAndCredentialRequest,
- registration_response::Data::PakeLoginResponse as RegistrationPakeLoginResponse,
- registration_response::Data::PakeRegistrationResponse,
- PakeLoginResponse as PakeLoginResponseStruct,
- PakeRegistrationRequestAndUserId as PakeRegistrationRequestAndUserIdStruct,
- PakeRegistrationUploadAndCredentialRequest as PakeRegistrationUploadAndCredentialRequestStruct,
- RegistrationRequest, RegistrationResponse as RegistrationResponseMessage,
- SessionInitializationInfo,
-};
-use crate::{AUTH_TOKEN, IDENTITY_SERVICE_SOCKET_ADDR};
-use comm_opaque::Cipher;
-use napi::bindgen_prelude::*;
-use opaque_ke::{
- ClientLogin, ClientLoginFinishParameters, ClientLoginStartParameters,
- ClientLoginStartResult, ClientRegistration,
- ClientRegistrationFinishParameters, CredentialFinalization,
- CredentialResponse, RegistrationResponse, RegistrationUpload,
-};
-use rand::{rngs::OsRng, CryptoRng, Rng};
-use std::collections::HashMap;
-use tokio::sync::mpsc;
-use tokio_stream::wrappers::ReceiverStream;
-use tonic::{metadata::MetadataValue, transport::Channel, Request};
-use tracing::{error, instrument};
+use super::*;
#[napi]
#[instrument(skip_all)]
@@ -41,7 +12,12 @@
let channel = Channel::from_static(&IDENTITY_SERVICE_SOCKET_ADDR)
.connect()
.await
- .map_err(|_| Error::from_status(Status::GenericFailure))?;
+ .map_err(|_| {
+ Error::new(
+ Status::GenericFailure,
+ "Unable to connect to identity service".to_string(),
+ )
+ })?;
let token: MetadataValue<_> = AUTH_TOKEN
.parse()
.map_err(|_| Error::from_status(Status::GenericFailure))?;
@@ -115,88 +91,6 @@
handle_registration_token_response(message)
}
-fn handle_unexpected_response<T: std::fmt::Debug>(message: Option<T>) -> Error {
- error!("Received an unexpected message: {:?}", message);
- Error::from_status(Status::GenericFailure)
-}
-
-async fn send_to_mpsc<T>(tx: mpsc::Sender<T>, request: T) -> Result<()> {
- if let Err(e) = tx.send(request).await {
- error!("Response was dropped: {}", e);
- return Err(Error::from_status(Status::GenericFailure));
- }
- Ok(())
-}
-
-fn pake_login_start(
- rng: &mut (impl Rng + CryptoRng),
- password: &str,
-) -> Result<ClientLoginStartResult<Cipher>> {
- ClientLogin::<Cipher>::start(
- rng,
- password.as_bytes(),
- ClientLoginStartParameters::default(),
- )
- .map_err(|e| {
- error!("Failed to start PAKE login: {}", e);
- Error::from_status(Status::GenericFailure)
- })
-}
-
-fn pake_login_finish(
- credential_response_bytes: &[u8],
- client_login: ClientLogin<Cipher>,
-) -> Result<CredentialFinalization<Cipher>> {
- client_login
- .finish(
- CredentialResponse::deserialize(credential_response_bytes).map_err(
- |e| {
- error!("Could not deserialize credential response bytes: {}", e);
- Error::from_status(Status::GenericFailure)
- },
- )?,
- ClientLoginFinishParameters::default(),
- )
- .map_err(|e| {
- error!("Failed to finish PAKE login: {}", e);
- Error::from_status(Status::GenericFailure)
- })
- .map(|res| res.message)
-}
-
-fn pake_registration_start(
- rng: &mut (impl Rng + CryptoRng),
- user_id: String,
- signing_public_key: String,
- password: &str,
- username: String,
- session_initialization_info: SessionInitializationInfo,
-) -> Result<(RegistrationRequest, ClientRegistration<Cipher>)> {
- let client_registration_start_result =
- ClientRegistration::<Cipher>::start(rng, password.as_bytes()).map_err(
- |e| {
- error!("Failed to start PAKE registration: {}", e);
- Error::from_status(Status::GenericFailure)
- },
- )?;
- let pake_registration_request =
- client_registration_start_result.message.serialize();
- Ok((
- RegistrationRequest {
- data: Some(PakeRegistrationRequestAndUserId(
- PakeRegistrationRequestAndUserIdStruct {
- user_id,
- pake_registration_request,
- username,
- signing_public_key,
- session_initialization_info: Some(session_initialization_info),
- },
- )),
- },
- client_registration_start_result.state,
- ))
-}
-
async fn handle_registration_response(
message: Option<RegistrationResponseMessage>,
client_rng: &mut (impl Rng + CryptoRng),
@@ -284,6 +178,39 @@
}
}
+fn pake_registration_start(
+ rng: &mut (impl Rng + CryptoRng),
+ user_id: String,
+ signing_public_key: String,
+ password: &str,
+ username: String,
+ session_initialization_info: SessionInitializationInfo,
+) -> Result<(RegistrationRequest, ClientRegistration<Cipher>)> {
+ let client_registration_start_result =
+ ClientRegistration::<Cipher>::start(rng, password.as_bytes()).map_err(
+ |e| {
+ error!("Failed to start PAKE registration: {}", e);
+ Error::from_status(Status::GenericFailure)
+ },
+ )?;
+ let pake_registration_request =
+ client_registration_start_result.message.serialize();
+ Ok((
+ RegistrationRequest {
+ data: Some(PakeRegistrationRequestAndUserId(
+ PakeRegistrationRequestAndUserIdStruct {
+ user_id,
+ pake_registration_request,
+ username,
+ signing_public_key,
+ session_initialization_info: Some(session_initialization_info),
+ },
+ )),
+ },
+ client_registration_start_result.state,
+ ))
+}
+
fn pake_registration_finish(
rng: &mut (impl Rng + CryptoRng),
registration_response_bytes: &[u8],
diff --git a/keyserver/addons/rust-node-addon/src/lib.rs b/keyserver/addons/rust-node-addon/src/lib.rs
--- a/keyserver/addons/rust-node-addon/src/lib.rs
+++ b/keyserver/addons/rust-node-addon/src/lib.rs
@@ -1,20 +1,5 @@
-pub mod delete_user;
pub mod identity_client;
-pub mod identity {
- tonic::include_proto!("identity");
-}
pub mod tunnelbroker_client;
#[macro_use]
extern crate napi_derive;
-
-use lazy_static::lazy_static;
-use std::env::var;
-
-lazy_static! {
- pub static ref IDENTITY_SERVICE_SOCKET_ADDR: String =
- var("COMM_IDENTITY_SERVICE_SOCKET_ADDR")
- .unwrap_or_else(|_| "https://[::1]:50051".to_string());
- pub static ref AUTH_TOKEN: String = var("COMM_IDENTITY_SERVICE_AUTH_TOKEN")
- .unwrap_or_else(|_| "test".to_string());
-}
diff --git a/keyserver/addons/rust-node-addon/src/tunnelbroker_client.rs b/keyserver/addons/rust-node-addon/src/tunnelbroker_client.rs
--- a/keyserver/addons/rust-node-addon/src/tunnelbroker_client.rs
+++ b/keyserver/addons/rust-node-addon/src/tunnelbroker_client.rs
@@ -15,7 +15,7 @@
lazy_static! {
static ref TUNNELBROKER_SERVICE_ADDR: String =
var("COMM_TUNNELBROKER_SERVICE_ADDR")
- .unwrap_or("https://[::1]:50051".to_string());
+ .unwrap_or_else(|_| "https://[::1]:50051".to_string());
}
#[napi]
@@ -86,7 +86,10 @@
blob_hashes: vec![],
}];
- if let Err(_) = tunnelbroker::publish_messages(&self.tx, messages).await {
+ if tunnelbroker::publish_messages(&self.tx, messages)
+ .await
+ .is_err()
+ {
return Err(napi::Error::from_status(napi::Status::GenericFailure));
}
Ok(())

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 1, 3:03 PM (19 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2605305
Default Alt Text
D6913.diff (13 KB)

Event Timeline