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