Skip to content

Commit a91288a

Browse files
committed
Doccomments
1 parent 809fe09 commit a91288a

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/attestation.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@ use x509_parser::prelude::*;
55

66
/// Represents a CVM technology with quote generation and verification
77
pub trait AttestationPlatform: Clone + Send + 'static {
8+
/// Whether this is CVM attestation. This should always return true except for the [NoAttestation] case.
9+
///
10+
/// When false, allows TLS client to be configured without client authentication
811
fn is_cvm(&self) -> bool;
912

13+
/// Generate an attestation
1014
fn create_attestation(
1115
&self,
1216
cert_chain: &[CertificateDer<'_>],
1317
exporter: [u8; 32],
1418
) -> Result<Vec<u8>, AttestationError>;
1519

20+
/// Verify the given attestation payload
1621
fn verify_attestation(
1722
&self,
1823
input: Vec<u8>,
@@ -71,7 +76,7 @@ impl AttestationPlatform for NoAttestation {
7176
false
7277
}
7378

74-
/// Mocks creating an attestation
79+
/// Create an empty attestation
7580
fn create_attestation(
7681
&self,
7782
_cert_chain: &[CertificateDer<'_>],
@@ -80,7 +85,7 @@ impl AttestationPlatform for NoAttestation {
8085
Ok(Vec::new())
8186
}
8287

83-
/// Mocks verifying an attestation
88+
/// Ensure that an empty attestation is given
8489
fn verify_attestation(
8590
&self,
8691
input: Vec<u8>,

src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ impl<L: AttestationPlatform, R: AttestationPlatform> ProxyClient<L, R> {
266266
.await
267267
}
268268

269+
/// Create a new proxy with given TLS configuration
270+
///
271+
/// This is private as it allows dangerous configuration but is used in tests
269272
async fn new_with_tls_config(
270273
client_config: Arc<ClientConfig>,
271274
local: impl ToSocketAddrs,
@@ -293,6 +296,7 @@ impl<L: AttestationPlatform, R: AttestationPlatform> ProxyClient<L, R> {
293296
})
294297
}
295298

299+
/// Accept an incoming connection and handle it
296300
pub async fn accept(&self) -> io::Result<()> {
297301
let (inbound, _client_addr) = self.inner.listener.accept().await?;
298302

@@ -322,10 +326,12 @@ impl<L: AttestationPlatform, R: AttestationPlatform> ProxyClient<L, R> {
322326
Ok(())
323327
}
324328

329+
/// Helper to return the local socket address from the underlying TCP listener
325330
pub fn local_addr(&self) -> std::io::Result<SocketAddr> {
326331
self.inner.listener.local_addr()
327332
}
328333

334+
/// Handle an incoming connection
329335
async fn handle_connection(
330336
inbound: TcpStream,
331337
connector: TlsConnector,
@@ -386,6 +392,7 @@ impl<L: AttestationPlatform, R: AttestationPlatform> ProxyClient<L, R> {
386392
}
387393
}
388394

395+
/// An error when running a proxy client or server
389396
#[derive(Error, Debug)]
390397
pub enum ProxyError {
391398
#[error("Client auth is required when the client is running in a CVM")]
@@ -404,6 +411,7 @@ pub enum ProxyError {
404411
IntConversion(#[from] TryFromIntError),
405412
}
406413

414+
/// Given a byte array, encode its length as a 4 byte big endian u32
407415
fn length_prefix(input: &[u8]) -> [u8; 4] {
408416
let len = input.len() as u32;
409417
len.to_be_bytes()

src/main.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ struct Cli {
1919
enum CliCommand {
2020
/// Run a proxy client
2121
Client {
22+
/// The socket address of the proxy server
2223
#[arg(short, long)]
2324
server_address: SocketAddr,
25+
/// The domain name of the proxy server
2426
#[arg(long)]
2527
server_name: String,
2628
/// The path to a PEM encoded private key for client authentication
@@ -41,6 +43,8 @@ enum CliCommand {
4143
/// The path to a PEM encoded certificate chain
4244
#[arg(long)]
4345
cert_chain: PathBuf,
46+
/// Whether to use client authentication. If the client is running in a CVM this must be
47+
/// enabled.
4448
#[arg(long)]
4549
client_auth: bool,
4650
},
@@ -115,6 +119,7 @@ async fn main() -> anyhow::Result<()> {
115119
}
116120
}
117121

122+
/// Load TLS details from storage
118123
fn load_tls_cert_and_key(
119124
cert_chain: PathBuf,
120125
private_key: PathBuf,

0 commit comments

Comments
 (0)