@@ -17,40 +17,36 @@ use credentialsd_common::{
1717 } ,
1818} ;
1919
20- use crate :: {
21- dbus:: CredentialRequestController ,
22- webauthn:: { AppId , NavigationContext , Origin } ,
23- } ;
20+ use crate :: webauthn:: { AppId , NavigationContext , Origin } ;
2421
2522use super :: {
2623 check_origin_from_app, check_origin_from_privileged_client, get_app_info_from_pid,
27- handle_create_credential, handle_get_client_capabilities, handle_get_credential,
28- CredentialGateway ,
24+ GatewayService ,
2925} ;
3026
3127pub const SERVICE_NAME : & str = "xyz.iinuwa.credentialsd.Credentials" ;
3228pub const SERVICE_PATH : & str = "/xyz/iinuwa/credentialsd/Credentials" ;
3329
34- pub ( super ) async fn start_dbus_gateway < C : CredentialRequestController + Send + Sync + ' static > (
35- controller : C ,
30+ pub ( super ) async fn start_dbus_gateway (
31+ svc : Arc < AsyncMutex < GatewayService > > ,
3632) -> Result < Connection , zbus:: Error > {
3733 zbus:: connection:: Builder :: session ( )
3834 . inspect_err ( |err| {
3935 tracing:: error!( "Failed to connect to D-Bus session: {err}" ) ;
4036 } ) ?
4137 . name ( SERVICE_NAME ) ?
42- . serve_at (
43- SERVICE_PATH ,
44- CredentialGateway {
45- controller : Arc :: new ( AsyncMutex :: new ( controller) ) ,
46- } ,
47- ) ?
38+ . serve_at ( SERVICE_PATH , CredentialGateway { svc : svc. clone ( ) } ) ?
4839 . build ( )
4940 . await
5041}
42+
43+ struct CredentialGateway {
44+ svc : Arc < AsyncMutex < GatewayService > > ,
45+ }
46+
5147/// These are public methods that can be called by arbitrary clients to begin a credential flow.
5248#[ interface( name = "xyz.iinuwa.credentialsd.Credentials1" ) ]
53- impl < C : CredentialRequestController + Send + Sync + ' static > super :: CredentialGateway < C > {
49+ impl CredentialGateway {
5450 async fn create_credential (
5551 & self ,
5652 #[ zbus( header) ] header : Header < ' _ > ,
@@ -86,14 +82,17 @@ impl<C: CredentialRequestController + Send + Sync + 'static> super::CredentialGa
8682 let request_environment = check_origin_from_privileged_client ( origin, top_origin) ?;
8783 // Find out where this request is coming from (which application is requesting this)
8884 let requesting_app = query_connection_peer_binary ( header, connection) . await ;
89- let response = handle_create_credential (
90- & self . controller ,
91- request,
92- request_environment,
93- requesting_app,
94- parent_window. into ( ) ,
95- )
96- . await ?;
85+ let response = self
86+ . svc
87+ . lock ( )
88+ . await
89+ . handle_create_credential (
90+ request,
91+ request_environment,
92+ requesting_app,
93+ parent_window. into ( ) ,
94+ )
95+ . await ?;
9796 Ok ( response)
9897 }
9998
@@ -132,19 +131,22 @@ impl<C: CredentialRequestController + Send + Sync + 'static> super::CredentialGa
132131 let request_environment = check_origin_from_privileged_client ( origin, top_origin) ?;
133132 // Find out where this request is coming from (which application is requesting this)
134133 let requesting_app = query_connection_peer_binary ( header, connection) . await ;
135- let response = handle_get_credential (
136- & self . controller ,
137- request,
138- request_environment,
139- requesting_app,
140- parent_window. into ( ) ,
141- )
142- . await ?;
134+ let response = self
135+ . svc
136+ . lock ( )
137+ . await
138+ . handle_get_credential (
139+ request,
140+ request_environment,
141+ requesting_app,
142+ parent_window. into ( ) ,
143+ )
144+ . await ?;
143145 Ok ( response)
144146 }
145147
146148 async fn get_client_capabilities ( & self ) -> fdo:: Result < GetClientCapabilitiesResponse > {
147- let capabilities = handle_get_client_capabilities ( ) ;
149+ let capabilities = self . svc . lock ( ) . await . handle_get_client_capabilities ( ) ;
148150 Ok ( capabilities)
149151 }
150152}
0 commit comments