Skip to content
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

fix: remove remote address #38

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions affinidi-messaging-mediator/src/database/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
#[serde(skip)]
pub session_id: String,
pub challenge: String,
pub remote_address: String,
pub state: SessionState,
pub did: String,
}
Expand All @@ -82,19 +81,6 @@
));
}

if let Some(remote_address) = hash.get("remote_address") {
session.remote_address.clone_from(remote_address);
} else {
warn!(
"{}: No remote_address found when retrieving session({})!",
sid, sid
);
return Err(MediatorError::SessionError(
sid.into(),
"No remote_address found when retrieving session!".into(),
));
}

if let Some(state) = hash.get("state") {
session.state = state.try_into()?;
} else {
Expand Down Expand Up @@ -122,7 +108,7 @@
impl DatabaseHandler {
/// Creates a new session in the database
/// Typically called when sending the initial challenge to the client
pub async fn create_session(&self, session: &Session) -> Result<(), MediatorError> {

Check warning on line 111 in affinidi-messaging-mediator/src/database/session.rs

View workflow job for this annotation

GitHub Actions / rust-pipeline / Cargo Check

this function depends on never type fallback being `()`

Check warning on line 111 in affinidi-messaging-mediator/src/database/session.rs

View workflow job for this annotation

GitHub Actions / rust-pipeline / Test Suite

this function depends on never type fallback being `()`
let mut con = self.get_async_connection().await?;

let sid = format!("SESSION:{}", session.session_id);
Expand All @@ -133,8 +119,6 @@
.arg(&sid)
.arg("challenge")
.arg(&session.challenge)
.arg("remote_address")
.arg(&session.remote_address)
.arg("state")
.arg(session.state.to_string())
.arg("did")
Expand Down
17 changes: 8 additions & 9 deletions affinidi-messaging-mediator/src/handlers/authenticate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::{net::SocketAddr, time::SystemTime};

Check warning on line 1 in affinidi-messaging-mediator/src/handlers/authenticate.rs

View workflow job for this annotation

GitHub Actions / rust-pipeline / Cargo Check

unused import: `net::SocketAddr`

Check warning on line 1 in affinidi-messaging-mediator/src/handlers/authenticate.rs

View workflow job for this annotation

GitHub Actions / rust-pipeline / Test Suite

unused import: `net::SocketAddr`

use affinidi_messaging_didcomm::{envelope::MetaEnvelope, Message, UnpackOptions};
use affinidi_messaging_sdk::messages::GenericDataStruct;
use axum::{
extract::{ConnectInfo, State},

Check warning on line 6 in affinidi-messaging-mediator/src/handlers/authenticate.rs

View workflow job for this annotation

GitHub Actions / rust-pipeline / Cargo Check

unused import: `ConnectInfo`

Check warning on line 6 in affinidi-messaging-mediator/src/handlers/authenticate.rs

View workflow job for this annotation

GitHub Actions / rust-pipeline / Test Suite

unused import: `ConnectInfo`
Json,
};
use http::StatusCode;
Expand Down Expand Up @@ -47,23 +47,22 @@
/// This is the first step in the authentication process
/// Creates a new sessionID and a random challenge string to the client
pub async fn authentication_challenge(
ConnectInfo(connect_info): ConnectInfo<SocketAddr>,
// ConnectInfo(connect_info): ConnectInfo<SocketAddr>,
State(state): State<SharedData>,
Json(body): Json<ChallengeBody>,
) -> Result<(StatusCode, Json<SuccessResponse<AuthenticationChallenge>>), AppError> {
let session = Session {
session_id: create_random_string(12),
challenge: create_random_string(32),
remote_address: connect_info.to_string(),
state: SessionState::ChallengeSent,
did: body.did.clone(),
};

state.database.create_session(&session).await?;

info!(
"{}:{}: Challenge sent to DID({})",
session.session_id, session.remote_address, session.did
debug!(
"{}: Challenge sent to DID({})",
session.session_id, session.did
);

Ok((
Expand Down Expand Up @@ -195,8 +194,8 @@
debug!("Database session state is ChallengeSent - Good to go!");
} else {
warn!(
"{}:{}: Session is in an invalid state for authentication",
session.session_id, session.remote_address
"{}: Session is in an invalid state for authentication",
session.session_id
);
return Err(MediatorError::SessionError(
session.session_id.clone(),
Expand Down Expand Up @@ -258,8 +257,8 @@
.await?;

info!(
"{}:{}: Authentication successful for DID({})",
session.session_id, session.remote_address, session.did
"{}: Authentication successful for DID({})",
session.session_id, session.did
);

Ok((
Expand Down
Loading