xref: /netbsd-src/external/ibm-public/postfix/dist/src/tls/tls_proxy.h (revision a8c74629f602faa0ccf8a463757d7baf858bbf3a)
1 /*	$NetBSD: tls_proxy.h,v 1.2 2020/03/18 19:05: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. 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_high_clist;
50     char   *tls_medium_clist;
51     char   *tls_low_clist;
52     char   *tls_export_clist;
53     char   *tls_null_clist;
54     char   *tls_eecdh_auto;
55     char   *tls_eecdh_strong;
56     char   *tls_eecdh_ultra;
57     char   *tls_bug_tweaks;
58     char   *tls_ssl_options;
59     char   *tls_dane_digests;
60     char   *tls_mgr_service;
61     char   *tls_tkt_cipher;
62     int     tls_daemon_rand_bytes;
63     int     tls_append_def_CA;
64     int     tls_bc_pkey_fprint;
65     int     tls_preempt_clist;
66     int     tls_multi_wildcard;
67 } TLS_CLIENT_PARAMS;
68 
69 #define TLS_PROXY_PARAMS(params, a1, a2, a3, a4, a5, a6, a7, a8, \
70     a9, a10, a11, a12, a13, a14, a15, a16, a17, a18) \
71     (((params)->a1), ((params)->a2), ((params)->a3), \
72     ((params)->a4), ((params)->a5), ((params)->a6), ((params)->a7), \
73     ((params)->a8), ((params)->a9), ((params)->a10), ((params)->a11), \
74     ((params)->a12), ((params)->a13), ((params)->a14), ((params)->a15), \
75     ((params)->a16), ((params)->a17), ((params)->a18))
76 
77  /*
78   * tls_proxy_client_param_misc.c, tls_proxy_client_param_print.c, and
79   * tls_proxy_client_param_scan.c.
80   */
81 extern TLS_CLIENT_PARAMS *tls_proxy_client_param_from_config(TLS_CLIENT_PARAMS *);
82 extern char *tls_proxy_client_param_to_string(VSTRING *, TLS_CLIENT_PARAMS *);
83 extern char *tls_proxy_client_param_with_names_to_string(VSTRING *, TLS_CLIENT_PARAMS *);
84 extern int tls_proxy_client_param_print(ATTR_PRINT_MASTER_FN, VSTREAM *, int, void *);
85 extern void tls_proxy_client_param_free(TLS_CLIENT_PARAMS *);
86 extern int tls_proxy_client_param_scan(ATTR_SCAN_MASTER_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_MASTER_FN, VSTREAM *, int, void *);
120 extern int tls_proxy_context_scan(ATTR_SCAN_MASTER_FN, VSTREAM *, int, void *);
121 
122 extern int tls_proxy_client_init_print(ATTR_PRINT_MASTER_FN, VSTREAM *, int, void *);
123 extern int tls_proxy_client_init_scan(ATTR_SCAN_MASTER_FN, VSTREAM *, int, void *);
124 extern void tls_proxy_client_init_free(TLS_CLIENT_INIT_PROPS *);
125 extern char *tls_proxy_client_init_to_string(VSTRING *, TLS_CLIENT_INIT_PROPS *);
126 extern char *tls_proxy_client_init_with_names_to_string(VSTRING *, TLS_CLIENT_INIT_PROPS *);
127 
128 extern int tls_proxy_client_start_print(ATTR_PRINT_MASTER_FN, VSTREAM *, int, void *);
129 extern int tls_proxy_client_start_scan(ATTR_SCAN_MASTER_FN, VSTREAM *, int, void *);
130 extern void tls_proxy_client_start_free(TLS_CLIENT_START_PROPS *);
131 
132 extern int tls_proxy_server_init_print(ATTR_PRINT_MASTER_FN, VSTREAM *, int, void *);
133 extern int tls_proxy_server_init_scan(ATTR_SCAN_MASTER_FN, VSTREAM *, int, void *);
134 extern void tls_proxy_server_init_free(TLS_SERVER_INIT_PROPS *);
135 
136 extern int tls_proxy_server_start_print(ATTR_PRINT_MASTER_FN, VSTREAM *, int, void *);
137 extern int tls_proxy_server_start_scan(ATTR_SCAN_MASTER_FN, VSTREAM *, int, void *);
138 
139 extern void tls_proxy_server_start_free(TLS_SERVER_START_PROPS *);
140 
141 #endif					/* USE_TLS */
142 
143  /*
144   * TLSPROXY attributes, unconditionally exposed.
145   */
146 #define TLS_ATTR_REMOTE_ENDPT	"remote_endpoint"	/* name[addr]:port */
147 #define TLS_ATTR_FLAGS		"flags"
148 #define TLS_ATTR_TIMEOUT	"timeout"
149 #define TLS_ATTR_SERVERID	"serverid"
150 
151 #ifdef USE_TLS
152 
153  /*
154   * Misc attributes.
155   */
156 #define TLS_ATTR_COUNT		"count"
157 
158  /*
159   * TLS_SESS_STATE attributes.
160   */
161 #define TLS_ATTR_PEER_CN	"peer_CN"
162 #define TLS_ATTR_ISSUER_CN	"issuer_CN"
163 #define TLS_ATTR_PEER_CERT_FPT	"peer_fingerprint"
164 #define TLS_ATTR_PEER_PKEY_FPT	"peer_pubkey_fingerprint"
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_LOG_PARAM	"log_param"
222 #define TLS_ATTR_LOG_LEVEL	"log_level"
223 #define TLS_ATTR_VERIFYDEPTH	"verifydepth"
224 #define TLS_ATTR_CACHE_TYPE	"cache_type"
225 #define TLS_ATTR_CHAIN_FILES	"chain_files"
226 #define TLS_ATTR_CERT_FILE	"cert_file"
227 #define TLS_ATTR_KEY_FILE	"key_file"
228 #define TLS_ATTR_DCERT_FILE	"dcert_file"
229 #define TLS_ATTR_DKEY_FILE	"dkey_file"
230 #define TLS_ATTR_ECCERT_FILE	"eccert_file"
231 #define TLS_ATTR_ECKEY_FILE	"eckey_file"
232 #define TLS_ATTR_CAFILE		"CAfile"
233 #define TLS_ATTR_CAPATH		"CApath"
234 #define TLS_ATTR_MDALG		"mdalg"
235 
236  /*
237   * TLS_CLIENT_START_PROPS attributes.
238   */
239 #define TLS_ATTR_TIMEOUT	"timeout"
240 #define TLS_ATTR_TLS_LEVEL	"tls_level"
241 #define TLS_ATTR_NEXTHOP	"nexthop"
242 #define TLS_ATTR_HOST		"host"
243 #define TLS_ATTR_NAMADDR	"namaddr"
244 #define TLS_ATTR_SNI		"sni"
245 #define TLS_ATTR_SERVERID	"serverid"
246 #define TLS_ATTR_HELO		"helo"
247 #define TLS_ATTR_PROTOCOLS	"protocols"
248 #define TLS_ATTR_CIPHER_GRADE	"cipher_grade"
249 #define TLS_ATTR_CIPHER_EXCLUSIONS "cipher_exclusions"
250 #define TLS_ATTR_MATCHARGV	"matchargv"
251 #define TLS_ATTR_MDALG		"mdalg"
252 #define	TLS_ATTR_DANE		"dane"
253 
254  /*
255   * TLS_TLSA attributes.
256   */
257 #define TLS_ATTR_MDALG		"mdalg"
258 #define TLS_ATTR_CERTS		"certs"
259 #define TLS_ATTR_PKEYS		"pkeys"
260 
261  /*
262   * TLS_CERTS attributes.
263   */
264 #define TLS_ATTR_CERT		"cert"
265 
266  /*
267   * TLS_PKEYS attributes.
268   */
269 #define TLS_ATTR_PKEY		"pkey"
270 
271  /*
272   * TLS_DANE attributes.
273   */
274 #define TLS_ATTR_TA		"ta"
275 #define TLS_ATTR_EE		"ee"
276 #define TLS_ATTR_CERTS		"certs"
277 #define TLS_ATTR_PKEYS		"pkeys"
278 #define TLS_ATTR_DOMAIN		"domain"
279 #define TLS_ATTR_FLAGS		"flags"
280 #define TLS_ATTR_EXP		"exp"
281 
282 #endif
283 
284 /* LICENSE
285 /* .ad
286 /* .fi
287 /*	The Secure Mailer license must be distributed with this software.
288 /* AUTHOR(S)
289 /*	Wietse Venema
290 /*	IBM T.J. Watson Research
291 /*	P.O. Box 704
292 /*	Yorktown Heights, NY 10598, USA
293 /*
294 /*	Wietse Venema
295 /*	Google, Inc.
296 /*	111 8th Avenue
297 /*	New York, NY 10011, USA
298 /*--*/
299 
300 #endif
301