1 /* $NetBSD: tls_proxy.h,v 1.6 2026/05/09 18:49:21 christos Exp $ */ 2 3 #ifndef _TLS_PROXY_H_INCLUDED_ 4 #define _TLS_PROXY_H_INCLUDED_ 5 6 /*++ 7 /* NAME 8 /* tls_proxy_clnt 3h 9 /* SUMMARY 10 /* postscreen TLS proxy support 11 /* SYNOPSIS 12 /* #include <tls_proxy_clnt.h> 13 /* DESCRIPTION 14 /* .nf 15 16 /* 17 * Utility library. 18 */ 19 #include <vstream.h> 20 #include <attr.h> 21 22 /* 23 * TLS library. 24 */ 25 #include <tls.h> 26 27 /* 28 * External interface. 29 */ 30 #define TLS_PROXY_FLAG_ROLE_SERVER (1<<0) /* request server role */ 31 #define TLS_PROXY_FLAG_ROLE_CLIENT (1<<1) /* request client role */ 32 #define TLS_PROXY_FLAG_SEND_CONTEXT (1<<2) /* send TLS context */ 33 34 #ifdef USE_TLS 35 36 /* 37 * TLS_CLIENT_PARAMS structure, to communicate global TLS library settings 38 * that are the same for all TLS client contexts. This information is used 39 * in tlsproxy(8) to detect inconsistencies. If this structure is changed, 40 * update all TLS_CLIENT_PARAMS related functions in tls_proxy_client_*.c. 41 * 42 * In the serialization these attributes are identified by their configuration 43 * parameter names. 44 * 45 * NOTE: this does not include openssl_path. 46 * 47 * TODO: TLS_SERVER_PARAM structure, like TLS_CLIENT_PARAMS plus 48 * VAR_TLS_SERVER_SNI_MAPS. 49 */ 50 typedef struct TLS_CLIENT_PARAMS { 51 char *tls_cnf_file; 52 char *tls_cnf_name; 53 char *tls_high_clist; 54 char *tls_medium_clist; 55 char *tls_null_clist; 56 char *tls_eecdh_auto; 57 char *tls_eecdh_strong; 58 char *tls_eecdh_ultra; 59 char *tls_ffdhe_auto; 60 char *tls_bug_tweaks; 61 char *tls_ssl_options; 62 char *tls_dane_digests; 63 char *tls_mgr_service; 64 char *tls_tkt_cipher; 65 int tls_daemon_rand_bytes; 66 int tls_append_def_CA; 67 int tls_preempt_clist; 68 int tls_multi_wildcard; 69 } TLS_CLIENT_PARAMS; 70 71 #define TLS_PROXY_PARAMS(params, a1, a2, a3, a4, a5, a6, a7, a8, \ 72 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) \ 73 (((params)->a1), ((params)->a2), ((params)->a3), \ 74 ((params)->a4), ((params)->a5), ((params)->a6), ((params)->a7), \ 75 ((params)->a8), ((params)->a9), ((params)->a10), ((params)->a11), \ 76 ((params)->a12), ((params)->a13), ((params)->a14), ((params)->a15), \ 77 ((params)->a16), ((params)->a17), ((params)->a18)) 78 79 /* 80 * tls_proxy_client_param_misc.c, tls_proxy_client_param_print.c, and 81 * tls_proxy_client_param_scan.c. 82 */ 83 extern TLS_CLIENT_PARAMS *tls_proxy_client_param_from_config(TLS_CLIENT_PARAMS *); 84 extern char *tls_proxy_client_param_serialize(ATTR_PRINT_COMMON_FN, VSTRING *, const TLS_CLIENT_PARAMS *); 85 extern int tls_proxy_client_param_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 86 extern void tls_proxy_client_param_free(TLS_CLIENT_PARAMS *); 87 extern int tls_proxy_client_param_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 88 89 /* 90 * Functions that handle TLS_XXX_INIT_PROPS and TLS_XXX_START_PROPS. These 91 * data structures are defined elsewhere, because they are also used in 92 * non-proxied requests. 93 */ 94 #define tls_proxy_legacy_open(service, flags, peer_stream, peer_addr, \ 95 peer_port, timeout, serverid) \ 96 tls_proxy_open((service), (flags), (peer_stream), (peer_addr), \ 97 (peer_port), (timeout), (timeout), (serverid), \ 98 (void *) 0, (void *) 0, (void *) 0) 99 100 extern VSTREAM *tls_proxy_open(const char *, int, VSTREAM *, const char *, 101 const char *, int, int, const char *, 102 void *, void *, void *); 103 104 #define TLS_PROXY_CLIENT_INIT_PROPS(props, a1, a2, a3, a4, a5, a6, a7, a8, \ 105 a9, a10, a11, a12, a13, a14) \ 106 (((props)->a1), ((props)->a2), ((props)->a3), \ 107 ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \ 108 ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \ 109 ((props)->a12), ((props)->a13), ((props)->a14)) 110 111 #define TLS_PROXY_CLIENT_START_PROPS(props, a1, a2, a3, a4, a5, a6, a7, a8, \ 112 a9, a10, a11, a12, a13, a14, a15, a16, a17) \ 113 (((props)->a1), ((props)->a2), ((props)->a3), \ 114 ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \ 115 ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \ 116 ((props)->a12), ((props)->a13), ((props)->a14), ((props)->a15), \ 117 ((props)->a16), ((props)->a17)) 118 119 extern TLS_SESS_STATE *tls_proxy_context_receive(VSTREAM *); 120 extern void tls_proxy_context_free(TLS_SESS_STATE *); 121 extern int tls_proxy_context_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 122 extern int tls_proxy_context_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 123 124 extern int tls_proxy_client_init_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 125 extern int tls_proxy_client_init_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 126 extern void tls_proxy_client_init_free(TLS_CLIENT_INIT_PROPS *); 127 extern char *tls_proxy_client_init_serialize(ATTR_PRINT_COMMON_FN, VSTRING *, const TLS_CLIENT_INIT_PROPS *); 128 129 extern int tls_proxy_client_start_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 130 extern int tls_proxy_client_start_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 131 extern void tls_proxy_client_start_free(TLS_CLIENT_START_PROPS *); 132 133 extern int tls_proxy_server_init_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 134 extern int tls_proxy_server_init_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 135 extern void tls_proxy_server_init_free(TLS_SERVER_INIT_PROPS *); 136 137 extern int tls_proxy_server_start_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *); 138 extern int tls_proxy_server_start_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *); 139 140 extern void tls_proxy_server_start_free(TLS_SERVER_START_PROPS *); 141 142 #endif /* USE_TLS */ 143 144 /* 145 * TLSPROXY attributes, unconditionally exposed. 146 */ 147 #define TLS_ATTR_REMOTE_ENDPT "remote_endpoint" /* name[addr]:port */ 148 #define TLS_ATTR_FLAGS "flags" 149 #define TLS_ATTR_TIMEOUT "timeout" 150 #define TLS_ATTR_SERVERID "serverid" 151 152 #ifdef USE_TLS 153 154 /* 155 * Misc attributes. 156 */ 157 #define TLS_ATTR_COUNT "count" 158 159 /* 160 * TLS_SESS_STATE attributes. 161 */ 162 #define TLS_ATTR_PEER_CN "peer_CN" 163 #define TLS_ATTR_ISSUER_CN "issuer_CN" 164 #define TLS_ATTR_PEER_CERT_FPT "peer_fingerprint" 165 #define TLS_ATTR_PEER_PKEY_FPT "peer_pubkey_fingerprint" 166 #define TLS_ATTR_SEC_LEVEL "level" 167 #define TLS_ATTR_PEER_STATUS "peer_status" 168 #define TLS_ATTR_CIPHER_PROTOCOL "cipher_protocol" 169 #define TLS_ATTR_CIPHER_NAME "cipher_name" 170 #define TLS_ATTR_CIPHER_USEBITS "cipher_usebits" 171 #define TLS_ATTR_CIPHER_ALGBITS "cipher_algbits" 172 #define TLS_ATTR_KEX_NAME "key_exchange" 173 #define TLS_ATTR_KEX_CURVE "key_exchange_curve" 174 #define TLS_ATTR_KEX_BITS "key_exchange_bits" 175 #define TLS_ATTR_CTOS_RPK "ctos_rpk" 176 #define TLS_ATTR_STOC_RPK "stoc_rpk" 177 #define TLS_ATTR_CLNT_SIG_NAME "clnt_signature" 178 #define TLS_ATTR_CLNT_SIG_CURVE "clnt_signature_curve" 179 #define TLS_ATTR_CLNT_SIG_BITS "clnt_signature_bits" 180 #define TLS_ATTR_CLNT_SIG_DGST "clnt_signature_digest" 181 #define TLS_ATTR_SRVR_SIG_NAME "srvr_signature" 182 #define TLS_ATTR_SRVR_SIG_CURVE "srvr_signature_curve" 183 #define TLS_ATTR_SRVR_SIG_BITS "srvr_signature_bits" 184 #define TLS_ATTR_SRVR_SIG_DGST "srvr_signature_digest" 185 #define TLS_ATTR_NAMADDR "namaddr" 186 #define TLS_ATTR_RPT_REPORTED "rpt_reported" 187 188 /* 189 * TLS_SERVER_INIT_PROPS attributes. 190 */ 191 #define TLS_ATTR_LOG_PARAM "log_param" 192 #define TLS_ATTR_LOG_LEVEL "log_level" 193 #define TLS_ATTR_VERIFYDEPTH "verifydepth" 194 #define TLS_ATTR_CACHE_TYPE "cache_type" 195 #define TLS_ATTR_SET_SESSID "set_sessid" 196 #define TLS_ATTR_CHAIN_FILES "chain_files" 197 #define TLS_ATTR_CERT_FILE "cert_file" 198 #define TLS_ATTR_KEY_FILE "key_file" 199 #define TLS_ATTR_DCERT_FILE "dcert_file" 200 #define TLS_ATTR_DKEY_FILE "dkey_file" 201 #define TLS_ATTR_ECCERT_FILE "eccert_file" 202 #define TLS_ATTR_ECKEY_FILE "eckey_file" 203 #define TLS_ATTR_CAFILE "CAfile" 204 #define TLS_ATTR_CAPATH "CApath" 205 #define TLS_ATTR_PROTOCOLS "protocols" 206 #define TLS_ATTR_EECDH_GRADE "eecdh_grade" 207 #define TLS_ATTR_DH1K_PARAM_FILE "dh1024_param_file" 208 #define TLS_ATTR_DH512_PARAM_FILE "dh512_param_file" 209 #define TLS_ATTR_ASK_CCERT "ask_ccert" 210 #define TLS_ATTR_MDALG "mdalg" 211 212 /* 213 * TLS_SERVER_START_PROPS attributes. 214 */ 215 #define TLS_ATTR_TIMEOUT "timeout" 216 #define TLS_ATTR_REQUIRECERT "requirecert" 217 #define TLS_ATTR_SERVERID "serverid" 218 #define TLS_ATTR_NAMADDR "namaddr" 219 #define TLS_ATTR_CIPHER_GRADE "cipher_grade" 220 #define TLS_ATTR_CIPHER_EXCLUSIONS "cipher_exclusions" 221 #define TLS_ATTR_MDALG "mdalg" 222 223 /* 224 * TLS_CLIENT_INIT_PROPS attributes. 225 */ 226 #define TLS_ATTR_CNF_FILE "config_file" 227 #define TLS_ATTR_CNF_NAME "config_name" 228 #define TLS_ATTR_LOG_PARAM "log_param" 229 #define TLS_ATTR_LOG_LEVEL "log_level" 230 #define TLS_ATTR_VERIFYDEPTH "verifydepth" 231 #define TLS_ATTR_CACHE_TYPE "cache_type" 232 #define TLS_ATTR_CHAIN_FILES "chain_files" 233 #define TLS_ATTR_CERT_FILE "cert_file" 234 #define TLS_ATTR_KEY_FILE "key_file" 235 #define TLS_ATTR_DCERT_FILE "dcert_file" 236 #define TLS_ATTR_DKEY_FILE "dkey_file" 237 #define TLS_ATTR_ECCERT_FILE "eccert_file" 238 #define TLS_ATTR_ECKEY_FILE "eckey_file" 239 #define TLS_ATTR_CAFILE "CAfile" 240 #define TLS_ATTR_CAPATH "CApath" 241 #define TLS_ATTR_MDALG "mdalg" 242 243 /* 244 * TLS_CLIENT_START_PROPS attributes. 245 */ 246 #define TLS_ATTR_TIMEOUT "timeout" 247 #define TLS_ATTR_ENABLE_RPK "enable_rpk" 248 #define TLS_ATTR_TLS_LEVEL "tls_level" 249 #define TLS_ATTR_NEXTHOP "nexthop" 250 #define TLS_ATTR_HOST "host" 251 #define TLS_ATTR_NAMADDR "namaddr" 252 #define TLS_ATTR_SNI "sni" 253 #define TLS_ATTR_SERVERID "serverid" 254 #define TLS_ATTR_HELO "helo" 255 #define TLS_ATTR_PROTOCOLS "protocols" 256 #define TLS_ATTR_CIPHER_GRADE "cipher_grade" 257 #define TLS_ATTR_CIPHER_EXCLUSIONS "cipher_exclusions" 258 #define TLS_ATTR_MATCHARGV "matchargv" 259 #define TLS_ATTR_MDALG "mdalg" 260 #define TLS_ATTR_DANE "dane" 261 #define TLS_ATTR_TLSRPT "tlsrpt" 262 #define TLS_ATTR_FFAIL_TYPE "forced_failure_type" 263 264 /* 265 * TLS_TLSA attributes. 266 */ 267 #define TLS_ATTR_USAGE "usage" 268 #define TLS_ATTR_SELECTOR "selector" 269 #define TLS_ATTR_MTYPE "mtype" 270 #define TLS_ATTR_DATA "data" 271 272 /* 273 * TLS_DANE attributes. 274 */ 275 #define TLS_ATTR_DOMAIN "domain" 276 277 #endif 278 279 /* LICENSE 280 /* .ad 281 /* .fi 282 /* The Secure Mailer license must be distributed with this software. 283 /* AUTHOR(S) 284 /* Wietse Venema 285 /* IBM T.J. Watson Research 286 /* P.O. Box 704 287 /* Yorktown Heights, NY 10598, USA 288 /* 289 /* Wietse Venema 290 /* Google, Inc. 291 /* 111 8th Avenue 292 /* New York, NY 10011, USA 293 /*--*/ 294 295 #endif 296