@@ -245,14 +245,21 @@ void SetCipherListToSSLContext(const Shared<TlsContext>::Ptr& context, const Str
245
245
* @return The value of the corresponding TLS*_VERSION macro.
246
246
*/
247
247
TlsProtocolMin ResolveTlsProtocolVersion (const std::string& version) {
248
+ #ifdef _WIN32
249
+ if (version == " TLSv1.2" ) {
250
+ return TlsProtocolMin ((int )TlsProtocolMin::tlsv12 | (int )TlsProtocolMin::tlsv13);
251
+ } else if (version == " TLSv1.3" ) {
252
+ return TlsProtocolMin::tlsv13;
253
+ #else /* _WIN32 */
248
254
if (version == " TLSv1.2" ) {
249
255
return TLS1_2_VERSION;
250
256
} else if (version == " TLSv1.3" ) {
251
- #if OPENSSL_VERSION_NUMBER >= 0x10101000L
257
+ # if OPENSSL_VERSION_NUMBER >= 0x10101000L
252
258
return TLS1_3_VERSION;
253
- #else /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
259
+ # else /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
254
260
throw std::runtime_error (" '" + version + " ' is only supported with OpenSSL 1.1.1 or newer" );
255
- #endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
261
+ # endif /* OPENSSL_VERSION_NUMBER >= 0x10101000L */
262
+ #endif /* _WIN32 */
256
263
} else {
257
264
throw std::runtime_error (" Unknown TLS protocol version '" + version + " '" );
258
265
}
@@ -265,10 +272,26 @@ Shared<TlsContext>::Ptr SetupSslContext(const String& certPath, const String& ke
265
272
266
273
Shared<TlsContext>::Ptr context;
267
274
275
+ #ifdef _WIN32
276
+ auto method (TlsProtocolMin::system_default);
277
+ #else /* _WIN32 */
278
+ auto method (TlsContext::tls);
279
+ #endif /* _WIN32 */
280
+
268
281
InitializeOpenSSL ();
269
282
283
+ #ifdef _WIN32
284
+ if (!protocolmin.IsEmpty ()) {
285
+ try {
286
+ method = ResolveTlsProtocolVersion (protocolmin);
287
+ } catch (const std::exception &) {
288
+ BOOST_THROW_EXCEPTION (ScriptError (" Cannot set minimum TLS protocol version to SSL context with tls_protocolmin: '" + protocolmin + " '." , std::move (di)));
289
+ }
290
+ }
291
+ #endif /* _WIN32 */
292
+
270
293
try {
271
- context = Shared<TlsContext>::Make (TlsContext::tls );
294
+ context = Shared<TlsContext>::Make (method );
272
295
273
296
InitSslContext (context, certPath, keyPath, caPath);
274
297
} catch (const std::exception &) {
@@ -294,17 +317,20 @@ Shared<TlsContext>::Ptr SetupSslContext(const String& certPath, const String& ke
294
317
}
295
318
}
296
319
320
+ #ifndef _WIN32
297
321
if (!protocolmin.IsEmpty ()){
298
322
try {
299
323
SetTlsProtocolminToSSLContext (context, ResolveTlsProtocolVersion (protocolmin));
300
324
} catch (const std::exception &) {
301
325
BOOST_THROW_EXCEPTION (ScriptError (" Cannot set minimum TLS protocol version to SSL context with tls_protocolmin: '" + protocolmin + " '." , std::move (di)));
302
326
}
303
327
}
328
+ #endif /* _WIN32 */
304
329
305
330
return context;
306
331
}
307
332
333
+ #ifndef _WIN32
308
334
/* *
309
335
* Set the minimum TLS protocol version to the specified SSL context.
310
336
*
@@ -313,7 +339,7 @@ Shared<TlsContext>::Ptr SetupSslContext(const String& certPath, const String& ke
313
339
*/
314
340
void SetTlsProtocolminToSSLContext (const Shared<TlsContext>::Ptr & context, TlsProtocolMin tlsProtocolmin)
315
341
{
316
- #if OPENSSL_VERSION_NUMBER >= 0x10100000L
342
+ # if OPENSSL_VERSION_NUMBER >= 0x10100000L
317
343
int ret = SSL_CTX_set_min_proto_version (context->native_handle (), tlsProtocolmin);
318
344
319
345
if (ret != 1 ) {
@@ -326,12 +352,13 @@ void SetTlsProtocolminToSSLContext(const Shared<TlsContext>::Ptr& context, TlsPr
326
352
<< boost::errinfo_api_function (" SSL_CTX_set_min_proto_version" )
327
353
<< errinfo_openssl_error (ERR_peek_error ()));
328
354
}
329
- #else /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
355
+ # else /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
330
356
// This should never happen. On this OpenSSL version, ResolveTlsProtocolVersion() should either return TLS 1.2
331
357
// or throw an exception, as that's the only TLS version supported by both Icinga and ancient OpenSSL.
332
358
VERIFY (tlsProtocolmin == TLS1_2_VERSION);
333
- #endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
359
+ # endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
334
360
}
361
+ #endif /* _WIN32 */
335
362
336
363
/* *
337
364
* Loads a CRL and appends its certificates to the specified Boost SSL context.
0 commit comments