1 /*        $NetBSD: tls_proxy_client_misc.c,v 1.4 2023/12/23 20:30:45 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_cnf_file = var_tls_cnf_file,
72                          tls_cnf_name = var_tls_cnf_name,
73                          tls_high_clist = var_tls_high_clist,
74                          tls_medium_clist = var_tls_medium_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_ffdhe_auto = var_tls_ffdhe_auto,
80                          tls_bug_tweaks = var_tls_bug_tweaks,
81                          tls_ssl_options = var_tls_ssl_options,
82                          tls_dane_digests = var_tls_dane_digests,
83                          tls_mgr_service = var_tls_mgr_service,
84                          tls_tkt_cipher = var_tls_tkt_cipher,
85                          tls_daemon_rand_bytes = var_tls_daemon_rand_bytes,
86                          tls_append_def_CA = var_tls_append_def_CA,
87                          tls_bc_pkey_fprint = var_tls_bc_pkey_fprint,
88                          tls_preempt_clist = var_tls_preempt_clist,
89                          tls_multi_wildcard = var_tls_multi_wildcard);
90     return (params);
91 }
92 
93 /* tls_proxy_client_param_serialize - serialize TLS_CLIENT_PARAMS to string */
94 
tls_proxy_client_param_serialize(ATTR_PRINT_COMMON_FN print_fn,VSTRING * buf,const TLS_CLIENT_PARAMS * params)95 char   *tls_proxy_client_param_serialize(ATTR_PRINT_COMMON_FN print_fn,
96                                                            VSTRING *buf,
97                                                     const TLS_CLIENT_PARAMS *params)
98 {
99     const char myname[] = "tls_proxy_client_param_serialize";
100     VSTREAM *mp;
101 
102     if ((mp = vstream_memopen(buf, O_WRONLY)) == 0
103           || print_fn(mp, ATTR_FLAG_NONE,
104                         SEND_ATTR_FUNC(tls_proxy_client_param_print,
105                                            (const void *) params),
106                         ATTR_TYPE_END) != 0
107           || vstream_fclose(mp) != 0)
108           msg_fatal("%s: can't serialize properties: %m", myname);
109     return (vstring_str(buf));
110 }
111 
112 /* tls_proxy_client_init_serialize - serialize to string */
113 
tls_proxy_client_init_serialize(ATTR_PRINT_COMMON_FN print_fn,VSTRING * buf,const TLS_CLIENT_INIT_PROPS * props)114 char   *tls_proxy_client_init_serialize(ATTR_PRINT_COMMON_FN print_fn,
115                                                           VSTRING *buf,
116                                                  const TLS_CLIENT_INIT_PROPS *props)
117 {
118     const char myname[] = "tls_proxy_client_init_serialize";
119     VSTREAM *mp;
120 
121     if ((mp = vstream_memopen(buf, O_WRONLY)) == 0
122           || print_fn(mp, ATTR_FLAG_NONE,
123                         SEND_ATTR_FUNC(tls_proxy_client_init_print,
124                                            (const void *) props),
125                         ATTR_TYPE_END) != 0
126           || vstream_fclose(mp) != 0)
127           msg_fatal("%s: can't serialize properties: %m", myname);
128     return (vstring_str(buf));
129 }
130 
131 #endif
132