Skip to content

Commit d7e0936

Browse files
🔧 Fix build with OPENSSL_NO_DEPRECATED (#228)
* Add missing include to fix build with OPENSSL_NO_DEPRECATED Creating and verifying RSA signatures requires some OpenSSL functions declared in the `openssl/rsa.h` header. When `OPENSSL_NO_DEPRECATED` is not defined this header gets indirectly included. But with this define set the function declarations are missing. This commit adds an explicit include for the file to fix this. * Remove unused functions in OpenSSLErrorTest Some functions from OpenSSL redefined in `OpenSSLErrorTest.cpp` use types that are not available when `OPENSSL_NO_DEPRECATED` is defined. Since they do not seem to be actually used this commit simply removes them. * Test with OPENSSL_NO_DEPRECATED Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
1 parent 0c810e2 commit d7e0936

File tree

3 files changed

+2
-37
lines changed

3 files changed

+2
-37
lines changed

.github/workflows/ssl.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
version: "openssl-3.0.1"
5151

5252
- name: configure
53-
run: cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp -DCMAKE_CXX_FLAGS="-DOPENSSL_NO_DEPRECATED_3_0=1" -DCMAKE_C_FLAGS="-DOPENSSL_NO_DEPRECATED_3_0=1"
53+
run: cmake . -DJWT_BUILD_TESTS=ON -DOPENSSL_ROOT_DIR=/tmp -DCMAKE_CXX_FLAGS="-DOPENSSL_NO_DEPRECATED=1" -DCMAKE_C_FLAGS="-DOPENSSL_NO_DEPRECATED=1"
5454
- run: make
5555

5656
libressl:

include/jwt-cpp/jwt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <openssl/evp.h>
1919
#include <openssl/hmac.h>
2020
#include <openssl/pem.h>
21+
#include <openssl/rsa.h>
2122
#include <openssl/ssl.h>
2223

2324
#include <algorithm>

tests/OpenSSLErrorTest.cpp

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ static uint64_t fail_BIO_ctrl = 0;
2525
static uint64_t fail_BIO_write = 0;
2626
static uint64_t fail_PEM_read_bio_PUBKEY = 0;
2727
static uint64_t fail_PEM_read_bio_PrivateKey = 0;
28-
static uint64_t fail_PEM_read_bio_EC_PUBKEY = 0;
29-
static uint64_t fail_PEM_read_bio_ECPrivateKey = 0;
3028
static uint64_t fail_HMAC = 0;
3129
static uint64_t fail_EVP_MD_CTX_new = 0;
3230
static uint64_t fail_EVP_DigestInit = 0;
@@ -43,7 +41,6 @@ static uint64_t fail_EC_KEY_check_key = 0;
4341
static uint64_t fail_EVP_PKEY_get1_EC_KEY = 0;
4442
#endif
4543
static uint64_t fail_ECDSA_SIG_new = 0;
46-
static uint64_t fail_ECDSA_do_sign = 0;
4744
static uint64_t fail_EVP_PKEY_get1_RSA = 0;
4845
static uint64_t fail_EVP_DigestSignInit = 0;
4946
static uint64_t fail_EVP_DigestSign = 0;
@@ -159,28 +156,6 @@ EVP_PKEY* PEM_read_bio_PrivateKey(BIO* bp, EVP_PKEY** x, pem_password_cb* cb, vo
159156
return origMethod(bp, x, cb, u);
160157
}
161158

162-
EC_KEY* PEM_read_bio_EC_PUBKEY(BIO* bp, EC_KEY** x, pem_password_cb* cb, void* u) {
163-
static EC_KEY* (*origMethod)(BIO * bp, EC_KEY * *x, pem_password_cb * cb, void* u) = nullptr;
164-
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_EC_PUBKEY");
165-
bool fail = fail_PEM_read_bio_EC_PUBKEY & 1;
166-
fail_PEM_read_bio_EC_PUBKEY = fail_PEM_read_bio_EC_PUBKEY >> 1;
167-
if (fail)
168-
return nullptr;
169-
else
170-
return origMethod(bp, x, cb, u);
171-
}
172-
173-
EC_KEY* PEM_read_bio_ECPrivateKey(BIO* bp, EC_KEY** x, pem_password_cb* cb, void* u) {
174-
static EC_KEY* (*origMethod)(BIO * bp, EC_KEY * *x, pem_password_cb * cb, void* u) = nullptr;
175-
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_ECPrivateKey");
176-
bool fail = fail_PEM_read_bio_ECPrivateKey & 1;
177-
fail_PEM_read_bio_ECPrivateKey = fail_PEM_read_bio_ECPrivateKey >> 1;
178-
if (fail)
179-
return nullptr;
180-
else
181-
return origMethod(bp, x, cb, u);
182-
}
183-
184159
unsigned char* HMAC(const EVP_MD* evp_md, const void* key, int key_len, const unsigned char* d, size_t n,
185160
unsigned char* md, unsigned int* md_len) {
186161
static unsigned char* (*origMethod)(const EVP_MD* evp_md, const void* key, int key_len, const unsigned char* d,
@@ -341,17 +316,6 @@ ECDSA_SIG* ECDSA_SIG_new(void) {
341316
return origMethod();
342317
}
343318

344-
ECDSA_SIG* ECDSA_do_sign(const unsigned char* dgst, int dgst_len, EC_KEY* eckey) {
345-
static ECDSA_SIG* (*origMethod)(const unsigned char* dgst, int dgst_len, EC_KEY* eckey) = nullptr;
346-
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "ECDSA_do_sign");
347-
bool fail = fail_ECDSA_do_sign & 1;
348-
fail_ECDSA_do_sign = fail_ECDSA_do_sign >> 1;
349-
if (fail)
350-
return nullptr;
351-
else
352-
return origMethod(dgst, dgst_len, eckey);
353-
}
354-
355319
struct rsa_st* EVP_PKEY_get1_RSA(EVP_PKEY* pkey) {
356320
static struct rsa_st* (*origMethod)(EVP_PKEY * pkey) = nullptr;
357321
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_get1_RSA");

0 commit comments

Comments
 (0)