1 /* $NetBSD: tls_proxy_client_misc.c,v 1.3 2022/10/08 16:12:50 christos Exp $ */
2
3 /*++
4 /* NAME
5 /* tls_proxy_client_misc 3
6 /* SUMMARY
7 /* TLS_CLIENT_XXX structure support
8 /* SYNOPSIS
9 /* #include <tls_proxy.h>
10 /*
11 /* TLS_CLIENT_PARAMS *tls_proxy_client_param_from_config(params)
12 /* TLS_CLIENT_PARAMS *params;
13 /*
14 /* char *tls_proxy_client_param_serialize(print_fn, buf, params)
15 /* ATTR_PRINT_COMMON_FN print_fn;
16 /* VSTRING *buf;
17 /* const TLS_CLIENT_PARAMS *params;
18 /*
19 /* char *tls_proxy_client_init_serialize(print_fn, buf, init_props)
20 /* ATTR_PRINT_COMMON_FN print_fn;
21 /* VSTRING *buf;
22 /* const TLS_CLIENT_INIT_PROPS *init_props;
23 /* DESCRIPTION
24 /* tls_proxy_client_param_from_config() initializes a TLS_CLIENT_PARAMS
25 /* structure from configuration parameters and returns its
26 /* argument. Strings are not copied. The result must therefore
27 /* not be passed to tls_proxy_client_param_free().
28 /*
29 /* tls_proxy_client_param_serialize() and
30 /* tls_proxy_client_init_serialize() serialize the specified
31 /* object to a memory buffer, using the specified print function
32 /* (typically, attr_print_plain). The result can be used
33 /* determine whether there are any differences between instances
34 /* of the same object type.
35 /* LICENSE
36 /* .ad
37 /* .fi
38 /* The Secure Mailer license must be distributed with this software.
39 /* AUTHOR(S)
40 /* Wietse Venema
41 /* Google, Inc.
42 /* 111 8th Avenue
43 /* New York, NY 10011, USA
44 /*--*/
45
46 #ifdef USE_TLS
47
48 /* System library. */
49
50 #include <sys_defs.h>
51
52 /* Utility library */
53
54 #include <attr.h>
55 #include <msg.h>
56
57 /* Global library. */
58
59 #include <mail_params.h>
60
61 /* TLS library. */
62
63 #include <tls.h>
64 #include <tls_proxy.h>
65
66 /* tls_proxy_client_param_from_config - initialize TLS_CLIENT_PARAMS from configuration */
67
tls_proxy_client_param_from_config(TLS_CLIENT_PARAMS * params)68 TLS_CLIENT_PARAMS *tls_proxy_client_param_from_config(TLS_CLIENT_PARAMS *params)
69 {
70 TLS_PROXY_PARAMS(params,
71 tls_high_clist = var_tls_high_clist,
72 tls_medium_clist = var_tls_medium_clist,
73 tls_low_clist = var_tls_low_clist,
74 tls_export_clist = var_tls_export_clist,
75 tls_null_clist = var_tls_null_clist,
76 tls_eecdh_auto = var_tls_eecdh_auto,
77 tls_eecdh_strong = var_tls_eecdh_strong,
78 tls_eecdh_ultra = var_tls_eecdh_ultra,
79 tls_bug_tweaks = var_tls_bug_tweaks,
80 tls_ssl_options = var_tls_ssl_options,
81 tls_dane_digests = var_tls_dane_digests,
82 tls_mgr_service = var_tls_mgr_service,
83 tls_tkt_cipher = var_tls_tkt_cipher,
84 tls_daemon_rand_bytes = var_tls_daemon_rand_bytes,
85 tls_append_def_CA = var_tls_append_def_CA,
86 tls_bc_pkey_fprint = var_tls_bc_pkey_fprint,
87 tls_preempt_clist = var_tls_preempt_clist,
88 tls_multi_wildcard = var_tls_multi_wildcard);
89 return (params);
90 }
91
92 /* tls_proxy_client_param_serialize - serialize TLS_CLIENT_PARAMS to string */
93
tls_proxy_client_param_serialize(ATTR_PRINT_COMMON_FN print_fn,VSTRING * buf,const TLS_CLIENT_PARAMS * params)94 char *tls_proxy_client_param_serialize(ATTR_PRINT_COMMON_FN print_fn,
95 VSTRING *buf,
96 const TLS_CLIENT_PARAMS *params)
97 {
98 const char myname[] = "tls_proxy_client_param_serialize";
99 VSTREAM *mp;
100
101 if ((mp = vstream_memopen(buf, O_WRONLY)) == 0
102 || print_fn(mp, ATTR_FLAG_NONE,
103 SEND_ATTR_FUNC(tls_proxy_client_param_print,
104 (const void *) params),
105 ATTR_TYPE_END) != 0
106 || vstream_fclose(mp) != 0)
107 msg_fatal("%s: can't serialize properties: %m", myname);
108 return (vstring_str(buf));
109 }
110
111 /* tls_proxy_client_init_serialize - serialize to string */
112
tls_proxy_client_init_serialize(ATTR_PRINT_COMMON_FN print_fn,VSTRING * buf,const TLS_CLIENT_INIT_PROPS * props)113 char *tls_proxy_client_init_serialize(ATTR_PRINT_COMMON_FN print_fn,
114 VSTRING *buf,
115 const TLS_CLIENT_INIT_PROPS *props)
116 {
117 const char myname[] = "tls_proxy_client_init_serialize";
118 VSTREAM *mp;
119
120 if ((mp = vstream_memopen(buf, O_WRONLY)) == 0
121 || print_fn(mp, ATTR_FLAG_NONE,
122 SEND_ATTR_FUNC(tls_proxy_client_init_print,
123 (const void *) props),
124 ATTR_TYPE_END) != 0
125 || vstream_fclose(mp) != 0)
126 msg_fatal("%s: can't serialize properties: %m", myname);
127 return (vstring_str(buf));
128 }
129
130 #endif
131