Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

S390x verifier bak #2

Merged
merged 28 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
362c641
Verifier: Add IBM Secure Execution verifier driver framework
Mar 6, 2024
abdf68f
Verifier: IBM SE add generate_challenge_extra_params
Mar 6, 2024
2c44b6f
Verifier: IBM SE add dummy claims
Mar 11, 2024
ada0e75
Verifier: add IBM SE create verify dummy code
Mar 13, 2024
c0b4061
Verifier: IBM SE make both se and sample tee test pass
Mar 15, 2024
417404b
Verifier: IBM SE refine for get_evidence
Mar 22, 2024
05739da
Verifier: IBM SE update kbs-types
Mar 25, 2024
d89b2a3
Verifier: IBM SE change fn to generate_challenge and add tee_parameters
Apr 3, 2024
3a6b84e
Verifier: IBM SE add generate_challenge in grpc and rest
Apr 3, 2024
12667a9
Merge branch 'main' into s390x-verifier
Apr 18, 2024
c9d7bee
Verifier: IBM SE simplify the method
Apr 18, 2024
4fac842
Verifier: change fn name from generate_challenge to generate_suppleme…
Apr 18, 2024
cf50eab
Merge branch 'main' into s390x-verifier
Apr 19, 2024
e310e76
Merge branch 'main' into s390x-verifier fix fmt err
Apr 19, 2024
302186a
Verifier: IBM SE refine fake trait
Apr 19, 2024
d1adc60
Verifier: IBM SE use string but not Vec<u8> for tee_parameters
Apr 19, 2024
7133279
Verifier: IBM SE use String but not Option for tee_parameters
Apr 24, 2024
c9487ea
Verifier: IBM SE rollback kbs_protocol in tools client
Apr 24, 2024
708167d
Merge branch 'main' into s390x-verifier
Apr 25, 2024
1942546
Verifier: IBM SE implementation PoC
May 7, 2024
67ab6f5
Merge branch 'main' into s390x-verifier
May 28, 2024
ac54815
Merge branch 'main' into s390x-verifier fix
May 29, 2024
b67ad0c
Merge branch 'main' into s390x-verifier
May 29, 2024
7a82caf
Merge branch 'main' into s390x-verifier fix
May 29, 2024
1970d06
Verifier: IBM SE to fix review comments
May 30, 2024
70ecb61
Verifier: IBM SE to fix review comments
May 31, 2024
89c0d65
Verifier: IBM SE refactoring
Jun 3, 2024
48c2c81
kbs/attestation: support attestation service to generate Challenge
Xynnn007 Jun 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ clap = { version = "4", features = ["derive"] }
config = "0.13.3"
env_logger = "0.10.0"
hex = "0.4.3"
kbs-types = "0.5.3"
kbs-types = "0.6.0"
jsonwebtoken = { version = "9", default-features = false }
log = "0.4.17"
prost = "0.11.0"
regorus = { version = "0.1.5", default-features = false, features = ["regex", "base64", "time"] }
rstest = "0.18.1"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.89"
serde_with = { version = "1.11.0", features = ["base64"] }
serial_test = "0.9.0"
sha2 = "0.10"
shadow-rs = "0.19.0"
Expand All @@ -46,4 +47,4 @@ thiserror = "1.0"
tokio = { version = "1.23.0", features = ["full"] }
tempfile = "3.4.0"
tonic = "0.8.1"
tonic-build = "0.8.0"
tonic-build = "0.8.0"
3 changes: 3 additions & 0 deletions attestation-service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Today, the AS can validate evidence from the following TEEs:
- Hygon CSV
- Intel TDX with vTPM on Azure
- AMD SEV-SNP with vTPM on Azure
- IBM Secure Execution (SE)

# Overview
```
Expand Down Expand Up @@ -80,6 +81,7 @@ Please refer to the individual verifiers for the specific format of the evidence
- Azure TDX vTPM: [Evidence](./verifier/src/az_tdx_vtpm/mod.rs)
- Arm CCA: [CcaEvidence](./verifier/src/cca/mod.rs)
- Hygon CSV: [CsvEvidence](./verifier/src/csv/mod.rs)
- IBM Secure Execution (SE) [(SeEvidence)](./verifier/src/se/mod.rs)

## Output

Expand Down Expand Up @@ -132,6 +134,7 @@ Supported Verifier Drivers:
- `azsnpvtpm`: Verifier Driver for Azure vTPM based on SNP (Azure SNP vTPM)
- `cca`: Verifier Driver for Confidential Compute Architecture (Arm CCA).
- `csv`: Verifier Driver for China Security Virtualization (Hygon CSV).
- `se`: Verifier Driver for IBM Secure Execution (SE).

### Policy Engine

Expand Down
1 change: 1 addition & 0 deletions attestation-service/attestation-service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ az-tdx-vtpm-verifier = [ "verifier/az-tdx-vtpm-verifier" ]
snp-verifier = [ "verifier/snp-verifier" ]
csv-verifier = [ "verifier/csv-verifier" ]
cca-verifier = [ "verifier/cca-verifier" ]
se-verifier = [ "verifier/se-verifier" ]

# Only for testing and CI
rvps-builtin = [ "reference-value-provider-service" ]
Expand Down
39 changes: 38 additions & 1 deletion attestation-service/attestation-service/src/bin/grpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ use tonic::transport::Server;
use tonic::{Request, Response, Status};

use crate::as_api::attestation_service_server::{AttestationService, AttestationServiceServer};
use crate::as_api::{AttestationRequest, AttestationResponse, SetPolicyRequest, SetPolicyResponse};
use crate::as_api::{
AttestationRequest, AttestationResponse, ChallengeRequest, ChallengeResponse, SetPolicyRequest,
SetPolicyResponse,
};

use crate::rvps_api::reference_value_provider_service_server::{
ReferenceValueProviderService, ReferenceValueProviderServiceServer,
Expand All @@ -37,6 +40,7 @@ fn to_kbs_tee(tee: &str) -> anyhow::Result<Tee> {
"azsnpvtpm" => Tee::AzSnpVtpm,
"cca" => Tee::Cca,
"aztdxvtpm" => Tee::AzTdxVtpm,
"se" => Tee::Se,
other => bail!("Unsupported TEE type: {other}"),
};

Expand Down Expand Up @@ -195,6 +199,39 @@ impl AttestationService for Arc<RwLock<AttestationServer>> {
let res = AttestationResponse { attestation_token };
Ok(Response::new(res))
}

async fn get_attestation_challenge(
&self,
request: Request<ChallengeRequest>,
) -> Result<Response<ChallengeResponse>, Status> {
let request: ChallengeRequest = request.into_inner();
info!("get_attestation_challenge API called.");
debug!("get_attestation_challenge: {request:#?}");

let inner_tee = request
.inner
.get("tee")
.ok_or(Status::aborted("Error parse inner_tee tee"))?;
let tee_params = request
.inner
.get("tee_params")
.map_or(Err(Status::aborted("Error parse inner_tee tee_params")), Ok)?;
let tee = to_kbs_tee(&inner_tee)
.map_err(|e| Status::aborted(format!("Error parse TEE type: {e}")))?;

let attestation_challenge = self
.read()
.await
.attestation_service
.generate_supplemental_challenge(tee, tee_params.clone())
.await
.map_err(|e| Status::aborted(format!("Challenge: {e:?}")))?;

let res = ChallengeResponse {
attestation_challenge,
};
Ok(Response::new(res))
}
}

#[tonic::async_trait]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use strum::{AsRefStr, EnumString};
use thiserror::Error;
use tokio::sync::RwLock;

use crate::restful::{attestation, get_policies, set_policy};
use crate::restful::{attestation, get_challenge, get_policies, set_policy};

mod restful;

Expand Down Expand Up @@ -48,6 +48,9 @@ enum WebApi {

#[strum(serialize = "/policy")]
Policy,

#[strum(serialize = "/challenge")]
Challenge,
}

#[derive(Error, Debug)]
Expand Down Expand Up @@ -100,6 +103,7 @@ async fn main() -> Result<(), RestfulError> {
.route(web::post().to(set_policy))
.route(web::get().to(get_policies)),
)
.service(web::resource(WebApi::Challenge.as_ref()).route(web::post().to(get_challenge)))
.app_data(web::Data::clone(&attestation_service))
});

Expand Down
43 changes: 41 additions & 2 deletions attestation-service/attestation-service/src/bin/restful/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::Arc;
use std::{collections::HashMap, sync::Arc};

use actix_web::{body::BoxBody, web, HttpRequest, HttpResponse, ResponseError};
use anyhow::{bail, Context};
use anyhow::{anyhow, bail, Context};
use attestation_service::{AttestationService, HashAlgorithm};
use base64::{engine::general_purpose::URL_SAFE_NO_PAD, Engine};
use kbs_types::Tee;
Expand Down Expand Up @@ -44,6 +44,14 @@ pub struct AttestationRequest {
policy_ids: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ChallengeRequest {
// ChallengeRequest uses HashMap to pass variables like:
// tee, tee_params etc
#[serde(flatten)]
inner: HashMap<String, String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
enum Data {
Expand All @@ -62,6 +70,7 @@ fn to_tee(tee: &str) -> anyhow::Result<Tee> {
"csv" => Tee::Csv,
"sample" => Tee::Sample,
"aztdxvtpm" => Tee::AzTdxVtpm,
"se" => Tee::Se,
other => bail!("tee `{other} not supported`"),
};

Expand Down Expand Up @@ -179,6 +188,36 @@ pub async fn set_policy(
Ok(HttpResponse::Ok().body(""))
}

/// This handler uses json extractor
pub async fn get_challenge(
request: web::Json<ChallengeRequest>,
cocoas: web::Data<Arc<RwLock<AttestationService>>>,
) -> Result<HttpResponse> {
info!("get_challenge API called.");
let request: ChallengeRequest = request.into_inner();

debug!("get_challenge: {request:#?}");
let inner_tee = request
.inner
.get("tee")
.as_ref()
.map(|s| s.as_str())
.ok_or(anyhow!("Failed to get inner tee"))?;
let tee_params = request
.inner
.get("tee_params")
.ok_or(anyhow!("Failed to get inner tee_params"))?;

let tee = to_tee(inner_tee)?;
let challenge = cocoas
.read()
.await
.generate_supplemental_challenge(tee, tee_params.to_string())
.await
.context("generate challenge")?;
Ok(HttpResponse::Ok().body(challenge))
}

/// GET /policy
/// GET /policy/{policy_id}
///
Expand Down
11 changes: 11 additions & 0 deletions attestation-service/attestation-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ impl AttestationService {
pub async fn register_reference_value(&mut self, message: &str) -> Result<()> {
self.rvps.verify_and_extract(message).await
}

pub async fn generate_supplemental_challenge(
&self,
tee: Tee,
tee_parameters: String,
) -> Result<String> {
let verifier = verifier::to_verifier(&tee)?;
verifier
.generate_supplemental_challenge(tee_parameters)
.await
}
}

/// Get the expected init/runtime data and potential claims due to the given input
Expand Down
Loading
Loading