Skip to content

Commit a88a0f2

Browse files
Always require OpenSSL (#1548)
OpenSSL is now required, and should be always present, hence OLP_SDK_NETWORK_HAS_OPENSSL could be removed Relates-To: HERESUP-1440 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent ff3d282 commit a88a0f2

4 files changed

Lines changed: 16 additions & 32 deletions

File tree

olp-cpp-sdk-core/cmake/curl.cmake

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,20 +33,13 @@ if(CURL_FOUND AND NOT NETWORK_NO_CURL)
3333
endif()
3434

3535
if(NOT OPENSSL_FOUND)
36-
if(ANDROID AND OLP_SDK_ENABLE_ANDROID_CURL)
37-
find_package(OpenSSL REQUIRED)
38-
else()
39-
find_package(OpenSSL)
40-
endif()
36+
# Enforcing OpenSSL to make sure that it is available
37+
find_package(OpenSSL REQUIRED)
4138
endif()
4239

43-
if(OPENSSL_FOUND)
44-
add_definitions(-DOLP_SDK_NETWORK_HAS_OPENSSL)
45-
46-
if(ANDROID AND OLP_SDK_ENABLE_ANDROID_CURL)
47-
include_directories(${OPENSSL_INCLUDE_DIR})
48-
set(OLP_SDK_NETWORK_CURL_LIBRARIES ${OLP_SDK_NETWORK_CURL_LIBRARIES} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
49-
endif()
40+
if(OPENSSL_FOUND AND ANDROID AND OLP_SDK_ENABLE_ANDROID_CURL)
41+
include_directories(${OPENSSL_INCLUDE_DIR})
42+
set(OLP_SDK_NETWORK_CURL_LIBRARIES ${OLP_SDK_NETWORK_CURL_LIBRARIES} ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY})
5043
endif()
5144

5245
option(OLP_SDK_ENABLE_CURL_VERBOSE "Enable support for CURL_VERBOSE environment variable to set libcurl to verbose mode" OFF)

olp-cpp-sdk-core/src/http/curl/NetworkCurl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#include <openssl/x509_vfy.h>
3939
#include <sys/stat.h>
4040
#include <cstdio>
41-
#elif OLP_SDK_NETWORK_HAS_OPENSSL
41+
#else
4242
#include "olp/core/utils/Dir.h"
4343
#endif
4444

@@ -112,19 +112,14 @@ int Md5LookupGetBySubject(X509_LOOKUP* ctx, X509_LOOKUP_TYPE type,
112112
}
113113
#endif
114114

115-
#elif OLP_SDK_NETWORK_HAS_OPENSSL
115+
#else
116116
const auto kCurlCaBundleName = "ca-bundle.crt";
117117

118118
std::string DefaultCaBundlePath() { return kCurlCaBundleName; }
119119

120-
std::string AlternativeCaBundlePath() { return kCurlCaBundleName; }
121-
122120
std::string CaBundlePath() {
123121
std::string bundle_path;
124122
bundle_path = DefaultCaBundlePath();
125-
if (!olp::utils::Dir::FileExists(bundle_path)) {
126-
bundle_path = AlternativeCaBundlePath();
127-
}
128123
if (!olp::utils::Dir::FileExists(bundle_path)) {
129124
bundle_path.clear();
130125
}
@@ -258,7 +253,7 @@ CURLcode SetCaBundlePaths(CURL* handle) {
258253
// (probably all of them) since OpenSSL still will be trying to find
259254
// certificate with SHA1 lookup
260255
return curl_easy_setopt(handle, CURLOPT_CAPATH, kCurlAndroidCaBundleFolder);
261-
#elif OLP_SDK_NETWORK_HAS_OPENSSL
256+
#else
262257
const auto curl_ca_bundle = CaBundlePath();
263258
if (!curl_ca_bundle.empty()) {
264259
return curl_easy_setopt(handle, CURLOPT_CAINFO, curl_ca_bundle.c_str());
@@ -321,10 +316,11 @@ NetworkCurl::NetworkCurl(NetworkInitializationSettings settings)
321316
LIBCURL_VERSION);
322317
#endif
323318

319+
const auto* version_data = curl_version_info(CURLVERSION_NOW);
320+
324321
std::string curl_ca_info;
325322
std::string curl_ca_path;
326323
#if CURL_AT_LEAST_VERSION(7, 70, 0)
327-
const auto* version_data = curl_version_info(CURLVERSION_NOW);
328324
curl_ca_path = version_data->capath ? version_data->capath : "<empty>";
329325
curl_ca_info = version_data->cainfo ? version_data->cainfo : "<empty>";
330326
#else
@@ -335,7 +331,7 @@ NetworkCurl::NetworkCurl(NetworkInitializationSettings settings)
335331
std::string ca_bundle_path;
336332
#if defined(OLP_SDK_ENABLE_ANDROID_CURL) && !defined(ANDROID_HOST)
337333
ca_bundle_path = kCurlAndroidCaBundleFolder;
338-
#elif OLP_SDK_NETWORK_HAS_OPENSSL
334+
#else
339335
ca_bundle_path = CaBundlePath();
340336
if (ca_bundle_path.empty()) {
341337
ca_bundle_path = "<empty>";
@@ -347,6 +343,10 @@ NetworkCurl::NetworkCurl(NetworkInitializationSettings settings)
347343
"ca_bundle_path=%s",
348344
curl_ca_path.c_str(), curl_ca_info.c_str(),
349345
ca_bundle_path.c_str());
346+
347+
OLP_SDK_LOG_INFO_F(
348+
kLogTag, "TLS backend: %s",
349+
version_data->ssl_version ? version_data->ssl_version : "<empty>");
350350
}
351351

352352
NetworkCurl::~NetworkCurl() {

olp-cpp-sdk-core/src/http/curl/NetworkCurl.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <boost/optional.hpp>
3535

3636
#if defined(OLP_SDK_ENABLE_ANDROID_CURL) && !defined(ANDROID_HOST)
37-
#ifdef OLP_SDK_NETWORK_HAS_OPENSSL
3837
#include <openssl/ossl_typ.h>
3938

4039
#ifdef OPENSSL_NO_MD5
@@ -47,7 +46,6 @@
4746
// lookup method that uses MD5. Old SHA1 lookup will be left as is.
4847
#define OLP_SDK_USE_MD5_CERT_LOOKUP
4948
#endif
50-
#endif
5149

5250
// CURLOPT_CAINFO_BLOB has become available only in curl-7.77
5351
// cf. https://curl.se/libcurl/c/CURLOPT_CAINFO_BLOB.html,
@@ -387,12 +385,6 @@ class NetworkCurl : public olp::http::Network,
387385
/// UNIX Pipe used to notify sleeping worker thread during select() call.
388386
int pipe_[2]{};
389387

390-
#ifdef OLP_SDK_NETWORK_HAS_OPENSSL
391-
/// Mutexes that are used by OpenSSL to synchronize during concurrent
392-
/// network transfer.
393-
std::unique_ptr<std::mutex[]> ssl_mutexes_{};
394-
#endif
395-
396388
/// Stores value if `curl_global_init()` was successful on construction.
397389
bool curl_initialized_;
398390

scripts/linux/nv/cppcheck_and_upload_sonar.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash -e
22
#
3-
# Copyright (C) 2019-2021 HERE Europe B.V.
3+
# Copyright (C) 2019-2024 HERE Europe B.V.
44
#
55
# Licensed under the Apache License, Version 2.0 (the "License");
66
# you may not use this file except in compliance with the License.
@@ -36,7 +36,6 @@ cppcheck \
3636
-DHAVE_SIGNAL_H \
3737
-DIGNORE_SIGPIPE \
3838
-DOLP_SDK_NETWORK_HAS_CURL \
39-
-DOLP_SDK_NETWORK_HAS_OPENSSL \
4039
-DOLP_SDK_NETWORK_HAS_PIPE=1 \
4140
-DOLP_SDK_NETWORK_HAS_UNISTD_H=1 \
4241
-DOLP_SDK_PLATFORM_NAME=\"Linux\" \

0 commit comments

Comments
 (0)