📈 Improving OpenSSL test coverage (#155)

This cleans up some of the testing for specific ssl versions, updates LibreSSL tests to the latest patch versions and adds badges for OpenSSL test.
This commit is contained in:
Chris Mc
2021-08-17 07:42:24 -04:00
committed by GitHub
parent 17fdd26d97
commit 23fd608caf
6 changed files with 77 additions and 42 deletions

View File

@@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
libressl: ["3.3.1", "3.2.3", "3.1.5"]
libressl: ["3.3.3", "3.2.5", "3.1.5"]
steps:
- uses: actions/checkout@v2
- uses: lukka/get-cmake@latest

View File

@@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
openssl: ["openssl-3.0.0-beta2", "OpenSSL_1_1_1k"]
openssl: ["openssl-3.0.0-beta2", "OpenSSL_1_1_1k", "OpenSSL_1_1_0i", "OpenSSL_1_0_2u"]
steps:
- uses: actions/checkout@v2
- uses: lukka/get-cmake@latest
@@ -34,3 +34,30 @@ jobs:
- name: test
run: ./tests/jwt-cpp-test
- name: badge success
if: github.event_name == 'push' && success()
uses: ./.github/actions/badge
with:
category: openssl
label: ${{ matrix.openssl }}
- name: badge failure
if: github.event_name == 'push' && !success()
uses: ./.github/actions/badge
with:
category: openssl
label: ${{ matrix.openssl }}
message: Failing
color: red
- name: badge publish
if: github.event_name == 'push'
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: badges
publish_dir: ./badges
keep_files: true
user_name: "github-actions[bot]"
user_email: "github-actions[bot]@users.noreply.github.com"

View File

@@ -33,17 +33,20 @@ For completeness, here is a list of all supported algorithms:
In the name of flexibility and extensibility, jwt-cpp supports both [OpenSSL](https://github.com/openssl/openssl) and [LibreSSL](https://github.com/libressl-portable/portable). These are the version which are, or have been, tested:
| OpenSSL | LibreSSL |
| -------------- | --------------- |
| [1.0.2][1.0.2] | ![3.1.5][3.1] |
| 1.1.0 | ![3.2.3][3.2] |
| [1.1.1][1.1.1] | ![3.3.1][3.3] |
| OpenSSL | LibreSSL |
| -------------------- | --------------- |
| ![1.0.2u][o1.0.2] | ![3.1.5][l3.1] |
| ![1.1.0i][o1.1.0] | ![3.2.5][l3.2] |
| ![1.1.1k][o1.1.1] | ![3.3.3][l3.3] |
| ![3.0.0-beta2][o3.0] | |
[1.0.2]: https://travis-ci.com/github/Thalhammer/jwt-cpp
[1.1.1]: https://github.com/Thalhammer/jwt-cpp/actions?query=workflow%3A%22Coverage+CI%22
[3.1]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.1.5/shields.json
[3.2]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.2.3/shields.json
[3.3]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.3.1/shields.json
[o1.0.2]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/OpenSSL_1_0_2u/shields.json
[o1.1.0]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/OpenSSL_1_1_0i/shields.json
[o1.1.1]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/OpenSSL_1_1_1k/shields.json
[o3.0]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/openssl/openssl-3.0.0-beta2/shields.json
[l3.1]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.1.5/shields.json
[l3.2]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.2.5/shields.json
[l3.3]: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/Thalhammer/jwt-cpp/badges/libressl/3.3.3/shields.json
## Overview

View File

@@ -40,23 +40,18 @@
#endif
#endif
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#define OPENSSL3
#endif
// If openssl version less than 1.1
#if OPENSSL_VERSION_NUMBER < 0x10100000L
#define OPENSSL10
#endif
// If openssl version less than 1.1.1
#if OPENSSL_VERSION_NUMBER < 0x10101000L
#define OPENSSL110
#if OPENSSL_VERSION_NUMBER >= 0x30000000L // 3.0.0
#define JWT_OPENSSL_3_0
#elif OPENSSL_VERSION_NUMBER >= 0x10101000L // 1.1.1
#define JWT_OPENSSL_1_1_1
#elif OPENSSL_VERSION_NUMBER >= 0x10100000L // 1.1.0
#define JWT_OPENSSL_1_1_0
#elif OPENSSL_VERSION_NUMBER >= 0x10000000L // 1.0.0
#define JWT_OPENSSL_1_0_0
#endif
#if defined(LIBRESSL_VERSION_NUMBER)
#define OPENSSL10
#define OPENSSL110
#define JWT_OPENSSL_1_0_0
#endif
#ifndef JWT_CLAIM_EXPLICIT
@@ -635,7 +630,7 @@ namespace jwt {
* \return bignum as string
*/
inline
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
static std::string
bn2raw(BIGNUM* bn)
#else
@@ -793,7 +788,7 @@ namespace jwt {
*/
std::string sign(const std::string& data, std::error_code& ec) const {
ec.clear();
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_destroy)> ctx(EVP_MD_CTX_create(), EVP_MD_CTX_destroy);
#else
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_create(), EVP_MD_CTX_free);
@@ -830,7 +825,7 @@ namespace jwt {
*/
void verify(const std::string& data, const std::string& signature, std::error_code& ec) const {
ec.clear();
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_destroy)> ctx(EVP_MD_CTX_create(), EVP_MD_CTX_destroy);
#else
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_create(), EVP_MD_CTX_free);
@@ -944,7 +939,7 @@ namespace jwt {
ec = error::signature_generation_error::ecdsa_do_sign_failed;
return {};
}
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
auto rr = helper::bn2raw(sig->r);
auto rs = helper::bn2raw(sig->s);
@@ -975,7 +970,7 @@ namespace jwt {
auto r = helper::raw2bn(signature.substr(0, signature.size() / 2));
auto s = helper::raw2bn(signature.substr(signature.size() / 2));
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
ECDSA_SIG sig;
sig.r = r.get();
sig.s = s.get();
@@ -1014,7 +1009,7 @@ namespace jwt {
* \return Hash of data
*/
std::string generate_hash(const std::string& data, std::error_code& ec) const {
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_destroy)> ctx(EVP_MD_CTX_create(),
&EVP_MD_CTX_destroy);
#else
@@ -1055,7 +1050,7 @@ namespace jwt {
const size_t signature_length;
};
#ifndef OPENSSL110
#if !defined(JWT_OPENSSL_1_0_0) && !defined(JWT_OPENSSL_1_1_0)
/**
* \brief Base class for EdDSA family of algorithms
*
@@ -1093,7 +1088,12 @@ namespace jwt {
*/
std::string sign(const std::string& data, std::error_code& ec) const {
ec.clear();
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_create(), EVP_MD_CTX_free);
#ifdef JWT_OPENSSL_1_0_0
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_destroy)> ctx(EVP_MD_CTX_create(),
&EVP_MD_CTX_destroy);
#else
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_new(), EVP_MD_CTX_free);
#endif
if (!ctx) {
ec = error::signature_generation_error::create_context_failed;
return {};
@@ -1141,7 +1141,12 @@ namespace jwt {
*/
void verify(const std::string& data, const std::string& signature, std::error_code& ec) const {
ec.clear();
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_create(), EVP_MD_CTX_free);
#ifdef JWT_OPENSSL_1_0_0
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_destroy)> ctx(EVP_MD_CTX_create(),
&EVP_MD_CTX_destroy);
#else
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_free)> ctx(EVP_MD_CTX_new(), EVP_MD_CTX_free);
#endif
if (!ctx) {
ec = error::signature_verification_error::create_context_failed;
return;
@@ -1293,7 +1298,7 @@ namespace jwt {
* \return Hash of data
*/
std::string generate_hash(const std::string& data, std::error_code& ec) const {
#ifdef OPENSSL10
#ifdef JWT_OPENSSL_1_0_0
std::unique_ptr<EVP_MD_CTX, decltype(&EVP_MD_CTX_destroy)> ctx(EVP_MD_CTX_create(),
&EVP_MD_CTX_destroy);
#else
@@ -1457,7 +1462,7 @@ namespace jwt {
: ecdsa(public_key, private_key, public_key_password, private_key_password, EVP_sha512, "ES512", 132) {}
};
#ifndef OPENSSL110
#if !defined(JWT_OPENSSL_1_0_0) && !defined(JWT_OPENSSL_1_1_0)
/**
* Ed25519 algorithm
*

View File

@@ -4,7 +4,7 @@
#include <dlfcn.h>
// TODO: Figure out why the tests fail on older openssl versions
#ifndef OPENSSL110 // It fails on < 1.1 but no idea why.
#ifndef JWT_OPENSSL_1_0_0 // It fails on < 1.1 but no idea why.
// LibreSSL has different return codes but was already outside of the effective scope
/**
@@ -73,7 +73,7 @@ EVP_PKEY* X509_get_pubkey(X509* x) {
return origMethod(x);
}
#ifdef OPENSSL3
#ifdef JWT_OPENSSL_3_0
#define OPENSSL_CONST const
#else
#define OPENSSL_CONST
@@ -733,7 +733,7 @@ TEST(OpenSSLErrorTest, PS256VerifyErrorCode) {
run_multitest(mapping, [&alg, &signature](std::error_code& ec) { alg.verify("testdata", signature, ec); });
}
#ifndef OPENSSL110
#if !defined(JWT_OPENSSL_1_0_0) && !defined(JWT_OPENSSL_1_1_0)
TEST(OpenSSLErrorTest, EdDSAKey) {
std::vector<multitest_entry> mapping{
// load_private_key_from_string

View File

@@ -174,7 +174,7 @@ TEST(TokenTest, CreateTokenES512NoPrivate) {
jwt::signature_generation_exception);
}
#ifndef OPENSSL110
#if !defined(JWT_OPENSSL_1_0_0) && !defined(JWT_OPENSSL_1_1_0)
TEST(TokenTest, CreateTokenEd25519) {
auto token =
@@ -582,7 +582,7 @@ TEST(TokenTest, VerifyTokenPS256FailNoKey) {
jwt::rsa_exception);
}
#ifndef OPENSSL110
#if !defined(JWT_OPENSSL_1_0_0) && !defined(JWT_OPENSSL_1_1_0)
TEST(TokenTest, VerifyTokenEd25519) {
const std::string token =
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"