Skip to content

Commit 154a2c7

Browse files
committed
cvm: Add mr-kms to RTMR3
1 parent 138e11c commit 154a2c7

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

kms/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async fn run_onboard_service(kms_config: KmsConfig, figment: Figment) -> Result<
4949
}
5050

5151
if !kms_config.onboard.auto_bootstrap_domain.is_empty() {
52-
onboard_service::bootstrap_keys(&kms_config)?;
52+
onboard_service::bootstrap_keys(&kms_config).await?;
5353
return Ok(());
5454
}
5555

kms/src/onboard_service.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ impl RpcCall<OnboardState> for OnboardHandler {
4444

4545
impl OnboardRpc for OnboardHandler {
4646
async fn bootstrap(self, request: BootstrapRequest) -> Result<BootstrapResponse> {
47-
let keys = Keys::generate(&request.domain).context("Failed to generate keys")?;
47+
let quote_enabled = self.state.config.onboard.quote_enabled;
48+
let keys = Keys::generate(&request.domain, quote_enabled)
49+
.await
50+
.context("Failed to generate keys")?;
4851

4952
let k256_pubkey = keys.k256_key.verifying_key().to_sec1_bytes().to_vec();
5053
let ca_pubkey = keys.ca_key.public_key_der();
5154
let quote;
5255
let eventlog;
53-
if self.state.config.onboard.quote_enabled {
56+
if quote_enabled {
5457
(quote, eventlog) = quote_keys(&ca_pubkey, &k256_pubkey).await?;
5558
} else {
5659
quote = vec![];
@@ -99,20 +102,21 @@ struct Keys {
99102
}
100103

101104
impl Keys {
102-
fn generate(domain: &str) -> Result<Self> {
105+
async fn generate(domain: &str, quote_enabled: bool) -> Result<Self> {
103106
let tmp_ca_key = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256)?;
104107
let ca_key = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256)?;
105108
let rpc_key = KeyPair::generate_for(&PKCS_ECDSA_P256_SHA256)?;
106109
let k256_key = SigningKey::random(&mut rand::rngs::OsRng);
107-
Self::from_keys(tmp_ca_key, ca_key, rpc_key, k256_key, domain)
110+
Self::from_keys(tmp_ca_key, ca_key, rpc_key, k256_key, domain, quote_enabled).await
108111
}
109112

110-
fn from_keys(
113+
async fn from_keys(
111114
tmp_ca_key: KeyPair,
112115
ca_key: KeyPair,
113116
rpc_key: KeyPair,
114117
k256_key: SigningKey,
115118
domain: &str,
119+
quote_enabled: bool,
116120
) -> Result<Self> {
117121
let tmp_ca_cert = CertRequest::builder()
118122
.org_name("Dstack")
@@ -131,11 +135,26 @@ impl Keys {
131135
.build()
132136
.self_signed()?;
133137

138+
let mut quote = None;
139+
let mut event_log = None;
140+
141+
if quote_enabled {
142+
let pubkey = rpc_key.public_key_der();
143+
let report_data = QuoteContentType::RaTlsCert.to_report_data(&pubkey);
144+
let resposne = tapp_quote(report_data.to_vec())
145+
.await
146+
.context("Failed to get quote")?;
147+
quote = Some(resposne.quote);
148+
event_log = Some(resposne.event_log.into_bytes());
149+
};
150+
134151
// Sign WWW server cert with KMS cert
135152
let rpc_cert = CertRequest::builder()
136153
.subject(domain)
137154
.alt_names(&[domain.to_string()])
138155
.special_usage("kms:rpc")
156+
.maybe_quote(quote.as_deref())
157+
.maybe_event_log(event_log.as_deref())
139158
.key(&rpc_key)
140159
.build()
141160
.signed_by(&ca_cert, &ca_key)?;
@@ -177,7 +196,15 @@ impl Keys {
177196
KeyPair::from_pem(&tmp_ca_key_pem).context("Failed to parse tmp CA key")?;
178197
let ecdsa_key =
179198
SigningKey::from_slice(&root_k256_key).context("Failed to parse ECDSA key")?;
180-
Self::from_keys(tmp_ca_key, ca_key, rpc_key, ecdsa_key, domain)
199+
Self::from_keys(
200+
tmp_ca_key,
201+
ca_key,
202+
rpc_key,
203+
ecdsa_key,
204+
domain,
205+
quote_enabled,
206+
)
207+
.await
181208
}
182209

183210
fn store(&self, cfg: &KmsConfig) -> Result<()> {
@@ -200,9 +227,13 @@ impl Keys {
200227
}
201228
}
202229

203-
pub(crate) fn bootstrap_keys(cfg: &KmsConfig) -> Result<()> {
204-
let keys =
205-
Keys::generate(&cfg.onboard.auto_bootstrap_domain).context("Failed to generate keys")?;
230+
pub(crate) async fn bootstrap_keys(cfg: &KmsConfig) -> Result<()> {
231+
let keys = Keys::generate(
232+
&cfg.onboard.auto_bootstrap_domain,
233+
cfg.onboard.quote_enabled,
234+
)
235+
.await
236+
.context("Failed to generate keys")?;
206237
keys.store(cfg)?;
207238
Ok(())
208239
}

tdxctl/src/fde_setup.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,13 @@ impl SetupFdeArgs {
253253
if usage != "kms:rpc" {
254254
bail!("Invalid server cert usage: {usage}");
255255
}
256+
if let Some(att) = &cert.attestation {
257+
let kms_info = att
258+
.decode_app_info(false)
259+
.context("Failed to decode app_info")?;
260+
extend_rtmr3("mr-kms", &kms_info.mr_aggregated)
261+
.context("Failed to extend mr-kms to RTMR3")?;
262+
}
256263
Ok(())
257264
}))
258265
.build()

0 commit comments

Comments
 (0)