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