Postfix3.3.1
全て データ構造 ファイル 関数 変数 型定義 マクロ定義
tls_proxy_scan.c
[詳解]
1 /*++
2 /* NAME
3 /* tls_proxy_scan
4 /* SUMMARY
5 /* read TLS session state from stream
6 /* SYNOPSIS
7 /* #include <tls_proxy.h>
8 /*
9 /* int tls_proxy_context_scan(scan_fn, stream, flags, ptr)
10 /* ATTR_SCAN_MASTER_FN scan_fn;
11 /* VSTREAM *stream;
12 /* int flags;
13 /* void *ptr;
14 /* DESCRIPTION
15 /* tls_proxy_context_scan() reads a TLS_SESS_STATE structure
16 /* from the named stream using the specified attribute scan
17 /* routine. tls_proxy_context_scan() is meant to be passed as
18 /* a call-back to attr_scan(), thusly:
19 /*
20 /* ... RECV_ATTR_FUNC(tls_proxy_context_scan, (void *) tls_context), ...
21 /* DIAGNOSTICS
22 /* Fatal: out of memory.
23 /* LICENSE
24 /* .ad
25 /* .fi
26 /* The Secure Mailer license must be distributed with this software.
27 /* AUTHOR(S)
28 /* Wietse Venema
29 /* IBM T.J. Watson Research
30 /* P.O. Box 704
31 /* Yorktown Heights, NY 10598, USA
32 /*--*/
33 
34 #ifdef USE_TLS
35 
36 /* System library. */
37 
38 #include <sys_defs.h>
39 
40 /* Utility library */
41 
42 #include <attr.h>
43 
44 /* Global library. */
45 
46 #include <mail_proto.h>
47 
48 /* TLS library. */
49 
50 #include <tls.h>
51 #include <tls_proxy.h>
52 
53 /* tls_proxy_context_scan - receive TLS session state from stream */
54 
55 int tls_proxy_context_scan(ATTR_SCAN_MASTER_FN scan_fn, VSTREAM *fp,
56  int flags, void *ptr)
57 {
58  TLS_SESS_STATE *tls_context = (TLS_SESS_STATE *) ptr;
59  int ret;
60  VSTRING *peer_CN = vstring_alloc(25);
61  VSTRING *issuer_CN = vstring_alloc(25);
62  VSTRING *peer_cert_fprint = vstring_alloc(60); /* 60 for SHA-1 */
63  VSTRING *peer_pkey_fprint = vstring_alloc(60); /* 60 for SHA-1 */
64  VSTRING *protocol = vstring_alloc(25);
65  VSTRING *cipher_name = vstring_alloc(25);
66 
67  /*
68  * Note: memset() is not a portable way to initialize non-integer types.
69  */
70  memset(ptr, 0, sizeof(TLS_SESS_STATE));
71  ret = scan_fn(fp, flags | ATTR_FLAG_MORE,
74  RECV_ATTR_STR(MAIL_ATTR_PEER_CERT_FPT, peer_cert_fprint),
75  RECV_ATTR_STR(MAIL_ATTR_PEER_PKEY_FPT, peer_pkey_fprint),
77  &tls_context->peer_status),
81  &tls_context->cipher_usebits),
83  &tls_context->cipher_algbits),
85  tls_context->peer_CN = vstring_export(peer_CN);
86  tls_context->issuer_CN = vstring_export(issuer_CN);
87  tls_context->peer_cert_fprint = vstring_export(peer_cert_fprint);
88  tls_context->peer_pkey_fprint = vstring_export(peer_pkey_fprint);
89  tls_context->protocol = vstring_export(protocol);
90  tls_context->cipher_name = vstring_export(cipher_name);
91  return (ret == 9 ? 1 : -1);
92 }
93 
94 #endif
#define MAIL_ATTR_PEER_CN
Definition: mail_proto.h:287
#define MAIL_ATTR_CIPHER_ALGBITS
Definition: mail_proto.h:295
#define RECV_ATTR_INT(name, val)
Definition: attr.h:71
#define ATTR_TYPE_END
Definition: attr.h:39
#define MAIL_ATTR_PEER_PKEY_FPT
Definition: mail_proto.h:290
#define MAIL_ATTR_CIPHER_PROTOCOL
Definition: mail_proto.h:292
int(* ATTR_SCAN_MASTER_FN)(VSTREAM *, int,...)
Definition: attr.h:31
VSTRING * vstring_alloc(ssize_t len)
Definition: vstring.c:353
#define MAIL_ATTR_CIPHER_USEBITS
Definition: mail_proto.h:294
#define MAIL_ATTR_PEER_CERT_FPT
Definition: mail_proto.h:289
#define MAIL_ATTR_CIPHER_NAME
Definition: mail_proto.h:293
#define MAIL_ATTR_PEER_STATUS
Definition: mail_proto.h:291
#define ATTR_FLAG_MORE
Definition: attr.h:101
#define MAIL_ATTR_ISSUER_CN
Definition: mail_proto.h:288
char * vstring_export(VSTRING *vp)
Definition: vstring.c:569
#define RECV_ATTR_STR(name, val)
Definition: attr.h:72