blob: 009c6c6e1aa34ceabbf6610483cc4589164ed0a8 [file] [log] [blame]
Emeric Brunfc0421f2012-09-07 17:30:07 +02001/*
2 * include/types/ssl_sock.h
3 * SSL settings for listeners and servers
4 *
5 * Copyright (C) 2012 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _TYPES_SSL_SOCK_H
23#define _TYPES_SSL_SOCK_H
Willy Tarreauc125cef2019-05-10 09:58:43 +020024#ifdef USE_OPENSSL
Emeric Brunfc0421f2012-09-07 17:30:07 +020025
Emeric Brunfc0421f2012-09-07 17:30:07 +020026#include <ebmbtree.h>
27
Christopher Faulet16f45c82018-02-16 11:23:49 +010028#include <common/hathreads.h>
Willy Tarreau55994562019-05-09 14:52:44 +020029#include <common/openssl-compat.h>
Christopher Faulet16f45c82018-02-16 11:23:49 +010030
Emmanuel Hocdetddc090b2017-10-27 18:43:29 +020031struct pkey_info {
32 uint8_t sig; /* TLSEXT_signature_[rsa,ecdsa,...] */
33 uint16_t bits; /* key size in bits */
34};
35
Emeric Brunfc0421f2012-09-07 17:30:07 +020036struct sni_ctx {
37 SSL_CTX *ctx; /* context associated to the certificate */
38 int order; /* load order for the certificate */
Tim Duesterhus6a0dd732020-01-18 01:32:49 +010039 unsigned int neg:1; /* reject if match */
40 unsigned int wild:1; /* wildcard sni */
Emmanuel Hocdetddc090b2017-10-27 18:43:29 +020041 struct pkey_info kinfo; /* pkey info */
Emmanuel Hocdet98263292016-12-29 18:26:15 +010042 struct ssl_bind_conf *conf; /* ssl "bind" conf for the certificate */
William Lallemand9117de92019-10-04 00:29:42 +020043 struct list by_ckch_inst; /* chained in ckch_inst's list of sni_ctx */
Emeric Brunfc0421f2012-09-07 17:30:07 +020044 struct ebmb_node name; /* node holding the servername value */
45};
46
Emmanuel Hocdet5db33cb2017-03-30 19:19:37 +020047struct tls_version_filter {
48 uint16_t flags; /* ssl options */
49 uint8_t min; /* min TLS version */
50 uint8_t max; /* max TLS version */
51};
52
Nenad Merdanovic200b0fa2015-05-09 08:46:01 +020053extern struct list tlskeys_reference;
54
Emeric Brun9e754772019-01-10 17:51:55 +010055struct tls_sess_key_128 {
Nenad Merdanovic05552d42015-02-27 19:56:49 +010056 unsigned char name[16];
57 unsigned char aes_key[16];
58 unsigned char hmac_key[16];
59} __attribute__((packed));
60
Emeric Brun9e754772019-01-10 17:51:55 +010061struct tls_sess_key_256 {
62 unsigned char name[16];
63 unsigned char aes_key[32];
64 unsigned char hmac_key[32];
65} __attribute__((packed));
66
67union tls_sess_key{
68 unsigned char name[16];
Nenad Merdanovic8ef70652019-04-14 16:06:46 +020069 struct tls_sess_key_128 key_128;
Emeric Brun9e754772019-01-10 17:51:55 +010070 struct tls_sess_key_256 key_256;
71} __attribute__((packed));
72
Nenad Merdanovic146defa2015-05-09 08:46:00 +020073struct tls_keys_ref {
74 struct list list; /* Used to chain refs. */
75 char *filename;
76 int unique_id; /* Each pattern reference have unique id. */
Willy Tarreau17b4aa12018-07-17 10:05:32 +020077 int refcount; /* number of users of this tls_keys_ref. */
Emeric Brun9e754772019-01-10 17:51:55 +010078 union tls_sess_key *tlskeys;
Nenad Merdanovic146defa2015-05-09 08:46:00 +020079 int tls_ticket_enc_index;
Emeric Brun9e754772019-01-10 17:51:55 +010080 int key_size_bits;
Christopher Faulet16f45c82018-02-16 11:23:49 +010081 __decl_hathreads(HA_RWLOCK_T lock); /* lock used to protect the ref */
Nenad Merdanovic146defa2015-05-09 08:46:00 +020082};
83
William Lallemand4f45bb92017-10-30 20:08:51 +010084/* shared ssl session */
85struct sh_ssl_sess_hdr {
86 struct ebmb_node key;
87 unsigned char key_data[SSL_MAX_SSL_SESSION_ID_LENGTH];
88};
89
William Lallemandf6adbe92019-09-11 16:33:52 +020090/* This is used to preload the certifcate, private key
91 * and Cert Chain of a file passed in via the crt
92 * argument
93 *
94 * This way, we do not have to read the file multiple times
95 */
96struct cert_key_and_chain {
97 X509 *cert;
98 EVP_PKEY *key;
99 STACK_OF(X509) *chain;
100 DH *dh;
William Lallemanda17f4112019-10-10 15:16:44 +0200101 struct buffer *sctl;
William Lallemand246c0242019-10-11 08:59:13 +0200102 struct buffer *ocsp_response;
103 X509 *ocsp_issuer;
William Lallemandf6adbe92019-09-11 16:33:52 +0200104};
105
106/*
107 * this is used to store 1 to SSL_SOCK_NUM_KEYTYPES cert_key_and_chain and
108 * metadata.
109 */
110struct ckch_store {
111 struct cert_key_and_chain *ckch;
Tim Duesterhus6a0dd732020-01-18 01:32:49 +0100112 unsigned int multi:1; /* is it a multi-cert bundle ? */
113 unsigned int filters:1;/* one of the instances is using filters, TODO:remove this flag once filters are supported */
William Lallemand9117de92019-10-04 00:29:42 +0200114 struct list ckch_inst; /* list of ckch_inst which uses this ckch_node */
William Lallemandf6adbe92019-09-11 16:33:52 +0200115 struct ebmb_node node;
116 char path[0];
117};
118
William Lallemand9117de92019-10-04 00:29:42 +0200119/*
120 * This structure describe a ckch instance. An instance is generated for each
121 * bind_conf. The instance contains a linked list of the sni ctx which uses
122 * the ckch in this bind_conf.
123 *
124 * XXX: the instance may evolve to handle ssl_bind_conf instead of bind_conf.
125 */
126struct ckch_inst {
127 struct bind_conf *bind_conf; /* pointer to the bind_conf that uses this ckch_inst */
William Lallemand150bfa82019-09-19 17:12:49 +0200128 struct ssl_bind_conf *ssl_conf; /* pointer to the ssl_conf which is used by every sni_ctx of this inst */
William Lallemand21724f02019-11-04 17:56:13 +0100129 int is_default; /* This instance is used as the default ctx for this bind_conf */
William Lallemand9117de92019-10-04 00:29:42 +0200130 struct list sni_ctx; /* list of sni_ctx using this ckch_inst */
131 struct list by_ckchs; /* chained in ckch_store's list of ckch_inst */
132};
William Lallemandf6adbe92019-09-11 16:33:52 +0200133
134#if HA_OPENSSL_VERSION_NUMBER >= 0x1000200fL
135
136#define SSL_SOCK_POSSIBLE_KT_COMBOS (1<<(SSL_SOCK_NUM_KEYTYPES))
137
138struct key_combo_ctx {
139 SSL_CTX *ctx;
140 int order;
141};
142
143/* Map used for processing multiple keypairs for a single purpose
144 *
145 * This maps CN/SNI name to certificate type
146 */
147struct sni_keytype {
148 int keytypes; /* BITMASK for keytypes */
149 struct ebmb_node name; /* node holding the servername value */
150};
151
152#endif
153
Willy Tarreauc125cef2019-05-10 09:58:43 +0200154#endif /* USE_OPENSSL */
Emeric Brunfc0421f2012-09-07 17:30:07 +0200155#endif /* _TYPES_SSL_SOCK_H */