~ubuntu-branches/ubuntu/trusty/postfix/trusty-updates

« back to all changes in this revision

Viewing changes to src/tls/tls.h

  • Committer: Package Import Robot
  • Author(s): LaMont Jones, LaMont Jones, localization folks
  • Date: 2014-02-11 07:44:30 UTC
  • mfrom: (58.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20140211074430-kwkoxdz0fbajn0fj
Tags: 2.11.0-1
[LaMont Jones]

* New upstream release: 2.11.0

[localization folks]

* l10n: Updated German translations.  Closes: #734893 (Helge Kreutzmann)

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
  * 
24
24
  * XXX TLS_LEV_NOTFOUND no longer belongs in this list. The SMTP client will
25
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.
26
40
  */
27
41
#define TLS_LEV_INVALID         -2      /* sentinel */
28
42
#define TLS_LEV_NOTFOUND        -1      /* XXX not in policy table */
30
44
#define TLS_LEV_MAY             1       /* wildcard */
31
45
#define TLS_LEV_ENCRYPT         2       /* encrypted connection */
32
46
#define TLS_LEV_FPRINT          3       /* "peer" CA-less verification */
33
 
#define TLS_LEV_VERIFY          4       /* certificate verified */
34
 
#define TLS_LEV_SECURE          5       /* "secure" verification */
 
47
#define TLS_LEV_DANE            4       /* Opportunistic TLSA policy */
 
48
#define TLS_LEV_DANE_ONLY       5       /* Required TLSA policy */
 
49
#define TLS_LEV_VERIFY          6       /* certificate verified */
 
50
#define TLS_LEV_SECURE          7       /* "secure" verification */
 
51
 
 
52
#define TLS_REQUIRED(l)         ((l) > TLS_LEV_MAY)
 
53
#define TLS_MUST_MATCH(l)       ((l) > TLS_LEV_ENCRYPT)
 
54
#define TLS_MUST_TRUST(l)       ((l) >= TLS_LEV_DANE)
 
55
#define TLS_MUST_PKIX(l)        ((l) >= TLS_LEV_VERIFY)
35
56
 
36
57
extern const NAME_CODE tls_level_table[];
37
58
 
52
73
#include <openssl/rand.h>
53
74
#include <openssl/ssl.h>
54
75
 
55
 
#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
56
 
#error "need OpenSSL version 0.9.5 or later"
 
76
 /* Appease indent(1) */
 
77
#define x509_stack_t STACK_OF(X509)
 
78
#define x509_extension_stack_t STACK_OF(X509_EXTENSION)
 
79
#define general_name_stack_t STACK_OF(GENERAL_NAME)
 
80
#define ssl_cipher_stack_t STACK_OF(SSL_CIPHER)
 
81
#define ssl_comp_stack_t STACK_OF(SSL_COMP)
 
82
 
 
83
#if (OPENSSL_VERSION_NUMBER < 0x00090700f)
 
84
#error "need OpenSSL version 0.9.7 or later"
 
85
#endif
 
86
 
 
87
/* SSL_CIPHER_get_name() got constified in 0.9.7g */
 
88
#if OPENSSL_VERSION_NUMBER >= 0x0090707fL       /* constification */
 
89
#define SSL_CIPHER_const const
 
90
#else
 
91
#define SSL_CIPHER_const
 
92
#endif
 
93
 
 
94
/* d2i_X509() got constified in 0.9.8a */
 
95
#if OPENSSL_VERSION_NUMBER >= 0x0090801fL
 
96
#define D2I_const const
 
97
#else
 
98
#define D2I_const
57
99
#endif
58
100
 
59
101
 /*
62
104
#include <vstream.h>
63
105
#include <name_mask.h>
64
106
#include <name_code.h>
 
107
#include <dns.h>
65
108
 
66
109
 /*
67
110
  * Names of valid tlsmgr(8) session caches.
71
114
#define TLS_MGR_SCACHE_LMTP     "lmtp"
72
115
 
73
116
 /*
 
117
  * RFC 6698 DANE
 
118
  */
 
119
#define TLS_DANE_TA     0               /* Match trust-anchor digests */
 
120
#define TLS_DANE_EE     1               /* Match end-entity digests */
 
121
 
 
122
#define TLS_DANE_CERT   0               /* Match the certificate digest */
 
123
#define TLS_DANE_PKEY   1               /* Match the public key digest */
 
124
 
 
125
#define TLS_DANE_FLAG_NORRS     (1<<0)  /* Nothing found in DNS */
 
126
#define TLS_DANE_FLAG_EMPTY     (1<<1)  /* Nothing usable found in DNS */
 
127
#define TLS_DANE_FLAG_ERROR     (1<<2)  /* TLSA record lookup error */
 
128
 
 
129
#define tls_dane_unusable(dane) ((dane)->flags & TLS_DANE_FLAG_EMPTY)
 
130
#define tls_dane_notfound(dane) ((dane)->flags & TLS_DANE_FLAG_NORRS)
 
131
 
 
132
#define TLS_DANE_CACHE_TTL_MIN 1        /* A lot can happen in ~2 seconds */
 
133
#define TLS_DANE_CACHE_TTL_MAX 100      /* Comparable to max_idle */
 
134
 
 
135
 /*
 
136
  * Certificate and public key digests (typically from TLSA RRs), grouped by
 
137
  * algorithm.
 
138
  */
 
139
typedef struct TLS_TLSA {
 
140
    char   *mdalg;                      /* Algorithm for this digest list */
 
141
    ARGV   *certs;                      /* Complete certificate digests */
 
142
    ARGV   *pkeys;                      /* SubjectPublicKeyInfo digests */
 
143
    struct TLS_TLSA *next;              /* Chain to next algorithm */
 
144
} TLS_TLSA;
 
145
 
 
146
 /*
 
147
  * Linked list of full X509 trust-anchor certs.
 
148
  */
 
149
typedef struct TLS_CERTS {
 
150
    X509   *cert;
 
151
    struct TLS_CERTS *next;
 
152
} TLS_CERTS;
 
153
 
 
154
 /*
 
155
  * Linked list of full EVP_PKEY trust-anchor public keys.
 
156
  */
 
157
typedef struct TLS_PKEYS {
 
158
    EVP_PKEY *pkey;
 
159
    struct TLS_PKEYS *next;
 
160
} TLS_PKEYS;
 
161
 
 
162
typedef struct TLS_DANE {
 
163
    TLS_TLSA *ta;                       /* Trust-anchor cert/pubkey digests */
 
164
    TLS_TLSA *ee;                       /* End-entity cert/pubkey digests */
 
165
    TLS_CERTS *certs;                   /* Full trust-anchor certificates */
 
166
    TLS_PKEYS *pkeys;                   /* Full trust-anchor public keys */
 
167
    char   *base_domain;                /* Base domain of TLSA RRset */
 
168
    int     flags;                      /* Conflate cert and pkey digests */
 
169
    time_t  expires;                    /* Expiration time of this record */
 
170
    int     refs;                       /* Reference count */
 
171
} TLS_DANE;
 
172
 
 
173
#define TLS_DANE_HASTA(d)       ((d) ? (d)->ta : 0)
 
174
#define TLS_DANE_HASEE(d)       ((d) ? (d)->ee : 0)
 
175
 
 
176
 /*
 
177
  * tls_dane.c
 
178
  */
 
179
extern int tls_dane_avail(void);
 
180
extern void tls_dane_flush(void);
 
181
extern void tls_dane_verbose(int);
 
182
extern TLS_DANE *tls_dane_alloc(void);
 
183
extern void tls_dane_add_ee_digests(TLS_DANE *, const char *, const char *,
 
184
                                            const char *);
 
185
extern void tls_dane_free(TLS_DANE *);
 
186
extern TLS_DANE *tls_dane_resolve(unsigned, const char *, DNS_RR *, int);
 
187
extern int tls_dane_load_trustfile(TLS_DANE *, const char *);
 
188
 
 
189
 /*
74
190
  * TLS session context, also used by the VSTREAM call-back routines for SMTP
75
191
  * input/output, and by OpenSSL call-back routines for key verification.
76
192
  * 
82
198
    /* Public, read-only. */
83
199
    char   *peer_CN;                    /* Peer Common Name */
84
200
    char   *issuer_CN;                  /* Issuer Common Name */
85
 
    char   *peer_fingerprint;           /* ASCII fingerprint */
 
201
    char   *peer_cert_fprint;           /* ASCII certificate fingerprint */
86
202
    char   *peer_pkey_fprint;           /* ASCII public key fingerprint */
87
203
    int     peer_status;                /* Certificate and match status */
88
204
    const char *protocol;
92
208
    /* Private. */
93
209
    SSL    *con;
94
210
    char   *cache_type;                 /* tlsmgr(8) cache type if enabled */
 
211
    int     ticketed;                   /* Session ticket issued */
95
212
    char   *serverid;                   /* unique server identifier */
96
213
    char   *namaddr;                    /* nam[addr] for logging */
97
214
    int     log_mask;                   /* What to log */
98
215
    int     session_reused;             /* this session was reused */
99
216
    int     am_server;                  /* Are we an SSL server or client? */
 
217
    const char *mdalg;                  /* default message digest algorithm */
100
218
    /* Built-in vs external SSL_accept/read/write/shutdown support. */
101
 
    char   *fpt_dgst;                   /* Certificate fingerprint digest */
102
219
    VSTREAM *stream;                    /* Blocking-mode SMTP session */
 
220
    /* RFC 6698 DANE trust input and verification state */
 
221
    const TLS_DANE *dane;               /* DANE TLSA digests */
 
222
    int     errordepth;                 /* Chain depth of error cert */
 
223
    int     tadepth;                    /* Chain depth of trust anchor */
 
224
    int     errorcode;                  /* First error at error depth */
 
225
    X509   *errorcert;                  /* Error certificate closest to leaf */
 
226
    x509_stack_t *untrusted;            /* Certificate chain fodder */
 
227
    x509_stack_t *trusted;              /* Internal root CA list */
103
228
} TLS_SESS_STATE;
104
229
 
105
230
 /*
141
266
#define TLS_LOG_DEBUG                   (1<<7)
142
267
#define TLS_LOG_TLSPKTS                 (1<<8)
143
268
#define TLS_LOG_ALLPKTS                 (1<<9)
 
269
#define TLS_LOG_SESSTKT                 (1<<10)
144
270
 
145
271
 /*
146
272
  * Client and Server application contexts
156
282
};
157
283
 
158
284
 /*
159
 
  * tls_misc.c One time finalization of application context.
 
285
  * tls_misc.c Application-context update and disposal.
160
286
  */
 
287
extern void tls_update_app_logmask(TLS_APPL_STATE *, int);
161
288
extern void tls_free_app_context(TLS_APPL_STATE *);
162
289
 
163
290
 /*
187
314
#undef  SSL_OP_NO_TLSv1_2
188
315
#define SSL_OP_NO_TLSv1_2       0L      /* Noop */
189
316
#endif
190
 
#define TLS_KNOWN_PROTOCOLS     \
 
317
#define TLS_KNOWN_PROTOCOLS \
191
318
        ( TLS_PROTOCOL_SSLv2 | TLS_PROTOCOL_SSLv3 | TLS_PROTOCOL_TLSv1 \
192
319
           | TLS_PROTOCOL_TLSv1_1 | TLS_PROTOCOL_TLSv1_2 )
 
320
#define TLS_SSL_OP_PROTOMASK(m) \
 
321
            ((((m) & TLS_PROTOCOL_SSLv2) ? SSL_OP_NO_SSLv2 : 0L) \
 
322
             | (((m) & TLS_PROTOCOL_SSLv3) ? SSL_OP_NO_SSLv3 : 0L) \
 
323
             | (((m) & TLS_PROTOCOL_TLSv1) ? SSL_OP_NO_TLSv1 : 0L) \
 
324
             | (((m) & TLS_PROTOCOL_TLSv1_1) ? SSL_OP_NO_TLSv1_1 : 0L) \
 
325
             | (((m) & TLS_PROTOCOL_TLSv1_2) ? SSL_OP_NO_TLSv1_2 : 0L))
 
326
 
 
327
/*
 
328
 * SSL options that are managed via dedicated Postfix features, rather than
 
329
 * just exposed via hex codes or named elements of tls_ssl_options.
 
330
 */
 
331
#define TLS_SSL_OP_MANAGED_BITS \
 
332
        (SSL_OP_CIPHER_SERVER_PREFERENCE | TLS_SSL_OP_PROTOMASK(~0))
193
333
 
194
334
extern int tls_protocol_mask(const char *);
195
335
 
234
374
    const char *eckey_file;
235
375
    const char *CAfile;
236
376
    const char *CApath;
237
 
    const char *fpt_dgst;               /* Fingerprint digest algorithm */
 
377
    const char *mdalg;                  /* default message digest algorithm */
238
378
} TLS_CLIENT_INIT_PROPS;
239
379
 
240
380
typedef struct {
246
386
    const char *host;                   /* MX hostname */
247
387
    const char *namaddr;                /* nam[addr] for logging */
248
388
    const char *serverid;               /* Session cache key */
 
389
    const char *helo;                   /* Server name from EHLO response */
249
390
    const char *protocols;              /* Enabled protocols */
250
391
    const char *cipher_grade;           /* Minimum cipher grade */
251
392
    const char *cipher_exclusions;      /* Ciphers to exclude */
252
393
    const ARGV *matchargv;              /* Cert match patterns */
253
 
    const char *fpt_dgst;               /* Fingerprint digest algorithm */
 
394
    const char *mdalg;                  /* default message digest algorithm */
 
395
    const TLS_DANE *dane;               /* RFC 6698 verification */
254
396
} TLS_CLIENT_START_PROPS;
255
397
 
256
398
extern TLS_APPL_STATE *tls_client_init(const TLS_CLIENT_INIT_PROPS *);
267
409
    ((props)->a12), ((props)->a13), (props)))
268
410
 
269
411
#define TLS_CLIENT_START(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, \
270
 
    a10, a11, a12, a13) \
 
412
    a10, a11, a12, a13, a14, a15) \
271
413
    tls_client_start((((props)->a1), ((props)->a2), ((props)->a3), \
272
414
    ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
273
415
    ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
274
 
    ((props)->a12), ((props)->a13), (props)))
 
416
    ((props)->a12), ((props)->a13), ((props)->a14), ((props)->a15), (props)))
275
417
 
276
418
 /*
277
419
  * tls_server.c
281
423
    const char *log_level;
282
424
    int     verifydepth;
283
425
    const char *cache_type;
284
 
    long    scache_timeout;
285
426
    int     set_sessid;
286
427
    const char *cert_file;
287
428
    const char *key_file;
296
437
    const char *dh1024_param_file;
297
438
    const char *dh512_param_file;
298
439
    int     ask_ccert;
299
 
    const char *fpt_dgst;               /* Fingerprint digest algorithm */
 
440
    const char *mdalg;                  /* default message digest algorithm */
300
441
} TLS_SERVER_INIT_PROPS;
301
442
 
302
443
typedef struct {
309
450
    const char *namaddr;                /* Client nam[addr] for logging */
310
451
    const char *cipher_grade;
311
452
    const char *cipher_exclusions;
312
 
    const char *fpt_dgst;               /* Fingerprint digest algorithm */
 
453
    const char *mdalg;                  /* default message digest algorithm */
313
454
} TLS_SERVER_START_PROPS;
314
455
 
315
456
extern TLS_APPL_STATE *tls_server_init(const TLS_SERVER_INIT_PROPS *);
320
461
        tls_session_stop(ctx, (stream), (timeout), (failure), (TLScontext))
321
462
 
322
463
#define TLS_SERVER_INIT(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, \
323
 
    a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) \
 
464
    a10, a11, a12, a13, a14, a15, a16, a17, a18, a19) \
324
465
    tls_server_init((((props)->a1), ((props)->a2), ((props)->a3), \
325
466
    ((props)->a4), ((props)->a5), ((props)->a6), ((props)->a7), \
326
467
    ((props)->a8), ((props)->a9), ((props)->a10), ((props)->a11), \
327
468
    ((props)->a12), ((props)->a13), ((props)->a14), ((props)->a15), \
328
 
    ((props)->a16), ((props)->a17), ((props)->a18), ((props)->a19), \
329
 
    ((props)->a20), (props)))
 
469
    ((props)->a16), ((props)->a17), ((props)->a18), ((props)->a19), (props)))
330
470
 
331
471
#define TLS_SERVER_START(props, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
332
472
    tls_server_start((((props)->a1), ((props)->a2), ((props)->a3), \
397
537
extern char *tls_peer_CN(X509 *, const TLS_SESS_STATE *);
398
538
extern char *tls_issuer_CN(X509 *, const TLS_SESS_STATE *);
399
539
extern const char *tls_dns_name(const GENERAL_NAME *, const TLS_SESS_STATE *);
400
 
extern char *tls_fingerprint(X509 *, const char *);
 
540
extern int tls_verify_certificate_callback(int, X509_STORE_CTX *);
 
541
extern void tls_log_verify_error(TLS_SESS_STATE *);
 
542
 
 
543
 /*
 
544
  * tls_dane.c
 
545
  */
 
546
extern int tls_dane_match(TLS_SESS_STATE *, int, X509 *, int);
 
547
extern void tls_dane_set_callback(SSL_CTX *, TLS_SESS_STATE *);
 
548
 
 
549
 /*
 
550
  * tls_fprint.c
 
551
  */
 
552
extern char *tls_digest_encode(const unsigned char *, int);
 
553
extern char *tls_data_fprint(const char *, int, const char *);
 
554
extern char *tls_cert_fprint(X509 *, const char *);
401
555
extern char *tls_pkey_fprint(X509 *, const char *);
402
 
extern int tls_verify_certificate_callback(int, X509_STORE_CTX *);
 
556
extern char *tls_serverid_digest(const TLS_CLIENT_START_PROPS *, long,
 
557
                                         const char *);
403
558
 
404
559
 /*
405
560
  * tls_certkey.c
423
578
extern void tls_print_errors(void);
424
579
extern void tls_info_callback(const SSL *, int, int);
425
580
extern long tls_bio_dump_cb(BIO *, int, const char *, int, long, long);
 
581
extern int tls_validate_digest(const char *);
426
582
 
427
583
 /*
428
584
  * tls_seed.c