~ubuntu-branches/ubuntu/raring/postfix/raring

« back to all changes in this revision

Viewing changes to src/tls/tls.h

Tags: upstream-2.2.6
ImportĀ upstreamĀ versionĀ 2.2.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  * OpenSSL library.
 
16
  */
 
17
#include <openssl/lhash.h>
 
18
#include <openssl/bn.h>
 
19
#include <openssl/err.h>
 
20
#include <openssl/pem.h>
 
21
#include <openssl/x509.h>
 
22
#include <openssl/x509v3.h>
 
23
#include <openssl/rand.h>
 
24
#include <openssl/ssl.h>
 
25
 
 
26
#if (OPENSSL_VERSION_NUMBER < 0x00905100L)
 
27
#error "need OpenSSL version 0.9.5 or later"
 
28
#endif
 
29
 
 
30
 /*
 
31
  * Utility library.
 
32
  */
 
33
#include <vstream.h>
 
34
 
 
35
 /*
 
36
  * TLS session context, also used by the VSTREAM call-back routines for SMTP
 
37
  * input/output, and by OpenSSL call-back routines for key verification.
 
38
  * 
 
39
  * XXX Eliminate fixed-length buffers where possible.
 
40
  * 
 
41
  * XXX Eliminate the tls_info structure; it is no longer needed now that the
 
42
  * TLScontext structure is exposed to the caller. If the caller's TLScontext
 
43
  * pointer is null, there is no TLS session. This change (plus other
 
44
  * changes) eliminated global variables that were shared between TLS client
 
45
  * and server code. Multiple clients and/or servers can now co-exist in the
 
46
  * same process.
 
47
  */
 
48
#define CCERT_BUFSIZ    256
 
49
#define HOST_BUFSIZ  255                /* RFC 1035 */
 
50
 
 
51
typedef struct {
 
52
    SSL    *con;
 
53
    BIO    *internal_bio;               /* postfix/TLS side of pair */
 
54
    BIO    *network_bio;                /* network side of pair */
 
55
    char   *serverid;                   /* unique server identifier */
 
56
    char    peer_subject[CCERT_BUFSIZ];
 
57
    char    peer_issuer[CCERT_BUFSIZ];
 
58
    char    peer_CN[CCERT_BUFSIZ];
 
59
    char    issuer_CN[CCERT_BUFSIZ];
 
60
    unsigned char md[EVP_MAX_MD_SIZE];
 
61
    char    fingerprint[EVP_MAX_MD_SIZE * 3];
 
62
    char    peername_save[HOST_BUFSIZ + 1];
 
63
    int     enforce_verify_errors;
 
64
    int     enforce_CN;
 
65
    int     hostname_matched;
 
66
    int     log_level;
 
67
} TLScontext_t;
 
68
 
 
69
#define TLS_BIO_BUFSIZE 8192
 
70
 
 
71
#define NEW_TLS_CONTEXT(p) do { \
 
72
        p = (TLScontext_t *) mymalloc(sizeof(*p)); \
 
73
        memset((char *) p, 0, sizeof(*p)); \
 
74
        p->serverid = 0; \
 
75
    } while (0)
 
76
    
 
77
#define FREE_TLS_CONTEXT(p) do { \
 
78
        if ((p)->serverid) \
 
79
            myfree((p)->serverid); \
 
80
        myfree((char *) (p)); \
 
81
    } while (0)
 
82
 
 
83
typedef struct {
 
84
    int     peer_verified;
 
85
    int     hostname_matched;
 
86
    char   *peer_subject;
 
87
    char   *peer_issuer;
 
88
    char   *peer_fingerprint;
 
89
    char   *peer_CN;
 
90
    char   *issuer_CN;
 
91
    const char *protocol;
 
92
    const char *cipher_name;
 
93
    int     cipher_usebits;
 
94
    int     cipher_algbits;
 
95
} tls_info_t;
 
96
 
 
97
extern const tls_info_t tls_info_zero;
 
98
 
 
99
 /*
 
100
  * tls_client.c
 
101
  */
 
102
extern SSL_CTX *tls_client_init(int);
 
103
extern TLScontext_t *tls_client_start(SSL_CTX *, VSTREAM *, int, int,
 
104
                                              const char *, const char *,
 
105
                                              tls_info_t *);
 
106
 
 
107
#define tls_client_stop(ctx , stream, timeout, failure, tls_info) \
 
108
        tls_session_stop((ctx), (stream), (timeout), (failure), (tls_info))
 
109
 
 
110
 /*
 
111
  * tls_server.c
 
112
  */
 
113
extern SSL_CTX *tls_server_init(int, int);
 
114
extern TLScontext_t *tls_server_start(SSL_CTX *, VSTREAM *, int,
 
115
                                              const char *, const char *,
 
116
                                              tls_info_t *, int);
 
117
 
 
118
#define tls_server_stop(ctx , stream, timeout, failure, tls_info) \
 
119
        tls_session_stop((ctx), (stream), (timeout), (failure), (tls_info))
 
120
 
 
121
 /*
 
122
  * tls_session.c
 
123
  */
 
124
extern void tls_session_stop(SSL_CTX *, VSTREAM *, int, int, tls_info_t *);
 
125
 
 
126
#ifdef TLS_INTERNAL
 
127
 
 
128
#include <vstring.h>
 
129
 
 
130
extern VSTRING *tls_session_passivate(SSL_SESSION *);
 
131
extern SSL_SESSION *tls_session_activate(char *, int);
 
132
 
 
133
 /*
 
134
  * tls_stream.c.
 
135
  */
 
136
extern void tls_stream_start(VSTREAM *, TLScontext_t *);
 
137
extern void tls_stream_stop(VSTREAM *);
 
138
 
 
139
 /*
 
140
  * tls_bio_ops.c: a generic multi-personality driver that retries SSL
 
141
  * operations until they are satisfied or until a hard error happens.
 
142
  * Because of its ugly multi-personality user interface we invoke it via
 
143
  * not-so-ugly single-personality wrappers.
 
144
  */
 
145
extern int tls_bio(int, int, TLScontext_t *,
 
146
                           int (*) (SSL *),     /* handshake */
 
147
                           int (*) (SSL *, void *, int),        /* read */
 
148
                           int (*) (SSL *, const void *, int),  /* write */
 
149
                           void *, int);
 
150
 
 
151
#define tls_bio_connect(fd, timeout, context) \
 
152
        tls_bio((fd), (timeout), (context), SSL_connect, \
 
153
                NULL, NULL, NULL, 0)
 
154
#define tls_bio_accept(fd, timeout, context) \
 
155
        tls_bio((fd), (timeout), (context), SSL_accept, \
 
156
                NULL, NULL, NULL, 0)
 
157
#define tls_bio_shutdown(fd, timeout, context) \
 
158
        tls_bio((fd), (timeout), (context), SSL_shutdown, \
 
159
                NULL, NULL, NULL, 0)
 
160
#define tls_bio_read(fd, buf, len, timeout, context) \
 
161
        tls_bio((fd), (timeout), (context), NULL, \
 
162
                SSL_read, NULL, (buf), (len))
 
163
#define tls_bio_write(fd, buf, len, timeout, context) \
 
164
        tls_bio((fd), (timeout), (context), NULL, \
 
165
                NULL, SSL_write, (buf), (len))
 
166
 
 
167
 /*
 
168
  * tls_dh.c
 
169
  */
 
170
extern void tls_set_dh_1024_from_file(const char *);
 
171
extern void tls_set_dh_512_from_file(const char *);
 
172
extern DH *tls_tmp_dh_cb(SSL *, int, int);
 
173
 
 
174
 /*
 
175
  * tls_rsa.c
 
176
  */
 
177
extern RSA *tls_tmp_rsa_cb(SSL *, int, int);
 
178
 
 
179
 /*
 
180
  * tls_verify.c
 
181
  */
 
182
extern int tls_verify_certificate_callback(int, X509_STORE_CTX *, int);
 
183
 
 
184
#define TLS_VERIFY_DEFAULT      (0)
 
185
#define TLS_VERIFY_PEERNAME     (1<<0)
 
186
 
 
187
 /*
 
188
  * tls_certkey.c
 
189
  */
 
190
extern int tls_set_ca_certificate_info(SSL_CTX *, const char *, const char *);
 
191
extern int tls_set_my_certificate_key_info(SSL_CTX *, const char *,
 
192
                                                   const char *,
 
193
                                                   const char *,
 
194
                                                   const char *);
 
195
 
 
196
 /*
 
197
  * tls_misc.c
 
198
  */
 
199
extern int TLScontext_index;
 
200
 
 
201
extern void tls_print_errors(void);
 
202
extern void tls_info_callback(const SSL *, int, int);
 
203
extern long tls_bio_dump_cb(BIO *, int, const char *, int, long, long);
 
204
 
 
205
 /*
 
206
  * tls_seed.c
 
207
  */
 
208
extern void tls_int_seed(void);
 
209
extern int tls_ext_seed(int);
 
210
 
 
211
 /*
 
212
  * tls_temp.c, code that is going away.
 
213
  */
 
214
#endif                                  /* TLS_INTERNAL */
 
215
 
 
216
/* LICENSE
 
217
/* .ad
 
218
/* .fi
 
219
/*      The Secure Mailer license must be distributed with this software.
 
220
/* AUTHOR(S)
 
221
/*      Wietse Venema
 
222
/*      IBM T.J. Watson Research
 
223
/*      P.O. Box 704
 
224
/*      Yorktown Heights, NY 10598, USA
 
225
/*--*/
 
226
 
 
227
#endif                                  /* _TLS_H_INCLUDED_ */