Skip to content

Commit 31e90a6

Browse files
Use CURL to handle lookups (#1374)
Do not interfere with CURL lookup management, since we need to only allocate and setup lookup. Relates-To: OLPSUP-21143 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent 5f0fe4a commit 31e90a6

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -325,23 +325,12 @@ bool NetworkCurl::Initialize() {
325325
return false;
326326
}
327327

328-
#ifdef OLP_SDK_USE_MD5_CERT_LOOKUP
329-
md5_lookup_method_ = X509_LOOKUP_meth_new(kLookupMethodName);
330-
331-
X509_LOOKUP_meth_set_ctrl(md5_lookup_method_, Md5LookupCtrl);
332-
X509_LOOKUP_meth_set_get_by_subject(md5_lookup_method_,
333-
Md5LookupGetBySubject);
334-
#endif
335-
336328
// handles setup
337329
std::shared_ptr<NetworkCurl> that = shared_from_this();
338330
for (auto& handle : handles_) {
339331
handle.handle = nullptr;
340332
handle.in_use = false;
341333
handle.self = that;
342-
#ifdef OLP_SDK_USE_MD5_CERT_LOOKUP
343-
handle.md5_lookup_method = md5_lookup_method_;
344-
#endif
345334
}
346335

347336
std::unique_lock<std::mutex> lock(event_mutex_);
@@ -357,10 +346,6 @@ bool NetworkCurl::Initialize() {
357346
void NetworkCurl::Deinitialize() {
358347
std::lock_guard<std::mutex> init_lock(init_mutex_);
359348

360-
#ifdef OLP_SDK_USE_MD5_CERT_LOOKUP
361-
X509_LOOKUP_meth_free(md5_lookup_method_);
362-
#endif
363-
364349
// Stop worker thread
365350
if (!IsStarted()) {
366351
OLP_SDK_LOG_DEBUG(kLogTag, "Already deinitialized, this=" << this);
@@ -1159,12 +1144,21 @@ CURLcode NetworkCurl::AddMd5LookupMethod(CURL*, SSL_CTX* ssl_ctx,
11591144
return CURLE_ABORTED_BY_CALLBACK;
11601145
}
11611146

1147+
auto* md5_lookup_method = X509_LOOKUP_meth_new(kLookupMethodName);
1148+
if (!md5_lookup_method) {
1149+
OLP_SDK_LOG_ERROR(kLogTag, "Failed to allocate MD5 lookup method");
1150+
return CURLE_ABORTED_BY_CALLBACK;
1151+
}
1152+
1153+
X509_LOOKUP_meth_set_ctrl(md5_lookup_method, Md5LookupCtrl);
1154+
X509_LOOKUP_meth_set_get_by_subject(md5_lookup_method, Md5LookupGetBySubject);
1155+
11621156
auto* cert_store = SSL_CTX_get_cert_store(ssl_ctx);
1163-
auto* lookup = X509_STORE_add_lookup(cert_store, handle->md5_lookup_method);
1157+
auto* lookup = X509_STORE_add_lookup(cert_store, md5_lookup_method);
11641158
if (lookup) {
11651159
X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_PEM);
11661160
} else {
1167-
OLP_SDK_LOG_ERROR(kLogTag, "Failed to add lookup method");
1161+
OLP_SDK_LOG_ERROR(kLogTag, "Failed to add MD5 lookup method");
11681162
return CURLE_ABORTED_BY_CALLBACK;
11691163
}
11701164

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ class NetworkCurl : public olp::http::Network,
124124
bool cancelled{};
125125
bool skip_content{};
126126
char error_text[CURL_ERROR_SIZE]{};
127-
#ifdef OLP_SDK_USE_MD5_CERT_LOOKUP
128-
X509_LOOKUP_METHOD* md5_lookup_method{nullptr};
129-
#endif
130127
};
131128

132129
/**
@@ -353,11 +350,6 @@ class NetworkCurl : public olp::http::Network,
353350
std::unique_ptr<std::mutex[]> ssl_mutexes_{};
354351
#endif
355352

356-
#ifdef OLP_SDK_USE_MD5_CERT_LOOKUP
357-
/// Additional lookup method.
358-
X509_LOOKUP_METHOD* md5_lookup_method_{nullptr};
359-
#endif
360-
361353
/// Stores value if `curl_global_init()` was successful on construction.
362354
bool curl_initialized_;
363355
};

0 commit comments

Comments
 (0)