284{
285 boost::asio::ssl::context ssl_context{boost::asio::ssl::context::tlsv12};
286 if (!bool(*this))
287 return ssl_context;
288
289
290 ssl_context.set_options(boost::asio::ssl::context::default_workarounds);
291 ssl_context.set_options(boost::asio::ssl::context::no_sslv2);
292 ssl_context.set_options(boost::asio::ssl::context::no_sslv3);
293 ssl_context.set_options(boost::asio::ssl::context::no_tlsv1);
294 ssl_context.set_options(boost::asio::ssl::context::no_tlsv1_1);
295
296
297 SSL_CTX_set_cipher_list(ssl_context.native_handle(), "ECDHE-ECDSA-CHACHA20-POLY1305-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256");
298
299
300 SSL_CTX *ctx = ssl_context.native_handle();
302 SSL_CTX_clear_options(ctx, SSL_OP_LEGACY_SERVER_CONNECT);
303 SSL_CTX_set_session_cache_mode(ctx, SSL_SESS_CACHE_OFF);
304#ifdef SSL_OP_NO_TICKET
305 SSL_CTX_set_options(ctx, SSL_OP_NO_TICKET);
306#endif
307#ifdef SSL_OP_NO_RENEGOTIATION
308 SSL_CTX_set_options(ctx, SSL_OP_NO_RENEGOTIATION);
309#endif
310#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
311 SSL_CTX_set_options(ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
312#endif
313#ifdef SSL_OP_NO_COMPRESSION
314 SSL_CTX_set_options(ctx, SSL_OP_NO_COMPRESSION);
315#endif
316#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
317 SSL_CTX_set_options(ctx, SSL_OP_CIPHER_SERVER_PREFERENCE);
318#endif
319 SSL_CTX_set_ecdh_auto(ctx, 1);
320
322 {
324 ssl_context.set_default_verify_paths();
325 break;
327 ssl_context.set_verify_depth(0);
328
331 {
332 const boost::system::error_code err = load_ca_file(ssl_context,
ca_path);
333 if (err)
334 throw boost::system::system_error{err,
"Failed to load user CA file at " +
ca_path};
335 }
336 break;
337 default:
338 break;
339 }
340
342 if (
auth.private_key_path.empty())
343 {
344 EVP_PKEY *pkey;
345 X509 *cert;
346 bool ok = false;
347
348#ifdef USE_EXTRA_EC_CERT
351 if (!SSL_CTX_use_PrivateKey(ctx, pkey))
352 MERROR(
"Failed to use generated EC private key for " << NID_secp256k1);
353 else
354 ok = true;
355 X509_free(cert);
356 EVP_PKEY_free(pkey);
357#endif
358
361 if (!SSL_CTX_use_PrivateKey(ctx, pkey))
362 MERROR(
"Failed to use generated RSA private key for RSA");
363 else
364 ok = true;
365 X509_free(cert);
366 EVP_PKEY_free(pkey);
367
369 }
370 else
371 auth.use_ssl_certificate(ssl_context);
372
373 return ssl_context;
374}
#define CHECK_AND_ASSERT_THROW_MES(expr, message)
@ user_ca
Verify peer via specific (possibly chain) certificate(s) only.
bool create_rsa_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)
bool create_ec_ssl_certificate(EVP_PKEY *&pkey, X509 *&cert)