1 /*++
2 /* NAME
3 /*	tls_proxy_server_print 3
4 /* SUMMARY
5 /*	write TLS_SERVER_XXX structures to stream
6 /* SYNOPSIS
7 /*	#include <tls_proxy.h>
8 /*
9 /*	int     tls_proxy_server_init_print(print_fn, stream, flags, ptr)
10 /*	ATTR_PRINT_COMMON_FN print_fn;
11 /*	VSTREAM *stream;
12 /*	int     flags;
13 /*	void    *ptr;
14 /*
15 /*	int     tls_proxy_server_start_print(print_fn, stream, flags, ptr)
16 /*	ATTR_PRINT_COMMON_FN print_fn;
17 /*	VSTREAM *stream;
18 /*	int     flags;
19 /*	void    *ptr;
20 /* DESCRIPTION
21 /*	tls_proxy_server_init_print() writes a TLS_SERVER_INIT_PROPS
22 /*	structure to the named stream using the specified attribute print
23 /*	routine. tls_proxy_server_init_print() is meant to be passed as
24 /*	a call-back to attr_print(), thusly:
25 /*
26 /*	... SEND_ATTR_FUNC(tls_proxy_server_init_print, (const void *) init_props), ...
27 /*
28 /*	tls_proxy_server_start_print() writes a TLS_SERVER_START_PROPS
29 /*	structure to the named stream using the specified attribute print
30 /*	routine. tls_proxy_server_start_print() is meant to be passed as
31 /*	a call-back to attr_print(), thusly:
32 /*
33 /*	... SEND_ATTR_FUNC(tls_proxy_server_start_print, (const void *) start_props), ...
34 /* DIAGNOSTICS
35 /*	Fatal: out of memory.
36 /* LICENSE
37 /* .ad
38 /* .fi
39 /*	The Secure Mailer license must be distributed with this software.
40 /* AUTHOR(S)
41 /*	Wietse Venema
42 /*	Google, Inc.
43 /*	111 8th Avenue
44 /*	New York, NY 10011, USA
45 /*--*/
46 
47 #ifdef USE_TLS
48 
49 /* System library. */
50 
51 #include <sys_defs.h>
52 
53 /* Utility library */
54 
55 #include <attr.h>
56 
57 /* TLS library. */
58 
59 #include <tls.h>
60 #include <tls_proxy.h>
61 
62 /* tls_proxy_server_init_print - send TLS_SERVER_INIT_PROPS over stream */
63 
tls_proxy_server_init_print(ATTR_PRINT_COMMON_FN print_fn,VSTREAM * fp,int flags,const void * ptr)64 int     tls_proxy_server_init_print(ATTR_PRINT_COMMON_FN print_fn, VSTREAM *fp,
65 				            int flags, const void *ptr)
66 {
67     const TLS_SERVER_INIT_PROPS *props = (const TLS_SERVER_INIT_PROPS *) ptr;
68     int     ret;
69 
70 #define STRING_OR_EMPTY(s) ((s) ? (s) : "")
71 
72     ret = print_fn(fp, flags | ATTR_FLAG_MORE,
73 		   SEND_ATTR_STR(TLS_ATTR_LOG_PARAM,
74 				 STRING_OR_EMPTY(props->log_param)),
75 		   SEND_ATTR_STR(TLS_ATTR_LOG_LEVEL,
76 				 STRING_OR_EMPTY(props->log_level)),
77 		   SEND_ATTR_INT(TLS_ATTR_VERIFYDEPTH, props->verifydepth),
78 		   SEND_ATTR_STR(TLS_ATTR_CACHE_TYPE,
79 				 STRING_OR_EMPTY(props->cache_type)),
80 		   SEND_ATTR_INT(TLS_ATTR_SET_SESSID, props->set_sessid),
81 		   SEND_ATTR_STR(TLS_ATTR_CHAIN_FILES,
82 				 STRING_OR_EMPTY(props->chain_files)),
83 		   SEND_ATTR_STR(TLS_ATTR_CERT_FILE,
84 				 STRING_OR_EMPTY(props->cert_file)),
85 		   SEND_ATTR_STR(TLS_ATTR_KEY_FILE,
86 				 STRING_OR_EMPTY(props->key_file)),
87 		   SEND_ATTR_STR(TLS_ATTR_DCERT_FILE,
88 				 STRING_OR_EMPTY(props->dcert_file)),
89 		   SEND_ATTR_STR(TLS_ATTR_DKEY_FILE,
90 				 STRING_OR_EMPTY(props->dkey_file)),
91 		   SEND_ATTR_STR(TLS_ATTR_ECCERT_FILE,
92 				 STRING_OR_EMPTY(props->eccert_file)),
93 		   SEND_ATTR_STR(TLS_ATTR_ECKEY_FILE,
94 				 STRING_OR_EMPTY(props->eckey_file)),
95 		   SEND_ATTR_STR(TLS_ATTR_CAFILE,
96 				 STRING_OR_EMPTY(props->CAfile)),
97 		   SEND_ATTR_STR(TLS_ATTR_CAPATH,
98 				 STRING_OR_EMPTY(props->CApath)),
99 		   SEND_ATTR_STR(TLS_ATTR_PROTOCOLS,
100 				 STRING_OR_EMPTY(props->protocols)),
101 		   SEND_ATTR_STR(TLS_ATTR_EECDH_GRADE,
102 				 STRING_OR_EMPTY(props->eecdh_grade)),
103 		   SEND_ATTR_STR(TLS_ATTR_DH1K_PARAM_FILE,
104 				 STRING_OR_EMPTY(props->dh1024_param_file)),
105 		   SEND_ATTR_STR(TLS_ATTR_DH512_PARAM_FILE,
106 				 STRING_OR_EMPTY(props->dh512_param_file)),
107 		   SEND_ATTR_INT(TLS_ATTR_ASK_CCERT, props->ask_ccert),
108 		   SEND_ATTR_STR(TLS_ATTR_MDALG,
109 				 STRING_OR_EMPTY(props->mdalg)),
110 		   ATTR_TYPE_END);
111     /* Do not flush the stream. */
112     return (ret);
113 }
114 
115 /* tls_proxy_server_start_print - send TLS_SERVER_START_PROPS over stream */
116 
tls_proxy_server_start_print(ATTR_PRINT_COMMON_FN print_fn,VSTREAM * fp,int flags,const void * ptr)117 int     tls_proxy_server_start_print(ATTR_PRINT_COMMON_FN print_fn, VSTREAM *fp,
118 				             int flags, const void *ptr)
119 {
120     const TLS_SERVER_START_PROPS *props = (const TLS_SERVER_START_PROPS *) ptr;
121     int     ret;
122 
123 #define STRING_OR_EMPTY(s) ((s) ? (s) : "")
124 
125     ret = print_fn(fp, flags | ATTR_FLAG_MORE,
126 		   SEND_ATTR_INT(TLS_ATTR_TIMEOUT, props->timeout),
127 		   SEND_ATTR_INT(TLS_ATTR_REQUIRECERT, props->requirecert),
128 		   SEND_ATTR_STR(TLS_ATTR_SERVERID,
129 				 STRING_OR_EMPTY(props->serverid)),
130 		   SEND_ATTR_STR(TLS_ATTR_NAMADDR,
131 				 STRING_OR_EMPTY(props->namaddr)),
132 		   SEND_ATTR_STR(TLS_ATTR_CIPHER_GRADE,
133 				 STRING_OR_EMPTY(props->cipher_grade)),
134 		   SEND_ATTR_STR(TLS_ATTR_CIPHER_EXCLUSIONS,
135 				 STRING_OR_EMPTY(props->cipher_exclusions)),
136 		   SEND_ATTR_STR(TLS_ATTR_MDALG,
137 				 STRING_OR_EMPTY(props->mdalg)),
138 		   ATTR_TYPE_END);
139     /* Do not flush the stream. */
140     return (ret);
141 }
142 
143 #endif
144