Skip to content

Commit 5d624f5

Browse files
committed
add prefer-post-quantum feature flag
When explicitly activated (it is not a default) this feature flag activates the matching upstream `rustls/prefer-post-quantum` feature flag, making the `aws-lc-rs` crypto provider prefer `X25519MLKEM768`. CI coverage for this build configuration is added to `test.yaml`, and a new daily test targetting the cloudflare PQ demo server is added to `daily-tests.yml`.
1 parent b6eb372 commit 5d624f5

File tree

6 files changed

+121
-4
lines changed

6 files changed

+121
-4
lines changed

.github/workflows/daily-tests.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,61 @@ jobs:
130130
shell: bash
131131
run: |
132132
grep 'sni=encrypted' ech-test.log
133+
134+
prefer-pq:
135+
name: "Post-quantum (${{ matrix.os }})"
136+
runs-on: ${{ matrix.os }}
137+
strategy:
138+
matrix:
139+
os: [ ubuntu-latest, macos-latest, windows-latest ]
140+
141+
steps:
142+
- name: Checkout sources
143+
uses: actions/checkout@v4
144+
with:
145+
persist-credentials: false
146+
147+
- name: Install nightly toolchain
148+
uses: dtolnay/rust-toolchain@nightly
149+
150+
- name: Install cargo-c (Ubuntu)
151+
if: matrix.os == 'ubuntu-latest'
152+
env:
153+
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
154+
CARGO_C_FILE: cargo-c-x86_64-unknown-linux-musl.tar.gz
155+
run: |
156+
curl -L $LINK/$CARGO_C_FILE | tar xz -C ~/.cargo/bin
157+
- name: Install cargo-c (macOS)
158+
if: matrix.os == 'macos-latest'
159+
env:
160+
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
161+
CARGO_C_FILE: cargo-c-macos.zip
162+
run: |
163+
curl -L $LINK/$CARGO_C_FILE -o cargo-c-macos.zip
164+
unzip cargo-c-macos.zip -d ~/.cargo/bin
165+
- name: Install cargo-c (Windows)
166+
if: matrix.os == 'windows-latest'
167+
env:
168+
LINK: https://github.com/lu-zero/cargo-c/releases/latest/download
169+
CARGO_C_FILE: cargo-c-windows-msvc.zip
170+
run: |
171+
curl -L "$env:LINK/$env:CARGO_C_FILE" -o cargo-c-windows-msvc.zip
172+
powershell -Command "Expand-Archive -Path cargo-c-windows-msvc.zip -DestinationPath $env:USERPROFILE\\.cargo\\bin -Force"
173+
- name: Setup cmake build
174+
run: |
175+
cmake ${{
176+
matrix.os != 'windows-latest' && '-DCMAKE_BUILD_TYPE=Release -DPREFER_POST_QUANTUM=on\' || '-DPREFER_POST_QUANTUM=on'
177+
}} ${{
178+
matrix.os == 'macos-latest' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || ''
179+
}} -S librustls -B build
180+
- name: Run PQ connect test
181+
# NOTE: uses bash as the shell to allow for easy no-powershell tee/grep pipeline.
182+
shell: bash
183+
run: |
184+
cmake --build build --target prefer-pq-test ${{
185+
matrix.os == 'windows-latest' && '--config Release' || ''
186+
}} | tee pq-test.log
187+
- name: Verify PQ status
188+
shell: bash
189+
run: |
190+
grep 'kex=X25519MLKEM768' pq-test.log

.github/workflows/test.yaml

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ on:
1212

1313
jobs:
1414
build:
15-
name: "Build+Test (${{ matrix.os }}, ${{ matrix.cc }}, ${{ matrix.rust }}, ${{ matrix.crypto }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }}${{ matrix.dyn_link == 'on' && ', dynamic linking' || '' }})"
15+
name: "Build+Test (${{ matrix.os }}, ${{ matrix.cc }}, ${{ matrix.rust }}, ${{ matrix.crypto }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }}${{ matrix.prefer-pq == 'on' && ', prefer-post-quantum' || '' }}${{ matrix.dyn_link == 'on' && ', dynamic linking' || '' }})"
1616
runs-on: ${{ matrix.os }}
1717
strategy:
1818
matrix:
@@ -42,6 +42,12 @@ jobs:
4242
crypto: aws-lc-rs
4343
rust: stable
4444
cert_compression: on
45+
# Linux prefer-pq build
46+
- os: ubuntu-latest
47+
cc: clang
48+
crypto: aws-lc-rs
49+
rust: stable
50+
prefer-pq: on
4551
# MacOS standard build
4652
- os: macos-latest
4753
cc: clang
@@ -60,6 +66,12 @@ jobs:
6066
crypto: aws-lc-rs
6167
rust: stable
6268
cert_compression: on
69+
# MacOS prefer-pq build
70+
- os: macos-latest
71+
cc: clang
72+
crypto: aws-lc-rs
73+
rust: stable
74+
prefer-pq: on
6375
steps:
6476
- name: Checkout sources
6577
uses: actions/checkout@v4
@@ -97,6 +109,7 @@ jobs:
97109
cmake \
98110
-DCRYPTO_PROVIDER=${{matrix.crypto}} \
99111
-DCERT_COMPRESSION=${{matrix.cert_compression}} \
112+
-DPREFER_POST_QUANTUM=${{matrix.prefer-pq}} \
100113
-DDYN_LINK=${{matrix.dyn_link}} \
101114
-DCMAKE_BUILD_TYPE=Debug \
102115
${{ matrix.os == 'macos-latest' && '-DCMAKE_OSX_DEPLOYMENT_TARGET=14.5' || '' }} \
@@ -117,7 +130,7 @@ jobs:
117130
- name: Build release binaries
118131
run: |
119132
cmake --build build -- clean
120-
CC=${{matrix.cc}} CXX=${{matrix.cc}} cmake -S librustls -B build -DCRYPTO_PROVIDER=${{matrix.crypto}} -DCMAKE_BUILD_TYPE=Release
133+
CC=${{matrix.cc}} CXX=${{matrix.cc}} cmake -S librustls -B build -DCRYPTO_PROVIDER=${{matrix.crypto}} -DPREFER_POST_QUANTUM=${{matrix.prefer-pq}} -DCMAKE_BUILD_TYPE=Release
121134
cmake --build build
122135
123136
- name: Verify release builds were not using ASAN
@@ -189,7 +202,7 @@ jobs:
189202
run: cmake --build build --target integration-test
190203

191204
test-windows:
192-
name: "Windows (${{ matrix.crypto }}, ${{ matrix.config }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }}${{ matrix.dyn_link == 'on' && ', dynamic linking' || '' }})"
205+
name: "Windows (${{ matrix.crypto }}, ${{ matrix.config }}${{ matrix.cert_compression == 'on' && ', cert compression' || '' }}${{ matrix.prefer-pq == 'on' && ', prefer-post-quantum' || '' }}${{ matrix.dyn_link == 'on' && ', dynamic linking' || '' }})"
193206
runs-on: windows-latest
194207
strategy:
195208
matrix:
@@ -206,6 +219,10 @@ jobs:
206219
- crypto: aws-lc-rs
207220
config: Release
208221
cert_compression: on
222+
# One build with prefer-pq.
223+
- crypto: aws-lc-rs
224+
config: Release
225+
prefer-pq: on
209226
steps:
210227
- uses: actions/checkout@v4
211228
with:
@@ -233,7 +250,7 @@ jobs:
233250
powershell -Command "Expand-Archive -Path cargo-c-windows-msvc.zip -DestinationPath $env:USERPROFILE\\.cargo\\bin -Force"
234251
235252
- name: Configure CMake
236-
run: cmake -DCRYPTO_PROVIDER="${{ matrix.crypto }}" -DCERT_COMPRESSION="${{ matrix.cert_compression }}" -DDYN_LINK="${{ matrix.dyn_link }}" -S librustls -B build
253+
run: cmake -DCRYPTO_PROVIDER="${{ matrix.crypto }}" -DCERT_COMPRESSION="${{ matrix.cert_compression }}" -DPREFER_POST_QUANTUM="${{ matrix.prefer-pq }}" -DDYN_LINK="${{ matrix.dyn_link }}" -S librustls -B build
237254

238255
- name: Build
239256
run: cmake --build build --config "${{ matrix.config }}"

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,17 @@ platforms see the upstream documentation:
9898
[`*ring*`]: https://crates.io/crates/ring
9999
[`*ring*` supported platforms]: https://github.com/briansmith/ring/blob/2e8363b433fa3b3962c877d9ed2e9145612f3160/include/ring-core/target.h#L18-L64
100100

101+
#### Post-Quantum X25519MLKEM768 Key Exchange
102+
103+
Post-quantum-secure key exchange using [X25519MLKEM768][] is supported when using the `aws-lc-rs`
104+
cryptography provider. At this time default support places `X25519MLKEM768` at a lower negotiation priority.
105+
106+
By enabling the `prefer-post-quantum` feature flag the `X25519MLKEM768` key exchange will be used as the most
107+
preferred key exchange algorithm. We expect to add this feature to the crate's default features in a future
108+
release.
109+
110+
[X25519MLKEM768]: https://datatracker.ietf.org/doc/draft-kwiatkowski-tls-ecdhe-mlkem
111+
101112
#### Certificate Compression
102113

103114
You can optionally enable [RFC 8879](https://www.rfc-editor.org/rfc/rfc8879)

librustls/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ ring = ["rustls/ring", "webpki/ring"]
2525
aws-lc-rs = ["rustls/aws-lc-rs", "webpki/aws_lc_rs"]
2626
cert_compression = ["rustls/brotli", "rustls/zlib"]
2727
fips = ["aws-lc-rs", "rustls/fips"]
28+
prefer-post-quantum = ["aws-lc-rs", "rustls/prefer-post-quantum"]
2829

2930
[dependencies]
3031
# Keep in sync with RUSTLS_CRATE_VERSION in build.rs

librustls/cmake/options.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ option(
2020

2121
option(FIPS "Whether to enable aws-lc-rs and FIPS support")
2222

23+
option(
24+
PREFER_POST_QUANTUM
25+
"Whether to enable aws-lc-rs and prefer post-quantum key exchange support"
26+
)
27+
2328
option(DYN_LINK "Use dynamic linking for rustls library" OFF)
2429

2530
if(DYN_LINK AND FIPS AND (APPLE OR WIN32))
@@ -45,6 +50,10 @@ if(FIPS)
4550
list(APPEND CARGO_FEATURES --features=fips)
4651
endif()
4752

53+
if(PREFER_POST_QUANTUM)
54+
list(APPEND CARGO_FEATURES --features=prefer-post-quantum)
55+
endif()
56+
4857
# By default w/ Makefile or Ninja generators (e.g. Linux/MacOS CLI)
4958
# the `CMAKE_BUILD_TYPE` is "" when using the C/C++ project tooling.
5059
#

librustls/cmake/rust.cmake

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,24 @@ add_custom_command(
9898
$<TARGET_FILE:client> cloudflare-ech.com 443 /cdn-cgi/trace
9999
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
100100
)
101+
102+
add_custom_target(prefer-pq-test DEPENDS client)
103+
104+
if(WIN32 AND DYN_LINK)
105+
add_custom_command(
106+
TARGET prefer-pq-test
107+
PRE_BUILD
108+
COMMAND
109+
${CMAKE_COMMAND} -E copy "${CMAKE_BINARY_DIR}/rust/bin/rustls.dll"
110+
"${CMAKE_BINARY_DIR}\\tests\\$<CONFIG>\\"
111+
)
112+
endif()
113+
114+
add_custom_command(
115+
TARGET prefer-pq-test
116+
POST_BUILD
117+
COMMAND
118+
${CMAKE_COMMAND} -E env RUSTLS_PLATFORM_VERIFIER=1 $<TARGET_FILE:client>
119+
pq.cloudflareresearch.com 443 /cdn-cgi/trace
120+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
121+
)

0 commit comments

Comments
 (0)