Skip to content

Commit 3877768

Browse files
committed
Avoid explicitly initializing OpenSSL in verifySignature()
This is no longer required in recent OpenSSL versions and thus better left out considering the related functions are deprecated and corresponding cleanup was missing.
1 parent 0ee3363 commit 3877768

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,14 @@ if (USE_PLATFORM_SPECIFIC_API_FOR_OPTIMIZING_COPY_HELPER)
260260
endif ()
261261

262262
# configure tests for verification helpers which require OpenSSL
263-
use_crypto(LIBRARIES_VARIABLE "TEST_LIBRARIES" PACKAGES_VARIABLE "TEST_PACKAGES" OPTIONAL)
263+
use_crypto(
264+
LIBRARIES_VARIABLE
265+
"TEST_LIBRARIES"
266+
PACKAGES_VARIABLE
267+
"TEST_PACKAGES"
268+
PACKAGE_ARGS
269+
1.1.0
270+
OPTIONAL)
264271
if ("OpenSSL::Crypto" IN_LIST "TEST_LIBRARIES")
265272
message(STATUS "Testing verification using OpenSSL crypto library")
266273
set_property(

misc/verification.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@
1717
namespace CppUtilities {
1818

1919
namespace Detail {
20-
/// \brief Initializes OpenSSL.
21-
/// \remarks This function is an implementation detail and must not be called by users this library.
22-
inline void initOpenSsl()
23-
{
24-
ERR_load_crypto_strings();
25-
OpenSSL_add_all_algorithms();
26-
}
27-
2820
/// \brief Returns the current OpenSSL error.
2921
/// \remarks This function is an implementation detail and must not be called by users this library.
3022
inline std::string getOpenSslError()
@@ -83,7 +75,10 @@ inline std::string parsePemSignature(std::string_view pemSignature, std::pair<st
8375
* \remarks
8476
* - The digest algorithm is assumed to be SHA256.
8577
* - The key and signature must both be provided in PEM format.
86-
* - This function requires linking with the OpenSSL crypto library and will initialize OpenSSL.
78+
* - This function requires linking with the OpenSSL crypto library. It will *not* initialize the OpenSSL crypto library
79+
* explicitly assuming OpenSSL version 1.1.0 or higher is used (which no longer requires explicit initialization). If
80+
* you are using an older version of OpenSSL you may need to call ERR_load_crypto_strings() and OpenSSL_add_all_algorithms()
81+
* before invoking this function.
8782
* - This function is experimental and might be changed in incompatible ways (API and ABI wise) or be completely removed
8883
* in further minor/patch releases.
8984
*
@@ -109,7 +104,6 @@ inline std::string parsePemSignature(std::string_view pemSignature, std::pair<st
109104
inline std::string verifySignature(std::string_view publicKeyPem, std::string_view signaturePem, std::string_view data)
110105
{
111106
auto error = std::string();
112-
Detail::initOpenSsl();
113107

114108
auto derSignature = std::pair<std::unique_ptr<std::uint8_t[]>, std::uint32_t>();
115109
if (error = Detail::parsePemSignature(signaturePem, derSignature); !error.empty()) {

0 commit comments

Comments
 (0)