Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support AWS-LC SSL Library. #2357

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ addons:
- libunwind-dev
- wget
- libbrotli1
- ninja-build # for aws-lc

cache:
directories:
@@ -65,6 +66,7 @@ env:
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.0.15 OPENSSL_PATCH_VER=3.0.15 TEST_NGINX_TIMEOUT=5 PCRE2_VER=10.42
- NGINX_VERSION=1.27.1 OPENSSL_VER=3.0.15 OPENSSL_PATCH_VER=3.0.15 TEST_NGINX_USE_HTTP3=1 TEST_NGINX_QUIC_IDLE_TIMEOUT=3 PCRE2_VER=10.42
- NGINX_VERSION=1.27.1 BORINGSSL=1 TEST_NGINX_USE_HTTP3=1 TEST_NGINX_QUIC_IDLE_TIMEOUT=3 PCRE2_VER=10.42
- NGINX_VERSION=1.27.1 AWSLC=1 TEST_NGINX_USE_HTTP3=1 USE_PCRE2=Y TEST_NGINX_QUIC_IDLE_TIMEOUT=3

services:
- memcached
@@ -85,6 +87,7 @@ install:
- if [ -n "$PCRE_VER" ]; then wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v1.0.0/pcre-${PCRE_VER}-x64-focal.tar.gz; fi
- if [ -n "$PCRE2_VER" ]; then wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v1.0.0/pcre2-${PCRE2_VER}-x64-focal.tar.gz; fi
- wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/boringssl-20230902-x64-focal.tar.gz
- wget -O aws-lc.tar.gz https://github.com/aws/aws-lc/archive/refs/tags/v1.34.2.tar.gz
- wget https://github.com/openresty/openresty-deps-prebuild/releases/download/v20230902/curl-h3-x64-focal.tar.gz
- git clone https://github.com/openresty/test-nginx.git
- git clone https://github.com/openresty/openresty.git ../openresty
@@ -139,6 +142,7 @@ script:
#- if [ -n "$PCRE2_VER" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
#- if [ -n "$OPENSSL_VER" ]; then tar zxf download-cache/openssl-$OPENSSL_VER.tar.gz; cd openssl-$OPENSSL_VER/; patch -p1 < ../../openresty/patches/openssl-$OPENSSL_PATCH_VER-sess_set_get_cb_yield.patch; ./config shared enable-ssl3 enable-ssl3-method -g --prefix=$OPENSSL_PREFIX --libdir=lib -DPURIFY > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo make PATH=$PATH install_sw > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
- if [ -n "$BORINGSSL" ]; then sudo mkdir -p /opt/ssl && sudo tar -C /opt/ssl -xf boringssl-20230902-x64-focal.tar.gz --strip-components=1; fi
- if [ -n "$AWSLC" ]; then sudo mkdir -p /opt/ssl; sudo sh util/build-aws-lc.sh; export ENABLE_AWS_LC="-DOPENSSL_IS_BORINGSSL "; fi
- if [ -n "$OPENSSL_VER" ]; then sudo mkdir -p /opt/ssl && sudo tar -C /opt/ssl -xf openssl-$OPENSSL_VER-x64-focal.tar.gz --strip-components=2; fi
- if [ -n "$PCRE_VER" ]; then sudo mkdir -p $PCRE_PREFIX && sudo tar -C $PCRE_PREFIX -xf pcre-$PCRE_VER-x64-focal.tar.gz --strip-components=2; fi
- if [ -n "$PCRE2_VER" ]; then sudo mkdir -p $PCRE2_PREFIX && sudo tar -C $PCRE2_PREFIX -xf pcre2-$PCRE2_VER-x64-focal.tar.gz --strip-components=2; fi
4 changes: 2 additions & 2 deletions src/ngx_http_lua_ssl_certby.c
Original file line number Diff line number Diff line change
@@ -1345,7 +1345,7 @@ ngx_http_lua_ffi_set_cert(ngx_http_request_t *r,

# else

#ifdef OPENSSL_IS_BORINGSSL
#if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC)
size_t i;
#else
int i;
@@ -1487,7 +1487,7 @@ ngx_http_lua_ffi_ssl_verify_client(ngx_http_request_t *r, void *client_certs,
X509 *x509 = NULL;
X509_NAME *subject = NULL;
X509_STORE *ca_store = NULL;
#ifdef OPENSSL_IS_BORINGSSL
#if defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC)
size_t i;
#else
int i;
11 changes: 7 additions & 4 deletions src/ngx_http_lua_ssl_export_keying_material.c
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ ngx_http_lua_ffi_ssl_export_keying_material(ngx_http_request_t *r,
u_char *out, size_t out_size, const char *label, size_t llen,
const u_char *context, size_t ctxlen, int use_ctx, char **err)
{
#if defined(OPENSSL_IS_BORINGSSL) || OPENSSL_VERSION_NUMBER < 0x10101000L
#if defined(OPENSSL_IS_BORINGSSL)
*err = "BoringSSL does not support SSL_export_keying_material";
return NGX_ERROR;
#elif defined(LIBRESSL_VERSION_NUMBER)
@@ -79,11 +79,14 @@ ngx_http_lua_ffi_ssl_export_keying_material_early(ngx_http_request_t *r,
u_char *out, size_t out_size, const char *label, size_t llen,
const u_char *context, size_t ctxlen, char **err)
{
#if defined(OPENSSL_IS_BORINGSSL) || OPENSSL_VERSION_NUMBER < 0x10101000L
*err = "BoringSSL does not support SSL_export_keying_material";
#if defined(OPENSSL_IS_BORINGSSL)
*err = "BoringSSL does not support SSL_export_keying_material_early";
return NGX_ERROR;
#elif defined(LIBRESSL_VERSION_NUMBER)
*err = "LibreSSL does not support SSL_export_keying_material";
*err = "LibreSSL does not support SSL_export_keying_material_early";
return NGX_ERROR;
#elif defined(OPENSSL_IS_AWSLC)
*err = "AWS-LC does not support SSL_export_keying_material_early";
return NGX_ERROR;
#elif OPENSSL_VERSION_NUMBER < 0x10101000L
*err = "OpenSSL too old";
2 changes: 1 addition & 1 deletion src/ngx_http_lua_ssl_ocsp.c
Original file line number Diff line number Diff line change
@@ -511,7 +511,7 @@ ngx_http_lua_ffi_ssl_set_ocsp_status_resp(ngx_http_request_t *r,
return NGX_ERROR;
}

#ifdef SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE
#if defined(SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE) || defined(OPENSSL_IS_AWSLC)
if (SSL_get_tlsext_status_type(ssl_conn) == -1) {
#else
if (ssl_conn->tlsext_status_type == -1) {
2 changes: 2 additions & 0 deletions t/140-ssl-c-api.t
Original file line number Diff line number Diff line change
@@ -11,6 +11,8 @@ my $openssl_version = eval { `$NginxBinary -V 2>&1` };
if ($openssl_version =~ m/built with OpenSSL (0|1\.0\.(?:0|1[^\d]|2[a-d]).*)/) {
plan(skip_all => "too old OpenSSL, need 1.0.2e, was $1");

} elsif ($openssl_version =~ m/AWS-LC/) {
plan(skip_all => "does not support AWS-LC");
} else {
plan tests => repeat_each() * (blocks() * 5 - 1);
}
2 changes: 2 additions & 0 deletions t/166-ssl-client-hello.t
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
} elsif ($openssl_version =~ m/running with BoringSSL/) {
plan(skip_all => "does not support BoringSSL");
} elsif ($openssl_version =~ m/AWS-LC/) {
plan(skip_all => "does not support AWS-LC");
} else {
plan tests => repeat_each() * (blocks() * 6 + 8);
}
2 changes: 2 additions & 0 deletions t/187-ssl-two-verification.t
Original file line number Diff line number Diff line change
@@ -12,6 +12,8 @@ if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
} elsif ($openssl_version =~ m/running with BoringSSL/) {
plan(skip_all => "does not support BoringSSL");
} elsif ($openssl_version =~ m/AWS-LC/) {
plan(skip_all => "does not support AWS-LC");
} else {
plan tests => repeat_each() * (blocks() * 7);
}
14 changes: 14 additions & 0 deletions util/build-aws-lc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

# this script is for developers only.
# to build nginx with aws-lc, need two patches:
# https://mailman.nginx.org/pipermail/nginx-devel/2024-February/3J4C2B5L67YSKARKNVLLQHHR7QXXMMRI.html
# https://mailman.nginx.org/pipermail/nginx-devel/2024-February/R2AD2Q4XEVNAYEZY6WEVQBAKTM45OMTG.html
# those patches are merged into nginx-*-aws-lc.patch

root=`pwd`

tar -xzf aws-lc.tar.gz
mv aws-lc-* aws-lc
cmake $root/aws-lc -GNinja -B$root/aws-lc-build -DCMAKE_INSTALL_PREFIX=/opt/ssl -DBUILD_TESTING=OFF -DDISABLE_GO=ON -DBUILD_TOOL=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=0
ninja -C $root/aws-lc-build install
2 changes: 1 addition & 1 deletion util/build-with-dd.sh
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ time ngx-build $force $version \
--with-pcre-jit \
$disable_pcre2 \
--with-ipv6 \
--with-cc-opt="-DNGX_LUA_USE_ASSERT -I$PCRE_INC -I$OPENSSL_INC -DDDEBUG=1" \
--with-cc-opt="$ENABLE_AWS_LC-DNGX_LUA_USE_ASSERT -I$PCRE_INC -I$OPENSSL_INC -DDDEBUG=1" \
--with-http_v2_module \
$add_http3_module \
--with-http_realip_module \
2 changes: 1 addition & 1 deletion util/build.sh
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ time ngx-build $force $version \
--with-pcre-jit \
$disable_pcre2 \
--with-ipv6 \
--with-cc-opt="-DNGX_LUA_USE_ASSERT -I$PCRE_INC -I$OPENSSL_INC" \
--with-cc-opt="$ENABLE_AWS_LC-DNGX_LUA_USE_ASSERT -I$PCRE_INC -I$OPENSSL_INC" \
--with-http_v2_module \
$add_http3_module \
--with-http_realip_module \