From 17fdd26d97dec5b77c03ccef9057b343894e54dd Mon Sep 17 00:00:00 2001 From: Marek Klein Date: Fri, 13 Aug 2021 13:33:43 +0200 Subject: [PATCH] Fix tests for OpenSSL 3.0.0 (#153) * update signatures of PEM_write_bio_PUBKEY and PEM_write_bio_X509 * run tests with openssl * Update .github/workflows/openssl.yml * fetch openssl from github Co-authored-by: Chris Mc --- .github/actions/install/openssl/action.yml | 19 ++++++++++++ .github/workflows/openssl.yml | 36 ++++++++++++++++++++++ include/jwt-cpp/jwt.h | 4 +++ tests/OpenSSLErrorTest.cpp | 14 ++++++--- 4 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 .github/actions/install/openssl/action.yml create mode 100644 .github/workflows/openssl.yml diff --git a/.github/actions/install/openssl/action.yml b/.github/actions/install/openssl/action.yml new file mode 100644 index 0000000..e8ca65d --- /dev/null +++ b/.github/actions/install/openssl/action.yml @@ -0,0 +1,19 @@ +name: Install OpenSSL +description: Install and setup OpenSSL for linking and building test application +inputs: + version: + description: The desired OpenSSL version to install + required: false + default: "openssl-3.0.0-beta2" +runs: + using: composite + steps: + - run: | + cd /tmp + wget https://github.com/openssl/openssl/archive/refs/tags/${{ inputs.version }}.tar.gz + tar -zxf /tmp/${{ inputs.version }}.tar.gz + cd openssl-${{ inputs.version }} + ./config --prefix=/tmp --libdir=lib + make -j $(nproc) + sudo make -j $(nproc) install_sw + shell: bash diff --git a/.github/workflows/openssl.yml b/.github/workflows/openssl.yml new file mode 100644 index 0000000..f5e7ef9 --- /dev/null +++ b/.github/workflows/openssl.yml @@ -0,0 +1,36 @@ +name: OpenSSL CI + +on: + push: + branches: [master] + pull_request: + branches: [master] + paths: + - "CMakeLists.txt" + - "include/jwt-cpp/**" + - "tests/cmake/**" + - ".github/actions/**" + - ".github/workflows/openssl.yml" + +jobs: + with-openssl: + runs-on: ubuntu-latest + strategy: + matrix: + openssl: ["openssl-3.0.0-beta2", "OpenSSL_1_1_1k"] + steps: + - uses: actions/checkout@v2 + - uses: lukka/get-cmake@latest + - uses: ./.github/actions/install/gtest + - uses: ./.github/actions/install/openssl + with: + version: ${{ matrix.openssl }} + + - name: configure + run: | + cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp + + - run: make + + - name: test + run: ./tests/jwt-cpp-test diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index b00ffde..9bf4f41 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -40,6 +40,10 @@ #endif #endif +#if OPENSSL_VERSION_NUMBER >= 0x30000000L +#define OPENSSL3 +#endif + // If openssl version less than 1.1 #if OPENSSL_VERSION_NUMBER < 0x10100000L #define OPENSSL10 diff --git a/tests/OpenSSLErrorTest.cpp b/tests/OpenSSLErrorTest.cpp index 18ef7be..b09a376 100644 --- a/tests/OpenSSLErrorTest.cpp +++ b/tests/OpenSSLErrorTest.cpp @@ -73,8 +73,14 @@ EVP_PKEY* X509_get_pubkey(X509* x) { return origMethod(x); } -int PEM_write_bio_PUBKEY(BIO* bp, EVP_PKEY* x) { - static int (*origMethod)(BIO * bp, EVP_PKEY * x) = nullptr; +#ifdef OPENSSL3 +#define OPENSSL_CONST const +#else +#define OPENSSL_CONST +#endif + +int PEM_write_bio_PUBKEY(BIO* bp, OPENSSL_CONST EVP_PKEY* x) { + static int (*origMethod)(BIO * bp, OPENSSL_CONST EVP_PKEY * x) = nullptr; if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_write_bio_PUBKEY"); bool fail = fail_PEM_write_bio_PUBKEY & 1; fail_PEM_write_bio_PUBKEY = fail_PEM_write_bio_PUBKEY >> 1; @@ -84,8 +90,8 @@ int PEM_write_bio_PUBKEY(BIO* bp, EVP_PKEY* x) { return origMethod(bp, x); } -int PEM_write_bio_X509(BIO* bp, X509* x) { - static int (*origMethod)(BIO * bp, X509 * x) = nullptr; +int PEM_write_bio_X509(BIO* bp, OPENSSL_CONST X509* x) { + static int (*origMethod)(BIO * bp, OPENSSL_CONST X509 * x) = nullptr; if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_write_bio_X509"); bool fail = fail_PEM_write_bio_cert & 1; fail_PEM_write_bio_cert = fail_PEM_write_bio_cert >> 1;