@@ -8,10 +8,13 @@ it under the terms of The Open Software License 3.0 (OSL-3.0).
8
8
See LICENSE for license details.
9
9
*/
10
10
11
+ #include < openssl/err.h>
12
+
11
13
#include " listener.h"
12
14
13
15
#include " utils.h"
14
16
#include " exceptions.h"
17
+ #include " logger.h"
15
18
16
19
void Listener::isValid ()
17
20
{
@@ -26,6 +29,7 @@ void Listener::isValid()
26
29
}
27
30
28
31
testSsl (sslFullchain, sslPrivkey);
32
+ testSslVerifyLocations (clientVerificationCaFile, clientVerificationCaDir, " Loading client_verification_ca_dir/client_verification_ca_file failed." );
29
33
}
30
34
else
31
35
{
@@ -38,6 +42,11 @@ void Listener::isValid()
38
42
}
39
43
}
40
44
45
+ if ((!clientVerificationCaDir.empty () || !clientVerificationCaFile.empty ()) && !isSsl ())
46
+ {
47
+ throw ConfigFileException (" X509 client verification can only be done on TLS listeners." );
48
+ }
49
+
41
50
if (port <= 0 || port > 65534 )
42
51
{
43
52
throw ConfigFileException (formatString (" Port nr %d is not valid" , port));
@@ -98,6 +107,35 @@ void Listener::loadCertAndKeyFromConfig()
98
107
throw std::runtime_error (" Loading cert failed. This was after test loading the certificate, so is very unexpected." );
99
108
if (SSL_CTX_use_PrivateKey_file (sslctx->get (), sslPrivkey.c_str (), SSL_FILETYPE_PEM) != 1 )
100
109
throw std::runtime_error (" Loading key failed. This was after test loading the certificate, so is very unexpected." );
110
+
111
+ {
112
+ const char *ca_file = clientVerificationCaFile.empty () ? nullptr : clientVerificationCaFile.c_str ();
113
+ const char *ca_dir = clientVerificationCaDir.empty () ? nullptr : clientVerificationCaDir.c_str ();
114
+
115
+ if (ca_file || ca_dir)
116
+ {
117
+ if (SSL_CTX_load_verify_locations (sslctx->get (), ca_file, ca_dir) != 1 )
118
+ {
119
+ ERR_print_errors_cb (logSslError, NULL );
120
+ throw std::runtime_error (" Loading client_verification_ca_dir/client_verification_ca_file failed. "
121
+ " This was after test loading the certificate, so is very unexpected." );
122
+ }
123
+ }
124
+ }
125
+ }
126
+
127
+ X509ClientVerification Listener::getX509ClientVerficiationMode () const
128
+ {
129
+ X509ClientVerification result = X509ClientVerification::None;
130
+ const bool clientCADefined = !clientVerificationCaDir.empty () || !clientVerificationCaFile.empty ();
131
+
132
+ if (clientCADefined)
133
+ result = X509ClientVerification::X509IsEnough;
134
+
135
+ if (result >= X509ClientVerification::X509IsEnough && clientVerifictionStillDoAuthn)
136
+ result = X509ClientVerification::X509AndUsernamePassword;
137
+
138
+ return result;
101
139
}
102
140
103
141
std::string Listener::getBindAddress (ListenerProtocol p)
0 commit comments