@@ -4631,6 +4631,38 @@ R"x*x*x(<html>
4631
4631
4632
4632
virtual ~proxy_server () = default ;
4633
4633
4634
+ bool rfc2818_verification_match_pattern (
4635
+ const char * pattern, std::size_t pattern_length, const char * host)
4636
+ {
4637
+ const char * p = pattern;
4638
+ const char * p_end = p + pattern_length;
4639
+ const char * h = host;
4640
+
4641
+ while (p != p_end && *h)
4642
+ {
4643
+ if (*p == ' *' )
4644
+ {
4645
+ ++p;
4646
+ while (*h && *h != ' .' )
4647
+ {
4648
+ if (rfc2818_verification_match_pattern (p, p_end - p, h++))
4649
+ return true ;
4650
+ }
4651
+ }
4652
+ else if (std::tolower (*p) == std::tolower (*h))
4653
+ {
4654
+ ++p;
4655
+ ++h;
4656
+ }
4657
+ else
4658
+ {
4659
+ return false ;
4660
+ }
4661
+ }
4662
+
4663
+ return p == p_end && !*h;
4664
+ }
4665
+
4634
4666
pem_file determine_pem_type (const std::string& filepath) noexcept
4635
4667
{
4636
4668
pem_file result{ filepath, pem_type::none };
@@ -4954,10 +4986,24 @@ R"x*x*x(<html>
4954
4986
4955
4987
for (auto & ctx : m_certificates)
4956
4988
{
4957
- if (ctx.domain_ == servername && ctx. ssl_context_ .has_value ())
4989
+ if (ctx.ssl_context_ .has_value ())
4958
4990
{
4959
- SSL_set_SSL_CTX (ssl, ctx.ssl_context_ ->native_handle ());
4960
- return SSL_TLSEXT_ERR_OK;
4991
+ if (rfc2818_verification_match_pattern (
4992
+ ctx.domain_ .c_str (), ctx.domain_ .length (), servername))
4993
+ {
4994
+ SSL_set_SSL_CTX (ssl, ctx.ssl_context_ ->native_handle ());
4995
+ return SSL_TLSEXT_ERR_OK;
4996
+ }
4997
+
4998
+ for (auto & alt_name : ctx.alt_names_ )
4999
+ {
5000
+ if (rfc2818_verification_match_pattern (
5001
+ alt_name.c_str (), alt_name.length (), servername))
5002
+ {
5003
+ SSL_set_SSL_CTX (ssl, ctx.ssl_context_ ->native_handle ());
5004
+ return SSL_TLSEXT_ERR_OK;
5005
+ }
5006
+ }
4961
5007
}
4962
5008
if (ctx.domain_ .empty ())
4963
5009
default_ctx = &ctx;
0 commit comments