Skip to content
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
12 changes: 9 additions & 3 deletions wallguard-server/src/orchestrator/auth_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ macro_rules! fail_with_status {
let _ = $outbound.send(Err(tonic::Status::internal($msg))).await;
return;
}};
($outbound:expr, $msg:expr, $err:expr) => {{
log::error!("{}: {}", $msg, $err.to_str());
let _ = $outbound.send(Err(tonic::Status::internal($msg))).await;
return;
}};
}

pub struct AuthReqHandler {
Expand Down Expand Up @@ -237,12 +242,13 @@ impl AuthReqHandler {
..Default::default()
};

let Ok(instance_id) = context
let instance_id = match context
.datastore
.create_device_instance(token, &device_instance)
.await
else {
fail_with_status!(outbound, "Failed to create device instance")
{
Ok(instance_id) => instance_id,
Err(err) => fail_with_status!(outbound, "Failed to create device instance", err),
};

let instance = Arc::new(Mutex::new(Instance::new(
Expand Down
25 changes: 20 additions & 5 deletions wallguard/src/control_channel/await_authorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,27 @@ pub async fn await_authorization(

match message {
server_message::Message::DeviceAuthorizedMessage(data) => {
if let Some(app_id) = data.app_id {
Storage::set_value(Secret::AppId, &app_id).await?;
}
let app_id = match data.app_id {
Some(app_id) => {
Storage::set_value(Secret::AppId, &app_id).await?;
Some(app_id)
}
None => Storage::get_value(Secret::AppId).await,
};

let app_secret = match data.app_secret {
Some(app_secret) => {
Storage::set_value(Secret::AppSecret, &app_secret).await?;
Some(app_secret)
}
None => Storage::get_value(Secret::AppSecret).await,
};

if let Some(app_secret) = data.app_secret {
Storage::set_value(Secret::AppSecret, &app_secret).await?;
if app_id.is_none() || app_secret.is_none() {
return Err(
"Server approved device without providing credentials, and none are cached locally",
)
.handle_err(location!());
}

Ok(Verdict::Approved)
Expand Down
Loading