Skip to content

Commit fe80f1b

Browse files
Allow flexible certificate configuration (#1541)
Now, all fields could be setup independently. For example, only CA info, or client certificate. Relates-To: HERESUP-978 Signed-off-by: Andrey Kashcheev <ext-andrey.kashcheev@here.com>
1 parent 1491397 commit fe80f1b

File tree

2 files changed

+31
-13
lines changed

2 files changed

+31
-13
lines changed

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,11 +696,11 @@ ErrorCode NetworkCurl::SendImplementation(
696696
#ifdef OLP_SDK_CURL_HAS_SUPPORT_SSL_BLOBS
697697
if (ssl_certificates_blobs_) {
698698
curl_easy_setopt(curl_handle, CURLOPT_SSLCERT_BLOB,
699-
&ssl_certificates_blobs_->ssl_cert_blob);
699+
ssl_certificates_blobs_->ssl_cert_blob.get_ptr());
700700
curl_easy_setopt(curl_handle, CURLOPT_SSLKEY_BLOB,
701-
&ssl_certificates_blobs_->ssl_key_blob);
701+
ssl_certificates_blobs_->ssl_key_blob.get_ptr());
702702
curl_easy_setopt(curl_handle, CURLOPT_CAINFO_BLOB,
703-
&ssl_certificates_blobs_->ca_info_blob);
703+
ssl_certificates_blobs_->ca_info_blob.get_ptr());
704704
} else
705705
#endif
706706
{
@@ -1312,17 +1312,23 @@ void NetworkCurl::Run() {
13121312

13131313
#ifdef OLP_SDK_CURL_HAS_SUPPORT_SSL_BLOBS
13141314
void NetworkCurl::SetupCertificateBlobs() {
1315-
if (certificate_settings_.client_cert_file_blob.empty() ||
1316-
certificate_settings_.client_key_file_blob.empty() ||
1315+
if (certificate_settings_.client_cert_file_blob.empty() &&
1316+
certificate_settings_.client_key_file_blob.empty() &&
13171317
certificate_settings_.cert_file_blob.empty()) {
13181318
OLP_SDK_LOG_INFO(kLogTag, "No certificate blobs provided");
13191319
return;
13201320
}
13211321

1322-
auto setup_blob = [](struct curl_blob& blob, std::string& src) {
1323-
blob.data = const_cast<char*>(src.data());
1324-
blob.len = src.size();
1325-
blob.flags = CURL_BLOB_NOCOPY;
1322+
auto setup_blob = [](SslCertificateBlobs::OptionalBlob& blob,
1323+
std::string& src) {
1324+
if (src.empty()) {
1325+
blob.reset();
1326+
return;
1327+
}
1328+
blob = SslCertificateBlobs::OptionalBlob::value_type{};
1329+
blob->data = const_cast<char*>(src.data());
1330+
blob->len = src.size();
1331+
blob->flags = CURL_BLOB_NOCOPY;
13261332
};
13271333

13281334
ssl_certificates_blobs_ = SslCertificateBlobs{};
@@ -1334,7 +1340,17 @@ void NetworkCurl::SetupCertificateBlobs() {
13341340
setup_blob(ssl_certificates_blobs_->ca_info_blob,
13351341
certificate_settings_.cert_file_blob);
13361342

1337-
OLP_SDK_LOG_INFO(kLogTag, "Certificate blobs provided");
1343+
auto to_log_str = [](const SslCertificateBlobs::OptionalBlob& blob) {
1344+
return blob ? "<provided>" : "<empty>";
1345+
};
1346+
1347+
OLP_SDK_LOG_INFO(kLogTag,
1348+
"Certificate blobs provided, client_cert_blob="
1349+
<< to_log_str(ssl_certificates_blobs_->ssl_cert_blob)
1350+
<< ", client_key_blob="
1351+
<< to_log_str(ssl_certificates_blobs_->ssl_key_blob)
1352+
<< ", ca_info_blob="
1353+
<< to_log_str(ssl_certificates_blobs_->ca_info_blob));
13381354
}
13391355
#endif
13401356

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,16 @@ class NetworkCurl : public olp::http::Network,
167167
* @brief Blobs required for custom certificate validation.
168168
*/
169169
struct SslCertificateBlobs {
170+
using OptionalBlob = boost::optional<struct curl_blob>;
171+
170172
/// Certificate blob.
171-
struct curl_blob ssl_cert_blob;
173+
OptionalBlob ssl_cert_blob;
172174

173175
/// Private key blob.
174-
struct curl_blob ssl_key_blob;
176+
OptionalBlob ssl_key_blob;
175177

176178
/// Certificate authority blob.
177-
struct curl_blob ca_info_blob;
179+
OptionalBlob ca_info_blob;
178180
};
179181
#endif
180182

0 commit comments

Comments
 (0)