summaryrefslogtreecommitdiff
path: root/src/lib/libssl
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/lib/libssl
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to '')
-rw-r--r--src/lib/libssl/LICENSE133
-rw-r--r--src/lib/libssl/Makefile127
-rw-r--r--src/lib/libssl/Symbols.list362
-rw-r--r--src/lib/libssl/bio_ssl.c596
-rw-r--r--src/lib/libssl/bs_ber.c270
-rw-r--r--src/lib/libssl/bs_cbb.c490
-rw-r--r--src/lib/libssl/bs_cbs.c616
-rw-r--r--src/lib/libssl/bytestring.h571
-rw-r--r--src/lib/libssl/d1_both.c1198
-rw-r--r--src/lib/libssl/d1_lib.c414
-rw-r--r--src/lib/libssl/d1_pkt.c1124
-rw-r--r--src/lib/libssl/d1_srtp.c266
-rw-r--r--src/lib/libssl/doc/openssl.cnf348
-rw-r--r--src/lib/libssl/doc/openssl.txt1254
-rw-r--r--src/lib/libssl/doc/standards.txt285
-rw-r--r--src/lib/libssl/dtls1.h103
-rw-r--r--src/lib/libssl/dtls_local.h232
-rw-r--r--src/lib/libssl/generate_pkgconfig.sh89
-rw-r--r--src/lib/libssl/hidden/openssl/srtp.h33
-rw-r--r--src/lib/libssl/hidden/openssl/ssl.h382
-rw-r--r--src/lib/libssl/hidden/openssl/tls1.h34
-rw-r--r--src/lib/libssl/hidden/ssl_namespace.h41
-rw-r--r--src/lib/libssl/man/BIO_f_ssl.3609
-rw-r--r--src/lib/libssl/man/DTLSv1_listen.3187
-rw-r--r--src/lib/libssl/man/Makefile134
-rw-r--r--src/lib/libssl/man/OPENSSL_init_ssl.376
-rw-r--r--src/lib/libssl/man/PEM_read_SSL_SESSION.3147
-rw-r--r--src/lib/libssl/man/SSL_CIPHER_get_name.3398
-rw-r--r--src/lib/libssl/man/SSL_COMP_add_compression_method.342
-rw-r--r--src/lib/libssl/man/SSL_CTX_add1_chain_cert.3222
-rw-r--r--src/lib/libssl/man/SSL_CTX_add_extra_chain_cert.3160
-rw-r--r--src/lib/libssl/man/SSL_CTX_add_session.3132
-rw-r--r--src/lib/libssl/man/SSL_CTX_ctrl.3122
-rw-r--r--src/lib/libssl/man/SSL_CTX_flush_sessions.3100
-rw-r--r--src/lib/libssl/man/SSL_CTX_free.3101
-rw-r--r--src/lib/libssl/man/SSL_CTX_get0_certificate.351
-rw-r--r--src/lib/libssl/man/SSL_CTX_get_ex_new_index.3124
-rw-r--r--src/lib/libssl/man/SSL_CTX_get_verify_mode.3131
-rw-r--r--src/lib/libssl/man/SSL_CTX_load_verify_locations.3238
-rw-r--r--src/lib/libssl/man/SSL_CTX_new.3345
-rw-r--r--src/lib/libssl/man/SSL_CTX_sess_number.3168
-rw-r--r--src/lib/libssl/man/SSL_CTX_sess_set_cache_size.3109
-rw-r--r--src/lib/libssl/man/SSL_CTX_sess_set_get_cb.3221
-rw-r--r--src/lib/libssl/man/SSL_CTX_sessions.386
-rw-r--r--src/lib/libssl/man/SSL_CTX_set1_groups.3163
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3305
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_cert_store.3146
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_cert_verify_callback.3163
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_cipher_list.3375
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_client_CA_list.3183
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_client_cert_cb.3191
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_default_passwd_cb.3216
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_generate_session_id.3221
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_info_callback.3233
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_keylog_callback.356
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_max_cert_list.3154
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_min_proto_version.3156
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_mode.3204
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_msg_callback.3183
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_num_tickets.363
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_options.3374
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_quiet_shutdown.3161
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_read_ahead.3144
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_security_level.3159
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_session_cache_mode.3198
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_session_id_context.3160
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_ssl_version.3146
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_timeout.3118
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_tlsext_servername_callback.3247
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_tlsext_status_cb.3238
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_tlsext_ticket_key_cb.3300
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_tlsext_use_srtp.3197
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_tmp_dh_callback.3229
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_tmp_rsa_callback.3114
-rw-r--r--src/lib/libssl/man/SSL_CTX_set_verify.3479
-rw-r--r--src/lib/libssl/man/SSL_CTX_use_certificate.3451
-rw-r--r--src/lib/libssl/man/SSL_SESSION_free.3148
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get0_cipher.394
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get0_peer.380
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get_compress_id.378
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get_ex_new_index.3134
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get_id.3112
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get_protocol_version.384
-rw-r--r--src/lib/libssl/man/SSL_SESSION_get_time.3165
-rw-r--r--src/lib/libssl/man/SSL_SESSION_has_ticket.385
-rw-r--r--src/lib/libssl/man/SSL_SESSION_is_resumable.381
-rw-r--r--src/lib/libssl/man/SSL_SESSION_new.378
-rw-r--r--src/lib/libssl/man/SSL_SESSION_print.374
-rw-r--r--src/lib/libssl/man/SSL_SESSION_set1_id_context.3113
-rw-r--r--src/lib/libssl/man/SSL_accept.3155
-rw-r--r--src/lib/libssl/man/SSL_alert_type_string.3253
-rw-r--r--src/lib/libssl/man/SSL_clear.3144
-rw-r--r--src/lib/libssl/man/SSL_connect.3154
-rw-r--r--src/lib/libssl/man/SSL_copy_session_id.379
-rw-r--r--src/lib/libssl/man/SSL_do_handshake.3152
-rw-r--r--src/lib/libssl/man/SSL_dup.362
-rw-r--r--src/lib/libssl/man/SSL_dup_CA_list.354
-rw-r--r--src/lib/libssl/man/SSL_export_keying_material.3133
-rw-r--r--src/lib/libssl/man/SSL_free.3115
-rw-r--r--src/lib/libssl/man/SSL_get_SSL_CTX.379
-rw-r--r--src/lib/libssl/man/SSL_get_certificate.364
-rw-r--r--src/lib/libssl/man/SSL_get_ciphers.3249
-rw-r--r--src/lib/libssl/man/SSL_get_client_CA_list.396
-rw-r--r--src/lib/libssl/man/SSL_get_client_random.3150
-rw-r--r--src/lib/libssl/man/SSL_get_current_cipher.3122
-rw-r--r--src/lib/libssl/man/SSL_get_default_timeout.385
-rw-r--r--src/lib/libssl/man/SSL_get_error.3217
-rw-r--r--src/lib/libssl/man/SSL_get_ex_data_X509_STORE_CTX_idx.3116
-rw-r--r--src/lib/libssl/man/SSL_get_ex_new_index.3136
-rw-r--r--src/lib/libssl/man/SSL_get_fd.3103
-rw-r--r--src/lib/libssl/man/SSL_get_finished.377
-rw-r--r--src/lib/libssl/man/SSL_get_peer_cert_chain.3107
-rw-r--r--src/lib/libssl/man/SSL_get_peer_certificate.3105
-rw-r--r--src/lib/libssl/man/SSL_get_rbio.398
-rw-r--r--src/lib/libssl/man/SSL_get_server_tmp_key.389
-rw-r--r--src/lib/libssl/man/SSL_get_session.3163
-rw-r--r--src/lib/libssl/man/SSL_get_shared_ciphers.3103
-rw-r--r--src/lib/libssl/man/SSL_get_state.3161
-rw-r--r--src/lib/libssl/man/SSL_get_verify_result.3102
-rw-r--r--src/lib/libssl/man/SSL_get_version.3123
-rw-r--r--src/lib/libssl/man/SSL_library_init.398
-rw-r--r--src/lib/libssl/man/SSL_load_client_CA_file.3185
-rw-r--r--src/lib/libssl/man/SSL_new.3110
-rw-r--r--src/lib/libssl/man/SSL_num_renegotiations.375
-rw-r--r--src/lib/libssl/man/SSL_pending.390
-rw-r--r--src/lib/libssl/man/SSL_read.3278
-rw-r--r--src/lib/libssl/man/SSL_read_early_data.3174
-rw-r--r--src/lib/libssl/man/SSL_renegotiate.3166
-rw-r--r--src/lib/libssl/man/SSL_rstate_string.3108
-rw-r--r--src/lib/libssl/man/SSL_session_reused.384
-rw-r--r--src/lib/libssl/man/SSL_set1_host.3172
-rw-r--r--src/lib/libssl/man/SSL_set1_param.3137
-rw-r--r--src/lib/libssl/man/SSL_set_SSL_CTX.367
-rw-r--r--src/lib/libssl/man/SSL_set_bio.399
-rw-r--r--src/lib/libssl/man/SSL_set_connect_state.3153
-rw-r--r--src/lib/libssl/man/SSL_set_fd.3129
-rw-r--r--src/lib/libssl/man/SSL_set_max_send_fragment.397
-rw-r--r--src/lib/libssl/man/SSL_set_psk_use_session_callback.386
-rw-r--r--src/lib/libssl/man/SSL_set_session.3119
-rw-r--r--src/lib/libssl/man/SSL_set_shutdown.3138
-rw-r--r--src/lib/libssl/man/SSL_set_tmp_ecdh.3119
-rw-r--r--src/lib/libssl/man/SSL_set_verify_result.390
-rw-r--r--src/lib/libssl/man/SSL_shutdown.3253
-rw-r--r--src/lib/libssl/man/SSL_state_string.3110
-rw-r--r--src/lib/libssl/man/SSL_want.3161
-rw-r--r--src/lib/libssl/man/SSL_write.3249
-rw-r--r--src/lib/libssl/man/d2i_SSL_SESSION.3181
-rw-r--r--src/lib/libssl/man/ssl.3353
-rw-r--r--src/lib/libssl/pqueue.c201
-rw-r--r--src/lib/libssl/pqueue.h93
-rw-r--r--src/lib/libssl/s3_cbc.c628
-rw-r--r--src/lib/libssl/s3_lib.c2534
-rw-r--r--src/lib/libssl/shlib_version3
-rw-r--r--src/lib/libssl/srtp.h148
-rw-r--r--src/lib/libssl/ssl.h2343
-rw-r--r--src/lib/libssl/ssl3.h441
-rw-r--r--src/lib/libssl/ssl_asn1.c410
-rw-r--r--src/lib/libssl/ssl_both.c577
-rw-r--r--src/lib/libssl/ssl_cert.c737
-rw-r--r--src/lib/libssl/ssl_ciph.c1631
-rw-r--r--src/lib/libssl/ssl_ciphers.c286
-rw-r--r--src/lib/libssl/ssl_clnt.c2456
-rw-r--r--src/lib/libssl/ssl_err.c676
-rw-r--r--src/lib/libssl/ssl_init.c58
-rw-r--r--src/lib/libssl/ssl_kex.c422
-rw-r--r--src/lib/libssl/ssl_lib.c3663
-rw-r--r--src/lib/libssl/ssl_local.h1463
-rw-r--r--src/lib/libssl/ssl_methods.c554
-rw-r--r--src/lib/libssl/ssl_packet.c88
-rw-r--r--src/lib/libssl/ssl_pkt.c1322
-rw-r--r--src/lib/libssl/ssl_rsa.c777
-rw-r--r--src/lib/libssl/ssl_seclevel.c479
-rw-r--r--src/lib/libssl/ssl_sess.c1347
-rw-r--r--src/lib/libssl/ssl_sigalgs.c361
-rw-r--r--src/lib/libssl/ssl_sigalgs.h71
-rw-r--r--src/lib/libssl/ssl_srvr.c2496
-rw-r--r--src/lib/libssl/ssl_stat.c596
-rw-r--r--src/lib/libssl/ssl_tlsext.c2745
-rw-r--r--src/lib/libssl/ssl_tlsext.h49
-rw-r--r--src/lib/libssl/ssl_transcript.c197
-rw-r--r--src/lib/libssl/ssl_txt.c202
-rw-r--r--src/lib/libssl/ssl_versions.c373
-rw-r--r--src/lib/libssl/t1_enc.c417
-rw-r--r--src/lib/libssl/t1_lib.c1119
-rw-r--r--src/lib/libssl/test/CAss.cnf76
-rw-r--r--src/lib/libssl/test/CAssdh.cnf24
-rw-r--r--src/lib/libssl/test/CAssdsa.cnf23
-rw-r--r--src/lib/libssl/test/CAssrsa.cnf24
-rw-r--r--src/lib/libssl/test/CAtsa.cnf163
-rw-r--r--src/lib/libssl/test/P1ss.cnf37
-rw-r--r--src/lib/libssl/test/P2ss.cnf45
-rw-r--r--src/lib/libssl/test/Sssdsa.cnf27
-rw-r--r--src/lib/libssl/test/Sssrsa.cnf26
-rw-r--r--src/lib/libssl/test/Uss.cnf36
-rw-r--r--src/lib/libssl/test/VMSca-response.11
-rw-r--r--src/lib/libssl/test/VMSca-response.22
-rw-r--r--src/lib/libssl/test/bctest111
-rw-r--r--src/lib/libssl/test/cms-examples.pl409
-rw-r--r--src/lib/libssl/test/cms-test.pl459
-rw-r--r--src/lib/libssl/test/pkcs7-1.pem15
-rw-r--r--src/lib/libssl/test/pkcs7.pem54
-rw-r--r--src/lib/libssl/test/pkits-test.pl949
-rw-r--r--src/lib/libssl/test/smcont.txt1
-rw-r--r--src/lib/libssl/test/smime-certs/smdsa1.pem34
-rw-r--r--src/lib/libssl/test/smime-certs/smdsa2.pem34
-rw-r--r--src/lib/libssl/test/smime-certs/smdsa3.pem34
-rw-r--r--src/lib/libssl/test/smime-certs/smdsap.pem9
-rw-r--r--src/lib/libssl/test/smime-certs/smroot.pem30
-rw-r--r--src/lib/libssl/test/smime-certs/smrsa1.pem31
-rw-r--r--src/lib/libssl/test/smime-certs/smrsa2.pem31
-rw-r--r--src/lib/libssl/test/smime-certs/smrsa3.pem31
-rw-r--r--src/lib/libssl/test/tcrl78
-rw-r--r--src/lib/libssl/test/test.cnf88
-rw-r--r--src/lib/libssl/test/test_aesni69
-rwxr-xr-xsrc/lib/libssl/test/test_padlock64
-rw-r--r--src/lib/libssl/test/testca51
-rw-r--r--src/lib/libssl/test/testcrl.pem16
-rw-r--r--src/lib/libssl/test/testenc54
-rw-r--r--src/lib/libssl/test/testgen44
-rw-r--r--src/lib/libssl/test/testp7.pem46
-rw-r--r--src/lib/libssl/test/testreq2.pem7
-rw-r--r--src/lib/libssl/test/testrsa.pem9
-rw-r--r--src/lib/libssl/test/testsid.pem12
-rw-r--r--src/lib/libssl/test/testss163
-rw-r--r--src/lib/libssl/test/testssl178
-rw-r--r--src/lib/libssl/test/testsslproxy10
-rw-r--r--src/lib/libssl/test/testtsa238
-rw-r--r--src/lib/libssl/test/testx509.pem10
-rw-r--r--src/lib/libssl/test/times113
-rw-r--r--src/lib/libssl/test/tpkcs748
-rw-r--r--src/lib/libssl/test/tpkcs7d41
-rw-r--r--src/lib/libssl/test/treq83
-rw-r--r--src/lib/libssl/test/trsa83
-rw-r--r--src/lib/libssl/test/tsid78
-rw-r--r--src/lib/libssl/test/tx50978
-rw-r--r--src/lib/libssl/test/v3-cert1.pem16
-rw-r--r--src/lib/libssl/test/v3-cert2.pem16
-rw-r--r--src/lib/libssl/tls1.h764
-rw-r--r--src/lib/libssl/tls12_internal.h29
-rw-r--r--src/lib/libssl/tls12_key_schedule.c291
-rw-r--r--src/lib/libssl/tls12_lib.c118
-rw-r--r--src/lib/libssl/tls12_record_layer.c1309
-rw-r--r--src/lib/libssl/tls13_client.c1060
-rw-r--r--src/lib/libssl/tls13_error.c99
-rw-r--r--src/lib/libssl/tls13_handshake.c723
-rw-r--r--src/lib/libssl/tls13_handshake.h54
-rw-r--r--src/lib/libssl/tls13_handshake_msg.c188
-rw-r--r--src/lib/libssl/tls13_internal.h447
-rw-r--r--src/lib/libssl/tls13_key_schedule.c458
-rw-r--r--src/lib/libssl/tls13_legacy.c563
-rw-r--r--src/lib/libssl/tls13_lib.c737
-rw-r--r--src/lib/libssl/tls13_quic.c191
-rw-r--r--src/lib/libssl/tls13_record.c186
-rw-r--r--src/lib/libssl/tls13_record.h66
-rw-r--r--src/lib/libssl/tls13_record_layer.c1229
-rw-r--r--src/lib/libssl/tls13_server.c1095
-rw-r--r--src/lib/libssl/tls_buffer.c257
-rw-r--r--src/lib/libssl/tls_content.c164
-rw-r--r--src/lib/libssl/tls_content.h50
-rw-r--r--src/lib/libssl/tls_internal.h101
-rw-r--r--src/lib/libssl/tls_key_share.c484
-rw-r--r--src/lib/libssl/tls_lib.c68
262 files changed, 0 insertions, 75954 deletions
diff --git a/src/lib/libssl/LICENSE b/src/lib/libssl/LICENSE
deleted file mode 100644
index 892e14a450..0000000000
--- a/src/lib/libssl/LICENSE
+++ /dev/null
@@ -1,133 +0,0 @@
1
2 LibReSSL files are retained under the copyright of the authors. New
3 additions are ISC licensed as per OpenBSD's normal licensing policy,
4 or are placed in the public domain.
5
6 The OpenSSL code is distributed under the terms of the original OpenSSL
7 licenses which follow:
8
9 LICENSE ISSUES
10 ==============
11
12 The OpenSSL toolkit stays under a dual license, i.e. both the conditions of
13 the OpenSSL License and the original SSLeay license apply to the toolkit.
14 See below for the actual license texts. In case of any license issues
15 related to OpenSSL please contact openssl-core@openssl.org.
16
17 OpenSSL License
18 ---------------
19
20/* ====================================================================
21 * Copyright (c) 1998-2011 The OpenSSL Project. All rights reserved.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 *
27 * 1. Redistributions of source code must retain the above copyright
28 * notice, this list of conditions and the following disclaimer.
29 *
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in
32 * the documentation and/or other materials provided with the
33 * distribution.
34 *
35 * 3. All advertising materials mentioning features or use of this
36 * software must display the following acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
39 *
40 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
41 * endorse or promote products derived from this software without
42 * prior written permission. For written permission, please contact
43 * openssl-core@openssl.org.
44 *
45 * 5. Products derived from this software may not be called "OpenSSL"
46 * nor may "OpenSSL" appear in their names without prior written
47 * permission of the OpenSSL Project.
48 *
49 * 6. Redistributions of any form whatsoever must retain the following
50 * acknowledgment:
51 * "This product includes software developed by the OpenSSL Project
52 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
55 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
58 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
60 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
61 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
62 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
63 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
64 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
65 * OF THE POSSIBILITY OF SUCH DAMAGE.
66 * ====================================================================
67 *
68 * This product includes cryptographic software written by Eric Young
69 * (eay@cryptsoft.com). This product includes software written by Tim
70 * Hudson (tjh@cryptsoft.com).
71 *
72 */
73
74 Original SSLeay License
75 -----------------------
76
77/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
78 * All rights reserved.
79 *
80 * This package is an SSL implementation written
81 * by Eric Young (eay@cryptsoft.com).
82 * The implementation was written so as to conform with Netscapes SSL.
83 *
84 * This library is free for commercial and non-commercial use as long as
85 * the following conditions are aheared to. The following conditions
86 * apply to all code found in this distribution, be it the RC4, RSA,
87 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
88 * included with this distribution is covered by the same copyright terms
89 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
90 *
91 * Copyright remains Eric Young's, and as such any Copyright notices in
92 * the code are not to be removed.
93 * If this package is used in a product, Eric Young should be given attribution
94 * as the author of the parts of the library used.
95 * This can be in the form of a textual message at program startup or
96 * in documentation (online or textual) provided with the package.
97 *
98 * Redistribution and use in source and binary forms, with or without
99 * modification, are permitted provided that the following conditions
100 * are met:
101 * 1. Redistributions of source code must retain the copyright
102 * notice, this list of conditions and the following disclaimer.
103 * 2. Redistributions in binary form must reproduce the above copyright
104 * notice, this list of conditions and the following disclaimer in the
105 * documentation and/or other materials provided with the distribution.
106 * 3. All advertising materials mentioning features or use of this software
107 * must display the following acknowledgement:
108 * "This product includes cryptographic software written by
109 * Eric Young (eay@cryptsoft.com)"
110 * The word 'cryptographic' can be left out if the rouines from the library
111 * being used are not cryptographic related :-).
112 * 4. If you include any Windows specific code (or a derivative thereof) from
113 * the apps directory (application code) you must include an acknowledgement:
114 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
115 *
116 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
117 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
118 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
119 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
120 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
121 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
122 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
123 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
124 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
125 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
126 * SUCH DAMAGE.
127 *
128 * The licence and distribution terms for any publically available version or
129 * derivative of this code cannot be changed. i.e. this code cannot simply be
130 * copied and put under another distribution licence
131 * [including the GNU Public Licence.]
132 */
133
diff --git a/src/lib/libssl/Makefile b/src/lib/libssl/Makefile
deleted file mode 100644
index 652ad4238f..0000000000
--- a/src/lib/libssl/Makefile
+++ /dev/null
@@ -1,127 +0,0 @@
1# $OpenBSD: Makefile,v 1.85 2024/08/11 13:04:46 jsing Exp $
2
3.include <bsd.own.mk>
4.ifndef NOMAN
5SUBDIR= man
6.endif
7
8PC_FILES=openssl.pc libssl.pc
9
10CLEANFILES=${PC_FILES} ${VERSION_SCRIPT}
11
12LIB= ssl
13
14CFLAGS+= -Wall -Wundef
15.if ${COMPILER_VERSION:L} == "clang"
16CFLAGS+= -Werror -Wshadow
17.endif
18CFLAGS+= -DLIBRESSL_INTERNAL
19
20CFLAGS+= -DLIBRESSL_NAMESPACE
21
22.ifdef TLS1_3_DEBUG
23CFLAGS+= -DTLS13_DEBUG
24.endif
25CFLAGS+= -I${.CURDIR}
26CFLAGS+= -I${.CURDIR}/../libcrypto
27CFLAGS+= -I${.CURDIR}/../libcrypto/arch/${MACHINE_CPU}
28CFLAGS+= -I${.CURDIR}/../libcrypto/hidden
29CFLAGS+= -I${.CURDIR}/../libcrypto/bio
30CFLAGS+= -I${.CURDIR}/hidden
31
32LDADD+= -L${BSDOBJDIR}/lib/libcrypto -lcrypto
33
34VERSION_SCRIPT= Symbols.map
35SYMBOL_LIST= ${.CURDIR}/Symbols.list
36
37SRCS= \
38 bio_ssl.c \
39 bs_ber.c \
40 bs_cbb.c \
41 bs_cbs.c \
42 d1_both.c \
43 d1_lib.c \
44 d1_pkt.c \
45 d1_srtp.c \
46 pqueue.c \
47 s3_cbc.c \
48 s3_lib.c \
49 ssl_asn1.c \
50 ssl_both.c \
51 ssl_cert.c \
52 ssl_ciph.c \
53 ssl_ciphers.c \
54 ssl_clnt.c \
55 ssl_err.c \
56 ssl_init.c \
57 ssl_kex.c \
58 ssl_lib.c \
59 ssl_methods.c \
60 ssl_packet.c \
61 ssl_pkt.c \
62 ssl_rsa.c \
63 ssl_seclevel.c \
64 ssl_sess.c \
65 ssl_sigalgs.c \
66 ssl_srvr.c \
67 ssl_stat.c \
68 ssl_tlsext.c \
69 ssl_transcript.c \
70 ssl_txt.c \
71 ssl_versions.c \
72 t1_enc.c \
73 t1_lib.c \
74 tls12_key_schedule.c \
75 tls12_lib.c \
76 tls12_record_layer.c \
77 tls13_client.c \
78 tls13_error.c \
79 tls13_handshake.c \
80 tls13_handshake_msg.c \
81 tls13_key_schedule.c \
82 tls13_legacy.c \
83 tls13_lib.c \
84 tls13_quic.c \
85 tls13_record.c \
86 tls13_record_layer.c \
87 tls13_server.c \
88 tls_buffer.c \
89 tls_content.c \
90 tls_key_share.c \
91 tls_lib.c
92
93HDRS= dtls1.h srtp.h ssl.h ssl3.h tls1.h
94
95.PATH: ${.CURDIR}
96
97includes:
98 @test -d ${DESTDIR}/usr/include/openssl || \
99 mkdir ${DESTDIR}/usr/include/openssl
100 @cd ${.CURDIR}; for i in $(HDRS); do \
101 j="cmp -s $$i ${DESTDIR}/usr/include/openssl/`basename $$i` || \
102 ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 $$i\
103 ${DESTDIR}/usr/include/openssl"; \
104 echo $$j; \
105 eval "$$j"; \
106 done;
107
108${VERSION_SCRIPT}: ${SYMBOL_LIST}
109 { printf '{\n\tglobal:\n'; \
110 sed '/^[._a-zA-Z]/s/$$/;/; s/^/ /' ${SYMBOL_LIST}; \
111 printf '\n\tlocal:\n\t\t*;\n};\n'; } >$@.tmp && mv $@.tmp $@
112
113.include <bsd.lib.mk>
114
115all: ${PC_FILES}
116${PC_FILES}: ${.CURDIR}/../libcrypto/opensslv.h
117 /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR}
118
119beforeinstall:
120 nm -o lib${LIB}.a | egrep -w 'printf|fprintf' && \
121 (echo please fix stdio usage in this library; false) || true
122.for p in ${PC_FILES}
123 ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \
124 -m ${SHAREMODE} ${.OBJDIR}/$p ${DESTDIR}/usr/lib/pkgconfig/
125.endfor
126
127.include <bsd.subdir.mk>
diff --git a/src/lib/libssl/Symbols.list b/src/lib/libssl/Symbols.list
deleted file mode 100644
index 65cd3e7f86..0000000000
--- a/src/lib/libssl/Symbols.list
+++ /dev/null
@@ -1,362 +0,0 @@
1BIO_f_ssl
2BIO_new_buffer_ssl_connect
3BIO_new_ssl
4BIO_new_ssl_connect
5BIO_ssl_copy_session_id
6BIO_ssl_shutdown
7DTLS_client_method
8DTLS_method
9DTLS_server_method
10DTLSv1_2_client_method
11DTLSv1_2_method
12DTLSv1_2_server_method
13DTLSv1_client_method
14DTLSv1_method
15DTLSv1_server_method
16ERR_load_SSL_strings
17OPENSSL_init_ssl
18PEM_read_SSL_SESSION
19PEM_read_bio_SSL_SESSION
20PEM_write_SSL_SESSION
21PEM_write_bio_SSL_SESSION
22SSL_CIPHER_description
23SSL_CIPHER_find
24SSL_CIPHER_get_auth_nid
25SSL_CIPHER_get_bits
26SSL_CIPHER_get_cipher_nid
27SSL_CIPHER_get_digest_nid
28SSL_CIPHER_get_handshake_digest
29SSL_CIPHER_get_id
30SSL_CIPHER_get_kx_nid
31SSL_CIPHER_get_name
32SSL_CIPHER_get_value
33SSL_CIPHER_get_version
34SSL_CIPHER_is_aead
35SSL_COMP_get_compression_methods
36SSL_COMP_get_name
37SSL_CTX_add0_chain_cert
38SSL_CTX_add1_chain_cert
39SSL_CTX_add_client_CA
40SSL_CTX_add_session
41SSL_CTX_callback_ctrl
42SSL_CTX_check_private_key
43SSL_CTX_clear_chain_certs
44SSL_CTX_ctrl
45SSL_CTX_flush_sessions
46SSL_CTX_free
47SSL_CTX_get0_certificate
48SSL_CTX_get0_chain_certs
49SSL_CTX_get0_param
50SSL_CTX_get0_privatekey
51SSL_CTX_get_cert_store
52SSL_CTX_get_ciphers
53SSL_CTX_get_client_CA_list
54SSL_CTX_get_client_cert_cb
55SSL_CTX_get_default_passwd_cb
56SSL_CTX_get_default_passwd_cb_userdata
57SSL_CTX_get_ex_data
58SSL_CTX_get_ex_new_index
59SSL_CTX_get_info_callback
60SSL_CTX_get_keylog_callback
61SSL_CTX_get_max_early_data
62SSL_CTX_get_max_proto_version
63SSL_CTX_get_min_proto_version
64SSL_CTX_get_num_tickets
65SSL_CTX_get_quiet_shutdown
66SSL_CTX_get_security_level
67SSL_CTX_get_ssl_method
68SSL_CTX_get_timeout
69SSL_CTX_get_verify_callback
70SSL_CTX_get_verify_depth
71SSL_CTX_get_verify_mode
72SSL_CTX_load_verify_locations
73SSL_CTX_load_verify_mem
74SSL_CTX_new
75SSL_CTX_remove_session
76SSL_CTX_sess_get_get_cb
77SSL_CTX_sess_get_new_cb
78SSL_CTX_sess_get_remove_cb
79SSL_CTX_sess_set_get_cb
80SSL_CTX_sess_set_new_cb
81SSL_CTX_sess_set_remove_cb
82SSL_CTX_sessions
83SSL_CTX_set0_chain
84SSL_CTX_set1_cert_store
85SSL_CTX_set1_chain
86SSL_CTX_set1_groups
87SSL_CTX_set1_groups_list
88SSL_CTX_set1_param
89SSL_CTX_set_alpn_protos
90SSL_CTX_set_alpn_select_cb
91SSL_CTX_set_cert_store
92SSL_CTX_set_cert_verify_callback
93SSL_CTX_set_cipher_list
94SSL_CTX_set_ciphersuites
95SSL_CTX_set_client_CA_list
96SSL_CTX_set_client_cert_cb
97SSL_CTX_set_cookie_generate_cb
98SSL_CTX_set_cookie_verify_cb
99SSL_CTX_set_default_passwd_cb
100SSL_CTX_set_default_passwd_cb_userdata
101SSL_CTX_set_default_verify_paths
102SSL_CTX_set_ex_data
103SSL_CTX_set_generate_session_id
104SSL_CTX_set_info_callback
105SSL_CTX_set_keylog_callback
106SSL_CTX_set_max_early_data
107SSL_CTX_set_max_proto_version
108SSL_CTX_set_min_proto_version
109SSL_CTX_set_msg_callback
110SSL_CTX_set_next_proto_select_cb
111SSL_CTX_set_next_protos_advertised_cb
112SSL_CTX_set_num_tickets
113SSL_CTX_set_post_handshake_auth
114SSL_CTX_set_purpose
115SSL_CTX_set_quic_method
116SSL_CTX_set_quiet_shutdown
117SSL_CTX_set_security_level
118SSL_CTX_set_session_id_context
119SSL_CTX_set_ssl_version
120SSL_CTX_set_timeout
121SSL_CTX_set_tlsext_use_srtp
122SSL_CTX_set_tmp_dh_callback
123SSL_CTX_set_tmp_ecdh_callback
124SSL_CTX_set_tmp_rsa_callback
125SSL_CTX_set_trust
126SSL_CTX_set_verify
127SSL_CTX_set_verify_depth
128SSL_CTX_up_ref
129SSL_CTX_use_PrivateKey
130SSL_CTX_use_PrivateKey_ASN1
131SSL_CTX_use_PrivateKey_file
132SSL_CTX_use_RSAPrivateKey
133SSL_CTX_use_RSAPrivateKey_ASN1
134SSL_CTX_use_RSAPrivateKey_file
135SSL_CTX_use_certificate
136SSL_CTX_use_certificate_ASN1
137SSL_CTX_use_certificate_chain_file
138SSL_CTX_use_certificate_chain_mem
139SSL_CTX_use_certificate_file
140SSL_SESSION_free
141SSL_SESSION_get0_cipher
142SSL_SESSION_get0_id_context
143SSL_SESSION_get0_peer
144SSL_SESSION_get_compress_id
145SSL_SESSION_get_ex_data
146SSL_SESSION_get_ex_new_index
147SSL_SESSION_get_id
148SSL_SESSION_get_master_key
149SSL_SESSION_get_max_early_data
150SSL_SESSION_get_protocol_version
151SSL_SESSION_get_ticket_lifetime_hint
152SSL_SESSION_get_time
153SSL_SESSION_get_timeout
154SSL_SESSION_has_ticket
155SSL_SESSION_is_resumable
156SSL_SESSION_new
157SSL_SESSION_print
158SSL_SESSION_print_fp
159SSL_SESSION_set1_id
160SSL_SESSION_set1_id_context
161SSL_SESSION_set_ex_data
162SSL_SESSION_set_max_early_data
163SSL_SESSION_set_time
164SSL_SESSION_set_timeout
165SSL_SESSION_up_ref
166SSL_accept
167SSL_add0_chain_cert
168SSL_add1_chain_cert
169SSL_add_client_CA
170SSL_add_dir_cert_subjects_to_stack
171SSL_add_file_cert_subjects_to_stack
172SSL_alert_desc_string
173SSL_alert_desc_string_long
174SSL_alert_type_string
175SSL_alert_type_string_long
176SSL_cache_hit
177SSL_callback_ctrl
178SSL_check_private_key
179SSL_clear
180SSL_clear_chain_certs
181SSL_connect
182SSL_copy_session_id
183SSL_ctrl
184SSL_do_handshake
185SSL_dup
186SSL_dup_CA_list
187SSL_export_keying_material
188SSL_free
189SSL_get0_alpn_selected
190SSL_get0_chain_certs
191SSL_get0_next_proto_negotiated
192SSL_get0_param
193SSL_get0_peername
194SSL_get0_verified_chain
195SSL_get1_session
196SSL_get1_supported_ciphers
197SSL_get_SSL_CTX
198SSL_get_certificate
199SSL_get_cipher_list
200SSL_get_ciphers
201SSL_get_client_CA_list
202SSL_get_client_ciphers
203SSL_get_client_random
204SSL_get_current_cipher
205SSL_get_current_compression
206SSL_get_current_expansion
207SSL_get_default_timeout
208SSL_get_early_data_status
209SSL_get_error
210SSL_get_ex_data
211SSL_get_ex_data_X509_STORE_CTX_idx
212SSL_get_ex_new_index
213SSL_get_fd
214SSL_get_finished
215SSL_get_info_callback
216SSL_get_max_early_data
217SSL_get_max_proto_version
218SSL_get_min_proto_version
219SSL_get_num_tickets
220SSL_get_peer_cert_chain
221SSL_get_peer_certificate
222SSL_get_peer_finished
223SSL_get_peer_quic_transport_params
224SSL_get_peer_signature_type_nid
225SSL_get_privatekey
226SSL_get_quiet_shutdown
227SSL_get_rbio
228SSL_get_read_ahead
229SSL_get_rfd
230SSL_get_security_level
231SSL_get_selected_srtp_profile
232SSL_get_server_random
233SSL_get_servername
234SSL_get_servername_type
235SSL_get_session
236SSL_get_shared_ciphers
237SSL_get_shutdown
238SSL_get_signature_type_nid
239SSL_get_srtp_profiles
240SSL_get_ssl_method
241SSL_get_verify_callback
242SSL_get_verify_depth
243SSL_get_verify_mode
244SSL_get_verify_result
245SSL_get_version
246SSL_get_wbio
247SSL_get_wfd
248SSL_has_matching_session_id
249SSL_is_dtls
250SSL_is_quic
251SSL_is_server
252SSL_library_init
253SSL_load_client_CA_file
254SSL_load_error_strings
255SSL_new
256SSL_peek
257SSL_peek_ex
258SSL_pending
259SSL_process_quic_post_handshake
260SSL_provide_quic_data
261SSL_quic_max_handshake_flight_len
262SSL_quic_read_level
263SSL_quic_write_level
264SSL_read
265SSL_read_early_data
266SSL_read_ex
267SSL_renegotiate
268SSL_renegotiate_abbreviated
269SSL_renegotiate_pending
270SSL_rstate_string
271SSL_rstate_string_long
272SSL_select_next_proto
273SSL_set0_chain
274SSL_set0_rbio
275SSL_set1_chain
276SSL_set1_groups
277SSL_set1_groups_list
278SSL_set1_host
279SSL_set1_param
280SSL_set_SSL_CTX
281SSL_set_accept_state
282SSL_set_alpn_protos
283SSL_set_bio
284SSL_set_cipher_list
285SSL_set_ciphersuites
286SSL_set_client_CA_list
287SSL_set_connect_state
288SSL_set_ex_data
289SSL_set_fd
290SSL_set_generate_session_id
291SSL_set_hostflags
292SSL_set_info_callback
293SSL_set_max_early_data
294SSL_set_max_proto_version
295SSL_set_min_proto_version
296SSL_set_msg_callback
297SSL_set_num_tickets
298SSL_set_post_handshake_auth
299SSL_set_psk_use_session_callback
300SSL_set_purpose
301SSL_set_quic_method
302SSL_set_quic_transport_params
303SSL_set_quic_use_legacy_codepoint
304SSL_set_quiet_shutdown
305SSL_set_read_ahead
306SSL_set_rfd
307SSL_set_security_level
308SSL_set_session
309SSL_set_session_id_context
310SSL_set_session_secret_cb
311SSL_set_session_ticket_ext
312SSL_set_session_ticket_ext_cb
313SSL_set_shutdown
314SSL_set_ssl_method
315SSL_set_state
316SSL_set_tlsext_use_srtp
317SSL_set_tmp_dh_callback
318SSL_set_tmp_ecdh_callback
319SSL_set_tmp_rsa_callback
320SSL_set_trust
321SSL_set_verify
322SSL_set_verify_depth
323SSL_set_verify_result
324SSL_set_wfd
325SSL_shutdown
326SSL_state
327SSL_state_string
328SSL_state_string_long
329SSL_up_ref
330SSL_use_PrivateKey
331SSL_use_PrivateKey_ASN1
332SSL_use_PrivateKey_file
333SSL_use_RSAPrivateKey
334SSL_use_RSAPrivateKey_ASN1
335SSL_use_RSAPrivateKey_file
336SSL_use_certificate
337SSL_use_certificate_ASN1
338SSL_use_certificate_chain_file
339SSL_use_certificate_file
340SSL_verify_client_post_handshake
341SSL_version
342SSL_want
343SSL_write
344SSL_write_early_data
345SSL_write_ex
346SSLv23_client_method
347SSLv23_method
348SSLv23_server_method
349TLS_client_method
350TLS_method
351TLS_server_method
352TLSv1_1_client_method
353TLSv1_1_method
354TLSv1_1_server_method
355TLSv1_2_client_method
356TLSv1_2_method
357TLSv1_2_server_method
358TLSv1_client_method
359TLSv1_method
360TLSv1_server_method
361d2i_SSL_SESSION
362i2d_SSL_SESSION
diff --git a/src/lib/libssl/bio_ssl.c b/src/lib/libssl/bio_ssl.c
deleted file mode 100644
index 6dd1699606..0000000000
--- a/src/lib/libssl/bio_ssl.c
+++ /dev/null
@@ -1,596 +0,0 @@
1/* $OpenBSD: bio_ssl.c,v 1.40 2023/07/19 13:34:33 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <errno.h>
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63
64#include <openssl/bio.h>
65#include <openssl/crypto.h>
66#include <openssl/err.h>
67#include <openssl/ssl.h>
68
69#include "bio_local.h"
70#include "ssl_local.h"
71
72static int ssl_write(BIO *h, const char *buf, int num);
73static int ssl_read(BIO *h, char *buf, int size);
74static int ssl_puts(BIO *h, const char *str);
75static long ssl_ctrl(BIO *h, int cmd, long arg1, void *arg2);
76static int ssl_new(BIO *h);
77static int ssl_free(BIO *data);
78static long ssl_callback_ctrl(BIO *h, int cmd, BIO_info_cb *fp);
79typedef struct bio_ssl_st {
80 SSL *ssl; /* The ssl handle :-) */
81 /* re-negotiate every time the total number of bytes is this size */
82 int num_renegotiates;
83 unsigned long renegotiate_count;
84 unsigned long byte_count;
85 unsigned long renegotiate_timeout;
86 time_t last_time;
87} BIO_SSL;
88
89static const BIO_METHOD methods_sslp = {
90 .type = BIO_TYPE_SSL,
91 .name = "ssl",
92 .bwrite = ssl_write,
93 .bread = ssl_read,
94 .bputs = ssl_puts,
95 .ctrl = ssl_ctrl,
96 .create = ssl_new,
97 .destroy = ssl_free,
98 .callback_ctrl = ssl_callback_ctrl,
99};
100
101const BIO_METHOD *
102BIO_f_ssl(void)
103{
104 return (&methods_sslp);
105}
106LSSL_ALIAS(BIO_f_ssl);
107
108static int
109ssl_new(BIO *bi)
110{
111 BIO_SSL *bs;
112
113 bs = calloc(1, sizeof(BIO_SSL));
114 if (bs == NULL) {
115 SSLerrorx(ERR_R_MALLOC_FAILURE);
116 return (0);
117 }
118 bi->init = 0;
119 bi->ptr = (char *)bs;
120 bi->flags = 0;
121 return (1);
122}
123LSSL_ALIAS(BIO_f_ssl);
124
125static int
126ssl_free(BIO *a)
127{
128 BIO_SSL *bs;
129
130 if (a == NULL)
131 return (0);
132 bs = (BIO_SSL *)a->ptr;
133 if (bs->ssl != NULL)
134 SSL_shutdown(bs->ssl);
135 if (a->shutdown) {
136 if (a->init && (bs->ssl != NULL))
137 SSL_free(bs->ssl);
138 a->init = 0;
139 a->flags = 0;
140 }
141 free(a->ptr);
142 return (1);
143}
144
145static int
146ssl_read(BIO *b, char *out, int outl)
147{
148 int ret = 1;
149 BIO_SSL *sb;
150 SSL *ssl;
151 int retry_reason = 0;
152 int r = 0;
153
154 if (out == NULL)
155 return (0);
156 sb = (BIO_SSL *)b->ptr;
157 ssl = sb->ssl;
158
159 BIO_clear_retry_flags(b);
160
161 ret = SSL_read(ssl, out, outl);
162
163 switch (SSL_get_error(ssl, ret)) {
164 case SSL_ERROR_NONE:
165 if (ret <= 0)
166 break;
167 if (sb->renegotiate_count > 0) {
168 sb->byte_count += ret;
169 if (sb->byte_count > sb->renegotiate_count) {
170 sb->byte_count = 0;
171 sb->num_renegotiates++;
172 SSL_renegotiate(ssl);
173 r = 1;
174 }
175 }
176 if ((sb->renegotiate_timeout > 0) && (!r)) {
177 time_t tm;
178
179 tm = time(NULL);
180 if (tm > sb->last_time + sb->renegotiate_timeout) {
181 sb->last_time = tm;
182 sb->num_renegotiates++;
183 SSL_renegotiate(ssl);
184 }
185 }
186
187 break;
188 case SSL_ERROR_WANT_READ:
189 BIO_set_retry_read(b);
190 break;
191 case SSL_ERROR_WANT_WRITE:
192 BIO_set_retry_write(b);
193 break;
194 case SSL_ERROR_WANT_X509_LOOKUP:
195 BIO_set_retry_special(b);
196 retry_reason = BIO_RR_SSL_X509_LOOKUP;
197 break;
198 case SSL_ERROR_WANT_ACCEPT:
199 BIO_set_retry_special(b);
200 retry_reason = BIO_RR_ACCEPT;
201 break;
202 case SSL_ERROR_WANT_CONNECT:
203 BIO_set_retry_special(b);
204 retry_reason = BIO_RR_CONNECT;
205 break;
206 case SSL_ERROR_SYSCALL:
207 case SSL_ERROR_SSL:
208 case SSL_ERROR_ZERO_RETURN:
209 default:
210 break;
211 }
212
213 b->retry_reason = retry_reason;
214 return (ret);
215}
216
217static int
218ssl_write(BIO *b, const char *out, int outl)
219{
220 int ret, r = 0;
221 int retry_reason = 0;
222 SSL *ssl;
223 BIO_SSL *bs;
224
225 if (out == NULL)
226 return (0);
227 bs = (BIO_SSL *)b->ptr;
228 ssl = bs->ssl;
229
230 BIO_clear_retry_flags(b);
231
232/* ret=SSL_do_handshake(ssl);
233 if (ret > 0) */
234 ret = SSL_write(ssl, out, outl);
235
236 switch (SSL_get_error(ssl, ret)) {
237 case SSL_ERROR_NONE:
238 if (ret <= 0)
239 break;
240 if (bs->renegotiate_count > 0) {
241 bs->byte_count += ret;
242 if (bs->byte_count > bs->renegotiate_count) {
243 bs->byte_count = 0;
244 bs->num_renegotiates++;
245 SSL_renegotiate(ssl);
246 r = 1;
247 }
248 }
249 if ((bs->renegotiate_timeout > 0) && (!r)) {
250 time_t tm;
251
252 tm = time(NULL);
253 if (tm > bs->last_time + bs->renegotiate_timeout) {
254 bs->last_time = tm;
255 bs->num_renegotiates++;
256 SSL_renegotiate(ssl);
257 }
258 }
259 break;
260 case SSL_ERROR_WANT_WRITE:
261 BIO_set_retry_write(b);
262 break;
263 case SSL_ERROR_WANT_READ:
264 BIO_set_retry_read(b);
265 break;
266 case SSL_ERROR_WANT_X509_LOOKUP:
267 BIO_set_retry_special(b);
268 retry_reason = BIO_RR_SSL_X509_LOOKUP;
269 break;
270 case SSL_ERROR_WANT_CONNECT:
271 BIO_set_retry_special(b);
272 retry_reason = BIO_RR_CONNECT;
273 case SSL_ERROR_SYSCALL:
274 case SSL_ERROR_SSL:
275 default:
276 break;
277 }
278
279 b->retry_reason = retry_reason;
280 return (ret);
281}
282
283static long
284ssl_ctrl(BIO *b, int cmd, long num, void *ptr)
285{
286 SSL **sslp, *ssl;
287 BIO_SSL *bs;
288 BIO *dbio, *bio;
289 long ret = 1;
290
291 bs = (BIO_SSL *)b->ptr;
292 ssl = bs->ssl;
293 if ((ssl == NULL) && (cmd != BIO_C_SET_SSL))
294 return (0);
295 switch (cmd) {
296 case BIO_CTRL_RESET:
297 SSL_shutdown(ssl);
298
299 if (ssl->handshake_func == ssl->method->ssl_connect)
300 SSL_set_connect_state(ssl);
301 else if (ssl->handshake_func == ssl->method->ssl_accept)
302 SSL_set_accept_state(ssl);
303
304 SSL_clear(ssl);
305
306 if (b->next_bio != NULL)
307 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
308 else if (ssl->rbio != NULL)
309 ret = BIO_ctrl(ssl->rbio, cmd, num, ptr);
310 else
311 ret = 1;
312 break;
313 case BIO_CTRL_INFO:
314 ret = 0;
315 break;
316 case BIO_C_SSL_MODE:
317 if (num) /* client mode */
318 SSL_set_connect_state(ssl);
319 else
320 SSL_set_accept_state(ssl);
321 break;
322 case BIO_C_SET_SSL_RENEGOTIATE_TIMEOUT:
323 ret = bs->renegotiate_timeout;
324 if (num < 60)
325 num = 5;
326 bs->renegotiate_timeout = (unsigned long)num;
327 bs->last_time = time(NULL);
328 break;
329 case BIO_C_SET_SSL_RENEGOTIATE_BYTES:
330 ret = bs->renegotiate_count;
331 if ((long)num >=512)
332 bs->renegotiate_count = (unsigned long)num;
333 break;
334 case BIO_C_GET_SSL_NUM_RENEGOTIATES:
335 ret = bs->num_renegotiates;
336 break;
337 case BIO_C_SET_SSL:
338 if (ssl != NULL) {
339 ssl_free(b);
340 if (!ssl_new(b))
341 return 0;
342 }
343 b->shutdown = (int)num;
344 ssl = (SSL *)ptr;
345 ((BIO_SSL *)b->ptr)->ssl = ssl;
346 bio = SSL_get_rbio(ssl);
347 if (bio != NULL) {
348 if (b->next_bio != NULL)
349 BIO_push(bio, b->next_bio);
350 b->next_bio = bio;
351 CRYPTO_add(&bio->references, 1, CRYPTO_LOCK_BIO);
352 }
353 b->init = 1;
354 break;
355 case BIO_C_GET_SSL:
356 if (ptr != NULL) {
357 sslp = (SSL **)ptr;
358 *sslp = ssl;
359 } else
360 ret = 0;
361 break;
362 case BIO_CTRL_GET_CLOSE:
363 ret = b->shutdown;
364 break;
365 case BIO_CTRL_SET_CLOSE:
366 b->shutdown = (int)num;
367 break;
368 case BIO_CTRL_WPENDING:
369 ret = BIO_ctrl(ssl->wbio, cmd, num, ptr);
370 break;
371 case BIO_CTRL_PENDING:
372 ret = SSL_pending(ssl);
373 if (ret == 0)
374 ret = BIO_pending(ssl->rbio);
375 break;
376 case BIO_CTRL_FLUSH:
377 BIO_clear_retry_flags(b);
378 ret = BIO_ctrl(ssl->wbio, cmd, num, ptr);
379 BIO_copy_next_retry(b);
380 break;
381 case BIO_CTRL_PUSH:
382 if ((b->next_bio != NULL) && (b->next_bio != ssl->rbio)) {
383 SSL_set_bio(ssl, b->next_bio, b->next_bio);
384 CRYPTO_add(&b->next_bio->references, 1,
385 CRYPTO_LOCK_BIO);
386 }
387 break;
388 case BIO_CTRL_POP:
389 /* Only detach if we are the BIO explicitly being popped */
390 if (b == ptr) {
391 /* Shouldn't happen in practice because the
392 * rbio and wbio are the same when pushed.
393 */
394 if (ssl->rbio != ssl->wbio)
395 BIO_free_all(ssl->wbio);
396 if (b->next_bio != NULL)
397 CRYPTO_add(&b->next_bio->references, -1, CRYPTO_LOCK_BIO);
398 ssl->wbio = NULL;
399 ssl->rbio = NULL;
400 }
401 break;
402 case BIO_C_DO_STATE_MACHINE:
403 BIO_clear_retry_flags(b);
404
405 b->retry_reason = 0;
406 ret = (int)SSL_do_handshake(ssl);
407
408 switch (SSL_get_error(ssl, (int)ret)) {
409 case SSL_ERROR_WANT_READ:
410 BIO_set_flags(b,
411 BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY);
412 break;
413 case SSL_ERROR_WANT_WRITE:
414 BIO_set_flags(b,
415 BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY);
416 break;
417 case SSL_ERROR_WANT_CONNECT:
418 BIO_set_flags(b,
419 BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY);
420 b->retry_reason = b->next_bio->retry_reason;
421 break;
422 default:
423 break;
424 }
425 break;
426 case BIO_CTRL_DUP:
427 dbio = (BIO *)ptr;
428 if (((BIO_SSL *)dbio->ptr)->ssl != NULL)
429 SSL_free(((BIO_SSL *)dbio->ptr)->ssl);
430 ((BIO_SSL *)dbio->ptr)->ssl = SSL_dup(ssl);
431 ((BIO_SSL *)dbio->ptr)->renegotiate_count =
432 ((BIO_SSL *)b->ptr)->renegotiate_count;
433 ((BIO_SSL *)dbio->ptr)->byte_count =
434 ((BIO_SSL *)b->ptr)->byte_count;
435 ((BIO_SSL *)dbio->ptr)->renegotiate_timeout =
436 ((BIO_SSL *)b->ptr)->renegotiate_timeout;
437 ((BIO_SSL *)dbio->ptr)->last_time =
438 ((BIO_SSL *)b->ptr)->last_time;
439 ret = (((BIO_SSL *)dbio->ptr)->ssl != NULL);
440 break;
441 case BIO_C_GET_FD:
442 ret = BIO_ctrl(ssl->rbio, cmd, num, ptr);
443 break;
444 case BIO_CTRL_SET_CALLBACK:
445 {
446 ret = 0;
447 }
448 break;
449 case BIO_CTRL_GET_CALLBACK:
450 {
451 void (**fptr)(const SSL *xssl, int type, int val);
452
453 fptr = (void (**)(const SSL *xssl, int type, int val))
454 ptr;
455 *fptr = SSL_get_info_callback(ssl);
456 }
457 break;
458 default:
459 ret = BIO_ctrl(ssl->rbio, cmd, num, ptr);
460 break;
461 }
462 return (ret);
463}
464
465static long
466ssl_callback_ctrl(BIO *b, int cmd, BIO_info_cb *fp)
467{
468 SSL *ssl;
469 BIO_SSL *bs;
470 long ret = 1;
471
472 bs = (BIO_SSL *)b->ptr;
473 ssl = bs->ssl;
474 switch (cmd) {
475 case BIO_CTRL_SET_CALLBACK:
476 {
477 /* FIXME: setting this via a completely different prototype
478 seems like a crap idea */
479 SSL_set_info_callback(ssl,
480 (void (*)(const SSL *, int, int))fp);
481 }
482 break;
483 default:
484 ret = BIO_callback_ctrl(ssl->rbio, cmd, fp);
485 break;
486 }
487 return (ret);
488}
489
490static int
491ssl_puts(BIO *bp, const char *str)
492{
493 int n, ret;
494
495 n = strlen(str);
496 ret = BIO_write(bp, str, n);
497 return (ret);
498}
499
500BIO *
501BIO_new_buffer_ssl_connect(SSL_CTX *ctx)
502{
503 BIO *ret = NULL, *buf = NULL, *ssl = NULL;
504
505 if ((buf = BIO_new(BIO_f_buffer())) == NULL)
506 goto err;
507 if ((ssl = BIO_new_ssl_connect(ctx)) == NULL)
508 goto err;
509 if ((ret = BIO_push(buf, ssl)) == NULL)
510 goto err;
511 return (ret);
512
513 err:
514 BIO_free(buf);
515 BIO_free(ssl);
516 return (NULL);
517}
518LSSL_ALIAS(BIO_new_buffer_ssl_connect);
519
520BIO *
521BIO_new_ssl_connect(SSL_CTX *ctx)
522{
523 BIO *ret = NULL, *con = NULL, *ssl = NULL;
524
525 if ((con = BIO_new(BIO_s_connect())) == NULL)
526 goto err;
527 if ((ssl = BIO_new_ssl(ctx, 1)) == NULL)
528 goto err;
529 if ((ret = BIO_push(ssl, con)) == NULL)
530 goto err;
531 return (ret);
532
533 err:
534 BIO_free(con);
535 BIO_free(ssl);
536 return (NULL);
537}
538LSSL_ALIAS(BIO_new_ssl_connect);
539
540BIO *
541BIO_new_ssl(SSL_CTX *ctx, int client)
542{
543 BIO *ret;
544 SSL *ssl;
545
546 if ((ret = BIO_new(BIO_f_ssl())) == NULL)
547 goto err;
548 if ((ssl = SSL_new(ctx)) == NULL)
549 goto err;
550
551 if (client)
552 SSL_set_connect_state(ssl);
553 else
554 SSL_set_accept_state(ssl);
555
556 BIO_set_ssl(ret, ssl, BIO_CLOSE);
557 return (ret);
558
559 err:
560 BIO_free(ret);
561 return (NULL);
562}
563LSSL_ALIAS(BIO_new_ssl);
564
565int
566BIO_ssl_copy_session_id(BIO *t, BIO *f)
567{
568 t = BIO_find_type(t, BIO_TYPE_SSL);
569 f = BIO_find_type(f, BIO_TYPE_SSL);
570 if ((t == NULL) || (f == NULL))
571 return (0);
572 if ((((BIO_SSL *)t->ptr)->ssl == NULL) ||
573 (((BIO_SSL *)f->ptr)->ssl == NULL))
574 return (0);
575 if (!SSL_copy_session_id(((BIO_SSL *)t->ptr)->ssl,
576 ((BIO_SSL *)f->ptr)->ssl))
577 return (0);
578 return (1);
579}
580LSSL_ALIAS(BIO_ssl_copy_session_id);
581
582void
583BIO_ssl_shutdown(BIO *b)
584{
585 SSL *s;
586
587 while (b != NULL) {
588 if (b->method->type == BIO_TYPE_SSL) {
589 s = ((BIO_SSL *)b->ptr)->ssl;
590 SSL_shutdown(s);
591 break;
592 }
593 b = b->next_bio;
594 }
595}
596LSSL_ALIAS(BIO_ssl_shutdown);
diff --git a/src/lib/libssl/bs_ber.c b/src/lib/libssl/bs_ber.c
deleted file mode 100644
index 923ec06f3d..0000000000
--- a/src/lib/libssl/bs_ber.c
+++ /dev/null
@@ -1,270 +0,0 @@
1/* $OpenBSD: bs_ber.c,v 1.13 2025/03/28 12:13:03 tb Exp $ */
2/*
3 * Copyright (c) 2014, Google Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdint.h>
19#include <string.h>
20
21#include "bytestring.h"
22
23/*
24 * kMaxDepth is a just a sanity limit. The code should be such that the length
25 * of the input being processes always decreases. None the less, a very large
26 * input could otherwise cause the stack to overflow.
27 */
28static const unsigned int kMaxDepth = 2048;
29
30/* Non-strict version that allows a relaxed DER with indefinite form. */
31static int
32cbs_nonstrict_get_any_asn1_element(CBS *cbs, CBS *out, unsigned int *out_tag,
33 size_t *out_header_len)
34{
35 return cbs_get_any_asn1_element_internal(cbs, out,
36 out_tag, out_header_len, 0);
37}
38
39/*
40 * cbs_find_indefinite walks an ASN.1 structure in |orig_in| and sets
41 * |*indefinite_found| depending on whether an indefinite length element was
42 * found. The value of |orig_in| is not modified.
43 *
44 * Returns one on success (i.e. |*indefinite_found| was set) and zero on error.
45 */
46static int
47cbs_find_indefinite(const CBS *orig_in, char *indefinite_found,
48 unsigned int depth)
49{
50 CBS in;
51
52 if (depth > kMaxDepth)
53 return 0;
54
55 CBS_init(&in, CBS_data(orig_in), CBS_len(orig_in));
56
57 while (CBS_len(&in) > 0) {
58 CBS contents;
59 unsigned int tag;
60 size_t header_len;
61
62 if (!cbs_nonstrict_get_any_asn1_element(&in, &contents, &tag,
63 &header_len))
64 return 0;
65
66 /* Indefinite form not allowed by DER. */
67 if (CBS_len(&contents) == header_len && header_len > 0 &&
68 CBS_data(&contents)[header_len - 1] == 0x80) {
69 *indefinite_found = 1;
70 return 1;
71 }
72 if (tag & CBS_ASN1_CONSTRUCTED) {
73 if (!CBS_skip(&contents, header_len) ||
74 !cbs_find_indefinite(&contents, indefinite_found,
75 depth + 1))
76 return 0;
77 }
78 }
79
80 *indefinite_found = 0;
81 return 1;
82}
83
84/*
85 * is_primitive_type returns true if |tag| likely a primitive type. Normally
86 * one can just test the "constructed" bit in the tag but, in BER, even
87 * primitive tags can have the constructed bit if they have indefinite
88 * length.
89 */
90static char
91is_primitive_type(unsigned int tag)
92{
93 return (tag & 0xc0) == 0 &&
94 (tag & 0x1f) != (CBS_ASN1_SEQUENCE & 0x1f) &&
95 (tag & 0x1f) != (CBS_ASN1_SET & 0x1f);
96}
97
98/*
99 * is_eoc returns true if |header_len| and |contents|, as returned by
100 * |cbs_nonstrict_get_any_asn1_element|, indicate an "end of contents" (EOC)
101 * value.
102 */
103static char
104is_eoc(size_t header_len, CBS *contents)
105{
106 const unsigned char eoc[] = {0x0, 0x0};
107
108 return header_len == 2 && CBS_mem_equal(contents, eoc, 2);
109}
110
111/*
112 * cbs_convert_indefinite reads data with DER encoding (but relaxed to allow
113 * indefinite form) from |in| and writes definite form DER data to |out|. If
114 * |squash_header| is set then the top-level of elements from |in| will not
115 * have their headers written. This is used when concatenating the fragments of
116 * an indefinite length, primitive value. If |looking_for_eoc| is set then any
117 * EOC elements found will cause the function to return after consuming it.
118 * It returns one on success and zero on error.
119 */
120static int
121cbs_convert_indefinite(CBS *in, CBB *out, char squash_header,
122 char looking_for_eoc, unsigned int depth)
123{
124 if (depth > kMaxDepth)
125 return 0;
126
127 while (CBS_len(in) > 0) {
128 CBS contents;
129 unsigned int tag;
130 size_t header_len;
131 CBB *out_contents, out_contents_storage;
132
133 if (!cbs_nonstrict_get_any_asn1_element(in, &contents, &tag,
134 &header_len))
135 return 0;
136
137 out_contents = out;
138
139 if (CBS_len(&contents) == header_len) {
140 if (is_eoc(header_len, &contents))
141 return looking_for_eoc;
142
143 if (header_len > 0 &&
144 CBS_data(&contents)[header_len - 1] == 0x80) {
145 /*
146 * This is an indefinite length element. If
147 * it's a SEQUENCE or SET then we just need to
148 * write the out the contents as normal, but
149 * with a concrete length prefix.
150 *
151 * If it's a something else then the contents
152 * will be a series of DER elements of the same
153 * type which need to be concatenated.
154 */
155 const char context_specific = (tag & 0xc0)
156 == 0x80;
157 char squash_child_headers =
158 is_primitive_type(tag);
159
160 /*
161 * This is a hack, but it sufficies to handle
162 * NSS's output. If we find an indefinite
163 * length, context-specific tag with a definite,
164 * primitive tag inside it, then we assume that
165 * the context-specific tag is implicit and the
166 * tags within are fragments of a primitive type
167 * that need to be concatenated.
168 */
169 if (context_specific &&
170 (tag & CBS_ASN1_CONSTRUCTED)) {
171 CBS in_copy, inner_contents;
172 unsigned int inner_tag;
173 size_t inner_header_len;
174
175 CBS_init(&in_copy, CBS_data(in),
176 CBS_len(in));
177 if (!cbs_nonstrict_get_any_asn1_element(
178 &in_copy, &inner_contents,
179 &inner_tag, &inner_header_len))
180 return 0;
181
182 if (CBS_len(&inner_contents) >
183 inner_header_len &&
184 is_primitive_type(inner_tag))
185 squash_child_headers = 1;
186 }
187
188 if (!squash_header) {
189 unsigned int out_tag = tag;
190
191 if (squash_child_headers)
192 out_tag &=
193 ~CBS_ASN1_CONSTRUCTED;
194
195 if (!CBB_add_asn1(out,
196 &out_contents_storage, out_tag))
197 return 0;
198
199 out_contents = &out_contents_storage;
200 }
201
202 if (!cbs_convert_indefinite(in, out_contents,
203 squash_child_headers,
204 1 /* looking for eoc */, depth + 1))
205 return 0;
206
207 if (out_contents != out && !CBB_flush(out))
208 return 0;
209
210 continue;
211 }
212 }
213
214 if (!squash_header) {
215 if (!CBB_add_asn1(out, &out_contents_storage, tag))
216 return 0;
217
218 out_contents = &out_contents_storage;
219 }
220
221 if (!CBS_skip(&contents, header_len))
222 return 0;
223
224 if (tag & CBS_ASN1_CONSTRUCTED) {
225 if (!cbs_convert_indefinite(&contents, out_contents,
226 0 /* don't squash header */,
227 0 /* not looking for eoc */, depth + 1))
228 return 0;
229 } else {
230 if (!CBB_add_bytes(out_contents, CBS_data(&contents),
231 CBS_len(&contents)))
232 return 0;
233 }
234
235 if (out_contents != out && !CBB_flush(out))
236 return 0;
237 }
238
239 return looking_for_eoc == 0;
240}
241
242int
243CBS_asn1_indefinite_to_definite(CBS *in, uint8_t **out, size_t *out_len)
244{
245 CBB cbb;
246
247 /*
248 * First, do a quick walk to find any indefinite-length elements. Most
249 * of the time we hope that there aren't any and thus we can quickly
250 * return.
251 */
252 char conversion_needed;
253 if (!cbs_find_indefinite(in, &conversion_needed, 0))
254 return 0;
255
256 if (!conversion_needed) {
257 *out = NULL;
258 *out_len = 0;
259 return 1;
260 }
261
262 if (!CBB_init(&cbb, CBS_len(in)))
263 return 0;
264 if (!cbs_convert_indefinite(in, &cbb, 0, 0, 0)) {
265 CBB_cleanup(&cbb);
266 return 0;
267 }
268
269 return CBB_finish(&cbb, out, out_len);
270}
diff --git a/src/lib/libssl/bs_cbb.c b/src/lib/libssl/bs_cbb.c
deleted file mode 100644
index 9d7ad7d46d..0000000000
--- a/src/lib/libssl/bs_cbb.c
+++ /dev/null
@@ -1,490 +0,0 @@
1/* $OpenBSD: bs_cbb.c,v 1.30 2024/06/22 15:25:06 jsing Exp $ */
2/*
3 * Copyright (c) 2014, Google Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdint.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include "bytestring.h"
23
24#define CBB_INITIAL_SIZE 64
25
26static int
27cbb_init(CBB *cbb, uint8_t *buf, size_t cap)
28{
29 struct cbb_buffer_st *base;
30
31 if ((base = calloc(1, sizeof(struct cbb_buffer_st))) == NULL)
32 return 0;
33
34 base->buf = buf;
35 base->len = 0;
36 base->cap = cap;
37 base->can_resize = 1;
38
39 cbb->base = base;
40 cbb->is_top_level = 1;
41
42 return 1;
43}
44
45int
46CBB_init(CBB *cbb, size_t initial_capacity)
47{
48 uint8_t *buf = NULL;
49
50 memset(cbb, 0, sizeof(*cbb));
51
52 if (initial_capacity == 0)
53 initial_capacity = CBB_INITIAL_SIZE;
54
55 if ((buf = calloc(1, initial_capacity)) == NULL)
56 return 0;
57
58 if (!cbb_init(cbb, buf, initial_capacity)) {
59 free(buf);
60 return 0;
61 }
62
63 return 1;
64}
65
66int
67CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len)
68{
69 memset(cbb, 0, sizeof(*cbb));
70
71 if (!cbb_init(cbb, buf, len))
72 return 0;
73
74 cbb->base->can_resize = 0;
75
76 return 1;
77}
78
79void
80CBB_cleanup(CBB *cbb)
81{
82 if (cbb->base) {
83 if (cbb->base->can_resize)
84 freezero(cbb->base->buf, cbb->base->cap);
85 free(cbb->base);
86 }
87 cbb->base = NULL;
88 cbb->child = NULL;
89}
90
91static int
92cbb_buffer_add(struct cbb_buffer_st *base, uint8_t **out, size_t len)
93{
94 size_t newlen;
95
96 if (base == NULL)
97 return 0;
98
99 newlen = base->len + len;
100 if (newlen < base->len)
101 /* Overflow */
102 return 0;
103
104 if (newlen > base->cap) {
105 size_t newcap = base->cap * 2;
106 uint8_t *newbuf;
107
108 if (!base->can_resize)
109 return 0;
110
111 if (newcap < base->cap || newcap < newlen)
112 newcap = newlen;
113
114 newbuf = recallocarray(base->buf, base->cap, newcap, 1);
115 if (newbuf == NULL)
116 return 0;
117
118 base->buf = newbuf;
119 base->cap = newcap;
120 }
121
122 if (out)
123 *out = base->buf + base->len;
124
125 base->len = newlen;
126 return 1;
127}
128
129static int
130cbb_add_u(CBB *cbb, uint32_t v, size_t len_len)
131{
132 uint8_t *buf;
133 size_t i;
134
135 if (len_len == 0)
136 return 1;
137
138 if (len_len > 4)
139 return 0;
140
141 if (!CBB_flush(cbb) || !cbb_buffer_add(cbb->base, &buf, len_len))
142 return 0;
143
144 for (i = len_len - 1; i < len_len; i--) {
145 buf[i] = v;
146 v >>= 8;
147 }
148 return 1;
149}
150
151int
152CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len)
153{
154 if (!cbb->is_top_level)
155 return 0;
156
157 if (!CBB_flush(cbb))
158 return 0;
159
160 if (cbb->base->can_resize && (out_data == NULL || out_len == NULL))
161 /*
162 * |out_data| and |out_len| can only be NULL if the CBB is
163 * fixed.
164 */
165 return 0;
166
167 if (out_data != NULL && *out_data != NULL)
168 return 0;
169
170 if (out_data != NULL)
171 *out_data = cbb->base->buf;
172
173 if (out_len != NULL)
174 *out_len = cbb->base->len;
175
176 cbb->base->buf = NULL;
177 CBB_cleanup(cbb);
178 return 1;
179}
180
181/*
182 * CBB_flush recurses and then writes out any pending length prefix. The current
183 * length of the underlying base is taken to be the length of the
184 * length-prefixed data.
185 */
186int
187CBB_flush(CBB *cbb)
188{
189 size_t child_start, i, len;
190
191 if (cbb->base == NULL)
192 return 0;
193
194 if (cbb->child == NULL || cbb->pending_len_len == 0)
195 return 1;
196
197 child_start = cbb->offset + cbb->pending_len_len;
198
199 if (!CBB_flush(cbb->child) || child_start < cbb->offset ||
200 cbb->base->len < child_start)
201 return 0;
202
203 len = cbb->base->len - child_start;
204
205 if (cbb->pending_is_asn1) {
206 /*
207 * For ASN.1, we assumed that we were using short form which
208 * only requires a single byte for the length octet.
209 *
210 * If it turns out that we need long form, we have to move
211 * the contents along in order to make space for more length
212 * octets.
213 */
214 size_t len_len = 1; /* total number of length octets */
215 uint8_t initial_length_byte;
216
217 /* We already wrote 1 byte for the length. */
218 if (cbb->pending_len_len != 1)
219 return 0;
220
221 /* Check for long form */
222 if (len > 0xfffffffe)
223 return 0; /* 0xffffffff is reserved */
224 else if (len > 0xffffff)
225 len_len = 5;
226 else if (len > 0xffff)
227 len_len = 4;
228 else if (len > 0xff)
229 len_len = 3;
230 else if (len > 0x7f)
231 len_len = 2;
232
233 if (len_len == 1) {
234 /* For short form, the initial byte is the length. */
235 initial_length_byte = len;
236 len = 0;
237
238 } else {
239 /*
240 * For long form, the initial byte is the number of
241 * subsequent length octets (plus bit 8 set).
242 */
243 initial_length_byte = 0x80 | (len_len - 1);
244
245 /*
246 * We need to move the contents along in order to make
247 * space for the long form length octets.
248 */
249 size_t extra_bytes = len_len - 1;
250 if (!cbb_buffer_add(cbb->base, NULL, extra_bytes))
251 return 0;
252
253 memmove(cbb->base->buf + child_start + extra_bytes,
254 cbb->base->buf + child_start, len);
255 }
256 cbb->base->buf[cbb->offset++] = initial_length_byte;
257 cbb->pending_len_len = len_len - 1;
258 }
259
260 for (i = cbb->pending_len_len - 1; i < cbb->pending_len_len; i--) {
261 cbb->base->buf[cbb->offset + i] = len;
262 len >>= 8;
263 }
264 if (len != 0)
265 return 0;
266
267 cbb->child->base = NULL;
268 cbb->child = NULL;
269 cbb->pending_len_len = 0;
270 cbb->pending_is_asn1 = 0;
271 cbb->offset = 0;
272
273 return 1;
274}
275
276void
277CBB_discard_child(CBB *cbb)
278{
279 if (cbb->child == NULL)
280 return;
281
282 cbb->base->len = cbb->offset;
283
284 cbb->child->base = NULL;
285 cbb->child = NULL;
286 cbb->pending_len_len = 0;
287 cbb->pending_is_asn1 = 0;
288 cbb->offset = 0;
289}
290
291static int
292cbb_add_length_prefixed(CBB *cbb, CBB *out_contents, size_t len_len)
293{
294 uint8_t *prefix_bytes;
295
296 if (!CBB_flush(cbb))
297 return 0;
298
299 cbb->offset = cbb->base->len;
300 if (!cbb_buffer_add(cbb->base, &prefix_bytes, len_len))
301 return 0;
302
303 memset(prefix_bytes, 0, len_len);
304 memset(out_contents, 0, sizeof(CBB));
305 out_contents->base = cbb->base;
306 cbb->child = out_contents;
307 cbb->pending_len_len = len_len;
308 cbb->pending_is_asn1 = 0;
309
310 return 1;
311}
312
313int
314CBB_add_u8_length_prefixed(CBB *cbb, CBB *out_contents)
315{
316 return cbb_add_length_prefixed(cbb, out_contents, 1);
317}
318
319int
320CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents)
321{
322 return cbb_add_length_prefixed(cbb, out_contents, 2);
323}
324
325int
326CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents)
327{
328 return cbb_add_length_prefixed(cbb, out_contents, 3);
329}
330
331int
332CBB_add_u32_length_prefixed(CBB *cbb, CBB *out_contents)
333{
334 return cbb_add_length_prefixed(cbb, out_contents, 4);
335}
336
337int
338CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned int tag)
339{
340 if (tag > UINT8_MAX)
341 return 0;
342
343 /* Long form identifier octets are not supported. */
344 if ((tag & 0x1f) == 0x1f)
345 return 0;
346
347 /* Short-form identifier octet only needs a single byte */
348 if (!CBB_flush(cbb) || !CBB_add_u8(cbb, tag))
349 return 0;
350
351 /*
352 * Add 1 byte to cover the short-form length octet case. If it turns
353 * out we need long-form, it will be extended later.
354 */
355 cbb->offset = cbb->base->len;
356 if (!CBB_add_u8(cbb, 0))
357 return 0;
358
359 memset(out_contents, 0, sizeof(CBB));
360 out_contents->base = cbb->base;
361 cbb->child = out_contents;
362 cbb->pending_len_len = 1;
363 cbb->pending_is_asn1 = 1;
364
365 return 1;
366}
367
368int
369CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len)
370{
371 uint8_t *dest;
372
373 if (!CBB_flush(cbb) || !cbb_buffer_add(cbb->base, &dest, len))
374 return 0;
375
376 memcpy(dest, data, len);
377 return 1;
378}
379
380int
381CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len)
382{
383 if (!CBB_flush(cbb) || !cbb_buffer_add(cbb->base, out_data, len))
384 return 0;
385
386 memset(*out_data, 0, len);
387 return 1;
388}
389
390int
391CBB_add_u8(CBB *cbb, size_t value)
392{
393 if (value > UINT8_MAX)
394 return 0;
395
396 return cbb_add_u(cbb, (uint32_t)value, 1);
397}
398
399int
400CBB_add_u16(CBB *cbb, size_t value)
401{
402 if (value > UINT16_MAX)
403 return 0;
404
405 return cbb_add_u(cbb, (uint32_t)value, 2);
406}
407
408int
409CBB_add_u24(CBB *cbb, size_t value)
410{
411 if (value > 0xffffffUL)
412 return 0;
413
414 return cbb_add_u(cbb, (uint32_t)value, 3);
415}
416
417int
418CBB_add_u32(CBB *cbb, size_t value)
419{
420 if (value > 0xffffffffUL)
421 return 0;
422
423 return cbb_add_u(cbb, (uint32_t)value, 4);
424}
425
426int
427CBB_add_u64(CBB *cbb, uint64_t value)
428{
429 uint32_t a, b;
430
431 a = value >> 32;
432 b = value & 0xffffffff;
433
434 if (!CBB_add_u32(cbb, a))
435 return 0;
436 return CBB_add_u32(cbb, b);
437}
438
439int
440CBB_add_asn1_uint64(CBB *cbb, uint64_t value)
441{
442 CBB child;
443 size_t i;
444 int started = 0;
445
446 if (!CBB_add_asn1(cbb, &child, CBS_ASN1_INTEGER))
447 return 0;
448
449 for (i = 0; i < 8; i++) {
450 uint8_t byte = (value >> 8 * (7 - i)) & 0xff;
451
452 /*
453 * ASN.1 restriction: first 9 bits cannot be all zeroes or
454 * all ones. Since this function only encodes unsigned
455 * integers, the only concerns are not encoding leading
456 * zeros and adding a padding byte if necessary.
457 *
458 * In practice, this means:
459 * 1) Skip leading octets of all zero bits in the value
460 * 2) After skipping the leading zero octets, if the next 9
461 * bits are all ones, add an all zero prefix octet (and
462 * set the high bit of the prefix octet if negative).
463 *
464 * Additionally, for an unsigned value, add an all zero
465 * prefix if the high bit of the first octet would be one.
466 */
467 if (!started) {
468 if (byte == 0)
469 /* Don't encode leading zeros. */
470 continue;
471
472 /*
473 * If the high bit is set, add a padding byte to make it
474 * unsigned.
475 */
476 if ((byte & 0x80) && !CBB_add_u8(&child, 0))
477 return 0;
478
479 started = 1;
480 }
481 if (!CBB_add_u8(&child, byte))
482 return 0;
483 }
484
485 /* 0 is encoded as a single 0, not the empty string. */
486 if (!started && !CBB_add_u8(&child, 0))
487 return 0;
488
489 return CBB_flush(cbb);
490}
diff --git a/src/lib/libssl/bs_cbs.c b/src/lib/libssl/bs_cbs.c
deleted file mode 100644
index 76e3bd2a89..0000000000
--- a/src/lib/libssl/bs_cbs.c
+++ /dev/null
@@ -1,616 +0,0 @@
1/* $OpenBSD: bs_cbs.c,v 1.25 2024/05/25 15:14:26 tb Exp $ */
2/*
3 * Copyright (c) 2014, Google Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdint.h>
19#include <stdlib.h>
20#include <string.h>
21
22#include "bytestring.h"
23
24void
25CBS_init(CBS *cbs, const uint8_t *data, size_t len)
26{
27 cbs->data = data;
28 cbs->initial_len = len;
29 cbs->len = len;
30}
31
32void
33CBS_dup(const CBS *cbs, CBS *out)
34{
35 CBS_init(out, CBS_data(cbs), CBS_len(cbs));
36 out->initial_len = cbs->initial_len;
37}
38
39static int
40cbs_get(CBS *cbs, const uint8_t **p, size_t n)
41{
42 if (cbs->len < n)
43 return 0;
44
45 *p = cbs->data;
46 cbs->data += n;
47 cbs->len -= n;
48 return 1;
49}
50
51static int
52cbs_peek(CBS *cbs, const uint8_t **p, size_t n)
53{
54 if (cbs->len < n)
55 return 0;
56
57 *p = cbs->data;
58 return 1;
59}
60
61size_t
62CBS_offset(const CBS *cbs)
63{
64 return cbs->initial_len - cbs->len;
65}
66
67int
68CBS_skip(CBS *cbs, size_t len)
69{
70 const uint8_t *dummy;
71 return cbs_get(cbs, &dummy, len);
72}
73
74const uint8_t *
75CBS_data(const CBS *cbs)
76{
77 return cbs->data;
78}
79
80size_t
81CBS_len(const CBS *cbs)
82{
83 return cbs->len;
84}
85
86int
87CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len)
88{
89 free(*out_ptr);
90 *out_ptr = NULL;
91 *out_len = 0;
92
93 if (cbs->len == 0)
94 return 1;
95
96 if ((*out_ptr = malloc(cbs->len)) == NULL)
97 return 0;
98
99 memcpy(*out_ptr, cbs->data, cbs->len);
100
101 *out_len = cbs->len;
102 return 1;
103}
104
105int
106CBS_strdup(const CBS *cbs, char **out_ptr)
107{
108 free(*out_ptr);
109 *out_ptr = NULL;
110
111 if (CBS_contains_zero_byte(cbs))
112 return 0;
113
114 *out_ptr = strndup((const char *)cbs->data, cbs->len);
115 return (*out_ptr != NULL);
116}
117
118int
119CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len, size_t *copied)
120{
121 if (dst_len < cbs->len)
122 return 0;
123
124 memmove(dst, cbs->data, cbs->len);
125
126 if (copied != NULL)
127 *copied = cbs->len;
128
129 return 1;
130}
131
132int
133CBS_contains_zero_byte(const CBS *cbs)
134{
135 return memchr(cbs->data, 0, cbs->len) != NULL;
136}
137
138int
139CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len)
140{
141 if (len != cbs->len)
142 return 0;
143
144 return timingsafe_memcmp(cbs->data, data, len) == 0;
145}
146
147static int
148cbs_get_u(CBS *cbs, uint32_t *out, size_t len)
149{
150 uint32_t result = 0;
151 size_t i;
152 const uint8_t *data;
153
154 if (len < 1 || len > 4)
155 return 0;
156
157 if (!cbs_get(cbs, &data, len))
158 return 0;
159
160 for (i = 0; i < len; i++) {
161 result <<= 8;
162 result |= data[i];
163 }
164 *out = result;
165 return 1;
166}
167
168int
169CBS_get_u8(CBS *cbs, uint8_t *out)
170{
171 const uint8_t *v;
172
173 if (!cbs_get(cbs, &v, 1))
174 return 0;
175
176 *out = *v;
177 return 1;
178}
179
180int
181CBS_get_u16(CBS *cbs, uint16_t *out)
182{
183 uint32_t v;
184
185 if (!cbs_get_u(cbs, &v, 2))
186 return 0;
187
188 *out = v;
189 return 1;
190}
191
192int
193CBS_get_u24(CBS *cbs, uint32_t *out)
194{
195 return cbs_get_u(cbs, out, 3);
196}
197
198int
199CBS_get_u32(CBS *cbs, uint32_t *out)
200{
201 return cbs_get_u(cbs, out, 4);
202}
203
204int
205CBS_get_u64(CBS *cbs, uint64_t *out)
206{
207 uint32_t a, b;
208
209 if (cbs->len < 8)
210 return 0;
211
212 if (!CBS_get_u32(cbs, &a))
213 return 0;
214 if (!CBS_get_u32(cbs, &b))
215 return 0;
216
217 *out = (uint64_t)a << 32 | b;
218 return 1;
219}
220
221int
222CBS_get_last_u8(CBS *cbs, uint8_t *out)
223{
224 if (cbs->len == 0)
225 return 0;
226
227 *out = cbs->data[cbs->len - 1];
228 cbs->len--;
229 return 1;
230}
231
232int
233CBS_get_bytes(CBS *cbs, CBS *out, size_t len)
234{
235 const uint8_t *v;
236
237 if (!cbs_get(cbs, &v, len))
238 return 0;
239
240 CBS_init(out, v, len);
241 return 1;
242}
243
244static int
245cbs_get_length_prefixed(CBS *cbs, CBS *out, size_t len_len)
246{
247 uint32_t len;
248
249 if (!cbs_get_u(cbs, &len, len_len))
250 return 0;
251
252 return CBS_get_bytes(cbs, out, len);
253}
254
255int
256CBS_get_u8_length_prefixed(CBS *cbs, CBS *out)
257{
258 return cbs_get_length_prefixed(cbs, out, 1);
259}
260
261int
262CBS_get_u16_length_prefixed(CBS *cbs, CBS *out)
263{
264 return cbs_get_length_prefixed(cbs, out, 2);
265}
266
267int
268CBS_get_u24_length_prefixed(CBS *cbs, CBS *out)
269{
270 return cbs_get_length_prefixed(cbs, out, 3);
271}
272
273static int
274cbs_peek_u(CBS *cbs, uint32_t *out, size_t len)
275{
276 uint32_t result = 0;
277 size_t i;
278 const uint8_t *data;
279
280 if (len < 1 || len > 4)
281 return 0;
282
283 if (!cbs_peek(cbs, &data, len))
284 return 0;
285
286 for (i = 0; i < len; i++) {
287 result <<= 8;
288 result |= data[i];
289 }
290 *out = result;
291 return 1;
292}
293
294int
295CBS_peek_u8(CBS *cbs, uint8_t *out)
296{
297 const uint8_t *v;
298
299 if (!cbs_peek(cbs, &v, 1))
300 return 0;
301
302 *out = *v;
303 return 1;
304}
305
306int
307CBS_peek_u16(CBS *cbs, uint16_t *out)
308{
309 uint32_t v;
310
311 if (!cbs_peek_u(cbs, &v, 2))
312 return 0;
313
314 *out = v;
315 return 1;
316}
317
318int
319CBS_peek_u24(CBS *cbs, uint32_t *out)
320{
321 return cbs_peek_u(cbs, out, 3);
322}
323
324int
325CBS_peek_u32(CBS *cbs, uint32_t *out)
326{
327 return cbs_peek_u(cbs, out, 4);
328}
329
330int
331CBS_peek_last_u8(CBS *cbs, uint8_t *out)
332{
333 if (cbs->len == 0)
334 return 0;
335
336 *out = cbs->data[cbs->len - 1];
337 return 1;
338}
339
340int
341CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned int *out_tag,
342 size_t *out_header_len)
343{
344 return cbs_get_any_asn1_element_internal(cbs, out, out_tag,
345 out_header_len, 1);
346}
347
348/*
349 * Review X.690 for details on ASN.1 DER encoding.
350 *
351 * If non-strict mode is enabled, then DER rules are relaxed
352 * for indefinite constructs (violates DER but a little closer to BER).
353 * Non-strict mode should only be used by bs_ber.c
354 *
355 * Sections 8, 10 and 11 for DER encoding
356 */
357int
358cbs_get_any_asn1_element_internal(CBS *cbs, CBS *out, unsigned int *out_tag,
359 size_t *out_header_len, int strict)
360{
361 uint8_t tag, length_byte;
362 CBS header = *cbs;
363 CBS throwaway;
364 size_t len;
365
366 if (out == NULL)
367 out = &throwaway;
368
369 /*
370 * Get identifier octet and length octet. Only 1 octet for each
371 * is a CBS limitation.
372 */
373 if (!CBS_get_u8(&header, &tag) || !CBS_get_u8(&header, &length_byte))
374 return 0;
375
376 /* CBS limitation: long form tags are not supported. */
377 if ((tag & 0x1f) == 0x1f)
378 return 0;
379
380 if (out_tag != NULL)
381 *out_tag = tag;
382
383 if ((length_byte & 0x80) == 0) {
384 /* Short form length. */
385 len = ((size_t) length_byte) + 2;
386 if (out_header_len != NULL)
387 *out_header_len = 2;
388
389 } else {
390 /* Long form length. */
391 const size_t num_bytes = length_byte & 0x7f;
392 uint32_t len32;
393
394 /* ASN.1 reserved value for future extensions */
395 if (num_bytes == 0x7f)
396 return 0;
397
398 /* Handle indefinite form length */
399 if (num_bytes == 0) {
400 /* DER encoding doesn't allow for indefinite form. */
401 if (strict)
402 return 0;
403
404 /* Primitive cannot use indefinite in BER or DER. */
405 if ((tag & CBS_ASN1_CONSTRUCTED) == 0)
406 return 0;
407
408 /* Constructed, indefinite length allowed in BER. */
409 if (out_header_len != NULL)
410 *out_header_len = 2;
411 return CBS_get_bytes(cbs, out, 2);
412 }
413
414 /* CBS limitation. */
415 if (num_bytes > 4)
416 return 0;
417
418 if (!cbs_get_u(&header, &len32, num_bytes))
419 return 0;
420
421 /* DER has a minimum length octet requirement. */
422 if (len32 < 128)
423 /* Should have used short form instead */
424 return 0;
425
426 if ((len32 >> ((num_bytes - 1) * 8)) == 0)
427 /* Length should have been at least one byte shorter. */
428 return 0;
429
430 len = len32;
431 if (len + 2 + num_bytes < len)
432 /* Overflow. */
433 return 0;
434
435 len += 2 + num_bytes;
436 if (out_header_len != NULL)
437 *out_header_len = 2 + num_bytes;
438 }
439
440 return CBS_get_bytes(cbs, out, len);
441}
442
443static int
444cbs_get_asn1(CBS *cbs, CBS *out, unsigned int tag_value, int skip_header)
445{
446 size_t header_len;
447 unsigned int tag;
448 CBS throwaway;
449
450 if (out == NULL)
451 out = &throwaway;
452
453 if (!CBS_get_any_asn1_element(cbs, out, &tag, &header_len) ||
454 tag != tag_value)
455 return 0;
456
457 if (skip_header && !CBS_skip(out, header_len))
458 return 0;
459
460 return 1;
461}
462
463int
464CBS_get_asn1(CBS *cbs, CBS *out, unsigned int tag_value)
465{
466 return cbs_get_asn1(cbs, out, tag_value, 1 /* skip header */);
467}
468
469int
470CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned int tag_value)
471{
472 return cbs_get_asn1(cbs, out, tag_value, 0 /* include header */);
473}
474
475int
476CBS_peek_asn1_tag(const CBS *cbs, unsigned int tag_value)
477{
478 if (CBS_len(cbs) < 1)
479 return 0;
480
481 /*
482 * Tag number 31 indicates the start of a long form number.
483 * This is valid in ASN.1, but CBS only supports short form.
484 */
485 if ((tag_value & 0x1f) == 0x1f)
486 return 0;
487
488 return CBS_data(cbs)[0] == tag_value;
489}
490
491/* Encoding details are in ASN.1: X.690 section 8.3 */
492int
493CBS_get_asn1_uint64(CBS *cbs, uint64_t *out)
494{
495 CBS bytes;
496 const uint8_t *data;
497 size_t i, len;
498
499 if (!CBS_get_asn1(cbs, &bytes, CBS_ASN1_INTEGER))
500 return 0;
501
502 *out = 0;
503 data = CBS_data(&bytes);
504 len = CBS_len(&bytes);
505
506 if (len == 0)
507 /* An INTEGER is encoded with at least one content octet. */
508 return 0;
509
510 if ((data[0] & 0x80) != 0)
511 /* Negative number. */
512 return 0;
513
514 if (data[0] == 0 && len > 1 && (data[1] & 0x80) == 0)
515 /* Violates smallest encoding rule: excessive leading zeros. */
516 return 0;
517
518 for (i = 0; i < len; i++) {
519 if ((*out >> 56) != 0)
520 /* Too large to represent as a uint64_t. */
521 return 0;
522
523 *out <<= 8;
524 *out |= data[i];
525 }
526
527 return 1;
528}
529
530int
531CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present, unsigned int tag)
532{
533 if (CBS_peek_asn1_tag(cbs, tag)) {
534 if (!CBS_get_asn1(cbs, out, tag))
535 return 0;
536
537 *out_present = 1;
538 } else {
539 *out_present = 0;
540 }
541 return 1;
542}
543
544int
545CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,
546 unsigned int tag)
547{
548 CBS child;
549 int present;
550
551 if (!CBS_get_optional_asn1(cbs, &child, &present, tag))
552 return 0;
553
554 if (present) {
555 if (!CBS_get_asn1(&child, out, CBS_ASN1_OCTETSTRING) ||
556 CBS_len(&child) != 0)
557 return 0;
558 } else {
559 CBS_init(out, NULL, 0);
560 }
561 if (out_present)
562 *out_present = present;
563
564 return 1;
565}
566
567int
568CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, unsigned int tag,
569 uint64_t default_value)
570{
571 CBS child;
572 int present;
573
574 if (!CBS_get_optional_asn1(cbs, &child, &present, tag))
575 return 0;
576
577 if (present) {
578 if (!CBS_get_asn1_uint64(&child, out) ||
579 CBS_len(&child) != 0)
580 return 0;
581 } else {
582 *out = default_value;
583 }
584 return 1;
585}
586
587int
588CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned int tag,
589 int default_value)
590{
591 CBS child, child2;
592 int present;
593
594 if (!CBS_get_optional_asn1(cbs, &child, &present, tag))
595 return 0;
596
597 if (present) {
598 uint8_t boolean;
599
600 if (!CBS_get_asn1(&child, &child2, CBS_ASN1_BOOLEAN) ||
601 CBS_len(&child2) != 1 || CBS_len(&child) != 0)
602 return 0;
603
604 boolean = CBS_data(&child2)[0];
605 if (boolean == 0)
606 *out = 0;
607 else if (boolean == 0xff)
608 *out = 1;
609 else
610 return 0;
611
612 } else {
613 *out = default_value;
614 }
615 return 1;
616}
diff --git a/src/lib/libssl/bytestring.h b/src/lib/libssl/bytestring.h
deleted file mode 100644
index 1d871e0236..0000000000
--- a/src/lib/libssl/bytestring.h
+++ /dev/null
@@ -1,571 +0,0 @@
1/* $OpenBSD: bytestring.h,v 1.26 2024/12/05 19:57:37 tb Exp $ */
2/*
3 * Copyright (c) 2014, Google Inc.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef OPENSSL_HEADER_BYTESTRING_H
19#define OPENSSL_HEADER_BYTESTRING_H
20
21#include <sys/types.h>
22#include <stdint.h>
23
24__BEGIN_HIDDEN_DECLS
25
26/*
27 * Bytestrings are used for parsing and building TLS and ASN.1 messages.
28 *
29 * A "CBS" (CRYPTO ByteString) represents a string of bytes in memory and
30 * provides utility functions for safely parsing length-prefixed structures
31 * like TLS and ASN.1 from it.
32 *
33 * A "CBB" (CRYPTO ByteBuilder) is a memory buffer that grows as needed and
34 * provides utility functions for building length-prefixed messages.
35 */
36
37/* CRYPTO ByteString */
38typedef struct cbs_st {
39 const uint8_t *data;
40 size_t initial_len;
41 size_t len;
42} CBS;
43
44/*
45 * CBS_init sets |cbs| to point to |data|. It does not take ownership of
46 * |data|.
47 */
48void CBS_init(CBS *cbs, const uint8_t *data, size_t len);
49
50/*
51 * CBS_skip advances |cbs| by |len| bytes. It returns one on success and zero
52 * otherwise.
53 */
54int CBS_skip(CBS *cbs, size_t len);
55
56/*
57 * CBS_data returns a pointer to the contents of |cbs|.
58 */
59const uint8_t *CBS_data(const CBS *cbs);
60
61/*
62 * CBS_len returns the number of bytes remaining in |cbs|.
63 */
64size_t CBS_len(const CBS *cbs);
65
66/*
67 * CBS_offset returns the current offset into the original data of |cbs|.
68 */
69size_t CBS_offset(const CBS *cbs);
70
71/*
72 * CBS_stow copies the current contents of |cbs| into |*out_ptr| and
73 * |*out_len|. If |*out_ptr| is not NULL, the contents are freed with
74 * free. It returns one on success and zero on allocation failure. On
75 * success, |*out_ptr| should be freed with free. If |cbs| is empty,
76 * |*out_ptr| will be NULL.
77 */
78int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len);
79
80/*
81 * CBS_strdup copies the current contents of |cbs| into |*out_ptr| as a
82 * NUL-terminated C string. If |*out_ptr| is not NULL, the contents are freed
83 * with free. It returns one on success and zero on failure. On success,
84 * |*out_ptr| should be freed with free. If |cbs| contains NUL bytes,
85 * CBS_strdup will fail.
86 */
87int CBS_strdup(const CBS *cbs, char **out_ptr);
88
89/*
90 * CBS_write_bytes writes all of the remaining data from |cbs| into |dst|
91 * if it is at most |dst_len| bytes. If |copied| is not NULL, it will be set
92 * to the amount copied. It returns one on success and zero otherwise.
93 */
94int CBS_write_bytes(const CBS *cbs, uint8_t *dst, size_t dst_len,
95 size_t *copied);
96
97/*
98 * CBS_contains_zero_byte returns one if the current contents of |cbs| contains
99 * a NUL byte and zero otherwise.
100 */
101int CBS_contains_zero_byte(const CBS *cbs);
102
103/*
104 * CBS_mem_equal compares the current contents of |cbs| with the |len| bytes
105 * starting at |data|. If they're equal, it returns one, otherwise zero. If the
106 * lengths match, it uses a constant-time comparison.
107 */
108int CBS_mem_equal(const CBS *cbs, const uint8_t *data, size_t len);
109
110/*
111 * CBS_get_u8 sets |*out| to the next uint8_t from |cbs| and advances |cbs|. It
112 * returns one on success and zero on error.
113 */
114int CBS_get_u8(CBS *cbs, uint8_t *out);
115
116/*
117 * CBS_get_u16 sets |*out| to the next, big-endian uint16_t from |cbs| and
118 * advances |cbs|. It returns one on success and zero on error.
119 */
120int CBS_get_u16(CBS *cbs, uint16_t *out);
121
122/*
123 * CBS_get_u24 sets |*out| to the next, big-endian 24-bit value from |cbs| and
124 * advances |cbs|. It returns one on success and zero on error.
125 */
126int CBS_get_u24(CBS *cbs, uint32_t *out);
127
128/*
129 * CBS_get_u32 sets |*out| to the next, big-endian uint32_t value from |cbs|
130 * and advances |cbs|. It returns one on success and zero on error.
131 */
132int CBS_get_u32(CBS *cbs, uint32_t *out);
133
134/*
135 * CBS_get_u64 sets |*out| to the next, big-endian uint64_t value from |cbs|
136 * and advances |cbs|. It returns one on success and zero on error.
137 */
138int CBS_get_u64(CBS *cbs, uint64_t *out);
139
140/*
141 * CBS_get_last_u8 sets |*out| to the last uint8_t from |cbs| and shortens
142 * |cbs|. It returns one on success and zero on error.
143 */
144int CBS_get_last_u8(CBS *cbs, uint8_t *out);
145
146/*
147 * CBS_get_bytes sets |*out| to the next |len| bytes from |cbs| and advances
148 * |cbs|. It returns one on success and zero on error.
149 */
150int CBS_get_bytes(CBS *cbs, CBS *out, size_t len);
151
152/*
153 * CBS_get_u8_length_prefixed sets |*out| to the contents of an 8-bit,
154 * length-prefixed value from |cbs| and advances |cbs| over it. It returns one
155 * on success and zero on error.
156 */
157int CBS_get_u8_length_prefixed(CBS *cbs, CBS *out);
158
159/*
160 * CBS_get_u16_length_prefixed sets |*out| to the contents of a 16-bit,
161 * big-endian, length-prefixed value from |cbs| and advances |cbs| over it. It
162 * returns one on success and zero on error.
163 */
164int CBS_get_u16_length_prefixed(CBS *cbs, CBS *out);
165
166/*
167 * CBS_get_u24_length_prefixed sets |*out| to the contents of a 24-bit,
168 * big-endian, length-prefixed value from |cbs| and advances |cbs| over it. It
169 * returns one on success and zero on error.
170 */
171int CBS_get_u24_length_prefixed(CBS *cbs, CBS *out);
172
173/*
174 * CBS_peek_u8 sets |*out| to the next uint8_t from |cbs|, but does not advance
175 * |cbs|. It returns one on success and zero on error.
176 */
177int CBS_peek_u8(CBS *cbs, uint8_t *out);
178
179/*
180 * CBS_peek_u16 sets |*out| to the next, big-endian uint16_t from |cbs|, but
181 * does not advance |cbs|. It returns one on success and zero on error.
182 */
183int CBS_peek_u16(CBS *cbs, uint16_t *out);
184
185/*
186 * CBS_peek_u24 sets |*out| to the next, big-endian 24-bit value from |cbs|, but
187 * does not advance |cbs|. It returns one on success and zero on error.
188 */
189int CBS_peek_u24(CBS *cbs, uint32_t *out);
190
191/*
192 * CBS_peek_u32 sets |*out| to the next, big-endian uint32_t value from |cbs|,
193 * but does not advance |cbs|. It returns one on success and zero on error.
194 */
195int CBS_peek_u32(CBS *cbs, uint32_t *out);
196
197/*
198 * CBS_peek_last_u8 sets |*out| to the last uint8_t from |cbs|, but does not
199 * shorten |cbs|. It returns one on success and zero on error.
200 */
201int CBS_peek_last_u8(CBS *cbs, uint8_t *out);
202
203
204/* Parsing ASN.1 */
205
206/*
207 * While an identifier can be multiple octets, this library only handles the
208 * single octet variety currently. This limits support up to tag number 30
209 * since tag number 31 is a reserved value to indicate multiple octets.
210 */
211
212/* Bits 8 and 7: class tag type: See X.690 section 8.1.2.2. */
213#define CBS_ASN1_UNIVERSAL 0x00
214#define CBS_ASN1_APPLICATION 0x40
215#define CBS_ASN1_CONTEXT_SPECIFIC 0x80
216#define CBS_ASN1_PRIVATE 0xc0
217
218/* Bit 6: Primitive or constructed: See X.690 section 8.1.2.3. */
219#define CBS_ASN1_PRIMITIVE 0x00
220#define CBS_ASN1_CONSTRUCTED 0x20
221
222/*
223 * Bits 5 to 1 are the tag number. See X.680 section 8.6 for tag numbers of
224 * the universal class.
225 */
226
227/*
228 * Common universal identifier octets.
229 * See X.690 section 8.1 and X.680 section 8.6 for universal tag numbers.
230 *
231 * Note: These definitions are the cause of some of the strange behavior in
232 * CBS's bs_ber.c.
233 *
234 * In BER, it is the sender's option to use primitive or constructed for
235 * bitstring (X.690 section 8.6.1) and octetstring (X.690 section 8.7.1).
236 *
237 * In DER, bitstring and octetstring are required to be primitive
238 * (X.690 section 10.2).
239 */
240#define CBS_ASN1_BOOLEAN (CBS_ASN1_UNIVERSAL | CBS_ASN1_PRIMITIVE | 0x1)
241#define CBS_ASN1_INTEGER (CBS_ASN1_UNIVERSAL | CBS_ASN1_PRIMITIVE | 0x2)
242#define CBS_ASN1_BITSTRING (CBS_ASN1_UNIVERSAL | CBS_ASN1_PRIMITIVE | 0x3)
243#define CBS_ASN1_OCTETSTRING (CBS_ASN1_UNIVERSAL | CBS_ASN1_PRIMITIVE | 0x4)
244#define CBS_ASN1_OBJECT (CBS_ASN1_UNIVERSAL | CBS_ASN1_PRIMITIVE | 0x6)
245#define CBS_ASN1_ENUMERATED (CBS_ASN1_UNIVERSAL | CBS_ASN1_PRIMITIVE | 0xa)
246#define CBS_ASN1_SEQUENCE (CBS_ASN1_UNIVERSAL | CBS_ASN1_CONSTRUCTED | 0x10)
247#define CBS_ASN1_SET (CBS_ASN1_UNIVERSAL | CBS_ASN1_CONSTRUCTED | 0x11)
248
249/*
250 * CBS_get_asn1 sets |*out| to the contents of DER-encoded, ASN.1 element (not
251 * including tag and length bytes) and advances |cbs| over it. The ASN.1
252 * element must match |tag_value|. It returns one on success and zero
253 * on error.
254 *
255 * Tag numbers greater than 30 are not supported (i.e. short form only).
256 */
257int CBS_get_asn1(CBS *cbs, CBS *out, unsigned int tag_value);
258
259/*
260 * CBS_get_asn1_element acts like |CBS_get_asn1| but |out| will include the
261 * ASN.1 header bytes too.
262 */
263int CBS_get_asn1_element(CBS *cbs, CBS *out, unsigned int tag_value);
264
265/*
266 * CBS_peek_asn1_tag looks ahead at the next ASN.1 tag and returns one
267 * if the next ASN.1 element on |cbs| would have tag |tag_value|. If
268 * |cbs| is empty or the tag does not match, it returns zero. Note: if
269 * it returns one, CBS_get_asn1 may still fail if the rest of the
270 * element is malformed.
271 */
272int CBS_peek_asn1_tag(const CBS *cbs, unsigned int tag_value);
273
274/*
275 * CBS_get_any_asn1_element sets |*out| to contain the next ASN.1 element from
276 * |*cbs| (including header bytes) and advances |*cbs|. It sets |*out_tag| to
277 * the tag number and |*out_header_len| to the length of the ASN.1 header.
278 * Each of |out|, |out_tag|, and |out_header_len| may be NULL to ignore
279 * the value.
280 *
281 * Tag numbers greater than 30 are not supported (i.e. short form only).
282 */
283int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned int *out_tag,
284 size_t *out_header_len);
285
286/*
287 * CBS_get_asn1_uint64 gets an ASN.1 INTEGER from |cbs| using |CBS_get_asn1|
288 * and sets |*out| to its value. It returns one on success and zero on error,
289 * where error includes the integer being negative, or too large to represent
290 * in 64 bits.
291 */
292int CBS_get_asn1_uint64(CBS *cbs, uint64_t *out);
293
294/*
295 * CBS_get_optional_asn1 gets an optional explicitly-tagged element
296 * from |cbs| tagged with |tag| and sets |*out| to its contents. If
297 * present, it sets |*out_present| to one, otherwise zero. It returns
298 * one on success, whether or not the element was present, and zero on
299 * decode failure.
300 */
301int CBS_get_optional_asn1(CBS *cbs, CBS *out, int *out_present,
302 unsigned int tag);
303
304/*
305 * CBS_get_optional_asn1_octet_string gets an optional
306 * explicitly-tagged OCTET STRING from |cbs|. If present, it sets
307 * |*out| to the string and |*out_present| to one. Otherwise, it sets
308 * |*out| to empty and |*out_present| to zero. |out_present| may be
309 * NULL. It returns one on success, whether or not the element was
310 * present, and zero on decode failure.
311 */
312int CBS_get_optional_asn1_octet_string(CBS *cbs, CBS *out, int *out_present,
313 unsigned int tag);
314
315/*
316 * CBS_get_optional_asn1_uint64 gets an optional explicitly-tagged
317 * INTEGER from |cbs|. If present, it sets |*out| to the
318 * value. Otherwise, it sets |*out| to |default_value|. It returns one
319 * on success, whether or not the element was present, and zero on
320 * decode failure.
321 */
322int CBS_get_optional_asn1_uint64(CBS *cbs, uint64_t *out, unsigned int tag,
323 uint64_t default_value);
324
325/*
326 * CBS_get_optional_asn1_bool gets an optional, explicitly-tagged BOOLEAN from
327 * |cbs|. If present, it sets |*out| to either zero or one, based on the
328 * boolean. Otherwise, it sets |*out| to |default_value|. It returns one on
329 * success, whether or not the element was present, and zero on decode
330 * failure.
331 */
332int CBS_get_optional_asn1_bool(CBS *cbs, int *out, unsigned int tag,
333 int default_value);
334
335
336/*
337 * CRYPTO ByteBuilder.
338 *
339 * |CBB| objects allow one to build length-prefixed serialisations. A |CBB|
340 * object is associated with a buffer and new buffers are created with
341 * |CBB_init|. Several |CBB| objects can point at the same buffer when a
342 * length-prefix is pending, however only a single |CBB| can be 'current' at
343 * any one time. For example, if one calls |CBB_add_u8_length_prefixed| then
344 * the new |CBB| points at the same buffer as the original. But if the original
345 * |CBB| is used then the length prefix is written out and the new |CBB| must
346 * not be used again.
347 *
348 * If one needs to force a length prefix to be written out because a |CBB| is
349 * going out of scope, use |CBB_flush|.
350 */
351
352struct cbb_buffer_st {
353 uint8_t *buf;
354
355 /* The number of valid bytes. */
356 size_t len;
357
358 /* The size of buf. */
359 size_t cap;
360
361 /*
362 * One iff |buf| is owned by this object. If not then |buf| cannot be
363 * resized.
364 */
365 char can_resize;
366};
367
368typedef struct cbb_st {
369 struct cbb_buffer_st *base;
370
371 /*
372 * offset is the offset from the start of |base->buf| to the position of any
373 * pending length-prefix.
374 */
375 size_t offset;
376
377 /* child points to a child CBB if a length-prefix is pending. */
378 struct cbb_st *child;
379
380 /*
381 * pending_len_len contains the number of bytes in a pending length-prefix,
382 * or zero if no length-prefix is pending.
383 */
384 uint8_t pending_len_len;
385
386 char pending_is_asn1;
387
388 /*
389 * is_top_level is true iff this is a top-level |CBB| (as opposed to a child
390 * |CBB|). Top-level objects are valid arguments for |CBB_finish|.
391 */
392 char is_top_level;
393} CBB;
394
395/*
396 * CBB_init initialises |cbb| with |initial_capacity|. Since a |CBB| grows as
397 * needed, the |initial_capacity| is just a hint. It returns one on success or
398 * zero on error.
399 */
400int CBB_init(CBB *cbb, size_t initial_capacity);
401
402/*
403 * CBB_init_fixed initialises |cbb| to write to |len| bytes at |buf|. Since
404 * |buf| cannot grow, trying to write more than |len| bytes will cause CBB
405 * functions to fail. It returns one on success or zero on error.
406 */
407int CBB_init_fixed(CBB *cbb, uint8_t *buf, size_t len);
408
409/*
410 * CBB_cleanup frees all resources owned by |cbb| and other |CBB| objects
411 * writing to the same buffer. This should be used in an error case where a
412 * serialisation is abandoned.
413 */
414void CBB_cleanup(CBB *cbb);
415
416/*
417 * CBB_finish completes any pending length prefix and sets |*out_data| to a
418 * malloced buffer and |*out_len| to the length of that buffer. The caller
419 * takes ownership of the buffer and, unless the buffer was fixed with
420 * |CBB_init_fixed|, must call |free| when done.
421 *
422 * It can only be called on a "top level" |CBB|, i.e. one initialised with
423 * |CBB_init| or |CBB_init_fixed|. It returns one on success and zero on
424 * error.
425 */
426int CBB_finish(CBB *cbb, uint8_t **out_data, size_t *out_len);
427
428/*
429 * CBB_flush causes any pending length prefixes to be written out and any child
430 * |CBB| objects of |cbb| to be invalidated. It returns one on success or zero
431 * on error.
432 */
433int CBB_flush(CBB *cbb);
434
435/*
436 * CBB_discard_child discards the current unflushed child of |cbb|. Neither the
437 * child's contents nor the length prefix will be included in the output.
438 */
439void CBB_discard_child(CBB *cbb);
440
441/*
442 * CBB_add_u8_length_prefixed sets |*out_contents| to a new child of |cbb|. The
443 * data written to |*out_contents| will be prefixed in |cbb| with an 8-bit
444 * length. It returns one on success or zero on error.
445 */
446int CBB_add_u8_length_prefixed(CBB *cbb, CBB *out_contents);
447
448/*
449 * CBB_add_u16_length_prefixed sets |*out_contents| to a new child of |cbb|.
450 * The data written to |*out_contents| will be prefixed in |cbb| with a 16-bit,
451 * big-endian length. It returns one on success or zero on error.
452 */
453int CBB_add_u16_length_prefixed(CBB *cbb, CBB *out_contents);
454
455/*
456 * CBB_add_u24_length_prefixed sets |*out_contents| to a new child of |cbb|.
457 * The data written to |*out_contents| will be prefixed in |cbb| with a 24-bit,
458 * big-endian length. It returns one on success or zero on error.
459 */
460int CBB_add_u24_length_prefixed(CBB *cbb, CBB *out_contents);
461
462/*
463 * CBB_add_u32_length_prefixed sets |*out_contents| to a new child of |cbb|.
464 * The data written to |*out_contents| will be prefixed in |cbb| with a 32-bit,
465 * big-endian length. It returns one on success or zero on error.
466 */
467int CBB_add_u32_length_prefixed(CBB *cbb, CBB *out_contents);
468
469/*
470 * CBB_add_asn sets |*out_contents| to a |CBB| into which the contents of an
471 * ASN.1 object can be written. The |tag| argument will be used as the tag for
472 * the object. Passing in |tag| number 31 will return in an error since only
473 * single octet identifiers are supported. It returns one on success or zero
474 * on error.
475 */
476int CBB_add_asn1(CBB *cbb, CBB *out_contents, unsigned int tag);
477
478/*
479 * CBB_add_bytes appends |len| bytes from |data| to |cbb|. It returns one on
480 * success and zero otherwise.
481 */
482int CBB_add_bytes(CBB *cbb, const uint8_t *data, size_t len);
483
484/*
485 * CBB_add_space appends |len| bytes to |cbb| and sets |*out_data| to point to
486 * the beginning of that space. The caller must then write |len| bytes of
487 * actual contents to |*out_data|. It returns one on success and zero
488 * otherwise.
489 */
490int CBB_add_space(CBB *cbb, uint8_t **out_data, size_t len);
491
492/*
493 * CBB_add_u8 appends an 8-bit number from |value| to |cbb|. It returns one on
494 * success and zero otherwise.
495 */
496int CBB_add_u8(CBB *cbb, size_t value);
497
498/*
499 * CBB_add_u8 appends a 16-bit, big-endian number from |value| to |cbb|. It
500 * returns one on success and zero otherwise.
501 */
502int CBB_add_u16(CBB *cbb, size_t value);
503
504/*
505 * CBB_add_u24 appends a 24-bit, big-endian number from |value| to |cbb|. It
506 * returns one on success and zero otherwise.
507 */
508int CBB_add_u24(CBB *cbb, size_t value);
509
510/*
511 * CBB_add_u32 appends a 32-bit, big-endian number from |value| to |cbb|. It
512 * returns one on success and zero otherwise.
513 */
514int CBB_add_u32(CBB *cbb, size_t value);
515
516/*
517 * CBB_add_u64 appends a 64-bit, big-endian number from |value| to |cbb|. It
518 * returns one on success and zero otherwise.
519 */
520int CBB_add_u64(CBB *cbb, uint64_t value);
521
522/*
523 * CBB_add_asn1_uint64 writes an ASN.1 INTEGER into |cbb| using |CBB_add_asn1|
524 * and writes |value| in its contents. It returns one on success and zero on
525 * error.
526 */
527int CBB_add_asn1_uint64(CBB *cbb, uint64_t value);
528
529#ifdef LIBRESSL_INTERNAL
530/*
531 * CBS_dup sets |out| to point to cbs's |data| and |len|. It results in two
532 * CBS that point to the same buffer.
533 */
534void CBS_dup(const CBS *cbs, CBS *out);
535
536/*
537 * cbs_get_any_asn1_element sets |*out| to contain the next ASN.1 element from
538 * |*cbs| (including header bytes) and advances |*cbs|. It sets |*out_tag| to
539 * the tag number and |*out_header_len| to the length of the ASN.1 header. If
540 * strict mode is disabled and the element has indefinite length then |*out|
541 * will only contain the header. Each of |out|, |out_tag|, and
542 * |out_header_len| may be NULL to ignore the value.
543 *
544 * Tag numbers greater than 30 are not supported (i.e. short form only).
545 */
546int cbs_get_any_asn1_element_internal(CBS *cbs, CBS *out, unsigned int *out_tag,
547 size_t *out_header_len, int strict);
548
549/*
550 * CBS_asn1_indefinite_to_definite reads an ASN.1 structure from |in|. If it
551 * finds indefinite-length elements that otherwise appear to be valid DER, it
552 * attempts to convert the DER-like data to DER and sets |*out| and
553 * |*out_length| to describe a malloced buffer containing the DER data.
554 * Additionally, |*in| will be advanced over the ASN.1 data.
555 *
556 * If it doesn't find any indefinite-length elements then it sets |*out| to
557 * NULL and |*in| is unmodified.
558 *
559 * This is NOT a conversion from BER to DER. There are many restrictions when
560 * dealing with DER data. This is only concerned with one: indefinite vs.
561 * definite form. However, this suffices to handle the PKCS#7 and PKCS#12 output
562 * from NSS.
563 *
564 * It returns one on success and zero otherwise.
565 */
566int CBS_asn1_indefinite_to_definite(CBS *in, uint8_t **out, size_t *out_len);
567#endif /* LIBRESSL_INTERNAL */
568
569__END_HIDDEN_DECLS
570
571#endif /* OPENSSL_HEADER_BYTESTRING_H */
diff --git a/src/lib/libssl/d1_both.c b/src/lib/libssl/d1_both.c
deleted file mode 100644
index e144d8f533..0000000000
--- a/src/lib/libssl/d1_both.c
+++ /dev/null
@@ -1,1198 +0,0 @@
1/* $OpenBSD: d1_both.c,v 1.85 2025/03/09 15:12:18 tb Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
60 * All rights reserved.
61 *
62 * This package is an SSL implementation written
63 * by Eric Young (eay@cryptsoft.com).
64 * The implementation was written so as to conform with Netscapes SSL.
65 *
66 * This library is free for commercial and non-commercial use as long as
67 * the following conditions are aheared to. The following conditions
68 * apply to all code found in this distribution, be it the RC4, RSA,
69 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
70 * included with this distribution is covered by the same copyright terms
71 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
72 *
73 * Copyright remains Eric Young's, and as such any Copyright notices in
74 * the code are not to be removed.
75 * If this package is used in a product, Eric Young should be given attribution
76 * as the author of the parts of the library used.
77 * This can be in the form of a textual message at program startup or
78 * in documentation (online or textual) provided with the package.
79 *
80 * Redistribution and use in source and binary forms, with or without
81 * modification, are permitted provided that the following conditions
82 * are met:
83 * 1. Redistributions of source code must retain the copyright
84 * notice, this list of conditions and the following disclaimer.
85 * 2. Redistributions in binary form must reproduce the above copyright
86 * notice, this list of conditions and the following disclaimer in the
87 * documentation and/or other materials provided with the distribution.
88 * 3. All advertising materials mentioning features or use of this software
89 * must display the following acknowledgement:
90 * "This product includes cryptographic software written by
91 * Eric Young (eay@cryptsoft.com)"
92 * The word 'cryptographic' can be left out if the rouines from the library
93 * being used are not cryptographic related :-).
94 * 4. If you include any Windows specific code (or a derivative thereof) from
95 * the apps directory (application code) you must include an acknowledgement:
96 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
97 *
98 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
99 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
102 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 * SUCH DAMAGE.
109 *
110 * The licence and distribution terms for any publically available version or
111 * derivative of this code cannot be changed. i.e. this code cannot simply be
112 * copied and put under another distribution licence
113 * [including the GNU Public Licence.]
114 */
115
116#include <limits.h>
117#include <stdio.h>
118#include <string.h>
119
120#include <openssl/buffer.h>
121#include <openssl/evp.h>
122#include <openssl/objects.h>
123#include <openssl/x509.h>
124
125#include "bytestring.h"
126#include "dtls_local.h"
127#include "pqueue.h"
128#include "ssl_local.h"
129
130#define RSMBLY_BITMASK_SIZE(msg_len) (((msg_len) + 7) / 8)
131
132#define RSMBLY_BITMASK_MARK(bitmask, start, end) { \
133 if ((end) - (start) <= 8) { \
134 long ii; \
135 for (ii = (start); ii < (end); ii++) bitmask[((ii) >> 3)] |= (1 << ((ii) & 7)); \
136 } else { \
137 long ii; \
138 bitmask[((start) >> 3)] |= bitmask_start_values[((start) & 7)]; \
139 for (ii = (((start) >> 3) + 1); ii < ((((end) - 1)) >> 3); ii++) bitmask[ii] = 0xff; \
140 bitmask[(((end) - 1) >> 3)] |= bitmask_end_values[((end) & 7)]; \
141 } }
142
143#define RSMBLY_BITMASK_IS_COMPLETE(bitmask, msg_len, is_complete) { \
144 long ii; \
145 OPENSSL_assert((msg_len) > 0); \
146 is_complete = 1; \
147 if (bitmask[(((msg_len) - 1) >> 3)] != bitmask_end_values[((msg_len) & 7)]) is_complete = 0; \
148 if (is_complete) for (ii = (((msg_len) - 1) >> 3) - 1; ii >= 0 ; ii--) \
149 if (bitmask[ii] != 0xff) { is_complete = 0; break; } }
150
151static const unsigned char bitmask_start_values[] = {
152 0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80
153};
154static const unsigned char bitmask_end_values[] = {
155 0xff, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f
156};
157
158/* XDTLS: figure out the right values */
159static const unsigned int g_probable_mtu[] = {1500 - 28, 512 - 28, 256 - 28};
160
161static unsigned int dtls1_guess_mtu(unsigned int curr_mtu);
162static void dtls1_fix_message_header(SSL *s, unsigned long frag_off,
163 unsigned long frag_len);
164static int dtls1_write_message_header(const struct hm_header_st *msg_hdr,
165 unsigned long frag_off, unsigned long frag_len, unsigned char *p);
166static long dtls1_get_message_fragment(SSL *s, int st1, int stn, long max,
167 int *ok);
168
169void dtls1_hm_fragment_free(hm_fragment *frag);
170
171static hm_fragment *
172dtls1_hm_fragment_new(unsigned long frag_len, int reassembly)
173{
174 hm_fragment *frag;
175
176 if ((frag = calloc(1, sizeof(*frag))) == NULL)
177 goto err;
178
179 if (frag_len > 0) {
180 if ((frag->fragment = calloc(1, frag_len)) == NULL)
181 goto err;
182 }
183
184 /* Initialize reassembly bitmask if necessary. */
185 if (reassembly) {
186 if ((frag->reassembly = calloc(1,
187 RSMBLY_BITMASK_SIZE(frag_len))) == NULL)
188 goto err;
189 }
190
191 return frag;
192
193 err:
194 dtls1_hm_fragment_free(frag);
195 return NULL;
196}
197
198void
199dtls1_hm_fragment_free(hm_fragment *frag)
200{
201 if (frag == NULL)
202 return;
203
204 free(frag->fragment);
205 free(frag->reassembly);
206 free(frag);
207}
208
209/* send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or SSL3_RT_CHANGE_CIPHER_SPEC) */
210int
211dtls1_do_write(SSL *s, int type)
212{
213 int ret;
214 int curr_mtu;
215 unsigned int len, frag_off;
216 size_t overhead;
217
218 /* AHA! Figure out the MTU, and stick to the right size */
219 if (s->d1->mtu < dtls1_min_mtu() &&
220 !(SSL_get_options(s) & SSL_OP_NO_QUERY_MTU)) {
221 s->d1->mtu = BIO_ctrl(SSL_get_wbio(s),
222 BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
223
224 /*
225 * I've seen the kernel return bogus numbers when it
226 * doesn't know the MTU (ie., the initial write), so just
227 * make sure we have a reasonable number
228 */
229 if (s->d1->mtu < dtls1_min_mtu()) {
230 s->d1->mtu = 0;
231 s->d1->mtu = dtls1_guess_mtu(s->d1->mtu);
232 BIO_ctrl(SSL_get_wbio(s), BIO_CTRL_DGRAM_SET_MTU,
233 s->d1->mtu, NULL);
234 }
235 }
236
237 OPENSSL_assert(s->d1->mtu >= dtls1_min_mtu());
238 /* should have something reasonable now */
239
240 if (s->init_off == 0 && type == SSL3_RT_HANDSHAKE)
241 OPENSSL_assert(s->init_num ==
242 (int)s->d1->w_msg_hdr.msg_len + DTLS1_HM_HEADER_LENGTH);
243
244 if (!tls12_record_layer_write_overhead(s->rl, &overhead))
245 return -1;
246
247 frag_off = 0;
248 while (s->init_num) {
249 curr_mtu = s->d1->mtu - BIO_wpending(SSL_get_wbio(s)) -
250 DTLS1_RT_HEADER_LENGTH - overhead;
251
252 if (curr_mtu <= DTLS1_HM_HEADER_LENGTH) {
253 /* grr.. we could get an error if MTU picked was wrong */
254 ret = BIO_flush(SSL_get_wbio(s));
255 if (ret <= 0)
256 return ret;
257 curr_mtu = s->d1->mtu - DTLS1_RT_HEADER_LENGTH -
258 overhead;
259 }
260
261 if (s->init_num > curr_mtu)
262 len = curr_mtu;
263 else
264 len = s->init_num;
265
266 /* XDTLS: this function is too long. split out the CCS part */
267 if (type == SSL3_RT_HANDSHAKE) {
268 if (s->init_off != 0) {
269 OPENSSL_assert(s->init_off > DTLS1_HM_HEADER_LENGTH);
270 s->init_off -= DTLS1_HM_HEADER_LENGTH;
271 s->init_num += DTLS1_HM_HEADER_LENGTH;
272
273 if (s->init_num > curr_mtu)
274 len = curr_mtu;
275 else
276 len = s->init_num;
277 }
278
279 dtls1_fix_message_header(s, frag_off,
280 len - DTLS1_HM_HEADER_LENGTH);
281
282 if (!dtls1_write_message_header(&s->d1->w_msg_hdr,
283 s->d1->w_msg_hdr.frag_off, s->d1->w_msg_hdr.frag_len,
284 (unsigned char *)&s->init_buf->data[s->init_off]))
285 return -1;
286
287 OPENSSL_assert(len >= DTLS1_HM_HEADER_LENGTH);
288 }
289
290 ret = dtls1_write_bytes(s, type,
291 &s->init_buf->data[s->init_off], len);
292 if (ret < 0) {
293 /*
294 * Might need to update MTU here, but we don't know
295 * which previous packet caused the failure -- so
296 * can't really retransmit anything. continue as
297 * if everything is fine and wait for an alert to
298 * handle the retransmit
299 */
300 if (BIO_ctrl(SSL_get_wbio(s),
301 BIO_CTRL_DGRAM_MTU_EXCEEDED, 0, NULL) > 0)
302 s->d1->mtu = BIO_ctrl(SSL_get_wbio(s),
303 BIO_CTRL_DGRAM_QUERY_MTU, 0, NULL);
304 else
305 return (-1);
306 } else {
307
308 /*
309 * Bad if this assert fails, only part of the
310 * handshake message got sent. but why would
311 * this happen?
312 */
313 OPENSSL_assert(len == (unsigned int)ret);
314
315 if (type == SSL3_RT_HANDSHAKE &&
316 !s->d1->retransmitting) {
317 /*
318 * Should not be done for 'Hello Request's,
319 * but in that case we'll ignore the result
320 * anyway
321 */
322 unsigned char *p = (unsigned char *)&s->init_buf->data[s->init_off];
323 const struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;
324 int xlen;
325
326 if (frag_off == 0) {
327 /*
328 * Reconstruct message header is if it
329 * is being sent in single fragment
330 */
331 if (!dtls1_write_message_header(msg_hdr,
332 0, msg_hdr->msg_len, p))
333 return (-1);
334 xlen = ret;
335 } else {
336 p += DTLS1_HM_HEADER_LENGTH;
337 xlen = ret - DTLS1_HM_HEADER_LENGTH;
338 }
339
340 tls1_transcript_record(s, p, xlen);
341 }
342
343 if (ret == s->init_num) {
344 if (s->msg_callback)
345 s->msg_callback(1, s->version, type,
346 s->init_buf->data,
347 (size_t)(s->init_off + s->init_num),
348 s, s->msg_callback_arg);
349
350 s->init_off = 0;
351 /* done writing this message */
352 s->init_num = 0;
353
354 return (1);
355 }
356 s->init_off += ret;
357 s->init_num -= ret;
358 frag_off += (ret -= DTLS1_HM_HEADER_LENGTH);
359 }
360 }
361 return (0);
362}
363
364
365/*
366 * Obtain handshake message of message type 'mt' (any if mt == -1),
367 * maximum acceptable body length 'max'.
368 * Read an entire handshake message. Handshake messages arrive in
369 * fragments.
370 */
371int
372dtls1_get_message(SSL *s, int st1, int stn, int mt, long max)
373{
374 struct hm_header_st *msg_hdr;
375 unsigned char *p;
376 unsigned long msg_len;
377 int i, al, ok;
378
379 /*
380 * s3->tmp is used to store messages that are unexpected, caused
381 * by the absence of an optional handshake message
382 */
383 if (s->s3->hs.tls12.reuse_message) {
384 s->s3->hs.tls12.reuse_message = 0;
385 if ((mt >= 0) && (s->s3->hs.tls12.message_type != mt)) {
386 al = SSL_AD_UNEXPECTED_MESSAGE;
387 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
388 goto fatal_err;
389 }
390 s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH;
391 s->init_num = (int)s->s3->hs.tls12.message_size;
392 return 1;
393 }
394
395 msg_hdr = &s->d1->r_msg_hdr;
396 memset(msg_hdr, 0, sizeof(struct hm_header_st));
397
398 again:
399 i = dtls1_get_message_fragment(s, st1, stn, max, &ok);
400 if (i == DTLS1_HM_BAD_FRAGMENT ||
401 i == DTLS1_HM_FRAGMENT_RETRY) /* bad fragment received */
402 goto again;
403 else if (i <= 0 && !ok)
404 return i;
405
406 p = (unsigned char *)s->init_buf->data;
407 msg_len = msg_hdr->msg_len;
408
409 /* reconstruct message header */
410 if (!dtls1_write_message_header(msg_hdr, 0, msg_len, p))
411 return -1;
412
413 msg_len += DTLS1_HM_HEADER_LENGTH;
414
415 tls1_transcript_record(s, p, msg_len);
416 if (s->msg_callback)
417 s->msg_callback(0, s->version, SSL3_RT_HANDSHAKE, p, msg_len,
418 s, s->msg_callback_arg);
419
420 memset(msg_hdr, 0, sizeof(struct hm_header_st));
421
422 /* Don't change sequence numbers while listening */
423 if (!s->d1->listen)
424 s->d1->handshake_read_seq++;
425
426 s->init_msg = s->init_buf->data + DTLS1_HM_HEADER_LENGTH;
427 return 1;
428
429 fatal_err:
430 ssl3_send_alert(s, SSL3_AL_FATAL, al);
431 return -1;
432}
433
434static int
435dtls1_preprocess_fragment(SSL *s, struct hm_header_st *msg_hdr, int max)
436{
437 size_t frag_off, frag_len, msg_len;
438
439 msg_len = msg_hdr->msg_len;
440 frag_off = msg_hdr->frag_off;
441 frag_len = msg_hdr->frag_len;
442
443 /* sanity checking */
444 if ((frag_off + frag_len) > msg_len) {
445 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);
446 return SSL_AD_ILLEGAL_PARAMETER;
447 }
448
449 if ((frag_off + frag_len) > (unsigned long)max) {
450 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);
451 return SSL_AD_ILLEGAL_PARAMETER;
452 }
453
454 if ( s->d1->r_msg_hdr.frag_off == 0) /* first fragment */
455 {
456 /*
457 * msg_len is limited to 2^24, but is effectively checked
458 * against max above
459 */
460 if (!BUF_MEM_grow_clean(s->init_buf,
461 msg_len + DTLS1_HM_HEADER_LENGTH)) {
462 SSLerror(s, ERR_R_BUF_LIB);
463 return SSL_AD_INTERNAL_ERROR;
464 }
465
466 s->s3->hs.tls12.message_size = msg_len;
467 s->d1->r_msg_hdr.msg_len = msg_len;
468 s->s3->hs.tls12.message_type = msg_hdr->type;
469 s->d1->r_msg_hdr.type = msg_hdr->type;
470 s->d1->r_msg_hdr.seq = msg_hdr->seq;
471 } else if (msg_len != s->d1->r_msg_hdr.msg_len) {
472 /*
473 * They must be playing with us! BTW, failure to enforce
474 * upper limit would open possibility for buffer overrun.
475 */
476 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);
477 return SSL_AD_ILLEGAL_PARAMETER;
478 }
479
480 return 0; /* no error */
481}
482
483static int
484dtls1_retrieve_buffered_fragment(SSL *s, long max, int *ok)
485{
486 /*
487 * (0) check whether the desired fragment is available
488 * if so:
489 * (1) copy over the fragment to s->init_buf->data[]
490 * (2) update s->init_num
491 */
492 pitem *item;
493 hm_fragment *frag;
494 int al;
495
496 *ok = 0;
497 item = pqueue_peek(s->d1->buffered_messages);
498 if (item == NULL)
499 return 0;
500
501 frag = (hm_fragment *)item->data;
502
503 /* Don't return if reassembly still in progress */
504 if (frag->reassembly != NULL)
505 return 0;
506
507 if (s->d1->handshake_read_seq == frag->msg_header.seq) {
508 unsigned long frag_len = frag->msg_header.frag_len;
509 pqueue_pop(s->d1->buffered_messages);
510
511 al = dtls1_preprocess_fragment(s, &frag->msg_header, max);
512
513 if (al == 0) /* no alert */
514 {
515 unsigned char *p = (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;
516 memcpy(&p[frag->msg_header.frag_off],
517 frag->fragment, frag->msg_header.frag_len);
518 }
519
520 dtls1_hm_fragment_free(frag);
521 pitem_free(item);
522
523 if (al == 0) {
524 *ok = 1;
525 return frag_len;
526 }
527
528 ssl3_send_alert(s, SSL3_AL_FATAL, al);
529 s->init_num = 0;
530 *ok = 0;
531 return -1;
532 } else
533 return 0;
534}
535
536/*
537 * dtls1_max_handshake_message_len returns the maximum number of bytes
538 * permitted in a DTLS handshake message for |s|. The minimum is 16KB,
539 * but may be greater if the maximum certificate list size requires it.
540 */
541static unsigned long
542dtls1_max_handshake_message_len(const SSL *s)
543{
544 unsigned long max_len;
545
546 max_len = DTLS1_HM_HEADER_LENGTH + SSL3_RT_MAX_ENCRYPTED_LENGTH;
547 if (max_len < (unsigned long)s->max_cert_list)
548 return s->max_cert_list;
549 return max_len;
550}
551
552static int
553dtls1_reassemble_fragment(SSL *s, struct hm_header_st* msg_hdr, int *ok)
554{
555 hm_fragment *frag = NULL;
556 pitem *item = NULL;
557 int i = -1, is_complete;
558 unsigned char seq64be[8];
559 unsigned long frag_len = msg_hdr->frag_len;
560
561 if ((msg_hdr->frag_off + frag_len) > msg_hdr->msg_len ||
562 msg_hdr->msg_len > dtls1_max_handshake_message_len(s))
563 goto err;
564
565 if (frag_len == 0) {
566 i = DTLS1_HM_FRAGMENT_RETRY;
567 goto err;
568 }
569
570 /* Try to find item in queue */
571 memset(seq64be, 0, sizeof(seq64be));
572 seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);
573 seq64be[7] = (unsigned char)msg_hdr->seq;
574 item = pqueue_find(s->d1->buffered_messages, seq64be);
575
576 if (item == NULL) {
577 frag = dtls1_hm_fragment_new(msg_hdr->msg_len, 1);
578 if (frag == NULL)
579 goto err;
580 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
581 frag->msg_header.frag_len = frag->msg_header.msg_len;
582 frag->msg_header.frag_off = 0;
583 } else {
584 frag = (hm_fragment*)item->data;
585 if (frag->msg_header.msg_len != msg_hdr->msg_len) {
586 item = NULL;
587 frag = NULL;
588 goto err;
589 }
590 }
591
592 /*
593 * If message is already reassembled, this must be a
594 * retransmit and can be dropped.
595 */
596 if (frag->reassembly == NULL) {
597 unsigned char devnull [256];
598
599 while (frag_len) {
600 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,
601 devnull, frag_len > sizeof(devnull) ?
602 sizeof(devnull) : frag_len, 0);
603 if (i <= 0)
604 goto err;
605 frag_len -= i;
606 }
607 i = DTLS1_HM_FRAGMENT_RETRY;
608 goto err;
609 }
610
611 /* read the body of the fragment (header has already been read */
612 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,
613 frag->fragment + msg_hdr->frag_off, frag_len, 0);
614 if (i <= 0 || (unsigned long)i != frag_len)
615 goto err;
616
617 RSMBLY_BITMASK_MARK(frag->reassembly, (long)msg_hdr->frag_off,
618 (long)(msg_hdr->frag_off + frag_len));
619
620 RSMBLY_BITMASK_IS_COMPLETE(frag->reassembly, (long)msg_hdr->msg_len,
621 is_complete);
622
623 if (is_complete) {
624 free(frag->reassembly);
625 frag->reassembly = NULL;
626 }
627
628 if (item == NULL) {
629 memset(seq64be, 0, sizeof(seq64be));
630 seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);
631 seq64be[7] = (unsigned char)(msg_hdr->seq);
632
633 item = pitem_new(seq64be, frag);
634 if (item == NULL) {
635 i = -1;
636 goto err;
637 }
638
639 pqueue_insert(s->d1->buffered_messages, item);
640 }
641
642 return DTLS1_HM_FRAGMENT_RETRY;
643
644 err:
645 if (item == NULL && frag != NULL)
646 dtls1_hm_fragment_free(frag);
647 *ok = 0;
648 return i;
649}
650
651
652static int
653dtls1_process_out_of_seq_message(SSL *s, struct hm_header_st* msg_hdr, int *ok)
654{
655 int i = -1;
656 hm_fragment *frag = NULL;
657 pitem *item = NULL;
658 unsigned char seq64be[8];
659 unsigned long frag_len = msg_hdr->frag_len;
660
661 if ((msg_hdr->frag_off + frag_len) > msg_hdr->msg_len)
662 goto err;
663
664 /* Try to find item in queue, to prevent duplicate entries */
665 memset(seq64be, 0, sizeof(seq64be));
666 seq64be[6] = (unsigned char) (msg_hdr->seq >> 8);
667 seq64be[7] = (unsigned char) msg_hdr->seq;
668 item = pqueue_find(s->d1->buffered_messages, seq64be);
669
670 /*
671 * If we already have an entry and this one is a fragment,
672 * don't discard it and rather try to reassemble it.
673 */
674 if (item != NULL && frag_len < msg_hdr->msg_len)
675 item = NULL;
676
677 /*
678 * Discard the message if sequence number was already there, is
679 * too far in the future, already in the queue or if we received
680 * a FINISHED before the SERVER_HELLO, which then must be a stale
681 * retransmit.
682 */
683 if (msg_hdr->seq <= s->d1->handshake_read_seq ||
684 msg_hdr->seq > s->d1->handshake_read_seq + 10 || item != NULL ||
685 (s->d1->handshake_read_seq == 0 &&
686 msg_hdr->type == SSL3_MT_FINISHED)) {
687 unsigned char devnull [256];
688
689 while (frag_len) {
690 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,
691 devnull, frag_len > sizeof(devnull) ?
692 sizeof(devnull) : frag_len, 0);
693 if (i <= 0)
694 goto err;
695 frag_len -= i;
696 }
697 } else {
698 if (frag_len < msg_hdr->msg_len)
699 return dtls1_reassemble_fragment(s, msg_hdr, ok);
700
701 if (frag_len > dtls1_max_handshake_message_len(s))
702 goto err;
703
704 frag = dtls1_hm_fragment_new(frag_len, 0);
705 if (frag == NULL)
706 goto err;
707
708 memcpy(&(frag->msg_header), msg_hdr, sizeof(*msg_hdr));
709
710 if (frag_len) {
711 /* read the body of the fragment (header has already been read */
712 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,
713 frag->fragment, frag_len, 0);
714 if (i <= 0 || (unsigned long)i != frag_len)
715 goto err;
716 }
717
718 memset(seq64be, 0, sizeof(seq64be));
719 seq64be[6] = (unsigned char)(msg_hdr->seq >> 8);
720 seq64be[7] = (unsigned char)(msg_hdr->seq);
721
722 item = pitem_new(seq64be, frag);
723 if (item == NULL)
724 goto err;
725
726 pqueue_insert(s->d1->buffered_messages, item);
727 }
728
729 return DTLS1_HM_FRAGMENT_RETRY;
730
731 err:
732 if (item == NULL && frag != NULL)
733 dtls1_hm_fragment_free(frag);
734 *ok = 0;
735 return i;
736}
737
738
739static long
740dtls1_get_message_fragment(SSL *s, int st1, int stn, long max, int *ok)
741{
742 unsigned char wire[DTLS1_HM_HEADER_LENGTH];
743 unsigned long len, frag_off, frag_len;
744 struct hm_header_st msg_hdr;
745 int i, al;
746 CBS cbs;
747
748 again:
749 /* see if we have the required fragment already */
750 if ((frag_len = dtls1_retrieve_buffered_fragment(s, max, ok)) || *ok) {
751 if (*ok)
752 s->init_num = frag_len;
753 return frag_len;
754 }
755
756 /* read handshake message header */
757 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE, wire,
758 DTLS1_HM_HEADER_LENGTH, 0);
759 if (i <= 0) {
760 /* nbio, or an error */
761 s->rwstate = SSL_READING;
762 *ok = 0;
763 return i;
764 }
765
766 CBS_init(&cbs, wire, i);
767 if (!dtls1_get_message_header(&cbs, &msg_hdr)) {
768 /* Handshake fails if message header is incomplete. */
769 al = SSL_AD_UNEXPECTED_MESSAGE;
770 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
771 goto fatal_err;
772 }
773
774 /*
775 * if this is a future (or stale) message it gets buffered
776 * (or dropped)--no further processing at this time
777 * While listening, we accept seq 1 (ClientHello with cookie)
778 * although we're still expecting seq 0 (ClientHello)
779 */
780 if (msg_hdr.seq != s->d1->handshake_read_seq &&
781 !(s->d1->listen && msg_hdr.seq == 1))
782 return dtls1_process_out_of_seq_message(s, &msg_hdr, ok);
783
784 len = msg_hdr.msg_len;
785 frag_off = msg_hdr.frag_off;
786 frag_len = msg_hdr.frag_len;
787
788 if (frag_len && frag_len < len)
789 return dtls1_reassemble_fragment(s, &msg_hdr, ok);
790
791 if (!s->server && s->d1->r_msg_hdr.frag_off == 0 &&
792 wire[0] == SSL3_MT_HELLO_REQUEST) {
793 /*
794 * The server may always send 'Hello Request' messages --
795 * we are doing a handshake anyway now, so ignore them
796 * if their format is correct. Does not count for
797 * 'Finished' MAC.
798 */
799 if (wire[1] == 0 && wire[2] == 0 && wire[3] == 0) {
800 if (s->msg_callback)
801 s->msg_callback(0, s->version,
802 SSL3_RT_HANDSHAKE, wire,
803 DTLS1_HM_HEADER_LENGTH, s,
804 s->msg_callback_arg);
805
806 s->init_num = 0;
807 goto again;
808 }
809 else /* Incorrectly formatted Hello request */
810 {
811 al = SSL_AD_UNEXPECTED_MESSAGE;
812 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
813 goto fatal_err;
814 }
815 }
816
817 if ((al = dtls1_preprocess_fragment(s, &msg_hdr, max)))
818 goto fatal_err;
819
820 /* XDTLS: resurrect this when restart is in place */
821 s->s3->hs.state = stn;
822
823 if (frag_len > 0) {
824 unsigned char *p = (unsigned char *)s->init_buf->data + DTLS1_HM_HEADER_LENGTH;
825
826 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,
827 &p[frag_off], frag_len, 0);
828 /* XDTLS: fix this--message fragments cannot span multiple packets */
829 if (i <= 0) {
830 s->rwstate = SSL_READING;
831 *ok = 0;
832 return i;
833 }
834 } else
835 i = 0;
836
837 /*
838 * XDTLS: an incorrectly formatted fragment should cause the
839 * handshake to fail
840 */
841 if (i != (int)frag_len) {
842 al = SSL_AD_ILLEGAL_PARAMETER;
843 SSLerror(s, SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER);
844 goto fatal_err;
845 }
846
847 /*
848 * Note that s->init_num is *not* used as current offset in
849 * s->init_buf->data, but as a counter summing up fragments'
850 * lengths: as soon as they sum up to handshake packet
851 * length, we assume we have got all the fragments.
852 */
853 s->init_num = frag_len;
854 *ok = 1;
855 return frag_len;
856
857 fatal_err:
858 ssl3_send_alert(s, SSL3_AL_FATAL, al);
859 s->init_num = 0;
860
861 *ok = 0;
862 return (-1);
863}
864
865int
866dtls1_read_failed(SSL *s, int code)
867{
868 if (code > 0) {
869#ifdef DEBUG
870 fprintf(stderr, "invalid state reached %s:%d",
871 OPENSSL_FILE, OPENSSL_LINE);
872#endif
873 return 1;
874 }
875
876 if (!dtls1_is_timer_expired(s)) {
877 /*
878 * not a timeout, none of our business, let higher layers
879 * handle this. in fact it's probably an error
880 */
881 return code;
882 }
883
884 if (!SSL_in_init(s)) /* done, no need to send a retransmit */
885 {
886 BIO_set_flags(SSL_get_rbio(s), BIO_FLAGS_READ);
887 return code;
888 }
889
890 return dtls1_handle_timeout(s);
891}
892
893int
894dtls1_get_queue_priority(unsigned short seq, int is_ccs)
895{
896 /*
897 * The index of the retransmission queue actually is the message
898 * sequence number, since the queue only contains messages of a
899 * single handshake. However, the ChangeCipherSpec has no message
900 * sequence number and so using only the sequence will result in
901 * the CCS and Finished having the same index. To prevent this, the
902 * sequence number is multiplied by 2. In case of a CCS 1 is
903 * subtracted. This does not only differ CSS and Finished, it also
904 * maintains the order of the index (important for priority queues)
905 * and fits in the unsigned short variable.
906 */
907 return seq * 2 - is_ccs;
908}
909
910int
911dtls1_retransmit_buffered_messages(SSL *s)
912{
913 pqueue sent = s->d1->sent_messages;
914 piterator iter;
915 pitem *item;
916 hm_fragment *frag;
917 int found = 0;
918
919 iter = pqueue_iterator(sent);
920
921 for (item = pqueue_next(&iter); item != NULL;
922 item = pqueue_next(&iter)) {
923 frag = (hm_fragment *)item->data;
924 if (dtls1_retransmit_message(s,
925 (unsigned short)dtls1_get_queue_priority(
926 frag->msg_header.seq, frag->msg_header.is_ccs), 0,
927 &found) <= 0 && found) {
928#ifdef DEBUG
929 fprintf(stderr, "dtls1_retransmit_message() failed\n");
930#endif
931 return -1;
932 }
933 }
934
935 return 1;
936}
937
938int
939dtls1_buffer_message(SSL *s, int is_ccs)
940{
941 pitem *item;
942 hm_fragment *frag;
943 unsigned char seq64be[8];
944
945 /* Buffer the message in order to handle DTLS retransmissions. */
946
947 /*
948 * This function is called immediately after a message has
949 * been serialized
950 */
951 OPENSSL_assert(s->init_off == 0);
952
953 frag = dtls1_hm_fragment_new(s->init_num, 0);
954 if (frag == NULL)
955 return 0;
956
957 memcpy(frag->fragment, s->init_buf->data, s->init_num);
958
959 OPENSSL_assert(s->d1->w_msg_hdr.msg_len +
960 (is_ccs ? DTLS1_CCS_HEADER_LENGTH : DTLS1_HM_HEADER_LENGTH) ==
961 (unsigned int)s->init_num);
962
963 frag->msg_header.msg_len = s->d1->w_msg_hdr.msg_len;
964 frag->msg_header.seq = s->d1->w_msg_hdr.seq;
965 frag->msg_header.type = s->d1->w_msg_hdr.type;
966 frag->msg_header.frag_off = 0;
967 frag->msg_header.frag_len = s->d1->w_msg_hdr.msg_len;
968 frag->msg_header.is_ccs = is_ccs;
969
970 /* save current state*/
971 frag->msg_header.saved_retransmit_state.session = s->session;
972 frag->msg_header.saved_retransmit_state.epoch =
973 tls12_record_layer_write_epoch(s->rl);
974
975 memset(seq64be, 0, sizeof(seq64be));
976 seq64be[6] = (unsigned char)(dtls1_get_queue_priority(
977 frag->msg_header.seq, frag->msg_header.is_ccs) >> 8);
978 seq64be[7] = (unsigned char)(dtls1_get_queue_priority(
979 frag->msg_header.seq, frag->msg_header.is_ccs));
980
981 item = pitem_new(seq64be, frag);
982 if (item == NULL) {
983 dtls1_hm_fragment_free(frag);
984 return 0;
985 }
986
987 pqueue_insert(s->d1->sent_messages, item);
988 return 1;
989}
990
991int
992dtls1_retransmit_message(SSL *s, unsigned short seq, unsigned long frag_off,
993 int *found)
994{
995 int ret;
996 /* XDTLS: for now assuming that read/writes are blocking */
997 pitem *item;
998 hm_fragment *frag;
999 unsigned long header_length;
1000 unsigned char seq64be[8];
1001 struct dtls1_retransmit_state saved_state;
1002
1003 /*
1004 OPENSSL_assert(s->init_num == 0);
1005 OPENSSL_assert(s->init_off == 0);
1006 */
1007
1008 /* XDTLS: the requested message ought to be found, otherwise error */
1009 memset(seq64be, 0, sizeof(seq64be));
1010 seq64be[6] = (unsigned char)(seq >> 8);
1011 seq64be[7] = (unsigned char)seq;
1012
1013 item = pqueue_find(s->d1->sent_messages, seq64be);
1014 if (item == NULL) {
1015#ifdef DEBUG
1016 fprintf(stderr, "retransmit: message %d non-existent\n", seq);
1017#endif
1018 *found = 0;
1019 return 0;
1020 }
1021
1022 *found = 1;
1023 frag = (hm_fragment *)item->data;
1024
1025 if (frag->msg_header.is_ccs)
1026 header_length = DTLS1_CCS_HEADER_LENGTH;
1027 else
1028 header_length = DTLS1_HM_HEADER_LENGTH;
1029
1030 memcpy(s->init_buf->data, frag->fragment,
1031 frag->msg_header.msg_len + header_length);
1032 s->init_num = frag->msg_header.msg_len + header_length;
1033
1034 dtls1_set_message_header_int(s, frag->msg_header.type,
1035 frag->msg_header.msg_len, frag->msg_header.seq, 0,
1036 frag->msg_header.frag_len);
1037
1038 /* save current state */
1039 saved_state.session = s->session;
1040 saved_state.epoch = tls12_record_layer_write_epoch(s->rl);
1041
1042 s->d1->retransmitting = 1;
1043
1044 /* restore state in which the message was originally sent */
1045 s->session = frag->msg_header.saved_retransmit_state.session;
1046 if (!tls12_record_layer_use_write_epoch(s->rl,
1047 frag->msg_header.saved_retransmit_state.epoch))
1048 return 0;
1049
1050 ret = dtls1_do_write(s, frag->msg_header.is_ccs ?
1051 SSL3_RT_CHANGE_CIPHER_SPEC : SSL3_RT_HANDSHAKE);
1052
1053 /* restore current state */
1054 s->session = saved_state.session;
1055 if (!tls12_record_layer_use_write_epoch(s->rl,
1056 saved_state.epoch))
1057 return 0;
1058
1059 s->d1->retransmitting = 0;
1060
1061 (void)BIO_flush(SSL_get_wbio(s));
1062 return ret;
1063}
1064
1065/* call this function when the buffered messages are no longer needed */
1066void
1067dtls1_clear_record_buffer(SSL *s)
1068{
1069 hm_fragment *frag;
1070 pitem *item;
1071
1072 for(item = pqueue_pop(s->d1->sent_messages); item != NULL;
1073 item = pqueue_pop(s->d1->sent_messages)) {
1074 frag = item->data;
1075 if (frag->msg_header.is_ccs)
1076 tls12_record_layer_write_epoch_done(s->rl,
1077 frag->msg_header.saved_retransmit_state.epoch);
1078 dtls1_hm_fragment_free(frag);
1079 pitem_free(item);
1080 }
1081}
1082
1083void
1084dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len,
1085 unsigned long frag_off, unsigned long frag_len)
1086{
1087 /* Don't change sequence numbers while listening */
1088 if (frag_off == 0 && !s->d1->listen) {
1089 s->d1->handshake_write_seq = s->d1->next_handshake_write_seq;
1090 s->d1->next_handshake_write_seq++;
1091 }
1092
1093 dtls1_set_message_header_int(s, mt, len, s->d1->handshake_write_seq,
1094 frag_off, frag_len);
1095}
1096
1097/* don't actually do the writing, wait till the MTU has been retrieved */
1098void
1099dtls1_set_message_header_int(SSL *s, unsigned char mt, unsigned long len,
1100 unsigned short seq_num, unsigned long frag_off, unsigned long frag_len)
1101{
1102 struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;
1103
1104 msg_hdr->type = mt;
1105 msg_hdr->msg_len = len;
1106 msg_hdr->seq = seq_num;
1107 msg_hdr->frag_off = frag_off;
1108 msg_hdr->frag_len = frag_len;
1109}
1110
1111static void
1112dtls1_fix_message_header(SSL *s, unsigned long frag_off, unsigned long frag_len)
1113{
1114 struct hm_header_st *msg_hdr = &s->d1->w_msg_hdr;
1115
1116 msg_hdr->frag_off = frag_off;
1117 msg_hdr->frag_len = frag_len;
1118}
1119
1120static int
1121dtls1_write_message_header(const struct hm_header_st *msg_hdr,
1122 unsigned long frag_off, unsigned long frag_len, unsigned char *p)
1123{
1124 CBB cbb;
1125
1126 /* We assume DTLS1_HM_HEADER_LENGTH bytes are available for now... */
1127 if (!CBB_init_fixed(&cbb, p, DTLS1_HM_HEADER_LENGTH))
1128 return 0;
1129 if (!CBB_add_u8(&cbb, msg_hdr->type))
1130 goto err;
1131 if (!CBB_add_u24(&cbb, msg_hdr->msg_len))
1132 goto err;
1133 if (!CBB_add_u16(&cbb, msg_hdr->seq))
1134 goto err;
1135 if (!CBB_add_u24(&cbb, frag_off))
1136 goto err;
1137 if (!CBB_add_u24(&cbb, frag_len))
1138 goto err;
1139 if (!CBB_finish(&cbb, NULL, NULL))
1140 goto err;
1141
1142 return 1;
1143
1144 err:
1145 CBB_cleanup(&cbb);
1146 return 0;
1147}
1148
1149unsigned int
1150dtls1_min_mtu(void)
1151{
1152 return (g_probable_mtu[(sizeof(g_probable_mtu) /
1153 sizeof(g_probable_mtu[0])) - 1]);
1154}
1155
1156static unsigned int
1157dtls1_guess_mtu(unsigned int curr_mtu)
1158{
1159 unsigned int i;
1160
1161 if (curr_mtu == 0)
1162 return g_probable_mtu[0];
1163
1164 for (i = 0; i < sizeof(g_probable_mtu) / sizeof(g_probable_mtu[0]); i++)
1165 if (curr_mtu > g_probable_mtu[i])
1166 return g_probable_mtu[i];
1167
1168 return curr_mtu;
1169}
1170
1171int
1172dtls1_get_message_header(CBS *header, struct hm_header_st *msg_hdr)
1173{
1174 uint32_t msg_len, frag_off, frag_len;
1175 uint16_t seq;
1176 uint8_t type;
1177
1178 memset(msg_hdr, 0, sizeof(*msg_hdr));
1179
1180 if (!CBS_get_u8(header, &type))
1181 return 0;
1182 if (!CBS_get_u24(header, &msg_len))
1183 return 0;
1184 if (!CBS_get_u16(header, &seq))
1185 return 0;
1186 if (!CBS_get_u24(header, &frag_off))
1187 return 0;
1188 if (!CBS_get_u24(header, &frag_len))
1189 return 0;
1190
1191 msg_hdr->type = type;
1192 msg_hdr->msg_len = msg_len;
1193 msg_hdr->seq = seq;
1194 msg_hdr->frag_off = frag_off;
1195 msg_hdr->frag_len = frag_len;
1196
1197 return 1;
1198}
diff --git a/src/lib/libssl/d1_lib.c b/src/lib/libssl/d1_lib.c
deleted file mode 100644
index 69db8a0df4..0000000000
--- a/src/lib/libssl/d1_lib.c
+++ /dev/null
@@ -1,414 +0,0 @@
1/* $OpenBSD: d1_lib.c,v 1.65 2024/07/23 14:40:53 jsing Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <sys/types.h>
61#include <sys/socket.h>
62#include <sys/time.h>
63
64#include <netinet/in.h>
65
66#include <stdio.h>
67
68#include <openssl/objects.h>
69
70#include "dtls_local.h"
71#include "pqueue.h"
72#include "ssl_local.h"
73
74void dtls1_hm_fragment_free(hm_fragment *frag);
75
76static int dtls1_listen(SSL *s, struct sockaddr *client);
77
78int
79dtls1_new(SSL *s)
80{
81 if (!ssl3_new(s))
82 goto err;
83
84 if ((s->d1 = calloc(1, sizeof(*s->d1))) == NULL)
85 goto err;
86
87 if ((s->d1->unprocessed_rcds.q = pqueue_new()) == NULL)
88 goto err;
89 if ((s->d1->buffered_messages = pqueue_new()) == NULL)
90 goto err;
91 if ((s->d1->sent_messages = pqueue_new()) == NULL)
92 goto err;
93 if ((s->d1->buffered_app_data.q = pqueue_new()) == NULL)
94 goto err;
95
96 if (s->server)
97 s->d1->cookie_len = sizeof(s->d1->cookie);
98
99 s->method->ssl_clear(s);
100 return (1);
101
102 err:
103 dtls1_free(s);
104 return (0);
105}
106
107static void
108dtls1_drain_rcontents(pqueue queue)
109{
110 DTLS1_RCONTENT_DATA_INTERNAL *rdata;
111 pitem *item;
112
113 if (queue == NULL)
114 return;
115
116 while ((item = pqueue_pop(queue)) != NULL) {
117 rdata = (DTLS1_RCONTENT_DATA_INTERNAL *)item->data;
118 tls_content_free(rdata->rcontent);
119 free(item->data);
120 pitem_free(item);
121 }
122}
123
124static void
125dtls1_drain_records(pqueue queue)
126{
127 pitem *item;
128 DTLS1_RECORD_DATA_INTERNAL *rdata;
129
130 if (queue == NULL)
131 return;
132
133 while ((item = pqueue_pop(queue)) != NULL) {
134 rdata = (DTLS1_RECORD_DATA_INTERNAL *)item->data;
135 ssl3_release_buffer(&rdata->rbuf);
136 free(item->data);
137 pitem_free(item);
138 }
139}
140
141static void
142dtls1_drain_fragments(pqueue queue)
143{
144 pitem *item;
145
146 if (queue == NULL)
147 return;
148
149 while ((item = pqueue_pop(queue)) != NULL) {
150 dtls1_hm_fragment_free(item->data);
151 pitem_free(item);
152 }
153}
154
155static void
156dtls1_clear_queues(SSL *s)
157{
158 dtls1_drain_records(s->d1->unprocessed_rcds.q);
159 dtls1_drain_fragments(s->d1->buffered_messages);
160 dtls1_drain_fragments(s->d1->sent_messages);
161 dtls1_drain_rcontents(s->d1->buffered_app_data.q);
162}
163
164void
165dtls1_free(SSL *s)
166{
167 if (s == NULL)
168 return;
169
170 ssl3_free(s);
171
172 if (s->d1 == NULL)
173 return;
174
175 dtls1_clear_queues(s);
176
177 pqueue_free(s->d1->unprocessed_rcds.q);
178 pqueue_free(s->d1->buffered_messages);
179 pqueue_free(s->d1->sent_messages);
180 pqueue_free(s->d1->buffered_app_data.q);
181
182 freezero(s->d1, sizeof(*s->d1));
183 s->d1 = NULL;
184}
185
186void
187dtls1_clear(SSL *s)
188{
189 pqueue unprocessed_rcds;
190 pqueue buffered_messages;
191 pqueue sent_messages;
192 pqueue buffered_app_data;
193 unsigned int mtu;
194
195 if (s->d1) {
196 unprocessed_rcds = s->d1->unprocessed_rcds.q;
197 buffered_messages = s->d1->buffered_messages;
198 sent_messages = s->d1->sent_messages;
199 buffered_app_data = s->d1->buffered_app_data.q;
200 mtu = s->d1->mtu;
201
202 dtls1_clear_queues(s);
203
204 memset(s->d1, 0, sizeof(*s->d1));
205
206 s->d1->unprocessed_rcds.epoch =
207 tls12_record_layer_read_epoch(s->rl) + 1;
208
209 if (s->server) {
210 s->d1->cookie_len = sizeof(s->d1->cookie);
211 }
212
213 if (SSL_get_options(s) & SSL_OP_NO_QUERY_MTU) {
214 s->d1->mtu = mtu;
215 }
216
217 s->d1->unprocessed_rcds.q = unprocessed_rcds;
218 s->d1->buffered_messages = buffered_messages;
219 s->d1->sent_messages = sent_messages;
220 s->d1->buffered_app_data.q = buffered_app_data;
221 }
222
223 ssl3_clear(s);
224
225 s->version = DTLS1_VERSION;
226}
227
228long
229dtls1_ctrl(SSL *s, int cmd, long larg, void *parg)
230{
231 int ret = 0;
232
233 switch (cmd) {
234 case DTLS_CTRL_GET_TIMEOUT:
235 if (dtls1_get_timeout(s, (struct timeval*) parg) != NULL) {
236 ret = 1;
237 }
238 break;
239 case DTLS_CTRL_HANDLE_TIMEOUT:
240 ret = dtls1_handle_timeout(s);
241 break;
242 case DTLS_CTRL_LISTEN:
243 ret = dtls1_listen(s, parg);
244 break;
245
246 default:
247 ret = ssl3_ctrl(s, cmd, larg, parg);
248 break;
249 }
250 return (ret);
251}
252
253void
254dtls1_start_timer(SSL *s)
255{
256
257 /* If timer is not set, initialize duration with 1 second */
258 if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
259 s->d1->timeout_duration = 1;
260 }
261
262 /* Set timeout to current time */
263 gettimeofday(&(s->d1->next_timeout), NULL);
264
265 /* Add duration to current time */
266 s->d1->next_timeout.tv_sec += s->d1->timeout_duration;
267 BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
268 &s->d1->next_timeout);
269}
270
271struct timeval*
272dtls1_get_timeout(SSL *s, struct timeval* timeleft)
273{
274 struct timeval timenow;
275
276 /* If no timeout is set, just return NULL */
277 if (s->d1->next_timeout.tv_sec == 0 && s->d1->next_timeout.tv_usec == 0) {
278 return NULL;
279 }
280
281 /* Get current time */
282 gettimeofday(&timenow, NULL);
283
284 /* If timer already expired, set remaining time to 0 */
285 if (s->d1->next_timeout.tv_sec < timenow.tv_sec ||
286 (s->d1->next_timeout.tv_sec == timenow.tv_sec &&
287 s->d1->next_timeout.tv_usec <= timenow.tv_usec)) {
288 memset(timeleft, 0, sizeof(struct timeval));
289 return timeleft;
290 }
291
292 /* Calculate time left until timer expires */
293 memcpy(timeleft, &(s->d1->next_timeout), sizeof(struct timeval));
294 timeleft->tv_sec -= timenow.tv_sec;
295 timeleft->tv_usec -= timenow.tv_usec;
296 if (timeleft->tv_usec < 0) {
297 timeleft->tv_sec--;
298 timeleft->tv_usec += 1000000;
299 }
300
301 /* If remaining time is less than 15 ms, set it to 0
302 * to prevent issues because of small devergences with
303 * socket timeouts.
304 */
305 if (timeleft->tv_sec == 0 && timeleft->tv_usec < 15000) {
306 memset(timeleft, 0, sizeof(struct timeval));
307 }
308
309
310 return timeleft;
311}
312
313int
314dtls1_is_timer_expired(SSL *s)
315{
316 struct timeval timeleft;
317
318 /* Get time left until timeout, return false if no timer running */
319 if (dtls1_get_timeout(s, &timeleft) == NULL) {
320 return 0;
321 }
322
323 /* Return false if timer is not expired yet */
324 if (timeleft.tv_sec > 0 || timeleft.tv_usec > 0) {
325 return 0;
326 }
327
328 /* Timer expired, so return true */
329 return 1;
330}
331
332void
333dtls1_double_timeout(SSL *s)
334{
335 s->d1->timeout_duration *= 2;
336 if (s->d1->timeout_duration > 60)
337 s->d1->timeout_duration = 60;
338 dtls1_start_timer(s);
339}
340
341void
342dtls1_stop_timer(SSL *s)
343{
344 /* Reset everything */
345 memset(&(s->d1->timeout), 0, sizeof(struct dtls1_timeout_st));
346 memset(&(s->d1->next_timeout), 0, sizeof(struct timeval));
347 s->d1->timeout_duration = 1;
348 BIO_ctrl(SSL_get_rbio(s), BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT, 0,
349 &(s->d1->next_timeout));
350 /* Clear retransmission buffer */
351 dtls1_clear_record_buffer(s);
352}
353
354int
355dtls1_check_timeout_num(SSL *s)
356{
357 s->d1->timeout.num_alerts++;
358
359 /* Reduce MTU after 2 unsuccessful retransmissions */
360 if (s->d1->timeout.num_alerts > 2) {
361 s->d1->mtu = BIO_ctrl(SSL_get_wbio(s),
362 BIO_CTRL_DGRAM_GET_FALLBACK_MTU, 0, NULL);
363
364 }
365
366 if (s->d1->timeout.num_alerts > DTLS1_TMO_ALERT_COUNT) {
367 /* fail the connection, enough alerts have been sent */
368 SSLerror(s, SSL_R_READ_TIMEOUT_EXPIRED);
369 return -1;
370 }
371
372 return 0;
373}
374
375int
376dtls1_handle_timeout(SSL *s)
377{
378 /* if no timer is expired, don't do anything */
379 if (!dtls1_is_timer_expired(s)) {
380 return 0;
381 }
382
383 dtls1_double_timeout(s);
384
385 if (dtls1_check_timeout_num(s) < 0)
386 return -1;
387
388 s->d1->timeout.read_timeouts++;
389 if (s->d1->timeout.read_timeouts > DTLS1_TMO_READ_COUNT) {
390 s->d1->timeout.read_timeouts = 1;
391 }
392
393 dtls1_start_timer(s);
394 return dtls1_retransmit_buffered_messages(s);
395}
396
397int
398dtls1_listen(SSL *s, struct sockaddr *client)
399{
400 int ret;
401
402 /* Ensure there is no state left over from a previous invocation */
403 SSL_clear(s);
404
405 SSL_set_options(s, SSL_OP_COOKIE_EXCHANGE);
406 s->d1->listen = 1;
407
408 ret = SSL_accept(s);
409 if (ret <= 0)
410 return ret;
411
412 (void)BIO_dgram_get_peer(SSL_get_rbio(s), client);
413 return 1;
414}
diff --git a/src/lib/libssl/d1_pkt.c b/src/lib/libssl/d1_pkt.c
deleted file mode 100644
index 8ba0bb0bcf..0000000000
--- a/src/lib/libssl/d1_pkt.c
+++ /dev/null
@@ -1,1124 +0,0 @@
1/* $OpenBSD: d1_pkt.c,v 1.130 2025/03/12 14:03:55 jsing Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
60 * All rights reserved.
61 *
62 * This package is an SSL implementation written
63 * by Eric Young (eay@cryptsoft.com).
64 * The implementation was written so as to conform with Netscapes SSL.
65 *
66 * This library is free for commercial and non-commercial use as long as
67 * the following conditions are aheared to. The following conditions
68 * apply to all code found in this distribution, be it the RC4, RSA,
69 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
70 * included with this distribution is covered by the same copyright terms
71 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
72 *
73 * Copyright remains Eric Young's, and as such any Copyright notices in
74 * the code are not to be removed.
75 * If this package is used in a product, Eric Young should be given attribution
76 * as the author of the parts of the library used.
77 * This can be in the form of a textual message at program startup or
78 * in documentation (online or textual) provided with the package.
79 *
80 * Redistribution and use in source and binary forms, with or without
81 * modification, are permitted provided that the following conditions
82 * are met:
83 * 1. Redistributions of source code must retain the copyright
84 * notice, this list of conditions and the following disclaimer.
85 * 2. Redistributions in binary form must reproduce the above copyright
86 * notice, this list of conditions and the following disclaimer in the
87 * documentation and/or other materials provided with the distribution.
88 * 3. All advertising materials mentioning features or use of this software
89 * must display the following acknowledgement:
90 * "This product includes cryptographic software written by
91 * Eric Young (eay@cryptsoft.com)"
92 * The word 'cryptographic' can be left out if the rouines from the library
93 * being used are not cryptographic related :-).
94 * 4. If you include any Windows specific code (or a derivative thereof) from
95 * the apps directory (application code) you must include an acknowledgement:
96 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
97 *
98 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
99 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
100 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
101 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
102 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
108 * SUCH DAMAGE.
109 *
110 * The licence and distribution terms for any publically available version or
111 * derivative of this code cannot be changed. i.e. this code cannot simply be
112 * copied and put under another distribution licence
113 * [including the GNU Public Licence.]
114 */
115
116#include <endian.h>
117#include <errno.h>
118#include <limits.h>
119#include <stdio.h>
120
121#include <openssl/buffer.h>
122#include <openssl/evp.h>
123
124#include "bytestring.h"
125#include "dtls_local.h"
126#include "pqueue.h"
127#include "ssl_local.h"
128#include "tls_content.h"
129
130/* mod 128 saturating subtract of two 64-bit values in big-endian order */
131static int
132satsub64be(const unsigned char *v1, const unsigned char *v2)
133{
134 int ret, sat, brw, i;
135
136 if (sizeof(long) == 8)
137 do {
138 long l;
139
140 if (BYTE_ORDER == LITTLE_ENDIAN)
141 break;
142 /* not reached on little-endians */
143 /* following test is redundant, because input is
144 * always aligned, but I take no chances... */
145 if (((size_t)v1 | (size_t)v2) & 0x7)
146 break;
147
148 l = *((long *)v1);
149 l -= *((long *)v2);
150 if (l > 128)
151 return 128;
152 else if (l<-128)
153 return -128;
154 else
155 return (int)l;
156 } while (0);
157
158 ret = (int)v1[7] - (int)v2[7];
159 sat = 0;
160 brw = ret >> 8; /* brw is either 0 or -1 */
161 if (ret & 0x80) {
162 for (i = 6; i >= 0; i--) {
163 brw += (int)v1[i]-(int)v2[i];
164 sat |= ~brw;
165 brw >>= 8;
166 }
167 } else {
168 for (i = 6; i >= 0; i--) {
169 brw += (int)v1[i]-(int)v2[i];
170 sat |= brw;
171 brw >>= 8;
172 }
173 }
174 brw <<= 8; /* brw is either 0 or -256 */
175
176 if (sat & 0xff)
177 return brw | 0x80;
178 else
179 return brw + (ret & 0xFF);
180}
181
182static int dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap,
183 const unsigned char *seq);
184static void dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap,
185 const unsigned char *seq);
186static DTLS1_BITMAP *dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr,
187 unsigned int *is_next_epoch);
188static int dtls1_buffer_record(SSL *s, record_pqueue *q,
189 unsigned char *priority);
190static int dtls1_process_record(SSL *s);
191
192/* copy buffered record into SSL structure */
193static int
194dtls1_copy_record(SSL *s, DTLS1_RECORD_DATA_INTERNAL *rdata)
195{
196 ssl3_release_buffer(&s->s3->rbuf);
197
198 s->packet = rdata->packet;
199 s->packet_length = rdata->packet_length;
200 memcpy(&(s->s3->rbuf), &(rdata->rbuf), sizeof(SSL3_BUFFER_INTERNAL));
201 memcpy(&(s->s3->rrec), &(rdata->rrec), sizeof(SSL3_RECORD_INTERNAL));
202
203 return (1);
204}
205
206static int
207dtls1_buffer_record(SSL *s, record_pqueue *queue, unsigned char *priority)
208{
209 DTLS1_RECORD_DATA_INTERNAL *rdata = NULL;
210 pitem *item = NULL;
211
212 /* Limit the size of the queue to prevent DOS attacks */
213 if (pqueue_size(queue->q) >= 100)
214 return 0;
215
216 if ((rdata = malloc(sizeof(*rdata))) == NULL)
217 goto init_err;
218 if ((item = pitem_new(priority, rdata)) == NULL)
219 goto init_err;
220
221 rdata->packet = s->packet;
222 rdata->packet_length = s->packet_length;
223 memcpy(&(rdata->rbuf), &(s->s3->rbuf), sizeof(SSL3_BUFFER_INTERNAL));
224 memcpy(&(rdata->rrec), &(s->s3->rrec), sizeof(SSL3_RECORD_INTERNAL));
225
226 item->data = rdata;
227
228 s->packet = NULL;
229 s->packet_length = 0;
230 memset(&(s->s3->rbuf), 0, sizeof(SSL3_BUFFER_INTERNAL));
231 memset(&(s->s3->rrec), 0, sizeof(SSL3_RECORD_INTERNAL));
232
233 if (!ssl3_setup_buffers(s))
234 goto err;
235
236 /* insert should not fail, since duplicates are dropped */
237 if (pqueue_insert(queue->q, item) == NULL)
238 goto err;
239
240 return (1);
241
242 err:
243 ssl3_release_buffer(&rdata->rbuf);
244
245 init_err:
246 SSLerror(s, ERR_R_INTERNAL_ERROR);
247 free(rdata);
248 pitem_free(item);
249 return (-1);
250}
251
252static int
253dtls1_buffer_rcontent(SSL *s, rcontent_pqueue *queue, unsigned char *priority)
254{
255 DTLS1_RCONTENT_DATA_INTERNAL *rdata = NULL;
256 pitem *item = NULL;
257
258 /* Limit the size of the queue to prevent DOS attacks */
259 if (pqueue_size(queue->q) >= 100)
260 return 0;
261
262 if ((rdata = malloc(sizeof(*rdata))) == NULL)
263 goto init_err;
264 if ((item = pitem_new(priority, rdata)) == NULL)
265 goto init_err;
266
267 rdata->rcontent = s->s3->rcontent;
268 s->s3->rcontent = NULL;
269
270 item->data = rdata;
271
272 /* insert should not fail, since duplicates are dropped */
273 if (pqueue_insert(queue->q, item) == NULL)
274 goto err;
275
276 if ((s->s3->rcontent = tls_content_new()) == NULL)
277 goto err;
278
279 return (1);
280
281 err:
282 tls_content_free(rdata->rcontent);
283
284 init_err:
285 SSLerror(s, ERR_R_INTERNAL_ERROR);
286 free(rdata);
287 pitem_free(item);
288 return (-1);
289}
290
291static int
292dtls1_retrieve_buffered_record(SSL *s, record_pqueue *queue)
293{
294 pitem *item;
295
296 item = pqueue_pop(queue->q);
297 if (item) {
298 dtls1_copy_record(s, item->data);
299
300 free(item->data);
301 pitem_free(item);
302
303 return (1);
304 }
305
306 return (0);
307}
308
309static int
310dtls1_retrieve_buffered_rcontent(SSL *s, rcontent_pqueue *queue)
311{
312 DTLS1_RCONTENT_DATA_INTERNAL *rdata;
313 pitem *item;
314
315 item = pqueue_pop(queue->q);
316 if (item) {
317 rdata = item->data;
318
319 tls_content_free(s->s3->rcontent);
320 s->s3->rcontent = rdata->rcontent;
321 s->s3->rrec.epoch = tls_content_epoch(s->s3->rcontent);
322
323 free(item->data);
324 pitem_free(item);
325
326 return (1);
327 }
328
329 return (0);
330}
331
332static int
333dtls1_process_buffered_record(SSL *s)
334{
335 /* Check if epoch is current. */
336 if (s->d1->unprocessed_rcds.epoch !=
337 tls12_record_layer_read_epoch(s->rl))
338 return (0);
339
340 /* Update epoch once all unprocessed records have been processed. */
341 if (pqueue_peek(s->d1->unprocessed_rcds.q) == NULL) {
342 s->d1->unprocessed_rcds.epoch =
343 tls12_record_layer_read_epoch(s->rl) + 1;
344 return (0);
345 }
346
347 /* Process one of the records. */
348 if (!dtls1_retrieve_buffered_record(s, &s->d1->unprocessed_rcds))
349 return (-1);
350 if (!dtls1_process_record(s))
351 return (-1);
352
353 return (1);
354}
355
356static int
357dtls1_process_record(SSL *s)
358{
359 SSL3_RECORD_INTERNAL *rr = &(s->s3->rrec);
360 uint8_t alert_desc;
361
362 tls12_record_layer_set_version(s->rl, s->version);
363
364 if (!tls12_record_layer_open_record(s->rl, s->packet, s->packet_length,
365 s->s3->rcontent)) {
366 tls12_record_layer_alert(s->rl, &alert_desc);
367
368 if (alert_desc == 0)
369 goto err;
370
371 /*
372 * DTLS should silently discard invalid records, including those
373 * with a bad MAC, as per RFC 6347 section 4.1.2.1.
374 */
375 if (alert_desc == SSL_AD_BAD_RECORD_MAC)
376 goto done;
377
378 if (alert_desc == SSL_AD_RECORD_OVERFLOW)
379 SSLerror(s, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
380
381 goto fatal_err;
382 }
383
384 /* XXX move to record layer. */
385 tls_content_set_epoch(s->s3->rcontent, rr->epoch);
386
387 done:
388 s->packet_length = 0;
389
390 return (1);
391
392 fatal_err:
393 ssl3_send_alert(s, SSL3_AL_FATAL, alert_desc);
394 err:
395 return (0);
396}
397
398/* Call this to get a new input record.
399 * It will return <= 0 if more data is needed, normally due to an error
400 * or non-blocking IO.
401 * When it finishes, one packet has been decoded and can be found in
402 * ssl->s3->rrec.type - is the type of record
403 * ssl->s3->rrec.data, - data
404 * ssl->s3->rrec.length, - number of bytes
405 */
406/* used only by dtls1_read_bytes */
407int
408dtls1_get_record(SSL *s)
409{
410 SSL3_RECORD_INTERNAL *rr = &(s->s3->rrec);
411 unsigned char *p = NULL;
412 DTLS1_BITMAP *bitmap;
413 unsigned int is_next_epoch;
414 int ret, n;
415
416 /* See if there are pending records that can now be processed. */
417 if ((ret = dtls1_process_buffered_record(s)) != 0)
418 return (ret);
419
420 /* get something from the wire */
421 if (0) {
422 again:
423 /* dump this record on all retries */
424 rr->length = 0;
425 s->packet_length = 0;
426 }
427
428 /* check if we have the header */
429 if ((s->rstate != SSL_ST_READ_BODY) ||
430 (s->packet_length < DTLS1_RT_HEADER_LENGTH)) {
431 CBS header, seq_no;
432 uint16_t epoch, len, ssl_version;
433 uint8_t type;
434
435 n = ssl3_packet_read(s, DTLS1_RT_HEADER_LENGTH);
436 if (n <= 0)
437 return (n);
438
439 /* If this packet contained a partial record, dump it. */
440 if (n != DTLS1_RT_HEADER_LENGTH)
441 goto again;
442
443 s->rstate = SSL_ST_READ_BODY;
444
445 CBS_init(&header, s->packet, s->packet_length);
446
447 /* Pull apart the header into the DTLS1_RECORD */
448 if (!CBS_get_u8(&header, &type))
449 goto again;
450 if (!CBS_get_u16(&header, &ssl_version))
451 goto again;
452
453 /* Sequence number is 64 bits, with top 2 bytes = epoch. */
454 if (!CBS_get_bytes(&header, &seq_no, SSL3_SEQUENCE_SIZE))
455 goto again;
456 if (!CBS_get_u16(&seq_no, &epoch))
457 goto again;
458 if (!CBS_write_bytes(&seq_no, &rr->seq_num[2],
459 sizeof(rr->seq_num) - 2, NULL))
460 goto again;
461
462 if (!CBS_get_u16(&header, &len))
463 goto again;
464
465 rr->type = type;
466 rr->epoch = epoch;
467 rr->length = len;
468
469 /* unexpected version, silently discard */
470 if (!s->first_packet && ssl_version != s->version)
471 goto again;
472
473 /* wrong version, silently discard record */
474 if ((ssl_version & 0xff00) != (s->version & 0xff00))
475 goto again;
476
477 /* record too long, silently discard it */
478 if (rr->length > SSL3_RT_MAX_ENCRYPTED_LENGTH)
479 goto again;
480
481 /* now s->rstate == SSL_ST_READ_BODY */
482 p = (unsigned char *)CBS_data(&header);
483 }
484
485 /* s->rstate == SSL_ST_READ_BODY, get and decode the data */
486
487 n = ssl3_packet_extend(s, DTLS1_RT_HEADER_LENGTH + rr->length);
488 if (n <= 0)
489 return (n);
490
491 /* If this packet contained a partial record, dump it. */
492 if (n != DTLS1_RT_HEADER_LENGTH + rr->length)
493 goto again;
494
495 s->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
496
497 /* match epochs. NULL means the packet is dropped on the floor */
498 bitmap = dtls1_get_bitmap(s, rr, &is_next_epoch);
499 if (bitmap == NULL)
500 goto again;
501
502 /*
503 * Check whether this is a repeat, or aged record.
504 * Don't check if we're listening and this message is
505 * a ClientHello. They can look as if they're replayed,
506 * since they arrive from different connections and
507 * would be dropped unnecessarily.
508 */
509 if (!(s->d1->listen && rr->type == SSL3_RT_HANDSHAKE &&
510 p != NULL && *p == SSL3_MT_CLIENT_HELLO) &&
511 !dtls1_record_replay_check(s, bitmap, rr->seq_num))
512 goto again;
513
514 /* just read a 0 length packet */
515 if (rr->length == 0)
516 goto again;
517
518 /* If this record is from the next epoch (either HM or ALERT),
519 * and a handshake is currently in progress, buffer it since it
520 * cannot be processed at this time. However, do not buffer
521 * anything while listening.
522 */
523 if (is_next_epoch) {
524 if ((SSL_in_init(s) || s->in_handshake) && !s->d1->listen) {
525 if (dtls1_buffer_record(s, &(s->d1->unprocessed_rcds),
526 rr->seq_num) < 0)
527 return (-1);
528 /* Mark receipt of record. */
529 dtls1_record_bitmap_update(s, bitmap, rr->seq_num);
530 }
531 goto again;
532 }
533
534 if (!dtls1_process_record(s))
535 goto again;
536
537 /* Mark receipt of record. */
538 dtls1_record_bitmap_update(s, bitmap, rr->seq_num);
539
540 return (1);
541}
542
543static int
544dtls1_read_handshake_unexpected(SSL *s)
545{
546 struct hm_header_st hs_msg_hdr;
547 CBS cbs;
548 int ret;
549
550 if (s->in_handshake) {
551 SSLerror(s, ERR_R_INTERNAL_ERROR);
552 return -1;
553 }
554
555 /* Parse handshake message header. */
556 CBS_dup(tls_content_cbs(s->s3->rcontent), &cbs);
557 if (!dtls1_get_message_header(&cbs, &hs_msg_hdr))
558 return -1; /* XXX - probably should drop/continue. */
559
560 /* This may just be a stale retransmit. */
561 if (tls_content_epoch(s->s3->rcontent) !=
562 tls12_record_layer_read_epoch(s->rl)) {
563 tls_content_clear(s->s3->rcontent);
564 s->s3->rrec.length = 0;
565 return 1;
566 }
567
568 if (hs_msg_hdr.type == SSL3_MT_HELLO_REQUEST) {
569 /*
570 * Incoming HelloRequest messages should only be received by a
571 * client. A server may send these at any time - a client should
572 * ignore the message if received in the middle of a handshake.
573 * See RFC 5246 sections 7.4 and 7.4.1.1.
574 */
575 if (s->server) {
576 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
577 ssl3_send_alert(s, SSL3_AL_FATAL,
578 SSL_AD_UNEXPECTED_MESSAGE);
579 return -1;
580 }
581
582 /* XXX - should also check frag offset/length. */
583 if (hs_msg_hdr.msg_len != 0) {
584 SSLerror(s, SSL_R_BAD_HELLO_REQUEST);
585 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
586 return -1;
587 }
588
589 ssl_msg_callback_cbs(s, 0, SSL3_RT_HANDSHAKE,
590 tls_content_cbs(s->s3->rcontent));
591
592 tls_content_clear(s->s3->rcontent);
593 s->s3->rrec.length = 0;
594
595 if ((s->options & SSL_OP_NO_RENEGOTIATION) != 0) {
596 ssl3_send_alert(s, SSL3_AL_WARNING,
597 SSL_AD_NO_RENEGOTIATION);
598 return 1;
599 }
600
601 /*
602 * It should be impossible to hit this, but keep the safety
603 * harness for now...
604 */
605 if (s->session == NULL || s->s3->hs.cipher == NULL)
606 return 1;
607
608 /*
609 * Ignore this message if we're currently handshaking,
610 * renegotiation is already pending or renegotiation is disabled
611 * via flags.
612 */
613 if (!SSL_is_init_finished(s) || s->s3->renegotiate ||
614 (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) != 0)
615 return 1;
616
617 s->d1->handshake_read_seq++;
618
619 /* XXX - why is this set here but not in ssl3? */
620 s->new_session = 1;
621
622 if (!ssl3_renegotiate(s))
623 return 1;
624 if (!ssl3_renegotiate_check(s))
625 return 1;
626
627 } else if (hs_msg_hdr.type == SSL3_MT_CLIENT_HELLO) {
628 /*
629 * Incoming ClientHello messages should only be received by a
630 * server. A client may send these in response to server
631 * initiated renegotiation (HelloRequest) or in order to
632 * initiate renegotiation by the client. See RFC 5246 section
633 * 7.4.1.2.
634 */
635 if (!s->server) {
636 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
637 ssl3_send_alert(s, SSL3_AL_FATAL,
638 SSL_AD_UNEXPECTED_MESSAGE);
639 return -1;
640 }
641
642 /*
643 * A client should not be sending a ClientHello unless we're not
644 * currently handshaking.
645 */
646 if (!SSL_is_init_finished(s)) {
647 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
648 ssl3_send_alert(s, SSL3_AL_FATAL,
649 SSL_AD_UNEXPECTED_MESSAGE);
650 return -1;
651 }
652
653 if ((s->options & SSL_OP_NO_CLIENT_RENEGOTIATION) != 0 ||
654 ((s->options & SSL_OP_NO_RENEGOTIATION) != 0 &&
655 (s->options & SSL_OP_ALLOW_CLIENT_RENEGOTIATION) == 0)) {
656 ssl3_send_alert(s, SSL3_AL_FATAL,
657 SSL_AD_NO_RENEGOTIATION);
658 return -1;
659 }
660
661 if (s->session == NULL || s->s3->hs.cipher == NULL) {
662 SSLerror(s, ERR_R_INTERNAL_ERROR);
663 return -1;
664 }
665
666 /* Client requested renegotiation but it is not permitted. */
667 if (!s->s3->send_connection_binding ||
668 (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) != 0) {
669 ssl3_send_alert(s, SSL3_AL_WARNING,
670 SSL_AD_NO_RENEGOTIATION);
671 return 1;
672 }
673
674 s->s3->hs.state = SSL_ST_ACCEPT;
675 s->renegotiate = 1;
676 s->new_session = 1;
677
678 } else if (hs_msg_hdr.type == SSL3_MT_FINISHED && s->server) {
679 /*
680 * If we are server, we may have a repeated FINISHED of the
681 * client here, then retransmit our CCS and FINISHED.
682 */
683 if (dtls1_check_timeout_num(s) < 0)
684 return -1;
685
686 /* XXX - should this be calling ssl_msg_callback()? */
687
688 dtls1_retransmit_buffered_messages(s);
689
690 tls_content_clear(s->s3->rcontent);
691 s->s3->rrec.length = 0;
692
693 return 1;
694
695 } else {
696 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
697 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
698 return -1;
699 }
700
701 if ((ret = s->handshake_func(s)) < 0)
702 return ret;
703 if (ret == 0) {
704 SSLerror(s, SSL_R_SSL_HANDSHAKE_FAILURE);
705 return -1;
706 }
707
708 if (!(s->mode & SSL_MODE_AUTO_RETRY)) {
709 if (s->s3->rbuf.left == 0) {
710 ssl_force_want_read(s);
711 return -1;
712 }
713 }
714
715 /*
716 * We either finished a handshake or ignored the request, now try again
717 * to obtain the (application) data we were asked for.
718 */
719 return 1;
720}
721
722/* Return up to 'len' payload bytes received in 'type' records.
723 * 'type' is one of the following:
724 *
725 * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
726 * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us)
727 * - 0 (during a shutdown, no data has to be returned)
728 *
729 * If we don't have stored data to work from, read a SSL/TLS record first
730 * (possibly multiple records if we still don't have anything to return).
731 *
732 * This function must handle any surprises the peer may have for us, such as
733 * Alert records (e.g. close_notify), ChangeCipherSpec records (not really
734 * a surprise, but handled as if it were), or renegotiation requests.
735 * Also if record payloads contain fragments too small to process, we store
736 * them until there is enough for the respective protocol (the record protocol
737 * may use arbitrary fragmentation and even interleaving):
738 * Change cipher spec protocol
739 * just 1 byte needed, no need for keeping anything stored
740 * Alert protocol
741 * 2 bytes needed (AlertLevel, AlertDescription)
742 * Handshake protocol
743 * 4 bytes needed (HandshakeType, uint24 length) -- we just have
744 * to detect unexpected Client Hello and Hello Request messages
745 * here, anything else is handled by higher layers
746 * Application data protocol
747 * none of our business
748 */
749int
750dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
751{
752 int rrcount = 0;
753 ssize_t ssret;
754 int ret;
755
756 if (s->s3->rbuf.buf == NULL) {
757 if (!ssl3_setup_buffers(s))
758 return -1;
759 }
760
761 if (s->s3->rcontent == NULL) {
762 if ((s->s3->rcontent = tls_content_new()) == NULL)
763 return -1;
764 }
765
766 if (len < 0) {
767 SSLerror(s, ERR_R_INTERNAL_ERROR);
768 return -1;
769 }
770
771 if (type != 0 && type != SSL3_RT_APPLICATION_DATA &&
772 type != SSL3_RT_HANDSHAKE) {
773 SSLerror(s, ERR_R_INTERNAL_ERROR);
774 return -1;
775 }
776 if (peek && type != SSL3_RT_APPLICATION_DATA) {
777 SSLerror(s, ERR_R_INTERNAL_ERROR);
778 return -1;
779 }
780
781 if (SSL_in_init(s) && !s->in_handshake) {
782 if ((ret = s->handshake_func(s)) < 0)
783 return ret;
784 if (ret == 0) {
785 SSLerror(s, SSL_R_SSL_HANDSHAKE_FAILURE);
786 return -1;
787 }
788 }
789
790 start:
791 /*
792 * Do not process more than three consecutive records, otherwise the
793 * peer can cause us to loop indefinitely. Instead, return with an
794 * SSL_ERROR_WANT_READ so the caller can choose when to handle further
795 * processing. In the future, the total number of non-handshake and
796 * non-application data records per connection should probably also be
797 * limited...
798 */
799 if (rrcount++ >= 3) {
800 ssl_force_want_read(s);
801 return -1;
802 }
803
804 s->rwstate = SSL_NOTHING;
805
806 /*
807 * We are not handshaking and have no data yet, so process data buffered
808 * during the last handshake in advance, if any.
809 */
810 if (s->s3->hs.state == SSL_ST_OK &&
811 tls_content_remaining(s->s3->rcontent) == 0)
812 dtls1_retrieve_buffered_rcontent(s, &s->d1->buffered_app_data);
813
814 if (dtls1_handle_timeout(s) > 0)
815 goto start;
816
817 if (tls_content_remaining(s->s3->rcontent) == 0) {
818 if ((ret = dtls1_get_record(s)) <= 0) {
819 /* Anything other than a timeout is an error. */
820 if ((ret = dtls1_read_failed(s, ret)) <= 0)
821 return ret;
822 goto start;
823 }
824 }
825
826 if (s->d1->listen &&
827 tls_content_type(s->s3->rcontent) != SSL3_RT_HANDSHAKE) {
828 tls_content_clear(s->s3->rcontent);
829 s->s3->rrec.length = 0;
830 goto start;
831 }
832
833 /* We now have a packet which can be read and processed. */
834
835 if (s->s3->change_cipher_spec &&
836 tls_content_type(s->s3->rcontent) != SSL3_RT_HANDSHAKE) {
837 /*
838 * We now have application data between CCS and Finished.
839 * Most likely the packets were reordered on their way, so
840 * buffer the application data for later processing rather
841 * than dropping the connection.
842 */
843 if (dtls1_buffer_rcontent(s, &s->d1->buffered_app_data,
844 s->s3->rrec.seq_num) < 0) {
845 SSLerror(s, ERR_R_INTERNAL_ERROR);
846 return (-1);
847 }
848 tls_content_clear(s->s3->rcontent);
849 s->s3->rrec.length = 0;
850 goto start;
851 }
852
853 /*
854 * If the other end has shut down, throw anything we read away (even in
855 * 'peek' mode).
856 */
857 if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
858 s->rwstate = SSL_NOTHING;
859 tls_content_clear(s->s3->rcontent);
860 s->s3->rrec.length = 0;
861 return 0;
862 }
863
864 /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */
865 if (tls_content_type(s->s3->rcontent) == type) {
866 /*
867 * Make sure that we are not getting application data when we
868 * are doing a handshake for the first time.
869 */
870 if (SSL_in_init(s) && type == SSL3_RT_APPLICATION_DATA &&
871 !tls12_record_layer_read_protected(s->rl)) {
872 SSLerror(s, SSL_R_APP_DATA_IN_HANDSHAKE);
873 ssl3_send_alert(s, SSL3_AL_FATAL,
874 SSL_AD_UNEXPECTED_MESSAGE);
875 return -1;
876 }
877
878 if (len <= 0)
879 return len;
880
881 if (peek) {
882 ssret = tls_content_peek(s->s3->rcontent, buf, len);
883 } else {
884 ssret = tls_content_read(s->s3->rcontent, buf, len);
885 }
886 if (ssret < INT_MIN || ssret > INT_MAX)
887 return -1;
888 if (ssret < 0)
889 return (int)ssret;
890
891 if (tls_content_remaining(s->s3->rcontent) == 0)
892 s->rstate = SSL_ST_READ_HEADER;
893
894 return (int)ssret;
895 }
896
897 if (tls_content_type(s->s3->rcontent) == SSL3_RT_ALERT) {
898 if ((ret = ssl3_read_alert(s)) <= 0)
899 return ret;
900 goto start;
901 }
902
903 if (s->shutdown & SSL_SENT_SHUTDOWN) {
904 s->rwstate = SSL_NOTHING;
905 tls_content_clear(s->s3->rcontent);
906 s->s3->rrec.length = 0;
907 return (0);
908 }
909
910 if (tls_content_type(s->s3->rcontent) == SSL3_RT_APPLICATION_DATA) {
911 /*
912 * At this point, we were expecting handshake data, but have
913 * application data. If the library was running inside
914 * ssl3_read() (i.e. in_read_app_data is set) and it makes
915 * sense to read application data at this point (session
916 * renegotiation not yet started), we will indulge it.
917 */
918 if (s->s3->in_read_app_data != 0 &&
919 s->s3->total_renegotiations != 0 &&
920 (((s->s3->hs.state & SSL_ST_CONNECT) &&
921 (s->s3->hs.state >= SSL3_ST_CW_CLNT_HELLO_A) &&
922 (s->s3->hs.state <= SSL3_ST_CR_SRVR_HELLO_A)) || (
923 (s->s3->hs.state & SSL_ST_ACCEPT) &&
924 (s->s3->hs.state <= SSL3_ST_SW_HELLO_REQ_A) &&
925 (s->s3->hs.state >= SSL3_ST_SR_CLNT_HELLO_A)))) {
926 s->s3->in_read_app_data = 2;
927 return -1;
928 } else {
929 SSLerror(s, SSL_R_UNEXPECTED_RECORD);
930 ssl3_send_alert(s, SSL3_AL_FATAL,
931 SSL_AD_UNEXPECTED_MESSAGE);
932 return -1;
933 }
934 }
935
936 if (tls_content_type(s->s3->rcontent) == SSL3_RT_CHANGE_CIPHER_SPEC) {
937 if ((ret = ssl3_read_change_cipher_spec(s)) <= 0)
938 return ret;
939 goto start;
940 }
941
942 if (tls_content_type(s->s3->rcontent) == SSL3_RT_HANDSHAKE) {
943 if ((ret = dtls1_read_handshake_unexpected(s)) <= 0)
944 return ret;
945 goto start;
946 }
947
948 /* Unknown record type. */
949 SSLerror(s, SSL_R_UNEXPECTED_RECORD);
950 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
951 return -1;
952}
953
954int
955dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, int len)
956{
957 int i;
958
959 if (SSL_in_init(s) && !s->in_handshake) {
960 i = s->handshake_func(s);
961 if (i < 0)
962 return (i);
963 if (i == 0) {
964 SSLerror(s, SSL_R_SSL_HANDSHAKE_FAILURE);
965 return -1;
966 }
967 }
968
969 if (len > SSL3_RT_MAX_PLAIN_LENGTH) {
970 SSLerror(s, SSL_R_DTLS_MESSAGE_TOO_BIG);
971 return -1;
972 }
973
974 i = dtls1_write_bytes(s, type, buf_, len);
975 return i;
976}
977
978/* Call this to write data in records of type 'type'
979 * It will return <= 0 if not all data has been sent or non-blocking IO.
980 */
981int
982dtls1_write_bytes(SSL *s, int type, const void *buf, int len)
983{
984 int i;
985
986 OPENSSL_assert(len <= SSL3_RT_MAX_PLAIN_LENGTH);
987 s->rwstate = SSL_NOTHING;
988 i = do_dtls1_write(s, type, buf, len);
989 return i;
990}
991
992int
993do_dtls1_write(SSL *s, int type, const unsigned char *buf, unsigned int len)
994{
995 SSL3_BUFFER_INTERNAL *wb = &(s->s3->wbuf);
996 size_t out_len;
997 CBB cbb;
998 int ret;
999
1000 memset(&cbb, 0, sizeof(cbb));
1001
1002 /*
1003 * First check if there is a SSL3_BUFFER_INTERNAL still being written
1004 * out. This will happen with non blocking IO.
1005 */
1006 if (wb->left != 0) {
1007 OPENSSL_assert(0); /* XDTLS: want to see if we ever get here */
1008 return (ssl3_write_pending(s, type, buf, len));
1009 }
1010
1011 /* If we have an alert to send, let's send it */
1012 if (s->s3->alert_dispatch) {
1013 if ((ret = ssl3_dispatch_alert(s)) <= 0)
1014 return (ret);
1015 /* If it went, fall through and send more stuff. */
1016 }
1017
1018 if (len == 0)
1019 return 0;
1020
1021 wb->offset = 0;
1022
1023 if (!CBB_init_fixed(&cbb, wb->buf, wb->len))
1024 goto err;
1025
1026 tls12_record_layer_set_version(s->rl, s->version);
1027
1028 if (!tls12_record_layer_seal_record(s->rl, type, buf, len, &cbb))
1029 goto err;
1030
1031 if (!CBB_finish(&cbb, NULL, &out_len))
1032 goto err;
1033
1034 wb->left = out_len;
1035
1036 /*
1037 * Memorize arguments so that ssl3_write_pending can detect
1038 * bad write retries later.
1039 */
1040 s->s3->wpend_tot = len;
1041 s->s3->wpend_buf = buf;
1042 s->s3->wpend_type = type;
1043 s->s3->wpend_ret = len;
1044
1045 /* We now just need to write the buffer. */
1046 return ssl3_write_pending(s, type, buf, len);
1047
1048 err:
1049 CBB_cleanup(&cbb);
1050
1051 return -1;
1052}
1053
1054static int
1055dtls1_record_replay_check(SSL *s, DTLS1_BITMAP *bitmap,
1056 const unsigned char *seq)
1057{
1058 unsigned int shift;
1059 int cmp;
1060
1061 cmp = satsub64be(seq, bitmap->max_seq_num);
1062 if (cmp > 0)
1063 return 1; /* this record in new */
1064 shift = -cmp;
1065 if (shift >= sizeof(bitmap->map)*8)
1066 return 0; /* stale, outside the window */
1067 else if (bitmap->map & (1UL << shift))
1068 return 0; /* record previously received */
1069
1070 return 1;
1071}
1072
1073static void
1074dtls1_record_bitmap_update(SSL *s, DTLS1_BITMAP *bitmap,
1075 const unsigned char *seq)
1076{
1077 unsigned int shift;
1078 int cmp;
1079
1080 cmp = satsub64be(seq, bitmap->max_seq_num);
1081 if (cmp > 0) {
1082 shift = cmp;
1083 if (shift < sizeof(bitmap->map)*8)
1084 bitmap->map <<= shift, bitmap->map |= 1UL;
1085 else
1086 bitmap->map = 1UL;
1087 memcpy(bitmap->max_seq_num, seq, 8);
1088 } else {
1089 shift = -cmp;
1090 if (shift < sizeof(bitmap->map) * 8)
1091 bitmap->map |= 1UL << shift;
1092 }
1093}
1094
1095static DTLS1_BITMAP *
1096dtls1_get_bitmap(SSL *s, SSL3_RECORD_INTERNAL *rr, unsigned int *is_next_epoch)
1097{
1098 uint16_t read_epoch, read_epoch_next;
1099
1100 *is_next_epoch = 0;
1101
1102 read_epoch = tls12_record_layer_read_epoch(s->rl);
1103 read_epoch_next = read_epoch + 1;
1104
1105 /* In current epoch, accept HM, CCS, DATA, & ALERT */
1106 if (rr->epoch == read_epoch)
1107 return &s->d1->bitmap;
1108
1109 /* Only HM and ALERT messages can be from the next epoch */
1110 if (rr->epoch == read_epoch_next &&
1111 (rr->type == SSL3_RT_HANDSHAKE || rr->type == SSL3_RT_ALERT)) {
1112 *is_next_epoch = 1;
1113 return &s->d1->next_bitmap;
1114 }
1115
1116 return NULL;
1117}
1118
1119void
1120dtls1_reset_read_seq_numbers(SSL *s)
1121{
1122 memcpy(&(s->d1->bitmap), &(s->d1->next_bitmap), sizeof(DTLS1_BITMAP));
1123 memset(&(s->d1->next_bitmap), 0, sizeof(DTLS1_BITMAP));
1124}
diff --git a/src/lib/libssl/d1_srtp.c b/src/lib/libssl/d1_srtp.c
deleted file mode 100644
index 67c4495a17..0000000000
--- a/src/lib/libssl/d1_srtp.c
+++ /dev/null
@@ -1,266 +0,0 @@
1/* $OpenBSD: d1_srtp.c,v 1.33 2023/07/08 16:40:13 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/*
112 * DTLS code by Eric Rescorla <ekr@rtfm.com>
113 *
114 * Copyright (C) 2006, Network Resonance, Inc.
115 * Copyright (C) 2011, RTFM, Inc.
116 */
117
118#include <stdio.h>
119
120#include <openssl/objects.h>
121#include <openssl/opensslconf.h>
122
123#ifndef OPENSSL_NO_SRTP
124
125#include "bytestring.h"
126#include "dtls_local.h"
127#include "ssl_local.h"
128#include "srtp.h"
129
130static const SRTP_PROTECTION_PROFILE srtp_known_profiles[] = {
131 {
132 "SRTP_AES128_CM_SHA1_80",
133 SRTP_AES128_CM_SHA1_80,
134 },
135 {
136 "SRTP_AES128_CM_SHA1_32",
137 SRTP_AES128_CM_SHA1_32,
138 },
139 {
140 "SRTP_AEAD_AES_128_GCM",
141 SRTP_AEAD_AES_128_GCM,
142 },
143 {
144 "SRTP_AEAD_AES_256_GCM",
145 SRTP_AEAD_AES_256_GCM,
146 },
147 {0}
148};
149
150int
151srtp_find_profile_by_name(const char *profile_name,
152 const SRTP_PROTECTION_PROFILE **pptr, unsigned int len)
153{
154 const SRTP_PROTECTION_PROFILE *p;
155
156 p = srtp_known_profiles;
157 while (p->name) {
158 if ((len == strlen(p->name)) &&
159 !strncmp(p->name, profile_name, len)) {
160 *pptr = p;
161 return 0;
162 }
163
164 p++;
165 }
166
167 return 1;
168}
169
170int
171srtp_find_profile_by_num(unsigned int profile_num,
172 const SRTP_PROTECTION_PROFILE **pptr)
173{
174 const SRTP_PROTECTION_PROFILE *p;
175
176 p = srtp_known_profiles;
177 while (p->name) {
178 if (p->id == profile_num) {
179 *pptr = p;
180 return 0;
181 }
182 p++;
183 }
184
185 return 1;
186}
187
188static int
189ssl_ctx_make_profiles(const char *profiles_string,
190 STACK_OF(SRTP_PROTECTION_PROFILE) **out)
191{
192 STACK_OF(SRTP_PROTECTION_PROFILE) *profiles;
193 char *col;
194 const char *ptr = profiles_string;
195 const SRTP_PROTECTION_PROFILE *p;
196
197 if (!(profiles = sk_SRTP_PROTECTION_PROFILE_new_null())) {
198 SSLerrorx(SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES);
199 return 1;
200 }
201
202 do {
203 col = strchr(ptr, ':');
204
205 if (!srtp_find_profile_by_name(ptr, &p,
206 col ? col - ptr : (int)strlen(ptr))) {
207 if (!sk_SRTP_PROTECTION_PROFILE_push(profiles, p)) {
208 sk_SRTP_PROTECTION_PROFILE_free(profiles);
209 return 1;
210 }
211 } else {
212 SSLerrorx(SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE);
213 sk_SRTP_PROTECTION_PROFILE_free(profiles);
214 return 1;
215 }
216
217 if (col)
218 ptr = col + 1;
219 } while (col);
220
221 sk_SRTP_PROTECTION_PROFILE_free(*out);
222 *out = profiles;
223
224 return 0;
225}
226
227int
228SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles)
229{
230 return ssl_ctx_make_profiles(profiles, &ctx->srtp_profiles);
231}
232LSSL_ALIAS(SSL_CTX_set_tlsext_use_srtp);
233
234int
235SSL_set_tlsext_use_srtp(SSL *s, const char *profiles)
236{
237 return ssl_ctx_make_profiles(profiles, &s->srtp_profiles);
238}
239LSSL_ALIAS(SSL_set_tlsext_use_srtp);
240
241
242STACK_OF(SRTP_PROTECTION_PROFILE) *
243SSL_get_srtp_profiles(SSL *s)
244{
245 if (s != NULL) {
246 if (s->srtp_profiles != NULL) {
247 return s->srtp_profiles;
248 } else if ((s->ctx != NULL) &&
249 (s->ctx->srtp_profiles != NULL)) {
250 return s->ctx->srtp_profiles;
251 }
252 }
253
254 return NULL;
255}
256LSSL_ALIAS(SSL_get_srtp_profiles);
257
258SRTP_PROTECTION_PROFILE *
259SSL_get_selected_srtp_profile(SSL *s)
260{
261 /* XXX cast away the const */
262 return (SRTP_PROTECTION_PROFILE *)s->srtp_profile;
263}
264LSSL_ALIAS(SSL_get_selected_srtp_profile);
265
266#endif
diff --git a/src/lib/libssl/doc/openssl.cnf b/src/lib/libssl/doc/openssl.cnf
deleted file mode 100644
index db95bb5c18..0000000000
--- a/src/lib/libssl/doc/openssl.cnf
+++ /dev/null
@@ -1,348 +0,0 @@
1#
2# OpenSSL example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6# This definition stops the following lines choking if HOME isn't
7# defined.
8HOME = .
9
10# Extra OBJECT IDENTIFIER info:
11#oid_file = $ENV::HOME/.oid
12oid_section = new_oids
13
14# To use this configuration file with the "-extfile" option of the
15# "openssl x509" utility, name here the section containing the
16# X.509v3 extensions to use:
17# extensions =
18# (Alternatively, use a configuration file that has only
19# X.509v3 extensions in its main [= default] section.)
20
21[ new_oids ]
22
23# We can add new OIDs in here for use by 'ca', 'req' and 'ts'.
24# Add a simple OID like this:
25# testoid1=1.2.3.4
26# Or use config file substitution like this:
27# testoid2=${testoid1}.5.6
28
29# Policies used by the TSA examples.
30tsa_policy1 = 1.2.3.4.1
31tsa_policy2 = 1.2.3.4.5.6
32tsa_policy3 = 1.2.3.4.5.7
33
34####################################################################
35[ ca ]
36default_ca = CA_default # The default ca section
37
38####################################################################
39[ CA_default ]
40
41dir = ./demoCA # Where everything is kept
42certs = $dir/certs # Where the issued certs are kept
43crl_dir = $dir/crl # Where the issued crl are kept
44database = $dir/index.txt # database index file.
45#unique_subject = no # Set to 'no' to allow creation of
46 # several certificates with same subject.
47new_certs_dir = $dir/newcerts # default place for new certs.
48
49certificate = $dir/cacert.pem # The CA certificate
50serial = $dir/serial # The current serial number
51crlnumber = $dir/crlnumber # the current crl number
52 # must be commented out to leave a V1 CRL
53crl = $dir/crl.pem # The current CRL
54private_key = $dir/private/cakey.pem# The private key
55
56x509_extensions = usr_cert # The extensions to add to the cert
57
58# Comment out the following two lines for the "traditional"
59# (and highly broken) format.
60name_opt = ca_default # Subject Name options
61cert_opt = ca_default # Certificate field options
62
63# Extension copying option: use with caution.
64# copy_extensions = copy
65
66# Extensions to add to a CRL. Note: Netscape communicator chokes on V2 CRLs
67# so this is commented out by default to leave a V1 CRL.
68# crlnumber must also be commented out to leave a V1 CRL.
69# crl_extensions = crl_ext
70
71default_days = 365 # how long to certify for
72default_crl_days= 30 # how long before next CRL
73default_md = default # use public key default MD
74preserve = no # keep passed DN ordering
75
76# A few difference way of specifying how similar the request should look
77# For type CA, the listed attributes must be the same, and the optional
78# and supplied fields are just that :-)
79policy = policy_match
80
81# For the CA policy
82[ policy_match ]
83countryName = match
84stateOrProvinceName = match
85organizationName = match
86organizationalUnitName = optional
87commonName = supplied
88emailAddress = optional
89
90# For the 'anything' policy
91# At this point in time, you must list all acceptable 'object'
92# types.
93[ policy_anything ]
94countryName = optional
95stateOrProvinceName = optional
96localityName = optional
97organizationName = optional
98organizationalUnitName = optional
99commonName = supplied
100emailAddress = optional
101
102####################################################################
103[ req ]
104default_bits = 1024
105default_keyfile = privkey.pem
106distinguished_name = req_distinguished_name
107attributes = req_attributes
108x509_extensions = v3_ca # The extensions to add to the self signed cert
109
110# Passwords for private keys if not present they will be prompted for
111# input_password = secret
112# output_password = secret
113
114# This sets a mask for permitted string types. There are several options.
115# default: PrintableString, T61String, BMPString.
116# pkix : PrintableString, BMPString (PKIX recommendation before 2004)
117# utf8only: only UTF8Strings (PKIX recommendation after 2004).
118# nombstr : PrintableString, T61String (no BMPStrings or UTF8Strings).
119# MASK:XXXX a literal mask value.
120# WARNING: ancient versions of Netscape crash on BMPStrings or UTF8Strings.
121string_mask = utf8only
122
123# req_extensions = v3_req # The extensions to add to a certificate request
124
125[ req_distinguished_name ]
126countryName = Country Name (2 letter code)
127countryName_default = AU
128countryName_min = 2
129countryName_max = 2
130
131stateOrProvinceName = State or Province Name (full name)
132stateOrProvinceName_default = Some-State
133
134localityName = Locality Name (eg, city)
135
1360.organizationName = Organization Name (eg, company)
1370.organizationName_default = Internet Widgits Pty Ltd
138
139# we can do this but it is not needed normally :-)
140#1.organizationName = Second Organization Name (eg, company)
141#1.organizationName_default = World Wide Web Pty Ltd
142
143organizationalUnitName = Organizational Unit Name (eg, section)
144#organizationalUnitName_default =
145
146commonName = Common Name (e.g. server FQDN or YOUR name)
147commonName_max = 64
148
149emailAddress = Email Address
150emailAddress_max = 64
151
152# SET-ex3 = SET extension number 3
153
154[ req_attributes ]
155challengePassword = A challenge password
156challengePassword_min = 4
157challengePassword_max = 20
158
159unstructuredName = An optional company name
160
161[ usr_cert ]
162
163# These extensions are added when 'ca' signs a request.
164
165# This goes against PKIX guidelines but some CAs do it and some software
166# requires this to avoid interpreting an end user certificate as a CA.
167
168basicConstraints=CA:FALSE
169
170# Here are some examples of the usage of nsCertType. If it is omitted
171# the certificate can be used for anything *except* object signing.
172
173# This is OK for an SSL server.
174# nsCertType = server
175
176# For an object signing certificate this would be used.
177# nsCertType = objsign
178
179# For normal client use this is typical
180# nsCertType = client, email
181
182# and for everything including object signing:
183# nsCertType = client, email, objsign
184
185# This is typical in keyUsage for a client certificate.
186# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
187
188# This will be displayed in Netscape's comment listbox.
189nsComment = "OpenSSL Generated Certificate"
190
191# PKIX recommendations harmless if included in all certificates.
192subjectKeyIdentifier=hash
193authorityKeyIdentifier=keyid,issuer
194
195# This stuff is for subjectAltName and issuerAltname.
196# Import the email address.
197# subjectAltName=email:copy
198# An alternative to produce certificates that aren't
199# deprecated according to PKIX.
200# subjectAltName=email:move
201
202# Copy subject details
203# issuerAltName=issuer:copy
204
205#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
206#nsBaseUrl
207#nsRevocationUrl
208#nsRenewalUrl
209#nsCaPolicyUrl
210#nsSslServerName
211
212# This is required for TSA certificates.
213# extendedKeyUsage = critical,timeStamping
214
215[ v3_req ]
216
217# Extensions to add to a certificate request
218
219basicConstraints = CA:FALSE
220keyUsage = nonRepudiation, digitalSignature, keyEncipherment
221
222[ v3_ca ]
223
224
225# Extensions for a typical CA
226
227
228# PKIX recommendation.
229
230subjectKeyIdentifier=hash
231
232authorityKeyIdentifier=keyid:always,issuer
233
234# This is what PKIX recommends but some broken software chokes on critical
235# extensions.
236#basicConstraints = critical,CA:true
237# So we do this instead.
238basicConstraints = CA:true
239
240# Key usage: this is typical for a CA certificate. However since it will
241# prevent it being used as an test self-signed certificate it is best
242# left out by default.
243# keyUsage = cRLSign, keyCertSign
244
245# Some might want this also
246# nsCertType = sslCA, emailCA
247
248# Include email address in subject alt name: another PKIX recommendation
249# subjectAltName=email:copy
250# Copy issuer details
251# issuerAltName=issuer:copy
252
253# DER hex encoding of an extension: beware experts only!
254# obj=DER:02:03
255# Where 'obj' is a standard or added object
256# You can even override a supported extension:
257# basicConstraints= critical, DER:30:03:01:01:FF
258
259[ crl_ext ]
260
261# CRL extensions.
262# Only issuerAltName and authorityKeyIdentifier make any sense in a CRL.
263
264# issuerAltName=issuer:copy
265authorityKeyIdentifier=keyid:always
266
267[ proxy_cert_ext ]
268# These extensions should be added when creating a proxy certificate
269
270# This goes against PKIX guidelines but some CAs do it and some software
271# requires this to avoid interpreting an end user certificate as a CA.
272
273basicConstraints=CA:FALSE
274
275# Here are some examples of the usage of nsCertType. If it is omitted
276# the certificate can be used for anything *except* object signing.
277
278# This is OK for an SSL server.
279# nsCertType = server
280
281# For an object signing certificate this would be used.
282# nsCertType = objsign
283
284# For normal client use this is typical
285# nsCertType = client, email
286
287# and for everything including object signing:
288# nsCertType = client, email, objsign
289
290# This is typical in keyUsage for a client certificate.
291# keyUsage = nonRepudiation, digitalSignature, keyEncipherment
292
293# This will be displayed in Netscape's comment listbox.
294nsComment = "OpenSSL Generated Certificate"
295
296# PKIX recommendations harmless if included in all certificates.
297subjectKeyIdentifier=hash
298authorityKeyIdentifier=keyid,issuer
299
300# This stuff is for subjectAltName and issuerAltname.
301# Import the email address.
302# subjectAltName=email:copy
303# An alternative to produce certificates that aren't
304# deprecated according to PKIX.
305# subjectAltName=email:move
306
307# Copy subject details
308# issuerAltName=issuer:copy
309
310#nsCaRevocationUrl = http://www.domain.dom/ca-crl.pem
311#nsBaseUrl
312#nsRevocationUrl
313#nsRenewalUrl
314#nsCaPolicyUrl
315#nsSslServerName
316
317# This really needs to be in place for it to be a proxy certificate.
318proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:3,policy:foo
319
320####################################################################
321[ tsa ]
322
323default_tsa = tsa_config1 # the default TSA section
324
325[ tsa_config1 ]
326
327# These are used by the TSA reply generation only.
328dir = ./demoCA # TSA root directory
329serial = $dir/tsaserial # The current serial number (mandatory)
330crypto_device = builtin # OpenSSL engine to use for signing
331signer_cert = $dir/tsacert.pem # The TSA signing certificate
332 # (optional)
333certs = $dir/cacert.pem # Certificate chain to include in reply
334 # (optional)
335signer_key = $dir/private/tsakey.pem # The TSA private key (optional)
336
337default_policy = tsa_policy1 # Policy if request did not specify it
338 # (optional)
339other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
340digests = md5, sha1 # Acceptable message digests (mandatory)
341accuracy = secs:1, millisecs:500, microsecs:100 # (optional)
342clock_precision_digits = 0 # number of digits after dot. (optional)
343ordering = yes # Is ordering defined for timestamps?
344 # (optional, default: no)
345tsa_name = yes # Must the TSA name be included in the reply?
346 # (optional, default: no)
347ess_cert_id_chain = no # Must the ESS cert id chain be included?
348 # (optional, default: no)
diff --git a/src/lib/libssl/doc/openssl.txt b/src/lib/libssl/doc/openssl.txt
deleted file mode 100644
index f8817b0a71..0000000000
--- a/src/lib/libssl/doc/openssl.txt
+++ /dev/null
@@ -1,1254 +0,0 @@
1
2This is some preliminary documentation for OpenSSL.
3
4Contents:
5
6 OpenSSL X509V3 extension configuration
7 X509V3 Extension code: programmers guide
8 PKCS#12 Library
9
10
11==============================================================================
12 OpenSSL X509V3 extension configuration
13==============================================================================
14
15OpenSSL X509V3 extension configuration: preliminary documentation.
16
17INTRODUCTION.
18
19For OpenSSL 0.9.2 the extension code has be considerably enhanced. It is now
20possible to add and print out common X509 V3 certificate and CRL extensions.
21
22BEGINNERS NOTE
23
24For most simple applications you don't need to know too much about extensions:
25the default openssl.cnf values will usually do sensible things.
26
27If you want to know more you can initially quickly look through the sections
28describing how the standard OpenSSL utilities display and add extensions and
29then the list of supported extensions.
30
31For more technical information about the meaning of extensions see:
32
33http://www.imc.org/ietf-pkix/
34http://home.netscape.com/eng/security/certs.html
35
36PRINTING EXTENSIONS.
37
38Extension values are automatically printed out for supported extensions.
39
40openssl x509 -in cert.pem -text
41openssl crl -in crl.pem -text
42
43will give information in the extension printout, for example:
44
45 X509v3 extensions:
46 X509v3 Basic Constraints:
47 CA:TRUE
48 X509v3 Subject Key Identifier:
49 73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15
50 X509v3 Authority Key Identifier:
51 keyid:73:FE:F7:59:A7:E1:26:84:44:D6:44:36:EE:79:1A:95:7C:B1:4B:15, DirName:/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/Email=email@1.address/Email=email@2.address, serial:00
52 X509v3 Key Usage:
53 Certificate Sign, CRL Sign
54 X509v3 Subject Alternative Name:
55 email:email@1.address, email:email@2.address
56
57CONFIGURATION FILES.
58
59The OpenSSL utilities 'ca' and 'req' can now have extension sections listing
60which certificate extensions to include. In each case a line:
61
62x509_extensions = extension_section
63
64indicates which section contains the extensions. In the case of 'req' the
65extension section is used when the -x509 option is present to create a
66self signed root certificate.
67
68The 'x509' utility also supports extensions when it signs a certificate.
69The -extfile option is used to set the configuration file containing the
70extensions. In this case a line with:
71
72extensions = extension_section
73
74in the nameless (default) section is used. If no such line is included then
75it uses the default section.
76
77You can also add extensions to CRLs: a line
78
79crl_extensions = crl_extension_section
80
81will include extensions when the -gencrl option is used with the 'ca' utility.
82You can add any extension to a CRL but of the supported extensions only
83issuerAltName and authorityKeyIdentifier make any real sense. Note: these are
84CRL extensions NOT CRL *entry* extensions which cannot currently be generated.
85CRL entry extensions can be displayed.
86
87NB. At this time Netscape Communicator rejects V2 CRLs: to get an old V1 CRL
88you should not include a crl_extensions line in the configuration file.
89
90As with all configuration files you can use the inbuilt environment expansion
91to allow the values to be passed in the environment. Therefore if you have
92several extension sections used for different purposes you can have a line:
93
94x509_extensions = $ENV::ENV_EXT
95
96and set the ENV_EXT environment variable before calling the relevant utility.
97
98EXTENSION SYNTAX.
99
100Extensions have the basic form:
101
102extension_name=[critical,] extension_options
103
104the use of the critical option makes the extension critical. Extreme caution
105should be made when using the critical flag. If an extension is marked
106as critical then any client that does not understand the extension should
107reject it as invalid. Some broken software will reject certificates which
108have *any* critical extensions (these violates PKIX but we have to live
109with it).
110
111There are three main types of extension: string extensions, multi-valued
112extensions, and raw extensions.
113
114String extensions simply have a string which contains either the value itself
115or how it is obtained.
116
117For example:
118
119nsComment="This is a Comment"
120
121Multi-valued extensions have a short form and a long form. The short form
122is a list of names and values:
123
124basicConstraints=critical,CA:true,pathlen:1
125
126The long form allows the values to be placed in a separate section:
127
128basicConstraints=critical,@bs_section
129
130[bs_section]
131
132CA=true
133pathlen=1
134
135Both forms are equivalent. However it should be noted that in some cases the
136same name can appear multiple times, for example,
137
138subjectAltName=email:steve@here,email:steve@there
139
140in this case an equivalent long form is:
141
142subjectAltName=@alt_section
143
144[alt_section]
145
146email.1=steve@here
147email.2=steve@there
148
149This is because the configuration file code cannot handle the same name
150occurring twice in the same section.
151
152The syntax of raw extensions is governed by the extension code: it can
153for example contain data in multiple sections. The correct syntax to
154use is defined by the extension code itself: check out the certificate
155policies extension for an example.
156
157There are two ways to encode arbitrary extensions.
158
159The first way is to use the word ASN1 followed by the extension content
160using the same syntax as ASN1_generate_nconf(). For example:
161
1621.2.3.4=critical,ASN1:UTF8String:Some random data
163
1641.2.3.4=ASN1:SEQUENCE:seq_sect
165
166[seq_sect]
167
168field1 = UTF8:field1
169field2 = UTF8:field2
170
171It is also possible to use the word DER to include arbitrary data in any
172extension.
173
1741.2.3.4=critical,DER:01:02:03:04
1751.2.3.4=DER:01020304
176
177The value following DER is a hex dump of the DER encoding of the extension
178Any extension can be placed in this form to override the default behaviour.
179For example:
180
181basicConstraints=critical,DER:00:01:02:03
182
183WARNING: DER should be used with caution. It is possible to create totally
184invalid extensions unless care is taken.
185
186CURRENTLY SUPPORTED EXTENSIONS.
187
188If you aren't sure about extensions then they can be largely ignored: its only
189when you want to do things like restrict certificate usage when you need to
190worry about them.
191
192The only extension that a beginner might want to look at is Basic Constraints.
193If in addition you want to try Netscape object signing the you should also
194look at Netscape Certificate Type.
195
196Literal String extensions.
197
198In each case the 'value' of the extension is placed directly in the
199extension. Currently supported extensions in this category are: nsBaseUrl,
200nsRevocationUrl, nsCaRevocationUrl, nsRenewalUrl, nsCaPolicyUrl,
201nsSslServerName and nsComment.
202
203For example:
204
205nsComment="This is a test comment"
206
207Bit Strings.
208
209Bit string extensions just consist of a list of supported bits, currently
210two extensions are in this category: PKIX keyUsage and the Netscape specific
211nsCertType.
212
213nsCertType (netscape certificate type) takes the flags: client, server, email,
214objsign, reserved, sslCA, emailCA, objCA.
215
216keyUsage (PKIX key usage) takes the flags: digitalSignature, nonRepudiation,
217keyEncipherment, dataEncipherment, keyAgreement, keyCertSign, cRLSign,
218encipherOnly, decipherOnly.
219
220For example:
221
222nsCertType=server
223
224keyUsage=digitalSignature, nonRepudiation
225
226Hints on Netscape Certificate Type.
227
228Other than Basic Constraints this is the only extension a beginner might
229want to use, if you want to try Netscape object signing, otherwise it can
230be ignored.
231
232If you want a certificate that can be used just for object signing then:
233
234nsCertType=objsign
235
236will do the job. If you want to use it as a normal end user and server
237certificate as well then
238
239nsCertType=objsign,email,server
240
241is more appropriate. You cannot use a self signed certificate for object
242signing (well Netscape signtool can but it cheats!) so you need to create
243a CA certificate and sign an end user certificate with it.
244
245Side note: If you want to conform to the Netscape specifications then you
246should really also set:
247
248nsCertType=objCA
249
250in the *CA* certificate for just an object signing CA and
251
252nsCertType=objCA,emailCA,sslCA
253
254for everything. Current Netscape software doesn't enforce this so it can
255be omitted.
256
257Basic Constraints.
258
259This is generally the only extension you need to worry about for simple
260applications. If you want your certificate to be usable as a CA certificate
261(in addition to an end user certificate) then you set this to:
262
263basicConstraints=CA:TRUE
264
265if you want to be certain the certificate cannot be used as a CA then do:
266
267basicConstraints=CA:FALSE
268
269The rest of this section describes more advanced usage.
270
271Basic constraints is a multi-valued extension that supports a CA and an
272optional pathlen option. The CA option takes the values true and false and
273pathlen takes an integer. Note if the CA option is false the pathlen option
274should be omitted.
275
276The pathlen parameter indicates the maximum number of CAs that can appear
277below this one in a chain. So if you have a CA with a pathlen of zero it can
278only be used to sign end user certificates and not further CAs. This all
279assumes that the software correctly interprets this extension of course.
280
281Examples:
282
283basicConstraints=CA:TRUE
284basicConstraints=critical,CA:TRUE, pathlen:0
285
286NOTE: for a CA to be considered valid it must have the CA option set to
287TRUE. An end user certificate MUST NOT have the CA value set to true.
288According to PKIX recommendations it should exclude the extension entirely,
289however some software may require CA set to FALSE for end entity certificates.
290
291Extended Key Usage.
292
293This extensions consists of a list of usages.
294
295These can either be object short names of the dotted numerical form of OIDs.
296While any OID can be used only certain values make sense. In particular the
297following PKIX, NS and MS values are meaningful:
298
299Value Meaning
300----- -------
301serverAuth SSL/TLS Web Server Authentication.
302clientAuth SSL/TLS Web Client Authentication.
303codeSigning Code signing.
304emailProtection E-mail Protection (S/MIME).
305timeStamping Trusted Timestamping
306msCodeInd Microsoft Individual Code Signing (authenticode)
307msCodeCom Microsoft Commercial Code Signing (authenticode)
308msCTLSign Microsoft Trust List Signing
309msSGC Microsoft Server Gated Crypto
310msEFS Microsoft Encrypted File System
311nsSGC Netscape Server Gated Crypto
312
313For example, under IE5 a CA can be used for any purpose: by including a list
314of the above usages the CA can be restricted to only authorised uses.
315
316Note: software packages may place additional interpretations on certificate
317use, in particular some usages may only work for selected CAs. Don't for example
318expect just including msSGC or nsSGC will automatically mean that a certificate
319can be used for SGC ("step up" encryption) otherwise anyone could use it.
320
321Examples:
322
323extendedKeyUsage=critical,codeSigning,1.2.3.4
324extendedKeyUsage=nsSGC,msSGC
325
326Subject Key Identifier.
327
328This is really a string extension and can take two possible values. Either
329a hex string giving details of the extension value to include or the word
330'hash' which then automatically follow PKIX guidelines in selecting and
331appropriate key identifier. The use of the hex string is strongly discouraged.
332
333Example: subjectKeyIdentifier=hash
334
335Authority Key Identifier.
336
337The authority key identifier extension permits two options. keyid and issuer:
338both can take the optional value "always".
339
340If the keyid option is present an attempt is made to copy the subject key
341identifier from the parent certificate. If the value "always" is present
342then an error is returned if the option fails.
343
344The issuer option copies the issuer and serial number from the issuer
345certificate. Normally this will only be done if the keyid option fails or
346is not included: the "always" flag will always include the value.
347
348Subject Alternative Name.
349
350The subject alternative name extension allows various literal values to be
351included in the configuration file. These include "email" (an email address)
352"URI" a uniform resource indicator, "DNS" (a DNS domain name), RID (a
353registered ID: OBJECT IDENTIFIER), IP (and IP address) and otherName.
354
355Also the email option include a special 'copy' value. This will automatically
356include and email addresses contained in the certificate subject name in
357the extension.
358
359otherName can include arbitrary data associated with an OID: the value
360should be the OID followed by a semicolon and the content in standard
361ASN1_generate_nconf() format.
362
363Examples:
364
365subjectAltName=email:copy,email:my@other.address,URI:http://my.url.here/
366subjectAltName=email:my@other.address,RID:1.2.3.4
367subjectAltName=otherName:1.2.3.4;UTF8:some other identifier
368
369Issuer Alternative Name.
370
371The issuer alternative name option supports all the literal options of
372subject alternative name. It does *not* support the email:copy option because
373that would not make sense. It does support an additional issuer:copy option
374that will copy all the subject alternative name values from the issuer
375certificate (if possible).
376
377Example:
378
379issuserAltName = issuer:copy
380
381Authority Info Access.
382
383The authority information access extension gives details about how to access
384certain information relating to the CA. Its syntax is accessOID;location
385where 'location' has the same syntax as subject alternative name (except
386that email:copy is not supported). accessOID can be any valid OID but only
387certain values are meaningful for example OCSP and caIssuers. OCSP gives the
388location of an OCSP responder: this is used by Netscape PSM and other software.
389
390Example:
391
392authorityInfoAccess = OCSP;URI:http://ocsp.my.host/
393authorityInfoAccess = caIssuers;URI:http://my.ca/ca.html
394
395CRL distribution points.
396
397This is a multi-valued extension that supports all the literal options of
398subject alternative name. Of the few software packages that currently interpret
399this extension most only interpret the URI option.
400
401Currently each option will set a new DistributionPoint with the fullName
402field set to the given value.
403
404Other fields like cRLissuer and reasons cannot currently be set or displayed:
405at this time no examples were available that used these fields.
406
407If you see this extension with <UNSUPPORTED> when you attempt to print it out
408or it doesn't appear to display correctly then let me know, including the
409certificate (mail me at steve@openssl.org) .
410
411Examples:
412
413crlDistributionPoints=URI:http://www.myhost.com/myca.crl
414crlDistributionPoints=URI:http://www.my.com/my.crl,URI:http://www.oth.com/my.crl
415
416Certificate Policies.
417
418This is a RAW extension. It attempts to display the contents of this extension:
419unfortunately this extension is often improperly encoded.
420
421The certificate policies extension will rarely be used in practice: few
422software packages interpret it correctly or at all. IE5 does partially
423support this extension: but it needs the 'ia5org' option because it will
424only correctly support a broken encoding. Of the options below only the
425policy OID, explicitText and CPS options are displayed with IE5.
426
427All the fields of this extension can be set by using the appropriate syntax.
428
429If you follow the PKIX recommendations of not including any qualifiers and just
430using only one OID then you just include the value of that OID. Multiple OIDs
431can be set separated by commas, for example:
432
433certificatePolicies= 1.2.4.5, 1.1.3.4
434
435If you wish to include qualifiers then the policy OID and qualifiers need to
436be specified in a separate section: this is done by using the @section syntax
437instead of a literal OID value.
438
439The section referred to must include the policy OID using the name
440policyIdentifier, cPSuri qualifiers can be included using the syntax:
441
442CPS.nnn=value
443
444userNotice qualifiers can be set using the syntax:
445
446userNotice.nnn=@notice
447
448The value of the userNotice qualifier is specified in the relevant section.
449This section can include explicitText, organization and noticeNumbers
450options. explicitText and organization are text strings, noticeNumbers is a
451comma separated list of numbers. The organization and noticeNumbers options
452(if included) must BOTH be present. If you use the userNotice option with IE5
453then you need the 'ia5org' option at the top level to modify the encoding:
454otherwise it will not be interpreted properly.
455
456Example:
457
458certificatePolicies=ia5org,1.2.3.4,1.5.6.7.8,@polsect
459
460[polsect]
461
462policyIdentifier = 1.3.5.8
463CPS.1="http://my.host.name/"
464CPS.2="http://my.your.name/"
465userNotice.1=@notice
466
467[notice]
468
469explicitText="Explicit Text Here"
470organization="Organisation Name"
471noticeNumbers=1,2,3,4
472
473TECHNICAL NOTE: the ia5org option changes the type of the 'organization' field,
474according to PKIX it should be of type DisplayText but Verisign uses an
475IA5STRING and IE5 needs this too.
476
477Display only extensions.
478
479Some extensions are only partially supported and currently are only displayed
480but cannot be set. These include private key usage period, CRL number, and
481CRL reason.
482
483==============================================================================
484 X509V3 Extension code: programmers guide
485==============================================================================
486
487The purpose of the extension code is twofold. It allows an extension to be
488created from a string or structure describing its contents and it prints out an
489extension in a human or machine readable form.
490
4911. Initialisation and cleanup.
492
493No special initialisation is needed before calling the extension functions.
494You used to have to call X509V3_add_standard_extensions(); but this is no longer
495required and this function no longer does anything.
496
497void X509V3_EXT_cleanup(void);
498
499This function should be called to cleanup the extension code if any custom
500extensions have been added. If no custom extensions have been added then this
501call does nothing. After this call all custom extension code is freed up but
502you can still use the standard extensions.
503
5042. Printing and parsing extensions.
505
506The simplest way to print out extensions is via the standard X509 printing
507routines: if you use the standard X509_print() function, the supported
508extensions will be printed out automatically.
509
510The following functions allow finer control over extension display:
511
512int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, int flag, int indent);
513int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, int indent);
514
515These two functions print out an individual extension to a BIO or FILE pointer.
516Currently the flag argument is unused and should be set to 0. The 'indent'
517argument is the number of spaces to indent each line.
518
519void *X509V3_EXT_d2i(X509_EXTENSION *ext);
520
521This function parses an extension and returns its internal structure. The
522precise structure you get back depends on the extension being parsed. If the
523extension if basicConstraints you will get back a pointer to a
524BASIC_CONSTRAINTS structure. Check out the source in crypto/x509v3 for more
525details about the structures returned. The returned structure should be freed
526after use using the relevant free function, BASIC_CONSTRAINTS_free() for
527example.
528
529void * X509_get_ext_d2i(X509 *x, int nid, int *crit, int *idx);
530void * X509_CRL_get_ext_d2i(X509_CRL *x, int nid, int *crit, int *idx);
531void * X509_REVOKED_get_ext_d2i(X509_REVOKED *x, int nid, int *crit, int *idx);
532void * X509V3_get_d2i(STACK_OF(X509_EXTENSION) *x, int nid, int *crit, int *idx);
533
534These functions combine the operations of searching for extensions and
535parsing them. They search a certificate, a CRL a CRL entry or a stack
536of extensions respectively for extension whose NID is 'nid' and return
537the parsed result of NULL if an error occurred. For example:
538
539BASIC_CONSTRAINTS *bs;
540bs = X509_get_ext_d2i(cert, NID_basic_constraints, NULL, NULL);
541
542This will search for the basicConstraints extension and either return
543it value or NULL. NULL can mean either the extension was not found, it
544occurred more than once or it could not be parsed.
545
546If 'idx' is NULL then an extension is only parsed if it occurs precisely
547once. This is standard behaviour because extensions normally cannot occur
548more than once. If however more than one extension of the same type can
549occur it can be used to parse successive extensions for example:
550
551int i;
552void *ext;
553
554i = -1;
555for(;;) {
556 ext = X509_get_ext_d2i(x, nid, crit, &idx);
557 if(ext == NULL) break;
558 /* Do something with ext */
559}
560
561If 'crit' is not NULL and the extension was found then the int it points to
562is set to 1 for critical extensions and 0 for non critical. Therefore if the
563function returns NULL but 'crit' is set to 0 or 1 then the extension was
564found but it could not be parsed.
565
566The int pointed to by crit will be set to -1 if the extension was not found
567and -2 if the extension occurred more than once (this will only happen if
568idx is NULL). In both cases the function will return NULL.
569
5703. Generating extensions.
571
572An extension will typically be generated from a configuration file, or some
573other kind of configuration database.
574
575int X509V3_EXT_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
576 X509 *cert);
577int X509V3_EXT_CRL_add_conf(LHASH *conf, X509V3_CTX *ctx, char *section,
578 X509_CRL *crl);
579
580These functions add all the extensions in the given section to the given
581certificate or CRL. They will normally be called just before the certificate
582or CRL is due to be signed. Both return 0 on error on non zero for success.
583
584In each case 'conf' is the LHASH pointer of the configuration file to use
585and 'section' is the section containing the extension details.
586
587See the 'context functions' section for a description of the ctx parameter.
588
589
590X509_EXTENSION *X509V3_EXT_conf(LHASH *conf, X509V3_CTX *ctx, char *name,
591 char *value);
592
593This function returns an extension based on a name and value pair, if the
594pair will not need to access other sections in a config file (or there is no
595config file) then the 'conf' parameter can be set to NULL.
596
597X509_EXTENSION *X509V3_EXT_conf_nid(char *conf, X509V3_CTX *ctx, int nid,
598 char *value);
599
600This function creates an extension in the same way as X509V3_EXT_conf() but
601takes the NID of the extension rather than its name.
602
603For example to produce basicConstraints with the CA flag and a path length of
60410:
605
606x = X509V3_EXT_conf_nid(NULL, NULL, NID_basic_constraints,"CA:TRUE,pathlen:10");
607
608
609X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, void *ext_struc);
610
611This function sets up an extension from its internal structure. The ext_nid
612parameter is the NID of the extension and 'crit' is the critical flag.
613
6144. Context functions.
615
616The following functions set and manipulate an extension context structure.
617The purpose of the extension context is to allow the extension code to
618access various structures relating to the "environment" of the certificate:
619for example the issuers certificate or the certificate request.
620
621void X509V3_set_ctx(X509V3_CTX *ctx, X509 *issuer, X509 *subject,
622 X509_REQ *req, X509_CRL *crl, int flags);
623
624This function sets up an X509V3_CTX structure with details of the certificate
625environment: specifically the issuers certificate, the subject certificate,
626the certificate request and the CRL: if these are not relevant or not
627available then they can be set to NULL. The 'flags' parameter should be set
628to zero.
629
630X509V3_set_ctx_test(ctx)
631
632This macro is used to set the 'ctx' structure to a 'test' value: this is to
633allow the syntax of an extension (or configuration file) to be tested.
634
635X509V3_set_ctx_nodb(ctx)
636
637This macro is used when no configuration database is present.
638
639void X509V3_set_conf_lhash(X509V3_CTX *ctx, LHASH *lhash);
640
641This function is used to set the configuration database when it is an LHASH
642structure: typically a configuration file.
643
644The following functions are used to access a configuration database: they
645should only be used in RAW extensions.
646
647char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section);
648
649This function returns the value of the parameter "name" in "section", or NULL
650if there has been an error.
651
652void X509V3_string_free(X509V3_CTX *ctx, char *str);
653
654This function frees up the string returned by the above function.
655
656STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section);
657
658This function returns a whole section as a STACK_OF(CONF_VALUE) .
659
660void X509V3_section_free( X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *section);
661
662This function frees up the STACK returned by the above function.
663
664Note: it is possible to use the extension code with a custom configuration
665database. To do this the "db_meth" element of the X509V3_CTX structure should
666be set to an X509V3_CTX_METHOD structure. This structure contains the following
667function pointers:
668
669char * (*get_string)(void *db, char *section, char *value);
670STACK_OF(CONF_VALUE) * (*get_section)(void *db, char *section);
671void (*free_string)(void *db, char * string);
672void (*free_section)(void *db, STACK_OF(CONF_VALUE) *section);
673
674these will be called and passed the 'db' element in the X509V3_CTX structure
675to access the database. If a given function is not implemented or not required
676it can be set to NULL.
677
6785. String helper functions.
679
680There are several "i2s" and "s2i" functions that convert structures to and
681from ASCII strings. In all the "i2s" cases the returned string should be
682freed using Free() after use. Since some of these are part of other extension
683code they may take a 'method' parameter. Unless otherwise stated it can be
684safely set to NULL.
685
686char *i2s_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method, ASN1_OCTET_STRING *oct);
687
688This returns a hex string from an ASN1_OCTET_STRING.
689
690char * i2s_ASN1_INTEGER(X509V3_EXT_METHOD *meth, ASN1_INTEGER *aint);
691char * i2s_ASN1_ENUMERATED(X509V3_EXT_METHOD *meth, ASN1_ENUMERATED *aint);
692
693These return a string decimal representations of an ASN1_INTEGER and an
694ASN1_ENUMERATED type, respectively.
695
696ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING(X509V3_EXT_METHOD *method,
697 X509V3_CTX *ctx, char *str);
698
699This converts an ASCII hex string to an ASN1_OCTET_STRING.
700
701ASN1_INTEGER * s2i_ASN1_INTEGER(X509V3_EXT_METHOD *meth, char *value);
702
703This converts a decimal ASCII string into an ASN1_INTEGER.
704
7056. Multi valued extension helper functions.
706
707The following functions can be used to manipulate STACKs of CONF_VALUE
708structures, as used by multi valued extensions.
709
710int X509V3_get_value_bool(CONF_VALUE *value, int *asn1_bool);
711
712This function expects a boolean value in 'value' and sets 'asn1_bool' to
713it. That is it sets it to 0 for FALSE or 0xff for TRUE. The following
714strings are acceptable: "TRUE", "true", "Y", "y", "YES", "yes", "FALSE"
715"false", "N", "n", "NO" or "no".
716
717int X509V3_get_value_int(CONF_VALUE *value, ASN1_INTEGER **aint);
718
719This accepts a decimal integer of arbitrary length and sets an ASN1_INTEGER.
720
721int X509V3_add_value(const char *name, const char *value,
722 STACK_OF(CONF_VALUE) **extlist);
723
724This simply adds a string name and value pair.
725
726int X509V3_add_value_uchar(const char *name, const unsigned char *value,
727 STACK_OF(CONF_VALUE) **extlist);
728
729The same as above but for an unsigned character value.
730
731int X509V3_add_value_bool(const char *name, int asn1_bool,
732 STACK_OF(CONF_VALUE) **extlist);
733
734This adds either "TRUE" or "FALSE" depending on the value of 'asn1_bool'
735
736int X509V3_add_value_bool_nf(char *name, int asn1_bool,
737 STACK_OF(CONF_VALUE) **extlist);
738
739This is the same as above except it adds nothing if asn1_bool is FALSE.
740
741int X509V3_add_value_int(const char *name, ASN1_INTEGER *aint,
742 STACK_OF(CONF_VALUE) **extlist);
743
744This function adds the value of the ASN1_INTEGER in decimal form.
745
7467. Other helper functions.
747
748<to be added>
749
750ADDING CUSTOM EXTENSIONS.
751
752Currently there are three types of supported extensions.
753
754String extensions are simple strings where the value is placed directly in the
755extensions, and the string returned is printed out.
756
757Multi value extensions are passed a STACK_OF(CONF_VALUE) name and value pairs
758or return a STACK_OF(CONF_VALUE).
759
760Raw extensions are just passed a BIO or a value and it is the extensions
761responsibility to handle all the necessary printing.
762
763There are two ways to add an extension. One is simply as an alias to an already
764existing extension. An alias is an extension that is identical in ASN1 structure
765to an existing extension but has a different OBJECT IDENTIFIER. This can be
766done by calling:
767
768int X509V3_EXT_add_alias(int nid_to, int nid_from);
769
770'nid_to' is the new extension NID and 'nid_from' is the already existing
771extension NID.
772
773Alternatively an extension can be written from scratch. This involves writing
774the ASN1 code to encode and decode the extension and functions to print out and
775generate the extension from strings. The relevant functions are then placed in
776a X509V3_EXT_METHOD structure and int X509V3_EXT_add(X509V3_EXT_METHOD *ext);
777called.
778
779The X509V3_EXT_METHOD structure is described below.
780
781struct {
782int ext_nid;
783int ext_flags;
784X509V3_EXT_NEW ext_new;
785X509V3_EXT_FREE ext_free;
786X509V3_EXT_D2I d2i;
787X509V3_EXT_I2D i2d;
788X509V3_EXT_I2S i2s;
789X509V3_EXT_S2I s2i;
790X509V3_EXT_I2V i2v;
791X509V3_EXT_V2I v2i;
792X509V3_EXT_R2I r2i;
793X509V3_EXT_I2R i2r;
794
795void *usr_data;
796};
797
798The elements have the following meanings.
799
800ext_nid is the NID of the object identifier of the extension.
801
802ext_flags is set of flags. Currently the only external flag is
803 X509V3_EXT_MULTILINE which means a multi valued extensions
804 should be printed on separate lines.
805
806usr_data is an extension specific pointer to any relevant data. This
807 allows extensions to share identical code but have different
808 uses. An example of this is the bit string extension which uses
809 usr_data to contain a list of the bit names.
810
811All the remaining elements are function pointers.
812
813ext_new is a pointer to a function that allocates memory for the
814 extension ASN1 structure: for example ASN1_OBJECT_new().
815
816ext_free is a pointer to a function that free up memory of the extension
817 ASN1 structure: for example ASN1_OBJECT_free().
818
819d2i is the standard ASN1 function that converts a DER buffer into
820 the internal ASN1 structure: for example d2i_ASN1_IA5STRING().
821
822i2d is the standard ASN1 function that converts the internal
823 structure into the DER representation: for example
824 i2d_ASN1_IA5STRING().
825
826The remaining functions are depend on the type of extension. One i2X and
827one X2i should be set and the rest set to NULL. The types set do not need
828to match up, for example the extension could be set using the multi valued
829v2i function and printed out using the raw i2r.
830
831All functions have the X509V3_EXT_METHOD passed to them in the 'method'
832parameter and an X509V3_CTX structure. Extension code can then access the
833parent structure via the 'method' parameter to for example make use of the value
834of usr_data. If the code needs to use detail relating to the request it can
835use the 'ctx' parameter.
836
837A note should be given here about the 'flags' member of the 'ctx' parameter.
838If it has the value CTX_TEST then the configuration syntax is being checked
839and no actual certificate or CRL exists. Therefore any attempt in the config
840file to access such information should silently succeed. If the syntax is OK
841then it should simply return a (possibly bogus) extension, otherwise it
842should return NULL.
843
844char *i2s(struct v3_ext_method *method, void *ext);
845
846This function takes the internal structure in the ext parameter and returns
847a Malloc'ed string representing its value.
848
849void * s2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
850
851This function takes the string representation in the ext parameter and returns
852an allocated internal structure: ext_free() will be used on this internal
853structure after use.
854
855i2v and v2i handle a STACK_OF(CONF_VALUE):
856
857typedef struct
858{
859 char *section;
860 char *name;
861 char *value;
862} CONF_VALUE;
863
864Only the name and value members are currently used.
865
866STACK_OF(CONF_VALUE) * i2v(struct v3_ext_method *method, void *ext);
867
868This function is passed the internal structure in the ext parameter and
869returns a STACK of CONF_VALUE structures. The values of name, value,
870section and the structure itself will be freed up with Free after use.
871Several helper functions are available to add values to this STACK.
872
873void * v2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx,
874 STACK_OF(CONF_VALUE) *values);
875
876This function takes a STACK_OF(CONF_VALUE) structures and should set the
877values of the external structure. This typically uses the name element to
878determine which structure element to set and the value element to determine
879what to set it to. Several helper functions are available for this
880purpose (see above).
881
882int i2r(struct v3_ext_method *method, void *ext, BIO *out, int indent);
883
884This function is passed the internal extension structure in the ext parameter
885and sends out a human readable version of the extension to out. The 'indent'
886parameter should be noted to determine the necessary amount of indentation
887needed on the output.
888
889void * r2i(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
890
891This is just passed the string representation of the extension. It is intended
892to be used for more elaborate extensions where the standard single and multi
893valued options are insufficient. They can use the 'ctx' parameter to parse the
894configuration database themselves. See the context functions section for details
895of how to do this.
896
897Note: although this type takes the same parameters as the "r2s" function there
898is a subtle difference. Whereas an "r2i" function can access a configuration
899database an "s2i" function MUST NOT. This is so the internal code can safely
900assume that an "s2i" function will work without a configuration database.
901
902==============================================================================
903 PKCS#12 Library
904==============================================================================
905
906This section describes the internal PKCS#12 support. There are very few
907differences between the old external library and the new internal code at
908present. This may well change because the external library will not be updated
909much in future.
910
911This version now includes a couple of high level PKCS#12 functions which
912generally "do the right thing" and should make it much easier to handle PKCS#12
913structures.
914
915HIGH LEVEL FUNCTIONS.
916
917For most applications you only need concern yourself with the high level
918functions. They can parse and generate simple PKCS#12 files as produced by
919Netscape and MSIE or indeed any compliant PKCS#12 file containing a single
920private key and certificate pair.
921
9221. Initialisation and cleanup.
923
924No special initialisation is needed for the internal PKCS#12 library: the
925standard SSLeay_add_all_algorithms() is sufficient. If you do not wish to
926add all algorithms (you should at least add SHA1 though) then you can manually
927initialise the PKCS#12 library with:
928
929PKCS12_PBE_add();
930
931The memory allocated by the PKCS#12 library is freed up when EVP_cleanup() is
932called or it can be directly freed with:
933
934EVP_PBE_cleanup();
935
936after this call (or EVP_cleanup() ) no more PKCS#12 library functions should
937be called.
938
9392. I/O functions.
940
941i2d_PKCS12_bio(bp, p12)
942
943This writes out a PKCS12 structure to a BIO.
944
945i2d_PKCS12_fp(fp, p12)
946
947This is the same but for a FILE pointer.
948
949d2i_PKCS12_bio(bp, p12)
950
951This reads in a PKCS12 structure from a BIO.
952
953d2i_PKCS12_fp(fp, p12)
954
955This is the same but for a FILE pointer.
956
9573. High level functions.
958
9593.1 Parsing with PKCS12_parse().
960
961int PKCS12_parse(PKCS12 *p12, char *pass, EVP_PKEY **pkey, X509 **cert,
962 STACK **ca);
963
964This function takes a PKCS12 structure and a password (ASCII, null terminated)
965and returns the private key, the corresponding certificate and any CA
966certificates. If any of these is not required it can be passed as a NULL.
967The 'ca' parameter should be either NULL, a pointer to NULL or a valid STACK
968structure. Typically to read in a PKCS#12 file you might do:
969
970p12 = d2i_PKCS12_fp(fp, NULL);
971PKCS12_parse(p12, password, &pkey, &cert, NULL); /* CAs not wanted */
972PKCS12_free(p12);
973
9743.2 PKCS#12 creation with PKCS12_create().
975
976PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
977 STACK *ca, int nid_key, int nid_cert, int iter,
978 int mac_iter, int keytype);
979
980This function will create a PKCS12 structure from a given password, name,
981private key, certificate and optional STACK of CA certificates. The remaining
9825 parameters can be set to 0 and sensible defaults will be used.
983
984The parameters nid_key and nid_cert are the key and certificate encryption
985algorithms, iter is the encryption iteration count, mac_iter is the MAC
986iteration count and keytype is the type of private key. If you really want
987to know what these last 5 parameters do then read the low level section.
988
989Typically to create a PKCS#12 file the following could be used:
990
991p12 = PKCS12_create(pass, "My Certificate", pkey, cert, NULL, 0,0,0,0,0);
992i2d_PKCS12_fp(fp, p12);
993PKCS12_free(p12);
994
9953.3 Changing a PKCS#12 structure password.
996
997int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass);
998
999This changes the password of an already existing PKCS#12 structure. oldpass
1000is the old password and newpass is the new one. An error occurs if the old
1001password is incorrect.
1002
1003LOW LEVEL FUNCTIONS.
1004
1005In some cases the high level functions do not provide the necessary
1006functionality. For example if you want to generate or parse more complex
1007PKCS#12 files. The sample pkcs12 application uses the low level functions
1008to display details about the internal structure of a PKCS#12 file.
1009
1010Introduction.
1011
1012This is a brief description of how a PKCS#12 file is represented internally:
1013some knowledge of PKCS#12 is assumed.
1014
1015A PKCS#12 object contains several levels.
1016
1017At the lowest level is a PKCS12_SAFEBAG. This can contain a certificate, a
1018CRL, a private key, encrypted or unencrypted, a set of safebags (so the
1019structure can be nested) or other secrets (not documented at present).
1020A safebag can optionally have attributes, currently these are: a unicode
1021friendlyName (a Unicode string) or a localKeyID (a string of bytes).
1022
1023At the next level is an authSafe which is a set of safebags collected into
1024a PKCS#7 ContentInfo. This can be just plain data, or encrypted itself.
1025
1026At the top level is the PKCS12 structure itself which contains a set of
1027authSafes in an embedded PKCS#7 Contentinfo of type data. In addition it
1028contains a MAC which is a kind of password protected digest to preserve
1029integrity (so any unencrypted stuff below can't be tampered with).
1030
1031The reason for these levels is so various objects can be encrypted in various
1032ways. For example you might want to encrypt a set of private keys with
1033triple-DES and then include the related certificates either unencrypted or
1034with lower encryption. Yes it's the dreaded crypto laws at work again which
1035allow strong encryption on private keys and only weak encryption on other
1036stuff.
1037
1038To build one of these things you turn all certificates and keys into safebags
1039(with optional attributes). You collect the safebags into (one or more) STACKS
1040and convert these into authsafes (encrypted or unencrypted). The authsafes
1041are collected into a STACK and added to a PKCS12 structure. Finally a MAC
1042inserted.
1043
1044Pulling one apart is basically the reverse process. The MAC is verified against
1045the given password. The authsafes are extracted and each authsafe split into
1046a set of safebags (possibly involving decryption). Finally the safebags are
1047decomposed into the original keys and certificates and the attributes used to
1048match up private key and certificate pairs.
1049
1050Anyway here are the functions that do the dirty work.
1051
10521. Construction functions.
1053
10541.1 Safebag functions.
1055
1056M_PKCS12_x5092certbag(x509)
1057
1058This macro takes an X509 structure and returns a certificate bag. The
1059X509 structure can be freed up after calling this function.
1060
1061M_PKCS12_x509crl2certbag(crl)
1062
1063As above but for a CRL.
1064
1065PKCS8_PRIV_KEY_INFO *PKEY2PKCS8(EVP_PKEY *pkey)
1066
1067Take a private key and convert it into a PKCS#8 PrivateKeyInfo structure.
1068Works for both RSA and DSA private keys. NB since the PKCS#8 PrivateKeyInfo
1069structure contains a private key data in plain text form it should be free'd
1070up as soon as it has been encrypted for security reasons (freeing up the
1071structure zeros out the sensitive data). This can be done with
1072PKCS8_PRIV_KEY_INFO_free().
1073
1074PKCS8_add_keyusage(PKCS8_PRIV_KEY_INFO *p8, int usage)
1075
1076This sets the key type when a key is imported into MSIE or Outlook 98. Two
1077values are currently supported: KEY_EX and KEY_SIG. KEY_EX is an exchange type
1078key that can also be used for signing but its size is limited in the export
1079versions of MS software to 512 bits, it is also the default. KEY_SIG is a
1080signing only key but the keysize is unlimited (well 16K is supposed to work).
1081If you are using the domestic version of MSIE then you can ignore this because
1082KEY_EX is not limited and can be used for both.
1083
1084PKCS12_SAFEBAG *PKCS12_MAKE_KEYBAG(PKCS8_PRIV_KEY_INFO *p8)
1085
1086Convert a PKCS8 private key structure into a keybag. This routine embeds the
1087p8 structure in the keybag so p8 should not be freed up or used after it is
1088called. The p8 structure will be freed up when the safebag is freed.
1089
1090PKCS12_SAFEBAG *PKCS12_MAKE_SHKEYBAG(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, PKCS8_PRIV_KEY_INFO *p8)
1091
1092Convert a PKCS#8 structure into a shrouded key bag (encrypted). p8 is not
1093embedded and can be freed up after use.
1094
1095int PKCS12_add_localkeyid(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1096int PKCS12_add_friendlyname(PKCS12_SAFEBAG *bag, unsigned char *name, int namelen)
1097
1098Add a local key id or a friendlyname to a safebag.
1099
11001.2 Authsafe functions.
1101
1102PKCS7 *PKCS12_pack_p7data(STACK *sk)
1103Take a stack of safebags and convert them into an unencrypted authsafe. The
1104stack of safebags can be freed up after calling this function.
1105
1106PKCS7 *PKCS12_pack_p7encdata(int pbe_nid, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, STACK *bags);
1107
1108As above but encrypted.
1109
11101.3 PKCS12 functions.
1111
1112PKCS12 *PKCS12_init(int mode)
1113
1114Initialise a PKCS12 structure (currently mode should be NID_pkcs7_data).
1115
1116M_PKCS12_pack_authsafes(p12, safes)
1117
1118This macro takes a STACK of authsafes and adds them to a PKCS#12 structure.
1119
1120int PKCS12_set_mac(PKCS12 *p12, unsigned char *pass, int passlen, unsigned char *salt, int saltlen, int iter, EVP_MD *md_type);
1121
1122Add a MAC to a PKCS12 structure. If EVP_MD is NULL use SHA-1, the spec suggests
1123that SHA-1 should be used.
1124
11252. Extraction Functions.
1126
11272.1 Safebags.
1128
1129M_PKCS12_bag_type(bag)
1130
1131Return the type of "bag". Returns one of the following
1132
1133NID_keyBag
1134NID_pkcs8ShroudedKeyBag 7
1135NID_certBag 8
1136NID_crlBag 9
1137NID_secretBag 10
1138NID_safeContentsBag 11
1139
1140M_PKCS12_cert_bag_type(bag)
1141
1142Returns type of certificate bag, following are understood.
1143
1144NID_x509Certificate 14
1145NID_sdsiCertificate 15
1146
1147M_PKCS12_crl_bag_type(bag)
1148
1149Returns crl bag type, currently only NID_crlBag is recognised.
1150
1151M_PKCS12_certbag2x509(bag)
1152
1153This macro extracts an X509 certificate from a certificate bag.
1154
1155M_PKCS12_certbag2x509crl(bag)
1156
1157As above but for a CRL.
1158
1159EVP_PKEY * PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
1160
1161Extract a private key from a PKCS8 private key info structure.
1162
1163M_PKCS12_decrypt_skey(bag, pass, passlen)
1164
1165Decrypt a shrouded key bag and return a PKCS8 private key info structure.
1166Works with both RSA and DSA keys
1167
1168char *PKCS12_get_friendlyname(bag)
1169
1170Returns the friendlyName of a bag if present or NULL if none. The returned
1171string is a null terminated ASCII string allocated with Malloc(). It should
1172thus be freed up with Free() after use.
1173
11742.2 AuthSafe functions.
1175
1176M_PKCS12_unpack_p7data(p7)
1177
1178Extract a STACK of safe bags from a PKCS#7 data ContentInfo.
1179
1180#define M_PKCS12_unpack_p7encdata(p7, pass, passlen)
1181
1182As above but for an encrypted content info.
1183
11842.3 PKCS12 functions.
1185
1186M_PKCS12_unpack_authsafes(p12)
1187
1188Extract a STACK of authsafes from a PKCS12 structure.
1189
1190M_PKCS12_mac_present(p12)
1191
1192Check to see if a MAC is present.
1193
1194int PKCS12_verify_mac(PKCS12 *p12, unsigned char *pass, int passlen)
1195
1196Verify a MAC on a PKCS12 structure. Returns an error if MAC not present.
1197
1198
1199Notes.
1200
12011. All the function return 0 or NULL on error.
12022. Encryption based functions take a common set of parameters. These are
1203described below.
1204
1205pass, passlen
1206ASCII password and length. The password on the MAC is called the "integrity
1207password" the encryption password is called the "privacy password" in the
1208PKCS#12 documentation. The passwords do not have to be the same. If -1 is
1209passed for the length it is worked out by the function itself (currently
1210this is sometimes done whatever is passed as the length but that may change).
1211
1212salt, saltlen
1213A 'salt' if salt is NULL a random salt is used. If saltlen is also zero a
1214default length is used.
1215
1216iter
1217Iteration count. This is a measure of how many times an internal function is
1218called to encrypt the data. The larger this value is the longer it takes, it
1219makes dictionary attacks on passwords harder. NOTE: Some implementations do
1220not support an iteration count on the MAC. If the password for the MAC and
1221encryption is the same then there is no point in having a high iteration
1222count for encryption if the MAC has no count. The MAC could be attacked
1223and the password used for the main decryption.
1224
1225pbe_nid
1226This is the NID of the password based encryption method used. The following are
1227supported.
1228NID_pbe_WithSHA1And128BitRC4
1229NID_pbe_WithSHA1And40BitRC4
1230NID_pbe_WithSHA1And3_Key_TripleDES_CBC
1231NID_pbe_WithSHA1And2_Key_TripleDES_CBC
1232NID_pbe_WithSHA1And128BitRC2_CBC
1233NID_pbe_WithSHA1And40BitRC2_CBC
1234
1235Which you use depends on the implementation you are exporting to. "Export
1236grade" (i.e. cryptographically challenged) products cannot support all
1237algorithms. Typically you may be able to use any encryption on shrouded key
1238bags but they must then be placed in an unencrypted authsafe. Other authsafes
1239may only support 40bit encryption. Of course if you are using SSLeay
1240throughout you can strongly encrypt everything and have high iteration counts
1241on everything.
1242
12433. For decryption routines only the password and length are needed.
1244
12454. Unlike the external version the nid's of objects are the values of the
1246constants: that is NID_certBag is the real nid, therefore there is no
1247PKCS12_obj_offset() function. Note the object constants are not the same as
1248those of the external version. If you use these constants then you will need
1249to recompile your code.
1250
12515. With the exception of PKCS12_MAKE_KEYBAG(), after calling any function or
1252macro of the form PKCS12_MAKE_SOMETHING(other) the "other" structure can be
1253reused or freed up safely.
1254
diff --git a/src/lib/libssl/doc/standards.txt b/src/lib/libssl/doc/standards.txt
deleted file mode 100644
index 6b3c5c5038..0000000000
--- a/src/lib/libssl/doc/standards.txt
+++ /dev/null
@@ -1,285 +0,0 @@
1Standards related to OpenSSL
2============================
3
4[Please, this is currently a draft. I made a first try at finding
5 documents that describe parts of what OpenSSL implements. There are
6 big gaps, and I've most certainly done something wrong. Please
7 correct whatever is... Also, this note should be removed when this
8 file is reaching a somewhat correct state. -- Richard Levitte]
9
10
11All pointers in here will be either URL's or blobs of text borrowed
12from miscellaneous indexes, like rfc-index.txt (index of RFCs),
131id-index.txt (index of Internet drafts) and the like.
14
15To find the latest possible RFCs, it's recommended to either browse
16ftp://ftp.isi.edu/in-notes/ or go to http://www.rfc-editor.org/ and
17use the search mechanism found there.
18To find the latest possible Internet drafts, it's recommended to
19browse ftp://ftp.isi.edu/internet-drafts/.
20To find the latest possible PKCS, it's recommended to browse
21http://www.rsasecurity.com/rsalabs/pkcs/.
22
23
24Implemented:
25------------
26
27These are documents that describe things that are implemented (in
28whole or at least great parts) in OpenSSL.
29
301319 The MD2 Message-Digest Algorithm. B. Kaliski. April 1992.
31 (Format: TXT=25661 bytes) (Status: INFORMATIONAL)
32
331320 The MD4 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
34 TXT=32407 bytes) (Status: INFORMATIONAL)
35
361321 The MD5 Message-Digest Algorithm. R. Rivest. April 1992. (Format:
37 TXT=35222 bytes) (Status: INFORMATIONAL)
38
392246 The TLS Protocol Version 1.0. T. Dierks, C. Allen. January 1999.
40 (Format: TXT=170401 bytes) (Status: PROPOSED STANDARD)
41
422268 A Description of the RC2(r) Encryption Algorithm. R. Rivest.
43 January 1998. (Format: TXT=19048 bytes) (Status: INFORMATIONAL)
44
452315 PKCS 7: Cryptographic Message Syntax Version 1.5. B. Kaliski.
46 March 1998. (Format: TXT=69679 bytes) (Status: INFORMATIONAL)
47
48PKCS#8: Private-Key Information Syntax Standard
49
50PKCS#12: Personal Information Exchange Syntax Standard, version 1.0.
51
522560 X.509 Internet Public Key Infrastructure Online Certificate
53 Status Protocol - OCSP. M. Myers, R. Ankney, A. Malpani, S. Galperin,
54 C. Adams. June 1999. (Format: TXT=43243 bytes) (Status: PROPOSED
55 STANDARD)
56
572712 Addition of Kerberos Cipher Suites to Transport Layer Security
58 (TLS). A. Medvinsky, M. Hur. October 1999. (Format: TXT=13763 bytes)
59 (Status: PROPOSED STANDARD)
60
612898 PKCS #5: Password-Based Cryptography Specification Version 2.0.
62 B. Kaliski. September 2000. (Format: TXT=68692 bytes) (Status:
63 INFORMATIONAL)
64
652986 PKCS #10: Certification Request Syntax Specification Version 1.7.
66 M. Nystrom, B. Kaliski. November 2000. (Format: TXT=27794 bytes)
67 (Obsoletes RFC2314) (Status: INFORMATIONAL)
68
693174 US Secure Hash Algorithm 1 (SHA1). D. Eastlake 3rd, P. Jones.
70 September 2001. (Format: TXT=35525 bytes) (Status: INFORMATIONAL)
71
723161 Internet X.509 Public Key Infrastructure, Time-Stamp Protocol (TSP)
73 C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001
74 (Status: PROPOSED STANDARD)
75
763268 Advanced Encryption Standard (AES) Ciphersuites for Transport
77 Layer Security (TLS). P. Chown. June 2002. (Format: TXT=13530 bytes)
78 (Status: PROPOSED STANDARD)
79
803279 Algorithms and Identifiers for the Internet X.509 Public Key
81 Infrastructure Certificate and Certificate Revocation List (CRL)
82 Profile. L. Bassham, W. Polk, R. Housley. April 2002. (Format:
83 TXT=53833 bytes) (Status: PROPOSED STANDARD)
84
853280 Internet X.509 Public Key Infrastructure Certificate and
86 Certificate Revocation List (CRL) Profile. R. Housley, W. Polk, W.
87 Ford, D. Solo. April 2002. (Format: TXT=295556 bytes) (Obsoletes
88 RFC2459) (Status: PROPOSED STANDARD)
89
903447 Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography
91 Specifications Version 2.1. J. Jonsson, B. Kaliski. February 2003.
92 (Format: TXT=143173 bytes) (Obsoletes RFC2437) (Status:
93 INFORMATIONAL)
94
953713 A Description of the Camellia Encryption Algorithm. M. Matsui,
96 J. Nakajima, S. Moriai. April 2004. (Format: TXT=25031 bytes)
97 (Status: INFORMATIONAL)
98
993820 Internet X.509 Public Key Infrastructure (PKI) Proxy Certificate
100 Profile. S. Tuecke, V. Welch, D. Engert, L. Pearlman, M. Thompson.
101 June 2004. (Format: TXT=86374 bytes) (Status: PROPOSED STANDARD)
102
1034132 Addition of Camellia Cipher Suites to Transport Layer Security
104 (TLS). S. Moriai, A. Kato, M. Kanda. July 2005. (Format: TXT=13590
105 bytes) (Status: PROPOSED STANDARD)
106
1074162 Addition of SEED Cipher Suites to Transport Layer Security (TLS).
108 H.J. Lee, J.H. Yoon, J.I. Lee. August 2005. (Format: TXT=10578 bytes)
109 (Status: PROPOSED STANDARD)
110
1114269 The SEED Encryption Algorithm. H.J. Lee, S.J. Lee, J.H. Yoon,
112 D.H. Cheon, J.I. Lee. December 2005. (Format: TXT=34390 bytes)
113 (Obsoletes RFC4009) (Status: INFORMATIONAL)
114
115
116Related:
117--------
118
119These are documents that are close to OpenSSL, for example the
120STARTTLS documents.
121
1221421 Privacy Enhancement for Internet Electronic Mail: Part I: Message
123 Encryption and Authentication Procedures. J. Linn. February 1993.
124 (Format: TXT=103894 bytes) (Obsoletes RFC1113) (Status: PROPOSED
125 STANDARD)
126
1271422 Privacy Enhancement for Internet Electronic Mail: Part II:
128 Certificate-Based Key Management. S. Kent. February 1993. (Format:
129 TXT=86085 bytes) (Obsoletes RFC1114) (Status: PROPOSED STANDARD)
130
1311423 Privacy Enhancement for Internet Electronic Mail: Part III:
132 Algorithms, Modes, and Identifiers. D. Balenson. February 1993.
133 (Format: TXT=33277 bytes) (Obsoletes RFC1115) (Status: PROPOSED
134 STANDARD)
135
1361424 Privacy Enhancement for Internet Electronic Mail: Part IV: Key
137 Certification and Related Services. B. Kaliski. February 1993.
138 (Format: TXT=17537 bytes) (Status: PROPOSED STANDARD)
139
1402025 The Simple Public-Key GSS-API Mechanism (SPKM). C. Adams. October
141 1996. (Format: TXT=101692 bytes) (Status: PROPOSED STANDARD)
142
1432510 Internet X.509 Public Key Infrastructure Certificate Management
144 Protocols. C. Adams, S. Farrell. March 1999. (Format: TXT=158178
145 bytes) (Status: PROPOSED STANDARD)
146
1472511 Internet X.509 Certificate Request Message Format. M. Myers, C.
148 Adams, D. Solo, D. Kemp. March 1999. (Format: TXT=48278 bytes)
149 (Status: PROPOSED STANDARD)
150
1512527 Internet X.509 Public Key Infrastructure Certificate Policy and
152 Certification Practices Framework. S. Chokhani, W. Ford. March 1999.
153 (Format: TXT=91860 bytes) (Status: INFORMATIONAL)
154
1552538 Storing Certificates in the Domain Name System (DNS). D. Eastlake
156 3rd, O. Gudmundsson. March 1999. (Format: TXT=19857 bytes) (Status:
157 PROPOSED STANDARD)
158
1592539 Storage of Diffie-Hellman Keys in the Domain Name System (DNS).
160 D. Eastlake 3rd. March 1999. (Format: TXT=21049 bytes) (Status:
161 PROPOSED STANDARD)
162
1632559 Internet X.509 Public Key Infrastructure Operational Protocols -
164 LDAPv2. S. Boeyen, T. Howes, P. Richard. April 1999. (Format:
165 TXT=22889 bytes) (Updates RFC1778) (Status: PROPOSED STANDARD)
166
1672585 Internet X.509 Public Key Infrastructure Operational Protocols:
168 FTP and HTTP. R. Housley, P. Hoffman. May 1999. (Format: TXT=14813
169 bytes) (Status: PROPOSED STANDARD)
170
1712587 Internet X.509 Public Key Infrastructure LDAPv2 Schema. S.
172 Boeyen, T. Howes, P. Richard. June 1999. (Format: TXT=15102 bytes)
173 (Status: PROPOSED STANDARD)
174
1752595 Using TLS with IMAP, POP3 and ACAP. C. Newman. June 1999.
176 (Format: TXT=32440 bytes) (Status: PROPOSED STANDARD)
177
1782631 Diffie-Hellman Key Agreement Method. E. Rescorla. June 1999.
179 (Format: TXT=25932 bytes) (Status: PROPOSED STANDARD)
180
1812632 S/MIME Version 3 Certificate Handling. B. Ramsdell, Ed.. June
182 1999. (Format: TXT=27925 bytes) (Status: PROPOSED STANDARD)
183
1842716 PPP EAP TLS Authentication Protocol. B. Aboba, D. Simon. October
185 1999. (Format: TXT=50108 bytes) (Status: EXPERIMENTAL)
186
1872773 Encryption using KEA and SKIPJACK. R. Housley, P. Yee, W. Nace.
188 February 2000. (Format: TXT=20008 bytes) (Updates RFC0959) (Status:
189 EXPERIMENTAL)
190
1912797 Certificate Management Messages over CMS. M. Myers, X. Liu, J.
192 Schaad, J. Weinstein. April 2000. (Format: TXT=103357 bytes) (Status:
193 PROPOSED STANDARD)
194
1952817 Upgrading to TLS Within HTTP/1.1. R. Khare, S. Lawrence. May
196 2000. (Format: TXT=27598 bytes) (Updates RFC2616) (Status: PROPOSED
197 STANDARD)
198
1992818 HTTP Over TLS. E. Rescorla. May 2000. (Format: TXT=15170 bytes)
200 (Status: INFORMATIONAL)
201
2022876 Use of the KEA and SKIPJACK Algorithms in CMS. J. Pawling. July
203 2000. (Format: TXT=29265 bytes) (Status: INFORMATIONAL)
204
2052984 Use of the CAST-128 Encryption Algorithm in CMS. C. Adams.
206 October 2000. (Format: TXT=11591 bytes) (Status: PROPOSED STANDARD)
207
2082985 PKCS #9: Selected Object Classes and Attribute Types Version 2.0.
209 M. Nystrom, B. Kaliski. November 2000. (Format: TXT=70703 bytes)
210 (Status: INFORMATIONAL)
211
2123029 Internet X.509 Public Key Infrastructure Data Validation and
213 Certification Server Protocols. C. Adams, P. Sylvester, M. Zolotarev,
214 R. Zuccherato. February 2001. (Format: TXT=107347 bytes) (Status:
215 EXPERIMENTAL)
216
2173039 Internet X.509 Public Key Infrastructure Qualified Certificates
218 Profile. S. Santesson, W. Polk, P. Barzin, M. Nystrom. January 2001.
219 (Format: TXT=67619 bytes) (Status: PROPOSED STANDARD)
220
2213058 Use of the IDEA Encryption Algorithm in CMS. S. Teiwes, P.
222 Hartmann, D. Kuenzi. February 2001. (Format: TXT=17257 bytes)
223 (Status: INFORMATIONAL)
224
2253161 Internet X.509 Public Key Infrastructure Time-Stamp Protocol
226 (TSP). C. Adams, P. Cain, D. Pinkas, R. Zuccherato. August 2001.
227 (Format: TXT=54585 bytes) (Status: PROPOSED STANDARD)
228
2293185 Reuse of CMS Content Encryption Keys. S. Farrell, S. Turner.
230 October 2001. (Format: TXT=20404 bytes) (Status: PROPOSED STANDARD)
231
2323207 SMTP Service Extension for Secure SMTP over Transport Layer
233 Security. P. Hoffman. February 2002. (Format: TXT=18679 bytes)
234 (Obsoletes RFC2487) (Status: PROPOSED STANDARD)
235
2363217 Triple-DES and RC2 Key Wrapping. R. Housley. December 2001.
237 (Format: TXT=19855 bytes) (Status: INFORMATIONAL)
238
2393274 Compressed Data Content Type for Cryptographic Message Syntax
240 (CMS). P. Gutmann. June 2002. (Format: TXT=11276 bytes) (Status:
241 PROPOSED STANDARD)
242
2433278 Use of Elliptic Curve Cryptography (ECC) Algorithms in
244 Cryptographic Message Syntax (CMS). S. Blake-Wilson, D. Brown, P.
245 Lambert. April 2002. (Format: TXT=33779 bytes) (Status:
246 INFORMATIONAL)
247
2483281 An Internet Attribute Certificate Profile for Authorization. S.
249 Farrell, R. Housley. April 2002. (Format: TXT=90580 bytes) (Status:
250 PROPOSED STANDARD)
251
2523369 Cryptographic Message Syntax (CMS). R. Housley. August 2002.
253 (Format: TXT=113975 bytes) (Obsoletes RFC2630, RFC3211) (Status:
254 PROPOSED STANDARD)
255
2563370 Cryptographic Message Syntax (CMS) Algorithms. R. Housley. August
257 2002. (Format: TXT=51001 bytes) (Obsoletes RFC2630, RFC3211) (Status:
258 PROPOSED STANDARD)
259
2603377 Lightweight Directory Access Protocol (v3): Technical
261 Specification. J. Hodges, R. Morgan. September 2002. (Format:
262 TXT=9981 bytes) (Updates RFC2251, RFC2252, RFC2253, RFC2254, RFC2255,
263 RFC2256, RFC2829, RFC2830) (Status: PROPOSED STANDARD)
264
2653394 Advanced Encryption Standard (AES) Key Wrap Algorithm. J. Schaad,
266 R. Housley. September 2002. (Format: TXT=73072 bytes) (Status:
267 INFORMATIONAL)
268
2693436 Transport Layer Security over Stream Control Transmission
270 Protocol. A. Jungmaier, E. Rescorla, M. Tuexen. December 2002.
271 (Format: TXT=16333 bytes) (Status: PROPOSED STANDARD)
272
2733657 Use of the Camellia Encryption Algorithm in Cryptographic
274 Message Syntax (CMS). S. Moriai, A. Kato. January 2004.
275 (Format: TXT=26282 bytes) (Status: PROPOSED STANDARD)
276
277"Securing FTP with TLS", 01/27/2000, <draft-murray-auth-ftp-ssl-05.txt>
278
279
280To be implemented:
281------------------
282
283These are documents that describe things that are planned to be
284implemented in the hopefully short future.
285
diff --git a/src/lib/libssl/dtls1.h b/src/lib/libssl/dtls1.h
deleted file mode 100644
index 7428d8ec3c..0000000000
--- a/src/lib/libssl/dtls1.h
+++ /dev/null
@@ -1,103 +0,0 @@
1/* $OpenBSD: dtls1.h,v 1.27 2021/05/16 13:56:30 jsing Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_DTLS1_H
61#define HEADER_DTLS1_H
62
63#include <sys/time.h>
64
65#include <stdio.h>
66#include <stdlib.h>
67#include <string.h>
68
69#include <openssl/opensslconf.h>
70#include <openssl/buffer.h>
71
72#ifdef __cplusplus
73extern "C" {
74#endif
75
76#define DTLS1_VERSION 0xFEFF
77#define DTLS1_2_VERSION 0xFEFD
78#define DTLS1_VERSION_MAJOR 0xFE
79
80/* lengths of messages */
81#define DTLS1_COOKIE_LENGTH 256
82
83#define DTLS1_RT_HEADER_LENGTH 13
84
85#define DTLS1_HM_HEADER_LENGTH 12
86
87#define DTLS1_HM_BAD_FRAGMENT -2
88#define DTLS1_HM_FRAGMENT_RETRY -3
89
90#define DTLS1_CCS_HEADER_LENGTH 1
91
92#define DTLS1_AL_HEADER_LENGTH 2
93
94/* Timeout multipliers (timeout slice is defined in apps/timeouts.h */
95#define DTLS1_TMO_READ_COUNT 2
96#define DTLS1_TMO_WRITE_COUNT 2
97
98#define DTLS1_TMO_ALERT_COUNT 12
99
100#ifdef __cplusplus
101}
102#endif
103#endif
diff --git a/src/lib/libssl/dtls_local.h b/src/lib/libssl/dtls_local.h
deleted file mode 100644
index c7c413fef4..0000000000
--- a/src/lib/libssl/dtls_local.h
+++ /dev/null
@@ -1,232 +0,0 @@
1/* $OpenBSD: dtls_local.h,v 1.2 2022/11/26 17:23:18 tb Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_DTLS_LOCL_H
61#define HEADER_DTLS_LOCL_H
62
63#include <sys/time.h>
64
65#include <openssl/dtls1.h>
66
67#include "ssl_local.h"
68#include "tls_content.h"
69
70__BEGIN_HIDDEN_DECLS
71
72typedef struct dtls1_bitmap_st {
73 unsigned long map; /* track 32 packets on 32-bit systems
74 and 64 - on 64-bit systems */
75 unsigned char max_seq_num[8]; /* max record number seen so far,
76 64-bit value in big-endian
77 encoding */
78} DTLS1_BITMAP;
79
80struct dtls1_retransmit_state {
81 SSL_SESSION *session;
82 unsigned short epoch;
83};
84
85struct hm_header_st {
86 unsigned char type;
87 unsigned long msg_len;
88 unsigned short seq;
89 unsigned long frag_off;
90 unsigned long frag_len;
91 unsigned int is_ccs;
92 struct dtls1_retransmit_state saved_retransmit_state;
93};
94
95struct dtls1_timeout_st {
96 /* Number of read timeouts so far */
97 unsigned int read_timeouts;
98
99 /* Number of write timeouts so far */
100 unsigned int write_timeouts;
101
102 /* Number of alerts received so far */
103 unsigned int num_alerts;
104};
105
106struct _pqueue;
107
108typedef struct record_pqueue_st {
109 unsigned short epoch;
110 struct _pqueue *q;
111} record_pqueue;
112
113typedef struct rcontent_pqueue_st {
114 unsigned short epoch;
115 struct _pqueue *q;
116} rcontent_pqueue;
117
118typedef struct hm_fragment_st {
119 struct hm_header_st msg_header;
120 unsigned char *fragment;
121 unsigned char *reassembly;
122} hm_fragment;
123
124typedef struct dtls1_record_data_internal_st {
125 unsigned char *packet;
126 unsigned int packet_length;
127 SSL3_BUFFER_INTERNAL rbuf;
128 SSL3_RECORD_INTERNAL rrec;
129} DTLS1_RECORD_DATA_INTERNAL;
130
131typedef struct dtls1_rcontent_data_internal_st {
132 struct tls_content *rcontent;
133} DTLS1_RCONTENT_DATA_INTERNAL;
134
135struct dtls1_state_st {
136 /* Buffered (sent) handshake records */
137 struct _pqueue *sent_messages;
138
139 /* Indicates when the last handshake msg or heartbeat sent will timeout */
140 struct timeval next_timeout;
141
142 /* Timeout duration */
143 unsigned short timeout_duration;
144
145 unsigned int send_cookie;
146 unsigned char cookie[DTLS1_COOKIE_LENGTH];
147 unsigned char rcvd_cookie[DTLS1_COOKIE_LENGTH];
148 unsigned int cookie_len;
149
150 /* records being received in the current epoch */
151 DTLS1_BITMAP bitmap;
152
153 /* renegotiation starts a new set of sequence numbers */
154 DTLS1_BITMAP next_bitmap;
155
156 /* handshake message numbers */
157 unsigned short handshake_write_seq;
158 unsigned short next_handshake_write_seq;
159
160 unsigned short handshake_read_seq;
161
162 /* Received handshake records (unprocessed) */
163 record_pqueue unprocessed_rcds;
164
165 /* Buffered handshake messages */
166 struct _pqueue *buffered_messages;
167
168 /* Buffered application records.
169 * Only for records between CCS and Finished
170 * to prevent either protocol violation or
171 * unnecessary message loss.
172 */
173 rcontent_pqueue buffered_app_data;
174
175 /* Is set when listening for new connections with dtls1_listen() */
176 unsigned int listen;
177
178 unsigned int mtu; /* max DTLS packet size */
179
180 struct hm_header_st w_msg_hdr;
181 struct hm_header_st r_msg_hdr;
182
183 struct dtls1_timeout_st timeout;
184
185 unsigned int retransmitting;
186 unsigned int change_cipher_spec_ok;
187};
188
189int dtls1_do_write(SSL *s, int type);
190int dtls1_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
191void dtls1_set_message_header(SSL *s, unsigned char mt, unsigned long len,
192 unsigned long frag_off, unsigned long frag_len);
193void dtls1_set_message_header_int(SSL *s, unsigned char mt,
194 unsigned long len, unsigned short seq_num, unsigned long frag_off,
195 unsigned long frag_len);
196
197int do_dtls1_write(SSL *s, int type, const unsigned char *buf,
198 unsigned int len);
199
200int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf, int len);
201int dtls1_write_bytes(SSL *s, int type, const void *buf, int len);
202
203int dtls1_read_failed(SSL *s, int code);
204int dtls1_buffer_message(SSL *s, int ccs);
205int dtls1_retransmit_message(SSL *s, unsigned short seq,
206 unsigned long frag_off, int *found);
207int dtls1_get_queue_priority(unsigned short seq, int is_ccs);
208int dtls1_retransmit_buffered_messages(SSL *s);
209void dtls1_clear_record_buffer(SSL *s);
210int dtls1_get_message_header(CBS *header, struct hm_header_st *msg_hdr);
211void dtls1_reset_read_seq_numbers(SSL *s);
212struct timeval* dtls1_get_timeout(SSL *s, struct timeval* timeleft);
213int dtls1_check_timeout_num(SSL *s);
214int dtls1_handle_timeout(SSL *s);
215const SSL_CIPHER *dtls1_get_cipher(unsigned int u);
216void dtls1_start_timer(SSL *s);
217void dtls1_stop_timer(SSL *s);
218int dtls1_is_timer_expired(SSL *s);
219void dtls1_double_timeout(SSL *s);
220unsigned int dtls1_min_mtu(void);
221
222int dtls1_new(SSL *s);
223void dtls1_free(SSL *s);
224void dtls1_clear(SSL *s);
225long dtls1_ctrl(SSL *s, int cmd, long larg, void *parg);
226
227int dtls1_get_message(SSL *s, int st1, int stn, int mt, long max);
228int dtls1_get_record(SSL *s);
229
230__END_HIDDEN_DECLS
231
232#endif /* !HEADER_DTLS_LOCL_H */
diff --git a/src/lib/libssl/generate_pkgconfig.sh b/src/lib/libssl/generate_pkgconfig.sh
deleted file mode 100644
index e1e663f399..0000000000
--- a/src/lib/libssl/generate_pkgconfig.sh
+++ /dev/null
@@ -1,89 +0,0 @@
1#!/bin/sh
2#
3# $OpenBSD: generate_pkgconfig.sh,v 1.11 2022/02/04 16:42:15 tb Exp $
4#
5# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse <jasper@openbsd.org>
6#
7# Permission to use, copy, modify, and distribute this software for any
8# purpose with or without fee is hereby granted, provided that the above
9# copyright notice and this permission notice appear in all copies.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18#
19# Generate pkg-config files for OpenSSL.
20
21usage() {
22 echo "usage: ${0##*/} -c current_directory -o obj_directory"
23 exit 1
24}
25
26curdir=
27objdir=
28while getopts "c:o:" flag; do
29 case "$flag" in
30 c)
31 curdir=$OPTARG
32 ;;
33 o)
34 objdir=$OPTARG
35 ;;
36 *)
37 usage
38 ;;
39 esac
40done
41
42[ -n "${curdir}" ] || usage
43if [ ! -d "${curdir}" ]; then
44 echo "${0##*/}: ${curdir}: not found"
45 exit 1
46fi
47[ -n "${objdir}" ] || usage
48if [ ! -w "${objdir}" ]; then
49 echo "${0##*/}: ${objdir}: not found or not writable"
50 exit 1
51fi
52
53version_re="s/^#define[[:blank:]]+SHLIB_VERSION_NUMBER[[:blank:]]+\"(.*)\".*/\1/p"
54version_file=${curdir}/../libcrypto/opensslv.h
55#lib_version=$(sed -nE ${version_re} ${version_file})
56lib_version=2.0.0
57
58# Put -I${includedir} into Cflags so configure script tests like
59# test -n "`pkg-config --cflags openssl`"
60# don't assume that OpenSSL isn't available.
61
62pc_file="${objdir}/libssl.pc"
63cat > ${pc_file} << __EOF__
64prefix=/usr
65exec_prefix=\${prefix}
66libdir=\${exec_prefix}/lib
67includedir=\${prefix}/include
68
69Name: OpenSSL-libssl
70Description: Secure Sockets Layer and cryptography libraries
71Version: ${lib_version}
72Requires.private: libcrypto
73Libs: -L\${libdir} -lssl
74Cflags: -I\${includedir}
75__EOF__
76
77
78pc_file="${objdir}/openssl.pc"
79cat > ${pc_file} << __EOF__
80prefix=/usr
81exec_prefix=\${prefix}
82libdir=\${exec_prefix}/lib
83includedir=\${prefix}/include
84
85Name: OpenSSL
86Description: Secure Sockets Layer and cryptography libraries and tools
87Version: ${lib_version}
88Requires: libssl libcrypto
89__EOF__
diff --git a/src/lib/libssl/hidden/openssl/srtp.h b/src/lib/libssl/hidden/openssl/srtp.h
deleted file mode 100644
index 2440fc93d9..0000000000
--- a/src/lib/libssl/hidden/openssl/srtp.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/* $OpenBSD: srtp.h,v 1.1 2023/07/08 16:40:14 beck Exp $ */
2/*
3 * Copyright (c) 2023 Bob Beck <beck@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _LIBSSL_SRTP_H
19#define _LIBSSL_SRTP_H
20
21#ifndef _MSC_VER
22#include_next <openssl/srtp.h>
23#else
24#include "../include/openssl/srtp.h"
25#endif
26#include "ssl_namespace.h"
27
28LSSL_USED(SSL_CTX_set_tlsext_use_srtp);
29LSSL_USED(SSL_set_tlsext_use_srtp);
30LSSL_USED(SSL_get_srtp_profiles);
31LSSL_USED(SSL_get_selected_srtp_profile);
32
33#endif /* _LIBSSL_SRTP_H */
diff --git a/src/lib/libssl/hidden/openssl/ssl.h b/src/lib/libssl/hidden/openssl/ssl.h
deleted file mode 100644
index b854dd7b73..0000000000
--- a/src/lib/libssl/hidden/openssl/ssl.h
+++ /dev/null
@@ -1,382 +0,0 @@
1/* $OpenBSD: ssl.h,v 1.9 2024/08/31 10:51:48 tb Exp $ */
2/*
3 * Copyright (c) 2023 Bob Beck <beck@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _LIBSSL_SSL_H
19#define _LIBSSL_SSL_H
20
21#ifndef _MSC_VER
22#include_next <openssl/ssl.h>
23#else
24#include "../include/openssl/ssl.h"
25#endif
26#include "ssl_namespace.h"
27
28LSSL_USED(SSL_CTX_set_msg_callback);
29LSSL_USED(SSL_set_msg_callback);
30LSSL_USED(SSL_CTX_set_keylog_callback);
31LSSL_USED(SSL_CTX_get_keylog_callback);
32LSSL_USED(SSL_set_num_tickets);
33LSSL_USED(SSL_get_num_tickets);
34LSSL_USED(SSL_CTX_set_num_tickets);
35LSSL_USED(SSL_CTX_get_num_tickets);
36LSSL_USED(SSL_get0_verified_chain);
37LSSL_USED(SSL_CTX_sessions);
38LSSL_USED(SSL_CTX_sess_set_new_cb);
39LSSL_USED(SSL_CTX_sess_get_new_cb);
40LSSL_USED(SSL_CTX_sess_set_remove_cb);
41LSSL_USED(SSL_CTX_sess_get_remove_cb);
42LSSL_USED(SSL_CTX_sess_set_get_cb);
43LSSL_USED(SSL_CTX_set_info_callback);
44LSSL_USED(SSL_CTX_get_info_callback);
45LSSL_USED(SSL_CTX_set_client_cert_cb);
46LSSL_USED(SSL_CTX_get_client_cert_cb);
47LSSL_USED(SSL_CTX_set_cookie_generate_cb);
48LSSL_USED(SSL_CTX_set_cookie_verify_cb);
49LSSL_USED(SSL_CTX_set_next_protos_advertised_cb);
50LSSL_USED(SSL_CTX_set_next_proto_select_cb);
51LSSL_USED(SSL_select_next_proto);
52LSSL_USED(SSL_get0_next_proto_negotiated);
53LSSL_USED(SSL_CTX_set_alpn_protos);
54LSSL_USED(SSL_set_alpn_protos);
55LSSL_USED(SSL_CTX_set_alpn_select_cb);
56LSSL_USED(SSL_get0_alpn_selected);
57LSSL_USED(SSL_set_psk_use_session_callback);
58LSSL_USED(SSL_get_finished);
59LSSL_USED(SSL_get_peer_finished);
60LSSL_USED(SSL_verify_client_post_handshake);
61LSSL_USED(SSL_CTX_set_post_handshake_auth);
62LSSL_USED(SSL_set_post_handshake_auth);
63LSSL_USED(PEM_read_bio_SSL_SESSION);
64LSSL_USED(PEM_read_SSL_SESSION);
65LSSL_USED(PEM_write_bio_SSL_SESSION);
66LSSL_USED(PEM_write_SSL_SESSION);
67LSSL_USED(SSL_CTX_set0_chain);
68LSSL_USED(SSL_CTX_set1_chain);
69LSSL_USED(SSL_CTX_add0_chain_cert);
70LSSL_USED(SSL_CTX_add1_chain_cert);
71LSSL_USED(SSL_CTX_get0_chain_certs);
72LSSL_USED(SSL_CTX_clear_chain_certs);
73LSSL_USED(SSL_set0_chain);
74LSSL_USED(SSL_set1_chain);
75LSSL_USED(SSL_add0_chain_cert);
76LSSL_USED(SSL_add1_chain_cert);
77LSSL_USED(SSL_get0_chain_certs);
78LSSL_USED(SSL_clear_chain_certs);
79LSSL_USED(SSL_CTX_set1_groups);
80LSSL_USED(SSL_CTX_set1_groups_list);
81LSSL_USED(SSL_set1_groups);
82LSSL_USED(SSL_set1_groups_list);
83LSSL_USED(SSL_CTX_get_min_proto_version);
84LSSL_USED(SSL_CTX_get_max_proto_version);
85LSSL_USED(SSL_CTX_set_min_proto_version);
86LSSL_USED(SSL_CTX_set_max_proto_version);
87LSSL_USED(SSL_get_min_proto_version);
88LSSL_USED(SSL_get_max_proto_version);
89LSSL_USED(SSL_set_min_proto_version);
90LSSL_USED(SSL_set_max_proto_version);
91LSSL_USED(SSL_CTX_get_ssl_method);
92LSSL_USED(BIO_f_ssl);
93LSSL_USED(BIO_new_ssl);
94LSSL_USED(BIO_new_ssl_connect);
95LSSL_USED(BIO_new_buffer_ssl_connect);
96LSSL_USED(BIO_ssl_copy_session_id);
97LSSL_USED(BIO_ssl_shutdown);
98LSSL_USED(SSL_CTX_get_ciphers);
99LSSL_USED(SSL_CTX_set_cipher_list);
100LSSL_USED(SSL_CTX_set_ciphersuites);
101LSSL_USED(SSL_CTX_new);
102LSSL_USED(SSL_CTX_free);
103LSSL_USED(SSL_CTX_up_ref);
104LSSL_USED(SSL_CTX_set_timeout);
105LSSL_USED(SSL_CTX_get_timeout);
106LSSL_USED(SSL_CTX_get_cert_store);
107LSSL_USED(SSL_CTX_set_cert_store);
108LSSL_USED(SSL_CTX_set1_cert_store);
109LSSL_USED(SSL_CTX_get0_certificate);
110LSSL_USED(SSL_CTX_get0_privatekey);
111LSSL_USED(SSL_want);
112LSSL_USED(SSL_clear);
113LSSL_USED(SSL_CTX_flush_sessions);
114LSSL_USED(SSL_get_current_cipher);
115LSSL_USED(SSL_CIPHER_get_bits);
116LSSL_USED(SSL_CIPHER_get_version);
117LSSL_USED(SSL_CIPHER_get_name);
118LSSL_USED(SSL_CIPHER_get_id);
119LSSL_USED(SSL_CIPHER_get_value);
120LSSL_USED(SSL_CIPHER_find);
121LSSL_USED(SSL_CIPHER_get_cipher_nid);
122LSSL_USED(SSL_CIPHER_get_digest_nid);
123LSSL_USED(SSL_CIPHER_get_kx_nid);
124LSSL_USED(SSL_CIPHER_get_auth_nid);
125LSSL_USED(SSL_CIPHER_is_aead);
126LSSL_USED(SSL_get_fd);
127LSSL_USED(SSL_get_rfd);
128LSSL_USED(SSL_get_wfd);
129LSSL_USED(SSL_get_cipher_list);
130LSSL_USED(SSL_get_shared_ciphers);
131LSSL_USED(SSL_get_read_ahead);
132LSSL_USED(SSL_pending);
133LSSL_USED(SSL_set_fd);
134LSSL_USED(SSL_set_rfd);
135LSSL_USED(SSL_set_wfd);
136LSSL_USED(SSL_set_bio);
137LSSL_USED(SSL_get_rbio);
138LSSL_USED(SSL_set0_rbio);
139LSSL_USED(SSL_get_wbio);
140LSSL_USED(SSL_set_cipher_list);
141LSSL_USED(SSL_set_ciphersuites);
142LSSL_USED(SSL_set_read_ahead);
143LSSL_USED(SSL_get_verify_mode);
144LSSL_USED(SSL_get_verify_depth);
145LSSL_USED(SSL_get_verify_callback);
146LSSL_USED(SSL_set_verify);
147LSSL_USED(SSL_set_verify_depth);
148LSSL_USED(SSL_use_RSAPrivateKey);
149LSSL_USED(SSL_use_RSAPrivateKey_ASN1);
150LSSL_USED(SSL_use_PrivateKey);
151LSSL_USED(SSL_use_PrivateKey_ASN1);
152LSSL_USED(SSL_use_certificate);
153LSSL_USED(SSL_use_certificate_ASN1);
154LSSL_USED(SSL_use_RSAPrivateKey_file);
155LSSL_USED(SSL_use_PrivateKey_file);
156LSSL_USED(SSL_use_certificate_file);
157LSSL_USED(SSL_use_certificate_chain_file);
158LSSL_USED(SSL_CTX_use_RSAPrivateKey_file);
159LSSL_USED(SSL_CTX_use_PrivateKey_file);
160LSSL_USED(SSL_CTX_use_certificate_file);
161LSSL_USED(SSL_CTX_use_certificate_chain_file);
162LSSL_USED(SSL_CTX_use_certificate_chain_mem);
163LSSL_USED(SSL_load_client_CA_file);
164LSSL_USED(SSL_add_file_cert_subjects_to_stack);
165LSSL_USED(SSL_add_dir_cert_subjects_to_stack);
166LSSL_USED(SSL_load_error_strings);
167LSSL_USED(SSL_state_string);
168LSSL_USED(SSL_rstate_string);
169LSSL_USED(SSL_state_string_long);
170LSSL_USED(SSL_rstate_string_long);
171LSSL_USED(SSL_SESSION_get0_cipher);
172LSSL_USED(SSL_SESSION_get_master_key);
173LSSL_USED(SSL_SESSION_get_protocol_version);
174LSSL_USED(SSL_SESSION_get_time);
175LSSL_USED(SSL_SESSION_set_time);
176LSSL_USED(SSL_SESSION_get_timeout);
177LSSL_USED(SSL_SESSION_set_timeout);
178LSSL_USED(SSL_copy_session_id);
179LSSL_USED(SSL_SESSION_get0_peer);
180LSSL_USED(SSL_SESSION_set1_id);
181LSSL_USED(SSL_SESSION_set1_id_context);
182LSSL_USED(SSL_SESSION_is_resumable);
183LSSL_USED(SSL_SESSION_new);
184LSSL_USED(SSL_SESSION_free);
185LSSL_USED(SSL_SESSION_up_ref);
186LSSL_USED(SSL_SESSION_get_id);
187LSSL_USED(SSL_SESSION_get0_id_context);
188LSSL_USED(SSL_SESSION_get_max_early_data);
189LSSL_USED(SSL_SESSION_set_max_early_data);
190LSSL_USED(SSL_SESSION_get_ticket_lifetime_hint);
191LSSL_USED(SSL_SESSION_has_ticket);
192LSSL_USED(SSL_SESSION_get_compress_id);
193LSSL_USED(SSL_SESSION_print_fp);
194LSSL_USED(SSL_SESSION_print);
195LSSL_USED(i2d_SSL_SESSION);
196LSSL_USED(SSL_set_session);
197LSSL_USED(SSL_CTX_add_session);
198LSSL_USED(SSL_CTX_remove_session);
199LSSL_USED(SSL_CTX_set_generate_session_id);
200LSSL_USED(SSL_set_generate_session_id);
201LSSL_USED(SSL_has_matching_session_id);
202LSSL_USED(d2i_SSL_SESSION);
203LSSL_USED(SSL_get_peer_cert_chain);
204LSSL_USED(SSL_CTX_get_verify_mode);
205LSSL_USED(SSL_CTX_get_verify_depth);
206LSSL_USED(SSL_CTX_get_verify_callback);
207LSSL_USED(SSL_CTX_set_verify);
208LSSL_USED(SSL_CTX_set_verify_depth);
209LSSL_USED(SSL_CTX_set_cert_verify_callback);
210LSSL_USED(SSL_CTX_use_RSAPrivateKey);
211LSSL_USED(SSL_CTX_use_RSAPrivateKey_ASN1);
212LSSL_USED(SSL_CTX_use_PrivateKey);
213LSSL_USED(SSL_CTX_use_PrivateKey_ASN1);
214LSSL_USED(SSL_CTX_use_certificate);
215LSSL_USED(SSL_CTX_use_certificate_ASN1);
216LSSL_USED(SSL_CTX_get_default_passwd_cb);
217LSSL_USED(SSL_CTX_set_default_passwd_cb);
218LSSL_USED(SSL_CTX_get_default_passwd_cb_userdata);
219LSSL_USED(SSL_CTX_set_default_passwd_cb_userdata);
220LSSL_USED(SSL_CTX_check_private_key);
221LSSL_USED(SSL_check_private_key);
222LSSL_USED(SSL_CTX_set_session_id_context);
223LSSL_USED(SSL_set_session_id_context);
224LSSL_USED(SSL_CTX_set_purpose);
225LSSL_USED(SSL_set_purpose);
226LSSL_USED(SSL_CTX_set_trust);
227LSSL_USED(SSL_set_trust);
228LSSL_USED(SSL_set1_host);
229LSSL_USED(SSL_set_hostflags);
230LSSL_USED(SSL_get0_peername);
231LSSL_USED(SSL_CTX_get0_param);
232LSSL_USED(SSL_CTX_set1_param);
233LSSL_USED(SSL_get0_param);
234LSSL_USED(SSL_set1_param);
235LSSL_USED(SSL_new);
236LSSL_USED(SSL_free);
237LSSL_USED(SSL_up_ref);
238LSSL_USED(SSL_accept);
239LSSL_USED(SSL_connect);
240LSSL_USED(SSL_is_dtls);
241LSSL_USED(SSL_is_server);
242LSSL_USED(SSL_read);
243LSSL_USED(SSL_peek);
244LSSL_USED(SSL_write);
245LSSL_USED(SSL_read_ex);
246LSSL_USED(SSL_peek_ex);
247LSSL_USED(SSL_write_ex);
248LSSL_USED(SSL_CTX_get_max_early_data);
249LSSL_USED(SSL_CTX_set_max_early_data);
250LSSL_USED(SSL_get_max_early_data);
251LSSL_USED(SSL_set_max_early_data);
252LSSL_USED(SSL_get_early_data_status);
253LSSL_USED(SSL_read_early_data);
254LSSL_USED(SSL_write_early_data);
255LSSL_USED(SSL_ctrl);
256LSSL_USED(SSL_callback_ctrl);
257LSSL_USED(SSL_CTX_ctrl);
258LSSL_USED(SSL_CTX_callback_ctrl);
259LSSL_USED(SSL_get_error);
260LSSL_USED(SSL_get_version);
261LSSL_USED(SSL_CTX_set_ssl_version);
262LSSL_USED(SSLv23_method);
263LSSL_USED(SSLv23_server_method);
264LSSL_USED(SSLv23_client_method);
265LSSL_USED(TLSv1_method);
266LSSL_USED(TLSv1_server_method);
267LSSL_USED(TLSv1_client_method);
268LSSL_USED(TLSv1_1_method);
269LSSL_USED(TLSv1_1_server_method);
270LSSL_USED(TLSv1_1_client_method);
271LSSL_USED(TLSv1_2_method);
272LSSL_USED(TLSv1_2_server_method);
273LSSL_USED(TLSv1_2_client_method);
274LSSL_USED(TLS_method);
275LSSL_USED(TLS_server_method);
276LSSL_USED(TLS_client_method);
277LSSL_USED(DTLSv1_method);
278LSSL_USED(DTLSv1_server_method);
279LSSL_USED(DTLSv1_client_method);
280LSSL_USED(DTLSv1_2_method);
281LSSL_USED(DTLSv1_2_server_method);
282LSSL_USED(DTLSv1_2_client_method);
283LSSL_USED(DTLS_method);
284LSSL_USED(DTLS_server_method);
285LSSL_USED(DTLS_client_method);
286LSSL_USED(SSL_get_ciphers);
287LSSL_USED(SSL_get_client_ciphers);
288LSSL_USED(SSL_get1_supported_ciphers);
289LSSL_USED(SSL_do_handshake);
290LSSL_USED(SSL_renegotiate);
291LSSL_USED(SSL_renegotiate_abbreviated);
292LSSL_USED(SSL_renegotiate_pending);
293LSSL_USED(SSL_shutdown);
294LSSL_USED(SSL_get_ssl_method);
295LSSL_USED(SSL_set_ssl_method);
296LSSL_USED(SSL_alert_type_string_long);
297LSSL_USED(SSL_alert_type_string);
298LSSL_USED(SSL_alert_desc_string_long);
299LSSL_USED(SSL_alert_desc_string);
300LSSL_USED(SSL_set_client_CA_list);
301LSSL_USED(SSL_CTX_set_client_CA_list);
302LSSL_USED(SSL_get_client_CA_list);
303LSSL_USED(SSL_CTX_get_client_CA_list);
304LSSL_USED(SSL_add_client_CA);
305LSSL_USED(SSL_CTX_add_client_CA);
306LSSL_USED(SSL_set_connect_state);
307LSSL_USED(SSL_set_accept_state);
308LSSL_USED(SSL_get_default_timeout);
309LSSL_USED(SSL_library_init);
310LSSL_USED(SSL_CIPHER_description);
311LSSL_USED(SSL_dup_CA_list);
312LSSL_USED(SSL_dup);
313LSSL_USED(SSL_get_certificate);
314LSSL_USED(SSL_get_privatekey);
315LSSL_USED(SSL_CTX_set_quiet_shutdown);
316LSSL_USED(SSL_CTX_get_quiet_shutdown);
317LSSL_USED(SSL_set_quiet_shutdown);
318LSSL_USED(SSL_get_quiet_shutdown);
319LSSL_USED(SSL_set_shutdown);
320LSSL_USED(SSL_get_shutdown);
321LSSL_USED(SSL_version);
322LSSL_USED(SSL_CTX_set_default_verify_paths);
323LSSL_USED(SSL_CTX_load_verify_locations);
324LSSL_USED(SSL_CTX_load_verify_mem);
325LSSL_USED(SSL_get_session);
326LSSL_USED(SSL_get1_session);
327LSSL_USED(SSL_get_SSL_CTX);
328LSSL_USED(SSL_set_SSL_CTX);
329LSSL_USED(SSL_set_info_callback);
330LSSL_USED(SSL_get_info_callback);
331LSSL_USED(SSL_state);
332LSSL_USED(SSL_set_state);
333LSSL_USED(SSL_set_verify_result);
334LSSL_USED(SSL_get_verify_result);
335LSSL_USED(SSL_set_ex_data);
336LSSL_USED(SSL_get_ex_data);
337LSSL_USED(SSL_get_ex_new_index);
338LSSL_USED(SSL_SESSION_set_ex_data);
339LSSL_USED(SSL_SESSION_get_ex_data);
340LSSL_USED(SSL_SESSION_get_ex_new_index);
341LSSL_USED(SSL_CTX_set_ex_data);
342LSSL_USED(SSL_CTX_get_ex_data);
343LSSL_USED(SSL_CTX_get_ex_new_index);
344LSSL_USED(SSL_get_ex_data_X509_STORE_CTX_idx);
345LSSL_USED(SSL_CTX_set_tmp_rsa_callback);
346LSSL_USED(SSL_set_tmp_rsa_callback);
347LSSL_USED(SSL_CTX_set_tmp_dh_callback);
348LSSL_USED(SSL_set_tmp_dh_callback);
349LSSL_USED(SSL_CTX_set_tmp_ecdh_callback);
350LSSL_USED(SSL_set_tmp_ecdh_callback);
351LSSL_USED(SSL_get_client_random);
352LSSL_USED(SSL_get_server_random);
353LSSL_USED(SSL_get_current_compression);
354LSSL_USED(SSL_get_current_expansion);
355LSSL_USED(SSL_get_peer_certificate);
356LSSL_USED(SSL_COMP_get_name);
357LSSL_USED(SSL_COMP_get_compression_methods);
358LSSL_USED(SSL_set_session_ticket_ext);
359LSSL_USED(SSL_set_session_ticket_ext_cb);
360LSSL_USED(SSL_set_session_secret_cb);
361LSSL_USED(SSL_cache_hit);
362LSSL_USED(SSL_set_security_level);
363LSSL_USED(SSL_get_security_level);
364LSSL_USED(SSL_CTX_set_security_level);
365LSSL_USED(SSL_CTX_get_security_level);
366LSSL_USED(SSL_CTX_set_quic_method);
367LSSL_USED(SSL_CTX_sess_get_get_cb);
368LSSL_USED(SSL_set_quic_method);
369LSSL_USED(SSL_is_quic);
370LSSL_USED(SSL_quic_max_handshake_flight_len);
371LSSL_USED(SSL_quic_read_level);
372LSSL_USED(SSL_quic_write_level);
373LSSL_USED(SSL_provide_quic_data);
374LSSL_USED(SSL_process_quic_post_handshake);
375LSSL_USED(SSL_set_quic_transport_params);
376LSSL_USED(SSL_get_peer_quic_transport_params);
377LSSL_USED(SSL_set_quic_use_legacy_codepoint);
378LSSL_USED(ERR_load_SSL_strings);
379LSSL_USED(OPENSSL_init_ssl);
380LSSL_USED(SSL_CIPHER_get_handshake_digest);
381
382#endif /* _LIBSSL_SSL_H */
diff --git a/src/lib/libssl/hidden/openssl/tls1.h b/src/lib/libssl/hidden/openssl/tls1.h
deleted file mode 100644
index e7c5721951..0000000000
--- a/src/lib/libssl/hidden/openssl/tls1.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/* $OpenBSD: tls1.h,v 1.2 2024/03/02 11:44:47 tb Exp $ */
2/*
3 * Copyright (c) 2023 Bob Beck <beck@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _LIBSSL_TLS1_H
19#define _LIBSSL_TLS1_H
20
21#ifndef _MSC_VER
22#include_next <openssl/tls1.h>
23#else
24#include "../include/openssl/tls1.h"
25#endif
26#include "ssl_namespace.h"
27
28LSSL_USED(SSL_get_servername);
29LSSL_USED(SSL_get_servername_type);
30LSSL_USED(SSL_export_keying_material);
31LSSL_USED(SSL_get_peer_signature_type_nid);
32LSSL_USED(SSL_get_signature_type_nid);
33
34#endif /* _LIBSSL_TLS1_H */
diff --git a/src/lib/libssl/hidden/ssl_namespace.h b/src/lib/libssl/hidden/ssl_namespace.h
deleted file mode 100644
index 5d26516f3c..0000000000
--- a/src/lib/libssl/hidden/ssl_namespace.h
+++ /dev/null
@@ -1,41 +0,0 @@
1/* $OpenBSD: ssl_namespace.h,v 1.3 2024/07/12 05:26:34 miod Exp $ */
2/*
3 * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _LIBSSL_SSL_NAMESPACE_H_
19#define _LIBSSL_SSL_NAMESPACE_H_
20
21/*
22 * If marked as 'used', then internal calls use the name with prefix "_lssl_"
23 * and we alias that to the normal name.
24 */
25
26#ifdef LIBRESSL_NAMESPACE
27#define LSSL_UNUSED(x) typeof(x) x __attribute__((deprecated))
28#define LSSL_USED(x) __attribute__((visibility("hidden"))) \
29 typeof(x) x asm("_lssl_"#x)
30#if defined(__hppa__)
31#define LSSL_ALIAS(x) asm("! .global "#x" ! .set "#x", _lssl_"#x)
32#else
33#define LSSL_ALIAS(x) asm(".global "#x"; "#x" = _lssl_"#x)
34#endif
35#else
36#define LSSL_UNUSED(x)
37#define LSSL_USED(x)
38#define LSSL_ALIAS(x) asm("")
39#endif
40
41#endif /* _LIBSSL_SSL_NAMESPACE_H_ */
diff --git a/src/lib/libssl/man/BIO_f_ssl.3 b/src/lib/libssl/man/BIO_f_ssl.3
deleted file mode 100644
index 3b74a3d6a4..0000000000
--- a/src/lib/libssl/man/BIO_f_ssl.3
+++ /dev/null
@@ -1,609 +0,0 @@
1.\" $OpenBSD: BIO_f_ssl.3,v 1.16 2024/01/13 18:37:51 tb Exp $
2.\" full merge up to: OpenSSL f672aee4 Feb 9 11:52:40 2016 -0500
3.\" selective merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800
4.\"
5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
6.\" Copyright (c) 2000, 2003, 2009, 2014-2016 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: January 13 2024 $
54.Dt BIO_F_SSL 3
55.Os
56.Sh NAME
57.Nm BIO_f_ssl ,
58.Nm BIO_set_ssl ,
59.Nm BIO_get_ssl ,
60.Nm BIO_set_ssl_mode ,
61.Nm BIO_set_ssl_renegotiate_bytes ,
62.Nm BIO_get_num_renegotiates ,
63.Nm BIO_set_ssl_renegotiate_timeout ,
64.Nm BIO_new_ssl ,
65.Nm BIO_new_ssl_connect ,
66.Nm BIO_new_buffer_ssl_connect ,
67.Nm BIO_ssl_copy_session_id ,
68.Nm BIO_ssl_shutdown ,
69.Nm BIO_do_handshake
70.Nd SSL BIO
71.Sh SYNOPSIS
72.In openssl/bio.h
73.In openssl/ssl.h
74.Ft const BIO_METHOD *
75.Fn BIO_f_ssl void
76.Ft long
77.Fo BIO_set_ssl
78.Fa "BIO *b"
79.Fa "SSL *ssl"
80.Fa "long c"
81.Fc
82.Ft long
83.Fo BIO_get_ssl
84.Fa "BIO *b"
85.Fa "SSL *sslp"
86.Fc
87.Ft long
88.Fo BIO_set_ssl_mode
89.Fa "BIO *b"
90.Fa "long client"
91.Fc
92.Ft long
93.Fo BIO_set_ssl_renegotiate_bytes
94.Fa "BIO *b"
95.Fa "long num"
96.Fc
97.Ft long
98.Fo BIO_set_ssl_renegotiate_timeout
99.Fa "BIO *b"
100.Fa "long seconds"
101.Fc
102.Ft long
103.Fo BIO_get_num_renegotiates
104.Fa "BIO *b"
105.Fc
106.Ft BIO *
107.Fn BIO_new_ssl "SSL_CTX *ctx" "int client"
108.Ft BIO *
109.Fn BIO_new_ssl_connect "SSL_CTX *ctx"
110.Ft BIO *
111.Fn BIO_new_buffer_ssl_connect "SSL_CTX *ctx"
112.Ft int
113.Fn BIO_ssl_copy_session_id "BIO *to" "BIO *from"
114.Ft void
115.Fn BIO_ssl_shutdown "BIO *bio"
116.Ft long
117.Fn BIO_do_handshake "BIO *b"
118.Sh DESCRIPTION
119.Fn BIO_f_ssl
120returns the
121.Vt SSL
122.Vt BIO
123method.
124This is a filter
125.Vt BIO
126which is a wrapper around the OpenSSL
127.Vt SSL
128routines adding a
129.Vt BIO
130.Dq flavor
131to SSL I/O.
132.Pp
133I/O performed on an
134.Vt SSL
135.Vt BIO
136communicates using the SSL protocol with
137the
138.Vt SSL Ns 's
139read and write
140.Vt BIO Ns s .
141If an SSL connection is not established then an attempt is made to establish
142one on the first I/O call.
143.Pp
144If a
145.Vt BIO
146is appended to an
147.Vt SSL
148.Vt BIO
149using
150.Xr BIO_push 3 ,
151it is automatically used as the
152.Vt SSL
153.Vt BIO Ns 's read and write
154.Vt BIO Ns s .
155.Pp
156Calling
157.Xr BIO_reset 3
158on an
159.Vt SSL
160.Vt BIO
161closes down any current SSL connection by calling
162.Xr SSL_shutdown 3 .
163.Xr BIO_reset 3
164is then sent to the next
165.Vt BIO
166in the chain; this will typically disconnect the underlying transport.
167The
168.Vt SSL
169.Vt BIO
170is then reset to the initial accept or connect state.
171.Pp
172If the close flag is set when an
173.Vt SSL
174.Vt BIO
175is freed then the internal
176.Vt SSL
177structure is also freed using
178.Xr SSL_free 3 .
179.Pp
180.Fn BIO_set_ssl
181sets the internal
182.Vt SSL
183pointer of
184.Vt BIO
185.Fa b
186to
187.Fa ssl
188using
189the close flag
190.Fa c .
191.Pp
192.Fn BIO_get_ssl
193retrieves the
194.Vt SSL
195pointer of
196.Vt BIO
197.Fa b ;
198it can then be manipulated using the standard SSL library functions.
199.Pp
200.Fn BIO_set_ssl_mode
201sets the
202.Vt SSL
203.Vt BIO
204mode to
205.Fa client .
206If
207.Fa client
208is 1, client mode is set.
209If
210.Fa client
211is 0, server mode is set.
212.Pp
213.Fn BIO_set_ssl_renegotiate_bytes
214sets the renegotiate byte count to
215.Fa num .
216When set, after every
217.Fa num
218bytes of I/O (read and write) the SSL session is automatically renegotiated.
219.Fa num
220must be at least 512 bytes.
221.Pp
222.Fn BIO_set_ssl_renegotiate_timeout
223sets the renegotiate timeout to
224.Fa seconds .
225When the renegotiate timeout elapses, the session is automatically renegotiated.
226.Pp
227.Fn BIO_get_num_renegotiates
228returns the total number of session renegotiations due to I/O or timeout.
229.Pp
230.Fn BIO_new_ssl
231allocates an
232.Vt SSL
233.Vt BIO
234using
235.Vt SSL_CTX
236.Va ctx
237and using client mode if
238.Fa client
239is nonzero.
240.Pp
241.Fn BIO_new_ssl_connect
242creates a new
243.Vt BIO
244chain consisting of an
245.Vt SSL
246.Vt BIO
247(using
248.Fa ctx )
249followed by a connect BIO.
250.Pp
251.Fn BIO_new_buffer_ssl_connect
252creates a new
253.Vt BIO
254chain consisting of a buffering
255.Vt BIO ,
256an
257.Vt SSL
258.Vt BIO
259(using
260.Fa ctx )
261and a connect
262.Vt BIO .
263.Pp
264.Fn BIO_ssl_copy_session_id
265copies an SSL session id between
266.Vt BIO
267chains
268.Fa from
269and
270.Fa to .
271It does this by locating the
272.Vt SSL
273.Vt BIO Ns s
274in each chain and calling
275.Xr SSL_copy_session_id 3
276on the internal
277.Vt SSL
278pointer.
279.Pp
280.Fn BIO_ssl_shutdown
281closes down an SSL connection on
282.Vt BIO
283chain
284.Fa bio .
285It does this by locating the
286.Vt SSL
287.Vt BIO
288in the
289chain and calling
290.Xr SSL_shutdown 3
291on its internal
292.Vt SSL
293pointer.
294.Pp
295.Fn BIO_do_handshake
296attempts to complete an SSL handshake on the supplied
297.Vt BIO
298and establish the SSL connection.
299It returns 1 if the connection was established successfully.
300A zero or negative value is returned if the connection could not be
301established; the call
302.Xr BIO_should_retry 3
303should be used for non blocking connect
304.Vt BIO Ns s
305to determine if the call should be retried.
306If an SSL connection has already been established, this call has no effect.
307.Pp
308When a chain containing an SSL BIO is copied with
309.Xr BIO_dup_chain 3 ,
310.Xr SSL_dup 3
311is called internally to copy the
312.Vt SSL
313object from the existing BIO object to the new BIO object,
314and the internal data related to
315.Fn BIO_set_ssl_renegotiate_bytes
316and
317.Fn BIO_set_ssl_renegotiate_timeout
318is also copied.
319.Pp
320.Vt SSL
321.Vt BIO Ns s
322are exceptional in that if the underlying transport is non-blocking they can
323still request a retry in exceptional circumstances.
324Specifically this will happen if a session renegotiation takes place during a
325.Xr BIO_read 3
326operation.
327One case where this happens is when step up occurs.
328.Pp
329In OpenSSL 0.9.6 and later the SSL flag
330.Dv SSL_AUTO_RETRY
331can be set to disable this behaviour.
332In other words, when this flag is set an
333.Vt SSL
334.Vt BIO
335using a blocking transport will never request a retry.
336.Pp
337Since unknown
338.Xr BIO_ctrl 3
339operations are sent through filter
340.Vt BIO Ns s ,
341the server name and port can be set using
342.Xr BIO_set_conn_hostname 3
343and
344.Xr BIO_set_conn_port 3
345on the
346.Vt BIO
347returned by
348.Fn BIO_new_ssl_connect
349without having to locate the connect
350.Vt BIO
351first.
352.Pp
353Applications do not have to call
354.Fn BIO_do_handshake
355but may wish to do so to separate the handshake process from other I/O
356processing.
357.Pp
358.Fn BIO_set_ssl ,
359.Fn BIO_get_ssl ,
360.Fn BIO_set_ssl_mode ,
361.Fn BIO_set_ssl_renegotiate_bytes ,
362.Fn BIO_set_ssl_renegotiate_timeout ,
363.Fn BIO_get_num_renegotiates ,
364and
365.Fn BIO_do_handshake
366are implemented as macros.
367.Sh RETURN VALUES
368.Fn BIO_f_ssl
369returns a pointer to a static
370.Vt BIO_METHOD
371structure.
372.Pp
373When called on an SSL BIO object,
374.Xr BIO_method_type 3
375returns the constant
376.Dv BIO_TYPE_SSL
377and
378.Xr BIO_method_name 3
379returns a pointer to the static string
380.Qq ssl .
381.Pp
382.Fn BIO_set_ssl ,
383.Fn BIO_get_ssl ,
384.Fn BIO_set_ssl_mode ,
385.Fn BIO_set_ssl_renegotiate_bytes ,
386.Fn BIO_set_ssl_renegotiate_timeout ,
387and
388.Fn BIO_get_num_renegotiates
389return 1 on success or a value less than or equal to 0
390if an error occurred.
391.Pp
392.Fn BIO_new_ssl ,
393.Fn BIO_new_ssl_connect ,
394and
395.Fn BIO_new_buffer_ssl_connect
396returns a pointer to a newly allocated
397.Vt BIO
398chain or
399.Dv NULL
400if an error occurred.
401.Pp
402.Fn BIO_ssl_copy_session_id
403returns 1 on success or 0 on error.
404.Pp
405.Fn BIO_do_handshake
406returns 1 if the connection was established successfully
407or a value less than or equal to 0 otherwise.
408.Sh EXAMPLES
409This SSL/TLS client example attempts to retrieve a page from an SSL/TLS web
410server.
411The I/O routines are identical to those of the unencrypted example in
412.Xr BIO_s_connect 3 .
413.Bd -literal
414BIO *sbio, *out;
415int len;
416char tmpbuf[1024];
417SSL_CTX *ctx;
418SSL *ssl;
419
420ERR_load_crypto_strings();
421ERR_load_SSL_strings();
422OpenSSL_add_all_algorithms();
423
424/*
425 * We would seed the PRNG here if the platform didn't do it automatically
426 */
427
428ctx = SSL_CTX_new(SSLv23_client_method());
429
430/*
431 * We'd normally set some stuff like the verify paths and mode here because
432 * as things stand this will connect to any server whose certificate is
433 * signed by any CA.
434 */
435
436sbio = BIO_new_ssl_connect(ctx);
437
438BIO_get_ssl(sbio, &ssl);
439
440if (!ssl) {
441 fprintf(stderr, "Can't locate SSL pointer\en");
442 /* whatever ... */
443}
444
445/* Don't want any retries */
446SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
447
448/* We might want to do other things with ssl here */
449
450BIO_set_conn_hostname(sbio, "localhost:https");
451
452out = BIO_new_fp(stdout, BIO_NOCLOSE);
453if (BIO_do_connect(sbio) <= 0) {
454 fprintf(stderr, "Error connecting to server\en");
455 ERR_print_errors_fp(stderr);
456 /* whatever ... */
457}
458
459if (BIO_do_handshake(sbio) <= 0) {
460 fprintf(stderr, "Error establishing SSL connection\en");
461 ERR_print_errors_fp(stderr);
462 /* whatever ... */
463}
464
465/* Could examine ssl here to get connection info */
466
467BIO_puts(sbio, "GET / HTTP/1.0\en\en");
468for (;;) {
469 len = BIO_read(sbio, tmpbuf, 1024);
470 if(len <= 0) break;
471 BIO_write(out, tmpbuf, len);
472}
473BIO_free_all(sbio);
474BIO_free(out);
475.Ed
476.Pp
477Here is a simple server example.
478It makes use of a buffering
479.Vt BIO
480to allow lines to be read from the
481.Vt SSL
482.Vt BIO
483using
484.Xr BIO_gets 3 .
485It creates a pseudo web page containing the actual request from a client and
486also echoes the request to standard output.
487.Bd -literal
488BIO *sbio, *bbio, *acpt, *out;
489int len;
490char tmpbuf[1024];
491SSL_CTX *ctx;
492SSL *ssl;
493
494ctx = SSL_CTX_new(SSLv23_server_method());
495
496if (!SSL_CTX_use_certificate_file(ctx,"server.pem",SSL_FILETYPE_PEM)
497 || !SSL_CTX_use_PrivateKey_file(ctx,"server.pem",SSL_FILETYPE_PEM)
498 || !SSL_CTX_check_private_key(ctx)) {
499 fprintf(stderr, "Error setting up SSL_CTX\en");
500 ERR_print_errors_fp(stderr);
501 return 0;
502}
503
504/*
505 * Might do other things here like setting verify locations and DH and/or
506 * RSA temporary key callbacks
507 */
508
509/* New SSL BIO setup as server */
510sbio = BIO_new_ssl(ctx,0);
511
512BIO_get_ssl(sbio, &ssl);
513
514if (!ssl) {
515 fprintf(stderr, "Can't locate SSL pointer\en");
516 /* whatever ... */
517}
518
519/* Don't want any retries */
520SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
521
522/* Create the buffering BIO */
523
524bbio = BIO_new(BIO_f_buffer());
525
526/* Add to chain */
527sbio = BIO_push(bbio, sbio);
528
529acpt = BIO_new_accept("4433");
530
531/*
532 * By doing this when a new connection is established we automatically
533 * have sbio inserted into it. The BIO chain is now 'swallowed' by the
534 * accept BIO and will be freed when the accept BIO is freed.
535 */
536
537BIO_set_accept_bios(acpt,sbio);
538
539out = BIO_new_fp(stdout, BIO_NOCLOSE);
540
541/* Wait for incoming connection */
542if (BIO_do_accept(acpt) <= 0) {
543 fprintf(stderr, "Error setting up accept BIO\en");
544 ERR_print_errors_fp(stderr);
545 return 0;
546}
547
548/* We only want one connection so remove and free accept BIO */
549
550sbio = BIO_pop(acpt);
551
552BIO_free_all(acpt);
553
554if (BIO_do_handshake(sbio) <= 0) {
555 fprintf(stderr, "Error in SSL handshake\en");
556 ERR_print_errors_fp(stderr);
557 return 0;
558}
559
560BIO_puts(sbio, "HTTP/1.0 200 OK\er\enContent-type: text/plain\er\en\er\en");
561BIO_puts(sbio, "\er\enConnection Established\er\enRequest headers:\er\en");
562BIO_puts(sbio, "--------------------------------------------------\er\en");
563
564for (;;) {
565 len = BIO_gets(sbio, tmpbuf, 1024);
566 if (len <= 0)
567 break;
568 BIO_write(sbio, tmpbuf, len);
569 BIO_write(out, tmpbuf, len);
570 /* Look for blank line signifying end of headers */
571 if ((tmpbuf[0] == '\er') || (tmpbuf[0] == '\en'))
572 break;
573}
574
575BIO_puts(sbio, "--------------------------------------------------\er\en");
576BIO_puts(sbio, "\er\en");
577
578/* Since there is a buffering BIO present we had better flush it */
579BIO_flush(sbio);
580
581BIO_free_all(sbio);
582.Ed
583.Sh SEE ALSO
584.Xr BIO_new 3 ,
585.Xr ssl 3
586.Sh HISTORY
587.Fn BIO_f_ssl ,
588.Fn BIO_set_ssl ,
589and
590.Fn BIO_get_ssl
591first appeared in SSLeay 0.6.0.
592.Fn BIO_set_ssl_mode ,
593.Fn BIO_new_ssl ,
594and
595.Fn BIO_ssl_copy_session_id
596first appeared in SSLeay 0.8.0.
597.Fn BIO_ssl_shutdown
598and
599.Fn BIO_do_handshake
600first appeared in SSLeay 0.8.1.
601.Fn BIO_set_ssl_renegotiate_bytes ,
602.Fn BIO_get_num_renegotiates ,
603.Fn BIO_set_ssl_renegotiate_timeout ,
604.Fn BIO_new_ssl_connect ,
605and
606.Fn BIO_new_buffer_ssl_connect
607first appeared in SSLeay 0.9.0.
608All these functions have been available since
609.Ox 2.4 .
diff --git a/src/lib/libssl/man/DTLSv1_listen.3 b/src/lib/libssl/man/DTLSv1_listen.3
deleted file mode 100644
index 047ec0a7ff..0000000000
--- a/src/lib/libssl/man/DTLSv1_listen.3
+++ /dev/null
@@ -1,187 +0,0 @@
1.\" $OpenBSD: DTLSv1_listen.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL 7795475f Dec 18 13:18:31 2015 -0500
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>.
5.\" Copyright (c) 2015 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt DTLSV1_LISTEN 3
53.Os
54.Sh NAME
55.Nm DTLSv1_listen
56.Nd listen for incoming DTLS connections
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fo DTLSv1_listen
61.Fa "SSL *ssl"
62.Fa "struct sockaddr *peer"
63.Fc
64.Sh DESCRIPTION
65.Fn DTLSv1_listen
66listens for new incoming DTLS connections.
67If a ClientHello is received that does not contain a cookie, then
68.Fn DTLSv1_listen
69responds with a HelloVerifyRequest.
70If a ClientHello is received with a cookie that is verified, then
71control is returned to user code to enable the handshake to be
72completed (for example by using
73.Xr SSL_accept 3 ) .
74.Pp
75.Fn DTLSv1_listen
76is currently implemented as a macro.
77.Pp
78Datagram based protocols can be susceptible to Denial of Service
79attacks.
80A DTLS attacker could, for example, submit a series of handshake
81initiation requests that cause the server to allocate state (and
82possibly perform cryptographic operations) thus consuming server
83resources.
84The attacker could also (with UDP) quite simply forge the source IP
85address in such an attack.
86.Pp
87As a counter measure to that DTLS includes a stateless cookie mechanism.
88The idea is that when a client attempts to connect to a server it sends
89a ClientHello message.
90The server responds with a HelloVerifyRequest which contains a unique
91cookie.
92The client then resends the ClientHello, but this time includes the
93cookie in the message thus proving that the client is capable of
94receiving messages sent to that address.
95All of this can be done by the server without allocating any state, and
96thus without consuming expensive resources.
97.Pp
98OpenSSL implements this capability via the
99.Fn DTLSv1_listen
100function.
101The
102.Fa ssl
103parameter should be a newly allocated
104.Vt SSL
105object with its read and write BIOs set, in the same way as might
106be done for a call to
107.Xr SSL_accept 3 .
108Typically the read BIO will be in an "unconnected" state and thus
109capable of receiving messages from any peer.
110.Pp
111When a ClientHello is received that contains a cookie that has been
112verified, then
113.Fn DTLSv1_listen
114will return with the
115.Fa ssl
116parameter updated into a state where the handshake can be continued by a
117call to (for example)
118.Xr SSL_accept 3 .
119Additionally the
120.Vt struct sockaddr
121pointed to by
122.Fa peer
123will be filled in with details of the peer that sent the ClientHello.
124It is the calling code's responsibility to ensure that the
125.Fa peer
126location is sufficiently large to accommodate the addressing scheme in use.
127For example this might be done by allocating space for a
128.Vt struct sockaddr_storage
129and casting the pointer to it to a
130.Vt struct sockaddr *
131for the call to
132.Fn DTLSv1_listen .
133Typically user code is expected to "connect" the underlying socket
134to the peer and continue the handshake in a connected state.
135.Pp
136Prior to calling
137.Fn DTLSv1_listen
138user code must ensure that cookie generation and verification callbacks
139have been set up using
140.Fn SSL_CTX_set_cookie_generate_cb
141and
142.Fn SSL_CTX_set_cookie_verify_cb
143respectively.
144.Pp
145Since
146.Fn DTLSv1_listen
147operates entirely statelessly whilst processing incoming ClientHellos,
148it is unable to process fragmented messages (since this would require
149the allocation of state).
150An implication of this is that
151.Fn DTLSv1_listen
152only supports ClientHellos that fit inside a single datagram.
153.Sh RETURN VALUES
154From OpenSSL 1.1.0 a return value of >= 1 indicates success.
155In this instance the
156.Fa peer
157value will be filled in and the
158.Fa ssl
159object set up ready to continue the handshake.
160.Pp
161A return value of 0 indicates a non-fatal error.
162This could (for example) be because of non-blocking IO, or some invalid
163message having been received from a peer.
164Errors may be placed on the OpenSSL error queue with further information
165if appropriate.
166Typically user code is expected to retry the call to
167.Fn DTLSv1_listen
168in the event of a non-fatal error.
169Any old errors on the error queue will be cleared in the subsequent
170call.
171.Pp
172A return value of <0 indicates a fatal error.
173This could (for example) be because of a failure to allocate sufficient
174memory for the operation.
175.Pp
176Prior to OpenSSL 1.1.0 fatal and non-fatal errors both produce return
177codes <= 0 (in typical implementations user code treats all errors as
178non-fatal), whilst return codes >0 indicate success.
179.Sh SEE ALSO
180.Xr BIO_new 3 ,
181.Xr ssl 3 ,
182.Xr SSL_accept 3 ,
183.Xr SSL_get_error 3
184.Sh HISTORY
185.Fn DTLSv1_listen
186first appeared in OpenSSL 0.9.8m and has been available since
187.Ox 4.9 .
diff --git a/src/lib/libssl/man/Makefile b/src/lib/libssl/man/Makefile
deleted file mode 100644
index c8f6e28541..0000000000
--- a/src/lib/libssl/man/Makefile
+++ /dev/null
@@ -1,134 +0,0 @@
1# $OpenBSD: Makefile,v 1.77 2022/07/13 20:52:36 schwarze Exp $
2
3.include <bsd.own.mk>
4
5MAN = BIO_f_ssl.3 \
6 DTLSv1_listen.3 \
7 OPENSSL_init_ssl.3 \
8 PEM_read_SSL_SESSION.3 \
9 SSL_CIPHER_get_name.3 \
10 SSL_COMP_add_compression_method.3 \
11 SSL_CTX_add1_chain_cert.3 \
12 SSL_CTX_add_extra_chain_cert.3 \
13 SSL_CTX_add_session.3 \
14 SSL_CTX_ctrl.3 \
15 SSL_CTX_flush_sessions.3 \
16 SSL_CTX_free.3 \
17 SSL_CTX_get0_certificate.3 \
18 SSL_CTX_get_ex_new_index.3 \
19 SSL_CTX_get_verify_mode.3 \
20 SSL_CTX_load_verify_locations.3 \
21 SSL_CTX_new.3 \
22 SSL_CTX_sess_number.3 \
23 SSL_CTX_sess_set_cache_size.3 \
24 SSL_CTX_sess_set_get_cb.3 \
25 SSL_CTX_sessions.3 \
26 SSL_CTX_set1_groups.3 \
27 SSL_CTX_set_alpn_select_cb.3 \
28 SSL_CTX_set_cert_store.3 \
29 SSL_CTX_set_cert_verify_callback.3 \
30 SSL_CTX_set_cipher_list.3 \
31 SSL_CTX_set_client_CA_list.3 \
32 SSL_CTX_set_client_cert_cb.3 \
33 SSL_CTX_set_default_passwd_cb.3 \
34 SSL_CTX_set_generate_session_id.3 \
35 SSL_CTX_set_info_callback.3 \
36 SSL_CTX_set_keylog_callback.3 \
37 SSL_CTX_set_max_cert_list.3 \
38 SSL_CTX_set_min_proto_version.3 \
39 SSL_CTX_set_mode.3 \
40 SSL_CTX_set_msg_callback.3 \
41 SSL_CTX_set_options.3 \
42 SSL_CTX_set_quiet_shutdown.3 \
43 SSL_CTX_set_read_ahead.3 \
44 SSL_CTX_set_security_level.3 \
45 SSL_CTX_set_session_cache_mode.3 \
46 SSL_CTX_set_session_id_context.3 \
47 SSL_CTX_set_ssl_version.3 \
48 SSL_CTX_set_timeout.3 \
49 SSL_CTX_set_tlsext_servername_callback.3 \
50 SSL_CTX_set_tlsext_status_cb.3 \
51 SSL_CTX_set_tlsext_ticket_key_cb.3 \
52 SSL_CTX_set_tlsext_use_srtp.3 \
53 SSL_CTX_set_tmp_dh_callback.3 \
54 SSL_CTX_set_tmp_rsa_callback.3 \
55 SSL_CTX_set_verify.3 \
56 SSL_CTX_use_certificate.3 \
57 SSL_SESSION_free.3 \
58 SSL_SESSION_get0_cipher.3 \
59 SSL_SESSION_get0_peer.3 \
60 SSL_SESSION_get_compress_id.3 \
61 SSL_SESSION_get_ex_new_index.3 \
62 SSL_SESSION_get_id.3 \
63 SSL_SESSION_get_protocol_version.3 \
64 SSL_SESSION_get_time.3 \
65 SSL_SESSION_has_ticket.3 \
66 SSL_SESSION_is_resumable.3 \
67 SSL_SESSION_new.3 \
68 SSL_SESSION_print.3 \
69 SSL_SESSION_set1_id_context.3 \
70 SSL_accept.3 \
71 SSL_alert_type_string.3 \
72 SSL_clear.3 \
73 SSL_connect.3 \
74 SSL_copy_session_id.3 \
75 SSL_do_handshake.3 \
76 SSL_dup.3 \
77 SSL_dup_CA_list.3 \
78 SSL_export_keying_material.3 \
79 SSL_free.3 \
80 SSL_get_SSL_CTX.3 \
81 SSL_get_certificate.3 \
82 SSL_get_ciphers.3 \
83 SSL_get_client_CA_list.3 \
84 SSL_get_client_random.3 \
85 SSL_get_current_cipher.3 \
86 SSL_get_default_timeout.3 \
87 SSL_get_error.3 \
88 SSL_get_ex_data_X509_STORE_CTX_idx.3 \
89 SSL_get_ex_new_index.3 \
90 SSL_get_fd.3 \
91 SSL_get_finished.3 \
92 SSL_get_peer_cert_chain.3 \
93 SSL_get_peer_certificate.3 \
94 SSL_get_rbio.3 \
95 SSL_get_server_tmp_key.3 \
96 SSL_get_session.3 \
97 SSL_get_shared_ciphers.3 \
98 SSL_get_state.3 \
99 SSL_get_verify_result.3 \
100 SSL_get_version.3 \
101 SSL_library_init.3 \
102 SSL_load_client_CA_file.3 \
103 SSL_new.3 \
104 SSL_num_renegotiations.3 \
105 SSL_pending.3 \
106 SSL_read.3 \
107 SSL_read_early_data.3 \
108 SSL_renegotiate.3 \
109 SSL_rstate_string.3 \
110 SSL_session_reused.3 \
111 SSL_set1_host.3 \
112 SSL_set1_param.3 \
113 SSL_set_SSL_CTX.3 \
114 SSL_set_bio.3 \
115 SSL_set_connect_state.3 \
116 SSL_set_fd.3 \
117 SSL_set_max_send_fragment.3 \
118 SSL_set_psk_use_session_callback.3 \
119 SSL_set_session.3 \
120 SSL_set_shutdown.3 \
121 SSL_set_tmp_ecdh.3 \
122 SSL_set_verify_result.3 \
123 SSL_shutdown.3 \
124 SSL_state_string.3 \
125 SSL_want.3 \
126 SSL_write.3 \
127 d2i_SSL_SESSION.3 \
128 ssl.3
129
130all clean cleandir depend includes obj tags:
131
132install: maninstall
133
134.include <bsd.man.mk>
diff --git a/src/lib/libssl/man/OPENSSL_init_ssl.3 b/src/lib/libssl/man/OPENSSL_init_ssl.3
deleted file mode 100644
index f37dccfaac..0000000000
--- a/src/lib/libssl/man/OPENSSL_init_ssl.3
+++ /dev/null
@@ -1,76 +0,0 @@
1.\" $OpenBSD: OPENSSL_init_ssl.3,v 1.4 2019/06/14 13:41:31 schwarze Exp $
2.\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org>
3.\"
4.\" Permission to use, copy, modify, and distribute this software for any
5.\" purpose with or without fee is hereby granted, provided that the above
6.\" copyright notice and this permission notice appear in all copies.
7.\"
8.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15.\"
16.Dd $Mdocdate: June 14 2019 $
17.Dt OPENSSL_INIT_SSL 3
18.Os
19.Sh NAME
20.Nm OPENSSL_init_ssl
21.Nd initialise the crypto and ssl libraries
22.Sh SYNOPSIS
23.In openssl/ssl.h
24.Ft int
25.Fo OPENSSL_init_ssl
26.Fa "uint64_t options"
27.Fa "const void *dummy"
28.Fc
29.Sh DESCRIPTION
30This function is deprecated.
31It is never useful for any application program to call it explicitly.
32The library automatically calls it internally with an
33.Fa options
34argument of 0 whenever needed.
35It is safest to assume that any function may do so.
36.Pp
37To enable or disable the standard configuration file, instead use
38.Xr OPENSSL_config 3
39or
40.Xr OPENSSL_no_config 3 ,
41respectively.
42To load a non-standard configuration file, refer to
43.Xr CONF_modules_load_file 3 .
44.Pp
45.Fn OPENSSL_init_ssl
46calls
47.Xr OPENSSL_init_crypto 3 ,
48.Xr SSL_load_error_strings 3 ,
49and
50.Xr SSL_library_init 3 .
51.Pp
52The
53.Fa options
54argument is passed on to
55.Xr OPENSSL_init_crypto 3
56and the
57.Fa dummy
58argument is ignored.
59.Pp
60If this function is called more than once,
61none of the calls except the first one have any effect.
62.Sh RETURN VALUES
63.Fn OPENSSL_init_ssl
64is intended to return 1 on success or 0 on error.
65.Sh SEE ALSO
66.Xr CONF_modules_load_file 3 ,
67.Xr OPENSSL_config 3 ,
68.Xr ssl 3
69.Sh HISTORY
70.Fn OPENSSL_init_ssl
71first appeared in OpenSSL 1.1.0 and has been available since
72.Ox 6.3 .
73.Sh BUGS
74.Fn OPENSSL_init_ssl
75silently ignores even more configuration failures than
76.Xr OPENSSL_init_crypto 3 .
diff --git a/src/lib/libssl/man/PEM_read_SSL_SESSION.3 b/src/lib/libssl/man/PEM_read_SSL_SESSION.3
deleted file mode 100644
index 3eb1414c62..0000000000
--- a/src/lib/libssl/man/PEM_read_SSL_SESSION.3
+++ /dev/null
@@ -1,147 +0,0 @@
1.\" $OpenBSD: PEM_read_SSL_SESSION.3,v 1.4 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL doc/man3/PEM_read_CMS.pod b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Rich Salz <rsalz@openssl.org>.
5.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 12 2019 $
52.Dt PEM_READ_SSL_SESSION 3
53.Os
54.Sh NAME
55.Nm PEM_read_SSL_SESSION ,
56.Nm PEM_read_bio_SSL_SESSION ,
57.Nm PEM_write_SSL_SESSION ,
58.Nm PEM_write_bio_SSL_SESSION
59.Nd encode and decode SSL session objects in PEM format
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft SSL_SESSION *
63.Fo PEM_read_SSL_SESSION
64.Fa "FILE *fp"
65.Fa "SSL_SESSION **a"
66.Fa "pem_password_cb *cb"
67.Fa "void *u"
68.Fc
69.Ft SSL_SESSION *
70.Fo PEM_read_bio_SSL_SESSION
71.Fa "BIO *bp"
72.Fa "SSL_SESSION **a"
73.Fa "pem_password_cb *cb"
74.Fa "void *u"
75.Fc
76.Ft int
77.Fo PEM_write_SSL_SESSION
78.Fa "FILE *fp"
79.Fa "const SSL_SESSION *a"
80.Fc
81.Ft int
82.Fo PEM_write_bio_SSL_SESSION
83.Fa "BIO *bp"
84.Fa "const SSL_SESSION *a"
85.Fc
86.Sh DESCRIPTION
87These routines convert between local instances of ASN.1
88.Vt SSL_SESSION
89objects and the PEM encoding.
90.Pp
91.Fn PEM_read_SSL_SESSION
92reads a PEM-encoded
93.Vt SSL_SESSION
94object from the file
95.Fa fp
96and returns it.
97The
98.Fa cb
99and
100.Fa u
101parameters are as described in
102.Xr PEM_read_bio_PrivateKey 3 .
103.Pp
104.Fn PEM_read_bio_SSL_SESSION
105is similar to
106.Fn PEM_read_SSL_SESSION
107but reads from the BIO
108.Fa bp .
109.Pp
110.Fn PEM_write_SSL_SESSION
111writes the PEM encoding of the object
112.Fa a
113to the file
114.Fa fp .
115.Pp
116.Fn PEM_write_bio_SSL_SESSION
117similarly writes to the BIO
118.Fa bp .
119.Sh RETURN VALUES
120.Fn PEM_read_SSL_SESSION
121and
122.Fn PEM_read_bio_SSL_SESSION
123return a pointer to an allocated object, which should be released by
124calling
125.Xr SSL_SESSION_free 3 ,
126or
127.Dv NULL
128on error.
129.Pp
130.Fn PEM_write_SSL_SESSION
131and
132.Fn PEM_write_bio_SSL_SESSION
133return the number of bytes written or 0 on error.
134.Sh SEE ALSO
135.Xr PEM_read 3 ,
136.Xr ssl 3
137.Sh HISTORY
138.Fn PEM_read_SSL_SESSION
139and
140.Fn PEM_write_SSL_SESSION
141first appeared in SSLeay 0.5.2.
142.Fn PEM_read_bio_SSL_SESSION
143and
144.Fn PEM_write_bio_SSL_SESSION
145first appeared in SSLeay 0.6.0.
146These functions have been available since
147.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CIPHER_get_name.3 b/src/lib/libssl/man/SSL_CIPHER_get_name.3
deleted file mode 100644
index 86c1d3c0ba..0000000000
--- a/src/lib/libssl/man/SSL_CIPHER_get_name.3
+++ /dev/null
@@ -1,398 +0,0 @@
1.\" $OpenBSD: SSL_CIPHER_get_name.3,v 1.17 2024/07/16 10:19:38 tb Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\" selective merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>,
6.\" Dr. Stephen Henson <steve@openssl.org>, Todd Short <tshort@akamai.com>,
7.\" and Paul Yang <yang.yang@baishancloud.com>.
8.\" Copyright (c) 2000, 2005, 2009, 2013, 2014, 2015, 2016, 2017
9.\" The OpenSSL Project. All rights reserved.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\"
15.\" 1. Redistributions of source code must retain the above copyright
16.\" notice, this list of conditions and the following disclaimer.
17.\"
18.\" 2. Redistributions in binary form must reproduce the above copyright
19.\" notice, this list of conditions and the following disclaimer in
20.\" the documentation and/or other materials provided with the
21.\" distribution.
22.\"
23.\" 3. All advertising materials mentioning features or use of this
24.\" software must display the following acknowledgment:
25.\" "This product includes software developed by the OpenSSL Project
26.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
27.\"
28.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
29.\" endorse or promote products derived from this software without
30.\" prior written permission. For written permission, please contact
31.\" openssl-core@openssl.org.
32.\"
33.\" 5. Products derived from this software may not be called "OpenSSL"
34.\" nor may "OpenSSL" appear in their names without prior written
35.\" permission of the OpenSSL Project.
36.\"
37.\" 6. Redistributions of any form whatsoever must retain the following
38.\" acknowledgment:
39.\" "This product includes software developed by the OpenSSL Project
40.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
41.\"
42.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
43.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
46.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53.\" OF THE POSSIBILITY OF SUCH DAMAGE.
54.\"
55.Dd $Mdocdate: July 16 2024 $
56.Dt SSL_CIPHER_GET_NAME 3
57.Os
58.Sh NAME
59.Nm SSL_CIPHER_get_name ,
60.Nm SSL_CIPHER_get_bits ,
61.Nm SSL_CIPHER_get_version ,
62.Nm SSL_CIPHER_get_cipher_nid ,
63.Nm SSL_CIPHER_get_digest_nid ,
64.Nm SSL_CIPHER_get_handshake_digest ,
65.Nm SSL_CIPHER_get_kx_nid ,
66.Nm SSL_CIPHER_get_auth_nid ,
67.Nm SSL_CIPHER_is_aead ,
68.Nm SSL_CIPHER_find ,
69.Nm SSL_CIPHER_get_id ,
70.Nm SSL_CIPHER_description
71.Nd get SSL_CIPHER properties
72.Sh SYNOPSIS
73.In openssl/ssl.h
74.Ft const char *
75.Fn SSL_CIPHER_get_name "const SSL_CIPHER *cipher"
76.Ft int
77.Fn SSL_CIPHER_get_bits "const SSL_CIPHER *cipher" "int *alg_bits"
78.Ft const char *
79.Fn SSL_CIPHER_get_version "const SSL_CIPHER *cipher"
80.Ft int
81.Fn SSL_CIPHER_get_cipher_nid "const SSL_CIPHER *cipher"
82.Ft int
83.Fn SSL_CIPHER_get_digest_nid "const SSL_CIPHER *cipher"
84.Ft "const EVP_MD *"
85.Fn SSL_CIPHER_get_handshake_digest "const SSL_CIPHER *cipher"
86.Ft int
87.Fn SSL_CIPHER_get_kx_nid "const SSL_CIPHER *cipher"
88.Ft int
89.Fn SSL_CIPHER_get_auth_nid "const SSL_CIPHER *cipher"
90.Ft int
91.Fn SSL_CIPHER_is_aead "const SSL_CIPHER *cipher"
92.Ft const SSL_CIPHER *
93.Fn SSL_CIPHER_find "SSL *ssl" "const unsigned char *ptr"
94.Ft unsigned long
95.Fn SSL_CIPHER_get_id "const SSL_CIPHER *cipher"
96.Ft char *
97.Fn SSL_CIPHER_description "const SSL_CIPHER *cipher" "char *buf" "int size"
98.Sh DESCRIPTION
99.Fn SSL_CIPHER_get_name
100returns a pointer to the name of
101.Fa cipher .
102.Pp
103.Fn SSL_CIPHER_get_bits
104returns the number of secret bits used for
105.Fa cipher .
106If
107.Fa alg_bits
108is not
109.Dv NULL ,
110the number of bits processed by the chosen algorithm is stored into it.
111.Pp
112.Fn SSL_CIPHER_get_version
113returns a string which indicates the SSL/TLS protocol version that first
114defined the cipher.
115This is currently
116.Qq TLSv1/SSLv3 .
117In some cases it should possibly return
118.Qq TLSv1.2
119but the function does not; use
120.Fn SSL_CIPHER_description
121instead.
122.Pp
123.Fn SSL_CIPHER_get_cipher_nid
124returns the cipher NID corresponding to the
125.Fa cipher .
126If there is no cipher (e.g. for cipher suites with no encryption), then
127.Dv NID_undef
128is returned.
129.Pp
130.Fn SSL_CIPHER_get_digest_nid
131returns the digest NID corresponding to the MAC used by the
132.Fa cipher
133during record encryption/decryption.
134If there is no digest (e.g. for AEAD cipher suites), then
135.Dv NID_undef
136is returned.
137.Pp
138.Fn SSL_CIPHER_get_handshake_digest
139returns the
140.Vt EVP_MD
141object representing the digest used during a TLS handshake with the cipher
142.Fa c ,
143which may be different to the digest used in the message authentication code
144for encrypted records.
145.Pp
146.Fn SSL_CIPHER_get_kx_nid
147returns the key exchange NID corresponding to the method used by the
148.Fa cipher .
149If there is no key exchange, then
150.Dv NID_undef
151is returned.
152Examples of possible return values include
153.Dv NID_kx_rsa ,
154.Dv NID_kx_dhe ,
155and
156.Dv NID_kx_ecdhe .
157.Pp
158.Fn SSL_CIPHER_get_auth_nid
159returns the authentication NID corresponding to the method used by the
160.Fa cipher .
161If there is no authentication,
162.Dv NID_undef
163is returned.
164Examples of possible return values include
165.Dv NID_auth_rsa
166and
167.Dv NID_auth_ecdsa .
168.Pp
169.Fn SSL_CIPHER_is_aead
170returns 1 if the
171.Fa cipher
172is AEAD (e.g. GCM or ChaCha20/Poly1305), or 0 if it is not AEAD.
173.Pp
174.Fn SSL_CIPHER_find
175returns a pointer to a
176.Vt SSL_CIPHER
177structure which has the cipher ID specified in
178.Fa ptr .
179The
180.Fa ptr
181parameter is an array of length two which stores the two-byte
182TLS cipher ID (as allocated by IANA) in network byte order.
183.Fa SSL_CIPHER_find
184returns
185.Dv NULL
186if an error occurs or the indicated cipher is not found.
187.Pp
188.Fn SSL_CIPHER_get_id
189returns the ID of the given
190.Fa cipher ,
191which must not be
192.Dv NULL .
193The ID here is an OpenSSL-specific concept, which stores a prefix
194of 0x0300 in the higher two bytes and the IANA-specified cipher
195suite ID in the lower two bytes.
196For instance, TLS_RSA_WITH_NULL_MD5 has IANA ID "0x00, 0x01", so
197.Fn SSL_CIPHER_get_id
198returns 0x03000001.
199.Pp
200.Fn SSL_CIPHER_description
201copies a textual description of
202.Fa cipher
203into the buffer
204.Fa buf ,
205which must be at least
206.Fa size
207bytes long.
208The
209.Fa cipher
210argument must not be a
211.Dv NULL
212pointer.
213If
214.Fa buf
215is
216.Dv NULL ,
217a buffer is allocated using
218.Xr asprintf 3 ;
219that buffer should be freed using the
220.Xr free 3
221function.
222If
223.Fa len
224is too small to hold the description, a pointer to the static string
225.Qq Buffer too small
226is returned.
227If memory allocation fails, which can happen even if a
228.Fa buf
229of sufficient size is provided, a pointer to the static string
230.Qq OPENSSL_malloc Error
231is returned and the content of
232.Fa buf
233remains unchanged.
234.Pp
235The string returned by
236.Fn SSL_CIPHER_description
237consists of several fields separated by whitespace:
238.Bl -tag -width Ds
239.It Aq Ar ciphername
240Textual representation of the cipher name.
241.It Aq Ar protocol version
242Protocol version:
243.Sy SSLv3 ,
244.Sy TLSv1.2 ,
245or
246.Sy TLSv1.3 .
247The TLSv1.0 ciphers are flagged with SSLv3.
248No new ciphers were added by TLSv1.1.
249.It Kx= Ns Aq Ar key exchange
250Key exchange method:
251.Sy DH ,
252.Sy ECDH ,
253.Sy GOST ,
254.Sy RSA ,
255or
256.Sy TLSv1.3 .
257.It Au= Ns Aq Ar authentication
258Authentication method:
259.Sy ECDSA ,
260.Sy GOST01 ,
261.Sy RSA ,
262.Sy TLSv1.3 ,
263or
264.Sy None .
265.Sy None
266is the representation of anonymous ciphers.
267.It Enc= Ns Aq Ar symmetric encryption method
268Encryption method with number of secret bits:
269.Sy 3DES(168) ,
270.Sy RC4(128) ,
271.Sy AES(128) ,
272.Sy AES(256) ,
273.Sy AESGCM(128) ,
274.Sy AESGCM(256) ,
275.Sy Camellia(128) ,
276.Sy Camellia(256) ,
277.Sy ChaCha20-Poly1305 ,
278.Sy GOST-28178-89-CNT ,
279or
280.Sy None .
281.It Mac= Ns Aq Ar message authentication code
282Message digest:
283.Sy MD5 ,
284.Sy SHA1 ,
285.Sy SHA256 ,
286.Sy SHA384 ,
287.Sy AEAD ,
288.Sy GOST94 ,
289.Sy GOST89IMIT ,
290or
291.Sy STREEBOG256 .
292.El
293.Sh RETURN VALUES
294.Fn SSL_CIPHER_get_name
295returns an internal pointer to a NUL-terminated string.
296.Fn SSL_CIPHER_get_version
297returns a pointer to a static NUL-terminated string.
298If
299.Fa cipher
300is a
301.Dv NULL
302pointer, both functions return a pointer to the static string
303.Qq Pq NONE .
304.Pp
305.Fn SSL_CIPHER_get_bits
306returns a positive integer representing the number of secret bits
307or 0 if
308.Fa cipher
309is a
310.Dv NULL
311pointer.
312.Pp
313.Fn SSL_CIPHER_get_cipher_nid ,
314.Fn SSL_CIPHER_get_digest_nid ,
315.Fn SSL_CIPHER_get_kx_nid ,
316and
317.Fn SSL_CIPHER_get_auth_nid
318return an NID constant or
319.Dv NID_undef
320if an error occurred.
321.Fn SSL_CIPHER_get_handshake_digest
322returns a valid
323.Vt EVP_MD
324object or
325.Dv NULL
326if an error occurred.
327.Pp
328.Fn SSL_CIPHER_is_aead
329returns 1 if the
330.Fa cipher
331is AEAD or 0 otherwise.
332.Pp
333.Fn SSL_CIPHER_find
334returns a pointer to a valid
335.Vt SSL_CIPHER
336structure or
337.Dv NULL
338if an error occurred.
339.Pp
340.Fn SSL_CIPHER_get_id
341returns a 32-bit unsigned integer.
342.Pp
343.Fn SSL_CIPHER_description
344returns
345.Fa buf
346or a newly allocated string on success or a pointer to a static
347string on error.
348.Sh EXAMPLES
349An example for the output of
350.Fn SSL_CIPHER_description :
351.Bd -literal
352ECDHE-RSA-AES256-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
353.Ed
354.Pp
355A complete list can be retrieved by invoking the following command:
356.Pp
357.Dl $ openssl ciphers -v ALL:COMPLEMENTOFALL
358.Sh SEE ALSO
359.Xr openssl 1 ,
360.Xr ssl 3 ,
361.Xr SSL_get_ciphers 3 ,
362.Xr SSL_get_current_cipher 3
363.Sh HISTORY
364.Fn SSL_CIPHER_description
365first appeared in SSLeay 0.8.0.
366.Fn SSL_CIPHER_get_name ,
367.Fn SSL_CIPHER_get_bits ,
368and
369.Fn SSL_CIPHER_get_version
370first appeared in SSLeay 0.8.1.
371These functions have been available since
372.Ox 2.4 .
373.Pp
374.Fn SSL_CIPHER_get_id
375first appeared in OpenSSL 1.0.1 and has been available since
376.Ox 5.3 .
377.Pp
378.Fn SSL_CIPHER_get_cipher_nid ,
379.Fn SSL_CIPHER_get_digest_nid ,
380.Fn SSL_CIPHER_get_kx_nid ,
381.Fn SSL_CIPHER_get_auth_nid ,
382and
383.Fn SSL_CIPHER_is_aead
384first appeared in OpenSSL 1.1.0 and have been available since
385.Ox 6.3 .
386.Fn SSL_CIPHER_find
387first appeared in OpenSSL 1.1.0 and has been available since
388.Ox 7.0 .
389.Fn SSL_CIPHER_get_handshake_digest
390first appeared in OpenSSL 1.1.1 and has been available since
391.Ox 7.6 .
392.Sh BUGS
393If
394.Fn SSL_CIPHER_description
395cannot handle a built-in cipher,
396the according description of the cipher property is
397.Qq unknown .
398This case should not occur.
diff --git a/src/lib/libssl/man/SSL_COMP_add_compression_method.3 b/src/lib/libssl/man/SSL_COMP_add_compression_method.3
deleted file mode 100644
index f9e25358d7..0000000000
--- a/src/lib/libssl/man/SSL_COMP_add_compression_method.3
+++ /dev/null
@@ -1,42 +0,0 @@
1.\" $OpenBSD: SSL_COMP_add_compression_method.3,v 1.7 2024/08/31 10:51:48 tb Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: August 31 2024 $
18.Dt SSL_COMP_ADD_COMPRESSION_METHOD 3
19.Os
20.Sh NAME
21.Nm SSL_COMP_get_compression_methods
22.Nd handle SSL/TLS integrated compression methods
23.Sh SYNOPSIS
24.In openssl/ssl.h
25.Ft STACK_OF(SSL_COMP) *
26.Fn SSL_COMP_get_compression_methods void
27.Sh DESCRIPTION
28This function is deprecated and has no effect.
29It is provided purely for compatibility with legacy application code.
30.Pp
31.Fn SSL_COMP_get_compression_methods
32used to return a stack of available compression methods.
33.Sh RETURN VALUES
34.Fn SSL_COMP_get_compression_methods
35always returns
36.Dv NULL .
37.Sh SEE ALSO
38.Xr ssl 3
39.Sh HISTORY
40.Fn SSL_COMP_get_compression_methods
41first appeared in OpenSSL 0.9.8 and has been available since
42.Ox 4.5 .
diff --git a/src/lib/libssl/man/SSL_CTX_add1_chain_cert.3 b/src/lib/libssl/man/SSL_CTX_add1_chain_cert.3
deleted file mode 100644
index 86eb27a523..0000000000
--- a/src/lib/libssl/man/SSL_CTX_add1_chain_cert.3
+++ /dev/null
@@ -1,222 +0,0 @@
1.\" $OpenBSD: SSL_CTX_add1_chain_cert.3,v 1.2 2025/01/18 10:45:12 tb Exp $
2.\" selective merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>
5.\" and Rob Stradling <rob.stradling@comodo.com>.
6.\" Copyright (c) 2013 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: January 18 2025 $
53.Dt SSL_CTX_ADD1_CHAIN_CERT 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set0_chain ,
57.Nm SSL_CTX_set1_chain ,
58.Nm SSL_CTX_add0_chain_cert ,
59.Nm SSL_CTX_add1_chain_cert ,
60.Nm SSL_CTX_get0_chain_certs ,
61.Nm SSL_CTX_clear_chain_certs ,
62.Nm SSL_set0_chain ,
63.Nm SSL_set1_chain ,
64.Nm SSL_add0_chain_cert ,
65.Nm SSL_add1_chain_cert ,
66.Nm SSL_get0_chain_certs ,
67.Nm SSL_clear_chain_certs
68.Nd extra chain certificate processing
69.Sh SYNOPSIS
70.In openssl/ssl.h
71.Ft int
72.Fo SSL_CTX_set0_chain
73.Fa "SSL_CTX *ctx"
74.Fa "STACK_OF(X509) *chain"
75.Fc
76.Ft int
77.Fo SSL_CTX_set1_chain
78.Fa "SSL_CTX *ctx"
79.Fa "STACK_OF(X509) *chain"
80.Fc
81.Ft int
82.Fo SSL_CTX_add0_chain_cert
83.Fa "SSL_CTX *ctx"
84.Fa "X509 *cert"
85.Fc
86.Ft int
87.Fo SSL_CTX_add1_chain_cert
88.Fa "SSL_CTX *ctx"
89.Fa "X509 *cert"
90.Fc
91.Ft int
92.Fo SSL_CTX_get0_chain_certs
93.Fa "SSL_CTX *ctx"
94.Fa "STACK_OF(X509) **chain"
95.Fc
96.Ft int
97.Fo SSL_CTX_clear_chain_certs
98.Fa "SSL_CTX *ctx"
99.Fc
100.Ft int
101.Fo SSL_set0_chain
102.Fa "SSL *ssl"
103.Fa "STACK_OF(X509) *chain"
104.Fc
105.Ft int
106.Fo SSL_set1_chain
107.Fa "SSL *ssl"
108.Fa "STACK_OF(X509) *chain"
109.Fc
110.Ft int
111.Fo SSL_add0_chain_cert
112.Fa "SSL *ssl"
113.Fa "X509 *cert"
114.Fc
115.Ft int
116.Fo SSL_add1_chain_cert
117.Fa "SSL *ssl"
118.Fa "X509 *cert"
119.Fc
120.Ft int
121.Fo SSL_get0_chain_certs
122.Fa "SSL *ssl"
123.Fa "STACK_OF(X509) **chain"
124.Fc
125.Ft int
126.Fo SSL_clear_chain_certs
127.Fa "SSL *ssl"
128.Fc
129.Sh DESCRIPTION
130.Fn SSL_CTX_set0_chain
131and
132.Fn SSL_CTX_set1_chain
133set the certificate chain associated with the current certificate of
134.Fa ctx
135to
136.Fa chain .
137The
138.Fa chain
139is not supposed to include the current certificate itself.
140.Pp
141.Fn SSL_CTX_add0_chain_cert
142and
143.Fn SSL_CTX_add1_chain_cert
144append the single certificate
145.Fa cert
146to the chain associated with the current certificate of
147.Fa ctx .
148.Pp
149.Fn SSL_CTX_get0_chain_certs
150retrieves the chain associated with the current certificate of
151.Fa ctx .
152.Pp
153.Fn SSL_CTX_clear_chain_certs
154clears the existing chain associated with the current certificate of
155.Fa ctx ,
156if any.
157This is equivalent to calling
158.Fn SSL_CTX_set0_chain
159with
160.Fa chain
161set to
162.Dv NULL .
163.Pp
164Each of these functions operates on the
165.Em current
166end entity (i.e. server or client) certificate.
167This is the last certificate loaded or selected on the corresponding
168.Fa ctx
169structure, for example using
170.Xr SSL_CTX_use_certificate 3 .
171.Pp
172.Fn SSL_set0_chain ,
173.Fn SSL_set1_chain ,
174.Fn SSL_add0_chain_cert ,
175.Fn SSL_add1_chain_cert ,
176.Fn SSL_get0_chain_certs ,
177and
178.Fn SSL_clear_chain_certs
179are similar except that they operate on the
180.Fa ssl
181connection.
182.Pp
183The functions containing a
184.Sy 1
185in their name increment the reference count of the supplied certificate
186or chain, so it must be freed at some point after the operation.
187Those containing a
188.Sy 0
189do not increment reference counts and the supplied certificate or chain
190must not be freed after the operation.
191.Pp
192The chains associated with an
193.Vt SSL_CTX
194structure are copied to the new
195.Vt SSL
196structure when
197.Xr SSL_new 3
198is called.
199Existing
200.Vt SSL
201structures are not affected by any chains subsequently changed
202in the parent
203.Vt SSL_CTX .
204.Pp
205One chain can be set for each key type supported by a server.
206So, for example, an RSA and an ECDSA certificate can have
207different chains.
208.Pp
209If any certificates are added using these functions, no certificates
210added using
211.Xr SSL_CTX_add_extra_chain_cert 3
212will be used.
213.Sh RETURN VALUES
214These functions return 1 for success or 0 for failure.
215.Sh SEE ALSO
216.Xr ssl 3 ,
217.Xr SSL_CTX_add_extra_chain_cert 3 ,
218.Xr SSL_CTX_use_certificate 3
219.Sh HISTORY
220These functions first appeared in OpenSSL 1.0.2
221and have been available since
222.Ox 6.5 .
diff --git a/src/lib/libssl/man/SSL_CTX_add_extra_chain_cert.3 b/src/lib/libssl/man/SSL_CTX_add_extra_chain_cert.3
deleted file mode 100644
index b9694b0cbc..0000000000
--- a/src/lib/libssl/man/SSL_CTX_add_extra_chain_cert.3
+++ /dev/null
@@ -1,160 +0,0 @@
1.\" $OpenBSD: SSL_CTX_add_extra_chain_cert.3,v 1.8 2025/01/18 10:45:12 tb Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org> and
5.\" Dr. Stephen Henson <steve@openssl.org>.
6.\" Copyright (c) 2000, 2002, 2013, 2015 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: January 18 2025 $
54.Dt SSL_CTX_ADD_EXTRA_CHAIN_CERT 3
55.Os
56.Sh NAME
57.Nm SSL_CTX_add_extra_chain_cert ,
58.Nm SSL_CTX_get_extra_chain_certs_only ,
59.Nm SSL_CTX_get_extra_chain_certs ,
60.Nm SSL_CTX_clear_extra_chain_certs
61.Nd add, retrieve, and clear extra chain certificates
62.Sh SYNOPSIS
63.In openssl/ssl.h
64.Ft long
65.Fn SSL_CTX_add_extra_chain_cert "SSL_CTX *ctx" "X509 *x509"
66.Ft long
67.Fn SSL_CTX_get_extra_chain_certs_only "SSL_CTX *ctx" "STACK_OF(X509) **certs"
68.Ft long
69.Fn SSL_CTX_get_extra_chain_certs "SSL_CTX *ctx" "STACK_OF(X509) **certs"
70.Ft long
71.Fn SSL_CTX_clear_extra_chain_certs "SSL_CTX *ctx"
72.Sh DESCRIPTION
73.Fn SSL_CTX_add_extra_chain_cert
74adds the certificate
75.Fa x509
76to the extra chain certificates associated with
77.Fa ctx .
78Several certificates can be added one after another.
79.Pp
80.Fn SSL_CTX_get_extra_chain_certs_only
81retrieves an internal pointer to the stack of extra chain certificates
82associated with
83.Fa ctx ,
84or set
85.Pf * Fa certs
86to
87.Dv NULL
88if there are none.
89.Pp
90.Fn SSL_CTX_get_extra_chain_certs
91does the same except that it retrieves an internal pointer
92to the chain associated with the certificate
93if there are no extra chain certificates.
94.Pp
95.Fn SSL_CTX_clear_extra_chain_certs
96clears all extra chain certificates associated with
97.Fa ctx .
98.Pp
99These functions are implemented as macros.
100.Pp
101When sending a certificate chain, extra chain certificates are sent
102in order following the end entity certificate.
103.Pp
104If no chain is specified, the library will try to complete the chain from the
105available CA certificates in the trusted CA storage, see
106.Xr SSL_CTX_load_verify_locations 3 .
107.Pp
108The x509 certificate provided to
109.Fn SSL_CTX_add_extra_chain_cert
110will be freed by the library when the
111.Vt SSL_CTX
112is destroyed.
113An application should not free the
114.Fa x509
115object, nor the
116.Pf * Fa certs
117object retrieved by
118.Fn SSL_CTX_get_extra_chain_certs .
119.Sh RETURN VALUES
120These functions return 1 on success or 0 for failure.
121Check out the error stack to find out the reason for failure.
122.Sh SEE ALSO
123.Xr ssl 3 ,
124.Xr SSL_CTX_add1_chain_cert 3 ,
125.Xr SSL_CTX_ctrl 3 ,
126.Xr SSL_CTX_load_verify_locations 3 ,
127.Xr SSL_CTX_set_client_cert_cb 3 ,
128.Xr SSL_CTX_use_certificate 3
129.Sh HISTORY
130.Fn SSL_CTX_add_extra_chain_cert
131first appeared in SSLeay 0.9.1 and has been available since
132.Ox 2.6 .
133.Pp
134.Fn SSL_CTX_get_extra_chain_certs
135and
136.Fn SSL_CTX_clear_extra_chain_certs
137first appeared in OpenSSL 1.0.1 and have been available since
138.Ox 5.3 .
139.Pp
140.Fn SSL_CTX_get_extra_chain_certs_only
141first appeared in OpenSSL 1.0.2 and has been available since
142.Ox 6.7 .
143.Sh CAVEATS
144Certificates added with
145.Fn SSL_CTX_add_extra_chain_cert
146are ignored when certificates are also available that have been
147added using the functions documented in
148.Xr SSL_CTX_set1_chain 3 .
149.Pp
150Only one set of extra chain certificates can be specified per
151.Vt SSL_CTX
152structure using
153.Fn SSL_CTX_add_extra_chain_cert .
154Different chains for different certificates (for example if both
155RSA and ECDSA certificates are specified by the same server) or
156different SSL structures with the same parent
157.Vt SSL_CTX
158require using the functions documented in
159.Xr SSL_CTX_set1_chain 3
160instead.
diff --git a/src/lib/libssl/man/SSL_CTX_add_session.3 b/src/lib/libssl/man/SSL_CTX_add_session.3
deleted file mode 100644
index 443bdb542a..0000000000
--- a/src/lib/libssl/man/SSL_CTX_add_session.3
+++ /dev/null
@@ -1,132 +0,0 @@
1.\" $OpenBSD: SSL_CTX_add_session.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL SSL_CTX_add_session.pod 1722496f Jun 8 15:18:38 2017 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org> and
5.\" Geoff Thorpe <geoff@openssl.org>.
6.\" Copyright (c) 2001, 2002, 2014 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 27 2018 $
53.Dt SSL_CTX_ADD_SESSION 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_add_session ,
57.Nm SSL_CTX_remove_session
58.Nd manipulate session cache
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fn SSL_CTX_add_session "SSL_CTX *ctx" "SSL_SESSION *c"
63.Ft int
64.Fn SSL_CTX_remove_session "SSL_CTX *ctx" "SSL_SESSION *c"
65.Sh DESCRIPTION
66.Fn SSL_CTX_add_session
67adds the session
68.Fa c
69to the context
70.Fa ctx .
71The reference count for session
72.Fa c
73is incremented by 1.
74If a session with the same session id already exists,
75the old session is removed by calling
76.Xr SSL_SESSION_free 3 .
77.Pp
78.Fn SSL_CTX_remove_session
79removes the session
80.Fa c
81from the context
82.Fa ctx
83and marks it as non-resumable.
84.Xr SSL_SESSION_free 3
85is called once for
86.Fa c .
87.Pp
88When adding a new session to the internal session cache, it is examined
89whether a session with the same session id already exists.
90In this case it is assumed that both sessions are identical.
91If the same session is stored in a different
92.Vt SSL_SESSION
93object, the old session is removed and replaced by the new session.
94If the session is actually identical (the
95.Vt SSL_SESSION
96object is identical),
97.Fn SSL_CTX_add_session
98is a no-op, and the return value is 0.
99.Pp
100If a server
101.Vt SSL_CTX
102is configured with the
103.Dv SSL_SESS_CACHE_NO_INTERNAL_STORE
104flag then the internal cache will not be populated automatically by new
105sessions negotiated by the SSL/TLS implementation, even though the internal
106cache will be searched automatically for session-resume requests (the
107latter can be suppressed by
108.Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP ) .
109So the application can use
110.Fn SSL_CTX_add_session
111directly to have full control over the sessions that can be resumed if desired.
112.Sh RETURN VALUES
113The following values are returned by all functions:
114.Bl -tag -width Ds
115.It 0
116The operation failed.
117In case of the add operation, it was tried to add the same (identical) session
118twice.
119In case of the remove operation, the session was not found in the cache.
120.It 1
121The operation succeeded.
122.El
123.Sh SEE ALSO
124.Xr ssl 3 ,
125.Xr SSL_CTX_set_session_cache_mode 3 ,
126.Xr SSL_SESSION_free 3
127.Sh HISTORY
128.Fn SSL_CTX_add_session
129and
130.Fn SSL_CTX_remove_session
131first appeared in SSLeay 0.8.0 and have been available since
132.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_ctrl.3 b/src/lib/libssl/man/SSL_CTX_ctrl.3
deleted file mode 100644
index c91ddff374..0000000000
--- a/src/lib/libssl/man/SSL_CTX_ctrl.3
+++ /dev/null
@@ -1,122 +0,0 @@
1.\" $OpenBSD: SSL_CTX_ctrl.3,v 1.7 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_CTRL 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_ctrl ,
56.Nm SSL_CTX_callback_ctrl ,
57.Nm SSL_ctrl ,
58.Nm SSL_callback_ctrl
59.Nd internal handling functions for SSL_CTX and SSL objects
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft long
63.Fn SSL_CTX_ctrl "SSL_CTX *ctx" "int cmd" "long larg" "void *parg"
64.Ft long
65.Fn SSL_CTX_callback_ctrl "SSL_CTX *" "int cmd" "void (*fp)()"
66.Ft long
67.Fn SSL_ctrl "SSL *ssl" "int cmd" "long larg" "void *parg"
68.Ft long
69.Fn SSL_callback_ctrl "SSL *" "int cmd" "void (*fp)()"
70.Sh DESCRIPTION
71The
72.Fn SSL_*_ctrl
73family of functions is used to manipulate settings of
74the
75.Vt SSL_CTX
76and
77.Vt SSL
78objects.
79Depending on the command
80.Fa cmd
81the arguments
82.Fa larg ,
83.Fa parg ,
84or
85.Fa fp
86are evaluated.
87These functions should never be called directly.
88All functionalities needed are made available via other functions or macros.
89.Sh RETURN VALUES
90The return values of the
91.Fn SSL*_ctrl
92functions depend on the command supplied via the
93.Fn cmd
94parameter.
95.Sh SEE ALSO
96.Xr ssl 3 ,
97.Xr SSL_CTX_add_extra_chain_cert 3 ,
98.Xr SSL_CTX_sess_number 3 ,
99.Xr SSL_CTX_sess_set_cache_size 3 ,
100.Xr SSL_CTX_set_max_cert_list 3 ,
101.Xr SSL_CTX_set_mode 3 ,
102.Xr SSL_CTX_set_options 3 ,
103.Xr SSL_CTX_set_session_cache_mode 3 ,
104.Xr SSL_CTX_set_tlsext_servername_callback 3 ,
105.Xr SSL_CTX_set_tlsext_status_cb 3 ,
106.Xr SSL_CTX_set_tlsext_ticket_key_cb 3 ,
107.Xr SSL_get_server_tmp_key 3 ,
108.Xr SSL_num_renegotiations 3 ,
109.Xr SSL_session_reused 3 ,
110.Xr SSL_set_max_send_fragment 3
111.Sh HISTORY
112.Fn SSL_CTX_ctrl
113and
114.Fn SSL_ctrl
115first appeared in SSLeay 0.8.0 and have been available since
116.Ox 2.4 .
117.Pp
118.Fn SSL_CTX_callback_ctrl
119and
120.Fn SSL_callback_ctrl
121first appeared in OpenSSL 0.9.5 and have been available since
122.Ox 2.7 .
diff --git a/src/lib/libssl/man/SSL_CTX_flush_sessions.3 b/src/lib/libssl/man/SSL_CTX_flush_sessions.3
deleted file mode 100644
index 2ef781cb4a..0000000000
--- a/src/lib/libssl/man/SSL_CTX_flush_sessions.3
+++ /dev/null
@@ -1,100 +0,0 @@
1.\" $OpenBSD: SSL_CTX_flush_sessions.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL SSL_CTX_flush_sessions.pod 1722496f Jun 8 15:18:38 2017 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_FLUSH_SESSIONS 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_flush_sessions
56.Nd remove expired sessions
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft void
60.Fn SSL_CTX_flush_sessions "SSL_CTX *ctx" "long tm"
61.Sh DESCRIPTION
62.Fn SSL_CTX_flush_sessions
63causes a run through the session cache of
64.Fa ctx
65to remove sessions expired at time
66.Fa tm .
67.Pp
68If enabled, the internal session cache will collect all sessions established
69up to the specified maximum number (see
70.Xr SSL_CTX_sess_set_cache_size 3 ) .
71As sessions will not be reused once they are expired, they should be
72removed from the cache to save resources.
73This can either be done automatically whenever 255 new sessions were
74established (see
75.Xr SSL_CTX_set_session_cache_mode 3 )
76or manually by calling
77.Fn SSL_CTX_flush_sessions .
78.Pp
79The parameter
80.Fa tm
81specifies the time which should be used for the
82expiration test, in most cases the actual time given by
83.Fn time 0
84will be used.
85.Pp
86.Fn SSL_CTX_flush_sessions
87will only check sessions stored in the internal cache.
88When a session is found and removed, the
89.Va remove_session_cb
90is however called to synchronize with the external cache (see
91.Xr SSL_CTX_sess_set_get_cb 3 ) .
92.Sh SEE ALSO
93.Xr ssl 3 ,
94.Xr SSL_CTX_sess_set_get_cb 3 ,
95.Xr SSL_CTX_set_session_cache_mode 3 ,
96.Xr SSL_CTX_set_timeout 3
97.Sh HISTORY
98.Fn SSL_CTX_flush_sessions
99first appeared in SSLeay 0.8.0 and has been available since
100.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_free.3 b/src/lib/libssl/man/SSL_CTX_free.3
deleted file mode 100644
index 47f247631b..0000000000
--- a/src/lib/libssl/man/SSL_CTX_free.3
+++ /dev/null
@@ -1,101 +0,0 @@
1.\" $OpenBSD: SSL_CTX_free.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2003 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_FREE 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_free
56.Nd free an allocated SSL_CTX object
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft void
60.Fn SSL_CTX_free "SSL_CTX *ctx"
61.Sh DESCRIPTION
62.Fn SSL_CTX_free
63decrements the reference count of
64.Fa ctx ,
65and removes the
66.Vt SSL_CTX
67object pointed to by
68.Fa ctx
69and frees up the allocated memory if the reference count has reached 0.
70If
71.Fa ctx
72is a
73.Dv NULL
74pointer, no action occurs.
75.Pp
76It also calls the
77.Xr free 3 Ns ing
78procedures for indirectly affected items, if applicable:
79the session cache, the list of ciphers, the list of Client CAs,
80the certificates and keys.
81.Sh WARNINGS
82If a session-remove callback is set
83.Pq Xr SSL_CTX_sess_set_remove_cb 3 ,
84this callback will be called for each session being freed from
85.Fa ctx Ns 's
86session cache.
87This implies that all corresponding sessions from an external session cache are
88removed as well.
89If this is not desired, the user should explicitly unset the callback by
90calling
91.Fn SSL_CTX_sess_set_remove_cb ctx NULL
92prior to calling
93.Fn SSL_CTX_free .
94.Sh SEE ALSO
95.Xr ssl 3 ,
96.Xr SSL_CTX_new 3 ,
97.Xr SSL_CTX_sess_set_get_cb 3
98.Sh HISTORY
99.Fn SSL_CTX_free
100first appeared in SSLeay 0.5.1 and has been available since
101.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_get0_certificate.3 b/src/lib/libssl/man/SSL_CTX_get0_certificate.3
deleted file mode 100644
index 63c86bd5e0..0000000000
--- a/src/lib/libssl/man/SSL_CTX_get0_certificate.3
+++ /dev/null
@@ -1,51 +0,0 @@
1.\" $OpenBSD: SSL_CTX_get0_certificate.3,v 1.3 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2018 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_CTX_GET0_CERTIFICATE 3
19.Os
20.Sh NAME
21.Nm SSL_CTX_get0_certificate
22.Nd get the active certificate from an SSL context
23.Sh SYNOPSIS
24.Ft X509 *
25.Fo SSL_CTX_get0_certificate
26.Fa "const SSL_CTX *ctx"
27.Fc
28.Sh DESCRIPTION
29The
30.Fn SSL_CTX_get0_certificate
31function returns an internal pointer
32to the ASN.1 certificate currently active in
33.Fa ctx
34or
35.Dv NULL
36if none was installed with
37.Xr SSL_CTX_use_certificate 3
38or similar functions.
39.Pp
40The returned pointer must not be freed by the caller.
41.Sh SEE ALSO
42.Xr ssl 3 ,
43.Xr SSL_CTX_new 3 ,
44.Xr SSL_CTX_use_certificate 3 ,
45.Xr X509_get_pubkey 3 ,
46.Xr X509_get_subject_name 3 ,
47.Xr X509_new 3
48.Sh HISTORY
49.Fn SSL_CTX_get0_certificate
50first appeared in OpenSSL 1.0.2 and have been available since
51.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_CTX_get_ex_new_index.3 b/src/lib/libssl/man/SSL_CTX_get_ex_new_index.3
deleted file mode 100644
index 3dbaf2e981..0000000000
--- a/src/lib/libssl/man/SSL_CTX_get_ex_new_index.3
+++ /dev/null
@@ -1,124 +0,0 @@
1.\" $OpenBSD: SSL_CTX_get_ex_new_index.3,v 1.3 2018/03/21 08:06:34 schwarze Exp $
2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 21 2018 $
52.Dt SSL_CTX_GET_EX_NEW_INDEX 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_get_ex_new_index ,
56.Nm SSL_CTX_set_ex_data ,
57.Nm SSL_CTX_get_ex_data
58.Nd internal application specific data functions
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fo SSL_CTX_get_ex_new_index
63.Fa "long argl"
64.Fa "void *argp"
65.Fa "CRYPTO_EX_new *new_func"
66.Fa "CRYPTO_EX_dup *dup_func"
67.Fa "CRYPTO_EX_free *free_func"
68.Fc
69.Ft int
70.Fn SSL_CTX_set_ex_data "SSL_CTX *ctx" "int idx" "void *arg"
71.Ft void *
72.Fn SSL_CTX_get_ex_data "const SSL_CTX *ctx" "int idx"
73.Bd -literal
74 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
75 int idx, long argl, void *argp);
76 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
77 int idx, long argl, void *argp);
78 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
79 int idx, long argl, void *argp);
80.Ed
81.Sh DESCRIPTION
82Several OpenSSL structures can have application specific data attached to them.
83These functions are used internally by OpenSSL to manipulate application
84specific data attached to a specific structure.
85.Pp
86.Fn SSL_CTX_get_ex_new_index
87is used to register a new index for application specific data.
88.Pp
89.Fn SSL_CTX_set_ex_data
90is used to store application data at
91.Fa arg
92for
93.Fa idx
94into the
95.Fa ctx
96object.
97.Pp
98.Fn SSL_CTX_get_ex_data
99is used to retrieve the information for
100.Fa idx
101from
102.Fa ctx .
103.Pp
104A detailed description for the
105.Fn *_get_ex_new_index
106functionality can be found in
107.Xr RSA_get_ex_new_index 3 .
108The
109.Fn *_get_ex_data
110and
111.Fn *_set_ex_data
112functionality is described in
113.Xr CRYPTO_set_ex_data 3 .
114.Sh SEE ALSO
115.Xr CRYPTO_set_ex_data 3 ,
116.Xr RSA_get_ex_new_index 3 ,
117.Xr ssl 3
118.Sh HISTORY
119.Fn SSL_CTX_get_ex_new_index ,
120.Fn SSL_CTX_set_ex_data ,
121and
122.Fn SSL_CTX_get_ex_data
123first appeared in SSLeay 0.9.0 and have been available since
124.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_get_verify_mode.3 b/src/lib/libssl/man/SSL_CTX_get_verify_mode.3
deleted file mode 100644
index 7c87775069..0000000000
--- a/src/lib/libssl/man/SSL_CTX_get_verify_mode.3
+++ /dev/null
@@ -1,131 +0,0 @@
1.\" $OpenBSD: SSL_CTX_get_verify_mode.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_GET_VERIFY_MODE 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_get_verify_mode ,
56.Nm SSL_get_verify_mode ,
57.Nm SSL_CTX_get_verify_depth ,
58.Nm SSL_get_verify_depth ,
59.Nm SSL_get_verify_callback ,
60.Nm SSL_CTX_get_verify_callback
61.Nd get currently set verification parameters
62.Sh SYNOPSIS
63.In openssl/ssl.h
64.Ft int
65.Fn SSL_CTX_get_verify_mode "const SSL_CTX *ctx"
66.Ft int
67.Fn SSL_get_verify_mode "const SSL *ssl"
68.Ft int
69.Fn SSL_CTX_get_verify_depth "const SSL_CTX *ctx"
70.Ft int
71.Fn SSL_get_verify_depth "const SSL *ssl"
72.Ft int
73.Fo "(*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))"
74.Fa int "X509_STORE_CTX *"
75.Fc
76.Ft int
77.Fo "(*SSL_get_verify_callback(const SSL *ssl))"
78.Fa int "X509_STORE_CTX *"
79.Fc
80.Sh DESCRIPTION
81.Fn SSL_CTX_get_verify_mode
82returns the verification mode currently set in
83.Fa ctx .
84.Pp
85.Fn SSL_get_verify_mode
86returns the verification mode currently set in
87.Fa ssl .
88.Pp
89.Fn SSL_CTX_get_verify_depth
90returns the verification depth limit currently set
91in
92.Fa ctx .
93If no limit has been explicitly set,
94\(mi1 is returned and the default value will be used.
95.Pp
96.Fn SSL_get_verify_depth
97returns the verification depth limit currently set in
98.Fa ssl .
99If no limit has been explicitly set,
100\(mi1 is returned and the default value will be used.
101.Pp
102.Fn SSL_CTX_get_verify_callback
103returns a function pointer to the verification callback currently set in
104.Fa ctx .
105If no callback was explicitly set, the
106.Dv NULL
107pointer is returned and the default callback will be used.
108.Pp
109.Fn SSL_get_verify_callback
110returns a function pointer to the verification callback currently set in
111.Fa ssl .
112If no callback was explicitly set, the
113.Dv NULL
114pointer is returned and the default callback will be used.
115.Sh SEE ALSO
116.Xr ssl 3 ,
117.Xr SSL_CTX_set_verify 3
118.Sh HISTORY
119.Fn SSL_CTX_get_verify_mode ,
120.Fn SSL_get_verify_mode ,
121.Fn SSL_get_verify_callback ,
122and
123.Fn SSL_CTX_get_verify_callback
124first appeared in SSLeay 0.8.0 and have been available since
125.Ox 2.4 .
126.Pp
127.Fn SSL_CTX_get_verify_depth
128and
129.Fn SSL_get_verify_depth
130first appeared in OpenSSL 0.9.3 and have been available since
131.Ox 2.6 .
diff --git a/src/lib/libssl/man/SSL_CTX_load_verify_locations.3 b/src/lib/libssl/man/SSL_CTX_load_verify_locations.3
deleted file mode 100644
index 373df2402e..0000000000
--- a/src/lib/libssl/man/SSL_CTX_load_verify_locations.3
+++ /dev/null
@@ -1,238 +0,0 @@
1.\" $OpenBSD: SSL_CTX_load_verify_locations.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2015, 2016 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 27 2018 $
53.Dt SSL_CTX_LOAD_VERIFY_LOCATIONS 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_load_verify_locations ,
57.Nm SSL_CTX_set_default_verify_paths
58.Nd set default locations for trusted CA certificates
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fo SSL_CTX_load_verify_locations
63.Fa "SSL_CTX *ctx" "const char *CAfile" "const char *CApath"
64.Fc
65.Ft int
66.Fo SSL_CTX_set_default_verify_paths
67.Fa "SSL_CTX *ctx"
68.Fc
69.Sh DESCRIPTION
70.Fn SSL_CTX_load_verify_locations
71specifies the locations for
72.Fa ctx ,
73at which CA certificates for verification purposes are located.
74The certificates available via
75.Fa CAfile
76and
77.Fa CApath
78are trusted.
79.Pp
80.Fn SSL_CTX_set_default_verify_paths
81specifies that the default locations from which CA certificates are
82loaded should be used.
83There is one default directory and one default file.
84The default CA certificates directory is called
85.Pa certs
86in the default OpenSSL directory.
87The default CA certificates file is called
88.Pa cert.pem
89in the default OpenSSL directory.
90.Pp
91If
92.Fa CAfile
93is not
94.Dv NULL ,
95it points to a file of CA certificates in PEM format.
96The file can contain several CA certificates identified by sequences of:
97.Bd -literal
98 -----BEGIN CERTIFICATE-----
99 ... (CA certificate in base64 encoding) ...
100 -----END CERTIFICATE-----
101.Ed
102.Pp
103Before, between, and after the certificates arbitrary text is allowed which can
104be used, e.g., for descriptions of the certificates.
105.Pp
106The
107.Fa CAfile
108is processed on execution of the
109.Fn SSL_CTX_load_verify_locations
110function.
111.Pp
112If
113.Fa CApath
114is not NULL, it points to a directory containing CA certificates in PEM format.
115The files each contain one CA certificate.
116The files are looked up by the CA subject name hash value,
117which must hence be available.
118If more than one CA certificate with the same name hash value exist,
119the extension must be different (e.g.,
120.Pa 9d66eef0.0 ,
121.Pa 9d66eef0.1 ,
122etc.).
123The search is performed in the ordering of the extension number,
124regardless of other properties of the certificates.
125.Pp
126The certificates in
127.Fa CApath
128are only looked up when required, e.g., when building the certificate chain or
129when actually performing the verification of a peer certificate.
130.Pp
131When looking up CA certificates, the OpenSSL library will first search the
132certificates in
133.Fa CAfile ,
134then those in
135.Fa CApath .
136Certificate matching is done based on the subject name, the key identifier (if
137present), and the serial number as taken from the certificate to be verified.
138If these data do not match, the next certificate will be tried.
139If a first certificate matching the parameters is found,
140the verification process will be performed;
141no other certificates for the same parameters will be searched in case of
142failure.
143.Pp
144In server mode, when requesting a client certificate, the server must send
145the list of CAs of which it will accept client certificates.
146This list is not influenced by the contents of
147.Fa CAfile
148or
149.Fa CApath
150and must explicitly be set using the
151.Xr SSL_CTX_set_client_CA_list 3
152family of functions.
153.Pp
154When building its own certificate chain, an OpenSSL client/server will try to
155fill in missing certificates from
156.Fa CAfile Ns / Fa CApath ,
157if the
158certificate chain was not explicitly specified (see
159.Xr SSL_CTX_add_extra_chain_cert 3
160and
161.Xr SSL_CTX_use_certificate 3 ) .
162.Sh RETURN VALUES
163For
164.Fn SSL_CTX_load_verify_locations ,
165the following return values can occur:
166.Bl -tag -width Ds
167.It 0
168The operation failed because
169.Fa CAfile
170and
171.Fa CApath
172are
173.Dv NULL
174or the processing at one of the locations specified failed.
175Check the error stack to find out the reason.
176.It 1
177The operation succeeded.
178.El
179.Pp
180.Fn SSL_CTX_set_default_verify_paths
181returns 1 on success or 0 on failure.
182A missing default location is still treated as a success.
183.Sh EXAMPLES
184Generate a CA certificate file with descriptive text from the CA certificates
185.Pa ca1.pem
186.Pa ca2.pem
187.Pa ca3.pem :
188.Bd -literal
189#!/bin/sh
190rm CAfile.pem
191for i in ca1.pem ca2.pem ca3.pem; do
192 openssl x509 -in $i -text >> CAfile.pem
193done
194.Ed
195.Pp
196Prepare the directory /some/where/certs containing several CA certificates
197for use as
198.Fa CApath :
199.Bd -literal
200$ cd /some/where/certs
201$ rm -f *.[0-9]* *.r[0-9]*
202$ for c in *.pem; do
203> [ "$c" = "*.pem" ] && continue
204> hash=$(openssl x509 -noout -hash -in "$c")
205> if egrep -q -- '-BEGIN( X509 | TRUSTED | )CERTIFICATE-' "$c"; then
206> suf=0
207> while [ -e $hash.$suf ]; do suf=$(( $suf + 1 )); done
208> ln -s "$c" $hash.$suf
209> fi
210> if egrep -q -- '-BEGIN X509 CRL-' "$c"; then
211> suf=0
212> while [ -e $hash.r$suf ]; do suf=$(( $suf + 1 )); done
213> ln -s "$c" $hash.r$suf
214> fi
215> done
216.Ed
217.Sh SEE ALSO
218.Xr ssl 3 ,
219.Xr SSL_CTX_add_extra_chain_cert 3 ,
220.Xr SSL_CTX_set_cert_store 3 ,
221.Xr SSL_CTX_set_client_CA_list 3 ,
222.Xr SSL_CTX_use_certificate 3 ,
223.Xr SSL_get_client_CA_list 3
224.Sh HISTORY
225.Fn SSL_CTX_load_verify_locations
226and
227.Fn SSL_CTX_set_default_verify_paths
228first appeared in SSLeay 0.8.0 and have been available since
229.Ox 2.4 .
230.Sh CAVEATS
231If several CA certificates matching the name, key identifier, and serial
232number condition are available, only the first one will be examined.
233This may lead to unexpected results if the same CA certificate is available
234with different expiration dates.
235If a
236.Dq certificate expired
237verification error occurs, no other certificate will be searched.
238Make sure to not have expired certificates mixed with valid ones.
diff --git a/src/lib/libssl/man/SSL_CTX_new.3 b/src/lib/libssl/man/SSL_CTX_new.3
deleted file mode 100644
index 4b50a03de4..0000000000
--- a/src/lib/libssl/man/SSL_CTX_new.3
+++ /dev/null
@@ -1,345 +0,0 @@
1.\" $OpenBSD: SSL_CTX_new.3,v 1.17 2022/07/13 22:05:53 schwarze Exp $
2.\" full merge up to: OpenSSL 21cd6e00 Oct 21 14:40:15 2015 +0100
3.\" selective merge up to: OpenSSL 8f75443f May 24 14:04:26 2019 +0200
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
6.\" Copyright (c) 2000, 2005, 2012, 2013, 2015, 2016 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: July 13 2022 $
54.Dt SSL_CTX_NEW 3
55.Os
56.Sh NAME
57.Nm SSL_CTX_new ,
58.Nm SSL_CTX_up_ref ,
59.Nm TLS_method ,
60.Nm TLS_server_method ,
61.Nm TLS_client_method ,
62.Nm SSLv23_method ,
63.Nm SSLv23_server_method ,
64.Nm SSLv23_client_method ,
65.Nm TLSv1_method ,
66.Nm TLSv1_server_method ,
67.Nm TLSv1_client_method ,
68.Nm TLSv1_1_method ,
69.Nm TLSv1_1_server_method ,
70.Nm TLSv1_1_client_method ,
71.Nm TLSv1_2_method ,
72.Nm TLSv1_2_server_method ,
73.Nm TLSv1_2_client_method ,
74.Nm DTLS_method ,
75.Nm DTLS_server_method ,
76.Nm DTLS_client_method ,
77.Nm DTLSv1_method ,
78.Nm DTLSv1_server_method ,
79.Nm DTLSv1_client_method ,
80.Nm DTLSv1_2_method ,
81.Nm DTLSv1_2_server_method ,
82.Nm DTLSv1_2_client_method
83.Nd create a new SSL_CTX object as a framework for TLS enabled functions
84.Sh SYNOPSIS
85.In openssl/ssl.h
86.Ft SSL_CTX *
87.Fn SSL_CTX_new "const SSL_METHOD *method"
88.Ft int
89.Fn SSL_CTX_up_ref "SSL_CTX *ctx"
90.Ft const SSL_METHOD *
91.Fn TLS_method void
92.Ft const SSL_METHOD *
93.Fn TLS_server_method void
94.Ft const SSL_METHOD *
95.Fn TLS_client_method void
96.Ft const SSL_METHOD *
97.Fn SSLv23_method void
98.Ft const SSL_METHOD *
99.Fn SSLv23_server_method void
100.Ft const SSL_METHOD *
101.Fn SSLv23_client_method void
102.Ft const SSL_METHOD *
103.Fn TLSv1_method void
104.Ft const SSL_METHOD *
105.Fn TLSv1_server_method void
106.Ft const SSL_METHOD *
107.Fn TLSv1_client_method void
108.Ft const SSL_METHOD *
109.Fn TLSv1_1_method void
110.Ft const SSL_METHOD *
111.Fn TLSv1_1_server_method void
112.Ft const SSL_METHOD *
113.Fn TLSv1_1_client_method void
114.Ft const SSL_METHOD *
115.Fn TLSv1_2_method void
116.Ft const SSL_METHOD *
117.Fn TLSv1_2_server_method void
118.Ft const SSL_METHOD *
119.Fn TLSv1_2_client_method void
120.Ft const SSL_METHOD *
121.Fn DTLS_method void
122.Ft const SSL_METHOD *
123.Fn DTLS_server_method void
124.Ft const SSL_METHOD *
125.Fn DTLS_client_method void
126.Ft const SSL_METHOD *
127.Fn DTLSv1_method void
128.Ft const SSL_METHOD *
129.Fn DTLSv1_server_method void
130.Ft const SSL_METHOD *
131.Fn DTLSv1_client_method void
132.Ft const SSL_METHOD *
133.Fn DTLSv1_2_method void
134.Ft const SSL_METHOD *
135.Fn DTLSv1_2_server_method void
136.Ft const SSL_METHOD *
137.Fn DTLSv1_2_client_method void
138.Sh DESCRIPTION
139.Fn SSL_CTX_new
140creates a new
141.Vt SSL_CTX
142object as a framework to establish TLS or DTLS enabled connections.
143It initializes the list of ciphers, the session cache setting, the
144callbacks, the keys and certificates, the options, and the security
145level to its default values.
146.Pp
147An
148.Vt SSL_CTX
149object is reference counted.
150Creating a new
151.Vt SSL_CTX
152object sets its reference count to 1.
153Calling
154.Fn SSL_CTX_up_ref
155on it increments the reference count by 1.
156Calling
157.Xr SSL_CTX_free 3
158on it decrements the reference count by 1.
159When the reference count drops to zero,
160any memory or resources allocated to the
161.Vt SSL_CTX
162object are freed.
163.Pp
164The
165.Vt SSL_CTX
166object uses
167.Fa method
168as its connection method, which can be:
169.Bl -tag -width Ds
170.It Fn TLS_method
171The general-purpose version-flexible TLS method.
172The protocol version used will be negotiated to the highest
173version mutually supported by the client and the server.
174The supported protocols are TLSv1, TLSv1.1, TLSv1.2, and TLSv1.3.
175.It Fn DTLS_method
176The version-flexible DTLS method.
177The currently supported protocols are DTLSv1 and DTLSv1.2.
178.El
179.Pp
180The following
181.Fa method
182arguments are deprecated:
183.Bl -tag -width Ds
184.It Xo
185.Fn TLS_server_method ,
186.Fn TLS_client_method ,
187.Fn SSLv23_method ,
188.Fn SSLv23_server_method ,
189.Fn SSLv23_client_method
190.Xc
191Deprecated aliases for
192.Fn TLS_method .
193.It Xo
194.Fn DTLS_server_method ,
195.Fn DTLS_client_method
196.Xc
197Deprecated aliases for
198.Fn DTLS_method .
199.It Xo
200.Fn TLSv1_method ,
201.Fn TLSv1_server_method ,
202.Fn TLSv1_client_method
203.Xc
204A connection established with these methods will only
205understand the TLSv1 protocol.
206.It Xo
207.Fn TLSv1_1_method ,
208.Fn TLSv1_1_server_method ,
209.Fn TLSv1_1_client_method
210.Xc
211A connection established with these methods will only
212understand the TLSv1.1 protocol.
213.It Xo
214.Fn TLSv1_2_method ,
215.Fn TLSv1_2_server_method ,
216.Fn TLSv1_2_client_method
217.Xc
218A connection established with these methods will only
219understand the TLSv1.2 protocol.
220.It Xo
221.Fn DTLSv1_method ,
222.Fn DTLSv1_server_method ,
223.Fn DTLSv1_client_method
224.Xc
225These are the version-specific methods for DTLSv1.
226.It Xo
227.Fn DTLSv1_2_method ,
228.Fn DTLSv1_2_server_method ,
229.Fn DTLSv1_2_client_method
230These are the version-specific methods for DTLSv1.2.
231.Xc
232.El
233.Pp
234In LibreSSL, the methods containing the substrings
235.Dq _server
236or
237.Dq _client
238in their names return the same objects
239as the methods without these substrings.
240.Pp
241The list of protocols available can also be limited using the
242.Dv SSL_OP_NO_TLSv1 ,
243.Dv SSL_OP_NO_TLSv1_1 ,
244and
245.Dv SSL_OP_NO_TLSv1_2
246options of the
247.Xr SSL_CTX_set_options 3
248or
249.Xr SSL_set_options 3
250functions, but this approach is not recommended.
251Clients should avoid creating "holes" in the set of protocols they support.
252When disabling a protocol, make sure that you also disable either
253all previous or all subsequent protocol versions.
254In clients, when a protocol version is disabled without disabling
255all previous protocol versions, the effect is to also disable all
256subsequent protocol versions.
257.Pp
258DTLSv1 and DTLSv1.2 can be disabled with
259.Xr SSL_CTX_set_options 3
260or
261.Xr SSL_set_options 3
262using the
263.Dv SSL_OP_NO_DTLSv1
264and
265.Dv SSL_OP_NO_DTLSv1_2
266options, respectively.
267.Sh RETURN VALUES
268.Fn SSL_CTX_new
269returns a pointer to the newly allocated object or
270.Dv NULL
271on failure.
272Check the error stack to find out the reason for failure.
273.Pp
274.Fn SSL_CTX_up_ref
275returns 1 for success or 0 for failure.
276.Pp
277.Fn TLS_method
278and the other
279.Fn *_method
280functions return pointers to constant static objects.
281.Sh SEE ALSO
282.Xr ssl 3 ,
283.Xr SSL_accept 3 ,
284.Xr SSL_CTX_free 3 ,
285.Xr SSL_CTX_set_min_proto_version 3 ,
286.Xr SSL_CTX_set_options 3 ,
287.Xr SSL_CTX_set_security_level 3 ,
288.Xr SSL_set_connect_state 3
289.Sh HISTORY
290.Fn SSL_CTX_new
291first appeared in SSLeay 0.5.1.
292.Fn SSLv23_method ,
293.Fn SSLv23_server_method ,
294and
295.Fn SSLv23_client_method
296first appeared in SSLeay 0.8.0.
297.Fn TLSv1_method ,
298.Fn TLSv1_server_method ,
299and
300.Fn TLSv1_client_method
301first appeared in SSLeay 0.9.0.
302All these functions have been available since
303.Ox 2.4 .
304.Pp
305.Fn DTLSv1_method ,
306.Fn DTLSv1_server_method ,
307and
308.Fn DTLSv1_client_method
309first appeared in OpenSSL 0.9.8 and have been available since
310.Ox 4.5 .
311.Pp
312.Fn TLSv1_1_method ,
313.Fn TLSv1_1_server_method ,
314.Fn TLSv1_1_client_method ,
315.Fn TLSv1_2_method ,
316.Fn TLSv1_2_server_method ,
317and
318.Fn TLSv1_2_client_method
319first appeared in OpenSSL 1.0.1 and have been available since
320.Ox 5.3 .
321.Pp
322.Fn DTLS_method ,
323.Fn DTLS_server_method ,
324and
325.Fn DTLS_client_method
326first appeared in OpenSSL 1.0.2 and have been available since
327.Ox 6.5 .
328.Pp
329.Fn TLS_method ,
330.Fn TLS_server_method ,
331and
332.Fn TLS_client_method
333first appeared in OpenSSL 1.1.0 and have been available since
334.Ox 5.8 .
335.Pp
336.Fn SSL_CTX_up_ref
337first appeared in OpenSSL 1.1.0 and has been available since
338.Ox 6.3 .
339.Pp
340.Fn DTLSv1_2_method ,
341.Fn DTLSv1_2_server_method ,
342and
343.Fn DTLSv1_2_client_method
344first appeared in OpenSSL 1.1.0 and have been available since
345.Ox 6.9 .
diff --git a/src/lib/libssl/man/SSL_CTX_sess_number.3 b/src/lib/libssl/man/SSL_CTX_sess_number.3
deleted file mode 100644
index 76d436cd17..0000000000
--- a/src/lib/libssl/man/SSL_CTX_sess_number.3
+++ /dev/null
@@ -1,168 +0,0 @@
1.\" $OpenBSD: SSL_CTX_sess_number.3,v 1.9 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL SSL_CTX_sess_number.pod 7bd27895 Mar 29 11:45:29 2017 +1000
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 12 2019 $
52.Dt SSL_CTX_SESS_NUMBER 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_sess_number ,
56.Nm SSL_CTX_sess_connect ,
57.Nm SSL_CTX_sess_connect_good ,
58.Nm SSL_CTX_sess_connect_renegotiate ,
59.Nm SSL_CTX_sess_accept ,
60.Nm SSL_CTX_sess_accept_good ,
61.Nm SSL_CTX_sess_accept_renegotiate ,
62.Nm SSL_CTX_sess_hits ,
63.Nm SSL_CTX_sess_cb_hits ,
64.Nm SSL_CTX_sess_misses ,
65.Nm SSL_CTX_sess_timeouts ,
66.Nm SSL_CTX_sess_cache_full
67.Nd obtain session cache statistics
68.Sh SYNOPSIS
69.In openssl/ssl.h
70.Ft long
71.Fn SSL_CTX_sess_number "SSL_CTX *ctx"
72.Ft long
73.Fn SSL_CTX_sess_connect "SSL_CTX *ctx"
74.Ft long
75.Fn SSL_CTX_sess_connect_good "SSL_CTX *ctx"
76.Ft long
77.Fn SSL_CTX_sess_connect_renegotiate "SSL_CTX *ctx"
78.Ft long
79.Fn SSL_CTX_sess_accept "SSL_CTX *ctx"
80.Ft long
81.Fn SSL_CTX_sess_accept_good "SSL_CTX *ctx"
82.Ft long
83.Fn SSL_CTX_sess_accept_renegotiate "SSL_CTX *ctx"
84.Ft long
85.Fn SSL_CTX_sess_hits "SSL_CTX *ctx"
86.Ft long
87.Fn SSL_CTX_sess_cb_hits "SSL_CTX *ctx"
88.Ft long
89.Fn SSL_CTX_sess_misses "SSL_CTX *ctx"
90.Ft long
91.Fn SSL_CTX_sess_timeouts "SSL_CTX *ctx"
92.Ft long
93.Fn SSL_CTX_sess_cache_full "SSL_CTX *ctx"
94.Sh DESCRIPTION
95.Fn SSL_CTX_sess_number
96returns the current number of sessions in the internal session cache.
97.Pp
98.Fn SSL_CTX_sess_connect
99returns the number of started SSL/TLS handshakes in client mode.
100.Pp
101.Fn SSL_CTX_sess_connect_good
102returns the number of successfully established SSL/TLS sessions in client mode.
103.Pp
104.Fn SSL_CTX_sess_connect_renegotiate
105returns the number of started renegotiations in client mode.
106.Pp
107.Fn SSL_CTX_sess_accept
108returns the number of started SSL/TLS handshakes in server mode.
109.Pp
110.Fn SSL_CTX_sess_accept_good
111returns the number of successfully established SSL/TLS sessions in server mode.
112.Pp
113.Fn SSL_CTX_sess_accept_renegotiate
114returns the number of started renegotiations in server mode.
115.Pp
116.Fn SSL_CTX_sess_hits
117returns the number of successfully reused sessions.
118In client mode a session set with
119.Xr SSL_set_session 3
120successfully reused is counted as a hit.
121In server mode a session successfully retrieved from internal or external cache
122is counted as a hit.
123.Pp
124.Fn SSL_CTX_sess_cb_hits
125returns the number of successfully retrieved sessions from the external session
126cache in server mode.
127.Pp
128.Fn SSL_CTX_sess_misses
129returns the number of sessions proposed by clients that were not found in the
130internal session cache in server mode.
131.Pp
132.Fn SSL_CTX_sess_timeouts
133returns the number of sessions proposed by clients and either found in the
134internal or external session cache in server mode,
135but that were invalid due to timeout.
136These sessions are not included in the
137.Fn SSL_CTX_sess_hits
138count.
139.Pp
140.Fn SSL_CTX_sess_cache_full
141returns the number of sessions that were removed because the maximum session
142cache size was exceeded.
143.Sh SEE ALSO
144.Xr ssl 3 ,
145.Xr SSL_CTX_ctrl 3 ,
146.Xr SSL_CTX_sess_set_cache_size 3 ,
147.Xr SSL_CTX_set_session_cache_mode 3 ,
148.Xr SSL_set_session 3
149.Sh HISTORY
150.Fn SSL_CTX_sess_number ,
151.Fn SSL_CTX_sess_connect ,
152.Fn SSL_CTX_sess_connect_good ,
153.Fn SSL_CTX_sess_accept ,
154.Fn SSL_CTX_sess_accept_good ,
155.Fn SSL_CTX_sess_hits ,
156.Fn SSL_CTX_sess_misses ,
157and
158.Fn SSL_CTX_sess_timeouts
159first appeared in SSLeay 0.5.2.
160.Fn SSL_CTX_sess_cb_hits
161first appeared in SSLeay 0.6.0.
162.Fn SSL_CTX_sess_connect_renegotiate ,
163.Fn SSL_CTX_sess_accept_renegotiate ,
164and
165.Fn SSL_CTX_sess_cache_full
166first appeared in SSLeay 0.9.0.
167All these functions have been available since
168.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_sess_set_cache_size.3 b/src/lib/libssl/man/SSL_CTX_sess_set_cache_size.3
deleted file mode 100644
index 6d5fede0b6..0000000000
--- a/src/lib/libssl/man/SSL_CTX_sess_set_cache_size.3
+++ /dev/null
@@ -1,109 +0,0 @@
1.\" $OpenBSD: SSL_CTX_sess_set_cache_size.3,v 1.5 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2002, 2014 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 12 2019 $
52.Dt SSL_CTX_SESS_SET_CACHE_SIZE 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_sess_set_cache_size ,
56.Nm SSL_CTX_sess_get_cache_size
57.Nd manipulate session cache size
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft long
61.Fn SSL_CTX_sess_set_cache_size "SSL_CTX *ctx" "long t"
62.Ft long
63.Fn SSL_CTX_sess_get_cache_size "SSL_CTX *ctx"
64.Sh DESCRIPTION
65.Fn SSL_CTX_sess_set_cache_size
66sets the size of the internal session cache of context
67.Fa ctx
68to
69.Fa t .
70.Pp
71.Fn SSL_CTX_sess_get_cache_size
72returns the currently valid session cache size.
73.Pp
74The internal session cache size is
75.Dv SSL_SESSION_CACHE_MAX_SIZE_DEFAULT ,
76currently 1024\(mu20, so that up to 20000 sessions can be held.
77This size can be modified using the
78.Fn SSL_CTX_sess_set_cache_size
79call.
80A special case is the size 0, which is used for unlimited size.
81.Pp
82If adding the session makes the cache exceed its size, then unused
83sessions are dropped from the end of the cache.
84Cache space may also be reclaimed by calling
85.Xr SSL_CTX_flush_sessions 3
86to remove expired sessions.
87.Pp
88If the size of the session cache is reduced and more sessions are already in
89the session cache,
90old session will be removed the next time a session shall be added.
91This removal is not synchronized with the expiration of sessions.
92.Sh RETURN VALUES
93.Fn SSL_CTX_sess_set_cache_size
94returns the previously valid size.
95.Pp
96.Fn SSL_CTX_sess_get_cache_size
97returns the currently valid size.
98.Sh SEE ALSO
99.Xr ssl 3 ,
100.Xr SSL_CTX_ctrl 3 ,
101.Xr SSL_CTX_flush_sessions 3 ,
102.Xr SSL_CTX_sess_number 3 ,
103.Xr SSL_CTX_set_session_cache_mode 3
104.Sh HISTORY
105.Fn SSL_CTX_sess_set_cache_size
106and
107.Fn SSL_CTX_sess_get_cache_size
108first appeared in SSLeay 0.9.0 and have been available since
109.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_sess_set_get_cb.3 b/src/lib/libssl/man/SSL_CTX_sess_set_get_cb.3
deleted file mode 100644
index e99f2be671..0000000000
--- a/src/lib/libssl/man/SSL_CTX_sess_set_get_cb.3
+++ /dev/null
@@ -1,221 +0,0 @@
1.\" $OpenBSD: SSL_CTX_sess_set_get_cb.3,v 1.7 2022/03/29 18:15:52 naddy Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2002, 2003, 2016 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 29 2022 $
53.Dt SSL_CTX_SESS_SET_GET_CB 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_sess_set_new_cb ,
57.Nm SSL_CTX_sess_set_remove_cb ,
58.Nm SSL_CTX_sess_set_get_cb ,
59.Nm SSL_CTX_sess_get_new_cb ,
60.Nm SSL_CTX_sess_get_remove_cb ,
61.Nm SSL_CTX_sess_get_get_cb
62.Nd provide callback functions for server side external session caching
63.Sh SYNOPSIS
64.In openssl/ssl.h
65.Ft void
66.Fo SSL_CTX_sess_set_new_cb
67.Fa "SSL_CTX *ctx"
68.Fa "int (*new_session_cb)(SSL *, SSL_SESSION *)"
69.Fc
70.Ft void
71.Fo SSL_CTX_sess_set_remove_cb
72.Fa "SSL_CTX *ctx"
73.Fa "void (*remove_session_cb)(SSL_CTX *ctx, SSL_SESSION *)"
74.Fc
75.Ft void
76.Fo SSL_CTX_sess_set_get_cb
77.Fa "SSL_CTX *ctx"
78.Fa "SSL_SESSION (*get_session_cb)(SSL *, const unsigned char *, int, int *)"
79.Fc
80.Ft int
81.Fo "(*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))"
82.Fa "SSL *ssl"
83.Fa "SSL_SESSION *sess"
84.Fc
85.Ft void
86.Fo "(*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))"
87.Fa "SSL_CTX *ctx"
88.Fa "SSL_SESSION *sess"
89.Fc
90.Ft SSL_SESSION *
91.Fo "(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))"
92.Fa "SSL *ssl"
93.Fa "const unsigned char *data"
94.Fa "int len"
95.Fa "int *copy"
96.Fc
97.Ft int
98.Fo "(*new_session_cb)"
99.Fa "SSL *ssl"
100.Fa "SSL_SESSION *sess"
101.Fc
102.Ft void
103.Fo "(*remove_session_cb)"
104.Fa "SSL_CTX *ctx"
105.Fa "SSL_SESSION *sess"
106.Fc
107.Ft SSL_SESSION *
108.Fo "(*get_session_cb)"
109.Fa "SSL *ssl"
110.Fa "unsigned char *data"
111.Fa "int len"
112.Fa "int *copy"
113.Fc
114.Sh DESCRIPTION
115.Fn SSL_CTX_sess_set_new_cb
116sets the callback function which is automatically called whenever a new session
117was negotiated.
118.Pp
119.Fn SSL_CTX_sess_set_remove_cb
120sets the callback function which is automatically called whenever a session is
121removed by the SSL engine (because it is considered faulty or the session has
122become obsolete because of exceeding the timeout value).
123.Pp
124.Fn SSL_CTX_sess_set_get_cb
125sets the callback function which is called whenever a SSL/TLS client proposes
126to resume a session but the session cannot be found in the internal session
127cache (see
128.Xr SSL_CTX_set_session_cache_mode 3 ) .
129(SSL/TLS server only.)
130.Pp
131.Fn SSL_CTX_sess_get_new_cb ,
132.Fn SSL_CTX_sess_get_remove_cb ,
133and
134.Fn SSL_CTX_sess_get_get_cb
135retrieve the function pointers of the provided callback functions.
136If a callback function has not been set, the
137.Dv NULL
138pointer is returned.
139.Pp
140In order to allow external session caching, synchronization with the internal
141session cache is realized via callback functions.
142Inside these callback functions, session can be saved to disk or put into a
143database using the
144.Xr d2i_SSL_SESSION 3
145interface.
146.Pp
147The
148.Fn new_session_cb
149function is called whenever a new session has been negotiated and session
150caching is enabled (see
151.Xr SSL_CTX_set_session_cache_mode 3 ) .
152The
153.Fn new_session_cb
154function is passed the
155.Fa ssl
156connection and the ssl session
157.Fa sess .
158If the callback returns 0, the session will be immediately removed again.
159.Pp
160The
161.Fn remove_session_cb
162function is called whenever the SSL engine removes a session from the
163internal cache.
164This happens when the session is removed because it is expired or when a
165connection was not shut down cleanly.
166It also happens for all sessions in the internal session cache when
167.Xr SSL_CTX_free 3
168is called.
169The
170.Fn remove_session_cb
171function is passed the
172.Fa ctx
173and the
174.Vt ssl
175session
176.Fa sess .
177It does not provide any feedback.
178.Pp
179The
180.Fn get_session_cb
181function is only called on SSL/TLS servers with the session id proposed by the
182client.
183The
184.Fn get_session_cb
185function is always called, also when session caching was disabled.
186The
187.Fn get_session_cb
188function is passed the
189.Fa ssl
190connection, the session id of length
191.Fa length
192at the memory location
193.Fa data .
194With the parameter
195.Fa copy
196the callback can require the SSL engine to increment the reference count of the
197.Vt SSL_SESSION
198object,
199Normally the reference count is not incremented and therefore the session must
200not be explicitly freed with
201.Xr SSL_SESSION_free 3 .
202.Sh SEE ALSO
203.Xr d2i_SSL_SESSION 3 ,
204.Xr ssl 3 ,
205.Xr SSL_CTX_flush_sessions 3 ,
206.Xr SSL_CTX_free 3 ,
207.Xr SSL_CTX_set_session_cache_mode 3 ,
208.Xr SSL_SESSION_free 3
209.Sh HISTORY
210.Fn SSL_CTX_sess_set_new_cb ,
211.Fn SSL_CTX_sess_set_get_cb ,
212.Fn SSL_CTX_sess_get_new_cb ,
213and
214.Fn SSL_CTX_sess_get_get_cb
215first appeared in SSLeay 0.6.0.
216.Fn SSL_CTX_sess_set_remove_cb
217and
218.Fn SSL_CTX_sess_get_remove_cb
219first appeared in SSLeay 0.8.0.
220These functions have been available since
221.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_sessions.3 b/src/lib/libssl/man/SSL_CTX_sessions.3
deleted file mode 100644
index 964d1a7346..0000000000
--- a/src/lib/libssl/man/SSL_CTX_sessions.3
+++ /dev/null
@@ -1,86 +0,0 @@
1.\" $OpenBSD: SSL_CTX_sessions.3,v 1.5 2018/04/25 14:19:39 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: April 25 2018 $
52.Dt SSL_CTX_SESSIONS 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_sessions
56.Nd access internal session cache
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft LHASH_OF(SSL_SESSION) *
60.Fn SSL_CTX_sessions "SSL_CTX *ctx"
61.Sh DESCRIPTION
62.Fn SSL_CTX_sessions
63returns a pointer to the lhash databases containing the internal session cache
64for
65.Fa ctx .
66.Pp
67The sessions in the internal session cache are kept in an
68lhash-type database
69(see
70.Xr lh_new 3 ) .
71It is possible to directly access this database, e.g., for searching.
72In parallel,
73the sessions form a linked list which is maintained separately from the
74lhash operations,
75so that the database must not be modified directly but by using the
76.Xr SSL_CTX_add_session 3
77family of functions.
78.Sh SEE ALSO
79.Xr lh_new 3 ,
80.Xr ssl 3 ,
81.Xr SSL_CTX_add_session 3 ,
82.Xr SSL_CTX_set_session_cache_mode 3
83.Sh HISTORY
84.Fn SSL_CTX_sessions
85first appeared in SSLeay 0.5.2 and has been available since
86.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_set1_groups.3 b/src/lib/libssl/man/SSL_CTX_set1_groups.3
deleted file mode 100644
index 0d1eb36ea7..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set1_groups.3
+++ /dev/null
@@ -1,163 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set1_groups.3,v 1.2 2017/08/19 19:36:39 schwarze Exp $
2.\" OpenSSL SSL_CTX_set1_curves.pod de4d764e Nov 9 14:51:06 2016 +0000
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2013, 2014, 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: August 19 2017 $
52.Dt SSL_CTX_SET1_GROUPS 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set1_groups ,
56.Nm SSL_CTX_set1_groups_list ,
57.Nm SSL_set1_groups ,
58.Nm SSL_set1_groups_list ,
59.Nm SSL_CTX_set1_curves ,
60.Nm SSL_CTX_set1_curves_list ,
61.Nm SSL_set1_curves ,
62.Nm SSL_set1_curves_list
63.Nd choose supported EC groups
64.Sh SYNOPSIS
65.In openssl/ssl.h
66.Ft int
67.Fo SSL_CTX_set1_groups
68.Fa "SSL_CTX *ctx"
69.Fa "const int *glist"
70.Fa "size_t glistlen"
71.Fc
72.Ft int
73.Fo SSL_CTX_set1_groups_list
74.Fa "SSL_CTX *ctx"
75.Fa "const char *list"
76.Fc
77.Ft int
78.Fo SSL_set1_groups
79.Fa "SSL *ssl"
80.Fa "const int *glist"
81.Fa "size_t glistlen"
82.Fc
83.Ft int
84.Fo SSL_set1_groups_list
85.Fa "SSL *ssl"
86.Fa "const char *list"
87.Fc
88.Ft int
89.Fo SSL_CTX_set1_curves
90.Fa "SSL_CTX *ctx"
91.Fa "const int *clist"
92.Fa "size_t clistlen"
93.Fc
94.Ft int
95.Fo SSL_CTX_set1_curves_list
96.Fa "SSL_CTX *ctx"
97.Fa "const char *list"
98.Fc
99.Ft int
100.Fo SSL_set1_curves
101.Fa "SSL *ssl"
102.Fa "const int *clist"
103.Fa "size_t clistlen"
104.Fc
105.Ft int
106.Fo SSL_set1_curves_list
107.Fa "SSL *ssl"
108.Fa "const char *list"
109.Fc
110.Sh DESCRIPTION
111.Fn SSL_CTX_set1_groups
112sets the supported groups for
113.Fa ctx
114to the
115.Fa glistlen
116groups in the array
117.Fa glist .
118The array consists of group NIDs in preference order.
119For a TLS client, the groups are used directly in the supported groups
120extension.
121For a TLS server, the groups are used to determine the set of shared
122groups.
123.Pp
124.Fn SSL_CTX_set1_groups_list
125sets the supported groups for
126.Fa ctx
127to the
128.Fa list
129represented as a colon separated list of group NIDs or names, for example
130"P-521:P-384:P-256".
131.Pp
132.Fn SSL_set1_groups
133and
134.Fn SSL_set1_groups_list
135are similar except that they set supported groups for the SSL structure
136.Fa ssl
137only.
138.Pp
139The curve functions are deprecated synonyms for the equivalently
140named group functions and are identical in every respect except
141that they are implemented as macros.
142They exist because prior to TLS1.3, there was only the concept of
143supported curves.
144In TLS1.3, this was renamed to supported groups and extended to include
145Diffie Hellman groups.
146.Pp
147If an application wishes to make use of several of these functions for
148configuration purposes either on a command line or in a file, it should
149consider using the SSL_CONF interface instead of manually parsing
150options.
151.Sh RETURN VALUES
152All these functions return 1 for success or 0 for failure.
153.Sh SEE ALSO
154.Xr ssl 3 ,
155.Xr SSL_CTX_add_extra_chain_cert 3 ,
156.Xr SSL_CTX_set_cipher_list 3 ,
157.Xr SSL_CTX_set_options 3 ,
158.Xr SSL_new 3
159.Sh HISTORY
160The curve functions first appeared in OpenSSL 1.0.2
161and the group functions in OpenSSL 1.1.1.
162Both have been available since
163.Ox 6.1 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3 b/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3
deleted file mode 100644
index 2317c57af4..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_alpn_select_cb.3
+++ /dev/null
@@ -1,305 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_alpn_select_cb.3,v 1.11 2025/02/04 14:00:05 tb Exp $
2.\" OpenSSL 87b81496 Apr 19 12:38:27 2017 -0400
3.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
4.\"
5.\" This file was written by Todd Short <tshort@akamai.com>.
6.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: February 4 2025 $
53.Dt SSL_CTX_SET_ALPN_SELECT_CB 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_alpn_protos ,
57.Nm SSL_set_alpn_protos ,
58.Nm SSL_CTX_set_alpn_select_cb ,
59.Nm SSL_select_next_proto ,
60.Nm SSL_get0_alpn_selected
61.Nd handle application layer protocol negotiation (ALPN)
62.Sh SYNOPSIS
63.In openssl/ssl.h
64.Ft int
65.Fo SSL_CTX_set_alpn_protos
66.Fa "SSL_CTX *ctx"
67.Fa "const unsigned char *protos"
68.Fa "unsigned int protos_len"
69.Fc
70.Ft int
71.Fo SSL_set_alpn_protos
72.Fa "SSL *ssl"
73.Fa "const unsigned char *protos"
74.Fa "unsigned int protos_len"
75.Fc
76.Ft void
77.Fo SSL_CTX_set_alpn_select_cb
78.Fa "SSL_CTX *ctx"
79.Fa "int (*cb)(SSL *ssl, const unsigned char **out,\
80 unsigned char *outlen, const unsigned char *in,\
81 unsigned int inlen, void *arg)"
82.Fa "void *arg"
83.Fc
84.Ft int
85.Fo SSL_select_next_proto
86.Fa "unsigned char **out"
87.Fa "unsigned char *outlen"
88.Fa "const unsigned char *peer_list"
89.Fa "unsigned int peer_list_len"
90.Fa "const unsigned char *supported_list"
91.Fa "unsigned int supported_list_len"
92.Fc
93.Ft void
94.Fo SSL_get0_alpn_selected
95.Fa "const SSL *ssl"
96.Fa "const unsigned char **data"
97.Fa "unsigned int *len"
98.Fc
99.Sh DESCRIPTION
100.Fn SSL_CTX_set_alpn_protos
101and
102.Fn SSL_set_alpn_protos
103are used by the client to set the list of protocols available to be
104negotiated.
105The
106.Fa protos
107must be in protocol-list format, described below.
108The length of
109.Fa protos
110is specified in
111.Fa protos_len .
112.Pp
113.Fn SSL_CTX_set_alpn_select_cb
114sets the application callback
115.Fa cb
116used by a server to select which protocol to use for the incoming
117connection.
118When
119.Fa cb
120is
121.Dv NULL ,
122ALPN is not used.
123The
124.Fa arg
125value is a pointer which is passed to the application callback.
126.Pp
127.Fa cb
128is the application defined callback.
129The
130.Fa in ,
131.Fa inlen
132parameters are a vector in protocol-list format.
133The value of the
134.Fa out ,
135.Fa outlen
136vector should be set to the value of a single protocol selected from the
137.Fa in ,
138.Fa inlen
139vector.
140The
141.Fa out
142buffer may point directly into
143.Fa in ,
144or to a buffer that outlives the handshake.
145The
146.Fa arg
147parameter is the pointer set via
148.Fn SSL_CTX_set_alpn_select_cb .
149.Pp
150.Fn SSL_select_next_proto
151is a helper function used to select protocols.
152It is expected that this function is called from the application
153callback
154.Fa cb .
155If
156.Fn SSL_select_next_proto
157returns
158.Dv OPENSSL_NPN_NO_OVERLAP ,
159.Fa cb
160should ignore
161.Fa out
162and fail by returning
163.Dv SSL_TLSEXT_ERR_ALERT_FATAL .
164The protocol data in
165.Fa peer_list ,
166.Fa peer_list_len
167and
168.Fa supported_list ,
169.Fa supported_list_len
170must be two non-empty lists, validly encoded
171in the protocol-list format described below.
172The first item in the
173.Fa peer_list
174that matches an item in the
175.Fa supported_list
176is selected, and returned in
177.Fa out ,
178.Fa outlen .
179The
180.Fa out
181value will point into either
182.Fa peer_list
183or
184.Fa supported_list ,
185so it must not be modified and
186should be copied immediately.
187If no match is found, the first item in
188.Fa supported_list
189is returned in
190.Fa out ,
191.Fa outlen .
192.Pp
193.Fn SSL_get0_alpn_selected
194returns a pointer to the selected protocol in
195.Fa data
196with length
197.Fa len .
198It is not NUL-terminated.
199.Fa data
200is set to
201.Dv NULL
202and
203.Fa len
204is set to 0 if no protocol has been selected.
205.Fa data
206must not be freed.
207.Pp
208The protocol-lists must be in wire-format, which is defined as a vector
209of non-empty, 8-bit length-prefixed byte strings.
210The length-prefix byte is not included in the length.
211Each string is limited to 255 bytes.
212A byte-string length of 0 is invalid.
213The length of the vector is not in the vector itself, but in a separate
214variable.
215.Pp
216For example:
217.Bd -literal
218const unsigned char *vector = "\ex06" "spdy/1" "\ex08" "http/1.1";
219unsigned int length = strlen(vector);
220.Ed
221.Pp
222The ALPN callback is executed after the servername callback; as that
223servername callback may update the SSL_CTX, and subsequently, the ALPN
224callback.
225.Pp
226If there is no ALPN proposed in the ClientHello, the ALPN callback is
227not invoked.
228.Sh RETURN VALUES
229.Fn SSL_CTX_set_alpn_protos
230and
231.Fn SSL_set_alpn_protos
232return 0 on success or non-zero on failure.
233WARNING: these functions reverse the return value convention.
234.Pp
235.Fn SSL_select_next_proto
236returns one of the following:
237.Bl -tag -width Ds
238.It OPENSSL_NPN_NEGOTIATED
239A match was found and is returned in
240.Fa out ,
241.Fa outlen .
242.It OPENSSL_NPN_NO_OVERLAP
243No match was found.
244The first item in
245.Fa supported_list ,
246.Fa supported_list_len
247is returned in
248.Fa out ,
249.Fa outlen .
250.El
251.Pp
252The ALPN select callback
253.Fa cb
254must return one of the following:
255.Bl -tag -width Ds
256.It SSL_TLSEXT_ERR_OK
257ALPN protocol selected.
258.It SSL_TLSEXT_ERR_ALERT_FATAL
259There was no overlap between the client's supplied list and the
260server configuration.
261.It SSL_TLSEXT_ERR_NOACK
262ALPN protocol not selected, e.g., because no ALPN protocols are
263configured for this connection.
264.El
265.Sh SEE ALSO
266.Xr ssl 3 ,
267.Xr SSL_CTX_set_tlsext_servername_arg 3 ,
268.Xr SSL_CTX_set_tlsext_servername_callback 3
269.Sh STANDARDS
270.Rs
271.%T TLS Application-Layer Protocol Negotiation Extension
272.%R RFC 7301
273.Re
274.Pp
275.Rs
276.%T TLS Next Protocol Negotiation Extension
277.%U https://datatracker.ietf.org/doc/html/draft-agl-tls-nextprotoneg
278.Re
279.Sh HISTORY
280.Fn SSL_select_next_proto
281first appeared in OpenSSL 1.0.1 and has been available since
282.Ox 5.3 .
283.Pp
284.Fn SSL_CTX_set_alpn_protos ,
285.Fn SSL_set_alpn_protos ,
286.Fn SSL_CTX_set_alpn_select_cb ,
287and
288.Fn SSL_get0_alpn_selected
289first appeared in OpenSSL 1.0.2 and have been available since
290.Ox 5.7 .
291.Sh CAVEATS
292The fallback to the first supported protocol in
293.Fn SSL_select_next_proto
294comes from the opportunistic fallback mechanism in the NPN extension.
295This behavior does not make sense for ALPN,
296where missing protocol overlap should result in a handshake failure.
297To avoid accidental selection of a protocol that the server does not
298support, it is recommended to pass the locally configured protocols
299as second pair of protocols in the ALPN callback.
300.Sh BUGS
301The
302.Fa out
303argument of
304.Fn SSL_select_next_proto
305should have been const.
diff --git a/src/lib/libssl/man/SSL_CTX_set_cert_store.3 b/src/lib/libssl/man/SSL_CTX_set_cert_store.3
deleted file mode 100644
index 1be1ba2f68..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_cert_store.3
+++ /dev/null
@@ -1,146 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_cert_store.3,v 1.8 2024/08/03 04:53:01 tb Exp $
2.\" OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2002, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: August 3 2024 $
52.Dt SSL_CTX_SET_CERT_STORE 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_cert_store ,
56.Nm SSL_CTX_set1_cert_store ,
57.Nm SSL_CTX_get_cert_store
58.Nd manipulate X509 certificate verification storage
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft void
62.Fn SSL_CTX_set_cert_store "SSL_CTX *ctx" "X509_STORE *store"
63.Ft void
64.Fn SSL_CTX_set1_cert_store "SSL_CTX *ctx" "X509_STORE *store"
65.Ft X509_STORE *
66.Fn SSL_CTX_get_cert_store "const SSL_CTX *ctx"
67.Sh DESCRIPTION
68.Fn SSL_CTX_set_cert_store
69sets the verification storage of
70.Fa ctx
71to or replaces it with
72.Fa store .
73If another
74.Vt X509_STORE
75object is currently set in
76.Fa ctx ,
77it will be freed.
78.Pp
79.Fn SSL_CTX_set1_cert_store
80sets the verification storage of
81.Fa ctx
82to or replaces it with
83.Fa store .
84The
85.Fa store Ns 's
86reference count is incremented.
87.Pp
88.Fn SSL_CTX_get_cert_store
89returns a pointer to the current certificate verification storage.
90.Pp
91In order to verify the certificates presented by the peer, trusted CA
92certificates must be accessed.
93These CA certificates are made available via lookup methods, handled inside the
94.Vt X509_STORE .
95From the
96.Vt X509_STORE
97the
98.Vt X509_STORE_CTX
99used when verifying certificates is created.
100.Pp
101Typically the trusted certificate store is handled indirectly via using
102.Xr SSL_CTX_load_verify_locations 3 .
103Using the
104.Fn SSL_CTX_set_cert_store
105and
106.Fn SSL_CTX_get_cert_store
107functions it is possible to manipulate the
108.Vt X509_STORE
109object beyond the
110.Xr SSL_CTX_load_verify_locations 3
111call.
112.Pp
113Currently no detailed documentation on how to use the
114.Vt X509_STORE
115object is available.
116Not all members of the
117.Vt X509_STORE
118are used when the verification takes place.
119So will, for example, the
120.Fn verify_callback
121be overridden with the
122.Fn verify_callback
123set via the
124.Xr SSL_CTX_set_verify 3
125family of functions.
126This document must therefore be updated when documentation about the
127.Vt X509_STORE
128object and its handling becomes available.
129.Sh RETURN VALUES
130.Fn SSL_CTX_get_cert_store
131returns the current setting.
132.Sh SEE ALSO
133.Xr ssl 3 ,
134.Xr SSL_CTX_load_verify_locations 3 ,
135.Xr SSL_CTX_set_verify 3 ,
136.Xr X509_STORE_new 3
137.Sh HISTORY
138.Fn SSL_CTX_set_cert_store
139and
140.Fn SSL_CTX_get_cert_store
141first appeared in SSLeay 0.8.1 and have been available since
142.Ox 2.4 .
143.Pp
144.Fn SSL_CTX_set1_cert_store
145first appeared in OpenSSL 1.1.1 and has been available since
146.Ox 7.6 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_cert_verify_callback.3 b/src/lib/libssl/man/SSL_CTX_set_cert_verify_callback.3
deleted file mode 100644
index 0e12b48c78..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_cert_verify_callback.3
+++ /dev/null
@@ -1,163 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_cert_verify_callback.3,v 1.5 2019/06/08 15:25:43 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2002 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 8 2019 $
52.Dt SSL_CTX_SET_CERT_VERIFY_CALLBACK 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_cert_verify_callback
56.Nd set peer certificate verification procedure
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft void
60.Fo SSL_CTX_set_cert_verify_callback
61.Fa "SSL_CTX *ctx"
62.Fa "int (*callback)(X509_STORE_CTX *, void *)"
63.Fa "void *arg"
64.Fc
65.Sh DESCRIPTION
66.Fn SSL_CTX_set_cert_verify_callback
67sets the verification callback function for
68.Fa ctx .
69.Vt SSL
70objects that are created from
71.Fa ctx
72inherit the setting valid at the time when
73.Xr SSL_new 3
74is called.
75.Pp
76Whenever a certificate is verified during a SSL/TLS handshake,
77a verification function is called.
78If the application does not explicitly specify a verification callback
79function, the built-in verification function is used.
80If a verification callback
81.Fa callback
82is specified via
83.Fn SSL_CTX_set_cert_verify_callback ,
84the supplied callback function is called instead.
85By setting
86.Fa callback
87to
88.Dv NULL ,
89the default behaviour is restored.
90.Pp
91When the verification must be performed,
92.Fa callback
93will be called with the arguments
94.Fn callback "X509_STORE_CTX *x509_store_ctx" "void *arg" .
95The argument
96.Fa arg
97is specified by the application when setting
98.Fa callback .
99.Pp
100.Fa callback
101should return 1 to indicate verification success and 0 to indicate verification
102failure.
103If
104.Dv SSL_VERIFY_PEER
105is set and
106.Fa callback
107returns 0, the handshake will fail.
108As the verification procedure may allow the connection to continue in case of
109failure (by always returning 1) the verification result must be set in any case
110using the
111.Fa error
112member of
113.Fa x509_store_ctx
114so that the calling application will be informed about the detailed result of
115the verification procedure!
116.Pp
117Within
118.Fa x509_store_ctx ,
119.Fa callback
120has access to the
121.Fa verify_callback
122function set using
123.Xr SSL_CTX_set_verify 3 .
124.Sh SEE ALSO
125.Xr ssl 3 ,
126.Xr SSL_CTX_load_verify_locations 3 ,
127.Xr SSL_CTX_set_verify 3 ,
128.Xr SSL_get_verify_result 3
129.Sh HISTORY
130.Fn SSL_CTX_set_cert_verify_callback
131first appeared in SSLeay 0.6.1 and has been available since
132.Ox 2.4 .
133.Pp
134Previous to OpenSSL 0.9.7, the
135.Fa arg
136argument to
137.Fn SSL_CTX_set_cert_verify_callback
138was ignored, and
139.Fa callback
140was called
141simply as
142.Ft int
143.Fn (*callback) "X509_STORE_CTX *" .
144To compile software written for previous versions of OpenSSL,
145a dummy argument will have to be added to
146.Fa callback .
147.Sh CAVEATS
148Do not mix the verification callback described in this function with the
149.Fa verify_callback
150function called during the verification process.
151The latter is set using the
152.Xr SSL_CTX_set_verify 3
153family of functions.
154.Pp
155Providing a complete verification procedure including certificate purpose
156settings, etc., is a complex task.
157The built-in procedure is quite powerful and in most cases it should be
158sufficient to modify its behaviour using the
159.Fa verify_callback
160function.
161.Sh BUGS
162.Fn SSL_CTX_set_cert_verify_callback
163does not provide diagnostic information.
diff --git a/src/lib/libssl/man/SSL_CTX_set_cipher_list.3 b/src/lib/libssl/man/SSL_CTX_set_cipher_list.3
deleted file mode 100644
index b3f0dc3541..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_cipher_list.3
+++ /dev/null
@@ -1,375 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_cipher_list.3,v 1.18 2025/01/18 12:20:02 tb Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2018, 2020 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" Permission to use, copy, modify, and distribute this software for any
10.\" purpose with or without fee is hereby granted, provided that the above
11.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" The original file was written by Lutz Jaenicke <jaenicke@openssl.org>.
22.\" Copyright (c) 2000, 2001, 2013 The OpenSSL Project. All rights reserved.
23.\"
24.\" Redistribution and use in source and binary forms, with or without
25.\" modification, are permitted provided that the following conditions
26.\" are met:
27.\"
28.\" 1. Redistributions of source code must retain the above copyright
29.\" notice, this list of conditions and the following disclaimer.
30.\"
31.\" 2. Redistributions in binary form must reproduce the above copyright
32.\" notice, this list of conditions and the following disclaimer in
33.\" the documentation and/or other materials provided with the
34.\" distribution.
35.\"
36.\" 3. All advertising materials mentioning features or use of this
37.\" software must display the following acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40.\"
41.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42.\" endorse or promote products derived from this software without
43.\" prior written permission. For written permission, please contact
44.\" openssl-core@openssl.org.
45.\"
46.\" 5. Products derived from this software may not be called "OpenSSL"
47.\" nor may "OpenSSL" appear in their names without prior written
48.\" permission of the OpenSSL Project.
49.\"
50.\" 6. Redistributions of any form whatsoever must retain the following
51.\" acknowledgment:
52.\" "This product includes software developed by the OpenSSL Project
53.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54.\"
55.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66.\" OF THE POSSIBILITY OF SUCH DAMAGE.
67.\"
68.Dd $Mdocdate: January 18 2025 $
69.Dt SSL_CTX_SET_CIPHER_LIST 3
70.Os
71.Sh NAME
72.Nm SSL_CTX_set_cipher_list ,
73.Nm SSL_set_cipher_list
74.Nd choose list of available SSL_CIPHERs
75.Sh SYNOPSIS
76.In openssl/ssl.h
77.Ft int
78.Fn SSL_CTX_set_cipher_list "SSL_CTX *ctx" "const char *control"
79.Ft int
80.Fn SSL_set_cipher_list "SSL *ssl" "const char *control"
81.Sh DESCRIPTION
82.Fn SSL_CTX_set_cipher_list
83sets the list of available cipher suites for
84.Fa ctx
85using the
86.Fa control
87string.
88The list of cipher suites is inherited by all
89.Fa ssl
90objects created from
91.Fa ctx .
92.Pp
93.Fn SSL_set_cipher_list
94sets the list of cipher suites only for
95.Fa ssl .
96.Pp
97The control string consists of one or more control words
98separated by colon characters
99.Pq Ql \&: .
100Space
101.Pq Ql \ \& ,
102semicolon
103.Pq Ql \&; ,
104and comma
105.Pq Ql \&,
106characters can also be used as separators.
107Each control words selects a set of cipher suites
108and can take one of the following optional prefix characters:
109.Bl -tag -width Ds
110.It \&No prefix:
111Those of the selected cipher suites that have not been made available
112yet are added to the end of the list of available cipher suites,
113preserving their order.
114.It Prefixed minus sign Pq Ql \- :
115Those of the selected cipher suites that have been made available
116earlier are moved back from the list of available cipher suites to
117the beginning of the list of unavailable cipher suites,
118also preserving their order.
119.It Prefixed plus sign Pq Ql + :
120Those of the selected cipher suites have been made available earlier
121are moved to end of the list of available cipher suites, reducing
122their priority, but preserving the order among themselves.
123.It Prefixed exclamation mark Pq Ql \&! :
124The selected cipher suites are permanently deleted, no matter whether
125they had earlier been made available or not, and can no longer
126be added or re-added by later words.
127.El
128.Pp
129The following special words can only be used without a prefix:
130.Bl -tag -width Ds
131.It Cm DEFAULT
132An alias for
133.Sm off
134.Cm ALL No :! Cm aNULL No :! Cm eNULL .
135.Sm on
136It can only be used as the first word.
137The
138.Cm DEFAULT
139cipher list can be displayed with the
140.Xr openssl 1
141.Cm ciphers
142command.
143.It Cm @SECLEVEL=n
144Set the security level to n, which should be a number between
145zero and five.
146See
147.Xr SSL_CTX_set_security_level 3
148for details.
149.It Cm @STRENGTH
150Sort the list by decreasing encryption strength,
151preserving the order of cipher suites that have the same strength.
152It is usually given as the last word.
153.El
154.Pp
155The following words can be used to select groups of cipher suites,
156with or without a prefix character.
157If two or more of these words are joined with plus signs
158.Pq Ql +
159to form a longer word, only the intersection of the specified sets
160is selected.
161.Bl -tag -width Ds
162.It Cm ADH
163Cipher suites using ephemeral DH for key exchange
164without doing any server authentication.
165Equivalent to
166.Cm DH Ns + Ns Cm aNULL .
167.It Cm AEAD
168Cipher suites using Authenticated Encryption with Additional Data.
169.It Cm AECDH
170Cipher suites using ephemeral ECDH for key exchange
171without doing any server authentication.
172Equivalent to
173.Cm ECDH Ns + Ns Cm aNULL .
174.It Cm aECDSA
175Cipher suites using ECDSA server authentication.
176.It Cm AES
177Cipher suites using AES or AESGCM for symmetric encryption.
178.It Cm AES128
179Cipher suites using AES(128) or AESGCM(128) for symmetric encryption.
180.It Cm AES256
181Cipher suites using AES(256) or AESGCM(256) for symmetric encryption.
182.It Cm AESGCM
183Cipher suites using AESGCM for symmetric encryption.
184.It Cm aGOST
185An alias for
186.Cm aGOST01 .
187.It Cm aGOST01
188Cipher suites using GOST R 34.10-2001 server authentication.
189.It Cm ALL
190All cipher suites except those selected by
191.Cm eNULL .
192.It Cm aNULL
193Cipher suites that don't do any server authentication.
194Not enabled by
195.Cm DEFAULT .
196Beware of man-in-the-middle attacks.
197.It Cm aRSA
198Cipher suites using RSA server authentication.
199.It Cm CAMELLIA
200Cipher suites using Camellia for symmetric encryption.
201.It Cm CAMELLIA128
202Cipher suites using Camellia(128) for symmetric encryption.
203.It Cm CAMELLIA256
204Cipher suites using Camellia(256) for symmetric encryption.
205.It Cm CHACHA20
206Cipher suites using ChaCha20-Poly1305 for symmetric encryption.
207.It Cm COMPLEMENTOFALL
208Cipher suites that are not included in
209.Cm ALL .
210Currently an alias for
211.Cm eNULL .
212.It Cm COMPLEMENTOFDEFAULT
213Cipher suites that are included in
214.Cm ALL ,
215but not included in
216.Cm DEFAULT .
217Currently similar to
218.Cm aNULL Ns :! Ns Cm eNULL
219except for the order of the cipher suites which are
220.Em not
221selected.
222.It Cm 3DES
223Cipher suites using triple DES for symmetric encryption.
224.It Cm DH
225Cipher suites using ephemeral DH for key exchange.
226.It Cm DHE
227Cipher suites using ephemeral DH for key exchange,
228but excluding those that don't do any server authentication.
229Similar to
230.Cm DH Ns :! Ns Cm aNULL
231except for the order of the cipher suites which are
232.Em not
233selected.
234.It Cm ECDH
235Cipher suites using ephemeral ECDH for key exchange.
236.It Cm ECDHE
237Cipher suites using ephemeral ECDH for key exchange,
238but excluding those that don't do any server authentication.
239Similar to
240.Cm ECDH Ns :! Ns Cm aNULL
241except for the order of the cipher suites which are
242.Em not
243selected.
244.It Cm ECDSA
245An alias for
246.Cm aECDSA .
247.It Cm eNULL
248Cipher suites that do not use any encryption.
249Not enabled by
250.Cm DEFAULT ,
251and not even included in
252.Cm ALL .
253.It Cm GOST89MAC
254Cipher suites using GOST 28147-89 for message authentication
255instead of HMAC.
256.It Cm GOST94
257Cipher suites using HMAC based on GOST R 34.11-94
258for message authentication.
259.It Cm HIGH
260Cipher suites of high strength.
261.It Cm kGOST
262Cipher suites using VKO 34.10 key exchange, specified in RFC 4357.
263.It Cm kRSA
264Cipher suites using RSA key exchange.
265.It Cm LOW
266Cipher suites of low strength.
267.It Cm MD5
268Cipher suites using MD5 for message authentication.
269.It Cm MEDIUM
270Cipher suites of medium strength.
271.It Cm NULL
272An alias for
273.Cm eNULL .
274.It Cm RC4
275Cipher suites using RC4 for symmetric encryption.
276.It Cm RSA
277Cipher suites using RSA for both key exchange and server authentication.
278Equivalent to
279.Cm kRSA Ns + Ns Cm aRSA .
280.It Cm SHA
281An alias for
282.Cm SHA1 .
283.It Cm SHA1
284Cipher suites using SHA1 for message authentication.
285.It Cm SHA256
286Cipher suites using SHA256 for message authentication.
287.It Cm SHA384
288Cipher suites using SHA384 for message authentication.
289.It Cm SSLv3
290An alias for
291.Cm TLSv1 .
292.It Cm STREEBOG256
293Cipher suites using STREEBOG256 for message authentication.
294.It Cm TLSv1
295Cipher suites usable with the TLSv1.0, TLSv1.1, and TLSv1.2 protocols.
296.It Cm TLSv1.2
297Cipher suites for the TLSv1.2 protocol.
298.It Cm TLSv1.3
299Cipher suites for the TLSv1.3 protocol.
300If the
301.Fa control
302string selects at least one cipher suite but neither contains the word
303.Cm TLSv1.3
304nor specifically includes nor excludes any TLSv1.3 cipher suites, all the
305.Cm TLSv1.3
306cipher suites are made available, too.
307.El
308.Pp
309The full words returned by the
310.Xr openssl 1
311.Cm ciphers
312command can be used to select individual cipher suites.
313.Pp
314The following are deprecated aliases:
315.Pp
316.Bl -column kEECDH ECDHE -compact -offset indent
317.It avoid: Ta use:
318.It Cm EDH Ta Cm DHE
319.It Cm EECDH Ta Cm ECDHE
320.It Cm kEDH Ta Cm DH
321.It Cm kEECDH Ta Cm ECDH
322.El
323.Pp
324Unknown words are silently ignored, selecting no cipher suites.
325Failure is only flagged if the
326.Fa control
327string contains invalid bytes
328or if no matching cipher suites are available at all.
329.Pp
330On the client side, including a cipher suite into the list of
331available cipher suites is sufficient for using it.
332On the server side, all cipher suites have additional requirements.
333ADH ciphers don't need a certificate, but DH-parameters must have been set.
334All other cipher suites need a corresponding certificate and key.
335.Pp
336A RSA cipher can only be chosen when an RSA certificate is available.
337RSA ciphers using DHE need a certificate and key and additional DH-parameters
338(see
339.Xr SSL_CTX_set_tmp_dh_callback 3 ) .
340.Pp
341When these conditions are not met
342for any cipher suite in the list (for example, a
343client only supports export RSA ciphers with an asymmetric key length of 512
344bits and the server is not configured to use temporary RSA keys), the
345.Dq no shared cipher
346.Pq Dv SSL_R_NO_SHARED_CIPHER
347error is generated and the handshake will fail.
348.Sh RETURN VALUES
349.Fn SSL_CTX_set_cipher_list
350and
351.Fn SSL_set_cipher_list
352return 1 if any cipher suite could be selected and 0 on complete failure.
353.Sh SEE ALSO
354.Xr ssl 3 ,
355.Xr SSL_CTX_set1_groups 3 ,
356.Xr SSL_CTX_set_tmp_dh_callback 3 ,
357.Xr SSL_CTX_use_certificate 3 ,
358.Xr SSL_get_ciphers 3
359.Sh HISTORY
360.Fn SSL_CTX_set_cipher_list
361and
362.Fn SSL_set_cipher_list
363first appeared in SSLeay 0.5.2 and have been available since
364.Ox 2.4 .
365.Sh CAVEATS
366In LibreSSL,
367.Fn SSL_CTX_set_cipher_list
368and
369.Fn SSL_set_cipher_list
370can be used to configure the list of available cipher suites for
371all versions of the TLS protocol, whereas in OpenSSL, they only
372control cipher suites for protocols up to TLSv1.2.
373If compatibility with OpenSSL is required, the list of
374available TLSv1.3 cipher suites can only be changed with
375.Fn SSL_set_ciphersuites .
diff --git a/src/lib/libssl/man/SSL_CTX_set_client_CA_list.3 b/src/lib/libssl/man/SSL_CTX_set_client_CA_list.3
deleted file mode 100644
index d19fb93ed0..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_client_CA_list.3
+++ /dev/null
@@ -1,183 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_client_CA_list.3,v 1.6 2020/03/30 10:28:59 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2013 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 30 2020 $
52.Dt SSL_CTX_SET_CLIENT_CA_LIST 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_client_CA_list ,
56.Nm SSL_set_client_CA_list ,
57.Nm SSL_CTX_add_client_CA ,
58.Nm SSL_add_client_CA
59.Nd set list of CAs sent to the client when requesting a client certificate
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft void
63.Fn SSL_CTX_set_client_CA_list "SSL_CTX *ctx" "STACK_OF(X509_NAME) *list"
64.Ft void
65.Fn SSL_set_client_CA_list "SSL *s" "STACK_OF(X509_NAME) *list"
66.Ft int
67.Fn SSL_CTX_add_client_CA "SSL_CTX *ctx" "X509 *cacert"
68.Ft int
69.Fn SSL_add_client_CA "SSL *ssl" "X509 *cacert"
70.Sh DESCRIPTION
71.Fn SSL_CTX_set_client_CA_list
72sets the
73.Fa list
74of CAs sent to the client when requesting a client certificate for
75.Fa ctx .
76.Pp
77.Fn SSL_set_client_CA_list
78sets the
79.Fa list
80of CAs sent to the client when requesting a client certificate for the chosen
81.Fa ssl ,
82overriding the setting valid for
83.Fa ssl Ns 's
84.Vt SSL_CTX
85object.
86.Pp
87.Fn SSL_CTX_add_client_CA
88adds the CA name extracted from
89.Fa cacert
90to the list of CAs sent to the client when requesting a client certificate for
91.Fa ctx .
92.Pp
93.Fn SSL_add_client_CA
94adds the CA name extracted from
95.Fa cacert
96to the list of CAs sent to the client when requesting a client certificate for
97the chosen
98.Fa ssl ,
99overriding the setting valid for
100.Fa ssl Ns 's
101.Va SSL_CTX
102object.
103.Pp
104When a TLS/SSL server requests a client certificate (see
105.Fn SSL_CTX_set_verify ) ,
106it sends a list of CAs for which it will accept certificates to the client.
107.Pp
108This list must explicitly be set using
109.Fn SSL_CTX_set_client_CA_list
110for
111.Fa ctx
112and
113.Fn SSL_set_client_CA_list
114for the specific
115.Fa ssl .
116The list specified overrides the previous setting.
117The CAs listed do not become trusted
118.Po
119.Fa list
120only contains the names, not the complete certificates
121.Pc ;
122use
123.Xr SSL_CTX_load_verify_locations 3
124to additionally load them for verification.
125.Pp
126If the list of acceptable CAs is compiled in a file, the
127.Xr SSL_load_client_CA_file 3
128function can be used to help importing the necessary data.
129.Pp
130.Fn SSL_CTX_add_client_CA
131and
132.Fn SSL_add_client_CA
133can be used to add additional items the list of client CAs.
134If no list was specified before using
135.Fn SSL_CTX_set_client_CA_list
136or
137.Fn SSL_set_client_CA_list ,
138a new client CA list for
139.Fa ctx
140or
141.Fa ssl
142(as appropriate) is opened.
143.Pp
144These functions are only useful for TLS/SSL servers.
145.Sh RETURN VALUES
146.Fn SSL_CTX_add_client_CA
147and
148.Fn SSL_add_client_CA
149have the following return values:
150.Bl -tag -width Ds
151.It 0
152A failure while manipulating the
153.Dv STACK_OF Ns
154.Pq Vt X509_NAME
155object occurred or the
156.Vt X509_NAME
157could not be extracted from
158.Fa cacert .
159Check the error stack to find out the reason.
160.It 1
161The operation succeeded.
162.El
163.Sh EXAMPLES
164Scan all certificates in
165.Fa CAfile
166and list them as acceptable CAs:
167.Bd -literal
168SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(CAfile));
169.Ed
170.Sh SEE ALSO
171.Xr ssl 3 ,
172.Xr SSL_CTX_load_verify_locations 3 ,
173.Xr SSL_get_client_CA_list 3 ,
174.Xr SSL_load_client_CA_file 3 ,
175.Xr X509_NAME_new 3
176.Sh HISTORY
177.Fn SSL_CTX_set_client_CA_list ,
178.Fn SSL_set_client_CA_list ,
179.Fn SSL_CTX_add_client_CA ,
180and
181.Fn SSL_add_client_CA
182first appeared in SSLeay 0.8.0 and have been available since
183.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_client_cert_cb.3 b/src/lib/libssl/man/SSL_CTX_set_client_cert_cb.3
deleted file mode 100644
index a2433b5e92..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_client_cert_cb.3
+++ /dev/null
@@ -1,191 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_client_cert_cb.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2002 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_SET_CLIENT_CERT_CB 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_client_cert_cb ,
56.Nm SSL_CTX_get_client_cert_cb
57.Nd handle client certificate callback function
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft void
61.Fo SSL_CTX_set_client_cert_cb
62.Fa "SSL_CTX *ctx"
63.Fa "int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey)"
64.Fc
65.Ft int
66.Fo "(*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))"
67.Fa "SSL *ssl" "X509 **x509" "EVP_PKEY **pkey"
68.Fc
69.Ft int
70.Fn "(*client_cert_cb)" "SSL *ssl" "X509 **x509" "EVP_PKEY **pkey"
71.Sh DESCRIPTION
72.Fn SSL_CTX_set_client_cert_cb
73sets the
74.Fa client_cert_cb()
75callback that is called when a client certificate is requested by a server and
76no certificate was yet set for the SSL object.
77.Pp
78When
79.Fa client_cert_cb
80is
81.Dv NULL ,
82no callback function is used.
83.Pp
84.Fn SSL_CTX_get_client_cert_cb
85returns a pointer to the currently set callback function.
86.Pp
87.Fn client_cert_cb
88is the application-defined callback.
89If it wants to set a certificate,
90a certificate/private key combination must be set using the
91.Fa x509
92and
93.Fa pkey
94arguments and 1 must be returned.
95The certificate will be installed into
96.Fa ssl .
97If no certificate should be set,
980 has to be returned and no certificate will be sent.
99A negative return value will suspend the handshake and the handshake function
100will return immediately.
101.Xr SSL_get_error 3
102will return
103.Dv SSL_ERROR_WANT_X509_LOOKUP
104to indicate that the handshake was suspended.
105The next call to the handshake function will again lead to the call of
106.Fa client_cert_cb() .
107It is the job of the
108.Fa client_cert_cb()
109to store information
110about the state of the last call, if required to continue.
111.Pp
112During a handshake (or renegotiation)
113a server may request a certificate from the client.
114A client certificate must only be sent when the server did send the request.
115.Pp
116When a certificate has been set using the
117.Xr SSL_CTX_use_certificate 3
118family of functions,
119it will be sent to the server.
120The TLS standard requires that only a certificate is sent if it matches the
121list of acceptable CAs sent by the server.
122This constraint is violated by the default behavior of the OpenSSL library.
123Using the callback function it is possible to implement a proper selection
124routine or to allow a user interaction to choose the certificate to be sent.
125.Pp
126If a callback function is defined and no certificate was yet defined for the
127.Vt SSL
128object, the callback function will be called.
129If the callback function returns a certificate, the OpenSSL library
130will try to load the private key and certificate data into the
131.Vt SSL
132object using the
133.Fn SSL_use_certificate
134and
135.Fn SSL_use_private_key
136functions.
137Thus it will permanently install the certificate and key for this SSL object.
138It will not be reset by calling
139.Xr SSL_clear 3 .
140If the callback returns no certificate, the OpenSSL library will not send a
141certificate.
142.Sh SEE ALSO
143.Xr ssl 3 ,
144.Xr SSL_clear 3 ,
145.Xr SSL_CTX_add_extra_chain_cert 3 ,
146.Xr SSL_CTX_use_certificate 3 ,
147.Xr SSL_free 3 ,
148.Xr SSL_get_client_CA_list 3
149.Sh HISTORY
150.Fn SSL_CTX_set_client_cert_cb
151and
152.Fn SSL_CTX_get_client_cert_cb
153first appeared in SSLeay 0.6.6 and have been available since
154.Ox 2.4 .
155.Sh BUGS
156The
157.Fa client_cert_cb()
158cannot return a complete certificate chain;
159it can only return one client certificate.
160If the chain only has a length of 2,
161the root CA certificate may be omitted according to the TLS standard and
162thus a standard conforming answer can be sent to the server.
163For a longer chain, the client must send the complete chain
164(with the option to leave out the root CA certificate).
165This can be accomplished only by either adding the intermediate CA certificates
166into the trusted certificate store for the
167.Vt SSL_CTX
168object (resulting in having to add CA certificates that otherwise maybe would
169not be trusted), or by adding the chain certificates using the
170.Xr SSL_CTX_add_extra_chain_cert 3
171function, which is only available for the
172.Vt SSL_CTX
173object as a whole and that therefore probably can only apply for one client
174certificate, making the concept of the callback function
175(to allow the choice from several certificates) questionable.
176.Pp
177Once the
178.Vt SSL
179object has been used in conjunction with the callback function,
180the certificate will be set for the
181.Vt SSL
182object and will not be cleared even when
183.Xr SSL_clear 3
184is called.
185It is therefore
186.Em mandatory
187to destroy the
188.Vt SSL
189object using
190.Xr SSL_free 3
191and create a new one to return to the previous state.
diff --git a/src/lib/libssl/man/SSL_CTX_set_default_passwd_cb.3 b/src/lib/libssl/man/SSL_CTX_set_default_passwd_cb.3
deleted file mode 100644
index 94b4ea543d..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_default_passwd_cb.3
+++ /dev/null
@@ -1,216 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_default_passwd_cb.3,v 1.9 2023/09/19 09:40:35 schwarze Exp $
2.\" full merge up to: OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\" selective merge up to: OpenSSL 18bad535 Apr 9 15:13:55 2019 +0100
4.\"
5.\" This file is a derived work.
6.\" The changes are covered by the following Copyright and license:
7.\"
8.\" Copyright (c) 2023 Ingo Schwarze <schwarze@openbsd.org>
9.\"
10.\" Permission to use, copy, modify, and distribute this software for any
11.\" purpose with or without fee is hereby granted, provided that the above
12.\" copyright notice and this permission notice appear in all copies.
13.\"
14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21.\"
22.\" The original file was written by Lutz Jaenicke <jaenicke@openssl.org>
23.\" and Christian Heimes <cheimes@redhat.com>.
24.\" Copyright (c) 2000, 2001, 2016 The OpenSSL Project. All rights reserved.
25.\"
26.\" Redistribution and use in source and binary forms, with or without
27.\" modification, are permitted provided that the following conditions
28.\" are met:
29.\"
30.\" 1. Redistributions of source code must retain the above copyright
31.\" notice, this list of conditions and the following disclaimer.
32.\"
33.\" 2. Redistributions in binary form must reproduce the above copyright
34.\" notice, this list of conditions and the following disclaimer in
35.\" the documentation and/or other materials provided with the
36.\" distribution.
37.\"
38.\" 3. All advertising materials mentioning features or use of this
39.\" software must display the following acknowledgment:
40.\" "This product includes software developed by the OpenSSL Project
41.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
42.\"
43.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
44.\" endorse or promote products derived from this software without
45.\" prior written permission. For written permission, please contact
46.\" openssl-core@openssl.org.
47.\"
48.\" 5. Products derived from this software may not be called "OpenSSL"
49.\" nor may "OpenSSL" appear in their names without prior written
50.\" permission of the OpenSSL Project.
51.\"
52.\" 6. Redistributions of any form whatsoever must retain the following
53.\" acknowledgment:
54.\" "This product includes software developed by the OpenSSL Project
55.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
56.\"
57.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
58.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
61.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
68.\" OF THE POSSIBILITY OF SUCH DAMAGE.
69.\"
70.Dd $Mdocdate: September 19 2023 $
71.Dt SSL_CTX_SET_DEFAULT_PASSWD_CB 3
72.Os
73.Sh NAME
74.Nm SSL_CTX_set_default_passwd_cb ,
75.Nm SSL_CTX_set_default_passwd_cb_userdata ,
76.Nm SSL_CTX_get_default_passwd_cb ,
77.Nm SSL_CTX_get_default_passwd_cb_userdata
78.Nd set or get passwd callback for encrypted PEM file handling
79.Sh SYNOPSIS
80.In openssl/ssl.h
81.Ft void
82.Fn SSL_CTX_set_default_passwd_cb "SSL_CTX *ctx" "pem_password_cb *cb"
83.Ft void
84.Fn SSL_CTX_set_default_passwd_cb_userdata "SSL_CTX *ctx" "void *userdata"
85.Ft pem_password_cb *
86.Fn SSL_CTX_get_default_passwd_cb "SSL_CTX *ctx"
87.Ft void *
88.Fn SSL_CTX_get_default_passwd_cb_userdata "SSL_CTX *ctx"
89.Sh DESCRIPTION
90.Fn SSL_CTX_set_default_passwd_cb
91sets the password callback for loading a certificate or private key
92from encrypted PEM format.
93In particular, the callback is used by
94.Xr SSL_CTX_use_certificate_file 3 ,
95.Xr SSL_use_certificate_file 3 ,
96.Xr SSL_CTX_use_certificate_chain_file 3 ,
97.Xr SSL_use_certificate_chain_file 3 ,
98.Xr SSL_CTX_use_certificate_chain_mem 3 ,
99.Xr SSL_CTX_use_PrivateKey_file 3 ,
100.Xr SSL_use_PrivateKey_file 3 ,
101.Xr SSL_CTX_use_RSAPrivateKey_file 3 ,
102and
103.Xr SSL_use_RSAPrivateKey_file 3 .
104.Pp
105The function pointer type of the
106.Fa cb
107argument is documented in the
108.Xr pem_password_cb 3
109manual page.
110If
111.Fn SSL_CTX_set_default_passwd_cb
112is not called on
113.Fa ctx
114or if it is called with a
115.Fa cb
116argument of
117.Dv NULL ,
118.Xr PEM_def_callback 3
119is used instead.
120.Pp
121.Fn SSL_CTX_set_default_passwd_cb_userdata
122sets a pointer to the
123.Fa userdata
124which will be provided to the password callback on invocation.
125.Pp
126Since the
127.Fa cb
128passed to
129.Fn SSL_CTX_set_default_passwd_cb
130will only be used for reading and decryption and not for writing and
131encryption, the library will only call it with a
132.Fa verify
133argument of 0.
134.Pp
135If an application program only needs to read and decrypt
136one single private key, it can be practical to have the
137callback handle the password dialog interactively.
138This happens by default if neither
139.Fn SSL_CTX_set_default_passwd_cb
140nor
141.Fn SSL_CTX_set_default_passwd_cb_userdata
142is called.
143In that case, the library uses
144.Xr PEM_def_callback 3
145with a
146.Fa userdata
147argument of
148.Dv NULL .
149.Pp
150If several keys have to be handled, it can be practical
151to ask for the password once, for example using
152.Xr UI_UTIL_read_pw_string 3 ,
153then keep it in memory and use it several times by passing a pointer to it to
154.Fn SSL_CTX_set_default_passwd_cb_userdata .
155.Xr PEM_def_callback 3
156is able to handle this case, too, so calling
157.Fn SSL_CTX_set_default_passwd_cb
158is not needed in this case either.
159.Pp
160Other items in PEM formatting (certificates) can also be encrypted; it is
161however atypical, as certificate information is considered public.
162.Sh RETURN VALUES
163.Fn SSL_CTX_get_default_passwd_cb
164returns a function pointer to the password callback currently set in
165.Fa ctx ,
166or
167.Dv NULL
168if none is set.
169.Pp
170.Fn SSL_CTX_get_default_passwd_cb_userdata
171returns a pointer to the userdata currently set in
172.Fa ctx ,
173or
174.Dv NULL
175if none is set.
176.Sh EXAMPLES
177The following example provides a subset of the functionality of
178.Xr PEM_def_callback 3 ,
179except that
180.Xr PEM_def_callback 3
181does not NUL-terminate and copies up to
182.Fa size
183rather than
184.Fa size No \- 1
185bytes.
186It interprets
187.Fa userdata
188as a NUL-terminated string and copies it to the
189.Fa password
190buffer, truncating the copy if it does not fit.
191.Bd -literal
192int
193trivial_passwd_cb(char *password, int size, int verify, void *userdata)
194{
195 strlcpy(password, userdata, size);
196 return strlen(password);
197}
198.Ed
199.Sh SEE ALSO
200.Xr pem_password_cb 3 ,
201.Xr ssl 3 ,
202.Xr SSL_CTX_use_certificate 3
203.Sh HISTORY
204.Fn SSL_CTX_set_default_passwd_cb
205first appeared in SSLeay 0.6.2 and has been available since
206.Ox 2.4 .
207.Pp
208.Fn SSL_CTX_set_default_passwd_cb_userdata
209first appeared in OpenSSL 0.9.4 and has been available since
210.Ox 2.6 .
211.Pp
212.Fn SSL_CTX_get_default_passwd_cb
213and
214.Fn SSL_CTX_get_default_passwd_cb_userdata
215first appeared in OpenSSL 1.1.0 and have been available since
216.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_generate_session_id.3 b/src/lib/libssl/man/SSL_CTX_set_generate_session_id.3
deleted file mode 100644
index d85383d776..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_generate_session_id.3
+++ /dev/null
@@ -1,221 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_generate_session_id.3,v 1.5 2018/03/22 21:09:18 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2014 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 22 2018 $
52.Dt SSL_CTX_SET_GENERATE_SESSION_ID 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_generate_session_id ,
56.Nm SSL_set_generate_session_id ,
57.Nm SSL_has_matching_session_id ,
58.Nm GEN_SESSION_CB
59.Nd manipulate generation of SSL session IDs (server only)
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft typedef int
63.Fo (*GEN_SESSION_CB)
64.Fa "const SSL *ssl"
65.Fa "unsigned char *id"
66.Fa "unsigned int *id_len"
67.Fc
68.Ft int
69.Fn SSL_CTX_set_generate_session_id "SSL_CTX *ctx" "GEN_SESSION_CB cb"
70.Ft int
71.Fn SSL_set_generate_session_id "SSL *ssl" "GEN_SESSION_CB cb"
72.Ft int
73.Fo SSL_has_matching_session_id
74.Fa "const SSL *ssl" "const unsigned char *id" "unsigned int id_len"
75.Fc
76.Sh DESCRIPTION
77.Fn SSL_CTX_set_generate_session_id
78sets the callback function for generating new session ids for SSL/TLS sessions
79for
80.Fa ctx
81to be
82.Fa cb .
83.Pp
84.Fn SSL_set_generate_session_id
85sets the callback function for generating new session ids for SSL/TLS sessions
86for
87.Fa ssl
88to be
89.Fa cb .
90.Pp
91.Fn SSL_has_matching_session_id
92checks, whether a session with id
93.Fa id
94(of length
95.Fa id_len )
96is already contained in the internal session cache
97of the parent context of
98.Fa ssl .
99.Pp
100When a new session is established between client and server,
101the server generates a session id.
102The session id is an arbitrary sequence of bytes.
103The length of the session id is between 1 and 32 bytes.
104The session id is not security critical but must be unique for the server.
105Additionally, the session id is transmitted in the clear when reusing the
106session so it must not contain sensitive information.
107.Pp
108Without a callback being set, an OpenSSL server will generate a unique session
109id from pseudo random numbers of the maximum possible length.
110Using the callback function, the session id can be changed to contain
111additional information like, e.g., a host id in order to improve load balancing
112or external caching techniques.
113.Pp
114The callback function receives a pointer to the memory location to put
115.Fa id
116into and a pointer to the maximum allowed length
117.Fa id_len .
118The buffer at location
119.Fa id
120is only guaranteed to have the size
121.Fa id_len .
122The callback is only allowed to generate a shorter id and reduce
123.Fa id_len ;
124the callback
125.Em must never
126increase
127.Fa id_len
128or write to the location
129.Fa id
130exceeding the given limit.
131.Pp
132The location
133.Fa id
134is filled with 0x00 before the callback is called,
135so the callback may only fill part of the possible length and leave
136.Fa id_len
137untouched while maintaining reproducibility.
138.Pp
139Since the sessions must be distinguished, session ids must be unique.
140Without the callback a random number is used,
141so that the probability of generating the same session id is extremely small
142(2^256 for TLSv1).
143In order to ensure the uniqueness of the generated session id,
144the callback must call
145.Fn SSL_has_matching_session_id
146and generate another id if a conflict occurs.
147If an id conflict is not resolved, the handshake will fail.
148If the application codes, e.g., a unique host id, a unique process number, and
149a unique sequence number into the session id, uniqueness could easily be
150achieved without randomness added (it should however be taken care that
151no confidential information is leaked this way).
152If the application cannot guarantee uniqueness,
153it is recommended to use the maximum
154.Fa id_len
155and fill in the bytes not used to code special information with random data to
156avoid collisions.
157.Pp
158.Fn SSL_has_matching_session_id
159will only query the internal session cache, not the external one.
160Since the session id is generated before the handshake is completed,
161it is not immediately added to the cache.
162If another thread is using the same internal session cache,
163a race condition can occur in that another thread generates the same session id.
164Collisions can also occur when using an external session cache,
165since the external cache is not tested with
166.Fn SSL_has_matching_session_id
167and the same race condition applies.
168.Pp
169The callback must return 0 if it cannot generate a session id for whatever
170reason and return 1 on success.
171.Sh RETURN VALUES
172.Fn SSL_CTX_set_generate_session_id
173and
174.Fn SSL_set_generate_session_id
175always return 1.
176.Pp
177.Fn SSL_has_matching_session_id
178returns 1 if another session with the same id is already in the cache.
179.Sh EXAMPLES
180The callback function listed will generate a session id with the server id
181given, and will fill the rest with pseudo random bytes:
182.Bd -literal
183const char session_id_prefix = "www-18";
184
185#define MAX_SESSION_ID_ATTEMPTS 10
186static int
187generate_session_id(const SSL *ssl, unsigned char *id,
188 unsigned int *id_len)
189{
190 unsigned int count = 0;
191
192 do {
193 RAND_pseudo_bytes(id, *id_len);
194 /*
195 * Prefix the session_id with the required prefix. NB: If
196 * our prefix is too long, clip it \(en but there will be
197 * worse effects anyway, e.g., the server could only
198 * possibly create one session ID (the prefix!) so all
199 * future session negotiations will fail due to conflicts.
200 */
201 memcpy(id, session_id_prefix,
202 (strlen(session_id_prefix) < *id_len) ?
203 strlen(session_id_prefix) : *id_len);
204 } while (SSL_has_matching_session_id(ssl, id, *id_len) &&
205 (++count < MAX_SESSION_ID_ATTEMPTS));
206
207 if (count >= MAX_SESSION_ID_ATTEMPTS)
208 return 0;
209 return 1;
210}
211.Ed
212.Sh SEE ALSO
213.Xr ssl 3 ,
214.Xr SSL_get_version 3
215.Sh HISTORY
216.Fn SSL_CTX_set_generate_session_id ,
217.Fn SSL_set_generate_session_id
218and
219.Fn SSL_has_matching_session_id
220first appeared in OpenSSL 0.9.7 and have been available since
221.Ox 3.2 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_info_callback.3 b/src/lib/libssl/man/SSL_CTX_set_info_callback.3
deleted file mode 100644
index 76eb8bee61..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_info_callback.3
+++ /dev/null
@@ -1,233 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_info_callback.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005, 2014 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_SET_INFO_CALLBACK 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_info_callback ,
56.Nm SSL_CTX_get_info_callback ,
57.Nm SSL_set_info_callback ,
58.Nm SSL_get_info_callback
59.Nd handle information callback for SSL connections
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft void
63.Fo SSL_CTX_set_info_callback
64.Fa "SSL_CTX *ctx"
65.Fa "void (*callback)(const SSL *ssl, int where, int ret)"
66.Fc
67.Ft void
68.Fo "(*SSL_CTX_get_info_callback(const SSL_CTX *ctx))"
69.Fa "const SSL *ssl"
70.Fa "int where"
71.Fa "int ret"
72.Fc
73.Ft void
74.Fo SSL_set_info_callback
75.Fa "SSL *ssl"
76.Fa "void (*callback)(const SSL *ssl, int where, int ret)"
77.Fc
78.Ft void
79.Fo "(*SSL_get_info_callback(const SSL *ssl))"
80.Fa "const SSL *ssl"
81.Fa "int where"
82.Fa "int ret"
83.Fc
84.Sh DESCRIPTION
85.Fn SSL_CTX_set_info_callback
86sets the
87.Fa callback
88function that can be used to obtain state information for SSL objects created
89from
90.Fa ctx
91during connection setup and use.
92The setting for
93.Fa ctx
94is overridden from the setting for a specific SSL object, if specified.
95When
96.Fa callback
97is
98.Dv NULL ,
99no callback function is used.
100.Pp
101.Fn SSL_set_info_callback
102sets the
103.Fa callback
104function that can be used to
105obtain state information for
106.Fa ssl
107during connection setup and use.
108When
109.Fa callback
110is
111.Dv NULL ,
112the callback setting currently valid for
113.Fa ctx
114is used.
115.Pp
116.Fn SSL_CTX_get_info_callback
117returns a pointer to the currently set information callback function for
118.Fa ctx .
119.Pp
120.Fn SSL_get_info_callback
121returns a pointer to the currently set information callback function for
122.Fa ssl .
123.Pp
124When setting up a connection and during use,
125it is possible to obtain state information from the SSL/TLS engine.
126When set, an information callback function is called whenever the state changes,
127an alert appears, or an error occurs.
128.Pp
129The callback function is called as
130.Fn callback "SSL *ssl" "int where" "int ret" .
131The
132.Fa where
133argument specifies information about where (in which context)
134the callback function was called.
135If
136.Fa ret
137is 0, an error condition occurred.
138If an alert is handled,
139.Dv SSL_CB_ALERT
140is set and
141.Fa ret
142specifies the alert information.
143.Pp
144.Fa where
145is a bitmask made up of the following bits:
146.Bl -tag -width Ds
147.It Dv SSL_CB_LOOP
148Callback has been called to indicate state change inside a loop.
149.It Dv SSL_CB_EXIT
150Callback has been called to indicate error exit of a handshake function.
151(May be soft error with retry option for non-blocking setups.)
152.It Dv SSL_CB_READ
153Callback has been called during read operation.
154.It Dv SSL_CB_WRITE
155Callback has been called during write operation.
156.It Dv SSL_CB_ALERT
157Callback has been called due to an alert being sent or received.
158.It Dv SSL_CB_READ_ALERT
159.It Dv SSL_CB_WRITE_ALERT
160.It Dv SSL_CB_ACCEPT_LOOP
161.It Dv SSL_CB_ACCEPT_EXIT
162.It Dv SSL_CB_CONNECT_LOOP
163.It Dv SSL_CB_CONNECT_EXIT
164.It Dv SSL_CB_HANDSHAKE_START
165Callback has been called because a new handshake is started.
166.It Dv SSL_CB_HANDSHAKE_DONE
167Callback has been called because a handshake is finished.
168.El
169.Pp
170The current state information can be obtained using the
171.Xr SSL_state_string 3
172family of functions.
173.Pp
174The
175.Fa ret
176information can be evaluated using the
177.Xr SSL_alert_type_string 3
178family of functions.
179.Sh RETURN VALUES
180.Fn SSL_CTX_get_info_callback
181and
182.Fn SSL_get_info_callback
183return a pointer to the current callback or
184.Dv NULL
185if none is set.
186.Sh EXAMPLES
187The following example callback function prints state strings,
188information about alerts being handled and error messages to the
189.Va bio_err
190.Vt BIO .
191.Bd -literal
192void
193apps_ssl_info_callback(SSL *s, int where, int ret)
194{
195 const char *str;
196 int w;
197
198 w = where & ~SSL_ST_MASK;
199
200 if (w & SSL_ST_CONNECT)
201 str = "SSL_connect";
202 else if (w & SSL_ST_ACCEPT)
203 str = "SSL_accept";
204 else
205 str = "undefined";
206
207 if (where & SSL_CB_LOOP) {
208 BIO_printf(bio_err, "%s:%s\en", str,
209 SSL_state_string_long(s));
210 } else if (where & SSL_CB_ALERT) {
211 str = (where & SSL_CB_READ) ? "read" : "write";
212 BIO_printf(bio_err, "SSL3 alert %s:%s:%s\en", str,
213 SSL_alert_type_string_long(ret),
214 SSL_alert_desc_string_long(ret));
215 } else if (where & SSL_CB_EXIT) {
216 if (ret == 0)
217 BIO_printf(bio_err, "%s:failed in %s\en",
218 str, SSL_state_string_long(s));
219 else if (ret < 0) {
220 BIO_printf(bio_err, "%s:error in %s\en",
221 str, SSL_state_string_long(s));
222 }
223 }
224}
225.Ed
226.Sh SEE ALSO
227.Xr ssl 3 ,
228.Xr SSL_alert_type_string 3 ,
229.Xr SSL_state_string 3
230.Sh HISTORY
231These functions first appeared in SSLeay 0.6.0
232and have been available since
233.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_keylog_callback.3 b/src/lib/libssl/man/SSL_CTX_set_keylog_callback.3
deleted file mode 100644
index 24b8f9992f..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_keylog_callback.3
+++ /dev/null
@@ -1,56 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_keylog_callback.3,v 1.3 2024/05/16 08:39:30 tb Exp $
2.\" OpenSSL pod checked up to: 61f805c1 Jan 16 01:01:46 2018 +0800
3.\"
4.\" Copyright (c) 2021 Bob Beck <beck@openbsd.org>
5.\"
6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies.
9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\"
18.Dd $Mdocdate: May 16 2024 $
19.Dt SSL_CTX_SET_KEYLOG_CALLBACK 3
20.Os
21.Sh NAME
22.Nm SSL_CTX_set_keylog_callback ,
23.Nm SSL_CTX_get_keylog_callback
24.Nd set and get the unused key logging callback
25.Sh SYNOPSIS
26.In openssl/ssl.h
27.Ft typedef void
28.Fo (*SSL_CTX_keylog_cb_func)
29.Fa "const SSL *ssl"
30.Fa "const char *line"
31.Fc
32.Ft void
33.Fn SSL_CTX_set_keylog_callback "SSL_CTX *ctx" "SSL_CTX_keylog_cb_func cb"
34.Ft SSL_CTX_keylog_cb_func
35.Fn SSL_CTX_get_keylog_callback "const SSL_CTX *ctx"
36.Sh DESCRIPTION
37.Fn SSL_CTX_set_keylog_callback
38sets the TLS key logging callback.
39This callback is never called in LibreSSL.
40.Pp
41.Fn SSL_CTX_get_keylog_callback
42retrieves the previously set TLS key logging callback.
43.Pp
44These functions are provided only for compatibility with OpenSSL.
45.Sh RETURN VALUES
46.Fn SSL_CTX_get_keylog_callback
47returns the previously set TLS key logging callback, or
48.Dv NULL
49if no callback has been set.
50.Sh SEE ALSO
51.Xr ssl 3 ,
52.Xr SSL_CTX_new 3
53.Sh HISTORY
54These function first appeared in OpenSSL 1.1.1
55and have been available since
56.Ox 7.1 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_max_cert_list.3 b/src/lib/libssl/man/SSL_CTX_set_max_cert_list.3
deleted file mode 100644
index 89513b1006..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_max_cert_list.3
+++ /dev/null
@@ -1,154 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_max_cert_list.3,v 1.6 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 12 2019 $
52.Dt SSL_CTX_SET_MAX_CERT_LIST 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_max_cert_list ,
56.Nm SSL_CTX_get_max_cert_list ,
57.Nm SSL_set_max_cert_list ,
58.Nm SSL_get_max_cert_list
59.Nd manipulate allowed size for the peer's certificate chain
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft long
63.Fn SSL_CTX_set_max_cert_list "SSL_CTX *ctx" "long size"
64.Ft long
65.Fn SSL_CTX_get_max_cert_list "SSL_CTX *ctx"
66.Ft long
67.Fn SSL_set_max_cert_list "SSL *ssl" "long size"
68.Ft long
69.Fn SSL_get_max_cert_list "SSL *ctx"
70.Sh DESCRIPTION
71.Fn SSL_CTX_set_max_cert_list
72sets the maximum size allowed for the peer's certificate chain for all
73.Vt SSL
74objects created from
75.Fa ctx
76to be
77.Fa size
78bytes.
79The
80.Vt SSL
81objects inherit the setting valid for
82.Fa ctx
83at the time
84.Xr SSL_new 3
85is being called.
86.Pp
87.Fn SSL_CTX_get_max_cert_list
88returns the currently set maximum size for
89.Fa ctx .
90.Pp
91.Fn SSL_set_max_cert_list
92sets the maximum size allowed for the peer's certificate chain for
93.Fa ssl
94to be
95.Fa size
96bytes.
97This setting stays valid until a new value is set.
98.Pp
99.Fn SSL_get_max_cert_list
100returns the currently set maximum size for
101.Fa ssl .
102.Pp
103During the handshake process, the peer may send a certificate chain.
104The TLS/SSL standard does not give any maximum size of the certificate chain.
105The OpenSSL library handles incoming data by a dynamically allocated buffer.
106In order to prevent this buffer from growing without bound due to data
107received from a faulty or malicious peer, a maximum size for the certificate
108chain is set.
109.Pp
110The default value for the maximum certificate chain size is 100kB (30kB
111on the 16bit DOS platform).
112This should be sufficient for usual certificate chains
113(OpenSSL's default maximum chain length is 10, see
114.Xr SSL_CTX_set_verify 3 ,
115and certificates without special extensions have a typical size of 1-2kB).
116.Pp
117For special applications it can be necessary to extend the maximum certificate
118chain size allowed to be sent by the peer.
119See for example the work on
120.%T "Internet X.509 Public Key Infrastructure Proxy Certificate Profile"
121and
122.%T "TLS Delegation Protocol"
123at
124.Lk https://www.ietf.org/
125and
126.Lk http://www.globus.org/ .
127.Pp
128Under normal conditions it should never be necessary to set a value smaller
129than the default, as the buffer is handled dynamically and only uses the
130memory actually required by the data sent by the peer.
131.Pp
132If the maximum certificate chain size allowed is exceeded, the handshake will
133fail with a
134.Dv SSL_R_EXCESSIVE_MESSAGE_SIZE
135error.
136.Sh RETURN VALUES
137.Fn SSL_CTX_set_max_cert_list
138and
139.Fn SSL_set_max_cert_list
140return the previously set value.
141.Pp
142.Fn SSL_CTX_get_max_cert_list
143and
144.Fn SSL_get_max_cert_list
145return the currently set value.
146.Sh SEE ALSO
147.Xr ssl 3 ,
148.Xr SSL_CTX_ctrl 3 ,
149.Xr SSL_CTX_set_verify 3 ,
150.Xr SSL_new 3
151.Sh HISTORY
152These functions first appeared in OpenSSL 0.9.7
153and have been available since
154.Ox 3.2 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_min_proto_version.3 b/src/lib/libssl/man/SSL_CTX_set_min_proto_version.3
deleted file mode 100644
index a2597cda83..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_min_proto_version.3
+++ /dev/null
@@ -1,156 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_min_proto_version.3,v 1.5 2021/04/15 16:40:32 tb Exp $
2.\" full merge up to: OpenSSL 3edabd3c Sep 14 09:28:39 2017 +0200
3.\"
4.\" This file was written by Kurt Roeckx <kurt@roeckx.be> and
5.\" Christian Heimes <christian@python.org>.
6.\" Copyright (c) 2015, 2017 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: April 15 2021 $
53.Dt SSL_CTX_SET_MIN_PROTO_VERSION 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_min_proto_version ,
57.Nm SSL_CTX_set_max_proto_version ,
58.Nm SSL_CTX_get_min_proto_version ,
59.Nm SSL_CTX_get_max_proto_version ,
60.Nm SSL_set_min_proto_version ,
61.Nm SSL_set_max_proto_version ,
62.Nm SSL_get_min_proto_version ,
63.Nm SSL_get_max_proto_version
64.Nd get and set minimum and maximum supported protocol version
65.Sh SYNOPSIS
66.In openssl/ssl.h
67.Ft int
68.Fo SSL_CTX_set_min_proto_version
69.Fa "SSL_CTX *ctx"
70.Fa "uint16_t version"
71.Fc
72.Ft int
73.Fo SSL_CTX_set_max_proto_version
74.Fa "SSL_CTX *ctx"
75.Fa "uint16_t version"
76.Fc
77.Ft int
78.Fo SSL_CTX_get_min_proto_version
79.Fa "SSL_CTX *ctx"
80.Fc
81.Ft int
82.Fo SSL_CTX_get_max_proto_version
83.Fa "SSL_CTX *ctx"
84.Fc
85.Ft int
86.Fo SSL_set_min_proto_version
87.Fa "SSL *ssl"
88.Fa "uint16_t version"
89.Fc
90.Ft int
91.Fo SSL_set_max_proto_version
92.Fa "SSL *ssl"
93.Fa "uint16_t version"
94.Fc
95.Ft int
96.Fo SSL_get_min_proto_version
97.Fa "SSL *ssl"
98.Fc
99.Ft int
100.Fo SSL_get_max_proto_version
101.Fa "SSL *ssl"
102.Fc
103.Sh DESCRIPTION
104These functions get or set the minimum and maximum supported protocol
105versions for
106.Fa ctx
107or
108.Fa ssl .
109This works in combination with the options set via
110.Xr SSL_CTX_set_options 3
111that also make it possible to disable specific protocol versions.
112Use these functions instead of disabling specific protocol versions.
113.Pp
114Setting the minimum or maximum version to 0 will enable protocol
115versions down to the lowest or up to the highest version supported
116by the library, respectively.
117.Pp
118Currently supported versions are
119.Dv TLS1_VERSION ,
120.Dv TLS1_1_VERSION ,
121and
122.Dv TLS1_2_VERSION
123for TLS and
124.Dv DTLS1_VERSION
125and
126.Dv DTLS1_2_VERSION
127for DTLS.
128.Pp
129In other implementations, these functions may be implemented as macros.
130.Sh RETURN VALUES
131The setter functions return 1 on success or 0 on failure.
132.Pp
133The getter functions return the configured version or 0 if
134.Fa ctx
135or
136.Fa ssl
137has been configured to automatically use the lowest or highest
138version supported by the library.
139.Sh SEE ALSO
140.Xr ssl 3 ,
141.Xr SSL_CTX_new 3 ,
142.Xr SSL_CTX_set_options 3
143.Sh HISTORY
144The setter functions first appeared in BoringSSL in December 2014,
145with shorter names without the
146.Sy proto_
147part.
148Two years later, OpenSSL included them in their 1.1.0 release,
149gratuitously changing the names; Google shrugged and adopted
150the longer names one month later.
151They have been available since
152.Ox 6.2 .
153.Pp
154The getter functions first appeared in OpenSSL 1.1.0g
155and have been available since
156.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_mode.3 b/src/lib/libssl/man/SSL_CTX_set_mode.3
deleted file mode 100644
index fca1a977d0..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_mode.3
+++ /dev/null
@@ -1,204 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_mode.3,v 1.7 2020/10/08 16:02:38 tb Exp $
2.\" full merge up to: OpenSSL 8671b898 Jun 3 02:48:34 2008 +0000
3.\" selective merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org> and
6.\" Ben Laurie <ben@openssl.org>.
7.\" Copyright (c) 2001, 2008 The OpenSSL Project. All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: October 8 2020 $
54.Dt SSL_CTX_SET_MODE 3
55.Os
56.Sh NAME
57.Nm SSL_CTX_set_mode ,
58.Nm SSL_set_mode ,
59.Nm SSL_CTX_clear_mode ,
60.Nm SSL_clear_mode ,
61.Nm SSL_CTX_get_mode ,
62.Nm SSL_get_mode
63.Nd manipulate SSL engine mode
64.Sh SYNOPSIS
65.In openssl/ssl.h
66.Ft long
67.Fn SSL_CTX_set_mode "SSL_CTX *ctx" "long mode"
68.Ft long
69.Fn SSL_set_mode "SSL *ssl" "long mode"
70.Ft long
71.Fn SSL_CTX_clear_mode "SSL_CTX *ctx" "long mode"
72.Ft long
73.Fn SSL_clear_mode "SSL *ssl" "long mode"
74.Ft long
75.Fn SSL_CTX_get_mode "SSL_CTX *ctx"
76.Ft long
77.Fn SSL_get_mode "SSL *ssl"
78.Sh DESCRIPTION
79.Fn SSL_CTX_set_mode
80and
81.Fn SSL_set_mode
82enable the options contained in the bitmask
83.Fa mode
84for the
85.Fa ctx
86or
87.Fa ssl
88object, respectively.
89Options that were already enabled before the call are not disabled.
90.Pp
91.Fn SSL_CTX_clear_mode
92and
93.Fn SSL_clear_mode
94disable the options contained in the bitmask
95.Fa mode
96for the
97.Fa ctx
98or
99.Fa ssl
100object.
101.Pp
102.Fn SSL_CTX_get_mode
103and
104.Fn SSL_get_mode
105return a bitmask representing the options
106that are currently enabled for the
107.Fa ctx
108or
109.Fa ssl
110object.
111.Pp
112The following options are available:
113.Bl -tag -width Ds
114.It Dv SSL_MODE_ENABLE_PARTIAL_WRITE
115Allow
116.Fn SSL_write ... n
117to return
118.Ms r
119with
120.EQ
1210 < r < n
122.EN
123(i.e., report success when just a single record has been written).
124When not set (the default),
125.Xr SSL_write 3
126will only report success once the complete chunk was written.
127Once
128.Xr SSL_write 3
129returns with
130.Ms r ,
131.Ms r
132bytes have been successfully written and the next call to
133.Xr SSL_write 3
134must only send the
135.Ms n \(mi r
136bytes left, imitating the behaviour of
137.Xr write 2 .
138.It Dv SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER
139Make it possible to retry
140.Xr SSL_write 3
141with changed buffer location (the buffer contents must stay the same).
142This is not the default to avoid the misconception that non-blocking
143.Xr SSL_write 3
144behaves like non-blocking
145.Xr write 2 .
146.It Dv SSL_MODE_AUTO_RETRY
147Never bother the application with retries if the transport is blocking.
148If a renegotiation takes place during normal operation, a
149.Xr SSL_read 3
150or
151.Xr SSL_write 3
152would return
153with \(mi1 and indicate the need to retry with
154.Dv SSL_ERROR_WANT_READ .
155In a non-blocking environment applications must be prepared to handle
156incomplete read/write operations.
157In a blocking environment, applications are not always prepared to deal with
158read/write operations returning without success report.
159The flag
160.Dv SSL_MODE_AUTO_RETRY
161will cause read/write operations to only return after the handshake and
162successful completion.
163.It Dv SSL_MODE_RELEASE_BUFFERS
164When we no longer need a read buffer or a write buffer for a given
165.Vt SSL ,
166then release the memory we were using to hold it.
167Using this flag can save around 34k per idle SSL connection.
168This flag has no effect on SSL v2 connections, or on DTLS connections.
169.El
170.Sh RETURN VALUES
171.Fn SSL_CTX_set_mode ,
172.Fn SSL_set_mode ,
173.Fn SSL_CTX_clear_mode ,
174and
175.Fn SSL_clear_mode
176return the new mode bitmask after adding or clearing
177.Fa mode .
178.Pp
179.Fn SSL_CTX_get_mode
180and
181.Fn SSL_get_mode
182return the current bitmask.
183.Sh SEE ALSO
184.Xr ssl 3 ,
185.Xr SSL_CTX_ctrl 3 ,
186.Xr SSL_read 3 ,
187.Xr SSL_write 3
188.Sh HISTORY
189.Fn SSL_CTX_set_mode ,
190.Fn SSL_set_mode ,
191.Fn SSL_CTX_get_mode ,
192and
193.Fn SSL_get_mode
194first appeared in OpenSSL 0.9.4 and have been available since
195.Ox 2.6 .
196.Pp
197.Fn SSL_CTX_clear_mode
198and
199.Fn SSL_clear_mode
200first appeared in OpenSSL 0.9.8m and have been available since
201.Ox 4.9 .
202.Pp
203.Dv SSL_MODE_AUTO_RETRY
204was added in OpenSSL 0.9.6.
diff --git a/src/lib/libssl/man/SSL_CTX_set_msg_callback.3 b/src/lib/libssl/man/SSL_CTX_set_msg_callback.3
deleted file mode 100644
index a27333e6d9..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_msg_callback.3
+++ /dev/null
@@ -1,183 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_msg_callback.3,v 1.5 2021/04/15 16:43:27 tb Exp $
2.\" OpenSSL SSL_CTX_set_msg_callback.pod e9b77246 Jan 20 19:58:49 2017 +0100
3.\" OpenSSL SSL_CTX_set_msg_callback.pod b97fdb57 Nov 11 09:33:09 2016 +0100
4.\"
5.\" This file was written by Bodo Moeller <bodo@openssl.org>.
6.\" Copyright (c) 2001, 2014, 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: April 15 2021 $
53.Dt SSL_CTX_SET_MSG_CALLBACK 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_msg_callback ,
57.Nm SSL_CTX_set_msg_callback_arg ,
58.Nm SSL_set_msg_callback ,
59.Nm SSL_set_msg_callback_arg
60.Nd install callback for observing protocol messages
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft void
64.Fo SSL_CTX_set_msg_callback
65.Fa "SSL_CTX *ctx"
66.Fa "void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)"
67.Fc
68.Ft void
69.Fn SSL_CTX_set_msg_callback_arg "SSL_CTX *ctx" "void *arg"
70.Ft void
71.Fo SSL_set_msg_callback
72.Fa "SSL *ssl"
73.Fa "void (*cb)(int write_p, int version, int content_type, const void *buf, size_t len, SSL *ssl, void *arg)"
74.Fc
75.Ft void
76.Fn SSL_set_msg_callback_arg "SSL *ssl" "void *arg"
77.Sh DESCRIPTION
78.Fn SSL_CTX_set_msg_callback
79or
80.Fn SSL_set_msg_callback
81can be used to define a message callback function
82.Fa cb
83for observing all SSL/TLS protocol messages (such as handshake messages)
84that are received or sent.
85.Fn SSL_CTX_set_msg_callback_arg
86and
87.Fn SSL_set_msg_callback_arg
88can be used to set argument
89.Fa arg
90to the callback function, which is available for arbitrary application use.
91.Pp
92.Fn SSL_CTX_set_msg_callback
93and
94.Fn SSL_CTX_set_msg_callback_arg
95specify default settings that will be copied to new
96.Vt SSL
97objects by
98.Xr SSL_new 3 .
99.Fn SSL_set_msg_callback
100and
101.Fn SSL_set_msg_callback_arg
102modify the actual settings of an
103.Vt SSL
104object.
105Using a
106.Dv NULL
107pointer for
108.Fa cb
109disables the message callback.
110.Pp
111When
112.Fa cb
113is called by the SSL/TLS library for a protocol message,
114the function arguments have the following meaning:
115.Bl -tag -width Ds
116.It Fa write_p
117This flag is 0 when a protocol message has been received and 1 when a protocol
118message has been sent.
119.It Fa version
120The protocol version according to which the protocol message is
121interpreted by the library, such as
122.Dv TLS1_VERSION ,
123.Dv TLS1_1_VERSION ,
124.Dv TLS1_2_VERSION ,
125.Dv DTLS1_VERSION ,
126or
127.Dv DTLS1_2_VERSION .
128.It Fa content_type
129This is one of the
130.Em ContentType
131values defined in the protocol specification
132.Po
133.Dv SSL3_RT_CHANGE_CIPHER_SPEC ,
134.Dv SSL3_RT_ALERT ,
135.Dv SSL3_RT_HANDSHAKE ,
136but never
137.Dv SSL3_RT_APPLICATION_DATA
138because the callback will only be called for protocol messages.
139.Pc
140.It Fa buf , Fa len
141.Fa buf
142points to a buffer containing the protocol message, which consists of
143.Fa len
144bytes.
145The buffer is no longer valid after the callback function has returned.
146.It Fa ssl
147The
148.Vt SSL
149object that received or sent the message.
150.It Fa arg
151The user-defined argument optionally defined by
152.Fn SSL_CTX_set_msg_callback_arg
153or
154.Fn SSL_set_msg_callback_arg .
155.El
156.Pp
157Protocol messages are passed to the callback function after decryption
158and fragment collection where applicable.
159(Thus record boundaries are not visible.)
160.Pp
161If processing a received protocol message results in an error,
162the callback function may not be called.
163For example, the callback function will never see messages that are considered
164too large to be processed.
165.Pp
166Due to automatic protocol version negotiation,
167.Fa version
168is not necessarily the protocol version used by the sender of the message:
169If a TLS 1.0 ClientHello message is received by an SSL 3.0-only server,
170.Fa version
171will be
172.Dv SSL3_VERSION .
173.Sh SEE ALSO
174.Xr ssl 3 ,
175.Xr SSL_new 3
176.Sh HISTORY
177.Fn SSL_CTX_set_msg_callback ,
178.Fn SSL_CTX_set_msg_callback_arg ,
179.Fn SSL_set_msg_callback
180and
181.Fn SSL_set_msg_callback_arg
182first appeared in OpenSSL 0.9.7 and have been available since
183.Ox 3.2 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_num_tickets.3 b/src/lib/libssl/man/SSL_CTX_set_num_tickets.3
deleted file mode 100644
index cb6d7e000a..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_num_tickets.3
+++ /dev/null
@@ -1,63 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_num_tickets.3,v 1.2 2021/10/23 17:20:50 schwarze Exp $
2.\" OpenSSL pod checked up to: 5402f96a Sep 11 09:58:52 2021 +0100
3.\"
4.\" Copyright (c) 2021 Bob Beck <beck@openbsd.org>
5.\"
6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies.
9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\"
18.Dd $Mdocdate: October 23 2021 $
19.Dt SSL_CTX_SET_NUM_TICKETS 3
20.Os
21.Sh NAME
22.Nm SSL_CTX_set_num_tickets ,
23.Nm SSL_CTX_get_num_tickets ,
24.Nm SSL_set_num_tickets ,
25.Nm SSL_get_num_tickets
26.Nd set and get the number of TLS 1.3 session tickets to be sent
27.Sh SYNOPSIS
28.In openssl/ssl.h
29.Ft int
30.Fn SSL_CTX_set_num_tickets "SSL_CTX *ctx" "size_t num_tickets"
31.Ft size_t
32.Fn SSL_CTX_get_num_tickets "const SSL_CTX *ctx"
33.Ft int
34.Fn SSL_set_num_tickets "SSL *ssl" "size_t num_tickets"
35.Ft size_t
36.Fn SSL_get_num_tickets "const SSL *ssl"
37.Sh DESCRIPTION
38These functions set and retrieve
39the configured number of session tickets for
40.Fa ctx
41and
42.Fa ssl ,
43respectively.
44.Pp
45They are provided only for compatibility with OpenSSL
46and have no effect in LibreSSL.
47.Sh RETURN VALUES
48.Fn SSL_CTX_set_num_tickets
49and
50.Fn SSL_set_num_tickets
51always return 1.
52.Pp
53.Fn SSL_CTX_get_num_tickets
54and
55.Fn SSL_get_num_tickets
56return the previously set number of tickets, or 0 if it has not been set.
57.Sh SEE ALSO
58.Xr ssl 3 ,
59.Xr SSL_CTX_new 3
60.Sh HISTORY
61These function first appeared in OpenSSL 1.1.1
62and have been available since
63.Ox 7.1 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_options.3 b/src/lib/libssl/man/SSL_CTX_set_options.3
deleted file mode 100644
index 5df0b07785..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_options.3
+++ /dev/null
@@ -1,374 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_options.3,v 1.16 2022/03/31 17:27:18 naddy Exp $
2.\" full merge up to: OpenSSL 7946ab33 Dec 6 17:56:41 2015 +0100
3.\" selective merge up to: OpenSSL edb79c3a Mar 29 10:07:14 2017 +1000
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>,
6.\" Bodo Moeller <bodo@openssl.org>, and
7.\" Dr. Stephen Henson <steve@openssl.org>.
8.\" Copyright (c) 2001-2003, 2005, 2007, 2009, 2010, 2013-2015
9.\" The OpenSSL Project. All rights reserved.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\"
15.\" 1. Redistributions of source code must retain the above copyright
16.\" notice, this list of conditions and the following disclaimer.
17.\"
18.\" 2. Redistributions in binary form must reproduce the above copyright
19.\" notice, this list of conditions and the following disclaimer in
20.\" the documentation and/or other materials provided with the
21.\" distribution.
22.\"
23.\" 3. All advertising materials mentioning features or use of this
24.\" software must display the following acknowledgment:
25.\" "This product includes software developed by the OpenSSL Project
26.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
27.\"
28.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
29.\" endorse or promote products derived from this software without
30.\" prior written permission. For written permission, please contact
31.\" openssl-core@openssl.org.
32.\"
33.\" 5. Products derived from this software may not be called "OpenSSL"
34.\" nor may "OpenSSL" appear in their names without prior written
35.\" permission of the OpenSSL Project.
36.\"
37.\" 6. Redistributions of any form whatsoever must retain the following
38.\" acknowledgment:
39.\" "This product includes software developed by the OpenSSL Project
40.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
41.\"
42.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
43.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
46.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53.\" OF THE POSSIBILITY OF SUCH DAMAGE.
54.\"
55.Dd $Mdocdate: March 31 2022 $
56.Dt SSL_CTX_SET_OPTIONS 3
57.Os
58.Sh NAME
59.Nm SSL_CTX_set_options ,
60.Nm SSL_set_options ,
61.Nm SSL_CTX_clear_options ,
62.Nm SSL_clear_options ,
63.Nm SSL_CTX_get_options ,
64.Nm SSL_get_options ,
65.Nm SSL_get_secure_renegotiation_support
66.Nd manipulate SSL options
67.Sh SYNOPSIS
68.In openssl/ssl.h
69.Ft long
70.Fn SSL_CTX_set_options "SSL_CTX *ctx" "long options"
71.Ft long
72.Fn SSL_set_options "SSL *ssl" "long options"
73.Ft long
74.Fn SSL_CTX_clear_options "SSL_CTX *ctx" "long options"
75.Ft long
76.Fn SSL_clear_options "SSL *ssl" "long options"
77.Ft long
78.Fn SSL_CTX_get_options "SSL_CTX *ctx"
79.Ft long
80.Fn SSL_get_options "SSL *ssl"
81.Ft long
82.Fn SSL_get_secure_renegotiation_support "SSL *ssl"
83.Sh DESCRIPTION
84.Fn SSL_CTX_set_options
85adds the options set via bitmask in
86.Fa options
87to
88.Fa ctx .
89Options already set before are not cleared!
90.Pp
91.Fn SSL_set_options
92adds the options set via bitmask in
93.Fa options
94to
95.Fa ssl .
96Options already set before are not cleared!
97.Pp
98.Fn SSL_CTX_clear_options
99clears the options set via bitmask in
100.Fa options
101to
102.Fa ctx .
103.Pp
104.Fn SSL_clear_options
105clears the options set via bitmask in
106.Fa options
107to
108.Fa ssl .
109.Pp
110.Fn SSL_CTX_get_options
111returns the options set for
112.Fa ctx .
113.Pp
114.Fn SSL_get_options
115returns the options set for
116.Fa ssl .
117.Pp
118.Fn SSL_get_secure_renegotiation_support
119indicates whether the peer supports secure renegotiation.
120.Pp
121All these functions are implemented using macros.
122.Pp
123The behaviour of the SSL library can be changed by setting several options.
124The options are coded as bitmasks and can be combined by a bitwise OR
125operation (|).
126.Pp
127.Fn SSL_CTX_set_options
128and
129.Fn SSL_set_options
130affect the (external) protocol behaviour of the SSL library.
131The (internal) behaviour of the API can be changed by using the similar
132.Xr SSL_CTX_set_mode 3
133and
134.Xr SSL_set_mode 3
135functions.
136.Pp
137During a handshake, the option settings of the SSL object are used.
138When a new SSL object is created from a context using
139.Xr SSL_new 3 ,
140the current option setting is copied.
141Changes to
142.Fa ctx
143do not affect already created
144.Vt SSL
145objects.
146.Fn SSL_clear
147does not affect the settings.
148.Pp
149The following
150.Em bug workaround
151options are available:
152.Bl -tag -width Ds
153.It Dv SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
154Disables a countermeasure against a TLS 1.0 protocol vulnerability
155affecting CBC ciphers, which cannot be handled by some broken SSL
156implementations.
157This option has no effect for connections using other ciphers.
158.It Dv SSL_OP_ALL
159This is currently an alias for
160.Dv SSL_OP_LEGACY_SERVER_CONNECT .
161.El
162.Pp
163It is usually safe to use
164.Dv SSL_OP_ALL
165to enable the bug workaround options if compatibility with somewhat broken
166implementations is desired.
167.Pp
168The following
169.Em modifying
170options are available:
171.Bl -tag -width Ds
172.It Dv SSL_OP_CIPHER_SERVER_PREFERENCE
173When choosing a cipher, use the server's preferences instead of the client
174preferences.
175When not set, the server will always follow the client's preferences.
176When set, the server will choose following its own preferences.
177.It Dv SSL_OP_COOKIE_EXCHANGE
178Turn on Cookie Exchange as described in RFC 4347 Section 4.2.1.
179Only affects DTLS connections.
180.It Dv SSL_OP_LEGACY_SERVER_CONNECT
181Allow legacy insecure renegotiation between OpenSSL and unpatched servers
182.Em only :
183this option is currently set by default.
184See the
185.Sx SECURE RENEGOTIATION
186section for more details.
187.It Dv SSL_OP_NO_DTLSv1
188Do not use the DTLSv1 protocol.
189Deprecated; use
190.Xr SSL_CTX_set_min_proto_version 3
191instead.
192.It Dv SSL_OP_NO_DTLSv1_2
193Do not use the DTLSv1.2 protocol.
194Deprecated; use
195.Xr SSL_CTX_set_min_proto_version 3
196instead.
197.It Dv SSL_OP_NO_QUERY_MTU
198Do not query the MTU.
199Only affects DTLS connections.
200.It Dv SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
201When performing renegotiation as a server, always start a new session (i.e.,
202session resumption requests are only accepted in the initial handshake).
203This option is not needed for clients.
204.It Dv SSL_OP_NO_TICKET
205Normally clients and servers using TLSv1.2 and earlier will, where possible,
206transparently make use of
207RFC 5077 tickets for stateless session resumption.
208.Pp
209If this option is set, this functionality is disabled and tickets will not be
210used by clients or servers.
211.It Dv SSL_OP_NO_TLSv1
212Do not use the TLSv1.0 protocol.
213Deprecated; use
214.Xr SSL_CTX_set_min_proto_version 3
215instead.
216.It Dv SSL_OP_NO_TLSv1_1
217Do not use the TLSv1.1 protocol.
218Deprecated; use
219.Xr SSL_CTX_set_min_proto_version 3
220instead.
221.It Dv SSL_OP_NO_TLSv1_2
222Do not use the TLSv1.2 protocol.
223Deprecated; use
224.Xr SSL_CTX_set_max_proto_version 3
225instead.
226.El
227.Pp
228The following options used to be supported at some point in the past
229and no longer have any effect:
230.Dv SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION ,
231.Dv SSL_OP_EPHEMERAL_RSA ,
232.Dv SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER ,
233.Dv SSL_OP_MICROSOFT_SESS_ID_BUG ,
234.Dv SSL_OP_NETSCAPE_CA_DN_BUG ,
235.Dv SSL_OP_NETSCAPE_CHALLENGE_BUG ,
236.Dv SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG ,
237.Dv SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG ,
238.Dv SSL_OP_NO_COMPRESSION ,
239.Dv SSL_OP_NO_SSLv2 ,
240.Dv SSL_OP_NO_SSLv3 ,
241.Dv SSL_OP_PKCS1_CHECK_1 ,
242.Dv SSL_OP_PKCS1_CHECK_2 ,
243.Dv SSL_OP_SAFARI_ECDHE_ECDSA_BUG ,
244.Dv SSL_OP_SINGLE_DH_USE ,
245.Dv SSL_OP_SINGLE_ECDH_USE ,
246.Dv SSL_OP_SSLEAY_080_CLIENT_DH_BUG ,
247.Dv SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG ,
248.Dv SSL_OP_TLS_BLOCK_PADDING_BUG ,
249.Dv SSL_OP_TLS_D5_BUG ,
250.Dv SSL_OP_TLS_ROLLBACK_BUG ,
251.Dv SSL_OP_TLSEXT_PADDING .
252.Sh SECURE RENEGOTIATION
253OpenSSL 0.9.8m and later always attempts to use secure renegotiation as
254described in RFC 5746.
255This counters the prefix attack described in CVE-2009-3555 and elsewhere.
256.Pp
257This attack has far-reaching consequences which application writers should be
258aware of.
259In the description below an implementation supporting secure renegotiation is
260referred to as
261.Dq patched .
262A server not supporting secure
263renegotiation is referred to as
264.Dq unpatched .
265.Pp
266The following sections describe the operations permitted by OpenSSL's secure
267renegotiation implementation.
268.Ss Patched client and server
269Connections and renegotiation are always permitted by OpenSSL implementations.
270.Ss Unpatched client and patched OpenSSL server
271The initial connection succeeds but client renegotiation is denied by the
272server with a
273.Em no_renegotiation
274warning alert.
275.Pp
276If the patched OpenSSL server attempts to renegotiate, a fatal
277.Em handshake_failure
278alert is sent.
279This is because the server code may be unaware of the unpatched nature of the
280client.
281.Pp
282Note that a bug in OpenSSL clients earlier than 0.9.8m (all of which
283are unpatched) will result in the connection hanging if it receives a
284.Em no_renegotiation
285alert.
286OpenSSL versions 0.9.8m and later will regard a
287.Em no_renegotiation
288alert as fatal and respond with a fatal
289.Em handshake_failure
290alert.
291This is because the OpenSSL API currently has no provision to indicate to an
292application that a renegotiation attempt was refused.
293.Ss Patched OpenSSL client and unpatched server
294If the option
295.Dv SSL_OP_LEGACY_SERVER_CONNECT
296is set then initial connections and renegotiation between patched OpenSSL
297clients and unpatched servers succeeds.
298If neither option is set then initial connections to unpatched servers will
299fail.
300.Pp
301The option
302.Dv SSL_OP_LEGACY_SERVER_CONNECT
303is currently set by default even though it has security implications:
304otherwise it would be impossible to connect to unpatched servers (i.e., all of
305them initially) and this is clearly not acceptable.
306Renegotiation is permitted because this does not add any additional security
307issues: during an attack clients do not see any renegotiations anyway.
308.Pp
309As more servers become patched, the option
310.Dv SSL_OP_LEGACY_SERVER_CONNECT
311will
312.Em not
313be set by default in a future version of OpenSSL.
314.Pp
315OpenSSL client applications wishing to ensure they can connect to unpatched
316servers should always
317.Em set
318.Dv SSL_OP_LEGACY_SERVER_CONNECT .
319.Pp
320OpenSSL client applications that want to ensure they can
321.Em not
322connect to unpatched servers (and thus avoid any security issues) should always
323.Em clear
324.Dv SSL_OP_LEGACY_SERVER_CONNECT
325using
326.Fn SSL_CTX_clear_options
327or
328.Fn SSL_clear_options .
329.Sh RETURN VALUES
330.Fn SSL_CTX_set_options
331and
332.Fn SSL_set_options
333return the new options bitmask after adding
334.Fa options .
335.Pp
336.Fn SSL_CTX_clear_options
337and
338.Fn SSL_clear_options
339return the new options bitmask after clearing
340.Fa options .
341.Pp
342.Fn SSL_CTX_get_options
343and
344.Fn SSL_get_options
345return the current bitmask.
346.Pp
347.Fn SSL_get_secure_renegotiation_support
348returns 1 is the peer supports secure renegotiation and 0 if it does not.
349.Sh SEE ALSO
350.Xr openssl 1 ,
351.Xr ssl 3 ,
352.Xr SSL_clear 3 ,
353.Xr SSL_CTX_ctrl 3 ,
354.Xr SSL_CTX_set_min_proto_version 3 ,
355.Xr SSL_new 3
356.Sh HISTORY
357.Fn SSL_CTX_set_options
358and
359.Fn SSL_set_options
360first appeared in SSLeay 0.9.0 and have been available since
361.Ox 2.4 .
362.Pp
363.Fn SSL_CTX_get_options
364and
365.Fn SSL_get_options
366first appeared in OpenSSL 0.9.2b and have been available since
367.Ox 2.6 .
368.Pp
369.Fn SSL_CTX_clear_options ,
370.Fn SSL_clear_options ,
371and
372.Fn SSL_get_secure_renegotiation_support
373first appeared in OpenSSL 0.9.8m and have been available since
374.Ox 4.9 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_quiet_shutdown.3 b/src/lib/libssl/man/SSL_CTX_set_quiet_shutdown.3
deleted file mode 100644
index 71463f1eca..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_quiet_shutdown.3
+++ /dev/null
@@ -1,161 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_quiet_shutdown.3,v 1.6 2020/03/30 10:28:59 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 30 2020 $
52.Dt SSL_CTX_SET_QUIET_SHUTDOWN 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_quiet_shutdown ,
56.Nm SSL_CTX_get_quiet_shutdown ,
57.Nm SSL_set_quiet_shutdown ,
58.Nm SSL_get_quiet_shutdown
59.Nd manipulate shutdown behaviour
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft void
63.Fn SSL_CTX_set_quiet_shutdown "SSL_CTX *ctx" "int mode"
64.Ft int
65.Fn SSL_CTX_get_quiet_shutdown "const SSL_CTX *ctx"
66.Ft void
67.Fn SSL_set_quiet_shutdown "SSL *ssl" "int mode"
68.Ft int
69.Fn SSL_get_quiet_shutdown "const SSL *ssl"
70.Sh DESCRIPTION
71.Fn SSL_CTX_set_quiet_shutdown
72sets the
73.Dq quiet shutdown
74flag for
75.Fa ctx
76to be
77.Fa mode .
78.Vt SSL
79objects created from
80.Fa ctx
81inherit the
82.Fa mode
83valid at the time
84.Xr SSL_new 3
85is called.
86.Fa mode
87may be 0 or 1.
88.Pp
89.Fn SSL_CTX_get_quiet_shutdown
90returns the
91.Dq quiet shutdown
92setting of
93.Fa ctx .
94.Pp
95.Fn SSL_set_quiet_shutdown
96sets the
97.Dq quiet shutdown
98flag for
99.Fa ssl
100to be
101.Fa mode .
102The setting stays valid until
103.Fa ssl
104is removed with
105.Xr SSL_free 3
106or
107.Fn SSL_set_quiet_shutdown
108is called again.
109It is not changed when
110.Xr SSL_clear 3
111is called.
112.Fa mode
113may be 0 or 1.
114.Pp
115.Fn SSL_get_quiet_shutdown
116returns the
117.Dq quiet shutdown
118setting of
119.Fa ssl .
120.Pp
121Normally when a SSL connection is finished, the parties must send out
122.Dq close notify
123alert messages using
124.Xr SSL_shutdown 3
125for a clean shutdown.
126.Pp
127When setting the
128.Dq quiet shutdown
129flag to 1,
130.Xr SSL_shutdown 3
131will set the internal flags to
132.Dv SSL_SENT_SHUTDOWN Ns | Ns Dv SSL_RECEIVED_SHUTDOWN
133.Po
134.Xr SSL_shutdown 3
135then behaves like
136.Xr SSL_set_shutdown 3
137called with
138.Dv SSL_SENT_SHUTDOWN Ns | Ns Dv SSL_RECEIVED_SHUTDOWN
139.Pc .
140The session is thus considered to be shut down, but no
141.Dq close notify
142alert is sent to the peer.
143This behaviour violates the TLS standard.
144.Pp
145The default is normal shutdown behaviour as described by the TLS standard.
146.Sh RETURN VALUES
147.Fn SSL_CTX_get_quiet_shutdown
148and
149.Fn SSL_get_quiet_shutdown
150return the current setting.
151.Sh SEE ALSO
152.Xr ssl 3 ,
153.Xr SSL_clear 3 ,
154.Xr SSL_free 3 ,
155.Xr SSL_new 3 ,
156.Xr SSL_set_shutdown 3 ,
157.Xr SSL_shutdown 3
158.Sh HISTORY
159These functions first appeared in SSLeay 0.8.1
160and have been available since
161.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_read_ahead.3 b/src/lib/libssl/man/SSL_CTX_set_read_ahead.3
deleted file mode 100644
index eae76eb472..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_read_ahead.3
+++ /dev/null
@@ -1,144 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_read_ahead.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>.
5.\" Copyright (c) 2015, 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_SET_READ_AHEAD 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_read_ahead ,
56.Nm SSL_CTX_get_read_ahead ,
57.Nm SSL_set_read_ahead ,
58.Nm SSL_get_read_ahead ,
59.Nm SSL_CTX_get_default_read_ahead
60.Nd manage whether to read as many input bytes as possible
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft void
64.Fo SSL_CTX_set_read_ahead
65.Fa "SSL_CTX *ctx"
66.Fa "int yes"
67.Fc
68.Ft long
69.Fo SSL_CTX_get_read_ahead
70.Fa "SSL_CTX *ctx"
71.Fc
72.Ft void
73.Fo SSL_set_read_ahead
74.Fa "SSL *s"
75.Fa "int yes"
76.Fc
77.Ft long
78.Fo SSL_get_read_ahead
79.Fa "const SSL *s"
80.Fc
81.Ft long
82.Fo SSL_CTX_get_default_read_ahead
83.Fa "SSL_CTX *ctx"
84.Fc
85.Sh DESCRIPTION
86.Fn SSL_CTX_set_read_ahead
87and
88.Fn SSL_set_read_ahead
89set whether as many input bytes as possible are read for non-blocking
90reads.
91For example if
92.Ar x
93bytes are currently required by OpenSSL, but
94.Ar y
95bytes are available from the underlying BIO (where
96.Ar y No > Ar x ) ,
97then OpenSSL will read all
98.Ar y
99bytes into its buffer (provided that the buffer is large enough) if
100reading ahead is on, or
101.Ar x
102bytes otherwise.
103The parameter
104.Fa yes
105should be 0 to ensure reading ahead is off, or non zero otherwise.
106.Pp
107.Fn SSL_CTX_get_read_ahead
108and
109.Fn SSL_get_read_ahead
110indicate whether reading ahead is set or not.
111.Pp
112.Fn SSL_CTX_get_default_read_ahead
113is identical to
114.Fn SSL_CTX_get_read_ahead .
115.Pp
116These functions are implemented as macros.
117.Pp
118These functions have no effect when used with DTLS.
119.Sh RETURN VALUES
120.Fn SSL_CTX_get_read_ahead
121and
122.Fn SSL_get_read_ahead
123return 0 if reading ahead is off or non-zero otherwise,
124except that the return values are undefined for DTLS.
125.Sh SEE ALSO
126.Xr ssl 3 ,
127.Xr SSL_pending 3
128.Sh HISTORY
129.Fn SSL_set_read_ahead
130and
131.Fn SSL_get_read_ahead
132appeared in SSLeay 0.4 or earlier and have been available since
133.Ox 2.4 .
134.Pp
135.Fn SSL_CTX_set_read_ahead ,
136.Fn SSL_CTX_get_read_ahead ,
137and
138.Fn SSL_CTX_get_default_read_ahead
139first appeared in OpenSSL 0.9.2b and have been available since
140.Ox 2.6 .
141.Sh CAVEATS
142Switching read ahead on can impact the behaviour of the
143.Xr SSL_pending 3
144function.
diff --git a/src/lib/libssl/man/SSL_CTX_set_security_level.3 b/src/lib/libssl/man/SSL_CTX_set_security_level.3
deleted file mode 100644
index 89adb3d65d..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_security_level.3
+++ /dev/null
@@ -1,159 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_security_level.3,v 1.2 2025/01/18 10:45:12 tb Exp $
2.\"
3.\" Copyright (c) 2022 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: January 18 2025 $
18.Dt SSL_CTX_SET_SECURITY_LEVEL 3
19.Os
20.Sh NAME
21.Nm SSL_CTX_set_security_level ,
22.Nm SSL_set_security_level ,
23.Nm SSL_CTX_get_security_level ,
24.Nm SSL_get_security_level
25.Nd change security level for TLS
26.Sh SYNOPSIS
27.In openssl/ssl.h
28.Ft void
29.Fo SSL_CTX_set_security_level
30.Fa "SSL_CTX *ctx"
31.Fa "int level"
32.Fc
33.Ft void
34.Fo SSL_set_security_level
35.Fa "SSL *s"
36.Fa "int level"
37.Fc
38.Ft int
39.Fo SSL_CTX_get_security_level
40.Fa "const SSL_CTX *ctx"
41.Fc
42.Ft int
43.Fo SSL_get_security_level
44.Fa "const SSL *s"
45.Fc
46.Sh DESCRIPTION
47A security level is a set of restrictions on algorithms, key lengths,
48protocol versions, and other features in TLS connections.
49These restrictions apply in addition to those that exist from individually
50selecting supported features, for example ciphers, curves, or algorithms.
51.Pp
52The following table shows properties of the various security levels:
53.Bl -column # sec 15360 ECC TLS SHA1 -offset indent
54.It # Ta sec Ta \0\0RSA Ta ECC Ta TLS Ta MAC
55.It 0 Ta \0\00 Ta \0\0\0\00 Ta \0\00 Ta 1.0 Ta MD5
56.It 1 Ta \080 Ta \01024 Ta 160 Ta 1.0 Ta RC4
57.It 2 Ta 112 Ta \02048 Ta 224 Ta 1.0 Ta
58.It 3 Ta 128 Ta \03072 Ta 256 Ta 1.1 Ta SHA1
59.It 4 Ta 192 Ta \07680 Ta 384 Ta 1.2 Ta
60.It 5 Ta 256 Ta 15360 Ta 512 Ta 1.2 Ta
61.El
62.Pp
63The meaning of the columns is as follows:
64.Pp
65.Bl -tag -width features -compact
66.It #
67The number of the
68.Fa level .
69.It sec
70The minimum security strength measured in bits, which is approximately
71the binary logarithm of the number of operations an attacker has
72to perform in order to break a cryptographic key.
73This minimum strength is enforced for all relevant parameters
74including cipher suite encryption algorithms, ECC curves, signature
75algorithms, DH parameter sizes, and certificate algorithms and key
76sizes.
77See SP800-57 below
78.Sx SEE ALSO
79for details on individual algorithms.
80.It RSA
81The minimum key length in bits for the RSA and DH algorithms.
82.It ECC
83The minimum key length in bits for ECC algorithms.
84.It TLS
85The minimum TLS protocol version.
86.It MAC
87Cipher suites using the given MACs are allowed on this level
88and on lower levels, but not on higher levels.
89.El
90.Pp
91Level 0 is only provided for backward compatibility and permits everything.
92.Pp
93Level 3 and higher disable support for session tickets
94and only accept cipher suites that provide forward secrecy.
95.Pp
96The functions
97.Fn SSL_CTX_set_security_level
98and
99.Fn SSL_set_security_level
100choose the security
101.Fa level
102for
103.Fa ctx
104or
105.Fa s ,
106respectively.
107If not set, security level 1 is used.
108.Pp
109.Xr SSL_CTX_new 3
110initializes the security level of the new object to 1.
111.Pp
112.Xr SSL_new 3
113and
114.Xr SSL_set_SSL_CTX 3
115copy the security level from the context to the SSL object.
116.Pp
117.Xr SSL_dup 3
118copies the security level from the old to the new object.
119.Sh RETURN VALUES
120.Fn SSL_CTX_get_security_level
121and
122.Fn SSL_get_security_level
123return the security level configured in
124.Fa ctx
125or
126.Fa s ,
127respectively.
128.Sh SEE ALSO
129.Xr EVP_PKEY_security_bits 3 ,
130.Xr RSA_security_bits 3 ,
131.Xr ssl 3 ,
132.Xr SSL_CTX_new 3 ,
133.Xr SSL_new 3
134.Rs
135.%A Elaine Barker
136.%T Recommendation for Key Management
137.%I U.S. National Institute of Standards and Technology
138.%R NIST Special Publication 800-57 Part 1 Revision 5
139.%U https://doi.org/10.6028/NIST.SP.800-57pt1r5
140.%C Gaithersburg, MD
141.%D May 2020
142.Re
143.Sh HISTORY
144These functions first appeared in OpenSSL 1.1.0
145and have been available since
146.Ox 7.2 .
147.Sh CAVEATS
148Applications which do not check the return values
149of configuration functions will misbehave.
150For example, if an application does not check the return value
151after trying to set a certificate and the certificate is rejected
152because of the security level, the application may behave as if
153no certificate had been provided at all.
154.Pp
155While some restrictions may be handled gracefully by negotiations
156between the client and the server, other restrictions may be
157fatal and abort the TLS handshake.
158For example, this can happen if the peer certificate contains a key
159that is too short or if the DH parameter size is too small.
diff --git a/src/lib/libssl/man/SSL_CTX_set_session_cache_mode.3 b/src/lib/libssl/man/SSL_CTX_set_session_cache_mode.3
deleted file mode 100644
index 1fe67b2a7e..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_session_cache_mode.3
+++ /dev/null
@@ -1,198 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_session_cache_mode.3,v 1.7 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL 67adf0a7 Dec 25 19:58:38 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org> and
5.\" Geoff Thorpe <geoff@openssl.org>.
6.\" Copyright (c) 2001, 2002 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 12 2019 $
53.Dt SSL_CTX_SET_SESSION_CACHE_MODE 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_session_cache_mode ,
57.Nm SSL_CTX_get_session_cache_mode
58.Nd enable/disable session caching
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft long
62.Fn SSL_CTX_set_session_cache_mode "SSL_CTX ctx" "long mode"
63.Ft long
64.Fn SSL_CTX_get_session_cache_mode "SSL_CTX ctx"
65.Sh DESCRIPTION
66.Fn SSL_CTX_set_session_cache_mode
67enables/disables session caching by setting the operational mode for
68.Ar ctx
69to
70.Ar mode .
71.Pp
72.Fn SSL_CTX_get_session_cache_mode
73returns the currently used cache mode.
74.Pp
75The OpenSSL library can store/retrieve SSL/TLS sessions for later reuse.
76The sessions can be held in memory for each
77.Fa ctx ,
78if more than one
79.Vt SSL_CTX
80object is being maintained, the sessions are unique for each
81.Vt SSL_CTX
82object.
83.Pp
84In order to reuse a session, a client must send the session's id to the server.
85It can only send exactly one id.
86The server then either agrees to reuse the session or it starts a full
87handshake (to create a new session).
88.Pp
89A server will look up the session in its internal session storage.
90If the session is not found in internal storage or lookups for the internal
91storage have been deactivated
92.Pq Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP ,
93the server will try the external storage if available.
94.Pp
95Since a client may try to reuse a session intended for use in a different
96context, the session id context must be set by the server (see
97.Xr SSL_CTX_set_session_id_context 3 ) .
98.Pp
99The following session cache modes and modifiers are available:
100.Bl -tag -width Ds
101.It Dv SSL_SESS_CACHE_OFF
102No session caching for client or server takes place.
103.It Dv SSL_SESS_CACHE_CLIENT
104Client sessions are added to the session cache.
105As there is no reliable way for the OpenSSL library to know whether a session
106should be reused or which session to choose (due to the abstract BIO layer the
107SSL engine does not have details about the connection),
108the application must select the session to be reused by using the
109.Xr SSL_set_session 3
110function.
111This option is not activated by default.
112.It Dv SSL_SESS_CACHE_SERVER
113Server sessions are added to the session cache.
114When a client proposes a session to be reused, the server looks for the
115corresponding session in (first) the internal session cache (unless
116.Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP
117is set), then (second) in the external cache if available.
118If the session is found, the server will try to reuse the session.
119This is the default.
120.It Dv SSL_SESS_CACHE_BOTH
121Enable both
122.Dv SSL_SESS_CACHE_CLIENT
123and
124.Dv SSL_SESS_CACHE_SERVER
125at the same time.
126.It Dv SSL_SESS_CACHE_NO_AUTO_CLEAR
127Normally the session cache is checked for expired sessions every 255
128connections using the
129.Xr SSL_CTX_flush_sessions 3
130function.
131Since this may lead to a delay which cannot be controlled,
132the automatic flushing may be disabled and
133.Xr SSL_CTX_flush_sessions 3
134can be called explicitly by the application.
135.It Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP
136By setting this flag, session-resume operations in an SSL/TLS server will not
137automatically look up sessions in the internal cache,
138even if sessions are automatically stored there.
139If external session caching callbacks are in use,
140this flag guarantees that all lookups are directed to the external cache.
141As automatic lookup only applies for SSL/TLS servers,
142the flag has no effect on clients.
143.It Dv SSL_SESS_CACHE_NO_INTERNAL_STORE
144Depending on the presence of
145.Dv SSL_SESS_CACHE_CLIENT
146and/or
147.Dv SSL_SESS_CACHE_SERVER ,
148sessions negotiated in an SSL/TLS handshake may be cached for possible reuse.
149Normally a new session is added to the internal cache as well as any external
150session caching (callback) that is configured for the
151.Vt SSL_CTX .
152This flag will prevent sessions being stored in the internal cache
153(though the application can add them manually using
154.Xr SSL_CTX_add_session 3 ) .
155Note:
156in any SSL/TLS servers where external caching is configured, any successful
157session lookups in the external cache (e.g., for session-resume requests) would
158normally be copied into the local cache before processing continues \(en this
159flag prevents these additions to the internal cache as well.
160.It Dv SSL_SESS_CACHE_NO_INTERNAL
161Enable both
162.Dv SSL_SESS_CACHE_NO_INTERNAL_LOOKUP
163and
164.Dv SSL_SESS_CACHE_NO_INTERNAL_STORE
165at the same time.
166.El
167.Pp
168The default mode is
169.Dv SSL_SESS_CACHE_SERVER .
170.Sh RETURN VALUES
171.Fn SSL_CTX_set_session_cache_mode
172returns the previously set cache mode.
173.Pp
174.Fn SSL_CTX_get_session_cache_mode
175returns the currently set cache mode.
176.Sh SEE ALSO
177.Xr ssl 3 ,
178.Xr SSL_CTX_add_session 3 ,
179.Xr SSL_CTX_ctrl 3 ,
180.Xr SSL_CTX_flush_sessions 3 ,
181.Xr SSL_CTX_sess_number 3 ,
182.Xr SSL_CTX_sess_set_cache_size 3 ,
183.Xr SSL_CTX_sess_set_get_cb 3 ,
184.Xr SSL_CTX_set_session_id_context 3 ,
185.Xr SSL_CTX_set_timeout 3 ,
186.Xr SSL_session_reused 3 ,
187.Xr SSL_set_session 3
188.Sh HISTORY
189.Fn SSL_CTX_set_session_cache_mode
190and
191.Fn SSL_CTX_get_session_cache_mode
192first appeared in SSLeay 0.6.1 and have been available since
193.Ox 2.4 .
194.Pp
195.Dv SSL_SESS_CACHE_NO_INTERNAL_STORE
196and
197.Dv SSL_SESS_CACHE_NO_INTERNAL
198were introduced in OpenSSL 0.9.6h.
diff --git a/src/lib/libssl/man/SSL_CTX_set_session_id_context.3 b/src/lib/libssl/man/SSL_CTX_set_session_id_context.3
deleted file mode 100644
index 06fd9348ae..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_session_id_context.3
+++ /dev/null
@@ -1,160 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_session_id_context.3,v 1.6 2019/06/08 15:25:43 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2004 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 8 2019 $
52.Dt SSL_CTX_SET_SESSION_ID_CONTEXT 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_session_id_context ,
56.Nm SSL_set_session_id_context
57.Nd set context within which session can be reused (server side only)
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft int
61.Fo SSL_CTX_set_session_id_context
62.Fa "SSL_CTX *ctx"
63.Fa "const unsigned char *sid_ctx"
64.Fa "unsigned int sid_ctx_len"
65.Fc
66.Ft int
67.Fo SSL_set_session_id_context
68.Fa "SSL *ssl"
69.Fa "const unsigned char *sid_ctx"
70.Fa "unsigned int sid_ctx_len"
71.Fc
72.Sh DESCRIPTION
73.Fn SSL_CTX_set_session_id_context
74sets the context
75.Fa sid_ctx
76of length
77.Fa sid_ctx_len
78within which a session can be reused for the
79.Fa ctx
80object.
81.Pp
82.Fn SSL_set_session_id_context
83sets the context
84.Fa sid_ctx
85of length
86.Fa sid_ctx_len
87within which a session can be reused for the
88.Fa ssl
89object.
90.Pp
91Sessions are generated within a certain context.
92When exporting/importing sessions with
93.Xr i2d_SSL_SESSION 3
94and
95.Xr d2i_SSL_SESSION 3 ,
96it would be possible to re-import a session generated from another context
97(e.g., another application), which might lead to malfunctions.
98Therefore each application must set its own session id context
99.Fa sid_ctx
100which is used to distinguish the contexts and is stored in exported sessions.
101The
102.Fa sid_ctx
103can be any kind of binary data with a given length; it is therefore possible
104to use, for instance, the name of the application, the hostname, the service
105name...
106.Pp
107The session id context becomes part of the session.
108The session id context is set by the SSL/TLS server.
109The
110.Fn SSL_CTX_set_session_id_context
111and
112.Fn SSL_set_session_id_context
113functions are therefore only useful on the server side.
114.Pp
115OpenSSL clients will check the session id context returned by the server when
116reusing a session.
117.Pp
118The maximum length of the
119.Fa sid_ctx
120is limited to
121.Dv SSL_MAX_SSL_SESSION_ID_LENGTH .
122.Sh WARNINGS
123If the session id context is not set on an SSL/TLS server and client
124certificates are used, stored sessions will not be reused but a fatal error
125will be flagged and the handshake will fail.
126.Pp
127If a server returns a different session id context to an OpenSSL client
128when reusing a session, an error will be flagged and the handshake will
129fail.
130OpenSSL servers will always return the correct session id context,
131as an OpenSSL server checks the session id context itself before reusing
132a session as described above.
133.Sh RETURN VALUES
134.Fn SSL_CTX_set_session_id_context
135and
136.Fn SSL_set_session_id_context
137return the following values:
138.Bl -tag -width Ds
139.It 0
140The length
141.Fa sid_ctx_len
142of the session id context
143.Fa sid_ctx
144exceeded
145the maximum allowed length of
146.Dv SSL_MAX_SSL_SESSION_ID_LENGTH .
147The error is logged to the error stack.
148.It 1
149The operation succeeded.
150.El
151.Sh SEE ALSO
152.Xr ssl 3 ,
153.Xr SSL_SESSION_set1_id_context 3
154.Sh HISTORY
155.Fn SSL_set_session_id_context
156first appeared in OpenSSL 0.9.2b.
157.Fn SSL_CTX_set_session_id_context
158first appeared in OpenSSL 0.9.3.
159Both functions have been available since
160.Ox 2.6 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_ssl_version.3 b/src/lib/libssl/man/SSL_CTX_set_ssl_version.3
deleted file mode 100644
index b1bdb92bb0..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_ssl_version.3
+++ /dev/null
@@ -1,146 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_ssl_version.3,v 1.5 2021/05/11 19:48:56 tb Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: May 11 2021 $
52.Dt SSL_CTX_SET_SSL_VERSION 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_ssl_version ,
56.Nm SSL_set_ssl_method ,
57.Nm SSL_CTX_get_ssl_method ,
58.Nm SSL_get_ssl_method
59.Nd choose a new TLS/SSL method
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft int
63.Fn SSL_CTX_set_ssl_version "SSL_CTX *ctx" "const SSL_METHOD *method"
64.Ft int
65.Fn SSL_set_ssl_method "SSL *s" "const SSL_METHOD *method"
66.Ft const SSL_METHOD *
67.Fn SSL_CTX_get_ssl_method "SSL_CTX *ctx"
68.Ft const SSL_METHOD *
69.Fn SSL_get_ssl_method "SSL *ssl"
70.Sh DESCRIPTION
71.Fn SSL_CTX_set_ssl_version
72sets a new default TLS/SSL
73.Fa method
74for
75.Vt SSL
76objects newly created from this
77.Fa ctx .
78.Vt SSL
79objects already created with
80.Xr SSL_new 3
81are not affected, except when
82.Xr SSL_clear 3
83is called.
84.Pp
85.Fn SSL_set_ssl_method
86sets a new TLS/SSL
87.Fa method
88for a particular
89.Vt SSL
90object
91.Fa s .
92It may be reset when
93.Xr SSL_clear 3
94is called.
95.Pp
96.Fn SSL_CTX_get_ssl_method
97and
98.Fn SSL_get_ssl_method
99return a function pointer to the TLS/SSL method set in
100.Fa ctx
101and
102.Fa ssl ,
103respectively.
104.Pp
105The available
106.Fa method
107choices are described in
108.Xr SSL_CTX_new 3 .
109.Pp
110When
111.Xr SSL_clear 3
112is called and no session is connected to an
113.Vt SSL
114object, the method of the
115.Vt SSL
116object is reset to the method currently set in the corresponding
117.Vt SSL_CTX
118object.
119.Sh RETURN VALUES
120The following return values can occur for
121.Fn SSL_CTX_set_ssl_version
122and
123.Fn SSL_set_ssl_method :
124.Bl -tag -width Ds
125.It 0
126The new choice failed.
127Check the error stack to find out the reason.
128.It 1
129The operation succeeded.
130.El
131.Sh SEE ALSO
132.Xr ssl 3 ,
133.Xr SSL_clear 3 ,
134.Xr SSL_CTX_new 3 ,
135.Xr SSL_new 3 ,
136.Xr SSL_set_connect_state 3
137.Sh HISTORY
138.Fn SSL_CTX_set_ssl_version ,
139.Fn SSL_set_ssl_method ,
140and
141.Fn SSL_get_ssl_method
142first appeared in SSLeay 0.8.0 and have been available since
143.Ox 2.4 .
144.Fn SSL_CTX_get_ssl_method
145first appeared in OpenSSL 1.1.0 and has been available since
146.Ox 7.0 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_timeout.3 b/src/lib/libssl/man/SSL_CTX_set_timeout.3
deleted file mode 100644
index ab99e2016e..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_timeout.3
+++ /dev/null
@@ -1,118 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_timeout.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_CTX_SET_TIMEOUT 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_timeout ,
56.Nm SSL_CTX_get_timeout
57.Nd manipulate timeout values for session caching
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft long
61.Fn SSL_CTX_set_timeout "SSL_CTX *ctx" "long t"
62.Ft long
63.Fn SSL_CTX_get_timeout "SSL_CTX *ctx"
64.Sh DESCRIPTION
65.Fn SSL_CTX_set_timeout
66sets the timeout for newly created sessions for
67.Fa ctx
68to
69.Fa t .
70The timeout value
71.Fa t
72must be given in seconds.
73.Pp
74.Fn SSL_CTX_get_timeout
75returns the currently set timeout value for
76.Fa ctx .
77.Pp
78Whenever a new session is created, it is assigned a maximum lifetime.
79This lifetime is specified by storing the creation time of the session and the
80timeout value valid at this time.
81If the actual time is later than creation time plus timeout,
82the session is not reused.
83.Pp
84Due to this realization, all sessions behave according to the timeout value
85valid at the time of the session negotiation.
86Changes of the timeout value do not affect already established sessions.
87.Pp
88The expiration time of a single session can be modified using the
89.Xr SSL_SESSION_get_time 3
90family of functions.
91.Pp
92Expired sessions are removed from the internal session cache, whenever
93.Xr SSL_CTX_flush_sessions 3
94is called, either directly by the application or automatically (see
95.Xr SSL_CTX_set_session_cache_mode 3 ) .
96.Pp
97The default value for session timeout is decided on a per-protocol basis; see
98.Xr SSL_get_default_timeout 3 .
99All currently supported protocols have the same default timeout value of 300
100seconds.
101.Sh RETURN VALUES
102.Fn SSL_CTX_set_timeout
103returns the previously set timeout value.
104.Pp
105.Fn SSL_CTX_get_timeout
106returns the currently set timeout value.
107.Sh SEE ALSO
108.Xr ssl 3 ,
109.Xr SSL_CTX_flush_sessions 3 ,
110.Xr SSL_CTX_set_session_cache_mode 3 ,
111.Xr SSL_get_default_timeout 3 ,
112.Xr SSL_SESSION_get_time 3
113.Sh HISTORY
114.Fn SSL_CTX_set_timeout
115and
116.Fn SSL_CTX_get_timeout
117first appeared in SSLeay 0.6.1 and have been available since
118.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_tlsext_servername_callback.3 b/src/lib/libssl/man/SSL_CTX_set_tlsext_servername_callback.3
deleted file mode 100644
index 2b54406de8..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_tlsext_servername_callback.3
+++ /dev/null
@@ -1,247 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_tlsext_servername_callback.3,v 1.6 2021/09/01 13:56:03 schwarze Exp $
2.\" full merge up to: OpenSSL 190b9a03 Jun 28 15:46:13 2017 +0800
3.\" selective merge up to: OpenSSL 6328d367 Jul 4 21:58:30 2020 +0200
4.\"
5.\" This file was written by Jon Spillett <jon.spillett@oracle.com>,
6.\" Paul Yang <yang dot yang at baishancloud dot com>, and
7.\" Matt Caswell <matt@openssl.org>.
8.\" Copyright (c) 2017, 2019 The OpenSSL Project. All rights reserved.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\"
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\"
17.\" 2. Redistributions in binary form must reproduce the above copyright
18.\" notice, this list of conditions and the following disclaimer in
19.\" the documentation and/or other materials provided with the
20.\" distribution.
21.\"
22.\" 3. All advertising materials mentioning features or use of this
23.\" software must display the following acknowledgment:
24.\" "This product includes software developed by the OpenSSL Project
25.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26.\"
27.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28.\" endorse or promote products derived from this software without
29.\" prior written permission. For written permission, please contact
30.\" openssl-core@openssl.org.
31.\"
32.\" 5. Products derived from this software may not be called "OpenSSL"
33.\" nor may "OpenSSL" appear in their names without prior written
34.\" permission of the OpenSSL Project.
35.\"
36.\" 6. Redistributions of any form whatsoever must retain the following
37.\" acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40.\"
41.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
53.\"
54.Dd $Mdocdate: September 1 2021 $
55.Dt SSL_CTX_SET_TLSEXT_SERVERNAME_CALLBACK 3
56.Os
57.Sh NAME
58.Nm SSL_CTX_set_tlsext_servername_callback ,
59.Nm SSL_CTX_set_tlsext_servername_arg ,
60.Nm SSL_get_servername_type ,
61.Nm SSL_get_servername ,
62.Nm SSL_set_tlsext_host_name
63.Nd handle server name indication (SNI)
64.Sh SYNOPSIS
65.In openssl/ssl.h
66.Ft long
67.Fo SSL_CTX_set_tlsext_servername_callback
68.Fa "SSL_CTX *ctx"
69.Fa "int (*cb)(SSL *ssl, int *alert, void *arg)"
70.Fc
71.Ft long
72.Fo SSL_CTX_set_tlsext_servername_arg
73.Fa "SSL_CTX *ctx"
74.Fa "void *arg"
75.Fc
76.Ft const char *
77.Fo SSL_get_servername
78.Fa "const SSL *ssl"
79.Fa "const int type"
80.Fc
81.Ft int
82.Fo SSL_get_servername_type
83.Fa "const SSL *ssl"
84.Fc
85.Ft int
86.Fo SSL_set_tlsext_host_name
87.Fa "const SSL *ssl"
88.Fa "const char *name"
89.Fc
90.Sh DESCRIPTION
91.Fn SSL_CTX_set_tlsext_servername_callback
92sets the application callback
93.Fa cb
94used by a server to perform any actions or configuration required based
95on the servername extension received in the incoming connection.
96Like the ALPN callback, it is executed during Client Hello processing.
97When
98.Fa cb
99is
100.Dv NULL ,
101SNI is not used.
102.Pp
103The servername callback should return one of the following values:
104.Bl -tag -width Ds
105.It Dv SSL_TLSEXT_ERR_OK
106This is used to indicate that the servername requested by the client
107has been accepted.
108Typically a server will call
109.Xr SSL_set_SSL_CTX 3
110in the callback to set up a different configuration
111for the selected servername in this case.
112.It Dv SSL_TLSEXT_ERR_ALERT_FATAL
113In this case the servername requested by the client is not accepted
114and the handshake will be aborted.
115The value of the alert to be used should be stored in the location
116pointed to by the
117.Fa alert
118parameter to the callback.
119By default this value is initialised to
120.Dv SSL_AD_UNRECOGNIZED_NAME .
121.It Dv SSL_TLSEXT_ERR_ALERT_WARNING
122If this value is returned, then the servername is not accepted by the server.
123However, the handshake will continue and send a warning alert instead.
124The value of the alert should be stored in the location pointed to by the
125.Fa alert
126parameter as for
127.Dv SSL_TLSEXT_ERR_ALERT_FATAL
128above.
129Note that TLSv1.3 does not support warning alerts, so if TLSv1.3 has
130been negotiated then this return value is treated the same way as
131.Dv SSL_TLSEXT_ERR_NOACK .
132.It Dv SSL_TLSEXT_ERR_NOACK
133This return value indicates
134that the servername is not accepted by the server.
135No alerts are sent
136and the server will not acknowledge the requested servername.
137.El
138.Pp
139.Fn SSL_CTX_set_tlsext_servername_arg
140sets a context-specific argument to be passed into the callback via the
141.Fa arg
142parameter for
143.Fa ctx .
144.ig end_of_get_servername_details
145.\" I would suggest to comment out that second wall text of dubious
146.\" usefulness and see if we can meet all these documented API
147.\" requirements in the future or decide that it's not worth the
148.\" effort. -- tb@ Aug 30, 2021
149.Pp
150The behaviour of
151.Fn SSL_get_servername
152depends on a number of different factors.
153In particular note that in TLSv1.3,
154the servername is negotiated in every handshake.
155In TLSv1.2 the servername is only negotiated on initial handshakes
156and not on resumption handshakes.
157.Bl -tag -width Ds
158.It On the client, before the handshake:
159If a servername has been set via a call to
160.Fn SSL_set_tlsext_host_name ,
161then it will return that servername.
162If one has not been set, but a TLSv1.2 resumption is being attempted
163and the session from the original handshake had a servername
164accepted by the server, then it will return that servername.
165Otherwise it returns
166.Dv NULL .
167.It On the client, during or after the handshake,\
168 if a TLSv1.2 (or below) resumption occurred:
169If the session from the original handshake had a servername accepted by the
170server, then it will return that servername.
171Otherwise it returns the servername set via
172.Fn SSL_set_tlsext_host_name
173or
174.Dv NULL
175if it was not called.
176.It On the client, during or after the handshake,\
177 if a TLSv1.2 (or below) resumption did not occur:
178It will return the servername set via
179.Fn SSL_set_tlsext_host_name
180or
181.Dv NULL
182if it was not called.
183.It On the server, before the handshake:
184The function will always return
185.Dv NULL
186before the handshake.
187.It On the server, after the servername extension has been processed,\
188 if a TLSv1.2 (or below) resumption occurred:
189If a servername was accepted by the server in the original handshake,
190then it will return that servername, or
191.Dv NULL
192otherwise.
193.It On the server, after the servername extension has been processed,\
194 if a TLSv1.2 (or below) resumption did not occur:
195The function will return the servername
196requested by the client in this handshake or
197.Dv NULL
198if none was requested.
199.El
200.Pp
201Note that the early callback occurs before a servername extension
202from the client is processed.
203The servername, certificate and ALPN callbacks occur
204after a servername extension from the client is processed.
205.end_of_get_servername_details
206.Pp
207.Fn SSL_set_tlsext_host_name
208sets the server name indication ClientHello extension
209to contain the value
210.Fa name ,
211or clears it if
212.Fa name
213is
214.Dv NULL .
215The type of server name indication
216extension is set to
217.Dv TLSEXT_NAMETYPE_host_name
218as defined in RFC 3546.
219.Pp
220All three functions are implemented as macros.
221.Sh RETURN VALUES
222.Fn SSL_CTX_set_tlsext_servername_callback
223and
224.Fn SSL_CTX_set_tlsext_servername_arg
225always return 1 indicating success.
226.Pp
227.Fn SSL_get_servername
228returns a servername extension value of the specified type if provided
229in the Client Hello, or
230.Dv NULL
231otherwise.
232.Pp
233.Fn SSL_get_servername_type
234returns the servername type or -1 if no servername is present.
235Currently the only supported type (defined in RFC 3546) is
236.Dv TLSEXT_NAMETYPE_host_name .
237.Pp
238.Fn SSL_set_tlsext_host_name
239returns 1 on success or 0 in case of an error.
240.Sh SEE ALSO
241.Xr ssl 3 ,
242.Xr SSL_CTX_callback_ctrl 3 ,
243.Xr SSL_CTX_set_alpn_select_cb 3
244.Sh HISTORY
245These functions first appeared in OpenSSL 0.9.8f
246and have been available since
247.Ox 4.5 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_tlsext_status_cb.3 b/src/lib/libssl/man/SSL_CTX_set_tlsext_status_cb.3
deleted file mode 100644
index d5979af1e8..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_tlsext_status_cb.3
+++ /dev/null
@@ -1,238 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_tlsext_status_cb.3,v 1.8 2021/09/11 18:58:41 schwarze Exp $
2.\" full merge up to: OpenSSL 43c34894 Nov 30 16:04:51 2015 +0000
3.\" selective merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
4.\"
5.\" This file was written by Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2015, 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: September 11 2021 $
53.Dt SSL_CTX_SET_TLSEXT_STATUS_CB 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_tlsext_status_cb ,
57.Nm SSL_CTX_get_tlsext_status_cb ,
58.Nm SSL_CTX_set_tlsext_status_arg ,
59.Nm SSL_CTX_get_tlsext_status_arg ,
60.Nm SSL_set_tlsext_status_type ,
61.Nm SSL_get_tlsext_status_type ,
62.Nm SSL_get_tlsext_status_ocsp_resp ,
63.Nm SSL_set_tlsext_status_ocsp_resp
64.Nd OCSP Certificate Status Request functions
65.Sh SYNOPSIS
66.In openssl/tls1.h
67.Ft long
68.Fo SSL_CTX_set_tlsext_status_cb
69.Fa "SSL_CTX *ctx"
70.Fa "int (*callback)(SSL *, void *)"
71.Fc
72.Ft long
73.Fo SSL_CTX_get_tlsext_status_cb
74.Fa "SSL_CTX *ctx"
75.Fa "int (*callback)(SSL *, void *)"
76.Fc
77.Ft long
78.Fo SSL_CTX_set_tlsext_status_arg
79.Fa "SSL_CTX *ctx"
80.Fa "void *arg"
81.Fc
82.Ft long
83.Fo SSL_CTX_get_tlsext_status_arg
84.Fa "SSL_CTX *ctx"
85.Fa "void **arg"
86.Fc
87.Ft long
88.Fo SSL_set_tlsext_status_type
89.Fa "SSL *s"
90.Fa "int type"
91.Fc
92.Ft long
93.Fo SSL_get_tlsext_status_type
94.Fa "SSL *s"
95.Fc
96.Ft long
97.Fo SSL_get_tlsext_status_ocsp_resp
98.Fa ssl
99.Fa "unsigned char **resp"
100.Fc
101.Ft long
102.Fo SSL_set_tlsext_status_ocsp_resp
103.Fa ssl
104.Fa "unsigned char *resp"
105.Fa "int len"
106.Fc
107.Sh DESCRIPTION
108A client application may request that a server send back an OCSP status
109response (also known as OCSP stapling).
110To do so the client should call the
111.Fn SSL_set_tlsext_status_type
112function on an individual
113.Vt SSL
114object prior to the start of the handshake.
115Currently the only supported type is
116.Dv TLSEXT_STATUSTYPE_ocsp .
117This value should be passed in the
118.Fa type
119argument.
120.Pp
121The client should additionally provide a callback function to decide
122what to do with the returned OCSP response by calling
123.Fn SSL_CTX_set_tlsext_status_cb .
124The callback function should determine whether the returned OCSP
125response is acceptable or not.
126The callback will be passed as an argument the value previously set via
127a call to
128.Fn SSL_CTX_set_tlsext_status_arg .
129Note that the callback will not be called in the event of a handshake
130where session resumption occurs (because there are no Certificates
131exchanged in such a handshake).
132.Pp
133The callback previously set via
134.Fn SSL_CTX_set_tlsext_status_cb
135can be retrieved by calling
136.Fn SSL_CTX_get_tlsext_status_cb ,
137and the argument by calling
138.Fn SSL_CTX_get_tlsext_status_arg .
139.Pp
140On the client side,
141.Fn SSL_get_tlsext_status_type
142can be used to determine whether the client has previously called
143.Fn SSL_set_tlsext_status_type .
144It will return
145.Dv TLSEXT_STATUSTYPE_ocsp
146if it has been called or \-1 otherwise.
147On the server side,
148.Fn SSL_get_tlsext_status_type
149can be used to determine whether the client requested OCSP stapling.
150If the client requested it, then this function will return
151.Dv TLSEXT_STATUSTYPE_ocsp ,
152or \-1 otherwise.
153.Pp
154The response returned by the server can be obtained via a call to
155.Fn SSL_get_tlsext_status_ocsp_resp .
156The value
157.Pf * Fa resp
158will be updated to point to the OCSP response data and the return value
159will be the length of that data.
160If the server has not provided any response data, then
161.Pf * Fa resp
162will be
163.Dv NULL
164and the return value from
165.Fn SSL_get_tlsext_status_ocsp_resp
166will be -1.
167.Pp
168A server application must also call the
169.Fn SSL_CTX_set_tlsext_status_cb
170function if it wants to be able to provide clients with OCSP Certificate
171Status responses.
172Typically the server callback would obtain the server certificate that
173is being sent back to the client via a call to
174.Xr SSL_get_certificate 3 ,
175obtain the OCSP response to be sent back, and then set that response
176data by calling
177.Fn SSL_set_tlsext_status_ocsp_resp .
178A pointer to the response data should be provided in the
179.Fa resp
180argument, and the length of that data should be in the
181.Fa len
182argument.
183.Sh RETURN VALUES
184The callback when used on the client side should return a negative
185value on error, 0 if the response is not acceptable (in which case
186the handshake will fail), or a positive value if it is acceptable.
187.Pp
188The callback when used on the server side should return with either
189.Dv SSL_TLSEXT_ERR_OK
190(meaning that the OCSP response that has been set should be returned),
191.Dv SSL_TLSEXT_ERR_NOACK
192(meaning that an OCSP response should not be returned), or
193.Dv SSL_TLSEXT_ERR_ALERT_FATAL
194(meaning that a fatal error has occurred).
195.Pp
196.Fn SSL_CTX_set_tlsext_status_cb ,
197.Fn SSL_CTX_get_tlsext_status_cb ,
198.Fn SSL_CTX_set_tlsext_status_arg ,
199.Fn SSL_CTX_get_tlsext_status_arg ,
200.Fn SSL_set_tlsext_status_type ,
201and
202.Fn SSL_set_tlsext_status_ocsp_resp
203always return 1, indicating success.
204.Pp
205.Fn SSL_get_tlsext_status_type
206returns
207.Dv TLSEXT_STATUSTYPE_ocsp
208on the client side if
209.Fn SSL_set_tlsext_status_type
210was previously called, or on the server side
211if the client requested OCSP stapling.
212Otherwise \-1 is returned.
213.Pp
214.Fn SSL_get_tlsext_status_ocsp_resp
215returns the length of the OCSP response data
216or \-1 if there is no OCSP response data.
217.Sh SEE ALSO
218.Xr ssl 3 ,
219.Xr SSL_CTX_callback_ctrl 3
220.Sh HISTORY
221.Fn SSL_CTX_set_tlsext_status_cb ,
222.Fn SSL_CTX_set_tlsext_status_arg ,
223.Fn SSL_set_tlsext_status_type ,
224.Fn SSL_get_tlsext_status_ocsp_resp ,
225and
226.Fn SSL_set_tlsext_status_ocsp_resp
227first appeared in OpenSSL 0.9.8h and have been available since
228.Ox 4.5 .
229.Pp
230.Fn SSL_CTX_get_tlsext_status_cb
231and
232.Fn SSL_CTX_get_tlsext_status_arg
233first appeared in OpenSSL 1.1.0 and have been available since
234.Ox 6.3 .
235.Pp
236.Fn SSL_get_tlsext_status_type
237first appeared in OpenSSL 1.1.0 and has been available since
238.Ox 7.0 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_tlsext_ticket_key_cb.3 b/src/lib/libssl/man/SSL_CTX_set_tlsext_ticket_key_cb.3
deleted file mode 100644
index b6ccabaeca..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_tlsext_ticket_key_cb.3
+++ /dev/null
@@ -1,300 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_tlsext_ticket_key_cb.3,v 1.8 2022/01/25 18:01:20 tb Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Rich Salz <rsalz@akamai.com>
5.\" Copyright (c) 2014, 2015, 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: January 25 2022 $
52.Dt SSL_CTX_SET_TLSEXT_TICKET_KEY_CB 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_tlsext_ticket_key_cb
56.Nd set a callback for session ticket processing
57.Sh SYNOPSIS
58.In openssl/tls1.h
59.Ft long
60.Fo SSL_CTX_set_tlsext_ticket_key_cb
61.Fa "SSL_CTX sslctx"
62.Fa "int (*cb)(SSL *s, unsigned char key_name[16],\
63 unsigned char iv[EVP_MAX_IV_LENGTH],\
64 EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc)"
65.Fc
66.Sh DESCRIPTION
67.Fn SSL_CTX_set_tlsext_ticket_key_cb
68sets a callback function
69.Fa cb
70for handling session tickets for the ssl context
71.Fa sslctx .
72Session tickets, defined in RFC 5077, provide an enhanced session
73resumption capability where the server implementation is not required to
74maintain per session state.
75.Pp
76The callback function
77.Fa cb
78will be called for every client instigated TLS session when session
79ticket extension is presented in the TLS hello message.
80It is the responsibility of this function to create or retrieve the
81cryptographic parameters and to maintain their state.
82.Pp
83The OpenSSL library uses the callback function to help implement a
84common TLS ticket construction state according to RFC 5077 Section 4 such
85that per session state is unnecessary and a small set of cryptographic
86variables needs to be maintained by the callback function
87implementation.
88.Pp
89In order to reuse a session, a TLS client must send a session ticket
90extension to the server.
91The client can only send exactly one session ticket.
92The server, through the callback function, either agrees to reuse the
93session ticket information or it starts a full TLS handshake to create a
94new session ticket.
95.Pp
96The callback is called with
97.Fa ctx
98and
99.Fa hctx
100which were newly allocated with
101.Xr EVP_CIPHER_CTX_new 3
102and
103.Xr HMAC_CTX_new 3 ,
104respectively.
105.Pp
106For new sessions tickets, when the client doesn't present a session
107ticket, or an attempted retrieval of the ticket failed, or a renew
108option was indicated, the callback function will be called with
109.Fa enc
110equal to 1.
111The OpenSSL library expects that the function will set an arbitrary
112.Fa key_name ,
113initialize
114.Fa iv ,
115and set the cipher context
116.Fa ctx
117and the hash context
118.Fa hctx .
119.Pp
120The
121.Fa key_name
122is 16 characters long and is used as a key identifier.
123.Pp
124The
125.Fa iv
126length is the length of the IV of the corresponding cipher.
127The maximum IV length is
128.Dv EVP_MAX_IV_LENGTH
129bytes defined in
130.In openssl/evp.h .
131.Pp
132The initialization vector
133.Fa iv
134should be a random value.
135The cipher context
136.Fa ctx
137should use the initialisation vector
138.Fa iv .
139The cipher context can be set using
140.Xr EVP_EncryptInit_ex 3 .
141The hmac context can be set using
142.Xr HMAC_Init_ex 3 .
143.Pp
144When the client presents a session ticket, the callback function
145with be called with
146.Fa enc
147set to 0 indicating that the
148.Fa cb
149function should retrieve a set of parameters.
150In this case
151.Fa key_name
152and
153.Fa iv
154have already been parsed out of the session ticket.
155The OpenSSL library expects that the
156.Em key_name
157will be used to retrieve a cryptographic parameters and that the
158cryptographic context
159.Fa ctx
160will be set with the retrieved parameters and the initialization vector
161.Fa iv
162using a function like
163.Xr EVP_DecryptInit_ex 3 .
164The
165.Fa hctx
166needs to be set using
167.Xr HMAC_Init_ex 3 .
168.Pp
169If the
170.Fa key_name
171is still valid but a renewal of the ticket is required, the callback
172function should return 2.
173The library will call the callback again with an argument of
174.Fa enc
175equal to 1 to set the new ticket.
176.Pp
177The return value of the
178.Fa cb
179function is used by OpenSSL to determine what further processing will
180occur.
181The following return values have meaning:
182.Bl -tag -width Ds
183.It 2
184This indicates that the
185.Fa ctx
186and
187.Fa hctx
188have been set and the session can continue on those parameters.
189Additionally it indicates that the session ticket is in a renewal period
190and should be replaced.
191The OpenSSL library will call
192.Fa cb
193again with an
194.Fa enc
195argument of 1 to set the new ticket (see RFC 5077 3.3 paragraph 2).
196.It 1
197This indicates that the
198.Fa ctx
199and
200.Fa hctx
201have been set and the session can continue on those parameters.
202.It 0
203This indicates that it was not possible to set/retrieve a session ticket
204and the SSL/TLS session will continue by negotiating a set of
205cryptographic parameters or using the alternate SSL/TLS resumption
206mechanism, session ids.
207.Pp
208If called with
209.Fa enc
210equal to 0, the library will call the
211.Fa cb
212again to get a new set of parameters.
213.It less than 0
214This indicates an error.
215.El
216.Pp
217Session resumption shortcuts the TLS so that the client certificate
218negotiation don't occur.
219It makes up for this by storing client certificate and all other
220negotiated state information encrypted within the ticket.
221In a resumed session the applications will have all this state
222information available exactly as if a full negotiation had occurred.
223.Pp
224If an attacker can obtain the key used to encrypt a session ticket, they
225can obtain the master secret for any ticket using that key and decrypt
226any traffic using that session: even if the ciphersuite supports forward
227secrecy.
228As a result applications may wish to use multiple keys and avoid using
229long term keys stored in files.
230.Pp
231Applications can use longer keys to maintain a consistent level of
232security.
233For example if a ciphersuite uses 256 bit ciphers but only a 128 bit
234ticket key the overall security is only 128 bits because breaking the
235ticket key will enable an attacker to obtain the session keys.
236.Sh RETURN VALUES
237This function returns 0 to indicate that the callback function was set.
238.Sh EXAMPLES
239Reference Implementation:
240.Bd -literal
241SSL_CTX_set_tlsext_ticket_key_cb(SSL, ssl_tlsext_ticket_key_cb);
242\&....
243static int ssl_tlsext_ticket_key_cb(SSL *s, unsigned char key_name[16],
244 unsigned char *iv, EVP_CIPHER_CTX *ctx, HMAC_CTX *hctx, int enc)
245{
246 if (enc) { /* create new session */
247 if (RAND_bytes(iv, EVP_MAX_IV_LENGTH))
248 return -1; /* insufficient random */
249
250 key = currentkey(); /* something you need to implement */
251 if (!key) {
252 /* current key doesn't exist or isn't valid */
253 key = createkey();
254 /* something that you need to implement.
255 * createkey needs to initialise a name,
256 * an aes_key, a hmac_key, and optionally
257 * an expire time. */
258 if (!key) /* key couldn't be created */
259 return 0;
260 }
261 memcpy(key_name, key->name, 16);
262
263 EVP_EncryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL,
264 key->aes_key, iv);
265 HMAC_Init_ex(&hctx, key->hmac_key, 16, EVP_sha256(), NULL);
266
267 return 1;
268
269 } else { /* retrieve session */
270 key = findkey(name);
271
272 if (!key || key->expire < now())
273 return 0;
274
275 HMAC_Init_ex(&hctx, key->hmac_key, 16, EVP_sha256(), NULL);
276 EVP_DecryptInit_ex(&ctx, EVP_aes_128_cbc(), NULL,
277 key->aes_key, iv );
278
279 if (key->expire < (now() - RENEW_TIME))
280 /* this session will get a new ticket
281 * even though the current is still valid */
282 return 2;
283
284 return 1;
285 }
286}
287.Ed
288.Sh SEE ALSO
289.Xr ssl 3 ,
290.Xr SSL_CTX_add_session 3 ,
291.Xr SSL_CTX_callback_ctrl 3 ,
292.Xr SSL_CTX_sess_number 3 ,
293.Xr SSL_CTX_sess_set_get_cb 3 ,
294.Xr SSL_CTX_set_session_id_context 3 ,
295.Xr SSL_session_reused 3 ,
296.Xr SSL_set_session 3
297.Sh HISTORY
298.Fn SSL_CTX_set_tlsext_ticket_key_cb
299first appeared in OpenSSL 0.9.8h and has been available since
300.Ox 4.5 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_tlsext_use_srtp.3 b/src/lib/libssl/man/SSL_CTX_set_tlsext_use_srtp.3
deleted file mode 100644
index 04c4833c6a..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_tlsext_use_srtp.3
+++ /dev/null
@@ -1,197 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_tlsext_use_srtp.3,v 1.6 2021/06/11 19:41:39 jmc Exp $
2.\" full merge up to: OpenSSL b0edda11 Mar 20 13:00:17 2018 +0000
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>.
5.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 11 2021 $
52.Dt SSL_CTX_SET_TLSEXT_USE_SRTP 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_tlsext_use_srtp ,
56.Nm SSL_set_tlsext_use_srtp ,
57.Nm SSL_get_srtp_profiles ,
58.Nm SSL_get_selected_srtp_profile
59.Nd Configure and query SRTP support
60.Sh SYNOPSIS
61.In openssl/srtp.h
62.Ft int
63.Fo SSL_CTX_set_tlsext_use_srtp
64.Fa "SSL_CTX *ctx"
65.Fa "const char *profiles"
66.Fc
67.Ft int
68.Fo SSL_set_tlsext_use_srtp
69.Fa "SSL *ssl"
70.Fa "const char *profiles"
71.Fc
72.Ft STACK_OF(SRTP_PROTECTION_PROFILE) *
73.Fo SSL_get_srtp_profiles
74.Fa "SSL *ssl"
75.Fc
76.Ft SRTP_PROTECTION_PROFILE *
77.Fo SSL_get_selected_srtp_profile
78.Fa "SSL *ssl"
79.Fc
80.Sh DESCRIPTION
81SRTP is the Secure Real-Time Transport Protocol.
82OpenSSL implements support for the "use_srtp" DTLS extension
83defined in RFC 5764.
84This provides a mechanism for establishing SRTP keying material,
85algorithms and parameters using DTLS.
86This capability may be used as part of an implementation that
87conforms to RFC 5763.
88OpenSSL does not implement SRTP itself or RFC 5763.
89Note that OpenSSL does not support the use of SRTP Master Key
90Identifiers (MKIs).
91Also note that this extension is only supported in DTLS.
92Any SRTP configuration is ignored if a TLS connection is attempted.
93.Pp
94An OpenSSL client wishing to send the "use_srtp" extension should call
95.Fn SSL_CTX_set_tlsext_use_srtp
96to set its use for all
97.Vt SSL
98objects subsequently created from
99.Fa ctx .
100Alternatively a client may call
101.Fn SSL_set_tlsext_use_srtp
102to set its use for an individual
103.Vt SSL
104object.
105The
106.Fa profiles
107parameter should point to a NUL-terminated, colon delimited list of
108SRTP protection profile names.
109.Pp
110The currently supported protection profile names are:
111.Bl -tag -width Ds
112.It Dv SRTP_AES128_CM_SHA1_80
113This corresponds to SRTP_AES128_CM_HMAC_SHA1_80 defined in RFC 5764.
114.It Dv SRTP_AES128_CM_SHA1_32
115This corresponds to SRTP_AES128_CM_HMAC_SHA1_32 defined in RFC 5764.
116.It Dv SRTP_AEAD_AES_128_GCM
117This corresponds to SRTP_AEAD_AES_128_GCM defined in RFC 7714.
118.It Dv SRTP_AEAD_AES_256_GCM
119This corresponds to SRTP_AEAD_AES_256_GCM defined in RFC 7714.
120.El
121.Pp
122Supplying an unrecognised protection profile name results in an error.
123.Pp
124An OpenSSL server wishing to support the "use_srtp" extension should
125also call
126.Fn SSL_CTX_set_tlsext_use_srtp
127or
128.Fn SSL_set_tlsext_use_srtp
129to indicate the protection profiles that it is willing to negotiate.
130.Pp
131The currently configured list of protection profiles for either a client
132or a server can be obtained by calling
133.Fn SSL_get_srtp_profiles .
134This returns a stack of
135.Vt SRTP_PROTECTION_PROFILE
136objects.
137The memory pointed to in the return value of this function should not be
138freed by the caller.
139.Pp
140After a handshake has been completed, the negotiated SRTP protection
141profile (if any) can be obtained (on the client or the server) by
142calling
143.Fn SSL_get_selected_srtp_profile .
144This function returns
145.Dv NULL
146if no SRTP protection profile was negotiated.
147The memory returned from this function should not be freed by the
148caller.
149.Pp
150If an SRTP protection profile has been successfully negotiated,
151then the SRTP keying material (on both the client and server)
152should be obtained by calling
153.Xr SSL_export_keying_material 3
154with a
155.Fa label
156of
157.Qq EXTRACTOR-dtls_srtp ,
158a
159.Fa context
160of
161.Dv NULL ,
162and a
163.Fa use_context
164argument of 0.
165The total length of keying material obtained should be equal to two
166times the sum of the master key length and the salt length as defined
167for the protection profile in use.
168This provides the client write master key, the server write master key,
169the client write master salt and the server write master salt in that
170order.
171.Sh RETURN VALUES
172Contrary to OpenSSL conventions,
173.Fn SSL_CTX_set_tlsext_use_srtp
174and
175.Fn SSL_set_tlsext_use_srtp
176return 0 on success or 1 on error.
177.Pp
178.Fn SSL_get_srtp_profiles
179returns a stack of
180.Vt SRTP_PROTECTION_PROFILE
181objects on success or
182.Dv NULL
183on error or if no protection profiles have been configured.
184.Pp
185.Fn SSL_get_selected_srtp_profile
186returns a pointer to an
187.Vt SRTP_PROTECTION_PROFILE
188object if one has been negotiated or
189.Dv NULL
190otherwise.
191.Sh SEE ALSO
192.Xr ssl 3 ,
193.Xr SSL_export_keying_material 3
194.Sh HISTORY
195These functions first appeared in OpenSSL 1.0.1
196and have been available since
197.Ox 5.3 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_tmp_dh_callback.3 b/src/lib/libssl/man/SSL_CTX_set_tmp_dh_callback.3
deleted file mode 100644
index c6f5253431..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_tmp_dh_callback.3
+++ /dev/null
@@ -1,229 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_tmp_dh_callback.3,v 1.11 2025/01/18 10:45:12 tb Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2014, 2015 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: January 18 2025 $
52.Dt SSL_CTX_SET_TMP_DH_CALLBACK 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_tmp_dh_callback ,
56.Nm SSL_CTX_set_tmp_dh ,
57.Nm SSL_set_tmp_dh_callback ,
58.Nm SSL_set_tmp_dh
59.Nd handle DH keys for ephemeral key exchange
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft void
63.Fo SSL_CTX_set_tmp_dh_callback
64.Fa "SSL_CTX *ctx"
65.Fa "DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength)"
66.Fc
67.Ft long
68.Fn SSL_CTX_set_tmp_dh "SSL_CTX *ctx" "DH *dh"
69.Ft void
70.Fo SSL_set_tmp_dh_callback
71.Fa "SSL *ssl"
72.Fa "DH *(*tmp_dh_callback)(SSL *ssl, int is_export, int keylength"
73.Fc
74.Ft long
75.Fn SSL_set_tmp_dh "SSL *ssl" "DH *dh"
76.Sh DESCRIPTION
77.Fn SSL_CTX_set_tmp_dh_callback
78sets the callback function for
79.Fa ctx
80to be used when a DH parameters are required to
81.Fa tmp_dh_callback .
82The callback is inherited by all
83.Vt ssl
84objects created from
85.Fa ctx .
86.Pp
87.Fn SSL_CTX_set_tmp_dh
88sets DH parameters to be used by
89.Fa ctx .
90The key is inherited by all
91.Fa ssl
92objects created from
93.Fa ctx .
94.Pp
95.Fn SSL_set_tmp_dh_callback
96sets the callback only for
97.Fa ssl .
98.Pp
99.Fn SSL_set_tmp_dh
100sets the parameters only for
101.Fa ssl .
102.Pp
103These functions apply to SSL/TLS servers only.
104.Pp
105When using a cipher with RSA authentication,
106an ephemeral DH key exchange can take place.
107In these cases, the session data are negotiated using the ephemeral/temporary
108DH key and the key supplied and certified by the certificate chain is only used
109for signing.
110Anonymous ciphers (without a permanent server key) also use ephemeral DH keys.
111.Pp
112Using ephemeral DH key exchange yields forward secrecy,
113as the connection can only be decrypted when the DH key is known.
114By generating a temporary DH key inside the server application that is lost
115when the application is left, it becomes impossible for attackers to decrypt
116past sessions, even if they get hold of the normal (certified) key,
117as this key was only used for signing.
118.Pp
119In order to perform a DH key exchange, the server must use a DH group
120(DH parameters) and generate a DH key.
121The server will always generate a new DH key during the negotiation.
122.Pp
123As generating DH parameters is extremely time consuming, an application should
124not generate the parameters on the fly but supply the parameters.
125DH parameters can be reused,
126as the actual key is newly generated during the negotiation.
127The risk in reusing DH parameters is that an attacker may specialize on a very
128often used DH group.
129Applications should therefore generate their own DH parameters during the
130installation process using the
131.Xr openssl 1
132.Cm dhparam
133application.
134This application guarantees that "strong" primes are used.
135.Pp
136Files
137.Pa dh2048.pem
138and
139.Pa dh4096.pem
140in the
141.Pa apps
142directory of the current version of the OpenSSL distribution contain the
143.Sq SKIP
144DH parameters,
145which use safe primes and were generated verifiably pseudo-randomly.
146These files can be converted into C code using the
147.Fl C
148option of the
149.Xr openssl 1
150.Cm dhparam
151application.
152Generation of custom DH parameters during installation should still
153be preferred to stop an attacker from specializing on a commonly
154used group.
155The file
156.Pa dh1024.pem
157contains old parameters that must not be used by applications.
158.Pp
159An application may either directly specify the DH parameters or can supply the
160DH parameters via a callback function.
161.Pp
162Previous versions of the callback used
163.Fa is_export
164and
165.Fa keylength
166parameters to control parameter generation for export and non-export
167cipher suites.
168Modern servers that do not support export ciphersuites are advised
169to either use
170.Fn SSL_CTX_set_tmp_dh
171or alternatively, use the callback but ignore
172.Fa keylength
173and
174.Fa is_export
175and simply supply at least 2048-bit parameters in the callback.
176.Sh RETURN VALUES
177.Fn SSL_CTX_set_tmp_dh
178and
179.Fn SSL_set_tmp_dh
180do return 1 on success and 0 on failure.
181Check the error queue to find out the reason of failure.
182.Sh EXAMPLES
183Set up DH parameters with a key length of 2048 bits.
184Error handling is partly left out.
185.Pp
186Command-line parameter generation:
187.Pp
188.Dl openssl dhparam -out dh_param_2048.pem 2048
189.Pp
190Code for setting up parameters during server initialization:
191.Bd -literal
192SSL_CTX ctx = SSL_CTX_new();
193\&...
194
195/* Set up ephemeral DH parameters. */
196DH *dh_2048 = NULL;
197FILE *paramfile;
198paramfile = fopen("dh_param_2048.pem", "r");
199if (paramfile) {
200 dh_2048 = PEM_read_DHparams(paramfile, NULL, NULL, NULL);
201 fclose(paramfile);
202} else {
203 /* Error. */
204}
205if (dh_2048 == NULL) {
206 /* Error. */
207}
208if (SSL_CTX_set_tmp_dh(ctx, dh_2048) != 1) {
209 /* Error. */
210}
211.Ed
212.Sh SEE ALSO
213.Xr openssl 1 ,
214.Xr ssl 3 ,
215.Xr SSL_CTX_set_cipher_list 3 ,
216.Xr SSL_CTX_set_options 3 ,
217.Xr SSL_set_tmp_ecdh 3
218.Sh HISTORY
219.Fn SSL_CTX_set_tmp_dh_callback
220and
221.Fn SSL_CTX_set_tmp_dh
222first appeared in SSLeay 0.8.0 and have been available since
223.Ox 2.4 .
224.Pp
225.Fn SSL_set_tmp_dh_callback
226and
227.Fn SSL_set_tmp_dh
228first appeared in OpenSSL 0.9.2b and have been available since
229.Ox 2.6 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_tmp_rsa_callback.3 b/src/lib/libssl/man/SSL_CTX_set_tmp_rsa_callback.3
deleted file mode 100644
index b4c3a3c647..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_tmp_rsa_callback.3
+++ /dev/null
@@ -1,114 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_tmp_rsa_callback.3,v 1.9 2022/03/29 14:27:59 naddy Exp $
2.\" OpenSSL 0b30fc90 Dec 19 15:23:05 2013 -0500
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2006, 2013 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 29 2022 $
52.Dt SSL_CTX_SET_TMP_RSA_CALLBACK 3
53.Os
54.Sh NAME
55.Nm SSL_CTX_set_tmp_rsa_callback ,
56.Nm SSL_CTX_set_tmp_rsa ,
57.Nm SSL_CTX_need_tmp_RSA ,
58.Nm SSL_set_tmp_rsa_callback ,
59.Nm SSL_set_tmp_rsa ,
60.Nm SSL_need_tmp_RSA
61.Nd handle RSA keys for ephemeral key exchange
62.Sh SYNOPSIS
63.In openssl/ssl.h
64.Ft void
65.Fo SSL_CTX_set_tmp_rsa_callback
66.Fa "SSL_CTX *ctx"
67.Fa "RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength)"
68.Fc
69.Ft long
70.Fn SSL_CTX_set_tmp_rsa "SSL_CTX *ctx" "RSA *rsa"
71.Ft long
72.Fn SSL_CTX_need_tmp_RSA "SSL_CTX *ctx"
73.Ft void
74.Fo SSL_set_tmp_rsa_callback
75.Fa "SSL_CTX *ctx"
76.Fa "RSA *(*tmp_rsa_callback)(SSL *ssl, int is_export, int keylength)"
77.Fc
78.Ft long
79.Fn SSL_set_tmp_rsa "SSL *ssl" "RSA *rsa"
80.Ft long
81.Fn SSL_need_tmp_RSA "SSL *ssl"
82.Sh DESCRIPTION
83Since they mattered only for deliberately insecure RSA authentication
84mandated by historical U.S. export restrictions, these functions
85are all deprecated and have no effect except that
86.Fn SSL_CTX_set_tmp_rsa_callback ,
87.Fn SSL_CTX_set_tmp_rsa ,
88.Fn SSL_set_tmp_rsa_callback ,
89and
90.Fn SSL_set_tmp_rsa
91issue error messages when called.
92.Sh RETURN VALUES
93These functions always return 0, indicating failure.
94.Sh SEE ALSO
95.Xr ssl 3 ,
96.Xr SSL_CTX_set_cipher_list 3 ,
97.Xr SSL_CTX_set_options 3 ,
98.Xr SSL_CTX_set_tmp_dh_callback 3 ,
99.Xr SSL_new 3 ,
100.Xr SSL_set_tmp_ecdh 3
101.Sh HISTORY
102.Fn SSL_CTX_set_tmp_rsa_callback ,
103.Fn SSL_CTX_set_tmp_rsa ,
104and
105.Fn SSL_CTX_need_tmp_RSA
106first appeared in SSLeay 0.8.0 and have been available since
107.Ox 2.4 .
108.Pp
109.Fn SSL_set_tmp_rsa_callback ,
110.Fn SSL_set_tmp_rsa ,
111and
112.Fn SSL_need_tmp_RSA
113first appeared in OpenSSL 0.9.2b and have been available since
114.Ox 2.6 .
diff --git a/src/lib/libssl/man/SSL_CTX_set_verify.3 b/src/lib/libssl/man/SSL_CTX_set_verify.3
deleted file mode 100644
index 1ed86407e9..0000000000
--- a/src/lib/libssl/man/SSL_CTX_set_verify.3
+++ /dev/null
@@ -1,479 +0,0 @@
1.\" $OpenBSD: SSL_CTX_set_verify.3,v 1.9 2021/06/12 16:59:53 jmc Exp $
2.\" full merge up to: OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\" selective merge up to: OpenSSL 1cb7eff4 Sep 10 13:56:40 2019 +0100
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
6.\" Copyright (c) 2000, 2001, 2002, 2003, 2014 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: June 12 2021 $
54.Dt SSL_CTX_SET_VERIFY 3
55.Os
56.Sh NAME
57.Nm SSL_CTX_set_verify ,
58.Nm SSL_set_verify ,
59.Nm SSL_CTX_set_verify_depth ,
60.Nm SSL_set_verify_depth
61.Nd set peer certificate verification parameters
62.Sh SYNOPSIS
63.In openssl/ssl.h
64.Ft void
65.Fo SSL_CTX_set_verify
66.Fa "SSL_CTX *ctx"
67.Fa "int mode"
68.Fa "int (*verify_callback)(int, X509_STORE_CTX *)"
69.Fc
70.Ft void
71.Fo SSL_set_verify
72.Fa "SSL *s"
73.Fa "int mode"
74.Fa "int (*verify_callback)(int, X509_STORE_CTX *)"
75.Fc
76.Ft void
77.Fn SSL_CTX_set_verify_depth "SSL_CTX *ctx" "int depth"
78.Ft void
79.Fn SSL_set_verify_depth "SSL *s" "int depth"
80.Ft int
81.Fn verify_callback "int preverify_ok" "X509_STORE_CTX *x509_ctx"
82.Sh DESCRIPTION
83.Fn SSL_CTX_set_verify
84sets the verification flags for
85.Fa ctx
86to be
87.Fa mode
88and
89specifies the
90.Fa verify_callback
91function to be used.
92If no callback function shall be specified, the
93.Dv NULL
94pointer can be used for
95.Fa verify_callback .
96.Pp
97.Fn SSL_set_verify
98sets the verification flags for
99.Fa ssl
100to be
101.Fa mode
102and specifies the
103.Fa verify_callback
104function to be used.
105If no callback function shall be specified, the
106.Dv NULL
107pointer can be used for
108.Fa verify_callback .
109In this case last
110.Fa verify_callback
111set specifically for this
112.Fa ssl
113remains.
114If no special callback was set before, the default callback for the underlying
115.Fa ctx
116is used, that was valid at the time
117.Fa ssl
118was created with
119.Xr SSL_new 3 .
120Within the callback function,
121.Xr SSL_get_ex_data_X509_STORE_CTX_idx 3
122can be called to get the data index of the current
123.Vt SSL
124object that is doing the verification.
125.Pp
126.Fn SSL_CTX_set_verify_depth
127sets the maximum
128.Fa depth
129for the certificate chain verification that shall be allowed for
130.Fa ctx .
131(See the
132.Sx BUGS
133section.)
134.Pp
135.Fn SSL_set_verify_depth
136sets the maximum
137.Fa depth
138for the certificate chain verification that shall be allowed for
139.Fa ssl .
140(See the
141.Sx BUGS
142section.)
143.Pp
144The verification of certificates can be controlled by a set of bitwise ORed
145.Fa mode
146flags:
147.Bl -tag -width Ds
148.It Dv SSL_VERIFY_NONE
149.Em Server mode :
150the server will not send a client certificate request to the client,
151so the client will not send a certificate.
152.Pp
153.Em Client mode :
154if not using an anonymous cipher (by default disabled),
155the server will send a certificate which will be checked.
156The result of the certificate verification process can be checked after the
157TLS/SSL handshake using the
158.Xr SSL_get_verify_result 3
159function.
160The handshake will be continued regardless of the verification result.
161.It Dv SSL_VERIFY_PEER
162.Em Server mode :
163the server sends a client certificate request to the client.
164The certificate returned (if any) is checked.
165If the verification process fails,
166the TLS/SSL handshake is immediately terminated with an alert message
167containing the reason for the verification failure.
168The behaviour can be controlled by the additional
169.Dv SSL_VERIFY_FAIL_IF_NO_PEER_CERT
170and
171.Dv SSL_VERIFY_CLIENT_ONCE
172flags.
173.Pp
174.Em Client mode :
175the server certificate is verified.
176If the verification process fails,
177the TLS/SSL handshake is immediately terminated with an alert message
178containing the reason for the verification failure.
179If no server certificate is sent, because an anonymous cipher is used,
180.Dv SSL_VERIFY_PEER
181is ignored.
182.It Dv SSL_VERIFY_FAIL_IF_NO_PEER_CERT
183.Em Server mode :
184if the client did not return a certificate, the TLS/SSL
185handshake is immediately terminated with a
186.Dq handshake failure
187alert.
188This flag must be used together with
189.Dv SSL_VERIFY_PEER .
190.Pp
191.Em Client mode :
192ignored
193.It Dv SSL_VERIFY_CLIENT_ONCE
194.Em Server mode :
195only request a client certificate on the initial TLS/SSL handshake.
196Do not ask for a client certificate again in case of a renegotiation.
197This flag must be used together with
198.Dv SSL_VERIFY_PEER .
199.Pp
200.Em Client mode :
201ignored
202.El
203.Pp
204Exactly one of the
205.Fa mode
206flags
207.Dv SSL_VERIFY_NONE
208and
209.Dv SSL_VERIFY_PEER
210must be set at any time.
211.Pp
212The actual verification procedure is performed either using the built-in
213verification procedure or using another application provided verification
214function set with
215.Xr SSL_CTX_set_cert_verify_callback 3 .
216The following descriptions apply in the case of the built-in procedure.
217An application provided procedure also has access to the verify depth
218information and the
219.Fa verify_callback Ns ()
220function, but the way this information is used may be different.
221.Pp
222.Fn SSL_CTX_set_verify_depth
223and
224.Fn SSL_set_verify_depth
225set the limit up to which depth certificates in a chain are used during the
226verification procedure.
227If the certificate chain is longer than allowed,
228the certificates above the limit are ignored.
229Error messages are generated as if these certificates would not be present,
230most likely a
231.Dv X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY
232will be issued.
233The depth count is
234.Dq level 0: peer certificate ,
235.Dq level 1: CA certificate ,
236.Dq level 2: higher level CA certificate ,
237and so on.
238Setting the maximum depth to 2 allows the levels 0, 1, and 2.
239The default depth limit is 100,
240allowing for the peer certificate and an additional 100 CA certificates.
241.Pp
242The
243.Fa verify_callback
244function is used to control the behaviour when the
245.Dv SSL_VERIFY_PEER
246flag is set.
247It must be supplied by the application and receives two arguments:
248.Fa preverify_ok
249indicates whether the verification of the certificate in question was passed
250(preverify_ok=1) or not (preverify_ok=0).
251.Fa x509_ctx
252is a pointer to the complete context used
253for the certificate chain verification.
254.Pp
255The certificate chain is checked starting with the deepest nesting level
256(the root CA certificate) and worked upward to the peer's certificate.
257At each level signatures and issuer attributes are checked.
258Whenever a verification error is found, the error number is stored in
259.Fa x509_ctx
260and
261.Fa verify_callback
262is called with
263.Fa preverify_ok
264equal to 0.
265By applying
266.Fn X509_CTX_store_*
267functions
268.Fa verify_callback
269can locate the certificate in question and perform additional steps (see
270.Sx EXAMPLES ) .
271If no error is found for a certificate,
272.Fa verify_callback
273is called with
274.Fa preverify_ok
275equal to 1 before advancing to the next level.
276.Pp
277The return value of
278.Fa verify_callback
279controls the strategy of the further verification process.
280If
281.Fa verify_callback
282returns 0, the verification process is immediately stopped with
283.Dq verification failed
284state.
285If
286.Dv SSL_VERIFY_PEER
287is set, a verification failure alert is sent to the peer and the TLS/SSL
288handshake is terminated.
289If
290.Fa verify_callback
291returns 1, the verification process is continued.
292If
293.Fa verify_callback
294always returns 1,
295the TLS/SSL handshake will not be terminated with respect to verification
296failures and the connection will be established.
297The calling process can however retrieve the error code of the last
298verification error using
299.Xr SSL_get_verify_result 3
300or by maintaining its own error storage managed by
301.Fa verify_callback .
302.Pp
303If no
304.Fa verify_callback
305is specified, the default callback will be used.
306Its return value is identical to
307.Fa preverify_ok ,
308so that any verification
309failure will lead to a termination of the TLS/SSL handshake with an
310alert message, if
311.Dv SSL_VERIFY_PEER
312is set.
313.Sh EXAMPLES
314The following code sequence realizes an example
315.Fa verify_callback
316function that will always continue the TLS/SSL handshake regardless of
317verification failure, if wished.
318The callback realizes a verification depth limit with more informational output.
319.Pp
320All verification errors are printed;
321information about the certificate chain is printed on request.
322The example is realized for a server that does allow but not require client
323certificates.
324.Pp
325The example makes use of the ex_data technique to store application data
326into/retrieve application data from the
327.Vt SSL
328structure (see
329.Xr SSL_get_ex_new_index 3 ,
330.Xr SSL_get_ex_data_X509_STORE_CTX_idx 3 ) .
331.Bd -literal
332\&...
333
334typedef struct {
335 int verbose_mode;
336 int verify_depth;
337 int always_continue;
338} mydata_t;
339int mydata_index;
340\&...
341static int
342verify_callback(int preverify_ok, X509_STORE_CTX *ctx)
343{
344 char buf[256];
345 X509 *err_cert;
346 int err, depth;
347 SSL *ssl;
348 mydata_t *mydata;
349
350 err_cert = X509_STORE_CTX_get_current_cert(ctx);
351 err = X509_STORE_CTX_get_error(ctx);
352 depth = X509_STORE_CTX_get_error_depth(ctx);
353
354 /*
355 * Retrieve the pointer to the SSL of the connection currently
356 * treated * and the application specific data stored into the
357 * SSL object.
358 */
359 ssl = X509_STORE_CTX_get_ex_data(ctx,
360 SSL_get_ex_data_X509_STORE_CTX_idx());
361 mydata = SSL_get_ex_data(ssl, mydata_index);
362
363 X509_NAME_oneline(X509_get_subject_name(err_cert), buf, 256);
364
365 /*
366 * Catch a too long certificate chain. The depth limit set using
367 * SSL_CTX_set_verify_depth() is by purpose set to "limit+1" so
368 * that whenever the "depth>verify_depth" condition is met, we
369 * have violated the limit and want to log this error condition.
370 * We must do it here, because the CHAIN_TOO_LONG error would not
371 * be found explicitly; only errors introduced by cutting off the
372 * additional certificates would be logged.
373 */
374 if (depth > mydata->verify_depth) {
375 preverify_ok = 0;
376 err = X509_V_ERR_CERT_CHAIN_TOO_LONG;
377 X509_STORE_CTX_set_error(ctx, err);
378 }
379 if (!preverify_ok) {
380 printf("verify error:num=%d:%s:depth=%d:%s\en", err,
381 X509_verify_cert_error_string(err), depth, buf);
382 } else if (mydata->verbose_mode) {
383 printf("depth=%d:%s\en", depth, buf);
384 }
385
386 /*
387 * At this point, err contains the last verification error.
388 * We can use it for something special
389 */
390 if (!preverify_ok && (err ==
391 X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT)) {
392 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),
393 buf, 256);
394 printf("issuer= %s\en", buf);
395 }
396
397 if (mydata->always_continue)
398 return 1;
399 else
400 return preverify_ok;
401}
402\&...
403
404mydata_t mydata;
405
406\&...
407
408mydata_index = SSL_get_ex_new_index(0, "mydata index", NULL, NULL, NULL);
409
410\&...
411
412SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_CLIENT_ONCE,
413 verify_callback);
414
415/*
416 * Let the verify_callback catch the verify_depth error so that we get
417 * an appropriate error in the logfile.
418 */
419SSL_CTX_set_verify_depth(verify_depth + 1);
420
421/*
422 * Set up the SSL specific data into "mydata" and store it into the SSL
423 * structure.
424 */
425mydata.verify_depth = verify_depth; ...
426SSL_set_ex_data(ssl, mydata_index, &mydata);
427
428\&...
429
430SSL_accept(ssl); /* check of success left out for clarity */
431if (peer = SSL_get_peer_certificate(ssl)) {
432 if (SSL_get_verify_result(ssl) == X509_V_OK) {
433 /* The client sent a certificate which verified OK */
434 }
435}
436.Ed
437.Sh SEE ALSO
438.Xr ssl 3 ,
439.Xr SSL_CTX_get_verify_mode 3 ,
440.Xr SSL_CTX_load_verify_locations 3 ,
441.Xr SSL_CTX_set_cert_verify_callback 3 ,
442.Xr SSL_get_ex_data_X509_STORE_CTX_idx 3 ,
443.Xr SSL_get_ex_new_index 3 ,
444.Xr SSL_get_peer_certificate 3 ,
445.Xr SSL_get_verify_result 3 ,
446.Xr SSL_new 3 ,
447.Xr SSL_set1_host 3
448.Sh HISTORY
449.Fn SSL_set_verify
450appeared in SSLeay 0.4 or earlier.
451.Fn SSL_CTX_set_verify
452first appeared in SSLeay 0.6.4.
453Both functions have been available since
454.Ox 2.4 .
455.Pp
456.Fn SSL_CTX_set_verify_depth
457and
458.Fn SSL_set_verify_depth
459first appeared in OpenSSL 0.9.3 and have been available since
460.Ox 2.6 .
461.Sh BUGS
462In client mode, it is not checked whether the
463.Dv SSL_VERIFY_PEER
464flag is set, but whether
465.Dv SSL_VERIFY_NONE
466is not set.
467This can lead to unexpected behaviour, if the
468.Dv SSL_VERIFY_PEER
469and
470.Dv SSL_VERIFY_NONE
471are not used as required (exactly one must be set at any time).
472.Pp
473The certificate verification depth set with
474.Fn SSL[_CTX]_verify_depth
475stops the verification at a certain depth.
476The error message produced will be that of an incomplete certificate chain and
477not
478.Dv X509_V_ERR_CERT_CHAIN_TOO_LONG
479as may be expected.
diff --git a/src/lib/libssl/man/SSL_CTX_use_certificate.3 b/src/lib/libssl/man/SSL_CTX_use_certificate.3
deleted file mode 100644
index c88a6971b2..0000000000
--- a/src/lib/libssl/man/SSL_CTX_use_certificate.3
+++ /dev/null
@@ -1,451 +0,0 @@
1.\" $OpenBSD: SSL_CTX_use_certificate.3,v 1.17 2025/01/18 10:45:12 tb Exp $
2.\" full merge up to: OpenSSL 3aaa1bd0 Mar 28 16:35:25 2017 +1000
3.\" selective merge up to: OpenSSL d1f7a1e6 Apr 26 14:05:40 2018 +0100
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
6.\" Copyright (c) 2000, 2001, 2002, 2003, 2005 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: January 18 2025 $
54.Dt SSL_CTX_USE_CERTIFICATE 3
55.Os
56.Sh NAME
57.Nm SSL_CTX_use_certificate ,
58.Nm SSL_CTX_use_certificate_ASN1 ,
59.Nm SSL_CTX_use_certificate_file ,
60.Nm SSL_use_certificate ,
61.Nm SSL_use_certificate_ASN1 ,
62.Nm SSL_use_certificate_chain_file ,
63.Nm SSL_use_certificate_file ,
64.Nm SSL_CTX_use_certificate_chain_file ,
65.Nm SSL_CTX_use_certificate_chain_mem ,
66.Nm SSL_CTX_use_PrivateKey ,
67.Nm SSL_CTX_use_PrivateKey_ASN1 ,
68.Nm SSL_CTX_use_PrivateKey_file ,
69.Nm SSL_CTX_use_RSAPrivateKey ,
70.Nm SSL_CTX_use_RSAPrivateKey_ASN1 ,
71.Nm SSL_CTX_use_RSAPrivateKey_file ,
72.Nm SSL_use_PrivateKey_file ,
73.Nm SSL_use_PrivateKey_ASN1 ,
74.Nm SSL_use_PrivateKey ,
75.Nm SSL_use_RSAPrivateKey ,
76.Nm SSL_use_RSAPrivateKey_ASN1 ,
77.Nm SSL_use_RSAPrivateKey_file ,
78.Nm SSL_CTX_check_private_key ,
79.Nm SSL_check_private_key
80.Nd load certificate and key data
81.Sh SYNOPSIS
82.In openssl/ssl.h
83.Ft int
84.Fn SSL_CTX_use_certificate "SSL_CTX *ctx" "X509 *x"
85.Ft int
86.Fn SSL_CTX_use_certificate_ASN1 "SSL_CTX *ctx" "int len" "unsigned char *d"
87.Ft int
88.Fn SSL_CTX_use_certificate_file "SSL_CTX *ctx" "const char *file" "int type"
89.Ft int
90.Fn SSL_use_certificate "SSL *ssl" "X509 *x"
91.Ft int
92.Fn SSL_use_certificate_ASN1 "SSL *ssl" "unsigned char *d" "int len"
93.Ft int
94.Fn SSL_use_certificate_chain_file "SSL *ssl" "const char *file"
95.Ft int
96.Fn SSL_use_certificate_file "SSL *ssl" "const char *file" "int type"
97.Ft int
98.Fn SSL_CTX_use_certificate_chain_file "SSL_CTX *ctx" "const char *file"
99.Ft int
100.Fn SSL_CTX_use_certificate_chain_mem "SSL_CTX *ctx" "void *buf" "int len"
101.Ft int
102.Fn SSL_CTX_use_PrivateKey "SSL_CTX *ctx" "EVP_PKEY *pkey"
103.Ft int
104.Fo SSL_CTX_use_PrivateKey_ASN1
105.Fa "int pk" "SSL_CTX *ctx" "unsigned char *d" "long len"
106.Fc
107.Ft int
108.Fn SSL_CTX_use_PrivateKey_file "SSL_CTX *ctx" "const char *file" "int type"
109.Ft int
110.Fn SSL_CTX_use_RSAPrivateKey "SSL_CTX *ctx" "RSA *rsa"
111.Ft int
112.Fn SSL_CTX_use_RSAPrivateKey_ASN1 "SSL_CTX *ctx" "unsigned char *d" "long len"
113.Ft int
114.Fn SSL_CTX_use_RSAPrivateKey_file "SSL_CTX *ctx" "const char *file" "int type"
115.Ft int
116.Fn SSL_use_PrivateKey "SSL *ssl" "EVP_PKEY *pkey"
117.Ft int
118.Fn SSL_use_PrivateKey_ASN1 "int pk" "SSL *ssl" "unsigned char *d" "long len"
119.Ft int
120.Fn SSL_use_PrivateKey_file "SSL *ssl" "const char *file" "int type"
121.Ft int
122.Fn SSL_use_RSAPrivateKey "SSL *ssl" "RSA *rsa"
123.Ft int
124.Fn SSL_use_RSAPrivateKey_ASN1 "SSL *ssl" "const unsigned char *d" "long len"
125.Ft int
126.Fn SSL_use_RSAPrivateKey_file "SSL *ssl" "const char *file" "int type"
127.Ft int
128.Fn SSL_CTX_check_private_key "const SSL_CTX *ctx"
129.Ft int
130.Fn SSL_check_private_key "const SSL *ssl"
131.Sh DESCRIPTION
132These functions load the certificates and private keys into the
133.Vt SSL_CTX
134or
135.Vt SSL
136object, respectively.
137.Pp
138The
139.Fn SSL_CTX_*
140class of functions loads the certificates and keys into the
141.Vt SSL_CTX
142object
143.Fa ctx .
144The information is passed to
145.Vt SSL
146objects
147.Fa ssl
148created from
149.Fa ctx
150with
151.Xr SSL_new 3
152by copying, so that changes applied to
153.Fa ctx
154do not propagate to already existing
155.Vt SSL
156objects.
157.Pp
158The
159.Fn SSL_*
160class of functions only loads certificates and keys into a specific
161.Vt SSL
162object.
163The specific information is kept when
164.Xr SSL_clear 3
165is called for this
166.Vt SSL
167object.
168.Pp
169.Fn SSL_CTX_use_certificate
170loads the certificate
171.Fa x
172into
173.Fa ctx ;
174.Fn SSL_use_certificate
175loads
176.Fa x
177into
178.Fa ssl .
179The rest of the certificates needed to form the complete certificate chain can
180be specified using the
181.Xr SSL_CTX_add_extra_chain_cert 3
182function.
183.Pp
184.Fn SSL_CTX_use_certificate_ASN1
185loads the ASN1 encoded certificate from the memory location
186.Fa d
187(with length
188.Fa len )
189into
190.Fa ctx ;
191.Fn SSL_use_certificate_ASN1
192loads the ASN1 encoded certificate into
193.Fa ssl .
194.Pp
195.Fn SSL_CTX_use_certificate_file
196loads the first certificate stored in
197.Fa file
198into
199.Fa ctx .
200The formatting
201.Fa type
202of the certificate must be specified from the known types
203.Dv SSL_FILETYPE_PEM
204and
205.Dv SSL_FILETYPE_ASN1 .
206.Fn SSL_use_certificate_file
207loads the certificate from
208.Fa file
209into
210.Fa ssl .
211See the
212.Sx NOTES
213section on why
214.Fn SSL_CTX_use_certificate_chain_file
215should be preferred.
216.Pp
217The
218.Fn SSL_CTX_use_certificate_chain*
219functions load a certificate chain into
220.Fa ctx .
221The certificates must be in PEM format and must be sorted starting with the
222subject's certificate (actual client or server certificate),
223followed by intermediate CA certificates if applicable,
224and ending at the highest level (root) CA.
225With the exception of
226.Fn SSL_use_certificate_chain_file ,
227there is no corresponding function working on a single
228.Vt SSL
229object.
230.Pp
231.Fn SSL_CTX_use_PrivateKey
232adds
233.Fa pkey
234as private key to
235.Fa ctx .
236.Fn SSL_CTX_use_RSAPrivateKey
237adds the private key
238.Fa rsa
239of type RSA to
240.Fa ctx .
241.Fn SSL_use_PrivateKey
242adds
243.Fa pkey
244as private key to
245.Fa ssl ;
246.Fn SSL_use_RSAPrivateKey
247adds
248.Fa rsa
249as private key of type RSA to
250.Fa ssl .
251If a certificate has already been set and the private does not belong to the
252certificate, an error is returned.
253To change a certificate private key pair,
254the new certificate needs to be set with
255.Fn SSL_use_certificate
256or
257.Fn SSL_CTX_use_certificate
258before setting the private key with
259.Fn SSL_CTX_use_PrivateKey
260or
261.Fn SSL_use_PrivateKey .
262.Pp
263.Fn SSL_CTX_use_PrivateKey_ASN1
264adds the private key of type
265.Fa pk
266stored at memory location
267.Fa d
268(length
269.Fa len )
270to
271.Fa ctx .
272.Fn SSL_CTX_use_RSAPrivateKey_ASN1
273adds the private key of type RSA stored at memory location
274.Fa d
275(length
276.Fa len )
277to
278.Fa ctx .
279.Fn SSL_use_PrivateKey_ASN1
280and
281.Fn SSL_use_RSAPrivateKey_ASN1
282add the private key to
283.Fa ssl .
284.Pp
285.Fn SSL_CTX_use_PrivateKey_file
286adds the first private key found in
287.Fa file
288to
289.Fa ctx .
290The formatting
291.Fa type
292of the private key must be specified from the known types
293.Dv SSL_FILETYPE_PEM
294and
295.Dv SSL_FILETYPE_ASN1 .
296.Fn SSL_CTX_use_RSAPrivateKey_file
297adds the first private RSA key found in
298.Fa file
299to
300.Fa ctx .
301.Fn SSL_use_PrivateKey_file
302adds the first private key found in
303.Fa file
304to
305.Fa ssl ;
306.Fn SSL_use_RSAPrivateKey_file
307adds the first private RSA key found to
308.Fa ssl .
309.Pp
310The
311.Fn SSL_CTX_check_private_key
312function is seriously misnamed.
313It compares the
314.Em public
315key components and parameters of an OpenSSL private key with the
316corresponding certificate loaded into
317.Fa ctx .
318If more than one key/certificate pair (RSA/ECDSA) is installed,
319the last item installed will be compared.
320If, e.g., the last item was an RSA certificate or key,
321the RSA key/certificate pair will be checked.
322.Fn SSL_check_private_key
323performs the same
324.Em public
325key comparison for
326.Fa ssl .
327If no key/certificate was explicitly added for this
328.Fa ssl ,
329the last item added into
330.Fa ctx
331will be checked.
332.Pp
333Despite the name, neither
334.Fn SSL_CTX_check_private_key
335nor
336.Fn SSL_check_private_key
337checks whether the private key component is indeed a private key,
338nor whether it matches the public key component.
339They merely compare the public materials (e.g. exponent and modulus of
340an RSA key) and/or key parameters (e.g. EC params of an EC key) of a
341key pair.
342.Sh NOTES
343The internal certificate store of OpenSSL can hold several private
344key/certificate pairs at a time.
345The certificate used depends on the cipher selected.
346See also
347.Xr SSL_CTX_set_cipher_list 3 .
348.Pp
349When reading certificates and private keys from file, files of type
350.Dv SSL_FILETYPE_ASN1
351(also known as
352.Em DER ,
353binary encoding) can only contain one certificate or private key; consequently,
354.Fn SSL_CTX_use_certificate_chain_file
355is only applicable to PEM formatting.
356Files of type
357.Dv SSL_FILETYPE_PEM
358can contain more than one item.
359.Pp
360.Fn SSL_CTX_use_certificate_chain_file
361adds the first certificate found in the file to the certificate store.
362The other certificates are added to the store of chain certificates using
363.Xr SSL_CTX_add1_chain_cert 3 .
364It is recommended to use the
365.Fn SSL_CTX_use_certificate_chain_file
366instead of the
367.Fn SSL_CTX_use_certificate_file
368function in order to allow the use of complete certificate chains even when no
369trusted CA storage is used or when the CA issuing the certificate shall not be
370added to the trusted CA storage.
371.Pp
372If additional certificates are needed to complete the chain during the TLS
373negotiation, CA certificates are additionally looked up in the locations of
374trusted CA certificates (see
375.Xr SSL_CTX_load_verify_locations 3 ) .
376.Pp
377The private keys loaded from file can be encrypted.
378In order to successfully load encrypted keys,
379a function returning the passphrase must have been supplied (see
380.Xr SSL_CTX_set_default_passwd_cb 3 ) .
381(Certificate files might be encrypted as well from the technical point of view,
382it however does not make sense as the data in the certificate is considered
383public anyway.)
384.Sh RETURN VALUES
385On success, the functions return 1.
386Otherwise check out the error stack to find out the reason.
387.Sh SEE ALSO
388.Xr ssl 3 ,
389.Xr SSL_clear 3 ,
390.Xr SSL_CTX_add1_chain_cert 3 ,
391.Xr SSL_CTX_add_extra_chain_cert 3 ,
392.Xr SSL_CTX_load_verify_locations 3 ,
393.Xr SSL_CTX_set_cipher_list 3 ,
394.Xr SSL_CTX_set_client_CA_list 3 ,
395.Xr SSL_CTX_set_client_cert_cb 3 ,
396.Xr SSL_CTX_set_default_passwd_cb 3 ,
397.Xr SSL_new 3 ,
398.Xr X509_check_private_key 3
399.Sh HISTORY
400.Fn SSL_use_certificate ,
401.Fn SSL_use_certificate_file ,
402.Fn SSL_use_RSAPrivateKey ,
403and
404.Fn SSL_use_RSAPrivateKey_file
405appeared in SSLeay 0.4 or earlier.
406.Fn SSL_use_certificate_ASN1
407and
408.Fn SSL_use_RSAPrivateKey_ASN1
409first appeared in SSLeay 0.5.1.
410.Fn SSL_use_PrivateKey_file ,
411.Fn SSL_use_PrivateKey_ASN1 ,
412and
413.Fn SSL_use_PrivateKey
414first appeared in SSLeay 0.6.0.
415.Fn SSL_CTX_use_certificate ,
416.Fn SSL_CTX_use_certificate_ASN1 ,
417.Fn SSL_CTX_use_certificate_file ,
418.Fn SSL_CTX_use_PrivateKey ,
419.Fn SSL_CTX_use_PrivateKey_ASN1 ,
420.Fn SSL_CTX_use_PrivateKey_file ,
421.Fn SSL_CTX_use_RSAPrivateKey ,
422.Fn SSL_CTX_use_RSAPrivateKey_ASN1 ,
423and
424.Fn SSL_CTX_use_RSAPrivateKey_file
425first appeared in SSLeay 0.6.1.
426.Fn SSL_CTX_check_private_key
427and
428.Fn SSL_check_private_key
429first appeared in SSLeay 0.6.5.
430All these functions have been available since
431.Ox 2.4 .
432.Pp
433.Fn SSL_CTX_use_certificate_chain_file
434first appeared in OpenSSL 0.9.4 and has been available since
435.Ox 2.6 .
436.Pp
437.Fn SSL_use_certificate_chain_file
438first appeared in OpenSSL 1.1.0 and has been available since
439.Ox 6.9 .
440.Pp
441Support for DER encoded private keys
442.Pq Dv SSL_FILETYPE_ASN1
443in
444.Fn SSL_CTX_use_PrivateKey_file
445and
446.Fn SSL_use_PrivateKey_file
447was added in 0.9.8.
448.Pp
449.Fn SSL_CTX_use_certificate_chain_mem
450first appeared in
451.Ox 5.7 .
diff --git a/src/lib/libssl/man/SSL_SESSION_free.3 b/src/lib/libssl/man/SSL_SESSION_free.3
deleted file mode 100644
index 3f785e95e5..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_free.3
+++ /dev/null
@@ -1,148 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_free.3,v 1.7 2019/06/12 09:36:30 schwarze Exp $
2.\" full merge up to: OpenSSL b31db505 Mar 24 16:01:50 2017 +0000
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>
5.\" and Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2000, 2001, 2009, 2017 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: June 12 2019 $
54.Dt SSL_SESSION_FREE 3
55.Os
56.Sh NAME
57.Nm SSL_SESSION_up_ref ,
58.Nm SSL_SESSION_free
59.Nd SSL_SESSION reference counting
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft int
63.Fn SSL_SESSION_up_ref "SSL_SESSION *session"
64.Ft void
65.Fn SSL_SESSION_free "SSL_SESSION *session"
66.Sh DESCRIPTION
67.Fn SSL_SESSION_up_ref
68increments the reference count of the given
69.Fa session
70by 1.
71.Pp
72.Fn SSL_SESSION_free
73decrements the reference count of the given
74.Fa session
75by 1.
76If the reference count reaches 0, it frees the memory used by the
77.Fa session .
78If
79.Fa session
80is a
81.Dv NULL
82pointer, no action occurs.
83.Pp
84.Vt SSL_SESSION
85objects are allocated when a TLS/SSL handshake operation is successfully
86completed.
87Depending on the settings, see
88.Xr SSL_CTX_set_session_cache_mode 3 ,
89the
90.Vt SSL_SESSION
91objects are internally referenced by the
92.Vt SSL_CTX
93and linked into its session cache.
94.Vt SSL
95objects may be using the
96.Vt SSL_SESSION
97object; as a session may be reused, several
98.Vt SSL
99objects may be using one
100.Vt SSL_SESSION
101object at the same time.
102It is therefore crucial to keep the reference count (usage information) correct
103and not delete a
104.Vt SSL_SESSION
105object that is still used, as this may lead to program failures due to dangling
106pointers.
107These failures may also appear delayed, e.g., when an
108.Vt SSL_SESSION
109object is completely freed as the reference count incorrectly becomes 0, but it
110is still referenced in the internal session cache and the cache list is
111processed during a
112.Xr SSL_CTX_flush_sessions 3
113operation.
114.Pp
115.Fn SSL_SESSION_free
116must only be called for
117.Vt SSL_SESSION
118objects, for which the reference count was explicitly incremented (e.g., by
119calling
120.Xr SSL_get1_session 3 ;
121see
122.Xr SSL_get_session 3 )
123or when the
124.Vt SSL_SESSION
125object was generated outside a TLS handshake operation, e.g., by using
126.Xr d2i_SSL_SESSION 3 .
127It must not be called on other
128.Vt SSL_SESSION
129objects, as this would cause incorrect reference counts and therefore program
130failures.
131.Sh RETURN VALUES
132.Fn SSL_SESSION_up_ref
133returns 1 on success or 0 on error.
134.Sh SEE ALSO
135.Xr d2i_SSL_SESSION 3 ,
136.Xr ssl 3 ,
137.Xr SSL_CTX_flush_sessions 3 ,
138.Xr SSL_CTX_set_session_cache_mode 3 ,
139.Xr SSL_get_session 3 ,
140.Xr SSL_SESSION_new 3
141.Sh HISTORY
142.Fn SSL_SESSION_free
143first appeared in SSLeay 0.5.2 and has been available since
144.Ox 2.4 .
145.Pp
146.Fn SSL_SESSION_up_ref
147first appeared in OpenSSL 1.1.0 and has been available since
148.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get0_cipher.3 b/src/lib/libssl/man/SSL_SESSION_get0_cipher.3
deleted file mode 100644
index 239a426dbd..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get0_cipher.3
+++ /dev/null
@@ -1,94 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get0_cipher.3,v 1.1 2021/05/12 14:16:25 tb Exp $
2.\" full merge up to: OpenSSL d42e7759f Mar 30 19:40:04 2017 +0200
3.\" selective merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
4.\"
5.\" This file was written by Rich Salz <rsalz@openssl.org>.
6.\" Copyright (c) 2016, 2017 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: May 12 2021 $
53.Dt SSL_SESSION_GET0_CIPHER 3
54.Os
55.Sh NAME
56.Nm SSL_SESSION_get0_cipher
57.Nd retrieve the SSL cipher associated with a session
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft const SSL_CIPHER *
61.Fo SSL_SESSION_get0_cipher
62.Fa "const SSL_SESSION *session"
63.Fc
64.Sh DESCRIPTION
65.Fn SSL_SESSION_get0_cipher
66retrieves the cipher that was used by the connection when the session
67was created, or
68.Dv NULL
69if it cannot be determined.
70.Pp
71The value returned is a pointer to an object maintained within
72.Fa session
73and should not be released.
74.Sh RETURN VALUES
75.Fn SSL_SESSION_get0_cipher
76returns the
77.Vt SSL_CIPHER
78associated with
79.Fa session
80or
81.Dv NULL
82if it cannot be determined.
83.Sh SEE ALSO
84.Xr ssl 3 ,
85.Xr SSL_CIPHER_get_name 3 ,
86.Xr SSL_get_current_cipher 3 ,
87.Xr SSL_get_session 3 ,
88.Xr SSL_SESSION_new 3
89.Sh HISTORY
90The
91.Fn SSL_SESSION_get0_cipher
92function first appeared in OpenSSL 1.1.0
93and has been available since
94.Ox 7.0 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get0_peer.3 b/src/lib/libssl/man/SSL_SESSION_get0_peer.3
deleted file mode 100644
index 6b1ef6680e..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get0_peer.3
+++ /dev/null
@@ -1,80 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get0_peer.3,v 1.2 2018/03/23 05:50:30 schwarze Exp $
2.\" OpenSSL SSL_SESSION_get0_peer.pod b31db505 Mar 24 16:01:50 2017 +0000
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>
5.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 23 2018 $
52.Dt SSL_SESSION_GET0_PEER 3
53.Os
54.Sh NAME
55.Nm SSL_SESSION_get0_peer
56.Nd get details about peer's certificate for a session
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft X509 *
60.Fo SSL_SESSION_get0_peer
61.Fa "SSL_SESSION *s"
62.Fc
63.Sh DESCRIPTION
64.Fn SSL_SESSION_get0_peer
65returns a pointer to the peer certificate associated with the session
66.Fa s
67or
68.Dv NULL
69if no peer certificate is available.
70The caller should not free the returned value, unless
71.Xr X509_up_ref 3
72has also been called.
73.Sh SEE ALSO
74.Xr ssl 3 ,
75.Xr SSL_get_session 3 ,
76.Xr SSL_SESSION_new 3
77.Sh HISTORY
78.Fn SSL_SESSION_get0_peer
79first appeared in OpenSSL 1.0.1 and has been available since
80.Ox 5.3 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get_compress_id.3 b/src/lib/libssl/man/SSL_SESSION_get_compress_id.3
deleted file mode 100644
index aedc216a15..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get_compress_id.3
+++ /dev/null
@@ -1,78 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get_compress_id.3,v 1.3 2018/03/23 05:50:30 schwarze Exp $
2.\" OpenSSL SSL_SESSION_get_compress_id.pod b31db505 Mar 24 16:01:50 2017
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>
5.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 23 2018 $
52.Dt SSL_SESSION_GET_COMPRESS_ID 3
53.Os
54.Sh NAME
55.Nm SSL_SESSION_get_compress_id
56.Nd get details about the compression associated with a session
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft unsigned int
60.Fo SSL_SESSION_get_compress_id
61.Fa "const SSL_SESSION *s"
62.Fc
63.Sh DESCRIPTION
64If compression has been negotiated for an ssl session,
65.Fn SSL_SESSION_get_compress_id
66returns the id for the compression method, or 0 otherwise.
67The only built-in supported compression method is zlib,
68which has an id of 1.
69.Sh SEE ALSO
70.Xr ssl 3 ,
71.Xr SSL_get_session 3 ,
72.Xr SSL_SESSION_get_id 3 ,
73.Xr SSL_SESSION_get_protocol_version 3 ,
74.Xr SSL_SESSION_new 3
75.Sh HISTORY
76.Fn SSL_SESSION_get_compress_id
77first appeared in OpenSSL 1.0.1 and has been available since
78.Ox 5.3 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get_ex_new_index.3 b/src/lib/libssl/man/SSL_SESSION_get_ex_new_index.3
deleted file mode 100644
index 9fd6949b6a..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get_ex_new_index.3
+++ /dev/null
@@ -1,134 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get_ex_new_index.3,v 1.3 2018/03/21 08:06:34 schwarze Exp $
2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 21 2018 $
52.Dt SSL_SESSION_GET_EX_NEW_INDEX 3
53.Os
54.Sh NAME
55.Nm SSL_SESSION_get_ex_new_index ,
56.Nm SSL_SESSION_set_ex_data ,
57.Nm SSL_SESSION_get_ex_data
58.Nd internal application specific data functions
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fo SSL_SESSION_get_ex_new_index
63.Fa "long argl"
64.Fa "void *argp"
65.Fa "CRYPTO_EX_new *new_func"
66.Fa "CRYPTO_EX_dup *dup_func"
67.Fa "CRYPTO_EX_free *free_func"
68.Fc
69.Ft int
70.Fn SSL_SESSION_set_ex_data "SSL_SESSION *session" "int idx" "void *arg"
71.Ft void *
72.Fn SSL_SESSION_get_ex_data "const SSL_SESSION *session" "int idx"
73.Bd -literal
74 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
75 int idx, long argl, void *argp);
76 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
77 int idx, long argl, void *argp);
78 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
79 int idx, long argl, void *argp);
80.Ed
81.Sh DESCRIPTION
82Several OpenSSL structures can have application specific data attached to them.
83These functions are used internally by OpenSSL to manipulate
84application-specific data attached to a specific structure.
85.Pp
86.Fn SSL_SESSION_get_ex_new_index
87is used to register a new index for application-specific data.
88.Pp
89.Fn SSL_SESSION_set_ex_data
90is used to store application data at
91.Fa arg
92for
93.Fa idx
94into the
95.Fa session
96object.
97.Pp
98.Fn SSL_SESSION_get_ex_data
99is used to retrieve the information for
100.Fa idx
101from
102.Fa session .
103.Pp
104A detailed description for the
105.Fn *_get_ex_new_index
106functionality
107can be found in
108.Xr RSA_get_ex_new_index 3 .
109The
110.Fn *_get_ex_data
111and
112.Fn *_set_ex_data
113functionality is described in
114.Xr CRYPTO_set_ex_data 3 .
115.Sh WARNINGS
116The application data is only maintained for sessions held in memory.
117The application data is not included when dumping the session with
118.Xr i2d_SSL_SESSION 3
119(and all functions indirectly calling the dump functions like
120.Xr PEM_write_SSL_SESSION 3
121and
122.Xr PEM_write_bio_SSL_SESSION 3 )
123and can therefore not be restored.
124.Sh SEE ALSO
125.Xr CRYPTO_set_ex_data 3 ,
126.Xr RSA_get_ex_new_index 3 ,
127.Xr ssl 3
128.Sh HISTORY
129.Fn SSL_SESSION_get_ex_new_index ,
130.Fn SSL_SESSION_set_ex_data ,
131and
132.Fn SSL_SESSION_get_ex_data
133first appeared in SSLeay 0.9.0 and have been available since
134.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get_id.3 b/src/lib/libssl/man/SSL_SESSION_get_id.3
deleted file mode 100644
index 6d0de1e52e..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get_id.3
+++ /dev/null
@@ -1,112 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get_id.3,v 1.6 2018/03/24 00:55:37 schwarze Exp $
2.\" full merge up to:
3.\" OpenSSL SSL_SESSION_set1_id 17b60280 Dec 21 09:08:25 2017 +0100
4.\"
5.\" This file was written by Remi Gacogne <rgacogne-github@coredump.fr>
6.\" and Matt Caswell <matt@openssl.org>.
7.\" Copyright (c) 2016, 2017 The OpenSSL Project. All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: March 24 2018 $
54.Dt SSL_SESSION_GET_ID 3
55.Os
56.Sh NAME
57.Nm SSL_SESSION_get_id ,
58.Nm SSL_SESSION_set1_id
59.Nd get and set the SSL session ID
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft const unsigned char *
63.Fo SSL_SESSION_get_id
64.Fa "const SSL_SESSION *s"
65.Fa "unsigned int *len"
66.Fc
67.Ft int
68.Fo SSL_SESSION_set1_id
69.Fa "SSL_SESSION *s"
70.Fa "const unsigned char *sid"
71.Fa "unsigned int sid_len"
72.Fc
73.Sh DESCRIPTION
74.Fn SSL_SESSION_get_id
75returns a pointer to the internal session ID value for the session
76.Fa s .
77The length of the ID in bytes is stored in
78.Pf * Fa len .
79The length may be 0.
80The caller should not free the returned pointer directly.
81.Pp
82.Fn SSL_SESSION_set1_id
83sets the session ID for
84.Fa s
85to a copy of the
86.Fa sid
87of length
88.Fa sid_len .
89.Sh RETURN VALUES
90.Fn SSL_SESSION_get_id
91returns a pointer to the session ID value.
92.Pp
93.Fn SSL_SESSION_set1_id
94returns 1 for success and 0 for failure,
95for example if the supplied session ID length exceeds
96.Dv SSL_MAX_SSL_SESSION_ID_LENGTH .
97.Sh SEE ALSO
98.Xr ssl 3 ,
99.Xr SSL_copy_session_id 3 ,
100.Xr SSL_get_session 3 ,
101.Xr SSL_SESSION_get_compress_id 3 ,
102.Xr SSL_SESSION_get_protocol_version 3 ,
103.Xr SSL_SESSION_has_ticket 3 ,
104.Xr SSL_SESSION_new 3
105.Sh HISTORY
106.Fn SSL_SESSION_get_id
107first appeared in OpenSSL 0.9.8 and has been available since
108.Ox 4.5 .
109.Pp
110.Fn SSL_SESSION_set1_id
111first appeared in OpenSSL 1.1.0 and has been available since
112.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get_protocol_version.3 b/src/lib/libssl/man/SSL_SESSION_get_protocol_version.3
deleted file mode 100644
index f14c0490e9..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get_protocol_version.3
+++ /dev/null
@@ -1,84 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get_protocol_version.3,v 1.2 2018/03/24 00:55:37 schwarze Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by TJ Saunders <tj@castaglia.org>
5.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 24 2018 $
52.Dt SSL_SESSION_GET_PROTOCOL_VERSION 3
53.Os
54.Sh NAME
55.Nm SSL_SESSION_get_protocol_version
56.Nd get the session protocol version
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fo SSL_SESSION_get_protocol_version
61.Fa "const SSL_SESSION *s"
62.Fc
63.Sh DESCRIPTION
64.Fn SSL_SESSION_get_protocol_version
65returns the protocol version number used by the session
66.Fa s .
67.Sh RETURN VALUES
68.Fn SSL_SESSION_get_protocol_version
69returns a constant like
70.Dv TLS1_VERSION
71or
72.Dv TLS1_2_VERSION .
73.Sh SEE ALSO
74.Xr ssl 3 ,
75.Xr SSL_get_session 3 ,
76.Xr SSL_SESSION_get0_peer 3 ,
77.Xr SSL_SESSION_get_compress_id 3 ,
78.Xr SSL_SESSION_get_id 3 ,
79.Xr SSL_SESSION_get_time 3 ,
80.Xr SSL_SESSION_new 3
81.Sh HISTORY
82.Fn SSL_SESSION_get_protocol_version
83first appeared in OpenSSL 1.1.0 and has been available since
84.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_SESSION_get_time.3 b/src/lib/libssl/man/SSL_SESSION_get_time.3
deleted file mode 100644
index aaadec5137..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_get_time.3
+++ /dev/null
@@ -1,165 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_get_time.3,v 1.8 2019/06/08 15:25:43 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005, 2006, 2016 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 8 2019 $
53.Dt SSL_SESSION_GET_TIME 3
54.Os
55.Sh NAME
56.Nm SSL_SESSION_get_time ,
57.Nm SSL_SESSION_set_time ,
58.Nm SSL_SESSION_get_timeout ,
59.Nm SSL_SESSION_set_timeout ,
60.Nm SSL_get_time ,
61.Nm SSL_set_time ,
62.Nm SSL_get_timeout ,
63.Nm SSL_set_timeout
64.Nd retrieve and manipulate session time and timeout settings
65.Sh SYNOPSIS
66.In openssl/ssl.h
67.Ft long
68.Fn SSL_SESSION_get_time "const SSL_SESSION *s"
69.Ft long
70.Fn SSL_SESSION_set_time "SSL_SESSION *s" "long tm"
71.Ft long
72.Fn SSL_SESSION_get_timeout "const SSL_SESSION *s"
73.Ft long
74.Fn SSL_SESSION_set_timeout "SSL_SESSION *s" "long tm"
75.Ft long
76.Fn SSL_get_time "const SSL_SESSION *s"
77.Ft long
78.Fn SSL_set_time "SSL_SESSION *s" "long tm"
79.Ft long
80.Fn SSL_get_timeout "const SSL_SESSION *s"
81.Ft long
82.Fn SSL_set_timeout "SSL_SESSION *s" "long tm"
83.Sh DESCRIPTION
84.Fn SSL_SESSION_get_time
85returns the time at which the session
86.Fa s
87was established.
88The time is given in seconds since the Epoch and therefore compatible to the
89time delivered by the
90.Xr time 3
91call.
92.Pp
93.Fn SSL_SESSION_set_time
94replaces the creation time of the session
95.Fa s
96with
97the chosen value
98.Fa tm .
99.Pp
100.Fn SSL_SESSION_get_timeout
101returns the timeout value set for session
102.Fa s
103in seconds.
104.Pp
105.Fn SSL_SESSION_set_timeout
106sets the timeout value for session
107.Fa s
108in seconds to
109.Fa tm .
110.Pp
111The
112.Fn SSL_get_time ,
113.Fn SSL_set_time ,
114.Fn SSL_get_timeout ,
115and
116.Fn SSL_set_timeout
117functions are synonyms for the
118.Fn SSL_SESSION_*
119counterparts.
120.Pp
121Sessions are expired by examining the creation time and the timeout value.
122Both are set at creation time of the session to the actual time and the default
123timeout value at creation, respectively, as set by
124.Xr SSL_CTX_set_timeout 3 .
125Using these functions it is possible to extend or shorten the lifetime of the
126session.
127.Sh RETURN VALUES
128.Fn SSL_SESSION_get_time
129and
130.Fn SSL_SESSION_get_timeout
131return the currently valid values.
132.Pp
133.Fn SSL_SESSION_set_time
134and
135.Fn SSL_SESSION_set_timeout
136return 1 on success.
137.Pp
138If any of the function is passed the
139.Dv NULL
140pointer for the session
141.Fa s ,
1420 is returned.
143.Sh SEE ALSO
144.Xr ssl 3 ,
145.Xr SSL_CTX_set_timeout 3 ,
146.Xr SSL_get_default_timeout 3 ,
147.Xr SSL_get_session 3 ,
148.Xr SSL_SESSION_has_ticket 3 ,
149.Xr SSL_SESSION_new 3
150.Sh HISTORY
151.Fn SSL_get_time ,
152.Fn SSL_get_timeout ,
153and
154.Fn SSL_set_timeout
155appeared in SSLeay 0.4 or earlier.
156.Fn SSL_set_time
157first appeared in SSLeay 0.5.2.
158.Fn SSL_SESSION_get_time ,
159.Fn SSL_SESSION_set_time ,
160.Fn SSL_SESSION_get_timeout ,
161and
162.Fn SSL_SESSION_set_timeout
163first appeared in SSLeay 0.9.0.
164All these functions have been available since
165.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_SESSION_has_ticket.3 b/src/lib/libssl/man/SSL_SESSION_has_ticket.3
deleted file mode 100644
index 322b49feef..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_has_ticket.3
+++ /dev/null
@@ -1,85 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_has_ticket.3,v 1.2 2018/03/24 00:55:37 schwarze Exp $
2.\" full merge up to: OpenSSL f2baac27 Feb 8 15:43:16 2015 +0000
3.\" selective merge up to: OpenSSL 61f805c1 Jan 16 01:01:46 2018 +0800
4.\"
5.\" This file was written by Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2015 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 24 2018 $
53.Dt SSL_SESSION_HAS_TICKET 3
54.Os
55.Sh NAME
56.Nm SSL_SESSION_has_ticket ,
57.Nm SSL_SESSION_get_ticket_lifetime_hint
58.Nd get details about the ticket associated with a session
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fo SSL_SESSION_has_ticket
63.Fa "const SSL_SESSION *s"
64.Fc
65.Ft unsigned long
66.Fo SSL_SESSION_get_ticket_lifetime_hint
67.Fa "const SSL_SESSION *s"
68.Fc
69.Sh DESCRIPTION
70.Fn SSL_SESSION_has_ticket
71returns 1 if there is a Session Ticket associated with
72.Fa s
73or 0 otherwise.
74.Pp
75.Fn SSL_SESSION_get_ticket_lifetime_hint
76returns the lifetime hint in seconds associated with the session ticket.
77.Sh SEE ALSO
78.Xr ssl 3 ,
79.Xr SSL_SESSION_get_id 3 ,
80.Xr SSL_SESSION_get_time 3 ,
81.Xr SSL_SESSION_new 3
82.Sh HISTORY
83These functions first appeared in OpenSSL 1.1.0
84and have been available since
85.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_SESSION_is_resumable.3 b/src/lib/libssl/man/SSL_SESSION_is_resumable.3
deleted file mode 100644
index 48d7d17889..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_is_resumable.3
+++ /dev/null
@@ -1,81 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_is_resumable.3,v 1.1 2021/09/14 14:08:15 schwarze Exp $
2.\" full merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>.
5.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: September 14 2021 $
52.Dt SSL_SESSION_IS_RESUMABLE 3
53.Os
54.Sh NAME
55.Nm SSL_SESSION_is_resumable
56.Nd determine whether an SSL_SESSION object can be used for resumption
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fo SSL_SESSION_is_resumable
61.Fa "const SSL_SESSION *session"
62.Fc
63.Sh DESCRIPTION
64.Fn SSL_SESSION_is_resumable
65determines whether the
66.Fa session
67object can be used to resume a session.
68Note that attempting to resume with a non-resumable session
69will result in a full handshake.
70.Sh RETURN VALUES
71.Fn SSL_SESSION_is_resumable
72returns 1 if the session is resumable or 0 otherwise.
73It always returns 0 with LibreSSL.
74.Sh SEE ALSO
75.Xr ssl 3 ,
76.Xr SSL_CTX_sess_set_new_cb 3 ,
77.Xr SSL_get_session 3
78.Sh HISTORY
79.Fn SSL_SESSION_is_resumable
80first appeared in OpenSSL 1.1.1 and has been available since
81.Ox 7.0 .
diff --git a/src/lib/libssl/man/SSL_SESSION_new.3 b/src/lib/libssl/man/SSL_SESSION_new.3
deleted file mode 100644
index 2dcdb264c1..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_new.3
+++ /dev/null
@@ -1,78 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_new.3,v 1.9 2021/09/14 14:08:15 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: September 14 2021 $
18.Dt SSL_SESSION_NEW 3
19.Os
20.Sh NAME
21.Nm SSL_SESSION_new
22.Nd construct a new SSL_SESSION object
23.Sh SYNOPSIS
24.In openssl/ssl.h
25.Ft SSL_SESSION *
26.Fn SSL_SESSION_new void
27.Sh DESCRIPTION
28.Fn SSL_SESSION_new
29allocates and initializes a new
30.Vt SSL_SESSION
31object.
32The reference count is set to 1, the time to the current time, and
33the timeout to five minutes.
34.Pp
35When the object is no longer needed, it can be destructed with
36.Xr SSL_SESSION_free 3 .
37.Pp
38.Fn SSL_SESSION_new
39is used internally, for example by
40.Xr SSL_connect 3 .
41.Sh RETURN VALUES
42.Fn SSL_SESSION_new
43returns the new
44.Vt SSL_SESSION
45object or
46.Dv NULL
47if insufficient memory is available.
48.Pp
49After failure,
50.Xr ERR_get_error 3
51returns
52.Dv ERR_R_MALLOC_FAILURE .
53.Sh SEE ALSO
54.Xr d2i_SSL_SESSION 3 ,
55.Xr PEM_read_SSL_SESSION 3 ,
56.Xr ssl 3 ,
57.Xr SSL_connect 3 ,
58.Xr SSL_copy_session_id 3 ,
59.Xr SSL_CTX_add_session 3 ,
60.Xr SSL_CTX_sess_set_get_cb 3 ,
61.Xr SSL_get_session 3 ,
62.Xr SSL_SESSION_free 3 ,
63.Xr SSL_SESSION_get0_peer 3 ,
64.Xr SSL_SESSION_get_compress_id 3 ,
65.Xr SSL_SESSION_get_ex_new_index 3 ,
66.Xr SSL_SESSION_get_id 3 ,
67.Xr SSL_SESSION_get_master_key 3 ,
68.Xr SSL_SESSION_get_protocol_version 3 ,
69.Xr SSL_SESSION_get_time 3 ,
70.Xr SSL_SESSION_has_ticket 3 ,
71.Xr SSL_SESSION_is_resumable 3 ,
72.Xr SSL_SESSION_print 3 ,
73.Xr SSL_SESSION_set1_id_context 3 ,
74.Xr SSL_set_session 3
75.Sh HISTORY
76.Fn SSL_SESSION_new
77first appeared in SSLeay 0.5.2 and has been available since
78.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_SESSION_print.3 b/src/lib/libssl/man/SSL_SESSION_print.3
deleted file mode 100644
index e92debde0e..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_print.3
+++ /dev/null
@@ -1,74 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_print.3,v 1.4 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_SESSION_PRINT 3
19.Os
20.Sh NAME
21.Nm SSL_SESSION_print ,
22.Nm SSL_SESSION_print_fp
23.Nd print some properties of an SSL_SESSION object
24.Sh SYNOPSIS
25.In openssl/ssl.h
26.Ft int
27.Fo SSL_SESSION_print
28.Fa "BIO *bp"
29.Fa "const SSL_SESSION *session"
30.Fc
31.Ft int
32.Fo SSL_SESSION_print_fp
33.Fa "FILE *fp"
34.Fa "const SSL_SESSION *session"
35.Fc
36.Sh DESCRIPTION
37.Fn SSL_SESSION_print
38prints some properties of
39.Fa session
40in a human-readable format to the
41.Fa "BIO *bp" ,
42including protocol version, cipher name, session ID,
43session ID context, master key, session ticket lifetime hint,
44session ticket, start time, timeout, and verify return code.
45.Pp
46.Fn SSL_SESSION_print_fp
47does the same as
48.Fn SSL_SESSION_print
49except that it prints to the
50.Fa "FILE *fp" .
51.Sh RETURN VALUES
52.Fn SSL_SESSION_print
53and
54.Fn SSL_SESSION_print_fp
55return 1 for success or 0 for failure.
56.Pp
57In some cases, the reason for failure can be determined with
58.Xr ERR_get_error 3 .
59.Sh SEE ALSO
60.Xr d2i_SSL_SESSION 3 ,
61.Xr PEM_read_SSL_SESSION 3 ,
62.Xr ssl 3 ,
63.Xr SSL_get_session 3 ,
64.Xr SSL_SESSION_free 3 ,
65.Xr SSL_SESSION_get_ex_new_index 3 ,
66.Xr SSL_SESSION_get_time 3 ,
67.Xr SSL_SESSION_new 3
68.Sh HISTORY
69.Fn SSL_SESSION_print
70first appeared in SSLeay 0.5.2.
71.Fn SSL_SESSION_print_fp
72first appeared in SSLeay 0.6.0.
73Both functions have been available since
74.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_SESSION_set1_id_context.3 b/src/lib/libssl/man/SSL_SESSION_set1_id_context.3
deleted file mode 100644
index dd7595baca..0000000000
--- a/src/lib/libssl/man/SSL_SESSION_set1_id_context.3
+++ /dev/null
@@ -1,113 +0,0 @@
1.\" $OpenBSD: SSL_SESSION_set1_id_context.3,v 1.4 2018/03/24 00:55:37 schwarze Exp $
2.\" full merge up to:
3.\" OpenSSL SSL_SESSION_get0_id_context b31db505 Mar 24 16:01:50 2017
4.\"
5.\" This file was written by Matt Caswell <matt@openssl.org>
6.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 24 2018 $
53.Dt SSL_SESSION_SET1_ID_CONTEXT 3
54.Os
55.Sh NAME
56.Nm SSL_SESSION_get0_id_context ,
57.Nm SSL_SESSION_set1_id_context
58.Nd get and set the SSL ID context associated with a session
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft const unsigned char *
62.Fo SSL_SESSION_get0_id_context
63.Fa "const SSL_SESSION *s"
64.Fa "unsigned int *len"
65.Fc
66.Ft int
67.Fo SSL_SESSION_set1_id_context
68.Fa "SSL_SESSION *s"
69.Fa "const unsigned char *sid_ctx"
70.Fa "unsigned int sid_ctx_len"
71.Fc
72.Sh DESCRIPTION
73.Fn SSL_SESSION_get0_id_context
74returns the ID context associated with
75.Fa s .
76The length of the ID context in bytes is written to
77.Pf * Fa len
78if
79.Fa len
80is not
81.Dv NULL .
82.Pp
83.Fn SSL_SESSION_set1_id_context
84takes a copy of the provided ID context given in
85.Fa sid_ctx
86and associates it with the session
87.Fa s .
88The length of the ID context is given by
89.Fa sid_ctx_len
90which must not exceed
91.Dv SSL_MAX_SID_CTX_LENGTH
92bytes.
93.Sh RETURN VALUES
94.Fn SSL_SESSION_get0_id_context
95returns an internal pointer to an object maintained within
96.Fa s
97that should not be freed by the caller.
98.Pp
99.Fn SSL_SESSION_set1_id_context
100returns 1 on success or 0 on error.
101.Sh SEE ALSO
102.Xr ssl 3 ,
103.Xr SSL_CTX_set_session_id_context 3 ,
104.Xr SSL_get_session 3 ,
105.Xr SSL_SESSION_new 3
106.Sh HISTORY
107.Fn SSL_SESSION_set1_id_context
108first appeared in OpenSSL 1.0.1 and has been available since
109.Ox 5.3 .
110.Pp
111.Fn SSL_SESSION_get0_id_context
112first appeared in OpenSSL 1.1.0 and has been available since
113.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_accept.3 b/src/lib/libssl/man/SSL_accept.3
deleted file mode 100644
index fb1d89eb57..0000000000
--- a/src/lib/libssl/man/SSL_accept.3
+++ /dev/null
@@ -1,155 +0,0 @@
1.\" $OpenBSD: SSL_accept.3,v 1.6 2019/06/08 15:25:43 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2002, 2003 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 8 2019 $
53.Dt SSL_ACCEPT 3
54.Os
55.Sh NAME
56.Nm SSL_accept
57.Nd wait for a TLS/SSL client to initiate a TLS/SSL handshake
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft int
61.Fn SSL_accept "SSL *ssl"
62.Sh DESCRIPTION
63.Fn SSL_accept
64waits for a TLS/SSL client to initiate the TLS/SSL handshake.
65The communication channel must already have been set and assigned to the
66.Fa ssl
67object by setting an underlying
68.Vt BIO .
69.Pp
70The behaviour of
71.Fn SSL_accept
72depends on the underlying
73.Vt BIO .
74.Pp
75If the underlying
76.Vt BIO
77is
78.Em blocking ,
79.Fn SSL_accept
80will only return once the handshake has been finished or an error occurred.
81.Pp
82If the underlying
83.Vt BIO
84is
85.Em non-blocking ,
86.Fn SSL_accept
87will also return when the underlying
88.Vt BIO
89could not satisfy the needs of
90.Fn SSL_accept
91to continue the handshake, indicating the problem by the return value \(mi1.
92In this case a call to
93.Xr SSL_get_error 3
94with the
95return value of
96.Fn SSL_accept
97will yield
98.Dv SSL_ERROR_WANT_READ
99or
100.Dv SSL_ERROR_WANT_WRITE .
101The calling process then must repeat the call after taking appropriate action
102to satisfy the needs of
103.Fn SSL_accept .
104The action depends on the underlying
105.Dv BIO .
106When using a non-blocking socket, nothing is to be done, but
107.Xr select 2
108can be used to check for the required condition.
109When using a buffering
110.Vt BIO ,
111like a
112.Vt BIO
113pair, data must be written into or retrieved out of the
114.Vt BIO
115before being able to continue.
116.Sh RETURN VALUES
117The following return values can occur:
118.Bl -tag -width Ds
119.It 0
120The TLS/SSL handshake was not successful but was shut down controlled and by
121the specifications of the TLS/SSL protocol.
122Call
123.Xr SSL_get_error 3
124with the return value
125.Fa ret
126to find out the reason.
127.It 1
128The TLS/SSL handshake was successfully completed,
129and a TLS/SSL connection has been established.
130.It <0
131The TLS/SSL handshake was not successful because a fatal error occurred either
132at the protocol level or a connection failure occurred.
133The shutdown was not clean.
134It can also occur of action is need to continue the operation for non-blocking
135.Vt BIO Ns
136s.
137Call
138.Xr SSL_get_error 3
139with the return value
140.Fa ret
141to find out the reason.
142.El
143.Sh SEE ALSO
144.Xr BIO_new 3 ,
145.Xr ssl 3 ,
146.Xr SSL_connect 3 ,
147.Xr SSL_CTX_new 3 ,
148.Xr SSL_do_handshake 3 ,
149.Xr SSL_get_error 3 ,
150.Xr SSL_set_connect_state 3 ,
151.Xr SSL_shutdown 3
152.Sh HISTORY
153.Fn SSL_accept
154appeared in SSLeay 0.4 or earlier and has been available since
155.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_alert_type_string.3 b/src/lib/libssl/man/SSL_alert_type_string.3
deleted file mode 100644
index 354865e546..0000000000
--- a/src/lib/libssl/man/SSL_alert_type_string.3
+++ /dev/null
@@ -1,253 +0,0 @@
1.\" $OpenBSD: SSL_alert_type_string.3,v 1.7 2024/10/13 08:25:09 jsg Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2011 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: October 13 2024 $
52.Dt SSL_ALERT_TYPE_STRING 3
53.Os
54.Sh NAME
55.Nm SSL_alert_type_string ,
56.Nm SSL_alert_type_string_long ,
57.Nm SSL_alert_desc_string ,
58.Nm SSL_alert_desc_string_long
59.Nd get textual description of alert information
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft const char *
63.Fn SSL_alert_type_string "int value"
64.Ft const char *
65.Fn SSL_alert_type_string_long "int value"
66.Ft const char *
67.Fn SSL_alert_desc_string "int value"
68.Ft const char *
69.Fn SSL_alert_desc_string_long "int value"
70.Sh DESCRIPTION
71.Fn SSL_alert_type_string
72returns a one letter string indicating the type of the alert specified by
73.Fa value .
74.Pp
75.Fn SSL_alert_type_string_long
76returns a string indicating the type of the alert specified by
77.Fa value .
78.Pp
79.Fn SSL_alert_desc_string
80returns a two letter string as a short form describing the reason of the alert
81specified by
82.Fa value .
83.Pp
84.Fn SSL_alert_desc_string_long
85returns a string describing the reason of the alert specified by
86.Fa value .
87.Pp
88When one side of an SSL/TLS communication wants to inform the peer about
89a special situation, it sends an alert.
90The alert is sent as a special message and does not influence the normal data
91stream (unless its contents results in the communication being canceled).
92.Pp
93A warning alert is sent, when a non-fatal error condition occurs.
94The
95.Dq close notify
96alert is sent as a warning alert.
97Other examples for non-fatal errors are certificate errors
98.Po
99.Dq certificate expired ,
100.Dq unsupported certificate
101.Pc ,
102for which a warning alert may be sent.
103(The sending party may, however, decide to send a fatal error.)
104The receiving side may cancel the connection on reception of a warning alert at
105its discretion.
106.Pp
107Several alert messages must be sent as fatal alert messages as specified
108by the TLS RFC.
109A fatal alert always leads to a connection abort.
110.Sh RETURN VALUES
111The following strings can occur for
112.Fn SSL_alert_type_string
113or
114.Fn SSL_alert_type_string_long :
115.Bl -tag -width Ds
116.It \(dqW\(dq/\(dqwarning\(dq
117.It \(dqF\(dq/\(dqfatal\(dq
118.It \(dqU\(dq/\(dqunknown\(dq
119This indicates that no support is available for this alert type.
120Probably
121.Fa value
122does not contain a correct alert message.
123.El
124.Pp
125The following strings can occur for
126.Fn SSL_alert_desc_string
127or
128.Fn SSL_alert_desc_string_long :
129.Bl -tag -width Ds
130.It \(dqCN\(dq/\(dqclose notify\(dq
131The connection shall be closed.
132This is a warning alert.
133.It \(dqUM\(dq/\(dqunexpected message\(dq
134An inappropriate message was received.
135This alert is always fatal and should never be observed in communication
136between proper implementations.
137.It \(dqBM\(dq/\(dqbad record mac\(dq
138This alert is returned if a record is received with an incorrect MAC.
139This message is always fatal.
140.It \(dqDF\(dq/\(dqdecompression failure\(dq
141The decompression function received improper input
142(e.g., data that would expand to excessive length).
143This message is always fatal.
144.It \(dqHF\(dq/\(dqhandshake failure\(dq
145Reception of a handshake_failure alert message indicates that the sender was
146unable to negotiate an acceptable set of security parameters given the options
147available.
148This is a fatal error.
149.It \(dqNC\(dq/\(dqno certificate\(dq
150A client, that was asked to send a certificate, does not send a certificate
151(SSLv3 only).
152.It \(dqBC\(dq/\(dqbad certificate\(dq
153A certificate was corrupt, contained signatures that did not verify correctly,
154etc.
155.It \(dqUC\(dq/\(dqunsupported certificate\(dq
156A certificate was of an unsupported type.
157.It \(dqCR\(dq/\(dqcertificate revoked\(dq
158A certificate was revoked by its signer.
159.It \(dqCE\(dq/\(dqcertificate expired\(dq
160A certificate has expired or is not currently valid.
161.It \(dqCU\(dq/\(dqcertificate unknown\(dq
162Some other (unspecified) issue arose in processing the certificate,
163rendering it unacceptable.
164.It \(dqIP\(dq/\(dqillegal parameter\(dq
165A field in the handshake was out of range or inconsistent with other fields.
166This is always fatal.
167.It \(dqDC\(dq/\(dqdecryption failed\(dq
168A TLSCiphertext decrypted in an invalid way: either it wasn't an even multiple
169of the block length or its padding values, when checked, weren't correct.
170This message is always fatal.
171.It \(dqRO\(dq/\(dqrecord overflow\(dq
172A TLSCiphertext record was received which had a length more than
1732^14+2048 bytes, or a record decrypted to a TLSCompressed record with more than
1742^14+1024 bytes.
175This message is always fatal.
176.It \(dqCA\(dq/\(dqunknown CA\(dq
177A valid certificate chain or partial chain was received,
178but the certificate was not accepted because the CA certificate could not be
179located or couldn't be matched with a known, trusted CA.
180This message is always fatal.
181.It \(dqAD\(dq/\(dqaccess denied\(dq
182A valid certificate was received, but when access control was applied,
183the sender decided not to proceed with negotiation.
184This message is always fatal.
185.It \(dqDE\(dq/\(dqdecode error\(dq
186A message could not be decoded because some field was out of the specified
187range or the length of the message was incorrect.
188This message is always fatal.
189.It \(dqCY\(dq/\(dqdecrypt error\(dq
190A handshake cryptographic operation failed, including being unable to correctly
191verify a signature, decrypt a key exchange, or validate a finished message.
192.It \(dqER\(dq/\(dqexport restriction\(dq
193A negotiation not in compliance with export restrictions was detected;
194for example, attempting to transfer a 1024 bit ephemeral RSA key for the
195RSA_EXPORT handshake method.
196This message is always fatal.
197.It \(dqPV\(dq/\(dqprotocol version\(dq
198The protocol version the client has attempted to negotiate is recognized,
199but not supported.
200(For example, old protocol versions might be avoided for security reasons.)
201This message is always fatal.
202.It \(dqIS\(dq/\(dqinsufficient security\(dq
203Returned instead of handshake_failure when a negotiation has failed
204specifically because the server requires ciphers more secure than those
205supported by the client.
206This message is always fatal.
207.It \(dqIE\(dq/\(dqinternal error\(dq
208An internal error unrelated to the peer or the correctness of the protocol
209makes it impossible to continue (such as a memory allocation failure).
210This message is always fatal.
211.It \(dqIF\(dq/\(dqinappropriate fallback\(dq
212Sent by a server in response to an invalid connection retry attempt from
213a client (see RFC 7507).
214.It \(dqUS\(dq/\(dquser canceled\(dq
215This handshake is being canceled for some reason unrelated to a protocol
216failure.
217If the user cancels an operation after the handshake is complete,
218just closing the connection by sending a close_notify is more appropriate.
219This alert should be followed by a close_notify.
220This message is generally a warning.
221.It \(dqNR\(dq/\(dqno renegotiation\(dq
222Sent by the client in response to a hello request or by the server in response
223to a client hello after initial handshaking.
224Either of these would normally lead to renegotiation; when that is not
225appropriate, the recipient should respond with this alert; at that point,
226the original requester can decide whether to proceed with the connection.
227One case where this would be appropriate would be where a server has spawned a
228process to satisfy a request; the process might receive security parameters
229(key length, authentication, etc.) at startup and it might be difficult to
230communicate changes to these parameters after that point.
231This message is always a warning.
232.It \(dqUP\(dq/\(dqunknown PSK identity\(dq
233Sent by the server to indicate that it does not recognize a PSK identity or an
234SRP identity.
235.It \(dqCQ\(dq/\(dqcertificate required\(dq
236Sent by servers when a client certificate is desired but none was provided
237by the client.
238.It \(dqAP\(dq/\(dqno application protocol\(dq
239Sent by servers when a client ALPN extension advertises only protocols that
240the server does not support (see RFC 7301).
241.It \(dqUK\(dq/\(dqunknown\(dq
242This indicates that no description is available for this alert type.
243Probably
244.Fa value
245does not contain a correct alert message.
246.El
247.Sh SEE ALSO
248.Xr ssl 3 ,
249.Xr SSL_CTX_set_info_callback 3
250.Sh HISTORY
251These functions first appeared in SSLeay 0.8.0
252and have been available since
253.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_clear.3 b/src/lib/libssl/man/SSL_clear.3
deleted file mode 100644
index 809c3b20f4..0000000000
--- a/src/lib/libssl/man/SSL_clear.3
+++ /dev/null
@@ -1,144 +0,0 @@
1.\" $OpenBSD: SSL_clear.3,v 1.5 2021/06/11 19:41:39 jmc Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2002, 2011, 2015 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 11 2021 $
53.Dt SSL_CLEAR 3
54.Os
55.Sh NAME
56.Nm SSL_clear
57.Nd reset SSL object to allow another connection
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft int
61.Fn SSL_clear "SSL *ssl"
62.Sh DESCRIPTION
63Reset
64.Fa ssl
65to allow another connection.
66All settings (method, ciphers, BIOs) are kept.
67.Pp
68.Fn SSL_clear
69is used to prepare an
70.Vt SSL
71object for a new connection.
72While all settings are kept,
73a side effect is the handling of the current SSL session.
74If a session is still
75.Em open ,
76it is considered bad and will be removed from the session cache,
77as required by RFC 2246.
78A session is considered open if
79.Xr SSL_shutdown 3
80was not called for the connection or at least
81.Xr SSL_set_shutdown 3
82was used to
83set the
84.Dv SSL_SENT_SHUTDOWN
85state.
86.Pp
87If a session was closed cleanly,
88the session object will be kept and all settings corresponding.
89This explicitly means that for example the special method used during the
90session will be kept for the next handshake.
91So if the session was a TLSv1 session, a
92.Vt SSL
93client object will use a TLSv1 client method for the next handshake and a
94.Vt SSL
95server object will use a TLSv1 server method, even if
96.Fn TLS_*_method Ns s
97were chosen on startup.
98This might lead to connection failures (see
99.Xr SSL_new 3 )
100for a description of the method's properties.
101.Sh RETURN VALUES
102The following return values can occur:
103.Bl -tag -width Ds
104.It 0
105The
106.Fn SSL_clear
107operation could not be performed.
108Check the error stack to find out the reason.
109.It 1
110The
111.Fn SSL_clear
112operation was successful.
113.El
114.Sh SEE ALSO
115.Xr ssl 3 ,
116.Xr SSL_CTX_set_client_cert_cb 3 ,
117.Xr SSL_CTX_set_options 3 ,
118.Xr SSL_free 3 ,
119.Xr SSL_new 3 ,
120.Xr SSL_set_shutdown 3 ,
121.Xr SSL_shutdown 3
122.Sh HISTORY
123.Fn SSL_clear
124first appeared in SSLeay 0.4.5b and has been available since
125.Ox 2.4 .
126.Sh CAVEATS
127.Fn SSL_clear
128resets the
129.Vt SSL
130object to allow for another connection.
131The reset operation however keeps several settings of the last sessions
132(some of these settings were made automatically during the last handshake).
133It only makes sense for a new connection with the exact same peer that shares
134these settings,
135and may fail if that peer changes its settings between connections.
136Use the sequence
137.Xr SSL_get_session 3 ;
138.Xr SSL_new 3 ;
139.Xr SSL_set_session 3 ;
140.Xr SSL_free 3
141instead to avoid such failures (or simply
142.Xr SSL_free 3 ;
143.Xr SSL_new 3
144if session reuse is not desired).
diff --git a/src/lib/libssl/man/SSL_connect.3 b/src/lib/libssl/man/SSL_connect.3
deleted file mode 100644
index d5b962a480..0000000000
--- a/src/lib/libssl/man/SSL_connect.3
+++ /dev/null
@@ -1,154 +0,0 @@
1.\" $OpenBSD: SSL_connect.3,v 1.6 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2002, 2003 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 27 2018 $
53.Dt SSL_CONNECT 3
54.Os
55.Sh NAME
56.Nm SSL_connect
57.Nd initiate the TLS/SSL handshake with a TLS/SSL server
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft int
61.Fn SSL_connect "SSL *ssl"
62.Sh DESCRIPTION
63.Fn SSL_connect
64initiates the TLS/SSL handshake with a server.
65The communication channel must already have been set and assigned to the
66.Fa ssl
67by setting an underlying
68.Vt BIO .
69.Pp
70The behaviour of
71.Fn SSL_connect
72depends on the underlying
73.Vt BIO .
74.Pp
75If the underlying
76.Vt BIO
77is
78.Em blocking ,
79.Fn SSL_connect
80will only return once the handshake has been finished or an error occurred.
81.Pp
82If the underlying
83.Vt BIO
84is
85.Em non-blocking ,
86.Fn SSL_connect
87will also return when the underlying
88.Vt BIO
89could not satisfy the needs of
90.Fn SSL_connect
91to continue the handshake, indicating the problem with the return value \(mi1.
92In this case a call to
93.Xr SSL_get_error 3
94with the return value of
95.Fn SSL_connect
96will yield
97.Dv SSL_ERROR_WANT_READ
98or
99.Dv SSL_ERROR_WANT_WRITE .
100The calling process then must repeat the call after taking appropriate action
101to satisfy the needs of
102.Fn SSL_connect .
103The action depends on the underlying
104.Vt BIO .
105When using a non-blocking socket, nothing is to be done, but
106.Xr select 2
107can be used to check for the required condition.
108When using a buffering
109.Vt BIO ,
110like a
111.Vt BIO
112pair, data must be written into or retrieved out of the
113.Vt BIO
114before being able to continue.
115.Sh RETURN VALUES
116The following return values can occur:
117.Bl -tag -width Ds
118.It 0
119The TLS/SSL handshake was not successful but was shut down controlled and
120by the specifications of the TLS/SSL protocol.
121Call
122.Xr SSL_get_error 3
123with the return value
124.Fa ret
125to find out the reason.
126.It 1
127The TLS/SSL handshake was successfully completed,
128and a TLS/SSL connection has been established.
129.It <0
130The TLS/SSL handshake was not successful, because either a fatal error occurred
131at the protocol level or a connection failure occurred.
132The shutdown was not clean.
133It can also occur if action is needed to continue the operation for
134non-blocking
135.Vt BIO Ns s .
136Call
137.Xr SSL_get_error 3
138with the return value
139.Fa ret
140to find out the reason.
141.El
142.Sh SEE ALSO
143.Xr BIO_new 3 ,
144.Xr ssl 3 ,
145.Xr SSL_accept 3 ,
146.Xr SSL_CTX_new 3 ,
147.Xr SSL_do_handshake 3 ,
148.Xr SSL_get_error 3 ,
149.Xr SSL_set_connect_state 3 ,
150.Xr SSL_shutdown 3
151.Sh HISTORY
152.Fn SSL_connect
153appeared in SSLeay 0.4 or earlier and has been available since
154.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_copy_session_id.3 b/src/lib/libssl/man/SSL_copy_session_id.3
deleted file mode 100644
index a7a7a8aa99..0000000000
--- a/src/lib/libssl/man/SSL_copy_session_id.3
+++ /dev/null
@@ -1,79 +0,0 @@
1.\" $OpenBSD: SSL_copy_session_id.3,v 1.7 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_COPY_SESSION_ID 3
19.Os
20.Sh NAME
21.Nm SSL_copy_session_id
22.Nd copy session details between SSL objects
23.Sh SYNOPSIS
24.In openssl/ssl.h
25.Ft int
26.Fo SSL_copy_session_id
27.Fa "SSL *to"
28.Fa "const SSL *from"
29.Fc
30.Sh DESCRIPTION
31.Fn SSL_copy_session_id
32copies the following data from
33.Fa from
34to
35.Fa to :
36.Bl -dash
37.It
38the pointer to the
39.Vt SSL_SESSION
40object, incrementing its reference count by 1
41.It
42the pointer to the
43.Vt SSL_METHOD
44object; if that changes the method, protocol-specific data is
45reinitialized
46.It
47the pointer to the
48.Vt CERT
49object, incrementing its reference count by 1
50.It
51the session ID context
52.El
53.Pp
54This function is used internally by
55.Xr SSL_dup 3
56and by
57.Xr BIO_ssl_copy_session_id 3 .
58.Sh RETURN VALUES
59.Fn SSL_copy_session_id
60returns 1 on success and 0 on error.
61.Sh SEE ALSO
62.Xr BIO_ssl_copy_session_id 3 ,
63.Xr ssl 3 ,
64.Xr SSL_dup 3 ,
65.Xr SSL_get_session 3 ,
66.Xr SSL_SESSION_get_id 3 ,
67.Xr SSL_SESSION_new 3 ,
68.Xr SSL_set_session 3 ,
69.Xr SSL_set_session_id_context 3
70.Sh HISTORY
71.Fn SSL_copy_session_id
72appeared in SSLeay 0.4 or earlier and has been available since
73.Ox 2.4 .
74.Sh BUGS
75Failures of
76.Xr CRYPTO_add 3
77are silently ignored and may leave
78.Fa to
79in an invalid or inconsistent state.
diff --git a/src/lib/libssl/man/SSL_do_handshake.3 b/src/lib/libssl/man/SSL_do_handshake.3
deleted file mode 100644
index e9327b4229..0000000000
--- a/src/lib/libssl/man/SSL_do_handshake.3
+++ /dev/null
@@ -1,152 +0,0 @@
1.\" $OpenBSD: SSL_do_handshake.3,v 1.6 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Martin Sjoegren <martin@strakt.com>.
5.\" Copyright (c) 2002 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_DO_HANDSHAKE 3
53.Os
54.Sh NAME
55.Nm SSL_do_handshake
56.Nd perform a TLS/SSL handshake
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fn SSL_do_handshake "SSL *ssl"
61.Sh DESCRIPTION
62.Fn SSL_do_handshake
63will wait for a SSL/TLS handshake to take place.
64If the connection is in client mode, the handshake will be started.
65The handshake routines may have to be explicitly set in advance using either
66.Xr SSL_set_connect_state 3
67or
68.Xr SSL_set_accept_state 3 .
69.Pp
70The behaviour of
71.Fn SSL_do_handshake
72depends on the underlying
73.Vt BIO .
74.Pp
75If the underlying
76.Vt BIO
77is
78.Em blocking ,
79.Fn SSL_do_handshake
80will only return once the handshake has been finished or an error occurred.
81.Pp
82If the underlying
83.Vt BIO
84is
85.Em non-blocking ,
86.Fn SSL_do_handshake
87will also return when the underlying
88.Vt BIO
89could not satisfy the needs of
90.Fn SSL_do_handshake
91to continue the handshake.
92In this case a call to
93.Xr SSL_get_error 3
94with the return value of
95.Fn SSL_do_handshake
96will yield
97.Dv SSL_ERROR_WANT_READ
98or
99.Dv SSL_ERROR_WANT_WRITE .
100The calling process then must repeat the call after taking appropriate action
101to satisfy the needs of
102.Fn SSL_do_handshake .
103The action depends on the underlying
104.Vt BIO .
105When using a non-blocking socket, nothing is to be done, but
106.Xr select 2
107can be used to check for the required condition.
108When using a buffering
109.Vt BIO ,
110like a
111.Vt BIO
112pair, data must be written into or retrieved out of the
113.Vt BIO
114before being able to continue.
115.Sh RETURN VALUES
116The following return values can occur:
117.Bl -tag -width Ds
118.It 0
119The TLS/SSL handshake was not successful but was shut down controlled and
120by the specifications of the TLS/SSL protocol.
121Call
122.Xr SSL_get_error 3
123with the return value
124.Fa ret
125to find out the reason.
126.It 1
127The TLS/SSL handshake was successfully completed,
128and a TLS/SSL connection has been established.
129.It <0
130The TLS/SSL handshake was not successful because either a fatal error occurred
131at the protocol level or a connection failure occurred.
132The shutdown was not clean.
133It can also occur if action is needed to continue the operation for
134non-blocking
135.Vt BIO Ns s .
136Call
137.Xr SSL_get_error 3
138with the return value
139.Fa ret
140to find out the reason.
141.El
142.Sh SEE ALSO
143.Xr BIO_new 3 ,
144.Xr ssl 3 ,
145.Xr SSL_accept 3 ,
146.Xr SSL_connect 3 ,
147.Xr SSL_get_error 3 ,
148.Xr SSL_set_connect_state 3
149.Sh HISTORY
150.Fn SSL_do_handshake
151first appeared in SSLeay 0.8.0 and has been available since
152.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_dup.3 b/src/lib/libssl/man/SSL_dup.3
deleted file mode 100644
index a83440b431..0000000000
--- a/src/lib/libssl/man/SSL_dup.3
+++ /dev/null
@@ -1,62 +0,0 @@
1.\" $OpenBSD: SSL_dup.3,v 1.5 2022/07/13 22:05:53 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: July 13 2022 $
18.Dt SSL_DUP 3
19.Os
20.Sh NAME
21.Nm SSL_dup
22.Nd deep copy of an SSL object
23.Sh SYNOPSIS
24.In openssl/ssl.h
25.Ft SSL *
26.Fo SSL_dup
27.Fa "SSL *ssl"
28.Fc
29.Sh DESCRIPTION
30.Fn SSL_dup
31constructs a new
32.Vt SSL
33object in the same context as
34.Fa ssl
35and copies much of the contained data from
36.Fa ssl
37to the new
38.Vt SSL
39object, but many fields, for example tlsext data, are not copied.
40.Pp
41As an exception from deep copying, if a session is already established,
42the new object shares
43.Fa ssl->cert
44with the original object.
45.Sh RETURN VALUES
46.Fn SSL_dup
47returns the new
48.Vt SSL
49object or
50.Dv NULL
51on failure.
52.Sh SEE ALSO
53.Xr ssl 3 ,
54.Xr SSL_clear 3 ,
55.Xr SSL_copy_session_id 3 ,
56.Xr SSL_free 3 ,
57.Xr SSL_new 3 ,
58.Xr SSL_set_security_level 3
59.Sh HISTORY
60.Fn SSL_dup
61first appeared in SSLeay 0.8.0 and has been available since
62.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_dup_CA_list.3 b/src/lib/libssl/man/SSL_dup_CA_list.3
deleted file mode 100644
index d073b07176..0000000000
--- a/src/lib/libssl/man/SSL_dup_CA_list.3
+++ /dev/null
@@ -1,54 +0,0 @@
1.\" $OpenBSD: SSL_dup_CA_list.3,v 1.6 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_DUP_CA_LIST 3
19.Os
20.Sh NAME
21.Nm SSL_dup_CA_list
22.Nd deep copy of a stack of X.509 Name objects
23.\" The capital "N" in "Name" is intentional (X.509 syntax).
24.Sh SYNOPSIS
25.Ft STACK_OF(X509_NAME) *
26.Fo SSL_dup_CA_list
27.Fa "const STACK_OF(X509_NAME) *sk"
28.Fc
29.Sh DESCRIPTION
30.Fn SSL_dup_CA_list
31constructs a new
32.Vt STACK_OF(X509_NAME)
33object and places copies of all the
34.Vt X509_NAME
35objects found on
36.Fa sk
37on it.
38.Sh RETURN VALUES
39.Fn SSL_dup_CA_list
40returns the new
41.Vt STACK_OF(X509_NAME)
42or
43.Dv NULL
44on failure.
45.Sh SEE ALSO
46.Xr ssl 3 ,
47.Xr SSL_CTX_set_client_CA_list 3 ,
48.Xr SSL_get_client_CA_list 3 ,
49.Xr SSL_load_client_CA_file 3 ,
50.Xr X509_NAME_new 3
51.Sh HISTORY
52.Fn SSL_dup_CA_list
53first appeared in SSLeay 0.8.0 and has been available since
54.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_export_keying_material.3 b/src/lib/libssl/man/SSL_export_keying_material.3
deleted file mode 100644
index e32a5c5d61..0000000000
--- a/src/lib/libssl/man/SSL_export_keying_material.3
+++ /dev/null
@@ -1,133 +0,0 @@
1.\" $OpenBSD: SSL_export_keying_material.3,v 1.3 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL a599574b Jun 28 17:18:27 2017 +0100
3.\" OpenSSL 23cec1f4 Jun 21 13:55:02 2017 +0100
4.\"
5.\" This file was written by Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 12 2019 $
53.Dt SSL_EXPORT_KEYING_MATERIAL 3
54.Os
55.Sh NAME
56.Nm SSL_export_keying_material
57.Nd obtain keying material for application use
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft int
61.Fo SSL_export_keying_material
62.Fa "SSL *s"
63.Fa "unsigned char *out"
64.Fa "size_t olen"
65.Fa "const char *label"
66.Fa "size_t llen"
67.Fa "const unsigned char *context"
68.Fa "size_t contextlen"
69.Fa "int use_context"
70.Fc
71.Sh DESCRIPTION
72During the creation of a TLS or DTLS connection,
73shared keying material is established between the two endpoints.
74The function
75.Fn SSL_export_keying_material
76enables an application to use some of this keying material
77for its own purposes in accordance with RFC 5705.
78.Pp
79An application may need to securely establish the context
80within which this keying material will be used.
81For example, this may include identifiers for the application session,
82application algorithms or parameters, or the lifetime of the context.
83The context value is left to the application but must be the same on
84both sides of the communication.
85.Pp
86For a given SSL connection
87.Fa s ,
88.Fa olen
89bytes of data will be written to
90.Fa out .
91The application specific context should be supplied
92in the location pointed to by
93.Fa context
94and should be
95.Fa contextlen
96bytes long.
97Provision of a context is optional.
98If the context should be omitted entirely, then
99.Fa use_context
100should be set to 0.
101Otherwise it should be any other value.
102If
103.Fa use_context
104is 0, then the values of
105.Fa context
106and
107.Fa contextlen
108are ignored.
109.Pp
110In TLSv1.2 and below, a zero length context is treated differently
111from no context at all, and will result in different keying material
112being returned.
113.Pp
114An application specific label should be provided in the location pointed
115to by
116.Fa label
117and should be
118.Fa llen
119bytes long.
120Typically this will be a value from the
121.Lk https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#exporter-labels "IANA Exporter Label Registry" .
122.Pp
123Alternatively, labels beginning with "EXPERIMENTAL" are permitted by the
124standard to be used without registration.
125.Sh RETURN VALUES
126.Fn SSL_export_keying_material
127returns 1 on success or 0 or -1 on failure.
128.Sh SEE ALSO
129.Xr ssl 3
130.Sh HISTORY
131.Fn SSL_export_keying_material
132first appeared in OpenSSL 1.0.1 and has been available since
133.Ox 5.3 .
diff --git a/src/lib/libssl/man/SSL_free.3 b/src/lib/libssl/man/SSL_free.3
deleted file mode 100644
index c713ded121..0000000000
--- a/src/lib/libssl/man/SSL_free.3
+++ /dev/null
@@ -1,115 +0,0 @@
1.\" $OpenBSD: SSL_free.3,v 1.6 2021/06/11 19:41:39 jmc Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 11 2021 $
52.Dt SSL_FREE 3
53.Os
54.Sh NAME
55.Nm SSL_free
56.Nd free an allocated SSL structure
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft void
60.Fn SSL_free "SSL *ssl"
61.Sh DESCRIPTION
62.Fn SSL_free
63decrements the reference count of
64.Fa ssl ,
65and removes the
66.Vt SSL
67structure pointed to by
68.Fa ssl
69and frees up the allocated memory if the reference count has reached 0.
70If
71.Fa ssl
72is a
73.Dv NULL
74pointer, no action occurs.
75.Pp
76.Fn SSL_free
77also calls the
78.Xr free 3 Ns
79ing procedures for indirectly affected items, if applicable: the buffering
80.Vt BIO ,
81the read and write
82.Vt BIOs ,
83cipher lists specially created for this
84.Fa ssl ,
85the
86.Sy SSL_SESSION .
87Do not explicitly free these indirectly freed up items before or after calling
88.Fn SSL_free ,
89as trying to free things twice may lead to program failure.
90.Pp
91The
92.Fa ssl
93session has reference counts from two users: the
94.Vt SSL
95object, for which the reference count is removed by
96.Fn SSL_free
97and the internal session cache.
98If the session is considered bad, because
99.Xr SSL_shutdown 3
100was not called for the connection and
101.Xr SSL_set_shutdown 3
102was not used to set the
103.Vt SSL_SENT_SHUTDOWN
104state, the session will also be removed from the session cache as required by
105RFC 2246.
106.Sh SEE ALSO
107.Xr ssl 3 ,
108.Xr SSL_clear 3 ,
109.Xr SSL_new 3 ,
110.Xr SSL_set_shutdown 3 ,
111.Xr SSL_shutdown 3
112.Sh HISTORY
113.Fn SSL_free
114appeared in SSLeay 0.4 or earlier and has been available since
115.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_SSL_CTX.3 b/src/lib/libssl/man/SSL_get_SSL_CTX.3
deleted file mode 100644
index 60fda555bc..0000000000
--- a/src/lib/libssl/man/SSL_get_SSL_CTX.3
+++ /dev/null
@@ -1,79 +0,0 @@
1.\" $OpenBSD: SSL_get_SSL_CTX.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_GET_SSL_CTX 3
53.Os
54.Sh NAME
55.Nm SSL_get_SSL_CTX
56.Nd get the SSL_CTX from which an SSL is created
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft SSL_CTX *
60.Fn SSL_get_SSL_CTX "const SSL *ssl"
61.Sh DESCRIPTION
62.Fn SSL_get_SSL_CTX
63returns a pointer to the
64.Vt SSL_CTX
65object from which
66.Fa ssl
67was created with
68.Xr SSL_new 3 .
69.Sh RETURN VALUES
70The pointer to the
71.Vt SSL_CTX
72object is returned.
73.Sh SEE ALSO
74.Xr ssl 3 ,
75.Xr SSL_new 3
76.Sh HISTORY
77.Fn SSL_get_SSL_CTX
78first appeared in SSLeay 0.5.1 and has been available since
79.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_certificate.3 b/src/lib/libssl/man/SSL_get_certificate.3
deleted file mode 100644
index eb53ea49bf..0000000000
--- a/src/lib/libssl/man/SSL_get_certificate.3
+++ /dev/null
@@ -1,64 +0,0 @@
1.\" $OpenBSD: SSL_get_certificate.3,v 1.5 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_GET_CERTIFICATE 3
19.Os
20.Sh NAME
21.Nm SSL_get_certificate ,
22.Nm SSL_get_privatekey
23.Nd get SSL certificate and private key
24.Sh SYNOPSIS
25.In openssl/ssl.h
26.Ft X509 *
27.Fo SSL_get_certificate
28.Fa "const SSL *ssl"
29.Fc
30.Ft EVP_PKEY *
31.Fo SSL_get_privatekey
32.Fa "const SSL *ssl"
33.Fc
34.Sh DESCRIPTION
35These functions retrieve certificate and key data from an
36.Vt SSL
37object.
38They return internal pointers that must not be freed by the application
39program.
40.Sh RETURN VALUES
41.Fn SSL_get_certificate
42returns the active X.509 certificate currently used by
43.Fa ssl
44or
45.Dv NULL
46if none is active.
47.Pp
48.Fn SSL_get_privatekey
49returns the active private key currently used by
50.Fa ssl
51or
52.Dv NULL
53if none is active.
54.Sh SEE ALSO
55.Xr ssl 3 ,
56.Xr SSL_check_private_key 3 ,
57.Xr SSL_use_certificate 3
58.Sh HISTORY
59.Fn SSL_get_certificate
60first appeared in SSLeay 0.5.2a.
61.Fn SSL_get_privatekey
62first appeared in SSLeay 0.8.0.
63Both functions have been available since
64.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_ciphers.3 b/src/lib/libssl/man/SSL_get_ciphers.3
deleted file mode 100644
index 8030f0bbb1..0000000000
--- a/src/lib/libssl/man/SSL_get_ciphers.3
+++ /dev/null
@@ -1,249 +0,0 @@
1.\" $OpenBSD: SSL_get_ciphers.3,v 1.11 2020/09/16 07:25:15 schwarze Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\" selective merge up to: OpenSSL 83cf7abf May 29 13:07:08 2018 +0100
4.\"
5.\" This file is a derived work.
6.\" The changes are covered by the following Copyright and license:
7.\"
8.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
9.\"
10.\" Permission to use, copy, modify, and distribute this software for any
11.\" purpose with or without fee is hereby granted, provided that the above
12.\" copyright notice and this permission notice appear in all copies.
13.\"
14.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21.\"
22.\" The original file was written by Lutz Jaenicke <jaenicke@openssl.org>,
23.\" Nick Mathewson <nickm@torproject.org>, Kurt Roeckx <kurt@roeckx.be>,
24.\" Kazuki Yamaguchi <k@rhe.jp>, and Benjamin Kaduk <bkaduk@akamai.com>.
25.\" Copyright (c) 2000, 2005, 2015, 2016, 2017 The OpenSSL Project.
26.\" All rights reserved.
27.\"
28.\" Redistribution and use in source and binary forms, with or without
29.\" modification, are permitted provided that the following conditions
30.\" are met:
31.\"
32.\" 1. Redistributions of source code must retain the above copyright
33.\" notice, this list of conditions and the following disclaimer.
34.\"
35.\" 2. Redistributions in binary form must reproduce the above copyright
36.\" notice, this list of conditions and the following disclaimer in
37.\" the documentation and/or other materials provided with the
38.\" distribution.
39.\"
40.\" 3. All advertising materials mentioning features or use of this
41.\" software must display the following acknowledgment:
42.\" "This product includes software developed by the OpenSSL Project
43.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
44.\"
45.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
46.\" endorse or promote products derived from this software without
47.\" prior written permission. For written permission, please contact
48.\" openssl-core@openssl.org.
49.\"
50.\" 5. Products derived from this software may not be called "OpenSSL"
51.\" nor may "OpenSSL" appear in their names without prior written
52.\" permission of the OpenSSL Project.
53.\"
54.\" 6. Redistributions of any form whatsoever must retain the following
55.\" acknowledgment:
56.\" "This product includes software developed by the OpenSSL Project
57.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
58.\"
59.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
60.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
62.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
63.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
64.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
65.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
66.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
68.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
69.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
70.\" OF THE POSSIBILITY OF SUCH DAMAGE.
71.\"
72.Dd $Mdocdate: September 16 2020 $
73.Dt SSL_GET_CIPHERS 3
74.Os
75.Sh NAME
76.Nm SSL_get_ciphers ,
77.Nm SSL_CTX_get_ciphers ,
78.Nm SSL_get1_supported_ciphers ,
79.Nm SSL_get_client_ciphers ,
80.Nm SSL_get_cipher_list
81.Nd get lists of available SSL_CIPHERs
82.Sh SYNOPSIS
83.In openssl/ssl.h
84.Ft STACK_OF(SSL_CIPHER) *
85.Fn SSL_get_ciphers "const SSL *ssl"
86.Ft STACK_OF(SSL_CIPHER) *
87.Fn SSL_CTX_get_ciphers "const SSL_CTX *ctx"
88.Ft STACK_OF(SSL_CIPHER) *
89.Fn SSL_get1_supported_ciphers "SSL *ssl"
90.Ft STACK_OF(SSL_CIPHER) *
91.Fn SSL_get_client_ciphers "const SSL *ssl"
92.Ft const char *
93.Fn SSL_get_cipher_list "const SSL *ssl" "int priority"
94.Sh DESCRIPTION
95.Fn SSL_get_ciphers
96returns the stack of available
97.Vt SSL_CIPHER Ns s
98for
99.Fa ssl ,
100sorted by preference.
101.Pp
102.Fn SSL_CTX_get_ciphers
103returns the stack of available
104.Vt SSL_CIPHER Ns s
105for
106.Fa ctx .
107.Pp
108.Fn SSL_get1_supported_ciphers
109returns a stack of enabled
110.Vt SSL_CIPHER Ns s
111for
112.Fa ssl
113as it would be sent in a ClientHello, sorted by preference.
114The list depends on settings like the cipher list, the supported
115protocol versions, the security level, and the enabled signature
116algorithms.
117The list of ciphers that would be sent in a ClientHello can differ
118from the list of ciphers that would be acceptable when acting as a
119server.
120For example,
121additional ciphers may be usable by a server if there is a gap in the
122list of supported protocols, and some ciphers may not be usable by a
123server if there is not a suitable certificate configured.
124.Pp
125.Fn SSL_get_client_ciphers
126returns the stack of available
127.Vt SSL_CIPHER Ns s
128matching the list received from the client on
129.Fa ssl .
130.Pp
131The details of the ciphers obtained by
132.Fn SSL_get_ciphers ,
133.Fn SSL_CTX_get_ciphers ,
134.Fn SSL_get1_supported_ciphers ,
135and
136.Fn SSL_get_client_ciphers
137can be obtained using the
138.Xr SSL_CIPHER_get_name 3
139family of functions.
140.Pp
141.Fn SSL_get_cipher_list
142is deprecated \(em use
143.Fn SSL_get_ciphers
144instead \(em and badly misnamed; it does not return a list
145but the name of one element of the return value of
146.Fn SSL_get_ciphers ,
147with the index given by the
148.Fa priority
149argument.
150Passing 0 selects the cipher with the highest priority.
151To iterate over all available ciphers in decreasing priority,
152repeatedly increment the argument by 1 until
153.Dv NULL
154is returned.
155.Sh RETURN VALUES
156.Fn SSL_get_ciphers
157returns an internal pointer to a list of ciphers or
158.Dv NULL
159if
160.Fa ssl
161is
162.Dv NULL
163or if no ciphers are available.
164The returned pointer may not only become invalid when
165.Fa ssl
166is destroyed or when
167.Xr SSL_set_cipher_list 3
168is called on it, but also when the
169.Vt SSL_CTX
170object in use by
171.Fa ssl
172at the time of the call is freed or when
173.Xr SSL_CTX_set_cipher_list 3
174is called on that context object.
175.Pp
176.Fn SSL_CTX_get_ciphers
177returns an internal pointer to a list of ciphers or
178.Dv NULL
179if
180.Fa ctx
181is
182.Dv NULL
183or if no ciphers are available.
184The returned pointer becomes invalid when
185.Fa ctx
186is destroyed or when
187.Xr SSL_CTX_set_cipher_list 3
188is called on it.
189.Pp
190.Fn SSL_get1_supported_ciphers
191returns a newly allocated list of ciphers or
192.Dv NULL
193if
194.Fa ssl
195is
196.Dv NULL ,
197if no ciphers are available, or if an error occurs.
198When the returned pointer is no longer needed, the caller is
199responsible for freeing it using
200.Fn sk_SSL_CIPHER_free .
201.Pp
202.Fn SSL_get_client_ciphers
203returns an internal pointer to a list of ciphers or
204.Dv NULL
205if
206.Fa ssl
207is
208.Dv NULL ,
209has no active session,
210or is not operating in server mode.
211The returned pointer becomes invalid when the
212.Vt SSL_SESSION
213object is destroyed, even if the
214.Fa ssl
215object remains valid.
216It may also become invalid in other circumstances,
217for example when processing a new ClientHello.
218.Pp
219.Fn SSL_get_cipher_list
220returns an internal pointer to a string or
221.Dv NULL
222if
223.Fa ssl
224is
225.Dv NULL ,
226if no ciphers are available, or if
227.Fa priority
228is greater than or equal to the number of available ciphers.
229.Sh SEE ALSO
230.Xr ssl 3 ,
231.Xr SSL_CIPHER_get_name 3 ,
232.Xr SSL_CTX_set_cipher_list 3
233.Sh HISTORY
234.Fn SSL_get_cipher_list
235first appeared in SSLeay 0.5.2.
236.Fn SSL_get_ciphers
237first appeared in SSLeay 0.8.0.
238Both functions have been available since
239.Ox 2.4 .
240.Pp
241.Fn SSL_CTX_get_ciphers
242first appeared in OpenSSL 1.1.0 and has been available since
243.Ox 6.3 .
244.Pp
245.Fn SSL_get1_supported_ciphers
246and
247.Fn SSL_get_client_ciphers
248first appeared in OpenSSL 1.1.0 and has been available since
249.Ox 6.5 .
diff --git a/src/lib/libssl/man/SSL_get_client_CA_list.3 b/src/lib/libssl/man/SSL_get_client_CA_list.3
deleted file mode 100644
index e80e5cb6f5..0000000000
--- a/src/lib/libssl/man/SSL_get_client_CA_list.3
+++ /dev/null
@@ -1,96 +0,0 @@
1.\" $OpenBSD: SSL_get_client_CA_list.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2002, 2005 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 27 2018 $
53.Dt SSL_GET_CLIENT_CA_LIST 3
54.Os
55.Sh NAME
56.Nm SSL_get_client_CA_list ,
57.Nm SSL_CTX_get_client_CA_list
58.Nd get list of client CAs
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft STACK_OF(X509_NAME) *
62.Fn SSL_get_client_CA_list "const SSL *s"
63.Ft STACK_OF(X509_NAME) *
64.Fn SSL_CTX_get_client_CA_list "const SSL_CTX *ctx"
65.Sh DESCRIPTION
66.Fn SSL_CTX_get_client_CA_list
67returns the list of client CAs explicitly set for
68.Fa ctx
69using
70.Xr SSL_CTX_set_client_CA_list 3 .
71.Pp
72.Fn SSL_get_client_CA_list
73returns the list of client CAs explicitly set for
74.Fa ssl
75using
76.Fn SSL_set_client_CA_list
77or
78.Fa ssl Ns 's
79.Vt SSL_CTX
80object with
81.Xr SSL_CTX_set_client_CA_list 3 ,
82when in server mode.
83In client mode,
84.Fn SSL_get_client_CA_list
85returns the list of client CAs sent from the server, if any.
86.Sh SEE ALSO
87.Xr ssl 3 ,
88.Xr SSL_CTX_set_client_CA_list 3 ,
89.Xr SSL_CTX_set_client_cert_cb 3 ,
90.Xr X509_NAME_new 3
91.Sh HISTORY
92.Fn SSL_get_client_CA_list
93and
94.Fn SSL_CTX_get_client_CA_list
95first appeared in SSLeay 0.8.0 and have been available since
96.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_client_random.3 b/src/lib/libssl/man/SSL_get_client_random.3
deleted file mode 100644
index eda74db355..0000000000
--- a/src/lib/libssl/man/SSL_get_client_random.3
+++ /dev/null
@@ -1,150 +0,0 @@
1.\" $OpenBSD: SSL_get_client_random.3,v 1.2 2018/03/24 00:55:37 schwarze Exp $
2.\" full merge up to: OpenSSL e9b77246 Jan 20 19:58:49 2017 +0100
3.\"
4.\" This file was written by Nick Mathewson <nickm@torproject.org>
5.\" Copyright (c) 2015 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 24 2018 $
52.Dt SSL_GET_CLIENT_RANDOM 3
53.Os
54.Sh NAME
55.Nm SSL_get_client_random ,
56.Nm SSL_get_server_random ,
57.Nm SSL_SESSION_get_master_key
58.Nd get internal TLS handshake random values and master key
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft size_t
62.Fo SSL_get_client_random
63.Fa "const SSL *ssl"
64.Fa "unsigned char *out"
65.Fa "size_t outlen"
66.Fc
67.Ft size_t
68.Fo SSL_get_server_random
69.Fa "const SSL *ssl"
70.Fa "unsigned char *out"
71.Fa "size_t outlen"
72.Fc
73.Ft size_t
74.Fo SSL_SESSION_get_master_key
75.Fa "const SSL_SESSION *session"
76.Fa "unsigned char *out"
77.Fa "size_t outlen"
78.Fc
79.Sh DESCRIPTION
80.Fn SSL_get_client_random
81extracts the random value that was sent from the client to the server
82during the initial TLS handshake.
83It copies at most
84.Fa outlen
85bytes of this value into the buffer
86.Fa out .
87If
88.Fa outlen
89is zero, nothing is copied.
90.Pp
91.Fn SSL_get_server_random
92behaves the same, but extracts the random value that was sent
93from the server to the client during the initial TLS handshake.
94.Pp
95.Fn SSL_SESSION_get_master_key
96behaves the same, but extracts the master secret used to guarantee the
97security of the TLS session.
98The security of the TLS session depends on keeping the master key
99secret: do not expose it, or any information about it, to anybody.
100To calculate another secret value that depends on the master secret,
101use
102.Xr SSL_export_keying_material 3
103instead.
104.Pp
105All these functions expose internal values from the TLS handshake,
106for use in low-level protocols.
107Avoid using them unless implementing a feature
108that requires access to the internal protocol details.
109.Pp
110Despite the names of
111.Fn SSL_get_client_random
112and
113.Fn SSL_get_server_random ,
114they are not random number generators.
115Instead, they return the mostly-random values that were already
116generated and used in the TLS protocol.
117.Pp
118In current versions of the TLS protocols,
119the length of client_random and server_random is always
120.Dv SSL3_RANDOM_SIZE
121bytes.
122Support for other
123.Fa outlen
124arguments is provided for the unlikely event that a future
125version or variant of TLS uses some other length.
126.Pp
127Finally, though the client_random and server_random values are called
128.Dq random ,
129many TLS implementations generate four bytes of those values
130based on their view of the current time.
131.Sh RETURN VALUES
132If
133.Fa outlen
134is greater than 0, these functions return the number of bytes
135actually copied, which is less than or equal to
136.Fa outlen .
137If
138.Fa outlen
139is 0, these functions return the maximum number of bytes they would
140copy \(em that is, the length of the underlying field.
141.Sh SEE ALSO
142.Xr ssl 3 ,
143.Xr SSL_export_keying_material 3 ,
144.Xr SSL_SESSION_get_id 3 ,
145.Xr SSL_SESSION_get_time 3 ,
146.Xr SSL_SESSION_new 3
147.Sh HISTORY
148These functions first appeared in OpenSSL 1.1.0
149and have been available since
150.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_get_current_cipher.3 b/src/lib/libssl/man/SSL_get_current_cipher.3
deleted file mode 100644
index 6b951d03ca..0000000000
--- a/src/lib/libssl/man/SSL_get_current_cipher.3
+++ /dev/null
@@ -1,122 +0,0 @@
1.\" $OpenBSD: SSL_get_current_cipher.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2005, 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_GET_CURRENT_CIPHER 3
53.Os
54.Sh NAME
55.Nm SSL_get_current_cipher ,
56.Nm SSL_get_cipher ,
57.Nm SSL_get_cipher_name ,
58.Nm SSL_get_cipher_bits ,
59.Nm SSL_get_cipher_version
60.Nd get SSL_CIPHER of a connection
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft const SSL_CIPHER *
64.Fn SSL_get_current_cipher "const SSL *ssl"
65.Ft const char *
66.Fn SSL_get_cipher "const SSL *ssl"
67.Ft const char *
68.Fn SSL_get_cipher_name "const SSL *ssl"
69.Ft int
70.Fn SSL_get_cipher_bits "const SSL *ssl" "int *np"
71.Ft char *
72.Fn SSL_get_cipher_version "const SSL *ssl"
73.Sh DESCRIPTION
74.Fn SSL_get_current_cipher
75returns a pointer to an
76.Vt SSL_CIPHER
77object containing the description of the actually used cipher of a connection
78established with the
79.Fa ssl
80object.
81See
82.Xr SSL_CIPHER_get_name 3
83for more details.
84.Pp
85.Fn SSL_get_cipher_name
86obtains the name of the currently used cipher.
87.Fn SSL_get_cipher
88is identical to
89.Fn SSL_get_cipher_name .
90.Pp
91.Fn SSL_get_cipher_bits
92obtains the number of secret/algorithm bits used and
93.Fn SSL_get_cipher_version
94returns the protocol name.
95.Pp
96.Fn SSL_get_cipher ,
97.Fn SSL_get_cipher_name ,
98.Fn SSL_get_cipher_bits ,
99and
100.Fn SSL_get_cipher_version
101are implemented as macros.
102.Sh RETURN VALUES
103.Fn SSL_get_current_cipher
104returns the cipher actually used, or
105.Dv NULL
106if no session has been established.
107.Sh SEE ALSO
108.Xr ssl 3 ,
109.Xr SSL_CIPHER_get_name 3
110.Sh HISTORY
111.Fn SSL_get_cipher
112appeared in SSLeay 0.4 or earlier.
113.Fn SSL_get_cipher_bits
114first appeared in SSLeay 0.6.4.
115.Fn SSL_get_cipher_name
116and
117.Fn SSL_get_cipher_version
118first appeared in SSLeay 0.8.0.
119.Fn SSL_get_current_cipher
120first appeared in SSLeay 0.8.1.
121These functions have been available since
122.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_default_timeout.3 b/src/lib/libssl/man/SSL_get_default_timeout.3
deleted file mode 100644
index 47737d8ee0..0000000000
--- a/src/lib/libssl/man/SSL_get_default_timeout.3
+++ /dev/null
@@ -1,85 +0,0 @@
1.\" $OpenBSD: SSL_get_default_timeout.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_GET_DEFAULT_TIMEOUT 3
53.Os
54.Sh NAME
55.Nm SSL_get_default_timeout
56.Nd get default session timeout value
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft long
60.Fn SSL_get_default_timeout "const SSL *ssl"
61.Sh DESCRIPTION
62.Fn SSL_get_default_timeout
63returns the default timeout value assigned to
64.Vt SSL_SESSION
65objects negotiated for the protocol valid for
66.Fa ssl .
67.Pp
68Whenever a new session is negotiated, it is assigned a timeout value,
69after which it will not be accepted for session reuse.
70If the timeout value was not explicitly set using
71.Xr SSL_CTX_set_timeout 3 ,
72the hardcoded default timeout for the protocol will be used.
73.Pp
74.Fn SSL_get_default_timeout
75return this hardcoded value, which is 300 seconds for all currently supported
76protocols (SSLv2, SSLv3, and TLSv1).
77.Sh SEE ALSO
78.Xr ssl 3 ,
79.Xr SSL_CTX_flush_sessions 3 ,
80.Xr SSL_CTX_set_session_cache_mode 3 ,
81.Xr SSL_SESSION_get_time 3
82.Sh HISTORY
83.Fn SSL_get_default_timeout
84first appeared in SSLeay 0.8.0 and has been available since
85.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_error.3 b/src/lib/libssl/man/SSL_get_error.3
deleted file mode 100644
index 5d325b3f56..0000000000
--- a/src/lib/libssl/man/SSL_get_error.3
+++ /dev/null
@@ -1,217 +0,0 @@
1.\" $OpenBSD: SSL_get_error.3,v 1.5 2018/04/29 07:37:01 guenther Exp $
2.\" OpenSSL a528d4f0 Oct 27 13:40:11 2015 -0400
3.\"
4.\" This file was written by Bodo Moeller <bodo@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2002, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: April 29 2018 $
52.Dt SSL_GET_ERROR 3
53.Os
54.Sh NAME
55.Nm SSL_get_error
56.Nd obtain result code for TLS/SSL I/O operation
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fn SSL_get_error "const SSL *ssl" "int ret"
61.Sh DESCRIPTION
62.Fn SSL_get_error
63returns a result code (suitable for the C
64.Dq switch
65statement) for a preceding call to
66.Xr SSL_connect 3 ,
67.Xr SSL_accept 3 ,
68.Xr SSL_do_handshake 3 ,
69.Xr SSL_read 3 ,
70.Xr SSL_peek 3 ,
71or
72.Xr SSL_write 3
73on
74.Fa ssl .
75The value returned by that TLS/SSL I/O function must be passed to
76.Fn SSL_get_error
77in parameter
78.Fa ret .
79.Pp
80In addition to
81.Fa ssl
82and
83.Fa ret ,
84.Fn SSL_get_error
85inspects the current thread's OpenSSL error queue.
86Thus,
87.Fn SSL_get_error
88must be used in the same thread that performed the TLS/SSL I/O operation,
89and no other OpenSSL function calls should appear in between.
90The current thread's error queue must be empty before the TLS/SSL I/O operation
91is attempted, or
92.Fn SSL_get_error
93will not work reliably.
94.Sh RETURN VALUES
95The following return values can currently occur:
96.Bl -tag -width Ds
97.It Dv SSL_ERROR_NONE
98The TLS/SSL I/O operation completed.
99This result code is returned if and only if
100.Fa ret
101> 0.
102.It Dv SSL_ERROR_ZERO_RETURN
103The TLS/SSL connection has been closed.
104If the protocol version is SSL 3.0 or TLS 1.0, this result code is returned
105only if a closure alert has occurred in the protocol, i.e., if the connection
106has been closed cleanly.
107Note that in this case
108.Dv SSL_ERROR_ZERO_RETURN
109does not necessarily indicate that the underlying transport has been closed.
110.It Dv SSL_ERROR_WANT_READ , Dv SSL_ERROR_WANT_WRITE
111The operation did not complete;
112the same TLS/SSL I/O function should be called again later.
113If, by then, the underlying
114.Vt BIO
115has data available for reading (if the result code is
116.Dv SSL_ERROR_WANT_READ )
117or allows writing data
118.Pq Dv SSL_ERROR_WANT_WRITE ,
119then some TLS/SSL protocol progress will take place,
120i.e., at least part of a TLS/SSL record will be read or written.
121Note that the retry may again lead to a
122.Dv SSL_ERROR_WANT_READ
123or
124.Dv SSL_ERROR_WANT_WRITE
125condition.
126There is no fixed upper limit for the number of iterations that may be
127necessary until progress becomes visible at application protocol level.
128.Pp
129For socket
130.Fa BIO Ns
131s (e.g., when
132.Fn SSL_set_fd
133was used),
134.Xr select 2
135or
136.Xr poll 2
137on the underlying socket can be used to find out when the TLS/SSL I/O function
138should be retried.
139.Pp
140Caveat: Any TLS/SSL I/O function can lead to either of
141.Dv SSL_ERROR_WANT_READ
142and
143.Dv SSL_ERROR_WANT_WRITE .
144In particular,
145.Xr SSL_read 3
146or
147.Xr SSL_peek 3
148may want to write data and
149.Xr SSL_write 3
150may want
151to read data.
152This is mainly because TLS/SSL handshakes may occur at any time during the
153protocol (initiated by either the client or the server);
154.Xr SSL_read 3 ,
155.Xr SSL_peek 3 ,
156and
157.Xr SSL_write 3
158will handle any pending handshakes.
159.It Dv SSL_ERROR_WANT_CONNECT , Dv SSL_ERROR_WANT_ACCEPT
160The operation did not complete; the same TLS/SSL I/O function should be
161called again later.
162The underlying BIO was not connected yet to the peer and the call would block
163in
164.Xr connect 2 Ns / Ns
165.Xr accept 2 .
166The SSL function should be
167called again when the connection is established.
168These messages can only appear with a
169.Xr BIO_s_connect 3
170or
171.Xr BIO_s_accept 3
172.Vt BIO ,
173respectively.
174In order to find out when the connection has been successfully established,
175on many platforms
176.Xr select 2
177or
178.Xr poll 2
179for writing on the socket file descriptor can be used.
180.It Dv SSL_ERROR_WANT_X509_LOOKUP
181The operation did not complete because an application callback set by
182.Xr SSL_CTX_set_client_cert_cb 3
183has asked to be called again.
184The TLS/SSL I/O function should be called again later.
185Details depend on the application.
186.It Dv SSL_ERROR_SYSCALL
187Some I/O error occurred.
188The OpenSSL error queue may contain more information on the error.
189If the error queue is empty (i.e.,
190.Fn ERR_get_error
191returns 0),
192.Fa ret
193can be used to find out more about the error:
194If
195.Fa ret
196== 0, an
197.Dv EOF
198was observed that violates the protocol.
199If
200.Fa ret
201== \(mi1, the underlying
202.Vt BIO
203reported an
204I/O error (for socket I/O on Unix systems, consult
205.Dv errno
206for details).
207.It Dv SSL_ERROR_SSL
208A failure in the SSL library occurred, usually a protocol error.
209The OpenSSL error queue contains more information on the error.
210.El
211.Sh SEE ALSO
212.Xr err 3 ,
213.Xr ssl 3
214.Sh HISTORY
215.Fn SSL_get_error
216first appeared in SSLeay 0.8.0 and have been available since
217.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_ex_data_X509_STORE_CTX_idx.3 b/src/lib/libssl/man/SSL_get_ex_data_X509_STORE_CTX_idx.3
deleted file mode 100644
index a249cda6ac..0000000000
--- a/src/lib/libssl/man/SSL_get_ex_data_X509_STORE_CTX_idx.3
+++ /dev/null
@@ -1,116 +0,0 @@
1.\" $OpenBSD: SSL_get_ex_data_X509_STORE_CTX_idx.3,v 1.5 2022/02/06 00:29:02 jsg Exp $
2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: February 6 2022 $
52.Dt SSL_GET_EX_DATA_X509_STORE_CTX_IDX 3
53.Os
54.Sh NAME
55.Nm SSL_get_ex_data_X509_STORE_CTX_idx
56.Nd get ex_data index to access SSL structure from X509_STORE_CTX
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fn SSL_get_ex_data_X509_STORE_CTX_idx void
61.Sh DESCRIPTION
62.Fn SSL_get_ex_data_X509_STORE_CTX_idx
63returns the index number under which the pointer to the
64.Vt SSL
65object is stored into the
66.Vt X509_STORE_CTX
67object.
68.Pp
69Whenever a
70.Vt X509_STORE_CTX
71object is created for the verification of the peer's certificate during a
72handshake, a pointer to the
73.Vt SSL
74object is stored into the
75.Vt X509_STORE_CTX
76object to identify the connection affected.
77To retrieve this pointer the
78.Xr X509_STORE_CTX_get_ex_data 3
79function can be used with the correct index.
80This index is globally the same for all
81.Vt X509_STORE_CTX
82objects and can be retrieved using
83.Fn SSL_get_ex_data_X509_STORE_CTX_idx .
84The index value is set when
85.Fn SSL_get_ex_data_X509_STORE_CTX_idx
86is first called either by the application program directly or indirectly during
87other SSL setup functions or during the handshake.
88.Pp
89The value depends on other index values defined for
90.Vt X509_STORE_CTX
91objects before the SSL index is created.
92.Sh RETURN VALUES
93.Bl -tag -width Ds
94.It \(>=0
95The index value to access the pointer.
96.It <0
97An error occurred, check the error stack for a detailed error message.
98.El
99.Sh EXAMPLES
100The index returned from
101.Fn SSL_get_ex_data_X509_STORE_CTX_idx
102provides access to
103.Vt SSL
104object for the connection during the
105.Fn verify_callback
106when checking the peer's certificate.
107Check the example in
108.Xr SSL_CTX_set_verify 3 .
109.Sh SEE ALSO
110.Xr CRYPTO_set_ex_data 3 ,
111.Xr ssl 3 ,
112.Xr SSL_CTX_set_verify 3
113.Sh HISTORY
114.Fn SSL_get_ex_data_X509_STORE_CTX_idx
115first appeared in SSLeay 0.9.1 and has been available since
116.Ox 2.6 .
diff --git a/src/lib/libssl/man/SSL_get_ex_new_index.3 b/src/lib/libssl/man/SSL_get_ex_new_index.3
deleted file mode 100644
index cecd25fa44..0000000000
--- a/src/lib/libssl/man/SSL_get_ex_new_index.3
+++ /dev/null
@@ -1,136 +0,0 @@
1.\" $OpenBSD: SSL_get_ex_new_index.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_GET_EX_NEW_INDEX 3
53.Os
54.Sh NAME
55.Nm SSL_get_ex_new_index ,
56.Nm SSL_set_ex_data ,
57.Nm SSL_get_ex_data
58.Nd internal application specific data functions
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fo SSL_get_ex_new_index
63.Fa "long argl"
64.Fa "void *argp"
65.Fa "CRYPTO_EX_new *new_func"
66.Fa "CRYPTO_EX_dup *dup_func"
67.Fa "CRYPTO_EX_free *free_func"
68.Fc
69.Ft int
70.Fn SSL_set_ex_data "SSL *ssl" "int idx" "void *arg"
71.Ft void *
72.Fn SSL_get_ex_data "const SSL *ssl" "int idx"
73.Bd -literal
74typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
75 int idx, long argl, void *argp);
76typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
77 int idx, long argl, void *argp);
78typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
79 int idx, long argl, void *argp);
80.Ed
81.Sh DESCRIPTION
82Several OpenSSL structures can have application specific data attached to them.
83These functions are used internally by OpenSSL to manipulate application
84specific data attached to a specific structure.
85.Pp
86.Fn SSL_get_ex_new_index
87is used to register a new index for application specific data.
88.Pp
89.Fn SSL_set_ex_data
90is used to store application data at
91.Fa arg
92for
93.Fa idx
94into the
95.Fa ssl
96object.
97.Pp
98.Fn SSL_get_ex_data
99is used to retrieve the information for
100.Fa idx
101from
102.Fa ssl .
103.Pp
104A detailed description for the
105.Fn *_get_ex_new_index
106functionality can be found in
107.Xr RSA_get_ex_new_index 3 .
108The
109.Fn *_get_ex_data
110and
111.Fn *_set_ex_data
112functionality is described in
113.Xr CRYPTO_set_ex_data 3 .
114.Sh EXAMPLES
115An example of how to use the functionality is included in the example
116.Fn verify_callback
117in
118.Xr SSL_CTX_set_verify 3 .
119.Sh SEE ALSO
120.Xr CRYPTO_set_ex_data 3 ,
121.Xr RSA_get_ex_new_index 3 ,
122.Xr ssl 3 ,
123.Xr SSL_CTX_set_verify 3
124.Sh HISTORY
125Precursor functions
126.Fn SSL_set_app_data
127and
128.Fn SSL_get_app_data
129first appeared in SSLeay 0.6.1.
130.Pp
131.Fn SSL_get_ex_new_index ,
132.Fn SSL_set_ex_data ,
133and
134.Fn SSL_get_ex_data
135first appeared in SSLeay 0.9.0 and have been available since
136.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_fd.3 b/src/lib/libssl/man/SSL_get_fd.3
deleted file mode 100644
index 1e093424cb..0000000000
--- a/src/lib/libssl/man/SSL_get_fd.3
+++ /dev/null
@@ -1,103 +0,0 @@
1.\" $OpenBSD: SSL_get_fd.3,v 1.6 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2005, 2013 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_GET_FD 3
53.Os
54.Sh NAME
55.Nm SSL_get_fd ,
56.Nm SSL_get_rfd ,
57.Nm SSL_get_wfd
58.Nd get file descriptor linked to an SSL object
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fn SSL_get_fd "const SSL *ssl"
63.Ft int
64.Fn SSL_get_rfd "const SSL *ssl"
65.Ft int
66.Fn SSL_get_wfd "const SSL *ssl"
67.Sh DESCRIPTION
68.Fn SSL_get_fd
69returns the file descriptor which is linked to
70.Fa ssl .
71.Fn SSL_get_rfd
72and
73.Fn SSL_get_wfd
74return the file descriptors for the read or the write channel,
75which can be different.
76If the read and the write channel are different,
77.Fn SSL_get_fd
78will return the file descriptor of the read channel.
79.Sh RETURN VALUES
80The following return values can occur:
81.Bl -tag -width Ds
82.It \(mi1
83The operation failed, because the underlying
84.Vt BIO
85is not of the correct type (suitable for file descriptors).
86.It \(>=0
87The file descriptor linked to
88.Fa ssl .
89.El
90.Sh SEE ALSO
91.Xr BIO_new 3 ,
92.Xr ssl 3 ,
93.Xr SSL_set_fd 3
94.Sh HISTORY
95.Fn SSL_get_fd
96appeared in SSLeay 0.4 or earlier and has been available since
97.Ox 2.4 .
98.Pp
99.Fn SSL_get_rfd
100and
101.Fn SSL_get_wfd
102first appeared in OpenSSL 0.9.6c and have been available since
103.Ox 3.2 .
diff --git a/src/lib/libssl/man/SSL_get_finished.3 b/src/lib/libssl/man/SSL_get_finished.3
deleted file mode 100644
index 3cfb655ea0..0000000000
--- a/src/lib/libssl/man/SSL_get_finished.3
+++ /dev/null
@@ -1,77 +0,0 @@
1.\" $OpenBSD: SSL_get_finished.3,v 1.2 2021/01/30 10:48:15 tb Exp $
2.\"
3.\" Copyright (c) 2020 Theo Buehler <tb@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: January 30 2021 $
18.Dt SSL_GET_FINISHED 3
19.Os
20.Sh NAME
21.Nm SSL_get_finished ,
22.Nm SSL_get_peer_finished
23.Nd get last sent or last expected finished message
24.Sh SYNOPSIS
25.In openssl/ssl.h
26.Ft size_t
27.Fn SSL_get_finished "const SSL *ssl" "void *buf" "size_t count"
28.Ft size_t
29.Fn SSL_get_peer_finished "const SSL *ssl" "void *buf" "size_t count"
30.Sh DESCRIPTION
31.Fn SSL_get_finished
32and
33.Fn SSL_get_peer_finished
34copy
35.Fa count
36bytes from the last finished message sent to the peer
37or expected from the peer into the
38caller-provided buffer
39.Fa buf .
40.Pp
41The finished message is computed from a checksum of the handshake records
42exchanged with the peer.
43Its length depends on the ciphersuite in use and is at most
44.Dv EVP_MAX_MD_SIZE ,
45i.e., 64 bytes.
46.\" In TLSv1.3 the length is equal to the length of the hash algorithm
47.\" used by the hash-based message authentication code (HMAC),
48.\" which is currently either 32 bytes for SHA-256 or 48 bytes for SHA-384.
49.\" In TLSv1.2 the length defaults to 12 bytes, but it can explicitly be
50.\" specified by the ciphersuite to be longer.
51.\" In TLS versions 1.1 and 1.0, the finished message has a fixed length
52.\" of 12 bytes.
53.Sh RETURN VALUES
54.Fn SSL_get_finished
55and
56.Fn SSL_get_peer_finished
57return the number of bytes copied into
58.Fa buf .
59The return value is zero if the handshake has not reached the
60finished message.
61.Sh SEE ALSO
62.Xr ssl 3 ,
63.Xr SSL_get_session 3 ,
64.Xr SSL_set_session 3
65.Sh STANDARDS
66RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3,
67section 4.4.4: Finished.
68.Pp
69RFC 5246: The Transport Layer Security (TLS) Protocol Version 1.2,
70section 7.4.9: Finished.
71.Sh HISTORY
72.Fn SSL_get_finished
73and
74.Fn SSL_get_peer_finished
75first appeared in SSLeay 0.9.5
76and have been available since
77.Ox 2.7 .
diff --git a/src/lib/libssl/man/SSL_get_peer_cert_chain.3 b/src/lib/libssl/man/SSL_get_peer_cert_chain.3
deleted file mode 100644
index eb2ae53dc4..0000000000
--- a/src/lib/libssl/man/SSL_get_peer_cert_chain.3
+++ /dev/null
@@ -1,107 +0,0 @@
1.\" $OpenBSD: SSL_get_peer_cert_chain.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL SSL_get_peer_cert_chain.pod 1f164c6f Jan 18 01:40:36 2017 +0100
3.\" OpenSSL SSL_get_peer_cert_chain.pod 9b86974e Aug 17 15:21:33 2015 -0400
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
6.\" Copyright (c) 2000, 2005, 2014, 2016 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: March 27 2018 $
54.Dt SSL_GET_PEER_CERT_CHAIN 3
55.Os
56.Sh NAME
57.Nm SSL_get_peer_cert_chain
58.Nd get the X509 certificate chain sent by the peer
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft STACK_OF(X509) *
62.Fn SSL_get_peer_cert_chain "const SSL *ssl"
63.Sh DESCRIPTION
64.Fn SSL_get_peer_cert_chain
65returns a pointer to
66.Dv STACK_OF Ns Po Vt X509 Pc
67certificates forming the certificate chain of the peer.
68If called on the client side, the stack also contains the peer's certificate;
69if called on the server side, the peer's certificate must be obtained
70separately using
71.Xr SSL_get_peer_certificate 3 .
72If the peer did not present a certificate,
73.Dv NULL
74is returned.
75.Pp
76.Fn SSL_get_peer_cert_chain
77returns the peer chain as sent by the peer: it only consists of
78certificates the peer has sent (in the order the peer has sent them)
79and it is not a verified chain.
80.Pp
81If the session is resumed, peers do not send certificates, so a
82.Dv NULL
83pointer is returned.
84Applications can call
85.Fn SSL_session_reused
86to determine whether a session is resumed.
87.Pp
88The reference count of the
89.Dv STACK_OF Ns Po Vt X509 Pc
90object is not incremented.
91If the corresponding session is freed, the pointer must not be used any longer.
92.Sh RETURN VALUES
93The following return values can occur:
94.Bl -tag -width Ds
95.It Dv NULL
96No certificate was presented by the peer or no connection was established or
97the certificate chain is no longer available when a session is reused.
98.It Pointer to a Dv STACK_OF Ns Po X509 Pc
99The return value points to the certificate chain presented by the peer.
100.El
101.Sh SEE ALSO
102.Xr ssl 3 ,
103.Xr SSL_get_peer_certificate 3
104.Sh HISTORY
105.Fn SSL_get_peer_cert_chain
106first appeared in SSLeay 0.8.0 and has been available since
107.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_peer_certificate.3 b/src/lib/libssl/man/SSL_get_peer_certificate.3
deleted file mode 100644
index 99f9330288..0000000000
--- a/src/lib/libssl/man/SSL_get_peer_certificate.3
+++ /dev/null
@@ -1,105 +0,0 @@
1.\" $OpenBSD: SSL_get_peer_certificate.3,v 1.6 2021/06/26 17:36:28 tb Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 26 2021 $
52.Dt SSL_GET_PEER_CERTIFICATE 3
53.Os
54.Sh NAME
55.Nm SSL_get_peer_certificate
56.Nd get the X509 certificate of the peer
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft X509 *
60.Fn SSL_get_peer_certificate "const SSL *ssl"
61.Sh DESCRIPTION
62.Fn SSL_get_peer_certificate
63returns a pointer to the X509 certificate the peer presented.
64If the peer did not present a certificate,
65.Dv NULL
66is returned.
67.Pp
68Due to the protocol definition, a TLS/SSL server will always send a
69certificate, if present.
70A client will only send a certificate when explicitly requested to do so by the
71server (see
72.Xr SSL_CTX_set_verify 3 ) .
73If an anonymous cipher is used, no certificates are sent.
74.Pp
75That a certificate is returned does not indicate information about the
76verification state.
77Use
78.Xr SSL_get_verify_result 3
79to check the verification state.
80.Pp
81The reference count of the
82.Vt X509
83object is incremented by one, so that it will not be destroyed when the session
84containing the peer certificate is freed.
85The
86.Vt X509
87object must be explicitly freed using
88.Xr X509_free 3 .
89.Sh RETURN VALUES
90The following return values can occur:
91.Bl -tag -width Ds
92.It Dv NULL
93No certificate was presented by the peer or no connection was established.
94.It Pointer to an X509 certificate
95The return value points to the certificate presented by the peer.
96.El
97.Sh SEE ALSO
98.Xr ssl 3 ,
99.Xr SSL_CTX_set_verify 3 ,
100.Xr SSL_get0_peername 3 ,
101.Xr SSL_get_verify_result 3
102.Sh HISTORY
103.Fn SSL_get_peer_certificate
104appeared in SSLeay 0.4 or earlier and has been available since
105.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_rbio.3 b/src/lib/libssl/man/SSL_get_rbio.3
deleted file mode 100644
index 38096fbecf..0000000000
--- a/src/lib/libssl/man/SSL_get_rbio.3
+++ /dev/null
@@ -1,98 +0,0 @@
1.\" $OpenBSD: SSL_get_rbio.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2013 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_GET_RBIO 3
53.Os
54.Sh NAME
55.Nm SSL_get_rbio ,
56.Nm SSL_get_wbio
57.Nd get BIO linked to an SSL object
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft BIO *
61.Fn SSL_get_rbio "SSL *ssl"
62.Ft BIO *
63.Fn SSL_get_wbio "SSL *ssl"
64.Sh DESCRIPTION
65.Fn SSL_get_rbio
66and
67.Fn SSL_get_wbio
68return pointers to the
69.Vt BIO Ns s
70for the read or the write channel, which can be different.
71The reference count of the
72.Vt BIO
73is not incremented.
74.Sh RETURN VALUES
75The following return values can occur:
76.Bl -tag -width Ds
77.It Dv NULL
78No
79.Vt BIO
80was connected to the
81.Vt SSL
82object.
83.It Any other pointer
84The
85.Vt BIO
86linked to
87.Fa ssl .
88.El
89.Sh SEE ALSO
90.Xr BIO_new 3 ,
91.Xr ssl 3 ,
92.Xr SSL_set_bio 3
93.Sh HISTORY
94.Fn SSL_get_rbio
95and
96.Fn SSL_get_wbio
97first appeared in SSLeay 0.6.0 and have been available since
98.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_server_tmp_key.3 b/src/lib/libssl/man/SSL_get_server_tmp_key.3
deleted file mode 100644
index aeeb358240..0000000000
--- a/src/lib/libssl/man/SSL_get_server_tmp_key.3
+++ /dev/null
@@ -1,89 +0,0 @@
1.\" $OpenBSD: SSL_get_server_tmp_key.3,v 1.4 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL SSL_get_server_tmp_key.pod 508fafd8 Apr 3 15:41:21 2017 +0100
3.\"
4.\" This file was written by Matt Caswell <matt@openssl.org>
5.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 12 2019 $
52.Dt SSL_GET_SERVER_TMP_KEY 3
53.Os
54.Sh NAME
55.Nm SSL_get_server_tmp_key
56.Nd temporary server key during a handshake
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft long
60.Fo SSL_get_server_tmp_key
61.Fa "SSL *ssl"
62.Fa "EVP_PKEY **key"
63.Fc
64.Sh DESCRIPTION
65.Fn SSL_get_server_tmp_key
66retrieves the temporary key provided by the server
67and used during key exchange.
68For example, if ECDHE is in use,
69this represents the server's public ECDHE key.
70.Pp
71In case of success, a copy of the key is stored in
72.Pf * Fa key .
73It is the caller's responsibility to free this key after use using
74.Xr EVP_PKEY_free 3 .
75.Pp
76This function may only be called by the client.
77.Pp
78This function is implemented as a macro.
79.Sh RETURN VALUES
80.Fn SSL_get_server_tmp_key
81returns 1 on success or 0 on failure.
82.Sh SEE ALSO
83.Xr EVP_PKEY_free 3 ,
84.Xr ssl 3 ,
85.Xr SSL_ctrl 3
86.Sh HISTORY
87.Fn SSL_get_server_tmp_key
88first appeared in OpenSSL 1.0.2 and has been available since
89.Ox 6.1 .
diff --git a/src/lib/libssl/man/SSL_get_session.3 b/src/lib/libssl/man/SSL_get_session.3
deleted file mode 100644
index 2ab43fdd3e..0000000000
--- a/src/lib/libssl/man/SSL_get_session.3
+++ /dev/null
@@ -1,163 +0,0 @@
1.\" $OpenBSD: SSL_get_session.3,v 1.8 2022/03/31 17:27:18 naddy Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2005, 2013, 2016 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 31 2022 $
53.Dt SSL_GET_SESSION 3
54.Os
55.Sh NAME
56.Nm SSL_get_session ,
57.Nm SSL_get0_session ,
58.Nm SSL_get1_session
59.Nd retrieve TLS/SSL session data
60.Sh SYNOPSIS
61.In openssl/ssl.h
62.Ft SSL_SESSION *
63.Fn SSL_get_session "const SSL *ssl"
64.Ft SSL_SESSION *
65.Fn SSL_get0_session "const SSL *ssl"
66.Ft SSL_SESSION *
67.Fn SSL_get1_session "SSL *ssl"
68.Sh DESCRIPTION
69.Fn SSL_get_session
70returns a pointer to the
71.Vt SSL_SESSION
72actually used in
73.Fa ssl .
74The reference count of the
75.Vt SSL_SESSION
76is not incremented, so that the pointer can become invalid by other operations.
77.Pp
78.Fn SSL_get0_session
79is the same as
80.Fn SSL_get_session .
81.Pp
82.Fn SSL_get1_session
83is the same as
84.Fn SSL_get_session ,
85but the reference count of the
86.Vt SSL_SESSION
87is incremented by one.
88.Pp
89The
90.Fa ssl
91session contains all information required to re-establish the connection
92without a new handshake.
93.Pp
94.Fn SSL_get0_session
95returns a pointer to the actual session.
96As the reference counter is not incremented,
97the pointer is only valid while the connection is in use.
98If
99.Xr SSL_clear 3
100or
101.Xr SSL_free 3
102is called, the session may be removed completely (if considered bad),
103and the pointer obtained will become invalid.
104Even if the session is valid,
105it can be removed at any time due to timeout during
106.Xr SSL_CTX_flush_sessions 3 .
107.Pp
108If the data is to be kept,
109.Fn SSL_get1_session
110will increment the reference count, so that the session will not be implicitly
111removed by other operations but stays in memory.
112In order to remove the session,
113.Xr SSL_SESSION_free 3
114must be explicitly called once to decrement the reference count again.
115.Pp
116.Vt SSL_SESSION
117objects keep internal link information about the session cache list when being
118inserted into one
119.Vt SSL_CTX
120object's session cache.
121One
122.Vt SSL_SESSION
123object, regardless of its reference count, must therefore only be used with one
124.Vt SSL_CTX
125object (and the
126.Vt SSL
127objects created from this
128.Vt SSL_CTX
129object).
130.Sh RETURN VALUES
131The following return values can occur:
132.Bl -tag -width Ds
133.It Dv NULL
134There is no session available in
135.Fa ssl .
136.It Pointer to an Vt SSL_SESSION
137The return value points to the data of an
138.Vt SSL
139session.
140.El
141.Sh SEE ALSO
142.Xr ssl 3 ,
143.Xr SSL_clear 3 ,
144.Xr SSL_free 3 ,
145.Xr SSL_SESSION_free 3 ,
146.Xr SSL_SESSION_get0_peer 3 ,
147.Xr SSL_SESSION_get_compress_id 3 ,
148.Xr SSL_SESSION_get_id 3 ,
149.Xr SSL_SESSION_get_protocol_version 3 ,
150.Xr SSL_SESSION_get_time 3 ,
151.Xr SSL_SESSION_new 3 ,
152.Xr SSL_SESSION_print 3 ,
153.Xr SSL_set_session 3
154.Sh HISTORY
155.Fn SSL_get_session
156first appeared in SSLeay 0.5.2 and has been available since
157.Ox 2.4 .
158.Pp
159.Fn SSL_get0_session
160and
161.Fn SSL_get1_session
162first appeared in OpenSSL 0.9.5 and have been available since
163.Ox 2.7 .
diff --git a/src/lib/libssl/man/SSL_get_shared_ciphers.3 b/src/lib/libssl/man/SSL_get_shared_ciphers.3
deleted file mode 100644
index 207e8c42eb..0000000000
--- a/src/lib/libssl/man/SSL_get_shared_ciphers.3
+++ /dev/null
@@ -1,103 +0,0 @@
1.\" $OpenBSD: SSL_get_shared_ciphers.3,v 1.5 2021/01/09 10:50:02 tb Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: January 9 2021 $
18.Dt SSL_GET_SHARED_CIPHERS 3
19.Os
20.Sh NAME
21.Nm SSL_get_shared_ciphers
22.Nd ciphers supported by both client and server
23.Sh SYNOPSIS
24.In openssl/ssl.h
25.Ft char *
26.Fo SSL_get_shared_ciphers
27.Fa "const SSL *ssl"
28.Fa "char *buf"
29.Fa "int len"
30.Fc
31.Sh DESCRIPTION
32If
33.Fa ssl
34contains a session in server mode,
35.Fn SSL_get_shared_ciphers
36puts as many names of ciphers that are supported by both the client
37and the server into the buffer
38.Fa buf
39as the buffer is long enough to contain.
40Names are separated by colons.
41At most
42.Fa len
43bytes are written to
44.Fa buf
45including the terminating NUL character.
46.Sh RETURN VALUES
47.Fn SSL_get_shared_ciphers
48returns
49.Fa buf
50on success or
51.Dv NULL
52on failure.
53The following situations cause failure:
54.Bl -bullet
55.It
56.Xr SSL_is_server 3
57is false, i.e.,
58.Ar ssl
59is not set to server mode.
60.It
61.Xr SSL_get_ciphers 3
62is
63.Dv NULL
64or empty, i.e., no ciphers are available for use by the server.
65.It
66.Xr SSL_get_session 3
67is
68.Dv NULL ,
69i.e.,
70.Ar ssl
71contains no session.
72.It
73.Xr SSL_get_client_ciphers 3
74is
75.Dv NULL
76or empty, i.e.,
77.Ar ssl
78contains no information about ciphers supported by the client,
79or the client does not support any ciphers.
80.It
81The
82.Fa len
83argument is less than 2.
84.El
85.Sh SEE ALSO
86.Xr ssl 3 ,
87.Xr SSL_get_ciphers 3
88.Sh HISTORY
89.Fn SSL_get_shared_ciphers
90first appeared in SSLeay 0.4.5b and has been available since
91.Ox 2.4 .
92.Sh BUGS
93If the list is too long to fit into
94.Fa len
95bytes, it is silently truncated after the last cipher name that fits,
96and all following ciphers are skipped.
97If the buffer is very short such that even the first cipher name
98does not fit, an empty string is returned even when some shared
99ciphers are actually available.
100.Pp
101There is no easy way to find out how much space is required for
102.Fa buf
103or whether the supplied space was sufficient.
diff --git a/src/lib/libssl/man/SSL_get_state.3 b/src/lib/libssl/man/SSL_get_state.3
deleted file mode 100644
index 297bbce876..0000000000
--- a/src/lib/libssl/man/SSL_get_state.3
+++ /dev/null
@@ -1,161 +0,0 @@
1.\" $OpenBSD: SSL_get_state.3,v 1.5 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_GET_STATE 3
19.Os
20.Sh NAME
21.Nm SSL_get_state ,
22.Nm SSL_state ,
23.Nm SSL_in_accept_init ,
24.Nm SSL_in_before ,
25.Nm SSL_in_connect_init ,
26.Nm SSL_in_init ,
27.Nm SSL_is_init_finished
28.Nd inspect the state of the SSL state machine
29.Sh SYNOPSIS
30.In openssl/ssl.h
31.Ft int
32.Fo SSL_get_state
33.Fa "const SSL *ssl"
34.Fc
35.Ft int
36.Fo SSL_state
37.Fa "const SSL *ssl"
38.Fc
39.Ft int
40.Fo SSL_in_accept_init
41.Fa "const SSL *ssl"
42.Fc
43.Ft int
44.Fo SSL_in_before
45.Fa "const SSL *ssl"
46.Fc
47.Ft int
48.Fo SSL_in_connect_init
49.Fa "const SSL *ssl"
50.Fc
51.Ft int
52.Fo SSL_in_init
53.Fa "const SSL *ssl"
54.Fc
55.Ft int
56.Fo SSL_is_init_finished
57.Fa "const SSL *ssl"
58.Fc
59.Sh DESCRIPTION
60.Fn SSL_get_state
61returns an encoded representation of the current state of the SSL
62state machine.
63.Fn SSL_state
64is a deprecated alias for
65.Fn SSL_get_state .
66.Pp
67The following bits may be set:
68.Bl -tag -width Ds
69.It Dv SSL_ST_ACCEPT
70This bit is set by
71.Xr SSL_accept 3
72and by
73.Xr SSL_set_accept_state 3 .
74It indicates that
75.Fa ssl
76is set up for server mode and no client initiated the TLS handshake yet.
77The function
78.Fn SSL_in_accept_init
79returns non-zero if this bit is set or 0 otherwise.
80.It Dv SSL_ST_BEFORE
81This bit is set by the
82.Xr SSL_accept 3 ,
83.Xr SSL_connect 3 ,
84.Xr SSL_set_accept_state 3 ,
85and
86.Xr SSL_set_connect_state 3
87functions.
88It indicates that the TLS handshake was not initiated yet.
89The function
90.Fn SSL_in_before
91returns non-zero if this bit is set or 0 otherwise.
92.It Dv SSL_ST_CONNECT
93This bit is set by
94.Xr SSL_connect 3
95and by
96.Xr SSL_set_connect_state 3 .
97It indicates that
98.Fa ssl
99is set up for client mode and no TLS handshake was initiated yet.
100The function
101.Fn SSL_in_connect_init
102returns non-zero if this bit is set or 0 otherwise.
103.El
104.Pp
105The following masks can be used:
106.Bl -tag -width Ds
107.It Dv SSL_ST_INIT
108Set if
109.Dv SSL_ST_ACCEPT
110or
111.Dv SSL_ST_CONNECT
112is set.
113The function
114.Fn SSL_in_init
115returns a non-zero value if one of these is set or 0 otherwise.
116.It Dv SSL_ST_MASK
117This mask includes all bits except
118.Dv SSL_ST_ACCEPT ,
119.Dv SSL_ST_BEFORE ,
120and
121.Dv SSL_ST_CONNECT .
122.It Dv SSL_ST_OK
123The state is set to this value when a connection is established.
124The function
125.Fn SSL_is_init_finished
126returns a non-zero value if the state equals this constant, or 0 otherwise.
127.It Dv SSL_ST_RENEGOTIATE
128The program is about to renegotiate, for example when entering
129.Xr SSL_read 3
130or
131.Xr SSL_write 3
132right after
133.Xr SSL_renegotiate 3
134was called.
135.El
136.Pp
137The meaning of other bits is protocol-dependent.
138Application programs usually do not need to inspect any of those
139other bits.
140.Pp
141All these functions may be implemented as macros.
142.Sh SEE ALSO
143.Xr ssl 3 ,
144.Xr SSL_renegotiate 3 ,
145.Xr SSL_set_connect_state 3
146.Sh HISTORY
147.Fn SSL_is_init_finished
148first appeared in SSLeay 0.4.5b.
149.Fn SSL_state
150first appeared in SSLeay 0.5.2.
151.Fn SSL_in_accept_init ,
152.Fn SSL_in_connect_init ,
153and
154.Fn SSL_in_init
155first appeared in SSLeay 0.6.0.
156.Fn SSL_in_before
157first appeared in SSLeay 0.8.0.
158.Fn SSL_get_state
159first appeared in SSLeay 0.9.0.
160All these functions have been available since
161.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_get_verify_result.3 b/src/lib/libssl/man/SSL_get_verify_result.3
deleted file mode 100644
index 180cf1bb73..0000000000
--- a/src/lib/libssl/man/SSL_get_verify_result.3
+++ /dev/null
@@ -1,102 +0,0 @@
1.\" $OpenBSD: SSL_get_verify_result.3,v 1.6 2021/06/26 17:36:28 tb Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 26 2021 $
52.Dt SSL_GET_VERIFY_RESULT 3
53.Os
54.Sh NAME
55.Nm SSL_get_verify_result
56.Nd get result of peer certificate verification
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft long
60.Fn SSL_get_verify_result "const SSL *ssl"
61.Sh DESCRIPTION
62.Fn SSL_get_verify_result
63returns the result of the verification of the X509 certificate presented by the
64peer, if any.
65.Pp
66.Fn SSL_get_verify_result
67can only return one error code while the verification of a certificate can fail
68because of many reasons at the same time.
69Only the last verification error that occurred during the processing is
70available from
71.Fn SSL_get_verify_result .
72.Pp
73The verification result is part of the established session and is restored when
74a session is reused.
75.Sh RETURN VALUES
76The following return values can currently occur:
77.Bl -tag -width Ds
78.It Dv X509_V_OK
79The verification succeeded or no peer certificate was presented.
80.It Any other value
81Documented in
82.Xr openssl 1 .
83.El
84.Sh SEE ALSO
85.Xr openssl 1 ,
86.Xr ssl 3 ,
87.Xr SSL_CTX_set_verify 3 ,
88.Xr SSL_get0_peername 3 ,
89.Xr SSL_get_peer_certificate 3 ,
90.Xr SSL_set_verify_result 3
91.Sh HISTORY
92.Fn SSL_get_verify_result
93first appeared in SSLeay 0.6.1 and has been available since
94.Ox 2.4 .
95.Sh BUGS
96If no peer certificate was presented, the returned result code is
97.Dv X509_V_OK .
98This is because no verification error occurred;
99however, it does not indicate success.
100.Fn SSL_get_verify_result
101is only useful in connection with
102.Xr SSL_get_peer_certificate 3 .
diff --git a/src/lib/libssl/man/SSL_get_version.3 b/src/lib/libssl/man/SSL_get_version.3
deleted file mode 100644
index a6cefb055b..0000000000
--- a/src/lib/libssl/man/SSL_get_version.3
+++ /dev/null
@@ -1,123 +0,0 @@
1.\" $OpenBSD: SSL_get_version.3,v 1.9 2021/04/15 16:13:22 tb Exp $
2.\" full merge up to: OpenSSL e417070c Jun 8 11:37:06 2016 -0400
3.\" selective merge up to: OpenSSL df75c2bf Dec 9 01:02:36 2018 +0100
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
6.\" Copyright (c) 2001, 2005, 2014 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: April 15 2021 $
53.Dt SSL_GET_VERSION 3
54.Os
55.Sh NAME
56.Nm SSL_get_version ,
57.Nm SSL_is_dtls ,
58.Nm SSL_version
59.\" The following are intentionally undocumented because
60.\" - the longer term plan is to remove them
61.\" - nothing appears to be using them in the wild
62.\" - and they have the wrong namespace prefix
63.\" Nm TLS1_get_version
64.\" Nm TLS1_get_client_version
65.Nd get the protocol information of a connection
66.Sh SYNOPSIS
67.In openssl/ssl.h
68.Ft const char *
69.Fn SSL_get_version "const SSL *ssl"
70.Ft int
71.Fn SSL_is_dtls "const SSL *ssl"
72.Ft int
73.Fn SSL_version "const SSL *ssl"
74.Sh DESCRIPTION
75.Fn SSL_get_version
76returns the name of the protocol used for the connection
77.Fa ssl .
78.Pp
79.Fn SSL_is_dtls
80returns 1 if the connection is using DTLS, 0 if not.
81.Pp
82.Fn SSL_version
83returns an integer constant representing that protocol.
84.Pp
85These functions only return reliable results
86after the initial handshake has been completed.
87.Sh RETURN VALUES
88The following strings or integers can be returned by
89.Fn SSL_get_version
90and
91.Fn SSL_version :
92.Bl -tag -width Ds
93.It Qo TLSv1 Qc No or Dv TLS1_VERSION
94The connection uses the TLSv1.0 protocol.
95.It Qo TLSv1.1 Qc No or Dv TLS1_1_VERSION
96The connection uses the TLSv1.1 protocol.
97.It Qo TLSv1.2 Qc No or Dv TLS1_2_VERSION
98The connection uses the TLSv1.2 protocol.
99.It Qo TLSv1.3 Qc No or Dv TLS1_3_VERSION
100The connection uses the TLSv1.3 protocol.
101.It Qo DTLSv1 Qc No or Dv DTLS1_VERSION
102The connection uses the Datagram Transport Layer Security 1.0 protocol.
103.It Qo DTLSv1.2 Qc No or Dv DTLS1_2_VERSION
104The connection uses the Datagram Transport Layer Security 1.2 protocol.
105.It Qq unknown
106This indicates an unknown protocol version;
107it cannot currently happen with LibreSSL.
108.El
109.Pp
110.Fn SSL_is_dtls
111returns 1 if the connection uses DTLS, 0 if not.
112.Sh SEE ALSO
113.Xr ssl 3
114.Sh HISTORY
115.Fn SSL_get_version
116and
117.Fn SSL_version
118first appeared in SSLeay 0.8.0 and have been available since
119.Ox 2.4 .
120.Pp
121.Fn SSL_is_dtls
122first appeared in OpenSSL 1.1.0 and has been available since
123.Ox 6.9 .
diff --git a/src/lib/libssl/man/SSL_library_init.3 b/src/lib/libssl/man/SSL_library_init.3
deleted file mode 100644
index 053c1e6fcb..0000000000
--- a/src/lib/libssl/man/SSL_library_init.3
+++ /dev/null
@@ -1,98 +0,0 @@
1.\" $OpenBSD: SSL_library_init.3,v 1.7 2019/06/14 13:41:31 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2006, 2010 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 14 2019 $
52.Dt SSL_LIBRARY_INIT 3
53.Os
54.Sh NAME
55.Nm SSL_library_init ,
56.Nm OpenSSL_add_ssl_algorithms ,
57.Nm SSLeay_add_ssl_algorithms
58.Nd initialize SSL library by registering algorithms
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fn SSL_library_init void
63.Ft int
64.Fn OpenSSL_add_ssl_algorithms void
65.Ft int
66.Fn SSLeay_add_ssl_algorithms void
67.Sh DESCRIPTION
68These functions are deprecated.
69It is never useful for any application program to call any of them explicitly.
70The library automatically calls them internally whenever needed.
71.Pp
72.Fn SSL_library_init
73registers the available ciphers and digests
74which are used directly or indirectly by TLS.
75.Pp
76.Fn OpenSSL_add_ssl_algorithms
77and
78.Fn SSLeay_add_ssl_algorithms
79are synonyms for
80.Fn SSL_library_init
81and are implemented as macros.
82.Sh RETURN VALUES
83.Fn SSL_library_init
84always returns 1.
85.Sh SEE ALSO
86.Xr ssl 3
87.Sh HISTORY
88.Fn SSLeay_add_ssl_algorithms
89first appeared in SSLeay 0.8.0 and has been available since
90.Ox 2.4 .
91.Pp
92.Fn SSL_library_init
93first appeared in OpenSSL 0.9.2b and has been available since
94.Ox 2.6 .
95.Pp
96.Fn OpenSSL_add_ssl_algorithms
97first appeared in OpenSSL 0.9.5 and has been available since
98.Ox 2.7 .
diff --git a/src/lib/libssl/man/SSL_load_client_CA_file.3 b/src/lib/libssl/man/SSL_load_client_CA_file.3
deleted file mode 100644
index f782d96dce..0000000000
--- a/src/lib/libssl/man/SSL_load_client_CA_file.3
+++ /dev/null
@@ -1,185 +0,0 @@
1.\" $OpenBSD: SSL_load_client_CA_file.3,v 1.9 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file is a derived work.
5.\" The changes are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" Permission to use, copy, modify, and distribute this software for any
10.\" purpose with or without fee is hereby granted, provided that the above
11.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" The original file was written by Lutz Jaenicke <jaenicke@openssl.org>.
22.\" Copyright (c) 2000 The OpenSSL Project. All rights reserved.
23.\"
24.\" Redistribution and use in source and binary forms, with or without
25.\" modification, are permitted provided that the following conditions
26.\" are met:
27.\"
28.\" 1. Redistributions of source code must retain the above copyright
29.\" notice, this list of conditions and the following disclaimer.
30.\"
31.\" 2. Redistributions in binary form must reproduce the above copyright
32.\" notice, this list of conditions and the following disclaimer in
33.\" the documentation and/or other materials provided with the
34.\" distribution.
35.\"
36.\" 3. All advertising materials mentioning features or use of this
37.\" software must display the following acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40.\"
41.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42.\" endorse or promote products derived from this software without
43.\" prior written permission. For written permission, please contact
44.\" openssl-core@openssl.org.
45.\"
46.\" 5. Products derived from this software may not be called "OpenSSL"
47.\" nor may "OpenSSL" appear in their names without prior written
48.\" permission of the OpenSSL Project.
49.\"
50.\" 6. Redistributions of any form whatsoever must retain the following
51.\" acknowledgment:
52.\" "This product includes software developed by the OpenSSL Project
53.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54.\"
55.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66.\" OF THE POSSIBILITY OF SUCH DAMAGE.
67.\"
68.Dd $Mdocdate: June 12 2019 $
69.Dt SSL_LOAD_CLIENT_CA_FILE 3
70.Os
71.Sh NAME
72.Nm SSL_load_client_CA_file ,
73.Nm SSL_add_file_cert_subjects_to_stack ,
74.Nm SSL_add_dir_cert_subjects_to_stack
75.Nd load certificate names from files
76.Sh SYNOPSIS
77.In openssl/ssl.h
78.Ft STACK_OF(X509_NAME) *
79.Fn SSL_load_client_CA_file "const char *file"
80.Ft int
81.Fo SSL_add_file_cert_subjects_to_stack
82.Fa "STACK_OF(X509_NAME) *stack"
83.Fa "const char *file"
84.Fc
85.Ft int
86.Fo SSL_add_dir_cert_subjects_to_stack
87.Fa "STACK_OF(X509_NAME) *stack"
88.Fa "const char *dir"
89.Fc
90.Sh DESCRIPTION
91.Fn SSL_load_client_CA_file
92reads PEM formatted certificates from
93.Fa file
94and returns a new
95.Vt STACK_OF(X509_NAME)
96with the subject names found.
97While the name suggests the specific usage as a support function for
98.Xr SSL_CTX_set_client_CA_list 3 ,
99it is not limited to CA certificates.
100.Pp
101.Fn SSL_add_file_cert_subjects_to_stack
102is similar except that the names are added to the existing
103.Fa stack .
104.Pp
105.Fn SSL_add_dir_cert_subjects_to_stack
106calls
107.Fn SSL_add_file_cert_subjects_to_stack
108on every file in the directory
109.Fa dir .
110.Pp
111If a name is already on the stack, all these functions skip it and
112do not add it again.
113.Sh RETURN VALUES
114.Fn SSL_load_client_CA_file
115returns a pointer to the new
116.Vt STACK_OF(X509_NAME)
117or
118.Dv NULL on failure .
119.Pp
120.Fn SSL_add_file_cert_subjects_to_stack
121and
122.Fn SSL_add_dir_cert_subjects_to_stack
123return 1 for success or 0 for failure.
124.Pp
125All these functions treat empty files and directories as failures.
126.Pp
127In some cases of failure, the reason can be determined with
128.Xr ERR_get_error 3 .
129.Sh EXAMPLES
130Load names of CAs from a file and use it as a client CA list:
131.Bd -literal
132SSL_CTX *ctx;
133STACK_OF(X509_NAME) *cert_names;
134\&...
135cert_names = SSL_load_client_CA_file("/path/to/CAfile.pem");
136if (cert_names != NULL)
137 SSL_CTX_set_client_CA_list(ctx, cert_names);
138else
139 error_handling();
140\&...
141.Ed
142.Sh SEE ALSO
143.Xr PEM_read_bio_X509 3 ,
144.Xr ssl 3 ,
145.Xr SSL_CTX_set_client_CA_list 3 ,
146.Xr X509_get_subject_name 3 ,
147.Xr X509_NAME_new 3
148.Sh HISTORY
149.Fn SSL_load_client_CA_file
150first appeared in SSLeay 0.8.0 and has been available since
151.Ox 2.4 .
152.Pp
153.Fn SSL_add_file_cert_subjects_to_stack
154and
155.Fn SSL_add_dir_cert_subjects_to_stack
156first appeared in OpenSSL 0.9.2b and have been available since
157.Ox 2.6 .
158.Sh AUTHORS
159.Fn SSL_add_file_cert_subjects_to_stack
160and
161.Fn SSL_add_dir_cert_subjects_to_stack
162were written by
163.An Ben Laurie Aq Mt ben@openssl.org
164in 1999.
165.Sh BUGS
166In some cases of failure, for example for empty files and directories,
167these functions fail to report an error, in the sense that
168.Xr ERR_get_error 3
169does not work.
170.Pp
171Even in case of failure, for example when parsing one of the
172files or certificates fails,
173.Fn SSL_add_file_cert_subjects_to_stack
174and
175.Fn SSL_add_dir_cert_subjects_to_stack
176may still have added some certificates to the stack.
177.Pp
178The behaviour of
179.Fn SSL_add_dir_cert_subjects_to_stack
180is non-deterministic.
181If parsing one file fails, parsing of the whole directory is aborted.
182Files in the directory are not parsed in any specific order.
183For example, adding an empty file to
184.Fa dir
185may or may not cause some of the other files to be ignored.
diff --git a/src/lib/libssl/man/SSL_new.3 b/src/lib/libssl/man/SSL_new.3
deleted file mode 100644
index 22c5dbf2db..0000000000
--- a/src/lib/libssl/man/SSL_new.3
+++ /dev/null
@@ -1,110 +0,0 @@
1.\" $OpenBSD: SSL_new.3,v 1.7 2022/07/13 22:05:53 schwarze Exp $
2.\" full merge up to: OpenSSL 1c7ae3dd Mar 29 19:17:55 2017 +1000
3.\"
4.\" This file was written by Richard Levitte <levitte@openssl.org>
5.\" and Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2000, 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: July 13 2022 $
53.Dt SSL_NEW 3
54.Os
55.Sh NAME
56.Nm SSL_new ,
57.Nm SSL_up_ref
58.Nd create a new SSL structure for a connection
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft SSL *
62.Fn SSL_new "SSL_CTX *ctx"
63.Ft int
64.Fn SSL_up_ref "SSL *ssl"
65.Sh DESCRIPTION
66.Fn SSL_new
67creates a new
68.Vt SSL
69structure which is needed to hold the data for a TLS/SSL connection.
70The new structure inherits the settings of the underlying context
71.Fa ctx :
72connection method, options, verification settings,
73timeout settings, security level.
74The reference count of the new structure is set to 1.
75.Pp
76.Fn SSL_up_ref
77increments the reference count of
78.Fa ssl
79by 1.
80.Sh RETURN VALUES
81The following return values can occur:
82.Bl -tag -width Ds
83.It Dv NULL
84The creation of a new
85.Vt SSL
86structure failed.
87Check the error stack to find out the reason.
88.It Pointer to an Vt SSL No structure
89The return value points to an allocated
90.Vt SSL
91structure.
92.El
93.Pp
94.Fn SSL_up_ref
95returns 1 for success or 0 for failure.
96.Sh SEE ALSO
97.Xr ssl 3 ,
98.Xr SSL_clear 3 ,
99.Xr SSL_CTX_set_options 3 ,
100.Xr SSL_CTX_set_security_level 3 ,
101.Xr SSL_free 3 ,
102.Xr SSL_get_SSL_CTX 3
103.Sh HISTORY
104.Fn SSL_new
105appeared in SSLeay 0.4 or earlier and has been available since
106.Ox 2.4 .
107.Pp
108.Fn SSL_up_ref
109first appeared in OpenSSL 1.1.0 and has been available since
110.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_num_renegotiations.3 b/src/lib/libssl/man/SSL_num_renegotiations.3
deleted file mode 100644
index 6a81b76a60..0000000000
--- a/src/lib/libssl/man/SSL_num_renegotiations.3
+++ /dev/null
@@ -1,75 +0,0 @@
1.\" $OpenBSD: SSL_num_renegotiations.3,v 1.5 2019/06/12 09:36:30 schwarze Exp $
2.\"
3.\" Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: June 12 2019 $
18.Dt SSL_NUM_RENEGOTIATIONS 3
19.Os
20.Sh NAME
21.Nm SSL_num_renegotiations ,
22.Nm SSL_clear_num_renegotiations ,
23.Nm SSL_total_renegotiations
24.Nd renegotiation counters
25.Sh SYNOPSIS
26.In openssl/ssl.h
27.Ft long
28.Fo SSL_num_renegotiations
29.Fa "SSL *ssl"
30.Fc
31.Ft long
32.Fo SSL_clear_num_renegotiations
33.Fa "SSL *ssl"
34.Fc
35.Ft long
36.Fo SSL_total_renegotiations
37.Fa "SSL *ssl"
38.Fc
39.Sh DESCRIPTION
40.Fn SSL_num_renegotiations
41reports the number of renegotiations initiated in
42.Fa ssl
43since
44.Xr SSL_new 3 ,
45.Xr SSL_clear 3 ,
46or
47.Fn SSL_clear_num_renegotiations
48was last called on that object.
49.Pp
50.Fn SSL_clear_num_renegotiations
51does the same and additionally resets the renegotiation counter to 0.
52.Pp
53.Fn SSL_total_renegotiations
54reports the number of renegotiations initiated in
55.Fa ssl
56since
57.Xr SSL_new 3
58or
59.Xr SSL_clear 3
60was last called on that object.
61.Pp
62These functions are implemented as macros.
63.Sh RETURN VALUES
64All these functions return a number of renegotiations.
65.Sh SEE ALSO
66.Xr BIO_set_ssl_renegotiate_bytes 3 ,
67.Xr ssl 3 ,
68.Xr SSL_ctrl 3 ,
69.Xr SSL_read 3 ,
70.Xr SSL_renegotiate 3 ,
71.Xr SSL_write 3
72.Sh HISTORY
73These functions first appeared in SSLeay 0.9.0
74and have been available since
75.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_pending.3 b/src/lib/libssl/man/SSL_pending.3
deleted file mode 100644
index bbc2e9bdd2..0000000000
--- a/src/lib/libssl/man/SSL_pending.3
+++ /dev/null
@@ -1,90 +0,0 @@
1.\" $OpenBSD: SSL_pending.3,v 1.5 2020/01/23 03:40:18 beck Exp $
2.\" OpenSSL a528d4f0 Oct 27 13:40:11 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>,
5.\" Bodo Moeller <bodo@openssl.org>, and Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2000, 2005, 2015, 2016 The OpenSSL Project.
7.\" All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: January 23 2020 $
54.Dt SSL_PENDING 3
55.Os
56.Sh NAME
57.Nm SSL_pending
58.Nd obtain number of readable bytes buffered in an SSL object
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fn SSL_pending "const SSL *ssl"
63.Sh DESCRIPTION
64Data is received in whole blocks known as records from the peer.
65A whole record is processed, for example decrypted, in one go and
66is buffered until it is read by the application via a call to
67.Xr SSL_read 3 .
68.Pp
69.Fn SSL_pending
70returns the number of bytes of application data which are available
71for immediate read.
72.Pp
73.Fn SSL_pending
74takes into account only bytes from the TLS/SSL record that is
75currently being processed (if any).
76.Sh RETURN VALUES
77.Fn SSL_pending
78returns the number of buffered and processed application data
79bytes that are pending and are available for immediate read.
80.Sh SEE ALSO
81.Xr ssl 3 ,
82.Xr SSL_read 3
83.Sh HISTORY
84.Fn SSL_pending
85appeared in SSLeay 0.4 or earlier and has been available since
86.Ox 2.4 .
87.Sh BUGS
88Up to OpenSSL 0.9.6,
89.Fn SSL_pending
90did not check if the record type of pending data is application data.
diff --git a/src/lib/libssl/man/SSL_read.3 b/src/lib/libssl/man/SSL_read.3
deleted file mode 100644
index bb72a8ed82..0000000000
--- a/src/lib/libssl/man/SSL_read.3
+++ /dev/null
@@ -1,278 +0,0 @@
1.\" $OpenBSD: SSL_read.3,v 1.8 2021/10/24 15:10:13 schwarze Exp $
2.\" full merge up to: OpenSSL 5a2443ae Nov 14 11:37:36 2016 +0000
3.\" partial merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org> and
6.\" Matt Caswell <matt@openssl.org>.
7.\" Copyright (c) 2000, 2001, 2008, 2016 The OpenSSL Project.
8.\" All rights reserved.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\"
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\"
17.\" 2. Redistributions in binary form must reproduce the above copyright
18.\" notice, this list of conditions and the following disclaimer in
19.\" the documentation and/or other materials provided with the
20.\" distribution.
21.\"
22.\" 3. All advertising materials mentioning features or use of this
23.\" software must display the following acknowledgment:
24.\" "This product includes software developed by the OpenSSL Project
25.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26.\"
27.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28.\" endorse or promote products derived from this software without
29.\" prior written permission. For written permission, please contact
30.\" openssl-core@openssl.org.
31.\"
32.\" 5. Products derived from this software may not be called "OpenSSL"
33.\" nor may "OpenSSL" appear in their names without prior written
34.\" permission of the OpenSSL Project.
35.\"
36.\" 6. Redistributions of any form whatsoever must retain the following
37.\" acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40.\"
41.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
53.\"
54.Dd $Mdocdate: October 24 2021 $
55.Dt SSL_READ 3
56.Os
57.Sh NAME
58.Nm SSL_read_ex ,
59.Nm SSL_read ,
60.Nm SSL_peek_ex ,
61.Nm SSL_peek
62.Nd read bytes from a TLS connection
63.Sh SYNOPSIS
64.In openssl/ssl.h
65.Ft int
66.Fn SSL_read_ex "SSL *ssl" "void *buf" "size_t num" "size_t *readbytes"
67.Ft int
68.Fn SSL_read "SSL *ssl" "void *buf" "int num"
69.Ft int
70.Fn SSL_peek_ex "SSL *ssl" "void *buf" "size_t num" "size_t *readbytes"
71.Ft int
72.Fn SSL_peek "SSL *ssl" "void *buf" "int num"
73.Sh DESCRIPTION
74.Fn SSL_read_ex
75and
76.Fn SSL_read
77try to read
78.Fa num
79bytes from the specified
80.Fa ssl
81into the buffer
82.Fa buf .
83On success
84.Fn SSL_read_ex
85stores the number of bytes actually read in
86.Pf * Fa readbytes .
87.Pp
88.Fn SSL_peek_ex
89and
90.Fn SSL_peek
91are identical to
92.Fn SSL_read_ex
93and
94.Fn SSL_read ,
95respectively,
96except that no bytes are removed from the underlying BIO during
97the read, such that a subsequent call to
98.Fn SSL_read_ex
99or
100.Fn SSL_read
101will yield at least the same bytes once again.
102.Pp
103In the following,
104.Fn SSL_read_ex ,
105.Fn SSL_read ,
106.Fn SSL_peek_ex ,
107and
108.Fn SSL_peek
109are called
110.Dq read functions .
111.Pp
112If necessary, a read function will negotiate a TLS session, if
113not already explicitly performed by
114.Xr SSL_connect 3
115or
116.Xr SSL_accept 3 .
117If the peer requests a re-negotiation, it will be performed
118transparently during the read function operation.
119The behaviour of the read functions depends on the underlying
120.Vt BIO .
121.Pp
122For the transparent negotiation to succeed, the
123.Fa ssl
124must have been initialized to client or server mode.
125This is done by calling
126.Xr SSL_set_connect_state 3
127or
128.Xr SSL_set_accept_state 3
129before the first call to a read function.
130.Pp
131The read functions work based on the TLS records.
132The data are received in records (with a maximum record size of 16kB).
133Only when a record has been completely received, it can be processed
134(decrypted and checked for integrity).
135Therefore, data that was not retrieved at the last read call can
136still be buffered inside the TLS layer and will be retrieved on the
137next read call.
138If
139.Fa num
140is higher than the number of bytes buffered, the read functions
141will return with the bytes buffered.
142If no more bytes are in the buffer, the read functions will trigger
143the processing of the next record.
144Only when the record has been received and processed completely
145will the read functions return reporting success.
146At most the contents of the record will be returned.
147As the size of a TLS record may exceed the maximum packet size
148of the underlying transport (e.g., TCP), it may be necessary to
149read several packets from the transport layer before the record is
150complete and the read call can succeed.
151.Pp
152If the underlying
153.Vt BIO
154is blocking,
155a read function will only return once the read operation has been
156finished or an error occurred, except when a renegotiation takes
157place, in which case an
158.Dv SSL_ERROR_WANT_READ
159may occur.
160This behavior can be controlled with the
161.Dv SSL_MODE_AUTO_RETRY
162flag of the
163.Xr SSL_CTX_set_mode 3
164call.
165.Pp
166If the underlying
167.Vt BIO
168is non-blocking, a read function will also return when the underlying
169.Vt BIO
170could not satisfy the needs of the function to continue the operation.
171In this case a call to
172.Xr SSL_get_error 3
173with the return value of the read function will yield
174.Dv SSL_ERROR_WANT_READ
175or
176.Dv SSL_ERROR_WANT_WRITE .
177As at any time a re-negotiation is possible, a read function may
178also cause write operations.
179The calling process must then repeat the call after taking appropriate
180action to satisfy the needs of the read function.
181The action depends on the underlying
182.Vt BIO .
183When using a non-blocking socket, nothing is to be done, but
184.Xr select 2
185can be used to check for the required condition.
186When using a buffering
187.Vt BIO ,
188like a
189.Vt BIO
190pair, data must be written into or retrieved out of the
191.Vt BIO
192before being able to continue.
193.Pp
194.Xr SSL_pending 3
195can be used to find out whether there are buffered bytes available for
196immediate retrieval.
197In this case a read function can be called without blocking or
198actually receiving new data from the underlying socket.
199.Pp
200When a read function operation has to be repeated because of
201.Dv SSL_ERROR_WANT_READ
202or
203.Dv SSL_ERROR_WANT_WRITE ,
204it must be repeated with the same arguments.
205.Sh RETURN VALUES
206.Fn SSL_read_ex
207and
208.Fn SSL_peek_ex
209return 1 for success or 0 for failure.
210Success means that one or more application data bytes
211have been read from the SSL connection.
212Failure means that no bytes could be read from the SSL connection.
213Failures can be retryable (e.g. we are waiting for more bytes to be
214delivered by the network) or non-retryable (e.g. a fatal network error).
215In the event of a failure, call
216.Xr SSL_get_error 3
217to find out the reason which indicates whether the call is retryable or not.
218.Pp
219For
220.Fn SSL_read
221and
222.Fn SSL_peek ,
223the following return values can occur:
224.Bl -tag -width Ds
225.It >0
226The read operation was successful.
227The return value is the number of bytes actually read from the
228TLS connection.
229.It 0
230The read operation was not successful.
231The reason may either be a clean shutdown due to a
232.Dq close notify
233alert sent by the peer (in which case the
234.Dv SSL_RECEIVED_SHUTDOWN
235flag in the ssl shutdown state is set (see
236.Xr SSL_shutdown 3
237and
238.Xr SSL_set_shutdown 3 ) .
239It is also possible that the peer simply shut down the underlying transport and
240the shutdown is incomplete.
241Call
242.Xr SSL_get_error 3
243with the return value to find out whether an error occurred or the connection
244was shut down cleanly
245.Pq Dv SSL_ERROR_ZERO_RETURN .
246.It <0
247The read operation was not successful, because either an error occurred or
248action must be taken by the calling process.
249Call
250.Xr SSL_get_error 3
251with the return value to find out the reason.
252.El
253.Sh SEE ALSO
254.Xr BIO_new 3 ,
255.Xr ssl 3 ,
256.Xr SSL_accept 3 ,
257.Xr SSL_connect 3 ,
258.Xr SSL_CTX_new 3 ,
259.Xr SSL_CTX_set_mode 3 ,
260.Xr SSL_get_error 3 ,
261.Xr SSL_pending 3 ,
262.Xr SSL_set_connect_state 3 ,
263.Xr SSL_set_shutdown 3 ,
264.Xr SSL_shutdown 3 ,
265.Xr SSL_write 3
266.Sh HISTORY
267.Fn SSL_read
268appeared in SSLeay 0.4 or earlier.
269.Fn SSL_peek
270first appeared in SSLeay 0.6.6.
271Both functions have been available since
272.Ox 2.4 .
273.Pp
274.Fn SSL_read_ex
275and
276.Fn SSL_peek_ex
277first appeared in OpenSSL 1.1.1 and have been available since
278.Ox 7.1 .
diff --git a/src/lib/libssl/man/SSL_read_early_data.3 b/src/lib/libssl/man/SSL_read_early_data.3
deleted file mode 100644
index 1435c15935..0000000000
--- a/src/lib/libssl/man/SSL_read_early_data.3
+++ /dev/null
@@ -1,174 +0,0 @@
1.\" $OpenBSD: SSL_read_early_data.3,v 1.4 2021/11/26 13:48:22 jsg Exp $
2.\" content checked up to: OpenSSL 6328d367 Jul 4 21:58:30 2020 +0200
3.\"
4.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
5.\"
6.\" Permission to use, copy, modify, and distribute this software for any
7.\" purpose with or without fee is hereby granted, provided that the above
8.\" copyright notice and this permission notice appear in all copies.
9.\"
10.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17.\"
18.Dd $Mdocdate: November 26 2021 $
19.Dt SSL_READ_EARLY_DATA 3
20.Os
21.Sh NAME
22.Nm SSL_CTX_set_max_early_data ,
23.Nm SSL_set_max_early_data ,
24.Nm SSL_SESSION_set_max_early_data ,
25.Nm SSL_CTX_get_max_early_data ,
26.Nm SSL_get_max_early_data ,
27.Nm SSL_SESSION_get_max_early_data ,
28.Nm SSL_write_early_data ,
29.Nm SSL_read_early_data ,
30.Nm SSL_get_early_data_status
31.Nd transmit application data during the handshake
32.Sh SYNOPSIS
33.In openssl/ssl.h
34.Ft int
35.Fo SSL_CTX_set_max_early_data
36.Fa "SSL_CTX *ctx"
37.Fa "uint32_t max_bytes"
38.Fc
39.Ft int
40.Fo SSL_set_max_early_data
41.Fa "SSL *ssl"
42.Fa "uint32_t max_bytes"
43.Fc
44.Ft int
45.Fo SSL_SESSION_set_max_early_data
46.Fa "SSL_SESSION *session"
47.Fa "uint32_t max_bytes"
48.Fc
49.Ft uint32_t
50.Fo SSL_CTX_get_max_early_data
51.Fa "const SSL_CTX *ctx"
52.Fc
53.Ft uint32_t
54.Fo SSL_get_max_early_data
55.Fa "const SSL *ssl"
56.Fc
57.Ft uint32_t
58.Fo SSL_SESSION_get_max_early_data
59.Fa "const SSL_SESSION *session"
60.Fc
61.Ft int
62.Fo SSL_write_early_data
63.Fa "SSL *ssl"
64.Fa "const void *buf"
65.Fa "size_t len"
66.Fa "size_t *written"
67.Fc
68.Ft int
69.Fo SSL_read_early_data
70.Fa "SSL *ssl"
71.Fa "void *buf"
72.Fa "size_t maxlen"
73.Fa "size_t *readbytes"
74.Fc
75.Ft int
76.Fo SSL_get_early_data_status
77.Fa "const SSL *ssl"
78.Fc
79.Sh DESCRIPTION
80In LibreSSL, these functions have no effect.
81They are only provided because some application programs
82expect the API to be available when TLSv1.3 is supported.
83Using these functions is strongly discouraged because they provide
84marginal benefit in the first place even when implemented and
85used as designed, because they have absurdly complicated semantics,
86and because when they are used, inconspicuous oversights are likely
87to cause serious security vulnerabilities.
88.Pp
89If these functions are used, other TLS implementations
90may allow the transfer of application data during the initial handshake.
91Even when used as designed, security of the connection is compromised;
92in particular, application data is exchanged with unauthenticated peers,
93and there is no forward secrecy.
94Other downsides include an increased risk of replay attacks.
95.Pp
96.Fn SSL_CTX_set_max_early_data ,
97.Fn SSL_set_max_early_data ,
98and
99.Fn SSL_SESSION_set_max_early_data
100are intended to configure the maximum number of bytes per session
101that can be transmitted during the handshake.
102With LibreSSL, all arguments are ignored.
103.Pp
104An endpoint can attempt to send application data with
105.Fn SSL_write_early_data
106during the handshake.
107With LibreSSL, such attempts always fail and set
108.Pf * Fa written
109to 0.
110.Pp
111A server can attempt to read application data from the client using
112.Fn SSL_read_early_data
113during the handshake.
114With LibreSSL, no such data is ever accepted and
115.Pf * Fa readbytes
116is always set to 0.
117.Sh RETURN VALUES
118.Fn SSL_CTX_set_max_early_data ,
119.Fn SSL_set_max_early_data ,
120and
121.Fn SSL_SESSION_set_max_early_data
122return 1 for success or 0 for failure.
123With LibreSSL, they always succeed.
124.Pp
125.Fn SSL_CTX_get_max_early_data ,
126.Fn SSL_get_max_early_data ,
127and
128.Fn SSL_SESSION_get_max_early_data
129return the maximum number of bytes of application data
130that will be accepted from the peer during the handshake.
131With LibreSSL, they always return 0.
132.Pp
133.Fn SSL_write_early_data
134returns 1 for success or 0 for failure.
135With LibreSSL, it always fails.
136.Pp
137With LibreSSL,
138.Fn SSL_read_early_data
139always returns
140.Dv SSL_READ_EARLY_DATA_FINISH
141on the server side and
142.Dv SSL_READ_EARLY_DATA_ERROR
143on the client side.
144.Dv SSL_READ_EARLY_DATA_SUCCESS
145can occur with other implementations, but not with LibreSSL.
146.Pp
147With LibreSSL,
148.Fn SSL_get_early_data_status
149always returns
150.Dv SSL_EARLY_DATA_REJECTED .
151With other implementations, it might also return
152.Dv SSL_EARLY_DATA_NOT_SENT
153or
154.Dv SSL_EARLY_DATA_ACCEPTED .
155.Sh SEE ALSO
156.Xr ssl 3 ,
157.Xr SSL_read 3 ,
158.Xr SSL_write 3
159.Sh STANDARDS
160RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3:
161.Bl -tag -width "section 4.2.10" -compact
162.It Section 2.3
1630-RTT data
164.It Section 4.2.10
165Early Data Indication
166.It Section 8
1670-RTT and Anti-Replay
168.It Appendix E.5
169Replay Attacks on 0-RTT
170.El
171.Sh HISTORY
172These functions first appeared in OpenSSL 1.1.1
173and have been available since
174.Ox 7.0 .
diff --git a/src/lib/libssl/man/SSL_renegotiate.3 b/src/lib/libssl/man/SSL_renegotiate.3
deleted file mode 100644
index 8188d37323..0000000000
--- a/src/lib/libssl/man/SSL_renegotiate.3
+++ /dev/null
@@ -1,166 +0,0 @@
1.\" $OpenBSD: SSL_renegotiate.3,v 1.9 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL SSL_key_update.pod 4fbfe86a Feb 16 17:04:40 2017 +0000
3.\"
4.\" This file is a derived work.
5.\" Some parts are covered by the following Copyright and license:
6.\"
7.\" Copyright (c) 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
8.\"
9.\" Permission to use, copy, modify, and distribute this software for any
10.\" purpose with or without fee is hereby granted, provided that the above
11.\" copyright notice and this permission notice appear in all copies.
12.\"
13.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
14.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
15.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
16.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
17.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
18.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
19.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20.\"
21.\" Other parts were written by Matt Caswell <matt@openssl.org>.
22.\" Copyright (c) 2017 The OpenSSL Project. All rights reserved.
23.\"
24.\" Redistribution and use in source and binary forms, with or without
25.\" modification, are permitted provided that the following conditions
26.\" are met:
27.\"
28.\" 1. Redistributions of source code must retain the above copyright
29.\" notice, this list of conditions and the following disclaimer.
30.\"
31.\" 2. Redistributions in binary form must reproduce the above copyright
32.\" notice, this list of conditions and the following disclaimer in
33.\" the documentation and/or other materials provided with the
34.\" distribution.
35.\"
36.\" 3. All advertising materials mentioning features or use of this
37.\" software must display the following acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40.\"
41.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42.\" endorse or promote products derived from this software without
43.\" prior written permission. For written permission, please contact
44.\" openssl-core@openssl.org.
45.\"
46.\" 5. Products derived from this software may not be called "OpenSSL"
47.\" nor may "OpenSSL" appear in their names without prior written
48.\" permission of the OpenSSL Project.
49.\"
50.\" 6. Redistributions of any form whatsoever must retain the following
51.\" acknowledgment:
52.\" "This product includes software developed by the OpenSSL Project
53.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54.\"
55.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66.\" OF THE POSSIBILITY OF SUCH DAMAGE.
67.\"
68.Dd $Mdocdate: June 12 2019 $
69.Dt SSL_RENEGOTIATE 3
70.Os
71.Sh NAME
72.Nm SSL_renegotiate ,
73.Nm SSL_renegotiate_abbreviated ,
74.Nm SSL_renegotiate_pending
75.Nd initiate a new TLS handshake
76.Sh SYNOPSIS
77.In openssl/ssl.h
78.Ft int
79.Fo SSL_renegotiate
80.Fa "SSL *ssl"
81.Fc
82.Ft int
83.Fo SSL_renegotiate_abbreviated
84.Fa "SSL *ssl"
85.Fc
86.Ft int
87.Fo SSL_renegotiate_pending
88.Fa "SSL *ssl"
89.Fc
90.Sh DESCRIPTION
91When called from the client side,
92.Fn SSL_renegotiate
93schedules a completely new handshake over an existing TLS connection.
94The next time an I/O operation such as
95.Fn SSL_read
96or
97.Fn SSL_write
98takes place on the connection, a check is performed to confirm
99that it is a suitable time to start a renegotiation.
100If so, a new handshake is initiated immediately.
101An existing session associated with the connection is not resumed.
102.Pp
103This function is automatically called by
104.Xr SSL_read 3
105and
106.Xr SSL_write 3
107whenever the renegotiation byte count set by
108.Xr BIO_set_ssl_renegotiate_bytes 3
109or the timeout set by
110.Xr BIO_set_ssl_renegotiate_timeout 3
111are exceeded.
112.Pp
113When called from the client side,
114.Fn SSL_renegotiate_abbreviated
115is similar to
116.Fn SSL_renegotiate
117except that resuming the session associated with the current
118connection is attempted in the new handshake.
119.Pp
120When called from the server side,
121.Fn SSL_renegotiate
122and
123.Fn SSL_renegotiate_abbreviated
124behave identically.
125They both schedule a request for a new handshake to be sent to the client.
126The next time an I/O operation is performed, the same checks as on
127the client side are performed and then, if appropriate, the request
128is sent.
129The client may or may not respond with a new handshake and it may
130or may not attempt to resume an existing session.
131If a new handshake is started, it is handled transparently during
132any I/O function.
133.Pp
134If a LibreSSL client receives a renegotiation request from a server,
135it is also handled transparently during any I/O function.
136The client attempts to resume the current session in the new
137handshake.
138For historical reasons, DTLS clients do not attempt to resume
139the session in the new handshake.
140.Sh RETURN VALUES
141.Fn SSL_renegotiate
142and
143.Fn SSL_renegotiate_abbreviated
144return 1 on success or 0 on error.
145.Pp
146.Fn SSL_renegotiate_pending
147returns 1 if a renegotiation or renegotiation request has been
148scheduled but not yet acted on, or 0 otherwise.
149.Sh SEE ALSO
150.Xr ssl 3 ,
151.Xr SSL_do_handshake 3 ,
152.Xr SSL_num_renegotiations 3 ,
153.Xr SSL_read 3 ,
154.Xr SSL_write 3
155.Sh HISTORY
156.Fn SSL_renegotiate
157first appeared in SSLeay 0.8.0 and has been available since
158.Ox 2.4 .
159.Pp
160.Fn SSL_renegotiate_pending
161first appeared in OpenSSL 0.9.7 and has been available since
162.Ox 3.2 .
163.Pp
164.Fn SSL_renegotiate_abbreviated
165first appeared in OpenSSL 1.0.1 and has been available since
166.Ox 5.3 .
diff --git a/src/lib/libssl/man/SSL_rstate_string.3 b/src/lib/libssl/man/SSL_rstate_string.3
deleted file mode 100644
index 99613ba3c0..0000000000
--- a/src/lib/libssl/man/SSL_rstate_string.3
+++ /dev/null
@@ -1,108 +0,0 @@
1.\" $OpenBSD: SSL_rstate_string.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_RSTATE_STRING 3
53.Os
54.Sh NAME
55.Nm SSL_rstate_string ,
56.Nm SSL_rstate_string_long
57.Nd get textual description of state of an SSL object during read operation
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft const char *
61.Fn SSL_rstate_string "SSL *ssl"
62.Ft const char *
63.Fn SSL_rstate_string_long "SSL *ssl"
64.Sh DESCRIPTION
65.Fn SSL_rstate_string
66returns a 2-letter string indicating the current read state of the
67.Vt SSL
68object
69.Fa ssl .
70.Pp
71.Fn SSL_rstate_string_long
72returns a string indicating the current read state of the
73.Vt SSL
74object
75.Fa ssl .
76.Pp
77When performing a read operation, the SSL/TLS engine must parse the record,
78consisting of header and body.
79When working in a blocking environment,
80.Fn SSL_rstate_string[_long]
81should always return
82.Qo RD Qc Ns / Ns Qo read done Qc .
83.Pp
84This function should only seldom be needed in applications.
85.Sh RETURN VALUES
86.Fn SSL_rstate_string
87and
88.Fn SSL_rstate_string_long
89can return the following values:
90.Bl -tag -width Ds
91.It Qo RH Qc Ns / Ns Qo read header Qc
92The header of the record is being evaluated.
93.It Qo RB Qc Ns / Ns Qo read body Qc
94The body of the record is being evaluated.
95.It Qo RD Qc Ns / Ns Qo read done Qc
96The record has been completely processed.
97.It Qo unknown Qc Ns / Ns Qo unknown Qc
98The read state is unknown.
99This should never happen.
100.El
101.Sh SEE ALSO
102.Xr ssl 3
103.Sh HISTORY
104.Fn SSL_rstate_string
105and
106.Fn SSL_rstate_string_long
107first appeared in SSLeay 0.6.0 and have been available since
108.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_session_reused.3 b/src/lib/libssl/man/SSL_session_reused.3
deleted file mode 100644
index add61a904b..0000000000
--- a/src/lib/libssl/man/SSL_session_reused.3
+++ /dev/null
@@ -1,84 +0,0 @@
1.\" $OpenBSD: SSL_session_reused.3,v 1.6 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 12 2019 $
52.Dt SSL_SESSION_REUSED 3
53.Os
54.Sh NAME
55.Nm SSL_session_reused
56.Nd query whether a reused session was negotiated during handshake
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fn SSL_session_reused "SSL *ssl"
61.Sh DESCRIPTION
62Query whether a reused session was negotiated during the handshake.
63.Pp
64During the negotiation, a client can propose to reuse a session.
65The server then looks up the session in its cache.
66If both client and server agree on the session,
67it will be reused and a flag is set that can be queried by the application.
68.Sh RETURN VALUES
69The following return values can occur:
70.Bl -tag -width Ds
71.It 0
72A new session was negotiated.
73.It 1
74A session was reused.
75.El
76.Sh SEE ALSO
77.Xr ssl 3 ,
78.Xr SSL_ctrl 3 ,
79.Xr SSL_CTX_set_session_cache_mode 3 ,
80.Xr SSL_set_session 3
81.Sh HISTORY
82.Fn SSL_session_reused
83first appeared in SSLeay 0.8.0 and has been available since
84.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_set1_host.3 b/src/lib/libssl/man/SSL_set1_host.3
deleted file mode 100644
index 2a3935c3f2..0000000000
--- a/src/lib/libssl/man/SSL_set1_host.3
+++ /dev/null
@@ -1,172 +0,0 @@
1.\" $OpenBSD: SSL_set1_host.3,v 1.4 2021/03/31 16:56:46 tb Exp $
2.\" selective merge up to: OpenSSL 6328d367 Jul 4 21:58:30 2020 +0200
3.\"
4.\" This file was written by Viktor Dukhovni <viktor@openssl.org>
5.\" Copyright (c) 2015 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 31 2021 $
52.Dt SSL_SET1_HOST 3
53.Os
54.Sh NAME
55.Nm SSL_set1_host ,
56.Nm SSL_set_hostflags ,
57.Nm SSL_get0_peername
58.Nd SSL server verification parameters
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fo SSL_set1_host
63.Fa "SSL *ssl"
64.Fa "const char *hostname"
65.Fc
66.Ft void
67.Fo SSL_set_hostflags
68.Fa "SSL *ssl"
69.Fa "unsigned int flags"
70.Fc
71.Ft const char *
72.Fo SSL_get0_peername
73.Fa "SSL *ssl"
74.Fc
75.Sh DESCRIPTION
76.Fn SSL_set1_host
77configures a server hostname check in the
78.Fa ssl
79client, setting the expected DNS hostname to
80.Fa hostname
81and clearing any previously specified hostname.
82If
83.Fa hostname
84is
85.Dv NULL
86or the empty string, name checks are not performed on the peer certificate.
87If a nonempty
88.Fa hostname
89is specified, certificate verification automatically checks the peer
90hostname via
91.Xr X509_check_host 3
92with
93.Fa flags
94set to 0.
95.Pp
96.Fn SSL_set_hostflags
97sets the flags that will be passed to
98.Xr X509_check_host 3
99when name checks are applicable,
100by default the flags value is 0.
101See
102.Xr X509_check_host 3
103for the list of available flags and their meaning.
104.Pp
105.Fn SSL_get0_peername
106returns the DNS hostname or subject CommonName from the peer certificate
107that matched one of the reference identifiers.
108Unless wildcard matching is disabled, the name matched in the peer
109certificate may be a wildcard name.
110A reference identifier starting with
111.Sq \&.
112indicates a parent domain prefix rather than a fixed name.
113In this case, the matched peername may be a sub-domain
114of the reference identifier.
115The returned string is owned by the library and is no longer valid
116once the associated
117.Fa ssl
118object is cleared or freed, or if a renegotiation takes place.
119Applications must not free the return value.
120.Pp
121SSL clients are advised to use these functions in preference to
122explicitly calling
123.Xr X509_check_host 3 .
124.Sh RETURN VALUES
125.Fn SSL_set1_host
126returns 1 for success or 0 for failure.
127.Pp
128.Fn SSL_get0_peername
129returns the matched peername or
130.Dv NULL
131if peername verification is not applicable
132or no trusted peername was matched.
133Use
134.Xr SSL_get_verify_result 3
135to determine whether verification succeeded.
136.Sh EXAMPLES
137The calls below check the hostname.
138Wildcards are supported, but they must match the entire label.
139The actual name matched in the certificate (which might be a wildcard)
140is retrieved, and must be copied by the application if it is to be
141retained beyond the lifetime of the SSL connection.
142.Bd -literal
143if (!SSL_set1_host(ssl, "smtp.example.com"))
144 /* error */
145
146/* XXX: Perform SSL_connect() handshake and handle errors here */
147
148if (SSL_get_verify_result(ssl) == X509_V_OK) {
149 const char *peername = SSL_get0_peername(ssl);
150
151 if (peername != NULL)
152 /* Name checks were in scope and matched the peername */
153}
154.Ed
155.Sh SEE ALSO
156.Xr ssl 3 ,
157.Xr SSL_CTX_set_verify 3 ,
158.Xr SSL_get_peer_certificate 3 ,
159.Xr SSL_get_verify_result 3 ,
160.Xr X509_check_host 3 ,
161.Xr X509_VERIFY_PARAM_set1_host 3
162.Sh HISTORY
163All three functions first appeared in OpenSSL 1.1.0.
164.Fn SSL_set1_host
165has been available since
166.Ox 6.5 ,
167and
168.Fn SSL_set_hostflags
169and
170.Fn SSL_get0_peername
171since
172.Ox 6.9 .
diff --git a/src/lib/libssl/man/SSL_set1_param.3 b/src/lib/libssl/man/SSL_set1_param.3
deleted file mode 100644
index cd8ad40ad0..0000000000
--- a/src/lib/libssl/man/SSL_set1_param.3
+++ /dev/null
@@ -1,137 +0,0 @@
1.\" $OpenBSD: SSL_set1_param.3,v 1.6 2022/09/10 10:22:46 jsg Exp $
2.\" full merge up to:
3.\" OpenSSL man3/SSL_CTX_get0_param 99d63d46 Oct 26 13:56:48 2016 -0400
4.\"
5.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
6.\" Copyright (c) 2015 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: September 10 2022 $
53.Dt SSL_SET1_PARAM 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_get0_param ,
57.Nm SSL_get0_param ,
58.Nm SSL_CTX_set1_param ,
59.Nm SSL_set1_param
60.Nd get and set verification parameters
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft X509_VERIFY_PARAM *
64.Fo SSL_CTX_get0_param
65.Fa "SSL_CTX *ctx"
66.Fc
67.Ft X509_VERIFY_PARAM *
68.Fo SSL_get0_param
69.Fa "SSL *ssl"
70.Fc
71.Ft int
72.Fo SSL_CTX_set1_param
73.Fa "SSL_CTX *ctx"
74.Fa "X509_VERIFY_PARAM *vpm"
75.Fc
76.Ft int
77.Fo SSL_set1_param
78.Fa "SSL *ssl"
79.Fa "X509_VERIFY_PARAM *vpm"
80.Fc
81.Sh DESCRIPTION
82.Fn SSL_CTX_get0_param
83and
84.Fn SSL_get0_param
85retrieve an internal pointer to the verification parameters for
86.Fa ctx
87or
88.Fa ssl ,
89respectively.
90The returned pointer must not be freed by the calling application,
91but the application can modify the parameters pointed to,
92to suit its needs: for example to add a hostname check.
93.Pp
94.Fn SSL_CTX_set1_param
95and
96.Fn SSL_set1_param
97set the verification parameters to
98.Fa vpm
99for
100.Fa ctx
101or
102.Fa ssl .
103.Sh RETURN VALUES
104.Fn SSL_CTX_get0_param
105and
106.Fn SSL_get0_param
107return a pointer to an
108.Vt X509_VERIFY_PARAM
109structure.
110.Pp
111.Fn SSL_CTX_set1_param
112and
113.Fn SSL_set1_param
114return 1 for success or 0 for failure.
115.Sh EXAMPLES
116Check that the hostname matches
117.Pa www.foo.com
118in the peer certificate:
119.Bd -literal -offset indent
120X509_VERIFY_PARAM *vpm = SSL_get0_param(ssl);
121X509_VERIFY_PARAM_set1_host(vpm, "www.foo.com", 0);
122.Ed
123.Sh SEE ALSO
124.Xr ssl 3 ,
125.Xr X509_VERIFY_PARAM_set_flags 3
126.Sh HISTORY
127.Fn SSL_CTX_set1_param
128and
129.Fn SSL_set1_param
130first appeared in OpenSSL 1.0.0 and have been available since
131.Ox 4.9 .
132.Pp
133.Fn SSL_CTX_get0_param
134and
135.Fn SSL_get0_param
136first appeared in OpenSSL 1.0.2 and have been available since
137.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_set_SSL_CTX.3 b/src/lib/libssl/man/SSL_set_SSL_CTX.3
deleted file mode 100644
index 2abaefb292..0000000000
--- a/src/lib/libssl/man/SSL_set_SSL_CTX.3
+++ /dev/null
@@ -1,67 +0,0 @@
1.\" $OpenBSD: SSL_set_SSL_CTX.3,v 1.4 2022/07/13 22:05:53 schwarze Exp $
2.\"
3.\" Copyright (c) 2020 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: July 13 2022 $
18.Dt SSL_SET_SSL_CTX 3
19.Os
20.Sh NAME
21.Nm SSL_set_SSL_CTX
22.Nd modify an SSL connection object to use another context
23.Sh SYNOPSIS
24.In openssl/ssl.h
25.Ft SSL_CTX *
26.Fo SSL_set_SSL_CTX
27.Fa "SSL *ssl"
28.Fa "SSL_CTX* ctx"
29.Fc
30.Sh DESCRIPTION
31.Fn SSL_set_SSL_CTX
32causes
33.Fa ssl
34to use the context
35.Fa ctx .
36.Pp
37If
38.Fa ctx
39is
40.Dv NULL ,
41.Fa ssl
42reverts to using the context that it was initially created from with
43.Xr SSL_new 3 .
44.Pp
45If
46.Fa ssl
47already uses
48.Fa ctx ,
49no action occurs.
50.Sh RETURN VALUES
51.Fn SSL_set_SSL_CTX
52returns an internal pointer to the context that
53.Fa ssl
54is using as a result of the call, or
55.Dv NULL
56if memory allocation fails.
57.Sh SEE ALSO
58.Xr ssl 3 ,
59.Xr SSL_clear 3 ,
60.Xr SSL_CTX_new 3 ,
61.Xr SSL_get_SSL_CTX 3 ,
62.Xr SSL_new 3 ,
63.Xr SSL_set_security_level 3
64.Sh HISTORY
65.Fn SSL_set_SSL_CTX
66first appeared in OpenSSL 0.9.8f and has been available since
67.Ox 4.5 .
diff --git a/src/lib/libssl/man/SSL_set_bio.3 b/src/lib/libssl/man/SSL_set_bio.3
deleted file mode 100644
index e727f442d6..0000000000
--- a/src/lib/libssl/man/SSL_set_bio.3
+++ /dev/null
@@ -1,99 +0,0 @@
1.\" $OpenBSD: SSL_set_bio.3,v 1.6 2020/10/08 18:21:30 tb Exp $
2.\" OpenSSL acb5b343 Sep 16 16:00:38 2000 +0000
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: October 8 2020 $
52.Dt SSL_SET_BIO 3
53.Os
54.Sh NAME
55.Nm SSL_set_bio
56.Nd connect the SSL object with a BIO
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft void
60.Fn SSL_set_bio "SSL *ssl" "BIO *rbio" "BIO *wbio"
61.Sh DESCRIPTION
62.Fn SSL_set_bio
63connects the
64.Vt BIO Ns
65s
66.Fa rbio
67and
68.Fa wbio
69for the read and write operations of the TLS/SSL (encrypted) side of
70.Fa ssl .
71.Pp
72The SSL engine inherits the behaviour of
73.Fa rbio
74and
75.Fa wbio ,
76respectively.
77If a
78.Vt BIO
79is non-blocking, the
80.Fa ssl
81will also have non-blocking behaviour.
82.Pp
83If there was already a
84.Vt BIO
85connected to
86.Fa ssl ,
87.Xr BIO_free 3
88will be called (for both the reading and writing side, if different).
89.Sh SEE ALSO
90.Xr BIO_new 3 ,
91.Xr ssl 3 ,
92.Xr SSL_accept 3 ,
93.Xr SSL_connect 3 ,
94.Xr SSL_get_rbio 3 ,
95.Xr SSL_shutdown 3
96.Sh HISTORY
97.Fn SSL_set_bio
98first appeared in SSLeay 0.6.0 and has been available since
99.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_set_connect_state.3 b/src/lib/libssl/man/SSL_set_connect_state.3
deleted file mode 100644
index c2072c4370..0000000000
--- a/src/lib/libssl/man/SSL_set_connect_state.3
+++ /dev/null
@@ -1,153 +0,0 @@
1.\" $OpenBSD: SSL_set_connect_state.3,v 1.6 2018/03/27 17:35:50 schwarze Exp $
2.\" full merge up to OpenSSL 99d63d46 Oct 26 13:56:48 2016 -0400
3.\" selective merge up to: OpenSSL dbd007d7 Jul 28 13:31:27 2017 +0800
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>
6.\" and Paul Yang <yang.yang@baishancloud.com>.
7.\" Copyright (c) 2001, 2017 The OpenSSL Project. All rights reserved.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\"
13.\" 1. Redistributions of source code must retain the above copyright
14.\" notice, this list of conditions and the following disclaimer.
15.\"
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\" notice, this list of conditions and the following disclaimer in
18.\" the documentation and/or other materials provided with the
19.\" distribution.
20.\"
21.\" 3. All advertising materials mentioning features or use of this
22.\" software must display the following acknowledgment:
23.\" "This product includes software developed by the OpenSSL Project
24.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25.\"
26.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27.\" endorse or promote products derived from this software without
28.\" prior written permission. For written permission, please contact
29.\" openssl-core@openssl.org.
30.\"
31.\" 5. Products derived from this software may not be called "OpenSSL"
32.\" nor may "OpenSSL" appear in their names without prior written
33.\" permission of the OpenSSL Project.
34.\"
35.\" 6. Redistributions of any form whatsoever must retain the following
36.\" acknowledgment:
37.\" "This product includes software developed by the OpenSSL Project
38.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39.\"
40.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51.\" OF THE POSSIBILITY OF SUCH DAMAGE.
52.\"
53.Dd $Mdocdate: March 27 2018 $
54.Dt SSL_SET_CONNECT_STATE 3
55.Os
56.Sh NAME
57.Nm SSL_set_connect_state ,
58.Nm SSL_set_accept_state ,
59.Nm SSL_is_server
60.Nd prepare SSL object to work in client or server mode
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft void
64.Fn SSL_set_connect_state "SSL *ssl"
65.Ft void
66.Fn SSL_set_accept_state "SSL *ssl"
67.Ft int
68.Fn SSL_is_server "const SSL *ssl"
69.Sh DESCRIPTION
70.Fn SSL_set_connect_state
71sets
72.Fa ssl
73to work in client mode.
74.Pp
75.Fn SSL_set_accept_state
76sets
77.Fa ssl
78to work in server mode.
79.Pp
80.Fn SSL_is_server
81checks whether
82.Fa ssl
83is set to server mode.
84.Pp
85When the
86.Vt SSL_CTX
87object was created with
88.Xr SSL_CTX_new 3 ,
89it was either assigned a dedicated client method, a dedicated server method, or
90a generic method, that can be used for both client and server connections.
91(The method might have been changed with
92.Xr SSL_CTX_set_ssl_version 3
93or
94.Xr SSL_set_ssl_method 3 . )
95.Pp
96When beginning a new handshake, the SSL engine must know whether it must call
97the connect (client) or accept (server) routines.
98Even though it may be clear from the method chosen whether client or server
99mode was requested, the handshake routines must be explicitly set.
100.Pp
101When using the
102.Xr SSL_connect 3
103or
104.Xr SSL_accept 3
105routines, the correct handshake routines are automatically set.
106When performing a transparent negotiation using
107.Xr SSL_write 3
108or
109.Xr SSL_read 3 ,
110the handshake routines must be explicitly set in advance using either
111.Fn SSL_set_connect_state
112or
113.Fn SSL_set_accept_state .
114.Pp
115If
116.Fn SSL_is_server
117is called before
118.Fn SSL_set_connect_state
119or
120.Fn SSL_set_accept_state
121was called either automatically or explicitly,
122the result depends on what method was used when the
123.Fa SSL_CTX
124was created.
125If a generic method or a dedicated server method was passed to
126.Xr SSL_CTX_new 3 ,
127.Fn SSL_is_server
128returns 1; otherwise, it returns 0.
129.Sh RETURN VALUES
130.Fn SSL_is_server
131returns 1 if
132.Fa ssl
133is set to server mode or 0 if it is set to client mode.
134.Sh SEE ALSO
135.Xr ssl 3 ,
136.Xr SSL_accept 3 ,
137.Xr SSL_connect 3 ,
138.Xr SSL_CTX_new 3 ,
139.Xr SSL_CTX_set_ssl_version 3 ,
140.Xr SSL_do_handshake 3 ,
141.Xr SSL_new 3 ,
142.Xr SSL_read 3 ,
143.Xr SSL_write 3
144.Sh HISTORY
145.Fn SSL_set_connect_state
146and
147.Fn SSL_set_accept_state
148first appeared in SSLeay 0.6.0 and have been available since
149.Ox 2.4 .
150.Pp
151.Fn SSL_is_server
152first appeared in OpenSSL 1.0.2 and has been available since
153.Ox 6.3 .
diff --git a/src/lib/libssl/man/SSL_set_fd.3 b/src/lib/libssl/man/SSL_set_fd.3
deleted file mode 100644
index 7b9727e9ad..0000000000
--- a/src/lib/libssl/man/SSL_set_fd.3
+++ /dev/null
@@ -1,129 +0,0 @@
1.\" $OpenBSD: SSL_set_fd.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2013 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_SET_FD 3
53.Os
54.Sh NAME
55.Nm SSL_set_fd ,
56.Nm SSL_set_rfd ,
57.Nm SSL_set_wfd
58.Nd connect the SSL object with a file descriptor
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft int
62.Fn SSL_set_fd "SSL *ssl" "int fd"
63.Ft int
64.Fn SSL_set_rfd "SSL *ssl" "int fd"
65.Ft int
66.Fn SSL_set_wfd "SSL *ssl" "int fd"
67.Sh DESCRIPTION
68.Fn SSL_set_fd
69sets the file descriptor
70.Fa fd
71as the input/output facility for the TLS/SSL (encrypted) side of
72.Fa ssl .
73.Fa fd
74will typically be the socket file descriptor of a network connection.
75.Pp
76When performing the operation, a socket
77.Vt BIO
78is automatically created to interface between the
79.Fa ssl
80and
81.Fa fd .
82The
83.Vt BIO
84and hence the SSL engine inherit the behaviour of
85.Fa fd .
86If
87.Fa fd
88is non-blocking, the
89.Fa ssl
90will also have non-blocking behaviour.
91.Pp
92If there was already a
93.Vt BIO
94connected to
95.Fa ssl ,
96.Xr BIO_free 3
97will be called (for both the reading and writing side, if different).
98.Pp
99.Fn SSL_set_rfd
100and
101.Fn SSL_set_wfd
102perform the respective action, but only for the read channel or the write
103channel, which can be set independently.
104.Sh RETURN VALUES
105The following return values can occur:
106.Bl -tag -width Ds
107.It 0
108The operation failed.
109Check the error stack to find out why.
110.It 1
111The operation succeeded.
112.El
113.Sh SEE ALSO
114.Xr BIO_new 3 ,
115.Xr ssl 3 ,
116.Xr SSL_accept 3 ,
117.Xr SSL_connect 3 ,
118.Xr SSL_get_fd 3 ,
119.Xr SSL_set_bio 3 ,
120.Xr SSL_shutdown 3
121.Sh HISTORY
122.Fn SSL_set_fd
123appeared in SSLeay 0.4 or earlier.
124.Fn SSL_set_rfd
125and
126.Fn SSL_set_wfd
127first appeared in SSLeay 0.6.0.
128These functions have been available since
129.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_set_max_send_fragment.3 b/src/lib/libssl/man/SSL_set_max_send_fragment.3
deleted file mode 100644
index 7de087a743..0000000000
--- a/src/lib/libssl/man/SSL_set_max_send_fragment.3
+++ /dev/null
@@ -1,97 +0,0 @@
1.\" $OpenBSD: SSL_set_max_send_fragment.3,v 1.5 2019/06/12 09:36:30 schwarze Exp $
2.\" OpenSSL doc/man3/SSL_CTX_set_split_send_fragment.pod
3.\" OpenSSL 6782e5fd Oct 21 16:16:20 2016 +0100
4.\"
5.\" This file was written by Matt Caswell <matt@openssl.org>.
6.\" Copyright (c) 2016 The OpenSSL Project. All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: June 12 2019 $
53.Dt SSL_SET_MAX_SEND_FRAGMENT 3
54.Os
55.Sh NAME
56.Nm SSL_CTX_set_max_send_fragment ,
57.Nm SSL_set_max_send_fragment
58.Nd control fragment sizes
59.Sh SYNOPSIS
60.In openssl/ssl.h
61.Ft long
62.Fo SSL_CTX_set_max_send_fragment
63.Fa "SSL_CTX *ctx"
64.Fa "long m"
65.Fc
66.Ft long
67.Fo SSL_set_max_send_fragment
68.Fa "SSL *ssl"
69.Fa "long m"
70.Fc
71.Sh DESCRIPTION
72.Fn SSL_CTX_set_max_send_fragment
73and
74.Fn SSL_set_max_send_fragment
75set the
76.Sy max_send_fragment
77parameter for SSL_CTX and SSL objects respectively.
78This value restricts the amount of plaintext bytes that will be sent in
79any one SSL/TLS record.
80By default its value is SSL3_RT_MAX_PLAIN_LENGTH (16384).
81These functions will only accept a value in the range 512 -
82SSL3_RT_MAX_PLAIN_LENGTH.
83.Pp
84These functions are implemented using macros.
85.Sh RETURN VALUES
86These functions return 1 on success or 0 on failure.
87.Sh SEE ALSO
88.Xr ssl 3 ,
89.Xr SSL_ctrl 3 ,
90.Xr SSL_CTX_set_read_ahead 3 ,
91.Xr SSL_pending 3
92.Sh HISTORY
93.Fn SSL_CTX_set_max_send_fragment
94and
95.Fn SSL_set_max_send_fragment
96first appeared in OpenSSL 1.0.0 and have been available since
97.Ox 4.9 .
diff --git a/src/lib/libssl/man/SSL_set_psk_use_session_callback.3 b/src/lib/libssl/man/SSL_set_psk_use_session_callback.3
deleted file mode 100644
index 7f2bfcc010..0000000000
--- a/src/lib/libssl/man/SSL_set_psk_use_session_callback.3
+++ /dev/null
@@ -1,86 +0,0 @@
1.\" $OpenBSD: SSL_set_psk_use_session_callback.3,v 1.1 2021/09/14 14:30:57 schwarze Exp $
2.\" OpenSSL man3/SSL_CTX_set_psk_client_callback.pod
3.\" checked up to 24a535ea Sep 22 13:14:20 2020 +0100
4.\"
5.\" Copyright (c) 2021 Ingo Schwarze <schwarze@openbsd.org>
6.\"
7.\" Permission to use, copy, modify, and distribute this software for any
8.\" purpose with or without fee is hereby granted, provided that the above
9.\" copyright notice and this permission notice appear in all copies.
10.\"
11.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18.\"
19.Dd $Mdocdate: September 14 2021 $
20.Dt SSL_SET_PSK_USE_SESSION_CALLBACK 3
21.Os
22.Sh NAME
23.Nm SSL_set_psk_use_session_callback ,
24.Nm SSL_psk_use_session_cb_func
25.Nd set TLS pre-shared key client callback
26.Sh SYNOPSIS
27.In openssl/ssl.h
28.Ft typedef int
29.Fo (*SSL_psk_use_session_cb_func)
30.Fa "SSL *ssl"
31.Fa "const EVP_MD *md"
32.Fa "const unsigned char **id"
33.Fa "size_t *idlen"
34.Fa "SSL_SESSION **session"
35.Fc
36.Ft void
37.Fo SSL_set_psk_use_session_callback
38.Fa "SSL *ssl"
39.Fa "SSL_psk_use_session_cb_func cb"
40.Fc
41.Sh DESCRIPTION
42LibreSSL provides the stub function
43.Fn SSL_set_psk_use_session_callback
44to allow compiling application programs
45that contain optional support for TLSv1.3 pre-shared keys.
46.Pp
47LibreSSL does not support TLS pre-shared keys,
48and no action occurs when
49.Fn SSL_set_psk_use_session_callback
50is called.
51In particular, both arguments are ignored.
52During session negotiation,
53LibreSSL never calls the callback
54.Fa cb
55and always behaves as if that callback succeeded and set the
56.Pf * Fa session
57pointer to
58.Dv NULL .
59That is, LibreSSL never sends a pre-shared key to the server
60and never aborts the handshake for lack of a pre-shared key.
61.Pp
62With OpenSSL, a client application wishing to use TLSv1.3 pre-shared keys
63can install a callback function
64.Fa cb
65using
66.Fn SSL_set_psk_use_session_callback .
67The OpenSSL library may call
68.Fa cb
69once or twice during session negotiation.
70If the callback fails, OpenSSL aborts connection setup.
71If the callback succeeds but sets the
72.Pf * Fa session
73pointer to
74.Dv NULL ,
75OpenSSL continues the handshake
76but does not send a pre-shared key to the server.
77.Sh RETURN VALUES
78The
79.Fn SSL_psk_use_session_cb_func
80callback is expected to return 1 on success or 0 on failure.
81.Sh HISTORY
82.Fn SSL_set_psk_use_session_callback
83and
84.Fn SSL_psk_use_session_cb_func
85first appeared in OpenSSL 1.1.1 and have been available since
86.Ox 7.0 .
diff --git a/src/lib/libssl/man/SSL_set_session.3 b/src/lib/libssl/man/SSL_set_session.3
deleted file mode 100644
index 7d85f5ad0c..0000000000
--- a/src/lib/libssl/man/SSL_set_session.3
+++ /dev/null
@@ -1,119 +0,0 @@
1.\" $OpenBSD: SSL_set_session.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL 05ea606a May 20 20:52:46 2016 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2016 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_SET_SESSION 3
53.Os
54.Sh NAME
55.Nm SSL_set_session
56.Nd set a TLS/SSL session to be used during TLS/SSL connect
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft int
60.Fn SSL_set_session "SSL *ssl" "SSL_SESSION *session"
61.Sh DESCRIPTION
62.Fn SSL_set_session
63sets
64.Fa session
65to be used when the TLS/SSL connection is to be established.
66.Fn SSL_set_session
67is only useful for TLS/SSL clients.
68When the session is set, the reference count of
69.Fa session
70is incremented
71by 1.
72If the session is not reused, the reference count is decremented again during
73.Fn SSL_connect .
74Whether the session was reused can be queried with the
75.Xr SSL_session_reused 3
76call.
77.Pp
78If there is already a session set inside
79.Fa ssl
80(because it was set with
81.Fn SSL_set_session
82before or because the same
83.Fa ssl
84was already used for a connection),
85.Xr SSL_SESSION_free 3
86will be called for that session.
87.Pp
88.Vt SSL_SESSION
89objects keep internal link information about the session cache list when being
90inserted into one
91.Vt SSL_CTX
92object's session cache.
93One
94.Vt SSL_SESSION
95object, regardless of its reference count, must therefore only be used with one
96.Vt SSL_CTX
97object (and the
98.Vt SSL
99objects created from this
100.Vt SSL_CTX
101object).
102.Sh RETURN VALUES
103The following return values can occur:
104.Bl -tag -width Ds
105.It 0
106The operation failed; check the error stack to find out the reason.
107.It 1
108The operation succeeded.
109.El
110.Sh SEE ALSO
111.Xr ssl 3 ,
112.Xr SSL_CTX_set_session_cache_mode 3 ,
113.Xr SSL_get_session 3 ,
114.Xr SSL_SESSION_free 3 ,
115.Xr SSL_session_reused 3
116.Sh HISTORY
117.Fn SSL_set_session
118first appeared in SSLeay 0.5.2 and has been available since
119.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_set_shutdown.3 b/src/lib/libssl/man/SSL_set_shutdown.3
deleted file mode 100644
index ef8c004f76..0000000000
--- a/src/lib/libssl/man/SSL_set_shutdown.3
+++ /dev/null
@@ -1,138 +0,0 @@
1.\" $OpenBSD: SSL_set_shutdown.3,v 1.7 2024/12/19 06:45:21 jmc Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: December 19 2024 $
52.Dt SSL_SET_SHUTDOWN 3
53.Os
54.Sh NAME
55.Nm SSL_set_shutdown ,
56.Nm SSL_get_shutdown
57.Nd manipulate shutdown state of an SSL connection
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft void
61.Fn SSL_set_shutdown "SSL *ssl" "int mode"
62.Ft int
63.Fn SSL_get_shutdown "const SSL *ssl"
64.Sh DESCRIPTION
65.Fn SSL_set_shutdown
66sets the shutdown state of
67.Fa ssl
68to
69.Fa mode .
70.Pp
71.Fn SSL_get_shutdown
72returns the shutdown mode of
73.Fa ssl .
74.Pp
75The shutdown state of an ssl connection is a bitmask of:
76.Bl -tag -width Ds
77.It 0
78No shutdown setting, yet.
79.It Dv SSL_SENT_SHUTDOWN
80A
81.Dq close notify
82shutdown alert was sent to the peer; the connection is being considered closed
83and the session is closed and correct.
84.It Dv SSL_RECEIVED_SHUTDOWN
85A shutdown alert was received from the peer, either a normal
86.Dq close notify
87or a fatal error.
88.El
89.Pp
90.Dv SSL_SENT_SHUTDOWN
91and
92.Dv SSL_RECEIVED_SHUTDOWN
93can be set at the same time.
94.Pp
95The shutdown state of the connection is used to determine the state of the
96.Fa ssl
97session.
98If the session is still open when
99.Xr SSL_clear 3
100or
101.Xr SSL_free 3
102is called, it is considered bad and removed according to RFC 2246.
103The actual condition for a correctly closed session is
104.Dv SSL_SENT_SHUTDOWN
105(according to the TLS RFC, it is acceptable to only send the
106.Dq close notify
107alert but to not wait for the peer's answer when the underlying connection is
108closed).
109.Fn SSL_set_shutdown
110can be used to set this state without sending a close alert to the peer (see
111.Xr SSL_shutdown 3 ) .
112.Pp
113If a
114.Dq close notify
115was received,
116.Dv SSL_RECEIVED_SHUTDOWN
117will be set, but to set
118.Dv SSL_SENT_SHUTDOWN
119the application must still call
120.Xr SSL_shutdown 3
121or
122.Fn SSL_set_shutdown
123itself.
124.Sh RETURN VALUES
125.Fn SSL_get_shutdown
126returns the current setting.
127.Sh SEE ALSO
128.Xr ssl 3 ,
129.Xr SSL_clear 3 ,
130.Xr SSL_CTX_set_quiet_shutdown 3 ,
131.Xr SSL_free 3 ,
132.Xr SSL_shutdown 3
133.Sh HISTORY
134.Fn SSL_set_shutdown
135and
136.Fn SSL_get_shutdown
137first appeared in SSLeay 0.8.0 and have been available since
138.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_set_tmp_ecdh.3 b/src/lib/libssl/man/SSL_set_tmp_ecdh.3
deleted file mode 100644
index 8fd2d9fd5b..0000000000
--- a/src/lib/libssl/man/SSL_set_tmp_ecdh.3
+++ /dev/null
@@ -1,119 +0,0 @@
1.\" $OpenBSD: SSL_set_tmp_ecdh.3,v 1.6 2021/11/30 15:58:08 jsing Exp $
2.\"
3.\" Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
4.\"
5.\" Permission to use, copy, modify, and distribute this software for any
6.\" purpose with or without fee is hereby granted, provided that the above
7.\" copyright notice and this permission notice appear in all copies.
8.\"
9.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16.\"
17.Dd $Mdocdate: November 30 2021 $
18.Dt SSL_SET_TMP_ECDH 3
19.Os
20.Sh NAME
21.Nm SSL_set_tmp_ecdh ,
22.Nm SSL_CTX_set_tmp_ecdh ,
23.Nm SSL_set_ecdh_auto ,
24.Nm SSL_CTX_set_ecdh_auto ,
25.Nm SSL_set_tmp_ecdh_callback ,
26.Nm SSL_CTX_set_tmp_ecdh_callback
27.Nd select a curve for ECDH ephemeral key exchange
28.Sh SYNOPSIS
29.In openssl/ssl.h
30.Ft long
31.Fo SSL_set_tmp_ecdh
32.Fa "SSL *ssl"
33.Fa "EC_KEY *ecdh"
34.Fc
35.Ft long
36.Fo SSL_CTX_set_tmp_ecdh
37.Fa "SSL_CTX *ctx"
38.Fa "EC_KEY *ecdh"
39.Fc
40.Ft long
41.Fo SSL_set_ecdh_auto
42.Fa "SSL *ssl"
43.Fa "int state"
44.Fc
45.Ft long
46.Fo SSL_CTX_set_ecdh_auto
47.Fa "SSL_CTX *ctx"
48.Fa "int state"
49.Fc
50.Ft void
51.Fo SSL_set_tmp_ecdh_callback
52.Fa "SSL *ssl"
53.Fa "EC_KEY *(*ecdh)(SSL *ssl, int is_export, int keylength)"
54.Fc
55.Ft void
56.Fo SSL_CTX_set_tmp_ecdh_callback
57.Fa "SSL_CTX *ctx"
58.Fa "EC_KEY *(*ecdh)(SSL *ssl, int is_export, int keylength)"
59.Fc
60.Sh DESCRIPTION
61Automatic EC curve selection and generation is always enabled in
62LibreSSL, and applications cannot manually provide EC keys for use
63with ECDH key exchange.
64.Pp
65The only remaining effect of
66.Fn SSL_set_tmp_ecdh
67is that the curve of the given
68.Fa ecdh
69key becomes the only curve enabled for the
70.Fa ssl
71connection, so it is equivalent to calling
72.Xr SSL_set1_groups_list 3
73with the same single curve name.
74.Pp
75.Fn SSL_CTX_set_tmp_ecdh
76has the same effect on all connections that will be created from
77.Fa ctx
78in the future.
79.Pp
80The functions
81.Fn SSL_set_ecdh_auto ,
82.Fn SSL_CTX_set_ecdh_auto ,
83.Fn SSL_set_tmp_ecdh_callback ,
84and
85.Fn SSL_CTX_set_tmp_ecdh_callback
86are deprecated and have no effect.
87.Sh RETURN VALUES
88.Fn SSL_set_tmp_ecdh
89and
90.Fn SSL_CTX_set_tmp_ecdh
91return 1 on success or 0 on failure.
92.Pp
93.Fn SSL_set_ecdh_auto ,
94.Fn SSL_CTX_set_ecdh_auto ,
95.Fn SSL_set_tmp_ecdh_callback ,
96and
97.Fn SSL_CTX_set_tmp_ecdh_callback
98always return 1.
99.Sh SEE ALSO
100.Xr ssl 3 ,
101.Xr SSL_CTX_set1_groups 3 ,
102.Xr SSL_CTX_set_cipher_list 3 ,
103.Xr SSL_CTX_set_options 3 ,
104.Xr SSL_CTX_set_tmp_dh_callback 3 ,
105.Xr SSL_new 3
106.Sh HISTORY
107.Fn SSL_set_tmp_ecdh ,
108.Fn SSL_CTX_set_tmp_ecdh ,
109.Fn SSL_set_tmp_ecdh_callback ,
110and
111.Fn SSL_CTX_set_tmp_ecdh_callback
112first appeared in OpenSSL 0.9.8 and have been available since
113.Ox 4.5 .
114.Pp
115.Fn SSL_CTX_set_ecdh_auto
116and
117.Fn SSL_set_ecdh_auto
118first appeared in OpenSSL 1.0.2 and have been available since
119.Ox 5.7 .
diff --git a/src/lib/libssl/man/SSL_set_verify_result.3 b/src/lib/libssl/man/SSL_set_verify_result.3
deleted file mode 100644
index 4b7cc6ec3c..0000000000
--- a/src/lib/libssl/man/SSL_set_verify_result.3
+++ /dev/null
@@ -1,90 +0,0 @@
1.\" $OpenBSD: SSL_set_verify_result.3,v 1.5 2020/03/29 17:05:02 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 29 2020 $
52.Dt SSL_SET_VERIFY_RESULT 3
53.Os
54.Sh NAME
55.Nm SSL_set_verify_result
56.Nd override result of peer certificate verification
57.Sh SYNOPSIS
58.In openssl/ssl.h
59.Ft void
60.Fn SSL_set_verify_result "SSL *ssl" "long verify_result"
61.Sh DESCRIPTION
62.Fn SSL_set_verify_result
63sets
64.Fa verify_result
65of the object
66.Fa ssl
67to be the result of the verification of the X509 certificate presented by the
68peer, if any.
69.Pp
70.Fn SSL_set_verify_result
71overrides the verification result.
72It only changes the verification result of the
73.Fa ssl
74object.
75It does not become part of the established session, so if the session is to be
76reused later, the original value will reappear.
77.Pp
78The valid codes for
79.Fa verify_result
80are documented in
81.Xr openssl 1 .
82.Sh SEE ALSO
83.Xr openssl 1 ,
84.Xr ssl 3 ,
85.Xr SSL_get_peer_certificate 3 ,
86.Xr SSL_get_verify_result 3
87.Sh HISTORY
88.Fn SSL_set_verify_result
89first appeared in SSLeay 0.6.1 and has been available since
90.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_shutdown.3 b/src/lib/libssl/man/SSL_shutdown.3
deleted file mode 100644
index bfb1e91ea7..0000000000
--- a/src/lib/libssl/man/SSL_shutdown.3
+++ /dev/null
@@ -1,253 +0,0 @@
1.\" $OpenBSD: SSL_shutdown.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2000, 2001, 2004, 2014 The OpenSSL Project.
6.\" All rights reserved.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\"
12.\" 1. Redistributions of source code must retain the above copyright
13.\" notice, this list of conditions and the following disclaimer.
14.\"
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\" notice, this list of conditions and the following disclaimer in
17.\" the documentation and/or other materials provided with the
18.\" distribution.
19.\"
20.\" 3. All advertising materials mentioning features or use of this
21.\" software must display the following acknowledgment:
22.\" "This product includes software developed by the OpenSSL Project
23.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24.\"
25.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26.\" endorse or promote products derived from this software without
27.\" prior written permission. For written permission, please contact
28.\" openssl-core@openssl.org.
29.\"
30.\" 5. Products derived from this software may not be called "OpenSSL"
31.\" nor may "OpenSSL" appear in their names without prior written
32.\" permission of the OpenSSL Project.
33.\"
34.\" 6. Redistributions of any form whatsoever must retain the following
35.\" acknowledgment:
36.\" "This product includes software developed by the OpenSSL Project
37.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38.\"
39.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50.\" OF THE POSSIBILITY OF SUCH DAMAGE.
51.\"
52.Dd $Mdocdate: March 27 2018 $
53.Dt SSL_SHUTDOWN 3
54.Os
55.Sh NAME
56.Nm SSL_shutdown
57.Nd shut down a TLS/SSL connection
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft int
61.Fn SSL_shutdown "SSL *ssl"
62.Sh DESCRIPTION
63.Fn SSL_shutdown
64shuts down an active TLS/SSL connection.
65It sends the
66.Dq close notify
67shutdown alert to the peer.
68.Pp
69.Fn SSL_shutdown
70tries to send the
71.Dq close notify
72shutdown alert to the peer.
73Whether the operation succeeds or not, the
74.Dv SSL_SENT_SHUTDOWN
75flag is set and a currently open session is considered closed and good and will
76be kept in the session cache for further reuse.
77.Pp
78The shutdown procedure consists of 2 steps: the sending of the
79.Dq close notify
80shutdown alert and the reception of the peer's
81.Dq close notify
82shutdown alert.
83According to the TLS standard, it is acceptable for an application to only send
84its shutdown alert and then close the underlying connection without waiting for
85the peer's response (this way resources can be saved, as the process can
86already terminate or serve another connection).
87When the underlying connection shall be used for more communications,
88the complete shutdown procedure (bidirectional
89.Dq close notify
90alerts) must be performed, so that the peers stay synchronized.
91.Pp
92.Fn SSL_shutdown
93supports both uni- and bidirectional shutdown by its 2 step behavior.
94.Pp
95When the application is the first party to send the
96.Dq close notify
97alert,
98.Fn SSL_shutdown
99will only send the alert and then set the
100.Dv SSL_SENT_SHUTDOWN
101flag (so that the session is considered good and will be kept in cache).
102.Fn SSL_shutdown
103will then return 0.
104If a unidirectional shutdown is enough
105(the underlying connection shall be closed anyway), this first call to
106.Fn SSL_shutdown
107is sufficient.
108In order to complete the bidirectional shutdown handshake,
109.Fn SSL_shutdown
110must be called again.
111The second call will make
112.Fn SSL_shutdown
113wait for the peer's
114.Dq close notify
115shutdown alert.
116On success, the second call to
117.Fn SSL_shutdown
118will return 1.
119.Pp
120If the peer already sent the
121.Dq close notify
122alert and it was already processed implicitly inside another function
123.Pq Xr SSL_read 3 ,
124the
125.Dv SSL_RECEIVED_SHUTDOWN
126flag is set.
127.Fn SSL_shutdown
128will send the
129.Dq close notify
130alert, set the
131.Dv SSL_SENT_SHUTDOWN
132flag and will immediately return with 1.
133Whether
134.Dv SSL_RECEIVED_SHUTDOWN
135is already set can be checked using the
136.Fn SSL_get_shutdown
137(see also the
138.Xr SSL_set_shutdown 3
139call).
140.Pp
141It is therefore recommended to check the return value of
142.Fn SSL_shutdown
143and call
144.Fn SSL_shutdown
145again, if the bidirectional shutdown is not yet complete (return value of the
146first call is 0).
147.Pp
148The behaviour of
149.Fn SSL_shutdown
150additionally depends on the underlying
151.Vt BIO .
152.Pp
153If the underlying
154.Vt BIO
155is
156.Em blocking ,
157.Fn SSL_shutdown
158will only return once the
159handshake step has been finished or an error occurred.
160.Pp
161If the underlying
162.Vt BIO
163is
164.Em non-blocking ,
165.Fn SSL_shutdown
166will also return when the underlying
167.Vt BIO
168could not satisfy the needs of
169.Fn SSL_shutdown
170to continue the handshake.
171In this case a call to
172.Xr SSL_get_error 3
173with the
174return value of
175.Fn SSL_shutdown
176will yield
177.Dv SSL_ERROR_WANT_READ
178or
179.Dv SSL_ERROR_WANT_WRITE .
180The calling process then must repeat the call after taking appropriate action
181to satisfy the needs of
182.Fn SSL_shutdown .
183The action depends on the underlying
184.Vt BIO .
185When using a non-blocking socket, nothing is to be done, but
186.Xr select 2
187can be used to check for the required condition.
188When using a buffering
189.Vt BIO ,
190like a
191.Vt BIO
192pair, data must be written into or retrieved out of the
193.Vt BIO
194before being able to continue.
195.Pp
196.Fn SSL_shutdown
197can be modified to only set the connection to
198.Dq shutdown
199state but not actually send the
200.Dq close notify
201alert messages; see
202.Xr SSL_CTX_set_quiet_shutdown 3 .
203When
204.Dq quiet shutdown
205is enabled,
206.Fn SSL_shutdown
207will always succeed and return 1.
208.Sh RETURN VALUES
209The following return values can occur:
210.Bl -tag -width Ds
211.It 0
212The shutdown is not yet finished.
213Call
214.Fn SSL_shutdown
215for a second time, if a bidirectional shutdown shall be performed.
216The output of
217.Xr SSL_get_error 3
218may be misleading, as an erroneous
219.Dv SSL_ERROR_SYSCALL
220may be flagged even though no error occurred.
221.It 1
222The shutdown was successfully completed.
223The
224.Dq close notify
225alert was sent and the peer's
226.Dq close notify
227alert was received.
228.It \(mi1
229The shutdown was not successful because a fatal error occurred either
230at the protocol level or a connection failure occurred.
231It can also occur if action is need to continue the operation for non-blocking
232.Vt BIO Ns
233s.
234Call
235.Xr SSL_get_error 3
236with the return value
237.Fa ret
238to find out the reason.
239.El
240.Sh SEE ALSO
241.Xr BIO_new 3 ,
242.Xr ssl 3 ,
243.Xr SSL_accept 3 ,
244.Xr SSL_clear 3 ,
245.Xr SSL_connect 3 ,
246.Xr SSL_CTX_set_quiet_shutdown 3 ,
247.Xr SSL_free 3 ,
248.Xr SSL_get_error 3 ,
249.Xr SSL_set_shutdown 3
250.Sh HISTORY
251.Fn SSL_shutdown
252first appeared in SSLeay 0.8.0 and has been available since
253.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_state_string.3 b/src/lib/libssl/man/SSL_state_string.3
deleted file mode 100644
index 1070335448..0000000000
--- a/src/lib/libssl/man/SSL_state_string.3
+++ /dev/null
@@ -1,110 +0,0 @@
1.\" $OpenBSD: SSL_state_string.3,v 1.4 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_STATE_STRING 3
53.Os
54.Sh NAME
55.Nm SSL_state_string ,
56.Nm SSL_state_string_long
57.Nd get textual description of state of an SSL object
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft const char *
61.Fn SSL_state_string "const SSL *ssl"
62.Ft const char *
63.Fn SSL_state_string_long "const SSL *ssl"
64.Sh DESCRIPTION
65.Fn SSL_state_string
66returns a 6 letter string indicating the current state of the
67.Vt SSL
68object
69.Fa ssl .
70.Pp
71.Fn SSL_state_string_long
72returns a string indicating the current state of the
73.Vt SSL
74object
75.Fa ssl .
76.Pp
77During its use, an
78.Vt SSL
79object passes several states.
80The state is internally maintained.
81Querying the state information is not very informative before or when a
82connection has been established.
83It however can be of significant interest during the handshake.
84.Pp
85When using non-blocking sockets,
86the function call performing the handshake may return with
87.Dv SSL_ERROR_WANT_READ
88or
89.Dv SSL_ERROR_WANT_WRITE
90condition, so that
91.Fn SSL_state_string[_long]
92may be called.
93.Pp
94For both blocking or non-blocking sockets,
95the details state information can be used within the
96.Fn info_callback
97function set with the
98.Xr SSL_set_info_callback 3
99call.
100.Sh RETURN VALUES
101Detailed description of possible states to be included later.
102.Sh SEE ALSO
103.Xr ssl 3 ,
104.Xr SSL_CTX_set_info_callback 3
105.Sh HISTORY
106.Fn SSL_state_string
107and
108.Fn SSL_state_string_long
109first appeared in SSLeay 0.6.0 and have been available since
110.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_want.3 b/src/lib/libssl/man/SSL_want.3
deleted file mode 100644
index 24e8645ba8..0000000000
--- a/src/lib/libssl/man/SSL_want.3
+++ /dev/null
@@ -1,161 +0,0 @@
1.\" $OpenBSD: SSL_want.3,v 1.5 2018/03/27 17:35:50 schwarze Exp $
2.\" OpenSSL 9b86974e Aug 17 15:21:33 2015 -0400
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: March 27 2018 $
52.Dt SSL_WANT 3
53.Os
54.Sh NAME
55.Nm SSL_want ,
56.Nm SSL_want_nothing ,
57.Nm SSL_want_read ,
58.Nm SSL_want_write ,
59.Nm SSL_want_x509_lookup
60.Nd obtain state information TLS/SSL I/O operation
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft int
64.Fn SSL_want "const SSL *ssl"
65.Ft int
66.Fn SSL_want_nothing "const SSL *ssl"
67.Ft int
68.Fn SSL_want_read "const SSL *ssl"
69.Ft int
70.Fn SSL_want_write "const SSL *ssl"
71.Ft int
72.Fn SSL_want_x509_lookup "const SSL *ssl"
73.Sh DESCRIPTION
74.Fn SSL_want
75returns state information for the
76.Vt SSL
77object
78.Fa ssl .
79.Pp
80The other
81.Fn SSL_want_*
82calls are shortcuts for the possible states returned by
83.Fn SSL_want .
84.Pp
85.Fn SSL_want
86examines the internal state information of the
87.Vt SSL
88object.
89Its return values are similar to those of
90.Xr SSL_get_error 3 .
91Unlike
92.Xr SSL_get_error 3 ,
93which also evaluates the error queue,
94the results are obtained by examining an internal state flag only.
95The information must therefore only be used for normal operation under
96non-blocking I/O.
97Error conditions are not handled and must be treated using
98.Xr SSL_get_error 3 .
99.Pp
100The result returned by
101.Fn SSL_want
102should always be consistent with the result of
103.Xr SSL_get_error 3 .
104.Sh RETURN VALUES
105The following return values can currently occur for
106.Fn SSL_want :
107.Bl -tag -width Ds
108.It Dv SSL_NOTHING
109There is no data to be written or to be read.
110.It Dv SSL_WRITING
111There are data in the SSL buffer that must be written to the underlying
112.Vt BIO
113layer in order to complete the actual
114.Fn SSL_*
115operation.
116A call to
117.Xr SSL_get_error 3
118should return
119.Dv SSL_ERROR_WANT_WRITE .
120.It Dv SSL_READING
121More data must be read from the underlying
122.Vt BIO
123layer in order to
124complete the actual
125.Fn SSL_*
126operation.
127A call to
128.Xr SSL_get_error 3
129should return
130.Dv SSL_ERROR_WANT_READ .
131.It Dv SSL_X509_LOOKUP
132The operation did not complete because an application callback set by
133.Xr SSL_CTX_set_client_cert_cb 3
134has asked to be called again.
135A call to
136.Xr SSL_get_error 3
137should return
138.Dv SSL_ERROR_WANT_X509_LOOKUP .
139.El
140.Pp
141.Fn SSL_want_nothing ,
142.Fn SSL_want_read ,
143.Fn SSL_want_write ,
144and
145.Fn SSL_want_x509_lookup
146return 1 when the corresponding condition is true or 0 otherwise.
147.Sh SEE ALSO
148.Xr err 3 ,
149.Xr ssl 3 ,
150.Xr SSL_get_error 3
151.Sh HISTORY
152.Fn SSL_want ,
153.Fn SSL_want_nothing ,
154.Fn SSL_want_read ,
155and
156.Fn SSL_want_write
157first appeared in SSLeay 0.5.2.
158.Fn SSL_want_x509_lookup
159first appeared in SSLeay 0.6.0.
160These functions have been available since
161.Ox 2.4 .
diff --git a/src/lib/libssl/man/SSL_write.3 b/src/lib/libssl/man/SSL_write.3
deleted file mode 100644
index 2c6fbcef08..0000000000
--- a/src/lib/libssl/man/SSL_write.3
+++ /dev/null
@@ -1,249 +0,0 @@
1.\" $OpenBSD: SSL_write.3,v 1.7 2021/10/24 15:10:13 schwarze Exp $
2.\" full merge up to: OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\" partial merge up to: OpenSSL 24a535ea Sep 22 13:14:20 2020 +0100
4.\"
5.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>
6.\" and Matt Caswell <matt@openssl.org>.
7.\" Copyright (c) 2000, 2001, 2002, 2016 The OpenSSL Project.
8.\" All rights reserved.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\"
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\"
17.\" 2. Redistributions in binary form must reproduce the above copyright
18.\" notice, this list of conditions and the following disclaimer in
19.\" the documentation and/or other materials provided with the
20.\" distribution.
21.\"
22.\" 3. All advertising materials mentioning features or use of this
23.\" software must display the following acknowledgment:
24.\" "This product includes software developed by the OpenSSL Project
25.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26.\"
27.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28.\" endorse or promote products derived from this software without
29.\" prior written permission. For written permission, please contact
30.\" openssl-core@openssl.org.
31.\"
32.\" 5. Products derived from this software may not be called "OpenSSL"
33.\" nor may "OpenSSL" appear in their names without prior written
34.\" permission of the OpenSSL Project.
35.\"
36.\" 6. Redistributions of any form whatsoever must retain the following
37.\" acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40.\"
41.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
53.\"
54.Dd $Mdocdate: October 24 2021 $
55.Dt SSL_WRITE 3
56.Os
57.Sh NAME
58.Nm SSL_write_ex ,
59.Nm SSL_write
60.Nd write bytes to a TLS connection
61.Sh SYNOPSIS
62.In openssl/ssl.h
63.Ft int
64.Fn SSL_write_ex "SSL *ssl" "const void *buf" "size_t num" "size_t *written"
65.Ft int
66.Fn SSL_write "SSL *ssl" "const void *buf" "int num"
67.Sh DESCRIPTION
68.Fn SSL_write_ex
69and
70.Fn SSL_write
71write
72.Fa num
73bytes from the buffer
74.Fa buf
75into the specified
76.Fa ssl
77connection.
78On success
79.Fn SSL_write_ex
80stores the number of bytes written in
81.Pf * Fa written .
82.Pp
83In the following,
84.Fn SSL_write_ex
85and
86.Fn SSL_write
87are called
88.Dq write functions .
89.Pp
90If necessary, a write function negotiates a TLS session,
91if not already explicitly performed by
92.Xr SSL_connect 3
93or
94.Xr SSL_accept 3 .
95If the peer requests a re-negotiation,
96it will be performed transparently during the
97write function operation.
98The behaviour of the write functions depends on the underlying
99.Vt BIO .
100.Pp
101For the transparent negotiation to succeed, the
102.Fa ssl
103must have been initialized to client or server mode.
104This is done by calling
105.Xr SSL_set_connect_state 3
106or
107.Xr SSL_set_accept_state 3
108before the first call to a write function.
109.Pp
110If the underlying
111.Vt BIO
112is
113.Em blocking ,
114the write function
115will only return once the write operation has been finished or an error
116occurred, except when a renegotiation takes place, in which case a
117.Dv SSL_ERROR_WANT_READ
118may occur.
119This behaviour can be controlled with the
120.Dv SSL_MODE_AUTO_RETRY
121flag of the
122.Xr SSL_CTX_set_mode 3
123call.
124.Pp
125If the underlying
126.Vt BIO
127is
128.Em non-blocking ,
129the write function will also return when the underlying
130.Vt BIO
131could not satisfy the needs of the function to continue the operation.
132In this case a call to
133.Xr SSL_get_error 3
134with the return value of the write function will yield
135.Dv SSL_ERROR_WANT_READ
136or
137.Dv SSL_ERROR_WANT_WRITE .
138As at any time a re-negotiation is possible, a call to
139a write function can also cause read operations.
140The calling process then must repeat the call after taking appropriate action
141to satisfy the needs of the write function.
142The action depends on the underlying
143.Vt BIO .
144When using a non-blocking socket, nothing is to be done, but
145.Xr select 2
146can be used to check for the required condition.
147When using a buffering
148.Vt BIO ,
149like a
150.Vt BIO
151pair, data must be written into or retrieved out of the BIO before being able
152to continue.
153.Pp
154The write functions
155will only return with success when the complete contents of
156.Fa buf
157of length
158.Fa num
159have been written.
160This default behaviour can be changed with the
161.Dv SSL_MODE_ENABLE_PARTIAL_WRITE
162option of
163.Xr SSL_CTX_set_mode 3 .
164When this flag is set, the write functions will also return with
165success when a partial write has been successfully completed.
166In this case the write function operation is considered completed.
167The bytes are sent and a new write call with a new buffer (with the
168already sent bytes removed) must be started.
169A partial write is performed with the size of a message block,
170which is 16kB.
171.Pp
172When a write function call has to be repeated because
173.Xr SSL_get_error 3
174returned
175.Dv SSL_ERROR_WANT_READ
176or
177.Dv SSL_ERROR_WANT_WRITE ,
178it must be repeated with the same arguments.
179.Pp
180When calling
181.Fn SSL_write
182with
183.Fa num Ns =0
184bytes to be sent, the behaviour is undefined.
185.Fn SSL_write_ex
186can be called with
187.Fa num Ns =0 ,
188but will not send application data to the peer.
189.Sh RETURN VALUES
190.Fn SSL_write_ex
191returns 1 for success or 0 for failure.
192Success means that all requested application data bytes have been
193written to the TLS connection or, if
194.Dv SSL_MODE_ENABLE_PARTIAL_WRITE
195is in use, at least one application data byte has been written
196to the TLS connection.
197Failure means that not all the requested bytes have been written yet (if
198.Dv SSL_MODE_ENABLE_PARTIAL_WRITE
199is not in use) or no bytes could be written to the TLS connection (if
200.Dv SSL_MODE_ENABLE_PARTIAL_WRITE
201is in use).
202Failures can be retryable (e.g. the network write buffer has temporarily
203filled up) or non-retryable (e.g. a fatal network error).
204In the event of a failure, call
205.Xr SSL_get_error 3
206to find out the reason
207which indicates whether the call is retryable or not.
208.Pp
209For
210.Fn SSL_write ,
211the following return values can occur:
212.Bl -tag -width Ds
213.It >0
214The write operation was successful.
215The return value is the number of bytes actually written to the TLS
216connection.
217.It 0
218The write operation was not successful.
219Probably the underlying connection was closed.
220Call
221.Xr SSL_get_error 3
222with the return value to find out whether an error occurred or the connection
223was shut down cleanly
224.Pq Dv SSL_ERROR_ZERO_RETURN .
225.It <0
226The write operation was not successful, because either an error occurred or
227action must be taken by the calling process.
228Call
229.Xr SSL_get_error 3
230with the return value to find out the reason.
231.El
232.Sh SEE ALSO
233.Xr BIO_new 3 ,
234.Xr ssl 3 ,
235.Xr SSL_accept 3 ,
236.Xr SSL_connect 3 ,
237.Xr SSL_CTX_new 3 ,
238.Xr SSL_CTX_set_mode 3 ,
239.Xr SSL_get_error 3 ,
240.Xr SSL_read 3 ,
241.Xr SSL_set_connect_state 3
242.Sh HISTORY
243.Fn SSL_write
244appeared in SSLeay 0.4 or earlier and has been available since
245.Ox 2.4 .
246.Pp
247.Fn SSL_write_ex
248first appeared in OpenSSL 1.1.1 and has been available since
249.Ox 7.1 .
diff --git a/src/lib/libssl/man/d2i_SSL_SESSION.3 b/src/lib/libssl/man/d2i_SSL_SESSION.3
deleted file mode 100644
index 7a2bc529ab..0000000000
--- a/src/lib/libssl/man/d2i_SSL_SESSION.3
+++ /dev/null
@@ -1,181 +0,0 @@
1.\" $OpenBSD: d2i_SSL_SESSION.3,v 1.7 2019/06/08 15:25:43 schwarze Exp $
2.\" OpenSSL b97fdb57 Nov 11 09:33:09 2016 +0100
3.\"
4.\" This file was written by Lutz Jaenicke <jaenicke@openssl.org>.
5.\" Copyright (c) 2001, 2005, 2014 The OpenSSL Project. All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\" notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\" notice, this list of conditions and the following disclaimer in
16.\" the documentation and/or other materials provided with the
17.\" distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\" software must display the following acknowledgment:
21.\" "This product includes software developed by the OpenSSL Project
22.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\" endorse or promote products derived from this software without
26.\" prior written permission. For written permission, please contact
27.\" openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\" nor may "OpenSSL" appear in their names without prior written
31.\" permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\" acknowledgment:
35.\" "This product includes software developed by the OpenSSL Project
36.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: June 8 2019 $
52.Dt D2I_SSL_SESSION 3
53.Os
54.Sh NAME
55.Nm d2i_SSL_SESSION ,
56.Nm i2d_SSL_SESSION
57.Nd convert SSL_SESSION object from/to ASN1 representation
58.Sh SYNOPSIS
59.In openssl/ssl.h
60.Ft SSL_SESSION *
61.Fn d2i_SSL_SESSION "SSL_SESSION **a" "const unsigned char **pp" "long length"
62.Ft int
63.Fn i2d_SSL_SESSION "SSL_SESSION *in" "unsigned char **pp"
64.Sh DESCRIPTION
65.Fn d2i_SSL_SESSION
66transforms the external ASN1 representation of an SSL/TLS session,
67stored as binary data at location
68.Fa pp
69with length
70.Fa length ,
71into
72an
73.Vt SSL_SESSION
74object.
75.Pp
76.Fn i2d_SSL_SESSION
77transforms the
78.Vt SSL_SESSION
79object
80.Fa in
81into the ASN1 representation and stores it into the memory location pointed to
82by
83.Fa pp .
84The length of the resulting ASN1 representation is returned.
85If
86.Fa pp
87is the
88.Dv NULL
89pointer, only the length is calculated and returned.
90.Pp
91The
92.Vt SSL_SESSION
93object is built from several
94.Xr malloc 3 Ns
95-ed parts; it can therefore not be moved, copied or stored directly.
96In order to store session data on disk or into a database,
97it must be transformed into a binary ASN1 representation.
98.Pp
99When using
100.Fn d2i_SSL_SESSION ,
101the
102.Vt SSL_SESSION
103object is automatically allocated.
104The reference count is 1, so that the session must be explicitly removed using
105.Xr SSL_SESSION_free 3 ,
106unless the
107.Vt SSL_SESSION
108object is completely taken over, when being called inside the
109.Fn get_session_cb ,
110see
111.Xr SSL_CTX_sess_set_get_cb 3 .
112.Pp
113.Vt SSL_SESSION
114objects keep internal link information about the session cache list when being
115inserted into one
116.Vt SSL_CTX
117object's session cache.
118One
119.Vt SSL_SESSION
120object, regardless of its reference count, must therefore only be used with one
121.Vt SSL_CTX
122object (and the
123.Vt SSL
124objects created from this
125.Vt SSL_CTX
126object).
127.Pp
128When using
129.Fn i2d_SSL_SESSION ,
130the memory location pointed to by
131.Fa pp
132must be large enough to hold the binary representation of the session.
133There is no known limit on the size of the created ASN1 representation,
134so call
135.Fn i2d_SSL_SESSION
136first with
137.Fa pp Ns = Ns Dv NULL
138to obtain the encoded size, before allocating the required amount of memory and
139calling
140.Fn i2d_SSL_SESSION
141again.
142Note that this will advance the value contained in
143.Fa *pp
144so it is necessary to save a copy of the original allocation.
145For example:
146.Bd -literal -offset indent
147char *p, *pp;
148int elen, len;
149
150elen = i2d_SSL_SESSION(sess, NULL);
151p = pp = malloc(elen);
152if (p != NULL) {
153 len = i2d_SSL_SESSION(sess, &pp);
154 assert(elen == len);
155 assert(p + len == pp);
156}
157.Ed
158.Sh RETURN VALUES
159.Fn d2i_SSL_SESSION
160returns a pointer to the newly allocated
161.Vt SSL_SESSION
162object.
163In case of failure a
164.Dv NULL
165pointer is returned and the error message can be retrieved from the error
166stack.
167.Pp
168.Fn i2d_SSL_SESSION
169returns the size of the ASN1 representation in bytes.
170When the session is not valid, 0 is returned and no operation is performed.
171.Sh SEE ALSO
172.Xr d2i_X509 3 ,
173.Xr ssl 3 ,
174.Xr SSL_CTX_sess_set_get_cb 3 ,
175.Xr SSL_SESSION_free 3
176.Sh HISTORY
177.Fn d2i_SSL_SESSION
178and
179.Fn i2d_SSL_SESSION
180first appeared in SSLeay 0.5.2 and have been available since
181.Ox 2.4 .
diff --git a/src/lib/libssl/man/ssl.3 b/src/lib/libssl/man/ssl.3
deleted file mode 100644
index 314a1b0a94..0000000000
--- a/src/lib/libssl/man/ssl.3
+++ /dev/null
@@ -1,353 +0,0 @@
1.\" $OpenBSD: ssl.3,v 1.26 2024/08/31 10:51:48 tb Exp $
2.\" full merge up to: OpenSSL e330f55d Nov 11 00:51:04 2016 +0100
3.\" selective merge up to: OpenSSL 322755cc Sep 1 08:40:51 2018 +0800
4.\"
5.\" This file was written by Ralf S. Engelschall <rse@openssl.org>,
6.\" Ben Laurie <ben@openssl.org>, and Ulf Moeller <ulf@openssl.org>.
7.\" Copyright (c) 1998-2002, 2005, 2013, 2015 The OpenSSL Project.
8.\" All rights reserved.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\"
14.\" 1. Redistributions of source code must retain the above copyright
15.\" notice, this list of conditions and the following disclaimer.
16.\"
17.\" 2. Redistributions in binary form must reproduce the above copyright
18.\" notice, this list of conditions and the following disclaimer in
19.\" the documentation and/or other materials provided with the
20.\" distribution.
21.\"
22.\" 3. All advertising materials mentioning features or use of this
23.\" software must display the following acknowledgment:
24.\" "This product includes software developed by the OpenSSL Project
25.\" for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26.\"
27.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28.\" endorse or promote products derived from this software without
29.\" prior written permission. For written permission, please contact
30.\" openssl-core@openssl.org.
31.\"
32.\" 5. Products derived from this software may not be called "OpenSSL"
33.\" nor may "OpenSSL" appear in their names without prior written
34.\" permission of the OpenSSL Project.
35.\"
36.\" 6. Redistributions of any form whatsoever must retain the following
37.\" acknowledgment:
38.\" "This product includes software developed by the OpenSSL Project
39.\" for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40.\"
41.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52.\" OF THE POSSIBILITY OF SUCH DAMAGE.
53.\"
54.Dd $Mdocdate: August 31 2024 $
55.Dt SSL 3
56.Os
57.Sh NAME
58.Nm ssl
59.Nd OpenSSL TLS library
60.Sh DESCRIPTION
61The
62.Nm ssl
63library implements the Transport Layer Security (TLS) protocol,
64the successor to the Secure Sockets Layer (SSL) protocol.
65.Pp
66An
67.Vt SSL_CTX
68object is created as a framework to establish TLS/SSL enabled connections (see
69.Xr SSL_CTX_new 3 ) .
70Various options regarding certificates, algorithms, etc., can be set in this
71object.
72.Pp
73When a network connection has been created, it can be assigned to an
74.Vt SSL
75object.
76After the
77.Vt SSL
78object has been created using
79.Xr SSL_new 3 ,
80.Xr SSL_set_fd 3
81or
82.Xr SSL_set_bio 3
83can be used to associate the network connection with the object.
84.Pp
85Then the TLS/SSL handshake is performed using
86.Xr SSL_accept 3
87or
88.Xr SSL_connect 3
89respectively.
90.Xr SSL_read 3
91and
92.Xr SSL_write 3
93are used to read and write data on the TLS/SSL connection.
94.Xr SSL_shutdown 3
95can be used to shut down the TLS/SSL connection.
96.Sh DATA STRUCTURES
97Currently the
98.Nm ssl
99library functions deal with the following data structures:
100.Bl -tag -width Ds
101.It Vt SSL_METHOD No (SSL Method)
102That's a dispatch structure describing the internal
103.Nm ssl
104library methods/functions which implement the various protocol versions.
105It's needed to create an
106.Vt SSL_CTX .
107See
108.Xr TLS_method 3
109for constructors.
110.It Vt SSL_CIPHER No (SSL Cipher)
111This structure holds the algorithm information for a particular cipher which
112is a core part of the SSL/TLS protocol.
113The available ciphers are configured on an
114.Vt SSL_CTX
115basis and the actually used ones are then part of the
116.Vt SSL_SESSION .
117.It Vt SSL_CTX No (SSL Context)
118That's the global context structure which is created by a server or client
119once per program lifetime and which holds mainly default values for the
120.Vt SSL
121structures which are later created for the connections.
122.It Vt SSL_SESSION No (SSL Session)
123This is a structure containing the current TLS/SSL session details for a
124connection:
125.Vt SSL_CIPHER Ns s ,
126client and server certificates, keys, etc.
127.It Vt SSL No (SSL Connection)
128That's the main SSL/TLS structure which is created by a server or client per
129established connection.
130This actually is the core structure in the SSL API.
131At run-time the application usually deals with this structure which has
132links to mostly all other structures.
133.El
134.Sh HEADER FILES
135Currently the
136.Nm ssl
137library provides the following C header files containing the prototypes for the
138data structures and functions:
139.Bl -tag -width Ds
140.It Pa ssl.h
141That's the common header file for the SSL/TLS API.
142Include it into your program to make the API of the
143.Nm ssl
144library available.
145It internally includes both more private SSL headers and headers from the
146.Em crypto
147library.
148Whenever you need hardcore details on the internals of the SSL API, look inside
149this header file.
150.It Pa ssl3.h
151That's the sub header file dealing with the SSLv3 protocol only.
152.Bf Em
153Usually you don't have to include it explicitly because it's already included
154by
155.Pa ssl.h .
156.Ef
157.It Pa tls1.h
158That's the sub header file dealing with the TLSv1 protocol only.
159.Bf Em
160Usually you don't have to include it explicitly because it's already included
161by
162.Pa ssl.h .
163.Ef
164.El
165.Sh API FUNCTIONS
166.Ss Ciphers
167The following pages describe functions acting on
168.Vt SSL_CIPHER
169objects:
170.Xr SSL_get_ciphers 3 ,
171.Xr SSL_get_current_cipher 3 ,
172.Xr SSL_CIPHER_get_name 3
173.Ss Protocol contexts
174The following pages describe functions acting on
175.Vt SSL_CTX
176objects.
177.Pp
178Constructors and destructors:
179.Xr SSL_CTX_new 3 ,
180.Xr SSL_CTX_set_ssl_version 3 ,
181.Xr SSL_CTX_free 3
182.Pp
183Certificate configuration:
184.Xr SSL_CTX_add_extra_chain_cert 3 ,
185.Xr SSL_CTX_get0_certificate 3 ,
186.Xr SSL_CTX_load_verify_locations 3 ,
187.Xr SSL_CTX_set_cert_store 3 ,
188.Xr SSL_CTX_set_cert_verify_callback 3 ,
189.Xr SSL_CTX_set_client_cert_cb 3 ,
190.Xr SSL_CTX_set_default_passwd_cb 3 ,
191.Xr SSL_CTX_set_tlsext_status_cb 3
192.Pp
193Session configuration:
194.Xr SSL_CTX_add_session 3 ,
195.Xr SSL_CTX_flush_sessions 3 ,
196.Xr SSL_CTX_sess_number 3 ,
197.Xr SSL_CTX_sess_set_cache_size 3 ,
198.Xr SSL_CTX_sess_set_get_cb 3 ,
199.Xr SSL_CTX_sessions 3 ,
200.Xr SSL_CTX_set_session_cache_mode 3 ,
201.Xr SSL_CTX_set_timeout 3 ,
202.Xr SSL_CTX_set_tlsext_ticket_key_cb 3
203.Pp
204Various configuration:
205.Xr SSL_CTX_get_ex_new_index 3 ,
206.Xr SSL_CTX_set_tlsext_servername_callback 3
207.Ss Common configuration of contexts and connections
208The functions on the following pages each come in two variants:
209one to directly configure a single
210.Vt SSL
211connection and another to be called on an
212.Vt SSL_CTX
213object, to set up defaults for all future
214.Vt SSL
215connections created from that context.
216.Pp
217Protocol and algorithm configuration:
218.Xr SSL_CTX_set_alpn_select_cb 3 ,
219.Xr SSL_CTX_set_cipher_list 3 ,
220.Xr SSL_CTX_set_min_proto_version 3 ,
221.Xr SSL_CTX_set_options 3 ,
222.Xr SSL_CTX_set_security_level 3 ,
223.Xr SSL_CTX_set_tlsext_use_srtp 3 ,
224.Xr SSL_CTX_set_tmp_dh_callback 3 ,
225.Xr SSL_CTX_set1_groups 3
226.Pp
227Certificate configuration:
228.Xr SSL_CTX_add1_chain_cert 3 ,
229.Xr SSL_CTX_get_verify_mode 3 ,
230.Xr SSL_CTX_set_client_CA_list 3 ,
231.Xr SSL_CTX_set_max_cert_list 3 ,
232.Xr SSL_CTX_set_verify 3 ,
233.Xr SSL_CTX_use_certificate 3 ,
234.Xr SSL_get_client_CA_list 3
235.Xr SSL_set1_param 3
236.Pp
237Session configuration:
238.Xr SSL_CTX_set_generate_session_id 3 ,
239.Xr SSL_CTX_set_session_id_context 3
240.Pp
241Various configuration:
242.Xr SSL_CTX_ctrl 3 ,
243.Xr SSL_CTX_set_info_callback 3 ,
244.Xr SSL_CTX_set_mode 3 ,
245.Xr SSL_CTX_set_msg_callback 3 ,
246.Xr SSL_CTX_set_quiet_shutdown 3 ,
247.Xr SSL_CTX_set_read_ahead 3 ,
248.Xr SSL_set_max_send_fragment 3
249.Ss Sessions
250The following pages describe functions acting on
251.Vt SSL_SESSION
252objects.
253.Pp
254Constructors and destructors:
255.Xr SSL_SESSION_new 3 ,
256.Xr SSL_SESSION_free 3
257.Pp
258Accessors:
259.Xr SSL_SESSION_get_compress_id 3 ,
260.Xr SSL_SESSION_get_ex_new_index 3 ,
261.Xr SSL_SESSION_get_id 3 ,
262.Xr SSL_SESSION_get_protocol_version 3 ,
263.Xr SSL_SESSION_get_time 3 ,
264.Xr SSL_SESSION_get0_peer 3 ,
265.Xr SSL_SESSION_has_ticket 3 ,
266.Xr SSL_SESSION_set1_id_context 3
267.Pp
268Encoding and decoding:
269.Xr d2i_SSL_SESSION 3 ,
270.Xr PEM_read_SSL_SESSION 3 ,
271.Xr SSL_SESSION_print 3
272.Ss Connections
273The following pages describe functions acting on
274.Vt SSL
275connection objects:
276.Pp
277Constructors and destructors:
278.Xr SSL_new 3 ,
279.Xr SSL_dup 3 ,
280.Xr SSL_free 3 ,
281.Xr BIO_f_ssl 3
282.Pp
283To change the configuration:
284.Xr SSL_clear 3 ,
285.Xr SSL_set_SSL_CTX 3 ,
286.Xr SSL_copy_session_id 3 ,
287.Xr SSL_set_bio 3 ,
288.Xr SSL_set_connect_state 3 ,
289.Xr SSL_set_fd 3 ,
290.Xr SSL_set_session 3 ,
291.Xr SSL_set1_host 3 ,
292.Xr SSL_set_verify_result 3
293.Pp
294To inspect the configuration:
295.Xr SSL_get_certificate 3 ,
296.Xr SSL_get_default_timeout 3 ,
297.Xr SSL_get_ex_new_index 3 ,
298.Xr SSL_get_fd 3 ,
299.Xr SSL_get_rbio 3 ,
300.Xr SSL_get_SSL_CTX 3
301.Pp
302To transmit data:
303.Xr DTLSv1_listen 3 ,
304.Xr SSL_accept 3 ,
305.Xr SSL_connect 3 ,
306.Xr SSL_do_handshake 3 ,
307.Xr SSL_read 3 ,
308.Xr SSL_read_early_data 3 ,
309.Xr SSL_renegotiate 3 ,
310.Xr SSL_shutdown 3 ,
311.Xr SSL_write 3
312.Pp
313To inspect the state after a connection is established:
314.Xr SSL_export_keying_material 3 ,
315.Xr SSL_get_client_random 3 ,
316.Xr SSL_get_ex_data_X509_STORE_CTX_idx 3 ,
317.Xr SSL_get_peer_cert_chain 3 ,
318.Xr SSL_get_peer_certificate 3 ,
319.Xr SSL_get_server_tmp_key 3 ,
320.Xr SSL_get_servername 3 ,
321.Xr SSL_get_session 3 ,
322.Xr SSL_get_shared_ciphers 3 ,
323.Xr SSL_get_verify_result 3 ,
324.Xr SSL_get_version 3 ,
325.Xr SSL_session_reused 3
326.Pp
327To inspect the state during ongoing communication:
328.Xr SSL_get_error 3 ,
329.Xr SSL_get_shutdown 3 ,
330.Xr SSL_get_state 3 ,
331.Xr SSL_num_renegotiations 3 ,
332.Xr SSL_pending 3 ,
333.Xr SSL_rstate_string 3 ,
334.Xr SSL_state_string 3 ,
335.Xr SSL_want 3
336.Ss Utility functions
337.Xr SSL_alert_type_string 3 ,
338.Xr SSL_dup_CA_list 3 ,
339.Xr SSL_load_client_CA_file 3
340.Ss Obsolete functions
341.Xr OPENSSL_init_ssl 3 ,
342.Xr SSL_COMP_get_compression_methods 3 ,
343.Xr SSL_CTX_set_tmp_rsa_callback 3 ,
344.Xr SSL_library_init 3 ,
345.Xr SSL_set_tmp_ecdh 3
346.Sh SEE ALSO
347.Xr openssl 1 ,
348.Xr crypto 3 ,
349.Xr tls_init 3
350.Sh HISTORY
351The
352.Nm
353document appeared in OpenSSL 0.9.2.
diff --git a/src/lib/libssl/pqueue.c b/src/lib/libssl/pqueue.c
deleted file mode 100644
index 602969deb0..0000000000
--- a/src/lib/libssl/pqueue.c
+++ /dev/null
@@ -1,201 +0,0 @@
1/* $OpenBSD: pqueue.c,v 1.5 2014/06/12 15:49:31 deraadt Exp $ */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <stdlib.h>
61#include <string.h>
62
63#include "pqueue.h"
64
65typedef struct _pqueue {
66 pitem *items;
67 int count;
68} pqueue_s;
69
70pitem *
71pitem_new(unsigned char *prio64be, void *data)
72{
73 pitem *item = malloc(sizeof(pitem));
74
75 if (item == NULL)
76 return NULL;
77
78 memcpy(item->priority, prio64be, sizeof(item->priority));
79
80 item->data = data;
81 item->next = NULL;
82
83 return item;
84}
85
86void
87pitem_free(pitem *item)
88{
89 free(item);
90}
91
92pqueue_s *
93pqueue_new(void)
94{
95 return calloc(1, sizeof(pqueue_s));
96}
97
98void
99pqueue_free(pqueue_s *pq)
100{
101 free(pq);
102}
103
104pitem *
105pqueue_insert(pqueue_s *pq, pitem *item)
106{
107 pitem *curr, *next;
108
109 if (pq->items == NULL) {
110 pq->items = item;
111 return item;
112 }
113
114 for (curr = NULL, next = pq->items; next != NULL;
115 curr = next, next = next->next) {
116 /* we can compare 64-bit value in big-endian encoding
117 * with memcmp:-) */
118 int cmp = memcmp(next->priority, item->priority,
119 sizeof(item->priority));
120 if (cmp > 0) { /* next > item */
121 item->next = next;
122
123 if (curr == NULL)
124 pq->items = item;
125 else
126 curr->next = item;
127
128 return item;
129 } else if (cmp == 0) /* duplicates not allowed */
130 return NULL;
131 }
132
133 item->next = NULL;
134 curr->next = item;
135
136 return item;
137}
138
139pitem *
140pqueue_peek(pqueue_s *pq)
141{
142 return pq->items;
143}
144
145pitem *
146pqueue_pop(pqueue_s *pq)
147{
148 pitem *item = pq->items;
149
150 if (pq->items != NULL)
151 pq->items = pq->items->next;
152
153 return item;
154}
155
156pitem *
157pqueue_find(pqueue_s *pq, unsigned char *prio64be)
158{
159 pitem *next;
160
161 for (next = pq->items; next != NULL; next = next->next)
162 if (memcmp(next->priority, prio64be,
163 sizeof(next->priority)) == 0)
164 return next;
165
166 return NULL;
167}
168
169pitem *
170pqueue_iterator(pqueue_s *pq)
171{
172 return pqueue_peek(pq);
173}
174
175pitem *
176pqueue_next(pitem **item)
177{
178 pitem *ret;
179
180 if (item == NULL || *item == NULL)
181 return NULL;
182
183 /* *item != NULL */
184 ret = *item;
185 *item = (*item)->next;
186
187 return ret;
188}
189
190int
191pqueue_size(pqueue_s *pq)
192{
193 pitem *item = pq->items;
194 int count = 0;
195
196 while (item != NULL) {
197 count++;
198 item = item->next;
199 }
200 return count;
201}
diff --git a/src/lib/libssl/pqueue.h b/src/lib/libssl/pqueue.h
deleted file mode 100644
index cdda4a3961..0000000000
--- a/src/lib/libssl/pqueue.h
+++ /dev/null
@@ -1,93 +0,0 @@
1/* $OpenBSD: pqueue.h,v 1.4 2016/11/04 18:28:58 guenther Exp $ */
2
3/*
4 * DTLS implementation written by Nagendra Modadugu
5 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
6 */
7/* ====================================================================
8 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this
23 * software must display the following acknowledgment:
24 * "This product includes software developed by the OpenSSL Project
25 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 *
27 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28 * endorse or promote products derived from this software without
29 * prior written permission. For written permission, please contact
30 * openssl-core@OpenSSL.org.
31 *
32 * 5. Products derived from this software may not be called "OpenSSL"
33 * nor may "OpenSSL" appear in their names without prior written
34 * permission of the OpenSSL Project.
35 *
36 * 6. Redistributions of any form whatsoever must retain the following
37 * acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This product includes cryptographic software written by Eric Young
56 * (eay@cryptsoft.com). This product includes software written by Tim
57 * Hudson (tjh@cryptsoft.com).
58 *
59 */
60
61#ifndef HEADER_PQUEUE_H
62#define HEADER_PQUEUE_H
63
64__BEGIN_HIDDEN_DECLS
65
66typedef struct _pqueue *pqueue;
67
68typedef struct _pitem {
69 unsigned char priority[8]; /* 64-bit value in big-endian encoding */
70 void *data;
71 struct _pitem *next;
72} pitem;
73
74typedef struct _pitem *piterator;
75
76pitem *pitem_new(unsigned char *prio64be, void *data);
77void pitem_free(pitem *item);
78
79pqueue pqueue_new(void);
80void pqueue_free(pqueue pq);
81
82pitem *pqueue_insert(pqueue pq, pitem *item);
83pitem *pqueue_peek(pqueue pq);
84pitem *pqueue_pop(pqueue pq);
85pitem *pqueue_find(pqueue pq, unsigned char *prio64be);
86pitem *pqueue_iterator(pqueue pq);
87pitem *pqueue_next(piterator *iter);
88
89int pqueue_size(pqueue pq);
90
91__END_HIDDEN_DECLS
92
93#endif /* ! HEADER_PQUEUE_H */
diff --git a/src/lib/libssl/s3_cbc.c b/src/lib/libssl/s3_cbc.c
deleted file mode 100644
index 32b7460870..0000000000
--- a/src/lib/libssl/s3_cbc.c
+++ /dev/null
@@ -1,628 +0,0 @@
1/* $OpenBSD: s3_cbc.c,v 1.26 2022/11/26 16:08:55 tb Exp $ */
2/* ====================================================================
3 * Copyright (c) 2012 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/md5.h>
57#include <openssl/sha.h>
58
59#include "ssl_local.h"
60
61/* MAX_HASH_BIT_COUNT_BYTES is the maximum number of bytes in the hash's length
62 * field. (SHA-384/512 have 128-bit length.) */
63#define MAX_HASH_BIT_COUNT_BYTES 16
64
65/* MAX_HASH_BLOCK_SIZE is the maximum hash block size that we'll support.
66 * Currently SHA-384/512 has a 128-byte block size and that's the largest
67 * supported by TLS.) */
68#define MAX_HASH_BLOCK_SIZE 128
69
70/* Some utility functions are needed:
71 *
72 * These macros return the given value with the MSB copied to all the other
73 * bits. They use the fact that arithmetic shift shifts-in the sign bit.
74 * However, this is not ensured by the C standard so you may need to replace
75 * them with something else on odd CPUs. */
76#define DUPLICATE_MSB_TO_ALL(x) ((unsigned int)((int)(x) >> (sizeof(int) * 8 - 1)))
77#define DUPLICATE_MSB_TO_ALL_8(x) ((unsigned char)(DUPLICATE_MSB_TO_ALL(x)))
78
79/* constant_time_lt returns 0xff if a<b and 0x00 otherwise. */
80static unsigned int
81constant_time_lt(unsigned int a, unsigned int b)
82{
83 a -= b;
84 return DUPLICATE_MSB_TO_ALL(a);
85}
86
87/* constant_time_ge returns 0xff if a>=b and 0x00 otherwise. */
88static unsigned int
89constant_time_ge(unsigned int a, unsigned int b)
90{
91 a -= b;
92 return DUPLICATE_MSB_TO_ALL(~a);
93}
94
95/* constant_time_eq_8 returns 0xff if a==b and 0x00 otherwise. */
96static unsigned char
97constant_time_eq_8(unsigned int a, unsigned int b)
98{
99 unsigned int c = a ^ b;
100 c--;
101 return DUPLICATE_MSB_TO_ALL_8(c);
102}
103
104/* ssl3_cbc_remove_padding removes the CBC padding from the decrypted, TLS, CBC
105 * record in |rec| in constant time and returns 1 if the padding is valid and
106 * -1 otherwise. It also removes any explicit IV from the start of the record
107 * without leaking any timing about whether there was enough space after the
108 * padding was removed.
109 *
110 * block_size: the block size of the cipher used to encrypt the record.
111 * returns:
112 * 0: (in non-constant time) if the record is publicly invalid.
113 * 1: if the padding was valid
114 * -1: otherwise. */
115int
116ssl3_cbc_remove_padding(SSL3_RECORD_INTERNAL *rec, unsigned int eiv_len,
117 unsigned int mac_size)
118{
119 unsigned int padding_length, good, to_check, i;
120 const unsigned int overhead = 1 /* padding length byte */ + mac_size;
121
122 /*
123 * These lengths are all public so we can test them in
124 * non-constant time.
125 */
126 if (overhead + eiv_len > rec->length)
127 return 0;
128
129 /* We can now safely skip explicit IV, if any. */
130 rec->data += eiv_len;
131 rec->input += eiv_len;
132 rec->length -= eiv_len;
133
134 padding_length = rec->data[rec->length - 1];
135
136 good = constant_time_ge(rec->length, overhead + padding_length);
137 /* The padding consists of a length byte at the end of the record and
138 * then that many bytes of padding, all with the same value as the
139 * length byte. Thus, with the length byte included, there are i+1
140 * bytes of padding.
141 *
142 * We can't check just |padding_length+1| bytes because that leaks
143 * decrypted information. Therefore we always have to check the maximum
144 * amount of padding possible. (Again, the length of the record is
145 * public information so we can use it.) */
146 to_check = 256; /* maximum amount of padding, inc length byte. */
147 if (to_check > rec->length)
148 to_check = rec->length;
149
150 for (i = 0; i < to_check; i++) {
151 unsigned char mask = constant_time_ge(padding_length, i);
152 unsigned char b = rec->data[rec->length - 1 - i];
153 /* The final |padding_length+1| bytes should all have the value
154 * |padding_length|. Therefore the XOR should be zero. */
155 good &= ~(mask&(padding_length ^ b));
156 }
157
158 /* If any of the final |padding_length+1| bytes had the wrong value,
159 * one or more of the lower eight bits of |good| will be cleared. We
160 * AND the bottom 8 bits together and duplicate the result to all the
161 * bits. */
162 good &= good >> 4;
163 good &= good >> 2;
164 good &= good >> 1;
165 good <<= sizeof(good)*8 - 1;
166 good = DUPLICATE_MSB_TO_ALL(good);
167
168 padding_length = good & (padding_length + 1);
169 rec->length -= padding_length;
170 rec->padding_length = padding_length;
171
172 return (int)((good & 1) | (~good & -1));
173}
174
175/* ssl3_cbc_copy_mac copies |md_size| bytes from the end of |rec| to |out| in
176 * constant time (independent of the concrete value of rec->length, which may
177 * vary within a 256-byte window).
178 *
179 * ssl3_cbc_remove_padding or tls1_cbc_remove_padding must be called prior to
180 * this function.
181 *
182 * On entry:
183 * rec->orig_len >= md_size
184 * md_size <= EVP_MAX_MD_SIZE
185 *
186 * If CBC_MAC_ROTATE_IN_PLACE is defined then the rotation is performed with
187 * variable accesses in a 64-byte-aligned buffer. Assuming that this fits into
188 * a single or pair of cache-lines, then the variable memory accesses don't
189 * actually affect the timing. CPUs with smaller cache-lines [if any] are
190 * not multi-core and are not considered vulnerable to cache-timing attacks.
191 */
192#define CBC_MAC_ROTATE_IN_PLACE
193
194void
195ssl3_cbc_copy_mac(unsigned char* out, const SSL3_RECORD_INTERNAL *rec,
196 unsigned int md_size, unsigned int orig_len)
197{
198#if defined(CBC_MAC_ROTATE_IN_PLACE)
199 unsigned char rotated_mac_buf[64 + EVP_MAX_MD_SIZE];
200 unsigned char *rotated_mac;
201#else
202 unsigned char rotated_mac[EVP_MAX_MD_SIZE];
203#endif
204
205 /* mac_end is the index of |rec->data| just after the end of the MAC. */
206 unsigned int mac_end = rec->length;
207 unsigned int mac_start = mac_end - md_size;
208 /* scan_start contains the number of bytes that we can ignore because
209 * the MAC's position can only vary by 255 bytes. */
210 unsigned int scan_start = 0;
211 unsigned int i, j;
212 unsigned int div_spoiler;
213 unsigned int rotate_offset;
214
215 OPENSSL_assert(orig_len >= md_size);
216 OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);
217
218#if defined(CBC_MAC_ROTATE_IN_PLACE)
219 rotated_mac = rotated_mac_buf + ((0 - (size_t)rotated_mac_buf)&63);
220#endif
221
222 /* This information is public so it's safe to branch based on it. */
223 if (orig_len > md_size + 255 + 1)
224 scan_start = orig_len - (md_size + 255 + 1);
225 /* div_spoiler contains a multiple of md_size that is used to cause the
226 * modulo operation to be constant time. Without this, the time varies
227 * based on the amount of padding when running on Intel chips at least.
228 *
229 * The aim of right-shifting md_size is so that the compiler doesn't
230 * figure out that it can remove div_spoiler as that would require it
231 * to prove that md_size is always even, which I hope is beyond it. */
232 div_spoiler = md_size >> 1;
233 div_spoiler <<= (sizeof(div_spoiler) - 1) * 8;
234 rotate_offset = (div_spoiler + mac_start - scan_start) % md_size;
235
236 memset(rotated_mac, 0, md_size);
237 for (i = scan_start, j = 0; i < orig_len; i++) {
238 unsigned char mac_started = constant_time_ge(i, mac_start);
239 unsigned char mac_ended = constant_time_ge(i, mac_end);
240 unsigned char b = rec->data[i];
241 rotated_mac[j++] |= b & mac_started & ~mac_ended;
242 j &= constant_time_lt(j, md_size);
243 }
244
245 /* Now rotate the MAC */
246#if defined(CBC_MAC_ROTATE_IN_PLACE)
247 j = 0;
248 for (i = 0; i < md_size; i++) {
249 /* in case cache-line is 32 bytes, touch second line */
250 ((volatile unsigned char *)rotated_mac)[rotate_offset^32];
251 out[j++] = rotated_mac[rotate_offset++];
252 rotate_offset &= constant_time_lt(rotate_offset, md_size);
253 }
254#else
255 memset(out, 0, md_size);
256 rotate_offset = md_size - rotate_offset;
257 rotate_offset &= constant_time_lt(rotate_offset, md_size);
258 for (i = 0; i < md_size; i++) {
259 for (j = 0; j < md_size; j++)
260 out[j] |= rotated_mac[i] & constant_time_eq_8(j, rotate_offset);
261 rotate_offset++;
262 rotate_offset &= constant_time_lt(rotate_offset, md_size);
263 }
264#endif
265}
266
267#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
268 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
269 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
270 *((c)++)=(unsigned char)(((l) )&0xff))
271
272#define l2n8(l,c) (*((c)++)=(unsigned char)(((l)>>56)&0xff), \
273 *((c)++)=(unsigned char)(((l)>>48)&0xff), \
274 *((c)++)=(unsigned char)(((l)>>40)&0xff), \
275 *((c)++)=(unsigned char)(((l)>>32)&0xff), \
276 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
277 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
278 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
279 *((c)++)=(unsigned char)(((l) )&0xff))
280
281/* u32toLE serialises an unsigned, 32-bit number (n) as four bytes at (p) in
282 * little-endian order. The value of p is advanced by four. */
283#define u32toLE(n, p) \
284 (*((p)++)=(unsigned char)(n), \
285 *((p)++)=(unsigned char)(n>>8), \
286 *((p)++)=(unsigned char)(n>>16), \
287 *((p)++)=(unsigned char)(n>>24))
288
289/* These functions serialize the state of a hash and thus perform the standard
290 * "final" operation without adding the padding and length that such a function
291 * typically does. */
292static void
293tls1_md5_final_raw(void* ctx, unsigned char *md_out)
294{
295 MD5_CTX *md5 = ctx;
296 u32toLE(md5->A, md_out);
297 u32toLE(md5->B, md_out);
298 u32toLE(md5->C, md_out);
299 u32toLE(md5->D, md_out);
300}
301
302static void
303tls1_sha1_final_raw(void* ctx, unsigned char *md_out)
304{
305 SHA_CTX *sha1 = ctx;
306 l2n(sha1->h0, md_out);
307 l2n(sha1->h1, md_out);
308 l2n(sha1->h2, md_out);
309 l2n(sha1->h3, md_out);
310 l2n(sha1->h4, md_out);
311}
312
313static void
314tls1_sha256_final_raw(void* ctx, unsigned char *md_out)
315{
316 SHA256_CTX *sha256 = ctx;
317 unsigned int i;
318
319 for (i = 0; i < 8; i++) {
320 l2n(sha256->h[i], md_out);
321 }
322}
323
324static void
325tls1_sha512_final_raw(void* ctx, unsigned char *md_out)
326{
327 SHA512_CTX *sha512 = ctx;
328 unsigned int i;
329
330 for (i = 0; i < 8; i++) {
331 l2n8(sha512->h[i], md_out);
332 }
333}
334
335/* Largest hash context ever used by the functions above. */
336#define LARGEST_DIGEST_CTX SHA512_CTX
337
338/* Type giving the alignment needed by the above */
339#define LARGEST_DIGEST_CTX_ALIGNMENT SHA_LONG64
340
341/* ssl3_cbc_record_digest_supported returns 1 iff |ctx| uses a hash function
342 * which ssl3_cbc_digest_record supports. */
343char
344ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx)
345{
346 switch (EVP_MD_CTX_type(ctx)) {
347 case NID_md5:
348 case NID_sha1:
349 case NID_sha224:
350 case NID_sha256:
351 case NID_sha384:
352 case NID_sha512:
353 return 1;
354 default:
355 return 0;
356 }
357}
358
359/* ssl3_cbc_digest_record computes the MAC of a decrypted, padded TLS
360 * record.
361 *
362 * ctx: the EVP_MD_CTX from which we take the hash function.
363 * ssl3_cbc_record_digest_supported must return true for this EVP_MD_CTX.
364 * md_out: the digest output. At most EVP_MAX_MD_SIZE bytes will be written.
365 * md_out_size: if non-NULL, the number of output bytes is written here.
366 * header: the 13-byte, TLS record header.
367 * data: the record data itself, less any preceeding explicit IV.
368 * data_plus_mac_size: the secret, reported length of the data and MAC
369 * once the padding has been removed.
370 * data_plus_mac_plus_padding_size: the public length of the whole
371 * record, including padding.
372 *
373 * On entry: by virtue of having been through one of the remove_padding
374 * functions, above, we know that data_plus_mac_size is large enough to contain
375 * a padding byte and MAC. (If the padding was invalid, it might contain the
376 * padding too. )
377 */
378int
379ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char* md_out,
380 size_t* md_out_size, const unsigned char header[13],
381 const unsigned char *data, size_t data_plus_mac_size,
382 size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret,
383 unsigned int mac_secret_length)
384{
385 union {
386 /*
387 * Alignment here is to allow this to be cast as SHA512_CTX
388 * without losing alignment required by the 64-bit SHA_LONG64
389 * integer it contains.
390 */
391 LARGEST_DIGEST_CTX_ALIGNMENT align;
392 unsigned char c[sizeof(LARGEST_DIGEST_CTX)];
393 } md_state;
394 void (*md_final_raw)(void *ctx, unsigned char *md_out);
395 void (*md_transform)(void *ctx, const unsigned char *block);
396 unsigned int md_size, md_block_size = 64;
397 unsigned int header_length, variance_blocks,
398 len, max_mac_bytes, num_blocks,
399 num_starting_blocks, k, mac_end_offset, c, index_a, index_b;
400 unsigned int bits; /* at most 18 bits */
401 unsigned char length_bytes[MAX_HASH_BIT_COUNT_BYTES];
402 /* hmac_pad is the masked HMAC key. */
403 unsigned char hmac_pad[MAX_HASH_BLOCK_SIZE];
404 unsigned char first_block[MAX_HASH_BLOCK_SIZE];
405 unsigned char mac_out[EVP_MAX_MD_SIZE];
406 unsigned int i, j, md_out_size_u;
407 EVP_MD_CTX *md_ctx;
408 /* mdLengthSize is the number of bytes in the length field that terminates
409 * the hash. */
410 unsigned int md_length_size = 8;
411 char length_is_big_endian = 1;
412
413 /* This is a, hopefully redundant, check that allows us to forget about
414 * many possible overflows later in this function. */
415 OPENSSL_assert(data_plus_mac_plus_padding_size < 1024*1024);
416
417 switch (EVP_MD_CTX_type(ctx)) {
418 case NID_md5:
419 MD5_Init((MD5_CTX*)md_state.c);
420 md_final_raw = tls1_md5_final_raw;
421 md_transform = (void(*)(void *ctx, const unsigned char *block)) MD5_Transform;
422 md_size = 16;
423 length_is_big_endian = 0;
424 break;
425 case NID_sha1:
426 SHA1_Init((SHA_CTX*)md_state.c);
427 md_final_raw = tls1_sha1_final_raw;
428 md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA1_Transform;
429 md_size = 20;
430 break;
431 case NID_sha224:
432 SHA224_Init((SHA256_CTX*)md_state.c);
433 md_final_raw = tls1_sha256_final_raw;
434 md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;
435 md_size = 224/8;
436 break;
437 case NID_sha256:
438 SHA256_Init((SHA256_CTX*)md_state.c);
439 md_final_raw = tls1_sha256_final_raw;
440 md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA256_Transform;
441 md_size = 32;
442 break;
443 case NID_sha384:
444 SHA384_Init((SHA512_CTX*)md_state.c);
445 md_final_raw = tls1_sha512_final_raw;
446 md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;
447 md_size = 384/8;
448 md_block_size = 128;
449 md_length_size = 16;
450 break;
451 case NID_sha512:
452 SHA512_Init((SHA512_CTX*)md_state.c);
453 md_final_raw = tls1_sha512_final_raw;
454 md_transform = (void(*)(void *ctx, const unsigned char *block)) SHA512_Transform;
455 md_size = 64;
456 md_block_size = 128;
457 md_length_size = 16;
458 break;
459 default:
460 /* ssl3_cbc_record_digest_supported should have been
461 * called first to check that the hash function is
462 * supported. */
463 OPENSSL_assert(0);
464 if (md_out_size)
465 *md_out_size = 0;
466 return 0;
467 }
468
469 OPENSSL_assert(md_length_size <= MAX_HASH_BIT_COUNT_BYTES);
470 OPENSSL_assert(md_block_size <= MAX_HASH_BLOCK_SIZE);
471 OPENSSL_assert(md_size <= EVP_MAX_MD_SIZE);
472
473 header_length = 13;
474
475 /* variance_blocks is the number of blocks of the hash that we have to
476 * calculate in constant time because they could be altered by the
477 * padding value.
478 *
479 * TLSv1 has MACs up to 48 bytes long (SHA-384) and the padding is not
480 * required to be minimal. Therefore we say that the final six blocks
481 * can vary based on the padding.
482 *
483 * Later in the function, if the message is short and there obviously
484 * cannot be this many blocks then variance_blocks can be reduced. */
485 variance_blocks = 6;
486 /* From now on we're dealing with the MAC, which conceptually has 13
487 * bytes of `header' before the start of the data (TLS) */
488 len = data_plus_mac_plus_padding_size + header_length;
489 /* max_mac_bytes contains the maximum bytes of bytes in the MAC, including
490 * |header|, assuming that there's no padding. */
491 max_mac_bytes = len - md_size - 1;
492 /* num_blocks is the maximum number of hash blocks. */
493 num_blocks = (max_mac_bytes + 1 + md_length_size + md_block_size - 1) / md_block_size;
494 /* In order to calculate the MAC in constant time we have to handle
495 * the final blocks specially because the padding value could cause the
496 * end to appear somewhere in the final |variance_blocks| blocks and we
497 * can't leak where. However, |num_starting_blocks| worth of data can
498 * be hashed right away because no padding value can affect whether
499 * they are plaintext. */
500 num_starting_blocks = 0;
501 /* k is the starting byte offset into the conceptual header||data where
502 * we start processing. */
503 k = 0;
504 /* mac_end_offset is the index just past the end of the data to be
505 * MACed. */
506 mac_end_offset = data_plus_mac_size + header_length - md_size;
507 /* c is the index of the 0x80 byte in the final hash block that
508 * contains application data. */
509 c = mac_end_offset % md_block_size;
510 /* index_a is the hash block number that contains the 0x80 terminating
511 * value. */
512 index_a = mac_end_offset / md_block_size;
513 /* index_b is the hash block number that contains the 64-bit hash
514 * length, in bits. */
515 index_b = (mac_end_offset + md_length_size) / md_block_size;
516 /* bits is the hash-length in bits. It includes the additional hash
517 * block for the masked HMAC key. */
518
519 if (num_blocks > variance_blocks) {
520 num_starting_blocks = num_blocks - variance_blocks;
521 k = md_block_size*num_starting_blocks;
522 }
523
524 bits = 8*mac_end_offset;
525 /* Compute the initial HMAC block. */
526 bits += 8*md_block_size;
527 memset(hmac_pad, 0, md_block_size);
528 OPENSSL_assert(mac_secret_length <= sizeof(hmac_pad));
529 memcpy(hmac_pad, mac_secret, mac_secret_length);
530 for (i = 0; i < md_block_size; i++)
531 hmac_pad[i] ^= 0x36;
532
533 md_transform(md_state.c, hmac_pad);
534
535 if (length_is_big_endian) {
536 memset(length_bytes, 0, md_length_size - 4);
537 length_bytes[md_length_size - 4] = (unsigned char)(bits >> 24);
538 length_bytes[md_length_size - 3] = (unsigned char)(bits >> 16);
539 length_bytes[md_length_size - 2] = (unsigned char)(bits >> 8);
540 length_bytes[md_length_size - 1] = (unsigned char)bits;
541 } else {
542 memset(length_bytes, 0, md_length_size);
543 length_bytes[md_length_size - 5] = (unsigned char)(bits >> 24);
544 length_bytes[md_length_size - 6] = (unsigned char)(bits >> 16);
545 length_bytes[md_length_size - 7] = (unsigned char)(bits >> 8);
546 length_bytes[md_length_size - 8] = (unsigned char)bits;
547 }
548
549 if (k > 0) {
550 /* k is a multiple of md_block_size. */
551 memcpy(first_block, header, 13);
552 memcpy(first_block + 13, data, md_block_size - 13);
553 md_transform(md_state.c, first_block);
554 for (i = 1; i < k/md_block_size; i++)
555 md_transform(md_state.c, data + md_block_size*i - 13);
556 }
557
558 memset(mac_out, 0, sizeof(mac_out));
559
560 /* We now process the final hash blocks. For each block, we construct
561 * it in constant time. If the |i==index_a| then we'll include the 0x80
562 * bytes and zero pad etc. For each block we selectively copy it, in
563 * constant time, to |mac_out|. */
564 for (i = num_starting_blocks; i <= num_starting_blocks + variance_blocks; i++) {
565 unsigned char block[MAX_HASH_BLOCK_SIZE];
566 unsigned char is_block_a = constant_time_eq_8(i, index_a);
567 unsigned char is_block_b = constant_time_eq_8(i, index_b);
568 for (j = 0; j < md_block_size; j++) {
569 unsigned char b = 0, is_past_c, is_past_cp1;
570 if (k < header_length)
571 b = header[k];
572 else if (k < data_plus_mac_plus_padding_size + header_length)
573 b = data[k - header_length];
574 k++;
575
576 is_past_c = is_block_a & constant_time_ge(j, c);
577 is_past_cp1 = is_block_a & constant_time_ge(j, c + 1);
578 /* If this is the block containing the end of the
579 * application data, and we are at the offset for the
580 * 0x80 value, then overwrite b with 0x80. */
581 b = (b&~is_past_c) | (0x80&is_past_c);
582 /* If this is the block containing the end of the
583 * application data and we're past the 0x80 value then
584 * just write zero. */
585 b = b&~is_past_cp1;
586 /* If this is index_b (the final block), but not
587 * index_a (the end of the data), then the 64-bit
588 * length didn't fit into index_a and we're having to
589 * add an extra block of zeros. */
590 b &= ~is_block_b | is_block_a;
591
592 /* The final bytes of one of the blocks contains the
593 * length. */
594 if (j >= md_block_size - md_length_size) {
595 /* If this is index_b, write a length byte. */
596 b = (b&~is_block_b) | (is_block_b&length_bytes[j - (md_block_size - md_length_size)]);
597 }
598 block[j] = b;
599 }
600
601 md_transform(md_state.c, block);
602 md_final_raw(md_state.c, block);
603 /* If this is index_b, copy the hash value to |mac_out|. */
604 for (j = 0; j < md_size; j++)
605 mac_out[j] |= block[j]&is_block_b;
606 }
607
608 if ((md_ctx = EVP_MD_CTX_new()) == NULL)
609 return 0;
610 if (!EVP_DigestInit_ex(md_ctx, EVP_MD_CTX_md(ctx), NULL /* engine */)) {
611 EVP_MD_CTX_free(md_ctx);
612 return 0;
613 }
614
615 /* Complete the HMAC in the standard manner. */
616 for (i = 0; i < md_block_size; i++)
617 hmac_pad[i] ^= 0x6a;
618
619 EVP_DigestUpdate(md_ctx, hmac_pad, md_block_size);
620 EVP_DigestUpdate(md_ctx, mac_out, md_size);
621
622 EVP_DigestFinal(md_ctx, md_out, &md_out_size_u);
623 if (md_out_size)
624 *md_out_size = md_out_size_u;
625 EVP_MD_CTX_free(md_ctx);
626
627 return 1;
628}
diff --git a/src/lib/libssl/s3_lib.c b/src/lib/libssl/s3_lib.c
deleted file mode 100644
index 86b32aec15..0000000000
--- a/src/lib/libssl/s3_lib.c
+++ /dev/null
@@ -1,2534 +0,0 @@
1/* $OpenBSD: s3_lib.c,v 1.257 2024/07/23 14:40:53 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 *
114 * Portions of the attached software ("Contribution") are developed by
115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
116 *
117 * The Contribution is licensed pursuant to the OpenSSL open source
118 * license provided above.
119 *
120 * ECC cipher suite support in OpenSSL originally written by
121 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
122 *
123 */
124/* ====================================================================
125 * Copyright 2005 Nokia. All rights reserved.
126 *
127 * The portions of the attached software ("Contribution") is developed by
128 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
129 * license.
130 *
131 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
132 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
133 * support (see RFC 4279) to OpenSSL.
134 *
135 * No patent licenses or other rights except those expressly stated in
136 * the OpenSSL open source license shall be deemed granted or received
137 * expressly, by implication, estoppel, or otherwise.
138 *
139 * No assurances are provided by Nokia that the Contribution does not
140 * infringe the patent or other intellectual property rights of any third
141 * party or that the license provides you with all the necessary rights
142 * to make use of the Contribution.
143 *
144 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
145 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
146 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
147 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
148 * OTHERWISE.
149 */
150
151#include <limits.h>
152#include <stdio.h>
153#include <stdlib.h>
154
155#include <openssl/bn.h>
156#include <openssl/curve25519.h>
157#include <openssl/dh.h>
158#include <openssl/md5.h>
159#include <openssl/objects.h>
160#include <openssl/opensslconf.h>
161
162#include "bytestring.h"
163#include "dtls_local.h"
164#include "ssl_local.h"
165#include "ssl_sigalgs.h"
166#include "ssl_tlsext.h"
167#include "tls_content.h"
168
169#define SSL3_NUM_CIPHERS (sizeof(ssl3_ciphers) / sizeof(SSL_CIPHER))
170
171/* list of available SSLv3 ciphers (sorted by id) */
172const SSL_CIPHER ssl3_ciphers[] = {
173
174 /*
175 * SSLv3 RSA cipher suites (RFC 6101, appendix A.6).
176 */
177 {
178 .value = 0x0001,
179 .name = SSL3_TXT_RSA_NULL_MD5,
180 .algorithm_mkey = SSL_kRSA,
181 .algorithm_auth = SSL_aRSA,
182 .algorithm_enc = SSL_eNULL,
183 .algorithm_mac = SSL_MD5,
184 .algorithm_ssl = SSL_SSLV3,
185 .algo_strength = SSL_STRONG_NONE,
186 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
187 .strength_bits = 0,
188 .alg_bits = 0,
189 },
190 {
191 .value = 0x0002,
192 .name = SSL3_TXT_RSA_NULL_SHA,
193 .algorithm_mkey = SSL_kRSA,
194 .algorithm_auth = SSL_aRSA,
195 .algorithm_enc = SSL_eNULL,
196 .algorithm_mac = SSL_SHA1,
197 .algorithm_ssl = SSL_SSLV3,
198 .algo_strength = SSL_STRONG_NONE,
199 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
200 .strength_bits = 0,
201 .alg_bits = 0,
202 },
203 {
204 .value = 0x0004,
205 .name = SSL3_TXT_RSA_RC4_128_MD5,
206 .algorithm_mkey = SSL_kRSA,
207 .algorithm_auth = SSL_aRSA,
208 .algorithm_enc = SSL_RC4,
209 .algorithm_mac = SSL_MD5,
210 .algorithm_ssl = SSL_SSLV3,
211 .algo_strength = SSL_LOW,
212 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
213 .strength_bits = 128,
214 .alg_bits = 128,
215 },
216 {
217 .value = 0x0005,
218 .name = SSL3_TXT_RSA_RC4_128_SHA,
219 .algorithm_mkey = SSL_kRSA,
220 .algorithm_auth = SSL_aRSA,
221 .algorithm_enc = SSL_RC4,
222 .algorithm_mac = SSL_SHA1,
223 .algorithm_ssl = SSL_SSLV3,
224 .algo_strength = SSL_LOW,
225 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
226 .strength_bits = 128,
227 .alg_bits = 128,
228 },
229 {
230 .value = 0x000a,
231 .name = SSL3_TXT_RSA_DES_192_CBC3_SHA,
232 .algorithm_mkey = SSL_kRSA,
233 .algorithm_auth = SSL_aRSA,
234 .algorithm_enc = SSL_3DES,
235 .algorithm_mac = SSL_SHA1,
236 .algorithm_ssl = SSL_SSLV3,
237 .algo_strength = SSL_MEDIUM,
238 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
239 .strength_bits = 112,
240 .alg_bits = 168,
241 },
242
243 /*
244 * SSLv3 DHE cipher suites (RFC 6101, appendix A.6).
245 */
246 {
247 .value = 0x0016,
248 .name = SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA,
249 .algorithm_mkey = SSL_kDHE,
250 .algorithm_auth = SSL_aRSA,
251 .algorithm_enc = SSL_3DES,
252 .algorithm_mac = SSL_SHA1,
253 .algorithm_ssl = SSL_SSLV3,
254 .algo_strength = SSL_MEDIUM,
255 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
256 .strength_bits = 112,
257 .alg_bits = 168,
258 },
259 {
260 .value = 0x0018,
261 .name = SSL3_TXT_ADH_RC4_128_MD5,
262 .algorithm_mkey = SSL_kDHE,
263 .algorithm_auth = SSL_aNULL,
264 .algorithm_enc = SSL_RC4,
265 .algorithm_mac = SSL_MD5,
266 .algorithm_ssl = SSL_SSLV3,
267 .algo_strength = SSL_LOW,
268 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
269 .strength_bits = 128,
270 .alg_bits = 128,
271 },
272 {
273 .value = 0x001b,
274 .name = SSL3_TXT_ADH_DES_192_CBC_SHA,
275 .algorithm_mkey = SSL_kDHE,
276 .algorithm_auth = SSL_aNULL,
277 .algorithm_enc = SSL_3DES,
278 .algorithm_mac = SSL_SHA1,
279 .algorithm_ssl = SSL_SSLV3,
280 .algo_strength = SSL_MEDIUM,
281 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
282 .strength_bits = 112,
283 .alg_bits = 168,
284 },
285
286 /*
287 * TLSv1.0 AES cipher suites (RFC 3268).
288 */
289 {
290 .value = 0x002f,
291 .name = TLS1_TXT_RSA_WITH_AES_128_SHA,
292 .algorithm_mkey = SSL_kRSA,
293 .algorithm_auth = SSL_aRSA,
294 .algorithm_enc = SSL_AES128,
295 .algorithm_mac = SSL_SHA1,
296 .algorithm_ssl = SSL_TLSV1,
297 .algo_strength = SSL_HIGH,
298 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
299 .strength_bits = 128,
300 .alg_bits = 128,
301 },
302 {
303 .value = 0x0033,
304 .name = TLS1_TXT_DHE_RSA_WITH_AES_128_SHA,
305 .algorithm_mkey = SSL_kDHE,
306 .algorithm_auth = SSL_aRSA,
307 .algorithm_enc = SSL_AES128,
308 .algorithm_mac = SSL_SHA1,
309 .algorithm_ssl = SSL_TLSV1,
310 .algo_strength = SSL_HIGH,
311 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
312 .strength_bits = 128,
313 .alg_bits = 128,
314 },
315 {
316 .value = 0x0034,
317 .name = TLS1_TXT_ADH_WITH_AES_128_SHA,
318 .algorithm_mkey = SSL_kDHE,
319 .algorithm_auth = SSL_aNULL,
320 .algorithm_enc = SSL_AES128,
321 .algorithm_mac = SSL_SHA1,
322 .algorithm_ssl = SSL_TLSV1,
323 .algo_strength = SSL_HIGH,
324 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
325 .strength_bits = 128,
326 .alg_bits = 128,
327 },
328 {
329 .value = 0x0035,
330 .name = TLS1_TXT_RSA_WITH_AES_256_SHA,
331 .algorithm_mkey = SSL_kRSA,
332 .algorithm_auth = SSL_aRSA,
333 .algorithm_enc = SSL_AES256,
334 .algorithm_mac = SSL_SHA1,
335 .algorithm_ssl = SSL_TLSV1,
336 .algo_strength = SSL_HIGH,
337 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
338 .strength_bits = 256,
339 .alg_bits = 256,
340 },
341 {
342 .value = 0x0039,
343 .name = TLS1_TXT_DHE_RSA_WITH_AES_256_SHA,
344 .algorithm_mkey = SSL_kDHE,
345 .algorithm_auth = SSL_aRSA,
346 .algorithm_enc = SSL_AES256,
347 .algorithm_mac = SSL_SHA1,
348 .algorithm_ssl = SSL_TLSV1,
349 .algo_strength = SSL_HIGH,
350 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
351 .strength_bits = 256,
352 .alg_bits = 256,
353 },
354 {
355 .value = 0x003a,
356 .name = TLS1_TXT_ADH_WITH_AES_256_SHA,
357 .algorithm_mkey = SSL_kDHE,
358 .algorithm_auth = SSL_aNULL,
359 .algorithm_enc = SSL_AES256,
360 .algorithm_mac = SSL_SHA1,
361 .algorithm_ssl = SSL_TLSV1,
362 .algo_strength = SSL_HIGH,
363 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
364 .strength_bits = 256,
365 .alg_bits = 256,
366 },
367
368 /*
369 * TLSv1.2 RSA cipher suites (RFC 5246, appendix A.5).
370 */
371 {
372 .value = 0x003b,
373 .name = TLS1_TXT_RSA_WITH_NULL_SHA256,
374 .algorithm_mkey = SSL_kRSA,
375 .algorithm_auth = SSL_aRSA,
376 .algorithm_enc = SSL_eNULL,
377 .algorithm_mac = SSL_SHA256,
378 .algorithm_ssl = SSL_TLSV1_2,
379 .algo_strength = SSL_STRONG_NONE,
380 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
381 .strength_bits = 0,
382 .alg_bits = 0,
383 },
384 {
385 .value = 0x003c,
386 .name = TLS1_TXT_RSA_WITH_AES_128_SHA256,
387 .algorithm_mkey = SSL_kRSA,
388 .algorithm_auth = SSL_aRSA,
389 .algorithm_enc = SSL_AES128,
390 .algorithm_mac = SSL_SHA256,
391 .algorithm_ssl = SSL_TLSV1_2,
392 .algo_strength = SSL_HIGH,
393 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
394 .strength_bits = 128,
395 .alg_bits = 128,
396 },
397 {
398 .value = 0x003d,
399 .name = TLS1_TXT_RSA_WITH_AES_256_SHA256,
400 .algorithm_mkey = SSL_kRSA,
401 .algorithm_auth = SSL_aRSA,
402 .algorithm_enc = SSL_AES256,
403 .algorithm_mac = SSL_SHA256,
404 .algorithm_ssl = SSL_TLSV1_2,
405 .algo_strength = SSL_HIGH,
406 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
407 .strength_bits = 256,
408 .alg_bits = 256,
409 },
410
411#ifndef OPENSSL_NO_CAMELLIA
412 /*
413 * TLSv1.0 Camellia 128 bit cipher suites (RFC 4132).
414 */
415 {
416 .value = 0x0041,
417 .name = TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA,
418 .algorithm_mkey = SSL_kRSA,
419 .algorithm_auth = SSL_aRSA,
420 .algorithm_enc = SSL_CAMELLIA128,
421 .algorithm_mac = SSL_SHA1,
422 .algorithm_ssl = SSL_TLSV1,
423 .algo_strength = SSL_HIGH,
424 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
425 .strength_bits = 128,
426 .alg_bits = 128,
427 },
428 {
429 .value = 0x0045,
430 .name = TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA,
431 .algorithm_mkey = SSL_kDHE,
432 .algorithm_auth = SSL_aRSA,
433 .algorithm_enc = SSL_CAMELLIA128,
434 .algorithm_mac = SSL_SHA1,
435 .algorithm_ssl = SSL_TLSV1,
436 .algo_strength = SSL_HIGH,
437 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
438 .strength_bits = 128,
439 .alg_bits = 128,
440 },
441 {
442 .value = 0x0046,
443 .name = TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA,
444 .algorithm_mkey = SSL_kDHE,
445 .algorithm_auth = SSL_aNULL,
446 .algorithm_enc = SSL_CAMELLIA128,
447 .algorithm_mac = SSL_SHA1,
448 .algorithm_ssl = SSL_TLSV1,
449 .algo_strength = SSL_HIGH,
450 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
451 .strength_bits = 128,
452 .alg_bits = 128,
453 },
454#endif /* OPENSSL_NO_CAMELLIA */
455
456 /*
457 * TLSv1.2 DHE cipher suites (RFC 5246, appendix A.5).
458 */
459 {
460 .value = 0x0067,
461 .name = TLS1_TXT_DHE_RSA_WITH_AES_128_SHA256,
462 .algorithm_mkey = SSL_kDHE,
463 .algorithm_auth = SSL_aRSA,
464 .algorithm_enc = SSL_AES128,
465 .algorithm_mac = SSL_SHA256,
466 .algorithm_ssl = SSL_TLSV1_2,
467 .algo_strength = SSL_HIGH,
468 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
469 .strength_bits = 128,
470 .alg_bits = 128,
471 },
472 {
473 .value = 0x006b,
474 .name = TLS1_TXT_DHE_RSA_WITH_AES_256_SHA256,
475 .algorithm_mkey = SSL_kDHE,
476 .algorithm_auth = SSL_aRSA,
477 .algorithm_enc = SSL_AES256,
478 .algorithm_mac = SSL_SHA256,
479 .algorithm_ssl = SSL_TLSV1_2,
480 .algo_strength = SSL_HIGH,
481 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
482 .strength_bits = 256,
483 .alg_bits = 256,
484 },
485 {
486 .value = 0x006c,
487 .name = TLS1_TXT_ADH_WITH_AES_128_SHA256,
488 .algorithm_mkey = SSL_kDHE,
489 .algorithm_auth = SSL_aNULL,
490 .algorithm_enc = SSL_AES128,
491 .algorithm_mac = SSL_SHA256,
492 .algorithm_ssl = SSL_TLSV1_2,
493 .algo_strength = SSL_HIGH,
494 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
495 .strength_bits = 128,
496 .alg_bits = 128,
497 },
498 {
499 .value = 0x006d,
500 .name = TLS1_TXT_ADH_WITH_AES_256_SHA256,
501 .algorithm_mkey = SSL_kDHE,
502 .algorithm_auth = SSL_aNULL,
503 .algorithm_enc = SSL_AES256,
504 .algorithm_mac = SSL_SHA256,
505 .algorithm_ssl = SSL_TLSV1_2,
506 .algo_strength = SSL_HIGH,
507 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
508 .strength_bits = 256,
509 .alg_bits = 256,
510 },
511
512#ifndef OPENSSL_NO_CAMELLIA
513 /*
514 * TLSv1.0 Camellia 256 bit cipher suites (RFC 4132).
515 */
516 {
517 .value = 0x0084,
518 .name = TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA,
519 .algorithm_mkey = SSL_kRSA,
520 .algorithm_auth = SSL_aRSA,
521 .algorithm_enc = SSL_CAMELLIA256,
522 .algorithm_mac = SSL_SHA1,
523 .algorithm_ssl = SSL_TLSV1,
524 .algo_strength = SSL_HIGH,
525 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
526 .strength_bits = 256,
527 .alg_bits = 256,
528 },
529 {
530 .value = 0x0088,
531 .name = TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA,
532 .algorithm_mkey = SSL_kDHE,
533 .algorithm_auth = SSL_aRSA,
534 .algorithm_enc = SSL_CAMELLIA256,
535 .algorithm_mac = SSL_SHA1,
536 .algorithm_ssl = SSL_TLSV1,
537 .algo_strength = SSL_HIGH,
538 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
539 .strength_bits = 256,
540 .alg_bits = 256,
541 },
542 {
543 .value = 0x0089,
544 .name = TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA,
545 .algorithm_mkey = SSL_kDHE,
546 .algorithm_auth = SSL_aNULL,
547 .algorithm_enc = SSL_CAMELLIA256,
548 .algorithm_mac = SSL_SHA1,
549 .algorithm_ssl = SSL_TLSV1,
550 .algo_strength = SSL_HIGH,
551 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
552 .strength_bits = 256,
553 .alg_bits = 256,
554 },
555#endif /* OPENSSL_NO_CAMELLIA */
556
557 /*
558 * TLSv1.2 AES GCM cipher suites (RFC 5288).
559 */
560 {
561 .value = 0x009c,
562 .name = TLS1_TXT_RSA_WITH_AES_128_GCM_SHA256,
563 .algorithm_mkey = SSL_kRSA,
564 .algorithm_auth = SSL_aRSA,
565 .algorithm_enc = SSL_AES128GCM,
566 .algorithm_mac = SSL_AEAD,
567 .algorithm_ssl = SSL_TLSV1_2,
568 .algo_strength = SSL_HIGH,
569 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
570 .strength_bits = 128,
571 .alg_bits = 128,
572 },
573 {
574 .value = 0x009d,
575 .name = TLS1_TXT_RSA_WITH_AES_256_GCM_SHA384,
576 .algorithm_mkey = SSL_kRSA,
577 .algorithm_auth = SSL_aRSA,
578 .algorithm_enc = SSL_AES256GCM,
579 .algorithm_mac = SSL_AEAD,
580 .algorithm_ssl = SSL_TLSV1_2,
581 .algo_strength = SSL_HIGH,
582 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
583 .strength_bits = 256,
584 .alg_bits = 256,
585 },
586 {
587 .value = 0x009e,
588 .name = TLS1_TXT_DHE_RSA_WITH_AES_128_GCM_SHA256,
589 .algorithm_mkey = SSL_kDHE,
590 .algorithm_auth = SSL_aRSA,
591 .algorithm_enc = SSL_AES128GCM,
592 .algorithm_mac = SSL_AEAD,
593 .algorithm_ssl = SSL_TLSV1_2,
594 .algo_strength = SSL_HIGH,
595 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
596 .strength_bits = 128,
597 .alg_bits = 128,
598 },
599 {
600 .value = 0x009f,
601 .name = TLS1_TXT_DHE_RSA_WITH_AES_256_GCM_SHA384,
602 .algorithm_mkey = SSL_kDHE,
603 .algorithm_auth = SSL_aRSA,
604 .algorithm_enc = SSL_AES256GCM,
605 .algorithm_mac = SSL_AEAD,
606 .algorithm_ssl = SSL_TLSV1_2,
607 .algo_strength = SSL_HIGH,
608 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
609 .strength_bits = 256,
610 .alg_bits = 256,
611 },
612 {
613 .value = 0x00a6,
614 .name = TLS1_TXT_ADH_WITH_AES_128_GCM_SHA256,
615 .algorithm_mkey = SSL_kDHE,
616 .algorithm_auth = SSL_aNULL,
617 .algorithm_enc = SSL_AES128GCM,
618 .algorithm_mac = SSL_AEAD,
619 .algorithm_ssl = SSL_TLSV1_2,
620 .algo_strength = SSL_HIGH,
621 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
622 .strength_bits = 128,
623 .alg_bits = 128,
624 },
625 {
626 .value = 0x00a7,
627 .name = TLS1_TXT_ADH_WITH_AES_256_GCM_SHA384,
628 .algorithm_mkey = SSL_kDHE,
629 .algorithm_auth = SSL_aNULL,
630 .algorithm_enc = SSL_AES256GCM,
631 .algorithm_mac = SSL_AEAD,
632 .algorithm_ssl = SSL_TLSV1_2,
633 .algo_strength = SSL_HIGH,
634 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
635 .strength_bits = 256,
636 .alg_bits = 256,
637 },
638
639#ifndef OPENSSL_NO_CAMELLIA
640 /*
641 * TLSv1.2 Camellia SHA-256 cipher suites (RFC 5932).
642 */
643 {
644 .value = 0x00ba,
645 .name = TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA256,
646 .algorithm_mkey = SSL_kRSA,
647 .algorithm_auth = SSL_aRSA,
648 .algorithm_enc = SSL_CAMELLIA128,
649 .algorithm_mac = SSL_SHA256,
650 .algorithm_ssl = SSL_TLSV1_2,
651 .algo_strength = SSL_HIGH,
652 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
653 .strength_bits = 128,
654 .alg_bits = 128,
655 },
656 {
657 .value = 0x000be,
658 .name = TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256,
659 .algorithm_mkey = SSL_kDHE,
660 .algorithm_auth = SSL_aRSA,
661 .algorithm_enc = SSL_CAMELLIA128,
662 .algorithm_mac = SSL_SHA256,
663 .algorithm_ssl = SSL_TLSV1_2,
664 .algo_strength = SSL_HIGH,
665 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
666 .strength_bits = 128,
667 .alg_bits = 128,
668 },
669 {
670 .value = 0x00bf,
671 .name = TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA256,
672 .algorithm_mkey = SSL_kDHE,
673 .algorithm_auth = SSL_aNULL,
674 .algorithm_enc = SSL_CAMELLIA128,
675 .algorithm_mac = SSL_SHA256,
676 .algorithm_ssl = SSL_TLSV1_2,
677 .algo_strength = SSL_HIGH,
678 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
679 .strength_bits = 128,
680 .alg_bits = 128,
681 },
682 {
683 .value = 0x00c0,
684 .name = TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA256,
685 .algorithm_mkey = SSL_kRSA,
686 .algorithm_auth = SSL_aRSA,
687 .algorithm_enc = SSL_CAMELLIA256,
688 .algorithm_mac = SSL_SHA256,
689 .algorithm_ssl = SSL_TLSV1_2,
690 .algo_strength = SSL_HIGH,
691 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
692 .strength_bits = 256,
693 .alg_bits = 256,
694 },
695 {
696 .value = 0x00c4,
697 .name = TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256,
698 .algorithm_mkey = SSL_kDHE,
699 .algorithm_auth = SSL_aRSA,
700 .algorithm_enc = SSL_CAMELLIA256,
701 .algorithm_mac = SSL_SHA256,
702 .algorithm_ssl = SSL_TLSV1_2,
703 .algo_strength = SSL_HIGH,
704 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
705 .strength_bits = 256,
706 .alg_bits = 256,
707 },
708 {
709 .value = 0x00c5,
710 .name = TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA256,
711 .algorithm_mkey = SSL_kDHE,
712 .algorithm_auth = SSL_aNULL,
713 .algorithm_enc = SSL_CAMELLIA256,
714 .algorithm_mac = SSL_SHA256,
715 .algorithm_ssl = SSL_TLSV1_2,
716 .algo_strength = SSL_HIGH,
717 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
718 .strength_bits = 256,
719 .alg_bits = 256,
720 },
721#endif /* OPENSSL_NO_CAMELLIA */
722
723#ifdef LIBRESSL_HAS_TLS1_3
724 /*
725 * TLSv1.3 cipher suites (RFC 8446).
726 */
727 {
728 .value = 0x1301,
729 .name = TLS1_3_RFC_AES_128_GCM_SHA256,
730 .algorithm_mkey = SSL_kTLS1_3,
731 .algorithm_auth = SSL_aTLS1_3,
732 .algorithm_enc = SSL_AES128GCM,
733 .algorithm_mac = SSL_AEAD,
734 .algorithm_ssl = SSL_TLSV1_3,
735 .algo_strength = SSL_HIGH,
736 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256, /* XXX */
737 .strength_bits = 128,
738 .alg_bits = 128,
739 },
740 {
741 .value = 0x1302,
742 .name = TLS1_3_RFC_AES_256_GCM_SHA384,
743 .algorithm_mkey = SSL_kTLS1_3,
744 .algorithm_auth = SSL_aTLS1_3,
745 .algorithm_enc = SSL_AES256GCM,
746 .algorithm_mac = SSL_AEAD,
747 .algorithm_ssl = SSL_TLSV1_3,
748 .algo_strength = SSL_HIGH,
749 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384, /* XXX */
750 .strength_bits = 256,
751 .alg_bits = 256,
752 },
753 {
754 .value = 0x1303,
755 .name = TLS1_3_RFC_CHACHA20_POLY1305_SHA256,
756 .algorithm_mkey = SSL_kTLS1_3,
757 .algorithm_auth = SSL_aTLS1_3,
758 .algorithm_enc = SSL_CHACHA20POLY1305,
759 .algorithm_mac = SSL_AEAD,
760 .algorithm_ssl = SSL_TLSV1_3,
761 .algo_strength = SSL_HIGH,
762 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256, /* XXX */
763 .strength_bits = 256,
764 .alg_bits = 256,
765 },
766#endif
767
768 /*
769 * TLSv1.0 Elliptic Curve cipher suites (RFC 4492, section 6).
770 */
771 {
772 .value = 0xc006,
773 .name = TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA,
774 .algorithm_mkey = SSL_kECDHE,
775 .algorithm_auth = SSL_aECDSA,
776 .algorithm_enc = SSL_eNULL,
777 .algorithm_mac = SSL_SHA1,
778 .algorithm_ssl = SSL_TLSV1,
779 .algo_strength = SSL_STRONG_NONE,
780 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
781 .strength_bits = 0,
782 .alg_bits = 0,
783 },
784 {
785 .value = 0xc007,
786 .name = TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA,
787 .algorithm_mkey = SSL_kECDHE,
788 .algorithm_auth = SSL_aECDSA,
789 .algorithm_enc = SSL_RC4,
790 .algorithm_mac = SSL_SHA1,
791 .algorithm_ssl = SSL_TLSV1,
792 .algo_strength = SSL_LOW,
793 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
794 .strength_bits = 128,
795 .alg_bits = 128,
796 },
797 {
798 .value = 0xc008,
799 .name = TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA,
800 .algorithm_mkey = SSL_kECDHE,
801 .algorithm_auth = SSL_aECDSA,
802 .algorithm_enc = SSL_3DES,
803 .algorithm_mac = SSL_SHA1,
804 .algorithm_ssl = SSL_TLSV1,
805 .algo_strength = SSL_MEDIUM,
806 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
807 .strength_bits = 112,
808 .alg_bits = 168,
809 },
810 {
811 .value = 0xc009,
812 .name = TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
813 .algorithm_mkey = SSL_kECDHE,
814 .algorithm_auth = SSL_aECDSA,
815 .algorithm_enc = SSL_AES128,
816 .algorithm_mac = SSL_SHA1,
817 .algorithm_ssl = SSL_TLSV1,
818 .algo_strength = SSL_HIGH,
819 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
820 .strength_bits = 128,
821 .alg_bits = 128,
822 },
823 {
824 .value = 0xc00a,
825 .name = TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
826 .algorithm_mkey = SSL_kECDHE,
827 .algorithm_auth = SSL_aECDSA,
828 .algorithm_enc = SSL_AES256,
829 .algorithm_mac = SSL_SHA1,
830 .algorithm_ssl = SSL_TLSV1,
831 .algo_strength = SSL_HIGH,
832 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
833 .strength_bits = 256,
834 .alg_bits = 256,
835 },
836 {
837 .value = 0xc010,
838 .name = TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA,
839 .algorithm_mkey = SSL_kECDHE,
840 .algorithm_auth = SSL_aRSA,
841 .algorithm_enc = SSL_eNULL,
842 .algorithm_mac = SSL_SHA1,
843 .algorithm_ssl = SSL_TLSV1,
844 .algo_strength = SSL_STRONG_NONE,
845 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
846 .strength_bits = 0,
847 .alg_bits = 0,
848 },
849 {
850 .value = 0xc011,
851 .name = TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA,
852 .algorithm_mkey = SSL_kECDHE,
853 .algorithm_auth = SSL_aRSA,
854 .algorithm_enc = SSL_RC4,
855 .algorithm_mac = SSL_SHA1,
856 .algorithm_ssl = SSL_TLSV1,
857 .algo_strength = SSL_LOW,
858 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
859 .strength_bits = 128,
860 .alg_bits = 128,
861 },
862 {
863 .value = 0xc012,
864 .name = TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA,
865 .algorithm_mkey = SSL_kECDHE,
866 .algorithm_auth = SSL_aRSA,
867 .algorithm_enc = SSL_3DES,
868 .algorithm_mac = SSL_SHA1,
869 .algorithm_ssl = SSL_TLSV1,
870 .algo_strength = SSL_MEDIUM,
871 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
872 .strength_bits = 112,
873 .alg_bits = 168,
874 },
875 {
876 .value = 0xc013,
877 .name = TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA,
878 .algorithm_mkey = SSL_kECDHE,
879 .algorithm_auth = SSL_aRSA,
880 .algorithm_enc = SSL_AES128,
881 .algorithm_mac = SSL_SHA1,
882 .algorithm_ssl = SSL_TLSV1,
883 .algo_strength = SSL_HIGH,
884 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
885 .strength_bits = 128,
886 .alg_bits = 128,
887 },
888 {
889 .value = 0xc014,
890 .name = TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA,
891 .algorithm_mkey = SSL_kECDHE,
892 .algorithm_auth = SSL_aRSA,
893 .algorithm_enc = SSL_AES256,
894 .algorithm_mac = SSL_SHA1,
895 .algorithm_ssl = SSL_TLSV1,
896 .algo_strength = SSL_HIGH,
897 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
898 .strength_bits = 256,
899 .alg_bits = 256,
900 },
901 {
902 .value = 0xc015,
903 .name = TLS1_TXT_ECDH_anon_WITH_NULL_SHA,
904 .algorithm_mkey = SSL_kECDHE,
905 .algorithm_auth = SSL_aNULL,
906 .algorithm_enc = SSL_eNULL,
907 .algorithm_mac = SSL_SHA1,
908 .algorithm_ssl = SSL_TLSV1,
909 .algo_strength = SSL_STRONG_NONE,
910 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
911 .strength_bits = 0,
912 .alg_bits = 0,
913 },
914 {
915 .value = 0xc016,
916 .name = TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA,
917 .algorithm_mkey = SSL_kECDHE,
918 .algorithm_auth = SSL_aNULL,
919 .algorithm_enc = SSL_RC4,
920 .algorithm_mac = SSL_SHA1,
921 .algorithm_ssl = SSL_TLSV1,
922 .algo_strength = SSL_LOW,
923 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
924 .strength_bits = 128,
925 .alg_bits = 128,
926 },
927 {
928 .value = 0xc017,
929 .name = TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA,
930 .algorithm_mkey = SSL_kECDHE,
931 .algorithm_auth = SSL_aNULL,
932 .algorithm_enc = SSL_3DES,
933 .algorithm_mac = SSL_SHA1,
934 .algorithm_ssl = SSL_TLSV1,
935 .algo_strength = SSL_MEDIUM,
936 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
937 .strength_bits = 112,
938 .alg_bits = 168,
939 },
940 {
941 .value = 0xc018,
942 .name = TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA,
943 .algorithm_mkey = SSL_kECDHE,
944 .algorithm_auth = SSL_aNULL,
945 .algorithm_enc = SSL_AES128,
946 .algorithm_mac = SSL_SHA1,
947 .algorithm_ssl = SSL_TLSV1,
948 .algo_strength = SSL_HIGH,
949 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
950 .strength_bits = 128,
951 .alg_bits = 128,
952 },
953 {
954 .value = 0xc019,
955 .name = TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA,
956 .algorithm_mkey = SSL_kECDHE,
957 .algorithm_auth = SSL_aNULL,
958 .algorithm_enc = SSL_AES256,
959 .algorithm_mac = SSL_SHA1,
960 .algorithm_ssl = SSL_TLSV1,
961 .algo_strength = SSL_HIGH,
962 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
963 .strength_bits = 256,
964 .alg_bits = 256,
965 },
966
967 /*
968 * TLSv1.2 Elliptic Curve HMAC cipher suites (RFC 5289, section 3.1).
969 */
970 {
971 .value = 0xc023,
972 .name = TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_SHA256,
973 .algorithm_mkey = SSL_kECDHE,
974 .algorithm_auth = SSL_aECDSA,
975 .algorithm_enc = SSL_AES128,
976 .algorithm_mac = SSL_SHA256,
977 .algorithm_ssl = SSL_TLSV1_2,
978 .algo_strength = SSL_HIGH,
979 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
980 .strength_bits = 128,
981 .alg_bits = 128,
982 },
983 {
984 .value = 0xc024,
985 .name = TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_SHA384,
986 .algorithm_mkey = SSL_kECDHE,
987 .algorithm_auth = SSL_aECDSA,
988 .algorithm_enc = SSL_AES256,
989 .algorithm_mac = SSL_SHA384,
990 .algorithm_ssl = SSL_TLSV1_2,
991 .algo_strength = SSL_HIGH,
992 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
993 .strength_bits = 256,
994 .alg_bits = 256,
995 },
996 {
997 .value = 0xc027,
998 .name = TLS1_TXT_ECDHE_RSA_WITH_AES_128_SHA256,
999 .algorithm_mkey = SSL_kECDHE,
1000 .algorithm_auth = SSL_aRSA,
1001 .algorithm_enc = SSL_AES128,
1002 .algorithm_mac = SSL_SHA256,
1003 .algorithm_ssl = SSL_TLSV1_2,
1004 .algo_strength = SSL_HIGH,
1005 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
1006 .strength_bits = 128,
1007 .alg_bits = 128,
1008 },
1009 {
1010 .value = 0xc028,
1011 .name = TLS1_TXT_ECDHE_RSA_WITH_AES_256_SHA384,
1012 .algorithm_mkey = SSL_kECDHE,
1013 .algorithm_auth = SSL_aRSA,
1014 .algorithm_enc = SSL_AES256,
1015 .algorithm_mac = SSL_SHA384,
1016 .algorithm_ssl = SSL_TLSV1_2,
1017 .algo_strength = SSL_HIGH,
1018 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
1019 .strength_bits = 256,
1020 .alg_bits = 256,
1021 },
1022
1023 /*
1024 * TLSv1.2 Elliptic Curve GCM cipher suites (RFC 5289, section 3.2).
1025 */
1026 {
1027 .value = 0xc02b,
1028 .name = TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
1029 .algorithm_mkey = SSL_kECDHE,
1030 .algorithm_auth = SSL_aECDSA,
1031 .algorithm_enc = SSL_AES128GCM,
1032 .algorithm_mac = SSL_AEAD,
1033 .algorithm_ssl = SSL_TLSV1_2,
1034 .algo_strength = SSL_HIGH,
1035 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
1036 .strength_bits = 128,
1037 .alg_bits = 128,
1038 },
1039 {
1040 .value = 0xc02c,
1041 .name = TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
1042 .algorithm_mkey = SSL_kECDHE,
1043 .algorithm_auth = SSL_aECDSA,
1044 .algorithm_enc = SSL_AES256GCM,
1045 .algorithm_mac = SSL_AEAD,
1046 .algorithm_ssl = SSL_TLSV1_2,
1047 .algo_strength = SSL_HIGH,
1048 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
1049 .strength_bits = 256,
1050 .alg_bits = 256,
1051 },
1052 {
1053 .value = 0xc02f,
1054 .name = TLS1_TXT_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
1055 .algorithm_mkey = SSL_kECDHE,
1056 .algorithm_auth = SSL_aRSA,
1057 .algorithm_enc = SSL_AES128GCM,
1058 .algorithm_mac = SSL_AEAD,
1059 .algorithm_ssl = SSL_TLSV1_2,
1060 .algo_strength = SSL_HIGH,
1061 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
1062 .strength_bits = 128,
1063 .alg_bits = 128,
1064 },
1065 {
1066 .value = 0xc030,
1067 .name = TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
1068 .algorithm_mkey = SSL_kECDHE,
1069 .algorithm_auth = SSL_aRSA,
1070 .algorithm_enc = SSL_AES256GCM,
1071 .algorithm_mac = SSL_AEAD,
1072 .algorithm_ssl = SSL_TLSV1_2,
1073 .algo_strength = SSL_HIGH,
1074 .algorithm2 = SSL_HANDSHAKE_MAC_SHA384,
1075 .strength_bits = 256,
1076 .alg_bits = 256,
1077 },
1078
1079 /*
1080 * TLSv1.2 ChaCha20-Poly1305 cipher suites (RFC 7905).
1081 */
1082 {
1083 .value = 0xcca8,
1084 .name = TLS1_TXT_ECDHE_RSA_WITH_CHACHA20_POLY1305,
1085 .algorithm_mkey = SSL_kECDHE,
1086 .algorithm_auth = SSL_aRSA,
1087 .algorithm_enc = SSL_CHACHA20POLY1305,
1088 .algorithm_mac = SSL_AEAD,
1089 .algorithm_ssl = SSL_TLSV1_2,
1090 .algo_strength = SSL_HIGH,
1091 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
1092 .strength_bits = 256,
1093 .alg_bits = 256,
1094 },
1095 {
1096 .value = 0xcca9,
1097 .name = TLS1_TXT_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
1098 .algorithm_mkey = SSL_kECDHE,
1099 .algorithm_auth = SSL_aECDSA,
1100 .algorithm_enc = SSL_CHACHA20POLY1305,
1101 .algorithm_mac = SSL_AEAD,
1102 .algorithm_ssl = SSL_TLSV1_2,
1103 .algo_strength = SSL_HIGH,
1104 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
1105 .strength_bits = 256,
1106 .alg_bits = 256,
1107 },
1108 {
1109 .value = 0xccaa,
1110 .name = TLS1_TXT_DHE_RSA_WITH_CHACHA20_POLY1305,
1111 .algorithm_mkey = SSL_kDHE,
1112 .algorithm_auth = SSL_aRSA,
1113 .algorithm_enc = SSL_CHACHA20POLY1305,
1114 .algorithm_mac = SSL_AEAD,
1115 .algorithm_ssl = SSL_TLSV1_2,
1116 .algo_strength = SSL_HIGH,
1117 .algorithm2 = SSL_HANDSHAKE_MAC_SHA256,
1118 .strength_bits = 256,
1119 .alg_bits = 256,
1120 },
1121};
1122
1123int
1124ssl3_num_ciphers(void)
1125{
1126 return (SSL3_NUM_CIPHERS);
1127}
1128
1129const SSL_CIPHER *
1130ssl3_get_cipher_by_index(int idx)
1131{
1132 if (idx < 0 || idx >= SSL3_NUM_CIPHERS)
1133 return NULL;
1134
1135 return &ssl3_ciphers[idx];
1136}
1137
1138static int
1139ssl3_cipher_value_cmp(const void *value, const void *cipher)
1140{
1141 uint16_t a = *(const uint16_t *)value;
1142 uint16_t b = ((const SSL_CIPHER *)cipher)->value;
1143
1144 return a < b ? -1 : a > b;
1145}
1146
1147const SSL_CIPHER *
1148ssl3_get_cipher_by_value(uint16_t value)
1149{
1150 return bsearch(&value, ssl3_ciphers, SSL3_NUM_CIPHERS,
1151 sizeof(ssl3_ciphers[0]), ssl3_cipher_value_cmp);
1152}
1153
1154int
1155ssl3_pending(const SSL *s)
1156{
1157 if (s->s3->rcontent == NULL)
1158 return 0;
1159 if (tls_content_type(s->s3->rcontent) != SSL3_RT_APPLICATION_DATA)
1160 return 0;
1161
1162 return tls_content_remaining(s->s3->rcontent);
1163}
1164
1165int
1166ssl3_handshake_msg_hdr_len(SSL *s)
1167{
1168 return (SSL_is_dtls(s) ? DTLS1_HM_HEADER_LENGTH :
1169 SSL3_HM_HEADER_LENGTH);
1170}
1171
1172int
1173ssl3_handshake_msg_start(SSL *s, CBB *handshake, CBB *body, uint8_t msg_type)
1174{
1175 int ret = 0;
1176
1177 if (!CBB_init(handshake, SSL3_RT_MAX_PLAIN_LENGTH))
1178 goto err;
1179 if (!CBB_add_u8(handshake, msg_type))
1180 goto err;
1181 if (SSL_is_dtls(s)) {
1182 unsigned char *data;
1183
1184 if (!CBB_add_space(handshake, &data, DTLS1_HM_HEADER_LENGTH -
1185 SSL3_HM_HEADER_LENGTH))
1186 goto err;
1187 }
1188 if (!CBB_add_u24_length_prefixed(handshake, body))
1189 goto err;
1190
1191 ret = 1;
1192
1193 err:
1194 return (ret);
1195}
1196
1197int
1198ssl3_handshake_msg_finish(SSL *s, CBB *handshake)
1199{
1200 unsigned char *data = NULL;
1201 size_t outlen;
1202 int ret = 0;
1203
1204 if (!CBB_finish(handshake, &data, &outlen))
1205 goto err;
1206
1207 if (outlen > INT_MAX)
1208 goto err;
1209
1210 if (!BUF_MEM_grow_clean(s->init_buf, outlen))
1211 goto err;
1212
1213 memcpy(s->init_buf->data, data, outlen);
1214
1215 s->init_num = (int)outlen;
1216 s->init_off = 0;
1217
1218 if (SSL_is_dtls(s)) {
1219 unsigned long len;
1220 uint8_t msg_type;
1221 CBS cbs;
1222
1223 CBS_init(&cbs, data, outlen);
1224 if (!CBS_get_u8(&cbs, &msg_type))
1225 goto err;
1226
1227 len = outlen - ssl3_handshake_msg_hdr_len(s);
1228
1229 dtls1_set_message_header(s, msg_type, len, 0, len);
1230 dtls1_buffer_message(s, 0);
1231 }
1232
1233 ret = 1;
1234
1235 err:
1236 free(data);
1237
1238 return (ret);
1239}
1240
1241int
1242ssl3_handshake_write(SSL *s)
1243{
1244 return ssl3_record_write(s, SSL3_RT_HANDSHAKE);
1245}
1246
1247int
1248ssl3_record_write(SSL *s, int type)
1249{
1250 if (SSL_is_dtls(s))
1251 return dtls1_do_write(s, type);
1252
1253 return ssl3_do_write(s, type);
1254}
1255
1256int
1257ssl3_new(SSL *s)
1258{
1259 if ((s->s3 = calloc(1, sizeof(*s->s3))) == NULL)
1260 return (0);
1261
1262 s->method->ssl_clear(s);
1263
1264 return (1);
1265}
1266
1267void
1268ssl3_free(SSL *s)
1269{
1270 if (s == NULL)
1271 return;
1272
1273 tls1_cleanup_key_block(s);
1274 ssl3_release_read_buffer(s);
1275 ssl3_release_write_buffer(s);
1276
1277 tls_content_free(s->s3->rcontent);
1278
1279 tls_buffer_free(s->s3->alert_fragment);
1280 tls_buffer_free(s->s3->handshake_fragment);
1281
1282 freezero(s->s3->hs.sigalgs, s->s3->hs.sigalgs_len);
1283
1284 sk_SSL_CIPHER_free(s->s3->hs.client_ciphers);
1285 sk_X509_pop_free(s->s3->hs.peer_certs, X509_free);
1286 sk_X509_pop_free(s->s3->hs.peer_certs_no_leaf, X509_free);
1287 sk_X509_pop_free(s->s3->hs.verified_chain, X509_free);
1288 tls_key_share_free(s->s3->hs.key_share);
1289
1290 tls13_secrets_destroy(s->s3->hs.tls13.secrets);
1291 freezero(s->s3->hs.tls13.cookie, s->s3->hs.tls13.cookie_len);
1292 tls13_clienthello_hash_clear(&s->s3->hs.tls13);
1293
1294 tls_buffer_free(s->s3->hs.tls13.quic_read_buffer);
1295
1296 sk_X509_NAME_pop_free(s->s3->hs.tls12.ca_names, X509_NAME_free);
1297
1298 tls1_transcript_free(s);
1299 tls1_transcript_hash_free(s);
1300
1301 free(s->s3->alpn_selected);
1302
1303 freezero(s->s3->peer_quic_transport_params,
1304 s->s3->peer_quic_transport_params_len);
1305
1306 freezero(s->s3, sizeof(*s->s3));
1307
1308 s->s3 = NULL;
1309}
1310
1311void
1312ssl3_clear(SSL *s)
1313{
1314 unsigned char *rp, *wp;
1315 size_t rlen, wlen;
1316
1317 tls1_cleanup_key_block(s);
1318 sk_X509_NAME_pop_free(s->s3->hs.tls12.ca_names, X509_NAME_free);
1319
1320 tls_buffer_free(s->s3->alert_fragment);
1321 s->s3->alert_fragment = NULL;
1322 tls_buffer_free(s->s3->handshake_fragment);
1323 s->s3->handshake_fragment = NULL;
1324
1325 freezero(s->s3->hs.sigalgs, s->s3->hs.sigalgs_len);
1326 s->s3->hs.sigalgs = NULL;
1327 s->s3->hs.sigalgs_len = 0;
1328
1329 sk_SSL_CIPHER_free(s->s3->hs.client_ciphers);
1330 s->s3->hs.client_ciphers = NULL;
1331 sk_X509_pop_free(s->s3->hs.peer_certs, X509_free);
1332 s->s3->hs.peer_certs = NULL;
1333 sk_X509_pop_free(s->s3->hs.peer_certs_no_leaf, X509_free);
1334 s->s3->hs.peer_certs_no_leaf = NULL;
1335 sk_X509_pop_free(s->s3->hs.verified_chain, X509_free);
1336 s->s3->hs.verified_chain = NULL;
1337
1338 tls_key_share_free(s->s3->hs.key_share);
1339 s->s3->hs.key_share = NULL;
1340
1341 tls13_secrets_destroy(s->s3->hs.tls13.secrets);
1342 s->s3->hs.tls13.secrets = NULL;
1343 freezero(s->s3->hs.tls13.cookie, s->s3->hs.tls13.cookie_len);
1344 s->s3->hs.tls13.cookie = NULL;
1345 s->s3->hs.tls13.cookie_len = 0;
1346 tls13_clienthello_hash_clear(&s->s3->hs.tls13);
1347
1348 tls_buffer_free(s->s3->hs.tls13.quic_read_buffer);
1349 s->s3->hs.tls13.quic_read_buffer = NULL;
1350 s->s3->hs.tls13.quic_read_level = ssl_encryption_initial;
1351 s->s3->hs.tls13.quic_write_level = ssl_encryption_initial;
1352
1353 s->s3->hs.extensions_seen = 0;
1354
1355 rp = s->s3->rbuf.buf;
1356 wp = s->s3->wbuf.buf;
1357 rlen = s->s3->rbuf.len;
1358 wlen = s->s3->wbuf.len;
1359
1360 tls_content_free(s->s3->rcontent);
1361 s->s3->rcontent = NULL;
1362
1363 tls1_transcript_free(s);
1364 tls1_transcript_hash_free(s);
1365
1366 free(s->s3->alpn_selected);
1367 s->s3->alpn_selected = NULL;
1368 s->s3->alpn_selected_len = 0;
1369
1370 freezero(s->s3->peer_quic_transport_params,
1371 s->s3->peer_quic_transport_params_len);
1372 s->s3->peer_quic_transport_params = NULL;
1373 s->s3->peer_quic_transport_params_len = 0;
1374
1375 memset(s->s3, 0, sizeof(*s->s3));
1376
1377 s->s3->rbuf.buf = rp;
1378 s->s3->wbuf.buf = wp;
1379 s->s3->rbuf.len = rlen;
1380 s->s3->wbuf.len = wlen;
1381
1382 ssl_free_wbio_buffer(s);
1383
1384 /* Not needed... */
1385 s->s3->renegotiate = 0;
1386 s->s3->total_renegotiations = 0;
1387 s->s3->num_renegotiations = 0;
1388 s->s3->in_read_app_data = 0;
1389
1390 s->packet_length = 0;
1391 s->version = TLS1_2_VERSION;
1392
1393 s->s3->hs.state = SSL_ST_BEFORE|((s->server) ? SSL_ST_ACCEPT : SSL_ST_CONNECT);
1394}
1395
1396long
1397_SSL_get_shared_group(SSL *s, long n)
1398{
1399 size_t count;
1400 int nid;
1401
1402 /* OpenSSL document that they return -1 for clients. They return 0. */
1403 if (!s->server)
1404 return 0;
1405
1406 if (n == -1) {
1407 if (!tls1_count_shared_groups(s, &count))
1408 return 0;
1409
1410 if (count > LONG_MAX)
1411 count = LONG_MAX;
1412
1413 return count;
1414 }
1415
1416 /* Undocumented special case added for Suite B profile support. */
1417 if (n == -2)
1418 n = 0;
1419
1420 if (n < 0)
1421 return 0;
1422
1423 if (!tls1_get_shared_group_by_index(s, n, &nid))
1424 return NID_undef;
1425
1426 return nid;
1427}
1428
1429long
1430_SSL_get_peer_tmp_key(SSL *s, EVP_PKEY **key)
1431{
1432 EVP_PKEY *pkey = NULL;
1433 int ret = 0;
1434
1435 *key = NULL;
1436
1437 if (s->s3->hs.key_share == NULL)
1438 goto err;
1439
1440 if ((pkey = EVP_PKEY_new()) == NULL)
1441 goto err;
1442 if (!tls_key_share_peer_pkey(s->s3->hs.key_share, pkey))
1443 goto err;
1444
1445 *key = pkey;
1446 pkey = NULL;
1447
1448 ret = 1;
1449
1450 err:
1451 EVP_PKEY_free(pkey);
1452
1453 return (ret);
1454}
1455
1456static int
1457_SSL_session_reused(SSL *s)
1458{
1459 return s->hit;
1460}
1461
1462static int
1463_SSL_num_renegotiations(SSL *s)
1464{
1465 return s->s3->num_renegotiations;
1466}
1467
1468static int
1469_SSL_clear_num_renegotiations(SSL *s)
1470{
1471 int renegs;
1472
1473 renegs = s->s3->num_renegotiations;
1474 s->s3->num_renegotiations = 0;
1475
1476 return renegs;
1477}
1478
1479static int
1480_SSL_total_renegotiations(SSL *s)
1481{
1482 return s->s3->total_renegotiations;
1483}
1484
1485static int
1486_SSL_set_tmp_dh(SSL *s, DH *dh)
1487{
1488 DH *dhe_params;
1489
1490 if (dh == NULL) {
1491 SSLerror(s, ERR_R_PASSED_NULL_PARAMETER);
1492 return 0;
1493 }
1494
1495 if (!ssl_security_dh(s, dh)) {
1496 SSLerror(s, SSL_R_DH_KEY_TOO_SMALL);
1497 return 0;
1498 }
1499
1500 if ((dhe_params = DHparams_dup(dh)) == NULL) {
1501 SSLerror(s, ERR_R_DH_LIB);
1502 return 0;
1503 }
1504
1505 DH_free(s->cert->dhe_params);
1506 s->cert->dhe_params = dhe_params;
1507
1508 return 1;
1509}
1510
1511static int
1512_SSL_set_dh_auto(SSL *s, int state)
1513{
1514 s->cert->dhe_params_auto = state;
1515 return 1;
1516}
1517
1518static int
1519_SSL_set_tmp_ecdh(SSL *s, EC_KEY *ecdh)
1520{
1521 const EC_GROUP *group;
1522 int nid;
1523
1524 if (ecdh == NULL)
1525 return 0;
1526 if ((group = EC_KEY_get0_group(ecdh)) == NULL)
1527 return 0;
1528
1529 nid = EC_GROUP_get_curve_name(group);
1530 return SSL_set1_groups(s, &nid, 1);
1531}
1532
1533static int
1534_SSL_set_ecdh_auto(SSL *s, int state)
1535{
1536 return 1;
1537}
1538
1539static int
1540_SSL_set_tlsext_host_name(SSL *s, const char *name)
1541{
1542 int is_ip;
1543 CBS cbs;
1544
1545 free(s->tlsext_hostname);
1546 s->tlsext_hostname = NULL;
1547
1548 if (name == NULL)
1549 return 1;
1550
1551 CBS_init(&cbs, name, strlen(name));
1552
1553 if (!tlsext_sni_is_valid_hostname(&cbs, &is_ip)) {
1554 SSLerror(s, SSL_R_SSL3_EXT_INVALID_SERVERNAME);
1555 return 0;
1556 }
1557 if ((s->tlsext_hostname = strdup(name)) == NULL) {
1558 SSLerror(s, ERR_R_INTERNAL_ERROR);
1559 return 0;
1560 }
1561
1562 return 1;
1563}
1564
1565static int
1566_SSL_set_tlsext_debug_arg(SSL *s, void *arg)
1567{
1568 s->tlsext_debug_arg = arg;
1569 return 1;
1570}
1571
1572static int
1573_SSL_get_tlsext_status_type(SSL *s)
1574{
1575 return s->tlsext_status_type;
1576}
1577
1578static int
1579_SSL_set_tlsext_status_type(SSL *s, int type)
1580{
1581 s->tlsext_status_type = type;
1582 return 1;
1583}
1584
1585static int
1586_SSL_get_tlsext_status_exts(SSL *s, STACK_OF(X509_EXTENSION) **exts)
1587{
1588 *exts = s->tlsext_ocsp_exts;
1589 return 1;
1590}
1591
1592static int
1593_SSL_set_tlsext_status_exts(SSL *s, STACK_OF(X509_EXTENSION) *exts)
1594{
1595 /* XXX - leak... */
1596 s->tlsext_ocsp_exts = exts;
1597 return 1;
1598}
1599
1600static int
1601_SSL_get_tlsext_status_ids(SSL *s, STACK_OF(OCSP_RESPID) **ids)
1602{
1603 *ids = s->tlsext_ocsp_ids;
1604 return 1;
1605}
1606
1607static int
1608_SSL_set_tlsext_status_ids(SSL *s, STACK_OF(OCSP_RESPID) *ids)
1609{
1610 /* XXX - leak... */
1611 s->tlsext_ocsp_ids = ids;
1612 return 1;
1613}
1614
1615static int
1616_SSL_get_tlsext_status_ocsp_resp(SSL *s, unsigned char **resp)
1617{
1618 if (s->tlsext_ocsp_resp != NULL &&
1619 s->tlsext_ocsp_resp_len < INT_MAX) {
1620 *resp = s->tlsext_ocsp_resp;
1621 return (int)s->tlsext_ocsp_resp_len;
1622 }
1623
1624 *resp = NULL;
1625
1626 return -1;
1627}
1628
1629static int
1630_SSL_set_tlsext_status_ocsp_resp(SSL *s, unsigned char *resp, int resp_len)
1631{
1632 free(s->tlsext_ocsp_resp);
1633 s->tlsext_ocsp_resp = NULL;
1634 s->tlsext_ocsp_resp_len = 0;
1635
1636 if (resp_len < 0)
1637 return 0;
1638
1639 s->tlsext_ocsp_resp = resp;
1640 s->tlsext_ocsp_resp_len = (size_t)resp_len;
1641
1642 return 1;
1643}
1644
1645int
1646SSL_set0_chain(SSL *ssl, STACK_OF(X509) *chain)
1647{
1648 return ssl_cert_set0_chain(NULL, ssl, chain);
1649}
1650LSSL_ALIAS(SSL_set0_chain);
1651
1652int
1653SSL_set1_chain(SSL *ssl, STACK_OF(X509) *chain)
1654{
1655 return ssl_cert_set1_chain(NULL, ssl, chain);
1656}
1657LSSL_ALIAS(SSL_set1_chain);
1658
1659int
1660SSL_add0_chain_cert(SSL *ssl, X509 *x509)
1661{
1662 return ssl_cert_add0_chain_cert(NULL, ssl, x509);
1663}
1664LSSL_ALIAS(SSL_add0_chain_cert);
1665
1666int
1667SSL_add1_chain_cert(SSL *ssl, X509 *x509)
1668{
1669 return ssl_cert_add1_chain_cert(NULL, ssl, x509);
1670}
1671LSSL_ALIAS(SSL_add1_chain_cert);
1672
1673int
1674SSL_get0_chain_certs(const SSL *ssl, STACK_OF(X509) **out_chain)
1675{
1676 *out_chain = NULL;
1677
1678 if (ssl->cert->key != NULL)
1679 *out_chain = ssl->cert->key->chain;
1680
1681 return 1;
1682}
1683LSSL_ALIAS(SSL_get0_chain_certs);
1684
1685int
1686SSL_clear_chain_certs(SSL *ssl)
1687{
1688 return ssl_cert_set0_chain(NULL, ssl, NULL);
1689}
1690LSSL_ALIAS(SSL_clear_chain_certs);
1691
1692int
1693SSL_set1_groups(SSL *s, const int *groups, size_t groups_len)
1694{
1695 return tls1_set_groups(&s->tlsext_supportedgroups,
1696 &s->tlsext_supportedgroups_length, groups, groups_len);
1697}
1698LSSL_ALIAS(SSL_set1_groups);
1699
1700int
1701SSL_set1_groups_list(SSL *s, const char *groups)
1702{
1703 return tls1_set_group_list(&s->tlsext_supportedgroups,
1704 &s->tlsext_supportedgroups_length, groups);
1705}
1706LSSL_ALIAS(SSL_set1_groups_list);
1707
1708static int
1709_SSL_get_signature_nid(SSL *s, int *nid)
1710{
1711 const struct ssl_sigalg *sigalg;
1712
1713 if ((sigalg = s->s3->hs.our_sigalg) == NULL)
1714 return 0;
1715
1716 *nid = EVP_MD_type(sigalg->md());
1717
1718 return 1;
1719}
1720
1721static int
1722_SSL_get_peer_signature_nid(SSL *s, int *nid)
1723{
1724 const struct ssl_sigalg *sigalg;
1725
1726 if ((sigalg = s->s3->hs.peer_sigalg) == NULL)
1727 return 0;
1728
1729 *nid = EVP_MD_type(sigalg->md());
1730
1731 return 1;
1732}
1733
1734int
1735SSL_get_signature_type_nid(const SSL *s, int *nid)
1736{
1737 const struct ssl_sigalg *sigalg;
1738
1739 if ((sigalg = s->s3->hs.our_sigalg) == NULL)
1740 return 0;
1741
1742 *nid = sigalg->key_type;
1743 if (sigalg->key_type == EVP_PKEY_RSA &&
1744 (sigalg->flags & SIGALG_FLAG_RSA_PSS))
1745 *nid = EVP_PKEY_RSA_PSS;
1746
1747 return 1;
1748}
1749LSSL_ALIAS(SSL_get_signature_type_nid);
1750
1751int
1752SSL_get_peer_signature_type_nid(const SSL *s, int *nid)
1753{
1754 const struct ssl_sigalg *sigalg;
1755
1756 if ((sigalg = s->s3->hs.peer_sigalg) == NULL)
1757 return 0;
1758
1759 *nid = sigalg->key_type;
1760 if (sigalg->key_type == EVP_PKEY_RSA &&
1761 (sigalg->flags & SIGALG_FLAG_RSA_PSS))
1762 *nid = EVP_PKEY_RSA_PSS;
1763
1764 return 1;
1765}
1766LSSL_ALIAS(SSL_get_peer_signature_type_nid);
1767
1768long
1769ssl3_ctrl(SSL *s, int cmd, long larg, void *parg)
1770{
1771 switch (cmd) {
1772 case SSL_CTRL_GET_SESSION_REUSED:
1773 return _SSL_session_reused(s);
1774
1775 case SSL_CTRL_GET_NUM_RENEGOTIATIONS:
1776 return _SSL_num_renegotiations(s);
1777
1778 case SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS:
1779 return _SSL_clear_num_renegotiations(s);
1780
1781 case SSL_CTRL_GET_TOTAL_RENEGOTIATIONS:
1782 return _SSL_total_renegotiations(s);
1783
1784 case SSL_CTRL_SET_TMP_DH:
1785 return _SSL_set_tmp_dh(s, parg);
1786
1787 case SSL_CTRL_SET_TMP_DH_CB:
1788 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1789 return 0;
1790
1791 case SSL_CTRL_SET_DH_AUTO:
1792 return _SSL_set_dh_auto(s, larg);
1793
1794 case SSL_CTRL_SET_TMP_ECDH:
1795 return _SSL_set_tmp_ecdh(s, parg);
1796
1797 case SSL_CTRL_SET_TMP_ECDH_CB:
1798 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1799 return 0;
1800
1801 case SSL_CTRL_SET_ECDH_AUTO:
1802 return _SSL_set_ecdh_auto(s, larg);
1803
1804 case SSL_CTRL_SET_TLSEXT_HOSTNAME:
1805 if (larg != TLSEXT_NAMETYPE_host_name) {
1806 SSLerror(s, SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE);
1807 return 0;
1808 }
1809 return _SSL_set_tlsext_host_name(s, parg);
1810
1811 case SSL_CTRL_SET_TLSEXT_DEBUG_ARG:
1812 return _SSL_set_tlsext_debug_arg(s, parg);
1813
1814 case SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE:
1815 return _SSL_get_tlsext_status_type(s);
1816
1817 case SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE:
1818 return _SSL_set_tlsext_status_type(s, larg);
1819
1820 case SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS:
1821 return _SSL_get_tlsext_status_exts(s, parg);
1822
1823 case SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS:
1824 return _SSL_set_tlsext_status_exts(s, parg);
1825
1826 case SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS:
1827 return _SSL_get_tlsext_status_ids(s, parg);
1828
1829 case SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS:
1830 return _SSL_set_tlsext_status_ids(s, parg);
1831
1832 case SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP:
1833 return _SSL_get_tlsext_status_ocsp_resp(s, parg);
1834
1835 case SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP:
1836 return _SSL_set_tlsext_status_ocsp_resp(s, parg, larg);
1837
1838 case SSL_CTRL_CHAIN:
1839 if (larg == 0)
1840 return SSL_set0_chain(s, (STACK_OF(X509) *)parg);
1841 else
1842 return SSL_set1_chain(s, (STACK_OF(X509) *)parg);
1843
1844 case SSL_CTRL_CHAIN_CERT:
1845 if (larg == 0)
1846 return SSL_add0_chain_cert(s, (X509 *)parg);
1847 else
1848 return SSL_add1_chain_cert(s, (X509 *)parg);
1849
1850 case SSL_CTRL_GET_CHAIN_CERTS:
1851 return SSL_get0_chain_certs(s, (STACK_OF(X509) **)parg);
1852
1853 case SSL_CTRL_SET_GROUPS:
1854 return SSL_set1_groups(s, parg, larg);
1855
1856 case SSL_CTRL_SET_GROUPS_LIST:
1857 return SSL_set1_groups_list(s, parg);
1858
1859 case SSL_CTRL_GET_SHARED_GROUP:
1860 return _SSL_get_shared_group(s, larg);
1861
1862 /* XXX - rename to SSL_CTRL_GET_PEER_TMP_KEY and remove server check. */
1863 case SSL_CTRL_GET_SERVER_TMP_KEY:
1864 if (s->server != 0)
1865 return 0;
1866 return _SSL_get_peer_tmp_key(s, parg);
1867
1868 case SSL_CTRL_GET_MIN_PROTO_VERSION:
1869 return SSL_get_min_proto_version(s);
1870
1871 case SSL_CTRL_GET_MAX_PROTO_VERSION:
1872 return SSL_get_max_proto_version(s);
1873
1874 case SSL_CTRL_SET_MIN_PROTO_VERSION:
1875 if (larg < 0 || larg > UINT16_MAX)
1876 return 0;
1877 return SSL_set_min_proto_version(s, larg);
1878
1879 case SSL_CTRL_SET_MAX_PROTO_VERSION:
1880 if (larg < 0 || larg > UINT16_MAX)
1881 return 0;
1882 return SSL_set_max_proto_version(s, larg);
1883
1884 case SSL_CTRL_GET_SIGNATURE_NID:
1885 return _SSL_get_signature_nid(s, parg);
1886
1887 case SSL_CTRL_GET_PEER_SIGNATURE_NID:
1888 return _SSL_get_peer_signature_nid(s, parg);
1889
1890 /*
1891 * Legacy controls that should eventually be removed.
1892 */
1893 case SSL_CTRL_GET_CLIENT_CERT_REQUEST:
1894 return 0;
1895
1896 case SSL_CTRL_GET_FLAGS:
1897 return (int)(s->s3->flags);
1898
1899 case SSL_CTRL_NEED_TMP_RSA:
1900 return 0;
1901
1902 case SSL_CTRL_SET_TMP_RSA:
1903 case SSL_CTRL_SET_TMP_RSA_CB:
1904 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1905 return 0;
1906 }
1907
1908 return 0;
1909}
1910
1911long
1912ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
1913{
1914 switch (cmd) {
1915 case SSL_CTRL_SET_TMP_RSA_CB:
1916 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1917 return 0;
1918
1919 case SSL_CTRL_SET_TMP_DH_CB:
1920 s->cert->dhe_params_cb = (DH *(*)(SSL *, int, int))fp;
1921 return 1;
1922
1923 case SSL_CTRL_SET_TMP_ECDH_CB:
1924 return 1;
1925
1926 case SSL_CTRL_SET_TLSEXT_DEBUG_CB:
1927 s->tlsext_debug_cb = (void (*)(SSL *, int , int,
1928 unsigned char *, int, void *))fp;
1929 return 1;
1930 }
1931
1932 return 0;
1933}
1934
1935static int
1936_SSL_CTX_set_tmp_dh(SSL_CTX *ctx, DH *dh)
1937{
1938 DH *dhe_params;
1939
1940 if (dh == NULL) {
1941 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
1942 return 0;
1943 }
1944
1945 if (!ssl_ctx_security_dh(ctx, dh)) {
1946 SSLerrorx(SSL_R_DH_KEY_TOO_SMALL);
1947 return 0;
1948 }
1949
1950 if ((dhe_params = DHparams_dup(dh)) == NULL) {
1951 SSLerrorx(ERR_R_DH_LIB);
1952 return 0;
1953 }
1954
1955 DH_free(ctx->cert->dhe_params);
1956 ctx->cert->dhe_params = dhe_params;
1957
1958 return 1;
1959}
1960
1961static int
1962_SSL_CTX_set_dh_auto(SSL_CTX *ctx, int state)
1963{
1964 ctx->cert->dhe_params_auto = state;
1965 return 1;
1966}
1967
1968static int
1969_SSL_CTX_set_tmp_ecdh(SSL_CTX *ctx, EC_KEY *ecdh)
1970{
1971 const EC_GROUP *group;
1972 int nid;
1973
1974 if (ecdh == NULL)
1975 return 0;
1976 if ((group = EC_KEY_get0_group(ecdh)) == NULL)
1977 return 0;
1978
1979 nid = EC_GROUP_get_curve_name(group);
1980 return SSL_CTX_set1_groups(ctx, &nid, 1);
1981}
1982
1983static int
1984_SSL_CTX_set_ecdh_auto(SSL_CTX *ctx, int state)
1985{
1986 return 1;
1987}
1988
1989static int
1990_SSL_CTX_set_tlsext_servername_arg(SSL_CTX *ctx, void *arg)
1991{
1992 ctx->tlsext_servername_arg = arg;
1993 return 1;
1994}
1995
1996static int
1997_SSL_CTX_get_tlsext_ticket_keys(SSL_CTX *ctx, unsigned char *keys, int keys_len)
1998{
1999 if (keys == NULL)
2000 return 48;
2001
2002 if (keys_len != 48) {
2003 SSLerrorx(SSL_R_INVALID_TICKET_KEYS_LENGTH);
2004 return 0;
2005 }
2006
2007 memcpy(keys, ctx->tlsext_tick_key_name, 16);
2008 memcpy(keys + 16, ctx->tlsext_tick_hmac_key, 16);
2009 memcpy(keys + 32, ctx->tlsext_tick_aes_key, 16);
2010
2011 return 1;
2012}
2013
2014static int
2015_SSL_CTX_set_tlsext_ticket_keys(SSL_CTX *ctx, unsigned char *keys, int keys_len)
2016{
2017 if (keys == NULL)
2018 return 48;
2019
2020 if (keys_len != 48) {
2021 SSLerrorx(SSL_R_INVALID_TICKET_KEYS_LENGTH);
2022 return 0;
2023 }
2024
2025 memcpy(ctx->tlsext_tick_key_name, keys, 16);
2026 memcpy(ctx->tlsext_tick_hmac_key, keys + 16, 16);
2027 memcpy(ctx->tlsext_tick_aes_key, keys + 32, 16);
2028
2029 return 1;
2030}
2031
2032static int
2033_SSL_CTX_get_tlsext_status_arg(SSL_CTX *ctx, void **arg)
2034{
2035 *arg = ctx->tlsext_status_arg;
2036 return 1;
2037}
2038
2039static int
2040_SSL_CTX_set_tlsext_status_arg(SSL_CTX *ctx, void *arg)
2041{
2042 ctx->tlsext_status_arg = arg;
2043 return 1;
2044}
2045
2046int
2047SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *chain)
2048{
2049 return ssl_cert_set0_chain(ctx, NULL, chain);
2050}
2051LSSL_ALIAS(SSL_CTX_set0_chain);
2052
2053int
2054SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *chain)
2055{
2056 return ssl_cert_set1_chain(ctx, NULL, chain);
2057}
2058LSSL_ALIAS(SSL_CTX_set1_chain);
2059
2060int
2061SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509)
2062{
2063 return ssl_cert_add0_chain_cert(ctx, NULL, x509);
2064}
2065LSSL_ALIAS(SSL_CTX_add0_chain_cert);
2066
2067int
2068SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509)
2069{
2070 return ssl_cert_add1_chain_cert(ctx, NULL, x509);
2071}
2072LSSL_ALIAS(SSL_CTX_add1_chain_cert);
2073
2074int
2075SSL_CTX_get0_chain_certs(const SSL_CTX *ctx, STACK_OF(X509) **out_chain)
2076{
2077 *out_chain = NULL;
2078
2079 if (ctx->cert->key != NULL)
2080 *out_chain = ctx->cert->key->chain;
2081
2082 return 1;
2083}
2084LSSL_ALIAS(SSL_CTX_get0_chain_certs);
2085
2086int
2087SSL_CTX_clear_chain_certs(SSL_CTX *ctx)
2088{
2089 return ssl_cert_set0_chain(ctx, NULL, NULL);
2090}
2091LSSL_ALIAS(SSL_CTX_clear_chain_certs);
2092
2093static int
2094_SSL_CTX_add_extra_chain_cert(SSL_CTX *ctx, X509 *cert)
2095{
2096 if (ctx->extra_certs == NULL) {
2097 if ((ctx->extra_certs = sk_X509_new_null()) == NULL)
2098 return 0;
2099 }
2100 if (sk_X509_push(ctx->extra_certs, cert) == 0)
2101 return 0;
2102
2103 return 1;
2104}
2105
2106static int
2107_SSL_CTX_get_extra_chain_certs(SSL_CTX *ctx, STACK_OF(X509) **certs)
2108{
2109 *certs = ctx->extra_certs;
2110 if (*certs == NULL)
2111 *certs = ctx->cert->key->chain;
2112
2113 return 1;
2114}
2115
2116static int
2117_SSL_CTX_get_extra_chain_certs_only(SSL_CTX *ctx, STACK_OF(X509) **certs)
2118{
2119 *certs = ctx->extra_certs;
2120 return 1;
2121}
2122
2123static int
2124_SSL_CTX_clear_extra_chain_certs(SSL_CTX *ctx)
2125{
2126 sk_X509_pop_free(ctx->extra_certs, X509_free);
2127 ctx->extra_certs = NULL;
2128 return 1;
2129}
2130
2131int
2132SSL_CTX_set1_groups(SSL_CTX *ctx, const int *groups, size_t groups_len)
2133{
2134 return tls1_set_groups(&ctx->tlsext_supportedgroups,
2135 &ctx->tlsext_supportedgroups_length, groups, groups_len);
2136}
2137LSSL_ALIAS(SSL_CTX_set1_groups);
2138
2139int
2140SSL_CTX_set1_groups_list(SSL_CTX *ctx, const char *groups)
2141{
2142 return tls1_set_group_list(&ctx->tlsext_supportedgroups,
2143 &ctx->tlsext_supportedgroups_length, groups);
2144}
2145LSSL_ALIAS(SSL_CTX_set1_groups_list);
2146
2147long
2148ssl3_ctx_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
2149{
2150 switch (cmd) {
2151 case SSL_CTRL_SET_TMP_DH:
2152 return _SSL_CTX_set_tmp_dh(ctx, parg);
2153
2154 case SSL_CTRL_SET_TMP_DH_CB:
2155 SSLerrorx(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2156 return 0;
2157
2158 case SSL_CTRL_SET_DH_AUTO:
2159 return _SSL_CTX_set_dh_auto(ctx, larg);
2160
2161 case SSL_CTRL_SET_TMP_ECDH:
2162 return _SSL_CTX_set_tmp_ecdh(ctx, parg);
2163
2164 case SSL_CTRL_SET_TMP_ECDH_CB:
2165 SSLerrorx(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2166 return 0;
2167
2168 case SSL_CTRL_SET_ECDH_AUTO:
2169 return _SSL_CTX_set_ecdh_auto(ctx, larg);
2170
2171 case SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG:
2172 return _SSL_CTX_set_tlsext_servername_arg(ctx, parg);
2173
2174 case SSL_CTRL_GET_TLSEXT_TICKET_KEYS:
2175 return _SSL_CTX_get_tlsext_ticket_keys(ctx, parg, larg);
2176
2177 case SSL_CTRL_SET_TLSEXT_TICKET_KEYS:
2178 return _SSL_CTX_set_tlsext_ticket_keys(ctx, parg, larg);
2179
2180 case SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG:
2181 return _SSL_CTX_get_tlsext_status_arg(ctx, parg);
2182
2183 case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG:
2184 return _SSL_CTX_set_tlsext_status_arg(ctx, parg);
2185
2186 case SSL_CTRL_CHAIN:
2187 if (larg == 0)
2188 return SSL_CTX_set0_chain(ctx, (STACK_OF(X509) *)parg);
2189 else
2190 return SSL_CTX_set1_chain(ctx, (STACK_OF(X509) *)parg);
2191
2192 case SSL_CTRL_CHAIN_CERT:
2193 if (larg == 0)
2194 return SSL_CTX_add0_chain_cert(ctx, (X509 *)parg);
2195 else
2196 return SSL_CTX_add1_chain_cert(ctx, (X509 *)parg);
2197
2198 case SSL_CTRL_GET_CHAIN_CERTS:
2199 return SSL_CTX_get0_chain_certs(ctx, (STACK_OF(X509) **)parg);
2200
2201 case SSL_CTRL_EXTRA_CHAIN_CERT:
2202 return _SSL_CTX_add_extra_chain_cert(ctx, parg);
2203
2204 case SSL_CTRL_GET_EXTRA_CHAIN_CERTS:
2205 if (larg == 0)
2206 return _SSL_CTX_get_extra_chain_certs(ctx, parg);
2207 else
2208 return _SSL_CTX_get_extra_chain_certs_only(ctx, parg);
2209
2210 case SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS:
2211 return _SSL_CTX_clear_extra_chain_certs(ctx);
2212
2213 case SSL_CTRL_SET_GROUPS:
2214 return SSL_CTX_set1_groups(ctx, parg, larg);
2215
2216 case SSL_CTRL_SET_GROUPS_LIST:
2217 return SSL_CTX_set1_groups_list(ctx, parg);
2218
2219 case SSL_CTRL_GET_MIN_PROTO_VERSION:
2220 return SSL_CTX_get_min_proto_version(ctx);
2221
2222 case SSL_CTRL_GET_MAX_PROTO_VERSION:
2223 return SSL_CTX_get_max_proto_version(ctx);
2224
2225 case SSL_CTRL_SET_MIN_PROTO_VERSION:
2226 if (larg < 0 || larg > UINT16_MAX)
2227 return 0;
2228 return SSL_CTX_set_min_proto_version(ctx, larg);
2229
2230 case SSL_CTRL_SET_MAX_PROTO_VERSION:
2231 if (larg < 0 || larg > UINT16_MAX)
2232 return 0;
2233 return SSL_CTX_set_max_proto_version(ctx, larg);
2234
2235 /*
2236 * Legacy controls that should eventually be removed.
2237 */
2238 case SSL_CTRL_NEED_TMP_RSA:
2239 return 0;
2240
2241 case SSL_CTRL_SET_TMP_RSA:
2242 case SSL_CTRL_SET_TMP_RSA_CB:
2243 SSLerrorx(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2244 return 0;
2245 }
2246
2247 return 0;
2248}
2249
2250long
2251ssl3_ctx_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
2252{
2253 switch (cmd) {
2254 case SSL_CTRL_SET_TMP_RSA_CB:
2255 SSLerrorx(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2256 return 0;
2257
2258 case SSL_CTRL_SET_TMP_DH_CB:
2259 ctx->cert->dhe_params_cb =
2260 (DH *(*)(SSL *, int, int))fp;
2261 return 1;
2262
2263 case SSL_CTRL_SET_TMP_ECDH_CB:
2264 return 1;
2265
2266 case SSL_CTRL_SET_TLSEXT_SERVERNAME_CB:
2267 ctx->tlsext_servername_callback =
2268 (int (*)(SSL *, int *, void *))fp;
2269 return 1;
2270
2271 case SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB:
2272 *(int (**)(SSL *, void *))fp = ctx->tlsext_status_cb;
2273 return 1;
2274
2275 case SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB:
2276 ctx->tlsext_status_cb = (int (*)(SSL *, void *))fp;
2277 return 1;
2278
2279 case SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB:
2280 ctx->tlsext_ticket_key_cb = (int (*)(SSL *, unsigned char *,
2281 unsigned char *, EVP_CIPHER_CTX *, HMAC_CTX *, int))fp;
2282 return 1;
2283 }
2284
2285 return 0;
2286}
2287
2288SSL_CIPHER *
2289ssl3_choose_cipher(SSL *s, STACK_OF(SSL_CIPHER) *clnt,
2290 STACK_OF(SSL_CIPHER) *srvr)
2291{
2292 unsigned long alg_k, alg_a, mask_k, mask_a;
2293 STACK_OF(SSL_CIPHER) *prio, *allow;
2294 SSL_CIPHER *c, *ret = NULL;
2295 int can_use_ecc;
2296 int i, ii, nid, ok;
2297 SSL_CERT *cert;
2298
2299 /* Let's see which ciphers we can support */
2300 cert = s->cert;
2301
2302 can_use_ecc = tls1_get_supported_group(s, &nid);
2303
2304 /*
2305 * Do not set the compare functions, because this may lead to a
2306 * reordering by "id". We want to keep the original ordering.
2307 * We may pay a price in performance during sk_SSL_CIPHER_find(),
2308 * but would have to pay with the price of sk_SSL_CIPHER_dup().
2309 */
2310
2311 if (s->options & SSL_OP_CIPHER_SERVER_PREFERENCE) {
2312 prio = srvr;
2313 allow = clnt;
2314 } else {
2315 prio = clnt;
2316 allow = srvr;
2317 }
2318
2319 for (i = 0; i < sk_SSL_CIPHER_num(prio); i++) {
2320 c = sk_SSL_CIPHER_value(prio, i);
2321
2322 /* Skip TLS v1.2 only ciphersuites if not supported. */
2323 if ((c->algorithm_ssl & SSL_TLSV1_2) &&
2324 !SSL_USE_TLS1_2_CIPHERS(s))
2325 continue;
2326
2327 /* Skip TLS v1.3 only ciphersuites if not supported. */
2328 if ((c->algorithm_ssl & SSL_TLSV1_3) &&
2329 !SSL_USE_TLS1_3_CIPHERS(s))
2330 continue;
2331
2332 /* If TLS v1.3, only allow TLS v1.3 ciphersuites. */
2333 if (SSL_USE_TLS1_3_CIPHERS(s) &&
2334 !(c->algorithm_ssl & SSL_TLSV1_3))
2335 continue;
2336
2337 if (!ssl_security_shared_cipher(s, c))
2338 continue;
2339
2340 ssl_set_cert_masks(cert, c);
2341 mask_k = cert->mask_k;
2342 mask_a = cert->mask_a;
2343
2344 alg_k = c->algorithm_mkey;
2345 alg_a = c->algorithm_auth;
2346
2347 ok = (alg_k & mask_k) && (alg_a & mask_a);
2348
2349 /*
2350 * If we are considering an ECC cipher suite that uses our
2351 * certificate check it.
2352 */
2353 if (alg_a & SSL_aECDSA)
2354 ok = ok && tls1_check_ec_server_key(s);
2355 /*
2356 * If we are considering an ECC cipher suite that uses
2357 * an ephemeral EC key check it.
2358 */
2359 if (alg_k & SSL_kECDHE)
2360 ok = ok && can_use_ecc;
2361
2362 if (!ok)
2363 continue;
2364 ii = sk_SSL_CIPHER_find(allow, c);
2365 if (ii >= 0) {
2366 ret = sk_SSL_CIPHER_value(allow, ii);
2367 break;
2368 }
2369 }
2370 return (ret);
2371}
2372
2373#define SSL3_CT_RSA_SIGN 1
2374#define SSL3_CT_RSA_FIXED_DH 3
2375#define SSL3_CT_ECDSA_SIGN 64
2376
2377int
2378ssl3_get_req_cert_types(SSL *s, CBB *cbb)
2379{
2380 unsigned long alg_k;
2381
2382 alg_k = s->s3->hs.cipher->algorithm_mkey;
2383
2384 if ((alg_k & SSL_kDHE) != 0) {
2385 if (!CBB_add_u8(cbb, SSL3_CT_RSA_FIXED_DH))
2386 return 0;
2387 }
2388
2389 if (!CBB_add_u8(cbb, SSL3_CT_RSA_SIGN))
2390 return 0;
2391
2392 /*
2393 * ECDSA certs can be used with RSA cipher suites as well
2394 * so we don't need to check for SSL_kECDH or SSL_kECDHE.
2395 */
2396 if (!CBB_add_u8(cbb, SSL3_CT_ECDSA_SIGN))
2397 return 0;
2398
2399 return 1;
2400}
2401
2402int
2403ssl3_shutdown(SSL *s)
2404{
2405 int ret;
2406
2407 /*
2408 * Don't do anything much if we have not done the handshake or
2409 * we don't want to send messages :-)
2410 */
2411 if ((s->quiet_shutdown) || (s->s3->hs.state == SSL_ST_BEFORE)) {
2412 s->shutdown = (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
2413 return (1);
2414 }
2415
2416 if (!(s->shutdown & SSL_SENT_SHUTDOWN)) {
2417 s->shutdown|=SSL_SENT_SHUTDOWN;
2418 ssl3_send_alert(s, SSL3_AL_WARNING, SSL_AD_CLOSE_NOTIFY);
2419 /*
2420 * Our shutdown alert has been sent now, and if it still needs
2421 * to be written, s->s3->alert_dispatch will be true
2422 */
2423 if (s->s3->alert_dispatch)
2424 return (-1); /* return WANT_WRITE */
2425 } else if (s->s3->alert_dispatch) {
2426 /* resend it if not sent */
2427 ret = ssl3_dispatch_alert(s);
2428 if (ret == -1) {
2429 /*
2430 * We only get to return -1 here the 2nd/Nth
2431 * invocation, we must have already signalled
2432 * return 0 upon a previous invoation,
2433 * return WANT_WRITE
2434 */
2435 return (ret);
2436 }
2437 } else if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) {
2438 /* If we are waiting for a close from our peer, we are closed */
2439 s->method->ssl_read_bytes(s, 0, NULL, 0, 0);
2440 if (!(s->shutdown & SSL_RECEIVED_SHUTDOWN)) {
2441 return (-1); /* return WANT_READ */
2442 }
2443 }
2444
2445 if ((s->shutdown == (SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN)) &&
2446 !s->s3->alert_dispatch)
2447 return (1);
2448 else
2449 return (0);
2450}
2451
2452int
2453ssl3_write(SSL *s, const void *buf, int len)
2454{
2455 errno = 0;
2456
2457 if (s->s3->renegotiate)
2458 ssl3_renegotiate_check(s);
2459
2460 return s->method->ssl_write_bytes(s, SSL3_RT_APPLICATION_DATA,
2461 buf, len);
2462}
2463
2464static int
2465ssl3_read_internal(SSL *s, void *buf, int len, int peek)
2466{
2467 int ret;
2468
2469 errno = 0;
2470 if (s->s3->renegotiate)
2471 ssl3_renegotiate_check(s);
2472 s->s3->in_read_app_data = 1;
2473
2474 ret = s->method->ssl_read_bytes(s, SSL3_RT_APPLICATION_DATA, buf, len,
2475 peek);
2476 if ((ret == -1) && (s->s3->in_read_app_data == 2)) {
2477 /*
2478 * ssl3_read_bytes decided to call s->handshake_func,
2479 * which called ssl3_read_bytes to read handshake data.
2480 * However, ssl3_read_bytes actually found application data
2481 * and thinks that application data makes sense here; so disable
2482 * handshake processing and try to read application data again.
2483 */
2484 s->in_handshake++;
2485 ret = s->method->ssl_read_bytes(s, SSL3_RT_APPLICATION_DATA,
2486 buf, len, peek);
2487 s->in_handshake--;
2488 } else
2489 s->s3->in_read_app_data = 0;
2490
2491 return (ret);
2492}
2493
2494int
2495ssl3_read(SSL *s, void *buf, int len)
2496{
2497 return ssl3_read_internal(s, buf, len, 0);
2498}
2499
2500int
2501ssl3_peek(SSL *s, void *buf, int len)
2502{
2503 return ssl3_read_internal(s, buf, len, 1);
2504}
2505
2506int
2507ssl3_renegotiate(SSL *s)
2508{
2509 if (s->handshake_func == NULL)
2510 return 1;
2511
2512 if (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS)
2513 return 0;
2514
2515 s->s3->renegotiate = 1;
2516
2517 return 1;
2518}
2519
2520int
2521ssl3_renegotiate_check(SSL *s)
2522{
2523 if (!s->s3->renegotiate)
2524 return 0;
2525 if (SSL_in_init(s) || s->s3->rbuf.left != 0 || s->s3->wbuf.left != 0)
2526 return 0;
2527
2528 s->s3->hs.state = SSL_ST_RENEGOTIATE;
2529 s->s3->renegotiate = 0;
2530 s->s3->num_renegotiations++;
2531 s->s3->total_renegotiations++;
2532
2533 return 1;
2534}
diff --git a/src/lib/libssl/shlib_version b/src/lib/libssl/shlib_version
deleted file mode 100644
index c2665004b4..0000000000
--- a/src/lib/libssl/shlib_version
+++ /dev/null
@@ -1,3 +0,0 @@
1# Don't forget to give libtls the same type of bump!
2major=59
3minor=1
diff --git a/src/lib/libssl/srtp.h b/src/lib/libssl/srtp.h
deleted file mode 100644
index 686e9d924a..0000000000
--- a/src/lib/libssl/srtp.h
+++ /dev/null
@@ -1,148 +0,0 @@
1/* $OpenBSD: srtp.h,v 1.8 2025/03/13 10:26:41 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/*
112 * DTLS code by Eric Rescorla <ekr@rtfm.com>
113 *
114 * Copyright (C) 2006, Network Resonance, Inc.
115 * Copyright (C) 2011, RTFM, Inc.
116 */
117
118#ifndef HEADER_D1_SRTP_H
119#define HEADER_D1_SRTP_H
120
121#include <openssl/ssl.h>
122
123#ifdef __cplusplus
124extern "C" {
125#endif
126
127#define SRTP_AES128_CM_SHA1_80 0x0001
128#define SRTP_AES128_CM_SHA1_32 0x0002
129#define SRTP_AES128_F8_SHA1_80 0x0003
130#define SRTP_AES128_F8_SHA1_32 0x0004
131#define SRTP_NULL_SHA1_80 0x0005
132#define SRTP_NULL_SHA1_32 0x0006
133
134/* AEAD SRTP protection profiles from RFC 7714 */
135#define SRTP_AEAD_AES_128_GCM 0x0007
136#define SRTP_AEAD_AES_256_GCM 0x0008
137
138int SSL_CTX_set_tlsext_use_srtp(SSL_CTX *ctx, const char *profiles);
139int SSL_set_tlsext_use_srtp(SSL *ctx, const char *profiles);
140
141STACK_OF(SRTP_PROTECTION_PROFILE) *SSL_get_srtp_profiles(SSL *ssl);
142SRTP_PROTECTION_PROFILE *SSL_get_selected_srtp_profile(SSL *s);
143
144#ifdef __cplusplus
145}
146#endif
147
148#endif
diff --git a/src/lib/libssl/ssl.h b/src/lib/libssl/ssl.h
deleted file mode 100644
index a1ed22b778..0000000000
--- a/src/lib/libssl/ssl.h
+++ /dev/null
@@ -1,2343 +0,0 @@
1/* $OpenBSD: ssl.h,v 1.247 2025/03/12 14:03:55 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#ifndef HEADER_SSL_H
144#define HEADER_SSL_H
145
146#include <stdint.h>
147
148#include <openssl/opensslconf.h>
149
150#include <openssl/hmac.h>
151#include <openssl/pem.h>
152#include <openssl/safestack.h>
153
154#include <openssl/bio.h>
155
156#ifndef OPENSSL_NO_DEPRECATED
157#include <openssl/buffer.h>
158#include <openssl/crypto.h>
159#include <openssl/lhash.h>
160
161#ifndef OPENSSL_NO_X509
162#include <openssl/x509.h>
163#endif
164#endif
165
166#ifdef __cplusplus
167extern "C" {
168#endif
169
170/* SSLeay version number for ASN.1 encoding of the session information */
171/* Version 0 - initial version
172 * Version 1 - added the optional peer certificate
173 */
174#define SSL_SESSION_ASN1_VERSION 0x0001
175
176/* text strings for the ciphers */
177#define SSL_TXT_NULL_WITH_MD5 SSL2_TXT_NULL_WITH_MD5
178#define SSL_TXT_RC4_128_WITH_MD5 SSL2_TXT_RC4_128_WITH_MD5
179#define SSL_TXT_RC4_128_EXPORT40_WITH_MD5 SSL2_TXT_RC4_128_EXPORT40_WITH_MD5
180#define SSL_TXT_RC2_128_CBC_WITH_MD5 SSL2_TXT_RC2_128_CBC_WITH_MD5
181#define SSL_TXT_RC2_128_CBC_EXPORT40_WITH_MD5 SSL2_TXT_RC2_128_CBC_EXPORT40_WITH_MD5
182#define SSL_TXT_IDEA_128_CBC_WITH_MD5 SSL2_TXT_IDEA_128_CBC_WITH_MD5
183#define SSL_TXT_DES_64_CBC_WITH_MD5 SSL2_TXT_DES_64_CBC_WITH_MD5
184#define SSL_TXT_DES_64_CBC_WITH_SHA SSL2_TXT_DES_64_CBC_WITH_SHA
185#define SSL_TXT_DES_192_EDE3_CBC_WITH_MD5 SSL2_TXT_DES_192_EDE3_CBC_WITH_MD5
186#define SSL_TXT_DES_192_EDE3_CBC_WITH_SHA SSL2_TXT_DES_192_EDE3_CBC_WITH_SHA
187
188/* VRS Additional Kerberos5 entries
189 */
190#define SSL_TXT_KRB5_RC4_128_SHA SSL3_TXT_KRB5_RC4_128_SHA
191#define SSL_TXT_KRB5_IDEA_128_CBC_SHA SSL3_TXT_KRB5_IDEA_128_CBC_SHA
192#define SSL_TXT_KRB5_RC4_128_MD5 SSL3_TXT_KRB5_RC4_128_MD5
193#define SSL_TXT_KRB5_IDEA_128_CBC_MD5 SSL3_TXT_KRB5_IDEA_128_CBC_MD5
194
195#define SSL_TXT_KRB5_RC2_40_CBC_SHA SSL3_TXT_KRB5_RC2_40_CBC_SHA
196#define SSL_TXT_KRB5_RC4_40_SHA SSL3_TXT_KRB5_RC4_40_SHA
197#define SSL_TXT_KRB5_RC2_40_CBC_MD5 SSL3_TXT_KRB5_RC2_40_CBC_MD5
198#define SSL_TXT_KRB5_RC4_40_MD5 SSL3_TXT_KRB5_RC4_40_MD5
199
200#define SSL_TXT_KRB5_DES_40_CBC_SHA SSL3_TXT_KRB5_DES_40_CBC_SHA
201#define SSL_TXT_KRB5_DES_40_CBC_MD5 SSL3_TXT_KRB5_DES_40_CBC_MD5
202#define SSL_TXT_KRB5_DES_64_CBC_SHA SSL3_TXT_KRB5_DES_64_CBC_SHA
203#define SSL_TXT_KRB5_DES_64_CBC_MD5 SSL3_TXT_KRB5_DES_64_CBC_MD5
204#define SSL_TXT_KRB5_DES_192_CBC3_SHA SSL3_TXT_KRB5_DES_192_CBC3_SHA
205#define SSL_TXT_KRB5_DES_192_CBC3_MD5 SSL3_TXT_KRB5_DES_192_CBC3_MD5
206#define SSL_MAX_KRB5_PRINCIPAL_LENGTH 256
207
208#define SSL_MAX_SSL_SESSION_ID_LENGTH 32
209#define SSL_MAX_SID_CTX_LENGTH 32
210
211#define SSL_MIN_RSA_MODULUS_LENGTH_IN_BYTES (512/8)
212#define SSL_MAX_KEY_ARG_LENGTH 8
213#define SSL_MAX_MASTER_KEY_LENGTH 48
214
215
216/* These are used to specify which ciphers to use and not to use */
217
218#define SSL_TXT_LOW "LOW"
219#define SSL_TXT_MEDIUM "MEDIUM"
220#define SSL_TXT_HIGH "HIGH"
221
222#define SSL_TXT_kFZA "kFZA" /* unused! */
223#define SSL_TXT_aFZA "aFZA" /* unused! */
224#define SSL_TXT_eFZA "eFZA" /* unused! */
225#define SSL_TXT_FZA "FZA" /* unused! */
226
227#define SSL_TXT_aNULL "aNULL"
228#define SSL_TXT_eNULL "eNULL"
229#define SSL_TXT_NULL "NULL"
230
231#define SSL_TXT_kRSA "kRSA"
232#define SSL_TXT_kDHr "kDHr" /* no such ciphersuites supported! */
233#define SSL_TXT_kDHd "kDHd" /* no such ciphersuites supported! */
234#define SSL_TXT_kDH "kDH" /* no such ciphersuites supported! */
235#define SSL_TXT_kEDH "kEDH"
236#define SSL_TXT_kKRB5 "kKRB5"
237#define SSL_TXT_kECDHr "kECDHr"
238#define SSL_TXT_kECDHe "kECDHe"
239#define SSL_TXT_kECDH "kECDH"
240#define SSL_TXT_kEECDH "kEECDH"
241#define SSL_TXT_kPSK "kPSK"
242#define SSL_TXT_kSRP "kSRP"
243
244#define SSL_TXT_aRSA "aRSA"
245#define SSL_TXT_aDSS "aDSS"
246#define SSL_TXT_aDH "aDH" /* no such ciphersuites supported! */
247#define SSL_TXT_aECDH "aECDH"
248#define SSL_TXT_aKRB5 "aKRB5"
249#define SSL_TXT_aECDSA "aECDSA"
250#define SSL_TXT_aPSK "aPSK"
251
252#define SSL_TXT_DSS "DSS"
253#define SSL_TXT_DH "DH"
254#define SSL_TXT_DHE "DHE" /* same as "kDHE:-ADH" */
255#define SSL_TXT_EDH "EDH" /* previous name for DHE */
256#define SSL_TXT_ADH "ADH"
257#define SSL_TXT_RSA "RSA"
258#define SSL_TXT_ECDH "ECDH"
259#define SSL_TXT_ECDHE "ECDHE" /* same as "kECDHE:-AECDH" */
260#define SSL_TXT_EECDH "EECDH" /* previous name for ECDHE */
261#define SSL_TXT_AECDH "AECDH"
262#define SSL_TXT_ECDSA "ECDSA"
263#define SSL_TXT_KRB5 "KRB5"
264#define SSL_TXT_PSK "PSK"
265#define SSL_TXT_SRP "SRP"
266
267#define SSL_TXT_DES "DES"
268#define SSL_TXT_3DES "3DES"
269#define SSL_TXT_RC4 "RC4"
270#define SSL_TXT_RC2 "RC2"
271#define SSL_TXT_IDEA "IDEA"
272#define SSL_TXT_SEED "SEED"
273#define SSL_TXT_AES128 "AES128"
274#define SSL_TXT_AES256 "AES256"
275#define SSL_TXT_AES "AES"
276#define SSL_TXT_AES_GCM "AESGCM"
277#define SSL_TXT_CAMELLIA128 "CAMELLIA128"
278#define SSL_TXT_CAMELLIA256 "CAMELLIA256"
279#define SSL_TXT_CAMELLIA "CAMELLIA"
280#define SSL_TXT_CHACHA20 "CHACHA20"
281
282#define SSL_TXT_AEAD "AEAD"
283#define SSL_TXT_MD5 "MD5"
284#define SSL_TXT_SHA1 "SHA1"
285#define SSL_TXT_SHA "SHA" /* same as "SHA1" */
286#define SSL_TXT_SHA256 "SHA256"
287#define SSL_TXT_SHA384 "SHA384"
288
289#define SSL_TXT_DTLS1 "DTLSv1"
290#define SSL_TXT_DTLS1_2 "DTLSv1.2"
291#define SSL_TXT_SSLV2 "SSLv2"
292#define SSL_TXT_SSLV3 "SSLv3"
293#define SSL_TXT_TLSV1 "TLSv1"
294#define SSL_TXT_TLSV1_1 "TLSv1.1"
295#define SSL_TXT_TLSV1_2 "TLSv1.2"
296#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
297#define SSL_TXT_TLSV1_3 "TLSv1.3"
298#endif
299
300#define SSL_TXT_EXP "EXP"
301#define SSL_TXT_EXPORT "EXPORT"
302
303#define SSL_TXT_ALL "ALL"
304
305/*
306 * COMPLEMENTOF* definitions. These identifiers are used to (de-select)
307 * ciphers normally not being used.
308 * Example: "RC4" will activate all ciphers using RC4 including ciphers
309 * without authentication, which would normally disabled by DEFAULT (due
310 * the "!ADH" being part of default). Therefore "RC4:!COMPLEMENTOFDEFAULT"
311 * will make sure that it is also disabled in the specific selection.
312 * COMPLEMENTOF* identifiers are portable between version, as adjustments
313 * to the default cipher setup will also be included here.
314 *
315 * COMPLEMENTOFDEFAULT does not experience the same special treatment that
316 * DEFAULT gets, as only selection is being done and no sorting as needed
317 * for DEFAULT.
318 */
319#define SSL_TXT_CMPALL "COMPLEMENTOFALL"
320#define SSL_TXT_CMPDEF "COMPLEMENTOFDEFAULT"
321
322/* The following cipher list is used by default.
323 * It also is substituted when an application-defined cipher list string
324 * starts with 'DEFAULT'. */
325#define SSL_DEFAULT_CIPHER_LIST "ALL:!aNULL:!eNULL:!SSLv2"
326/* As of OpenSSL 1.0.0, ssl_create_cipher_list() in ssl/ssl_ciph.c always
327 * starts with a reasonable order, and all we have to do for DEFAULT is
328 * throwing out anonymous and unencrypted ciphersuites!
329 * (The latter are not actually enabled by ALL, but "ALL:RSA" would enable
330 * some of them.)
331 */
332
333/* Used in SSL_set_shutdown()/SSL_get_shutdown(); */
334#define SSL_SENT_SHUTDOWN 1
335#define SSL_RECEIVED_SHUTDOWN 2
336
337
338#define SSL_FILETYPE_ASN1 X509_FILETYPE_ASN1
339#define SSL_FILETYPE_PEM X509_FILETYPE_PEM
340
341/* This is needed to stop compilers complaining about the
342 * 'struct ssl_st *' function parameters used to prototype callbacks
343 * in SSL_CTX. */
344typedef struct ssl_st *ssl_crock_st;
345
346typedef struct ssl_method_st SSL_METHOD;
347typedef struct ssl_cipher_st SSL_CIPHER;
348typedef struct ssl_session_st SSL_SESSION;
349
350#if defined(LIBRESSL_HAS_QUIC) || defined(LIBRESSL_INTERNAL)
351typedef struct ssl_quic_method_st SSL_QUIC_METHOD;
352#endif
353
354DECLARE_STACK_OF(SSL_CIPHER)
355
356/* SRTP protection profiles for use with the use_srtp extension (RFC 5764)*/
357typedef struct srtp_protection_profile_st {
358 const char *name;
359 unsigned long id;
360} SRTP_PROTECTION_PROFILE;
361
362DECLARE_STACK_OF(SRTP_PROTECTION_PROFILE)
363
364typedef int (*tls_session_ticket_ext_cb_fn)(SSL *s, const unsigned char *data,
365 int len, void *arg);
366typedef int (*tls_session_secret_cb_fn)(SSL *s, void *secret, int *secret_len,
367 STACK_OF(SSL_CIPHER) *peer_ciphers, const SSL_CIPHER **cipher, void *arg);
368
369/* Allow initial connection to servers that don't support RI */
370#define SSL_OP_LEGACY_SERVER_CONNECT 0x00000004L
371
372/* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
373 * in OpenSSL 0.9.6d. Usually (depending on the application protocol)
374 * the workaround is not needed.
375 * Unfortunately some broken SSL/TLS implementations cannot handle it
376 * at all, which is why it was previously included in SSL_OP_ALL.
377 * Now it's not.
378 */
379#define SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS 0x00000800L
380
381/* DTLS options */
382#define SSL_OP_NO_QUERY_MTU 0x00001000L
383/* Turn on Cookie Exchange (on relevant for servers) */
384#define SSL_OP_COOKIE_EXCHANGE 0x00002000L
385/* Don't use RFC4507 ticket extension */
386#define SSL_OP_NO_TICKET 0x00004000L
387
388/* As server, disallow session resumption on renegotiation */
389#define SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION 0x00010000L
390/* Disallow client initiated renegotiation. */
391#define SSL_OP_NO_CLIENT_RENEGOTIATION 0x00020000L
392/* Disallow client and server initiated renegotiation. */
393#define SSL_OP_NO_RENEGOTIATION 0x00040000L
394/* Allow client initiated renegotiation. */
395#define SSL_OP_ALLOW_CLIENT_RENEGOTIATION 0x00080000L
396/* If set, always create a new key when using tmp_dh parameters */
397#define SSL_OP_SINGLE_DH_USE 0x00100000L
398/* Set on servers to choose the cipher according to the server's
399 * preferences */
400#define SSL_OP_CIPHER_SERVER_PREFERENCE 0x00400000L
401
402#define SSL_OP_NO_TLSv1 0x04000000L
403#define SSL_OP_NO_TLSv1_2 0x08000000L
404#define SSL_OP_NO_TLSv1_1 0x10000000L
405
406#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
407#define SSL_OP_NO_TLSv1_3 0x20000000L
408#endif
409
410#define SSL_OP_NO_DTLSv1 0x40000000L
411#define SSL_OP_NO_DTLSv1_2 0x80000000L
412
413/* SSL_OP_ALL: various bug workarounds that should be rather harmless. */
414#define SSL_OP_ALL \
415 (SSL_OP_LEGACY_SERVER_CONNECT)
416
417/* Obsolete flags kept for compatibility. No sane code should use them. */
418#define SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION 0x0
419#define SSL_OP_CISCO_ANYCONNECT 0x0
420#define SSL_OP_CRYPTOPRO_TLSEXT_BUG 0x0
421#define SSL_OP_EPHEMERAL_RSA 0x0
422#define SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER 0x0
423#define SSL_OP_MICROSOFT_SESS_ID_BUG 0x0
424#define SSL_OP_MSIE_SSLV2_RSA_PADDING 0x0
425#define SSL_OP_NETSCAPE_CA_DN_BUG 0x0
426#define SSL_OP_NETSCAPE_CHALLENGE_BUG 0x0
427#define SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG 0x0
428#define SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG 0x0
429#define SSL_OP_NO_COMPRESSION 0x0
430#define SSL_OP_NO_SSLv2 0x0
431#define SSL_OP_NO_SSLv3 0x0
432#define SSL_OP_PKCS1_CHECK_1 0x0
433#define SSL_OP_PKCS1_CHECK_2 0x0
434#define SSL_OP_SAFARI_ECDHE_ECDSA_BUG 0x0
435#define SSL_OP_SINGLE_ECDH_USE 0x0
436#define SSL_OP_SSLEAY_080_CLIENT_DH_BUG 0x0
437#define SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG 0x0
438#define SSL_OP_TLSEXT_PADDING 0x0
439#define SSL_OP_TLS_BLOCK_PADDING_BUG 0x0
440#define SSL_OP_TLS_D5_BUG 0x0
441#define SSL_OP_TLS_ROLLBACK_BUG 0x0
442
443/* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
444 * when just a single record has been written): */
445#define SSL_MODE_ENABLE_PARTIAL_WRITE 0x00000001L
446/* Make it possible to retry SSL_write() with changed buffer location
447 * (buffer contents must stay the same!); this is not the default to avoid
448 * the misconception that non-blocking SSL_write() behaves like
449 * non-blocking write(): */
450#define SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER 0x00000002L
451/* Never bother the application with retries if the transport
452 * is blocking: */
453#define SSL_MODE_AUTO_RETRY 0x00000004L
454/* Don't attempt to automatically build certificate chain */
455#define SSL_MODE_NO_AUTO_CHAIN 0x00000008L
456/* Save RAM by releasing read and write buffers when they're empty. (SSL3 and
457 * TLS only.) "Released" buffers are put onto a free-list in the context
458 * or just freed (depending on the context's setting for freelist_max_len). */
459#define SSL_MODE_RELEASE_BUFFERS 0x00000010L
460
461/* Note: SSL[_CTX]_set_{options,mode} use |= op on the previous value,
462 * they cannot be used to clear bits. */
463
464#define SSL_CTX_set_options(ctx,op) \
465 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,(op),NULL)
466#define SSL_CTX_clear_options(ctx,op) \
467 SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_OPTIONS,(op),NULL)
468#define SSL_CTX_get_options(ctx) \
469 SSL_CTX_ctrl((ctx),SSL_CTRL_OPTIONS,0,NULL)
470#define SSL_set_options(ssl,op) \
471 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,(op),NULL)
472#define SSL_clear_options(ssl,op) \
473 SSL_ctrl((ssl),SSL_CTRL_CLEAR_OPTIONS,(op),NULL)
474#define SSL_get_options(ssl) \
475 SSL_ctrl((ssl),SSL_CTRL_OPTIONS,0,NULL)
476
477#define SSL_CTX_set_mode(ctx,op) \
478 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL)
479#define SSL_CTX_clear_mode(ctx,op) \
480 SSL_CTX_ctrl((ctx),SSL_CTRL_CLEAR_MODE,(op),NULL)
481#define SSL_CTX_get_mode(ctx) \
482 SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,0,NULL)
483#define SSL_clear_mode(ssl,op) \
484 SSL_ctrl((ssl),SSL_CTRL_CLEAR_MODE,(op),NULL)
485#define SSL_set_mode(ssl,op) \
486 SSL_ctrl((ssl),SSL_CTRL_MODE,(op),NULL)
487#define SSL_get_mode(ssl) \
488 SSL_ctrl((ssl),SSL_CTRL_MODE,0,NULL)
489#define SSL_set_mtu(ssl, mtu) \
490 SSL_ctrl((ssl),SSL_CTRL_SET_MTU,(mtu),NULL)
491
492#define SSL_get_secure_renegotiation_support(ssl) \
493 SSL_ctrl((ssl), SSL_CTRL_GET_RI_SUPPORT, 0, NULL)
494
495void SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p,
496 int version, int content_type, const void *buf, size_t len, SSL *ssl,
497 void *arg));
498void SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version,
499 int content_type, const void *buf, size_t len, SSL *ssl, void *arg));
500#define SSL_CTX_set_msg_callback_arg(ctx, arg) SSL_CTX_ctrl((ctx), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
501#define SSL_set_msg_callback_arg(ssl, arg) SSL_ctrl((ssl), SSL_CTRL_SET_MSG_CALLBACK_ARG, 0, (arg))
502typedef void (*SSL_CTX_keylog_cb_func)(const SSL *ssl, const char *line);
503void SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb);
504SSL_CTX_keylog_cb_func SSL_CTX_get_keylog_callback(const SSL_CTX *ctx);
505int SSL_set_num_tickets(SSL *s, size_t num_tickets);
506size_t SSL_get_num_tickets(const SSL *s);
507int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets);
508size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx);
509STACK_OF(X509) *SSL_get0_verified_chain(const SSL *s);
510
511#define SSL_MAX_CERT_LIST_DEFAULT 1024*100 /* 100k max cert list :-) */
512
513#define SSL_SESSION_CACHE_MAX_SIZE_DEFAULT (1024*20)
514
515/* This callback type is used inside SSL_CTX, SSL, and in the functions that set
516 * them. It is used to override the generation of SSL/TLS session IDs in a
517 * server. Return value should be zero on an error, non-zero to proceed. Also,
518 * callbacks should themselves check if the id they generate is unique otherwise
519 * the SSL handshake will fail with an error - callbacks can do this using the
520 * 'ssl' value they're passed by;
521 * SSL_has_matching_session_id(ssl, id, *id_len)
522 * The length value passed in is set at the maximum size the session ID can be.
523 * In SSLv2 this is 16 bytes, whereas SSLv3/TLSv1 it is 32 bytes. The callback
524 * can alter this length to be less if desired, but under SSLv2 session IDs are
525 * supposed to be fixed at 16 bytes so the id will be padded after the callback
526 * returns in this case. It is also an error for the callback to set the size to
527 * zero. */
528typedef int (*GEN_SESSION_CB)(const SSL *ssl, unsigned char *id,
529 unsigned int *id_len);
530
531typedef struct ssl_comp_st SSL_COMP;
532
533#ifdef LIBRESSL_INTERNAL
534DECLARE_STACK_OF(SSL_COMP)
535struct lhash_st_SSL_SESSION {
536 int dummy;
537};
538#endif
539
540#define SSL_SESS_CACHE_OFF 0x0000
541#define SSL_SESS_CACHE_CLIENT 0x0001
542#define SSL_SESS_CACHE_SERVER 0x0002
543#define SSL_SESS_CACHE_BOTH (SSL_SESS_CACHE_CLIENT|SSL_SESS_CACHE_SERVER)
544#define SSL_SESS_CACHE_NO_AUTO_CLEAR 0x0080
545/* enough comments already ... see SSL_CTX_set_session_cache_mode(3) */
546#define SSL_SESS_CACHE_NO_INTERNAL_LOOKUP 0x0100
547#define SSL_SESS_CACHE_NO_INTERNAL_STORE 0x0200
548#define SSL_SESS_CACHE_NO_INTERNAL \
549 (SSL_SESS_CACHE_NO_INTERNAL_LOOKUP|SSL_SESS_CACHE_NO_INTERNAL_STORE)
550
551struct lhash_st_SSL_SESSION *SSL_CTX_sessions(SSL_CTX *ctx);
552#define SSL_CTX_sess_number(ctx) \
553 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_NUMBER,0,NULL)
554#define SSL_CTX_sess_connect(ctx) \
555 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT,0,NULL)
556#define SSL_CTX_sess_connect_good(ctx) \
557 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_GOOD,0,NULL)
558#define SSL_CTX_sess_connect_renegotiate(ctx) \
559 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CONNECT_RENEGOTIATE,0,NULL)
560#define SSL_CTX_sess_accept(ctx) \
561 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT,0,NULL)
562#define SSL_CTX_sess_accept_renegotiate(ctx) \
563 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_RENEGOTIATE,0,NULL)
564#define SSL_CTX_sess_accept_good(ctx) \
565 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_ACCEPT_GOOD,0,NULL)
566#define SSL_CTX_sess_hits(ctx) \
567 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_HIT,0,NULL)
568#define SSL_CTX_sess_cb_hits(ctx) \
569 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CB_HIT,0,NULL)
570#define SSL_CTX_sess_misses(ctx) \
571 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_MISSES,0,NULL)
572#define SSL_CTX_sess_timeouts(ctx) \
573 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_TIMEOUTS,0,NULL)
574#define SSL_CTX_sess_cache_full(ctx) \
575 SSL_CTX_ctrl(ctx,SSL_CTRL_SESS_CACHE_FULL,0,NULL)
576
577void SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
578 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess));
579int (*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
580 SSL_SESSION *sess);
581void SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
582 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess));
583void (*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(struct ssl_ctx_st *ctx,
584 SSL_SESSION *sess);
585void SSL_CTX_sess_set_get_cb(SSL_CTX *ctx,
586 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
587 const unsigned char *data, int len, int *copy));
588SSL_SESSION *(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(struct ssl_st *ssl,
589 const unsigned char *data, int len, int *copy);
590void SSL_CTX_set_info_callback(SSL_CTX *ctx, void (*cb)(const SSL *ssl,
591 int type, int val));
592void (*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl, int type,
593 int val);
594void SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
595 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey));
596int (*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL *ssl, X509 **x509,
597 EVP_PKEY **pkey);
598void SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
599 int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
600 unsigned int *cookie_len));
601void SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
602 int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie,
603 unsigned int cookie_len));
604void SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *s, int (*cb)(SSL *ssl,
605 const unsigned char **out, unsigned int *outlen, void *arg), void *arg);
606void SSL_CTX_set_next_proto_select_cb(SSL_CTX *s, int (*cb)(SSL *ssl,
607 unsigned char **out, unsigned char *outlen, const unsigned char *in,
608 unsigned int inlen, void *arg), void *arg);
609
610int SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
611 const unsigned char *in, unsigned int inlen, const unsigned char *client,
612 unsigned int client_len);
613void SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
614 unsigned int *len);
615
616#define OPENSSL_NPN_UNSUPPORTED 0
617#define OPENSSL_NPN_NEGOTIATED 1
618#define OPENSSL_NPN_NO_OVERLAP 2
619
620int SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
621 unsigned int protos_len);
622int SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
623 unsigned int protos_len);
624void SSL_CTX_set_alpn_select_cb(SSL_CTX *ctx,
625 int (*cb)(SSL *ssl, const unsigned char **out, unsigned char *outlen,
626 const unsigned char *in, unsigned int inlen, void *arg), void *arg);
627void SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
628 unsigned int *len);
629
630#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
631typedef int (*SSL_psk_use_session_cb_func)(SSL *ssl, const EVP_MD *md,
632 const unsigned char **id, size_t *idlen, SSL_SESSION **sess);
633void SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb);
634#endif
635
636#define SSL_NOTHING 1
637#define SSL_WRITING 2
638#define SSL_READING 3
639#define SSL_X509_LOOKUP 4
640
641/* These will only be used when doing non-blocking IO */
642#define SSL_want_nothing(s) (SSL_want(s) == SSL_NOTHING)
643#define SSL_want_read(s) (SSL_want(s) == SSL_READING)
644#define SSL_want_write(s) (SSL_want(s) == SSL_WRITING)
645#define SSL_want_x509_lookup(s) (SSL_want(s) == SSL_X509_LOOKUP)
646
647#define SSL_MAC_FLAG_READ_MAC_STREAM 1
648#define SSL_MAC_FLAG_WRITE_MAC_STREAM 2
649
650#ifdef __cplusplus
651}
652#endif
653
654#include <openssl/ssl3.h>
655#include <openssl/tls1.h> /* This is mostly sslv3 with a few tweaks */
656#include <openssl/dtls1.h> /* Datagram TLS */
657#include <openssl/srtp.h> /* Support for the use_srtp extension */
658
659#ifdef __cplusplus
660extern "C" {
661#endif
662
663/* compatibility */
664#define SSL_set_app_data(s,arg) (SSL_set_ex_data(s,0,(char *)arg))
665#define SSL_get_app_data(s) (SSL_get_ex_data(s,0))
666#define SSL_SESSION_set_app_data(s,a) (SSL_SESSION_set_ex_data(s,0,(char *)a))
667#define SSL_SESSION_get_app_data(s) (SSL_SESSION_get_ex_data(s,0))
668#define SSL_CTX_get_app_data(ctx) (SSL_CTX_get_ex_data(ctx,0))
669#define SSL_CTX_set_app_data(ctx,arg) (SSL_CTX_set_ex_data(ctx,0,(char *)arg))
670
671/* The following are the possible values for ssl->state are are
672 * used to indicate where we are up to in the SSL connection establishment.
673 * The macros that follow are about the only things you should need to use
674 * and even then, only when using non-blocking IO.
675 * It can also be useful to work out where you were when the connection
676 * failed */
677
678#define SSL_ST_CONNECT 0x1000
679#define SSL_ST_ACCEPT 0x2000
680#define SSL_ST_MASK 0x0FFF
681#define SSL_ST_INIT (SSL_ST_CONNECT|SSL_ST_ACCEPT)
682#define SSL_ST_BEFORE 0x4000
683#define SSL_ST_OK 0x03
684#define SSL_ST_RENEGOTIATE (0x04|SSL_ST_INIT)
685
686#define SSL_CB_LOOP 0x01
687#define SSL_CB_EXIT 0x02
688#define SSL_CB_READ 0x04
689#define SSL_CB_WRITE 0x08
690#define SSL_CB_ALERT 0x4000 /* used in callback */
691#define SSL_CB_READ_ALERT (SSL_CB_ALERT|SSL_CB_READ)
692#define SSL_CB_WRITE_ALERT (SSL_CB_ALERT|SSL_CB_WRITE)
693#define SSL_CB_ACCEPT_LOOP (SSL_ST_ACCEPT|SSL_CB_LOOP)
694#define SSL_CB_ACCEPT_EXIT (SSL_ST_ACCEPT|SSL_CB_EXIT)
695#define SSL_CB_CONNECT_LOOP (SSL_ST_CONNECT|SSL_CB_LOOP)
696#define SSL_CB_CONNECT_EXIT (SSL_ST_CONNECT|SSL_CB_EXIT)
697#define SSL_CB_HANDSHAKE_START 0x10
698#define SSL_CB_HANDSHAKE_DONE 0x20
699
700/* Is the SSL_connection established? */
701#define SSL_get_state(a) (SSL_state((a)))
702#define SSL_is_init_finished(a) (SSL_state((a)) == SSL_ST_OK)
703#define SSL_in_init(a) (SSL_state((a))&SSL_ST_INIT)
704#define SSL_in_before(a) (SSL_state((a))&SSL_ST_BEFORE)
705#define SSL_in_connect_init(a) (SSL_state((a))&SSL_ST_CONNECT)
706#define SSL_in_accept_init(a) (SSL_state((a))&SSL_ST_ACCEPT)
707
708/* The following 2 states are kept in ssl->rstate when reads fail,
709 * you should not need these */
710#define SSL_ST_READ_HEADER 0xF0
711#define SSL_ST_READ_BODY 0xF1
712#define SSL_ST_READ_DONE 0xF2
713
714/* Obtain latest Finished message
715 * -- that we sent (SSL_get_finished)
716 * -- that we expected from peer (SSL_get_peer_finished).
717 * Returns length (0 == no Finished so far), copies up to 'count' bytes. */
718size_t SSL_get_finished(const SSL *s, void *buf, size_t count);
719size_t SSL_get_peer_finished(const SSL *s, void *buf, size_t count);
720
721/* use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
722 * are 'ored' with SSL_VERIFY_PEER if they are desired */
723#define SSL_VERIFY_NONE 0x00
724#define SSL_VERIFY_PEER 0x01
725#define SSL_VERIFY_FAIL_IF_NO_PEER_CERT 0x02
726#define SSL_VERIFY_CLIENT_ONCE 0x04
727#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
728#define SSL_VERIFY_POST_HANDSHAKE 0x08
729
730int SSL_verify_client_post_handshake(SSL *s);
731void SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val);
732void SSL_set_post_handshake_auth(SSL *s, int val);
733#endif
734
735#define OpenSSL_add_ssl_algorithms() SSL_library_init()
736#define SSLeay_add_ssl_algorithms() SSL_library_init()
737
738/* More backward compatibility */
739#define SSL_get_cipher(s) \
740 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
741#define SSL_get_cipher_bits(s,np) \
742 SSL_CIPHER_get_bits(SSL_get_current_cipher(s),np)
743#define SSL_get_cipher_version(s) \
744 SSL_CIPHER_get_version(SSL_get_current_cipher(s))
745#define SSL_get_cipher_name(s) \
746 SSL_CIPHER_get_name(SSL_get_current_cipher(s))
747#define SSL_get_time(a) SSL_SESSION_get_time(a)
748#define SSL_set_time(a,b) SSL_SESSION_set_time((a),(b))
749#define SSL_get_timeout(a) SSL_SESSION_get_timeout(a)
750#define SSL_set_timeout(a,b) SSL_SESSION_set_timeout((a),(b))
751
752#define d2i_SSL_SESSION_bio(bp,s_id) ASN1_d2i_bio_of(SSL_SESSION,SSL_SESSION_new,d2i_SSL_SESSION,bp,s_id)
753#define i2d_SSL_SESSION_bio(bp,s_id) ASN1_i2d_bio_of(SSL_SESSION,i2d_SSL_SESSION,bp,s_id)
754
755SSL_SESSION *PEM_read_bio_SSL_SESSION(BIO *bp, SSL_SESSION **x,
756 pem_password_cb *cb, void *u);
757SSL_SESSION *PEM_read_SSL_SESSION(FILE *fp, SSL_SESSION **x,
758 pem_password_cb *cb, void *u);
759int PEM_write_bio_SSL_SESSION(BIO *bp, SSL_SESSION *x);
760int PEM_write_SSL_SESSION(FILE *fp, SSL_SESSION *x);
761
762/*
763 * TLS Alerts.
764 *
765 * https://www.iana.org/assignments/tls-parameters/#tls-parameters-6
766 */
767
768/* Obsolete alerts. */
769#ifndef LIBRESSL_INTERNAL
770#define SSL_AD_DECRYPTION_FAILED 21 /* Removed in TLSv1.1 */
771#define SSL_AD_NO_CERTIFICATE 41 /* Removed in TLSv1.0 */
772#define SSL_AD_EXPORT_RESTRICTION 60 /* Removed in TLSv1.1 */
773#endif
774
775#define SSL_AD_CLOSE_NOTIFY 0
776#define SSL_AD_UNEXPECTED_MESSAGE 10
777#define SSL_AD_BAD_RECORD_MAC 20
778#define SSL_AD_RECORD_OVERFLOW 22
779#define SSL_AD_DECOMPRESSION_FAILURE 30 /* Removed in TLSv1.3 */
780#define SSL_AD_HANDSHAKE_FAILURE 40
781#define SSL_AD_BAD_CERTIFICATE 42
782#define SSL_AD_UNSUPPORTED_CERTIFICATE 43
783#define SSL_AD_CERTIFICATE_REVOKED 44
784#define SSL_AD_CERTIFICATE_EXPIRED 45
785#define SSL_AD_CERTIFICATE_UNKNOWN 46
786#define SSL_AD_ILLEGAL_PARAMETER 47
787#define SSL_AD_UNKNOWN_CA 48
788#define SSL_AD_ACCESS_DENIED 49
789#define SSL_AD_DECODE_ERROR 50
790#define SSL_AD_DECRYPT_ERROR 51
791#define SSL_AD_PROTOCOL_VERSION 70
792#define SSL_AD_INSUFFICIENT_SECURITY 71
793#define SSL_AD_INTERNAL_ERROR 80
794#define SSL_AD_INAPPROPRIATE_FALLBACK 86
795#define SSL_AD_USER_CANCELLED 90
796#define SSL_AD_NO_RENEGOTIATION 100 /* Removed in TLSv1.3 */
797#define SSL_AD_MISSING_EXTENSION 109 /* Added in TLSv1.3. */
798#define SSL_AD_UNSUPPORTED_EXTENSION 110
799#define SSL_AD_CERTIFICATE_UNOBTAINABLE 111 /* Removed in TLSv1.3 */
800#define SSL_AD_UNRECOGNIZED_NAME 112
801#define SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113
802#define SSL_AD_BAD_CERTIFICATE_HASH_VALUE 114 /* Removed in TLSv1.3 */
803#define SSL_AD_UNKNOWN_PSK_IDENTITY 115
804#define SSL_AD_CERTIFICATE_REQUIRED 116
805#define SSL_AD_NO_APPLICATION_PROTOCOL 120
806
807/* Offset to get an SSL_R_... value from an SSL_AD_... value. */
808#define SSL_AD_REASON_OFFSET 1000
809
810#define SSL_ERROR_NONE 0
811#define SSL_ERROR_SSL 1
812#define SSL_ERROR_WANT_READ 2
813#define SSL_ERROR_WANT_WRITE 3
814#define SSL_ERROR_WANT_X509_LOOKUP 4
815#define SSL_ERROR_SYSCALL 5
816#define SSL_ERROR_ZERO_RETURN 6
817#define SSL_ERROR_WANT_CONNECT 7
818#define SSL_ERROR_WANT_ACCEPT 8
819#define SSL_ERROR_WANT_ASYNC 9
820#define SSL_ERROR_WANT_ASYNC_JOB 10
821#define SSL_ERROR_WANT_CLIENT_HELLO_CB 11
822
823#define SSL_CTRL_NEED_TMP_RSA 1
824#define SSL_CTRL_SET_TMP_RSA 2
825#define SSL_CTRL_SET_TMP_DH 3
826#define SSL_CTRL_SET_TMP_ECDH 4
827#define SSL_CTRL_SET_TMP_RSA_CB 5
828#define SSL_CTRL_SET_TMP_DH_CB 6
829#define SSL_CTRL_SET_TMP_ECDH_CB 7
830
831#define SSL_CTRL_GET_SESSION_REUSED 8
832#define SSL_CTRL_GET_CLIENT_CERT_REQUEST 9
833#define SSL_CTRL_GET_NUM_RENEGOTIATIONS 10
834#define SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS 11
835#define SSL_CTRL_GET_TOTAL_RENEGOTIATIONS 12
836#define SSL_CTRL_GET_FLAGS 13
837#define SSL_CTRL_EXTRA_CHAIN_CERT 14
838
839#define SSL_CTRL_SET_MSG_CALLBACK 15
840#define SSL_CTRL_SET_MSG_CALLBACK_ARG 16
841
842/* only applies to datagram connections */
843#define SSL_CTRL_SET_MTU 17
844/* Stats */
845#define SSL_CTRL_SESS_NUMBER 20
846#define SSL_CTRL_SESS_CONNECT 21
847#define SSL_CTRL_SESS_CONNECT_GOOD 22
848#define SSL_CTRL_SESS_CONNECT_RENEGOTIATE 23
849#define SSL_CTRL_SESS_ACCEPT 24
850#define SSL_CTRL_SESS_ACCEPT_GOOD 25
851#define SSL_CTRL_SESS_ACCEPT_RENEGOTIATE 26
852#define SSL_CTRL_SESS_HIT 27
853#define SSL_CTRL_SESS_CB_HIT 28
854#define SSL_CTRL_SESS_MISSES 29
855#define SSL_CTRL_SESS_TIMEOUTS 30
856#define SSL_CTRL_SESS_CACHE_FULL 31
857#define SSL_CTRL_OPTIONS 32
858#define SSL_CTRL_MODE 33
859
860#define SSL_CTRL_GET_READ_AHEAD 40
861#define SSL_CTRL_SET_READ_AHEAD 41
862#define SSL_CTRL_SET_SESS_CACHE_SIZE 42
863#define SSL_CTRL_GET_SESS_CACHE_SIZE 43
864#define SSL_CTRL_SET_SESS_CACHE_MODE 44
865#define SSL_CTRL_GET_SESS_CACHE_MODE 45
866
867#define SSL_CTRL_GET_MAX_CERT_LIST 50
868#define SSL_CTRL_SET_MAX_CERT_LIST 51
869
870#define SSL_CTRL_SET_MAX_SEND_FRAGMENT 52
871
872/* see tls1.h for macros based on these */
873#define SSL_CTRL_SET_TLSEXT_SERVERNAME_CB 53
874#define SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG 54
875#define SSL_CTRL_SET_TLSEXT_HOSTNAME 55
876#define SSL_CTRL_SET_TLSEXT_DEBUG_CB 56
877#define SSL_CTRL_SET_TLSEXT_DEBUG_ARG 57
878#define SSL_CTRL_GET_TLSEXT_TICKET_KEYS 58
879#define SSL_CTRL_SET_TLSEXT_TICKET_KEYS 59
880#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB 128
881#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB 63
882#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG 129
883#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG 64
884#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE 127
885#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE 65
886#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS 66
887#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS 67
888#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS 68
889#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS 69
890#define SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP 70
891#define SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP 71
892
893#define SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB 72
894
895#define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME_CB 75
896#define SSL_CTRL_SET_SRP_VERIFY_PARAM_CB 76
897#define SSL_CTRL_SET_SRP_GIVE_CLIENT_PWD_CB 77
898
899#define SSL_CTRL_SET_SRP_ARG 78
900#define SSL_CTRL_SET_TLS_EXT_SRP_USERNAME 79
901#define SSL_CTRL_SET_TLS_EXT_SRP_STRENGTH 80
902#define SSL_CTRL_SET_TLS_EXT_SRP_PASSWORD 81
903
904#define DTLS_CTRL_GET_TIMEOUT 73
905#define DTLS_CTRL_HANDLE_TIMEOUT 74
906#define DTLS_CTRL_LISTEN 75
907
908#define SSL_CTRL_GET_RI_SUPPORT 76
909#define SSL_CTRL_CLEAR_OPTIONS 77
910#define SSL_CTRL_CLEAR_MODE 78
911
912#define SSL_CTRL_GET_EXTRA_CHAIN_CERTS 82
913#define SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS 83
914
915#define SSL_CTRL_CHAIN 88
916#define SSL_CTRL_CHAIN_CERT 89
917
918#define SSL_CTRL_SET_GROUPS 91
919#define SSL_CTRL_SET_GROUPS_LIST 92
920#define SSL_CTRL_GET_SHARED_GROUP 93
921#define SSL_CTRL_SET_ECDH_AUTO 94
922
923#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
924#define SSL_CTRL_GET_PEER_SIGNATURE_NID 108
925#define SSL_CTRL_GET_PEER_TMP_KEY 109
926#define SSL_CTRL_GET_SERVER_TMP_KEY SSL_CTRL_GET_PEER_TMP_KEY
927#else
928#define SSL_CTRL_GET_SERVER_TMP_KEY 109
929#endif
930
931#define SSL_CTRL_GET_CHAIN_CERTS 115
932
933#define SSL_CTRL_SET_DH_AUTO 118
934
935#define SSL_CTRL_SET_MIN_PROTO_VERSION 123
936#define SSL_CTRL_SET_MAX_PROTO_VERSION 124
937#define SSL_CTRL_GET_MIN_PROTO_VERSION 130
938#define SSL_CTRL_GET_MAX_PROTO_VERSION 131
939
940#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
941#define SSL_CTRL_GET_SIGNATURE_NID 132
942#endif
943
944#define DTLSv1_get_timeout(ssl, arg) \
945 SSL_ctrl(ssl,DTLS_CTRL_GET_TIMEOUT,0, (void *)arg)
946#define DTLSv1_handle_timeout(ssl) \
947 SSL_ctrl(ssl,DTLS_CTRL_HANDLE_TIMEOUT,0, NULL)
948#define DTLSv1_listen(ssl, peer) \
949 SSL_ctrl(ssl,DTLS_CTRL_LISTEN,0, (void *)peer)
950
951#define SSL_session_reused(ssl) \
952 SSL_ctrl((ssl),SSL_CTRL_GET_SESSION_REUSED,0,NULL)
953#define SSL_num_renegotiations(ssl) \
954 SSL_ctrl((ssl),SSL_CTRL_GET_NUM_RENEGOTIATIONS,0,NULL)
955#define SSL_clear_num_renegotiations(ssl) \
956 SSL_ctrl((ssl),SSL_CTRL_CLEAR_NUM_RENEGOTIATIONS,0,NULL)
957#define SSL_total_renegotiations(ssl) \
958 SSL_ctrl((ssl),SSL_CTRL_GET_TOTAL_RENEGOTIATIONS,0,NULL)
959
960#define SSL_CTX_need_tmp_RSA(ctx) \
961 SSL_CTX_ctrl(ctx,SSL_CTRL_NEED_TMP_RSA,0,NULL)
962#define SSL_CTX_set_tmp_rsa(ctx,rsa) \
963 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
964#define SSL_CTX_set_tmp_dh(ctx,dh) \
965 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
966#define SSL_CTX_set_tmp_ecdh(ctx,ecdh) \
967 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh)
968#define SSL_CTX_set_dh_auto(ctx, onoff) \
969 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
970#define SSL_CTX_set_ecdh_auto(ctx, onoff) \
971 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_ECDH_AUTO,onoff,NULL)
972
973#define SSL_need_tmp_RSA(ssl) \
974 SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
975#define SSL_set_tmp_rsa(ssl,rsa) \
976 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
977#define SSL_set_tmp_dh(ssl,dh) \
978 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
979#define SSL_set_tmp_ecdh(ssl,ecdh) \
980 SSL_ctrl(ssl,SSL_CTRL_SET_TMP_ECDH,0,(char *)ecdh)
981#define SSL_set_dh_auto(s, onoff) \
982 SSL_ctrl(s,SSL_CTRL_SET_DH_AUTO,onoff,NULL)
983#define SSL_set_ecdh_auto(s, onoff) \
984 SSL_ctrl(s,SSL_CTRL_SET_ECDH_AUTO,onoff,NULL)
985
986int SSL_CTX_set0_chain(SSL_CTX *ctx, STACK_OF(X509) *chain);
987int SSL_CTX_set1_chain(SSL_CTX *ctx, STACK_OF(X509) *chain);
988int SSL_CTX_add0_chain_cert(SSL_CTX *ctx, X509 *x509);
989int SSL_CTX_add1_chain_cert(SSL_CTX *ctx, X509 *x509);
990int SSL_CTX_get0_chain_certs(const SSL_CTX *ctx, STACK_OF(X509) **out_chain);
991int SSL_CTX_clear_chain_certs(SSL_CTX *ctx);
992
993int SSL_set0_chain(SSL *ssl, STACK_OF(X509) *chain);
994int SSL_set1_chain(SSL *ssl, STACK_OF(X509) *chain);
995int SSL_add0_chain_cert(SSL *ssl, X509 *x509);
996int SSL_add1_chain_cert(SSL *ssl, X509 *x509);
997int SSL_get0_chain_certs(const SSL *ssl, STACK_OF(X509) **out_chain);
998int SSL_clear_chain_certs(SSL *ssl);
999
1000int SSL_CTX_set1_groups(SSL_CTX *ctx, const int *groups, size_t groups_len);
1001int SSL_CTX_set1_groups_list(SSL_CTX *ctx, const char *groups);
1002
1003int SSL_set1_groups(SSL *ssl, const int *groups, size_t groups_len);
1004int SSL_set1_groups_list(SSL *ssl, const char *groups);
1005
1006int SSL_CTX_get_min_proto_version(SSL_CTX *ctx);
1007int SSL_CTX_get_max_proto_version(SSL_CTX *ctx);
1008int SSL_CTX_set_min_proto_version(SSL_CTX *ctx, uint16_t version);
1009int SSL_CTX_set_max_proto_version(SSL_CTX *ctx, uint16_t version);
1010
1011int SSL_get_min_proto_version(SSL *ssl);
1012int SSL_get_max_proto_version(SSL *ssl);
1013int SSL_set_min_proto_version(SSL *ssl, uint16_t version);
1014int SSL_set_max_proto_version(SSL *ssl, uint16_t version);
1015
1016const SSL_METHOD *SSL_CTX_get_ssl_method(const SSL_CTX *ctx);
1017
1018#ifndef LIBRESSL_INTERNAL
1019#define SSL_CTRL_SET_CURVES SSL_CTRL_SET_GROUPS
1020#define SSL_CTRL_SET_CURVES_LIST SSL_CTRL_SET_GROUPS_LIST
1021
1022#define SSL_CTX_set1_curves SSL_CTX_set1_groups
1023#define SSL_CTX_set1_curves_list SSL_CTX_set1_groups_list
1024#define SSL_set1_curves SSL_set1_groups
1025#define SSL_set1_curves_list SSL_set1_groups_list
1026#endif
1027
1028#define SSL_CTX_add_extra_chain_cert(ctx, x509) \
1029 SSL_CTX_ctrl(ctx, SSL_CTRL_EXTRA_CHAIN_CERT, 0, (char *)x509)
1030#define SSL_CTX_get_extra_chain_certs(ctx, px509) \
1031 SSL_CTX_ctrl(ctx, SSL_CTRL_GET_EXTRA_CHAIN_CERTS, 0, px509)
1032#define SSL_CTX_get_extra_chain_certs_only(ctx, px509) \
1033 SSL_CTX_ctrl(ctx, SSL_CTRL_GET_EXTRA_CHAIN_CERTS, 1, px509)
1034#define SSL_CTX_clear_extra_chain_certs(ctx) \
1035 SSL_CTX_ctrl(ctx, SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS, 0, NULL)
1036
1037#define SSL_get_shared_group(s, n) \
1038 SSL_ctrl((s), SSL_CTRL_GET_SHARED_GROUP, (n), NULL)
1039#define SSL_get_shared_curve SSL_get_shared_group
1040
1041#define SSL_get_server_tmp_key(s, pk) \
1042 SSL_ctrl(s,SSL_CTRL_GET_SERVER_TMP_KEY,0,pk)
1043
1044#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
1045#define SSL_get_signature_nid(s, pn) \
1046 SSL_ctrl(s, SSL_CTRL_GET_SIGNATURE_NID, 0, pn)
1047
1048#define SSL_get_peer_signature_nid(s, pn) \
1049 SSL_ctrl(s, SSL_CTRL_GET_PEER_SIGNATURE_NID, 0, pn)
1050#define SSL_get_peer_tmp_key(s, pk) \
1051 SSL_ctrl(s, SSL_CTRL_GET_PEER_TMP_KEY, 0, pk)
1052#endif /* LIBRESSL_HAS_TLS1_3 || LIBRESSL_INTERNAL */
1053
1054#ifndef LIBRESSL_INTERNAL
1055/*
1056 * Also provide those functions as macros for compatibility with
1057 * existing users.
1058 */
1059#define SSL_CTX_set0_chain SSL_CTX_set0_chain
1060#define SSL_CTX_set1_chain SSL_CTX_set1_chain
1061#define SSL_CTX_add0_chain_cert SSL_CTX_add0_chain_cert
1062#define SSL_CTX_add1_chain_cert SSL_CTX_add1_chain_cert
1063#define SSL_CTX_get0_chain_certs SSL_CTX_get0_chain_certs
1064#define SSL_CTX_clear_chain_certs SSL_CTX_clear_chain_certs
1065
1066#define SSL_add0_chain_cert SSL_add0_chain_cert
1067#define SSL_add1_chain_cert SSL_add1_chain_cert
1068#define SSL_set0_chain SSL_set0_chain
1069#define SSL_set1_chain SSL_set1_chain
1070#define SSL_get0_chain_certs SSL_get0_chain_certs
1071#define SSL_clear_chain_certs SSL_clear_chain_certs
1072
1073#define SSL_CTX_set1_groups SSL_CTX_set1_groups
1074#define SSL_CTX_set1_groups_list SSL_CTX_set1_groups_list
1075#define SSL_set1_groups SSL_set1_groups
1076#define SSL_set1_groups_list SSL_set1_groups_list
1077
1078#define SSL_CTX_get_min_proto_version SSL_CTX_get_min_proto_version
1079#define SSL_CTX_get_max_proto_version SSL_CTX_get_max_proto_version
1080#define SSL_CTX_set_min_proto_version SSL_CTX_set_min_proto_version
1081#define SSL_CTX_set_max_proto_version SSL_CTX_set_max_proto_version
1082
1083#define SSL_get_min_proto_version SSL_get_min_proto_version
1084#define SSL_get_max_proto_version SSL_get_max_proto_version
1085#define SSL_set_min_proto_version SSL_set_min_proto_version
1086#define SSL_set_max_proto_version SSL_set_max_proto_version
1087#endif
1088
1089const BIO_METHOD *BIO_f_ssl(void);
1090BIO *BIO_new_ssl(SSL_CTX *ctx, int client);
1091BIO *BIO_new_ssl_connect(SSL_CTX *ctx);
1092BIO *BIO_new_buffer_ssl_connect(SSL_CTX *ctx);
1093int BIO_ssl_copy_session_id(BIO *to, BIO *from);
1094void BIO_ssl_shutdown(BIO *ssl_bio);
1095
1096STACK_OF(SSL_CIPHER) *SSL_CTX_get_ciphers(const SSL_CTX *ctx);
1097int SSL_CTX_set_cipher_list(SSL_CTX *, const char *str);
1098#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
1099int SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str);
1100#endif
1101SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth);
1102void SSL_CTX_free(SSL_CTX *);
1103int SSL_CTX_up_ref(SSL_CTX *ctx);
1104long SSL_CTX_set_timeout(SSL_CTX *ctx, long t);
1105long SSL_CTX_get_timeout(const SSL_CTX *ctx);
1106X509_STORE *SSL_CTX_get_cert_store(const SSL_CTX *);
1107void SSL_CTX_set_cert_store(SSL_CTX *, X509_STORE *);
1108void SSL_CTX_set1_cert_store(SSL_CTX *ctx, X509_STORE *store);
1109X509 *SSL_CTX_get0_certificate(const SSL_CTX *ctx);
1110EVP_PKEY *SSL_CTX_get0_privatekey(const SSL_CTX *ctx);
1111int SSL_want(const SSL *s);
1112int SSL_clear(SSL *s);
1113
1114void SSL_CTX_flush_sessions(SSL_CTX *ctx, long tm);
1115
1116const SSL_CIPHER *SSL_get_current_cipher(const SSL *s);
1117int SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits);
1118const char * SSL_CIPHER_get_version(const SSL_CIPHER *c);
1119const char * SSL_CIPHER_get_name(const SSL_CIPHER *c);
1120unsigned long SSL_CIPHER_get_id(const SSL_CIPHER *c);
1121uint16_t SSL_CIPHER_get_value(const SSL_CIPHER *c);
1122const SSL_CIPHER *SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr);
1123int SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c);
1124int SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c);
1125int SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c);
1126int SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c);
1127const EVP_MD *SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c);
1128int SSL_CIPHER_is_aead(const SSL_CIPHER *c);
1129
1130int SSL_get_fd(const SSL *s);
1131int SSL_get_rfd(const SSL *s);
1132int SSL_get_wfd(const SSL *s);
1133const char * SSL_get_cipher_list(const SSL *s, int n);
1134char * SSL_get_shared_ciphers(const SSL *s, char *buf, int len);
1135int SSL_get_read_ahead(const SSL * s);
1136int SSL_pending(const SSL *s);
1137int SSL_set_fd(SSL *s, int fd);
1138int SSL_set_rfd(SSL *s, int fd);
1139int SSL_set_wfd(SSL *s, int fd);
1140void SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio);
1141BIO * SSL_get_rbio(const SSL *s);
1142void SSL_set0_rbio(SSL *s, BIO *rbio);
1143BIO * SSL_get_wbio(const SSL *s);
1144int SSL_set_cipher_list(SSL *s, const char *str);
1145#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
1146int SSL_set_ciphersuites(SSL *s, const char *str);
1147#endif
1148void SSL_set_read_ahead(SSL *s, int yes);
1149int SSL_get_verify_mode(const SSL *s);
1150int SSL_get_verify_depth(const SSL *s);
1151int (*SSL_get_verify_callback(const SSL *s))(int, X509_STORE_CTX *);
1152void SSL_set_verify(SSL *s, int mode,
1153 int (*callback)(int ok, X509_STORE_CTX *ctx));
1154void SSL_set_verify_depth(SSL *s, int depth);
1155int SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa);
1156int SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const unsigned char *d, long len);
1157int SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey);
1158int SSL_use_PrivateKey_ASN1(int pk, SSL *ssl, const unsigned char *d, long len);
1159int SSL_use_certificate(SSL *ssl, X509 *x);
1160int SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len);
1161
1162int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type);
1163int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type);
1164int SSL_use_certificate_file(SSL *ssl, const char *file, int type);
1165int SSL_use_certificate_chain_file(SSL *ssl, const char *file);
1166int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1167int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
1168int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);
1169int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file); /* PEM type */
1170int SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len);
1171STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file);
1172int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1173 const char *file);
1174int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stackCAs,
1175 const char *dir);
1176
1177void SSL_load_error_strings(void );
1178const char *SSL_state_string(const SSL *s);
1179const char *SSL_rstate_string(const SSL *s);
1180const char *SSL_state_string_long(const SSL *s);
1181const char *SSL_rstate_string_long(const SSL *s);
1182const SSL_CIPHER *SSL_SESSION_get0_cipher(const SSL_SESSION *ss);
1183size_t SSL_SESSION_get_master_key(const SSL_SESSION *ss,
1184 unsigned char *out, size_t max_out);
1185int SSL_SESSION_get_protocol_version(const SSL_SESSION *s);
1186long SSL_SESSION_get_time(const SSL_SESSION *s);
1187long SSL_SESSION_set_time(SSL_SESSION *s, long t);
1188long SSL_SESSION_get_timeout(const SSL_SESSION *s);
1189long SSL_SESSION_set_timeout(SSL_SESSION *s, long t);
1190int SSL_copy_session_id(SSL *to, const SSL *from);
1191X509 *SSL_SESSION_get0_peer(SSL_SESSION *s);
1192int SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
1193 unsigned int sid_len);
1194int SSL_SESSION_set1_id_context(SSL_SESSION *s,
1195 const unsigned char *sid_ctx, unsigned int sid_ctx_len);
1196#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
1197int SSL_SESSION_is_resumable(const SSL_SESSION *s);
1198#endif
1199
1200SSL_SESSION *SSL_SESSION_new(void);
1201void SSL_SESSION_free(SSL_SESSION *ses);
1202int SSL_SESSION_up_ref(SSL_SESSION *ss);
1203const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *ss,
1204 unsigned int *len);
1205const unsigned char *SSL_SESSION_get0_id_context(const SSL_SESSION *ss,
1206 unsigned int *len);
1207#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
1208uint32_t SSL_SESSION_get_max_early_data(const SSL_SESSION *sess);
1209int SSL_SESSION_set_max_early_data(SSL_SESSION *sess, uint32_t max_early_data);
1210#endif
1211unsigned long SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s);
1212int SSL_SESSION_has_ticket(const SSL_SESSION *s);
1213unsigned int SSL_SESSION_get_compress_id(const SSL_SESSION *ss);
1214int SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *ses);
1215int SSL_SESSION_print(BIO *fp, const SSL_SESSION *ses);
1216int i2d_SSL_SESSION(SSL_SESSION *in, unsigned char **pp);
1217int SSL_set_session(SSL *to, SSL_SESSION *session);
1218int SSL_CTX_add_session(SSL_CTX *s, SSL_SESSION *c);
1219int SSL_CTX_remove_session(SSL_CTX *, SSL_SESSION *c);
1220int SSL_CTX_set_generate_session_id(SSL_CTX *, GEN_SESSION_CB);
1221int SSL_set_generate_session_id(SSL *, GEN_SESSION_CB);
1222int SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
1223 unsigned int id_len);
1224SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp,
1225 long length);
1226
1227#ifdef HEADER_X509_H
1228X509 * SSL_get_peer_certificate(const SSL *s);
1229#endif
1230
1231STACK_OF(X509) *SSL_get_peer_cert_chain(const SSL *s);
1232
1233int SSL_CTX_get_verify_mode(const SSL_CTX *ctx);
1234int SSL_CTX_get_verify_depth(const SSL_CTX *ctx);
1235int (*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int, X509_STORE_CTX *);
1236void SSL_CTX_set_verify(SSL_CTX *ctx, int mode,
1237 int (*callback)(int, X509_STORE_CTX *));
1238void SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth);
1239void SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx, int (*cb)(X509_STORE_CTX *, void *), void *arg);
1240int SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa);
1241int SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len);
1242int SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey);
1243int SSL_CTX_use_PrivateKey_ASN1(int pk, SSL_CTX *ctx, const unsigned char *d, long len);
1244int SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x);
1245int SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d);
1246
1247pem_password_cb *SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx);
1248void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb);
1249void *SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx);
1250void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u);
1251
1252int SSL_CTX_check_private_key(const SSL_CTX *ctx);
1253int SSL_check_private_key(const SSL *ctx);
1254
1255int SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx, unsigned int sid_ctx_len);
1256
1257int SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx, unsigned int sid_ctx_len);
1258
1259int SSL_CTX_set_purpose(SSL_CTX *s, int purpose);
1260int SSL_set_purpose(SSL *s, int purpose);
1261int SSL_CTX_set_trust(SSL_CTX *s, int trust);
1262int SSL_set_trust(SSL *s, int trust);
1263int SSL_set1_host(SSL *s, const char *hostname);
1264void SSL_set_hostflags(SSL *s, unsigned int flags);
1265const char *SSL_get0_peername(SSL *s);
1266
1267X509_VERIFY_PARAM *SSL_CTX_get0_param(SSL_CTX *ctx);
1268int SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm);
1269X509_VERIFY_PARAM *SSL_get0_param(SSL *ssl);
1270int SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm);
1271
1272SSL *SSL_new(SSL_CTX *ctx);
1273void SSL_free(SSL *ssl);
1274int SSL_up_ref(SSL *ssl);
1275int SSL_accept(SSL *ssl);
1276int SSL_connect(SSL *ssl);
1277int SSL_is_dtls(const SSL *s);
1278int SSL_is_server(const SSL *s);
1279int SSL_read(SSL *ssl, void *buf, int num);
1280int SSL_peek(SSL *ssl, void *buf, int num);
1281int SSL_write(SSL *ssl, const void *buf, int num);
1282int SSL_read_ex(SSL *ssl, void *buf, size_t num, size_t *bytes_read);
1283int SSL_peek_ex(SSL *ssl, void *buf, size_t num, size_t *bytes_peeked);
1284int SSL_write_ex(SSL *ssl, const void *buf, size_t num, size_t *bytes_written);
1285
1286#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
1287uint32_t SSL_CTX_get_max_early_data(const SSL_CTX *ctx);
1288int SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data);
1289
1290uint32_t SSL_get_max_early_data(const SSL *s);
1291int SSL_set_max_early_data(SSL *s, uint32_t max_early_data);
1292
1293#define SSL_EARLY_DATA_NOT_SENT 0
1294#define SSL_EARLY_DATA_REJECTED 1
1295#define SSL_EARLY_DATA_ACCEPTED 2
1296int SSL_get_early_data_status(const SSL *s);
1297
1298#define SSL_READ_EARLY_DATA_ERROR 0
1299#define SSL_READ_EARLY_DATA_SUCCESS 1
1300#define SSL_READ_EARLY_DATA_FINISH 2
1301int SSL_read_early_data(SSL *s, void *buf, size_t num, size_t *readbytes);
1302int SSL_write_early_data(SSL *s, const void *buf, size_t num, size_t *written);
1303#endif
1304
1305long SSL_ctrl(SSL *ssl, int cmd, long larg, void *parg);
1306long SSL_callback_ctrl(SSL *, int, void (*)(void));
1307long SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg);
1308long SSL_CTX_callback_ctrl(SSL_CTX *, int, void (*)(void));
1309
1310int SSL_get_error(const SSL *s, int ret_code);
1311const char *SSL_get_version(const SSL *s);
1312
1313/* This sets the 'default' SSL version that SSL_new() will create */
1314int SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth);
1315
1316const SSL_METHOD *SSLv23_method(void); /* SSLv3 or TLSv1.* */
1317const SSL_METHOD *SSLv23_server_method(void); /* SSLv3 or TLSv1.* */
1318const SSL_METHOD *SSLv23_client_method(void); /* SSLv3 or TLSv1.* */
1319
1320const SSL_METHOD *TLSv1_method(void); /* TLSv1.0 */
1321const SSL_METHOD *TLSv1_server_method(void); /* TLSv1.0 */
1322const SSL_METHOD *TLSv1_client_method(void); /* TLSv1.0 */
1323
1324const SSL_METHOD *TLSv1_1_method(void); /* TLSv1.1 */
1325const SSL_METHOD *TLSv1_1_server_method(void); /* TLSv1.1 */
1326const SSL_METHOD *TLSv1_1_client_method(void); /* TLSv1.1 */
1327
1328const SSL_METHOD *TLSv1_2_method(void); /* TLSv1.2 */
1329const SSL_METHOD *TLSv1_2_server_method(void); /* TLSv1.2 */
1330const SSL_METHOD *TLSv1_2_client_method(void); /* TLSv1.2 */
1331
1332const SSL_METHOD *TLS_method(void); /* TLS v1.0 or later */
1333const SSL_METHOD *TLS_server_method(void); /* TLS v1.0 or later */
1334const SSL_METHOD *TLS_client_method(void); /* TLS v1.0 or later */
1335
1336const SSL_METHOD *DTLSv1_method(void); /* DTLSv1.0 */
1337const SSL_METHOD *DTLSv1_server_method(void); /* DTLSv1.0 */
1338const SSL_METHOD *DTLSv1_client_method(void); /* DTLSv1.0 */
1339
1340const SSL_METHOD *DTLSv1_2_method(void); /* DTLSv1.2 */
1341const SSL_METHOD *DTLSv1_2_server_method(void); /* DTLSv1.2 */
1342const SSL_METHOD *DTLSv1_2_client_method(void); /* DTLSv1.2 */
1343
1344const SSL_METHOD *DTLS_method(void); /* DTLS v1.0 or later */
1345const SSL_METHOD *DTLS_server_method(void); /* DTLS v1.0 or later */
1346const SSL_METHOD *DTLS_client_method(void); /* DTLS v1.0 or later */
1347
1348STACK_OF(SSL_CIPHER) *SSL_get_ciphers(const SSL *s);
1349STACK_OF(SSL_CIPHER) *SSL_get_client_ciphers(const SSL *s);
1350STACK_OF(SSL_CIPHER) *SSL_get1_supported_ciphers(SSL *s);
1351
1352int SSL_do_handshake(SSL *s);
1353int SSL_renegotiate(SSL *s);
1354int SSL_renegotiate_abbreviated(SSL *s);
1355int SSL_renegotiate_pending(SSL *s);
1356int SSL_shutdown(SSL *s);
1357
1358const SSL_METHOD *SSL_get_ssl_method(SSL *s);
1359int SSL_set_ssl_method(SSL *s, const SSL_METHOD *method);
1360const char *SSL_alert_type_string_long(int value);
1361const char *SSL_alert_type_string(int value);
1362const char *SSL_alert_desc_string_long(int value);
1363const char *SSL_alert_desc_string(int value);
1364
1365void SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list);
1366void SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list);
1367STACK_OF(X509_NAME) *SSL_get_client_CA_list(const SSL *s);
1368STACK_OF(X509_NAME) *SSL_CTX_get_client_CA_list(const SSL_CTX *s);
1369int SSL_add_client_CA(SSL *ssl, X509 *x);
1370int SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x);
1371
1372void SSL_set_connect_state(SSL *s);
1373void SSL_set_accept_state(SSL *s);
1374
1375long SSL_get_default_timeout(const SSL *s);
1376
1377char *SSL_CIPHER_description(const SSL_CIPHER *, char *buf, int size);
1378STACK_OF(X509_NAME) *SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk);
1379
1380SSL *SSL_dup(SSL *ssl);
1381
1382X509 *SSL_get_certificate(const SSL *ssl);
1383/* EVP_PKEY */ struct evp_pkey_st *SSL_get_privatekey(const SSL *ssl);
1384
1385void SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx,int mode);
1386int SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx);
1387void SSL_set_quiet_shutdown(SSL *ssl,int mode);
1388int SSL_get_quiet_shutdown(const SSL *ssl);
1389void SSL_set_shutdown(SSL *ssl,int mode);
1390int SSL_get_shutdown(const SSL *ssl);
1391int SSL_version(const SSL *ssl);
1392int SSL_CTX_set_default_verify_paths(SSL_CTX *ctx);
1393int SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
1394 const char *CApath);
1395int SSL_CTX_load_verify_mem(SSL_CTX *ctx, void *buf, int len);
1396#define SSL_get0_session SSL_get_session /* just peek at pointer */
1397SSL_SESSION *SSL_get_session(const SSL *ssl);
1398SSL_SESSION *SSL_get1_session(SSL *ssl); /* obtain a reference count */
1399SSL_CTX *SSL_get_SSL_CTX(const SSL *ssl);
1400SSL_CTX *SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx);
1401void SSL_set_info_callback(SSL *ssl,
1402 void (*cb)(const SSL *ssl, int type, int val));
1403void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int type, int val);
1404int SSL_state(const SSL *ssl);
1405void SSL_set_state(SSL *ssl, int state);
1406
1407void SSL_set_verify_result(SSL *ssl, long v);
1408long SSL_get_verify_result(const SSL *ssl);
1409
1410int SSL_set_ex_data(SSL *ssl, int idx, void *data);
1411void *SSL_get_ex_data(const SSL *ssl, int idx);
1412int SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1413 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1414
1415int SSL_SESSION_set_ex_data(SSL_SESSION *ss, int idx, void *data);
1416void *SSL_SESSION_get_ex_data(const SSL_SESSION *ss, int idx);
1417int SSL_SESSION_get_ex_new_index(long argl, void *argp,
1418 CRYPTO_EX_new *new_func, CRYPTO_EX_dup *dup_func,
1419 CRYPTO_EX_free *free_func);
1420
1421int SSL_CTX_set_ex_data(SSL_CTX *ssl, int idx, void *data);
1422void *SSL_CTX_get_ex_data(const SSL_CTX *ssl, int idx);
1423int SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1424 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1425
1426int SSL_get_ex_data_X509_STORE_CTX_idx(void );
1427
1428#define SSL_CTX_sess_set_cache_size(ctx,t) \
1429 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_SIZE,t,NULL)
1430#define SSL_CTX_sess_get_cache_size(ctx) \
1431 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_SIZE,0,NULL)
1432#define SSL_CTX_set_session_cache_mode(ctx,m) \
1433 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_SESS_CACHE_MODE,m,NULL)
1434#define SSL_CTX_get_session_cache_mode(ctx) \
1435 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_SESS_CACHE_MODE,0,NULL)
1436
1437#define SSL_CTX_get_default_read_ahead(ctx) SSL_CTX_get_read_ahead(ctx)
1438#define SSL_CTX_set_default_read_ahead(ctx,m) SSL_CTX_set_read_ahead(ctx,m)
1439#define SSL_CTX_get_read_ahead(ctx) \
1440 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_READ_AHEAD,0,NULL)
1441#define SSL_CTX_set_read_ahead(ctx,m) \
1442 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_READ_AHEAD,m,NULL)
1443#define SSL_CTX_get_max_cert_list(ctx) \
1444 SSL_CTX_ctrl(ctx,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1445#define SSL_CTX_set_max_cert_list(ctx,m) \
1446 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1447#define SSL_get_max_cert_list(ssl) \
1448 SSL_ctrl(ssl,SSL_CTRL_GET_MAX_CERT_LIST,0,NULL)
1449#define SSL_set_max_cert_list(ssl,m) \
1450 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_CERT_LIST,m,NULL)
1451
1452#define SSL_CTX_set_max_send_fragment(ctx,m) \
1453 SSL_CTX_ctrl(ctx,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
1454#define SSL_set_max_send_fragment(ssl,m) \
1455 SSL_ctrl(ssl,SSL_CTRL_SET_MAX_SEND_FRAGMENT,m,NULL)
1456
1457/* NB: the keylength is only applicable when is_export is true */
1458void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx,
1459 RSA *(*cb)(SSL *ssl, int is_export, int keylength));
1460
1461void SSL_set_tmp_rsa_callback(SSL *ssl,
1462 RSA *(*cb)(SSL *ssl, int is_export, int keylength));
1463void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
1464 DH *(*dh)(SSL *ssl, int is_export, int keylength));
1465void SSL_set_tmp_dh_callback(SSL *ssl,
1466 DH *(*dh)(SSL *ssl, int is_export, int keylength));
1467void SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx,
1468 EC_KEY *(*ecdh)(SSL *ssl, int is_export, int keylength));
1469void SSL_set_tmp_ecdh_callback(SSL *ssl,
1470 EC_KEY *(*ecdh)(SSL *ssl, int is_export, int keylength));
1471
1472size_t SSL_get_client_random(const SSL *s, unsigned char *out, size_t max_out);
1473size_t SSL_get_server_random(const SSL *s, unsigned char *out, size_t max_out);
1474
1475const void *SSL_get_current_compression(SSL *s);
1476const void *SSL_get_current_expansion(SSL *s);
1477
1478const char *SSL_COMP_get_name(const void *comp);
1479void *SSL_COMP_get_compression_methods(void);
1480
1481/* TLS extensions functions */
1482int SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len);
1483
1484int SSL_set_session_ticket_ext_cb(SSL *s,
1485 tls_session_ticket_ext_cb_fn cb, void *arg);
1486
1487/* Pre-shared secret session resumption functions */
1488int SSL_set_session_secret_cb(SSL *s,
1489 tls_session_secret_cb_fn tls_session_secret_cb, void *arg);
1490
1491int SSL_cache_hit(SSL *s);
1492
1493/* What the "other" parameter contains in security callback */
1494/* Mask for type */
1495#define SSL_SECOP_OTHER_TYPE 0xffff0000
1496#define SSL_SECOP_OTHER_NONE 0
1497#define SSL_SECOP_OTHER_CIPHER (1 << 16)
1498#define SSL_SECOP_OTHER_CURVE (2 << 16)
1499#define SSL_SECOP_OTHER_DH (3 << 16)
1500#define SSL_SECOP_OTHER_PKEY (4 << 16)
1501#define SSL_SECOP_OTHER_SIGALG (5 << 16)
1502#define SSL_SECOP_OTHER_CERT (6 << 16)
1503
1504/* Indicated operation refers to peer key or certificate */
1505#define SSL_SECOP_PEER 0x1000
1506
1507/* Values for "op" parameter in security callback */
1508
1509/* Called to filter ciphers */
1510/* Ciphers client supports */
1511#define SSL_SECOP_CIPHER_SUPPORTED (1 | SSL_SECOP_OTHER_CIPHER)
1512/* Cipher shared by client/server */
1513#define SSL_SECOP_CIPHER_SHARED (2 | SSL_SECOP_OTHER_CIPHER)
1514/* Sanity check of cipher server selects */
1515#define SSL_SECOP_CIPHER_CHECK (3 | SSL_SECOP_OTHER_CIPHER)
1516/* Curves supported by client */
1517#define SSL_SECOP_CURVE_SUPPORTED (4 | SSL_SECOP_OTHER_CURVE)
1518/* Curves shared by client/server */
1519#define SSL_SECOP_CURVE_SHARED (5 | SSL_SECOP_OTHER_CURVE)
1520/* Sanity check of curve server selects */
1521#define SSL_SECOP_CURVE_CHECK (6 | SSL_SECOP_OTHER_CURVE)
1522/* Temporary DH key */
1523/*
1524 * XXX: changed in OpenSSL e2b420fdd70 to (7 | SSL_SECOP_OTHER_PKEY)
1525 * Needs switching internal use of DH to EVP_PKEY. The code is not reachable
1526 * from outside the library as long as we do not expose the callback in the API.
1527 */
1528#define SSL_SECOP_TMP_DH (7 | SSL_SECOP_OTHER_DH)
1529/* SSL/TLS version */
1530#define SSL_SECOP_VERSION (9 | SSL_SECOP_OTHER_NONE)
1531/* Session tickets */
1532#define SSL_SECOP_TICKET (10 | SSL_SECOP_OTHER_NONE)
1533/* Supported signature algorithms sent to peer */
1534#define SSL_SECOP_SIGALG_SUPPORTED (11 | SSL_SECOP_OTHER_SIGALG)
1535/* Shared signature algorithm */
1536#define SSL_SECOP_SIGALG_SHARED (12 | SSL_SECOP_OTHER_SIGALG)
1537/* Sanity check signature algorithm allowed */
1538#define SSL_SECOP_SIGALG_CHECK (13 | SSL_SECOP_OTHER_SIGALG)
1539/* Used to get mask of supported public key signature algorithms */
1540#define SSL_SECOP_SIGALG_MASK (14 | SSL_SECOP_OTHER_SIGALG)
1541/* Use to see if compression is allowed */
1542#define SSL_SECOP_COMPRESSION (15 | SSL_SECOP_OTHER_NONE)
1543/* EE key in certificate */
1544#define SSL_SECOP_EE_KEY (16 | SSL_SECOP_OTHER_CERT)
1545/* CA key in certificate */
1546#define SSL_SECOP_CA_KEY (17 | SSL_SECOP_OTHER_CERT)
1547/* CA digest algorithm in certificate */
1548#define SSL_SECOP_CA_MD (18 | SSL_SECOP_OTHER_CERT)
1549/* Peer EE key in certificate */
1550#define SSL_SECOP_PEER_EE_KEY (SSL_SECOP_EE_KEY | SSL_SECOP_PEER)
1551/* Peer CA key in certificate */
1552#define SSL_SECOP_PEER_CA_KEY (SSL_SECOP_CA_KEY | SSL_SECOP_PEER)
1553/* Peer CA digest algorithm in certificate */
1554#define SSL_SECOP_PEER_CA_MD (SSL_SECOP_CA_MD | SSL_SECOP_PEER)
1555
1556void SSL_set_security_level(SSL *ssl, int level);
1557int SSL_get_security_level(const SSL *ssl);
1558
1559void SSL_CTX_set_security_level(SSL_CTX *ctx, int level);
1560int SSL_CTX_get_security_level(const SSL_CTX *ctx);
1561
1562#if defined(LIBRESSL_HAS_QUIC) || defined(LIBRESSL_INTERNAL)
1563/*
1564 * QUIC integration.
1565 *
1566 * QUIC acts as an underlying transport for the TLS 1.3 handshake. The following
1567 * functions allow a QUIC implementation to serve as the underlying transport as
1568 * described in RFC 9001.
1569 *
1570 * When configured for QUIC, |SSL_do_handshake| will drive the handshake as
1571 * before, but it will not use the configured |BIO|. It will call functions on
1572 * |SSL_QUIC_METHOD| to configure secrets and send data. If data is needed from
1573 * the peer, it will return |SSL_ERROR_WANT_READ|. As the caller receives data
1574 * it can decrypt, it calls |SSL_provide_quic_data|. Subsequent
1575 * |SSL_do_handshake| calls will then consume that data and progress the
1576 * handshake. After the handshake is complete, the caller should continue to
1577 * call |SSL_provide_quic_data| for any post-handshake data, followed by
1578 * |SSL_process_quic_post_handshake| to process it. It is an error to call
1579 * |SSL_peek|, |SSL_read| and |SSL_write| in QUIC.
1580 *
1581 * To avoid DoS attacks, the QUIC implementation must limit the amount of data
1582 * being queued up. The implementation can call
1583 * |SSL_quic_max_handshake_flight_len| to get the maximum buffer length at each
1584 * encryption level.
1585 *
1586 * QUIC implementations must additionally configure transport parameters with
1587 * |SSL_set_quic_transport_params|. |SSL_get_peer_quic_transport_params| may be
1588 * used to query the value received from the peer. This extension is handled
1589 * as an opaque byte string, which the caller is responsible for serializing
1590 * and parsing. See RFC 9000 section 7.4 for further details.
1591 */
1592
1593/*
1594 * ssl_encryption_level_t specifies the QUIC encryption level used to transmit
1595 * handshake messages.
1596 */
1597typedef enum ssl_encryption_level_t {
1598 ssl_encryption_initial = 0,
1599 ssl_encryption_early_data,
1600 ssl_encryption_handshake,
1601 ssl_encryption_application,
1602} OSSL_ENCRYPTION_LEVEL;
1603
1604/*
1605 * ssl_quic_method_st (aka |SSL_QUIC_METHOD|) describes custom QUIC hooks.
1606 *
1607 * Note that we provide both the new (BoringSSL) secrets interface
1608 * (set_read_secret/set_write_secret) along with the old interface
1609 * (set_encryption_secrets), which quictls is still using.
1610 *
1611 * Since some consumers fail to use named initialisers, the order of these
1612 * functions is important. Hopefully all of these consumers use the old version.
1613 */
1614struct ssl_quic_method_st {
1615 /*
1616 * set_encryption_secrets configures the read and write secrets for the
1617 * given encryption level. This function will always be called before an
1618 * encryption level other than |ssl_encryption_initial| is used.
1619 *
1620 * When reading packets at a given level, the QUIC implementation must
1621 * send ACKs at the same level, so this function provides read and write
1622 * secrets together. The exception is |ssl_encryption_early_data|, where
1623 * secrets are only available in the client to server direction. The
1624 * other secret will be NULL. The server acknowledges such data at
1625 * |ssl_encryption_application|, which will be configured in the same
1626 * |SSL_do_handshake| call.
1627 *
1628 * This function should use |SSL_get_current_cipher| to determine the TLS
1629 * cipher suite.
1630 */
1631 int (*set_encryption_secrets)(SSL *ssl, enum ssl_encryption_level_t level,
1632 const uint8_t *read_secret, const uint8_t *write_secret,
1633 size_t secret_len);
1634
1635 /*
1636 * add_handshake_data adds handshake data to the current flight at the
1637 * given encryption level. It returns one on success and zero on error.
1638 * Callers should defer writing data to the network until |flush_flight|
1639 * to better pack QUIC packets into transport datagrams.
1640 *
1641 * If |level| is not |ssl_encryption_initial|, this function will not be
1642 * called before |level| is initialized with |set_write_secret|.
1643 */
1644 int (*add_handshake_data)(SSL *ssl, enum ssl_encryption_level_t level,
1645 const uint8_t *data, size_t len);
1646
1647 /*
1648 * flush_flight is called when the current flight is complete and should
1649 * be written to the transport. Note a flight may contain data at
1650 * several encryption levels. It returns one on success and zero on
1651 * error.
1652 */
1653 int (*flush_flight)(SSL *ssl);
1654
1655 /*
1656 * send_alert sends a fatal alert at the specified encryption level. It
1657 * returns one on success and zero on error.
1658 *
1659 * If |level| is not |ssl_encryption_initial|, this function will not be
1660 * called before |level| is initialized with |set_write_secret|.
1661 */
1662 int (*send_alert)(SSL *ssl, enum ssl_encryption_level_t level,
1663 uint8_t alert);
1664
1665 /*
1666 * set_read_secret configures the read secret and cipher suite for the
1667 * given encryption level. It returns one on success and zero to
1668 * terminate the handshake with an error. It will be called at most once
1669 * per encryption level.
1670 *
1671 * Read keys will not be released before QUIC may use them. Once a level
1672 * has been initialized, QUIC may begin processing data from it.
1673 * Handshake data should be passed to |SSL_provide_quic_data| and
1674 * application data (if |level| is |ssl_encryption_early_data| or
1675 * |ssl_encryption_application|) may be processed according to the rules
1676 * of the QUIC protocol.
1677 */
1678 int (*set_read_secret)(SSL *ssl, enum ssl_encryption_level_t level,
1679 const SSL_CIPHER *cipher, const uint8_t *secret, size_t secret_len);
1680
1681 /*
1682 * set_write_secret behaves like |set_read_secret| but configures the
1683 * write secret and cipher suite for the given encryption level. It will
1684 * be called at most once per encryption level.
1685 *
1686 * Write keys will not be released before QUIC may use them. If |level|
1687 * is |ssl_encryption_early_data| or |ssl_encryption_application|, QUIC
1688 * may begin sending application data at |level|.
1689 */
1690 int (*set_write_secret)(SSL *ssl, enum ssl_encryption_level_t level,
1691 const SSL_CIPHER *cipher, const uint8_t *secret, size_t secret_len);
1692};
1693
1694/*
1695 * SSL_CTX_set_quic_method configures the QUIC hooks. This should only be
1696 * configured with a minimum version of TLS 1.3. |quic_method| must remain valid
1697 * for the lifetime of |ctx|. It returns one on success and zero on error.
1698 */
1699int SSL_CTX_set_quic_method(SSL_CTX *ctx, const SSL_QUIC_METHOD *quic_method);
1700
1701/*
1702 * SSL_set_quic_method configures the QUIC hooks. This should only be
1703 * configured with a minimum version of TLS 1.3. |quic_method| must remain valid
1704 * for the lifetime of |ssl|. It returns one on success and zero on error.
1705 */
1706int SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method);
1707
1708/* SSL_is_quic returns true if an SSL has been configured for use with QUIC. */
1709int SSL_is_quic(const SSL *ssl);
1710
1711/*
1712 * SSL_quic_max_handshake_flight_len returns returns the maximum number of bytes
1713 * that may be received at the given encryption level. This function should be
1714 * used to limit buffering in the QUIC implementation. See RFC 9000 section 7.5.
1715 */
1716size_t SSL_quic_max_handshake_flight_len(const SSL *ssl,
1717 enum ssl_encryption_level_t level);
1718
1719/*
1720 * SSL_quic_read_level returns the current read encryption level.
1721 */
1722enum ssl_encryption_level_t SSL_quic_read_level(const SSL *ssl);
1723
1724/*
1725 * SSL_quic_write_level returns the current write encryption level.
1726 */
1727enum ssl_encryption_level_t SSL_quic_write_level(const SSL *ssl);
1728
1729/*
1730 * SSL_provide_quic_data provides data from QUIC at a particular encryption
1731 * level |level|. It returns one on success and zero on error. Note this
1732 * function will return zero if the handshake is not expecting data from |level|
1733 * at this time. The QUIC implementation should then close the connection with
1734 * an error.
1735 */
1736int SSL_provide_quic_data(SSL *ssl, enum ssl_encryption_level_t level,
1737 const uint8_t *data, size_t len);
1738
1739/*
1740 * SSL_process_quic_post_handshake processes any data that QUIC has provided
1741 * after the handshake has completed. This includes NewSessionTicket messages
1742 * sent by the server. It returns one on success and zero on error.
1743 */
1744int SSL_process_quic_post_handshake(SSL *ssl);
1745
1746/*
1747 * SSL_set_quic_transport_params configures |ssl| to send |params| (of length
1748 * |params_len|) in the quic_transport_parameters extension in either the
1749 * ClientHello or EncryptedExtensions handshake message. It is an error to set
1750 * transport parameters if |ssl| is not configured for QUIC. The buffer pointed
1751 * to by |params| only need be valid for the duration of the call to this
1752 * function. This function returns 1 on success and 0 on failure.
1753 */
1754int SSL_set_quic_transport_params(SSL *ssl, const uint8_t *params,
1755 size_t params_len);
1756
1757/*
1758 * SSL_get_peer_quic_transport_params provides the caller with the value of the
1759 * quic_transport_parameters extension sent by the peer. A pointer to the buffer
1760 * containing the TransportParameters will be put in |*out_params|, and its
1761 * length in |*params_len|. This buffer will be valid for the lifetime of the
1762 * |SSL|. If no params were received from the peer, |*out_params_len| will be 0.
1763 */
1764void SSL_get_peer_quic_transport_params(const SSL *ssl,
1765 const uint8_t **out_params, size_t *out_params_len);
1766
1767/*
1768 * SSL_set_quic_use_legacy_codepoint configures whether to use the legacy QUIC
1769 * extension codepoint 0xffa5 as opposed to the official value 57. This is
1770 * unsupported in LibreSSL.
1771 */
1772void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);
1773
1774#endif
1775
1776void ERR_load_SSL_strings(void);
1777
1778/* Error codes for the SSL functions. */
1779
1780/* Function codes. */
1781#define SSL_F_CLIENT_CERTIFICATE 100
1782#define SSL_F_CLIENT_FINISHED 167
1783#define SSL_F_CLIENT_HELLO 101
1784#define SSL_F_CLIENT_MASTER_KEY 102
1785#define SSL_F_D2I_SSL_SESSION 103
1786#define SSL_F_DO_DTLS1_WRITE 245
1787#define SSL_F_DO_SSL3_WRITE 104
1788#define SSL_F_DTLS1_ACCEPT 246
1789#define SSL_F_DTLS1_ADD_CERT_TO_BUF 295
1790#define SSL_F_DTLS1_BUFFER_RECORD 247
1791#define SSL_F_DTLS1_CHECK_TIMEOUT_NUM 316
1792#define SSL_F_DTLS1_CLIENT_HELLO 248
1793#define SSL_F_DTLS1_CONNECT 249
1794#define SSL_F_DTLS1_ENC 250
1795#define SSL_F_DTLS1_GET_HELLO_VERIFY 251
1796#define SSL_F_DTLS1_GET_MESSAGE 252
1797#define SSL_F_DTLS1_GET_MESSAGE_FRAGMENT 253
1798#define SSL_F_DTLS1_GET_RECORD 254
1799#define SSL_F_DTLS1_HANDLE_TIMEOUT 297
1800#define SSL_F_DTLS1_HEARTBEAT 305
1801#define SSL_F_DTLS1_OUTPUT_CERT_CHAIN 255
1802#define SSL_F_DTLS1_PREPROCESS_FRAGMENT 288
1803#define SSL_F_DTLS1_PROCESS_OUT_OF_SEQ_MESSAGE 256
1804#define SSL_F_DTLS1_PROCESS_RECORD 257
1805#define SSL_F_DTLS1_READ_BYTES 258
1806#define SSL_F_DTLS1_READ_FAILED 259
1807#define SSL_F_DTLS1_SEND_CERTIFICATE_REQUEST 260
1808#define SSL_F_DTLS1_SEND_CLIENT_CERTIFICATE 261
1809#define SSL_F_DTLS1_SEND_CLIENT_KEY_EXCHANGE 262
1810#define SSL_F_DTLS1_SEND_CLIENT_VERIFY 263
1811#define SSL_F_DTLS1_SEND_HELLO_VERIFY_REQUEST 264
1812#define SSL_F_DTLS1_SEND_SERVER_CERTIFICATE 265
1813#define SSL_F_DTLS1_SEND_SERVER_HELLO 266
1814#define SSL_F_DTLS1_SEND_SERVER_KEY_EXCHANGE 267
1815#define SSL_F_DTLS1_WRITE_APP_DATA_BYTES 268
1816#define SSL_F_GET_CLIENT_FINISHED 105
1817#define SSL_F_GET_CLIENT_HELLO 106
1818#define SSL_F_GET_CLIENT_MASTER_KEY 107
1819#define SSL_F_GET_SERVER_FINISHED 108
1820#define SSL_F_GET_SERVER_HELLO 109
1821#define SSL_F_GET_SERVER_VERIFY 110
1822#define SSL_F_I2D_SSL_SESSION 111
1823#define SSL_F_READ_N 112
1824#define SSL_F_REQUEST_CERTIFICATE 113
1825#define SSL_F_SERVER_FINISH 239
1826#define SSL_F_SERVER_HELLO 114
1827#define SSL_F_SERVER_VERIFY 240
1828#define SSL_F_SSL23_ACCEPT 115
1829#define SSL_F_SSL23_CLIENT_HELLO 116
1830#define SSL_F_SSL23_CONNECT 117
1831#define SSL_F_SSL23_GET_CLIENT_HELLO 118
1832#define SSL_F_SSL23_GET_SERVER_HELLO 119
1833#define SSL_F_SSL23_PEEK 237
1834#define SSL_F_SSL23_READ 120
1835#define SSL_F_SSL23_WRITE 121
1836#define SSL_F_SSL2_ACCEPT 122
1837#define SSL_F_SSL2_CONNECT 123
1838#define SSL_F_SSL2_ENC_INIT 124
1839#define SSL_F_SSL2_GENERATE_KEY_MATERIAL 241
1840#define SSL_F_SSL2_PEEK 234
1841#define SSL_F_SSL2_READ 125
1842#define SSL_F_SSL2_READ_INTERNAL 236
1843#define SSL_F_SSL2_SET_CERTIFICATE 126
1844#define SSL_F_SSL2_WRITE 127
1845#define SSL_F_SSL3_ACCEPT 128
1846#define SSL_F_SSL3_ADD_CERT_TO_BUF 296
1847#define SSL_F_SSL3_CALLBACK_CTRL 233
1848#define SSL_F_SSL3_CHANGE_CIPHER_STATE 129
1849#define SSL_F_SSL3_CHECK_CERT_AND_ALGORITHM 130
1850#define SSL_F_SSL3_CHECK_CLIENT_HELLO 304
1851#define SSL_F_SSL3_CLIENT_HELLO 131
1852#define SSL_F_SSL3_CONNECT 132
1853#define SSL_F_SSL3_CTRL 213
1854#define SSL_F_SSL3_CTX_CTRL 133
1855#define SSL_F_SSL3_DIGEST_CACHED_RECORDS 293
1856#define SSL_F_SSL3_DO_CHANGE_CIPHER_SPEC 292
1857#define SSL_F_SSL3_ENC 134
1858#define SSL_F_SSL3_GENERATE_KEY_BLOCK 238
1859#define SSL_F_SSL3_GET_CERTIFICATE_REQUEST 135
1860#define SSL_F_SSL3_GET_CERT_STATUS 289
1861#define SSL_F_SSL3_GET_CERT_VERIFY 136
1862#define SSL_F_SSL3_GET_CLIENT_CERTIFICATE 137
1863#define SSL_F_SSL3_GET_CLIENT_HELLO 138
1864#define SSL_F_SSL3_GET_CLIENT_KEY_EXCHANGE 139
1865#define SSL_F_SSL3_GET_FINISHED 140
1866#define SSL_F_SSL3_GET_KEY_EXCHANGE 141
1867#define SSL_F_SSL3_GET_MESSAGE 142
1868#define SSL_F_SSL3_GET_NEW_SESSION_TICKET 283
1869#define SSL_F_SSL3_GET_NEXT_PROTO 306
1870#define SSL_F_SSL3_GET_RECORD 143
1871#define SSL_F_SSL3_GET_SERVER_CERTIFICATE 144
1872#define SSL_F_SSL3_GET_SERVER_DONE 145
1873#define SSL_F_SSL3_GET_SERVER_HELLO 146
1874#define SSL_F_SSL3_HANDSHAKE_MAC 285
1875#define SSL_F_SSL3_NEW_SESSION_TICKET 287
1876#define SSL_F_SSL3_OUTPUT_CERT_CHAIN 147
1877#define SSL_F_SSL3_PEEK 235
1878#define SSL_F_SSL3_READ_BYTES 148
1879#define SSL_F_SSL3_READ_N 149
1880#define SSL_F_SSL3_SEND_CERTIFICATE_REQUEST 150
1881#define SSL_F_SSL3_SEND_CLIENT_CERTIFICATE 151
1882#define SSL_F_SSL3_SEND_CLIENT_KEY_EXCHANGE 152
1883#define SSL_F_SSL3_SEND_CLIENT_VERIFY 153
1884#define SSL_F_SSL3_SEND_SERVER_CERTIFICATE 154
1885#define SSL_F_SSL3_SEND_SERVER_HELLO 242
1886#define SSL_F_SSL3_SEND_SERVER_KEY_EXCHANGE 155
1887#define SSL_F_SSL3_SETUP_KEY_BLOCK 157
1888#define SSL_F_SSL3_SETUP_READ_BUFFER 156
1889#define SSL_F_SSL3_SETUP_WRITE_BUFFER 291
1890#define SSL_F_SSL3_WRITE_BYTES 158
1891#define SSL_F_SSL3_WRITE_PENDING 159
1892#define SSL_F_SSL_ADD_CLIENTHELLO_RENEGOTIATE_EXT 298
1893#define SSL_F_SSL_ADD_CLIENTHELLO_TLSEXT 277
1894#define SSL_F_SSL_ADD_CLIENTHELLO_USE_SRTP_EXT 307
1895#define SSL_F_SSL_ADD_DIR_CERT_SUBJECTS_TO_STACK 215
1896#define SSL_F_SSL_ADD_FILE_CERT_SUBJECTS_TO_STACK 216
1897#define SSL_F_SSL_ADD_SERVERHELLO_RENEGOTIATE_EXT 299
1898#define SSL_F_SSL_ADD_SERVERHELLO_TLSEXT 278
1899#define SSL_F_SSL_ADD_SERVERHELLO_USE_SRTP_EXT 308
1900#define SSL_F_SSL_BAD_METHOD 160
1901#define SSL_F_SSL_BYTES_TO_CIPHER_LIST 161
1902#define SSL_F_SSL_CERT_DUP 221
1903#define SSL_F_SSL_CERT_INST 222
1904#define SSL_F_SSL_CERT_INSTANTIATE 214
1905#define SSL_F_SSL_CERT_NEW 162
1906#define SSL_F_SSL_CHECK_PRIVATE_KEY 163
1907#define SSL_F_SSL_CHECK_SERVERHELLO_TLSEXT 280
1908#define SSL_F_SSL_CHECK_SRVR_ECC_CERT_AND_ALG 279
1909#define SSL_F_SSL_CIPHER_PROCESS_RULESTR 230
1910#define SSL_F_SSL_CIPHER_STRENGTH_SORT 231
1911#define SSL_F_SSL_CLEAR 164
1912#define SSL_F_SSL_COMP_ADD_COMPRESSION_METHOD 165
1913#define SSL_F_SSL_CREATE_CIPHER_LIST 166
1914#define SSL_F_SSL_CTRL 232
1915#define SSL_F_SSL_CTX_CHECK_PRIVATE_KEY 168
1916#define SSL_F_SSL_CTX_MAKE_PROFILES 309
1917#define SSL_F_SSL_CTX_NEW 169
1918#define SSL_F_SSL_CTX_SET_CIPHER_LIST 269
1919#define SSL_F_SSL_CTX_SET_CLIENT_CERT_ENGINE 290
1920#define SSL_F_SSL_CTX_SET_PURPOSE 226
1921#define SSL_F_SSL_CTX_SET_SESSION_ID_CONTEXT 219
1922#define SSL_F_SSL_CTX_SET_SSL_VERSION 170
1923#define SSL_F_SSL_CTX_SET_TRUST 229
1924#define SSL_F_SSL_CTX_USE_CERTIFICATE 171
1925#define SSL_F_SSL_CTX_USE_CERTIFICATE_ASN1 172
1926#define SSL_F_SSL_CTX_USE_CERTIFICATE_CHAIN_FILE 220
1927#define SSL_F_SSL_CTX_USE_CERTIFICATE_FILE 173
1928#define SSL_F_SSL_CTX_USE_PRIVATEKEY 174
1929#define SSL_F_SSL_CTX_USE_PRIVATEKEY_ASN1 175
1930#define SSL_F_SSL_CTX_USE_PRIVATEKEY_FILE 176
1931#define SSL_F_SSL_CTX_USE_PSK_IDENTITY_HINT 272
1932#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY 177
1933#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_ASN1 178
1934#define SSL_F_SSL_CTX_USE_RSAPRIVATEKEY_FILE 179
1935#define SSL_F_SSL_DO_HANDSHAKE 180
1936#define SSL_F_SSL_GET_NEW_SESSION 181
1937#define SSL_F_SSL_GET_PREV_SESSION 217
1938#define SSL_F_SSL_GET_SERVER_SEND_CERT 182
1939#define SSL_F_SSL_GET_SERVER_SEND_PKEY 317
1940#define SSL_F_SSL_GET_SIGN_PKEY 183
1941#define SSL_F_SSL_INIT_WBIO_BUFFER 184
1942#define SSL_F_SSL_LOAD_CLIENT_CA_FILE 185
1943#define SSL_F_SSL_NEW 186
1944#define SSL_F_SSL_PARSE_CLIENTHELLO_RENEGOTIATE_EXT 300
1945#define SSL_F_SSL_PARSE_CLIENTHELLO_TLSEXT 302
1946#define SSL_F_SSL_PARSE_CLIENTHELLO_USE_SRTP_EXT 310
1947#define SSL_F_SSL_PARSE_SERVERHELLO_RENEGOTIATE_EXT 301
1948#define SSL_F_SSL_PARSE_SERVERHELLO_TLSEXT 303
1949#define SSL_F_SSL_PARSE_SERVERHELLO_USE_SRTP_EXT 311
1950#define SSL_F_SSL_PEEK 270
1951#define SSL_F_SSL_PREPARE_CLIENTHELLO_TLSEXT 281
1952#define SSL_F_SSL_PREPARE_SERVERHELLO_TLSEXT 282
1953#define SSL_F_SSL_READ 223
1954#define SSL_F_SSL_RSA_PRIVATE_DECRYPT 187
1955#define SSL_F_SSL_RSA_PUBLIC_ENCRYPT 188
1956#define SSL_F_SSL_SESSION_NEW 189
1957#define SSL_F_SSL_SESSION_PRINT_FP 190
1958#define SSL_F_SSL_SESSION_SET1_ID_CONTEXT 312
1959#define SSL_F_SSL_SESS_CERT_NEW 225
1960#define SSL_F_SSL_SET_CERT 191
1961#define SSL_F_SSL_SET_CIPHER_LIST 271
1962#define SSL_F_SSL_SET_FD 192
1963#define SSL_F_SSL_SET_PKEY 193
1964#define SSL_F_SSL_SET_PURPOSE 227
1965#define SSL_F_SSL_SET_RFD 194
1966#define SSL_F_SSL_SET_SESSION 195
1967#define SSL_F_SSL_SET_SESSION_ID_CONTEXT 218
1968#define SSL_F_SSL_SET_SESSION_TICKET_EXT 294
1969#define SSL_F_SSL_SET_TRUST 228
1970#define SSL_F_SSL_SET_WFD 196
1971#define SSL_F_SSL_SHUTDOWN 224
1972#define SSL_F_SSL_SRP_CTX_INIT 313
1973#define SSL_F_SSL_UNDEFINED_CONST_FUNCTION 243
1974#define SSL_F_SSL_UNDEFINED_FUNCTION 197
1975#define SSL_F_SSL_UNDEFINED_VOID_FUNCTION 244
1976#define SSL_F_SSL_USE_CERTIFICATE 198
1977#define SSL_F_SSL_USE_CERTIFICATE_ASN1 199
1978#define SSL_F_SSL_USE_CERTIFICATE_FILE 200
1979#define SSL_F_SSL_USE_PRIVATEKEY 201
1980#define SSL_F_SSL_USE_PRIVATEKEY_ASN1 202
1981#define SSL_F_SSL_USE_PRIVATEKEY_FILE 203
1982#define SSL_F_SSL_USE_PSK_IDENTITY_HINT 273
1983#define SSL_F_SSL_USE_RSAPRIVATEKEY 204
1984#define SSL_F_SSL_USE_RSAPRIVATEKEY_ASN1 205
1985#define SSL_F_SSL_USE_RSAPRIVATEKEY_FILE 206
1986#define SSL_F_SSL_VERIFY_CERT_CHAIN 207
1987#define SSL_F_SSL_WRITE 208
1988#define SSL_F_TLS1_AEAD_CTX_INIT 339
1989#define SSL_F_TLS1_CERT_VERIFY_MAC 286
1990#define SSL_F_TLS1_CHANGE_CIPHER_STATE 209
1991#define SSL_F_TLS1_CHANGE_CIPHER_STATE_AEAD 340
1992#define SSL_F_TLS1_CHANGE_CIPHER_STATE_CIPHER 338
1993#define SSL_F_TLS1_CHECK_SERVERHELLO_TLSEXT 274
1994#define SSL_F_TLS1_ENC 210
1995#define SSL_F_TLS1_EXPORT_KEYING_MATERIAL 314
1996#define SSL_F_TLS1_HEARTBEAT 315
1997#define SSL_F_TLS1_PREPARE_CLIENTHELLO_TLSEXT 275
1998#define SSL_F_TLS1_PREPARE_SERVERHELLO_TLSEXT 276
1999#define SSL_F_TLS1_PRF 284
2000#define SSL_F_TLS1_SETUP_KEY_BLOCK 211
2001#define SSL_F_WRITE_PENDING 212
2002
2003/* Reason codes. */
2004#define SSL_R_APP_DATA_IN_HANDSHAKE 100
2005#define SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT 272
2006#define SSL_R_BAD_ALERT_RECORD 101
2007#define SSL_R_BAD_AUTHENTICATION_TYPE 102
2008#define SSL_R_BAD_CHANGE_CIPHER_SPEC 103
2009#define SSL_R_BAD_CHECKSUM 104
2010#define SSL_R_BAD_DATA_RETURNED_BY_CALLBACK 106
2011#define SSL_R_BAD_DECOMPRESSION 107
2012#define SSL_R_BAD_DH_G_LENGTH 108
2013#define SSL_R_BAD_DH_PUB_KEY_LENGTH 109
2014#define SSL_R_BAD_DH_P_LENGTH 110
2015#define SSL_R_BAD_DIGEST_LENGTH 111
2016#define SSL_R_BAD_DSA_SIGNATURE 112
2017#define SSL_R_BAD_ECC_CERT 304
2018#define SSL_R_BAD_ECDSA_SIGNATURE 305
2019#define SSL_R_BAD_ECPOINT 306
2020#define SSL_R_BAD_HANDSHAKE_LENGTH 332
2021#define SSL_R_BAD_HELLO_REQUEST 105
2022#define SSL_R_BAD_LENGTH 271
2023#define SSL_R_BAD_MAC_DECODE 113
2024#define SSL_R_BAD_MAC_LENGTH 333
2025#define SSL_R_BAD_MESSAGE_TYPE 114
2026#define SSL_R_BAD_PACKET_LENGTH 115
2027#define SSL_R_BAD_PROTOCOL_VERSION_NUMBER 116
2028#define SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH 316
2029#define SSL_R_BAD_RESPONSE_ARGUMENT 117
2030#define SSL_R_BAD_RSA_DECRYPT 118
2031#define SSL_R_BAD_RSA_ENCRYPT 119
2032#define SSL_R_BAD_RSA_E_LENGTH 120
2033#define SSL_R_BAD_RSA_MODULUS_LENGTH 121
2034#define SSL_R_BAD_RSA_SIGNATURE 122
2035#define SSL_R_BAD_SIGNATURE 123
2036#define SSL_R_BAD_SRP_A_LENGTH 347
2037#define SSL_R_BAD_SRP_B_LENGTH 348
2038#define SSL_R_BAD_SRP_G_LENGTH 349
2039#define SSL_R_BAD_SRP_N_LENGTH 350
2040#define SSL_R_BAD_SRP_S_LENGTH 351
2041#define SSL_R_BAD_SRTP_MKI_VALUE 352
2042#define SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST 353
2043#define SSL_R_BAD_SSL_FILETYPE 124
2044#define SSL_R_BAD_SSL_SESSION_ID_LENGTH 125
2045#define SSL_R_BAD_STATE 126
2046#define SSL_R_BAD_WRITE_RETRY 127
2047#define SSL_R_BIO_NOT_SET 128
2048#define SSL_R_BLOCK_CIPHER_PAD_IS_WRONG 129
2049#define SSL_R_BN_LIB 130
2050#define SSL_R_CA_DN_LENGTH_MISMATCH 131
2051#define SSL_R_CA_DN_TOO_LONG 132
2052#define SSL_R_CA_KEY_TOO_SMALL 397
2053#define SSL_R_CA_MD_TOO_WEAK 398
2054#define SSL_R_CCS_RECEIVED_EARLY 133
2055#define SSL_R_CERTIFICATE_VERIFY_FAILED 134
2056#define SSL_R_CERT_LENGTH_MISMATCH 135
2057#define SSL_R_CHALLENGE_IS_DIFFERENT 136
2058#define SSL_R_CIPHER_CODE_WRONG_LENGTH 137
2059#define SSL_R_CIPHER_COMPRESSION_UNAVAILABLE 371
2060#define SSL_R_CIPHER_OR_HASH_UNAVAILABLE 138
2061#define SSL_R_CIPHER_TABLE_SRC_ERROR 139
2062#define SSL_R_CLIENTHELLO_TLSEXT 226
2063#define SSL_R_COMPRESSED_LENGTH_TOO_LONG 140
2064#define SSL_R_COMPRESSION_DISABLED 343
2065#define SSL_R_COMPRESSION_FAILURE 141
2066#define SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE 307
2067#define SSL_R_COMPRESSION_LIBRARY_ERROR 142
2068#define SSL_R_CONNECTION_ID_IS_DIFFERENT 143
2069#define SSL_R_CONNECTION_TYPE_NOT_SET 144
2070#define SSL_R_COOKIE_MISMATCH 308
2071#define SSL_R_DATA_BETWEEN_CCS_AND_FINISHED 145
2072#define SSL_R_DATA_LENGTH_TOO_LONG 146
2073#define SSL_R_DECRYPTION_FAILED 147
2074#define SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC 281
2075#define SSL_R_DH_KEY_TOO_SMALL 394
2076#define SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG 148
2077#define SSL_R_DIGEST_CHECK_FAILED 149
2078#define SSL_R_DTLS_MESSAGE_TOO_BIG 334
2079#define SSL_R_DUPLICATE_COMPRESSION_ID 309
2080#define SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT 317
2081#define SSL_R_ECC_CERT_NOT_FOR_SIGNING 318
2082#define SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE 322
2083#define SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE 323
2084#define SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER 310
2085#define SSL_R_EE_KEY_TOO_SMALL 399
2086#define SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST 354
2087#define SSL_R_ENCRYPTED_LENGTH_TOO_LONG 150
2088#define SSL_R_ERROR_GENERATING_TMP_RSA_KEY 282
2089#define SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST 151
2090#define SSL_R_EXCESSIVE_MESSAGE_SIZE 152
2091#define SSL_R_EXTRA_DATA_IN_MESSAGE 153
2092#define SSL_R_GOT_A_FIN_BEFORE_A_CCS 154
2093#define SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS 355
2094#define SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION 356
2095#define SSL_R_HTTPS_PROXY_REQUEST 155
2096#define SSL_R_HTTP_REQUEST 156
2097#define SSL_R_ILLEGAL_PADDING 283
2098#define SSL_R_INAPPROPRIATE_FALLBACK 373
2099#define SSL_R_INCONSISTENT_COMPRESSION 340
2100#define SSL_R_INVALID_CHALLENGE_LENGTH 158
2101#define SSL_R_INVALID_COMMAND 280
2102#define SSL_R_INVALID_COMPRESSION_ALGORITHM 341
2103#define SSL_R_INVALID_PURPOSE 278
2104#define SSL_R_INVALID_SRP_USERNAME 357
2105#define SSL_R_INVALID_STATUS_RESPONSE 328
2106#define SSL_R_INVALID_TICKET_KEYS_LENGTH 325
2107#define SSL_R_INVALID_TRUST 279
2108#define SSL_R_KEY_ARG_TOO_LONG 284
2109#define SSL_R_KRB5 285
2110#define SSL_R_KRB5_C_CC_PRINC 286
2111#define SSL_R_KRB5_C_GET_CRED 287
2112#define SSL_R_KRB5_C_INIT 288
2113#define SSL_R_KRB5_C_MK_REQ 289
2114#define SSL_R_KRB5_S_BAD_TICKET 290
2115#define SSL_R_KRB5_S_INIT 291
2116#define SSL_R_KRB5_S_RD_REQ 292
2117#define SSL_R_KRB5_S_TKT_EXPIRED 293
2118#define SSL_R_KRB5_S_TKT_NYV 294
2119#define SSL_R_KRB5_S_TKT_SKEW 295
2120#define SSL_R_LENGTH_MISMATCH 159
2121#define SSL_R_LENGTH_TOO_SHORT 160
2122#define SSL_R_LIBRARY_BUG 274
2123#define SSL_R_LIBRARY_HAS_NO_CIPHERS 161
2124#define SSL_R_MESSAGE_TOO_LONG 296
2125#define SSL_R_MISSING_DH_DSA_CERT 162
2126#define SSL_R_MISSING_DH_KEY 163
2127#define SSL_R_MISSING_DH_RSA_CERT 164
2128#define SSL_R_MISSING_DSA_SIGNING_CERT 165
2129#define SSL_R_MISSING_EXPORT_TMP_DH_KEY 166
2130#define SSL_R_MISSING_EXPORT_TMP_RSA_KEY 167
2131#define SSL_R_MISSING_RSA_CERTIFICATE 168
2132#define SSL_R_MISSING_RSA_ENCRYPTING_CERT 169
2133#define SSL_R_MISSING_RSA_SIGNING_CERT 170
2134#define SSL_R_MISSING_SRP_PARAM 358
2135#define SSL_R_MISSING_TMP_DH_KEY 171
2136#define SSL_R_MISSING_TMP_ECDH_KEY 311
2137#define SSL_R_MISSING_TMP_RSA_KEY 172
2138#define SSL_R_MISSING_TMP_RSA_PKEY 173
2139#define SSL_R_MISSING_VERIFY_MESSAGE 174
2140#define SSL_R_MULTIPLE_SGC_RESTARTS 346
2141#define SSL_R_NON_SSLV2_INITIAL_PACKET 175
2142#define SSL_R_NO_APPLICATION_PROTOCOL 235
2143#define SSL_R_NO_CERTIFICATES_RETURNED 176
2144#define SSL_R_NO_CERTIFICATE_ASSIGNED 177
2145#define SSL_R_NO_CERTIFICATE_RETURNED 178
2146#define SSL_R_NO_CERTIFICATE_SET 179
2147#define SSL_R_NO_CERTIFICATE_SPECIFIED 180
2148#define SSL_R_NO_CIPHERS_AVAILABLE 181
2149#define SSL_R_NO_CIPHERS_PASSED 182
2150#define SSL_R_NO_CIPHERS_SPECIFIED 183
2151#define SSL_R_NO_CIPHER_LIST 184
2152#define SSL_R_NO_CIPHER_MATCH 185
2153#define SSL_R_NO_CLIENT_CERT_METHOD 331
2154#define SSL_R_NO_CLIENT_CERT_RECEIVED 186
2155#define SSL_R_NO_COMPRESSION_SPECIFIED 187
2156#define SSL_R_NO_METHOD_SPECIFIED 188
2157#define SSL_R_NO_PRIVATEKEY 189
2158#define SSL_R_NO_PRIVATE_KEY_ASSIGNED 190
2159#define SSL_R_NO_PROTOCOLS_AVAILABLE 191
2160#define SSL_R_NO_PUBLICKEY 192
2161#define SSL_R_NO_RENEGOTIATION 339
2162#define SSL_R_NO_REQUIRED_DIGEST 324
2163#define SSL_R_NO_SHARED_CIPHER 193
2164#define SSL_R_NO_SRTP_PROFILES 359
2165#define SSL_R_NO_VERIFY_CALLBACK 194
2166#define SSL_R_NULL_SSL_CTX 195
2167#define SSL_R_NULL_SSL_METHOD_PASSED 196
2168#define SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED 197
2169#define SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED 344
2170#define SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE 297
2171#define SSL_R_PACKET_LENGTH_TOO_LONG 198
2172#define SSL_R_PARSE_TLSEXT 227
2173#define SSL_R_PATH_TOO_LONG 270
2174#define SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE 199
2175#define SSL_R_PEER_ERROR 200
2176#define SSL_R_PEER_ERROR_CERTIFICATE 201
2177#define SSL_R_PEER_ERROR_NO_CERTIFICATE 202
2178#define SSL_R_PEER_ERROR_NO_CIPHER 203
2179#define SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE 204
2180#define SSL_R_PRE_MAC_LENGTH_TOO_LONG 205
2181#define SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS 206
2182#define SSL_R_PROTOCOL_IS_SHUTDOWN 207
2183#define SSL_R_PSK_IDENTITY_NOT_FOUND 223
2184#define SSL_R_PSK_NO_CLIENT_CB 224
2185#define SSL_R_PSK_NO_SERVER_CB 225
2186#define SSL_R_PUBLIC_KEY_ENCRYPT_ERROR 208
2187#define SSL_R_PUBLIC_KEY_IS_NOT_RSA 209
2188#define SSL_R_PUBLIC_KEY_NOT_RSA 210
2189#define SSL_R_READ_BIO_NOT_SET 211
2190#define SSL_R_READ_TIMEOUT_EXPIRED 312
2191#define SSL_R_READ_WRONG_PACKET_TYPE 212
2192#define SSL_R_RECORD_LENGTH_MISMATCH 213
2193#define SSL_R_RECORD_TOO_LARGE 214
2194#define SSL_R_RECORD_TOO_SMALL 298
2195#define SSL_R_RENEGOTIATE_EXT_TOO_LONG 335
2196#define SSL_R_RENEGOTIATION_ENCODING_ERR 336
2197#define SSL_R_RENEGOTIATION_MISMATCH 337
2198#define SSL_R_REQUIRED_CIPHER_MISSING 215
2199#define SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING 342
2200#define SSL_R_REUSE_CERT_LENGTH_NOT_ZERO 216
2201#define SSL_R_REUSE_CERT_TYPE_NOT_ZERO 217
2202#define SSL_R_REUSE_CIPHER_LIST_NOT_ZERO 218
2203#define SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING 345
2204#define SSL_R_SERVERHELLO_TLSEXT 275
2205#define SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED 277
2206#define SSL_R_SHORT_READ 219
2207#define SSL_R_SIGNATURE_ALGORITHMS_ERROR 360
2208#define SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE 220
2209#define SSL_R_SRP_A_CALC 361
2210#define SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES 362
2211#define SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG 363
2212#define SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE 364
2213#define SSL_R_SSL23_DOING_SESSION_ID_REUSE 221
2214#define SSL_R_SSL2_CONNECTION_ID_TOO_LONG 299
2215#define SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT 321
2216#define SSL_R_SSL3_EXT_INVALID_SERVERNAME 319
2217#define SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE 320
2218#define SSL_R_SSL3_SESSION_ID_TOO_LONG 300
2219#define SSL_R_SSL3_SESSION_ID_TOO_SHORT 222
2220#define SSL_R_SSLV3_ALERT_BAD_CERTIFICATE 1042
2221#define SSL_R_SSLV3_ALERT_BAD_RECORD_MAC 1020
2222#define SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED 1045
2223#define SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED 1044
2224#define SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN 1046
2225#define SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE 1030
2226#define SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE 1040
2227#define SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER 1047
2228#define SSL_R_SSLV3_ALERT_NO_CERTIFICATE 1041
2229#define SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE 1010
2230#define SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE 1043
2231#define SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION 228
2232#define SSL_R_SSL_HANDSHAKE_FAILURE 229
2233#define SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS 230
2234#define SSL_R_SSL_SESSION_ID_CALLBACK_FAILED 301
2235#define SSL_R_SSL_SESSION_ID_CONFLICT 302
2236#define SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG 273
2237#define SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH 303
2238#define SSL_R_SSL_SESSION_ID_IS_DIFFERENT 231
2239#define SSL_R_SSL_SESSION_ID_TOO_LONG 408
2240#define SSL_R_TLSV13_ALERT_MISSING_EXTENSION 1109
2241#define SSL_R_TLSV13_ALERT_CERTIFICATE_REQUIRED 1116
2242#define SSL_R_TLSV1_ALERT_ACCESS_DENIED 1049
2243#define SSL_R_TLSV1_ALERT_NO_APPLICATION_PROTOCOL 1120
2244#define SSL_R_TLSV1_ALERT_DECODE_ERROR 1050
2245#define SSL_R_TLSV1_ALERT_DECRYPTION_FAILED 1021
2246#define SSL_R_TLSV1_ALERT_DECRYPT_ERROR 1051
2247#define SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION 1060
2248#define SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK 1086
2249#define SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY 1071
2250#define SSL_R_TLSV1_ALERT_INTERNAL_ERROR 1080
2251#define SSL_R_TLSV1_ALERT_NO_RENEGOTIATION 1100
2252#define SSL_R_TLSV1_ALERT_PROTOCOL_VERSION 1070
2253#define SSL_R_TLSV1_ALERT_RECORD_OVERFLOW 1022
2254#define SSL_R_TLSV1_ALERT_UNKNOWN_CA 1048
2255#define SSL_R_TLSV1_ALERT_UNKNOWN_PSK_IDENTITY 1115
2256#define SSL_R_TLSV1_ALERT_USER_CANCELLED 1090
2257#define SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE 1114
2258#define SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE 1113
2259#define SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE 1111
2260#define SSL_R_TLSV1_UNRECOGNIZED_NAME 1112
2261#define SSL_R_TLSV1_UNSUPPORTED_EXTENSION 1110
2262#define SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER 232
2263#define SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT 365
2264#define SSL_R_TLS_HEARTBEAT_PENDING 366
2265#define SSL_R_TLS_ILLEGAL_EXPORTER_LABEL 367
2266#define SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST 157
2267#define SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST 233
2268#define SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG 234
2269#define SSL_R_UNABLE_TO_DECODE_DH_CERTS 236
2270#define SSL_R_UNABLE_TO_DECODE_ECDH_CERTS 313
2271#define SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY 237
2272#define SSL_R_UNABLE_TO_FIND_DH_PARAMETERS 238
2273#define SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS 314
2274#define SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS 239
2275#define SSL_R_UNABLE_TO_FIND_SSL_METHOD 240
2276#define SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES 241
2277#define SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES 242
2278#define SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES 243
2279#define SSL_R_UNEXPECTED_MESSAGE 244
2280#define SSL_R_UNEXPECTED_RECORD 245
2281#define SSL_R_UNINITIALIZED 276
2282#define SSL_R_UNKNOWN_ALERT_TYPE 246
2283#define SSL_R_UNKNOWN_CERTIFICATE_TYPE 247
2284#define SSL_R_UNKNOWN_CIPHER_RETURNED 248
2285#define SSL_R_UNKNOWN_CIPHER_TYPE 249
2286#define SSL_R_UNKNOWN_DIGEST 368
2287#define SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE 250
2288#define SSL_R_UNKNOWN_PKEY_TYPE 251
2289#define SSL_R_UNKNOWN_PROTOCOL 252
2290#define SSL_R_UNKNOWN_REMOTE_ERROR_TYPE 253
2291#define SSL_R_UNKNOWN_SSL_VERSION 254
2292#define SSL_R_UNKNOWN_STATE 255
2293#define SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED 338
2294#define SSL_R_UNSUPPORTED_CIPHER 256
2295#define SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM 257
2296#define SSL_R_UNSUPPORTED_DIGEST_TYPE 326
2297#define SSL_R_UNSUPPORTED_ELLIPTIC_CURVE 315
2298#define SSL_R_UNSUPPORTED_PROTOCOL 258
2299#define SSL_R_UNSUPPORTED_SSL_VERSION 259
2300#define SSL_R_UNSUPPORTED_STATUS_TYPE 329
2301#define SSL_R_USE_SRTP_NOT_NEGOTIATED 369
2302#define SSL_R_VERSION_TOO_LOW 396
2303#define SSL_R_WRITE_BIO_NOT_SET 260
2304#define SSL_R_WRONG_CIPHER_RETURNED 261
2305#define SSL_R_WRONG_CURVE 378
2306#define SSL_R_WRONG_MESSAGE_TYPE 262
2307#define SSL_R_WRONG_NUMBER_OF_KEY_BITS 263
2308#define SSL_R_WRONG_SIGNATURE_LENGTH 264
2309#define SSL_R_WRONG_SIGNATURE_SIZE 265
2310#define SSL_R_WRONG_SIGNATURE_TYPE 370
2311#define SSL_R_WRONG_SSL_VERSION 266
2312#define SSL_R_WRONG_VERSION_NUMBER 267
2313#define SSL_R_X509_LIB 268
2314#define SSL_R_X509_VERIFICATION_SETUP_PROBLEMS 269
2315#define SSL_R_PEER_BEHAVING_BADLY 666
2316#define SSL_R_QUIC_INTERNAL_ERROR 667
2317#define SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED 668
2318#define SSL_R_UNKNOWN 999
2319
2320/*
2321 * OpenSSL compatible OPENSSL_INIT options
2322 */
2323
2324/*
2325 * These are provided for compatibility, but have no effect
2326 * on how LibreSSL is initialized.
2327 */
2328#define OPENSSL_INIT_LOAD_SSL_STRINGS _OPENSSL_INIT_FLAG_NOOP
2329#define OPENSSL_INIT_SSL_DEFAULT _OPENSSL_INIT_FLAG_NOOP
2330
2331int OPENSSL_init_ssl(uint64_t opts, const void *settings);
2332int SSL_library_init(void);
2333
2334/*
2335 * A few things still use this without #ifdef guard.
2336 */
2337
2338#define SSL2_VERSION 0x0002
2339
2340#ifdef __cplusplus
2341}
2342#endif
2343#endif
diff --git a/src/lib/libssl/ssl3.h b/src/lib/libssl/ssl3.h
deleted file mode 100644
index 1b1110b4e9..0000000000
--- a/src/lib/libssl/ssl3.h
+++ /dev/null
@@ -1,441 +0,0 @@
1/* $OpenBSD: ssl3.h,v 1.60 2024/03/02 11:47:41 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116
117#ifndef HEADER_SSL3_H
118#define HEADER_SSL3_H
119
120#include <openssl/opensslconf.h>
121#include <openssl/buffer.h>
122#include <openssl/evp.h>
123#include <openssl/ssl.h>
124
125#ifdef __cplusplus
126extern "C" {
127#endif
128
129/* TLS_EMPTY_RENEGOTIATION_INFO_SCSV from RFC 5746. */
130#define SSL3_CK_SCSV 0x030000FF
131
132/* TLS_FALLBACK_SCSV from draft-ietf-tls-downgrade-scsv-03. */
133#define SSL3_CK_FALLBACK_SCSV 0x03005600
134
135#define SSL3_CK_RSA_NULL_MD5 0x03000001
136#define SSL3_CK_RSA_NULL_SHA 0x03000002
137#define SSL3_CK_RSA_RC4_40_MD5 0x03000003
138#define SSL3_CK_RSA_RC4_128_MD5 0x03000004
139#define SSL3_CK_RSA_RC4_128_SHA 0x03000005
140#define SSL3_CK_RSA_RC2_40_MD5 0x03000006
141#define SSL3_CK_RSA_IDEA_128_SHA 0x03000007
142#define SSL3_CK_RSA_DES_40_CBC_SHA 0x03000008
143#define SSL3_CK_RSA_DES_64_CBC_SHA 0x03000009
144#define SSL3_CK_RSA_DES_192_CBC3_SHA 0x0300000A
145
146#define SSL3_CK_DH_DSS_DES_40_CBC_SHA 0x0300000B
147#define SSL3_CK_DH_DSS_DES_64_CBC_SHA 0x0300000C
148#define SSL3_CK_DH_DSS_DES_192_CBC3_SHA 0x0300000D
149#define SSL3_CK_DH_RSA_DES_40_CBC_SHA 0x0300000E
150#define SSL3_CK_DH_RSA_DES_64_CBC_SHA 0x0300000F
151#define SSL3_CK_DH_RSA_DES_192_CBC3_SHA 0x03000010
152
153#define SSL3_CK_EDH_DSS_DES_40_CBC_SHA 0x03000011
154#define SSL3_CK_EDH_DSS_DES_64_CBC_SHA 0x03000012
155#define SSL3_CK_EDH_DSS_DES_192_CBC3_SHA 0x03000013
156#define SSL3_CK_EDH_RSA_DES_40_CBC_SHA 0x03000014
157#define SSL3_CK_EDH_RSA_DES_64_CBC_SHA 0x03000015
158#define SSL3_CK_EDH_RSA_DES_192_CBC3_SHA 0x03000016
159
160#define SSL3_CK_ADH_RC4_40_MD5 0x03000017
161#define SSL3_CK_ADH_RC4_128_MD5 0x03000018
162#define SSL3_CK_ADH_DES_40_CBC_SHA 0x03000019
163#define SSL3_CK_ADH_DES_64_CBC_SHA 0x0300001A
164#define SSL3_CK_ADH_DES_192_CBC_SHA 0x0300001B
165
166/* VRS Additional Kerberos5 entries
167 */
168#define SSL3_CK_KRB5_DES_64_CBC_SHA 0x0300001E
169#define SSL3_CK_KRB5_DES_192_CBC3_SHA 0x0300001F
170#define SSL3_CK_KRB5_RC4_128_SHA 0x03000020
171#define SSL3_CK_KRB5_IDEA_128_CBC_SHA 0x03000021
172#define SSL3_CK_KRB5_DES_64_CBC_MD5 0x03000022
173#define SSL3_CK_KRB5_DES_192_CBC3_MD5 0x03000023
174#define SSL3_CK_KRB5_RC4_128_MD5 0x03000024
175#define SSL3_CK_KRB5_IDEA_128_CBC_MD5 0x03000025
176
177#define SSL3_CK_KRB5_DES_40_CBC_SHA 0x03000026
178#define SSL3_CK_KRB5_RC2_40_CBC_SHA 0x03000027
179#define SSL3_CK_KRB5_RC4_40_SHA 0x03000028
180#define SSL3_CK_KRB5_DES_40_CBC_MD5 0x03000029
181#define SSL3_CK_KRB5_RC2_40_CBC_MD5 0x0300002A
182#define SSL3_CK_KRB5_RC4_40_MD5 0x0300002B
183
184#define SSL3_TXT_RSA_NULL_MD5 "NULL-MD5"
185#define SSL3_TXT_RSA_NULL_SHA "NULL-SHA"
186#define SSL3_TXT_RSA_RC4_40_MD5 "EXP-RC4-MD5"
187#define SSL3_TXT_RSA_RC4_128_MD5 "RC4-MD5"
188#define SSL3_TXT_RSA_RC4_128_SHA "RC4-SHA"
189#define SSL3_TXT_RSA_RC2_40_MD5 "EXP-RC2-CBC-MD5"
190#define SSL3_TXT_RSA_IDEA_128_SHA "IDEA-CBC-SHA"
191#define SSL3_TXT_RSA_DES_40_CBC_SHA "EXP-DES-CBC-SHA"
192#define SSL3_TXT_RSA_DES_64_CBC_SHA "DES-CBC-SHA"
193#define SSL3_TXT_RSA_DES_192_CBC3_SHA "DES-CBC3-SHA"
194
195#define SSL3_TXT_DH_DSS_DES_40_CBC_SHA "EXP-DH-DSS-DES-CBC-SHA"
196#define SSL3_TXT_DH_DSS_DES_64_CBC_SHA "DH-DSS-DES-CBC-SHA"
197#define SSL3_TXT_DH_DSS_DES_192_CBC3_SHA "DH-DSS-DES-CBC3-SHA"
198#define SSL3_TXT_DH_RSA_DES_40_CBC_SHA "EXP-DH-RSA-DES-CBC-SHA"
199#define SSL3_TXT_DH_RSA_DES_64_CBC_SHA "DH-RSA-DES-CBC-SHA"
200#define SSL3_TXT_DH_RSA_DES_192_CBC3_SHA "DH-RSA-DES-CBC3-SHA"
201
202#define SSL3_TXT_EDH_DSS_DES_40_CBC_SHA "EXP-EDH-DSS-DES-CBC-SHA"
203#define SSL3_TXT_EDH_DSS_DES_64_CBC_SHA "EDH-DSS-DES-CBC-SHA"
204#define SSL3_TXT_EDH_DSS_DES_192_CBC3_SHA "EDH-DSS-DES-CBC3-SHA"
205#define SSL3_TXT_EDH_RSA_DES_40_CBC_SHA "EXP-EDH-RSA-DES-CBC-SHA"
206#define SSL3_TXT_EDH_RSA_DES_64_CBC_SHA "EDH-RSA-DES-CBC-SHA"
207#define SSL3_TXT_EDH_RSA_DES_192_CBC3_SHA "EDH-RSA-DES-CBC3-SHA"
208
209#define SSL3_TXT_ADH_RC4_40_MD5 "EXP-ADH-RC4-MD5"
210#define SSL3_TXT_ADH_RC4_128_MD5 "ADH-RC4-MD5"
211#define SSL3_TXT_ADH_DES_40_CBC_SHA "EXP-ADH-DES-CBC-SHA"
212#define SSL3_TXT_ADH_DES_64_CBC_SHA "ADH-DES-CBC-SHA"
213#define SSL3_TXT_ADH_DES_192_CBC_SHA "ADH-DES-CBC3-SHA"
214
215#define SSL3_TXT_KRB5_DES_64_CBC_SHA "KRB5-DES-CBC-SHA"
216#define SSL3_TXT_KRB5_DES_192_CBC3_SHA "KRB5-DES-CBC3-SHA"
217#define SSL3_TXT_KRB5_RC4_128_SHA "KRB5-RC4-SHA"
218#define SSL3_TXT_KRB5_IDEA_128_CBC_SHA "KRB5-IDEA-CBC-SHA"
219#define SSL3_TXT_KRB5_DES_64_CBC_MD5 "KRB5-DES-CBC-MD5"
220#define SSL3_TXT_KRB5_DES_192_CBC3_MD5 "KRB5-DES-CBC3-MD5"
221#define SSL3_TXT_KRB5_RC4_128_MD5 "KRB5-RC4-MD5"
222#define SSL3_TXT_KRB5_IDEA_128_CBC_MD5 "KRB5-IDEA-CBC-MD5"
223
224#define SSL3_TXT_KRB5_DES_40_CBC_SHA "EXP-KRB5-DES-CBC-SHA"
225#define SSL3_TXT_KRB5_RC2_40_CBC_SHA "EXP-KRB5-RC2-CBC-SHA"
226#define SSL3_TXT_KRB5_RC4_40_SHA "EXP-KRB5-RC4-SHA"
227#define SSL3_TXT_KRB5_DES_40_CBC_MD5 "EXP-KRB5-DES-CBC-MD5"
228#define SSL3_TXT_KRB5_RC2_40_CBC_MD5 "EXP-KRB5-RC2-CBC-MD5"
229#define SSL3_TXT_KRB5_RC4_40_MD5 "EXP-KRB5-RC4-MD5"
230
231#define SSL3_SSL_SESSION_ID_LENGTH 32
232#define SSL3_MAX_SSL_SESSION_ID_LENGTH 32
233
234#define SSL3_MASTER_SECRET_SIZE 48
235#define SSL3_RANDOM_SIZE 32
236#define SSL3_SEQUENCE_SIZE 8
237#define SSL3_SESSION_ID_SIZE 32
238#define SSL3_CIPHER_VALUE_SIZE 2
239
240#define SSL3_RT_HEADER_LENGTH 5
241#define SSL3_HM_HEADER_LENGTH 4
242
243#define SSL3_ALIGN_PAYLOAD 8
244
245/* This is the maximum MAC (digest) size used by the SSL library.
246 * Currently maximum of 20 is used by SHA1, but we reserve for
247 * future extension for 512-bit hashes.
248 */
249
250#define SSL3_RT_MAX_MD_SIZE 64
251
252/* Maximum block size used in all ciphersuites. Currently 16 for AES.
253 */
254
255#define SSL_RT_MAX_CIPHER_BLOCK_SIZE 16
256
257#define SSL3_RT_MAX_EXTRA (16384)
258
259/* Maximum plaintext length: defined by SSL/TLS standards */
260#define SSL3_RT_MAX_PLAIN_LENGTH 16384
261/* Maximum compression overhead: defined by SSL/TLS standards */
262#define SSL3_RT_MAX_COMPRESSED_OVERHEAD 1024
263
264/* The standards give a maximum encryption overhead of 1024 bytes.
265 * In practice the value is lower than this. The overhead is the maximum
266 * number of padding bytes (256) plus the mac size.
267 */
268#define SSL3_RT_MAX_ENCRYPTED_OVERHEAD (256 + SSL3_RT_MAX_MD_SIZE)
269
270/* OpenSSL currently only uses a padding length of at most one block so
271 * the send overhead is smaller.
272 */
273
274#define SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD \
275 (SSL_RT_MAX_CIPHER_BLOCK_SIZE + SSL3_RT_MAX_MD_SIZE)
276
277/* If compression isn't used don't include the compression overhead */
278#define SSL3_RT_MAX_COMPRESSED_LENGTH SSL3_RT_MAX_PLAIN_LENGTH
279#define SSL3_RT_MAX_ENCRYPTED_LENGTH \
280 (SSL3_RT_MAX_ENCRYPTED_OVERHEAD+SSL3_RT_MAX_COMPRESSED_LENGTH)
281#define SSL3_RT_MAX_PACKET_SIZE \
282 (SSL3_RT_MAX_ENCRYPTED_LENGTH+SSL3_RT_HEADER_LENGTH)
283
284#define SSL3_MD_CLIENT_FINISHED_CONST "\x43\x4C\x4E\x54"
285#define SSL3_MD_SERVER_FINISHED_CONST "\x53\x52\x56\x52"
286
287#define SSL3_VERSION 0x0300
288#define SSL3_VERSION_MAJOR 0x03
289#define SSL3_VERSION_MINOR 0x00
290
291#define SSL3_RT_CHANGE_CIPHER_SPEC 20
292#define SSL3_RT_ALERT 21
293#define SSL3_RT_HANDSHAKE 22
294#define SSL3_RT_APPLICATION_DATA 23
295
296#define SSL3_AL_WARNING 1
297#define SSL3_AL_FATAL 2
298
299#ifndef LIBRESSL_INTERNAL
300#define SSL3_AD_CLOSE_NOTIFY 0
301#define SSL3_AD_UNEXPECTED_MESSAGE 10 /* fatal */
302#define SSL3_AD_BAD_RECORD_MAC 20 /* fatal */
303#define SSL3_AD_DECOMPRESSION_FAILURE 30 /* fatal */
304#define SSL3_AD_HANDSHAKE_FAILURE 40 /* fatal */
305#define SSL3_AD_NO_CERTIFICATE 41
306#define SSL3_AD_BAD_CERTIFICATE 42
307#define SSL3_AD_UNSUPPORTED_CERTIFICATE 43
308#define SSL3_AD_CERTIFICATE_REVOKED 44
309#define SSL3_AD_CERTIFICATE_EXPIRED 45
310#define SSL3_AD_CERTIFICATE_UNKNOWN 46
311#define SSL3_AD_ILLEGAL_PARAMETER 47 /* fatal */
312#endif
313
314#define TLS1_HB_REQUEST 1
315#define TLS1_HB_RESPONSE 2
316
317#define SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS 0x0001
318#define TLS1_FLAGS_FREEZE_TRANSCRIPT 0x0020
319#define SSL3_FLAGS_CCS_OK 0x0080
320
321/* SSLv3 */
322/*client */
323/* extra state */
324#define SSL3_ST_CW_FLUSH (0x100|SSL_ST_CONNECT)
325/* write to server */
326#define SSL3_ST_CW_CLNT_HELLO_A (0x110|SSL_ST_CONNECT)
327#define SSL3_ST_CW_CLNT_HELLO_B (0x111|SSL_ST_CONNECT)
328/* read from server */
329#define SSL3_ST_CR_SRVR_HELLO_A (0x120|SSL_ST_CONNECT)
330#define SSL3_ST_CR_SRVR_HELLO_B (0x121|SSL_ST_CONNECT)
331#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A (0x126|SSL_ST_CONNECT)
332#define DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B (0x127|SSL_ST_CONNECT)
333#define SSL3_ST_CR_CERT_A (0x130|SSL_ST_CONNECT)
334#define SSL3_ST_CR_CERT_B (0x131|SSL_ST_CONNECT)
335#define SSL3_ST_CR_KEY_EXCH_A (0x140|SSL_ST_CONNECT)
336#define SSL3_ST_CR_KEY_EXCH_B (0x141|SSL_ST_CONNECT)
337#define SSL3_ST_CR_CERT_REQ_A (0x150|SSL_ST_CONNECT)
338#define SSL3_ST_CR_CERT_REQ_B (0x151|SSL_ST_CONNECT)
339#define SSL3_ST_CR_SRVR_DONE_A (0x160|SSL_ST_CONNECT)
340#define SSL3_ST_CR_SRVR_DONE_B (0x161|SSL_ST_CONNECT)
341/* write to server */
342#define SSL3_ST_CW_CERT_A (0x170|SSL_ST_CONNECT)
343#define SSL3_ST_CW_CERT_B (0x171|SSL_ST_CONNECT)
344#define SSL3_ST_CW_CERT_C (0x172|SSL_ST_CONNECT)
345#define SSL3_ST_CW_CERT_D (0x173|SSL_ST_CONNECT)
346#define SSL3_ST_CW_KEY_EXCH_A (0x180|SSL_ST_CONNECT)
347#define SSL3_ST_CW_KEY_EXCH_B (0x181|SSL_ST_CONNECT)
348#define SSL3_ST_CW_CERT_VRFY_A (0x190|SSL_ST_CONNECT)
349#define SSL3_ST_CW_CERT_VRFY_B (0x191|SSL_ST_CONNECT)
350#define SSL3_ST_CW_CHANGE_A (0x1A0|SSL_ST_CONNECT)
351#define SSL3_ST_CW_CHANGE_B (0x1A1|SSL_ST_CONNECT)
352#define SSL3_ST_CW_FINISHED_A (0x1B0|SSL_ST_CONNECT)
353#define SSL3_ST_CW_FINISHED_B (0x1B1|SSL_ST_CONNECT)
354/* read from server */
355#define SSL3_ST_CR_CHANGE_A (0x1C0|SSL_ST_CONNECT)
356#define SSL3_ST_CR_CHANGE_B (0x1C1|SSL_ST_CONNECT)
357#define SSL3_ST_CR_FINISHED_A (0x1D0|SSL_ST_CONNECT)
358#define SSL3_ST_CR_FINISHED_B (0x1D1|SSL_ST_CONNECT)
359#define SSL3_ST_CR_SESSION_TICKET_A (0x1E0|SSL_ST_CONNECT)
360#define SSL3_ST_CR_SESSION_TICKET_B (0x1E1|SSL_ST_CONNECT)
361#define SSL3_ST_CR_CERT_STATUS_A (0x1F0|SSL_ST_CONNECT)
362#define SSL3_ST_CR_CERT_STATUS_B (0x1F1|SSL_ST_CONNECT)
363
364/* server */
365/* extra state */
366#define SSL3_ST_SW_FLUSH (0x100|SSL_ST_ACCEPT)
367/* read from client */
368/* Do not change the number values, they do matter */
369#define SSL3_ST_SR_CLNT_HELLO_A (0x110|SSL_ST_ACCEPT)
370#define SSL3_ST_SR_CLNT_HELLO_B (0x111|SSL_ST_ACCEPT)
371#define SSL3_ST_SR_CLNT_HELLO_C (0x112|SSL_ST_ACCEPT)
372/* write to client */
373#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A (0x113|SSL_ST_ACCEPT)
374#define DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B (0x114|SSL_ST_ACCEPT)
375#define SSL3_ST_SW_HELLO_REQ_A (0x120|SSL_ST_ACCEPT)
376#define SSL3_ST_SW_HELLO_REQ_B (0x121|SSL_ST_ACCEPT)
377#define SSL3_ST_SW_HELLO_REQ_C (0x122|SSL_ST_ACCEPT)
378#define SSL3_ST_SW_SRVR_HELLO_A (0x130|SSL_ST_ACCEPT)
379#define SSL3_ST_SW_SRVR_HELLO_B (0x131|SSL_ST_ACCEPT)
380#define SSL3_ST_SW_CERT_A (0x140|SSL_ST_ACCEPT)
381#define SSL3_ST_SW_CERT_B (0x141|SSL_ST_ACCEPT)
382#define SSL3_ST_SW_KEY_EXCH_A (0x150|SSL_ST_ACCEPT)
383#define SSL3_ST_SW_KEY_EXCH_B (0x151|SSL_ST_ACCEPT)
384#define SSL3_ST_SW_CERT_REQ_A (0x160|SSL_ST_ACCEPT)
385#define SSL3_ST_SW_CERT_REQ_B (0x161|SSL_ST_ACCEPT)
386#define SSL3_ST_SW_SRVR_DONE_A (0x170|SSL_ST_ACCEPT)
387#define SSL3_ST_SW_SRVR_DONE_B (0x171|SSL_ST_ACCEPT)
388/* read from client */
389#define SSL3_ST_SR_CERT_A (0x180|SSL_ST_ACCEPT)
390#define SSL3_ST_SR_CERT_B (0x181|SSL_ST_ACCEPT)
391#define SSL3_ST_SR_KEY_EXCH_A (0x190|SSL_ST_ACCEPT)
392#define SSL3_ST_SR_KEY_EXCH_B (0x191|SSL_ST_ACCEPT)
393#define SSL3_ST_SR_CERT_VRFY_A (0x1A0|SSL_ST_ACCEPT)
394#define SSL3_ST_SR_CERT_VRFY_B (0x1A1|SSL_ST_ACCEPT)
395#define SSL3_ST_SR_CHANGE_A (0x1B0|SSL_ST_ACCEPT)
396#define SSL3_ST_SR_CHANGE_B (0x1B1|SSL_ST_ACCEPT)
397#define SSL3_ST_SR_FINISHED_A (0x1C0|SSL_ST_ACCEPT)
398#define SSL3_ST_SR_FINISHED_B (0x1C1|SSL_ST_ACCEPT)
399/* write to client */
400#define SSL3_ST_SW_CHANGE_A (0x1D0|SSL_ST_ACCEPT)
401#define SSL3_ST_SW_CHANGE_B (0x1D1|SSL_ST_ACCEPT)
402#define SSL3_ST_SW_FINISHED_A (0x1E0|SSL_ST_ACCEPT)
403#define SSL3_ST_SW_FINISHED_B (0x1E1|SSL_ST_ACCEPT)
404#define SSL3_ST_SW_SESSION_TICKET_A (0x1F0|SSL_ST_ACCEPT)
405#define SSL3_ST_SW_SESSION_TICKET_B (0x1F1|SSL_ST_ACCEPT)
406#define SSL3_ST_SW_CERT_STATUS_A (0x200|SSL_ST_ACCEPT)
407#define SSL3_ST_SW_CERT_STATUS_B (0x201|SSL_ST_ACCEPT)
408
409#define SSL3_MT_HELLO_REQUEST 0
410#define SSL3_MT_CLIENT_HELLO 1
411#define SSL3_MT_SERVER_HELLO 2
412#define SSL3_MT_NEWSESSION_TICKET 4
413#define SSL3_MT_CERTIFICATE 11
414#define SSL3_MT_SERVER_KEY_EXCHANGE 12
415#define SSL3_MT_CERTIFICATE_REQUEST 13
416#define SSL3_MT_SERVER_DONE 14
417#define SSL3_MT_CERTIFICATE_VERIFY 15
418#define SSL3_MT_CLIENT_KEY_EXCHANGE 16
419#define SSL3_MT_FINISHED 20
420#define SSL3_MT_CERTIFICATE_STATUS 22
421
422#define DTLS1_MT_HELLO_VERIFY_REQUEST 3
423
424#define SSL3_MT_CCS 1
425
426#ifndef LIBRESSL_INTERNAL
427/* These are used when changing over to a new cipher */
428#define SSL3_CC_READ 0x01
429#define SSL3_CC_WRITE 0x02
430#define SSL3_CC_CLIENT 0x10
431#define SSL3_CC_SERVER 0x20
432#define SSL3_CHANGE_CIPHER_CLIENT_WRITE (SSL3_CC_CLIENT|SSL3_CC_WRITE)
433#define SSL3_CHANGE_CIPHER_SERVER_READ (SSL3_CC_SERVER|SSL3_CC_READ)
434#define SSL3_CHANGE_CIPHER_CLIENT_READ (SSL3_CC_CLIENT|SSL3_CC_READ)
435#define SSL3_CHANGE_CIPHER_SERVER_WRITE (SSL3_CC_SERVER|SSL3_CC_WRITE)
436#endif
437
438#ifdef __cplusplus
439}
440#endif
441#endif
diff --git a/src/lib/libssl/ssl_asn1.c b/src/lib/libssl/ssl_asn1.c
deleted file mode 100644
index fcf4631a59..0000000000
--- a/src/lib/libssl/ssl_asn1.c
+++ /dev/null
@@ -1,410 +0,0 @@
1/* $OpenBSD: ssl_asn1.c,v 1.69 2024/07/22 14:47:15 jsing Exp $ */
2/*
3 * Copyright (c) 2016 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <limits.h>
19
20#include <openssl/ssl.h>
21#include <openssl/x509.h>
22
23#include "bytestring.h"
24#include "ssl_local.h"
25
26#define SSLASN1_TAG (CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC)
27#define SSLASN1_TIME_TAG (SSLASN1_TAG | 1)
28#define SSLASN1_TIMEOUT_TAG (SSLASN1_TAG | 2)
29#define SSLASN1_PEER_CERT_TAG (SSLASN1_TAG | 3)
30#define SSLASN1_SESSION_ID_CTX_TAG (SSLASN1_TAG | 4)
31#define SSLASN1_VERIFY_RESULT_TAG (SSLASN1_TAG | 5)
32#define SSLASN1_HOSTNAME_TAG (SSLASN1_TAG | 6)
33#define SSLASN1_LIFETIME_TAG (SSLASN1_TAG | 9)
34#define SSLASN1_TICKET_TAG (SSLASN1_TAG | 10)
35
36static uint64_t
37time_max(void)
38{
39 if (sizeof(time_t) == sizeof(int32_t))
40 return INT32_MAX;
41 if (sizeof(time_t) == sizeof(int64_t))
42 return INT64_MAX;
43 return 0;
44}
45
46static int
47SSL_SESSION_encode(SSL_SESSION *s, unsigned char **out, size_t *out_len,
48 int ticket_encoding)
49{
50 CBB cbb, session, cipher_suite, session_id, master_key, time, timeout;
51 CBB peer_cert, sidctx, verify_result, hostname, lifetime, ticket, value;
52 unsigned char *peer_cert_bytes = NULL;
53 int len, rv = 0;
54
55 if (!CBB_init(&cbb, 0))
56 goto err;
57
58 if (!CBB_add_asn1(&cbb, &session, CBS_ASN1_SEQUENCE))
59 goto err;
60
61 /* Session ASN1 version. */
62 if (!CBB_add_asn1_uint64(&session, SSL_SESSION_ASN1_VERSION))
63 goto err;
64
65 /* TLS/SSL protocol version. */
66 if (s->ssl_version < 0)
67 goto err;
68 if (!CBB_add_asn1_uint64(&session, s->ssl_version))
69 goto err;
70
71 /* Cipher suite value. */
72 if (!CBB_add_asn1(&session, &cipher_suite, CBS_ASN1_OCTETSTRING))
73 goto err;
74 if (!CBB_add_u16(&cipher_suite, s->cipher_value))
75 goto err;
76
77 /* Session ID - zero length for a ticket. */
78 if (!CBB_add_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING))
79 goto err;
80 if (!CBB_add_bytes(&session_id, s->session_id,
81 ticket_encoding ? 0 : s->session_id_length))
82 goto err;
83
84 /* Master key. */
85 if (!CBB_add_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING))
86 goto err;
87 if (!CBB_add_bytes(&master_key, s->master_key, s->master_key_length))
88 goto err;
89
90 /* Time [1]. */
91 if (s->time != 0) {
92 if (s->time < 0)
93 goto err;
94 if (!CBB_add_asn1(&session, &time, SSLASN1_TIME_TAG))
95 goto err;
96 if (!CBB_add_asn1_uint64(&time, s->time))
97 goto err;
98 }
99
100 /* Timeout [2]. */
101 if (s->timeout != 0) {
102 if (s->timeout < 0)
103 goto err;
104 if (!CBB_add_asn1(&session, &timeout, SSLASN1_TIMEOUT_TAG))
105 goto err;
106 if (!CBB_add_asn1_uint64(&timeout, s->timeout))
107 goto err;
108 }
109
110 /* Peer certificate [3]. */
111 if (s->peer_cert != NULL) {
112 if ((len = i2d_X509(s->peer_cert, &peer_cert_bytes)) <= 0)
113 goto err;
114 if (!CBB_add_asn1(&session, &peer_cert, SSLASN1_PEER_CERT_TAG))
115 goto err;
116 if (!CBB_add_bytes(&peer_cert, peer_cert_bytes, len))
117 goto err;
118 }
119
120 /* Session ID context [4]. */
121 /* XXX - Actually handle this as optional? */
122 if (!CBB_add_asn1(&session, &sidctx, SSLASN1_SESSION_ID_CTX_TAG))
123 goto err;
124 if (!CBB_add_asn1(&sidctx, &value, CBS_ASN1_OCTETSTRING))
125 goto err;
126 if (!CBB_add_bytes(&value, s->sid_ctx, s->sid_ctx_length))
127 goto err;
128
129 /* Verify result [5]. */
130 if (s->verify_result != X509_V_OK) {
131 if (s->verify_result < 0)
132 goto err;
133 if (!CBB_add_asn1(&session, &verify_result,
134 SSLASN1_VERIFY_RESULT_TAG))
135 goto err;
136 if (!CBB_add_asn1_uint64(&verify_result, s->verify_result))
137 goto err;
138 }
139
140 /* Hostname [6]. */
141 if (s->tlsext_hostname != NULL) {
142 if (!CBB_add_asn1(&session, &hostname, SSLASN1_HOSTNAME_TAG))
143 goto err;
144 if (!CBB_add_asn1(&hostname, &value, CBS_ASN1_OCTETSTRING))
145 goto err;
146 if (!CBB_add_bytes(&value, (const uint8_t *)s->tlsext_hostname,
147 strlen(s->tlsext_hostname)))
148 goto err;
149 }
150
151 /* PSK identity hint [7]. */
152 /* PSK identity [8]. */
153
154 /* Ticket lifetime hint [9]. */
155 if (s->tlsext_tick_lifetime_hint > 0) {
156 if (!CBB_add_asn1(&session, &lifetime, SSLASN1_LIFETIME_TAG))
157 goto err;
158 if (!CBB_add_asn1_uint64(&lifetime,
159 s->tlsext_tick_lifetime_hint))
160 goto err;
161 }
162
163 /* Ticket [10]. */
164 if (s->tlsext_tick != NULL) {
165 if (!CBB_add_asn1(&session, &ticket, SSLASN1_TICKET_TAG))
166 goto err;
167 if (!CBB_add_asn1(&ticket, &value, CBS_ASN1_OCTETSTRING))
168 goto err;
169 if (!CBB_add_bytes(&value, s->tlsext_tick, s->tlsext_ticklen))
170 goto err;
171 }
172
173 /* Compression method [11]. */
174 /* SRP username [12]. */
175
176 if (!CBB_finish(&cbb, out, out_len))
177 goto err;
178
179 rv = 1;
180
181 err:
182 CBB_cleanup(&cbb);
183 free(peer_cert_bytes);
184
185 return rv;
186}
187
188int
189SSL_SESSION_ticket(SSL_SESSION *ss, unsigned char **out, size_t *out_len)
190{
191 if (ss == NULL)
192 return 0;
193
194 if (ss->cipher_value == 0)
195 return 0;
196
197 return SSL_SESSION_encode(ss, out, out_len, 1);
198}
199
200int
201i2d_SSL_SESSION(SSL_SESSION *ss, unsigned char **pp)
202{
203 unsigned char *data = NULL;
204 size_t data_len = 0;
205 int rv = -1;
206
207 if (ss == NULL)
208 return 0;
209
210 if (ss->cipher_value == 0)
211 return 0;
212
213 if (!SSL_SESSION_encode(ss, &data, &data_len, 0))
214 goto err;
215
216 if (data_len > INT_MAX)
217 goto err;
218
219 if (pp != NULL) {
220 if (*pp == NULL) {
221 *pp = data;
222 data = NULL;
223 } else {
224 memcpy(*pp, data, data_len);
225 *pp += data_len;
226 }
227 }
228
229 rv = (int)data_len;
230
231 err:
232 freezero(data, data_len);
233
234 return rv;
235}
236LSSL_ALIAS(i2d_SSL_SESSION);
237
238SSL_SESSION *
239d2i_SSL_SESSION(SSL_SESSION **a, const unsigned char **pp, long length)
240{
241 CBS cbs, session, cipher_suite, session_id, master_key, peer_cert;
242 CBS hostname, ticket;
243 uint64_t version, tls_version, stime, timeout, verify_result, lifetime;
244 const unsigned char *peer_cert_bytes;
245 SSL_SESSION *s = NULL;
246 size_t data_len;
247 int present;
248
249 if (a != NULL)
250 s = *a;
251
252 if (s == NULL) {
253 if ((s = SSL_SESSION_new()) == NULL) {
254 SSLerrorx(ERR_R_MALLOC_FAILURE);
255 return (NULL);
256 }
257 }
258
259 CBS_init(&cbs, *pp, length);
260
261 if (!CBS_get_asn1(&cbs, &session, CBS_ASN1_SEQUENCE))
262 goto err;
263
264 /* Session ASN1 version. */
265 if (!CBS_get_asn1_uint64(&session, &version))
266 goto err;
267 if (version != SSL_SESSION_ASN1_VERSION)
268 goto err;
269
270 /* TLS/SSL Protocol Version. */
271 if (!CBS_get_asn1_uint64(&session, &tls_version))
272 goto err;
273 if (tls_version > INT_MAX)
274 goto err;
275 s->ssl_version = (int)tls_version;
276
277 /* Cipher suite value. */
278 if (!CBS_get_asn1(&session, &cipher_suite, CBS_ASN1_OCTETSTRING))
279 goto err;
280 if (!CBS_get_u16(&cipher_suite, &s->cipher_value))
281 goto err;
282 if (CBS_len(&cipher_suite) != 0)
283 goto err;
284
285 /* Session ID. */
286 if (!CBS_get_asn1(&session, &session_id, CBS_ASN1_OCTETSTRING))
287 goto err;
288 if (!CBS_write_bytes(&session_id, s->session_id, sizeof(s->session_id),
289 &s->session_id_length))
290 goto err;
291
292 /* Master key. */
293 if (!CBS_get_asn1(&session, &master_key, CBS_ASN1_OCTETSTRING))
294 goto err;
295 if (!CBS_write_bytes(&master_key, s->master_key, sizeof(s->master_key),
296 &s->master_key_length))
297 goto err;
298
299 /* Time [1]. */
300 s->time = time(NULL);
301 if (!CBS_get_optional_asn1_uint64(&session, &stime, SSLASN1_TIME_TAG,
302 0))
303 goto err;
304 if (stime > time_max())
305 goto err;
306 if (stime != 0)
307 s->time = (time_t)stime;
308
309 /* Timeout [2]. */
310 s->timeout = 3;
311 if (!CBS_get_optional_asn1_uint64(&session, &timeout,
312 SSLASN1_TIMEOUT_TAG, 0))
313 goto err;
314 if (timeout > LONG_MAX)
315 goto err;
316 if (timeout != 0)
317 s->timeout = (long)timeout;
318
319 /* Peer certificate [3]. */
320 X509_free(s->peer_cert);
321 s->peer_cert = NULL;
322 if (!CBS_get_optional_asn1(&session, &peer_cert, &present,
323 SSLASN1_PEER_CERT_TAG))
324 goto err;
325 if (present) {
326 data_len = CBS_len(&peer_cert);
327 if (data_len > LONG_MAX)
328 goto err;
329 peer_cert_bytes = CBS_data(&peer_cert);
330 if (d2i_X509(&s->peer_cert, &peer_cert_bytes,
331 (long)data_len) == NULL)
332 goto err;
333 }
334
335 /* Session ID context [4]. */
336 s->sid_ctx_length = 0;
337 if (!CBS_get_optional_asn1_octet_string(&session, &session_id, &present,
338 SSLASN1_SESSION_ID_CTX_TAG))
339 goto err;
340 if (present) {
341 if (!CBS_write_bytes(&session_id, (uint8_t *)&s->sid_ctx,
342 sizeof(s->sid_ctx), &s->sid_ctx_length))
343 goto err;
344 }
345
346 /* Verify result [5]. */
347 s->verify_result = X509_V_OK;
348 if (!CBS_get_optional_asn1_uint64(&session, &verify_result,
349 SSLASN1_VERIFY_RESULT_TAG, X509_V_OK))
350 goto err;
351 if (verify_result > LONG_MAX)
352 goto err;
353 s->verify_result = (long)verify_result;
354
355 /* Hostname [6]. */
356 free(s->tlsext_hostname);
357 s->tlsext_hostname = NULL;
358 if (!CBS_get_optional_asn1_octet_string(&session, &hostname, &present,
359 SSLASN1_HOSTNAME_TAG))
360 goto err;
361 if (present) {
362 if (CBS_contains_zero_byte(&hostname))
363 goto err;
364 if (!CBS_strdup(&hostname, &s->tlsext_hostname))
365 goto err;
366 }
367
368 /* PSK identity hint [7]. */
369 /* PSK identity [8]. */
370
371 /* Ticket lifetime [9]. */
372 s->tlsext_tick_lifetime_hint = 0;
373 if (!CBS_get_optional_asn1_uint64(&session, &lifetime,
374 SSLASN1_LIFETIME_TAG, 0))
375 goto err;
376 if (lifetime > UINT32_MAX)
377 goto err;
378 if (lifetime > 0)
379 s->tlsext_tick_lifetime_hint = (uint32_t)lifetime;
380
381 /* Ticket [10]. */
382 free(s->tlsext_tick);
383 s->tlsext_tick = NULL;
384 if (!CBS_get_optional_asn1_octet_string(&session, &ticket, &present,
385 SSLASN1_TICKET_TAG))
386 goto err;
387 if (present) {
388 if (!CBS_stow(&ticket, &s->tlsext_tick, &s->tlsext_ticklen))
389 goto err;
390 }
391
392 /* Compression method [11]. */
393 /* SRP username [12]. */
394
395 *pp = CBS_data(&cbs);
396
397 if (a != NULL)
398 *a = s;
399
400 return (s);
401
402 err:
403 ERR_asprintf_error_data("offset=%d", (int)(CBS_data(&cbs) - *pp));
404
405 if (s != NULL && (a == NULL || *a != s))
406 SSL_SESSION_free(s);
407
408 return (NULL);
409}
410LSSL_ALIAS(d2i_SSL_SESSION);
diff --git a/src/lib/libssl/ssl_both.c b/src/lib/libssl/ssl_both.c
deleted file mode 100644
index 995f1c4601..0000000000
--- a/src/lib/libssl/ssl_both.c
+++ /dev/null
@@ -1,577 +0,0 @@
1/* $OpenBSD: ssl_both.c,v 1.47 2024/02/03 15:58:33 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116
117#include <limits.h>
118#include <stdio.h>
119#include <string.h>
120
121#include <openssl/buffer.h>
122#include <openssl/evp.h>
123#include <openssl/objects.h>
124#include <openssl/x509.h>
125
126#include "bytestring.h"
127#include "dtls_local.h"
128#include "ssl_local.h"
129
130/*
131 * Send s->init_buf in records of type 'type' (SSL3_RT_HANDSHAKE or
132 * SSL3_RT_CHANGE_CIPHER_SPEC).
133 */
134int
135ssl3_do_write(SSL *s, int type)
136{
137 int ret;
138
139 ret = ssl3_write_bytes(s, type, &s->init_buf->data[s->init_off],
140 s->init_num);
141 if (ret < 0)
142 return (-1);
143
144 if (type == SSL3_RT_HANDSHAKE)
145 /*
146 * Should not be done for 'Hello Request's, but in that case
147 * we'll ignore the result anyway.
148 */
149 tls1_transcript_record(s,
150 (unsigned char *)&s->init_buf->data[s->init_off], ret);
151
152 if (ret == s->init_num) {
153 ssl_msg_callback(s, 1, type, s->init_buf->data,
154 (size_t)(s->init_off + s->init_num));
155 return (1);
156 }
157
158 s->init_off += ret;
159 s->init_num -= ret;
160
161 return (0);
162}
163
164static int
165ssl3_add_cert(CBB *cbb, X509 *x)
166{
167 unsigned char *data;
168 int cert_len;
169 int ret = 0;
170 CBB cert;
171
172 if ((cert_len = i2d_X509(x, NULL)) < 0)
173 goto err;
174
175 if (!CBB_add_u24_length_prefixed(cbb, &cert))
176 goto err;
177 if (!CBB_add_space(&cert, &data, cert_len))
178 goto err;
179 if (i2d_X509(x, &data) < 0)
180 goto err;
181 if (!CBB_flush(cbb))
182 goto err;
183
184 ret = 1;
185
186 err:
187 return (ret);
188}
189
190int
191ssl3_output_cert_chain(SSL *s, CBB *cbb, SSL_CERT_PKEY *cpk)
192{
193 X509_STORE_CTX *xs_ctx = NULL;
194 STACK_OF(X509) *chain;
195 CBB cert_list;
196 X509 *x;
197 int ret = 0;
198 int i;
199
200 if (!CBB_add_u24_length_prefixed(cbb, &cert_list))
201 goto err;
202
203 /* Send an empty certificate list when no certificate is available. */
204 if (cpk == NULL)
205 goto done;
206
207 if ((chain = cpk->chain) == NULL)
208 chain = s->ctx->extra_certs;
209
210 if (chain != NULL || (s->mode & SSL_MODE_NO_AUTO_CHAIN)) {
211 if (!ssl3_add_cert(&cert_list, cpk->x509))
212 goto err;
213 } else {
214 if ((xs_ctx = X509_STORE_CTX_new()) == NULL)
215 goto err;
216 if (!X509_STORE_CTX_init(xs_ctx, s->ctx->cert_store,
217 cpk->x509, NULL)) {
218 SSLerror(s, ERR_R_X509_LIB);
219 goto err;
220 }
221 X509_VERIFY_PARAM_set_flags(X509_STORE_CTX_get0_param(xs_ctx),
222 X509_V_FLAG_LEGACY_VERIFY);
223 X509_verify_cert(xs_ctx);
224 ERR_clear_error();
225 chain = X509_STORE_CTX_get0_chain(xs_ctx);
226 }
227
228 for (i = 0; i < sk_X509_num(chain); i++) {
229 x = sk_X509_value(chain, i);
230 if (!ssl3_add_cert(&cert_list, x))
231 goto err;
232 }
233
234 done:
235 if (!CBB_flush(cbb))
236 goto err;
237
238 ret = 1;
239
240 err:
241 X509_STORE_CTX_free(xs_ctx);
242
243 return (ret);
244}
245
246/*
247 * Obtain handshake message of message type 'mt' (any if mt == -1),
248 * maximum acceptable body length 'max'.
249 * The first four bytes (msg_type and length) are read in state 'st1',
250 * the body is read in state 'stn'.
251 */
252int
253ssl3_get_message(SSL *s, int st1, int stn, int mt, long max)
254{
255 unsigned char *p;
256 uint32_t l;
257 long n;
258 int i, al;
259 CBS cbs;
260 uint8_t u8;
261
262 if (SSL_is_dtls(s))
263 return dtls1_get_message(s, st1, stn, mt, max);
264
265 if (s->s3->hs.tls12.reuse_message) {
266 s->s3->hs.tls12.reuse_message = 0;
267 if ((mt >= 0) && (s->s3->hs.tls12.message_type != mt)) {
268 al = SSL_AD_UNEXPECTED_MESSAGE;
269 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
270 goto fatal_err;
271 }
272 s->init_msg = s->init_buf->data +
273 SSL3_HM_HEADER_LENGTH;
274 s->init_num = (int)s->s3->hs.tls12.message_size;
275 return 1;
276 }
277
278 p = (unsigned char *)s->init_buf->data;
279
280 if (s->s3->hs.state == st1) {
281 int skip_message;
282
283 do {
284 while (s->init_num < SSL3_HM_HEADER_LENGTH) {
285 i = s->method->ssl_read_bytes(s,
286 SSL3_RT_HANDSHAKE, &p[s->init_num],
287 SSL3_HM_HEADER_LENGTH - s->init_num, 0);
288 if (i <= 0) {
289 s->rwstate = SSL_READING;
290 return i;
291 }
292 s->init_num += i;
293 }
294
295 skip_message = 0;
296 if (!s->server && p[0] == SSL3_MT_HELLO_REQUEST) {
297 /*
298 * The server may always send 'Hello Request'
299 * messages -- we are doing a handshake anyway
300 * now, so ignore them if their format is
301 * correct. Does not count for 'Finished' MAC.
302 */
303 if (p[1] == 0 && p[2] == 0 &&p[3] == 0) {
304 s->init_num = 0;
305 skip_message = 1;
306
307 ssl_msg_callback(s, 0,
308 SSL3_RT_HANDSHAKE, p,
309 SSL3_HM_HEADER_LENGTH);
310 }
311 }
312 } while (skip_message);
313
314 if ((mt >= 0) && (*p != mt)) {
315 al = SSL_AD_UNEXPECTED_MESSAGE;
316 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
317 goto fatal_err;
318 }
319
320 CBS_init(&cbs, p, SSL3_HM_HEADER_LENGTH);
321 if (!CBS_get_u8(&cbs, &u8) ||
322 !CBS_get_u24(&cbs, &l)) {
323 SSLerror(s, ERR_R_BUF_LIB);
324 goto err;
325 }
326 s->s3->hs.tls12.message_type = u8;
327
328 if (l > (unsigned long)max) {
329 al = SSL_AD_ILLEGAL_PARAMETER;
330 SSLerror(s, SSL_R_EXCESSIVE_MESSAGE_SIZE);
331 goto fatal_err;
332 }
333 if (l && !BUF_MEM_grow_clean(s->init_buf,
334 l + SSL3_HM_HEADER_LENGTH)) {
335 SSLerror(s, ERR_R_BUF_LIB);
336 goto err;
337 }
338 s->s3->hs.tls12.message_size = l;
339 s->s3->hs.state = stn;
340
341 s->init_msg = s->init_buf->data +
342 SSL3_HM_HEADER_LENGTH;
343 s->init_num = 0;
344 }
345
346 /* next state (stn) */
347 p = s->init_msg;
348 n = s->s3->hs.tls12.message_size - s->init_num;
349 while (n > 0) {
350 i = s->method->ssl_read_bytes(s, SSL3_RT_HANDSHAKE,
351 &p[s->init_num], n, 0);
352 if (i <= 0) {
353 s->rwstate = SSL_READING;
354 return i;
355 }
356 s->init_num += i;
357 n -= i;
358 }
359
360 /* Feed this message into MAC computation. */
361 if (s->mac_packet) {
362 tls1_transcript_record(s, (unsigned char *)s->init_buf->data,
363 s->init_num + SSL3_HM_HEADER_LENGTH);
364
365 ssl_msg_callback(s, 0, SSL3_RT_HANDSHAKE,
366 s->init_buf->data,
367 (size_t)s->init_num + SSL3_HM_HEADER_LENGTH);
368 }
369
370 return 1;
371
372 fatal_err:
373 ssl3_send_alert(s, SSL3_AL_FATAL, al);
374 err:
375 return -1;
376}
377
378int
379ssl_cert_type(EVP_PKEY *pkey)
380{
381 if (pkey == NULL)
382 return -1;
383
384 switch (EVP_PKEY_id(pkey)) {
385 case EVP_PKEY_EC:
386 return SSL_PKEY_ECC;
387 case EVP_PKEY_RSA:
388 case EVP_PKEY_RSA_PSS:
389 return SSL_PKEY_RSA;
390 }
391
392 return -1;
393}
394
395int
396ssl_verify_alarm_type(long type)
397{
398 int al;
399
400 switch (type) {
401 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
402 case X509_V_ERR_UNABLE_TO_GET_CRL:
403 case X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER:
404 al = SSL_AD_UNKNOWN_CA;
405 break;
406 case X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE:
407 case X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE:
408 case X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY:
409 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
410 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
411 case X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD:
412 case X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD:
413 case X509_V_ERR_CERT_NOT_YET_VALID:
414 case X509_V_ERR_CRL_NOT_YET_VALID:
415 case X509_V_ERR_CERT_UNTRUSTED:
416 case X509_V_ERR_CERT_REJECTED:
417 al = SSL_AD_BAD_CERTIFICATE;
418 break;
419 case X509_V_ERR_CERT_SIGNATURE_FAILURE:
420 case X509_V_ERR_CRL_SIGNATURE_FAILURE:
421 al = SSL_AD_DECRYPT_ERROR;
422 break;
423 case X509_V_ERR_CERT_HAS_EXPIRED:
424 case X509_V_ERR_CRL_HAS_EXPIRED:
425 al = SSL_AD_CERTIFICATE_EXPIRED;
426 break;
427 case X509_V_ERR_CERT_REVOKED:
428 al = SSL_AD_CERTIFICATE_REVOKED;
429 break;
430 case X509_V_ERR_OUT_OF_MEM:
431 al = SSL_AD_INTERNAL_ERROR;
432 break;
433 case X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT:
434 case X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN:
435 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY:
436 case X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE:
437 case X509_V_ERR_CERT_CHAIN_TOO_LONG:
438 case X509_V_ERR_PATH_LENGTH_EXCEEDED:
439 case X509_V_ERR_INVALID_CA:
440 al = SSL_AD_UNKNOWN_CA;
441 break;
442 case X509_V_ERR_APPLICATION_VERIFICATION:
443 al = SSL_AD_HANDSHAKE_FAILURE;
444 break;
445 case X509_V_ERR_INVALID_PURPOSE:
446 al = SSL_AD_UNSUPPORTED_CERTIFICATE;
447 break;
448 default:
449 al = SSL_AD_CERTIFICATE_UNKNOWN;
450 break;
451 }
452 return (al);
453}
454
455int
456ssl3_setup_init_buffer(SSL *s)
457{
458 BUF_MEM *buf = NULL;
459
460 if (s->init_buf != NULL)
461 return (1);
462
463 if ((buf = BUF_MEM_new()) == NULL)
464 goto err;
465 if (!BUF_MEM_grow(buf, SSL3_RT_MAX_PLAIN_LENGTH))
466 goto err;
467
468 s->init_buf = buf;
469 return (1);
470
471 err:
472 BUF_MEM_free(buf);
473 return (0);
474}
475
476void
477ssl3_release_init_buffer(SSL *s)
478{
479 BUF_MEM_free(s->init_buf);
480 s->init_buf = NULL;
481 s->init_msg = NULL;
482 s->init_num = 0;
483 s->init_off = 0;
484}
485
486int
487ssl3_setup_read_buffer(SSL *s)
488{
489 unsigned char *p;
490 size_t len, align, headerlen;
491
492 if (SSL_is_dtls(s))
493 headerlen = DTLS1_RT_HEADER_LENGTH;
494 else
495 headerlen = SSL3_RT_HEADER_LENGTH;
496
497 align = (-SSL3_RT_HEADER_LENGTH) & (SSL3_ALIGN_PAYLOAD - 1);
498
499 if (s->s3->rbuf.buf == NULL) {
500 len = SSL3_RT_MAX_PLAIN_LENGTH +
501 SSL3_RT_MAX_ENCRYPTED_OVERHEAD + headerlen + align;
502 if ((p = calloc(1, len)) == NULL)
503 goto err;
504 s->s3->rbuf.buf = p;
505 s->s3->rbuf.len = len;
506 }
507
508 s->packet = s->s3->rbuf.buf;
509 return 1;
510
511 err:
512 SSLerror(s, ERR_R_MALLOC_FAILURE);
513 return 0;
514}
515
516int
517ssl3_setup_write_buffer(SSL *s)
518{
519 unsigned char *p;
520 size_t len, align, headerlen;
521
522 if (SSL_is_dtls(s))
523 headerlen = DTLS1_RT_HEADER_LENGTH + 1;
524 else
525 headerlen = SSL3_RT_HEADER_LENGTH;
526
527 align = (-SSL3_RT_HEADER_LENGTH) & (SSL3_ALIGN_PAYLOAD - 1);
528
529 if (s->s3->wbuf.buf == NULL) {
530 len = s->max_send_fragment +
531 SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD + headerlen + align;
532 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS))
533 len += headerlen + align +
534 SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD;
535
536 if ((p = calloc(1, len)) == NULL)
537 goto err;
538 s->s3->wbuf.buf = p;
539 s->s3->wbuf.len = len;
540 }
541
542 return 1;
543
544 err:
545 SSLerror(s, ERR_R_MALLOC_FAILURE);
546 return 0;
547}
548
549int
550ssl3_setup_buffers(SSL *s)
551{
552 if (!ssl3_setup_read_buffer(s))
553 return 0;
554 if (!ssl3_setup_write_buffer(s))
555 return 0;
556 return 1;
557}
558
559void
560ssl3_release_buffer(SSL3_BUFFER_INTERNAL *b)
561{
562 freezero(b->buf, b->len);
563 b->buf = NULL;
564 b->len = 0;
565}
566
567void
568ssl3_release_read_buffer(SSL *s)
569{
570 ssl3_release_buffer(&s->s3->rbuf);
571}
572
573void
574ssl3_release_write_buffer(SSL *s)
575{
576 ssl3_release_buffer(&s->s3->wbuf);
577}
diff --git a/src/lib/libssl/ssl_cert.c b/src/lib/libssl/ssl_cert.c
deleted file mode 100644
index 5b2fe1a48d..0000000000
--- a/src/lib/libssl/ssl_cert.c
+++ /dev/null
@@ -1,737 +0,0 @@
1/* $OpenBSD: ssl_cert.c,v 1.108 2024/02/03 15:58:33 beck Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116
117#include <sys/types.h>
118
119#include <dirent.h>
120#include <stdio.h>
121#include <unistd.h>
122
123#include <openssl/bio.h>
124#include <openssl/bn.h>
125#include <openssl/dh.h>
126#include <openssl/objects.h>
127#include <openssl/opensslconf.h>
128#include <openssl/pem.h>
129#include <openssl/x509v3.h>
130
131#include "ssl_local.h"
132
133int
134SSL_get_ex_data_X509_STORE_CTX_idx(void)
135{
136 static volatile int ssl_x509_store_ctx_idx = -1;
137 int got_write_lock = 0;
138
139 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
140
141 if (ssl_x509_store_ctx_idx < 0) {
142 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
143 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
144 got_write_lock = 1;
145
146 if (ssl_x509_store_ctx_idx < 0) {
147 ssl_x509_store_ctx_idx =
148 X509_STORE_CTX_get_ex_new_index(
149 0, "SSL for verify callback", NULL, NULL, NULL);
150 }
151 }
152
153 if (got_write_lock)
154 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
155 else
156 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
157
158 return ssl_x509_store_ctx_idx;
159}
160LSSL_ALIAS(SSL_get_ex_data_X509_STORE_CTX_idx);
161
162SSL_CERT *
163ssl_cert_new(void)
164{
165 SSL_CERT *ret;
166
167 ret = calloc(1, sizeof(SSL_CERT));
168 if (ret == NULL) {
169 SSLerrorx(ERR_R_MALLOC_FAILURE);
170 return (NULL);
171 }
172 ret->key = &(ret->pkeys[SSL_PKEY_RSA]);
173 ret->references = 1;
174 ret->security_cb = ssl_security_default_cb;
175 ret->security_level = OPENSSL_TLS_SECURITY_LEVEL;
176 ret->security_ex_data = NULL;
177 return (ret);
178}
179
180SSL_CERT *
181ssl_cert_dup(SSL_CERT *cert)
182{
183 SSL_CERT *ret;
184 int i;
185
186 ret = calloc(1, sizeof(SSL_CERT));
187 if (ret == NULL) {
188 SSLerrorx(ERR_R_MALLOC_FAILURE);
189 return (NULL);
190 }
191
192 /*
193 * same as ret->key = ret->pkeys + (cert->key - cert->pkeys),
194 * if you find that more readable
195 */
196 ret->key = &ret->pkeys[cert->key - &cert->pkeys[0]];
197
198 ret->valid = cert->valid;
199 ret->mask_k = cert->mask_k;
200 ret->mask_a = cert->mask_a;
201
202 if (cert->dhe_params != NULL) {
203 ret->dhe_params = DHparams_dup(cert->dhe_params);
204 if (ret->dhe_params == NULL) {
205 SSLerrorx(ERR_R_DH_LIB);
206 goto err;
207 }
208 }
209 ret->dhe_params_cb = cert->dhe_params_cb;
210 ret->dhe_params_auto = cert->dhe_params_auto;
211
212 for (i = 0; i < SSL_PKEY_NUM; i++) {
213 if (cert->pkeys[i].x509 != NULL) {
214 ret->pkeys[i].x509 = cert->pkeys[i].x509;
215 X509_up_ref(ret->pkeys[i].x509);
216 }
217
218 if (cert->pkeys[i].privatekey != NULL) {
219 ret->pkeys[i].privatekey = cert->pkeys[i].privatekey;
220 EVP_PKEY_up_ref(ret->pkeys[i].privatekey);
221 switch (i) {
222 /*
223 * If there was anything special to do for
224 * certain types of keys, we'd do it here.
225 * (Nothing at the moment, I think.)
226 */
227
228 case SSL_PKEY_RSA:
229 /* We have an RSA key. */
230 break;
231
232 case SSL_PKEY_ECC:
233 /* We have an ECC key */
234 break;
235
236 default:
237 /* Can't happen. */
238 SSLerrorx(SSL_R_LIBRARY_BUG);
239 }
240 }
241
242 if (cert->pkeys[i].chain != NULL) {
243 if ((ret->pkeys[i].chain =
244 X509_chain_up_ref(cert->pkeys[i].chain)) == NULL)
245 goto err;
246 }
247 }
248
249 ret->security_cb = cert->security_cb;
250 ret->security_level = cert->security_level;
251 ret->security_ex_data = cert->security_ex_data;
252
253 /*
254 * ret->extra_certs *should* exist, but currently the own certificate
255 * chain is held inside SSL_CTX
256 */
257
258 ret->references = 1;
259
260 return (ret);
261
262 err:
263 DH_free(ret->dhe_params);
264
265 for (i = 0; i < SSL_PKEY_NUM; i++) {
266 X509_free(ret->pkeys[i].x509);
267 EVP_PKEY_free(ret->pkeys[i].privatekey);
268 sk_X509_pop_free(ret->pkeys[i].chain, X509_free);
269 }
270 free (ret);
271 return NULL;
272}
273
274
275void
276ssl_cert_free(SSL_CERT *c)
277{
278 int i;
279
280 if (c == NULL)
281 return;
282
283 i = CRYPTO_add(&c->references, -1, CRYPTO_LOCK_SSL_CERT);
284 if (i > 0)
285 return;
286
287 DH_free(c->dhe_params);
288
289 for (i = 0; i < SSL_PKEY_NUM; i++) {
290 X509_free(c->pkeys[i].x509);
291 EVP_PKEY_free(c->pkeys[i].privatekey);
292 sk_X509_pop_free(c->pkeys[i].chain, X509_free);
293 }
294
295 free(c);
296}
297
298SSL_CERT *
299ssl_get0_cert(SSL_CTX *ctx, SSL *ssl)
300{
301 if (ssl != NULL)
302 return ssl->cert;
303
304 return ctx->cert;
305}
306
307int
308ssl_cert_set0_chain(SSL_CTX *ctx, SSL *ssl, STACK_OF(X509) *chain)
309{
310 SSL_CERT *ssl_cert;
311 SSL_CERT_PKEY *cpk;
312 X509 *x509;
313 int ssl_err;
314 int i;
315
316 if ((ssl_cert = ssl_get0_cert(ctx, ssl)) == NULL)
317 return 0;
318
319 if ((cpk = ssl_cert->key) == NULL)
320 return 0;
321
322 for (i = 0; i < sk_X509_num(chain); i++) {
323 x509 = sk_X509_value(chain, i);
324 if (!ssl_security_cert(ctx, ssl, x509, 0, &ssl_err)) {
325 SSLerrorx(ssl_err);
326 return 0;
327 }
328 }
329
330 sk_X509_pop_free(cpk->chain, X509_free);
331 cpk->chain = chain;
332
333 return 1;
334}
335
336int
337ssl_cert_set1_chain(SSL_CTX *ctx, SSL *ssl, STACK_OF(X509) *chain)
338{
339 STACK_OF(X509) *new_chain = NULL;
340
341 if (chain != NULL) {
342 if ((new_chain = X509_chain_up_ref(chain)) == NULL)
343 return 0;
344 }
345 if (!ssl_cert_set0_chain(ctx, ssl, new_chain)) {
346 sk_X509_pop_free(new_chain, X509_free);
347 return 0;
348 }
349
350 return 1;
351}
352
353int
354ssl_cert_add0_chain_cert(SSL_CTX *ctx, SSL *ssl, X509 *cert)
355{
356 SSL_CERT *ssl_cert;
357 SSL_CERT_PKEY *cpk;
358 int ssl_err;
359
360 if ((ssl_cert = ssl_get0_cert(ctx, ssl)) == NULL)
361 return 0;
362
363 if ((cpk = ssl_cert->key) == NULL)
364 return 0;
365
366 if (!ssl_security_cert(ctx, ssl, cert, 0, &ssl_err)) {
367 SSLerrorx(ssl_err);
368 return 0;
369 }
370
371 if (cpk->chain == NULL) {
372 if ((cpk->chain = sk_X509_new_null()) == NULL)
373 return 0;
374 }
375 if (!sk_X509_push(cpk->chain, cert))
376 return 0;
377
378 return 1;
379}
380
381int
382ssl_cert_add1_chain_cert(SSL_CTX *ctx, SSL *ssl, X509 *cert)
383{
384 if (!ssl_cert_add0_chain_cert(ctx, ssl, cert))
385 return 0;
386
387 X509_up_ref(cert);
388
389 return 1;
390}
391
392int
393ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *certs)
394{
395 X509_STORE_CTX *ctx = NULL;
396 X509_VERIFY_PARAM *param;
397 X509 *cert;
398 int ret = 0;
399
400 if (sk_X509_num(certs) < 1)
401 goto err;
402
403 if ((ctx = X509_STORE_CTX_new()) == NULL)
404 goto err;
405
406 cert = sk_X509_value(certs, 0);
407 if (!X509_STORE_CTX_init(ctx, s->ctx->cert_store, cert, certs)) {
408 SSLerror(s, ERR_R_X509_LIB);
409 goto err;
410 }
411 X509_STORE_CTX_set_ex_data(ctx, SSL_get_ex_data_X509_STORE_CTX_idx(), s);
412
413 /*
414 * We need to inherit the verify parameters. These can be
415 * determined by the context: if its a server it will verify
416 * SSL client certificates or vice versa.
417 */
418 X509_STORE_CTX_set_default(ctx, s->server ? "ssl_client" : "ssl_server");
419
420 param = X509_STORE_CTX_get0_param(ctx);
421
422 X509_VERIFY_PARAM_set_auth_level(param, SSL_get_security_level(s));
423
424 /*
425 * Anything non-default in "param" should overwrite anything
426 * in the ctx.
427 */
428 X509_VERIFY_PARAM_set1(param, s->param);
429
430 if (s->verify_callback)
431 X509_STORE_CTX_set_verify_cb(ctx, s->verify_callback);
432
433 if (s->ctx->app_verify_callback != NULL)
434 ret = s->ctx->app_verify_callback(ctx,
435 s->ctx->app_verify_arg);
436 else
437 ret = X509_verify_cert(ctx);
438
439 s->verify_result = X509_STORE_CTX_get_error(ctx);
440 sk_X509_pop_free(s->s3->hs.verified_chain, X509_free);
441 s->s3->hs.verified_chain = NULL;
442 if (X509_STORE_CTX_get0_chain(ctx) != NULL) {
443 s->s3->hs.verified_chain = X509_STORE_CTX_get1_chain(ctx);
444 if (s->s3->hs.verified_chain == NULL) {
445 SSLerrorx(ERR_R_MALLOC_FAILURE);
446 ret = 0;
447 }
448 }
449
450 err:
451 X509_STORE_CTX_free(ctx);
452
453 return (ret);
454}
455
456static void
457set_client_CA_list(STACK_OF(X509_NAME) **ca_list,
458 STACK_OF(X509_NAME) *name_list)
459{
460 sk_X509_NAME_pop_free(*ca_list, X509_NAME_free);
461 *ca_list = name_list;
462}
463
464STACK_OF(X509_NAME) *
465SSL_dup_CA_list(const STACK_OF(X509_NAME) *sk)
466{
467 int i;
468 STACK_OF(X509_NAME) *ret;
469 X509_NAME *name = NULL;
470
471 if ((ret = sk_X509_NAME_new_null()) == NULL)
472 goto err;
473
474 for (i = 0; i < sk_X509_NAME_num(sk); i++) {
475 if ((name = X509_NAME_dup(sk_X509_NAME_value(sk, i))) == NULL)
476 goto err;
477 if (!sk_X509_NAME_push(ret, name))
478 goto err;
479 }
480 return (ret);
481
482 err:
483 X509_NAME_free(name);
484 sk_X509_NAME_pop_free(ret, X509_NAME_free);
485 return NULL;
486}
487LSSL_ALIAS(SSL_dup_CA_list);
488
489void
490SSL_set_client_CA_list(SSL *s, STACK_OF(X509_NAME) *name_list)
491{
492 set_client_CA_list(&(s->client_CA), name_list);
493}
494LSSL_ALIAS(SSL_set_client_CA_list);
495
496void
497SSL_CTX_set_client_CA_list(SSL_CTX *ctx, STACK_OF(X509_NAME) *name_list)
498{
499 set_client_CA_list(&(ctx->client_CA), name_list);
500}
501LSSL_ALIAS(SSL_CTX_set_client_CA_list);
502
503STACK_OF(X509_NAME) *
504SSL_CTX_get_client_CA_list(const SSL_CTX *ctx)
505{
506 return (ctx->client_CA);
507}
508LSSL_ALIAS(SSL_CTX_get_client_CA_list);
509
510STACK_OF(X509_NAME) *
511SSL_get_client_CA_list(const SSL *s)
512{
513 if (!s->server) {
514 /* We are in the client. */
515 if ((s->version >> 8) == SSL3_VERSION_MAJOR)
516 return (s->s3->hs.tls12.ca_names);
517 else
518 return (NULL);
519 } else {
520 if (s->client_CA != NULL)
521 return (s->client_CA);
522 else
523 return (s->ctx->client_CA);
524 }
525}
526LSSL_ALIAS(SSL_get_client_CA_list);
527
528static int
529add_client_CA(STACK_OF(X509_NAME) **sk, X509 *x)
530{
531 X509_NAME *name;
532
533 if (x == NULL)
534 return (0);
535 if ((*sk == NULL) && ((*sk = sk_X509_NAME_new_null()) == NULL))
536 return (0);
537
538 if ((name = X509_NAME_dup(X509_get_subject_name(x))) == NULL)
539 return (0);
540
541 if (!sk_X509_NAME_push(*sk, name)) {
542 X509_NAME_free(name);
543 return (0);
544 }
545 return (1);
546}
547
548int
549SSL_add_client_CA(SSL *ssl, X509 *x)
550{
551 return (add_client_CA(&(ssl->client_CA), x));
552}
553LSSL_ALIAS(SSL_add_client_CA);
554
555int
556SSL_CTX_add_client_CA(SSL_CTX *ctx, X509 *x)
557{
558 return (add_client_CA(&(ctx->client_CA), x));
559}
560LSSL_ALIAS(SSL_CTX_add_client_CA);
561
562static int
563xname_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
564{
565 return (X509_NAME_cmp(*a, *b));
566}
567
568/*!
569 * Load CA certs from a file into a ::STACK. Note that it is somewhat misnamed;
570 * it doesn't really have anything to do with clients (except that a common use
571 * for a stack of CAs is to send it to the client). Actually, it doesn't have
572 * much to do with CAs, either, since it will load any old cert.
573 * \param file the file containing one or more certs.
574 * \return a ::STACK containing the certs.
575 */
576STACK_OF(X509_NAME) *
577SSL_load_client_CA_file(const char *file)
578{
579 BIO *in;
580 X509 *x = NULL;
581 X509_NAME *xn = NULL;
582 STACK_OF(X509_NAME) *ret = NULL, *sk;
583
584 sk = sk_X509_NAME_new(xname_cmp);
585
586 in = BIO_new(BIO_s_file());
587
588 if ((sk == NULL) || (in == NULL)) {
589 SSLerrorx(ERR_R_MALLOC_FAILURE);
590 goto err;
591 }
592
593 if (!BIO_read_filename(in, file))
594 goto err;
595
596 for (;;) {
597 if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL)
598 break;
599 if (ret == NULL) {
600 ret = sk_X509_NAME_new_null();
601 if (ret == NULL) {
602 SSLerrorx(ERR_R_MALLOC_FAILURE);
603 goto err;
604 }
605 }
606 if ((xn = X509_get_subject_name(x)) == NULL)
607 goto err;
608 /* check for duplicates */
609 xn = X509_NAME_dup(xn);
610 if (xn == NULL)
611 goto err;
612 if (sk_X509_NAME_find(sk, xn) >= 0)
613 X509_NAME_free(xn);
614 else {
615 if (!sk_X509_NAME_push(sk, xn))
616 goto err;
617 if (!sk_X509_NAME_push(ret, xn))
618 goto err;
619 }
620 }
621
622 if (0) {
623 err:
624 sk_X509_NAME_pop_free(ret, X509_NAME_free);
625 ret = NULL;
626 }
627 sk_X509_NAME_free(sk);
628 BIO_free(in);
629 X509_free(x);
630 if (ret != NULL)
631 ERR_clear_error();
632
633 return (ret);
634}
635LSSL_ALIAS(SSL_load_client_CA_file);
636
637/*!
638 * Add a file of certs to a stack.
639 * \param stack the stack to add to.
640 * \param file the file to add from. All certs in this file that are not
641 * already in the stack will be added.
642 * \return 1 for success, 0 for failure. Note that in the case of failure some
643 * certs may have been added to \c stack.
644 */
645
646int
647SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
648 const char *file)
649{
650 BIO *in;
651 X509 *x = NULL;
652 X509_NAME *xn = NULL;
653 int ret = 1;
654 int (*oldcmp)(const X509_NAME * const *a, const X509_NAME * const *b);
655
656 oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_cmp);
657
658 in = BIO_new(BIO_s_file());
659
660 if (in == NULL) {
661 SSLerrorx(ERR_R_MALLOC_FAILURE);
662 goto err;
663 }
664
665 if (!BIO_read_filename(in, file))
666 goto err;
667
668 for (;;) {
669 if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL)
670 break;
671 if ((xn = X509_get_subject_name(x)) == NULL)
672 goto err;
673 xn = X509_NAME_dup(xn);
674 if (xn == NULL)
675 goto err;
676 if (sk_X509_NAME_find(stack, xn) >= 0)
677 X509_NAME_free(xn);
678 else
679 if (!sk_X509_NAME_push(stack, xn))
680 goto err;
681 }
682
683 ERR_clear_error();
684
685 if (0) {
686 err:
687 ret = 0;
688 }
689 BIO_free(in);
690 X509_free(x);
691
692 (void)sk_X509_NAME_set_cmp_func(stack, oldcmp);
693
694 return ret;
695}
696LSSL_ALIAS(SSL_add_file_cert_subjects_to_stack);
697
698/*!
699 * Add a directory of certs to a stack.
700 * \param stack the stack to append to.
701 * \param dir the directory to append from. All files in this directory will be
702 * examined as potential certs. Any that are acceptable to
703 * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will
704 * be included.
705 * \return 1 for success, 0 for failure. Note that in the case of failure some
706 * certs may have been added to \c stack.
707 */
708
709int
710SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack, const char *dir)
711{
712 DIR *dirp = NULL;
713 char *path = NULL;
714 int ret = 0;
715
716 dirp = opendir(dir);
717 if (dirp) {
718 struct dirent *dp;
719 while ((dp = readdir(dirp)) != NULL) {
720 if (asprintf(&path, "%s/%s", dir, dp->d_name) != -1) {
721 ret = SSL_add_file_cert_subjects_to_stack(
722 stack, path);
723 free(path);
724 }
725 if (!ret)
726 break;
727 }
728 (void) closedir(dirp);
729 }
730 if (!ret) {
731 SYSerror(errno);
732 ERR_asprintf_error_data("opendir ('%s')", dir);
733 SSLerrorx(ERR_R_SYS_LIB);
734 }
735 return ret;
736}
737LSSL_ALIAS(SSL_add_dir_cert_subjects_to_stack);
diff --git a/src/lib/libssl/ssl_ciph.c b/src/lib/libssl/ssl_ciph.c
deleted file mode 100644
index 7d84e42cfe..0000000000
--- a/src/lib/libssl/ssl_ciph.c
+++ /dev/null
@@ -1,1631 +0,0 @@
1/* $OpenBSD: ssl_ciph.c,v 1.151 2025/01/18 12:20:37 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#include <stdio.h>
144
145#include <openssl/evp.h>
146#include <openssl/objects.h>
147#include <openssl/opensslconf.h>
148
149#include "ssl_local.h"
150
151#define CIPHER_ADD 1
152#define CIPHER_KILL 2
153#define CIPHER_DEL 3
154#define CIPHER_ORD 4
155#define CIPHER_SPECIAL 5
156
157typedef struct cipher_order_st {
158 const SSL_CIPHER *cipher;
159 int active;
160 int dead;
161 struct cipher_order_st *next, *prev;
162} CIPHER_ORDER;
163
164static const SSL_CIPHER cipher_aliases[] = {
165
166 /* "ALL" doesn't include eNULL (must be specifically enabled) */
167 {
168 .name = SSL_TXT_ALL,
169 .algorithm_enc = ~SSL_eNULL,
170 },
171
172 /* "COMPLEMENTOFALL" */
173 {
174 .name = SSL_TXT_CMPALL,
175 .algorithm_enc = SSL_eNULL,
176 },
177
178 /*
179 * "COMPLEMENTOFDEFAULT"
180 * (does *not* include ciphersuites not found in ALL!)
181 */
182 {
183 .name = SSL_TXT_CMPDEF,
184 .algorithm_mkey = SSL_kDHE|SSL_kECDHE,
185 .algorithm_auth = SSL_aNULL,
186 .algorithm_enc = ~SSL_eNULL,
187 },
188
189 /*
190 * key exchange aliases
191 * (some of those using only a single bit here combine multiple key
192 * exchange algs according to the RFCs, e.g. kEDH combines DHE_DSS
193 * and DHE_RSA)
194 */
195 {
196 .name = SSL_TXT_kRSA,
197 .algorithm_mkey = SSL_kRSA,
198 },
199 {
200 .name = SSL_TXT_kEDH,
201 .algorithm_mkey = SSL_kDHE,
202 },
203 {
204 .name = SSL_TXT_DH,
205 .algorithm_mkey = SSL_kDHE,
206 },
207 {
208 .name = SSL_TXT_kEECDH,
209 .algorithm_mkey = SSL_kECDHE,
210 },
211 {
212 .name = SSL_TXT_ECDH,
213 .algorithm_mkey = SSL_kECDHE,
214 },
215
216 /* server authentication aliases */
217 {
218 .name = SSL_TXT_aRSA,
219 .algorithm_auth = SSL_aRSA,
220 },
221 {
222 .name = SSL_TXT_aNULL,
223 .algorithm_auth = SSL_aNULL,
224 },
225 {
226 .name = SSL_TXT_aECDSA,
227 .algorithm_auth = SSL_aECDSA,
228 },
229 {
230 .name = SSL_TXT_ECDSA,
231 .algorithm_auth = SSL_aECDSA,
232 },
233
234 /* aliases combining key exchange and server authentication */
235 {
236 .name = SSL_TXT_DHE,
237 .algorithm_mkey = SSL_kDHE,
238 .algorithm_auth = ~SSL_aNULL,
239 },
240 {
241 .name = SSL_TXT_EDH,
242 .algorithm_mkey = SSL_kDHE,
243 .algorithm_auth = ~SSL_aNULL,
244 },
245 {
246 .name = SSL_TXT_ECDHE,
247 .algorithm_mkey = SSL_kECDHE,
248 .algorithm_auth = ~SSL_aNULL,
249 },
250 {
251 .name = SSL_TXT_EECDH,
252 .algorithm_mkey = SSL_kECDHE,
253 .algorithm_auth = ~SSL_aNULL,
254 },
255 {
256 .name = SSL_TXT_NULL,
257 .algorithm_enc = SSL_eNULL,
258 },
259 {
260 .name = SSL_TXT_RSA,
261 .algorithm_mkey = SSL_kRSA,
262 .algorithm_auth = SSL_aRSA,
263 },
264 {
265 .name = SSL_TXT_ADH,
266 .algorithm_mkey = SSL_kDHE,
267 .algorithm_auth = SSL_aNULL,
268 },
269 {
270 .name = SSL_TXT_AECDH,
271 .algorithm_mkey = SSL_kECDHE,
272 .algorithm_auth = SSL_aNULL,
273 },
274
275 /* symmetric encryption aliases */
276 {
277 .name = SSL_TXT_3DES,
278 .algorithm_enc = SSL_3DES,
279 },
280 {
281 .name = SSL_TXT_RC4,
282 .algorithm_enc = SSL_RC4,
283 },
284 {
285 .name = SSL_TXT_eNULL,
286 .algorithm_enc = SSL_eNULL,
287 },
288 {
289 .name = SSL_TXT_AES128,
290 .algorithm_enc = SSL_AES128|SSL_AES128GCM,
291 },
292 {
293 .name = SSL_TXT_AES256,
294 .algorithm_enc = SSL_AES256|SSL_AES256GCM,
295 },
296 {
297 .name = SSL_TXT_AES,
298 .algorithm_enc = SSL_AES,
299 },
300 {
301 .name = SSL_TXT_AES_GCM,
302 .algorithm_enc = SSL_AES128GCM|SSL_AES256GCM,
303 },
304 {
305 .name = SSL_TXT_CAMELLIA128,
306 .algorithm_enc = SSL_CAMELLIA128,
307 },
308 {
309 .name = SSL_TXT_CAMELLIA256,
310 .algorithm_enc = SSL_CAMELLIA256,
311 },
312 {
313 .name = SSL_TXT_CAMELLIA,
314 .algorithm_enc = SSL_CAMELLIA128|SSL_CAMELLIA256,
315 },
316 {
317 .name = SSL_TXT_CHACHA20,
318 .algorithm_enc = SSL_CHACHA20POLY1305,
319 },
320
321 /* MAC aliases */
322 {
323 .name = SSL_TXT_AEAD,
324 .algorithm_mac = SSL_AEAD,
325 },
326 {
327 .name = SSL_TXT_MD5,
328 .algorithm_mac = SSL_MD5,
329 },
330 {
331 .name = SSL_TXT_SHA1,
332 .algorithm_mac = SSL_SHA1,
333 },
334 {
335 .name = SSL_TXT_SHA,
336 .algorithm_mac = SSL_SHA1,
337 },
338 {
339 .name = SSL_TXT_SHA256,
340 .algorithm_mac = SSL_SHA256,
341 },
342 {
343 .name = SSL_TXT_SHA384,
344 .algorithm_mac = SSL_SHA384,
345 },
346
347 /* protocol version aliases */
348 {
349 .name = SSL_TXT_SSLV3,
350 .algorithm_ssl = SSL_SSLV3,
351 },
352 {
353 .name = SSL_TXT_TLSV1,
354 .algorithm_ssl = SSL_TLSV1,
355 },
356 {
357 .name = SSL_TXT_TLSV1_2,
358 .algorithm_ssl = SSL_TLSV1_2,
359 },
360 {
361 .name = SSL_TXT_TLSV1_3,
362 .algorithm_ssl = SSL_TLSV1_3,
363 },
364
365 /* cipher suite aliases */
366#ifdef LIBRESSL_HAS_TLS1_3
367 {
368 .value = 0x1301,
369 .name = "TLS_AES_128_GCM_SHA256",
370 .algorithm_ssl = SSL_TLSV1_3,
371 },
372 {
373 .value = 0x1302,
374 .name = "TLS_AES_256_GCM_SHA384",
375 .algorithm_ssl = SSL_TLSV1_3,
376 },
377 {
378 .value = 0x1303,
379 .name = "TLS_CHACHA20_POLY1305_SHA256",
380 .algorithm_ssl = SSL_TLSV1_3,
381 },
382#endif
383
384 /* strength classes */
385 {
386 .name = SSL_TXT_LOW,
387 .algo_strength = SSL_LOW,
388 },
389 {
390 .name = SSL_TXT_MEDIUM,
391 .algo_strength = SSL_MEDIUM,
392 },
393 {
394 .name = SSL_TXT_HIGH,
395 .algo_strength = SSL_HIGH,
396 },
397};
398
399int
400ssl_cipher_get_evp(SSL *s, const EVP_CIPHER **enc, const EVP_MD **md,
401 int *mac_pkey_type, int *mac_secret_size)
402{
403 const SSL_CIPHER *cipher;
404
405 *enc = NULL;
406 *md = NULL;
407 *mac_pkey_type = NID_undef;
408 *mac_secret_size = 0;
409
410 if ((cipher = s->s3->hs.cipher) == NULL)
411 return 0;
412
413 /*
414 * This function does not handle EVP_AEAD.
415 * See ssl_cipher_get_evp_aead instead.
416 */
417 if (cipher->algorithm_mac & SSL_AEAD)
418 return 0;
419
420 switch (cipher->algorithm_enc) {
421 case SSL_3DES:
422 *enc = EVP_des_ede3_cbc();
423 break;
424 case SSL_RC4:
425 *enc = EVP_rc4();
426 break;
427 case SSL_eNULL:
428 *enc = EVP_enc_null();
429 break;
430 case SSL_AES128:
431 *enc = EVP_aes_128_cbc();
432 break;
433 case SSL_AES256:
434 *enc = EVP_aes_256_cbc();
435 break;
436 case SSL_CAMELLIA128:
437 *enc = EVP_camellia_128_cbc();
438 break;
439 case SSL_CAMELLIA256:
440 *enc = EVP_camellia_256_cbc();
441 break;
442 }
443
444 switch (cipher->algorithm_mac) {
445 case SSL_MD5:
446 *md = EVP_md5();
447 break;
448 case SSL_SHA1:
449 *md = EVP_sha1();
450 break;
451 case SSL_SHA256:
452 *md = EVP_sha256();
453 break;
454 case SSL_SHA384:
455 *md = EVP_sha384();
456 break;
457 }
458 if (*enc == NULL || *md == NULL)
459 return 0;
460
461 /* XXX remove these from ssl_cipher_get_evp? */
462 /*
463 * EVP_CIPH_FLAG_AEAD_CIPHER and EVP_CIPH_GCM_MODE ciphers are not
464 * supported via EVP_CIPHER (they should be using EVP_AEAD instead).
465 */
466 if (EVP_CIPHER_flags(*enc) & EVP_CIPH_FLAG_AEAD_CIPHER)
467 return 0;
468 if (EVP_CIPHER_mode(*enc) == EVP_CIPH_GCM_MODE)
469 return 0;
470
471 *mac_pkey_type = EVP_PKEY_HMAC;
472 *mac_secret_size = EVP_MD_size(*md);
473 return 1;
474}
475
476/*
477 * ssl_cipher_get_evp_aead sets aead to point to the correct EVP_AEAD object
478 * for s->cipher. It returns 1 on success and 0 on error.
479 */
480int
481ssl_cipher_get_evp_aead(SSL *s, const EVP_AEAD **aead)
482{
483 const SSL_CIPHER *cipher;
484
485 *aead = NULL;
486
487 if ((cipher = s->s3->hs.cipher) == NULL)
488 return 0;
489 if ((cipher->algorithm_mac & SSL_AEAD) == 0)
490 return 0;
491
492 switch (cipher->algorithm_enc) {
493 case SSL_AES128GCM:
494 *aead = EVP_aead_aes_128_gcm();
495 return 1;
496 case SSL_AES256GCM:
497 *aead = EVP_aead_aes_256_gcm();
498 return 1;
499 case SSL_CHACHA20POLY1305:
500 *aead = EVP_aead_chacha20_poly1305();
501 return 1;
502 default:
503 break;
504 }
505 return 0;
506}
507
508int
509ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md)
510{
511 const SSL_CIPHER *cipher;
512
513 *md = NULL;
514
515 if ((cipher = s->s3->hs.cipher) == NULL)
516 return 0;
517
518 switch (cipher->algorithm2 & SSL_HANDSHAKE_MAC_MASK) {
519 case SSL_HANDSHAKE_MAC_SHA256:
520 *md = EVP_sha256();
521 return 1;
522 case SSL_HANDSHAKE_MAC_SHA384:
523 *md = EVP_sha384();
524 return 1;
525 default:
526 break;
527 }
528
529 return 0;
530}
531
532#define ITEM_SEP(a) \
533 (((a) == ':') || ((a) == ' ') || ((a) == ';') || ((a) == ','))
534
535static void
536ll_append_tail(CIPHER_ORDER **head, CIPHER_ORDER *curr,
537 CIPHER_ORDER **tail)
538{
539 if (curr == *tail)
540 return;
541 if (curr == *head)
542 *head = curr->next;
543 if (curr->prev != NULL)
544 curr->prev->next = curr->next;
545 if (curr->next != NULL)
546 curr->next->prev = curr->prev;
547 (*tail)->next = curr;
548 curr->prev= *tail;
549 curr->next = NULL;
550 *tail = curr;
551}
552
553static void
554ll_append_head(CIPHER_ORDER **head, CIPHER_ORDER *curr,
555 CIPHER_ORDER **tail)
556{
557 if (curr == *head)
558 return;
559 if (curr == *tail)
560 *tail = curr->prev;
561 if (curr->next != NULL)
562 curr->next->prev = curr->prev;
563 if (curr->prev != NULL)
564 curr->prev->next = curr->next;
565 (*head)->prev = curr;
566 curr->next= *head;
567 curr->prev = NULL;
568 *head = curr;
569}
570
571static void
572ssl_cipher_collect_ciphers(const SSL_METHOD *ssl_method, int num_of_ciphers,
573 unsigned long disabled_mkey, unsigned long disabled_auth,
574 unsigned long disabled_enc, unsigned long disabled_mac,
575 unsigned long disabled_ssl, CIPHER_ORDER *co_list,
576 CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
577{
578 int i, co_list_num;
579 const SSL_CIPHER *c;
580
581 /*
582 * We have num_of_ciphers descriptions compiled in, depending on the
583 * method selected (SSLv3, TLSv1, etc). These will later be sorted in
584 * a linked list with at most num entries.
585 */
586
587 /*
588 * Get the initial list of ciphers, iterating backwards over the
589 * cipher list - the list is ordered by cipher value and we currently
590 * hope that ciphers with higher cipher values are preferable...
591 */
592 co_list_num = 0; /* actual count of ciphers */
593 for (i = num_of_ciphers - 1; i >= 0; i--) {
594 c = ssl3_get_cipher_by_index(i);
595
596 /*
597 * Drop any invalid ciphers and any which use unavailable
598 * algorithms.
599 */
600 if ((c != NULL) &&
601 !(c->algorithm_mkey & disabled_mkey) &&
602 !(c->algorithm_auth & disabled_auth) &&
603 !(c->algorithm_enc & disabled_enc) &&
604 !(c->algorithm_mac & disabled_mac) &&
605 !(c->algorithm_ssl & disabled_ssl)) {
606 co_list[co_list_num].cipher = c;
607 co_list[co_list_num].next = NULL;
608 co_list[co_list_num].prev = NULL;
609 co_list[co_list_num].active = 0;
610 co_list_num++;
611 }
612 }
613
614 /*
615 * Prepare linked list from list entries
616 */
617 if (co_list_num > 0) {
618 co_list[0].prev = NULL;
619
620 if (co_list_num > 1) {
621 co_list[0].next = &co_list[1];
622
623 for (i = 1; i < co_list_num - 1; i++) {
624 co_list[i].prev = &co_list[i - 1];
625 co_list[i].next = &co_list[i + 1];
626 }
627
628 co_list[co_list_num - 1].prev =
629 &co_list[co_list_num - 2];
630 }
631
632 co_list[co_list_num - 1].next = NULL;
633
634 *head_p = &co_list[0];
635 *tail_p = &co_list[co_list_num - 1];
636 }
637}
638
639static void
640ssl_cipher_collect_aliases(const SSL_CIPHER **ca_list, int num_of_group_aliases,
641 unsigned long disabled_mkey, unsigned long disabled_auth,
642 unsigned long disabled_enc, unsigned long disabled_mac,
643 unsigned long disabled_ssl, CIPHER_ORDER *head)
644{
645 CIPHER_ORDER *ciph_curr;
646 const SSL_CIPHER **ca_curr;
647 int i;
648 unsigned long mask_mkey = ~disabled_mkey;
649 unsigned long mask_auth = ~disabled_auth;
650 unsigned long mask_enc = ~disabled_enc;
651 unsigned long mask_mac = ~disabled_mac;
652 unsigned long mask_ssl = ~disabled_ssl;
653
654 /*
655 * First, add the real ciphers as already collected
656 */
657 ciph_curr = head;
658 ca_curr = ca_list;
659 while (ciph_curr != NULL) {
660 *ca_curr = ciph_curr->cipher;
661 ca_curr++;
662 ciph_curr = ciph_curr->next;
663 }
664
665 /*
666 * Now we add the available ones from the cipher_aliases[] table.
667 * They represent either one or more algorithms, some of which
668 * in any affected category must be supported (set in enabled_mask),
669 * or represent a cipher strength value (will be added in any case because algorithms=0).
670 */
671 for (i = 0; i < num_of_group_aliases; i++) {
672 unsigned long algorithm_mkey = cipher_aliases[i].algorithm_mkey;
673 unsigned long algorithm_auth = cipher_aliases[i].algorithm_auth;
674 unsigned long algorithm_enc = cipher_aliases[i].algorithm_enc;
675 unsigned long algorithm_mac = cipher_aliases[i].algorithm_mac;
676 unsigned long algorithm_ssl = cipher_aliases[i].algorithm_ssl;
677
678 if (algorithm_mkey)
679 if ((algorithm_mkey & mask_mkey) == 0)
680 continue;
681
682 if (algorithm_auth)
683 if ((algorithm_auth & mask_auth) == 0)
684 continue;
685
686 if (algorithm_enc)
687 if ((algorithm_enc & mask_enc) == 0)
688 continue;
689
690 if (algorithm_mac)
691 if ((algorithm_mac & mask_mac) == 0)
692 continue;
693
694 if (algorithm_ssl)
695 if ((algorithm_ssl & mask_ssl) == 0)
696 continue;
697
698 *ca_curr = (SSL_CIPHER *)(cipher_aliases + i);
699 ca_curr++;
700 }
701
702 *ca_curr = NULL; /* end of list */
703}
704
705static void
706ssl_cipher_apply_rule(uint16_t cipher_value, unsigned long alg_mkey,
707 unsigned long alg_auth, unsigned long alg_enc, unsigned long alg_mac,
708 unsigned long alg_ssl, unsigned long algo_strength, int rule,
709 int strength_bits, CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
710{
711 CIPHER_ORDER *head, *tail, *curr, *next, *last;
712 const SSL_CIPHER *cp;
713 int reverse = 0;
714
715 if (rule == CIPHER_DEL)
716 reverse = 1; /* needed to maintain sorting between currently deleted ciphers */
717
718 head = *head_p;
719 tail = *tail_p;
720
721 if (reverse) {
722 next = tail;
723 last = head;
724 } else {
725 next = head;
726 last = tail;
727 }
728
729 curr = NULL;
730 for (;;) {
731 if (curr == last)
732 break;
733 curr = next;
734 next = reverse ? curr->prev : curr->next;
735
736 cp = curr->cipher;
737
738 if (cipher_value != 0 && cp->value != cipher_value)
739 continue;
740
741 /*
742 * Selection criteria is either the value of strength_bits
743 * or the algorithms used.
744 */
745 if (strength_bits >= 0) {
746 if (strength_bits != cp->strength_bits)
747 continue;
748 } else {
749 if (alg_mkey && !(alg_mkey & cp->algorithm_mkey))
750 continue;
751 if (alg_auth && !(alg_auth & cp->algorithm_auth))
752 continue;
753 if (alg_enc && !(alg_enc & cp->algorithm_enc))
754 continue;
755 if (alg_mac && !(alg_mac & cp->algorithm_mac))
756 continue;
757 if (alg_ssl && !(alg_ssl & cp->algorithm_ssl))
758 continue;
759 if ((algo_strength & SSL_STRONG_MASK) && !(algo_strength & SSL_STRONG_MASK & cp->algo_strength))
760 continue;
761 }
762
763 /* add the cipher if it has not been added yet. */
764 if (rule == CIPHER_ADD) {
765 /* reverse == 0 */
766 if (!curr->active) {
767 ll_append_tail(&head, curr, &tail);
768 curr->active = 1;
769 }
770 }
771 /* Move the added cipher to this location */
772 else if (rule == CIPHER_ORD) {
773 /* reverse == 0 */
774 if (curr->active) {
775 ll_append_tail(&head, curr, &tail);
776 }
777 } else if (rule == CIPHER_DEL) {
778 /* reverse == 1 */
779 if (curr->active) {
780 /* most recently deleted ciphersuites get best positions
781 * for any future CIPHER_ADD (note that the CIPHER_DEL loop
782 * works in reverse to maintain the order) */
783 ll_append_head(&head, curr, &tail);
784 curr->active = 0;
785 }
786 } else if (rule == CIPHER_KILL) {
787 /* reverse == 0 */
788 if (head == curr)
789 head = curr->next;
790 else
791 curr->prev->next = curr->next;
792 if (tail == curr)
793 tail = curr->prev;
794 curr->active = 0;
795 if (curr->next != NULL)
796 curr->next->prev = curr->prev;
797 if (curr->prev != NULL)
798 curr->prev->next = curr->next;
799 curr->next = NULL;
800 curr->prev = NULL;
801 }
802 }
803
804 *head_p = head;
805 *tail_p = tail;
806}
807
808static int
809ssl_cipher_strength_sort(CIPHER_ORDER **head_p, CIPHER_ORDER **tail_p)
810{
811 int max_strength_bits, i, *number_uses;
812 CIPHER_ORDER *curr;
813
814 /*
815 * This routine sorts the ciphers with descending strength. The sorting
816 * must keep the pre-sorted sequence, so we apply the normal sorting
817 * routine as '+' movement to the end of the list.
818 */
819 max_strength_bits = 0;
820 curr = *head_p;
821 while (curr != NULL) {
822 if (curr->active &&
823 (curr->cipher->strength_bits > max_strength_bits))
824 max_strength_bits = curr->cipher->strength_bits;
825 curr = curr->next;
826 }
827
828 number_uses = calloc((max_strength_bits + 1), sizeof(int));
829 if (!number_uses) {
830 SSLerrorx(ERR_R_MALLOC_FAILURE);
831 return (0);
832 }
833
834 /*
835 * Now find the strength_bits values actually used
836 */
837 curr = *head_p;
838 while (curr != NULL) {
839 if (curr->active)
840 number_uses[curr->cipher->strength_bits]++;
841 curr = curr->next;
842 }
843 /*
844 * Go through the list of used strength_bits values in descending
845 * order.
846 */
847 for (i = max_strength_bits; i >= 0; i--)
848 if (number_uses[i] > 0)
849 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ORD, i, head_p, tail_p);
850
851 free(number_uses);
852 return (1);
853}
854
855static int
856ssl_cipher_process_rulestr(const char *rule_str, CIPHER_ORDER **head_p,
857 CIPHER_ORDER **tail_p, const SSL_CIPHER **ca_list, SSL_CERT *cert,
858 int *tls13_seen)
859{
860 unsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl;
861 unsigned long algo_strength;
862 int j, multi, found, rule, retval, ok, buflen;
863 uint16_t cipher_value = 0;
864 const char *l, *buf;
865 char ch;
866
867 *tls13_seen = 0;
868
869 retval = 1;
870 l = rule_str;
871 for (;;) {
872 ch = *l;
873
874 if (ch == '\0')
875 break;
876
877 if (ch == '-') {
878 rule = CIPHER_DEL;
879 l++;
880 } else if (ch == '+') {
881 rule = CIPHER_ORD;
882 l++;
883 } else if (ch == '!') {
884 rule = CIPHER_KILL;
885 l++;
886 } else if (ch == '@') {
887 rule = CIPHER_SPECIAL;
888 l++;
889 } else {
890 rule = CIPHER_ADD;
891 }
892
893 if (ITEM_SEP(ch)) {
894 l++;
895 continue;
896 }
897
898 alg_mkey = 0;
899 alg_auth = 0;
900 alg_enc = 0;
901 alg_mac = 0;
902 alg_ssl = 0;
903 algo_strength = 0;
904
905 for (;;) {
906 ch = *l;
907 buf = l;
908 buflen = 0;
909 while (((ch >= 'A') && (ch <= 'Z')) ||
910 ((ch >= '0') && (ch <= '9')) ||
911 ((ch >= 'a') && (ch <= 'z')) ||
912 (ch == '-') || (ch == '.') ||
913 (ch == '_') || (ch == '=')) {
914 ch = *(++l);
915 buflen++;
916 }
917
918 if (buflen == 0) {
919 /*
920 * We hit something we cannot deal with,
921 * it is no command or separator nor
922 * alphanumeric, so we call this an error.
923 */
924 SSLerrorx(SSL_R_INVALID_COMMAND);
925 return 0;
926 }
927
928 if (rule == CIPHER_SPECIAL) {
929 /* unused -- avoid compiler warning */
930 found = 0;
931 /* special treatment */
932 break;
933 }
934
935 /* check for multi-part specification */
936 if (ch == '+') {
937 multi = 1;
938 l++;
939 } else
940 multi = 0;
941
942 /*
943 * Now search for the cipher alias in the ca_list.
944 * Be careful with the strncmp, because the "buflen"
945 * limitation will make the rule "ADH:SOME" and the
946 * cipher "ADH-MY-CIPHER" look like a match for
947 * buflen=3. So additionally check whether the cipher
948 * name found has the correct length. We can save a
949 * strlen() call: just checking for the '\0' at the
950 * right place is sufficient, we have to strncmp()
951 * anyway (we cannot use strcmp(), because buf is not
952 * '\0' terminated.)
953 */
954 j = found = 0;
955 cipher_value = 0;
956 while (ca_list[j]) {
957 if (!strncmp(buf, ca_list[j]->name, buflen) &&
958 (ca_list[j]->name[buflen] == '\0')) {
959 found = 1;
960 break;
961 } else
962 j++;
963 }
964
965 if (!found)
966 break; /* ignore this entry */
967
968 if (ca_list[j]->algorithm_mkey) {
969 if (alg_mkey) {
970 alg_mkey &= ca_list[j]->algorithm_mkey;
971 if (!alg_mkey) {
972 found = 0;
973 break;
974 }
975 } else
976 alg_mkey = ca_list[j]->algorithm_mkey;
977 }
978
979 if (ca_list[j]->algorithm_auth) {
980 if (alg_auth) {
981 alg_auth &= ca_list[j]->algorithm_auth;
982 if (!alg_auth) {
983 found = 0;
984 break;
985 }
986 } else
987 alg_auth = ca_list[j]->algorithm_auth;
988 }
989
990 if (ca_list[j]->algorithm_enc) {
991 if (alg_enc) {
992 alg_enc &= ca_list[j]->algorithm_enc;
993 if (!alg_enc) {
994 found = 0;
995 break;
996 }
997 } else
998 alg_enc = ca_list[j]->algorithm_enc;
999 }
1000
1001 if (ca_list[j]->algorithm_mac) {
1002 if (alg_mac) {
1003 alg_mac &= ca_list[j]->algorithm_mac;
1004 if (!alg_mac) {
1005 found = 0;
1006 break;
1007 }
1008 } else
1009 alg_mac = ca_list[j]->algorithm_mac;
1010 }
1011
1012 if (ca_list[j]->algo_strength & SSL_STRONG_MASK) {
1013 if (algo_strength & SSL_STRONG_MASK) {
1014 algo_strength &=
1015 (ca_list[j]->algo_strength &
1016 SSL_STRONG_MASK) | ~SSL_STRONG_MASK;
1017 if (!(algo_strength &
1018 SSL_STRONG_MASK)) {
1019 found = 0;
1020 break;
1021 }
1022 } else
1023 algo_strength |=
1024 ca_list[j]->algo_strength &
1025 SSL_STRONG_MASK;
1026 }
1027
1028 if (ca_list[j]->value != 0) {
1029 /*
1030 * explicit ciphersuite found; its protocol
1031 * version does not become part of the search
1032 * pattern!
1033 */
1034 cipher_value = ca_list[j]->value;
1035 if (ca_list[j]->algorithm_ssl == SSL_TLSV1_3)
1036 *tls13_seen = 1;
1037 } else {
1038 /*
1039 * not an explicit ciphersuite; only in this
1040 * case, the protocol version is considered
1041 * part of the search pattern
1042 */
1043 if (ca_list[j]->algorithm_ssl) {
1044 if (alg_ssl) {
1045 alg_ssl &=
1046 ca_list[j]->algorithm_ssl;
1047 if (!alg_ssl) {
1048 found = 0;
1049 break;
1050 }
1051 } else
1052 alg_ssl =
1053 ca_list[j]->algorithm_ssl;
1054 }
1055 }
1056
1057 if (!multi)
1058 break;
1059 }
1060
1061 /*
1062 * Ok, we have the rule, now apply it
1063 */
1064 if (rule == CIPHER_SPECIAL) {
1065 /* special command */
1066 ok = 0;
1067 if (buflen == 8 && strncmp(buf, "STRENGTH", 8) == 0) {
1068 ok = ssl_cipher_strength_sort(head_p, tail_p);
1069 } else if (buflen == 10 &&
1070 strncmp(buf, "SECLEVEL=", 9) == 0) {
1071 int level = buf[9] - '0';
1072
1073 if (level >= 0 && level <= 5) {
1074 cert->security_level = level;
1075 ok = 1;
1076 } else {
1077 SSLerrorx(SSL_R_INVALID_COMMAND);
1078 }
1079 } else {
1080 SSLerrorx(SSL_R_INVALID_COMMAND);
1081 }
1082 if (ok == 0)
1083 retval = 0;
1084
1085 while ((*l != '\0') && !ITEM_SEP(*l))
1086 l++;
1087 } else if (found) {
1088 if (alg_ssl == SSL_TLSV1_3)
1089 *tls13_seen = 1;
1090 ssl_cipher_apply_rule(cipher_value, alg_mkey, alg_auth,
1091 alg_enc, alg_mac, alg_ssl, algo_strength, rule,
1092 -1, head_p, tail_p);
1093 } else {
1094 while ((*l != '\0') && !ITEM_SEP(*l))
1095 l++;
1096 }
1097 if (*l == '\0')
1098 break; /* done */
1099 }
1100
1101 return (retval);
1102}
1103
1104static inline int
1105ssl_aes_is_accelerated(void)
1106{
1107 return (OPENSSL_cpu_caps() & CRYPTO_CPU_CAPS_ACCELERATED_AES) != 0;
1108}
1109
1110STACK_OF(SSL_CIPHER) *
1111ssl_create_cipher_list(const SSL_METHOD *ssl_method,
1112 STACK_OF(SSL_CIPHER) **cipher_list,
1113 STACK_OF(SSL_CIPHER) *cipher_list_tls13,
1114 const char *rule_str, SSL_CERT *cert)
1115{
1116 int ok, num_of_ciphers, num_of_alias_max, num_of_group_aliases;
1117 unsigned long disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl;
1118 STACK_OF(SSL_CIPHER) *cipherstack = NULL, *ret = NULL;
1119 const char *rule_p;
1120 CIPHER_ORDER *co_list = NULL, *head = NULL, *tail = NULL, *curr;
1121 const SSL_CIPHER **ca_list = NULL;
1122 const SSL_CIPHER *cipher;
1123 int tls13_seen = 0;
1124 int any_active;
1125 int i;
1126
1127 /*
1128 * Return with error if nothing to do.
1129 */
1130 if (rule_str == NULL || cipher_list == NULL)
1131 goto err;
1132
1133 disabled_mkey = 0;
1134 disabled_auth = 0;
1135 disabled_enc = 0;
1136 disabled_mac = 0;
1137 disabled_ssl = 0;
1138
1139#ifdef SSL_FORBID_ENULL
1140 disabled_enc |= SSL_eNULL;
1141#endif
1142
1143 /* DTLS cannot be used with stream ciphers. */
1144 if (ssl_method->dtls)
1145 disabled_enc |= SSL_RC4;
1146
1147 /*
1148 * Now we have to collect the available ciphers from the compiled
1149 * in ciphers. We cannot get more than the number compiled in, so
1150 * it is used for allocation.
1151 */
1152 num_of_ciphers = ssl3_num_ciphers();
1153 co_list = reallocarray(NULL, num_of_ciphers, sizeof(CIPHER_ORDER));
1154 if (co_list == NULL) {
1155 SSLerrorx(ERR_R_MALLOC_FAILURE);
1156 goto err;
1157 }
1158
1159 ssl_cipher_collect_ciphers(ssl_method, num_of_ciphers,
1160 disabled_mkey, disabled_auth, disabled_enc, disabled_mac, disabled_ssl,
1161 co_list, &head, &tail);
1162
1163
1164 /* Now arrange all ciphers by preference: */
1165
1166 /* Everything else being equal, prefer ephemeral ECDH over other key exchange mechanisms */
1167 ssl_cipher_apply_rule(0, SSL_kECDHE, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1168 ssl_cipher_apply_rule(0, SSL_kECDHE, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);
1169
1170 if (ssl_aes_is_accelerated()) {
1171 /*
1172 * We have hardware assisted AES - prefer AES as a symmetric
1173 * cipher, with CHACHA20 second.
1174 */
1175 ssl_cipher_apply_rule(0, 0, 0, SSL_AES, 0, 0, 0,
1176 CIPHER_ADD, -1, &head, &tail);
1177 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305,
1178 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1179 } else {
1180 /*
1181 * CHACHA20 is fast and safe on all hardware and is thus our
1182 * preferred symmetric cipher, with AES second.
1183 */
1184 ssl_cipher_apply_rule(0, 0, 0, SSL_CHACHA20POLY1305,
1185 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1186 ssl_cipher_apply_rule(0, 0, 0, SSL_AES, 0, 0, 0,
1187 CIPHER_ADD, -1, &head, &tail);
1188 }
1189
1190 /* Temporarily enable everything else for sorting */
1191 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_ADD, -1, &head, &tail);
1192
1193 /* Low priority for MD5 */
1194 ssl_cipher_apply_rule(0, 0, 0, 0, SSL_MD5, 0, 0, CIPHER_ORD, -1, &head, &tail);
1195
1196 /* Move anonymous ciphers to the end. Usually, these will remain disabled.
1197 * (For applications that allow them, they aren't too bad, but we prefer
1198 * authenticated ciphers.) */
1199 ssl_cipher_apply_rule(0, 0, SSL_aNULL, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1200
1201 /* Move ciphers without forward secrecy to the end */
1202 ssl_cipher_apply_rule(0, SSL_kRSA, 0, 0, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1203
1204 /* RC4 is sort of broken - move it to the end */
1205 ssl_cipher_apply_rule(0, 0, 0, SSL_RC4, 0, 0, 0, CIPHER_ORD, -1, &head, &tail);
1206
1207 /* Now sort by symmetric encryption strength. The above ordering remains
1208 * in force within each class */
1209 if (!ssl_cipher_strength_sort(&head, &tail))
1210 goto err;
1211
1212 /* Now disable everything (maintaining the ordering!) */
1213 ssl_cipher_apply_rule(0, 0, 0, 0, 0, 0, 0, CIPHER_DEL, -1, &head, &tail);
1214
1215 /* TLSv1.3 first. */
1216 ssl_cipher_apply_rule(0, 0, 0, 0, 0, SSL_TLSV1_3, 0, CIPHER_ADD, -1, &head, &tail);
1217 ssl_cipher_apply_rule(0, 0, 0, 0, 0, SSL_TLSV1_3, 0, CIPHER_DEL, -1, &head, &tail);
1218
1219 /*
1220 * We also need cipher aliases for selecting based on the rule_str.
1221 * There might be two types of entries in the rule_str: 1) names
1222 * of ciphers themselves 2) aliases for groups of ciphers.
1223 * For 1) we need the available ciphers and for 2) the cipher
1224 * groups of cipher_aliases added together in one list (otherwise
1225 * we would be happy with just the cipher_aliases table).
1226 */
1227 num_of_group_aliases = sizeof(cipher_aliases) / sizeof(SSL_CIPHER);
1228 num_of_alias_max = num_of_ciphers + num_of_group_aliases + 1;
1229 ca_list = reallocarray(NULL, num_of_alias_max, sizeof(SSL_CIPHER *));
1230 if (ca_list == NULL) {
1231 SSLerrorx(ERR_R_MALLOC_FAILURE);
1232 goto err;
1233 }
1234 ssl_cipher_collect_aliases(ca_list, num_of_group_aliases, disabled_mkey,
1235 disabled_auth, disabled_enc, disabled_mac, disabled_ssl, head);
1236
1237 /*
1238 * If the rule_string begins with DEFAULT, apply the default rule
1239 * before using the (possibly available) additional rules.
1240 */
1241 ok = 1;
1242 rule_p = rule_str;
1243 if (strncmp(rule_str, "DEFAULT", 7) == 0) {
1244 ok = ssl_cipher_process_rulestr(SSL_DEFAULT_CIPHER_LIST,
1245 &head, &tail, ca_list, cert, &tls13_seen);
1246 rule_p += 7;
1247 if (*rule_p == ':')
1248 rule_p++;
1249 }
1250
1251 if (ok && (strlen(rule_p) > 0))
1252 ok = ssl_cipher_process_rulestr(rule_p, &head, &tail, ca_list,
1253 cert, &tls13_seen);
1254
1255 if (!ok) {
1256 /* Rule processing failure */
1257 goto err;
1258 }
1259
1260 /*
1261 * Allocate new "cipherstack" for the result, return with error
1262 * if we cannot get one.
1263 */
1264 if ((cipherstack = sk_SSL_CIPHER_new_null()) == NULL) {
1265 SSLerrorx(ERR_R_MALLOC_FAILURE);
1266 goto err;
1267 }
1268
1269 /* Prefer TLSv1.3 cipher suites. */
1270 if (cipher_list_tls13 != NULL) {
1271 for (i = 0; i < sk_SSL_CIPHER_num(cipher_list_tls13); i++) {
1272 cipher = sk_SSL_CIPHER_value(cipher_list_tls13, i);
1273 if (!sk_SSL_CIPHER_push(cipherstack, cipher)) {
1274 SSLerrorx(ERR_R_MALLOC_FAILURE);
1275 goto err;
1276 }
1277 }
1278 tls13_seen = 1;
1279 }
1280
1281 /*
1282 * The cipher selection for the list is done. The ciphers are added
1283 * to the resulting precedence to the STACK_OF(SSL_CIPHER).
1284 *
1285 * If the rule string did not contain any references to TLSv1.3 and
1286 * TLSv1.3 cipher suites have not been configured separately,
1287 * include inactive TLSv1.3 cipher suites. This avoids attempts to
1288 * use TLSv1.3 with an older rule string that does not include
1289 * TLSv1.3 cipher suites. If the rule string resulted in no active
1290 * cipher suites then we return an empty stack.
1291 */
1292 any_active = 0;
1293 for (curr = head; curr != NULL; curr = curr->next) {
1294 if (curr->active ||
1295 (!tls13_seen && curr->cipher->algorithm_ssl == SSL_TLSV1_3)) {
1296 if (!sk_SSL_CIPHER_push(cipherstack, curr->cipher)) {
1297 SSLerrorx(ERR_R_MALLOC_FAILURE);
1298 goto err;
1299 }
1300 }
1301 any_active |= curr->active;
1302 }
1303 if (!any_active)
1304 sk_SSL_CIPHER_zero(cipherstack);
1305
1306 sk_SSL_CIPHER_free(*cipher_list);
1307 *cipher_list = cipherstack;
1308 cipherstack = NULL;
1309
1310 ret = *cipher_list;
1311
1312 err:
1313 sk_SSL_CIPHER_free(cipherstack);
1314 free((void *)ca_list);
1315 free(co_list);
1316
1317 return ret;
1318}
1319
1320char *
1321SSL_CIPHER_description(const SSL_CIPHER *cipher, char *buf, int len)
1322{
1323 unsigned long alg_mkey, alg_auth, alg_enc, alg_mac, alg_ssl;
1324 const char *ver, *kx, *au, *enc, *mac;
1325 char *ret;
1326 int l;
1327
1328 alg_mkey = cipher->algorithm_mkey;
1329 alg_auth = cipher->algorithm_auth;
1330 alg_enc = cipher->algorithm_enc;
1331 alg_mac = cipher->algorithm_mac;
1332 alg_ssl = cipher->algorithm_ssl;
1333
1334 if (alg_ssl & SSL_SSLV3)
1335 ver = "SSLv3";
1336 else if (alg_ssl & SSL_TLSV1_2)
1337 ver = "TLSv1.2";
1338 else if (alg_ssl & SSL_TLSV1_3)
1339 ver = "TLSv1.3";
1340 else
1341 ver = "unknown";
1342
1343 switch (alg_mkey) {
1344 case SSL_kRSA:
1345 kx = "RSA";
1346 break;
1347 case SSL_kDHE:
1348 kx = "DH";
1349 break;
1350 case SSL_kECDHE:
1351 kx = "ECDH";
1352 break;
1353 case SSL_kTLS1_3:
1354 kx = "TLSv1.3";
1355 break;
1356 default:
1357 kx = "unknown";
1358 }
1359
1360 switch (alg_auth) {
1361 case SSL_aRSA:
1362 au = "RSA";
1363 break;
1364 case SSL_aNULL:
1365 au = "None";
1366 break;
1367 case SSL_aECDSA:
1368 au = "ECDSA";
1369 break;
1370 case SSL_aTLS1_3:
1371 au = "TLSv1.3";
1372 break;
1373 default:
1374 au = "unknown";
1375 break;
1376 }
1377
1378 switch (alg_enc) {
1379 case SSL_3DES:
1380 enc = "3DES(168)";
1381 break;
1382 case SSL_RC4:
1383 enc = "RC4(128)";
1384 break;
1385 case SSL_eNULL:
1386 enc = "None";
1387 break;
1388 case SSL_AES128:
1389 enc = "AES(128)";
1390 break;
1391 case SSL_AES256:
1392 enc = "AES(256)";
1393 break;
1394 case SSL_AES128GCM:
1395 enc = "AESGCM(128)";
1396 break;
1397 case SSL_AES256GCM:
1398 enc = "AESGCM(256)";
1399 break;
1400 case SSL_CAMELLIA128:
1401 enc = "Camellia(128)";
1402 break;
1403 case SSL_CAMELLIA256:
1404 enc = "Camellia(256)";
1405 break;
1406 case SSL_CHACHA20POLY1305:
1407 enc = "ChaCha20-Poly1305";
1408 break;
1409 default:
1410 enc = "unknown";
1411 break;
1412 }
1413
1414 switch (alg_mac) {
1415 case SSL_MD5:
1416 mac = "MD5";
1417 break;
1418 case SSL_SHA1:
1419 mac = "SHA1";
1420 break;
1421 case SSL_SHA256:
1422 mac = "SHA256";
1423 break;
1424 case SSL_SHA384:
1425 mac = "SHA384";
1426 break;
1427 case SSL_AEAD:
1428 mac = "AEAD";
1429 break;
1430 default:
1431 mac = "unknown";
1432 break;
1433 }
1434
1435 if (asprintf(&ret, "%-23s %s Kx=%-8s Au=%-4s Enc=%-9s Mac=%-4s\n",
1436 cipher->name, ver, kx, au, enc, mac) == -1)
1437 return "OPENSSL_malloc Error";
1438
1439 if (buf != NULL) {
1440 l = strlcpy(buf, ret, len);
1441 free(ret);
1442 ret = buf;
1443 if (l >= len)
1444 ret = "Buffer too small";
1445 }
1446
1447 return (ret);
1448}
1449LSSL_ALIAS(SSL_CIPHER_description);
1450
1451const char *
1452SSL_CIPHER_get_version(const SSL_CIPHER *cipher)
1453{
1454 if (cipher == NULL)
1455 return "(NONE)";
1456
1457 return "TLSv1/SSLv3";
1458}
1459LSSL_ALIAS(SSL_CIPHER_get_version);
1460
1461/* return the actual cipher being used */
1462const char *
1463SSL_CIPHER_get_name(const SSL_CIPHER *cipher)
1464{
1465 if (cipher == NULL)
1466 return "(NONE)";
1467
1468 return cipher->name;
1469}
1470LSSL_ALIAS(SSL_CIPHER_get_name);
1471
1472/* number of bits for symmetric cipher */
1473int
1474SSL_CIPHER_get_bits(const SSL_CIPHER *c, int *alg_bits)
1475{
1476 int ret = 0;
1477
1478 if (c != NULL) {
1479 if (alg_bits != NULL)
1480 *alg_bits = c->alg_bits;
1481 ret = c->strength_bits;
1482 }
1483 return (ret);
1484}
1485LSSL_ALIAS(SSL_CIPHER_get_bits);
1486
1487unsigned long
1488SSL_CIPHER_get_id(const SSL_CIPHER *cipher)
1489{
1490 return SSL3_CK_ID | cipher->value;
1491}
1492LSSL_ALIAS(SSL_CIPHER_get_id);
1493
1494uint16_t
1495SSL_CIPHER_get_value(const SSL_CIPHER *cipher)
1496{
1497 return cipher->value;
1498}
1499LSSL_ALIAS(SSL_CIPHER_get_value);
1500
1501const SSL_CIPHER *
1502SSL_CIPHER_find(SSL *ssl, const unsigned char *ptr)
1503{
1504 uint16_t cipher_value;
1505 CBS cbs;
1506
1507 /* This API is documented with ptr being an array of length two. */
1508 CBS_init(&cbs, ptr, 2);
1509 if (!CBS_get_u16(&cbs, &cipher_value))
1510 return NULL;
1511
1512 return ssl3_get_cipher_by_value(cipher_value);
1513}
1514LSSL_ALIAS(SSL_CIPHER_find);
1515
1516int
1517SSL_CIPHER_get_cipher_nid(const SSL_CIPHER *c)
1518{
1519 switch (c->algorithm_enc) {
1520 case SSL_eNULL:
1521 return NID_undef;
1522 case SSL_3DES:
1523 return NID_des_ede3_cbc;
1524 case SSL_AES128:
1525 return NID_aes_128_cbc;
1526 case SSL_AES128GCM:
1527 return NID_aes_128_gcm;
1528 case SSL_AES256:
1529 return NID_aes_256_cbc;
1530 case SSL_AES256GCM:
1531 return NID_aes_256_gcm;
1532 case SSL_CAMELLIA128:
1533 return NID_camellia_128_cbc;
1534 case SSL_CAMELLIA256:
1535 return NID_camellia_256_cbc;
1536 case SSL_CHACHA20POLY1305:
1537 return NID_chacha20_poly1305;
1538 case SSL_RC4:
1539 return NID_rc4;
1540 default:
1541 return NID_undef;
1542 }
1543}
1544LSSL_ALIAS(SSL_CIPHER_get_cipher_nid);
1545
1546int
1547SSL_CIPHER_get_digest_nid(const SSL_CIPHER *c)
1548{
1549 switch (c->algorithm_mac) {
1550 case SSL_AEAD:
1551 return NID_undef;
1552 case SSL_MD5:
1553 return NID_md5;
1554 case SSL_SHA1:
1555 return NID_sha1;
1556 case SSL_SHA256:
1557 return NID_sha256;
1558 case SSL_SHA384:
1559 return NID_sha384;
1560 default:
1561 return NID_undef;
1562 }
1563}
1564LSSL_ALIAS(SSL_CIPHER_get_digest_nid);
1565
1566int
1567SSL_CIPHER_get_kx_nid(const SSL_CIPHER *c)
1568{
1569 switch (c->algorithm_mkey) {
1570 case SSL_kDHE:
1571 return NID_kx_dhe;
1572 case SSL_kECDHE:
1573 return NID_kx_ecdhe;
1574 case SSL_kRSA:
1575 return NID_kx_rsa;
1576 default:
1577 return NID_undef;
1578 }
1579}
1580LSSL_ALIAS(SSL_CIPHER_get_kx_nid);
1581
1582int
1583SSL_CIPHER_get_auth_nid(const SSL_CIPHER *c)
1584{
1585 switch (c->algorithm_auth) {
1586 case SSL_aNULL:
1587 return NID_auth_null;
1588 case SSL_aECDSA:
1589 return NID_auth_ecdsa;
1590 case SSL_aRSA:
1591 return NID_auth_rsa;
1592 default:
1593 return NID_undef;
1594 }
1595}
1596LSSL_ALIAS(SSL_CIPHER_get_auth_nid);
1597
1598const EVP_MD *
1599SSL_CIPHER_get_handshake_digest(const SSL_CIPHER *c)
1600{
1601 switch (c->algorithm2 & SSL_HANDSHAKE_MAC_MASK) {
1602 case SSL_HANDSHAKE_MAC_SHA256:
1603 return EVP_sha256();
1604 case SSL_HANDSHAKE_MAC_SHA384:
1605 return EVP_sha384();
1606 default:
1607 return NULL;
1608 }
1609}
1610LSSL_ALIAS(SSL_CIPHER_get_handshake_digest);
1611
1612int
1613SSL_CIPHER_is_aead(const SSL_CIPHER *c)
1614{
1615 return (c->algorithm_mac & SSL_AEAD) == SSL_AEAD;
1616}
1617LSSL_ALIAS(SSL_CIPHER_is_aead);
1618
1619void *
1620SSL_COMP_get_compression_methods(void)
1621{
1622 return NULL;
1623}
1624LSSL_ALIAS(SSL_COMP_get_compression_methods);
1625
1626const char *
1627SSL_COMP_get_name(const void *comp)
1628{
1629 return NULL;
1630}
1631LSSL_ALIAS(SSL_COMP_get_name);
diff --git a/src/lib/libssl/ssl_ciphers.c b/src/lib/libssl/ssl_ciphers.c
deleted file mode 100644
index 503ef9d03c..0000000000
--- a/src/lib/libssl/ssl_ciphers.c
+++ /dev/null
@@ -1,286 +0,0 @@
1/* $OpenBSD: ssl_ciphers.c,v 1.18 2024/07/22 14:47:15 jsing Exp $ */
2/*
3 * Copyright (c) 2015-2017 Doug Hogan <doug@openbsd.org>
4 * Copyright (c) 2015-2018, 2020 Joel Sing <jsing@openbsd.org>
5 * Copyright (c) 2019 Theo Buehler <tb@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <openssl/safestack.h>
21
22#include "bytestring.h"
23#include "ssl_local.h"
24
25int
26ssl_cipher_in_list(STACK_OF(SSL_CIPHER) *ciphers, const SSL_CIPHER *cipher)
27{
28 int i;
29
30 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
31 if (sk_SSL_CIPHER_value(ciphers, i)->value == cipher->value)
32 return 1;
33 }
34
35 return 0;
36}
37
38int
39ssl_cipher_allowed_in_tls_version_range(const SSL_CIPHER *cipher, uint16_t min_ver,
40 uint16_t max_ver)
41{
42 switch(cipher->algorithm_ssl) {
43 case SSL_SSLV3:
44 return (min_ver <= TLS1_2_VERSION);
45 case SSL_TLSV1_2:
46 return (min_ver <= TLS1_2_VERSION && TLS1_2_VERSION <= max_ver);
47 case SSL_TLSV1_3:
48 return (min_ver <= TLS1_3_VERSION && TLS1_3_VERSION <= max_ver);
49 }
50 return 0;
51}
52
53int
54ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb)
55{
56 SSL_CIPHER *cipher;
57 int num_ciphers = 0;
58 uint16_t min_vers, max_vers;
59 int i;
60
61 if (ciphers == NULL)
62 return 0;
63
64 if (!ssl_supported_tls_version_range(s, &min_vers, &max_vers))
65 return 0;
66
67 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
68 if ((cipher = sk_SSL_CIPHER_value(ciphers, i)) == NULL)
69 return 0;
70 if (!ssl_cipher_allowed_in_tls_version_range(cipher, min_vers,
71 max_vers))
72 continue;
73 if (!ssl_security_cipher_check(s, cipher))
74 continue;
75 if (!CBB_add_u16(cbb, cipher->value))
76 return 0;
77
78 num_ciphers++;
79 }
80
81 /* Add SCSV if there are other ciphers and we're not renegotiating. */
82 if (num_ciphers > 0 && !s->renegotiate) {
83 if (!CBB_add_u16(cbb, SSL3_CK_SCSV & SSL3_CK_VALUE_MASK))
84 return 0;
85 }
86
87 if (!CBB_flush(cbb))
88 return 0;
89
90 return 1;
91}
92
93STACK_OF(SSL_CIPHER) *
94ssl_bytes_to_cipher_list(SSL *s, CBS *cbs)
95{
96 STACK_OF(SSL_CIPHER) *ciphers = NULL;
97 const SSL_CIPHER *cipher;
98 uint16_t cipher_value;
99 unsigned long cipher_id;
100
101 s->s3->send_connection_binding = 0;
102
103 if ((ciphers = sk_SSL_CIPHER_new_null()) == NULL) {
104 SSLerror(s, ERR_R_MALLOC_FAILURE);
105 goto err;
106 }
107
108 while (CBS_len(cbs) > 0) {
109 if (!CBS_get_u16(cbs, &cipher_value)) {
110 SSLerror(s, SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST);
111 goto err;
112 }
113
114 cipher_id = SSL3_CK_ID | cipher_value;
115
116 if (cipher_id == SSL3_CK_SCSV) {
117 /*
118 * TLS_EMPTY_RENEGOTIATION_INFO_SCSV is fatal if
119 * renegotiating.
120 */
121 if (s->renegotiate) {
122 SSLerror(s, SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING);
123 ssl3_send_alert(s, SSL3_AL_FATAL,
124 SSL_AD_HANDSHAKE_FAILURE);
125
126 goto err;
127 }
128 s->s3->send_connection_binding = 1;
129 continue;
130 }
131
132 if (cipher_id == SSL3_CK_FALLBACK_SCSV) {
133 /*
134 * TLS_FALLBACK_SCSV indicates that the client
135 * previously tried a higher protocol version.
136 * Fail if the current version is an unexpected
137 * downgrade.
138 */
139 if (s->s3->hs.negotiated_tls_version <
140 s->s3->hs.our_max_tls_version) {
141 SSLerror(s, SSL_R_INAPPROPRIATE_FALLBACK);
142 ssl3_send_alert(s, SSL3_AL_FATAL,
143 SSL_AD_INAPPROPRIATE_FALLBACK);
144 goto err;
145 }
146 continue;
147 }
148
149 if ((cipher = ssl3_get_cipher_by_value(cipher_value)) != NULL) {
150 if (!sk_SSL_CIPHER_push(ciphers, cipher)) {
151 SSLerror(s, ERR_R_MALLOC_FAILURE);
152 goto err;
153 }
154 }
155 }
156
157 return (ciphers);
158
159 err:
160 sk_SSL_CIPHER_free(ciphers);
161
162 return (NULL);
163}
164
165struct ssl_tls13_ciphersuite {
166 const char *name;
167 const char *alias;
168 uint16_t value;
169};
170
171static const struct ssl_tls13_ciphersuite ssl_tls13_ciphersuites[] = {
172 {
173 .name = TLS1_3_RFC_AES_128_GCM_SHA256,
174 .alias = TLS1_3_TXT_AES_128_GCM_SHA256,
175 .value = 0x1301,
176 },
177 {
178 .name = TLS1_3_RFC_AES_256_GCM_SHA384,
179 .alias = TLS1_3_TXT_AES_256_GCM_SHA384,
180 .value = 0x1302,
181 },
182 {
183 .name = TLS1_3_RFC_CHACHA20_POLY1305_SHA256,
184 .alias = TLS1_3_TXT_CHACHA20_POLY1305_SHA256,
185 .value = 0x1303,
186 },
187 {
188 .name = TLS1_3_RFC_AES_128_CCM_SHA256,
189 .alias = TLS1_3_TXT_AES_128_CCM_SHA256,
190 .value = 0x1304,
191 },
192 {
193 .name = TLS1_3_RFC_AES_128_CCM_8_SHA256,
194 .alias = TLS1_3_TXT_AES_128_CCM_8_SHA256,
195 .value = 0x1305,
196 },
197 {
198 .name = NULL,
199 },
200};
201
202int
203ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str)
204{
205 const struct ssl_tls13_ciphersuite *ciphersuite;
206 STACK_OF(SSL_CIPHER) *ciphers;
207 const SSL_CIPHER *cipher;
208 char *s = NULL;
209 char *p, *q;
210 int i;
211 int ret = 0;
212
213 if ((ciphers = sk_SSL_CIPHER_new_null()) == NULL)
214 goto err;
215
216 /* An empty string is valid and means no ciphers. */
217 if (strcmp(str, "") == 0)
218 goto done;
219
220 if ((s = strdup(str)) == NULL)
221 goto err;
222
223 q = s;
224 while ((p = strsep(&q, ":")) != NULL) {
225 ciphersuite = &ssl_tls13_ciphersuites[0];
226 for (i = 0; ciphersuite->name != NULL; i++) {
227 if (strcmp(p, ciphersuite->name) == 0)
228 break;
229 if (strcmp(p, ciphersuite->alias) == 0)
230 break;
231 ciphersuite = &ssl_tls13_ciphersuites[i];
232 }
233 if (ciphersuite->name == NULL)
234 goto err;
235
236 /* We know about the cipher suite, but it is not supported. */
237 if ((cipher = ssl3_get_cipher_by_value(ciphersuite->value)) == NULL)
238 continue;
239
240 if (!sk_SSL_CIPHER_push(ciphers, cipher))
241 goto err;
242 }
243
244 done:
245 sk_SSL_CIPHER_free(*out_ciphers);
246 *out_ciphers = ciphers;
247 ciphers = NULL;
248 ret = 1;
249
250 err:
251 sk_SSL_CIPHER_free(ciphers);
252 free(s);
253
254 return ret;
255}
256
257int
258ssl_merge_cipherlists(STACK_OF(SSL_CIPHER) *cipherlist,
259 STACK_OF(SSL_CIPHER) *cipherlist_tls13,
260 STACK_OF(SSL_CIPHER) **out_cipherlist)
261{
262 STACK_OF(SSL_CIPHER) *ciphers = NULL;
263 const SSL_CIPHER *cipher;
264 int i, ret = 0;
265
266 if ((ciphers = sk_SSL_CIPHER_dup(cipherlist_tls13)) == NULL)
267 goto err;
268 for (i = 0; i < sk_SSL_CIPHER_num(cipherlist); i++) {
269 cipher = sk_SSL_CIPHER_value(cipherlist, i);
270 if (cipher->algorithm_ssl == SSL_TLSV1_3)
271 continue;
272 if (!sk_SSL_CIPHER_push(ciphers, cipher))
273 goto err;
274 }
275
276 sk_SSL_CIPHER_free(*out_cipherlist);
277 *out_cipherlist = ciphers;
278 ciphers = NULL;
279
280 ret = 1;
281
282 err:
283 sk_SSL_CIPHER_free(ciphers);
284
285 return ret;
286}
diff --git a/src/lib/libssl/ssl_clnt.c b/src/lib/libssl/ssl_clnt.c
deleted file mode 100644
index 0d3dcf78af..0000000000
--- a/src/lib/libssl/ssl_clnt.c
+++ /dev/null
@@ -1,2456 +0,0 @@
1/* $OpenBSD: ssl_clnt.c,v 1.169 2025/03/09 15:53:36 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 *
114 * Portions of the attached software ("Contribution") are developed by
115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
116 *
117 * The Contribution is licensed pursuant to the OpenSSL open source
118 * license provided above.
119 *
120 * ECC cipher suite support in OpenSSL originally written by
121 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
122 *
123 */
124/* ====================================================================
125 * Copyright 2005 Nokia. All rights reserved.
126 *
127 * The portions of the attached software ("Contribution") is developed by
128 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
129 * license.
130 *
131 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
132 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
133 * support (see RFC 4279) to OpenSSL.
134 *
135 * No patent licenses or other rights except those expressly stated in
136 * the OpenSSL open source license shall be deemed granted or received
137 * expressly, by implication, estoppel, or otherwise.
138 *
139 * No assurances are provided by Nokia that the Contribution does not
140 * infringe the patent or other intellectual property rights of any third
141 * party or that the license provides you with all the necessary rights
142 * to make use of the Contribution.
143 *
144 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
145 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
146 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
147 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
148 * OTHERWISE.
149 */
150
151#include <limits.h>
152#include <stdint.h>
153#include <stdio.h>
154
155#include <openssl/bn.h>
156#include <openssl/buffer.h>
157#include <openssl/curve25519.h>
158#include <openssl/dh.h>
159#include <openssl/evp.h>
160#include <openssl/md5.h>
161#include <openssl/objects.h>
162#include <openssl/opensslconf.h>
163
164#include "bytestring.h"
165#include "dtls_local.h"
166#include "ssl_local.h"
167#include "ssl_sigalgs.h"
168#include "ssl_tlsext.h"
169
170static int ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b);
171
172static int ssl3_send_client_hello(SSL *s);
173static int ssl3_get_dtls_hello_verify(SSL *s);
174static int ssl3_get_server_hello(SSL *s);
175static int ssl3_get_certificate_request(SSL *s);
176static int ssl3_get_new_session_ticket(SSL *s);
177static int ssl3_get_cert_status(SSL *s);
178static int ssl3_get_server_done(SSL *s);
179static int ssl3_send_client_verify(SSL *s);
180static int ssl3_send_client_certificate(SSL *s);
181static int ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey);
182static int ssl3_send_client_key_exchange(SSL *s);
183static int ssl3_get_server_key_exchange(SSL *s);
184static int ssl3_get_server_certificate(SSL *s);
185static int ssl3_check_cert_and_algorithm(SSL *s);
186static int ssl3_check_finished(SSL *s);
187static int ssl3_send_client_change_cipher_spec(SSL *s);
188static int ssl3_send_client_finished(SSL *s);
189static int ssl3_get_server_finished(SSL *s);
190
191int
192ssl3_connect(SSL *s)
193{
194 int new_state, state, skip = 0;
195 int ret = -1;
196
197 ERR_clear_error();
198 errno = 0;
199
200 s->in_handshake++;
201 if (!SSL_in_init(s) || SSL_in_before(s))
202 SSL_clear(s);
203
204 for (;;) {
205 state = s->s3->hs.state;
206
207 switch (s->s3->hs.state) {
208 case SSL_ST_RENEGOTIATE:
209 s->renegotiate = 1;
210 s->s3->hs.state = SSL_ST_CONNECT;
211 s->ctx->stats.sess_connect_renegotiate++;
212 /* break */
213 case SSL_ST_BEFORE:
214 case SSL_ST_CONNECT:
215 case SSL_ST_BEFORE|SSL_ST_CONNECT:
216 case SSL_ST_OK|SSL_ST_CONNECT:
217
218 s->server = 0;
219
220 ssl_info_callback(s, SSL_CB_HANDSHAKE_START, 1);
221
222 if (!ssl_legacy_stack_version(s, s->version)) {
223 SSLerror(s, ERR_R_INTERNAL_ERROR);
224 ret = -1;
225 goto end;
226 }
227
228 if (!ssl_supported_tls_version_range(s,
229 &s->s3->hs.our_min_tls_version,
230 &s->s3->hs.our_max_tls_version)) {
231 SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE);
232 ret = -1;
233 goto end;
234 }
235
236 if (!ssl_security_version(s,
237 s->s3->hs.our_min_tls_version)) {
238 SSLerror(s, SSL_R_VERSION_TOO_LOW);
239 ret = -1;
240 goto end;
241 }
242
243 if (!ssl3_setup_init_buffer(s)) {
244 ret = -1;
245 goto end;
246 }
247 if (!ssl3_setup_buffers(s)) {
248 ret = -1;
249 goto end;
250 }
251 if (!ssl_init_wbio_buffer(s, 0)) {
252 ret = -1;
253 goto end;
254 }
255
256 /* don't push the buffering BIO quite yet */
257
258 if (!tls1_transcript_init(s)) {
259 ret = -1;
260 goto end;
261 }
262
263 s->s3->hs.state = SSL3_ST_CW_CLNT_HELLO_A;
264 s->ctx->stats.sess_connect++;
265 s->init_num = 0;
266
267 if (SSL_is_dtls(s)) {
268 /* mark client_random uninitialized */
269 memset(s->s3->client_random, 0,
270 sizeof(s->s3->client_random));
271 s->d1->send_cookie = 0;
272 s->hit = 0;
273 }
274 break;
275
276 case SSL3_ST_CW_CLNT_HELLO_A:
277 case SSL3_ST_CW_CLNT_HELLO_B:
278 s->shutdown = 0;
279
280 if (SSL_is_dtls(s)) {
281 /* every DTLS ClientHello resets Finished MAC */
282 tls1_transcript_reset(s);
283
284 dtls1_start_timer(s);
285 }
286
287 ret = ssl3_send_client_hello(s);
288 if (ret <= 0)
289 goto end;
290
291 if (SSL_is_dtls(s) && s->d1->send_cookie) {
292 s->s3->hs.state = SSL3_ST_CW_FLUSH;
293 s->s3->hs.tls12.next_state = SSL3_ST_CR_SRVR_HELLO_A;
294 } else
295 s->s3->hs.state = SSL3_ST_CR_SRVR_HELLO_A;
296
297 s->init_num = 0;
298
299 /* turn on buffering for the next lot of output */
300 if (s->bbio != s->wbio)
301 s->wbio = BIO_push(s->bbio, s->wbio);
302
303 break;
304
305 case SSL3_ST_CR_SRVR_HELLO_A:
306 case SSL3_ST_CR_SRVR_HELLO_B:
307 ret = ssl3_get_server_hello(s);
308 if (ret <= 0)
309 goto end;
310
311 if (s->hit) {
312 s->s3->hs.state = SSL3_ST_CR_FINISHED_A;
313 if (!SSL_is_dtls(s)) {
314 if (s->tlsext_ticket_expected) {
315 /* receive renewed session ticket */
316 s->s3->hs.state = SSL3_ST_CR_SESSION_TICKET_A;
317 }
318
319 /* No client certificate verification. */
320 tls1_transcript_free(s);
321 }
322 } else if (SSL_is_dtls(s)) {
323 s->s3->hs.state = DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A;
324 } else {
325 s->s3->hs.state = SSL3_ST_CR_CERT_A;
326 }
327 s->init_num = 0;
328 break;
329
330 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
331 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
332 ret = ssl3_get_dtls_hello_verify(s);
333 if (ret <= 0)
334 goto end;
335 dtls1_stop_timer(s);
336 if (s->d1->send_cookie) /* start again, with a cookie */
337 s->s3->hs.state = SSL3_ST_CW_CLNT_HELLO_A;
338 else
339 s->s3->hs.state = SSL3_ST_CR_CERT_A;
340 s->init_num = 0;
341 break;
342
343 case SSL3_ST_CR_CERT_A:
344 case SSL3_ST_CR_CERT_B:
345 ret = ssl3_check_finished(s);
346 if (ret <= 0)
347 goto end;
348 if (ret == 2) {
349 s->hit = 1;
350 if (s->tlsext_ticket_expected)
351 s->s3->hs.state = SSL3_ST_CR_SESSION_TICKET_A;
352 else
353 s->s3->hs.state = SSL3_ST_CR_FINISHED_A;
354 s->init_num = 0;
355 break;
356 }
357 /* Check if it is anon DH/ECDH. */
358 if (!(s->s3->hs.cipher->algorithm_auth &
359 SSL_aNULL)) {
360 ret = ssl3_get_server_certificate(s);
361 if (ret <= 0)
362 goto end;
363 if (s->tlsext_status_expected)
364 s->s3->hs.state = SSL3_ST_CR_CERT_STATUS_A;
365 else
366 s->s3->hs.state = SSL3_ST_CR_KEY_EXCH_A;
367 } else {
368 skip = 1;
369 s->s3->hs.state = SSL3_ST_CR_KEY_EXCH_A;
370 }
371 s->init_num = 0;
372 break;
373
374 case SSL3_ST_CR_KEY_EXCH_A:
375 case SSL3_ST_CR_KEY_EXCH_B:
376 ret = ssl3_get_server_key_exchange(s);
377 if (ret <= 0)
378 goto end;
379 s->s3->hs.state = SSL3_ST_CR_CERT_REQ_A;
380 s->init_num = 0;
381
382 /*
383 * At this point we check that we have the
384 * required stuff from the server.
385 */
386 if (!ssl3_check_cert_and_algorithm(s)) {
387 ret = -1;
388 goto end;
389 }
390 break;
391
392 case SSL3_ST_CR_CERT_REQ_A:
393 case SSL3_ST_CR_CERT_REQ_B:
394 ret = ssl3_get_certificate_request(s);
395 if (ret <= 0)
396 goto end;
397 s->s3->hs.state = SSL3_ST_CR_SRVR_DONE_A;
398 s->init_num = 0;
399 break;
400
401 case SSL3_ST_CR_SRVR_DONE_A:
402 case SSL3_ST_CR_SRVR_DONE_B:
403 ret = ssl3_get_server_done(s);
404 if (ret <= 0)
405 goto end;
406 if (SSL_is_dtls(s))
407 dtls1_stop_timer(s);
408 if (s->s3->hs.tls12.cert_request)
409 s->s3->hs.state = SSL3_ST_CW_CERT_A;
410 else
411 s->s3->hs.state = SSL3_ST_CW_KEY_EXCH_A;
412 s->init_num = 0;
413
414 break;
415
416 case SSL3_ST_CW_CERT_A:
417 case SSL3_ST_CW_CERT_B:
418 case SSL3_ST_CW_CERT_C:
419 case SSL3_ST_CW_CERT_D:
420 if (SSL_is_dtls(s))
421 dtls1_start_timer(s);
422 ret = ssl3_send_client_certificate(s);
423 if (ret <= 0)
424 goto end;
425 s->s3->hs.state = SSL3_ST_CW_KEY_EXCH_A;
426 s->init_num = 0;
427 break;
428
429 case SSL3_ST_CW_KEY_EXCH_A:
430 case SSL3_ST_CW_KEY_EXCH_B:
431 if (SSL_is_dtls(s))
432 dtls1_start_timer(s);
433 ret = ssl3_send_client_key_exchange(s);
434 if (ret <= 0)
435 goto end;
436 /*
437 * EAY EAY EAY need to check for DH fix cert
438 * sent back
439 */
440 /*
441 * For TLS, cert_req is set to 2, so a cert chain
442 * of nothing is sent, but no verify packet is sent
443 */
444 /*
445 * XXX: For now, we do not support client
446 * authentication in ECDH cipher suites with
447 * ECDH (rather than ECDSA) certificates.
448 * We need to skip the certificate verify
449 * message when client's ECDH public key is sent
450 * inside the client certificate.
451 */
452 if (s->s3->hs.tls12.cert_request == 1) {
453 s->s3->hs.state = SSL3_ST_CW_CERT_VRFY_A;
454 } else {
455 s->s3->hs.state = SSL3_ST_CW_CHANGE_A;
456 s->s3->change_cipher_spec = 0;
457 }
458
459 s->init_num = 0;
460 break;
461
462 case SSL3_ST_CW_CERT_VRFY_A:
463 case SSL3_ST_CW_CERT_VRFY_B:
464 if (SSL_is_dtls(s))
465 dtls1_start_timer(s);
466 ret = ssl3_send_client_verify(s);
467 if (ret <= 0)
468 goto end;
469 s->s3->hs.state = SSL3_ST_CW_CHANGE_A;
470 s->init_num = 0;
471 s->s3->change_cipher_spec = 0;
472 break;
473
474 case SSL3_ST_CW_CHANGE_A:
475 case SSL3_ST_CW_CHANGE_B:
476 if (SSL_is_dtls(s) && !s->hit)
477 dtls1_start_timer(s);
478 ret = ssl3_send_client_change_cipher_spec(s);
479 if (ret <= 0)
480 goto end;
481
482 s->s3->hs.state = SSL3_ST_CW_FINISHED_A;
483 s->init_num = 0;
484 s->session->cipher_value = s->s3->hs.cipher->value;
485
486 if (!tls1_setup_key_block(s)) {
487 ret = -1;
488 goto end;
489 }
490 if (!tls1_change_write_cipher_state(s)) {
491 ret = -1;
492 goto end;
493 }
494 break;
495
496 case SSL3_ST_CW_FINISHED_A:
497 case SSL3_ST_CW_FINISHED_B:
498 if (SSL_is_dtls(s) && !s->hit)
499 dtls1_start_timer(s);
500 ret = ssl3_send_client_finished(s);
501 if (ret <= 0)
502 goto end;
503 if (!SSL_is_dtls(s))
504 s->s3->flags |= SSL3_FLAGS_CCS_OK;
505 s->s3->hs.state = SSL3_ST_CW_FLUSH;
506
507 /* clear flags */
508 if (s->hit) {
509 s->s3->hs.tls12.next_state = SSL_ST_OK;
510 } else {
511 /* Allow NewSessionTicket if ticket expected */
512 if (s->tlsext_ticket_expected)
513 s->s3->hs.tls12.next_state =
514 SSL3_ST_CR_SESSION_TICKET_A;
515 else
516 s->s3->hs.tls12.next_state =
517 SSL3_ST_CR_FINISHED_A;
518 }
519 s->init_num = 0;
520 break;
521
522 case SSL3_ST_CR_SESSION_TICKET_A:
523 case SSL3_ST_CR_SESSION_TICKET_B:
524 ret = ssl3_get_new_session_ticket(s);
525 if (ret <= 0)
526 goto end;
527 s->s3->hs.state = SSL3_ST_CR_FINISHED_A;
528 s->init_num = 0;
529 break;
530
531 case SSL3_ST_CR_CERT_STATUS_A:
532 case SSL3_ST_CR_CERT_STATUS_B:
533 ret = ssl3_get_cert_status(s);
534 if (ret <= 0)
535 goto end;
536 s->s3->hs.state = SSL3_ST_CR_KEY_EXCH_A;
537 s->init_num = 0;
538 break;
539
540 case SSL3_ST_CR_FINISHED_A:
541 case SSL3_ST_CR_FINISHED_B:
542 if (SSL_is_dtls(s))
543 s->d1->change_cipher_spec_ok = 1;
544 else
545 s->s3->flags |= SSL3_FLAGS_CCS_OK;
546 ret = ssl3_get_server_finished(s);
547 if (ret <= 0)
548 goto end;
549 if (SSL_is_dtls(s))
550 dtls1_stop_timer(s);
551
552 if (s->hit)
553 s->s3->hs.state = SSL3_ST_CW_CHANGE_A;
554 else
555 s->s3->hs.state = SSL_ST_OK;
556 s->init_num = 0;
557 break;
558
559 case SSL3_ST_CW_FLUSH:
560 s->rwstate = SSL_WRITING;
561 if (BIO_flush(s->wbio) <= 0) {
562 if (SSL_is_dtls(s)) {
563 /* If the write error was fatal, stop trying */
564 if (!BIO_should_retry(s->wbio)) {
565 s->rwstate = SSL_NOTHING;
566 s->s3->hs.state = s->s3->hs.tls12.next_state;
567 }
568 }
569 ret = -1;
570 goto end;
571 }
572 s->rwstate = SSL_NOTHING;
573 s->s3->hs.state = s->s3->hs.tls12.next_state;
574 break;
575
576 case SSL_ST_OK:
577 /* clean a few things up */
578 tls1_cleanup_key_block(s);
579
580 if (s->s3->handshake_transcript != NULL) {
581 SSLerror(s, ERR_R_INTERNAL_ERROR);
582 ret = -1;
583 goto end;
584 }
585
586 if (!SSL_is_dtls(s))
587 ssl3_release_init_buffer(s);
588
589 ssl_free_wbio_buffer(s);
590
591 s->init_num = 0;
592 s->renegotiate = 0;
593 s->new_session = 0;
594
595 ssl_update_cache(s, SSL_SESS_CACHE_CLIENT);
596 if (s->hit)
597 s->ctx->stats.sess_hit++;
598
599 ret = 1;
600 /* s->server=0; */
601 s->handshake_func = ssl3_connect;
602 s->ctx->stats.sess_connect_good++;
603
604 ssl_info_callback(s, SSL_CB_HANDSHAKE_DONE, 1);
605
606 if (SSL_is_dtls(s)) {
607 /* done with handshaking */
608 s->d1->handshake_read_seq = 0;
609 s->d1->next_handshake_write_seq = 0;
610 }
611
612 goto end;
613 /* break; */
614
615 default:
616 SSLerror(s, SSL_R_UNKNOWN_STATE);
617 ret = -1;
618 goto end;
619 /* break; */
620 }
621
622 /* did we do anything */
623 if (!s->s3->hs.tls12.reuse_message && !skip) {
624 if (s->s3->hs.state != state) {
625 new_state = s->s3->hs.state;
626 s->s3->hs.state = state;
627 ssl_info_callback(s, SSL_CB_CONNECT_LOOP, 1);
628 s->s3->hs.state = new_state;
629 }
630 }
631 skip = 0;
632 }
633
634 end:
635 s->in_handshake--;
636 ssl_info_callback(s, SSL_CB_CONNECT_EXIT, ret);
637
638 return (ret);
639}
640
641static int
642ssl3_send_client_hello(SSL *s)
643{
644 CBB cbb, client_hello, session_id, cookie, cipher_suites;
645 CBB compression_methods;
646 uint16_t max_version;
647 size_t sl;
648
649 memset(&cbb, 0, sizeof(cbb));
650
651 if (s->s3->hs.state == SSL3_ST_CW_CLNT_HELLO_A) {
652 SSL_SESSION *sess = s->session;
653
654 if (!ssl_max_supported_version(s, &max_version)) {
655 SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE);
656 return (-1);
657 }
658 s->version = max_version;
659
660 if (sess == NULL || sess->ssl_version != s->version ||
661 (sess->session_id_length == 0 && sess->tlsext_tick == NULL) ||
662 sess->not_resumable) {
663 if (!ssl_get_new_session(s, 0))
664 goto err;
665 }
666 /* else use the pre-loaded session */
667
668 /*
669 * If a DTLS ClientHello message is being resent after a
670 * HelloVerifyRequest, we must retain the original client
671 * random value.
672 */
673 if (!SSL_is_dtls(s) || s->d1->send_cookie == 0)
674 arc4random_buf(s->s3->client_random, SSL3_RANDOM_SIZE);
675
676 if (!ssl3_handshake_msg_start(s, &cbb, &client_hello,
677 SSL3_MT_CLIENT_HELLO))
678 goto err;
679
680 if (!CBB_add_u16(&client_hello, s->version))
681 goto err;
682
683 /* Random stuff */
684 if (!CBB_add_bytes(&client_hello, s->s3->client_random,
685 sizeof(s->s3->client_random)))
686 goto err;
687
688 /* Session ID */
689 if (!CBB_add_u8_length_prefixed(&client_hello, &session_id))
690 goto err;
691 if (!s->new_session &&
692 s->session->session_id_length > 0) {
693 sl = s->session->session_id_length;
694 if (sl > sizeof(s->session->session_id)) {
695 SSLerror(s, ERR_R_INTERNAL_ERROR);
696 goto err;
697 }
698 if (!CBB_add_bytes(&session_id,
699 s->session->session_id, sl))
700 goto err;
701 }
702
703 /* DTLS Cookie. */
704 if (SSL_is_dtls(s)) {
705 if (s->d1->cookie_len > sizeof(s->d1->cookie)) {
706 SSLerror(s, ERR_R_INTERNAL_ERROR);
707 goto err;
708 }
709 if (!CBB_add_u8_length_prefixed(&client_hello, &cookie))
710 goto err;
711 if (!CBB_add_bytes(&cookie, s->d1->cookie,
712 s->d1->cookie_len))
713 goto err;
714 }
715
716 /* Ciphers supported */
717 if (!CBB_add_u16_length_prefixed(&client_hello, &cipher_suites))
718 return 0;
719 if (!ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s),
720 &cipher_suites)) {
721 SSLerror(s, SSL_R_NO_CIPHERS_AVAILABLE);
722 goto err;
723 }
724
725 /* Add in compression methods (null) */
726 if (!CBB_add_u8_length_prefixed(&client_hello,
727 &compression_methods))
728 goto err;
729 if (!CBB_add_u8(&compression_methods, 0))
730 goto err;
731
732 /* TLS extensions */
733 if (!tlsext_client_build(s, SSL_TLSEXT_MSG_CH, &client_hello)) {
734 SSLerror(s, ERR_R_INTERNAL_ERROR);
735 goto err;
736 }
737
738 if (!ssl3_handshake_msg_finish(s, &cbb))
739 goto err;
740
741 s->s3->hs.state = SSL3_ST_CW_CLNT_HELLO_B;
742 }
743
744 /* SSL3_ST_CW_CLNT_HELLO_B */
745 return (ssl3_handshake_write(s));
746
747 err:
748 CBB_cleanup(&cbb);
749
750 return (-1);
751}
752
753static int
754ssl3_get_dtls_hello_verify(SSL *s)
755{
756 CBS hello_verify_request, cookie;
757 size_t cookie_len;
758 uint16_t ssl_version;
759 int al, ret;
760
761 if ((ret = ssl3_get_message(s, DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A,
762 DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B, -1, s->max_cert_list)) <= 0)
763 return ret;
764
765 if (s->s3->hs.tls12.message_type != DTLS1_MT_HELLO_VERIFY_REQUEST) {
766 s->d1->send_cookie = 0;
767 s->s3->hs.tls12.reuse_message = 1;
768 return (1);
769 }
770
771 if (s->init_num < 0)
772 goto decode_err;
773
774 CBS_init(&hello_verify_request, s->init_msg,
775 s->init_num);
776
777 if (!CBS_get_u16(&hello_verify_request, &ssl_version))
778 goto decode_err;
779 if (!CBS_get_u8_length_prefixed(&hello_verify_request, &cookie))
780 goto decode_err;
781 if (CBS_len(&hello_verify_request) != 0)
782 goto decode_err;
783
784 /*
785 * Per RFC 6347 section 4.2.1, the HelloVerifyRequest should always
786 * contain DTLSv1.0 the version that is going to be negotiated.
787 * Tolerate DTLSv1.2 just in case.
788 */
789 if (ssl_version != DTLS1_VERSION && ssl_version != DTLS1_2_VERSION) {
790 SSLerror(s, SSL_R_WRONG_SSL_VERSION);
791 s->version = (s->version & 0xff00) | (ssl_version & 0xff);
792 al = SSL_AD_PROTOCOL_VERSION;
793 goto fatal_err;
794 }
795
796 if (!CBS_write_bytes(&cookie, s->d1->cookie,
797 sizeof(s->d1->cookie), &cookie_len)) {
798 s->d1->cookie_len = 0;
799 al = SSL_AD_ILLEGAL_PARAMETER;
800 goto fatal_err;
801 }
802 s->d1->cookie_len = cookie_len;
803 s->d1->send_cookie = 1;
804
805 return 1;
806
807 decode_err:
808 al = SSL_AD_DECODE_ERROR;
809 fatal_err:
810 ssl3_send_alert(s, SSL3_AL_FATAL, al);
811 return -1;
812}
813
814static int
815ssl3_get_server_hello(SSL *s)
816{
817 CBS cbs, server_random, session_id;
818 uint16_t server_version, cipher_suite;
819 uint8_t compression_method;
820 const SSL_CIPHER *cipher;
821 const SSL_METHOD *method;
822 int al, ret;
823
824 s->first_packet = 1;
825 if ((ret = ssl3_get_message(s, SSL3_ST_CR_SRVR_HELLO_A,
826 SSL3_ST_CR_SRVR_HELLO_B, -1, 20000 /* ?? */)) <= 0)
827 return ret;
828 s->first_packet = 0;
829
830 if (s->init_num < 0)
831 goto decode_err;
832
833 CBS_init(&cbs, s->init_msg, s->init_num);
834
835 if (SSL_is_dtls(s)) {
836 if (s->s3->hs.tls12.message_type == DTLS1_MT_HELLO_VERIFY_REQUEST) {
837 if (s->d1->send_cookie == 0) {
838 s->s3->hs.tls12.reuse_message = 1;
839 return (1);
840 } else {
841 /* Already sent a cookie. */
842 al = SSL_AD_UNEXPECTED_MESSAGE;
843 SSLerror(s, SSL_R_BAD_MESSAGE_TYPE);
844 goto fatal_err;
845 }
846 }
847 }
848
849 if (s->s3->hs.tls12.message_type != SSL3_MT_SERVER_HELLO) {
850 al = SSL_AD_UNEXPECTED_MESSAGE;
851 SSLerror(s, SSL_R_BAD_MESSAGE_TYPE);
852 goto fatal_err;
853 }
854
855 if (!CBS_get_u16(&cbs, &server_version))
856 goto decode_err;
857
858 if (!ssl_check_version_from_server(s, server_version)) {
859 SSLerror(s, SSL_R_WRONG_SSL_VERSION);
860 s->version = (s->version & 0xff00) | (server_version & 0xff);
861 al = SSL_AD_PROTOCOL_VERSION;
862 goto fatal_err;
863 }
864 s->s3->hs.peer_legacy_version = server_version;
865 s->version = server_version;
866
867 s->s3->hs.negotiated_tls_version = ssl_tls_version(server_version);
868 if (s->s3->hs.negotiated_tls_version == 0) {
869 SSLerror(s, ERR_R_INTERNAL_ERROR);
870 goto err;
871 }
872
873 if ((method = ssl_get_method(server_version)) == NULL) {
874 SSLerror(s, ERR_R_INTERNAL_ERROR);
875 goto err;
876 }
877 s->method = method;
878
879 /* Server random. */
880 if (!CBS_get_bytes(&cbs, &server_random, SSL3_RANDOM_SIZE))
881 goto decode_err;
882 if (!CBS_write_bytes(&server_random, s->s3->server_random,
883 sizeof(s->s3->server_random), NULL))
884 goto err;
885
886 if (s->s3->hs.our_max_tls_version >= TLS1_2_VERSION &&
887 s->s3->hs.negotiated_tls_version < s->s3->hs.our_max_tls_version) {
888 /*
889 * RFC 8446 section 4.1.3. We must not downgrade if the server
890 * random value contains the TLS 1.2 or TLS 1.1 magical value.
891 */
892 if (!CBS_skip(&server_random,
893 CBS_len(&server_random) - sizeof(tls13_downgrade_12)))
894 goto err;
895 if (s->s3->hs.negotiated_tls_version == TLS1_2_VERSION &&
896 CBS_mem_equal(&server_random, tls13_downgrade_12,
897 sizeof(tls13_downgrade_12))) {
898 al = SSL_AD_ILLEGAL_PARAMETER;
899 SSLerror(s, SSL_R_INAPPROPRIATE_FALLBACK);
900 goto fatal_err;
901 }
902 if (CBS_mem_equal(&server_random, tls13_downgrade_11,
903 sizeof(tls13_downgrade_11))) {
904 al = SSL_AD_ILLEGAL_PARAMETER;
905 SSLerror(s, SSL_R_INAPPROPRIATE_FALLBACK);
906 goto fatal_err;
907 }
908 }
909
910 /* Session ID. */
911 if (!CBS_get_u8_length_prefixed(&cbs, &session_id))
912 goto decode_err;
913
914 if (CBS_len(&session_id) > SSL3_SESSION_ID_SIZE) {
915 al = SSL_AD_ILLEGAL_PARAMETER;
916 SSLerror(s, SSL_R_SSL3_SESSION_ID_TOO_LONG);
917 goto fatal_err;
918 }
919
920 /* Cipher suite. */
921 if (!CBS_get_u16(&cbs, &cipher_suite))
922 goto decode_err;
923
924 /*
925 * Check if we want to resume the session based on external
926 * pre-shared secret.
927 */
928 if (s->tls_session_secret_cb != NULL) {
929 const SSL_CIPHER *pref_cipher = NULL;
930 int master_key_length = sizeof(s->session->master_key);
931
932 if (!s->tls_session_secret_cb(s,
933 s->session->master_key, &master_key_length, NULL,
934 &pref_cipher, s->tls_session_secret_cb_arg)) {
935 SSLerror(s, ERR_R_INTERNAL_ERROR);
936 goto err;
937 }
938 if (master_key_length <= 0) {
939 SSLerror(s, ERR_R_INTERNAL_ERROR);
940 goto err;
941 }
942 s->session->master_key_length = master_key_length;
943
944 /*
945 * XXX - this appears to be completely broken. The
946 * client cannot change the cipher at this stage,
947 * as the server has already made a selection.
948 */
949 if ((s->s3->hs.cipher = pref_cipher) == NULL)
950 s->s3->hs.cipher =
951 ssl3_get_cipher_by_value(cipher_suite);
952 s->s3->flags |= SSL3_FLAGS_CCS_OK;
953 }
954
955 if (s->session->session_id_length != 0 &&
956 CBS_mem_equal(&session_id, s->session->session_id,
957 s->session->session_id_length)) {
958 if (s->sid_ctx_length != s->session->sid_ctx_length ||
959 timingsafe_memcmp(s->session->sid_ctx,
960 s->sid_ctx, s->sid_ctx_length) != 0) {
961 /* actually a client application bug */
962 al = SSL_AD_ILLEGAL_PARAMETER;
963 SSLerror(s, SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT);
964 goto fatal_err;
965 }
966 s->s3->flags |= SSL3_FLAGS_CCS_OK;
967 s->hit = 1;
968 } else {
969 /* a miss or crap from the other end */
970
971 /* If we were trying for session-id reuse, make a new
972 * SSL_SESSION so we don't stuff up other people */
973 s->hit = 0;
974 if (s->session->session_id_length > 0) {
975 if (!ssl_get_new_session(s, 0)) {
976 al = SSL_AD_INTERNAL_ERROR;
977 goto fatal_err;
978 }
979 }
980
981 /*
982 * XXX - improve the handling for the case where there is a
983 * zero length session identifier.
984 */
985 if (!CBS_write_bytes(&session_id, s->session->session_id,
986 sizeof(s->session->session_id),
987 &s->session->session_id_length))
988 goto err;
989
990 s->session->ssl_version = s->version;
991 }
992
993 if ((cipher = ssl3_get_cipher_by_value(cipher_suite)) == NULL) {
994 al = SSL_AD_ILLEGAL_PARAMETER;
995 SSLerror(s, SSL_R_UNKNOWN_CIPHER_RETURNED);
996 goto fatal_err;
997 }
998
999 /* TLS v1.2 only ciphersuites require v1.2 or later. */
1000 if ((cipher->algorithm_ssl & SSL_TLSV1_2) &&
1001 s->s3->hs.negotiated_tls_version < TLS1_2_VERSION) {
1002 al = SSL_AD_ILLEGAL_PARAMETER;
1003 SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED);
1004 goto fatal_err;
1005 }
1006
1007 if (!ssl_cipher_in_list(SSL_get_ciphers(s), cipher)) {
1008 /* we did not say we would use this cipher */
1009 al = SSL_AD_ILLEGAL_PARAMETER;
1010 SSLerror(s, SSL_R_WRONG_CIPHER_RETURNED);
1011 goto fatal_err;
1012 }
1013
1014 /*
1015 * Depending on the session caching (internal/external), the cipher
1016 * and/or cipher_id values may not be set. Make sure that
1017 * cipher_id is set and use it for comparison.
1018 */
1019 if (s->hit && (s->session->cipher_value != cipher->value)) {
1020 al = SSL_AD_ILLEGAL_PARAMETER;
1021 SSLerror(s, SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED);
1022 goto fatal_err;
1023 }
1024 s->s3->hs.cipher = cipher;
1025 s->session->cipher_value = cipher->value;
1026
1027 if (!tls1_transcript_hash_init(s))
1028 goto err;
1029
1030 /*
1031 * Don't digest cached records if no sigalgs: we may need them for
1032 * client authentication.
1033 */
1034 if (!SSL_USE_SIGALGS(s))
1035 tls1_transcript_free(s);
1036
1037 if (!CBS_get_u8(&cbs, &compression_method))
1038 goto decode_err;
1039
1040 if (compression_method != 0) {
1041 al = SSL_AD_ILLEGAL_PARAMETER;
1042 SSLerror(s, SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM);
1043 goto fatal_err;
1044 }
1045
1046 if (!tlsext_client_parse(s, SSL_TLSEXT_MSG_SH, &cbs, &al)) {
1047 SSLerror(s, SSL_R_PARSE_TLSEXT);
1048 goto fatal_err;
1049 }
1050
1051 if (CBS_len(&cbs) != 0)
1052 goto decode_err;
1053
1054 /*
1055 * Determine if we need to see RI. Strictly speaking if we want to
1056 * avoid an attack we should *always* see RI even on initial server
1057 * hello because the client doesn't see any renegotiation during an
1058 * attack. However this would mean we could not connect to any server
1059 * which doesn't support RI so for the immediate future tolerate RI
1060 * absence on initial connect only.
1061 */
1062 if (!s->s3->renegotiate_seen &&
1063 !(s->options & SSL_OP_LEGACY_SERVER_CONNECT)) {
1064 al = SSL_AD_HANDSHAKE_FAILURE;
1065 SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
1066 goto fatal_err;
1067 }
1068
1069 if (ssl_check_serverhello_tlsext(s) <= 0) {
1070 SSLerror(s, SSL_R_SERVERHELLO_TLSEXT);
1071 goto err;
1072 }
1073
1074 return (1);
1075
1076 decode_err:
1077 /* wrong packet length */
1078 al = SSL_AD_DECODE_ERROR;
1079 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1080 fatal_err:
1081 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1082 err:
1083 return (-1);
1084}
1085
1086static int
1087ssl3_get_server_certificate(SSL *s)
1088{
1089 CBS cbs, cert_list, cert_data;
1090 STACK_OF(X509) *certs = NULL;
1091 X509 *cert = NULL;
1092 const uint8_t *p;
1093 int al, ret;
1094
1095 if ((ret = ssl3_get_message(s, SSL3_ST_CR_CERT_A,
1096 SSL3_ST_CR_CERT_B, -1, s->max_cert_list)) <= 0)
1097 return ret;
1098
1099 ret = -1;
1100
1101 if (s->s3->hs.tls12.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) {
1102 s->s3->hs.tls12.reuse_message = 1;
1103 return (1);
1104 }
1105
1106 if (s->s3->hs.tls12.message_type != SSL3_MT_CERTIFICATE) {
1107 al = SSL_AD_UNEXPECTED_MESSAGE;
1108 SSLerror(s, SSL_R_BAD_MESSAGE_TYPE);
1109 goto fatal_err;
1110 }
1111
1112 if ((certs = sk_X509_new_null()) == NULL) {
1113 SSLerror(s, ERR_R_MALLOC_FAILURE);
1114 goto err;
1115 }
1116
1117 if (s->init_num < 0)
1118 goto decode_err;
1119
1120 CBS_init(&cbs, s->init_msg, s->init_num);
1121
1122 if (!CBS_get_u24_length_prefixed(&cbs, &cert_list))
1123 goto decode_err;
1124 if (CBS_len(&cbs) != 0)
1125 goto decode_err;
1126
1127 while (CBS_len(&cert_list) > 0) {
1128 if (!CBS_get_u24_length_prefixed(&cert_list, &cert_data))
1129 goto decode_err;
1130 p = CBS_data(&cert_data);
1131 if ((cert = d2i_X509(NULL, &p, CBS_len(&cert_data))) == NULL) {
1132 al = SSL_AD_BAD_CERTIFICATE;
1133 SSLerror(s, ERR_R_ASN1_LIB);
1134 goto fatal_err;
1135 }
1136 if (p != CBS_data(&cert_data) + CBS_len(&cert_data))
1137 goto decode_err;
1138 if (!sk_X509_push(certs, cert)) {
1139 SSLerror(s, ERR_R_MALLOC_FAILURE);
1140 goto err;
1141 }
1142 cert = NULL;
1143 }
1144
1145 /* A server must always provide a non-empty certificate list. */
1146 if (sk_X509_num(certs) < 1) {
1147 SSLerror(s, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
1148 goto decode_err;
1149 }
1150
1151 if (ssl_verify_cert_chain(s, certs) <= 0 &&
1152 s->verify_mode != SSL_VERIFY_NONE) {
1153 al = ssl_verify_alarm_type(s->verify_result);
1154 SSLerror(s, SSL_R_CERTIFICATE_VERIFY_FAILED);
1155 goto fatal_err;
1156 }
1157 s->session->verify_result = s->verify_result;
1158 ERR_clear_error();
1159
1160 if (!tls_process_peer_certs(s, certs))
1161 goto err;
1162
1163 ret = 1;
1164
1165 if (0) {
1166 decode_err:
1167 /* wrong packet length */
1168 al = SSL_AD_DECODE_ERROR;
1169 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1170 fatal_err:
1171 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1172 }
1173 err:
1174 sk_X509_pop_free(certs, X509_free);
1175 X509_free(cert);
1176
1177 return (ret);
1178}
1179
1180static int
1181ssl3_get_server_kex_dhe(SSL *s, CBS *cbs)
1182{
1183 int decode_error, invalid_params, invalid_key;
1184 int nid = NID_dhKeyAgreement;
1185
1186 tls_key_share_free(s->s3->hs.key_share);
1187 if ((s->s3->hs.key_share = tls_key_share_new_nid(nid)) == NULL)
1188 goto err;
1189
1190 if (!tls_key_share_peer_params(s->s3->hs.key_share, cbs,
1191 &decode_error, &invalid_params)) {
1192 if (decode_error) {
1193 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1194 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1195 }
1196 goto err;
1197 }
1198 if (!tls_key_share_peer_public(s->s3->hs.key_share, cbs,
1199 &decode_error, &invalid_key)) {
1200 if (decode_error) {
1201 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1202 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1203 }
1204 goto err;
1205 }
1206
1207 if (invalid_params) {
1208 SSLerror(s, SSL_R_BAD_DH_P_LENGTH);
1209 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
1210 goto err;
1211 }
1212 if (invalid_key) {
1213 SSLerror(s, SSL_R_BAD_DH_PUB_KEY_LENGTH);
1214 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
1215 goto err;
1216 }
1217
1218 if (!tls_key_share_peer_security(s, s->s3->hs.key_share)) {
1219 SSLerror(s, SSL_R_DH_KEY_TOO_SMALL);
1220 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1221 return 0;
1222 }
1223
1224 return 1;
1225
1226 err:
1227 return 0;
1228}
1229
1230static int
1231ssl3_get_server_kex_ecdhe(SSL *s, CBS *cbs)
1232{
1233 uint8_t curve_type;
1234 uint16_t group_id;
1235 int decode_error;
1236 CBS public;
1237
1238 if (!CBS_get_u8(cbs, &curve_type))
1239 goto decode_err;
1240 if (!CBS_get_u16(cbs, &group_id))
1241 goto decode_err;
1242
1243 /* Only named curves are supported. */
1244 if (curve_type != NAMED_CURVE_TYPE) {
1245 SSLerror(s, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
1246 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1247 goto err;
1248 }
1249
1250 if (!CBS_get_u8_length_prefixed(cbs, &public))
1251 goto decode_err;
1252
1253 /*
1254 * Check that the group is one of our preferences - if it is not,
1255 * the server has sent us an invalid group.
1256 */
1257 if (!tls1_check_group(s, group_id)) {
1258 SSLerror(s, SSL_R_WRONG_CURVE);
1259 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
1260 goto err;
1261 }
1262
1263 tls_key_share_free(s->s3->hs.key_share);
1264 if ((s->s3->hs.key_share = tls_key_share_new(group_id)) == NULL)
1265 goto err;
1266
1267 if (!tls_key_share_peer_public(s->s3->hs.key_share, &public,
1268 &decode_error, NULL)) {
1269 if (decode_error)
1270 goto decode_err;
1271 goto err;
1272 }
1273
1274 return 1;
1275
1276 decode_err:
1277 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1278 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1279 err:
1280 return 0;
1281}
1282
1283static int
1284ssl3_get_server_key_exchange(SSL *s)
1285{
1286 CBB cbb;
1287 CBS cbs, params, signature;
1288 EVP_MD_CTX *md_ctx;
1289 unsigned char *signed_params = NULL;
1290 size_t signed_params_len;
1291 size_t params_len;
1292 long alg_k, alg_a;
1293 int al, ret;
1294
1295 memset(&cbb, 0, sizeof(cbb));
1296
1297 alg_k = s->s3->hs.cipher->algorithm_mkey;
1298 alg_a = s->s3->hs.cipher->algorithm_auth;
1299
1300 /*
1301 * Use same message size as in ssl3_get_certificate_request()
1302 * as ServerKeyExchange message may be skipped.
1303 */
1304 if ((ret = ssl3_get_message(s, SSL3_ST_CR_KEY_EXCH_A,
1305 SSL3_ST_CR_KEY_EXCH_B, -1, s->max_cert_list)) <= 0)
1306 return ret;
1307
1308 if ((md_ctx = EVP_MD_CTX_new()) == NULL)
1309 goto err;
1310
1311 if (s->init_num < 0)
1312 goto err;
1313
1314 CBS_init(&cbs, s->init_msg, s->init_num);
1315
1316 if (s->s3->hs.tls12.message_type != SSL3_MT_SERVER_KEY_EXCHANGE) {
1317 /*
1318 * Do not skip server key exchange if this cipher suite uses
1319 * ephemeral keys.
1320 */
1321 if (alg_k & (SSL_kDHE|SSL_kECDHE)) {
1322 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
1323 al = SSL_AD_UNEXPECTED_MESSAGE;
1324 goto fatal_err;
1325 }
1326
1327 s->s3->hs.tls12.reuse_message = 1;
1328 EVP_MD_CTX_free(md_ctx);
1329 return (1);
1330 }
1331
1332 if (!CBB_init(&cbb, 0))
1333 goto err;
1334 if (!CBB_add_bytes(&cbb, s->s3->client_random, SSL3_RANDOM_SIZE))
1335 goto err;
1336 if (!CBB_add_bytes(&cbb, s->s3->server_random, SSL3_RANDOM_SIZE))
1337 goto err;
1338
1339 CBS_dup(&cbs, &params);
1340
1341 if (alg_k & SSL_kDHE) {
1342 if (!ssl3_get_server_kex_dhe(s, &cbs))
1343 goto err;
1344 } else if (alg_k & SSL_kECDHE) {
1345 if (!ssl3_get_server_kex_ecdhe(s, &cbs))
1346 goto err;
1347 } else if (alg_k != 0) {
1348 al = SSL_AD_UNEXPECTED_MESSAGE;
1349 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
1350 goto fatal_err;
1351 }
1352
1353 if ((params_len = CBS_offset(&cbs)) > CBS_len(&params))
1354 goto err;
1355 if (!CBB_add_bytes(&cbb, CBS_data(&params), params_len))
1356 goto err;
1357 if (!CBB_finish(&cbb, &signed_params, &signed_params_len))
1358 goto err;
1359
1360 /* if it was signed, check the signature */
1361 if ((alg_a & SSL_aNULL) == 0) {
1362 uint16_t sigalg_value = SIGALG_NONE;
1363 const struct ssl_sigalg *sigalg;
1364 EVP_PKEY_CTX *pctx;
1365 EVP_PKEY *pkey = NULL;
1366
1367 if ((alg_a & SSL_aRSA) != 0 &&
1368 s->session->peer_cert_type == SSL_PKEY_RSA) {
1369 pkey = X509_get0_pubkey(s->session->peer_cert);
1370 } else if ((alg_a & SSL_aECDSA) != 0 &&
1371 s->session->peer_cert_type == SSL_PKEY_ECC) {
1372 pkey = X509_get0_pubkey(s->session->peer_cert);
1373 }
1374 if (pkey == NULL) {
1375 al = SSL_AD_ILLEGAL_PARAMETER;
1376 SSLerror(s, SSL_R_UNKNOWN_CERTIFICATE_TYPE);
1377 goto fatal_err;
1378 }
1379
1380 if (SSL_USE_SIGALGS(s)) {
1381 if (!CBS_get_u16(&cbs, &sigalg_value))
1382 goto decode_err;
1383 }
1384 if (!CBS_get_u16_length_prefixed(&cbs, &signature))
1385 goto decode_err;
1386 if (CBS_len(&signature) > EVP_PKEY_size(pkey)) {
1387 al = SSL_AD_DECODE_ERROR;
1388 SSLerror(s, SSL_R_WRONG_SIGNATURE_LENGTH);
1389 goto fatal_err;
1390 }
1391
1392 if ((sigalg = ssl_sigalg_for_peer(s, pkey,
1393 sigalg_value)) == NULL) {
1394 al = SSL_AD_DECODE_ERROR;
1395 goto fatal_err;
1396 }
1397 s->s3->hs.peer_sigalg = sigalg;
1398
1399 if (!EVP_DigestVerifyInit(md_ctx, &pctx, sigalg->md(),
1400 NULL, pkey))
1401 goto err;
1402 if ((sigalg->flags & SIGALG_FLAG_RSA_PSS) &&
1403 (!EVP_PKEY_CTX_set_rsa_padding(pctx,
1404 RSA_PKCS1_PSS_PADDING) ||
1405 !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1)))
1406 goto err;
1407 if (EVP_DigestVerify(md_ctx, CBS_data(&signature),
1408 CBS_len(&signature), signed_params, signed_params_len) <= 0) {
1409 al = SSL_AD_DECRYPT_ERROR;
1410 SSLerror(s, SSL_R_BAD_SIGNATURE);
1411 goto fatal_err;
1412 }
1413 }
1414
1415 if (CBS_len(&cbs) != 0) {
1416 al = SSL_AD_DECODE_ERROR;
1417 SSLerror(s, SSL_R_EXTRA_DATA_IN_MESSAGE);
1418 goto fatal_err;
1419 }
1420
1421 EVP_MD_CTX_free(md_ctx);
1422 free(signed_params);
1423
1424 return (1);
1425
1426 decode_err:
1427 al = SSL_AD_DECODE_ERROR;
1428 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1429
1430 fatal_err:
1431 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1432
1433 err:
1434 CBB_cleanup(&cbb);
1435 EVP_MD_CTX_free(md_ctx);
1436 free(signed_params);
1437
1438 return (-1);
1439}
1440
1441static int
1442ssl3_get_certificate_request(SSL *s)
1443{
1444 CBS cert_request, cert_types, rdn_list;
1445 X509_NAME *xn = NULL;
1446 const unsigned char *q;
1447 STACK_OF(X509_NAME) *ca_sk = NULL;
1448 int ret;
1449
1450 if ((ret = ssl3_get_message(s, SSL3_ST_CR_CERT_REQ_A,
1451 SSL3_ST_CR_CERT_REQ_B, -1, s->max_cert_list)) <= 0)
1452 return ret;
1453
1454 ret = 0;
1455
1456 s->s3->hs.tls12.cert_request = 0;
1457
1458 if (s->s3->hs.tls12.message_type == SSL3_MT_SERVER_DONE) {
1459 s->s3->hs.tls12.reuse_message = 1;
1460 /*
1461 * If we get here we don't need any cached handshake records
1462 * as we wont be doing client auth.
1463 */
1464 tls1_transcript_free(s);
1465 return (1);
1466 }
1467
1468 if (s->s3->hs.tls12.message_type != SSL3_MT_CERTIFICATE_REQUEST) {
1469 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1470 SSLerror(s, SSL_R_WRONG_MESSAGE_TYPE);
1471 goto err;
1472 }
1473
1474 /* TLS does not like anon-DH with client cert */
1475 if (s->s3->hs.cipher->algorithm_auth & SSL_aNULL) {
1476 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1477 SSLerror(s, SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER);
1478 goto err;
1479 }
1480
1481 if (s->init_num < 0)
1482 goto decode_err;
1483 CBS_init(&cert_request, s->init_msg, s->init_num);
1484
1485 if ((ca_sk = sk_X509_NAME_new(ca_dn_cmp)) == NULL) {
1486 SSLerror(s, ERR_R_MALLOC_FAILURE);
1487 goto err;
1488 }
1489
1490 if (!CBS_get_u8_length_prefixed(&cert_request, &cert_types))
1491 goto decode_err;
1492
1493 if (SSL_USE_SIGALGS(s)) {
1494 CBS sigalgs;
1495
1496 if (CBS_len(&cert_request) < 2) {
1497 SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG);
1498 goto err;
1499 }
1500 if (!CBS_get_u16_length_prefixed(&cert_request, &sigalgs)) {
1501 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1502 SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG);
1503 goto err;
1504 }
1505 if (CBS_len(&sigalgs) % 2 != 0 || CBS_len(&sigalgs) > 64) {
1506 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1507 SSLerror(s, SSL_R_SIGNATURE_ALGORITHMS_ERROR);
1508 goto err;
1509 }
1510 if (!CBS_stow(&sigalgs, &s->s3->hs.sigalgs,
1511 &s->s3->hs.sigalgs_len))
1512 goto err;
1513 }
1514
1515 /* get the CA RDNs */
1516 if (CBS_len(&cert_request) < 2) {
1517 SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG);
1518 goto err;
1519 }
1520
1521 if (!CBS_get_u16_length_prefixed(&cert_request, &rdn_list) ||
1522 CBS_len(&cert_request) != 0) {
1523 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1524 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1525 goto err;
1526 }
1527
1528 while (CBS_len(&rdn_list) > 0) {
1529 CBS rdn;
1530
1531 if (CBS_len(&rdn_list) < 2) {
1532 SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG);
1533 goto err;
1534 }
1535
1536 if (!CBS_get_u16_length_prefixed(&rdn_list, &rdn)) {
1537 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1538 SSLerror(s, SSL_R_CA_DN_TOO_LONG);
1539 goto err;
1540 }
1541
1542 q = CBS_data(&rdn);
1543 if ((xn = d2i_X509_NAME(NULL, &q, CBS_len(&rdn))) == NULL) {
1544 ssl3_send_alert(s, SSL3_AL_FATAL,
1545 SSL_AD_DECODE_ERROR);
1546 SSLerror(s, ERR_R_ASN1_LIB);
1547 goto err;
1548 }
1549
1550 if (q != CBS_data(&rdn) + CBS_len(&rdn)) {
1551 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1552 SSLerror(s, SSL_R_CA_DN_LENGTH_MISMATCH);
1553 goto err;
1554 }
1555 if (!sk_X509_NAME_push(ca_sk, xn)) {
1556 SSLerror(s, ERR_R_MALLOC_FAILURE);
1557 goto err;
1558 }
1559 xn = NULL; /* avoid free in err block */
1560 }
1561
1562 /* we should setup a certificate to return.... */
1563 s->s3->hs.tls12.cert_request = 1;
1564 sk_X509_NAME_pop_free(s->s3->hs.tls12.ca_names, X509_NAME_free);
1565 s->s3->hs.tls12.ca_names = ca_sk;
1566 ca_sk = NULL;
1567
1568 ret = 1;
1569 if (0) {
1570 decode_err:
1571 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1572 }
1573 err:
1574 X509_NAME_free(xn);
1575 sk_X509_NAME_pop_free(ca_sk, X509_NAME_free);
1576 return (ret);
1577}
1578
1579static int
1580ca_dn_cmp(const X509_NAME * const *a, const X509_NAME * const *b)
1581{
1582 return (X509_NAME_cmp(*a, *b));
1583}
1584
1585static int
1586ssl3_get_new_session_ticket(SSL *s)
1587{
1588 uint32_t lifetime_hint;
1589 CBS cbs, session_ticket;
1590 unsigned int session_id_length = 0;
1591 int al, ret;
1592
1593 if ((ret = ssl3_get_message(s, SSL3_ST_CR_SESSION_TICKET_A,
1594 SSL3_ST_CR_SESSION_TICKET_B, -1, 16384)) <= 0)
1595 return ret;
1596
1597 if (s->s3->hs.tls12.message_type == SSL3_MT_FINISHED) {
1598 s->s3->hs.tls12.reuse_message = 1;
1599 return (1);
1600 }
1601 if (s->s3->hs.tls12.message_type != SSL3_MT_NEWSESSION_TICKET) {
1602 al = SSL_AD_UNEXPECTED_MESSAGE;
1603 SSLerror(s, SSL_R_BAD_MESSAGE_TYPE);
1604 goto fatal_err;
1605 }
1606
1607 if (s->init_num < 0) {
1608 al = SSL_AD_DECODE_ERROR;
1609 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1610 goto fatal_err;
1611 }
1612
1613 CBS_init(&cbs, s->init_msg, s->init_num);
1614 if (!CBS_get_u32(&cbs, &lifetime_hint) ||
1615 !CBS_get_u16_length_prefixed(&cbs, &session_ticket) ||
1616 CBS_len(&cbs) != 0) {
1617 al = SSL_AD_DECODE_ERROR;
1618 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1619 goto fatal_err;
1620 }
1621 s->session->tlsext_tick_lifetime_hint = lifetime_hint;
1622
1623 if (!CBS_stow(&session_ticket, &s->session->tlsext_tick,
1624 &s->session->tlsext_ticklen)) {
1625 SSLerror(s, ERR_R_MALLOC_FAILURE);
1626 goto err;
1627 }
1628
1629 /*
1630 * There are two ways to detect a resumed ticket session.
1631 * One is to set an appropriate session ID and then the server
1632 * must return a match in ServerHello. This allows the normal
1633 * client session ID matching to work and we know much
1634 * earlier that the ticket has been accepted.
1635 *
1636 * The other way is to set zero length session ID when the
1637 * ticket is presented and rely on the handshake to determine
1638 * session resumption.
1639 *
1640 * We choose the former approach because this fits in with
1641 * assumptions elsewhere in OpenSSL. The session ID is set
1642 * to the SHA256 hash of the ticket.
1643 */
1644 /* XXX - ensure this doesn't overflow session_id if hash is changed. */
1645 if (!EVP_Digest(CBS_data(&session_ticket), CBS_len(&session_ticket),
1646 s->session->session_id, &session_id_length, EVP_sha256(), NULL)) {
1647 al = SSL_AD_INTERNAL_ERROR;
1648 SSLerror(s, ERR_R_EVP_LIB);
1649 goto fatal_err;
1650 }
1651 s->session->session_id_length = session_id_length;
1652
1653 return (1);
1654
1655 fatal_err:
1656 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1657 err:
1658 return (-1);
1659}
1660
1661static int
1662ssl3_get_cert_status(SSL *s)
1663{
1664 CBS cert_status, response;
1665 uint8_t status_type;
1666 int al, ret;
1667
1668 if ((ret = ssl3_get_message(s, SSL3_ST_CR_CERT_STATUS_A,
1669 SSL3_ST_CR_CERT_STATUS_B, -1, 16384)) <= 0)
1670 return ret;
1671
1672 if (s->s3->hs.tls12.message_type == SSL3_MT_SERVER_KEY_EXCHANGE) {
1673 /*
1674 * Tell the callback the server did not send us an OSCP
1675 * response, and has decided to head directly to key exchange.
1676 */
1677 if (s->ctx->tlsext_status_cb) {
1678 free(s->tlsext_ocsp_resp);
1679 s->tlsext_ocsp_resp = NULL;
1680 s->tlsext_ocsp_resp_len = 0;
1681
1682 ret = s->ctx->tlsext_status_cb(s,
1683 s->ctx->tlsext_status_arg);
1684 if (ret == 0) {
1685 al = SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE;
1686 SSLerror(s, SSL_R_INVALID_STATUS_RESPONSE);
1687 goto fatal_err;
1688 }
1689 if (ret < 0) {
1690 al = SSL_AD_INTERNAL_ERROR;
1691 SSLerror(s, ERR_R_MALLOC_FAILURE);
1692 goto fatal_err;
1693 }
1694 }
1695 s->s3->hs.tls12.reuse_message = 1;
1696 return (1);
1697 }
1698
1699 if (s->s3->hs.tls12.message_type != SSL3_MT_CERTIFICATE &&
1700 s->s3->hs.tls12.message_type != SSL3_MT_CERTIFICATE_STATUS) {
1701 al = SSL_AD_UNEXPECTED_MESSAGE;
1702 SSLerror(s, SSL_R_BAD_MESSAGE_TYPE);
1703 goto fatal_err;
1704 }
1705
1706 if (s->init_num < 0) {
1707 /* need at least status type + length */
1708 al = SSL_AD_DECODE_ERROR;
1709 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1710 goto fatal_err;
1711 }
1712
1713 CBS_init(&cert_status, s->init_msg, s->init_num);
1714 if (!CBS_get_u8(&cert_status, &status_type) ||
1715 CBS_len(&cert_status) < 3) {
1716 /* need at least status type + length */
1717 al = SSL_AD_DECODE_ERROR;
1718 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1719 goto fatal_err;
1720 }
1721
1722 if (status_type != TLSEXT_STATUSTYPE_ocsp) {
1723 al = SSL_AD_DECODE_ERROR;
1724 SSLerror(s, SSL_R_UNSUPPORTED_STATUS_TYPE);
1725 goto fatal_err;
1726 }
1727
1728 if (!CBS_get_u24_length_prefixed(&cert_status, &response) ||
1729 CBS_len(&cert_status) != 0) {
1730 al = SSL_AD_DECODE_ERROR;
1731 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1732 goto fatal_err;
1733 }
1734
1735 if (!CBS_stow(&response, &s->tlsext_ocsp_resp,
1736 &s->tlsext_ocsp_resp_len)) {
1737 al = SSL_AD_INTERNAL_ERROR;
1738 SSLerror(s, ERR_R_MALLOC_FAILURE);
1739 goto fatal_err;
1740 }
1741
1742 if (s->ctx->tlsext_status_cb) {
1743 ret = s->ctx->tlsext_status_cb(s,
1744 s->ctx->tlsext_status_arg);
1745 if (ret == 0) {
1746 al = SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE;
1747 SSLerror(s, SSL_R_INVALID_STATUS_RESPONSE);
1748 goto fatal_err;
1749 }
1750 if (ret < 0) {
1751 al = SSL_AD_INTERNAL_ERROR;
1752 SSLerror(s, ERR_R_MALLOC_FAILURE);
1753 goto fatal_err;
1754 }
1755 }
1756 return (1);
1757 fatal_err:
1758 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1759 return (-1);
1760}
1761
1762static int
1763ssl3_get_server_done(SSL *s)
1764{
1765 int ret;
1766
1767 if ((ret = ssl3_get_message(s, SSL3_ST_CR_SRVR_DONE_A,
1768 SSL3_ST_CR_SRVR_DONE_B, SSL3_MT_SERVER_DONE,
1769 30 /* should be very small, like 0 :-) */)) <= 0)
1770 return ret;
1771
1772 if (s->init_num != 0) {
1773 /* should contain no data */
1774 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1775 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1776 return -1;
1777 }
1778
1779 return 1;
1780}
1781
1782static int
1783ssl3_send_client_kex_rsa(SSL *s, CBB *cbb)
1784{
1785 unsigned char pms[SSL_MAX_MASTER_KEY_LENGTH];
1786 unsigned char *enc_pms = NULL;
1787 uint16_t max_legacy_version;
1788 EVP_PKEY *pkey;
1789 RSA *rsa;
1790 int ret = 0;
1791 int enc_len;
1792 CBB epms;
1793
1794 /*
1795 * RSA-Encrypted Premaster Secret Message - RFC 5246 section 7.4.7.1.
1796 */
1797
1798 pkey = X509_get0_pubkey(s->session->peer_cert);
1799 if (pkey == NULL || (rsa = EVP_PKEY_get0_RSA(pkey)) == NULL) {
1800 SSLerror(s, ERR_R_INTERNAL_ERROR);
1801 goto err;
1802 }
1803
1804 /*
1805 * Our maximum legacy protocol version - while RFC 5246 section 7.4.7.1
1806 * says "The latest (newest) version supported by the client", if we're
1807 * doing RSA key exchange then we have to presume that we're talking to
1808 * a server that does not understand the supported versions extension
1809 * and therefore our maximum version is that sent in the ClientHello.
1810 */
1811 if (!ssl_max_legacy_version(s, &max_legacy_version))
1812 goto err;
1813 pms[0] = max_legacy_version >> 8;
1814 pms[1] = max_legacy_version & 0xff;
1815 arc4random_buf(&pms[2], sizeof(pms) - 2);
1816
1817 if ((enc_pms = malloc(RSA_size(rsa))) == NULL) {
1818 SSLerror(s, ERR_R_MALLOC_FAILURE);
1819 goto err;
1820 }
1821
1822 enc_len = RSA_public_encrypt(sizeof(pms), pms, enc_pms, rsa,
1823 RSA_PKCS1_PADDING);
1824 if (enc_len <= 0) {
1825 SSLerror(s, SSL_R_BAD_RSA_ENCRYPT);
1826 goto err;
1827 }
1828
1829 if (!CBB_add_u16_length_prefixed(cbb, &epms))
1830 goto err;
1831 if (!CBB_add_bytes(&epms, enc_pms, enc_len))
1832 goto err;
1833 if (!CBB_flush(cbb))
1834 goto err;
1835
1836 if (!tls12_derive_master_secret(s, pms, sizeof(pms)))
1837 goto err;
1838
1839 ret = 1;
1840
1841 err:
1842 explicit_bzero(pms, sizeof(pms));
1843 free(enc_pms);
1844
1845 return ret;
1846}
1847
1848static int
1849ssl3_send_client_kex_dhe(SSL *s, CBB *cbb)
1850{
1851 uint8_t *key = NULL;
1852 size_t key_len = 0;
1853 int ret = 0;
1854
1855 /* Ensure that we have an ephemeral key from the server for DHE. */
1856 if (s->s3->hs.key_share == NULL) {
1857 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1858 SSLerror(s, SSL_R_UNABLE_TO_FIND_DH_PARAMETERS);
1859 goto err;
1860 }
1861
1862 if (!tls_key_share_generate(s->s3->hs.key_share))
1863 goto err;
1864 if (!tls_key_share_public(s->s3->hs.key_share, cbb))
1865 goto err;
1866 if (!tls_key_share_derive(s->s3->hs.key_share, &key, &key_len))
1867 goto err;
1868
1869 if (!tls_key_share_peer_security(s, s->s3->hs.key_share)) {
1870 SSLerror(s, SSL_R_DH_KEY_TOO_SMALL);
1871 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1872 return 0;
1873 }
1874
1875 if (!tls12_derive_master_secret(s, key, key_len))
1876 goto err;
1877
1878 ret = 1;
1879
1880 err:
1881 freezero(key, key_len);
1882
1883 return ret;
1884}
1885
1886static int
1887ssl3_send_client_kex_ecdhe(SSL *s, CBB *cbb)
1888{
1889 uint8_t *key = NULL;
1890 size_t key_len = 0;
1891 CBB public;
1892 int ret = 0;
1893
1894 /* Ensure that we have an ephemeral key for ECDHE. */
1895 if (s->s3->hs.key_share == NULL) {
1896 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1897 SSLerror(s, ERR_R_INTERNAL_ERROR);
1898 goto err;
1899 }
1900
1901 if (!tls_key_share_generate(s->s3->hs.key_share))
1902 goto err;
1903
1904 if (!CBB_add_u8_length_prefixed(cbb, &public))
1905 return 0;
1906 if (!tls_key_share_public(s->s3->hs.key_share, &public))
1907 goto err;
1908 if (!CBB_flush(cbb))
1909 goto err;
1910
1911 if (!tls_key_share_derive(s->s3->hs.key_share, &key, &key_len))
1912 goto err;
1913
1914 if (!tls12_derive_master_secret(s, key, key_len))
1915 goto err;
1916
1917 ret = 1;
1918
1919 err:
1920 freezero(key, key_len);
1921
1922 return ret;
1923}
1924
1925static int
1926ssl3_send_client_key_exchange(SSL *s)
1927{
1928 unsigned long alg_k;
1929 CBB cbb, kex;
1930
1931 memset(&cbb, 0, sizeof(cbb));
1932
1933 if (s->s3->hs.state == SSL3_ST_CW_KEY_EXCH_A) {
1934 alg_k = s->s3->hs.cipher->algorithm_mkey;
1935
1936 if (!ssl3_handshake_msg_start(s, &cbb, &kex,
1937 SSL3_MT_CLIENT_KEY_EXCHANGE))
1938 goto err;
1939
1940 if (alg_k & SSL_kRSA) {
1941 if (!ssl3_send_client_kex_rsa(s, &kex))
1942 goto err;
1943 } else if (alg_k & SSL_kDHE) {
1944 if (!ssl3_send_client_kex_dhe(s, &kex))
1945 goto err;
1946 } else if (alg_k & SSL_kECDHE) {
1947 if (!ssl3_send_client_kex_ecdhe(s, &kex))
1948 goto err;
1949 } else {
1950 ssl3_send_alert(s, SSL3_AL_FATAL,
1951 SSL_AD_HANDSHAKE_FAILURE);
1952 SSLerror(s, ERR_R_INTERNAL_ERROR);
1953 goto err;
1954 }
1955
1956 if (!ssl3_handshake_msg_finish(s, &cbb))
1957 goto err;
1958
1959 s->s3->hs.state = SSL3_ST_CW_KEY_EXCH_B;
1960 }
1961
1962 /* SSL3_ST_CW_KEY_EXCH_B */
1963 return (ssl3_handshake_write(s));
1964
1965 err:
1966 CBB_cleanup(&cbb);
1967
1968 return (-1);
1969}
1970
1971static int
1972ssl3_send_client_verify_sigalgs(SSL *s, EVP_PKEY *pkey,
1973 const struct ssl_sigalg *sigalg, CBB *cert_verify)
1974{
1975 CBB cbb_signature;
1976 EVP_PKEY_CTX *pctx = NULL;
1977 EVP_MD_CTX *mctx = NULL;
1978 const unsigned char *hdata;
1979 unsigned char *signature = NULL;
1980 size_t signature_len, hdata_len;
1981 int ret = 0;
1982
1983 if ((mctx = EVP_MD_CTX_new()) == NULL)
1984 goto err;
1985
1986 if (!tls1_transcript_data(s, &hdata, &hdata_len)) {
1987 SSLerror(s, ERR_R_INTERNAL_ERROR);
1988 goto err;
1989 }
1990 if (!EVP_DigestSignInit(mctx, &pctx, sigalg->md(), NULL, pkey)) {
1991 SSLerror(s, ERR_R_EVP_LIB);
1992 goto err;
1993 }
1994 if ((sigalg->flags & SIGALG_FLAG_RSA_PSS) &&
1995 (!EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING) ||
1996 !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))) {
1997 SSLerror(s, ERR_R_EVP_LIB);
1998 goto err;
1999 }
2000 if (!EVP_DigestSign(mctx, NULL, &signature_len, hdata, hdata_len)) {
2001 SSLerror(s, ERR_R_EVP_LIB);
2002 goto err;
2003 }
2004 if ((signature = calloc(1, signature_len)) == NULL) {
2005 SSLerror(s, ERR_R_MALLOC_FAILURE);
2006 goto err;
2007 }
2008 if (!EVP_DigestSign(mctx, signature, &signature_len, hdata, hdata_len)) {
2009 SSLerror(s, ERR_R_EVP_LIB);
2010 goto err;
2011 }
2012
2013 if (!CBB_add_u16(cert_verify, sigalg->value))
2014 goto err;
2015 if (!CBB_add_u16_length_prefixed(cert_verify, &cbb_signature))
2016 goto err;
2017 if (!CBB_add_bytes(&cbb_signature, signature, signature_len))
2018 goto err;
2019 if (!CBB_flush(cert_verify))
2020 goto err;
2021
2022 ret = 1;
2023
2024 err:
2025 EVP_MD_CTX_free(mctx);
2026 free(signature);
2027 return ret;
2028}
2029
2030static int
2031ssl3_send_client_verify_rsa(SSL *s, EVP_PKEY *pkey, CBB *cert_verify)
2032{
2033 CBB cbb_signature;
2034 RSA *rsa;
2035 unsigned char data[EVP_MAX_MD_SIZE];
2036 unsigned char *signature = NULL;
2037 unsigned int signature_len;
2038 size_t data_len;
2039 int ret = 0;
2040
2041 if (!tls1_transcript_hash_value(s, data, sizeof(data), &data_len))
2042 goto err;
2043 if ((signature = calloc(1, EVP_PKEY_size(pkey))) == NULL)
2044 goto err;
2045 if ((rsa = EVP_PKEY_get0_RSA(pkey)) == NULL)
2046 goto err;
2047 if (RSA_sign(NID_md5_sha1, data, data_len, signature, &signature_len,
2048 rsa) <= 0 ) {
2049 SSLerror(s, ERR_R_RSA_LIB);
2050 goto err;
2051 }
2052
2053 if (!CBB_add_u16_length_prefixed(cert_verify, &cbb_signature))
2054 goto err;
2055 if (!CBB_add_bytes(&cbb_signature, signature, signature_len))
2056 goto err;
2057 if (!CBB_flush(cert_verify))
2058 goto err;
2059
2060 ret = 1;
2061 err:
2062 free(signature);
2063 return ret;
2064}
2065
2066static int
2067ssl3_send_client_verify_ec(SSL *s, EVP_PKEY *pkey, CBB *cert_verify)
2068{
2069 CBB cbb_signature;
2070 EC_KEY *eckey;
2071 unsigned char data[EVP_MAX_MD_SIZE];
2072 unsigned char *signature = NULL;
2073 unsigned int signature_len;
2074 int ret = 0;
2075
2076 if (!tls1_transcript_hash_value(s, data, sizeof(data), NULL))
2077 goto err;
2078 if ((signature = calloc(1, EVP_PKEY_size(pkey))) == NULL)
2079 goto err;
2080 if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL)
2081 goto err;
2082 if (!ECDSA_sign(0, &data[MD5_DIGEST_LENGTH], SHA_DIGEST_LENGTH,
2083 signature, &signature_len, eckey)) {
2084 SSLerror(s, ERR_R_ECDSA_LIB);
2085 goto err;
2086 }
2087
2088 if (!CBB_add_u16_length_prefixed(cert_verify, &cbb_signature))
2089 goto err;
2090 if (!CBB_add_bytes(&cbb_signature, signature, signature_len))
2091 goto err;
2092 if (!CBB_flush(cert_verify))
2093 goto err;
2094
2095 ret = 1;
2096 err:
2097 free(signature);
2098 return ret;
2099}
2100
2101static int
2102ssl3_send_client_verify(SSL *s)
2103{
2104 const struct ssl_sigalg *sigalg;
2105 CBB cbb, cert_verify;
2106 EVP_PKEY *pkey;
2107
2108 memset(&cbb, 0, sizeof(cbb));
2109
2110 if (s->s3->hs.state == SSL3_ST_CW_CERT_VRFY_A) {
2111 if (!ssl3_handshake_msg_start(s, &cbb, &cert_verify,
2112 SSL3_MT_CERTIFICATE_VERIFY))
2113 goto err;
2114
2115 pkey = s->cert->key->privatekey;
2116 if ((sigalg = ssl_sigalg_select(s, pkey)) == NULL) {
2117 SSLerror(s, SSL_R_SIGNATURE_ALGORITHMS_ERROR);
2118 goto err;
2119 }
2120 s->s3->hs.our_sigalg = sigalg;
2121
2122 /*
2123 * For TLS v1.2 send signature algorithm and signature using
2124 * agreed digest and cached handshake records.
2125 */
2126 if (SSL_USE_SIGALGS(s)) {
2127 if (!ssl3_send_client_verify_sigalgs(s, pkey, sigalg,
2128 &cert_verify))
2129 goto err;
2130 } else if (EVP_PKEY_id(pkey) == EVP_PKEY_RSA) {
2131 if (!ssl3_send_client_verify_rsa(s, pkey, &cert_verify))
2132 goto err;
2133 } else if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
2134 if (!ssl3_send_client_verify_ec(s, pkey, &cert_verify))
2135 goto err;
2136 } else {
2137 SSLerror(s, ERR_R_INTERNAL_ERROR);
2138 goto err;
2139 }
2140
2141 tls1_transcript_free(s);
2142
2143 if (!ssl3_handshake_msg_finish(s, &cbb))
2144 goto err;
2145
2146 s->s3->hs.state = SSL3_ST_CW_CERT_VRFY_B;
2147 }
2148
2149 return (ssl3_handshake_write(s));
2150
2151 err:
2152 CBB_cleanup(&cbb);
2153
2154 return (-1);
2155}
2156
2157static int
2158ssl3_send_client_certificate(SSL *s)
2159{
2160 EVP_PKEY *pkey = NULL;
2161 X509 *x509 = NULL;
2162 CBB cbb, client_cert;
2163 int i;
2164
2165 memset(&cbb, 0, sizeof(cbb));
2166
2167 if (s->s3->hs.state == SSL3_ST_CW_CERT_A) {
2168 if (s->cert->key->x509 == NULL ||
2169 s->cert->key->privatekey == NULL)
2170 s->s3->hs.state = SSL3_ST_CW_CERT_B;
2171 else
2172 s->s3->hs.state = SSL3_ST_CW_CERT_C;
2173 }
2174
2175 /* We need to get a client cert */
2176 if (s->s3->hs.state == SSL3_ST_CW_CERT_B) {
2177 /*
2178 * If we get an error, we need to
2179 * ssl->rwstate = SSL_X509_LOOKUP; return(-1);
2180 * We then get retried later.
2181 */
2182 i = ssl_do_client_cert_cb(s, &x509, &pkey);
2183 if (i < 0) {
2184 s->rwstate = SSL_X509_LOOKUP;
2185 return (-1);
2186 }
2187 s->rwstate = SSL_NOTHING;
2188 if ((i == 1) && (pkey != NULL) && (x509 != NULL)) {
2189 s->s3->hs.state = SSL3_ST_CW_CERT_B;
2190 if (!SSL_use_certificate(s, x509) ||
2191 !SSL_use_PrivateKey(s, pkey))
2192 i = 0;
2193 } else if (i == 1) {
2194 i = 0;
2195 SSLerror(s, SSL_R_BAD_DATA_RETURNED_BY_CALLBACK);
2196 }
2197
2198 X509_free(x509);
2199 EVP_PKEY_free(pkey);
2200 if (i == 0) {
2201 s->s3->hs.tls12.cert_request = 2;
2202
2203 /* There is no client certificate to verify. */
2204 tls1_transcript_free(s);
2205 }
2206
2207 /* Ok, we have a cert */
2208 s->s3->hs.state = SSL3_ST_CW_CERT_C;
2209 }
2210
2211 if (s->s3->hs.state == SSL3_ST_CW_CERT_C) {
2212 if (!ssl3_handshake_msg_start(s, &cbb, &client_cert,
2213 SSL3_MT_CERTIFICATE))
2214 goto err;
2215 if (!ssl3_output_cert_chain(s, &client_cert,
2216 (s->s3->hs.tls12.cert_request == 2) ? NULL : s->cert->key))
2217 goto err;
2218 if (!ssl3_handshake_msg_finish(s, &cbb))
2219 goto err;
2220
2221 s->s3->hs.state = SSL3_ST_CW_CERT_D;
2222 }
2223
2224 /* SSL3_ST_CW_CERT_D */
2225 return (ssl3_handshake_write(s));
2226
2227 err:
2228 CBB_cleanup(&cbb);
2229
2230 return (0);
2231}
2232
2233#define has_bits(i,m) (((i)&(m)) == (m))
2234
2235static int
2236ssl3_check_cert_and_algorithm(SSL *s)
2237{
2238 long alg_k, alg_a;
2239 int nid = NID_undef;
2240 int i;
2241
2242 alg_k = s->s3->hs.cipher->algorithm_mkey;
2243 alg_a = s->s3->hs.cipher->algorithm_auth;
2244
2245 /* We don't have a certificate. */
2246 if (alg_a & SSL_aNULL)
2247 return (1);
2248
2249 if (s->s3->hs.key_share != NULL)
2250 nid = tls_key_share_nid(s->s3->hs.key_share);
2251
2252 /* This is the passed certificate. */
2253
2254 if (s->session->peer_cert_type == SSL_PKEY_ECC) {
2255 if (!ssl_check_srvr_ecc_cert_and_alg(s, s->session->peer_cert)) {
2256 SSLerror(s, SSL_R_BAD_ECC_CERT);
2257 goto fatal_err;
2258 }
2259 return (1);
2260 }
2261
2262 i = X509_certificate_type(s->session->peer_cert, NULL);
2263
2264 /* Check that we have a certificate if we require one. */
2265 if ((alg_a & SSL_aRSA) && !has_bits(i, EVP_PK_RSA|EVP_PKT_SIGN)) {
2266 SSLerror(s, SSL_R_MISSING_RSA_SIGNING_CERT);
2267 goto fatal_err;
2268 }
2269 if ((alg_k & SSL_kRSA) && !has_bits(i, EVP_PK_RSA|EVP_PKT_ENC)) {
2270 SSLerror(s, SSL_R_MISSING_RSA_ENCRYPTING_CERT);
2271 goto fatal_err;
2272 }
2273 if ((alg_k & SSL_kDHE) &&
2274 !(has_bits(i, EVP_PK_DH|EVP_PKT_EXCH) || (nid == NID_dhKeyAgreement))) {
2275 SSLerror(s, SSL_R_MISSING_DH_KEY);
2276 goto fatal_err;
2277 }
2278
2279 return (1);
2280
2281 fatal_err:
2282 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
2283
2284 return (0);
2285}
2286
2287/*
2288 * Check to see if handshake is full or resumed. Usually this is just a
2289 * case of checking to see if a cache hit has occurred. In the case of
2290 * session tickets we have to check the next message to be sure.
2291 */
2292
2293static int
2294ssl3_check_finished(SSL *s)
2295{
2296 int ret;
2297
2298 /* If we have no ticket it cannot be a resumed session. */
2299 if (!s->session->tlsext_tick)
2300 return (1);
2301 /* this function is called when we really expect a Certificate
2302 * message, so permit appropriate message length */
2303 if ((ret = ssl3_get_message(s, SSL3_ST_CR_CERT_A,
2304 SSL3_ST_CR_CERT_B, -1, s->max_cert_list)) <= 0)
2305 return ret;
2306
2307 s->s3->hs.tls12.reuse_message = 1;
2308 if ((s->s3->hs.tls12.message_type == SSL3_MT_FINISHED) ||
2309 (s->s3->hs.tls12.message_type == SSL3_MT_NEWSESSION_TICKET))
2310 return (2);
2311
2312 return (1);
2313}
2314
2315static int
2316ssl_do_client_cert_cb(SSL *s, X509 **px509, EVP_PKEY **ppkey)
2317{
2318 if (s->ctx->client_cert_cb == NULL)
2319 return 0;
2320
2321 return s->ctx->client_cert_cb(s, px509, ppkey);
2322}
2323
2324static int
2325ssl3_send_client_change_cipher_spec(SSL *s)
2326{
2327 size_t outlen;
2328 CBB cbb;
2329
2330 memset(&cbb, 0, sizeof(cbb));
2331
2332 if (s->s3->hs.state == SSL3_ST_CW_CHANGE_A) {
2333 if (!CBB_init_fixed(&cbb, s->init_buf->data,
2334 s->init_buf->length))
2335 goto err;
2336 if (!CBB_add_u8(&cbb, SSL3_MT_CCS))
2337 goto err;
2338 if (!CBB_finish(&cbb, NULL, &outlen))
2339 goto err;
2340
2341 if (outlen > INT_MAX)
2342 goto err;
2343
2344 s->init_num = (int)outlen;
2345 s->init_off = 0;
2346
2347 if (SSL_is_dtls(s)) {
2348 s->d1->handshake_write_seq =
2349 s->d1->next_handshake_write_seq;
2350 dtls1_set_message_header_int(s, SSL3_MT_CCS, 0,
2351 s->d1->handshake_write_seq, 0, 0);
2352 dtls1_buffer_message(s, 1);
2353 }
2354
2355 s->s3->hs.state = SSL3_ST_CW_CHANGE_B;
2356 }
2357
2358 /* SSL3_ST_CW_CHANGE_B */
2359 return ssl3_record_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);
2360
2361 err:
2362 CBB_cleanup(&cbb);
2363
2364 return -1;
2365}
2366
2367static int
2368ssl3_send_client_finished(SSL *s)
2369{
2370 CBB cbb, finished;
2371
2372 memset(&cbb, 0, sizeof(cbb));
2373
2374 if (s->s3->hs.state == SSL3_ST_CW_FINISHED_A) {
2375 if (!tls12_derive_finished(s))
2376 goto err;
2377
2378 /* Copy finished so we can use it for renegotiation checks. */
2379 memcpy(s->s3->previous_client_finished,
2380 s->s3->hs.finished, s->s3->hs.finished_len);
2381 s->s3->previous_client_finished_len =
2382 s->s3->hs.finished_len;
2383
2384 if (!ssl3_handshake_msg_start(s, &cbb, &finished,
2385 SSL3_MT_FINISHED))
2386 goto err;
2387 if (!CBB_add_bytes(&finished, s->s3->hs.finished,
2388 s->s3->hs.finished_len))
2389 goto err;
2390 if (!ssl3_handshake_msg_finish(s, &cbb))
2391 goto err;
2392
2393 s->s3->hs.state = SSL3_ST_CW_FINISHED_B;
2394 }
2395
2396 return (ssl3_handshake_write(s));
2397
2398 err:
2399 CBB_cleanup(&cbb);
2400
2401 return (-1);
2402}
2403
2404static int
2405ssl3_get_server_finished(SSL *s)
2406{
2407 int al, md_len, ret;
2408 CBS cbs;
2409
2410 /* should actually be 36+4 :-) */
2411 if ((ret = ssl3_get_message(s, SSL3_ST_CR_FINISHED_A,
2412 SSL3_ST_CR_FINISHED_B, SSL3_MT_FINISHED, 64)) <= 0)
2413 return ret;
2414
2415 /* If this occurs, we have missed a message */
2416 if (!s->s3->change_cipher_spec) {
2417 al = SSL_AD_UNEXPECTED_MESSAGE;
2418 SSLerror(s, SSL_R_GOT_A_FIN_BEFORE_A_CCS);
2419 goto fatal_err;
2420 }
2421 s->s3->change_cipher_spec = 0;
2422
2423 md_len = TLS1_FINISH_MAC_LENGTH;
2424
2425 if (s->init_num < 0) {
2426 al = SSL_AD_DECODE_ERROR;
2427 SSLerror(s, SSL_R_BAD_DIGEST_LENGTH);
2428 goto fatal_err;
2429 }
2430
2431 CBS_init(&cbs, s->init_msg, s->init_num);
2432
2433 if (s->s3->hs.peer_finished_len != md_len ||
2434 CBS_len(&cbs) != md_len) {
2435 al = SSL_AD_DECODE_ERROR;
2436 SSLerror(s, SSL_R_BAD_DIGEST_LENGTH);
2437 goto fatal_err;
2438 }
2439
2440 if (!CBS_mem_equal(&cbs, s->s3->hs.peer_finished, CBS_len(&cbs))) {
2441 al = SSL_AD_DECRYPT_ERROR;
2442 SSLerror(s, SSL_R_DIGEST_CHECK_FAILED);
2443 goto fatal_err;
2444 }
2445
2446 /* Copy finished so we can use it for renegotiation checks. */
2447 OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE);
2448 memcpy(s->s3->previous_server_finished,
2449 s->s3->hs.peer_finished, md_len);
2450 s->s3->previous_server_finished_len = md_len;
2451
2452 return (1);
2453 fatal_err:
2454 ssl3_send_alert(s, SSL3_AL_FATAL, al);
2455 return (0);
2456}
diff --git a/src/lib/libssl/ssl_err.c b/src/lib/libssl/ssl_err.c
deleted file mode 100644
index eac2d9e61f..0000000000
--- a/src/lib/libssl/ssl_err.c
+++ /dev/null
@@ -1,676 +0,0 @@
1/* $OpenBSD: ssl_err.c,v 1.53 2024/10/09 08:00:29 tb Exp $ */
2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57
58#include <openssl/err.h>
59#include <openssl/opensslconf.h>
60#include <openssl/ssl.h>
61
62#include "ssl_local.h"
63
64#ifndef OPENSSL_NO_ERR
65
66#define ERR_FUNC(func) ERR_PACK(ERR_LIB_SSL,func,0)
67#define ERR_REASON(reason) ERR_PACK(ERR_LIB_SSL,0,reason)
68
69/* See SSL_state_func_code below */
70static const ERR_STRING_DATA SSL_str_functs[] = {
71 {ERR_FUNC(1), "CONNECT_CW_FLUSH"},
72 {ERR_FUNC(2), "CONNECT_CW_CLNT_HELLO"},
73 {ERR_FUNC(3), "CONNECT_CW_CLNT_HELLO"},
74 {ERR_FUNC(4), "CONNECT_CR_SRVR_HELLO"},
75 {ERR_FUNC(5), "CONNECT_CR_SRVR_HELLO"},
76 {ERR_FUNC(6), "CONNECT_CR_CERT"},
77 {ERR_FUNC(7), "CONNECT_CR_CERT"},
78 {ERR_FUNC(8), "CONNECT_CR_KEY_EXCH"},
79 {ERR_FUNC(9), "CONNECT_CR_KEY_EXCH"},
80 {ERR_FUNC(10), "CONNECT_CR_CERT_REQ"},
81 {ERR_FUNC(11), "CONNECT_CR_CERT_REQ"},
82 {ERR_FUNC(12), "CONNECT_CR_SRVR_DONE"},
83 {ERR_FUNC(13), "CONNECT_CR_SRVR_DONE"},
84 {ERR_FUNC(14), "CONNECT_CW_CERT"},
85 {ERR_FUNC(15), "CONNECT_CW_CERT"},
86 {ERR_FUNC(16), "CONNECT_CW_CERT_C"},
87 {ERR_FUNC(17), "CONNECT_CW_CERT_D"},
88 {ERR_FUNC(18), "CONNECT_CW_KEY_EXCH"},
89 {ERR_FUNC(19), "CONNECT_CW_KEY_EXCH"},
90 {ERR_FUNC(20), "CONNECT_CW_CERT_VRFY"},
91 {ERR_FUNC(21), "CONNECT_CW_CERT_VRFY"},
92 {ERR_FUNC(22), "CONNECT_CW_CHANGE"},
93 {ERR_FUNC(23), "CONNECT_CW_CHANGE"},
94 {ERR_FUNC(26), "CONNECT_CW_FINISHED"},
95 {ERR_FUNC(27), "CONNECT_CW_FINISHED"},
96 {ERR_FUNC(28), "CONNECT_CR_CHANGE"},
97 {ERR_FUNC(29), "CONNECT_CR_CHANGE"},
98 {ERR_FUNC(30), "CONNECT_CR_FINISHED"},
99 {ERR_FUNC(31), "CONNECT_CR_FINISHED"},
100 {ERR_FUNC(32), "CONNECT_CR_SESSION_TICKET"},
101 {ERR_FUNC(33), "CONNECT_CR_SESSION_TICKET"},
102 {ERR_FUNC(34), "CONNECT_CR_CERT_STATUS"},
103 {ERR_FUNC(35), "CONNECT_CR_CERT_STATUS"},
104 {ERR_FUNC(36), "ACCEPT_SW_FLUSH"},
105 {ERR_FUNC(37), "ACCEPT_SR_CLNT_HELLO"},
106 {ERR_FUNC(38), "ACCEPT_SR_CLNT_HELLO"},
107 {ERR_FUNC(39), "ACCEPT_SR_CLNT_HELLO_C"},
108 {ERR_FUNC(40), "ACCEPT_SW_HELLO_REQ"},
109 {ERR_FUNC(41), "ACCEPT_SW_HELLO_REQ"},
110 {ERR_FUNC(42), "ACCEPT_SW_HELLO_REQ_C"},
111 {ERR_FUNC(43), "ACCEPT_SW_SRVR_HELLO"},
112 {ERR_FUNC(44), "ACCEPT_SW_SRVR_HELLO"},
113 {ERR_FUNC(45), "ACCEPT_SW_CERT"},
114 {ERR_FUNC(46), "ACCEPT_SW_CERT"},
115 {ERR_FUNC(47), "ACCEPT_SW_KEY_EXCH"},
116 {ERR_FUNC(48), "ACCEPT_SW_KEY_EXCH"},
117 {ERR_FUNC(49), "ACCEPT_SW_CERT_REQ"},
118 {ERR_FUNC(50), "ACCEPT_SW_CERT_REQ"},
119 {ERR_FUNC(51), "ACCEPT_SW_SRVR_DONE"},
120 {ERR_FUNC(52), "ACCEPT_SW_SRVR_DONE"},
121 {ERR_FUNC(53), "ACCEPT_SR_CERT"},
122 {ERR_FUNC(54), "ACCEPT_SR_CERT"},
123 {ERR_FUNC(55), "ACCEPT_SR_KEY_EXCH"},
124 {ERR_FUNC(56), "ACCEPT_SR_KEY_EXCH"},
125 {ERR_FUNC(57), "ACCEPT_SR_CERT_VRFY"},
126 {ERR_FUNC(58), "ACCEPT_SR_CERT_VRFY"},
127 {ERR_FUNC(59), "ACCEPT_SR_CHANGE"},
128 {ERR_FUNC(60), "ACCEPT_SR_CHANGE"},
129 {ERR_FUNC(63), "ACCEPT_SR_FINISHED"},
130 {ERR_FUNC(64), "ACCEPT_SR_FINISHED"},
131 {ERR_FUNC(65), "ACCEPT_SW_CHANGE"},
132 {ERR_FUNC(66), "ACCEPT_SW_CHANGE"},
133 {ERR_FUNC(67), "ACCEPT_SW_FINISHED"},
134 {ERR_FUNC(68), "ACCEPT_SW_FINISHED"},
135 {ERR_FUNC(69), "ACCEPT_SW_SESSION_TICKET"},
136 {ERR_FUNC(70), "ACCEPT_SW_SESSION_TICKET"},
137 {ERR_FUNC(71), "ACCEPT_SW_CERT_STATUS"},
138 {ERR_FUNC(72), "ACCEPT_SW_CERT_STATUS"},
139 {ERR_FUNC(73), "ST_BEFORE"},
140 {ERR_FUNC(74), "ST_ACCEPT"},
141 {ERR_FUNC(75), "ST_CONNECT"},
142 {ERR_FUNC(76), "ST_OK"},
143 {ERR_FUNC(77), "ST_RENEGOTIATE"},
144 {ERR_FUNC(78), "ST_BEFORE_CONNECT"},
145 {ERR_FUNC(79), "ST_OK_CONNECT"},
146 {ERR_FUNC(80), "ST_BEFORE_ACCEPT"},
147 {ERR_FUNC(81), "ST_OK_ACCEPT"},
148 {ERR_FUNC(83), "DTLS1_ST_CR_HELLO_VERIFY_REQUEST"},
149 {ERR_FUNC(84), "DTLS1_ST_CR_HELLO_VERIFY_REQUEST"},
150 {ERR_FUNC(85), "DTLS1_ST_SW_HELLO_VERIFY_REQUEST"},
151 {ERR_FUNC(86), "DTLS1_ST_SW_HELLO_VERIFY_REQUEST"},
152 {ERR_FUNC(0xfff), "(UNKNOWN)SSL_internal"},
153 {0, NULL}
154};
155
156static const ERR_STRING_DATA SSL_str_reasons[] = {
157 {ERR_REASON(SSL_R_APP_DATA_IN_HANDSHAKE) , "app data in handshake"},
158 {ERR_REASON(SSL_R_ATTEMPT_TO_REUSE_SESSION_IN_DIFFERENT_CONTEXT), "attempt to reuse session in different context"},
159 {ERR_REASON(SSL_R_BAD_ALERT_RECORD) , "bad alert record"},
160 {ERR_REASON(SSL_R_BAD_AUTHENTICATION_TYPE), "bad authentication type"},
161 {ERR_REASON(SSL_R_BAD_CHANGE_CIPHER_SPEC), "bad change cipher spec"},
162 {ERR_REASON(SSL_R_BAD_CHECKSUM) , "bad checksum"},
163 {ERR_REASON(SSL_R_BAD_DATA_RETURNED_BY_CALLBACK), "bad data returned by callback"},
164 {ERR_REASON(SSL_R_BAD_DECOMPRESSION) , "bad decompression"},
165 {ERR_REASON(SSL_R_BAD_DH_G_LENGTH) , "bad dh g length"},
166 {ERR_REASON(SSL_R_BAD_DH_PUB_KEY_LENGTH) , "bad dh pub key length"},
167 {ERR_REASON(SSL_R_BAD_DH_P_LENGTH) , "bad dh p length"},
168 {ERR_REASON(SSL_R_BAD_DIGEST_LENGTH) , "bad digest length"},
169 {ERR_REASON(SSL_R_BAD_DSA_SIGNATURE) , "bad dsa signature"},
170 {ERR_REASON(SSL_R_BAD_ECC_CERT) , "bad ecc cert"},
171 {ERR_REASON(SSL_R_BAD_ECDSA_SIGNATURE) , "bad ecdsa signature"},
172 {ERR_REASON(SSL_R_BAD_ECPOINT) , "bad ecpoint"},
173 {ERR_REASON(SSL_R_BAD_HANDSHAKE_LENGTH) , "bad handshake length"},
174 {ERR_REASON(SSL_R_BAD_HELLO_REQUEST) , "bad hello request"},
175 {ERR_REASON(SSL_R_BAD_LENGTH) , "bad length"},
176 {ERR_REASON(SSL_R_BAD_MAC_DECODE) , "bad mac decode"},
177 {ERR_REASON(SSL_R_BAD_MAC_LENGTH) , "bad mac length"},
178 {ERR_REASON(SSL_R_BAD_MESSAGE_TYPE) , "bad message type"},
179 {ERR_REASON(SSL_R_BAD_PACKET_LENGTH) , "bad packet length"},
180 {ERR_REASON(SSL_R_BAD_PROTOCOL_VERSION_NUMBER), "bad protocol version number"},
181 {ERR_REASON(SSL_R_BAD_PSK_IDENTITY_HINT_LENGTH), "bad psk identity hint length"},
182 {ERR_REASON(SSL_R_BAD_RESPONSE_ARGUMENT) , "bad response argument"},
183 {ERR_REASON(SSL_R_BAD_RSA_DECRYPT) , "bad rsa decrypt"},
184 {ERR_REASON(SSL_R_BAD_RSA_ENCRYPT) , "bad rsa encrypt"},
185 {ERR_REASON(SSL_R_BAD_RSA_E_LENGTH) , "bad rsa e length"},
186 {ERR_REASON(SSL_R_BAD_RSA_MODULUS_LENGTH), "bad rsa modulus length"},
187 {ERR_REASON(SSL_R_BAD_RSA_SIGNATURE) , "bad rsa signature"},
188 {ERR_REASON(SSL_R_BAD_SIGNATURE) , "bad signature"},
189 {ERR_REASON(SSL_R_BAD_SRP_A_LENGTH) , "bad srp a length"},
190 {ERR_REASON(SSL_R_BAD_SRP_B_LENGTH) , "bad srp b length"},
191 {ERR_REASON(SSL_R_BAD_SRP_G_LENGTH) , "bad srp g length"},
192 {ERR_REASON(SSL_R_BAD_SRP_N_LENGTH) , "bad srp n length"},
193 {ERR_REASON(SSL_R_BAD_SRP_S_LENGTH) , "bad srp s length"},
194 {ERR_REASON(SSL_R_BAD_SRTP_MKI_VALUE) , "bad srtp mki value"},
195 {ERR_REASON(SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST), "bad srtp protection profile list"},
196 {ERR_REASON(SSL_R_BAD_SSL_FILETYPE) , "bad ssl filetype"},
197 {ERR_REASON(SSL_R_BAD_SSL_SESSION_ID_LENGTH), "bad ssl session id length"},
198 {ERR_REASON(SSL_R_BAD_STATE) , "bad state"},
199 {ERR_REASON(SSL_R_BAD_WRITE_RETRY) , "bad write retry"},
200 {ERR_REASON(SSL_R_BIO_NOT_SET) , "bio not set"},
201 {ERR_REASON(SSL_R_BLOCK_CIPHER_PAD_IS_WRONG), "block cipher pad is wrong"},
202 {ERR_REASON(SSL_R_BN_LIB) , "bn lib"},
203 {ERR_REASON(SSL_R_CA_DN_LENGTH_MISMATCH) , "ca dn length mismatch"},
204 {ERR_REASON(SSL_R_CA_DN_TOO_LONG) , "ca dn too long"},
205 {ERR_REASON(SSL_R_CA_KEY_TOO_SMALL) , "ca key too small"},
206 {ERR_REASON(SSL_R_CA_MD_TOO_WEAK) , "ca md too weak"},
207 {ERR_REASON(SSL_R_CCS_RECEIVED_EARLY) , "ccs received early"},
208 {ERR_REASON(SSL_R_CERTIFICATE_VERIFY_FAILED), "certificate verify failed"},
209 {ERR_REASON(SSL_R_CERT_LENGTH_MISMATCH) , "cert length mismatch"},
210 {ERR_REASON(SSL_R_CHALLENGE_IS_DIFFERENT), "challenge is different"},
211 {ERR_REASON(SSL_R_CIPHER_CODE_WRONG_LENGTH), "cipher code wrong length"},
212 {ERR_REASON(SSL_R_CIPHER_COMPRESSION_UNAVAILABLE), "cipher compression unavailable"},
213 {ERR_REASON(SSL_R_CIPHER_OR_HASH_UNAVAILABLE), "cipher or hash unavailable"},
214 {ERR_REASON(SSL_R_CIPHER_TABLE_SRC_ERROR), "cipher table src error"},
215 {ERR_REASON(SSL_R_CLIENTHELLO_TLSEXT) , "clienthello tlsext"},
216 {ERR_REASON(SSL_R_COMPRESSED_LENGTH_TOO_LONG), "compressed length too long"},
217 {ERR_REASON(SSL_R_COMPRESSION_DISABLED) , "compression disabled"},
218 {ERR_REASON(SSL_R_COMPRESSION_FAILURE) , "compression failure"},
219 {ERR_REASON(SSL_R_COMPRESSION_ID_NOT_WITHIN_PRIVATE_RANGE), "compression id not within private range"},
220 {ERR_REASON(SSL_R_COMPRESSION_LIBRARY_ERROR), "compression library error"},
221 {ERR_REASON(SSL_R_CONNECTION_ID_IS_DIFFERENT), "connection id is different"},
222 {ERR_REASON(SSL_R_CONNECTION_TYPE_NOT_SET), "connection type not set"},
223 {ERR_REASON(SSL_R_COOKIE_MISMATCH) , "cookie mismatch"},
224 {ERR_REASON(SSL_R_DATA_BETWEEN_CCS_AND_FINISHED), "data between ccs and finished"},
225 {ERR_REASON(SSL_R_DATA_LENGTH_TOO_LONG) , "data length too long"},
226 {ERR_REASON(SSL_R_DECRYPTION_FAILED) , "decryption failed"},
227 {ERR_REASON(SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC), "decryption failed or bad record mac"},
228 {ERR_REASON(SSL_R_DH_KEY_TOO_SMALL) , "dh key too small"},
229 {ERR_REASON(SSL_R_DH_PUBLIC_VALUE_LENGTH_IS_WRONG), "dh public value length is wrong"},
230 {ERR_REASON(SSL_R_DIGEST_CHECK_FAILED) , "digest check failed"},
231 {ERR_REASON(SSL_R_DTLS_MESSAGE_TOO_BIG) , "dtls message too big"},
232 {ERR_REASON(SSL_R_DUPLICATE_COMPRESSION_ID), "duplicate compression id"},
233 {ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_KEY_AGREEMENT), "ecc cert not for key agreement"},
234 {ERR_REASON(SSL_R_ECC_CERT_NOT_FOR_SIGNING), "ecc cert not for signing"},
235 {ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_RSA_SIGNATURE), "ecc cert should have rsa signature"},
236 {ERR_REASON(SSL_R_ECC_CERT_SHOULD_HAVE_SHA1_SIGNATURE), "ecc cert should have sha1 signature"},
237 {ERR_REASON(SSL_R_ECGROUP_TOO_LARGE_FOR_CIPHER), "ecgroup too large for cipher"},
238 {ERR_REASON(SSL_R_EE_KEY_TOO_SMALL) , "ee key too small"},
239 {ERR_REASON(SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST), "empty srtp protection profile list"},
240 {ERR_REASON(SSL_R_ENCRYPTED_LENGTH_TOO_LONG), "encrypted length too long"},
241 {ERR_REASON(SSL_R_ERROR_GENERATING_TMP_RSA_KEY), "error generating tmp rsa key"},
242 {ERR_REASON(SSL_R_ERROR_IN_RECEIVED_CIPHER_LIST), "error in received cipher list"},
243 {ERR_REASON(SSL_R_EXCESSIVE_MESSAGE_SIZE), "excessive message size"},
244 {ERR_REASON(SSL_R_EXTRA_DATA_IN_MESSAGE) , "extra data in message"},
245 {ERR_REASON(SSL_R_GOT_A_FIN_BEFORE_A_CCS), "got a fin before a ccs"},
246 {ERR_REASON(SSL_R_GOT_NEXT_PROTO_BEFORE_A_CCS), "got next proto before a ccs"},
247 {ERR_REASON(SSL_R_GOT_NEXT_PROTO_WITHOUT_EXTENSION), "got next proto without seeing extension"},
248 {ERR_REASON(SSL_R_HTTPS_PROXY_REQUEST) , "https proxy request"},
249 {ERR_REASON(SSL_R_HTTP_REQUEST) , "http request"},
250 {ERR_REASON(SSL_R_ILLEGAL_PADDING) , "illegal padding"},
251 {ERR_REASON(SSL_R_INAPPROPRIATE_FALLBACK), "inappropriate fallback"},
252 {ERR_REASON(SSL_R_INCONSISTENT_COMPRESSION), "inconsistent compression"},
253 {ERR_REASON(SSL_R_INVALID_CHALLENGE_LENGTH), "invalid challenge length"},
254 {ERR_REASON(SSL_R_INVALID_COMMAND) , "invalid command"},
255 {ERR_REASON(SSL_R_INVALID_COMPRESSION_ALGORITHM), "invalid compression algorithm"},
256 {ERR_REASON(SSL_R_INVALID_PURPOSE) , "invalid purpose"},
257 {ERR_REASON(SSL_R_INVALID_SRP_USERNAME) , "invalid srp username"},
258 {ERR_REASON(SSL_R_INVALID_STATUS_RESPONSE), "invalid status response"},
259 {ERR_REASON(SSL_R_INVALID_TICKET_KEYS_LENGTH), "invalid ticket keys length"},
260 {ERR_REASON(SSL_R_INVALID_TRUST) , "invalid trust"},
261 {ERR_REASON(SSL_R_KEY_ARG_TOO_LONG) , "key arg too long"},
262 {ERR_REASON(SSL_R_KRB5) , "krb5"},
263 {ERR_REASON(SSL_R_KRB5_C_CC_PRINC) , "krb5 client cc principal (no tkt?)"},
264 {ERR_REASON(SSL_R_KRB5_C_GET_CRED) , "krb5 client get cred"},
265 {ERR_REASON(SSL_R_KRB5_C_INIT) , "krb5 client init"},
266 {ERR_REASON(SSL_R_KRB5_C_MK_REQ) , "krb5 client mk_req (expired tkt?)"},
267 {ERR_REASON(SSL_R_KRB5_S_BAD_TICKET) , "krb5 server bad ticket"},
268 {ERR_REASON(SSL_R_KRB5_S_INIT) , "krb5 server init"},
269 {ERR_REASON(SSL_R_KRB5_S_RD_REQ) , "krb5 server rd_req (keytab perms?)"},
270 {ERR_REASON(SSL_R_KRB5_S_TKT_EXPIRED) , "krb5 server tkt expired"},
271 {ERR_REASON(SSL_R_KRB5_S_TKT_NYV) , "krb5 server tkt not yet valid"},
272 {ERR_REASON(SSL_R_KRB5_S_TKT_SKEW) , "krb5 server tkt skew"},
273 {ERR_REASON(SSL_R_LENGTH_MISMATCH) , "length mismatch"},
274 {ERR_REASON(SSL_R_LENGTH_TOO_SHORT) , "length too short"},
275 {ERR_REASON(SSL_R_LIBRARY_BUG) , "library bug"},
276 {ERR_REASON(SSL_R_LIBRARY_HAS_NO_CIPHERS), "library has no ciphers"},
277 {ERR_REASON(SSL_R_MESSAGE_TOO_LONG) , "message too long"},
278 {ERR_REASON(SSL_R_MISSING_DH_DSA_CERT) , "missing dh dsa cert"},
279 {ERR_REASON(SSL_R_MISSING_DH_KEY) , "missing dh key"},
280 {ERR_REASON(SSL_R_MISSING_DH_RSA_CERT) , "missing dh rsa cert"},
281 {ERR_REASON(SSL_R_MISSING_DSA_SIGNING_CERT), "missing dsa signing cert"},
282 {ERR_REASON(SSL_R_MISSING_EXPORT_TMP_DH_KEY), "missing export tmp dh key"},
283 {ERR_REASON(SSL_R_MISSING_EXPORT_TMP_RSA_KEY), "missing export tmp rsa key"},
284 {ERR_REASON(SSL_R_MISSING_RSA_CERTIFICATE), "missing rsa certificate"},
285 {ERR_REASON(SSL_R_MISSING_RSA_ENCRYPTING_CERT), "missing rsa encrypting cert"},
286 {ERR_REASON(SSL_R_MISSING_RSA_SIGNING_CERT), "missing rsa signing cert"},
287 {ERR_REASON(SSL_R_MISSING_SRP_PARAM) , "can't find SRP server param"},
288 {ERR_REASON(SSL_R_MISSING_TMP_DH_KEY) , "missing tmp dh key"},
289 {ERR_REASON(SSL_R_MISSING_TMP_ECDH_KEY) , "missing tmp ecdh key"},
290 {ERR_REASON(SSL_R_MISSING_TMP_RSA_KEY) , "missing tmp rsa key"},
291 {ERR_REASON(SSL_R_MISSING_TMP_RSA_PKEY) , "missing tmp rsa pkey"},
292 {ERR_REASON(SSL_R_MISSING_VERIFY_MESSAGE), "missing verify message"},
293 {ERR_REASON(SSL_R_MULTIPLE_SGC_RESTARTS) , "multiple sgc restarts"},
294 {ERR_REASON(SSL_R_NON_SSLV2_INITIAL_PACKET), "non sslv2 initial packet"},
295 {ERR_REASON(SSL_R_NO_APPLICATION_PROTOCOL), "no application protocol"},
296 {ERR_REASON(SSL_R_NO_CERTIFICATES_RETURNED), "no certificates returned"},
297 {ERR_REASON(SSL_R_NO_CERTIFICATE_ASSIGNED), "no certificate assigned"},
298 {ERR_REASON(SSL_R_NO_CERTIFICATE_RETURNED), "no certificate returned"},
299 {ERR_REASON(SSL_R_NO_CERTIFICATE_SET) , "no certificate set"},
300 {ERR_REASON(SSL_R_NO_CERTIFICATE_SPECIFIED), "no certificate specified"},
301 {ERR_REASON(SSL_R_NO_CIPHERS_AVAILABLE) , "no ciphers available"},
302 {ERR_REASON(SSL_R_NO_CIPHERS_PASSED) , "no ciphers passed"},
303 {ERR_REASON(SSL_R_NO_CIPHERS_SPECIFIED) , "no ciphers specified"},
304 {ERR_REASON(SSL_R_NO_CIPHER_LIST) , "no cipher list"},
305 {ERR_REASON(SSL_R_NO_CIPHER_MATCH) , "no cipher match"},
306 {ERR_REASON(SSL_R_NO_CLIENT_CERT_METHOD) , "no client cert method"},
307 {ERR_REASON(SSL_R_NO_CLIENT_CERT_RECEIVED), "no client cert received"},
308 {ERR_REASON(SSL_R_NO_COMPRESSION_SPECIFIED), "no compression specified"},
309 {ERR_REASON(SSL_R_NO_METHOD_SPECIFIED) , "no method specified"},
310 {ERR_REASON(SSL_R_NO_PRIVATEKEY) , "no privatekey"},
311 {ERR_REASON(SSL_R_NO_PRIVATE_KEY_ASSIGNED), "no private key assigned"},
312 {ERR_REASON(SSL_R_NO_PROTOCOLS_AVAILABLE), "no protocols available"},
313 {ERR_REASON(SSL_R_NO_PUBLICKEY) , "no publickey"},
314 {ERR_REASON(SSL_R_NO_RENEGOTIATION) , "no renegotiation"},
315 {ERR_REASON(SSL_R_NO_REQUIRED_DIGEST) , "digest requred for handshake isn't computed"},
316 {ERR_REASON(SSL_R_NO_SHARED_CIPHER) , "no shared cipher"},
317 {ERR_REASON(SSL_R_NO_SRTP_PROFILES) , "no srtp profiles"},
318 {ERR_REASON(SSL_R_NO_VERIFY_CALLBACK) , "no verify callback"},
319 {ERR_REASON(SSL_R_NULL_SSL_CTX) , "null ssl ctx"},
320 {ERR_REASON(SSL_R_NULL_SSL_METHOD_PASSED), "null ssl method passed"},
321 {ERR_REASON(SSL_R_OLD_SESSION_CIPHER_NOT_RETURNED), "old session cipher not returned"},
322 {ERR_REASON(SSL_R_OLD_SESSION_COMPRESSION_ALGORITHM_NOT_RETURNED), "old session compression algorithm not returned"},
323 {ERR_REASON(SSL_R_ONLY_TLS_ALLOWED_IN_FIPS_MODE), "only tls allowed in fips mode"},
324 {ERR_REASON(SSL_R_PACKET_LENGTH_TOO_LONG), "packet length too long"},
325 {ERR_REASON(SSL_R_PARSE_TLSEXT) , "parse tlsext"},
326 {ERR_REASON(SSL_R_PATH_TOO_LONG) , "path too long"},
327 {ERR_REASON(SSL_R_PEER_BEHAVING_BADLY) , "peer is doing strange or hostile things"},
328 {ERR_REASON(SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE), "peer did not return a certificate"},
329 {ERR_REASON(SSL_R_PEER_ERROR) , "peer error"},
330 {ERR_REASON(SSL_R_PEER_ERROR_CERTIFICATE), "peer error certificate"},
331 {ERR_REASON(SSL_R_PEER_ERROR_NO_CERTIFICATE), "peer error no certificate"},
332 {ERR_REASON(SSL_R_PEER_ERROR_NO_CIPHER) , "peer error no cipher"},
333 {ERR_REASON(SSL_R_PEER_ERROR_UNSUPPORTED_CERTIFICATE_TYPE), "peer error unsupported certificate type"},
334 {ERR_REASON(SSL_R_PRE_MAC_LENGTH_TOO_LONG), "pre mac length too long"},
335 {ERR_REASON(SSL_R_PROBLEMS_MAPPING_CIPHER_FUNCTIONS), "problems mapping cipher functions"},
336 {ERR_REASON(SSL_R_PROTOCOL_IS_SHUTDOWN) , "protocol is shutdown"},
337 {ERR_REASON(SSL_R_PSK_IDENTITY_NOT_FOUND), "psk identity not found"},
338 {ERR_REASON(SSL_R_PSK_NO_CLIENT_CB) , "psk no client cb"},
339 {ERR_REASON(SSL_R_PSK_NO_SERVER_CB) , "psk no server cb"},
340 {ERR_REASON(SSL_R_PUBLIC_KEY_ENCRYPT_ERROR), "public key encrypt error"},
341 {ERR_REASON(SSL_R_PUBLIC_KEY_IS_NOT_RSA) , "public key is not rsa"},
342 {ERR_REASON(SSL_R_PUBLIC_KEY_NOT_RSA) , "public key not rsa"},
343 {ERR_REASON(SSL_R_QUIC_INTERNAL_ERROR) , "QUIC: internal error"},
344 {ERR_REASON(SSL_R_READ_BIO_NOT_SET) , "read bio not set"},
345 {ERR_REASON(SSL_R_READ_TIMEOUT_EXPIRED) , "read timeout expired"},
346 {ERR_REASON(SSL_R_READ_WRONG_PACKET_TYPE), "read wrong packet type"},
347 {ERR_REASON(SSL_R_RECORD_LENGTH_MISMATCH), "record length mismatch"},
348 {ERR_REASON(SSL_R_RECORD_TOO_LARGE) , "record too large"},
349 {ERR_REASON(SSL_R_RECORD_TOO_SMALL) , "record too small"},
350 {ERR_REASON(SSL_R_RENEGOTIATE_EXT_TOO_LONG), "renegotiate ext too long"},
351 {ERR_REASON(SSL_R_RENEGOTIATION_ENCODING_ERR), "renegotiation encoding err"},
352 {ERR_REASON(SSL_R_RENEGOTIATION_MISMATCH), "renegotiation mismatch"},
353 {ERR_REASON(SSL_R_REQUIRED_CIPHER_MISSING), "required cipher missing"},
354 {ERR_REASON(SSL_R_REQUIRED_COMPRESSSION_ALGORITHM_MISSING), "required compresssion algorithm missing"},
355 {ERR_REASON(SSL_R_REUSE_CERT_LENGTH_NOT_ZERO), "reuse cert length not zero"},
356 {ERR_REASON(SSL_R_REUSE_CERT_TYPE_NOT_ZERO), "reuse cert type not zero"},
357 {ERR_REASON(SSL_R_REUSE_CIPHER_LIST_NOT_ZERO), "reuse cipher list not zero"},
358 {ERR_REASON(SSL_R_SCSV_RECEIVED_WHEN_RENEGOTIATING), "scsv received when renegotiating"},
359 {ERR_REASON(SSL_R_SERVERHELLO_TLSEXT) , "serverhello tlsext"},
360 {ERR_REASON(SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED), "session id context uninitialized"},
361 {ERR_REASON(SSL_R_SHORT_READ) , "short read"},
362 {ERR_REASON(SSL_R_SIGNATURE_ALGORITHMS_ERROR), "signature algorithms error"},
363 {ERR_REASON(SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE), "signature for non signing certificate"},
364 {ERR_REASON(SSL_R_SRP_A_CALC) , "error with the srp params"},
365 {ERR_REASON(SSL_R_SRTP_COULD_NOT_ALLOCATE_PROFILES), "srtp could not allocate profiles"},
366 {ERR_REASON(SSL_R_SRTP_PROTECTION_PROFILE_LIST_TOO_LONG), "srtp protection profile list too long"},
367 {ERR_REASON(SSL_R_SRTP_UNKNOWN_PROTECTION_PROFILE), "srtp unknown protection profile"},
368 {ERR_REASON(SSL_R_SSL23_DOING_SESSION_ID_REUSE), "ssl23 doing session id reuse"},
369 {ERR_REASON(SSL_R_SSL2_CONNECTION_ID_TOO_LONG), "ssl2 connection id too long"},
370 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_ECPOINTFORMAT), "ssl3 ext invalid ecpointformat"},
371 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME), "ssl3 ext invalid servername"},
372 {ERR_REASON(SSL_R_SSL3_EXT_INVALID_SERVERNAME_TYPE), "ssl3 ext invalid servername type"},
373 {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_LONG), "ssl3 session id too long"},
374 {ERR_REASON(SSL_R_SSL3_SESSION_ID_TOO_SHORT), "ssl3 session id too short"},
375 {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_CERTIFICATE), "sslv3 alert bad certificate"},
376 {ERR_REASON(SSL_R_SSLV3_ALERT_BAD_RECORD_MAC), "sslv3 alert bad record mac"},
377 {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_EXPIRED), "sslv3 alert certificate expired"},
378 {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_REVOKED), "sslv3 alert certificate revoked"},
379 {ERR_REASON(SSL_R_SSLV3_ALERT_CERTIFICATE_UNKNOWN), "sslv3 alert certificate unknown"},
380 {ERR_REASON(SSL_R_SSLV3_ALERT_DECOMPRESSION_FAILURE), "sslv3 alert decompression failure"},
381 {ERR_REASON(SSL_R_SSLV3_ALERT_HANDSHAKE_FAILURE), "sslv3 alert handshake failure"},
382 {ERR_REASON(SSL_R_SSLV3_ALERT_ILLEGAL_PARAMETER), "sslv3 alert illegal parameter"},
383 {ERR_REASON(SSL_R_SSLV3_ALERT_NO_CERTIFICATE), "sslv3 alert no certificate"},
384 {ERR_REASON(SSL_R_SSLV3_ALERT_UNEXPECTED_MESSAGE), "sslv3 alert unexpected message"},
385 {ERR_REASON(SSL_R_SSLV3_ALERT_UNSUPPORTED_CERTIFICATE), "sslv3 alert unsupported certificate"},
386 {ERR_REASON(SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION), "ssl ctx has no default ssl version"},
387 {ERR_REASON(SSL_R_SSL_HANDSHAKE_FAILURE) , "ssl handshake failure"},
388 {ERR_REASON(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS), "ssl library has no ciphers"},
389 {ERR_REASON(SSL_R_SSL_SESSION_ID_CALLBACK_FAILED), "ssl session id callback failed"},
390 {ERR_REASON(SSL_R_SSL_SESSION_ID_CONFLICT), "ssl session id conflict"},
391 {ERR_REASON(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG), "ssl session id context too long"},
392 {ERR_REASON(SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH), "ssl session id has bad length"},
393 {ERR_REASON(SSL_R_SSL_SESSION_ID_IS_DIFFERENT), "ssl session id is different"},
394 {ERR_REASON(SSL_R_SSL_SESSION_ID_TOO_LONG), "ssl session id is too long"},
395 {ERR_REASON(SSL_R_TLSV13_ALERT_CERTIFICATE_REQUIRED), "tlsv13 alert certificate required"},
396 {ERR_REASON(SSL_R_TLSV13_ALERT_MISSING_EXTENSION), "tlsv13 alert missing extension"},
397 {ERR_REASON(SSL_R_TLSV1_ALERT_ACCESS_DENIED), "tlsv1 alert access denied"},
398 {ERR_REASON(SSL_R_TLSV1_ALERT_DECODE_ERROR), "tlsv1 alert decode error"},
399 {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPTION_FAILED), "tlsv1 alert decryption failed"},
400 {ERR_REASON(SSL_R_TLSV1_ALERT_DECRYPT_ERROR), "tlsv1 alert decrypt error"},
401 {ERR_REASON(SSL_R_TLSV1_ALERT_EXPORT_RESTRICTION), "tlsv1 alert export restriction"},
402 {ERR_REASON(SSL_R_TLSV1_ALERT_INAPPROPRIATE_FALLBACK), "tlsv1 alert inappropriate fallback"},
403 {ERR_REASON(SSL_R_TLSV1_ALERT_INSUFFICIENT_SECURITY), "tlsv1 alert insufficient security"},
404 {ERR_REASON(SSL_R_TLSV1_ALERT_INTERNAL_ERROR), "tlsv1 alert internal error"},
405 {ERR_REASON(SSL_R_TLSV1_ALERT_NO_APPLICATION_PROTOCOL), "tlsv1 alert no application protocol"},
406 {ERR_REASON(SSL_R_TLSV1_ALERT_NO_RENEGOTIATION), "tlsv1 alert no renegotiation"},
407 {ERR_REASON(SSL_R_TLSV1_ALERT_PROTOCOL_VERSION), "tlsv1 alert protocol version"},
408 {ERR_REASON(SSL_R_TLSV1_ALERT_RECORD_OVERFLOW), "tlsv1 alert record overflow"},
409 {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_CA), "tlsv1 alert unknown ca"},
410 {ERR_REASON(SSL_R_TLSV1_ALERT_UNKNOWN_PSK_IDENTITY), "tlsv1 alert unknown psk_identity"},
411 {ERR_REASON(SSL_R_TLSV1_ALERT_USER_CANCELLED), "tlsv1 alert user cancelled"},
412 {ERR_REASON(SSL_R_TLSV1_BAD_CERTIFICATE_HASH_VALUE), "tlsv1 bad certificate hash value"},
413 {ERR_REASON(SSL_R_TLSV1_BAD_CERTIFICATE_STATUS_RESPONSE), "tlsv1 bad certificate status response"},
414 {ERR_REASON(SSL_R_TLSV1_CERTIFICATE_UNOBTAINABLE), "tlsv1 certificate unobtainable"},
415 {ERR_REASON(SSL_R_TLSV1_UNRECOGNIZED_NAME), "tlsv1 unrecognized name"},
416 {ERR_REASON(SSL_R_TLSV1_UNSUPPORTED_EXTENSION), "tlsv1 unsupported extension"},
417 {ERR_REASON(SSL_R_TLS_CLIENT_CERT_REQ_WITH_ANON_CIPHER), "tls client cert req with anon cipher"},
418 {ERR_REASON(SSL_R_TLS_HEARTBEAT_PEER_DOESNT_ACCEPT), "peer does not accept heartbeats"},
419 {ERR_REASON(SSL_R_TLS_HEARTBEAT_PENDING) , "heartbeat request already pending"},
420 {ERR_REASON(SSL_R_TLS_ILLEGAL_EXPORTER_LABEL), "tls illegal exporter label"},
421 {ERR_REASON(SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST), "tls invalid ecpointformat list"},
422 {ERR_REASON(SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST), "tls peer did not respond with certificate list"},
423 {ERR_REASON(SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG), "tls rsa encrypted value length is wrong"},
424 {ERR_REASON(SSL_R_UNABLE_TO_DECODE_DH_CERTS), "unable to decode dh certs"},
425 {ERR_REASON(SSL_R_UNABLE_TO_DECODE_ECDH_CERTS), "unable to decode ecdh certs"},
426 {ERR_REASON(SSL_R_UNABLE_TO_EXTRACT_PUBLIC_KEY), "unable to extract public key"},
427 {ERR_REASON(SSL_R_UNABLE_TO_FIND_DH_PARAMETERS), "unable to find dh parameters"},
428 {ERR_REASON(SSL_R_UNABLE_TO_FIND_ECDH_PARAMETERS), "unable to find ecdh parameters"},
429 {ERR_REASON(SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS), "unable to find public key parameters"},
430 {ERR_REASON(SSL_R_UNABLE_TO_FIND_SSL_METHOD), "unable to find ssl method"},
431 {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL2_MD5_ROUTINES), "unable to load ssl2 md5 routines"},
432 {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_MD5_ROUTINES), "unable to load ssl3 md5 routines"},
433 {ERR_REASON(SSL_R_UNABLE_TO_LOAD_SSL3_SHA1_ROUTINES), "unable to load ssl3 sha1 routines"},
434 {ERR_REASON(SSL_R_UNEXPECTED_MESSAGE) , "unexpected message"},
435 {ERR_REASON(SSL_R_UNEXPECTED_RECORD) , "unexpected record"},
436 {ERR_REASON(SSL_R_UNINITIALIZED) , "uninitialized"},
437 {ERR_REASON(SSL_R_UNKNOWN), "unknown failure occurred"},
438 {ERR_REASON(SSL_R_UNKNOWN_ALERT_TYPE) , "unknown alert type"},
439 {ERR_REASON(SSL_R_UNKNOWN_CERTIFICATE_TYPE), "unknown certificate type"},
440 {ERR_REASON(SSL_R_UNKNOWN_CIPHER_RETURNED), "unknown cipher returned"},
441 {ERR_REASON(SSL_R_UNKNOWN_CIPHER_TYPE) , "unknown cipher type"},
442 {ERR_REASON(SSL_R_UNKNOWN_DIGEST) , "unknown digest"},
443 {ERR_REASON(SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE), "unknown key exchange type"},
444 {ERR_REASON(SSL_R_UNKNOWN_PKEY_TYPE) , "unknown pkey type"},
445 {ERR_REASON(SSL_R_UNKNOWN_PROTOCOL) , "unknown protocol"},
446 {ERR_REASON(SSL_R_UNKNOWN_REMOTE_ERROR_TYPE), "unknown remote error type"},
447 {ERR_REASON(SSL_R_UNKNOWN_SSL_VERSION) , "unknown ssl version"},
448 {ERR_REASON(SSL_R_UNKNOWN_STATE) , "unknown state"},
449 {ERR_REASON(SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED), "unsafe legacy renegotiation disabled"},
450 {ERR_REASON(SSL_R_UNSUPPORTED_CIPHER) , "unsupported cipher"},
451 {ERR_REASON(SSL_R_UNSUPPORTED_COMPRESSION_ALGORITHM), "unsupported compression algorithm"},
452 {ERR_REASON(SSL_R_UNSUPPORTED_DIGEST_TYPE), "unsupported digest type"},
453 {ERR_REASON(SSL_R_UNSUPPORTED_ELLIPTIC_CURVE), "unsupported elliptic curve"},
454 {ERR_REASON(SSL_R_UNSUPPORTED_PROTOCOL) , "unsupported protocol"},
455 {ERR_REASON(SSL_R_UNSUPPORTED_SSL_VERSION), "unsupported ssl version"},
456 {ERR_REASON(SSL_R_UNSUPPORTED_STATUS_TYPE), "unsupported status type"},
457 {ERR_REASON(SSL_R_USE_SRTP_NOT_NEGOTIATED), "use srtp not negotiated"},
458 {ERR_REASON(SSL_R_VERSION_TOO_LOW) , "version too low"},
459 {ERR_REASON(SSL_R_WRITE_BIO_NOT_SET) , "write bio not set"},
460 {ERR_REASON(SSL_R_WRONG_CIPHER_RETURNED) , "wrong cipher returned"},
461 {ERR_REASON(SSL_R_WRONG_CURVE) , "wrong curve"},
462 {ERR_REASON(SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED), "QUIC: wrong encryption level received"},
463 {ERR_REASON(SSL_R_WRONG_MESSAGE_TYPE) , "wrong message type"},
464 {ERR_REASON(SSL_R_WRONG_NUMBER_OF_KEY_BITS), "wrong number of key bits"},
465 {ERR_REASON(SSL_R_WRONG_SIGNATURE_LENGTH), "wrong signature length"},
466 {ERR_REASON(SSL_R_WRONG_SIGNATURE_SIZE) , "wrong signature size"},
467 {ERR_REASON(SSL_R_WRONG_SIGNATURE_TYPE) , "wrong signature type"},
468 {ERR_REASON(SSL_R_WRONG_SSL_VERSION) , "wrong ssl version"},
469 {ERR_REASON(SSL_R_WRONG_VERSION_NUMBER) , "wrong version number"},
470 {ERR_REASON(SSL_R_X509_LIB) , "x509 lib"},
471 {ERR_REASON(SSL_R_X509_VERIFICATION_SETUP_PROBLEMS), "x509 verification setup problems"},
472 {0, NULL}
473};
474
475#endif
476
477void
478ERR_load_SSL_strings(void)
479{
480#ifndef OPENSSL_NO_ERR
481 if (ERR_func_error_string(SSL_str_functs[0].error) == NULL) {
482 /* TMP UGLY CASTS */
483 ERR_load_strings(0, (ERR_STRING_DATA *)SSL_str_functs);
484 ERR_load_strings(0, (ERR_STRING_DATA *)SSL_str_reasons);
485 }
486#endif
487}
488LSSL_ALIAS(ERR_load_SSL_strings);
489
490void
491SSL_load_error_strings(void)
492{
493#ifndef OPENSSL_NO_ERR
494 ERR_load_crypto_strings();
495 ERR_load_SSL_strings();
496#endif
497}
498LSSL_ALIAS(SSL_load_error_strings);
499
500int
501SSL_state_func_code(int state) {
502 switch (state) {
503 case SSL3_ST_CW_FLUSH:
504 return 1;
505 case SSL3_ST_CW_CLNT_HELLO_A:
506 return 2;
507 case SSL3_ST_CW_CLNT_HELLO_B:
508 return 3;
509 case SSL3_ST_CR_SRVR_HELLO_A:
510 return 4;
511 case SSL3_ST_CR_SRVR_HELLO_B:
512 return 5;
513 case SSL3_ST_CR_CERT_A:
514 return 6;
515 case SSL3_ST_CR_CERT_B:
516 return 7;
517 case SSL3_ST_CR_KEY_EXCH_A:
518 return 8;
519 case SSL3_ST_CR_KEY_EXCH_B:
520 return 9;
521 case SSL3_ST_CR_CERT_REQ_A:
522 return 10;
523 case SSL3_ST_CR_CERT_REQ_B:
524 return 11;
525 case SSL3_ST_CR_SRVR_DONE_A:
526 return 12;
527 case SSL3_ST_CR_SRVR_DONE_B:
528 return 13;
529 case SSL3_ST_CW_CERT_A:
530 return 14;
531 case SSL3_ST_CW_CERT_B:
532 return 15;
533 case SSL3_ST_CW_CERT_C:
534 return 16;
535 case SSL3_ST_CW_CERT_D:
536 return 17;
537 case SSL3_ST_CW_KEY_EXCH_A:
538 return 18;
539 case SSL3_ST_CW_KEY_EXCH_B:
540 return 19;
541 case SSL3_ST_CW_CERT_VRFY_A:
542 return 20;
543 case SSL3_ST_CW_CERT_VRFY_B:
544 return 21;
545 case SSL3_ST_CW_CHANGE_A:
546 return 22;
547 case SSL3_ST_CW_CHANGE_B:
548 return 23;
549 case SSL3_ST_CW_FINISHED_A:
550 return 26;
551 case SSL3_ST_CW_FINISHED_B:
552 return 27;
553 case SSL3_ST_CR_CHANGE_A:
554 return 28;
555 case SSL3_ST_CR_CHANGE_B:
556 return 29;
557 case SSL3_ST_CR_FINISHED_A:
558 return 30;
559 case SSL3_ST_CR_FINISHED_B:
560 return 31;
561 case SSL3_ST_CR_SESSION_TICKET_A:
562 return 32;
563 case SSL3_ST_CR_SESSION_TICKET_B:
564 return 33;
565 case SSL3_ST_CR_CERT_STATUS_A:
566 return 34;
567 case SSL3_ST_CR_CERT_STATUS_B:
568 return 35;
569 case SSL3_ST_SW_FLUSH:
570 return 36;
571 case SSL3_ST_SR_CLNT_HELLO_A:
572 return 37;
573 case SSL3_ST_SR_CLNT_HELLO_B:
574 return 38;
575 case SSL3_ST_SR_CLNT_HELLO_C:
576 return 39;
577 case SSL3_ST_SW_HELLO_REQ_A:
578 return 40;
579 case SSL3_ST_SW_HELLO_REQ_B:
580 return 41;
581 case SSL3_ST_SW_HELLO_REQ_C:
582 return 42;
583 case SSL3_ST_SW_SRVR_HELLO_A:
584 return 43;
585 case SSL3_ST_SW_SRVR_HELLO_B:
586 return 44;
587 case SSL3_ST_SW_CERT_A:
588 return 45;
589 case SSL3_ST_SW_CERT_B:
590 return 46;
591 case SSL3_ST_SW_KEY_EXCH_A:
592 return 47;
593 case SSL3_ST_SW_KEY_EXCH_B:
594 return 48;
595 case SSL3_ST_SW_CERT_REQ_A:
596 return 49;
597 case SSL3_ST_SW_CERT_REQ_B:
598 return 50;
599 case SSL3_ST_SW_SRVR_DONE_A:
600 return 51;
601 case SSL3_ST_SW_SRVR_DONE_B:
602 return 52;
603 case SSL3_ST_SR_CERT_A:
604 return 53;
605 case SSL3_ST_SR_CERT_B:
606 return 54;
607 case SSL3_ST_SR_KEY_EXCH_A:
608 return 55;
609 case SSL3_ST_SR_KEY_EXCH_B:
610 return 56;
611 case SSL3_ST_SR_CERT_VRFY_A:
612 return 57;
613 case SSL3_ST_SR_CERT_VRFY_B:
614 return 58;
615 case SSL3_ST_SR_CHANGE_A:
616 return 59;
617 case SSL3_ST_SR_CHANGE_B:
618 return 60;
619 case SSL3_ST_SR_FINISHED_A:
620 return 63;
621 case SSL3_ST_SR_FINISHED_B:
622 return 64;
623 case SSL3_ST_SW_CHANGE_A:
624 return 65;
625 case SSL3_ST_SW_CHANGE_B:
626 return 66;
627 case SSL3_ST_SW_FINISHED_A:
628 return 67;
629 case SSL3_ST_SW_FINISHED_B:
630 return 68;
631 case SSL3_ST_SW_SESSION_TICKET_A:
632 return 69;
633 case SSL3_ST_SW_SESSION_TICKET_B:
634 return 70;
635 case SSL3_ST_SW_CERT_STATUS_A:
636 return 71;
637 case SSL3_ST_SW_CERT_STATUS_B:
638 return 72;
639 case SSL_ST_BEFORE:
640 return 73;
641 case SSL_ST_ACCEPT:
642 return 74;
643 case SSL_ST_CONNECT:
644 return 75;
645 case SSL_ST_OK:
646 return 76;
647 case SSL_ST_RENEGOTIATE:
648 return 77;
649 case SSL_ST_BEFORE|SSL_ST_CONNECT:
650 return 78;
651 case SSL_ST_OK|SSL_ST_CONNECT:
652 return 79;
653 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
654 return 80;
655 case SSL_ST_OK|SSL_ST_ACCEPT:
656 return 81;
657 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
658 return 83;
659 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
660 return 84;
661 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
662 return 85;
663 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
664 return 86;
665 default:
666 break;
667 }
668 return 0xfff;
669}
670
671void
672SSL_error_internal(const SSL *s, int r, char *f, int l)
673{
674 ERR_PUT_error(ERR_LIB_SSL,
675 (SSL_state_func_code(s->s3->hs.state)), r, f, l);
676}
diff --git a/src/lib/libssl/ssl_init.c b/src/lib/libssl/ssl_init.c
deleted file mode 100644
index b314e714c1..0000000000
--- a/src/lib/libssl/ssl_init.c
+++ /dev/null
@@ -1,58 +0,0 @@
1/* $OpenBSD: ssl_init.c,v 1.6 2023/11/22 15:53:53 tb Exp $ */
2/*
3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18/* OpenSSL style init */
19
20#include <pthread.h>
21#include <stdio.h>
22
23#include <openssl/objects.h>
24
25#include "ssl_local.h"
26
27static pthread_t ssl_init_thread;
28
29int
30SSL_library_init(void)
31{
32 return OPENSSL_init_ssl(0, NULL);
33}
34LSSL_ALIAS(SSL_library_init);
35
36static void
37OPENSSL_init_ssl_internal(void)
38{
39 ssl_init_thread = pthread_self();
40 SSL_load_error_strings();
41}
42
43int
44OPENSSL_init_ssl(uint64_t opts, const void *settings)
45{
46 static pthread_once_t once = PTHREAD_ONCE_INIT;
47
48 if (pthread_equal(pthread_self(), ssl_init_thread))
49 return 1; /* don't recurse */
50
51 OPENSSL_init_crypto(opts, settings);
52
53 if (pthread_once(&once, OPENSSL_init_ssl_internal) != 0)
54 return 0;
55
56 return 1;
57}
58LSSL_ALIAS(OPENSSL_init_ssl);
diff --git a/src/lib/libssl/ssl_kex.c b/src/lib/libssl/ssl_kex.c
deleted file mode 100644
index fa420a35a3..0000000000
--- a/src/lib/libssl/ssl_kex.c
+++ /dev/null
@@ -1,422 +0,0 @@
1/* $OpenBSD: ssl_kex.c,v 1.12 2023/07/28 16:02:34 tb Exp $ */
2/*
3 * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19
20#include <openssl/bn.h>
21#include <openssl/dh.h>
22#include <openssl/ec.h>
23#include <openssl/evp.h>
24#include <openssl/objects.h>
25
26#include "bytestring.h"
27
28#define DHE_MINIMUM_BITS 1024
29
30int
31ssl_kex_generate_dhe(DH *dh, DH *dh_params)
32{
33 BIGNUM *p = NULL, *g = NULL;
34 int ret = 0;
35
36 if ((p = BN_dup(DH_get0_p(dh_params))) == NULL)
37 goto err;
38 if ((g = BN_dup(DH_get0_g(dh_params))) == NULL)
39 goto err;
40
41 if (!DH_set0_pqg(dh, p, NULL, g))
42 goto err;
43 p = NULL;
44 g = NULL;
45
46 if (!DH_generate_key(dh))
47 goto err;
48
49 ret = 1;
50
51 err:
52 BN_free(p);
53 BN_free(g);
54
55 return ret;
56}
57
58int
59ssl_kex_generate_dhe_params_auto(DH *dh, size_t key_bits)
60{
61 BIGNUM *p = NULL, *g = NULL;
62 int ret = 0;
63
64 if (key_bits >= 8192)
65 p = BN_get_rfc3526_prime_8192(NULL);
66 else if (key_bits >= 4096)
67 p = BN_get_rfc3526_prime_4096(NULL);
68 else if (key_bits >= 3072)
69 p = BN_get_rfc3526_prime_3072(NULL);
70 else if (key_bits >= 2048)
71 p = BN_get_rfc3526_prime_2048(NULL);
72 else if (key_bits >= 1536)
73 p = BN_get_rfc3526_prime_1536(NULL);
74 else
75 p = BN_get_rfc2409_prime_1024(NULL);
76
77 if (p == NULL)
78 goto err;
79
80 if ((g = BN_new()) == NULL)
81 goto err;
82 if (!BN_set_word(g, 2))
83 goto err;
84
85 if (!DH_set0_pqg(dh, p, NULL, g))
86 goto err;
87 p = NULL;
88 g = NULL;
89
90 if (!DH_generate_key(dh))
91 goto err;
92
93 ret = 1;
94
95 err:
96 BN_free(p);
97 BN_free(g);
98
99 return ret;
100}
101
102int
103ssl_kex_params_dhe(DH *dh, CBB *cbb)
104{
105 int dh_p_len, dh_g_len;
106 CBB dh_p, dh_g;
107 uint8_t *data;
108
109 if ((dh_p_len = BN_num_bytes(DH_get0_p(dh))) <= 0)
110 return 0;
111 if ((dh_g_len = BN_num_bytes(DH_get0_g(dh))) <= 0)
112 return 0;
113
114 if (!CBB_add_u16_length_prefixed(cbb, &dh_p))
115 return 0;
116 if (!CBB_add_space(&dh_p, &data, dh_p_len))
117 return 0;
118 if (BN_bn2bin(DH_get0_p(dh), data) != dh_p_len)
119 return 0;
120
121 if (!CBB_add_u16_length_prefixed(cbb, &dh_g))
122 return 0;
123 if (!CBB_add_space(&dh_g, &data, dh_g_len))
124 return 0;
125 if (BN_bn2bin(DH_get0_g(dh), data) != dh_g_len)
126 return 0;
127
128 if (!CBB_flush(cbb))
129 return 0;
130
131 return 1;
132}
133
134int
135ssl_kex_public_dhe(DH *dh, CBB *cbb)
136{
137 uint8_t *data;
138 int dh_y_len;
139 CBB dh_y;
140
141 if ((dh_y_len = BN_num_bytes(DH_get0_pub_key(dh))) <= 0)
142 return 0;
143
144 if (!CBB_add_u16_length_prefixed(cbb, &dh_y))
145 return 0;
146 if (!CBB_add_space(&dh_y, &data, dh_y_len))
147 return 0;
148 if (BN_bn2bin(DH_get0_pub_key(dh), data) != dh_y_len)
149 return 0;
150
151 if (!CBB_flush(cbb))
152 return 0;
153
154 return 1;
155}
156
157int
158ssl_kex_peer_params_dhe(DH *dh, CBS *cbs, int *decode_error,
159 int *invalid_params)
160{
161 BIGNUM *p = NULL, *g = NULL;
162 CBS dh_p, dh_g;
163 int ret = 0;
164
165 *decode_error = 0;
166 *invalid_params = 0;
167
168 if (!CBS_get_u16_length_prefixed(cbs, &dh_p)) {
169 *decode_error = 1;
170 goto err;
171 }
172 if (!CBS_get_u16_length_prefixed(cbs, &dh_g)) {
173 *decode_error = 1;
174 goto err;
175 }
176
177 if ((p = BN_bin2bn(CBS_data(&dh_p), CBS_len(&dh_p), NULL)) == NULL)
178 goto err;
179 if ((g = BN_bin2bn(CBS_data(&dh_g), CBS_len(&dh_g), NULL)) == NULL)
180 goto err;
181
182 if (!DH_set0_pqg(dh, p, NULL, g))
183 goto err;
184 p = NULL;
185 g = NULL;
186
187 /* XXX - consider calling DH_check(). */
188
189 if (DH_bits(dh) < DHE_MINIMUM_BITS)
190 *invalid_params = 1;
191
192 ret = 1;
193
194 err:
195 BN_free(p);
196 BN_free(g);
197
198 return ret;
199}
200
201int
202ssl_kex_peer_public_dhe(DH *dh, CBS *cbs, int *decode_error,
203 int *invalid_key)
204{
205 BIGNUM *pub_key = NULL;
206 int check_flags;
207 CBS dh_y;
208 int ret = 0;
209
210 *decode_error = 0;
211 *invalid_key = 0;
212
213 if (!CBS_get_u16_length_prefixed(cbs, &dh_y)) {
214 *decode_error = 1;
215 goto err;
216 }
217
218 if ((pub_key = BN_bin2bn(CBS_data(&dh_y), CBS_len(&dh_y),
219 NULL)) == NULL)
220 goto err;
221
222 if (!DH_set0_key(dh, pub_key, NULL))
223 goto err;
224 pub_key = NULL;
225
226 if (!DH_check_pub_key(dh, DH_get0_pub_key(dh), &check_flags))
227 goto err;
228 if (check_flags != 0)
229 *invalid_key = 1;
230
231 ret = 1;
232
233 err:
234 BN_free(pub_key);
235
236 return ret;
237}
238
239int
240ssl_kex_derive_dhe(DH *dh, DH *dh_peer,
241 uint8_t **shared_key, size_t *shared_key_len)
242{
243 uint8_t *key = NULL;
244 int key_len = 0;
245 int ret = 0;
246
247 if ((key_len = DH_size(dh)) <= 0)
248 goto err;
249 if ((key = calloc(1, key_len)) == NULL)
250 goto err;
251
252 if ((key_len = DH_compute_key(key, DH_get0_pub_key(dh_peer), dh)) <= 0)
253 goto err;
254
255 *shared_key = key;
256 *shared_key_len = key_len;
257 key = NULL;
258
259 ret = 1;
260
261 err:
262 freezero(key, key_len);
263
264 return ret;
265}
266
267int
268ssl_kex_dummy_ecdhe_x25519(EVP_PKEY *pkey)
269{
270 EC_GROUP *group = NULL;
271 EC_POINT *point = NULL;
272 EC_KEY *ec_key = NULL;
273 BIGNUM *order = NULL;
274 int ret = 0;
275
276 /* Fudge up an EC_KEY that looks like X25519... */
277 if ((group = EC_GROUP_new_by_curve_name(NID_X9_62_prime256v1)) == NULL)
278 goto err;
279 if ((point = EC_POINT_new(group)) == NULL)
280 goto err;
281 if ((order = BN_new()) == NULL)
282 goto err;
283 if (!BN_set_bit(order, 252))
284 goto err;
285 if (!EC_GROUP_set_generator(group, point, order, NULL))
286 goto err;
287 EC_GROUP_set_curve_name(group, NID_X25519);
288 if ((ec_key = EC_KEY_new()) == NULL)
289 goto err;
290 if (!EC_KEY_set_group(ec_key, group))
291 goto err;
292 if (!EVP_PKEY_set1_EC_KEY(pkey, ec_key))
293 goto err;
294
295 ret = 1;
296
297 err:
298 EC_GROUP_free(group);
299 EC_POINT_free(point);
300 EC_KEY_free(ec_key);
301 BN_free(order);
302
303 return ret;
304}
305
306int
307ssl_kex_generate_ecdhe_ecp(EC_KEY *ecdh, int nid)
308{
309 EC_GROUP *group;
310 int ret = 0;
311
312 if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL)
313 goto err;
314
315 if (!EC_KEY_set_group(ecdh, group))
316 goto err;
317 if (!EC_KEY_generate_key(ecdh))
318 goto err;
319
320 ret = 1;
321
322 err:
323 EC_GROUP_free(group);
324
325 return ret;
326}
327
328int
329ssl_kex_public_ecdhe_ecp(EC_KEY *ecdh, CBB *cbb)
330{
331 const EC_GROUP *group;
332 const EC_POINT *point;
333 uint8_t *ecp;
334 size_t ecp_len;
335 int ret = 0;
336
337 if ((group = EC_KEY_get0_group(ecdh)) == NULL)
338 goto err;
339 if ((point = EC_KEY_get0_public_key(ecdh)) == NULL)
340 goto err;
341
342 if ((ecp_len = EC_POINT_point2oct(group, point,
343 POINT_CONVERSION_UNCOMPRESSED, NULL, 0, NULL)) == 0)
344 goto err;
345 if (!CBB_add_space(cbb, &ecp, ecp_len))
346 goto err;
347 if ((EC_POINT_point2oct(group, point, POINT_CONVERSION_UNCOMPRESSED,
348 ecp, ecp_len, NULL)) == 0)
349 goto err;
350
351 ret = 1;
352
353 err:
354 return ret;
355}
356
357int
358ssl_kex_peer_public_ecdhe_ecp(EC_KEY *ecdh, int nid, CBS *cbs)
359{
360 EC_GROUP *group = NULL;
361 EC_POINT *point = NULL;
362 int ret = 0;
363
364 if ((group = EC_GROUP_new_by_curve_name(nid)) == NULL)
365 goto err;
366
367 if (!EC_KEY_set_group(ecdh, group))
368 goto err;
369
370 if ((point = EC_POINT_new(group)) == NULL)
371 goto err;
372 if (EC_POINT_oct2point(group, point, CBS_data(cbs), CBS_len(cbs),
373 NULL) == 0)
374 goto err;
375 if (!EC_KEY_set_public_key(ecdh, point))
376 goto err;
377
378 ret = 1;
379
380 err:
381 EC_GROUP_free(group);
382 EC_POINT_free(point);
383
384 return ret;
385}
386
387int
388ssl_kex_derive_ecdhe_ecp(EC_KEY *ecdh, EC_KEY *ecdh_peer,
389 uint8_t **shared_key, size_t *shared_key_len)
390{
391 const EC_POINT *point;
392 uint8_t *key = NULL;
393 int key_len = 0;
394 int ret = 0;
395
396 if (!EC_GROUP_check(EC_KEY_get0_group(ecdh), NULL))
397 goto err;
398 if (!EC_GROUP_check(EC_KEY_get0_group(ecdh_peer), NULL))
399 goto err;
400
401 if ((point = EC_KEY_get0_public_key(ecdh_peer)) == NULL)
402 goto err;
403
404 if ((key_len = ECDH_size(ecdh)) <= 0)
405 goto err;
406 if ((key = calloc(1, key_len)) == NULL)
407 goto err;
408
409 if (ECDH_compute_key(key, key_len, point, ecdh, NULL) <= 0)
410 goto err;
411
412 *shared_key = key;
413 *shared_key_len = key_len;
414 key = NULL;
415
416 ret = 1;
417
418 err:
419 freezero(key, key_len);
420
421 return ret;
422}
diff --git a/src/lib/libssl/ssl_lib.c b/src/lib/libssl/ssl_lib.c
deleted file mode 100644
index ce68981493..0000000000
--- a/src/lib/libssl/ssl_lib.c
+++ /dev/null
@@ -1,3663 +0,0 @@
1/* $OpenBSD: ssl_lib.c,v 1.331 2025/03/12 14:03:55 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#include <arpa/inet.h>
144#include <sys/socket.h>
145#include <netinet/in.h>
146
147#include <limits.h>
148#include <stdio.h>
149
150#include <openssl/dh.h>
151#include <openssl/lhash.h>
152#include <openssl/objects.h>
153#include <openssl/ocsp.h>
154#include <openssl/opensslconf.h>
155#include <openssl/x509v3.h>
156
157#include "bytestring.h"
158#include "dtls_local.h"
159#include "ssl_local.h"
160#include "ssl_sigalgs.h"
161#include "ssl_tlsext.h"
162#include "tls12_internal.h"
163
164int
165SSL_clear(SSL *s)
166{
167 if (s->method == NULL) {
168 SSLerror(s, SSL_R_NO_METHOD_SPECIFIED);
169 return (0);
170 }
171
172 if (ssl_clear_bad_session(s)) {
173 SSL_SESSION_free(s->session);
174 s->session = NULL;
175 }
176
177 s->error = 0;
178 s->hit = 0;
179 s->shutdown = 0;
180
181 if (s->renegotiate) {
182 SSLerror(s, ERR_R_INTERNAL_ERROR);
183 return (0);
184 }
185
186 s->version = s->method->version;
187 s->client_version = s->version;
188 s->rwstate = SSL_NOTHING;
189 s->rstate = SSL_ST_READ_HEADER;
190
191 tls13_ctx_free(s->tls13);
192 s->tls13 = NULL;
193
194 ssl3_release_init_buffer(s);
195
196 ssl_clear_cipher_state(s);
197
198 s->first_packet = 0;
199
200 /*
201 * Check to see if we were changed into a different method, if
202 * so, revert back if we are not doing session-id reuse.
203 */
204 if (!s->in_handshake && (s->session == NULL) &&
205 (s->method != s->ctx->method)) {
206 s->method->ssl_free(s);
207 s->method = s->ctx->method;
208 if (!s->method->ssl_new(s))
209 return (0);
210 } else
211 s->method->ssl_clear(s);
212
213 return (1);
214}
215LSSL_ALIAS(SSL_clear);
216
217/* Used to change an SSL_CTXs default SSL method type */
218int
219SSL_CTX_set_ssl_version(SSL_CTX *ctx, const SSL_METHOD *meth)
220{
221 STACK_OF(SSL_CIPHER) *ciphers;
222
223 ctx->method = meth;
224
225 ciphers = ssl_create_cipher_list(ctx->method, &ctx->cipher_list,
226 ctx->cipher_list_tls13, SSL_DEFAULT_CIPHER_LIST,
227 ctx->cert);
228 if (ciphers == NULL || sk_SSL_CIPHER_num(ciphers) <= 0) {
229 SSLerrorx(SSL_R_SSL_LIBRARY_HAS_NO_CIPHERS);
230 return (0);
231 }
232 return (1);
233}
234LSSL_ALIAS(SSL_CTX_set_ssl_version);
235
236SSL *
237SSL_new(SSL_CTX *ctx)
238{
239 SSL *s;
240 CBS cbs;
241
242 if (ctx == NULL) {
243 SSLerrorx(SSL_R_NULL_SSL_CTX);
244 return (NULL);
245 }
246 if (ctx->method == NULL) {
247 SSLerrorx(SSL_R_SSL_CTX_HAS_NO_DEFAULT_SSL_VERSION);
248 return (NULL);
249 }
250
251 if ((s = calloc(1, sizeof(*s))) == NULL)
252 goto err;
253
254 if ((s->rl = tls12_record_layer_new()) == NULL)
255 goto err;
256
257 s->min_tls_version = ctx->min_tls_version;
258 s->max_tls_version = ctx->max_tls_version;
259 s->min_proto_version = ctx->min_proto_version;
260 s->max_proto_version = ctx->max_proto_version;
261
262 s->options = ctx->options;
263 s->mode = ctx->mode;
264 s->max_cert_list = ctx->max_cert_list;
265 s->num_tickets = ctx->num_tickets;
266
267 if ((s->cert = ssl_cert_dup(ctx->cert)) == NULL)
268 goto err;
269
270 s->read_ahead = ctx->read_ahead;
271 s->msg_callback = ctx->msg_callback;
272 s->msg_callback_arg = ctx->msg_callback_arg;
273 s->verify_mode = ctx->verify_mode;
274 s->sid_ctx_length = ctx->sid_ctx_length;
275 OPENSSL_assert(s->sid_ctx_length <= sizeof s->sid_ctx);
276 memcpy(&s->sid_ctx, &ctx->sid_ctx, sizeof(s->sid_ctx));
277 s->verify_callback = ctx->default_verify_callback;
278 s->generate_session_id = ctx->generate_session_id;
279
280 s->param = X509_VERIFY_PARAM_new();
281 if (!s->param)
282 goto err;
283 X509_VERIFY_PARAM_inherit(s->param, ctx->param);
284 s->quiet_shutdown = ctx->quiet_shutdown;
285 s->max_send_fragment = ctx->max_send_fragment;
286
287 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
288 s->ctx = ctx;
289 s->tlsext_debug_cb = NULL;
290 s->tlsext_debug_arg = NULL;
291 s->tlsext_ticket_expected = 0;
292 s->tlsext_status_type = -1;
293 s->tlsext_status_expected = 0;
294 s->tlsext_ocsp_ids = NULL;
295 s->tlsext_ocsp_exts = NULL;
296 s->tlsext_ocsp_resp = NULL;
297 s->tlsext_ocsp_resp_len = 0;
298 CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
299 s->initial_ctx = ctx;
300
301 if (!tlsext_randomize_build_order(s))
302 goto err;
303
304 if (ctx->tlsext_ecpointformatlist != NULL) {
305 s->tlsext_ecpointformatlist =
306 calloc(ctx->tlsext_ecpointformatlist_length,
307 sizeof(ctx->tlsext_ecpointformatlist[0]));
308 if (s->tlsext_ecpointformatlist == NULL)
309 goto err;
310 memcpy(s->tlsext_ecpointformatlist,
311 ctx->tlsext_ecpointformatlist,
312 ctx->tlsext_ecpointformatlist_length *
313 sizeof(ctx->tlsext_ecpointformatlist[0]));
314 s->tlsext_ecpointformatlist_length =
315 ctx->tlsext_ecpointformatlist_length;
316 }
317 if (ctx->tlsext_supportedgroups != NULL) {
318 s->tlsext_supportedgroups =
319 calloc(ctx->tlsext_supportedgroups_length,
320 sizeof(ctx->tlsext_supportedgroups[0]));
321 if (s->tlsext_supportedgroups == NULL)
322 goto err;
323 memcpy(s->tlsext_supportedgroups,
324 ctx->tlsext_supportedgroups,
325 ctx->tlsext_supportedgroups_length *
326 sizeof(ctx->tlsext_supportedgroups[0]));
327 s->tlsext_supportedgroups_length =
328 ctx->tlsext_supportedgroups_length;
329 }
330
331 CBS_init(&cbs, ctx->alpn_client_proto_list,
332 ctx->alpn_client_proto_list_len);
333 if (!CBS_stow(&cbs, &s->alpn_client_proto_list,
334 &s->alpn_client_proto_list_len))
335 goto err;
336
337 s->verify_result = X509_V_OK;
338
339 s->method = ctx->method;
340 s->quic_method = ctx->quic_method;
341
342 if (!s->method->ssl_new(s))
343 goto err;
344
345 s->references = 1;
346 s->server = ctx->method->server;
347
348 SSL_clear(s);
349
350 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
351
352 return (s);
353
354 err:
355 SSL_free(s);
356 SSLerrorx(ERR_R_MALLOC_FAILURE);
357 return (NULL);
358}
359LSSL_ALIAS(SSL_new);
360
361int
362SSL_CTX_set_session_id_context(SSL_CTX *ctx, const unsigned char *sid_ctx,
363 unsigned int sid_ctx_len)
364{
365 if (sid_ctx_len > sizeof ctx->sid_ctx) {
366 SSLerrorx(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
367 return (0);
368 }
369 ctx->sid_ctx_length = sid_ctx_len;
370 memcpy(ctx->sid_ctx, sid_ctx, sid_ctx_len);
371
372 return (1);
373}
374LSSL_ALIAS(SSL_CTX_set_session_id_context);
375
376int
377SSL_set_session_id_context(SSL *ssl, const unsigned char *sid_ctx,
378 unsigned int sid_ctx_len)
379{
380 if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
381 SSLerror(ssl, SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
382 return (0);
383 }
384 ssl->sid_ctx_length = sid_ctx_len;
385 memcpy(ssl->sid_ctx, sid_ctx, sid_ctx_len);
386
387 return (1);
388}
389LSSL_ALIAS(SSL_set_session_id_context);
390
391int
392SSL_CTX_set_generate_session_id(SSL_CTX *ctx, GEN_SESSION_CB cb)
393{
394 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
395 ctx->generate_session_id = cb;
396 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
397 return (1);
398}
399LSSL_ALIAS(SSL_CTX_set_generate_session_id);
400
401int
402SSL_set_generate_session_id(SSL *ssl, GEN_SESSION_CB cb)
403{
404 CRYPTO_w_lock(CRYPTO_LOCK_SSL);
405 ssl->generate_session_id = cb;
406 CRYPTO_w_unlock(CRYPTO_LOCK_SSL);
407 return (1);
408}
409LSSL_ALIAS(SSL_set_generate_session_id);
410
411int
412SSL_has_matching_session_id(const SSL *ssl, const unsigned char *id,
413 unsigned int id_len)
414{
415 /*
416 * A quick examination of SSL_SESSION_hash and SSL_SESSION_cmp
417 * shows how we can "construct" a session to give us the desired
418 * check - ie. to find if there's a session in the hash table
419 * that would conflict with any new session built out of this
420 * id/id_len and the ssl_version in use by this SSL.
421 */
422 SSL_SESSION r, *p;
423
424 if (id_len > sizeof r.session_id)
425 return (0);
426
427 r.ssl_version = ssl->version;
428 r.session_id_length = id_len;
429 memcpy(r.session_id, id, id_len);
430
431 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
432 p = lh_SSL_SESSION_retrieve(ssl->ctx->sessions, &r);
433 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
434 return (p != NULL);
435}
436LSSL_ALIAS(SSL_has_matching_session_id);
437
438int
439SSL_CTX_set_purpose(SSL_CTX *s, int purpose)
440{
441 return (X509_VERIFY_PARAM_set_purpose(s->param, purpose));
442}
443LSSL_ALIAS(SSL_CTX_set_purpose);
444
445int
446SSL_set_purpose(SSL *s, int purpose)
447{
448 return (X509_VERIFY_PARAM_set_purpose(s->param, purpose));
449}
450LSSL_ALIAS(SSL_set_purpose);
451
452int
453SSL_CTX_set_trust(SSL_CTX *s, int trust)
454{
455 return (X509_VERIFY_PARAM_set_trust(s->param, trust));
456}
457LSSL_ALIAS(SSL_CTX_set_trust);
458
459int
460SSL_set_trust(SSL *s, int trust)
461{
462 return (X509_VERIFY_PARAM_set_trust(s->param, trust));
463}
464LSSL_ALIAS(SSL_set_trust);
465
466int
467SSL_set1_host(SSL *s, const char *hostname)
468{
469 struct in_addr ina;
470 struct in6_addr in6a;
471
472 if (hostname != NULL && *hostname != '\0' &&
473 (inet_pton(AF_INET, hostname, &ina) == 1 ||
474 inet_pton(AF_INET6, hostname, &in6a) == 1))
475 return X509_VERIFY_PARAM_set1_ip_asc(s->param, hostname);
476 else
477 return X509_VERIFY_PARAM_set1_host(s->param, hostname, 0);
478}
479LSSL_ALIAS(SSL_set1_host);
480
481void
482SSL_set_hostflags(SSL *s, unsigned int flags)
483{
484 X509_VERIFY_PARAM_set_hostflags(s->param, flags);
485}
486LSSL_ALIAS(SSL_set_hostflags);
487
488const char *
489SSL_get0_peername(SSL *s)
490{
491 return X509_VERIFY_PARAM_get0_peername(s->param);
492}
493LSSL_ALIAS(SSL_get0_peername);
494
495X509_VERIFY_PARAM *
496SSL_CTX_get0_param(SSL_CTX *ctx)
497{
498 return (ctx->param);
499}
500LSSL_ALIAS(SSL_CTX_get0_param);
501
502int
503SSL_CTX_set1_param(SSL_CTX *ctx, X509_VERIFY_PARAM *vpm)
504{
505 return (X509_VERIFY_PARAM_set1(ctx->param, vpm));
506}
507LSSL_ALIAS(SSL_CTX_set1_param);
508
509X509_VERIFY_PARAM *
510SSL_get0_param(SSL *ssl)
511{
512 return (ssl->param);
513}
514LSSL_ALIAS(SSL_get0_param);
515
516int
517SSL_set1_param(SSL *ssl, X509_VERIFY_PARAM *vpm)
518{
519 return (X509_VERIFY_PARAM_set1(ssl->param, vpm));
520}
521LSSL_ALIAS(SSL_set1_param);
522
523void
524SSL_free(SSL *s)
525{
526 int i;
527
528 if (s == NULL)
529 return;
530
531 i = CRYPTO_add(&s->references, -1, CRYPTO_LOCK_SSL);
532 if (i > 0)
533 return;
534
535 X509_VERIFY_PARAM_free(s->param);
536
537 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL, s, &s->ex_data);
538
539 if (s->bbio != NULL) {
540 /* If the buffering BIO is in place, pop it off */
541 if (s->bbio == s->wbio) {
542 s->wbio = BIO_pop(s->wbio);
543 }
544 BIO_free(s->bbio);
545 s->bbio = NULL;
546 }
547
548 if (s->rbio != s->wbio)
549 BIO_free_all(s->rbio);
550 BIO_free_all(s->wbio);
551
552 tls13_ctx_free(s->tls13);
553
554 ssl3_release_init_buffer(s);
555
556 sk_SSL_CIPHER_free(s->cipher_list);
557 sk_SSL_CIPHER_free(s->cipher_list_tls13);
558
559 /* Make the next call work :-) */
560 if (s->session != NULL) {
561 ssl_clear_bad_session(s);
562 SSL_SESSION_free(s->session);
563 }
564
565 ssl_clear_cipher_state(s);
566
567 ssl_cert_free(s->cert);
568
569 free(s->tlsext_build_order);
570
571 free(s->tlsext_hostname);
572 SSL_CTX_free(s->initial_ctx);
573
574 free(s->tlsext_ecpointformatlist);
575 free(s->tlsext_supportedgroups);
576
577 sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
578 X509_EXTENSION_free);
579 sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);
580 free(s->tlsext_ocsp_resp);
581
582 sk_X509_NAME_pop_free(s->client_CA, X509_NAME_free);
583
584 if (s->method != NULL)
585 s->method->ssl_free(s);
586
587 SSL_CTX_free(s->ctx);
588
589 free(s->alpn_client_proto_list);
590
591 free(s->quic_transport_params);
592
593#ifndef OPENSSL_NO_SRTP
594 sk_SRTP_PROTECTION_PROFILE_free(s->srtp_profiles);
595#endif
596
597 tls12_record_layer_free(s->rl);
598
599 free(s);
600}
601LSSL_ALIAS(SSL_free);
602
603int
604SSL_up_ref(SSL *s)
605{
606 return CRYPTO_add(&s->references, 1, CRYPTO_LOCK_SSL) > 1;
607}
608LSSL_ALIAS(SSL_up_ref);
609
610void
611SSL_set_bio(SSL *s, BIO *rbio, BIO *wbio)
612{
613 /* If the output buffering BIO is still in place, remove it */
614 if (s->bbio != NULL) {
615 if (s->wbio == s->bbio) {
616 s->wbio = BIO_next(s->wbio);
617 BIO_set_next(s->bbio, NULL);
618 }
619 }
620
621 if (s->rbio != rbio && s->rbio != s->wbio)
622 BIO_free_all(s->rbio);
623 if (s->wbio != wbio)
624 BIO_free_all(s->wbio);
625 s->rbio = rbio;
626 s->wbio = wbio;
627}
628LSSL_ALIAS(SSL_set_bio);
629
630BIO *
631SSL_get_rbio(const SSL *s)
632{
633 return (s->rbio);
634}
635LSSL_ALIAS(SSL_get_rbio);
636
637void
638SSL_set0_rbio(SSL *s, BIO *rbio)
639{
640 BIO_free_all(s->rbio);
641 s->rbio = rbio;
642}
643LSSL_ALIAS(SSL_set0_rbio);
644
645BIO *
646SSL_get_wbio(const SSL *s)
647{
648 return (s->wbio);
649}
650LSSL_ALIAS(SSL_get_wbio);
651
652int
653SSL_get_fd(const SSL *s)
654{
655 return (SSL_get_rfd(s));
656}
657LSSL_ALIAS(SSL_get_fd);
658
659int
660SSL_get_rfd(const SSL *s)
661{
662 int ret = -1;
663 BIO *b, *r;
664
665 b = SSL_get_rbio(s);
666 r = BIO_find_type(b, BIO_TYPE_DESCRIPTOR);
667 if (r != NULL)
668 BIO_get_fd(r, &ret);
669 return (ret);
670}
671LSSL_ALIAS(SSL_get_rfd);
672
673int
674SSL_get_wfd(const SSL *s)
675{
676 int ret = -1;
677 BIO *b, *r;
678
679 b = SSL_get_wbio(s);
680 r = BIO_find_type(b, BIO_TYPE_DESCRIPTOR);
681 if (r != NULL)
682 BIO_get_fd(r, &ret);
683 return (ret);
684}
685LSSL_ALIAS(SSL_get_wfd);
686
687int
688SSL_set_fd(SSL *s, int fd)
689{
690 int ret = 0;
691 BIO *bio = NULL;
692
693 bio = BIO_new(BIO_s_socket());
694
695 if (bio == NULL) {
696 SSLerror(s, ERR_R_BUF_LIB);
697 goto err;
698 }
699 BIO_set_fd(bio, fd, BIO_NOCLOSE);
700 SSL_set_bio(s, bio, bio);
701 ret = 1;
702 err:
703 return (ret);
704}
705LSSL_ALIAS(SSL_set_fd);
706
707int
708SSL_set_wfd(SSL *s, int fd)
709{
710 int ret = 0;
711 BIO *bio = NULL;
712
713 if ((s->rbio == NULL) || (BIO_method_type(s->rbio) != BIO_TYPE_SOCKET)
714 || ((int)BIO_get_fd(s->rbio, NULL) != fd)) {
715 bio = BIO_new(BIO_s_socket());
716
717 if (bio == NULL) {
718 SSLerror(s, ERR_R_BUF_LIB);
719 goto err;
720 }
721 BIO_set_fd(bio, fd, BIO_NOCLOSE);
722 SSL_set_bio(s, SSL_get_rbio(s), bio);
723 } else
724 SSL_set_bio(s, SSL_get_rbio(s), SSL_get_rbio(s));
725 ret = 1;
726 err:
727 return (ret);
728}
729LSSL_ALIAS(SSL_set_wfd);
730
731int
732SSL_set_rfd(SSL *s, int fd)
733{
734 int ret = 0;
735 BIO *bio = NULL;
736
737 if ((s->wbio == NULL) || (BIO_method_type(s->wbio) != BIO_TYPE_SOCKET)
738 || ((int)BIO_get_fd(s->wbio, NULL) != fd)) {
739 bio = BIO_new(BIO_s_socket());
740
741 if (bio == NULL) {
742 SSLerror(s, ERR_R_BUF_LIB);
743 goto err;
744 }
745 BIO_set_fd(bio, fd, BIO_NOCLOSE);
746 SSL_set_bio(s, bio, SSL_get_wbio(s));
747 } else
748 SSL_set_bio(s, SSL_get_wbio(s), SSL_get_wbio(s));
749 ret = 1;
750 err:
751 return (ret);
752}
753LSSL_ALIAS(SSL_set_rfd);
754
755
756/* return length of latest Finished message we sent, copy to 'buf' */
757size_t
758SSL_get_finished(const SSL *s, void *buf, size_t count)
759{
760 size_t ret;
761
762 ret = s->s3->hs.finished_len;
763 if (count > ret)
764 count = ret;
765 memcpy(buf, s->s3->hs.finished, count);
766 return (ret);
767}
768LSSL_ALIAS(SSL_get_finished);
769
770/* return length of latest Finished message we expected, copy to 'buf' */
771size_t
772SSL_get_peer_finished(const SSL *s, void *buf, size_t count)
773{
774 size_t ret;
775
776 ret = s->s3->hs.peer_finished_len;
777 if (count > ret)
778 count = ret;
779 memcpy(buf, s->s3->hs.peer_finished, count);
780 return (ret);
781}
782LSSL_ALIAS(SSL_get_peer_finished);
783
784
785int
786SSL_get_verify_mode(const SSL *s)
787{
788 return (s->verify_mode);
789}
790LSSL_ALIAS(SSL_get_verify_mode);
791
792int
793SSL_get_verify_depth(const SSL *s)
794{
795 return (X509_VERIFY_PARAM_get_depth(s->param));
796}
797LSSL_ALIAS(SSL_get_verify_depth);
798
799int
800(*SSL_get_verify_callback(const SSL *s))(int, X509_STORE_CTX *)
801{
802 return (s->verify_callback);
803}
804LSSL_ALIAS(SSL_get_verify_callback);
805
806void
807SSL_CTX_set_keylog_callback(SSL_CTX *ctx, SSL_CTX_keylog_cb_func cb)
808{
809 ctx->keylog_callback = cb;
810}
811LSSL_ALIAS(SSL_CTX_set_keylog_callback);
812
813SSL_CTX_keylog_cb_func
814SSL_CTX_get_keylog_callback(const SSL_CTX *ctx)
815{
816 return (ctx->keylog_callback);
817}
818LSSL_ALIAS(SSL_CTX_get_keylog_callback);
819
820int
821SSL_set_num_tickets(SSL *s, size_t num_tickets)
822{
823 s->num_tickets = num_tickets;
824
825 return 1;
826}
827LSSL_ALIAS(SSL_set_num_tickets);
828
829size_t
830SSL_get_num_tickets(const SSL *s)
831{
832 return s->num_tickets;
833}
834LSSL_ALIAS(SSL_get_num_tickets);
835
836int
837SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets)
838{
839 ctx->num_tickets = num_tickets;
840
841 return 1;
842}
843LSSL_ALIAS(SSL_CTX_set_num_tickets);
844
845size_t
846SSL_CTX_get_num_tickets(const SSL_CTX *ctx)
847{
848 return ctx->num_tickets;
849}
850LSSL_ALIAS(SSL_CTX_get_num_tickets);
851
852int
853SSL_CTX_get_verify_mode(const SSL_CTX *ctx)
854{
855 return (ctx->verify_mode);
856}
857LSSL_ALIAS(SSL_CTX_get_verify_mode);
858
859int
860SSL_CTX_get_verify_depth(const SSL_CTX *ctx)
861{
862 return (X509_VERIFY_PARAM_get_depth(ctx->param));
863}
864LSSL_ALIAS(SSL_CTX_get_verify_depth);
865
866int
867(*SSL_CTX_get_verify_callback(const SSL_CTX *ctx))(int, X509_STORE_CTX *)
868{
869 return (ctx->default_verify_callback);
870}
871LSSL_ALIAS(SSL_CTX_get_verify_callback);
872
873void
874SSL_set_verify(SSL *s, int mode,
875 int (*callback)(int ok, X509_STORE_CTX *ctx))
876{
877 s->verify_mode = mode;
878 if (callback != NULL)
879 s->verify_callback = callback;
880}
881LSSL_ALIAS(SSL_set_verify);
882
883void
884SSL_set_verify_depth(SSL *s, int depth)
885{
886 X509_VERIFY_PARAM_set_depth(s->param, depth);
887}
888LSSL_ALIAS(SSL_set_verify_depth);
889
890void
891SSL_set_read_ahead(SSL *s, int yes)
892{
893 s->read_ahead = yes;
894}
895LSSL_ALIAS(SSL_set_read_ahead);
896
897int
898SSL_get_read_ahead(const SSL *s)
899{
900 return (s->read_ahead);
901}
902LSSL_ALIAS(SSL_get_read_ahead);
903
904int
905SSL_pending(const SSL *s)
906{
907 return (s->method->ssl_pending(s));
908}
909LSSL_ALIAS(SSL_pending);
910
911X509 *
912SSL_get_peer_certificate(const SSL *s)
913{
914 X509 *cert;
915
916 if (s == NULL || s->session == NULL)
917 return NULL;
918
919 if ((cert = s->session->peer_cert) == NULL)
920 return NULL;
921
922 X509_up_ref(cert);
923
924 return cert;
925}
926LSSL_ALIAS(SSL_get_peer_certificate);
927
928STACK_OF(X509) *
929SSL_get_peer_cert_chain(const SSL *s)
930{
931 if (s == NULL)
932 return NULL;
933
934 /*
935 * Achtung! Due to API inconsistency, a client includes the peer's leaf
936 * certificate in the peer certificate chain, while a server does not.
937 */
938 if (!s->server)
939 return s->s3->hs.peer_certs;
940
941 return s->s3->hs.peer_certs_no_leaf;
942}
943LSSL_ALIAS(SSL_get_peer_cert_chain);
944
945STACK_OF(X509) *
946SSL_get0_verified_chain(const SSL *s)
947{
948 if (s->s3 == NULL)
949 return NULL;
950 return s->s3->hs.verified_chain;
951}
952LSSL_ALIAS(SSL_get0_verified_chain);
953
954/*
955 * Now in theory, since the calling process own 't' it should be safe to
956 * modify. We need to be able to read f without being hassled
957 */
958int
959SSL_copy_session_id(SSL *t, const SSL *f)
960{
961 SSL_CERT *tmp;
962
963 /* Do we need to do SSL locking? */
964 if (!SSL_set_session(t, SSL_get_session(f)))
965 return 0;
966
967 /* What if we are set up for one protocol but want to talk another? */
968 if (t->method != f->method) {
969 t->method->ssl_free(t);
970 t->method = f->method;
971 if (!t->method->ssl_new(t))
972 return 0;
973 }
974
975 tmp = t->cert;
976 if (f->cert != NULL) {
977 CRYPTO_add(&f->cert->references, 1, CRYPTO_LOCK_SSL_CERT);
978 t->cert = f->cert;
979 } else
980 t->cert = NULL;
981 ssl_cert_free(tmp);
982
983 if (!SSL_set_session_id_context(t, f->sid_ctx, f->sid_ctx_length))
984 return 0;
985
986 return 1;
987}
988LSSL_ALIAS(SSL_copy_session_id);
989
990/* Fix this so it checks all the valid key/cert options */
991int
992SSL_CTX_check_private_key(const SSL_CTX *ctx)
993{
994 if ((ctx == NULL) || (ctx->cert == NULL) ||
995 (ctx->cert->key->x509 == NULL)) {
996 SSLerrorx(SSL_R_NO_CERTIFICATE_ASSIGNED);
997 return (0);
998 }
999 if (ctx->cert->key->privatekey == NULL) {
1000 SSLerrorx(SSL_R_NO_PRIVATE_KEY_ASSIGNED);
1001 return (0);
1002 }
1003 return (X509_check_private_key(ctx->cert->key->x509,
1004 ctx->cert->key->privatekey));
1005}
1006LSSL_ALIAS(SSL_CTX_check_private_key);
1007
1008/* Fix this function so that it takes an optional type parameter */
1009int
1010SSL_check_private_key(const SSL *ssl)
1011{
1012 if (ssl == NULL) {
1013 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
1014 return (0);
1015 }
1016 if (ssl->cert == NULL) {
1017 SSLerror(ssl, SSL_R_NO_CERTIFICATE_ASSIGNED);
1018 return (0);
1019 }
1020 if (ssl->cert->key->x509 == NULL) {
1021 SSLerror(ssl, SSL_R_NO_CERTIFICATE_ASSIGNED);
1022 return (0);
1023 }
1024 if (ssl->cert->key->privatekey == NULL) {
1025 SSLerror(ssl, SSL_R_NO_PRIVATE_KEY_ASSIGNED);
1026 return (0);
1027 }
1028 return (X509_check_private_key(ssl->cert->key->x509,
1029 ssl->cert->key->privatekey));
1030}
1031LSSL_ALIAS(SSL_check_private_key);
1032
1033int
1034SSL_accept(SSL *s)
1035{
1036 if (s->handshake_func == NULL)
1037 SSL_set_accept_state(s); /* Not properly initialized yet */
1038
1039 return (s->method->ssl_accept(s));
1040}
1041LSSL_ALIAS(SSL_accept);
1042
1043int
1044SSL_connect(SSL *s)
1045{
1046 if (s->handshake_func == NULL)
1047 SSL_set_connect_state(s); /* Not properly initialized yet */
1048
1049 return (s->method->ssl_connect(s));
1050}
1051LSSL_ALIAS(SSL_connect);
1052
1053int
1054SSL_is_dtls(const SSL *s)
1055{
1056 return s->method->dtls;
1057}
1058LSSL_ALIAS(SSL_is_dtls);
1059
1060int
1061SSL_is_server(const SSL *s)
1062{
1063 return s->server;
1064}
1065LSSL_ALIAS(SSL_is_server);
1066
1067static long
1068ssl_get_default_timeout(void)
1069{
1070 /*
1071 * 2 hours, the 24 hours mentioned in the TLSv1 spec
1072 * is way too long for http, the cache would over fill.
1073 */
1074 return (2 * 60 * 60);
1075}
1076
1077long
1078SSL_get_default_timeout(const SSL *s)
1079{
1080 return (ssl_get_default_timeout());
1081}
1082LSSL_ALIAS(SSL_get_default_timeout);
1083
1084int
1085SSL_read(SSL *s, void *buf, int num)
1086{
1087 if (num < 0) {
1088 SSLerror(s, SSL_R_BAD_LENGTH);
1089 return -1;
1090 }
1091
1092 if (SSL_is_quic(s)) {
1093 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1094 return (-1);
1095 }
1096
1097 if (s->handshake_func == NULL) {
1098 SSLerror(s, SSL_R_UNINITIALIZED);
1099 return (-1);
1100 }
1101
1102 if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
1103 s->rwstate = SSL_NOTHING;
1104 return (0);
1105 }
1106 return ssl3_read(s, buf, num);
1107}
1108LSSL_ALIAS(SSL_read);
1109
1110int
1111SSL_read_ex(SSL *s, void *buf, size_t num, size_t *bytes_read)
1112{
1113 int ret;
1114
1115 /* We simply don't bother supporting enormous reads */
1116 if (num > INT_MAX) {
1117 SSLerror(s, SSL_R_BAD_LENGTH);
1118 return 0;
1119 }
1120
1121 ret = SSL_read(s, buf, (int)num);
1122 if (ret < 0)
1123 ret = 0;
1124 *bytes_read = ret;
1125
1126 return ret > 0;
1127}
1128LSSL_ALIAS(SSL_read_ex);
1129
1130int
1131SSL_peek(SSL *s, void *buf, int num)
1132{
1133 if (num < 0) {
1134 SSLerror(s, SSL_R_BAD_LENGTH);
1135 return -1;
1136 }
1137
1138 if (SSL_is_quic(s)) {
1139 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1140 return (-1);
1141 }
1142
1143 if (s->handshake_func == NULL) {
1144 SSLerror(s, SSL_R_UNINITIALIZED);
1145 return (-1);
1146 }
1147
1148 if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
1149 return (0);
1150 }
1151 return ssl3_peek(s, buf, num);
1152}
1153LSSL_ALIAS(SSL_peek);
1154
1155int
1156SSL_peek_ex(SSL *s, void *buf, size_t num, size_t *bytes_peeked)
1157{
1158 int ret;
1159
1160 /* We simply don't bother supporting enormous peeks */
1161 if (num > INT_MAX) {
1162 SSLerror(s, SSL_R_BAD_LENGTH);
1163 return 0;
1164 }
1165
1166 ret = SSL_peek(s, buf, (int)num);
1167 if (ret < 0)
1168 ret = 0;
1169 *bytes_peeked = ret;
1170
1171 return ret > 0;
1172}
1173LSSL_ALIAS(SSL_peek_ex);
1174
1175int
1176SSL_write(SSL *s, const void *buf, int num)
1177{
1178 if (num < 0) {
1179 SSLerror(s, SSL_R_BAD_LENGTH);
1180 return -1;
1181 }
1182
1183 if (SSL_is_quic(s)) {
1184 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1185 return (-1);
1186 }
1187
1188 if (s->handshake_func == NULL) {
1189 SSLerror(s, SSL_R_UNINITIALIZED);
1190 return (-1);
1191 }
1192
1193 if (s->shutdown & SSL_SENT_SHUTDOWN) {
1194 s->rwstate = SSL_NOTHING;
1195 SSLerror(s, SSL_R_PROTOCOL_IS_SHUTDOWN);
1196 return (-1);
1197 }
1198 return ssl3_write(s, buf, num);
1199}
1200LSSL_ALIAS(SSL_write);
1201
1202int
1203SSL_write_ex(SSL *s, const void *buf, size_t num, size_t *bytes_written)
1204{
1205 int ret;
1206
1207 /* We simply don't bother supporting enormous writes */
1208 if (num > INT_MAX) {
1209 SSLerror(s, SSL_R_BAD_LENGTH);
1210 return 0;
1211 }
1212
1213 if (num == 0) {
1214 /* This API is special */
1215 bytes_written = 0;
1216 return 1;
1217 }
1218
1219 ret = SSL_write(s, buf, (int)num);
1220 if (ret < 0)
1221 ret = 0;
1222 *bytes_written = ret;
1223
1224 return ret > 0;
1225}
1226LSSL_ALIAS(SSL_write_ex);
1227
1228uint32_t
1229SSL_CTX_get_max_early_data(const SSL_CTX *ctx)
1230{
1231 return 0;
1232}
1233LSSL_ALIAS(SSL_CTX_get_max_early_data);
1234
1235int
1236SSL_CTX_set_max_early_data(SSL_CTX *ctx, uint32_t max_early_data)
1237{
1238 return 1;
1239}
1240LSSL_ALIAS(SSL_CTX_set_max_early_data);
1241
1242uint32_t
1243SSL_get_max_early_data(const SSL *s)
1244{
1245 return 0;
1246}
1247LSSL_ALIAS(SSL_get_max_early_data);
1248
1249int
1250SSL_set_max_early_data(SSL *s, uint32_t max_early_data)
1251{
1252 return 1;
1253}
1254LSSL_ALIAS(SSL_set_max_early_data);
1255
1256int
1257SSL_get_early_data_status(const SSL *s)
1258{
1259 return SSL_EARLY_DATA_REJECTED;
1260}
1261LSSL_ALIAS(SSL_get_early_data_status);
1262
1263int
1264SSL_read_early_data(SSL *s, void *buf, size_t num, size_t *readbytes)
1265{
1266 *readbytes = 0;
1267
1268 if (!s->server) {
1269 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1270 return SSL_READ_EARLY_DATA_ERROR;
1271 }
1272
1273 return SSL_READ_EARLY_DATA_FINISH;
1274}
1275LSSL_ALIAS(SSL_read_early_data);
1276
1277int
1278SSL_write_early_data(SSL *s, const void *buf, size_t num, size_t *written)
1279{
1280 *written = 0;
1281 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1282 return 0;
1283}
1284LSSL_ALIAS(SSL_write_early_data);
1285
1286int
1287SSL_shutdown(SSL *s)
1288{
1289 /*
1290 * Note that this function behaves differently from what one might
1291 * expect. Return values are 0 for no success (yet),
1292 * 1 for success; but calling it once is usually not enough,
1293 * even if blocking I/O is used (see ssl3_shutdown).
1294 */
1295
1296 if (s->handshake_func == NULL) {
1297 SSLerror(s, SSL_R_UNINITIALIZED);
1298 return (-1);
1299 }
1300
1301 if (s != NULL && !SSL_in_init(s))
1302 return (s->method->ssl_shutdown(s));
1303
1304 return (1);
1305}
1306LSSL_ALIAS(SSL_shutdown);
1307
1308int
1309SSL_renegotiate(SSL *s)
1310{
1311 if ((s->options & SSL_OP_NO_RENEGOTIATION) != 0) {
1312 SSLerror(s, SSL_R_NO_RENEGOTIATION);
1313 return 0;
1314 }
1315
1316 if (s->renegotiate == 0)
1317 s->renegotiate = 1;
1318
1319 s->new_session = 1;
1320
1321 return (s->method->ssl_renegotiate(s));
1322}
1323LSSL_ALIAS(SSL_renegotiate);
1324
1325int
1326SSL_renegotiate_abbreviated(SSL *s)
1327{
1328 if ((s->options & SSL_OP_NO_RENEGOTIATION) != 0) {
1329 SSLerror(s, SSL_R_NO_RENEGOTIATION);
1330 return 0;
1331 }
1332
1333 if (s->renegotiate == 0)
1334 s->renegotiate = 1;
1335
1336 s->new_session = 0;
1337
1338 return (s->method->ssl_renegotiate(s));
1339}
1340LSSL_ALIAS(SSL_renegotiate_abbreviated);
1341
1342int
1343SSL_renegotiate_pending(SSL *s)
1344{
1345 /*
1346 * Becomes true when negotiation is requested;
1347 * false again once a handshake has finished.
1348 */
1349 return (s->renegotiate != 0);
1350}
1351LSSL_ALIAS(SSL_renegotiate_pending);
1352
1353long
1354SSL_ctrl(SSL *s, int cmd, long larg, void *parg)
1355{
1356 long l;
1357
1358 switch (cmd) {
1359 case SSL_CTRL_GET_READ_AHEAD:
1360 return (s->read_ahead);
1361 case SSL_CTRL_SET_READ_AHEAD:
1362 l = s->read_ahead;
1363 s->read_ahead = larg;
1364 return (l);
1365
1366 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
1367 s->msg_callback_arg = parg;
1368 return (1);
1369
1370 case SSL_CTRL_OPTIONS:
1371 return (s->options|=larg);
1372 case SSL_CTRL_CLEAR_OPTIONS:
1373 return (s->options&=~larg);
1374 case SSL_CTRL_MODE:
1375 return (s->mode|=larg);
1376 case SSL_CTRL_CLEAR_MODE:
1377 return (s->mode &=~larg);
1378 case SSL_CTRL_GET_MAX_CERT_LIST:
1379 return (s->max_cert_list);
1380 case SSL_CTRL_SET_MAX_CERT_LIST:
1381 l = s->max_cert_list;
1382 s->max_cert_list = larg;
1383 return (l);
1384 case SSL_CTRL_SET_MTU:
1385 if (larg < (long)dtls1_min_mtu())
1386 return (0);
1387 if (SSL_is_dtls(s)) {
1388 s->d1->mtu = larg;
1389 return (larg);
1390 }
1391 return (0);
1392 case SSL_CTRL_SET_MAX_SEND_FRAGMENT:
1393 if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH)
1394 return (0);
1395 s->max_send_fragment = larg;
1396 return (1);
1397 case SSL_CTRL_GET_RI_SUPPORT:
1398 if (s->s3)
1399 return (s->s3->send_connection_binding);
1400 else return (0);
1401 default:
1402 if (SSL_is_dtls(s))
1403 return dtls1_ctrl(s, cmd, larg, parg);
1404 return ssl3_ctrl(s, cmd, larg, parg);
1405 }
1406}
1407LSSL_ALIAS(SSL_ctrl);
1408
1409long
1410SSL_callback_ctrl(SSL *s, int cmd, void (*fp)(void))
1411{
1412 switch (cmd) {
1413 case SSL_CTRL_SET_MSG_CALLBACK:
1414 s->msg_callback = (ssl_msg_callback_fn *)(fp);
1415 return (1);
1416
1417 default:
1418 return (ssl3_callback_ctrl(s, cmd, fp));
1419 }
1420}
1421LSSL_ALIAS(SSL_callback_ctrl);
1422
1423struct lhash_st_SSL_SESSION *
1424SSL_CTX_sessions(SSL_CTX *ctx)
1425{
1426 return (ctx->sessions);
1427}
1428LSSL_ALIAS(SSL_CTX_sessions);
1429
1430long
1431SSL_CTX_ctrl(SSL_CTX *ctx, int cmd, long larg, void *parg)
1432{
1433 long l;
1434
1435 switch (cmd) {
1436 case SSL_CTRL_GET_READ_AHEAD:
1437 return (ctx->read_ahead);
1438 case SSL_CTRL_SET_READ_AHEAD:
1439 l = ctx->read_ahead;
1440 ctx->read_ahead = larg;
1441 return (l);
1442
1443 case SSL_CTRL_SET_MSG_CALLBACK_ARG:
1444 ctx->msg_callback_arg = parg;
1445 return (1);
1446
1447 case SSL_CTRL_GET_MAX_CERT_LIST:
1448 return (ctx->max_cert_list);
1449 case SSL_CTRL_SET_MAX_CERT_LIST:
1450 l = ctx->max_cert_list;
1451 ctx->max_cert_list = larg;
1452 return (l);
1453
1454 case SSL_CTRL_SET_SESS_CACHE_SIZE:
1455 l = ctx->session_cache_size;
1456 ctx->session_cache_size = larg;
1457 return (l);
1458 case SSL_CTRL_GET_SESS_CACHE_SIZE:
1459 return (ctx->session_cache_size);
1460 case SSL_CTRL_SET_SESS_CACHE_MODE:
1461 l = ctx->session_cache_mode;
1462 ctx->session_cache_mode = larg;
1463 return (l);
1464 case SSL_CTRL_GET_SESS_CACHE_MODE:
1465 return (ctx->session_cache_mode);
1466
1467 case SSL_CTRL_SESS_NUMBER:
1468 return (lh_SSL_SESSION_num_items(ctx->sessions));
1469 case SSL_CTRL_SESS_CONNECT:
1470 return (ctx->stats.sess_connect);
1471 case SSL_CTRL_SESS_CONNECT_GOOD:
1472 return (ctx->stats.sess_connect_good);
1473 case SSL_CTRL_SESS_CONNECT_RENEGOTIATE:
1474 return (ctx->stats.sess_connect_renegotiate);
1475 case SSL_CTRL_SESS_ACCEPT:
1476 return (ctx->stats.sess_accept);
1477 case SSL_CTRL_SESS_ACCEPT_GOOD:
1478 return (ctx->stats.sess_accept_good);
1479 case SSL_CTRL_SESS_ACCEPT_RENEGOTIATE:
1480 return (ctx->stats.sess_accept_renegotiate);
1481 case SSL_CTRL_SESS_HIT:
1482 return (ctx->stats.sess_hit);
1483 case SSL_CTRL_SESS_CB_HIT:
1484 return (ctx->stats.sess_cb_hit);
1485 case SSL_CTRL_SESS_MISSES:
1486 return (ctx->stats.sess_miss);
1487 case SSL_CTRL_SESS_TIMEOUTS:
1488 return (ctx->stats.sess_timeout);
1489 case SSL_CTRL_SESS_CACHE_FULL:
1490 return (ctx->stats.sess_cache_full);
1491 case SSL_CTRL_OPTIONS:
1492 return (ctx->options|=larg);
1493 case SSL_CTRL_CLEAR_OPTIONS:
1494 return (ctx->options&=~larg);
1495 case SSL_CTRL_MODE:
1496 return (ctx->mode|=larg);
1497 case SSL_CTRL_CLEAR_MODE:
1498 return (ctx->mode&=~larg);
1499 case SSL_CTRL_SET_MAX_SEND_FRAGMENT:
1500 if (larg < 512 || larg > SSL3_RT_MAX_PLAIN_LENGTH)
1501 return (0);
1502 ctx->max_send_fragment = larg;
1503 return (1);
1504 default:
1505 return (ssl3_ctx_ctrl(ctx, cmd, larg, parg));
1506 }
1507}
1508LSSL_ALIAS(SSL_CTX_ctrl);
1509
1510long
1511SSL_CTX_callback_ctrl(SSL_CTX *ctx, int cmd, void (*fp)(void))
1512{
1513 switch (cmd) {
1514 case SSL_CTRL_SET_MSG_CALLBACK:
1515 ctx->msg_callback = (ssl_msg_callback_fn *)fp;
1516 return (1);
1517
1518 default:
1519 return (ssl3_ctx_callback_ctrl(ctx, cmd, fp));
1520 }
1521}
1522LSSL_ALIAS(SSL_CTX_callback_ctrl);
1523
1524STACK_OF(SSL_CIPHER) *
1525SSL_get_ciphers(const SSL *s)
1526{
1527 if (s == NULL)
1528 return (NULL);
1529 if (s->cipher_list != NULL)
1530 return (s->cipher_list);
1531
1532 return (s->ctx->cipher_list);
1533}
1534LSSL_ALIAS(SSL_get_ciphers);
1535
1536STACK_OF(SSL_CIPHER) *
1537SSL_get_client_ciphers(const SSL *s)
1538{
1539 if (s == NULL || !s->server)
1540 return NULL;
1541 return s->s3->hs.client_ciphers;
1542}
1543LSSL_ALIAS(SSL_get_client_ciphers);
1544
1545STACK_OF(SSL_CIPHER) *
1546SSL_get1_supported_ciphers(SSL *s)
1547{
1548 STACK_OF(SSL_CIPHER) *supported_ciphers = NULL, *ciphers;
1549 SSL_CIPHER *cipher;
1550 uint16_t min_vers, max_vers;
1551 int i;
1552
1553 if (s == NULL)
1554 return NULL;
1555 if (!ssl_supported_tls_version_range(s, &min_vers, &max_vers))
1556 return NULL;
1557 if ((ciphers = SSL_get_ciphers(s)) == NULL)
1558 return NULL;
1559 if ((supported_ciphers = sk_SSL_CIPHER_new_null()) == NULL)
1560 return NULL;
1561
1562 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
1563 if ((cipher = sk_SSL_CIPHER_value(ciphers, i)) == NULL)
1564 goto err;
1565 if (!ssl_cipher_allowed_in_tls_version_range(cipher, min_vers,
1566 max_vers))
1567 continue;
1568 if (!ssl_security_supported_cipher(s, cipher))
1569 continue;
1570 if (!sk_SSL_CIPHER_push(supported_ciphers, cipher))
1571 goto err;
1572 }
1573
1574 if (sk_SSL_CIPHER_num(supported_ciphers) > 0)
1575 return supported_ciphers;
1576
1577 err:
1578 sk_SSL_CIPHER_free(supported_ciphers);
1579 return NULL;
1580}
1581LSSL_ALIAS(SSL_get1_supported_ciphers);
1582
1583/* See if we have any ECC cipher suites. */
1584int
1585ssl_has_ecc_ciphers(SSL *s)
1586{
1587 STACK_OF(SSL_CIPHER) *ciphers;
1588 unsigned long alg_k, alg_a;
1589 SSL_CIPHER *cipher;
1590 int i;
1591
1592 if ((ciphers = SSL_get_ciphers(s)) == NULL)
1593 return 0;
1594
1595 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
1596 cipher = sk_SSL_CIPHER_value(ciphers, i);
1597
1598 alg_k = cipher->algorithm_mkey;
1599 alg_a = cipher->algorithm_auth;
1600
1601 if ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA))
1602 return 1;
1603 }
1604
1605 return 0;
1606}
1607
1608/* The old interface to get the same thing as SSL_get_ciphers(). */
1609const char *
1610SSL_get_cipher_list(const SSL *s, int n)
1611{
1612 STACK_OF(SSL_CIPHER) *ciphers;
1613 const SSL_CIPHER *cipher;
1614
1615 if ((ciphers = SSL_get_ciphers(s)) == NULL)
1616 return (NULL);
1617 if ((cipher = sk_SSL_CIPHER_value(ciphers, n)) == NULL)
1618 return (NULL);
1619
1620 return (cipher->name);
1621}
1622LSSL_ALIAS(SSL_get_cipher_list);
1623
1624STACK_OF(SSL_CIPHER) *
1625SSL_CTX_get_ciphers(const SSL_CTX *ctx)
1626{
1627 if (ctx == NULL)
1628 return NULL;
1629 return ctx->cipher_list;
1630}
1631LSSL_ALIAS(SSL_CTX_get_ciphers);
1632
1633/* Specify the ciphers to be used by default by the SSL_CTX. */
1634int
1635SSL_CTX_set_cipher_list(SSL_CTX *ctx, const char *str)
1636{
1637 STACK_OF(SSL_CIPHER) *ciphers;
1638
1639 /*
1640 * ssl_create_cipher_list may return an empty stack if it was unable to
1641 * find a cipher matching the given rule string (for example if the
1642 * rule string specifies a cipher which has been disabled). This is not
1643 * an error as far as ssl_create_cipher_list is concerned, and hence
1644 * ctx->cipher_list has been updated.
1645 */
1646 ciphers = ssl_create_cipher_list(ctx->method, &ctx->cipher_list,
1647 ctx->cipher_list_tls13, str, ctx->cert);
1648 if (ciphers == NULL) {
1649 return (0);
1650 } else if (sk_SSL_CIPHER_num(ciphers) == 0) {
1651 SSLerrorx(SSL_R_NO_CIPHER_MATCH);
1652 return (0);
1653 }
1654 return (1);
1655}
1656LSSL_ALIAS(SSL_CTX_set_cipher_list);
1657
1658int
1659SSL_CTX_set_ciphersuites(SSL_CTX *ctx, const char *str)
1660{
1661 if (!ssl_parse_ciphersuites(&ctx->cipher_list_tls13, str)) {
1662 SSLerrorx(SSL_R_NO_CIPHER_MATCH);
1663 return 0;
1664 }
1665 if (!ssl_merge_cipherlists(ctx->cipher_list,
1666 ctx->cipher_list_tls13, &ctx->cipher_list))
1667 return 0;
1668
1669 return 1;
1670}
1671LSSL_ALIAS(SSL_CTX_set_ciphersuites);
1672
1673/* Specify the ciphers to be used by the SSL. */
1674int
1675SSL_set_cipher_list(SSL *s, const char *str)
1676{
1677 STACK_OF(SSL_CIPHER) *ciphers, *ciphers_tls13;
1678
1679 if ((ciphers_tls13 = s->cipher_list_tls13) == NULL)
1680 ciphers_tls13 = s->ctx->cipher_list_tls13;
1681
1682 /* See comment in SSL_CTX_set_cipher_list. */
1683 ciphers = ssl_create_cipher_list(s->ctx->method, &s->cipher_list,
1684 ciphers_tls13, str, s->cert);
1685 if (ciphers == NULL) {
1686 return (0);
1687 } else if (sk_SSL_CIPHER_num(ciphers) == 0) {
1688 SSLerror(s, SSL_R_NO_CIPHER_MATCH);
1689 return (0);
1690 }
1691 return (1);
1692}
1693LSSL_ALIAS(SSL_set_cipher_list);
1694
1695int
1696SSL_set_ciphersuites(SSL *s, const char *str)
1697{
1698 STACK_OF(SSL_CIPHER) *ciphers;
1699
1700 if ((ciphers = s->cipher_list) == NULL)
1701 ciphers = s->ctx->cipher_list;
1702
1703 if (!ssl_parse_ciphersuites(&s->cipher_list_tls13, str)) {
1704 SSLerrorx(SSL_R_NO_CIPHER_MATCH);
1705 return (0);
1706 }
1707 if (!ssl_merge_cipherlists(ciphers, s->cipher_list_tls13,
1708 &s->cipher_list))
1709 return 0;
1710
1711 return 1;
1712}
1713LSSL_ALIAS(SSL_set_ciphersuites);
1714
1715char *
1716SSL_get_shared_ciphers(const SSL *s, char *buf, int len)
1717{
1718 STACK_OF(SSL_CIPHER) *client_ciphers, *server_ciphers;
1719 const SSL_CIPHER *cipher;
1720 size_t curlen = 0;
1721 char *end;
1722 int i;
1723
1724 if (!s->server || len < 2)
1725 return NULL;
1726
1727 if ((client_ciphers = s->s3->hs.client_ciphers) == NULL)
1728 return NULL;
1729 if ((server_ciphers = SSL_get_ciphers(s)) == NULL)
1730 return NULL;
1731 if (sk_SSL_CIPHER_num(client_ciphers) == 0 ||
1732 sk_SSL_CIPHER_num(server_ciphers) == 0)
1733 return NULL;
1734
1735 buf[0] = '\0';
1736 for (i = 0; i < sk_SSL_CIPHER_num(client_ciphers); i++) {
1737 cipher = sk_SSL_CIPHER_value(client_ciphers, i);
1738
1739 if (sk_SSL_CIPHER_find(server_ciphers, cipher) < 0)
1740 continue;
1741
1742 end = buf + curlen;
1743 if (strlcat(buf, cipher->name, len) >= len ||
1744 (curlen = strlcat(buf, ":", len)) >= len) {
1745 /* remove truncated cipher from list */
1746 *end = '\0';
1747 break;
1748 }
1749 }
1750 /* remove trailing colon */
1751 if ((end = strrchr(buf, ':')) != NULL)
1752 *end = '\0';
1753 return buf;
1754}
1755LSSL_ALIAS(SSL_get_shared_ciphers);
1756
1757/*
1758 * Return a servername extension value if provided in Client Hello, or NULL.
1759 * So far, only host_name types are defined (RFC 3546).
1760 */
1761const char *
1762SSL_get_servername(const SSL *s, const int type)
1763{
1764 if (type != TLSEXT_NAMETYPE_host_name)
1765 return (NULL);
1766
1767 return (s->session && !s->tlsext_hostname ?
1768 s->session->tlsext_hostname :
1769 s->tlsext_hostname);
1770}
1771LSSL_ALIAS(SSL_get_servername);
1772
1773int
1774SSL_get_servername_type(const SSL *s)
1775{
1776 if (s->session &&
1777 (!s->tlsext_hostname ?
1778 s->session->tlsext_hostname : s->tlsext_hostname))
1779 return (TLSEXT_NAMETYPE_host_name);
1780 return (-1);
1781}
1782LSSL_ALIAS(SSL_get_servername_type);
1783
1784/*
1785 * SSL_select_next_proto implements standard protocol selection. It is
1786 * expected that this function is called from the callback set by
1787 * SSL_CTX_set_alpn_select_cb.
1788 *
1789 * The protocol data is assumed to be a vector of 8-bit, length prefixed byte
1790 * strings. The length byte itself is not included in the length. A byte
1791 * string of length 0 is invalid. No byte string may be truncated.
1792 *
1793 * It returns either:
1794 * OPENSSL_NPN_NEGOTIATED if a common protocol was found, or
1795 * OPENSSL_NPN_NO_OVERLAP if the fallback case was reached.
1796 *
1797 * XXX - the out argument points into server_list or client_list and should
1798 * therefore really be const. We can't fix that without breaking the callers.
1799 */
1800int
1801SSL_select_next_proto(unsigned char **out, unsigned char *outlen,
1802 const unsigned char *peer_list, unsigned int peer_list_len,
1803 const unsigned char *supported_list, unsigned int supported_list_len)
1804{
1805 CBS peer, peer_proto, supported, supported_proto;
1806
1807 *out = NULL;
1808 *outlen = 0;
1809
1810 /* First check that the supported list is well-formed. */
1811 CBS_init(&supported, supported_list, supported_list_len);
1812 if (!tlsext_alpn_check_format(&supported))
1813 goto err;
1814
1815 /*
1816 * Use first supported protocol as fallback. This is one way of doing
1817 * NPN's "opportunistic" protocol selection (see security considerations
1818 * in draft-agl-tls-nextprotoneg-04), and it is the documented behavior
1819 * of this API. For ALPN it's the callback's responsibility to fail on
1820 * OPENSSL_NPN_NO_OVERLAP.
1821 */
1822
1823 if (!CBS_get_u8_length_prefixed(&supported, &supported_proto))
1824 goto err;
1825
1826 *out = (unsigned char *)CBS_data(&supported_proto);
1827 *outlen = CBS_len(&supported_proto);
1828
1829 /* Now check that the peer list is well-formed. */
1830 CBS_init(&peer, peer_list, peer_list_len);
1831 if (!tlsext_alpn_check_format(&peer))
1832 goto err;
1833
1834 /*
1835 * Walk the peer list and select the first protocol that appears in
1836 * the supported list. Thus we honor peer preference rather than local
1837 * preference contrary to a SHOULD in RFC 7301, section 3.2.
1838 */
1839 while (CBS_len(&peer) > 0) {
1840 if (!CBS_get_u8_length_prefixed(&peer, &peer_proto))
1841 goto err;
1842
1843 CBS_init(&supported, supported_list, supported_list_len);
1844
1845 while (CBS_len(&supported) > 0) {
1846 if (!CBS_get_u8_length_prefixed(&supported,
1847 &supported_proto))
1848 goto err;
1849
1850 if (CBS_mem_equal(&supported_proto,
1851 CBS_data(&peer_proto), CBS_len(&peer_proto))) {
1852 *out = (unsigned char *)CBS_data(&peer_proto);
1853 *outlen = CBS_len(&peer_proto);
1854
1855 return OPENSSL_NPN_NEGOTIATED;
1856 }
1857 }
1858 }
1859
1860 err:
1861 return OPENSSL_NPN_NO_OVERLAP;
1862}
1863LSSL_ALIAS(SSL_select_next_proto);
1864
1865/* SSL_get0_next_proto_negotiated is deprecated. */
1866void
1867SSL_get0_next_proto_negotiated(const SSL *s, const unsigned char **data,
1868 unsigned int *len)
1869{
1870 *data = NULL;
1871 *len = 0;
1872}
1873LSSL_ALIAS(SSL_get0_next_proto_negotiated);
1874
1875/* SSL_CTX_set_next_protos_advertised_cb is deprecated. */
1876void
1877SSL_CTX_set_next_protos_advertised_cb(SSL_CTX *ctx, int (*cb) (SSL *ssl,
1878 const unsigned char **out, unsigned int *outlen, void *arg), void *arg)
1879{
1880}
1881LSSL_ALIAS(SSL_CTX_set_next_protos_advertised_cb);
1882
1883/* SSL_CTX_set_next_proto_select_cb is deprecated. */
1884void
1885SSL_CTX_set_next_proto_select_cb(SSL_CTX *ctx, int (*cb) (SSL *s,
1886 unsigned char **out, unsigned char *outlen, const unsigned char *in,
1887 unsigned int inlen, void *arg), void *arg)
1888{
1889}
1890LSSL_ALIAS(SSL_CTX_set_next_proto_select_cb);
1891
1892/*
1893 * SSL_CTX_set_alpn_protos sets the ALPN protocol list to the specified
1894 * protocols, which must be in wire-format (i.e. a series of non-empty,
1895 * 8-bit length-prefixed strings). Returns 0 on success.
1896 */
1897int
1898SSL_CTX_set_alpn_protos(SSL_CTX *ctx, const unsigned char *protos,
1899 unsigned int protos_len)
1900{
1901 CBS cbs;
1902 int failed = 1;
1903
1904 if (protos == NULL)
1905 protos_len = 0;
1906
1907 CBS_init(&cbs, protos, protos_len);
1908
1909 if (protos_len > 0) {
1910 if (!tlsext_alpn_check_format(&cbs))
1911 goto err;
1912 }
1913
1914 if (!CBS_stow(&cbs, &ctx->alpn_client_proto_list,
1915 &ctx->alpn_client_proto_list_len))
1916 goto err;
1917
1918 failed = 0;
1919
1920 err:
1921 /* NOTE: Return values are the reverse of what you expect. */
1922 return failed;
1923}
1924LSSL_ALIAS(SSL_CTX_set_alpn_protos);
1925
1926/*
1927 * SSL_set_alpn_protos sets the ALPN protocol list to the specified
1928 * protocols, which must be in wire-format (i.e. a series of non-empty,
1929 * 8-bit length-prefixed strings). Returns 0 on success.
1930 */
1931int
1932SSL_set_alpn_protos(SSL *ssl, const unsigned char *protos,
1933 unsigned int protos_len)
1934{
1935 CBS cbs;
1936 int failed = 1;
1937
1938 if (protos == NULL)
1939 protos_len = 0;
1940
1941 CBS_init(&cbs, protos, protos_len);
1942
1943 if (protos_len > 0) {
1944 if (!tlsext_alpn_check_format(&cbs))
1945 goto err;
1946 }
1947
1948 if (!CBS_stow(&cbs, &ssl->alpn_client_proto_list,
1949 &ssl->alpn_client_proto_list_len))
1950 goto err;
1951
1952 failed = 0;
1953
1954 err:
1955 /* NOTE: Return values are the reverse of what you expect. */
1956 return failed;
1957}
1958LSSL_ALIAS(SSL_set_alpn_protos);
1959
1960/*
1961 * SSL_CTX_set_alpn_select_cb sets a callback function that is called during
1962 * ClientHello processing in order to select an ALPN protocol from the
1963 * client's list of offered protocols.
1964 */
1965void
1966SSL_CTX_set_alpn_select_cb(SSL_CTX* ctx,
1967 int (*cb) (SSL *ssl, const unsigned char **out, unsigned char *outlen,
1968 const unsigned char *in, unsigned int inlen, void *arg), void *arg)
1969{
1970 ctx->alpn_select_cb = cb;
1971 ctx->alpn_select_cb_arg = arg;
1972}
1973LSSL_ALIAS(SSL_CTX_set_alpn_select_cb);
1974
1975/*
1976 * SSL_get0_alpn_selected gets the selected ALPN protocol (if any). On return
1977 * it sets data to point to len bytes of protocol name (not including the
1978 * leading length-prefix byte). If the server didn't respond with* a negotiated
1979 * protocol then len will be zero.
1980 */
1981void
1982SSL_get0_alpn_selected(const SSL *ssl, const unsigned char **data,
1983 unsigned int *len)
1984{
1985 *data = ssl->s3->alpn_selected;
1986 *len = ssl->s3->alpn_selected_len;
1987}
1988LSSL_ALIAS(SSL_get0_alpn_selected);
1989
1990void
1991SSL_set_psk_use_session_callback(SSL *s, SSL_psk_use_session_cb_func cb)
1992{
1993 return;
1994}
1995LSSL_ALIAS(SSL_set_psk_use_session_callback);
1996
1997int
1998SSL_export_keying_material(SSL *s, unsigned char *out, size_t out_len,
1999 const char *label, size_t label_len, const unsigned char *context,
2000 size_t context_len, int use_context)
2001{
2002 if (s->tls13 != NULL && s->version == TLS1_3_VERSION) {
2003 if (!use_context) {
2004 context = NULL;
2005 context_len = 0;
2006 }
2007 return tls13_exporter(s->tls13, label, label_len, context,
2008 context_len, out, out_len);
2009 }
2010
2011 return tls12_exporter(s, label, label_len, context, context_len,
2012 use_context, out, out_len);
2013}
2014LSSL_ALIAS(SSL_export_keying_material);
2015
2016static unsigned long
2017ssl_session_hash(const SSL_SESSION *a)
2018{
2019 unsigned long l;
2020
2021 l = (unsigned long)
2022 ((unsigned int) a->session_id[0] )|
2023 ((unsigned int) a->session_id[1]<< 8L)|
2024 ((unsigned long)a->session_id[2]<<16L)|
2025 ((unsigned long)a->session_id[3]<<24L);
2026 return (l);
2027}
2028
2029/*
2030 * NB: If this function (or indeed the hash function which uses a sort of
2031 * coarser function than this one) is changed, ensure
2032 * SSL_CTX_has_matching_session_id() is checked accordingly. It relies on being
2033 * able to construct an SSL_SESSION that will collide with any existing session
2034 * with a matching session ID.
2035 */
2036static int
2037ssl_session_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
2038{
2039 if (a->ssl_version != b->ssl_version)
2040 return (1);
2041 if (a->session_id_length != b->session_id_length)
2042 return (1);
2043 if (timingsafe_memcmp(a->session_id, b->session_id, a->session_id_length) != 0)
2044 return (1);
2045 return (0);
2046}
2047
2048/*
2049 * These wrapper functions should remain rather than redeclaring
2050 * SSL_SESSION_hash and SSL_SESSION_cmp for void* types and casting each
2051 * variable. The reason is that the functions aren't static, they're exposed via
2052 * ssl.h.
2053 */
2054static unsigned long
2055ssl_session_LHASH_HASH(const void *arg)
2056{
2057 const SSL_SESSION *a = arg;
2058
2059 return ssl_session_hash(a);
2060}
2061
2062static int
2063ssl_session_LHASH_COMP(const void *arg1, const void *arg2)
2064{
2065 const SSL_SESSION *a = arg1;
2066 const SSL_SESSION *b = arg2;
2067
2068 return ssl_session_cmp(a, b);
2069}
2070
2071SSL_CTX *
2072SSL_CTX_new(const SSL_METHOD *meth)
2073{
2074 SSL_CTX *ret;
2075
2076 if (!OPENSSL_init_ssl(0, NULL)) {
2077 SSLerrorx(SSL_R_LIBRARY_BUG);
2078 return (NULL);
2079 }
2080
2081 if (meth == NULL) {
2082 SSLerrorx(SSL_R_NULL_SSL_METHOD_PASSED);
2083 return (NULL);
2084 }
2085
2086 if ((ret = calloc(1, sizeof(*ret))) == NULL) {
2087 SSLerrorx(ERR_R_MALLOC_FAILURE);
2088 return (NULL);
2089 }
2090
2091 if (SSL_get_ex_data_X509_STORE_CTX_idx() < 0) {
2092 SSLerrorx(SSL_R_X509_VERIFICATION_SETUP_PROBLEMS);
2093 goto err;
2094 }
2095
2096 ret->method = meth;
2097 ret->min_tls_version = meth->min_tls_version;
2098 ret->max_tls_version = meth->max_tls_version;
2099 ret->min_proto_version = 0;
2100 ret->max_proto_version = 0;
2101 ret->mode = SSL_MODE_AUTO_RETRY;
2102
2103 ret->cert_store = NULL;
2104 ret->session_cache_mode = SSL_SESS_CACHE_SERVER;
2105 ret->session_cache_size = SSL_SESSION_CACHE_MAX_SIZE_DEFAULT;
2106 ret->session_cache_head = NULL;
2107 ret->session_cache_tail = NULL;
2108
2109 /* We take the system default */
2110 ret->session_timeout = ssl_get_default_timeout();
2111
2112 ret->new_session_cb = NULL;
2113 ret->remove_session_cb = NULL;
2114 ret->get_session_cb = NULL;
2115 ret->generate_session_id = NULL;
2116
2117 memset((char *)&ret->stats, 0, sizeof(ret->stats));
2118
2119 ret->references = 1;
2120 ret->quiet_shutdown = 0;
2121
2122 ret->info_callback = NULL;
2123
2124 ret->app_verify_callback = NULL;
2125 ret->app_verify_arg = NULL;
2126
2127 ret->max_cert_list = SSL_MAX_CERT_LIST_DEFAULT;
2128 ret->read_ahead = 0;
2129 ret->msg_callback = NULL;
2130 ret->msg_callback_arg = NULL;
2131 ret->verify_mode = SSL_VERIFY_NONE;
2132 ret->sid_ctx_length = 0;
2133 ret->default_verify_callback = NULL;
2134
2135 if ((ret->cert = ssl_cert_new()) == NULL)
2136 goto err;
2137
2138 ret->default_passwd_callback = NULL;
2139 ret->default_passwd_callback_userdata = NULL;
2140 ret->client_cert_cb = NULL;
2141 ret->app_gen_cookie_cb = NULL;
2142 ret->app_verify_cookie_cb = NULL;
2143
2144 ret->sessions = lh_SSL_SESSION_new();
2145 if (ret->sessions == NULL)
2146 goto err;
2147 ret->cert_store = X509_STORE_new();
2148 if (ret->cert_store == NULL)
2149 goto err;
2150
2151 ssl_create_cipher_list(ret->method, &ret->cipher_list,
2152 NULL, SSL_DEFAULT_CIPHER_LIST, ret->cert);
2153 if (ret->cipher_list == NULL ||
2154 sk_SSL_CIPHER_num(ret->cipher_list) <= 0) {
2155 SSLerrorx(SSL_R_LIBRARY_HAS_NO_CIPHERS);
2156 goto err2;
2157 }
2158
2159 ret->param = X509_VERIFY_PARAM_new();
2160 if (!ret->param)
2161 goto err;
2162
2163 if ((ret->client_CA = sk_X509_NAME_new_null()) == NULL)
2164 goto err;
2165
2166 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ret, &ret->ex_data);
2167
2168 ret->extra_certs = NULL;
2169
2170 ret->max_send_fragment = SSL3_RT_MAX_PLAIN_LENGTH;
2171
2172 ret->tlsext_servername_callback = 0;
2173 ret->tlsext_servername_arg = NULL;
2174
2175 /* Setup RFC4507 ticket keys */
2176 arc4random_buf(ret->tlsext_tick_key_name, 16);
2177 arc4random_buf(ret->tlsext_tick_hmac_key, 16);
2178 arc4random_buf(ret->tlsext_tick_aes_key, 16);
2179
2180 ret->tlsext_status_cb = 0;
2181 ret->tlsext_status_arg = NULL;
2182
2183 /*
2184 * Default is to connect to non-RI servers. When RI is more widely
2185 * deployed might change this.
2186 */
2187 ret->options |= SSL_OP_LEGACY_SERVER_CONNECT;
2188
2189 return (ret);
2190 err:
2191 SSLerrorx(ERR_R_MALLOC_FAILURE);
2192 err2:
2193 SSL_CTX_free(ret);
2194 return (NULL);
2195}
2196LSSL_ALIAS(SSL_CTX_new);
2197
2198void
2199SSL_CTX_free(SSL_CTX *ctx)
2200{
2201 int i;
2202
2203 if (ctx == NULL)
2204 return;
2205
2206 i = CRYPTO_add(&ctx->references, -1, CRYPTO_LOCK_SSL_CTX);
2207 if (i > 0)
2208 return;
2209
2210 X509_VERIFY_PARAM_free(ctx->param);
2211
2212 /*
2213 * Free internal session cache. However: the remove_cb() may reference
2214 * the ex_data of SSL_CTX, thus the ex_data store can only be removed
2215 * after the sessions were flushed.
2216 * As the ex_data handling routines might also touch the session cache,
2217 * the most secure solution seems to be: empty (flush) the cache, then
2218 * free ex_data, then finally free the cache.
2219 * (See ticket [openssl.org #212].)
2220 */
2221 if (ctx->sessions != NULL)
2222 SSL_CTX_flush_sessions(ctx, 0);
2223
2224 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_CTX, ctx, &ctx->ex_data);
2225
2226 lh_SSL_SESSION_free(ctx->sessions);
2227
2228 X509_STORE_free(ctx->cert_store);
2229 sk_SSL_CIPHER_free(ctx->cipher_list);
2230 sk_SSL_CIPHER_free(ctx->cipher_list_tls13);
2231 ssl_cert_free(ctx->cert);
2232 sk_X509_NAME_pop_free(ctx->client_CA, X509_NAME_free);
2233 sk_X509_pop_free(ctx->extra_certs, X509_free);
2234
2235#ifndef OPENSSL_NO_SRTP
2236 if (ctx->srtp_profiles)
2237 sk_SRTP_PROTECTION_PROFILE_free(ctx->srtp_profiles);
2238#endif
2239
2240 free(ctx->tlsext_ecpointformatlist);
2241 free(ctx->tlsext_supportedgroups);
2242
2243 free(ctx->alpn_client_proto_list);
2244
2245 free(ctx);
2246}
2247LSSL_ALIAS(SSL_CTX_free);
2248
2249int
2250SSL_CTX_up_ref(SSL_CTX *ctx)
2251{
2252 return CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX) > 1;
2253}
2254LSSL_ALIAS(SSL_CTX_up_ref);
2255
2256pem_password_cb *
2257SSL_CTX_get_default_passwd_cb(SSL_CTX *ctx)
2258{
2259 return (ctx->default_passwd_callback);
2260}
2261LSSL_ALIAS(SSL_CTX_get_default_passwd_cb);
2262
2263void
2264SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb)
2265{
2266 ctx->default_passwd_callback = cb;
2267}
2268LSSL_ALIAS(SSL_CTX_set_default_passwd_cb);
2269
2270void *
2271SSL_CTX_get_default_passwd_cb_userdata(SSL_CTX *ctx)
2272{
2273 return ctx->default_passwd_callback_userdata;
2274}
2275LSSL_ALIAS(SSL_CTX_get_default_passwd_cb_userdata);
2276
2277void
2278SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *u)
2279{
2280 ctx->default_passwd_callback_userdata = u;
2281}
2282LSSL_ALIAS(SSL_CTX_set_default_passwd_cb_userdata);
2283
2284void
2285SSL_CTX_set_cert_verify_callback(SSL_CTX *ctx,
2286 int (*cb)(X509_STORE_CTX *, void *), void *arg)
2287{
2288 ctx->app_verify_callback = cb;
2289 ctx->app_verify_arg = arg;
2290}
2291LSSL_ALIAS(SSL_CTX_set_cert_verify_callback);
2292
2293void
2294SSL_CTX_set_verify(SSL_CTX *ctx, int mode, int (*cb)(int, X509_STORE_CTX *))
2295{
2296 ctx->verify_mode = mode;
2297 ctx->default_verify_callback = cb;
2298}
2299LSSL_ALIAS(SSL_CTX_set_verify);
2300
2301void
2302SSL_CTX_set_verify_depth(SSL_CTX *ctx, int depth)
2303{
2304 X509_VERIFY_PARAM_set_depth(ctx->param, depth);
2305}
2306LSSL_ALIAS(SSL_CTX_set_verify_depth);
2307
2308void
2309ssl_set_cert_masks(SSL_CERT *c, const SSL_CIPHER *cipher)
2310{
2311 unsigned long mask_a, mask_k;
2312 SSL_CERT_PKEY *cpk;
2313
2314 if (c == NULL)
2315 return;
2316
2317 mask_a = SSL_aNULL | SSL_aTLS1_3;
2318 mask_k = SSL_kECDHE | SSL_kTLS1_3;
2319
2320 if (c->dhe_params != NULL || c->dhe_params_cb != NULL ||
2321 c->dhe_params_auto != 0)
2322 mask_k |= SSL_kDHE;
2323
2324 cpk = &(c->pkeys[SSL_PKEY_ECC]);
2325 if (cpk->x509 != NULL && cpk->privatekey != NULL) {
2326 /* Key usage, if present, must allow signing. */
2327 if (X509_get_key_usage(cpk->x509) & X509v3_KU_DIGITAL_SIGNATURE)
2328 mask_a |= SSL_aECDSA;
2329 }
2330
2331 cpk = &(c->pkeys[SSL_PKEY_RSA]);
2332 if (cpk->x509 != NULL && cpk->privatekey != NULL) {
2333 mask_a |= SSL_aRSA;
2334 mask_k |= SSL_kRSA;
2335 }
2336
2337 c->mask_k = mask_k;
2338 c->mask_a = mask_a;
2339 c->valid = 1;
2340}
2341
2342/* See if this handshake is using an ECC cipher suite. */
2343int
2344ssl_using_ecc_cipher(SSL *s)
2345{
2346 unsigned long alg_a, alg_k;
2347
2348 alg_a = s->s3->hs.cipher->algorithm_auth;
2349 alg_k = s->s3->hs.cipher->algorithm_mkey;
2350
2351 return s->session->tlsext_ecpointformatlist != NULL &&
2352 s->session->tlsext_ecpointformatlist_length > 0 &&
2353 ((alg_k & SSL_kECDHE) || (alg_a & SSL_aECDSA));
2354}
2355
2356int
2357ssl_check_srvr_ecc_cert_and_alg(SSL *s, X509 *x)
2358{
2359 const SSL_CIPHER *cs = s->s3->hs.cipher;
2360 unsigned long alg_a;
2361
2362 alg_a = cs->algorithm_auth;
2363
2364 if (alg_a & SSL_aECDSA) {
2365 /* Key usage, if present, must allow signing. */
2366 if (!(X509_get_key_usage(x) & X509v3_KU_DIGITAL_SIGNATURE)) {
2367 SSLerror(s, SSL_R_ECC_CERT_NOT_FOR_SIGNING);
2368 return (0);
2369 }
2370 }
2371
2372 return (1);
2373}
2374
2375SSL_CERT_PKEY *
2376ssl_get_server_send_pkey(const SSL *s)
2377{
2378 unsigned long alg_a;
2379 SSL_CERT *c;
2380 int i;
2381
2382 c = s->cert;
2383 ssl_set_cert_masks(c, s->s3->hs.cipher);
2384
2385 alg_a = s->s3->hs.cipher->algorithm_auth;
2386
2387 if (alg_a & SSL_aECDSA) {
2388 i = SSL_PKEY_ECC;
2389 } else if (alg_a & SSL_aRSA) {
2390 i = SSL_PKEY_RSA;
2391 } else { /* if (alg_a & SSL_aNULL) */
2392 SSLerror(s, ERR_R_INTERNAL_ERROR);
2393 return (NULL);
2394 }
2395
2396 return (c->pkeys + i);
2397}
2398
2399EVP_PKEY *
2400ssl_get_sign_pkey(SSL *s, const SSL_CIPHER *cipher, const EVP_MD **pmd,
2401 const struct ssl_sigalg **sap)
2402{
2403 const struct ssl_sigalg *sigalg = NULL;
2404 EVP_PKEY *pkey = NULL;
2405 unsigned long alg_a;
2406 SSL_CERT *c;
2407 int idx = -1;
2408
2409 alg_a = cipher->algorithm_auth;
2410 c = s->cert;
2411
2412 if (alg_a & SSL_aRSA) {
2413 idx = SSL_PKEY_RSA;
2414 } else if ((alg_a & SSL_aECDSA) &&
2415 (c->pkeys[SSL_PKEY_ECC].privatekey != NULL))
2416 idx = SSL_PKEY_ECC;
2417 if (idx == -1) {
2418 SSLerror(s, ERR_R_INTERNAL_ERROR);
2419 return (NULL);
2420 }
2421
2422 pkey = c->pkeys[idx].privatekey;
2423 if ((sigalg = ssl_sigalg_select(s, pkey)) == NULL) {
2424 SSLerror(s, SSL_R_SIGNATURE_ALGORITHMS_ERROR);
2425 return (NULL);
2426 }
2427 *pmd = sigalg->md();
2428 *sap = sigalg;
2429
2430 return (pkey);
2431}
2432
2433size_t
2434ssl_dhe_params_auto_key_bits(SSL *s)
2435{
2436 SSL_CERT_PKEY *cpk;
2437 int key_bits;
2438
2439 if (s->cert->dhe_params_auto == 2) {
2440 key_bits = 1024;
2441 } else if (s->s3->hs.cipher->algorithm_auth & SSL_aNULL) {
2442 key_bits = 1024;
2443 if (s->s3->hs.cipher->strength_bits == 256)
2444 key_bits = 3072;
2445 } else {
2446 if ((cpk = ssl_get_server_send_pkey(s)) == NULL)
2447 return 0;
2448 if (cpk->privatekey == NULL ||
2449 EVP_PKEY_get0_RSA(cpk->privatekey) == NULL)
2450 return 0;
2451 if ((key_bits = EVP_PKEY_bits(cpk->privatekey)) <= 0)
2452 return 0;
2453 }
2454
2455 return key_bits;
2456}
2457
2458static int
2459ssl_should_update_external_cache(SSL *s, int mode)
2460{
2461 int cache_mode;
2462
2463 cache_mode = s->session_ctx->session_cache_mode;
2464
2465 /* Don't cache if mode says not to */
2466 if ((cache_mode & mode) == 0)
2467 return 0;
2468
2469 /* if it is not already cached, cache it */
2470 if (!s->hit)
2471 return 1;
2472
2473 /* If it's TLS 1.3, do it to match OpenSSL */
2474 if (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION)
2475 return 1;
2476
2477 return 0;
2478}
2479
2480static int
2481ssl_should_update_internal_cache(SSL *s, int mode)
2482{
2483 int cache_mode;
2484
2485 cache_mode = s->session_ctx->session_cache_mode;
2486
2487 /* Don't cache if mode says not to */
2488 if ((cache_mode & mode) == 0)
2489 return 0;
2490
2491 /* If it is already cached, don't cache it again */
2492 if (s->hit)
2493 return 0;
2494
2495 if ((cache_mode & SSL_SESS_CACHE_NO_INTERNAL_STORE) != 0)
2496 return 0;
2497
2498 /* If we are lesser than TLS 1.3, Cache it. */
2499 if (s->s3->hs.negotiated_tls_version < TLS1_3_VERSION)
2500 return 1;
2501
2502 /* Below this we consider TLS 1.3 or later */
2503
2504 /* If it's not a server, add it? OpenSSL does this. */
2505 if (!s->server)
2506 return 1;
2507
2508 /* XXX if we support early data / PSK need to add */
2509
2510 /*
2511 * If we have the remove session callback, we will want
2512 * to know about this even if it's a stateless ticket
2513 * from 1.3 so we can know when it is removed.
2514 */
2515 if (s->session_ctx->remove_session_cb != NULL)
2516 return 1;
2517
2518 /* If we have set OP_NO_TICKET, cache it. */
2519 if ((s->options & SSL_OP_NO_TICKET) != 0)
2520 return 1;
2521
2522 /* Otherwise do not cache */
2523 return 0;
2524}
2525
2526void
2527ssl_update_cache(SSL *s, int mode)
2528{
2529 int cache_mode, do_callback;
2530
2531 if (s->session->session_id_length == 0)
2532 return;
2533
2534 cache_mode = s->session_ctx->session_cache_mode;
2535 do_callback = ssl_should_update_external_cache(s, mode);
2536
2537 if (ssl_should_update_internal_cache(s, mode)) {
2538 /*
2539 * XXX should we fail if the add to the internal cache
2540 * fails? OpenSSL doesn't care..
2541 */
2542 (void) SSL_CTX_add_session(s->session_ctx, s->session);
2543 }
2544
2545 /*
2546 * Update the "external cache" by calling the new session
2547 * callback if present, even with TLS 1.3 without early data
2548 * "because some application just want to know about the
2549 * creation of a session and aren't doing a full cache".
2550 * Apparently, if they are doing a full cache, they'll have
2551 * some fun, but we endeavour to give application writers the
2552 * same glorious experience they expect from OpenSSL which
2553 * does it this way.
2554 */
2555 if (do_callback && s->session_ctx->new_session_cb != NULL) {
2556 CRYPTO_add(&s->session->references, 1, CRYPTO_LOCK_SSL_SESSION);
2557 if (!s->session_ctx->new_session_cb(s, s->session))
2558 SSL_SESSION_free(s->session);
2559 }
2560
2561 /* Auto flush every 255 connections. */
2562 if (!(cache_mode & SSL_SESS_CACHE_NO_AUTO_CLEAR) &&
2563 (cache_mode & mode) != 0) {
2564 int connections;
2565 if (mode & SSL_SESS_CACHE_CLIENT)
2566 connections = s->session_ctx->stats.sess_connect_good;
2567 else
2568 connections = s->session_ctx->stats.sess_accept_good;
2569 if ((connections & 0xff) == 0xff)
2570 SSL_CTX_flush_sessions(s->session_ctx, time(NULL));
2571 }
2572}
2573
2574const SSL_METHOD *
2575SSL_get_ssl_method(SSL *s)
2576{
2577 return (s->method);
2578}
2579LSSL_ALIAS(SSL_get_ssl_method);
2580
2581int
2582SSL_set_ssl_method(SSL *s, const SSL_METHOD *method)
2583{
2584 int (*handshake_func)(SSL *) = NULL;
2585 int ret = 1;
2586
2587 if (s->method == method)
2588 return (ret);
2589
2590 if (s->handshake_func == s->method->ssl_connect)
2591 handshake_func = method->ssl_connect;
2592 else if (s->handshake_func == s->method->ssl_accept)
2593 handshake_func = method->ssl_accept;
2594
2595 if (s->method->version == method->version) {
2596 s->method = method;
2597 } else {
2598 s->method->ssl_free(s);
2599 s->method = method;
2600 ret = s->method->ssl_new(s);
2601 }
2602 s->handshake_func = handshake_func;
2603
2604 return (ret);
2605}
2606LSSL_ALIAS(SSL_set_ssl_method);
2607
2608int
2609SSL_get_error(const SSL *s, int i)
2610{
2611 unsigned long l;
2612 int reason;
2613 BIO *bio;
2614
2615 if (i > 0)
2616 return (SSL_ERROR_NONE);
2617
2618 /*
2619 * Make things return SSL_ERROR_SYSCALL when doing SSL_do_handshake
2620 * etc, where we do encode the error.
2621 */
2622 if ((l = ERR_peek_error()) != 0) {
2623 if (ERR_GET_LIB(l) == ERR_LIB_SYS)
2624 return (SSL_ERROR_SYSCALL);
2625 else
2626 return (SSL_ERROR_SSL);
2627 }
2628
2629 if (SSL_want_read(s)) {
2630 bio = SSL_get_rbio(s);
2631 if (BIO_should_read(bio)) {
2632 return (SSL_ERROR_WANT_READ);
2633 } else if (BIO_should_write(bio)) {
2634 /*
2635 * This one doesn't make too much sense... We never
2636 * try to write to the rbio, and an application
2637 * program where rbio and wbio are separate couldn't
2638 * even know what it should wait for. However if we
2639 * ever set s->rwstate incorrectly (so that we have
2640 * SSL_want_read(s) instead of SSL_want_write(s))
2641 * and rbio and wbio *are* the same, this test works
2642 * around that bug; so it might be safer to keep it.
2643 */
2644 return (SSL_ERROR_WANT_WRITE);
2645 } else if (BIO_should_io_special(bio)) {
2646 reason = BIO_get_retry_reason(bio);
2647 if (reason == BIO_RR_CONNECT)
2648 return (SSL_ERROR_WANT_CONNECT);
2649 else if (reason == BIO_RR_ACCEPT)
2650 return (SSL_ERROR_WANT_ACCEPT);
2651 else
2652 return (SSL_ERROR_SYSCALL); /* unknown */
2653 }
2654 }
2655
2656 if (SSL_want_write(s)) {
2657 bio = SSL_get_wbio(s);
2658 if (BIO_should_write(bio)) {
2659 return (SSL_ERROR_WANT_WRITE);
2660 } else if (BIO_should_read(bio)) {
2661 /*
2662 * See above (SSL_want_read(s) with
2663 * BIO_should_write(bio))
2664 */
2665 return (SSL_ERROR_WANT_READ);
2666 } else if (BIO_should_io_special(bio)) {
2667 reason = BIO_get_retry_reason(bio);
2668 if (reason == BIO_RR_CONNECT)
2669 return (SSL_ERROR_WANT_CONNECT);
2670 else if (reason == BIO_RR_ACCEPT)
2671 return (SSL_ERROR_WANT_ACCEPT);
2672 else
2673 return (SSL_ERROR_SYSCALL);
2674 }
2675 }
2676
2677 if (SSL_want_x509_lookup(s))
2678 return (SSL_ERROR_WANT_X509_LOOKUP);
2679
2680 if ((s->shutdown & SSL_RECEIVED_SHUTDOWN) &&
2681 (s->s3->warn_alert == SSL_AD_CLOSE_NOTIFY))
2682 return (SSL_ERROR_ZERO_RETURN);
2683
2684 return (SSL_ERROR_SYSCALL);
2685}
2686LSSL_ALIAS(SSL_get_error);
2687
2688int
2689SSL_CTX_set_quic_method(SSL_CTX *ctx, const SSL_QUIC_METHOD *quic_method)
2690{
2691 if (ctx->method->dtls)
2692 return 0;
2693
2694 ctx->quic_method = quic_method;
2695
2696 return 1;
2697}
2698LSSL_ALIAS(SSL_CTX_set_quic_method);
2699
2700int
2701SSL_set_quic_method(SSL *ssl, const SSL_QUIC_METHOD *quic_method)
2702{
2703 if (ssl->method->dtls)
2704 return 0;
2705
2706 ssl->quic_method = quic_method;
2707
2708 return 1;
2709}
2710LSSL_ALIAS(SSL_set_quic_method);
2711
2712size_t
2713SSL_quic_max_handshake_flight_len(const SSL *ssl,
2714 enum ssl_encryption_level_t level)
2715{
2716 size_t flight_len;
2717
2718 /* Limit flights to 16K when there are no large certificate messages. */
2719 flight_len = 16384;
2720
2721 switch (level) {
2722 case ssl_encryption_initial:
2723 return flight_len;
2724
2725 case ssl_encryption_early_data:
2726 /* QUIC does not send EndOfEarlyData. */
2727 return 0;
2728
2729 case ssl_encryption_handshake:
2730 if (ssl->server) {
2731 /*
2732 * Servers may receive Certificate message if configured
2733 * to request client certificates.
2734 */
2735 if ((SSL_get_verify_mode(ssl) & SSL_VERIFY_PEER) != 0 &&
2736 ssl->max_cert_list > flight_len)
2737 flight_len = ssl->max_cert_list;
2738 } else {
2739 /*
2740 * Clients may receive both Certificate message and a
2741 * CertificateRequest message.
2742 */
2743 if (ssl->max_cert_list * 2 > flight_len)
2744 flight_len = ssl->max_cert_list * 2;
2745 }
2746 return flight_len;
2747 case ssl_encryption_application:
2748 /*
2749 * Note there is not actually a bound on the number of
2750 * NewSessionTickets one may send in a row. This level may need
2751 * more involved flow control.
2752 */
2753 return flight_len;
2754 }
2755
2756 return 0;
2757}
2758LSSL_ALIAS(SSL_quic_max_handshake_flight_len);
2759
2760enum ssl_encryption_level_t
2761SSL_quic_read_level(const SSL *ssl)
2762{
2763 return ssl->s3->hs.tls13.quic_read_level;
2764}
2765LSSL_ALIAS(SSL_quic_read_level);
2766
2767enum ssl_encryption_level_t
2768SSL_quic_write_level(const SSL *ssl)
2769{
2770 return ssl->s3->hs.tls13.quic_write_level;
2771}
2772LSSL_ALIAS(SSL_quic_write_level);
2773
2774int
2775SSL_provide_quic_data(SSL *ssl, enum ssl_encryption_level_t level,
2776 const uint8_t *data, size_t len)
2777{
2778 if (!SSL_is_quic(ssl)) {
2779 SSLerror(ssl, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2780 return 0;
2781 }
2782
2783 if (level != SSL_quic_read_level(ssl)) {
2784 SSLerror(ssl, SSL_R_WRONG_ENCRYPTION_LEVEL_RECEIVED);
2785 return 0;
2786 }
2787
2788 if (ssl->s3->hs.tls13.quic_read_buffer == NULL) {
2789 ssl->s3->hs.tls13.quic_read_buffer = tls_buffer_new(0);
2790 if (ssl->s3->hs.tls13.quic_read_buffer == NULL) {
2791 SSLerror(ssl, ERR_R_MALLOC_FAILURE);
2792 return 0;
2793 }
2794 }
2795
2796 /* XXX - note that this does not currently downsize. */
2797 tls_buffer_set_capacity_limit(ssl->s3->hs.tls13.quic_read_buffer,
2798 SSL_quic_max_handshake_flight_len(ssl, level));
2799
2800 /*
2801 * XXX - an append that fails due to exceeding capacity should set
2802 * SSL_R_EXCESSIVE_MESSAGE_SIZE.
2803 */
2804 return tls_buffer_append(ssl->s3->hs.tls13.quic_read_buffer, data, len);
2805}
2806LSSL_ALIAS(SSL_provide_quic_data);
2807
2808int
2809SSL_process_quic_post_handshake(SSL *ssl)
2810{
2811 /* XXX - this needs to run PHH received. */
2812 return 1;
2813}
2814LSSL_ALIAS(SSL_process_quic_post_handshake);
2815
2816int
2817SSL_do_handshake(SSL *s)
2818{
2819 if (s->handshake_func == NULL) {
2820 SSLerror(s, SSL_R_CONNECTION_TYPE_NOT_SET);
2821 return (-1);
2822 }
2823
2824 s->method->ssl_renegotiate_check(s);
2825
2826 if (!SSL_in_init(s) && !SSL_in_before(s))
2827 return 1;
2828
2829 return s->handshake_func(s);
2830}
2831LSSL_ALIAS(SSL_do_handshake);
2832
2833/*
2834 * For the next 2 functions, SSL_clear() sets shutdown and so
2835 * one of these calls will reset it
2836 */
2837void
2838SSL_set_accept_state(SSL *s)
2839{
2840 s->server = 1;
2841 s->shutdown = 0;
2842 s->s3->hs.state = SSL_ST_ACCEPT|SSL_ST_BEFORE;
2843 s->handshake_func = s->method->ssl_accept;
2844 ssl_clear_cipher_state(s);
2845}
2846LSSL_ALIAS(SSL_set_accept_state);
2847
2848void
2849SSL_set_connect_state(SSL *s)
2850{
2851 s->server = 0;
2852 s->shutdown = 0;
2853 s->s3->hs.state = SSL_ST_CONNECT|SSL_ST_BEFORE;
2854 s->handshake_func = s->method->ssl_connect;
2855 ssl_clear_cipher_state(s);
2856}
2857LSSL_ALIAS(SSL_set_connect_state);
2858
2859int
2860ssl_undefined_function(SSL *s)
2861{
2862 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2863 return (0);
2864}
2865
2866int
2867ssl_undefined_void_function(void)
2868{
2869 SSLerrorx(ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2870 return (0);
2871}
2872
2873int
2874ssl_undefined_const_function(const SSL *s)
2875{
2876 SSLerror(s, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
2877 return (0);
2878}
2879
2880const char *
2881ssl_version_string(int ver)
2882{
2883 switch (ver) {
2884 case TLS1_VERSION:
2885 return (SSL_TXT_TLSV1);
2886 case TLS1_1_VERSION:
2887 return (SSL_TXT_TLSV1_1);
2888 case TLS1_2_VERSION:
2889 return (SSL_TXT_TLSV1_2);
2890 case TLS1_3_VERSION:
2891 return (SSL_TXT_TLSV1_3);
2892 case DTLS1_VERSION:
2893 return (SSL_TXT_DTLS1);
2894 case DTLS1_2_VERSION:
2895 return (SSL_TXT_DTLS1_2);
2896 default:
2897 return ("unknown");
2898 }
2899}
2900
2901const char *
2902SSL_get_version(const SSL *s)
2903{
2904 return ssl_version_string(s->version);
2905}
2906LSSL_ALIAS(SSL_get_version);
2907
2908SSL *
2909SSL_dup(SSL *s)
2910{
2911 STACK_OF(X509_NAME) *sk;
2912 X509_NAME *xn;
2913 SSL *ret;
2914 int i;
2915
2916 if ((ret = SSL_new(SSL_get_SSL_CTX(s))) == NULL)
2917 goto err;
2918
2919 ret->version = s->version;
2920 ret->method = s->method;
2921
2922 if (s->session != NULL) {
2923 if (!SSL_copy_session_id(ret, s))
2924 goto err;
2925 } else {
2926 /*
2927 * No session has been established yet, so we have to expect
2928 * that s->cert or ret->cert will be changed later --
2929 * they should not both point to the same object,
2930 * and thus we can't use SSL_copy_session_id.
2931 */
2932
2933 ret->method->ssl_free(ret);
2934 ret->method = s->method;
2935 ret->method->ssl_new(ret);
2936
2937 ssl_cert_free(ret->cert);
2938 if ((ret->cert = ssl_cert_dup(s->cert)) == NULL)
2939 goto err;
2940
2941 if (!SSL_set_session_id_context(ret, s->sid_ctx,
2942 s->sid_ctx_length))
2943 goto err;
2944 }
2945
2946 ret->options = s->options;
2947 ret->mode = s->mode;
2948 SSL_set_max_cert_list(ret, SSL_get_max_cert_list(s));
2949 SSL_set_read_ahead(ret, SSL_get_read_ahead(s));
2950 ret->msg_callback = s->msg_callback;
2951 ret->msg_callback_arg = s->msg_callback_arg;
2952 SSL_set_verify(ret, SSL_get_verify_mode(s),
2953 SSL_get_verify_callback(s));
2954 SSL_set_verify_depth(ret, SSL_get_verify_depth(s));
2955 ret->generate_session_id = s->generate_session_id;
2956
2957 SSL_set_info_callback(ret, SSL_get_info_callback(s));
2958
2959 /* copy app data, a little dangerous perhaps */
2960 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL,
2961 &ret->ex_data, &s->ex_data))
2962 goto err;
2963
2964 /* setup rbio, and wbio */
2965 if (s->rbio != NULL) {
2966 if (!BIO_dup_state(s->rbio,(char *)&ret->rbio))
2967 goto err;
2968 }
2969 if (s->wbio != NULL) {
2970 if (s->wbio != s->rbio) {
2971 if (!BIO_dup_state(s->wbio,(char *)&ret->wbio))
2972 goto err;
2973 } else
2974 ret->wbio = ret->rbio;
2975 }
2976 ret->rwstate = s->rwstate;
2977 ret->in_handshake = s->in_handshake;
2978 ret->handshake_func = s->handshake_func;
2979 ret->server = s->server;
2980 ret->renegotiate = s->renegotiate;
2981 ret->new_session = s->new_session;
2982 ret->quiet_shutdown = s->quiet_shutdown;
2983 ret->shutdown = s->shutdown;
2984 /* SSL_dup does not really work at any state, though */
2985 ret->s3->hs.state = s->s3->hs.state;
2986 ret->rstate = s->rstate;
2987
2988 /*
2989 * Would have to copy ret->init_buf, ret->init_msg, ret->init_num,
2990 * ret->init_off
2991 */
2992 ret->init_num = 0;
2993
2994 ret->hit = s->hit;
2995
2996 X509_VERIFY_PARAM_inherit(ret->param, s->param);
2997
2998 if (s->cipher_list != NULL) {
2999 if ((ret->cipher_list =
3000 sk_SSL_CIPHER_dup(s->cipher_list)) == NULL)
3001 goto err;
3002 }
3003 if (s->cipher_list_tls13 != NULL) {
3004 if ((ret->cipher_list_tls13 =
3005 sk_SSL_CIPHER_dup(s->cipher_list_tls13)) == NULL)
3006 goto err;
3007 }
3008
3009 /* Dup the client_CA list */
3010 if (s->client_CA != NULL) {
3011 if ((sk = sk_X509_NAME_dup(s->client_CA)) == NULL) goto err;
3012 ret->client_CA = sk;
3013 for (i = 0; i < sk_X509_NAME_num(sk); i++) {
3014 xn = sk_X509_NAME_value(sk, i);
3015 if (sk_X509_NAME_set(sk, i,
3016 X509_NAME_dup(xn)) == NULL) {
3017 X509_NAME_free(xn);
3018 goto err;
3019 }
3020 }
3021 }
3022
3023 return ret;
3024 err:
3025 SSL_free(ret);
3026 return NULL;
3027}
3028LSSL_ALIAS(SSL_dup);
3029
3030void
3031ssl_clear_cipher_state(SSL *s)
3032{
3033 tls12_record_layer_clear_read_state(s->rl);
3034 tls12_record_layer_clear_write_state(s->rl);
3035}
3036
3037void
3038ssl_info_callback(const SSL *s, int type, int value)
3039{
3040 ssl_info_callback_fn *cb;
3041
3042 if ((cb = s->info_callback) == NULL)
3043 cb = s->ctx->info_callback;
3044 if (cb != NULL)
3045 cb(s, type, value);
3046}
3047
3048void
3049ssl_msg_callback(SSL *s, int is_write, int content_type,
3050 const void *msg_buf, size_t msg_len)
3051{
3052 if (s->msg_callback == NULL)
3053 return;
3054
3055 s->msg_callback(is_write, s->version, content_type,
3056 msg_buf, msg_len, s, s->msg_callback_arg);
3057}
3058
3059void
3060ssl_msg_callback_cbs(SSL *s, int is_write, int content_type, CBS *cbs)
3061{
3062 ssl_msg_callback(s, is_write, content_type, CBS_data(cbs), CBS_len(cbs));
3063}
3064
3065/* Fix this function so that it takes an optional type parameter */
3066X509 *
3067SSL_get_certificate(const SSL *s)
3068{
3069 return (s->cert->key->x509);
3070}
3071LSSL_ALIAS(SSL_get_certificate);
3072
3073/* Fix this function so that it takes an optional type parameter */
3074EVP_PKEY *
3075SSL_get_privatekey(const SSL *s)
3076{
3077 return (s->cert->key->privatekey);
3078}
3079LSSL_ALIAS(SSL_get_privatekey);
3080
3081const SSL_CIPHER *
3082SSL_get_current_cipher(const SSL *s)
3083{
3084 return s->s3->hs.cipher;
3085}
3086LSSL_ALIAS(SSL_get_current_cipher);
3087
3088const void *
3089SSL_get_current_compression(SSL *s)
3090{
3091 return (NULL);
3092}
3093LSSL_ALIAS(SSL_get_current_compression);
3094
3095const void *
3096SSL_get_current_expansion(SSL *s)
3097{
3098 return (NULL);
3099}
3100LSSL_ALIAS(SSL_get_current_expansion);
3101
3102size_t
3103SSL_get_client_random(const SSL *s, unsigned char *out, size_t max_out)
3104{
3105 size_t len = sizeof(s->s3->client_random);
3106
3107 if (out == NULL)
3108 return len;
3109
3110 if (len > max_out)
3111 len = max_out;
3112
3113 memcpy(out, s->s3->client_random, len);
3114
3115 return len;
3116}
3117LSSL_ALIAS(SSL_get_client_random);
3118
3119size_t
3120SSL_get_server_random(const SSL *s, unsigned char *out, size_t max_out)
3121{
3122 size_t len = sizeof(s->s3->server_random);
3123
3124 if (out == NULL)
3125 return len;
3126
3127 if (len > max_out)
3128 len = max_out;
3129
3130 memcpy(out, s->s3->server_random, len);
3131
3132 return len;
3133}
3134LSSL_ALIAS(SSL_get_server_random);
3135
3136int
3137ssl_init_wbio_buffer(SSL *s, int push)
3138{
3139 BIO *bbio;
3140
3141 if (s->bbio == NULL) {
3142 bbio = BIO_new(BIO_f_buffer());
3143 if (bbio == NULL)
3144 return (0);
3145 s->bbio = bbio;
3146 } else {
3147 bbio = s->bbio;
3148 if (s->bbio == s->wbio)
3149 s->wbio = BIO_pop(s->wbio);
3150 }
3151 (void)BIO_reset(bbio);
3152/* if (!BIO_set_write_buffer_size(bbio,16*1024)) */
3153 if (!BIO_set_read_buffer_size(bbio, 1)) {
3154 SSLerror(s, ERR_R_BUF_LIB);
3155 return (0);
3156 }
3157 if (push) {
3158 if (s->wbio != bbio)
3159 s->wbio = BIO_push(bbio, s->wbio);
3160 } else {
3161 if (s->wbio == bbio)
3162 s->wbio = BIO_pop(bbio);
3163 }
3164 return (1);
3165}
3166
3167void
3168ssl_free_wbio_buffer(SSL *s)
3169{
3170 if (s == NULL)
3171 return;
3172
3173 if (s->bbio == NULL)
3174 return;
3175
3176 if (s->bbio == s->wbio) {
3177 /* remove buffering */
3178 s->wbio = BIO_pop(s->wbio);
3179 }
3180 BIO_free(s->bbio);
3181 s->bbio = NULL;
3182}
3183
3184void
3185SSL_CTX_set_quiet_shutdown(SSL_CTX *ctx, int mode)
3186{
3187 ctx->quiet_shutdown = mode;
3188}
3189LSSL_ALIAS(SSL_CTX_set_quiet_shutdown);
3190
3191int
3192SSL_CTX_get_quiet_shutdown(const SSL_CTX *ctx)
3193{
3194 return (ctx->quiet_shutdown);
3195}
3196LSSL_ALIAS(SSL_CTX_get_quiet_shutdown);
3197
3198void
3199SSL_set_quiet_shutdown(SSL *s, int mode)
3200{
3201 s->quiet_shutdown = mode;
3202}
3203LSSL_ALIAS(SSL_set_quiet_shutdown);
3204
3205int
3206SSL_get_quiet_shutdown(const SSL *s)
3207{
3208 return (s->quiet_shutdown);
3209}
3210LSSL_ALIAS(SSL_get_quiet_shutdown);
3211
3212void
3213SSL_set_shutdown(SSL *s, int mode)
3214{
3215 s->shutdown = mode;
3216}
3217LSSL_ALIAS(SSL_set_shutdown);
3218
3219int
3220SSL_get_shutdown(const SSL *s)
3221{
3222 return (s->shutdown);
3223}
3224LSSL_ALIAS(SSL_get_shutdown);
3225
3226int
3227SSL_version(const SSL *s)
3228{
3229 return (s->version);
3230}
3231LSSL_ALIAS(SSL_version);
3232
3233SSL_CTX *
3234SSL_get_SSL_CTX(const SSL *ssl)
3235{
3236 return (ssl->ctx);
3237}
3238LSSL_ALIAS(SSL_get_SSL_CTX);
3239
3240SSL_CTX *
3241SSL_set_SSL_CTX(SSL *ssl, SSL_CTX* ctx)
3242{
3243 SSL_CERT *new_cert;
3244
3245 if (ctx == NULL)
3246 ctx = ssl->initial_ctx;
3247 if (ssl->ctx == ctx)
3248 return (ssl->ctx);
3249
3250 if ((new_cert = ssl_cert_dup(ctx->cert)) == NULL)
3251 return NULL;
3252 ssl_cert_free(ssl->cert);
3253 ssl->cert = new_cert;
3254
3255 SSL_CTX_up_ref(ctx);
3256 SSL_CTX_free(ssl->ctx); /* decrement reference count */
3257 ssl->ctx = ctx;
3258
3259 return (ssl->ctx);
3260}
3261LSSL_ALIAS(SSL_set_SSL_CTX);
3262
3263int
3264SSL_CTX_set_default_verify_paths(SSL_CTX *ctx)
3265{
3266 return (X509_STORE_set_default_paths(ctx->cert_store));
3267}
3268LSSL_ALIAS(SSL_CTX_set_default_verify_paths);
3269
3270int
3271SSL_CTX_load_verify_locations(SSL_CTX *ctx, const char *CAfile,
3272 const char *CApath)
3273{
3274 return (X509_STORE_load_locations(ctx->cert_store, CAfile, CApath));
3275}
3276LSSL_ALIAS(SSL_CTX_load_verify_locations);
3277
3278int
3279SSL_CTX_load_verify_mem(SSL_CTX *ctx, void *buf, int len)
3280{
3281 return (X509_STORE_load_mem(ctx->cert_store, buf, len));
3282}
3283LSSL_ALIAS(SSL_CTX_load_verify_mem);
3284
3285void
3286SSL_set_info_callback(SSL *ssl, void (*cb)(const SSL *ssl, int type, int val))
3287{
3288 ssl->info_callback = cb;
3289}
3290LSSL_ALIAS(SSL_set_info_callback);
3291
3292void (*SSL_get_info_callback(const SSL *ssl))(const SSL *ssl, int type, int val)
3293{
3294 return (ssl->info_callback);
3295}
3296LSSL_ALIAS(SSL_get_info_callback);
3297
3298int
3299SSL_state(const SSL *ssl)
3300{
3301 return (ssl->s3->hs.state);
3302}
3303LSSL_ALIAS(SSL_state);
3304
3305void
3306SSL_set_state(SSL *ssl, int state)
3307{
3308 ssl->s3->hs.state = state;
3309}
3310LSSL_ALIAS(SSL_set_state);
3311
3312void
3313SSL_set_verify_result(SSL *ssl, long arg)
3314{
3315 ssl->verify_result = arg;
3316}
3317LSSL_ALIAS(SSL_set_verify_result);
3318
3319long
3320SSL_get_verify_result(const SSL *ssl)
3321{
3322 return (ssl->verify_result);
3323}
3324LSSL_ALIAS(SSL_get_verify_result);
3325
3326int
3327SSL_verify_client_post_handshake(SSL *ssl)
3328{
3329 return 0;
3330}
3331LSSL_ALIAS(SSL_verify_client_post_handshake);
3332
3333void
3334SSL_CTX_set_post_handshake_auth(SSL_CTX *ctx, int val)
3335{
3336 return;
3337}
3338LSSL_ALIAS(SSL_CTX_set_post_handshake_auth);
3339
3340void
3341SSL_set_post_handshake_auth(SSL *ssl, int val)
3342{
3343 return;
3344}
3345LSSL_ALIAS(SSL_set_post_handshake_auth);
3346
3347int
3348SSL_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
3349 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
3350{
3351 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL, argl, argp,
3352 new_func, dup_func, free_func));
3353}
3354LSSL_ALIAS(SSL_get_ex_new_index);
3355
3356int
3357SSL_set_ex_data(SSL *s, int idx, void *arg)
3358{
3359 return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
3360}
3361LSSL_ALIAS(SSL_set_ex_data);
3362
3363void *
3364SSL_get_ex_data(const SSL *s, int idx)
3365{
3366 return (CRYPTO_get_ex_data(&s->ex_data, idx));
3367}
3368LSSL_ALIAS(SSL_get_ex_data);
3369
3370int
3371SSL_CTX_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
3372 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
3373{
3374 return (CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_CTX, argl, argp,
3375 new_func, dup_func, free_func));
3376}
3377LSSL_ALIAS(SSL_CTX_get_ex_new_index);
3378
3379int
3380SSL_CTX_set_ex_data(SSL_CTX *s, int idx, void *arg)
3381{
3382 return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
3383}
3384LSSL_ALIAS(SSL_CTX_set_ex_data);
3385
3386void *
3387SSL_CTX_get_ex_data(const SSL_CTX *s, int idx)
3388{
3389 return (CRYPTO_get_ex_data(&s->ex_data, idx));
3390}
3391LSSL_ALIAS(SSL_CTX_get_ex_data);
3392
3393int
3394ssl_ok(SSL *s)
3395{
3396 return (1);
3397}
3398
3399X509_STORE *
3400SSL_CTX_get_cert_store(const SSL_CTX *ctx)
3401{
3402 return (ctx->cert_store);
3403}
3404LSSL_ALIAS(SSL_CTX_get_cert_store);
3405
3406void
3407SSL_CTX_set_cert_store(SSL_CTX *ctx, X509_STORE *store)
3408{
3409 X509_STORE_free(ctx->cert_store);
3410 ctx->cert_store = store;
3411}
3412LSSL_ALIAS(SSL_CTX_set_cert_store);
3413
3414void
3415SSL_CTX_set1_cert_store(SSL_CTX *ctx, X509_STORE *store)
3416{
3417 if (store != NULL)
3418 X509_STORE_up_ref(store);
3419
3420 SSL_CTX_set_cert_store(ctx, store);
3421}
3422LSSL_ALIAS(SSL_CTX_set1_cert_store);
3423
3424X509 *
3425SSL_CTX_get0_certificate(const SSL_CTX *ctx)
3426{
3427 if (ctx->cert == NULL)
3428 return NULL;
3429
3430 return ctx->cert->key->x509;
3431}
3432LSSL_ALIAS(SSL_CTX_get0_certificate);
3433
3434EVP_PKEY *
3435SSL_CTX_get0_privatekey(const SSL_CTX *ctx)
3436{
3437 if (ctx->cert == NULL)
3438 return NULL;
3439
3440 return ctx->cert->key->privatekey;
3441}
3442LSSL_ALIAS(SSL_CTX_get0_privatekey);
3443
3444int
3445SSL_want(const SSL *s)
3446{
3447 return (s->rwstate);
3448}
3449LSSL_ALIAS(SSL_want);
3450
3451void
3452SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, RSA *(*cb)(SSL *ssl, int is_export,
3453 int keylength))
3454{
3455 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb);
3456}
3457LSSL_ALIAS(SSL_CTX_set_tmp_rsa_callback);
3458
3459void
3460SSL_set_tmp_rsa_callback(SSL *ssl, RSA *(*cb)(SSL *ssl, int is_export,
3461 int keylength))
3462{
3463 SSL_callback_ctrl(ssl, SSL_CTRL_SET_TMP_RSA_CB,(void (*)(void))cb);
3464}
3465LSSL_ALIAS(SSL_set_tmp_rsa_callback);
3466
3467void
3468SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx, DH *(*dh)(SSL *ssl, int is_export,
3469 int keylength))
3470{
3471 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh);
3472}
3473LSSL_ALIAS(SSL_CTX_set_tmp_dh_callback);
3474
3475void
3476SSL_set_tmp_dh_callback(SSL *ssl, DH *(*dh)(SSL *ssl, int is_export,
3477 int keylength))
3478{
3479 SSL_callback_ctrl(ssl, SSL_CTRL_SET_TMP_DH_CB,(void (*)(void))dh);
3480}
3481LSSL_ALIAS(SSL_set_tmp_dh_callback);
3482
3483void
3484SSL_CTX_set_tmp_ecdh_callback(SSL_CTX *ctx, EC_KEY *(*ecdh)(SSL *ssl,
3485 int is_export, int keylength))
3486{
3487 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_TMP_ECDH_CB,
3488 (void (*)(void))ecdh);
3489}
3490LSSL_ALIAS(SSL_CTX_set_tmp_ecdh_callback);
3491
3492void
3493SSL_set_tmp_ecdh_callback(SSL *ssl, EC_KEY *(*ecdh)(SSL *ssl, int is_export,
3494 int keylength))
3495{
3496 SSL_callback_ctrl(ssl, SSL_CTRL_SET_TMP_ECDH_CB,(void (*)(void))ecdh);
3497}
3498LSSL_ALIAS(SSL_set_tmp_ecdh_callback);
3499
3500
3501void
3502SSL_CTX_set_msg_callback(SSL_CTX *ctx, void (*cb)(int write_p, int version,
3503 int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
3504{
3505 SSL_CTX_callback_ctrl(ctx, SSL_CTRL_SET_MSG_CALLBACK,
3506 (void (*)(void))cb);
3507}
3508LSSL_ALIAS(SSL_CTX_set_msg_callback);
3509
3510void
3511SSL_set_msg_callback(SSL *ssl, void (*cb)(int write_p, int version,
3512 int content_type, const void *buf, size_t len, SSL *ssl, void *arg))
3513{
3514 SSL_callback_ctrl(ssl, SSL_CTRL_SET_MSG_CALLBACK, (void (*)(void))cb);
3515}
3516LSSL_ALIAS(SSL_set_msg_callback);
3517
3518int
3519SSL_cache_hit(SSL *s)
3520{
3521 return (s->hit);
3522}
3523LSSL_ALIAS(SSL_cache_hit);
3524
3525int
3526SSL_CTX_get_min_proto_version(SSL_CTX *ctx)
3527{
3528 return ctx->min_proto_version;
3529}
3530LSSL_ALIAS(SSL_CTX_get_min_proto_version);
3531
3532int
3533SSL_CTX_set_min_proto_version(SSL_CTX *ctx, uint16_t version)
3534{
3535 return ssl_version_set_min(ctx->method, version,
3536 ctx->max_tls_version, &ctx->min_tls_version,
3537 &ctx->min_proto_version);
3538}
3539LSSL_ALIAS(SSL_CTX_set_min_proto_version);
3540
3541int
3542SSL_CTX_get_max_proto_version(SSL_CTX *ctx)
3543{
3544 return ctx->max_proto_version;
3545}
3546LSSL_ALIAS(SSL_CTX_get_max_proto_version);
3547
3548int
3549SSL_CTX_set_max_proto_version(SSL_CTX *ctx, uint16_t version)
3550{
3551 return ssl_version_set_max(ctx->method, version,
3552 ctx->min_tls_version, &ctx->max_tls_version,
3553 &ctx->max_proto_version);
3554}
3555LSSL_ALIAS(SSL_CTX_set_max_proto_version);
3556
3557int
3558SSL_get_min_proto_version(SSL *ssl)
3559{
3560 return ssl->min_proto_version;
3561}
3562LSSL_ALIAS(SSL_get_min_proto_version);
3563
3564int
3565SSL_set_min_proto_version(SSL *ssl, uint16_t version)
3566{
3567 return ssl_version_set_min(ssl->method, version,
3568 ssl->max_tls_version, &ssl->min_tls_version,
3569 &ssl->min_proto_version);
3570}
3571LSSL_ALIAS(SSL_set_min_proto_version);
3572int
3573SSL_get_max_proto_version(SSL *ssl)
3574{
3575 return ssl->max_proto_version;
3576}
3577LSSL_ALIAS(SSL_get_max_proto_version);
3578
3579int
3580SSL_set_max_proto_version(SSL *ssl, uint16_t version)
3581{
3582 return ssl_version_set_max(ssl->method, version,
3583 ssl->min_tls_version, &ssl->max_tls_version,
3584 &ssl->max_proto_version);
3585}
3586LSSL_ALIAS(SSL_set_max_proto_version);
3587
3588const SSL_METHOD *
3589SSL_CTX_get_ssl_method(const SSL_CTX *ctx)
3590{
3591 return ctx->method;
3592}
3593LSSL_ALIAS(SSL_CTX_get_ssl_method);
3594
3595int
3596SSL_CTX_get_security_level(const SSL_CTX *ctx)
3597{
3598 return ctx->cert->security_level;
3599}
3600LSSL_ALIAS(SSL_CTX_get_security_level);
3601
3602void
3603SSL_CTX_set_security_level(SSL_CTX *ctx, int level)
3604{
3605 ctx->cert->security_level = level;
3606}
3607LSSL_ALIAS(SSL_CTX_set_security_level);
3608
3609int
3610SSL_get_security_level(const SSL *ssl)
3611{
3612 return ssl->cert->security_level;
3613}
3614LSSL_ALIAS(SSL_get_security_level);
3615
3616void
3617SSL_set_security_level(SSL *ssl, int level)
3618{
3619 ssl->cert->security_level = level;
3620}
3621LSSL_ALIAS(SSL_set_security_level);
3622
3623int
3624SSL_is_quic(const SSL *ssl)
3625{
3626 return ssl->quic_method != NULL;
3627}
3628LSSL_ALIAS(SSL_is_quic);
3629
3630int
3631SSL_set_quic_transport_params(SSL *ssl, const uint8_t *params,
3632 size_t params_len)
3633{
3634 freezero(ssl->quic_transport_params,
3635 ssl->quic_transport_params_len);
3636 ssl->quic_transport_params = NULL;
3637 ssl->quic_transport_params_len = 0;
3638
3639 if ((ssl->quic_transport_params = malloc(params_len)) == NULL)
3640 return 0;
3641
3642 memcpy(ssl->quic_transport_params, params, params_len);
3643 ssl->quic_transport_params_len = params_len;
3644
3645 return 1;
3646}
3647LSSL_ALIAS(SSL_set_quic_transport_params);
3648
3649void
3650SSL_get_peer_quic_transport_params(const SSL *ssl, const uint8_t **out_params,
3651 size_t *out_params_len)
3652{
3653 *out_params = ssl->s3->peer_quic_transport_params;
3654 *out_params_len = ssl->s3->peer_quic_transport_params_len;
3655}
3656LSSL_ALIAS(SSL_get_peer_quic_transport_params);
3657
3658void
3659SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy)
3660{
3661 /* Not supported. */
3662}
3663LSSL_ALIAS(SSL_set_quic_use_legacy_codepoint);
diff --git a/src/lib/libssl/ssl_local.h b/src/lib/libssl/ssl_local.h
deleted file mode 100644
index 6095940388..0000000000
--- a/src/lib/libssl/ssl_local.h
+++ /dev/null
@@ -1,1463 +0,0 @@
1/* $OpenBSD: ssl_local.h,v 1.27 2025/03/09 15:12:18 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECC cipher suite support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116/* ====================================================================
117 * Copyright 2005 Nokia. All rights reserved.
118 *
119 * The portions of the attached software ("Contribution") is developed by
120 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
121 * license.
122 *
123 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
124 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
125 * support (see RFC 4279) to OpenSSL.
126 *
127 * No patent licenses or other rights except those expressly stated in
128 * the OpenSSL open source license shall be deemed granted or received
129 * expressly, by implication, estoppel, or otherwise.
130 *
131 * No assurances are provided by Nokia that the Contribution does not
132 * infringe the patent or other intellectual property rights of any third
133 * party or that the license provides you with all the necessary rights
134 * to make use of the Contribution.
135 *
136 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
137 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
138 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
139 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
140 * OTHERWISE.
141 */
142
143#ifndef HEADER_SSL_LOCL_H
144#define HEADER_SSL_LOCL_H
145
146#include <sys/types.h>
147
148#include <errno.h>
149#include <stdlib.h>
150#include <string.h>
151#include <time.h>
152#include <unistd.h>
153
154#include <openssl/opensslconf.h>
155
156#include <openssl/bio.h>
157#include <openssl/buffer.h>
158#include <openssl/err.h>
159#include <openssl/rsa.h>
160#include <openssl/ssl.h>
161#include <openssl/stack.h>
162
163#include "bytestring.h"
164#include "tls_content.h"
165#include "tls13_internal.h"
166
167__BEGIN_HIDDEN_DECLS
168
169#ifndef CTASSERT
170#define CTASSERT(x) extern char _ctassert[(x) ? 1 : -1 ] \
171 __attribute__((__unused__))
172#endif
173
174#ifndef LIBRESSL_HAS_DTLS1_2
175#define LIBRESSL_HAS_DTLS1_2
176#endif
177
178/* LOCAL STUFF */
179
180#define SSL_DECRYPT 0
181#define SSL_ENCRYPT 1
182
183/*
184 * Define the Bitmasks for SSL_CIPHER.algorithms.
185 * This bits are used packed as dense as possible. If new methods/ciphers
186 * etc will be added, the bits a likely to change, so this information
187 * is for internal library use only, even though SSL_CIPHER.algorithms
188 * can be publicly accessed.
189 * Use the according functions for cipher management instead.
190 *
191 * The bit mask handling in the selection and sorting scheme in
192 * ssl_create_cipher_list() has only limited capabilities, reflecting
193 * that the different entities within are mutually exclusive:
194 * ONLY ONE BIT PER MASK CAN BE SET AT A TIME.
195 */
196
197/* Bits for algorithm_mkey (key exchange algorithm) */
198#define SSL_kRSA 0x00000001L /* RSA key exchange */
199#define SSL_kDHE 0x00000008L /* tmp DH key no DH cert */
200#define SSL_kECDHE 0x00000080L /* ephemeral ECDH */
201#define SSL_kTLS1_3 0x00000400L /* TLSv1.3 key exchange */
202
203/* Bits for algorithm_auth (server authentication) */
204#define SSL_aRSA 0x00000001L /* RSA auth */
205#define SSL_aNULL 0x00000004L /* no auth (i.e. use ADH or AECDH) */
206#define SSL_aECDSA 0x00000040L /* ECDSA auth*/
207#define SSL_aTLS1_3 0x00000400L /* TLSv1.3 authentication */
208
209/* Bits for algorithm_enc (symmetric encryption) */
210#define SSL_3DES 0x00000002L
211#define SSL_RC4 0x00000004L
212#define SSL_eNULL 0x00000010L
213#define SSL_AES128 0x00000020L
214#define SSL_AES256 0x00000040L
215#define SSL_CAMELLIA128 0x00000080L
216#define SSL_CAMELLIA256 0x00000100L
217#define SSL_AES128GCM 0x00000400L
218#define SSL_AES256GCM 0x00000800L
219#define SSL_CHACHA20POLY1305 0x00001000L
220
221#define SSL_AES (SSL_AES128|SSL_AES256|SSL_AES128GCM|SSL_AES256GCM)
222#define SSL_CAMELLIA (SSL_CAMELLIA128|SSL_CAMELLIA256)
223
224
225/* Bits for algorithm_mac (symmetric authentication) */
226
227#define SSL_MD5 0x00000001L
228#define SSL_SHA1 0x00000002L
229#define SSL_SHA256 0x00000010L
230#define SSL_SHA384 0x00000020L
231/* Not a real MAC, just an indication it is part of cipher */
232#define SSL_AEAD 0x00000040L
233#define SSL_STREEBOG256 0x00000080L
234
235/* Bits for algorithm_ssl (protocol version) */
236#define SSL_SSLV3 0x00000002L
237#define SSL_TLSV1 SSL_SSLV3 /* for now */
238#define SSL_TLSV1_2 0x00000004L
239#define SSL_TLSV1_3 0x00000008L
240
241
242/* Bits for algorithm2 (handshake digests and other extra flags) */
243
244#define SSL_HANDSHAKE_MAC_MASK 0xff0
245#define SSL_HANDSHAKE_MAC_SHA256 0x080
246#define SSL_HANDSHAKE_MAC_SHA384 0x100
247
248#define SSL3_CK_ID 0x03000000
249#define SSL3_CK_VALUE_MASK 0x0000ffff
250
251/*
252 * Cipher strength information.
253 */
254#define SSL_STRONG_MASK 0x000001fcL
255#define SSL_STRONG_NONE 0x00000004L
256#define SSL_LOW 0x00000020L
257#define SSL_MEDIUM 0x00000040L
258#define SSL_HIGH 0x00000080L
259
260/*
261 * The keylength (measured in RSA key bits, I guess) for temporary keys.
262 * Cipher argument is so that this can be variable in the future.
263 */
264#define SSL_C_PKEYLENGTH(c) 1024
265
266/* See if we use signature algorithms extension. */
267#define SSL_USE_SIGALGS(s) \
268 (s->method->enc_flags & SSL_ENC_FLAG_SIGALGS)
269
270/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
271#define SSL_USE_TLS1_2_CIPHERS(s) \
272 (s->method->enc_flags & SSL_ENC_FLAG_TLS1_2_CIPHERS)
273
274/* Allow TLS 1.3 ciphersuites only. */
275#define SSL_USE_TLS1_3_CIPHERS(s) \
276 (s->method->enc_flags & SSL_ENC_FLAG_TLS1_3_CIPHERS)
277
278#define SSL_PKEY_RSA 0
279#define SSL_PKEY_ECC 1
280#define SSL_PKEY_NUM 2
281
282#define SSL_MAX_EMPTY_RECORDS 32
283
284/* SSL_kRSA <- RSA_ENC | (RSA_TMP & RSA_SIGN) |
285 * <- (EXPORT & (RSA_ENC | RSA_TMP) & RSA_SIGN)
286 * SSL_kDH <- DH_ENC & (RSA_ENC | RSA_SIGN | DSA_SIGN)
287 * SSL_kDHE <- RSA_ENC | RSA_SIGN | DSA_SIGN
288 * SSL_aRSA <- RSA_ENC | RSA_SIGN
289 * SSL_aDSS <- DSA_SIGN
290 */
291
292/* From ECC-TLS draft, used in encoding the curve type in
293 * ECParameters
294 */
295#define EXPLICIT_PRIME_CURVE_TYPE 1
296#define EXPLICIT_CHAR2_CURVE_TYPE 2
297#define NAMED_CURVE_TYPE 3
298
299typedef struct ssl_cert_pkey_st {
300 X509 *x509;
301 EVP_PKEY *privatekey;
302 STACK_OF(X509) *chain;
303} SSL_CERT_PKEY;
304
305typedef struct ssl_cert_st {
306 /* Current active set */
307 /* ALWAYS points to an element of the pkeys array
308 * Probably it would make more sense to store
309 * an index, not a pointer. */
310 SSL_CERT_PKEY *key;
311
312 SSL_CERT_PKEY pkeys[SSL_PKEY_NUM];
313
314 /* The following masks are for the key and auth
315 * algorithms that are supported by the certs below */
316 int valid;
317 unsigned long mask_k;
318 unsigned long mask_a;
319
320 DH *dhe_params;
321 DH *(*dhe_params_cb)(SSL *ssl, int is_export, int keysize);
322 int dhe_params_auto;
323
324 int (*security_cb)(const SSL *s, const SSL_CTX *ctx, int op, int bits,
325 int nid, void *other, void *ex_data); /* Not exposed in API. */
326 int security_level;
327 void *security_ex_data; /* Not exposed in API. */
328
329 int references; /* >1 only if SSL_copy_session_id is used */
330} SSL_CERT;
331
332struct ssl_comp_st {
333 int id;
334 const char *name;
335};
336
337struct ssl_cipher_st {
338 uint16_t value; /* Cipher suite value. */
339
340 const char *name; /* text name */
341
342 unsigned long algorithm_mkey; /* key exchange algorithm */
343 unsigned long algorithm_auth; /* server authentication */
344 unsigned long algorithm_enc; /* symmetric encryption */
345 unsigned long algorithm_mac; /* symmetric authentication */
346 unsigned long algorithm_ssl; /* (major) protocol version */
347
348 unsigned long algo_strength; /* strength and export flags */
349 unsigned long algorithm2; /* Extra flags */
350 int strength_bits; /* Number of bits really used */
351 int alg_bits; /* Number of bits for algorithm */
352};
353
354struct ssl_method_st {
355 int dtls;
356 int server;
357 int version;
358
359 uint16_t min_tls_version;
360 uint16_t max_tls_version;
361
362 int (*ssl_new)(SSL *s);
363 void (*ssl_clear)(SSL *s);
364 void (*ssl_free)(SSL *s);
365
366 int (*ssl_accept)(SSL *s);
367 int (*ssl_connect)(SSL *s);
368 int (*ssl_shutdown)(SSL *s);
369
370 int (*ssl_renegotiate)(SSL *s);
371 int (*ssl_renegotiate_check)(SSL *s);
372
373 int (*ssl_pending)(const SSL *s);
374 int (*ssl_read_bytes)(SSL *s, int type, unsigned char *buf, int len,
375 int peek);
376 int (*ssl_write_bytes)(SSL *s, int type, const void *buf_, int len);
377
378 unsigned int enc_flags; /* SSL_ENC_FLAG_* */
379};
380
381/*
382 * Let's make this into an ASN.1 type structure as follows
383 * SSL_SESSION_ID ::= SEQUENCE {
384 * version INTEGER, -- structure version number
385 * SSLversion INTEGER, -- SSL version number
386 * Cipher OCTET STRING, -- the 2 byte cipher ID
387 * Session_ID OCTET STRING, -- the Session ID
388 * Master_key OCTET STRING, -- the master key
389 * KRB5_principal OCTET STRING -- optional Kerberos principal
390 * Time [ 1 ] EXPLICIT INTEGER, -- optional Start Time
391 * Timeout [ 2 ] EXPLICIT INTEGER, -- optional Timeout ins seconds
392 * Peer [ 3 ] EXPLICIT X509, -- optional Peer Certificate
393 * Session_ID_context [ 4 ] EXPLICIT OCTET STRING, -- the Session ID context
394 * Verify_result [ 5 ] EXPLICIT INTEGER, -- X509_V_... code for `Peer'
395 * HostName [ 6 ] EXPLICIT OCTET STRING, -- optional HostName from servername TLS extension
396 * PSK_identity_hint [ 7 ] EXPLICIT OCTET STRING, -- optional PSK identity hint
397 * PSK_identity [ 8 ] EXPLICIT OCTET STRING, -- optional PSK identity
398 * Ticket_lifetime_hint [9] EXPLICIT INTEGER, -- server's lifetime hint for session ticket
399 * Ticket [10] EXPLICIT OCTET STRING, -- session ticket (clients only)
400 * Compression_meth [11] EXPLICIT OCTET STRING, -- optional compression method
401 * SRP_username [ 12 ] EXPLICIT OCTET STRING -- optional SRP username
402 * }
403 * Look in ssl/ssl_asn1.c for more details
404 * I'm using EXPLICIT tags so I can read the damn things using asn1parse :-).
405 */
406struct ssl_session_st {
407 int ssl_version; /* what ssl version session info is
408 * being kept in here? */
409
410 size_t master_key_length;
411 unsigned char master_key[SSL_MAX_MASTER_KEY_LENGTH];
412
413 /* session_id - valid? */
414 size_t session_id_length;
415 unsigned char session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
416
417 /* this is used to determine whether the session is being reused in
418 * the appropriate context. It is up to the application to set this,
419 * via SSL_new */
420 size_t sid_ctx_length;
421 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
422
423 /* Peer provided leaf (end-entity) certificate. */
424 X509 *peer_cert;
425 int peer_cert_type;
426
427 /* when app_verify_callback accepts a session where the peer's certificate
428 * is not ok, we must remember the error for session reuse: */
429 long verify_result; /* only for servers */
430
431 long timeout;
432 time_t time;
433 int references;
434
435 uint16_t cipher_value;
436
437 char *tlsext_hostname;
438
439 /* Session resumption - RFC 5077 and RFC 8446. */
440 unsigned char *tlsext_tick; /* Session ticket */
441 size_t tlsext_ticklen; /* Session ticket length */
442 uint32_t tlsext_tick_lifetime_hint; /* Session lifetime hint in seconds */
443 uint32_t tlsext_tick_age_add; /* TLSv1.3 ticket age obfuscation (in ms) */
444 struct tls13_secret resumption_master_secret;
445
446 CRYPTO_EX_DATA ex_data; /* application specific data */
447
448 /* These are used to make removal of session-ids more
449 * efficient and to implement a maximum cache size. */
450 struct ssl_session_st *prev, *next;
451
452 /* Used to indicate that session resumption is not allowed.
453 * Applications can also set this bit for a new session via
454 * not_resumable_session_cb to disable session caching and tickets. */
455 int not_resumable;
456
457 size_t tlsext_ecpointformatlist_length;
458 uint8_t *tlsext_ecpointformatlist; /* peer's list */
459 size_t tlsext_supportedgroups_length;
460 uint16_t *tlsext_supportedgroups; /* peer's list */
461};
462
463struct ssl_sigalg;
464
465typedef struct ssl_handshake_tls12_st {
466 /* Used when SSL_ST_FLUSH_DATA is entered. */
467 int next_state;
468
469 /* Handshake message type and size. */
470 int message_type;
471 unsigned long message_size;
472
473 /* Reuse current handshake message. */
474 int reuse_message;
475
476 /* Client certificate requests. */
477 int cert_request;
478 STACK_OF(X509_NAME) *ca_names;
479
480 /* Record-layer key block for TLS 1.2 and earlier. */
481 struct tls12_key_block *key_block;
482
483 /* Transcript hash prior to sending certificate verify message. */
484 uint8_t cert_verify[EVP_MAX_MD_SIZE];
485} SSL_HANDSHAKE_TLS12;
486
487typedef struct ssl_handshake_tls13_st {
488 int use_legacy;
489 int hrr;
490
491 /* Client indicates psk_dhe_ke support in PskKeyExchangeMode. */
492 int use_psk_dhe_ke;
493
494 /* Certificate selected for use (static pointer). */
495 const SSL_CERT_PKEY *cpk;
496
497 /* Version proposed by peer server. */
498 uint16_t server_version;
499
500 uint16_t server_group;
501 struct tls13_secrets *secrets;
502
503 uint8_t *cookie;
504 size_t cookie_len;
505
506 /* Preserved transcript hash. */
507 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
508 size_t transcript_hash_len;
509
510 /* Legacy session ID. */
511 uint8_t legacy_session_id[SSL_MAX_SSL_SESSION_ID_LENGTH];
512 size_t legacy_session_id_len;
513
514 /* ClientHello hash, used to validate following HelloRetryRequest */
515 EVP_MD_CTX *clienthello_md_ctx;
516 unsigned char *clienthello_hash;
517 unsigned int clienthello_hash_len;
518
519 /* QUIC read buffer and read/write encryption levels. */
520 struct tls_buffer *quic_read_buffer;
521 enum ssl_encryption_level_t quic_read_level;
522 enum ssl_encryption_level_t quic_write_level;
523} SSL_HANDSHAKE_TLS13;
524
525typedef struct ssl_handshake_st {
526 /*
527 * Minimum and maximum versions supported for this handshake. These are
528 * initialised at the start of a handshake based on the method in use
529 * and the current protocol version configuration.
530 */
531 uint16_t our_min_tls_version;
532 uint16_t our_max_tls_version;
533
534 /*
535 * Version negotiated for this session. For a client this is set once
536 * the server selected version is parsed from the ServerHello (either
537 * from the legacy version or supported versions extension). For a
538 * server this is set once we select the version we will use with the
539 * client.
540 */
541 uint16_t negotiated_tls_version;
542
543 /*
544 * Legacy version advertised by our peer. For a server this is the
545 * version specified by the client in the ClientHello message. For a
546 * client, this is the version provided in the ServerHello message.
547 */
548 uint16_t peer_legacy_version;
549
550 /*
551 * Current handshake state - contains one of the SSL3_ST_* values and
552 * is used by the TLSv1.2 state machine, as well as being updated by
553 * the TLSv1.3 stack due to it being exposed externally.
554 */
555 int state;
556
557 /* Cipher being negotiated in this handshake. */
558 const SSL_CIPHER *cipher;
559
560 /* Ciphers sent by the client. */
561 STACK_OF(SSL_CIPHER) *client_ciphers;
562
563 /* Extensions seen in this handshake. */
564 uint32_t extensions_seen;
565
566 /* Extensions processed in this handshake. */
567 uint32_t extensions_processed;
568
569 /* Signature algorithms selected for use (static pointers). */
570 const struct ssl_sigalg *our_sigalg;
571 const struct ssl_sigalg *peer_sigalg;
572
573 /* sigalgs offered in this handshake in wire form */
574 uint8_t *sigalgs;
575 size_t sigalgs_len;
576
577 /* Key share for ephemeral key exchange. */
578 struct tls_key_share *key_share;
579
580 /*
581 * Copies of the verify data sent in our finished message and the
582 * verify data received in the finished message sent by our peer.
583 */
584 uint8_t finished[EVP_MAX_MD_SIZE];
585 size_t finished_len;
586 uint8_t peer_finished[EVP_MAX_MD_SIZE];
587 size_t peer_finished_len;
588
589 /* List of certificates received from our peer. */
590 STACK_OF(X509) *peer_certs;
591 STACK_OF(X509) *peer_certs_no_leaf;
592
593 /* Certificate chain resulting from X.509 verification. */
594 STACK_OF(X509) *verified_chain;
595
596 SSL_HANDSHAKE_TLS12 tls12;
597 SSL_HANDSHAKE_TLS13 tls13;
598} SSL_HANDSHAKE;
599
600typedef struct tls_session_ticket_ext_st TLS_SESSION_TICKET_EXT;
601
602/* TLS Session Ticket extension struct. */
603struct tls_session_ticket_ext_st {
604 unsigned short length;
605 void *data;
606};
607
608struct tls12_key_block;
609
610struct tls12_key_block *tls12_key_block_new(void);
611void tls12_key_block_free(struct tls12_key_block *kb);
612void tls12_key_block_client_write(struct tls12_key_block *kb, CBS *mac_key,
613 CBS *key, CBS *iv);
614void tls12_key_block_server_write(struct tls12_key_block *kb, CBS *mac_key,
615 CBS *key, CBS *iv);
616int tls12_key_block_generate(struct tls12_key_block *kb, SSL *s,
617 const EVP_AEAD *aead, const EVP_CIPHER *cipher, const EVP_MD *mac_hash);
618
619struct tls12_record_layer;
620
621struct tls12_record_layer *tls12_record_layer_new(void);
622void tls12_record_layer_free(struct tls12_record_layer *rl);
623void tls12_record_layer_alert(struct tls12_record_layer *rl,
624 uint8_t *alert_desc);
625int tls12_record_layer_write_overhead(struct tls12_record_layer *rl,
626 size_t *overhead);
627int tls12_record_layer_read_protected(struct tls12_record_layer *rl);
628int tls12_record_layer_write_protected(struct tls12_record_layer *rl);
629void tls12_record_layer_set_aead(struct tls12_record_layer *rl,
630 const EVP_AEAD *aead);
631void tls12_record_layer_set_cipher_hash(struct tls12_record_layer *rl,
632 const EVP_CIPHER *cipher, const EVP_MD *handshake_hash,
633 const EVP_MD *mac_hash);
634void tls12_record_layer_set_version(struct tls12_record_layer *rl,
635 uint16_t version);
636void tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl,
637 uint16_t epoch);
638uint16_t tls12_record_layer_read_epoch(struct tls12_record_layer *rl);
639uint16_t tls12_record_layer_write_epoch(struct tls12_record_layer *rl);
640int tls12_record_layer_use_write_epoch(struct tls12_record_layer *rl,
641 uint16_t epoch);
642void tls12_record_layer_write_epoch_done(struct tls12_record_layer *rl,
643 uint16_t epoch);
644void tls12_record_layer_clear_read_state(struct tls12_record_layer *rl);
645void tls12_record_layer_clear_write_state(struct tls12_record_layer *rl);
646void tls12_record_layer_reflect_seq_num(struct tls12_record_layer *rl);
647int tls12_record_layer_change_read_cipher_state(struct tls12_record_layer *rl,
648 CBS *mac_key, CBS *key, CBS *iv);
649int tls12_record_layer_change_write_cipher_state(struct tls12_record_layer *rl,
650 CBS *mac_key, CBS *key, CBS *iv);
651int tls12_record_layer_open_record(struct tls12_record_layer *rl,
652 uint8_t *buf, size_t buf_len, struct tls_content *out);
653int tls12_record_layer_seal_record(struct tls12_record_layer *rl,
654 uint8_t content_type, const uint8_t *content, size_t content_len,
655 CBB *out);
656
657typedef void (ssl_info_callback_fn)(const SSL *s, int type, int val);
658typedef void (ssl_msg_callback_fn)(int is_write, int version, int content_type,
659 const void *buf, size_t len, SSL *ssl, void *arg);
660
661struct ssl_ctx_st {
662 const SSL_METHOD *method;
663 const SSL_QUIC_METHOD *quic_method;
664
665 STACK_OF(SSL_CIPHER) *cipher_list;
666
667 struct x509_store_st /* X509_STORE */ *cert_store;
668
669 /* If timeout is not 0, it is the default timeout value set
670 * when SSL_new() is called. This has been put in to make
671 * life easier to set things up */
672 long session_timeout;
673
674 int references;
675
676 /* Default values to use in SSL structures follow (these are copied by SSL_new) */
677
678 STACK_OF(X509) *extra_certs;
679
680 int verify_mode;
681 size_t sid_ctx_length;
682 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
683
684 X509_VERIFY_PARAM *param;
685
686 /*
687 * XXX
688 * default_passwd_cb used by python and openvpn, need to keep it until we
689 * add an accessor
690 */
691 /* Default password callback. */
692 pem_password_cb *default_passwd_callback;
693
694 /* Default password callback user data. */
695 void *default_passwd_callback_userdata;
696
697 uint16_t min_tls_version;
698 uint16_t max_tls_version;
699
700 /*
701 * These may be zero to imply minimum or maximum version supported by
702 * the method.
703 */
704 uint16_t min_proto_version;
705 uint16_t max_proto_version;
706
707 unsigned long options;
708 unsigned long mode;
709
710 /* If this callback is not null, it will be called each
711 * time a session id is added to the cache. If this function
712 * returns 1, it means that the callback will do a
713 * SSL_SESSION_free() when it has finished using it. Otherwise,
714 * on 0, it means the callback has finished with it.
715 * If remove_session_cb is not null, it will be called when
716 * a session-id is removed from the cache. After the call,
717 * OpenSSL will SSL_SESSION_free() it. */
718 int (*new_session_cb)(struct ssl_st *ssl, SSL_SESSION *sess);
719 void (*remove_session_cb)(struct ssl_ctx_st *ctx, SSL_SESSION *sess);
720 SSL_SESSION *(*get_session_cb)(struct ssl_st *ssl,
721 const unsigned char *data, int len, int *copy);
722
723 /* if defined, these override the X509_verify_cert() calls */
724 int (*app_verify_callback)(X509_STORE_CTX *, void *);
725 void *app_verify_arg;
726
727 /* get client cert callback */
728 int (*client_cert_cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey);
729
730 /* cookie generate callback */
731 int (*app_gen_cookie_cb)(SSL *ssl, unsigned char *cookie,
732 unsigned int *cookie_len);
733
734 /* verify cookie callback */
735 int (*app_verify_cookie_cb)(SSL *ssl, const unsigned char *cookie,
736 unsigned int cookie_len);
737
738 ssl_info_callback_fn *info_callback;
739
740 /* callback that allows applications to peek at protocol messages */
741 ssl_msg_callback_fn *msg_callback;
742 void *msg_callback_arg;
743
744 int (*default_verify_callback)(int ok,X509_STORE_CTX *ctx); /* called 'verify_callback' in the SSL */
745
746 /* Default generate session ID callback. */
747 GEN_SESSION_CB generate_session_id;
748
749 /* TLS extensions servername callback */
750 int (*tlsext_servername_callback)(SSL*, int *, void *);
751 void *tlsext_servername_arg;
752
753 /* Callback to support customisation of ticket key setting */
754 int (*tlsext_ticket_key_cb)(SSL *ssl, unsigned char *name,
755 unsigned char *iv, EVP_CIPHER_CTX *ectx, HMAC_CTX *hctx, int enc);
756
757 /* certificate status request info */
758 /* Callback for status request */
759 int (*tlsext_status_cb)(SSL *ssl, void *arg);
760 void *tlsext_status_arg;
761
762 struct lhash_st_SSL_SESSION *sessions;
763
764 /* Most session-ids that will be cached, default is
765 * SSL_SESSION_CACHE_MAX_SIZE_DEFAULT. 0 is unlimited. */
766 unsigned long session_cache_size;
767 struct ssl_session_st *session_cache_head;
768 struct ssl_session_st *session_cache_tail;
769
770 /* This can have one of 2 values, ored together,
771 * SSL_SESS_CACHE_CLIENT,
772 * SSL_SESS_CACHE_SERVER,
773 * Default is SSL_SESSION_CACHE_SERVER, which means only
774 * SSL_accept which cache SSL_SESSIONS. */
775 int session_cache_mode;
776
777 struct {
778 int sess_connect; /* SSL new conn - started */
779 int sess_connect_renegotiate;/* SSL reneg - requested */
780 int sess_connect_good; /* SSL new conne/reneg - finished */
781 int sess_accept; /* SSL new accept - started */
782 int sess_accept_renegotiate;/* SSL reneg - requested */
783 int sess_accept_good; /* SSL accept/reneg - finished */
784 int sess_miss; /* session lookup misses */
785 int sess_timeout; /* reuse attempt on timeouted session */
786 int sess_cache_full; /* session removed due to full cache */
787 int sess_hit; /* session reuse actually done */
788 int sess_cb_hit; /* session-id that was not
789 * in the cache was
790 * passed back via the callback. This
791 * indicates that the application is
792 * supplying session-id's from other
793 * processes - spooky :-) */
794 } stats;
795
796 CRYPTO_EX_DATA ex_data;
797
798 STACK_OF(SSL_CIPHER) *cipher_list_tls13;
799
800 SSL_CERT *cert;
801
802 /* Default values used when no per-SSL value is defined follow */
803
804 /* what we put in client cert requests */
805 STACK_OF(X509_NAME) *client_CA;
806
807 long max_cert_list;
808
809 int read_ahead;
810
811 int quiet_shutdown;
812
813 /* Maximum amount of data to send in one fragment.
814 * actual record size can be more than this due to
815 * padding and MAC overheads.
816 */
817 unsigned int max_send_fragment;
818
819 /* RFC 4507 session ticket keys */
820 unsigned char tlsext_tick_key_name[16];
821 unsigned char tlsext_tick_hmac_key[16];
822 unsigned char tlsext_tick_aes_key[16];
823
824 /* SRTP profiles we are willing to do from RFC 5764 */
825 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles;
826
827 /*
828 * ALPN information.
829 */
830
831 /*
832 * Server callback function that allows the server to select the
833 * protocol for the connection.
834 * out: on successful return, this must point to the raw protocol
835 * name (without the length prefix).
836 * outlen: on successful return, this contains the length of out.
837 * in: points to the client's list of supported protocols in
838 * wire-format.
839 * inlen: the length of in.
840 */
841 int (*alpn_select_cb)(SSL *s, const unsigned char **out,
842 unsigned char *outlen, const unsigned char *in, unsigned int inlen,
843 void *arg);
844 void *alpn_select_cb_arg;
845
846 /* Client list of supported protocols in wire format. */
847 uint8_t *alpn_client_proto_list;
848 size_t alpn_client_proto_list_len;
849
850 size_t tlsext_ecpointformatlist_length;
851 uint8_t *tlsext_ecpointformatlist; /* our list */
852 size_t tlsext_supportedgroups_length;
853 uint16_t *tlsext_supportedgroups; /* our list */
854 SSL_CTX_keylog_cb_func keylog_callback; /* Unused. For OpenSSL compatibility. */
855 size_t num_tickets; /* Unused, for OpenSSL compatibility */
856};
857
858struct ssl_st {
859 /* protocol version
860 * (one of SSL2_VERSION, SSL3_VERSION, TLS1_VERSION, DTLS1_VERSION)
861 */
862 int version;
863
864 const SSL_METHOD *method;
865 const SSL_QUIC_METHOD *quic_method;
866
867 /* There are 2 BIO's even though they are normally both the
868 * same. This is so data can be read and written to different
869 * handlers */
870
871 BIO *rbio; /* used by SSL_read */
872 BIO *wbio; /* used by SSL_write */
873 BIO *bbio; /* used during session-id reuse to concatenate
874 * messages */
875 int server; /* are we the server side? - mostly used by SSL_clear*/
876
877 struct ssl3_state_st *s3; /* SSLv3 variables */
878 struct dtls1_state_st *d1; /* DTLSv1 variables */
879
880 X509_VERIFY_PARAM *param;
881
882 /* crypto */
883 STACK_OF(SSL_CIPHER) *cipher_list;
884
885 /* This is used to hold the server certificate used */
886 SSL_CERT *cert;
887
888 /* the session_id_context is used to ensure sessions are only reused
889 * in the appropriate context */
890 size_t sid_ctx_length;
891 unsigned char sid_ctx[SSL_MAX_SID_CTX_LENGTH];
892
893 /* This can also be in the session once a session is established */
894 SSL_SESSION *session;
895
896 /* Used in SSL2 and SSL3 */
897 int verify_mode; /* 0 don't care about verify failure.
898 * 1 fail if verify fails */
899 int error; /* error bytes to be written */
900 int error_code; /* actual code */
901
902 SSL_CTX *ctx;
903
904 long verify_result;
905
906 int references;
907
908 int client_version; /* what was passed, used for
909 * SSLv3/TLS rollback check */
910
911 unsigned int max_send_fragment;
912
913 const struct tls_extension **tlsext_build_order;
914 size_t tlsext_build_order_len;
915
916 char *tlsext_hostname;
917
918 /* certificate status request info */
919 /* Status type or -1 if no status type */
920 int tlsext_status_type;
921
922 SSL_CTX * initial_ctx; /* initial ctx, used to store sessions */
923#define session_ctx initial_ctx
924
925 struct tls13_ctx *tls13;
926
927 uint16_t min_tls_version;
928 uint16_t max_tls_version;
929
930 /*
931 * These may be zero to imply minimum or maximum version supported by
932 * the method.
933 */
934 uint16_t min_proto_version;
935 uint16_t max_proto_version;
936
937 unsigned long options; /* protocol behaviour */
938 unsigned long mode; /* API behaviour */
939
940 /* Client list of supported protocols in wire format. */
941 uint8_t *alpn_client_proto_list;
942 size_t alpn_client_proto_list_len;
943
944 /* QUIC transport params we will send */
945 uint8_t *quic_transport_params;
946 size_t quic_transport_params_len;
947
948 /* XXX Callbacks */
949
950 /* true when we are actually in SSL_accept() or SSL_connect() */
951 int in_handshake;
952 int (*handshake_func)(SSL *);
953
954 ssl_info_callback_fn *info_callback;
955
956 /* callback that allows applications to peek at protocol messages */
957 ssl_msg_callback_fn *msg_callback;
958 void *msg_callback_arg;
959
960 int (*verify_callback)(int ok,X509_STORE_CTX *ctx); /* fail if callback returns 0 */
961
962 /* Default generate session ID callback. */
963 GEN_SESSION_CB generate_session_id;
964
965 /* TLS extension debug callback */
966 void (*tlsext_debug_cb)(SSL *s, int client_server, int type,
967 unsigned char *data, int len, void *arg);
968 void *tlsext_debug_arg;
969
970 /* TLS Session Ticket extension callback */
971 tls_session_ticket_ext_cb_fn tls_session_ticket_ext_cb;
972 void *tls_session_ticket_ext_cb_arg;
973
974 /* TLS pre-shared secret session resumption */
975 tls_session_secret_cb_fn tls_session_secret_cb;
976 void *tls_session_secret_cb_arg;
977
978 /* XXX non-callback */
979
980 /* This holds a variable that indicates what we were doing
981 * when a 0 or -1 is returned. This is needed for
982 * non-blocking IO so we know what request needs re-doing when
983 * in SSL_accept or SSL_connect */
984 int rwstate;
985
986 /* Imagine that here's a boolean member "init" that is
987 * switched as soon as SSL_set_{accept/connect}_state
988 * is called for the first time, so that "state" and
989 * "handshake_func" are properly initialized. But as
990 * handshake_func is == 0 until then, we use this
991 * test instead of an "init" member.
992 */
993
994 int new_session;/* Generate a new session or reuse an old one.
995 * NB: For servers, the 'new' session may actually be a previously
996 * cached session or even the previous session unless
997 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION is set */
998 int quiet_shutdown;/* don't send shutdown packets */
999 int shutdown; /* we have shut things down, 0x01 sent, 0x02
1000 * for received */
1001 BUF_MEM *init_buf; /* buffer used during init */
1002 void *init_msg; /* pointer to handshake message body, set by ssl3_get_message() */
1003 int init_num; /* amount read/written */
1004 int init_off; /* amount read/written */
1005
1006 /* used internally to point at a raw packet */
1007 unsigned char *packet;
1008 unsigned int packet_length;
1009
1010 int read_ahead; /* Read as many input bytes as possible
1011 * (for non-blocking reads) */
1012
1013 int hit; /* reusing a previous session */
1014
1015 STACK_OF(SSL_CIPHER) *cipher_list_tls13;
1016
1017 struct tls12_record_layer *rl;
1018
1019 /* session info */
1020
1021 /* extra application data */
1022 CRYPTO_EX_DATA ex_data;
1023
1024 /* client cert? */
1025 /* for server side, keep the list of CA_dn we can use */
1026 STACK_OF(X509_NAME) *client_CA;
1027
1028 long max_cert_list;
1029 int first_packet;
1030
1031 /* Expect OCSP CertificateStatus message */
1032 int tlsext_status_expected;
1033 /* OCSP status request only */
1034 STACK_OF(OCSP_RESPID) *tlsext_ocsp_ids;
1035 X509_EXTENSIONS *tlsext_ocsp_exts;
1036
1037 /* OCSP response received or to be sent */
1038 unsigned char *tlsext_ocsp_resp;
1039 size_t tlsext_ocsp_resp_len;
1040
1041 /* RFC4507 session ticket expected to be received or sent */
1042 int tlsext_ticket_expected;
1043
1044 size_t tlsext_ecpointformatlist_length;
1045 uint8_t *tlsext_ecpointformatlist; /* our list */
1046 size_t tlsext_supportedgroups_length;
1047 uint16_t *tlsext_supportedgroups; /* our list */
1048
1049 /* TLS Session Ticket extension override */
1050 TLS_SESSION_TICKET_EXT *tlsext_session_ticket;
1051
1052 STACK_OF(SRTP_PROTECTION_PROFILE) *srtp_profiles; /* What we'll do */
1053 const SRTP_PROTECTION_PROFILE *srtp_profile; /* What's been chosen */
1054
1055 int renegotiate;/* 1 if we are renegotiating.
1056 * 2 if we are a server and are inside a handshake
1057 * (i.e. not just sending a HelloRequest) */
1058
1059 int rstate; /* where we are when reading */
1060
1061 int mac_packet;
1062
1063 int empty_record_count;
1064
1065 size_t num_tickets; /* Unused, for OpenSSL compatibility */
1066};
1067
1068typedef struct ssl3_record_internal_st {
1069 int type; /* type of record */
1070 unsigned int length; /* How many bytes available */
1071 unsigned int padding_length; /* Number of padding bytes. */
1072 unsigned int off; /* read/write offset into 'buf' */
1073 unsigned char *data; /* pointer to the record data */
1074 unsigned char *input; /* where the decode bytes are */
1075 uint16_t epoch; /* epoch number, needed by DTLS1 */
1076 unsigned char seq_num[8]; /* sequence number, needed by DTLS1 */
1077} SSL3_RECORD_INTERNAL;
1078
1079typedef struct ssl3_buffer_internal_st {
1080 unsigned char *buf; /* at least SSL3_RT_MAX_PACKET_SIZE bytes,
1081 * see ssl3_setup_buffers() */
1082 size_t len; /* buffer size */
1083 int offset; /* where to 'copy from' */
1084 int left; /* how many bytes left */
1085} SSL3_BUFFER_INTERNAL;
1086
1087typedef struct ssl3_state_st {
1088 long flags;
1089
1090 unsigned char server_random[SSL3_RANDOM_SIZE];
1091 unsigned char client_random[SSL3_RANDOM_SIZE];
1092
1093 SSL3_BUFFER_INTERNAL rbuf; /* read IO goes into here */
1094 SSL3_BUFFER_INTERNAL wbuf; /* write IO goes into here */
1095
1096 SSL3_RECORD_INTERNAL rrec; /* each decoded record goes in here */
1097
1098 struct tls_content *rcontent; /* Content from opened TLS records. */
1099
1100 /* we allow one fatal and one warning alert to be outstanding,
1101 * send close alert via the warning alert */
1102 int alert_dispatch;
1103 unsigned char send_alert[2];
1104
1105 /* flags for countermeasure against known-IV weakness */
1106 int need_empty_fragments;
1107 int empty_fragment_done;
1108
1109 /* Unprocessed Alert/Handshake protocol data. */
1110 struct tls_buffer *alert_fragment;
1111 struct tls_buffer *handshake_fragment;
1112
1113 /* partial write - check the numbers match */
1114 unsigned int wnum; /* number of bytes sent so far */
1115 int wpend_tot; /* number bytes written */
1116 int wpend_type;
1117 int wpend_ret; /* number of bytes submitted */
1118 const unsigned char *wpend_buf;
1119
1120 /* Transcript of handshake messages that have been sent and received. */
1121 struct tls_buffer *handshake_transcript;
1122
1123 /* Rolling hash of handshake messages. */
1124 EVP_MD_CTX *handshake_hash;
1125
1126 /* this is set whenerver we see a change_cipher_spec message
1127 * come in when we are not looking for one */
1128 int change_cipher_spec;
1129
1130 int warn_alert;
1131 int fatal_alert;
1132
1133 /* This flag is set when we should renegotiate ASAP, basically when
1134 * there is no more data in the read or write buffers */
1135 int renegotiate;
1136 int total_renegotiations;
1137 int num_renegotiations;
1138
1139 int in_read_app_data;
1140
1141 SSL_HANDSHAKE hs;
1142
1143 /* Connection binding to prevent renegotiation attacks */
1144 unsigned char previous_client_finished[EVP_MAX_MD_SIZE];
1145 unsigned char previous_client_finished_len;
1146 unsigned char previous_server_finished[EVP_MAX_MD_SIZE];
1147 unsigned char previous_server_finished_len;
1148 int send_connection_binding; /* TODOEKR */
1149
1150 /* Set if we saw a Renegotiation Indication extension from our peer. */
1151 int renegotiate_seen;
1152
1153 /*
1154 * ALPN information.
1155 *
1156 * In a server these point to the selected ALPN protocol after the
1157 * ClientHello has been processed. In a client these contain the
1158 * protocol that the server selected once the ServerHello has been
1159 * processed.
1160 */
1161 uint8_t *alpn_selected;
1162 size_t alpn_selected_len;
1163
1164 /* Contains the QUIC transport params received from our peer. */
1165 uint8_t *peer_quic_transport_params;
1166 size_t peer_quic_transport_params_len;
1167} SSL3_STATE;
1168
1169/*
1170 * Flag values for enc_flags.
1171 */
1172
1173/* Uses signature algorithms extension. */
1174#define SSL_ENC_FLAG_SIGALGS (1 << 1)
1175
1176/* Allow TLS 1.2 ciphersuites: applies to DTLS 1.2 as well as TLS 1.2. */
1177#define SSL_ENC_FLAG_TLS1_2_CIPHERS (1 << 4)
1178
1179/* Allow TLS 1.3 ciphersuites only. */
1180#define SSL_ENC_FLAG_TLS1_3_CIPHERS (1 << 5)
1181
1182#define TLSV1_ENC_FLAGS 0
1183#define TLSV1_1_ENC_FLAGS 0
1184#define TLSV1_2_ENC_FLAGS (SSL_ENC_FLAG_SIGALGS | \
1185 SSL_ENC_FLAG_TLS1_2_CIPHERS)
1186#define TLSV1_3_ENC_FLAGS (SSL_ENC_FLAG_SIGALGS | \
1187 SSL_ENC_FLAG_TLS1_3_CIPHERS)
1188
1189extern const SSL_CIPHER ssl3_ciphers[];
1190
1191const char *ssl_version_string(int ver);
1192int ssl_version_set_min(const SSL_METHOD *meth, uint16_t proto_ver,
1193 uint16_t max_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver);
1194int ssl_version_set_max(const SSL_METHOD *meth, uint16_t proto_ver,
1195 uint16_t min_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver);
1196int ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1197int ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver);
1198uint16_t ssl_tls_version(uint16_t version);
1199uint16_t ssl_effective_tls_version(SSL *s);
1200int ssl_max_supported_version(SSL *s, uint16_t *max_ver);
1201int ssl_max_legacy_version(SSL *s, uint16_t *max_ver);
1202int ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver);
1203int ssl_check_version_from_server(SSL *s, uint16_t server_version);
1204int ssl_legacy_stack_version(SSL *s, uint16_t version);
1205int ssl_cipher_in_list(STACK_OF(SSL_CIPHER) *ciphers, const SSL_CIPHER *cipher);
1206int ssl_cipher_allowed_in_tls_version_range(const SSL_CIPHER *cipher,
1207 uint16_t min_ver, uint16_t max_ver);
1208
1209const SSL_METHOD *tls_legacy_method(void);
1210const SSL_METHOD *ssl_get_method(uint16_t version);
1211
1212void ssl_clear_cipher_state(SSL *s);
1213int ssl_clear_bad_session(SSL *s);
1214
1215void ssl_info_callback(const SSL *s, int type, int value);
1216void ssl_msg_callback(SSL *s, int is_write, int content_type,
1217 const void *msg_buf, size_t msg_len);
1218void ssl_msg_callback_cbs(SSL *s, int is_write, int content_type, CBS *cbs);
1219
1220SSL_CERT *ssl_cert_new(void);
1221SSL_CERT *ssl_cert_dup(SSL_CERT *cert);
1222void ssl_cert_free(SSL_CERT *c);
1223SSL_CERT *ssl_get0_cert(SSL_CTX *ctx, SSL *ssl);
1224int ssl_cert_set0_chain(SSL_CTX *ctx, SSL *ssl, STACK_OF(X509) *chain);
1225int ssl_cert_set1_chain(SSL_CTX *ctx, SSL *ssl, STACK_OF(X509) *chain);
1226int ssl_cert_add0_chain_cert(SSL_CTX *ctx, SSL *ssl, X509 *cert);
1227int ssl_cert_add1_chain_cert(SSL_CTX *ctx, SSL *ssl, X509 *cert);
1228
1229int ssl_security_default_cb(const SSL *ssl, const SSL_CTX *ctx, int op,
1230 int bits, int nid, void *other, void *ex_data);
1231
1232int ssl_security_cipher_check(const SSL *ssl, SSL_CIPHER *cipher);
1233int ssl_security_shared_cipher(const SSL *ssl, SSL_CIPHER *cipher);
1234int ssl_security_supported_cipher(const SSL *ssl, SSL_CIPHER *cipher);
1235int ssl_ctx_security_dh(const SSL_CTX *ctx, DH *dh);
1236int ssl_security_dh(const SSL *ssl, DH *dh);
1237int ssl_security_sigalg_check(const SSL *ssl, const EVP_PKEY *pkey);
1238int ssl_security_tickets(const SSL *ssl);
1239int ssl_security_version(const SSL *ssl, int version);
1240int ssl_security_cert(const SSL_CTX *ctx, const SSL *ssl, X509 *x509,
1241 int is_peer, int *out_error);
1242int ssl_security_cert_chain(const SSL *ssl, STACK_OF(X509) *sk,
1243 X509 *x509, int *out_error);
1244int ssl_security_shared_group(const SSL *ssl, uint16_t group_id);
1245int ssl_security_supported_group(const SSL *ssl, uint16_t group_id);
1246
1247SSL_SESSION *ssl_session_dup(SSL_SESSION *src, int include_ticket);
1248int ssl_get_new_session(SSL *s, int session);
1249int ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block,
1250 int *alert);
1251int ssl_cipher_list_to_bytes(SSL *s, STACK_OF(SSL_CIPHER) *ciphers, CBB *cbb);
1252STACK_OF(SSL_CIPHER) *ssl_bytes_to_cipher_list(SSL *s, CBS *cbs);
1253STACK_OF(SSL_CIPHER) *ssl_create_cipher_list(const SSL_METHOD *meth,
1254 STACK_OF(SSL_CIPHER) **pref, STACK_OF(SSL_CIPHER) *tls13,
1255 const char *rule_str, SSL_CERT *cert);
1256int ssl_parse_ciphersuites(STACK_OF(SSL_CIPHER) **out_ciphers, const char *str);
1257int ssl_merge_cipherlists(STACK_OF(SSL_CIPHER) *cipherlist,
1258 STACK_OF(SSL_CIPHER) *cipherlist_tls13,
1259 STACK_OF(SSL_CIPHER) **out_cipherlist);
1260void ssl_update_cache(SSL *s, int mode);
1261int ssl_cipher_get_evp(SSL *s, const EVP_CIPHER **enc,
1262 const EVP_MD **md, int *mac_pkey_type, int *mac_secret_size);
1263int ssl_cipher_get_evp_aead(SSL *s, const EVP_AEAD **aead);
1264int ssl_get_handshake_evp_md(SSL *s, const EVP_MD **md);
1265
1266int ssl_verify_cert_chain(SSL *s, STACK_OF(X509) *sk);
1267int ssl_undefined_function(SSL *s);
1268int ssl_undefined_void_function(void);
1269int ssl_undefined_const_function(const SSL *s);
1270SSL_CERT_PKEY *ssl_get_server_send_pkey(const SSL *s);
1271EVP_PKEY *ssl_get_sign_pkey(SSL *s, const SSL_CIPHER *c, const EVP_MD **pmd,
1272 const struct ssl_sigalg **sap);
1273size_t ssl_dhe_params_auto_key_bits(SSL *s);
1274int ssl_cert_type(EVP_PKEY *pkey);
1275void ssl_set_cert_masks(SSL_CERT *c, const SSL_CIPHER *cipher);
1276STACK_OF(SSL_CIPHER) *ssl_get_ciphers_by_id(SSL *s);
1277int ssl_has_ecc_ciphers(SSL *s);
1278int ssl_verify_alarm_type(long type);
1279
1280int SSL_SESSION_ticket(SSL_SESSION *ss, unsigned char **out, size_t *out_len);
1281
1282int ssl3_do_write(SSL *s, int type);
1283int ssl3_send_alert(SSL *s, int level, int desc);
1284int ssl3_get_req_cert_types(SSL *s, CBB *cbb);
1285int ssl3_get_message(SSL *s, int st1, int stn, int mt, long max);
1286int ssl3_num_ciphers(void);
1287const SSL_CIPHER *ssl3_get_cipher_by_index(int idx);
1288const SSL_CIPHER *ssl3_get_cipher_by_value(uint16_t value);
1289int ssl3_renegotiate(SSL *ssl);
1290
1291int ssl3_renegotiate_check(SSL *ssl);
1292
1293void ssl_force_want_read(SSL *s);
1294
1295int ssl3_dispatch_alert(SSL *s);
1296int ssl3_read_alert(SSL *s);
1297int ssl3_read_change_cipher_spec(SSL *s);
1298int ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek);
1299int ssl3_write_bytes(SSL *s, int type, const void *buf, int len);
1300int ssl3_output_cert_chain(SSL *s, CBB *cbb, SSL_CERT_PKEY *cpk);
1301SSL_CIPHER *ssl3_choose_cipher(SSL *ssl, STACK_OF(SSL_CIPHER) *clnt,
1302 STACK_OF(SSL_CIPHER) *srvr);
1303int ssl3_setup_buffers(SSL *s);
1304int ssl3_setup_init_buffer(SSL *s);
1305void ssl3_release_init_buffer(SSL *s);
1306int ssl3_setup_read_buffer(SSL *s);
1307int ssl3_setup_write_buffer(SSL *s);
1308void ssl3_release_buffer(SSL3_BUFFER_INTERNAL *b);
1309void ssl3_release_read_buffer(SSL *s);
1310void ssl3_release_write_buffer(SSL *s);
1311int ssl3_new(SSL *s);
1312void ssl3_free(SSL *s);
1313int ssl3_accept(SSL *s);
1314int ssl3_connect(SSL *s);
1315int ssl3_read(SSL *s, void *buf, int len);
1316int ssl3_peek(SSL *s, void *buf, int len);
1317int ssl3_write(SSL *s, const void *buf, int len);
1318int ssl3_shutdown(SSL *s);
1319void ssl3_clear(SSL *s);
1320long ssl3_ctrl(SSL *s, int cmd, long larg, void *parg);
1321long ssl3_ctx_ctrl(SSL_CTX *s, int cmd, long larg, void *parg);
1322long ssl3_callback_ctrl(SSL *s, int cmd, void (*fp)(void));
1323long ssl3_ctx_callback_ctrl(SSL_CTX *s, int cmd, void (*fp)(void));
1324int ssl3_pending(const SSL *s);
1325
1326int ssl3_handshake_msg_hdr_len(SSL *s);
1327int ssl3_handshake_msg_start(SSL *s, CBB *handshake, CBB *body,
1328 uint8_t msg_type);
1329int ssl3_handshake_msg_finish(SSL *s, CBB *handshake);
1330int ssl3_handshake_write(SSL *s);
1331int ssl3_record_write(SSL *s, int type);
1332
1333int ssl3_do_change_cipher_spec(SSL *ssl);
1334
1335int ssl3_packet_read(SSL *s, int plen);
1336int ssl3_packet_extend(SSL *s, int plen);
1337int ssl_server_legacy_first_packet(SSL *s);
1338int ssl3_write_pending(SSL *s, int type, const unsigned char *buf,
1339 unsigned int len);
1340
1341int ssl_kex_generate_dhe(DH *dh, DH *dh_params);
1342int ssl_kex_generate_dhe_params_auto(DH *dh, size_t key_len);
1343int ssl_kex_params_dhe(DH *dh, CBB *cbb);
1344int ssl_kex_public_dhe(DH *dh, CBB *cbb);
1345int ssl_kex_peer_params_dhe(DH *dh, CBS *cbs, int *decode_error,
1346 int *invalid_params);
1347int ssl_kex_peer_public_dhe(DH *dh, CBS *cbs, int *decode_error,
1348 int *invalid_key);
1349int ssl_kex_derive_dhe(DH *dh, DH *dh_peer,
1350 uint8_t **shared_key, size_t *shared_key_len);
1351
1352int ssl_kex_dummy_ecdhe_x25519(EVP_PKEY *pkey);
1353int ssl_kex_generate_ecdhe_ecp(EC_KEY *ecdh, int nid);
1354int ssl_kex_public_ecdhe_ecp(EC_KEY *ecdh, CBB *cbb);
1355int ssl_kex_peer_public_ecdhe_ecp(EC_KEY *ecdh, int nid, CBS *cbs);
1356int ssl_kex_derive_ecdhe_ecp(EC_KEY *ecdh, EC_KEY *ecdh_peer,
1357 uint8_t **shared_key, size_t *shared_key_len);
1358
1359int tls1_new(SSL *s);
1360void tls1_free(SSL *s);
1361void tls1_clear(SSL *s);
1362
1363int ssl_init_wbio_buffer(SSL *s, int push);
1364void ssl_free_wbio_buffer(SSL *s);
1365
1366int tls1_transcript_hash_init(SSL *s);
1367int tls1_transcript_hash_update(SSL *s, const unsigned char *buf, size_t len);
1368int tls1_transcript_hash_value(SSL *s, unsigned char *out, size_t len,
1369 size_t *outlen);
1370void tls1_transcript_hash_free(SSL *s);
1371
1372int tls1_transcript_init(SSL *s);
1373void tls1_transcript_free(SSL *s);
1374void tls1_transcript_reset(SSL *s);
1375int tls1_transcript_append(SSL *s, const unsigned char *buf, size_t len);
1376int tls1_transcript_data(SSL *s, const unsigned char **data, size_t *len);
1377void tls1_transcript_freeze(SSL *s);
1378void tls1_transcript_unfreeze(SSL *s);
1379int tls1_transcript_record(SSL *s, const unsigned char *buf, size_t len);
1380
1381int tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len,
1382 const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len,
1383 const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len,
1384 const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len);
1385
1386void tls1_cleanup_key_block(SSL *s);
1387int tls1_change_read_cipher_state(SSL *s);
1388int tls1_change_write_cipher_state(SSL *s);
1389int tls1_setup_key_block(SSL *s);
1390int tls1_generate_key_block(SSL *s, uint8_t *key_block, size_t key_block_len);
1391int ssl_ok(SSL *s);
1392
1393int tls12_derive_finished(SSL *s);
1394int tls12_derive_peer_finished(SSL *s);
1395int tls12_derive_master_secret(SSL *s, uint8_t *premaster_secret,
1396 size_t premaster_secret_len);
1397
1398int ssl_using_ecc_cipher(SSL *s);
1399int ssl_check_srvr_ecc_cert_and_alg(SSL *s, X509 *x);
1400
1401void tls1_get_formatlist(const SSL *s, int client_formats,
1402 const uint8_t **pformats, size_t *pformatslen);
1403void tls1_get_group_list(const SSL *s, int client_groups,
1404 const uint16_t **pgroups, size_t *pgroupslen);
1405
1406int tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len,
1407 const int *groups, size_t ngroups);
1408int tls1_set_group_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
1409 const char *groups);
1410
1411int tls1_ec_group_id2nid(uint16_t group_id, int *out_nid);
1412int tls1_ec_group_id2bits(uint16_t group_id, int *out_bits);
1413int tls1_ec_nid2group_id(int nid, uint16_t *out_group_id);
1414int tls1_check_group(SSL *s, uint16_t group_id);
1415int tls1_count_shared_groups(const SSL *ssl, size_t *out_count);
1416int tls1_get_shared_group_by_index(const SSL *ssl, size_t index, int *out_nid);
1417int tls1_get_supported_group(const SSL *s, int *out_nid);
1418
1419int ssl_check_clienthello_tlsext_early(SSL *s);
1420int ssl_check_clienthello_tlsext_late(SSL *s);
1421int ssl_check_serverhello_tlsext(SSL *s);
1422
1423#define TLS1_TICKET_FATAL_ERROR -1
1424#define TLS1_TICKET_NONE 0
1425#define TLS1_TICKET_EMPTY 1
1426#define TLS1_TICKET_NOT_DECRYPTED 2
1427#define TLS1_TICKET_DECRYPTED 3
1428
1429int tls1_process_ticket(SSL *s, CBS *ext_block, int *alert, SSL_SESSION **ret);
1430
1431int tls1_check_ec_server_key(SSL *s);
1432
1433/* s3_cbc.c */
1434void ssl3_cbc_copy_mac(unsigned char *out, const SSL3_RECORD_INTERNAL *rec,
1435 unsigned int md_size, unsigned int orig_len);
1436int ssl3_cbc_remove_padding(SSL3_RECORD_INTERNAL *rec, unsigned int eiv_len,
1437 unsigned int mac_size);
1438char ssl3_cbc_record_digest_supported(const EVP_MD_CTX *ctx);
1439int ssl3_cbc_digest_record(const EVP_MD_CTX *ctx, unsigned char *md_out,
1440 size_t *md_out_size, const unsigned char header[13],
1441 const unsigned char *data, size_t data_plus_mac_size,
1442 size_t data_plus_mac_plus_padding_size, const unsigned char *mac_secret,
1443 unsigned int mac_secret_length);
1444int SSL_state_func_code(int _state);
1445
1446#define SSLerror(s, r) SSL_error_internal(s, r, OPENSSL_FILE, OPENSSL_LINE)
1447#define SSLerrorx(r) ERR_PUT_error(ERR_LIB_SSL,(0xfff),(r),OPENSSL_FILE,OPENSSL_LINE)
1448void SSL_error_internal(const SSL *s, int r, char *f, int l);
1449
1450#ifndef OPENSSL_NO_SRTP
1451
1452int srtp_find_profile_by_name(const char *profile_name,
1453 const SRTP_PROTECTION_PROFILE **pptr, unsigned int len);
1454int srtp_find_profile_by_num(unsigned int profile_num,
1455 const SRTP_PROTECTION_PROFILE **pptr);
1456
1457#endif /* OPENSSL_NO_SRTP */
1458
1459int tls_process_peer_certs(SSL *s, STACK_OF(X509) *peer_certs);
1460
1461__END_HIDDEN_DECLS
1462
1463#endif /* !HEADER_SSL_LOCL_H */
diff --git a/src/lib/libssl/ssl_methods.c b/src/lib/libssl/ssl_methods.c
deleted file mode 100644
index dee52decf1..0000000000
--- a/src/lib/libssl/ssl_methods.c
+++ /dev/null
@@ -1,554 +0,0 @@
1/* $OpenBSD: ssl_methods.c,v 1.32 2024/07/23 14:40:54 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "dtls_local.h"
60#include "ssl_local.h"
61#include "tls13_internal.h"
62
63static const SSL_METHOD DTLS_method_data = {
64 .dtls = 1,
65 .server = 1,
66 .version = DTLS1_2_VERSION,
67 .min_tls_version = TLS1_1_VERSION,
68 .max_tls_version = TLS1_2_VERSION,
69 .ssl_new = dtls1_new,
70 .ssl_clear = dtls1_clear,
71 .ssl_free = dtls1_free,
72 .ssl_accept = ssl3_accept,
73 .ssl_connect = ssl3_connect,
74 .ssl_shutdown = ssl3_shutdown,
75 .ssl_renegotiate = ssl3_renegotiate,
76 .ssl_renegotiate_check = ssl3_renegotiate_check,
77 .ssl_pending = ssl3_pending,
78 .ssl_read_bytes = dtls1_read_bytes,
79 .ssl_write_bytes = dtls1_write_app_data_bytes,
80 .enc_flags = TLSV1_2_ENC_FLAGS,
81};
82
83static const SSL_METHOD DTLS_client_method_data = {
84 .dtls = 1,
85 .server = 0,
86 .version = DTLS1_2_VERSION,
87 .min_tls_version = TLS1_1_VERSION,
88 .max_tls_version = TLS1_2_VERSION,
89 .ssl_new = dtls1_new,
90 .ssl_clear = dtls1_clear,
91 .ssl_free = dtls1_free,
92 .ssl_accept = ssl_undefined_function,
93 .ssl_connect = ssl3_connect,
94 .ssl_shutdown = ssl3_shutdown,
95 .ssl_renegotiate = ssl3_renegotiate,
96 .ssl_renegotiate_check = ssl3_renegotiate_check,
97 .ssl_pending = ssl3_pending,
98 .ssl_read_bytes = dtls1_read_bytes,
99 .ssl_write_bytes = dtls1_write_app_data_bytes,
100 .enc_flags = TLSV1_2_ENC_FLAGS,
101};
102
103static const SSL_METHOD DTLSv1_method_data = {
104 .dtls = 1,
105 .server = 1,
106 .version = DTLS1_VERSION,
107 .min_tls_version = TLS1_1_VERSION,
108 .max_tls_version = TLS1_1_VERSION,
109 .ssl_new = dtls1_new,
110 .ssl_clear = dtls1_clear,
111 .ssl_free = dtls1_free,
112 .ssl_accept = ssl3_accept,
113 .ssl_connect = ssl3_connect,
114 .ssl_shutdown = ssl3_shutdown,
115 .ssl_renegotiate = ssl3_renegotiate,
116 .ssl_renegotiate_check = ssl3_renegotiate_check,
117 .ssl_pending = ssl3_pending,
118 .ssl_read_bytes = dtls1_read_bytes,
119 .ssl_write_bytes = dtls1_write_app_data_bytes,
120 .enc_flags = TLSV1_1_ENC_FLAGS,
121};
122
123static const SSL_METHOD DTLSv1_client_method_data = {
124 .dtls = 1,
125 .server = 0,
126 .version = DTLS1_VERSION,
127 .min_tls_version = TLS1_1_VERSION,
128 .max_tls_version = TLS1_1_VERSION,
129 .ssl_new = dtls1_new,
130 .ssl_clear = dtls1_clear,
131 .ssl_free = dtls1_free,
132 .ssl_accept = ssl_undefined_function,
133 .ssl_connect = ssl3_connect,
134 .ssl_shutdown = ssl3_shutdown,
135 .ssl_renegotiate = ssl3_renegotiate,
136 .ssl_renegotiate_check = ssl3_renegotiate_check,
137 .ssl_pending = ssl3_pending,
138 .ssl_read_bytes = dtls1_read_bytes,
139 .ssl_write_bytes = dtls1_write_app_data_bytes,
140 .enc_flags = TLSV1_1_ENC_FLAGS,
141};
142
143static const SSL_METHOD DTLSv1_2_method_data = {
144 .dtls = 1,
145 .server = 1,
146 .version = DTLS1_2_VERSION,
147 .min_tls_version = TLS1_2_VERSION,
148 .max_tls_version = TLS1_2_VERSION,
149 .ssl_new = dtls1_new,
150 .ssl_clear = dtls1_clear,
151 .ssl_free = dtls1_free,
152 .ssl_accept = ssl3_accept,
153 .ssl_connect = ssl3_connect,
154 .ssl_shutdown = ssl3_shutdown,
155 .ssl_renegotiate = ssl3_renegotiate,
156 .ssl_renegotiate_check = ssl3_renegotiate_check,
157 .ssl_pending = ssl3_pending,
158 .ssl_read_bytes = dtls1_read_bytes,
159 .ssl_write_bytes = dtls1_write_app_data_bytes,
160 .enc_flags = TLSV1_2_ENC_FLAGS,
161};
162
163static const SSL_METHOD DTLSv1_2_client_method_data = {
164 .dtls = 1,
165 .server = 0,
166 .version = DTLS1_2_VERSION,
167 .min_tls_version = TLS1_2_VERSION,
168 .max_tls_version = TLS1_2_VERSION,
169 .ssl_new = dtls1_new,
170 .ssl_clear = dtls1_clear,
171 .ssl_free = dtls1_free,
172 .ssl_accept = ssl_undefined_function,
173 .ssl_connect = ssl3_connect,
174 .ssl_shutdown = ssl3_shutdown,
175 .ssl_renegotiate = ssl3_renegotiate,
176 .ssl_renegotiate_check = ssl3_renegotiate_check,
177 .ssl_pending = ssl3_pending,
178 .ssl_read_bytes = dtls1_read_bytes,
179 .ssl_write_bytes = dtls1_write_app_data_bytes,
180 .enc_flags = TLSV1_2_ENC_FLAGS,
181};
182
183const SSL_METHOD *
184DTLSv1_client_method(void)
185{
186 return &DTLSv1_client_method_data;
187}
188LSSL_ALIAS(DTLSv1_client_method);
189
190const SSL_METHOD *
191DTLSv1_method(void)
192{
193 return &DTLSv1_method_data;
194}
195LSSL_ALIAS(DTLSv1_method);
196
197const SSL_METHOD *
198DTLSv1_server_method(void)
199{
200 return &DTLSv1_method_data;
201}
202LSSL_ALIAS(DTLSv1_server_method);
203
204const SSL_METHOD *
205DTLSv1_2_client_method(void)
206{
207 return &DTLSv1_2_client_method_data;
208}
209LSSL_ALIAS(DTLSv1_2_client_method);
210
211const SSL_METHOD *
212DTLSv1_2_method(void)
213{
214 return &DTLSv1_2_method_data;
215}
216LSSL_ALIAS(DTLSv1_2_method);
217
218const SSL_METHOD *
219DTLSv1_2_server_method(void)
220{
221 return &DTLSv1_2_method_data;
222}
223LSSL_ALIAS(DTLSv1_2_server_method);
224
225const SSL_METHOD *
226DTLS_client_method(void)
227{
228 return &DTLS_client_method_data;
229}
230LSSL_ALIAS(DTLS_client_method);
231
232const SSL_METHOD *
233DTLS_method(void)
234{
235 return &DTLS_method_data;
236}
237LSSL_ALIAS(DTLS_method);
238
239const SSL_METHOD *
240DTLS_server_method(void)
241{
242 return &DTLS_method_data;
243}
244LSSL_ALIAS(DTLS_server_method);
245
246static const SSL_METHOD TLS_method_data = {
247 .dtls = 0,
248 .server = 1,
249 .version = TLS1_3_VERSION,
250 .min_tls_version = TLS1_VERSION,
251 .max_tls_version = TLS1_3_VERSION,
252 .ssl_new = tls1_new,
253 .ssl_clear = tls1_clear,
254 .ssl_free = tls1_free,
255 .ssl_accept = tls13_legacy_accept,
256 .ssl_connect = tls13_legacy_connect,
257 .ssl_shutdown = tls13_legacy_shutdown,
258 .ssl_renegotiate = ssl_undefined_function,
259 .ssl_renegotiate_check = ssl_ok,
260 .ssl_pending = tls13_legacy_pending,
261 .ssl_read_bytes = tls13_legacy_read_bytes,
262 .ssl_write_bytes = tls13_legacy_write_bytes,
263 .enc_flags = TLSV1_3_ENC_FLAGS,
264};
265
266static const SSL_METHOD TLS_legacy_method_data = {
267 .dtls = 0,
268 .server = 1,
269 .version = TLS1_2_VERSION,
270 .min_tls_version = TLS1_VERSION,
271 .max_tls_version = TLS1_2_VERSION,
272 .ssl_new = tls1_new,
273 .ssl_clear = tls1_clear,
274 .ssl_free = tls1_free,
275 .ssl_accept = ssl3_accept,
276 .ssl_connect = ssl3_connect,
277 .ssl_shutdown = ssl3_shutdown,
278 .ssl_renegotiate = ssl_undefined_function,
279 .ssl_renegotiate_check = ssl_ok,
280 .ssl_pending = ssl3_pending,
281 .ssl_read_bytes = ssl3_read_bytes,
282 .ssl_write_bytes = ssl3_write_bytes,
283 .enc_flags = TLSV1_2_ENC_FLAGS,
284};
285
286static const SSL_METHOD TLS_client_method_data = {
287 .dtls = 0,
288 .server = 0,
289 .version = TLS1_3_VERSION,
290 .min_tls_version = TLS1_VERSION,
291 .max_tls_version = TLS1_3_VERSION,
292 .ssl_new = tls1_new,
293 .ssl_clear = tls1_clear,
294 .ssl_free = tls1_free,
295 .ssl_accept = tls13_legacy_accept,
296 .ssl_connect = tls13_legacy_connect,
297 .ssl_shutdown = tls13_legacy_shutdown,
298 .ssl_renegotiate = ssl_undefined_function,
299 .ssl_renegotiate_check = ssl_ok,
300 .ssl_pending = tls13_legacy_pending,
301 .ssl_read_bytes = tls13_legacy_read_bytes,
302 .ssl_write_bytes = tls13_legacy_write_bytes,
303 .enc_flags = TLSV1_3_ENC_FLAGS,
304};
305
306static const SSL_METHOD TLSv1_method_data = {
307 .dtls = 0,
308 .server = 1,
309 .version = TLS1_VERSION,
310 .min_tls_version = TLS1_VERSION,
311 .max_tls_version = TLS1_VERSION,
312 .ssl_new = tls1_new,
313 .ssl_clear = tls1_clear,
314 .ssl_free = tls1_free,
315 .ssl_accept = ssl3_accept,
316 .ssl_connect = ssl3_connect,
317 .ssl_shutdown = ssl3_shutdown,
318 .ssl_renegotiate = ssl3_renegotiate,
319 .ssl_renegotiate_check = ssl3_renegotiate_check,
320 .ssl_pending = ssl3_pending,
321 .ssl_read_bytes = ssl3_read_bytes,
322 .ssl_write_bytes = ssl3_write_bytes,
323 .enc_flags = TLSV1_ENC_FLAGS,
324};
325
326static const SSL_METHOD TLSv1_client_method_data = {
327 .dtls = 0,
328 .server = 0,
329 .version = TLS1_VERSION,
330 .min_tls_version = TLS1_VERSION,
331 .max_tls_version = TLS1_VERSION,
332 .ssl_new = tls1_new,
333 .ssl_clear = tls1_clear,
334 .ssl_free = tls1_free,
335 .ssl_accept = ssl_undefined_function,
336 .ssl_connect = ssl3_connect,
337 .ssl_shutdown = ssl3_shutdown,
338 .ssl_renegotiate = ssl3_renegotiate,
339 .ssl_renegotiate_check = ssl3_renegotiate_check,
340 .ssl_pending = ssl3_pending,
341 .ssl_read_bytes = ssl3_read_bytes,
342 .ssl_write_bytes = ssl3_write_bytes,
343 .enc_flags = TLSV1_ENC_FLAGS,
344};
345
346static const SSL_METHOD TLSv1_1_method_data = {
347 .dtls = 0,
348 .server = 1,
349 .version = TLS1_1_VERSION,
350 .min_tls_version = TLS1_1_VERSION,
351 .max_tls_version = TLS1_1_VERSION,
352 .ssl_new = tls1_new,
353 .ssl_clear = tls1_clear,
354 .ssl_free = tls1_free,
355 .ssl_accept = ssl3_accept,
356 .ssl_connect = ssl3_connect,
357 .ssl_shutdown = ssl3_shutdown,
358 .ssl_renegotiate = ssl3_renegotiate,
359 .ssl_renegotiate_check = ssl3_renegotiate_check,
360 .ssl_pending = ssl3_pending,
361 .ssl_read_bytes = ssl3_read_bytes,
362 .ssl_write_bytes = ssl3_write_bytes,
363 .enc_flags = TLSV1_1_ENC_FLAGS,
364};
365
366static const SSL_METHOD TLSv1_1_client_method_data = {
367 .dtls = 0,
368 .server = 0,
369 .version = TLS1_1_VERSION,
370 .min_tls_version = TLS1_1_VERSION,
371 .max_tls_version = TLS1_1_VERSION,
372 .ssl_new = tls1_new,
373 .ssl_clear = tls1_clear,
374 .ssl_free = tls1_free,
375 .ssl_accept = ssl_undefined_function,
376 .ssl_connect = ssl3_connect,
377 .ssl_shutdown = ssl3_shutdown,
378 .ssl_renegotiate = ssl3_renegotiate,
379 .ssl_renegotiate_check = ssl3_renegotiate_check,
380 .ssl_pending = ssl3_pending,
381 .ssl_read_bytes = ssl3_read_bytes,
382 .ssl_write_bytes = ssl3_write_bytes,
383 .enc_flags = TLSV1_1_ENC_FLAGS,
384};
385
386static const SSL_METHOD TLSv1_2_method_data = {
387 .dtls = 0,
388 .server = 1,
389 .version = TLS1_2_VERSION,
390 .min_tls_version = TLS1_2_VERSION,
391 .max_tls_version = TLS1_2_VERSION,
392 .ssl_new = tls1_new,
393 .ssl_clear = tls1_clear,
394 .ssl_free = tls1_free,
395 .ssl_accept = ssl3_accept,
396 .ssl_connect = ssl3_connect,
397 .ssl_shutdown = ssl3_shutdown,
398 .ssl_renegotiate = ssl3_renegotiate,
399 .ssl_renegotiate_check = ssl3_renegotiate_check,
400 .ssl_pending = ssl3_pending,
401 .ssl_read_bytes = ssl3_read_bytes,
402 .ssl_write_bytes = ssl3_write_bytes,
403 .enc_flags = TLSV1_2_ENC_FLAGS,
404};
405
406static const SSL_METHOD TLSv1_2_client_method_data = {
407 .dtls = 0,
408 .server = 0,
409 .version = TLS1_2_VERSION,
410 .min_tls_version = TLS1_2_VERSION,
411 .max_tls_version = TLS1_2_VERSION,
412 .ssl_new = tls1_new,
413 .ssl_clear = tls1_clear,
414 .ssl_free = tls1_free,
415 .ssl_accept = ssl_undefined_function,
416 .ssl_connect = ssl3_connect,
417 .ssl_shutdown = ssl3_shutdown,
418 .ssl_renegotiate = ssl3_renegotiate,
419 .ssl_renegotiate_check = ssl3_renegotiate_check,
420 .ssl_pending = ssl3_pending,
421 .ssl_read_bytes = ssl3_read_bytes,
422 .ssl_write_bytes = ssl3_write_bytes,
423 .enc_flags = TLSV1_2_ENC_FLAGS,
424};
425
426const SSL_METHOD *
427TLS_client_method(void)
428{
429 return (&TLS_client_method_data);
430}
431LSSL_ALIAS(TLS_client_method);
432
433const SSL_METHOD *
434TLS_method(void)
435{
436 return (&TLS_method_data);
437}
438LSSL_ALIAS(TLS_method);
439
440const SSL_METHOD *
441TLS_server_method(void)
442{
443 return TLS_method();
444}
445LSSL_ALIAS(TLS_server_method);
446
447const SSL_METHOD *
448tls_legacy_method(void)
449{
450 return (&TLS_legacy_method_data);
451}
452
453const SSL_METHOD *
454SSLv23_client_method(void)
455{
456 return TLS_client_method();
457}
458LSSL_ALIAS(SSLv23_client_method);
459
460const SSL_METHOD *
461SSLv23_method(void)
462{
463 return TLS_method();
464}
465LSSL_ALIAS(SSLv23_method);
466
467const SSL_METHOD *
468SSLv23_server_method(void)
469{
470 return TLS_method();
471}
472LSSL_ALIAS(SSLv23_server_method);
473
474const SSL_METHOD *
475TLSv1_client_method(void)
476{
477 return (&TLSv1_client_method_data);
478}
479LSSL_ALIAS(TLSv1_client_method);
480
481const SSL_METHOD *
482TLSv1_method(void)
483{
484 return (&TLSv1_method_data);
485}
486LSSL_ALIAS(TLSv1_method);
487
488const SSL_METHOD *
489TLSv1_server_method(void)
490{
491 return (&TLSv1_method_data);
492}
493LSSL_ALIAS(TLSv1_server_method);
494
495const SSL_METHOD *
496TLSv1_1_client_method(void)
497{
498 return (&TLSv1_1_client_method_data);
499}
500LSSL_ALIAS(TLSv1_1_client_method);
501
502const SSL_METHOD *
503TLSv1_1_method(void)
504{
505 return (&TLSv1_1_method_data);
506}
507LSSL_ALIAS(TLSv1_1_method);
508
509const SSL_METHOD *
510TLSv1_1_server_method(void)
511{
512 return (&TLSv1_1_method_data);
513}
514LSSL_ALIAS(TLSv1_1_server_method);
515
516const SSL_METHOD *
517TLSv1_2_client_method(void)
518{
519 return (&TLSv1_2_client_method_data);
520}
521LSSL_ALIAS(TLSv1_2_client_method);
522
523const SSL_METHOD *
524TLSv1_2_method(void)
525{
526 return (&TLSv1_2_method_data);
527}
528LSSL_ALIAS(TLSv1_2_method);
529
530const SSL_METHOD *
531TLSv1_2_server_method(void)
532{
533 return (&TLSv1_2_method_data);
534}
535LSSL_ALIAS(TLSv1_2_server_method);
536
537const SSL_METHOD *
538ssl_get_method(uint16_t version)
539{
540 if (version == TLS1_3_VERSION)
541 return (TLS_method());
542 if (version == TLS1_2_VERSION)
543 return (TLSv1_2_method());
544 if (version == TLS1_1_VERSION)
545 return (TLSv1_1_method());
546 if (version == TLS1_VERSION)
547 return (TLSv1_method());
548 if (version == DTLS1_VERSION)
549 return (DTLSv1_method());
550 if (version == DTLS1_2_VERSION)
551 return (DTLSv1_2_method());
552
553 return (NULL);
554}
diff --git a/src/lib/libssl/ssl_packet.c b/src/lib/libssl/ssl_packet.c
deleted file mode 100644
index 32d6cceb7a..0000000000
--- a/src/lib/libssl/ssl_packet.c
+++ /dev/null
@@ -1,88 +0,0 @@
1/* $OpenBSD: ssl_packet.c,v 1.16 2024/06/28 13:37:49 jsing Exp $ */
2/*
3 * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "bytestring.h"
19#include "ssl_local.h"
20
21static int
22ssl_is_sslv3_handshake(CBS *header)
23{
24 uint16_t record_version;
25 uint8_t record_type;
26 CBS cbs;
27
28 CBS_dup(header, &cbs);
29
30 if (!CBS_get_u8(&cbs, &record_type) ||
31 !CBS_get_u16(&cbs, &record_version))
32 return 0;
33
34 if (record_type != SSL3_RT_HANDSHAKE)
35 return 0;
36 if ((record_version >> 8) != SSL3_VERSION_MAJOR)
37 return 0;
38
39 return 1;
40}
41
42/*
43 * Potentially do legacy processing on the first packet received by a TLS
44 * server. We return 1 if we want SSLv3/TLS record processing to continue
45 * normally, otherwise we must set an SSLerr and return -1.
46 */
47int
48ssl_server_legacy_first_packet(SSL *s)
49{
50 const char *data;
51 CBS header;
52
53 if (SSL_is_dtls(s))
54 return 1;
55
56 CBS_init(&header, s->packet, SSL3_RT_HEADER_LENGTH);
57
58 if (ssl_is_sslv3_handshake(&header) == 1)
59 return 1;
60
61 /* Only continue if this is not a version locked method. */
62 if (s->method->min_tls_version == s->method->max_tls_version)
63 return 1;
64
65 /* Ensure that we have SSL3_RT_HEADER_LENGTH (5 bytes) of the packet. */
66 if (CBS_len(&header) != SSL3_RT_HEADER_LENGTH) {
67 SSLerror(s, ERR_R_INTERNAL_ERROR);
68 return -1;
69 }
70 data = (const char *)CBS_data(&header);
71
72 /* Is this a cleartext protocol? */
73 if (strncmp("GET ", data, 4) == 0 ||
74 strncmp("POST ", data, 5) == 0 ||
75 strncmp("HEAD ", data, 5) == 0 ||
76 strncmp("PUT ", data, 4) == 0) {
77 SSLerror(s, SSL_R_HTTP_REQUEST);
78 return -1;
79 }
80 if (strncmp("CONNE", data, 5) == 0) {
81 SSLerror(s, SSL_R_HTTPS_PROXY_REQUEST);
82 return -1;
83 }
84
85 SSLerror(s, SSL_R_UNKNOWN_PROTOCOL);
86
87 return -1;
88}
diff --git a/src/lib/libssl/ssl_pkt.c b/src/lib/libssl/ssl_pkt.c
deleted file mode 100644
index 7032175aac..0000000000
--- a/src/lib/libssl/ssl_pkt.c
+++ /dev/null
@@ -1,1322 +0,0 @@
1/* $OpenBSD: ssl_pkt.c,v 1.69 2025/03/12 14:03:55 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <errno.h>
113#include <limits.h>
114#include <stdio.h>
115
116#include <openssl/buffer.h>
117#include <openssl/evp.h>
118
119#include "bytestring.h"
120#include "dtls_local.h"
121#include "ssl_local.h"
122#include "tls_content.h"
123
124static int do_ssl3_write(SSL *s, int type, const unsigned char *buf,
125 unsigned int len);
126static int ssl3_get_record(SSL *s);
127
128/*
129 * Force a WANT_READ return for certain error conditions where
130 * we don't want to spin internally.
131 */
132void
133ssl_force_want_read(SSL *s)
134{
135 BIO *bio;
136
137 bio = SSL_get_rbio(s);
138 BIO_clear_retry_flags(bio);
139 BIO_set_retry_read(bio);
140
141 s->rwstate = SSL_READING;
142}
143
144/*
145 * If extend == 0, obtain new n-byte packet; if extend == 1, increase
146 * packet by another n bytes.
147 * The packet will be in the sub-array of s->s3->rbuf.buf specified
148 * by s->packet and s->packet_length.
149 * (If s->read_ahead is set, 'max' bytes may be stored in rbuf
150 * [plus s->packet_length bytes if extend == 1].)
151 */
152static int
153ssl3_read_n(SSL *s, int n, int max, int extend)
154{
155 SSL3_BUFFER_INTERNAL *rb = &(s->s3->rbuf);
156 int i, len, left;
157 size_t align;
158 unsigned char *pkt;
159
160 if (n <= 0)
161 return n;
162
163 if (rb->buf == NULL) {
164 if (!ssl3_setup_read_buffer(s))
165 return -1;
166 }
167 if (rb->buf == NULL)
168 return -1;
169
170 left = rb->left;
171 align = (size_t)rb->buf + SSL3_RT_HEADER_LENGTH;
172 align = (-align) & (SSL3_ALIGN_PAYLOAD - 1);
173
174 if (!extend) {
175 /* start with empty packet ... */
176 if (left == 0)
177 rb->offset = align;
178 else if (align != 0 && left >= SSL3_RT_HEADER_LENGTH) {
179 /* check if next packet length is large
180 * enough to justify payload alignment... */
181 pkt = rb->buf + rb->offset;
182 if (pkt[0] == SSL3_RT_APPLICATION_DATA &&
183 (pkt[3]<<8|pkt[4]) >= 128) {
184 /* Note that even if packet is corrupted
185 * and its length field is insane, we can
186 * only be led to wrong decision about
187 * whether memmove will occur or not.
188 * Header values has no effect on memmove
189 * arguments and therefore no buffer
190 * overrun can be triggered. */
191 memmove(rb->buf + align, pkt, left);
192 rb->offset = align;
193 }
194 }
195 s->packet = rb->buf + rb->offset;
196 s->packet_length = 0;
197 /* ... now we can act as if 'extend' was set */
198 }
199
200 /* For DTLS/UDP reads should not span multiple packets
201 * because the read operation returns the whole packet
202 * at once (as long as it fits into the buffer). */
203 if (SSL_is_dtls(s)) {
204 if (left > 0 && n > left)
205 n = left;
206 }
207
208 /* if there is enough in the buffer from a previous read, take some */
209 if (left >= n) {
210 s->packet_length += n;
211 rb->left = left - n;
212 rb->offset += n;
213 return (n);
214 }
215
216 /* else we need to read more data */
217
218 len = s->packet_length;
219 pkt = rb->buf + align;
220 /* Move any available bytes to front of buffer:
221 * 'len' bytes already pointed to by 'packet',
222 * 'left' extra ones at the end */
223 if (s->packet != pkt) {
224 /* len > 0 */
225 memmove(pkt, s->packet, len + left);
226 s->packet = pkt;
227 rb->offset = len + align;
228 }
229
230 if (n > (int)(rb->len - rb->offset)) {
231 /* does not happen */
232 SSLerror(s, ERR_R_INTERNAL_ERROR);
233 return -1;
234 }
235
236 if (s->read_ahead || SSL_is_dtls(s)) {
237 if (max < n)
238 max = n;
239 if (max > (int)(rb->len - rb->offset))
240 max = rb->len - rb->offset;
241 } else {
242 /* ignore max parameter */
243 max = n;
244 }
245
246 while (left < n) {
247 /* Now we have len+left bytes at the front of s->s3->rbuf.buf
248 * and need to read in more until we have len+n (up to
249 * len+max if possible) */
250
251 errno = 0;
252 if (s->rbio != NULL) {
253 s->rwstate = SSL_READING;
254 i = BIO_read(s->rbio, pkt + len + left, max - left);
255 } else {
256 SSLerror(s, SSL_R_READ_BIO_NOT_SET);
257 i = -1;
258 }
259
260 if (i <= 0) {
261 rb->left = left;
262 if (s->mode & SSL_MODE_RELEASE_BUFFERS &&
263 !SSL_is_dtls(s)) {
264 if (len + left == 0)
265 ssl3_release_read_buffer(s);
266 }
267 return (i);
268 }
269 left += i;
270
271 /*
272 * reads should *never* span multiple packets for DTLS because
273 * the underlying transport protocol is message oriented as
274 * opposed to byte oriented as in the TLS case.
275 */
276 if (SSL_is_dtls(s)) {
277 if (n > left)
278 n = left; /* makes the while condition false */
279 }
280 }
281
282 /* done reading, now the book-keeping */
283 rb->offset += n;
284 rb->left = left - n;
285 s->packet_length += n;
286 s->rwstate = SSL_NOTHING;
287
288 return (n);
289}
290
291int
292ssl3_packet_read(SSL *s, int plen)
293{
294 int n;
295
296 n = ssl3_read_n(s, plen, s->s3->rbuf.len, 0);
297 if (n <= 0)
298 return n;
299 if (s->packet_length < plen)
300 return s->packet_length;
301
302 return plen;
303}
304
305int
306ssl3_packet_extend(SSL *s, int plen)
307{
308 int rlen, n;
309
310 if (s->packet_length >= plen)
311 return plen;
312 rlen = plen - s->packet_length;
313
314 n = ssl3_read_n(s, rlen, rlen, 1);
315 if (n <= 0)
316 return n;
317 if (s->packet_length < plen)
318 return s->packet_length;
319
320 return plen;
321}
322
323/* Call this to get a new input record.
324 * It will return <= 0 if more data is needed, normally due to an error
325 * or non-blocking IO.
326 * When it finishes, one packet has been decoded and can be found in
327 * ssl->s3->rrec.type - is the type of record
328 * ssl->s3->rrec.data, - data
329 * ssl->s3->rrec.length, - number of bytes
330 */
331/* used only by ssl3_read_bytes */
332static int
333ssl3_get_record(SSL *s)
334{
335 SSL3_BUFFER_INTERNAL *rb = &(s->s3->rbuf);
336 SSL3_RECORD_INTERNAL *rr = &(s->s3->rrec);
337 uint8_t alert_desc;
338 int al, n;
339 int ret = -1;
340
341 again:
342 /* check if we have the header */
343 if ((s->rstate != SSL_ST_READ_BODY) ||
344 (s->packet_length < SSL3_RT_HEADER_LENGTH)) {
345 CBS header;
346 uint16_t len, ssl_version;
347 uint8_t type;
348
349 n = ssl3_packet_read(s, SSL3_RT_HEADER_LENGTH);
350 if (n <= 0)
351 return (n);
352
353 s->mac_packet = 1;
354 s->rstate = SSL_ST_READ_BODY;
355
356 if (s->server && s->first_packet) {
357 if ((ret = ssl_server_legacy_first_packet(s)) != 1)
358 return (ret);
359 ret = -1;
360 }
361
362 CBS_init(&header, s->packet, SSL3_RT_HEADER_LENGTH);
363
364 /* Pull apart the header into the SSL3_RECORD_INTERNAL */
365 if (!CBS_get_u8(&header, &type) ||
366 !CBS_get_u16(&header, &ssl_version) ||
367 !CBS_get_u16(&header, &len)) {
368 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
369 goto err;
370 }
371
372 rr->type = type;
373 rr->length = len;
374
375 /* Lets check version */
376 if (!s->first_packet && ssl_version != s->version) {
377 if ((s->version & 0xFF00) == (ssl_version & 0xFF00) &&
378 !tls12_record_layer_write_protected(s->rl)) {
379 /* Send back error using their minor version number :-) */
380 s->version = ssl_version;
381 }
382 SSLerror(s, SSL_R_WRONG_VERSION_NUMBER);
383 al = SSL_AD_PROTOCOL_VERSION;
384 goto fatal_err;
385 }
386
387 if ((ssl_version >> 8) != SSL3_VERSION_MAJOR) {
388 SSLerror(s, SSL_R_WRONG_VERSION_NUMBER);
389 goto err;
390 }
391
392 if (rr->length > rb->len - SSL3_RT_HEADER_LENGTH) {
393 al = SSL_AD_RECORD_OVERFLOW;
394 SSLerror(s, SSL_R_PACKET_LENGTH_TOO_LONG);
395 goto fatal_err;
396 }
397 }
398
399 n = ssl3_packet_extend(s, SSL3_RT_HEADER_LENGTH + rr->length);
400 if (n <= 0)
401 return (n);
402 if (n != SSL3_RT_HEADER_LENGTH + rr->length)
403 return (n);
404
405 s->rstate = SSL_ST_READ_HEADER; /* set state for later operations */
406
407 /*
408 * A full record has now been read from the wire, which now needs
409 * to be processed.
410 */
411 tls12_record_layer_set_version(s->rl, s->version);
412
413 if (!tls12_record_layer_open_record(s->rl, s->packet, s->packet_length,
414 s->s3->rcontent)) {
415 tls12_record_layer_alert(s->rl, &alert_desc);
416
417 if (alert_desc == 0)
418 goto err;
419
420 if (alert_desc == SSL_AD_RECORD_OVERFLOW)
421 SSLerror(s, SSL_R_ENCRYPTED_LENGTH_TOO_LONG);
422 else if (alert_desc == SSL_AD_BAD_RECORD_MAC)
423 SSLerror(s, SSL_R_DECRYPTION_FAILED_OR_BAD_RECORD_MAC);
424
425 al = alert_desc;
426 goto fatal_err;
427 }
428
429 /* we have pulled in a full packet so zero things */
430 s->packet_length = 0;
431
432 if (tls_content_remaining(s->s3->rcontent) == 0) {
433 /*
434 * Zero-length fragments are only permitted for application
435 * data, as per RFC 5246 section 6.2.1.
436 */
437 if (rr->type != SSL3_RT_APPLICATION_DATA) {
438 SSLerror(s, SSL_R_BAD_LENGTH);
439 al = SSL_AD_UNEXPECTED_MESSAGE;
440 goto fatal_err;
441 }
442
443 tls_content_clear(s->s3->rcontent);
444
445 /*
446 * CBC countermeasures for known IV weaknesses can legitimately
447 * insert a single empty record, so we allow ourselves to read
448 * once past a single empty record without forcing want_read.
449 */
450 if (s->empty_record_count++ > SSL_MAX_EMPTY_RECORDS) {
451 SSLerror(s, SSL_R_PEER_BEHAVING_BADLY);
452 return -1;
453 }
454 if (s->empty_record_count > 1) {
455 ssl_force_want_read(s);
456 return -1;
457 }
458 goto again;
459 }
460
461 s->empty_record_count = 0;
462
463 return (1);
464
465 fatal_err:
466 ssl3_send_alert(s, SSL3_AL_FATAL, al);
467 err:
468 return (ret);
469}
470
471/* Call this to write data in records of type 'type'
472 * It will return <= 0 if not all data has been sent or non-blocking IO.
473 */
474int
475ssl3_write_bytes(SSL *s, int type, const void *buf_, int len)
476{
477 const unsigned char *buf = buf_;
478 unsigned int tot, n, nw;
479 int i;
480
481 if (len < 0) {
482 SSLerror(s, ERR_R_INTERNAL_ERROR);
483 return -1;
484 }
485
486 s->rwstate = SSL_NOTHING;
487 tot = s->s3->wnum;
488 s->s3->wnum = 0;
489
490 if (SSL_in_init(s) && !s->in_handshake) {
491 i = s->handshake_func(s);
492 if (i < 0)
493 return (i);
494 if (i == 0) {
495 SSLerror(s, SSL_R_SSL_HANDSHAKE_FAILURE);
496 return -1;
497 }
498 }
499
500 if (len < tot)
501 len = tot;
502 n = (len - tot);
503 for (;;) {
504 if (n > s->max_send_fragment)
505 nw = s->max_send_fragment;
506 else
507 nw = n;
508
509 i = do_ssl3_write(s, type, &(buf[tot]), nw);
510 if (i <= 0) {
511 s->s3->wnum = tot;
512 return i;
513 }
514
515 if ((i == (int)n) || (type == SSL3_RT_APPLICATION_DATA &&
516 (s->mode & SSL_MODE_ENABLE_PARTIAL_WRITE))) {
517 /*
518 * Next chunk of data should get another prepended
519 * empty fragment in ciphersuites with known-IV
520 * weakness.
521 */
522 s->s3->empty_fragment_done = 0;
523
524 return tot + i;
525 }
526
527 n -= i;
528 tot += i;
529 }
530}
531
532static int
533do_ssl3_write(SSL *s, int type, const unsigned char *buf, unsigned int len)
534{
535 SSL3_BUFFER_INTERNAL *wb = &(s->s3->wbuf);
536 SSL_SESSION *sess = s->session;
537 int need_empty_fragment = 0;
538 size_t align, out_len;
539 CBB cbb;
540 int ret;
541
542 memset(&cbb, 0, sizeof(cbb));
543
544 if (wb->buf == NULL)
545 if (!ssl3_setup_write_buffer(s))
546 return -1;
547
548 /*
549 * First check if there is a SSL3_BUFFER_INTERNAL still being written
550 * out. This will happen with non blocking IO.
551 */
552 if (wb->left != 0)
553 return (ssl3_write_pending(s, type, buf, len));
554
555 /* If we have an alert to send, let's send it. */
556 if (s->s3->alert_dispatch) {
557 if ((ret = ssl3_dispatch_alert(s)) <= 0)
558 return (ret);
559 /* If it went, fall through and send more stuff. */
560
561 /* We may have released our buffer, if so get it again. */
562 if (wb->buf == NULL)
563 if (!ssl3_setup_write_buffer(s))
564 return -1;
565 }
566
567 if (len == 0)
568 return 0;
569
570 /*
571 * Countermeasure against known-IV weakness in CBC ciphersuites
572 * (see http://www.openssl.org/~bodo/tls-cbc.txt). Note that this
573 * is unnecessary for AEAD.
574 */
575 if (sess != NULL && tls12_record_layer_write_protected(s->rl)) {
576 if (s->s3->need_empty_fragments &&
577 !s->s3->empty_fragment_done &&
578 type == SSL3_RT_APPLICATION_DATA)
579 need_empty_fragment = 1;
580 }
581
582 /*
583 * An extra fragment would be a couple of cipher blocks, which would
584 * be a multiple of SSL3_ALIGN_PAYLOAD, so if we want to align the real
585 * payload, then we can just simply pretend we have two headers.
586 */
587 align = (size_t)wb->buf + SSL3_RT_HEADER_LENGTH;
588 if (need_empty_fragment)
589 align += SSL3_RT_HEADER_LENGTH;
590 align = (-align) & (SSL3_ALIGN_PAYLOAD - 1);
591 wb->offset = align;
592
593 if (!CBB_init_fixed(&cbb, wb->buf + align, wb->len - align))
594 goto err;
595
596 tls12_record_layer_set_version(s->rl, s->version);
597
598 if (need_empty_fragment) {
599 if (!tls12_record_layer_seal_record(s->rl, type,
600 buf, 0, &cbb))
601 goto err;
602 s->s3->empty_fragment_done = 1;
603 }
604
605 if (!tls12_record_layer_seal_record(s->rl, type, buf, len, &cbb))
606 goto err;
607
608 if (!CBB_finish(&cbb, NULL, &out_len))
609 goto err;
610
611 wb->left = out_len;
612
613 /*
614 * Memorize arguments so that ssl3_write_pending can detect
615 * bad write retries later.
616 */
617 s->s3->wpend_tot = len;
618 s->s3->wpend_buf = buf;
619 s->s3->wpend_type = type;
620 s->s3->wpend_ret = len;
621
622 /* We now just need to write the buffer. */
623 return ssl3_write_pending(s, type, buf, len);
624
625 err:
626 CBB_cleanup(&cbb);
627
628 return -1;
629}
630
631/* if s->s3->wbuf.left != 0, we need to call this */
632int
633ssl3_write_pending(SSL *s, int type, const unsigned char *buf, unsigned int len)
634{
635 int i;
636 SSL3_BUFFER_INTERNAL *wb = &(s->s3->wbuf);
637
638 /* XXXX */
639 if ((s->s3->wpend_tot > (int)len) || ((s->s3->wpend_buf != buf) &&
640 !(s->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER)) ||
641 (s->s3->wpend_type != type)) {
642 SSLerror(s, SSL_R_BAD_WRITE_RETRY);
643 return (-1);
644 }
645
646 for (;;) {
647 errno = 0;
648 if (s->wbio != NULL) {
649 s->rwstate = SSL_WRITING;
650 i = BIO_write(s->wbio, (char *)&(wb->buf[wb->offset]),
651 (unsigned int)wb->left);
652 } else {
653 SSLerror(s, SSL_R_BIO_NOT_SET);
654 i = -1;
655 }
656 if (i == wb->left) {
657 wb->left = 0;
658 wb->offset += i;
659 if (s->mode & SSL_MODE_RELEASE_BUFFERS &&
660 !SSL_is_dtls(s))
661 ssl3_release_write_buffer(s);
662 s->rwstate = SSL_NOTHING;
663 return (s->s3->wpend_ret);
664 } else if (i <= 0) {
665 /*
666 * For DTLS, just drop it. That's kind of the
667 * whole point in using a datagram service.
668 */
669 if (SSL_is_dtls(s))
670 wb->left = 0;
671 return (i);
672 }
673 wb->offset += i;
674 wb->left -= i;
675 }
676}
677
678static ssize_t
679ssl3_read_cb(void *buf, size_t n, void *cb_arg)
680{
681 SSL *s = cb_arg;
682
683 return tls_content_read(s->s3->rcontent, buf, n);
684}
685
686#define SSL3_ALERT_LENGTH 2
687
688int
689ssl3_read_alert(SSL *s)
690{
691 uint8_t alert_level, alert_descr;
692 ssize_t ret;
693 CBS cbs;
694
695 /*
696 * TLSv1.2 permits an alert to be fragmented across multiple records or
697 * for multiple alerts to be be coalesced into a single alert record.
698 * In the case of DTLS, there is no way to reassemble an alert
699 * fragmented across multiple records, hence a full alert must be
700 * available in the record.
701 */
702 if (s->s3->alert_fragment == NULL) {
703 if ((s->s3->alert_fragment = tls_buffer_new(0)) == NULL)
704 return -1;
705 tls_buffer_set_capacity_limit(s->s3->alert_fragment,
706 SSL3_ALERT_LENGTH);
707 }
708 ret = tls_buffer_extend(s->s3->alert_fragment, SSL3_ALERT_LENGTH,
709 ssl3_read_cb, s);
710 if (ret <= 0 && ret != TLS_IO_WANT_POLLIN)
711 return -1;
712 if (ret != SSL3_ALERT_LENGTH) {
713 if (SSL_is_dtls(s)) {
714 SSLerror(s, SSL_R_BAD_LENGTH);
715 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
716 return -1;
717 }
718 return 1;
719 }
720
721 if (!tls_buffer_data(s->s3->alert_fragment, &cbs))
722 return -1;
723
724 ssl_msg_callback_cbs(s, 0, SSL3_RT_ALERT, &cbs);
725
726 if (!CBS_get_u8(&cbs, &alert_level))
727 return -1;
728 if (!CBS_get_u8(&cbs, &alert_descr))
729 return -1;
730
731 tls_buffer_free(s->s3->alert_fragment);
732 s->s3->alert_fragment = NULL;
733
734 ssl_info_callback(s, SSL_CB_READ_ALERT,
735 (alert_level << 8) | alert_descr);
736
737 if (alert_level == SSL3_AL_WARNING) {
738 s->s3->warn_alert = alert_descr;
739 if (alert_descr == SSL_AD_CLOSE_NOTIFY) {
740 s->shutdown |= SSL_RECEIVED_SHUTDOWN;
741 return 0;
742 }
743 /* We requested renegotiation and the peer rejected it. */
744 if (alert_descr == SSL_AD_NO_RENEGOTIATION) {
745 SSLerror(s, SSL_R_NO_RENEGOTIATION);
746 ssl3_send_alert(s, SSL3_AL_FATAL,
747 SSL_AD_HANDSHAKE_FAILURE);
748 return -1;
749 }
750 } else if (alert_level == SSL3_AL_FATAL) {
751 s->rwstate = SSL_NOTHING;
752 s->s3->fatal_alert = alert_descr;
753 SSLerror(s, SSL_AD_REASON_OFFSET + alert_descr);
754 ERR_asprintf_error_data("SSL alert number %d", alert_descr);
755 s->shutdown |= SSL_RECEIVED_SHUTDOWN;
756 SSL_CTX_remove_session(s->ctx, s->session);
757 return 0;
758 } else {
759 SSLerror(s, SSL_R_UNKNOWN_ALERT_TYPE);
760 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
761 return -1;
762 }
763
764 return 1;
765}
766
767int
768ssl3_read_change_cipher_spec(SSL *s)
769{
770 const uint8_t ccs[1] = { SSL3_MT_CCS };
771
772 /*
773 * 'Change Cipher Spec' is just a single byte, so we know exactly what
774 * the record payload has to look like.
775 */
776 if (tls_content_remaining(s->s3->rcontent) != sizeof(ccs)) {
777 SSLerror(s, SSL_R_BAD_CHANGE_CIPHER_SPEC);
778 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
779 return -1;
780 }
781 if (!tls_content_equal(s->s3->rcontent, ccs, sizeof(ccs))) {
782 SSLerror(s, SSL_R_BAD_CHANGE_CIPHER_SPEC);
783 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
784 return -1;
785 }
786
787 /* XDTLS: check that epoch is consistent */
788
789 ssl_msg_callback_cbs(s, 0, SSL3_RT_CHANGE_CIPHER_SPEC,
790 tls_content_cbs(s->s3->rcontent));
791
792 /* Check that we have a cipher to change to. */
793 if (s->s3->hs.cipher == NULL) {
794 SSLerror(s, SSL_R_CCS_RECEIVED_EARLY);
795 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
796 return -1;
797 }
798
799 /* Check that we should be receiving a Change Cipher Spec. */
800 if (SSL_is_dtls(s)) {
801 if (!s->d1->change_cipher_spec_ok) {
802 /*
803 * We can't process a CCS now, because previous
804 * handshake messages are still missing, so just
805 * drop it.
806 */
807 tls_content_clear(s->s3->rcontent);
808 return 1;
809 }
810 s->d1->change_cipher_spec_ok = 0;
811 } else {
812 if ((s->s3->flags & SSL3_FLAGS_CCS_OK) == 0) {
813 SSLerror(s, SSL_R_CCS_RECEIVED_EARLY);
814 ssl3_send_alert(s, SSL3_AL_FATAL,
815 SSL_AD_UNEXPECTED_MESSAGE);
816 return -1;
817 }
818 s->s3->flags &= ~SSL3_FLAGS_CCS_OK;
819 }
820
821 tls_content_clear(s->s3->rcontent);
822
823 s->s3->change_cipher_spec = 1;
824 if (!ssl3_do_change_cipher_spec(s))
825 return -1;
826
827 return 1;
828}
829
830static int
831ssl3_read_handshake_unexpected(SSL *s)
832{
833 uint32_t hs_msg_length;
834 uint8_t hs_msg_type;
835 ssize_t ssret;
836 CBS cbs;
837 int ret;
838
839 /*
840 * We need four bytes of handshake data so we have a handshake message
841 * header - this may be in the same record or fragmented across multiple
842 * records.
843 */
844 if (s->s3->handshake_fragment == NULL) {
845 if ((s->s3->handshake_fragment = tls_buffer_new(0)) == NULL)
846 return -1;
847 tls_buffer_set_capacity_limit(s->s3->handshake_fragment,
848 SSL3_HM_HEADER_LENGTH);
849 }
850 ssret = tls_buffer_extend(s->s3->handshake_fragment, SSL3_HM_HEADER_LENGTH,
851 ssl3_read_cb, s);
852 if (ssret <= 0 && ssret != TLS_IO_WANT_POLLIN)
853 return -1;
854 if (ssret != SSL3_HM_HEADER_LENGTH)
855 return 1;
856
857 if (s->in_handshake) {
858 SSLerror(s, ERR_R_INTERNAL_ERROR);
859 return -1;
860 }
861
862 /*
863 * This code currently deals with HelloRequest and ClientHello messages -
864 * anything else is pushed to the handshake_func. Almost all of this
865 * belongs in the client/server handshake code.
866 */
867
868 /* Parse handshake message header. */
869 if (!tls_buffer_data(s->s3->handshake_fragment, &cbs))
870 return -1;
871 if (!CBS_get_u8(&cbs, &hs_msg_type))
872 return -1;
873 if (!CBS_get_u24(&cbs, &hs_msg_length))
874 return -1;
875
876 if (hs_msg_type == SSL3_MT_HELLO_REQUEST) {
877 /*
878 * Incoming HelloRequest messages should only be received by a
879 * client. A server may send these at any time - a client should
880 * ignore the message if received in the middle of a handshake.
881 * See RFC 5246 sections 7.4 and 7.4.1.1.
882 */
883 if (s->server) {
884 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
885 ssl3_send_alert(s, SSL3_AL_FATAL,
886 SSL_AD_UNEXPECTED_MESSAGE);
887 return -1;
888 }
889
890 if (hs_msg_length != 0) {
891 SSLerror(s, SSL_R_BAD_HELLO_REQUEST);
892 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
893 return -1;
894 }
895
896 if (!tls_buffer_data(s->s3->handshake_fragment, &cbs))
897 return -1;
898 ssl_msg_callback_cbs(s, 0, SSL3_RT_HANDSHAKE, &cbs);
899
900 tls_buffer_free(s->s3->handshake_fragment);
901 s->s3->handshake_fragment = NULL;
902
903 if ((s->options & SSL_OP_NO_RENEGOTIATION) != 0) {
904 ssl3_send_alert(s, SSL3_AL_WARNING,
905 SSL_AD_NO_RENEGOTIATION);
906 return 1;
907 }
908
909 /*
910 * It should be impossible to hit this, but keep the safety
911 * harness for now...
912 */
913 if (s->session == NULL || s->s3->hs.cipher == NULL)
914 return 1;
915
916 /*
917 * Ignore this message if we're currently handshaking,
918 * renegotiation is already pending or renegotiation is disabled
919 * via flags.
920 */
921 if (!SSL_is_init_finished(s) || s->s3->renegotiate ||
922 (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) != 0)
923 return 1;
924
925 if (!ssl3_renegotiate(s))
926 return 1;
927 if (!ssl3_renegotiate_check(s))
928 return 1;
929
930 } else if (hs_msg_type == SSL3_MT_CLIENT_HELLO) {
931 /*
932 * Incoming ClientHello messages should only be received by a
933 * server. A client may send these in response to server
934 * initiated renegotiation (HelloRequest) or in order to
935 * initiate renegotiation by the client. See RFC 5246 section
936 * 7.4.1.2.
937 */
938 if (!s->server) {
939 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
940 ssl3_send_alert(s, SSL3_AL_FATAL,
941 SSL_AD_UNEXPECTED_MESSAGE);
942 return -1;
943 }
944
945 /*
946 * A client should not be sending a ClientHello unless we're not
947 * currently handshaking.
948 */
949 if (!SSL_is_init_finished(s)) {
950 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
951 ssl3_send_alert(s, SSL3_AL_FATAL,
952 SSL_AD_UNEXPECTED_MESSAGE);
953 return -1;
954 }
955
956 if ((s->options & SSL_OP_NO_CLIENT_RENEGOTIATION) != 0 ||
957 ((s->options & SSL_OP_NO_RENEGOTIATION) != 0 &&
958 (s->options & SSL_OP_ALLOW_CLIENT_RENEGOTIATION) == 0)) {
959 ssl3_send_alert(s, SSL3_AL_FATAL,
960 SSL_AD_NO_RENEGOTIATION);
961 return -1;
962 }
963
964 if (s->session == NULL || s->s3->hs.cipher == NULL) {
965 SSLerror(s, ERR_R_INTERNAL_ERROR);
966 return -1;
967 }
968
969 /* Client requested renegotiation but it is not permitted. */
970 if (!s->s3->send_connection_binding ||
971 (s->s3->flags & SSL3_FLAGS_NO_RENEGOTIATE_CIPHERS) != 0) {
972 ssl3_send_alert(s, SSL3_AL_WARNING,
973 SSL_AD_NO_RENEGOTIATION);
974 return 1;
975 }
976
977 s->s3->hs.state = SSL_ST_ACCEPT;
978 s->renegotiate = 1;
979 s->new_session = 1;
980
981 } else {
982 SSLerror(s, SSL_R_UNEXPECTED_MESSAGE);
983 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
984 return -1;
985 }
986
987 if ((ret = s->handshake_func(s)) < 0)
988 return ret;
989 if (ret == 0) {
990 SSLerror(s, SSL_R_SSL_HANDSHAKE_FAILURE);
991 return -1;
992 }
993
994 if (!(s->mode & SSL_MODE_AUTO_RETRY)) {
995 if (s->s3->rbuf.left == 0) {
996 ssl_force_want_read(s);
997 return -1;
998 }
999 }
1000
1001 /*
1002 * We either finished a handshake or ignored the request, now try again
1003 * to obtain the (application) data we were asked for.
1004 */
1005 return 1;
1006}
1007
1008/* Return up to 'len' payload bytes received in 'type' records.
1009 * 'type' is one of the following:
1010 *
1011 * - SSL3_RT_HANDSHAKE (when ssl3_get_message calls us)
1012 * - SSL3_RT_APPLICATION_DATA (when ssl3_read calls us)
1013 * - 0 (during a shutdown, no data has to be returned)
1014 *
1015 * If we don't have stored data to work from, read a SSL/TLS record first
1016 * (possibly multiple records if we still don't have anything to return).
1017 *
1018 * This function must handle any surprises the peer may have for us, such as
1019 * Alert records (e.g. close_notify), ChangeCipherSpec records (not really
1020 * a surprise, but handled as if it were), or renegotiation requests.
1021 * Also if record payloads contain fragments too small to process, we store
1022 * them until there is enough for the respective protocol (the record protocol
1023 * may use arbitrary fragmentation and even interleaving):
1024 * Change cipher spec protocol
1025 * just 1 byte needed, no need for keeping anything stored
1026 * Alert protocol
1027 * 2 bytes needed (AlertLevel, AlertDescription)
1028 * Handshake protocol
1029 * 4 bytes needed (HandshakeType, uint24 length) -- we just have
1030 * to detect unexpected Client Hello and Hello Request messages
1031 * here, anything else is handled by higher layers
1032 * Application data protocol
1033 * none of our business
1034 */
1035int
1036ssl3_read_bytes(SSL *s, int type, unsigned char *buf, int len, int peek)
1037{
1038 int rrcount = 0;
1039 ssize_t ssret;
1040 int ret;
1041
1042 if (s->s3->rbuf.buf == NULL) {
1043 if (!ssl3_setup_read_buffer(s))
1044 return -1;
1045 }
1046
1047 if (s->s3->rcontent == NULL) {
1048 if ((s->s3->rcontent = tls_content_new()) == NULL)
1049 return -1;
1050 }
1051
1052 if (len < 0) {
1053 SSLerror(s, ERR_R_INTERNAL_ERROR);
1054 return -1;
1055 }
1056
1057 if (type != 0 && type != SSL3_RT_APPLICATION_DATA &&
1058 type != SSL3_RT_HANDSHAKE) {
1059 SSLerror(s, ERR_R_INTERNAL_ERROR);
1060 return -1;
1061 }
1062 if (peek && type != SSL3_RT_APPLICATION_DATA) {
1063 SSLerror(s, ERR_R_INTERNAL_ERROR);
1064 return -1;
1065 }
1066
1067 if (type == SSL3_RT_HANDSHAKE &&
1068 s->s3->handshake_fragment != NULL &&
1069 tls_buffer_remaining(s->s3->handshake_fragment) > 0) {
1070 ssize_t ssn;
1071
1072 if ((ssn = tls_buffer_read(s->s3->handshake_fragment, buf,
1073 len)) <= 0)
1074 return -1;
1075
1076 if (tls_buffer_remaining(s->s3->handshake_fragment) == 0) {
1077 tls_buffer_free(s->s3->handshake_fragment);
1078 s->s3->handshake_fragment = NULL;
1079 }
1080
1081 return (int)ssn;
1082 }
1083
1084 if (SSL_in_init(s) && !s->in_handshake) {
1085 if ((ret = s->handshake_func(s)) < 0)
1086 return ret;
1087 if (ret == 0) {
1088 SSLerror(s, SSL_R_SSL_HANDSHAKE_FAILURE);
1089 return -1;
1090 }
1091 }
1092
1093 start:
1094 /*
1095 * Do not process more than three consecutive records, otherwise the
1096 * peer can cause us to loop indefinitely. Instead, return with an
1097 * SSL_ERROR_WANT_READ so the caller can choose when to handle further
1098 * processing. In the future, the total number of non-handshake and
1099 * non-application data records per connection should probably also be
1100 * limited...
1101 */
1102 if (rrcount++ >= 3) {
1103 ssl_force_want_read(s);
1104 return -1;
1105 }
1106
1107 s->rwstate = SSL_NOTHING;
1108
1109 if (tls_content_remaining(s->s3->rcontent) == 0) {
1110 if ((ret = ssl3_get_record(s)) <= 0)
1111 return ret;
1112 }
1113
1114 /* We now have a packet which can be read and processed. */
1115
1116 if (s->s3->change_cipher_spec &&
1117 tls_content_type(s->s3->rcontent) != SSL3_RT_HANDSHAKE) {
1118 SSLerror(s, SSL_R_DATA_BETWEEN_CCS_AND_FINISHED);
1119 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1120 return -1;
1121 }
1122
1123 /*
1124 * If the other end has shut down, throw anything we read away (even in
1125 * 'peek' mode).
1126 */
1127 if (s->shutdown & SSL_RECEIVED_SHUTDOWN) {
1128 s->rwstate = SSL_NOTHING;
1129 tls_content_clear(s->s3->rcontent);
1130 s->s3->rrec.length = 0;
1131 return 0;
1132 }
1133
1134 /* SSL3_RT_APPLICATION_DATA or SSL3_RT_HANDSHAKE */
1135 if (tls_content_type(s->s3->rcontent) == type) {
1136 /*
1137 * Make sure that we are not getting application data when we
1138 * are doing a handshake for the first time.
1139 */
1140 if (SSL_in_init(s) && type == SSL3_RT_APPLICATION_DATA &&
1141 !tls12_record_layer_read_protected(s->rl)) {
1142 SSLerror(s, SSL_R_APP_DATA_IN_HANDSHAKE);
1143 ssl3_send_alert(s, SSL3_AL_FATAL,
1144 SSL_AD_UNEXPECTED_MESSAGE);
1145 return -1;
1146 }
1147
1148 if (len <= 0)
1149 return len;
1150
1151 if (peek) {
1152 ssret = tls_content_peek(s->s3->rcontent, buf, len);
1153 } else {
1154 ssret = tls_content_read(s->s3->rcontent, buf, len);
1155 }
1156 if (ssret < INT_MIN || ssret > INT_MAX)
1157 return -1;
1158 if (ssret < 0)
1159 return (int)ssret;
1160
1161 if (tls_content_remaining(s->s3->rcontent) == 0) {
1162 s->rstate = SSL_ST_READ_HEADER;
1163
1164 if (s->mode & SSL_MODE_RELEASE_BUFFERS &&
1165 s->s3->rbuf.left == 0)
1166 ssl3_release_read_buffer(s);
1167 }
1168
1169 return ssret;
1170 }
1171
1172 if (tls_content_type(s->s3->rcontent) == SSL3_RT_ALERT) {
1173 if ((ret = ssl3_read_alert(s)) <= 0)
1174 return ret;
1175 goto start;
1176 }
1177
1178 if (s->shutdown & SSL_SENT_SHUTDOWN) {
1179 s->rwstate = SSL_NOTHING;
1180 tls_content_clear(s->s3->rcontent);
1181 s->s3->rrec.length = 0;
1182 return 0;
1183 }
1184
1185 if (tls_content_type(s->s3->rcontent) == SSL3_RT_APPLICATION_DATA) {
1186 /*
1187 * At this point, we were expecting handshake data, but have
1188 * application data. If the library was running inside
1189 * ssl3_read() (i.e. in_read_app_data is set) and it makes
1190 * sense to read application data at this point (session
1191 * renegotiation not yet started), we will indulge it.
1192 */
1193 if (s->s3->in_read_app_data != 0 &&
1194 s->s3->total_renegotiations != 0 &&
1195 (((s->s3->hs.state & SSL_ST_CONNECT) &&
1196 (s->s3->hs.state >= SSL3_ST_CW_CLNT_HELLO_A) &&
1197 (s->s3->hs.state <= SSL3_ST_CR_SRVR_HELLO_A)) || (
1198 (s->s3->hs.state & SSL_ST_ACCEPT) &&
1199 (s->s3->hs.state <= SSL3_ST_SW_HELLO_REQ_A) &&
1200 (s->s3->hs.state >= SSL3_ST_SR_CLNT_HELLO_A)))) {
1201 s->s3->in_read_app_data = 2;
1202 return -1;
1203 } else {
1204 SSLerror(s, SSL_R_UNEXPECTED_RECORD);
1205 ssl3_send_alert(s, SSL3_AL_FATAL,
1206 SSL_AD_UNEXPECTED_MESSAGE);
1207 return -1;
1208 }
1209 }
1210
1211 if (tls_content_type(s->s3->rcontent) == SSL3_RT_CHANGE_CIPHER_SPEC) {
1212 if ((ret = ssl3_read_change_cipher_spec(s)) <= 0)
1213 return ret;
1214 goto start;
1215 }
1216
1217 if (tls_content_type(s->s3->rcontent) == SSL3_RT_HANDSHAKE) {
1218 if ((ret = ssl3_read_handshake_unexpected(s)) <= 0)
1219 return ret;
1220 goto start;
1221 }
1222
1223 /*
1224 * Unknown record type - TLSv1.2 sends an unexpected message alert while
1225 * earlier versions silently ignore the record.
1226 */
1227 if (ssl_effective_tls_version(s) <= TLS1_1_VERSION) {
1228 tls_content_clear(s->s3->rcontent);
1229 goto start;
1230 }
1231 SSLerror(s, SSL_R_UNEXPECTED_RECORD);
1232 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_UNEXPECTED_MESSAGE);
1233 return -1;
1234}
1235
1236int
1237ssl3_do_change_cipher_spec(SSL *s)
1238{
1239 if (s->s3->hs.tls12.key_block == NULL) {
1240 if (s->session == NULL || s->session->master_key_length == 0) {
1241 /* might happen if dtls1_read_bytes() calls this */
1242 SSLerror(s, SSL_R_CCS_RECEIVED_EARLY);
1243 return (0);
1244 }
1245
1246 s->session->cipher_value = s->s3->hs.cipher->value;
1247
1248 if (!tls1_setup_key_block(s))
1249 return (0);
1250 }
1251
1252 if (!tls1_change_read_cipher_state(s))
1253 return (0);
1254
1255 /*
1256 * We have to record the message digest at this point so we can get it
1257 * before we read the finished message.
1258 */
1259 if (!tls12_derive_peer_finished(s))
1260 return (0);
1261
1262 return (1);
1263}
1264
1265static int
1266ssl3_write_alert(SSL *s)
1267{
1268 if (SSL_is_dtls(s))
1269 return do_dtls1_write(s, SSL3_RT_ALERT, s->s3->send_alert,
1270 sizeof(s->s3->send_alert));
1271
1272 return do_ssl3_write(s, SSL3_RT_ALERT, s->s3->send_alert,
1273 sizeof(s->s3->send_alert));
1274}
1275
1276int
1277ssl3_send_alert(SSL *s, int level, int desc)
1278{
1279 /* If alert is fatal, remove session from cache. */
1280 if (level == SSL3_AL_FATAL)
1281 SSL_CTX_remove_session(s->ctx, s->session);
1282
1283 s->s3->alert_dispatch = 1;
1284 s->s3->send_alert[0] = level;
1285 s->s3->send_alert[1] = desc;
1286
1287 /*
1288 * If data is still being written out, the alert will be dispatched at
1289 * some point in the future.
1290 */
1291 if (s->s3->wbuf.left != 0)
1292 return -1;
1293
1294 return ssl3_dispatch_alert(s);
1295}
1296
1297int
1298ssl3_dispatch_alert(SSL *s)
1299{
1300 int ret;
1301
1302 s->s3->alert_dispatch = 0;
1303 if ((ret = ssl3_write_alert(s)) <= 0) {
1304 s->s3->alert_dispatch = 1;
1305 return ret;
1306 }
1307
1308 /*
1309 * Alert sent to BIO. If it is important, flush it now.
1310 * If the message does not get sent due to non-blocking IO,
1311 * we will not worry too much.
1312 */
1313 if (s->s3->send_alert[0] == SSL3_AL_FATAL)
1314 (void)BIO_flush(s->wbio);
1315
1316 ssl_msg_callback(s, 1, SSL3_RT_ALERT, s->s3->send_alert, 2);
1317
1318 ssl_info_callback(s, SSL_CB_WRITE_ALERT,
1319 (s->s3->send_alert[0] << 8) | s->s3->send_alert[1]);
1320
1321 return ret;
1322}
diff --git a/src/lib/libssl/ssl_rsa.c b/src/lib/libssl/ssl_rsa.c
deleted file mode 100644
index 6c8a2be3d3..0000000000
--- a/src/lib/libssl/ssl_rsa.c
+++ /dev/null
@@ -1,777 +0,0 @@
1/* $OpenBSD: ssl_rsa.c,v 1.51 2023/12/30 06:25:56 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60
61#include <openssl/bio.h>
62#include <openssl/evp.h>
63#include <openssl/objects.h>
64#include <openssl/pem.h>
65#include <openssl/x509.h>
66
67#include "ssl_local.h"
68
69static int ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl,
70 pem_password_cb **passwd_cb, void **passwd_arg);
71static int ssl_set_cert(SSL_CTX *ctx, SSL *ssl, X509 *x509);
72static int ssl_set_pkey(SSL_CTX *ctx, SSL *ssl, EVP_PKEY *pkey);
73static int ssl_use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in);
74static int ssl_use_certificate_chain_file(SSL_CTX *ctx, SSL *ssl,
75 const char *file);
76
77int
78SSL_use_certificate(SSL *ssl, X509 *x)
79{
80 if (x == NULL) {
81 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
82 return (0);
83 }
84 return ssl_set_cert(NULL, ssl, x);
85}
86LSSL_ALIAS(SSL_use_certificate);
87
88int
89SSL_use_certificate_file(SSL *ssl, const char *file, int type)
90{
91 int j;
92 BIO *in;
93 int ret = 0;
94 X509 *x = NULL;
95
96 in = BIO_new(BIO_s_file());
97 if (in == NULL) {
98 SSLerror(ssl, ERR_R_BUF_LIB);
99 goto end;
100 }
101
102 if (BIO_read_filename(in, file) <= 0) {
103 SSLerror(ssl, ERR_R_SYS_LIB);
104 goto end;
105 }
106 if (type == SSL_FILETYPE_ASN1) {
107 j = ERR_R_ASN1_LIB;
108 x = d2i_X509_bio(in, NULL);
109 } else if (type == SSL_FILETYPE_PEM) {
110 j = ERR_R_PEM_LIB;
111 x = PEM_read_bio_X509(in, NULL,
112 ssl->ctx->default_passwd_callback,
113 ssl->ctx->default_passwd_callback_userdata);
114 } else {
115 SSLerror(ssl, SSL_R_BAD_SSL_FILETYPE);
116 goto end;
117 }
118
119 if (x == NULL) {
120 SSLerror(ssl, j);
121 goto end;
122 }
123
124 ret = SSL_use_certificate(ssl, x);
125 end:
126 X509_free(x);
127 BIO_free(in);
128 return (ret);
129}
130LSSL_ALIAS(SSL_use_certificate_file);
131
132int
133SSL_use_certificate_ASN1(SSL *ssl, const unsigned char *d, int len)
134{
135 X509 *x;
136 int ret;
137
138 x = d2i_X509(NULL, &d, (long)len);
139 if (x == NULL) {
140 SSLerror(ssl, ERR_R_ASN1_LIB);
141 return (0);
142 }
143
144 ret = SSL_use_certificate(ssl, x);
145 X509_free(x);
146 return (ret);
147}
148LSSL_ALIAS(SSL_use_certificate_ASN1);
149
150int
151SSL_use_RSAPrivateKey(SSL *ssl, RSA *rsa)
152{
153 EVP_PKEY *pkey = NULL;
154 int ret = 0;
155
156 if (rsa == NULL) {
157 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
158 goto err;
159 }
160 if ((pkey = EVP_PKEY_new()) == NULL) {
161 SSLerror(ssl, ERR_R_EVP_LIB);
162 goto err;
163 }
164 if (!EVP_PKEY_set1_RSA(pkey, rsa))
165 goto err;
166 if (!ssl_set_pkey(NULL, ssl, pkey))
167 goto err;
168
169 ret = 1;
170
171 err:
172 EVP_PKEY_free(pkey);
173
174 return ret;
175}
176LSSL_ALIAS(SSL_use_RSAPrivateKey);
177
178static int
179ssl_set_pkey(SSL_CTX *ctx, SSL *ssl, EVP_PKEY *pkey)
180{
181 SSL_CERT *c;
182 int i;
183
184 i = ssl_cert_type(pkey);
185 if (i < 0) {
186 SSLerrorx(SSL_R_UNKNOWN_CERTIFICATE_TYPE);
187 return (0);
188 }
189
190 if ((c = ssl_get0_cert(ctx, ssl)) == NULL)
191 return (0);
192
193 if (c->pkeys[i].x509 != NULL) {
194 EVP_PKEY *pktmp;
195
196 if ((pktmp = X509_get0_pubkey(c->pkeys[i].x509)) == NULL)
197 return 0;
198
199 /*
200 * Callers of EVP_PKEY_copy_parameters() can't distinguish
201 * errors from the absence of a param_copy() method. So
202 * pretend it can never fail.
203 */
204 EVP_PKEY_copy_parameters(pktmp, pkey);
205
206 ERR_clear_error();
207
208 /*
209 * Don't check the public/private key, this is mostly
210 * for smart cards.
211 */
212 if (EVP_PKEY_id(pkey) != EVP_PKEY_RSA ||
213 !(RSA_flags(EVP_PKEY_get0_RSA(pkey)) & RSA_METHOD_FLAG_NO_CHECK)) {
214 if (!X509_check_private_key(c->pkeys[i].x509, pkey)) {
215 X509_free(c->pkeys[i].x509);
216 c->pkeys[i].x509 = NULL;
217 return 0;
218 }
219 }
220 }
221
222 EVP_PKEY_free(c->pkeys[i].privatekey);
223 EVP_PKEY_up_ref(pkey);
224 c->pkeys[i].privatekey = pkey;
225 c->key = &(c->pkeys[i]);
226
227 c->valid = 0;
228 return 1;
229}
230
231int
232SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type)
233{
234 int j, ret = 0;
235 BIO *in;
236 RSA *rsa = NULL;
237
238 in = BIO_new(BIO_s_file());
239 if (in == NULL) {
240 SSLerror(ssl, ERR_R_BUF_LIB);
241 goto end;
242 }
243
244 if (BIO_read_filename(in, file) <= 0) {
245 SSLerror(ssl, ERR_R_SYS_LIB);
246 goto end;
247 }
248 if (type == SSL_FILETYPE_ASN1) {
249 j = ERR_R_ASN1_LIB;
250 rsa = d2i_RSAPrivateKey_bio(in, NULL);
251 } else if (type == SSL_FILETYPE_PEM) {
252 j = ERR_R_PEM_LIB;
253 rsa = PEM_read_bio_RSAPrivateKey(in, NULL,
254 ssl->ctx->default_passwd_callback,
255 ssl->ctx->default_passwd_callback_userdata);
256 } else {
257 SSLerror(ssl, SSL_R_BAD_SSL_FILETYPE);
258 goto end;
259 }
260 if (rsa == NULL) {
261 SSLerror(ssl, j);
262 goto end;
263 }
264 ret = SSL_use_RSAPrivateKey(ssl, rsa);
265 RSA_free(rsa);
266 end:
267 BIO_free(in);
268 return (ret);
269}
270LSSL_ALIAS(SSL_use_RSAPrivateKey_file);
271
272int
273SSL_use_RSAPrivateKey_ASN1(SSL *ssl, const unsigned char *d, long len)
274{
275 int ret;
276 RSA *rsa;
277
278 if ((rsa = d2i_RSAPrivateKey(NULL, &d, (long)len)) == NULL) {
279 SSLerror(ssl, ERR_R_ASN1_LIB);
280 return (0);
281 }
282
283 ret = SSL_use_RSAPrivateKey(ssl, rsa);
284 RSA_free(rsa);
285 return (ret);
286}
287LSSL_ALIAS(SSL_use_RSAPrivateKey_ASN1);
288
289int
290SSL_use_PrivateKey(SSL *ssl, EVP_PKEY *pkey)
291{
292 int ret;
293
294 if (pkey == NULL) {
295 SSLerror(ssl, ERR_R_PASSED_NULL_PARAMETER);
296 return (0);
297 }
298 ret = ssl_set_pkey(NULL, ssl, pkey);
299 return (ret);
300}
301LSSL_ALIAS(SSL_use_PrivateKey);
302
303int
304SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type)
305{
306 int j, ret = 0;
307 BIO *in;
308 EVP_PKEY *pkey = NULL;
309
310 in = BIO_new(BIO_s_file());
311 if (in == NULL) {
312 SSLerror(ssl, ERR_R_BUF_LIB);
313 goto end;
314 }
315
316 if (BIO_read_filename(in, file) <= 0) {
317 SSLerror(ssl, ERR_R_SYS_LIB);
318 goto end;
319 }
320 if (type == SSL_FILETYPE_PEM) {
321 j = ERR_R_PEM_LIB;
322 pkey = PEM_read_bio_PrivateKey(in, NULL,
323 ssl->ctx->default_passwd_callback,
324 ssl->ctx->default_passwd_callback_userdata);
325 } else if (type == SSL_FILETYPE_ASN1) {
326 j = ERR_R_ASN1_LIB;
327 pkey = d2i_PrivateKey_bio(in, NULL);
328 } else {
329 SSLerror(ssl, SSL_R_BAD_SSL_FILETYPE);
330 goto end;
331 }
332 if (pkey == NULL) {
333 SSLerror(ssl, j);
334 goto end;
335 }
336 ret = SSL_use_PrivateKey(ssl, pkey);
337 EVP_PKEY_free(pkey);
338 end:
339 BIO_free(in);
340 return (ret);
341}
342LSSL_ALIAS(SSL_use_PrivateKey_file);
343
344int
345SSL_use_PrivateKey_ASN1(int type, SSL *ssl, const unsigned char *d, long len)
346{
347 int ret;
348 EVP_PKEY *pkey;
349
350 if ((pkey = d2i_PrivateKey(type, NULL, &d, (long)len)) == NULL) {
351 SSLerror(ssl, ERR_R_ASN1_LIB);
352 return (0);
353 }
354
355 ret = SSL_use_PrivateKey(ssl, pkey);
356 EVP_PKEY_free(pkey);
357 return (ret);
358}
359LSSL_ALIAS(SSL_use_PrivateKey_ASN1);
360
361int
362SSL_CTX_use_certificate(SSL_CTX *ctx, X509 *x)
363{
364 if (x == NULL) {
365 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
366 return (0);
367 }
368 return ssl_set_cert(ctx, NULL, x);
369}
370LSSL_ALIAS(SSL_CTX_use_certificate);
371
372static int
373ssl_get_password_cb_and_arg(SSL_CTX *ctx, SSL *ssl,
374 pem_password_cb **passwd_cb, void **passwd_arg)
375{
376 if (ssl != NULL)
377 ctx = ssl->ctx;
378
379 *passwd_cb = ctx->default_passwd_callback;
380 *passwd_arg = ctx->default_passwd_callback_userdata;
381
382 return 1;
383}
384
385static int
386ssl_set_cert(SSL_CTX *ctx, SSL *ssl, X509 *x)
387{
388 SSL_CERT *c;
389 EVP_PKEY *pkey;
390 int ssl_err;
391 int i;
392
393 if (!ssl_security_cert(ctx, ssl, x, 1, &ssl_err)) {
394 SSLerrorx(ssl_err);
395 return (0);
396 }
397
398 if ((c = ssl_get0_cert(ctx, ssl)) == NULL)
399 return (0);
400
401 pkey = X509_get_pubkey(x);
402 if (pkey == NULL) {
403 SSLerrorx(SSL_R_X509_LIB);
404 return (0);
405 }
406
407 i = ssl_cert_type(pkey);
408 if (i < 0) {
409 SSLerrorx(SSL_R_UNKNOWN_CERTIFICATE_TYPE);
410 EVP_PKEY_free(pkey);
411 return (0);
412 }
413
414 if (c->pkeys[i].privatekey != NULL) {
415 EVP_PKEY *priv_key = c->pkeys[i].privatekey;
416
417 EVP_PKEY_copy_parameters(pkey, priv_key);
418 ERR_clear_error();
419
420 /*
421 * Don't check the public/private key, this is mostly
422 * for smart cards.
423 */
424 if (EVP_PKEY_id(priv_key) != EVP_PKEY_RSA ||
425 !(RSA_flags(EVP_PKEY_get0_RSA(priv_key)) & RSA_METHOD_FLAG_NO_CHECK)) {
426 if (!X509_check_private_key(x, priv_key)) {
427 /*
428 * don't fail for a cert/key mismatch, just free
429 * current private key (when switching to a
430 * different cert & key, first this function
431 * should be used, then ssl_set_pkey.
432 */
433 EVP_PKEY_free(c->pkeys[i].privatekey);
434 c->pkeys[i].privatekey = NULL;
435 ERR_clear_error();
436 }
437 }
438 }
439
440 EVP_PKEY_free(pkey);
441
442 X509_free(c->pkeys[i].x509);
443 X509_up_ref(x);
444 c->pkeys[i].x509 = x;
445 c->key = &(c->pkeys[i]);
446
447 c->valid = 0;
448 return (1);
449}
450
451int
452SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type)
453{
454 int j;
455 BIO *in;
456 int ret = 0;
457 X509 *x = NULL;
458
459 in = BIO_new(BIO_s_file());
460 if (in == NULL) {
461 SSLerrorx(ERR_R_BUF_LIB);
462 goto end;
463 }
464
465 if (BIO_read_filename(in, file) <= 0) {
466 SSLerrorx(ERR_R_SYS_LIB);
467 goto end;
468 }
469 if (type == SSL_FILETYPE_ASN1) {
470 j = ERR_R_ASN1_LIB;
471 x = d2i_X509_bio(in, NULL);
472 } else if (type == SSL_FILETYPE_PEM) {
473 j = ERR_R_PEM_LIB;
474 x = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback,
475 ctx->default_passwd_callback_userdata);
476 } else {
477 SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
478 goto end;
479 }
480
481 if (x == NULL) {
482 SSLerrorx(j);
483 goto end;
484 }
485
486 ret = SSL_CTX_use_certificate(ctx, x);
487 end:
488 X509_free(x);
489 BIO_free(in);
490 return (ret);
491}
492LSSL_ALIAS(SSL_CTX_use_certificate_file);
493
494int
495SSL_CTX_use_certificate_ASN1(SSL_CTX *ctx, int len, const unsigned char *d)
496{
497 X509 *x;
498 int ret;
499
500 x = d2i_X509(NULL, &d, (long)len);
501 if (x == NULL) {
502 SSLerrorx(ERR_R_ASN1_LIB);
503 return (0);
504 }
505
506 ret = SSL_CTX_use_certificate(ctx, x);
507 X509_free(x);
508 return (ret);
509}
510LSSL_ALIAS(SSL_CTX_use_certificate_ASN1);
511
512int
513SSL_CTX_use_RSAPrivateKey(SSL_CTX *ctx, RSA *rsa)
514{
515 EVP_PKEY *pkey = NULL;
516 int ret = 0;
517
518 if (rsa == NULL) {
519 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
520 goto err;
521 }
522 if ((pkey = EVP_PKEY_new()) == NULL) {
523 SSLerrorx(ERR_R_EVP_LIB);
524 goto err;
525 }
526 if (!EVP_PKEY_set1_RSA(pkey, rsa))
527 goto err;
528 if (!ssl_set_pkey(ctx, NULL, pkey))
529 goto err;
530
531 ret = 1;
532
533 err:
534 EVP_PKEY_free(pkey);
535
536 return ret;
537}
538LSSL_ALIAS(SSL_CTX_use_RSAPrivateKey);
539
540int
541SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type)
542{
543 int j, ret = 0;
544 BIO *in;
545 RSA *rsa = NULL;
546
547 in = BIO_new(BIO_s_file());
548 if (in == NULL) {
549 SSLerrorx(ERR_R_BUF_LIB);
550 goto end;
551 }
552
553 if (BIO_read_filename(in, file) <= 0) {
554 SSLerrorx(ERR_R_SYS_LIB);
555 goto end;
556 }
557 if (type == SSL_FILETYPE_ASN1) {
558 j = ERR_R_ASN1_LIB;
559 rsa = d2i_RSAPrivateKey_bio(in, NULL);
560 } else if (type == SSL_FILETYPE_PEM) {
561 j = ERR_R_PEM_LIB;
562 rsa = PEM_read_bio_RSAPrivateKey(in, NULL,
563 ctx->default_passwd_callback,
564 ctx->default_passwd_callback_userdata);
565 } else {
566 SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
567 goto end;
568 }
569 if (rsa == NULL) {
570 SSLerrorx(j);
571 goto end;
572 }
573 ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa);
574 RSA_free(rsa);
575 end:
576 BIO_free(in);
577 return (ret);
578}
579LSSL_ALIAS(SSL_CTX_use_RSAPrivateKey_file);
580
581int
582SSL_CTX_use_RSAPrivateKey_ASN1(SSL_CTX *ctx, const unsigned char *d, long len)
583{
584 int ret;
585 RSA *rsa;
586
587 if ((rsa = d2i_RSAPrivateKey(NULL, &d, (long)len)) == NULL) {
588 SSLerrorx(ERR_R_ASN1_LIB);
589 return (0);
590 }
591
592 ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa);
593 RSA_free(rsa);
594 return (ret);
595}
596LSSL_ALIAS(SSL_CTX_use_RSAPrivateKey_ASN1);
597
598int
599SSL_CTX_use_PrivateKey(SSL_CTX *ctx, EVP_PKEY *pkey)
600{
601 if (pkey == NULL) {
602 SSLerrorx(ERR_R_PASSED_NULL_PARAMETER);
603 return (0);
604 }
605 return ssl_set_pkey(ctx, NULL, pkey);
606}
607LSSL_ALIAS(SSL_CTX_use_PrivateKey);
608
609int
610SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type)
611{
612 int j, ret = 0;
613 BIO *in;
614 EVP_PKEY *pkey = NULL;
615
616 in = BIO_new(BIO_s_file());
617 if (in == NULL) {
618 SSLerrorx(ERR_R_BUF_LIB);
619 goto end;
620 }
621
622 if (BIO_read_filename(in, file) <= 0) {
623 SSLerrorx(ERR_R_SYS_LIB);
624 goto end;
625 }
626 if (type == SSL_FILETYPE_PEM) {
627 j = ERR_R_PEM_LIB;
628 pkey = PEM_read_bio_PrivateKey(in, NULL,
629 ctx->default_passwd_callback,
630 ctx->default_passwd_callback_userdata);
631 } else if (type == SSL_FILETYPE_ASN1) {
632 j = ERR_R_ASN1_LIB;
633 pkey = d2i_PrivateKey_bio(in, NULL);
634 } else {
635 SSLerrorx(SSL_R_BAD_SSL_FILETYPE);
636 goto end;
637 }
638 if (pkey == NULL) {
639 SSLerrorx(j);
640 goto end;
641 }
642 ret = SSL_CTX_use_PrivateKey(ctx, pkey);
643 EVP_PKEY_free(pkey);
644 end:
645 BIO_free(in);
646 return (ret);
647}
648LSSL_ALIAS(SSL_CTX_use_PrivateKey_file);
649
650int
651SSL_CTX_use_PrivateKey_ASN1(int type, SSL_CTX *ctx, const unsigned char *d,
652 long len)
653{
654 int ret;
655 EVP_PKEY *pkey;
656
657 if ((pkey = d2i_PrivateKey(type, NULL, &d, (long)len)) == NULL) {
658 SSLerrorx(ERR_R_ASN1_LIB);
659 return (0);
660 }
661
662 ret = SSL_CTX_use_PrivateKey(ctx, pkey);
663 EVP_PKEY_free(pkey);
664 return (ret);
665}
666LSSL_ALIAS(SSL_CTX_use_PrivateKey_ASN1);
667
668
669/*
670 * Read a bio that contains our certificate in "PEM" format,
671 * possibly followed by a sequence of CA certificates that should be
672 * sent to the peer in the Certificate message.
673 */
674static int
675ssl_use_certificate_chain_bio(SSL_CTX *ctx, SSL *ssl, BIO *in)
676{
677 pem_password_cb *passwd_cb;
678 void *passwd_arg;
679 X509 *ca, *x = NULL;
680 unsigned long err;
681 int ret = 0;
682
683 if (!ssl_get_password_cb_and_arg(ctx, ssl, &passwd_cb, &passwd_arg))
684 goto err;
685
686 if ((x = PEM_read_bio_X509_AUX(in, NULL, passwd_cb, passwd_arg)) ==
687 NULL) {
688 SSLerrorx(ERR_R_PEM_LIB);
689 goto err;
690 }
691
692 if (!ssl_set_cert(ctx, ssl, x))
693 goto err;
694
695 if (!ssl_cert_set0_chain(ctx, ssl, NULL))
696 goto err;
697
698 /* Process any additional CA certificates. */
699 while ((ca = PEM_read_bio_X509(in, NULL, passwd_cb, passwd_arg)) !=
700 NULL) {
701 if (!ssl_cert_add0_chain_cert(ctx, ssl, ca)) {
702 X509_free(ca);
703 goto err;
704 }
705 }
706
707 /* When the while loop ends, it's usually just EOF. */
708 err = ERR_peek_last_error();
709 if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
710 ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
711 ERR_clear_error();
712 ret = 1;
713 }
714
715 err:
716 X509_free(x);
717
718 return (ret);
719}
720
721int
722ssl_use_certificate_chain_file(SSL_CTX *ctx, SSL *ssl, const char *file)
723{
724 BIO *in;
725 int ret = 0;
726
727 in = BIO_new(BIO_s_file());
728 if (in == NULL) {
729 SSLerrorx(ERR_R_BUF_LIB);
730 goto end;
731 }
732
733 if (BIO_read_filename(in, file) <= 0) {
734 SSLerrorx(ERR_R_SYS_LIB);
735 goto end;
736 }
737
738 ret = ssl_use_certificate_chain_bio(ctx, ssl, in);
739
740 end:
741 BIO_free(in);
742 return (ret);
743}
744
745int
746SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file)
747{
748 return ssl_use_certificate_chain_file(ctx, NULL, file);
749}
750LSSL_ALIAS(SSL_CTX_use_certificate_chain_file);
751
752int
753SSL_use_certificate_chain_file(SSL *ssl, const char *file)
754{
755 return ssl_use_certificate_chain_file(NULL, ssl, file);
756}
757LSSL_ALIAS(SSL_use_certificate_chain_file);
758
759int
760SSL_CTX_use_certificate_chain_mem(SSL_CTX *ctx, void *buf, int len)
761{
762 BIO *in;
763 int ret = 0;
764
765 in = BIO_new_mem_buf(buf, len);
766 if (in == NULL) {
767 SSLerrorx(ERR_R_BUF_LIB);
768 goto end;
769 }
770
771 ret = ssl_use_certificate_chain_bio(ctx, NULL, in);
772
773 end:
774 BIO_free(in);
775 return (ret);
776}
777LSSL_ALIAS(SSL_CTX_use_certificate_chain_mem);
diff --git a/src/lib/libssl/ssl_seclevel.c b/src/lib/libssl/ssl_seclevel.c
deleted file mode 100644
index 979da31942..0000000000
--- a/src/lib/libssl/ssl_seclevel.c
+++ /dev/null
@@ -1,479 +0,0 @@
1/* $OpenBSD: ssl_seclevel.c,v 1.30 2025/01/18 10:52:09 tb Exp $ */
2/*
3 * Copyright (c) 2020-2022 Theo Buehler <tb@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stddef.h>
19
20#include <openssl/asn1.h>
21#include <openssl/dh.h>
22#include <openssl/evp.h>
23#include <openssl/objects.h>
24#include <openssl/ossl_typ.h>
25#include <openssl/ssl.h>
26#include <openssl/tls1.h>
27#include <openssl/x509.h>
28#include <openssl/x509v3.h>
29
30#include "bytestring.h"
31#include "ssl_local.h"
32
33static int
34ssl_security_normalize_level(const SSL_CTX *ctx, const SSL *ssl, int *out_level)
35{
36 int security_level;
37
38 if (ctx != NULL)
39 security_level = SSL_CTX_get_security_level(ctx);
40 else
41 security_level = SSL_get_security_level(ssl);
42
43 if (security_level < 0)
44 security_level = 0;
45 if (security_level > 5)
46 security_level = 5;
47
48 *out_level = security_level;
49
50 return 1;
51}
52
53static int
54ssl_security_level_to_minimum_bits(int security_level, int *out_minimum_bits)
55{
56 if (security_level < 0)
57 return 0;
58
59 if (security_level == 0)
60 *out_minimum_bits = 0;
61 else if (security_level == 1)
62 *out_minimum_bits = 80;
63 else if (security_level == 2)
64 *out_minimum_bits = 112;
65 else if (security_level == 3)
66 *out_minimum_bits = 128;
67 else if (security_level == 4)
68 *out_minimum_bits = 192;
69 else if (security_level >= 5)
70 *out_minimum_bits = 256;
71
72 return 1;
73}
74
75static int
76ssl_security_level_and_minimum_bits(const SSL_CTX *ctx, const SSL *ssl,
77 int *out_level, int *out_minimum_bits)
78{
79 int security_level = 0, minimum_bits = 0;
80
81 if (!ssl_security_normalize_level(ctx, ssl, &security_level))
82 return 0;
83 if (!ssl_security_level_to_minimum_bits(security_level, &minimum_bits))
84 return 0;
85
86 if (out_level != NULL)
87 *out_level = security_level;
88 if (out_minimum_bits != NULL)
89 *out_minimum_bits = minimum_bits;
90
91 return 1;
92}
93
94static int
95ssl_security_secop_cipher(const SSL_CTX *ctx, const SSL *ssl, int bits,
96 void *arg)
97{
98 const SSL_CIPHER *cipher = arg;
99 int security_level, minimum_bits;
100
101 if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level,
102 &minimum_bits))
103 return 0;
104
105 if (security_level <= 0)
106 return 1;
107
108 if (bits < minimum_bits)
109 return 0;
110
111 /* No unauthenticated ciphersuites. */
112 if (cipher->algorithm_auth & SSL_aNULL)
113 return 0;
114
115 if (cipher->algorithm_mac & SSL_MD5)
116 return 0;
117
118 if (security_level <= 1)
119 return 1;
120
121 if (cipher->algorithm_enc & SSL_RC4)
122 return 0;
123
124 if (security_level <= 2)
125 return 1;
126
127 /* Security level >= 3 requires a cipher with forward secrecy. */
128 if ((cipher->algorithm_mkey & (SSL_kDHE | SSL_kECDHE)) == 0 &&
129 cipher->algorithm_ssl != SSL_TLSV1_3)
130 return 0;
131
132 if (security_level <= 3)
133 return 1;
134
135 if (cipher->algorithm_mac & SSL_SHA1)
136 return 0;
137
138 return 1;
139}
140
141static int
142ssl_security_secop_version(const SSL_CTX *ctx, const SSL *ssl, int version)
143{
144 int min_version = TLS1_2_VERSION;
145 int security_level;
146
147 if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level, NULL))
148 return 0;
149
150 if (security_level < 4)
151 min_version = TLS1_1_VERSION;
152 if (security_level < 3)
153 min_version = TLS1_VERSION;
154
155 return ssl_tls_version(version) >= min_version;
156}
157
158static int
159ssl_security_secop_compression(const SSL_CTX *ctx, const SSL *ssl)
160{
161 return 0;
162}
163
164static int
165ssl_security_secop_tickets(const SSL_CTX *ctx, const SSL *ssl)
166{
167 int security_level;
168
169 if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level, NULL))
170 return 0;
171
172 return security_level < 3;
173}
174
175static int
176ssl_security_secop_tmp_dh(const SSL_CTX *ctx, const SSL *ssl, int bits)
177{
178 int security_level, minimum_bits;
179
180 if (!ssl_security_level_and_minimum_bits(ctx, ssl, &security_level,
181 &minimum_bits))
182 return 0;
183
184 /* Disallow DHE keys weaker than 1024 bits even at security level 0. */
185 if (security_level <= 0 && bits < 80)
186 return 0;
187
188 return bits >= minimum_bits;
189}
190
191static int
192ssl_security_secop_default(const SSL_CTX *ctx, const SSL *ssl, int bits)
193{
194 int minimum_bits;
195
196 if (!ssl_security_level_and_minimum_bits(ctx, ssl, NULL, &minimum_bits))
197 return 0;
198
199 return bits >= minimum_bits;
200}
201
202int
203ssl_security_default_cb(const SSL *ssl, const SSL_CTX *ctx, int secop, int bits,
204 int version, void *cipher, void *ex_data)
205{
206 switch (secop) {
207 case SSL_SECOP_CIPHER_SUPPORTED:
208 case SSL_SECOP_CIPHER_SHARED:
209 case SSL_SECOP_CIPHER_CHECK:
210 return ssl_security_secop_cipher(ctx, ssl, bits, cipher);
211 case SSL_SECOP_VERSION:
212 return ssl_security_secop_version(ctx, ssl, version);
213 case SSL_SECOP_COMPRESSION:
214 return ssl_security_secop_compression(ctx, ssl);
215 case SSL_SECOP_TICKET:
216 return ssl_security_secop_tickets(ctx, ssl);
217 case SSL_SECOP_TMP_DH:
218 return ssl_security_secop_tmp_dh(ctx, ssl, bits);
219 default:
220 return ssl_security_secop_default(ctx, ssl, bits);
221 }
222}
223
224static int
225ssl_ctx_security(const SSL_CTX *ctx, int secop, int bits, int nid, void *other)
226{
227 return ctx->cert->security_cb(NULL, ctx, secop, bits, nid,
228 other, ctx->cert->security_ex_data);
229}
230
231static int
232ssl_security(const SSL *ssl, int secop, int bits, int nid, void *other)
233{
234 return ssl->cert->security_cb(ssl, NULL, secop, bits, nid, other,
235 ssl->cert->security_ex_data);
236}
237
238int
239ssl_security_sigalg_check(const SSL *ssl, const EVP_PKEY *pkey)
240{
241 int bits;
242
243 bits = EVP_PKEY_security_bits(pkey);
244
245 return ssl_security(ssl, SSL_SECOP_SIGALG_CHECK, bits, 0, NULL);
246}
247
248int
249ssl_security_tickets(const SSL *ssl)
250{
251 return ssl_security(ssl, SSL_SECOP_TICKET, 0, 0, NULL);
252}
253
254int
255ssl_security_version(const SSL *ssl, int version)
256{
257 return ssl_security(ssl, SSL_SECOP_VERSION, 0, version, NULL);
258}
259
260static int
261ssl_security_cipher(const SSL *ssl, SSL_CIPHER *cipher, int secop)
262{
263 return ssl_security(ssl, secop, cipher->strength_bits, 0, cipher);
264}
265
266int
267ssl_security_cipher_check(const SSL *ssl, SSL_CIPHER *cipher)
268{
269 return ssl_security_cipher(ssl, cipher, SSL_SECOP_CIPHER_CHECK);
270}
271
272int
273ssl_security_shared_cipher(const SSL *ssl, SSL_CIPHER *cipher)
274{
275 return ssl_security_cipher(ssl, cipher, SSL_SECOP_CIPHER_SHARED);
276}
277
278int
279ssl_security_supported_cipher(const SSL *ssl, SSL_CIPHER *cipher)
280{
281 return ssl_security_cipher(ssl, cipher, SSL_SECOP_CIPHER_SUPPORTED);
282}
283
284int
285ssl_ctx_security_dh(const SSL_CTX *ctx, DH *dh)
286{
287 int bits;
288
289 bits = DH_security_bits(dh);
290
291 return ssl_ctx_security(ctx, SSL_SECOP_TMP_DH, bits, 0, dh);
292}
293
294int
295ssl_security_dh(const SSL *ssl, DH *dh)
296{
297 int bits;
298
299 bits = DH_security_bits(dh);
300
301 return ssl_security(ssl, SSL_SECOP_TMP_DH, bits, 0, dh);
302}
303
304static int
305ssl_cert_pubkey_security_bits(const X509 *x509)
306{
307 EVP_PKEY *pkey;
308
309 if ((pkey = X509_get0_pubkey(x509)) == NULL)
310 return -1;
311
312 return EVP_PKEY_security_bits(pkey);
313}
314
315static int
316ssl_security_cert_key(const SSL_CTX *ctx, const SSL *ssl, X509 *x509, int secop)
317{
318 int security_bits;
319
320 security_bits = ssl_cert_pubkey_security_bits(x509);
321
322 if (ssl != NULL)
323 return ssl_security(ssl, secop, security_bits, 0, x509);
324
325 return ssl_ctx_security(ctx, secop, security_bits, 0, x509);
326}
327
328static int
329ssl_security_cert_sig_security_bits(X509 *x509, int *out_md_nid)
330{
331 int pkey_nid, security_bits;
332 uint32_t flags;
333
334 *out_md_nid = NID_undef;
335
336 /*
337 * Returning -1 security bits makes the default security callback fail
338 * to match bonkers behavior in OpenSSL. This in turn lets a security
339 * callback override such failures.
340 */
341 if (!X509_get_signature_info(x509, out_md_nid, &pkey_nid, &security_bits,
342 &flags))
343 return -1;
344 /*
345 * OpenSSL doesn't check flags. Test RSA-PSS certs we were provided have
346 * a salt length distinct from hash length and thus fail this check.
347 */
348 if ((flags & X509_SIG_INFO_TLS) == 0)
349 return -1;
350
351 /* Weird OpenSSL behavior only relevant for EdDSA certs in LibreSSL. */
352 if (*out_md_nid == NID_undef)
353 *out_md_nid = pkey_nid;
354
355 return security_bits;
356}
357
358static int
359ssl_security_cert_sig(const SSL_CTX *ctx, const SSL *ssl, X509 *x509, int secop)
360{
361 int md_nid = NID_undef, security_bits = -1;
362
363 /* Don't check signature if self signed. */
364 if ((X509_get_extension_flags(x509) & EXFLAG_SS) != 0)
365 return 1;
366
367 /*
368 * The default security callback fails on -1 security bits. It ignores
369 * the md_nid (aka version) argument we pass from here.
370 */
371 security_bits = ssl_security_cert_sig_security_bits(x509, &md_nid);
372
373 if (ssl != NULL)
374 return ssl_security(ssl, secop, security_bits, md_nid, x509);
375
376 return ssl_ctx_security(ctx, secop, security_bits, md_nid, x509);
377}
378
379int
380ssl_security_cert(const SSL_CTX *ctx, const SSL *ssl, X509 *x509,
381 int is_ee, int *out_error)
382{
383 int key_error, operation;
384
385 *out_error = 0;
386
387 if (is_ee) {
388 operation = SSL_SECOP_EE_KEY;
389 key_error = SSL_R_EE_KEY_TOO_SMALL;
390 } else {
391 operation = SSL_SECOP_CA_KEY;
392 key_error = SSL_R_CA_KEY_TOO_SMALL;
393 }
394
395 if (!ssl_security_cert_key(ctx, ssl, x509, operation)) {
396 *out_error = key_error;
397 return 0;
398 }
399
400 if (!ssl_security_cert_sig(ctx, ssl, x509, SSL_SECOP_CA_MD)) {
401 *out_error = SSL_R_CA_MD_TOO_WEAK;
402 return 0;
403 }
404
405 return 1;
406}
407
408/*
409 * Check security of a chain. If |sk| includes the end entity certificate
410 * then |x509| must be NULL.
411 */
412int
413ssl_security_cert_chain(const SSL *ssl, STACK_OF(X509) *sk, X509 *x509,
414 int *out_error)
415{
416 int start_idx = 0;
417 int is_ee;
418 int i;
419
420 if (x509 == NULL) {
421 x509 = sk_X509_value(sk, 0);
422 start_idx = 1;
423 }
424
425 is_ee = 1;
426 if (!ssl_security_cert(NULL, ssl, x509, is_ee, out_error))
427 return 0;
428
429 is_ee = 0;
430 for (i = start_idx; i < sk_X509_num(sk); i++) {
431 x509 = sk_X509_value(sk, i);
432
433 if (!ssl_security_cert(NULL, ssl, x509, is_ee, out_error))
434 return 0;
435 }
436
437 return 1;
438}
439
440static int
441ssl_security_group(const SSL *ssl, uint16_t group_id, int secop)
442{
443 CBB cbb;
444 int bits, nid;
445 uint8_t group[2];
446
447 memset(&cbb, 0, sizeof(cbb));
448
449 if (!tls1_ec_group_id2bits(group_id, &bits))
450 goto err;
451 if (!tls1_ec_group_id2nid(group_id, &nid))
452 goto err;
453
454 if (!CBB_init_fixed(&cbb, group, sizeof(group)))
455 goto err;
456 if (!CBB_add_u16(&cbb, group_id))
457 goto err;
458 if (!CBB_finish(&cbb, NULL, NULL))
459 goto err;
460
461 return ssl_security(ssl, secop, bits, nid, group);
462
463 err:
464 CBB_cleanup(&cbb);
465
466 return 0;
467}
468
469int
470ssl_security_shared_group(const SSL *ssl, uint16_t group_id)
471{
472 return ssl_security_group(ssl, group_id, SSL_SECOP_CURVE_SHARED);
473}
474
475int
476ssl_security_supported_group(const SSL *ssl, uint16_t group_id)
477{
478 return ssl_security_group(ssl, group_id, SSL_SECOP_CURVE_SUPPORTED);
479}
diff --git a/src/lib/libssl/ssl_sess.c b/src/lib/libssl/ssl_sess.c
deleted file mode 100644
index a5cfc33c04..0000000000
--- a/src/lib/libssl/ssl_sess.c
+++ /dev/null
@@ -1,1347 +0,0 @@
1/* $OpenBSD: ssl_sess.c,v 1.129 2025/03/09 15:53:36 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2005 Nokia. All rights reserved.
113 *
114 * The portions of the attached software ("Contribution") is developed by
115 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
116 * license.
117 *
118 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
119 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
120 * support (see RFC 4279) to OpenSSL.
121 *
122 * No patent licenses or other rights except those expressly stated in
123 * the OpenSSL open source license shall be deemed granted or received
124 * expressly, by implication, estoppel, or otherwise.
125 *
126 * No assurances are provided by Nokia that the Contribution does not
127 * infringe the patent or other intellectual property rights of any third
128 * party or that the license provides you with all the necessary rights
129 * to make use of the Contribution.
130 *
131 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
132 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
133 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
134 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
135 * OTHERWISE.
136 */
137
138#include <openssl/lhash.h>
139#include <openssl/opensslconf.h>
140
141#include "ssl_local.h"
142
143static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
144static void SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s);
145static int remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck);
146
147/* aka SSL_get0_session; gets 0 objects, just returns a copy of the pointer */
148SSL_SESSION *
149SSL_get_session(const SSL *ssl)
150{
151 return (ssl->session);
152}
153LSSL_ALIAS(SSL_get_session);
154
155/* variant of SSL_get_session: caller really gets something */
156SSL_SESSION *
157SSL_get1_session(SSL *ssl)
158{
159 SSL_SESSION *sess;
160
161 /*
162 * Need to lock this all up rather than just use CRYPTO_add so that
163 * somebody doesn't free ssl->session between when we check it's
164 * non-null and when we up the reference count.
165 */
166 CRYPTO_w_lock(CRYPTO_LOCK_SSL_SESSION);
167 sess = ssl->session;
168 if (sess)
169 sess->references++;
170 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_SESSION);
171
172 return (sess);
173}
174LSSL_ALIAS(SSL_get1_session);
175
176int
177SSL_SESSION_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
178 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
179{
180 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_SSL_SESSION,
181 argl, argp, new_func, dup_func, free_func);
182}
183LSSL_ALIAS(SSL_SESSION_get_ex_new_index);
184
185int
186SSL_SESSION_set_ex_data(SSL_SESSION *s, int idx, void *arg)
187{
188 return (CRYPTO_set_ex_data(&s->ex_data, idx, arg));
189}
190LSSL_ALIAS(SSL_SESSION_set_ex_data);
191
192void *
193SSL_SESSION_get_ex_data(const SSL_SESSION *s, int idx)
194{
195 return (CRYPTO_get_ex_data(&s->ex_data, idx));
196}
197LSSL_ALIAS(SSL_SESSION_get_ex_data);
198
199uint32_t
200SSL_SESSION_get_max_early_data(const SSL_SESSION *s)
201{
202 return 0;
203}
204LSSL_ALIAS(SSL_SESSION_get_max_early_data);
205
206int
207SSL_SESSION_set_max_early_data(SSL_SESSION *s, uint32_t max_early_data)
208{
209 return 1;
210}
211LSSL_ALIAS(SSL_SESSION_set_max_early_data);
212
213SSL_SESSION *
214SSL_SESSION_new(void)
215{
216 SSL_SESSION *ss;
217
218 if (!OPENSSL_init_ssl(0, NULL)) {
219 SSLerrorx(SSL_R_LIBRARY_BUG);
220 return(NULL);
221 }
222
223 if ((ss = calloc(1, sizeof(*ss))) == NULL) {
224 SSLerrorx(ERR_R_MALLOC_FAILURE);
225 return (NULL);
226 }
227
228 ss->verify_result = 1; /* avoid 0 (= X509_V_OK) just in case */
229 ss->references = 1;
230 ss->timeout = 60 * 5 + 4; /* 5 minutes 4 seconds timeout by default */
231 ss->time = time(NULL);
232 ss->prev = NULL;
233 ss->next = NULL;
234 ss->tlsext_hostname = NULL;
235
236 ss->peer_cert_type = -1;
237
238 ss->tlsext_ecpointformatlist_length = 0;
239 ss->tlsext_ecpointformatlist = NULL;
240 ss->tlsext_supportedgroups_length = 0;
241 ss->tlsext_supportedgroups = NULL;
242
243 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
244
245 return (ss);
246}
247LSSL_ALIAS(SSL_SESSION_new);
248
249SSL_SESSION *
250ssl_session_dup(SSL_SESSION *sess, int include_ticket)
251{
252 SSL_SESSION *copy;
253 CBS cbs;
254
255 if ((copy = calloc(1, sizeof(*copy))) == NULL) {
256 SSLerrorx(ERR_R_MALLOC_FAILURE);
257 goto err;
258 }
259
260 copy->ssl_version = sess->ssl_version;
261
262 CBS_init(&cbs, sess->master_key, sess->master_key_length);
263 if (!CBS_write_bytes(&cbs, copy->master_key, sizeof(copy->master_key),
264 &copy->master_key_length))
265 goto err;
266
267 CBS_init(&cbs, sess->session_id, sess->session_id_length);
268 if (!CBS_write_bytes(&cbs, copy->session_id, sizeof(copy->session_id),
269 &copy->session_id_length))
270 goto err;
271
272 CBS_init(&cbs, sess->sid_ctx, sess->sid_ctx_length);
273 if (!CBS_write_bytes(&cbs, copy->sid_ctx, sizeof(copy->sid_ctx),
274 &copy->sid_ctx_length))
275 goto err;
276
277 if (sess->peer_cert != NULL) {
278 if (!X509_up_ref(sess->peer_cert))
279 goto err;
280 copy->peer_cert = sess->peer_cert;
281 }
282 copy->peer_cert_type = sess->peer_cert_type;
283
284 copy->verify_result = sess->verify_result;
285
286 copy->timeout = sess->timeout;
287 copy->time = sess->time;
288 copy->references = 1;
289
290 copy->cipher_value = sess->cipher_value;
291
292 if (sess->tlsext_hostname != NULL) {
293 copy->tlsext_hostname = strdup(sess->tlsext_hostname);
294 if (copy->tlsext_hostname == NULL)
295 goto err;
296 }
297
298 if (include_ticket) {
299 CBS_init(&cbs, sess->tlsext_tick, sess->tlsext_ticklen);
300 if (!CBS_stow(&cbs, &copy->tlsext_tick, &copy->tlsext_ticklen))
301 goto err;
302 copy->tlsext_tick_lifetime_hint =
303 sess->tlsext_tick_lifetime_hint;
304
305 /*
306 * XXX - copy sess->resumption_master_secret and all other
307 * TLSv1.3 info here.
308 */
309 }
310
311 if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, copy,
312 &copy->ex_data))
313 goto err;
314
315 if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, &copy->ex_data,
316 &sess->ex_data))
317 goto err;
318
319 /* Omit prev/next: the new session gets its own slot in the cache. */
320
321 copy->not_resumable = sess->not_resumable;
322
323 CBS_init(&cbs, sess->tlsext_ecpointformatlist,
324 sess->tlsext_ecpointformatlist_length);
325 if (!CBS_stow(&cbs, &copy->tlsext_ecpointformatlist,
326 &copy->tlsext_ecpointformatlist_length))
327 goto err;
328
329 if (sess->tlsext_supportedgroups != NULL) {
330 if ((copy->tlsext_supportedgroups = calloc(sizeof(uint16_t),
331 sess->tlsext_supportedgroups_length)) == NULL)
332 goto err;
333 memcpy(copy->tlsext_supportedgroups,
334 sess->tlsext_supportedgroups,
335 sizeof(uint16_t) * sess->tlsext_supportedgroups_length);
336 copy->tlsext_supportedgroups_length =
337 sess->tlsext_supportedgroups_length;
338 }
339
340 return copy;
341
342 err:
343 SSL_SESSION_free(copy);
344
345 return NULL;
346}
347
348const unsigned char *
349SSL_SESSION_get_id(const SSL_SESSION *ss, unsigned int *len)
350{
351 if (len != NULL)
352 *len = (unsigned int)ss->session_id_length;
353 return ss->session_id;
354}
355LSSL_ALIAS(SSL_SESSION_get_id);
356
357const unsigned char *
358SSL_SESSION_get0_id_context(const SSL_SESSION *ss, unsigned int *len)
359{
360 if (len != NULL)
361 *len = (unsigned int)ss->sid_ctx_length;
362 return ss->sid_ctx;
363}
364LSSL_ALIAS(SSL_SESSION_get0_id_context);
365
366unsigned int
367SSL_SESSION_get_compress_id(const SSL_SESSION *ss)
368{
369 return 0;
370}
371LSSL_ALIAS(SSL_SESSION_get_compress_id);
372
373unsigned long
374SSL_SESSION_get_ticket_lifetime_hint(const SSL_SESSION *s)
375{
376 return s->tlsext_tick_lifetime_hint;
377}
378LSSL_ALIAS(SSL_SESSION_get_ticket_lifetime_hint);
379
380int
381SSL_SESSION_has_ticket(const SSL_SESSION *s)
382{
383 return (s->tlsext_ticklen > 0) ? 1 : 0;
384}
385LSSL_ALIAS(SSL_SESSION_has_ticket);
386
387/*
388 * SSLv3/TLSv1 has 32 bytes (256 bits) of session ID space. As such, filling
389 * the ID with random gunk repeatedly until we have no conflict is going to
390 * complete in one iteration pretty much "most" of the time (btw:
391 * understatement). So, if it takes us 10 iterations and we still can't avoid
392 * a conflict - well that's a reasonable point to call it quits. Either the
393 * arc4random code is broken or someone is trying to open roughly very close to
394 * 2^128 (or 2^256) SSL sessions to our server. How you might store that many
395 * sessions is perhaps a more interesting question...
396 */
397
398#define MAX_SESS_ID_ATTEMPTS 10
399
400static int
401def_generate_session_id(const SSL *ssl, unsigned char *id, unsigned int *id_len)
402{
403 unsigned int retry = 0;
404
405 do {
406 arc4random_buf(id, *id_len);
407 } while (SSL_has_matching_session_id(ssl, id, *id_len) &&
408 (++retry < MAX_SESS_ID_ATTEMPTS));
409
410 if (retry < MAX_SESS_ID_ATTEMPTS)
411 return 1;
412
413 /* else - woops a session_id match */
414 /* XXX We should also check the external cache --
415 * but the probability of a collision is negligible, and
416 * we could not prevent the concurrent creation of sessions
417 * with identical IDs since we currently don't have means
418 * to atomically check whether a session ID already exists
419 * and make a reservation for it if it does not
420 * (this problem applies to the internal cache as well).
421 */
422 return 0;
423}
424
425int
426ssl_get_new_session(SSL *s, int session)
427{
428 unsigned int tmp;
429 SSL_SESSION *ss = NULL;
430 GEN_SESSION_CB cb = def_generate_session_id;
431
432 /* This gets used by clients and servers. */
433
434 if ((ss = SSL_SESSION_new()) == NULL)
435 return (0);
436
437 /* If the context has a default timeout, use it */
438 if (s->session_ctx->session_timeout == 0)
439 ss->timeout = SSL_get_default_timeout(s);
440 else
441 ss->timeout = s->session_ctx->session_timeout;
442
443 if (s->session != NULL) {
444 SSL_SESSION_free(s->session);
445 s->session = NULL;
446 }
447
448 if (session) {
449 switch (s->version) {
450 case TLS1_VERSION:
451 case TLS1_1_VERSION:
452 case TLS1_2_VERSION:
453 case DTLS1_VERSION:
454 case DTLS1_2_VERSION:
455 ss->ssl_version = s->version;
456 ss->session_id_length = SSL3_SSL_SESSION_ID_LENGTH;
457 break;
458 default:
459 SSLerror(s, SSL_R_UNSUPPORTED_SSL_VERSION);
460 SSL_SESSION_free(ss);
461 return (0);
462 }
463
464 /* If RFC4507 ticket use empty session ID. */
465 if (s->tlsext_ticket_expected) {
466 ss->session_id_length = 0;
467 goto sess_id_done;
468 }
469
470 /* Choose which callback will set the session ID. */
471 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
472 if (s->generate_session_id)
473 cb = s->generate_session_id;
474 else if (s->session_ctx->generate_session_id)
475 cb = s->session_ctx->generate_session_id;
476 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
477
478 /* Choose a session ID. */
479 tmp = ss->session_id_length;
480 if (!cb(s, ss->session_id, &tmp)) {
481 /* The callback failed */
482 SSLerror(s, SSL_R_SSL_SESSION_ID_CALLBACK_FAILED);
483 SSL_SESSION_free(ss);
484 return (0);
485 }
486
487 /*
488 * Don't allow the callback to set the session length to zero.
489 * nor set it higher than it was.
490 */
491 if (tmp == 0 || tmp > ss->session_id_length) {
492 /* The callback set an illegal length */
493 SSLerror(s, SSL_R_SSL_SESSION_ID_HAS_BAD_LENGTH);
494 SSL_SESSION_free(ss);
495 return (0);
496 }
497 ss->session_id_length = tmp;
498
499 /* Finally, check for a conflict. */
500 if (SSL_has_matching_session_id(s, ss->session_id,
501 ss->session_id_length)) {
502 SSLerror(s, SSL_R_SSL_SESSION_ID_CONFLICT);
503 SSL_SESSION_free(ss);
504 return (0);
505 }
506
507 sess_id_done:
508 if (s->tlsext_hostname) {
509 ss->tlsext_hostname = strdup(s->tlsext_hostname);
510 if (ss->tlsext_hostname == NULL) {
511 SSLerror(s, ERR_R_INTERNAL_ERROR);
512 SSL_SESSION_free(ss);
513 return 0;
514 }
515 }
516 } else {
517 ss->session_id_length = 0;
518 }
519
520 if (s->sid_ctx_length > sizeof ss->sid_ctx) {
521 SSLerror(s, ERR_R_INTERNAL_ERROR);
522 SSL_SESSION_free(ss);
523 return 0;
524 }
525
526 memcpy(ss->sid_ctx, s->sid_ctx, s->sid_ctx_length);
527 ss->sid_ctx_length = s->sid_ctx_length;
528 s->session = ss;
529 ss->ssl_version = s->version;
530 ss->verify_result = X509_V_OK;
531
532 return (1);
533}
534
535static SSL_SESSION *
536ssl_session_from_cache(SSL *s, CBS *session_id)
537{
538 SSL_SESSION *sess;
539 SSL_SESSION data;
540
541 if ((s->session_ctx->session_cache_mode &
542 SSL_SESS_CACHE_NO_INTERNAL_LOOKUP))
543 return NULL;
544
545 memset(&data, 0, sizeof(data));
546
547 data.ssl_version = s->version;
548
549 if (!CBS_write_bytes(session_id, data.session_id,
550 sizeof(data.session_id), &data.session_id_length))
551 return NULL;
552
553 CRYPTO_r_lock(CRYPTO_LOCK_SSL_CTX);
554 sess = lh_SSL_SESSION_retrieve(s->session_ctx->sessions, &data);
555 if (sess != NULL)
556 CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
557 CRYPTO_r_unlock(CRYPTO_LOCK_SSL_CTX);
558
559 if (sess == NULL)
560 s->session_ctx->stats.sess_miss++;
561
562 return sess;
563}
564
565static SSL_SESSION *
566ssl_session_from_callback(SSL *s, CBS *session_id)
567{
568 SSL_SESSION *sess;
569 int copy;
570
571 if (s->session_ctx->get_session_cb == NULL)
572 return NULL;
573
574 copy = 1;
575 if ((sess = s->session_ctx->get_session_cb(s,
576 CBS_data(session_id), CBS_len(session_id), &copy)) == NULL)
577 return NULL;
578 /*
579 * The copy handler may have set copy == 0 to indicate that the session
580 * structures are shared between threads and that it handles the
581 * reference count itself. If it didn't set copy to zero, we must
582 * increment the reference count.
583 */
584 if (copy)
585 CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
586
587 s->session_ctx->stats.sess_cb_hit++;
588
589 /* Add the externally cached session to the internal cache as well. */
590 if (!(s->session_ctx->session_cache_mode &
591 SSL_SESS_CACHE_NO_INTERNAL_STORE)) {
592 /*
593 * The following should not return 1,
594 * otherwise, things are very strange.
595 */
596 SSL_CTX_add_session(s->session_ctx, sess);
597 }
598
599 return sess;
600}
601
602static SSL_SESSION *
603ssl_session_by_id(SSL *s, CBS *session_id)
604{
605 SSL_SESSION *sess;
606
607 if (CBS_len(session_id) == 0)
608 return NULL;
609
610 if ((sess = ssl_session_from_cache(s, session_id)) == NULL)
611 sess = ssl_session_from_callback(s, session_id);
612
613 return sess;
614}
615
616/*
617 * ssl_get_prev_session attempts to find an SSL_SESSION to be used to resume
618 * this connection. It is only called by servers.
619 *
620 * session_id: points at the session ID in the ClientHello. This code will
621 * read past the end of this in order to parse out the session ticket
622 * extension, if any.
623 * ext_block: a CBS for the ClientHello extensions block.
624 * alert: alert that the caller should send in case of failure.
625 *
626 * Returns:
627 * -1: error
628 * 0: a session may have been found.
629 *
630 * Side effects:
631 * - If a session is found then s->session is pointed at it (after freeing
632 * an existing session if need be) and s->verify_result is set from the
633 * session.
634 * - For both new and resumed sessions, s->tlsext_ticket_expected
635 * indicates whether the server should issue a new session ticket or not.
636 */
637int
638ssl_get_prev_session(SSL *s, CBS *session_id, CBS *ext_block, int *alert)
639{
640 SSL_SESSION *sess = NULL;
641 int alert_desc = SSL_AD_INTERNAL_ERROR, fatal = 0;
642 int ticket_decrypted = 0;
643
644 /* This is used only by servers. */
645
646 if (CBS_len(session_id) > SSL_MAX_SSL_SESSION_ID_LENGTH)
647 goto err;
648
649 /* Sets s->tlsext_ticket_expected. */
650 switch (tls1_process_ticket(s, ext_block, &alert_desc, &sess)) {
651 case TLS1_TICKET_FATAL_ERROR:
652 fatal = 1;
653 goto err;
654 case TLS1_TICKET_NONE:
655 case TLS1_TICKET_EMPTY:
656 if ((sess = ssl_session_by_id(s, session_id)) == NULL)
657 goto err;
658 break;
659 case TLS1_TICKET_NOT_DECRYPTED:
660 goto err;
661 case TLS1_TICKET_DECRYPTED:
662 ticket_decrypted = 1;
663
664 /*
665 * The session ID is used by some clients to detect that the
666 * ticket has been accepted so we copy it into sess.
667 */
668 if (!CBS_write_bytes(session_id, sess->session_id,
669 sizeof(sess->session_id), &sess->session_id_length)) {
670 fatal = 1;
671 goto err;
672 }
673 break;
674 default:
675 SSLerror(s, ERR_R_INTERNAL_ERROR);
676 fatal = 1;
677 goto err;
678 }
679
680 /* Now sess is non-NULL and we own one of its reference counts. */
681
682 if (sess->sid_ctx_length != s->sid_ctx_length ||
683 timingsafe_memcmp(sess->sid_ctx, s->sid_ctx,
684 sess->sid_ctx_length) != 0) {
685 /*
686 * We have the session requested by the client, but we don't
687 * want to use it in this context. Treat it like a cache miss.
688 */
689 goto err;
690 }
691
692 if ((s->verify_mode & SSL_VERIFY_PEER) && s->sid_ctx_length == 0) {
693 /*
694 * We can't be sure if this session is being used out of
695 * context, which is especially important for SSL_VERIFY_PEER.
696 * The application should have used
697 * SSL[_CTX]_set_session_id_context.
698 *
699 * For this error case, we generate an error instead of treating
700 * the event like a cache miss (otherwise it would be easy for
701 * applications to effectively disable the session cache by
702 * accident without anyone noticing).
703 */
704 SSLerror(s, SSL_R_SESSION_ID_CONTEXT_UNINITIALIZED);
705 fatal = 1;
706 goto err;
707 }
708
709 if (sess->timeout < (time(NULL) - sess->time)) {
710 s->session_ctx->stats.sess_timeout++;
711 if (!ticket_decrypted) {
712 /* The session was from the cache, so remove it. */
713 SSL_CTX_remove_session(s->session_ctx, sess);
714 }
715 goto err;
716 }
717
718 s->session_ctx->stats.sess_hit++;
719
720 SSL_SESSION_free(s->session);
721 s->session = sess;
722 s->verify_result = s->session->verify_result;
723
724 return 1;
725
726 err:
727 SSL_SESSION_free(sess);
728 if (ticket_decrypted) {
729 /*
730 * The session was from a ticket. Issue a ticket for the new
731 * session.
732 */
733 s->tlsext_ticket_expected = 1;
734 }
735 if (fatal) {
736 *alert = alert_desc;
737 return -1;
738 }
739 return 0;
740}
741
742int
743SSL_CTX_add_session(SSL_CTX *ctx, SSL_SESSION *c)
744{
745 int ret = 0;
746 SSL_SESSION *s;
747
748 /*
749 * Add just 1 reference count for the SSL_CTX's session cache
750 * even though it has two ways of access: each session is in a
751 * doubly linked list and an lhash.
752 */
753 CRYPTO_add(&c->references, 1, CRYPTO_LOCK_SSL_SESSION);
754
755 /*
756 * If session c is in already in cache, we take back the increment
757 * later.
758 */
759 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
760 s = lh_SSL_SESSION_insert(ctx->sessions, c);
761
762 /*
763 * s != NULL iff we already had a session with the given PID.
764 * In this case, s == c should hold (then we did not really modify
765 * ctx->sessions), or we're in trouble.
766 */
767 if (s != NULL && s != c) {
768 /* We *are* in trouble ... */
769 SSL_SESSION_list_remove(ctx, s);
770 SSL_SESSION_free(s);
771 /*
772 * ... so pretend the other session did not exist in cache
773 * (we cannot handle two SSL_SESSION structures with identical
774 * session ID in the same cache, which could happen e.g. when
775 * two threads concurrently obtain the same session from an
776 * external cache).
777 */
778 s = NULL;
779 }
780
781 /* Put at the head of the queue unless it is already in the cache */
782 if (s == NULL)
783 SSL_SESSION_list_add(ctx, c);
784
785 if (s != NULL) {
786 /*
787 * existing cache entry -- decrement previously incremented
788 * reference count because it already takes into account the
789 * cache.
790 */
791 SSL_SESSION_free(s); /* s == c */
792 ret = 0;
793 } else {
794 /*
795 * New cache entry -- remove old ones if cache has become
796 * too large.
797 */
798
799 ret = 1;
800
801 if (SSL_CTX_sess_get_cache_size(ctx) > 0) {
802 while (SSL_CTX_sess_number(ctx) >
803 SSL_CTX_sess_get_cache_size(ctx)) {
804 if (!remove_session_lock(ctx,
805 ctx->session_cache_tail, 0))
806 break;
807 else
808 ctx->stats.sess_cache_full++;
809 }
810 }
811 }
812 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
813 return (ret);
814}
815LSSL_ALIAS(SSL_CTX_add_session);
816
817int
818SSL_CTX_remove_session(SSL_CTX *ctx, SSL_SESSION *c)
819{
820 return remove_session_lock(ctx, c, 1);
821}
822LSSL_ALIAS(SSL_CTX_remove_session);
823
824static int
825remove_session_lock(SSL_CTX *ctx, SSL_SESSION *c, int lck)
826{
827 SSL_SESSION *r;
828 int ret = 0;
829
830 if (c == NULL || c->session_id_length == 0)
831 return 0;
832
833 if (lck)
834 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
835 if ((r = lh_SSL_SESSION_retrieve(ctx->sessions, c)) == c) {
836 ret = 1;
837 r = lh_SSL_SESSION_delete(ctx->sessions, c);
838 SSL_SESSION_list_remove(ctx, c);
839 }
840 if (lck)
841 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
842
843 if (ret) {
844 r->not_resumable = 1;
845 if (ctx->remove_session_cb != NULL)
846 ctx->remove_session_cb(ctx, r);
847 SSL_SESSION_free(r);
848 }
849
850 return ret;
851}
852
853void
854SSL_SESSION_free(SSL_SESSION *ss)
855{
856 int i;
857
858 if (ss == NULL)
859 return;
860
861 i = CRYPTO_add(&ss->references, -1, CRYPTO_LOCK_SSL_SESSION);
862 if (i > 0)
863 return;
864
865 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
866
867 explicit_bzero(ss->master_key, sizeof ss->master_key);
868 explicit_bzero(ss->session_id, sizeof ss->session_id);
869
870 X509_free(ss->peer_cert);
871
872 free(ss->tlsext_hostname);
873 free(ss->tlsext_tick);
874 free(ss->tlsext_ecpointformatlist);
875 free(ss->tlsext_supportedgroups);
876
877 tls13_secret_cleanup(&ss->resumption_master_secret);
878
879 freezero(ss, sizeof(*ss));
880}
881LSSL_ALIAS(SSL_SESSION_free);
882
883int
884SSL_SESSION_up_ref(SSL_SESSION *ss)
885{
886 return CRYPTO_add(&ss->references, 1, CRYPTO_LOCK_SSL_SESSION) > 1;
887}
888LSSL_ALIAS(SSL_SESSION_up_ref);
889
890int
891SSL_set_session(SSL *s, SSL_SESSION *session)
892{
893 const SSL_METHOD *method;
894
895 if (session == NULL) {
896 SSL_SESSION_free(s->session);
897 s->session = NULL;
898
899 return SSL_set_ssl_method(s, s->ctx->method);
900 }
901
902 if ((method = ssl_get_method(session->ssl_version)) == NULL) {
903 SSLerror(s, SSL_R_UNABLE_TO_FIND_SSL_METHOD);
904 return (0);
905 }
906
907 if (!SSL_set_ssl_method(s, method))
908 return (0);
909
910 CRYPTO_add(&session->references, 1, CRYPTO_LOCK_SSL_SESSION);
911 SSL_SESSION_free(s->session);
912 s->session = session;
913 s->verify_result = s->session->verify_result;
914
915 return (1);
916}
917LSSL_ALIAS(SSL_set_session);
918
919size_t
920SSL_SESSION_get_master_key(const SSL_SESSION *ss, unsigned char *out,
921 size_t max_out)
922{
923 size_t len = ss->master_key_length;
924
925 if (out == NULL)
926 return len;
927
928 if (len > max_out)
929 len = max_out;
930
931 memcpy(out, ss->master_key, len);
932
933 return len;
934}
935LSSL_ALIAS(SSL_SESSION_get_master_key);
936
937long
938SSL_SESSION_set_timeout(SSL_SESSION *s, long t)
939{
940 if (s == NULL)
941 return (0);
942 s->timeout = t;
943 return (1);
944}
945LSSL_ALIAS(SSL_SESSION_set_timeout);
946
947long
948SSL_SESSION_get_timeout(const SSL_SESSION *s)
949{
950 if (s == NULL)
951 return (0);
952 return (s->timeout);
953}
954LSSL_ALIAS(SSL_SESSION_get_timeout);
955
956/* XXX 2038 */
957long
958SSL_SESSION_get_time(const SSL_SESSION *s)
959{
960 if (s == NULL)
961 return (0);
962 return (s->time);
963}
964LSSL_ALIAS(SSL_SESSION_get_time);
965
966/* XXX 2038 */
967long
968SSL_SESSION_set_time(SSL_SESSION *s, long t)
969{
970 if (s == NULL)
971 return (0);
972 s->time = t;
973 return (t);
974}
975LSSL_ALIAS(SSL_SESSION_set_time);
976
977int
978SSL_SESSION_get_protocol_version(const SSL_SESSION *s)
979{
980 return s->ssl_version;
981}
982LSSL_ALIAS(SSL_SESSION_get_protocol_version);
983
984const SSL_CIPHER *
985SSL_SESSION_get0_cipher(const SSL_SESSION *s)
986{
987 return ssl3_get_cipher_by_value(s->cipher_value);
988}
989LSSL_ALIAS(SSL_SESSION_get0_cipher);
990
991X509 *
992SSL_SESSION_get0_peer(SSL_SESSION *s)
993{
994 return s->peer_cert;
995}
996LSSL_ALIAS(SSL_SESSION_get0_peer);
997
998int
999SSL_SESSION_set1_id(SSL_SESSION *s, const unsigned char *sid,
1000 unsigned int sid_len)
1001{
1002 if (sid_len > SSL_MAX_SSL_SESSION_ID_LENGTH) {
1003 SSLerrorx(SSL_R_SSL_SESSION_ID_TOO_LONG);
1004 return 0;
1005 }
1006 s->session_id_length = sid_len;
1007 memmove(s->session_id, sid, sid_len);
1008 return 1;
1009}
1010LSSL_ALIAS(SSL_SESSION_set1_id);
1011
1012int
1013SSL_SESSION_set1_id_context(SSL_SESSION *s, const unsigned char *sid_ctx,
1014 unsigned int sid_ctx_len)
1015{
1016 if (sid_ctx_len > SSL_MAX_SID_CTX_LENGTH) {
1017 SSLerrorx(SSL_R_SSL_SESSION_ID_CONTEXT_TOO_LONG);
1018 return 0;
1019 }
1020 s->sid_ctx_length = sid_ctx_len;
1021 memcpy(s->sid_ctx, sid_ctx, sid_ctx_len);
1022
1023 return 1;
1024}
1025LSSL_ALIAS(SSL_SESSION_set1_id_context);
1026
1027int
1028SSL_SESSION_is_resumable(const SSL_SESSION *s)
1029{
1030 return 0;
1031}
1032LSSL_ALIAS(SSL_SESSION_is_resumable);
1033
1034long
1035SSL_CTX_set_timeout(SSL_CTX *s, long t)
1036{
1037 long l;
1038
1039 if (s == NULL)
1040 return (0);
1041 l = s->session_timeout;
1042 s->session_timeout = t;
1043
1044 return (l);
1045}
1046LSSL_ALIAS(SSL_CTX_set_timeout);
1047
1048long
1049SSL_CTX_get_timeout(const SSL_CTX *s)
1050{
1051 if (s == NULL)
1052 return (0);
1053 return (s->session_timeout);
1054}
1055LSSL_ALIAS(SSL_CTX_get_timeout);
1056
1057int
1058SSL_set_session_secret_cb(SSL *s, int (*tls_session_secret_cb)(SSL *s,
1059 void *secret, int *secret_len, STACK_OF(SSL_CIPHER) *peer_ciphers,
1060 const SSL_CIPHER **cipher, void *arg), void *arg)
1061{
1062 if (s == NULL)
1063 return (0);
1064 s->tls_session_secret_cb = tls_session_secret_cb;
1065 s->tls_session_secret_cb_arg = arg;
1066 return (1);
1067}
1068LSSL_ALIAS(SSL_set_session_secret_cb);
1069
1070int
1071SSL_set_session_ticket_ext_cb(SSL *s, tls_session_ticket_ext_cb_fn cb,
1072 void *arg)
1073{
1074 if (s == NULL)
1075 return (0);
1076 s->tls_session_ticket_ext_cb = cb;
1077 s->tls_session_ticket_ext_cb_arg = arg;
1078 return (1);
1079}
1080LSSL_ALIAS(SSL_set_session_ticket_ext_cb);
1081
1082int
1083SSL_set_session_ticket_ext(SSL *s, void *ext_data, int ext_len)
1084{
1085 if (s->version >= TLS1_VERSION) {
1086 free(s->tlsext_session_ticket);
1087 s->tlsext_session_ticket =
1088 malloc(sizeof(TLS_SESSION_TICKET_EXT) + ext_len);
1089 if (!s->tlsext_session_ticket) {
1090 SSLerror(s, ERR_R_MALLOC_FAILURE);
1091 return 0;
1092 }
1093
1094 if (ext_data) {
1095 s->tlsext_session_ticket->length = ext_len;
1096 s->tlsext_session_ticket->data =
1097 s->tlsext_session_ticket + 1;
1098 memcpy(s->tlsext_session_ticket->data,
1099 ext_data, ext_len);
1100 } else {
1101 s->tlsext_session_ticket->length = 0;
1102 s->tlsext_session_ticket->data = NULL;
1103 }
1104
1105 return 1;
1106 }
1107
1108 return 0;
1109}
1110LSSL_ALIAS(SSL_set_session_ticket_ext);
1111
1112typedef struct timeout_param_st {
1113 SSL_CTX *ctx;
1114 long time;
1115 struct lhash_st_SSL_SESSION *cache;
1116} TIMEOUT_PARAM;
1117
1118static void
1119timeout_doall_arg(SSL_SESSION *s, TIMEOUT_PARAM *p)
1120{
1121 if ((p->time == 0) || (p->time > (s->time + s->timeout))) {
1122 /* timeout */
1123 /* The reason we don't call SSL_CTX_remove_session() is to
1124 * save on locking overhead */
1125 (void)lh_SSL_SESSION_delete(p->cache, s);
1126 SSL_SESSION_list_remove(p->ctx, s);
1127 s->not_resumable = 1;
1128 if (p->ctx->remove_session_cb != NULL)
1129 p->ctx->remove_session_cb(p->ctx, s);
1130 SSL_SESSION_free(s);
1131 }
1132}
1133
1134static void
1135timeout_LHASH_DOALL_ARG(void *arg1, void *arg2)
1136{
1137 SSL_SESSION *a = arg1;
1138 TIMEOUT_PARAM *b = arg2;
1139
1140 timeout_doall_arg(a, b);
1141}
1142
1143/* XXX 2038 */
1144void
1145SSL_CTX_flush_sessions(SSL_CTX *s, long t)
1146{
1147 TIMEOUT_PARAM tp;
1148
1149 tp.ctx = s;
1150 tp.cache = s->sessions;
1151 if (tp.cache == NULL)
1152 return;
1153 tp.time = t;
1154
1155 CRYPTO_w_lock(CRYPTO_LOCK_SSL_CTX);
1156 lh_SSL_SESSION_doall_arg(tp.cache, timeout_LHASH_DOALL_ARG,
1157 TIMEOUT_PARAM, &tp);
1158 CRYPTO_w_unlock(CRYPTO_LOCK_SSL_CTX);
1159}
1160LSSL_ALIAS(SSL_CTX_flush_sessions);
1161
1162int
1163ssl_clear_bad_session(SSL *s)
1164{
1165 if ((s->session != NULL) && !(s->shutdown & SSL_SENT_SHUTDOWN) &&
1166 !(SSL_in_init(s) || SSL_in_before(s))) {
1167 SSL_CTX_remove_session(s->ctx, s->session);
1168 return (1);
1169 } else
1170 return (0);
1171}
1172
1173/* locked by SSL_CTX in the calling function */
1174static void
1175SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s)
1176{
1177 if (s->next == NULL || s->prev == NULL)
1178 return;
1179
1180 if (s->next == (SSL_SESSION *)&(ctx->session_cache_tail)) {
1181 /* last element in list */
1182 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
1183 /* only one element in list */
1184 ctx->session_cache_head = NULL;
1185 ctx->session_cache_tail = NULL;
1186 } else {
1187 ctx->session_cache_tail = s->prev;
1188 s->prev->next =
1189 (SSL_SESSION *)&(ctx->session_cache_tail);
1190 }
1191 } else {
1192 if (s->prev == (SSL_SESSION *)&(ctx->session_cache_head)) {
1193 /* first element in list */
1194 ctx->session_cache_head = s->next;
1195 s->next->prev =
1196 (SSL_SESSION *)&(ctx->session_cache_head);
1197 } else {
1198 /* middle of list */
1199 s->next->prev = s->prev;
1200 s->prev->next = s->next;
1201 }
1202 }
1203 s->prev = s->next = NULL;
1204}
1205
1206static void
1207SSL_SESSION_list_add(SSL_CTX *ctx, SSL_SESSION *s)
1208{
1209 if (s->next != NULL && s->prev != NULL)
1210 SSL_SESSION_list_remove(ctx, s);
1211
1212 if (ctx->session_cache_head == NULL) {
1213 ctx->session_cache_head = s;
1214 ctx->session_cache_tail = s;
1215 s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
1216 s->next = (SSL_SESSION *)&(ctx->session_cache_tail);
1217 } else {
1218 s->next = ctx->session_cache_head;
1219 s->next->prev = s;
1220 s->prev = (SSL_SESSION *)&(ctx->session_cache_head);
1221 ctx->session_cache_head = s;
1222 }
1223}
1224
1225void
1226SSL_CTX_sess_set_new_cb(SSL_CTX *ctx,
1227 int (*cb)(struct ssl_st *ssl, SSL_SESSION *sess)) {
1228 ctx->new_session_cb = cb;
1229}
1230LSSL_ALIAS(SSL_CTX_sess_set_new_cb);
1231
1232int
1233(*SSL_CTX_sess_get_new_cb(SSL_CTX *ctx))(SSL *ssl, SSL_SESSION *sess)
1234{
1235 return ctx->new_session_cb;
1236}
1237LSSL_ALIAS(SSL_CTX_sess_get_new_cb);
1238
1239void
1240SSL_CTX_sess_set_remove_cb(SSL_CTX *ctx,
1241 void (*cb)(SSL_CTX *ctx, SSL_SESSION *sess))
1242{
1243 ctx->remove_session_cb = cb;
1244}
1245LSSL_ALIAS(SSL_CTX_sess_set_remove_cb);
1246
1247void
1248(*SSL_CTX_sess_get_remove_cb(SSL_CTX *ctx))(SSL_CTX * ctx, SSL_SESSION *sess)
1249{
1250 return ctx->remove_session_cb;
1251}
1252LSSL_ALIAS(SSL_CTX_sess_get_remove_cb);
1253
1254void
1255SSL_CTX_sess_set_get_cb(SSL_CTX *ctx, SSL_SESSION *(*cb)(struct ssl_st *ssl,
1256 const unsigned char *data, int len, int *copy))
1257{
1258 ctx->get_session_cb = cb;
1259}
1260LSSL_ALIAS(SSL_CTX_sess_set_get_cb);
1261
1262SSL_SESSION *
1263(*SSL_CTX_sess_get_get_cb(SSL_CTX *ctx))(SSL *ssl, const unsigned char *data,
1264 int len, int *copy)
1265{
1266 return ctx->get_session_cb;
1267}
1268LSSL_ALIAS(SSL_CTX_sess_get_get_cb);
1269
1270void
1271SSL_CTX_set_info_callback(SSL_CTX *ctx,
1272 void (*cb)(const SSL *ssl, int type, int val))
1273{
1274 ctx->info_callback = cb;
1275}
1276LSSL_ALIAS(SSL_CTX_set_info_callback);
1277
1278void
1279(*SSL_CTX_get_info_callback(SSL_CTX *ctx))(const SSL *ssl, int type, int val)
1280{
1281 return ctx->info_callback;
1282}
1283LSSL_ALIAS(SSL_CTX_get_info_callback);
1284
1285void
1286SSL_CTX_set_client_cert_cb(SSL_CTX *ctx,
1287 int (*cb)(SSL *ssl, X509 **x509, EVP_PKEY **pkey))
1288{
1289 ctx->client_cert_cb = cb;
1290}
1291LSSL_ALIAS(SSL_CTX_set_client_cert_cb);
1292
1293int
1294(*SSL_CTX_get_client_cert_cb(SSL_CTX *ctx))(SSL * ssl, X509 ** x509,
1295 EVP_PKEY **pkey)
1296{
1297 return ctx->client_cert_cb;
1298}
1299LSSL_ALIAS(SSL_CTX_get_client_cert_cb);
1300
1301void
1302SSL_CTX_set_cookie_generate_cb(SSL_CTX *ctx,
1303 int (*cb)(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len))
1304{
1305 ctx->app_gen_cookie_cb = cb;
1306}
1307LSSL_ALIAS(SSL_CTX_set_cookie_generate_cb);
1308
1309void
1310SSL_CTX_set_cookie_verify_cb(SSL_CTX *ctx,
1311 int (*cb)(SSL *ssl, const unsigned char *cookie, unsigned int cookie_len))
1312{
1313 ctx->app_verify_cookie_cb = cb;
1314}
1315LSSL_ALIAS(SSL_CTX_set_cookie_verify_cb);
1316
1317int
1318PEM_write_SSL_SESSION(FILE *fp, SSL_SESSION *x)
1319{
1320 return PEM_ASN1_write((i2d_of_void *)i2d_SSL_SESSION,
1321 PEM_STRING_SSL_SESSION, fp, x, NULL, NULL, 0, NULL, NULL);
1322}
1323LSSL_ALIAS(PEM_write_SSL_SESSION);
1324
1325SSL_SESSION *
1326PEM_read_SSL_SESSION(FILE *fp, SSL_SESSION **x, pem_password_cb *cb, void *u)
1327{
1328 return PEM_ASN1_read((d2i_of_void *)d2i_SSL_SESSION,
1329 PEM_STRING_SSL_SESSION, fp, (void **)x, cb, u);
1330}
1331LSSL_ALIAS(PEM_read_SSL_SESSION);
1332
1333SSL_SESSION *
1334PEM_read_bio_SSL_SESSION(BIO *bp, SSL_SESSION **x, pem_password_cb *cb, void *u)
1335{
1336 return PEM_ASN1_read_bio((d2i_of_void *)d2i_SSL_SESSION,
1337 PEM_STRING_SSL_SESSION, bp, (void **)x, cb, u);
1338}
1339LSSL_ALIAS(PEM_read_bio_SSL_SESSION);
1340
1341int
1342PEM_write_bio_SSL_SESSION(BIO *bp, SSL_SESSION *x)
1343{
1344 return PEM_ASN1_write_bio((i2d_of_void *)i2d_SSL_SESSION,
1345 PEM_STRING_SSL_SESSION, bp, x, NULL, NULL, 0, NULL, NULL);
1346}
1347LSSL_ALIAS(PEM_write_bio_SSL_SESSION);
diff --git a/src/lib/libssl/ssl_sigalgs.c b/src/lib/libssl/ssl_sigalgs.c
deleted file mode 100644
index 18d71f6b95..0000000000
--- a/src/lib/libssl/ssl_sigalgs.c
+++ /dev/null
@@ -1,361 +0,0 @@
1/* $OpenBSD: ssl_sigalgs.c,v 1.50 2024/07/09 13:43:57 beck Exp $ */
2/*
3 * Copyright (c) 2018-2020 Bob Beck <beck@openbsd.org>
4 * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
13 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
15 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
16 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <string.h>
20#include <stdlib.h>
21
22#include <openssl/evp.h>
23#include <openssl/opensslconf.h>
24
25#include "bytestring.h"
26#include "ssl_local.h"
27#include "ssl_sigalgs.h"
28#include "tls13_internal.h"
29
30const struct ssl_sigalg sigalgs[] = {
31 {
32 .value = SIGALG_RSA_PKCS1_SHA512,
33 .key_type = EVP_PKEY_RSA,
34 .md = EVP_sha512,
35 .security_level = 5,
36 },
37 {
38 .value = SIGALG_ECDSA_SECP521R1_SHA512,
39 .key_type = EVP_PKEY_EC,
40 .md = EVP_sha512,
41 .security_level = 5,
42 .group_nid = NID_secp521r1,
43 },
44 {
45 .value = SIGALG_RSA_PKCS1_SHA384,
46 .key_type = EVP_PKEY_RSA,
47 .md = EVP_sha384,
48 .security_level = 4,
49 },
50 {
51 .value = SIGALG_ECDSA_SECP384R1_SHA384,
52 .key_type = EVP_PKEY_EC,
53 .md = EVP_sha384,
54 .security_level = 4,
55 .group_nid = NID_secp384r1,
56 },
57 {
58 .value = SIGALG_RSA_PKCS1_SHA256,
59 .key_type = EVP_PKEY_RSA,
60 .md = EVP_sha256,
61 .security_level = 3,
62 },
63 {
64 .value = SIGALG_ECDSA_SECP256R1_SHA256,
65 .key_type = EVP_PKEY_EC,
66 .md = EVP_sha256,
67 .security_level = 3,
68 .group_nid = NID_X9_62_prime256v1,
69 },
70 {
71 .value = SIGALG_RSA_PSS_RSAE_SHA256,
72 .key_type = EVP_PKEY_RSA,
73 .md = EVP_sha256,
74 .security_level = 3,
75 .flags = SIGALG_FLAG_RSA_PSS,
76 },
77 {
78 .value = SIGALG_RSA_PSS_RSAE_SHA384,
79 .key_type = EVP_PKEY_RSA,
80 .md = EVP_sha384,
81 .security_level = 4,
82 .flags = SIGALG_FLAG_RSA_PSS,
83 },
84 {
85 .value = SIGALG_RSA_PSS_RSAE_SHA512,
86 .key_type = EVP_PKEY_RSA,
87 .md = EVP_sha512,
88 .security_level = 5,
89 .flags = SIGALG_FLAG_RSA_PSS,
90 },
91 {
92 .value = SIGALG_RSA_PSS_PSS_SHA256,
93 .key_type = EVP_PKEY_RSA,
94 .md = EVP_sha256,
95 .security_level = 3,
96 .flags = SIGALG_FLAG_RSA_PSS,
97 },
98 {
99 .value = SIGALG_RSA_PSS_PSS_SHA384,
100 .key_type = EVP_PKEY_RSA,
101 .md = EVP_sha384,
102 .security_level = 4,
103 .flags = SIGALG_FLAG_RSA_PSS,
104 },
105 {
106 .value = SIGALG_RSA_PSS_PSS_SHA512,
107 .key_type = EVP_PKEY_RSA,
108 .md = EVP_sha512,
109 .security_level = 5,
110 .flags = SIGALG_FLAG_RSA_PSS,
111 },
112 {
113 .value = SIGALG_RSA_PKCS1_SHA224,
114 .key_type = EVP_PKEY_RSA,
115 .md = EVP_sha224,
116 .security_level = 2,
117 },
118 {
119 .value = SIGALG_ECDSA_SECP224R1_SHA224,
120 .key_type = EVP_PKEY_EC,
121 .md = EVP_sha224,
122 .security_level = 2,
123 },
124 {
125 .value = SIGALG_RSA_PKCS1_SHA1,
126 .key_type = EVP_PKEY_RSA,
127 .md = EVP_sha1,
128 .security_level = 1,
129 },
130 {
131 .value = SIGALG_ECDSA_SHA1,
132 .key_type = EVP_PKEY_EC,
133 .md = EVP_sha1,
134 .security_level = 1,
135 },
136 {
137 .value = SIGALG_RSA_PKCS1_MD5_SHA1,
138 .key_type = EVP_PKEY_RSA,
139 .md = EVP_md5_sha1,
140 .security_level = 1,
141 },
142 {
143 .value = SIGALG_NONE,
144 },
145};
146
147/* Sigalgs for TLSv1.3, in preference order. */
148const uint16_t tls13_sigalgs[] = {
149 SIGALG_RSA_PSS_RSAE_SHA512,
150 SIGALG_RSA_PKCS1_SHA512,
151 SIGALG_ECDSA_SECP521R1_SHA512,
152 SIGALG_RSA_PSS_RSAE_SHA384,
153 SIGALG_RSA_PKCS1_SHA384,
154 SIGALG_ECDSA_SECP384R1_SHA384,
155 SIGALG_RSA_PSS_RSAE_SHA256,
156 SIGALG_RSA_PKCS1_SHA256,
157 SIGALG_ECDSA_SECP256R1_SHA256,
158};
159const size_t tls13_sigalgs_len = (sizeof(tls13_sigalgs) / sizeof(tls13_sigalgs[0]));
160
161/* Sigalgs for TLSv1.2, in preference order. */
162const uint16_t tls12_sigalgs[] = {
163 SIGALG_RSA_PSS_RSAE_SHA512,
164 SIGALG_RSA_PKCS1_SHA512,
165 SIGALG_ECDSA_SECP521R1_SHA512,
166 SIGALG_RSA_PSS_RSAE_SHA384,
167 SIGALG_RSA_PKCS1_SHA384,
168 SIGALG_ECDSA_SECP384R1_SHA384,
169 SIGALG_RSA_PSS_RSAE_SHA256,
170 SIGALG_RSA_PKCS1_SHA256,
171 SIGALG_ECDSA_SECP256R1_SHA256,
172 SIGALG_RSA_PKCS1_SHA1, /* XXX */
173 SIGALG_ECDSA_SHA1, /* XXX */
174};
175const size_t tls12_sigalgs_len = (sizeof(tls12_sigalgs) / sizeof(tls12_sigalgs[0]));
176
177static void
178ssl_sigalgs_for_version(uint16_t tls_version, const uint16_t **out_values,
179 size_t *out_len)
180{
181 if (tls_version >= TLS1_3_VERSION) {
182 *out_values = tls13_sigalgs;
183 *out_len = tls13_sigalgs_len;
184 } else {
185 *out_values = tls12_sigalgs;
186 *out_len = tls12_sigalgs_len;
187 }
188}
189
190static const struct ssl_sigalg *
191ssl_sigalg_lookup(uint16_t value)
192{
193 int i;
194
195 for (i = 0; sigalgs[i].value != SIGALG_NONE; i++) {
196 if (sigalgs[i].value == value)
197 return &sigalgs[i];
198 }
199
200 return NULL;
201}
202
203static const struct ssl_sigalg *
204ssl_sigalg_from_value(SSL *s, uint16_t value)
205{
206 const uint16_t *values;
207 size_t len;
208 int i;
209
210 ssl_sigalgs_for_version(s->s3->hs.negotiated_tls_version,
211 &values, &len);
212
213 for (i = 0; i < len; i++) {
214 if (values[i] == value)
215 return ssl_sigalg_lookup(value);
216 }
217
218 return NULL;
219}
220
221int
222ssl_sigalgs_build(uint16_t tls_version, CBB *cbb, int security_level)
223{
224 const struct ssl_sigalg *sigalg;
225 const uint16_t *values;
226 size_t len;
227 size_t i;
228 int ret = 0;
229
230 ssl_sigalgs_for_version(tls_version, &values, &len);
231
232 /* Add values in order as long as they are supported. */
233 for (i = 0; i < len; i++) {
234 /* Do not allow the legacy value for < 1.2 to be used. */
235 if (values[i] == SIGALG_RSA_PKCS1_MD5_SHA1)
236 return 0;
237 if ((sigalg = ssl_sigalg_lookup(values[i])) == NULL)
238 return 0;
239 if (sigalg->security_level < security_level)
240 continue;
241
242 if (!CBB_add_u16(cbb, values[i]))
243 return 0;
244
245 ret = 1;
246 }
247 return ret;
248}
249
250static const struct ssl_sigalg *
251ssl_sigalg_for_legacy(SSL *s, EVP_PKEY *pkey)
252{
253 if (SSL_get_security_level(s) > 1)
254 return NULL;
255
256 /* Default signature algorithms used for TLSv1.2 and earlier. */
257 switch (EVP_PKEY_id(pkey)) {
258 case EVP_PKEY_RSA:
259 if (s->s3->hs.negotiated_tls_version < TLS1_2_VERSION)
260 return ssl_sigalg_lookup(SIGALG_RSA_PKCS1_MD5_SHA1);
261 return ssl_sigalg_lookup(SIGALG_RSA_PKCS1_SHA1);
262 case EVP_PKEY_EC:
263 return ssl_sigalg_lookup(SIGALG_ECDSA_SHA1);
264 }
265 SSLerror(s, SSL_R_UNKNOWN_PKEY_TYPE);
266 return NULL;
267}
268
269static int
270ssl_sigalg_pkey_ok(SSL *s, const struct ssl_sigalg *sigalg, EVP_PKEY *pkey)
271{
272 if (sigalg == NULL || pkey == NULL)
273 return 0;
274 if (sigalg->key_type != EVP_PKEY_id(pkey))
275 return 0;
276
277 /* RSA PSS must have a sufficiently large RSA key. */
278 if ((sigalg->flags & SIGALG_FLAG_RSA_PSS)) {
279 if (EVP_PKEY_id(pkey) != EVP_PKEY_RSA ||
280 EVP_PKEY_size(pkey) < (2 * EVP_MD_size(sigalg->md()) + 2))
281 return 0;
282 }
283
284 if (!ssl_security_sigalg_check(s, pkey))
285 return 0;
286
287 if (s->s3->hs.negotiated_tls_version < TLS1_3_VERSION)
288 return 1;
289
290 /* RSA cannot be used without PSS in TLSv1.3. */
291 if (sigalg->key_type == EVP_PKEY_RSA &&
292 (sigalg->flags & SIGALG_FLAG_RSA_PSS) == 0)
293 return 0;
294
295 /* Ensure that group matches for EC keys. */
296 if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
297 if (sigalg->group_nid == 0)
298 return 0;
299 if (EC_GROUP_get_curve_name(EC_KEY_get0_group(
300 EVP_PKEY_get0_EC_KEY(pkey))) != sigalg->group_nid)
301 return 0;
302 }
303
304 return 1;
305}
306
307const struct ssl_sigalg *
308ssl_sigalg_select(SSL *s, EVP_PKEY *pkey)
309{
310 CBS cbs;
311
312 if (!SSL_USE_SIGALGS(s))
313 return ssl_sigalg_for_legacy(s, pkey);
314
315 /*
316 * RFC 5246 allows a TLS 1.2 client to send no sigalgs extension,
317 * in which case the server must use the default.
318 */
319 if (s->s3->hs.negotiated_tls_version < TLS1_3_VERSION &&
320 s->s3->hs.sigalgs == NULL)
321 return ssl_sigalg_for_legacy(s, pkey);
322
323 /*
324 * If we get here, we have client or server sent sigalgs, use one.
325 */
326 CBS_init(&cbs, s->s3->hs.sigalgs, s->s3->hs.sigalgs_len);
327 while (CBS_len(&cbs) > 0) {
328 const struct ssl_sigalg *sigalg;
329 uint16_t sigalg_value;
330
331 if (!CBS_get_u16(&cbs, &sigalg_value))
332 return NULL;
333
334 if ((sigalg = ssl_sigalg_from_value(s, sigalg_value)) == NULL)
335 continue;
336 if (ssl_sigalg_pkey_ok(s, sigalg, pkey))
337 return sigalg;
338 }
339
340 return NULL;
341}
342
343const struct ssl_sigalg *
344ssl_sigalg_for_peer(SSL *s, EVP_PKEY *pkey, uint16_t sigalg_value)
345{
346 const struct ssl_sigalg *sigalg;
347
348 if (!SSL_USE_SIGALGS(s))
349 return ssl_sigalg_for_legacy(s, pkey);
350
351 if ((sigalg = ssl_sigalg_from_value(s, sigalg_value)) == NULL) {
352 SSLerror(s, SSL_R_UNKNOWN_DIGEST);
353 return NULL;
354 }
355 if (!ssl_sigalg_pkey_ok(s, sigalg, pkey)) {
356 SSLerror(s, SSL_R_WRONG_SIGNATURE_TYPE);
357 return NULL;
358 }
359
360 return sigalg;
361}
diff --git a/src/lib/libssl/ssl_sigalgs.h b/src/lib/libssl/ssl_sigalgs.h
deleted file mode 100644
index 5211ec6b62..0000000000
--- a/src/lib/libssl/ssl_sigalgs.h
+++ /dev/null
@@ -1,71 +0,0 @@
1/* $OpenBSD: ssl_sigalgs.h,v 1.27 2024/02/03 15:58:34 beck Exp $ */
2/*
3 * Copyright (c) 2018-2019 Bob Beck <beck@openbsd.org>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef HEADER_SSL_SIGALGS_H
19#define HEADER_SSL_SIGALGS_H
20
21__BEGIN_HIDDEN_DECLS
22
23#define SIGALG_NONE 0x0000
24
25/*
26 * RFC 8446 Section 4.2.3
27 * RFC 5246 Section 7.4.1.4.1
28 */
29#define SIGALG_RSA_PKCS1_SHA224 0x0301
30#define SIGALG_RSA_PKCS1_SHA256 0x0401
31#define SIGALG_RSA_PKCS1_SHA384 0x0501
32#define SIGALG_RSA_PKCS1_SHA512 0x0601
33#define SIGALG_ECDSA_SECP224R1_SHA224 0x0303
34#define SIGALG_ECDSA_SECP256R1_SHA256 0x0403
35#define SIGALG_ECDSA_SECP384R1_SHA384 0x0503
36#define SIGALG_ECDSA_SECP521R1_SHA512 0x0603
37#define SIGALG_RSA_PSS_RSAE_SHA256 0x0804
38#define SIGALG_RSA_PSS_RSAE_SHA384 0x0805
39#define SIGALG_RSA_PSS_RSAE_SHA512 0x0806
40#define SIGALG_ED25519 0x0807
41#define SIGALG_ED448 0x0808
42#define SIGALG_RSA_PSS_PSS_SHA256 0x0809
43#define SIGALG_RSA_PSS_PSS_SHA384 0x080a
44#define SIGALG_RSA_PSS_PSS_SHA512 0x080b
45#define SIGALG_RSA_PKCS1_SHA1 0x0201
46#define SIGALG_ECDSA_SHA1 0x0203
47#define SIGALG_PRIVATE_START 0xFE00
48#define SIGALG_PRIVATE_END 0xFFFF
49
50/* Legacy sigalg for < TLSv1.2 same value as BoringSSL uses. */
51#define SIGALG_RSA_PKCS1_MD5_SHA1 0xFF01
52
53#define SIGALG_FLAG_RSA_PSS 0x00000001
54
55struct ssl_sigalg {
56 uint16_t value;
57 int key_type;
58 const EVP_MD *(*md)(void);
59 int security_level;
60 int group_nid;
61 int flags;
62};
63
64int ssl_sigalgs_build(uint16_t tls_version, CBB *cbb, int security_level);
65const struct ssl_sigalg *ssl_sigalg_select(SSL *s, EVP_PKEY *pkey);
66const struct ssl_sigalg *ssl_sigalg_for_peer(SSL *s, EVP_PKEY *pkey,
67 uint16_t sigalg_value);
68
69__END_HIDDEN_DECLS
70
71#endif
diff --git a/src/lib/libssl/ssl_srvr.c b/src/lib/libssl/ssl_srvr.c
deleted file mode 100644
index db4ba38b51..0000000000
--- a/src/lib/libssl/ssl_srvr.c
+++ /dev/null
@@ -1,2496 +0,0 @@
1/* $OpenBSD: ssl_srvr.c,v 1.166 2025/03/09 15:53:36 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 *
114 * Portions of the attached software ("Contribution") are developed by
115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
116 *
117 * The Contribution is licensed pursuant to the OpenSSL open source
118 * license provided above.
119 *
120 * ECC cipher suite support in OpenSSL originally written by
121 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
122 *
123 */
124/* ====================================================================
125 * Copyright 2005 Nokia. All rights reserved.
126 *
127 * The portions of the attached software ("Contribution") is developed by
128 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
129 * license.
130 *
131 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
132 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
133 * support (see RFC 4279) to OpenSSL.
134 *
135 * No patent licenses or other rights except those expressly stated in
136 * the OpenSSL open source license shall be deemed granted or received
137 * expressly, by implication, estoppel, or otherwise.
138 *
139 * No assurances are provided by Nokia that the Contribution does not
140 * infringe the patent or other intellectual property rights of any third
141 * party or that the license provides you with all the necessary rights
142 * to make use of the Contribution.
143 *
144 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
145 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
146 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
147 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
148 * OTHERWISE.
149 */
150
151#include <limits.h>
152#include <stdio.h>
153
154#include <openssl/bn.h>
155#include <openssl/buffer.h>
156#include <openssl/curve25519.h>
157#include <openssl/evp.h>
158#include <openssl/dh.h>
159#include <openssl/hmac.h>
160#include <openssl/md5.h>
161#include <openssl/objects.h>
162#include <openssl/opensslconf.h>
163#include <openssl/x509.h>
164
165#include "bytestring.h"
166#include "crypto_internal.h"
167#include "dtls_local.h"
168#include "ssl_local.h"
169#include "ssl_sigalgs.h"
170#include "ssl_tlsext.h"
171
172static int ssl3_get_client_hello(SSL *s);
173static int ssl3_send_dtls_hello_verify_request(SSL *s);
174static int ssl3_send_server_hello(SSL *s);
175static int ssl3_send_hello_request(SSL *s);
176static int ssl3_send_server_certificate(SSL *s);
177static int ssl3_send_server_key_exchange(SSL *s);
178static int ssl3_send_certificate_request(SSL *s);
179static int ssl3_send_server_done(SSL *s);
180static int ssl3_get_client_certificate(SSL *s);
181static int ssl3_get_client_key_exchange(SSL *s);
182static int ssl3_get_cert_verify(SSL *s);
183static int ssl3_send_newsession_ticket(SSL *s);
184static int ssl3_send_cert_status(SSL *s);
185static int ssl3_send_server_change_cipher_spec(SSL *s);
186static int ssl3_send_server_finished(SSL *s);
187static int ssl3_get_client_finished(SSL *s);
188
189int
190ssl3_accept(SSL *s)
191{
192 unsigned long alg_k;
193 int new_state, state, skip = 0;
194 int listen = 0;
195 int ret = -1;
196
197 ERR_clear_error();
198 errno = 0;
199
200 if (SSL_is_dtls(s))
201 listen = s->d1->listen;
202
203 /* init things to blank */
204 s->in_handshake++;
205 if (!SSL_in_init(s) || SSL_in_before(s))
206 SSL_clear(s);
207
208 if (SSL_is_dtls(s))
209 s->d1->listen = listen;
210
211 for (;;) {
212 state = s->s3->hs.state;
213
214 switch (s->s3->hs.state) {
215 case SSL_ST_RENEGOTIATE:
216 s->renegotiate = 1;
217 /* s->s3->hs.state=SSL_ST_ACCEPT; */
218
219 case SSL_ST_BEFORE:
220 case SSL_ST_ACCEPT:
221 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
222 case SSL_ST_OK|SSL_ST_ACCEPT:
223 s->server = 1;
224
225 ssl_info_callback(s, SSL_CB_HANDSHAKE_START, 1);
226
227 if (!ssl_legacy_stack_version(s, s->version)) {
228 SSLerror(s, ERR_R_INTERNAL_ERROR);
229 ret = -1;
230 goto end;
231 }
232
233 if (!ssl_supported_tls_version_range(s,
234 &s->s3->hs.our_min_tls_version,
235 &s->s3->hs.our_max_tls_version)) {
236 SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE);
237 ret = -1;
238 goto end;
239 }
240
241 if (!ssl_security_version(s,
242 s->s3->hs.our_min_tls_version)) {
243 SSLerror(s, SSL_R_VERSION_TOO_LOW);
244 ret = -1;
245 goto end;
246 }
247
248 if (!ssl3_setup_init_buffer(s)) {
249 ret = -1;
250 goto end;
251 }
252 if (!ssl3_setup_buffers(s)) {
253 ret = -1;
254 goto end;
255 }
256
257 s->init_num = 0;
258
259 if (s->s3->hs.state != SSL_ST_RENEGOTIATE) {
260 /*
261 * Ok, we now need to push on a buffering BIO
262 * so that the output is sent in a way that
263 * TCP likes :-)
264 */
265 if (!ssl_init_wbio_buffer(s, 1)) {
266 ret = -1;
267 goto end;
268 }
269
270 if (!tls1_transcript_init(s)) {
271 ret = -1;
272 goto end;
273 }
274
275 s->s3->hs.state = SSL3_ST_SR_CLNT_HELLO_A;
276 s->ctx->stats.sess_accept++;
277 } else if (!SSL_is_dtls(s) && !s->s3->send_connection_binding) {
278 /*
279 * Server attempting to renegotiate with
280 * client that doesn't support secure
281 * renegotiation.
282 */
283 SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
284 ssl3_send_alert(s, SSL3_AL_FATAL,
285 SSL_AD_HANDSHAKE_FAILURE);
286 ret = -1;
287 goto end;
288 } else {
289 /*
290 * s->s3->hs.state == SSL_ST_RENEGOTIATE,
291 * we will just send a HelloRequest.
292 */
293 s->ctx->stats.sess_accept_renegotiate++;
294 s->s3->hs.state = SSL3_ST_SW_HELLO_REQ_A;
295 }
296 break;
297
298 case SSL3_ST_SW_HELLO_REQ_A:
299 case SSL3_ST_SW_HELLO_REQ_B:
300 s->shutdown = 0;
301 if (SSL_is_dtls(s)) {
302 dtls1_clear_record_buffer(s);
303 dtls1_start_timer(s);
304 }
305 ret = ssl3_send_hello_request(s);
306 if (ret <= 0)
307 goto end;
308 if (SSL_is_dtls(s))
309 s->s3->hs.tls12.next_state = SSL3_ST_SR_CLNT_HELLO_A;
310 else
311 s->s3->hs.tls12.next_state = SSL3_ST_SW_HELLO_REQ_C;
312 s->s3->hs.state = SSL3_ST_SW_FLUSH;
313 s->init_num = 0;
314
315 if (SSL_is_dtls(s)) {
316 if (!tls1_transcript_init(s)) {
317 ret = -1;
318 goto end;
319 }
320 }
321 break;
322
323 case SSL3_ST_SW_HELLO_REQ_C:
324 s->s3->hs.state = SSL_ST_OK;
325 break;
326
327 case SSL3_ST_SR_CLNT_HELLO_A:
328 case SSL3_ST_SR_CLNT_HELLO_B:
329 case SSL3_ST_SR_CLNT_HELLO_C:
330 s->shutdown = 0;
331 if (SSL_is_dtls(s)) {
332 ret = ssl3_get_client_hello(s);
333 if (ret <= 0)
334 goto end;
335 dtls1_stop_timer(s);
336
337 if (ret == 1 &&
338 (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE))
339 s->s3->hs.state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A;
340 else
341 s->s3->hs.state = SSL3_ST_SW_SRVR_HELLO_A;
342
343 s->init_num = 0;
344
345 /*
346 * Reflect ClientHello sequence to remain
347 * stateless while listening.
348 */
349 if (listen) {
350 tls12_record_layer_reflect_seq_num(
351 s->rl);
352 }
353
354 /* If we're just listening, stop here */
355 if (listen && s->s3->hs.state == SSL3_ST_SW_SRVR_HELLO_A) {
356 ret = 2;
357 s->d1->listen = 0;
358 /*
359 * Set expected sequence numbers to
360 * continue the handshake.
361 */
362 s->d1->handshake_read_seq = 2;
363 s->d1->handshake_write_seq = 1;
364 s->d1->next_handshake_write_seq = 1;
365 goto end;
366 }
367 } else {
368 if (s->rwstate != SSL_X509_LOOKUP) {
369 ret = ssl3_get_client_hello(s);
370 if (ret <= 0)
371 goto end;
372 }
373
374 s->renegotiate = 2;
375 s->s3->hs.state = SSL3_ST_SW_SRVR_HELLO_A;
376 s->init_num = 0;
377 }
378 break;
379
380 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
381 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
382 ret = ssl3_send_dtls_hello_verify_request(s);
383 if (ret <= 0)
384 goto end;
385 s->s3->hs.state = SSL3_ST_SW_FLUSH;
386 s->s3->hs.tls12.next_state = SSL3_ST_SR_CLNT_HELLO_A;
387
388 /* HelloVerifyRequest resets Finished MAC. */
389 tls1_transcript_reset(s);
390 break;
391
392 case SSL3_ST_SW_SRVR_HELLO_A:
393 case SSL3_ST_SW_SRVR_HELLO_B:
394 if (SSL_is_dtls(s)) {
395 s->renegotiate = 2;
396 dtls1_start_timer(s);
397 }
398 ret = ssl3_send_server_hello(s);
399 if (ret <= 0)
400 goto end;
401 if (s->hit) {
402 if (s->tlsext_ticket_expected)
403 s->s3->hs.state = SSL3_ST_SW_SESSION_TICKET_A;
404 else
405 s->s3->hs.state = SSL3_ST_SW_CHANGE_A;
406 } else {
407 s->s3->hs.state = SSL3_ST_SW_CERT_A;
408 }
409 s->init_num = 0;
410 break;
411
412 case SSL3_ST_SW_CERT_A:
413 case SSL3_ST_SW_CERT_B:
414 /* Check if it is anon DH or anon ECDH. */
415 if (!(s->s3->hs.cipher->algorithm_auth &
416 SSL_aNULL)) {
417 if (SSL_is_dtls(s))
418 dtls1_start_timer(s);
419 ret = ssl3_send_server_certificate(s);
420 if (ret <= 0)
421 goto end;
422 if (s->tlsext_status_expected)
423 s->s3->hs.state = SSL3_ST_SW_CERT_STATUS_A;
424 else
425 s->s3->hs.state = SSL3_ST_SW_KEY_EXCH_A;
426 } else {
427 skip = 1;
428 s->s3->hs.state = SSL3_ST_SW_KEY_EXCH_A;
429 }
430 s->init_num = 0;
431 break;
432
433 case SSL3_ST_SW_KEY_EXCH_A:
434 case SSL3_ST_SW_KEY_EXCH_B:
435 alg_k = s->s3->hs.cipher->algorithm_mkey;
436
437 /*
438 * Only send if using a DH key exchange.
439 *
440 * For ECC ciphersuites, we send a ServerKeyExchange
441 * message only if the cipher suite is ECDHE. In other
442 * cases, the server certificate contains the server's
443 * public key for key exchange.
444 */
445 if (alg_k & (SSL_kDHE|SSL_kECDHE)) {
446 if (SSL_is_dtls(s))
447 dtls1_start_timer(s);
448 ret = ssl3_send_server_key_exchange(s);
449 if (ret <= 0)
450 goto end;
451 } else
452 skip = 1;
453
454 s->s3->hs.state = SSL3_ST_SW_CERT_REQ_A;
455 s->init_num = 0;
456 break;
457
458 case SSL3_ST_SW_CERT_REQ_A:
459 case SSL3_ST_SW_CERT_REQ_B:
460 /*
461 * Determine whether or not we need to request a
462 * certificate.
463 *
464 * Do not request a certificate if:
465 *
466 * - We did not ask for it (SSL_VERIFY_PEER is unset).
467 *
468 * - SSL_VERIFY_CLIENT_ONCE is set and we are
469 * renegotiating.
470 *
471 * - We are using an anonymous ciphersuites
472 * (see section "Certificate request" in SSL 3 drafts
473 * and in RFC 2246) ... except when the application
474 * insists on verification (against the specs, but
475 * s3_clnt.c accepts this for SSL 3).
476 */
477 if (!(s->verify_mode & SSL_VERIFY_PEER) ||
478 ((s->session->peer_cert != NULL) &&
479 (s->verify_mode & SSL_VERIFY_CLIENT_ONCE)) ||
480 ((s->s3->hs.cipher->algorithm_auth &
481 SSL_aNULL) && !(s->verify_mode &
482 SSL_VERIFY_FAIL_IF_NO_PEER_CERT))) {
483 /* No cert request. */
484 skip = 1;
485 s->s3->hs.tls12.cert_request = 0;
486 s->s3->hs.state = SSL3_ST_SW_SRVR_DONE_A;
487
488 if (!SSL_is_dtls(s))
489 tls1_transcript_free(s);
490 } else {
491 s->s3->hs.tls12.cert_request = 1;
492 if (SSL_is_dtls(s))
493 dtls1_start_timer(s);
494 ret = ssl3_send_certificate_request(s);
495 if (ret <= 0)
496 goto end;
497 s->s3->hs.state = SSL3_ST_SW_SRVR_DONE_A;
498 s->init_num = 0;
499 }
500 break;
501
502 case SSL3_ST_SW_SRVR_DONE_A:
503 case SSL3_ST_SW_SRVR_DONE_B:
504 if (SSL_is_dtls(s))
505 dtls1_start_timer(s);
506 ret = ssl3_send_server_done(s);
507 if (ret <= 0)
508 goto end;
509 s->s3->hs.tls12.next_state = SSL3_ST_SR_CERT_A;
510 s->s3->hs.state = SSL3_ST_SW_FLUSH;
511 s->init_num = 0;
512 break;
513
514 case SSL3_ST_SW_FLUSH:
515 /*
516 * This code originally checked to see if
517 * any data was pending using BIO_CTRL_INFO
518 * and then flushed. This caused problems
519 * as documented in PR#1939. The proposed
520 * fix doesn't completely resolve this issue
521 * as buggy implementations of BIO_CTRL_PENDING
522 * still exist. So instead we just flush
523 * unconditionally.
524 */
525 s->rwstate = SSL_WRITING;
526 if (BIO_flush(s->wbio) <= 0) {
527 if (SSL_is_dtls(s)) {
528 /* If the write error was fatal, stop trying. */
529 if (!BIO_should_retry(s->wbio)) {
530 s->rwstate = SSL_NOTHING;
531 s->s3->hs.state = s->s3->hs.tls12.next_state;
532 }
533 }
534 ret = -1;
535 goto end;
536 }
537 s->rwstate = SSL_NOTHING;
538 s->s3->hs.state = s->s3->hs.tls12.next_state;
539 break;
540
541 case SSL3_ST_SR_CERT_A:
542 case SSL3_ST_SR_CERT_B:
543 if (s->s3->hs.tls12.cert_request != 0) {
544 ret = ssl3_get_client_certificate(s);
545 if (ret <= 0)
546 goto end;
547 }
548 s->init_num = 0;
549 s->s3->hs.state = SSL3_ST_SR_KEY_EXCH_A;
550 break;
551
552 case SSL3_ST_SR_KEY_EXCH_A:
553 case SSL3_ST_SR_KEY_EXCH_B:
554 ret = ssl3_get_client_key_exchange(s);
555 if (ret <= 0)
556 goto end;
557
558 if (SSL_is_dtls(s)) {
559 s->s3->hs.state = SSL3_ST_SR_CERT_VRFY_A;
560 s->init_num = 0;
561 }
562
563 alg_k = s->s3->hs.cipher->algorithm_mkey;
564 if (SSL_USE_SIGALGS(s)) {
565 s->s3->hs.state = SSL3_ST_SR_CERT_VRFY_A;
566 s->init_num = 0;
567 if (!s->session->peer_cert)
568 break;
569 /*
570 * Freeze the transcript for use during client
571 * certificate verification.
572 */
573 tls1_transcript_freeze(s);
574 } else {
575 s->s3->hs.state = SSL3_ST_SR_CERT_VRFY_A;
576 s->init_num = 0;
577
578 tls1_transcript_free(s);
579
580 /*
581 * We need to get hashes here so if there is
582 * a client cert, it can be verified.
583 */
584 if (!tls1_transcript_hash_value(s,
585 s->s3->hs.tls12.cert_verify,
586 sizeof(s->s3->hs.tls12.cert_verify),
587 NULL)) {
588 ret = -1;
589 goto end;
590 }
591 }
592 break;
593
594 case SSL3_ST_SR_CERT_VRFY_A:
595 case SSL3_ST_SR_CERT_VRFY_B:
596 if (SSL_is_dtls(s))
597 s->d1->change_cipher_spec_ok = 1;
598 else
599 s->s3->flags |= SSL3_FLAGS_CCS_OK;
600
601 /* we should decide if we expected this one */
602 ret = ssl3_get_cert_verify(s);
603 if (ret <= 0)
604 goto end;
605 s->s3->hs.state = SSL3_ST_SR_FINISHED_A;
606 s->init_num = 0;
607 break;
608
609 case SSL3_ST_SR_FINISHED_A:
610 case SSL3_ST_SR_FINISHED_B:
611 if (SSL_is_dtls(s))
612 s->d1->change_cipher_spec_ok = 1;
613 else
614 s->s3->flags |= SSL3_FLAGS_CCS_OK;
615 ret = ssl3_get_client_finished(s);
616 if (ret <= 0)
617 goto end;
618 if (SSL_is_dtls(s))
619 dtls1_stop_timer(s);
620 if (s->hit)
621 s->s3->hs.state = SSL_ST_OK;
622 else if (s->tlsext_ticket_expected)
623 s->s3->hs.state = SSL3_ST_SW_SESSION_TICKET_A;
624 else
625 s->s3->hs.state = SSL3_ST_SW_CHANGE_A;
626 s->init_num = 0;
627 break;
628
629 case SSL3_ST_SW_SESSION_TICKET_A:
630 case SSL3_ST_SW_SESSION_TICKET_B:
631 ret = ssl3_send_newsession_ticket(s);
632 if (ret <= 0)
633 goto end;
634 s->s3->hs.state = SSL3_ST_SW_CHANGE_A;
635 s->init_num = 0;
636 break;
637
638 case SSL3_ST_SW_CERT_STATUS_A:
639 case SSL3_ST_SW_CERT_STATUS_B:
640 ret = ssl3_send_cert_status(s);
641 if (ret <= 0)
642 goto end;
643 s->s3->hs.state = SSL3_ST_SW_KEY_EXCH_A;
644 s->init_num = 0;
645 break;
646
647 case SSL3_ST_SW_CHANGE_A:
648 case SSL3_ST_SW_CHANGE_B:
649 ret = ssl3_send_server_change_cipher_spec(s);
650 if (ret <= 0)
651 goto end;
652 s->s3->hs.state = SSL3_ST_SW_FINISHED_A;
653 s->init_num = 0;
654 s->session->cipher_value = s->s3->hs.cipher->value;
655
656 if (!tls1_setup_key_block(s)) {
657 ret = -1;
658 goto end;
659 }
660 if (!tls1_change_write_cipher_state(s)) {
661 ret = -1;
662 goto end;
663 }
664 break;
665
666 case SSL3_ST_SW_FINISHED_A:
667 case SSL3_ST_SW_FINISHED_B:
668 ret = ssl3_send_server_finished(s);
669 if (ret <= 0)
670 goto end;
671 s->s3->hs.state = SSL3_ST_SW_FLUSH;
672 if (s->hit) {
673 s->s3->hs.tls12.next_state = SSL3_ST_SR_FINISHED_A;
674 tls1_transcript_free(s);
675 } else
676 s->s3->hs.tls12.next_state = SSL_ST_OK;
677 s->init_num = 0;
678 break;
679
680 case SSL_ST_OK:
681 /* clean a few things up */
682 tls1_cleanup_key_block(s);
683
684 if (s->s3->handshake_transcript != NULL) {
685 SSLerror(s, ERR_R_INTERNAL_ERROR);
686 ret = -1;
687 goto end;
688 }
689
690 if (!SSL_is_dtls(s))
691 ssl3_release_init_buffer(s);
692
693 /* remove buffering on output */
694 ssl_free_wbio_buffer(s);
695
696 s->init_num = 0;
697
698 /* Skipped if we just sent a HelloRequest. */
699 if (s->renegotiate == 2) {
700 s->renegotiate = 0;
701 s->new_session = 0;
702
703 ssl_update_cache(s, SSL_SESS_CACHE_SERVER);
704
705 s->ctx->stats.sess_accept_good++;
706 /* s->server=1; */
707 s->handshake_func = ssl3_accept;
708
709 ssl_info_callback(s, SSL_CB_HANDSHAKE_DONE, 1);
710 }
711
712 ret = 1;
713
714 if (SSL_is_dtls(s)) {
715 /* Done handshaking, next message is client hello. */
716 s->d1->handshake_read_seq = 0;
717 /* Next message is server hello. */
718 s->d1->handshake_write_seq = 0;
719 s->d1->next_handshake_write_seq = 0;
720 }
721 goto end;
722 /* break; */
723
724 default:
725 SSLerror(s, SSL_R_UNKNOWN_STATE);
726 ret = -1;
727 goto end;
728 /* break; */
729 }
730
731 if (!s->s3->hs.tls12.reuse_message && !skip) {
732 if (s->s3->hs.state != state) {
733 new_state = s->s3->hs.state;
734 s->s3->hs.state = state;
735 ssl_info_callback(s, SSL_CB_ACCEPT_LOOP, 1);
736 s->s3->hs.state = new_state;
737 }
738 }
739 skip = 0;
740 }
741 end:
742 /* BIO_flush(s->wbio); */
743 s->in_handshake--;
744 ssl_info_callback(s, SSL_CB_ACCEPT_EXIT, ret);
745
746 return (ret);
747}
748
749static int
750ssl3_send_hello_request(SSL *s)
751{
752 CBB cbb, hello;
753
754 memset(&cbb, 0, sizeof(cbb));
755
756 if (s->s3->hs.state == SSL3_ST_SW_HELLO_REQ_A) {
757 if (!ssl3_handshake_msg_start(s, &cbb, &hello,
758 SSL3_MT_HELLO_REQUEST))
759 goto err;
760 if (!ssl3_handshake_msg_finish(s, &cbb))
761 goto err;
762
763 s->s3->hs.state = SSL3_ST_SW_HELLO_REQ_B;
764 }
765
766 /* SSL3_ST_SW_HELLO_REQ_B */
767 return (ssl3_handshake_write(s));
768
769 err:
770 CBB_cleanup(&cbb);
771
772 return (-1);
773}
774
775static int
776ssl3_get_client_hello(SSL *s)
777{
778 CBS cbs, client_random, session_id, cookie, cipher_suites;
779 CBS compression_methods;
780 uint16_t client_version;
781 uint8_t comp_method;
782 int comp_null;
783 int i, j, al, ret, cookie_valid = 0;
784 SSL_CIPHER *c;
785 STACK_OF(SSL_CIPHER) *ciphers = NULL;
786 const SSL_METHOD *method;
787 uint16_t shared_version;
788
789 /*
790 * We do this so that we will respond with our native type.
791 * If we are TLSv1 and we get SSLv3, we will respond with TLSv1,
792 * This down switching should be handled by a different method.
793 * If we are SSLv3, we will respond with SSLv3, even if prompted with
794 * TLSv1.
795 */
796 if (s->s3->hs.state == SSL3_ST_SR_CLNT_HELLO_A)
797 s->s3->hs.state = SSL3_ST_SR_CLNT_HELLO_B;
798
799 s->first_packet = 1;
800 if ((ret = ssl3_get_message(s, SSL3_ST_SR_CLNT_HELLO_B,
801 SSL3_ST_SR_CLNT_HELLO_C, SSL3_MT_CLIENT_HELLO,
802 SSL3_RT_MAX_PLAIN_LENGTH)) <= 0)
803 return ret;
804 s->first_packet = 0;
805
806 ret = -1;
807
808 if (s->init_num < 0)
809 goto err;
810
811 CBS_init(&cbs, s->init_msg, s->init_num);
812
813 /* Parse client hello up until the extensions (if any). */
814 if (!CBS_get_u16(&cbs, &client_version))
815 goto decode_err;
816 if (!CBS_get_bytes(&cbs, &client_random, SSL3_RANDOM_SIZE))
817 goto decode_err;
818 if (!CBS_get_u8_length_prefixed(&cbs, &session_id))
819 goto decode_err;
820 if (CBS_len(&session_id) > SSL3_SESSION_ID_SIZE) {
821 al = SSL_AD_ILLEGAL_PARAMETER;
822 SSLerror(s, SSL_R_SSL3_SESSION_ID_TOO_LONG);
823 goto fatal_err;
824 }
825 if (SSL_is_dtls(s)) {
826 if (!CBS_get_u8_length_prefixed(&cbs, &cookie))
827 goto decode_err;
828 }
829 if (!CBS_get_u16_length_prefixed(&cbs, &cipher_suites))
830 goto decode_err;
831 if (!CBS_get_u8_length_prefixed(&cbs, &compression_methods))
832 goto decode_err;
833
834 /*
835 * Use version from inside client hello, not from record header.
836 * (may differ: see RFC 2246, Appendix E, second paragraph)
837 */
838 if (!ssl_max_shared_version(s, client_version, &shared_version)) {
839 if ((client_version >> 8) == SSL3_VERSION_MAJOR &&
840 !tls12_record_layer_write_protected(s->rl)) {
841 /*
842 * Similar to ssl3_get_record, send alert using remote
843 * version number.
844 */
845 s->version = client_version;
846 }
847 SSLerror(s, SSL_R_WRONG_VERSION_NUMBER);
848 al = SSL_AD_PROTOCOL_VERSION;
849 goto fatal_err;
850 }
851 s->s3->hs.peer_legacy_version = client_version;
852 s->version = shared_version;
853
854 s->s3->hs.negotiated_tls_version = ssl_tls_version(shared_version);
855 if (s->s3->hs.negotiated_tls_version == 0) {
856 SSLerror(s, ERR_R_INTERNAL_ERROR);
857 goto err;
858 }
859
860 if ((method = ssl_get_method(shared_version)) == NULL) {
861 SSLerror(s, ERR_R_INTERNAL_ERROR);
862 goto err;
863 }
864 s->method = method;
865
866 /*
867 * If we require cookies (DTLS) and this ClientHello does not contain
868 * one, just return since we do not want to allocate any memory yet.
869 * So check cookie length...
870 */
871 if (SSL_is_dtls(s)) {
872 if (SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) {
873 if (CBS_len(&cookie) == 0)
874 return (1);
875 }
876 }
877
878 if (!CBS_write_bytes(&client_random, s->s3->client_random,
879 sizeof(s->s3->client_random), NULL))
880 goto err;
881
882 s->hit = 0;
883
884 /*
885 * Versions before 0.9.7 always allow clients to resume sessions in
886 * renegotiation. 0.9.7 and later allow this by default, but optionally
887 * ignore resumption requests with flag
888 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION (it's a new flag
889 * rather than a change to default behavior so that applications
890 * relying on this for security won't even compile against older
891 * library versions).
892 *
893 * 1.0.1 and later also have a function SSL_renegotiate_abbreviated()
894 * to request renegotiation but not a new session (s->new_session
895 * remains unset): for servers, this essentially just means that the
896 * SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION setting will be
897 * ignored.
898 */
899 if ((s->new_session && (s->options &
900 SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION))) {
901 if (!ssl_get_new_session(s, 1))
902 goto err;
903 } else {
904 CBS ext_block;
905
906 CBS_dup(&cbs, &ext_block);
907
908 i = ssl_get_prev_session(s, &session_id, &ext_block, &al);
909 if (i == 1) { /* previous session */
910 s->hit = 1;
911 } else if (i == -1)
912 goto fatal_err;
913 else {
914 /* i == 0 */
915 if (!ssl_get_new_session(s, 1))
916 goto err;
917 }
918 }
919
920 if (SSL_is_dtls(s)) {
921 /*
922 * The ClientHello may contain a cookie even if the HelloVerify
923 * message has not been sent - make sure that it does not cause
924 * an overflow.
925 */
926 if (CBS_len(&cookie) > sizeof(s->d1->rcvd_cookie)) {
927 al = SSL_AD_DECODE_ERROR;
928 SSLerror(s, SSL_R_COOKIE_MISMATCH);
929 goto fatal_err;
930 }
931
932 /* Verify the cookie if appropriate option is set. */
933 if ((SSL_get_options(s) & SSL_OP_COOKIE_EXCHANGE) &&
934 CBS_len(&cookie) > 0) {
935 size_t cookie_len;
936
937 /* XXX - rcvd_cookie seems to only be used here... */
938 if (!CBS_write_bytes(&cookie, s->d1->rcvd_cookie,
939 sizeof(s->d1->rcvd_cookie), &cookie_len))
940 goto err;
941
942 if (s->ctx->app_verify_cookie_cb != NULL) {
943 if (s->ctx->app_verify_cookie_cb(s,
944 s->d1->rcvd_cookie, cookie_len) == 0) {
945 al = SSL_AD_HANDSHAKE_FAILURE;
946 SSLerror(s, SSL_R_COOKIE_MISMATCH);
947 goto fatal_err;
948 }
949 /* else cookie verification succeeded */
950 /* XXX - can d1->cookie_len > sizeof(rcvd_cookie) ? */
951 } else if (timingsafe_memcmp(s->d1->rcvd_cookie,
952 s->d1->cookie, s->d1->cookie_len) != 0) {
953 /* default verification */
954 al = SSL_AD_HANDSHAKE_FAILURE;
955 SSLerror(s, SSL_R_COOKIE_MISMATCH);
956 goto fatal_err;
957 }
958 cookie_valid = 1;
959 }
960 }
961
962 /* XXX - This logic seems wrong... */
963 if (CBS_len(&cipher_suites) == 0 && CBS_len(&session_id) != 0) {
964 /* we need a cipher if we are not resuming a session */
965 al = SSL_AD_ILLEGAL_PARAMETER;
966 SSLerror(s, SSL_R_NO_CIPHERS_SPECIFIED);
967 goto fatal_err;
968 }
969
970 if (CBS_len(&cipher_suites) > 0) {
971 if ((ciphers = ssl_bytes_to_cipher_list(s,
972 &cipher_suites)) == NULL)
973 goto err;
974 }
975
976 /* If it is a hit, check that the cipher is in the list */
977 /* XXX - CBS_len(&cipher_suites) will always be zero here... */
978 if (s->hit && CBS_len(&cipher_suites) > 0) {
979 j = 0;
980
981 for (i = 0; i < sk_SSL_CIPHER_num(ciphers); i++) {
982 c = sk_SSL_CIPHER_value(ciphers, i);
983 if (c->value == s->session->cipher_value) {
984 j = 1;
985 break;
986 }
987 }
988 if (j == 0) {
989 /*
990 * We need to have the cipher in the cipher
991 * list if we are asked to reuse it
992 */
993 al = SSL_AD_ILLEGAL_PARAMETER;
994 SSLerror(s, SSL_R_REQUIRED_CIPHER_MISSING);
995 goto fatal_err;
996 }
997 }
998
999 comp_null = 0;
1000 while (CBS_len(&compression_methods) > 0) {
1001 if (!CBS_get_u8(&compression_methods, &comp_method))
1002 goto decode_err;
1003 if (comp_method == 0)
1004 comp_null = 1;
1005 }
1006 if (comp_null == 0) {
1007 al = SSL_AD_DECODE_ERROR;
1008 SSLerror(s, SSL_R_NO_COMPRESSION_SPECIFIED);
1009 goto fatal_err;
1010 }
1011
1012 if (!tlsext_server_parse(s, SSL_TLSEXT_MSG_CH, &cbs, &al)) {
1013 SSLerror(s, SSL_R_PARSE_TLSEXT);
1014 goto fatal_err;
1015 }
1016
1017 if (CBS_len(&cbs) != 0)
1018 goto decode_err;
1019
1020 if (!s->s3->renegotiate_seen && s->renegotiate) {
1021 al = SSL_AD_HANDSHAKE_FAILURE;
1022 SSLerror(s, SSL_R_UNSAFE_LEGACY_RENEGOTIATION_DISABLED);
1023 goto fatal_err;
1024 }
1025
1026 if (ssl_check_clienthello_tlsext_early(s) <= 0) {
1027 SSLerror(s, SSL_R_CLIENTHELLO_TLSEXT);
1028 goto err;
1029 }
1030
1031 /*
1032 * Check if we want to use external pre-shared secret for this
1033 * handshake for not reused session only. We need to generate
1034 * server_random before calling tls_session_secret_cb in order to allow
1035 * SessionTicket processing to use it in key derivation.
1036 */
1037 arc4random_buf(s->s3->server_random, SSL3_RANDOM_SIZE);
1038
1039 if (s->s3->hs.our_max_tls_version >= TLS1_2_VERSION &&
1040 s->s3->hs.negotiated_tls_version < s->s3->hs.our_max_tls_version) {
1041 /*
1042 * RFC 8446 section 4.1.3. If we are downgrading from TLS 1.3
1043 * we must set the last 8 bytes of the server random to magical
1044 * values to indicate we meant to downgrade. For TLS 1.2 it is
1045 * recommended that we do the same.
1046 */
1047 size_t index = SSL3_RANDOM_SIZE - sizeof(tls13_downgrade_12);
1048 uint8_t *magic = &s->s3->server_random[index];
1049 if (s->s3->hs.negotiated_tls_version == TLS1_2_VERSION) {
1050 /* Indicate we chose to downgrade to 1.2. */
1051 memcpy(magic, tls13_downgrade_12,
1052 sizeof(tls13_downgrade_12));
1053 } else {
1054 /* Indicate we chose to downgrade to 1.1 or lower */
1055 memcpy(magic, tls13_downgrade_11,
1056 sizeof(tls13_downgrade_11));
1057 }
1058 }
1059
1060 if (!s->hit && s->tls_session_secret_cb != NULL) {
1061 const SSL_CIPHER *pref_cipher = NULL;
1062 int master_key_length = sizeof(s->session->master_key);
1063
1064 if (!s->tls_session_secret_cb(s,
1065 s->session->master_key, &master_key_length, ciphers,
1066 &pref_cipher, s->tls_session_secret_cb_arg)) {
1067 SSLerror(s, ERR_R_INTERNAL_ERROR);
1068 goto err;
1069 }
1070 if (master_key_length <= 0) {
1071 SSLerror(s, ERR_R_INTERNAL_ERROR);
1072 goto err;
1073 }
1074 s->session->master_key_length = master_key_length;
1075
1076 s->hit = 1;
1077 s->session->verify_result = X509_V_OK;
1078
1079 sk_SSL_CIPHER_free(s->s3->hs.client_ciphers);
1080 s->s3->hs.client_ciphers = ciphers;
1081 ciphers = NULL;
1082
1083 /*
1084 * XXX - this allows the callback to use any client cipher and
1085 * completely ignore the server cipher list. We should ensure
1086 * that the pref_cipher is in both the client list and the
1087 * server list.
1088 */
1089
1090 /* Check if some cipher was preferred by the callback. */
1091 if (pref_cipher == NULL)
1092 pref_cipher = ssl3_choose_cipher(s, s->s3->hs.client_ciphers,
1093 SSL_get_ciphers(s));
1094 if (pref_cipher == NULL) {
1095 al = SSL_AD_HANDSHAKE_FAILURE;
1096 SSLerror(s, SSL_R_NO_SHARED_CIPHER);
1097 goto fatal_err;
1098 }
1099 s->s3->hs.cipher = pref_cipher;
1100
1101 /* XXX - why? */
1102 sk_SSL_CIPHER_free(s->cipher_list);
1103 s->cipher_list = sk_SSL_CIPHER_dup(s->s3->hs.client_ciphers);
1104 }
1105
1106 /*
1107 * Given s->session->ciphers and SSL_get_ciphers, we must
1108 * pick a cipher
1109 */
1110
1111 if (!s->hit) {
1112 if (ciphers == NULL) {
1113 al = SSL_AD_ILLEGAL_PARAMETER;
1114 SSLerror(s, SSL_R_NO_CIPHERS_PASSED);
1115 goto fatal_err;
1116 }
1117 sk_SSL_CIPHER_free(s->s3->hs.client_ciphers);
1118 s->s3->hs.client_ciphers = ciphers;
1119 ciphers = NULL;
1120
1121 if ((c = ssl3_choose_cipher(s, s->s3->hs.client_ciphers,
1122 SSL_get_ciphers(s))) == NULL) {
1123 al = SSL_AD_HANDSHAKE_FAILURE;
1124 SSLerror(s, SSL_R_NO_SHARED_CIPHER);
1125 goto fatal_err;
1126 }
1127 s->s3->hs.cipher = c;
1128 s->session->cipher_value = s->s3->hs.cipher->value;
1129 } else {
1130 s->s3->hs.cipher = ssl3_get_cipher_by_value(s->session->cipher_value);
1131 if (s->s3->hs.cipher == NULL)
1132 goto fatal_err;
1133 }
1134
1135 if (!tls1_transcript_hash_init(s))
1136 goto err;
1137
1138 if (!SSL_USE_SIGALGS(s) || !(s->verify_mode & SSL_VERIFY_PEER))
1139 tls1_transcript_free(s);
1140
1141 /*
1142 * We now have the following setup.
1143 * client_random
1144 * cipher_list - our preferred list of ciphers
1145 * ciphers - the clients preferred list of ciphers
1146 * compression - basically ignored right now
1147 * ssl version is set - sslv3
1148 * s->session - The ssl session has been setup.
1149 * s->hit - session reuse flag
1150 * s->hs.cipher - the new cipher to use.
1151 */
1152
1153 /* Handles TLS extensions that we couldn't check earlier */
1154 if (ssl_check_clienthello_tlsext_late(s) <= 0) {
1155 SSLerror(s, SSL_R_CLIENTHELLO_TLSEXT);
1156 goto err;
1157 }
1158
1159 ret = cookie_valid ? 2 : 1;
1160
1161 if (0) {
1162 decode_err:
1163 al = SSL_AD_DECODE_ERROR;
1164 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1165 fatal_err:
1166 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1167 }
1168 err:
1169 sk_SSL_CIPHER_free(ciphers);
1170
1171 return (ret);
1172}
1173
1174static int
1175ssl3_send_dtls_hello_verify_request(SSL *s)
1176{
1177 CBB cbb, verify, cookie;
1178
1179 memset(&cbb, 0, sizeof(cbb));
1180
1181 if (s->s3->hs.state == DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A) {
1182 if (s->ctx->app_gen_cookie_cb == NULL ||
1183 s->ctx->app_gen_cookie_cb(s, s->d1->cookie,
1184 &(s->d1->cookie_len)) == 0) {
1185 SSLerror(s, ERR_R_INTERNAL_ERROR);
1186 return 0;
1187 }
1188
1189 /*
1190 * Per RFC 6347 section 4.2.1, the HelloVerifyRequest should
1191 * always contain DTLSv1.0 regardless of the version that is
1192 * going to be negotiated.
1193 */
1194 if (!ssl3_handshake_msg_start(s, &cbb, &verify,
1195 DTLS1_MT_HELLO_VERIFY_REQUEST))
1196 goto err;
1197 if (!CBB_add_u16(&verify, DTLS1_VERSION))
1198 goto err;
1199 if (!CBB_add_u8_length_prefixed(&verify, &cookie))
1200 goto err;
1201 if (!CBB_add_bytes(&cookie, s->d1->cookie, s->d1->cookie_len))
1202 goto err;
1203 if (!ssl3_handshake_msg_finish(s, &cbb))
1204 goto err;
1205
1206 s->s3->hs.state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B;
1207 }
1208
1209 /* s->s3->hs.state = DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B */
1210 return (ssl3_handshake_write(s));
1211
1212 err:
1213 CBB_cleanup(&cbb);
1214
1215 return (-1);
1216}
1217
1218static int
1219ssl3_send_server_hello(SSL *s)
1220{
1221 CBB cbb, server_hello, session_id;
1222 size_t sl;
1223
1224 memset(&cbb, 0, sizeof(cbb));
1225
1226 if (s->s3->hs.state == SSL3_ST_SW_SRVR_HELLO_A) {
1227 if (!ssl3_handshake_msg_start(s, &cbb, &server_hello,
1228 SSL3_MT_SERVER_HELLO))
1229 goto err;
1230
1231 if (!CBB_add_u16(&server_hello, s->version))
1232 goto err;
1233 if (!CBB_add_bytes(&server_hello, s->s3->server_random,
1234 sizeof(s->s3->server_random)))
1235 goto err;
1236
1237 /*
1238 * There are several cases for the session ID to send
1239 * back in the server hello:
1240 *
1241 * - For session reuse from the session cache,
1242 * we send back the old session ID.
1243 * - If stateless session reuse (using a session ticket)
1244 * is successful, we send back the client's "session ID"
1245 * (which doesn't actually identify the session).
1246 * - If it is a new session, we send back the new
1247 * session ID.
1248 * - However, if we want the new session to be single-use,
1249 * we send back a 0-length session ID.
1250 *
1251 * s->hit is non-zero in either case of session reuse,
1252 * so the following won't overwrite an ID that we're supposed
1253 * to send back.
1254 */
1255 if (!(s->ctx->session_cache_mode & SSL_SESS_CACHE_SERVER)
1256 && !s->hit)
1257 s->session->session_id_length = 0;
1258
1259 sl = s->session->session_id_length;
1260 if (sl > sizeof(s->session->session_id)) {
1261 SSLerror(s, ERR_R_INTERNAL_ERROR);
1262 goto err;
1263 }
1264 if (!CBB_add_u8_length_prefixed(&server_hello, &session_id))
1265 goto err;
1266 if (!CBB_add_bytes(&session_id, s->session->session_id, sl))
1267 goto err;
1268
1269 /* Cipher suite. */
1270 if (!CBB_add_u16(&server_hello, s->s3->hs.cipher->value))
1271 goto err;
1272
1273 /* Compression method (null). */
1274 if (!CBB_add_u8(&server_hello, 0))
1275 goto err;
1276
1277 /* TLS extensions */
1278 if (!tlsext_server_build(s, SSL_TLSEXT_MSG_SH, &server_hello)) {
1279 SSLerror(s, ERR_R_INTERNAL_ERROR);
1280 goto err;
1281 }
1282
1283 if (!ssl3_handshake_msg_finish(s, &cbb))
1284 goto err;
1285 }
1286
1287 /* SSL3_ST_SW_SRVR_HELLO_B */
1288 return (ssl3_handshake_write(s));
1289
1290 err:
1291 CBB_cleanup(&cbb);
1292
1293 return (-1);
1294}
1295
1296static int
1297ssl3_send_server_done(SSL *s)
1298{
1299 CBB cbb, done;
1300
1301 memset(&cbb, 0, sizeof(cbb));
1302
1303 if (s->s3->hs.state == SSL3_ST_SW_SRVR_DONE_A) {
1304 if (!ssl3_handshake_msg_start(s, &cbb, &done,
1305 SSL3_MT_SERVER_DONE))
1306 goto err;
1307 if (!ssl3_handshake_msg_finish(s, &cbb))
1308 goto err;
1309
1310 s->s3->hs.state = SSL3_ST_SW_SRVR_DONE_B;
1311 }
1312
1313 /* SSL3_ST_SW_SRVR_DONE_B */
1314 return (ssl3_handshake_write(s));
1315
1316 err:
1317 CBB_cleanup(&cbb);
1318
1319 return (-1);
1320}
1321
1322static int
1323ssl3_send_server_kex_dhe(SSL *s, CBB *cbb)
1324{
1325 int nid = NID_dhKeyAgreement;
1326
1327 tls_key_share_free(s->s3->hs.key_share);
1328 if ((s->s3->hs.key_share = tls_key_share_new_nid(nid)) == NULL)
1329 goto err;
1330
1331 if (s->cert->dhe_params_auto != 0) {
1332 size_t key_bits;
1333
1334 if ((key_bits = ssl_dhe_params_auto_key_bits(s)) == 0) {
1335 SSLerror(s, ERR_R_INTERNAL_ERROR);
1336 ssl3_send_alert(s, SSL3_AL_FATAL,
1337 SSL_AD_INTERNAL_ERROR);
1338 goto err;
1339 }
1340 tls_key_share_set_key_bits(s->s3->hs.key_share,
1341 key_bits);
1342 } else {
1343 DH *dh_params = s->cert->dhe_params;
1344
1345 if (dh_params == NULL && s->cert->dhe_params_cb != NULL)
1346 dh_params = s->cert->dhe_params_cb(s, 0,
1347 SSL_C_PKEYLENGTH(s->s3->hs.cipher));
1348
1349 if (dh_params == NULL) {
1350 SSLerror(s, SSL_R_MISSING_TMP_DH_KEY);
1351 ssl3_send_alert(s, SSL3_AL_FATAL,
1352 SSL_AD_HANDSHAKE_FAILURE);
1353 goto err;
1354 }
1355
1356 if (!tls_key_share_set_dh_params(s->s3->hs.key_share, dh_params))
1357 goto err;
1358 }
1359
1360 if (!tls_key_share_generate(s->s3->hs.key_share))
1361 goto err;
1362
1363 if (!tls_key_share_params(s->s3->hs.key_share, cbb))
1364 goto err;
1365 if (!tls_key_share_public(s->s3->hs.key_share, cbb))
1366 goto err;
1367
1368 if (!tls_key_share_peer_security(s, s->s3->hs.key_share)) {
1369 SSLerror(s, SSL_R_DH_KEY_TOO_SMALL);
1370 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1371 return 0;
1372 }
1373
1374 return 1;
1375
1376 err:
1377 return 0;
1378}
1379
1380static int
1381ssl3_send_server_kex_ecdhe(SSL *s, CBB *cbb)
1382{
1383 CBB public;
1384 int nid;
1385
1386 if (!tls1_get_supported_group(s, &nid)) {
1387 SSLerror(s, SSL_R_UNSUPPORTED_ELLIPTIC_CURVE);
1388 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1389 goto err;
1390 }
1391
1392 tls_key_share_free(s->s3->hs.key_share);
1393 if ((s->s3->hs.key_share = tls_key_share_new_nid(nid)) == NULL)
1394 goto err;
1395
1396 if (!tls_key_share_generate(s->s3->hs.key_share))
1397 goto err;
1398
1399 /*
1400 * ECC key exchange - see RFC 8422, section 5.4.
1401 */
1402 if (!CBB_add_u8(cbb, NAMED_CURVE_TYPE))
1403 goto err;
1404 if (!CBB_add_u16(cbb, tls_key_share_group(s->s3->hs.key_share)))
1405 goto err;
1406 if (!CBB_add_u8_length_prefixed(cbb, &public))
1407 goto err;
1408 if (!tls_key_share_public(s->s3->hs.key_share, &public))
1409 goto err;
1410 if (!CBB_flush(cbb))
1411 goto err;
1412
1413 return 1;
1414
1415 err:
1416 return 0;
1417}
1418
1419static int
1420ssl3_send_server_key_exchange(SSL *s)
1421{
1422 CBB cbb, cbb_signature, cbb_signed_params, server_kex;
1423 CBS params;
1424 const struct ssl_sigalg *sigalg = NULL;
1425 unsigned char *signed_params = NULL;
1426 size_t signed_params_len;
1427 unsigned char *signature = NULL;
1428 size_t signature_len = 0;
1429 const EVP_MD *md = NULL;
1430 unsigned long type;
1431 EVP_MD_CTX *md_ctx = NULL;
1432 EVP_PKEY_CTX *pctx;
1433 EVP_PKEY *pkey;
1434 int al;
1435
1436 memset(&cbb, 0, sizeof(cbb));
1437 memset(&cbb_signed_params, 0, sizeof(cbb_signed_params));
1438
1439 if ((md_ctx = EVP_MD_CTX_new()) == NULL)
1440 goto err;
1441
1442 if (s->s3->hs.state == SSL3_ST_SW_KEY_EXCH_A) {
1443
1444 if (!ssl3_handshake_msg_start(s, &cbb, &server_kex,
1445 SSL3_MT_SERVER_KEY_EXCHANGE))
1446 goto err;
1447
1448 if (!CBB_init(&cbb_signed_params, 0))
1449 goto err;
1450
1451 if (!CBB_add_bytes(&cbb_signed_params, s->s3->client_random,
1452 SSL3_RANDOM_SIZE)) {
1453 SSLerror(s, ERR_R_INTERNAL_ERROR);
1454 goto err;
1455 }
1456 if (!CBB_add_bytes(&cbb_signed_params, s->s3->server_random,
1457 SSL3_RANDOM_SIZE)) {
1458 SSLerror(s, ERR_R_INTERNAL_ERROR);
1459 goto err;
1460 }
1461
1462 type = s->s3->hs.cipher->algorithm_mkey;
1463 if (type & SSL_kDHE) {
1464 if (!ssl3_send_server_kex_dhe(s, &cbb_signed_params))
1465 goto err;
1466 } else if (type & SSL_kECDHE) {
1467 if (!ssl3_send_server_kex_ecdhe(s, &cbb_signed_params))
1468 goto err;
1469 } else {
1470 al = SSL_AD_HANDSHAKE_FAILURE;
1471 SSLerror(s, SSL_R_UNKNOWN_KEY_EXCHANGE_TYPE);
1472 goto fatal_err;
1473 }
1474
1475 if (!CBB_finish(&cbb_signed_params, &signed_params,
1476 &signed_params_len))
1477 goto err;
1478
1479 CBS_init(&params, signed_params, signed_params_len);
1480 if (!CBS_skip(&params, 2 * SSL3_RANDOM_SIZE))
1481 goto err;
1482
1483 if (!CBB_add_bytes(&server_kex, CBS_data(&params),
1484 CBS_len(&params)))
1485 goto err;
1486
1487 /* Add signature unless anonymous. */
1488 if (!(s->s3->hs.cipher->algorithm_auth & SSL_aNULL)) {
1489 if ((pkey = ssl_get_sign_pkey(s, s->s3->hs.cipher,
1490 &md, &sigalg)) == NULL) {
1491 al = SSL_AD_DECODE_ERROR;
1492 goto fatal_err;
1493 }
1494 s->s3->hs.our_sigalg = sigalg;
1495
1496 /* Send signature algorithm. */
1497 if (SSL_USE_SIGALGS(s)) {
1498 if (!CBB_add_u16(&server_kex, sigalg->value)) {
1499 al = SSL_AD_INTERNAL_ERROR;
1500 SSLerror(s, ERR_R_INTERNAL_ERROR);
1501 goto fatal_err;
1502 }
1503 }
1504
1505 if (!EVP_DigestSignInit(md_ctx, &pctx, md, NULL, pkey)) {
1506 SSLerror(s, ERR_R_EVP_LIB);
1507 goto err;
1508 }
1509 if ((sigalg->flags & SIGALG_FLAG_RSA_PSS) &&
1510 (!EVP_PKEY_CTX_set_rsa_padding(pctx,
1511 RSA_PKCS1_PSS_PADDING) ||
1512 !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))) {
1513 SSLerror(s, ERR_R_EVP_LIB);
1514 goto err;
1515 }
1516 if (!EVP_DigestSign(md_ctx, NULL, &signature_len,
1517 signed_params, signed_params_len)) {
1518 SSLerror(s, ERR_R_EVP_LIB);
1519 goto err;
1520 }
1521 if ((signature = calloc(1, signature_len)) == NULL) {
1522 SSLerror(s, ERR_R_MALLOC_FAILURE);
1523 goto err;
1524 }
1525 if (!EVP_DigestSign(md_ctx, signature, &signature_len,
1526 signed_params, signed_params_len)) {
1527 SSLerror(s, ERR_R_EVP_LIB);
1528 goto err;
1529 }
1530
1531 if (!CBB_add_u16_length_prefixed(&server_kex,
1532 &cbb_signature))
1533 goto err;
1534 if (!CBB_add_bytes(&cbb_signature, signature,
1535 signature_len))
1536 goto err;
1537 }
1538
1539 if (!ssl3_handshake_msg_finish(s, &cbb))
1540 goto err;
1541
1542 s->s3->hs.state = SSL3_ST_SW_KEY_EXCH_B;
1543 }
1544
1545 EVP_MD_CTX_free(md_ctx);
1546 free(signature);
1547 free(signed_params);
1548
1549 return (ssl3_handshake_write(s));
1550
1551 fatal_err:
1552 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1553 err:
1554 CBB_cleanup(&cbb_signed_params);
1555 CBB_cleanup(&cbb);
1556 EVP_MD_CTX_free(md_ctx);
1557 free(signature);
1558 free(signed_params);
1559
1560 return (-1);
1561}
1562
1563static int
1564ssl3_send_certificate_request(SSL *s)
1565{
1566 CBB cbb, cert_request, cert_types, sigalgs, cert_auth, dn;
1567 STACK_OF(X509_NAME) *sk = NULL;
1568 X509_NAME *name;
1569 int i;
1570
1571 /*
1572 * Certificate Request - RFC 5246 section 7.4.4.
1573 */
1574
1575 memset(&cbb, 0, sizeof(cbb));
1576
1577 if (s->s3->hs.state == SSL3_ST_SW_CERT_REQ_A) {
1578 if (!ssl3_handshake_msg_start(s, &cbb, &cert_request,
1579 SSL3_MT_CERTIFICATE_REQUEST))
1580 goto err;
1581
1582 if (!CBB_add_u8_length_prefixed(&cert_request, &cert_types))
1583 goto err;
1584 if (!ssl3_get_req_cert_types(s, &cert_types))
1585 goto err;
1586
1587 if (SSL_USE_SIGALGS(s)) {
1588 if (!CBB_add_u16_length_prefixed(&cert_request,
1589 &sigalgs))
1590 goto err;
1591 if (!ssl_sigalgs_build(s->s3->hs.negotiated_tls_version,
1592 &sigalgs, SSL_get_security_level(s)))
1593 goto err;
1594 }
1595
1596 if (!CBB_add_u16_length_prefixed(&cert_request, &cert_auth))
1597 goto err;
1598
1599 sk = SSL_get_client_CA_list(s);
1600 for (i = 0; i < sk_X509_NAME_num(sk); i++) {
1601 unsigned char *name_data;
1602 size_t name_len;
1603
1604 name = sk_X509_NAME_value(sk, i);
1605 name_len = i2d_X509_NAME(name, NULL);
1606
1607 if (!CBB_add_u16_length_prefixed(&cert_auth, &dn))
1608 goto err;
1609 if (!CBB_add_space(&dn, &name_data, name_len))
1610 goto err;
1611 if (i2d_X509_NAME(name, &name_data) != name_len)
1612 goto err;
1613 }
1614
1615 if (!ssl3_handshake_msg_finish(s, &cbb))
1616 goto err;
1617
1618 s->s3->hs.state = SSL3_ST_SW_CERT_REQ_B;
1619 }
1620
1621 /* SSL3_ST_SW_CERT_REQ_B */
1622 return (ssl3_handshake_write(s));
1623
1624 err:
1625 CBB_cleanup(&cbb);
1626
1627 return (-1);
1628}
1629
1630static int
1631ssl3_get_client_kex_rsa(SSL *s, CBS *cbs)
1632{
1633 uint8_t fakepms[SSL_MAX_MASTER_KEY_LENGTH];
1634 uint8_t *pms = NULL;
1635 size_t pms_len = 0;
1636 size_t pad_len;
1637 EVP_PKEY *pkey = NULL;
1638 RSA *rsa = NULL;
1639 CBS enc_pms;
1640 int decrypt_len;
1641 uint8_t mask;
1642 size_t i;
1643 int valid = 1;
1644 int ret = 0;
1645
1646 /*
1647 * Handle key exchange in the form of an RSA-Encrypted Premaster Secret
1648 * Message. See RFC 5246, section 7.4.7.1.
1649 */
1650
1651 arc4random_buf(fakepms, sizeof(fakepms));
1652
1653 fakepms[0] = s->s3->hs.peer_legacy_version >> 8;
1654 fakepms[1] = s->s3->hs.peer_legacy_version & 0xff;
1655
1656 pkey = s->cert->pkeys[SSL_PKEY_RSA].privatekey;
1657 if (pkey == NULL || (rsa = EVP_PKEY_get0_RSA(pkey)) == NULL) {
1658 SSLerror(s, SSL_R_MISSING_RSA_CERTIFICATE);
1659 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1660 goto err;
1661 }
1662
1663 /*
1664 * The minimum size of an encrypted premaster secret is 11 bytes of
1665 * padding (00 02 <8 or more non-zero bytes> 00) (RFC 8017, section
1666 * 9.2) and 48 bytes of premaster secret (RFC 5246, section 7.4.7.1).
1667 * This means an RSA key size of at least 472 bits.
1668 */
1669 pms_len = RSA_size(rsa);
1670 if (pms_len < 11 + SSL_MAX_MASTER_KEY_LENGTH) {
1671 SSLerror(s, SSL_R_DECRYPTION_FAILED);
1672 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
1673 goto err;
1674 }
1675 pad_len = pms_len - SSL_MAX_MASTER_KEY_LENGTH;
1676
1677 if (!CBS_get_u16_length_prefixed(cbs, &enc_pms)) {
1678 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1679 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1680 goto err;
1681 }
1682 if (CBS_len(&enc_pms) != pms_len || CBS_len(cbs) != 0) {
1683 SSLerror(s, SSL_R_TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG);
1684 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1685 goto err;
1686 }
1687
1688 if ((pms = calloc(1, pms_len)) == NULL)
1689 goto err;
1690
1691 decrypt_len = RSA_private_decrypt(CBS_len(&enc_pms), CBS_data(&enc_pms),
1692 pms, rsa, RSA_NO_PADDING);
1693
1694 if (decrypt_len != pms_len) {
1695 SSLerror(s, SSL_R_DECRYPTION_FAILED);
1696 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECRYPT_ERROR);
1697 goto err;
1698 }
1699
1700 /*
1701 * All processing from here on needs to avoid leaking any information
1702 * about the decrypted content, in order to prevent oracle attacks and
1703 * minimise timing attacks.
1704 */
1705
1706 /* Check padding - 00 02 <8 or more non-zero bytes> 00 */
1707 valid &= crypto_ct_eq_u8(pms[0], 0x00);
1708 valid &= crypto_ct_eq_u8(pms[1], 0x02);
1709 for (i = 2; i < pad_len - 1; i++)
1710 valid &= crypto_ct_ne_u8(pms[i], 0x00);
1711 valid &= crypto_ct_eq_u8(pms[pad_len - 1], 0x00);
1712
1713 /* Ensure client version in premaster secret matches ClientHello version. */
1714 valid &= crypto_ct_eq_u8(pms[pad_len + 0], s->s3->hs.peer_legacy_version >> 8);
1715 valid &= crypto_ct_eq_u8(pms[pad_len + 1], s->s3->hs.peer_legacy_version & 0xff);
1716
1717 /* Use the premaster secret if padding is correct, if not use the fake. */
1718 mask = crypto_ct_eq_mask_u8(valid, 1);
1719 for (i = 0; i < SSL_MAX_MASTER_KEY_LENGTH; i++)
1720 pms[i] = (pms[pad_len + i] & mask) | (fakepms[i] & ~mask);
1721
1722 if (!tls12_derive_master_secret(s, pms, SSL_MAX_MASTER_KEY_LENGTH))
1723 goto err;
1724
1725 ret = 1;
1726
1727 err:
1728 freezero(pms, pms_len);
1729
1730 return ret;
1731}
1732
1733static int
1734ssl3_get_client_kex_dhe(SSL *s, CBS *cbs)
1735{
1736 uint8_t *key = NULL;
1737 size_t key_len = 0;
1738 int decode_error, invalid_key;
1739 int ret = 0;
1740
1741 if (s->s3->hs.key_share == NULL) {
1742 SSLerror(s, SSL_R_MISSING_TMP_DH_KEY);
1743 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1744 goto err;
1745 }
1746
1747 if (!tls_key_share_peer_public(s->s3->hs.key_share, cbs,
1748 &decode_error, &invalid_key)) {
1749 if (decode_error) {
1750 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1751 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1752 }
1753 goto err;
1754 }
1755 if (invalid_key) {
1756 SSLerror(s, SSL_R_BAD_DH_PUB_KEY_LENGTH);
1757 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_ILLEGAL_PARAMETER);
1758 goto err;
1759 }
1760
1761 if (!tls_key_share_derive(s->s3->hs.key_share, &key, &key_len))
1762 goto err;
1763
1764 if (!tls12_derive_master_secret(s, key, key_len))
1765 goto err;
1766
1767 ret = 1;
1768
1769 err:
1770 freezero(key, key_len);
1771
1772 return ret;
1773}
1774
1775static int
1776ssl3_get_client_kex_ecdhe(SSL *s, CBS *cbs)
1777{
1778 uint8_t *key = NULL;
1779 size_t key_len = 0;
1780 int decode_error;
1781 CBS public;
1782 int ret = 0;
1783
1784 if (s->s3->hs.key_share == NULL) {
1785 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE);
1786 SSLerror(s, SSL_R_MISSING_TMP_DH_KEY);
1787 goto err;
1788 }
1789
1790 if (!CBS_get_u8_length_prefixed(cbs, &public)) {
1791 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1792 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1793 goto err;
1794 }
1795 if (!tls_key_share_peer_public(s->s3->hs.key_share, &public,
1796 &decode_error, NULL)) {
1797 if (decode_error) {
1798 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1799 ssl3_send_alert(s, SSL3_AL_FATAL, SSL_AD_DECODE_ERROR);
1800 }
1801 goto err;
1802 }
1803
1804 if (!tls_key_share_derive(s->s3->hs.key_share, &key, &key_len))
1805 goto err;
1806
1807 if (!tls12_derive_master_secret(s, key, key_len))
1808 goto err;
1809
1810 ret = 1;
1811
1812 err:
1813 freezero(key, key_len);
1814
1815 return ret;
1816}
1817
1818static int
1819ssl3_get_client_key_exchange(SSL *s)
1820{
1821 unsigned long alg_k;
1822 int al, ret;
1823 CBS cbs;
1824
1825 /* 2048 maxlen is a guess. How long a key does that permit? */
1826 if ((ret = ssl3_get_message(s, SSL3_ST_SR_KEY_EXCH_A,
1827 SSL3_ST_SR_KEY_EXCH_B, SSL3_MT_CLIENT_KEY_EXCHANGE, 2048)) <= 0)
1828 return ret;
1829
1830 if (s->init_num < 0)
1831 goto err;
1832
1833 CBS_init(&cbs, s->init_msg, s->init_num);
1834
1835 alg_k = s->s3->hs.cipher->algorithm_mkey;
1836
1837 if (alg_k & SSL_kRSA) {
1838 if (!ssl3_get_client_kex_rsa(s, &cbs))
1839 goto err;
1840 } else if (alg_k & SSL_kDHE) {
1841 if (!ssl3_get_client_kex_dhe(s, &cbs))
1842 goto err;
1843 } else if (alg_k & SSL_kECDHE) {
1844 if (!ssl3_get_client_kex_ecdhe(s, &cbs))
1845 goto err;
1846 } else {
1847 al = SSL_AD_HANDSHAKE_FAILURE;
1848 SSLerror(s, SSL_R_UNKNOWN_CIPHER_TYPE);
1849 goto fatal_err;
1850 }
1851
1852 if (CBS_len(&cbs) != 0) {
1853 al = SSL_AD_DECODE_ERROR;
1854 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
1855 goto fatal_err;
1856 }
1857
1858 return (1);
1859
1860 fatal_err:
1861 ssl3_send_alert(s, SSL3_AL_FATAL, al);
1862 err:
1863 return (-1);
1864}
1865
1866static int
1867ssl3_get_cert_verify(SSL *s)
1868{
1869 CBS cbs, signature;
1870 const struct ssl_sigalg *sigalg = NULL;
1871 uint16_t sigalg_value = SIGALG_NONE;
1872 EVP_PKEY *pkey;
1873 X509 *peer_cert = NULL;
1874 EVP_MD_CTX *mctx = NULL;
1875 int al, verify;
1876 const unsigned char *hdata;
1877 size_t hdatalen;
1878 int type = 0;
1879 int ret;
1880
1881 if ((ret = ssl3_get_message(s, SSL3_ST_SR_CERT_VRFY_A,
1882 SSL3_ST_SR_CERT_VRFY_B, -1, SSL3_RT_MAX_PLAIN_LENGTH)) <= 0)
1883 return ret;
1884
1885 ret = 0;
1886
1887 if (s->init_num < 0)
1888 goto err;
1889
1890 if ((mctx = EVP_MD_CTX_new()) == NULL)
1891 goto err;
1892
1893 CBS_init(&cbs, s->init_msg, s->init_num);
1894
1895 peer_cert = s->session->peer_cert;
1896 pkey = X509_get0_pubkey(peer_cert);
1897 type = X509_certificate_type(peer_cert, pkey);
1898
1899 if (s->s3->hs.tls12.message_type != SSL3_MT_CERTIFICATE_VERIFY) {
1900 s->s3->hs.tls12.reuse_message = 1;
1901 if (peer_cert != NULL) {
1902 al = SSL_AD_UNEXPECTED_MESSAGE;
1903 SSLerror(s, SSL_R_MISSING_VERIFY_MESSAGE);
1904 goto fatal_err;
1905 }
1906 ret = 1;
1907 goto end;
1908 }
1909
1910 if (peer_cert == NULL) {
1911 SSLerror(s, SSL_R_NO_CLIENT_CERT_RECEIVED);
1912 al = SSL_AD_UNEXPECTED_MESSAGE;
1913 goto fatal_err;
1914 }
1915
1916 if (!(type & EVP_PKT_SIGN)) {
1917 SSLerror(s, SSL_R_SIGNATURE_FOR_NON_SIGNING_CERTIFICATE);
1918 al = SSL_AD_ILLEGAL_PARAMETER;
1919 goto fatal_err;
1920 }
1921
1922 if (s->s3->change_cipher_spec) {
1923 SSLerror(s, SSL_R_CCS_RECEIVED_EARLY);
1924 al = SSL_AD_UNEXPECTED_MESSAGE;
1925 goto fatal_err;
1926 }
1927
1928 if (SSL_USE_SIGALGS(s)) {
1929 if (!CBS_get_u16(&cbs, &sigalg_value))
1930 goto decode_err;
1931 }
1932 if (!CBS_get_u16_length_prefixed(&cbs, &signature))
1933 goto err;
1934 if (CBS_len(&cbs) != 0) {
1935 al = SSL_AD_DECODE_ERROR;
1936 SSLerror(s, SSL_R_EXTRA_DATA_IN_MESSAGE);
1937 goto fatal_err;
1938 }
1939
1940 if (CBS_len(&signature) > EVP_PKEY_size(pkey)) {
1941 SSLerror(s, SSL_R_WRONG_SIGNATURE_SIZE);
1942 al = SSL_AD_DECODE_ERROR;
1943 goto fatal_err;
1944 }
1945
1946 if ((sigalg = ssl_sigalg_for_peer(s, pkey,
1947 sigalg_value)) == NULL) {
1948 al = SSL_AD_DECODE_ERROR;
1949 goto fatal_err;
1950 }
1951 s->s3->hs.peer_sigalg = sigalg;
1952
1953 if (SSL_USE_SIGALGS(s)) {
1954 EVP_PKEY_CTX *pctx;
1955
1956 if (!tls1_transcript_data(s, &hdata, &hdatalen)) {
1957 SSLerror(s, ERR_R_INTERNAL_ERROR);
1958 al = SSL_AD_INTERNAL_ERROR;
1959 goto fatal_err;
1960 }
1961 if (!EVP_DigestVerifyInit(mctx, &pctx, sigalg->md(),
1962 NULL, pkey)) {
1963 SSLerror(s, ERR_R_EVP_LIB);
1964 al = SSL_AD_INTERNAL_ERROR;
1965 goto fatal_err;
1966 }
1967 if ((sigalg->flags & SIGALG_FLAG_RSA_PSS) &&
1968 (!EVP_PKEY_CTX_set_rsa_padding(pctx,
1969 RSA_PKCS1_PSS_PADDING) ||
1970 !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))) {
1971 al = SSL_AD_INTERNAL_ERROR;
1972 goto fatal_err;
1973 }
1974 if (EVP_DigestVerify(mctx, CBS_data(&signature),
1975 CBS_len(&signature), hdata, hdatalen) <= 0) {
1976 SSLerror(s, ERR_R_EVP_LIB);
1977 al = SSL_AD_INTERNAL_ERROR;
1978 goto fatal_err;
1979 }
1980 } else if (EVP_PKEY_id(pkey) == EVP_PKEY_RSA) {
1981 RSA *rsa;
1982
1983 if ((rsa = EVP_PKEY_get0_RSA(pkey)) == NULL) {
1984 al = SSL_AD_INTERNAL_ERROR;
1985 SSLerror(s, ERR_R_EVP_LIB);
1986 goto fatal_err;
1987 }
1988 verify = RSA_verify(NID_md5_sha1, s->s3->hs.tls12.cert_verify,
1989 MD5_DIGEST_LENGTH + SHA_DIGEST_LENGTH, CBS_data(&signature),
1990 CBS_len(&signature), rsa);
1991 if (verify < 0) {
1992 al = SSL_AD_DECRYPT_ERROR;
1993 SSLerror(s, SSL_R_BAD_RSA_DECRYPT);
1994 goto fatal_err;
1995 }
1996 if (verify == 0) {
1997 al = SSL_AD_DECRYPT_ERROR;
1998 SSLerror(s, SSL_R_BAD_RSA_SIGNATURE);
1999 goto fatal_err;
2000 }
2001 } else if (EVP_PKEY_id(pkey) == EVP_PKEY_EC) {
2002 EC_KEY *eckey;
2003
2004 if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL) {
2005 al = SSL_AD_INTERNAL_ERROR;
2006 SSLerror(s, ERR_R_EVP_LIB);
2007 goto fatal_err;
2008 }
2009 verify = ECDSA_verify(0,
2010 &(s->s3->hs.tls12.cert_verify[MD5_DIGEST_LENGTH]),
2011 SHA_DIGEST_LENGTH, CBS_data(&signature),
2012 CBS_len(&signature), eckey);
2013 if (verify <= 0) {
2014 al = SSL_AD_DECRYPT_ERROR;
2015 SSLerror(s, SSL_R_BAD_ECDSA_SIGNATURE);
2016 goto fatal_err;
2017 }
2018 } else {
2019 SSLerror(s, ERR_R_INTERNAL_ERROR);
2020 al = SSL_AD_UNSUPPORTED_CERTIFICATE;
2021 goto fatal_err;
2022 }
2023
2024 ret = 1;
2025 if (0) {
2026 decode_err:
2027 al = SSL_AD_DECODE_ERROR;
2028 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
2029 fatal_err:
2030 ssl3_send_alert(s, SSL3_AL_FATAL, al);
2031 }
2032 end:
2033 tls1_transcript_free(s);
2034 err:
2035 EVP_MD_CTX_free(mctx);
2036
2037 return (ret);
2038}
2039
2040static int
2041ssl3_get_client_certificate(SSL *s)
2042{
2043 CBS cbs, cert_list, cert_data;
2044 STACK_OF(X509) *certs = NULL;
2045 X509 *cert = NULL;
2046 const uint8_t *p;
2047 int al, ret;
2048
2049 if ((ret = ssl3_get_message(s, SSL3_ST_SR_CERT_A, SSL3_ST_SR_CERT_B,
2050 -1, s->max_cert_list)) <= 0)
2051 return ret;
2052
2053 ret = -1;
2054
2055 if (s->s3->hs.tls12.message_type == SSL3_MT_CLIENT_KEY_EXCHANGE) {
2056 if ((s->verify_mode & SSL_VERIFY_PEER) &&
2057 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
2058 SSLerror(s, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
2059 al = SSL_AD_HANDSHAKE_FAILURE;
2060 goto fatal_err;
2061 }
2062
2063 /*
2064 * If we asked for a client certificate and the client has none,
2065 * it must respond with a certificate list of length zero.
2066 */
2067 if (s->s3->hs.tls12.cert_request != 0) {
2068 SSLerror(s, SSL_R_TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST);
2069 al = SSL_AD_UNEXPECTED_MESSAGE;
2070 goto fatal_err;
2071 }
2072 s->s3->hs.tls12.reuse_message = 1;
2073 return (1);
2074 }
2075
2076 if (s->s3->hs.tls12.message_type != SSL3_MT_CERTIFICATE) {
2077 al = SSL_AD_UNEXPECTED_MESSAGE;
2078 SSLerror(s, SSL_R_WRONG_MESSAGE_TYPE);
2079 goto fatal_err;
2080 }
2081
2082 if (s->init_num < 0)
2083 goto decode_err;
2084
2085 CBS_init(&cbs, s->init_msg, s->init_num);
2086
2087 if (!CBS_get_u24_length_prefixed(&cbs, &cert_list))
2088 goto decode_err;
2089 if (CBS_len(&cbs) != 0)
2090 goto decode_err;
2091
2092 /*
2093 * A TLS client must send an empty certificate list, if no suitable
2094 * certificate is available (rather than omitting the Certificate
2095 * handshake message) - see RFC 5246 section 7.4.6.
2096 */
2097 if (CBS_len(&cert_list) == 0) {
2098 if ((s->verify_mode & SSL_VERIFY_PEER) &&
2099 (s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT)) {
2100 SSLerror(s, SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE);
2101 al = SSL_AD_HANDSHAKE_FAILURE;
2102 goto fatal_err;
2103 }
2104 /* No client certificate so free transcript. */
2105 tls1_transcript_free(s);
2106 goto done;
2107 }
2108
2109 if ((certs = sk_X509_new_null()) == NULL) {
2110 SSLerror(s, ERR_R_MALLOC_FAILURE);
2111 goto err;
2112 }
2113
2114 while (CBS_len(&cert_list) > 0) {
2115 if (!CBS_get_u24_length_prefixed(&cert_list, &cert_data))
2116 goto decode_err;
2117 p = CBS_data(&cert_data);
2118 if ((cert = d2i_X509(NULL, &p, CBS_len(&cert_data))) == NULL) {
2119 SSLerror(s, ERR_R_ASN1_LIB);
2120 goto err;
2121 }
2122 if (p != CBS_data(&cert_data) + CBS_len(&cert_data))
2123 goto decode_err;
2124 if (!sk_X509_push(certs, cert)) {
2125 SSLerror(s, ERR_R_MALLOC_FAILURE);
2126 goto err;
2127 }
2128 cert = NULL;
2129 }
2130
2131 if (ssl_verify_cert_chain(s, certs) <= 0) {
2132 al = ssl_verify_alarm_type(s->verify_result);
2133 SSLerror(s, SSL_R_NO_CERTIFICATE_RETURNED);
2134 goto fatal_err;
2135 }
2136 s->session->verify_result = s->verify_result;
2137 ERR_clear_error();
2138
2139 if (!tls_process_peer_certs(s, certs))
2140 goto err;
2141
2142 done:
2143 ret = 1;
2144 if (0) {
2145 decode_err:
2146 al = SSL_AD_DECODE_ERROR;
2147 SSLerror(s, SSL_R_BAD_PACKET_LENGTH);
2148 fatal_err:
2149 ssl3_send_alert(s, SSL3_AL_FATAL, al);
2150 }
2151 err:
2152 sk_X509_pop_free(certs, X509_free);
2153 X509_free(cert);
2154
2155 return (ret);
2156}
2157
2158static int
2159ssl3_send_server_certificate(SSL *s)
2160{
2161 CBB cbb, server_cert;
2162 SSL_CERT_PKEY *cpk;
2163
2164 /*
2165 * Server Certificate - RFC 5246, section 7.4.2.
2166 */
2167
2168 memset(&cbb, 0, sizeof(cbb));
2169
2170 if (s->s3->hs.state == SSL3_ST_SW_CERT_A) {
2171 if ((cpk = ssl_get_server_send_pkey(s)) == NULL) {
2172 SSLerror(s, ERR_R_INTERNAL_ERROR);
2173 return (0);
2174 }
2175
2176 if (!ssl3_handshake_msg_start(s, &cbb, &server_cert,
2177 SSL3_MT_CERTIFICATE))
2178 goto err;
2179 if (!ssl3_output_cert_chain(s, &server_cert, cpk))
2180 goto err;
2181 if (!ssl3_handshake_msg_finish(s, &cbb))
2182 goto err;
2183
2184 s->s3->hs.state = SSL3_ST_SW_CERT_B;
2185 }
2186
2187 /* SSL3_ST_SW_CERT_B */
2188 return (ssl3_handshake_write(s));
2189
2190 err:
2191 CBB_cleanup(&cbb);
2192
2193 return (0);
2194}
2195
2196/* send a new session ticket (not necessarily for a new session) */
2197static int
2198ssl3_send_newsession_ticket(SSL *s)
2199{
2200 CBB cbb, session_ticket, ticket;
2201 SSL_CTX *tctx = s->initial_ctx;
2202 size_t enc_session_len, enc_session_max_len, hmac_len;
2203 size_t session_len = 0;
2204 unsigned char *enc_session = NULL, *session = NULL;
2205 unsigned char iv[EVP_MAX_IV_LENGTH];
2206 unsigned char key_name[16];
2207 unsigned char *hmac;
2208 unsigned int hlen;
2209 EVP_CIPHER_CTX *ctx = NULL;
2210 HMAC_CTX *hctx = NULL;
2211 int iv_len, len;
2212
2213 /*
2214 * New Session Ticket - RFC 5077, section 3.3.
2215 */
2216
2217 memset(&cbb, 0, sizeof(cbb));
2218
2219 if ((ctx = EVP_CIPHER_CTX_new()) == NULL)
2220 goto err;
2221 if ((hctx = HMAC_CTX_new()) == NULL)
2222 goto err;
2223
2224 if (s->s3->hs.state == SSL3_ST_SW_SESSION_TICKET_A) {
2225 if (!ssl3_handshake_msg_start(s, &cbb, &session_ticket,
2226 SSL3_MT_NEWSESSION_TICKET))
2227 goto err;
2228
2229 if (!SSL_SESSION_ticket(s->session, &session, &session_len))
2230 goto err;
2231 if (session_len > 0xffff)
2232 goto err;
2233
2234 /*
2235 * Initialize HMAC and cipher contexts. If callback is present
2236 * it does all the work, otherwise use generated values from
2237 * parent context.
2238 */
2239 if (tctx->tlsext_ticket_key_cb != NULL) {
2240 if (tctx->tlsext_ticket_key_cb(s,
2241 key_name, iv, ctx, hctx, 1) < 0)
2242 goto err;
2243 } else {
2244 arc4random_buf(iv, 16);
2245 EVP_EncryptInit_ex(ctx, EVP_aes_128_cbc(), NULL,
2246 tctx->tlsext_tick_aes_key, iv);
2247 HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key,
2248 16, EVP_sha256(), NULL);
2249 memcpy(key_name, tctx->tlsext_tick_key_name, 16);
2250 }
2251
2252 /* Encrypt the session state. */
2253 enc_session_max_len = session_len + EVP_MAX_BLOCK_LENGTH;
2254 if ((enc_session = calloc(1, enc_session_max_len)) == NULL)
2255 goto err;
2256 enc_session_len = 0;
2257 if (!EVP_EncryptUpdate(ctx, enc_session, &len, session,
2258 session_len))
2259 goto err;
2260 enc_session_len += len;
2261 if (!EVP_EncryptFinal_ex(ctx, enc_session + enc_session_len,
2262 &len))
2263 goto err;
2264 enc_session_len += len;
2265
2266 if (enc_session_len > enc_session_max_len)
2267 goto err;
2268
2269 /* Generate the HMAC. */
2270 if (!HMAC_Update(hctx, key_name, sizeof(key_name)))
2271 goto err;
2272 if (!HMAC_Update(hctx, iv, EVP_CIPHER_CTX_iv_length(ctx)))
2273 goto err;
2274 if (!HMAC_Update(hctx, enc_session, enc_session_len))
2275 goto err;
2276
2277 if ((hmac_len = HMAC_size(hctx)) <= 0)
2278 goto err;
2279
2280 /*
2281 * Ticket lifetime hint (advisory only):
2282 * We leave this unspecified for resumed session
2283 * (for simplicity), and guess that tickets for new
2284 * sessions will live as long as their sessions.
2285 */
2286 if (!CBB_add_u32(&session_ticket,
2287 s->hit ? 0 : s->session->timeout))
2288 goto err;
2289
2290 if (!CBB_add_u16_length_prefixed(&session_ticket, &ticket))
2291 goto err;
2292 if (!CBB_add_bytes(&ticket, key_name, sizeof(key_name)))
2293 goto err;
2294 if ((iv_len = EVP_CIPHER_CTX_iv_length(ctx)) < 0)
2295 goto err;
2296 if (!CBB_add_bytes(&ticket, iv, iv_len))
2297 goto err;
2298 if (!CBB_add_bytes(&ticket, enc_session, enc_session_len))
2299 goto err;
2300 if (!CBB_add_space(&ticket, &hmac, hmac_len))
2301 goto err;
2302
2303 if (!HMAC_Final(hctx, hmac, &hlen))
2304 goto err;
2305 if (hlen != hmac_len)
2306 goto err;
2307
2308 if (!ssl3_handshake_msg_finish(s, &cbb))
2309 goto err;
2310
2311 s->s3->hs.state = SSL3_ST_SW_SESSION_TICKET_B;
2312 }
2313
2314 EVP_CIPHER_CTX_free(ctx);
2315 HMAC_CTX_free(hctx);
2316 freezero(session, session_len);
2317 free(enc_session);
2318
2319 /* SSL3_ST_SW_SESSION_TICKET_B */
2320 return (ssl3_handshake_write(s));
2321
2322 err:
2323 CBB_cleanup(&cbb);
2324 EVP_CIPHER_CTX_free(ctx);
2325 HMAC_CTX_free(hctx);
2326 freezero(session, session_len);
2327 free(enc_session);
2328
2329 return (-1);
2330}
2331
2332static int
2333ssl3_send_cert_status(SSL *s)
2334{
2335 CBB cbb, certstatus, ocspresp;
2336
2337 memset(&cbb, 0, sizeof(cbb));
2338
2339 if (s->s3->hs.state == SSL3_ST_SW_CERT_STATUS_A) {
2340 if (!ssl3_handshake_msg_start(s, &cbb, &certstatus,
2341 SSL3_MT_CERTIFICATE_STATUS))
2342 goto err;
2343 if (!CBB_add_u8(&certstatus, s->tlsext_status_type))
2344 goto err;
2345 if (!CBB_add_u24_length_prefixed(&certstatus, &ocspresp))
2346 goto err;
2347 if (!CBB_add_bytes(&ocspresp, s->tlsext_ocsp_resp,
2348 s->tlsext_ocsp_resp_len))
2349 goto err;
2350 if (!ssl3_handshake_msg_finish(s, &cbb))
2351 goto err;
2352
2353 s->s3->hs.state = SSL3_ST_SW_CERT_STATUS_B;
2354 }
2355
2356 /* SSL3_ST_SW_CERT_STATUS_B */
2357 return (ssl3_handshake_write(s));
2358
2359 err:
2360 CBB_cleanup(&cbb);
2361
2362 return (-1);
2363}
2364
2365static int
2366ssl3_send_server_change_cipher_spec(SSL *s)
2367{
2368 size_t outlen;
2369 CBB cbb;
2370
2371 memset(&cbb, 0, sizeof(cbb));
2372
2373 if (s->s3->hs.state == SSL3_ST_SW_CHANGE_A) {
2374 if (!CBB_init_fixed(&cbb, s->init_buf->data,
2375 s->init_buf->length))
2376 goto err;
2377 if (!CBB_add_u8(&cbb, SSL3_MT_CCS))
2378 goto err;
2379 if (!CBB_finish(&cbb, NULL, &outlen))
2380 goto err;
2381
2382 if (outlen > INT_MAX)
2383 goto err;
2384
2385 s->init_num = (int)outlen;
2386 s->init_off = 0;
2387
2388 if (SSL_is_dtls(s)) {
2389 s->d1->handshake_write_seq =
2390 s->d1->next_handshake_write_seq;
2391 dtls1_set_message_header_int(s, SSL3_MT_CCS, 0,
2392 s->d1->handshake_write_seq, 0, 0);
2393 dtls1_buffer_message(s, 1);
2394 }
2395
2396 s->s3->hs.state = SSL3_ST_SW_CHANGE_B;
2397 }
2398
2399 /* SSL3_ST_SW_CHANGE_B */
2400 return ssl3_record_write(s, SSL3_RT_CHANGE_CIPHER_SPEC);
2401
2402 err:
2403 CBB_cleanup(&cbb);
2404
2405 return -1;
2406}
2407
2408static int
2409ssl3_get_client_finished(SSL *s)
2410{
2411 int al, md_len, ret;
2412 CBS cbs;
2413
2414 /* should actually be 36+4 :-) */
2415 if ((ret = ssl3_get_message(s, SSL3_ST_SR_FINISHED_A,
2416 SSL3_ST_SR_FINISHED_B, SSL3_MT_FINISHED, 64)) <= 0)
2417 return ret;
2418
2419 /* If this occurs, we have missed a message */
2420 if (!s->s3->change_cipher_spec) {
2421 al = SSL_AD_UNEXPECTED_MESSAGE;
2422 SSLerror(s, SSL_R_GOT_A_FIN_BEFORE_A_CCS);
2423 goto fatal_err;
2424 }
2425 s->s3->change_cipher_spec = 0;
2426
2427 md_len = TLS1_FINISH_MAC_LENGTH;
2428
2429 if (s->init_num < 0) {
2430 al = SSL_AD_DECODE_ERROR;
2431 SSLerror(s, SSL_R_BAD_DIGEST_LENGTH);
2432 goto fatal_err;
2433 }
2434
2435 CBS_init(&cbs, s->init_msg, s->init_num);
2436
2437 if (s->s3->hs.peer_finished_len != md_len ||
2438 CBS_len(&cbs) != md_len) {
2439 al = SSL_AD_DECODE_ERROR;
2440 SSLerror(s, SSL_R_BAD_DIGEST_LENGTH);
2441 goto fatal_err;
2442 }
2443
2444 if (!CBS_mem_equal(&cbs, s->s3->hs.peer_finished, CBS_len(&cbs))) {
2445 al = SSL_AD_DECRYPT_ERROR;
2446 SSLerror(s, SSL_R_DIGEST_CHECK_FAILED);
2447 goto fatal_err;
2448 }
2449
2450 /* Copy finished so we can use it for renegotiation checks. */
2451 OPENSSL_assert(md_len <= EVP_MAX_MD_SIZE);
2452 memcpy(s->s3->previous_client_finished,
2453 s->s3->hs.peer_finished, md_len);
2454 s->s3->previous_client_finished_len = md_len;
2455
2456 return (1);
2457 fatal_err:
2458 ssl3_send_alert(s, SSL3_AL_FATAL, al);
2459 return (0);
2460}
2461
2462static int
2463ssl3_send_server_finished(SSL *s)
2464{
2465 CBB cbb, finished;
2466
2467 memset(&cbb, 0, sizeof(cbb));
2468
2469 if (s->s3->hs.state == SSL3_ST_SW_FINISHED_A) {
2470 if (!tls12_derive_finished(s))
2471 goto err;
2472
2473 /* Copy finished so we can use it for renegotiation checks. */
2474 memcpy(s->s3->previous_server_finished,
2475 s->s3->hs.finished, s->s3->hs.finished_len);
2476 s->s3->previous_server_finished_len = s->s3->hs.finished_len;
2477
2478 if (!ssl3_handshake_msg_start(s, &cbb, &finished,
2479 SSL3_MT_FINISHED))
2480 goto err;
2481 if (!CBB_add_bytes(&finished, s->s3->hs.finished,
2482 s->s3->hs.finished_len))
2483 goto err;
2484 if (!ssl3_handshake_msg_finish(s, &cbb))
2485 goto err;
2486
2487 s->s3->hs.state = SSL3_ST_SW_FINISHED_B;
2488 }
2489
2490 return (ssl3_handshake_write(s));
2491
2492 err:
2493 CBB_cleanup(&cbb);
2494
2495 return (-1);
2496}
diff --git a/src/lib/libssl/ssl_stat.c b/src/lib/libssl/ssl_stat.c
deleted file mode 100644
index b19944ca83..0000000000
--- a/src/lib/libssl/ssl_stat.c
+++ /dev/null
@@ -1,596 +0,0 @@
1/* $OpenBSD: ssl_stat.c,v 1.23 2024/10/12 03:54:18 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright 2005 Nokia. All rights reserved.
60 *
61 * The portions of the attached software ("Contribution") is developed by
62 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63 * license.
64 *
65 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67 * support (see RFC 4279) to OpenSSL.
68 *
69 * No patent licenses or other rights except those expressly stated in
70 * the OpenSSL open source license shall be deemed granted or received
71 * expressly, by implication, estoppel, or otherwise.
72 *
73 * No assurances are provided by Nokia that the Contribution does not
74 * infringe the patent or other intellectual property rights of any third
75 * party or that the license provides you with all the necessary rights
76 * to make use of the Contribution.
77 *
78 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82 * OTHERWISE.
83 */
84
85#include <stdio.h>
86
87#include "ssl_local.h"
88
89const char *
90SSL_state_string_long(const SSL *s)
91{
92 switch (s->s3->hs.state) {
93 case SSL_ST_BEFORE:
94 return "before SSL initialization";
95 case SSL_ST_ACCEPT:
96 return "before accept initialization";
97 case SSL_ST_CONNECT:
98 return "before connect initialization";
99 case SSL_ST_OK:
100 return "SSL negotiation finished successfully";
101 case SSL_ST_RENEGOTIATE:
102 return "SSL renegotiate ciphers";
103 case SSL_ST_BEFORE|SSL_ST_CONNECT:
104 return "before/connect initialization";
105 case SSL_ST_OK|SSL_ST_CONNECT:
106 return "ok/connect SSL initialization";
107 case SSL_ST_BEFORE|SSL_ST_ACCEPT:
108 return "before/accept initialization";
109 case SSL_ST_OK|SSL_ST_ACCEPT:
110 return "ok/accept SSL initialization";
111
112 /* SSLv3 additions */
113 case SSL3_ST_CW_CLNT_HELLO_A:
114 return "SSLv3 write client hello A";
115 case SSL3_ST_CW_CLNT_HELLO_B:
116 return "SSLv3 write client hello B";
117 case SSL3_ST_CR_SRVR_HELLO_A:
118 return "SSLv3 read server hello A";
119 case SSL3_ST_CR_SRVR_HELLO_B:
120 return "SSLv3 read server hello B";
121 case SSL3_ST_CR_CERT_A:
122 return "SSLv3 read server certificate A";
123 case SSL3_ST_CR_CERT_B:
124 return "SSLv3 read server certificate B";
125 case SSL3_ST_CR_KEY_EXCH_A:
126 return "SSLv3 read server key exchange A";
127 case SSL3_ST_CR_KEY_EXCH_B:
128 return "SSLv3 read server key exchange B";
129 case SSL3_ST_CR_CERT_REQ_A:
130 return "SSLv3 read server certificate request A";
131 case SSL3_ST_CR_CERT_REQ_B:
132 return "SSLv3 read server certificate request B";
133 case SSL3_ST_CR_SESSION_TICKET_A:
134 return "SSLv3 read server session ticket A";
135 case SSL3_ST_CR_SESSION_TICKET_B:
136 return "SSLv3 read server session ticket B";
137 case SSL3_ST_CR_SRVR_DONE_A:
138 return "SSLv3 read server done A";
139 case SSL3_ST_CR_SRVR_DONE_B:
140 return "SSLv3 read server done B";
141 case SSL3_ST_CW_CERT_A:
142 return "SSLv3 write client certificate A";
143 case SSL3_ST_CW_CERT_B:
144 return "SSLv3 write client certificate B";
145 case SSL3_ST_CW_CERT_C:
146 return "SSLv3 write client certificate C";
147 case SSL3_ST_CW_CERT_D:
148 return "SSLv3 write client certificate D";
149 case SSL3_ST_CW_KEY_EXCH_A:
150 return "SSLv3 write client key exchange A";
151 case SSL3_ST_CW_KEY_EXCH_B:
152 return "SSLv3 write client key exchange B";
153 case SSL3_ST_CW_CERT_VRFY_A:
154 return "SSLv3 write certificate verify A";
155 case SSL3_ST_CW_CERT_VRFY_B:
156 return "SSLv3 write certificate verify B";
157
158 case SSL3_ST_CW_CHANGE_A:
159 case SSL3_ST_SW_CHANGE_A:
160 return "SSLv3 write change cipher spec A";
161 case SSL3_ST_CW_CHANGE_B:
162 case SSL3_ST_SW_CHANGE_B:
163 return "SSLv3 write change cipher spec B";
164 case SSL3_ST_CW_FINISHED_A:
165 case SSL3_ST_SW_FINISHED_A:
166 return "SSLv3 write finished A";
167 case SSL3_ST_CW_FINISHED_B:
168 case SSL3_ST_SW_FINISHED_B:
169 return "SSLv3 write finished B";
170 case SSL3_ST_CR_CHANGE_A:
171 case SSL3_ST_SR_CHANGE_A:
172 return "SSLv3 read change cipher spec A";
173 case SSL3_ST_CR_CHANGE_B:
174 case SSL3_ST_SR_CHANGE_B:
175 return "SSLv3 read change cipher spec B";
176 case SSL3_ST_CR_FINISHED_A:
177 case SSL3_ST_SR_FINISHED_A:
178 return "SSLv3 read finished A";
179 case SSL3_ST_CR_FINISHED_B:
180 case SSL3_ST_SR_FINISHED_B:
181 return "SSLv3 read finished B";
182
183 case SSL3_ST_CW_FLUSH:
184 case SSL3_ST_SW_FLUSH:
185 return "SSLv3 flush data";
186
187 case SSL3_ST_SR_CLNT_HELLO_A:
188 return "SSLv3 read client hello A";
189 case SSL3_ST_SR_CLNT_HELLO_B:
190 return "SSLv3 read client hello B";
191 case SSL3_ST_SR_CLNT_HELLO_C:
192 return "SSLv3 read client hello C";
193 case SSL3_ST_SW_HELLO_REQ_A:
194 return "SSLv3 write hello request A";
195 case SSL3_ST_SW_HELLO_REQ_B:
196 return "SSLv3 write hello request B";
197 case SSL3_ST_SW_HELLO_REQ_C:
198 return "SSLv3 write hello request C";
199 case SSL3_ST_SW_SRVR_HELLO_A:
200 return "SSLv3 write server hello A";
201 case SSL3_ST_SW_SRVR_HELLO_B:
202 return "SSLv3 write server hello B";
203 case SSL3_ST_SW_CERT_A:
204 return "SSLv3 write certificate A";
205 case SSL3_ST_SW_CERT_B:
206 return "SSLv3 write certificate B";
207 case SSL3_ST_SW_KEY_EXCH_A:
208 return "SSLv3 write key exchange A";
209 case SSL3_ST_SW_KEY_EXCH_B:
210 return "SSLv3 write key exchange B";
211 case SSL3_ST_SW_CERT_REQ_A:
212 return "SSLv3 write certificate request A";
213 case SSL3_ST_SW_CERT_REQ_B:
214 return "SSLv3 write certificate request B";
215 case SSL3_ST_SW_SESSION_TICKET_A:
216 return "SSLv3 write session ticket A";
217 case SSL3_ST_SW_SESSION_TICKET_B:
218 return "SSLv3 write session ticket B";
219 case SSL3_ST_SW_SRVR_DONE_A:
220 return "SSLv3 write server done A";
221 case SSL3_ST_SW_SRVR_DONE_B:
222 return "SSLv3 write server done B";
223 case SSL3_ST_SR_CERT_A:
224 return "SSLv3 read client certificate A";
225 case SSL3_ST_SR_CERT_B:
226 return "SSLv3 read client certificate B";
227 case SSL3_ST_SR_KEY_EXCH_A:
228 return "SSLv3 read client key exchange A";
229 case SSL3_ST_SR_KEY_EXCH_B:
230 return "SSLv3 read client key exchange B";
231 case SSL3_ST_SR_CERT_VRFY_A:
232 return "SSLv3 read certificate verify A";
233 case SSL3_ST_SR_CERT_VRFY_B:
234 return "SSLv3 read certificate verify B";
235
236 /* DTLS */
237 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
238 return "DTLS1 read hello verify request A";
239 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
240 return "DTLS1 read hello verify request B";
241 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
242 return "DTLS1 write hello verify request A";
243 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
244 return "DTLS1 write hello verify request B";
245
246 default:
247 return "unknown state";
248 }
249}
250LSSL_ALIAS(SSL_state_string_long);
251
252const char *
253SSL_rstate_string_long(const SSL *s)
254{
255 switch (s->rstate) {
256 case SSL_ST_READ_HEADER:
257 return "read header";
258 case SSL_ST_READ_BODY:
259 return "read body";
260 case SSL_ST_READ_DONE:
261 return "read done";
262 default:
263 return "unknown";
264 }
265}
266LSSL_ALIAS(SSL_rstate_string_long);
267
268const char *
269SSL_state_string(const SSL *s)
270{
271 switch (s->s3->hs.state) {
272 case SSL_ST_BEFORE:
273 return "PINIT ";
274 case SSL_ST_ACCEPT:
275 return "AINIT ";
276 case SSL_ST_CONNECT:
277 return "CINIT ";
278 case SSL_ST_OK:
279 return "SSLOK ";
280
281 /* SSLv3 additions */
282 case SSL3_ST_SW_FLUSH:
283 case SSL3_ST_CW_FLUSH:
284 return "3FLUSH";
285 case SSL3_ST_CW_CLNT_HELLO_A:
286 return "3WCH_A";
287 case SSL3_ST_CW_CLNT_HELLO_B:
288 return "3WCH_B";
289 case SSL3_ST_CR_SRVR_HELLO_A:
290 return "3RSH_A";
291 case SSL3_ST_CR_SRVR_HELLO_B:
292 return "3RSH_B";
293 case SSL3_ST_CR_CERT_A:
294 return "3RSC_A";
295 case SSL3_ST_CR_CERT_B:
296 return "3RSC_B";
297 case SSL3_ST_CR_KEY_EXCH_A:
298 return "3RSKEA";
299 case SSL3_ST_CR_KEY_EXCH_B:
300 return "3RSKEB";
301 case SSL3_ST_CR_CERT_REQ_A:
302 return "3RCR_A";
303 case SSL3_ST_CR_CERT_REQ_B:
304 return "3RCR_B";
305 case SSL3_ST_CR_SRVR_DONE_A:
306 return "3RSD_A";
307 case SSL3_ST_CR_SRVR_DONE_B:
308 return "3RSD_B";
309 case SSL3_ST_CW_CERT_A:
310 return "3WCC_A";
311 case SSL3_ST_CW_CERT_B:
312 return "3WCC_B";
313 case SSL3_ST_CW_CERT_C:
314 return "3WCC_C";
315 case SSL3_ST_CW_CERT_D:
316 return "3WCC_D";
317 case SSL3_ST_CW_KEY_EXCH_A:
318 return "3WCKEA";
319 case SSL3_ST_CW_KEY_EXCH_B:
320 return "3WCKEB";
321 case SSL3_ST_CW_CERT_VRFY_A:
322 return "3WCV_A";
323 case SSL3_ST_CW_CERT_VRFY_B:
324 return "3WCV_B";
325
326 case SSL3_ST_SW_CHANGE_A:
327 case SSL3_ST_CW_CHANGE_A:
328 return "3WCCSA";
329 case SSL3_ST_SW_CHANGE_B:
330 case SSL3_ST_CW_CHANGE_B:
331 return "3WCCSB";
332 case SSL3_ST_SW_FINISHED_A:
333 case SSL3_ST_CW_FINISHED_A:
334 return "3WFINA";
335 case SSL3_ST_SW_FINISHED_B:
336 case SSL3_ST_CW_FINISHED_B:
337 return "3WFINB";
338 case SSL3_ST_SR_CHANGE_A:
339 case SSL3_ST_CR_CHANGE_A:
340 return "3RCCSA";
341 case SSL3_ST_SR_CHANGE_B:
342 case SSL3_ST_CR_CHANGE_B:
343 return "3RCCSB";
344 case SSL3_ST_SR_FINISHED_A:
345 case SSL3_ST_CR_FINISHED_A:
346 return "3RFINA";
347 case SSL3_ST_SR_FINISHED_B:
348 case SSL3_ST_CR_FINISHED_B:
349 return "3RFINB";
350
351 case SSL3_ST_SW_HELLO_REQ_A:
352 return "3WHR_A";
353 case SSL3_ST_SW_HELLO_REQ_B:
354 return "3WHR_B";
355 case SSL3_ST_SW_HELLO_REQ_C:
356 return "3WHR_C";
357 case SSL3_ST_SR_CLNT_HELLO_A:
358 return "3RCH_A";
359 case SSL3_ST_SR_CLNT_HELLO_B:
360 return "3RCH_B";
361 case SSL3_ST_SR_CLNT_HELLO_C:
362 return "3RCH_C";
363 case SSL3_ST_SW_SRVR_HELLO_A:
364 return "3WSH_A";
365 case SSL3_ST_SW_SRVR_HELLO_B:
366 return "3WSH_B";
367 case SSL3_ST_SW_CERT_A:
368 return "3WSC_A";
369 case SSL3_ST_SW_CERT_B:
370 return "3WSC_B";
371 case SSL3_ST_SW_KEY_EXCH_A:
372 return "3WSKEA";
373 case SSL3_ST_SW_KEY_EXCH_B:
374 return "3WSKEB";
375 case SSL3_ST_SW_CERT_REQ_A:
376 return "3WCR_A";
377 case SSL3_ST_SW_CERT_REQ_B:
378 return "3WCR_B";
379 case SSL3_ST_SW_SRVR_DONE_A:
380 return "3WSD_A";
381 case SSL3_ST_SW_SRVR_DONE_B:
382 return "3WSD_B";
383 case SSL3_ST_SR_CERT_A:
384 return "3RCC_A";
385 case SSL3_ST_SR_CERT_B:
386 return "3RCC_B";
387 case SSL3_ST_SR_KEY_EXCH_A:
388 return "3RCKEA";
389 case SSL3_ST_SR_KEY_EXCH_B:
390 return "3RCKEB";
391 case SSL3_ST_SR_CERT_VRFY_A:
392 return "3RCV_A";
393 case SSL3_ST_SR_CERT_VRFY_B:
394 return "3RCV_B";
395
396 /* DTLS */
397 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_A:
398 return "DRCHVA";
399 case DTLS1_ST_CR_HELLO_VERIFY_REQUEST_B:
400 return "DRCHVB";
401 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_A:
402 return "DWCHVA";
403 case DTLS1_ST_SW_HELLO_VERIFY_REQUEST_B:
404 return "DWCHVB";
405
406 default:
407 return "UNKWN ";
408 }
409}
410LSSL_ALIAS(SSL_state_string);
411
412const char *
413SSL_alert_type_string_long(int value)
414{
415 value >>= 8;
416 if (value == SSL3_AL_WARNING)
417 return "warning";
418 else if (value == SSL3_AL_FATAL)
419 return "fatal";
420 else
421 return "unknown";
422}
423LSSL_ALIAS(SSL_alert_type_string_long);
424
425const char *
426SSL_alert_type_string(int value)
427{
428 value >>= 8;
429 if (value == SSL3_AL_WARNING)
430 return "W";
431 else if (value == SSL3_AL_FATAL)
432 return "F";
433 else
434 return "U";
435}
436LSSL_ALIAS(SSL_alert_type_string);
437
438const char *
439SSL_alert_desc_string(int value)
440{
441 switch (value & 0xff) {
442 case SSL_AD_CLOSE_NOTIFY:
443 return "CN";
444 case SSL_AD_UNEXPECTED_MESSAGE:
445 return "UM";
446 case SSL_AD_BAD_RECORD_MAC:
447 return "BM";
448 case SSL_AD_RECORD_OVERFLOW:
449 return "RO";
450 case SSL_AD_DECOMPRESSION_FAILURE:
451 return "DF";
452 case SSL_AD_HANDSHAKE_FAILURE:
453 return "HF";
454 case SSL_AD_BAD_CERTIFICATE:
455 return "BC";
456 case SSL_AD_UNSUPPORTED_CERTIFICATE:
457 return "UC";
458 case SSL_AD_CERTIFICATE_REVOKED:
459 return "CR";
460 case SSL_AD_CERTIFICATE_EXPIRED:
461 return "CE";
462 case SSL_AD_CERTIFICATE_UNKNOWN:
463 return "CU";
464 case SSL_AD_ILLEGAL_PARAMETER:
465 return "IP";
466 case SSL_AD_UNKNOWN_CA:
467 return "CA";
468 case SSL_AD_ACCESS_DENIED:
469 return "AD";
470 case SSL_AD_DECODE_ERROR:
471 return "DE";
472 case SSL_AD_DECRYPT_ERROR:
473 return "CY";
474 case SSL_AD_PROTOCOL_VERSION:
475 return "PV";
476 case SSL_AD_INSUFFICIENT_SECURITY:
477 return "IS";
478 case SSL_AD_INTERNAL_ERROR:
479 return "IE";
480 case SSL_AD_INAPPROPRIATE_FALLBACK:
481 return "IF";
482 case SSL_AD_USER_CANCELLED:
483 return "US";
484 case SSL_AD_NO_RENEGOTIATION:
485 return "NR";
486 case SSL_AD_MISSING_EXTENSION:
487 return "ME";
488 case SSL_AD_UNSUPPORTED_EXTENSION:
489 return "UE";
490 case SSL_AD_CERTIFICATE_UNOBTAINABLE:
491 return "CO";
492 case SSL_AD_UNRECOGNIZED_NAME:
493 return "UN";
494 case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
495 return "BR";
496 case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
497 return "BH";
498 case SSL_AD_UNKNOWN_PSK_IDENTITY:
499 return "UP";
500 case SSL_AD_CERTIFICATE_REQUIRED:
501 return "CQ"; /* XXX */
502 case SSL_AD_NO_APPLICATION_PROTOCOL:
503 return "AP";
504 default:
505 return "UK";
506 }
507}
508LSSL_ALIAS(SSL_alert_desc_string);
509
510const char *
511SSL_alert_desc_string_long(int value)
512{
513 switch (value & 0xff) {
514 case SSL_AD_CLOSE_NOTIFY:
515 return "close notify";
516 case SSL_AD_UNEXPECTED_MESSAGE:
517 return "unexpected_message";
518 case SSL_AD_BAD_RECORD_MAC:
519 return "bad record mac";
520 case SSL_AD_RECORD_OVERFLOW:
521 return "record overflow";
522 case SSL_AD_DECOMPRESSION_FAILURE:
523 return "decompression failure";
524 case SSL_AD_HANDSHAKE_FAILURE:
525 return "handshake failure";
526 case SSL_AD_BAD_CERTIFICATE:
527 return "bad certificate";
528 case SSL_AD_UNSUPPORTED_CERTIFICATE:
529 return "unsupported certificate";
530 case SSL_AD_CERTIFICATE_REVOKED:
531 return "certificate revoked";
532 case SSL_AD_CERTIFICATE_EXPIRED:
533 return "certificate expired";
534 case SSL_AD_CERTIFICATE_UNKNOWN:
535 return "certificate unknown";
536 case SSL_AD_ILLEGAL_PARAMETER:
537 return "illegal parameter";
538 case SSL_AD_UNKNOWN_CA:
539 return "unknown CA";
540 case SSL_AD_ACCESS_DENIED:
541 return "access denied";
542 case SSL_AD_DECODE_ERROR:
543 return "decode error";
544 case SSL_AD_DECRYPT_ERROR:
545 return "decrypt error";
546 case SSL_AD_PROTOCOL_VERSION:
547 return "protocol version";
548 case SSL_AD_INSUFFICIENT_SECURITY:
549 return "insufficient security";
550 case SSL_AD_INTERNAL_ERROR:
551 return "internal error";
552 case SSL_AD_INAPPROPRIATE_FALLBACK:
553 return "inappropriate fallback";
554 case SSL_AD_USER_CANCELLED:
555 return "user canceled";
556 case SSL_AD_NO_RENEGOTIATION:
557 return "no renegotiation";
558 case SSL_AD_MISSING_EXTENSION:
559 return "missing extension";
560 case SSL_AD_UNSUPPORTED_EXTENSION:
561 return "unsupported extension";
562 case SSL_AD_CERTIFICATE_UNOBTAINABLE:
563 return "certificate unobtainable";
564 case SSL_AD_UNRECOGNIZED_NAME:
565 return "unrecognized name";
566 case SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE:
567 return "bad certificate status response";
568 case SSL_AD_BAD_CERTIFICATE_HASH_VALUE:
569 return "bad certificate hash value";
570 case SSL_AD_UNKNOWN_PSK_IDENTITY:
571 return "unknown PSK identity";
572 case SSL_AD_CERTIFICATE_REQUIRED:
573 return "certificate required";
574 case SSL_AD_NO_APPLICATION_PROTOCOL:
575 return "no application protocol";
576 default:
577 return "unknown";
578 }
579}
580LSSL_ALIAS(SSL_alert_desc_string_long);
581
582const char *
583SSL_rstate_string(const SSL *s)
584{
585 switch (s->rstate) {
586 case SSL_ST_READ_HEADER:
587 return "RH";
588 case SSL_ST_READ_BODY:
589 return "RB";
590 case SSL_ST_READ_DONE:
591 return "RD";
592 default:
593 return "unknown";
594 }
595}
596LSSL_ALIAS(SSL_rstate_string);
diff --git a/src/lib/libssl/ssl_tlsext.c b/src/lib/libssl/ssl_tlsext.c
deleted file mode 100644
index 08bf5593ec..0000000000
--- a/src/lib/libssl/ssl_tlsext.c
+++ /dev/null
@@ -1,2745 +0,0 @@
1/* $OpenBSD: ssl_tlsext.c,v 1.154 2024/07/09 12:27:27 beck Exp $ */
2/*
3 * Copyright (c) 2016, 2017, 2019 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2017 Doug Hogan <doug@openbsd.org>
5 * Copyright (c) 2018-2019, 2024 Bob Beck <beck@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include <sys/socket.h>
21
22#include <arpa/inet.h>
23#include <netinet/in.h>
24
25#include <ctype.h>
26
27#include <openssl/ocsp.h>
28#include <openssl/opensslconf.h>
29
30#include "bytestring.h"
31#include "ssl_local.h"
32#include "ssl_sigalgs.h"
33#include "ssl_tlsext.h"
34
35#define TLSEXT_TYPE_alpn TLSEXT_TYPE_application_layer_protocol_negotiation
36#define TLSEXT_MAX_SUPPORTED_GROUPS 64
37
38/*
39 * Supported Application-Layer Protocol Negotiation - RFC 7301
40 */
41
42static int
43tlsext_alpn_client_needs(SSL *s, uint16_t msg_type)
44{
45 /* ALPN protos have been specified and this is the initial handshake */
46 return s->alpn_client_proto_list != NULL &&
47 s->s3->hs.finished_len == 0;
48}
49
50static int
51tlsext_alpn_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
52{
53 CBB protolist;
54
55 if (!CBB_add_u16_length_prefixed(cbb, &protolist))
56 return 0;
57
58 if (!CBB_add_bytes(&protolist, s->alpn_client_proto_list,
59 s->alpn_client_proto_list_len))
60 return 0;
61
62 if (!CBB_flush(cbb))
63 return 0;
64
65 return 1;
66}
67
68int
69tlsext_alpn_check_format(CBS *cbs)
70{
71 CBS proto_name_list;
72
73 if (CBS_len(cbs) == 0)
74 return 0;
75
76 CBS_dup(cbs, &proto_name_list);
77 while (CBS_len(&proto_name_list) > 0) {
78 CBS proto_name;
79
80 if (!CBS_get_u8_length_prefixed(&proto_name_list, &proto_name))
81 return 0;
82 if (CBS_len(&proto_name) == 0)
83 return 0;
84 }
85
86 return 1;
87}
88
89static int
90tlsext_alpn_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
91{
92 CBS alpn, selected_cbs;
93 const unsigned char *selected;
94 unsigned char selected_len;
95 int r;
96
97 if (!CBS_get_u16_length_prefixed(cbs, &alpn))
98 return 0;
99 if (!tlsext_alpn_check_format(&alpn))
100 return 0;
101
102 if (s->ctx->alpn_select_cb == NULL)
103 return 1;
104
105 /*
106 * XXX - A few things should be considered here:
107 * 1. Ensure that the same protocol is selected on session resumption.
108 * 2. Should the callback be called even if no ALPN extension was sent?
109 * 3. TLSv1.2 and earlier: ensure that SNI has already been processed.
110 */
111 r = s->ctx->alpn_select_cb(s, &selected, &selected_len,
112 CBS_data(&alpn), CBS_len(&alpn), s->ctx->alpn_select_cb_arg);
113
114 if (r == SSL_TLSEXT_ERR_OK) {
115 CBS_init(&selected_cbs, selected, selected_len);
116
117 if (!CBS_stow(&selected_cbs, &s->s3->alpn_selected,
118 &s->s3->alpn_selected_len)) {
119 *alert = SSL_AD_INTERNAL_ERROR;
120 return 0;
121 }
122
123 return 1;
124 }
125
126 /* On SSL_TLSEXT_ERR_NOACK behave as if no callback was present. */
127 if (r == SSL_TLSEXT_ERR_NOACK)
128 return 1;
129
130 *alert = SSL_AD_NO_APPLICATION_PROTOCOL;
131 SSLerror(s, SSL_R_NO_APPLICATION_PROTOCOL);
132
133 return 0;
134}
135
136static int
137tlsext_alpn_server_needs(SSL *s, uint16_t msg_type)
138{
139 return s->s3->alpn_selected != NULL;
140}
141
142static int
143tlsext_alpn_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
144{
145 CBB list, selected;
146
147 if (!CBB_add_u16_length_prefixed(cbb, &list))
148 return 0;
149
150 if (!CBB_add_u8_length_prefixed(&list, &selected))
151 return 0;
152
153 if (!CBB_add_bytes(&selected, s->s3->alpn_selected,
154 s->s3->alpn_selected_len))
155 return 0;
156
157 if (!CBB_flush(cbb))
158 return 0;
159
160 return 1;
161}
162
163static int
164tlsext_alpn_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
165{
166 CBS list, proto;
167
168 if (s->alpn_client_proto_list == NULL) {
169 *alert = SSL_AD_UNSUPPORTED_EXTENSION;
170 return 0;
171 }
172
173 if (!CBS_get_u16_length_prefixed(cbs, &list))
174 return 0;
175
176 if (!CBS_get_u8_length_prefixed(&list, &proto))
177 return 0;
178
179 if (CBS_len(&list) != 0)
180 return 0;
181 if (CBS_len(&proto) == 0)
182 return 0;
183
184 if (!CBS_stow(&proto, &s->s3->alpn_selected, &s->s3->alpn_selected_len))
185 return 0;
186
187 return 1;
188}
189
190/*
191 * Supported Groups - RFC 7919 section 2
192 */
193static int
194tlsext_supportedgroups_client_needs(SSL *s, uint16_t msg_type)
195{
196 return ssl_has_ecc_ciphers(s) ||
197 (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION);
198}
199
200static int
201tlsext_supportedgroups_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
202{
203 const uint16_t *groups;
204 size_t groups_len;
205 CBB grouplist;
206 int i;
207
208 tls1_get_group_list(s, 0, &groups, &groups_len);
209 if (groups_len == 0) {
210 SSLerror(s, ERR_R_INTERNAL_ERROR);
211 return 0;
212 }
213
214 if (!CBB_add_u16_length_prefixed(cbb, &grouplist))
215 return 0;
216
217 for (i = 0; i < groups_len; i++) {
218 if (!ssl_security_supported_group(s, groups[i]))
219 continue;
220 if (!CBB_add_u16(&grouplist, groups[i]))
221 return 0;
222 }
223
224 if (!CBB_flush(cbb))
225 return 0;
226
227 return 1;
228}
229
230static int
231tlsext_supportedgroups_server_process(SSL *s, uint16_t msg_type, CBS *cbs,
232 int *alert)
233{
234 uint16_t *groups = NULL;
235 size_t groups_len;
236 CBS grouplist;
237 int i, j;
238 int ret = 0;
239
240 if (!CBS_get_u16_length_prefixed(cbs, &grouplist))
241 goto err;
242
243 groups_len = CBS_len(&grouplist);
244 if (groups_len == 0 || groups_len % 2 != 0)
245 goto err;
246 groups_len /= 2;
247
248 if (groups_len > TLSEXT_MAX_SUPPORTED_GROUPS)
249 goto err;
250
251 if (s->hit)
252 goto done;
253
254 if (s->s3->hs.tls13.hrr) {
255 if (s->session->tlsext_supportedgroups == NULL) {
256 *alert = SSL_AD_HANDSHAKE_FAILURE;
257 return 0;
258 }
259
260 /*
261 * The ClientHello extension hashing ensures that the client
262 * did not change its list of supported groups.
263 */
264
265 goto done;
266 }
267
268 if (s->session->tlsext_supportedgroups != NULL)
269 goto err; /* XXX internal error? */
270
271 if ((groups = reallocarray(NULL, groups_len, sizeof(uint16_t))) == NULL) {
272 *alert = SSL_AD_INTERNAL_ERROR;
273 goto err;
274 }
275
276 for (i = 0; i < groups_len; i++) {
277 if (!CBS_get_u16(&grouplist, &groups[i]))
278 goto err;
279 /*
280 * Do not allow duplicate groups to be sent. This is not
281 * currently specified in RFC 8446 or earlier, but there is no
282 * legitimate justification for this to occur in TLS 1.2 or TLS
283 * 1.3.
284 */
285 for (j = 0; j < i; j++) {
286 if (groups[i] == groups[j]) {
287 *alert = SSL_AD_ILLEGAL_PARAMETER;
288 goto err;
289 }
290 }
291 }
292
293 if (CBS_len(&grouplist) != 0)
294 goto err;
295
296 s->session->tlsext_supportedgroups = groups;
297 s->session->tlsext_supportedgroups_length = groups_len;
298 groups = NULL;
299
300
301 done:
302 ret = 1;
303
304 err:
305 free(groups);
306
307 return ret;
308}
309
310/* This extension is never used by the server. */
311static int
312tlsext_supportedgroups_server_needs(SSL *s, uint16_t msg_type)
313{
314 return 0;
315}
316
317static int
318tlsext_supportedgroups_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
319{
320 return 0;
321}
322
323static int
324tlsext_supportedgroups_client_process(SSL *s, uint16_t msg_type, CBS *cbs,
325 int *alert)
326{
327 /*
328 * This extension is only allowed in TLSv1.3 encrypted extensions.
329 * It is not permitted in a ServerHello in any version of TLS.
330 */
331 if (msg_type != SSL_TLSEXT_MSG_EE)
332 return 0;
333
334 /*
335 * RFC 8446, section 4.2.7: TLSv1.3 servers can send this extension but
336 * clients must not act on it during the handshake. This allows servers
337 * to advertise their preferences for subsequent handshakes. We ignore
338 * this complication.
339 */
340 if (!CBS_skip(cbs, CBS_len(cbs))) {
341 *alert = SSL_AD_INTERNAL_ERROR;
342 return 0;
343 }
344
345 return 1;
346}
347
348/*
349 * Supported Point Formats Extension - RFC 4492 section 5.1.2
350 */
351static int
352tlsext_ecpf_build(SSL *s, uint16_t msg_type, CBB *cbb)
353{
354 CBB ecpf;
355 size_t formats_len;
356 const uint8_t *formats;
357
358 tls1_get_formatlist(s, 0, &formats, &formats_len);
359
360 if (formats_len == 0) {
361 SSLerror(s, ERR_R_INTERNAL_ERROR);
362 return 0;
363 }
364
365 if (!CBB_add_u8_length_prefixed(cbb, &ecpf))
366 return 0;
367 if (!CBB_add_bytes(&ecpf, formats, formats_len))
368 return 0;
369 if (!CBB_flush(cbb))
370 return 0;
371
372 return 1;
373}
374
375static int
376tlsext_ecpf_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
377{
378 CBS ecpf;
379
380 if (!CBS_get_u8_length_prefixed(cbs, &ecpf))
381 return 0;
382 if (CBS_len(&ecpf) == 0)
383 return 0;
384
385 /* Must contain uncompressed (0) - RFC 8422, section 5.1.2. */
386 if (!CBS_contains_zero_byte(&ecpf)) {
387 SSLerror(s, SSL_R_TLS_INVALID_ECPOINTFORMAT_LIST);
388 *alert = SSL_AD_ILLEGAL_PARAMETER;
389 return 0;
390 }
391
392 if (!s->hit) {
393 if (!CBS_stow(&ecpf, &(s->session->tlsext_ecpointformatlist),
394 &(s->session->tlsext_ecpointformatlist_length))) {
395 *alert = SSL_AD_INTERNAL_ERROR;
396 return 0;
397 }
398 }
399
400 return 1;
401}
402
403static int
404tlsext_ecpf_client_needs(SSL *s, uint16_t msg_type)
405{
406 return ssl_has_ecc_ciphers(s);
407}
408
409static int
410tlsext_ecpf_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
411{
412 return tlsext_ecpf_build(s, msg_type, cbb);
413}
414
415static int
416tlsext_ecpf_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
417{
418 return tlsext_ecpf_process(s, msg_type, cbs, alert);
419}
420
421static int
422tlsext_ecpf_server_needs(SSL *s, uint16_t msg_type)
423{
424 return ssl_using_ecc_cipher(s);
425}
426
427static int
428tlsext_ecpf_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
429{
430 return tlsext_ecpf_build(s, msg_type, cbb);
431}
432
433static int
434tlsext_ecpf_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
435{
436 return tlsext_ecpf_process(s, msg_type, cbs, alert);
437}
438
439/*
440 * Renegotiation Indication - RFC 5746.
441 */
442static int
443tlsext_ri_client_needs(SSL *s, uint16_t msg_type)
444{
445 return (s->renegotiate);
446}
447
448static int
449tlsext_ri_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
450{
451 CBB reneg;
452
453 if (!CBB_add_u8_length_prefixed(cbb, &reneg))
454 return 0;
455 if (!CBB_add_bytes(&reneg, s->s3->previous_client_finished,
456 s->s3->previous_client_finished_len))
457 return 0;
458 if (!CBB_flush(cbb))
459 return 0;
460
461 return 1;
462}
463
464static int
465tlsext_ri_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
466{
467 CBS reneg;
468
469 if (!CBS_get_u8_length_prefixed(cbs, &reneg)) {
470 SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
471 return 0;
472 }
473
474 if (!CBS_mem_equal(&reneg, s->s3->previous_client_finished,
475 s->s3->previous_client_finished_len)) {
476 SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
477 *alert = SSL_AD_HANDSHAKE_FAILURE;
478 return 0;
479 }
480
481 s->s3->renegotiate_seen = 1;
482 s->s3->send_connection_binding = 1;
483
484 return 1;
485}
486
487static int
488tlsext_ri_server_needs(SSL *s, uint16_t msg_type)
489{
490 return (s->s3->hs.negotiated_tls_version < TLS1_3_VERSION &&
491 s->s3->send_connection_binding);
492}
493
494static int
495tlsext_ri_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
496{
497 CBB reneg;
498
499 if (!CBB_add_u8_length_prefixed(cbb, &reneg))
500 return 0;
501 if (!CBB_add_bytes(&reneg, s->s3->previous_client_finished,
502 s->s3->previous_client_finished_len))
503 return 0;
504 if (!CBB_add_bytes(&reneg, s->s3->previous_server_finished,
505 s->s3->previous_server_finished_len))
506 return 0;
507 if (!CBB_flush(cbb))
508 return 0;
509
510 return 1;
511}
512
513static int
514tlsext_ri_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
515{
516 CBS reneg, prev_client, prev_server;
517
518 /*
519 * Ensure that the previous client and server values are both not
520 * present, or that they are both present.
521 */
522 if ((s->s3->previous_client_finished_len == 0 &&
523 s->s3->previous_server_finished_len != 0) ||
524 (s->s3->previous_client_finished_len != 0 &&
525 s->s3->previous_server_finished_len == 0)) {
526 *alert = SSL_AD_INTERNAL_ERROR;
527 return 0;
528 }
529
530 if (!CBS_get_u8_length_prefixed(cbs, &reneg)) {
531 SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
532 return 0;
533 }
534 if (!CBS_get_bytes(&reneg, &prev_client,
535 s->s3->previous_client_finished_len)) {
536 SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
537 return 0;
538 }
539 if (!CBS_get_bytes(&reneg, &prev_server,
540 s->s3->previous_server_finished_len)) {
541 SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
542 return 0;
543 }
544 if (CBS_len(&reneg) != 0) {
545 SSLerror(s, SSL_R_RENEGOTIATION_ENCODING_ERR);
546 return 0;
547 }
548
549 if (!CBS_mem_equal(&prev_client, s->s3->previous_client_finished,
550 s->s3->previous_client_finished_len)) {
551 SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
552 *alert = SSL_AD_HANDSHAKE_FAILURE;
553 return 0;
554 }
555 if (!CBS_mem_equal(&prev_server, s->s3->previous_server_finished,
556 s->s3->previous_server_finished_len)) {
557 SSLerror(s, SSL_R_RENEGOTIATION_MISMATCH);
558 *alert = SSL_AD_HANDSHAKE_FAILURE;
559 return 0;
560 }
561
562 s->s3->renegotiate_seen = 1;
563 s->s3->send_connection_binding = 1;
564
565 return 1;
566}
567
568/*
569 * Signature Algorithms - RFC 5246 section 7.4.1.4.1.
570 */
571static int
572tlsext_sigalgs_client_needs(SSL *s, uint16_t msg_type)
573{
574 return (s->s3->hs.our_max_tls_version >= TLS1_2_VERSION);
575}
576
577static int
578tlsext_sigalgs_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
579{
580 uint16_t tls_version = s->s3->hs.negotiated_tls_version;
581 CBB sigalgs;
582
583 if (msg_type == SSL_TLSEXT_MSG_CH)
584 tls_version = s->s3->hs.our_min_tls_version;
585
586 if (!CBB_add_u16_length_prefixed(cbb, &sigalgs))
587 return 0;
588 if (!ssl_sigalgs_build(tls_version, &sigalgs, SSL_get_security_level(s)))
589 return 0;
590 if (!CBB_flush(cbb))
591 return 0;
592
593 return 1;
594}
595
596static int
597tlsext_sigalgs_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
598{
599 CBS sigalgs;
600
601 if (!CBS_get_u16_length_prefixed(cbs, &sigalgs))
602 return 0;
603 if (CBS_len(&sigalgs) % 2 != 0 || CBS_len(&sigalgs) > 64)
604 return 0;
605 if (!CBS_stow(&sigalgs, &s->s3->hs.sigalgs, &s->s3->hs.sigalgs_len))
606 return 0;
607
608 return 1;
609}
610
611static int
612tlsext_sigalgs_server_needs(SSL *s, uint16_t msg_type)
613{
614 return (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION);
615}
616
617static int
618tlsext_sigalgs_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
619{
620 CBB sigalgs;
621
622 if (!CBB_add_u16_length_prefixed(cbb, &sigalgs))
623 return 0;
624 if (!ssl_sigalgs_build(s->s3->hs.negotiated_tls_version, &sigalgs,
625 SSL_get_security_level(s)))
626 return 0;
627 if (!CBB_flush(cbb))
628 return 0;
629
630 return 1;
631}
632
633static int
634tlsext_sigalgs_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
635{
636 CBS sigalgs;
637
638 if (ssl_effective_tls_version(s) < TLS1_3_VERSION)
639 return 0;
640
641 if (!CBS_get_u16_length_prefixed(cbs, &sigalgs))
642 return 0;
643 if (CBS_len(&sigalgs) % 2 != 0 || CBS_len(&sigalgs) > 64)
644 return 0;
645 if (!CBS_stow(&sigalgs, &s->s3->hs.sigalgs, &s->s3->hs.sigalgs_len))
646 return 0;
647
648 return 1;
649}
650
651/*
652 * Server Name Indication - RFC 6066, section 3.
653 */
654static int
655tlsext_sni_client_needs(SSL *s, uint16_t msg_type)
656{
657 return (s->tlsext_hostname != NULL);
658}
659
660static int
661tlsext_sni_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
662{
663 CBB server_name_list, host_name;
664
665 if (!CBB_add_u16_length_prefixed(cbb, &server_name_list))
666 return 0;
667 if (!CBB_add_u8(&server_name_list, TLSEXT_NAMETYPE_host_name))
668 return 0;
669 if (!CBB_add_u16_length_prefixed(&server_name_list, &host_name))
670 return 0;
671 if (!CBB_add_bytes(&host_name, (const uint8_t *)s->tlsext_hostname,
672 strlen(s->tlsext_hostname)))
673 return 0;
674 if (!CBB_flush(cbb))
675 return 0;
676
677 return 1;
678}
679
680static int
681tlsext_sni_is_ip_literal(CBS *cbs, int *is_ip)
682{
683 union {
684 struct in_addr ip4;
685 struct in6_addr ip6;
686 } addrbuf;
687 char *hostname = NULL;
688
689 *is_ip = 0;
690
691 if (!CBS_strdup(cbs, &hostname))
692 return 0;
693
694 if (inet_pton(AF_INET, hostname, &addrbuf) == 1 ||
695 inet_pton(AF_INET6, hostname, &addrbuf) == 1)
696 *is_ip = 1;
697
698 free(hostname);
699
700 return 1;
701}
702
703/*
704 * Validate that the CBS contains only a hostname consisting of RFC 5890
705 * compliant A-labels (see RFC 6066 section 3). Not a complete check
706 * since we don't parse punycode to verify its validity but limits to
707 * correct structure and character set.
708 */
709int
710tlsext_sni_is_valid_hostname(CBS *cbs, int *is_ip)
711{
712 uint8_t prev, c = 0;
713 int component = 0;
714 CBS hostname;
715
716 *is_ip = 0;
717
718 CBS_dup(cbs, &hostname);
719
720 if (CBS_len(&hostname) > TLSEXT_MAXLEN_host_name)
721 return 0;
722
723 /* An IP literal is invalid as a host name (RFC 6066 section 3). */
724 if (!tlsext_sni_is_ip_literal(&hostname, is_ip))
725 return 0;
726 if (*is_ip)
727 return 0;
728
729 while (CBS_len(&hostname) > 0) {
730 prev = c;
731 if (!CBS_get_u8(&hostname, &c))
732 return 0;
733 /* Everything has to be ASCII, with no NUL byte. */
734 if (!isascii(c) || c == '\0')
735 return 0;
736 /* It must be alphanumeric, a '-', or a '.' */
737 if (!isalnum(c) && c != '-' && c != '.')
738 return 0;
739 /* '-' and '.' must not start a component or be at the end. */
740 if (component == 0 || CBS_len(&hostname) == 0) {
741 if (c == '-' || c == '.')
742 return 0;
743 }
744 if (c == '.') {
745 /* Components can not end with a dash. */
746 if (prev == '-')
747 return 0;
748 /* Start new component */
749 component = 0;
750 continue;
751 }
752 /* Components must be 63 chars or less. */
753 if (++component > 63)
754 return 0;
755 }
756
757 return 1;
758}
759
760static int
761tlsext_sni_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
762{
763 CBS server_name_list, host_name;
764 uint8_t name_type;
765 int is_ip;
766
767 if (!CBS_get_u16_length_prefixed(cbs, &server_name_list))
768 goto err;
769
770 if (!CBS_get_u8(&server_name_list, &name_type))
771 goto err;
772
773 /*
774 * RFC 6066 section 3, only one type (host_name) is specified.
775 * We do not tolerate unknown types, neither does BoringSSL.
776 * other implementations appear more tolerant.
777 */
778 if (name_type != TLSEXT_NAMETYPE_host_name) {
779 *alert = SSL_AD_ILLEGAL_PARAMETER;
780 goto err;
781 }
782
783 /*
784 * RFC 6066 section 3 specifies a host name must be at least 1 byte
785 * so 0 length is a decode error.
786 */
787 if (!CBS_get_u16_length_prefixed(&server_name_list, &host_name))
788 goto err;
789 if (CBS_len(&host_name) < 1)
790 goto err;
791
792 if (!tlsext_sni_is_valid_hostname(&host_name, &is_ip)) {
793 /*
794 * Various pieces of software have been known to set the SNI
795 * host name to an IP address, even though that violates the
796 * RFC. If this is the case, pretend the SNI extension does
797 * not exist.
798 */
799 if (is_ip)
800 goto done;
801
802 *alert = SSL_AD_ILLEGAL_PARAMETER;
803 goto err;
804 }
805
806 if (s->hit || s->s3->hs.tls13.hrr) {
807 if (s->session->tlsext_hostname == NULL) {
808 *alert = SSL_AD_UNRECOGNIZED_NAME;
809 goto err;
810 }
811 if (!CBS_mem_equal(&host_name, s->session->tlsext_hostname,
812 strlen(s->session->tlsext_hostname))) {
813 *alert = SSL_AD_UNRECOGNIZED_NAME;
814 goto err;
815 }
816 } else {
817 if (s->session->tlsext_hostname != NULL)
818 goto err;
819 if (!CBS_strdup(&host_name, &s->session->tlsext_hostname)) {
820 *alert = SSL_AD_INTERNAL_ERROR;
821 goto err;
822 }
823 }
824
825 done:
826 /*
827 * RFC 6066 section 3 forbids multiple host names with the same type,
828 * therefore we allow only one entry.
829 */
830 if (CBS_len(&server_name_list) != 0) {
831 *alert = SSL_AD_ILLEGAL_PARAMETER;
832 goto err;
833 }
834
835 return 1;
836
837 err:
838 return 0;
839}
840
841static int
842tlsext_sni_server_needs(SSL *s, uint16_t msg_type)
843{
844 if (s->hit)
845 return 0;
846
847 return (s->session->tlsext_hostname != NULL);
848}
849
850static int
851tlsext_sni_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
852{
853 return 1;
854}
855
856static int
857tlsext_sni_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
858{
859 if (s->tlsext_hostname == NULL || CBS_len(cbs) != 0) {
860 *alert = SSL_AD_UNRECOGNIZED_NAME;
861 return 0;
862 }
863
864 if (s->hit) {
865 if (s->session->tlsext_hostname == NULL) {
866 *alert = SSL_AD_UNRECOGNIZED_NAME;
867 return 0;
868 }
869 if (strcmp(s->tlsext_hostname,
870 s->session->tlsext_hostname) != 0) {
871 *alert = SSL_AD_UNRECOGNIZED_NAME;
872 return 0;
873 }
874 } else {
875 if (s->session->tlsext_hostname != NULL)
876 return 0;
877 if ((s->session->tlsext_hostname =
878 strdup(s->tlsext_hostname)) == NULL) {
879 *alert = SSL_AD_INTERNAL_ERROR;
880 return 0;
881 }
882 }
883
884 return 1;
885}
886
887/*
888 * Certificate Status Request - RFC 6066 section 8.
889 */
890
891static int
892tlsext_ocsp_client_needs(SSL *s, uint16_t msg_type)
893{
894 if (msg_type != SSL_TLSEXT_MSG_CH)
895 return 0;
896
897 return (s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp);
898}
899
900static int
901tlsext_ocsp_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
902{
903 CBB respid_list, respid, exts;
904 unsigned char *ext_data;
905 size_t ext_len;
906 int i;
907
908 if (!CBB_add_u8(cbb, TLSEXT_STATUSTYPE_ocsp))
909 return 0;
910 if (!CBB_add_u16_length_prefixed(cbb, &respid_list))
911 return 0;
912 for (i = 0; i < sk_OCSP_RESPID_num(s->tlsext_ocsp_ids); i++) {
913 unsigned char *respid_data;
914 OCSP_RESPID *id;
915 size_t id_len;
916
917 if ((id = sk_OCSP_RESPID_value(s->tlsext_ocsp_ids,
918 i)) == NULL)
919 return 0;
920 if ((id_len = i2d_OCSP_RESPID(id, NULL)) == -1)
921 return 0;
922 if (!CBB_add_u16_length_prefixed(&respid_list, &respid))
923 return 0;
924 if (!CBB_add_space(&respid, &respid_data, id_len))
925 return 0;
926 if ((i2d_OCSP_RESPID(id, &respid_data)) != id_len)
927 return 0;
928 }
929 if (!CBB_add_u16_length_prefixed(cbb, &exts))
930 return 0;
931 if ((ext_len = i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts,
932 NULL)) == -1)
933 return 0;
934 if (!CBB_add_space(&exts, &ext_data, ext_len))
935 return 0;
936 if ((i2d_X509_EXTENSIONS(s->tlsext_ocsp_exts, &ext_data) !=
937 ext_len))
938 return 0;
939 if (!CBB_flush(cbb))
940 return 0;
941 return 1;
942}
943
944static int
945tlsext_ocsp_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
946{
947 int alert_desc = SSL_AD_DECODE_ERROR;
948 CBS respid_list, respid, exts;
949 const unsigned char *p;
950 uint8_t status_type;
951 int ret = 0;
952
953 if (msg_type != SSL_TLSEXT_MSG_CH)
954 goto err;
955
956 if (!CBS_get_u8(cbs, &status_type))
957 goto err;
958 if (status_type != TLSEXT_STATUSTYPE_ocsp) {
959 /* ignore unknown status types */
960 s->tlsext_status_type = -1;
961
962 if (!CBS_skip(cbs, CBS_len(cbs))) {
963 *alert = SSL_AD_INTERNAL_ERROR;
964 return 0;
965 }
966 return 1;
967 }
968 s->tlsext_status_type = status_type;
969 if (!CBS_get_u16_length_prefixed(cbs, &respid_list))
970 goto err;
971
972 /* XXX */
973 sk_OCSP_RESPID_pop_free(s->tlsext_ocsp_ids, OCSP_RESPID_free);
974 s->tlsext_ocsp_ids = NULL;
975 if (CBS_len(&respid_list) > 0) {
976 s->tlsext_ocsp_ids = sk_OCSP_RESPID_new_null();
977 if (s->tlsext_ocsp_ids == NULL) {
978 alert_desc = SSL_AD_INTERNAL_ERROR;
979 goto err;
980 }
981 }
982
983 while (CBS_len(&respid_list) > 0) {
984 OCSP_RESPID *id;
985
986 if (!CBS_get_u16_length_prefixed(&respid_list, &respid))
987 goto err;
988 p = CBS_data(&respid);
989 if ((id = d2i_OCSP_RESPID(NULL, &p, CBS_len(&respid))) == NULL)
990 goto err;
991 if (!sk_OCSP_RESPID_push(s->tlsext_ocsp_ids, id)) {
992 alert_desc = SSL_AD_INTERNAL_ERROR;
993 OCSP_RESPID_free(id);
994 goto err;
995 }
996 }
997
998 /* Read in request_extensions */
999 if (!CBS_get_u16_length_prefixed(cbs, &exts))
1000 goto err;
1001 if (CBS_len(&exts) > 0) {
1002 sk_X509_EXTENSION_pop_free(s->tlsext_ocsp_exts,
1003 X509_EXTENSION_free);
1004 p = CBS_data(&exts);
1005 if ((s->tlsext_ocsp_exts = d2i_X509_EXTENSIONS(NULL,
1006 &p, CBS_len(&exts))) == NULL)
1007 goto err;
1008 }
1009
1010 ret = 1;
1011 err:
1012 if (ret == 0)
1013 *alert = alert_desc;
1014 return ret;
1015}
1016
1017static int
1018tlsext_ocsp_server_needs(SSL *s, uint16_t msg_type)
1019{
1020 if (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION &&
1021 s->tlsext_status_type == TLSEXT_STATUSTYPE_ocsp &&
1022 s->ctx->tlsext_status_cb != NULL) {
1023 s->tlsext_status_expected = 0;
1024 if (s->ctx->tlsext_status_cb(s,
1025 s->ctx->tlsext_status_arg) == SSL_TLSEXT_ERR_OK &&
1026 s->tlsext_ocsp_resp_len > 0)
1027 s->tlsext_status_expected = 1;
1028 }
1029 return s->tlsext_status_expected;
1030}
1031
1032static int
1033tlsext_ocsp_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1034{
1035 CBB ocsp_response;
1036
1037 if (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION) {
1038 if (!CBB_add_u8(cbb, TLSEXT_STATUSTYPE_ocsp))
1039 return 0;
1040 if (!CBB_add_u24_length_prefixed(cbb, &ocsp_response))
1041 return 0;
1042 if (!CBB_add_bytes(&ocsp_response,
1043 s->tlsext_ocsp_resp,
1044 s->tlsext_ocsp_resp_len))
1045 return 0;
1046 if (!CBB_flush(cbb))
1047 return 0;
1048 }
1049 return 1;
1050}
1051
1052static int
1053tlsext_ocsp_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1054{
1055 uint8_t status_type;
1056 CBS response;
1057
1058 if (ssl_effective_tls_version(s) >= TLS1_3_VERSION) {
1059 if (msg_type == SSL_TLSEXT_MSG_CR) {
1060 /*
1061 * RFC 8446, 4.4.2.1 - the server may request an OCSP
1062 * response with an empty status_request.
1063 */
1064 if (CBS_len(cbs) == 0)
1065 return 1;
1066
1067 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1068 return 0;
1069 }
1070 if (!CBS_get_u8(cbs, &status_type)) {
1071 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1072 return 0;
1073 }
1074 if (status_type != TLSEXT_STATUSTYPE_ocsp) {
1075 SSLerror(s, SSL_R_UNSUPPORTED_STATUS_TYPE);
1076 return 0;
1077 }
1078 if (!CBS_get_u24_length_prefixed(cbs, &response)) {
1079 SSLerror(s, SSL_R_LENGTH_MISMATCH);
1080 return 0;
1081 }
1082 if (CBS_len(&response) > 65536) {
1083 SSLerror(s, SSL_R_DATA_LENGTH_TOO_LONG);
1084 return 0;
1085 }
1086 if (!CBS_stow(&response, &s->tlsext_ocsp_resp,
1087 &s->tlsext_ocsp_resp_len)) {
1088 *alert = SSL_AD_INTERNAL_ERROR;
1089 return 0;
1090 }
1091 } else {
1092 if (s->tlsext_status_type == -1) {
1093 *alert = SSL_AD_UNSUPPORTED_EXTENSION;
1094 return 0;
1095 }
1096 /* Set flag to expect CertificateStatus message */
1097 s->tlsext_status_expected = 1;
1098 }
1099 return 1;
1100}
1101
1102/*
1103 * SessionTicket extension - RFC 5077 section 3.2
1104 */
1105static int
1106tlsext_sessionticket_client_needs(SSL *s, uint16_t msg_type)
1107{
1108 /*
1109 * Send session ticket extension when enabled and not overridden.
1110 *
1111 * When renegotiating, send an empty session ticket to indicate support.
1112 */
1113 if ((SSL_get_options(s) & SSL_OP_NO_TICKET) != 0)
1114 return 0;
1115
1116 if (!ssl_security_tickets(s))
1117 return 0;
1118
1119 if (s->new_session)
1120 return 1;
1121
1122 if (s->tlsext_session_ticket != NULL &&
1123 s->tlsext_session_ticket->data == NULL)
1124 return 0;
1125
1126 return 1;
1127}
1128
1129static int
1130tlsext_sessionticket_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1131{
1132 /*
1133 * Signal that we support session tickets by sending an empty
1134 * extension when renegotiating or no session found.
1135 */
1136 if (s->new_session || s->session == NULL)
1137 return 1;
1138
1139 if (s->session->tlsext_tick != NULL) {
1140 /* Attempt to resume with an existing session ticket */
1141 if (!CBB_add_bytes(cbb, s->session->tlsext_tick,
1142 s->session->tlsext_ticklen))
1143 return 0;
1144
1145 } else if (s->tlsext_session_ticket != NULL) {
1146 /*
1147 * Attempt to resume with a custom provided session ticket set
1148 * by SSL_set_session_ticket_ext().
1149 */
1150 if (s->tlsext_session_ticket->length > 0) {
1151 size_t ticklen = s->tlsext_session_ticket->length;
1152
1153 if ((s->session->tlsext_tick = malloc(ticklen)) == NULL)
1154 return 0;
1155 memcpy(s->session->tlsext_tick,
1156 s->tlsext_session_ticket->data,
1157 ticklen);
1158 s->session->tlsext_ticklen = ticklen;
1159
1160 if (!CBB_add_bytes(cbb, s->session->tlsext_tick,
1161 s->session->tlsext_ticklen))
1162 return 0;
1163 }
1164 }
1165
1166 if (!CBB_flush(cbb))
1167 return 0;
1168
1169 return 1;
1170}
1171
1172static int
1173tlsext_sessionticket_server_process(SSL *s, uint16_t msg_type, CBS *cbs,
1174 int *alert)
1175{
1176 if (s->tls_session_ticket_ext_cb) {
1177 if (!s->tls_session_ticket_ext_cb(s, CBS_data(cbs),
1178 (int)CBS_len(cbs),
1179 s->tls_session_ticket_ext_cb_arg)) {
1180 *alert = SSL_AD_INTERNAL_ERROR;
1181 return 0;
1182 }
1183 }
1184
1185 /* We need to signal that this was processed fully */
1186 if (!CBS_skip(cbs, CBS_len(cbs))) {
1187 *alert = SSL_AD_INTERNAL_ERROR;
1188 return 0;
1189 }
1190
1191 return 1;
1192}
1193
1194static int
1195tlsext_sessionticket_server_needs(SSL *s, uint16_t msg_type)
1196{
1197 return (s->tlsext_ticket_expected &&
1198 !(SSL_get_options(s) & SSL_OP_NO_TICKET) &&
1199 ssl_security_tickets(s));
1200}
1201
1202static int
1203tlsext_sessionticket_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1204{
1205 /* Empty ticket */
1206 return 1;
1207}
1208
1209static int
1210tlsext_sessionticket_client_process(SSL *s, uint16_t msg_type, CBS *cbs,
1211 int *alert)
1212{
1213 if (s->tls_session_ticket_ext_cb) {
1214 if (!s->tls_session_ticket_ext_cb(s, CBS_data(cbs),
1215 (int)CBS_len(cbs),
1216 s->tls_session_ticket_ext_cb_arg)) {
1217 *alert = SSL_AD_INTERNAL_ERROR;
1218 return 0;
1219 }
1220 }
1221
1222 if ((SSL_get_options(s) & SSL_OP_NO_TICKET) != 0 || CBS_len(cbs) > 0) {
1223 *alert = SSL_AD_UNSUPPORTED_EXTENSION;
1224 return 0;
1225 }
1226
1227 s->tlsext_ticket_expected = 1;
1228
1229 return 1;
1230}
1231
1232/*
1233 * DTLS extension for SRTP key establishment - RFC 5764
1234 */
1235
1236#ifndef OPENSSL_NO_SRTP
1237
1238static int
1239tlsext_srtp_client_needs(SSL *s, uint16_t msg_type)
1240{
1241 return SSL_is_dtls(s) && SSL_get_srtp_profiles(s) != NULL;
1242}
1243
1244static int
1245tlsext_srtp_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1246{
1247 CBB profiles, mki;
1248 int ct, i;
1249 STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = NULL;
1250 const SRTP_PROTECTION_PROFILE *prof;
1251
1252 if ((clnt = SSL_get_srtp_profiles(s)) == NULL) {
1253 SSLerror(s, SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST);
1254 return 0;
1255 }
1256
1257 if ((ct = sk_SRTP_PROTECTION_PROFILE_num(clnt)) < 1) {
1258 SSLerror(s, SSL_R_EMPTY_SRTP_PROTECTION_PROFILE_LIST);
1259 return 0;
1260 }
1261
1262 if (!CBB_add_u16_length_prefixed(cbb, &profiles))
1263 return 0;
1264
1265 for (i = 0; i < ct; i++) {
1266 if ((prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i)) == NULL)
1267 return 0;
1268 if (!CBB_add_u16(&profiles, prof->id))
1269 return 0;
1270 }
1271
1272 if (!CBB_add_u8_length_prefixed(cbb, &mki))
1273 return 0;
1274
1275 if (!CBB_flush(cbb))
1276 return 0;
1277
1278 return 1;
1279}
1280
1281static int
1282tlsext_srtp_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1283{
1284 const SRTP_PROTECTION_PROFILE *cprof, *sprof;
1285 STACK_OF(SRTP_PROTECTION_PROFILE) *clnt = NULL, *srvr;
1286 int i, j;
1287 int ret;
1288 uint16_t id;
1289 CBS profiles, mki;
1290
1291 ret = 0;
1292
1293 if (!CBS_get_u16_length_prefixed(cbs, &profiles))
1294 goto err;
1295 if (CBS_len(&profiles) == 0 || CBS_len(&profiles) % 2 != 0)
1296 goto err;
1297
1298 if ((clnt = sk_SRTP_PROTECTION_PROFILE_new_null()) == NULL)
1299 goto err;
1300
1301 while (CBS_len(&profiles) > 0) {
1302 if (!CBS_get_u16(&profiles, &id))
1303 goto err;
1304
1305 if (!srtp_find_profile_by_num(id, &cprof)) {
1306 if (!sk_SRTP_PROTECTION_PROFILE_push(clnt, cprof))
1307 goto err;
1308 }
1309 }
1310
1311 if (!CBS_get_u8_length_prefixed(cbs, &mki) || CBS_len(&mki) != 0) {
1312 SSLerror(s, SSL_R_BAD_SRTP_MKI_VALUE);
1313 goto done;
1314 }
1315
1316 /*
1317 * Per RFC 5764 section 4.1.1
1318 *
1319 * Find the server preferred profile using the client's list.
1320 *
1321 * The server MUST send a profile if it sends the use_srtp
1322 * extension. If one is not found, it should fall back to the
1323 * negotiated DTLS cipher suite or return a DTLS alert.
1324 */
1325 if ((srvr = SSL_get_srtp_profiles(s)) == NULL)
1326 goto err;
1327 for (i = 0; i < sk_SRTP_PROTECTION_PROFILE_num(srvr); i++) {
1328 if ((sprof = sk_SRTP_PROTECTION_PROFILE_value(srvr, i)) == NULL)
1329 goto err;
1330
1331 for (j = 0; j < sk_SRTP_PROTECTION_PROFILE_num(clnt); j++) {
1332 if ((cprof = sk_SRTP_PROTECTION_PROFILE_value(clnt, j))
1333 == NULL)
1334 goto err;
1335
1336 if (cprof->id == sprof->id) {
1337 s->srtp_profile = sprof;
1338 ret = 1;
1339 goto done;
1340 }
1341 }
1342 }
1343
1344 /* If we didn't find anything, fall back to the negotiated */
1345 ret = 1;
1346 goto done;
1347
1348 err:
1349 SSLerror(s, SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
1350
1351 done:
1352 sk_SRTP_PROTECTION_PROFILE_free(clnt);
1353 return ret;
1354}
1355
1356static int
1357tlsext_srtp_server_needs(SSL *s, uint16_t msg_type)
1358{
1359 return SSL_is_dtls(s) && SSL_get_selected_srtp_profile(s) != NULL;
1360}
1361
1362static int
1363tlsext_srtp_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1364{
1365 SRTP_PROTECTION_PROFILE *profile;
1366 CBB srtp, mki;
1367
1368 if (!CBB_add_u16_length_prefixed(cbb, &srtp))
1369 return 0;
1370
1371 if ((profile = SSL_get_selected_srtp_profile(s)) == NULL)
1372 return 0;
1373
1374 if (!CBB_add_u16(&srtp, profile->id))
1375 return 0;
1376
1377 if (!CBB_add_u8_length_prefixed(cbb, &mki))
1378 return 0;
1379
1380 if (!CBB_flush(cbb))
1381 return 0;
1382
1383 return 1;
1384}
1385
1386static int
1387tlsext_srtp_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1388{
1389 STACK_OF(SRTP_PROTECTION_PROFILE) *clnt;
1390 const SRTP_PROTECTION_PROFILE *prof;
1391 int i;
1392 uint16_t id;
1393 CBS profile_ids, mki;
1394
1395 if (!CBS_get_u16_length_prefixed(cbs, &profile_ids)) {
1396 SSLerror(s, SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
1397 return 0;
1398 }
1399
1400 if (!CBS_get_u16(&profile_ids, &id) || CBS_len(&profile_ids) != 0) {
1401 SSLerror(s, SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
1402 return 0;
1403 }
1404
1405 if (!CBS_get_u8_length_prefixed(cbs, &mki) || CBS_len(&mki) != 0) {
1406 SSLerror(s, SSL_R_BAD_SRTP_MKI_VALUE);
1407 *alert = SSL_AD_ILLEGAL_PARAMETER;
1408 return 0;
1409 }
1410
1411 if ((clnt = SSL_get_srtp_profiles(s)) == NULL) {
1412 SSLerror(s, SSL_R_NO_SRTP_PROFILES);
1413 return 0;
1414 }
1415
1416 for (i = 0; i < sk_SRTP_PROTECTION_PROFILE_num(clnt); i++) {
1417 if ((prof = sk_SRTP_PROTECTION_PROFILE_value(clnt, i))
1418 == NULL) {
1419 SSLerror(s, SSL_R_NO_SRTP_PROFILES);
1420 return 0;
1421 }
1422
1423 if (prof->id == id) {
1424 s->srtp_profile = prof;
1425 return 1;
1426 }
1427 }
1428
1429 SSLerror(s, SSL_R_BAD_SRTP_PROTECTION_PROFILE_LIST);
1430
1431 return 0;
1432}
1433
1434#endif /* OPENSSL_NO_SRTP */
1435
1436/*
1437 * TLSv1.3 Key Share - RFC 8446 section 4.2.8.
1438 */
1439static int
1440tlsext_keyshare_client_needs(SSL *s, uint16_t msg_type)
1441{
1442 return (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION);
1443}
1444
1445static int
1446tlsext_keyshare_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1447{
1448 CBB client_shares, key_exchange;
1449
1450 if (!CBB_add_u16_length_prefixed(cbb, &client_shares))
1451 return 0;
1452
1453 if (!CBB_add_u16(&client_shares,
1454 tls_key_share_group(s->s3->hs.key_share)))
1455 return 0;
1456 if (!CBB_add_u16_length_prefixed(&client_shares, &key_exchange))
1457 return 0;
1458 if (!tls_key_share_public(s->s3->hs.key_share, &key_exchange))
1459 return 0;
1460
1461 if (!CBB_flush(cbb))
1462 return 0;
1463
1464 return 1;
1465}
1466
1467static int
1468tlsext_keyshare_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1469{
1470 const uint16_t *client_groups = NULL, *server_groups = NULL;
1471 size_t client_groups_len = 0, server_groups_len = 0;
1472 size_t i, j, client_groups_index;
1473 int preferred_group_found = 0;
1474 int decode_error;
1475 uint16_t client_preferred_group = 0;
1476 uint16_t group;
1477 CBS client_shares, key_exchange;
1478
1479 /*
1480 * RFC 8446 section 4.2.8:
1481 *
1482 * Each KeyShareEntry value MUST correspond to a group offered in the
1483 * "supported_groups" extension and MUST appear in the same order.
1484 * However, the values MAY be a non-contiguous subset of the
1485 * "supported_groups".
1486 */
1487
1488 if (!tlsext_extension_seen(s, TLSEXT_TYPE_supported_groups)) {
1489 *alert = SSL_AD_ILLEGAL_PARAMETER;
1490 return 0;
1491 }
1492 if (!tlsext_extension_processed(s, TLSEXT_TYPE_supported_groups)) {
1493 *alert = SSL_AD_INTERNAL_ERROR;
1494 return 0;
1495 }
1496
1497 if (s->s3->hs.tls13.hrr) {
1498 if (!CBS_get_u16_length_prefixed(cbs, &client_shares))
1499 return 0;
1500
1501 /* Unpack client share. */
1502 if (!CBS_get_u16(&client_shares, &group))
1503 return 0;
1504 if (!CBS_get_u16_length_prefixed(&client_shares, &key_exchange))
1505 return 0;
1506
1507 /* There should only be one share. */
1508 if (CBS_len(&client_shares) != 0)
1509 return 0;
1510
1511 if (group != s->s3->hs.tls13.server_group) {
1512 *alert = SSL_AD_ILLEGAL_PARAMETER;
1513 return 0;
1514 }
1515
1516 if (s->s3->hs.key_share != NULL) {
1517 *alert = SSL_AD_INTERNAL_ERROR;
1518 return 0;
1519 }
1520
1521 /* Decode and store the selected key share. */
1522 if ((s->s3->hs.key_share = tls_key_share_new(group)) == NULL) {
1523 *alert = SSL_AD_INTERNAL_ERROR;
1524 return 0;
1525 }
1526 if (!tls_key_share_peer_public(s->s3->hs.key_share,
1527 &key_exchange, &decode_error, NULL)) {
1528 if (!decode_error)
1529 *alert = SSL_AD_INTERNAL_ERROR;
1530 return 0;
1531 }
1532
1533 return 1;
1534 }
1535
1536 /*
1537 * XXX similar to tls1_get_supported_group, but client pref
1538 * only - consider deduping later.
1539 */
1540 /*
1541 * We are now assured of at least one client group.
1542 * Get the client and server group preference orders.
1543 */
1544 tls1_get_group_list(s, 0, &server_groups, &server_groups_len);
1545 tls1_get_group_list(s, 1, &client_groups, &client_groups_len);
1546
1547 /*
1548 * Find the group that is most preferred by the client that
1549 * we also support.
1550 */
1551 for (i = 0; i < client_groups_len && !preferred_group_found; i++) {
1552 if (!ssl_security_supported_group(s, client_groups[i]))
1553 continue;
1554 for (j = 0; j < server_groups_len; j++) {
1555 if (server_groups[j] == client_groups[i]) {
1556 client_preferred_group = client_groups[i];
1557 preferred_group_found = 1;
1558 break;
1559 }
1560 }
1561 }
1562
1563 if (!CBS_get_u16_length_prefixed(cbs, &client_shares))
1564 return 0;
1565
1566 client_groups_index = 0;
1567 while (CBS_len(&client_shares) > 0) {
1568 int client_sent_group;
1569
1570 /* Unpack client share. */
1571 if (!CBS_get_u16(&client_shares, &group))
1572 return 0;
1573 if (!CBS_get_u16_length_prefixed(&client_shares, &key_exchange))
1574 return 0;
1575
1576 /* Ignore this client share if we're using earlier than TLSv1.3 */
1577 if (s->s3->hs.our_max_tls_version < TLS1_3_VERSION)
1578 continue;
1579
1580 /*
1581 * Ensure the client share group was sent in supported groups,
1582 * and was sent in the same order as supported groups. The
1583 * supported groups has already been checked for duplicates.
1584 */
1585 client_sent_group = 0;
1586 while (client_groups_index < client_groups_len) {
1587 if (group == client_groups[client_groups_index++]) {
1588 client_sent_group = 1;
1589 break;
1590 }
1591 }
1592 if (!client_sent_group) {
1593 *alert = SSL_AD_ILLEGAL_PARAMETER;
1594 return 0;
1595 }
1596
1597 /* Ignore this client share if we have already selected a key share */
1598 if (s->s3->hs.key_share != NULL)
1599 continue;
1600
1601 /*
1602 * Ignore this client share if it is not for the most client
1603 * preferred supported group. This avoids a potential downgrade
1604 * situation where the client sends a client share for something
1605 * less preferred, and we choose to to use it instead of
1606 * requesting the more preferred group.
1607 */
1608 if (!preferred_group_found || group != client_preferred_group)
1609 continue;
1610
1611 /* Decode and store the selected key share. */
1612 if ((s->s3->hs.key_share = tls_key_share_new(group)) == NULL) {
1613 *alert = SSL_AD_INTERNAL_ERROR;
1614 return 0;
1615 }
1616 if (!tls_key_share_peer_public(s->s3->hs.key_share,
1617 &key_exchange, &decode_error, NULL)) {
1618 if (!decode_error)
1619 *alert = SSL_AD_INTERNAL_ERROR;
1620 return 0;
1621 }
1622 }
1623
1624 return 1;
1625}
1626
1627static int
1628tlsext_keyshare_server_needs(SSL *s, uint16_t msg_type)
1629{
1630 return (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION &&
1631 tlsext_extension_seen(s, TLSEXT_TYPE_key_share));
1632}
1633
1634static int
1635tlsext_keyshare_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1636{
1637 CBB key_exchange;
1638
1639 /* In the case of a HRR, we only send the server selected group. */
1640 if (s->s3->hs.tls13.hrr) {
1641 if (s->s3->hs.tls13.server_group == 0)
1642 return 0;
1643 return CBB_add_u16(cbb, s->s3->hs.tls13.server_group);
1644 }
1645
1646 if (s->s3->hs.key_share == NULL)
1647 return 0;
1648
1649 if (!CBB_add_u16(cbb, tls_key_share_group(s->s3->hs.key_share)))
1650 return 0;
1651 if (!CBB_add_u16_length_prefixed(cbb, &key_exchange))
1652 return 0;
1653 if (!tls_key_share_public(s->s3->hs.key_share, &key_exchange))
1654 return 0;
1655
1656 if (!CBB_flush(cbb))
1657 return 0;
1658
1659 return 1;
1660}
1661
1662static int
1663tlsext_keyshare_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1664{
1665 CBS key_exchange;
1666 int decode_error;
1667 uint16_t group;
1668
1669 /* Unpack server share. */
1670 if (!CBS_get_u16(cbs, &group))
1671 return 0;
1672
1673 if (CBS_len(cbs) == 0) {
1674 /* HRR does not include an actual key share, only the group. */
1675 if (msg_type != SSL_TLSEXT_MSG_HRR)
1676 return 0;
1677
1678 s->s3->hs.tls13.server_group = group;
1679 return 1;
1680 }
1681
1682 if (!CBS_get_u16_length_prefixed(cbs, &key_exchange))
1683 return 0;
1684
1685 if (s->s3->hs.key_share == NULL) {
1686 *alert = SSL_AD_INTERNAL_ERROR;
1687 return 0;
1688 }
1689 if (tls_key_share_group(s->s3->hs.key_share) != group) {
1690 *alert = SSL_AD_INTERNAL_ERROR;
1691 return 0;
1692 }
1693 if (!tls_key_share_peer_public(s->s3->hs.key_share,
1694 &key_exchange, &decode_error, NULL)) {
1695 if (!decode_error)
1696 *alert = SSL_AD_INTERNAL_ERROR;
1697 return 0;
1698 }
1699
1700 return 1;
1701}
1702
1703/*
1704 * Supported Versions - RFC 8446 section 4.2.1.
1705 */
1706static int
1707tlsext_versions_client_needs(SSL *s, uint16_t msg_type)
1708{
1709 return (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION);
1710}
1711
1712static int
1713tlsext_versions_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1714{
1715 uint16_t max, min;
1716 uint16_t version;
1717 CBB versions;
1718
1719 max = s->s3->hs.our_max_tls_version;
1720 min = s->s3->hs.our_min_tls_version;
1721
1722 if (!CBB_add_u8_length_prefixed(cbb, &versions))
1723 return 0;
1724
1725 /* XXX - fix, but contiguous for now... */
1726 for (version = max; version >= min; version--) {
1727 if (!CBB_add_u16(&versions, version))
1728 return 0;
1729 }
1730
1731 if (!CBB_flush(cbb))
1732 return 0;
1733
1734 return 1;
1735}
1736
1737static int
1738tlsext_versions_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1739{
1740 CBS versions;
1741 uint16_t version;
1742 uint16_t max, min;
1743 uint16_t matched_version = 0;
1744
1745 max = s->s3->hs.our_max_tls_version;
1746 min = s->s3->hs.our_min_tls_version;
1747
1748 if (!CBS_get_u8_length_prefixed(cbs, &versions))
1749 return 0;
1750
1751 while (CBS_len(&versions) > 0) {
1752 if (!CBS_get_u16(&versions, &version))
1753 return 0;
1754 /*
1755 * XXX What is below implements client preference, and
1756 * ignores any server preference entirely.
1757 */
1758 if (matched_version == 0 && version >= min && version <= max)
1759 matched_version = version;
1760 }
1761
1762 if (matched_version > 0) {
1763 /* XXX - this should be stored for later processing. */
1764 s->version = matched_version;
1765 return 1;
1766 }
1767
1768 *alert = SSL_AD_PROTOCOL_VERSION;
1769 return 0;
1770}
1771
1772static int
1773tlsext_versions_server_needs(SSL *s, uint16_t msg_type)
1774{
1775 return (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION);
1776}
1777
1778static int
1779tlsext_versions_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1780{
1781 return CBB_add_u16(cbb, TLS1_3_VERSION);
1782}
1783
1784static int
1785tlsext_versions_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1786{
1787 uint16_t selected_version;
1788
1789 if (!CBS_get_u16(cbs, &selected_version))
1790 return 0;
1791
1792 /* XXX - need to fix for DTLS 1.3 */
1793 if (selected_version < TLS1_3_VERSION) {
1794 *alert = SSL_AD_ILLEGAL_PARAMETER;
1795 return 0;
1796 }
1797
1798 /* XXX test between min and max once initialization code goes in */
1799 s->s3->hs.tls13.server_version = selected_version;
1800
1801 return 1;
1802}
1803
1804
1805/*
1806 * Cookie - RFC 8446 section 4.2.2.
1807 */
1808
1809static int
1810tlsext_cookie_client_needs(SSL *s, uint16_t msg_type)
1811{
1812 return (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION &&
1813 s->s3->hs.tls13.cookie_len > 0 && s->s3->hs.tls13.cookie != NULL);
1814}
1815
1816static int
1817tlsext_cookie_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1818{
1819 CBB cookie;
1820
1821 if (!CBB_add_u16_length_prefixed(cbb, &cookie))
1822 return 0;
1823
1824 if (!CBB_add_bytes(&cookie, s->s3->hs.tls13.cookie,
1825 s->s3->hs.tls13.cookie_len))
1826 return 0;
1827
1828 if (!CBB_flush(cbb))
1829 return 0;
1830
1831 return 1;
1832}
1833
1834static int
1835tlsext_cookie_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1836{
1837 CBS cookie;
1838
1839 if (!CBS_get_u16_length_prefixed(cbs, &cookie))
1840 return 0;
1841
1842 if (CBS_len(&cookie) != s->s3->hs.tls13.cookie_len)
1843 return 0;
1844
1845 /*
1846 * Check provided cookie value against what server previously
1847 * sent - client *MUST* send the same cookie with new CR after
1848 * a cookie is sent by the server with an HRR.
1849 */
1850 if (!CBS_mem_equal(&cookie, s->s3->hs.tls13.cookie,
1851 s->s3->hs.tls13.cookie_len)) {
1852 /* XXX special cookie mismatch alert? */
1853 *alert = SSL_AD_ILLEGAL_PARAMETER;
1854 return 0;
1855 }
1856
1857 return 1;
1858}
1859
1860static int
1861tlsext_cookie_server_needs(SSL *s, uint16_t msg_type)
1862{
1863 /*
1864 * Server needs to set cookie value in tls13 handshake
1865 * in order to send one, should only be sent with HRR.
1866 */
1867 return (s->s3->hs.our_max_tls_version >= TLS1_3_VERSION &&
1868 s->s3->hs.tls13.cookie_len > 0 && s->s3->hs.tls13.cookie != NULL);
1869}
1870
1871static int
1872tlsext_cookie_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1873{
1874 CBB cookie;
1875
1876 /* XXX deduplicate with client code */
1877
1878 if (!CBB_add_u16_length_prefixed(cbb, &cookie))
1879 return 0;
1880
1881 if (!CBB_add_bytes(&cookie, s->s3->hs.tls13.cookie,
1882 s->s3->hs.tls13.cookie_len))
1883 return 0;
1884
1885 if (!CBB_flush(cbb))
1886 return 0;
1887
1888 return 1;
1889}
1890
1891static int
1892tlsext_cookie_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
1893{
1894 CBS cookie;
1895
1896 /*
1897 * XXX This currently assumes we will not get a second
1898 * HRR from a server with a cookie to process after accepting
1899 * one from the server in the same handshake
1900 */
1901 if (s->s3->hs.tls13.cookie != NULL ||
1902 s->s3->hs.tls13.cookie_len != 0) {
1903 *alert = SSL_AD_ILLEGAL_PARAMETER;
1904 return 0;
1905 }
1906
1907 if (!CBS_get_u16_length_prefixed(cbs, &cookie))
1908 return 0;
1909
1910 if (!CBS_stow(&cookie, &s->s3->hs.tls13.cookie,
1911 &s->s3->hs.tls13.cookie_len))
1912 return 0;
1913
1914 return 1;
1915}
1916
1917/*
1918 * Pre-Shared Key Exchange Modes - RFC 8446, 4.2.9.
1919 */
1920
1921static int
1922tlsext_psk_kex_modes_client_needs(SSL *s, uint16_t msg_type)
1923{
1924 return (s->s3->hs.tls13.use_psk_dhe_ke &&
1925 s->s3->hs.our_max_tls_version >= TLS1_3_VERSION);
1926}
1927
1928static int
1929tlsext_psk_kex_modes_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1930{
1931 CBB ke_modes;
1932
1933 if (!CBB_add_u8_length_prefixed(cbb, &ke_modes))
1934 return 0;
1935
1936 /* Only indicate support for PSK with DHE key establishment. */
1937 if (!CBB_add_u8(&ke_modes, TLS13_PSK_DHE_KE))
1938 return 0;
1939
1940 if (!CBB_flush(cbb))
1941 return 0;
1942
1943 return 1;
1944}
1945
1946static int
1947tlsext_psk_kex_modes_server_process(SSL *s, uint16_t msg_type, CBS *cbs,
1948 int *alert)
1949{
1950 CBS ke_modes;
1951 uint8_t ke_mode;
1952
1953 if (!CBS_get_u8_length_prefixed(cbs, &ke_modes))
1954 return 0;
1955
1956 while (CBS_len(&ke_modes) > 0) {
1957 if (!CBS_get_u8(&ke_modes, &ke_mode))
1958 return 0;
1959
1960 if (ke_mode == TLS13_PSK_DHE_KE)
1961 s->s3->hs.tls13.use_psk_dhe_ke = 1;
1962 }
1963
1964 return 1;
1965}
1966
1967static int
1968tlsext_psk_kex_modes_server_needs(SSL *s, uint16_t msg_type)
1969{
1970 /* Servers MUST NOT send this extension. */
1971 return 0;
1972}
1973
1974static int
1975tlsext_psk_kex_modes_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
1976{
1977 return 0;
1978}
1979
1980static int
1981tlsext_psk_kex_modes_client_process(SSL *s, uint16_t msg_type, CBS *cbs,
1982 int *alert)
1983{
1984 return 0;
1985}
1986
1987/*
1988 * Pre-Shared Key Extension - RFC 8446, 4.2.11
1989 */
1990
1991static int
1992tlsext_psk_client_needs(SSL *s, uint16_t msg_type)
1993{
1994 return 0;
1995}
1996
1997static int
1998tlsext_psk_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
1999{
2000 return 0;
2001}
2002
2003static int
2004tlsext_psk_client_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
2005{
2006 return CBS_skip(cbs, CBS_len(cbs));
2007}
2008
2009static int
2010tlsext_psk_server_needs(SSL *s, uint16_t msg_type)
2011{
2012 return 0;
2013}
2014
2015static int
2016tlsext_psk_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
2017{
2018 return 0;
2019}
2020
2021static int
2022tlsext_psk_server_process(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
2023{
2024 return CBS_skip(cbs, CBS_len(cbs));
2025}
2026
2027/*
2028 * QUIC transport parameters extension - RFC 9001 section 8.2.
2029 */
2030
2031static int
2032tlsext_quic_transport_parameters_client_needs(SSL *s, uint16_t msg_type)
2033{
2034 return SSL_is_quic(s) && s->quic_transport_params_len > 0;
2035}
2036
2037static int
2038tlsext_quic_transport_parameters_client_build(SSL *s, uint16_t msg_type,
2039 CBB *cbb)
2040{
2041 if (!CBB_add_bytes(cbb, s->quic_transport_params,
2042 s->quic_transport_params_len))
2043 return 0;
2044
2045 return 1;
2046}
2047
2048static int
2049tlsext_quic_transport_parameters_client_process(SSL *s, uint16_t msg_type,
2050 CBS *cbs, int *alert)
2051{
2052 if (!SSL_is_quic(s)) {
2053 *alert = SSL_AD_UNSUPPORTED_EXTENSION;
2054 return 0;
2055 }
2056
2057 if (!CBS_stow(cbs, &s->s3->peer_quic_transport_params,
2058 &s->s3->peer_quic_transport_params_len))
2059 return 0;
2060 if (!CBS_skip(cbs, s->s3->peer_quic_transport_params_len))
2061 return 0;
2062
2063 return 1;
2064}
2065
2066static int
2067tlsext_quic_transport_parameters_server_needs(SSL *s, uint16_t msg_type)
2068{
2069 return SSL_is_quic(s) && s->quic_transport_params_len > 0;
2070}
2071
2072static int
2073tlsext_quic_transport_parameters_server_build(SSL *s, uint16_t msg_type,
2074 CBB *cbb)
2075{
2076 if (!CBB_add_bytes(cbb, s->quic_transport_params,
2077 s->quic_transport_params_len))
2078 return 0;
2079
2080 return 1;
2081}
2082
2083static int
2084tlsext_quic_transport_parameters_server_process(SSL *s, uint16_t msg_type,
2085 CBS *cbs, int *alert)
2086{
2087 if (!SSL_is_quic(s)) {
2088 *alert = SSL_AD_UNSUPPORTED_EXTENSION;
2089 return 0;
2090 }
2091
2092 if (!CBS_stow(cbs, &s->s3->peer_quic_transport_params,
2093 &s->s3->peer_quic_transport_params_len))
2094 return 0;
2095 if (!CBS_skip(cbs, s->s3->peer_quic_transport_params_len))
2096 return 0;
2097
2098 return 1;
2099}
2100
2101struct tls_extension_funcs {
2102 int (*needs)(SSL *s, uint16_t msg_type);
2103 int (*build)(SSL *s, uint16_t msg_type, CBB *cbb);
2104 int (*process)(SSL *s, uint16_t msg_type, CBS *cbs, int *alert);
2105};
2106
2107struct tls_extension {
2108 uint16_t type;
2109 uint16_t messages;
2110 struct tls_extension_funcs client;
2111 struct tls_extension_funcs server;
2112};
2113
2114/*
2115 * TLS extensions (in processing order).
2116 */
2117static const struct tls_extension tls_extensions[] = {
2118 {
2119 .type = TLSEXT_TYPE_supported_versions,
2120 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH |
2121 SSL_TLSEXT_MSG_HRR,
2122 .client = {
2123 .needs = tlsext_versions_client_needs,
2124 .build = tlsext_versions_client_build,
2125 .process = tlsext_versions_client_process,
2126 },
2127 .server = {
2128 .needs = tlsext_versions_server_needs,
2129 .build = tlsext_versions_server_build,
2130 .process = tlsext_versions_server_process,
2131 },
2132 },
2133 {
2134 .type = TLSEXT_TYPE_supported_groups,
2135 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_EE,
2136 .client = {
2137 .needs = tlsext_supportedgroups_client_needs,
2138 .build = tlsext_supportedgroups_client_build,
2139 .process = tlsext_supportedgroups_client_process,
2140 },
2141 .server = {
2142 .needs = tlsext_supportedgroups_server_needs,
2143 .build = tlsext_supportedgroups_server_build,
2144 .process = tlsext_supportedgroups_server_process,
2145 },
2146 },
2147 {
2148 .type = TLSEXT_TYPE_key_share,
2149 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH |
2150 SSL_TLSEXT_MSG_HRR,
2151 .client = {
2152 .needs = tlsext_keyshare_client_needs,
2153 .build = tlsext_keyshare_client_build,
2154 .process = tlsext_keyshare_client_process,
2155 },
2156 .server = {
2157 .needs = tlsext_keyshare_server_needs,
2158 .build = tlsext_keyshare_server_build,
2159 .process = tlsext_keyshare_server_process,
2160 },
2161 },
2162 {
2163 .type = TLSEXT_TYPE_server_name,
2164 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_EE,
2165 .client = {
2166 .needs = tlsext_sni_client_needs,
2167 .build = tlsext_sni_client_build,
2168 .process = tlsext_sni_client_process,
2169 },
2170 .server = {
2171 .needs = tlsext_sni_server_needs,
2172 .build = tlsext_sni_server_build,
2173 .process = tlsext_sni_server_process,
2174 },
2175 },
2176 {
2177 .type = TLSEXT_TYPE_renegotiate,
2178 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH,
2179 .client = {
2180 .needs = tlsext_ri_client_needs,
2181 .build = tlsext_ri_client_build,
2182 .process = tlsext_ri_client_process,
2183 },
2184 .server = {
2185 .needs = tlsext_ri_server_needs,
2186 .build = tlsext_ri_server_build,
2187 .process = tlsext_ri_server_process,
2188 },
2189 },
2190 {
2191 .type = TLSEXT_TYPE_status_request,
2192 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_CR |
2193 SSL_TLSEXT_MSG_CT,
2194 .client = {
2195 .needs = tlsext_ocsp_client_needs,
2196 .build = tlsext_ocsp_client_build,
2197 .process = tlsext_ocsp_client_process,
2198 },
2199 .server = {
2200 .needs = tlsext_ocsp_server_needs,
2201 .build = tlsext_ocsp_server_build,
2202 .process = tlsext_ocsp_server_process,
2203 },
2204 },
2205 {
2206 .type = TLSEXT_TYPE_ec_point_formats,
2207 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH,
2208 .client = {
2209 .needs = tlsext_ecpf_client_needs,
2210 .build = tlsext_ecpf_client_build,
2211 .process = tlsext_ecpf_client_process,
2212 },
2213 .server = {
2214 .needs = tlsext_ecpf_server_needs,
2215 .build = tlsext_ecpf_server_build,
2216 .process = tlsext_ecpf_server_process,
2217 },
2218 },
2219 {
2220 .type = TLSEXT_TYPE_session_ticket,
2221 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH,
2222 .client = {
2223 .needs = tlsext_sessionticket_client_needs,
2224 .build = tlsext_sessionticket_client_build,
2225 .process = tlsext_sessionticket_client_process,
2226 },
2227 .server = {
2228 .needs = tlsext_sessionticket_server_needs,
2229 .build = tlsext_sessionticket_server_build,
2230 .process = tlsext_sessionticket_server_process,
2231 },
2232 },
2233 {
2234 .type = TLSEXT_TYPE_signature_algorithms,
2235 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_CR,
2236 .client = {
2237 .needs = tlsext_sigalgs_client_needs,
2238 .build = tlsext_sigalgs_client_build,
2239 .process = tlsext_sigalgs_client_process,
2240 },
2241 .server = {
2242 .needs = tlsext_sigalgs_server_needs,
2243 .build = tlsext_sigalgs_server_build,
2244 .process = tlsext_sigalgs_server_process,
2245 },
2246 },
2247 {
2248 .type = TLSEXT_TYPE_alpn,
2249 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_EE,
2250 .client = {
2251 .needs = tlsext_alpn_client_needs,
2252 .build = tlsext_alpn_client_build,
2253 .process = tlsext_alpn_client_process,
2254 },
2255 .server = {
2256 .needs = tlsext_alpn_server_needs,
2257 .build = tlsext_alpn_server_build,
2258 .process = tlsext_alpn_server_process,
2259 },
2260 },
2261 {
2262 .type = TLSEXT_TYPE_cookie,
2263 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_HRR,
2264 .client = {
2265 .needs = tlsext_cookie_client_needs,
2266 .build = tlsext_cookie_client_build,
2267 .process = tlsext_cookie_client_process,
2268 },
2269 .server = {
2270 .needs = tlsext_cookie_server_needs,
2271 .build = tlsext_cookie_server_build,
2272 .process = tlsext_cookie_server_process,
2273 },
2274 },
2275#ifndef OPENSSL_NO_SRTP
2276 {
2277 .type = TLSEXT_TYPE_use_srtp,
2278 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH /* XXX */ |
2279 SSL_TLSEXT_MSG_EE,
2280 .client = {
2281 .needs = tlsext_srtp_client_needs,
2282 .build = tlsext_srtp_client_build,
2283 .process = tlsext_srtp_client_process,
2284 },
2285 .server = {
2286 .needs = tlsext_srtp_server_needs,
2287 .build = tlsext_srtp_server_build,
2288 .process = tlsext_srtp_server_process,
2289 },
2290 },
2291#endif /* OPENSSL_NO_SRTP */
2292 {
2293 .type = TLSEXT_TYPE_quic_transport_parameters,
2294 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_EE,
2295 .client = {
2296 .needs = tlsext_quic_transport_parameters_client_needs,
2297 .build = tlsext_quic_transport_parameters_client_build,
2298 .process = tlsext_quic_transport_parameters_client_process,
2299 },
2300 .server = {
2301 .needs = tlsext_quic_transport_parameters_server_needs,
2302 .build = tlsext_quic_transport_parameters_server_build,
2303 .process = tlsext_quic_transport_parameters_server_process,
2304 },
2305 },
2306 {
2307 .type = TLSEXT_TYPE_psk_key_exchange_modes,
2308 .messages = SSL_TLSEXT_MSG_CH,
2309 .client = {
2310 .needs = tlsext_psk_kex_modes_client_needs,
2311 .build = tlsext_psk_kex_modes_client_build,
2312 .process = tlsext_psk_kex_modes_client_process,
2313 },
2314 .server = {
2315 .needs = tlsext_psk_kex_modes_server_needs,
2316 .build = tlsext_psk_kex_modes_server_build,
2317 .process = tlsext_psk_kex_modes_server_process,
2318 },
2319 },
2320 {
2321 .type = TLSEXT_TYPE_pre_shared_key,
2322 .messages = SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH,
2323 .client = {
2324 .needs = tlsext_psk_client_needs,
2325 .build = tlsext_psk_client_build,
2326 .process = tlsext_psk_client_process,
2327 },
2328 .server = {
2329 .needs = tlsext_psk_server_needs,
2330 .build = tlsext_psk_server_build,
2331 .process = tlsext_psk_server_process,
2332 },
2333 },
2334};
2335
2336#define N_TLS_EXTENSIONS (sizeof(tls_extensions) / sizeof(*tls_extensions))
2337
2338/* Ensure that extensions fit in a uint32_t bitmask. */
2339CTASSERT(N_TLS_EXTENSIONS <= (sizeof(uint32_t) * 8));
2340
2341struct tlsext_data {
2342 CBS extensions[N_TLS_EXTENSIONS];
2343};
2344
2345static struct tlsext_data *
2346tlsext_data_new(void)
2347{
2348 return calloc(1, sizeof(struct tlsext_data));
2349}
2350
2351static void
2352tlsext_data_free(struct tlsext_data *td)
2353{
2354 freezero(td, sizeof(*td));
2355}
2356
2357uint16_t
2358tls_extension_type(const struct tls_extension *extension)
2359{
2360 return extension->type;
2361}
2362
2363const struct tls_extension *
2364tls_extension_find(uint16_t type, size_t *tls_extensions_idx)
2365{
2366 size_t i;
2367
2368 for (i = 0; i < N_TLS_EXTENSIONS; i++) {
2369 if (tls_extensions[i].type == type) {
2370 if (tls_extensions_idx != NULL)
2371 *tls_extensions_idx = i;
2372 return &tls_extensions[i];
2373 }
2374 }
2375
2376 return NULL;
2377}
2378
2379int
2380tlsext_extension_seen(SSL *s, uint16_t type)
2381{
2382 size_t idx;
2383
2384 if (tls_extension_find(type, &idx) == NULL)
2385 return 0;
2386 return ((s->s3->hs.extensions_seen & (1 << idx)) != 0);
2387}
2388
2389int
2390tlsext_extension_processed(SSL *s, uint16_t type)
2391{
2392 size_t idx;
2393
2394 if (tls_extension_find(type, &idx) == NULL)
2395 return 0;
2396 return ((s->s3->hs.extensions_processed & (1 << idx)) != 0);
2397}
2398
2399const struct tls_extension_funcs *
2400tlsext_funcs(const struct tls_extension *tlsext, int is_server)
2401{
2402 if (is_server)
2403 return &tlsext->server;
2404
2405 return &tlsext->client;
2406}
2407
2408int
2409tlsext_randomize_build_order(SSL *s)
2410{
2411 const struct tls_extension *psk_ext;
2412 size_t idx, new_idx;
2413 size_t alpn_idx = 0, sni_idx = 0;
2414
2415 free(s->tlsext_build_order);
2416 s->tlsext_build_order_len = 0;
2417
2418 if ((s->tlsext_build_order = calloc(sizeof(*s->tlsext_build_order),
2419 N_TLS_EXTENSIONS)) == NULL)
2420 return 0;
2421 s->tlsext_build_order_len = N_TLS_EXTENSIONS;
2422
2423 /* RFC 8446, section 4.2 - PSK MUST be the last extension in the CH. */
2424 if ((psk_ext = tls_extension_find(TLSEXT_TYPE_pre_shared_key,
2425 NULL)) == NULL)
2426 return 0;
2427 s->tlsext_build_order[N_TLS_EXTENSIONS - 1] = psk_ext;
2428
2429 /* Fisher-Yates shuffle with PSK fixed. */
2430 for (idx = 0; idx < N_TLS_EXTENSIONS - 1; idx++) {
2431 new_idx = arc4random_uniform(idx + 1);
2432 s->tlsext_build_order[idx] = s->tlsext_build_order[new_idx];
2433 s->tlsext_build_order[new_idx] = &tls_extensions[idx];
2434 }
2435
2436 /*
2437 * XXX - Apache2 special until year 2025: ensure that SNI precedes ALPN
2438 * for clients so that virtual host setups work correctly.
2439 */
2440
2441 if (s->server)
2442 return 1;
2443
2444 for (idx = 0; idx < N_TLS_EXTENSIONS; idx++) {
2445 if (s->tlsext_build_order[idx]->type == TLSEXT_TYPE_alpn)
2446 alpn_idx = idx;
2447 if (s->tlsext_build_order[idx]->type == TLSEXT_TYPE_server_name)
2448 sni_idx = idx;
2449 }
2450 if (alpn_idx < sni_idx) {
2451 const struct tls_extension *tmp;
2452
2453 tmp = s->tlsext_build_order[alpn_idx];
2454 s->tlsext_build_order[alpn_idx] = s->tlsext_build_order[sni_idx];
2455 s->tlsext_build_order[sni_idx] = tmp;
2456 }
2457
2458 return 1;
2459}
2460
2461int
2462tlsext_linearize_build_order(SSL *s)
2463{
2464 size_t idx;
2465
2466 free(s->tlsext_build_order);
2467 s->tlsext_build_order_len = 0;
2468
2469 if ((s->tlsext_build_order = calloc(sizeof(*s->tlsext_build_order),
2470 N_TLS_EXTENSIONS)) == NULL)
2471 return 0;
2472 s->tlsext_build_order_len = N_TLS_EXTENSIONS;
2473
2474 for (idx = 0; idx < N_TLS_EXTENSIONS; idx++)
2475 s->tlsext_build_order[idx] = &tls_extensions[idx];
2476
2477 return 1;
2478}
2479
2480static int
2481tlsext_build(SSL *s, int is_server, uint16_t msg_type, CBB *cbb)
2482{
2483 const struct tls_extension_funcs *ext;
2484 const struct tls_extension *tlsext;
2485 CBB extensions, extension_data;
2486 int extensions_present = 0;
2487 uint16_t tls_version;
2488 size_t i;
2489
2490 tls_version = ssl_effective_tls_version(s);
2491
2492 if (!CBB_add_u16_length_prefixed(cbb, &extensions))
2493 return 0;
2494
2495 for (i = 0; i < N_TLS_EXTENSIONS; i++) {
2496 tlsext = s->tlsext_build_order[i];
2497 ext = tlsext_funcs(tlsext, is_server);
2498
2499 /* RFC 8446 Section 4.2 */
2500 if (tls_version >= TLS1_3_VERSION &&
2501 !(tlsext->messages & msg_type))
2502 continue;
2503
2504 if (!ext->needs(s, msg_type))
2505 continue;
2506
2507 if (!CBB_add_u16(&extensions, tlsext->type))
2508 return 0;
2509 if (!CBB_add_u16_length_prefixed(&extensions, &extension_data))
2510 return 0;
2511
2512 if (!ext->build(s, msg_type, &extension_data))
2513 return 0;
2514
2515 extensions_present = 1;
2516 }
2517
2518 if (!extensions_present &&
2519 (msg_type & (SSL_TLSEXT_MSG_CH | SSL_TLSEXT_MSG_SH)) != 0)
2520 CBB_discard_child(cbb);
2521
2522 if (!CBB_flush(cbb))
2523 return 0;
2524
2525 return 1;
2526}
2527
2528int
2529tlsext_clienthello_hash_extension(SSL *s, uint16_t type, CBS *cbs)
2530{
2531 /*
2532 * RFC 8446 4.1.2. For subsequent CH, early data will be removed,
2533 * cookie may be added, padding may be removed.
2534 */
2535 struct tls13_ctx *ctx = s->tls13;
2536
2537 if (type == TLSEXT_TYPE_early_data || type == TLSEXT_TYPE_cookie ||
2538 type == TLSEXT_TYPE_padding)
2539 return 1;
2540 if (!tls13_clienthello_hash_update_bytes(ctx, (void *)&type,
2541 sizeof(type)))
2542 return 0;
2543 /*
2544 * key_share data may be changed, and pre_shared_key data may
2545 * be changed.
2546 */
2547 if (type == TLSEXT_TYPE_pre_shared_key || type == TLSEXT_TYPE_key_share)
2548 return 1;
2549 if (!tls13_clienthello_hash_update(ctx, cbs))
2550 return 0;
2551
2552 return 1;
2553}
2554
2555static int
2556tlsext_parse(SSL *s, struct tlsext_data *td, int is_server, uint16_t msg_type,
2557 CBS *cbs, int *alert)
2558{
2559 const struct tls_extension *tlsext;
2560 CBS extensions, extension_data;
2561 uint16_t type;
2562 size_t idx;
2563 uint16_t tls_version;
2564 int alert_desc;
2565
2566 tls_version = ssl_effective_tls_version(s);
2567
2568 s->s3->hs.extensions_seen = 0;
2569
2570 /* An empty extensions block is valid. */
2571 if (CBS_len(cbs) == 0)
2572 return 1;
2573
2574 alert_desc = SSL_AD_DECODE_ERROR;
2575
2576 if (!CBS_get_u16_length_prefixed(cbs, &extensions))
2577 goto err;
2578
2579 while (CBS_len(&extensions) > 0) {
2580 if (!CBS_get_u16(&extensions, &type))
2581 goto err;
2582 if (!CBS_get_u16_length_prefixed(&extensions, &extension_data))
2583 goto err;
2584
2585 if (s->tlsext_debug_cb != NULL)
2586 s->tlsext_debug_cb(s, !is_server, type,
2587 (unsigned char *)CBS_data(&extension_data),
2588 CBS_len(&extension_data),
2589 s->tlsext_debug_arg);
2590
2591 /* Unknown extensions are ignored. */
2592 if ((tlsext = tls_extension_find(type, &idx)) == NULL)
2593 continue;
2594
2595 if (tls_version >= TLS1_3_VERSION && is_server &&
2596 msg_type == SSL_TLSEXT_MSG_CH) {
2597 if (!tlsext_clienthello_hash_extension(s, type,
2598 &extension_data))
2599 goto err;
2600 }
2601
2602 /* RFC 8446 Section 4.2 */
2603 if (tls_version >= TLS1_3_VERSION &&
2604 !(tlsext->messages & msg_type)) {
2605 alert_desc = SSL_AD_ILLEGAL_PARAMETER;
2606 goto err;
2607 }
2608
2609 /* Check for duplicate known extensions. */
2610 if ((s->s3->hs.extensions_seen & (1 << idx)) != 0)
2611 goto err;
2612 s->s3->hs.extensions_seen |= (1 << idx);
2613
2614 CBS_dup(&extension_data, &td->extensions[idx]);
2615 }
2616
2617 return 1;
2618
2619 err:
2620 *alert = alert_desc;
2621
2622 return 0;
2623}
2624
2625static int
2626tlsext_process(SSL *s, struct tlsext_data *td, int is_server, uint16_t msg_type,
2627 int *alert)
2628{
2629 const struct tls_extension_funcs *ext;
2630 const struct tls_extension *tlsext;
2631 int alert_desc;
2632 size_t idx;
2633
2634 alert_desc = SSL_AD_DECODE_ERROR;
2635
2636 s->s3->hs.extensions_processed = 0;
2637
2638 /* Run processing for present TLS extensions, in a defined order. */
2639 for (idx = 0; idx < N_TLS_EXTENSIONS; idx++) {
2640 tlsext = &tls_extensions[idx];
2641 if ((s->s3->hs.extensions_seen & (1 << idx)) == 0)
2642 continue;
2643 ext = tlsext_funcs(tlsext, is_server);
2644 if (ext->process == NULL)
2645 continue;
2646 if (!ext->process(s, msg_type, &td->extensions[idx], &alert_desc))
2647 goto err;
2648
2649 if (CBS_len(&td->extensions[idx]) != 0)
2650 goto err;
2651
2652 s->s3->hs.extensions_processed |= (1 << idx);
2653 }
2654
2655 return 1;
2656
2657 err:
2658 *alert = alert_desc;
2659
2660 return 0;
2661}
2662
2663static void
2664tlsext_server_reset_state(SSL *s)
2665{
2666 s->tlsext_status_type = -1;
2667 s->s3->renegotiate_seen = 0;
2668 free(s->s3->alpn_selected);
2669 s->s3->alpn_selected = NULL;
2670 s->s3->alpn_selected_len = 0;
2671 s->srtp_profile = NULL;
2672}
2673
2674int
2675tlsext_server_build(SSL *s, uint16_t msg_type, CBB *cbb)
2676{
2677 return tlsext_build(s, 1, msg_type, cbb);
2678}
2679
2680int
2681tlsext_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
2682{
2683 struct tlsext_data *td;
2684 int ret = 0;
2685
2686 if ((td = tlsext_data_new()) == NULL)
2687 goto err;
2688
2689 /* XXX - this should be done by the caller... */
2690 if (msg_type == SSL_TLSEXT_MSG_CH)
2691 tlsext_server_reset_state(s);
2692
2693 if (!tlsext_parse(s, td, 1, msg_type, cbs, alert))
2694 goto err;
2695 if (!tlsext_process(s, td, 1, msg_type, alert))
2696 goto err;
2697
2698 ret = 1;
2699
2700 err:
2701 tlsext_data_free(td);
2702
2703 return ret;
2704}
2705
2706static void
2707tlsext_client_reset_state(SSL *s)
2708{
2709 s->s3->renegotiate_seen = 0;
2710 free(s->s3->alpn_selected);
2711 s->s3->alpn_selected = NULL;
2712 s->s3->alpn_selected_len = 0;
2713}
2714
2715int
2716tlsext_client_build(SSL *s, uint16_t msg_type, CBB *cbb)
2717{
2718 return tlsext_build(s, 0, msg_type, cbb);
2719}
2720
2721int
2722tlsext_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert)
2723{
2724 struct tlsext_data *td;
2725 int ret = 0;
2726
2727 if ((td = tlsext_data_new()) == NULL)
2728 goto err;
2729
2730 /* XXX - this should be done by the caller... */
2731 if (msg_type == SSL_TLSEXT_MSG_SH)
2732 tlsext_client_reset_state(s);
2733
2734 if (!tlsext_parse(s, td, 0, msg_type, cbs, alert))
2735 goto err;
2736 if (!tlsext_process(s, td, 0, msg_type, alert))
2737 goto err;
2738
2739 ret = 1;
2740
2741 err:
2742 tlsext_data_free(td);
2743
2744 return ret;
2745}
diff --git a/src/lib/libssl/ssl_tlsext.h b/src/lib/libssl/ssl_tlsext.h
deleted file mode 100644
index 4fd2ec05a0..0000000000
--- a/src/lib/libssl/ssl_tlsext.h
+++ /dev/null
@@ -1,49 +0,0 @@
1/* $OpenBSD: ssl_tlsext.h,v 1.34 2024/03/26 03:44:11 beck Exp $ */
2/*
3 * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2017 Doug Hogan <doug@openbsd.org>
5 * Copyright (c) 2019 Bob Beck <beck@openbsd.org>
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef HEADER_SSL_TLSEXT_H
21#define HEADER_SSL_TLSEXT_H
22
23/* TLSv1.3 - RFC 8446 Section 4.2. */
24#define SSL_TLSEXT_MSG_CH 0x0001 /* ClientHello */
25#define SSL_TLSEXT_MSG_SH 0x0002 /* ServerHello */
26#define SSL_TLSEXT_MSG_EE 0x0004 /* EncryptedExtension */
27#define SSL_TLSEXT_MSG_CT 0x0008 /* Certificate */
28#define SSL_TLSEXT_MSG_CR 0x0010 /* CertificateRequest */
29#define SSL_TLSEXT_MSG_NST 0x0020 /* NewSessionTicket */
30#define SSL_TLSEXT_MSG_HRR 0x0040 /* HelloRetryRequest */
31
32__BEGIN_HIDDEN_DECLS
33
34int tlsext_alpn_check_format(CBS *cbs);
35int tlsext_sni_is_valid_hostname(CBS *cbs, int *is_ip);
36
37int tlsext_client_build(SSL *s, uint16_t msg_type, CBB *cbb);
38int tlsext_client_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert);
39
40int tlsext_server_build(SSL *s, uint16_t msg_type, CBB *cbb);
41int tlsext_server_parse(SSL *s, uint16_t msg_type, CBS *cbs, int *alert);
42
43int tlsext_extension_seen(SSL *s, uint16_t);
44int tlsext_extension_processed(SSL *s, uint16_t);
45int tlsext_randomize_build_order(SSL *s);
46
47__END_HIDDEN_DECLS
48
49#endif
diff --git a/src/lib/libssl/ssl_transcript.c b/src/lib/libssl/ssl_transcript.c
deleted file mode 100644
index 22cd6c3cfa..0000000000
--- a/src/lib/libssl/ssl_transcript.c
+++ /dev/null
@@ -1,197 +0,0 @@
1/* $OpenBSD: ssl_transcript.c,v 1.9 2022/11/26 16:08:56 tb Exp $ */
2/*
3 * Copyright (c) 2017 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <openssl/ssl.h>
19
20#include "ssl_local.h"
21#include "tls_internal.h"
22
23int
24tls1_transcript_hash_init(SSL *s)
25{
26 const unsigned char *data;
27 const EVP_MD *md;
28 size_t len;
29
30 tls1_transcript_hash_free(s);
31
32 if (!ssl_get_handshake_evp_md(s, &md)) {
33 SSLerrorx(ERR_R_INTERNAL_ERROR);
34 goto err;
35 }
36
37 if ((s->s3->handshake_hash = EVP_MD_CTX_new()) == NULL) {
38 SSLerror(s, ERR_R_MALLOC_FAILURE);
39 goto err;
40 }
41 if (!EVP_DigestInit_ex(s->s3->handshake_hash, md, NULL)) {
42 SSLerror(s, ERR_R_EVP_LIB);
43 goto err;
44 }
45
46 if (!tls1_transcript_data(s, &data, &len)) {
47 SSLerror(s, SSL_R_BAD_HANDSHAKE_LENGTH);
48 goto err;
49 }
50 if (!tls1_transcript_hash_update(s, data, len)) {
51 SSLerror(s, ERR_R_EVP_LIB);
52 goto err;
53 }
54
55 return 1;
56
57 err:
58 tls1_transcript_hash_free(s);
59
60 return 0;
61}
62
63int
64tls1_transcript_hash_update(SSL *s, const unsigned char *buf, size_t len)
65{
66 if (s->s3->handshake_hash == NULL)
67 return 1;
68
69 return EVP_DigestUpdate(s->s3->handshake_hash, buf, len);
70}
71
72int
73tls1_transcript_hash_value(SSL *s, unsigned char *out, size_t len,
74 size_t *outlen)
75{
76 EVP_MD_CTX *mdctx = NULL;
77 unsigned int mdlen;
78 int ret = 0;
79
80 if (s->s3->handshake_hash == NULL)
81 goto err;
82
83 if (EVP_MD_CTX_size(s->s3->handshake_hash) > len)
84 goto err;
85
86 if ((mdctx = EVP_MD_CTX_new()) == NULL) {
87 SSLerror(s, ERR_R_MALLOC_FAILURE);
88 goto err;
89 }
90 if (!EVP_MD_CTX_copy_ex(mdctx, s->s3->handshake_hash)) {
91 SSLerror(s, ERR_R_EVP_LIB);
92 goto err;
93 }
94 if (!EVP_DigestFinal_ex(mdctx, out, &mdlen)) {
95 SSLerror(s, ERR_R_EVP_LIB);
96 goto err;
97 }
98 if (outlen != NULL)
99 *outlen = mdlen;
100
101 ret = 1;
102
103 err:
104 EVP_MD_CTX_free(mdctx);
105
106 return (ret);
107}
108
109void
110tls1_transcript_hash_free(SSL *s)
111{
112 EVP_MD_CTX_free(s->s3->handshake_hash);
113 s->s3->handshake_hash = NULL;
114}
115
116int
117tls1_transcript_init(SSL *s)
118{
119 if (s->s3->handshake_transcript != NULL)
120 return 0;
121
122 if ((s->s3->handshake_transcript = tls_buffer_new(0)) == NULL)
123 return 0;
124
125 tls1_transcript_reset(s);
126
127 return 1;
128}
129
130void
131tls1_transcript_free(SSL *s)
132{
133 tls_buffer_free(s->s3->handshake_transcript);
134 s->s3->handshake_transcript = NULL;
135}
136
137void
138tls1_transcript_reset(SSL *s)
139{
140 tls_buffer_clear(s->s3->handshake_transcript);
141
142 tls1_transcript_unfreeze(s);
143}
144
145int
146tls1_transcript_append(SSL *s, const unsigned char *buf, size_t len)
147{
148 if (s->s3->handshake_transcript == NULL)
149 return 1;
150
151 if (s->s3->flags & TLS1_FLAGS_FREEZE_TRANSCRIPT)
152 return 1;
153
154 return tls_buffer_append(s->s3->handshake_transcript, buf, len);
155}
156
157int
158tls1_transcript_data(SSL *s, const unsigned char **data, size_t *len)
159{
160 CBS cbs;
161
162 if (s->s3->handshake_transcript == NULL)
163 return 0;
164
165 if (!tls_buffer_data(s->s3->handshake_transcript, &cbs))
166 return 0;
167
168 /* XXX - change to caller providing a CBS argument. */
169 *data = CBS_data(&cbs);
170 *len = CBS_len(&cbs);
171
172 return 1;
173}
174
175void
176tls1_transcript_freeze(SSL *s)
177{
178 s->s3->flags |= TLS1_FLAGS_FREEZE_TRANSCRIPT;
179}
180
181void
182tls1_transcript_unfreeze(SSL *s)
183{
184 s->s3->flags &= ~TLS1_FLAGS_FREEZE_TRANSCRIPT;
185}
186
187int
188tls1_transcript_record(SSL *s, const unsigned char *buf, size_t len)
189{
190 if (!tls1_transcript_hash_update(s, buf, len))
191 return 0;
192
193 if (!tls1_transcript_append(s, buf, len))
194 return 0;
195
196 return 1;
197}
diff --git a/src/lib/libssl/ssl_txt.c b/src/lib/libssl/ssl_txt.c
deleted file mode 100644
index 4ed76c95ab..0000000000
--- a/src/lib/libssl/ssl_txt.c
+++ /dev/null
@@ -1,202 +0,0 @@
1/* $OpenBSD: ssl_txt.c,v 1.39 2024/07/22 14:47:15 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright 2005 Nokia. All rights reserved.
60 *
61 * The portions of the attached software ("Contribution") is developed by
62 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
63 * license.
64 *
65 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
66 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
67 * support (see RFC 4279) to OpenSSL.
68 *
69 * No patent licenses or other rights except those expressly stated in
70 * the OpenSSL open source license shall be deemed granted or received
71 * expressly, by implication, estoppel, or otherwise.
72 *
73 * No assurances are provided by Nokia that the Contribution does not
74 * infringe the patent or other intellectual property rights of any third
75 * party or that the license provides you with all the necessary rights
76 * to make use of the Contribution.
77 *
78 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
79 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
80 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
81 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
82 * OTHERWISE.
83 */
84
85#include <stdio.h>
86
87#include <openssl/buffer.h>
88
89#include "ssl_local.h"
90
91int
92SSL_SESSION_print_fp(FILE *fp, const SSL_SESSION *x)
93{
94 BIO *b;
95 int ret;
96
97 if ((b = BIO_new(BIO_s_file())) == NULL) {
98 SSLerrorx(ERR_R_BUF_LIB);
99 return 0;
100 }
101 BIO_set_fp(b, fp, BIO_NOCLOSE);
102 ret = SSL_SESSION_print(b, x);
103 BIO_free(b);
104 return ret;
105}
106LSSL_ALIAS(SSL_SESSION_print_fp);
107
108int
109SSL_SESSION_print(BIO *bp, const SSL_SESSION *x)
110{
111 const SSL_CIPHER *cipher;
112 size_t i;
113 int ret = 0;
114
115 if (x == NULL)
116 goto err;
117
118 if (BIO_puts(bp, "SSL-Session:\n") <= 0)
119 goto err;
120
121 if (BIO_printf(bp, " Protocol : %s\n",
122 ssl_version_string(x->ssl_version)) <= 0)
123 goto err;
124
125 if ((cipher = ssl3_get_cipher_by_value(x->cipher_value)) == NULL) {
126 if (BIO_printf(bp, " Cipher : %04X\n",
127 x->cipher_value) <= 0)
128 goto err;
129 } else {
130 const char *cipher_name = "unknown";
131
132 if (cipher->name != NULL)
133 cipher_name = cipher->name;
134
135 if (BIO_printf(bp, " Cipher : %s\n", cipher_name) <= 0)
136 goto err;
137 }
138
139 if (BIO_puts(bp, " Session-ID: ") <= 0)
140 goto err;
141
142 for (i = 0; i < x->session_id_length; i++) {
143 if (BIO_printf(bp, "%02X", x->session_id[i]) <= 0)
144 goto err;
145 }
146
147 if (BIO_puts(bp, "\n Session-ID-ctx: ") <= 0)
148 goto err;
149
150 for (i = 0; i < x->sid_ctx_length; i++) {
151 if (BIO_printf(bp, "%02X", x->sid_ctx[i]) <= 0)
152 goto err;
153 }
154
155 if (BIO_puts(bp, "\n Master-Key: ") <= 0)
156 goto err;
157
158 for (i = 0; i < x->master_key_length; i++) {
159 if (BIO_printf(bp, "%02X", x->master_key[i]) <= 0)
160 goto err;
161 }
162
163 if (x->tlsext_tick_lifetime_hint > 0) {
164 if (BIO_printf(bp,
165 "\n TLS session ticket lifetime hint: %u (seconds)",
166 x->tlsext_tick_lifetime_hint) <= 0)
167 goto err;
168 }
169
170 if (x->tlsext_tick != NULL) {
171 if (BIO_puts(bp, "\n TLS session ticket:\n") <= 0)
172 goto err;
173 if (BIO_dump_indent(bp, x->tlsext_tick, x->tlsext_ticklen,
174 4) <= 0)
175 goto err;
176 }
177
178 if (x->time != 0) {
179 if (BIO_printf(bp, "\n Start Time: %lld",
180 (long long)x->time) <= 0)
181 goto err;
182 }
183
184 if (x->timeout != 0) {
185 if (BIO_printf(bp, "\n Timeout : %ld (sec)",
186 x->timeout) <= 0)
187 goto err;
188 }
189
190 if (BIO_puts(bp, "\n") <= 0)
191 goto err;
192
193 if (BIO_printf(bp, " Verify return code: %ld (%s)\n",
194 x->verify_result,
195 X509_verify_cert_error_string(x->verify_result)) <= 0)
196 goto err;
197
198 ret = 1;
199 err:
200 return ret;
201}
202LSSL_ALIAS(SSL_SESSION_print);
diff --git a/src/lib/libssl/ssl_versions.c b/src/lib/libssl/ssl_versions.c
deleted file mode 100644
index 8273546062..0000000000
--- a/src/lib/libssl/ssl_versions.c
+++ /dev/null
@@ -1,373 +0,0 @@
1/* $OpenBSD: ssl_versions.c,v 1.27 2023/07/02 17:21:32 beck Exp $ */
2/*
3 * Copyright (c) 2016, 2017 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "ssl_local.h"
19
20static uint16_t
21ssl_dtls_to_tls_version(uint16_t dtls_ver)
22{
23 if (dtls_ver == DTLS1_VERSION)
24 return TLS1_1_VERSION;
25 if (dtls_ver == DTLS1_2_VERSION)
26 return TLS1_2_VERSION;
27 return 0;
28}
29
30static uint16_t
31ssl_tls_to_dtls_version(uint16_t tls_ver)
32{
33 if (tls_ver == TLS1_1_VERSION)
34 return DTLS1_VERSION;
35 if (tls_ver == TLS1_2_VERSION)
36 return DTLS1_2_VERSION;
37 return 0;
38}
39
40static int
41ssl_clamp_tls_version_range(uint16_t *min_ver, uint16_t *max_ver,
42 uint16_t clamp_min, uint16_t clamp_max)
43{
44 if (clamp_min > clamp_max || *min_ver > *max_ver)
45 return 0;
46 if (clamp_max < *min_ver || clamp_min > *max_ver)
47 return 0;
48
49 if (*min_ver < clamp_min)
50 *min_ver = clamp_min;
51 if (*max_ver > clamp_max)
52 *max_ver = clamp_max;
53
54 return 1;
55}
56
57int
58ssl_version_set_min(const SSL_METHOD *meth, uint16_t proto_ver,
59 uint16_t max_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver)
60{
61 uint16_t min_proto, min_version, max_version;
62
63 if (proto_ver == 0) {
64 *out_tls_ver = meth->min_tls_version;
65 *out_proto_ver = 0;
66 return 1;
67 }
68
69 min_version = proto_ver;
70 max_version = max_tls_ver;
71
72 if (meth->dtls) {
73 if ((min_version = ssl_dtls_to_tls_version(proto_ver)) == 0)
74 return 0;
75 }
76
77 if (!ssl_clamp_tls_version_range(&min_version, &max_version,
78 meth->min_tls_version, meth->max_tls_version))
79 return 0;
80
81 min_proto = min_version;
82 if (meth->dtls) {
83 if ((min_proto = ssl_tls_to_dtls_version(min_version)) == 0)
84 return 0;
85 }
86 *out_tls_ver = min_version;
87 *out_proto_ver = min_proto;
88
89 return 1;
90}
91
92int
93ssl_version_set_max(const SSL_METHOD *meth, uint16_t proto_ver,
94 uint16_t min_tls_ver, uint16_t *out_tls_ver, uint16_t *out_proto_ver)
95{
96 uint16_t max_proto, min_version, max_version;
97
98 if (proto_ver == 0) {
99 *out_tls_ver = meth->max_tls_version;
100 *out_proto_ver = 0;
101 return 1;
102 }
103
104 min_version = min_tls_ver;
105 max_version = proto_ver;
106
107 if (meth->dtls) {
108 if ((max_version = ssl_dtls_to_tls_version(proto_ver)) == 0)
109 return 0;
110 }
111
112 if (!ssl_clamp_tls_version_range(&min_version, &max_version,
113 meth->min_tls_version, meth->max_tls_version))
114 return 0;
115
116 max_proto = max_version;
117 if (meth->dtls) {
118 if ((max_proto = ssl_tls_to_dtls_version(max_version)) == 0)
119 return 0;
120 }
121 *out_tls_ver = max_version;
122 *out_proto_ver = max_proto;
123
124 return 1;
125}
126
127int
128ssl_enabled_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver)
129{
130 uint16_t min_version, max_version;
131 unsigned long options;
132
133 /*
134 * The enabled versions have to be a contiguous range, which means we
135 * cannot enable and disable single versions at our whim, even though
136 * this is what the OpenSSL flags allow. The historical way this has
137 * been handled is by making a flag mean that all higher versions
138 * are disabled, if any version lower than the flag is enabled.
139 */
140
141 min_version = 0;
142 max_version = TLS1_3_VERSION;
143 options = s->options;
144
145 if (SSL_is_dtls(s)) {
146 options = 0;
147 if (s->options & SSL_OP_NO_DTLSv1)
148 options |= SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1;
149 if (s->options & SSL_OP_NO_DTLSv1_2)
150 options |= SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_2;
151 }
152
153 if ((options & SSL_OP_NO_TLSv1_2) == 0)
154 min_version = TLS1_2_VERSION;
155 else if ((options & SSL_OP_NO_TLSv1_3) == 0)
156 min_version = TLS1_3_VERSION;
157
158 if ((options & SSL_OP_NO_TLSv1_3) && min_version < TLS1_3_VERSION)
159 max_version = TLS1_2_VERSION;
160 if ((options & SSL_OP_NO_TLSv1_2) && min_version < TLS1_2_VERSION)
161 max_version = 0;
162
163 /* Everything has been disabled... */
164 if (min_version == 0 || max_version == 0)
165 return 0;
166
167 /* Limit to configured version range. */
168 if (!ssl_clamp_tls_version_range(&min_version, &max_version,
169 s->min_tls_version, s->max_tls_version))
170 return 0;
171
172 /* QUIC requires a minimum of TLSv1.3. */
173 if (SSL_is_quic(s)) {
174 if (max_version < TLS1_3_VERSION)
175 return 0;
176 if (min_version < TLS1_3_VERSION)
177 min_version = TLS1_3_VERSION;
178 }
179
180 if (min_ver != NULL)
181 *min_ver = min_version;
182 if (max_ver != NULL)
183 *max_ver = max_version;
184
185 return 1;
186}
187
188int
189ssl_supported_tls_version_range(SSL *s, uint16_t *min_ver, uint16_t *max_ver)
190{
191 uint16_t min_version, max_version;
192
193 if (!ssl_enabled_tls_version_range(s, &min_version, &max_version))
194 return 0;
195
196 /* Limit to the versions supported by this method. */
197 if (!ssl_clamp_tls_version_range(&min_version, &max_version,
198 s->method->min_tls_version, s->method->max_tls_version))
199 return 0;
200
201 if (min_ver != NULL)
202 *min_ver = min_version;
203 if (max_ver != NULL)
204 *max_ver = max_version;
205
206 return 1;
207}
208
209uint16_t
210ssl_tls_version(uint16_t version)
211{
212 if (version == TLS1_VERSION || version == TLS1_1_VERSION ||
213 version == TLS1_2_VERSION || version == TLS1_3_VERSION)
214 return version;
215
216 if (version == DTLS1_VERSION)
217 return TLS1_1_VERSION;
218 if (version == DTLS1_2_VERSION)
219 return TLS1_2_VERSION;
220
221 return 0;
222}
223
224uint16_t
225ssl_effective_tls_version(SSL *s)
226{
227 if (s->s3->hs.negotiated_tls_version > 0)
228 return s->s3->hs.negotiated_tls_version;
229
230 return s->s3->hs.our_max_tls_version;
231}
232
233int
234ssl_max_supported_version(SSL *s, uint16_t *max_ver)
235{
236 uint16_t max_version;
237
238 *max_ver = 0;
239
240 if (!ssl_supported_tls_version_range(s, NULL, &max_version))
241 return 0;
242
243 if (SSL_is_dtls(s)) {
244 if ((max_version = ssl_tls_to_dtls_version(max_version)) == 0)
245 return 0;
246 }
247
248 *max_ver = max_version;
249
250 return 1;
251}
252
253int
254ssl_max_legacy_version(SSL *s, uint16_t *max_ver)
255{
256 uint16_t max_version;
257
258 if ((max_version = s->s3->hs.our_max_tls_version) > TLS1_2_VERSION)
259 max_version = TLS1_2_VERSION;
260
261 if (SSL_is_dtls(s)) {
262 if ((max_version = ssl_tls_to_dtls_version(max_version)) == 0)
263 return 0;
264 }
265
266 *max_ver = max_version;
267
268 return 1;
269}
270
271int
272ssl_max_shared_version(SSL *s, uint16_t peer_ver, uint16_t *max_ver)
273{
274 uint16_t min_version, max_version, peer_tls_version, shared_version;
275
276 *max_ver = 0;
277 peer_tls_version = peer_ver;
278
279 if (SSL_is_dtls(s)) {
280 if ((peer_ver >> 8) != DTLS1_VERSION_MAJOR)
281 return 0;
282
283 /*
284 * Convert the peer version to a TLS version - DTLS versions are
285 * the 1's complement of TLS version numbers (but not the actual
286 * protocol version numbers, that would be too sensible). Not to
287 * mention that DTLSv1.0 is really equivalent to DTLSv1.1.
288 */
289 peer_tls_version = ssl_dtls_to_tls_version(peer_ver);
290
291 /*
292 * This may be a version that we do not know about, if it is
293 * newer than DTLS1_2_VERSION (yes, less than is correct due
294 * to the "clever" versioning scheme), use TLS1_2_VERSION.
295 */
296 if (peer_tls_version == 0) {
297 if (peer_ver < DTLS1_2_VERSION)
298 peer_tls_version = TLS1_2_VERSION;
299 }
300 }
301
302 if (peer_tls_version >= TLS1_3_VERSION)
303 shared_version = TLS1_3_VERSION;
304 else if (peer_tls_version >= TLS1_2_VERSION)
305 shared_version = TLS1_2_VERSION;
306 else if (peer_tls_version >= TLS1_1_VERSION)
307 shared_version = TLS1_1_VERSION;
308 else if (peer_tls_version >= TLS1_VERSION)
309 shared_version = TLS1_VERSION;
310 else
311 return 0;
312
313 if (!ssl_supported_tls_version_range(s, &min_version, &max_version))
314 return 0;
315
316 if (shared_version < min_version)
317 return 0;
318
319 if (shared_version > max_version)
320 shared_version = max_version;
321
322 if (SSL_is_dtls(s)) {
323 /*
324 * The resulting shared version will by definition be something
325 * that we know about. Switch back from TLS to DTLS.
326 */
327 shared_version = ssl_tls_to_dtls_version(shared_version);
328 if (shared_version == 0)
329 return 0;
330 }
331
332 if (!ssl_security_version(s, shared_version))
333 return 0;
334
335 *max_ver = shared_version;
336
337 return 1;
338}
339
340int
341ssl_check_version_from_server(SSL *s, uint16_t server_version)
342{
343 uint16_t min_tls_version, max_tls_version, server_tls_version;
344
345 /* Ensure that the version selected by the server is valid. */
346
347 server_tls_version = server_version;
348 if (SSL_is_dtls(s)) {
349 server_tls_version = ssl_dtls_to_tls_version(server_version);
350 if (server_tls_version == 0)
351 return 0;
352 }
353
354 if (!ssl_supported_tls_version_range(s, &min_tls_version,
355 &max_tls_version))
356 return 0;
357
358 if (server_tls_version < min_tls_version ||
359 server_tls_version > max_tls_version)
360 return 0;
361
362 return ssl_security_version(s, server_tls_version);
363}
364
365int
366ssl_legacy_stack_version(SSL *s, uint16_t version)
367{
368 if (SSL_is_dtls(s))
369 return version == DTLS1_VERSION || version == DTLS1_2_VERSION;
370
371 return version == TLS1_VERSION || version == TLS1_1_VERSION ||
372 version == TLS1_2_VERSION;
373}
diff --git a/src/lib/libssl/t1_enc.c b/src/lib/libssl/t1_enc.c
deleted file mode 100644
index 64e1dd5b63..0000000000
--- a/src/lib/libssl/t1_enc.c
+++ /dev/null
@@ -1,417 +0,0 @@
1/* $OpenBSD: t1_enc.c,v 1.158 2024/07/20 04:04:23 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2005 Nokia. All rights reserved.
113 *
114 * The portions of the attached software ("Contribution") is developed by
115 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
116 * license.
117 *
118 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
119 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
120 * support (see RFC 4279) to OpenSSL.
121 *
122 * No patent licenses or other rights except those expressly stated in
123 * the OpenSSL open source license shall be deemed granted or received
124 * expressly, by implication, estoppel, or otherwise.
125 *
126 * No assurances are provided by Nokia that the Contribution does not
127 * infringe the patent or other intellectual property rights of any third
128 * party or that the license provides you with all the necessary rights
129 * to make use of the Contribution.
130 *
131 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
132 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
133 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
134 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
135 * OTHERWISE.
136 */
137
138#include <limits.h>
139#include <stdio.h>
140
141#include <openssl/evp.h>
142#include <openssl/hmac.h>
143#include <openssl/md5.h>
144#include <openssl/opensslconf.h>
145
146#include "dtls_local.h"
147#include "ssl_local.h"
148
149void
150tls1_cleanup_key_block(SSL *s)
151{
152 tls12_key_block_free(s->s3->hs.tls12.key_block);
153 s->s3->hs.tls12.key_block = NULL;
154}
155
156/*
157 * TLS P_hash() data expansion function - see RFC 5246, section 5.
158 */
159static int
160tls1_P_hash(const EVP_MD *md, const unsigned char *secret, size_t secret_len,
161 const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len,
162 const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len,
163 const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len)
164{
165 unsigned char A1[EVP_MAX_MD_SIZE], hmac[EVP_MAX_MD_SIZE];
166 size_t A1_len, hmac_len;
167 EVP_MD_CTX *ctx = NULL;
168 EVP_PKEY *mac_key = NULL;
169 int ret = 0;
170 int chunk;
171 size_t i;
172
173 chunk = EVP_MD_size(md);
174 OPENSSL_assert(chunk >= 0);
175
176 if ((ctx = EVP_MD_CTX_new()) == NULL)
177 goto err;
178
179 mac_key = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC, NULL, secret, secret_len);
180 if (mac_key == NULL)
181 goto err;
182 if (!EVP_DigestSignInit(ctx, NULL, md, NULL, mac_key))
183 goto err;
184 if (seed1 && !EVP_DigestSignUpdate(ctx, seed1, seed1_len))
185 goto err;
186 if (seed2 && !EVP_DigestSignUpdate(ctx, seed2, seed2_len))
187 goto err;
188 if (seed3 && !EVP_DigestSignUpdate(ctx, seed3, seed3_len))
189 goto err;
190 if (seed4 && !EVP_DigestSignUpdate(ctx, seed4, seed4_len))
191 goto err;
192 if (seed5 && !EVP_DigestSignUpdate(ctx, seed5, seed5_len))
193 goto err;
194 if (!EVP_DigestSignFinal(ctx, A1, &A1_len))
195 goto err;
196
197 for (;;) {
198 if (!EVP_DigestSignInit(ctx, NULL, md, NULL, mac_key))
199 goto err;
200 if (!EVP_DigestSignUpdate(ctx, A1, A1_len))
201 goto err;
202 if (seed1 && !EVP_DigestSignUpdate(ctx, seed1, seed1_len))
203 goto err;
204 if (seed2 && !EVP_DigestSignUpdate(ctx, seed2, seed2_len))
205 goto err;
206 if (seed3 && !EVP_DigestSignUpdate(ctx, seed3, seed3_len))
207 goto err;
208 if (seed4 && !EVP_DigestSignUpdate(ctx, seed4, seed4_len))
209 goto err;
210 if (seed5 && !EVP_DigestSignUpdate(ctx, seed5, seed5_len))
211 goto err;
212 if (!EVP_DigestSignFinal(ctx, hmac, &hmac_len))
213 goto err;
214
215 if (hmac_len > out_len)
216 hmac_len = out_len;
217
218 for (i = 0; i < hmac_len; i++)
219 out[i] ^= hmac[i];
220
221 out += hmac_len;
222 out_len -= hmac_len;
223
224 if (out_len == 0)
225 break;
226
227 if (!EVP_DigestSignInit(ctx, NULL, md, NULL, mac_key))
228 goto err;
229 if (!EVP_DigestSignUpdate(ctx, A1, A1_len))
230 goto err;
231 if (!EVP_DigestSignFinal(ctx, A1, &A1_len))
232 goto err;
233 }
234 ret = 1;
235
236 err:
237 EVP_PKEY_free(mac_key);
238 EVP_MD_CTX_free(ctx);
239
240 explicit_bzero(A1, sizeof(A1));
241 explicit_bzero(hmac, sizeof(hmac));
242
243 return ret;
244}
245
246int
247tls1_PRF(SSL *s, const unsigned char *secret, size_t secret_len,
248 const void *seed1, size_t seed1_len, const void *seed2, size_t seed2_len,
249 const void *seed3, size_t seed3_len, const void *seed4, size_t seed4_len,
250 const void *seed5, size_t seed5_len, unsigned char *out, size_t out_len)
251{
252 const EVP_MD *md;
253 size_t half_len;
254
255 memset(out, 0, out_len);
256
257 if (!ssl_get_handshake_evp_md(s, &md))
258 return (0);
259
260 if (EVP_MD_type(md) == NID_md5_sha1) {
261 /*
262 * Partition secret between MD5 and SHA1, then XOR result.
263 * If the secret length is odd, a one byte overlap is used.
264 */
265 half_len = secret_len - (secret_len / 2);
266 if (!tls1_P_hash(EVP_md5(), secret, half_len, seed1, seed1_len,
267 seed2, seed2_len, seed3, seed3_len, seed4, seed4_len,
268 seed5, seed5_len, out, out_len))
269 return (0);
270
271 secret += secret_len - half_len;
272 if (!tls1_P_hash(EVP_sha1(), secret, half_len, seed1, seed1_len,
273 seed2, seed2_len, seed3, seed3_len, seed4, seed4_len,
274 seed5, seed5_len, out, out_len))
275 return (0);
276
277 return (1);
278 }
279
280 if (!tls1_P_hash(md, secret, secret_len, seed1, seed1_len,
281 seed2, seed2_len, seed3, seed3_len, seed4, seed4_len,
282 seed5, seed5_len, out, out_len))
283 return (0);
284
285 return (1);
286}
287
288int
289tls1_generate_key_block(SSL *s, uint8_t *key_block, size_t key_block_len)
290{
291 return tls1_PRF(s,
292 s->session->master_key, s->session->master_key_length,
293 TLS_MD_KEY_EXPANSION_CONST, TLS_MD_KEY_EXPANSION_CONST_SIZE,
294 s->s3->server_random, SSL3_RANDOM_SIZE,
295 s->s3->client_random, SSL3_RANDOM_SIZE,
296 NULL, 0, NULL, 0, key_block, key_block_len);
297}
298
299static int
300tls1_change_cipher_state(SSL *s, int is_write)
301{
302 CBS mac_key, key, iv;
303
304 /* Use client write keys on client write and server read. */
305 if ((!s->server && is_write) || (s->server && !is_write)) {
306 tls12_key_block_client_write(s->s3->hs.tls12.key_block,
307 &mac_key, &key, &iv);
308 } else {
309 tls12_key_block_server_write(s->s3->hs.tls12.key_block,
310 &mac_key, &key, &iv);
311 }
312
313 if (!is_write) {
314 if (!tls12_record_layer_change_read_cipher_state(s->rl,
315 &mac_key, &key, &iv))
316 goto err;
317 if (SSL_is_dtls(s))
318 dtls1_reset_read_seq_numbers(s);
319 } else {
320 if (!tls12_record_layer_change_write_cipher_state(s->rl,
321 &mac_key, &key, &iv))
322 goto err;
323 }
324 return (1);
325
326 err:
327 return (0);
328}
329
330int
331tls1_change_read_cipher_state(SSL *s)
332{
333 return tls1_change_cipher_state(s, 0);
334}
335
336int
337tls1_change_write_cipher_state(SSL *s)
338{
339 return tls1_change_cipher_state(s, 1);
340}
341
342int
343tls1_setup_key_block(SSL *s)
344{
345 struct tls12_key_block *key_block;
346 int mac_type = NID_undef, mac_secret_size = 0;
347 const EVP_CIPHER *cipher = NULL;
348 const EVP_AEAD *aead = NULL;
349 const EVP_MD *handshake_hash = NULL;
350 const EVP_MD *mac_hash = NULL;
351 int ret = 0;
352
353 /*
354 * XXX - callers should be changed so that they only call this
355 * function once.
356 */
357 if (s->s3->hs.tls12.key_block != NULL)
358 return (1);
359
360 if (s->s3->hs.cipher == NULL)
361 return (0);
362
363 if ((s->s3->hs.cipher->algorithm_mac & SSL_AEAD) != 0) {
364 if (!ssl_cipher_get_evp_aead(s, &aead)) {
365 SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
366 return (0);
367 }
368 } else {
369 /* XXX - mac_type and mac_secret_size are now unused. */
370 if (!ssl_cipher_get_evp(s, &cipher, &mac_hash,
371 &mac_type, &mac_secret_size)) {
372 SSLerror(s, SSL_R_CIPHER_OR_HASH_UNAVAILABLE);
373 return (0);
374 }
375 }
376
377 if (!ssl_get_handshake_evp_md(s, &handshake_hash))
378 return (0);
379
380 tls12_record_layer_set_aead(s->rl, aead);
381 tls12_record_layer_set_cipher_hash(s->rl, cipher,
382 handshake_hash, mac_hash);
383
384 if ((key_block = tls12_key_block_new()) == NULL)
385 goto err;
386 if (!tls12_key_block_generate(key_block, s, aead, cipher, mac_hash))
387 goto err;
388
389 s->s3->hs.tls12.key_block = key_block;
390 key_block = NULL;
391
392 if (!(s->options & SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS) &&
393 s->method->version <= TLS1_VERSION) {
394 /*
395 * Enable vulnerability countermeasure for CBC ciphers with
396 * known-IV problem (http://www.openssl.org/~bodo/tls-cbc.txt)
397 */
398 s->s3->need_empty_fragments = 1;
399
400 if (s->s3->hs.cipher != NULL) {
401 if (s->s3->hs.cipher->algorithm_enc == SSL_eNULL)
402 s->s3->need_empty_fragments = 0;
403
404#ifndef OPENSSL_NO_RC4
405 if (s->s3->hs.cipher->algorithm_enc == SSL_RC4)
406 s->s3->need_empty_fragments = 0;
407#endif
408 }
409 }
410
411 ret = 1;
412
413 err:
414 tls12_key_block_free(key_block);
415
416 return (ret);
417}
diff --git a/src/lib/libssl/t1_lib.c b/src/lib/libssl/t1_lib.c
deleted file mode 100644
index b200f78098..0000000000
--- a/src/lib/libssl/t1_lib.c
+++ /dev/null
@@ -1,1119 +0,0 @@
1/* $OpenBSD: t1_lib.c,v 1.204 2025/01/18 14:17:05 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include <stdio.h>
113
114#include <openssl/evp.h>
115#include <openssl/hmac.h>
116#include <openssl/objects.h>
117#include <openssl/ocsp.h>
118
119#include "bytestring.h"
120#include "ssl_local.h"
121#include "ssl_sigalgs.h"
122#include "ssl_tlsext.h"
123
124static int tls_decrypt_ticket(SSL *s, CBS *ticket, int *alert,
125 SSL_SESSION **psess);
126
127int
128tls1_new(SSL *s)
129{
130 if (!ssl3_new(s))
131 return 0;
132 s->method->ssl_clear(s);
133 return 1;
134}
135
136void
137tls1_free(SSL *s)
138{
139 if (s == NULL)
140 return;
141
142 free(s->tlsext_session_ticket);
143 ssl3_free(s);
144}
145
146void
147tls1_clear(SSL *s)
148{
149 ssl3_clear(s);
150 s->version = s->method->version;
151}
152
153struct supported_group {
154 int nid;
155 int bits;
156};
157
158/*
159 * Supported groups (formerly known as named curves)
160 * https://www.iana.org/assignments/tls-parameters/#tls-parameters-8
161 */
162static const struct supported_group nid_list[] = {
163 [1] = {
164 .nid = NID_sect163k1,
165 .bits = 80,
166 },
167 [2] = {
168 .nid = NID_sect163r1,
169 .bits = 80,
170 },
171 [3] = {
172 .nid = NID_sect163r2,
173 .bits = 80,
174 },
175 [4] = {
176 .nid = NID_sect193r1,
177 .bits = 80,
178 },
179 [5] = {
180 .nid = NID_sect193r2,
181 .bits = 80,
182 },
183 [6] = {
184 .nid = NID_sect233k1,
185 .bits = 112,
186 },
187 [7] = {
188 .nid = NID_sect233r1,
189 .bits = 112,
190 },
191 [8] = {
192 .nid = NID_sect239k1,
193 .bits = 112,
194 },
195 [9] = {
196 .nid = NID_sect283k1,
197 .bits = 128,
198 },
199 [10] = {
200 .nid = NID_sect283r1,
201 .bits = 128,
202 },
203 [11] = {
204 .nid = NID_sect409k1,
205 .bits = 192,
206 },
207 [12] = {
208 .nid = NID_sect409r1,
209 .bits = 192,
210 },
211 [13] = {
212 .nid = NID_sect571k1,
213 .bits = 256,
214 },
215 [14] = {
216 .nid = NID_sect571r1,
217 .bits = 256,
218 },
219 [15] = {
220 .nid = NID_secp160k1,
221 .bits = 80,
222 },
223 [16] = {
224 .nid = NID_secp160r1,
225 .bits = 80,
226 },
227 [17] = {
228 .nid = NID_secp160r2,
229 .bits = 80,
230 },
231 [18] = {
232 .nid = NID_secp192k1,
233 .bits = 80,
234 },
235 [19] = {
236 .nid = NID_X9_62_prime192v1, /* aka secp192r1 */
237 .bits = 80,
238 },
239 [20] = {
240 .nid = NID_secp224k1,
241 .bits = 112,
242 },
243 [21] = {
244 .nid = NID_secp224r1,
245 .bits = 112,
246 },
247 [22] = {
248 .nid = NID_secp256k1,
249 .bits = 128,
250 },
251 [23] = {
252 .nid = NID_X9_62_prime256v1, /* aka secp256r1 */
253 .bits = 128,
254 },
255 [24] = {
256 .nid = NID_secp384r1,
257 .bits = 192,
258 },
259 [25] = {
260 .nid = NID_secp521r1,
261 .bits = 256,
262 },
263 [26] = {
264 .nid = NID_brainpoolP256r1,
265 .bits = 128,
266 },
267 [27] = {
268 .nid = NID_brainpoolP384r1,
269 .bits = 192,
270 },
271 [28] = {
272 .nid = NID_brainpoolP512r1,
273 .bits = 256,
274 },
275 [29] = {
276 .nid = NID_X25519,
277 .bits = 128,
278 },
279};
280
281#define NID_LIST_LEN (sizeof(nid_list) / sizeof(nid_list[0]))
282
283#if 0
284static const uint8_t ecformats_list[] = {
285 TLSEXT_ECPOINTFORMAT_uncompressed,
286 TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime,
287 TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2
288};
289#endif
290
291static const uint8_t ecformats_default[] = {
292 TLSEXT_ECPOINTFORMAT_uncompressed,
293};
294
295#if 0
296static const uint16_t ecgroups_list[] = {
297 29, /* X25519 (29) */
298 14, /* sect571r1 (14) */
299 13, /* sect571k1 (13) */
300 25, /* secp521r1 (25) */
301 28, /* brainpoolP512r1 (28) */
302 11, /* sect409k1 (11) */
303 12, /* sect409r1 (12) */
304 27, /* brainpoolP384r1 (27) */
305 24, /* secp384r1 (24) */
306 9, /* sect283k1 (9) */
307 10, /* sect283r1 (10) */
308 26, /* brainpoolP256r1 (26) */
309 22, /* secp256k1 (22) */
310 23, /* secp256r1 (23) */
311 8, /* sect239k1 (8) */
312 6, /* sect233k1 (6) */
313 7, /* sect233r1 (7) */
314 20, /* secp224k1 (20) */
315 21, /* secp224r1 (21) */
316 4, /* sect193r1 (4) */
317 5, /* sect193r2 (5) */
318 18, /* secp192k1 (18) */
319 19, /* secp192r1 (19) */
320 1, /* sect163k1 (1) */
321 2, /* sect163r1 (2) */
322 3, /* sect163r2 (3) */
323 15, /* secp160k1 (15) */
324 16, /* secp160r1 (16) */
325 17, /* secp160r2 (17) */
326};
327#endif
328
329static const uint16_t ecgroups_client_default[] = {
330 29, /* X25519 (29) */
331 23, /* secp256r1 (23) */
332 24, /* secp384r1 (24) */
333 25, /* secp521r1 (25) */
334};
335
336static const uint16_t ecgroups_server_default[] = {
337 29, /* X25519 (29) */
338 23, /* secp256r1 (23) */
339 24, /* secp384r1 (24) */
340};
341
342int
343tls1_ec_group_id2nid(uint16_t group_id, int *out_nid)
344{
345 int nid;
346
347 if (group_id >= NID_LIST_LEN)
348 return 0;
349
350 if ((nid = nid_list[group_id].nid) == 0)
351 return 0;
352
353 *out_nid = nid;
354
355 return 1;
356}
357
358int
359tls1_ec_group_id2bits(uint16_t group_id, int *out_bits)
360{
361 int bits;
362
363 if (group_id >= NID_LIST_LEN)
364 return 0;
365
366 if ((bits = nid_list[group_id].bits) == 0)
367 return 0;
368
369 *out_bits = bits;
370
371 return 1;
372}
373
374int
375tls1_ec_nid2group_id(int nid, uint16_t *out_group_id)
376{
377 uint16_t group_id;
378
379 if (nid == 0)
380 return 0;
381
382 for (group_id = 0; group_id < NID_LIST_LEN; group_id++) {
383 if (nid_list[group_id].nid == nid) {
384 *out_group_id = group_id;
385 return 1;
386 }
387 }
388
389 return 0;
390}
391
392/*
393 * Return the appropriate format list. If client_formats is non-zero, return
394 * the client/session formats. Otherwise return the custom format list if one
395 * exists, or the default formats if a custom list has not been specified.
396 */
397void
398tls1_get_formatlist(const SSL *s, int client_formats, const uint8_t **pformats,
399 size_t *pformatslen)
400{
401 if (client_formats != 0) {
402 *pformats = s->session->tlsext_ecpointformatlist;
403 *pformatslen = s->session->tlsext_ecpointformatlist_length;
404 return;
405 }
406
407 *pformats = s->tlsext_ecpointformatlist;
408 *pformatslen = s->tlsext_ecpointformatlist_length;
409 if (*pformats == NULL) {
410 *pformats = ecformats_default;
411 *pformatslen = sizeof(ecformats_default);
412 }
413}
414
415/*
416 * Return the appropriate group list. If client_groups is non-zero, return
417 * the client/session groups. Otherwise return the custom group list if one
418 * exists, or the default groups if a custom list has not been specified.
419 */
420void
421tls1_get_group_list(const SSL *s, int client_groups, const uint16_t **pgroups,
422 size_t *pgroupslen)
423{
424 if (client_groups != 0) {
425 *pgroups = s->session->tlsext_supportedgroups;
426 *pgroupslen = s->session->tlsext_supportedgroups_length;
427 return;
428 }
429
430 *pgroups = s->tlsext_supportedgroups;
431 *pgroupslen = s->tlsext_supportedgroups_length;
432 if (*pgroups != NULL)
433 return;
434
435 if (!s->server) {
436 *pgroups = ecgroups_client_default;
437 *pgroupslen = sizeof(ecgroups_client_default) / 2;
438 } else {
439 *pgroups = ecgroups_server_default;
440 *pgroupslen = sizeof(ecgroups_server_default) / 2;
441 }
442}
443
444static int
445tls1_get_group_lists(const SSL *ssl, const uint16_t **pref, size_t *preflen,
446 const uint16_t **supp, size_t *supplen)
447{
448 unsigned long server_pref;
449
450 /* Cannot do anything on the client side. */
451 if (!ssl->server)
452 return 0;
453
454 server_pref = (ssl->options & SSL_OP_CIPHER_SERVER_PREFERENCE);
455 tls1_get_group_list(ssl, (server_pref == 0), pref, preflen);
456 tls1_get_group_list(ssl, (server_pref != 0), supp, supplen);
457
458 return 1;
459}
460
461static int
462tls1_group_id_present(uint16_t group_id, const uint16_t *list, size_t list_len)
463{
464 size_t i;
465
466 for (i = 0; i < list_len; i++) {
467 if (group_id == list[i])
468 return 1;
469 }
470
471 return 0;
472}
473
474int
475tls1_count_shared_groups(const SSL *ssl, size_t *out_count)
476{
477 size_t count, preflen, supplen, i;
478 const uint16_t *pref, *supp;
479
480 if (!tls1_get_group_lists(ssl, &pref, &preflen, &supp, &supplen))
481 return 0;
482
483 count = 0;
484 for (i = 0; i < preflen; i++) {
485 if (!tls1_group_id_present(pref[i], supp, supplen))
486 continue;
487
488 if (!ssl_security_shared_group(ssl, pref[i]))
489 continue;
490
491 count++;
492 }
493
494 *out_count = count;
495
496 return 1;
497}
498
499static int
500tls1_group_by_index(const SSL *ssl, size_t n, int *out_nid,
501 int (*ssl_security_fn)(const SSL *, uint16_t))
502{
503 size_t count, preflen, supplen, i;
504 const uint16_t *pref, *supp;
505
506 if (!tls1_get_group_lists(ssl, &pref, &preflen, &supp, &supplen))
507 return 0;
508
509 count = 0;
510 for (i = 0; i < preflen; i++) {
511 if (!tls1_group_id_present(pref[i], supp, supplen))
512 continue;
513
514 if (!ssl_security_fn(ssl, pref[i]))
515 continue;
516
517 if (count++ == n)
518 return tls1_ec_group_id2nid(pref[i], out_nid);
519 }
520
521 return 0;
522}
523
524int
525tls1_get_shared_group_by_index(const SSL *ssl, size_t index, int *out_nid)
526{
527 return tls1_group_by_index(ssl, index, out_nid,
528 ssl_security_shared_group);
529}
530
531int
532tls1_get_supported_group(const SSL *ssl, int *out_nid)
533{
534 return tls1_group_by_index(ssl, 0, out_nid,
535 ssl_security_supported_group);
536}
537
538int
539tls1_set_groups(uint16_t **out_group_ids, size_t *out_group_ids_len,
540 const int *groups, size_t ngroups)
541{
542 uint16_t *group_ids;
543 size_t i;
544
545 if ((group_ids = calloc(ngroups, sizeof(uint16_t))) == NULL)
546 return 0;
547
548 for (i = 0; i < ngroups; i++) {
549 if (!tls1_ec_nid2group_id(groups[i], &group_ids[i])) {
550 free(group_ids);
551 return 0;
552 }
553 }
554
555 free(*out_group_ids);
556 *out_group_ids = group_ids;
557 *out_group_ids_len = ngroups;
558
559 return 1;
560}
561
562int
563tls1_set_group_list(uint16_t **out_group_ids, size_t *out_group_ids_len,
564 const char *groups)
565{
566 uint16_t *new_group_ids, *group_ids = NULL;
567 size_t ngroups = 0;
568 char *gs, *p, *q;
569 int nid;
570
571 if ((gs = strdup(groups)) == NULL)
572 return 0;
573
574 q = gs;
575 while ((p = strsep(&q, ":")) != NULL) {
576 nid = OBJ_sn2nid(p);
577 if (nid == NID_undef)
578 nid = OBJ_ln2nid(p);
579 if (nid == NID_undef)
580 nid = EC_curve_nist2nid(p);
581 if (nid == NID_undef)
582 goto err;
583
584 if ((new_group_ids = reallocarray(group_ids, ngroups + 1,
585 sizeof(uint16_t))) == NULL)
586 goto err;
587 group_ids = new_group_ids;
588
589 if (!tls1_ec_nid2group_id(nid, &group_ids[ngroups]))
590 goto err;
591
592 ngroups++;
593 }
594
595 free(gs);
596 free(*out_group_ids);
597 *out_group_ids = group_ids;
598 *out_group_ids_len = ngroups;
599
600 return 1;
601
602 err:
603 free(gs);
604 free(group_ids);
605
606 return 0;
607}
608
609/* Check that a group is one of our preferences. */
610int
611tls1_check_group(SSL *s, uint16_t group_id)
612{
613 const uint16_t *groups;
614 size_t groupslen, i;
615
616 tls1_get_group_list(s, 0, &groups, &groupslen);
617
618 for (i = 0; i < groupslen; i++) {
619 if (!ssl_security_supported_group(s, groups[i]))
620 continue;
621 if (groups[i] == group_id)
622 return 1;
623 }
624 return 0;
625}
626
627/* For an EC key set TLS ID and required compression based on parameters. */
628static int
629tls1_set_ec_id(uint16_t *group_id, uint8_t *comp_id, EC_KEY *ec)
630{
631 const EC_GROUP *group;
632 int nid;
633
634 if ((group = EC_KEY_get0_group(ec)) == NULL)
635 return 0;
636
637 /* Determine group ID. */
638 nid = EC_GROUP_get_curve_name(group);
639 if (!tls1_ec_nid2group_id(nid, group_id))
640 return 0;
641
642 /* Specify the compression identifier. */
643 if (EC_KEY_get0_public_key(ec) == NULL)
644 return 0;
645 *comp_id = TLSEXT_ECPOINTFORMAT_uncompressed;
646 if (EC_KEY_get_conv_form(ec) == POINT_CONVERSION_COMPRESSED) {
647 *comp_id = TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime;
648 }
649
650 return 1;
651}
652
653/* Check that an EC key is compatible with extensions. */
654static int
655tls1_check_ec_key(SSL *s, const uint16_t group_id, const uint8_t comp_id)
656{
657 size_t groupslen, formatslen, i;
658 const uint16_t *groups;
659 const uint8_t *formats;
660
661 /*
662 * Check point formats extension if present, otherwise everything
663 * is supported (see RFC4492).
664 */
665 tls1_get_formatlist(s, 1, &formats, &formatslen);
666 if (formats != NULL) {
667 for (i = 0; i < formatslen; i++) {
668 if (formats[i] == comp_id)
669 break;
670 }
671 if (i == formatslen)
672 return 0;
673 }
674
675 /*
676 * Check group list if present, otherwise everything is supported.
677 */
678 tls1_get_group_list(s, 1, &groups, &groupslen);
679 if (groups != NULL) {
680 for (i = 0; i < groupslen; i++) {
681 if (groups[i] == group_id)
682 break;
683 }
684 if (i == groupslen)
685 return 0;
686 }
687
688 return 1;
689}
690
691/* Check EC server key is compatible with client extensions. */
692int
693tls1_check_ec_server_key(SSL *s)
694{
695 SSL_CERT_PKEY *cpk = s->cert->pkeys + SSL_PKEY_ECC;
696 uint16_t group_id;
697 uint8_t comp_id;
698 EC_KEY *eckey;
699 EVP_PKEY *pkey;
700
701 if (cpk->x509 == NULL || cpk->privatekey == NULL)
702 return 0;
703 if ((pkey = X509_get0_pubkey(cpk->x509)) == NULL)
704 return 0;
705 if ((eckey = EVP_PKEY_get0_EC_KEY(pkey)) == NULL)
706 return 0;
707 if (!tls1_set_ec_id(&group_id, &comp_id, eckey))
708 return 0;
709
710 return tls1_check_ec_key(s, group_id, comp_id);
711}
712
713int
714ssl_check_clienthello_tlsext_early(SSL *s)
715{
716 int ret = SSL_TLSEXT_ERR_NOACK;
717 int al = SSL_AD_UNRECOGNIZED_NAME;
718
719 /* The handling of the ECPointFormats extension is done elsewhere, namely in
720 * ssl3_choose_cipher in s3_lib.c.
721 */
722 /* The handling of the EllipticCurves extension is done elsewhere, namely in
723 * ssl3_choose_cipher in s3_lib.c.
724 */
725
726 if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0)
727 ret = s->ctx->tlsext_servername_callback(s, &al,
728 s->ctx->tlsext_servername_arg);
729 else if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0)
730 ret = s->initial_ctx->tlsext_servername_callback(s, &al,
731 s->initial_ctx->tlsext_servername_arg);
732
733 switch (ret) {
734 case SSL_TLSEXT_ERR_ALERT_FATAL:
735 ssl3_send_alert(s, SSL3_AL_FATAL, al);
736 return -1;
737 case SSL_TLSEXT_ERR_ALERT_WARNING:
738 ssl3_send_alert(s, SSL3_AL_WARNING, al);
739 return 1;
740 case SSL_TLSEXT_ERR_NOACK:
741 default:
742 return 1;
743 }
744}
745
746int
747ssl_check_clienthello_tlsext_late(SSL *s)
748{
749 int ret = SSL_TLSEXT_ERR_OK;
750 int al = 0; /* XXX gcc3 */
751
752 /* If status request then ask callback what to do.
753 * Note: this must be called after servername callbacks in case
754 * the certificate has changed, and must be called after the cipher
755 * has been chosen because this may influence which certificate is sent
756 */
757 if ((s->tlsext_status_type != -1) &&
758 s->ctx && s->ctx->tlsext_status_cb) {
759 int r;
760 SSL_CERT_PKEY *certpkey;
761 certpkey = ssl_get_server_send_pkey(s);
762 /* If no certificate can't return certificate status */
763 if (certpkey == NULL) {
764 s->tlsext_status_expected = 0;
765 return 1;
766 }
767 /* Set current certificate to one we will use so
768 * SSL_get_certificate et al can pick it up.
769 */
770 s->cert->key = certpkey;
771 r = s->ctx->tlsext_status_cb(s,
772 s->ctx->tlsext_status_arg);
773 switch (r) {
774 /* We don't want to send a status request response */
775 case SSL_TLSEXT_ERR_NOACK:
776 s->tlsext_status_expected = 0;
777 break;
778 /* status request response should be sent */
779 case SSL_TLSEXT_ERR_OK:
780 if (s->tlsext_ocsp_resp)
781 s->tlsext_status_expected = 1;
782 else
783 s->tlsext_status_expected = 0;
784 break;
785 /* something bad happened */
786 case SSL_TLSEXT_ERR_ALERT_FATAL:
787 ret = SSL_TLSEXT_ERR_ALERT_FATAL;
788 al = SSL_AD_INTERNAL_ERROR;
789 goto err;
790 }
791 } else
792 s->tlsext_status_expected = 0;
793
794 err:
795 switch (ret) {
796 case SSL_TLSEXT_ERR_ALERT_FATAL:
797 ssl3_send_alert(s, SSL3_AL_FATAL, al);
798 return -1;
799 case SSL_TLSEXT_ERR_ALERT_WARNING:
800 ssl3_send_alert(s, SSL3_AL_WARNING, al);
801 return 1;
802 default:
803 return 1;
804 }
805}
806
807int
808ssl_check_serverhello_tlsext(SSL *s)
809{
810 int ret = SSL_TLSEXT_ERR_NOACK;
811 int al = SSL_AD_UNRECOGNIZED_NAME;
812
813 ret = SSL_TLSEXT_ERR_OK;
814
815 if (s->ctx != NULL && s->ctx->tlsext_servername_callback != 0)
816 ret = s->ctx->tlsext_servername_callback(s, &al,
817 s->ctx->tlsext_servername_arg);
818 else if (s->initial_ctx != NULL && s->initial_ctx->tlsext_servername_callback != 0)
819 ret = s->initial_ctx->tlsext_servername_callback(s, &al,
820 s->initial_ctx->tlsext_servername_arg);
821
822 /* If we've requested certificate status and we wont get one
823 * tell the callback
824 */
825 if ((s->tlsext_status_type != -1) && !(s->tlsext_status_expected) &&
826 s->ctx && s->ctx->tlsext_status_cb) {
827 int r;
828
829 free(s->tlsext_ocsp_resp);
830 s->tlsext_ocsp_resp = NULL;
831 s->tlsext_ocsp_resp_len = 0;
832
833 r = s->ctx->tlsext_status_cb(s,
834 s->ctx->tlsext_status_arg);
835 if (r == 0) {
836 al = SSL_AD_BAD_CERTIFICATE_STATUS_RESPONSE;
837 ret = SSL_TLSEXT_ERR_ALERT_FATAL;
838 }
839 if (r < 0) {
840 al = SSL_AD_INTERNAL_ERROR;
841 ret = SSL_TLSEXT_ERR_ALERT_FATAL;
842 }
843 }
844
845 switch (ret) {
846 case SSL_TLSEXT_ERR_ALERT_FATAL:
847 ssl3_send_alert(s, SSL3_AL_FATAL, al);
848 return -1;
849 case SSL_TLSEXT_ERR_ALERT_WARNING:
850 ssl3_send_alert(s, SSL3_AL_WARNING, al);
851 return 1;
852 case SSL_TLSEXT_ERR_NOACK:
853 default:
854 return 1;
855 }
856}
857
858/* Since the server cache lookup is done early on in the processing of the
859 * ClientHello, and other operations depend on the result, we need to handle
860 * any TLS session ticket extension at the same time.
861 *
862 * ext_block: a CBS for the ClientHello extensions block.
863 * ret: (output) on return, if a ticket was decrypted, then this is set to
864 * point to the resulting session.
865 *
866 * If s->tls_session_secret_cb is set then we are expecting a pre-shared key
867 * ciphersuite, in which case we have no use for session tickets and one will
868 * never be decrypted, nor will s->tlsext_ticket_expected be set to 1.
869 *
870 * Returns:
871 * TLS1_TICKET_FATAL_ERROR: error from parsing or decrypting the ticket.
872 * TLS1_TICKET_NONE: no ticket was found (or was ignored, based on settings).
873 * TLS1_TICKET_EMPTY: a zero length extension was found, indicating that the
874 * client supports session tickets but doesn't currently have one to offer.
875 * TLS1_TICKET_NOT_DECRYPTED: either s->tls_session_secret_cb was
876 * set, or a ticket was offered but couldn't be decrypted because of a
877 * non-fatal error.
878 * TLS1_TICKET_DECRYPTED: a ticket was successfully decrypted and *ret was set.
879 *
880 * Side effects:
881 * Sets s->tlsext_ticket_expected to 1 if the server will have to issue
882 * a new session ticket to the client because the client indicated support
883 * (and s->tls_session_secret_cb is NULL) but the client either doesn't have
884 * a session ticket or we couldn't use the one it gave us, or if
885 * s->ctx->tlsext_ticket_key_cb asked to renew the client's ticket.
886 * Otherwise, s->tlsext_ticket_expected is set to 0.
887 */
888int
889tls1_process_ticket(SSL *s, CBS *ext_block, int *alert, SSL_SESSION **ret)
890{
891 CBS extensions, ext_data;
892 uint16_t ext_type = 0;
893
894 s->tlsext_ticket_expected = 0;
895 *ret = NULL;
896
897 /*
898 * If tickets disabled behave as if no ticket present to permit stateful
899 * resumption.
900 */
901 if (SSL_get_options(s) & SSL_OP_NO_TICKET)
902 return TLS1_TICKET_NONE;
903
904 /*
905 * An empty extensions block is valid, but obviously does not contain
906 * a session ticket.
907 */
908 if (CBS_len(ext_block) == 0)
909 return TLS1_TICKET_NONE;
910
911 if (!CBS_get_u16_length_prefixed(ext_block, &extensions)) {
912 *alert = SSL_AD_DECODE_ERROR;
913 return TLS1_TICKET_FATAL_ERROR;
914 }
915
916 while (CBS_len(&extensions) > 0) {
917 if (!CBS_get_u16(&extensions, &ext_type) ||
918 !CBS_get_u16_length_prefixed(&extensions, &ext_data)) {
919 *alert = SSL_AD_DECODE_ERROR;
920 return TLS1_TICKET_FATAL_ERROR;
921 }
922
923 if (ext_type == TLSEXT_TYPE_session_ticket)
924 break;
925 }
926
927 if (ext_type != TLSEXT_TYPE_session_ticket)
928 return TLS1_TICKET_NONE;
929
930 if (CBS_len(&ext_data) == 0) {
931 /*
932 * The client will accept a ticket but does not currently
933 * have one.
934 */
935 s->tlsext_ticket_expected = 1;
936 return TLS1_TICKET_EMPTY;
937 }
938
939 if (s->tls_session_secret_cb != NULL) {
940 /*
941 * Indicate that the ticket could not be decrypted rather than
942 * generating the session from ticket now, trigger abbreviated
943 * handshake based on external mechanism to calculate the master
944 * secret later.
945 */
946 return TLS1_TICKET_NOT_DECRYPTED;
947 }
948
949 return tls_decrypt_ticket(s, &ext_data, alert, ret);
950}
951
952/* tls_decrypt_ticket attempts to decrypt a session ticket.
953 *
954 * ticket: a CBS containing the body of the session ticket extension.
955 * psess: (output) on return, if a ticket was decrypted, then this is set to
956 * point to the resulting session.
957 *
958 * Returns:
959 * TLS1_TICKET_FATAL_ERROR: error from parsing or decrypting the ticket.
960 * TLS1_TICKET_NOT_DECRYPTED: the ticket couldn't be decrypted.
961 * TLS1_TICKET_DECRYPTED: a ticket was decrypted and *psess was set.
962 */
963static int
964tls_decrypt_ticket(SSL *s, CBS *ticket, int *alert, SSL_SESSION **psess)
965{
966 CBS ticket_name, ticket_iv, ticket_encdata, ticket_hmac;
967 SSL_SESSION *sess = NULL;
968 unsigned char *sdec = NULL;
969 size_t sdec_len = 0;
970 const unsigned char *p;
971 unsigned char hmac[EVP_MAX_MD_SIZE];
972 HMAC_CTX *hctx = NULL;
973 EVP_CIPHER_CTX *cctx = NULL;
974 SSL_CTX *tctx = s->initial_ctx;
975 int slen, hlen, iv_len;
976 int alert_desc = SSL_AD_INTERNAL_ERROR;
977 int ret = TLS1_TICKET_FATAL_ERROR;
978
979 *psess = NULL;
980
981 if (!CBS_get_bytes(ticket, &ticket_name, 16))
982 goto derr;
983
984 /*
985 * Initialize session ticket encryption and HMAC contexts.
986 */
987 if ((cctx = EVP_CIPHER_CTX_new()) == NULL)
988 goto err;
989 if ((hctx = HMAC_CTX_new()) == NULL)
990 goto err;
991
992 if (tctx->tlsext_ticket_key_cb != NULL) {
993 int rv;
994
995 /*
996 * The API guarantees EVP_MAX_IV_LENGTH bytes of space for
997 * the iv to tlsext_ticket_key_cb(). Since the total space
998 * required for a session cookie is never less than this,
999 * this check isn't too strict. The exact check comes later.
1000 */
1001 if (CBS_len(ticket) < EVP_MAX_IV_LENGTH)
1002 goto derr;
1003
1004 if ((rv = tctx->tlsext_ticket_key_cb(s,
1005 (unsigned char *)CBS_data(&ticket_name),
1006 (unsigned char *)CBS_data(ticket), cctx, hctx, 0)) < 0)
1007 goto err;
1008 if (rv == 0)
1009 goto derr;
1010 if (rv == 2) {
1011 /* Renew ticket. */
1012 s->tlsext_ticket_expected = 1;
1013 }
1014
1015 if ((iv_len = EVP_CIPHER_CTX_iv_length(cctx)) < 0)
1016 goto err;
1017 /*
1018 * Now that the cipher context is initialised, we can extract
1019 * the IV since its length is known.
1020 */
1021 if (!CBS_get_bytes(ticket, &ticket_iv, iv_len))
1022 goto derr;
1023 } else {
1024 /* Check that the key name matches. */
1025 if (!CBS_mem_equal(&ticket_name,
1026 tctx->tlsext_tick_key_name,
1027 sizeof(tctx->tlsext_tick_key_name)))
1028 goto derr;
1029 if ((iv_len = EVP_CIPHER_iv_length(EVP_aes_128_cbc())) < 0)
1030 goto err;
1031 if (!CBS_get_bytes(ticket, &ticket_iv, iv_len))
1032 goto derr;
1033 if (!EVP_DecryptInit_ex(cctx, EVP_aes_128_cbc(), NULL,
1034 tctx->tlsext_tick_aes_key, CBS_data(&ticket_iv)))
1035 goto err;
1036 if (!HMAC_Init_ex(hctx, tctx->tlsext_tick_hmac_key,
1037 sizeof(tctx->tlsext_tick_hmac_key), EVP_sha256(),
1038 NULL))
1039 goto err;
1040 }
1041
1042 /*
1043 * Attempt to process session ticket.
1044 */
1045
1046 if ((hlen = HMAC_size(hctx)) < 0)
1047 goto err;
1048
1049 if (hlen > CBS_len(ticket))
1050 goto derr;
1051 if (!CBS_get_bytes(ticket, &ticket_encdata, CBS_len(ticket) - hlen))
1052 goto derr;
1053 if (!CBS_get_bytes(ticket, &ticket_hmac, hlen))
1054 goto derr;
1055 if (CBS_len(ticket) != 0) {
1056 alert_desc = SSL_AD_DECODE_ERROR;
1057 goto err;
1058 }
1059
1060 /* Check HMAC of encrypted ticket. */
1061 if (HMAC_Update(hctx, CBS_data(&ticket_name),
1062 CBS_len(&ticket_name)) <= 0)
1063 goto err;
1064 if (HMAC_Update(hctx, CBS_data(&ticket_iv),
1065 CBS_len(&ticket_iv)) <= 0)
1066 goto err;
1067 if (HMAC_Update(hctx, CBS_data(&ticket_encdata),
1068 CBS_len(&ticket_encdata)) <= 0)
1069 goto err;
1070 if (HMAC_Final(hctx, hmac, &hlen) <= 0)
1071 goto err;
1072
1073 if (!CBS_mem_equal(&ticket_hmac, hmac, hlen))
1074 goto derr;
1075
1076 /* Attempt to decrypt session data. */
1077 sdec_len = CBS_len(&ticket_encdata);
1078 if ((sdec = calloc(1, sdec_len)) == NULL)
1079 goto err;
1080 if (EVP_DecryptUpdate(cctx, sdec, &slen, CBS_data(&ticket_encdata),
1081 CBS_len(&ticket_encdata)) <= 0)
1082 goto derr;
1083 if (EVP_DecryptFinal_ex(cctx, sdec + slen, &hlen) <= 0)
1084 goto derr;
1085
1086 slen += hlen;
1087
1088 /*
1089 * For session parse failures, indicate that we need to send a new
1090 * ticket.
1091 */
1092 p = sdec;
1093 if ((sess = d2i_SSL_SESSION(NULL, &p, slen)) == NULL)
1094 goto derr;
1095 *psess = sess;
1096 sess = NULL;
1097
1098 ret = TLS1_TICKET_DECRYPTED;
1099 goto done;
1100
1101 derr:
1102 ERR_clear_error();
1103 s->tlsext_ticket_expected = 1;
1104 ret = TLS1_TICKET_NOT_DECRYPTED;
1105 goto done;
1106
1107 err:
1108 *alert = alert_desc;
1109 ret = TLS1_TICKET_FATAL_ERROR;
1110 goto done;
1111
1112 done:
1113 freezero(sdec, sdec_len);
1114 EVP_CIPHER_CTX_free(cctx);
1115 HMAC_CTX_free(hctx);
1116 SSL_SESSION_free(sess);
1117
1118 return ret;
1119}
diff --git a/src/lib/libssl/test/CAss.cnf b/src/lib/libssl/test/CAss.cnf
deleted file mode 100644
index 336e82fd52..0000000000
--- a/src/lib/libssl/test/CAss.cnf
+++ /dev/null
@@ -1,76 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 2048
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = sha1
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
24commonName = Common Name (eg, YOUR name)
25commonName_value = Dodgy CA
26
27####################################################################
28[ ca ]
29default_ca = CA_default # The default ca section
30
31####################################################################
32[ CA_default ]
33
34dir = ./demoCA # Where everything is kept
35certs = $dir/certs # Where the issued certs are kept
36crl_dir = $dir/crl # Where the issued crl are kept
37database = $dir/index.txt # database index file.
38#unique_subject = no # Set to 'no' to allow creation of
39 # several certificates with same subject.
40new_certs_dir = $dir/newcerts # default place for new certs.
41
42certificate = $dir/cacert.pem # The CA certificate
43serial = $dir/serial # The current serial number
44crl = $dir/crl.pem # The current CRL
45private_key = $dir/private/cakey.pem# The private key
46RANDFILE = $dir/private/.rand # private random number file
47
48x509_extensions = v3_ca # The extensions to add to the cert
49
50name_opt = ca_default # Subject Name options
51cert_opt = ca_default # Certificate field options
52
53default_days = 365 # how long to certify for
54default_crl_days= 30 # how long before next CRL
55default_md = md5 # which md to use.
56preserve = no # keep passed DN ordering
57
58policy = policy_anything
59
60[ policy_anything ]
61countryName = optional
62stateOrProvinceName = optional
63localityName = optional
64organizationName = optional
65organizationalUnitName = optional
66commonName = supplied
67emailAddress = optional
68
69
70
71[ v3_ca ]
72subjectKeyIdentifier=hash
73authorityKeyIdentifier=keyid:always,issuer:always
74basicConstraints = CA:true,pathlen:1
75keyUsage = cRLSign, keyCertSign
76issuerAltName=issuer:copy
diff --git a/src/lib/libssl/test/CAssdh.cnf b/src/lib/libssl/test/CAssdh.cnf
deleted file mode 100644
index 4e0a908679..0000000000
--- a/src/lib/libssl/test/CAssdh.cnf
+++ /dev/null
@@ -1,24 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# hacked by iang to do DH certs - CA
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = CU
17countryName_value = CU
18
19organizationName = Organization Name (eg, company)
20organizationName_value = La Junta de la Revolucion
21
22commonName = Common Name (eg, YOUR name)
23commonName_value = Junta
24
diff --git a/src/lib/libssl/test/CAssdsa.cnf b/src/lib/libssl/test/CAssdsa.cnf
deleted file mode 100644
index a6b4d1810c..0000000000
--- a/src/lib/libssl/test/CAssdsa.cnf
+++ /dev/null
@@ -1,23 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# hacked by iang to do DSA certs - CA
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Hermanos Locos
21
22commonName = Common Name (eg, YOUR name)
23commonName_value = Hermanos Locos CA
diff --git a/src/lib/libssl/test/CAssrsa.cnf b/src/lib/libssl/test/CAssrsa.cnf
deleted file mode 100644
index eb24a6dfc0..0000000000
--- a/src/lib/libssl/test/CAssrsa.cnf
+++ /dev/null
@@ -1,24 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# create RSA certs - CA
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Hermanos Locos
21
22commonName = Common Name (eg, YOUR name)
23commonName_value = Hermanos Locos CA
24
diff --git a/src/lib/libssl/test/CAtsa.cnf b/src/lib/libssl/test/CAtsa.cnf
deleted file mode 100644
index b497b50452..0000000000
--- a/src/lib/libssl/test/CAtsa.cnf
+++ /dev/null
@@ -1,163 +0,0 @@
1
2#
3# This config is used by the Time Stamp Authority tests.
4#
5
6RANDFILE = ./.rnd
7
8# Extra OBJECT IDENTIFIER info:
9oid_section = new_oids
10
11TSDNSECT = ts_cert_dn
12INDEX = 1
13
14[ new_oids ]
15
16# Policies used by the TSA tests.
17tsa_policy1 = 1.2.3.4.1
18tsa_policy2 = 1.2.3.4.5.6
19tsa_policy3 = 1.2.3.4.5.7
20
21#----------------------------------------------------------------------
22[ ca ]
23default_ca = CA_default # The default ca section
24
25[ CA_default ]
26
27dir = ./demoCA
28certs = $dir/certs # Where the issued certs are kept
29database = $dir/index.txt # database index file.
30new_certs_dir = $dir/newcerts # default place for new certs.
31
32certificate = $dir/cacert.pem # The CA certificate
33serial = $dir/serial # The current serial number
34private_key = $dir/private/cakey.pem# The private key
35RANDFILE = $dir/private/.rand # private random number file
36
37default_days = 365 # how long to certify for
38default_md = sha1 # which md to use.
39preserve = no # keep passed DN ordering
40
41policy = policy_match
42
43# For the CA policy
44[ policy_match ]
45countryName = supplied
46stateOrProvinceName = supplied
47organizationName = supplied
48organizationalUnitName = optional
49commonName = supplied
50emailAddress = optional
51
52#----------------------------------------------------------------------
53[ req ]
54default_bits = 1024
55default_md = sha1
56distinguished_name = $ENV::TSDNSECT
57encrypt_rsa_key = no
58prompt = no
59# attributes = req_attributes
60x509_extensions = v3_ca # The extensions to add to the self signed cert
61
62string_mask = nombstr
63
64[ ts_ca_dn ]
65countryName = HU
66stateOrProvinceName = Budapest
67localityName = Budapest
68organizationName = Gov-CA Ltd.
69commonName = ca1
70
71[ ts_cert_dn ]
72countryName = HU
73stateOrProvinceName = Budapest
74localityName = Buda
75organizationName = Hun-TSA Ltd.
76commonName = tsa$ENV::INDEX
77
78[ tsa_cert ]
79
80# TSA server cert is not a CA cert.
81basicConstraints=CA:FALSE
82
83# The following key usage flags are needed for TSA server certificates.
84keyUsage = nonRepudiation, digitalSignature
85extendedKeyUsage = critical,timeStamping
86
87# PKIX recommendations harmless if included in all certificates.
88subjectKeyIdentifier=hash
89authorityKeyIdentifier=keyid,issuer:always
90
91[ non_tsa_cert ]
92
93# This is not a CA cert and not a TSA cert, either (timeStamping usage missing)
94basicConstraints=CA:FALSE
95
96# The following key usage flags are needed for TSA server certificates.
97keyUsage = nonRepudiation, digitalSignature
98# timeStamping is not supported by this certificate
99# extendedKeyUsage = critical,timeStamping
100
101# PKIX recommendations harmless if included in all certificates.
102subjectKeyIdentifier=hash
103authorityKeyIdentifier=keyid,issuer:always
104
105[ v3_req ]
106
107# Extensions to add to a certificate request
108basicConstraints = CA:FALSE
109keyUsage = nonRepudiation, digitalSignature
110
111[ v3_ca ]
112
113# Extensions for a typical CA
114
115subjectKeyIdentifier=hash
116authorityKeyIdentifier=keyid:always,issuer:always
117basicConstraints = critical,CA:true
118keyUsage = cRLSign, keyCertSign
119
120#----------------------------------------------------------------------
121[ tsa ]
122
123default_tsa = tsa_config1 # the default TSA section
124
125[ tsa_config1 ]
126
127# These are used by the TSA reply generation only.
128dir = . # TSA root directory
129serial = $dir/tsa_serial # The current serial number (mandatory)
130signer_cert = $dir/tsa_cert1.pem # The TSA signing certificate
131 # (optional)
132certs = $dir/tsaca.pem # Certificate chain to include in reply
133 # (optional)
134signer_key = $dir/tsa_key1.pem # The TSA private key (optional)
135
136default_policy = tsa_policy1 # Policy if request did not specify it
137 # (optional)
138other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
139digests = md5, sha1 # Acceptable message digests (mandatory)
140accuracy = secs:1, millisecs:500, microsecs:100 # (optional)
141ordering = yes # Is ordering defined for timestamps?
142 # (optional, default: no)
143tsa_name = yes # Must the TSA name be included in the reply?
144 # (optional, default: no)
145ess_cert_id_chain = yes # Must the ESS cert id chain be included?
146 # (optional, default: no)
147
148[ tsa_config2 ]
149
150# This configuration uses a certificate which doesn't have timeStamping usage.
151# These are used by the TSA reply generation only.
152dir = . # TSA root directory
153serial = $dir/tsa_serial # The current serial number (mandatory)
154signer_cert = $dir/tsa_cert2.pem # The TSA signing certificate
155 # (optional)
156certs = $dir/demoCA/cacert.pem# Certificate chain to include in reply
157 # (optional)
158signer_key = $dir/tsa_key2.pem # The TSA private key (optional)
159
160default_policy = tsa_policy1 # Policy if request did not specify it
161 # (optional)
162other_policies = tsa_policy2, tsa_policy3 # acceptable policies (optional)
163digests = md5, sha1 # Acceptable message digests (mandatory)
diff --git a/src/lib/libssl/test/P1ss.cnf b/src/lib/libssl/test/P1ss.cnf
deleted file mode 100644
index 326cce2ba8..0000000000
--- a/src/lib/libssl/test/P1ss.cnf
+++ /dev/null
@@ -1,37 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 1024
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = md2
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2
29
302.commonName = Common Name (eg, YOUR name)
312.commonName_value = Proxy 1
32
33[ v3_proxy ]
34basicConstraints=CA:FALSE
35subjectKeyIdentifier=hash
36authorityKeyIdentifier=keyid,issuer:always
37proxyCertInfo=critical,language:id-ppl-anyLanguage,pathlen:1,policy:text:AB
diff --git a/src/lib/libssl/test/P2ss.cnf b/src/lib/libssl/test/P2ss.cnf
deleted file mode 100644
index 8b502321b8..0000000000
--- a/src/lib/libssl/test/P2ss.cnf
+++ /dev/null
@@ -1,45 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 1024
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = md2
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2
29
302.commonName = Common Name (eg, YOUR name)
312.commonName_value = Proxy 1
32
333.commonName = Common Name (eg, YOUR name)
343.commonName_value = Proxy 2
35
36[ v3_proxy ]
37basicConstraints=CA:FALSE
38subjectKeyIdentifier=hash
39authorityKeyIdentifier=keyid,issuer:always
40proxyCertInfo=critical,@proxy_ext
41
42[ proxy_ext ]
43language=id-ppl-anyLanguage
44pathlen=0
45policy=text:BC
diff --git a/src/lib/libssl/test/Sssdsa.cnf b/src/lib/libssl/test/Sssdsa.cnf
deleted file mode 100644
index 8e170a28ef..0000000000
--- a/src/lib/libssl/test/Sssdsa.cnf
+++ /dev/null
@@ -1,27 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# hacked by iang to do DSA certs - Server
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_rsa_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Tortilleras S.A.
21
220.commonName = Common Name (eg, YOUR name)
230.commonName_value = Torti
24
251.commonName = Common Name (eg, YOUR name)
261.commonName_value = Gordita
27
diff --git a/src/lib/libssl/test/Sssrsa.cnf b/src/lib/libssl/test/Sssrsa.cnf
deleted file mode 100644
index 8c79a03fca..0000000000
--- a/src/lib/libssl/test/Sssrsa.cnf
+++ /dev/null
@@ -1,26 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5# create RSA certs - Server
6
7RANDFILE = ./.rnd
8
9####################################################################
10[ req ]
11distinguished_name = req_distinguished_name
12encrypt_key = no
13
14[ req_distinguished_name ]
15countryName = Country Name (2 letter code)
16countryName_default = ES
17countryName_value = ES
18
19organizationName = Organization Name (eg, company)
20organizationName_value = Tortilleras S.A.
21
220.commonName = Common Name (eg, YOUR name)
230.commonName_value = Torti
24
251.commonName = Common Name (eg, YOUR name)
261.commonName_value = Gordita
diff --git a/src/lib/libssl/test/Uss.cnf b/src/lib/libssl/test/Uss.cnf
deleted file mode 100644
index 58ac0ca54d..0000000000
--- a/src/lib/libssl/test/Uss.cnf
+++ /dev/null
@@ -1,36 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ req ]
10default_bits = 2048
11default_keyfile = keySS.pem
12distinguished_name = req_distinguished_name
13encrypt_rsa_key = no
14default_md = sha256
15
16[ req_distinguished_name ]
17countryName = Country Name (2 letter code)
18countryName_default = AU
19countryName_value = AU
20
21organizationName = Organization Name (eg, company)
22organizationName_value = Dodgy Brothers
23
240.commonName = Common Name (eg, YOUR name)
250.commonName_value = Brother 1
26
271.commonName = Common Name (eg, YOUR name)
281.commonName_value = Brother 2
29
30[ v3_ee ]
31subjectKeyIdentifier=hash
32authorityKeyIdentifier=keyid,issuer:always
33basicConstraints = CA:false
34keyUsage = nonRepudiation, digitalSignature, keyEncipherment
35issuerAltName=issuer:copy
36
diff --git a/src/lib/libssl/test/VMSca-response.1 b/src/lib/libssl/test/VMSca-response.1
deleted file mode 100644
index 8b13789179..0000000000
--- a/src/lib/libssl/test/VMSca-response.1
+++ /dev/null
@@ -1 +0,0 @@
1
diff --git a/src/lib/libssl/test/VMSca-response.2 b/src/lib/libssl/test/VMSca-response.2
deleted file mode 100644
index 9b48ee4cf9..0000000000
--- a/src/lib/libssl/test/VMSca-response.2
+++ /dev/null
@@ -1,2 +0,0 @@
1y
2y
diff --git a/src/lib/libssl/test/bctest b/src/lib/libssl/test/bctest
deleted file mode 100644
index bdb3218f7a..0000000000
--- a/src/lib/libssl/test/bctest
+++ /dev/null
@@ -1,111 +0,0 @@
1#!/bin/sh
2
3# This script is used by test/Makefile.ssl to check whether a sane 'bc'
4# is installed.
5# ('make test_bn' should not try to run 'bc' if it does not exist or if
6# it is a broken 'bc' version that is known to cause trouble.)
7#
8# If 'bc' works, we also test if it knows the 'print' command.
9#
10# In any case, output an appropriate command line for running (or not
11# running) bc.
12
13
14IFS=:
15try_without_dir=true
16# First we try "bc", then "$dir/bc" for each item in $PATH.
17for dir in dummy:$PATH; do
18 if [ "$try_without_dir" = true ]; then
19 # first iteration
20 bc=bc
21 try_without_dir=false
22 else
23 # second and later iterations
24 bc="$dir/bc"
25 if [ ! -f "$bc" ]; then # '-x' is not available on Ultrix
26 bc=''
27 fi
28 fi
29
30 if [ ! "$bc" = '' ]; then
31 failure=none
32
33
34 # Test for SunOS 5.[78] bc bug
35 "$bc" >tmp.bctest <<\EOF
36obase=16
37ibase=16
38a=AD88C418F31B3FC712D0425001D522B3AE9134FF3A98C13C1FCC1682211195406C1A6C66C6A\
39CEEC1A0EC16950233F77F1C2F2363D56DD71A36C57E0B2511FC4BA8F22D261FE2E9356D99AF57\
4010F3817C0E05BF79C423C3F66FDF321BE8D3F18F625D91B670931C1EF25F28E489BDA1C5422D1\
41C3F6F7A1AD21585746ECC4F10A14A778AF56F08898E965E9909E965E0CB6F85B514150C644759\
423BE731877B16EA07B552088FF2EA728AC5E0FF3A23EB939304519AB8B60F2C33D6BA0945B66F0\
434FC3CADF855448B24A9D7640BCF473E
44b=DCE91E7D120B983EA9A104B5A96D634DD644C37657B1C7860B45E6838999B3DCE5A555583C6\
459209E41F413422954175A06E67FFEF6746DD652F0F48AEFECC3D8CAC13523BDAAD3F5AF4212BD\
468B3CD64126E1A82E190228020C05B91C8B141F1110086FC2A4C6ED631EBA129D04BB9A19FC53D\
473ED0E2017D60A68775B75481449
48(a/b)*b + (a%b) - a
49EOF
50 if [ 0 != "`cat tmp.bctest`" ]; then
51 failure=SunOStest
52 fi
53
54
55 if [ "$failure" = none ]; then
56 # Test for SCO bc bug.
57 "$bc" >tmp.bctest <<\EOF
58obase=16
59ibase=16
60-FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4AEC6F15AC177F176F2274D2\
619DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7F5ADFACEE54573F5D256A06\
6211B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99FB9812A0E4A5773D8B254117\
631239157EC6E3D8D50199 * -FFDD63BA1A4648F0D804F8A1C66C53F0D2110590E8A3907EC73B4\
64AEC6F15AC177F176F2274D29DC8022EA0D7DD3ABE9746D2D46DD3EA5B5F6F69DF12877E0AC5E7\
65F5ADFACEE54573F5D256A0611B5D2BC24947724E22AE4EC3FB0C39D9B4694A01AFE5E43B4D99F\
66B9812A0E4A5773D8B2541171239157EC6E3D8D50199 - FFBACC221682DA464B6D7F123482522\
6702EDAEDCA38C3B69E9B7BBCD6165A9CD8716C4903417F23C09A85B851961F92C217258CEEB866\
6885EFCC5DD131853A02C07A873B8E2AF2E40C6D5ED598CD0E8F35AD49F3C3A17FDB7653E4E2DC4\
69A8D23CC34686EE4AD01F7407A7CD74429AC6D36DBF0CB6A3E302D0E5BDFCD048A3B90C1BE5AA8\
70E16C3D5884F9136B43FF7BB443764153D4AEC176C681B078F4CC53D6EB6AB76285537DDEE7C18\
718C72441B52EDBDDBC77E02D34E513F2AABF92F44109CAFE8242BD0ECBAC5604A94B02EA44D43C\
7204E9476E6FBC48043916BFA1485C6093603600273C9C33F13114D78064AE42F3DC466C7DA543D\
7389C8D71
74AD534AFBED2FA39EE9F40E20FCF9E2C861024DB98DDCBA1CD118C49CA55EEBC20D6BA51B2271C\
75928B693D6A73F67FEB1B4571448588B46194617D25D910C6A9A130CC963155CF34079CB218A44\
768A1F57E276D92A33386DDCA3D241DB78C8974ABD71DD05B0FA555709C9910D745185E6FE108E3\
7737F1907D0C56F8BFBF52B9704 % -E557905B56B13441574CAFCE2BD257A750B1A8B2C88D0E36\
78E18EF7C38DAC80D3948E17ED63AFF3B3467866E3B89D09A81B3D16B52F6A3C7134D3C6F5123E9\
79F617E3145BBFBE9AFD0D6E437EA4FF6F04BC67C4F1458B4F0F47B64 - 1C2BBBB19B74E86FD32\
809E8DB6A8C3B1B9986D57ED5419C2E855F7D5469E35E76334BB42F4C43E3F3A31B9697C171DAC4\
81D97935A7E1A14AD209D6CF811F55C6DB83AA9E6DFECFCD6669DED7171EE22A40C6181615CAF3F\
825296964
83EOF
84 if [ "0
850" != "`cat tmp.bctest`" ]; then
86 failure=SCOtest
87 fi
88 fi
89
90
91 if [ "$failure" = none ]; then
92 # bc works; now check if it knows the 'print' command.
93 if [ "OK" = "`echo 'print \"OK\"' | $bc 2>/dev/null`" ]
94 then
95 echo "$bc"
96 else
97 echo "sed 's/print.*//' | $bc"
98 fi
99 exit 0
100 fi
101
102 echo "$bc does not work properly ('$failure' failed). Looking for another bc ..." >&2
103 fi
104done
105
106echo "No working bc found. Consider installing GNU bc." >&2
107if [ "$1" = ignore ]; then
108 echo "cat >/dev/null"
109 exit 0
110fi
111exit 1
diff --git a/src/lib/libssl/test/cms-examples.pl b/src/lib/libssl/test/cms-examples.pl
deleted file mode 100644
index 2e95b48ba4..0000000000
--- a/src/lib/libssl/test/cms-examples.pl
+++ /dev/null
@@ -1,409 +0,0 @@
1# test/cms-examples.pl
2# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3# project.
4#
5# ====================================================================
6# Copyright (c) 2008 The OpenSSL Project. All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11#
12# 1. Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer.
14#
15# 2. Redistributions in binary form must reproduce the above copyright
16# notice, this list of conditions and the following disclaimer in
17# the documentation and/or other materials provided with the
18# distribution.
19#
20# 3. All advertising materials mentioning features or use of this
21# software must display the following acknowledgment:
22# "This product includes software developed by the OpenSSL Project
23# for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24#
25# 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26# endorse or promote products derived from this software without
27# prior written permission. For written permission, please contact
28# licensing@OpenSSL.org.
29#
30# 5. Products derived from this software may not be called "OpenSSL"
31# nor may "OpenSSL" appear in their names without prior written
32# permission of the OpenSSL Project.
33#
34# 6. Redistributions of any form whatsoever must retain the following
35# acknowledgment:
36# "This product includes software developed by the OpenSSL Project
37# for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38#
39# THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50# OF THE POSSIBILITY OF SUCH DAMAGE.
51# ====================================================================
52
53# Perl script to run tests against S/MIME examples in RFC4134
54# Assumes RFC is in current directory and called "rfc4134.txt"
55
56use MIME::Base64;
57
58my $badttest = 0;
59my $verbose = 1;
60
61my $cmscmd;
62my $exdir = "./";
63my $exfile = "./rfc4134.txt";
64
65if (-f "../apps/openssl")
66 {
67 $cmscmd = "../util/shlib_wrap.sh ../apps/openssl cms";
68 }
69elsif (-f "..\\out32dll\\openssl.exe")
70 {
71 $cmscmd = "..\\out32dll\\openssl.exe cms";
72 }
73elsif (-f "..\\out32\\openssl.exe")
74 {
75 $cmscmd = "..\\out32\\openssl.exe cms";
76 }
77
78my @test_list = (
79 [ "3.1.bin" => "dataout" ],
80 [ "3.2.bin" => "encode, dataout" ],
81 [ "4.1.bin" => "encode, verifyder, cont, dss" ],
82 [ "4.2.bin" => "encode, verifyder, cont, rsa" ],
83 [ "4.3.bin" => "encode, verifyder, cont_extern, dss" ],
84 [ "4.4.bin" => "encode, verifyder, cont, dss" ],
85 [ "4.5.bin" => "verifyder, cont, rsa" ],
86 [ "4.6.bin" => "encode, verifyder, cont, dss" ],
87 [ "4.7.bin" => "encode, verifyder, cont, dss" ],
88 [ "4.8.eml" => "verifymime, dss" ],
89 [ "4.9.eml" => "verifymime, dss" ],
90 [ "4.10.bin" => "encode, verifyder, cont, dss" ],
91 [ "4.11.bin" => "encode, certsout" ],
92 [ "5.1.bin" => "encode, envelopeder, cont" ],
93 [ "5.2.bin" => "encode, envelopeder, cont" ],
94 [ "5.3.eml" => "envelopemime, cont" ],
95 [ "6.0.bin" => "encode, digest, cont" ],
96 [ "7.1.bin" => "encode, encrypted, cont" ],
97 [ "7.2.bin" => "encode, encrypted, cont" ]
98);
99
100# Extract examples from RFC4134 text.
101# Base64 decode all examples, certificates and
102# private keys are converted to PEM format.
103
104my ( $filename, $data );
105
106my @cleanup = ( "cms.out", "cms.err", "tmp.der", "tmp.txt" );
107
108$data = "";
109
110open( IN, $exfile ) || die "Can't Open RFC examples file $exfile";
111
112while (<IN>) {
113 next unless (/^\|/);
114 s/^\|//;
115 next if (/^\*/);
116 if (/^>(.*)$/) {
117 $filename = $1;
118 next;
119 }
120 if (/^</) {
121 $filename = "$exdir/$filename";
122 if ( $filename =~ /\.bin$/ || $filename =~ /\.eml$/ ) {
123 $data = decode_base64($data);
124 open OUT, ">$filename";
125 binmode OUT;
126 print OUT $data;
127 close OUT;
128 push @cleanup, $filename;
129 }
130 elsif ( $filename =~ /\.cer$/ ) {
131 write_pem( $filename, "CERTIFICATE", $data );
132 }
133 elsif ( $filename =~ /\.pri$/ ) {
134 write_pem( $filename, "PRIVATE KEY", $data );
135 }
136 $data = "";
137 $filename = "";
138 }
139 else {
140 $data .= $_;
141 }
142
143}
144
145my $secretkey =
146 "73:7c:79:1f:25:ea:d0:e0:46:29:25:43:52:f7:dc:62:91:e5:cb:26:91:7a:da:32";
147
148foreach (@test_list) {
149 my ( $file, $tlist ) = @$_;
150 print "Example file $file:\n";
151 if ( $tlist =~ /encode/ ) {
152 run_reencode_test( $exdir, $file );
153 }
154 if ( $tlist =~ /certsout/ ) {
155 run_certsout_test( $exdir, $file );
156 }
157 if ( $tlist =~ /dataout/ ) {
158 run_dataout_test( $exdir, $file );
159 }
160 if ( $tlist =~ /verify/ ) {
161 run_verify_test( $exdir, $tlist, $file );
162 }
163 if ( $tlist =~ /digest/ ) {
164 run_digest_test( $exdir, $tlist, $file );
165 }
166 if ( $tlist =~ /encrypted/ ) {
167 run_encrypted_test( $exdir, $tlist, $file, $secretkey );
168 }
169 if ( $tlist =~ /envelope/ ) {
170 run_envelope_test( $exdir, $tlist, $file );
171 }
172
173}
174
175foreach (@cleanup) {
176 unlink $_;
177}
178
179if ($badtest) {
180 print "\n$badtest TESTS FAILED!!\n";
181}
182else {
183 print "\n***All tests successful***\n";
184}
185
186sub write_pem {
187 my ( $filename, $str, $data ) = @_;
188
189 $filename =~ s/\.[^.]*$/.pem/;
190
191 push @cleanup, $filename;
192
193 open OUT, ">$filename";
194
195 print OUT "-----BEGIN $str-----\n";
196 print OUT $data;
197 print OUT "-----END $str-----\n";
198
199 close OUT;
200}
201
202sub run_reencode_test {
203 my ( $cmsdir, $tfile ) = @_;
204 unlink "tmp.der";
205
206 system( "$cmscmd -cmsout -inform DER -outform DER"
207 . " -in $cmsdir/$tfile -out tmp.der" );
208
209 if ($?) {
210 print "\tReencode command FAILED!!\n";
211 $badtest++;
212 }
213 elsif ( !cmp_files( "$cmsdir/$tfile", "tmp.der" ) ) {
214 print "\tReencode FAILED!!\n";
215 $badtest++;
216 }
217 else {
218 print "\tReencode passed\n" if $verbose;
219 }
220}
221
222sub run_certsout_test {
223 my ( $cmsdir, $tfile ) = @_;
224 unlink "tmp.der";
225 unlink "tmp.pem";
226
227 system( "$cmscmd -cmsout -inform DER -certsout tmp.pem"
228 . " -in $cmsdir/$tfile -out tmp.der" );
229
230 if ($?) {
231 print "\tCertificate output command FAILED!!\n";
232 $badtest++;
233 }
234 else {
235 print "\tCertificate output passed\n" if $verbose;
236 }
237}
238
239sub run_dataout_test {
240 my ( $cmsdir, $tfile ) = @_;
241 unlink "tmp.txt";
242
243 system(
244 "$cmscmd -data_out -inform DER" . " -in $cmsdir/$tfile -out tmp.txt" );
245
246 if ($?) {
247 print "\tDataout command FAILED!!\n";
248 $badtest++;
249 }
250 elsif ( !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) ) {
251 print "\tDataout compare FAILED!!\n";
252 $badtest++;
253 }
254 else {
255 print "\tDataout passed\n" if $verbose;
256 }
257}
258
259sub run_verify_test {
260 my ( $cmsdir, $tlist, $tfile ) = @_;
261 unlink "tmp.txt";
262
263 $form = "DER" if $tlist =~ /verifyder/;
264 $form = "SMIME" if $tlist =~ /verifymime/;
265 $cafile = "$cmsdir/CarlDSSSelf.pem" if $tlist =~ /dss/;
266 $cafile = "$cmsdir/CarlRSASelf.pem" if $tlist =~ /rsa/;
267
268 $cmd =
269 "$cmscmd -verify -inform $form"
270 . " -CAfile $cafile"
271 . " -in $cmsdir/$tfile -out tmp.txt";
272
273 $cmd .= " -content $cmsdir/ExContent.bin" if $tlist =~ /cont_extern/;
274
275 system("$cmd 2>cms.err 1>cms.out");
276
277 if ($?) {
278 print "\tVerify command FAILED!!\n";
279 $badtest++;
280 }
281 elsif ( $tlist =~ /cont/
282 && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
283 {
284 print "\tVerify content compare FAILED!!\n";
285 $badtest++;
286 }
287 else {
288 print "\tVerify passed\n" if $verbose;
289 }
290}
291
292sub run_envelope_test {
293 my ( $cmsdir, $tlist, $tfile ) = @_;
294 unlink "tmp.txt";
295
296 $form = "DER" if $tlist =~ /envelopeder/;
297 $form = "SMIME" if $tlist =~ /envelopemime/;
298
299 $cmd =
300 "$cmscmd -decrypt -inform $form"
301 . " -recip $cmsdir/BobRSASignByCarl.pem"
302 . " -inkey $cmsdir/BobPrivRSAEncrypt.pem"
303 . " -in $cmsdir/$tfile -out tmp.txt";
304
305 system("$cmd 2>cms.err 1>cms.out");
306
307 if ($?) {
308 print "\tDecrypt command FAILED!!\n";
309 $badtest++;
310 }
311 elsif ( $tlist =~ /cont/
312 && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
313 {
314 print "\tDecrypt content compare FAILED!!\n";
315 $badtest++;
316 }
317 else {
318 print "\tDecrypt passed\n" if $verbose;
319 }
320}
321
322sub run_digest_test {
323 my ( $cmsdir, $tlist, $tfile ) = @_;
324 unlink "tmp.txt";
325
326 my $cmd =
327 "$cmscmd -digest_verify -inform DER" . " -in $cmsdir/$tfile -out tmp.txt";
328
329 system("$cmd 2>cms.err 1>cms.out");
330
331 if ($?) {
332 print "\tDigest verify command FAILED!!\n";
333 $badtest++;
334 }
335 elsif ( $tlist =~ /cont/
336 && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
337 {
338 print "\tDigest verify content compare FAILED!!\n";
339 $badtest++;
340 }
341 else {
342 print "\tDigest verify passed\n" if $verbose;
343 }
344}
345
346sub run_encrypted_test {
347 my ( $cmsdir, $tlist, $tfile, $key ) = @_;
348 unlink "tmp.txt";
349
350 system( "$cmscmd -EncryptedData_decrypt -inform DER"
351 . " -secretkey $key"
352 . " -in $cmsdir/$tfile -out tmp.txt" );
353
354 if ($?) {
355 print "\tEncrypted Data command FAILED!!\n";
356 $badtest++;
357 }
358 elsif ( $tlist =~ /cont/
359 && !cmp_files( "$cmsdir/ExContent.bin", "tmp.txt" ) )
360 {
361 print "\tEncrypted Data content compare FAILED!!\n";
362 $badtest++;
363 }
364 else {
365 print "\tEncryptedData verify passed\n" if $verbose;
366 }
367}
368
369sub cmp_files {
370 my ( $f1, $f2 ) = @_;
371 my ( $fp1, $fp2 );
372
373 my ( $rd1, $rd2 );
374
375 if ( !open( $fp1, "<$f1" ) ) {
376 print STDERR "Can't Open file $f1\n";
377 return 0;
378 }
379
380 if ( !open( $fp2, "<$f2" ) ) {
381 print STDERR "Can't Open file $f2\n";
382 return 0;
383 }
384
385 binmode $fp1;
386 binmode $fp2;
387
388 my $ret = 0;
389
390 for ( ; ; ) {
391 $n1 = sysread $fp1, $rd1, 4096;
392 $n2 = sysread $fp2, $rd2, 4096;
393 last if ( $n1 != $n2 );
394 last if ( $rd1 ne $rd2 );
395
396 if ( $n1 == 0 ) {
397 $ret = 1;
398 last;
399 }
400
401 }
402
403 close $fp1;
404 close $fp2;
405
406 return $ret;
407
408}
409
diff --git a/src/lib/libssl/test/cms-test.pl b/src/lib/libssl/test/cms-test.pl
deleted file mode 100644
index dfef799be2..0000000000
--- a/src/lib/libssl/test/cms-test.pl
+++ /dev/null
@@ -1,459 +0,0 @@
1# test/cms-test.pl
2# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3# project.
4#
5# ====================================================================
6# Copyright (c) 2008 The OpenSSL Project. All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11#
12# 1. Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer.
14#
15# 2. Redistributions in binary form must reproduce the above copyright
16# notice, this list of conditions and the following disclaimer in
17# the documentation and/or other materials provided with the
18# distribution.
19#
20# 3. All advertising materials mentioning features or use of this
21# software must display the following acknowledgment:
22# "This product includes software developed by the OpenSSL Project
23# for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24#
25# 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26# endorse or promote products derived from this software without
27# prior written permission. For written permission, please contact
28# licensing@OpenSSL.org.
29#
30# 5. Products derived from this software may not be called "OpenSSL"
31# nor may "OpenSSL" appear in their names without prior written
32# permission of the OpenSSL Project.
33#
34# 6. Redistributions of any form whatsoever must retain the following
35# acknowledgment:
36# "This product includes software developed by the OpenSSL Project
37# for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38#
39# THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50# OF THE POSSIBILITY OF SUCH DAMAGE.
51# ====================================================================
52
53# CMS, PKCS7 consistency test script. Run extensive tests on
54# OpenSSL PKCS#7 and CMS implementations.
55
56my $ossl_path;
57my $redir = " 2> cms.err > cms.out";
58# Make VMS work
59if ( $^O eq "VMS" && -f "OSSLX:openssl.exe" ) {
60 $ossl_path = "pipe mcr OSSLX:openssl";
61}
62# Make MSYS work
63elsif ( $^O eq "MSWin32" && -f "../apps/openssl.exe" ) {
64 $ossl_path = "cmd /c ..\\apps\\openssl";
65}
66elsif ( -f "../apps/openssl$ENV{EXE_EXT}" ) {
67 $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
68}
69elsif ( -f "..\\out32dll\\openssl.exe" ) {
70 $ossl_path = "..\\out32dll\\openssl.exe";
71}
72elsif ( -f "..\\out32\\openssl.exe" ) {
73 $ossl_path = "..\\out32\\openssl.exe";
74}
75else {
76 die "Can't find OpenSSL executable";
77}
78
79my $pk7cmd = "$ossl_path smime ";
80my $cmscmd = "$ossl_path cms ";
81my $smdir = "smime-certs";
82my $halt_err = 1;
83
84my $badcmd = 0;
85my $ossl8 = `$ossl_path version -v` =~ /0\.9\.8/;
86
87my @smime_pkcs7_tests = (
88
89 [
90 "signed content DER format, RSA key",
91 "-sign -in smcont.txt -outform \"DER\" -nodetach"
92 . " -certfile $smdir/smroot.pem"
93 . " -signer $smdir/smrsa1.pem -out test.cms",
94 "-verify -in test.cms -inform \"DER\" "
95 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
96 ],
97
98 [
99 "signed detached content DER format, RSA key",
100 "-sign -in smcont.txt -outform \"DER\""
101 . " -signer $smdir/smrsa1.pem -out test.cms",
102 "-verify -in test.cms -inform \"DER\" "
103 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
104 ],
105
106 [
107 "signed content test streaming BER format, RSA",
108 "-sign -in smcont.txt -outform \"DER\" -nodetach"
109 . " -stream -signer $smdir/smrsa1.pem -out test.cms",
110 "-verify -in test.cms -inform \"DER\" "
111 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
112 ],
113
114 [
115 "signed content DER format, DSA key",
116 "-sign -in smcont.txt -outform \"DER\" -nodetach"
117 . " -signer $smdir/smdsa1.pem -out test.cms",
118 "-verify -in test.cms -inform \"DER\" "
119 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
120 ],
121
122 [
123 "signed detached content DER format, DSA key",
124 "-sign -in smcont.txt -outform \"DER\""
125 . " -signer $smdir/smdsa1.pem -out test.cms",
126 "-verify -in test.cms -inform \"DER\" "
127 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
128 ],
129
130 [
131 "signed detached content DER format, add RSA signer",
132 "-resign -inform \"DER\" -in test.cms -outform \"DER\""
133 . " -signer $smdir/smrsa1.pem -out test2.cms",
134 "-verify -in test2.cms -inform \"DER\" "
135 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt -content smcont.txt"
136 ],
137
138 [
139 "signed content test streaming BER format, DSA key",
140 "-sign -in smcont.txt -outform \"DER\" -nodetach"
141 . " -stream -signer $smdir/smdsa1.pem -out test.cms",
142 "-verify -in test.cms -inform \"DER\" "
143 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
144 ],
145
146 [
147 "signed content test streaming BER format, 2 DSA and 2 RSA keys",
148 "-sign -in smcont.txt -outform \"DER\" -nodetach"
149 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
150 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
151 . " -stream -out test.cms",
152 "-verify -in test.cms -inform \"DER\" "
153 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
154 ],
155
156 [
157"signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes",
158 "-sign -in smcont.txt -outform \"DER\" -noattr -nodetach"
159 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
160 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
161 . " -stream -out test.cms",
162 "-verify -in test.cms -inform \"DER\" "
163 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
164 ],
165
166 [
167 "signed content test streaming S/MIME format, 2 DSA and 2 RSA keys",
168 "-sign -in smcont.txt -nodetach"
169 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
170 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
171 . " -stream -out test.cms",
172 "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
173 ],
174
175 [
176"signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys",
177 "-sign -in smcont.txt"
178 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
179 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
180 . " -stream -out test.cms",
181 "-verify -in test.cms " . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
182 ],
183
184 [
185 "enveloped content test streaming S/MIME format, 3 recipients",
186 "-encrypt -in smcont.txt"
187 . " -stream -out test.cms"
188 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
189 "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
190 ],
191
192 [
193"enveloped content test streaming S/MIME format, 3 recipients, 3rd used",
194 "-encrypt -in smcont.txt"
195 . " -stream -out test.cms"
196 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
197 "-decrypt -recip $smdir/smrsa3.pem -in test.cms -out smtst.txt"
198 ],
199
200 [
201"enveloped content test streaming S/MIME format, 3 recipients, key only used",
202 "-encrypt -in smcont.txt"
203 . " -stream -out test.cms"
204 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
205 "-decrypt -inkey $smdir/smrsa3.pem -in test.cms -out smtst.txt"
206 ],
207
208 [
209"enveloped content test streaming S/MIME format, AES-256 cipher, 3 recipients",
210 "-encrypt -in smcont.txt"
211 . " -aes256 -stream -out test.cms"
212 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
213 "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
214 ],
215
216);
217
218my @smime_cms_tests = (
219
220 [
221 "signed content test streaming BER format, 2 DSA and 2 RSA keys, keyid",
222 "-sign -in smcont.txt -outform \"DER\" -nodetach -keyid"
223 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
224 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
225 . " -stream -out test.cms",
226 "-verify -in test.cms -inform \"DER\" "
227 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
228 ],
229
230 [
231 "signed content test streaming PEM format, 2 DSA and 2 RSA keys",
232 "-sign -in smcont.txt -outform PEM -nodetach"
233 . " -signer $smdir/smrsa1.pem -signer $smdir/smrsa2.pem"
234 . " -signer $smdir/smdsa1.pem -signer $smdir/smdsa2.pem"
235 . " -stream -out test.cms",
236 "-verify -in test.cms -inform PEM "
237 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
238 ],
239
240 [
241 "signed content MIME format, RSA key, signed receipt request",
242 "-sign -in smcont.txt -signer $smdir/smrsa1.pem -nodetach"
243 . " -receipt_request_to test\@openssl.org -receipt_request_all"
244 . " -out test.cms",
245 "-verify -in test.cms "
246 . " \"-CAfile\" $smdir/smroot.pem -out smtst.txt"
247 ],
248
249 [
250 "signed receipt MIME format, RSA key",
251 "-sign_receipt -in test.cms"
252 . " -signer $smdir/smrsa2.pem"
253 . " -out test2.cms",
254 "-verify_receipt test2.cms -in test.cms"
255 . " \"-CAfile\" $smdir/smroot.pem"
256 ],
257
258 [
259 "enveloped content test streaming S/MIME format, 3 recipients, keyid",
260 "-encrypt -in smcont.txt"
261 . " -stream -out test.cms -keyid"
262 . " $smdir/smrsa1.pem $smdir/smrsa2.pem $smdir/smrsa3.pem ",
263 "-decrypt -recip $smdir/smrsa1.pem -in test.cms -out smtst.txt"
264 ],
265
266 [
267 "enveloped content test streaming PEM format, KEK",
268 "-encrypt -in smcont.txt -outform PEM -aes128"
269 . " -stream -out test.cms "
270 . " -secretkey 000102030405060708090A0B0C0D0E0F "
271 . " -secretkeyid C0FEE0",
272 "-decrypt -in test.cms -out smtst.txt -inform PEM"
273 . " -secretkey 000102030405060708090A0B0C0D0E0F "
274 . " -secretkeyid C0FEE0"
275 ],
276
277 [
278 "enveloped content test streaming PEM format, KEK, key only",
279 "-encrypt -in smcont.txt -outform PEM -aes128"
280 . " -stream -out test.cms "
281 . " -secretkey 000102030405060708090A0B0C0D0E0F "
282 . " -secretkeyid C0FEE0",
283 "-decrypt -in test.cms -out smtst.txt -inform PEM"
284 . " -secretkey 000102030405060708090A0B0C0D0E0F "
285 ],
286
287 [
288 "data content test streaming PEM format",
289 "-data_create -in smcont.txt -outform PEM -nodetach"
290 . " -stream -out test.cms",
291 "-data_out -in test.cms -inform PEM -out smtst.txt"
292 ],
293
294 [
295 "encrypted content test streaming PEM format, 128 bit RC2 key",
296 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
297 . " -rc2 -secretkey 000102030405060708090A0B0C0D0E0F"
298 . " -stream -out test.cms",
299 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
300 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
301 ],
302
303 [
304 "encrypted content test streaming PEM format, 40 bit RC2 key",
305 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
306 . " -rc2 -secretkey 0001020304"
307 . " -stream -out test.cms",
308 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
309 . " -secretkey 0001020304 -out smtst.txt"
310 ],
311
312 [
313 "encrypted content test streaming PEM format, triple DES key",
314 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
315 . " -des3 -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
316 . " -stream -out test.cms",
317 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
318 . " -secretkey 000102030405060708090A0B0C0D0E0F1011121314151617"
319 . " -out smtst.txt"
320 ],
321
322 [
323 "encrypted content test streaming PEM format, 128 bit AES key",
324 "\"-EncryptedData_encrypt\" -in smcont.txt -outform PEM"
325 . " -aes128 -secretkey 000102030405060708090A0B0C0D0E0F"
326 . " -stream -out test.cms",
327 "\"-EncryptedData_decrypt\" -in test.cms -inform PEM "
328 . " -secretkey 000102030405060708090A0B0C0D0E0F -out smtst.txt"
329 ],
330
331);
332
333my @smime_cms_comp_tests = (
334
335 [
336 "compressed content test streaming PEM format",
337 "-compress -in smcont.txt -outform PEM -nodetach"
338 . " -stream -out test.cms",
339 "-uncompress -in test.cms -inform PEM -out smtst.txt"
340 ]
341
342);
343
344print "CMS => PKCS#7 compatibility tests\n";
345
346run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $pk7cmd );
347
348print "CMS <= PKCS#7 compatibility tests\n";
349
350run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $pk7cmd, $cmscmd );
351
352print "CMS <=> CMS consistency tests\n";
353
354run_smime_tests( \$badcmd, \@smime_pkcs7_tests, $cmscmd, $cmscmd );
355run_smime_tests( \$badcmd, \@smime_cms_tests, $cmscmd, $cmscmd );
356
357if ( `$ossl_path version -f` =~ /ZLIB/ ) {
358 run_smime_tests( \$badcmd, \@smime_cms_comp_tests, $cmscmd, $cmscmd );
359}
360else {
361 print "Zlib not supported: compression tests skipped\n";
362}
363
364print "Running modified tests for OpenSSL 0.9.8 cms backport\n" if($ossl8);
365
366if ($badcmd) {
367 print "$badcmd TESTS FAILED!!\n";
368}
369else {
370 print "ALL TESTS SUCCESSFUL.\n";
371}
372
373unlink "test.cms";
374unlink "test2.cms";
375unlink "smtst.txt";
376unlink "cms.out";
377unlink "cms.err";
378
379sub run_smime_tests {
380 my ( $rv, $aref, $scmd, $vcmd ) = @_;
381
382 foreach $smtst (@$aref) {
383 my ( $tnam, $rscmd, $rvcmd ) = @$smtst;
384 if ($ossl8)
385 {
386 # Skip smime resign: 0.9.8 smime doesn't support -resign
387 next if ($scmd =~ /smime/ && $rscmd =~ /-resign/);
388 # Disable streaming: option not supported in 0.9.8
389 $tnam =~ s/streaming//;
390 $rscmd =~ s/-stream//;
391 $rvcmd =~ s/-stream//;
392 }
393 system("$scmd$rscmd$redir");
394 if ($?) {
395 print "$tnam: generation error\n";
396 $$rv++;
397 exit 1 if $halt_err;
398 next;
399 }
400 system("$vcmd$rvcmd$redir");
401 if ($?) {
402 print "$tnam: verify error\n";
403 $$rv++;
404 exit 1 if $halt_err;
405 next;
406 }
407 if (!cmp_files("smtst.txt", "smcont.txt")) {
408 print "$tnam: content verify error\n";
409 $$rv++;
410 exit 1 if $halt_err;
411 next;
412 }
413 print "$tnam: OK\n";
414 }
415}
416
417sub cmp_files {
418 use FileHandle;
419 my ( $f1, $f2 ) = @_;
420 my $fp1 = FileHandle->new();
421 my $fp2 = FileHandle->new();
422
423 my ( $rd1, $rd2 );
424
425 if ( !open( $fp1, "<$f1" ) ) {
426 print STDERR "Can't Open file $f1\n";
427 return 0;
428 }
429
430 if ( !open( $fp2, "<$f2" ) ) {
431 print STDERR "Can't Open file $f2\n";
432 return 0;
433 }
434
435 binmode $fp1;
436 binmode $fp2;
437
438 my $ret = 0;
439
440 for ( ; ; ) {
441 $n1 = sysread $fp1, $rd1, 4096;
442 $n2 = sysread $fp2, $rd2, 4096;
443 last if ( $n1 != $n2 );
444 last if ( $rd1 ne $rd2 );
445
446 if ( $n1 == 0 ) {
447 $ret = 1;
448 last;
449 }
450
451 }
452
453 close $fp1;
454 close $fp2;
455
456 return $ret;
457
458}
459
diff --git a/src/lib/libssl/test/pkcs7-1.pem b/src/lib/libssl/test/pkcs7-1.pem
deleted file mode 100644
index c47b27af88..0000000000
--- a/src/lib/libssl/test/pkcs7-1.pem
+++ /dev/null
@@ -1,15 +0,0 @@
1-----BEGIN PKCS7-----
2MIICUAYJKoZIhvcNAQcCoIICQTCCAj0CAQExDjAMBggqhkiG9w0CAgUAMCgGCSqG
3SIb3DQEHAaAbBBlFdmVyeW9uZSBnZXRzIEZyaWRheSBvZmYuoIIBXjCCAVowggEE
4AgQUAAApMA0GCSqGSIb3DQEBAgUAMCwxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRF
5eGFtcGxlIE9yZ2FuaXphdGlvbjAeFw05MjA5MDkyMjE4MDZaFw05NDA5MDkyMjE4
6MDVaMEIxCzAJBgNVBAYTAlVTMR0wGwYDVQQKExRFeGFtcGxlIE9yZ2FuaXphdGlv
7bjEUMBIGA1UEAxMLVGVzdCBVc2VyIDEwWzANBgkqhkiG9w0BAQEFAANKADBHAkAK
8ZnkdxpiBaN56t3QZu3+wwAHGJxAnAHUUKULhmo2MUdBTs+N4Kh3l3Fr06+mUaBcB
9FKHf5nzcmpr1XWVWILurAgMBAAEwDQYJKoZIhvcNAQECBQADQQBFGqHhqncgSl/N
109XYGnQL3MsJvNnsNV4puZPOakR9Hld8JlDQFEaDR30ogsmp3TMrvdfxpLlTCoZN8
11BxEmnZsWMYGbMIGYAgEBMDQwLDELMAkGA1UEBhMCVVMxHTAbBgNVBAoTFEV4YW1w
12bGUgT3JnYW5pemF0aW9uAgQUAAApMAwGCCqGSIb3DQICBQAwDQYJKoZIhvcNAQEB
13BQAEQAX6aoEvx9+L9PJUJQngPoRuEbnGIL4gCe+0QO+8xmkhaZSsBPNBtX0FIC1C
14j7Kie1x339mxW/w9VZNTUDQQweHh
15-----END PKCS7-----
diff --git a/src/lib/libssl/test/pkcs7.pem b/src/lib/libssl/test/pkcs7.pem
deleted file mode 100644
index d55c60b94e..0000000000
--- a/src/lib/libssl/test/pkcs7.pem
+++ /dev/null
@@ -1,54 +0,0 @@
1 MIAGCSqGSIb3DQEHAqCAMIACAQExADCABgkqhkiG9w0BBwEAAKCAMIIE+DCCBGGg
2 AwIBAgIQaGSF/JpbS1C223+yrc+N1DANBgkqhkiG9w0BAQQFADBiMREwDwYDVQQH
3 EwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1Zl
4 cmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIwHhcNOTYw
5 ODEyMDAwMDAwWhcNOTYwODE3MjM1OTU5WjCCASAxETAPBgNVBAcTCEludGVybmV0
6 MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNpZ24gQ2xh
7 c3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjE3MDUGA1UECxMuRGlnaXRh
8 bCBJRCBDbGFzcyAxIC0gU01JTUUgVmVyaVNpZ24sIEluYy4gVEVTVDFGMEQGA1UE
9 CxM9d3d3LnZlcmlzaWduLmNvbS9yZXBvc2l0b3J5L0NQUyBJbmNvcnAuIGJ5IFJl
10 Zi4sTElBQi5MVEQoYyk5NjEZMBcGA1UEAxMQQWxleGFuZHJlIERlYWNvbjEgMB4G
11 CSqGSIb3DQEJARYRYWxleEB2ZXJpc2lnbi5jb20wWzANBgkqhkiG9w0BAQEFAANK
12 ADBHAkAOy7xxCAIkOfuIA2LyRpxgKlDORl8htdXYhF5iBGUx1GYaK6KF+bK/CCI0
13 l4j2OfWGFBUrwGoWqxTNcWgTfMzRAgMBAAGjggIyMIICLjAJBgNVHRMEAjAAMIIC
14 HwYDVR0DBIICFjCCAhIwggIOMIICCgYLYIZIAYb4RQEHAQEwggH5FoIBp1RoaXMg
15 Y2VydGlmaWNhdGUgaW5jb3Jwb3JhdGVzIGJ5IHJlZmVyZW5jZSwgYW5kIGl0cyB1
16 c2UgaXMgc3RyaWN0bHkgc3ViamVjdCB0bywgdGhlIFZlcmlTaWduIENlcnRpZmlj
17 YXRpb24gUHJhY3RpY2UgU3RhdGVtZW50IChDUFMpLCBhdmFpbGFibGUgYXQ6IGh0
18 dHBzOi8vd3d3LnZlcmlzaWduLmNvbS9DUFM7IGJ5IEUtbWFpbCBhdCBDUFMtcmVx
19 dWVzdHNAdmVyaXNpZ24uY29tOyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMu
20 LCAyNTkzIENvYXN0IEF2ZS4sIE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBU
21 ZWwuICsxICg0MTUpIDk2MS04ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2ln
22 biwgSW5jLiAgQWxsIFJpZ2h0cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVT
23 IERJU0NMQUlNRUQgYW5kIExJQUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcB
24 AQGhDgYMYIZIAYb4RQEHAQECMCwwKhYoaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
25 L3JlcG9zaXRvcnkvQ1BTIDANBgkqhkiG9w0BAQQFAAOBgQAimWMGQwwwxk+b3KAL
26 HlSWXtU7LWHe29CEG8XeVNTvrqs6SBqT7OoENOkGxpfdpVgZ3Qw2SKjxDvbvpfSF
27 slsqcxWSgB/hWuaVuZCkvTw/dYGGOxkTJGxvDCfl1PZjX4dKbatslsi9Z9HpGWT7
28 ttItRwKqcBKgmCJvKi1pGWED0zCCAnkwggHioAMCAQICEDURpVKQb+fQKaRAGdQR
29 /D4wDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlT
30 aWduLCBJbmMuMTcwNQYDVQQLEy5DbGFzcyAxIFB1YmxpYyBQcmltYXJ5IENlcnRp
31 ZmljYXRpb24gQXV0aG9yaXR5MB4XDTk2MDYyNzAwMDAwMFoXDTk3MDYyNzIzNTk1
32 OVowYjERMA8GA1UEBxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMu
33 MTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJz
34 Y3JpYmVyMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2FKbPTdAFDdjKI9Bv
35 qrQpkmOOLPhvltcunXZLEbE2jVfJw/0cxrr+Hgi6M8qV6r7jW80GqLd5HUQq7XPy
36 sVKDaBBwZJHXPmv5912dFEObbpdFmIFH0S3L3bty10w/cariQPJUObwW7s987Lrb
37 P2wqsxaxhhKdrpM01bjV0Pc+qQIDAQABozMwMTAPBgNVHRMECDAGAQH/AgEBMAsG
38 A1UdDwQEAwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADgYEA
39 KeXHoBmnbxRCgk0jM9e9mDppdxpsipIna/J8DOHEUuD4nONAr4+xOg73SBl026n7
40 Bk55A2wvAMGo7+kKTZ+rHaFDDcmq4O+rzFri2RIOeGAncj1IcGptAQhvXoIhFMG4
41 Jlzg1KlHZHqy7D3jex78zcSU7kKOu8f5tAX1jC3+sToAAKGAMIIBJzCBkTANBgkq
42 hkiG9w0BAQIFADBiMREwDwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNp
43 Z24sIEluYy4xNDAyBgNVBAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlk
44 dWFsIFN1YnNjcmliZXIXDTk2MDcwMTE3MzA0MFoXDTk3MDcwMTAwMDAwMFowDQYJ
45 KoZIhvcNAQECBQADgYEAGLuQ6PX8A7AiqBEtWzYtl6lZNSDI0bR5YUo+D2Jzkw30
46 dxQnJSbKXEc6XYuzAW5HvrzATXu5c19WWPT4cRDwmjH71i9QcDysWwf/wE0qGTiW
47 I3tQT0I5VGh7jIJD07nlBw3R4Xl8dH9kr85JsWinqDH5YKpIo9o8knY5n7+qjOow
48 ggEkMIGOMA0GCSqGSIb3DQEBAgUAMF8xCzAJBgNVBAYTAlVTMRcwFQYDVQQKEw5W
49 ZXJpU2lnbiwgSW5jLjE3MDUGA1UECxMuQ2xhc3MgMSBQdWJsaWMgUHJpbWFyeSBD
50 ZXJ0aWZpY2F0aW9uIEF1dGhvcml0eRcNOTYwNzE2MjMxMTI5WhcNOTYwODE1MDAw
51 MDAwWjANBgkqhkiG9w0BAQIFAAOBgQAXsLE4vnsY6sY67QrmWec7iaU2ehzxanEK
52 /9wKHZNuhlNzk+qGZZw2evxfUe2OaRbYpl8zuZvhK9BHD3ad14OSe9/zx5hOPgP/
53 DQXt6R4R8Q/1JheBrolrgbavjvI2wKS8/Psp2prBrkF4T48+AKRmS8Zzh1guxgvP
54 b+xSu/jH0gAAMYAAAAAAAAAAAA==
diff --git a/src/lib/libssl/test/pkits-test.pl b/src/lib/libssl/test/pkits-test.pl
deleted file mode 100644
index f10da008c0..0000000000
--- a/src/lib/libssl/test/pkits-test.pl
+++ /dev/null
@@ -1,949 +0,0 @@
1# test/pkits-test.pl
2# Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3# project.
4#
5# ====================================================================
6# Copyright (c) 2008 The OpenSSL Project. All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11#
12# 1. Redistributions of source code must retain the above copyright
13# notice, this list of conditions and the following disclaimer.
14#
15# 2. Redistributions in binary form must reproduce the above copyright
16# notice, this list of conditions and the following disclaimer in
17# the documentation and/or other materials provided with the
18# distribution.
19#
20# 3. All advertising materials mentioning features or use of this
21# software must display the following acknowledgment:
22# "This product includes software developed by the OpenSSL Project
23# for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24#
25# 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26# endorse or promote products derived from this software without
27# prior written permission. For written permission, please contact
28# licensing@OpenSSL.org.
29#
30# 5. Products derived from this software may not be called "OpenSSL"
31# nor may "OpenSSL" appear in their names without prior written
32# permission of the OpenSSL Project.
33#
34# 6. Redistributions of any form whatsoever must retain the following
35# acknowledgment:
36# "This product includes software developed by the OpenSSL Project
37# for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38#
39# THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40# EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43# ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50# OF THE POSSIBILITY OF SUCH DAMAGE.
51# ====================================================================
52
53# Perl utility to run PKITS tests for RFC3280 compliance.
54
55my $ossl_path;
56
57if ( -f "../apps/openssl" ) {
58 $ossl_path = "../util/shlib_wrap.sh ../apps/openssl";
59}
60elsif ( -f "..\\out32dll\\openssl.exe" ) {
61 $ossl_path = "..\\out32dll\\openssl.exe";
62}
63elsif ( -f "..\\out32\\openssl.exe" ) {
64 $ossl_path = "..\\out32\\openssl.exe";
65}
66else {
67 die "Can't find OpenSSL executable";
68}
69
70my $pkitsdir = "pkits/smime";
71my $pkitsta = "pkits/certs/TrustAnchorRootCertificate.crt";
72
73die "Can't find PKITS test data" if !-d $pkitsdir;
74
75my $nist1 = "2.16.840.1.101.3.2.1.48.1";
76my $nist2 = "2.16.840.1.101.3.2.1.48.2";
77my $nist3 = "2.16.840.1.101.3.2.1.48.3";
78my $nist4 = "2.16.840.1.101.3.2.1.48.4";
79my $nist5 = "2.16.840.1.101.3.2.1.48.5";
80my $nist6 = "2.16.840.1.101.3.2.1.48.6";
81
82my $apolicy = "X509v3 Any Policy";
83
84# This table contains the chapter headings of the accompanying PKITS
85# document. They provide useful informational output and their names
86# can be converted into the filename to test.
87
88my @testlists = (
89 [ "4.1", "Signature Verification" ],
90 [ "4.1.1", "Valid Signatures Test1", 0 ],
91 [ "4.1.2", "Invalid CA Signature Test2", 7 ],
92 [ "4.1.3", "Invalid EE Signature Test3", 7 ],
93 [ "4.1.4", "Valid DSA Signatures Test4", 0 ],
94 [ "4.1.5", "Valid DSA Parameter Inheritance Test5", 0 ],
95 [ "4.1.6", "Invalid DSA Signature Test6", 7 ],
96 [ "4.2", "Validity Periods" ],
97 [ "4.2.1", "Invalid CA notBefore Date Test1", 9 ],
98 [ "4.2.2", "Invalid EE notBefore Date Test2", 9 ],
99 [ "4.2.3", "Valid pre2000 UTC notBefore Date Test3", 0 ],
100 [ "4.2.4", "Valid GeneralizedTime notBefore Date Test4", 0 ],
101 [ "4.2.5", "Invalid CA notAfter Date Test5", 10 ],
102 [ "4.2.6", "Invalid EE notAfter Date Test6", 10 ],
103 [ "4.2.7", "Invalid pre2000 UTC EE notAfter Date Test7", 10 ],
104 [ "4.2.8", "Valid GeneralizedTime notAfter Date Test8", 0 ],
105 [ "4.3", "Verifying Name Chaining" ],
106 [ "4.3.1", "Invalid Name Chaining EE Test1", 20 ],
107 [ "4.3.2", "Invalid Name Chaining Order Test2", 20 ],
108 [ "4.3.3", "Valid Name Chaining Whitespace Test3", 0 ],
109 [ "4.3.4", "Valid Name Chaining Whitespace Test4", 0 ],
110 [ "4.3.5", "Valid Name Chaining Capitalization Test5", 0 ],
111 [ "4.3.6", "Valid Name Chaining UIDs Test6", 0 ],
112 [ "4.3.7", "Valid RFC3280 Mandatory Attribute Types Test7", 0 ],
113 [ "4.3.8", "Valid RFC3280 Optional Attribute Types Test8", 0 ],
114 [ "4.3.9", "Valid UTF8String Encoded Names Test9", 0 ],
115 [ "4.3.10", "Valid Rollover from PrintableString to UTF8String Test10", 0 ],
116 [ "4.3.11", "Valid UTF8String Case Insensitive Match Test11", 0 ],
117 [ "4.4", "Basic Certificate Revocation Tests" ],
118 [ "4.4.1", "Missing CRL Test1", 3 ],
119 [ "4.4.2", "Invalid Revoked CA Test2", 23 ],
120 [ "4.4.3", "Invalid Revoked EE Test3", 23 ],
121 [ "4.4.4", "Invalid Bad CRL Signature Test4", 8 ],
122 [ "4.4.5", "Invalid Bad CRL Issuer Name Test5", 3 ],
123 [ "4.4.6", "Invalid Wrong CRL Test6", 3 ],
124 [ "4.4.7", "Valid Two CRLs Test7", 0 ],
125
126 # The test document suggests these should return certificate revoked...
127 # Subsequent discussion has concluded they should not due to unhandled
128 # critical CRL extensions.
129 [ "4.4.8", "Invalid Unknown CRL Entry Extension Test8", 36 ],
130 [ "4.4.9", "Invalid Unknown CRL Extension Test9", 36 ],
131
132 [ "4.4.10", "Invalid Unknown CRL Extension Test10", 36 ],
133 [ "4.4.11", "Invalid Old CRL nextUpdate Test11", 12 ],
134 [ "4.4.12", "Invalid pre2000 CRL nextUpdate Test12", 12 ],
135 [ "4.4.13", "Valid GeneralizedTime CRL nextUpdate Test13", 0 ],
136 [ "4.4.14", "Valid Negative Serial Number Test14", 0 ],
137 [ "4.4.15", "Invalid Negative Serial Number Test15", 23 ],
138 [ "4.4.16", "Valid Long Serial Number Test16", 0 ],
139 [ "4.4.17", "Valid Long Serial Number Test17", 0 ],
140 [ "4.4.18", "Invalid Long Serial Number Test18", 23 ],
141 [ "4.4.19", "Valid Separate Certificate and CRL Keys Test19", 0 ],
142 [ "4.4.20", "Invalid Separate Certificate and CRL Keys Test20", 23 ],
143
144 # CRL path is revoked so get a CRL path validation error
145 [ "4.4.21", "Invalid Separate Certificate and CRL Keys Test21", 54 ],
146 [ "4.5", "Verifying Paths with Self-Issued Certificates" ],
147 [ "4.5.1", "Valid Basic Self-Issued Old With New Test1", 0 ],
148 [ "4.5.2", "Invalid Basic Self-Issued Old With New Test2", 23 ],
149 [ "4.5.3", "Valid Basic Self-Issued New With Old Test3", 0 ],
150 [ "4.5.4", "Valid Basic Self-Issued New With Old Test4", 0 ],
151 [ "4.5.5", "Invalid Basic Self-Issued New With Old Test5", 23 ],
152 [ "4.5.6", "Valid Basic Self-Issued CRL Signing Key Test6", 0 ],
153 [ "4.5.7", "Invalid Basic Self-Issued CRL Signing Key Test7", 23 ],
154 [ "4.5.8", "Invalid Basic Self-Issued CRL Signing Key Test8", 20 ],
155 [ "4.6", "Verifying Basic Constraints" ],
156 [ "4.6.1", "Invalid Missing basicConstraints Test1", 24 ],
157 [ "4.6.2", "Invalid cA False Test2", 24 ],
158 [ "4.6.3", "Invalid cA False Test3", 24 ],
159 [ "4.6.4", "Valid basicConstraints Not Critical Test4", 0 ],
160 [ "4.6.5", "Invalid pathLenConstraint Test5", 25 ],
161 [ "4.6.6", "Invalid pathLenConstraint Test6", 25 ],
162 [ "4.6.7", "Valid pathLenConstraint Test7", 0 ],
163 [ "4.6.8", "Valid pathLenConstraint Test8", 0 ],
164 [ "4.6.9", "Invalid pathLenConstraint Test9", 25 ],
165 [ "4.6.10", "Invalid pathLenConstraint Test10", 25 ],
166 [ "4.6.11", "Invalid pathLenConstraint Test11", 25 ],
167 [ "4.6.12", "Invalid pathLenConstraint Test12", 25 ],
168 [ "4.6.13", "Valid pathLenConstraint Test13", 0 ],
169 [ "4.6.14", "Valid pathLenConstraint Test14", 0 ],
170 [ "4.6.15", "Valid Self-Issued pathLenConstraint Test15", 0 ],
171 [ "4.6.16", "Invalid Self-Issued pathLenConstraint Test16", 25 ],
172 [ "4.6.17", "Valid Self-Issued pathLenConstraint Test17", 0 ],
173 [ "4.7", "Key Usage" ],
174 [ "4.7.1", "Invalid keyUsage Critical keyCertSign False Test1", 20 ],
175 [ "4.7.2", "Invalid keyUsage Not Critical keyCertSign False Test2", 20 ],
176 [ "4.7.3", "Valid keyUsage Not Critical Test3", 0 ],
177 [ "4.7.4", "Invalid keyUsage Critical cRLSign False Test4", 35 ],
178 [ "4.7.5", "Invalid keyUsage Not Critical cRLSign False Test5", 35 ],
179
180 # Certificate policy tests need special handling. They can have several
181 # sub tests and we need to check the outputs are correct.
182
183 [ "4.8", "Certificate Policies" ],
184 [
185 "4.8.1.1",
186 "All Certificates Same Policy Test1",
187 "-policy anyPolicy -explicit_policy",
188 "True", $nist1, $nist1, 0
189 ],
190 [
191 "4.8.1.2",
192 "All Certificates Same Policy Test1",
193 "-policy $nist1 -explicit_policy",
194 "True", $nist1, $nist1, 0
195 ],
196 [
197 "4.8.1.3",
198 "All Certificates Same Policy Test1",
199 "-policy $nist2 -explicit_policy",
200 "True", $nist1, "<empty>", 43
201 ],
202 [
203 "4.8.1.4",
204 "All Certificates Same Policy Test1",
205 "-policy $nist1 -policy $nist2 -explicit_policy",
206 "True", $nist1, $nist1, 0
207 ],
208 [
209 "4.8.2.1",
210 "All Certificates No Policies Test2",
211 "-policy anyPolicy",
212 "False", "<empty>", "<empty>", 0
213 ],
214 [
215 "4.8.2.2",
216 "All Certificates No Policies Test2",
217 "-policy anyPolicy -explicit_policy",
218 "True", "<empty>", "<empty>", 43
219 ],
220 [
221 "4.8.3.1",
222 "Different Policies Test3",
223 "-policy anyPolicy",
224 "False", "<empty>", "<empty>", 0
225 ],
226 [
227 "4.8.3.2",
228 "Different Policies Test3",
229 "-policy anyPolicy -explicit_policy",
230 "True", "<empty>", "<empty>", 43
231 ],
232 [
233 "4.8.3.3",
234 "Different Policies Test3",
235 "-policy $nist1 -policy $nist2 -explicit_policy",
236 "True", "<empty>", "<empty>", 43
237 ],
238
239 [
240 "4.8.4",
241 "Different Policies Test4",
242 "-policy anyPolicy",
243 "True", "<empty>", "<empty>", 43
244 ],
245 [
246 "4.8.5",
247 "Different Policies Test5",
248 "-policy anyPolicy",
249 "True", "<empty>", "<empty>", 43
250 ],
251 [
252 "4.8.6.1",
253 "Overlapping Policies Test6",
254 "-policy anyPolicy",
255 "True", $nist1, $nist1, 0
256 ],
257 [
258 "4.8.6.2",
259 "Overlapping Policies Test6",
260 "-policy $nist1",
261 "True", $nist1, $nist1, 0
262 ],
263 [
264 "4.8.6.3",
265 "Overlapping Policies Test6",
266 "-policy $nist2",
267 "True", $nist1, "<empty>", 43
268 ],
269 [
270 "4.8.7",
271 "Different Policies Test7",
272 "-policy anyPolicy",
273 "True", "<empty>", "<empty>", 43
274 ],
275 [
276 "4.8.8",
277 "Different Policies Test8",
278 "-policy anyPolicy",
279 "True", "<empty>", "<empty>", 43
280 ],
281 [
282 "4.8.9",
283 "Different Policies Test9",
284 "-policy anyPolicy",
285 "True", "<empty>", "<empty>", 43
286 ],
287 [
288 "4.8.10.1",
289 "All Certificates Same Policies Test10",
290 "-policy $nist1",
291 "True", "$nist1:$nist2", "$nist1", 0
292 ],
293 [
294 "4.8.10.2",
295 "All Certificates Same Policies Test10",
296 "-policy $nist2",
297 "True", "$nist1:$nist2", "$nist2", 0
298 ],
299 [
300 "4.8.10.3",
301 "All Certificates Same Policies Test10",
302 "-policy anyPolicy",
303 "True", "$nist1:$nist2", "$nist1:$nist2", 0
304 ],
305 [
306 "4.8.11.1",
307 "All Certificates AnyPolicy Test11",
308 "-policy anyPolicy",
309 "True", "$apolicy", "$apolicy", 0
310 ],
311 [
312 "4.8.11.2",
313 "All Certificates AnyPolicy Test11",
314 "-policy $nist1",
315 "True", "$apolicy", "$nist1", 0
316 ],
317 [
318 "4.8.12",
319 "Different Policies Test12",
320 "-policy anyPolicy",
321 "True", "<empty>", "<empty>", 43
322 ],
323 [
324 "4.8.13.1",
325 "All Certificates Same Policies Test13",
326 "-policy $nist1",
327 "True", "$nist1:$nist2:$nist3", "$nist1", 0
328 ],
329 [
330 "4.8.13.2",
331 "All Certificates Same Policies Test13",
332 "-policy $nist2",
333 "True", "$nist1:$nist2:$nist3", "$nist2", 0
334 ],
335 [
336 "4.8.13.3",
337 "All Certificates Same Policies Test13",
338 "-policy $nist3",
339 "True", "$nist1:$nist2:$nist3", "$nist3", 0
340 ],
341 [
342 "4.8.14.1", "AnyPolicy Test14",
343 "-policy $nist1", "True",
344 "$nist1", "$nist1",
345 0
346 ],
347 [
348 "4.8.14.2", "AnyPolicy Test14",
349 "-policy $nist2", "True",
350 "$nist1", "<empty>",
351 43
352 ],
353 [
354 "4.8.15",
355 "User Notice Qualifier Test15",
356 "-policy anyPolicy",
357 "False", "$nist1", "$nist1", 0
358 ],
359 [
360 "4.8.16",
361 "User Notice Qualifier Test16",
362 "-policy anyPolicy",
363 "False", "$nist1", "$nist1", 0
364 ],
365 [
366 "4.8.17",
367 "User Notice Qualifier Test17",
368 "-policy anyPolicy",
369 "False", "$nist1", "$nist1", 0
370 ],
371 [
372 "4.8.18.1",
373 "User Notice Qualifier Test18",
374 "-policy $nist1",
375 "True", "$nist1:$nist2", "$nist1", 0
376 ],
377 [
378 "4.8.18.2",
379 "User Notice Qualifier Test18",
380 "-policy $nist2",
381 "True", "$nist1:$nist2", "$nist2", 0
382 ],
383 [
384 "4.8.19",
385 "User Notice Qualifier Test19",
386 "-policy anyPolicy",
387 "False", "$nist1", "$nist1", 0
388 ],
389 [
390 "4.8.20",
391 "CPS Pointer Qualifier Test20",
392 "-policy anyPolicy -explicit_policy",
393 "True", "$nist1", "$nist1", 0
394 ],
395 [ "4.9", "Require Explicit Policy" ],
396 [
397 "4.9.1",
398 "Valid RequireExplicitPolicy Test1",
399 "-policy anyPolicy",
400 "False", "<empty>", "<empty>", 0
401 ],
402 [
403 "4.9.2",
404 "Valid RequireExplicitPolicy Test2",
405 "-policy anyPolicy",
406 "False", "<empty>", "<empty>", 0
407 ],
408 [
409 "4.9.3",
410 "Invalid RequireExplicitPolicy Test3",
411 "-policy anyPolicy",
412 "True", "<empty>", "<empty>", 43
413 ],
414 [
415 "4.9.4",
416 "Valid RequireExplicitPolicy Test4",
417 "-policy anyPolicy",
418 "True", "$nist1", "$nist1", 0
419 ],
420 [
421 "4.9.5",
422 "Invalid RequireExplicitPolicy Test5",
423 "-policy anyPolicy",
424 "True", "<empty>", "<empty>", 43
425 ],
426 [
427 "4.9.6",
428 "Valid Self-Issued requireExplicitPolicy Test6",
429 "-policy anyPolicy",
430 "False", "<empty>", "<empty>", 0
431 ],
432 [
433 "4.9.7",
434 "Invalid Self-Issued requireExplicitPolicy Test7",
435 "-policy anyPolicy",
436 "True", "<empty>", "<empty>", 43
437 ],
438 [
439 "4.9.8",
440 "Invalid Self-Issued requireExplicitPolicy Test8",
441 "-policy anyPolicy",
442 "True", "<empty>", "<empty>", 43
443 ],
444 [ "4.10", "Policy Mappings" ],
445 [
446 "4.10.1.1",
447 "Valid Policy Mapping Test1",
448 "-policy $nist1",
449 "True", "$nist1", "$nist1", 0
450 ],
451 [
452 "4.10.1.2",
453 "Valid Policy Mapping Test1",
454 "-policy $nist2",
455 "True", "$nist1", "<empty>", 43
456 ],
457 [
458 "4.10.1.3",
459 "Valid Policy Mapping Test1",
460 "-policy anyPolicy -inhibit_map",
461 "True", "<empty>", "<empty>", 43
462 ],
463 [
464 "4.10.2.1",
465 "Invalid Policy Mapping Test2",
466 "-policy anyPolicy",
467 "True", "<empty>", "<empty>", 43
468 ],
469 [
470 "4.10.2.2",
471 "Invalid Policy Mapping Test2",
472 "-policy anyPolicy -inhibit_map",
473 "True", "<empty>", "<empty>", 43
474 ],
475 [
476 "4.10.3.1",
477 "Valid Policy Mapping Test3",
478 "-policy $nist1",
479 "True", "$nist2", "<empty>", 43
480 ],
481 [
482 "4.10.3.2",
483 "Valid Policy Mapping Test3",
484 "-policy $nist2",
485 "True", "$nist2", "$nist2", 0
486 ],
487 [
488 "4.10.4",
489 "Invalid Policy Mapping Test4",
490 "-policy anyPolicy",
491 "True", "<empty>", "<empty>", 43
492 ],
493 [
494 "4.10.5.1",
495 "Valid Policy Mapping Test5",
496 "-policy $nist1",
497 "True", "$nist1", "$nist1", 0
498 ],
499 [
500 "4.10.5.2",
501 "Valid Policy Mapping Test5",
502 "-policy $nist6",
503 "True", "$nist1", "<empty>", 43
504 ],
505 [
506 "4.10.6.1",
507 "Valid Policy Mapping Test6",
508 "-policy $nist1",
509 "True", "$nist1", "$nist1", 0
510 ],
511 [
512 "4.10.6.2",
513 "Valid Policy Mapping Test6",
514 "-policy $nist6",
515 "True", "$nist1", "<empty>", 43
516 ],
517 [ "4.10.7", "Invalid Mapping From anyPolicy Test7", 42 ],
518 [ "4.10.8", "Invalid Mapping To anyPolicy Test8", 42 ],
519 [
520 "4.10.9",
521 "Valid Policy Mapping Test9",
522 "-policy anyPolicy",
523 "True", "$nist1", "$nist1", 0
524 ],
525 [
526 "4.10.10",
527 "Invalid Policy Mapping Test10",
528 "-policy anyPolicy",
529 "True", "<empty>", "<empty>", 43
530 ],
531 [
532 "4.10.11",
533 "Valid Policy Mapping Test11",
534 "-policy anyPolicy",
535 "True", "$nist1", "$nist1", 0
536 ],
537
538 # TODO: check notice display
539 [
540 "4.10.12.1",
541 "Valid Policy Mapping Test12",
542 "-policy $nist1",
543 "True", "$nist1:$nist2", "$nist1", 0
544 ],
545
546 # TODO: check notice display
547 [
548 "4.10.12.2",
549 "Valid Policy Mapping Test12",
550 "-policy $nist2",
551 "True", "$nist1:$nist2", "$nist2", 0
552 ],
553 [
554 "4.10.13",
555 "Valid Policy Mapping Test13",
556 "-policy anyPolicy",
557 "True", "$nist1", "$nist1", 0
558 ],
559
560 # TODO: check notice display
561 [
562 "4.10.14",
563 "Valid Policy Mapping Test14",
564 "-policy anyPolicy",
565 "True", "$nist1", "$nist1", 0
566 ],
567 [ "4.11", "Inhibit Policy Mapping" ],
568 [
569 "4.11.1",
570 "Invalid inhibitPolicyMapping Test1",
571 "-policy anyPolicy",
572 "True", "<empty>", "<empty>", 43
573 ],
574 [
575 "4.11.2",
576 "Valid inhibitPolicyMapping Test2",
577 "-policy anyPolicy",
578 "True", "$nist1", "$nist1", 0
579 ],
580 [
581 "4.11.3",
582 "Invalid inhibitPolicyMapping Test3",
583 "-policy anyPolicy",
584 "True", "<empty>", "<empty>", 43
585 ],
586 [
587 "4.11.4",
588 "Valid inhibitPolicyMapping Test4",
589 "-policy anyPolicy",
590 "True", "$nist2", "$nist2", 0
591 ],
592 [
593 "4.11.5",
594 "Invalid inhibitPolicyMapping Test5",
595 "-policy anyPolicy",
596 "True", "<empty>", "<empty>", 43
597 ],
598 [
599 "4.11.6",
600 "Invalid inhibitPolicyMapping Test6",
601 "-policy anyPolicy",
602 "True", "<empty>", "<empty>", 43
603 ],
604 [
605 "4.11.7",
606 "Valid Self-Issued inhibitPolicyMapping Test7",
607 "-policy anyPolicy",
608 "True", "$nist1", "$nist1", 0
609 ],
610 [
611 "4.11.8",
612 "Invalid Self-Issued inhibitPolicyMapping Test8",
613 "-policy anyPolicy",
614 "True", "<empty>", "<empty>", 43
615 ],
616 [
617 "4.11.9",
618 "Invalid Self-Issued inhibitPolicyMapping Test9",
619 "-policy anyPolicy",
620 "True", "<empty>", "<empty>", 43
621 ],
622 [
623 "4.11.10",
624 "Invalid Self-Issued inhibitPolicyMapping Test10",
625 "-policy anyPolicy",
626 "True", "<empty>", "<empty>", 43
627 ],
628 [
629 "4.11.11",
630 "Invalid Self-Issued inhibitPolicyMapping Test11",
631 "-policy anyPolicy",
632 "True", "<empty>", "<empty>", 43
633 ],
634 [ "4.12", "Inhibit Any Policy" ],
635 [
636 "4.12.1",
637 "Invalid inhibitAnyPolicy Test1",
638 "-policy anyPolicy",
639 "True", "<empty>", "<empty>", 43
640 ],
641 [
642 "4.12.2",
643 "Valid inhibitAnyPolicy Test2",
644 "-policy anyPolicy",
645 "True", "$nist1", "$nist1", 0
646 ],
647 [
648 "4.12.3.1",
649 "inhibitAnyPolicy Test3",
650 "-policy anyPolicy",
651 "True", "$nist1", "$nist1", 0
652 ],
653 [
654 "4.12.3.2",
655 "inhibitAnyPolicy Test3",
656 "-policy anyPolicy -inhibit_any",
657 "True", "<empty>", "<empty>", 43
658 ],
659 [
660 "4.12.4",
661 "Invalid inhibitAnyPolicy Test4",
662 "-policy anyPolicy",
663 "True", "<empty>", "<empty>", 43
664 ],
665 [
666 "4.12.5",
667 "Invalid inhibitAnyPolicy Test5",
668 "-policy anyPolicy",
669 "True", "<empty>", "<empty>", 43
670 ],
671 [
672 "4.12.6",
673 "Invalid inhibitAnyPolicy Test6",
674 "-policy anyPolicy",
675 "True", "<empty>", "<empty>", 43
676 ],
677 [ "4.12.7", "Valid Self-Issued inhibitAnyPolicy Test7", 0 ],
678 [ "4.12.8", "Invalid Self-Issued inhibitAnyPolicy Test8", 43 ],
679 [ "4.12.9", "Valid Self-Issued inhibitAnyPolicy Test9", 0 ],
680 [ "4.12.10", "Invalid Self-Issued inhibitAnyPolicy Test10", 43 ],
681 [ "4.13", "Name Constraints" ],
682 [ "4.13.1", "Valid DN nameConstraints Test1", 0 ],
683 [ "4.13.2", "Invalid DN nameConstraints Test2", 47 ],
684 [ "4.13.3", "Invalid DN nameConstraints Test3", 47 ],
685 [ "4.13.4", "Valid DN nameConstraints Test4", 0 ],
686 [ "4.13.5", "Valid DN nameConstraints Test5", 0 ],
687 [ "4.13.6", "Valid DN nameConstraints Test6", 0 ],
688 [ "4.13.7", "Invalid DN nameConstraints Test7", 48 ],
689 [ "4.13.8", "Invalid DN nameConstraints Test8", 48 ],
690 [ "4.13.9", "Invalid DN nameConstraints Test9", 48 ],
691 [ "4.13.10", "Invalid DN nameConstraints Test10", 48 ],
692 [ "4.13.11", "Valid DN nameConstraints Test11", 0 ],
693 [ "4.13.12", "Invalid DN nameConstraints Test12", 47 ],
694 [ "4.13.13", "Invalid DN nameConstraints Test13", 47 ],
695 [ "4.13.14", "Valid DN nameConstraints Test14", 0 ],
696 [ "4.13.15", "Invalid DN nameConstraints Test15", 48 ],
697 [ "4.13.16", "Invalid DN nameConstraints Test16", 48 ],
698 [ "4.13.17", "Invalid DN nameConstraints Test17", 48 ],
699 [ "4.13.18", "Valid DN nameConstraints Test18", 0 ],
700 [ "4.13.19", "Valid Self-Issued DN nameConstraints Test19", 0 ],
701 [ "4.13.20", "Invalid Self-Issued DN nameConstraints Test20", 47 ],
702 [ "4.13.21", "Valid RFC822 nameConstraints Test21", 0 ],
703 [ "4.13.22", "Invalid RFC822 nameConstraints Test22", 47 ],
704 [ "4.13.23", "Valid RFC822 nameConstraints Test23", 0 ],
705 [ "4.13.24", "Invalid RFC822 nameConstraints Test24", 47 ],
706 [ "4.13.25", "Valid RFC822 nameConstraints Test25", 0 ],
707 [ "4.13.26", "Invalid RFC822 nameConstraints Test26", 48 ],
708 [ "4.13.27", "Valid DN and RFC822 nameConstraints Test27", 0 ],
709 [ "4.13.28", "Invalid DN and RFC822 nameConstraints Test28", 47 ],
710 [ "4.13.29", "Invalid DN and RFC822 nameConstraints Test29", 47 ],
711 [ "4.13.30", "Valid DNS nameConstraints Test30", 0 ],
712 [ "4.13.31", "Invalid DNS nameConstraints Test31", 47 ],
713 [ "4.13.32", "Valid DNS nameConstraints Test32", 0 ],
714 [ "4.13.33", "Invalid DNS nameConstraints Test33", 48 ],
715 [ "4.13.34", "Valid URI nameConstraints Test34", 0 ],
716 [ "4.13.35", "Invalid URI nameConstraints Test35", 47 ],
717 [ "4.13.36", "Valid URI nameConstraints Test36", 0 ],
718 [ "4.13.37", "Invalid URI nameConstraints Test37", 48 ],
719 [ "4.13.38", "Invalid DNS nameConstraints Test38", 47 ],
720 [ "4.14", "Distribution Points" ],
721 [ "4.14.1", "Valid distributionPoint Test1", 0 ],
722 [ "4.14.2", "Invalid distributionPoint Test2", 23 ],
723 [ "4.14.3", "Invalid distributionPoint Test3", 44 ],
724 [ "4.14.4", "Valid distributionPoint Test4", 0 ],
725 [ "4.14.5", "Valid distributionPoint Test5", 0 ],
726 [ "4.14.6", "Invalid distributionPoint Test6", 23 ],
727 [ "4.14.7", "Valid distributionPoint Test7", 0 ],
728 [ "4.14.8", "Invalid distributionPoint Test8", 44 ],
729 [ "4.14.9", "Invalid distributionPoint Test9", 44 ],
730 [ "4.14.10", "Valid No issuingDistributionPoint Test10", 0 ],
731 [ "4.14.11", "Invalid onlyContainsUserCerts CRL Test11", 44 ],
732 [ "4.14.12", "Invalid onlyContainsCACerts CRL Test12", 44 ],
733 [ "4.14.13", "Valid onlyContainsCACerts CRL Test13", 0 ],
734 [ "4.14.14", "Invalid onlyContainsAttributeCerts Test14", 44 ],
735 [ "4.14.15", "Invalid onlySomeReasons Test15", 23 ],
736 [ "4.14.16", "Invalid onlySomeReasons Test16", 23 ],
737 [ "4.14.17", "Invalid onlySomeReasons Test17", 3 ],
738 [ "4.14.18", "Valid onlySomeReasons Test18", 0 ],
739 [ "4.14.19", "Valid onlySomeReasons Test19", 0 ],
740 [ "4.14.20", "Invalid onlySomeReasons Test20", 23 ],
741 [ "4.14.21", "Invalid onlySomeReasons Test21", 23 ],
742 [ "4.14.22", "Valid IDP with indirectCRL Test22", 0 ],
743 [ "4.14.23", "Invalid IDP with indirectCRL Test23", 23 ],
744 [ "4.14.24", "Valid IDP with indirectCRL Test24", 0 ],
745 [ "4.14.25", "Valid IDP with indirectCRL Test25", 0 ],
746 [ "4.14.26", "Invalid IDP with indirectCRL Test26", 44 ],
747 [ "4.14.27", "Invalid cRLIssuer Test27", 3 ],
748 [ "4.14.28", "Valid cRLIssuer Test28", 0 ],
749 [ "4.14.29", "Valid cRLIssuer Test29", 0 ],
750
751 # Although this test is valid it has a circular dependency. As a result
752 # an attempt is made to recursively check a CRL path and rejected due to
753 # a CRL path validation error. PKITS notes suggest this test does not
754 # need to be run due to this issue.
755 [ "4.14.30", "Valid cRLIssuer Test30", 54 ],
756 [ "4.14.31", "Invalid cRLIssuer Test31", 23 ],
757 [ "4.14.32", "Invalid cRLIssuer Test32", 23 ],
758 [ "4.14.33", "Valid cRLIssuer Test33", 0 ],
759 [ "4.14.34", "Invalid cRLIssuer Test34", 23 ],
760 [ "4.14.35", "Invalid cRLIssuer Test35", 44 ],
761 [ "4.15", "Delta-CRLs" ],
762 [ "4.15.1", "Invalid deltaCRLIndicator No Base Test1", 3 ],
763 [ "4.15.2", "Valid delta-CRL Test2", 0 ],
764 [ "4.15.3", "Invalid delta-CRL Test3", 23 ],
765 [ "4.15.4", "Invalid delta-CRL Test4", 23 ],
766 [ "4.15.5", "Valid delta-CRL Test5", 0 ],
767 [ "4.15.6", "Invalid delta-CRL Test6", 23 ],
768 [ "4.15.7", "Valid delta-CRL Test7", 0 ],
769 [ "4.15.8", "Valid delta-CRL Test8", 0 ],
770 [ "4.15.9", "Invalid delta-CRL Test9", 23 ],
771 [ "4.15.10", "Invalid delta-CRL Test10", 12 ],
772 [ "4.16", "Private Certificate Extensions" ],
773 [ "4.16.1", "Valid Unknown Not Critical Certificate Extension Test1", 0 ],
774 [ "4.16.2", "Invalid Unknown Critical Certificate Extension Test2", 34 ],
775);
776
777
778my $verbose = 1;
779
780my $numtest = 0;
781my $numfail = 0;
782
783my $ossl = "ossl/apps/openssl";
784
785my $ossl_cmd = "$ossl_path cms -verify -verify_retcode ";
786$ossl_cmd .= "-CAfile pkitsta.pem -crl_check_all -x509_strict ";
787
788# Check for expiry of trust anchor
789system "$ossl_path x509 -inform DER -in $pkitsta -checkend 0";
790if ($? == 256)
791 {
792 print STDERR "WARNING: using older expired data\n";
793 $ossl_cmd .= "-attime 1291940972 ";
794 }
795
796$ossl_cmd .= "-policy_check -extended_crl -use_deltas -out /dev/null 2>&1 ";
797
798system "$ossl_path x509 -inform DER -in $pkitsta -out pkitsta.pem";
799
800die "Can't create trust anchor file" if $?;
801
802print "Running PKITS tests:\n" if $verbose;
803
804foreach (@testlists) {
805 my $argnum = @$_;
806 if ( $argnum == 2 ) {
807 my ( $tnum, $title ) = @$_;
808 print "$tnum $title\n" if $verbose;
809 }
810 elsif ( $argnum == 3 ) {
811 my ( $tnum, $title, $exp_ret ) = @$_;
812 my $filename = $title;
813 $exp_ret += 32 if $exp_ret;
814 $filename =~ tr/ -//d;
815 $filename = "Signed${filename}.eml";
816 if ( !-f "$pkitsdir/$filename" ) {
817 print "\"$filename\" not found\n";
818 }
819 else {
820 my $ret;
821 my $test_fail = 0;
822 my $errmsg = "";
823 my $cmd = $ossl_cmd;
824 $cmd .= "-in $pkitsdir/$filename -policy anyPolicy";
825 my $cmdout = `$cmd`;
826 $ret = $? >> 8;
827 if ( $? & 0xff ) {
828 $errmsg .= "Abnormal OpenSSL termination\n";
829 $test_fail = 1;
830 }
831 if ( $exp_ret != $ret ) {
832 $errmsg .= "Return code:$ret, ";
833 $errmsg .= "expected $exp_ret\n";
834 $test_fail = 1;
835 }
836 if ($test_fail) {
837 print "$tnum $title : Failed!\n";
838 print "Filename: $pkitsdir/$filename\n";
839 print $errmsg;
840 print "Command output:\n$cmdout\n";
841 $numfail++;
842 }
843 $numtest++;
844 }
845 }
846 elsif ( $argnum == 7 ) {
847 my ( $tnum, $title, $exargs, $exp_epol, $exp_aset, $exp_uset, $exp_ret )
848 = @$_;
849 my $filename = $title;
850 $exp_ret += 32 if $exp_ret;
851 $filename =~ tr/ -//d;
852 $filename = "Signed${filename}.eml";
853 if ( !-f "$pkitsdir/$filename" ) {
854 print "\"$filename\" not found\n";
855 }
856 else {
857 my $ret;
858 my $cmdout = "";
859 my $errmsg = "";
860 my $epol = "";
861 my $aset = "";
862 my $uset = "";
863 my $pol = -1;
864 my $test_fail = 0;
865 my $cmd = $ossl_cmd;
866 $cmd .= "-in $pkitsdir/$filename $exargs -policy_print";
867 @oparr = `$cmd`;
868 $ret = $? >> 8;
869
870 if ( $? & 0xff ) {
871 $errmsg .= "Abnormal OpenSSL termination\n";
872 $test_fail = 1;
873 }
874 foreach (@oparr) {
875 my $test_failed = 0;
876 $cmdout .= $_;
877 if (/^Require explicit Policy: (.*)$/) {
878 $epol = $1;
879 }
880 if (/^Authority Policies/) {
881 if (/empty/) {
882 $aset = "<empty>";
883 }
884 else {
885 $pol = 1;
886 }
887 }
888 $test_fail = 1 if (/leak/i);
889 if (/^User Policies/) {
890 if (/empty/) {
891 $uset = "<empty>";
892 }
893 else {
894 $pol = 2;
895 }
896 }
897 if (/\s+Policy: (.*)$/) {
898 if ( $pol == 1 ) {
899 $aset .= ":" if $aset ne "";
900 $aset .= $1;
901 }
902 elsif ( $pol == 2 ) {
903 $uset .= ":" if $uset ne "";
904 $uset .= $1;
905 }
906 }
907 }
908
909 if ( $epol ne $exp_epol ) {
910 $errmsg .= "Explicit policy:$epol, ";
911 $errmsg .= "expected $exp_epol\n";
912 $test_fail = 1;
913 }
914 if ( $aset ne $exp_aset ) {
915 $errmsg .= "Authority policy set :$aset, ";
916 $errmsg .= "expected $exp_aset\n";
917 $test_fail = 1;
918 }
919 if ( $uset ne $exp_uset ) {
920 $errmsg .= "User policy set :$uset, ";
921 $errmsg .= "expected $exp_uset\n";
922 $test_fail = 1;
923 }
924
925 if ( $exp_ret != $ret ) {
926 print "Return code:$ret, expected $exp_ret\n";
927 $test_fail = 1;
928 }
929
930 if ($test_fail) {
931 print "$tnum $title : Failed!\n";
932 print "Filename: $pkitsdir/$filename\n";
933 print "Command output:\n$cmdout\n";
934 $numfail++;
935 }
936 $numtest++;
937 }
938 }
939}
940
941if ($numfail) {
942 print "$numfail tests failed out of $numtest\n";
943}
944else {
945 print "All Tests Successful.\n";
946}
947
948unlink "pkitsta.pem";
949
diff --git a/src/lib/libssl/test/smcont.txt b/src/lib/libssl/test/smcont.txt
deleted file mode 100644
index e837c0b75b..0000000000
--- a/src/lib/libssl/test/smcont.txt
+++ /dev/null
@@ -1 +0,0 @@
1Some test content for OpenSSL CMS \ No newline at end of file
diff --git a/src/lib/libssl/test/smime-certs/smdsa1.pem b/src/lib/libssl/test/smime-certs/smdsa1.pem
deleted file mode 100644
index d5677dbfbe..0000000000
--- a/src/lib/libssl/test/smime-certs/smdsa1.pem
+++ /dev/null
@@ -1,34 +0,0 @@
1-----BEGIN DSA PRIVATE KEY-----
2MIIBuwIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3
3OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt
4GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J
5jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt
6wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK
7+FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z
8SJCBQw5zAoGATQlPPF+OeU8nu3rsdXGDiZdJzOkuCce3KQfTABA9C+Dk4CVcvBdd
9YRLGpnykumkNTO1sTO+4/Gphsuje1ujK9td4UEhdYqylCe5QjEMrszDlJtelDQF9
10C0yhdjKGTP0kxofLhsGckcuQvcKEKffT2pDDKJIy4vWQO0UyJl1vjLcCFG2uiGGx
119fMUZq1v0ePD4Wo0Xkxo
12-----END DSA PRIVATE KEY-----
13-----BEGIN CERTIFICATE-----
14MIIDpDCCAw2gAwIBAgIJAMtotfHYdEsWMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
15BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
16TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
17CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
18ZXN0IFMvTUlNRSBFRSBEU0EgIzEwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7
19CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ
20mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2
21jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB
22CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV
23kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D
24xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhAACgYBN
25CU88X455Tye7eux1cYOJl0nM6S4Jx7cpB9MAED0L4OTgJVy8F11hEsamfKS6aQ1M
267WxM77j8amGy6N7W6Mr213hQSF1irKUJ7lCMQyuzMOUm16UNAX0LTKF2MoZM/STG
27h8uGwZyRy5C9woQp99PakMMokjLi9ZA7RTImXW+Mt6OBgzCBgDAdBgNVHQ4EFgQU
284Qfbhpi5yqXaXuCLXj427mR25MkwHwYDVR0jBBgwFoAUE89Lp7uJLrM4Vxd2xput
29aFvl7RcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwIAYDVR0RBBkwF4EV
30c21pbWVkc2ExQG9wZW5zc2wub3JnMA0GCSqGSIb3DQEBBQUAA4GBAFrdUzKK1pWO
31kd02S423KUBc4GWWyiGlVoEO7WxVhHLJ8sm67X7OtJOwe0UGt+Nc5qLtyJYSirw8
32phjiTdNpQCTJ8+Kc56tWkJ6H7NAI4vTJtPL5BM/EmeYrVSU9JI9xhqpyKw9IBD+n
33hRJ79W9FaiJRvaAOX+TkyTukJrxAWRyv
34-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/smime-certs/smdsa2.pem b/src/lib/libssl/test/smime-certs/smdsa2.pem
deleted file mode 100644
index ef86c115d7..0000000000
--- a/src/lib/libssl/test/smime-certs/smdsa2.pem
+++ /dev/null
@@ -1,34 +0,0 @@
1-----BEGIN DSA PRIVATE KEY-----
2MIIBvAIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3
3OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt
4GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J
5jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt
6wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK
7+FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z
8SJCBQw5zAoGBAIPmO8BtJ+Yac58trrPwq9b/6VW3jQTWzTLWSH84/QQdqQa+Pz3v
9It/+hHM0daNF5uls8ICsPL1aLXmRx0pHvIyb0aAzYae4T4Jv/COPDMTdKbA1uitJ
10VbkGZrm+LIrs7I9lOkb4T0vI6kL/XdOCXY1469zsqCgJ/O2ibn6mq0nWAhR716o2
11Nf8SimTZYB0/CKje6M5ufA==
12-----END DSA PRIVATE KEY-----
13-----BEGIN CERTIFICATE-----
14MIIDpTCCAw6gAwIBAgIJAMtotfHYdEsXMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
15BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
16TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
17CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
18ZXN0IFMvTUlNRSBFRSBEU0EgIzIwggG4MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7
19CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ
20mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2
21jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB
22CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV
23kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D
24xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhQACgYEA
25g+Y7wG0n5hpzny2us/Cr1v/pVbeNBNbNMtZIfzj9BB2pBr4/Pe8i3/6EczR1o0Xm
266WzwgKw8vVoteZHHSke8jJvRoDNhp7hPgm/8I48MxN0psDW6K0lVuQZmub4siuzs
27j2U6RvhPS8jqQv9d04JdjXjr3OyoKAn87aJufqarSdajgYMwgYAwHQYDVR0OBBYE
28FHsAGNfVltSYUq4hC+YVYwsYtA+dMB8GA1UdIwQYMBaAFBPPS6e7iS6zOFcXdsab
29rWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgbAMCAGA1UdEQQZMBeB
30FXNtaW1lZHNhMkBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQCx9BtCbaYF
31FXjLClkuKXbESaDZA1biPgY25i00FsUzARuhCpqD2v+0tu5c33ZzIhL6xlvBRU5l
326Atw/xpZhae+hdBEtxPJoGekLLrHOau7Md3XwDjV4lFgcEJkWZoaSOOIK+4D5jF0
33jZWtHjnwEzuLYlo7ScHSsbcQfjH0M1TP5A==
34-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/smime-certs/smdsa3.pem b/src/lib/libssl/test/smime-certs/smdsa3.pem
deleted file mode 100644
index eeb848dabc..0000000000
--- a/src/lib/libssl/test/smime-certs/smdsa3.pem
+++ /dev/null
@@ -1,34 +0,0 @@
1-----BEGIN DSA PRIVATE KEY-----
2MIIBvAIBAAKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3
3OjSGLh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqt
4GcoAgsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2J
5jt+dqk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qt
6wjqvWp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK
7+FMOGnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4Z
8SJCBQw5zAoGAYzOpPmh8Je1IDauEXhgaLz14wqYUHHcrj2VWVJ6fRm8GhdQFJSI7
9GUk08pgKZSKic2lNqxuzW7/vFxKQ/nvzfytY16b+2i+BR4Q6yvMzCebE1hHVg0Ju
10TwfUMwoFEOhYP6ZwHSUiQl9IBMH9TNJCMwYMxfY+VOrURFsjGTRUgpwCFQCIGt5g
11Y+XZd0Sv69CatDIRYWvaIA==
12-----END DSA PRIVATE KEY-----
13-----BEGIN CERTIFICATE-----
14MIIDpDCCAw2gAwIBAgIJAMtotfHYdEsYMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
15BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
16TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
17CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
18ZXN0IFMvTUlNRSBFRSBEU0EgIzMwggG3MIIBLAYHKoZIzjgEATCCAR8CgYEAxSX7
19CDziGsDDuW4sPgKGFITVcUXgTi0KLFN0L+AfJK2nNATa9zo0hi4dcGcR6oZQBNEJ
20mrE2iqI7pNtJzVnhZ3M0s+rw5dCFSRIUvFWKK+ZLfYC6rRnKAILH+IEQyLrSckA2
21jZ9yFWPPbl1FSKHsb0Hi0AwQoEDwuTvKyXagcLcCFQCtiY7fnapNO3kFBOfZKGFB
22CsjaKwKBgQCOCBKbrH/BteJAh5kbZx1zNrRuRFiQ5lukLcI6r1qdRilMeVhctbVV
23kfZ5eay9A4vpDXRDaPkpCo+4d7g7pRjiOk9JkGG1dodSCvhTDhpzqr2fHjUxNp+D
24xk6OabmetywZvkGK0LKzYlGOL2pCxUNqxCv0i8HbAxSuGUiQgUMOcwOBhAACgYBj
25M6k+aHwl7UgNq4ReGBovPXjCphQcdyuPZVZUnp9GbwaF1AUlIjsZSTTymAplIqJz
26aU2rG7Nbv+8XEpD+e/N/K1jXpv7aL4FHhDrK8zMJ5sTWEdWDQm5PB9QzCgUQ6Fg/
27pnAdJSJCX0gEwf1M0kIzBgzF9j5U6tREWyMZNFSCnKOBgzCBgDAdBgNVHQ4EFgQU
28VhpVXqQ/EzUMdxLvP7o9EhJ8h70wHwYDVR0jBBgwFoAUE89Lp7uJLrM4Vxd2xput
29aFvl7RcwDAYDVR0TAQH/BAIwADAOBgNVHQ8BAf8EBAMCBsAwIAYDVR0RBBkwF4EV
30c21pbWVkc2EzQG9wZW5zc2wub3JnMA0GCSqGSIb3DQEBBQUAA4GBACM9e75EQa8m
31k/AZkH/tROqf3yeqijULl9x8FjFatqoY+29OM6oMGM425IqSkKd2ipz7OxO0SShu
32rE0O3edS7DvYBwvhWPviRaYBMyZ4iFJVup+fOzoYK/j/bASxS3BHQBwb2r4rhe25
33OlTyyFEk7DJyW18YFOG97S1P52oQ5f5x
34-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/smime-certs/smdsap.pem b/src/lib/libssl/test/smime-certs/smdsap.pem
deleted file mode 100644
index 249706c8c7..0000000000
--- a/src/lib/libssl/test/smime-certs/smdsap.pem
+++ /dev/null
@@ -1,9 +0,0 @@
1-----BEGIN DSA PARAMETERS-----
2MIIBHwKBgQDFJfsIPOIawMO5biw+AoYUhNVxReBOLQosU3Qv4B8krac0BNr3OjSG
3Lh1wZxHqhlAE0QmasTaKojuk20nNWeFnczSz6vDl0IVJEhS8VYor5kt9gLqtGcoA
4gsf4gRDIutJyQDaNn3IVY89uXUVIoexvQeLQDBCgQPC5O8rJdqBwtwIVAK2Jjt+d
5qk07eQUE59koYUEKyNorAoGBAI4IEpusf8G14kCHmRtnHXM2tG5EWJDmW6Qtwjqv
6Wp1GKUx5WFy1tVWR9nl5rL0Di+kNdENo+SkKj7h3uDulGOI6T0mQYbV2h1IK+FMO
7GnOqvZ8eNTE2n4PGTo5puZ63LBm+QYrQsrNiUY4vakLFQ2rEK/SLwdsDFK4ZSJCB
8Qw5z
9-----END DSA PARAMETERS-----
diff --git a/src/lib/libssl/test/smime-certs/smroot.pem b/src/lib/libssl/test/smime-certs/smroot.pem
deleted file mode 100644
index a59eb2684c..0000000000
--- a/src/lib/libssl/test/smime-certs/smroot.pem
+++ /dev/null
@@ -1,30 +0,0 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXAIBAAKBgQDBV1Z/Q5gPF7lojc8pKUdyz5+Jf2B3vs4he6egekugWnoJduki
39Lnae/JchB/soIX0co3nLc11NuFFlnAWJNMDJr08l5AHAJLYNHevF5l/f9oDQwvZ
4speKh1xpIAJNqCTzVeQ/ZLx6/GccIXV/xDuKIiovqJTPgR5WPkYKaw++lQIDAQAB
5AoGALXnUj5SflJU4+B2652ydMKUjWl0KnL/VjkyejgGV/j6py8Ybaixz9q8Gv7oY
6JDlRqMC1HfZJCFQDQrHy5VJ+CywA/H9WrqKo/Ch9U4tJAZtkig1Cmay/BAYixVu0
7xBeim10aKF6hxHH4Chg9We+OCuzWBWJhqveNjuDedL/i7JUCQQDlejovcwBUCbhJ
8U12qKOwlaboolWbl7yF3XdckTJZg7+1UqQHZH5jYZlLZyZxiaC92SNV0SyTLJZnS
9Jh5CO+VDAkEA16/pPcuVtMMz/R6SSPpRSIAa1stLs0mFSs3NpR4pdm0n42mu05pO
101tJEt3a1g7zkreQBf53+Dwb+lA841EkjRwJBAIFmt0DifKDnCkBu/jZh9SfzwsH3
113Zpzik+hXxxdA7+ODCrdUul449vDd5zQD5t+XKU61QNLDGhxv5e9XvrCg7kCQH/a
123ldsVF0oDaxxL+QkxoREtCQ5tLEd1u7F2q6Tl56FDE0pe6Ih6bQ8RtG+g9EI60IN
13U7oTrOO5kLWx5E0q4ccCQAZVgoenn9MhRU1agKOCuM6LT2DxReTu4XztJzynej+8
140J93n3ebanB1MlRpn1XJwhQ7gAC8ImaQKLJK5jdJzFc=
15-----END RSA PRIVATE KEY-----
16-----BEGIN CERTIFICATE-----
17MIICaTCCAdKgAwIBAgIJAP6VN47boiXRMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
18BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
19TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDdaFw0xNjA1MTExMzUzMDdaMEQx
20CzAJBgNVBAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRU
21ZXN0IFMvTUlNRSBSU0EgUm9vdDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA
22wVdWf0OYDxe5aI3PKSlHcs+fiX9gd77OIXunoHpLoFp6CXbpIvS52nvyXIQf7KCF
239HKN5y3NdTbhRZZwFiTTAya9PJeQBwCS2DR3rxeZf3/aA0ML2bKXiodcaSACTagk
2481XkP2S8evxnHCF1f8Q7iiIqL6iUz4EeVj5GCmsPvpUCAwEAAaNjMGEwHQYDVR0O
25BBYEFBPPS6e7iS6zOFcXdsabrWhb5e0XMB8GA1UdIwQYMBaAFBPPS6e7iS6zOFcX
26dsabrWhb5e0XMA8GA1UdEwEB/wQFMAMBAf8wDgYDVR0PAQH/BAQDAgEGMA0GCSqG
27SIb3DQEBBQUAA4GBAIECprq5viDvnDbkyOaiSr9ubMUmWqvycfAJMdPZRKcOZczS
28l+L9R9lF3JSqbt3knOe9u6bGDBOTY2285PdCCuHRVMk2Af1f6El1fqAlRUwNqipp
29r68sWFuRqrcRNtk6QQvXfkOhrqQBuDa7te/OVQLa2lGN9Dr2mQsD8ijctatG
30-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/smime-certs/smrsa1.pem b/src/lib/libssl/test/smime-certs/smrsa1.pem
deleted file mode 100644
index 2cf3148e33..0000000000
--- a/src/lib/libssl/test/smime-certs/smrsa1.pem
+++ /dev/null
@@ -1,31 +0,0 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXgIBAAKBgQC6A978j4pmPgUtUQqF+bjh6vdhwGOGZSD7xXgFTMjm88twfv+E
3ixkq2KXSDjD0ZXoQbdOaSbvGRQrIJpG2NGiKAFdYNrP025kCCdh5wF/aEI7KLEm7
4JlHwXpQsuj4wkMgmkFjL3Ty4Z55aNH+2pPQIa0k+ENJXm2gDuhqgBmduAwIDAQAB
5AoGBAJMuYu51aO2THyeHGwt81uOytcCbqGP7eoib62ZOJhxPRGYjpmuqX+R9/V5i
6KiwGavm63JYUx0WO9YP+uIZxm1BUATzkgkS74u5LP6ajhkZh6/Bck1oIYYkbVOXl
7JVrdENuH6U7nupznsyYgONByo+ykFPVUGmutgiaC7NMVo/MxAkEA6KLejWXdCIEn
8xr7hGph9NlvY9xuRIMexRV/WrddcFfCdjI1PciIupgrIkR65M9yr7atm1iU6/aRf
9KOr8rLZsSQJBAMyyXN71NsDNx4BP6rtJ/LJMP0BylznWkA7zWfGCbAYn9VhZVlSY
10Eu9Gyr7quD1ix7G3kInKVYOEEOpockBLz+sCQQCedyMmKjcQLfpMVYW8uhbAynvW
11h36qV5yXZxszO7nMcCTBsxhk5IfmLv5EbCs3+p9avCDGyoGOeUMg+kC33WORAkAg
12oUIarH4o5+SoeJTTfCzTA0KF9H5U0vYt2+73h7HOnWoHxl3zqDZEfEVvf50U8/0f
13QELDJETTbScBJtsnkq43AkEA38etvoZ2i4FJvvo7R/9gWBHVEcrGzcsCBYrNnIR1
14SZLRwHEGaiOK1wxMsWzqp7PJwL9z/M8A8DyOFBx3GPOniA==
15-----END RSA PRIVATE KEY-----
16-----BEGIN CERTIFICATE-----
17MIICizCCAfSgAwIBAgIJAMtotfHYdEsTMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
18BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
19TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDhaFw0xNjA1MTAxMzUzMDhaMEUx
20CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
21ZXN0IFMvTUlNRSBFRSBSU0EgIzEwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
22ALoD3vyPimY+BS1RCoX5uOHq92HAY4ZlIPvFeAVMyObzy3B+/4SLGSrYpdIOMPRl
23ehBt05pJu8ZFCsgmkbY0aIoAV1g2s/TbmQIJ2HnAX9oQjsosSbsmUfBelCy6PjCQ
24yCaQWMvdPLhnnlo0f7ak9AhrST4Q0lebaAO6GqAGZ24DAgMBAAGjgYMwgYAwHQYD
25VR0OBBYEFE2vMvKz5jrC7Lbdg68XwZ95iL/QMB8GA1UdIwQYMBaAFBPPS6e7iS6z
26OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud
27EQQZMBeBFXNtaW1lcnNhMUBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQAi
28O3GOkUl646oLnOimc36i9wxZ1tejsqs8vMjJ0Pym6Uq9FE2JoGzJ6OhB1GOsEVmj
299cQ5UNQcRYL3cqOFtl6f4Dpu/lhzfbaqgmLjv29G1mS0uuTZrixhlyCXjwcbOkNC
30I/+wvHHENYIK5+T/79M9LaZ2Qk4F9MNE1VMljdz9Qw==
31-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/smime-certs/smrsa2.pem b/src/lib/libssl/test/smime-certs/smrsa2.pem
deleted file mode 100644
index d41f69c82f..0000000000
--- a/src/lib/libssl/test/smime-certs/smrsa2.pem
+++ /dev/null
@@ -1,31 +0,0 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICWwIBAAKBgQCwBfryW4Vu5U9wNIDKspJO/N9YF4CcTlrCUyzVlKgb+8urHlSe
359i5verR9IOCCXkemjOzZ/3nALTGqYZlnEvHp0Rjk+KdKXnKBIB+SRPpeu3LcXMT
4WPgsThPa0UQxedNKG0g6aG+kLhsDlFBCoxd09jJtSpb9jmroJOq0ZYEHLwIDAQAB
5AoGAKa/w4677Je1W5+r3SYoLDnvi5TkDs4D3C6ipKJgBTEdQz+DqB4w/DpZE4551
6+rkFn1LDxcxuHGRVa+tAMhZW97fwq9YUbjVZEyOz79qrX+BMyl/NbHkf1lIKDo3q
7dWalzQvop7nbzeLC+VmmviwZfLQUbA61AQl3jm4dswT4XykCQQDloDadEv/28NTx
8bvvywvyGuvJkCkEIycm4JrIInvwsd76h/chZ3oymrqzc7hkEtK6kThqlS5y+WXl6
9QzPruTKTAkEAxD2ro/VUoN+scIVaLmn0RBmZ67+9Pdn6pNSfjlK3s0T0EM6/iUWS
10M06l6L9wFS3/ceu1tIifsh9BeqOGTa+udQJARIFnybTBaIqw/NZ/lA1YCVn8tpvY
11iyaoZ6gjtS65TQrsdKeh/i3HCHNUXxUpoZ3F/H7QtD+6o49ODou+EbVOwQJAVmex
12A2gp8wuJKaINqxIL81AybZLnCCzKJ3lXJ5tUNyLNM/lUbGStktm2Q1zHRQwTxV07
13jFn7trn8YrtNjzcjYQJAUKIJRt38A8Jw3HoPT+D0WS2IgxjVL0eYGsZX1lyeammG
146rfnQ3u5uP7mEK2EH2o8mDUpAE0gclWBU9UkKxJsGA==
15-----END RSA PRIVATE KEY-----
16-----BEGIN CERTIFICATE-----
17MIICizCCAfSgAwIBAgIJAMtotfHYdEsUMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
18BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
19TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDhaFw0xNjA1MTAxMzUzMDhaMEUx
20CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
21ZXN0IFMvTUlNRSBFRSBSU0EgIzIwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
22ALAF+vJbhW7lT3A0gMqykk7831gXgJxOWsJTLNWUqBv7y6seVJ7n2Lm96tH0g4IJ
23eR6aM7Nn/ecAtMaphmWcS8enRGOT4p0pecoEgH5JE+l67ctxcxNY+CxOE9rRRDF5
2400obSDpob6QuGwOUUEKjF3T2Mm1Klv2Oaugk6rRlgQcvAgMBAAGjgYMwgYAwHQYD
25VR0OBBYEFIL/u+mEvaw7RuKLRuElfVkxSQjYMB8GA1UdIwQYMBaAFBPPS6e7iS6z
26OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud
27EQQZMBeBFXNtaW1lcnNhMkBvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQC2
28rXR5bm/9RtOMQPleNpd3y6uUX3oy+0CafK5Yl3PMnItjjnKJ0l1/DbLbDj2twehe
29ewaB8CROcBCA3AMLSmGvPKgUCFMGtWam3328M4fBHzon5ka7qDXzM+imkAly/Yx2
30YNdR/aNOug+5sXygHmTSKqiCpQjOIClzXoPVVeEVHw==
31-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/smime-certs/smrsa3.pem b/src/lib/libssl/test/smime-certs/smrsa3.pem
deleted file mode 100644
index c8cbe55151..0000000000
--- a/src/lib/libssl/test/smime-certs/smrsa3.pem
+++ /dev/null
@@ -1,31 +0,0 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIICXAIBAAKBgQC6syTZtZNe1hRScFc4PUVyVLsr7+C1HDIZnOHmwFoLayX6RHwy
3ep/TkdwiPHnemVLuwvpSjLMLZkXy/J764kSHJrNeVl3UvmCVCOm40hAtK1+F39pM
4h8phkbPPD7i+hwq4/Vs79o46nzwbVKmzgoZBJhZ+codujUSYM3LjJ4aq+wIDAQAB
5AoGAE1Zixrnr3bLGwBMqtYSDIOhtyos59whImCaLr17U9MHQWS+mvYO98if1aQZi
6iQ/QazJ+wvYXxWJ+dEB+JvYwqrGeuAU6He/rAb4OShG4FPVU2D19gzRnaButWMeT
7/1lgXV08hegGBL7RQNaN7b0viFYMcKnSghleMP0/q+Y/oaECQQDkXEwDYJW13X9p
8ijS20ykWdY5lLknjkHRhhOYux0rlhOqsyMZjoUmwI2m0qj9yrIysKhrk4MZaM/uC
9hy0xp3hdAkEA0Uv/UY0Kwsgc+W6YxeypECtg1qCE6FBib8n4iFy/6VcWqhvE5xrs
10OdhKv9/p6aLjLneGd1sU+F8eS9LGyKIbNwJBAJPgbNzXA7uUZriqZb5qeTXxBDfj
11RLfXSHYKAKEULxz3+JvRHB9SR4yHMiFrCdExiZrHXUkPgYLSHLGG5a4824UCQD6T
129XvhquUARkGCAuWy0/3Eqoihp/t6BWSdQ9Upviu7YUhtUxsyXo0REZB7F4pGrJx5
13GlhXgFaewgUzuUHFzlMCQCzJMMWslWpoLntnR6sMhBMhBFHSw+Y5CbxBmFrdtSkd
14VdtNO1VuDCTxjjW7W3Khj7LX4KZ1ye/5jfAgnnnXisc=
15-----END RSA PRIVATE KEY-----
16-----BEGIN CERTIFICATE-----
17MIICizCCAfSgAwIBAgIJAMtotfHYdEsVMA0GCSqGSIb3DQEBBQUAMEQxCzAJBgNV
18BAYTAlVLMRYwFAYDVQQKEw1PcGVuU1NMIEdyb3VwMR0wGwYDVQQDExRUZXN0IFMv
19TUlNRSBSU0EgUm9vdDAeFw0wODAyMjIxMzUzMDlaFw0xNjA1MTAxMzUzMDlaMEUx
20CzAJBgNVBAYTAlVLMRYwFAYDVQQKDA1PcGVuU1NMIEdyb3VwMR4wHAYDVQQDDBVU
21ZXN0IFMvTUlNRSBFRSBSU0EgIzMwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGB
22ALqzJNm1k17WFFJwVzg9RXJUuyvv4LUcMhmc4ebAWgtrJfpEfDJ6n9OR3CI8ed6Z
23Uu7C+lKMswtmRfL8nvriRIcms15WXdS+YJUI6bjSEC0rX4Xf2kyHymGRs88PuL6H
24Crj9Wzv2jjqfPBtUqbOChkEmFn5yh26NRJgzcuMnhqr7AgMBAAGjgYMwgYAwHQYD
25VR0OBBYEFDsSFjNtYZzd0tTHafNS7tneQQj6MB8GA1UdIwQYMBaAFBPPS6e7iS6z
26OFcXdsabrWhb5e0XMAwGA1UdEwEB/wQCMAAwDgYDVR0PAQH/BAQDAgXgMCAGA1Ud
27EQQZMBeBFXNtaW1lcnNhM0BvcGVuc3NsLm9yZzANBgkqhkiG9w0BAQUFAAOBgQBE
28tUDB+1Dqigu4p1xtdq7JRK6S+gfA7RWmhz0j2scb2zhpS12h37JLHsidGeKAzZYq
29jUjOrH/j3xcV5AnuJoqImJaN23nzzxtR4qGGX2mrq6EtObzdEGgCUaizsGM+0slJ
30PYxcy8KeY/63B1BpYhj2RjGkL6HrvuAaxVORa3acoA==
31-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/tcrl b/src/lib/libssl/test/tcrl
deleted file mode 100644
index 055269eab8..0000000000
--- a/src/lib/libssl/test/tcrl
+++ /dev/null
@@ -1,78 +0,0 @@
1#!/bin/sh
2
3cmd='../util/shlib_wrap.sh ../apps/openssl crl'
4
5if [ "$1"x != "x" ]; then
6 t=$1
7else
8 t=testcrl.pem
9fi
10
11echo testing crl conversions
12cp $t fff.p
13
14echo "p -> d"
15$cmd -in fff.p -inform p -outform d >f.d
16if [ $? != 0 ]; then exit 1; fi
17#echo "p -> t"
18#$cmd -in fff.p -inform p -outform t >f.t
19#if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27#echo "t -> d"
28#$cmd -in f.t -inform t -outform d >ff.d2
29#if [ $? != 0 ]; then exit 1; fi
30echo "p -> d"
31$cmd -in f.p -inform p -outform d >ff.d3
32if [ $? != 0 ]; then exit 1; fi
33
34#echo "d -> t"
35#$cmd -in f.d -inform d -outform t >ff.t1
36#if [ $? != 0 ]; then exit 1; fi
37#echo "t -> t"
38#$cmd -in f.t -inform t -outform t >ff.t2
39#if [ $? != 0 ]; then exit 1; fi
40#echo "p -> t"
41#$cmd -in f.p -inform p -outform t >ff.t3
42#if [ $? != 0 ]; then exit 1; fi
43
44echo "d -> p"
45$cmd -in f.d -inform d -outform p >ff.p1
46if [ $? != 0 ]; then exit 1; fi
47#echo "t -> p"
48#$cmd -in f.t -inform t -outform p >ff.p2
49#if [ $? != 0 ]; then exit 1; fi
50echo "p -> p"
51$cmd -in f.p -inform p -outform p >ff.p3
52if [ $? != 0 ]; then exit 1; fi
53
54cmp fff.p f.p
55if [ $? != 0 ]; then exit 1; fi
56cmp fff.p ff.p1
57if [ $? != 0 ]; then exit 1; fi
58#cmp fff.p ff.p2
59#if [ $? != 0 ]; then exit 1; fi
60cmp fff.p ff.p3
61if [ $? != 0 ]; then exit 1; fi
62
63#cmp f.t ff.t1
64#if [ $? != 0 ]; then exit 1; fi
65#cmp f.t ff.t2
66#if [ $? != 0 ]; then exit 1; fi
67#cmp f.t ff.t3
68#if [ $? != 0 ]; then exit 1; fi
69
70cmp f.p ff.p1
71if [ $? != 0 ]; then exit 1; fi
72#cmp f.p ff.p2
73#if [ $? != 0 ]; then exit 1; fi
74cmp f.p ff.p3
75if [ $? != 0 ]; then exit 1; fi
76
77/bin/rm -f f.* ff.* fff.*
78exit 0
diff --git a/src/lib/libssl/test/test.cnf b/src/lib/libssl/test/test.cnf
deleted file mode 100644
index 10834442a1..0000000000
--- a/src/lib/libssl/test/test.cnf
+++ /dev/null
@@ -1,88 +0,0 @@
1#
2# SSLeay example configuration file.
3# This is mostly being used for generation of certificate requests.
4#
5
6RANDFILE = ./.rnd
7
8####################################################################
9[ ca ]
10default_ca = CA_default # The default ca section
11
12####################################################################
13[ CA_default ]
14
15dir = ./demoCA # Where everything is kept
16certs = $dir/certs # Where the issued certs are kept
17crl_dir = $dir/crl # Where the issued crl are kept
18database = $dir/index.txt # database index file.
19new_certs_dir = $dir/new_certs # default place for new certs.
20
21certificate = $dir/CAcert.pem # The CA certificate
22serial = $dir/serial # The current serial number
23crl = $dir/crl.pem # The current CRL
24private_key = $dir/private/CAkey.pem# The private key
25RANDFILE = $dir/private/.rand # private random number file
26
27default_days = 365 # how long to certify for
28default_crl_days= 30 # how long before next CRL
29default_md = md5 # which md to use.
30
31# A few difference way of specifying how similar the request should look
32# For type CA, the listed attributes must be the same, and the optional
33# and supplied fields are just that :-)
34policy = policy_match
35
36# For the CA policy
37[ policy_match ]
38countryName = match
39stateOrProvinceName = match
40organizationName = match
41organizationalUnitName = optional
42commonName = supplied
43emailAddress = optional
44
45# For the 'anything' policy
46# At this point in time, you must list all acceptable 'object'
47# types.
48[ policy_anything ]
49countryName = optional
50stateOrProvinceName = optional
51localityName = optional
52organizationName = optional
53organizationalUnitName = optional
54commonName = supplied
55emailAddress = optional
56
57####################################################################
58[ req ]
59default_bits = 1024
60default_keyfile = testkey.pem
61distinguished_name = req_distinguished_name
62encrypt_rsa_key = no
63
64[ req_distinguished_name ]
65countryName = Country Name (2 letter code)
66countryName_default = AU
67countryName_value = AU
68
69stateOrProvinceName = State or Province Name (full name)
70stateOrProvinceName_default = Queensland
71stateOrProvinceName_value =
72
73localityName = Locality Name (eg, city)
74localityName_value = Brisbane
75
76organizationName = Organization Name (eg, company)
77organizationName_default =
78organizationName_value = CryptSoft Pty Ltd
79
80organizationalUnitName = Organizational Unit Name (eg, section)
81organizationalUnitName_default =
82organizationalUnitName_value = .
83
84commonName = Common Name (eg, YOUR name)
85commonName_value = Eric Young
86
87emailAddress = Email Address
88emailAddress_value = eay@mincom.oz.au
diff --git a/src/lib/libssl/test/test_aesni b/src/lib/libssl/test/test_aesni
deleted file mode 100644
index e8fb63ee2b..0000000000
--- a/src/lib/libssl/test/test_aesni
+++ /dev/null
@@ -1,69 +0,0 @@
1#!/bin/sh
2
3PROG=$1
4
5if [ -x $PROG ]; then
6 if expr "x`$PROG version`" : "xOpenSSL" > /dev/null; then
7 :
8 else
9 echo "$PROG is not OpenSSL executable"
10 exit 1
11 fi
12else
13 echo "$PROG is not executable"
14 exit 1;
15fi
16
17if $PROG engine aesni | grep -v no-aesni; then
18
19 HASH=`cat $PROG | $PROG dgst -hex`
20
21 AES_ALGS=" aes-128-ecb aes-192-ecb aes-256-ecb \
22 aes-128-cbc aes-192-cbc aes-256-cbc \
23 aes-128-cfb aes-192-cfb aes-256-cfb \
24 aes-128-ofb aes-192-ofb aes-256-ofb"
25 BUFSIZE="16 32 48 64 80 96 128 144 999"
26
27 nerr=0
28
29 for alg in $AES_ALGS; do
30 echo $alg
31 for bufsize in $BUFSIZE; do
32 TEST=`( cat $PROG | \
33 $PROG enc -e -k "$HASH" -$alg -bufsize $bufsize -engine aesni | \
34 $PROG enc -d -k "$HASH" -$alg | \
35 $PROG dgst -hex ) 2>/dev/null`
36 if [ "$TEST" != "$HASH" ]; then
37 echo "-$alg/$bufsize encrypt test failed"
38 nerr=`expr $nerr + 1`
39 fi
40 done
41 for bufsize in $BUFSIZE; do
42 TEST=`( cat $PROG | \
43 $PROG enc -e -k "$HASH" -$alg | \
44 $PROG enc -d -k "$HASH" -$alg -bufsize $bufsize -engine aesni | \
45 $PROG dgst -hex ) 2>/dev/null`
46 if [ "$TEST" != "$HASH" ]; then
47 echo "-$alg/$bufsize decrypt test failed"
48 nerr=`expr $nerr + 1`
49 fi
50 done
51 TEST=`( cat $PROG | \
52 $PROG enc -e -k "$HASH" -$alg -engine aesni | \
53 $PROG enc -d -k "$HASH" -$alg -engine aesni | \
54 $PROG dgst -hex ) 2>/dev/null`
55 if [ "$TEST" != "$HASH" ]; then
56 echo "-$alg en/decrypt test failed"
57 nerr=`expr $nerr + 1`
58 fi
59 done
60
61 if [ $nerr -gt 0 ]; then
62 echo "AESNI engine test failed."
63 exit 1;
64 fi
65else
66 echo "AESNI engine is not available"
67fi
68
69exit 0
diff --git a/src/lib/libssl/test/test_padlock b/src/lib/libssl/test/test_padlock
deleted file mode 100755
index 5c0f21043c..0000000000
--- a/src/lib/libssl/test/test_padlock
+++ /dev/null
@@ -1,64 +0,0 @@
1#!/bin/sh
2
3PROG=$1
4
5if [ -x $PROG ]; then
6 if expr "x`$PROG version`" : "xOpenSSL" > /dev/null; then
7 :
8 else
9 echo "$PROG is not OpenSSL executable"
10 exit 1
11 fi
12else
13 echo "$PROG is not executable"
14 exit 1;
15fi
16
17if $PROG engine padlock | grep -v no-ACE; then
18
19 HASH=`cat $PROG | $PROG dgst -hex`
20
21 ACE_ALGS=" aes-128-ecb aes-192-ecb aes-256-ecb \
22 aes-128-cbc aes-192-cbc aes-256-cbc \
23 aes-128-cfb aes-192-cfb aes-256-cfb \
24 aes-128-ofb aes-192-ofb aes-256-ofb"
25
26 nerr=0
27
28 for alg in $ACE_ALGS; do
29 echo $alg
30 TEST=`( cat $PROG | \
31 $PROG enc -e -k "$HASH" -$alg -bufsize 999 -engine padlock | \
32 $PROG enc -d -k "$HASH" -$alg | \
33 $PROG dgst -hex ) 2>/dev/null`
34 if [ "$TEST" != "$HASH" ]; then
35 echo "-$alg encrypt test failed"
36 nerr=`expr $nerr + 1`
37 fi
38 TEST=`( cat $PROG | \
39 $PROG enc -e -k "$HASH" -$alg | \
40 $PROG enc -d -k "$HASH" -$alg -bufsize 999 -engine padlock | \
41 $PROG dgst -hex ) 2>/dev/null`
42 if [ "$TEST" != "$HASH" ]; then
43 echo "-$alg decrypt test failed"
44 nerr=`expr $nerr + 1`
45 fi
46 TEST=`( cat $PROG | \
47 $PROG enc -e -k "$HASH" -$alg -engine padlock | \
48 $PROG enc -d -k "$HASH" -$alg -engine padlock | \
49 $PROG dgst -hex ) 2>/dev/null`
50 if [ "$TEST" != "$HASH" ]; then
51 echo "-$alg en/decrypt test failed"
52 nerr=`expr $nerr + 1`
53 fi
54 done
55
56 if [ $nerr -gt 0 ]; then
57 echo "PadLock ACE test failed."
58 exit 1;
59 fi
60else
61 echo "PadLock ACE is not available"
62fi
63
64exit 0
diff --git a/src/lib/libssl/test/testca b/src/lib/libssl/test/testca
deleted file mode 100644
index b109cfe271..0000000000
--- a/src/lib/libssl/test/testca
+++ /dev/null
@@ -1,51 +0,0 @@
1#!/bin/sh
2
3SH="/bin/sh"
4if test "$OSTYPE" = msdosdjgpp; then
5 PATH="../apps\;$PATH"
6else
7 PATH="../apps:$PATH"
8fi
9export SH PATH
10
11SSLEAY_CONFIG="-config CAss.cnf"
12export SSLEAY_CONFIG
13
14OPENSSL="`pwd`/../util/opensslwrap.sh"
15export OPENSSL
16
17/bin/rm -fr demoCA
18$SH ../apps/CA.sh -newca <<EOF
19EOF
20
21if [ $? != 0 ]; then
22 exit 1;
23fi
24
25SSLEAY_CONFIG="-config Uss.cnf"
26export SSLEAY_CONFIG
27$SH ../apps/CA.sh -newreq
28if [ $? != 0 ]; then
29 exit 1;
30fi
31
32
33SSLEAY_CONFIG="-config ../apps/openssl.cnf"
34export SSLEAY_CONFIG
35$SH ../apps/CA.sh -sign <<EOF
36y
37y
38EOF
39if [ $? != 0 ]; then
40 exit 1;
41fi
42
43
44$SH ../apps/CA.sh -verify newcert.pem
45if [ $? != 0 ]; then
46 exit 1;
47fi
48
49/bin/rm -fr demoCA newcert.pem newreq.pem
50#usage: CA -newcert|-newreq|-newca|-sign|-verify
51
diff --git a/src/lib/libssl/test/testcrl.pem b/src/lib/libssl/test/testcrl.pem
deleted file mode 100644
index 0989788354..0000000000
--- a/src/lib/libssl/test/testcrl.pem
+++ /dev/null
@@ -1,16 +0,0 @@
1-----BEGIN X509 CRL-----
2MIICjTCCAfowDQYJKoZIhvcNAQECBQAwXzELMAkGA1UEBhMCVVMxIDAeBgNVBAoT
3F1JTQSBEYXRhIFNlY3VyaXR5LCBJbmMuMS4wLAYDVQQLEyVTZWN1cmUgU2VydmVy
4IENlcnRpZmljYXRpb24gQXV0aG9yaXR5Fw05NTA1MDIwMjEyMjZaFw05NTA2MDEw
5MDAxNDlaMIIBaDAWAgUCQQAABBcNOTUwMjAxMTcyNDI2WjAWAgUCQQAACRcNOTUw
6MjEwMDIxNjM5WjAWAgUCQQAADxcNOTUwMjI0MDAxMjQ5WjAWAgUCQQAADBcNOTUw
7MjI1MDA0NjQ0WjAWAgUCQQAAGxcNOTUwMzEzMTg0MDQ5WjAWAgUCQQAAFhcNOTUw
8MzE1MTkxNjU0WjAWAgUCQQAAGhcNOTUwMzE1MTk0MDQxWjAWAgUCQQAAHxcNOTUw
9MzI0MTk0NDMzWjAWAgUCcgAABRcNOTUwMzI5MjAwNzExWjAWAgUCcgAAERcNOTUw
10MzMwMDIzNDI2WjAWAgUCQQAAIBcNOTUwNDA3MDExMzIxWjAWAgUCcgAAHhcNOTUw
11NDA4MDAwMjU5WjAWAgUCcgAAQRcNOTUwNDI4MTcxNzI0WjAWAgUCcgAAOBcNOTUw
12NDI4MTcyNzIxWjAWAgUCcgAATBcNOTUwNTAyMDIxMjI2WjANBgkqhkiG9w0BAQIF
13AAN+AHqOEJXSDejYy0UwxxrH/9+N2z5xu/if0J6qQmK92W0hW158wpJg+ovV3+wQ
14wvIEPRL2rocL0tKfAsVq1IawSJzSNgxG0lrcla3MrJBnZ4GaZDu4FutZh72MR3Gt
15JaAL3iTJHJD55kK2D/VoyY1djlsPuNh6AEgdVwFAyp0v
16-----END X509 CRL-----
diff --git a/src/lib/libssl/test/testenc b/src/lib/libssl/test/testenc
deleted file mode 100644
index f5ce7c0c45..0000000000
--- a/src/lib/libssl/test/testenc
+++ /dev/null
@@ -1,54 +0,0 @@
1#!/bin/sh
2
3testsrc=Makefile
4test=./p
5cmd="../util/shlib_wrap.sh ../apps/openssl"
6
7cat $testsrc >$test;
8
9echo cat
10$cmd enc < $test > $test.cipher
11$cmd enc < $test.cipher >$test.clear
12cmp $test $test.clear
13if [ $? != 0 ]
14then
15 exit 1
16else
17 /bin/rm $test.cipher $test.clear
18fi
19echo base64
20$cmd enc -a -e < $test > $test.cipher
21$cmd enc -a -d < $test.cipher >$test.clear
22cmp $test $test.clear
23if [ $? != 0 ]
24then
25 exit 1
26else
27 /bin/rm $test.cipher $test.clear
28fi
29
30for i in `$cmd list-cipher-commands`
31do
32 echo $i
33 $cmd $i -bufsize 113 -e -k test < $test > $test.$i.cipher
34 $cmd $i -bufsize 157 -d -k test < $test.$i.cipher >$test.$i.clear
35 cmp $test $test.$i.clear
36 if [ $? != 0 ]
37 then
38 exit 1
39 else
40 /bin/rm $test.$i.cipher $test.$i.clear
41 fi
42
43 echo $i base64
44 $cmd $i -bufsize 113 -a -e -k test < $test > $test.$i.cipher
45 $cmd $i -bufsize 157 -a -d -k test < $test.$i.cipher >$test.$i.clear
46 cmp $test $test.$i.clear
47 if [ $? != 0 ]
48 then
49 exit 1
50 else
51 /bin/rm $test.$i.cipher $test.$i.clear
52 fi
53done
54rm -f $test
diff --git a/src/lib/libssl/test/testgen b/src/lib/libssl/test/testgen
deleted file mode 100644
index 524c0d134c..0000000000
--- a/src/lib/libssl/test/testgen
+++ /dev/null
@@ -1,44 +0,0 @@
1#!/bin/sh
2
3T=testcert
4KEY=512
5CA=../certs/testca.pem
6
7/bin/rm -f $T.1 $T.2 $T.key
8
9if test "$OSTYPE" = msdosdjgpp; then
10 PATH=../apps\;$PATH;
11else
12 PATH=../apps:$PATH;
13fi
14export PATH
15
16echo "generating certificate request"
17
18echo "string to make the random number generator think it has entropy" >> ./.rnd
19
20if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
21 req_new='-newkey dsa:../apps/dsa512.pem'
22else
23 req_new='-new'
24 echo "There should be a 2 sequences of .'s and some +'s."
25 echo "There should not be more that at most 80 per line"
26fi
27
28echo "This could take some time."
29
30rm -f testkey.pem testreq.pem
31
32../util/shlib_wrap.sh ../apps/openssl req -config test.cnf $req_new -out testreq.pem
33if [ $? != 0 ]; then
34echo problems creating request
35exit 1
36fi
37
38../util/shlib_wrap.sh ../apps/openssl req -config test.cnf -verify -in testreq.pem -noout
39if [ $? != 0 ]; then
40echo signature on req is wrong
41exit 1
42fi
43
44exit 0
diff --git a/src/lib/libssl/test/testp7.pem b/src/lib/libssl/test/testp7.pem
deleted file mode 100644
index e5b7866c31..0000000000
--- a/src/lib/libssl/test/testp7.pem
+++ /dev/null
@@ -1,46 +0,0 @@
1-----BEGIN PKCS7-----
2MIIIGAYJKoZIhvcNAQcCoIIICTCCCAUCAQExADALBgkqhkiG9w0BBwGgggY8MIIE
3cjCCBBygAwIBAgIQeS+OJfWJUZAx6cX0eAiMjzANBgkqhkiG9w0BAQQFADBiMREw
4DwYDVQQHEwhJbnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNV
5BAsTK1ZlcmlTaWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXIw
6HhcNOTYwNzE5MDAwMDAwWhcNOTcwMzMwMjM1OTU5WjCB1TERMA8GA1UEBxMISW50
7ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2ln
8biBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyMSgwJgYDVQQLEx9E
9aWdpdGFsIElEIENsYXNzIDEgLSBTTUlNRSBUZXN0MUcwRQYDVQQLEz53d3cudmVy
10aXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEuMCBJbmMuIGJ5IFJlZi4sTElBQi5M
11VEQoYyk5NjBbMA0GCSqGSIb3DQEBAQUAA0oAMEcCQA7LvHEIAiQ5+4gDYvJGnGAq
12UM5GXyG11diEXmIEZTHUZhorooX5sr8IIjSXiPY59YYUFSvAaharFM1xaBN8zNEC
13AwEAAaOCAjkwggI1MAkGA1UdEwQCMAAwggImBgNVHQMEggIdMIICGTCCAhUwggIR
14BgtghkgBhvhFAQcBATCCAgAWggGrVGhpcyBjZXJ0aWZpY2F0ZSBpbmNvcnBvcmF0
15ZXMgYnkgcmVmZXJlbmNlLCBhbmQgaXRzIHVzZSBpcyBzdHJpY3RseSBzdWJqZWN0
16IHRvLCB0aGUgVmVyaVNpZ24gQ2VydGlmaWNhdGlvbiBQcmFjdGljZSBTdGF0ZW1l
17bnQgKENQUyksIGF2YWlsYWJsZSBhdDogaHR0cHM6Ly93d3cudmVyaXNpZ24uY29t
18L0NQUy0xLjA7IGJ5IEUtbWFpbCBhdCBDUFMtcmVxdWVzdHNAdmVyaXNpZ24uY29t
19OyBvciBieSBtYWlsIGF0IFZlcmlTaWduLCBJbmMuLCAyNTkzIENvYXN0IEF2ZS4s
20IE1vdW50YWluIFZpZXcsIENBIDk0MDQzIFVTQSBUZWwuICsxICg0MTUpIDk2MS04
21ODMwIENvcHlyaWdodCAoYykgMTk5NiBWZXJpU2lnbiwgSW5jLiAgQWxsIFJpZ2h0
22cyBSZXNlcnZlZC4gQ0VSVEFJTiBXQVJSQU5USUVTIERJU0NMQUlNRUQgYW5kIExJ
23QUJJTElUWSBMSU1JVEVELqAOBgxghkgBhvhFAQcBAQGhDgYMYIZIAYb4RQEHAQEC
24MC8wLRYraHR0cHM6Ly93d3cudmVyaXNpZ24uY29tL3JlcG9zaXRvcnkvQ1BTLTEu
25AzANBgkqhkiG9w0BAQQFAANBAMCYDuSb/eIlYSxY31nZZTaCZkCSfHjlacMofExr
26cF+A2yHoEuT+eCQkqM0pMNHXddUeoQ9RjV+VuMBNmm63DUYwggHCMIIBbKADAgEC
27AhB8CYTq1bkRFJBYOd67cp9JMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
28MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
29QTAeFw05NjA3MTcwMDAwMDBaFw05NzA3MTcyMzU5NTlaMGIxETAPBgNVBAcTCElu
30dGVybmV0MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjE0MDIGA1UECxMrVmVyaVNp
31Z24gQ2xhc3MgMSBDQSAtIEluZGl2aWR1YWwgU3Vic2NyaWJlcjBcMA0GCSqGSIb3
32DQEBAQUAA0sAMEgCQQDsVzrNgnDhbAJZrWeLd9g1vMZJA2W67D33TTbga6yMt+ES
33TWEywhS6RNP+fzLGg7utinjH4tL60cXa0G27GDsLAgMBAAGjIjAgMAsGA1UdDwQE
34AwIBBjARBglghkgBhvhCAQEEBAMCAgQwDQYJKoZIhvcNAQECBQADQQAUp6bRwkaD
352d1MBs/mjUcgTI2fXVmW8tTm/Ud6OzUwpC3vYgybiOOA4f6mOC5dbyUHrLOsrihU
3647ZQ0Jo1DUfboYIBrTCBwTBtMA0GCSqGSIb3DQEBAgUAMD4xCzAJBgNVBAYTAlVT
37MRcwFQYDVQQKEw5WZXJpU2lnbiwgSW5jLjEWMBQGA1UECxMNVEVTVCBSb290IFBD
38QRcNOTYwNzE3MTc0NDA5WhcNOTgwNzE3MDAwMDAwWjANBgkqhkiG9w0BAQIFAANB
39AHitA0/xAukCjHzeh1AMT/l2oC68N+yFb+aJPHBBMxc6gG2MaKjBNwb5hcXUllMl
40ExONA3ju10f7owIq3s3wx10wgeYwgZEwDQYJKoZIhvcNAQECBQAwYjERMA8GA1UE
41BxMISW50ZXJuZXQxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytW
42ZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5kaXZpZHVhbCBTdWJzY3JpYmVyFw05NjA3
43MTcxNzU5MjlaFw05NzA3MTgwMDAwMDBaMA0GCSqGSIb3DQEBAgUAA0EAubVWYTsW
44sQmste9f+UgMw8BkjDlM25fwQLrCfmmnLxjewey10kSROypUaJLb+r4oRALc0fG9
45XfZsaiiIgotQHjEA
46-----END PKCS7-----
diff --git a/src/lib/libssl/test/testreq2.pem b/src/lib/libssl/test/testreq2.pem
deleted file mode 100644
index c3cdcffcbc..0000000000
--- a/src/lib/libssl/test/testreq2.pem
+++ /dev/null
@@ -1,7 +0,0 @@
1-----BEGIN CERTIFICATE REQUEST-----
2MIHaMIGFAgEAMA4xDDAKBgNVBAMTA2NuNDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgC
3QQCQsnkyUGDY2R3mYoeTprFJKgWuJ3f1jUjlIuW5+wfAUoeMt35c4vcFZ2mIBpEG
4DtzkNQN1kr2O9ldm9zYnYhyhAgMBAAGgEjAQBgorBgEEAYI3AgEOMQIwADANBgkq
5hkiG9w0BAQQFAANBAAb2szZgVIxg3vK6kYLjGSBISyuzcXJ6IvuPW6M+yzi1Qgoi
6gQhazHTJp91T8ItZEzUJGZSZl2e5iXlnffWB+/U=
7-----END CERTIFICATE REQUEST-----
diff --git a/src/lib/libssl/test/testrsa.pem b/src/lib/libssl/test/testrsa.pem
deleted file mode 100644
index aad21067a8..0000000000
--- a/src/lib/libssl/test/testrsa.pem
+++ /dev/null
@@ -1,9 +0,0 @@
1-----BEGIN RSA PRIVATE KEY-----
2MIIBPAIBAAJBAKrbeqkuRk8VcRmWFmtP+LviMB3+6dizWW3DwaffznyHGAFwUJ/I
3Tv0XtbsCyl3QoyKGhrOAy3RvPK5M38iuXT0CAwEAAQJAZ3cnzaHXM/bxGaR5CR1R
4rD1qFBAVfoQFiOH9uPJgMaoAuoQEisPHVcZDKcOv4wEg6/TInAIXBnEigtqvRzuy
5oQIhAPcgZzUq3yVooAaoov8UbXPxqHlwo6GBMqnv20xzkf6ZAiEAsP4BnIaQTM8S
6mvcpHZwQJdmdHHkGKAs37Dfxi67HbkUCIQCeZGliHXFa071Fp06ZeWlR2ADonTZz
7rJBhdTe0v5pCeQIhAIZfkiGgGBX4cIuuckzEm43g9WMUjxP/0GlK39vIyihxAiEA
8mymehFRT0MvqW5xAKAx7Pgkt8HVKwVhc2LwGKHE0DZM=
9-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libssl/test/testsid.pem b/src/lib/libssl/test/testsid.pem
deleted file mode 100644
index 7ffd008f66..0000000000
--- a/src/lib/libssl/test/testsid.pem
+++ /dev/null
@@ -1,12 +0,0 @@
1-----BEGIN SSL SESSION PARAMETERS-----
2MIIB1gIBAQIBAgQDAQCABBCi11xa5qkOP8xrr02K/NQCBBBkIYQZM0Bt95W0EHNV
3bA58oQYCBDIBr7WiBAICASyjggGGMIIBgjCCASwCAQMwDQYJKoZIhvcNAQEEBQAw
4ODELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3Jz
5YSB0ZXN0IENBMB4XDTk1MTAwOTIzMzEzNFoXDTk4MDcwNTIzMzEzNFowYDELMAkG
6A1UEBhMCQVUxDDAKBgNVBAgTA1FMRDEZMBcGA1UEChMQTWluY29tIFB0eS4gTHRk
7LjELMAkGA1UECxMCQ1MxGzAZBgNVBAMTElNTTGVheSBkZW1vIGNsaWVudDBcMA0G
8CSqGSIb3DQEBAQUAA0sAMEgCQQC4pcXEL1lgVA+B5Q3TcuW/O3LZHoA73IYm8oFD
9TezgCDhL2RTMn+seKWF36UtJKRIOBU9jZHCVVd0Me5ls6BEjAgMBAAEwDQYJKoZI
10hvcNAQEEBQADQQBoIpOcwUY1qlVF7j3ROSGvUsbvByOBFmYWkIBgsCqR+9qo1A7L
11CrWF5i8LWt/vLwAHaxWNx2YuBJMFyuK81fTvpA0EC3Rlc3Rjb250ZXh0
12-----END SSL SESSION PARAMETERS-----
diff --git a/src/lib/libssl/test/testss b/src/lib/libssl/test/testss
deleted file mode 100644
index 1a426857d3..0000000000
--- a/src/lib/libssl/test/testss
+++ /dev/null
@@ -1,163 +0,0 @@
1#!/bin/sh
2
3digest='-sha1'
4reqcmd="../util/shlib_wrap.sh ../apps/openssl req"
5x509cmd="../util/shlib_wrap.sh ../apps/openssl x509 $digest"
6verifycmd="../util/shlib_wrap.sh ../apps/openssl verify"
7dummycnf="../apps/openssl.cnf"
8
9CAkey="keyCA.ss"
10CAcert="certCA.ss"
11CAreq="reqCA.ss"
12CAconf="CAss.cnf"
13CAreq2="req2CA.ss" # temp
14
15Uconf="Uss.cnf"
16Ukey="keyU.ss"
17Ureq="reqU.ss"
18Ucert="certU.ss"
19
20P1conf="P1ss.cnf"
21P1key="keyP1.ss"
22P1req="reqP1.ss"
23P1cert="certP1.ss"
24P1intermediate="tmp_intP1.ss"
25
26P2conf="P2ss.cnf"
27P2key="keyP2.ss"
28P2req="reqP2.ss"
29P2cert="certP2.ss"
30P2intermediate="tmp_intP2.ss"
31
32echo
33echo "make a certificate request using 'req'"
34
35echo "string to make the random number generator think it has entropy" >> ./.rnd
36
37if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
38 req_new='-newkey dsa:../apps/dsa512.pem'
39else
40 req_new='-new'
41fi
42
43$reqcmd -config $CAconf -out $CAreq -keyout $CAkey $req_new #>err.ss
44if [ $? != 0 ]; then
45 echo "error using 'req' to generate a certificate request"
46 exit 1
47fi
48echo
49echo "convert the certificate request into a self signed certificate using 'x509'"
50$x509cmd -CAcreateserial -in $CAreq -days 30 -req -out $CAcert -signkey $CAkey -extfile $CAconf -extensions v3_ca >err.ss
51if [ $? != 0 ]; then
52 echo "error using 'x509' to self sign a certificate request"
53 exit 1
54fi
55
56echo
57echo "convert a certificate into a certificate request using 'x509'"
58$x509cmd -in $CAcert -x509toreq -signkey $CAkey -out $CAreq2 >err.ss
59if [ $? != 0 ]; then
60 echo "error using 'x509' convert a certificate to a certificate request"
61 exit 1
62fi
63
64$reqcmd -config $dummycnf -verify -in $CAreq -noout
65if [ $? != 0 ]; then
66 echo first generated request is invalid
67 exit 1
68fi
69
70$reqcmd -config $dummycnf -verify -in $CAreq2 -noout
71if [ $? != 0 ]; then
72 echo second generated request is invalid
73 exit 1
74fi
75
76$verifycmd -CAfile $CAcert $CAcert
77if [ $? != 0 ]; then
78 echo first generated cert is invalid
79 exit 1
80fi
81
82echo
83echo "make a user certificate request using 'req'"
84$reqcmd -config $Uconf -out $Ureq -keyout $Ukey $req_new >err.ss
85if [ $? != 0 ]; then
86 echo "error using 'req' to generate a user certificate request"
87 exit 1
88fi
89
90echo
91echo "sign user certificate request with the just created CA via 'x509'"
92$x509cmd -CAcreateserial -in $Ureq -days 30 -req -out $Ucert -CA $CAcert -CAkey $CAkey -extfile $Uconf -extensions v3_ee >err.ss
93if [ $? != 0 ]; then
94 echo "error using 'x509' to sign a user certificate request"
95 exit 1
96fi
97
98$verifycmd -CAfile $CAcert $Ucert
99echo
100echo "Certificate details"
101$x509cmd -subject -issuer -startdate -enddate -noout -in $Ucert
102
103echo
104echo "make a proxy certificate request using 'req'"
105$reqcmd -config $P1conf -out $P1req -keyout $P1key $req_new >err.ss
106if [ $? != 0 ]; then
107 echo "error using 'req' to generate a proxy certificate request"
108 exit 1
109fi
110
111echo
112echo "sign proxy certificate request with the just created user certificate via 'x509'"
113$x509cmd -CAcreateserial -in $P1req -days 30 -req -out $P1cert -CA $Ucert -CAkey $Ukey -extfile $P1conf -extensions v3_proxy >err.ss
114if [ $? != 0 ]; then
115 echo "error using 'x509' to sign a proxy certificate request"
116 exit 1
117fi
118
119cat $Ucert > $P1intermediate
120$verifycmd -CAfile $CAcert -untrusted $P1intermediate $P1cert
121echo
122echo "Certificate details"
123$x509cmd -subject -issuer -startdate -enddate -noout -in $P1cert
124
125echo
126echo "make another proxy certificate request using 'req'"
127$reqcmd -config $P2conf -out $P2req -keyout $P2key $req_new >err.ss
128if [ $? != 0 ]; then
129 echo "error using 'req' to generate another proxy certificate request"
130 exit 1
131fi
132
133echo
134echo "sign second proxy certificate request with the first proxy certificate via 'x509'"
135$x509cmd -CAcreateserial -in $P2req -days 30 -req -out $P2cert -CA $P1cert -CAkey $P1key -extfile $P2conf -extensions v3_proxy >err.ss
136if [ $? != 0 ]; then
137 echo "error using 'x509' to sign a second proxy certificate request"
138 exit 1
139fi
140
141cat $Ucert $P1cert > $P2intermediate
142$verifycmd -CAfile $CAcert -untrusted $P2intermediate $P2cert
143echo
144echo "Certificate details"
145$x509cmd -subject -issuer -startdate -enddate -noout -in $P2cert
146
147echo
148echo The generated CA certificate is $CAcert
149echo The generated CA private key is $CAkey
150
151echo The generated user certificate is $Ucert
152echo The generated user private key is $Ukey
153
154echo The first generated proxy certificate is $P1cert
155echo The first generated proxy private key is $P1key
156
157echo The second generated proxy certificate is $P2cert
158echo The second generated proxy private key is $P2key
159
160/bin/rm err.ss
161#/bin/rm $P1intermediate
162#/bin/rm $P2intermediate
163exit 0
diff --git a/src/lib/libssl/test/testssl b/src/lib/libssl/test/testssl
deleted file mode 100644
index 4e8542b556..0000000000
--- a/src/lib/libssl/test/testssl
+++ /dev/null
@@ -1,178 +0,0 @@
1#!/bin/sh
2
3if [ "$1" = "" ]; then
4 key=../apps/server.pem
5else
6 key="$1"
7fi
8if [ "$2" = "" ]; then
9 cert=../apps/server.pem
10else
11 cert="$2"
12fi
13ssltest="../util/shlib_wrap.sh ./ssltest -key $key -cert $cert -c_key $key -c_cert $cert"
14
15if ../util/shlib_wrap.sh ../apps/openssl x509 -in $cert -text -noout | fgrep 'DSA Public Key' >/dev/null; then
16 dsa_cert=YES
17else
18 dsa_cert=NO
19fi
20
21if [ "$3" = "" ]; then
22 CA="-CApath ../certs"
23else
24 CA="-CAfile $3"
25fi
26
27if [ "$4" = "" ]; then
28 extra=""
29else
30 extra="$4"
31fi
32
33#############################################################################
34
35echo test sslv2
36$ssltest -ssl2 $extra || exit 1
37
38echo test sslv2 with server authentication
39$ssltest -ssl2 -server_auth $CA $extra || exit 1
40
41if [ $dsa_cert = NO ]; then
42 echo test sslv2 with client authentication
43 $ssltest -ssl2 -client_auth $CA $extra || exit 1
44
45 echo test sslv2 with both client and server authentication
46 $ssltest -ssl2 -server_auth -client_auth $CA $extra || exit 1
47fi
48
49echo test sslv3
50$ssltest -ssl3 $extra || exit 1
51
52echo test sslv3 with server authentication
53$ssltest -ssl3 -server_auth $CA $extra || exit 1
54
55echo test sslv3 with client authentication
56$ssltest -ssl3 -client_auth $CA $extra || exit 1
57
58echo test sslv3 with both client and server authentication
59$ssltest -ssl3 -server_auth -client_auth $CA $extra || exit 1
60
61echo test sslv2/sslv3
62$ssltest $extra || exit 1
63
64echo test sslv2/sslv3 with server authentication
65$ssltest -server_auth $CA $extra || exit 1
66
67echo test sslv2/sslv3 with client authentication
68$ssltest -client_auth $CA $extra || exit 1
69
70echo test sslv2/sslv3 with both client and server authentication
71$ssltest -server_auth -client_auth $CA $extra || exit 1
72
73echo test sslv2 via BIO pair
74$ssltest -bio_pair -ssl2 $extra || exit 1
75
76echo test sslv2 with server authentication via BIO pair
77$ssltest -bio_pair -ssl2 -server_auth $CA $extra || exit 1
78
79if [ $dsa_cert = NO ]; then
80 echo test sslv2 with client authentication via BIO pair
81 $ssltest -bio_pair -ssl2 -client_auth $CA $extra || exit 1
82
83 echo test sslv2 with both client and server authentication via BIO pair
84 $ssltest -bio_pair -ssl2 -server_auth -client_auth $CA $extra || exit 1
85fi
86
87echo test sslv3 via BIO pair
88$ssltest -bio_pair -ssl3 $extra || exit 1
89
90echo test sslv3 with server authentication via BIO pair
91$ssltest -bio_pair -ssl3 -server_auth $CA $extra || exit 1
92
93echo test sslv3 with client authentication via BIO pair
94$ssltest -bio_pair -ssl3 -client_auth $CA $extra || exit 1
95
96echo test sslv3 with both client and server authentication via BIO pair
97$ssltest -bio_pair -ssl3 -server_auth -client_auth $CA $extra || exit 1
98
99echo test sslv2/sslv3 via BIO pair
100$ssltest $extra || exit 1
101
102if [ $dsa_cert = NO ]; then
103 echo 'test sslv2/sslv3 w/o (EC)DHE via BIO pair'
104 $ssltest -bio_pair -no_dhe -no_ecdhe $extra || exit 1
105fi
106
107echo test sslv2/sslv3 with 1024bit DHE via BIO pair
108$ssltest -bio_pair -dhe1024dsa -v $extra || exit 1
109
110echo test sslv2/sslv3 with server authentication
111$ssltest -bio_pair -server_auth $CA $extra || exit 1
112
113echo test sslv2/sslv3 with client authentication via BIO pair
114$ssltest -bio_pair -client_auth $CA $extra || exit 1
115
116echo test sslv2/sslv3 with both client and server authentication via BIO pair
117$ssltest -bio_pair -server_auth -client_auth $CA $extra || exit 1
118
119echo test sslv2/sslv3 with both client and server authentication via BIO pair and app verify
120$ssltest -bio_pair -server_auth -client_auth -app_verify $CA $extra || exit 1
121
122echo "Testing ciphersuites"
123for protocol in TLSv1.2 SSLv3; do
124 echo "Testing ciphersuites for $protocol"
125 for cipher in `../util/shlib_wrap.sh ../apps/openssl ciphers "RSA+$protocol" | tr ':' ' '`; do
126 echo "Testing $cipher"
127 prot=""
128 if [ $protocol = "SSLv3" ] ; then
129 prot="-ssl3"
130 fi
131 $ssltest -cipher $cipher $prot
132 if [ $? -ne 0 ] ; then
133 echo "Failed $cipher"
134 exit 1
135 fi
136 done
137done
138
139#############################################################################
140
141if ../util/shlib_wrap.sh ../apps/openssl no-dh; then
142 echo skipping anonymous DH tests
143else
144 echo test tls1 with 1024bit anonymous DH, multiple handshakes
145 $ssltest -v -bio_pair -tls1 -cipher ADH -dhe1024dsa -num 10 -f -time $extra || exit 1
146fi
147
148if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
149 echo skipping RSA tests
150else
151 echo 'test tls1 with 1024bit RSA, no (EC)DHE, multiple handshakes'
152 ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -no_dhe -no_ecdhe -num 10 -f -time $extra || exit 1
153
154 if ../util/shlib_wrap.sh ../apps/openssl no-dh; then
155 echo skipping RSA+DHE tests
156 else
157 echo test tls1 with 1024bit RSA, 1024bit DHE, multiple handshakes
158 ../util/shlib_wrap.sh ./ssltest -v -bio_pair -tls1 -cert ../apps/server2.pem -dhe1024dsa -num 10 -f -time $extra || exit 1
159 fi
160fi
161
162echo test tls1 with PSK
163$ssltest -tls1 -cipher PSK -psk abc123 $extra || exit 1
164
165echo test tls1 with PSK via BIO pair
166$ssltest -bio_pair -tls1 -cipher PSK -psk abc123 $extra || exit 1
167
168if ../util/shlib_wrap.sh ../apps/openssl no-srp; then
169 echo skipping SRP tests
170else
171 echo test tls1 with SRP
172 $ssltest -tls1 -cipher SRP -srpuser test -srppass abc123
173
174 echo test tls1 with SRP via BIO pair
175 $ssltest -bio_pair -tls1 -cipher SRP -srpuser test -srppass abc123
176fi
177
178exit 0
diff --git a/src/lib/libssl/test/testsslproxy b/src/lib/libssl/test/testsslproxy
deleted file mode 100644
index 58bbda8ab7..0000000000
--- a/src/lib/libssl/test/testsslproxy
+++ /dev/null
@@ -1,10 +0,0 @@
1#! /bin/sh
2
3echo 'Testing a lot of proxy conditions.'
4echo 'Some of them may turn out being invalid, which is fine.'
5for auth in A B C BC; do
6 for cond in A B C 'A|B&!C'; do
7 sh ./testssl $1 $2 $3 "-proxy -proxy_auth $auth -proxy_cond $cond"
8 if [ $? = 3 ]; then exit 1; fi
9 done
10done
diff --git a/src/lib/libssl/test/testtsa b/src/lib/libssl/test/testtsa
deleted file mode 100644
index bb653b5f73..0000000000
--- a/src/lib/libssl/test/testtsa
+++ /dev/null
@@ -1,238 +0,0 @@
1#!/bin/sh
2
3#
4# A few very basic tests for the 'ts' time stamping authority command.
5#
6
7SH="/bin/sh"
8if test "$OSTYPE" = msdosdjgpp; then
9 PATH="../apps\;$PATH"
10else
11 PATH="../apps:$PATH"
12fi
13export SH PATH
14
15OPENSSL_CONF="../CAtsa.cnf"
16export OPENSSL_CONF
17# Because that's what ../apps/CA.sh really looks at
18SSLEAY_CONFIG="-config $OPENSSL_CONF"
19export SSLEAY_CONFIG
20
21OPENSSL="`pwd`/../util/opensslwrap.sh"
22export OPENSSL
23
24error () {
25
26 echo "TSA test failed!" >&2
27 exit 1
28}
29
30setup_dir () {
31
32 rm -rf tsa 2>/dev/null
33 mkdir tsa
34 cd ./tsa
35}
36
37clean_up_dir () {
38
39 cd ..
40 rm -rf tsa
41}
42
43create_ca () {
44
45 echo "Creating a new CA for the TSA tests..."
46 TSDNSECT=ts_ca_dn
47 export TSDNSECT
48 ../../util/shlib_wrap.sh ../../apps/openssl req -new -x509 -nodes \
49 -out tsaca.pem -keyout tsacakey.pem
50 test $? != 0 && error
51}
52
53create_tsa_cert () {
54
55 INDEX=$1
56 export INDEX
57 EXT=$2
58 TSDNSECT=ts_cert_dn
59 export TSDNSECT
60
61 ../../util/shlib_wrap.sh ../../apps/openssl req -new \
62 -out tsa_req${INDEX}.pem -keyout tsa_key${INDEX}.pem
63 test $? != 0 && error
64echo Using extension $EXT
65 ../../util/shlib_wrap.sh ../../apps/openssl x509 -req \
66 -in tsa_req${INDEX}.pem -out tsa_cert${INDEX}.pem \
67 -CA tsaca.pem -CAkey tsacakey.pem -CAcreateserial \
68 -extfile $OPENSSL_CONF -extensions $EXT
69 test $? != 0 && error
70}
71
72print_request () {
73
74 ../../util/shlib_wrap.sh ../../apps/openssl ts -query -in $1 -text
75}
76
77create_time_stamp_request1 () {
78
79 ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy1 -cert -out req1.tsq
80 test $? != 0 && error
81}
82
83create_time_stamp_request2 () {
84
85 ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../testtsa -policy tsa_policy2 -no_nonce \
86 -out req2.tsq
87 test $? != 0 && error
88}
89
90create_time_stamp_request3 () {
91
92 ../../util/shlib_wrap.sh ../../apps/openssl ts -query -data ../CAtsa.cnf -no_nonce -out req3.tsq
93 test $? != 0 && error
94}
95
96print_response () {
97
98 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $1 -text
99 test $? != 0 && error
100}
101
102create_time_stamp_response () {
103
104 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -section $3 -queryfile $1 -out $2
105 test $? != 0 && error
106}
107
108time_stamp_response_token_test () {
109
110 RESPONSE2=$2.copy.tsr
111 TOKEN_DER=$2.token.der
112 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $TOKEN_DER -token_out
113 test $? != 0 && error
114 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -out $RESPONSE2
115 test $? != 0 && error
116 cmp $RESPONSE2 $2
117 test $? != 0 && error
118 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -text -token_out
119 test $? != 0 && error
120 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $TOKEN_DER -token_in -text -token_out
121 test $? != 0 && error
122 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -queryfile $1 -text -token_out
123 test $? != 0 && error
124}
125
126verify_time_stamp_response () {
127
128 ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
129 -untrusted tsa_cert1.pem
130 test $? != 0 && error
131 ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2 -CAfile tsaca.pem \
132 -untrusted tsa_cert1.pem
133 test $? != 0 && error
134}
135
136verify_time_stamp_token () {
137
138 # create the token from the response first
139 ../../util/shlib_wrap.sh ../../apps/openssl ts -reply -in $2 -out $2.token -token_out
140 test $? != 0 && error
141 ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2.token -token_in \
142 -CAfile tsaca.pem -untrusted tsa_cert1.pem
143 test $? != 0 && error
144 ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -data $3 -in $2.token -token_in \
145 -CAfile tsaca.pem -untrusted tsa_cert1.pem
146 test $? != 0 && error
147}
148
149verify_time_stamp_response_fail () {
150
151 ../../util/shlib_wrap.sh ../../apps/openssl ts -verify -queryfile $1 -in $2 -CAfile tsaca.pem \
152 -untrusted tsa_cert1.pem
153 # Checks if the verification failed, as it should have.
154 test $? = 0 && error
155 echo Ok
156}
157
158# main functions
159
160echo "Setting up TSA test directory..."
161setup_dir
162
163echo "Creating CA for TSA tests..."
164create_ca
165
166echo "Creating tsa_cert1.pem TSA server cert..."
167create_tsa_cert 1 tsa_cert
168
169echo "Creating tsa_cert2.pem non-TSA server cert..."
170create_tsa_cert 2 non_tsa_cert
171
172echo "Creating req1.req time stamp request for file testtsa..."
173create_time_stamp_request1
174
175echo "Printing req1.req..."
176print_request req1.tsq
177
178echo "Generating valid response for req1.req..."
179create_time_stamp_response req1.tsq resp1.tsr tsa_config1
180
181echo "Printing response..."
182print_response resp1.tsr
183
184echo "Verifying valid response..."
185verify_time_stamp_response req1.tsq resp1.tsr ../testtsa
186
187echo "Verifying valid token..."
188verify_time_stamp_token req1.tsq resp1.tsr ../testtsa
189
190# The tests below are commented out, because invalid signer certificates
191# can no longer be specified in the config file.
192
193# echo "Generating _invalid_ response for req1.req..."
194# create_time_stamp_response req1.tsq resp1_bad.tsr tsa_config2
195
196# echo "Printing response..."
197# print_response resp1_bad.tsr
198
199# echo "Verifying invalid response, it should fail..."
200# verify_time_stamp_response_fail req1.tsq resp1_bad.tsr
201
202echo "Creating req2.req time stamp request for file testtsa..."
203create_time_stamp_request2
204
205echo "Printing req2.req..."
206print_request req2.tsq
207
208echo "Generating valid response for req2.req..."
209create_time_stamp_response req2.tsq resp2.tsr tsa_config1
210
211echo "Checking '-token_in' and '-token_out' options with '-reply'..."
212time_stamp_response_token_test req2.tsq resp2.tsr
213
214echo "Printing response..."
215print_response resp2.tsr
216
217echo "Verifying valid response..."
218verify_time_stamp_response req2.tsq resp2.tsr ../testtsa
219
220echo "Verifying response against wrong request, it should fail..."
221verify_time_stamp_response_fail req1.tsq resp2.tsr
222
223echo "Verifying response against wrong request, it should fail..."
224verify_time_stamp_response_fail req2.tsq resp1.tsr
225
226echo "Creating req3.req time stamp request for file CAtsa.cnf..."
227create_time_stamp_request3
228
229echo "Printing req3.req..."
230print_request req3.tsq
231
232echo "Verifying response against wrong request, it should fail..."
233verify_time_stamp_response_fail req3.tsq resp1.tsr
234
235echo "Cleaning up..."
236clean_up_dir
237
238exit 0
diff --git a/src/lib/libssl/test/testx509.pem b/src/lib/libssl/test/testx509.pem
deleted file mode 100644
index 8a85d14964..0000000000
--- a/src/lib/libssl/test/testx509.pem
+++ /dev/null
@@ -1,10 +0,0 @@
1-----BEGIN CERTIFICATE-----
2MIIBWzCCAQYCARgwDQYJKoZIhvcNAQEEBQAwODELMAkGA1UEBhMCQVUxDDAKBgNV
3BAgTA1FMRDEbMBkGA1UEAxMSU1NMZWF5L3JzYSB0ZXN0IENBMB4XDTk1MDYxOTIz
4MzMxMloXDTk1MDcxNzIzMzMxMlowOjELMAkGA1UEBhMCQVUxDDAKBgNVBAgTA1FM
5RDEdMBsGA1UEAxMUU1NMZWF5L3JzYSB0ZXN0IGNlcnQwXDANBgkqhkiG9w0BAQEF
6AANLADBIAkEAqtt6qS5GTxVxGZYWa0/4u+IwHf7p2LNZbcPBp9/OfIcYAXBQn8hO
7/Re1uwLKXdCjIoaGs4DLdG88rkzfyK5dPQIDAQABMAwGCCqGSIb3DQIFBQADQQAE
8Wc7EcF8po2/ZO6kNCwK/ICH6DobgLekA5lSLr5EvuioZniZp5lFzAw4+YzPQ7XKJ
9zl9HYIMxATFyqSiD9jsx
10-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/times b/src/lib/libssl/test/times
deleted file mode 100644
index 6b66eb342e..0000000000
--- a/src/lib/libssl/test/times
+++ /dev/null
@@ -1,113 +0,0 @@
1
2More number for the questions about SSL overheads....
3
4The following numbers were generated on a Pentium pro 200, running Linux.
5They give an indication of the SSL protocol and encryption overheads.
6
7The program that generated them is an unreleased version of ssl/ssltest.c
8which is the SSLeay ssl protocol testing program. It is a single process that
9talks both sides of the SSL protocol via a non-blocking memory buffer
10interface.
11
12How do I read this? The protocol and cipher are reasonable obvious.
13The next number is the number of connections being made. The next is the
14number of bytes exchanged between the client and server side of the protocol.
15This is the number of bytes that the client sends to the server, and then
16the server sends back. Because this is all happening in one process,
17the data is being encrypted, decrypted, encrypted and then decrypted again.
18It is a round trip of that many bytes. Because the one process performs
19both the client and server sides of the protocol and it sends this many bytes
20each direction, multiply this number by 4 to generate the number
21of bytes encrypted/decrypted/MACed. The first time value is how many seconds
22elapsed doing a full SSL handshake, the second is the cost of one
23full handshake and the rest being session-id reuse.
24
25SSLv2 RC4-MD5 1000 x 1 12.83s 0.70s
26SSLv3 NULL-MD5 1000 x 1 14.35s 1.47s
27SSLv3 RC4-MD5 1000 x 1 14.46s 1.56s
28SSLv3 RC4-MD5 1000 x 1 51.93s 1.62s 1024bit RSA
29SSLv3 RC4-SHA 1000 x 1 14.61s 1.83s
30SSLv3 DES-CBC-SHA 1000 x 1 14.70s 1.89s
31SSLv3 DES-CBC3-SHA 1000 x 1 15.16s 2.16s
32
33SSLv2 RC4-MD5 1000 x 1024 13.72s 1.27s
34SSLv3 NULL-MD5 1000 x 1024 14.79s 1.92s
35SSLv3 RC4-MD5 1000 x 1024 52.58s 2.29s 1024bit RSA
36SSLv3 RC4-SHA 1000 x 1024 15.39s 2.67s
37SSLv3 DES-CBC-SHA 1000 x 1024 16.45s 3.55s
38SSLv3 DES-CBC3-SHA 1000 x 1024 18.21s 5.38s
39
40SSLv2 RC4-MD5 1000 x 10240 18.97s 6.52s
41SSLv3 NULL-MD5 1000 x 10240 17.79s 5.11s
42SSLv3 RC4-MD5 1000 x 10240 20.25s 7.90s
43SSLv3 RC4-MD5 1000 x 10240 58.26s 8.08s 1024bit RSA
44SSLv3 RC4-SHA 1000 x 10240 22.96s 11.44s
45SSLv3 DES-CBC-SHA 1000 x 10240 30.65s 18.41s
46SSLv3 DES-CBC3-SHA 1000 x 10240 47.04s 34.53s
47
48SSLv2 RC4-MD5 1000 x 102400 70.22s 57.74s
49SSLv3 NULL-MD5 1000 x 102400 43.73s 31.03s
50SSLv3 RC4-MD5 1000 x 102400 71.32s 58.83s
51SSLv3 RC4-MD5 1000 x 102400 109.66s 59.20s 1024bit RSA
52SSLv3 RC4-SHA 1000 x 102400 95.88s 82.21s
53SSLv3 DES-CBC-SHA 1000 x 102400 173.22s 160.55s
54SSLv3 DES-CBC3-SHA 1000 x 102400 336.61s 323.82s
55
56What does this all mean? Well for a server, with no session-id reuse, with
57a transfer size of 10240 bytes, using RC4-MD5 and a 512bit server key,
58a Pentium pro 200 running Linux can handle the SSLv3 protocol overheads of
59about 49 connections a second. Reality will be quite different :-).
60
61Remember the first number is 1000 full ssl handshakes, the second is
621 full and 999 with session-id reuse. The RSA overheads for each exchange
63would be one public and one private operation, but the protocol/MAC/cipher
64cost would be quite similar in both the client and server.
65
66eric (adding numbers to speculation)
67
68--- Appendix ---
69- The time measured is user time but these number a very rough.
70- Remember this is the cost of both client and server sides of the protocol.
71- The TCP/kernel overhead of connection establishment is normally the
72 killer in SSL. Often delays in the TCP protocol will make session-id
73 reuse look slower that new sessions, but this would not be the case on
74 a loaded server.
75- The TCP round trip latencies, while slowing individual connections,
76 would have minimal impact on throughput.
77- Instead of sending one 102400 byte buffer, one 8k buffer is sent until
78- the required number of bytes are processed.
79- The SSLv3 connections were actually SSLv2 compatible SSLv3 headers.
80- A 512bit server key was being used except where noted.
81- No server key verification was being performed on the client side of the
82 protocol. This would slow things down very little.
83- The library being used is SSLeay 0.8.x.
84- The normal measuring system was commands of the form
85 time ./ssltest -num 1000 -bytes 102400 -cipher DES-CBC-SHA -reuse
86 This modified version of ssltest should be in the next public release of
87 SSLeay.
88
89The general cipher performance number for this platform are
90
91SSLeay 0.8.2a 04-Sep-1997
92built on Fri Sep 5 17:37:05 EST 1997
93options:bn(64,32) md2(int) rc4(idx,int) des(ptr,risc1,16,long) idea(int) blowfish(ptr2)
94C flags:gcc -DL_ENDIAN -DTERMIO -O3 -fomit-frame-pointer -m486 -Wall -Wuninitialized
95The 'numbers' are in 1000s of bytes per second processed.
96type 8 bytes 64 bytes 256 bytes 1024 bytes 8192 bytes
97md2 131.02k 368.41k 500.57k 549.21k 566.09k
98mdc2 535.60k 589.10k 595.88k 595.97k 594.54k
99md5 1801.53k 9674.77k 17484.03k 21849.43k 23592.96k
100sha 1261.63k 5533.25k 9285.63k 11187.88k 11913.90k
101sha1 1103.13k 4782.53k 7933.78k 9472.34k 10070.70k
102rc4 10722.53k 14443.93k 15215.79k 15299.24k 15219.59k
103des cbc 3286.57k 3827.73k 3913.39k 3931.82k 3926.70k
104des ede3 1443.50k 1549.08k 1561.17k 1566.38k 1564.67k
105idea cbc 2203.64k 2508.16k 2538.33k 2543.62k 2547.71k
106rc2 cbc 1430.94k 1511.59k 1524.82k 1527.13k 1523.33k
107blowfish cbc 4716.07k 5965.82k 6190.17k 6243.67k 6234.11k
108 sign verify
109rsa 512 bits 0.0100s 0.0011s
110rsa 1024 bits 0.0451s 0.0012s
111rsa 2048 bits 0.2605s 0.0086s
112rsa 4096 bits 1.6883s 0.0302s
113
diff --git a/src/lib/libssl/test/tpkcs7 b/src/lib/libssl/test/tpkcs7
deleted file mode 100644
index 3e435ffbf9..0000000000
--- a/src/lib/libssl/test/tpkcs7
+++ /dev/null
@@ -1,48 +0,0 @@
1#!/bin/sh
2
3cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7'
4
5if [ "$1"x != "x" ]; then
6 t=$1
7else
8 t=testp7.pem
9fi
10
11echo testing pkcs7 conversions
12cp $t fff.p
13
14echo "p -> d"
15$cmd -in fff.p -inform p -outform d >f.d
16if [ $? != 0 ]; then exit 1; fi
17echo "p -> p"
18$cmd -in fff.p -inform p -outform p >f.p
19if [ $? != 0 ]; then exit 1; fi
20
21echo "d -> d"
22$cmd -in f.d -inform d -outform d >ff.d1
23if [ $? != 0 ]; then exit 1; fi
24echo "p -> d"
25$cmd -in f.p -inform p -outform d >ff.d3
26if [ $? != 0 ]; then exit 1; fi
27
28echo "d -> p"
29$cmd -in f.d -inform d -outform p >ff.p1
30if [ $? != 0 ]; then exit 1; fi
31echo "p -> p"
32$cmd -in f.p -inform p -outform p >ff.p3
33if [ $? != 0 ]; then exit 1; fi
34
35cmp fff.p f.p
36if [ $? != 0 ]; then exit 1; fi
37cmp fff.p ff.p1
38if [ $? != 0 ]; then exit 1; fi
39cmp fff.p ff.p3
40if [ $? != 0 ]; then exit 1; fi
41
42cmp f.p ff.p1
43if [ $? != 0 ]; then exit 1; fi
44cmp f.p ff.p3
45if [ $? != 0 ]; then exit 1; fi
46
47/bin/rm -f f.* ff.* fff.*
48exit 0
diff --git a/src/lib/libssl/test/tpkcs7d b/src/lib/libssl/test/tpkcs7d
deleted file mode 100644
index 64fc28e88f..0000000000
--- a/src/lib/libssl/test/tpkcs7d
+++ /dev/null
@@ -1,41 +0,0 @@
1#!/bin/sh
2
3cmd='../util/shlib_wrap.sh ../apps/openssl pkcs7'
4
5if [ "$1"x != "x" ]; then
6 t=$1
7else
8 t=pkcs7-1.pem
9fi
10
11echo "testing pkcs7 conversions (2)"
12cp $t fff.p
13
14echo "p -> d"
15$cmd -in fff.p -inform p -outform d >f.d
16if [ $? != 0 ]; then exit 1; fi
17echo "p -> p"
18$cmd -in fff.p -inform p -outform p >f.p
19if [ $? != 0 ]; then exit 1; fi
20
21echo "d -> d"
22$cmd -in f.d -inform d -outform d >ff.d1
23if [ $? != 0 ]; then exit 1; fi
24echo "p -> d"
25$cmd -in f.p -inform p -outform d >ff.d3
26if [ $? != 0 ]; then exit 1; fi
27
28echo "d -> p"
29$cmd -in f.d -inform d -outform p >ff.p1
30if [ $? != 0 ]; then exit 1; fi
31echo "p -> p"
32$cmd -in f.p -inform p -outform p >ff.p3
33if [ $? != 0 ]; then exit 1; fi
34
35cmp f.p ff.p1
36if [ $? != 0 ]; then exit 1; fi
37cmp f.p ff.p3
38if [ $? != 0 ]; then exit 1; fi
39
40/bin/rm -f f.* ff.* fff.*
41exit 0
diff --git a/src/lib/libssl/test/treq b/src/lib/libssl/test/treq
deleted file mode 100644
index 77f37dcf3a..0000000000
--- a/src/lib/libssl/test/treq
+++ /dev/null
@@ -1,83 +0,0 @@
1#!/bin/sh
2
3cmd='../util/shlib_wrap.sh ../apps/openssl req -config ../apps/openssl.cnf'
4
5if [ "$1"x != "x" ]; then
6 t=$1
7else
8 t=testreq.pem
9fi
10
11if $cmd -in $t -inform p -noout -text 2>&1 | fgrep -i 'Unknown Public Key'; then
12 echo "skipping req conversion test for $t"
13 exit 0
14fi
15
16echo testing req conversions
17cp $t fff.p
18
19echo "p -> d"
20$cmd -in fff.p -inform p -outform d >f.d
21if [ $? != 0 ]; then exit 1; fi
22#echo "p -> t"
23#$cmd -in fff.p -inform p -outform t >f.t
24#if [ $? != 0 ]; then exit 1; fi
25echo "p -> p"
26$cmd -in fff.p -inform p -outform p >f.p
27if [ $? != 0 ]; then exit 1; fi
28
29echo "d -> d"
30$cmd -verify -in f.d -inform d -outform d >ff.d1
31if [ $? != 0 ]; then exit 1; fi
32#echo "t -> d"
33#$cmd -in f.t -inform t -outform d >ff.d2
34#if [ $? != 0 ]; then exit 1; fi
35echo "p -> d"
36$cmd -verify -in f.p -inform p -outform d >ff.d3
37if [ $? != 0 ]; then exit 1; fi
38
39#echo "d -> t"
40#$cmd -in f.d -inform d -outform t >ff.t1
41#if [ $? != 0 ]; then exit 1; fi
42#echo "t -> t"
43#$cmd -in f.t -inform t -outform t >ff.t2
44#if [ $? != 0 ]; then exit 1; fi
45#echo "p -> t"
46#$cmd -in f.p -inform p -outform t >ff.t3
47#if [ $? != 0 ]; then exit 1; fi
48
49echo "d -> p"
50$cmd -in f.d -inform d -outform p >ff.p1
51if [ $? != 0 ]; then exit 1; fi
52#echo "t -> p"
53#$cmd -in f.t -inform t -outform p >ff.p2
54#if [ $? != 0 ]; then exit 1; fi
55echo "p -> p"
56$cmd -in f.p -inform p -outform p >ff.p3
57if [ $? != 0 ]; then exit 1; fi
58
59cmp fff.p f.p
60if [ $? != 0 ]; then exit 1; fi
61cmp fff.p ff.p1
62if [ $? != 0 ]; then exit 1; fi
63#cmp fff.p ff.p2
64#if [ $? != 0 ]; then exit 1; fi
65cmp fff.p ff.p3
66if [ $? != 0 ]; then exit 1; fi
67
68#cmp f.t ff.t1
69#if [ $? != 0 ]; then exit 1; fi
70#cmp f.t ff.t2
71#if [ $? != 0 ]; then exit 1; fi
72#cmp f.t ff.t3
73#if [ $? != 0 ]; then exit 1; fi
74
75cmp f.p ff.p1
76if [ $? != 0 ]; then exit 1; fi
77#cmp f.p ff.p2
78#if [ $? != 0 ]; then exit 1; fi
79cmp f.p ff.p3
80if [ $? != 0 ]; then exit 1; fi
81
82/bin/rm -f f.* ff.* fff.*
83exit 0
diff --git a/src/lib/libssl/test/trsa b/src/lib/libssl/test/trsa
deleted file mode 100644
index 249ac1ddcc..0000000000
--- a/src/lib/libssl/test/trsa
+++ /dev/null
@@ -1,83 +0,0 @@
1#!/bin/sh
2
3if ../util/shlib_wrap.sh ../apps/openssl no-rsa; then
4 echo skipping rsa conversion test
5 exit 0
6fi
7
8cmd='../util/shlib_wrap.sh ../apps/openssl rsa'
9
10if [ "$1"x != "x" ]; then
11 t=$1
12else
13 t=testrsa.pem
14fi
15
16echo testing rsa conversions
17cp $t fff.p
18
19echo "p -> d"
20$cmd -in fff.p -inform p -outform d >f.d
21if [ $? != 0 ]; then exit 1; fi
22#echo "p -> t"
23#$cmd -in fff.p -inform p -outform t >f.t
24#if [ $? != 0 ]; then exit 1; fi
25echo "p -> p"
26$cmd -in fff.p -inform p -outform p >f.p
27if [ $? != 0 ]; then exit 1; fi
28
29echo "d -> d"
30$cmd -in f.d -inform d -outform d >ff.d1
31if [ $? != 0 ]; then exit 1; fi
32#echo "t -> d"
33#$cmd -in f.t -inform t -outform d >ff.d2
34#if [ $? != 0 ]; then exit 1; fi
35echo "p -> d"
36$cmd -in f.p -inform p -outform d >ff.d3
37if [ $? != 0 ]; then exit 1; fi
38
39#echo "d -> t"
40#$cmd -in f.d -inform d -outform t >ff.t1
41#if [ $? != 0 ]; then exit 1; fi
42#echo "t -> t"
43#$cmd -in f.t -inform t -outform t >ff.t2
44#if [ $? != 0 ]; then exit 1; fi
45#echo "p -> t"
46#$cmd -in f.p -inform p -outform t >ff.t3
47#if [ $? != 0 ]; then exit 1; fi
48
49echo "d -> p"
50$cmd -in f.d -inform d -outform p >ff.p1
51if [ $? != 0 ]; then exit 1; fi
52#echo "t -> p"
53#$cmd -in f.t -inform t -outform p >ff.p2
54#if [ $? != 0 ]; then exit 1; fi
55echo "p -> p"
56$cmd -in f.p -inform p -outform p >ff.p3
57if [ $? != 0 ]; then exit 1; fi
58
59cmp fff.p f.p
60if [ $? != 0 ]; then exit 1; fi
61cmp fff.p ff.p1
62if [ $? != 0 ]; then exit 1; fi
63#cmp fff.p ff.p2
64#if [ $? != 0 ]; then exit 1; fi
65cmp fff.p ff.p3
66if [ $? != 0 ]; then exit 1; fi
67
68#cmp f.t ff.t1
69#if [ $? != 0 ]; then exit 1; fi
70#cmp f.t ff.t2
71#if [ $? != 0 ]; then exit 1; fi
72#cmp f.t ff.t3
73#if [ $? != 0 ]; then exit 1; fi
74
75cmp f.p ff.p1
76if [ $? != 0 ]; then exit 1; fi
77#cmp f.p ff.p2
78#if [ $? != 0 ]; then exit 1; fi
79cmp f.p ff.p3
80if [ $? != 0 ]; then exit 1; fi
81
82/bin/rm -f f.* ff.* fff.*
83exit 0
diff --git a/src/lib/libssl/test/tsid b/src/lib/libssl/test/tsid
deleted file mode 100644
index 6adbd531ce..0000000000
--- a/src/lib/libssl/test/tsid
+++ /dev/null
@@ -1,78 +0,0 @@
1#!/bin/sh
2
3cmd='../util/shlib_wrap.sh ../apps/openssl sess_id'
4
5if [ "$1"x != "x" ]; then
6 t=$1
7else
8 t=testsid.pem
9fi
10
11echo testing session-id conversions
12cp $t fff.p
13
14echo "p -> d"
15$cmd -in fff.p -inform p -outform d >f.d
16if [ $? != 0 ]; then exit 1; fi
17#echo "p -> t"
18#$cmd -in fff.p -inform p -outform t >f.t
19#if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27#echo "t -> d"
28#$cmd -in f.t -inform t -outform d >ff.d2
29#if [ $? != 0 ]; then exit 1; fi
30echo "p -> d"
31$cmd -in f.p -inform p -outform d >ff.d3
32if [ $? != 0 ]; then exit 1; fi
33
34#echo "d -> t"
35#$cmd -in f.d -inform d -outform t >ff.t1
36#if [ $? != 0 ]; then exit 1; fi
37#echo "t -> t"
38#$cmd -in f.t -inform t -outform t >ff.t2
39#if [ $? != 0 ]; then exit 1; fi
40#echo "p -> t"
41#$cmd -in f.p -inform p -outform t >ff.t3
42#if [ $? != 0 ]; then exit 1; fi
43
44echo "d -> p"
45$cmd -in f.d -inform d -outform p >ff.p1
46if [ $? != 0 ]; then exit 1; fi
47#echo "t -> p"
48#$cmd -in f.t -inform t -outform p >ff.p2
49#if [ $? != 0 ]; then exit 1; fi
50echo "p -> p"
51$cmd -in f.p -inform p -outform p >ff.p3
52if [ $? != 0 ]; then exit 1; fi
53
54cmp fff.p f.p
55if [ $? != 0 ]; then exit 1; fi
56cmp fff.p ff.p1
57if [ $? != 0 ]; then exit 1; fi
58#cmp fff.p ff.p2
59#if [ $? != 0 ]; then exit 1; fi
60cmp fff.p ff.p3
61if [ $? != 0 ]; then exit 1; fi
62
63#cmp f.t ff.t1
64#if [ $? != 0 ]; then exit 1; fi
65#cmp f.t ff.t2
66#if [ $? != 0 ]; then exit 1; fi
67#cmp f.t ff.t3
68#if [ $? != 0 ]; then exit 1; fi
69
70cmp f.p ff.p1
71if [ $? != 0 ]; then exit 1; fi
72#cmp f.p ff.p2
73#if [ $? != 0 ]; then exit 1; fi
74cmp f.p ff.p3
75if [ $? != 0 ]; then exit 1; fi
76
77/bin/rm -f f.* ff.* fff.*
78exit 0
diff --git a/src/lib/libssl/test/tx509 b/src/lib/libssl/test/tx509
deleted file mode 100644
index 4a15b98d17..0000000000
--- a/src/lib/libssl/test/tx509
+++ /dev/null
@@ -1,78 +0,0 @@
1#!/bin/sh
2
3cmd='../util/shlib_wrap.sh ../apps/openssl x509'
4
5if [ "$1"x != "x" ]; then
6 t=$1
7else
8 t=testx509.pem
9fi
10
11echo testing X509 conversions
12cp $t fff.p
13
14echo "p -> d"
15$cmd -in fff.p -inform p -outform d >f.d
16if [ $? != 0 ]; then exit 1; fi
17echo "p -> n"
18$cmd -in fff.p -inform p -outform n >f.n
19if [ $? != 0 ]; then exit 1; fi
20echo "p -> p"
21$cmd -in fff.p -inform p -outform p >f.p
22if [ $? != 0 ]; then exit 1; fi
23
24echo "d -> d"
25$cmd -in f.d -inform d -outform d >ff.d1
26if [ $? != 0 ]; then exit 1; fi
27echo "n -> d"
28$cmd -in f.n -inform n -outform d >ff.d2
29if [ $? != 0 ]; then exit 1; fi
30echo "p -> d"
31$cmd -in f.p -inform p -outform d >ff.d3
32if [ $? != 0 ]; then exit 1; fi
33
34echo "d -> n"
35$cmd -in f.d -inform d -outform n >ff.n1
36if [ $? != 0 ]; then exit 1; fi
37echo "n -> n"
38$cmd -in f.n -inform n -outform n >ff.n2
39if [ $? != 0 ]; then exit 1; fi
40echo "p -> n"
41$cmd -in f.p -inform p -outform n >ff.n3
42if [ $? != 0 ]; then exit 1; fi
43
44echo "d -> p"
45$cmd -in f.d -inform d -outform p >ff.p1
46if [ $? != 0 ]; then exit 1; fi
47echo "n -> p"
48$cmd -in f.n -inform n -outform p >ff.p2
49if [ $? != 0 ]; then exit 1; fi
50echo "p -> p"
51$cmd -in f.p -inform p -outform p >ff.p3
52if [ $? != 0 ]; then exit 1; fi
53
54cmp fff.p f.p
55if [ $? != 0 ]; then exit 1; fi
56cmp fff.p ff.p1
57if [ $? != 0 ]; then exit 1; fi
58cmp fff.p ff.p2
59if [ $? != 0 ]; then exit 1; fi
60cmp fff.p ff.p3
61if [ $? != 0 ]; then exit 1; fi
62
63cmp f.n ff.n1
64if [ $? != 0 ]; then exit 1; fi
65cmp f.n ff.n2
66if [ $? != 0 ]; then exit 1; fi
67cmp f.n ff.n3
68if [ $? != 0 ]; then exit 1; fi
69
70cmp f.p ff.p1
71if [ $? != 0 ]; then exit 1; fi
72cmp f.p ff.p2
73if [ $? != 0 ]; then exit 1; fi
74cmp f.p ff.p3
75if [ $? != 0 ]; then exit 1; fi
76
77/bin/rm -f f.* ff.* fff.*
78exit 0
diff --git a/src/lib/libssl/test/v3-cert1.pem b/src/lib/libssl/test/v3-cert1.pem
deleted file mode 100644
index 0da253d5c3..0000000000
--- a/src/lib/libssl/test/v3-cert1.pem
+++ /dev/null
@@ -1,16 +0,0 @@
1-----BEGIN CERTIFICATE-----
2MIICjTCCAfigAwIBAgIEMaYgRzALBgkqhkiG9w0BAQQwRTELMAkGA1UEBhMCVVMx
3NjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFuZCBTcGFjZSBBZG1pbmlz
4dHJhdGlvbjAmFxE5NjA1MjgxMzQ5MDUrMDgwMBcROTgwNTI4MTM0OTA1KzA4MDAw
5ZzELMAkGA1UEBhMCVVMxNjA0BgNVBAoTLU5hdGlvbmFsIEFlcm9uYXV0aWNzIGFu
6ZCBTcGFjZSBBZG1pbmlzdHJhdGlvbjEgMAkGA1UEBRMCMTYwEwYDVQQDEwxTdGV2
7ZSBTY2hvY2gwWDALBgkqhkiG9w0BAQEDSQAwRgJBALrAwyYdgxmzNP/ts0Uyf6Bp
8miJYktU/w4NG67ULaN4B5CnEz7k57s9o3YY3LecETgQ5iQHmkwlYDTL2fTgVfw0C
9AQOjgaswgagwZAYDVR0ZAQH/BFowWDBWMFQxCzAJBgNVBAYTAlVTMTYwNAYDVQQK
10Ey1OYXRpb25hbCBBZXJvbmF1dGljcyBhbmQgU3BhY2UgQWRtaW5pc3RyYXRpb24x
11DTALBgNVBAMTBENSTDEwFwYDVR0BAQH/BA0wC4AJODMyOTcwODEwMBgGA1UdAgQR
12MA8ECTgzMjk3MDgyM4ACBSAwDQYDVR0KBAYwBAMCBkAwCwYJKoZIhvcNAQEEA4GB
13AH2y1VCEw/A4zaXzSYZJTTUi3uawbbFiS2yxHvgf28+8Js0OHXk1H1w2d6qOHH21
14X82tZXd/0JtG0g1T9usFFBDvYK8O0ebgz/P5ELJnBL2+atObEuJy1ZZ0pBDWINR3
15WkDNLCGiTkCKp0F5EWIrVDwh54NNevkCQRZita+z4IBO
16-----END CERTIFICATE-----
diff --git a/src/lib/libssl/test/v3-cert2.pem b/src/lib/libssl/test/v3-cert2.pem
deleted file mode 100644
index de0723ff8d..0000000000
--- a/src/lib/libssl/test/v3-cert2.pem
+++ /dev/null
@@ -1,16 +0,0 @@
1-----BEGIN CERTIFICATE-----
2MIICiTCCAfKgAwIBAgIEMeZfHzANBgkqhkiG9w0BAQQFADB9MQswCQYDVQQGEwJD
3YTEPMA0GA1UEBxMGTmVwZWFuMR4wHAYDVQQLExVObyBMaWFiaWxpdHkgQWNjZXB0
4ZWQxHzAdBgNVBAoTFkZvciBEZW1vIFB1cnBvc2VzIE9ubHkxHDAaBgNVBAMTE0Vu
5dHJ1c3QgRGVtbyBXZWIgQ0EwHhcNOTYwNzEyMTQyMDE1WhcNOTYxMDEyMTQyMDE1
6WjB0MSQwIgYJKoZIhvcNAQkBExVjb29rZUBpc3NsLmF0bC5ocC5jb20xCzAJBgNV
7BAYTAlVTMScwJQYDVQQLEx5IZXdsZXR0IFBhY2thcmQgQ29tcGFueSAoSVNTTCkx
8FjAUBgNVBAMTDVBhdWwgQS4gQ29va2UwXDANBgkqhkiG9w0BAQEFAANLADBIAkEA
96ceSq9a9AU6g+zBwaL/yVmW1/9EE8s5you1mgjHnj0wAILuoB3L6rm6jmFRy7QZT
10G43IhVZdDua4e+5/n1ZslwIDAQABo2MwYTARBglghkgBhvhCAQEEBAMCB4AwTAYJ
11YIZIAYb4QgENBD8WPVRoaXMgY2VydGlmaWNhdGUgaXMgb25seSBpbnRlbmRlZCBm
12b3IgZGVtb25zdHJhdGlvbiBwdXJwb3Nlcy4wDQYJKoZIhvcNAQEEBQADgYEAi8qc
13F3zfFqy1sV8NhjwLVwOKuSfhR/Z8mbIEUeSTlnH3QbYt3HWZQ+vXI8mvtZoBc2Fz
14lexKeIkAZXCesqGbs6z6nCt16P6tmdfbZF3I3AWzLquPcOXjPf4HgstkyvVBn0Ap
15jAFN418KF/Cx4qyHB4cjdvLrRjjQLnb2+ibo7QU=
16-----END CERTIFICATE-----
diff --git a/src/lib/libssl/tls1.h b/src/lib/libssl/tls1.h
deleted file mode 100644
index d018fced5c..0000000000
--- a/src/lib/libssl/tls1.h
+++ /dev/null
@@ -1,764 +0,0 @@
1/* $OpenBSD: tls1.h,v 1.60 2024/10/23 01:57:19 jsg Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 *
114 * Portions of the attached software ("Contribution") are developed by
115 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
116 *
117 * The Contribution is licensed pursuant to the OpenSSL open source
118 * license provided above.
119 *
120 * ECC cipher suite support in OpenSSL originally written by
121 * Vipul Gupta and Sumit Gupta of Sun Microsystems Laboratories.
122 *
123 */
124/* ====================================================================
125 * Copyright 2005 Nokia. All rights reserved.
126 *
127 * The portions of the attached software ("Contribution") is developed by
128 * Nokia Corporation and is licensed pursuant to the OpenSSL open source
129 * license.
130 *
131 * The Contribution, originally written by Mika Kousa and Pasi Eronen of
132 * Nokia Corporation, consists of the "PSK" (Pre-Shared Key) ciphersuites
133 * support (see RFC 4279) to OpenSSL.
134 *
135 * No patent licenses or other rights except those expressly stated in
136 * the OpenSSL open source license shall be deemed granted or received
137 * expressly, by implication, estoppel, or otherwise.
138 *
139 * No assurances are provided by Nokia that the Contribution does not
140 * infringe the patent or other intellectual property rights of any third
141 * party or that the license provides you with all the necessary rights
142 * to make use of the Contribution.
143 *
144 * THE SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. IN
145 * ADDITION TO THE DISCLAIMERS INCLUDED IN THE LICENSE, NOKIA
146 * SPECIFICALLY DISCLAIMS ANY LIABILITY FOR CLAIMS BROUGHT BY YOU OR ANY
147 * OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS OR
148 * OTHERWISE.
149 */
150
151#ifndef HEADER_TLS1_H
152#define HEADER_TLS1_H
153
154#include <openssl/opensslconf.h>
155
156#include <openssl/buffer.h>
157
158#ifdef __cplusplus
159extern "C" {
160#endif
161
162#define OPENSSL_TLS_SECURITY_LEVEL 1
163
164#define TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES 0
165
166#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
167#define TLS1_3_VERSION 0x0304
168#endif
169
170#define TLS1_2_VERSION 0x0303
171#define TLS1_2_VERSION_MAJOR 0x03
172#define TLS1_2_VERSION_MINOR 0x03
173
174#define TLS1_1_VERSION 0x0302
175#define TLS1_1_VERSION_MAJOR 0x03
176#define TLS1_1_VERSION_MINOR 0x02
177
178#define TLS1_VERSION 0x0301
179#define TLS1_VERSION_MAJOR 0x03
180#define TLS1_VERSION_MINOR 0x01
181
182#ifndef LIBRESSL_INTERNAL
183#define TLS1_AD_DECRYPTION_FAILED 21
184#define TLS1_AD_RECORD_OVERFLOW 22
185#define TLS1_AD_UNKNOWN_CA 48 /* fatal */
186#define TLS1_AD_ACCESS_DENIED 49 /* fatal */
187#define TLS1_AD_DECODE_ERROR 50 /* fatal */
188#define TLS1_AD_DECRYPT_ERROR 51
189#define TLS1_AD_EXPORT_RESTRICTION 60 /* fatal */
190#define TLS1_AD_PROTOCOL_VERSION 70 /* fatal */
191#define TLS1_AD_INSUFFICIENT_SECURITY 71 /* fatal */
192#define TLS1_AD_INTERNAL_ERROR 80 /* fatal */
193/* Code 86 from RFC 7507. */
194#define TLS1_AD_INAPPROPRIATE_FALLBACK 86 /* fatal */
195#define TLS1_AD_USER_CANCELLED 90
196#define TLS1_AD_NO_RENEGOTIATION 100
197/* Codes 110-114 from RFC 3546. */
198#define TLS1_AD_UNSUPPORTED_EXTENSION 110
199#define TLS1_AD_CERTIFICATE_UNOBTAINABLE 111
200#define TLS1_AD_UNRECOGNIZED_NAME 112
201#define TLS1_AD_BAD_CERTIFICATE_STATUS_RESPONSE 113
202#define TLS1_AD_BAD_CERTIFICATE_HASH_VALUE 114
203/* Code 115 from RFC 4279. */
204#define TLS1_AD_UNKNOWN_PSK_IDENTITY 115 /* fatal */
205#endif
206
207/*
208 * TLS ExtensionType values.
209 *
210 * https://www.iana.org/assignments/tls-extensiontype-values/
211 */
212
213/* ExtensionType values from RFC 3546, RFC 4366 and RFC 6066. */
214#define TLSEXT_TYPE_server_name 0
215#define TLSEXT_TYPE_max_fragment_length 1
216#define TLSEXT_TYPE_client_certificate_url 2
217#define TLSEXT_TYPE_trusted_ca_keys 3
218#define TLSEXT_TYPE_truncated_hmac 4
219#define TLSEXT_TYPE_status_request 5
220
221/* ExtensionType values from RFC 4681. */
222#define TLSEXT_TYPE_user_mapping 6
223
224/* ExtensionType values from RFC 5878. */
225#define TLSEXT_TYPE_client_authz 7
226#define TLSEXT_TYPE_server_authz 8
227
228/* ExtensionType values from RFC 6091. */
229#define TLSEXT_TYPE_cert_type 9
230
231/* ExtensionType values from RFC 7919. */
232#define TLSEXT_TYPE_supported_groups 10
233
234/* ExtensionType values from RFC 4492. */
235#ifndef LIBRESSL_INTERNAL
236#define TLSEXT_TYPE_elliptic_curves TLSEXT_TYPE_supported_groups
237#endif
238#define TLSEXT_TYPE_ec_point_formats 11
239
240/* ExtensionType value from RFC 5054. */
241#define TLSEXT_TYPE_srp 12
242
243/* ExtensionType value from RFC 5246/RFC 8446. */
244#define TLSEXT_TYPE_signature_algorithms 13
245
246/* ExtensionType value from RFC 5764. */
247#define TLSEXT_TYPE_use_srtp 14
248
249/* ExtensionType value from RFC 5620. */
250#define TLSEXT_TYPE_heartbeat 15
251
252/* ExtensionType value from RFC 7301. */
253#define TLSEXT_TYPE_application_layer_protocol_negotiation 16
254
255/* ExtensionType value from RFC 7685. */
256#define TLSEXT_TYPE_padding 21
257
258/* ExtensionType value from RFC 4507. */
259#define TLSEXT_TYPE_session_ticket 35
260
261/* ExtensionType values from RFC 8446 section 4.2 */
262#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
263#define TLSEXT_TYPE_pre_shared_key 41
264#define TLSEXT_TYPE_early_data 42
265#define TLSEXT_TYPE_supported_versions 43
266#define TLSEXT_TYPE_cookie 44
267#define TLSEXT_TYPE_psk_key_exchange_modes 45
268#define TLSEXT_TYPE_certificate_authorities 47
269#define TLSEXT_TYPE_oid_filters 48
270#define TLSEXT_TYPE_post_handshake_auth 49
271#define TLSEXT_TYPE_signature_algorithms_cert 50
272#define TLSEXT_TYPE_key_share 51
273#endif
274
275/* ExtensionType value from RFC 9001 section 8.2 */
276#if defined(LIBRESSL_HAS_QUIC) || defined(LIBRESSL_INTERNAL)
277#define TLSEXT_TYPE_quic_transport_parameters 57
278#endif
279
280/*
281 * TLS 1.3 extension names from OpenSSL, where they decided to use a different
282 * name from that given in RFC 8446.
283 */
284#if defined(LIBRESSL_HAS_TLS1_3)
285#define TLSEXT_TYPE_psk TLSEXT_TYPE_pre_shared_key
286#define TLSEXT_TYPE_psk_kex_modes TLSEXT_TYPE_psk_key_exchange_modes
287#endif
288
289/* Temporary extension type */
290#define TLSEXT_TYPE_renegotiate 0xff01
291
292/* NameType value from RFC 3546. */
293#define TLSEXT_NAMETYPE_host_name 0
294/* status request value from RFC 3546 */
295#define TLSEXT_STATUSTYPE_ocsp 1
296
297/* ECPointFormat values from RFC 4492. */
298#define TLSEXT_ECPOINTFORMAT_first 0
299#define TLSEXT_ECPOINTFORMAT_uncompressed 0
300#define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_prime 1
301#define TLSEXT_ECPOINTFORMAT_ansiX962_compressed_char2 2
302#define TLSEXT_ECPOINTFORMAT_last 2
303
304#define TLSEXT_MAXLEN_host_name 255
305
306const char *SSL_get_servername(const SSL *s, const int type);
307int SSL_get_servername_type(const SSL *s);
308/* SSL_export_keying_material exports a value derived from the master secret,
309 * as specified in RFC 5705. It writes |olen| bytes to |out| given a label and
310 * optional context. (Since a zero length context is allowed, the |use_context|
311 * flag controls whether a context is included.)
312 *
313 * It returns 1 on success and zero otherwise.
314 */
315int SSL_export_keying_material(SSL *s, unsigned char *out, size_t olen,
316 const char *label, size_t llen, const unsigned char *p, size_t plen,
317 int use_context);
318
319int SSL_get_signature_type_nid(const SSL *ssl, int *nid);
320int SSL_get_peer_signature_type_nid(const SSL *ssl, int *nid);
321
322#define SSL_set_tlsext_host_name(s,name) \
323SSL_ctrl(s,SSL_CTRL_SET_TLSEXT_HOSTNAME,TLSEXT_NAMETYPE_host_name,(char *)name)
324
325#define SSL_set_tlsext_debug_callback(ssl, cb) \
326SSL_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_CB,(void (*)(void))cb)
327
328#define SSL_set_tlsext_debug_arg(ssl, arg) \
329SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_DEBUG_ARG,0, (void *)arg)
330
331#define SSL_get_tlsext_status_type(ssl) \
332SSL_ctrl(ssl, SSL_CTRL_GET_TLSEXT_STATUS_REQ_TYPE, 0, NULL)
333
334#define SSL_set_tlsext_status_type(ssl, type) \
335SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_TYPE,type, NULL)
336
337#define SSL_get_tlsext_status_exts(ssl, arg) \
338SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg)
339
340#define SSL_set_tlsext_status_exts(ssl, arg) \
341SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_EXTS,0, (void *)arg)
342
343#define SSL_get_tlsext_status_ids(ssl, arg) \
344SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg)
345
346#define SSL_set_tlsext_status_ids(ssl, arg) \
347SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_IDS,0, (void *)arg)
348
349#define SSL_get_tlsext_status_ocsp_resp(ssl, arg) \
350SSL_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_OCSP_RESP,0, (void *)arg)
351
352#define SSL_set_tlsext_status_ocsp_resp(ssl, arg, arglen) \
353SSL_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_OCSP_RESP,arglen, (void *)arg)
354
355#define SSL_CTX_set_tlsext_servername_callback(ctx, cb) \
356SSL_CTX_callback_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_CB,(void (*)(void))cb)
357
358#define SSL_TLSEXT_ERR_OK 0
359#define SSL_TLSEXT_ERR_ALERT_WARNING 1
360#define SSL_TLSEXT_ERR_ALERT_FATAL 2
361#define SSL_TLSEXT_ERR_NOACK 3
362
363#define SSL_CTX_set_tlsext_servername_arg(ctx, arg) \
364SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG,0, (void *)arg)
365
366#define SSL_CTX_get_tlsext_ticket_keys(ctx, keys, keylen) \
367 SSL_CTX_ctrl((ctx),SSL_CTRL_GET_TLSEXT_TICKET_KEYS,(keylen),(keys))
368#define SSL_CTX_set_tlsext_ticket_keys(ctx, keys, keylen) \
369 SSL_CTX_ctrl((ctx),SSL_CTRL_SET_TLSEXT_TICKET_KEYS,(keylen),(keys))
370
371#define SSL_CTX_get_tlsext_status_cb(ssl, cb) \
372SSL_CTX_callback_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB,(void (*)(void))cb)
373#define SSL_CTX_set_tlsext_status_cb(ssl, cb) \
374SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB,(void (*)(void))cb)
375
376#define SSL_CTX_get_tlsext_status_arg(ssl, arg) \
377SSL_CTX_ctrl(ssl,SSL_CTRL_GET_TLSEXT_STATUS_REQ_CB_ARG,0,(void *)arg)
378#define SSL_CTX_set_tlsext_status_arg(ssl, arg) \
379SSL_CTX_ctrl(ssl,SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB_ARG,0,(void *)arg)
380
381#define SSL_CTX_set_tlsext_ticket_key_cb(ssl, cb) \
382SSL_CTX_callback_ctrl(ssl,SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB,(void (*)(void))cb)
383
384/* PSK ciphersuites from RFC 4279. */
385#define TLS1_CK_PSK_WITH_RC4_128_SHA 0x0300008A
386#define TLS1_CK_PSK_WITH_3DES_EDE_CBC_SHA 0x0300008B
387#define TLS1_CK_PSK_WITH_AES_128_CBC_SHA 0x0300008C
388#define TLS1_CK_PSK_WITH_AES_256_CBC_SHA 0x0300008D
389
390/* Additional TLS ciphersuites from expired Internet Draft
391 * draft-ietf-tls-56-bit-ciphersuites-01.txt
392 * (available if TLS1_ALLOW_EXPERIMENTAL_CIPHERSUITES is defined, see
393 * s3_lib.c). We actually treat them like SSL 3.0 ciphers, which we probably
394 * shouldn't. Note that the first two are actually not in the IDs. */
395#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_MD5 0x03000060 /* not in ID */
396#define TLS1_CK_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 0x03000061 /* not in ID */
397#define TLS1_CK_RSA_EXPORT1024_WITH_DES_CBC_SHA 0x03000062
398#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA 0x03000063
399#define TLS1_CK_RSA_EXPORT1024_WITH_RC4_56_SHA 0x03000064
400#define TLS1_CK_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA 0x03000065
401#define TLS1_CK_DHE_DSS_WITH_RC4_128_SHA 0x03000066
402
403/* AES ciphersuites from RFC 3268. */
404
405#define TLS1_CK_RSA_WITH_AES_128_SHA 0x0300002F
406#define TLS1_CK_DH_DSS_WITH_AES_128_SHA 0x03000030
407#define TLS1_CK_DH_RSA_WITH_AES_128_SHA 0x03000031
408#define TLS1_CK_DHE_DSS_WITH_AES_128_SHA 0x03000032
409#define TLS1_CK_DHE_RSA_WITH_AES_128_SHA 0x03000033
410#define TLS1_CK_ADH_WITH_AES_128_SHA 0x03000034
411
412#define TLS1_CK_RSA_WITH_AES_256_SHA 0x03000035
413#define TLS1_CK_DH_DSS_WITH_AES_256_SHA 0x03000036
414#define TLS1_CK_DH_RSA_WITH_AES_256_SHA 0x03000037
415#define TLS1_CK_DHE_DSS_WITH_AES_256_SHA 0x03000038
416#define TLS1_CK_DHE_RSA_WITH_AES_256_SHA 0x03000039
417#define TLS1_CK_ADH_WITH_AES_256_SHA 0x0300003A
418
419/* TLS v1.2 ciphersuites */
420#define TLS1_CK_RSA_WITH_NULL_SHA256 0x0300003B
421#define TLS1_CK_RSA_WITH_AES_128_SHA256 0x0300003C
422#define TLS1_CK_RSA_WITH_AES_256_SHA256 0x0300003D
423#define TLS1_CK_DH_DSS_WITH_AES_128_SHA256 0x0300003E
424#define TLS1_CK_DH_RSA_WITH_AES_128_SHA256 0x0300003F
425#define TLS1_CK_DHE_DSS_WITH_AES_128_SHA256 0x03000040
426
427/* Camellia ciphersuites from RFC 4132. */
428#define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000041
429#define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000042
430#define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000043
431#define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA 0x03000044
432#define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA 0x03000045
433#define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA 0x03000046
434
435/* TLS v1.2 ciphersuites */
436#define TLS1_CK_DHE_RSA_WITH_AES_128_SHA256 0x03000067
437#define TLS1_CK_DH_DSS_WITH_AES_256_SHA256 0x03000068
438#define TLS1_CK_DH_RSA_WITH_AES_256_SHA256 0x03000069
439#define TLS1_CK_DHE_DSS_WITH_AES_256_SHA256 0x0300006A
440#define TLS1_CK_DHE_RSA_WITH_AES_256_SHA256 0x0300006B
441#define TLS1_CK_ADH_WITH_AES_128_SHA256 0x0300006C
442#define TLS1_CK_ADH_WITH_AES_256_SHA256 0x0300006D
443
444/* Camellia ciphersuites from RFC 4132. */
445#define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000084
446#define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000085
447#define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000086
448#define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA 0x03000087
449#define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA 0x03000088
450#define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA 0x03000089
451
452/* SEED ciphersuites from RFC 4162. */
453#define TLS1_CK_RSA_WITH_SEED_SHA 0x03000096
454#define TLS1_CK_DH_DSS_WITH_SEED_SHA 0x03000097
455#define TLS1_CK_DH_RSA_WITH_SEED_SHA 0x03000098
456#define TLS1_CK_DHE_DSS_WITH_SEED_SHA 0x03000099
457#define TLS1_CK_DHE_RSA_WITH_SEED_SHA 0x0300009A
458#define TLS1_CK_ADH_WITH_SEED_SHA 0x0300009B
459
460/* TLS v1.2 GCM ciphersuites from RFC 5288. */
461#define TLS1_CK_RSA_WITH_AES_128_GCM_SHA256 0x0300009C
462#define TLS1_CK_RSA_WITH_AES_256_GCM_SHA384 0x0300009D
463#define TLS1_CK_DHE_RSA_WITH_AES_128_GCM_SHA256 0x0300009E
464#define TLS1_CK_DHE_RSA_WITH_AES_256_GCM_SHA384 0x0300009F
465#define TLS1_CK_DH_RSA_WITH_AES_128_GCM_SHA256 0x030000A0
466#define TLS1_CK_DH_RSA_WITH_AES_256_GCM_SHA384 0x030000A1
467#define TLS1_CK_DHE_DSS_WITH_AES_128_GCM_SHA256 0x030000A2
468#define TLS1_CK_DHE_DSS_WITH_AES_256_GCM_SHA384 0x030000A3
469#define TLS1_CK_DH_DSS_WITH_AES_128_GCM_SHA256 0x030000A4
470#define TLS1_CK_DH_DSS_WITH_AES_256_GCM_SHA384 0x030000A5
471#define TLS1_CK_ADH_WITH_AES_128_GCM_SHA256 0x030000A6
472#define TLS1_CK_ADH_WITH_AES_256_GCM_SHA384 0x030000A7
473
474/* TLS 1.2 Camellia SHA-256 ciphersuites from RFC5932 */
475#define TLS1_CK_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BA
476#define TLS1_CK_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 0x030000BB
477#define TLS1_CK_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BC
478#define TLS1_CK_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 0x030000BD
479#define TLS1_CK_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 0x030000BE
480#define TLS1_CK_ADH_WITH_CAMELLIA_128_CBC_SHA256 0x030000BF
481
482#define TLS1_CK_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C0
483#define TLS1_CK_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 0x030000C1
484#define TLS1_CK_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C2
485#define TLS1_CK_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 0x030000C3
486#define TLS1_CK_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 0x030000C4
487#define TLS1_CK_ADH_WITH_CAMELLIA_256_CBC_SHA256 0x030000C5
488
489/* TLS 1.3 cipher suites from RFC 8446 appendix B.4. */
490#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
491#define TLS1_3_CK_AES_128_GCM_SHA256 0x03001301
492#define TLS1_3_CK_AES_256_GCM_SHA384 0x03001302
493#define TLS1_3_CK_CHACHA20_POLY1305_SHA256 0x03001303
494#define TLS1_3_CK_AES_128_CCM_SHA256 0x03001304
495#define TLS1_3_CK_AES_128_CCM_8_SHA256 0x03001305
496#endif
497
498/* ECC ciphersuites from RFC 4492. */
499#define TLS1_CK_ECDH_ECDSA_WITH_NULL_SHA 0x0300C001
500#define TLS1_CK_ECDH_ECDSA_WITH_RC4_128_SHA 0x0300C002
501#define TLS1_CK_ECDH_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C003
502#define TLS1_CK_ECDH_ECDSA_WITH_AES_128_CBC_SHA 0x0300C004
503#define TLS1_CK_ECDH_ECDSA_WITH_AES_256_CBC_SHA 0x0300C005
504
505#define TLS1_CK_ECDHE_ECDSA_WITH_NULL_SHA 0x0300C006
506#define TLS1_CK_ECDHE_ECDSA_WITH_RC4_128_SHA 0x0300C007
507#define TLS1_CK_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA 0x0300C008
508#define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_CBC_SHA 0x0300C009
509#define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_CBC_SHA 0x0300C00A
510
511#define TLS1_CK_ECDH_RSA_WITH_NULL_SHA 0x0300C00B
512#define TLS1_CK_ECDH_RSA_WITH_RC4_128_SHA 0x0300C00C
513#define TLS1_CK_ECDH_RSA_WITH_DES_192_CBC3_SHA 0x0300C00D
514#define TLS1_CK_ECDH_RSA_WITH_AES_128_CBC_SHA 0x0300C00E
515#define TLS1_CK_ECDH_RSA_WITH_AES_256_CBC_SHA 0x0300C00F
516
517#define TLS1_CK_ECDHE_RSA_WITH_NULL_SHA 0x0300C010
518#define TLS1_CK_ECDHE_RSA_WITH_RC4_128_SHA 0x0300C011
519#define TLS1_CK_ECDHE_RSA_WITH_DES_192_CBC3_SHA 0x0300C012
520#define TLS1_CK_ECDHE_RSA_WITH_AES_128_CBC_SHA 0x0300C013
521#define TLS1_CK_ECDHE_RSA_WITH_AES_256_CBC_SHA 0x0300C014
522
523#define TLS1_CK_ECDH_anon_WITH_NULL_SHA 0x0300C015
524#define TLS1_CK_ECDH_anon_WITH_RC4_128_SHA 0x0300C016
525#define TLS1_CK_ECDH_anon_WITH_DES_192_CBC3_SHA 0x0300C017
526#define TLS1_CK_ECDH_anon_WITH_AES_128_CBC_SHA 0x0300C018
527#define TLS1_CK_ECDH_anon_WITH_AES_256_CBC_SHA 0x0300C019
528
529/* SRP ciphersuites from RFC 5054. */
530#define TLS1_CK_SRP_SHA_WITH_3DES_EDE_CBC_SHA 0x0300C01A
531#define TLS1_CK_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA 0x0300C01B
532#define TLS1_CK_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA 0x0300C01C
533#define TLS1_CK_SRP_SHA_WITH_AES_128_CBC_SHA 0x0300C01D
534#define TLS1_CK_SRP_SHA_RSA_WITH_AES_128_CBC_SHA 0x0300C01E
535#define TLS1_CK_SRP_SHA_DSS_WITH_AES_128_CBC_SHA 0x0300C01F
536#define TLS1_CK_SRP_SHA_WITH_AES_256_CBC_SHA 0x0300C020
537#define TLS1_CK_SRP_SHA_RSA_WITH_AES_256_CBC_SHA 0x0300C021
538#define TLS1_CK_SRP_SHA_DSS_WITH_AES_256_CBC_SHA 0x0300C022
539
540/* ECDH HMAC based ciphersuites from RFC 5289. */
541#define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_SHA256 0x0300C023
542#define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_SHA384 0x0300C024
543#define TLS1_CK_ECDH_ECDSA_WITH_AES_128_SHA256 0x0300C025
544#define TLS1_CK_ECDH_ECDSA_WITH_AES_256_SHA384 0x0300C026
545#define TLS1_CK_ECDHE_RSA_WITH_AES_128_SHA256 0x0300C027
546#define TLS1_CK_ECDHE_RSA_WITH_AES_256_SHA384 0x0300C028
547#define TLS1_CK_ECDH_RSA_WITH_AES_128_SHA256 0x0300C029
548#define TLS1_CK_ECDH_RSA_WITH_AES_256_SHA384 0x0300C02A
549
550/* ECDH GCM based ciphersuites from RFC 5289. */
551#define TLS1_CK_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 0x0300C02B
552#define TLS1_CK_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 0x0300C02C
553#define TLS1_CK_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 0x0300C02D
554#define TLS1_CK_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 0x0300C02E
555#define TLS1_CK_ECDHE_RSA_WITH_AES_128_GCM_SHA256 0x0300C02F
556#define TLS1_CK_ECDHE_RSA_WITH_AES_256_GCM_SHA384 0x0300C030
557#define TLS1_CK_ECDH_RSA_WITH_AES_128_GCM_SHA256 0x0300C031
558#define TLS1_CK_ECDH_RSA_WITH_AES_256_GCM_SHA384 0x0300C032
559
560/* ChaCha20-Poly1305 based ciphersuites. */
561#define TLS1_CK_ECDHE_RSA_CHACHA20_POLY1305 0x0300CCA8
562#define TLS1_CK_ECDHE_ECDSA_CHACHA20_POLY1305 0x0300CCA9
563#define TLS1_CK_DHE_RSA_CHACHA20_POLY1305 0x0300CCAA
564
565#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_MD5 "EXP1024-RC4-MD5"
566#define TLS1_TXT_RSA_EXPORT1024_WITH_RC2_CBC_56_MD5 "EXP1024-RC2-CBC-MD5"
567#define TLS1_TXT_RSA_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DES-CBC-SHA"
568#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_DES_CBC_SHA "EXP1024-DHE-DSS-DES-CBC-SHA"
569#define TLS1_TXT_RSA_EXPORT1024_WITH_RC4_56_SHA "EXP1024-RC4-SHA"
570#define TLS1_TXT_DHE_DSS_EXPORT1024_WITH_RC4_56_SHA "EXP1024-DHE-DSS-RC4-SHA"
571#define TLS1_TXT_DHE_DSS_WITH_RC4_128_SHA "DHE-DSS-RC4-SHA"
572
573/* AES ciphersuites from RFC 3268. */
574#define TLS1_TXT_RSA_WITH_AES_128_SHA "AES128-SHA"
575#define TLS1_TXT_DH_DSS_WITH_AES_128_SHA "DH-DSS-AES128-SHA"
576#define TLS1_TXT_DH_RSA_WITH_AES_128_SHA "DH-RSA-AES128-SHA"
577#define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA "DHE-DSS-AES128-SHA"
578#define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA "DHE-RSA-AES128-SHA"
579#define TLS1_TXT_ADH_WITH_AES_128_SHA "ADH-AES128-SHA"
580
581#define TLS1_TXT_RSA_WITH_AES_256_SHA "AES256-SHA"
582#define TLS1_TXT_DH_DSS_WITH_AES_256_SHA "DH-DSS-AES256-SHA"
583#define TLS1_TXT_DH_RSA_WITH_AES_256_SHA "DH-RSA-AES256-SHA"
584#define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA "DHE-DSS-AES256-SHA"
585#define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA "DHE-RSA-AES256-SHA"
586#define TLS1_TXT_ADH_WITH_AES_256_SHA "ADH-AES256-SHA"
587
588/* ECC ciphersuites from draft-ietf-tls-ecc-01.txt (Mar 15, 2001) */
589#define TLS1_TXT_ECDH_ECDSA_WITH_NULL_SHA "ECDH-ECDSA-NULL-SHA"
590#define TLS1_TXT_ECDH_ECDSA_WITH_RC4_128_SHA "ECDH-ECDSA-RC4-SHA"
591#define TLS1_TXT_ECDH_ECDSA_WITH_DES_192_CBC3_SHA "ECDH-ECDSA-DES-CBC3-SHA"
592#define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_CBC_SHA "ECDH-ECDSA-AES128-SHA"
593#define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_CBC_SHA "ECDH-ECDSA-AES256-SHA"
594
595#define TLS1_TXT_ECDHE_ECDSA_WITH_NULL_SHA "ECDHE-ECDSA-NULL-SHA"
596#define TLS1_TXT_ECDHE_ECDSA_WITH_RC4_128_SHA "ECDHE-ECDSA-RC4-SHA"
597#define TLS1_TXT_ECDHE_ECDSA_WITH_DES_192_CBC3_SHA "ECDHE-ECDSA-DES-CBC3-SHA"
598#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_CBC_SHA "ECDHE-ECDSA-AES128-SHA"
599#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_CBC_SHA "ECDHE-ECDSA-AES256-SHA"
600
601#define TLS1_TXT_ECDH_RSA_WITH_NULL_SHA "ECDH-RSA-NULL-SHA"
602#define TLS1_TXT_ECDH_RSA_WITH_RC4_128_SHA "ECDH-RSA-RC4-SHA"
603#define TLS1_TXT_ECDH_RSA_WITH_DES_192_CBC3_SHA "ECDH-RSA-DES-CBC3-SHA"
604#define TLS1_TXT_ECDH_RSA_WITH_AES_128_CBC_SHA "ECDH-RSA-AES128-SHA"
605#define TLS1_TXT_ECDH_RSA_WITH_AES_256_CBC_SHA "ECDH-RSA-AES256-SHA"
606
607#define TLS1_TXT_ECDHE_RSA_WITH_NULL_SHA "ECDHE-RSA-NULL-SHA"
608#define TLS1_TXT_ECDHE_RSA_WITH_RC4_128_SHA "ECDHE-RSA-RC4-SHA"
609#define TLS1_TXT_ECDHE_RSA_WITH_DES_192_CBC3_SHA "ECDHE-RSA-DES-CBC3-SHA"
610#define TLS1_TXT_ECDHE_RSA_WITH_AES_128_CBC_SHA "ECDHE-RSA-AES128-SHA"
611#define TLS1_TXT_ECDHE_RSA_WITH_AES_256_CBC_SHA "ECDHE-RSA-AES256-SHA"
612
613#define TLS1_TXT_ECDH_anon_WITH_NULL_SHA "AECDH-NULL-SHA"
614#define TLS1_TXT_ECDH_anon_WITH_RC4_128_SHA "AECDH-RC4-SHA"
615#define TLS1_TXT_ECDH_anon_WITH_DES_192_CBC3_SHA "AECDH-DES-CBC3-SHA"
616#define TLS1_TXT_ECDH_anon_WITH_AES_128_CBC_SHA "AECDH-AES128-SHA"
617#define TLS1_TXT_ECDH_anon_WITH_AES_256_CBC_SHA "AECDH-AES256-SHA"
618
619/* PSK ciphersuites from RFC 4279. */
620#define TLS1_TXT_PSK_WITH_RC4_128_SHA "PSK-RC4-SHA"
621#define TLS1_TXT_PSK_WITH_3DES_EDE_CBC_SHA "PSK-3DES-EDE-CBC-SHA"
622#define TLS1_TXT_PSK_WITH_AES_128_CBC_SHA "PSK-AES128-CBC-SHA"
623#define TLS1_TXT_PSK_WITH_AES_256_CBC_SHA "PSK-AES256-CBC-SHA"
624
625/* SRP ciphersuite from RFC 5054. */
626#define TLS1_TXT_SRP_SHA_WITH_3DES_EDE_CBC_SHA "SRP-3DES-EDE-CBC-SHA"
627#define TLS1_TXT_SRP_SHA_RSA_WITH_3DES_EDE_CBC_SHA "SRP-RSA-3DES-EDE-CBC-SHA"
628#define TLS1_TXT_SRP_SHA_DSS_WITH_3DES_EDE_CBC_SHA "SRP-DSS-3DES-EDE-CBC-SHA"
629#define TLS1_TXT_SRP_SHA_WITH_AES_128_CBC_SHA "SRP-AES-128-CBC-SHA"
630#define TLS1_TXT_SRP_SHA_RSA_WITH_AES_128_CBC_SHA "SRP-RSA-AES-128-CBC-SHA"
631#define TLS1_TXT_SRP_SHA_DSS_WITH_AES_128_CBC_SHA "SRP-DSS-AES-128-CBC-SHA"
632#define TLS1_TXT_SRP_SHA_WITH_AES_256_CBC_SHA "SRP-AES-256-CBC-SHA"
633#define TLS1_TXT_SRP_SHA_RSA_WITH_AES_256_CBC_SHA "SRP-RSA-AES-256-CBC-SHA"
634#define TLS1_TXT_SRP_SHA_DSS_WITH_AES_256_CBC_SHA "SRP-DSS-AES-256-CBC-SHA"
635
636/* Camellia ciphersuites from RFC 4132. */
637#define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA "CAMELLIA128-SHA"
638#define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA "DH-DSS-CAMELLIA128-SHA"
639#define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA "DH-RSA-CAMELLIA128-SHA"
640#define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA "DHE-DSS-CAMELLIA128-SHA"
641#define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA "DHE-RSA-CAMELLIA128-SHA"
642#define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA "ADH-CAMELLIA128-SHA"
643
644#define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA "CAMELLIA256-SHA"
645#define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA "DH-DSS-CAMELLIA256-SHA"
646#define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA "DH-RSA-CAMELLIA256-SHA"
647#define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA "DHE-DSS-CAMELLIA256-SHA"
648#define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA "DHE-RSA-CAMELLIA256-SHA"
649#define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA "ADH-CAMELLIA256-SHA"
650
651/* TLS 1.2 Camellia SHA-256 ciphersuites from RFC5932 */
652#define TLS1_TXT_RSA_WITH_CAMELLIA_128_CBC_SHA256 "CAMELLIA128-SHA256"
653#define TLS1_TXT_DH_DSS_WITH_CAMELLIA_128_CBC_SHA256 "DH-DSS-CAMELLIA128-SHA256"
654#define TLS1_TXT_DH_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DH-RSA-CAMELLIA128-SHA256"
655#define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_128_CBC_SHA256 "DHE-DSS-CAMELLIA128-SHA256"
656#define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256 "DHE-RSA-CAMELLIA128-SHA256"
657#define TLS1_TXT_ADH_WITH_CAMELLIA_128_CBC_SHA256 "ADH-CAMELLIA128-SHA256"
658
659#define TLS1_TXT_RSA_WITH_CAMELLIA_256_CBC_SHA256 "CAMELLIA256-SHA256"
660#define TLS1_TXT_DH_DSS_WITH_CAMELLIA_256_CBC_SHA256 "DH-DSS-CAMELLIA256-SHA256"
661#define TLS1_TXT_DH_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DH-RSA-CAMELLIA256-SHA256"
662#define TLS1_TXT_DHE_DSS_WITH_CAMELLIA_256_CBC_SHA256 "DHE-DSS-CAMELLIA256-SHA256"
663#define TLS1_TXT_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256 "DHE-RSA-CAMELLIA256-SHA256"
664#define TLS1_TXT_ADH_WITH_CAMELLIA_256_CBC_SHA256 "ADH-CAMELLIA256-SHA256"
665
666/* SEED ciphersuites from RFC 4162. */
667#define TLS1_TXT_RSA_WITH_SEED_SHA "SEED-SHA"
668#define TLS1_TXT_DH_DSS_WITH_SEED_SHA "DH-DSS-SEED-SHA"
669#define TLS1_TXT_DH_RSA_WITH_SEED_SHA "DH-RSA-SEED-SHA"
670#define TLS1_TXT_DHE_DSS_WITH_SEED_SHA "DHE-DSS-SEED-SHA"
671#define TLS1_TXT_DHE_RSA_WITH_SEED_SHA "DHE-RSA-SEED-SHA"
672#define TLS1_TXT_ADH_WITH_SEED_SHA "ADH-SEED-SHA"
673
674/* TLS v1.2 ciphersuites. */
675#define TLS1_TXT_RSA_WITH_NULL_SHA256 "NULL-SHA256"
676#define TLS1_TXT_RSA_WITH_AES_128_SHA256 "AES128-SHA256"
677#define TLS1_TXT_RSA_WITH_AES_256_SHA256 "AES256-SHA256"
678#define TLS1_TXT_DH_DSS_WITH_AES_128_SHA256 "DH-DSS-AES128-SHA256"
679#define TLS1_TXT_DH_RSA_WITH_AES_128_SHA256 "DH-RSA-AES128-SHA256"
680#define TLS1_TXT_DHE_DSS_WITH_AES_128_SHA256 "DHE-DSS-AES128-SHA256"
681#define TLS1_TXT_DHE_RSA_WITH_AES_128_SHA256 "DHE-RSA-AES128-SHA256"
682#define TLS1_TXT_DH_DSS_WITH_AES_256_SHA256 "DH-DSS-AES256-SHA256"
683#define TLS1_TXT_DH_RSA_WITH_AES_256_SHA256 "DH-RSA-AES256-SHA256"
684#define TLS1_TXT_DHE_DSS_WITH_AES_256_SHA256 "DHE-DSS-AES256-SHA256"
685#define TLS1_TXT_DHE_RSA_WITH_AES_256_SHA256 "DHE-RSA-AES256-SHA256"
686#define TLS1_TXT_ADH_WITH_AES_128_SHA256 "ADH-AES128-SHA256"
687#define TLS1_TXT_ADH_WITH_AES_256_SHA256 "ADH-AES256-SHA256"
688
689/* TLS v1.2 GCM ciphersuites from RFC 5288. */
690#define TLS1_TXT_RSA_WITH_AES_128_GCM_SHA256 "AES128-GCM-SHA256"
691#define TLS1_TXT_RSA_WITH_AES_256_GCM_SHA384 "AES256-GCM-SHA384"
692#define TLS1_TXT_DHE_RSA_WITH_AES_128_GCM_SHA256 "DHE-RSA-AES128-GCM-SHA256"
693#define TLS1_TXT_DHE_RSA_WITH_AES_256_GCM_SHA384 "DHE-RSA-AES256-GCM-SHA384"
694#define TLS1_TXT_DH_RSA_WITH_AES_128_GCM_SHA256 "DH-RSA-AES128-GCM-SHA256"
695#define TLS1_TXT_DH_RSA_WITH_AES_256_GCM_SHA384 "DH-RSA-AES256-GCM-SHA384"
696#define TLS1_TXT_DHE_DSS_WITH_AES_128_GCM_SHA256 "DHE-DSS-AES128-GCM-SHA256"
697#define TLS1_TXT_DHE_DSS_WITH_AES_256_GCM_SHA384 "DHE-DSS-AES256-GCM-SHA384"
698#define TLS1_TXT_DH_DSS_WITH_AES_128_GCM_SHA256 "DH-DSS-AES128-GCM-SHA256"
699#define TLS1_TXT_DH_DSS_WITH_AES_256_GCM_SHA384 "DH-DSS-AES256-GCM-SHA384"
700#define TLS1_TXT_ADH_WITH_AES_128_GCM_SHA256 "ADH-AES128-GCM-SHA256"
701#define TLS1_TXT_ADH_WITH_AES_256_GCM_SHA384 "ADH-AES256-GCM-SHA384"
702
703/* ECDH HMAC based ciphersuites from RFC 5289. */
704#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_SHA256 "ECDHE-ECDSA-AES128-SHA256"
705#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_SHA384 "ECDHE-ECDSA-AES256-SHA384"
706#define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_SHA256 "ECDH-ECDSA-AES128-SHA256"
707#define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_SHA384 "ECDH-ECDSA-AES256-SHA384"
708#define TLS1_TXT_ECDHE_RSA_WITH_AES_128_SHA256 "ECDHE-RSA-AES128-SHA256"
709#define TLS1_TXT_ECDHE_RSA_WITH_AES_256_SHA384 "ECDHE-RSA-AES256-SHA384"
710#define TLS1_TXT_ECDH_RSA_WITH_AES_128_SHA256 "ECDH-RSA-AES128-SHA256"
711#define TLS1_TXT_ECDH_RSA_WITH_AES_256_SHA384 "ECDH-RSA-AES256-SHA384"
712
713/* ECDH GCM based ciphersuites from RFC 5289. */
714#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 "ECDHE-ECDSA-AES128-GCM-SHA256"
715#define TLS1_TXT_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 "ECDHE-ECDSA-AES256-GCM-SHA384"
716#define TLS1_TXT_ECDH_ECDSA_WITH_AES_128_GCM_SHA256 "ECDH-ECDSA-AES128-GCM-SHA256"
717#define TLS1_TXT_ECDH_ECDSA_WITH_AES_256_GCM_SHA384 "ECDH-ECDSA-AES256-GCM-SHA384"
718#define TLS1_TXT_ECDHE_RSA_WITH_AES_128_GCM_SHA256 "ECDHE-RSA-AES128-GCM-SHA256"
719#define TLS1_TXT_ECDHE_RSA_WITH_AES_256_GCM_SHA384 "ECDHE-RSA-AES256-GCM-SHA384"
720#define TLS1_TXT_ECDH_RSA_WITH_AES_128_GCM_SHA256 "ECDH-RSA-AES128-GCM-SHA256"
721#define TLS1_TXT_ECDH_RSA_WITH_AES_256_GCM_SHA384 "ECDH-RSA-AES256-GCM-SHA384"
722
723/* ChaCha20-Poly1305 based ciphersuites. */
724#define TLS1_TXT_ECDHE_RSA_WITH_CHACHA20_POLY1305 "ECDHE-RSA-CHACHA20-POLY1305"
725#define TLS1_TXT_ECDHE_ECDSA_WITH_CHACHA20_POLY1305 "ECDHE-ECDSA-CHACHA20-POLY1305"
726#define TLS1_TXT_DHE_RSA_WITH_CHACHA20_POLY1305 "DHE-RSA-CHACHA20-POLY1305"
727
728/* TLS 1.3 cipher suites from RFC 8446 appendix B.4. */
729#if defined(LIBRESSL_HAS_TLS1_3) || defined(LIBRESSL_INTERNAL)
730#define TLS1_3_TXT_AES_128_GCM_SHA256 "AEAD-AES128-GCM-SHA256"
731#define TLS1_3_TXT_AES_256_GCM_SHA384 "AEAD-AES256-GCM-SHA384"
732#define TLS1_3_TXT_CHACHA20_POLY1305_SHA256 "AEAD-CHACHA20-POLY1305-SHA256"
733#define TLS1_3_TXT_AES_128_CCM_SHA256 "AEAD-AES128-CCM-SHA256"
734#define TLS1_3_TXT_AES_128_CCM_8_SHA256 "AEAD-AES128-CCM-8-SHA256"
735
736#define TLS1_3_RFC_AES_128_GCM_SHA256 "TLS_AES_128_GCM_SHA256"
737#define TLS1_3_RFC_AES_256_GCM_SHA384 "TLS_AES_256_GCM_SHA384"
738#define TLS1_3_RFC_CHACHA20_POLY1305_SHA256 "TLS_CHACHA20_POLY1305_SHA256"
739#define TLS1_3_RFC_AES_128_CCM_SHA256 "TLS_AES_128_CCM_SHA256"
740#define TLS1_3_RFC_AES_128_CCM_8_SHA256 "TLS_AES_128_CCM_8_SHA256"
741#endif
742
743#define TLS1_FINISH_MAC_LENGTH 12
744
745#define TLS_MD_MAX_CONST_SIZE 20
746#define TLS_MD_CLIENT_FINISH_CONST "client finished"
747#define TLS_MD_CLIENT_FINISH_CONST_SIZE 15
748#define TLS_MD_SERVER_FINISH_CONST "server finished"
749#define TLS_MD_SERVER_FINISH_CONST_SIZE 15
750#define TLS_MD_KEY_EXPANSION_CONST "key expansion"
751#define TLS_MD_KEY_EXPANSION_CONST_SIZE 13
752#define TLS_MD_CLIENT_WRITE_KEY_CONST "client write key"
753#define TLS_MD_CLIENT_WRITE_KEY_CONST_SIZE 16
754#define TLS_MD_SERVER_WRITE_KEY_CONST "server write key"
755#define TLS_MD_SERVER_WRITE_KEY_CONST_SIZE 16
756#define TLS_MD_IV_BLOCK_CONST "IV block"
757#define TLS_MD_IV_BLOCK_CONST_SIZE 8
758#define TLS_MD_MASTER_SECRET_CONST "master secret"
759#define TLS_MD_MASTER_SECRET_CONST_SIZE 13
760
761#ifdef __cplusplus
762}
763#endif
764#endif
diff --git a/src/lib/libssl/tls12_internal.h b/src/lib/libssl/tls12_internal.h
deleted file mode 100644
index d416b2e3f1..0000000000
--- a/src/lib/libssl/tls12_internal.h
+++ /dev/null
@@ -1,29 +0,0 @@
1/* $OpenBSD: tls12_internal.h,v 1.1 2022/11/07 11:58:45 jsing Exp $ */
2/*
3 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef HEADER_TLS12_INTERNAL_H
19#define HEADER_TLS12_INTERNAL_H
20
21__BEGIN_HIDDEN_DECLS
22
23int tls12_exporter(SSL *s, const uint8_t *label, size_t label_len,
24 const uint8_t *context_value, size_t context_value_len, int use_context,
25 uint8_t *out, size_t out_len);
26
27__END_HIDDEN_DECLS
28
29#endif
diff --git a/src/lib/libssl/tls12_key_schedule.c b/src/lib/libssl/tls12_key_schedule.c
deleted file mode 100644
index 1ac003329e..0000000000
--- a/src/lib/libssl/tls12_key_schedule.c
+++ /dev/null
@@ -1,291 +0,0 @@
1/* $OpenBSD: tls12_key_schedule.c,v 1.4 2024/02/03 15:58:34 beck Exp $ */
2/*
3 * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19
20#include <openssl/evp.h>
21
22#include "bytestring.h"
23#include "ssl_local.h"
24#include "tls12_internal.h"
25
26struct tls12_key_block {
27 CBS client_write_mac_key;
28 CBS server_write_mac_key;
29 CBS client_write_key;
30 CBS server_write_key;
31 CBS client_write_iv;
32 CBS server_write_iv;
33
34 uint8_t *key_block;
35 size_t key_block_len;
36};
37
38struct tls12_key_block *
39tls12_key_block_new(void)
40{
41 return calloc(1, sizeof(struct tls12_key_block));
42}
43
44static void
45tls12_key_block_clear(struct tls12_key_block *kb)
46{
47 CBS_init(&kb->client_write_mac_key, NULL, 0);
48 CBS_init(&kb->server_write_mac_key, NULL, 0);
49 CBS_init(&kb->client_write_key, NULL, 0);
50 CBS_init(&kb->server_write_key, NULL, 0);
51 CBS_init(&kb->client_write_iv, NULL, 0);
52 CBS_init(&kb->server_write_iv, NULL, 0);
53
54 freezero(kb->key_block, kb->key_block_len);
55 kb->key_block = NULL;
56 kb->key_block_len = 0;
57}
58
59void
60tls12_key_block_free(struct tls12_key_block *kb)
61{
62 if (kb == NULL)
63 return;
64
65 tls12_key_block_clear(kb);
66
67 freezero(kb, sizeof(struct tls12_key_block));
68}
69
70void
71tls12_key_block_client_write(struct tls12_key_block *kb, CBS *mac_key,
72 CBS *key, CBS *iv)
73{
74 CBS_dup(&kb->client_write_mac_key, mac_key);
75 CBS_dup(&kb->client_write_key, key);
76 CBS_dup(&kb->client_write_iv, iv);
77}
78
79void
80tls12_key_block_server_write(struct tls12_key_block *kb, CBS *mac_key,
81 CBS *key, CBS *iv)
82{
83 CBS_dup(&kb->server_write_mac_key, mac_key);
84 CBS_dup(&kb->server_write_key, key);
85 CBS_dup(&kb->server_write_iv, iv);
86}
87
88int
89tls12_key_block_generate(struct tls12_key_block *kb, SSL *s,
90 const EVP_AEAD *aead, const EVP_CIPHER *cipher, const EVP_MD *mac_hash)
91{
92 size_t mac_key_len = 0, key_len = 0, iv_len = 0;
93 uint8_t *key_block = NULL;
94 size_t key_block_len = 0;
95 CBS cbs;
96
97 /*
98 * Generate a TLSv1.2 key block and partition into individual secrets,
99 * as per RFC 5246 section 6.3.
100 */
101
102 tls12_key_block_clear(kb);
103
104 /* Must have AEAD or cipher/MAC pair. */
105 if (aead == NULL && (cipher == NULL || mac_hash == NULL))
106 goto err;
107
108 if (aead != NULL) {
109 key_len = EVP_AEAD_key_length(aead);
110
111 /* AEAD fixed nonce length. */
112 if (aead == EVP_aead_aes_128_gcm() ||
113 aead == EVP_aead_aes_256_gcm())
114 iv_len = 4;
115 else if (aead == EVP_aead_chacha20_poly1305())
116 iv_len = 12;
117 else
118 goto err;
119 } else if (cipher != NULL && mac_hash != NULL) {
120 /*
121 * A negative integer return value will be detected via the
122 * EVP_MAX_* checks against the size_t variables below.
123 */
124 mac_key_len = EVP_MD_size(mac_hash);
125 key_len = EVP_CIPHER_key_length(cipher);
126 iv_len = EVP_CIPHER_iv_length(cipher);
127 }
128
129 if (mac_key_len > EVP_MAX_MD_SIZE)
130 goto err;
131 if (key_len > EVP_MAX_KEY_LENGTH)
132 goto err;
133 if (iv_len > EVP_MAX_IV_LENGTH)
134 goto err;
135
136 key_block_len = 2 * mac_key_len + 2 * key_len + 2 * iv_len;
137 if ((key_block = calloc(1, key_block_len)) == NULL)
138 goto err;
139
140 if (!tls1_generate_key_block(s, key_block, key_block_len))
141 goto err;
142
143 kb->key_block = key_block;
144 kb->key_block_len = key_block_len;
145 key_block = NULL;
146 key_block_len = 0;
147
148 /* Partition key block into individual secrets. */
149 CBS_init(&cbs, kb->key_block, kb->key_block_len);
150 if (!CBS_get_bytes(&cbs, &kb->client_write_mac_key, mac_key_len))
151 goto err;
152 if (!CBS_get_bytes(&cbs, &kb->server_write_mac_key, mac_key_len))
153 goto err;
154 if (!CBS_get_bytes(&cbs, &kb->client_write_key, key_len))
155 goto err;
156 if (!CBS_get_bytes(&cbs, &kb->server_write_key, key_len))
157 goto err;
158 if (!CBS_get_bytes(&cbs, &kb->client_write_iv, iv_len))
159 goto err;
160 if (!CBS_get_bytes(&cbs, &kb->server_write_iv, iv_len))
161 goto err;
162 if (CBS_len(&cbs) != 0)
163 goto err;
164
165 return 1;
166
167 err:
168 tls12_key_block_clear(kb);
169 freezero(key_block, key_block_len);
170
171 return 0;
172}
173
174struct tls12_reserved_label {
175 const char *label;
176 size_t label_len;
177};
178
179/*
180 * RFC 5705 section 6.
181 */
182static const struct tls12_reserved_label tls12_reserved_labels[] = {
183 {
184 .label = TLS_MD_CLIENT_FINISH_CONST,
185 .label_len = TLS_MD_CLIENT_FINISH_CONST_SIZE,
186 },
187 {
188 .label = TLS_MD_SERVER_FINISH_CONST,
189 .label_len = TLS_MD_SERVER_FINISH_CONST_SIZE,
190 },
191 {
192 .label = TLS_MD_MASTER_SECRET_CONST,
193 .label_len = TLS_MD_MASTER_SECRET_CONST_SIZE,
194 },
195 {
196 .label = TLS_MD_KEY_EXPANSION_CONST,
197 .label_len = TLS_MD_KEY_EXPANSION_CONST_SIZE,
198 },
199 {
200 .label = NULL,
201 .label_len = 0,
202 },
203};
204
205int
206tls12_exporter(SSL *s, const uint8_t *label, size_t label_len,
207 const uint8_t *context_value, size_t context_value_len, int use_context,
208 uint8_t *out, size_t out_len)
209{
210 uint8_t *data = NULL;
211 size_t data_len = 0;
212 CBB cbb, context;
213 CBS seed;
214 size_t i;
215 int ret = 0;
216
217 /*
218 * RFC 5705 - Key Material Exporters for TLS.
219 */
220
221 memset(&cbb, 0, sizeof(cbb));
222
223 if (!SSL_is_init_finished(s)) {
224 SSLerror(s, SSL_R_BAD_STATE);
225 goto err;
226 }
227
228 if (s->s3->hs.negotiated_tls_version >= TLS1_3_VERSION)
229 goto err;
230
231 /*
232 * Due to exceptional design choices, we need to build a concatenation
233 * of the label and the seed value, before checking for reserved
234 * labels. This prevents a reserved label from being split across the
235 * label and the seed (that includes the client random), which are
236 * concatenated by the PRF.
237 */
238 if (!CBB_init(&cbb, 0))
239 goto err;
240 if (!CBB_add_bytes(&cbb, label, label_len))
241 goto err;
242 if (!CBB_add_bytes(&cbb, s->s3->client_random, SSL3_RANDOM_SIZE))
243 goto err;
244 if (!CBB_add_bytes(&cbb, s->s3->server_random, SSL3_RANDOM_SIZE))
245 goto err;
246 if (use_context) {
247 if (!CBB_add_u16_length_prefixed(&cbb, &context))
248 goto err;
249 if (context_value_len > 0) {
250 if (!CBB_add_bytes(&context, context_value,
251 context_value_len))
252 goto err;
253 }
254 }
255 if (!CBB_finish(&cbb, &data, &data_len))
256 goto err;
257
258 /*
259 * Ensure that the block (label + seed) does not start with a reserved
260 * label - in an ideal world we would ensure that the label has an
261 * explicitly permitted prefix instead, but of course this also got
262 * messed up by the standards.
263 */
264 for (i = 0; tls12_reserved_labels[i].label != NULL; i++) {
265 /* XXX - consider adding/using CBS_has_prefix(). */
266 if (tls12_reserved_labels[i].label_len > data_len)
267 goto err;
268 if (memcmp(data, tls12_reserved_labels[i].label,
269 tls12_reserved_labels[i].label_len) == 0) {
270 SSLerror(s, SSL_R_TLS_ILLEGAL_EXPORTER_LABEL);
271 goto err;
272 }
273 }
274
275 CBS_init(&seed, data, data_len);
276 if (!CBS_skip(&seed, label_len))
277 goto err;
278
279 if (!tls1_PRF(s, s->session->master_key, s->session->master_key_length,
280 label, label_len, CBS_data(&seed), CBS_len(&seed), NULL, 0, NULL, 0,
281 NULL, 0, out, out_len))
282 goto err;
283
284 ret = 1;
285
286 err:
287 freezero(data, data_len);
288 CBB_cleanup(&cbb);
289
290 return ret;
291}
diff --git a/src/lib/libssl/tls12_lib.c b/src/lib/libssl/tls12_lib.c
deleted file mode 100644
index 96b3abcd2a..0000000000
--- a/src/lib/libssl/tls12_lib.c
+++ /dev/null
@@ -1,118 +0,0 @@
1/* $OpenBSD: tls12_lib.c,v 1.6 2022/11/26 16:08:56 tb Exp $ */
2/*
3 * Copyright (c) 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "ssl_local.h"
19
20static int
21tls12_finished_verify_data(SSL *s, const char *finished_label,
22 size_t finished_label_len, uint8_t *verify_data, size_t verify_data_len,
23 size_t *out_len)
24{
25 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
26 size_t transcript_hash_len;
27
28 *out_len = 0;
29
30 if (s->session->master_key_length == 0)
31 return 0;
32
33 if (verify_data_len < TLS1_FINISH_MAC_LENGTH)
34 return 0;
35
36 if (!tls1_transcript_hash_value(s, transcript_hash,
37 sizeof(transcript_hash), &transcript_hash_len))
38 return 0;
39
40 if (!tls1_PRF(s, s->session->master_key, s->session->master_key_length,
41 finished_label, finished_label_len, transcript_hash,
42 transcript_hash_len, NULL, 0, NULL, 0, NULL, 0, verify_data,
43 TLS1_FINISH_MAC_LENGTH))
44 return 0;
45
46 *out_len = TLS1_FINISH_MAC_LENGTH;
47
48 return 1;
49}
50
51static int
52tls12_client_finished_verify_data(SSL *s, uint8_t *verify_data,
53 size_t verify_data_len, size_t *out_len)
54{
55 return tls12_finished_verify_data(s, TLS_MD_CLIENT_FINISH_CONST,
56 TLS_MD_CLIENT_FINISH_CONST_SIZE, verify_data, verify_data_len,
57 out_len);
58}
59
60static int
61tls12_server_finished_verify_data(SSL *s, uint8_t *verify_data,
62 size_t verify_data_len, size_t *out_len)
63{
64 return tls12_finished_verify_data(s, TLS_MD_SERVER_FINISH_CONST,
65 TLS_MD_SERVER_FINISH_CONST_SIZE, verify_data, verify_data_len,
66 out_len);
67}
68
69int
70tls12_derive_finished(SSL *s)
71{
72 if (!s->server) {
73 return tls12_client_finished_verify_data(s,
74 s->s3->hs.finished, sizeof(s->s3->hs.finished),
75 &s->s3->hs.finished_len);
76 } else {
77 return tls12_server_finished_verify_data(s,
78 s->s3->hs.finished, sizeof(s->s3->hs.finished),
79 &s->s3->hs.finished_len);
80 }
81}
82
83int
84tls12_derive_peer_finished(SSL *s)
85{
86 if (s->server) {
87 return tls12_client_finished_verify_data(s,
88 s->s3->hs.peer_finished, sizeof(s->s3->hs.peer_finished),
89 &s->s3->hs.peer_finished_len);
90 } else {
91 return tls12_server_finished_verify_data(s,
92 s->s3->hs.peer_finished, sizeof(s->s3->hs.peer_finished),
93 &s->s3->hs.peer_finished_len);
94 }
95}
96
97int
98tls12_derive_master_secret(SSL *s, uint8_t *premaster_secret,
99 size_t premaster_secret_len)
100{
101 s->session->master_key_length = 0;
102
103 if (premaster_secret_len == 0)
104 return 0;
105
106 CTASSERT(sizeof(s->session->master_key) == SSL_MAX_MASTER_KEY_LENGTH);
107
108 if (!tls1_PRF(s, premaster_secret, premaster_secret_len,
109 TLS_MD_MASTER_SECRET_CONST, TLS_MD_MASTER_SECRET_CONST_SIZE,
110 s->s3->client_random, SSL3_RANDOM_SIZE, NULL, 0,
111 s->s3->server_random, SSL3_RANDOM_SIZE, NULL, 0,
112 s->session->master_key, sizeof(s->session->master_key)))
113 return 0;
114
115 s->session->master_key_length = SSL_MAX_MASTER_KEY_LENGTH;
116
117 return 1;
118}
diff --git a/src/lib/libssl/tls12_record_layer.c b/src/lib/libssl/tls12_record_layer.c
deleted file mode 100644
index 9786d7d0bd..0000000000
--- a/src/lib/libssl/tls12_record_layer.c
+++ /dev/null
@@ -1,1309 +0,0 @@
1/* $OpenBSD: tls12_record_layer.c,v 1.42 2024/02/03 15:58:34 beck Exp $ */
2/*
3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <limits.h>
19#include <stdlib.h>
20
21#include <openssl/evp.h>
22
23#include "ssl_local.h"
24
25#define TLS12_RECORD_SEQ_NUM_LEN 8
26#define TLS12_AEAD_FIXED_NONCE_MAX_LEN 12
27
28struct tls12_record_protection {
29 uint16_t epoch;
30 uint8_t seq_num[TLS12_RECORD_SEQ_NUM_LEN];
31
32 EVP_AEAD_CTX *aead_ctx;
33
34 uint8_t *aead_nonce;
35 size_t aead_nonce_len;
36
37 uint8_t *aead_fixed_nonce;
38 size_t aead_fixed_nonce_len;
39
40 size_t aead_variable_nonce_len;
41 size_t aead_tag_len;
42
43 int aead_xor_nonces;
44 int aead_variable_nonce_in_record;
45
46 EVP_CIPHER_CTX *cipher_ctx;
47 EVP_MD_CTX *hash_ctx;
48
49 int stream_mac;
50
51 uint8_t *mac_key;
52 size_t mac_key_len;
53};
54
55static struct tls12_record_protection *
56tls12_record_protection_new(void)
57{
58 return calloc(1, sizeof(struct tls12_record_protection));
59}
60
61static void
62tls12_record_protection_clear(struct tls12_record_protection *rp)
63{
64 EVP_AEAD_CTX_free(rp->aead_ctx);
65
66 freezero(rp->aead_nonce, rp->aead_nonce_len);
67 freezero(rp->aead_fixed_nonce, rp->aead_fixed_nonce_len);
68
69 EVP_CIPHER_CTX_free(rp->cipher_ctx);
70 EVP_MD_CTX_free(rp->hash_ctx);
71
72 freezero(rp->mac_key, rp->mac_key_len);
73
74 memset(rp, 0, sizeof(*rp));
75}
76
77static void
78tls12_record_protection_free(struct tls12_record_protection *rp)
79{
80 if (rp == NULL)
81 return;
82
83 tls12_record_protection_clear(rp);
84
85 freezero(rp, sizeof(struct tls12_record_protection));
86}
87
88static int
89tls12_record_protection_engaged(struct tls12_record_protection *rp)
90{
91 return rp->aead_ctx != NULL || rp->cipher_ctx != NULL;
92}
93
94static int
95tls12_record_protection_unused(struct tls12_record_protection *rp)
96{
97 return rp->aead_ctx == NULL && rp->cipher_ctx == NULL &&
98 rp->hash_ctx == NULL && rp->mac_key == NULL;
99}
100
101static int
102tls12_record_protection_eiv_len(struct tls12_record_protection *rp,
103 size_t *out_eiv_len)
104{
105 int eiv_len;
106
107 *out_eiv_len = 0;
108
109 if (rp->cipher_ctx == NULL)
110 return 0;
111
112 eiv_len = 0;
113 if (EVP_CIPHER_CTX_mode(rp->cipher_ctx) == EVP_CIPH_CBC_MODE)
114 eiv_len = EVP_CIPHER_CTX_iv_length(rp->cipher_ctx);
115 if (eiv_len < 0 || eiv_len > EVP_MAX_IV_LENGTH)
116 return 0;
117
118 *out_eiv_len = eiv_len;
119
120 return 1;
121}
122
123static int
124tls12_record_protection_block_size(struct tls12_record_protection *rp,
125 size_t *out_block_size)
126{
127 int block_size;
128
129 *out_block_size = 0;
130
131 if (rp->cipher_ctx == NULL)
132 return 0;
133
134 block_size = EVP_CIPHER_CTX_block_size(rp->cipher_ctx);
135 if (block_size < 0 || block_size > EVP_MAX_BLOCK_LENGTH)
136 return 0;
137
138 *out_block_size = block_size;
139
140 return 1;
141}
142
143static int
144tls12_record_protection_mac_len(struct tls12_record_protection *rp,
145 size_t *out_mac_len)
146{
147 int mac_len;
148
149 *out_mac_len = 0;
150
151 if (rp->hash_ctx == NULL)
152 return 0;
153
154 mac_len = EVP_MD_CTX_size(rp->hash_ctx);
155 if (mac_len <= 0 || mac_len > EVP_MAX_MD_SIZE)
156 return 0;
157
158 *out_mac_len = mac_len;
159
160 return 1;
161}
162
163struct tls12_record_layer {
164 uint16_t version;
165 uint16_t initial_epoch;
166 int dtls;
167
168 uint8_t alert_desc;
169
170 const EVP_AEAD *aead;
171 const EVP_CIPHER *cipher;
172 const EVP_MD *handshake_hash;
173 const EVP_MD *mac_hash;
174
175 /* Pointers to active record protection (memory is not owned). */
176 struct tls12_record_protection *read;
177 struct tls12_record_protection *write;
178
179 struct tls12_record_protection *read_current;
180 struct tls12_record_protection *write_current;
181 struct tls12_record_protection *write_previous;
182};
183
184struct tls12_record_layer *
185tls12_record_layer_new(void)
186{
187 struct tls12_record_layer *rl;
188
189 if ((rl = calloc(1, sizeof(struct tls12_record_layer))) == NULL)
190 goto err;
191 if ((rl->read_current = tls12_record_protection_new()) == NULL)
192 goto err;
193 if ((rl->write_current = tls12_record_protection_new()) == NULL)
194 goto err;
195
196 rl->read = rl->read_current;
197 rl->write = rl->write_current;
198
199 return rl;
200
201 err:
202 tls12_record_layer_free(rl);
203
204 return NULL;
205}
206
207void
208tls12_record_layer_free(struct tls12_record_layer *rl)
209{
210 if (rl == NULL)
211 return;
212
213 tls12_record_protection_free(rl->read_current);
214 tls12_record_protection_free(rl->write_current);
215 tls12_record_protection_free(rl->write_previous);
216
217 freezero(rl, sizeof(struct tls12_record_layer));
218}
219
220void
221tls12_record_layer_alert(struct tls12_record_layer *rl, uint8_t *alert_desc)
222{
223 *alert_desc = rl->alert_desc;
224}
225
226int
227tls12_record_layer_write_overhead(struct tls12_record_layer *rl,
228 size_t *overhead)
229{
230 size_t block_size, eiv_len, mac_len;
231
232 *overhead = 0;
233
234 if (rl->write->aead_ctx != NULL) {
235 *overhead = rl->write->aead_tag_len;
236 } else if (rl->write->cipher_ctx != NULL) {
237 eiv_len = 0;
238 if (rl->version != TLS1_VERSION) {
239 if (!tls12_record_protection_eiv_len(rl->write, &eiv_len))
240 return 0;
241 }
242 if (!tls12_record_protection_block_size(rl->write, &block_size))
243 return 0;
244 if (!tls12_record_protection_mac_len(rl->write, &mac_len))
245 return 0;
246
247 *overhead = eiv_len + block_size + mac_len;
248 }
249
250 return 1;
251}
252
253int
254tls12_record_layer_read_protected(struct tls12_record_layer *rl)
255{
256 return tls12_record_protection_engaged(rl->read);
257}
258
259int
260tls12_record_layer_write_protected(struct tls12_record_layer *rl)
261{
262 return tls12_record_protection_engaged(rl->write);
263}
264
265void
266tls12_record_layer_set_aead(struct tls12_record_layer *rl, const EVP_AEAD *aead)
267{
268 rl->aead = aead;
269}
270
271void
272tls12_record_layer_set_cipher_hash(struct tls12_record_layer *rl,
273 const EVP_CIPHER *cipher, const EVP_MD *handshake_hash,
274 const EVP_MD *mac_hash)
275{
276 rl->cipher = cipher;
277 rl->handshake_hash = handshake_hash;
278 rl->mac_hash = mac_hash;
279}
280
281void
282tls12_record_layer_set_version(struct tls12_record_layer *rl, uint16_t version)
283{
284 rl->version = version;
285 rl->dtls = ((version >> 8) == DTLS1_VERSION_MAJOR);
286}
287
288void
289tls12_record_layer_set_initial_epoch(struct tls12_record_layer *rl,
290 uint16_t epoch)
291{
292 rl->initial_epoch = epoch;
293}
294
295uint16_t
296tls12_record_layer_read_epoch(struct tls12_record_layer *rl)
297{
298 return rl->read->epoch;
299}
300
301uint16_t
302tls12_record_layer_write_epoch(struct tls12_record_layer *rl)
303{
304 return rl->write->epoch;
305}
306
307int
308tls12_record_layer_use_write_epoch(struct tls12_record_layer *rl, uint16_t epoch)
309{
310 if (rl->write->epoch == epoch)
311 return 1;
312
313 if (rl->write_current->epoch == epoch) {
314 rl->write = rl->write_current;
315 return 1;
316 }
317
318 if (rl->write_previous != NULL && rl->write_previous->epoch == epoch) {
319 rl->write = rl->write_previous;
320 return 1;
321 }
322
323 return 0;
324}
325
326void
327tls12_record_layer_write_epoch_done(struct tls12_record_layer *rl, uint16_t epoch)
328{
329 if (rl->write_previous == NULL || rl->write_previous->epoch != epoch)
330 return;
331
332 rl->write = rl->write_current;
333
334 tls12_record_protection_free(rl->write_previous);
335 rl->write_previous = NULL;
336}
337
338void
339tls12_record_layer_clear_read_state(struct tls12_record_layer *rl)
340{
341 tls12_record_protection_clear(rl->read);
342 rl->read->epoch = rl->initial_epoch;
343}
344
345void
346tls12_record_layer_clear_write_state(struct tls12_record_layer *rl)
347{
348 tls12_record_protection_clear(rl->write);
349 rl->write->epoch = rl->initial_epoch;
350
351 tls12_record_protection_free(rl->write_previous);
352 rl->write_previous = NULL;
353}
354
355void
356tls12_record_layer_reflect_seq_num(struct tls12_record_layer *rl)
357{
358 memcpy(rl->write->seq_num, rl->read->seq_num,
359 sizeof(rl->write->seq_num));
360}
361
362static const uint8_t tls12_max_seq_num[TLS12_RECORD_SEQ_NUM_LEN] = {
363 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
364};
365
366int
367tls12_record_layer_inc_seq_num(struct tls12_record_layer *rl, uint8_t *seq_num)
368{
369 CBS max_seq_num;
370 int i;
371
372 /*
373 * RFC 5246 section 6.1 and RFC 6347 section 4.1 - both TLS and DTLS
374 * sequence numbers must not wrap. Note that for DTLS the first two
375 * bytes are used as an "epoch" and not part of the sequence number.
376 */
377 CBS_init(&max_seq_num, seq_num, TLS12_RECORD_SEQ_NUM_LEN);
378 if (rl->dtls) {
379 if (!CBS_skip(&max_seq_num, 2))
380 return 0;
381 }
382 if (CBS_mem_equal(&max_seq_num, tls12_max_seq_num,
383 CBS_len(&max_seq_num)))
384 return 0;
385
386 for (i = TLS12_RECORD_SEQ_NUM_LEN - 1; i >= 0; i--) {
387 if (++seq_num[i] != 0)
388 break;
389 }
390
391 return 1;
392}
393
394static int
395tls12_record_layer_set_mac_key(struct tls12_record_protection *rp,
396 const uint8_t *mac_key, size_t mac_key_len)
397{
398 freezero(rp->mac_key, rp->mac_key_len);
399 rp->mac_key = NULL;
400 rp->mac_key_len = 0;
401
402 if (mac_key == NULL || mac_key_len == 0)
403 return 1;
404
405 if ((rp->mac_key = calloc(1, mac_key_len)) == NULL)
406 return 0;
407
408 memcpy(rp->mac_key, mac_key, mac_key_len);
409 rp->mac_key_len = mac_key_len;
410
411 return 1;
412}
413
414static int
415tls12_record_layer_ccs_aead(struct tls12_record_layer *rl,
416 struct tls12_record_protection *rp, int is_write, CBS *mac_key, CBS *key,
417 CBS *iv)
418{
419 if (!tls12_record_protection_unused(rp))
420 return 0;
421
422 if ((rp->aead_ctx = EVP_AEAD_CTX_new()) == NULL)
423 return 0;
424
425 /* AES GCM cipher suites use variable nonce in record. */
426 if (rl->aead == EVP_aead_aes_128_gcm() ||
427 rl->aead == EVP_aead_aes_256_gcm())
428 rp->aead_variable_nonce_in_record = 1;
429
430 /* ChaCha20 Poly1305 XORs the fixed and variable nonces. */
431 if (rl->aead == EVP_aead_chacha20_poly1305())
432 rp->aead_xor_nonces = 1;
433
434 if (!CBS_stow(iv, &rp->aead_fixed_nonce, &rp->aead_fixed_nonce_len))
435 return 0;
436
437 rp->aead_nonce = calloc(1, EVP_AEAD_nonce_length(rl->aead));
438 if (rp->aead_nonce == NULL)
439 return 0;
440
441 rp->aead_nonce_len = EVP_AEAD_nonce_length(rl->aead);
442 rp->aead_tag_len = EVP_AEAD_max_overhead(rl->aead);
443 rp->aead_variable_nonce_len = TLS12_RECORD_SEQ_NUM_LEN;
444
445 if (rp->aead_xor_nonces) {
446 /* Fixed nonce length must match, variable must not exceed. */
447 if (rp->aead_fixed_nonce_len != rp->aead_nonce_len)
448 return 0;
449 if (rp->aead_variable_nonce_len > rp->aead_nonce_len)
450 return 0;
451 } else {
452 /* Concatenated nonce length must equal AEAD nonce length. */
453 if (rp->aead_fixed_nonce_len +
454 rp->aead_variable_nonce_len != rp->aead_nonce_len)
455 return 0;
456 }
457
458 if (!EVP_AEAD_CTX_init(rp->aead_ctx, rl->aead, CBS_data(key),
459 CBS_len(key), EVP_AEAD_DEFAULT_TAG_LENGTH, NULL))
460 return 0;
461
462 return 1;
463}
464
465static int
466tls12_record_layer_ccs_cipher(struct tls12_record_layer *rl,
467 struct tls12_record_protection *rp, int is_write, CBS *mac_key, CBS *key,
468 CBS *iv)
469{
470 EVP_PKEY *mac_pkey = NULL;
471 int mac_type;
472 int ret = 0;
473
474 if (!tls12_record_protection_unused(rp))
475 goto err;
476
477 mac_type = EVP_PKEY_HMAC;
478 rp->stream_mac = 0;
479
480 if (CBS_len(iv) > INT_MAX || CBS_len(key) > INT_MAX)
481 goto err;
482 if (EVP_CIPHER_iv_length(rl->cipher) != CBS_len(iv))
483 goto err;
484 if (EVP_CIPHER_key_length(rl->cipher) != CBS_len(key))
485 goto err;
486 if (CBS_len(mac_key) > INT_MAX)
487 goto err;
488 if (EVP_MD_size(rl->mac_hash) != CBS_len(mac_key))
489 goto err;
490 if ((rp->cipher_ctx = EVP_CIPHER_CTX_new()) == NULL)
491 goto err;
492 if ((rp->hash_ctx = EVP_MD_CTX_new()) == NULL)
493 goto err;
494
495 if (!tls12_record_layer_set_mac_key(rp, CBS_data(mac_key),
496 CBS_len(mac_key)))
497 goto err;
498
499 if ((mac_pkey = EVP_PKEY_new_mac_key(mac_type, NULL, CBS_data(mac_key),
500 CBS_len(mac_key))) == NULL)
501 goto err;
502
503 if (!EVP_CipherInit_ex(rp->cipher_ctx, rl->cipher, NULL, CBS_data(key),
504 CBS_data(iv), is_write))
505 goto err;
506
507 if (EVP_DigestSignInit(rp->hash_ctx, NULL, rl->mac_hash, NULL,
508 mac_pkey) <= 0)
509 goto err;
510
511 ret = 1;
512
513 err:
514 EVP_PKEY_free(mac_pkey);
515
516 return ret;
517}
518
519static int
520tls12_record_layer_change_cipher_state(struct tls12_record_layer *rl,
521 struct tls12_record_protection *rp, int is_write, CBS *mac_key, CBS *key,
522 CBS *iv)
523{
524 if (rl->aead != NULL)
525 return tls12_record_layer_ccs_aead(rl, rp, is_write, mac_key,
526 key, iv);
527
528 return tls12_record_layer_ccs_cipher(rl, rp, is_write, mac_key,
529 key, iv);
530}
531
532int
533tls12_record_layer_change_read_cipher_state(struct tls12_record_layer *rl,
534 CBS *mac_key, CBS *key, CBS *iv)
535{
536 struct tls12_record_protection *read_new = NULL;
537 int ret = 0;
538
539 if ((read_new = tls12_record_protection_new()) == NULL)
540 goto err;
541
542 /* Read sequence number gets reset to zero. */
543
544 /* DTLS epoch is incremented and is permitted to wrap. */
545 if (rl->dtls)
546 read_new->epoch = rl->read_current->epoch + 1;
547
548 if (!tls12_record_layer_change_cipher_state(rl, read_new, 0,
549 mac_key, key, iv))
550 goto err;
551
552 tls12_record_protection_free(rl->read_current);
553 rl->read = rl->read_current = read_new;
554 read_new = NULL;
555
556 ret = 1;
557
558 err:
559 tls12_record_protection_free(read_new);
560
561 return ret;
562}
563
564int
565tls12_record_layer_change_write_cipher_state(struct tls12_record_layer *rl,
566 CBS *mac_key, CBS *key, CBS *iv)
567{
568 struct tls12_record_protection *write_new;
569 int ret = 0;
570
571 if ((write_new = tls12_record_protection_new()) == NULL)
572 goto err;
573
574 /* Write sequence number gets reset to zero. */
575
576 /* DTLS epoch is incremented and is permitted to wrap. */
577 if (rl->dtls)
578 write_new->epoch = rl->write_current->epoch + 1;
579
580 if (!tls12_record_layer_change_cipher_state(rl, write_new, 1,
581 mac_key, key, iv))
582 goto err;
583
584 if (rl->dtls) {
585 tls12_record_protection_free(rl->write_previous);
586 rl->write_previous = rl->write_current;
587 rl->write_current = NULL;
588 }
589 tls12_record_protection_free(rl->write_current);
590 rl->write = rl->write_current = write_new;
591 write_new = NULL;
592
593 ret = 1;
594
595 err:
596 tls12_record_protection_free(write_new);
597
598 return ret;
599}
600
601static int
602tls12_record_layer_build_seq_num(struct tls12_record_layer *rl, CBB *cbb,
603 uint16_t epoch, uint8_t *seq_num, size_t seq_num_len)
604{
605 CBS seq;
606
607 CBS_init(&seq, seq_num, seq_num_len);
608
609 if (rl->dtls) {
610 if (!CBB_add_u16(cbb, epoch))
611 return 0;
612 if (!CBS_skip(&seq, 2))
613 return 0;
614 }
615
616 return CBB_add_bytes(cbb, CBS_data(&seq), CBS_len(&seq));
617}
618
619static int
620tls12_record_layer_pseudo_header(struct tls12_record_layer *rl,
621 uint8_t content_type, uint16_t record_len, CBS *seq_num, uint8_t **out,
622 size_t *out_len)
623{
624 CBB cbb;
625
626 *out = NULL;
627 *out_len = 0;
628
629 /* Build the pseudo-header used for MAC/AEAD. */
630 if (!CBB_init(&cbb, 13))
631 goto err;
632
633 if (!CBB_add_bytes(&cbb, CBS_data(seq_num), CBS_len(seq_num)))
634 goto err;
635 if (!CBB_add_u8(&cbb, content_type))
636 goto err;
637 if (!CBB_add_u16(&cbb, rl->version))
638 goto err;
639 if (!CBB_add_u16(&cbb, record_len))
640 goto err;
641
642 if (!CBB_finish(&cbb, out, out_len))
643 goto err;
644
645 return 1;
646
647 err:
648 CBB_cleanup(&cbb);
649
650 return 0;
651}
652
653static int
654tls12_record_layer_mac(struct tls12_record_layer *rl, CBB *cbb,
655 EVP_MD_CTX *hash_ctx, int stream_mac, CBS *seq_num, uint8_t content_type,
656 const uint8_t *content, size_t content_len, size_t *out_len)
657{
658 EVP_MD_CTX *mac_ctx = NULL;
659 uint8_t *header = NULL;
660 size_t header_len = 0;
661 size_t mac_len;
662 uint8_t *mac;
663 int ret = 0;
664
665 if ((mac_ctx = EVP_MD_CTX_new()) == NULL)
666 goto err;
667 if (!EVP_MD_CTX_copy(mac_ctx, hash_ctx))
668 goto err;
669
670 if (!tls12_record_layer_pseudo_header(rl, content_type, content_len,
671 seq_num, &header, &header_len))
672 goto err;
673
674 if (EVP_DigestSignUpdate(mac_ctx, header, header_len) <= 0)
675 goto err;
676 if (EVP_DigestSignUpdate(mac_ctx, content, content_len) <= 0)
677 goto err;
678 if (EVP_DigestSignFinal(mac_ctx, NULL, &mac_len) <= 0)
679 goto err;
680 if (!CBB_add_space(cbb, &mac, mac_len))
681 goto err;
682 if (EVP_DigestSignFinal(mac_ctx, mac, &mac_len) <= 0)
683 goto err;
684 if (mac_len == 0)
685 goto err;
686
687 if (stream_mac) {
688 if (!EVP_MD_CTX_copy(hash_ctx, mac_ctx))
689 goto err;
690 }
691
692 *out_len = mac_len;
693 ret = 1;
694
695 err:
696 EVP_MD_CTX_free(mac_ctx);
697 freezero(header, header_len);
698
699 return ret;
700}
701
702static int
703tls12_record_layer_read_mac_cbc(struct tls12_record_layer *rl, CBB *cbb,
704 uint8_t content_type, CBS *seq_num, const uint8_t *content,
705 size_t content_len, size_t mac_len, size_t padding_len)
706{
707 uint8_t *header = NULL;
708 size_t header_len = 0;
709 uint8_t *mac = NULL;
710 size_t out_mac_len = 0;
711 int ret = 0;
712
713 /*
714 * Must be constant time to avoid leaking details about CBC padding.
715 */
716
717 if (!ssl3_cbc_record_digest_supported(rl->read->hash_ctx))
718 goto err;
719
720 if (!tls12_record_layer_pseudo_header(rl, content_type, content_len,
721 seq_num, &header, &header_len))
722 goto err;
723
724 if (!CBB_add_space(cbb, &mac, mac_len))
725 goto err;
726 if (!ssl3_cbc_digest_record(rl->read->hash_ctx, mac, &out_mac_len, header,
727 content, content_len + mac_len, content_len + mac_len + padding_len,
728 rl->read->mac_key, rl->read->mac_key_len))
729 goto err;
730 if (mac_len != out_mac_len)
731 goto err;
732
733 ret = 1;
734
735 err:
736 freezero(header, header_len);
737
738 return ret;
739}
740
741static int
742tls12_record_layer_read_mac(struct tls12_record_layer *rl, CBB *cbb,
743 uint8_t content_type, CBS *seq_num, const uint8_t *content,
744 size_t content_len)
745{
746 EVP_CIPHER_CTX *enc = rl->read->cipher_ctx;
747 size_t out_len;
748
749 if (EVP_CIPHER_CTX_mode(enc) == EVP_CIPH_CBC_MODE)
750 return 0;
751
752 return tls12_record_layer_mac(rl, cbb, rl->read->hash_ctx,
753 rl->read->stream_mac, seq_num, content_type, content, content_len,
754 &out_len);
755}
756
757static int
758tls12_record_layer_write_mac(struct tls12_record_layer *rl, CBB *cbb,
759 uint8_t content_type, CBS *seq_num, const uint8_t *content,
760 size_t content_len, size_t *out_len)
761{
762 return tls12_record_layer_mac(rl, cbb, rl->write->hash_ctx,
763 rl->write->stream_mac, seq_num, content_type, content, content_len,
764 out_len);
765}
766
767static int
768tls12_record_layer_aead_concat_nonce(struct tls12_record_layer *rl,
769 struct tls12_record_protection *rp, CBS *seq_num)
770{
771 CBB cbb;
772
773 if (rp->aead_variable_nonce_len > CBS_len(seq_num))
774 return 0;
775
776 /* Fixed nonce and variable nonce (sequence number) are concatenated. */
777 if (!CBB_init_fixed(&cbb, rp->aead_nonce, rp->aead_nonce_len))
778 goto err;
779 if (!CBB_add_bytes(&cbb, rp->aead_fixed_nonce,
780 rp->aead_fixed_nonce_len))
781 goto err;
782 if (!CBB_add_bytes(&cbb, CBS_data(seq_num),
783 rp->aead_variable_nonce_len))
784 goto err;
785 if (!CBB_finish(&cbb, NULL, NULL))
786 goto err;
787
788 return 1;
789
790 err:
791 CBB_cleanup(&cbb);
792
793 return 0;
794}
795
796static int
797tls12_record_layer_aead_xored_nonce(struct tls12_record_layer *rl,
798 struct tls12_record_protection *rp, CBS *seq_num)
799{
800 uint8_t *pad;
801 CBB cbb;
802 int i;
803
804 if (rp->aead_variable_nonce_len > CBS_len(seq_num))
805 return 0;
806 if (rp->aead_fixed_nonce_len < rp->aead_variable_nonce_len)
807 return 0;
808 if (rp->aead_fixed_nonce_len != rp->aead_nonce_len)
809 return 0;
810
811 /*
812 * Variable nonce (sequence number) is right padded, before the fixed
813 * nonce is XOR'd in.
814 */
815 if (!CBB_init_fixed(&cbb, rp->aead_nonce, rp->aead_nonce_len))
816 goto err;
817 if (!CBB_add_space(&cbb, &pad,
818 rp->aead_fixed_nonce_len - rp->aead_variable_nonce_len))
819 goto err;
820 if (!CBB_add_bytes(&cbb, CBS_data(seq_num),
821 rp->aead_variable_nonce_len))
822 goto err;
823 if (!CBB_finish(&cbb, NULL, NULL))
824 goto err;
825
826 for (i = 0; i < rp->aead_fixed_nonce_len; i++)
827 rp->aead_nonce[i] ^= rp->aead_fixed_nonce[i];
828
829 return 1;
830
831 err:
832 CBB_cleanup(&cbb);
833
834 return 0;
835}
836
837static int
838tls12_record_layer_open_record_plaintext(struct tls12_record_layer *rl,
839 uint8_t content_type, CBS *fragment, struct tls_content *out)
840{
841 if (tls12_record_protection_engaged(rl->read))
842 return 0;
843
844 return tls_content_dup_data(out, content_type, CBS_data(fragment),
845 CBS_len(fragment));
846}
847
848static int
849tls12_record_layer_open_record_protected_aead(struct tls12_record_layer *rl,
850 uint8_t content_type, CBS *seq_num, CBS *fragment, struct tls_content *out)
851{
852 struct tls12_record_protection *rp = rl->read;
853 uint8_t *header = NULL;
854 size_t header_len = 0;
855 uint8_t *content = NULL;
856 size_t content_len = 0;
857 size_t out_len = 0;
858 CBS var_nonce;
859 int ret = 0;
860
861 if (rp->aead_xor_nonces) {
862 if (!tls12_record_layer_aead_xored_nonce(rl, rp, seq_num))
863 goto err;
864 } else if (rp->aead_variable_nonce_in_record) {
865 if (!CBS_get_bytes(fragment, &var_nonce,
866 rp->aead_variable_nonce_len))
867 goto err;
868 if (!tls12_record_layer_aead_concat_nonce(rl, rp, &var_nonce))
869 goto err;
870 } else {
871 if (!tls12_record_layer_aead_concat_nonce(rl, rp, seq_num))
872 goto err;
873 }
874
875 /* XXX EVP_AEAD_max_tag_len vs EVP_AEAD_CTX_tag_len. */
876 if (CBS_len(fragment) < rp->aead_tag_len) {
877 rl->alert_desc = SSL_AD_BAD_RECORD_MAC;
878 goto err;
879 }
880 if (CBS_len(fragment) > SSL3_RT_MAX_ENCRYPTED_LENGTH) {
881 rl->alert_desc = SSL_AD_RECORD_OVERFLOW;
882 goto err;
883 }
884
885 content_len = CBS_len(fragment) - rp->aead_tag_len;
886 if ((content = calloc(1, CBS_len(fragment))) == NULL) {
887 content_len = 0;
888 goto err;
889 }
890
891 if (!tls12_record_layer_pseudo_header(rl, content_type, content_len,
892 seq_num, &header, &header_len))
893 goto err;
894
895 if (!EVP_AEAD_CTX_open(rp->aead_ctx, content, &out_len, content_len,
896 rp->aead_nonce, rp->aead_nonce_len, CBS_data(fragment),
897 CBS_len(fragment), header, header_len)) {
898 rl->alert_desc = SSL_AD_BAD_RECORD_MAC;
899 goto err;
900 }
901
902 if (out_len > SSL3_RT_MAX_PLAIN_LENGTH) {
903 rl->alert_desc = SSL_AD_RECORD_OVERFLOW;
904 goto err;
905 }
906
907 if (out_len != content_len)
908 goto err;
909
910 tls_content_set_data(out, content_type, content, content_len);
911 content = NULL;
912 content_len = 0;
913
914 ret = 1;
915
916 err:
917 freezero(header, header_len);
918 freezero(content, content_len);
919
920 return ret;
921}
922
923static int
924tls12_record_layer_open_record_protected_cipher(struct tls12_record_layer *rl,
925 uint8_t content_type, CBS *seq_num, CBS *fragment, struct tls_content *out)
926{
927 EVP_CIPHER_CTX *enc = rl->read->cipher_ctx;
928 SSL3_RECORD_INTERNAL rrec;
929 size_t block_size, eiv_len;
930 uint8_t *mac = NULL;
931 size_t mac_len = 0;
932 uint8_t *out_mac = NULL;
933 size_t out_mac_len = 0;
934 uint8_t *content = NULL;
935 size_t content_len = 0;
936 size_t min_len;
937 CBB cbb_mac;
938 int ret = 0;
939
940 memset(&cbb_mac, 0, sizeof(cbb_mac));
941 memset(&rrec, 0, sizeof(rrec));
942
943 if (!tls12_record_protection_block_size(rl->read, &block_size))
944 goto err;
945
946 /* Determine explicit IV length. */
947 eiv_len = 0;
948 if (rl->version != TLS1_VERSION) {
949 if (!tls12_record_protection_eiv_len(rl->read, &eiv_len))
950 goto err;
951 }
952
953 mac_len = 0;
954 if (rl->read->hash_ctx != NULL) {
955 if (!tls12_record_protection_mac_len(rl->read, &mac_len))
956 goto err;
957 }
958
959 /* CBC has at least one padding byte. */
960 min_len = eiv_len + mac_len;
961 if (EVP_CIPHER_CTX_mode(enc) == EVP_CIPH_CBC_MODE)
962 min_len += 1;
963
964 if (CBS_len(fragment) < min_len) {
965 rl->alert_desc = SSL_AD_BAD_RECORD_MAC;
966 goto err;
967 }
968 if (CBS_len(fragment) > SSL3_RT_MAX_ENCRYPTED_LENGTH) {
969 rl->alert_desc = SSL_AD_RECORD_OVERFLOW;
970 goto err;
971 }
972 if (CBS_len(fragment) % block_size != 0) {
973 rl->alert_desc = SSL_AD_BAD_RECORD_MAC;
974 goto err;
975 }
976
977 if ((content = calloc(1, CBS_len(fragment))) == NULL)
978 goto err;
979 content_len = CBS_len(fragment);
980
981 if (!EVP_Cipher(enc, content, CBS_data(fragment), CBS_len(fragment)))
982 goto err;
983
984 rrec.data = content;
985 rrec.input = content;
986 rrec.length = content_len;
987
988 /*
989 * We now have to remove padding, extract MAC, calculate MAC
990 * and compare MAC in constant time.
991 */
992 if (block_size > 1)
993 ssl3_cbc_remove_padding(&rrec, eiv_len, mac_len);
994
995 if ((mac = calloc(1, mac_len)) == NULL)
996 goto err;
997
998 if (!CBB_init(&cbb_mac, EVP_MAX_MD_SIZE))
999 goto err;
1000 if (EVP_CIPHER_CTX_mode(enc) == EVP_CIPH_CBC_MODE) {
1001 ssl3_cbc_copy_mac(mac, &rrec, mac_len, rrec.length +
1002 rrec.padding_length);
1003 rrec.length -= mac_len;
1004 if (!tls12_record_layer_read_mac_cbc(rl, &cbb_mac, content_type,
1005 seq_num, rrec.input, rrec.length, mac_len,
1006 rrec.padding_length))
1007 goto err;
1008 } else {
1009 rrec.length -= mac_len;
1010 memcpy(mac, rrec.data + rrec.length, mac_len);
1011 if (!tls12_record_layer_read_mac(rl, &cbb_mac, content_type,
1012 seq_num, rrec.input, rrec.length))
1013 goto err;
1014 }
1015 if (!CBB_finish(&cbb_mac, &out_mac, &out_mac_len))
1016 goto err;
1017 if (mac_len != out_mac_len)
1018 goto err;
1019
1020 if (timingsafe_memcmp(mac, out_mac, mac_len) != 0) {
1021 rl->alert_desc = SSL_AD_BAD_RECORD_MAC;
1022 goto err;
1023 }
1024
1025 if (rrec.length > SSL3_RT_MAX_COMPRESSED_LENGTH + mac_len) {
1026 rl->alert_desc = SSL_AD_BAD_RECORD_MAC;
1027 goto err;
1028 }
1029 if (rrec.length > SSL3_RT_MAX_PLAIN_LENGTH) {
1030 rl->alert_desc = SSL_AD_RECORD_OVERFLOW;
1031 goto err;
1032 }
1033
1034 tls_content_set_data(out, content_type, content, content_len);
1035 content = NULL;
1036 content_len = 0;
1037
1038 /* Actual content is after EIV, minus padding and MAC. */
1039 if (!tls_content_set_bounds(out, eiv_len, rrec.length))
1040 goto err;
1041
1042 ret = 1;
1043
1044 err:
1045 CBB_cleanup(&cbb_mac);
1046 freezero(mac, mac_len);
1047 freezero(out_mac, out_mac_len);
1048 freezero(content, content_len);
1049
1050 return ret;
1051}
1052
1053int
1054tls12_record_layer_open_record(struct tls12_record_layer *rl, uint8_t *buf,
1055 size_t buf_len, struct tls_content *out)
1056{
1057 CBS cbs, fragment, seq_num;
1058 uint16_t version;
1059 uint8_t content_type;
1060
1061 CBS_init(&cbs, buf, buf_len);
1062 CBS_init(&seq_num, rl->read->seq_num, sizeof(rl->read->seq_num));
1063
1064 if (!CBS_get_u8(&cbs, &content_type))
1065 return 0;
1066 if (!CBS_get_u16(&cbs, &version))
1067 return 0;
1068 if (rl->dtls) {
1069 /*
1070 * The DTLS sequence number is split into a 16 bit epoch and
1071 * 48 bit sequence number, however for the purposes of record
1072 * processing it is treated the same as a TLS 64 bit sequence
1073 * number. DTLS also uses explicit read sequence numbers, which
1074 * we need to extract from the DTLS record header.
1075 */
1076 if (!CBS_get_bytes(&cbs, &seq_num, SSL3_SEQUENCE_SIZE))
1077 return 0;
1078 if (!CBS_write_bytes(&seq_num, rl->read->seq_num,
1079 sizeof(rl->read->seq_num), NULL))
1080 return 0;
1081 }
1082 if (!CBS_get_u16_length_prefixed(&cbs, &fragment))
1083 return 0;
1084
1085 if (rl->read->aead_ctx != NULL) {
1086 if (!tls12_record_layer_open_record_protected_aead(rl,
1087 content_type, &seq_num, &fragment, out))
1088 return 0;
1089 } else if (rl->read->cipher_ctx != NULL) {
1090 if (!tls12_record_layer_open_record_protected_cipher(rl,
1091 content_type, &seq_num, &fragment, out))
1092 return 0;
1093 } else {
1094 if (!tls12_record_layer_open_record_plaintext(rl,
1095 content_type, &fragment, out))
1096 return 0;
1097 }
1098
1099 if (!rl->dtls) {
1100 if (!tls12_record_layer_inc_seq_num(rl, rl->read->seq_num))
1101 return 0;
1102 }
1103
1104 return 1;
1105}
1106
1107static int
1108tls12_record_layer_seal_record_plaintext(struct tls12_record_layer *rl,
1109 uint8_t content_type, const uint8_t *content, size_t content_len, CBB *out)
1110{
1111 if (tls12_record_protection_engaged(rl->write))
1112 return 0;
1113
1114 return CBB_add_bytes(out, content, content_len);
1115}
1116
1117static int
1118tls12_record_layer_seal_record_protected_aead(struct tls12_record_layer *rl,
1119 uint8_t content_type, CBS *seq_num, const uint8_t *content,
1120 size_t content_len, CBB *out)
1121{
1122 struct tls12_record_protection *rp = rl->write;
1123 uint8_t *header = NULL;
1124 size_t header_len = 0;
1125 size_t enc_record_len, out_len;
1126 uint8_t *enc_data;
1127 int ret = 0;
1128
1129 if (rp->aead_xor_nonces) {
1130 if (!tls12_record_layer_aead_xored_nonce(rl, rp, seq_num))
1131 goto err;
1132 } else {
1133 if (!tls12_record_layer_aead_concat_nonce(rl, rp, seq_num))
1134 goto err;
1135 }
1136
1137 if (rp->aead_variable_nonce_in_record) {
1138 if (rp->aead_variable_nonce_len > CBS_len(seq_num))
1139 goto err;
1140 if (!CBB_add_bytes(out, CBS_data(seq_num),
1141 rp->aead_variable_nonce_len))
1142 goto err;
1143 }
1144
1145 if (!tls12_record_layer_pseudo_header(rl, content_type, content_len,
1146 seq_num, &header, &header_len))
1147 goto err;
1148
1149 /* XXX EVP_AEAD_max_tag_len vs EVP_AEAD_CTX_tag_len. */
1150 enc_record_len = content_len + rp->aead_tag_len;
1151 if (enc_record_len > SSL3_RT_MAX_ENCRYPTED_LENGTH)
1152 goto err;
1153 if (!CBB_add_space(out, &enc_data, enc_record_len))
1154 goto err;
1155
1156 if (!EVP_AEAD_CTX_seal(rp->aead_ctx, enc_data, &out_len, enc_record_len,
1157 rp->aead_nonce, rp->aead_nonce_len, content, content_len, header,
1158 header_len))
1159 goto err;
1160
1161 if (out_len != enc_record_len)
1162 goto err;
1163
1164 ret = 1;
1165
1166 err:
1167 freezero(header, header_len);
1168
1169 return ret;
1170}
1171
1172static int
1173tls12_record_layer_seal_record_protected_cipher(struct tls12_record_layer *rl,
1174 uint8_t content_type, CBS *seq_num, const uint8_t *content,
1175 size_t content_len, CBB *out)
1176{
1177 EVP_CIPHER_CTX *enc = rl->write->cipher_ctx;
1178 size_t block_size, eiv_len, mac_len, pad_len;
1179 uint8_t *enc_data, *eiv, *pad, pad_val;
1180 uint8_t *plain = NULL;
1181 size_t plain_len = 0;
1182 int ret = 0;
1183 CBB cbb;
1184
1185 if (!CBB_init(&cbb, SSL3_RT_MAX_PLAIN_LENGTH))
1186 goto err;
1187
1188 /* Add explicit IV if necessary. */
1189 eiv_len = 0;
1190 if (rl->version != TLS1_VERSION) {
1191 if (!tls12_record_protection_eiv_len(rl->write, &eiv_len))
1192 goto err;
1193 }
1194 if (eiv_len > 0) {
1195 if (!CBB_add_space(&cbb, &eiv, eiv_len))
1196 goto err;
1197 arc4random_buf(eiv, eiv_len);
1198 }
1199
1200 if (!CBB_add_bytes(&cbb, content, content_len))
1201 goto err;
1202
1203 mac_len = 0;
1204 if (rl->write->hash_ctx != NULL) {
1205 if (!tls12_record_layer_write_mac(rl, &cbb, content_type,
1206 seq_num, content, content_len, &mac_len))
1207 goto err;
1208 }
1209
1210 plain_len = eiv_len + content_len + mac_len;
1211
1212 /* Add padding to block size, if necessary. */
1213 if (!tls12_record_protection_block_size(rl->write, &block_size))
1214 goto err;
1215 if (block_size > 1) {
1216 pad_len = block_size - (plain_len % block_size);
1217 pad_val = pad_len - 1;
1218
1219 if (pad_len > 255)
1220 goto err;
1221 if (!CBB_add_space(&cbb, &pad, pad_len))
1222 goto err;
1223 memset(pad, pad_val, pad_len);
1224 }
1225
1226 if (!CBB_finish(&cbb, &plain, &plain_len))
1227 goto err;
1228
1229 if (plain_len % block_size != 0)
1230 goto err;
1231 if (plain_len > SSL3_RT_MAX_ENCRYPTED_LENGTH)
1232 goto err;
1233
1234 if (!CBB_add_space(out, &enc_data, plain_len))
1235 goto err;
1236 if (!EVP_Cipher(enc, enc_data, plain, plain_len))
1237 goto err;
1238
1239 ret = 1;
1240
1241 err:
1242 CBB_cleanup(&cbb);
1243 freezero(plain, plain_len);
1244
1245 return ret;
1246}
1247
1248int
1249tls12_record_layer_seal_record(struct tls12_record_layer *rl,
1250 uint8_t content_type, const uint8_t *content, size_t content_len, CBB *cbb)
1251{
1252 uint8_t *seq_num_data = NULL;
1253 size_t seq_num_len = 0;
1254 CBB fragment, seq_num_cbb;
1255 CBS seq_num;
1256 int ret = 0;
1257
1258 /*
1259 * Construct the effective sequence number - this is used in both
1260 * the DTLS header and for MAC calculations.
1261 */
1262 if (!CBB_init(&seq_num_cbb, SSL3_SEQUENCE_SIZE))
1263 goto err;
1264 if (!tls12_record_layer_build_seq_num(rl, &seq_num_cbb, rl->write->epoch,
1265 rl->write->seq_num, sizeof(rl->write->seq_num)))
1266 goto err;
1267 if (!CBB_finish(&seq_num_cbb, &seq_num_data, &seq_num_len))
1268 goto err;
1269 CBS_init(&seq_num, seq_num_data, seq_num_len);
1270
1271 if (!CBB_add_u8(cbb, content_type))
1272 goto err;
1273 if (!CBB_add_u16(cbb, rl->version))
1274 goto err;
1275 if (rl->dtls) {
1276 if (!CBB_add_bytes(cbb, CBS_data(&seq_num), CBS_len(&seq_num)))
1277 goto err;
1278 }
1279 if (!CBB_add_u16_length_prefixed(cbb, &fragment))
1280 goto err;
1281
1282 if (rl->write->aead_ctx != NULL) {
1283 if (!tls12_record_layer_seal_record_protected_aead(rl,
1284 content_type, &seq_num, content, content_len, &fragment))
1285 goto err;
1286 } else if (rl->write->cipher_ctx != NULL) {
1287 if (!tls12_record_layer_seal_record_protected_cipher(rl,
1288 content_type, &seq_num, content, content_len, &fragment))
1289 goto err;
1290 } else {
1291 if (!tls12_record_layer_seal_record_plaintext(rl,
1292 content_type, content, content_len, &fragment))
1293 goto err;
1294 }
1295
1296 if (!CBB_flush(cbb))
1297 goto err;
1298
1299 if (!tls12_record_layer_inc_seq_num(rl, rl->write->seq_num))
1300 goto err;
1301
1302 ret = 1;
1303
1304 err:
1305 CBB_cleanup(&seq_num_cbb);
1306 free(seq_num_data);
1307
1308 return ret;
1309}
diff --git a/src/lib/libssl/tls13_client.c b/src/lib/libssl/tls13_client.c
deleted file mode 100644
index 901b38f860..0000000000
--- a/src/lib/libssl/tls13_client.c
+++ /dev/null
@@ -1,1060 +0,0 @@
1/* $OpenBSD: tls13_client.c,v 1.104 2024/07/22 14:47:15 jsing Exp $ */
2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <openssl/ssl3.h>
19
20#include "bytestring.h"
21#include "ssl_local.h"
22#include "ssl_sigalgs.h"
23#include "ssl_tlsext.h"
24#include "tls13_handshake.h"
25#include "tls13_internal.h"
26
27int
28tls13_client_init(struct tls13_ctx *ctx)
29{
30 const uint16_t *groups;
31 size_t groups_len;
32 SSL *s = ctx->ssl;
33
34 if (!ssl_supported_tls_version_range(s, &ctx->hs->our_min_tls_version,
35 &ctx->hs->our_max_tls_version)) {
36 SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE);
37 return 0;
38 }
39 s->version = ctx->hs->our_max_tls_version;
40
41 tls13_record_layer_set_retry_after_phh(ctx->rl,
42 (s->mode & SSL_MODE_AUTO_RETRY) != 0);
43
44 if (!ssl_get_new_session(s, 0)) /* XXX */
45 return 0;
46
47 if (!tls1_transcript_init(s))
48 return 0;
49
50 /* Generate a key share using our preferred group. */
51 tls1_get_group_list(s, 0, &groups, &groups_len);
52 if (groups_len < 1)
53 return 0;
54 if ((ctx->hs->key_share = tls_key_share_new(groups[0])) == NULL)
55 return 0;
56 if (!tls_key_share_generate(ctx->hs->key_share))
57 return 0;
58
59 arc4random_buf(s->s3->client_random, SSL3_RANDOM_SIZE);
60
61 /*
62 * The legacy session identifier should either be set to an
63 * unpredictable 32-byte value or zero length... a non-zero length
64 * legacy session identifier triggers compatibility mode (see RFC 8446
65 * Appendix D.4). In the pre-TLSv1.3 case a zero length value is used.
66 */
67 if (ctx->middlebox_compat &&
68 ctx->hs->our_max_tls_version >= TLS1_3_VERSION) {
69 arc4random_buf(ctx->hs->tls13.legacy_session_id,
70 sizeof(ctx->hs->tls13.legacy_session_id));
71 ctx->hs->tls13.legacy_session_id_len =
72 sizeof(ctx->hs->tls13.legacy_session_id);
73 }
74
75 return 1;
76}
77
78int
79tls13_client_connect(struct tls13_ctx *ctx)
80{
81 if (ctx->mode != TLS13_HS_CLIENT)
82 return TLS13_IO_FAILURE;
83
84 return tls13_handshake_perform(ctx);
85}
86
87static int
88tls13_client_hello_build(struct tls13_ctx *ctx, CBB *cbb)
89{
90 CBB cipher_suites, compression_methods, session_id;
91 uint16_t client_version;
92 SSL *s = ctx->ssl;
93
94 /* Legacy client version is capped at TLS 1.2. */
95 if (!ssl_max_legacy_version(s, &client_version))
96 goto err;
97
98 if (!CBB_add_u16(cbb, client_version))
99 goto err;
100 if (!CBB_add_bytes(cbb, s->s3->client_random, SSL3_RANDOM_SIZE))
101 goto err;
102
103 if (!CBB_add_u8_length_prefixed(cbb, &session_id))
104 goto err;
105 if (!CBB_add_bytes(&session_id, ctx->hs->tls13.legacy_session_id,
106 ctx->hs->tls13.legacy_session_id_len))
107 goto err;
108
109 if (!CBB_add_u16_length_prefixed(cbb, &cipher_suites))
110 goto err;
111 if (!ssl_cipher_list_to_bytes(s, SSL_get_ciphers(s), &cipher_suites)) {
112 SSLerror(s, SSL_R_NO_CIPHERS_AVAILABLE);
113 goto err;
114 }
115
116 if (!CBB_add_u8_length_prefixed(cbb, &compression_methods))
117 goto err;
118 if (!CBB_add_u8(&compression_methods, 0))
119 goto err;
120
121 if (!tlsext_client_build(s, SSL_TLSEXT_MSG_CH, cbb))
122 goto err;
123
124 if (!CBB_flush(cbb))
125 goto err;
126
127 return 1;
128
129 err:
130 return 0;
131}
132
133int
134tls13_client_hello_send(struct tls13_ctx *ctx, CBB *cbb)
135{
136 if (ctx->hs->our_min_tls_version < TLS1_2_VERSION)
137 tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION);
138
139 /* We may receive a pre-TLSv1.3 alert in response to the client hello. */
140 tls13_record_layer_allow_legacy_alerts(ctx->rl, 1);
141
142 if (!tls13_client_hello_build(ctx, cbb))
143 return 0;
144
145 return 1;
146}
147
148int
149tls13_client_hello_sent(struct tls13_ctx *ctx)
150{
151 tls1_transcript_freeze(ctx->ssl);
152
153 if (ctx->middlebox_compat) {
154 tls13_record_layer_allow_ccs(ctx->rl, 1);
155 ctx->send_dummy_ccs = 1;
156 }
157
158 return 1;
159}
160
161static int
162tls13_server_hello_is_legacy(CBS *cbs)
163{
164 CBS extensions_block, extensions, extension_data;
165 uint16_t selected_version = 0;
166 uint16_t type;
167
168 CBS_dup(cbs, &extensions_block);
169
170 if (!CBS_get_u16_length_prefixed(&extensions_block, &extensions))
171 return 1;
172
173 while (CBS_len(&extensions) > 0) {
174 if (!CBS_get_u16(&extensions, &type))
175 return 1;
176 if (!CBS_get_u16_length_prefixed(&extensions, &extension_data))
177 return 1;
178
179 if (type != TLSEXT_TYPE_supported_versions)
180 continue;
181 if (!CBS_get_u16(&extension_data, &selected_version))
182 return 1;
183 if (CBS_len(&extension_data) != 0)
184 return 1;
185 }
186
187 return (selected_version < TLS1_3_VERSION);
188}
189
190static int
191tls13_server_hello_is_retry(CBS *cbs)
192{
193 CBS server_hello, server_random;
194 uint16_t legacy_version;
195
196 CBS_dup(cbs, &server_hello);
197
198 if (!CBS_get_u16(&server_hello, &legacy_version))
199 return 0;
200 if (!CBS_get_bytes(&server_hello, &server_random, SSL3_RANDOM_SIZE))
201 return 0;
202
203 /* See if this is a HelloRetryRequest. */
204 return CBS_mem_equal(&server_random, tls13_hello_retry_request_hash,
205 sizeof(tls13_hello_retry_request_hash));
206}
207
208static int
209tls13_server_hello_process(struct tls13_ctx *ctx, CBS *cbs)
210{
211 CBS server_random, session_id;
212 uint16_t tlsext_msg_type = SSL_TLSEXT_MSG_SH;
213 uint16_t cipher_suite, legacy_version;
214 uint8_t compression_method;
215 const SSL_CIPHER *cipher;
216 int alert_desc;
217 SSL *s = ctx->ssl;
218
219 if (!CBS_get_u16(cbs, &legacy_version))
220 goto err;
221 if (!CBS_get_bytes(cbs, &server_random, SSL3_RANDOM_SIZE))
222 goto err;
223 if (!CBS_get_u8_length_prefixed(cbs, &session_id))
224 goto err;
225 if (!CBS_get_u16(cbs, &cipher_suite))
226 goto err;
227 if (!CBS_get_u8(cbs, &compression_method))
228 goto err;
229
230 if (tls13_server_hello_is_legacy(cbs)) {
231 if (ctx->hs->our_max_tls_version >= TLS1_3_VERSION) {
232 /*
233 * RFC 8446 section 4.1.3: we must not downgrade if
234 * the server random value contains the TLS 1.2 or 1.1
235 * magical value.
236 */
237 if (!CBS_skip(&server_random, CBS_len(&server_random) -
238 sizeof(tls13_downgrade_12)))
239 goto err;
240 if (CBS_mem_equal(&server_random, tls13_downgrade_12,
241 sizeof(tls13_downgrade_12)) ||
242 CBS_mem_equal(&server_random, tls13_downgrade_11,
243 sizeof(tls13_downgrade_11))) {
244 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
245 goto err;
246 }
247 }
248
249 if (!CBS_skip(cbs, CBS_len(cbs)))
250 goto err;
251
252 ctx->hs->tls13.use_legacy = 1;
253 return 1;
254 }
255
256 /* From here on in we know we are doing TLSv1.3. */
257 tls13_record_layer_set_legacy_version(ctx->rl, TLS1_2_VERSION);
258 tls13_record_layer_allow_legacy_alerts(ctx->rl, 0);
259
260 /* See if this is a HelloRetryRequest. */
261 /* XXX - see if we can avoid doing this twice. */
262 if (CBS_mem_equal(&server_random, tls13_hello_retry_request_hash,
263 sizeof(tls13_hello_retry_request_hash))) {
264 tlsext_msg_type = SSL_TLSEXT_MSG_HRR;
265 ctx->hs->tls13.hrr = 1;
266 }
267
268 if (!tlsext_client_parse(s, tlsext_msg_type, cbs, &alert_desc)) {
269 ctx->alert = alert_desc;
270 goto err;
271 }
272
273 /*
274 * The supported versions extension indicated 0x0304 or greater.
275 * Ensure that it was 0x0304 and that legacy version is set to 0x0303
276 * (RFC 8446 section 4.2.1).
277 */
278 if (ctx->hs->tls13.server_version != TLS1_3_VERSION ||
279 legacy_version != TLS1_2_VERSION) {
280 ctx->alert = TLS13_ALERT_PROTOCOL_VERSION;
281 goto err;
282 }
283 ctx->hs->negotiated_tls_version = ctx->hs->tls13.server_version;
284 ctx->hs->peer_legacy_version = legacy_version;
285
286 /* The session_id must match. */
287 if (!CBS_mem_equal(&session_id, ctx->hs->tls13.legacy_session_id,
288 ctx->hs->tls13.legacy_session_id_len)) {
289 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
290 goto err;
291 }
292
293 /*
294 * Ensure that the cipher suite is one that we offered in the client
295 * hello and that it is a TLSv1.3 cipher suite.
296 */
297 cipher = ssl3_get_cipher_by_value(cipher_suite);
298 if (cipher == NULL || !ssl_cipher_in_list(SSL_get_ciphers(s), cipher)) {
299 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
300 goto err;
301 }
302 if (cipher->algorithm_ssl != SSL_TLSV1_3) {
303 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
304 goto err;
305 }
306 if (!(ctx->handshake_stage.hs_type & WITHOUT_HRR) && !ctx->hs->tls13.hrr) {
307 /*
308 * A ServerHello following a HelloRetryRequest MUST use the same
309 * cipher suite (RFC 8446 section 4.1.4).
310 */
311 if (ctx->hs->cipher != cipher) {
312 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
313 goto err;
314 }
315 }
316 ctx->hs->cipher = cipher;
317
318 if (compression_method != 0) {
319 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
320 goto err;
321 }
322
323 return 1;
324
325 err:
326 if (ctx->alert == 0)
327 ctx->alert = TLS13_ALERT_DECODE_ERROR;
328
329 return 0;
330}
331
332static int
333tls13_client_engage_record_protection(struct tls13_ctx *ctx)
334{
335 struct tls13_secrets *secrets;
336 struct tls13_secret context;
337 unsigned char buf[EVP_MAX_MD_SIZE];
338 uint8_t *shared_key = NULL;
339 size_t shared_key_len = 0;
340 size_t hash_len;
341 SSL *s = ctx->ssl;
342 int ret = 0;
343
344 /* Derive the shared key and engage record protection. */
345
346 if (!tls_key_share_derive(ctx->hs->key_share, &shared_key,
347 &shared_key_len))
348 goto err;
349
350 s->session->cipher_value = ctx->hs->cipher->value;
351 s->session->ssl_version = ctx->hs->tls13.server_version;
352
353 if ((ctx->aead = tls13_cipher_aead(ctx->hs->cipher)) == NULL)
354 goto err;
355 if ((ctx->hash = tls13_cipher_hash(ctx->hs->cipher)) == NULL)
356 goto err;
357
358 if ((secrets = tls13_secrets_create(ctx->hash, 0)) == NULL)
359 goto err;
360 ctx->hs->tls13.secrets = secrets;
361
362 /* XXX - pass in hash. */
363 if (!tls1_transcript_hash_init(s))
364 goto err;
365 tls1_transcript_free(s);
366 if (!tls1_transcript_hash_value(s, buf, sizeof(buf), &hash_len))
367 goto err;
368 context.data = buf;
369 context.len = hash_len;
370
371 /* Early secrets. */
372 if (!tls13_derive_early_secrets(secrets, secrets->zeros.data,
373 secrets->zeros.len, &context))
374 goto err;
375
376 /* Handshake secrets. */
377 if (!tls13_derive_handshake_secrets(ctx->hs->tls13.secrets, shared_key,
378 shared_key_len, &context))
379 goto err;
380
381 tls13_record_layer_set_aead(ctx->rl, ctx->aead);
382 tls13_record_layer_set_hash(ctx->rl, ctx->hash);
383
384 if (!tls13_record_layer_set_read_traffic_key(ctx->rl,
385 &secrets->server_handshake_traffic, ssl_encryption_handshake))
386 goto err;
387 if (!tls13_record_layer_set_write_traffic_key(ctx->rl,
388 &secrets->client_handshake_traffic, ssl_encryption_handshake))
389 goto err;
390
391 ret = 1;
392
393 err:
394 freezero(shared_key, shared_key_len);
395
396 return ret;
397}
398
399int
400tls13_server_hello_retry_request_recv(struct tls13_ctx *ctx, CBS *cbs)
401{
402 /*
403 * The state machine has no way of knowing if we're going to receive a
404 * HelloRetryRequest or a ServerHello. As such, we have to handle
405 * this case here and hand off to the appropriate function.
406 */
407 if (!tls13_server_hello_is_retry(cbs)) {
408 ctx->handshake_stage.hs_type |= WITHOUT_HRR;
409 return tls13_server_hello_recv(ctx, cbs);
410 }
411
412 if (!tls13_server_hello_process(ctx, cbs))
413 return 0;
414
415 /*
416 * This may have been a TLSv1.2 or earlier ServerHello that just
417 * happened to have matching server random...
418 */
419 if (ctx->hs->tls13.use_legacy)
420 return tls13_use_legacy_client(ctx);
421
422 if (!ctx->hs->tls13.hrr)
423 return 0;
424
425 if (!tls13_synthetic_handshake_message(ctx))
426 return 0;
427 if (!tls13_handshake_msg_record(ctx))
428 return 0;
429
430 ctx->hs->tls13.hrr = 0;
431
432 return 1;
433}
434
435int
436tls13_client_hello_retry_send(struct tls13_ctx *ctx, CBB *cbb)
437{
438 /*
439 * Ensure that the server supported group is one that we listed in our
440 * supported groups and is not the same as the key share we previously
441 * offered.
442 */
443 if (!tls1_check_group(ctx->ssl, ctx->hs->tls13.server_group))
444 return 0; /* XXX alert */
445 if (ctx->hs->tls13.server_group == tls_key_share_group(ctx->hs->key_share))
446 return 0; /* XXX alert */
447
448 /* Switch to new key share. */
449 tls_key_share_free(ctx->hs->key_share);
450 if ((ctx->hs->key_share =
451 tls_key_share_new(ctx->hs->tls13.server_group)) == NULL)
452 return 0;
453 if (!tls_key_share_generate(ctx->hs->key_share))
454 return 0;
455
456 if (!tls13_client_hello_build(ctx, cbb))
457 return 0;
458
459 return 1;
460}
461
462int
463tls13_server_hello_recv(struct tls13_ctx *ctx, CBS *cbs)
464{
465 SSL *s = ctx->ssl;
466
467 /*
468 * We may have received a legacy (pre-TLSv1.3) ServerHello or a TLSv1.3
469 * ServerHello. HelloRetryRequests have already been handled.
470 */
471 if (!tls13_server_hello_process(ctx, cbs))
472 return 0;
473
474 if (ctx->handshake_stage.hs_type & WITHOUT_HRR) {
475 tls1_transcript_unfreeze(s);
476 if (!tls13_handshake_msg_record(ctx))
477 return 0;
478 }
479
480 if (ctx->hs->tls13.use_legacy) {
481 if (!(ctx->handshake_stage.hs_type & WITHOUT_HRR))
482 return 0;
483 return tls13_use_legacy_client(ctx);
484 }
485
486 if (ctx->hs->tls13.hrr) {
487 /* The server has sent two HelloRetryRequests. */
488 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
489 return 0;
490 }
491
492 if (!tls13_client_engage_record_protection(ctx))
493 return 0;
494
495 ctx->handshake_stage.hs_type |= NEGOTIATED;
496
497 return 1;
498}
499
500int
501tls13_server_encrypted_extensions_recv(struct tls13_ctx *ctx, CBS *cbs)
502{
503 int alert_desc;
504
505 if (!tlsext_client_parse(ctx->ssl, SSL_TLSEXT_MSG_EE, cbs, &alert_desc)) {
506 ctx->alert = alert_desc;
507 return 0;
508 }
509
510 return 1;
511}
512
513int
514tls13_server_certificate_request_recv(struct tls13_ctx *ctx, CBS *cbs)
515{
516 CBS cert_request_context;
517 int alert_desc;
518
519 /*
520 * Thanks to poor state design in the RFC, this function can be called
521 * when we actually have a certificate message instead of a certificate
522 * request... in that case we call the certificate handler after
523 * switching state, to avoid advancing state.
524 */
525 if (tls13_handshake_msg_type(ctx->hs_msg) == TLS13_MT_CERTIFICATE) {
526 ctx->handshake_stage.hs_type |= WITHOUT_CR;
527 return tls13_server_certificate_recv(ctx, cbs);
528 }
529
530 if (!CBS_get_u8_length_prefixed(cbs, &cert_request_context))
531 goto err;
532 if (CBS_len(&cert_request_context) != 0)
533 goto err;
534
535 if (!tlsext_client_parse(ctx->ssl, SSL_TLSEXT_MSG_CR, cbs, &alert_desc)) {
536 ctx->alert = alert_desc;
537 goto err;
538 }
539
540 return 1;
541
542 err:
543 if (ctx->alert == 0)
544 ctx->alert = TLS13_ALERT_DECODE_ERROR;
545
546 return 0;
547}
548
549int
550tls13_server_certificate_recv(struct tls13_ctx *ctx, CBS *cbs)
551{
552 CBS cert_request_context, cert_list, cert_data;
553 struct stack_st_X509 *certs = NULL;
554 SSL *s = ctx->ssl;
555 X509 *cert = NULL;
556 const uint8_t *p;
557 int alert_desc;
558 int ret = 0;
559
560 if ((certs = sk_X509_new_null()) == NULL)
561 goto err;
562
563 if (!CBS_get_u8_length_prefixed(cbs, &cert_request_context))
564 goto err;
565 if (CBS_len(&cert_request_context) != 0)
566 goto err;
567 if (!CBS_get_u24_length_prefixed(cbs, &cert_list))
568 goto err;
569
570 while (CBS_len(&cert_list) > 0) {
571 if (!CBS_get_u24_length_prefixed(&cert_list, &cert_data))
572 goto err;
573
574 if (!tlsext_client_parse(ctx->ssl, SSL_TLSEXT_MSG_CT,
575 &cert_list, &alert_desc)) {
576 ctx->alert = alert_desc;
577 goto err;
578 }
579
580 p = CBS_data(&cert_data);
581 if ((cert = d2i_X509(NULL, &p, CBS_len(&cert_data))) == NULL)
582 goto err;
583 if (p != CBS_data(&cert_data) + CBS_len(&cert_data))
584 goto err;
585
586 if (!sk_X509_push(certs, cert))
587 goto err;
588
589 cert = NULL;
590 }
591
592 /* A server must always provide a non-empty certificate list. */
593 if (sk_X509_num(certs) < 1) {
594 ctx->alert = TLS13_ALERT_DECODE_ERROR;
595 tls13_set_errorx(ctx, TLS13_ERR_NO_PEER_CERTIFICATE, 0,
596 "peer failed to provide a certificate", NULL);
597 goto err;
598 }
599
600 /*
601 * At this stage we still have no proof of possession. As such, it would
602 * be preferable to keep the chain and verify once we have successfully
603 * processed the CertificateVerify message.
604 */
605 if (ssl_verify_cert_chain(s, certs) <= 0 &&
606 s->verify_mode != SSL_VERIFY_NONE) {
607 ctx->alert = ssl_verify_alarm_type(s->verify_result);
608 tls13_set_errorx(ctx, TLS13_ERR_VERIFY_FAILED, 0,
609 "failed to verify peer certificate", NULL);
610 goto err;
611 }
612 s->session->verify_result = s->verify_result;
613 ERR_clear_error();
614
615 if (!tls_process_peer_certs(s, certs))
616 goto err;
617
618 if (ctx->ocsp_status_recv_cb != NULL &&
619 !ctx->ocsp_status_recv_cb(ctx))
620 goto err;
621
622 ret = 1;
623
624 err:
625 sk_X509_pop_free(certs, X509_free);
626 X509_free(cert);
627
628 return ret;
629}
630
631int
632tls13_server_certificate_verify_recv(struct tls13_ctx *ctx, CBS *cbs)
633{
634 const struct ssl_sigalg *sigalg;
635 uint16_t signature_scheme;
636 uint8_t *sig_content = NULL;
637 size_t sig_content_len;
638 EVP_MD_CTX *mdctx = NULL;
639 EVP_PKEY_CTX *pctx;
640 EVP_PKEY *pkey;
641 X509 *cert;
642 CBS signature;
643 CBB cbb;
644 int ret = 0;
645
646 memset(&cbb, 0, sizeof(cbb));
647
648 if (!CBS_get_u16(cbs, &signature_scheme))
649 goto err;
650 if (!CBS_get_u16_length_prefixed(cbs, &signature))
651 goto err;
652
653 if (!CBB_init(&cbb, 0))
654 goto err;
655 if (!CBB_add_bytes(&cbb, tls13_cert_verify_pad,
656 sizeof(tls13_cert_verify_pad)))
657 goto err;
658 if (!CBB_add_bytes(&cbb, tls13_cert_server_verify_context,
659 strlen(tls13_cert_server_verify_context)))
660 goto err;
661 if (!CBB_add_u8(&cbb, 0))
662 goto err;
663 if (!CBB_add_bytes(&cbb, ctx->hs->tls13.transcript_hash,
664 ctx->hs->tls13.transcript_hash_len))
665 goto err;
666 if (!CBB_finish(&cbb, &sig_content, &sig_content_len))
667 goto err;
668
669 if ((cert = ctx->ssl->session->peer_cert) == NULL)
670 goto err;
671 if ((pkey = X509_get0_pubkey(cert)) == NULL)
672 goto err;
673 if ((sigalg = ssl_sigalg_for_peer(ctx->ssl, pkey,
674 signature_scheme)) == NULL)
675 goto err;
676 ctx->hs->peer_sigalg = sigalg;
677
678 if (CBS_len(&signature) > EVP_PKEY_size(pkey))
679 goto err;
680
681 if ((mdctx = EVP_MD_CTX_new()) == NULL)
682 goto err;
683 if (!EVP_DigestVerifyInit(mdctx, &pctx, sigalg->md(), NULL, pkey))
684 goto err;
685 if (sigalg->flags & SIGALG_FLAG_RSA_PSS) {
686 if (!EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING))
687 goto err;
688 if (!EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))
689 goto err;
690 }
691 if (EVP_DigestVerify(mdctx, CBS_data(&signature), CBS_len(&signature),
692 sig_content, sig_content_len) <= 0) {
693 ctx->alert = TLS13_ALERT_DECRYPT_ERROR;
694 goto err;
695 }
696
697 ret = 1;
698
699 err:
700 if (!ret && ctx->alert == 0)
701 ctx->alert = TLS13_ALERT_DECODE_ERROR;
702 CBB_cleanup(&cbb);
703 EVP_MD_CTX_free(mdctx);
704 free(sig_content);
705
706 return ret;
707}
708
709int
710tls13_server_finished_recv(struct tls13_ctx *ctx, CBS *cbs)
711{
712 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
713 struct tls13_secret context = { .data = "", .len = 0 };
714 struct tls13_secret finished_key;
715 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
716 size_t transcript_hash_len;
717 uint8_t *verify_data = NULL;
718 size_t verify_data_len;
719 uint8_t key[EVP_MAX_MD_SIZE];
720 HMAC_CTX *hmac_ctx = NULL;
721 unsigned int hlen;
722 int ret = 0;
723
724 /*
725 * Verify server finished.
726 */
727 finished_key.data = key;
728 finished_key.len = EVP_MD_size(ctx->hash);
729
730 if (!tls13_hkdf_expand_label(&finished_key, ctx->hash,
731 &secrets->server_handshake_traffic, "finished",
732 &context))
733 goto err;
734
735 if ((hmac_ctx = HMAC_CTX_new()) == NULL)
736 goto err;
737 if (!HMAC_Init_ex(hmac_ctx, finished_key.data, finished_key.len,
738 ctx->hash, NULL))
739 goto err;
740 if (!HMAC_Update(hmac_ctx, ctx->hs->tls13.transcript_hash,
741 ctx->hs->tls13.transcript_hash_len))
742 goto err;
743 verify_data_len = HMAC_size(hmac_ctx);
744 if ((verify_data = calloc(1, verify_data_len)) == NULL)
745 goto err;
746 if (!HMAC_Final(hmac_ctx, verify_data, &hlen))
747 goto err;
748 if (hlen != verify_data_len)
749 goto err;
750
751 if (!CBS_mem_equal(cbs, verify_data, verify_data_len)) {
752 ctx->alert = TLS13_ALERT_DECRYPT_ERROR;
753 goto err;
754 }
755
756 if (!CBS_write_bytes(cbs, ctx->hs->peer_finished,
757 sizeof(ctx->hs->peer_finished),
758 &ctx->hs->peer_finished_len))
759 goto err;
760
761 if (!CBS_skip(cbs, verify_data_len))
762 goto err;
763
764 /*
765 * Derive application traffic keys.
766 */
767 if (!tls1_transcript_hash_value(ctx->ssl, transcript_hash,
768 sizeof(transcript_hash), &transcript_hash_len))
769 goto err;
770
771 context.data = transcript_hash;
772 context.len = transcript_hash_len;
773
774 if (!tls13_derive_application_secrets(secrets, &context))
775 goto err;
776
777 /*
778 * Any records following the server finished message must be encrypted
779 * using the server application traffic keys.
780 */
781 if (!tls13_record_layer_set_read_traffic_key(ctx->rl,
782 &secrets->server_application_traffic, ssl_encryption_application))
783 goto err;
784
785 tls13_record_layer_allow_ccs(ctx->rl, 0);
786
787 ret = 1;
788
789 err:
790 HMAC_CTX_free(hmac_ctx);
791 free(verify_data);
792
793 return ret;
794}
795
796static int
797tls13_client_check_certificate(struct tls13_ctx *ctx, SSL_CERT_PKEY *cpk,
798 int *ok, const struct ssl_sigalg **out_sigalg)
799{
800 const struct ssl_sigalg *sigalg;
801 SSL *s = ctx->ssl;
802
803 *ok = 0;
804 *out_sigalg = NULL;
805
806 if (cpk->x509 == NULL || cpk->privatekey == NULL)
807 goto done;
808
809 if ((sigalg = ssl_sigalg_select(s, cpk->privatekey)) == NULL)
810 goto done;
811
812 *ok = 1;
813 *out_sigalg = sigalg;
814
815 done:
816 return 1;
817}
818
819static int
820tls13_client_select_certificate(struct tls13_ctx *ctx, SSL_CERT_PKEY **out_cpk,
821 const struct ssl_sigalg **out_sigalg)
822{
823 SSL *s = ctx->ssl;
824 const struct ssl_sigalg *sigalg;
825 SSL_CERT_PKEY *cpk;
826 int cert_ok;
827
828 *out_cpk = NULL;
829 *out_sigalg = NULL;
830
831 /*
832 * XXX - RFC 8446, 4.4.2.3: the server can communicate preferences
833 * with the certificate_authorities (4.2.4) and oid_filters (4.2.5)
834 * extensions. We should honor the former and must apply the latter.
835 */
836
837 cpk = &s->cert->pkeys[SSL_PKEY_ECC];
838 if (!tls13_client_check_certificate(ctx, cpk, &cert_ok, &sigalg))
839 return 0;
840 if (cert_ok)
841 goto done;
842
843 cpk = &s->cert->pkeys[SSL_PKEY_RSA];
844 if (!tls13_client_check_certificate(ctx, cpk, &cert_ok, &sigalg))
845 return 0;
846 if (cert_ok)
847 goto done;
848
849 cpk = NULL;
850 sigalg = NULL;
851
852 done:
853 *out_cpk = cpk;
854 *out_sigalg = sigalg;
855
856 return 1;
857}
858
859int
860tls13_client_certificate_send(struct tls13_ctx *ctx, CBB *cbb)
861{
862 SSL *s = ctx->ssl;
863 CBB cert_request_context, cert_list;
864 const struct ssl_sigalg *sigalg;
865 STACK_OF(X509) *chain;
866 SSL_CERT_PKEY *cpk;
867 X509 *cert;
868 int i, ret = 0;
869
870 if (!tls13_client_select_certificate(ctx, &cpk, &sigalg))
871 goto err;
872
873 ctx->hs->tls13.cpk = cpk;
874 ctx->hs->our_sigalg = sigalg;
875
876 if (!CBB_add_u8_length_prefixed(cbb, &cert_request_context))
877 goto err;
878 if (!CBB_add_u24_length_prefixed(cbb, &cert_list))
879 goto err;
880
881 /* No certificate selected. */
882 if (cpk == NULL)
883 goto done;
884
885 if ((chain = cpk->chain) == NULL)
886 chain = s->ctx->extra_certs;
887
888 if (!tls13_cert_add(ctx, &cert_list, cpk->x509, tlsext_client_build))
889 goto err;
890
891 for (i = 0; i < sk_X509_num(chain); i++) {
892 cert = sk_X509_value(chain, i);
893 if (!tls13_cert_add(ctx, &cert_list, cert, tlsext_client_build))
894 goto err;
895 }
896
897 ctx->handshake_stage.hs_type |= WITH_CCV;
898 done:
899 if (!CBB_flush(cbb))
900 goto err;
901
902 ret = 1;
903
904 err:
905 return ret;
906}
907
908int
909tls13_client_certificate_verify_send(struct tls13_ctx *ctx, CBB *cbb)
910{
911 const struct ssl_sigalg *sigalg;
912 uint8_t *sig = NULL, *sig_content = NULL;
913 size_t sig_len, sig_content_len;
914 EVP_MD_CTX *mdctx = NULL;
915 EVP_PKEY_CTX *pctx;
916 EVP_PKEY *pkey;
917 const SSL_CERT_PKEY *cpk;
918 CBB sig_cbb;
919 int ret = 0;
920
921 memset(&sig_cbb, 0, sizeof(sig_cbb));
922
923 if ((cpk = ctx->hs->tls13.cpk) == NULL)
924 goto err;
925 if ((sigalg = ctx->hs->our_sigalg) == NULL)
926 goto err;
927 pkey = cpk->privatekey;
928
929 if (!CBB_init(&sig_cbb, 0))
930 goto err;
931 if (!CBB_add_bytes(&sig_cbb, tls13_cert_verify_pad,
932 sizeof(tls13_cert_verify_pad)))
933 goto err;
934 if (!CBB_add_bytes(&sig_cbb, tls13_cert_client_verify_context,
935 strlen(tls13_cert_client_verify_context)))
936 goto err;
937 if (!CBB_add_u8(&sig_cbb, 0))
938 goto err;
939 if (!CBB_add_bytes(&sig_cbb, ctx->hs->tls13.transcript_hash,
940 ctx->hs->tls13.transcript_hash_len))
941 goto err;
942 if (!CBB_finish(&sig_cbb, &sig_content, &sig_content_len))
943 goto err;
944
945 if ((mdctx = EVP_MD_CTX_new()) == NULL)
946 goto err;
947 if (!EVP_DigestSignInit(mdctx, &pctx, sigalg->md(), NULL, pkey))
948 goto err;
949 if (sigalg->flags & SIGALG_FLAG_RSA_PSS) {
950 if (!EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING))
951 goto err;
952 if (!EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))
953 goto err;
954 }
955 if (!EVP_DigestSign(mdctx, NULL, &sig_len, sig_content, sig_content_len))
956 goto err;
957 if ((sig = calloc(1, sig_len)) == NULL)
958 goto err;
959 if (!EVP_DigestSign(mdctx, sig, &sig_len, sig_content, sig_content_len))
960 goto err;
961
962 if (!CBB_add_u16(cbb, sigalg->value))
963 goto err;
964 if (!CBB_add_u16_length_prefixed(cbb, &sig_cbb))
965 goto err;
966 if (!CBB_add_bytes(&sig_cbb, sig, sig_len))
967 goto err;
968
969 if (!CBB_flush(cbb))
970 goto err;
971
972 ret = 1;
973
974 err:
975 if (!ret && ctx->alert == 0)
976 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
977
978 CBB_cleanup(&sig_cbb);
979 EVP_MD_CTX_free(mdctx);
980 free(sig_content);
981 free(sig);
982
983 return ret;
984}
985
986int
987tls13_client_end_of_early_data_send(struct tls13_ctx *ctx, CBB *cbb)
988{
989 return 0;
990}
991
992int
993tls13_client_finished_send(struct tls13_ctx *ctx, CBB *cbb)
994{
995 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
996 struct tls13_secret context = { .data = "", .len = 0 };
997 struct tls13_secret finished_key = { .data = NULL, .len = 0 };
998 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
999 size_t transcript_hash_len;
1000 uint8_t *verify_data;
1001 size_t verify_data_len;
1002 unsigned int hlen;
1003 HMAC_CTX *hmac_ctx = NULL;
1004 CBS cbs;
1005 int ret = 0;
1006
1007 if (!tls13_secret_init(&finished_key, EVP_MD_size(ctx->hash)))
1008 goto err;
1009
1010 if (!tls13_hkdf_expand_label(&finished_key, ctx->hash,
1011 &secrets->client_handshake_traffic, "finished",
1012 &context))
1013 goto err;
1014
1015 if (!tls1_transcript_hash_value(ctx->ssl, transcript_hash,
1016 sizeof(transcript_hash), &transcript_hash_len))
1017 goto err;
1018
1019 if ((hmac_ctx = HMAC_CTX_new()) == NULL)
1020 goto err;
1021 if (!HMAC_Init_ex(hmac_ctx, finished_key.data, finished_key.len,
1022 ctx->hash, NULL))
1023 goto err;
1024 if (!HMAC_Update(hmac_ctx, transcript_hash, transcript_hash_len))
1025 goto err;
1026
1027 verify_data_len = HMAC_size(hmac_ctx);
1028 if (!CBB_add_space(cbb, &verify_data, verify_data_len))
1029 goto err;
1030 if (!HMAC_Final(hmac_ctx, verify_data, &hlen))
1031 goto err;
1032 if (hlen != verify_data_len)
1033 goto err;
1034
1035 CBS_init(&cbs, verify_data, verify_data_len);
1036 if (!CBS_write_bytes(&cbs, ctx->hs->finished,
1037 sizeof(ctx->hs->finished), &ctx->hs->finished_len))
1038 goto err;
1039
1040 ret = 1;
1041
1042 err:
1043 tls13_secret_cleanup(&finished_key);
1044 HMAC_CTX_free(hmac_ctx);
1045
1046 return ret;
1047}
1048
1049int
1050tls13_client_finished_sent(struct tls13_ctx *ctx)
1051{
1052 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
1053
1054 /*
1055 * Any records following the client finished message must be encrypted
1056 * using the client application traffic keys.
1057 */
1058 return tls13_record_layer_set_write_traffic_key(ctx->rl,
1059 &secrets->client_application_traffic, ssl_encryption_application);
1060}
diff --git a/src/lib/libssl/tls13_error.c b/src/lib/libssl/tls13_error.c
deleted file mode 100644
index 295b6c4fab..0000000000
--- a/src/lib/libssl/tls13_error.c
+++ /dev/null
@@ -1,99 +0,0 @@
1/* $OpenBSD: tls13_error.c,v 1.1 2020/01/20 13:10:37 jsing Exp $ */
2/*
3 * Copyright (c) 2014,2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <errno.h>
19
20#include "tls13_internal.h"
21
22void
23tls13_error_clear(struct tls13_error *error)
24{
25 error->code = 0;
26 error->subcode = 0;
27 error->errnum = 0;
28 error->file = NULL;
29 error->line = 0;
30 free(error->msg);
31 error->msg = NULL;
32}
33
34static int
35tls13_error_vset(struct tls13_error *error, int code, int subcode, int errnum,
36 const char *file, int line, const char *fmt, va_list ap)
37{
38 char *errmsg = NULL;
39 int rv = -1;
40
41 tls13_error_clear(error);
42
43 error->code = code;
44 error->subcode = subcode;
45 error->errnum = errnum;
46 error->file = file;
47 error->line = line;
48
49 if (vasprintf(&errmsg, fmt, ap) == -1) {
50 errmsg = NULL;
51 goto err;
52 }
53
54 if (errnum == -1) {
55 error->msg = errmsg;
56 return 0;
57 }
58
59 if (asprintf(&error->msg, "%s: %s", errmsg, strerror(errnum)) == -1) {
60 error->msg = NULL;
61 goto err;
62 }
63 rv = 0;
64
65 err:
66 free(errmsg);
67
68 return rv;
69}
70
71int
72tls13_error_set(struct tls13_error *error, int code, int subcode,
73 const char *file, int line, const char *fmt, ...)
74{
75 va_list ap;
76 int errnum, rv;
77
78 errnum = errno;
79
80 va_start(ap, fmt);
81 rv = tls13_error_vset(error, code, subcode, errnum, file, line, fmt, ap);
82 va_end(ap);
83
84 return (rv);
85}
86
87int
88tls13_error_setx(struct tls13_error *error, int code, int subcode,
89 const char *file, int line, const char *fmt, ...)
90{
91 va_list ap;
92 int rv;
93
94 va_start(ap, fmt);
95 rv = tls13_error_vset(error, code, subcode, -1, file, line, fmt, ap);
96 va_end(ap);
97
98 return (rv);
99}
diff --git a/src/lib/libssl/tls13_handshake.c b/src/lib/libssl/tls13_handshake.c
deleted file mode 100644
index 0dc2333708..0000000000
--- a/src/lib/libssl/tls13_handshake.c
+++ /dev/null
@@ -1,723 +0,0 @@
1/* $OpenBSD: tls13_handshake.c,v 1.73 2024/02/03 19:57:14 tb Exp $ */
2/*
3 * Copyright (c) 2018-2021 Theo Buehler <tb@openbsd.org>
4 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <stddef.h>
20
21#include "ssl_local.h"
22#include "tls13_handshake.h"
23#include "tls13_internal.h"
24
25/* Based on RFC 8446 and inspired by s2n's TLS 1.2 state machine. */
26
27struct tls13_handshake_action {
28 uint8_t handshake_type;
29 uint8_t sender;
30 uint8_t handshake_complete;
31 uint8_t send_preserve_transcript_hash;
32 uint8_t recv_preserve_transcript_hash;
33
34 int (*send)(struct tls13_ctx *ctx, CBB *cbb);
35 int (*sent)(struct tls13_ctx *ctx);
36 int (*recv)(struct tls13_ctx *ctx, CBS *cbs);
37};
38
39static enum tls13_message_type
40 tls13_handshake_active_state(struct tls13_ctx *ctx);
41
42static const struct tls13_handshake_action *
43 tls13_handshake_active_action(struct tls13_ctx *ctx);
44static int tls13_handshake_advance_state_machine(struct tls13_ctx *ctx);
45
46static int tls13_handshake_send_action(struct tls13_ctx *ctx,
47 const struct tls13_handshake_action *action);
48static int tls13_handshake_recv_action(struct tls13_ctx *ctx,
49 const struct tls13_handshake_action *action);
50
51static int tls13_handshake_set_legacy_state(struct tls13_ctx *ctx);
52static int tls13_handshake_legacy_info_callback(struct tls13_ctx *ctx);
53
54static const struct tls13_handshake_action state_machine[] = {
55 [CLIENT_HELLO] = {
56 .handshake_type = TLS13_MT_CLIENT_HELLO,
57 .sender = TLS13_HS_CLIENT,
58 .send = tls13_client_hello_send,
59 .sent = tls13_client_hello_sent,
60 .recv = tls13_client_hello_recv,
61 },
62 [CLIENT_HELLO_RETRY] = {
63 .handshake_type = TLS13_MT_CLIENT_HELLO,
64 .sender = TLS13_HS_CLIENT,
65 .send = tls13_client_hello_retry_send,
66 .recv = tls13_client_hello_retry_recv,
67 },
68 [CLIENT_END_OF_EARLY_DATA] = {
69 .handshake_type = TLS13_MT_END_OF_EARLY_DATA,
70 .sender = TLS13_HS_CLIENT,
71 .send = tls13_client_end_of_early_data_send,
72 .recv = tls13_client_end_of_early_data_recv,
73 },
74 [CLIENT_CERTIFICATE] = {
75 .handshake_type = TLS13_MT_CERTIFICATE,
76 .sender = TLS13_HS_CLIENT,
77 .send_preserve_transcript_hash = 1,
78 .send = tls13_client_certificate_send,
79 .recv = tls13_client_certificate_recv,
80 },
81 [CLIENT_CERTIFICATE_VERIFY] = {
82 .handshake_type = TLS13_MT_CERTIFICATE_VERIFY,
83 .sender = TLS13_HS_CLIENT,
84 .recv_preserve_transcript_hash = 1,
85 .send = tls13_client_certificate_verify_send,
86 .recv = tls13_client_certificate_verify_recv,
87 },
88 [CLIENT_FINISHED] = {
89 .handshake_type = TLS13_MT_FINISHED,
90 .sender = TLS13_HS_CLIENT,
91 .recv_preserve_transcript_hash = 1,
92 .send = tls13_client_finished_send,
93 .sent = tls13_client_finished_sent,
94 .recv = tls13_client_finished_recv,
95 },
96 [SERVER_HELLO] = {
97 .handshake_type = TLS13_MT_SERVER_HELLO,
98 .sender = TLS13_HS_SERVER,
99 .send = tls13_server_hello_send,
100 .sent = tls13_server_hello_sent,
101 .recv = tls13_server_hello_recv,
102 },
103 [SERVER_HELLO_RETRY_REQUEST] = {
104 .handshake_type = TLS13_MT_SERVER_HELLO,
105 .sender = TLS13_HS_SERVER,
106 .send = tls13_server_hello_retry_request_send,
107 .recv = tls13_server_hello_retry_request_recv,
108 .sent = tls13_server_hello_retry_request_sent,
109 },
110 [SERVER_ENCRYPTED_EXTENSIONS] = {
111 .handshake_type = TLS13_MT_ENCRYPTED_EXTENSIONS,
112 .sender = TLS13_HS_SERVER,
113 .send = tls13_server_encrypted_extensions_send,
114 .recv = tls13_server_encrypted_extensions_recv,
115 },
116 [SERVER_CERTIFICATE] = {
117 .handshake_type = TLS13_MT_CERTIFICATE,
118 .sender = TLS13_HS_SERVER,
119 .send_preserve_transcript_hash = 1,
120 .send = tls13_server_certificate_send,
121 .recv = tls13_server_certificate_recv,
122 },
123 [SERVER_CERTIFICATE_REQUEST] = {
124 .handshake_type = TLS13_MT_CERTIFICATE_REQUEST,
125 .sender = TLS13_HS_SERVER,
126 .send = tls13_server_certificate_request_send,
127 .recv = tls13_server_certificate_request_recv,
128 },
129 [SERVER_CERTIFICATE_VERIFY] = {
130 .handshake_type = TLS13_MT_CERTIFICATE_VERIFY,
131 .sender = TLS13_HS_SERVER,
132 .recv_preserve_transcript_hash = 1,
133 .send = tls13_server_certificate_verify_send,
134 .recv = tls13_server_certificate_verify_recv,
135 },
136 [SERVER_FINISHED] = {
137 .handshake_type = TLS13_MT_FINISHED,
138 .sender = TLS13_HS_SERVER,
139 .recv_preserve_transcript_hash = 1,
140 .send_preserve_transcript_hash = 1,
141 .send = tls13_server_finished_send,
142 .sent = tls13_server_finished_sent,
143 .recv = tls13_server_finished_recv,
144 },
145 [APPLICATION_DATA] = {
146 .handshake_complete = 1,
147 },
148};
149
150const enum tls13_message_type handshakes[][TLS13_NUM_MESSAGE_TYPES] = {
151 [INITIAL] = {
152 CLIENT_HELLO,
153 SERVER_HELLO_RETRY_REQUEST,
154 CLIENT_HELLO_RETRY,
155 SERVER_HELLO,
156 },
157 [NEGOTIATED] = {
158 CLIENT_HELLO,
159 SERVER_HELLO_RETRY_REQUEST,
160 CLIENT_HELLO_RETRY,
161 SERVER_HELLO,
162 SERVER_ENCRYPTED_EXTENSIONS,
163 SERVER_CERTIFICATE_REQUEST,
164 SERVER_CERTIFICATE,
165 SERVER_CERTIFICATE_VERIFY,
166 SERVER_FINISHED,
167 CLIENT_CERTIFICATE,
168 CLIENT_FINISHED,
169 APPLICATION_DATA,
170 },
171 [NEGOTIATED | WITHOUT_HRR] = {
172 CLIENT_HELLO,
173 SERVER_HELLO,
174 SERVER_ENCRYPTED_EXTENSIONS,
175 SERVER_CERTIFICATE_REQUEST,
176 SERVER_CERTIFICATE,
177 SERVER_CERTIFICATE_VERIFY,
178 SERVER_FINISHED,
179 CLIENT_CERTIFICATE,
180 CLIENT_FINISHED,
181 APPLICATION_DATA,
182 },
183 [NEGOTIATED | WITHOUT_CR] = {
184 CLIENT_HELLO,
185 SERVER_HELLO_RETRY_REQUEST,
186 CLIENT_HELLO_RETRY,
187 SERVER_HELLO,
188 SERVER_ENCRYPTED_EXTENSIONS,
189 SERVER_CERTIFICATE,
190 SERVER_CERTIFICATE_VERIFY,
191 SERVER_FINISHED,
192 CLIENT_FINISHED,
193 APPLICATION_DATA,
194 },
195 [NEGOTIATED | WITHOUT_HRR | WITHOUT_CR] = {
196 CLIENT_HELLO,
197 SERVER_HELLO,
198 SERVER_ENCRYPTED_EXTENSIONS,
199 SERVER_CERTIFICATE,
200 SERVER_CERTIFICATE_VERIFY,
201 SERVER_FINISHED,
202 CLIENT_FINISHED,
203 APPLICATION_DATA,
204 },
205 [NEGOTIATED | WITH_PSK] = {
206 CLIENT_HELLO,
207 SERVER_HELLO_RETRY_REQUEST,
208 CLIENT_HELLO_RETRY,
209 SERVER_HELLO,
210 SERVER_ENCRYPTED_EXTENSIONS,
211 SERVER_FINISHED,
212 CLIENT_FINISHED,
213 APPLICATION_DATA,
214 },
215 [NEGOTIATED | WITHOUT_HRR | WITH_PSK] = {
216 CLIENT_HELLO,
217 SERVER_HELLO,
218 SERVER_ENCRYPTED_EXTENSIONS,
219 SERVER_FINISHED,
220 CLIENT_FINISHED,
221 APPLICATION_DATA,
222 },
223 [NEGOTIATED | WITH_CCV] = {
224 CLIENT_HELLO,
225 SERVER_HELLO_RETRY_REQUEST,
226 CLIENT_HELLO_RETRY,
227 SERVER_HELLO,
228 SERVER_ENCRYPTED_EXTENSIONS,
229 SERVER_CERTIFICATE_REQUEST,
230 SERVER_CERTIFICATE,
231 SERVER_CERTIFICATE_VERIFY,
232 SERVER_FINISHED,
233 CLIENT_CERTIFICATE,
234 CLIENT_CERTIFICATE_VERIFY,
235 CLIENT_FINISHED,
236 APPLICATION_DATA,
237 },
238 [NEGOTIATED | WITHOUT_HRR | WITH_CCV] = {
239 CLIENT_HELLO,
240 SERVER_HELLO,
241 SERVER_ENCRYPTED_EXTENSIONS,
242 SERVER_CERTIFICATE_REQUEST,
243 SERVER_CERTIFICATE,
244 SERVER_CERTIFICATE_VERIFY,
245 SERVER_FINISHED,
246 CLIENT_CERTIFICATE,
247 CLIENT_CERTIFICATE_VERIFY,
248 CLIENT_FINISHED,
249 APPLICATION_DATA,
250 },
251};
252
253const size_t handshake_count = sizeof(handshakes) / sizeof(handshakes[0]);
254
255#ifndef TLS13_DEBUG
256#define DEBUGF(...)
257#else
258#define DEBUGF(...) fprintf(stderr, __VA_ARGS__)
259
260static const char *
261tls13_handshake_mode_name(uint8_t mode)
262{
263 switch (mode) {
264 case TLS13_HS_CLIENT:
265 return "Client";
266 case TLS13_HS_SERVER:
267 return "Server";
268 }
269 return "Unknown";
270}
271
272static const char *
273tls13_handshake_message_name(uint8_t msg_type)
274{
275 switch (msg_type) {
276 case TLS13_MT_CLIENT_HELLO:
277 return "ClientHello";
278 case TLS13_MT_SERVER_HELLO:
279 return "ServerHello";
280 case TLS13_MT_NEW_SESSION_TICKET:
281 return "NewSessionTicket";
282 case TLS13_MT_END_OF_EARLY_DATA:
283 return "EndOfEarlyData";
284 case TLS13_MT_ENCRYPTED_EXTENSIONS:
285 return "EncryptedExtensions";
286 case TLS13_MT_CERTIFICATE:
287 return "Certificate";
288 case TLS13_MT_CERTIFICATE_REQUEST:
289 return "CertificateRequest";
290 case TLS13_MT_CERTIFICATE_VERIFY:
291 return "CertificateVerify";
292 case TLS13_MT_FINISHED:
293 return "Finished";
294 }
295 return "Unknown";
296}
297#endif
298
299static enum tls13_message_type
300tls13_handshake_active_state(struct tls13_ctx *ctx)
301{
302 struct tls13_handshake_stage hs = ctx->handshake_stage;
303
304 if (hs.hs_type >= handshake_count)
305 return INVALID;
306 if (hs.message_number >= TLS13_NUM_MESSAGE_TYPES)
307 return INVALID;
308
309 return handshakes[hs.hs_type][hs.message_number];
310}
311
312static const struct tls13_handshake_action *
313tls13_handshake_active_action(struct tls13_ctx *ctx)
314{
315 enum tls13_message_type mt = tls13_handshake_active_state(ctx);
316
317 if (mt == INVALID)
318 return NULL;
319
320 return &state_machine[mt];
321}
322
323static int
324tls13_handshake_advance_state_machine(struct tls13_ctx *ctx)
325{
326 if (++ctx->handshake_stage.message_number >= TLS13_NUM_MESSAGE_TYPES)
327 return 0;
328
329 return 1;
330}
331
332static int
333tls13_handshake_end_of_flight(struct tls13_ctx *ctx,
334 const struct tls13_handshake_action *previous)
335{
336 const struct tls13_handshake_action *current;
337
338 if ((current = tls13_handshake_active_action(ctx)) == NULL)
339 return 1;
340
341 return current->sender != previous->sender;
342}
343
344int
345tls13_handshake_msg_record(struct tls13_ctx *ctx)
346{
347 CBS cbs;
348
349 tls13_handshake_msg_data(ctx->hs_msg, &cbs);
350 return tls1_transcript_record(ctx->ssl, CBS_data(&cbs), CBS_len(&cbs));
351}
352
353int
354tls13_handshake_perform(struct tls13_ctx *ctx)
355{
356 const struct tls13_handshake_action *action;
357 int sending;
358 int ret;
359
360 if (!ctx->handshake_started) {
361 /*
362 * Set legacy state to connect/accept and call info callback
363 * to signal that the handshake started.
364 */
365 if (!tls13_handshake_set_legacy_state(ctx))
366 return TLS13_IO_FAILURE;
367 if (!tls13_handshake_legacy_info_callback(ctx))
368 return TLS13_IO_FAILURE;
369
370 ctx->handshake_started = 1;
371
372 /* Set legacy state for initial ClientHello read or write. */
373 if (!tls13_handshake_set_legacy_state(ctx))
374 return TLS13_IO_FAILURE;
375 }
376
377 for (;;) {
378 if ((action = tls13_handshake_active_action(ctx)) == NULL)
379 return TLS13_IO_FAILURE;
380
381 if (ctx->need_flush) {
382 if ((ret = tls13_record_layer_flush(ctx->rl)) !=
383 TLS13_IO_SUCCESS)
384 return ret;
385 ctx->need_flush = 0;
386 }
387
388 if (action->handshake_complete) {
389 ctx->handshake_completed = 1;
390 tls13_record_layer_handshake_completed(ctx->rl);
391
392 if (!tls13_handshake_set_legacy_state(ctx))
393 return TLS13_IO_FAILURE;
394 if (!tls13_handshake_legacy_info_callback(ctx))
395 return TLS13_IO_FAILURE;
396
397 return TLS13_IO_SUCCESS;
398 }
399
400 sending = action->sender == ctx->mode;
401
402 DEBUGF("%s %s %s\n", tls13_handshake_mode_name(ctx->mode),
403 sending ? "sending" : "receiving",
404 tls13_handshake_message_name(action->handshake_type));
405
406 if (ctx->alert != 0)
407 return tls13_send_alert(ctx->rl, ctx->alert);
408
409 if (sending)
410 ret = tls13_handshake_send_action(ctx, action);
411 else
412 ret = tls13_handshake_recv_action(ctx, action);
413
414 if (ctx->alert != 0)
415 return tls13_send_alert(ctx->rl, ctx->alert);
416
417 if (ret <= 0) {
418 DEBUGF("%s %s returned %d\n",
419 tls13_handshake_mode_name(ctx->mode),
420 (action->sender == ctx->mode) ? "send" : "recv",
421 ret);
422 return ret;
423 }
424
425 if (!tls13_handshake_legacy_info_callback(ctx))
426 return TLS13_IO_FAILURE;
427
428 if (!tls13_handshake_advance_state_machine(ctx))
429 return TLS13_IO_FAILURE;
430
431 if (sending)
432 ctx->need_flush = tls13_handshake_end_of_flight(ctx,
433 action);
434
435 if (!tls13_handshake_set_legacy_state(ctx))
436 return TLS13_IO_FAILURE;
437 }
438}
439
440static int
441tls13_handshake_send_action(struct tls13_ctx *ctx,
442 const struct tls13_handshake_action *action)
443{
444 ssize_t ret;
445 CBB cbb;
446
447 if (ctx->send_dummy_ccs) {
448 if ((ret = tls13_send_dummy_ccs(ctx->rl)) != TLS13_IO_SUCCESS)
449 return ret;
450 ctx->send_dummy_ccs = 0;
451 if (ctx->send_dummy_ccs_after) {
452 ctx->send_dummy_ccs_after = 0;
453 return TLS13_IO_SUCCESS;
454 }
455 }
456
457 /* If we have no handshake message, we need to build one. */
458 if (ctx->hs_msg == NULL) {
459 if ((ctx->hs_msg = tls13_handshake_msg_new()) == NULL)
460 return TLS13_IO_FAILURE;
461 if (!tls13_handshake_msg_start(ctx->hs_msg, &cbb,
462 action->handshake_type))
463 return TLS13_IO_FAILURE;
464 if (!action->send(ctx, &cbb))
465 return TLS13_IO_FAILURE;
466 if (!tls13_handshake_msg_finish(ctx->hs_msg))
467 return TLS13_IO_FAILURE;
468 }
469
470 if ((ret = tls13_handshake_msg_send(ctx->hs_msg, ctx->rl)) <= 0)
471 return ret;
472
473 if (!tls13_handshake_msg_record(ctx))
474 return TLS13_IO_FAILURE;
475
476 if (action->send_preserve_transcript_hash) {
477 if (!tls1_transcript_hash_value(ctx->ssl,
478 ctx->hs->tls13.transcript_hash,
479 sizeof(ctx->hs->tls13.transcript_hash),
480 &ctx->hs->tls13.transcript_hash_len))
481 return TLS13_IO_FAILURE;
482 }
483
484 if (ctx->handshake_message_sent_cb != NULL)
485 ctx->handshake_message_sent_cb(ctx);
486
487 tls13_handshake_msg_free(ctx->hs_msg);
488 ctx->hs_msg = NULL;
489
490 if (action->sent != NULL && !action->sent(ctx))
491 return TLS13_IO_FAILURE;
492
493 if (ctx->send_dummy_ccs_after) {
494 ctx->send_dummy_ccs = 1;
495 if ((ret = tls13_send_dummy_ccs(ctx->rl)) != TLS13_IO_SUCCESS)
496 return ret;
497 ctx->send_dummy_ccs = 0;
498 ctx->send_dummy_ccs_after = 0;
499 }
500
501 return TLS13_IO_SUCCESS;
502}
503
504static int
505tls13_handshake_recv_action(struct tls13_ctx *ctx,
506 const struct tls13_handshake_action *action)
507{
508 uint8_t msg_type;
509 ssize_t ret;
510 CBS cbs;
511
512 if (ctx->hs_msg == NULL) {
513 if ((ctx->hs_msg = tls13_handshake_msg_new()) == NULL)
514 return TLS13_IO_FAILURE;
515 }
516
517 if ((ret = tls13_handshake_msg_recv(ctx->hs_msg, ctx->rl)) <= 0)
518 return ret;
519
520 if (action->recv_preserve_transcript_hash) {
521 if (!tls1_transcript_hash_value(ctx->ssl,
522 ctx->hs->tls13.transcript_hash,
523 sizeof(ctx->hs->tls13.transcript_hash),
524 &ctx->hs->tls13.transcript_hash_len))
525 return TLS13_IO_FAILURE;
526 }
527
528 if (!tls13_handshake_msg_record(ctx))
529 return TLS13_IO_FAILURE;
530
531 if (ctx->handshake_message_recv_cb != NULL)
532 ctx->handshake_message_recv_cb(ctx);
533
534 /*
535 * In TLSv1.3 there is no way to know if you're going to receive a
536 * certificate request message or not, hence we have to special case it
537 * here. The receive handler also knows how to deal with this situation.
538 */
539 msg_type = tls13_handshake_msg_type(ctx->hs_msg);
540 if (msg_type != action->handshake_type &&
541 (msg_type != TLS13_MT_CERTIFICATE ||
542 action->handshake_type != TLS13_MT_CERTIFICATE_REQUEST))
543 return tls13_send_alert(ctx->rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
544
545 if (!tls13_handshake_msg_content(ctx->hs_msg, &cbs))
546 return TLS13_IO_FAILURE;
547
548 ret = TLS13_IO_FAILURE;
549 if (!action->recv(ctx, &cbs))
550 goto err;
551
552 if (CBS_len(&cbs) != 0) {
553 tls13_set_errorx(ctx, TLS13_ERR_TRAILING_DATA, 0,
554 "trailing data in handshake message", NULL);
555 ctx->alert = TLS13_ALERT_DECODE_ERROR;
556 goto err;
557 }
558
559 ret = TLS13_IO_SUCCESS;
560 if (ctx->ssl->method->version < TLS1_3_VERSION)
561 ret = TLS13_IO_USE_LEGACY;
562
563 err:
564 tls13_handshake_msg_free(ctx->hs_msg);
565 ctx->hs_msg = NULL;
566
567 return ret;
568}
569
570struct tls13_handshake_legacy_state {
571 int recv;
572 int send;
573};
574
575static const struct tls13_handshake_legacy_state legacy_states[] = {
576 [CLIENT_HELLO] = {
577 .recv = SSL3_ST_SR_CLNT_HELLO_A,
578 .send = SSL3_ST_CW_CLNT_HELLO_A,
579 },
580 [SERVER_HELLO_RETRY_REQUEST] = {
581 .recv = SSL3_ST_CR_SRVR_HELLO_A,
582 .send = SSL3_ST_SW_SRVR_HELLO_A,
583 },
584 [CLIENT_HELLO_RETRY] = {
585 .recv = SSL3_ST_SR_CLNT_HELLO_A,
586 .send = SSL3_ST_CW_CLNT_HELLO_A,
587 },
588 [SERVER_HELLO] = {
589 .recv = SSL3_ST_CR_SRVR_HELLO_A,
590 .send = SSL3_ST_SW_SRVR_HELLO_A,
591 },
592 [SERVER_ENCRYPTED_EXTENSIONS] = {
593 .send = 0,
594 .recv = 0,
595 },
596 [SERVER_CERTIFICATE_REQUEST] = {
597 .recv = SSL3_ST_CR_CERT_REQ_A,
598 .send = SSL3_ST_SW_CERT_REQ_A,
599 },
600 [SERVER_CERTIFICATE] = {
601 .recv = SSL3_ST_CR_CERT_A,
602 .send = SSL3_ST_SW_CERT_A,
603 },
604 [SERVER_CERTIFICATE_VERIFY] = {
605 .send = 0,
606 .recv = 0,
607 },
608 [SERVER_FINISHED] = {
609 .recv = SSL3_ST_CR_FINISHED_A,
610 .send = SSL3_ST_SW_FINISHED_A,
611 },
612 [CLIENT_END_OF_EARLY_DATA] = {
613 .send = 0,
614 .recv = 0,
615 },
616 [CLIENT_CERTIFICATE] = {
617 .recv = SSL3_ST_SR_CERT_VRFY_A,
618 .send = SSL3_ST_CW_CERT_VRFY_B,
619 },
620 [CLIENT_CERTIFICATE_VERIFY] = {
621 .send = 0,
622 .recv = 0,
623 },
624 [CLIENT_FINISHED] = {
625 .recv = SSL3_ST_SR_FINISHED_A,
626 .send = SSL3_ST_CW_FINISHED_A,
627 },
628 [APPLICATION_DATA] = {
629 .recv = 0,
630 .send = 0,
631 },
632};
633
634CTASSERT(sizeof(state_machine) / sizeof(state_machine[0]) ==
635 sizeof(legacy_states) / sizeof(legacy_states[0]));
636
637static int
638tls13_handshake_legacy_state(struct tls13_ctx *ctx, int *out_state)
639{
640 const struct tls13_handshake_action *action;
641 enum tls13_message_type mt;
642
643 *out_state = 0;
644
645 if (!ctx->handshake_started) {
646 if (ctx->mode == TLS13_HS_CLIENT)
647 *out_state = SSL_ST_CONNECT;
648 else
649 *out_state = SSL_ST_ACCEPT;
650
651 return 1;
652 }
653
654 if (ctx->handshake_completed) {
655 *out_state = SSL_ST_OK;
656 return 1;
657 }
658
659 if ((mt = tls13_handshake_active_state(ctx)) == INVALID)
660 return 0;
661
662 if ((action = tls13_handshake_active_action(ctx)) == NULL)
663 return 0;
664
665 if (action->sender == ctx->mode)
666 *out_state = legacy_states[mt].send;
667 else
668 *out_state = legacy_states[mt].recv;
669
670 return 1;
671}
672
673static int
674tls13_handshake_info_position(struct tls13_ctx *ctx)
675{
676 if (!ctx->handshake_started)
677 return TLS13_INFO_HANDSHAKE_STARTED;
678
679 if (ctx->handshake_completed)
680 return TLS13_INFO_HANDSHAKE_COMPLETED;
681
682 if (ctx->mode == TLS13_HS_CLIENT)
683 return TLS13_INFO_CONNECT_LOOP;
684 else
685 return TLS13_INFO_ACCEPT_LOOP;
686}
687
688static int
689tls13_handshake_legacy_info_callback(struct tls13_ctx *ctx)
690{
691 int state, where;
692
693 if (!tls13_handshake_legacy_state(ctx, &state))
694 return 0;
695
696 /* Do nothing if there's no corresponding legacy state. */
697 if (state == 0)
698 return 1;
699
700 if (ctx->info_cb != NULL) {
701 where = tls13_handshake_info_position(ctx);
702 ctx->info_cb(ctx, where, 1);
703 }
704
705 return 1;
706}
707
708static int
709tls13_handshake_set_legacy_state(struct tls13_ctx *ctx)
710{
711 int state;
712
713 if (!tls13_handshake_legacy_state(ctx, &state))
714 return 0;
715
716 /* Do nothing if there's no corresponding legacy state. */
717 if (state == 0)
718 return 1;
719
720 ctx->hs->state = state;
721
722 return 1;
723}
diff --git a/src/lib/libssl/tls13_handshake.h b/src/lib/libssl/tls13_handshake.h
deleted file mode 100644
index 8a08b9fd5b..0000000000
--- a/src/lib/libssl/tls13_handshake.h
+++ /dev/null
@@ -1,54 +0,0 @@
1/* $OpenBSD: tls13_handshake.h,v 1.5 2020/04/22 17:05:07 jsing Exp $ */
2/*
3 * Copyright (c) 2019 Theo Buehler <tb@openbsd.org>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef HEADER_TLS13_HANDSHAKE_H
19#define HEADER_TLS13_HANDSHAKE_H
20
21#include <stddef.h> /* for NULL */
22
23__BEGIN_HIDDEN_DECLS
24
25#define INITIAL 0x00
26#define NEGOTIATED 0x01
27#define WITHOUT_HRR 0x02
28#define WITHOUT_CR 0x04
29#define WITH_PSK 0x08
30#define WITH_CCV 0x10
31#define WITH_0RTT 0x20
32
33enum tls13_message_type {
34 INVALID,
35 CLIENT_HELLO,
36 SERVER_HELLO_RETRY_REQUEST,
37 CLIENT_HELLO_RETRY,
38 SERVER_HELLO,
39 SERVER_ENCRYPTED_EXTENSIONS,
40 SERVER_CERTIFICATE_REQUEST,
41 SERVER_CERTIFICATE,
42 SERVER_CERTIFICATE_VERIFY,
43 SERVER_FINISHED,
44 CLIENT_END_OF_EARLY_DATA,
45 CLIENT_CERTIFICATE,
46 CLIENT_CERTIFICATE_VERIFY,
47 CLIENT_FINISHED,
48 APPLICATION_DATA,
49 TLS13_NUM_MESSAGE_TYPES,
50};
51
52__END_HIDDEN_DECLS
53
54#endif /* !HEADER_TLS13_HANDSHAKE_H */
diff --git a/src/lib/libssl/tls13_handshake_msg.c b/src/lib/libssl/tls13_handshake_msg.c
deleted file mode 100644
index c7f4d7b7ec..0000000000
--- a/src/lib/libssl/tls13_handshake_msg.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/* $OpenBSD: tls13_handshake_msg.c,v 1.7 2024/02/04 20:50:23 tb Exp $ */
2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "bytestring.h"
19#include "tls13_internal.h"
20
21#define TLS13_HANDSHAKE_MSG_HEADER_LEN 4
22#define TLS13_HANDSHAKE_MSG_INITIAL_LEN 256
23#define TLS13_HANDSHAKE_MSG_MAX_LEN (256 * 1024)
24
25struct tls13_handshake_msg {
26 uint8_t msg_type;
27 uint32_t msg_len;
28 uint8_t *data;
29 size_t data_len;
30
31 struct tls_buffer *buf;
32 CBS cbs;
33 CBB cbb;
34};
35
36struct tls13_handshake_msg *
37tls13_handshake_msg_new(void)
38{
39 struct tls13_handshake_msg *msg = NULL;
40
41 if ((msg = calloc(1, sizeof(struct tls13_handshake_msg))) == NULL)
42 goto err;
43 if ((msg->buf = tls_buffer_new(0)) == NULL)
44 goto err;
45
46 return msg;
47
48 err:
49 tls13_handshake_msg_free(msg);
50
51 return NULL;
52}
53
54void
55tls13_handshake_msg_free(struct tls13_handshake_msg *msg)
56{
57 if (msg == NULL)
58 return;
59
60 tls_buffer_free(msg->buf);
61
62 CBB_cleanup(&msg->cbb);
63
64 freezero(msg->data, msg->data_len);
65 freezero(msg, sizeof(struct tls13_handshake_msg));
66}
67
68void
69tls13_handshake_msg_data(struct tls13_handshake_msg *msg, CBS *cbs)
70{
71 CBS_init(cbs, msg->data, msg->data_len);
72}
73
74uint8_t
75tls13_handshake_msg_type(struct tls13_handshake_msg *msg)
76{
77 return msg->msg_type;
78}
79
80int
81tls13_handshake_msg_content(struct tls13_handshake_msg *msg, CBS *cbs)
82{
83 tls13_handshake_msg_data(msg, cbs);
84
85 return CBS_skip(cbs, TLS13_HANDSHAKE_MSG_HEADER_LEN);
86}
87
88int
89tls13_handshake_msg_start(struct tls13_handshake_msg *msg, CBB *body,
90 uint8_t msg_type)
91{
92 if (!CBB_init(&msg->cbb, TLS13_HANDSHAKE_MSG_INITIAL_LEN))
93 return 0;
94 if (!CBB_add_u8(&msg->cbb, msg_type))
95 return 0;
96 if (!CBB_add_u24_length_prefixed(&msg->cbb, body))
97 return 0;
98
99 return 1;
100}
101
102int
103tls13_handshake_msg_finish(struct tls13_handshake_msg *msg)
104{
105 if (!CBB_finish(&msg->cbb, &msg->data, &msg->data_len))
106 return 0;
107
108 CBS_init(&msg->cbs, msg->data, msg->data_len);
109
110 return 1;
111}
112
113static ssize_t
114tls13_handshake_msg_read_cb(void *buf, size_t n, void *cb_arg)
115{
116 struct tls13_record_layer *rl = cb_arg;
117
118 return tls13_read_handshake_data(rl, buf, n);
119}
120
121int
122tls13_handshake_msg_recv(struct tls13_handshake_msg *msg,
123 struct tls13_record_layer *rl)
124{
125 uint8_t msg_type;
126 uint32_t msg_len;
127 CBS cbs;
128 int ret;
129
130 if (msg->data != NULL)
131 return TLS13_IO_FAILURE;
132
133 if (msg->msg_type == 0) {
134 if ((ret = tls_buffer_extend(msg->buf,
135 TLS13_HANDSHAKE_MSG_HEADER_LEN,
136 tls13_handshake_msg_read_cb, rl)) <= 0)
137 return ret;
138
139 if (!tls_buffer_data(msg->buf, &cbs))
140 return TLS13_IO_FAILURE;
141
142 if (!CBS_get_u8(&cbs, &msg_type))
143 return TLS13_IO_FAILURE;
144 if (!CBS_get_u24(&cbs, &msg_len))
145 return TLS13_IO_FAILURE;
146
147 /* XXX - do we want to make this variable on message type? */
148 if (msg_len > TLS13_HANDSHAKE_MSG_MAX_LEN)
149 return TLS13_IO_FAILURE;
150
151 msg->msg_type = msg_type;
152 msg->msg_len = msg_len;
153 }
154
155 if ((ret = tls_buffer_extend(msg->buf,
156 TLS13_HANDSHAKE_MSG_HEADER_LEN + msg->msg_len,
157 tls13_handshake_msg_read_cb, rl)) <= 0)
158 return ret;
159
160 if (!tls_buffer_finish(msg->buf, &msg->data, &msg->data_len))
161 return TLS13_IO_FAILURE;
162
163 return TLS13_IO_SUCCESS;
164}
165
166int
167tls13_handshake_msg_send(struct tls13_handshake_msg *msg,
168 struct tls13_record_layer *rl)
169{
170 ssize_t ret;
171
172 if (msg->data == NULL)
173 return TLS13_IO_FAILURE;
174
175 if (CBS_len(&msg->cbs) == 0)
176 return TLS13_IO_FAILURE;
177
178 while (CBS_len(&msg->cbs) > 0) {
179 if ((ret = tls13_write_handshake_data(rl, CBS_data(&msg->cbs),
180 CBS_len(&msg->cbs))) <= 0)
181 return ret;
182
183 if (!CBS_skip(&msg->cbs, ret))
184 return TLS13_IO_FAILURE;
185 }
186
187 return TLS13_IO_SUCCESS;
188}
diff --git a/src/lib/libssl/tls13_internal.h b/src/lib/libssl/tls13_internal.h
deleted file mode 100644
index 7a7f8abc63..0000000000
--- a/src/lib/libssl/tls13_internal.h
+++ /dev/null
@@ -1,447 +0,0 @@
1/* $OpenBSD: tls13_internal.h,v 1.105 2025/03/09 15:12:18 tb Exp $ */
2/*
3 * Copyright (c) 2018 Bob Beck <beck@openbsd.org>
4 * Copyright (c) 2018 Theo Buehler <tb@openbsd.org>
5 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
14 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
16 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
17 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#ifndef HEADER_TLS13_INTERNAL_H
21#define HEADER_TLS13_INTERNAL_H
22
23#include <openssl/evp.h>
24#include <openssl/ssl.h>
25
26#include "bytestring.h"
27#include "tls_internal.h"
28
29__BEGIN_HIDDEN_DECLS
30
31#define TLS13_HS_CLIENT 1
32#define TLS13_HS_SERVER 2
33
34#define TLS13_IO_SUCCESS 1
35#define TLS13_IO_EOF 0
36#define TLS13_IO_FAILURE -1
37#define TLS13_IO_ALERT -2
38#define TLS13_IO_WANT_POLLIN -3
39#define TLS13_IO_WANT_POLLOUT -4
40#define TLS13_IO_WANT_RETRY -5 /* Retry the previous call immediately. */
41#define TLS13_IO_USE_LEGACY -6
42#define TLS13_IO_RECORD_VERSION -7
43#define TLS13_IO_RECORD_OVERFLOW -8
44
45#define TLS13_ERR_VERIFY_FAILED 16
46#define TLS13_ERR_HRR_FAILED 17
47#define TLS13_ERR_TRAILING_DATA 18
48#define TLS13_ERR_NO_SHARED_CIPHER 19
49#define TLS13_ERR_NO_CERTIFICATE 20
50#define TLS13_ERR_NO_PEER_CERTIFICATE 21
51
52#define TLS13_ALERT_LEVEL_WARNING 1
53#define TLS13_ALERT_LEVEL_FATAL 2
54
55#define TLS13_ALERT_CLOSE_NOTIFY 0
56#define TLS13_ALERT_UNEXPECTED_MESSAGE 10
57#define TLS13_ALERT_BAD_RECORD_MAC 20
58#define TLS13_ALERT_RECORD_OVERFLOW 22
59#define TLS13_ALERT_HANDSHAKE_FAILURE 40
60#define TLS13_ALERT_BAD_CERTIFICATE 42
61#define TLS13_ALERT_UNSUPPORTED_CERTIFICATE 43
62#define TLS13_ALERT_CERTIFICATE_REVOKED 44
63#define TLS13_ALERT_CERTIFICATE_EXPIRED 45
64#define TLS13_ALERT_CERTIFICATE_UNKNOWN 46
65#define TLS13_ALERT_ILLEGAL_PARAMETER 47
66#define TLS13_ALERT_UNKNOWN_CA 48
67#define TLS13_ALERT_ACCESS_DENIED 49
68#define TLS13_ALERT_DECODE_ERROR 50
69#define TLS13_ALERT_DECRYPT_ERROR 51
70#define TLS13_ALERT_PROTOCOL_VERSION 70
71#define TLS13_ALERT_INSUFFICIENT_SECURITY 71
72#define TLS13_ALERT_INTERNAL_ERROR 80
73#define TLS13_ALERT_INAPPROPRIATE_FALLBACK 86
74#define TLS13_ALERT_USER_CANCELED 90
75#define TLS13_ALERT_MISSING_EXTENSION 109
76#define TLS13_ALERT_UNSUPPORTED_EXTENSION 110
77#define TLS13_ALERT_UNRECOGNIZED_NAME 112
78#define TLS13_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE 113
79#define TLS13_ALERT_UNKNOWN_PSK_IDENTITY 115
80#define TLS13_ALERT_CERTIFICATE_REQUIRED 116
81#define TLS13_ALERT_NO_APPLICATION_PROTOCOL 120
82
83#define TLS13_INFO_HANDSHAKE_STARTED SSL_CB_HANDSHAKE_START
84#define TLS13_INFO_HANDSHAKE_COMPLETED SSL_CB_HANDSHAKE_DONE
85#define TLS13_INFO_ACCEPT_LOOP SSL_CB_ACCEPT_LOOP
86#define TLS13_INFO_CONNECT_LOOP SSL_CB_CONNECT_LOOP
87#define TLS13_INFO_ACCEPT_EXIT SSL_CB_ACCEPT_EXIT
88#define TLS13_INFO_CONNECT_EXIT SSL_CB_CONNECT_EXIT
89
90typedef void (*tls13_alert_cb)(uint8_t _alert_level, uint8_t _alert_desc,
91 void *_cb_arg);
92typedef ssize_t (*tls13_phh_recv_cb)(void *_cb_arg);
93typedef void (*tls13_phh_sent_cb)(void *_cb_arg);
94typedef void (*tls13_handshake_message_cb)(void *_cb_arg);
95typedef void (*tls13_info_cb)(void *_cb_arg, int _state, int _ret);
96typedef int (*tls13_ocsp_status_cb)(void *_cb_arg);
97
98/*
99 * PSK support.
100 */
101
102/*
103 * Known PskKeyExchangeMode values.
104 * https://www.iana.org/assignments/tls-parameters/#tls-pskkeyexchangemode
105 */
106#define TLS13_PSK_KE 0
107#define TLS13_PSK_DHE_KE 1
108
109/*
110 * Secrets.
111 */
112struct tls13_secret {
113 uint8_t *data;
114 size_t len;
115};
116
117/* RFC 8446 Section 7.1 Page 92 */
118struct tls13_secrets {
119 const EVP_MD *digest;
120 int resumption;
121 int init_done;
122 int early_done;
123 int handshake_done;
124 int schedule_done;
125 int insecure; /* Set by tests */
126 struct tls13_secret zeros;
127 struct tls13_secret empty_hash;
128 struct tls13_secret extracted_early;
129 struct tls13_secret binder_key;
130 struct tls13_secret client_early_traffic;
131 struct tls13_secret early_exporter_master;
132 struct tls13_secret derived_early;
133 struct tls13_secret extracted_handshake;
134 struct tls13_secret client_handshake_traffic;
135 struct tls13_secret server_handshake_traffic;
136 struct tls13_secret derived_handshake;
137 struct tls13_secret extracted_master;
138 struct tls13_secret client_application_traffic;
139 struct tls13_secret server_application_traffic;
140 struct tls13_secret exporter_master;
141 struct tls13_secret resumption_master;
142};
143
144int tls13_secret_init(struct tls13_secret *secret, size_t len);
145void tls13_secret_cleanup(struct tls13_secret *secret);
146struct tls13_secrets *tls13_secrets_create(const EVP_MD *digest,
147 int resumption);
148void tls13_secrets_destroy(struct tls13_secrets *secrets);
149
150int tls13_hkdf_expand_label(struct tls13_secret *out, const EVP_MD *digest,
151 const struct tls13_secret *secret, const char *label,
152 const struct tls13_secret *context);
153int tls13_hkdf_expand_label_with_length(struct tls13_secret *out,
154 const EVP_MD *digest, const struct tls13_secret *secret,
155 const uint8_t *label, size_t label_len, const struct tls13_secret *context);
156
157int tls13_derive_secret(struct tls13_secret *out, const EVP_MD *digest,
158 const struct tls13_secret *secret, const char *label,
159 const struct tls13_secret *context);
160int tls13_derive_secret_with_label_length(struct tls13_secret *out,
161 const EVP_MD *digest, const struct tls13_secret *secret,
162 const uint8_t *label, size_t label_len, const struct tls13_secret *context);
163
164int tls13_derive_early_secrets(struct tls13_secrets *secrets, uint8_t *psk,
165 size_t psk_len, const struct tls13_secret *context);
166int tls13_derive_handshake_secrets(struct tls13_secrets *secrets,
167 const uint8_t *ecdhe, size_t ecdhe_len, const struct tls13_secret *context);
168int tls13_derive_application_secrets(struct tls13_secrets *secrets,
169 const struct tls13_secret *context);
170int tls13_update_client_traffic_secret(struct tls13_secrets *secrets);
171int tls13_update_server_traffic_secret(struct tls13_secrets *secrets);
172
173/*
174 * Record Layer.
175 */
176struct tls13_record_layer;
177
178struct tls13_record_layer_callbacks {
179 /* Wire callbacks. */
180 tls_read_cb wire_read;
181 tls_write_cb wire_write;
182 tls_flush_cb wire_flush;
183
184 /* Interceptors. */
185 tls_handshake_read_cb handshake_read;
186 tls_handshake_write_cb handshake_write;
187 tls_traffic_key_cb set_read_traffic_key;
188 tls_traffic_key_cb set_write_traffic_key;
189 tls_alert_send_cb alert_send;
190
191 /* Notification callbacks. */
192 tls13_alert_cb alert_recv;
193 tls13_alert_cb alert_sent;
194 tls13_phh_recv_cb phh_recv;
195 tls13_phh_sent_cb phh_sent;
196};
197
198struct tls13_record_layer *tls13_record_layer_new(
199 const struct tls13_record_layer_callbacks *callbacks, void *cb_arg);
200void tls13_record_layer_free(struct tls13_record_layer *rl);
201void tls13_record_layer_set_callbacks(struct tls13_record_layer *rl,
202 const struct tls13_record_layer_callbacks *callbacks, void *cb_arg);
203void tls13_record_layer_allow_ccs(struct tls13_record_layer *rl, int allow);
204void tls13_record_layer_allow_legacy_alerts(struct tls13_record_layer *rl, int allow);
205void tls13_record_layer_rcontent(struct tls13_record_layer *rl, CBS *cbs);
206void tls13_record_layer_set_aead(struct tls13_record_layer *rl,
207 const EVP_AEAD *aead);
208void tls13_record_layer_set_hash(struct tls13_record_layer *rl,
209 const EVP_MD *hash);
210void tls13_record_layer_set_legacy_version(struct tls13_record_layer *rl,
211 uint16_t version);
212void tls13_record_layer_set_retry_after_phh(struct tls13_record_layer *rl, int retry);
213void tls13_record_layer_alert_sent(struct tls13_record_layer *rl,
214 uint8_t alert_level, uint8_t alert_desc);
215void tls13_record_layer_handshake_completed(struct tls13_record_layer *rl);
216int tls13_record_layer_set_read_traffic_key(struct tls13_record_layer *rl,
217 struct tls13_secret *read_key, enum ssl_encryption_level_t read_level);
218int tls13_record_layer_set_write_traffic_key(struct tls13_record_layer *rl,
219 struct tls13_secret *write_key, enum ssl_encryption_level_t write_level);
220ssize_t tls13_record_layer_send_pending(struct tls13_record_layer *rl);
221ssize_t tls13_record_layer_phh(struct tls13_record_layer *rl, CBS *cbs);
222ssize_t tls13_record_layer_flush(struct tls13_record_layer *rl);
223
224ssize_t tls13_read_handshake_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n);
225ssize_t tls13_write_handshake_data(struct tls13_record_layer *rl, const uint8_t *buf,
226 size_t n);
227ssize_t tls13_pending_application_data(struct tls13_record_layer *rl);
228ssize_t tls13_peek_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n);
229ssize_t tls13_read_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n);
230ssize_t tls13_write_application_data(struct tls13_record_layer *rl, const uint8_t *buf,
231 size_t n);
232
233ssize_t tls13_send_alert(struct tls13_record_layer *rl, uint8_t alert_desc);
234ssize_t tls13_send_dummy_ccs(struct tls13_record_layer *rl);
235
236/*
237 * Handshake Messages.
238 */
239struct tls13_handshake_msg;
240
241struct tls13_handshake_msg *tls13_handshake_msg_new(void);
242void tls13_handshake_msg_free(struct tls13_handshake_msg *msg);
243void tls13_handshake_msg_data(struct tls13_handshake_msg *msg, CBS *cbs);
244uint8_t tls13_handshake_msg_type(struct tls13_handshake_msg *msg);
245int tls13_handshake_msg_content(struct tls13_handshake_msg *msg, CBS *cbs);
246int tls13_handshake_msg_start(struct tls13_handshake_msg *msg, CBB *body,
247 uint8_t msg_type);
248int tls13_handshake_msg_finish(struct tls13_handshake_msg *msg);
249int tls13_handshake_msg_recv(struct tls13_handshake_msg *msg,
250 struct tls13_record_layer *rl);
251int tls13_handshake_msg_send(struct tls13_handshake_msg *msg,
252 struct tls13_record_layer *rl);
253
254struct tls13_handshake_stage {
255 uint8_t hs_type;
256 uint8_t message_number;
257};
258
259struct ssl_handshake_tls13_st;
260
261struct tls13_error {
262 int code;
263 int subcode;
264 int errnum;
265 const char *file;
266 int line;
267 char *msg;
268};
269
270struct tls13_ctx {
271 struct tls13_error error;
272
273 SSL *ssl;
274 struct ssl_handshake_st *hs;
275 uint8_t mode;
276 struct tls13_handshake_stage handshake_stage;
277 int handshake_started;
278 int handshake_completed;
279 int need_flush;
280 int middlebox_compat;
281 int send_dummy_ccs;
282 int send_dummy_ccs_after;
283
284 int close_notify_sent;
285 int close_notify_recv;
286
287 const EVP_AEAD *aead;
288 const EVP_MD *hash;
289
290 struct tls13_record_layer *rl;
291 struct tls13_handshake_msg *hs_msg;
292 uint8_t key_update_request;
293 uint8_t alert;
294 int phh_count;
295 time_t phh_last_seen;
296
297 tls13_alert_cb alert_sent_cb;
298 tls13_alert_cb alert_recv_cb;
299 tls13_handshake_message_cb handshake_message_sent_cb;
300 tls13_handshake_message_cb handshake_message_recv_cb;
301 tls13_info_cb info_cb;
302 tls13_ocsp_status_cb ocsp_status_recv_cb;
303};
304#ifndef TLS13_PHH_LIMIT_TIME
305#define TLS13_PHH_LIMIT_TIME 3600
306#endif
307#ifndef TLS13_PHH_LIMIT
308#define TLS13_PHH_LIMIT 100
309#endif
310
311struct tls13_ctx *tls13_ctx_new(int mode, SSL *ssl);
312void tls13_ctx_free(struct tls13_ctx *ctx);
313
314const EVP_AEAD *tls13_cipher_aead(const SSL_CIPHER *cipher);
315const EVP_MD *tls13_cipher_hash(const SSL_CIPHER *cipher);
316
317void tls13_alert_received_cb(uint8_t alert_level, uint8_t alert_desc, void *arg);
318void tls13_alert_sent_cb(uint8_t alert_level, uint8_t alert_desc, void *arg);
319ssize_t tls13_phh_received_cb(void *cb_arg);
320void tls13_phh_done_cb(void *cb_arg);
321
322int tls13_quic_init(struct tls13_ctx *ctx);
323
324/*
325 * Legacy interfaces.
326 */
327int tls13_use_legacy_client(struct tls13_ctx *ctx);
328int tls13_use_legacy_server(struct tls13_ctx *ctx);
329int tls13_legacy_accept(SSL *ssl);
330int tls13_legacy_connect(SSL *ssl);
331ssize_t tls13_legacy_wire_read_cb(void *buf, size_t n, void *arg);
332ssize_t tls13_legacy_wire_write_cb(const void *buf, size_t n, void *arg);
333ssize_t tls13_legacy_wire_flush_cb(void *arg);
334int tls13_legacy_pending(const SSL *ssl);
335int tls13_legacy_read_bytes(SSL *ssl, int type, unsigned char *buf, int len,
336 int peek);
337int tls13_legacy_write_bytes(SSL *ssl, int type, const void *buf, int len);
338int tls13_legacy_shutdown(SSL *ssl);
339int tls13_legacy_servername_process(struct tls13_ctx *ctx, uint8_t *alert);
340
341/*
342 * Message Types - RFC 8446, Section B.3.
343 *
344 * Values listed as "_RESERVED" were used in previous versions of TLS and are
345 * listed here for completeness. TLS 1.3 implementations MUST NOT send them but
346 * might receive them from older TLS implementations.
347 */
348#define TLS13_MT_HELLO_REQUEST_RESERVED 0
349#define TLS13_MT_CLIENT_HELLO 1
350#define TLS13_MT_SERVER_HELLO 2
351#define TLS13_MT_HELLO_VERIFY_REQUEST_RESERVED 3
352#define TLS13_MT_NEW_SESSION_TICKET 4
353#define TLS13_MT_END_OF_EARLY_DATA 5
354#define TLS13_MT_HELLO_RETRY_REQUEST_RESERVED 6
355#define TLS13_MT_ENCRYPTED_EXTENSIONS 8
356#define TLS13_MT_CERTIFICATE 11
357#define TLS13_MT_SERVER_KEY_EXCHANGE_RESERVED 12
358#define TLS13_MT_CERTIFICATE_REQUEST 13
359#define TLS13_MT_SERVER_HELLO_DONE_RESERVED 14
360#define TLS13_MT_CERTIFICATE_VERIFY 15
361#define TLS13_MT_CLIENT_KEY_EXCHANGE_RESERVED 16
362#define TLS13_MT_FINISHED 20
363#define TLS13_MT_CERTIFICATE_URL_RESERVED 21
364#define TLS13_MT_CERTIFICATE_STATUS_RESERVED 22
365#define TLS13_MT_SUPPLEMENTAL_DATA_RESERVED 23
366#define TLS13_MT_KEY_UPDATE 24
367#define TLS13_MT_MESSAGE_HASH 254
368
369int tls13_handshake_msg_record(struct tls13_ctx *ctx);
370int tls13_handshake_perform(struct tls13_ctx *ctx);
371
372int tls13_client_init(struct tls13_ctx *ctx);
373int tls13_server_init(struct tls13_ctx *ctx);
374int tls13_client_connect(struct tls13_ctx *ctx);
375int tls13_server_accept(struct tls13_ctx *ctx);
376
377int tls13_client_hello_send(struct tls13_ctx *ctx, CBB *cbb);
378int tls13_client_hello_sent(struct tls13_ctx *ctx);
379int tls13_client_hello_recv(struct tls13_ctx *ctx, CBS *cbs);
380int tls13_client_hello_retry_send(struct tls13_ctx *ctx, CBB *cbb);
381int tls13_client_hello_retry_recv(struct tls13_ctx *ctx, CBS *cbs);
382int tls13_client_end_of_early_data_send(struct tls13_ctx *ctx, CBB *cbb);
383int tls13_client_end_of_early_data_recv(struct tls13_ctx *ctx, CBS *cbs);
384int tls13_client_certificate_send(struct tls13_ctx *ctx, CBB *cbb);
385int tls13_client_certificate_recv(struct tls13_ctx *ctx, CBS *cbs);
386int tls13_client_certificate_verify_send(struct tls13_ctx *ctx, CBB *cbb);
387int tls13_client_certificate_verify_recv(struct tls13_ctx *ctx, CBS *cbs);
388int tls13_client_finished_recv(struct tls13_ctx *ctx, CBS *cbs);
389int tls13_client_finished_send(struct tls13_ctx *ctx, CBB *cbb);
390int tls13_client_finished_sent(struct tls13_ctx *ctx);
391int tls13_server_hello_recv(struct tls13_ctx *ctx, CBS *cbs);
392int tls13_server_hello_send(struct tls13_ctx *ctx, CBB *cbb);
393int tls13_server_hello_sent(struct tls13_ctx *ctx);
394int tls13_server_hello_retry_request_recv(struct tls13_ctx *ctx, CBS *cbs);
395int tls13_server_hello_retry_request_send(struct tls13_ctx *ctx, CBB *cbb);
396int tls13_server_hello_retry_request_sent(struct tls13_ctx *ctx);
397int tls13_server_encrypted_extensions_recv(struct tls13_ctx *ctx, CBS *cbs);
398int tls13_server_encrypted_extensions_send(struct tls13_ctx *ctx, CBB *cbb);
399int tls13_server_certificate_recv(struct tls13_ctx *ctx, CBS *cbs);
400int tls13_server_certificate_send(struct tls13_ctx *ctx, CBB *cbb);
401int tls13_server_certificate_request_recv(struct tls13_ctx *ctx, CBS *cbs);
402int tls13_server_certificate_request_send(struct tls13_ctx *ctx, CBB *cbb);
403int tls13_server_certificate_verify_send(struct tls13_ctx *ctx, CBB *cbb);
404int tls13_server_certificate_verify_recv(struct tls13_ctx *ctx, CBS *cbs);
405int tls13_server_finished_recv(struct tls13_ctx *ctx, CBS *cbs);
406int tls13_server_finished_send(struct tls13_ctx *ctx, CBB *cbb);
407int tls13_server_finished_sent(struct tls13_ctx *ctx);
408
409void tls13_error_clear(struct tls13_error *error);
410int tls13_cert_add(struct tls13_ctx *ctx, CBB *cbb, X509 *cert,
411 int(*build_extensions)(SSL *s, uint16_t msg_type, CBB *cbb));
412
413int tls13_synthetic_handshake_message(struct tls13_ctx *ctx);
414int tls13_clienthello_hash_init(struct tls13_ctx *ctx);
415void tls13_clienthello_hash_clear(struct ssl_handshake_tls13_st *hs);
416int tls13_clienthello_hash_update_bytes(struct tls13_ctx *ctx, void *data,
417 size_t len);
418int tls13_clienthello_hash_update(struct tls13_ctx *ctx, CBS *cbs);
419int tls13_clienthello_hash_finalize(struct tls13_ctx *ctx);
420int tls13_clienthello_hash_validate(struct tls13_ctx *ctx);
421
422int tls13_error_set(struct tls13_error *error, int code, int subcode,
423 const char *file, int line, const char *fmt, ...);
424int tls13_error_setx(struct tls13_error *error, int code, int subcode,
425 const char *file, int line, const char *fmt, ...);
426
427#define tls13_set_error(ctx, code, subcode, fmt, ...) \
428 tls13_error_set(&(ctx)->error, (code), (subcode), OPENSSL_FILE, OPENSSL_LINE, \
429 (fmt), __VA_ARGS__)
430#define tls13_set_errorx(ctx, code, subcode, fmt, ...) \
431 tls13_error_setx(&(ctx)->error, (code), (subcode), OPENSSL_FILE, OPENSSL_LINE, \
432 (fmt), __VA_ARGS__)
433
434int tls13_exporter(struct tls13_ctx *ctx, const uint8_t *label, size_t label_len,
435 const uint8_t *context_value, size_t context_value_len, uint8_t *out,
436 size_t out_len);
437
438extern const uint8_t tls13_downgrade_12[8];
439extern const uint8_t tls13_downgrade_11[8];
440extern const uint8_t tls13_hello_retry_request_hash[32];
441extern const uint8_t tls13_cert_verify_pad[64];
442extern const uint8_t tls13_cert_client_verify_context[];
443extern const uint8_t tls13_cert_server_verify_context[];
444
445__END_HIDDEN_DECLS
446
447#endif
diff --git a/src/lib/libssl/tls13_key_schedule.c b/src/lib/libssl/tls13_key_schedule.c
deleted file mode 100644
index 05bcf0f006..0000000000
--- a/src/lib/libssl/tls13_key_schedule.c
+++ /dev/null
@@ -1,458 +0,0 @@
1/* $OpenBSD: tls13_key_schedule.c,v 1.18 2022/11/26 16:08:56 tb Exp $ */
2/*
3 * Copyright (c) 2018, Bob Beck <beck@openbsd.org>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
12 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
14 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
15 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <string.h>
19#include <stdlib.h>
20
21#include <openssl/hkdf.h>
22
23#include "bytestring.h"
24#include "ssl_local.h"
25#include "tls13_internal.h"
26
27int
28tls13_secret_init(struct tls13_secret *secret, size_t len)
29{
30 if (secret->data != NULL)
31 return 0;
32
33 if ((secret->data = calloc(1, len)) == NULL)
34 return 0;
35 secret->len = len;
36
37 return 1;
38}
39
40void
41tls13_secret_cleanup(struct tls13_secret *secret)
42{
43 freezero(secret->data, secret->len);
44 secret->data = NULL;
45 secret->len = 0;
46}
47
48/*
49 * Allocate a set of secrets for a key schedule using
50 * a size of hash_length from RFC 8446 section 7.1.
51 */
52struct tls13_secrets *
53tls13_secrets_create(const EVP_MD *digest, int resumption)
54{
55 struct tls13_secrets *secrets = NULL;
56 EVP_MD_CTX *mdctx = NULL;
57 unsigned int mdlen;
58 size_t hash_length;
59
60 hash_length = EVP_MD_size(digest);
61
62 if ((secrets = calloc(1, sizeof(struct tls13_secrets))) == NULL)
63 goto err;
64
65 if (!tls13_secret_init(&secrets->zeros, hash_length))
66 goto err;
67 if (!tls13_secret_init(&secrets->empty_hash, hash_length))
68 goto err;
69
70 if (!tls13_secret_init(&secrets->extracted_early, hash_length))
71 goto err;
72 if (!tls13_secret_init(&secrets->binder_key, hash_length))
73 goto err;
74 if (!tls13_secret_init(&secrets->client_early_traffic, hash_length))
75 goto err;
76 if (!tls13_secret_init(&secrets->early_exporter_master, hash_length))
77 goto err;
78 if (!tls13_secret_init(&secrets->derived_early, hash_length))
79 goto err;
80 if (!tls13_secret_init(&secrets->extracted_handshake, hash_length))
81 goto err;
82 if (!tls13_secret_init(&secrets->client_handshake_traffic, hash_length))
83 goto err;
84 if (!tls13_secret_init(&secrets->server_handshake_traffic, hash_length))
85 goto err;
86 if (!tls13_secret_init(&secrets->derived_handshake, hash_length))
87 goto err;
88 if (!tls13_secret_init(&secrets->extracted_master, hash_length))
89 goto err;
90 if (!tls13_secret_init(&secrets->client_application_traffic, hash_length))
91 goto err;
92 if (!tls13_secret_init(&secrets->server_application_traffic, hash_length))
93 goto err;
94 if (!tls13_secret_init(&secrets->exporter_master, hash_length))
95 goto err;
96 if (!tls13_secret_init(&secrets->resumption_master, hash_length))
97 goto err;
98
99 /*
100 * Calculate the hash of a zero-length string - this is needed during
101 * the "derived" step for key extraction.
102 */
103 if ((mdctx = EVP_MD_CTX_new()) == NULL)
104 goto err;
105 if (!EVP_DigestInit_ex(mdctx, digest, NULL))
106 goto err;
107 if (!EVP_DigestUpdate(mdctx, secrets->zeros.data, 0))
108 goto err;
109 if (!EVP_DigestFinal_ex(mdctx, secrets->empty_hash.data, &mdlen))
110 goto err;
111 EVP_MD_CTX_free(mdctx);
112 mdctx = NULL;
113
114 if (secrets->empty_hash.len != mdlen)
115 goto err;
116
117 secrets->digest = digest;
118 secrets->resumption = resumption;
119 secrets->init_done = 1;
120
121 return secrets;
122
123 err:
124 tls13_secrets_destroy(secrets);
125 EVP_MD_CTX_free(mdctx);
126
127 return NULL;
128}
129
130void
131tls13_secrets_destroy(struct tls13_secrets *secrets)
132{
133 if (secrets == NULL)
134 return;
135
136 /* you can never be too sure :) */
137 tls13_secret_cleanup(&secrets->zeros);
138 tls13_secret_cleanup(&secrets->empty_hash);
139
140 tls13_secret_cleanup(&secrets->extracted_early);
141 tls13_secret_cleanup(&secrets->binder_key);
142 tls13_secret_cleanup(&secrets->client_early_traffic);
143 tls13_secret_cleanup(&secrets->early_exporter_master);
144 tls13_secret_cleanup(&secrets->derived_early);
145 tls13_secret_cleanup(&secrets->extracted_handshake);
146 tls13_secret_cleanup(&secrets->client_handshake_traffic);
147 tls13_secret_cleanup(&secrets->server_handshake_traffic);
148 tls13_secret_cleanup(&secrets->derived_handshake);
149 tls13_secret_cleanup(&secrets->extracted_master);
150 tls13_secret_cleanup(&secrets->client_application_traffic);
151 tls13_secret_cleanup(&secrets->server_application_traffic);
152 tls13_secret_cleanup(&secrets->exporter_master);
153 tls13_secret_cleanup(&secrets->resumption_master);
154
155 freezero(secrets, sizeof(struct tls13_secrets));
156}
157
158int
159tls13_hkdf_expand_label(struct tls13_secret *out, const EVP_MD *digest,
160 const struct tls13_secret *secret, const char *label,
161 const struct tls13_secret *context)
162{
163 return tls13_hkdf_expand_label_with_length(out, digest, secret, label,
164 strlen(label), context);
165}
166
167int
168tls13_hkdf_expand_label_with_length(struct tls13_secret *out,
169 const EVP_MD *digest, const struct tls13_secret *secret,
170 const uint8_t *label, size_t label_len, const struct tls13_secret *context)
171{
172 const char tls13_plabel[] = "tls13 ";
173 uint8_t *hkdf_label = NULL;
174 size_t hkdf_label_len;
175 CBB cbb, child;
176 int ret;
177
178 if (!CBB_init(&cbb, 256))
179 goto err;
180
181 if (out->data == NULL || out->len == 0)
182 goto err;
183
184 if (!CBB_add_u16(&cbb, out->len))
185 goto err;
186 if (!CBB_add_u8_length_prefixed(&cbb, &child))
187 goto err;
188 if (!CBB_add_bytes(&child, tls13_plabel, strlen(tls13_plabel)))
189 goto err;
190 if (!CBB_add_bytes(&child, label, label_len))
191 goto err;
192 if (!CBB_add_u8_length_prefixed(&cbb, &child))
193 goto err;
194 if (!CBB_add_bytes(&child, context->data, context->len))
195 goto err;
196 if (!CBB_finish(&cbb, &hkdf_label, &hkdf_label_len))
197 goto err;
198
199 ret = HKDF_expand(out->data, out->len, digest, secret->data,
200 secret->len, hkdf_label, hkdf_label_len);
201
202 free(hkdf_label);
203 return(ret);
204 err:
205 CBB_cleanup(&cbb);
206 return(0);
207}
208
209int
210tls13_derive_secret(struct tls13_secret *out, const EVP_MD *digest,
211 const struct tls13_secret *secret, const char *label,
212 const struct tls13_secret *context)
213{
214 return tls13_hkdf_expand_label(out, digest, secret, label, context);
215}
216
217int
218tls13_derive_secret_with_label_length(struct tls13_secret *out,
219 const EVP_MD *digest, const struct tls13_secret *secret, const uint8_t *label,
220 size_t label_len, const struct tls13_secret *context)
221{
222 return tls13_hkdf_expand_label_with_length(out, digest, secret, label,
223 label_len, context);
224}
225
226int
227tls13_derive_early_secrets(struct tls13_secrets *secrets,
228 uint8_t *psk, size_t psk_len, const struct tls13_secret *context)
229{
230 if (!secrets->init_done || secrets->early_done)
231 return 0;
232
233 if (!HKDF_extract(secrets->extracted_early.data,
234 &secrets->extracted_early.len, secrets->digest, psk, psk_len,
235 secrets->zeros.data, secrets->zeros.len))
236 return 0;
237
238 if (secrets->extracted_early.len != secrets->zeros.len)
239 return 0;
240
241 if (!tls13_derive_secret(&secrets->binder_key, secrets->digest,
242 &secrets->extracted_early,
243 secrets->resumption ? "res binder" : "ext binder",
244 &secrets->empty_hash))
245 return 0;
246 if (!tls13_derive_secret(&secrets->client_early_traffic,
247 secrets->digest, &secrets->extracted_early, "c e traffic",
248 context))
249 return 0;
250 if (!tls13_derive_secret(&secrets->early_exporter_master,
251 secrets->digest, &secrets->extracted_early, "e exp master",
252 context))
253 return 0;
254 if (!tls13_derive_secret(&secrets->derived_early,
255 secrets->digest, &secrets->extracted_early, "derived",
256 &secrets->empty_hash))
257 return 0;
258
259 /* RFC 8446 recommends */
260 if (!secrets->insecure)
261 explicit_bzero(secrets->extracted_early.data,
262 secrets->extracted_early.len);
263 secrets->early_done = 1;
264 return 1;
265}
266
267int
268tls13_derive_handshake_secrets(struct tls13_secrets *secrets,
269 const uint8_t *ecdhe, size_t ecdhe_len,
270 const struct tls13_secret *context)
271{
272 if (!secrets->init_done || !secrets->early_done ||
273 secrets->handshake_done)
274 return 0;
275
276 if (!HKDF_extract(secrets->extracted_handshake.data,
277 &secrets->extracted_handshake.len, secrets->digest,
278 ecdhe, ecdhe_len, secrets->derived_early.data,
279 secrets->derived_early.len))
280 return 0;
281
282 if (secrets->extracted_handshake.len != secrets->zeros.len)
283 return 0;
284
285 /* XXX */
286 if (!secrets->insecure)
287 explicit_bzero(secrets->derived_early.data,
288 secrets->derived_early.len);
289
290 if (!tls13_derive_secret(&secrets->client_handshake_traffic,
291 secrets->digest, &secrets->extracted_handshake, "c hs traffic",
292 context))
293 return 0;
294 if (!tls13_derive_secret(&secrets->server_handshake_traffic,
295 secrets->digest, &secrets->extracted_handshake, "s hs traffic",
296 context))
297 return 0;
298 if (!tls13_derive_secret(&secrets->derived_handshake,
299 secrets->digest, &secrets->extracted_handshake, "derived",
300 &secrets->empty_hash))
301 return 0;
302
303 /* RFC 8446 recommends */
304 if (!secrets->insecure)
305 explicit_bzero(secrets->extracted_handshake.data,
306 secrets->extracted_handshake.len);
307
308 secrets->handshake_done = 1;
309
310 return 1;
311}
312
313int
314tls13_derive_application_secrets(struct tls13_secrets *secrets,
315 const struct tls13_secret *context)
316{
317 if (!secrets->init_done || !secrets->early_done ||
318 !secrets->handshake_done || secrets->schedule_done)
319 return 0;
320
321 if (!HKDF_extract(secrets->extracted_master.data,
322 &secrets->extracted_master.len, secrets->digest,
323 secrets->zeros.data, secrets->zeros.len,
324 secrets->derived_handshake.data, secrets->derived_handshake.len))
325 return 0;
326
327 if (secrets->extracted_master.len != secrets->zeros.len)
328 return 0;
329
330 /* XXX */
331 if (!secrets->insecure)
332 explicit_bzero(secrets->derived_handshake.data,
333 secrets->derived_handshake.len);
334
335 if (!tls13_derive_secret(&secrets->client_application_traffic,
336 secrets->digest, &secrets->extracted_master, "c ap traffic",
337 context))
338 return 0;
339 if (!tls13_derive_secret(&secrets->server_application_traffic,
340 secrets->digest, &secrets->extracted_master, "s ap traffic",
341 context))
342 return 0;
343 if (!tls13_derive_secret(&secrets->exporter_master,
344 secrets->digest, &secrets->extracted_master, "exp master",
345 context))
346 return 0;
347 if (!tls13_derive_secret(&secrets->resumption_master,
348 secrets->digest, &secrets->extracted_master, "res master",
349 context))
350 return 0;
351
352 /* RFC 8446 recommends */
353 if (!secrets->insecure)
354 explicit_bzero(secrets->extracted_master.data,
355 secrets->extracted_master.len);
356
357 secrets->schedule_done = 1;
358
359 return 1;
360}
361
362int
363tls13_update_client_traffic_secret(struct tls13_secrets *secrets)
364{
365 struct tls13_secret context = { .data = "", .len = 0 };
366
367 if (!secrets->init_done || !secrets->early_done ||
368 !secrets->handshake_done || !secrets->schedule_done)
369 return 0;
370
371 return tls13_hkdf_expand_label(&secrets->client_application_traffic,
372 secrets->digest, &secrets->client_application_traffic,
373 "traffic upd", &context);
374}
375
376int
377tls13_update_server_traffic_secret(struct tls13_secrets *secrets)
378{
379 struct tls13_secret context = { .data = "", .len = 0 };
380
381 if (!secrets->init_done || !secrets->early_done ||
382 !secrets->handshake_done || !secrets->schedule_done)
383 return 0;
384
385 return tls13_hkdf_expand_label(&secrets->server_application_traffic,
386 secrets->digest, &secrets->server_application_traffic,
387 "traffic upd", &context);
388}
389
390int
391tls13_exporter(struct tls13_ctx *ctx, const uint8_t *label, size_t label_len,
392 const uint8_t *context_value, size_t context_value_len, uint8_t *out,
393 size_t out_len)
394{
395 struct tls13_secret context, export_out, export_secret;
396 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
397 EVP_MD_CTX *md_ctx = NULL;
398 unsigned int md_out_len;
399 int md_len;
400 int ret = 0;
401
402 /*
403 * RFC 8446 Section 7.5.
404 */
405
406 memset(&context, 0, sizeof(context));
407 memset(&export_secret, 0, sizeof(export_secret));
408
409 export_out.data = out;
410 export_out.len = out_len;
411
412 if (!ctx->handshake_completed)
413 return 0;
414
415 md_len = EVP_MD_size(secrets->digest);
416 if (md_len <= 0 || md_len > EVP_MAX_MD_SIZE)
417 goto err;
418
419 if (!tls13_secret_init(&export_secret, md_len))
420 goto err;
421 if (!tls13_secret_init(&context, md_len))
422 goto err;
423
424 /* In TLSv1.3 no context is equivalent to an empty context. */
425 if (context_value == NULL) {
426 context_value = "";
427 context_value_len = 0;
428 }
429
430 if ((md_ctx = EVP_MD_CTX_new()) == NULL)
431 goto err;
432 if (!EVP_DigestInit_ex(md_ctx, secrets->digest, NULL))
433 goto err;
434 if (!EVP_DigestUpdate(md_ctx, context_value, context_value_len))
435 goto err;
436 if (!EVP_DigestFinal_ex(md_ctx, context.data, &md_out_len))
437 goto err;
438 if (md_len != md_out_len)
439 goto err;
440
441 if (!tls13_derive_secret_with_label_length(&export_secret,
442 secrets->digest, &secrets->exporter_master, label, label_len,
443 &secrets->empty_hash))
444 goto err;
445
446 if (!tls13_hkdf_expand_label(&export_out, secrets->digest,
447 &export_secret, "exporter", &context))
448 goto err;
449
450 ret = 1;
451
452 err:
453 EVP_MD_CTX_free(md_ctx);
454 tls13_secret_cleanup(&context);
455 tls13_secret_cleanup(&export_secret);
456
457 return ret;
458}
diff --git a/src/lib/libssl/tls13_legacy.c b/src/lib/libssl/tls13_legacy.c
deleted file mode 100644
index 6c33eccc61..0000000000
--- a/src/lib/libssl/tls13_legacy.c
+++ /dev/null
@@ -1,563 +0,0 @@
1/* $OpenBSD: tls13_legacy.c,v 1.44 2024/01/30 14:50:50 jsing Exp $ */
2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <limits.h>
19
20#include "ssl_local.h"
21#include "tls13_internal.h"
22
23static ssize_t
24tls13_legacy_wire_read(SSL *ssl, uint8_t *buf, size_t len)
25{
26 int n;
27
28 if (ssl->rbio == NULL) {
29 SSLerror(ssl, SSL_R_BIO_NOT_SET);
30 return TLS13_IO_FAILURE;
31 }
32
33 ssl->rwstate = SSL_READING;
34 errno = 0;
35
36 if ((n = BIO_read(ssl->rbio, buf, len)) <= 0) {
37 if (BIO_should_read(ssl->rbio))
38 return TLS13_IO_WANT_POLLIN;
39 if (n == 0)
40 return TLS13_IO_EOF;
41
42 if (ERR_peek_error() == 0 && errno != 0)
43 SYSerror(errno);
44
45 return TLS13_IO_FAILURE;
46 }
47
48 if (n == len)
49 ssl->rwstate = SSL_NOTHING;
50
51 return n;
52}
53
54ssize_t
55tls13_legacy_wire_read_cb(void *buf, size_t n, void *arg)
56{
57 struct tls13_ctx *ctx = arg;
58
59 return tls13_legacy_wire_read(ctx->ssl, buf, n);
60}
61
62static ssize_t
63tls13_legacy_wire_write(SSL *ssl, const uint8_t *buf, size_t len)
64{
65 int n;
66
67 if (ssl->wbio == NULL) {
68 SSLerror(ssl, SSL_R_BIO_NOT_SET);
69 return TLS13_IO_FAILURE;
70 }
71
72 ssl->rwstate = SSL_WRITING;
73 errno = 0;
74
75 if ((n = BIO_write(ssl->wbio, buf, len)) <= 0) {
76 if (BIO_should_write(ssl->wbio))
77 return TLS13_IO_WANT_POLLOUT;
78
79 if (ERR_peek_error() == 0 && errno != 0)
80 SYSerror(errno);
81
82 return TLS13_IO_FAILURE;
83 }
84
85 if (n == len)
86 ssl->rwstate = SSL_NOTHING;
87
88 return n;
89}
90
91ssize_t
92tls13_legacy_wire_write_cb(const void *buf, size_t n, void *arg)
93{
94 struct tls13_ctx *ctx = arg;
95
96 return tls13_legacy_wire_write(ctx->ssl, buf, n);
97}
98
99static ssize_t
100tls13_legacy_wire_flush(SSL *ssl)
101{
102 if (BIO_flush(ssl->wbio) <= 0) {
103 if (BIO_should_write(ssl->wbio))
104 return TLS13_IO_WANT_POLLOUT;
105
106 if (ERR_peek_error() == 0 && errno != 0)
107 SYSerror(errno);
108
109 return TLS13_IO_FAILURE;
110 }
111
112 return TLS13_IO_SUCCESS;
113}
114
115ssize_t
116tls13_legacy_wire_flush_cb(void *arg)
117{
118 struct tls13_ctx *ctx = arg;
119
120 return tls13_legacy_wire_flush(ctx->ssl);
121}
122
123static void
124tls13_legacy_error(SSL *ssl)
125{
126 struct tls13_ctx *ctx = ssl->tls13;
127 int reason = SSL_R_UNKNOWN;
128
129 /* If we received a fatal alert we already put an error on the stack. */
130 if (ssl->s3->fatal_alert != 0)
131 return;
132
133 switch (ctx->error.code) {
134 case TLS13_ERR_VERIFY_FAILED:
135 reason = SSL_R_CERTIFICATE_VERIFY_FAILED;
136 break;
137 case TLS13_ERR_HRR_FAILED:
138 reason = SSL_R_NO_CIPHERS_AVAILABLE;
139 break;
140 case TLS13_ERR_TRAILING_DATA:
141 reason = SSL_R_EXTRA_DATA_IN_MESSAGE;
142 break;
143 case TLS13_ERR_NO_SHARED_CIPHER:
144 reason = SSL_R_NO_SHARED_CIPHER;
145 break;
146 case TLS13_ERR_NO_CERTIFICATE:
147 reason = SSL_R_MISSING_RSA_CERTIFICATE; /* XXX */
148 break;
149 case TLS13_ERR_NO_PEER_CERTIFICATE:
150 reason = SSL_R_PEER_DID_NOT_RETURN_A_CERTIFICATE;
151 break;
152 }
153
154 /* Something (probably libcrypto) already pushed an error on the stack. */
155 if (reason == SSL_R_UNKNOWN && ERR_peek_error() != 0)
156 return;
157
158 ERR_put_error(ERR_LIB_SSL, (0xfff), reason, ctx->error.file,
159 ctx->error.line);
160}
161
162static int
163tls13_legacy_return_code(SSL *ssl, ssize_t ret)
164{
165 if (ret > INT_MAX) {
166 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
167 return -1;
168 }
169
170 /* A successful read, write or other operation. */
171 if (ret > 0)
172 return ret;
173
174 ssl->rwstate = SSL_NOTHING;
175
176 switch (ret) {
177 case TLS13_IO_EOF:
178 return 0;
179
180 case TLS13_IO_FAILURE:
181 tls13_legacy_error(ssl);
182 return -1;
183
184 case TLS13_IO_ALERT:
185 tls13_legacy_error(ssl);
186 return -1;
187
188 case TLS13_IO_WANT_POLLIN:
189 BIO_set_retry_read(ssl->rbio);
190 ssl->rwstate = SSL_READING;
191 return -1;
192
193 case TLS13_IO_WANT_POLLOUT:
194 BIO_set_retry_write(ssl->wbio);
195 ssl->rwstate = SSL_WRITING;
196 return -1;
197
198 case TLS13_IO_WANT_RETRY:
199 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
200 return -1;
201 }
202
203 SSLerror(ssl, ERR_R_INTERNAL_ERROR);
204 return -1;
205}
206
207int
208tls13_legacy_pending(const SSL *ssl)
209{
210 struct tls13_ctx *ctx = ssl->tls13;
211 ssize_t ret;
212
213 if (ctx == NULL)
214 return 0;
215
216 ret = tls13_pending_application_data(ctx->rl);
217 if (ret < 0 || ret > INT_MAX)
218 return 0;
219
220 return ret;
221}
222
223int
224tls13_legacy_read_bytes(SSL *ssl, int type, unsigned char *buf, int len, int peek)
225{
226 struct tls13_ctx *ctx = ssl->tls13;
227 ssize_t ret;
228
229 if (ctx == NULL || !ctx->handshake_completed) {
230 if ((ret = ssl->handshake_func(ssl)) <= 0)
231 return ret;
232 if (len == 0)
233 return 0;
234 return tls13_legacy_return_code(ssl, TLS13_IO_WANT_POLLIN);
235 }
236
237 tls13_record_layer_set_retry_after_phh(ctx->rl,
238 (ctx->ssl->mode & SSL_MODE_AUTO_RETRY) != 0);
239
240 if (type != SSL3_RT_APPLICATION_DATA) {
241 SSLerror(ssl, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
242 return -1;
243 }
244 if (len < 0) {
245 SSLerror(ssl, SSL_R_BAD_LENGTH);
246 return -1;
247 }
248
249 if (peek)
250 ret = tls13_peek_application_data(ctx->rl, buf, len);
251 else
252 ret = tls13_read_application_data(ctx->rl, buf, len);
253
254 return tls13_legacy_return_code(ssl, ret);
255}
256
257int
258tls13_legacy_write_bytes(SSL *ssl, int type, const void *vbuf, int len)
259{
260 struct tls13_ctx *ctx = ssl->tls13;
261 const uint8_t *buf = vbuf;
262 size_t n, sent;
263 ssize_t ret;
264
265 if (ctx == NULL || !ctx->handshake_completed) {
266 if ((ret = ssl->handshake_func(ssl)) <= 0)
267 return ret;
268 if (len == 0)
269 return 0;
270 return tls13_legacy_return_code(ssl, TLS13_IO_WANT_POLLOUT);
271 }
272
273 if (type != SSL3_RT_APPLICATION_DATA) {
274 SSLerror(ssl, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
275 return -1;
276 }
277 if (len < 0) {
278 SSLerror(ssl, SSL_R_BAD_LENGTH);
279 return -1;
280 }
281
282 /*
283 * The TLSv1.3 record layer write behaviour is the same as
284 * SSL_MODE_ENABLE_PARTIAL_WRITE.
285 */
286 if (ssl->mode & SSL_MODE_ENABLE_PARTIAL_WRITE) {
287 ret = tls13_write_application_data(ctx->rl, buf, len);
288 return tls13_legacy_return_code(ssl, ret);
289 }
290
291 /*
292 * In the non-SSL_MODE_ENABLE_PARTIAL_WRITE case we have to loop until
293 * we have written out all of the requested data.
294 */
295 sent = ssl->s3->wnum;
296 if (len < sent) {
297 SSLerror(ssl, SSL_R_BAD_LENGTH);
298 return -1;
299 }
300 n = len - sent;
301 for (;;) {
302 if (n == 0) {
303 ssl->s3->wnum = 0;
304 return sent;
305 }
306 if ((ret = tls13_write_application_data(ctx->rl,
307 &buf[sent], n)) <= 0) {
308 ssl->s3->wnum = sent;
309 return tls13_legacy_return_code(ssl, ret);
310 }
311 sent += ret;
312 n -= ret;
313 }
314}
315
316static int
317tls13_use_legacy_stack(struct tls13_ctx *ctx)
318{
319 SSL *s = ctx->ssl;
320 CBB cbb, fragment;
321 CBS cbs;
322
323 memset(&cbb, 0, sizeof(cbb));
324
325 if (!ssl3_setup_init_buffer(s))
326 goto err;
327 if (!ssl3_setup_buffers(s))
328 goto err;
329 if (!ssl_init_wbio_buffer(s, 1))
330 goto err;
331
332 /* Stash any unprocessed data from the last record. */
333 tls13_record_layer_rcontent(ctx->rl, &cbs);
334 if (CBS_len(&cbs) > 0) {
335 if (!CBB_init_fixed(&cbb, s->s3->rbuf.buf,
336 s->s3->rbuf.len))
337 goto err;
338 if (!CBB_add_u8(&cbb, SSL3_RT_HANDSHAKE))
339 goto err;
340 if (!CBB_add_u16(&cbb, TLS1_2_VERSION))
341 goto err;
342 if (!CBB_add_u16_length_prefixed(&cbb, &fragment))
343 goto err;
344 if (!CBB_add_bytes(&fragment, CBS_data(&cbs), CBS_len(&cbs)))
345 goto err;
346 if (!CBB_finish(&cbb, NULL, NULL))
347 goto err;
348
349 s->s3->rbuf.offset = SSL3_RT_HEADER_LENGTH;
350 s->s3->rbuf.left = CBS_len(&cbs);
351 s->s3->rrec.type = SSL3_RT_HANDSHAKE;
352 s->s3->rrec.length = CBS_len(&cbs);
353 s->rstate = SSL_ST_READ_BODY;
354 s->packet = s->s3->rbuf.buf;
355 s->packet_length = SSL3_RT_HEADER_LENGTH;
356 s->mac_packet = 1;
357 }
358
359 /* Stash the current handshake message. */
360 tls13_handshake_msg_data(ctx->hs_msg, &cbs);
361 if (!BUF_MEM_grow_clean(s->init_buf, CBS_len(&cbs)))
362 goto err;
363 if (!CBS_write_bytes(&cbs, s->init_buf->data,
364 s->init_buf->length, NULL))
365 goto err;
366
367 s->s3->hs.tls12.reuse_message = 1;
368 s->s3->hs.tls12.message_type = tls13_handshake_msg_type(ctx->hs_msg);
369 s->s3->hs.tls12.message_size = CBS_len(&cbs) - SSL3_HM_HEADER_LENGTH;
370
371 /*
372 * Only switch the method after initialization is complete
373 * as we start part way into the legacy state machine.
374 */
375 s->method = tls_legacy_method();
376
377 return 1;
378
379 err:
380 CBB_cleanup(&cbb);
381
382 return 0;
383}
384
385int
386tls13_use_legacy_client(struct tls13_ctx *ctx)
387{
388 SSL *s = ctx->ssl;
389
390 if (!tls13_use_legacy_stack(ctx))
391 return 0;
392
393 s->handshake_func = s->method->ssl_connect;
394 s->version = s->method->max_tls_version;
395
396 return 1;
397}
398
399int
400tls13_use_legacy_server(struct tls13_ctx *ctx)
401{
402 SSL *s = ctx->ssl;
403
404 if (!tls13_use_legacy_stack(ctx))
405 return 0;
406
407 s->handshake_func = s->method->ssl_accept;
408 s->version = s->method->max_tls_version;
409 s->server = 1;
410
411 return 1;
412}
413
414int
415tls13_legacy_accept(SSL *ssl)
416{
417 struct tls13_ctx *ctx = ssl->tls13;
418 int ret;
419
420 if (ctx == NULL) {
421 if ((ctx = tls13_ctx_new(TLS13_HS_SERVER, ssl)) == NULL) {
422 SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */
423 return -1;
424 }
425 if (!tls13_server_init(ctx)) {
426 if (ERR_peek_error() == 0)
427 SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */
428 return -1;
429 }
430 }
431
432 ERR_clear_error();
433
434 ret = tls13_server_accept(ctx);
435 if (ret == TLS13_IO_USE_LEGACY)
436 return ssl->method->ssl_accept(ssl);
437
438 ret = tls13_legacy_return_code(ssl, ret);
439
440 if (ctx->info_cb != NULL)
441 ctx->info_cb(ctx, TLS13_INFO_ACCEPT_EXIT, ret);
442
443 return ret;
444}
445
446int
447tls13_legacy_connect(SSL *ssl)
448{
449 struct tls13_ctx *ctx = ssl->tls13;
450 int ret;
451
452 if (ctx == NULL) {
453 if ((ctx = tls13_ctx_new(TLS13_HS_CLIENT, ssl)) == NULL) {
454 SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */
455 return -1;
456 }
457 if (!tls13_client_init(ctx)) {
458 if (ERR_peek_error() == 0)
459 SSLerror(ssl, ERR_R_INTERNAL_ERROR); /* XXX */
460 return -1;
461 }
462 }
463
464 ERR_clear_error();
465
466 ret = tls13_client_connect(ctx);
467 if (ret == TLS13_IO_USE_LEGACY)
468 return ssl->method->ssl_connect(ssl);
469
470 ret = tls13_legacy_return_code(ssl, ret);
471
472 if (ctx->info_cb != NULL)
473 ctx->info_cb(ctx, TLS13_INFO_CONNECT_EXIT, ret);
474
475 return ret;
476}
477
478int
479tls13_legacy_shutdown(SSL *ssl)
480{
481 struct tls13_ctx *ctx = ssl->tls13;
482 uint8_t buf[512]; /* XXX */
483 ssize_t ret;
484
485 /*
486 * We need to return 0 at the point that we have completed sending a
487 * close-notify. We return 1 when we have sent and received close-notify
488 * alerts. All other cases, including EOF, return -1 and set internal
489 * state appropriately. Note that all of this insanity can also be
490 * externally controlled by manipulating the shutdown flags.
491 */
492 if (ctx == NULL || ssl->quiet_shutdown) {
493 ssl->shutdown = SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN;
494 return 1;
495 }
496
497 if ((ssl->shutdown & SSL_SENT_SHUTDOWN) == 0) {
498 ssl->shutdown |= SSL_SENT_SHUTDOWN;
499 ret = tls13_send_alert(ctx->rl, TLS13_ALERT_CLOSE_NOTIFY);
500 if (ret == TLS13_IO_EOF)
501 return -1;
502 if (ret != TLS13_IO_SUCCESS)
503 return tls13_legacy_return_code(ssl, ret);
504 goto done;
505 }
506
507 ret = tls13_record_layer_send_pending(ctx->rl);
508 if (ret == TLS13_IO_EOF)
509 return -1;
510 if (ret != TLS13_IO_SUCCESS)
511 return tls13_legacy_return_code(ssl, ret);
512
513 if ((ssl->shutdown & SSL_RECEIVED_SHUTDOWN) == 0) {
514 /*
515 * If there is no application data pending, attempt to read more
516 * data in order to receive a close-notify. This should trigger
517 * a record to be read from the wire, which may be application
518 * handshake or alert data. Only one attempt is made with no
519 * error handling, in order to match previous semantics.
520 */
521 if (tls13_pending_application_data(ctx->rl) == 0) {
522 (void)tls13_read_application_data(ctx->rl, buf, sizeof(buf));
523 if (!ctx->close_notify_recv)
524 return -1;
525 }
526 }
527
528 done:
529 if (ssl->shutdown == (SSL_SENT_SHUTDOWN | SSL_RECEIVED_SHUTDOWN))
530 return 1;
531
532 return 0;
533}
534
535int
536tls13_legacy_servername_process(struct tls13_ctx *ctx, uint8_t *alert)
537{
538 int legacy_alert = SSL_AD_UNRECOGNIZED_NAME;
539 int ret = SSL_TLSEXT_ERR_NOACK;
540 SSL_CTX *ssl_ctx = ctx->ssl->ctx;
541 SSL *s = ctx->ssl;
542
543 if (ssl_ctx->tlsext_servername_callback == NULL)
544 ssl_ctx = s->initial_ctx;
545 if (ssl_ctx->tlsext_servername_callback == NULL)
546 return 1;
547
548 ret = ssl_ctx->tlsext_servername_callback(s, &legacy_alert,
549 ssl_ctx->tlsext_servername_arg);
550
551 /*
552 * Ignore SSL_TLSEXT_ERR_ALERT_WARNING returns to match OpenSSL's
553 * behavior: the only warning alerts in TLSv1.3 are close_notify and
554 * user_canceled, neither of which should be returned by the callback.
555 */
556 if (ret == SSL_TLSEXT_ERR_ALERT_FATAL) {
557 if (legacy_alert >= 0 && legacy_alert <= 255)
558 *alert = legacy_alert;
559 return 0;
560 }
561
562 return 1;
563}
diff --git a/src/lib/libssl/tls13_lib.c b/src/lib/libssl/tls13_lib.c
deleted file mode 100644
index 331a3ad1a7..0000000000
--- a/src/lib/libssl/tls13_lib.c
+++ /dev/null
@@ -1,737 +0,0 @@
1/* $OpenBSD: tls13_lib.c,v 1.77 2024/01/27 14:23:51 jsing Exp $ */
2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2019 Bob Beck <beck@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <stddef.h>
20
21#include <openssl/evp.h>
22
23#include "ssl_local.h"
24#include "ssl_tlsext.h"
25#include "tls13_internal.h"
26
27/*
28 * RFC 8446, section 4.6.1. Servers must not indicate a lifetime longer than
29 * 7 days and clients must not cache tickets for longer than 7 days.
30 */
31
32#define TLS13_MAX_TICKET_LIFETIME (7 * 24 * 3600)
33
34/*
35 * Downgrade sentinels - RFC 8446 section 4.1.3, magic values which must be set
36 * by the server in server random if it is willing to downgrade but supports
37 * TLSv1.3
38 */
39const uint8_t tls13_downgrade_12[8] = {
40 0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x01,
41};
42const uint8_t tls13_downgrade_11[8] = {
43 0x44, 0x4f, 0x57, 0x4e, 0x47, 0x52, 0x44, 0x00,
44};
45
46/*
47 * HelloRetryRequest hash - RFC 8446 section 4.1.3.
48 */
49const uint8_t tls13_hello_retry_request_hash[32] = {
50 0xcf, 0x21, 0xad, 0x74, 0xe5, 0x9a, 0x61, 0x11,
51 0xbe, 0x1d, 0x8c, 0x02, 0x1e, 0x65, 0xb8, 0x91,
52 0xc2, 0xa2, 0x11, 0x16, 0x7a, 0xbb, 0x8c, 0x5e,
53 0x07, 0x9e, 0x09, 0xe2, 0xc8, 0xa8, 0x33, 0x9c,
54};
55
56/*
57 * Certificate Verify padding - RFC 8446 section 4.4.3.
58 */
59const uint8_t tls13_cert_verify_pad[64] = {
60 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
61 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
62 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
63 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
64 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
65 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
66 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
67 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
68};
69
70const uint8_t tls13_cert_client_verify_context[] =
71 "TLS 1.3, client CertificateVerify";
72const uint8_t tls13_cert_server_verify_context[] =
73 "TLS 1.3, server CertificateVerify";
74
75const EVP_AEAD *
76tls13_cipher_aead(const SSL_CIPHER *cipher)
77{
78 if (cipher == NULL)
79 return NULL;
80 if (cipher->algorithm_ssl != SSL_TLSV1_3)
81 return NULL;
82
83 switch (cipher->algorithm_enc) {
84 case SSL_AES128GCM:
85 return EVP_aead_aes_128_gcm();
86 case SSL_AES256GCM:
87 return EVP_aead_aes_256_gcm();
88 case SSL_CHACHA20POLY1305:
89 return EVP_aead_chacha20_poly1305();
90 }
91
92 return NULL;
93}
94
95const EVP_MD *
96tls13_cipher_hash(const SSL_CIPHER *cipher)
97{
98 if (cipher == NULL)
99 return NULL;
100 if (cipher->algorithm_ssl != SSL_TLSV1_3)
101 return NULL;
102
103 switch (cipher->algorithm2) {
104 case SSL_HANDSHAKE_MAC_SHA256:
105 return EVP_sha256();
106 case SSL_HANDSHAKE_MAC_SHA384:
107 return EVP_sha384();
108 }
109
110 return NULL;
111}
112
113static void
114tls13_legacy_alert_cb(int sent, uint8_t alert_level, uint8_t alert_desc,
115 void *arg)
116{
117 uint8_t alert[] = {alert_level, alert_desc};
118 struct tls13_ctx *ctx = arg;
119 SSL *s = ctx->ssl;
120 CBS cbs;
121
122 if (s->msg_callback == NULL)
123 return;
124
125 CBS_init(&cbs, alert, sizeof(alert));
126 ssl_msg_callback_cbs(s, sent, SSL3_RT_ALERT, &cbs);
127}
128
129static void
130tls13_legacy_alert_recv_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
131{
132 tls13_legacy_alert_cb(0, alert_level, alert_desc, arg);
133}
134
135static void
136tls13_legacy_alert_sent_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
137{
138 tls13_legacy_alert_cb(1, alert_level, alert_desc, arg);
139}
140
141void
142tls13_alert_received_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
143{
144 struct tls13_ctx *ctx = arg;
145
146 if (ctx->alert_recv_cb != NULL)
147 ctx->alert_recv_cb(alert_level, alert_desc, arg);
148
149 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
150 ctx->close_notify_recv = 1;
151 ctx->ssl->shutdown |= SSL_RECEIVED_SHUTDOWN;
152 ctx->ssl->s3->warn_alert = alert_desc;
153 return;
154 }
155
156 if (alert_desc == TLS13_ALERT_USER_CANCELED) {
157 /*
158 * We treat this as advisory, since a close_notify alert
159 * SHOULD follow this alert (RFC 8446 section 6.1).
160 */
161 return;
162 }
163
164 /* All other alerts are treated as fatal in TLSv1.3. */
165 ctx->ssl->s3->fatal_alert = alert_desc;
166
167 SSLerror(ctx->ssl, SSL_AD_REASON_OFFSET + alert_desc);
168 ERR_asprintf_error_data("SSL alert number %d", alert_desc);
169
170 SSL_CTX_remove_session(ctx->ssl->ctx, ctx->ssl->session);
171}
172
173void
174tls13_alert_sent_cb(uint8_t alert_level, uint8_t alert_desc, void *arg)
175{
176 struct tls13_ctx *ctx = arg;
177
178 if (ctx->alert_sent_cb != NULL)
179 ctx->alert_sent_cb(alert_level, alert_desc, arg);
180
181 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
182 ctx->close_notify_sent = 1;
183 return;
184 }
185
186 if (alert_desc == TLS13_ALERT_USER_CANCELED) {
187 return;
188 }
189
190 /* All other alerts are treated as fatal in TLSv1.3. */
191 if (ctx->error.code == 0)
192 SSLerror(ctx->ssl, SSL_AD_REASON_OFFSET + alert_desc);
193}
194
195static void
196tls13_legacy_handshake_message_recv_cb(void *arg)
197{
198 struct tls13_ctx *ctx = arg;
199 SSL *s = ctx->ssl;
200 CBS cbs;
201
202 if (s->msg_callback == NULL)
203 return;
204
205 tls13_handshake_msg_data(ctx->hs_msg, &cbs);
206 ssl_msg_callback_cbs(s, 0, SSL3_RT_HANDSHAKE, &cbs);
207}
208
209static void
210tls13_legacy_handshake_message_sent_cb(void *arg)
211{
212 struct tls13_ctx *ctx = arg;
213 SSL *s = ctx->ssl;
214 CBS cbs;
215
216 if (s->msg_callback == NULL)
217 return;
218
219 tls13_handshake_msg_data(ctx->hs_msg, &cbs);
220 ssl_msg_callback_cbs(s, 1, SSL3_RT_HANDSHAKE, &cbs);
221}
222
223static void
224tls13_legacy_info_cb(void *arg, int state, int ret)
225{
226 struct tls13_ctx *ctx = arg;
227 SSL *s = ctx->ssl;
228
229 ssl_info_callback(s, state, ret);
230}
231
232static int
233tls13_legacy_ocsp_status_recv_cb(void *arg)
234{
235 struct tls13_ctx *ctx = arg;
236 SSL *s = ctx->ssl;
237 int ret;
238
239 if (s->ctx->tlsext_status_cb == NULL)
240 return 1;
241
242 ret = s->ctx->tlsext_status_cb(s,
243 s->ctx->tlsext_status_arg);
244 if (ret < 0) {
245 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
246 SSLerror(s, ERR_R_MALLOC_FAILURE);
247 return 0;
248 }
249 if (ret == 0) {
250 ctx->alert = TLS13_ALERT_BAD_CERTIFICATE_STATUS_RESPONSE;
251 SSLerror(s, SSL_R_INVALID_STATUS_RESPONSE);
252 return 0;
253 }
254
255 return 1;
256}
257
258static int
259tls13_phh_update_read_traffic_secret(struct tls13_ctx *ctx)
260{
261 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
262 struct tls13_secret *secret;
263
264 if (ctx->mode == TLS13_HS_CLIENT) {
265 secret = &secrets->server_application_traffic;
266 if (!tls13_update_server_traffic_secret(secrets))
267 return 0;
268 } else {
269 secret = &secrets->client_application_traffic;
270 if (!tls13_update_client_traffic_secret(secrets))
271 return 0;
272 }
273
274 return tls13_record_layer_set_read_traffic_key(ctx->rl,
275 secret, ssl_encryption_application);
276}
277
278static int
279tls13_phh_update_write_traffic_secret(struct tls13_ctx *ctx)
280{
281 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
282 struct tls13_secret *secret;
283
284 if (ctx->mode == TLS13_HS_CLIENT) {
285 secret = &secrets->client_application_traffic;
286 if (!tls13_update_client_traffic_secret(secrets))
287 return 0;
288 } else {
289 secret = &secrets->server_application_traffic;
290 if (!tls13_update_server_traffic_secret(secrets))
291 return 0;
292 }
293
294 return tls13_record_layer_set_write_traffic_key(ctx->rl,
295 secret, ssl_encryption_application);
296}
297
298/*
299 * XXX arbitrarily chosen limit of 100 post handshake handshake
300 * messages in an hour - to avoid a hostile peer from constantly
301 * requesting certificates or key renegotiaitons, etc.
302 */
303static int
304tls13_phh_limit_check(struct tls13_ctx *ctx)
305{
306 time_t now = time(NULL);
307
308 if (ctx->phh_last_seen > now - TLS13_PHH_LIMIT_TIME) {
309 if (ctx->phh_count > TLS13_PHH_LIMIT)
310 return 0;
311 } else
312 ctx->phh_count = 0;
313 ctx->phh_count++;
314 ctx->phh_last_seen = now;
315 return 1;
316}
317
318static ssize_t
319tls13_key_update_recv(struct tls13_ctx *ctx, CBS *cbs)
320{
321 struct tls13_handshake_msg *hs_msg = NULL;
322 CBB cbb_hs;
323 CBS cbs_hs;
324 uint8_t alert = TLS13_ALERT_INTERNAL_ERROR;
325 uint8_t key_update_request;
326 ssize_t ret;
327
328 if (!CBS_get_u8(cbs, &key_update_request)) {
329 alert = TLS13_ALERT_DECODE_ERROR;
330 goto err;
331 }
332 if (CBS_len(cbs) != 0) {
333 alert = TLS13_ALERT_DECODE_ERROR;
334 goto err;
335 }
336 if (key_update_request > 1) {
337 alert = TLS13_ALERT_ILLEGAL_PARAMETER;
338 goto err;
339 }
340
341 if (!tls13_phh_update_read_traffic_secret(ctx))
342 goto err;
343
344 if (key_update_request == 0)
345 return TLS13_IO_SUCCESS;
346
347 /* Our peer requested that we update our write traffic keys. */
348 if ((hs_msg = tls13_handshake_msg_new()) == NULL)
349 goto err;
350 if (!tls13_handshake_msg_start(hs_msg, &cbb_hs, TLS13_MT_KEY_UPDATE))
351 goto err;
352 if (!CBB_add_u8(&cbb_hs, 0))
353 goto err;
354 if (!tls13_handshake_msg_finish(hs_msg))
355 goto err;
356
357 ctx->key_update_request = 1;
358 tls13_handshake_msg_data(hs_msg, &cbs_hs);
359 ret = tls13_record_layer_phh(ctx->rl, &cbs_hs);
360
361 tls13_handshake_msg_free(hs_msg);
362 hs_msg = NULL;
363
364 return ret;
365
366 err:
367 tls13_handshake_msg_free(hs_msg);
368
369 return tls13_send_alert(ctx->rl, alert);
370}
371
372/* RFC 8446 section 4.6.1 */
373static ssize_t
374tls13_new_session_ticket_recv(struct tls13_ctx *ctx, CBS *cbs)
375{
376 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
377 struct tls13_secret nonce;
378 uint32_t ticket_lifetime, ticket_age_add;
379 CBS ticket_nonce, ticket;
380 SSL_SESSION *sess = NULL;
381 int alert, session_id_length;
382 ssize_t ret = 0;
383
384 memset(&nonce, 0, sizeof(nonce));
385
386 if (ctx->mode != TLS13_HS_CLIENT) {
387 alert = TLS13_ALERT_UNEXPECTED_MESSAGE;
388 goto err;
389 }
390
391 alert = TLS13_ALERT_DECODE_ERROR;
392
393 if (!CBS_get_u32(cbs, &ticket_lifetime))
394 goto err;
395 if (!CBS_get_u32(cbs, &ticket_age_add))
396 goto err;
397 if (!CBS_get_u8_length_prefixed(cbs, &ticket_nonce))
398 goto err;
399 if (!CBS_get_u16_length_prefixed(cbs, &ticket))
400 goto err;
401 /* Extensions can only contain early_data, which we currently ignore. */
402 if (!tlsext_client_parse(ctx->ssl, SSL_TLSEXT_MSG_NST, cbs, &alert))
403 goto err;
404
405 if (CBS_len(cbs) != 0)
406 goto err;
407
408 /* Zero indicates that the ticket should be discarded immediately. */
409 if (ticket_lifetime == 0) {
410 ret = TLS13_IO_SUCCESS;
411 goto done;
412 }
413
414 /* Servers MUST NOT use any value larger than 7 days. */
415 if (ticket_lifetime > TLS13_MAX_TICKET_LIFETIME) {
416 alert = TLS13_ALERT_ILLEGAL_PARAMETER;
417 goto err;
418 }
419
420 alert = TLS13_ALERT_INTERNAL_ERROR;
421
422 /*
423 * Create new session instead of modifying the current session.
424 * The current session could already be in the session cache.
425 */
426 if ((sess = ssl_session_dup(ctx->ssl->session, 0)) == NULL)
427 goto err;
428
429 sess->time = time(NULL);
430
431 sess->tlsext_tick_lifetime_hint = ticket_lifetime;
432 sess->tlsext_tick_age_add = ticket_age_add;
433
434 if (!CBS_stow(&ticket, &sess->tlsext_tick, &sess->tlsext_ticklen))
435 goto err;
436
437 /* XXX - ensure this doesn't overflow session_id if hash is changed. */
438 if (!EVP_Digest(CBS_data(&ticket), CBS_len(&ticket),
439 sess->session_id, &session_id_length, EVP_sha256(), NULL))
440 goto err;
441 sess->session_id_length = session_id_length;
442
443 if (!CBS_stow(&ticket_nonce, &nonce.data, &nonce.len))
444 goto err;
445
446 if (!tls13_secret_init(&sess->resumption_master_secret, 256))
447 goto err;
448
449 if (!tls13_derive_secret(&sess->resumption_master_secret,
450 secrets->digest, &secrets->resumption_master, "resumption",
451 &nonce))
452 goto err;
453
454 SSL_SESSION_free(ctx->ssl->session);
455 ctx->ssl->session = sess;
456 sess = NULL;
457
458 ssl_update_cache(ctx->ssl, SSL_SESS_CACHE_CLIENT);
459
460 ret = TLS13_IO_SUCCESS;
461 goto done;
462
463 err:
464 ret = tls13_send_alert(ctx->rl, alert);
465
466 done:
467 tls13_secret_cleanup(&nonce);
468 SSL_SESSION_free(sess);
469
470 return ret;
471}
472
473ssize_t
474tls13_phh_received_cb(void *cb_arg)
475{
476 ssize_t ret = TLS13_IO_FAILURE;
477 struct tls13_ctx *ctx = cb_arg;
478 CBS cbs;
479
480 if (!tls13_phh_limit_check(ctx))
481 return tls13_send_alert(ctx->rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
482
483 if ((ctx->hs_msg == NULL) &&
484 ((ctx->hs_msg = tls13_handshake_msg_new()) == NULL))
485 return TLS13_IO_FAILURE;
486
487 if ((ret = tls13_handshake_msg_recv(ctx->hs_msg, ctx->rl)) !=
488 TLS13_IO_SUCCESS)
489 return ret;
490
491 if (!tls13_handshake_msg_content(ctx->hs_msg, &cbs))
492 return TLS13_IO_FAILURE;
493
494 switch(tls13_handshake_msg_type(ctx->hs_msg)) {
495 case TLS13_MT_KEY_UPDATE:
496 ret = tls13_key_update_recv(ctx, &cbs);
497 break;
498 case TLS13_MT_NEW_SESSION_TICKET:
499 ret = tls13_new_session_ticket_recv(ctx, &cbs);
500 break;
501 case TLS13_MT_CERTIFICATE_REQUEST:
502 /* XXX add support if we choose to advertise this */
503 /* FALLTHROUGH */
504 default:
505 ret = TLS13_IO_FAILURE; /* XXX send alert */
506 break;
507 }
508
509 tls13_handshake_msg_free(ctx->hs_msg);
510 ctx->hs_msg = NULL;
511 return ret;
512}
513
514void
515tls13_phh_done_cb(void *cb_arg)
516{
517 struct tls13_ctx *ctx = cb_arg;
518
519 if (ctx->key_update_request) {
520 tls13_phh_update_write_traffic_secret(ctx);
521 ctx->key_update_request = 0;
522 }
523}
524
525static const struct tls13_record_layer_callbacks tls13_rl_callbacks = {
526 .wire_read = tls13_legacy_wire_read_cb,
527 .wire_write = tls13_legacy_wire_write_cb,
528 .wire_flush = tls13_legacy_wire_flush_cb,
529
530 .alert_recv = tls13_alert_received_cb,
531 .alert_sent = tls13_alert_sent_cb,
532 .phh_recv = tls13_phh_received_cb,
533 .phh_sent = tls13_phh_done_cb,
534};
535
536struct tls13_ctx *
537tls13_ctx_new(int mode, SSL *ssl)
538{
539 struct tls13_ctx *ctx = NULL;
540
541 if ((ctx = calloc(sizeof(struct tls13_ctx), 1)) == NULL)
542 goto err;
543
544 ctx->hs = &ssl->s3->hs;
545 ctx->mode = mode;
546 ctx->ssl = ssl;
547
548 if ((ctx->rl = tls13_record_layer_new(&tls13_rl_callbacks, ctx)) == NULL)
549 goto err;
550
551 ctx->alert_sent_cb = tls13_legacy_alert_sent_cb;
552 ctx->alert_recv_cb = tls13_legacy_alert_recv_cb;
553 ctx->handshake_message_sent_cb = tls13_legacy_handshake_message_sent_cb;
554 ctx->handshake_message_recv_cb = tls13_legacy_handshake_message_recv_cb;
555 ctx->info_cb = tls13_legacy_info_cb;
556 ctx->ocsp_status_recv_cb = tls13_legacy_ocsp_status_recv_cb;
557
558 ctx->middlebox_compat = 1;
559
560 ssl->tls13 = ctx;
561
562 if (SSL_is_quic(ssl)) {
563 if (!tls13_quic_init(ctx))
564 goto err;
565 }
566
567 return ctx;
568
569 err:
570 tls13_ctx_free(ctx);
571
572 return NULL;
573}
574
575void
576tls13_ctx_free(struct tls13_ctx *ctx)
577{
578 if (ctx == NULL)
579 return;
580
581 tls13_error_clear(&ctx->error);
582 tls13_record_layer_free(ctx->rl);
583 tls13_handshake_msg_free(ctx->hs_msg);
584
585 freezero(ctx, sizeof(struct tls13_ctx));
586}
587
588int
589tls13_cert_add(struct tls13_ctx *ctx, CBB *cbb, X509 *cert,
590 int (*build_extensions)(SSL *s, uint16_t msg_type, CBB *cbb))
591{
592 CBB cert_data, cert_exts;
593 uint8_t *data;
594 int cert_len;
595
596 if ((cert_len = i2d_X509(cert, NULL)) < 0)
597 return 0;
598
599 if (!CBB_add_u24_length_prefixed(cbb, &cert_data))
600 return 0;
601 if (!CBB_add_space(&cert_data, &data, cert_len))
602 return 0;
603 if (i2d_X509(cert, &data) != cert_len)
604 return 0;
605 if (build_extensions != NULL) {
606 if (!build_extensions(ctx->ssl, SSL_TLSEXT_MSG_CT, cbb))
607 return 0;
608 } else {
609 if (!CBB_add_u16_length_prefixed(cbb, &cert_exts))
610 return 0;
611 }
612 if (!CBB_flush(cbb))
613 return 0;
614
615 return 1;
616}
617
618int
619tls13_synthetic_handshake_message(struct tls13_ctx *ctx)
620{
621 struct tls13_handshake_msg *hm = NULL;
622 unsigned char buf[EVP_MAX_MD_SIZE];
623 size_t hash_len;
624 CBB cbb;
625 CBS cbs;
626 SSL *s = ctx->ssl;
627 int ret = 0;
628
629 /*
630 * Replace ClientHello with synthetic handshake message - see
631 * RFC 8446 section 4.4.1.
632 */
633 if (!tls1_transcript_hash_init(s))
634 goto err;
635 if (!tls1_transcript_hash_value(s, buf, sizeof(buf), &hash_len))
636 goto err;
637
638 if ((hm = tls13_handshake_msg_new()) == NULL)
639 goto err;
640 if (!tls13_handshake_msg_start(hm, &cbb, TLS13_MT_MESSAGE_HASH))
641 goto err;
642 if (!CBB_add_bytes(&cbb, buf, hash_len))
643 goto err;
644 if (!tls13_handshake_msg_finish(hm))
645 goto err;
646
647 tls13_handshake_msg_data(hm, &cbs);
648
649 tls1_transcript_reset(ctx->ssl);
650 if (!tls1_transcript_record(ctx->ssl, CBS_data(&cbs), CBS_len(&cbs)))
651 goto err;
652
653 ret = 1;
654
655 err:
656 tls13_handshake_msg_free(hm);
657
658 return ret;
659}
660
661int
662tls13_clienthello_hash_init(struct tls13_ctx *ctx)
663{
664 if (ctx->hs->tls13.clienthello_md_ctx != NULL)
665 return 0;
666 if ((ctx->hs->tls13.clienthello_md_ctx = EVP_MD_CTX_new()) == NULL)
667 return 0;
668 if (!EVP_DigestInit_ex(ctx->hs->tls13.clienthello_md_ctx,
669 EVP_sha256(), NULL))
670 return 0;
671
672 if ((ctx->hs->tls13.clienthello_hash == NULL) &&
673 (ctx->hs->tls13.clienthello_hash = calloc(1, EVP_MAX_MD_SIZE)) ==
674 NULL)
675 return 0;
676
677 return 1;
678}
679
680void
681tls13_clienthello_hash_clear(struct ssl_handshake_tls13_st *hs) /* XXX */
682{
683 EVP_MD_CTX_free(hs->clienthello_md_ctx);
684 hs->clienthello_md_ctx = NULL;
685 freezero(hs->clienthello_hash, EVP_MAX_MD_SIZE);
686 hs->clienthello_hash = NULL;
687}
688
689int
690tls13_clienthello_hash_update_bytes(struct tls13_ctx *ctx, void *data,
691 size_t len)
692{
693 return EVP_DigestUpdate(ctx->hs->tls13.clienthello_md_ctx, data, len);
694}
695
696int
697tls13_clienthello_hash_update(struct tls13_ctx *ctx, CBS *cbs)
698{
699 return tls13_clienthello_hash_update_bytes(ctx, (void *)CBS_data(cbs),
700 CBS_len(cbs));
701}
702
703int
704tls13_clienthello_hash_finalize(struct tls13_ctx *ctx)
705{
706 if (!EVP_DigestFinal_ex(ctx->hs->tls13.clienthello_md_ctx,
707 ctx->hs->tls13.clienthello_hash,
708 &ctx->hs->tls13.clienthello_hash_len))
709 return 0;
710 EVP_MD_CTX_free(ctx->hs->tls13.clienthello_md_ctx);
711 ctx->hs->tls13.clienthello_md_ctx = NULL;
712 return 1;
713}
714
715int
716tls13_clienthello_hash_validate(struct tls13_ctx *ctx)
717{
718 unsigned char new_ch_hash[EVP_MAX_MD_SIZE];
719 unsigned int new_ch_hash_len;
720
721 if (ctx->hs->tls13.clienthello_hash == NULL)
722 return 0;
723
724 if (!EVP_DigestFinal_ex(ctx->hs->tls13.clienthello_md_ctx,
725 new_ch_hash, &new_ch_hash_len))
726 return 0;
727 EVP_MD_CTX_free(ctx->hs->tls13.clienthello_md_ctx);
728 ctx->hs->tls13.clienthello_md_ctx = NULL;
729
730 if (ctx->hs->tls13.clienthello_hash_len != new_ch_hash_len)
731 return 0;
732 if (memcmp(ctx->hs->tls13.clienthello_hash, new_ch_hash,
733 new_ch_hash_len) != 0)
734 return 0;
735
736 return 1;
737}
diff --git a/src/lib/libssl/tls13_quic.c b/src/lib/libssl/tls13_quic.c
deleted file mode 100644
index 656af6fe6b..0000000000
--- a/src/lib/libssl/tls13_quic.c
+++ /dev/null
@@ -1,191 +0,0 @@
1/* $OpenBSD: tls13_quic.c,v 1.8 2024/09/09 03:55:55 tb Exp $ */
2/*
3 * Copyright (c) 2022 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "ssl_local.h"
19#include "tls13_internal.h"
20
21static ssize_t
22tls13_quic_wire_read_cb(void *buf, size_t n, void *arg)
23{
24 struct tls13_ctx *ctx = arg;
25 SSL *ssl = ctx->ssl;
26
27 SSLerror(ssl, SSL_R_QUIC_INTERNAL_ERROR);
28 return TLS13_IO_FAILURE;
29}
30
31static ssize_t
32tls13_quic_wire_write_cb(const void *buf, size_t n, void *arg)
33{
34 struct tls13_ctx *ctx = arg;
35 SSL *ssl = ctx->ssl;
36
37 SSLerror(ssl, SSL_R_QUIC_INTERNAL_ERROR);
38 return TLS13_IO_FAILURE;
39}
40
41static ssize_t
42tls13_quic_wire_flush_cb(void *arg)
43{
44 struct tls13_ctx *ctx = arg;
45 SSL *ssl = ctx->ssl;
46
47 if (!ssl->quic_method->flush_flight(ssl)) {
48 SSLerror(ssl, SSL_R_QUIC_INTERNAL_ERROR);
49 return TLS13_IO_FAILURE;
50 }
51
52 return TLS13_IO_SUCCESS;
53}
54
55static ssize_t
56tls13_quic_handshake_read_cb(void *buf, size_t n, void *arg)
57{
58 struct tls13_ctx *ctx = arg;
59
60 if (ctx->hs->tls13.quic_read_buffer == NULL)
61 return TLS13_IO_WANT_POLLIN;
62
63 return tls_buffer_read(ctx->hs->tls13.quic_read_buffer, buf, n);
64}
65
66static ssize_t
67tls13_quic_handshake_write_cb(const void *buf, size_t n, void *arg)
68{
69 struct tls13_ctx *ctx = arg;
70 SSL *ssl = ctx->ssl;
71
72 if (!ssl->quic_method->add_handshake_data(ssl,
73 ctx->hs->tls13.quic_write_level, buf, n)) {
74 SSLerror(ssl, SSL_R_QUIC_INTERNAL_ERROR);
75 return TLS13_IO_FAILURE;
76 }
77
78 return n;
79}
80
81static int
82tls13_quic_set_read_traffic_key(struct tls13_secret *read_key,
83 enum ssl_encryption_level_t read_level, void *arg)
84{
85 struct tls13_ctx *ctx = arg;
86 SSL *ssl = ctx->ssl;
87
88 ctx->hs->tls13.quic_read_level = read_level;
89
90 /* Handle both the new (BoringSSL) and old (quictls) APIs. */
91
92 if (ssl->quic_method->set_read_secret != NULL)
93 return ssl->quic_method->set_read_secret(ssl,
94 ctx->hs->tls13.quic_read_level, ctx->hs->cipher,
95 read_key->data, read_key->len);
96
97 if (ssl->quic_method->set_encryption_secrets != NULL)
98 return ssl->quic_method->set_encryption_secrets(ssl,
99 ctx->hs->tls13.quic_read_level, read_key->data, NULL,
100 read_key->len);
101
102 return 0;
103}
104
105static int
106tls13_quic_set_write_traffic_key(struct tls13_secret *write_key,
107 enum ssl_encryption_level_t write_level, void *arg)
108{
109 struct tls13_ctx *ctx = arg;
110 SSL *ssl = ctx->ssl;
111
112 ctx->hs->tls13.quic_write_level = write_level;
113
114 /* Handle both the new (BoringSSL) and old (quictls) APIs. */
115
116 if (ssl->quic_method->set_write_secret != NULL)
117 return ssl->quic_method->set_write_secret(ssl,
118 ctx->hs->tls13.quic_write_level, ctx->hs->cipher,
119 write_key->data, write_key->len);
120
121 if (ssl->quic_method->set_encryption_secrets != NULL)
122 return ssl->quic_method->set_encryption_secrets(ssl,
123 ctx->hs->tls13.quic_write_level, NULL, write_key->data,
124 write_key->len);
125
126 return 0;
127}
128
129static int
130tls13_quic_alert_send_cb(int alert_desc, void *arg)
131{
132 struct tls13_ctx *ctx = arg;
133 SSL *ssl = ctx->ssl;
134 uint8_t alert_level = TLS13_ALERT_LEVEL_FATAL;
135 int ret = TLS13_IO_ALERT;
136
137 if (!ssl->quic_method->send_alert(ssl, ctx->hs->tls13.quic_write_level,
138 alert_desc)) {
139 SSLerror(ssl, SSL_R_QUIC_INTERNAL_ERROR);
140 return TLS13_IO_FAILURE;
141 }
142
143 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY ||
144 alert_desc == TLS13_ALERT_USER_CANCELED) {
145 alert_level = TLS13_ALERT_LEVEL_WARNING;
146 ret = TLS13_IO_SUCCESS;
147 }
148
149 tls13_record_layer_alert_sent(ctx->rl, alert_level, alert_desc);
150
151 return ret;
152}
153
154static const struct tls13_record_layer_callbacks quic_rl_callbacks = {
155 .wire_read = tls13_quic_wire_read_cb,
156 .wire_write = tls13_quic_wire_write_cb,
157 .wire_flush = tls13_quic_wire_flush_cb,
158
159 .handshake_read = tls13_quic_handshake_read_cb,
160 .handshake_write = tls13_quic_handshake_write_cb,
161 .set_read_traffic_key = tls13_quic_set_read_traffic_key,
162 .set_write_traffic_key = tls13_quic_set_write_traffic_key,
163 .alert_send = tls13_quic_alert_send_cb,
164
165 .alert_recv = tls13_alert_received_cb,
166 .alert_sent = tls13_alert_sent_cb,
167 .phh_recv = tls13_phh_received_cb,
168 .phh_sent = tls13_phh_done_cb,
169};
170
171int
172tls13_quic_init(struct tls13_ctx *ctx)
173{
174 BIO *bio;
175
176 tls13_record_layer_set_callbacks(ctx->rl, &quic_rl_callbacks, ctx);
177
178 ctx->middlebox_compat = 0;
179
180 /*
181 * QUIC does not use BIOs, however we currently expect a BIO to exist
182 * for status handling.
183 */
184 if ((bio = BIO_new(BIO_s_null())) == NULL)
185 return 0;
186
187 SSL_set_bio(ctx->ssl, bio, bio);
188 bio = NULL;
189
190 return 1;
191}
diff --git a/src/lib/libssl/tls13_record.c b/src/lib/libssl/tls13_record.c
deleted file mode 100644
index dbc835c546..0000000000
--- a/src/lib/libssl/tls13_record.c
+++ /dev/null
@@ -1,186 +0,0 @@
1/* $OpenBSD: tls13_record.c,v 1.10 2022/07/22 19:33:53 jsing Exp $ */
2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "tls13_internal.h"
19#include "tls13_record.h"
20
21struct tls13_record {
22 uint16_t version;
23 uint8_t content_type;
24 size_t rec_len;
25 uint8_t *data;
26 size_t data_len;
27 CBS cbs;
28
29 struct tls_buffer *buf;
30};
31
32struct tls13_record *
33tls13_record_new(void)
34{
35 struct tls13_record *rec = NULL;
36
37 if ((rec = calloc(1, sizeof(struct tls13_record))) == NULL)
38 goto err;
39 if ((rec->buf = tls_buffer_new(TLS13_RECORD_MAX_LEN)) == NULL)
40 goto err;
41
42 return rec;
43
44 err:
45 tls13_record_free(rec);
46
47 return NULL;
48}
49
50void
51tls13_record_free(struct tls13_record *rec)
52{
53 if (rec == NULL)
54 return;
55
56 tls_buffer_free(rec->buf);
57
58 freezero(rec->data, rec->data_len);
59 freezero(rec, sizeof(struct tls13_record));
60}
61
62uint16_t
63tls13_record_version(struct tls13_record *rec)
64{
65 return rec->version;
66}
67
68uint8_t
69tls13_record_content_type(struct tls13_record *rec)
70{
71 return rec->content_type;
72}
73
74int
75tls13_record_header(struct tls13_record *rec, CBS *cbs)
76{
77 if (rec->data_len < TLS13_RECORD_HEADER_LEN)
78 return 0;
79
80 CBS_init(cbs, rec->data, TLS13_RECORD_HEADER_LEN);
81
82 return 1;
83}
84
85int
86tls13_record_content(struct tls13_record *rec, CBS *cbs)
87{
88 CBS content;
89
90 tls13_record_data(rec, &content);
91
92 if (!CBS_skip(&content, TLS13_RECORD_HEADER_LEN))
93 return 0;
94
95 CBS_dup(&content, cbs);
96
97 return 1;
98}
99
100void
101tls13_record_data(struct tls13_record *rec, CBS *cbs)
102{
103 CBS_init(cbs, rec->data, rec->data_len);
104}
105
106int
107tls13_record_set_data(struct tls13_record *rec, uint8_t *data, size_t data_len)
108{
109 if (data_len > TLS13_RECORD_MAX_LEN)
110 return 0;
111
112 freezero(rec->data, rec->data_len);
113 rec->data = data;
114 rec->data_len = data_len;
115 CBS_init(&rec->cbs, rec->data, rec->data_len);
116
117 return 1;
118}
119
120ssize_t
121tls13_record_recv(struct tls13_record *rec, tls_read_cb wire_read,
122 void *wire_arg)
123{
124 uint16_t rec_len, rec_version;
125 uint8_t content_type;
126 ssize_t ret;
127 CBS cbs;
128
129 if (rec->data != NULL)
130 return TLS13_IO_FAILURE;
131
132 if (rec->content_type == 0) {
133 if ((ret = tls_buffer_extend(rec->buf,
134 TLS13_RECORD_HEADER_LEN, wire_read, wire_arg)) <= 0)
135 return ret;
136
137 if (!tls_buffer_data(rec->buf, &cbs))
138 return TLS13_IO_FAILURE;
139
140 if (!CBS_get_u8(&cbs, &content_type))
141 return TLS13_IO_FAILURE;
142 if (!CBS_get_u16(&cbs, &rec_version))
143 return TLS13_IO_FAILURE;
144 if (!CBS_get_u16(&cbs, &rec_len))
145 return TLS13_IO_FAILURE;
146
147 if ((rec_version >> 8) != SSL3_VERSION_MAJOR)
148 return TLS13_IO_RECORD_VERSION;
149 if (rec_len > TLS13_RECORD_MAX_CIPHERTEXT_LEN)
150 return TLS13_IO_RECORD_OVERFLOW;
151
152 rec->content_type = content_type;
153 rec->version = rec_version;
154 rec->rec_len = rec_len;
155 }
156
157 if ((ret = tls_buffer_extend(rec->buf,
158 TLS13_RECORD_HEADER_LEN + rec->rec_len, wire_read, wire_arg)) <= 0)
159 return ret;
160
161 if (!tls_buffer_finish(rec->buf, &rec->data, &rec->data_len))
162 return TLS13_IO_FAILURE;
163
164 return rec->data_len;
165}
166
167ssize_t
168tls13_record_send(struct tls13_record *rec, tls_write_cb wire_write,
169 void *wire_arg)
170{
171 ssize_t ret;
172
173 if (rec->data == NULL)
174 return TLS13_IO_FAILURE;
175
176 while (CBS_len(&rec->cbs) > 0) {
177 if ((ret = wire_write(CBS_data(&rec->cbs),
178 CBS_len(&rec->cbs), wire_arg)) <= 0)
179 return ret;
180
181 if (!CBS_skip(&rec->cbs, ret))
182 return TLS13_IO_FAILURE;
183 }
184
185 return rec->data_len;
186}
diff --git a/src/lib/libssl/tls13_record.h b/src/lib/libssl/tls13_record.h
deleted file mode 100644
index 18e4fa1aba..0000000000
--- a/src/lib/libssl/tls13_record.h
+++ /dev/null
@@ -1,66 +0,0 @@
1/* $OpenBSD: tls13_record.h,v 1.5 2021/10/23 13:12:14 jsing Exp $ */
2/*
3 * Copyright (c) 2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef HEADER_TLS13_RECORD_H
19#define HEADER_TLS13_RECORD_H
20
21#include "bytestring.h"
22
23__BEGIN_HIDDEN_DECLS
24
25/*
26 * TLSv1.3 Record Protocol - RFC 8446 section 5.
27 *
28 * The maximum plaintext is 2^14, however for inner plaintext an additional
29 * byte is allowed for the content type. A maximum AEAD overhead of 255-bytes
30 * is permitted, along with a 5-byte header, giving a maximum size of
31 * 5 + 2^14 + 1 + 255 = 16,645-bytes.
32 */
33#define TLS13_RECORD_HEADER_LEN 5
34#define TLS13_RECORD_MAX_AEAD_OVERHEAD 255
35#define TLS13_RECORD_MAX_PLAINTEXT_LEN 16384
36#define TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN \
37 (TLS13_RECORD_MAX_PLAINTEXT_LEN + 1)
38#define TLS13_RECORD_MAX_CIPHERTEXT_LEN \
39 (TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN + TLS13_RECORD_MAX_AEAD_OVERHEAD)
40#define TLS13_RECORD_MAX_LEN \
41 (TLS13_RECORD_HEADER_LEN + TLS13_RECORD_MAX_CIPHERTEXT_LEN)
42
43/*
44 * TLSv1.3 Per-Record Nonces and Sequence Numbers - RFC 8446 section 5.3.
45 */
46#define TLS13_RECORD_SEQ_NUM_LEN 8
47
48struct tls13_record;
49
50struct tls13_record *tls13_record_new(void);
51void tls13_record_free(struct tls13_record *_rec);
52uint16_t tls13_record_version(struct tls13_record *_rec);
53uint8_t tls13_record_content_type(struct tls13_record *_rec);
54int tls13_record_header(struct tls13_record *_rec, CBS *_cbs);
55int tls13_record_content(struct tls13_record *_rec, CBS *_cbs);
56void tls13_record_data(struct tls13_record *_rec, CBS *_cbs);
57int tls13_record_set_data(struct tls13_record *_rec, uint8_t *_data,
58 size_t _data_len);
59ssize_t tls13_record_recv(struct tls13_record *_rec, tls_read_cb _wire_read,
60 void *_wire_arg);
61ssize_t tls13_record_send(struct tls13_record *_rec, tls_write_cb _wire_write,
62 void *_wire_arg);
63
64__END_HIDDEN_DECLS
65
66#endif
diff --git a/src/lib/libssl/tls13_record_layer.c b/src/lib/libssl/tls13_record_layer.c
deleted file mode 100644
index f5604adbeb..0000000000
--- a/src/lib/libssl/tls13_record_layer.c
+++ /dev/null
@@ -1,1229 +0,0 @@
1/* $OpenBSD: tls13_record_layer.c,v 1.74 2024/09/09 03:32:29 tb Exp $ */
2/*
3 * Copyright (c) 2018, 2019 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "tls13_internal.h"
19#include "tls13_record.h"
20#include "tls_content.h"
21
22static ssize_t tls13_record_layer_write_chunk(struct tls13_record_layer *rl,
23 uint8_t content_type, const uint8_t *buf, size_t n);
24static ssize_t tls13_record_layer_write_record(struct tls13_record_layer *rl,
25 uint8_t content_type, const uint8_t *content, size_t content_len);
26
27struct tls13_record_protection {
28 EVP_AEAD_CTX *aead_ctx;
29 struct tls13_secret iv;
30 struct tls13_secret nonce;
31 uint8_t seq_num[TLS13_RECORD_SEQ_NUM_LEN];
32};
33
34struct tls13_record_protection *
35tls13_record_protection_new(void)
36{
37 return calloc(1, sizeof(struct tls13_record_protection));
38}
39
40void
41tls13_record_protection_clear(struct tls13_record_protection *rp)
42{
43 EVP_AEAD_CTX_free(rp->aead_ctx);
44
45 tls13_secret_cleanup(&rp->iv);
46 tls13_secret_cleanup(&rp->nonce);
47
48 memset(rp, 0, sizeof(*rp));
49}
50
51void
52tls13_record_protection_free(struct tls13_record_protection *rp)
53{
54 if (rp == NULL)
55 return;
56
57 tls13_record_protection_clear(rp);
58
59 freezero(rp, sizeof(struct tls13_record_protection));
60}
61
62struct tls13_record_layer {
63 uint16_t legacy_version;
64
65 int ccs_allowed;
66 int ccs_seen;
67 int ccs_sent;
68 int handshake_completed;
69 int legacy_alerts_allowed;
70 int phh;
71 int phh_retry;
72
73 /*
74 * Read and/or write channels are closed due to an alert being
75 * sent or received. In the case of an error alert both channels
76 * are closed, whereas in the case of a close notify only one
77 * channel is closed.
78 */
79 int read_closed;
80 int write_closed;
81
82 struct tls13_record *rrec;
83
84 struct tls13_record *wrec;
85 uint8_t wrec_content_type;
86 size_t wrec_appdata_len;
87 size_t wrec_content_len;
88
89 /* Alert to be sent on return from current read handler. */
90 uint8_t alert;
91
92 /* Pending alert messages. */
93 uint8_t *alert_data;
94 size_t alert_len;
95 uint8_t alert_level;
96 uint8_t alert_desc;
97
98 /* Pending post-handshake handshake messages (RFC 8446, section 4.6). */
99 CBS phh_cbs;
100 uint8_t *phh_data;
101 size_t phh_len;
102
103 /* Content from opened records. */
104 struct tls_content *rcontent;
105
106 /* Record protection. */
107 const EVP_MD *hash;
108 const EVP_AEAD *aead;
109 struct tls13_record_protection *read;
110 struct tls13_record_protection *write;
111
112 /* Callbacks. */
113 struct tls13_record_layer_callbacks cb;
114 void *cb_arg;
115};
116
117static void
118tls13_record_layer_rrec_free(struct tls13_record_layer *rl)
119{
120 tls13_record_free(rl->rrec);
121 rl->rrec = NULL;
122}
123
124static void
125tls13_record_layer_wrec_free(struct tls13_record_layer *rl)
126{
127 tls13_record_free(rl->wrec);
128 rl->wrec = NULL;
129}
130
131struct tls13_record_layer *
132tls13_record_layer_new(const struct tls13_record_layer_callbacks *callbacks,
133 void *cb_arg)
134{
135 struct tls13_record_layer *rl;
136
137 if ((rl = calloc(1, sizeof(struct tls13_record_layer))) == NULL)
138 goto err;
139
140 if ((rl->rcontent = tls_content_new()) == NULL)
141 goto err;
142
143 if ((rl->read = tls13_record_protection_new()) == NULL)
144 goto err;
145 if ((rl->write = tls13_record_protection_new()) == NULL)
146 goto err;
147
148 rl->legacy_version = TLS1_2_VERSION;
149
150 tls13_record_layer_set_callbacks(rl, callbacks, cb_arg);
151
152 return rl;
153
154 err:
155 tls13_record_layer_free(rl);
156
157 return NULL;
158}
159
160void
161tls13_record_layer_free(struct tls13_record_layer *rl)
162{
163 if (rl == NULL)
164 return;
165
166 tls13_record_layer_rrec_free(rl);
167 tls13_record_layer_wrec_free(rl);
168
169 freezero(rl->alert_data, rl->alert_len);
170 freezero(rl->phh_data, rl->phh_len);
171
172 tls_content_free(rl->rcontent);
173
174 tls13_record_protection_free(rl->read);
175 tls13_record_protection_free(rl->write);
176
177 freezero(rl, sizeof(struct tls13_record_layer));
178}
179
180void
181tls13_record_layer_set_callbacks(struct tls13_record_layer *rl,
182 const struct tls13_record_layer_callbacks *callbacks, void *cb_arg)
183{
184 rl->cb = *callbacks;
185 rl->cb_arg = cb_arg;
186}
187
188void
189tls13_record_layer_rcontent(struct tls13_record_layer *rl, CBS *cbs)
190{
191 CBS_dup(tls_content_cbs(rl->rcontent), cbs);
192}
193
194static const uint8_t tls13_max_seq_num[TLS13_RECORD_SEQ_NUM_LEN] = {
195 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
196};
197
198int
199tls13_record_layer_inc_seq_num(uint8_t *seq_num)
200{
201 int i;
202
203 /* RFC 8446 section 5.3 - sequence numbers must not wrap. */
204 if (memcmp(seq_num, tls13_max_seq_num, TLS13_RECORD_SEQ_NUM_LEN) == 0)
205 return 0;
206
207 for (i = TLS13_RECORD_SEQ_NUM_LEN - 1; i >= 0; i--) {
208 if (++seq_num[i] != 0)
209 break;
210 }
211
212 return 1;
213}
214
215static int
216tls13_record_layer_update_nonce(struct tls13_secret *nonce,
217 struct tls13_secret *iv, uint8_t *seq_num)
218{
219 ssize_t i, j;
220
221 if (nonce->len != iv->len)
222 return 0;
223
224 /*
225 * RFC 8446 section 5.3 - sequence number is zero padded and XOR'd
226 * with the IV to produce a per-record nonce. The IV will also be
227 * at least 8-bytes in length.
228 */
229 for (i = nonce->len - 1, j = TLS13_RECORD_SEQ_NUM_LEN - 1; i >= 0; i--, j--)
230 nonce->data[i] = iv->data[i] ^ (j >= 0 ? seq_num[j] : 0);
231
232 return 1;
233}
234
235void
236tls13_record_layer_allow_ccs(struct tls13_record_layer *rl, int allow)
237{
238 rl->ccs_allowed = allow;
239}
240
241void
242tls13_record_layer_allow_legacy_alerts(struct tls13_record_layer *rl, int allow)
243{
244 rl->legacy_alerts_allowed = allow;
245}
246
247void
248tls13_record_layer_set_aead(struct tls13_record_layer *rl,
249 const EVP_AEAD *aead)
250{
251 rl->aead = aead;
252}
253
254void
255tls13_record_layer_set_hash(struct tls13_record_layer *rl,
256 const EVP_MD *hash)
257{
258 rl->hash = hash;
259}
260
261void
262tls13_record_layer_set_legacy_version(struct tls13_record_layer *rl,
263 uint16_t version)
264{
265 rl->legacy_version = version;
266}
267
268void
269tls13_record_layer_handshake_completed(struct tls13_record_layer *rl)
270{
271 rl->handshake_completed = 1;
272}
273
274void
275tls13_record_layer_set_retry_after_phh(struct tls13_record_layer *rl, int retry)
276{
277 rl->phh_retry = retry;
278}
279
280static ssize_t
281tls13_record_layer_process_alert(struct tls13_record_layer *rl)
282{
283 uint8_t alert_level, alert_desc;
284 ssize_t ret = TLS13_IO_FAILURE;
285
286 /*
287 * RFC 8446 - sections 5.1 and 6.
288 *
289 * A TLSv1.3 alert record can only contain a single alert - this means
290 * that processing the alert must consume all of the record. The alert
291 * will result in one of three things - continuation (user_cancelled),
292 * read channel closure (close_notify) or termination (all others).
293 */
294 if (tls_content_type(rl->rcontent) != SSL3_RT_ALERT)
295 return TLS13_IO_FAILURE;
296
297 if (!CBS_get_u8(tls_content_cbs(rl->rcontent), &alert_level))
298 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
299 if (!CBS_get_u8(tls_content_cbs(rl->rcontent), &alert_desc))
300 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
301
302 if (tls_content_remaining(rl->rcontent) != 0)
303 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
304
305 tls_content_clear(rl->rcontent);
306
307 /*
308 * Alert level is ignored for closure alerts (RFC 8446 section 6.1),
309 * however for error alerts (RFC 8446 section 6.2), the alert level
310 * must be specified as fatal.
311 */
312 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
313 rl->read_closed = 1;
314 ret = TLS13_IO_EOF;
315 } else if (alert_desc == TLS13_ALERT_USER_CANCELED) {
316 /* Ignored at the record layer. */
317 ret = TLS13_IO_WANT_RETRY;
318 } else if (alert_level == TLS13_ALERT_LEVEL_FATAL) {
319 rl->read_closed = 1;
320 rl->write_closed = 1;
321 ret = TLS13_IO_ALERT;
322 } else if (rl->legacy_alerts_allowed &&
323 alert_level == TLS13_ALERT_LEVEL_WARNING) {
324 /* Ignored and not passed to the callback. */
325 return TLS13_IO_WANT_RETRY;
326 } else {
327 return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER);
328 }
329
330 rl->cb.alert_recv(alert_level, alert_desc, rl->cb_arg);
331
332 return ret;
333}
334
335void
336tls13_record_layer_alert_sent(struct tls13_record_layer *rl,
337 uint8_t alert_level, uint8_t alert_desc)
338{
339 rl->cb.alert_sent(alert_level, alert_desc, rl->cb_arg);
340}
341
342static ssize_t
343tls13_record_layer_send_alert(struct tls13_record_layer *rl)
344{
345 ssize_t ret;
346
347 /* This has to fit into a single record, per RFC 8446 section 5.1. */
348 if ((ret = tls13_record_layer_write_record(rl, SSL3_RT_ALERT,
349 rl->alert_data, rl->alert_len)) != rl->alert_len) {
350 if (ret == TLS13_IO_EOF)
351 ret = TLS13_IO_ALERT;
352 return ret;
353 }
354
355 freezero(rl->alert_data, rl->alert_len);
356 rl->alert_data = NULL;
357 rl->alert_len = 0;
358
359 if (rl->alert_desc == TLS13_ALERT_CLOSE_NOTIFY) {
360 rl->write_closed = 1;
361 ret = TLS13_IO_SUCCESS;
362 } else if (rl->alert_desc == TLS13_ALERT_USER_CANCELED) {
363 /* Ignored at the record layer. */
364 ret = TLS13_IO_SUCCESS;
365 } else {
366 rl->read_closed = 1;
367 rl->write_closed = 1;
368 ret = TLS13_IO_ALERT;
369 }
370
371 tls13_record_layer_alert_sent(rl, rl->alert_level, rl->alert_desc);
372
373 return ret;
374}
375
376static ssize_t
377tls13_record_layer_send_phh(struct tls13_record_layer *rl)
378{
379 ssize_t ret;
380
381 /* Push out pending post-handshake handshake messages. */
382 if ((ret = tls13_record_layer_write_chunk(rl, SSL3_RT_HANDSHAKE,
383 CBS_data(&rl->phh_cbs), CBS_len(&rl->phh_cbs))) <= 0)
384 return ret;
385 if (!CBS_skip(&rl->phh_cbs, ret))
386 return TLS13_IO_FAILURE;
387 if (CBS_len(&rl->phh_cbs) != 0)
388 return TLS13_IO_WANT_RETRY;
389
390 freezero(rl->phh_data, rl->phh_len);
391 rl->phh_data = NULL;
392 rl->phh_len = 0;
393
394 CBS_init(&rl->phh_cbs, rl->phh_data, rl->phh_len);
395
396 rl->cb.phh_sent(rl->cb_arg);
397
398 return TLS13_IO_SUCCESS;
399}
400
401ssize_t
402tls13_record_layer_send_pending(struct tls13_record_layer *rl)
403{
404 /*
405 * If an alert is pending, then it needs to be sent. However,
406 * if we're already part of the way through sending post-handshake
407 * handshake messages, then we need to finish that first...
408 */
409
410 if (rl->phh_data != NULL && CBS_len(&rl->phh_cbs) != rl->phh_len)
411 return tls13_record_layer_send_phh(rl);
412
413 if (rl->alert_data != NULL)
414 return tls13_record_layer_send_alert(rl);
415
416 if (rl->phh_data != NULL)
417 return tls13_record_layer_send_phh(rl);
418
419 return TLS13_IO_SUCCESS;
420}
421
422static ssize_t
423tls13_record_layer_enqueue_alert(struct tls13_record_layer *rl,
424 uint8_t alert_level, uint8_t alert_desc)
425{
426 CBB cbb;
427
428 if (rl->alert_data != NULL)
429 return TLS13_IO_FAILURE;
430
431 if (!CBB_init(&cbb, 0))
432 goto err;
433
434 if (!CBB_add_u8(&cbb, alert_level))
435 goto err;
436 if (!CBB_add_u8(&cbb, alert_desc))
437 goto err;
438 if (!CBB_finish(&cbb, &rl->alert_data, &rl->alert_len))
439 goto err;
440
441 rl->alert_level = alert_level;
442 rl->alert_desc = alert_desc;
443
444 return tls13_record_layer_send_pending(rl);
445
446 err:
447 CBB_cleanup(&cbb);
448
449 return TLS13_IO_FAILURE;
450}
451
452ssize_t
453tls13_record_layer_phh(struct tls13_record_layer *rl, CBS *cbs)
454{
455 if (rl->phh_data != NULL)
456 return TLS13_IO_FAILURE;
457
458 if (!CBS_stow(cbs, &rl->phh_data, &rl->phh_len))
459 return TLS13_IO_FAILURE;
460
461 CBS_init(&rl->phh_cbs, rl->phh_data, rl->phh_len);
462
463 return tls13_record_layer_send_pending(rl);
464}
465
466static int
467tls13_record_layer_set_traffic_key(const EVP_AEAD *aead, const EVP_MD *hash,
468 struct tls13_record_protection *rp, struct tls13_secret *traffic_key)
469{
470 struct tls13_secret context = { .data = "", .len = 0 };
471 struct tls13_secret key = { .data = NULL, .len = 0 };
472 int ret = 0;
473
474 tls13_record_protection_clear(rp);
475
476 if ((rp->aead_ctx = EVP_AEAD_CTX_new()) == NULL)
477 return 0;
478
479 if (!tls13_secret_init(&rp->iv, EVP_AEAD_nonce_length(aead)))
480 goto err;
481 if (!tls13_secret_init(&rp->nonce, EVP_AEAD_nonce_length(aead)))
482 goto err;
483 if (!tls13_secret_init(&key, EVP_AEAD_key_length(aead)))
484 goto err;
485
486 if (!tls13_hkdf_expand_label(&rp->iv, hash, traffic_key, "iv", &context))
487 goto err;
488 if (!tls13_hkdf_expand_label(&key, hash, traffic_key, "key", &context))
489 goto err;
490
491 if (!EVP_AEAD_CTX_init(rp->aead_ctx, aead, key.data, key.len,
492 EVP_AEAD_DEFAULT_TAG_LENGTH, NULL))
493 goto err;
494
495 ret = 1;
496
497 err:
498 tls13_secret_cleanup(&key);
499
500 return ret;
501}
502
503int
504tls13_record_layer_set_read_traffic_key(struct tls13_record_layer *rl,
505 struct tls13_secret *read_key, enum ssl_encryption_level_t read_level)
506{
507 if (rl->cb.set_read_traffic_key != NULL)
508 return rl->cb.set_read_traffic_key(read_key, read_level,
509 rl->cb_arg);
510
511 return tls13_record_layer_set_traffic_key(rl->aead, rl->hash,
512 rl->read, read_key);
513}
514
515int
516tls13_record_layer_set_write_traffic_key(struct tls13_record_layer *rl,
517 struct tls13_secret *write_key, enum ssl_encryption_level_t write_level)
518{
519 if (rl->cb.set_write_traffic_key != NULL)
520 return rl->cb.set_write_traffic_key(write_key, write_level,
521 rl->cb_arg);
522
523 return tls13_record_layer_set_traffic_key(rl->aead, rl->hash,
524 rl->write, write_key);
525}
526
527static int
528tls13_record_layer_open_record_plaintext(struct tls13_record_layer *rl)
529{
530 CBS cbs;
531
532 if (rl->aead != NULL)
533 return 0;
534
535 /*
536 * We're still operating in plaintext mode, so just copy the
537 * content from the record to the plaintext buffer.
538 */
539 if (!tls13_record_content(rl->rrec, &cbs))
540 return 0;
541
542 if (CBS_len(&cbs) > TLS13_RECORD_MAX_PLAINTEXT_LEN) {
543 rl->alert = TLS13_ALERT_RECORD_OVERFLOW;
544 return 0;
545 }
546
547 if (!tls_content_dup_data(rl->rcontent,
548 tls13_record_content_type(rl->rrec), CBS_data(&cbs), CBS_len(&cbs)))
549 return 0;
550
551 return 1;
552}
553
554static int
555tls13_record_layer_open_record_protected(struct tls13_record_layer *rl)
556{
557 CBS header, enc_record, inner;
558 uint8_t *content = NULL;
559 size_t content_len = 0;
560 uint8_t content_type;
561 size_t out_len;
562
563 if (rl->aead == NULL)
564 goto err;
565
566 if (!tls13_record_header(rl->rrec, &header))
567 goto err;
568 if (!tls13_record_content(rl->rrec, &enc_record))
569 goto err;
570
571 /* XXX - minus tag len? */
572 if ((content = calloc(1, CBS_len(&enc_record))) == NULL)
573 goto err;
574 content_len = CBS_len(&enc_record);
575
576 if (!tls13_record_layer_update_nonce(&rl->read->nonce, &rl->read->iv,
577 rl->read->seq_num))
578 goto err;
579
580 if (!EVP_AEAD_CTX_open(rl->read->aead_ctx,
581 content, &out_len, content_len,
582 rl->read->nonce.data, rl->read->nonce.len,
583 CBS_data(&enc_record), CBS_len(&enc_record),
584 CBS_data(&header), CBS_len(&header)))
585 goto err;
586
587 if (out_len > TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN) {
588 rl->alert = TLS13_ALERT_RECORD_OVERFLOW;
589 goto err;
590 }
591
592 if (!tls13_record_layer_inc_seq_num(rl->read->seq_num))
593 goto err;
594
595 /*
596 * The real content type is hidden at the end of the record content and
597 * it may be followed by padding that consists of one or more zeroes.
598 * Time to hunt for that elusive content type!
599 */
600 CBS_init(&inner, content, out_len);
601 content_type = 0;
602 while (CBS_get_last_u8(&inner, &content_type)) {
603 if (content_type != 0)
604 break;
605 }
606 if (content_type == 0) {
607 /* Unexpected message per RFC 8446 section 5.4. */
608 rl->alert = TLS13_ALERT_UNEXPECTED_MESSAGE;
609 goto err;
610 }
611 if (CBS_len(&inner) > TLS13_RECORD_MAX_PLAINTEXT_LEN) {
612 rl->alert = TLS13_ALERT_RECORD_OVERFLOW;
613 goto err;
614 }
615
616 tls_content_set_data(rl->rcontent, content_type, CBS_data(&inner),
617 CBS_len(&inner));
618
619 return 1;
620
621 err:
622 freezero(content, content_len);
623
624 return 0;
625}
626
627static int
628tls13_record_layer_open_record(struct tls13_record_layer *rl)
629{
630 if (rl->handshake_completed && rl->aead == NULL)
631 return 0;
632
633 if (rl->aead == NULL)
634 return tls13_record_layer_open_record_plaintext(rl);
635
636 return tls13_record_layer_open_record_protected(rl);
637}
638
639static int
640tls13_record_layer_seal_record_plaintext(struct tls13_record_layer *rl,
641 uint8_t content_type, const uint8_t *content, size_t content_len)
642{
643 uint8_t *data = NULL;
644 size_t data_len = 0;
645 CBB cbb, body;
646
647 /*
648 * Allow dummy CCS messages to be sent in plaintext even when
649 * record protection has been engaged, as long as the handshake
650 * has not yet completed.
651 */
652 if (rl->handshake_completed)
653 return 0;
654 if (rl->aead != NULL && content_type != SSL3_RT_CHANGE_CIPHER_SPEC)
655 return 0;
656
657 /*
658 * We're still operating in plaintext mode, so just copy the
659 * content into the record.
660 */
661 if (!CBB_init(&cbb, TLS13_RECORD_HEADER_LEN + content_len))
662 goto err;
663
664 if (!CBB_add_u8(&cbb, content_type))
665 goto err;
666 if (!CBB_add_u16(&cbb, rl->legacy_version))
667 goto err;
668 if (!CBB_add_u16_length_prefixed(&cbb, &body))
669 goto err;
670 if (!CBB_add_bytes(&body, content, content_len))
671 goto err;
672
673 if (!CBB_finish(&cbb, &data, &data_len))
674 goto err;
675
676 if (!tls13_record_set_data(rl->wrec, data, data_len))
677 goto err;
678
679 rl->wrec_content_len = content_len;
680 rl->wrec_content_type = content_type;
681
682 return 1;
683
684 err:
685 CBB_cleanup(&cbb);
686 freezero(data, data_len);
687
688 return 0;
689}
690
691static int
692tls13_record_layer_seal_record_protected(struct tls13_record_layer *rl,
693 uint8_t content_type, const uint8_t *content, size_t content_len)
694{
695 uint8_t *data = NULL, *header = NULL, *inner = NULL;
696 size_t data_len = 0, header_len = 0, inner_len = 0;
697 uint8_t *enc_record;
698 size_t enc_record_len;
699 ssize_t ret = 0;
700 size_t out_len;
701 CBB cbb;
702
703 if (rl->aead == NULL)
704 return 0;
705
706 memset(&cbb, 0, sizeof(cbb));
707
708 /* Build inner plaintext. */
709 if (!CBB_init(&cbb, content_len + 1))
710 goto err;
711 if (!CBB_add_bytes(&cbb, content, content_len))
712 goto err;
713 if (!CBB_add_u8(&cbb, content_type))
714 goto err;
715 /* XXX - padding? */
716 if (!CBB_finish(&cbb, &inner, &inner_len))
717 goto err;
718
719 if (inner_len > TLS13_RECORD_MAX_INNER_PLAINTEXT_LEN)
720 goto err;
721
722 /* XXX EVP_AEAD_max_tag_len vs EVP_AEAD_CTX_tag_len. */
723 enc_record_len = inner_len + EVP_AEAD_max_tag_len(rl->aead);
724 if (enc_record_len > TLS13_RECORD_MAX_CIPHERTEXT_LEN)
725 goto err;
726
727 /* Build the record header. */
728 if (!CBB_init(&cbb, TLS13_RECORD_HEADER_LEN))
729 goto err;
730 if (!CBB_add_u8(&cbb, SSL3_RT_APPLICATION_DATA))
731 goto err;
732 if (!CBB_add_u16(&cbb, TLS1_2_VERSION))
733 goto err;
734 if (!CBB_add_u16(&cbb, enc_record_len))
735 goto err;
736 if (!CBB_finish(&cbb, &header, &header_len))
737 goto err;
738
739 /* Build the actual record. */
740 if (!CBB_init(&cbb, TLS13_RECORD_HEADER_LEN + enc_record_len))
741 goto err;
742 if (!CBB_add_bytes(&cbb, header, header_len))
743 goto err;
744 if (!CBB_add_space(&cbb, &enc_record, enc_record_len))
745 goto err;
746 if (!CBB_finish(&cbb, &data, &data_len))
747 goto err;
748
749 if (!tls13_record_layer_update_nonce(&rl->write->nonce,
750 &rl->write->iv, rl->write->seq_num))
751 goto err;
752
753 /*
754 * XXX - consider a EVP_AEAD_CTX_seal_iov() that takes an iovec...
755 * this would avoid a copy since the inner would be passed as two
756 * separate pieces.
757 */
758 if (!EVP_AEAD_CTX_seal(rl->write->aead_ctx,
759 enc_record, &out_len, enc_record_len,
760 rl->write->nonce.data, rl->write->nonce.len,
761 inner, inner_len, header, header_len))
762 goto err;
763
764 if (out_len != enc_record_len)
765 goto err;
766
767 if (!tls13_record_layer_inc_seq_num(rl->write->seq_num))
768 goto err;
769
770 if (!tls13_record_set_data(rl->wrec, data, data_len))
771 goto err;
772
773 rl->wrec_content_len = content_len;
774 rl->wrec_content_type = content_type;
775
776 data = NULL;
777 data_len = 0;
778
779 ret = 1;
780
781 err:
782 CBB_cleanup(&cbb);
783
784 freezero(data, data_len);
785 freezero(header, header_len);
786 freezero(inner, inner_len);
787
788 return ret;
789}
790
791static int
792tls13_record_layer_seal_record(struct tls13_record_layer *rl,
793 uint8_t content_type, const uint8_t *content, size_t content_len)
794{
795 if (rl->handshake_completed && rl->aead == NULL)
796 return 0;
797
798 tls13_record_layer_wrec_free(rl);
799
800 if ((rl->wrec = tls13_record_new()) == NULL)
801 return 0;
802
803 if (rl->aead == NULL || content_type == SSL3_RT_CHANGE_CIPHER_SPEC)
804 return tls13_record_layer_seal_record_plaintext(rl,
805 content_type, content, content_len);
806
807 return tls13_record_layer_seal_record_protected(rl, content_type,
808 content, content_len);
809}
810
811static ssize_t
812tls13_record_layer_read_record(struct tls13_record_layer *rl)
813{
814 uint8_t content_type, ccs;
815 ssize_t ret;
816 CBS cbs;
817
818 if (rl->rrec == NULL) {
819 if ((rl->rrec = tls13_record_new()) == NULL)
820 goto err;
821 }
822
823 if ((ret = tls13_record_recv(rl->rrec, rl->cb.wire_read, rl->cb_arg)) <= 0) {
824 switch (ret) {
825 case TLS13_IO_RECORD_VERSION:
826 return tls13_send_alert(rl, TLS13_ALERT_PROTOCOL_VERSION);
827 case TLS13_IO_RECORD_OVERFLOW:
828 return tls13_send_alert(rl, TLS13_ALERT_RECORD_OVERFLOW);
829 }
830 return ret;
831 }
832
833 content_type = tls13_record_content_type(rl->rrec);
834
835 /*
836 * In response to a client hello we may receive an alert in a
837 * record with a legacy version. Otherwise enforce that the
838 * legacy record version is 0x0303 per RFC 8446, section 5.1.
839 */
840 if (rl->legacy_version == TLS1_2_VERSION &&
841 tls13_record_version(rl->rrec) != TLS1_2_VERSION &&
842 (content_type != SSL3_RT_ALERT || !rl->legacy_alerts_allowed))
843 return tls13_send_alert(rl, TLS13_ALERT_PROTOCOL_VERSION);
844
845 /*
846 * Bag of hacks ahead... after the first ClientHello message has been
847 * sent or received and before the peer's Finished message has been
848 * received, we may receive an unencrypted ChangeCipherSpec record
849 * (see RFC 8446 section 5 and appendix D.4). This record must be
850 * ignored.
851 */
852 if (content_type == SSL3_RT_CHANGE_CIPHER_SPEC) {
853 if (!rl->ccs_allowed || rl->ccs_seen >= 2)
854 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
855 if (!tls13_record_content(rl->rrec, &cbs))
856 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
857 if (!CBS_get_u8(&cbs, &ccs))
858 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
859 if (ccs != 1)
860 return tls13_send_alert(rl, TLS13_ALERT_ILLEGAL_PARAMETER);
861 if (CBS_len(&cbs) != 0)
862 return tls13_send_alert(rl, TLS13_ALERT_DECODE_ERROR);
863 rl->ccs_seen++;
864 tls13_record_layer_rrec_free(rl);
865 return TLS13_IO_WANT_RETRY;
866 }
867
868 /*
869 * Once record protection is engaged, we should only receive
870 * protected application data messages (aside from the
871 * dummy ChangeCipherSpec messages, handled above).
872 */
873 if (rl->aead != NULL && content_type != SSL3_RT_APPLICATION_DATA)
874 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
875
876 if (!tls13_record_layer_open_record(rl))
877 goto err;
878
879 tls13_record_layer_rrec_free(rl);
880
881 /*
882 * On receiving a handshake or alert record with empty inner plaintext,
883 * we must terminate the connection with an unexpected_message alert.
884 * See RFC 8446 section 5.4.
885 */
886 if (tls_content_remaining(rl->rcontent) == 0 &&
887 (tls_content_type(rl->rcontent) == SSL3_RT_ALERT ||
888 tls_content_type(rl->rcontent) == SSL3_RT_HANDSHAKE))
889 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
890
891 switch (tls_content_type(rl->rcontent)) {
892 case SSL3_RT_ALERT:
893 return tls13_record_layer_process_alert(rl);
894
895 case SSL3_RT_HANDSHAKE:
896 break;
897
898 case SSL3_RT_APPLICATION_DATA:
899 if (!rl->handshake_completed)
900 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
901 break;
902
903 default:
904 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
905 }
906
907 return TLS13_IO_SUCCESS;
908
909 err:
910 return TLS13_IO_FAILURE;
911}
912
913static ssize_t
914tls13_record_layer_pending(struct tls13_record_layer *rl, uint8_t content_type)
915{
916 if (tls_content_type(rl->rcontent) != content_type)
917 return 0;
918
919 return tls_content_remaining(rl->rcontent);
920}
921
922static ssize_t
923tls13_record_layer_recv_phh(struct tls13_record_layer *rl)
924{
925 ssize_t ret = TLS13_IO_FAILURE;
926
927 rl->phh = 1;
928
929 /*
930 * The post handshake handshake receive callback is allowed to return:
931 *
932 * TLS13_IO_WANT_POLLIN need more handshake data.
933 * TLS13_IO_WANT_POLLOUT got whole handshake message, response enqueued.
934 * TLS13_IO_SUCCESS got the whole handshake, nothing more to do.
935 * TLS13_IO_FAILURE something broke.
936 */
937 if (rl->cb.phh_recv != NULL)
938 ret = rl->cb.phh_recv(rl->cb_arg);
939
940 tls_content_clear(rl->rcontent);
941
942 /* Leave post handshake handshake mode unless we need more data. */
943 if (ret != TLS13_IO_WANT_POLLIN)
944 rl->phh = 0;
945
946 if (ret == TLS13_IO_SUCCESS) {
947 if (rl->phh_retry)
948 return TLS13_IO_WANT_RETRY;
949
950 return TLS13_IO_WANT_POLLIN;
951 }
952
953 return ret;
954}
955
956static ssize_t
957tls13_record_layer_read_internal(struct tls13_record_layer *rl,
958 uint8_t content_type, uint8_t *buf, size_t n, int peek)
959{
960 ssize_t ret;
961
962 if ((ret = tls13_record_layer_send_pending(rl)) != TLS13_IO_SUCCESS)
963 return ret;
964
965 if (rl->read_closed)
966 return TLS13_IO_EOF;
967
968 /* If necessary, pull up the next record. */
969 if (tls_content_remaining(rl->rcontent) == 0) {
970 if ((ret = tls13_record_layer_read_record(rl)) <= 0)
971 return ret;
972
973 /*
974 * We may have read a valid 0-byte application data record,
975 * in which case we need to read the next record.
976 */
977 if (tls_content_remaining(rl->rcontent) == 0)
978 return TLS13_IO_WANT_POLLIN;
979 }
980
981 /*
982 * If we are in post handshake handshake mode, we must not see
983 * any record type that isn't a handshake until we are done.
984 */
985 if (rl->phh && tls_content_type(rl->rcontent) != SSL3_RT_HANDSHAKE)
986 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
987
988 /*
989 * Handshake content can appear as post-handshake messages (yup,
990 * the RFC reused the same content type...), which means we can
991 * be trying to read application data and need to handle a
992 * post-handshake handshake message instead...
993 */
994 if (tls_content_type(rl->rcontent) != content_type) {
995 if (tls_content_type(rl->rcontent) == SSL3_RT_HANDSHAKE) {
996 if (rl->handshake_completed)
997 return tls13_record_layer_recv_phh(rl);
998 }
999 return tls13_send_alert(rl, TLS13_ALERT_UNEXPECTED_MESSAGE);
1000 }
1001
1002 if (peek)
1003 return tls_content_peek(rl->rcontent, buf, n);
1004
1005 return tls_content_read(rl->rcontent, buf, n);
1006}
1007
1008static ssize_t
1009tls13_record_layer_peek(struct tls13_record_layer *rl, uint8_t content_type,
1010 uint8_t *buf, size_t n)
1011{
1012 ssize_t ret;
1013
1014 do {
1015 ret = tls13_record_layer_read_internal(rl, content_type, buf, n, 1);
1016 } while (ret == TLS13_IO_WANT_RETRY);
1017
1018 if (rl->alert != 0)
1019 return tls13_send_alert(rl, rl->alert);
1020
1021 return ret;
1022}
1023
1024static ssize_t
1025tls13_record_layer_read(struct tls13_record_layer *rl, uint8_t content_type,
1026 uint8_t *buf, size_t n)
1027{
1028 ssize_t ret;
1029
1030 do {
1031 ret = tls13_record_layer_read_internal(rl, content_type, buf, n, 0);
1032 } while (ret == TLS13_IO_WANT_RETRY);
1033
1034 if (rl->alert != 0)
1035 return tls13_send_alert(rl, rl->alert);
1036
1037 return ret;
1038}
1039
1040static ssize_t
1041tls13_record_layer_write_record(struct tls13_record_layer *rl,
1042 uint8_t content_type, const uint8_t *content, size_t content_len)
1043{
1044 ssize_t ret;
1045
1046 if (rl->write_closed)
1047 return TLS13_IO_EOF;
1048
1049 /*
1050 * If we pushed out application data while handling other messages,
1051 * we need to return content length on the next call.
1052 */
1053 if (content_type == SSL3_RT_APPLICATION_DATA &&
1054 rl->wrec_appdata_len != 0) {
1055 ret = rl->wrec_appdata_len;
1056 rl->wrec_appdata_len = 0;
1057 return ret;
1058 }
1059
1060 /* See if there is an existing record and attempt to push it out... */
1061 if (rl->wrec != NULL) {
1062 if ((ret = tls13_record_send(rl->wrec, rl->cb.wire_write,
1063 rl->cb_arg)) <= 0)
1064 return ret;
1065 tls13_record_layer_wrec_free(rl);
1066
1067 if (rl->wrec_content_type == content_type) {
1068 ret = rl->wrec_content_len;
1069 rl->wrec_content_len = 0;
1070 rl->wrec_content_type = 0;
1071 return ret;
1072 }
1073
1074 /*
1075 * The only partial record type should be application data.
1076 * All other cases are handled to completion.
1077 */
1078 if (rl->wrec_content_type != SSL3_RT_APPLICATION_DATA)
1079 return TLS13_IO_FAILURE;
1080 rl->wrec_appdata_len = rl->wrec_content_len;
1081 }
1082
1083 if (content_len > TLS13_RECORD_MAX_PLAINTEXT_LEN)
1084 goto err;
1085
1086 if (!tls13_record_layer_seal_record(rl, content_type, content, content_len))
1087 goto err;
1088
1089 if ((ret = tls13_record_send(rl->wrec, rl->cb.wire_write, rl->cb_arg)) <= 0)
1090 return ret;
1091
1092 tls13_record_layer_wrec_free(rl);
1093
1094 return content_len;
1095
1096 err:
1097 return TLS13_IO_FAILURE;
1098}
1099
1100static ssize_t
1101tls13_record_layer_write_chunk(struct tls13_record_layer *rl,
1102 uint8_t content_type, const uint8_t *buf, size_t n)
1103{
1104 if (n > TLS13_RECORD_MAX_PLAINTEXT_LEN)
1105 n = TLS13_RECORD_MAX_PLAINTEXT_LEN;
1106
1107 return tls13_record_layer_write_record(rl, content_type, buf, n);
1108}
1109
1110static ssize_t
1111tls13_record_layer_write(struct tls13_record_layer *rl, uint8_t content_type,
1112 const uint8_t *buf, size_t n)
1113{
1114 ssize_t ret;
1115
1116 do {
1117 ret = tls13_record_layer_send_pending(rl);
1118 } while (ret == TLS13_IO_WANT_RETRY);
1119 if (ret != TLS13_IO_SUCCESS)
1120 return ret;
1121
1122 do {
1123 ret = tls13_record_layer_write_chunk(rl, content_type, buf, n);
1124 } while (ret == TLS13_IO_WANT_RETRY);
1125
1126 return ret;
1127}
1128
1129ssize_t
1130tls13_record_layer_flush(struct tls13_record_layer *rl)
1131{
1132 return rl->cb.wire_flush(rl->cb_arg);
1133}
1134
1135static const uint8_t tls13_dummy_ccs[] = { 0x01 };
1136
1137ssize_t
1138tls13_send_dummy_ccs(struct tls13_record_layer *rl)
1139{
1140 ssize_t ret;
1141
1142 if (rl->ccs_sent)
1143 return TLS13_IO_FAILURE;
1144
1145 if ((ret = tls13_record_layer_write(rl, SSL3_RT_CHANGE_CIPHER_SPEC,
1146 tls13_dummy_ccs, sizeof(tls13_dummy_ccs))) <= 0)
1147 return ret;
1148
1149 rl->ccs_sent = 1;
1150
1151 return TLS13_IO_SUCCESS;
1152}
1153
1154ssize_t
1155tls13_read_handshake_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n)
1156{
1157 if (rl->cb.handshake_read != NULL)
1158 return rl->cb.handshake_read(buf, n, rl->cb_arg);
1159
1160 return tls13_record_layer_read(rl, SSL3_RT_HANDSHAKE, buf, n);
1161}
1162
1163ssize_t
1164tls13_write_handshake_data(struct tls13_record_layer *rl, const uint8_t *buf,
1165 size_t n)
1166{
1167 if (rl->cb.handshake_write != NULL)
1168 return rl->cb.handshake_write(buf, n, rl->cb_arg);
1169
1170 return tls13_record_layer_write(rl, SSL3_RT_HANDSHAKE, buf, n);
1171}
1172
1173ssize_t
1174tls13_pending_application_data(struct tls13_record_layer *rl)
1175{
1176 if (!rl->handshake_completed)
1177 return 0;
1178
1179 return tls13_record_layer_pending(rl, SSL3_RT_APPLICATION_DATA);
1180}
1181
1182ssize_t
1183tls13_peek_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n)
1184{
1185 if (!rl->handshake_completed)
1186 return TLS13_IO_FAILURE;
1187
1188 return tls13_record_layer_peek(rl, SSL3_RT_APPLICATION_DATA, buf, n);
1189}
1190
1191ssize_t
1192tls13_read_application_data(struct tls13_record_layer *rl, uint8_t *buf, size_t n)
1193{
1194 if (!rl->handshake_completed)
1195 return TLS13_IO_FAILURE;
1196
1197 return tls13_record_layer_read(rl, SSL3_RT_APPLICATION_DATA, buf, n);
1198}
1199
1200ssize_t
1201tls13_write_application_data(struct tls13_record_layer *rl, const uint8_t *buf,
1202 size_t n)
1203{
1204 if (!rl->handshake_completed)
1205 return TLS13_IO_FAILURE;
1206
1207 return tls13_record_layer_write(rl, SSL3_RT_APPLICATION_DATA, buf, n);
1208}
1209
1210ssize_t
1211tls13_send_alert(struct tls13_record_layer *rl, uint8_t alert_desc)
1212{
1213 uint8_t alert_level = TLS13_ALERT_LEVEL_FATAL;
1214 ssize_t ret;
1215
1216 if (rl->cb.alert_send != NULL)
1217 return rl->cb.alert_send(alert_desc, rl->cb_arg);
1218
1219 if (alert_desc == TLS13_ALERT_CLOSE_NOTIFY ||
1220 alert_desc == TLS13_ALERT_USER_CANCELED)
1221 alert_level = TLS13_ALERT_LEVEL_WARNING;
1222
1223 do {
1224 ret = tls13_record_layer_enqueue_alert(rl, alert_level,
1225 alert_desc);
1226 } while (ret == TLS13_IO_WANT_RETRY);
1227
1228 return ret;
1229}
diff --git a/src/lib/libssl/tls13_server.c b/src/lib/libssl/tls13_server.c
deleted file mode 100644
index 63b7d92093..0000000000
--- a/src/lib/libssl/tls13_server.c
+++ /dev/null
@@ -1,1095 +0,0 @@
1/* $OpenBSD: tls13_server.c,v 1.109 2024/07/22 14:47:15 jsing Exp $ */
2/*
3 * Copyright (c) 2019, 2020 Joel Sing <jsing@openbsd.org>
4 * Copyright (c) 2020 Bob Beck <beck@openbsd.org>
5 *
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19#include <openssl/x509v3.h>
20
21#include "ssl_local.h"
22#include "ssl_sigalgs.h"
23#include "ssl_tlsext.h"
24#include "tls13_handshake.h"
25#include "tls13_internal.h"
26
27int
28tls13_server_init(struct tls13_ctx *ctx)
29{
30 SSL *s = ctx->ssl;
31
32 if (!ssl_supported_tls_version_range(s, &ctx->hs->our_min_tls_version,
33 &ctx->hs->our_max_tls_version)) {
34 SSLerror(s, SSL_R_NO_PROTOCOLS_AVAILABLE);
35 return 0;
36 }
37 s->version = ctx->hs->our_max_tls_version;
38
39 tls13_record_layer_set_retry_after_phh(ctx->rl,
40 (s->mode & SSL_MODE_AUTO_RETRY) != 0);
41
42 if (!ssl_get_new_session(s, 0)) /* XXX */
43 return 0;
44
45 tls13_record_layer_set_legacy_version(ctx->rl, TLS1_VERSION);
46
47 if (!tls1_transcript_init(s))
48 return 0;
49
50 arc4random_buf(s->s3->server_random, SSL3_RANDOM_SIZE);
51
52 return 1;
53}
54
55int
56tls13_server_accept(struct tls13_ctx *ctx)
57{
58 if (ctx->mode != TLS13_HS_SERVER)
59 return TLS13_IO_FAILURE;
60
61 return tls13_handshake_perform(ctx);
62}
63
64static int
65tls13_client_hello_is_legacy(CBS *cbs)
66{
67 CBS extensions_block, extensions, extension_data, versions;
68 uint16_t version, max_version = 0;
69 uint16_t type;
70
71 CBS_dup(cbs, &extensions_block);
72
73 if (!CBS_get_u16_length_prefixed(&extensions_block, &extensions))
74 return 1;
75
76 while (CBS_len(&extensions) > 0) {
77 if (!CBS_get_u16(&extensions, &type))
78 return 1;
79 if (!CBS_get_u16_length_prefixed(&extensions, &extension_data))
80 return 1;
81
82 if (type != TLSEXT_TYPE_supported_versions)
83 continue;
84 if (!CBS_get_u8_length_prefixed(&extension_data, &versions))
85 return 1;
86 while (CBS_len(&versions) > 0) {
87 if (!CBS_get_u16(&versions, &version))
88 return 1;
89 if (version >= max_version)
90 max_version = version;
91 }
92 if (CBS_len(&extension_data) != 0)
93 return 1;
94 }
95
96 return (max_version < TLS1_3_VERSION);
97}
98
99int
100tls13_client_hello_required_extensions(struct tls13_ctx *ctx)
101{
102 SSL *s = ctx->ssl;
103
104 /*
105 * RFC 8446, section 9.2. If the ClientHello has supported_versions
106 * containing TLSv1.3, presence or absence of some extensions requires
107 * presence or absence of others.
108 */
109
110 /*
111 * RFC 8446 section 4.2.9 - if we received a pre_shared_key, then we
112 * also need psk_key_exchange_modes. Otherwise, section 9.2 specifies
113 * that we need both signature_algorithms and supported_groups.
114 */
115 if (tlsext_extension_seen(s, TLSEXT_TYPE_pre_shared_key)) {
116 if (!tlsext_extension_seen(s,
117 TLSEXT_TYPE_psk_key_exchange_modes))
118 return 0;
119 } else {
120 if (!tlsext_extension_seen(s, TLSEXT_TYPE_signature_algorithms))
121 return 0;
122 if (!tlsext_extension_seen(s, TLSEXT_TYPE_supported_groups))
123 return 0;
124 }
125
126 /*
127 * supported_groups and key_share must either both be present or
128 * both be absent.
129 */
130 if (tlsext_extension_seen(s, TLSEXT_TYPE_supported_groups) !=
131 tlsext_extension_seen(s, TLSEXT_TYPE_key_share))
132 return 0;
133
134 /*
135 * XXX - Require server_name from client? If so, we SHOULD enforce
136 * this here - RFC 8446, 9.2.
137 */
138
139 return 1;
140}
141
142static const uint8_t tls13_compression_null_only[] = { 0 };
143
144static int
145tls13_client_hello_process(struct tls13_ctx *ctx, CBS *cbs)
146{
147 CBS cipher_suites, client_random, compression_methods, session_id;
148 STACK_OF(SSL_CIPHER) *ciphers = NULL;
149 const SSL_CIPHER *cipher;
150 uint16_t legacy_version;
151 int alert_desc;
152 SSL *s = ctx->ssl;
153 int ret = 0;
154
155 if (!CBS_get_u16(cbs, &legacy_version))
156 goto err;
157 if (!CBS_get_bytes(cbs, &client_random, SSL3_RANDOM_SIZE))
158 goto err;
159 if (!CBS_get_u8_length_prefixed(cbs, &session_id))
160 goto err;
161 if (!CBS_get_u16_length_prefixed(cbs, &cipher_suites))
162 goto err;
163 if (!CBS_get_u8_length_prefixed(cbs, &compression_methods))
164 goto err;
165
166 if (tls13_client_hello_is_legacy(cbs) || s->version < TLS1_3_VERSION) {
167 if (!CBS_skip(cbs, CBS_len(cbs)))
168 goto err;
169 return tls13_use_legacy_server(ctx);
170 }
171 ctx->hs->negotiated_tls_version = TLS1_3_VERSION;
172 ctx->hs->peer_legacy_version = legacy_version;
173
174 /* Ensure we send subsequent alerts with the correct record version. */
175 tls13_record_layer_set_legacy_version(ctx->rl, TLS1_2_VERSION);
176
177 /*
178 * Ensure that the client has not requested middlebox compatibility mode
179 * if it is prohibited from doing so.
180 */
181 if (!ctx->middlebox_compat && CBS_len(&session_id) != 0) {
182 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
183 goto err;
184 }
185
186 /* Add decoded values to the current ClientHello hash */
187 if (!tls13_clienthello_hash_init(ctx)) {
188 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
189 goto err;
190 }
191 if (!tls13_clienthello_hash_update_bytes(ctx, (void *)&legacy_version,
192 sizeof(legacy_version))) {
193 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
194 goto err;
195 }
196 if (!tls13_clienthello_hash_update(ctx, &client_random)) {
197 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
198 goto err;
199 }
200 if (!tls13_clienthello_hash_update(ctx, &session_id)) {
201 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
202 goto err;
203 }
204 if (!tls13_clienthello_hash_update(ctx, &cipher_suites)) {
205 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
206 goto err;
207 }
208 if (!tls13_clienthello_hash_update(ctx, &compression_methods)) {
209 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
210 goto err;
211 }
212
213 if (!tlsext_server_parse(s, SSL_TLSEXT_MSG_CH, cbs, &alert_desc)) {
214 ctx->alert = alert_desc;
215 goto err;
216 }
217
218 /* Finalize first ClientHello hash, or validate against it */
219 if (!ctx->hs->tls13.hrr) {
220 if (!tls13_clienthello_hash_finalize(ctx)) {
221 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
222 goto err;
223 }
224 } else {
225 if (!tls13_clienthello_hash_validate(ctx)) {
226 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
227 goto err;
228 }
229 tls13_clienthello_hash_clear(&ctx->hs->tls13);
230 }
231
232 if (!tls13_client_hello_required_extensions(ctx)) {
233 ctx->alert = TLS13_ALERT_MISSING_EXTENSION;
234 goto err;
235 }
236
237 /*
238 * If we got this far we have a supported versions extension that offers
239 * TLS 1.3 or later. This requires the legacy version be set to 0x0303.
240 */
241 if (legacy_version != TLS1_2_VERSION) {
242 ctx->alert = TLS13_ALERT_PROTOCOL_VERSION;
243 goto err;
244 }
245
246 /*
247 * The legacy session identifier must either be zero length or a 32 byte
248 * value (in which case the client is requesting middlebox compatibility
249 * mode), as per RFC 8446 section 4.1.2. If it is valid, store the value
250 * so that we can echo it back to the client.
251 */
252 if (CBS_len(&session_id) != 0 &&
253 CBS_len(&session_id) != sizeof(ctx->hs->tls13.legacy_session_id)) {
254 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
255 goto err;
256 }
257 if (!CBS_write_bytes(&session_id, ctx->hs->tls13.legacy_session_id,
258 sizeof(ctx->hs->tls13.legacy_session_id),
259 &ctx->hs->tls13.legacy_session_id_len)) {
260 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
261 goto err;
262 }
263
264 /* Parse cipher suites list and select preferred cipher. */
265 if ((ciphers = ssl_bytes_to_cipher_list(s, &cipher_suites)) == NULL) {
266 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
267 goto err;
268 }
269 cipher = ssl3_choose_cipher(s, ciphers, SSL_get_ciphers(s));
270 if (cipher == NULL) {
271 tls13_set_errorx(ctx, TLS13_ERR_NO_SHARED_CIPHER, 0,
272 "no shared cipher found", NULL);
273 ctx->alert = TLS13_ALERT_HANDSHAKE_FAILURE;
274 goto err;
275 }
276 ctx->hs->cipher = cipher;
277
278 sk_SSL_CIPHER_free(s->s3->hs.client_ciphers);
279 s->s3->hs.client_ciphers = ciphers;
280 ciphers = NULL;
281
282 /* Ensure only the NULL compression method is advertised. */
283 if (!CBS_mem_equal(&compression_methods, tls13_compression_null_only,
284 sizeof(tls13_compression_null_only))) {
285 ctx->alert = TLS13_ALERT_ILLEGAL_PARAMETER;
286 goto err;
287 }
288
289 ret = 1;
290
291 err:
292 sk_SSL_CIPHER_free(ciphers);
293
294 return ret;
295}
296
297int
298tls13_client_hello_recv(struct tls13_ctx *ctx, CBS *cbs)
299{
300 SSL *s = ctx->ssl;
301
302 if (!tls13_client_hello_process(ctx, cbs))
303 goto err;
304
305 /* See if we switched back to the legacy client method. */
306 if (s->method->version < TLS1_3_VERSION)
307 return 1;
308
309 /*
310 * If a matching key share was provided, we do not need to send a
311 * HelloRetryRequest.
312 */
313 /*
314 * XXX - ideally NEGOTIATED would only be added after record protection
315 * has been enabled. This would probably mean using either an
316 * INITIAL | WITHOUT_HRR state, or another intermediate state.
317 */
318 if (ctx->hs->key_share != NULL)
319 ctx->handshake_stage.hs_type |= NEGOTIATED | WITHOUT_HRR;
320
321 tls13_record_layer_allow_ccs(ctx->rl, 1);
322
323 return 1;
324
325 err:
326 return 0;
327}
328
329static int
330tls13_server_hello_build(struct tls13_ctx *ctx, CBB *cbb, int hrr)
331{
332 uint16_t tlsext_msg_type = SSL_TLSEXT_MSG_SH;
333 const uint8_t *server_random;
334 CBB session_id;
335 SSL *s = ctx->ssl;
336 uint16_t cipher;
337
338 cipher = SSL_CIPHER_get_value(ctx->hs->cipher);
339 server_random = s->s3->server_random;
340
341 if (hrr) {
342 server_random = tls13_hello_retry_request_hash;
343 tlsext_msg_type = SSL_TLSEXT_MSG_HRR;
344 }
345
346 if (!CBB_add_u16(cbb, TLS1_2_VERSION))
347 goto err;
348 if (!CBB_add_bytes(cbb, server_random, SSL3_RANDOM_SIZE))
349 goto err;
350 if (!CBB_add_u8_length_prefixed(cbb, &session_id))
351 goto err;
352 if (!CBB_add_bytes(&session_id, ctx->hs->tls13.legacy_session_id,
353 ctx->hs->tls13.legacy_session_id_len))
354 goto err;
355 if (!CBB_add_u16(cbb, cipher))
356 goto err;
357 if (!CBB_add_u8(cbb, 0))
358 goto err;
359 if (!tlsext_server_build(s, tlsext_msg_type, cbb))
360 goto err;
361
362 if (!CBB_flush(cbb))
363 goto err;
364
365 return 1;
366 err:
367 return 0;
368}
369
370static int
371tls13_server_engage_record_protection(struct tls13_ctx *ctx)
372{
373 struct tls13_secrets *secrets;
374 struct tls13_secret context;
375 unsigned char buf[EVP_MAX_MD_SIZE];
376 uint8_t *shared_key = NULL;
377 size_t shared_key_len = 0;
378 size_t hash_len;
379 SSL *s = ctx->ssl;
380 int ret = 0;
381
382 if (!tls_key_share_derive(ctx->hs->key_share, &shared_key,
383 &shared_key_len))
384 goto err;
385
386 s->session->cipher_value = ctx->hs->cipher->value;
387
388 if ((ctx->aead = tls13_cipher_aead(ctx->hs->cipher)) == NULL)
389 goto err;
390 if ((ctx->hash = tls13_cipher_hash(ctx->hs->cipher)) == NULL)
391 goto err;
392
393 if ((secrets = tls13_secrets_create(ctx->hash, 0)) == NULL)
394 goto err;
395 ctx->hs->tls13.secrets = secrets;
396
397 /* XXX - pass in hash. */
398 if (!tls1_transcript_hash_init(s))
399 goto err;
400 tls1_transcript_free(s);
401 if (!tls1_transcript_hash_value(s, buf, sizeof(buf), &hash_len))
402 goto err;
403 context.data = buf;
404 context.len = hash_len;
405
406 /* Early secrets. */
407 if (!tls13_derive_early_secrets(secrets, secrets->zeros.data,
408 secrets->zeros.len, &context))
409 goto err;
410
411 /* Handshake secrets. */
412 if (!tls13_derive_handshake_secrets(ctx->hs->tls13.secrets, shared_key,
413 shared_key_len, &context))
414 goto err;
415
416 tls13_record_layer_set_aead(ctx->rl, ctx->aead);
417 tls13_record_layer_set_hash(ctx->rl, ctx->hash);
418
419 if (!tls13_record_layer_set_read_traffic_key(ctx->rl,
420 &secrets->client_handshake_traffic, ssl_encryption_handshake))
421 goto err;
422 if (!tls13_record_layer_set_write_traffic_key(ctx->rl,
423 &secrets->server_handshake_traffic, ssl_encryption_handshake))
424 goto err;
425
426 ctx->handshake_stage.hs_type |= NEGOTIATED;
427 if (!(SSL_get_verify_mode(s) & SSL_VERIFY_PEER))
428 ctx->handshake_stage.hs_type |= WITHOUT_CR;
429
430 ret = 1;
431
432 err:
433 freezero(shared_key, shared_key_len);
434 return ret;
435}
436
437int
438tls13_server_hello_retry_request_send(struct tls13_ctx *ctx, CBB *cbb)
439{
440 int nid;
441
442 ctx->hs->tls13.hrr = 1;
443
444 if (!tls13_synthetic_handshake_message(ctx))
445 return 0;
446
447 if (ctx->hs->key_share != NULL)
448 return 0;
449 if (!tls1_get_supported_group(ctx->ssl, &nid))
450 return 0;
451 if (!tls1_ec_nid2group_id(nid, &ctx->hs->tls13.server_group))
452 return 0;
453
454 if (!tls13_server_hello_build(ctx, cbb, 1))
455 return 0;
456
457 return 1;
458}
459
460int
461tls13_server_hello_retry_request_sent(struct tls13_ctx *ctx)
462{
463 /*
464 * If the client has requested middlebox compatibility mode,
465 * we MUST send a dummy CCS following our first handshake message.
466 * See RFC 8446 Appendix D.4.
467 */
468 if (ctx->hs->tls13.legacy_session_id_len > 0)
469 ctx->send_dummy_ccs_after = 1;
470
471 return 1;
472}
473
474int
475tls13_client_hello_retry_recv(struct tls13_ctx *ctx, CBS *cbs)
476{
477 SSL *s = ctx->ssl;
478
479 if (!tls13_client_hello_process(ctx, cbs))
480 return 0;
481
482 /* XXX - need further checks. */
483 if (s->method->version < TLS1_3_VERSION)
484 return 0;
485
486 ctx->hs->tls13.hrr = 0;
487
488 return 1;
489}
490
491static int
492tls13_servername_process(struct tls13_ctx *ctx)
493{
494 uint8_t alert = TLS13_ALERT_INTERNAL_ERROR;
495
496 if (!tls13_legacy_servername_process(ctx, &alert)) {
497 ctx->alert = alert;
498 return 0;
499 }
500
501 return 1;
502}
503
504int
505tls13_server_hello_send(struct tls13_ctx *ctx, CBB *cbb)
506{
507 if (ctx->hs->key_share == NULL)
508 return 0;
509 if (!tls_key_share_generate(ctx->hs->key_share))
510 return 0;
511 if (!tls13_servername_process(ctx))
512 return 0;
513
514 ctx->hs->tls13.server_group = 0;
515
516 if (!tls13_server_hello_build(ctx, cbb, 0))
517 return 0;
518
519 return 1;
520}
521
522int
523tls13_server_hello_sent(struct tls13_ctx *ctx)
524{
525 /*
526 * If the client has requested middlebox compatibility mode,
527 * we MUST send a dummy CCS following our first handshake message.
528 * See RFC 8446 Appendix D.4.
529 */
530 if ((ctx->handshake_stage.hs_type & WITHOUT_HRR) &&
531 ctx->hs->tls13.legacy_session_id_len > 0)
532 ctx->send_dummy_ccs_after = 1;
533
534 return tls13_server_engage_record_protection(ctx);
535}
536
537int
538tls13_server_encrypted_extensions_send(struct tls13_ctx *ctx, CBB *cbb)
539{
540 if (!tlsext_server_build(ctx->ssl, SSL_TLSEXT_MSG_EE, cbb))
541 goto err;
542
543 return 1;
544 err:
545 return 0;
546}
547
548int
549tls13_server_certificate_request_send(struct tls13_ctx *ctx, CBB *cbb)
550{
551 CBB certificate_request_context;
552
553 if (!CBB_add_u8_length_prefixed(cbb, &certificate_request_context))
554 goto err;
555 if (!tlsext_server_build(ctx->ssl, SSL_TLSEXT_MSG_CR, cbb))
556 goto err;
557
558 if (!CBB_flush(cbb))
559 goto err;
560
561 return 1;
562 err:
563 return 0;
564}
565
566static int
567tls13_server_check_certificate(struct tls13_ctx *ctx, SSL_CERT_PKEY *cpk,
568 int *ok, const struct ssl_sigalg **out_sigalg)
569{
570 const struct ssl_sigalg *sigalg;
571 SSL *s = ctx->ssl;
572
573 *ok = 0;
574 *out_sigalg = NULL;
575
576 if (cpk->x509 == NULL || cpk->privatekey == NULL)
577 goto done;
578
579 /*
580 * The digitalSignature bit MUST be set if the Key Usage extension is
581 * present as per RFC 8446 section 4.4.2.2.
582 */
583 if (!(X509_get_key_usage(cpk->x509) & X509v3_KU_DIGITAL_SIGNATURE))
584 goto done;
585
586 if ((sigalg = ssl_sigalg_select(s, cpk->privatekey)) == NULL)
587 goto done;
588
589 *ok = 1;
590 *out_sigalg = sigalg;
591
592 done:
593 return 1;
594}
595
596static int
597tls13_server_select_certificate(struct tls13_ctx *ctx, SSL_CERT_PKEY **out_cpk,
598 const struct ssl_sigalg **out_sigalg)
599{
600 SSL *s = ctx->ssl;
601 const struct ssl_sigalg *sigalg;
602 SSL_CERT_PKEY *cpk;
603 int cert_ok;
604
605 *out_cpk = NULL;
606 *out_sigalg = NULL;
607
608 cpk = &s->cert->pkeys[SSL_PKEY_ECC];
609 if (!tls13_server_check_certificate(ctx, cpk, &cert_ok, &sigalg))
610 return 0;
611 if (cert_ok)
612 goto done;
613
614 cpk = &s->cert->pkeys[SSL_PKEY_RSA];
615 if (!tls13_server_check_certificate(ctx, cpk, &cert_ok, &sigalg))
616 return 0;
617 if (cert_ok)
618 goto done;
619
620 cpk = NULL;
621 sigalg = NULL;
622
623 done:
624 *out_cpk = cpk;
625 *out_sigalg = sigalg;
626
627 return 1;
628}
629
630int
631tls13_server_certificate_send(struct tls13_ctx *ctx, CBB *cbb)
632{
633 SSL *s = ctx->ssl;
634 CBB cert_request_context, cert_list;
635 const struct ssl_sigalg *sigalg;
636 X509_STORE_CTX *xsc = NULL;
637 STACK_OF(X509) *chain;
638 SSL_CERT_PKEY *cpk;
639 X509 *cert;
640 int i, ret = 0;
641
642 if (!tls13_server_select_certificate(ctx, &cpk, &sigalg))
643 goto err;
644
645 if (cpk == NULL) {
646 /* A server must always provide a certificate. */
647 ctx->alert = TLS13_ALERT_HANDSHAKE_FAILURE;
648 tls13_set_errorx(ctx, TLS13_ERR_NO_CERTIFICATE, 0,
649 "no server certificate", NULL);
650 goto err;
651 }
652
653 ctx->hs->tls13.cpk = cpk;
654 ctx->hs->our_sigalg = sigalg;
655
656 if ((chain = cpk->chain) == NULL)
657 chain = s->ctx->extra_certs;
658
659 if (chain == NULL && !(s->mode & SSL_MODE_NO_AUTO_CHAIN)) {
660 if ((xsc = X509_STORE_CTX_new()) == NULL)
661 goto err;
662 if (!X509_STORE_CTX_init(xsc, s->ctx->cert_store, cpk->x509, NULL))
663 goto err;
664 X509_VERIFY_PARAM_set_flags(X509_STORE_CTX_get0_param(xsc),
665 X509_V_FLAG_LEGACY_VERIFY);
666 X509_verify_cert(xsc);
667 ERR_clear_error();
668 chain = X509_STORE_CTX_get0_chain(xsc);
669 }
670
671 if (!CBB_add_u8_length_prefixed(cbb, &cert_request_context))
672 goto err;
673 if (!CBB_add_u24_length_prefixed(cbb, &cert_list))
674 goto err;
675
676 if (!tls13_cert_add(ctx, &cert_list, cpk->x509, tlsext_server_build))
677 goto err;
678
679 for (i = 0; i < sk_X509_num(chain); i++) {
680 cert = sk_X509_value(chain, i);
681
682 /*
683 * In the case of auto chain, the leaf certificate will be at
684 * the top of the chain - skip over it as we've already added
685 * it earlier.
686 */
687 if (i == 0 && cert == cpk->x509)
688 continue;
689
690 /*
691 * XXX we don't send extensions with chain certs to avoid sending
692 * a leaf ocsp staple with the chain certs. This needs to get
693 * fixed.
694 */
695 if (!tls13_cert_add(ctx, &cert_list, cert, NULL))
696 goto err;
697 }
698
699 if (!CBB_flush(cbb))
700 goto err;
701
702 ret = 1;
703
704 err:
705 X509_STORE_CTX_free(xsc);
706
707 return ret;
708}
709
710int
711tls13_server_certificate_verify_send(struct tls13_ctx *ctx, CBB *cbb)
712{
713 const struct ssl_sigalg *sigalg;
714 uint8_t *sig = NULL, *sig_content = NULL;
715 size_t sig_len, sig_content_len;
716 EVP_MD_CTX *mdctx = NULL;
717 EVP_PKEY_CTX *pctx;
718 EVP_PKEY *pkey;
719 const SSL_CERT_PKEY *cpk;
720 CBB sig_cbb;
721 int ret = 0;
722
723 memset(&sig_cbb, 0, sizeof(sig_cbb));
724
725 if ((cpk = ctx->hs->tls13.cpk) == NULL)
726 goto err;
727 if ((sigalg = ctx->hs->our_sigalg) == NULL)
728 goto err;
729 pkey = cpk->privatekey;
730
731 if (!CBB_init(&sig_cbb, 0))
732 goto err;
733 if (!CBB_add_bytes(&sig_cbb, tls13_cert_verify_pad,
734 sizeof(tls13_cert_verify_pad)))
735 goto err;
736 if (!CBB_add_bytes(&sig_cbb, tls13_cert_server_verify_context,
737 strlen(tls13_cert_server_verify_context)))
738 goto err;
739 if (!CBB_add_u8(&sig_cbb, 0))
740 goto err;
741 if (!CBB_add_bytes(&sig_cbb, ctx->hs->tls13.transcript_hash,
742 ctx->hs->tls13.transcript_hash_len))
743 goto err;
744 if (!CBB_finish(&sig_cbb, &sig_content, &sig_content_len))
745 goto err;
746
747 if ((mdctx = EVP_MD_CTX_new()) == NULL)
748 goto err;
749 if (!EVP_DigestSignInit(mdctx, &pctx, sigalg->md(), NULL, pkey))
750 goto err;
751 if (sigalg->flags & SIGALG_FLAG_RSA_PSS) {
752 if (!EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING))
753 goto err;
754 if (!EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))
755 goto err;
756 }
757 if (!EVP_DigestSign(mdctx, NULL, &sig_len, sig_content, sig_content_len))
758 goto err;
759 if ((sig = calloc(1, sig_len)) == NULL)
760 goto err;
761 if (!EVP_DigestSign(mdctx, sig, &sig_len, sig_content, sig_content_len))
762 goto err;
763
764 if (!CBB_add_u16(cbb, sigalg->value))
765 goto err;
766 if (!CBB_add_u16_length_prefixed(cbb, &sig_cbb))
767 goto err;
768 if (!CBB_add_bytes(&sig_cbb, sig, sig_len))
769 goto err;
770
771 if (!CBB_flush(cbb))
772 goto err;
773
774 ret = 1;
775
776 err:
777 if (!ret && ctx->alert == 0)
778 ctx->alert = TLS13_ALERT_INTERNAL_ERROR;
779
780 CBB_cleanup(&sig_cbb);
781 EVP_MD_CTX_free(mdctx);
782 free(sig_content);
783 free(sig);
784
785 return ret;
786}
787
788int
789tls13_server_finished_send(struct tls13_ctx *ctx, CBB *cbb)
790{
791 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
792 struct tls13_secret context = { .data = "", .len = 0 };
793 struct tls13_secret finished_key = { .data = NULL, .len = 0 } ;
794 uint8_t transcript_hash[EVP_MAX_MD_SIZE];
795 size_t transcript_hash_len;
796 uint8_t *verify_data;
797 size_t verify_data_len;
798 unsigned int hlen;
799 HMAC_CTX *hmac_ctx = NULL;
800 CBS cbs;
801 int ret = 0;
802
803 if (!tls13_secret_init(&finished_key, EVP_MD_size(ctx->hash)))
804 goto err;
805
806 if (!tls13_hkdf_expand_label(&finished_key, ctx->hash,
807 &secrets->server_handshake_traffic, "finished",
808 &context))
809 goto err;
810
811 if (!tls1_transcript_hash_value(ctx->ssl, transcript_hash,
812 sizeof(transcript_hash), &transcript_hash_len))
813 goto err;
814
815 if ((hmac_ctx = HMAC_CTX_new()) == NULL)
816 goto err;
817 if (!HMAC_Init_ex(hmac_ctx, finished_key.data, finished_key.len,
818 ctx->hash, NULL))
819 goto err;
820 if (!HMAC_Update(hmac_ctx, transcript_hash, transcript_hash_len))
821 goto err;
822
823 verify_data_len = HMAC_size(hmac_ctx);
824 if (!CBB_add_space(cbb, &verify_data, verify_data_len))
825 goto err;
826 if (!HMAC_Final(hmac_ctx, verify_data, &hlen))
827 goto err;
828 if (hlen != verify_data_len)
829 goto err;
830
831 CBS_init(&cbs, verify_data, verify_data_len);
832 if (!CBS_write_bytes(&cbs, ctx->hs->finished,
833 sizeof(ctx->hs->finished), &ctx->hs->finished_len))
834 goto err;
835
836 ret = 1;
837
838 err:
839 tls13_secret_cleanup(&finished_key);
840 HMAC_CTX_free(hmac_ctx);
841
842 return ret;
843}
844
845int
846tls13_server_finished_sent(struct tls13_ctx *ctx)
847{
848 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
849 struct tls13_secret context = { .data = "", .len = 0 };
850
851 /*
852 * Derive application traffic keys.
853 */
854 context.data = ctx->hs->tls13.transcript_hash;
855 context.len = ctx->hs->tls13.transcript_hash_len;
856
857 if (!tls13_derive_application_secrets(secrets, &context))
858 return 0;
859
860 /*
861 * Any records following the server finished message must be encrypted
862 * using the server application traffic keys.
863 */
864 return tls13_record_layer_set_write_traffic_key(ctx->rl,
865 &secrets->server_application_traffic, ssl_encryption_application);
866}
867
868int
869tls13_client_certificate_recv(struct tls13_ctx *ctx, CBS *cbs)
870{
871 CBS cert_request_context, cert_list, cert_data, cert_exts;
872 struct stack_st_X509 *certs = NULL;
873 SSL *s = ctx->ssl;
874 X509 *cert = NULL;
875 const uint8_t *p;
876 int ret = 0;
877
878 if (!CBS_get_u8_length_prefixed(cbs, &cert_request_context))
879 goto err;
880 if (CBS_len(&cert_request_context) != 0)
881 goto err;
882 if (!CBS_get_u24_length_prefixed(cbs, &cert_list))
883 goto err;
884 if (CBS_len(&cert_list) == 0) {
885 if (!(s->verify_mode & SSL_VERIFY_FAIL_IF_NO_PEER_CERT))
886 return 1;
887 ctx->alert = TLS13_ALERT_CERTIFICATE_REQUIRED;
888 tls13_set_errorx(ctx, TLS13_ERR_NO_PEER_CERTIFICATE, 0,
889 "peer did not provide a certificate", NULL);
890 goto err;
891 }
892
893 if ((certs = sk_X509_new_null()) == NULL)
894 goto err;
895 while (CBS_len(&cert_list) > 0) {
896 if (!CBS_get_u24_length_prefixed(&cert_list, &cert_data))
897 goto err;
898 if (!CBS_get_u16_length_prefixed(&cert_list, &cert_exts))
899 goto err;
900
901 p = CBS_data(&cert_data);
902 if ((cert = d2i_X509(NULL, &p, CBS_len(&cert_data))) == NULL)
903 goto err;
904 if (p != CBS_data(&cert_data) + CBS_len(&cert_data))
905 goto err;
906
907 if (!sk_X509_push(certs, cert))
908 goto err;
909
910 cert = NULL;
911 }
912
913 /*
914 * At this stage we still have no proof of possession. As such, it would
915 * be preferable to keep the chain and verify once we have successfully
916 * processed the CertificateVerify message.
917 */
918 if (ssl_verify_cert_chain(s, certs) <= 0) {
919 ctx->alert = ssl_verify_alarm_type(s->verify_result);
920 tls13_set_errorx(ctx, TLS13_ERR_VERIFY_FAILED, 0,
921 "failed to verify peer certificate", NULL);
922 goto err;
923 }
924 s->session->verify_result = s->verify_result;
925 ERR_clear_error();
926
927 if (!tls_process_peer_certs(s, certs))
928 goto err;
929
930 ctx->handshake_stage.hs_type |= WITH_CCV;
931 ret = 1;
932
933 err:
934 sk_X509_pop_free(certs, X509_free);
935 X509_free(cert);
936
937 return ret;
938}
939
940int
941tls13_client_certificate_verify_recv(struct tls13_ctx *ctx, CBS *cbs)
942{
943 const struct ssl_sigalg *sigalg;
944 uint16_t signature_scheme;
945 uint8_t *sig_content = NULL;
946 size_t sig_content_len;
947 EVP_MD_CTX *mdctx = NULL;
948 EVP_PKEY_CTX *pctx;
949 EVP_PKEY *pkey;
950 X509 *cert;
951 CBS signature;
952 CBB cbb;
953 int ret = 0;
954
955 memset(&cbb, 0, sizeof(cbb));
956
957 if (!CBS_get_u16(cbs, &signature_scheme))
958 goto err;
959 if (!CBS_get_u16_length_prefixed(cbs, &signature))
960 goto err;
961
962 if (!CBB_init(&cbb, 0))
963 goto err;
964 if (!CBB_add_bytes(&cbb, tls13_cert_verify_pad,
965 sizeof(tls13_cert_verify_pad)))
966 goto err;
967 if (!CBB_add_bytes(&cbb, tls13_cert_client_verify_context,
968 strlen(tls13_cert_client_verify_context)))
969 goto err;
970 if (!CBB_add_u8(&cbb, 0))
971 goto err;
972 if (!CBB_add_bytes(&cbb, ctx->hs->tls13.transcript_hash,
973 ctx->hs->tls13.transcript_hash_len))
974 goto err;
975 if (!CBB_finish(&cbb, &sig_content, &sig_content_len))
976 goto err;
977
978 if ((cert = ctx->ssl->session->peer_cert) == NULL)
979 goto err;
980 if ((pkey = X509_get0_pubkey(cert)) == NULL)
981 goto err;
982 if ((sigalg = ssl_sigalg_for_peer(ctx->ssl, pkey,
983 signature_scheme)) == NULL)
984 goto err;
985 ctx->hs->peer_sigalg = sigalg;
986
987 if (CBS_len(&signature) > EVP_PKEY_size(pkey))
988 goto err;
989
990 if ((mdctx = EVP_MD_CTX_new()) == NULL)
991 goto err;
992 if (!EVP_DigestVerifyInit(mdctx, &pctx, sigalg->md(), NULL, pkey))
993 goto err;
994 if (sigalg->flags & SIGALG_FLAG_RSA_PSS) {
995 if (!EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING))
996 goto err;
997 if (!EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, -1))
998 goto err;
999 }
1000 if (EVP_DigestVerify(mdctx, CBS_data(&signature), CBS_len(&signature),
1001 sig_content, sig_content_len) <= 0) {
1002 ctx->alert = TLS13_ALERT_DECRYPT_ERROR;
1003 goto err;
1004 }
1005
1006 ret = 1;
1007
1008 err:
1009 if (!ret && ctx->alert == 0)
1010 ctx->alert = TLS13_ALERT_DECODE_ERROR;
1011
1012 CBB_cleanup(&cbb);
1013 EVP_MD_CTX_free(mdctx);
1014 free(sig_content);
1015
1016 return ret;
1017}
1018
1019int
1020tls13_client_end_of_early_data_recv(struct tls13_ctx *ctx, CBS *cbs)
1021{
1022 return 0;
1023}
1024
1025int
1026tls13_client_finished_recv(struct tls13_ctx *ctx, CBS *cbs)
1027{
1028 struct tls13_secrets *secrets = ctx->hs->tls13.secrets;
1029 struct tls13_secret context = { .data = "", .len = 0 };
1030 struct tls13_secret finished_key;
1031 uint8_t *verify_data = NULL;
1032 size_t verify_data_len;
1033 uint8_t key[EVP_MAX_MD_SIZE];
1034 HMAC_CTX *hmac_ctx = NULL;
1035 unsigned int hlen;
1036 int ret = 0;
1037
1038 /*
1039 * Verify client finished.
1040 */
1041 finished_key.data = key;
1042 finished_key.len = EVP_MD_size(ctx->hash);
1043
1044 if (!tls13_hkdf_expand_label(&finished_key, ctx->hash,
1045 &secrets->client_handshake_traffic, "finished",
1046 &context))
1047 goto err;
1048
1049 if ((hmac_ctx = HMAC_CTX_new()) == NULL)
1050 goto err;
1051 if (!HMAC_Init_ex(hmac_ctx, finished_key.data, finished_key.len,
1052 ctx->hash, NULL))
1053 goto err;
1054 if (!HMAC_Update(hmac_ctx, ctx->hs->tls13.transcript_hash,
1055 ctx->hs->tls13.transcript_hash_len))
1056 goto err;
1057 verify_data_len = HMAC_size(hmac_ctx);
1058 if ((verify_data = calloc(1, verify_data_len)) == NULL)
1059 goto err;
1060 if (!HMAC_Final(hmac_ctx, verify_data, &hlen))
1061 goto err;
1062 if (hlen != verify_data_len)
1063 goto err;
1064
1065 if (!CBS_mem_equal(cbs, verify_data, verify_data_len)) {
1066 ctx->alert = TLS13_ALERT_DECRYPT_ERROR;
1067 goto err;
1068 }
1069
1070 if (!CBS_write_bytes(cbs, ctx->hs->peer_finished,
1071 sizeof(ctx->hs->peer_finished),
1072 &ctx->hs->peer_finished_len))
1073 goto err;
1074
1075 if (!CBS_skip(cbs, verify_data_len))
1076 goto err;
1077
1078 /*
1079 * Any records following the client finished message must be encrypted
1080 * using the client application traffic keys.
1081 */
1082 if (!tls13_record_layer_set_read_traffic_key(ctx->rl,
1083 &secrets->client_application_traffic, ssl_encryption_application))
1084 goto err;
1085
1086 tls13_record_layer_allow_ccs(ctx->rl, 0);
1087
1088 ret = 1;
1089
1090 err:
1091 HMAC_CTX_free(hmac_ctx);
1092 free(verify_data);
1093
1094 return ret;
1095}
diff --git a/src/lib/libssl/tls_buffer.c b/src/lib/libssl/tls_buffer.c
deleted file mode 100644
index 517d66d685..0000000000
--- a/src/lib/libssl/tls_buffer.c
+++ /dev/null
@@ -1,257 +0,0 @@
1/* $OpenBSD: tls_buffer.c,v 1.4 2022/11/10 18:06:37 jsing Exp $ */
2/*
3 * Copyright (c) 2018, 2019, 2022 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19#include <string.h>
20
21#include "bytestring.h"
22#include "tls_internal.h"
23
24#define TLS_BUFFER_CAPACITY_LIMIT (1024 * 1024)
25
26struct tls_buffer {
27 size_t capacity;
28 size_t capacity_limit;
29 uint8_t *data;
30 size_t len;
31 size_t offset;
32};
33
34static int tls_buffer_resize(struct tls_buffer *buf, size_t capacity);
35
36struct tls_buffer *
37tls_buffer_new(size_t init_size)
38{
39 struct tls_buffer *buf = NULL;
40
41 if ((buf = calloc(1, sizeof(struct tls_buffer))) == NULL)
42 goto err;
43
44 buf->capacity_limit = TLS_BUFFER_CAPACITY_LIMIT;
45
46 if (!tls_buffer_resize(buf, init_size))
47 goto err;
48
49 return buf;
50
51 err:
52 tls_buffer_free(buf);
53
54 return NULL;
55}
56
57void
58tls_buffer_clear(struct tls_buffer *buf)
59{
60 freezero(buf->data, buf->capacity);
61
62 buf->data = NULL;
63 buf->capacity = 0;
64 buf->len = 0;
65 buf->offset = 0;
66}
67
68void
69tls_buffer_free(struct tls_buffer *buf)
70{
71 if (buf == NULL)
72 return;
73
74 tls_buffer_clear(buf);
75
76 freezero(buf, sizeof(struct tls_buffer));
77}
78
79static int
80tls_buffer_grow(struct tls_buffer *buf, size_t capacity)
81{
82 if (buf->capacity >= capacity)
83 return 1;
84
85 return tls_buffer_resize(buf, capacity);
86}
87
88static int
89tls_buffer_resize(struct tls_buffer *buf, size_t capacity)
90{
91 uint8_t *data;
92
93 /*
94 * XXX - Consider maintaining a minimum size and growing more
95 * intelligently (rather than exactly).
96 */
97 if (buf->capacity == capacity)
98 return 1;
99
100 if (capacity > buf->capacity_limit)
101 return 0;
102
103 if ((data = recallocarray(buf->data, buf->capacity, capacity, 1)) == NULL)
104 return 0;
105
106 buf->data = data;
107 buf->capacity = capacity;
108
109 /* Ensure that len and offset are valid if capacity decreased. */
110 if (buf->len > buf->capacity)
111 buf->len = buf->capacity;
112 if (buf->offset > buf->len)
113 buf->offset = buf->len;
114
115 return 1;
116}
117
118void
119tls_buffer_set_capacity_limit(struct tls_buffer *buf, size_t limit)
120{
121 /*
122 * XXX - do we want to force a resize if this limit is less than current
123 * capacity... and what do we do with existing data? Force a clear?
124 */
125 buf->capacity_limit = limit;
126}
127
128ssize_t
129tls_buffer_extend(struct tls_buffer *buf, size_t len,
130 tls_read_cb read_cb, void *cb_arg)
131{
132 ssize_t ret;
133
134 if (len == buf->len)
135 return buf->len;
136
137 if (len < buf->len)
138 return TLS_IO_FAILURE;
139
140 if (!tls_buffer_resize(buf, len))
141 return TLS_IO_FAILURE;
142
143 for (;;) {
144 if ((ret = read_cb(&buf->data[buf->len],
145 buf->capacity - buf->len, cb_arg)) <= 0)
146 return ret;
147
148 if (ret > buf->capacity - buf->len)
149 return TLS_IO_FAILURE;
150
151 buf->len += ret;
152
153 if (buf->len == buf->capacity)
154 return buf->len;
155 }
156}
157
158size_t
159tls_buffer_remaining(struct tls_buffer *buf)
160{
161 if (buf->offset > buf->len)
162 return 0;
163
164 return buf->len - buf->offset;
165}
166
167ssize_t
168tls_buffer_read(struct tls_buffer *buf, uint8_t *rbuf, size_t n)
169{
170 if (buf->offset > buf->len)
171 return TLS_IO_FAILURE;
172
173 if (buf->offset == buf->len)
174 return TLS_IO_WANT_POLLIN;
175
176 if (n > buf->len - buf->offset)
177 n = buf->len - buf->offset;
178
179 memcpy(rbuf, &buf->data[buf->offset], n);
180
181 buf->offset += n;
182
183 return n;
184}
185
186ssize_t
187tls_buffer_write(struct tls_buffer *buf, const uint8_t *wbuf, size_t n)
188{
189 if (buf->offset > buf->len)
190 return TLS_IO_FAILURE;
191
192 /*
193 * To avoid continually growing the buffer, pull data up to the
194 * start of the buffer. If all data has been read then we can simply
195 * reset, otherwise wait until we're going to save at least 4KB of
196 * memory to reduce overhead.
197 */
198 if (buf->offset == buf->len) {
199 buf->len = 0;
200 buf->offset = 0;
201 }
202 if (buf->offset >= 4096) {
203 memmove(buf->data, &buf->data[buf->offset],
204 buf->len - buf->offset);
205 buf->len -= buf->offset;
206 buf->offset = 0;
207 }
208
209 if (buf->len > SIZE_MAX - n)
210 return TLS_IO_FAILURE;
211 if (!tls_buffer_grow(buf, buf->len + n))
212 return TLS_IO_FAILURE;
213
214 memcpy(&buf->data[buf->len], wbuf, n);
215
216 buf->len += n;
217
218 return n;
219}
220
221int
222tls_buffer_append(struct tls_buffer *buf, const uint8_t *wbuf, size_t n)
223{
224 return tls_buffer_write(buf, wbuf, n) == n;
225}
226
227int
228tls_buffer_data(struct tls_buffer *buf, CBS *out_cbs)
229{
230 CBS cbs;
231
232 CBS_init(&cbs, buf->data, buf->len);
233
234 if (!CBS_skip(&cbs, buf->offset))
235 return 0;
236
237 CBS_dup(&cbs, out_cbs);
238
239 return 1;
240}
241
242int
243tls_buffer_finish(struct tls_buffer *buf, uint8_t **out, size_t *out_len)
244{
245 if (out == NULL || out_len == NULL)
246 return 0;
247
248 *out = buf->data;
249 *out_len = buf->len;
250
251 buf->data = NULL;
252 buf->capacity = 0;
253 buf->len = 0;
254 buf->offset = 0;
255
256 return 1;
257}
diff --git a/src/lib/libssl/tls_content.c b/src/lib/libssl/tls_content.c
deleted file mode 100644
index 726de0fdc4..0000000000
--- a/src/lib/libssl/tls_content.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/* $OpenBSD: tls_content.c,v 1.2 2022/11/11 17:15:27 jsing Exp $ */
2/*
3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19#include <string.h>
20
21#include "tls_content.h"
22
23/* Content from a TLS record. */
24struct tls_content {
25 uint8_t type;
26 uint16_t epoch;
27
28 const uint8_t *data;
29 size_t data_len;
30 CBS cbs;
31};
32
33struct tls_content *
34tls_content_new(void)
35{
36 return calloc(1, sizeof(struct tls_content));
37}
38
39void
40tls_content_clear(struct tls_content *content)
41{
42 freezero((void *)content->data, content->data_len);
43 memset(content, 0, sizeof(*content));
44}
45
46void
47tls_content_free(struct tls_content *content)
48{
49 if (content == NULL)
50 return;
51
52 tls_content_clear(content);
53
54 freezero(content, sizeof(struct tls_content));
55}
56
57CBS *
58tls_content_cbs(struct tls_content *content)
59{
60 return &content->cbs;
61}
62
63int
64tls_content_equal(struct tls_content *content, const uint8_t *buf, size_t n)
65{
66 return CBS_mem_equal(&content->cbs, buf, n);
67}
68
69size_t
70tls_content_remaining(struct tls_content *content)
71{
72 return CBS_len(&content->cbs);
73}
74
75uint8_t
76tls_content_type(struct tls_content *content)
77{
78 return content->type;
79}
80
81int
82tls_content_dup_data(struct tls_content *content, uint8_t type,
83 const uint8_t *data, size_t data_len)
84{
85 uint8_t *dup;
86
87 if ((dup = calloc(1, data_len)) == NULL)
88 return 0;
89 memcpy(dup, data, data_len);
90
91 tls_content_set_data(content, type, dup, data_len);
92
93 return 1;
94}
95
96uint16_t
97tls_content_epoch(struct tls_content *content)
98{
99 return content->epoch;
100}
101
102void
103tls_content_set_epoch(struct tls_content *content, uint16_t epoch)
104{
105 content->epoch = epoch;
106}
107
108void
109tls_content_set_data(struct tls_content *content, uint8_t type,
110 const uint8_t *data, size_t data_len)
111{
112 tls_content_clear(content);
113
114 content->type = type;
115 content->data = data;
116 content->data_len = data_len;
117
118 CBS_init(&content->cbs, content->data, content->data_len);
119}
120
121int
122tls_content_set_bounds(struct tls_content *content, size_t offset, size_t len)
123{
124 size_t content_len;
125
126 content_len = offset + len;
127 if (content_len < len)
128 return 0;
129 if (content_len > content->data_len)
130 return 0;
131
132 CBS_init(&content->cbs, content->data, content_len);
133 return CBS_skip(&content->cbs, offset);
134}
135
136static ssize_t
137tls_content_read_internal(struct tls_content *content, uint8_t *buf, size_t n,
138 int peek)
139{
140 if (n > CBS_len(&content->cbs))
141 n = CBS_len(&content->cbs);
142
143 /* XXX - CBS_memcpy? CBS_copy_bytes? */
144 memcpy(buf, CBS_data(&content->cbs), n);
145
146 if (!peek) {
147 if (!CBS_skip(&content->cbs, n))
148 return -1;
149 }
150
151 return n;
152}
153
154ssize_t
155tls_content_peek(struct tls_content *content, uint8_t *buf, size_t n)
156{
157 return tls_content_read_internal(content, buf, n, 1);
158}
159
160ssize_t
161tls_content_read(struct tls_content *content, uint8_t *buf, size_t n)
162{
163 return tls_content_read_internal(content, buf, n, 0);
164}
diff --git a/src/lib/libssl/tls_content.h b/src/lib/libssl/tls_content.h
deleted file mode 100644
index b807248f60..0000000000
--- a/src/lib/libssl/tls_content.h
+++ /dev/null
@@ -1,50 +0,0 @@
1/* $OpenBSD: tls_content.h,v 1.2 2022/11/11 17:15:27 jsing Exp $ */
2/*
3 * Copyright (c) 2020 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef HEADER_TLS_CONTENT_H
19#define HEADER_TLS_CONTENT_H
20
21#include "bytestring.h"
22
23__BEGIN_HIDDEN_DECLS
24
25struct tls_content;
26
27struct tls_content *tls_content_new(void);
28void tls_content_clear(struct tls_content *content);
29void tls_content_free(struct tls_content *content);
30
31CBS *tls_content_cbs(struct tls_content *content);
32int tls_content_equal(struct tls_content *content, const uint8_t *buf, size_t n);
33size_t tls_content_remaining(struct tls_content *content);
34uint8_t tls_content_type(struct tls_content *content);
35uint16_t tls_content_epoch(struct tls_content *content);
36
37int tls_content_dup_data(struct tls_content *content, uint8_t type,
38 const uint8_t *data, size_t data_len);
39void tls_content_set_data(struct tls_content *content, uint8_t type,
40 const uint8_t *data, size_t data_len);
41int tls_content_set_bounds(struct tls_content *content, size_t offset,
42 size_t len);
43void tls_content_set_epoch(struct tls_content *content, uint16_t epoch);
44
45ssize_t tls_content_peek(struct tls_content *content, uint8_t *buf, size_t n);
46ssize_t tls_content_read(struct tls_content *content, uint8_t *buf, size_t n);
47
48__END_HIDDEN_DECLS
49
50#endif
diff --git a/src/lib/libssl/tls_internal.h b/src/lib/libssl/tls_internal.h
deleted file mode 100644
index 84edde8474..0000000000
--- a/src/lib/libssl/tls_internal.h
+++ /dev/null
@@ -1,101 +0,0 @@
1/* $OpenBSD: tls_internal.h,v 1.10 2022/11/10 18:06:37 jsing Exp $ */
2/*
3 * Copyright (c) 2018, 2019, 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef HEADER_TLS_INTERNAL_H
19#define HEADER_TLS_INTERNAL_H
20
21#include <openssl/dh.h>
22#include <openssl/evp.h>
23
24#include "bytestring.h"
25
26__BEGIN_HIDDEN_DECLS
27
28#define TLS_IO_SUCCESS 1
29#define TLS_IO_EOF 0
30#define TLS_IO_FAILURE -1
31#define TLS_IO_ALERT -2
32#define TLS_IO_WANT_POLLIN -3
33#define TLS_IO_WANT_POLLOUT -4
34#define TLS_IO_WANT_RETRY -5 /* Retry the previous call immediately. */
35
36enum ssl_encryption_level_t;
37
38struct tls13_secret;
39
40/*
41 * Callbacks.
42 */
43typedef ssize_t (*tls_read_cb)(void *_buf, size_t _buflen, void *_cb_arg);
44typedef ssize_t (*tls_write_cb)(const void *_buf, size_t _buflen,
45 void *_cb_arg);
46typedef ssize_t (*tls_flush_cb)(void *_cb_arg);
47
48typedef ssize_t (*tls_handshake_read_cb)(void *_buf, size_t _buflen,
49 void *_cb_arg);
50typedef ssize_t (*tls_handshake_write_cb)(const void *_buf, size_t _buflen,
51 void *_cb_arg);
52typedef int (*tls_traffic_key_cb)(struct tls13_secret *key,
53 enum ssl_encryption_level_t level, void *_cb_arg);
54typedef int (*tls_alert_send_cb)(int _alert_desc, void *_cb_arg);
55
56/*
57 * Buffers.
58 */
59struct tls_buffer;
60
61struct tls_buffer *tls_buffer_new(size_t init_size);
62void tls_buffer_clear(struct tls_buffer *buf);
63void tls_buffer_free(struct tls_buffer *buf);
64void tls_buffer_set_capacity_limit(struct tls_buffer *buf, size_t limit);
65ssize_t tls_buffer_extend(struct tls_buffer *buf, size_t len,
66 tls_read_cb read_cb, void *cb_arg);
67size_t tls_buffer_remaining(struct tls_buffer *buf);
68ssize_t tls_buffer_read(struct tls_buffer *buf, uint8_t *rbuf, size_t n);
69ssize_t tls_buffer_write(struct tls_buffer *buf, const uint8_t *wbuf, size_t n);
70int tls_buffer_append(struct tls_buffer *buf, const uint8_t *wbuf, size_t n);
71int tls_buffer_data(struct tls_buffer *buf, CBS *cbs);
72int tls_buffer_finish(struct tls_buffer *buf, uint8_t **out, size_t *out_len);
73
74/*
75 * Key shares.
76 */
77struct tls_key_share;
78
79struct tls_key_share *tls_key_share_new(uint16_t group_id);
80struct tls_key_share *tls_key_share_new_nid(int nid);
81void tls_key_share_free(struct tls_key_share *ks);
82
83uint16_t tls_key_share_group(struct tls_key_share *ks);
84int tls_key_share_nid(struct tls_key_share *ks);
85void tls_key_share_set_key_bits(struct tls_key_share *ks, size_t key_bits);
86int tls_key_share_set_dh_params(struct tls_key_share *ks, DH *dh_params);
87int tls_key_share_peer_pkey(struct tls_key_share *ks, EVP_PKEY *pkey);
88int tls_key_share_generate(struct tls_key_share *ks);
89int tls_key_share_params(struct tls_key_share *ks, CBB *cbb);
90int tls_key_share_public(struct tls_key_share *ks, CBB *cbb);
91int tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs,
92 int *decode_error, int *invalid_params);
93int tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs,
94 int *decode_error, int *invalid_key);
95int tls_key_share_derive(struct tls_key_share *ks, uint8_t **shared_key,
96 size_t *shared_key_len);
97int tls_key_share_peer_security(const SSL *ssl, struct tls_key_share *ks);
98
99__END_HIDDEN_DECLS
100
101#endif
diff --git a/src/lib/libssl/tls_key_share.c b/src/lib/libssl/tls_key_share.c
deleted file mode 100644
index cf7b1da262..0000000000
--- a/src/lib/libssl/tls_key_share.c
+++ /dev/null
@@ -1,484 +0,0 @@
1/* $OpenBSD: tls_key_share.c,v 1.8 2022/11/26 16:08:56 tb Exp $ */
2/*
3 * Copyright (c) 2020, 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdlib.h>
19
20#include <openssl/curve25519.h>
21#include <openssl/dh.h>
22#include <openssl/ec.h>
23#include <openssl/evp.h>
24
25#include "bytestring.h"
26#include "ssl_local.h"
27#include "tls_internal.h"
28
29struct tls_key_share {
30 int nid;
31 uint16_t group_id;
32 size_t key_bits;
33
34 DH *dhe;
35 DH *dhe_peer;
36
37 EC_KEY *ecdhe;
38 EC_KEY *ecdhe_peer;
39
40 uint8_t *x25519_public;
41 uint8_t *x25519_private;
42 uint8_t *x25519_peer_public;
43};
44
45static struct tls_key_share *
46tls_key_share_new_internal(int nid, uint16_t group_id)
47{
48 struct tls_key_share *ks;
49
50 if ((ks = calloc(1, sizeof(struct tls_key_share))) == NULL)
51 return NULL;
52
53 ks->group_id = group_id;
54 ks->nid = nid;
55
56 return ks;
57}
58
59struct tls_key_share *
60tls_key_share_new(uint16_t group_id)
61{
62 int nid;
63
64 if (!tls1_ec_group_id2nid(group_id, &nid))
65 return NULL;
66
67 return tls_key_share_new_internal(nid, group_id);
68}
69
70struct tls_key_share *
71tls_key_share_new_nid(int nid)
72{
73 uint16_t group_id = 0;
74
75 if (nid != NID_dhKeyAgreement) {
76 if (!tls1_ec_nid2group_id(nid, &group_id))
77 return NULL;
78 }
79
80 return tls_key_share_new_internal(nid, group_id);
81}
82
83void
84tls_key_share_free(struct tls_key_share *ks)
85{
86 if (ks == NULL)
87 return;
88
89 DH_free(ks->dhe);
90 DH_free(ks->dhe_peer);
91
92 EC_KEY_free(ks->ecdhe);
93 EC_KEY_free(ks->ecdhe_peer);
94
95 freezero(ks->x25519_public, X25519_KEY_LENGTH);
96 freezero(ks->x25519_private, X25519_KEY_LENGTH);
97 freezero(ks->x25519_peer_public, X25519_KEY_LENGTH);
98
99 freezero(ks, sizeof(*ks));
100}
101
102uint16_t
103tls_key_share_group(struct tls_key_share *ks)
104{
105 return ks->group_id;
106}
107
108int
109tls_key_share_nid(struct tls_key_share *ks)
110{
111 return ks->nid;
112}
113
114void
115tls_key_share_set_key_bits(struct tls_key_share *ks, size_t key_bits)
116{
117 ks->key_bits = key_bits;
118}
119
120int
121tls_key_share_set_dh_params(struct tls_key_share *ks, DH *dh_params)
122{
123 if (ks->nid != NID_dhKeyAgreement)
124 return 0;
125 if (ks->dhe != NULL || ks->dhe_peer != NULL)
126 return 0;
127
128 if ((ks->dhe = DHparams_dup(dh_params)) == NULL)
129 return 0;
130 if ((ks->dhe_peer = DHparams_dup(dh_params)) == NULL)
131 return 0;
132
133 return 1;
134}
135
136int
137tls_key_share_peer_pkey(struct tls_key_share *ks, EVP_PKEY *pkey)
138{
139 if (ks->nid == NID_dhKeyAgreement && ks->dhe_peer != NULL)
140 return EVP_PKEY_set1_DH(pkey, ks->dhe_peer);
141
142 if (ks->nid == NID_X25519 && ks->x25519_peer_public != NULL)
143 return ssl_kex_dummy_ecdhe_x25519(pkey);
144
145 if (ks->ecdhe_peer != NULL)
146 return EVP_PKEY_set1_EC_KEY(pkey, ks->ecdhe_peer);
147
148 return 0;
149}
150
151static int
152tls_key_share_generate_dhe(struct tls_key_share *ks)
153{
154 /*
155 * If auto params are not being used then we must already have DH
156 * parameters set.
157 */
158 if (ks->key_bits == 0) {
159 if (ks->dhe == NULL)
160 return 0;
161
162 return ssl_kex_generate_dhe(ks->dhe, ks->dhe);
163 }
164
165 if (ks->dhe != NULL || ks->dhe_peer != NULL)
166 return 0;
167
168 if ((ks->dhe = DH_new()) == NULL)
169 return 0;
170 if (!ssl_kex_generate_dhe_params_auto(ks->dhe, ks->key_bits))
171 return 0;
172 if ((ks->dhe_peer = DHparams_dup(ks->dhe)) == NULL)
173 return 0;
174
175 return 1;
176}
177
178static int
179tls_key_share_generate_ecdhe_ecp(struct tls_key_share *ks)
180{
181 EC_KEY *ecdhe = NULL;
182 int ret = 0;
183
184 if (ks->ecdhe != NULL)
185 goto err;
186
187 if ((ecdhe = EC_KEY_new()) == NULL)
188 goto err;
189 if (!ssl_kex_generate_ecdhe_ecp(ecdhe, ks->nid))
190 goto err;
191
192 ks->ecdhe = ecdhe;
193 ecdhe = NULL;
194
195 ret = 1;
196
197 err:
198 EC_KEY_free(ecdhe);
199
200 return ret;
201}
202
203static int
204tls_key_share_generate_x25519(struct tls_key_share *ks)
205{
206 uint8_t *public = NULL, *private = NULL;
207 int ret = 0;
208
209 if (ks->x25519_public != NULL || ks->x25519_private != NULL)
210 goto err;
211
212 if ((public = calloc(1, X25519_KEY_LENGTH)) == NULL)
213 goto err;
214 if ((private = calloc(1, X25519_KEY_LENGTH)) == NULL)
215 goto err;
216
217 X25519_keypair(public, private);
218
219 ks->x25519_public = public;
220 ks->x25519_private = private;
221 public = NULL;
222 private = NULL;
223
224 ret = 1;
225
226 err:
227 freezero(public, X25519_KEY_LENGTH);
228 freezero(private, X25519_KEY_LENGTH);
229
230 return ret;
231}
232
233int
234tls_key_share_generate(struct tls_key_share *ks)
235{
236 if (ks->nid == NID_dhKeyAgreement)
237 return tls_key_share_generate_dhe(ks);
238
239 if (ks->nid == NID_X25519)
240 return tls_key_share_generate_x25519(ks);
241
242 return tls_key_share_generate_ecdhe_ecp(ks);
243}
244
245static int
246tls_key_share_params_dhe(struct tls_key_share *ks, CBB *cbb)
247{
248 if (ks->dhe == NULL)
249 return 0;
250
251 return ssl_kex_params_dhe(ks->dhe, cbb);
252}
253
254int
255tls_key_share_params(struct tls_key_share *ks, CBB *cbb)
256{
257 if (ks->nid == NID_dhKeyAgreement)
258 return tls_key_share_params_dhe(ks, cbb);
259
260 return 0;
261}
262
263static int
264tls_key_share_public_dhe(struct tls_key_share *ks, CBB *cbb)
265{
266 if (ks->dhe == NULL)
267 return 0;
268
269 return ssl_kex_public_dhe(ks->dhe, cbb);
270}
271
272static int
273tls_key_share_public_ecdhe_ecp(struct tls_key_share *ks, CBB *cbb)
274{
275 if (ks->ecdhe == NULL)
276 return 0;
277
278 return ssl_kex_public_ecdhe_ecp(ks->ecdhe, cbb);
279}
280
281static int
282tls_key_share_public_x25519(struct tls_key_share *ks, CBB *cbb)
283{
284 if (ks->x25519_public == NULL)
285 return 0;
286
287 return CBB_add_bytes(cbb, ks->x25519_public, X25519_KEY_LENGTH);
288}
289
290int
291tls_key_share_public(struct tls_key_share *ks, CBB *cbb)
292{
293 if (ks->nid == NID_dhKeyAgreement)
294 return tls_key_share_public_dhe(ks, cbb);
295
296 if (ks->nid == NID_X25519)
297 return tls_key_share_public_x25519(ks, cbb);
298
299 return tls_key_share_public_ecdhe_ecp(ks, cbb);
300}
301
302static int
303tls_key_share_peer_params_dhe(struct tls_key_share *ks, CBS *cbs,
304 int *decode_error, int *invalid_params)
305{
306 if (ks->dhe != NULL || ks->dhe_peer != NULL)
307 return 0;
308
309 if ((ks->dhe_peer = DH_new()) == NULL)
310 return 0;
311 if (!ssl_kex_peer_params_dhe(ks->dhe_peer, cbs, decode_error,
312 invalid_params))
313 return 0;
314 if ((ks->dhe = DHparams_dup(ks->dhe_peer)) == NULL)
315 return 0;
316
317 return 1;
318}
319
320int
321tls_key_share_peer_params(struct tls_key_share *ks, CBS *cbs,
322 int *decode_error, int *invalid_params)
323{
324 if (ks->nid != NID_dhKeyAgreement)
325 return 0;
326
327 return tls_key_share_peer_params_dhe(ks, cbs, decode_error,
328 invalid_params);
329}
330
331static int
332tls_key_share_peer_public_dhe(struct tls_key_share *ks, CBS *cbs,
333 int *decode_error, int *invalid_key)
334{
335 if (ks->dhe_peer == NULL)
336 return 0;
337
338 return ssl_kex_peer_public_dhe(ks->dhe_peer, cbs, decode_error,
339 invalid_key);
340}
341
342static int
343tls_key_share_peer_public_ecdhe_ecp(struct tls_key_share *ks, CBS *cbs)
344{
345 EC_KEY *ecdhe = NULL;
346 int ret = 0;
347
348 if (ks->ecdhe_peer != NULL)
349 goto err;
350
351 if ((ecdhe = EC_KEY_new()) == NULL)
352 goto err;
353 if (!ssl_kex_peer_public_ecdhe_ecp(ecdhe, ks->nid, cbs))
354 goto err;
355
356 ks->ecdhe_peer = ecdhe;
357 ecdhe = NULL;
358
359 ret = 1;
360
361 err:
362 EC_KEY_free(ecdhe);
363
364 return ret;
365}
366
367static int
368tls_key_share_peer_public_x25519(struct tls_key_share *ks, CBS *cbs,
369 int *decode_error)
370{
371 size_t out_len;
372
373 *decode_error = 0;
374
375 if (ks->x25519_peer_public != NULL)
376 return 0;
377
378 if (CBS_len(cbs) != X25519_KEY_LENGTH) {
379 *decode_error = 1;
380 return 0;
381 }
382
383 return CBS_stow(cbs, &ks->x25519_peer_public, &out_len);
384}
385
386int
387tls_key_share_peer_public(struct tls_key_share *ks, CBS *cbs, int *decode_error,
388 int *invalid_key)
389{
390 *decode_error = 0;
391
392 if (invalid_key != NULL)
393 *invalid_key = 0;
394
395 if (ks->nid == NID_dhKeyAgreement)
396 return tls_key_share_peer_public_dhe(ks, cbs, decode_error,
397 invalid_key);
398
399 if (ks->nid == NID_X25519)
400 return tls_key_share_peer_public_x25519(ks, cbs, decode_error);
401
402 return tls_key_share_peer_public_ecdhe_ecp(ks, cbs);
403}
404
405static int
406tls_key_share_derive_dhe(struct tls_key_share *ks,
407 uint8_t **shared_key, size_t *shared_key_len)
408{
409 if (ks->dhe == NULL || ks->dhe_peer == NULL)
410 return 0;
411
412 return ssl_kex_derive_dhe(ks->dhe, ks->dhe_peer, shared_key,
413 shared_key_len);
414}
415
416static int
417tls_key_share_derive_ecdhe_ecp(struct tls_key_share *ks,
418 uint8_t **shared_key, size_t *shared_key_len)
419{
420 if (ks->ecdhe == NULL || ks->ecdhe_peer == NULL)
421 return 0;
422
423 return ssl_kex_derive_ecdhe_ecp(ks->ecdhe, ks->ecdhe_peer,
424 shared_key, shared_key_len);
425}
426
427static int
428tls_key_share_derive_x25519(struct tls_key_share *ks,
429 uint8_t **shared_key, size_t *shared_key_len)
430{
431 uint8_t *sk = NULL;
432 int ret = 0;
433
434 if (ks->x25519_private == NULL || ks->x25519_peer_public == NULL)
435 goto err;
436
437 if ((sk = calloc(1, X25519_KEY_LENGTH)) == NULL)
438 goto err;
439 if (!X25519(sk, ks->x25519_private, ks->x25519_peer_public))
440 goto err;
441
442 *shared_key = sk;
443 *shared_key_len = X25519_KEY_LENGTH;
444 sk = NULL;
445
446 ret = 1;
447
448 err:
449 freezero(sk, X25519_KEY_LENGTH);
450
451 return ret;
452}
453
454int
455tls_key_share_derive(struct tls_key_share *ks, uint8_t **shared_key,
456 size_t *shared_key_len)
457{
458 if (*shared_key != NULL)
459 return 0;
460
461 *shared_key_len = 0;
462
463 if (ks->nid == NID_dhKeyAgreement)
464 return tls_key_share_derive_dhe(ks, shared_key,
465 shared_key_len);
466
467 if (ks->nid == NID_X25519)
468 return tls_key_share_derive_x25519(ks, shared_key,
469 shared_key_len);
470
471 return tls_key_share_derive_ecdhe_ecp(ks, shared_key,
472 shared_key_len);
473}
474
475int
476tls_key_share_peer_security(const SSL *ssl, struct tls_key_share *ks)
477{
478 switch (ks->nid) {
479 case NID_dhKeyAgreement:
480 return ssl_security_dh(ssl, ks->dhe_peer);
481 default:
482 return 0;
483 }
484}
diff --git a/src/lib/libssl/tls_lib.c b/src/lib/libssl/tls_lib.c
deleted file mode 100644
index db734c34e4..0000000000
--- a/src/lib/libssl/tls_lib.c
+++ /dev/null
@@ -1,68 +0,0 @@
1/* $OpenBSD: tls_lib.c,v 1.3 2022/11/26 16:08:56 tb Exp $ */
2/*
3 * Copyright (c) 2019, 2021 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include "ssl_local.h"
19
20int
21tls_process_peer_certs(SSL *s, STACK_OF(X509) *peer_certs)
22{
23 STACK_OF(X509) *peer_certs_no_leaf;
24 X509 *peer_cert = NULL;
25 EVP_PKEY *pkey;
26 int cert_type;
27 int ret = 0;
28
29 if (sk_X509_num(peer_certs) < 1)
30 goto err;
31 peer_cert = sk_X509_value(peer_certs, 0);
32 X509_up_ref(peer_cert);
33
34 if ((pkey = X509_get0_pubkey(peer_cert)) == NULL) {
35 SSLerror(s, SSL_R_NO_PUBLICKEY);
36 goto err;
37 }
38 if (EVP_PKEY_missing_parameters(pkey)) {
39 SSLerror(s, SSL_R_UNABLE_TO_FIND_PUBLIC_KEY_PARAMETERS);
40 goto err;
41 }
42 if ((cert_type = ssl_cert_type(pkey)) < 0) {
43 SSLerror(s, SSL_R_UNKNOWN_CERTIFICATE_TYPE);
44 goto err;
45 }
46
47 s->session->peer_cert_type = cert_type;
48
49 X509_free(s->session->peer_cert);
50 s->session->peer_cert = peer_cert;
51 peer_cert = NULL;
52
53 sk_X509_pop_free(s->s3->hs.peer_certs, X509_free);
54 if ((s->s3->hs.peer_certs = X509_chain_up_ref(peer_certs)) == NULL)
55 goto err;
56
57 if ((peer_certs_no_leaf = X509_chain_up_ref(peer_certs)) == NULL)
58 goto err;
59 X509_free(sk_X509_shift(peer_certs_no_leaf));
60 sk_X509_pop_free(s->s3->hs.peer_certs_no_leaf, X509_free);
61 s->s3->hs.peer_certs_no_leaf = peer_certs_no_leaf;
62
63 ret = 1;
64 err:
65 X509_free(peer_cert);
66
67 return ret;
68}