Skip to content

Commit 75fd188

Browse files
committed
add opt-in FIPS feature, CI coverage
Using `make FIPS=true` with the Makefiles, or `cmake -DFIPS="true" -S . -B build` with the Windows cmake build will activate the `aws-lc-rs` feature of `rustls-ffi`, and the `rustls/fips` feature of Rustls. On MacOS and Windows this requires some additional build tooling (Golang and Ninja). See the rustls manual[0] and the aws-lc-rs-fips-sys crate[1] for more information. Note presently the Mac and Windows FIPS-enabled builds fail with unresolved symbol errors when building the client/server examples. A fix is TBD. [0]: https://docs.rs/rustls/latest/rustls/manual/_06_fips/index.html [1]: https://crates.io/crates/aws-lc-fips-sys
1 parent 217d833 commit 75fd188

File tree

7 files changed

+95
-2
lines changed

7 files changed

+95
-2
lines changed

.github/workflows/test.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,32 @@ jobs:
9999
- name: Integration tests
100100
run: make PROFILE=debug CERT_COMPRESSION=true integration
101101

102+
fips:
103+
name: FIPS
104+
runs-on: "${{ matrix.os }}"
105+
continue-on-error: true # TODO(@cpu): remove this after debugging MacOS failures.
106+
strategy:
107+
matrix:
108+
os: [ ubuntu-latest, macos-latest ]
109+
steps:
110+
- uses: actions/checkout@v4
111+
with:
112+
persist-credentials: false
113+
- uses: actions/checkout@v4
114+
with:
115+
persist-credentials: false
116+
- name: Install golang for aws-lc-fips-sys on macos
117+
if: runner.os == 'MacOS'
118+
uses: actions/setup-go@v5
119+
with:
120+
go-version: "1.22.2"
121+
- name: Install nightly rust toolchain
122+
uses: dtolnay/rust-toolchain@nightly
123+
- name: Unit tests
124+
run: make FIPS=true test
125+
- name: Integration tests
126+
run: make FIPS=true integration
127+
102128
test-windows-cmake-debug:
103129
name: Windows CMake, Debug configuration
104130
runs-on: windows-latest
@@ -168,6 +194,31 @@ jobs:
168194
CLIENT_BINARY: D:\a\rustls-ffi\rustls-ffi\build\tests\Release\client.exe
169195
SERVER_BINARY: D:\a\rustls-ffi\rustls-ffi\build\tests\Release\server.exe
170196

197+
test-windows-cmake-fips:
198+
name: Windows CMake, FIPS
199+
runs-on: windows-latest
200+
env:
201+
AWS_LC_SYS_PREBUILT_NASM: 1
202+
steps:
203+
- uses: actions/checkout@v4
204+
with:
205+
persist-credentials: false
206+
- name: Install nightly rust toolchain
207+
uses: dtolnay/rust-toolchain@nightly
208+
- name: Install NASM for aws-lc-rs
209+
uses: ilammy/setup-nasm@v1
210+
- name: Install ninja-build tool for aws-lc-fips-sys on Windows
211+
uses: seanmiddleditch/gha-setup-ninja@v5
212+
- name: Configure CMake enabling FIPS
213+
run: cmake -DFIPS="true" -S . -B build
214+
- name: Build, release configuration, FIPS
215+
run: cmake --build build --config Release
216+
- name: Integration test, release configuration, FIPS
217+
run: cargo test --features=fips --locked --test client_server client_server_integration -- --ignored --exact
218+
env:
219+
CLIENT_BINARY: D:\a\rustls-ffi\rustls-ffi\build\tests\Release\client.exe
220+
SERVER_BINARY: D:\a\rustls-ffi\rustls-ffi\build\tests\Release\server.exe
221+
171222
ensure-header-updated:
172223
runs-on: ubuntu-latest
173224
steps:

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ endif ()
1010

1111
set(CERT_COMPRESSION "false" CACHE STRING "Whether to enable brotli and zlib certificate compression support")
1212

13+
set(FIPS "false" CACHE STRING "Whether to enable aws-lc-rs and FIPS support")
14+
1315
set(CARGO_FEATURES --no-default-features)
1416
if (CRYPTO_PROVIDER STREQUAL "aws-lc-rs")
1517
list(APPEND CARGO_FEATURES --features=aws-lc-rs)
@@ -21,6 +23,11 @@ if (CERT_COMPRESSION STREQUAL "true")
2123
list(APPEND CARGO_FEATURES --features=cert_compression)
2224
endif ()
2325

26+
# See https://docs.rs/rustls/latest/rustls/manual/_06_fips/index.html
27+
if (FIPS STREQUAL "true")
28+
list(APPEND CARGO_FEATURES --features=fips)
29+
endif ()
30+
2431
add_subdirectory(tests)
2532

2633
include(ExternalProject)

Cargo.lock

Lines changed: 16 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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ capi = []
2424
ring = ["rustls/ring", "webpki/ring"]
2525
aws-lc-rs = ["rustls/aws-lc-rs", "webpki/aws_lc_rs"]
2626
cert_compression = ["rustls/brotli", "rustls/zlib"]
27+
fips = ["aws-lc-rs", "rustls/fips"]
2728

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

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ CFLAGS := -Werror -Wall -Wextra -Wpedantic -g -I src/
1111
PROFILE := release
1212
CRYPTO_PROVIDER := aws-lc-rs
1313
COMPRESSION := false
14+
FIPS := false
1415
DESTDIR=/usr/local
1516

1617
ifeq ($(PROFILE), debug)
@@ -41,6 +42,11 @@ ifeq ($(COMPRESSION), true)
4142
LDFLAGS += -lm
4243
endif
4344

45+
# See https://docs.rs/rustls/latest/rustls/manual/_06_fips/index.html
46+
ifeq ($(FIPS), true)
47+
CARGOFLAGS += --features fips
48+
endif
49+
4450
default: target/$(PROFILE)/librustls_ffi.a
4551

4652
all: default test integration connect-test

Makefile.pkg-config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ CFLAGS := -Werror -Wall -Wextra -Wpedantic -g -I src/
1515
PROFILE := release
1616
CRYPTO_PROVIDER := aws-lc-rs
1717
CERT_COMPRESSION := false
18+
FIPS := false
1819
PREFIX=/usr/local
1920

2021
ifeq ($(PROFILE), debug)
@@ -39,6 +40,11 @@ ifeq ($(CERT_COMPRESSION), true)
3940
CARGOFLAGS += --features cert_compression
4041
endif
4142

43+
# See https://docs.rs/rustls/latest/rustls/manual/_06_fips/index.html
44+
ifeq ($(FIPS), true)
45+
CARGOFLAGS += --features fips
46+
endif
47+
4248
all: target/client target/server
4349

4450
integration: all

tests/client_server.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,25 @@ fn client_server_integration() {
110110
],
111111
};
112112

113+
// CHACHA20 is not FIPS approved :)
114+
#[cfg(not(feature = "fips"))]
115+
let custom_ciphersuite = "TLS13_CHACHA20_POLY1305_SHA256";
116+
#[cfg(feature = "fips")]
117+
let custom_ciphersuite = "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256";
118+
113119
let custom_ciphersuites = TestCase {
114120
name: "client/server with limited ciphersuites",
115121
server_opts: ServerOptions {
116122
valgrind: valgrind.clone(),
117-
env: vec![("RUSTLS_CIPHERSUITE", "TLS13_CHACHA20_POLY1305_SHA256")],
123+
env: vec![("RUSTLS_CIPHERSUITE", custom_ciphersuite)],
118124
},
119125
client_tests: vec![
120126
ClientTest {
121127
name: "limited ciphersuite, supported by server",
122128
valgrind: valgrind.clone(),
123129
env: vec![
124130
("NO_CHECK_CERTIFICATE", "1"),
125-
("RUSTLS_CIPHERSUITE", "TLS13_CHACHA20_POLY1305_SHA256"),
131+
("RUSTLS_CIPHERSUITE", custom_ciphersuite),
126132
],
127133
expect_error: false,
128134
},

0 commit comments

Comments
 (0)