Skip to content

Commit 5d04b9f

Browse files
committed
Add and test AWS-LC support.
1 parent e929adb commit 5d04b9f

File tree

4 files changed

+111
-8
lines changed

4 files changed

+111
-8
lines changed

.github/workflows/ci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ on:
99
env:
1010
CARGO_TERM_COLOR: 'always'
1111
RUST_BACKTRACE: '1'
12+
AWSLC_SOURCE_DIR: ${{ github.workspace }}/aws-lc
1213
NGINX_SOURCE_DIR: nginx
1314

1415
jobs:
@@ -55,6 +56,11 @@ jobs:
5556
nginx-ref: stable-1.28
5657
build: debug
5758

59+
- runner: ubuntu
60+
rust-version: stable
61+
nginx-ref: master # AWS-LC is not supported in stable-1.28
62+
build: aws-lc
63+
5864
- runner: macos
5965
rust-version: stable
6066
nginx-ref: stable-1.28
@@ -81,6 +87,12 @@ jobs:
8187
repository: 'nginx/nginx-tests'
8288
path: 'nginx/tests'
8389

90+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
91+
if: startsWith(matrix.build, 'aws-lc')
92+
with:
93+
repository: 'aws/aws-lc'
94+
path: ${{ env.AWSLC_SOURCE_DIR }}
95+
8496
- uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9
8597
with:
8698
toolchain: ${{ matrix.rust-version }}

build/build-aws-lc-static.mk

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#
2+
# Build static module with AWS-LC
3+
#
4+
5+
LIBSSL_SRCDIR = $(AWSLC_SOURCE_DIR)
6+
LIBSSL_BUILDDIR = $(NGINX_BUILD_DIR)/lib/aws-lc/build
7+
LIBSSL_DESTDIR = $(NGINX_BUILD_DIR)/lib/aws-lc/install
8+
9+
# pass SSL library location to openssl-sys
10+
11+
BUILD_ENV += OPENSSL_INCLUDE_DIR="$(LIBSSL_DESTDIR)/include"
12+
BUILD_ENV += OPENSSL_LIB_DIR="$(LIBSSL_DESTDIR)/lib"
13+
BUILD_ENV += OPENSSL_STATIC=1
14+
15+
NGINX_CONFIGURE = \
16+
$(NGINX_CONFIGURE_BASE) \
17+
--with-cc-opt="-I$(LIBSSL_DESTDIR)/include" \
18+
--with-ld-opt="-L$(LIBSSL_DESTDIR)/lib -lstdc++" \
19+
--with-debug \
20+
--add-module="$(CURDIR)"
21+
22+
23+
$(LIBSSL_BUILDDIR)/CMakeCache.txt: $(LIBSSL_SRCDIR)/CMakeLists.txt
24+
cmake -S $(LIBSSL_SRCDIR) \
25+
-B $(LIBSSL_BUILDDIR) \
26+
-DBUILD_TESTING:BOOL=OFF \
27+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
28+
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
29+
-DCMAKE_INSTALL_PREFIX:STRING=$(LIBSSL_DESTDIR)
30+
31+
$(LIBSSL_DESTDIR)/lib/libssl.a: $(LIBSSL_BUILDDIR)/CMakeCache.txt
32+
cmake --build $(LIBSSL_BUILDDIR)
33+
cmake --install $(LIBSSL_BUILDDIR)
34+
35+
$(NGINX_BUILD_DIR)/Makefile: $(LIBSSL_DESTDIR)/lib/libssl.a

build/build-aws-lc.mk

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Build dynamic module with AWS-LC
3+
#
4+
# This build flavor requires shared AWS-LC, because:
5+
#
6+
# * we use libssl objects created by nginx, and thus have to link to the same
7+
# library
8+
#
9+
# * linking static libssl.a to the nginx binary alone results in missing
10+
# symbols during module load
11+
#
12+
# * linking static libssl.a to both the binary and the module results in two
13+
# different sets of static globals
14+
#
15+
16+
LIBSSL_SRCDIR = $(AWSLC_SOURCE_DIR)
17+
LIBSSL_BUILDDIR = $(NGINX_BUILD_DIR)/lib/aws-lc/build
18+
LIBSSL_DESTDIR = $(NGINX_BUILD_DIR)/lib/aws-lc/install
19+
20+
# pass SSL library location to openssl-sys
21+
22+
BUILD_ENV += OPENSSL_INCLUDE_DIR="$(LIBSSL_DESTDIR)/include"
23+
BUILD_ENV += OPENSSL_LIB_DIR="$(LIBSSL_DESTDIR)/lib"
24+
BUILD_ENV += OPENSSL_STATIC=0
25+
26+
TEST_ENV += LD_LIBRARY_PATH="$(LIBSSL_DESTDIR)/lib"
27+
28+
NGINX_CONFIGURE = \
29+
$(NGINX_CONFIGURE_BASE) \
30+
--with-cc-opt="-I$(LIBSSL_DESTDIR)/include" \
31+
--with-ld-opt="-L$(LIBSSL_DESTDIR)/lib -lstdc++" \
32+
--with-debug \
33+
--add-dynamic-module="$(CURDIR)"
34+
35+
36+
NGX_MODULE = $(NGINX_BUILD_DIR)/ngx_http_acme_module.so
37+
TEST_NGINX_GLOBALS += load_module $(NGX_MODULE);
38+
39+
.PHONY: $(NGX_MODULE)
40+
41+
build: $(NGX_MODULE)
42+
43+
44+
$(LIBSSL_BUILDDIR)/CMakeCache.txt: $(LIBSSL_SRCDIR)/CMakeLists.txt
45+
cmake -S $(LIBSSL_SRCDIR) \
46+
-B $(LIBSSL_BUILDDIR) \
47+
-DBUILD_SHARED_LIBS:BOOL=ON \
48+
-DBUILD_TESTING:BOOL=OFF \
49+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
50+
-DCMAKE_INSTALL_LIBDIR:STRING=lib \
51+
-DCMAKE_INSTALL_PREFIX:STRING=$(LIBSSL_DESTDIR)
52+
53+
$(LIBSSL_DESTDIR)/lib/libssl.so: $(LIBSSL_BUILDDIR)/CMakeCache.txt
54+
cmake --build $(LIBSSL_BUILDDIR)
55+
cmake --install $(LIBSSL_BUILDDIR)
56+
57+
$(NGINX_BUILD_DIR)/Makefile: $(LIBSSL_DESTDIR)/lib/libssl.so

src/jws.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ impl Serialize for ShaWithRsaKey {
253253
let num_bytes = rsa.e().num_bytes().max(rsa.n().num_bytes()) as usize;
254254
let mut buf = vec![0u8; num_bytes];
255255

256-
let e = base64url(bn2bin(rsa.e(), &mut buf).map_err(Error::custom)?);
257-
let n = base64url(bn2bin(rsa.n(), &mut buf).map_err(Error::custom)?);
256+
let e = base64url(bn2bin(rsa.e(), &mut buf));
257+
let n = base64url(bn2bin(rsa.n(), &mut buf));
258258

259259
let mut map = serializer.serialize_map(Some(3))?;
260260
// order is important for thumbprint generation (RFC7638)
@@ -344,14 +344,13 @@ where
344344
}
345345

346346
/// [openssl] offers [BigNumRef::to_vec()], but we want to avoid an extra allocation.
347-
fn bn2bin<'a>(bn: &BigNumRef, out: &'a mut [u8]) -> Result<&'a [u8], ErrorStack> {
347+
fn bn2bin<'a>(bn: &BigNumRef, out: &'a mut [u8]) -> &'a [u8] {
348348
debug_assert!(bn.num_bytes() as usize <= out.len());
349+
// BN_bn2bin cannot fail.
349350
let n = unsafe { openssl_sys::BN_bn2bin(bn.as_ptr(), out.as_mut_ptr()) };
350-
if n >= 0 {
351-
Ok(&out[..n as usize])
352-
} else {
353-
Err(ErrorStack::get())
354-
}
351+
#[cfg(not(any(openssl = "awslc", openssl = "boringssl")))]
352+
debug_assert!(n >= 0);
353+
&out[..n as usize]
355354
}
356355

357356
/// [openssl] offers [BigNumRef::to_vec_padded()], but we want to avoid an extra allocation.

0 commit comments

Comments
 (0)