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