diff --git a/.github/workflows/ssl.yml b/.github/workflows/ssl.yml index 47eaf7c..c9ff72f 100644 --- a/.github/workflows/ssl.yml +++ b/.github/workflows/ssl.yml @@ -47,6 +47,21 @@ jobs: label: ${{ matrix.openssl.name }} github_token: ${{ secrets.GITHUB_TOKEN }} + openssl-no-deprecated: + runs-on: ubuntu-latest + name: OpenSSL 3.0 No Deprecated + steps: + - uses: actions/checkout@v2 + - uses: lukka/get-cmake@latest + - uses: ./.github/actions/install/gtest + - uses: ./.github/actions/install/openssl + with: + version: "openssl-3.0.0" + + - name: configure + 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" + - run: make + libressl: runs-on: ubuntu-latest strategy: diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index 6f23f60..b260e79 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -146,7 +146,8 @@ namespace jwt { create_mem_bio_failed, no_key_provided, invalid_key_size, - invalid_key + invalid_key, + create_context_failed }; /** * \brief Error category for ECDSA errors @@ -165,6 +166,7 @@ namespace jwt { return "at least one of public or private key need to be present"; case ecdsa_error::invalid_key_size: return "invalid key size"; case ecdsa_error::invalid_key: return "invalid key"; + case ecdsa_error::create_context_failed: return "failed to create context"; default: return "unknown ECDSA error"; } } @@ -186,7 +188,8 @@ namespace jwt { verifyupdate_failed, verifyfinal_failed, get_key_failed, - set_rsa_pss_saltlen_failed + set_rsa_pss_saltlen_failed, + signature_encoding_failed }; /** * \brief Error category for verification errors @@ -211,6 +214,8 @@ namespace jwt { return "failed to verify signature: Could not get key"; case signature_verification_error::set_rsa_pss_saltlen_failed: return "failed to verify signature: EVP_PKEY_CTX_set_rsa_pss_saltlen failed"; + case signature_verification_error::signature_encoding_failed: + return "failed to verify signature: i2d_ECDSA_SIG failed"; default: return "unknown signature verification error"; } } @@ -241,6 +246,7 @@ namespace jwt { rsa_private_encrypt_failed, get_key_failed, set_rsa_pss_saltlen_failed, + signature_decoding_failed }; /** * \brief Error category for signature generation errors @@ -276,6 +282,8 @@ namespace jwt { return "failed to generate signature: Could not get key"; case signature_generation_error::set_rsa_pss_saltlen_failed: return "failed to create signature: EVP_PKEY_CTX_set_rsa_pss_saltlen failed"; + case signature_generation_error::signature_decoding_failed: + return "failed to create signature: d2i_ECDSA_SIG failed"; default: return "unknown signature generation error"; } } @@ -995,21 +1003,21 @@ namespace jwt { const std::string& private_key_password, const EVP_MD* (*md)(), std::string name, size_t siglen) : md(md), alg_name(std::move(name)), signature_length(siglen) { if (!private_key.empty()) { - auto epkey = helper::load_private_ec_key_from_string(private_key, private_key_password); - pkey.reset(EVP_PKEY_get1_EC_KEY(epkey.get()), EC_KEY_free); + pkey = helper::load_private_ec_key_from_string(private_key, private_key_password); + check_private_key(pkey.get()); } else if (!public_key.empty()) { - auto epkey = helper::load_public_ec_key_from_string(public_key, public_key_password); - pkey.reset(EVP_PKEY_get1_EC_KEY(epkey.get()), EC_KEY_free); + pkey = helper::load_public_ec_key_from_string(public_key, public_key_password); + check_public_key(pkey.get()); } else { throw ecdsa_exception(error::ecdsa_error::no_key_provided); } if (!pkey) throw ecdsa_exception(error::ecdsa_error::invalid_key); - size_t keysize = EC_GROUP_get_degree(EC_KEY_get0_group(pkey.get())); + + size_t keysize = EVP_PKEY_bits(pkey.get()); if (keysize != signature_length * 4 && (signature_length != 132 || keysize != 521)) throw ecdsa_exception(error::ecdsa_error::invalid_key_size); - - if (EC_KEY_check_key(pkey.get()) == 0) throw ecdsa_exception(error::ecdsa_error::invalid_key); } + /** * Sign jwt data * \param data The data to sign @@ -1018,17 +1026,122 @@ namespace jwt { */ std::string sign(const std::string& data, std::error_code& ec) const { ec.clear(); - const std::string hash = generate_hash(data, ec); - if (ec) return {}; - - std::unique_ptr sig( - ECDSA_do_sign(reinterpret_cast(hash.data()), static_cast(hash.size()), - pkey.get()), - ECDSA_SIG_free); - if (!sig) { - ec = error::signature_generation_error::ecdsa_do_sign_failed; +#ifdef JWT_OPENSSL_1_0_0 + std::unique_ptr ctx(EVP_MD_CTX_create(), EVP_MD_CTX_destroy); +#else + std::unique_ptr ctx(EVP_MD_CTX_create(), EVP_MD_CTX_free); +#endif + if (!ctx) { + ec = error::signature_generation_error::create_context_failed; return {}; } + if (!EVP_DigestSignInit(ctx.get(), nullptr, md(), nullptr, pkey.get())) { + ec = error::signature_generation_error::signinit_failed; + return {}; + } + if (!EVP_DigestUpdate(ctx.get(), data.data(), data.size())) { + ec = error::signature_generation_error::digestupdate_failed; + return {}; + } + + size_t len = 0; + if (!EVP_DigestSignFinal(ctx.get(), nullptr, &len)) { + ec = error::signature_generation_error::signfinal_failed; + return {}; + } + std::string res(len, '\0'); + if (!EVP_DigestSignFinal(ctx.get(), (unsigned char*)res.data(), &len)) { + ec = error::signature_generation_error::signfinal_failed; + return {}; + } + + res.resize(len); + return der_to_p1363_signature(res, ec); + } + + /** + * Check if signature is valid + * \param data The data to check signature against + * \param signature Signature provided by the jwt + * \param ec Filled with details on error + */ + void verify(const std::string& data, const std::string& signature, std::error_code& ec) const { + ec.clear(); + std::string der_signature = p1363_to_der_signature(signature, ec); + if (ec) { return; } + +#ifdef JWT_OPENSSL_1_0_0 + std::unique_ptr ctx(EVP_MD_CTX_create(), EVP_MD_CTX_destroy); +#else + std::unique_ptr ctx(EVP_MD_CTX_create(), EVP_MD_CTX_free); +#endif + if (!ctx) { + ec = error::signature_verification_error::create_context_failed; + return; + } + if (!EVP_DigestVerifyInit(ctx.get(), nullptr, md(), nullptr, pkey.get())) { + ec = error::signature_verification_error::verifyinit_failed; + return; + } + if (!EVP_DigestUpdate(ctx.get(), data.data(), data.size())) { + ec = error::signature_verification_error::verifyupdate_failed; + return; + } + + auto res = + EVP_DigestVerifyFinal(ctx.get(), reinterpret_cast(der_signature.data()), + static_cast(der_signature.length())); + if (res == 0) { + ec = error::signature_verification_error::invalid_signature; + return; + } + if (res == -1) { + ec = error::signature_verification_error::verifyfinal_failed; + return; + } + } + /** + * Returns the algorithm name provided to the constructor + * \return algorithm's name + */ + std::string name() const { return alg_name; } + + private: + static void check_public_key(EVP_PKEY* pkey) { +#ifdef JWT_OPENSSL_3_0 + std::unique_ptr ctx( + EVP_PKEY_CTX_new_from_pkey(nullptr, pkey, nullptr), EVP_PKEY_CTX_free); + if (!ctx) { throw ecdsa_exception(error::ecdsa_error::create_context_failed); } + if (EVP_PKEY_public_check(ctx.get()) != 1) { throw ecdsa_exception(error::ecdsa_error::invalid_key); } +#else + std::unique_ptr eckey(EVP_PKEY_get1_EC_KEY(pkey), EC_KEY_free); + if (!eckey) { throw ecdsa_exception(error::ecdsa_error::invalid_key); } + if (EC_KEY_check_key(eckey.get()) == 0) throw ecdsa_exception(error::ecdsa_error::invalid_key); +#endif + } + + static void check_private_key(EVP_PKEY* pkey) { +#ifdef JWT_OPENSSL_3_0 + std::unique_ptr ctx( + EVP_PKEY_CTX_new_from_pkey(nullptr, pkey, nullptr), EVP_PKEY_CTX_free); + if (!ctx) { throw ecdsa_exception(error::ecdsa_error::create_context_failed); } + if (EVP_PKEY_private_check(ctx.get()) != 1) { throw ecdsa_exception(error::ecdsa_error::invalid_key); } +#else + std::unique_ptr eckey(EVP_PKEY_get1_EC_KEY(pkey), EC_KEY_free); + if (!eckey) { throw ecdsa_exception(error::ecdsa_error::invalid_key); } + if (EC_KEY_check_key(eckey.get()) == 0) throw ecdsa_exception(error::ecdsa_error::invalid_key); +#endif + } + + std::string der_to_p1363_signature(const std::string& der_signature, std::error_code& ec) const { + const unsigned char* possl_signature = reinterpret_cast(der_signature.data()); + std::unique_ptr sig( + d2i_ECDSA_SIG(nullptr, &possl_signature, der_signature.length()), ECDSA_SIG_free); + if (!sig) { + ec = error::signature_generation_error::signature_decoding_failed; + return {}; + } + #ifdef JWT_OPENSSL_1_0_0 auto rr = helper::bn2raw(sig->r); @@ -1047,91 +1160,45 @@ namespace jwt { return rr + rs; } - /** - * Check if signature is valid - * \param data The data to check signature against - * \param signature Signature provided by the jwt - * \param ec Filled with details on error - */ - void verify(const std::string& data, const std::string& signature, std::error_code& ec) const { + std::string p1363_to_der_signature(const std::string& signature, std::error_code& ec) const { ec.clear(); - const std::string hash = generate_hash(data, ec); - if (ec) return; auto r = helper::raw2bn(signature.substr(0, signature.size() / 2)); auto s = helper::raw2bn(signature.substr(signature.size() / 2)); + ECDSA_SIG* psig; #ifdef JWT_OPENSSL_1_0_0 ECDSA_SIG sig; sig.r = r.get(); sig.s = s.get(); - - if (ECDSA_do_verify((const unsigned char*)hash.data(), static_cast(hash.size()), &sig, - pkey.get()) != 1) { - ec = error::signature_verification_error::invalid_signature; - return; - } + psig = &sig; #else std::unique_ptr sig(ECDSA_SIG_new(), ECDSA_SIG_free); if (!sig) { ec = error::signature_verification_error::create_context_failed; - return; + return {}; } - ECDSA_SIG_set0(sig.get(), r.release(), s.release()); - - if (ECDSA_do_verify(reinterpret_cast(hash.data()), static_cast(hash.size()), - sig.get(), pkey.get()) != 1) { - ec = error::signature_verification_error::invalid_signature; - return; - } + psig = sig.get(); #endif - } - /** - * Returns the algorithm name provided to the constructor - * \return algorithm's name - */ - std::string name() const { return alg_name; } - private: - /** - * Hash the provided data using the hash function specified in constructor - * \param data Data to hash - * \return Hash of data - */ - std::string generate_hash(const std::string& data, std::error_code& ec) const { -#ifdef JWT_OPENSSL_1_0_0 - std::unique_ptr ctx(EVP_MD_CTX_create(), - &EVP_MD_CTX_destroy); -#else - std::unique_ptr ctx(EVP_MD_CTX_new(), EVP_MD_CTX_free); -#endif - if (!ctx) { - ec = error::signature_generation_error::create_context_failed; + int length = i2d_ECDSA_SIG(psig, nullptr); + if (length < 0) { + ec = error::signature_verification_error::signature_encoding_failed; return {}; } - if (EVP_DigestInit(ctx.get(), md()) == 0) { - ec = error::signature_generation_error::digestinit_failed; + std::string der_signature(length, '\0'); + unsigned char* psbuffer = (unsigned char*)der_signature.data(); + length = i2d_ECDSA_SIG(psig, &psbuffer); + if (length < 0) { + ec = error::signature_verification_error::signature_encoding_failed; return {}; } - if (EVP_DigestUpdate(ctx.get(), data.data(), data.size()) == 0) { - ec = error::signature_generation_error::digestupdate_failed; - return {}; - } - unsigned int len = 0; - std::string res(EVP_MD_CTX_size(ctx.get()), '\0'); - if (EVP_DigestFinal( - ctx.get(), - (unsigned char*)res.data(), // NOLINT(google-readability-casting) requires `const_cast` - &len) == 0) { - ec = error::signature_generation_error::digestfinal_failed; - return {}; - } - res.resize(len); - return res; + der_signature.resize(length); + return der_signature; } /// OpenSSL struct containing keys - std::shared_ptr pkey; + std::shared_ptr pkey; /// Hash generator function const EVP_MD* (*md)(); /// algorithm's name diff --git a/tests/HelperTest.cpp b/tests/HelperTest.cpp index 33029f2..c4ad6c4 100644 --- a/tests/HelperTest.cpp +++ b/tests/HelperTest.cpp @@ -52,21 +52,21 @@ TEST(HelperTest, ErrorCodeMessages) { ASSERT_EQ(std::error_code(static_cast(i)).message(), std::error_code(static_cast(-1)).message()); - for (i = 10; i < 16; i++) { + for (i = 10; i < 17; i++) { ASSERT_NE(std::error_code(static_cast(i)).message(), std::error_code(static_cast(-1)).message()); } ASSERT_EQ(std::error_code(static_cast(i)).message(), std::error_code(static_cast(-1)).message()); - for (i = 10; i < 17; i++) { + for (i = 10; i < 18; i++) { ASSERT_NE(std::error_code(static_cast(i)).message(), std::error_code(static_cast(-1)).message()); } ASSERT_EQ(std::error_code(static_cast(i)).message(), std::error_code(static_cast(-1)).message()); - for (i = 10; i < 23; i++) { + for (i = 10; i < 24; i++) { ASSERT_NE(std::error_code(static_cast(i)).message(), std::error_code(static_cast(-1)).message()); } diff --git a/tests/OpenSSLErrorTest.cpp b/tests/OpenSSLErrorTest.cpp index 3b02d59..356a153 100644 --- a/tests/OpenSSLErrorTest.cpp +++ b/tests/OpenSSLErrorTest.cpp @@ -34,7 +34,14 @@ static uint64_t fail_EVP_DigestUpdate = 0; static uint64_t fail_EVP_DigestFinal = 0; static uint64_t fail_EVP_SignFinal = 0; static uint64_t fail_EVP_VerifyFinal = 0; +#ifdef JWT_OPENSSL_3_0 +static uint64_t fail_EVP_PKEY_public_check = 0; +static uint64_t fail_EVP_PKEY_private_check = 0; +static uint64_t fail_EVP_PKEY_CTX_new_from_pkey = 0; +#else static uint64_t fail_EC_KEY_check_key = 0; +static uint64_t fail_EVP_PKEY_get1_EC_KEY = 0; +#endif static uint64_t fail_ECDSA_SIG_new = 0; static uint64_t fail_ECDSA_do_sign = 0; static uint64_t fail_EVP_PKEY_get1_RSA = 0; @@ -42,9 +49,10 @@ static uint64_t fail_EVP_DigestSignInit = 0; static uint64_t fail_EVP_DigestSign = 0; static uint64_t fail_EVP_DigestVerifyInit = 0; static uint64_t fail_EVP_DigestVerify = 0; -static uint64_t fail_EVP_PKEY_get1_EC_KEY = 0; static uint64_t fail_EVP_DigestSignFinal = 0; static uint64_t fail_EVP_DigestVerifyFinal = 0; +static uint64_t fail_d2i_ECDSA_SIG = 0; +static uint64_t fail_i2d_ECDSA_SIG = 0; BIO* BIO_new(const BIO_METHOD* type) { static BIO* (*origMethod)(const BIO_METHOD*) = nullptr; @@ -264,6 +272,41 @@ int EVP_VerifyFinal(EVP_MD_CTX* ctx, const unsigned char* sigbuf, unsigned int s return origMethod(ctx, sigbuf, siglen, pkey); } +#ifdef JWT_OPENSSL_3_0 +int EVP_PKEY_public_check(EVP_PKEY_CTX* ctx) { + static int (*origMethod)(EVP_PKEY_CTX * ctx) = nullptr; + if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_public_check"); + bool fail = fail_EVP_PKEY_public_check & 1; + fail_EVP_PKEY_public_check = fail_EVP_PKEY_public_check >> 1; + if (fail) + return 0; + else + return origMethod(ctx); +} + +int EVP_PKEY_private_check(EVP_PKEY_CTX* ctx) { + static int (*origMethod)(EVP_PKEY_CTX * ctx) = nullptr; + if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_private_check"); + bool fail = fail_EVP_PKEY_private_check & 1; + fail_EVP_PKEY_private_check = fail_EVP_PKEY_private_check >> 1; + if (fail) + return 0; + else + return origMethod(ctx); +} + +EVP_PKEY_CTX* EVP_PKEY_CTX_new_from_pkey(OSSL_LIB_CTX* libctx, EVP_PKEY* pkey, const char* propquery) { + static EVP_PKEY_CTX* (*origMethod)(OSSL_LIB_CTX * libctx, EVP_PKEY * pkey, const char* propquery) = nullptr; + if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_CTX_new_from_pkey"); + bool fail = fail_EVP_PKEY_CTX_new_from_pkey & 1; + fail_EVP_PKEY_CTX_new_from_pkey = fail_EVP_PKEY_CTX_new_from_pkey >> 1; + if (fail) + return nullptr; + else + return origMethod(libctx, pkey, propquery); +} + +#else int EC_KEY_check_key(const EC_KEY* key) { static int (*origMethod)(const EC_KEY* key) = nullptr; if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EC_KEY_check_key"); @@ -275,6 +318,18 @@ int EC_KEY_check_key(const EC_KEY* key) { return origMethod(key); } +EC_KEY* EVP_PKEY_get1_EC_KEY(EVP_PKEY* pkey) { + static EC_KEY* (*origMethod)(EVP_PKEY * pkey) = nullptr; + if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_get1_EC_KEY"); + bool fail = fail_EVP_PKEY_get1_EC_KEY & 1; + fail_EVP_PKEY_get1_EC_KEY = fail_EVP_PKEY_get1_EC_KEY >> 1; + if (fail) + return nullptr; + else + return origMethod(pkey); +} +#endif + ECDSA_SIG* ECDSA_SIG_new(void) { static ECDSA_SIG* (*origMethod)() = nullptr; if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "ECDSA_SIG_new"); @@ -356,17 +411,6 @@ int EVP_DigestVerify(EVP_MD_CTX* ctx, unsigned char* sigret, size_t* siglen, con return origMethod(ctx, sigret, siglen, tbs, tbslen); } -EC_KEY* EVP_PKEY_get1_EC_KEY(EVP_PKEY* pkey) { - static EC_KEY* (*origMethod)(EVP_PKEY * pkey) = nullptr; - if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_get1_EC_KEY"); - bool fail = fail_EVP_PKEY_get1_EC_KEY & 1; - fail_EVP_PKEY_get1_EC_KEY = fail_EVP_PKEY_get1_EC_KEY >> 1; - if (fail) - return nullptr; - else - return origMethod(pkey); -} - int EVP_DigestVerifyFinal(EVP_MD_CTX* ctx, const unsigned char* sigret, size_t siglen) { static int (*origMethod)(EVP_MD_CTX * ctx, const unsigned char* sigret, size_t siglen) = nullptr; if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestVerifyFinal"); @@ -378,6 +422,28 @@ int EVP_DigestVerifyFinal(EVP_MD_CTX* ctx, const unsigned char* sigret, size_t s return origMethod(ctx, sigret, siglen); } +int i2d_ECDSA_SIG(const ECDSA_SIG* sig, unsigned char** ppout) { + static int (*origMethod)(const ECDSA_SIG* sig, unsigned char** ppout) = nullptr; + if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "i2d_ECDSA_SIG"); + bool fail = fail_i2d_ECDSA_SIG & 1; + fail_i2d_ECDSA_SIG = fail_i2d_ECDSA_SIG >> 1; + if (fail) + return -1; + else + return origMethod(sig, ppout); +} + +ECDSA_SIG* d2i_ECDSA_SIG(ECDSA_SIG** psig, const unsigned char** ppin, long len) { + static ECDSA_SIG* (*origMethod)(ECDSA_SIG * *psig, const unsigned char** ppin, long len) = nullptr; + if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "d2i_ECDSA_SIG"); + bool fail = fail_d2i_ECDSA_SIG & 1; + fail_d2i_ECDSA_SIG = fail_d2i_ECDSA_SIG >> 1; + if (fail) + return nullptr; + else + return origMethod(psig, ppin, len); +} + /** * =========== End of black magic ============ */ @@ -650,8 +716,13 @@ TEST(OpenSSLErrorTest, LoadECDSAPrivateKeyFromString) { {&fail_BIO_new, 1, jwt::error::ecdsa_error::create_mem_bio_failed}, {&fail_BIO_write, 1, jwt::error::ecdsa_error::load_key_bio_write}, {&fail_PEM_read_bio_PrivateKey, 1, jwt::error::ecdsa_error::load_key_bio_read}, +#ifdef JWT_OPENSSL_3_0 + {&fail_EVP_PKEY_private_check, 1, jwt::error::ecdsa_error::invalid_key}, + {&fail_EVP_PKEY_CTX_new_from_pkey, 1, jwt::error::ecdsa_error::create_context_failed}, +#else {&fail_EC_KEY_check_key, 1, jwt::error::ecdsa_error::invalid_key}, {&fail_EVP_PKEY_get1_EC_KEY, 1, jwt::error::ecdsa_error::invalid_key}, +#endif }; run_multitest(mapping, [](std::error_code& ec) { @@ -667,8 +738,13 @@ TEST(OpenSSLErrorTest, LoadECDSAPublicKeyFromString) { {&fail_BIO_new, 1, jwt::error::ecdsa_error::create_mem_bio_failed}, {&fail_BIO_write, 1, jwt::error::ecdsa_error::load_key_bio_write}, {&fail_PEM_read_bio_PUBKEY, 1, jwt::error::ecdsa_error::load_key_bio_read}, +#ifdef JWT_OPENSSL_3_0 + {&fail_EVP_PKEY_public_check, 1, jwt::error::ecdsa_error::invalid_key}, + {&fail_EVP_PKEY_CTX_new_from_pkey, 1, jwt::error::ecdsa_error::create_context_failed}, +#else {&fail_EC_KEY_check_key, 1, jwt::error::ecdsa_error::invalid_key}, {&fail_EVP_PKEY_get1_EC_KEY, 1, jwt::error::ecdsa_error::invalid_key}, +#endif }; run_multitest(mapping, [](std::error_code& ec) { @@ -712,10 +788,12 @@ TEST(OpenSSLErrorTest, ES256SignErrorCode) { jwt::algorithm::es256 alg{ecdsa256_pub_key, ecdsa256_priv_key}; std::vector mapping{ {&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed}, - {&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::digestinit_failed}, + {&fail_EVP_DigestSignInit, 1, jwt::error::signature_generation_error::signinit_failed}, {&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed}, - {&fail_EVP_DigestFinal, 1, jwt::error::signature_generation_error::digestfinal_failed}, - {&fail_ECDSA_do_sign, 1, jwt::error::signature_generation_error::ecdsa_do_sign_failed}}; + {&fail_EVP_DigestSignFinal, 1, jwt::error::signature_generation_error::signfinal_failed}, + {&fail_EVP_DigestSignFinal, 2, jwt::error::signature_generation_error::signfinal_failed}, + {&fail_d2i_ECDSA_SIG, 1, jwt::error::signature_generation_error::signature_decoding_failed}, + }; run_multitest(mapping, [&alg](std::error_code& ec) { auto res = alg.sign("testdata", ec); @@ -728,11 +806,13 @@ TEST(OpenSSLErrorTest, ES256VerifyErrorCode) { auto signature = jwt::base::decode( "aC/NqyHfPw5FDA0yRAnrbkrAlXjsr0obRkCg/HgP+77QYJrAg6YKkKoJwMXjUX8fQrxXKTN7em5L9dtmOep37Q=="); std::vector mapping{ - {&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed}, - {&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::digestinit_failed}, - {&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed}, - {&fail_EVP_DigestFinal, 1, jwt::error::signature_generation_error::digestfinal_failed}, + {&fail_EVP_MD_CTX_new, 1, jwt::error::signature_verification_error::create_context_failed}, + {&fail_EVP_DigestVerifyInit, 1, jwt::error::signature_verification_error::verifyinit_failed}, + {&fail_EVP_DigestUpdate, 1, jwt::error::signature_verification_error::verifyupdate_failed}, + {&fail_EVP_DigestVerifyFinal, 1, jwt::error::signature_verification_error::invalid_signature}, {&fail_ECDSA_SIG_new, 1, jwt::error::signature_verification_error::create_context_failed}, + {&fail_i2d_ECDSA_SIG, 1, jwt::error::signature_verification_error::signature_encoding_failed}, + {&fail_i2d_ECDSA_SIG, 2, jwt::error::signature_verification_error::signature_encoding_failed}, }; run_multitest(mapping, [&alg, &signature](std::error_code& ec) { alg.verify("testdata", signature, ec); });