1 /* $NetBSD: tls_proxy_context_print.c,v 1.3 2022/10/08 16:12:50 christos Exp $ */
2
3 /*++
4 /* NAME
5 /* tls_proxy_context_print
6 /* SUMMARY
7 /* write TLS_ATTR_STATE structure to stream
8 /* SYNOPSIS
9 /* #include <tls_proxy.h>
10 /*
11 /* int tls_proxy_context_print(print_fn, stream, flags, ptr)
12 /* ATTR_PRINT_COMMON_FN print_fn;
13 /* VSTREAM *stream;
14 /* int flags;
15 /* const void *ptr;
16 /* DESCRIPTION
17 /* tls_proxy_context_print() writes the public members of a
18 /* TLS_ATTR_STATE structure to the named stream using the
19 /* specified attribute print routine. tls_proxy_context_print()
20 /* is meant to be passed as a call-back to attr_print(), thusly:
21 /*
22 /* ... SEND_ATTR_FUNC(tls_proxy_context_print, (const void *) tls_context), ...
23 /* DIAGNOSTICS
24 /* Fatal: out of memory.
25 /* LICENSE
26 /* .ad
27 /* .fi
28 /* The Secure Mailer license must be distributed with this software.
29 /* AUTHOR(S)
30 /* Wietse Venema
31 /* IBM T.J. Watson Research
32 /* P.O. Box 704
33 /* Yorktown Heights, NY 10598, USA
34 /*
35 /* Wietse Venema
36 /* Google, Inc.
37 /* 111 8th Avenue
38 /* New York, NY 10011, USA
39 /*--*/
40
41 #ifdef USE_TLS
42
43 /* System library. */
44
45 #include <sys_defs.h>
46
47 /* Utility library */
48
49 #include <attr.h>
50
51 /* TLS library. */
52
53 #include <tls.h>
54 #include <tls_proxy.h>
55
56 /* tls_proxy_context_print - send TLS session state over stream */
57
tls_proxy_context_print(ATTR_PRINT_COMMON_FN print_fn,VSTREAM * fp,int flags,const void * ptr)58 int tls_proxy_context_print(ATTR_PRINT_COMMON_FN print_fn, VSTREAM *fp,
59 int flags, const void *ptr)
60 {
61 const TLS_SESS_STATE *tp = (const TLS_SESS_STATE *) ptr;
62 int ret;
63
64 #define STRING_OR_EMPTY(s) ((s) ? (s) : "")
65
66 ret = print_fn(fp, flags | ATTR_FLAG_MORE,
67 SEND_ATTR_STR(TLS_ATTR_PEER_CN,
68 STRING_OR_EMPTY(tp->peer_CN)),
69 SEND_ATTR_STR(TLS_ATTR_ISSUER_CN,
70 STRING_OR_EMPTY(tp->issuer_CN)),
71 SEND_ATTR_STR(TLS_ATTR_PEER_CERT_FPT,
72 STRING_OR_EMPTY(tp->peer_cert_fprint)),
73 SEND_ATTR_STR(TLS_ATTR_PEER_PKEY_FPT,
74 STRING_OR_EMPTY(tp->peer_pkey_fprint)),
75 SEND_ATTR_INT(TLS_ATTR_SEC_LEVEL,
76 tp->level),
77 SEND_ATTR_INT(TLS_ATTR_PEER_STATUS,
78 tp->peer_status),
79 SEND_ATTR_STR(TLS_ATTR_CIPHER_PROTOCOL,
80 STRING_OR_EMPTY(tp->protocol)),
81 SEND_ATTR_STR(TLS_ATTR_CIPHER_NAME,
82 STRING_OR_EMPTY(tp->cipher_name)),
83 SEND_ATTR_INT(TLS_ATTR_CIPHER_USEBITS,
84 tp->cipher_usebits),
85 SEND_ATTR_INT(TLS_ATTR_CIPHER_ALGBITS,
86 tp->cipher_algbits),
87 SEND_ATTR_STR(TLS_ATTR_KEX_NAME,
88 STRING_OR_EMPTY(tp->kex_name)),
89 SEND_ATTR_STR(TLS_ATTR_KEX_CURVE,
90 STRING_OR_EMPTY(tp->kex_curve)),
91 SEND_ATTR_INT(TLS_ATTR_KEX_BITS,
92 tp->kex_bits),
93 SEND_ATTR_STR(TLS_ATTR_CLNT_SIG_NAME,
94 STRING_OR_EMPTY(tp->clnt_sig_name)),
95 SEND_ATTR_STR(TLS_ATTR_CLNT_SIG_CURVE,
96 STRING_OR_EMPTY(tp->clnt_sig_curve)),
97 SEND_ATTR_INT(TLS_ATTR_CLNT_SIG_BITS,
98 tp->clnt_sig_bits),
99 SEND_ATTR_STR(TLS_ATTR_CLNT_SIG_DGST,
100 STRING_OR_EMPTY(tp->clnt_sig_dgst)),
101 SEND_ATTR_STR(TLS_ATTR_SRVR_SIG_NAME,
102 STRING_OR_EMPTY(tp->srvr_sig_name)),
103 SEND_ATTR_STR(TLS_ATTR_SRVR_SIG_CURVE,
104 STRING_OR_EMPTY(tp->srvr_sig_curve)),
105 SEND_ATTR_INT(TLS_ATTR_SRVR_SIG_BITS,
106 tp->srvr_sig_bits),
107 SEND_ATTR_STR(TLS_ATTR_SRVR_SIG_DGST,
108 STRING_OR_EMPTY(tp->srvr_sig_dgst)),
109 SEND_ATTR_STR(TLS_ATTR_NAMADDR,
110 STRING_OR_EMPTY(tp->namaddr)),
111 ATTR_TYPE_END);
112 /* Do not flush the stream. */
113 return (ret);
114 }
115
116 #endif
117