@@ -27,8 +27,11 @@ use luks2::{
2727 LuksAf , LuksConfig , LuksDigest , LuksHeader , LuksJson , LuksKdf , LuksKeyslot , LuksSegment ,
2828 LuksSegmentSize ,
2929} ;
30- use ra_rpc:: client:: { CertInfo , RaClient , RaClientConfig } ;
31- use ra_tls:: cert:: { generate_ra_cert, CertConfigV2 } ;
30+ use ra_rpc:: { client:: { CertInfo , RaClient , RaClientConfig } , Attestation } ;
31+ use ra_tls:: {
32+ attestation:: QuoteContentType ,
33+ cert:: { generate_ra_cert, CertConfigV2 , CertSigningRequestV2 , Csr } ,
34+ } ;
3235use rand:: Rng as _;
3336use safe_write:: safe_write;
3437use scopeguard:: defer;
@@ -53,6 +56,30 @@ use ra_tls::rcgen::{KeyPair, PKCS_ECDSA_P256_SHA256};
5356use serde_human_bytes as hex_bytes;
5457use serde_json:: Value ;
5558
59+
60+ async fn sign_cert_request (
61+ cert_client : & CertRequestClient ,
62+ key : & KeyPair ,
63+ config : CertConfigV2 ,
64+ ) -> Result < Vec < String > > {
65+ let pubkey = key. public_key_der ( ) ;
66+ let report_data = QuoteContentType :: RaTlsCert . to_report_data ( & pubkey) ;
67+ let attestation = Attestation :: quote ( & report_data)
68+ . context ( "Failed to get quote for cert pubkey" ) ?
69+ . into_versioned ( ) ;
70+ let csr = CertSigningRequestV2 {
71+ confirm : "please sign cert:" . to_string ( ) ,
72+ pubkey,
73+ config,
74+ attestation,
75+ } ;
76+ let signature = csr. signed_by ( key) . context ( "Failed to sign the CSR" ) ?;
77+ cert_client
78+ . sign_csr ( & csr, & signature)
79+ . await
80+ . context ( "Failed to sign the CSR" )
81+ }
82+
5683mod config_id_verifier;
5784
5885#[ derive( clap:: Parser ) ]
@@ -500,8 +527,7 @@ impl<'a> GatewayContext<'a> {
500527 not_before : None ,
501528 not_after : Some ( cert_not_after) ,
502529 } ;
503- let certs = cert_client
504- . request_cert ( & key, config, None )
530+ let certs = sign_cert_request ( & cert_client, & key, config)
505531 . await
506532 . context ( "Failed to request cert" ) ?;
507533 let client_cert = certs. join ( "\n " ) ;
@@ -520,8 +546,7 @@ impl<'a> GatewayContext<'a> {
520546 not_before : None ,
521547 not_after : Some ( cert_not_after) ,
522548 } ;
523- let certs_with_quote = cert_client
524- . request_cert ( & key, config_with_quote, None )
549+ let certs_with_quote = sign_cert_request ( & cert_client, & key, config_with_quote)
525550 . await
526551 . context ( "Failed to request cert with quote" ) ?;
527552 let client_cert_with_quote = certs_with_quote. join ( "\n " ) ;
0 commit comments