Postfix3.3.1
tls_level.c
[詳解]
1 /*++
2 /* NAME
3 /* tls_level 3
4 /* SUMMARY
5 /* TLS security level conversion
6 /* SYNOPSIS
7 /* #include <tls.h>
8 /*
9 /* int tls_level_lookup(name)
10 /* const char *name;
11 /*
12 /* const char *str_tls_level(level)
13 /* int level;
14 /* DESCRIPTION
15 /* The functions in this module convert TLS levels from symbolic
16 /* name to internal form and vice versa.
17 /*
18 /* tls_level_lookup() converts a TLS level from symbolic name
19 /* to internal form. When an unknown level is specified,
20 /* tls_level_lookup() logs no warning, and returns TLS_LEV_INVALID.
21 /*
22 /* str_tls_level() converts a TLS level from internal form to
23 /* symbolic name. The result is a null pointer for an unknown
24 /* level. The "halfdane" level is not a valid user-selected TLS level,
25 /* it is generated internally and is only valid output for the
26 /* str_tls_level() function.
27 /* SEE ALSO
28 /* name_code(3) name to number mapping
29 /* LICENSE
30 /* .ad
31 /* .fi
32 /* The Secure Mailer license must be distributed with this software.
33 /* AUTHOR(S)
34 /* Wietse Venema
35 /* IBM T.J. Watson Research
36 /* P.O. Box 704
37 /* Yorktown Heights, NY 10598, USA
38 /*
39 /* Victor Duchovni
40 /* Morgan Stanley
41 /*--*/
42 
43 /* System library. */
44 
45 #include <sys_defs.h>
46 
47 /* Utility library. */
48 
49 #include <name_code.h>
50 
51 /* TLS library. */
52 
53 #include <tls.h>
54 
55 /* Application-specific. */
56 
57  /*
58  * Numerical order of levels is critical (see tls.h):
59  *
60  * - With "may" and higher, TLS is enabled.
61  *
62  * - With "encrypt" and higher, TLS is required.
63  *
64  * - With "fingerprint" and higher, the peer certificate must match.
65  *
66  * - With "dane" and higher, the peer certificate must also be trusted,
67  * possibly via TLSA RRs that make it its own authority.
68  *
69  * The smtp(8) client will report trust failure in preference to reporting
70  * failure to match, so we make "dane" larger than "fingerprint".
71  */
72 static const NAME_CODE tls_level_table[] = {
73  "none", TLS_LEV_NONE,
74  "may", TLS_LEV_MAY,
75  "encrypt", TLS_LEV_ENCRYPT,
76  "fingerprint", TLS_LEV_FPRINT,
77  "halfdane", TLS_LEV_HALF_DANE, /* output only */
78  "dane", TLS_LEV_DANE,
79  "dane-only", TLS_LEV_DANE_ONLY,
80  "verify", TLS_LEV_VERIFY,
81  "secure", TLS_LEV_SECURE,
82  0, TLS_LEV_INVALID,
83 };
84 
85 int tls_level_lookup(const char *name)
86 {
87  int level = name_code(tls_level_table, NAME_CODE_FLAG_NONE, name);
88 
89  return ((level != TLS_LEV_HALF_DANE) ? level : TLS_LEV_INVALID);
90 }
91 
92 const char *str_tls_level(int level)
93 {
94  return (str_name_code(tls_level_table, level));
95 }
#define TLS_LEV_DANE_ONLY
Definition: tls.h:49
#define TLS_LEV_HALF_DANE
Definition: tls.h:47
#define TLS_LEV_VERIFY
Definition: tls.h:50
const char * str_tls_level(int level)
Definition: tls_level.c:92
#define TLS_LEV_NONE
Definition: tls.h:43
#define TLS_LEV_DANE
Definition: tls.h:48
#define TLS_LEV_SECURE
Definition: tls.h:51
const char * str_name_code(const NAME_CODE *table, int code)
Definition: name_code.c:83
#define NAME_CODE_FLAG_NONE
Definition: name_code.h:22
#define TLS_LEV_ENCRYPT
Definition: tls.h:45
int name_code(const NAME_CODE *table, int flags, const char *name)
Definition: name_code.c:65
#define TLS_LEV_FPRINT
Definition: tls.h:46
int tls_level_lookup(const char *name)
Definition: tls_level.c:85
#define TLS_LEV_MAY
Definition: tls.h:44
#define TLS_LEV_INVALID
Definition: tls.h:41