Skip to content
This repository was archived by the owner on Aug 8, 2025. It is now read-only.

feat: add authentication for RPC service#89

Merged
lauti7 merged 7 commits into
mainfrom
feat/ws-auth
May 9, 2023
Merged

feat: add authentication for RPC service#89
lauti7 merged 7 commits into
mainfrom
feat/ws-auth

Conversation

@lauti7

@lauti7 lauti7 commented May 5, 2023

Copy link
Copy Markdown
Contributor

This PR:

@lauti7 lauti7 changed the title auth wip feat: add authentication for RPC service May 5, 2023
@lauti7
lauti7 marked this pull request as ready for review May 8, 2023 15:42
@lauti7
lauti7 requested a review from guidota May 8, 2023 15:43

@guidota guidota left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread 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 {

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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

Comment thread 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();

Copy link
Copy Markdown
Contributor

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?

Comment thread crates/server/src/rpc/mod.rs Outdated
WrongSignature,
Timeout,
NotTextMessage,
UnexpectedError(Box<dyn std::error::Error + Send + Sync>),

Copy link
Copy Markdown
Contributor

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.

Comment thread crates/server/src/rpc/mod.rs Outdated
}
}

pub enum AuthenticationErrors {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pub enum AuthenticationErrors {
pub enum AuthenticationError {

Comment thread 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();

Copy link
Copy Markdown
Contributor

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?

Comment thread crates/server/src/rpc/mod.rs Outdated
Comment on lines +166 to +172
if ws_write
.send(Message::text(&message_to_be_firmed))
.await
.is_err()
{
return Err(AuthenticationErrors::FailedToSendChallenge);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)?;

@lauti7 lauti7 linked an issue May 9, 2023 that may be closed by this pull request
@lauti7
lauti7 merged commit 2aaff1d into main May 9, 2023
@lauti7
lauti7 deleted the feat/ws-auth branch May 9, 2023 13:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Middleware for websocket server (RPC Server)

2 participants