Postfix3.3.1
tls.h
[詳解]
1 #ifndef _TLS_H_INCLUDED_
2 #define _TLS_H_INCLUDED_
3 
4 /*++
5 /* NAME
6 /* tls 3h
7 /* SUMMARY
8 /* libtls internal interfaces
9 /* SYNOPSIS
10 /* #include <tls.h>
11 /* DESCRIPTION
12 /* .nf
13 
14  /*
15  * Utility library.
16  */
17 #include <name_code.h>
18 #include <argv.h>
19 
20  /*
21  * TLS enforcement levels. Non-sentinel values may also be used to indicate
22  * the actual security level of a session.
23  *
24  * XXX TLS_LEV_NOTFOUND no longer belongs in this list. The SMTP client will
25  * have to use something else to report that policy table lookup failed.
26  *
27  * The order of levels matters, but we hide most of the details in macros.
28  *
29  * "dane" vs. "fingerprint", both must lie between "encrypt" and "verify".
30  *
31  * - With "may" and higher, TLS is enabled.
32  *
33  * - With "encrypt" and higher, TLS encryption must be applied.
34  *
35  * - Strictly above "encrypt", the peer certificate must match.
36  *
37  * - At "dane" and higher, the peer certificate must also be trusted. With
38  * "dane" the trust may be self-asserted, so we only log trust verification
39  * errors when TA associations are involved.
40  */
41 #define TLS_LEV_INVALID -2 /* sentinel */
42 #define TLS_LEV_NOTFOUND -1 /* XXX not in policy table */
43 #define TLS_LEV_NONE 0 /* plain-text only */
44 #define TLS_LEV_MAY 1 /* wildcard */
45 #define TLS_LEV_ENCRYPT 2 /* encrypted connection */
46 #define TLS_LEV_FPRINT 3 /* "peer" CA-less verification */
47 #define TLS_LEV_HALF_DANE 4 /* DANE TLSA MX host, insecure MX RR */
48 #define TLS_LEV_DANE 5 /* Opportunistic TLSA policy */
49 #define TLS_LEV_DANE_ONLY 6 /* Required TLSA policy */
50 #define TLS_LEV_VERIFY 7 /* certificate verified */
51 #define TLS_LEV_SECURE 8 /* "secure" verification */
52 
53 #define TLS_REQUIRED(l) ((l) > TLS_LEV_MAY)
54 #define TLS_MUST_MATCH(l) ((l) > TLS_LEV_ENCRYPT)
55 #define TLS_MUST_TRUST(l) ((l) >= TLS_LEV_HALF_DANE)
56 #define TLS_MUST_PKIX(l) ((l) >= TLS_LEV_VERIFY)
57 #define TLS_OPPORTUNISTIC(l) ((l) == TLS_LEV_MAY || (l) == TLS_LEV_DANE)
58 #define TLS_DANE_BASED(l) \
59  ((l) >= TLS_LEV_HALF_DANE && (l) <= TLS_LEV_DANE_ONLY)
60 #define TLS_NEVER_SECURED(l) ((l) == TLS_LEV_HALF_DANE)
61 
62 extern int tls_level_lookup(const char *);
63 extern const char *str_tls_level(int);
64 
65 #ifdef USE_TLS
66 
67  /*
68  * OpenSSL library.
69  */
70 #include <openssl/lhash.h>
71 #include <openssl/bn.h>
72 #include <openssl/err.h>
73 #include <openssl/pem.h>
74 #include <openssl/x509.h>
75 #include <openssl/x509v3.h>
76 #include <openssl/rand.h>
77 #include <openssl/crypto.h> /* Legacy SSLEAY_VERSION_NUMBER */
78 #include <openssl/opensslv.h> /* OPENSSL_VERSION_NUMBER */
79 #include <openssl/ssl.h>
80 
81  /* Appease indent(1) */
82 #define x509_stack_t STACK_OF(X509)
83 #define general_name_stack_t STACK_OF(GENERAL_NAME)
84 #define ssl_cipher_stack_t STACK_OF(SSL_CIPHER)
85 #define ssl_comp_stack_t STACK_OF(SSL_COMP)
86 
87 #if (OPENSSL_VERSION_NUMBER < 0x00090700f)
88 #error "need OpenSSL version 0.9.7 or later"
89 #endif
90 
91  /* Backwards compatibility with OpenSSL < 1.1.0 */
92 #if OPENSSL_VERSION_NUMBER < 0x10100000L
93 #define OpenSSL_version_num SSLeay
94 #define OpenSSL_version SSLeay_version
95 #define OPENSSL_VERSION SSLEAY_VERSION
96 #define X509_up_ref(x) \
97  CRYPTO_add(&((x)->references), 1, CRYPTO_LOCK_X509)
98 #define EVP_PKEY_up_ref(k) \
99  CRYPTO_add(&((k)->references), 1, CRYPTO_LOCK_EVP_PKEY)
100 #define X509_STORE_CTX_get0_cert(ctx) ((ctx)->cert)
101 #define X509_STORE_CTX_get0_untrusted(ctx) ((ctx)->untrusted)
102 #define X509_STORE_CTX_set0_untrusted X509_STORE_CTX_set_chain
103 #define X509_STORE_CTX_set0_trusted_stack X509_STORE_CTX_trusted_stack
104 #define ASN1_STRING_get0_data ASN1_STRING_data
105 #define X509_getm_notBefore X509_get_notBefore
106 #define X509_getm_notAfter X509_get_notAfter
107 #define TLS_method SSLv23_method
108 #define TLS_client_method SSLv23_client_method
109 #define TLS_server_method SSLv23_server_method
110 #endif
111 
112 /* SSL_CIPHER_get_name() got constified in 0.9.7g */
113 #if OPENSSL_VERSION_NUMBER >= 0x0090707fL /* constification */
114 #define SSL_CIPHER_const const
115 #else
116 #define SSL_CIPHER_const
117 #endif
118 
119 /* d2i_X509() got constified in 0.9.8a */
120 #if OPENSSL_VERSION_NUMBER >= 0x0090801fL
121 #define D2I_const const
122 #else
123 #define D2I_const
124 #endif
125 
126  /*
127  * Utility library.
128  */
129 #include <vstream.h>
130 #include <name_mask.h>
131 #include <name_code.h>
132 
133  /*
134  * TLS library.
135  */
136 #include <dns.h>
137 
138  /*
139  * Names of valid tlsmgr(8) session caches.
140  */
141 #define TLS_MGR_SCACHE_SMTPD "smtpd"
142 #define TLS_MGR_SCACHE_SMTP "smtp"
143 #define TLS_MGR_SCACHE_LMTP "lmtp"
144 
145  /*
146  * RFC 6698, 7671, 7672 DANE
147  */
148 #define TLS_DANE_TA 0 /* Match trust-anchor digests */
149 #define TLS_DANE_EE 1 /* Match end-entity digests */
150 
151 #define TLS_DANE_CERT 0 /* Match the certificate digest */
152 #define TLS_DANE_PKEY 1 /* Match the public key digest */
153 
154 #define TLS_DANE_FLAG_NORRS (1<<0) /* Nothing found in DNS */
155 #define TLS_DANE_FLAG_EMPTY (1<<1) /* Nothing usable found in DNS */
156 #define TLS_DANE_FLAG_ERROR (1<<2) /* TLSA record lookup error */
157 
158 #define tls_dane_unusable(dane) ((dane)->flags & TLS_DANE_FLAG_EMPTY)
159 #define tls_dane_notfound(dane) ((dane)->flags & TLS_DANE_FLAG_NORRS)
160 
161 #define TLS_DANE_CACHE_TTL_MIN 1 /* A lot can happen in ~2 seconds */
162 #define TLS_DANE_CACHE_TTL_MAX 100 /* Comparable to max_idle */
163 
164  /*
165  * Certificate and public key digests (typically from TLSA RRs), grouped by
166  * algorithm.
167  */
168 typedef struct TLS_TLSA {
169  char *mdalg; /* Algorithm for this digest list */
170  ARGV *certs; /* Complete certificate digests */
171  ARGV *pkeys; /* SubjectPublicKeyInfo digests */
172  struct TLS_TLSA *next; /* Chain to next algorithm */
173 } TLS_TLSA;
174 
175  /*
176  * Linked list of full X509 trust-anchor certs.
177  */
178 typedef struct TLS_CERTS {
179  X509 *cert;
180  struct TLS_CERTS *next;
181 } TLS_CERTS;
182 
183  /*
184  * Linked list of full EVP_PKEY trust-anchor public keys.
185  */
186 typedef struct TLS_PKEYS {
187  EVP_PKEY *pkey;
188  struct TLS_PKEYS *next;
189 } TLS_PKEYS;
190 
191 typedef struct TLS_DANE {
192  TLS_TLSA *ta; /* Trust-anchor cert/pubkey digests */
193  TLS_TLSA *ee; /* End-entity cert/pubkey digests */
194  TLS_CERTS *certs; /* Full trust-anchor certificates */
195  TLS_PKEYS *pkeys; /* Full trust-anchor public keys */
196  char *base_domain; /* Base domain of TLSA RRset */
197  int flags; /* Lookup status */
198  time_t expires; /* Expiration time of this record */
199  int refs; /* Reference count */
200 } TLS_DANE;
201 
202 #define TLS_DANE_HASTA(d) ((d) ? (d)->ta : 0)
203 #define TLS_DANE_HASEE(d) ((d) ? (d)->ee : 0)
204 
205  /*
206  * tls_dane.c
207  */
208 extern int tls_dane_avail(void);
209 extern void tls_dane_flush(void);
210 extern void tls_dane_verbose(int);
211 extern TLS_DANE *tls_dane_alloc(void);
212 extern void tls_dane_add_ee_digests(TLS_DANE *, const char *, const char *,
213  const char *);
214 extern void tls_dane_free(TLS_DANE *);
215 extern TLS_DANE *tls_dane_resolve(unsigned, const char *, DNS_RR *, int);
216 extern int tls_dane_load_trustfile(TLS_DANE *, const char *);
217 
218  /*
219  * TLS session context, also used by the VSTREAM call-back routines for SMTP
220  * input/output, and by OpenSSL call-back routines for key verification.
221  *
222  * Only some members are (read-only) accessible by the public.
223  */
224 #define CCERT_BUFSIZ 256
225 
226 typedef struct {
227  /* Public, read-only. */
228  char *peer_CN; /* Peer Common Name */
229  char *issuer_CN; /* Issuer Common Name */
230  char *peer_cert_fprint; /* ASCII certificate fingerprint */
231  char *peer_pkey_fprint; /* ASCII public key fingerprint */
232  int peer_status; /* Certificate and match status */
233  const char *protocol;
234  const char *cipher_name;
235  int cipher_usebits;
236  int cipher_algbits;
237  /* Private. */
238  SSL *con;
239  char *cache_type; /* tlsmgr(8) cache type if enabled */
240  int ticketed; /* Session ticket issued */
241  char *serverid; /* unique server identifier */
242  char *namaddr; /* nam[addr] for logging */
243  int log_mask; /* What to log */
244  int session_reused; /* this session was reused */
245  int am_server; /* Are we an SSL server or client? */
246  const char *mdalg; /* default message digest algorithm */
247  /* Built-in vs external SSL_accept/read/write/shutdown support. */
248  VSTREAM *stream; /* Blocking-mode SMTP session */
249  /* DANE TLSA trust input and verification state */
250  const TLS_DANE *dane; /* DANE TLSA digests */
251  int errordepth; /* Chain depth of error cert */
252  int tadepth; /* Chain depth of trust anchor */
253  int errorcode; /* First error at error depth */
254  X509 *errorcert; /* Error certificate closest to leaf */
255  x509_stack_t *untrusted; /* Certificate chain fodder */
256  x509_stack_t *trusted; /* Internal root CA list */
257 } TLS_SESS_STATE;
258 
259  /*
260  * Peer status bits. TLS_CERT_FLAG_MATCHED implies TLS_CERT_FLAG_TRUSTED
261  * only in the case of a hostname match.
262  */
263 #define TLS_CERT_FLAG_PRESENT (1<<0)
264 #define TLS_CERT_FLAG_ALTNAME (1<<1)
265 #define TLS_CERT_FLAG_TRUSTED (1<<2)
266 #define TLS_CERT_FLAG_MATCHED (1<<3)
267 #define TLS_CERT_FLAG_SECURED (1<<4)
268 
269 #define TLS_CERT_IS_PRESENT(c) ((c) && ((c)->peer_status&TLS_CERT_FLAG_PRESENT))
270 #define TLS_CERT_IS_ALTNAME(c) ((c) && ((c)->peer_status&TLS_CERT_FLAG_ALTNAME))
271 #define TLS_CERT_IS_TRUSTED(c) ((c) && ((c)->peer_status&TLS_CERT_FLAG_TRUSTED))
272 #define TLS_CERT_IS_MATCHED(c) ((c) && ((c)->peer_status&TLS_CERT_FLAG_MATCHED))
273 #define TLS_CERT_IS_SECURED(c) ((c) && ((c)->peer_status&TLS_CERT_FLAG_SECURED))
274 
275  /*
276  * Opaque client context handle.
277  */
278 typedef struct TLS_APPL_STATE TLS_APPL_STATE;
279 
280 #ifdef TLS_INTERNAL
281 
282  /*
283  * Log mask details are internal to the library.
284  */
285 extern int tls_log_mask(const char *, const char *);
286 
287  /*
288  * What to log.
289  */
290 #define TLS_LOG_NONE (1<<0)
291 #define TLS_LOG_SUMMARY (1<<1)
292 #define TLS_LOG_UNTRUSTED (1<<2)
293 #define TLS_LOG_PEERCERT (1<<3)
294 #define TLS_LOG_CERTMATCH (1<<4)
295 #define TLS_LOG_VERBOSE (1<<5)
296 #define TLS_LOG_CACHE (1<<6)
297 #define TLS_LOG_DEBUG (1<<7)
298 #define TLS_LOG_TLSPKTS (1<<8)
299 #define TLS_LOG_ALLPKTS (1<<9)
300 
301  /*
302  * Client and Server application contexts
303  */
304 struct TLS_APPL_STATE {
305  SSL_CTX *ssl_ctx;
306  int log_mask;
307  char *cache_type;
308  char *cipher_exclusions; /* Last cipher selection state */
309  char *cipher_list; /* Last cipher selection state */
310  int cipher_grade; /* Last cipher selection state */
311  VSTRING *why;
312 };
313 
314  /*
315  * tls_misc.c Application-context update and disposal.
316  */
317 extern void tls_update_app_logmask(TLS_APPL_STATE *, int);
318 extern void tls_free_app_context(TLS_APPL_STATE *);
319 
320  /*
321  * tls_misc.c
322  */
323 extern void tls_param_init(void);
324 
325  /*
326  * Protocol selection.
327  */
328 #define TLS_PROTOCOL_INVALID (~0) /* All protocol bits masked */
329 
330 #ifdef SSL_TXT_SSLV2
331 #define TLS_PROTOCOL_SSLv2 (1<<0) /* SSLv2 */
332 #else
333 #define SSL_TXT_SSLV2 "SSLv2"
334 #define TLS_PROTOCOL_SSLv2 0 /* Unknown */
335 #undef SSL_OP_NO_SSLv2
336 #define SSL_OP_NO_SSLv2 0L /* Noop */
337 #endif
338 
339 #ifdef SSL_TXT_SSLV3
340 #define TLS_PROTOCOL_SSLv3 (1<<1) /* SSLv3 */
341 #else
342 #define SSL_TXT_SSLV3 "SSLv3"
343 #define TLS_PROTOCOL_SSLv3 0 /* Unknown */
344 #undef SSL_OP_NO_SSLv3
345 #define SSL_OP_NO_SSLv3 0L /* Noop */
346 #endif
347 
348 #ifdef SSL_TXT_TLSV1
349 #define TLS_PROTOCOL_TLSv1 (1<<2) /* TLSv1 */
350 #else
351 #define SSL_TXT_TLSV1 "TLSv1"
352 #define TLS_PROTOCOL_TLSv1 0 /* Unknown */
353 #undef SSL_OP_NO_TLSv1
354 #define SSL_OP_NO_TLSv1 0L /* Noop */
355 #endif
356 
357 #ifdef SSL_TXT_TLSV1_1
358 #define TLS_PROTOCOL_TLSv1_1 (1<<3) /* TLSv1_1 */
359 #else
360 #define SSL_TXT_TLSV1_1 "TLSv1.1"
361 #define TLS_PROTOCOL_TLSv1_1 0 /* Unknown */
362 #undef SSL_OP_NO_TLSv1_1
363 #define SSL_OP_NO_TLSv1_1 0L /* Noop */
364 #endif
365 
366 #ifdef SSL_TXT_TLSV1_2
367 #define TLS_PROTOCOL_TLSv1_2 (1<<4) /* TLSv1_2 */
368 #else
369 #define SSL_TXT_TLSV1_2 "TLSv1.2"
370 #define TLS_PROTOCOL_TLSv1_2 0 /* Unknown */
371 #undef SSL_OP_NO_TLSv1_2
372 #define SSL_OP_NO_TLSv1_2 0L /* Noop */
373 #endif
374 
375 #ifdef SSL_TXT_TLSV1_3
376 #define TLS_PROTOCOL_TLSv1_3 (1<<5) /* TLSv1_3 */
377 #else
378 #define SSL_TXT_TLSV1_3 "TLSv1.3"
379 #define TLS_PROTOCOL_TLSv1_3 0 /* Unknown */
380 #undef SSL_OP_NO_TLSv1_3
381 #define SSL_OP_NO_TLSv1_3 0L /* Noop */
382 #endif
383 
384 #define TLS_KNOWN_PROTOCOLS \
385  ( TLS_PROTOCOL_SSLv2 | TLS_PROTOCOL_SSLv3 | TLS_PROTOCOL_TLSv1 \
386  | TLS_PROTOCOL_TLSv1_1 | TLS_PROTOCOL_TLSv1_2 )
387 #define TLS_SSL_OP_PROTOMASK(m) \
388  ((((m) & TLS_PROTOCOL_SSLv2) ? SSL_OP_NO_SSLv2 : 0L) \
389  | (((m) & TLS_PROTOCOL_SSLv3) ? SSL_OP_NO_SSLv3 : 0L) \
390  | (((m) & TLS_PROTOCOL_TLSv1) ? SSL_OP_NO_TLSv1 : 0L) \
391  | (((m) & TLS_PROTOCOL_TLSv1_1) ? SSL_OP_NO_TLSv1_1 : 0L) \
392  | (((m) & TLS_PROTOCOL_TLSv1_2) ? SSL_OP_NO_TLSv1_2 : 0L) \
393  | (((m) & TLS_PROTOCOL_TLSv1_3) ? SSL_OP_NO_TLSv1_3 : 0L))
394 
395 /*
396  * SSL options that are managed via dedicated Postfix features, rather than
397  * just exposed via hex codes or named elements of tls_ssl_options.
398  */
399 #define TLS_SSL_OP_MANAGED_BITS \
400  (SSL_OP_CIPHER_SERVER_PREFERENCE | TLS_SSL_OP_PROTOMASK(~0))
401 
402 extern int tls_protocol_mask(const char *);
403 
404  /*
405  * Cipher grade selection.
406  */
407 #define TLS_CIPHER_NONE 0
408 #define TLS_CIPHER_NULL 1
409 #define TLS_CIPHER_EXPORT 2
410 #define TLS_CIPHER_LOW 3
411 #define TLS_CIPHER_MEDIUM 4
412 #define TLS_CIPHER_HIGH 5
413 
414 extern const NAME_CODE tls_cipher_grade_table[];
415 
416 #define tls_cipher_grade(str) \
417  name_code(tls_cipher_grade_table, NAME_CODE_FLAG_NONE, (str))
418 #define str_tls_cipher_grade(gr) \
419  str_name_code(tls_cipher_grade_table, (gr))
420 
421  /*
422  * Cipher lists with exclusions.
423  */
424 extern const char *tls_set_ciphers(TLS_APPL_STATE *, const char *,
425  const char *, const char *);
426 
427 #endif
428 
429  /*
430  * tls_client.c
431  */
432 typedef struct {
433  const char *log_param;
434  const char *log_level;
435  int verifydepth;
436  const char *cache_type;
437  const char *cert_file;
438  const char *key_file;
439  const char *dcert_file;
440  const char *dkey_file;
441  const char *eccert_file;
442  const char *eckey_file;
443  const char *CAfile;
444  const char *CApath;
445  const char *mdalg; /* default message digest algorithm */
446 } TLS_CLIENT_INIT_PROPS;
447 
448 typedef struct {
449  TLS_APPL_STATE *ctx;
450  VSTREAM *stream;
451  int timeout;
452  int tls_level; /* Security level */
453  const char *nexthop; /* destination domain */
454  const char *host; /* MX hostname */
455  const char *namaddr; /* nam[addr] for logging */
456  const char *serverid; /* Session cache key */
457  const char *helo; /* Server name from EHLO response */
458  const char *protocols; /* Enabled protocols */
459  const char *cipher_grade; /* Minimum cipher grade */
460  const char *cipher_exclusions; /* Ciphers to exclude */
461  const ARGV *matchargv; /* Cert match patterns */
462  const char *mdalg; /* default message digest algorithm */
463  const TLS_DANE *dane; /* DANE TLSA verification */
464 } TLS_CLIENT_START_PROPS;
465 
466 extern TLS_APPL_STATE *tls_client_init(const TLS_CLIENT_INIT_PROPS *);
467 extern TLS_SESS_STATE *tls_client_start(const TLS_CLIENT_START_PROPS *);
468 
469 #define tls_client_stop(ctx, stream, timeout, failure, TLScontext) \
470  tls_session_stop(ctx, (stream), (timeout), (failure), (TLScontext))
471 
472 #define TLS_CLIENT_INIT(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, \
473  a10, a11, a12, a13) \
474  tls_client_init((((props)->a1), ((props)->a2), ((props)->a3), \
475  ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
476  ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
477  ((props)->a12), ((props)->a13), (props)))
478 
479 #define TLS_CLIENT_START(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, \
480  a10, a11, a12, a13, a14, a15) \
481  tls_client_start((((props)->a1), ((props)->a2), ((props)->a3), \
482  ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
483  ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
484  ((props)->a12), ((props)->a13), ((props)->a14), ((props)->a15), (props)))
485 
486  /*
487  * tls_server.c
488  */
489 typedef struct {
490  const char *log_param;
491  const char *log_level;
492  int verifydepth;
493  const char *cache_type;
494  int set_sessid;
495  const char *cert_file;
496  const char *key_file;
497  const char *dcert_file;
498  const char *dkey_file;
499  const char *eccert_file;
500  const char *eckey_file;
501  const char *CAfile;
502  const char *CApath;
503  const char *protocols;
504  const char *eecdh_grade;
505  const char *dh1024_param_file;
506  const char *dh512_param_file;
507  int ask_ccert;
508  const char *mdalg; /* default message digest algorithm */
509 } TLS_SERVER_INIT_PROPS;
510 
511 typedef struct {
512  TLS_APPL_STATE *ctx; /* TLS application context */
513  VSTREAM *stream; /* Client stream */
514  int fd; /* Event-driven file descriptor */
515  int timeout; /* TLS handshake timeout */
516  int requirecert; /* Insist on client cert? */
517  const char *serverid; /* Server instance (salt cache key) */
518  const char *namaddr; /* Client nam[addr] for logging */
519  const char *cipher_grade;
520  const char *cipher_exclusions;
521  const char *mdalg; /* default message digest algorithm */
522 } TLS_SERVER_START_PROPS;
523 
524 extern TLS_APPL_STATE *tls_server_init(const TLS_SERVER_INIT_PROPS *);
525 extern TLS_SESS_STATE *tls_server_start(const TLS_SERVER_START_PROPS *props);
526 extern TLS_SESS_STATE *tls_server_post_accept(TLS_SESS_STATE *);
527 
528 #define tls_server_stop(ctx, stream, timeout, failure, TLScontext) \
529  tls_session_stop(ctx, (stream), (timeout), (failure), (TLScontext))
530 
531 #define TLS_SERVER_INIT(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, \
532  a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) \
533  tls_server_init((((props)->a1), ((props)->a2), ((props)->a3), \
534  ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
535  ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
536  ((props)->a12), ((props)->a13), ((props)->a14), ((props)->a15), \
537  ((props)->a16), ((props)->a17), ((props)->a18), ((props)->a19), (props)))
538 
539 #define TLS_SERVER_START(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
540  tls_server_start((((props)->a1), ((props)->a2), ((props)->a3), \
541  ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
542  ((props)->a8), ((props)->a9), ((props)->a10), (props)))
543 
544  /*
545  * tls_session.c
546  */
547 extern void tls_session_stop(TLS_APPL_STATE *, VSTREAM *, int, int, TLS_SESS_STATE *);
548 
549  /*
550  * tls_misc.c
551  */
552 extern const char *tls_compile_version(void);
553 extern const char *tls_run_version(void);
554 extern const char **tls_pkey_algorithms(void);
555 
556 #ifdef TLS_INTERNAL
557 
558 #include <vstring.h>
559 
560 extern VSTRING *tls_session_passivate(SSL_SESSION *);
561 extern SSL_SESSION *tls_session_activate(const char *, int);
562 
563  /*
564  * tls_stream.c.
565  */
566 extern void tls_stream_start(VSTREAM *, TLS_SESS_STATE *);
567 extern void tls_stream_stop(VSTREAM *);
568 
569  /*
570  * tls_bio_ops.c: a generic multi-personality driver that retries SSL
571  * operations until they are satisfied or until a hard error happens.
572  * Because of its ugly multi-personality user interface we invoke it via
573  * not-so-ugly single-personality wrappers.
574  */
575 extern int tls_bio(int, int, TLS_SESS_STATE *,
576  int (*) (SSL *), /* handshake */
577  int (*) (SSL *, void *, int), /* read */
578  int (*) (SSL *, const void *, int), /* write */
579  void *, int);
580 
581 #define tls_bio_connect(fd, timeout, context) \
582  tls_bio((fd), (timeout), (context), SSL_connect, \
583  NULL, NULL, NULL, 0)
584 #define tls_bio_accept(fd, timeout, context) \
585  tls_bio((fd), (timeout), (context), SSL_accept, \
586  NULL, NULL, NULL, 0)
587 #define tls_bio_shutdown(fd, timeout, context) \
588  tls_bio((fd), (timeout), (context), SSL_shutdown, \
589  NULL, NULL, NULL, 0)
590 #define tls_bio_read(fd, buf, len, timeout, context) \
591  tls_bio((fd), (timeout), (context), NULL, \
592  SSL_read, NULL, (buf), (len))
593 #define tls_bio_write(fd, buf, len, timeout, context) \
594  tls_bio((fd), (timeout), (context), NULL, \
595  NULL, SSL_write, (buf), (len))
596 
597  /*
598  * tls_dh.c
599  */
600 extern void tls_set_dh_from_file(const char *, int);
601 extern DH *tls_tmp_dh_cb(SSL *, int, int);
602 extern void tls_set_eecdh_curve(SSL_CTX *, const char *);
603 extern void tls_auto_eecdh_curves(SSL_CTX *);
604 
605  /*
606  * tls_rsa.c
607  */
608 extern RSA *tls_tmp_rsa_cb(SSL *, int, int);
609 
610  /*
611  * tls_verify.c
612  */
613 extern char *tls_peer_CN(X509 *, const TLS_SESS_STATE *);
614 extern char *tls_issuer_CN(X509 *, const TLS_SESS_STATE *);
615 extern const char *tls_dns_name(const GENERAL_NAME *, const TLS_SESS_STATE *);
616 extern int tls_verify_certificate_callback(int, X509_STORE_CTX *);
617 extern void tls_log_verify_error(TLS_SESS_STATE *);
618 
619  /*
620  * tls_dane.c
621  */
622 extern int tls_dane_match(TLS_SESS_STATE *, int, X509 *, int);
623 extern void tls_dane_set_callback(SSL_CTX *, TLS_SESS_STATE *);
624 
625  /*
626  * tls_fprint.c
627  */
628 extern char *tls_digest_encode(const unsigned char *, int);
629 extern char *tls_data_fprint(const char *, int, const char *);
630 extern char *tls_cert_fprint(X509 *, const char *);
631 extern char *tls_pkey_fprint(X509 *, const char *);
632 extern char *tls_serverid_digest(const TLS_CLIENT_START_PROPS *, long,
633  const char *);
634 
635  /*
636  * tls_certkey.c
637  */
638 extern int tls_set_ca_certificate_info(SSL_CTX *, const char *, const char *);
639 extern int tls_set_my_certificate_key_info(SSL_CTX *,
640  /* RSA */ const char *, const char *,
641  /* DSA */ const char *, const char *,
642  /* ECDSA */ const char *, const char *);
643 
644  /*
645  * tls_misc.c
646  */
647 extern int TLScontext_index;
648 
649 extern TLS_APPL_STATE *tls_alloc_app_context(SSL_CTX *, int);
650 extern TLS_SESS_STATE *tls_alloc_sess_context(int, const char *);
651 extern void tls_free_context(TLS_SESS_STATE *);
652 extern void tls_check_version(void);
653 extern long tls_bug_bits(void);
654 extern void tls_print_errors(void);
655 extern void tls_info_callback(const SSL *, int, int);
656 extern long tls_bio_dump_cb(BIO *, int, const char *, int, long, long);
657 extern int tls_validate_digest(const char *);
658 
659  /*
660  * tls_seed.c
661  */
662 extern void tls_int_seed(void);
663 extern int tls_ext_seed(int);
664 
665 #endif /* TLS_INTERNAL */
666 
667 /* LICENSE
668 /* .ad
669 /* .fi
670 /* The Secure Mailer license must be distributed with this software.
671 /* AUTHOR(S)
672 /* Wietse Venema
673 /* IBM T.J. Watson Research
674 /* P.O. Box 704
675 /* Yorktown Heights, NY 10598, USA
676 /*
677 /* Victor Duchovni
678 /* Morgan Stanley
679 /*--*/
680 
681 #endif /* USE_TLS */
682 #endif /* _TLS_H_INCLUDED_ */
const char * str_tls_level(int)
Definition: tls_level.c:92
Definition: argv.h:17
int tls_level_lookup(const char *)
Definition: tls_level.c:85
Definition: dns.h:139