reSIProcate
SIP stack, Dialog Usage Manager and related libraries
Loading...
Searching...
No Matches
OpenSSLOptions.cxx
Go to the documentation of this file.
1#if defined(HAVE_CONFIG_H)
2#include "config.h"
3#endif
4
5#include <stdexcept>
6
7#include <openssl/ssl.h>
8
10
11using namespace std;
12
13namespace resip
14{
15
16long
17parseOpenSSLCTXOption(const Data& optionName)
18{
19 if(optionName == "SSL_OP_ALL")
20 {
21 // Various bug workarounds that should be rather harmless.
22 return SSL_OP_ALL;
23 }
24 if(optionName == "SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION")
25 {
26 return SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION;
27 }
28 if(optionName == "SSL_OP_CIPHER_SERVER_PREFERENCE")
29 {
30 // Set on servers to choose the cipher according to server's preferences.
31 return SSL_OP_CIPHER_SERVER_PREFERENCE;
32 }
33#if defined SSL_OP_CISCO_ANYCONNECT
34 if(optionName == "SSL_OP_CISCO_ANYCONNECT")
35 {
36 // Use Cisco's version identifier of DTLS_BAD_VER (only with deprecated DTLSv1_client_method())
37 return SSL_OP_CISCO_ANYCONNECT;
38 }
39#endif
40 if(optionName == "SSL_OP_COOKIE_EXCHANGE")
41 {
42 // Turn on DTLS cookie exchange (RFC 4347 section 4.2.1); only relevant for DTLS servers
43 return SSL_OP_COOKIE_EXCHANGE;
44 }
45#if defined SSL_OP_CRYPTOPRO_TLSEXT_BUG
46 if(optionName == "SSL_OP_CRYPTOPRO_TLSEXT_BUG")
47 {
48 // Make server add server-hello extension from early version of
49 // cryptopro draft, when GOST ciphersuite is negotiated. Required for
50 // interoperability with CryptoPro CSP 3.x
51 return SSL_OP_CRYPTOPRO_TLSEXT_BUG;
52 }
53#endif
54 if(optionName == "SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS")
55 {
56 // Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
57 // in OpenSSL 0.9.6d.Usually (depending on the application protocol)
58 // the workaround is not needed.Unfortunately some broken SSL/TLS
59 // implementations cannot handle it at all, which is why we include it
60 // in SSL_OP_ALL. Added in 0.9.6e
61 return SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS;
62 }
63 if(optionName == "SSL_OP_EPHEMERAL_RSA")
64 {
65 // Obsolete in newer OpenSSL versions
66 return SSL_OP_EPHEMERAL_RSA;
67 }
68 if(optionName == "SSL_OP_LEGACY_SERVER_CONNECT")
69 {
70 // Allow initial connection to servers that don't support RI
71 return SSL_OP_LEGACY_SERVER_CONNECT;
72 }
73 if(optionName == "SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER")
74 {
75 // Obsolete in newer OpenSSL versions
76 return SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER;
77 }
78 if(optionName == "SSL_OP_MICROSOFT_SESS_ID_BUG")
79 {
80 // Obsolete in newer OpenSSL versions
81 return SSL_OP_MICROSOFT_SESS_ID_BUG;
82 }
83 if(optionName == "SSL_OP_MSIE_SSLV2_RSA_PADDING")
84 {
85 // Obsolete in newer OpenSSL versions
86 return SSL_OP_MSIE_SSLV2_RSA_PADDING;
87 }
88 if(optionName == "SSL_OP_NETSCAPE_CA_DN_BUG")
89 {
90 // Obsolete in newer OpenSSL versions
91 return SSL_OP_NETSCAPE_CA_DN_BUG;
92 }
93 if(optionName == "SSL_OP_NETSCAPE_CHALLENGE_BUG")
94 {
95 // Obsolete in newer OpenSSL versions
96 return SSL_OP_NETSCAPE_CHALLENGE_BUG;
97 }
98 if(optionName == "SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG")
99 {
100 // Obsolete in newer OpenSSL versions
101 return SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG;
102 }
103 if(optionName == "SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG")
104 {
105 // Obsolete in newer OpenSSL versions
106 return SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG;
107 }
108#if defined SSL_OP_NO_COMPRESSION
109 if(optionName == "SSL_OP_NO_COMPRESSION")
110 {
111 // Don't use compression even if supported
112 return SSL_OP_NO_COMPRESSION;
113 }
114#endif
115 if(optionName == "SSL_OP_NO_QUERY_MTU")
116 {
117 // DTLS option
118 return SSL_OP_NO_QUERY_MTU;
119 }
120 if(optionName == "SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION")
121 {
122 // As server, disallow session resumption on renegotiation
123 return SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION;
124 }
125 if(optionName == "SSL_OP_NO_SSLv2")
126 {
127 // Obsolete in newer OpenSSL versions
128 return SSL_OP_NO_SSLv2;
129 }
130 if(optionName == "SSL_OP_NO_SSLv3")
131 {
132 return SSL_OP_NO_SSLv3;
133 }
134 if(optionName == "SSL_OP_NO_TICKET")
135 {
136 // Don't use stateless session tickets (RFC 4507/5077) for session resumption
137 return SSL_OP_NO_TICKET;
138 }
139 if(optionName == "SSL_OP_NO_TLSv1")
140 {
141 return SSL_OP_NO_TLSv1;
142 }
143#ifdef SSL_OP_NO_TLSv1_1
144 if(optionName == "SSL_OP_NO_TLSv1_1")
145 {
146 return SSL_OP_NO_TLSv1_1;
147 }
148#endif
149#ifdef SSL_OP_NO_TLSv1_2
150 if(optionName == "SSL_OP_NO_TLSv1_2")
151 {
152 return SSL_OP_NO_TLSv1_2;
153 }
154#endif
155 if(optionName == "SSL_OP_PKCS1_CHECK_1")
156 {
157 // Obsolete in newer OpenSSL versions
158 return SSL_OP_PKCS1_CHECK_1;
159 }
160 if(optionName == "SSL_OP_PKCS1_CHECK_2")
161 {
162 // Obsolete in newer OpenSSL versions
163 return SSL_OP_PKCS1_CHECK_2;
164 }
165#ifdef SSL_OP_SAFARI_ECDHE_ECDSA_BUG
166 if(optionName == "SSL_OP_SAFARI_ECDHE_ECDSA_BUG")
167 {
168 return SSL_OP_SAFARI_ECDHE_ECDSA_BUG;
169 }
170#endif
171 if(optionName == "SSL_OP_SINGLE_DH_USE")
172 {
173 // Obsolete in newer OpenSSL versions
174 return SSL_OP_SINGLE_DH_USE;
175 }
176 if(optionName == "SSL_OP_SINGLE_ECDH_USE")
177 {
178 // Obsolete in newer OpenSSL versions
179 return SSL_OP_SINGLE_ECDH_USE;
180 }
181 if(optionName == "SSL_OP_SSLEAY_080_CLIENT_DH_BUG")
182 {
183 // Obsolete in newer OpenSSL versions
184 return SSL_OP_SSLEAY_080_CLIENT_DH_BUG;
185 }
186 if(optionName == "SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG")
187 {
188 // Obsolete in newer OpenSSL versions
189 return SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG;
190 }
191 if(optionName == "SSL_OP_TLS_BLOCK_PADDING_BUG")
192 {
193 // Obsolete in newer OpenSSL versions
194 return SSL_OP_TLS_BLOCK_PADDING_BUG;
195 }
196 if(optionName == "SSL_OP_TLS_D5_BUG")
197 {
198 // Obsolete in newer OpenSSL versions
199 return SSL_OP_TLS_D5_BUG;
200 }
201 if(optionName == "SSL_OP_TLS_ROLLBACK_BUG")
202 {
203 // If set, a server will allow a client to issue an SSLv3.0 version
204 // number as latest version supported in the premaster secret, even when
205 // TLSv1.0 (version 3.1) was announced in the client hello. Normally
206 // this is forbidden to prevent version rollback attacks.
207 return SSL_OP_TLS_ROLLBACK_BUG;
208 }
209#ifdef SSL_OP_NO_EXTENDED_MASTER_SECRET
210 if (optionName == "SSL_OP_NO_EXTENDED_MASTER_SECRET")
211 {
212 return SSL_OP_NO_EXTENDED_MASTER_SECRET;
213 }
214#endif
215#ifdef SSL_OP_CLEANSE_PLAINTEXT
216 if (optionName == "SSL_OP_CLEANSE_PLAINTEXT")
217 {
218 // Cleanse plaintext copies of data delivered to the application
219 return SSL_OP_CLEANSE_PLAINTEXT;
220 }
221#endif
222#ifdef SSL_OP_ENABLE_KTLS
223 if (optionName == "SSL_OP_ENABLE_KTLS")
224 {
225 return SSL_OP_ENABLE_KTLS;
226 }
227#endif
228#ifdef SSL_OP_TLSEXT_PADDING
229 if (optionName == "SSL_OP_TLSEXT_PADDING")
230 {
231 return SSL_OP_TLSEXT_PADDING;
232 }
233#endif
234#ifdef SSL_OP_IGNORE_UNEXPECTED_EOF
235 if (optionName == "SSL_OP_IGNORE_UNEXPECTED_EOF")
236 {
237 return SSL_OP_IGNORE_UNEXPECTED_EOF;
238 }
239#endif
240#ifdef SSL_OP_ALLOW_CLIENT_RENEGOTIATION
241 if (optionName == "SSL_OP_ALLOW_CLIENT_RENEGOTIATION")
242 {
243 return SSL_OP_ALLOW_CLIENT_RENEGOTIATION;
244 }
245#endif
246#ifdef SSL_OP_DISABLE_TLSEXT_CA_NAMES
247 if (optionName == "SSL_OP_DISABLE_TLSEXT_CA_NAMES")
248 {
249 return SSL_OP_DISABLE_TLSEXT_CA_NAMES;
250 }
251#endif
252#ifdef SSL_OP_ALLOW_NO_DHE_KEX
253 if (optionName == "SSL_OP_ALLOW_NO_DHE_KEX")
254 {
255 // In TLSv1.3 allow a non-(ec)dhe based kex_mode
256 return SSL_OP_ALLOW_NO_DHE_KEX;
257 }
258#endif
259#ifdef SSL_OP_NO_ENCRYPT_THEN_MAC
260 if (optionName == "SSL_OP_NO_ENCRYPT_THEN_MAC")
261 {
262 return SSL_OP_NO_ENCRYPT_THEN_MAC;
263 }
264#endif
265#ifdef SSL_OP_ENABLE_MIDDLEBOX_COMPAT
266 if (optionName == "SSL_OP_ENABLE_MIDDLEBOX_COMPAT")
267 {
268 // Enable TLSv1.3 Compatibility mode. This is on by default. A future
269 // version of OpenSSL may have this disabled by default.
270 return SSL_OP_ENABLE_MIDDLEBOX_COMPAT;
271 }
272#endif
273#ifdef SSL_OP_PRIORITIZE_CHACHA
274 if (optionName == "SSL_OP_PRIORITIZE_CHACHA")
275 {
276 // Prioritize Chacha20Poly1305 when client does. Modifies SSL_OP_CIPHER_SERVER_PREFERENCE.
277 return SSL_OP_PRIORITIZE_CHACHA;
278 }
279#endif
280#ifdef SSL_OP_NO_ANTI_REPLAY
281 if (optionName == "SSL_OP_NO_ANTI_REPLAY")
282 {
283 // Switches off automatic TLSv1.3 anti-replay protection for early data.
284 // This is a server-side option only (no effect on the client).
285 return SSL_OP_NO_ANTI_REPLAY;
286 }
287#endif
288#ifdef SSL_OP_NO_TLSv1_3
289 if (optionName == "SSL_OP_NO_TLSv1_3")
290 {
291 return SSL_OP_NO_TLSv1_3;
292 }
293#endif
294#ifdef SSL_OP_NO_DTLSv1
295 if (optionName == "SSL_OP_NO_DTLSv1")
296 {
297 return SSL_OP_NO_DTLSv1;
298 }
299#endif
300#ifdef SSL_OP_NO_DTLSv1_2
301 if (optionName == "SSL_OP_NO_DTLSv1_2")
302 {
303 return SSL_OP_NO_DTLSv1_2;
304 }
305#endif
306#ifdef SSL_OP_NO_RENEGOTIATION
307 if (optionName == "SSL_OP_NO_RENEGOTIATION")
308 {
309 return SSL_OP_NO_RENEGOTIATION;
310 }
311#endif
312#ifdef SSL_OP_NO_TX_CERTIFICATE_COMPRESSION
313 if (optionName == "SSL_OP_NO_TX_CERTIFICATE_COMPRESSION")
314 {
315 // Disable RFC8879 certificate compression: don't send compressed certificates,
316 // and ignore the extension when received.
317 return SSL_OP_NO_TX_CERTIFICATE_COMPRESSION;
318 }
319#endif
320#ifdef SSL_OP_NO_RX_CERTIFICATE_COMPRESSION
321 if (optionName == "SSL_OP_NO_RX_CERTIFICATE_COMPRESSION")
322 {
323 // Disable RFC8879 certificate compression: don't send the extension, and
324 // subsequently indicating that receiving is not supported
325 return SSL_OP_NO_RX_CERTIFICATE_COMPRESSION;
326 }
327#endif
328#ifdef SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE
329 if (optionName == "SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE")
330 {
331 return SSL_OP_ENABLE_KTLS_TX_ZEROCOPY_SENDFILE;
332 }
333#endif
334#ifdef SSL_OP_PREFER_NO_DHE_KEX
335 if (optionName == "SSL_OP_PREFER_NO_DHE_KEX")
336 {
337 return SSL_OP_PREFER_NO_DHE_KEX;
338 }
339#endif
340#ifdef SSL_OP_NO_SSL_MASK
341 if (optionName == "SSL_OP_NO_SSL_MASK")
342 {
343 // (SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2 | SSL_OP_NO_TLSv1_3)
344 return SSL_OP_NO_SSL_MASK;
345 }
346#endif
347#ifdef SSL_OP_NO_DTLS_MASK
348 if (optionName == "SSL_OP_NO_DTLS_MASK")
349 {
350 // (SSL_OP_NO_DTLSv1 | SSL_OP_NO_DTLSv1_2)
351 return SSL_OP_NO_DTLS_MASK;
352 }
353#endif
354 Data error = "Not a recognized OpenSSL option name: " + optionName;
355 throw invalid_argument(error.c_str());
356}
357
358}
359
360/* ====================================================================
361 *
362 * Copyright (c) 2026 SIP Spectrum, Inc. https://www.sipspectrum.com
363 *
364 * Redistribution and use in source and binary forms, with or without
365 * modification, are permitted provided that the following conditions
366 * are met:
367 *
368 * 1. Redistributions of source code must retain the above copyright
369 * notice, this list of conditions and the following disclaimer.
370 *
371 * 2. Redistributions in binary form must reproduce the above copyright
372 * notice, this list of conditions and the following disclaimer in
373 * the documentation and/or other materials provided with the
374 * distribution.
375 *
376 * 3. Neither the name of the author(s) nor the names of any contributors
377 * may be used to endorse or promote products derived from this software
378 * without specific prior written permission.
379 *
380 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) AND CONTRIBUTORS "AS IS" AND
381 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
382 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
383 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) OR CONTRIBUTORS BE LIABLE
384 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
385 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
386 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
387 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
388 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
389 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
390 * SUCH DAMAGE.
391 *
392 * ====================================================================
393 */
An alternative to std::string, encapsulates an arbitrary buffer of bytes.
Definition Data.hxx:90
const char * c_str() const
Returns a null-terminated string representing.
Definition Data.cxx:1097
dcm! – add UnusedChecking(_enum) below;
long parseOpenSSLCTXOption(const Data &optionName)
Converts an OpenSSL option name (eg.