@@ -29,14 +29,18 @@ use crate::{
2929 } ,
3030 DB_POOL ,
3131 } ,
32- enterprise:: { periodic:: config:: poll_instance, provisioning:: ProvisioningConfig } ,
32+ enterprise:: {
33+ periodic:: config:: poll_instance, posture:: authorize_posture_session,
34+ provisioning:: ProvisioningConfig ,
35+ } ,
3336 error:: Error ,
3437 events:: EventKey ,
3538 log_watcher:: {
3639 global_log_watcher:: { spawn_global_log_watcher_task, stop_global_log_watcher_task} ,
3740 service_log_watcher:: stop_log_watcher_task,
3841 } ,
3942 proto:: defguard:: client_types:: DeviceConfigResponse ,
43+ service:: proto:: defguard:: enterprise:: posture:: v2:: DevicePostureData ,
4044 tray:: { configure_tray_icon, reload_tray_menu} ,
4145 utils:: {
4246 construct_platform_header, disconnect_interface, get_location_interface_details,
@@ -50,7 +54,7 @@ use crate::{
5054use crate :: {
5155 service:: {
5256 client:: DAEMON_CLIENT ,
53- proto:: {
57+ proto:: defguard :: client :: v1 :: {
5458 DeleteServiceLocationsRequest , RemoveInterfaceRequest , SaveServiceLocationsRequest ,
5559 } ,
5660 } ,
@@ -72,6 +76,11 @@ pub async fn connect(
7276 "Identified location with ID {location_id} as \" {}\" , handling connection." ,
7377 location. name
7478 ) ;
79+ let preshared_key = if location. posture_check_required && preshared_key. is_none ( ) {
80+ Some ( authorize_posture_session ( & location) . await ?)
81+ } else {
82+ preshared_key
83+ } ;
7584 handle_connection_for_location ( & location, preshared_key, & handle) . await ?;
7685 reload_tray_menu ( & handle) . await ;
7786 info ! ( "Connected to location {location}" ) ;
@@ -490,6 +499,7 @@ pub struct LocationInfo {
490499 pub pubkey : String ,
491500 pub network_id : Id ,
492501 pub location_mfa_mode : LocationMfaMode ,
502+ pub posture_check_required : bool ,
493503 pub mfa_method : Option < LocationMfaMethod > ,
494504}
495505
@@ -543,6 +553,7 @@ pub async fn all_locations(instance_id: Id) -> Result<Vec<LocationInfo>, Error>
543553 pubkey : location. pubkey ,
544554 network_id : location. network_id ,
545555 location_mfa_mode : location. location_mfa_mode ,
556+ posture_check_required : location. posture_check_required ,
546557 mfa_method : location. mfa_method ,
547558 } ;
548559 location_info. push ( info) ;
@@ -1521,6 +1532,28 @@ pub fn get_platform_header() -> String {
15211532 construct_platform_header ( )
15221533}
15231534
1535+ #[ tauri:: command( async ) ]
1536+ #[ cfg( not( windows) ) ]
1537+ pub async fn get_posture_data ( ) -> Result < DevicePostureData , Error > {
1538+ debug ! ( "Received a command to prepare posture report" ) ;
1539+ Ok ( DevicePostureData :: new ( ) )
1540+ }
1541+
1542+ #[ tauri:: command( async ) ]
1543+ #[ cfg( windows) ]
1544+ pub async fn get_posture_data ( ) -> Result < DevicePostureData , Error > {
1545+ debug ! ( "Received a command to prepare posture report" ) ;
1546+ DAEMON_CLIENT
1547+ . clone ( )
1548+ . get_posture_data ( tonic:: Request :: new ( ( ) ) )
1549+ . await
1550+ . map ( |response| response. into_inner ( ) )
1551+ . map_err ( |err| {
1552+ error ! ( "Failed to get posture data from the daemon: {err}" ) ;
1553+ Error :: InternalError ( format ! ( "Failed to get posture data from the daemon: {err}" ) )
1554+ } )
1555+ }
1556+
15241557#[ derive( Debug , Serialize ) ]
15251558pub struct ActiveConnectionSummary {
15261559 pub id : Id ,
0 commit comments