Skip to content

Commit cf79004

Browse files
Merge branch 'Thalhammer:master' into improve-ux-actions-installers
2 parents 946d01c + 971b897 commit cf79004

3 files changed

Lines changed: 38 additions & 24 deletions

File tree

include/jwt-cpp/jwt.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
#endif
5858

5959
#if defined(LIBRESSL_VERSION_NUMBER)
60-
#if LIBRESSL_VERSION_NUMBER >= 0x3050300fL
60+
#if LIBRESSL_VERSION_NUMBER >= 0x3070100fL // 3.7.1 - EdDSA support
61+
#define JWT_OPENSSL_1_1_1
62+
#elif LIBRESSL_VERSION_NUMBER >= 0x3050300fL // 3.5.3
6163
#define JWT_OPENSSL_1_1_0
6264
#else
6365
#define JWT_OPENSSL_1_0_0
@@ -1806,6 +1808,7 @@ namespace jwt {
18061808
*
18071809
* The EdDSA algorithms were introduced in [OpenSSL v1.1.1](https://www.openssl.org/news/openssl-1.1.1-notes.html),
18081810
* so these algorithms are only available when building against this version or higher.
1811+
* LibreSSL added EdDSA (Ed25519) functionality in [LibreSSL 3.7.1](https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-3.7.1-relnotes.txt)
18091812
*/
18101813
struct eddsa {
18111814
/**
@@ -1849,10 +1852,9 @@ namespace jwt {
18491852
size_t len = EVP_PKEY_size(pkey.get());
18501853
std::string res(len, '\0');
18511854

1852-
// LibreSSL is the special kid in the block, as it does not support EVP_DigestSign.
1853-
// OpenSSL on the otherhand does not support using EVP_DigestSignUpdate for eddsa, which is why we end up with this
1854-
// mess.
1855-
#if defined(LIBRESSL_VERSION_NUMBER) || defined(LIBWOLFSSL_VERSION_HEX)
1855+
// LibreSSL and OpenSSL, require the oneshot EVP_DigestSign API.
1856+
// wolfSSL uses the Update/Final pattern.
1857+
#if defined(LIBWOLFSSL_VERSION_HEX)
18561858
ERR_clear_error();
18571859
if (EVP_DigestSignUpdate(ctx.get(), reinterpret_cast<const unsigned char*>(data.data()), data.size()) !=
18581860
1) {
@@ -1893,10 +1895,9 @@ namespace jwt {
18931895
ec = error::signature_verification_error::verifyinit_failed;
18941896
return;
18951897
}
1896-
// LibreSSL is the special kid in the block, as it does not support EVP_DigestVerify.
1897-
// OpenSSL on the otherhand does not support using EVP_DigestVerifyUpdate for eddsa, which is why we end up with this
1898-
// mess.
1899-
#if defined(LIBRESSL_VERSION_NUMBER) || defined(LIBWOLFSSL_VERSION_HEX)
1898+
// LibreSSL and OpenSSL, require the oneshot EVP_DigestVerify API.
1899+
// wolfSSL uses the Update/Final pattern.
1900+
#if defined(LIBWOLFSSL_VERSION_HEX)
19001901
if (EVP_DigestVerifyUpdate(ctx.get(), reinterpret_cast<const unsigned char*>(data.data()),
19011902
data.size()) != 1) {
19021903
ec = error::signature_verification_error::verifyupdate_failed;
@@ -2210,7 +2211,7 @@ namespace jwt {
22102211
*
22112212
* https://en.wikipedia.org/wiki/EdDSA#Ed25519
22122213
*
2213-
* Requires at least OpenSSL 1.1.1.
2214+
* Requires at least OpenSSL 1.1.1 or LibreSSL 3.7.1.
22142215
*/
22152216
struct ed25519 : public eddsa {
22162217
/**
@@ -2227,12 +2228,13 @@ namespace jwt {
22272228
: eddsa(public_key, private_key, public_key_password, private_key_password, "EdDSA") {}
22282229
};
22292230

2231+
#if !defined(LIBRESSL_VERSION_NUMBER)
22302232
/**
22312233
* Ed448 algorithm
22322234
*
22332235
* https://en.wikipedia.org/wiki/EdDSA#Ed448
22342236
*
2235-
* Requires at least OpenSSL 1.1.1.
2237+
* Requires at least OpenSSL 1.1.1. Note: Not supported by LibreSSL.
22362238
*/
22372239
struct ed448 : public eddsa {
22382240
/**
@@ -2248,7 +2250,8 @@ namespace jwt {
22482250
const std::string& public_key_password = "", const std::string& private_key_password = "")
22492251
: eddsa(public_key, private_key, public_key_password, private_key_password, "EdDSA") {}
22502252
};
2251-
#endif
2253+
#endif // !LIBRESSL_VERSION_NUMBER
2254+
#endif // !JWT_OPENSSL_1_0_0 && !JWT_OPENSSL_1_1_0
22522255

22532256
/**
22542257
* PS256 algorithm

tests/OpenSSLErrorTest.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,16 +1346,23 @@ TEST(OpenSSLErrorTest, EdDSAKey) {
13461346
}
13471347

13481348
TEST(OpenSSLErrorTest, EdDSACertificate) {
1349-
std::vector<multitest_entry> mapping{// load_public_key_from_string
1350-
{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
1351-
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
1352-
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read},
1353-
// extract_pubkey_from_cert
1354-
{&fail_BIO_new, 2, jwt::error::rsa_error::create_mem_bio_failed},
1355-
{&fail_PEM_read_bio_X509, 1, jwt::error::rsa_error::cert_load_failed},
1356-
{&fail_X509_get_pubkey, 1, jwt::error::rsa_error::get_key_failed},
1357-
{&fail_PEM_write_bio_PUBKEY, 1, jwt::error::rsa_error::write_key_failed},
1358-
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
1349+
std::vector<multitest_entry> mapping {
1350+
// load_public_key_from_string
1351+
{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
1352+
#if !defined(LIBRESSL_VERSION_NUMBER) || LIBRESSL_VERSION_NUMBER < 0x3070100fL // 3.7.1 - EdDSA support
1353+
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
1354+
#else
1355+
{&fail_BIO_write, 1, jwt::error::rsa_error::write_key_failed},
1356+
#endif
1357+
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read},
1358+
// extract_pubkey_from_cert
1359+
{&fail_BIO_new, 2, jwt::error::rsa_error::create_mem_bio_failed},
1360+
{&fail_PEM_read_bio_X509, 1, jwt::error::rsa_error::cert_load_failed},
1361+
{&fail_X509_get_pubkey, 1, jwt::error::rsa_error::get_key_failed},
1362+
{&fail_PEM_write_bio_PUBKEY, 1, jwt::error::rsa_error::write_key_failed}, {
1363+
&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed
1364+
}
1365+
};
13591366

13601367
run_multitest(mapping, [](std::error_code& ec) {
13611368
try {

tests/TokenTest.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ TEST(TokenTest, CreateTokenEd25519) {
279279
jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", "")).verify(decoded));
280280
}
281281

282+
#if !defined(LIBRESSL_VERSION_NUMBER)
282283
TEST(TokenTest, CreateTokenEd448) {
283284

284285
auto token =
@@ -291,7 +292,8 @@ TEST(TokenTest, CreateTokenEd448) {
291292
jwt::error::signature_verification_exception);
292293
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key, "", "", "")).verify(decoded));
293294
}
294-
#endif
295+
#endif // !LIBRESSL_VERSION_NUMBER
296+
#endif // !JWT_OPENSSL_1_0_0 && !JWT_OPENSSL_1_1_0
295297

296298
TEST(TokenTest, VerifyTokenWrongAlgorithm) {
297299
std::string token =
@@ -779,6 +781,7 @@ TEST(TokenTest, VerifyTokenEd25519Fail) {
779781
ASSERT_THROW(verify.verify(decoded_token), jwt::error::signature_verification_exception);
780782
}
781783

784+
#if !defined(LIBRESSL_VERSION_NUMBER)
782785
TEST(TokenTest, VerifyTokenEd448) {
783786
const std::string token =
784787
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
@@ -802,7 +805,8 @@ TEST(TokenTest, VerifyTokenEd448Fail) {
802805

803806
ASSERT_THROW(verify.verify(decoded_token), jwt::error::signature_verification_exception);
804807
}
805-
#endif
808+
#endif // !LIBRESSL_VERSION_NUMBER
809+
#endif // !JWT_OPENSSL_1_0_0 && !JWT_OPENSSL_1_1_0
806810

807811
struct test_clock {
808812
jwt::date n;

0 commit comments

Comments
 (0)