summaryrefslogtreecommitdiffstats
path: root/src/tls/tls_proxy_client_misc.c
blob: 6c4158563a63896e13c736f5cf95ecd4a42f1263 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*++
/* NAME
/*	tls_proxy_client_misc 3
/* SUMMARY
/*	TLS_CLIENT_XXX structure support
/* SYNOPSIS
/*	#include <tls_proxy.h>
/*
/*	TLS_CLIENT_PARAMS *tls_proxy_client_param_from_config(params)
/*	TLS_CLIENT_PARAMS *params;
/*
/*	char	*tls_proxy_client_param_to_string(buf, params)
/*	VSTRING *buf;
/*	TLS_CLIENT_PARAMS *params;
/*
/*	char	*tls_proxy_client_param_with_names_to_string(buf, params)
/*	VSTRING *buf;
/*	TLS_CLIENT_PARAMS *params;
/*
/*	char	*tls_proxy_client_init_to_string(buf, init_props)
/*	VSTRING *buf;
/*	TLS_CLIENT_INIT_PROPS *init_props;
/* DESCRIPTION
/*	tls_proxy_client_param_from_config() initializes a TLS_CLIENT_PARAMS
/*	structure from configuration parameters and returns its
/*	argument. Strings are not copied. The result must therefore
/*	not be passed to tls_proxy_client_param_free().
/*
/*	tls_proxy_client_param_to_string() produces a lookup key
/*	that is unique for the TLS_CLIENT_PARAMS member values.
/*
/*	tls_proxy_client_param_with_names_to_string() produces a
/*	string with "name = value\n" for each TLS_CLIENT_PARAMS
/*	member. This may be useful for reporting differences between
/*	TLS_CLIENT_PARAMS instances.
/*
/*	tls_proxy_client_init_to_string() produces a lookup key
/*	that is unique for the properties received by
/*	tls_proxy_client_init_scan().
/*
/*	tls_proxy_client_init_with_names_to_string() produces a
/*	string with "name = value\n" for each TLS_CLIENT_INIT_PROPS
/*	member. This may be useful for reporting differences between
/*	TLS_CLIENT_INIT_PROPS instances.
/* LICENSE
/* .ad
/* .fi
/*	The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/*	Wietse Venema
/*	Google, Inc.
/*	111 8th Avenue
/*	New York, NY 10011, USA
/*--*/

#ifdef USE_TLS

/* System library. */

#include <sys_defs.h>

/* Utility library */

#include <attr.h>
#include <msg.h>

/* Global library. */

#include <mail_params.h>

/* TLS library. */

#include <tls.h>
#include <tls_proxy.h>

/* tls_proxy_client_param_from_config - initialize TLS_CLIENT_PARAMS from configuration */

TLS_CLIENT_PARAMS *tls_proxy_client_param_from_config(TLS_CLIENT_PARAMS *params)
{
    TLS_PROXY_PARAMS(params,
		     tls_high_clist = var_tls_high_clist,
		     tls_medium_clist = var_tls_medium_clist,
		     tls_low_clist = var_tls_low_clist,
		     tls_export_clist = var_tls_export_clist,
		     tls_null_clist = var_tls_null_clist,
		     tls_eecdh_auto = var_tls_eecdh_auto,
		     tls_eecdh_strong = var_tls_eecdh_strong,
		     tls_eecdh_ultra = var_tls_eecdh_ultra,
		     tls_bug_tweaks = var_tls_bug_tweaks,
		     tls_ssl_options = var_tls_ssl_options,
		     tls_dane_digests = var_tls_dane_digests,
		     tls_mgr_service = var_tls_mgr_service,
		     tls_tkt_cipher = var_tls_tkt_cipher,
		     tls_daemon_rand_bytes = var_tls_daemon_rand_bytes,
		     tls_append_def_CA = var_tls_append_def_CA,
		     tls_bc_pkey_fprint = var_tls_bc_pkey_fprint,
		     tls_preempt_clist = var_tls_preempt_clist,
		     tls_multi_wildcard = var_tls_multi_wildcard);
    return (params);
}

/* tls_proxy_client_param_to_string - serialize TLS_CLIENT_PARAMS to string */

char   *tls_proxy_client_param_to_string(VSTRING *buf, TLS_CLIENT_PARAMS *params)
{
    vstring_sprintf(buf, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n"
		    "%s\n%s\n%d\n%d\n%d\n%d\n%d\n",
		    params->tls_high_clist, params->tls_medium_clist,
		    params->tls_low_clist, params->tls_export_clist,
		    params->tls_null_clist, params->tls_eecdh_auto,
		    params->tls_eecdh_strong, params->tls_eecdh_ultra,
		    params->tls_bug_tweaks, params->tls_ssl_options,
		    params->tls_dane_digests, params->tls_mgr_service,
		    params->tls_tkt_cipher, params->tls_daemon_rand_bytes,
		    params->tls_append_def_CA, params->tls_bc_pkey_fprint,
		    params->tls_preempt_clist, params->tls_multi_wildcard);
    return (vstring_str(buf));
}

/* tls_proxy_client_param_with_names_to_string - serialize TLS_CLIENT_PARAMS to string */

char   *tls_proxy_client_param_with_names_to_string(VSTRING *buf, TLS_CLIENT_PARAMS *params)
{
    vstring_sprintf(buf, "%s = %s\n%s = %s\n%s = %s\n%s = %s\n%s = %s\n"
		    "%s = %s\n%s = %s\n%s = %s\n%s = %s\n%s = %s\n%s = %s\n"
		    "%s = %s\n%s = %s\n%s = %d\n"
		    "%s = %d\n%s = %d\n%s = %d\n%s = %d\n",
		    VAR_TLS_HIGH_CLIST, params->tls_high_clist,
		    VAR_TLS_MEDIUM_CLIST, params->tls_medium_clist,
		    VAR_TLS_LOW_CLIST, params->tls_low_clist,
		    VAR_TLS_EXPORT_CLIST, params->tls_export_clist,
		    VAR_TLS_NULL_CLIST, params->tls_null_clist,
		    VAR_TLS_EECDH_AUTO, params->tls_eecdh_auto,
		    VAR_TLS_EECDH_STRONG, params->tls_eecdh_strong,
		    VAR_TLS_EECDH_ULTRA, params->tls_eecdh_ultra,
		    VAR_TLS_BUG_TWEAKS, params->tls_bug_tweaks,
		    VAR_TLS_SSL_OPTIONS, params->tls_ssl_options,
		    VAR_TLS_DANE_DIGESTS, params->tls_dane_digests,
		    VAR_TLS_MGR_SERVICE, params->tls_mgr_service,
		    VAR_TLS_TKT_CIPHER, params->tls_tkt_cipher,
		    VAR_TLS_DAEMON_RAND_BYTES, params->tls_daemon_rand_bytes,
		    VAR_TLS_APPEND_DEF_CA, params->tls_append_def_CA,
		    VAR_TLS_BC_PKEY_FPRINT, params->tls_bc_pkey_fprint,
		    VAR_TLS_PREEMPT_CLIST, params->tls_preempt_clist,
		    VAR_TLS_MULTI_WILDCARD, params->tls_multi_wildcard);
    return (vstring_str(buf));
}

/* tls_proxy_client_init_to_string - serialize to string */

char   *tls_proxy_client_init_to_string(VSTRING *buf,
					        TLS_CLIENT_INIT_PROPS *props)
{
    vstring_sprintf(buf, "%s\n%s\n%d\n%s\n%s\n%s\n%s\n%s\n%s\n"
		    "%s\n%s\n%s\n%s\n%s\n", props->log_param,
		    props->log_level, props->verifydepth,
		    props->cache_type, props->chain_files,
		    props->cert_file, props->key_file,
		    props->dcert_file, props->dkey_file,
		    props->eccert_file, props->eckey_file,
		    props->CAfile, props->CApath, props->mdalg);
    return (vstring_str(buf));
}

/* tls_proxy_client_init_with_names_to_string - serialize to string */

char   *tls_proxy_client_init_with_names_to_string(VSTRING *buf,
					        TLS_CLIENT_INIT_PROPS *props)
{
    vstring_sprintf(buf, "%s = %s\n%s = %s\n%s = %d\n%s = %s\n%s = %s\n"
		    "%s = %s\n%s = %s\n%s = %s\n%s = %s\n%s = %s\n"
		    "%s = %s\n%s = %s\n%s = %s\n%s = %s\n",
		    TLS_ATTR_LOG_PARAM, props->log_param,
		    TLS_ATTR_LOG_LEVEL, props->log_level,
		    TLS_ATTR_VERIFYDEPTH, props->verifydepth,
		    TLS_ATTR_CACHE_TYPE, props->cache_type,
		    TLS_ATTR_CHAIN_FILES, props->chain_files,
		    TLS_ATTR_CERT_FILE, props->cert_file,
		    TLS_ATTR_KEY_FILE, props->key_file,
		    TLS_ATTR_DCERT_FILE, props->dcert_file,
		    TLS_ATTR_DKEY_FILE, props->dkey_file,
		    TLS_ATTR_ECCERT_FILE, props->eccert_file,
		    TLS_ATTR_ECKEY_FILE, props->eckey_file,
		    TLS_ATTR_CAFILE, props->CAfile,
		    TLS_ATTR_CAPATH, props->CApath,
		    TLS_ATTR_MDALG, props->mdalg);
    return (vstring_str(buf));
}

#endif