Ice 3.8
C++ API Reference
Loading...
Searching...
No Matches
ServerAuthenticationOptions.h
1// Copyright (c) ZeroC, Inc.
2
3#ifndef ICE_SSL_SERVER_AUTHENTICATION_OPTIONS_H
4#define ICE_SSL_SERVER_AUTHENTICATION_OPTIONS_H
5
6#include "Config.h"
7#include "ConnectionInfo.h"
8
9#include <functional>
10
11// This file defines the `XxxServerAuthenticationOptions` structure for each platform-specific SSL implementation. The
12// `#if defined(ICE_USE_XXX)/#endif` directives are used to include the appropriate structure based on the platform. We
13// avoid using `#elif` directives because we want to define all the structures when building the doxygen documentation.
14
15namespace Ice::SSL
16{
17#if defined(ICE_DOXYGEN)
18 /// An alias for the platform-specific implementation of the SSL %ServerAuthenticationOptions.
20#endif
21
22#if defined(ICE_USE_SCHANNEL) || defined(ICE_DOXYGEN)
23 /// The SSL transport options for server connections on Windows.
24 ///
25 /// The SchannelServerAuthenticationOptions structure is only available when the Ice library is built on
26 /// Windows. For macOS and iOS, see SecureTransportServerAuthenticationOptions, and for Linux, see
27 /// OpenSSLServerAuthenticationOptions.
28 /// @see ::Ice::SSL::ServerAuthenticationOptions
30 {
31 /// A callback for selecting the server's SSL credentials based on the name of the object adapter that accepts
32 /// the connection.
33 ///
34 /// This callback is invoked by the SSL transport for each new incoming connection before starting the SSL
35 /// handshake to determine the appropriate server credentials. The callback must return a `SCH_CREDENTIALS` that
36 /// represents the server's credentials. The returned credentials are passed to [AcquireCredentialsHandle] to
37 /// create the credential handle for the connection; see the Schannel documentation for details on the
38 /// available fields. The SSL transport takes ownership of the credentials' `paCred` and `hRootStore` members
39 /// and releases them when the connection is closed.
40 ///
41 /// Certificate validation is not performed through the returned credentials. Use `trustedRootCertificates`
42 /// or `clientCertificateValidationCallback` instead.
43 ///
44 /// @param adapterName The name of the object adapter that accepted the connection.
45 /// @return The server SSL credentials.
46 ///
47 /// Example of setting `serverCertificateSelectionCallback`:
48 /// @snippet Ice/SSL/SchannelServerAuthenticationOptions.cpp serverCertificateSelectionCallback
49 ///
50 /// @see [SCH_CREDENTIALS]
51 /// @see [AcquireCredentialsHandle]
52 ///
53 /// [SCH_CREDENTIALS]:
54 /// https://learn.microsoft.com/en-us/windows/win32/api/schannel/ns-schannel-sch_credentials
55 /// [AcquireCredentialsHandle]:
56 /// https://learn.microsoft.com/en-us/windows/win32/secauthn/acquirecredentialshandle--schannel
57 std::function<SCH_CREDENTIALS(const std::string& adapterName)> serverCredentialsSelectionCallback;
58
59 /// A callback invoked before initiating a new SSL handshake, providing an opportunity to customize the SSL
60 /// parameters for the session based on specific server settings or requirements.
61 ///
62 /// @param context An opaque type that represents the security context associated with the current connection.
63 /// @param adapterName The name of the object adapter that accepted the connection.
64 std::function<void(CtxtHandle context, const std::string& adapterName)> sslNewSessionCallback;
65
66 /// Whether or not the client must provide a certificate. The default value is false.
68
69 /// The trusted root certificates used for validating the client's certificate chain. If this field is set, the
70 /// client's certificate chain is validated against these certificates; otherwise, the system's default root
71 /// certificates are used.
72 ///
73 /// Example of setting `trustedRootCertificates`:
74 /// @snippet Ice/SSL/SchannelServerAuthenticationOptions.cpp trustedRootCertificates
75 HCERTSTORE trustedRootCertificates = nullptr;
76
77 /// A callback for validating the client certificate chain. If the verification callback returns false, the
78 /// connection will be aborted with an Ice::SecurityException.
79 ///
80 /// When this callback is set, it replaces the default validation callback and must perform all necessary
81 /// validation steps.
82 ///
83 /// Example of setting `clientCertificateValidationCallback`:
84 /// @snippet Ice/SSL/SchannelServerAuthenticationOptions.cpp clientCertificateValidationCallback
85 ///
86 /// @param context An opaque object representing the security context associated with the current connection.
87 /// This context contains security data relevant for validation, such as the server's certificate chain and
88 /// cipher suite.
89 /// @param info The connection info object that provides additional connection-related data. The
90 /// `ConnectionInfo` type is an alias for the platform-specific connection info class.
91 /// @return `true` if the certificate chain is valid and the connection should proceed; `false` if the
92 /// certificate chain is invalid and the connection should be aborted.
93 /// @throws Ice::SecurityException if the certificate chain is invalid and the connection should be aborted.
94 /// @see SSL::OpenSSLConnectionInfo
95 /// @see SSL::SecureTransportConnectionInfo
96 /// @see SSL::SchannelConnectionInfo
97 std::function<bool(CtxtHandle context, const ConnectionInfoPtr& info)> clientCertificateValidationCallback;
98 };
99
100 /// @cond INTERNAL
101 /// An alias for the platform-specific implementation of ClientAuthenticationOptions on Windows.
103 /// @endcond
104#endif
105
106#if defined(ICE_USE_SECURE_TRANSPORT) || defined(ICE_DOXYGEN)
107 /// SSL transport options for server connections on macOS and iOS.
108 ///
109 /// The SecureTransportServerAuthenticationOptions structure is only available when the Ice library is built on
110 /// macOS and iOS. For Linux, refer to OpenSSLServerAuthenticationOptions, and for Windows, refer to
111 /// SchannelServerAuthenticationOptions.
112 /// @see ::Ice::SSL::ServerAuthenticationOptions
114 {
115 /// A callback for selecting the server's SSL certificate chain based on the name of the object adapter that
116 /// accepts the connection.
117 ///
118 /// This callback is invoked by the SSL transport for each new incoming connection before starting the SSL
119 /// handshake to determine the appropriate server certificate chain. The callback must return a `CFArrayRef`
120 /// that represents the server's certificate chain, or nullptr if no certificate chain should be used for the
121 /// connection. The SSL transport takes ownership of the returned `CFArrayRef` and releases it when the
122 /// connection is closed.
123 ///
124 /// @param adapterName The name of the object adapter that accepted the connection.
125 /// @return A `CFArrayRef` containing the server's certificate chain, or nullptr to indicate that no certificate
126 /// is used.
127 ///
128 /// Example of setting `serverCertificateSelectionCallback`:
129 /// @snippet Ice/SSL/SecureTransportServerAuthenticationOptions.cpp serverCertificateSelectionCallback
130 ///
131 /// See the [SSLSetCertificate] documentation for requirements on the certificate chain format.
132 ///
133 /// [SSLSetCertificate]:
134 /// https://developer.apple.com/documentation/security/1392400-sslsetcertificate?changes=_3&language=objc
135 std::function<CFArrayRef(const std::string& adapterName)> serverCertificateSelectionCallback;
136
137 /// A callback invoked before initiating a new SSL handshake, providing an opportunity to customize the SSL
138 /// parameters for the session based on specific server settings or requirements.
139 ///
140 /// @param context An opaque type that represents an SSL session context object.
141 /// @param adapterName The name of the object adapter that accepted the connection.
142 ///
143 /// Example of setting `sslNewSessionCallback`:
144 /// @snippet Ice/SSL/SecureTransportServerAuthenticationOptions.cpp sslNewSessionCallback
145 std::function<void(SSLContextRef context, const std::string& adapterName)> sslNewSessionCallback;
146
147 /// The requirements for client-side authentication. The default is `kNeverAuthenticate`.
148 ///
149 /// [see SSLAuthenticate](https://developer.apple.com/documentation/security/sslauthenticate)
150 SSLAuthenticate clientCertificateRequired = kNeverAuthenticate;
151
152 /// The trusted root certificates used for validating the client's certificate chain. If this field is set, the
153 /// client's certificate chain is validated against these certificates; otherwise, the system's default root
154 /// certificates are used.
155 ///
156 /// The trusted root certificates are used by both the default validation callback and by custom validation
157 /// callbacks set in `clientCertificateValidationCallback`.
158 ///
159 /// This is equivalent to calling [SecTrustSetAnchorCertificates] with the `CFArrayRef` object, and
160 /// [SecTrustSetAnchorCertificatesOnly] with the `anchorCertificatesOnly` parameter set to true.
161 ///
162 /// Example of setting `trustedRootCertificates`:
163 /// @snippet Ice/SSL/SecureTransportServerAuthenticationOptions.cpp trustedRootCertificates
164 ///
165 /// [SecTrustSetAnchorCertificates]:
166 /// https://developer.apple.com/documentation/security/1396098-sectrustsetanchorcertificates?language=objc
167 /// [SecTrustSetAnchorCertificatesOnly]:
168 /// https://developer.apple.com/documentation/security/1399071-sectrustsetanchorcertificatesonl?language=objc
169 CFArrayRef trustedRootCertificates = nullptr;
170
171 /// A callback for validating the client certificate chain. If the verification callback returns false, the
172 /// connection will be aborted with an Ice::SecurityException.
173 ///
174 /// The client certificate chain is validated using the trust object passed to the callback. When this callback
175 /// is set, it replaces the default validation callback and must perform all necessary validation steps. If
176 /// `trustedRootCertificates` is set, the passed trust object will use them as the anchor certificates for
177 /// evaluating trust. This setting can be modified by the application using [SecTrustSetAnchorCertificates].
178 ///
179 /// Example of setting `clientCertificateValidationCallback`:
180 /// @snippet Ice/SSL/SecureTransportServerAuthenticationOptions.cpp clientCertificateValidationCallback
181 ///
182 /// @param trust The trust object that contains the client's certificate chain.
183 /// @param info The connection info object that provides additional connection-related data. The
184 /// `ConnectionInfo` type is an alias for the platform-specific connection info class.
185 /// @return `true` if the certificate chain is valid and the connection should proceed; `false` if the
186 /// certificate chain is invalid and the connection should be aborted.
187 /// @throws Ice::SecurityException if the certificate chain is invalid and the connection should be aborted.
188 ///
189 /// @see [SecTrustEvaluateWithError]
190 /// @see SSL::OpenSSLConnectionInfo
191 /// @see SSL::SecureTransportConnectionInfo
192 /// @see SSL::SchannelConnectionInfo
193 ///
194 /// [SecTrustSetAnchorCertificates]:
195 /// https://developer.apple.com/documentation/security/1396098-sectrustsetanchorcertificates?language=objc
196 /// [SecTrustEvaluateWithError]:
197 /// https://developer.apple.com/documentation/security/2980705-sectrustevaluatewitherror?language=objc
198 std::function<bool(SecTrustRef trust, ConnectionInfoPtr info)> clientCertificateValidationCallback;
199 };
200
201 /// @cond INTERNAL
202 // An alias for the platform-specific implementation of ClientAuthenticationOptions on macOS and iOS.
204 /// @endcond
205#endif
206
207#if defined(ICE_USE_OPENSSL) || defined(ICE_DOXYGEN)
208 /// SSL transport options for server connections on Linux.
209 ///
210 /// The OpenSSLServerAuthenticationOptions structure is only available when the Ice library is built on
211 /// Linux. For macOS and iOS, refer to SecureTransportServerAuthenticationOptions, and for Windows, refer to
212 /// SchannelServerAuthenticationOptions.
213 /// @see ::Ice::SSL::ServerAuthenticationOptions
215 {
216 /// A callback that selects the server's [SSL_CTX][SSL_CTX_new] object based on the name of the object
217 /// adapter that accepted the connection.
218 ///
219 /// This callback associates a specific SSL configuration with an incoming connection identified by
220 /// the name of the object adapter that accepted the connection. The callback must return a pointer to a valid
221 /// `SSL_CTX` object previously initialized using the OpenSSL API. The SSL transport takes ownership of the
222 /// returned `SSL_CTX` object and releases it after closing the connection.
223 ///
224 /// If the application does not provide a callback, the SSL transport will use an `SSL_CTX` object created with
225 /// `SSL_CTX_new()`, which uses the default OpenSSL configuration.
226 ///
227 /// The SSL transport calls this callback for each new incoming connection to obtain the `SSL_CTX` object
228 /// before starting the SSL handshake.
229 ///
230 /// @param adapterName The name of the object adapter that accepted the connection.
231 /// @return A pointer to an `SSL_CTX` object representing the SSL configuration for the new incoming
232 /// connection.
233 ///
234 /// Example of setting `serverSSLContextSelectionCallback`:
235 /// @snippet Ice/SSL/OpenSSLServerAuthenticationOptions.cpp serverSSLContextSelectionCallback
236 ///
237 /// [SSL_CTX_new]: https://www.openssl.org/docs/manmaster/man3/SSL_CTX_new.html
238 std::function<SSL_CTX*(const std::string& adapterName)> serverSSLContextSelectionCallback{};
239
240 /// A callback invoked before initiating a new SSL handshake, providing an opportunity to customize the SSL
241 /// parameters for the connection.
242 ///
243 /// @param ssl A pointer to the SSL object representing the connection.
244 /// @param adapterName The name of the object adapter that accepted the connection.
245 ///
246 /// Example of setting `sslNewSessionCallback`:
247 /// @snippet Ice/SSL/OpenSSLServerAuthenticationOptions.cpp sslNewSessionCallback
248 ///
249 /// @see [SSL_new].
250 ///
251 /// [SSL_new]: https://www.openssl.org/docs/manmaster/man3/SSL_new.html
252 std::function<void(::SSL* ssl, const std::string& adapterName)> sslNewSessionCallback{};
253
254 /// A callback for validating the client certificate chain. If the verification callback returns false,
255 /// the connection will be aborted with an Ice::SecurityException.
256 ///
257 /// @param verified A boolean indicating whether the preliminary certificate verification performed by OpenSSL's
258 /// built-in mechanisms succeeded or failed. `true` if the preliminary checks passed, `false` otherwise.
259 /// @param ctx A pointer to an `X509_STORE_CTX` object, which contains the certificate chain to be verified.
260 /// @param info The connection info object that provides additional connection-related data. The
261 /// `ConnectionInfo` type is an alias for the platform-specific connection info class.
262 /// @return `true` if the certificate chain is valid and the connection should proceed; `false` if the
263 /// certificate chain is invalid and the connection should be aborted.
264 /// @throws Ice::SecurityException if the certificate chain is invalid and the connection should be aborted.
265 ///
266 /// Example of setting `clientCertificateValidationCallback`:
267 /// @snippet Ice/SSL/OpenSSLServerAuthenticationOptions.cpp clientCertificateValidationCallback
268 ///
269 /// @see [Certificate verification in OpenSSL][SSL_set_verify].
270 ///
271 /// [SSL_set_verify]: https://www.openssl.org/docs/manmaster/man3/SSL_set_verify.html
272 /// @see SSL::OpenSSLConnectionInfo
273 /// @see SSL::SecureTransportConnectionInfo
274 /// @see SSL::SchannelConnectionInfo
275 std::function<bool(bool verified, X509_STORE_CTX* ctx, const ConnectionInfoPtr& info)>
277 };
278
279 /// @cond INTERNAL
280 // An alias for the platform-specific implementation of ClientAuthenticationOptions on Linux.
281 using ServerAuthenticationOptions = OpenSSLServerAuthenticationOptions;
282 /// @endcond
283#endif
284}
285
286#endif
std::shared_ptr< ConnectionInfo > ConnectionInfoPtr
A shared pointer to a ConnectionInfo.
... ServerAuthenticationOptions
An alias for the platform-specific implementation of the SSL ServerAuthenticationOptions.
Secure connections with SSL/TLS.
std::function< SSL_CTX *(const std::string &adapterName)> serverSSLContextSelectionCallback
A callback that selects the server's SSL_CTX object based on the name of the object adapter that acce...
std::function< void(::SSL *ssl, const std::string &adapterName)> sslNewSessionCallback
A callback invoked before initiating a new SSL handshake, providing an opportunity to customize the S...
std::function< bool(bool verified, X509_STORE_CTX *ctx, const ConnectionInfoPtr &info)> clientCertificateValidationCallback
A callback for validating the client certificate chain.
SSL transport options for server connections on Linux.
std::function< SCH_CREDENTIALS(const std::string &adapterName)> serverCredentialsSelectionCallback
A callback for selecting the server's SSL credentials based on the name of the object adapter that ac...
bool clientCertificateRequired
Whether or not the client must provide a certificate. The default value is false.
std::function< bool(CtxtHandle context, const ConnectionInfoPtr &info)> clientCertificateValidationCallback
A callback for validating the client certificate chain.
std::function< void(CtxtHandle context, const std::string &adapterName)> sslNewSessionCallback
A callback invoked before initiating a new SSL handshake, providing an opportunity to customize the S...
HCERTSTORE trustedRootCertificates
The trusted root certificates used for validating the client's certificate chain.
The SSL transport options for server connections on Windows.
std::function< CFArrayRef(const std::string &adapterName)> serverCertificateSelectionCallback
A callback for selecting the server's SSL certificate chain based on the name of the object adapter t...
std::function< void(SSLContextRef context, const std::string &adapterName)> sslNewSessionCallback
A callback invoked before initiating a new SSL handshake, providing an opportunity to customize the S...
std::function< bool(SecTrustRef trust, ConnectionInfoPtr info)> clientCertificateValidationCallback
A callback for validating the client certificate chain.
SSLAuthenticate clientCertificateRequired
The requirements for client-side authentication.
CFArrayRef trustedRootCertificates
The trusted root certificates used for validating the client's certificate chain.
SSL transport options for server connections on macOS and iOS.