diff --git a/giterated-daemon/src/connection/authentication.rs b/giterated-daemon/src/connection/authentication.rs index 8a3444b..48f29ea 100644 --- a/giterated-daemon/src/connection/authentication.rs +++ b/giterated-daemon/src/connection/authentication.rs @@ -14,21 +14,21 @@ pub async fn authentication_handle( state: &ConnectionState, ) -> Result { match message_type { - "&giterated_daemon::messages::authentication::RegisterAccountRequest" => { + "&giterated_models::messages::authentication::RegisterAccountRequest" => { register_account_request .handle_message(&message, state) .await?; Ok(true) } - "&giterated_daemon::messages::authentication::AuthenticationTokenRequest" => { + "&giterated_models::messages::authentication::AuthenticationTokenRequest" => { authentication_token_request .handle_message(&message, state) .await?; Ok(true) } - "&giterated_daemon::messages::authentication::TokenExtensionRequest" => { + "&giterated_models::messages::authentication::TokenExtensionRequest" => { token_extension_request .handle_message(&message, state) .await?; diff --git a/giterated-daemon/src/connection/handshake.rs b/giterated-daemon/src/connection/handshake.rs index 189dec2..111c613 100644 --- a/giterated-daemon/src/connection/handshake.rs +++ b/giterated-daemon/src/connection/handshake.rs @@ -117,6 +117,8 @@ async fn handshake_finalize( Message(finalize): Message, State(connection_state): State, ) -> Result<(), HandshakeError> { + connection_state.handshaked.store(true, Ordering::SeqCst); + connection_state .send(HandshakeFinalize { success: true }) .await diff --git a/giterated-daemon/src/connection/repository.rs b/giterated-daemon/src/connection/repository.rs index 3bfc034..2a37637 100644 --- a/giterated-daemon/src/connection/repository.rs +++ b/giterated-daemon/src/connection/repository.rs @@ -17,34 +17,34 @@ pub async fn repository_handle( state: &ConnectionState, ) -> Result { match message_type { - "&giterated_daemon::messages::repository::RepositoryCreateRequest" => { + "&giterated_models::messages::repository::RepositoryCreateRequest" => { create_repository.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::repository::RepositoryFileInspectRequest" => { + "&giterated_models::messages::repository::RepositoryFileInspectRequest" => { repository_file_inspect .handle_message(&message, state) .await?; Ok(true) } - "&giterated_daemon::messages::repository::RepositoryInfoRequest" => { + "&giterated_models::messages::repository::RepositoryInfoRequest" => { repository_info.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::repository::RepositoryIssuesCountRequest" => { + "&giterated_models::messages::repository::RepositoryIssuesCountRequest" => { issues_count.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::repository::RepositoryIssueLabelsRequest" => { + "&giterated_models::messages::repository::RepositoryIssueLabelsRequest" => { issue_labels.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::repository::RepositoryIssuesRequest" => { + "&giterated_models::messages::repository::RepositoryIssuesRequest" => { issues.handle_message(&message, state).await?; Ok(true) diff --git a/giterated-daemon/src/connection/user.rs b/giterated-daemon/src/connection/user.rs index ba9783f..3704bf8 100644 --- a/giterated-daemon/src/connection/user.rs +++ b/giterated-daemon/src/connection/user.rs @@ -18,32 +18,32 @@ pub async fn user_handle( state: &ConnectionState, ) -> Result { match message_type { - "&giterated_daemon::messages::user::UserDisplayNameRequest" => { + "&giterated_models::messages::user::UserDisplayNameRequest" => { display_name.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::user::UserDisplayImageRequest" => { + "&giterated_models::messages::user::UserDisplayImageRequest" => { display_image.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::user::UserBioRequest" => { + "&giterated_models::messages::user::UserBioRequest" => { bio.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::user::UserRepositoriesRequest" => { + "&giterated_models::messages::user::UserRepositoriesRequest" => { repositories.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::user::UserSettingsRequest" => { + "&giterated_models::messages::user::UserSettingsRequest" => { user_settings.handle_message(&message, state).await?; Ok(true) } - "&giterated_daemon::messages::user::UserWriteSettingsRequest" => { + "&giterated_models::messages::user::UserWriteSettingsRequest" => { write_user_settings.handle_message(&message, state).await?; Ok(true) diff --git a/giterated-daemon/src/connection/wrapper.rs b/giterated-daemon/src/connection/wrapper.rs index 20cc785..38b3a48 100644 --- a/giterated-daemon/src/connection/wrapper.rs +++ b/giterated-daemon/src/connection/wrapper.rs @@ -78,6 +78,11 @@ pub async fn connection_wrapper( _ => continue, }; + info!( + "Received payload: {}", + std::str::from_utf8(&payload).unwrap() + ); + let message = NetworkMessage(payload.clone()); if !handshaked { @@ -91,6 +96,7 @@ pub async fn connection_wrapper( if let Some(target_instance) = &raw.target_instance { // Forward request + info!("Forwarding message to {}", target_instance.url); let mut instance_connections = instance_connections.lock().await; let pool = instance_connections.get_or_open(&target_instance).unwrap(); let pool_clone = pool.clone(); @@ -106,6 +112,8 @@ pub async fn connection_wrapper( let message_type = &raw.message_type; + info!("Handling message with type: {}", message_type); + match authentication_handle(message_type, &message, &connection_state).await { Err(e) => { let _ = connection_state.send(ConnectionError(e.to_string())).await; diff --git a/giterated-daemon/src/message.rs b/giterated-daemon/src/message.rs index 8db301e..86410cc 100644 --- a/giterated-daemon/src/message.rs +++ b/giterated-daemon/src/message.rs @@ -148,6 +148,11 @@ impl FromMessage for AuthenticatedInstance { let message_json = serde_json::to_vec(&message.message).unwrap(); + info!( + "Verification against: {}", + std::str::from_utf8(&message_json).unwrap() + ); + verifying_key.verify( &message_json, &Signature::try_from(signature.as_ref()).unwrap(), diff --git a/giterated-models/src/model/authenticated.rs b/giterated-models/src/model/authenticated.rs index 858f8f0..c5f9ae4 100644 --- a/giterated-models/src/model/authenticated.rs +++ b/giterated-models/src/model/authenticated.rs @@ -8,6 +8,7 @@ use rsa::{ RsaPrivateKey, }; use serde::{Deserialize, Serialize}; +use tracing::info; use super::{instance::Instance, user::User}; @@ -77,6 +78,11 @@ impl Authenticated { ) -> Self { let message_payload = serde_json::to_vec(&message).unwrap(); + info!( + "Verifying payload: {}", + std::str::from_utf8(&message_payload).unwrap() + ); + let authentication = auth_sources.authenticate_all(&message_payload); Self { @@ -99,6 +105,11 @@ impl Authenticated { pub fn append_authentication(&mut self, authentication: impl AuthenticationSourceProvider) { let message_payload = serde_json::to_vec(&self.message).unwrap(); + info!( + "Verifying payload: {}", + std::str::from_utf8(&message_payload).unwrap() + ); + self.source .push(authentication.authenticate(&message_payload)); }