From 3b28c8aab65fbcefacd22a7d1bc6ce6c6f96a54c Mon Sep 17 00:00:00 2001 From: Xynnn007 Date: Sun, 7 Apr 2024 12:56:17 +0800 Subject: [PATCH] AA: add built-in plugin information in --help Signed-off-by: Xynnn007 --- .../attestation-agent/Cargo.toml | 12 +++--- attestation-agent/attestation-agent/build.rs | 41 +++++++++++++++++++ .../attestation-agent/src/bin/grpc-aa/main.rs | 4 +- .../src/bin/ttrpc-aa/main.rs | 4 +- 4 files changed, 53 insertions(+), 8 deletions(-) diff --git a/attestation-agent/attestation-agent/Cargo.toml b/attestation-agent/attestation-agent/Cargo.toml index b37463959..2e0e8f5da 100644 --- a/attestation-agent/attestation-agent/Cargo.toml +++ b/attestation-agent/attestation-agent/Cargo.toml @@ -55,12 +55,12 @@ kbs = ["kbs_protocol/background_check", "token"] # CoCoAS Attestation Token coco_as = ["reqwest", "token"] -all-attesters = ["kbs_protocol?/all-attesters", "attester/all-attesters"] -tdx-attester = ["kbs_protocol/tdx-attester", "attester/tdx-attester"] -sgx-attester = ["kbs_protocol/sgx-attester", "attester/sgx-attester"] -az-snp-vtpm-attester = ["kbs_protocol/az-snp-vtpm-attester", "attester/az-snp-vtpm-attester"] -az-tdx-vtpm-attester = ["kbs_protocol/az-tdx-vtpm-attester", "attester/az-tdx-vtpm-attester"] -snp-attester = ["kbs_protocol/snp-attester", "attester/snp-attester"] +all-attesters = ["tdx-attester", "sgx-attester", "az-snp-vtpm-attester", "az-tdx-vtpm-attester", "snp-attester"] +tdx-attester = ["kbs_protocol?/tdx-attester", "attester/tdx-attester"] +sgx-attester = ["kbs_protocol?/sgx-attester", "attester/sgx-attester"] +az-snp-vtpm-attester = ["kbs_protocol?/az-snp-vtpm-attester", "attester/az-snp-vtpm-attester"] +az-tdx-vtpm-attester = ["kbs_protocol?/az-tdx-vtpm-attester", "attester/az-tdx-vtpm-attester"] +snp-attester = ["kbs_protocol?/snp-attester", "attester/snp-attester"] # Either `rust-crypto` or `openssl` should be enabled to work as underlying crypto module rust-crypto = ["kbs_protocol?/rust-crypto"] diff --git a/attestation-agent/attestation-agent/build.rs b/attestation-agent/attestation-agent/build.rs index d48bc81c1..39bf9a983 100644 --- a/attestation-agent/attestation-agent/build.rs +++ b/attestation-agent/attestation-agent/build.rs @@ -34,5 +34,46 @@ fn main() -> std::io::Result<()> { .expect("Generate ttrpc protocol code failed."); } + #[cfg(feature = "bin")] + { + use std::env; + use std::fs::File; + use std::io::Write; + use std::path::Path; + + // generate an `intro` file that includes the feature information of the build + fn feature_list(features: Vec<&str>) -> String { + let enabled_features: Vec<&str> = features + .into_iter() + .filter(|&feature| env::var(format!("CARGO_FEATURE_{}", feature)).is_ok()) + .collect(); + + enabled_features.join(", ") + } + + let token_plugins = feature_list(vec!["KBS", "COCO_AS"]); + let attester = feature_list(vec![ + "TDX_ATTESTER", + "SGX_ATTESTER", + "AZ_SNP_VTPM_ATTESTER", + "AZ_TDX_VTPM_ATTESTER", + "SNP_ATTESTER", + ]); + + let out_dir = env::var("OUT_DIR").unwrap(); + let dest_path = Path::new(&out_dir).join("intro"); + let mut f = File::create(&dest_path).unwrap(); + + writeln!( + f, + "Attestation Agent (AA for short) is a service function set for attestation procedure in Confidential Containers. It provides kinds of service APIs related to attestation.\n\n", + ) + .unwrap(); + + writeln!(f, "Supported Attesters: {}", attester).unwrap(); + + writeln!(f, "Token plugins: {}", token_plugins).unwrap(); + } + Ok(()) } diff --git a/attestation-agent/attestation-agent/src/bin/grpc-aa/main.rs b/attestation-agent/attestation-agent/src/bin/grpc-aa/main.rs index 0c8bcc14a..f2fa0dfee 100644 --- a/attestation-agent/attestation-agent/src/bin/grpc-aa/main.rs +++ b/attestation-agent/attestation-agent/src/bin/grpc-aa/main.rs @@ -14,8 +14,10 @@ use std::net::SocketAddr; const DEFAULT_ATTESTATION_AGENT_ADDR: &str = "127.0.0.1:50002"; +const ABOUT: &str = include_str!(concat!(env!("OUT_DIR"), "/intro")); + #[derive(Debug, Parser)] -#[command(author, version, about, long_about = None)] +#[command(author, version, about, long_about = Some(ABOUT))] struct Cli { /// Attestation gRPC Unix socket addr. /// diff --git a/attestation-agent/attestation-agent/src/bin/ttrpc-aa/main.rs b/attestation-agent/attestation-agent/src/bin/ttrpc-aa/main.rs index 719bdde4d..8e119e488 100644 --- a/attestation-agent/attestation-agent/src/bin/ttrpc-aa/main.rs +++ b/attestation-agent/attestation-agent/src/bin/ttrpc-aa/main.rs @@ -22,8 +22,10 @@ const DEFAULT_ATTESTATION_SOCKET_ADDR: &str = concatcp!( "attestation-agent.sock" ); +const ABOUT: &str = include_str!(concat!(env!("OUT_DIR"), "/intro")); + #[derive(Debug, Parser)] -#[command(author, version, about, long_about = None)] +#[command(author, version, about, long_about = Some(ABOUT))] struct Cli { /// Attestation ttRPC Unix socket addr. ///