@@ -6,9 +6,9 @@ use dstack_guest_agent_rpc::{
66 dstack_guest_server:: { DstackGuestRpc , DstackGuestServer } ,
77 tappd_server:: { TappdRpc , TappdServer } ,
88 worker_server:: { WorkerRpc , WorkerServer } ,
9- DeriveK256KeyResponse , DeriveKeyArgs , EmitEventArgs , GetKeyArgs , GetKeyResponse ,
9+ AppInfo , DeriveK256KeyResponse , DeriveKeyArgs , EmitEventArgs , GetKeyArgs , GetKeyResponse ,
1010 GetQuoteResponse , GetTlsKeyArgs , GetTlsKeyResponse , RawQuoteArgs , TdxQuoteArgs ,
11- TdxQuoteResponse , WorkerInfo , WorkerVersion ,
11+ TdxQuoteResponse , WorkerVersion ,
1212} ;
1313use dstack_types:: { AppKeys , SysConfig } ;
1414use fs_err as fs;
@@ -89,6 +89,66 @@ pub struct InternalRpcHandler {
8989 state : AppState ,
9090}
9191
92+ pub async fn get_info ( state : & AppState , external : bool ) -> Result < AppInfo > {
93+ let hide_tcb_info = external && !state. config ( ) . app_compose . public_tcbinfo ;
94+ let response = InternalRpcHandler {
95+ state : state. clone ( ) ,
96+ }
97+ . get_quote ( RawQuoteArgs {
98+ report_data : [ 0 ; 64 ] . to_vec ( ) ,
99+ } )
100+ . await ;
101+ let Ok ( response) = response else {
102+ return Ok ( AppInfo :: default ( ) ) ;
103+ } ;
104+ let Ok ( attestation) = Attestation :: new ( response. quote , response. event_log . into ( ) ) else {
105+ return Ok ( AppInfo :: default ( ) ) ;
106+ } ;
107+ let app_info = attestation
108+ . decode_app_info ( false )
109+ . context ( "Failed to decode app info" ) ?;
110+ let event_log = & attestation. event_log ;
111+ let tcb_info = if hide_tcb_info {
112+ "" . to_string ( )
113+ } else {
114+ let app_compose = state. config ( ) . app_compose . raw . clone ( ) ;
115+ serde_json:: to_string_pretty ( & json ! ( {
116+ "mrtd" : hex:: encode( app_info. mrtd) ,
117+ "rtmr0" : hex:: encode( app_info. rtmr0) ,
118+ "rtmr1" : hex:: encode( app_info. rtmr1) ,
119+ "rtmr2" : hex:: encode( app_info. rtmr2) ,
120+ "rtmr3" : hex:: encode( app_info. rtmr3) ,
121+ "mr_aggregated" : hex:: encode( app_info. mr_aggregated) ,
122+ "os_image_hash" : hex:: encode( & app_info. os_image_hash) ,
123+ "mr_key_provider" : hex:: encode( app_info. mr_key_provider) ,
124+ "compose_hash" : hex:: encode( & app_info. compose_hash) ,
125+ "device_id" : hex:: encode( & app_info. device_id) ,
126+ "event_log" : event_log,
127+ "app_compose" : app_compose,
128+ } ) )
129+ . unwrap_or_default ( )
130+ } ;
131+ let vm_config = if hide_tcb_info {
132+ "" . to_string ( )
133+ } else {
134+ state. inner . vm_config . clone ( )
135+ } ;
136+ Ok ( AppInfo {
137+ app_name : state. config ( ) . app_compose . name . clone ( ) ,
138+ app_id : app_info. app_id ,
139+ instance_id : app_info. instance_id ,
140+ device_id : app_info. device_id ,
141+ mr_aggregated : app_info. mr_aggregated . to_vec ( ) ,
142+ os_image_hash : app_info. os_image_hash . clone ( ) ,
143+ mr_key_provider : app_info. mr_key_provider . to_vec ( ) ,
144+ key_provider_info : String :: from_utf8 ( app_info. key_provider_info ) . unwrap_or_default ( ) ,
145+ compose_hash : app_info. compose_hash . clone ( ) ,
146+ app_cert : state. inner . demo_cert . clone ( ) ,
147+ tcb_info,
148+ vm_config,
149+ } )
150+ }
151+
92152impl DstackGuestRpc for InternalRpcHandler {
93153 async fn get_tls_key ( self , request : GetTlsKeyArgs ) -> anyhow:: Result < GetTlsKeyResponse > {
94154 let mut seed = [ 0u8 ; 32 ] ;
@@ -175,8 +235,8 @@ impl DstackGuestRpc for InternalRpcHandler {
175235 tdx_attest:: extend_rtmr3 ( & request. event , & request. payload )
176236 }
177237
178- async fn info ( self ) -> Result < WorkerInfo > {
179- ExternalRpcHandler { state : self . state } . info ( ) . await
238+ async fn info ( self ) -> Result < AppInfo > {
239+ get_info ( & self . state , false ) . await
180240 }
181241}
182242
@@ -304,8 +364,8 @@ impl TappdRpc for InternalRpcHandlerV0 {
304364 . await
305365 }
306366
307- async fn info ( self ) -> Result < WorkerInfo > {
308- ExternalRpcHandler { state : self . state } . info ( ) . await
367+ async fn info ( self ) -> Result < AppInfo > {
368+ get_info ( & self . state , false ) . await
309369 }
310370}
311371
@@ -330,56 +390,8 @@ impl ExternalRpcHandler {
330390}
331391
332392impl WorkerRpc for ExternalRpcHandler {
333- async fn info ( self ) -> Result < WorkerInfo > {
334- let response = InternalRpcHandler {
335- state : self . state . clone ( ) ,
336- }
337- . get_quote ( RawQuoteArgs {
338- report_data : [ 0 ; 64 ] . to_vec ( ) ,
339- } )
340- . await ;
341- let Ok ( response) = response else {
342- return Ok ( WorkerInfo :: default ( ) ) ;
343- } ;
344- let Ok ( attestation) = Attestation :: new ( response. quote , response. event_log . into ( ) ) else {
345- return Ok ( WorkerInfo :: default ( ) ) ;
346- } ;
347- let app_info = attestation
348- . decode_app_info ( false )
349- . context ( "Failed to decode app info" ) ?;
350- let event_log = & attestation. event_log ;
351- let app_compose = fs:: read_to_string ( & self . state . config ( ) . compose_file ) . unwrap_or_default ( ) ;
352- let tcb_info = serde_json:: to_string_pretty ( & json ! ( {
353- "mrtd" : hex:: encode( app_info. mrtd) ,
354- "rtmr0" : hex:: encode( app_info. rtmr0) ,
355- "rtmr1" : hex:: encode( app_info. rtmr1) ,
356- "rtmr2" : hex:: encode( app_info. rtmr2) ,
357- "rtmr3" : hex:: encode( app_info. rtmr3) ,
358- "mr_aggregated" : hex:: encode( app_info. mr_aggregated) ,
359- "os_image_hash" : hex:: encode( & app_info. os_image_hash) ,
360- "mr_key_provider" : hex:: encode( app_info. mr_key_provider) ,
361- "compose_hash" : hex:: encode( & app_info. compose_hash) ,
362- "device_id" : hex:: encode( & app_info. device_id) ,
363- "event_log" : event_log,
364- "app_compose" : app_compose,
365- } ) )
366- . unwrap_or_default ( ) ;
367- Ok ( WorkerInfo {
368- app_name : self . state . config ( ) . app_name . clone ( ) ,
369- app_id : app_info. app_id ,
370- instance_id : app_info. instance_id ,
371- device_id : app_info. device_id ,
372- mr_aggregated : app_info. mr_aggregated . to_vec ( ) ,
373- os_image_hash : app_info. os_image_hash . clone ( ) ,
374- mr_key_provider : app_info. mr_key_provider . to_vec ( ) ,
375- key_provider_info : String :: from_utf8 ( app_info. key_provider_info ) . unwrap_or_default ( ) ,
376- compose_hash : app_info. compose_hash . clone ( ) ,
377- app_cert : self . state . inner . demo_cert . clone ( ) ,
378- tcb_info,
379- public_logs : self . state . config ( ) . public_logs ,
380- public_sysinfo : self . state . config ( ) . public_sysinfo ,
381- vm_config : self . state . inner . vm_config . clone ( ) ,
382- } )
393+ async fn info ( self ) -> Result < AppInfo > {
394+ get_info ( & self . state , true ) . await
383395 }
384396
385397 async fn version ( self ) -> Result < WorkerVersion > {
0 commit comments