1 /*	$NetBSD: tls_proxy.h,v 1.3 2022/10/08 16:12:50 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_serialize(ATTR_PRINT_COMMON_FN, VSTRING *, const TLS_CLIENT_PARAMS *);
83 extern int tls_proxy_client_param_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *);
84 extern void tls_proxy_client_param_free(TLS_CLIENT_PARAMS *);
85 extern int tls_proxy_client_param_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *);
86 
87  /*
88   * Functions that handle TLS_XXX_INIT_PROPS and TLS_XXX_START_PROPS. These
89   * data structures are defined elsewhere, because they are also used in
90   * non-proxied requests.
91   */
92 #define tls_proxy_legacy_open(service, flags, peer_stream, peer_addr, \
93                                           peer_port, timeout, serverid) \
94     tls_proxy_open((service), (flags), (peer_stream), (peer_addr), \
95 	(peer_port), (timeout), (timeout), (serverid), \
96 	(void *) 0, (void *) 0, (void *) 0)
97 
98 extern VSTREAM *tls_proxy_open(const char *, int, VSTREAM *, const char *,
99 			               const char *, int, int, const char *,
100 			               void *, void *, void *);
101 
102 #define TLS_PROXY_CLIENT_INIT_PROPS(props, a1, a2, a3, a4, a5, a6, a7, a8, \
103     a9, a10, a11, a12, a13, a14) \
104     (((props)->a1), ((props)->a2), ((props)->a3), \
105     ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
106     ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
107     ((props)->a12), ((props)->a13), ((props)->a14))
108 
109 #define TLS_PROXY_CLIENT_START_PROPS(props, a1, a2, a3, a4, a5, a6, a7, a8, \
110     a9, a10, a11, a12, a13, a14) \
111     (((props)->a1), ((props)->a2), ((props)->a3), \
112     ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
113     ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
114     ((props)->a12), ((props)->a13), ((props)->a14))
115 
116 extern TLS_SESS_STATE *tls_proxy_context_receive(VSTREAM *);
117 extern void tls_proxy_context_free(TLS_SESS_STATE *);
118 extern int tls_proxy_context_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *);
119 extern int tls_proxy_context_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *);
120 
121 extern int tls_proxy_client_init_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *);
122 extern int tls_proxy_client_init_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *);
123 extern void tls_proxy_client_init_free(TLS_CLIENT_INIT_PROPS *);
124 extern char *tls_proxy_client_init_serialize(ATTR_PRINT_COMMON_FN, VSTRING *, const TLS_CLIENT_INIT_PROPS *);
125 
126 extern int tls_proxy_client_start_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *);
127 extern int tls_proxy_client_start_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *);
128 extern void tls_proxy_client_start_free(TLS_CLIENT_START_PROPS *);
129 
130 extern int tls_proxy_server_init_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *);
131 extern int tls_proxy_server_init_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *);
132 extern void tls_proxy_server_init_free(TLS_SERVER_INIT_PROPS *);
133 
134 extern int tls_proxy_server_start_print(ATTR_PRINT_COMMON_FN, VSTREAM *, int, const void *);
135 extern int tls_proxy_server_start_scan(ATTR_SCAN_COMMON_FN, VSTREAM *, int, void *);
136 
137 extern void tls_proxy_server_start_free(TLS_SERVER_START_PROPS *);
138 
139 #endif					/* USE_TLS */
140 
141  /*
142   * TLSPROXY attributes, unconditionally exposed.
143   */
144 #define TLS_ATTR_REMOTE_ENDPT	"remote_endpoint"	/* name[addr]:port */
145 #define TLS_ATTR_FLAGS		"flags"
146 #define TLS_ATTR_TIMEOUT	"timeout"
147 #define TLS_ATTR_SERVERID	"serverid"
148 
149 #ifdef USE_TLS
150 
151  /*
152   * Misc attributes.
153   */
154 #define TLS_ATTR_COUNT		"count"
155 
156  /*
157   * TLS_SESS_STATE attributes.
158   */
159 #define TLS_ATTR_PEER_CN	"peer_CN"
160 #define TLS_ATTR_ISSUER_CN	"issuer_CN"
161 #define TLS_ATTR_PEER_CERT_FPT	"peer_fingerprint"
162 #define TLS_ATTR_PEER_PKEY_FPT	"peer_pubkey_fingerprint"
163 #define TLS_ATTR_SEC_LEVEL      "level"
164 #define TLS_ATTR_PEER_STATUS	"peer_status"
165 #define TLS_ATTR_CIPHER_PROTOCOL "cipher_protocol"
166 #define TLS_ATTR_CIPHER_NAME	"cipher_name"
167 #define TLS_ATTR_CIPHER_USEBITS	"cipher_usebits"
168 #define TLS_ATTR_CIPHER_ALGBITS	"cipher_algbits"
169 #define TLS_ATTR_KEX_NAME	"key_exchange"
170 #define TLS_ATTR_KEX_CURVE	"key_exchange_curve"
171 #define TLS_ATTR_KEX_BITS	"key_exchange_bits"
172 #define TLS_ATTR_CLNT_SIG_NAME	"clnt_signature"
173 #define TLS_ATTR_CLNT_SIG_CURVE	"clnt_signature_curve"
174 #define TLS_ATTR_CLNT_SIG_BITS	"clnt_signature_bits"
175 #define TLS_ATTR_CLNT_SIG_DGST	"clnt_signature_digest"
176 #define TLS_ATTR_SRVR_SIG_NAME	"srvr_signature"
177 #define TLS_ATTR_SRVR_SIG_CURVE	"srvr_signature_curve"
178 #define TLS_ATTR_SRVR_SIG_BITS	"srvr_signature_bits"
179 #define TLS_ATTR_SRVR_SIG_DGST	"srvr_signature_digest"
180 #define TLS_ATTR_NAMADDR	"namaddr"
181 
182  /*
183   * TLS_SERVER_INIT_PROPS attributes.
184   */
185 #define TLS_ATTR_LOG_PARAM	"log_param"
186 #define TLS_ATTR_LOG_LEVEL	"log_level"
187 #define TLS_ATTR_VERIFYDEPTH	"verifydepth"
188 #define TLS_ATTR_CACHE_TYPE	"cache_type"
189 #define TLS_ATTR_SET_SESSID	"set_sessid"
190 #define TLS_ATTR_CHAIN_FILES	"chain_files"
191 #define TLS_ATTR_CERT_FILE	"cert_file"
192 #define TLS_ATTR_KEY_FILE	"key_file"
193 #define TLS_ATTR_DCERT_FILE	"dcert_file"
194 #define TLS_ATTR_DKEY_FILE	"dkey_file"
195 #define TLS_ATTR_ECCERT_FILE	"eccert_file"
196 #define TLS_ATTR_ECKEY_FILE	"eckey_file"
197 #define TLS_ATTR_CAFILE		"CAfile"
198 #define TLS_ATTR_CAPATH		"CApath"
199 #define TLS_ATTR_PROTOCOLS	"protocols"
200 #define TLS_ATTR_EECDH_GRADE	"eecdh_grade"
201 #define TLS_ATTR_DH1K_PARAM_FILE "dh1024_param_file"
202 #define TLS_ATTR_DH512_PARAM_FILE "dh512_param_file"
203 #define TLS_ATTR_ASK_CCERT	"ask_ccert"
204 #define TLS_ATTR_MDALG		"mdalg"
205 
206  /*
207   * TLS_SERVER_START_PROPS attributes.
208   */
209 #define TLS_ATTR_TIMEOUT	"timeout"
210 #define TLS_ATTR_REQUIRECERT	"requirecert"
211 #define TLS_ATTR_SERVERID	"serverid"
212 #define TLS_ATTR_NAMADDR	"namaddr"
213 #define TLS_ATTR_CIPHER_GRADE	"cipher_grade"
214 #define TLS_ATTR_CIPHER_EXCLUSIONS "cipher_exclusions"
215 #define TLS_ATTR_MDALG		"mdalg"
216 
217  /*
218   * TLS_CLIENT_INIT_PROPS attributes.
219   */
220 #define TLS_ATTR_LOG_PARAM	"log_param"
221 #define TLS_ATTR_LOG_LEVEL	"log_level"
222 #define TLS_ATTR_VERIFYDEPTH	"verifydepth"
223 #define TLS_ATTR_CACHE_TYPE	"cache_type"
224 #define TLS_ATTR_CHAIN_FILES	"chain_files"
225 #define TLS_ATTR_CERT_FILE	"cert_file"
226 #define TLS_ATTR_KEY_FILE	"key_file"
227 #define TLS_ATTR_DCERT_FILE	"dcert_file"
228 #define TLS_ATTR_DKEY_FILE	"dkey_file"
229 #define TLS_ATTR_ECCERT_FILE	"eccert_file"
230 #define TLS_ATTR_ECKEY_FILE	"eckey_file"
231 #define TLS_ATTR_CAFILE		"CAfile"
232 #define TLS_ATTR_CAPATH		"CApath"
233 #define TLS_ATTR_MDALG		"mdalg"
234 
235  /*
236   * TLS_CLIENT_START_PROPS attributes.
237   */
238 #define TLS_ATTR_TIMEOUT	"timeout"
239 #define TLS_ATTR_TLS_LEVEL	"tls_level"
240 #define TLS_ATTR_NEXTHOP	"nexthop"
241 #define TLS_ATTR_HOST		"host"
242 #define TLS_ATTR_NAMADDR	"namaddr"
243 #define TLS_ATTR_SNI		"sni"
244 #define TLS_ATTR_SERVERID	"serverid"
245 #define TLS_ATTR_HELO		"helo"
246 #define TLS_ATTR_PROTOCOLS	"protocols"
247 #define TLS_ATTR_CIPHER_GRADE	"cipher_grade"
248 #define TLS_ATTR_CIPHER_EXCLUSIONS "cipher_exclusions"
249 #define TLS_ATTR_MATCHARGV	"matchargv"
250 #define TLS_ATTR_MDALG		"mdalg"
251 #define	TLS_ATTR_DANE		"dane"
252 
253  /*
254   * TLS_TLSA attributes.
255   */
256 #define TLS_ATTR_USAGE		"usage"
257 #define TLS_ATTR_SELECTOR	"selector"
258 #define TLS_ATTR_MTYPE		"mtype"
259 #define TLS_ATTR_DATA		"data"
260 
261  /*
262   * TLS_DANE attributes.
263   */
264 #define TLS_ATTR_DOMAIN		"domain"
265 
266 #endif
267 
268 /* LICENSE
269 /* .ad
270 /* .fi
271 /*	The Secure Mailer license must be distributed with this software.
272 /* AUTHOR(S)
273 /*	Wietse Venema
274 /*	IBM T.J. Watson Research
275 /*	P.O. Box 704
276 /*	Yorktown Heights, NY 10598, USA
277 /*
278 /*	Wietse Venema
279 /*	Google, Inc.
280 /*	111 8th Avenue
281 /*	New York, NY 10011, USA
282 /*--*/
283 
284 #endif
285