Skip to content

Commit

Permalink
refactor(*) drop OpenSSL 1.0.2, 1.1.0 and BoringSSL support
Browse files Browse the repository at this point in the history
  • Loading branch information
fffonion committed Nov 1, 2023
1 parent 8d12024 commit d3351ac
Show file tree
Hide file tree
Showing 52 changed files with 346 additions and 1,732 deletions.
84 changes: 1 addition & 83 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ jobs:
include:
# TODO: arm64
# latest and one version older for valgrind and perf test
- nginx: "1.19.9"
openssl: "1.0.2u"
extras: "valgrind"
lua_nginx_module: "v0.10.20"
lua_resty_core: "v0.1.22"
- nginx: "1.19.9"
openssl: "1.1.1w"
extras: "valgrind"
Expand All @@ -45,11 +40,6 @@ jobs:
lua_nginx_module: "v0.10.20"
lua_resty_core: "v0.1.22"
nginx_cc_opts: "-Wno-error"
- nginx: "1.21.4"
openssl: "1.0.2u"
extras: "valgrind"
lua_nginx_module: "v0.10.25"
lua_resty_core: "v0.1.27"
- nginx: "1.21.4"
openssl: "1.1.1w"
extras: "valgrind perf"
Expand All @@ -76,23 +66,6 @@ jobs:
lua_nginx_module: "v0.10.25"
lua_resty_core: "v0.1.27"
nginx_cc_opts: "-Wno-error"
#
# latest version with EOL 1.1.0
- nginx: "1.21.4"
openssl: "1.1.0l"
lua_nginx_module: "v0.10.25"
lua_resty_core: "v0.1.27"
# version that kong uses, for fips
- nginx: "1.21.4"
boringssl: "ae223d6138807a13006342edfeef32e813246b39" # fips-20190808
extras: "valgrind perf"
lua_nginx_module: "v0.10.25"
lua_resty_core: "v0.1.27"
- nginx: "1.21.4"
boringssl: "853ca1ea1168dff08011e5d42d94609cc0ca2e27" # fips-20210429, not active yet
extras: "valgrind perf"
lua_nginx_module: "v0.10.25"
lua_resty_core: "v0.1.27"

env:
JOBS: 3
Expand Down Expand Up @@ -122,7 +95,7 @@ jobs:
with:
path: |
/home/runner/work/cache
key: ${{ runner.os }}-${{ hashFiles('**/tests.yml') }}-nginx-${{ matrix.nginx }}-openssl-${{ matrix.openssl }}-${{ matrix.fips2 }}-boringssl-${{ matrix.boringssl }}
key: ${{ runner.os }}-${{ hashFiles('**/tests.yml') }}-nginx-${{ matrix.nginx }}-openssl-${{ matrix.openssl }}-fips-${{ matrix.openssl_fips }}

- name: Setup tools
run: |
Expand Down Expand Up @@ -152,8 +125,6 @@ jobs:
run: |
T=$OPENSSL_PREFIX
mkdir -p $T
# fips doesn't seem to support to build parallelly
if [ "X${{ matrix.fips2 }}" != "X" ]; then wget https://www.openssl.org/source/old/fips/openssl-fips-${{ matrix.fips2 }}.tar.gz -qO - | tar zxf - ; pushd openssl-fips-${{ matrix.fips2 }}/; FIPSDIR=$T/fips ./config; make; make install; popd; fi
if [ "X$OPENSSL_HASH" != "X" ]; then wget https://github.com/openssl/openssl/archive/$OPENSSL_HASH.tar.gz -qO - | tar zxf ; pushd openssl-$OPENSSL_HASH/; fi
if [ "X$OPENSSL_HASH" = "X" ] ; then wget https://www.openssl.org/source/openssl-${{ matrix.openssl }}.tar.gz -qO - | tar zxf -; pushd openssl-${{ matrix.openssl }}/; fi
if [ ! -e $T/include ]; then ./config shared -d --prefix=$T -DPURIFY > build.log 2>&1 || (cat build.log && exit 1); fi
Expand All @@ -178,47 +149,6 @@ jobs:
# don't activate by default
sed -i "/activate = 1/d" $OPENSSL_PREFIX/ssl/fipsmodule.cnf
- name: Build BoringSSL
if: matrix.boringssl != ''
run: |
mkdir -p $OPENSSL_PREFIX
if [ ! -e $OPENSSL_PREFIX/include ]; then
# libtinfo5 is a dependency of clang7 on ubuntu20.04
sudo apt-get install -qq -y cmake libtinfo5 unzip libunwind-dev libgcc-9-dev libstdc++-9-dev
wget https://releases.llvm.org/7.0.1/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04.tar.xz -qO - |tar Jxf -
export HOME="$PWD"
printf "set(CMAKE_C_COMPILER \"clang\")\nset(CMAKE_CXX_COMPILER \"clang++\")\n" > ${HOME}/toolchain
export PATH="$PWD/clang+llvm-7.0.1-x86_64-linux-gnu-ubuntu-18.04/bin:$PATH"
clang --version
wget https://dl.google.com/go/go1.12.7.linux-amd64.tar.gz -qO - |tar zxf -
export GOPATH="$PWD/gopath"
export GOROOT="$PWD/go"
export PATH="$GOPATH/bin:$GOROOT/bin:$PATH"
go version
wget https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip -q
unzip -o ninja-linux.zip
export PATH="$PWD:$PATH"
ninja --version
wget https://commondatastorage.googleapis.com/chromium-boringssl-fips/boringssl-${{ matrix.boringssl }}.tar.xz -qO - | tar Jxf -; pushd boringssl
if [ "${{ matrix.boringssl }}" == "ae223d6138807a13006342edfeef32e813246b39" ]; then
patch -p1 < ../t/fixtures/boringssl_fips.patch
fi
rm -rf build; mkdir build; pushd build
cmake -GNinja -DCMAKE_TOOLCHAIN_FILE=${HOME}/toolchain -DFIPS=1 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1 .. > build.log 2>&1 || (cat build.log && exit 1)
ninja > build.log 2>&1 || (cat build.log && exit 1)
./tool/bssl isfips
popd; rm -rf $OPENSSL_INC; cp -r include $OPENSSL_INC
mkdir -p $OPENSSL_LIB; cp -r build/*/*.so $OPENSSL_LIB
fi
mkdir -p $OPENSSL_PREFIX/certs/ && sudo cp -r /etc/ssl/certs/* $OPENSSL_PREFIX/certs/
- name: Build LuaJIT
env:
LUAJIT_CC_OPTS: ${{ matrix.luajit_cc_opts }}
Expand Down Expand Up @@ -305,18 +235,6 @@ jobs:
export TEST_NGINX_FIPS=1
fi
# openssl 1.0.2 with fips module
if [ "X${{ matrix.fips2 }}" != "X" ]; then
echo "FIPS for OpenSSL 1.0.2"
export TEST_NGINX_FIPS=1
fi
# BoringSSL
if [ "X${{ matrix.boringssl }}" != "X" ]; then
echo "FIPS for BoringSSL ${{ matrix.boringssl }}"
export TEST_NGINX_FIPS=1
fi
if [ "X$TEST_NGINX_FIPS" != "X" ]; then
echo "Running FIPS tests"
Expand Down
54 changes: 12 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# lua-resty-openssl

FFI-based OpenSSL binding for LuaJIT, supporting OpenSSL 3.1, 3.0, 1.1 and 1.0.2 series.
FFI-based OpenSSL binding for LuaJIT, supporting OpenSSL 3.x, 1.1 series.

BoringSSL is also supported.
OpenSSL 1.1.0, 1.0.2 and BoringSSL support has been dropped, but are still available at the [0.x branch](https://github.com/fffonion/lua-resty-openssl/tree/0.x).

![Build Status](https://github.com/fffonion/lua-resty-openssl/workflows/Tests/badge.svg) ![luarocks](https://img.shields.io/luarocks/v/fffonion/lua-resty-openssl?color=%232c3e67) ![opm](https://img.shields.io/opm/v/fffonion/lua-resty-openssl?color=%23599059)

Expand Down Expand Up @@ -295,10 +295,7 @@ Description
===========

`lua-resty-openssl` is a FFI-based OpenSSL binding library, currently
supports OpenSSL `3.1.x`, `3.0.x`, `1.1.1`, `1.1.0` and `1.0.2` series.

**Note: when using with OpenSSL 1.0.2, it's recommanded to not use this library with other FFI-based OpenSSL binding libraries to avoid potential mismatch of `cdef`.**

supports OpenSSL `3.x` and `1.1.1` series.

[Back to TOC](#table-of-contents)

Expand All @@ -321,9 +318,6 @@ using `error()` but instead return as last parameter.
Each Lua table returned by `new()` contains a cdata object `ctx`. User are not supposed to manully setting
`ffi.gc` or calling corresponding destructor of the `ctx` struct (like `*_free` functions).

BoringSSL removes some algorithms and not all functionalities below is supported by BoringSSL. Please
consul its manual for differences between OpenSSL API.

[Back to TOC](#table-of-contents)

## resty.openssl
Expand Down Expand Up @@ -443,7 +437,6 @@ print(c:get_provider_name()) -- prints "fips"
Compile the module per [security policy](https://csrc.nist.gov/CSRC/media/projects/cryptographic-module-validation-program/documents/security-policies/140sp3678.pdf)

Check if FIPS is acticated by running `assert(openssl.set_fips_mode(true))`.
BoringSSL doesn't support "turn FIPS mode off" once it's compiled.

[Back to TOC](#table-of-contents)

Expand Down Expand Up @@ -596,11 +589,6 @@ Returns various OpenSSL version information. Available values for `types` are:
MODULES_DIR
CPU_INFO

For OpenSSL prior to 1.1.x, only `VERSION`, `CFLAGS`, `BUILT_ON`, `PLATFORM`
and `DIR` are supported. Please refer to
[OPENSSL_VERSION_NUMBER(3)](https://www.openssl.org/docs/manmaster/man3/OPENSSL_VERSION_NUMBER.html)
for explanation of each type.

```lua
local version = require("resty.openssl.version")
ngx.say(string.format("%x", version.version_num))
Expand Down Expand Up @@ -767,10 +755,6 @@ X25519 | Y | Y | | | Y (ECDH) |
Ed448 | Y | Y | | Y (PureEdDSA) | |
X448 | Y | Y | | | Y (ECDH) |

`Ed25519`, `X25519`, `Ed448` and `X448` keys are only supported since OpenSSL 1.1.0.

Note BoringSSL doesn't support `Ed448` and `X448` keys.

Direct support of encryption and decryption for EC and ECX does not exist, but
processes like ECIES is possible with [pkey:derive](#pkeyderive),
[kdf](#restyopensslkdf) and [cipher](#restyopensslcipher)
Expand Down Expand Up @@ -1067,8 +1051,7 @@ This mode only supports RSA and EC keys.
When passing a string as first parameter, `md_alg` parameter will specify the name
to use when signing. When `md_alg` is undefined, for RSA and EC keys, this function does SHA256
by default. For Ed25519 or Ed448 keys, this function does a PureEdDSA signing,
no message digest should be specified and will not be used. BoringSSL doesn't have default
digest thus `md_alg` must be specified.
no message digest should be specified and will not be used.

`opts` is a table that accepts additional parameters.

Expand All @@ -1083,8 +1066,7 @@ obsolete MD5 hash algorithm and will return error on this combination. See
for a list of algorithms and associated public key algorithms. Normally, the ECDSA signature
is encoded in ASN.1 DER format. If the `opts` table contains a `ecdsa_use_raw` field with
a true value, a binary with just the concatenation of binary representation `pr` and `ps` is returned.
This is useful for example to send the signature as JWS. This feature
is only supported on OpenSSL 1.1.0 or later.
This is useful for example to send the signature as JWS.

[Back to TOC](#table-of-contents)

Expand All @@ -1106,8 +1088,7 @@ This mode only supports RSA and EC keys.
When passing a string as second parameter, `md_alg` parameter will specify the name
to use when verifying. When `md_alg` is undefined, for RSA and EC keys, this function does SHA256
by default. For Ed25519 or Ed448 keys, this function does a PureEdDSA verification,
no message digest should be specified and will not be used. BoringSSL doesn't have default
digest thus `md_alg` must be specified.
no message digest should be specified and will not be used.

`opts` is a table that accepts additional parameters.

Expand All @@ -1118,8 +1099,7 @@ possible to specify PSS salt length by setting `opts.pss_saltlen`.
For EC key, this function does a ECDSA verification. Normally, the ECDSA signature
should be encoded in ASN.1 DER format. If the `opts` table contains a `ecdsa_use_raw` field with
a true value, this library treat `signature` as concatenation of binary representation `pr` and `ps`.
This is useful for example to verify the signature as JWS. This feature
is only supported on OpenSSL 1.1.0 or later.
This is useful for example to verify the signature as JWS.

```lua
-- RSA and EC keys
Expand Down Expand Up @@ -1313,8 +1293,7 @@ Creates a `bn` instance from binary string.
Exports the BIGNUM value in binary string.

`bn:to_binary` accepts an optional number argument `padto` that can be
used to pad leading zeros to the output to a specific length. This feature
is only supported on OpenSSL 1.1.0 or later.
used to pad leading zeros to the output to a specific length.

```lua
local b, err = require("resty.openssl.bn").from_binary(ngx.decode_base64("WyU="))
Expand Down Expand Up @@ -2030,8 +2009,7 @@ instead.

Derive a key from given material. Various KDFs are supported based on OpenSSL version:

- On OpenSSL 1.0.2 and later, `PBKDF2`([RFC 2898], [NIST SP 800-132]) is available.
- On OpenSSL 1.1.0 and later, `HKDF`([RFC 5869]), `TLS1-PRF`([RFC 2246], [RFC 5246] and [NIST SP 800-135 r1]) and `scrypt`([RFC 7914]) is available.
`PBKDF2`([RFC 2898], [NIST SP 800-132]), `HKDF`([RFC 5869]), `TLS1-PRF`([RFC 2246], [RFC 5246] and [NIST SP 800-135 r1]) and `scrypt`([RFC 7914]) is available.


`options` is a table that contains:
Expand All @@ -2047,7 +2025,7 @@ Derive a key from given material. Various KDFs are supported based on OpenSSL ve
to explictly select provider to fetch algorithms. | |
| pbkdf2_iter | number | PBKDF2 iteration count. RFC 2898 suggests an iteration count of at least 1000. Any value less than 1 is treated as a single iteration. | `1` |
| hkdf_key | string | HKDF key | **required** |
| hkdf_mode | number | HKDF mode to use, one of `kdf.HKDEF_MODE_EXTRACT_AND_EXPAND`, `kdf.HKDEF_MODE_EXTRACT_ONLY` or `kdf.HKDEF_MODE_EXPAND_ONLY`. This is only effective with OpenSSL >= 1.1.1. To learn about mode, please refer to [EVP_PKEY_CTX_set1_hkdf_key(3)](https://www.openssl.org/docs/manmaster/man3/EVP_PKEY_CTX_set1_hkdf_key.html). Note with `kdf.HKDEF_MODE_EXTRACT_ONLY`, `outlen` is ignored and the output will be fixed size of `HMAC-<md>`. | `kdf.HKDEF_MODE_EXTRACT_AND_EXPAND`|
| hkdf_mode | number | HKDF mode to use, one of `kdf.HKDEF_MODE_EXTRACT_AND_EXPAND`, `kdf.HKDEF_MODE_EXTRACT_ONLY` or `kdf.HKDEF_MODE_EXPAND_ONLY`. To learn about mode, please refer to [EVP_PKEY_CTX_set1_hkdf_key(3)](https://www.openssl.org/docs/manmaster/man3/EVP_PKEY_CTX_set1_hkdf_key.html). Note with `kdf.HKDEF_MODE_EXTRACT_ONLY`, `outlen` is ignored and the output will be fixed size of `HMAC-<md>`. | `kdf.HKDEF_MODE_EXTRACT_AND_EXPAND`|
| hkdf_info | string | HKDF info value | (empty string) |
| tls1_prf_secret | string | TLS1-PRF secret | **required** |
| tls1_prf_seed | string | TLS1-PRF seed | **required** |
Expand Down Expand Up @@ -2592,8 +2570,6 @@ Sign the certificate using the private key specified by `pkey`, which must be a
parameter to set digest method, whichmust be a [resty.openssl.digest](#restyopenssldigest) instance.
Returns a boolean indicating if signing is successful and error if any.

In BoringSSL when `digest` is not set it's fallback to `SHA256`.

[Back to TOC](#table-of-contents)

### x509:verify
Expand Down Expand Up @@ -2804,8 +2780,6 @@ Sign the certificate request using the private key specified by `pkey`, which mu
parameter to set digest method, whichmust be a [resty.openssl.digest](#restyopenssldigest) instance.
Returns a boolean indicating if signing is successful and error if any.

In BoringSSL when `digest` is not set it's fallback to `SHA256`.

[Back to TOC](#table-of-contents)

### csr:verify
Expand Down Expand Up @@ -3020,8 +2994,6 @@ Sign the CRL using the private key specified by `pkey`, which must be a
parameter to set digest method, whichmust be a [resty.openssl.digest](#restyopenssldigest) instance.
Returns a boolean indicating if signing is successful and error if any.

In BoringSSL when `digest` is not set it's fallback to `SHA256`.

[Back to TOC](#table-of-contents)

### crl:verify
Expand Down Expand Up @@ -3973,8 +3945,6 @@ to explictly select provider to fetch algorithms.
Returns `true` when the certificate isn't revoked,
otherwise returns `nil` and error explaining the reason.

Note this function is supported from OpenSSL 1.1.0 and not supported in BoringSSL.

[Back to TOC](#table-of-contents)

## resty.openssl.x509.revoked
Expand Down Expand Up @@ -4539,7 +4509,7 @@ Copyright and License

This module is licensed under the BSD license.

Copyright (C) 2019-2020, by fffonion <[email protected]>.
Copyright (C) 2019-2023, by fffonion <[email protected]>.

All rights reserved.

Expand All @@ -4557,7 +4527,7 @@ See Also
========
* [luaossl](https://github.com/wahern/luaossl)
* [API/ABI changes review for OpenSSL](https://abi-laboratory.pro/index.php?view=timeline&l=openssl)
* [OpenSSL API manual](https://www.openssl.org/docs/man1.1.1/man3/)
* [OpenSSL API manual](https://www.openssl.org/docs/man3.1/man3/)

[Back to TOC](#table-of-contents)

Expand Down
11 changes: 1 addition & 10 deletions lib/resty/openssl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ local ffi_str = ffi.string

local format_error = require("resty.openssl.err").format_error

local OPENSSL_3X, BORINGSSL
local OPENSSL_3X

local function try_require_modules()
package.loaded["resty.openssl.version"] = nil

local pok, lib = pcall(require, "resty.openssl.version")
if pok then
OPENSSL_3X = lib.OPENSSL_3X
BORINGSSL = lib.BORINGSSL

require "resty.openssl.include.crypto"
require "resty.openssl.include.objects"
Expand Down Expand Up @@ -362,10 +361,6 @@ local function list_provided(typ)
end

function _M.list_cipher_algorithms()
if BORINGSSL then
return nil, "openssl.list_cipher_algorithms is not supported on BoringSSL"
end

require "resty.openssl.include.evp.cipher"
local ret = list_legacy("EVP_CIPHER",
OPENSSL_3X and C.EVP_CIPHER_get_nid or C.EVP_CIPHER_nid)
Expand All @@ -381,10 +376,6 @@ function _M.list_cipher_algorithms()
end

function _M.list_digest_algorithms()
if BORINGSSL then
return nil, "openssl.list_digest_algorithms is not supported on BoringSSL"
end

require "resty.openssl.include.evp.md"
local ret = list_legacy("EVP_MD",
OPENSSL_3X and C.EVP_MD_get_type or C.EVP_MD_type)
Expand Down
Loading

0 comments on commit d3351ac

Please sign in to comment.