Skip to content

examples: add server_acceptor example.#1402

Merged
cpu merged 2 commits into
rustls:mainfrom
cpu:cpu-1361-acceptor-crl-eg
Aug 16, 2023
Merged

examples: add server_acceptor example.#1402
cpu merged 2 commits into
rustls:mainfrom
cpu:cpu-1361-acceptor-crl-eg

Conversation

@cpu

@cpu cpu commented Aug 16, 2023

Copy link
Copy Markdown
Member

Description

This branch resolves #1361 by adding an example of using the Acceptor API to provide up-to-date CRL information per-connection.

server: fix acceptor rustdoc typo.

Small typo fix.

examples: add server_acceptor example.

This example has two main purposes:

  1. It shows how to use the Acceptor API to customize a ServerConfig per-connection, possibly using information from the received ClientHello.
  2. It shows how to load CRL information per-connection to ensure the freshest CRL content is used when validating client certificate revocation status.

Additionally this example uses rcgen to generate its own test PKI (and CRLs), potentially being a helpful reference for folks that want to do similar without needing to manually construct certs with openssl.

To simulate CRL updates this example program spawns a background thread that periodically replaces the CRL content, flipping back and forth between a CRL that lists the client certificate as revoked, and a CRL that has no revoked certificates.

Using tlsclient-mio (or another TLS client program) with the generated client certificate/key you can observe the CRL updates happening by connecting to the server, waiting a little bit, and then connecting again. The result will differ based on the CRL update:

$ cargo run --bin tlsclient-mio -- \
  --auth-certs ./client-cert.pem \
  --auth-key ./client-key.pem \
  --cafile ca-cert.pem \
  --port 4443 \
  --http \
  localhost
TLS error: AlertReceived(CertificateRevoked)
Connection closed

<waiting>

$ cargo run --bin tlsclient-mio -- \
   --auth-certs ./client-cert.pem \
   --auth-key ./client-key.pem \
   --cafile ca-cert.pem \
   --port 4443 \
   --http \
   localhost
EOF
Connection closed

Comment thread Cargo.toml
Comment on lines +11 to +13
[patch.crates-io]
# TODO(XXX): Remove this once rcgen has cut a release w/ CRL support included. Only used in examples.
rcgen = { git = 'https://github.com/est31/rcgen.git' }

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth pinging the upstream to cut a release to avoid this.

I've been holding off on that only because I'm hoping to add support for the cert CRL distribution point and CRL issuing distribution point extensions first.

I might be able to find time to work on that ~today, but perhaps it shouldn't block a release either way?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be able to find time to work on that ~today, but perhaps it shouldn't block a release either way?

Depends on whether those changes would need to be semver-breaking.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be done w/o breaking semver for the cert CRL distrib point because the CertificateParams struct is non-exhaustive.

For the CRL issuing distribution point I think it will need to be breaking, I didn't mark the CertificateRevocationListParams struct as non-exhaustive (in retrospect, an oversight).

@cpu cpu force-pushed the cpu-1361-acceptor-crl-eg branch from 4f9d3a4 to 5644f3b Compare August 16, 2023 14:57
@codecov

codecov Bot commented Aug 16, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1402 (9107021) into main (9330cd7) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main    #1402   +/-   ##
=======================================
  Coverage   96.33%   96.33%           
=======================================
  Files          66       66           
  Lines       14860    14860           
=======================================
  Hits        14316    14316           
  Misses        544      544           
Files Changed Coverage Δ
rustls/src/server/server_conn.rs 87.41% <ø> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment thread examples/src/bin/server_acceptor.rs Outdated

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread examples/src/bin/server_acceptor.rs Outdated
This example has two main purposes:

1. It shows how to use the `Acceptor` API to customize a `ServerConfig`
   per-connection, possibly using information from the received
   `ClientHello`.
2. It shows how to load CRL information per-connection to ensure the
   freshest CRL content is used when validating client certificate
   revocation status.

Additionally this example uses `rcgen` to generate its own test PKI,
potentially being a helpful reference for folks that want to do similar
without needing to manually construct certs with `openssl`.

To simulate CRL updates this example program spawns a background thread
that periodically replaces the CRL content, flipping back and forth
between a CRL that lists the client certificate as revoked, and a CRL
that has no revoked certificates.

Using `tlsclient-mio` (or another TLS client program) with the generated
client certificate/key you can observe the CRL updates happening by
connecting to the server, waiting a little bit, and then connecting
again. The result will differ based on the CRL update:

```
$ cargo run --bin tlsclient-mio -- --auth-certs ./client-cert.pem --auth-key ./client-key.pem --cafile ca-cert.pem --port 4443 --http localhost
TLS error: AlertReceived(CertificateRevoked)
Connection closed

<waiting>

$ cargo run --bin tlsclient-mio -- --auth-certs ./client-cert.pem --auth-key ./client-key.pem --cafile ca-cert.pem --port 4443 --http localhost
EOF
Connection closed
```
@cpu cpu force-pushed the cpu-1361-acceptor-crl-eg branch from 5644f3b to 9107021 Compare August 16, 2023 15:36
@cpu cpu enabled auto-merge August 16, 2023 15:37
@cpu cpu disabled auto-merge August 16, 2023 15:39
@cpu cpu added this pull request to the merge queue Aug 16, 2023
Merged via the queue into rustls:main with commit 6bdaf04 Aug 16, 2023
@cpu cpu deleted the cpu-1361-acceptor-crl-eg branch August 16, 2023 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

doc: examples of how to use ClientCertVerifier impls with CRLs

3 participants