This repository was archived by the owner on Aug 8, 2025. It is now read-only.
feat: add authentication for RPC service#89
Merged
Merged
Conversation
lauti7
marked this pull request as ready for review
May 8, 2023 15:42
guidota
suggested changes
May 8, 2023
guidota
left a comment
Contributor
There was a problem hiding this comment.
I think it would be great to move the authentication stuff to its own module.
| Ok(ws) => Ok((ws, address)), | ||
| Err(err) => Err(AuthenticationErrors::UnexpectedError(Box::new(err))), | ||
| } | ||
| } else if let Err(err) = ws_write.close().await { |
Contributor
There was a problem hiding this comment.
What do you say if we close the websocket in the upgrade handler and return the error first?
Contributor
Author
There was a problem hiding this comment.
Okay but the error would be Err((Websocket,AuthenticationErrors)) because we have to consume the ws
|
|
||
| match tokio::time::timeout(Duration::from_secs(30), ws_read.next()).await { | ||
| Ok(client_response) => { | ||
| let response = client_response.unwrap().unwrap(); |
Contributor
There was a problem hiding this comment.
Shouldn't we handle the possible errors here?
| WrongSignature, | ||
| Timeout, | ||
| NotTextMessage, | ||
| UnexpectedError(Box<dyn std::error::Error + Send + Sync>), |
Contributor
There was a problem hiding this comment.
If we move the socket close to the handler, then we don't need this one.
| } | ||
| } | ||
|
|
||
| pub enum AuthenticationErrors { |
Contributor
There was a problem hiding this comment.
Suggested change
| pub enum AuthenticationErrors { | |
| pub enum AuthenticationError { |
guidota
reviewed
May 8, 2023
| 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(); |
Contributor
There was a problem hiding this comment.
Shouldn't we handle possible errors here?
guidota
reviewed
May 8, 2023
Comment on lines
+166
to
+172
| if ws_write | ||
| .send(Message::text(&message_to_be_firmed)) | ||
| .await | ||
| .is_err() | ||
| { | ||
| return Err(AuthenticationErrors::FailedToSendChallenge); | ||
| } |
Contributor
There was a problem hiding this comment.
Suggested change
| 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)?; |
guidota
approved these changes
May 8, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR: