Skip to content

Commit 3246241

Browse files
Custom certificate settings (#1402)
Certificate settings for setting up SSL for CURL by using blobs Relates-To: OLPEDGE-1750 Signed-off-by: Andrey Kashcheev <[email protected]>
1 parent 26ec13f commit 3246241

File tree

10 files changed

+292
-43
lines changed

10 files changed

+292
-43
lines changed

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ set(OLP_SDK_GENERATED_HEADERS
100100
)
101101

102102
set(OLP_SDK_HTTP_HEADERS
103+
./include/olp/core/http/CertificateSettings.h
103104
./include/olp/core/http/HttpStatusCode.h
104105
./include/olp/core/http/Network.h
105106
./include/olp/core/http/HttpStatusCode.h
106107
./include/olp/core/http/NetworkConstants.h
108+
./include/olp/core/http/NetworkInitializationSettings.h
107109
./include/olp/core/http/NetworkProxySettings.h
108110
./include/olp/core/http/NetworkRequest.h
109111
./include/olp/core/http/NetworkResponse.h

olp-cpp-sdk-core/include/olp/core/client/OlpClientSettingsFactory.h

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,12 +20,15 @@
2020
#pragma once
2121

2222
#include <memory>
23+
#include <string>
2324

24-
#include <olp/core/CoreApi.h>
25-
#include <olp/core/http/Network.h>
26-
#include <olp/core/thread/TaskScheduler.h>
2725
#include <boost/optional.hpp>
2826

27+
#include "olp/core/CoreApi.h"
28+
#include "olp/core/http/Network.h"
29+
#include "olp/core/http/NetworkInitializationSettings.h"
30+
#include "olp/core/thread/TaskScheduler.h"
31+
2932
namespace olp {
3033
namespace cache {
3134
class KeyValueCache;
@@ -74,6 +77,29 @@ class CORE_API OlpClientSettingsFactory final {
7477
static std::shared_ptr<http::Network> CreateDefaultNetworkRequestHandler(
7578
size_t max_requests_count = 30u);
7679

80+
/**
81+
* @brief Creates the `Network` instance used for all the non-local requests.
82+
*
83+
* Defaulted to platform-specific implementation.
84+
*
85+
* On UNIX platforms, the default network request handler is libcurl-based and
86+
* has the known issue of static initialization and cleanup that needs special
87+
* care. Therefore, we recommend initializing this network request handler at
88+
* a very early stage, preferably as global static or from the main thread,
89+
* and pass it on to every created client. For this matter, it is also not
90+
* recommended to create multiple network request handlers.
91+
*
92+
* @see [cURL documentation]
93+
* (Lhttps://curl.haxx.se/libcurl/c/curl_global_init.html) for more
94+
* information.
95+
*
96+
* @param[in] settings The `NetworkInitializationSettings` instance.
97+
*
98+
* @return The `Network` instance.
99+
*/
100+
static std::shared_ptr<http::Network> CreateDefaultNetworkRequestHandler(
101+
http::NetworkInitializationSettings settings);
102+
77103
/**
78104
* @brief Creates the `KeyValueCache` instance that includes both a small
79105
* memory LRU cache and a larger persistent database cache.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2023 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
#pragma once
21+
22+
#include <string>
23+
24+
#include "olp/core/CoreApi.h"
25+
26+
namespace olp {
27+
namespace http {
28+
29+
/**
30+
* @brief Settings for custom network certificate.
31+
*/
32+
struct CORE_API CertificateSettings {
33+
/**
34+
* @brief The client certificate file as blob.
35+
*/
36+
std::string client_cert_file_blob;
37+
38+
/**
39+
* @brief The client key file as blob.
40+
*/
41+
std::string client_key_file_blob;
42+
43+
/**
44+
* @brief The CA file as blob.
45+
*/
46+
std::string cert_file_blob;
47+
};
48+
49+
} // namespace http
50+
} // namespace olp

olp-cpp-sdk-core/include/olp/core/http/Network.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -24,10 +24,11 @@
2424
#include <memory>
2525
#include <string>
2626

27-
#include <olp/core/CoreApi.h>
28-
#include <olp/core/http/NetworkRequest.h>
29-
#include <olp/core/http/NetworkResponse.h>
30-
#include <olp/core/http/NetworkTypes.h>
27+
#include "olp/core/CoreApi.h"
28+
#include "olp/core/http/NetworkInitializationSettings.h"
29+
#include "olp/core/http/NetworkRequest.h"
30+
#include "olp/core/http/NetworkResponse.h"
31+
#include "olp/core/http/NetworkTypes.h"
3132

3233
namespace olp {
3334
/// Provides a platform specific network abstraction layer.
@@ -147,8 +148,15 @@ class CORE_API Network {
147148
};
148149

149150
/// Creates a default `Network` implementation.
151+
OLP_SDK_DEPRECATED(
152+
"Will be removed by 05.2024, use "
153+
"CreateDefaultNetwork(NetworkInitializationSettings) instead")
150154
CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
151155
size_t max_requests_count);
152156

157+
/// Creates a default `Network` implementation.
158+
CORE_API std::shared_ptr<Network> CreateDefaultNetwork(
159+
NetworkInitializationSettings settings);
160+
153161
} // namespace http
154162
} // namespace olp
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2023 HERE Europe B.V.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
* SPDX-License-Identifier: Apache-2.0
17+
* License-Filename: LICENSE
18+
*/
19+
20+
#pragma once
21+
22+
#include "olp/core/CoreApi.h"
23+
#include "olp/core/http/CertificateSettings.h"
24+
25+
namespace olp {
26+
namespace http {
27+
28+
/**
29+
* @brief Settings for network initialization.
30+
*/
31+
struct CORE_API NetworkInitializationSettings {
32+
/**
33+
* @brief The maximum number of requests that can be sent simultaneously.
34+
*/
35+
size_t max_requests_count = 30u;
36+
37+
/**
38+
* @brief The custom certificate settings.
39+
*/
40+
CertificateSettings certificate_settings;
41+
};
42+
43+
} // namespace http
44+
} // namespace olp

olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "olp/core/cache/DefaultCache.h"
2525
#include "olp/core/client/OlpClientSettings.h"
2626
#include "olp/core/http/NetworkConstants.h"
27+
#include "olp/core/http/NetworkInitializationSettings.h"
2728
#include "olp/core/logging/Log.h"
2829
#include "olp/core/porting/make_unique.h"
2930
#include "olp/core/thread/ThreadPoolTaskScheduler.h"
@@ -43,7 +44,15 @@ OlpClientSettingsFactory::CreateDefaultTaskScheduler(size_t thread_count) {
4344
std::shared_ptr<http::Network>
4445
OlpClientSettingsFactory::CreateDefaultNetworkRequestHandler(
4546
size_t max_requests_count) {
46-
return http::CreateDefaultNetwork(max_requests_count);
47+
http::NetworkInitializationSettings settings;
48+
settings.max_requests_count = max_requests_count;
49+
return CreateDefaultNetworkRequestHandler(std::move(settings));
50+
}
51+
52+
std::shared_ptr<http::Network>
53+
OlpClientSettingsFactory::CreateDefaultNetworkRequestHandler(
54+
http::NetworkInitializationSettings settings) {
55+
return http::CreateDefaultNetwork(std::move(settings));
4756
}
4857

4958
std::unique_ptr<cache::KeyValueCache>

olp-cpp-sdk-core/src/http/Network.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2020 HERE Europe B.V.
2+
* Copyright (C) 2019-2023 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,16 +36,17 @@ namespace olp {
3636
namespace http {
3737

3838
namespace {
39-
std::shared_ptr<Network> CreateDefaultNetworkImpl(size_t max_requests_count) {
40-
OLP_SDK_CORE_UNUSED(max_requests_count);
39+
std::shared_ptr<Network> CreateDefaultNetworkImpl(
40+
NetworkInitializationSettings settings) {
41+
OLP_SDK_CORE_UNUSED(settings);
4142
#ifdef OLP_SDK_NETWORK_HAS_CURL
42-
return std::make_shared<NetworkCurl>(max_requests_count);
43+
return std::make_shared<NetworkCurl>(settings);
4344
#elif OLP_SDK_NETWORK_HAS_ANDROID
44-
return std::make_shared<NetworkAndroid>(max_requests_count);
45+
return std::make_shared<NetworkAndroid>(settings.max_requests_count);
4546
#elif OLP_SDK_NETWORK_HAS_IOS
46-
return std::make_shared<OLPNetworkIOS>(max_requests_count);
47+
return std::make_shared<OLPNetworkIOS>(settings.max_requests_count);
4748
#elif OLP_SDK_NETWORK_HAS_WINHTTP
48-
return std::make_shared<NetworkWinHttp>(max_requests_count);
49+
return std::make_shared<NetworkWinHttp>(settings.max_requests_count);
4950
#else
5051
static_assert(false, "No default network implementation provided");
5152
#endif
@@ -61,7 +62,14 @@ Network::Statistics Network::GetStatistics(uint8_t /*bucket_id*/) {
6162
}
6263

6364
std::shared_ptr<Network> CreateDefaultNetwork(size_t max_requests_count) {
64-
auto network = CreateDefaultNetworkImpl(max_requests_count);
65+
NetworkInitializationSettings settings;
66+
settings.max_requests_count = max_requests_count;
67+
return CreateDefaultNetwork(std::move(settings));
68+
}
69+
70+
std::shared_ptr<Network> CreateDefaultNetwork(
71+
NetworkInitializationSettings settings) {
72+
auto network = CreateDefaultNetworkImpl(std::move(settings));
6573
if (network) {
6674
return std::make_shared<DefaultNetwork>(network);
6775
}

0 commit comments

Comments
 (0)