@@ -26,7 +26,7 @@ use k256::ecdsa::SigningKey;
2626use or_panic:: ResultOrPanic ;
2727use ra_rpc:: { CallContext , RpcCall } ;
2828use ra_tls:: {
29- attestation:: { QuoteContentType , VersionedAttestation , DEFAULT_HASH_ALGORITHM } ,
29+ attestation:: { QuoteContentType , DEFAULT_HASH_ALGORITHM } ,
3030 cert:: CertConfigV2 ,
3131 kdf:: { derive_key, derive_p256_key_pair_from_bytes} ,
3232} ;
@@ -62,20 +62,25 @@ struct AppStateInner {
6262}
6363
6464impl AppStateInner {
65- fn attestation_override ( & self ) -> Result < Option < VersionedAttestation > > {
66- self . platform . attestation_override ( )
67- }
68-
6965 fn info_attestation ( & self ) -> Result < Option < ra_rpc:: Attestation > > {
7066 self . platform . attestation_for_info ( )
7167 }
7268
69+ async fn issue_cert ( & self , key : & KeyPair , config : CertConfigV2 ) -> Result < Vec < String > > {
70+ let attestation = self
71+ . platform
72+ . certificate_attestation ( & key. public_key_der ( ) )
73+ . context ( "Failed to get certificate attestation" ) ?;
74+ self . cert_client
75+ . sign_cert_with_attestation ( key, config, attestation)
76+ . await
77+ . context ( "Failed to sign the CSR" )
78+ }
79+
7380 async fn request_demo_cert ( & self ) -> Result < String > {
7481 let key = KeyPair :: generate ( ) . context ( "Failed to generate demo key" ) ?;
75- let attestation_override = self . attestation_override ( ) ?;
7682 let demo_cert = self
77- . cert_client
78- . request_cert (
83+ . issue_cert (
7984 & key,
8085 CertConfigV2 {
8186 org_name : None ,
@@ -88,7 +93,6 @@ impl AppStateInner {
8893 not_after : None ,
8994 not_before : None ,
9095 } ,
91- attestation_override,
9296 )
9397 . await
9498 . context ( "Failed to get app cert" ) ?
@@ -260,18 +264,7 @@ impl DstackGuestRpc for InternalRpcHandler {
260264 not_after : request. not_after ,
261265 not_before : request. not_before ,
262266 } ;
263- let attestation_override = self
264- . state
265- . inner
266- . attestation_override ( )
267- . context ( "Failed to load platform attestation override" ) ?;
268- let certificate_chain = self
269- . state
270- . inner
271- . cert_client
272- . request_cert ( & derived_key, config, attestation_override)
273- . await
274- . context ( "Failed to sign the CSR" ) ?;
267+ let certificate_chain = self . state . inner . issue_cert ( & derived_key, config) . await ?;
275268 Ok ( GetTlsKeyResponse {
276269 key : derived_key. serialize_pem ( ) ,
277270 certificate_chain,
@@ -497,18 +490,7 @@ impl TappdRpc for InternalRpcHandlerV0 {
497490 not_before : None ,
498491 not_after : None ,
499492 } ;
500- let attestation_override = self
501- . state
502- . inner
503- . attestation_override ( )
504- . context ( "Failed to load platform attestation override" ) ?;
505- let certificate_chain = self
506- . state
507- . inner
508- . cert_client
509- . request_cert ( & derived_key, config, attestation_override)
510- . await
511- . context ( "Failed to sign the CSR" ) ?;
493+ let certificate_chain = self . state . inner . issue_cert ( & derived_key, config) . await ?;
512494 Ok ( GetTlsKeyResponse {
513495 key : derived_key. serialize_pem ( ) ,
514496 certificate_chain,
@@ -671,12 +653,14 @@ mod tests {
671653 use super :: * ;
672654 use crate :: {
673655 backend:: {
674- load_versioned_attestation, simulated_attest_response, simulated_info_attestation,
656+ load_versioned_attestation, simulated_attest_response,
657+ simulated_certificate_attestation, simulated_info_attestation,
675658 simulated_quote_response, PlatformBackend ,
676659 } ,
677660 config:: { AppComposeWrapper , Config } ,
678661 } ;
679662 use dstack_guest_agent_rpc:: { GetAttestationForAppKeyRequest , SignRequest } ;
663+ use ra_tls:: attestation:: VersionedAttestation ;
680664 use dstack_types:: { AppCompose , AppKeys , KeyProvider } ;
681665 use ed25519_dalek:: ed25519:: signature:: hazmat:: PrehashVerifier ;
682666 use ed25519_dalek:: {
@@ -827,8 +811,8 @@ pNs85uhOZE8z2jr8Pg==
827811 Ok ( Some ( simulated_info_attestation ( & self . attestation ) ) )
828812 }
829813
830- fn attestation_override ( & self ) -> Result < Option < VersionedAttestation > > {
831- Ok ( Some ( self . attestation . clone ( ) ) )
814+ fn certificate_attestation ( & self , pubkey : & [ u8 ] ) -> Result < VersionedAttestation > {
815+ Ok ( simulated_certificate_attestation ( & self . attestation , pubkey ) )
832816 }
833817
834818 fn quote_response (
0 commit comments