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