From 372212a3af28ede03a247f257be1d622b941ff8b Mon Sep 17 00:00:00 2001 From: The-EDev Date: Wed, 27 Apr 2022 05:54:33 +0300 Subject: [PATCH] Added method for assigning an SSL certificate chain file --- include/crow/app.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/include/crow/app.h b/include/crow/app.h index 5de5741a5..b8cfb3c08 100644 --- a/include/crow/app.h +++ b/include/crow/app.h @@ -367,6 +367,22 @@ namespace crow return *this; } + /// Use certificate chain and key files for SSL + self_t& ssl_chainfile(const std::string& crt_filename, const std::string& key_filename) + { + ssl_used_ = true; + ssl_context_.set_verify_mode(boost::asio::ssl::verify_peer); + ssl_context_.set_verify_mode(boost::asio::ssl::verify_client_once); + ssl_context_.use_certificate_chain_file(crt_filename); + ssl_context_.use_private_key_file(key_filename, ssl_context_t::pem); + ssl_context_.set_options( + boost::asio::ssl::context::default_workarounds + | boost::asio::ssl::context::no_sslv2 + | boost::asio::ssl::context::no_sslv3 + ); + return *this; + } + self_t& ssl(boost::asio::ssl::context&& ctx) { ssl_used_ = true; @@ -390,6 +406,17 @@ namespace crow return *this; } + template + self_t& ssl_chainfile(T&&, Remain&&...) + { + // We can't call .ssl() member function unless CROW_ENABLE_SSL is defined. + static_assert( + // make static_assert dependent to T; always false + std::is_base_of::value, + "Define CROW_ENABLE_SSL to enable ssl support."); + return *this; + } + template self_t& ssl(T&&) {