Skip to content

Commit bcf7d2e

Browse files
committed
Allow no client auth
1 parent 06aafe4 commit bcf7d2e

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/lib.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl ProxyServer {
204204
None, // context
205205
)?;
206206

207-
let input_data = compute_report_input(&cert_chain, exporter)?;
207+
let input_data = compute_report_input(Some(&cert_chain), exporter)?;
208208

209209
// Get the TLS certficate chain of the client, if there is one
210210
let remote_cert_chain = connection.peer_certificates().map(|c| c.to_owned());
@@ -234,10 +234,7 @@ impl ProxyServer {
234234

235235
// If we expect an attestaion from the client, verify it and get measurements
236236
let measurements = if attestation_verifier.has_remote_attestion() {
237-
let remote_input_data = compute_report_input(
238-
&remote_cert_chain.ok_or(ProxyError::NoClientAuth)?,
239-
exporter,
240-
)?;
237+
let remote_input_data = compute_report_input(remote_cert_chain.as_deref(), exporter)?;
241238

242239
attestation_verifier
243240
.verify_attestation(remote_attestation_message, remote_input_data)
@@ -620,7 +617,7 @@ impl ProxyClient {
620617
.ok_or(ProxyError::NoCertificate)?
621618
.to_owned();
622619

623-
let remote_input_data = compute_report_input(&remote_cert_chain, exporter)?;
620+
let remote_input_data = compute_report_input(Some(&remote_cert_chain), exporter)?;
624621

625622
// Read a length prefixed attestation from the proxy-server
626623
let mut length_bytes = [0; 4];
@@ -640,8 +637,7 @@ impl ProxyClient {
640637

641638
// If we are in a CVM, provide an attestation
642639
let attestation = if attestation_generator.attestation_type != AttestationType::None {
643-
let local_input_data =
644-
compute_report_input(&cert_chain.ok_or(ProxyError::NoClientAuth)?, exporter)?;
640+
let local_input_data = compute_report_input(cert_chain.as_deref(), exporter)?;
645641
attestation_generator
646642
.generate_attestation(local_input_data)
647643
.await?
@@ -731,7 +727,7 @@ async fn get_tls_cert_with_config(
731727

732728
let remote_attestation_message = AttestationExchangeMessage::decode(&mut &buf[..])?;
733729

734-
let remote_input_data = compute_report_input(&remote_cert_chain, exporter)?;
730+
let remote_input_data = compute_report_input(Some(&remote_cert_chain), exporter)?;
735731

736732
let _measurements = attestation_verifier
737733
.verify_attestation(remote_attestation_message, remote_input_data)
@@ -743,12 +739,14 @@ async fn get_tls_cert_with_config(
743739
/// Given a certificate chain and an exporter (session key material), build the quote input value
744740
/// SHA256(pki) || exporter
745741
pub fn compute_report_input(
746-
cert_chain: &[CertificateDer<'_>],
742+
cert_chain: Option<&[CertificateDer<'_>]>,
747743
exporter: [u8; 32],
748744
) -> Result<[u8; 64], AttestationError> {
749745
let mut quote_input = [0u8; 64];
750-
let pki_hash = get_pki_hash_from_certificate_chain(cert_chain)?;
751-
quote_input[..32].copy_from_slice(&pki_hash);
746+
if let Some(cert_chain) = cert_chain {
747+
let pki_hash = get_pki_hash_from_certificate_chain(cert_chain)?;
748+
quote_input[..32].copy_from_slice(&pki_hash);
749+
}
752750
quote_input[32..].copy_from_slice(&exporter);
753751
Ok(quote_input)
754752
}

0 commit comments

Comments
 (0)