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