Fixes
parent: tbd commit: 25c3410
Showing 7 changed files with 41 insertions and 15 deletions
giterated-daemon/src/connection/authentication.rs
@@ -14,21 +14,21 @@ pub async fn authentication_handle( | ||
14 | 14 | state: &ConnectionState, |
15 | 15 | ) -> Result<bool, Error> { |
16 | 16 | match message_type { |
17 | "&giterated_daemon::messages::authentication::RegisterAccountRequest" => { | |
17 | "&giterated_models::messages::authentication::RegisterAccountRequest" => { | |
18 | 18 | register_account_request |
19 | 19 | .handle_message(&message, state) |
20 | 20 | .await?; |
21 | 21 | |
22 | 22 | Ok(true) |
23 | 23 | } |
24 | "&giterated_daemon::messages::authentication::AuthenticationTokenRequest" => { | |
24 | "&giterated_models::messages::authentication::AuthenticationTokenRequest" => { | |
25 | 25 | authentication_token_request |
26 | 26 | .handle_message(&message, state) |
27 | 27 | .await?; |
28 | 28 | |
29 | 29 | Ok(true) |
30 | 30 | } |
31 | "&giterated_daemon::messages::authentication::TokenExtensionRequest" => { | |
31 | "&giterated_models::messages::authentication::TokenExtensionRequest" => { | |
32 | 32 | token_extension_request |
33 | 33 | .handle_message(&message, state) |
34 | 34 | .await?; |
giterated-daemon/src/connection/handshake.rs
@@ -117,6 +117,8 @@ async fn handshake_finalize( | ||
117 | 117 | Message(finalize): Message<HandshakeFinalize>, |
118 | 118 | State(connection_state): State<ConnectionState>, |
119 | 119 | ) -> Result<(), HandshakeError> { |
120 | connection_state.handshaked.store(true, Ordering::SeqCst); | |
121 | ||
120 | 122 | connection_state |
121 | 123 | .send(HandshakeFinalize { success: true }) |
122 | 124 | .await |
giterated-daemon/src/connection/repository.rs
@@ -17,34 +17,34 @@ pub async fn repository_handle( | ||
17 | 17 | state: &ConnectionState, |
18 | 18 | ) -> Result<bool, Error> { |
19 | 19 | match message_type { |
20 | "&giterated_daemon::messages::repository::RepositoryCreateRequest" => { | |
20 | "&giterated_models::messages::repository::RepositoryCreateRequest" => { | |
21 | 21 | create_repository.handle_message(&message, state).await?; |
22 | 22 | |
23 | 23 | Ok(true) |
24 | 24 | } |
25 | "&giterated_daemon::messages::repository::RepositoryFileInspectRequest" => { | |
25 | "&giterated_models::messages::repository::RepositoryFileInspectRequest" => { | |
26 | 26 | repository_file_inspect |
27 | 27 | .handle_message(&message, state) |
28 | 28 | .await?; |
29 | 29 | |
30 | 30 | Ok(true) |
31 | 31 | } |
32 | "&giterated_daemon::messages::repository::RepositoryInfoRequest" => { | |
32 | "&giterated_models::messages::repository::RepositoryInfoRequest" => { | |
33 | 33 | repository_info.handle_message(&message, state).await?; |
34 | 34 | |
35 | 35 | Ok(true) |
36 | 36 | } |
37 | "&giterated_daemon::messages::repository::RepositoryIssuesCountRequest" => { | |
37 | "&giterated_models::messages::repository::RepositoryIssuesCountRequest" => { | |
38 | 38 | issues_count.handle_message(&message, state).await?; |
39 | 39 | |
40 | 40 | Ok(true) |
41 | 41 | } |
42 | "&giterated_daemon::messages::repository::RepositoryIssueLabelsRequest" => { | |
42 | "&giterated_models::messages::repository::RepositoryIssueLabelsRequest" => { | |
43 | 43 | issue_labels.handle_message(&message, state).await?; |
44 | 44 | |
45 | 45 | Ok(true) |
46 | 46 | } |
47 | "&giterated_daemon::messages::repository::RepositoryIssuesRequest" => { | |
47 | "&giterated_models::messages::repository::RepositoryIssuesRequest" => { | |
48 | 48 | issues.handle_message(&message, state).await?; |
49 | 49 | |
50 | 50 | Ok(true) |
giterated-daemon/src/connection/user.rs
@@ -18,32 +18,32 @@ pub async fn user_handle( | ||
18 | 18 | state: &ConnectionState, |
19 | 19 | ) -> Result<bool, Error> { |
20 | 20 | match message_type { |
21 | "&giterated_daemon::messages::user::UserDisplayNameRequest" => { | |
21 | "&giterated_models::messages::user::UserDisplayNameRequest" => { | |
22 | 22 | display_name.handle_message(&message, state).await?; |
23 | 23 | |
24 | 24 | Ok(true) |
25 | 25 | } |
26 | "&giterated_daemon::messages::user::UserDisplayImageRequest" => { | |
26 | "&giterated_models::messages::user::UserDisplayImageRequest" => { | |
27 | 27 | display_image.handle_message(&message, state).await?; |
28 | 28 | |
29 | 29 | Ok(true) |
30 | 30 | } |
31 | "&giterated_daemon::messages::user::UserBioRequest" => { | |
31 | "&giterated_models::messages::user::UserBioRequest" => { | |
32 | 32 | bio.handle_message(&message, state).await?; |
33 | 33 | |
34 | 34 | Ok(true) |
35 | 35 | } |
36 | "&giterated_daemon::messages::user::UserRepositoriesRequest" => { | |
36 | "&giterated_models::messages::user::UserRepositoriesRequest" => { | |
37 | 37 | repositories.handle_message(&message, state).await?; |
38 | 38 | |
39 | 39 | Ok(true) |
40 | 40 | } |
41 | "&giterated_daemon::messages::user::UserSettingsRequest" => { | |
41 | "&giterated_models::messages::user::UserSettingsRequest" => { | |
42 | 42 | user_settings.handle_message(&message, state).await?; |
43 | 43 | |
44 | 44 | Ok(true) |
45 | 45 | } |
46 | "&giterated_daemon::messages::user::UserWriteSettingsRequest" => { | |
46 | "&giterated_models::messages::user::UserWriteSettingsRequest" => { | |
47 | 47 | write_user_settings.handle_message(&message, state).await?; |
48 | 48 | |
49 | 49 | Ok(true) |
giterated-daemon/src/connection/wrapper.rs
@@ -78,6 +78,11 @@ pub async fn connection_wrapper( | ||
78 | 78 | _ => continue, |
79 | 79 | }; |
80 | 80 | |
81 | info!( | |
82 | "Received payload: {}", | |
83 | std::str::from_utf8(&payload).unwrap() | |
84 | ); | |
85 | ||
81 | 86 | let message = NetworkMessage(payload.clone()); |
82 | 87 | |
83 | 88 | if !handshaked { |
@@ -91,6 +96,7 @@ pub async fn connection_wrapper( | ||
91 | 96 | |
92 | 97 | if let Some(target_instance) = &raw.target_instance { |
93 | 98 | // Forward request |
99 | info!("Forwarding message to {}", target_instance.url); | |
94 | 100 | let mut instance_connections = instance_connections.lock().await; |
95 | 101 | let pool = instance_connections.get_or_open(&target_instance).unwrap(); |
96 | 102 | let pool_clone = pool.clone(); |
@@ -106,6 +112,8 @@ pub async fn connection_wrapper( | ||
106 | 112 | |
107 | 113 | let message_type = &raw.message_type; |
108 | 114 | |
115 | info!("Handling message with type: {}", message_type); | |
116 | ||
109 | 117 | match authentication_handle(message_type, &message, &connection_state).await { |
110 | 118 | Err(e) => { |
111 | 119 | let _ = connection_state.send(ConnectionError(e.to_string())).await; |
giterated-daemon/src/message.rs
@@ -148,6 +148,11 @@ impl FromMessage<ConnectionState> for AuthenticatedInstance { | ||
148 | 148 | |
149 | 149 | let message_json = serde_json::to_vec(&message.message).unwrap(); |
150 | 150 | |
151 | info!( | |
152 | "Verification against: {}", | |
153 | std::str::from_utf8(&message_json).unwrap() | |
154 | ); | |
155 | ||
151 | 156 | verifying_key.verify( |
152 | 157 | &message_json, |
153 | 158 | &Signature::try_from(signature.as_ref()).unwrap(), |
giterated-models/src/model/authenticated.rs
@@ -8,6 +8,7 @@ use rsa::{ | ||
8 | 8 | RsaPrivateKey, |
9 | 9 | }; |
10 | 10 | use serde::{Deserialize, Serialize}; |
11 | use tracing::info; | |
11 | 12 | |
12 | 13 | use super::{instance::Instance, user::User}; |
13 | 14 | |
@@ -77,6 +78,11 @@ impl<T: Serialize> Authenticated<T> { | ||
77 | 78 | ) -> Self { |
78 | 79 | let message_payload = serde_json::to_vec(&message).unwrap(); |
79 | 80 | |
81 | info!( | |
82 | "Verifying payload: {}", | |
83 | std::str::from_utf8(&message_payload).unwrap() | |
84 | ); | |
85 | ||
80 | 86 | let authentication = auth_sources.authenticate_all(&message_payload); |
81 | 87 | |
82 | 88 | Self { |
@@ -99,6 +105,11 @@ impl<T: Serialize> Authenticated<T> { | ||
99 | 105 | pub fn append_authentication(&mut self, authentication: impl AuthenticationSourceProvider) { |
100 | 106 | let message_payload = serde_json::to_vec(&self.message).unwrap(); |
101 | 107 | |
108 | info!( | |
109 | "Verifying payload: {}", | |
110 | std::str::from_utf8(&message_payload).unwrap() | |
111 | ); | |
112 | ||
102 | 113 | self.source |
103 | 114 | .push(authentication.authenticate(&message_payload)); |
104 | 115 | } |