Skip to content

Commit 14055ca

Browse files
committed
Merge main
2 parents ac43bb7 + 03b9f86 commit 14055ca

File tree

6 files changed

+393
-183
lines changed

6 files changed

+393
-183
lines changed

Cargo.lock

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "attested-tls-proxy"
33
version = "0.1.0"
44
edition = "2024"
5-
license = "MIT OR Apache-2.0"
5+
license = "MIT"
66

77
[dependencies]
88
tokio = { version = "1.48.0", features = ["full"] }
@@ -20,7 +20,7 @@ configfs-tsm = "0.0.2"
2020
rand_core = { version = "0.6.4", features = ["getrandom"] }
2121
dcap-qvl = "0.3.4"
2222
hex = "0.4.3"
23-
hyper = { version = "1.7.0", features = ["server"] }
23+
hyper = { version = "1.7.0", features = ["server", "http2"] }
2424
hyper-util = "0.1.17"
2525
http-body-util = "0.1.3"
2626
bytes = "1.10.1"
@@ -29,6 +29,7 @@ serde_json = "1.0.145"
2929
serde = "1.0.228"
3030
tracing = "0.1.41"
3131
tracing-subscriber = { version = "0.3.20", features = ["env-filter", "json"] }
32+
parity-scale-codec = "3.7.5"
3233

3334
[dev-dependencies]
3435
rcgen = "0.14.5"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

src/attestation/mod.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod measurements;
22

33
use measurements::{CvmImageMeasurements, MeasurementRecord, Measurements, PlatformMeasurements};
4+
use parity_scale_codec::{Decode, Encode};
45
use serde::{Deserialize, Serialize};
56
use std::{
67
fmt::{self, Display, Formatter},
@@ -22,13 +23,19 @@ use x509_parser::prelude::*;
2223
/// For fetching collateral directly from intel, if no PCCS is specified
2324
const PCS_URL: &str = "https://api.trustedservices.intel.com";
2425

25-
#[derive(Debug, Serialize, Deserialize)]
26+
/// This is the type sent over the channel to provide an attestation
27+
#[derive(Debug, Serialize, Deserialize, Encode, Decode)]
2628
pub struct AttesationPayload {
29+
/// What CVM platform is used (including none)
2730
pub attestation_type: AttestationType,
31+
/// The attestation evidence as bytes - in the case of DCAP this is a quote
2832
pub attestation: Vec<u8>,
2933
}
3034

3135
impl AttesationPayload {
36+
/// Given an attestation generator (quote generation function for a specific platform)
37+
/// return an attestation
38+
/// This also takes the certificate chain and exporter as they are given as input to the attestation
3239
pub fn from_attestation_generator(
3340
cert_chain: &[CertificateDer<'_>],
3441
exporter: [u8; 32],
@@ -39,6 +46,15 @@ impl AttesationPayload {
3946
attestation: attesation_generator.create_attestation(cert_chain, exporter)?,
4047
})
4148
}
49+
50+
/// Create an empty attestation payload for the case that we are running in a non-confidential
51+
/// environment
52+
pub fn without_attestation() -> Self {
53+
Self {
54+
attestation_type: AttestationType::None,
55+
attestation: Vec::new(),
56+
}
57+
}
4258
}
4359

4460
/// Type of attestaion used
@@ -73,6 +89,7 @@ impl AttestationType {
7389
}
7490
}
7591

92+
/// Get a quote generator for this type of platform
7693
pub fn get_quote_generator(&self) -> Result<Arc<dyn QuoteGenerator>, AttestationError> {
7794
match self {
7895
AttestationType::None => Ok(Arc::new(NoQuoteGenerator)),
@@ -85,6 +102,23 @@ impl AttestationType {
85102
}
86103
}
87104

105+
/// SCALE encode (used over the wire)
106+
impl Encode for AttestationType {
107+
fn encode(&self) -> Vec<u8> {
108+
self.as_str().encode()
109+
}
110+
}
111+
112+
/// SCALE decode
113+
impl Decode for AttestationType {
114+
fn decode<I: parity_scale_codec::Input>(
115+
input: &mut I,
116+
) -> Result<Self, parity_scale_codec::Error> {
117+
let s: String = String::decode(input)?;
118+
serde_json::from_str(&format!("\"{s}\"")).map_err(|_| "Failed to decode enum".into())
119+
}
120+
}
121+
88122
impl Display for AttestationType {
89123
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
90124
f.write_str(self.as_str())
@@ -104,9 +138,15 @@ pub trait QuoteGenerator: Send + Sync + 'static {
104138
) -> Result<Vec<u8>, AttestationError>;
105139
}
106140

141+
/// Allows remote attestations to be verified
107142
#[derive(Clone, Debug)]
108143
pub struct AttestationVerifier {
144+
/// The measurement values we accept
145+
///
146+
/// If this is empty, anything will be accepted - but measurements are always injected into HTTP
147+
/// headers, so that they can be verified upstream
109148
accepted_measurements: Vec<MeasurementRecord>,
149+
/// A PCCS service to use - defaults to Intel PCS
110150
pccs_url: Option<String>,
111151
}
112152

0 commit comments

Comments
 (0)