William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1 | /* |
| 2 | * This file contains the sample fetches related to the SSL |
| 3 | * |
| 4 | * Copyright (C) 2012 EXCELIANCE, Emeric Brun <ebrun@exceliance.fr> |
| 5 | * Copyright (C) 2020 HAProxy Technologies, William Lallemand <wlallemand@haproxy.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; either version |
| 10 | * 2 of the License, or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #define _GNU_SOURCE |
| 14 | #include <ctype.h> |
| 15 | #include <dirent.h> |
| 16 | #include <errno.h> |
| 17 | #include <fcntl.h> |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <unistd.h> |
| 22 | |
Willy Tarreau | dcc048a | 2020-06-04 19:11:43 +0200 | [diff] [blame] | 23 | #include <haproxy/acl.h> |
Willy Tarreau | 4c7e4b7 | 2020-05-27 12:58:42 +0200 | [diff] [blame] | 24 | #include <haproxy/api.h> |
Willy Tarreau | b255105 | 2020-06-09 09:07:15 +0200 | [diff] [blame] | 25 | #include <haproxy/arg.h> |
Willy Tarreau | 2741c8c | 2020-06-02 11:28:02 +0200 | [diff] [blame] | 26 | #include <haproxy/buf-t.h> |
Willy Tarreau | 8efbdfb | 2020-06-04 11:29:21 +0200 | [diff] [blame] | 27 | #include <haproxy/obj_type.h> |
Willy Tarreau | 6019fab | 2020-05-27 16:26:00 +0200 | [diff] [blame] | 28 | #include <haproxy/openssl-compat.h> |
Willy Tarreau | e6ce10b | 2020-06-04 15:33:47 +0200 | [diff] [blame] | 29 | #include <haproxy/sample.h> |
Willy Tarreau | 209108d | 2020-06-04 20:30:20 +0200 | [diff] [blame] | 30 | #include <haproxy/ssl_sock.h> |
Willy Tarreau | b2bd865 | 2020-06-04 14:21:22 +0200 | [diff] [blame] | 31 | #include <haproxy/ssl_utils.h> |
Willy Tarreau | 48fbcae | 2020-06-03 18:09:46 +0200 | [diff] [blame] | 32 | #include <haproxy/tools.h> |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 33 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 34 | |
| 35 | /***** Below are some sample fetching functions for ACL/patterns *****/ |
| 36 | |
| 37 | static int |
| 38 | smp_fetch_ssl_fc_has_early(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 39 | { |
| 40 | SSL *ssl; |
| 41 | struct connection *conn; |
| 42 | |
| 43 | conn = objt_conn(smp->sess->origin); |
| 44 | ssl = ssl_sock_get_ssl_object(conn); |
| 45 | if (!ssl) |
| 46 | return 0; |
| 47 | |
| 48 | smp->flags = 0; |
| 49 | smp->data.type = SMP_T_BOOL; |
| 50 | #ifdef OPENSSL_IS_BORINGSSL |
| 51 | { |
| 52 | smp->data.u.sint = (SSL_in_early_data(ssl) && |
| 53 | SSL_early_data_accepted(ssl)); |
| 54 | } |
| 55 | #else |
| 56 | smp->data.u.sint = ((conn->flags & CO_FL_EARLY_DATA) && |
| 57 | (conn->flags & (CO_FL_EARLY_SSL_HS | CO_FL_SSL_WAIT_HS))) ? 1 : 0; |
| 58 | #endif |
| 59 | return 1; |
| 60 | } |
| 61 | |
| 62 | /* boolean, returns true if client cert was present */ |
| 63 | static int |
| 64 | smp_fetch_ssl_fc_has_crt(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 65 | { |
| 66 | struct connection *conn; |
| 67 | struct ssl_sock_ctx *ctx; |
| 68 | |
| 69 | conn = objt_conn(smp->sess->origin); |
| 70 | if (!conn || conn->xprt != &ssl_sock) |
| 71 | return 0; |
| 72 | |
| 73 | ctx = conn->xprt_ctx; |
| 74 | |
| 75 | if (conn->flags & CO_FL_WAIT_XPRT) { |
| 76 | smp->flags |= SMP_F_MAY_CHANGE; |
| 77 | return 0; |
| 78 | } |
| 79 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 80 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 81 | smp->data.type = SMP_T_BOOL; |
| 82 | smp->data.u.sint = SSL_SOCK_ST_FL_VERIFY_DONE & ctx->xprt_st ? 1 : 0; |
| 83 | |
| 84 | return 1; |
| 85 | } |
| 86 | |
| 87 | /* binary, returns a certificate in a binary chunk (der/raw). |
| 88 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 89 | * should be use. |
| 90 | */ |
| 91 | static int |
| 92 | smp_fetch_ssl_x_der(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 93 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 94 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 95 | int conn_server = (kw[4] == 's') ? 1 : 0; |
| 96 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 97 | X509 *crt = NULL; |
| 98 | int ret = 0; |
| 99 | struct buffer *smp_trash; |
| 100 | struct connection *conn; |
| 101 | SSL *ssl; |
| 102 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 103 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 104 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 105 | else |
| 106 | conn = objt_conn(smp->sess->origin); |
| 107 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 108 | ssl = ssl_sock_get_ssl_object(conn); |
| 109 | if (!ssl) |
| 110 | return 0; |
| 111 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 112 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 113 | smp->flags |= SMP_F_MAY_CHANGE; |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 118 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 119 | else |
| 120 | crt = SSL_get_certificate(ssl); |
| 121 | |
| 122 | if (!crt) |
| 123 | goto out; |
| 124 | |
| 125 | smp_trash = get_trash_chunk(); |
| 126 | if (ssl_sock_crt2der(crt, smp_trash) <= 0) |
| 127 | goto out; |
| 128 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 129 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 130 | smp->data.u.str = *smp_trash; |
| 131 | smp->data.type = SMP_T_BIN; |
| 132 | ret = 1; |
| 133 | out: |
| 134 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 135 | if (cert_peer && crt) |
| 136 | X509_free(crt); |
| 137 | return ret; |
| 138 | } |
| 139 | |
William Dauchy | a598b50 | 2020-08-06 18:11:38 +0200 | [diff] [blame] | 140 | /* binary, returns a chain certificate in a binary chunk (der/raw). |
| 141 | * The 5th keyword char is used to support only peer cert |
| 142 | */ |
| 143 | static int |
| 144 | smp_fetch_ssl_x_chain_der(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 145 | { |
| 146 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 147 | int conn_server = (kw[4] == 's') ? 1 : 0; |
| 148 | struct buffer *smp_trash; |
| 149 | struct buffer *tmp_trash = NULL; |
| 150 | struct connection *conn; |
| 151 | STACK_OF(X509) *certs = NULL; |
| 152 | X509 *crt = NULL; |
| 153 | SSL *ssl; |
| 154 | int ret = 0; |
| 155 | int num_certs; |
| 156 | int i; |
| 157 | |
| 158 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 159 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Dauchy | a598b50 | 2020-08-06 18:11:38 +0200 | [diff] [blame] | 160 | else |
| 161 | conn = objt_conn(smp->sess->origin); |
| 162 | |
| 163 | if (!conn) |
| 164 | return 0; |
| 165 | |
| 166 | ssl = ssl_sock_get_ssl_object(conn); |
| 167 | if (!ssl) |
| 168 | return 0; |
| 169 | |
| 170 | if (conn->flags & CO_FL_WAIT_XPRT) { |
| 171 | smp->flags |= SMP_F_MAY_CHANGE; |
| 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | if (!cert_peer) |
| 176 | return 0; |
| 177 | |
| 178 | certs = SSL_get_peer_cert_chain(ssl); |
| 179 | if (!certs) |
| 180 | return 0; |
| 181 | |
| 182 | num_certs = sk_X509_num(certs); |
| 183 | if (!num_certs) |
| 184 | goto out; |
| 185 | smp_trash = get_trash_chunk(); |
| 186 | tmp_trash = alloc_trash_chunk(); |
| 187 | if (!tmp_trash) |
| 188 | goto out; |
| 189 | for (i = 0; i < num_certs; i++) { |
| 190 | crt = sk_X509_value(certs, i); |
| 191 | if (ssl_sock_crt2der(crt, tmp_trash) <= 0) |
| 192 | goto out; |
| 193 | chunk_cat(smp_trash, tmp_trash); |
| 194 | } |
| 195 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 196 | smp->flags = SMP_F_VOL_SESS; |
William Dauchy | a598b50 | 2020-08-06 18:11:38 +0200 | [diff] [blame] | 197 | smp->data.u.str = *smp_trash; |
| 198 | smp->data.type = SMP_T_BIN; |
| 199 | ret = 1; |
| 200 | out: |
| 201 | if (tmp_trash) |
| 202 | free_trash_chunk(tmp_trash); |
William Dauchy | a598b50 | 2020-08-06 18:11:38 +0200 | [diff] [blame] | 203 | return ret; |
| 204 | } |
| 205 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 206 | /* binary, returns serial of certificate in a binary chunk. |
| 207 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 208 | * should be use. |
| 209 | */ |
| 210 | static int |
| 211 | smp_fetch_ssl_x_serial(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 212 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 213 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 214 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 215 | X509 *crt = NULL; |
| 216 | int ret = 0; |
| 217 | struct buffer *smp_trash; |
| 218 | struct connection *conn; |
| 219 | SSL *ssl; |
| 220 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 221 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 222 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 223 | else |
| 224 | conn = objt_conn(smp->sess->origin); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 225 | ssl = ssl_sock_get_ssl_object(conn); |
| 226 | if (!ssl) |
| 227 | return 0; |
| 228 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 229 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 230 | smp->flags |= SMP_F_MAY_CHANGE; |
| 231 | return 0; |
| 232 | } |
| 233 | |
| 234 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 235 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 236 | else |
| 237 | crt = SSL_get_certificate(ssl); |
| 238 | |
| 239 | if (!crt) |
| 240 | goto out; |
| 241 | |
| 242 | smp_trash = get_trash_chunk(); |
| 243 | if (ssl_sock_get_serial(crt, smp_trash) <= 0) |
| 244 | goto out; |
| 245 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 246 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 247 | smp->data.u.str = *smp_trash; |
| 248 | smp->data.type = SMP_T_BIN; |
| 249 | ret = 1; |
| 250 | out: |
| 251 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 252 | if (cert_peer && crt) |
| 253 | X509_free(crt); |
| 254 | return ret; |
| 255 | } |
| 256 | |
| 257 | /* binary, returns the client certificate's SHA-1 fingerprint (SHA-1 hash of DER-encoded certificate) in a binary chunk. |
| 258 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 259 | * should be use. |
| 260 | */ |
| 261 | static int |
| 262 | smp_fetch_ssl_x_sha1(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 263 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 264 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 265 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 266 | X509 *crt = NULL; |
| 267 | const EVP_MD *digest; |
| 268 | int ret = 0; |
| 269 | unsigned int len = 0; |
| 270 | struct buffer *smp_trash; |
| 271 | struct connection *conn; |
| 272 | SSL *ssl; |
| 273 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 274 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 275 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 276 | else |
| 277 | conn = objt_conn(smp->sess->origin); |
| 278 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 279 | ssl = ssl_sock_get_ssl_object(conn); |
| 280 | if (!ssl) |
| 281 | return 0; |
| 282 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 283 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 284 | smp->flags |= SMP_F_MAY_CHANGE; |
| 285 | return 0; |
| 286 | } |
| 287 | |
| 288 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 289 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 290 | else |
| 291 | crt = SSL_get_certificate(ssl); |
| 292 | if (!crt) |
| 293 | goto out; |
| 294 | |
| 295 | smp_trash = get_trash_chunk(); |
| 296 | digest = EVP_sha1(); |
| 297 | X509_digest(crt, digest, (unsigned char *) smp_trash->area, &len); |
| 298 | smp_trash->data = len; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 299 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 300 | smp->data.u.str = *smp_trash; |
| 301 | smp->data.type = SMP_T_BIN; |
| 302 | ret = 1; |
| 303 | out: |
| 304 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 305 | if (cert_peer && crt) |
| 306 | X509_free(crt); |
| 307 | return ret; |
| 308 | } |
| 309 | |
| 310 | /* string, returns certificate's notafter date in ASN1_UTCTIME format. |
| 311 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 312 | * should be use. |
| 313 | */ |
| 314 | static int |
| 315 | smp_fetch_ssl_x_notafter(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 316 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 317 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 318 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 319 | X509 *crt = NULL; |
| 320 | int ret = 0; |
| 321 | struct buffer *smp_trash; |
| 322 | struct connection *conn; |
| 323 | SSL *ssl; |
| 324 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 325 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 326 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 327 | else |
| 328 | conn = objt_conn(smp->sess->origin); |
| 329 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 330 | ssl = ssl_sock_get_ssl_object(conn); |
| 331 | if (!ssl) |
| 332 | return 0; |
| 333 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 334 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 335 | smp->flags |= SMP_F_MAY_CHANGE; |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 340 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 341 | else |
| 342 | crt = SSL_get_certificate(ssl); |
| 343 | if (!crt) |
| 344 | goto out; |
| 345 | |
| 346 | smp_trash = get_trash_chunk(); |
| 347 | if (ssl_sock_get_time(X509_getm_notAfter(crt), smp_trash) <= 0) |
| 348 | goto out; |
| 349 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 350 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 351 | smp->data.u.str = *smp_trash; |
| 352 | smp->data.type = SMP_T_STR; |
| 353 | ret = 1; |
| 354 | out: |
| 355 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 356 | if (cert_peer && crt) |
| 357 | X509_free(crt); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | /* string, returns a string of a formatted full dn \C=..\O=..\OU=.. \CN=.. of certificate's issuer |
| 362 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 363 | * should be use. |
| 364 | */ |
| 365 | static int |
| 366 | smp_fetch_ssl_x_i_dn(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 367 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 368 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 369 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 370 | X509 *crt = NULL; |
| 371 | X509_NAME *name; |
| 372 | int ret = 0; |
| 373 | struct buffer *smp_trash; |
| 374 | struct connection *conn; |
| 375 | SSL *ssl; |
| 376 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 377 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 378 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 379 | else |
| 380 | conn = objt_conn(smp->sess->origin); |
| 381 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 382 | ssl = ssl_sock_get_ssl_object(conn); |
| 383 | if (!ssl) |
| 384 | return 0; |
| 385 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 386 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 387 | smp->flags |= SMP_F_MAY_CHANGE; |
| 388 | return 0; |
| 389 | } |
| 390 | |
| 391 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 392 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 393 | else |
| 394 | crt = SSL_get_certificate(ssl); |
| 395 | if (!crt) |
| 396 | goto out; |
| 397 | |
| 398 | name = X509_get_issuer_name(crt); |
| 399 | if (!name) |
| 400 | goto out; |
| 401 | |
| 402 | smp_trash = get_trash_chunk(); |
Christopher Faulet | 3702f78 | 2021-01-29 11:30:37 +0100 | [diff] [blame] | 403 | if (args[0].type == ARGT_STR && args[0].data.str.data > 0) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 404 | int pos = 1; |
| 405 | |
| 406 | if (args[1].type == ARGT_SINT) |
| 407 | pos = args[1].data.sint; |
| 408 | |
| 409 | if (ssl_sock_get_dn_entry(name, &args[0].data.str, pos, smp_trash) <= 0) |
| 410 | goto out; |
| 411 | } |
Christopher Faulet | 3702f78 | 2021-01-29 11:30:37 +0100 | [diff] [blame] | 412 | else if (args[2].type == ARGT_STR && args[2].data.str.data > 0) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 413 | if (ssl_sock_get_dn_formatted(name, &args[2].data.str, smp_trash) <= 0) |
| 414 | goto out; |
| 415 | } |
| 416 | else if (ssl_sock_get_dn_oneline(name, smp_trash) <= 0) |
| 417 | goto out; |
| 418 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 419 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 420 | smp->data.type = SMP_T_STR; |
| 421 | smp->data.u.str = *smp_trash; |
| 422 | ret = 1; |
| 423 | out: |
| 424 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 425 | if (cert_peer && crt) |
| 426 | X509_free(crt); |
| 427 | return ret; |
| 428 | } |
| 429 | |
| 430 | /* string, returns notbefore date in ASN1_UTCTIME format. |
| 431 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 432 | * should be use. |
| 433 | */ |
| 434 | static int |
| 435 | smp_fetch_ssl_x_notbefore(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 436 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 437 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 438 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 439 | X509 *crt = NULL; |
| 440 | int ret = 0; |
| 441 | struct buffer *smp_trash; |
| 442 | struct connection *conn; |
| 443 | SSL *ssl; |
| 444 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 445 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 446 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 447 | else |
| 448 | conn = objt_conn(smp->sess->origin); |
| 449 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 450 | ssl = ssl_sock_get_ssl_object(conn); |
| 451 | if (!ssl) |
| 452 | return 0; |
| 453 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 454 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 455 | smp->flags |= SMP_F_MAY_CHANGE; |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 460 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 461 | else |
| 462 | crt = SSL_get_certificate(ssl); |
| 463 | if (!crt) |
| 464 | goto out; |
| 465 | |
| 466 | smp_trash = get_trash_chunk(); |
| 467 | if (ssl_sock_get_time(X509_getm_notBefore(crt), smp_trash) <= 0) |
| 468 | goto out; |
| 469 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 470 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 471 | smp->data.u.str = *smp_trash; |
| 472 | smp->data.type = SMP_T_STR; |
| 473 | ret = 1; |
| 474 | out: |
| 475 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 476 | if (cert_peer && crt) |
| 477 | X509_free(crt); |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | /* string, returns a string of a formatted full dn \C=..\O=..\OU=.. \CN=.. of certificate's subject |
| 482 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 483 | * should be use. |
| 484 | */ |
| 485 | static int |
| 486 | smp_fetch_ssl_x_s_dn(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 487 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 488 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 489 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 490 | X509 *crt = NULL; |
| 491 | X509_NAME *name; |
| 492 | int ret = 0; |
| 493 | struct buffer *smp_trash; |
| 494 | struct connection *conn; |
| 495 | SSL *ssl; |
| 496 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 497 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 498 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 499 | else |
| 500 | conn = objt_conn(smp->sess->origin); |
| 501 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 502 | ssl = ssl_sock_get_ssl_object(conn); |
| 503 | if (!ssl) |
| 504 | return 0; |
| 505 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 506 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 507 | smp->flags |= SMP_F_MAY_CHANGE; |
| 508 | return 0; |
| 509 | } |
| 510 | |
| 511 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 512 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 513 | else |
| 514 | crt = SSL_get_certificate(ssl); |
| 515 | if (!crt) |
| 516 | goto out; |
| 517 | |
| 518 | name = X509_get_subject_name(crt); |
| 519 | if (!name) |
| 520 | goto out; |
| 521 | |
| 522 | smp_trash = get_trash_chunk(); |
Christopher Faulet | 3702f78 | 2021-01-29 11:30:37 +0100 | [diff] [blame] | 523 | if (args[0].type == ARGT_STR && args[0].data.str.data > 0) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 524 | int pos = 1; |
| 525 | |
| 526 | if (args[1].type == ARGT_SINT) |
| 527 | pos = args[1].data.sint; |
| 528 | |
| 529 | if (ssl_sock_get_dn_entry(name, &args[0].data.str, pos, smp_trash) <= 0) |
| 530 | goto out; |
| 531 | } |
Christopher Faulet | 3702f78 | 2021-01-29 11:30:37 +0100 | [diff] [blame] | 532 | else if (args[2].type == ARGT_STR && args[2].data.str.data > 0) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 533 | if (ssl_sock_get_dn_formatted(name, &args[2].data.str, smp_trash) <= 0) |
| 534 | goto out; |
| 535 | } |
| 536 | else if (ssl_sock_get_dn_oneline(name, smp_trash) <= 0) |
| 537 | goto out; |
| 538 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 539 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 540 | smp->data.type = SMP_T_STR; |
| 541 | smp->data.u.str = *smp_trash; |
| 542 | ret = 1; |
| 543 | out: |
| 544 | /* SSL_get_peer_certificate, it increase X509 * ref count */ |
| 545 | if (cert_peer && crt) |
| 546 | X509_free(crt); |
| 547 | return ret; |
| 548 | } |
| 549 | |
| 550 | /* integer, returns true if current session use a client certificate */ |
| 551 | static int |
| 552 | smp_fetch_ssl_c_used(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 553 | { |
| 554 | X509 *crt; |
| 555 | struct connection *conn; |
| 556 | SSL *ssl; |
| 557 | |
| 558 | conn = objt_conn(smp->sess->origin); |
| 559 | ssl = ssl_sock_get_ssl_object(conn); |
| 560 | if (!ssl) |
| 561 | return 0; |
| 562 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 563 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 564 | smp->flags |= SMP_F_MAY_CHANGE; |
| 565 | return 0; |
| 566 | } |
| 567 | |
| 568 | /* SSL_get_peer_certificate returns a ptr on allocated X509 struct */ |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 569 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 570 | if (crt) { |
| 571 | X509_free(crt); |
| 572 | } |
| 573 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 574 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 575 | smp->data.type = SMP_T_BOOL; |
| 576 | smp->data.u.sint = (crt != NULL); |
| 577 | return 1; |
| 578 | } |
| 579 | |
| 580 | /* integer, returns the certificate version |
| 581 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 582 | * should be use. |
| 583 | */ |
| 584 | static int |
| 585 | smp_fetch_ssl_x_version(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 586 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 587 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 588 | int conn_server = (kw[4] == 's') ? 1 : 0; |
| 589 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 590 | X509 *crt; |
| 591 | struct connection *conn; |
| 592 | SSL *ssl; |
| 593 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 594 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 595 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 596 | else |
| 597 | conn = objt_conn(smp->sess->origin); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 598 | ssl = ssl_sock_get_ssl_object(conn); |
| 599 | if (!ssl) |
| 600 | return 0; |
| 601 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 602 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 603 | smp->flags |= SMP_F_MAY_CHANGE; |
| 604 | return 0; |
| 605 | } |
| 606 | |
| 607 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 608 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 609 | else |
| 610 | crt = SSL_get_certificate(ssl); |
| 611 | if (!crt) |
| 612 | return 0; |
| 613 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 614 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 615 | smp->data.u.sint = (unsigned int)(1 + X509_get_version(crt)); |
| 616 | /* SSL_get_peer_certificate increase X509 * ref count */ |
| 617 | if (cert_peer) |
| 618 | X509_free(crt); |
| 619 | smp->data.type = SMP_T_SINT; |
| 620 | |
| 621 | return 1; |
| 622 | } |
| 623 | |
| 624 | /* string, returns the certificate's signature algorithm. |
| 625 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 626 | * should be use. |
| 627 | */ |
| 628 | static int |
| 629 | smp_fetch_ssl_x_sig_alg(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 630 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 631 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 632 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 633 | X509 *crt; |
| 634 | __OPENSSL_110_CONST__ ASN1_OBJECT *algorithm; |
| 635 | int nid; |
| 636 | struct connection *conn; |
| 637 | SSL *ssl; |
| 638 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 639 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 640 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 641 | else |
| 642 | conn = objt_conn(smp->sess->origin); |
| 643 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 644 | ssl = ssl_sock_get_ssl_object(conn); |
| 645 | if (!ssl) |
| 646 | return 0; |
| 647 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 648 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 649 | smp->flags |= SMP_F_MAY_CHANGE; |
| 650 | return 0; |
| 651 | } |
| 652 | |
| 653 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 654 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 655 | else |
| 656 | crt = SSL_get_certificate(ssl); |
| 657 | if (!crt) |
| 658 | return 0; |
| 659 | |
| 660 | X509_ALGOR_get0(&algorithm, NULL, NULL, X509_get0_tbs_sigalg(crt)); |
| 661 | nid = OBJ_obj2nid(algorithm); |
| 662 | |
| 663 | smp->data.u.str.area = (char *)OBJ_nid2sn(nid); |
| 664 | if (!smp->data.u.str.area) { |
| 665 | /* SSL_get_peer_certificate increase X509 * ref count */ |
| 666 | if (cert_peer) |
| 667 | X509_free(crt); |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | smp->data.type = SMP_T_STR; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 672 | smp->flags |= SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 673 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
| 674 | /* SSL_get_peer_certificate increase X509 * ref count */ |
| 675 | if (cert_peer) |
| 676 | X509_free(crt); |
| 677 | |
| 678 | return 1; |
| 679 | } |
| 680 | |
| 681 | /* string, returns the certificate's key algorithm. |
| 682 | * The 5th keyword char is used to know if SSL_get_certificate or SSL_get_peer_certificate |
| 683 | * should be use. |
| 684 | */ |
| 685 | static int |
| 686 | smp_fetch_ssl_x_key_alg(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 687 | { |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 688 | int cert_peer = (kw[4] == 'c' || kw[4] == 's') ? 1 : 0; |
| 689 | int conn_server = (kw[4] == 's') ? 1 : 0; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 690 | X509 *crt; |
| 691 | ASN1_OBJECT *algorithm; |
| 692 | int nid; |
| 693 | struct connection *conn; |
| 694 | SSL *ssl; |
| 695 | |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 696 | if (conn_server) |
Amaury Denoyelle | 5fcd428 | 2021-07-21 11:50:12 +0200 | [diff] [blame] | 697 | conn = smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 698 | else |
| 699 | conn = objt_conn(smp->sess->origin); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 700 | ssl = ssl_sock_get_ssl_object(conn); |
| 701 | if (!ssl) |
| 702 | return 0; |
| 703 | |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 704 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 705 | smp->flags |= SMP_F_MAY_CHANGE; |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | if (cert_peer) |
Remi Tricot-Le Breton | 74f6ab6 | 2021-08-19 18:06:30 +0200 | [diff] [blame] | 710 | crt = ssl_sock_get_peer_certificate(ssl); |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 711 | else |
| 712 | crt = SSL_get_certificate(ssl); |
| 713 | if (!crt) |
| 714 | return 0; |
| 715 | |
| 716 | X509_PUBKEY_get0_param(&algorithm, NULL, NULL, NULL, X509_get_X509_PUBKEY(crt)); |
| 717 | nid = OBJ_obj2nid(algorithm); |
| 718 | |
| 719 | smp->data.u.str.area = (char *)OBJ_nid2sn(nid); |
| 720 | if (!smp->data.u.str.area) { |
| 721 | /* SSL_get_peer_certificate increase X509 * ref count */ |
| 722 | if (cert_peer) |
| 723 | X509_free(crt); |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | smp->data.type = SMP_T_STR; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 728 | smp->flags |= SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 729 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
| 730 | if (cert_peer) |
| 731 | X509_free(crt); |
| 732 | |
| 733 | return 1; |
| 734 | } |
| 735 | |
| 736 | /* boolean, returns true if front conn. transport layer is SSL. |
| 737 | * This function is also usable on backend conn if the fetch keyword 5th |
| 738 | * char is 'b'. |
| 739 | */ |
| 740 | static int |
| 741 | smp_fetch_ssl_fc(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 742 | { |
| 743 | struct connection *conn; |
| 744 | |
| 745 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 746 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 747 | else |
| 748 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 749 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 750 | |
| 751 | smp->data.type = SMP_T_BOOL; |
| 752 | smp->data.u.sint = (conn && conn->xprt == &ssl_sock); |
| 753 | return 1; |
| 754 | } |
| 755 | |
| 756 | /* boolean, returns true if client present a SNI */ |
| 757 | static int |
| 758 | smp_fetch_ssl_fc_has_sni(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 759 | { |
| 760 | #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
| 761 | struct connection *conn = objt_conn(smp->sess->origin); |
| 762 | SSL *ssl = ssl_sock_get_ssl_object(conn); |
| 763 | |
| 764 | smp->data.type = SMP_T_BOOL; |
| 765 | smp->data.u.sint = ssl && SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name) != NULL; |
| 766 | return 1; |
| 767 | #else |
| 768 | return 0; |
| 769 | #endif |
| 770 | } |
| 771 | |
| 772 | /* boolean, returns true if client session has been resumed. |
| 773 | * This function is also usable on backend conn if the fetch keyword 5th |
| 774 | * char is 'b'. |
| 775 | */ |
| 776 | static int |
| 777 | smp_fetch_ssl_fc_is_resumed(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 778 | { |
| 779 | struct connection *conn; |
| 780 | SSL *ssl; |
| 781 | |
| 782 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 783 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 784 | else |
| 785 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 786 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 787 | |
| 788 | ssl = ssl_sock_get_ssl_object(conn); |
| 789 | |
| 790 | smp->data.type = SMP_T_BOOL; |
| 791 | smp->data.u.sint = ssl && SSL_session_reused(ssl); |
| 792 | return 1; |
| 793 | } |
| 794 | |
| 795 | /* string, returns the used cipher if front conn. transport layer is SSL. |
| 796 | * This function is also usable on backend conn if the fetch keyword 5th |
| 797 | * char is 'b'. |
| 798 | */ |
| 799 | static int |
| 800 | smp_fetch_ssl_fc_cipher(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 801 | { |
| 802 | struct connection *conn; |
| 803 | SSL *ssl; |
| 804 | |
| 805 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 806 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 807 | else |
| 808 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 809 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 810 | |
| 811 | smp->flags = 0; |
| 812 | ssl = ssl_sock_get_ssl_object(conn); |
| 813 | if (!ssl) |
| 814 | return 0; |
| 815 | |
| 816 | smp->data.u.str.area = (char *)SSL_get_cipher_name(ssl); |
| 817 | if (!smp->data.u.str.area) |
| 818 | return 0; |
| 819 | |
| 820 | smp->data.type = SMP_T_STR; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 821 | smp->flags |= SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 822 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
| 823 | |
| 824 | return 1; |
| 825 | } |
| 826 | |
| 827 | /* integer, returns the algoritm's keysize if front conn. transport layer |
| 828 | * is SSL. |
| 829 | * This function is also usable on backend conn if the fetch keyword 5th |
| 830 | * char is 'b'. |
| 831 | */ |
| 832 | static int |
| 833 | smp_fetch_ssl_fc_alg_keysize(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 834 | { |
| 835 | struct connection *conn; |
| 836 | SSL *ssl; |
| 837 | int sint; |
| 838 | |
| 839 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 840 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 841 | else |
| 842 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 843 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 844 | |
| 845 | smp->flags = 0; |
| 846 | ssl = ssl_sock_get_ssl_object(conn); |
| 847 | if (!ssl) |
| 848 | return 0; |
| 849 | |
| 850 | if (!SSL_get_cipher_bits(ssl, &sint)) |
| 851 | return 0; |
| 852 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 853 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 854 | smp->data.u.sint = sint; |
| 855 | smp->data.type = SMP_T_SINT; |
| 856 | |
| 857 | return 1; |
| 858 | } |
| 859 | |
| 860 | /* integer, returns the used keysize if front conn. transport layer is SSL. |
| 861 | * This function is also usable on backend conn if the fetch keyword 5th |
| 862 | * char is 'b'. |
| 863 | */ |
| 864 | static int |
| 865 | smp_fetch_ssl_fc_use_keysize(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 866 | { |
| 867 | struct connection *conn; |
| 868 | SSL *ssl; |
| 869 | |
| 870 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 871 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 872 | else |
| 873 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 874 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 875 | |
| 876 | smp->flags = 0; |
| 877 | ssl = ssl_sock_get_ssl_object(conn); |
| 878 | if (!ssl) |
| 879 | return 0; |
| 880 | |
| 881 | smp->data.u.sint = (unsigned int)SSL_get_cipher_bits(ssl, NULL); |
| 882 | if (!smp->data.u.sint) |
| 883 | return 0; |
| 884 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 885 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 886 | smp->data.type = SMP_T_SINT; |
| 887 | |
| 888 | return 1; |
| 889 | } |
| 890 | |
| 891 | #if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
| 892 | static int |
| 893 | smp_fetch_ssl_fc_npn(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 894 | { |
| 895 | struct connection *conn; |
| 896 | SSL *ssl; |
| 897 | unsigned int len = 0; |
| 898 | |
| 899 | smp->flags = SMP_F_CONST; |
| 900 | smp->data.type = SMP_T_STR; |
| 901 | |
| 902 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 903 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 904 | else |
| 905 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 906 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 907 | |
| 908 | ssl = ssl_sock_get_ssl_object(conn); |
| 909 | if (!ssl) |
| 910 | return 0; |
| 911 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 912 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 913 | smp->data.u.str.area = NULL; |
| 914 | SSL_get0_next_proto_negotiated(ssl, |
| 915 | (const unsigned char **)&smp->data.u.str.area, |
| 916 | &len); |
| 917 | |
| 918 | if (!smp->data.u.str.area) |
| 919 | return 0; |
| 920 | |
| 921 | smp->data.u.str.data = len; |
| 922 | return 1; |
| 923 | } |
| 924 | #endif |
| 925 | |
| 926 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 927 | static int |
| 928 | smp_fetch_ssl_fc_alpn(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 929 | { |
| 930 | struct connection *conn; |
| 931 | SSL *ssl; |
| 932 | unsigned int len = 0; |
| 933 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 934 | smp->flags = SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 935 | smp->data.type = SMP_T_STR; |
| 936 | |
| 937 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 938 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 939 | else |
| 940 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 941 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 942 | |
| 943 | ssl = ssl_sock_get_ssl_object(conn); |
| 944 | if (!ssl) |
| 945 | return 0; |
| 946 | |
| 947 | smp->data.u.str.area = NULL; |
| 948 | SSL_get0_alpn_selected(ssl, |
| 949 | (const unsigned char **)&smp->data.u.str.area, |
| 950 | &len); |
| 951 | |
| 952 | if (!smp->data.u.str.area) |
| 953 | return 0; |
| 954 | |
| 955 | smp->data.u.str.data = len; |
| 956 | return 1; |
| 957 | } |
| 958 | #endif |
| 959 | |
| 960 | /* string, returns the used protocol if front conn. transport layer is SSL. |
| 961 | * This function is also usable on backend conn if the fetch keyword 5th |
| 962 | * char is 'b'. |
| 963 | */ |
| 964 | static int |
| 965 | smp_fetch_ssl_fc_protocol(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 966 | { |
| 967 | struct connection *conn; |
| 968 | SSL *ssl; |
| 969 | |
| 970 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 971 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 972 | else |
| 973 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 974 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 975 | |
| 976 | smp->flags = 0; |
| 977 | ssl = ssl_sock_get_ssl_object(conn); |
| 978 | if (!ssl) |
| 979 | return 0; |
| 980 | |
| 981 | smp->data.u.str.area = (char *)SSL_get_version(ssl); |
| 982 | if (!smp->data.u.str.area) |
| 983 | return 0; |
| 984 | |
| 985 | smp->data.type = SMP_T_STR; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 986 | smp->flags = SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 987 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
| 988 | |
| 989 | return 1; |
| 990 | } |
| 991 | |
| 992 | /* binary, returns the SSL stream id if front conn. transport layer is SSL. |
| 993 | * This function is also usable on backend conn if the fetch keyword 5th |
| 994 | * char is 'b'. |
| 995 | */ |
| 996 | #if HA_OPENSSL_VERSION_NUMBER > 0x0090800fL |
| 997 | static int |
| 998 | smp_fetch_ssl_fc_session_id(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 999 | { |
| 1000 | struct connection *conn; |
| 1001 | SSL_SESSION *ssl_sess; |
| 1002 | SSL *ssl; |
| 1003 | unsigned int len = 0; |
| 1004 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1005 | smp->flags = SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1006 | smp->data.type = SMP_T_BIN; |
| 1007 | |
| 1008 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 1009 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1010 | else |
| 1011 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1012 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1013 | |
| 1014 | ssl = ssl_sock_get_ssl_object(conn); |
| 1015 | if (!ssl) |
| 1016 | return 0; |
| 1017 | |
| 1018 | ssl_sess = SSL_get_session(ssl); |
| 1019 | if (!ssl_sess) |
| 1020 | return 0; |
| 1021 | |
| 1022 | smp->data.u.str.area = (char *)SSL_SESSION_get_id(ssl_sess, &len); |
| 1023 | if (!smp->data.u.str.area || !len) |
| 1024 | return 0; |
| 1025 | |
| 1026 | smp->data.u.str.data = len; |
| 1027 | return 1; |
| 1028 | } |
| 1029 | #endif |
| 1030 | |
| 1031 | |
Ilya Shipitsin | df62794 | 2021-03-25 00:41:41 +0500 | [diff] [blame] | 1032 | #ifdef HAVE_SSL_EXTRACT_RANDOM |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1033 | static int |
| 1034 | smp_fetch_ssl_fc_random(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1035 | { |
| 1036 | struct connection *conn; |
| 1037 | struct buffer *data; |
| 1038 | SSL *ssl; |
| 1039 | |
| 1040 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 1041 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1042 | else |
| 1043 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1044 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1045 | |
| 1046 | ssl = ssl_sock_get_ssl_object(conn); |
| 1047 | if (!ssl) |
| 1048 | return 0; |
| 1049 | |
| 1050 | data = get_trash_chunk(); |
| 1051 | if (kw[7] == 'c') |
| 1052 | data->data = SSL_get_client_random(ssl, |
| 1053 | (unsigned char *) data->area, |
| 1054 | data->size); |
| 1055 | else |
| 1056 | data->data = SSL_get_server_random(ssl, |
| 1057 | (unsigned char *) data->area, |
| 1058 | data->size); |
| 1059 | if (!data->data) |
| 1060 | return 0; |
| 1061 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1062 | smp->flags = SMP_F_VOL_TEST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1063 | smp->data.type = SMP_T_BIN; |
| 1064 | smp->data.u.str = *data; |
| 1065 | |
| 1066 | return 1; |
| 1067 | } |
| 1068 | |
| 1069 | static int |
| 1070 | smp_fetch_ssl_fc_session_key(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1071 | { |
| 1072 | struct connection *conn; |
| 1073 | SSL_SESSION *ssl_sess; |
| 1074 | struct buffer *data; |
| 1075 | SSL *ssl; |
| 1076 | |
| 1077 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 1078 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1079 | else |
| 1080 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1081 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1082 | |
| 1083 | ssl = ssl_sock_get_ssl_object(conn); |
| 1084 | if (!ssl) |
| 1085 | return 0; |
| 1086 | |
| 1087 | ssl_sess = SSL_get_session(ssl); |
| 1088 | if (!ssl_sess) |
| 1089 | return 0; |
| 1090 | |
| 1091 | data = get_trash_chunk(); |
| 1092 | data->data = SSL_SESSION_get_master_key(ssl_sess, |
| 1093 | (unsigned char *) data->area, |
| 1094 | data->size); |
| 1095 | if (!data->data) |
| 1096 | return 0; |
| 1097 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1098 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1099 | smp->data.type = SMP_T_BIN; |
| 1100 | smp->data.u.str = *data; |
| 1101 | |
| 1102 | return 1; |
| 1103 | } |
| 1104 | #endif |
| 1105 | |
| 1106 | #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
| 1107 | static int |
| 1108 | smp_fetch_ssl_fc_sni(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1109 | { |
| 1110 | struct connection *conn; |
| 1111 | SSL *ssl; |
| 1112 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1113 | smp->flags = SMP_F_VOL_SESS | SMP_F_CONST; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1114 | smp->data.type = SMP_T_STR; |
| 1115 | |
| 1116 | conn = objt_conn(smp->sess->origin); |
| 1117 | ssl = ssl_sock_get_ssl_object(conn); |
| 1118 | if (!ssl) |
| 1119 | return 0; |
| 1120 | |
| 1121 | smp->data.u.str.area = (char *)SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); |
| 1122 | if (!smp->data.u.str.area) |
| 1123 | return 0; |
| 1124 | |
| 1125 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
| 1126 | return 1; |
| 1127 | } |
| 1128 | #endif |
| 1129 | |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1130 | /* binary, returns tls client hello cipher list. |
| 1131 | * Arguments: filter_option (0,1) |
| 1132 | */ |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1133 | static int |
| 1134 | smp_fetch_ssl_fc_cl_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1135 | { |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1136 | struct buffer *smp_trash; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1137 | struct connection *conn; |
| 1138 | struct ssl_capture *capture; |
| 1139 | SSL *ssl; |
| 1140 | |
| 1141 | conn = objt_conn(smp->sess->origin); |
| 1142 | ssl = ssl_sock_get_ssl_object(conn); |
| 1143 | if (!ssl) |
| 1144 | return 0; |
| 1145 | |
| 1146 | capture = SSL_get_ex_data(ssl, ssl_capture_ptr_index); |
| 1147 | if (!capture) |
| 1148 | return 0; |
| 1149 | |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1150 | if (args[0].data.sint) { |
| 1151 | smp_trash = get_trash_chunk(); |
| 1152 | exclude_tls_grease(capture->data + capture->ciphersuite_offset, capture->ciphersuite_len, smp_trash); |
| 1153 | smp->data.u.str.area = smp_trash->area; |
| 1154 | smp->data.u.str.data = smp_trash->data; |
| 1155 | smp->flags = SMP_F_VOL_SESS; |
| 1156 | } |
| 1157 | else { |
| 1158 | smp->data.u.str.area = capture->data + capture->ciphersuite_offset; |
| 1159 | smp->data.u.str.data = capture->ciphersuite_len; |
| 1160 | smp->flags = SMP_F_VOL_TEST | SMP_F_CONST; |
| 1161 | } |
| 1162 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1163 | smp->data.type = SMP_T_BIN; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1164 | return 1; |
| 1165 | } |
| 1166 | |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1167 | /* binary, returns tls client hello cipher list as hexadecimal string. |
| 1168 | * Arguments: filter_option (0,1) |
| 1169 | */ |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1170 | static int |
| 1171 | smp_fetch_ssl_fc_cl_hex(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1172 | { |
| 1173 | struct buffer *data; |
| 1174 | |
| 1175 | if (!smp_fetch_ssl_fc_cl_bin(args, smp, kw, private)) |
| 1176 | return 0; |
| 1177 | |
| 1178 | data = get_trash_chunk(); |
| 1179 | dump_binary(data, smp->data.u.str.area, smp->data.u.str.data); |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1180 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1181 | smp->data.type = SMP_T_BIN; |
| 1182 | smp->data.u.str = *data; |
| 1183 | return 1; |
| 1184 | } |
| 1185 | |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1186 | /* integer, returns xxh64 hash of tls client hello cipher list. */ |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1187 | static int |
| 1188 | smp_fetch_ssl_fc_cl_xxh64(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1189 | { |
| 1190 | struct connection *conn; |
| 1191 | struct ssl_capture *capture; |
| 1192 | SSL *ssl; |
| 1193 | |
| 1194 | conn = objt_conn(smp->sess->origin); |
| 1195 | ssl = ssl_sock_get_ssl_object(conn); |
| 1196 | if (!ssl) |
| 1197 | return 0; |
| 1198 | |
| 1199 | capture = SSL_get_ex_data(ssl, ssl_capture_ptr_index); |
| 1200 | if (!capture) |
| 1201 | return 0; |
| 1202 | |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1203 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1204 | smp->data.type = SMP_T_SINT; |
| 1205 | smp->data.u.sint = capture->xxh64; |
| 1206 | return 1; |
| 1207 | } |
| 1208 | |
Remi Tricot-Le Breton | 7c6898e | 2021-07-29 09:45:51 +0200 | [diff] [blame] | 1209 | static int |
| 1210 | smp_fetch_ssl_fc_hsk_err(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1211 | { |
| 1212 | struct connection *conn; |
| 1213 | struct ssl_sock_ctx *ctx; |
| 1214 | |
Remi Tricot-Le Breton | 163cdeb | 2021-09-01 15:52:14 +0200 | [diff] [blame^] | 1215 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
| 1216 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
| 1217 | else |
| 1218 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1219 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1220 | |
Remi Tricot-Le Breton | 7c6898e | 2021-07-29 09:45:51 +0200 | [diff] [blame] | 1221 | if (!conn || conn->xprt != &ssl_sock) |
| 1222 | return 0; |
| 1223 | ctx = conn->xprt_ctx; |
| 1224 | |
| 1225 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
| 1226 | smp->flags = SMP_F_MAY_CHANGE; |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | if (!ctx) |
| 1231 | return 0; |
| 1232 | |
| 1233 | smp->flags = SMP_F_VOL_SESS; |
| 1234 | smp->data.type = SMP_T_SINT; |
| 1235 | smp->data.u.sint = ctx->hsk_error_code; |
| 1236 | return 1; |
| 1237 | } |
| 1238 | |
| 1239 | static int |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1240 | smp_fetch_ssl_fc_protocol_hello_id(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1241 | { |
| 1242 | struct connection *conn; |
| 1243 | struct ssl_capture *capture; |
| 1244 | SSL *ssl; |
| 1245 | |
| 1246 | conn = objt_conn(smp->sess->origin); |
| 1247 | ssl = ssl_sock_get_ssl_object(conn); |
| 1248 | if (!ssl) |
| 1249 | return 0; |
| 1250 | |
| 1251 | capture = SSL_get_ex_data(ssl, ssl_capture_ptr_index); |
| 1252 | if (!capture) |
| 1253 | return 0; |
| 1254 | |
| 1255 | smp->flags = SMP_F_VOL_SESS; |
| 1256 | smp->data.type = SMP_T_SINT; |
| 1257 | smp->data.u.sint = capture->protocol_version; |
| 1258 | return 1; |
| 1259 | } |
| 1260 | |
| 1261 | static int |
Remi Tricot-Le Breton | 7c6898e | 2021-07-29 09:45:51 +0200 | [diff] [blame] | 1262 | smp_fetch_ssl_fc_hsk_err_str(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1263 | { |
| 1264 | struct connection *conn; |
| 1265 | struct ssl_sock_ctx *ctx; |
| 1266 | const char *err_code_str; |
| 1267 | |
Remi Tricot-Le Breton | 163cdeb | 2021-09-01 15:52:14 +0200 | [diff] [blame^] | 1268 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
| 1269 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
| 1270 | else |
| 1271 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1272 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1273 | |
Remi Tricot-Le Breton | 7c6898e | 2021-07-29 09:45:51 +0200 | [diff] [blame] | 1274 | if (!conn || conn->xprt != &ssl_sock) |
| 1275 | return 0; |
| 1276 | ctx = conn->xprt_ctx; |
| 1277 | |
| 1278 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
| 1279 | smp->flags = SMP_F_MAY_CHANGE; |
| 1280 | return 0; |
| 1281 | } |
| 1282 | |
| 1283 | if (!ctx || !ctx->hsk_error_code) |
| 1284 | return 0; |
| 1285 | |
| 1286 | err_code_str = ERR_error_string(ctx->hsk_error_code, NULL); |
| 1287 | |
| 1288 | smp->flags = SMP_F_VOL_SESS; |
| 1289 | smp->data.type = SMP_T_STR; |
| 1290 | smp->data.u.str.area = (char*)err_code_str; |
| 1291 | smp->data.u.str.data = strlen(err_code_str); |
| 1292 | |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | /* binary, returns tls client hello extensions list. |
| 1297 | * Arguments: filter_option (0,1) |
| 1298 | */ |
| 1299 | static int |
| 1300 | smp_fetch_ssl_fc_ext_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1301 | { |
| 1302 | struct buffer *smp_trash; |
| 1303 | struct connection *conn; |
| 1304 | struct ssl_capture *capture; |
| 1305 | SSL *ssl; |
| 1306 | |
| 1307 | conn = objt_conn(smp->sess->origin); |
| 1308 | ssl = ssl_sock_get_ssl_object(conn); |
| 1309 | if (!ssl) |
| 1310 | return 0; |
| 1311 | |
| 1312 | capture = SSL_get_ex_data(ssl, ssl_capture_ptr_index); |
| 1313 | if (!capture) |
| 1314 | return 0; |
| 1315 | |
| 1316 | if (args[0].data.sint) { |
| 1317 | smp_trash = get_trash_chunk(); |
| 1318 | exclude_tls_grease(capture->data + capture->extensions_offset, capture->extensions_len, smp_trash); |
| 1319 | smp->data.u.str.area = smp_trash->area; |
| 1320 | smp->data.u.str.data = smp_trash->data; |
| 1321 | smp->flags = SMP_F_VOL_SESS; |
| 1322 | } |
| 1323 | else { |
| 1324 | smp->data.u.str.area = capture->data + capture->extensions_offset; |
| 1325 | smp->data.u.str.data = capture->extensions_len; |
| 1326 | smp->flags = SMP_F_VOL_TEST | SMP_F_CONST; |
| 1327 | } |
| 1328 | |
| 1329 | smp->data.type = SMP_T_BIN; |
| 1330 | return 1; |
| 1331 | } |
| 1332 | |
| 1333 | /* binary, returns tls client hello supported elliptic curves. |
| 1334 | * Arguments: filter_option (0,1) |
| 1335 | */ |
| 1336 | static int |
| 1337 | smp_fetch_ssl_fc_ecl_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1338 | { |
| 1339 | struct buffer *smp_trash; |
| 1340 | struct connection *conn; |
| 1341 | struct ssl_capture *capture; |
| 1342 | SSL *ssl; |
| 1343 | |
| 1344 | conn = objt_conn(smp->sess->origin); |
| 1345 | ssl = ssl_sock_get_ssl_object(conn); |
| 1346 | if (!ssl) |
| 1347 | return 0; |
| 1348 | |
| 1349 | capture = SSL_get_ex_data(ssl, ssl_capture_ptr_index); |
| 1350 | if (!capture) |
| 1351 | return 0; |
| 1352 | |
| 1353 | if (args[0].data.sint) { |
| 1354 | smp_trash = get_trash_chunk(); |
| 1355 | exclude_tls_grease(capture->data + capture->ec_offset, capture->ec_len, smp_trash); |
| 1356 | smp->data.u.str.area = smp_trash->area; |
| 1357 | smp->data.u.str.data = smp_trash->data; |
| 1358 | smp->flags = SMP_F_VOL_SESS; |
| 1359 | } |
| 1360 | else { |
| 1361 | smp->data.u.str.area = capture->data + capture->ec_offset; |
| 1362 | smp->data.u.str.data = capture->ec_len; |
| 1363 | smp->flags = SMP_F_VOL_TEST | SMP_F_CONST; |
| 1364 | } |
| 1365 | |
| 1366 | smp->data.type = SMP_T_BIN; |
| 1367 | return 1; |
| 1368 | } |
| 1369 | |
| 1370 | /* binary, returns tls client hello supported elliptic curve point formats */ |
| 1371 | static int |
| 1372 | smp_fetch_ssl_fc_ecf_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1373 | { |
| 1374 | struct connection *conn; |
| 1375 | struct ssl_capture *capture; |
| 1376 | SSL *ssl; |
| 1377 | |
| 1378 | conn = objt_conn(smp->sess->origin); |
| 1379 | ssl = ssl_sock_get_ssl_object(conn); |
| 1380 | if (!ssl) |
| 1381 | return 0; |
| 1382 | |
| 1383 | capture = SSL_get_ex_data(ssl, ssl_capture_ptr_index); |
| 1384 | if (!capture) |
| 1385 | return 0; |
| 1386 | |
| 1387 | smp->flags = SMP_F_VOL_TEST | SMP_F_CONST; |
| 1388 | smp->data.type = SMP_T_BIN; |
| 1389 | smp->data.u.str.area = capture->data + capture->ec_formats_offset; |
| 1390 | smp->data.u.str.data = capture->ec_formats_len; |
Remi Tricot-Le Breton | 7c6898e | 2021-07-29 09:45:51 +0200 | [diff] [blame] | 1391 | return 1; |
| 1392 | } |
| 1393 | |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1394 | /* Dump the SSL keylog, it only works with "tune.ssl.keylog 1" */ |
William Lallemand | 722180a | 2021-06-09 16:46:12 +0200 | [diff] [blame] | 1395 | #ifdef HAVE_SSL_KEYLOG |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1396 | static int smp_fetch_ssl_x_keylog(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1397 | { |
| 1398 | struct connection *conn; |
| 1399 | struct ssl_keylog *keylog; |
| 1400 | SSL *ssl; |
| 1401 | char *src = NULL; |
| 1402 | const char *sfx; |
| 1403 | |
| 1404 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1405 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1406 | |
William Lallemand | eec1d45 | 2020-07-07 10:48:13 +0200 | [diff] [blame] | 1407 | if (!conn) |
| 1408 | return 0; |
| 1409 | |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1410 | if (conn->flags & CO_FL_WAIT_XPRT) { |
| 1411 | smp->flags |= SMP_F_MAY_CHANGE; |
| 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | ssl = ssl_sock_get_ssl_object(conn); |
| 1416 | if (!ssl) |
| 1417 | return 0; |
| 1418 | |
| 1419 | keylog = SSL_get_ex_data(ssl, ssl_keylog_index); |
| 1420 | if (!keylog) |
| 1421 | return 0; |
| 1422 | |
| 1423 | sfx = kw + strlen("ssl_xx_"); |
| 1424 | |
| 1425 | if (strcmp(sfx, "client_early_traffic_secret") == 0) { |
| 1426 | src = keylog->client_early_traffic_secret; |
| 1427 | } else if (strcmp(sfx, "client_handshake_traffic_secret") == 0) { |
| 1428 | src = keylog->client_handshake_traffic_secret; |
| 1429 | } else if (strcmp(sfx, "server_handshake_traffic_secret") == 0) { |
| 1430 | src = keylog->server_handshake_traffic_secret; |
| 1431 | } else if (strcmp(sfx, "client_traffic_secret_0") == 0) { |
| 1432 | src = keylog->client_traffic_secret_0; |
| 1433 | } else if (strcmp(sfx, "server_traffic_secret_0") == 0) { |
| 1434 | src = keylog->server_traffic_secret_0; |
| 1435 | } else if (strcmp(sfx, "exporter_secret") == 0) { |
| 1436 | src = keylog->exporter_secret; |
| 1437 | } else if (strcmp(sfx, "early_exporter_secret") == 0) { |
| 1438 | src = keylog->early_exporter_secret; |
| 1439 | } |
| 1440 | |
| 1441 | if (!src || !*src) |
| 1442 | return 0; |
| 1443 | |
| 1444 | smp->data.u.str.area = src; |
| 1445 | smp->data.type = SMP_T_STR; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1446 | smp->flags |= SMP_F_VOL_TEST | SMP_F_CONST; |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1447 | smp->data.u.str.data = strlen(smp->data.u.str.area); |
| 1448 | return 1; |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1449 | } |
| 1450 | #endif |
| 1451 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1452 | static int |
| 1453 | smp_fetch_ssl_fc_cl_str(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1454 | { |
Ilya Shipitsin | c9dfee4 | 2020-10-31 02:10:02 +0500 | [diff] [blame] | 1455 | #if defined(OPENSSL_IS_BORINGSSL) || defined(SSL_CTRL_GET_RAW_CIPHERLIST) |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1456 | struct buffer *data; |
| 1457 | int i; |
| 1458 | |
| 1459 | if (!smp_fetch_ssl_fc_cl_bin(args, smp, kw, private)) |
| 1460 | return 0; |
| 1461 | |
| 1462 | data = get_trash_chunk(); |
| 1463 | for (i = 0; i + 1 < smp->data.u.str.data; i += 2) { |
| 1464 | const char *str; |
| 1465 | const SSL_CIPHER *cipher; |
| 1466 | const unsigned char *bin = (const unsigned char *) smp->data.u.str.area + i; |
| 1467 | uint16_t id = (bin[0] << 8) | bin[1]; |
| 1468 | #if defined(OPENSSL_IS_BORINGSSL) |
| 1469 | cipher = SSL_get_cipher_by_value(id); |
| 1470 | #else |
| 1471 | struct connection *conn = __objt_conn(smp->sess->origin); |
| 1472 | SSL *ssl = ssl_sock_get_ssl_object(conn); |
| 1473 | cipher = SSL_CIPHER_find(ssl, bin); |
| 1474 | #endif |
| 1475 | str = SSL_CIPHER_get_name(cipher); |
| 1476 | if (!str || strcmp(str, "(NONE)") == 0) |
| 1477 | chunk_appendf(data, "%sUNKNOWN(%04x)", i == 0 ? "" : ",", id); |
| 1478 | else |
| 1479 | chunk_appendf(data, "%s%s", i == 0 ? "" : ",", str); |
| 1480 | } |
| 1481 | smp->data.type = SMP_T_STR; |
| 1482 | smp->data.u.str = *data; |
| 1483 | return 1; |
| 1484 | #else |
| 1485 | return smp_fetch_ssl_fc_cl_xxh64(args, smp, kw, private); |
| 1486 | #endif |
| 1487 | } |
| 1488 | |
| 1489 | #if HA_OPENSSL_VERSION_NUMBER > 0x0090800fL |
| 1490 | static int |
| 1491 | smp_fetch_ssl_fc_unique_id(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1492 | { |
| 1493 | struct connection *conn; |
| 1494 | int finished_len; |
| 1495 | struct buffer *finished_trash; |
| 1496 | SSL *ssl; |
| 1497 | |
| 1498 | if (obj_type(smp->sess->origin) == OBJ_TYPE_CHECK) |
Christopher Faulet | 4bef8d1 | 2021-04-14 15:49:41 +0200 | [diff] [blame] | 1499 | conn = (kw[4] == 'b') ? cs_conn(__objt_check(smp->sess->origin)->cs) : NULL; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1500 | else |
| 1501 | conn = (kw[4] != 'b') ? objt_conn(smp->sess->origin) : |
| 1502 | smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL; |
| 1503 | |
| 1504 | smp->flags = 0; |
| 1505 | ssl = ssl_sock_get_ssl_object(conn); |
| 1506 | if (!ssl) |
| 1507 | return 0; |
| 1508 | |
| 1509 | if (conn->flags & CO_FL_WAIT_XPRT) { |
| 1510 | smp->flags |= SMP_F_MAY_CHANGE; |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
| 1514 | finished_trash = get_trash_chunk(); |
| 1515 | if (!SSL_session_reused(ssl)) |
| 1516 | finished_len = SSL_get_peer_finished(ssl, |
| 1517 | finished_trash->area, |
| 1518 | finished_trash->size); |
| 1519 | else |
| 1520 | finished_len = SSL_get_finished(ssl, |
| 1521 | finished_trash->area, |
| 1522 | finished_trash->size); |
| 1523 | |
| 1524 | if (!finished_len) |
| 1525 | return 0; |
| 1526 | |
| 1527 | finished_trash->data = finished_len; |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1528 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1529 | smp->data.u.str = *finished_trash; |
| 1530 | smp->data.type = SMP_T_BIN; |
| 1531 | |
| 1532 | return 1; |
| 1533 | } |
| 1534 | #endif |
| 1535 | |
| 1536 | /* integer, returns the first verify error in CA chain of client certificate chain. */ |
| 1537 | static int |
| 1538 | smp_fetch_ssl_c_ca_err(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1539 | { |
| 1540 | struct connection *conn; |
| 1541 | struct ssl_sock_ctx *ctx; |
| 1542 | |
| 1543 | conn = objt_conn(smp->sess->origin); |
| 1544 | if (!conn || conn->xprt != &ssl_sock) |
| 1545 | return 0; |
| 1546 | ctx = conn->xprt_ctx; |
| 1547 | |
Remi Tricot-Le Breton | 89b65cf | 2021-07-29 09:45:50 +0200 | [diff] [blame] | 1548 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1549 | smp->flags = SMP_F_MAY_CHANGE; |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
Remi Tricot-Le Breton | 89b65cf | 2021-07-29 09:45:50 +0200 | [diff] [blame] | 1553 | if (!ctx) |
| 1554 | return 0; |
| 1555 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1556 | smp->data.type = SMP_T_SINT; |
| 1557 | smp->data.u.sint = (unsigned long long int)SSL_SOCK_ST_TO_CA_ERROR(ctx->xprt_st); |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1558 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1559 | |
| 1560 | return 1; |
| 1561 | } |
| 1562 | |
| 1563 | /* integer, returns the depth of the first verify error in CA chain of client certificate chain. */ |
| 1564 | static int |
| 1565 | smp_fetch_ssl_c_ca_err_depth(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1566 | { |
| 1567 | struct connection *conn; |
| 1568 | struct ssl_sock_ctx *ctx; |
| 1569 | |
| 1570 | conn = objt_conn(smp->sess->origin); |
| 1571 | if (!conn || conn->xprt != &ssl_sock) |
| 1572 | return 0; |
| 1573 | |
Remi Tricot-Le Breton | 89b65cf | 2021-07-29 09:45:50 +0200 | [diff] [blame] | 1574 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1575 | smp->flags = SMP_F_MAY_CHANGE; |
| 1576 | return 0; |
| 1577 | } |
| 1578 | ctx = conn->xprt_ctx; |
| 1579 | |
Remi Tricot-Le Breton | 89b65cf | 2021-07-29 09:45:50 +0200 | [diff] [blame] | 1580 | if (!ctx) |
| 1581 | return 0; |
| 1582 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1583 | smp->data.type = SMP_T_SINT; |
| 1584 | smp->data.u.sint = (long long int)SSL_SOCK_ST_TO_CAEDEPTH(ctx->xprt_st); |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1585 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1586 | |
| 1587 | return 1; |
| 1588 | } |
| 1589 | |
| 1590 | /* integer, returns the first verify error on client certificate */ |
| 1591 | static int |
| 1592 | smp_fetch_ssl_c_err(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1593 | { |
| 1594 | struct connection *conn; |
| 1595 | struct ssl_sock_ctx *ctx; |
| 1596 | |
| 1597 | conn = objt_conn(smp->sess->origin); |
| 1598 | if (!conn || conn->xprt != &ssl_sock) |
| 1599 | return 0; |
| 1600 | |
Remi Tricot-Le Breton | 89b65cf | 2021-07-29 09:45:50 +0200 | [diff] [blame] | 1601 | if (conn->flags & CO_FL_WAIT_XPRT && !conn->err_code) { |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1602 | smp->flags = SMP_F_MAY_CHANGE; |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
| 1606 | ctx = conn->xprt_ctx; |
| 1607 | |
Remi Tricot-Le Breton | 89b65cf | 2021-07-29 09:45:50 +0200 | [diff] [blame] | 1608 | if (!ctx) |
| 1609 | return 0; |
| 1610 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1611 | smp->data.type = SMP_T_SINT; |
| 1612 | smp->data.u.sint = (long long int)SSL_SOCK_ST_TO_CRTERROR(ctx->xprt_st); |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1613 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1614 | |
| 1615 | return 1; |
| 1616 | } |
| 1617 | |
| 1618 | /* integer, returns the verify result on client cert */ |
| 1619 | static int |
| 1620 | smp_fetch_ssl_c_verify(const struct arg *args, struct sample *smp, const char *kw, void *private) |
| 1621 | { |
| 1622 | struct connection *conn; |
| 1623 | SSL *ssl; |
| 1624 | |
| 1625 | conn = objt_conn(smp->sess->origin); |
| 1626 | ssl = ssl_sock_get_ssl_object(conn); |
| 1627 | if (!ssl) |
| 1628 | return 0; |
| 1629 | |
| 1630 | if (conn->flags & CO_FL_WAIT_XPRT) { |
| 1631 | smp->flags = SMP_F_MAY_CHANGE; |
| 1632 | return 0; |
| 1633 | } |
| 1634 | |
| 1635 | smp->data.type = SMP_T_SINT; |
| 1636 | smp->data.u.sint = (long long int)SSL_get_verify_result(ssl); |
Amaury Denoyelle | 2f0a797 | 2020-10-15 16:41:08 +0200 | [diff] [blame] | 1637 | smp->flags = SMP_F_VOL_SESS; |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1638 | |
| 1639 | return 1; |
| 1640 | } |
| 1641 | |
| 1642 | /* Argument validation functions */ |
| 1643 | |
| 1644 | /* This function is used to validate the arguments passed to any "x_dn" ssl |
| 1645 | * keywords. These keywords support specifying a third parameter that must be |
| 1646 | * either empty or the value "rfc2253". Returns 0 on error, non-zero if OK. |
| 1647 | */ |
| 1648 | int val_dnfmt(struct arg *arg, char **err_msg) |
| 1649 | { |
| 1650 | if (arg && arg[2].type == ARGT_STR && arg[2].data.str.data > 0 && (strcmp(arg[2].data.str.area, "rfc2253") != 0)) { |
| 1651 | memprintf(err_msg, "only rfc2253 or a blank value are currently supported as the format argument."); |
| 1652 | return 0; |
| 1653 | } |
| 1654 | return 1; |
| 1655 | } |
| 1656 | |
| 1657 | /* Note: must not be declared <const> as its list will be overwritten. |
| 1658 | * Please take care of keeping this list alphabetically sorted. |
| 1659 | */ |
| 1660 | static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, { |
| 1661 | { "ssl_bc", smp_fetch_ssl_fc, 0, NULL, SMP_T_BOOL, SMP_USE_L5SRV }, |
| 1662 | { "ssl_bc_alg_keysize", smp_fetch_ssl_fc_alg_keysize, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV }, |
| 1663 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 1664 | { "ssl_bc_alpn", smp_fetch_ssl_fc_alpn, 0, NULL, SMP_T_STR, SMP_USE_L5SRV }, |
| 1665 | #endif |
| 1666 | { "ssl_bc_cipher", smp_fetch_ssl_fc_cipher, 0, NULL, SMP_T_STR, SMP_USE_L5SRV }, |
| 1667 | #if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
| 1668 | { "ssl_bc_npn", smp_fetch_ssl_fc_npn, 0, NULL, SMP_T_STR, SMP_USE_L5SRV }, |
| 1669 | #endif |
| 1670 | { "ssl_bc_is_resumed", smp_fetch_ssl_fc_is_resumed, 0, NULL, SMP_T_BOOL, SMP_USE_L5SRV }, |
| 1671 | { "ssl_bc_protocol", smp_fetch_ssl_fc_protocol, 0, NULL, SMP_T_STR, SMP_USE_L5SRV }, |
| 1672 | { "ssl_bc_unique_id", smp_fetch_ssl_fc_unique_id, 0, NULL, SMP_T_BIN, SMP_USE_L5SRV }, |
| 1673 | { "ssl_bc_use_keysize", smp_fetch_ssl_fc_use_keysize, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV }, |
| 1674 | #if HA_OPENSSL_VERSION_NUMBER > 0x0090800fL |
| 1675 | { "ssl_bc_session_id", smp_fetch_ssl_fc_session_id, 0, NULL, SMP_T_BIN, SMP_USE_L5SRV }, |
| 1676 | #endif |
Ilya Shipitsin | df62794 | 2021-03-25 00:41:41 +0500 | [diff] [blame] | 1677 | #ifdef HAVE_SSL_EXTRACT_RANDOM |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1678 | { "ssl_bc_client_random", smp_fetch_ssl_fc_random, 0, NULL, SMP_T_BIN, SMP_USE_L5SRV }, |
| 1679 | { "ssl_bc_server_random", smp_fetch_ssl_fc_random, 0, NULL, SMP_T_BIN, SMP_USE_L5SRV }, |
| 1680 | { "ssl_bc_session_key", smp_fetch_ssl_fc_session_key, 0, NULL, SMP_T_BIN, SMP_USE_L5SRV }, |
| 1681 | #endif |
Remi Tricot-Le Breton | 163cdeb | 2021-09-01 15:52:14 +0200 | [diff] [blame^] | 1682 | { "ssl_bc_hsk_err", smp_fetch_ssl_fc_hsk_err, 0, NULL, SMP_T_SINT, SMP_USE_L5SRV }, |
| 1683 | { "ssl_bc_hsk_err_str", smp_fetch_ssl_fc_hsk_err_str, 0, NULL, SMP_T_STR, SMP_USE_L5SRV }, |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1684 | { "ssl_c_ca_err", smp_fetch_ssl_c_ca_err, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1685 | { "ssl_c_ca_err_depth", smp_fetch_ssl_c_ca_err_depth, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1686 | { "ssl_c_der", smp_fetch_ssl_x_der, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
William Dauchy | a598b50 | 2020-08-06 18:11:38 +0200 | [diff] [blame] | 1687 | { "ssl_c_chain_der", smp_fetch_ssl_x_chain_der, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1688 | { "ssl_c_err", smp_fetch_ssl_c_err, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1689 | { "ssl_c_i_dn", smp_fetch_ssl_x_i_dn, ARG3(0,STR,SINT,STR),val_dnfmt, SMP_T_STR, SMP_USE_L5CLI }, |
| 1690 | { "ssl_c_key_alg", smp_fetch_ssl_x_key_alg, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1691 | { "ssl_c_notafter", smp_fetch_ssl_x_notafter, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1692 | { "ssl_c_notbefore", smp_fetch_ssl_x_notbefore, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1693 | { "ssl_c_sig_alg", smp_fetch_ssl_x_sig_alg, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1694 | { "ssl_c_s_dn", smp_fetch_ssl_x_s_dn, ARG3(0,STR,SINT,STR),val_dnfmt, SMP_T_STR, SMP_USE_L5CLI }, |
| 1695 | { "ssl_c_serial", smp_fetch_ssl_x_serial, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1696 | { "ssl_c_sha1", smp_fetch_ssl_x_sha1, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1697 | { "ssl_c_used", smp_fetch_ssl_c_used, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI }, |
| 1698 | { "ssl_c_verify", smp_fetch_ssl_c_verify, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1699 | { "ssl_c_version", smp_fetch_ssl_x_version, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1700 | { "ssl_f_der", smp_fetch_ssl_x_der, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1701 | { "ssl_f_i_dn", smp_fetch_ssl_x_i_dn, ARG3(0,STR,SINT,STR),val_dnfmt, SMP_T_STR, SMP_USE_L5CLI }, |
| 1702 | { "ssl_f_key_alg", smp_fetch_ssl_x_key_alg, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1703 | { "ssl_f_notafter", smp_fetch_ssl_x_notafter, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1704 | { "ssl_f_notbefore", smp_fetch_ssl_x_notbefore, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1705 | { "ssl_f_sig_alg", smp_fetch_ssl_x_sig_alg, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1706 | { "ssl_f_s_dn", smp_fetch_ssl_x_s_dn, ARG3(0,STR,SINT,STR),val_dnfmt, SMP_T_STR, SMP_USE_L5CLI }, |
| 1707 | { "ssl_f_serial", smp_fetch_ssl_x_serial, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1708 | { "ssl_f_sha1", smp_fetch_ssl_x_sha1, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1709 | { "ssl_f_version", smp_fetch_ssl_x_version, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1710 | { "ssl_fc", smp_fetch_ssl_fc, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI }, |
| 1711 | { "ssl_fc_alg_keysize", smp_fetch_ssl_fc_alg_keysize, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1712 | { "ssl_fc_cipher", smp_fetch_ssl_fc_cipher, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1713 | { "ssl_fc_has_crt", smp_fetch_ssl_fc_has_crt, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI }, |
| 1714 | { "ssl_fc_has_early", smp_fetch_ssl_fc_has_early, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI }, |
| 1715 | { "ssl_fc_has_sni", smp_fetch_ssl_fc_has_sni, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI }, |
| 1716 | { "ssl_fc_is_resumed", smp_fetch_ssl_fc_is_resumed, 0, NULL, SMP_T_BOOL, SMP_USE_L5CLI }, |
| 1717 | #if defined(OPENSSL_NPN_NEGOTIATED) && !defined(OPENSSL_NO_NEXTPROTONEG) |
| 1718 | { "ssl_fc_npn", smp_fetch_ssl_fc_npn, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1719 | #endif |
| 1720 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
| 1721 | { "ssl_fc_alpn", smp_fetch_ssl_fc_alpn, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1722 | #endif |
| 1723 | { "ssl_fc_protocol", smp_fetch_ssl_fc_protocol, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1724 | #if HA_OPENSSL_VERSION_NUMBER > 0x0090800fL |
| 1725 | { "ssl_fc_unique_id", smp_fetch_ssl_fc_unique_id, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1726 | #endif |
| 1727 | { "ssl_fc_use_keysize", smp_fetch_ssl_fc_use_keysize, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1728 | #if HA_OPENSSL_VERSION_NUMBER > 0x0090800fL |
| 1729 | { "ssl_fc_session_id", smp_fetch_ssl_fc_session_id, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1730 | #endif |
Ilya Shipitsin | df62794 | 2021-03-25 00:41:41 +0500 | [diff] [blame] | 1731 | #ifdef HAVE_SSL_EXTRACT_RANDOM |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1732 | { "ssl_fc_client_random", smp_fetch_ssl_fc_random, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1733 | { "ssl_fc_server_random", smp_fetch_ssl_fc_random, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1734 | { "ssl_fc_session_key", smp_fetch_ssl_fc_session_key, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1735 | #endif |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1736 | |
William Lallemand | 722180a | 2021-06-09 16:46:12 +0200 | [diff] [blame] | 1737 | #ifdef HAVE_SSL_KEYLOG |
William Lallemand | 7d42ef5 | 2020-07-06 11:41:30 +0200 | [diff] [blame] | 1738 | { "ssl_fc_client_early_traffic_secret", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1739 | { "ssl_fc_client_handshake_traffic_secret", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1740 | { "ssl_fc_server_handshake_traffic_secret", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1741 | { "ssl_fc_client_traffic_secret_0", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1742 | { "ssl_fc_server_traffic_secret_0", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1743 | { "ssl_fc_exporter_secret", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1744 | { "ssl_fc_early_exporter_secret", smp_fetch_ssl_x_keylog, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1745 | #endif |
| 1746 | |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1747 | #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME |
| 1748 | { "ssl_fc_sni", smp_fetch_ssl_fc_sni, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1749 | #endif |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1750 | { "ssl_fc_cipherlist_bin", smp_fetch_ssl_fc_cl_bin, ARG1(0,SINT), NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1751 | { "ssl_fc_cipherlist_hex", smp_fetch_ssl_fc_cl_hex, ARG1(0,SINT), NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1752 | { "ssl_fc_cipherlist_str", smp_fetch_ssl_fc_cl_str, ARG1(0,SINT), NULL, SMP_T_STR, SMP_USE_L5CLI }, |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1753 | { "ssl_fc_cipherlist_xxh", smp_fetch_ssl_fc_cl_xxh64, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
Remi Tricot-Le Breton | 7c6898e | 2021-07-29 09:45:51 +0200 | [diff] [blame] | 1754 | { "ssl_fc_hsk_err", smp_fetch_ssl_fc_hsk_err, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1755 | { "ssl_fc_hsk_err_str", smp_fetch_ssl_fc_hsk_err_str, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
Marcin Deranek | 959a48c | 2021-07-13 15:14:21 +0200 | [diff] [blame] | 1756 | { "ssl_fc_protocol_hello_id",smp_fetch_ssl_fc_protocol_hello_id,0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
| 1757 | { "ssl_fc_extlist_bin", smp_fetch_ssl_fc_ext_bin, ARG1(0,SINT), NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1758 | { "ssl_fc_eclist_bin", smp_fetch_ssl_fc_ecl_bin, ARG1(0,SINT), NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1759 | { "ssl_fc_ecformats_bin", smp_fetch_ssl_fc_ecf_bin, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 1760 | |
| 1761 | /* SSL server certificate fetches */ |
| 1762 | { "ssl_s_der", smp_fetch_ssl_x_der, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
William Dauchy | a598b50 | 2020-08-06 18:11:38 +0200 | [diff] [blame] | 1763 | { "ssl_s_chain_der", smp_fetch_ssl_x_chain_der, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
William Lallemand | bfa3e81 | 2020-06-25 20:07:18 +0200 | [diff] [blame] | 1764 | { "ssl_s_key_alg", smp_fetch_ssl_x_key_alg, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1765 | { "ssl_s_notafter", smp_fetch_ssl_x_notafter, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1766 | { "ssl_s_notbefore", smp_fetch_ssl_x_notbefore, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1767 | { "ssl_s_sig_alg", smp_fetch_ssl_x_sig_alg, 0, NULL, SMP_T_STR, SMP_USE_L5CLI }, |
| 1768 | { "ssl_s_s_dn", smp_fetch_ssl_x_s_dn, ARG3(0,STR,SINT,STR),val_dnfmt, SMP_T_STR, SMP_USE_L5CLI }, |
| 1769 | { "ssl_s_i_dn", smp_fetch_ssl_x_i_dn, ARG3(0,STR,SINT,STR),val_dnfmt, SMP_T_STR, SMP_USE_L5CLI }, |
| 1770 | { "ssl_s_serial", smp_fetch_ssl_x_serial, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1771 | { "ssl_s_sha1", smp_fetch_ssl_x_sha1, 0, NULL, SMP_T_BIN, SMP_USE_L5CLI }, |
| 1772 | { "ssl_s_version", smp_fetch_ssl_x_version, 0, NULL, SMP_T_SINT, SMP_USE_L5CLI }, |
William Lallemand | 15e1694 | 2020-05-15 00:25:08 +0200 | [diff] [blame] | 1773 | { NULL, NULL, 0, 0, 0 }, |
| 1774 | }}; |
| 1775 | |
| 1776 | INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords); |
| 1777 | |
| 1778 | /* Note: must not be declared <const> as its list will be overwritten. |
| 1779 | * Please take care of keeping this list alphabetically sorted. |
| 1780 | */ |
| 1781 | static struct acl_kw_list acl_kws = {ILH, { |
| 1782 | { "ssl_fc_sni_end", "ssl_fc_sni", PAT_MATCH_END }, |
| 1783 | { "ssl_fc_sni_reg", "ssl_fc_sni", PAT_MATCH_REG }, |
| 1784 | { /* END */ }, |
| 1785 | }}; |
| 1786 | |
| 1787 | INITCALL1(STG_REGISTER, acl_register_keywords, &acl_kws); |