Skip to content

Commit 504823b

Browse files
committed
feat(tdx-attest): Rewrite TDX attestation in pure Rust
Replace the C-based tdx-attest-sys with a pure Rust implementation: - Implement TDX ioctl commands directly using libc - Support ConfigFS quote generation (Linux 6.7+) - Handle both glibc and musl ioctl request types - Remove dependency on vendored Linux kernel headers - Simplify API: get_quote now returns Result<Vec<u8>> This eliminates all C code from tdx-attest, making it easier to build for different libc targets (glibc, musl) without header compatibility issues. The implementation supports: - get_quote() via ConfigFS TSM interface - get_report() via /dev/tdx_guest ioctl - extend_rtmr() via /dev/tdx_guest ioctl - get_supported_att_key_ids() returns Intel TDQE UUID Note: VSock and TDVMCALL quote methods are not implemented as ConfigFS is the recommended approach for Linux 6.7+. They can be added later if needed for older kernel support.
1 parent 7f82973 commit 504823b

7 files changed

Lines changed: 393 additions & 295 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tdx-attest-sys/csrc/linux/ioctl.h

Lines changed: 0 additions & 66 deletions
This file was deleted.

tdx-attest-sys/csrc/linux/types.h

Lines changed: 0 additions & 32 deletions
This file was deleted.

tdx-attest-sys/csrc/linux/vm_sockets.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

tdx-attest/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ license.workspace = true
1313
[dependencies]
1414
anyhow.workspace = true
1515
hex.workspace = true
16-
num_enum.workspace = true
1716
scale.workspace = true
1817
serde.workspace = true
1918
serde-human-bytes.workspace = true
@@ -23,9 +22,9 @@ fs-err.workspace = true
2322
serde_json = { workspace = true, features = ["alloc"] }
2423
sha2.workspace = true
2524

26-
# Linux x86_64 with glibc or musl
25+
# Linux x86_64 - pure Rust implementation using libc for syscalls
2726
[target.'cfg(all(target_os = "linux", target_arch = "x86_64"))'.dependencies]
28-
tdx-attest-sys.workspace = true
27+
libc.workspace = true
2928

3029
[dev-dependencies]
3130
insta.workspace = true

tdx-attest/src/dummy.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5-
use cc_eventlog::TdxEventLog;
6-
use num_enum::FromPrimitive;
7-
use thiserror::Error;
5+
//! Dummy implementation for non-Linux/non-x86_64 platforms.
6+
//!
7+
//! All functions return `NotSupported` error.
88
9-
use crate::{TdxReport, TdxReportData, TdxUuid};
9+
use thiserror::Error;
1010

11-
type Result<T> = std::result::Result<T, TdxAttestError>;
11+
use crate::{Result, TdxReport, TdxReportData, TdxUuid};
1212

13-
#[repr(u32)]
14-
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromPrimitive, Error)]
13+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Error)]
1514
pub enum TdxAttestError {
16-
#[error("unexpected")]
15+
#[error("unexpected error")]
1716
Unexpected,
1817
#[error("invalid parameter")]
1918
InvalidParameter,
@@ -29,32 +28,28 @@ pub enum TdxAttestError {
2928
NotSupported,
3029
#[error("quote failure")]
3130
QuoteFailure,
32-
#[error("busy")]
31+
#[error("device busy")]
3332
Busy,
3433
#[error("device failure")]
3534
DeviceFailure,
36-
#[error("invalid rtmr index")]
35+
#[error("invalid RTMR index")]
3736
InvalidRtmrIndex,
38-
#[error("unsupported att key id")]
37+
#[error("unsupported attestation key ID")]
3938
UnsupportedAttKeyId,
40-
#[num_enum(catch_all)]
41-
#[error("unknown error ({0})")]
42-
UnknownError(u32),
4339
}
4440

45-
pub fn extend_rtmr(_index: u32, _event_type: u32, _digest: [u8; 48]) -> Result<()> {
41+
pub fn get_quote(_report_data: &TdxReportData) -> Result<Vec<u8>> {
4642
Err(TdxAttestError::NotSupported)
4743
}
44+
4845
pub fn get_report(_report_data: &TdxReportData) -> Result<TdxReport> {
4946
Err(TdxAttestError::NotSupported)
5047
}
51-
pub fn get_quote(
52-
_report_data: &TdxReportData,
53-
_att_key_id_list: Option<&[TdxUuid]>,
54-
) -> Result<(TdxUuid, Vec<u8>)> {
55-
let _ = _report_data;
48+
49+
pub fn extend_rtmr(_index: u32, _event_type: u32, _digest: [u8; 48]) -> Result<()> {
5650
Err(TdxAttestError::NotSupported)
5751
}
52+
5853
pub fn get_supported_att_key_ids() -> Result<Vec<TdxUuid>> {
5954
Err(TdxAttestError::NotSupported)
6055
}

0 commit comments

Comments
 (0)