RTI TCP Transport Version 7.3.0
rtitls_openssl.h
1/*
2 * Copyright (c) 2009-2024 Real-Time Innovations, Inc. All rights reserved.
3 * No duplications, whole or partial, manual or electronic, may be made
4 * without express written permission. Any such copies, or revisions thereof,
5 * must display this notice unaltered.
6 * This code contains trade secrets of Real-Time Innovations, Inc.
7 */
8
9#ifndef rtitls_openssl_h
10#define rtitls_openssl_h
11
12 #ifndef rtitls_dll_h
13 #include "rtitls/rtitls_dll.h"
14 #endif
15
16 #ifndef dds_c_infrastructure_h
17 #include "dds_c/dds_c_infrastructure.h"
18 #endif
19
20/* if required, include openssl/ssl.h before this file */
21#ifndef SSL_ERROR_NONE
22 #define X509_STORE_CTX void
23 #define SSL_CTX void
24#endif
25
26#ifdef __cplusplus
27 extern "C" {
28#endif
29
30/* {{{ Doxygen group definitions
31 * ------------------------------------------------------------------------- */
32
33/*e \defgroup RTITLS_Plugin RTI TLS Support
34 @brief OpenSSL configuration interfaces and definitions.
35 <br>TLS Support is included with some RTI purchases and must be downloaded and installed separately.
36*/
37
38/* }}} */
39
40/*i \file
41 \ingroup RTITLS_Plugin
42 \brief TLS Transport OpenSSL configuration interfaces and definitions.
43 <br>TLS Support is included with some RTI purchases and must be downloaded and installed separately.
44*/
45
46/*e \ingroup RTITLS_Plugin
47 \brief Callback used to verify peer certificates.
48
49 See the OpenSSL manual page for SSL_CTX_set_verify for more information.
50 */
52 (int preverify_ok, X509_STORE_CTX *x509_ctx);
53
54/*e \ingroup RTITLS_Plugin
55 \brief Set of TLS properties for certificate authorities (CAs) and verification
56 */
58 /*e
59 * \brief Name of file containing Certificate Authority certificates
60 *
61 * File should be in PEM format. See the OpenSSL manual page for
62 * SSL_load_verify_locations for more information.
63 *
64 * At least one of ca_file and ca_path must be specified; both may be
65 * specified.
66 *
67 * \default NULL
68 */
69 char *ca_file;
70 /*e
71 * \brief Paths to directories containing Certificate Authority certificates
72 *
73 * Files should be in PEM format, and follow the OpenSSL-required naming
74 * conventions. See the OpenSSL manual page for SSL_CTX_load_verify_locations
75 * for more information.
76 *
77 * At least one of ca_file and ca_path must be specified; both may be
78 * specified.
79 *
80 * \default NULL
81 */
82 char *ca_path;
83 /*e
84 * \brief List of Certificate Authority certificates
85 *
86 * Certificates should be in PEM format, and follow the OpenSSL-required naming
87 * conventions. See the OpenSSL manual page for X509_STORE_add_cert
88 * for more information.
89 *
90 * ca_file and ca_path have precedence if specified. If not, ca must be
91 * specified.
92 *
93 * \default NULL
94 */
95 char *ca;
96
97 /*e
98 * \brief Maximum certificate chain length for verification
99 *
100 * \default -1 (no limit)
101 */
103 /*e
104 * \brief Callback used to verify peer certificates
105 *
106 * See the OpenSSL manual page for SSL_set_verify for more information.
107 * There are a number of default callbacks included in the Secure
108 * Transport. See RTITLS_default_verify_callback() ,
109 * RTITLS_verbose_verify_callback() .
110 *
111 * \default NULL (use RTITLS_default_verify_callback() )
112 */
114 /*e
115 * \brief Name of file containing Certificate Revocation List
116 *
117 * File should be in PEM format.
118 *
119 * \default NULL
120 */
121 char *crl_file;
122};
123
124/*e \ingroup RTITLS_Plugin
125 \brief Set of TLS properties for identity
126 */
128 /*e \brief String containing identifying certificate (in PEM format) or
129 * certificate chain (appending intermediate CA certs in order).
130 *
131 * An identifying certificate is required for secure communication.
132 * The string must be sorted starting with the certificate to the highest
133 * level (root CA). If this is specified certificate_chain_file must be
134 * empty.
135 *
136 * \default NULL
137 */
139
140 /*e \brief File containing identifying certificate (in PEM format) or
141 * certificate chain (appending intermediate CA certs in order).
142 *
143 * An identifying certificate is required for secure communication.
144 * The file must be sorted starting with the certificate to the highest
145 * level (root CA). If this is specified certificate_chain must be
146 * empty.
147 *
148 * Optionally, a private key may be appended to this file. If no private
149 * key option is specified, this file will be used to load a private key.
150 *
151 * \default NULL
152 */
154
155 /*e @brief Password for private key
156 *
157 * \default NULL (no password)
158 */
160
161 /*e \brief String containing private key (in PEM format)
162 *
163 * At most one of private_key and private_key_file may be specified. If no
164 * private key is specified (all values are NULL), the private key will be read
165 * from the certificate chain file.
166 *
167 * \default NULL
168 */
170
171 /*e \brief File containing private key (in PEM format)
172 *
173 * At most one of private_key and private_key_file may be specified. If no
174 * private key is specified (all values are NULL), the private key will be read
175 * from the certificate chain file.
176 *
177 * \default NULL
178 */
180
181 /*e \brief String containing additional RSA private key (in PEM format)
182 *
183 * For use if both an RSA and non-RSA key are required for the selected cipher.
184 * At most one of rsa_private_key and rsa_private_key_file may be specified.
185 *
186 * \default NULL
187 */
189
190 /*e \brief File containing additional RSA private key (in PEM format)
191 *
192 * For use if both an RSA and non-RSA key are required for the selected cipher.
193 * At most one of rsa_private_key and rsa_private_key_file may be specified.
194 *
195 * \default NULL
196 */
198};
199
200/*e \ingroup RTITLS_Plugin
201 \brief Name of a Diffie-Helman (DH) key file and the length of the
202 contained key in bits
203 */
205 /*e \brief Name of DH key file
206 *
207 * \default 0
208 */
209 char *file;
210
211 /*e \brief Length of DH key in bits
212 *
213 * \default NULL
214 */
216};
217
218/*e \ingroup RTITLS_Plugin
219 \brief Set of TLS properties for cipher configuration
220 */
222 /*e \brief List of available TLS ciphers for TLS 1.2 or below
223 *
224 * See the OpenSSL manual page for SSL_set_cipher_list(3) or ciphers(1)
225 * for more information on the format of this string. Some typical
226 * values are defined: RTITLS_Plugin#RTITLS_CIPHER_LIST_DEFAULT,
227 * RTITLS_Plugin#RTITLS_CIPHER_LIST_ENCRYPT_HIGH, and
228 * RTITLS_Plugin#RTITLS_CIPHER_LIST_UNENCRYPTED.
229 *
230 * \default NULL
231 */
232 char *cipher_list; /* cipher list in OpenSSL format */
233
234 /*e \brief List of available TLS ciphersuites for TLS 1.3 or below
235 *
236 * See the OpenSSL manual page for SSL_CTX_set_ciphersuites
237 * for more information on the format of this string.
238 *
239 * \default NULL
240 */
241 char *ciphersuites; /* ciphersuites in OpenSSL format */
242
243 /*e \brief Number of DH key files supplied
244 *
245 * Must not be greater than 1 if RTI_SUPPORT_OSSL_DECODER is defined.
246 *
247 * \default 0
248 */
250
251 /*e \brief List of available DH key files
252 *
253 * OpenSSL 3 does not allow generating a file with fewer than 512 bits.
254 * According to
255 * https://www.openssl.org/docs/man3.0/man3/SSL_CTX_set0_tmp_dh_pkey.html ,
256 * "Applications may supply their own DH parameters instead of using the
257 * built-in values. This approach is discouraged and applications should in
258 * preference use the built-in parameter support described above." So
259 * setting these files is not recommended.
260 *
261 * \default NULL
262 */
264
265 /*e \brief ID of OpenSSL cipher engine to request
266 *
267 * \default NULL
268 */
270
271 /*i \brief pre-load commands: length, name/parameter pairs */
272 DDS_Long engine_pre_cmd_length;
273 const char **engine_pre_cmd_names, **engine_pre_cmd_parameters;
274 /*i \brief post-load commands: length, name/parameter pairs */
275 DDS_Long engine_post_cmd_length;
276 const char **engine_post_cmd_names, **engine_post_cmd_parameters;
277};
278
279/*i \ingroup RTITLS_Plugin
280 \brief Set of TLS properties for required renegotiation.
281 */
282struct RTITLS_Renegotiate {
283 /*i \brief Force renegotiation after connection open for time period
284 *
285 * \default DDS_DURATION_INFINITE
286 */
287 struct DDS_Duration_t force_after_time;
288
289 /*i \brief Force renegotiation after amount of data transferred
290 *
291 * Data sent or received, measured in total unencryted length (0 = no force)
292 *
293 * \default 0
294 */
295 DDS_UnsignedLong force_after_Kbytes;
296
297 /*i \brief Require renegotiation to complete with this period
298 *
299 * \default DDS_DURATION_INFINITE
300 */
301 struct DDS_Duration_t completion_period;
302};
303
304/*i */
305typedef enum {
306 RTITLS_PROTOCOL_TLS = 0,
307 RTITLS_PROTOCOL_DTLS = 1
308} RTITLS_Protocol_t;
309
310/*e \ingroup RTITLS_Plugin
311 \brief Full set of TLS properties
312
313 Should be initialized with RTITLS_Plugin#RTITLS_OPENSSL_CONFIGURATION_DEFAULT
314 */
316 /*e \brief Verification properties */
318 /*e \brief Identity properties */
320 /*e \brief Cipher properties */
322 /*i \brief Renegotiation properties */
323 struct RTITLS_Renegotiate renegotiate;
324};
325
326/*e \ingroup RTITLS_Plugin
327 \brief Use this to initialize a RTITLS_Verfication structure.
328
329 \showinitializer
330*/
331#define RTITLS_VERIFY_DEFAULT { \
332 NULL, NULL, NULL, /* ca_file, ca_path, ca */ \
333 -1, /* verify_depth (no depth limit) */ \
334 NULL, /* callback (use default verify callback) */ \
335 NULL /* crl_file */ }
336
337/*e \ingroup RTITLS_Plugin
338 \brief Use this to initialize a RTITLS_Identity structure.
339
340 \showinitializer
341*/
342#define RTITLS_IDENTITY_DEFAULT { \
343 NULL, /* certificate_chain */ \
344 NULL, /* certificate_chain_file */ \
345 NULL, /* private_key_password */ \
346 NULL, /* private_key */ \
347 NULL, /* private_key_file */ \
348 NULL, /* rsa_private_key */ \
349 NULL /* rsa_private_key_file */ }
350
351/*e \ingroup RTITLS_Plugin
352 \brief Cipher list string for default channel (encrypted) */
353#define RTITLS_CIPHER_LIST_DEFAULT "AES:ALL:!aNULL:!eNULL:+RC4:@STRENGTH"
354
355/*e \ingroup RTITLS_Plugin
356 \brief Cipher list string for default channel (encrypted, no low-strength) */
357#define RTITLS_CIPHER_LIST_ENCRYPT_HIGH "AES:ALL:!aNULL:!eNULL:!LOW:!EXP:+RC4:@STRENGTH"
358
359/*e \ingroup RTITLS_Plugin
360 \brief Cipher list string for authentication-only channel (no encryption) */
361#define RTITLS_CIPHER_LIST_UNENCRYPTED "aNULL"
362
363/*e \ingroup RTITLS_Plugin
364 \brief Use this to initialize a RTITLS_Ciphers structure.
365
366 \showinitializer
367*/
368#define RTITLS_CIPHER_DEFAULT { \
369 NULL, /* cipher_list */ \
370 NULL, /* ciphersuites */ \
371 0, NULL, /* dh_param_files_length, dh_param_files (no DH params) */ \
372 NULL, /* engine_id (no engine) */ \
373 0, NULL, NULL, /* engine_pre_cmd_length, engine_pre_cmd_names, engine_pre_cmd_parameters */ \
374 0, NULL, NULL /* engine_post_cmd_length, engine_post_cmd_names, engeine_post_cmd_parameters */ }
375
376/*i \ingroup RTITLS_Plugin
377 \brief Use this to initialize a RTITLS_Renegotiate structure.
378
379 \showinitializer
380*/
381#define RTITLS_RENEGOTIATE_DEFAULT { \
382 DDS_DURATION_INFINITE_VALUE, /* force_after_time */ \
383 0, /* force_after_Kbytes */ \
384 DDS_DURATION_INFINITE_VALUE /* completion_period */ }
385
386/*e \ingroup RTITLS_Plugin
387 \brief Use this to initialize a RTITLS_OpenSSL_Configuration structure.
388
389 \showinitializer
390*/
391#define RTITLS_OPENSSL_CONFIGURATION_DEFAULT { \
392 RTITLS_VERIFY_DEFAULT, /* verify */ \
393 RTITLS_IDENTITY_DEFAULT, /* identity */ \
394 RTITLS_CIPHER_DEFAULT, /* cipher */ \
395 RTITLS_RENEGOTIATE_DEFAULT /* renegotiate */ }
396
397/*e \ingroup RTITLS_Plugin
398 \brief clean up OpenSSL resources for current thread (call before exit)
399*/
400extern RTITLSDllExport
402
403/*e \ingroup RTITLS_Plugin
404 \brief Default verify callback: log errors when verification fails
405
406 See the OpenSSL manual page for SSL_CTX_set_verify for more information.
407*/
408extern int RTITLS_default_verify_callback(int ok, X509_STORE_CTX *store);
409
410/*e \ingroup RTITLS_Plugin
411 \brief Verbose verify callback: log information about successful verification
412 as well as errors when verification fails
413
414 See the OpenSSL manual page for SSL_CTX_set_verify for more information.
415*/
416extern int RTITLS_verbose_verify_callback(int ok, X509_STORE_CTX *store);
417
418/*
419 * tls is only compiled with OpenSSL support.
420 * In the future this may change to support WolfSSL.
421 */
422#if defined(RTI_OPENSSL_ARCHITECTURE) || defined(RTI_OPENSSL3_ARCHITECTURE)
423 /* methods below only supported on TLS architectures */
424
425/*i \brief verify protocol configuration struct */
426extern RTITLSDllExport
427int RTITLS_configuration_verify(
428 const struct RTITLS_OpenSSL_Configuration *config);
429
430/*i \brief configure protocol, identity based on configuration struct */
431extern RTITLSDllExport
432SSL_CTX *RTITLS_context_init(
433 RTITLS_Protocol_t protocol,
434 const struct RTITLS_OpenSSL_Configuration *config);
435
436/*i \brief clean up OpenSSL resources for context */
437extern RTITLSDllExport
438void RTITLS_context_done(SSL_CTX *context);
439
440/* ================================================================= */
441#endif /* RTI_OPENSSL_ARCHITECTURE || RTI_OPENSSL3_ARCHITECTURE */
442
443#ifdef __cplusplus
444 } /* extern "C" */
445#endif
446
447#endif /* rtitls_openssl_h */
RTICdrUnsignedLong DDS_UnsignedLong
RTICdrLong DDS_Long
int RTITLS_verbose_verify_callback(int ok, X509_STORE_CTX *store)
Verbose verify callback: log information about successful verification as well as errors when verific...
int RTITLS_default_verify_callback(int ok, X509_STORE_CTX *store)
Default verify callback: log errors when verification fails.
void RTITLS_thread_exit(void)
clean up OpenSSL resources for current thread (call before exit)
int(* RTITLS_Verify_Callback)(int preverify_ok, X509_STORE_CTX *x509_ctx)
Callback used to verify peer certificates.
Definition: rtitls_openssl.h:52
Set of TLS properties for cipher configuration.
Definition: rtitls_openssl.h:221
char * cipher_list
List of available TLS ciphers for TLS 1.2 or below.
Definition: rtitls_openssl.h:232
DDS_Long dh_param_files_length
Number of DH key files supplied.
Definition: rtitls_openssl.h:249
char * engine_id
ID of OpenSSL cipher engine to request.
Definition: rtitls_openssl.h:269
char * ciphersuites
List of available TLS ciphersuites for TLS 1.3 or below.
Definition: rtitls_openssl.h:241
struct RTITLS_DHParamFile * dh_param_files
List of available DH key files.
Definition: rtitls_openssl.h:263
Name of a Diffie-Helman (DH) key file and the length of the contained key in bits.
Definition: rtitls_openssl.h:204
char * file
Name of DH key file.
Definition: rtitls_openssl.h:209
DDS_Long bits
Length of DH key in bits.
Definition: rtitls_openssl.h:215
Set of TLS properties for identity.
Definition: rtitls_openssl.h:127
char * private_key_password
Password for private key.
Definition: rtitls_openssl.h:159
char * certificate_chain_file
File containing identifying certificate (in PEM format) or certificate chain (appending intermediate ...
Definition: rtitls_openssl.h:153
char * rsa_private_key
String containing additional RSA private key (in PEM format)
Definition: rtitls_openssl.h:188
char * rsa_private_key_file
File containing additional RSA private key (in PEM format)
Definition: rtitls_openssl.h:197
char * certificate_chain
String containing identifying certificate (in PEM format) or certificate chain (appending intermediat...
Definition: rtitls_openssl.h:138
char * private_key
String containing private key (in PEM format)
Definition: rtitls_openssl.h:169
char * private_key_file
File containing private key (in PEM format)
Definition: rtitls_openssl.h:179
Full set of TLS properties.
Definition: rtitls_openssl.h:315
struct RTITLS_Identity identity
Identity properties.
Definition: rtitls_openssl.h:319
struct RTITLS_Ciphers cipher
Cipher properties.
Definition: rtitls_openssl.h:321
struct RTITLS_Verification verify
Verification properties.
Definition: rtitls_openssl.h:317
Set of TLS properties for certificate authorities (CAs) and verification.
Definition: rtitls_openssl.h:57
char * ca_file
Name of file containing Certificate Authority certificates.
Definition: rtitls_openssl.h:69
DDS_Long verify_depth
Maximum certificate chain length for verification.
Definition: rtitls_openssl.h:102
RTITLS_Verify_Callback callback
Callback used to verify peer certificates.
Definition: rtitls_openssl.h:113
char * crl_file
Name of file containing Certificate Revocation List.
Definition: rtitls_openssl.h:121
char * ca_path
Paths to directories containing Certificate Authority certificates.
Definition: rtitls_openssl.h:82
char * ca
List of Certificate Authority certificates.
Definition: rtitls_openssl.h:95