From 7b07819d3fb28d49c431a9d20253492a9542e0f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=9Al=C4=99zak?= Date: Thu, 31 Jul 2025 15:34:53 +0200 Subject: [PATCH 1/2] add register mobile auth endpoint --- proto | 2 +- src/handlers/enrollment.rs | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/proto b/proto index b9f24ac4..749b3844 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit b9f24ac41326bffe4c7e72019ccc8a785f6bd343 +Subproject commit 749b384442ccb245eefa0290bfaa2f7a7aad6ce3 diff --git a/src/handlers/enrollment.rs b/src/handlers/enrollment.rs index f5194f23..cf63b35b 100644 --- a/src/handlers/enrollment.rs +++ b/src/handlers/enrollment.rs @@ -1,5 +1,6 @@ use axum::{extract::State, routing::post, Json, Router}; use axum_extra::extract::{cookie::Cookie, PrivateCookieJar}; +use serde::Deserialize; use time::OffsetDateTime; use crate::{ @@ -9,6 +10,7 @@ use crate::{ proto::{ core_request, core_response, ActivateUserRequest, DeviceConfigResponse, DeviceInfo, EnrollmentStartRequest, EnrollmentStartResponse, ExistingDevice, NewDevice, + RegisterMobileAuthRequest, }, }; @@ -18,6 +20,48 @@ pub(crate) fn router() -> Router { .route("/activate_user", post(activate_user)) .route("/create_device", post(create_device)) .route("/network_info", post(get_network_info)) + .route("/register_mobile", post(register_mobile_auth)) +} + +#[derive(Deserialize, Clone, Debug)] +struct RegisterMobileAuth { + pub auth_pub_key: String, + pub device_pub_key: String, +} + +#[instrument(level = "debug", skip(state))] +async fn register_mobile_auth( + State(state): State, + device_info: DeviceInfo, + private_cookies: PrivateCookieJar, + Json(req): Json, +) -> Result<(), ApiError> { + debug!("Register mobile auth started"); + // set auth info + let token = match private_cookies + .get(ENROLLMENT_COOKIE_NAME) + .map(|cookie| cookie.value().to_string()) + { + Some(token) => token, + None => return Err(ApiError::BadRequest("No token present".into())), + }; + let send_data = RegisterMobileAuthRequest { + token, + auth_pub_key: req.auth_pub_key, + device_pub_key: req.device_pub_key, + }; + let rx = state.grpc_server.send( + core_request::Payload::RegisterMobileAuth(send_data), + device_info, + )?; + let payload = get_core_response(rx).await?; + if let core_response::Payload::Empty(()) = payload { + info!("Registered mobile device for auth"); + Ok(()) + } else { + error!("Received invalid gRPC response type: {payload:#?}"); + Err(ApiError::InvalidResponseType) + } } #[instrument(level = "debug", skip(state))] From 3c8bfb6fe30d527a776dc4302d0c98e43a7635df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=9Al=C4=99zak?= Date: Fri, 1 Aug 2025 15:20:00 +0200 Subject: [PATCH 2/2] update proto --- proto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto b/proto index 749b3844..54b7b78d 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 749b384442ccb245eefa0290bfaa2f7a7aad6ce3 +Subproject commit 54b7b78dde005e6abcf783633e8af92f7e20db4b