-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add authentication for RPC service #89
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be great to move the authentication stuff to its own module.
crates/server/src/rpc/mod.rs
Outdated
Ok(ws) => Ok((ws, address)), | ||
Err(err) => Err(AuthenticationErrors::UnexpectedError(Box::new(err))), | ||
} | ||
} else if let Err(err) = ws_write.close().await { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you say if we close the websocket in the upgrade handler and return the error first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay but the error would be Err((Websocket,AuthenticationErrors))
because we have to consume the ws
crates/server/src/rpc/mod.rs
Outdated
|
||
match tokio::time::timeout(Duration::from_secs(30), ws_read.next()).await { | ||
Ok(client_response) => { | ||
let response = client_response.unwrap().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we handle the possible errors here?
crates/server/src/rpc/mod.rs
Outdated
WrongSignature, | ||
Timeout, | ||
NotTextMessage, | ||
UnexpectedError(Box<dyn std::error::Error + Send + Sync>), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we move the socket close to the handler, then we don't need this one.
crates/server/src/rpc/mod.rs
Outdated
@@ -121,3 +146,60 @@ async fn handle_rejection(err: Rejection) -> Result<impl Reply, std::convert::In | |||
)) | |||
} | |||
} | |||
|
|||
pub enum AuthenticationErrors { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub enum AuthenticationErrors { | |
pub enum AuthenticationError { |
crates/server/src/rpc/mod.rs
Outdated
Ok(client_response) => { | ||
let response = client_response.unwrap().unwrap(); | ||
if let Ok(auth_chain) = response.to_str() { | ||
let auth_chain = AuthChain::from_json(auth_chain).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we handle possible errors here?
crates/server/src/rpc/mod.rs
Outdated
if ws_write | ||
.send(Message::text(&message_to_be_firmed)) | ||
.await | ||
.is_err() | ||
{ | ||
return Err(AuthenticationErrors::FailedToSendChallenge); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ws_write | |
.send(Message::text(&message_to_be_firmed)) | |
.await | |
.is_err() | |
{ | |
return Err(AuthenticationErrors::FailedToSendChallenge); | |
} | |
ws_write | |
.send(Message::text(&message_to_be_firmed)) | |
.await | |
.map_err(|_| AuthenticationErrors::FailedToSendChallenge)?; |
This PR: