Mercurial > dovecot > original-hg > dovecot-1.2
annotate src/login-common/ssl-proxy-openssl.c @ 8224:7ac86b33ad64 HEAD
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 05 Oct 2008 00:33:05 +0300 |
parents | 3917bf9cf311 |
children | 0db37acdc59f |
rev | line source |
---|---|
7086
7ed926ed7aa4
Updated copyright notices to include year 2008.
Timo Sirainen <tss@iki.fi>
parents:
6495
diff
changeset
|
1 /* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */ |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
2 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
3 #include "common.h" |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
4 #include "array.h" |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
5 #include "ioloop.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
6 #include "network.h" |
4474
1ff1603403de
Second try with SSL proxy rewrite. Did some fixes since last try.
Timo Sirainen <tss@iki.fi>
parents:
4471
diff
changeset
|
7 #include "ostream.h" |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
8 #include "read-full.h" |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
9 #include "llist.h" |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
10 #include "ssl-proxy.h" |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
11 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
12 #include <fcntl.h> |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
13 #include <unistd.h> |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
14 #include <sys/stat.h> |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
15 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
16 #ifdef HAVE_OPENSSL |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
17 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
18 #include <openssl/crypto.h> |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
19 #include <openssl/x509.h> |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
20 #include <openssl/pem.h> |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
21 #include <openssl/ssl.h> |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
22 #include <openssl/err.h> |
1556
545f6b150e2c
Make sure PRNG gets initialized before chrooting so it can open /dev/urandom.
Timo Sirainen <tss@iki.fi>
parents:
1544
diff
changeset
|
23 #include <openssl/rand.h> |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
24 |
4696 | 25 #define DOVECOT_SSL_DEFAULT_CIPHER_LIST "ALL:!LOW:!SSLv2" |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
26 /* Check every 30 minutes if parameters file has been updated */ |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
27 #define SSL_PARAMFILE_CHECK_INTERVAL (60*30) |
1544
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
28 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
29 enum ssl_io_action { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
30 SSL_ADD_INPUT, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
31 SSL_REMOVE_INPUT, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
32 SSL_ADD_OUTPUT, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
33 SSL_REMOVE_OUTPUT |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
34 }; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
35 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
36 struct ssl_proxy { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
37 int refcount; |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
38 struct ssl_proxy *prev, *next; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
39 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
40 SSL *ssl; |
1235 | 41 struct ip_addr ip; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
42 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
43 int fd_ssl, fd_plain; |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
44 struct io *io_ssl_read, *io_ssl_write, *io_plain_read, *io_plain_write; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
45 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
46 unsigned char plainout_buf[1024]; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
47 unsigned int plainout_size; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
48 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
49 unsigned char sslout_buf[1024]; |
1324
13d8f69d4f1a
rewrite, maybe it works properly now.
Timo Sirainen <tss@iki.fi>
parents:
1268
diff
changeset
|
50 unsigned int sslout_size; |
1458
98362534b2c7
Unexpected SSL connection errors sometimes crashed
Timo Sirainen <tss@iki.fi>
parents:
1457
diff
changeset
|
51 |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
52 char *last_error; |
1458
98362534b2c7
Unexpected SSL connection errors sometimes crashed
Timo Sirainen <tss@iki.fi>
parents:
1457
diff
changeset
|
53 unsigned int handshaked:1; |
98362534b2c7
Unexpected SSL connection errors sometimes crashed
Timo Sirainen <tss@iki.fi>
parents:
1457
diff
changeset
|
54 unsigned int destroyed:1; |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
55 unsigned int cert_received:1; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
56 unsigned int cert_broken:1; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
57 }; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
58 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
59 struct ssl_parameters { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
60 const char *fname; |
4505
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
61 time_t last_mtime, last_check; |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
62 int fd; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
63 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
64 DH *dh_512, *dh_1024; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
65 }; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
66 |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
67 static int extdata_index; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
68 static SSL_CTX *ssl_ctx; |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
69 static unsigned int ssl_proxy_count; |
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
70 static struct ssl_proxy *ssl_proxies; |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
71 static struct ssl_parameters ssl_params; |
6364
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
72 static int ssl_username_nid; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
73 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4827
diff
changeset
|
74 static void plain_read(struct ssl_proxy *proxy); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
75 static void ssl_read(struct ssl_proxy *proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
76 static void ssl_write(struct ssl_proxy *proxy); |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4827
diff
changeset
|
77 static void ssl_step(struct ssl_proxy *proxy); |
1458
98362534b2c7
Unexpected SSL connection errors sometimes crashed
Timo Sirainen <tss@iki.fi>
parents:
1457
diff
changeset
|
78 static void ssl_proxy_destroy(struct ssl_proxy *proxy); |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3635
diff
changeset
|
79 static void ssl_proxy_unref(struct ssl_proxy *proxy); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
80 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
81 static void read_next(struct ssl_parameters *params, void *data, size_t size) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
82 { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
83 int ret; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
84 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
85 if ((ret = read_full(params->fd, data, size)) < 0) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
86 i_fatal("read(%s) failed: %m", params->fname); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
87 if (ret == 0) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
88 i_fatal("read(%s) failed: Unexpected EOF", params->fname); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
89 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
90 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
91 static bool read_dh_parameters_next(struct ssl_parameters *params) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
92 { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
93 unsigned char *buf; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
94 const unsigned char *cbuf; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
95 unsigned int len; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
96 int bits; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
97 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
98 /* read bit size. 0 ends the DH parameters list. */ |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
99 read_next(params, &bits, sizeof(bits)); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
100 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
101 if (bits == 0) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
102 return FALSE; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
103 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
104 /* read data size. */ |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
105 read_next(params, &len, sizeof(len)); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
106 if (len > 1024*100) /* should be enough? */ |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
107 i_fatal("Corrupted SSL parameters file: %s", params->fname); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
108 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
109 buf = i_malloc(len); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
110 read_next(params, buf, len); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
111 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
112 cbuf = buf; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
113 switch (bits) { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
114 case 512: |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
115 params->dh_512 = d2i_DHparams(NULL, &cbuf, len); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
116 break; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
117 case 1024: |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
118 params->dh_1024 = d2i_DHparams(NULL, &cbuf, len); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
119 break; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
120 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
121 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
122 i_free(buf); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
123 return TRUE; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
124 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
125 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
126 static void ssl_free_parameters(struct ssl_parameters *params) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
127 { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
128 if (params->dh_512 != NULL) { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
129 DH_free(params->dh_512); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
130 params->dh_512 = NULL; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
131 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
132 if (params->dh_1024 != NULL) { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
133 DH_free(params->dh_1024); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
134 params->dh_1024 = NULL; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
135 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
136 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
137 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
138 static void ssl_read_parameters(struct ssl_parameters *params) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
139 { |
4505
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
140 struct stat st; |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
141 bool warned = FALSE; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
142 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
143 /* we'll wait until parameter file exists */ |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
144 for (;;) { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
145 params->fd = open(params->fname, O_RDONLY); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
146 if (params->fd != -1) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
147 break; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
148 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
149 if (errno != ENOENT) { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
150 i_fatal("Can't open SSL parameter file %s: %m", |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
151 params->fname); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
152 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
153 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
154 if (!warned) { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
155 i_warning("Waiting for SSL parameter file %s", |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
156 params->fname); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
157 warned = TRUE; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
158 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
159 sleep(1); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
160 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
161 |
4505
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
162 if (fstat(params->fd, &st) < 0) |
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
163 i_error("fstat(%s) failed: %m", params->fname); |
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
164 else |
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
165 params->last_mtime = st.st_mtime; |
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
166 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
167 ssl_free_parameters(params); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
168 while (read_dh_parameters_next(params)) ; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
169 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
170 if (close(params->fd) < 0) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
171 i_error("close() failed: %m"); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
172 params->fd = -1; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
173 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
174 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
175 static void ssl_refresh_parameters(struct ssl_parameters *params) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
176 { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
177 struct stat st; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
178 |
4505
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
179 if (params->last_check > ioloop_time - SSL_PARAMFILE_CHECK_INTERVAL) |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
180 return; |
4505
886d7af1f38d
Don't constantly re-read ssl-parameters.dat. Make sure that in input handler
Timo Sirainen <tss@iki.fi>
parents:
4474
diff
changeset
|
181 params->last_check = ioloop_time; |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
182 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
183 if (params->last_mtime == 0) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
184 ssl_read_parameters(params); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
185 else { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
186 if (stat(params->fname, &st) < 0) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
187 i_error("stat(%s) failed: %m", params->fname); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
188 else if (st.st_mtime != params->last_mtime) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
189 ssl_read_parameters(params); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
190 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
191 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
192 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
193 static void ssl_set_io(struct ssl_proxy *proxy, enum ssl_io_action action) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
194 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
195 switch (action) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
196 case SSL_ADD_INPUT: |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
197 if (proxy->io_ssl_read != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
198 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
199 proxy->io_ssl_read = io_add(proxy->fd_ssl, IO_READ, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
200 ssl_step, proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
201 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
202 case SSL_REMOVE_INPUT: |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
203 if (proxy->io_ssl_read != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
204 io_remove(&proxy->io_ssl_read); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
205 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
206 case SSL_ADD_OUTPUT: |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
207 if (proxy->io_ssl_write != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
208 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
209 proxy->io_ssl_write = io_add(proxy->fd_ssl, IO_WRITE, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
210 ssl_step, proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
211 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
212 case SSL_REMOVE_OUTPUT: |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
213 if (proxy->io_ssl_write != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
214 io_remove(&proxy->io_ssl_write); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
215 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
216 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
217 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
218 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
219 static void plain_block_input(struct ssl_proxy *proxy, bool block) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
220 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
221 if (block) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
222 if (proxy->io_plain_read != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
223 io_remove(&proxy->io_plain_read); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
224 } else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
225 if (proxy->io_plain_read == NULL) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
226 proxy->io_plain_read = io_add(proxy->fd_plain, IO_READ, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
227 plain_read, proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
228 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
229 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
230 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
231 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4827
diff
changeset
|
232 static void plain_read(struct ssl_proxy *proxy) |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
233 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
234 ssize_t ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
235 bool corked = FALSE; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
236 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
237 if (proxy->sslout_size == sizeof(proxy->sslout_buf)) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
238 /* buffer full, block input until it's written */ |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
239 plain_block_input(proxy, TRUE); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
240 return; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
241 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
242 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
243 proxy->refcount++; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
244 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
245 while (proxy->sslout_size < sizeof(proxy->sslout_buf) && |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
246 !proxy->destroyed) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
247 ret = net_receive(proxy->fd_plain, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
248 proxy->sslout_buf + proxy->sslout_size, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
249 sizeof(proxy->sslout_buf) - |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
250 proxy->sslout_size); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
251 if (ret <= 0) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
252 if (ret < 0) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
253 ssl_proxy_destroy(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
254 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
255 } else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
256 proxy->sslout_size += ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
257 if (!corked) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
258 net_set_cork(proxy->fd_ssl, TRUE); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
259 corked = TRUE; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
260 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
261 ssl_write(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
262 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
263 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
264 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
265 if (corked) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
266 net_set_cork(proxy->fd_ssl, FALSE); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
267 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
268 ssl_proxy_unref(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
269 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
270 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4827
diff
changeset
|
271 static void plain_write(struct ssl_proxy *proxy) |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
272 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
273 ssize_t ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
274 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
275 proxy->refcount++; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
276 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
277 ret = net_transmit(proxy->fd_plain, proxy->plainout_buf, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
278 proxy->plainout_size); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
279 if (ret < 0) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
280 ssl_proxy_destroy(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
281 else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
282 proxy->plainout_size -= ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
283 memmove(proxy->plainout_buf, proxy->plainout_buf + ret, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
284 proxy->plainout_size); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
285 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
286 if (proxy->plainout_size > 0) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
287 if (proxy->io_plain_write == NULL) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
288 proxy->io_plain_write = |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
289 io_add(proxy->fd_plain, IO_WRITE, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
290 plain_write, proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
291 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
292 } else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
293 if (proxy->io_plain_write != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
294 io_remove(&proxy->io_plain_write); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
295 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
296 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
297 ssl_set_io(proxy, SSL_ADD_INPUT); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
298 if (SSL_pending(proxy->ssl) > 0) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
299 ssl_read(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
300 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
301 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
302 ssl_proxy_unref(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
303 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
304 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
305 static const char *ssl_last_error(void) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
306 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
307 unsigned long err; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
308 char *buf; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
309 size_t err_size = 256; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
310 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
311 err = ERR_get_error(); |
7508
bec3cd8e8151
If SSL function fails and there are no errors, return "Unknown error"
Timo Sirainen <tss@iki.fi>
parents:
7500
diff
changeset
|
312 if (err == 0) { |
bec3cd8e8151
If SSL function fails and there are no errors, return "Unknown error"
Timo Sirainen <tss@iki.fi>
parents:
7500
diff
changeset
|
313 if (errno != 0) |
bec3cd8e8151
If SSL function fails and there are no errors, return "Unknown error"
Timo Sirainen <tss@iki.fi>
parents:
7500
diff
changeset
|
314 return strerror(errno); |
bec3cd8e8151
If SSL function fails and there are no errors, return "Unknown error"
Timo Sirainen <tss@iki.fi>
parents:
7500
diff
changeset
|
315 return "Unknown error"; |
bec3cd8e8151
If SSL function fails and there are no errors, return "Unknown error"
Timo Sirainen <tss@iki.fi>
parents:
7500
diff
changeset
|
316 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
317 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
318 buf = t_malloc(err_size); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
319 buf[err_size-1] = '\0'; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
320 ERR_error_string_n(err, buf, err_size-1); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
321 return buf; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
322 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
323 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
324 static void ssl_handle_error(struct ssl_proxy *proxy, int ret, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
325 const char *func_name) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
326 { |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
327 const char *errstr = NULL; |
1235 | 328 int err; |
329 | |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
330 proxy->refcount++; |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
331 |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
332 i_free_and_null(proxy->last_error); |
1235 | 333 err = SSL_get_error(proxy->ssl, ret); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
334 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
335 switch (err) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
336 case SSL_ERROR_WANT_READ: |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
337 ssl_set_io(proxy, SSL_ADD_INPUT); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
338 break; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
339 case SSL_ERROR_WANT_WRITE: |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
340 ssl_set_io(proxy, SSL_ADD_OUTPUT); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
341 break; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
342 case SSL_ERROR_SYSCALL: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
343 /* eat up the error queue */ |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
344 if (ERR_peek_error() != 0) |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
345 errstr = ssl_last_error(); |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
346 else if (ret != 0) |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
347 errstr = strerror(errno); |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
348 else { |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
349 /* EOF. */ |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
350 errstr = "Disconnected"; |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
351 break; |
1235 | 352 } |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
353 errstr = t_strdup_printf("%s syscall failed: %s", |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
354 func_name, errstr); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
355 break; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
356 case SSL_ERROR_ZERO_RETURN: |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
357 /* clean connection closing */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
358 ssl_proxy_destroy(proxy); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
359 break; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
360 case SSL_ERROR_SSL: |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
361 errstr = t_strdup_printf("%s failed: %s", |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
362 func_name, ssl_last_error()); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
363 break; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
364 default: |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
365 errstr = t_strdup_printf("%s failed: unknown failure %d (%s)", |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
366 func_name, err, ssl_last_error()); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
367 break; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
368 } |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
369 |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
370 if (errstr != NULL) { |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
371 proxy->last_error = i_strdup(errstr); |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
372 ssl_proxy_destroy(proxy); |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
373 } |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
374 ssl_proxy_unref(proxy); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
375 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
376 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
377 static void ssl_handshake(struct ssl_proxy *proxy) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
378 { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
379 int ret; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
380 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
381 ret = SSL_accept(proxy->ssl); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
382 if (ret != 1) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
383 ssl_handle_error(proxy, ret, "SSL_accept()"); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
384 else { |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
385 i_free_and_null(proxy->last_error); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
386 proxy->handshaked = TRUE; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
387 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
388 ssl_set_io(proxy, SSL_ADD_INPUT); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
389 plain_block_input(proxy, FALSE); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
390 } |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
391 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
392 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
393 static void ssl_read(struct ssl_proxy *proxy) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
394 { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
395 int ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
396 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
397 while (proxy->plainout_size < sizeof(proxy->plainout_buf) && |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
398 !proxy->destroyed) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
399 ret = SSL_read(proxy->ssl, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
400 proxy->plainout_buf + proxy->plainout_size, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
401 sizeof(proxy->plainout_buf) - |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
402 proxy->plainout_size); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
403 if (ret <= 0) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
404 ssl_handle_error(proxy, ret, "SSL_read()"); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
405 break; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
406 } else { |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
407 i_free_and_null(proxy->last_error); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
408 proxy->plainout_size += ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
409 plain_write(proxy); |
4131 | 410 } |
4127
60583fb75d9e
Rewrite. Hopefully works better.
Timo Sirainen <tss@iki.fi>
parents:
3960
diff
changeset
|
411 } |
60583fb75d9e
Rewrite. Hopefully works better.
Timo Sirainen <tss@iki.fi>
parents:
3960
diff
changeset
|
412 } |
60583fb75d9e
Rewrite. Hopefully works better.
Timo Sirainen <tss@iki.fi>
parents:
3960
diff
changeset
|
413 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
414 static void ssl_write(struct ssl_proxy *proxy) |
4127
60583fb75d9e
Rewrite. Hopefully works better.
Timo Sirainen <tss@iki.fi>
parents:
3960
diff
changeset
|
415 { |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
416 int ret; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
417 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
418 ret = SSL_write(proxy->ssl, proxy->sslout_buf, proxy->sslout_size); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
419 if (ret <= 0) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
420 ssl_handle_error(proxy, ret, "SSL_write()"); |
4127
60583fb75d9e
Rewrite. Hopefully works better.
Timo Sirainen <tss@iki.fi>
parents:
3960
diff
changeset
|
421 else { |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
422 i_free_and_null(proxy->last_error); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
423 proxy->sslout_size -= ret; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
424 memmove(proxy->sslout_buf, proxy->sslout_buf + ret, |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
425 proxy->sslout_size); |
4474
1ff1603403de
Second try with SSL proxy rewrite. Did some fixes since last try.
Timo Sirainen <tss@iki.fi>
parents:
4471
diff
changeset
|
426 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
427 ssl_set_io(proxy, proxy->sslout_size > 0 ? |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
428 SSL_ADD_OUTPUT : SSL_REMOVE_OUTPUT); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
429 plain_block_input(proxy, FALSE); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
430 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
431 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
432 |
4907
5b4c9b20eba0
Replaced void *context from a lot of callbacks with the actual context
Timo Sirainen <tss@iki.fi>
parents:
4827
diff
changeset
|
433 static void ssl_step(struct ssl_proxy *proxy) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
434 { |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
435 proxy->refcount++; |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
436 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
437 if (!proxy->handshaked) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
438 ssl_handshake(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
439 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
440 if (proxy->handshaked) { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
441 if (proxy->plainout_size == sizeof(proxy->plainout_buf)) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
442 ssl_set_io(proxy, SSL_REMOVE_INPUT); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
443 else |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
444 ssl_read(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
445 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
446 if (proxy->sslout_size == 0) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
447 ssl_set_io(proxy, SSL_REMOVE_OUTPUT); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
448 else { |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
449 net_set_cork(proxy->fd_ssl, TRUE); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
450 ssl_write(proxy); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
451 net_set_cork(proxy->fd_ssl, FALSE); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
452 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
453 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
454 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
455 ssl_proxy_unref(proxy); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
456 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
457 |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
458 int ssl_proxy_new(int fd, struct ip_addr *ip, struct ssl_proxy **proxy_r) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
459 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
460 struct ssl_proxy *proxy; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
461 SSL *ssl; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
462 int sfd[2]; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
463 |
4664 | 464 i_assert(fd != -1); |
465 | |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
466 *proxy_r = NULL; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
467 |
2679
8f7b01c29bcb
Show clear error messages if --ssl is tried to be used but it's not
Timo Sirainen <tss@iki.fi>
parents:
2629
diff
changeset
|
468 if (!ssl_initialized) { |
8f7b01c29bcb
Show clear error messages if --ssl is tried to be used but it's not
Timo Sirainen <tss@iki.fi>
parents:
2629
diff
changeset
|
469 i_error("SSL support not enabled in configuration"); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
470 return -1; |
2679
8f7b01c29bcb
Show clear error messages if --ssl is tried to be used but it's not
Timo Sirainen <tss@iki.fi>
parents:
2629
diff
changeset
|
471 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
472 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
473 ssl_refresh_parameters(&ssl_params); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
474 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
475 ssl = SSL_new(ssl_ctx); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
476 if (ssl == NULL) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
477 i_error("SSL_new() failed: %s", ssl_last_error()); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
478 return -1; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
479 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
480 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
481 if (SSL_set_fd(ssl, fd) != 1) { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
482 i_error("SSL_set_fd() failed: %s", ssl_last_error()); |
1457 | 483 SSL_free(ssl); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
484 return -1; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
485 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
486 |
4664 | 487 if (socketpair(AF_UNIX, SOCK_STREAM, 0, sfd) < 0) { |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
488 i_error("socketpair() failed: %m"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
489 SSL_free(ssl); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
490 return -1; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
491 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
492 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
493 net_set_nonblock(sfd[0], TRUE); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
494 net_set_nonblock(sfd[1], TRUE); |
1268
0d9f0e617a1a
net_* functions don't anymore set sockets to non-blocking by default.
Timo Sirainen <tss@iki.fi>
parents:
1235
diff
changeset
|
495 net_set_nonblock(fd, TRUE); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
496 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
497 proxy = i_new(struct ssl_proxy, 1); |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
498 proxy->refcount = 2; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
499 proxy->ssl = ssl; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
500 proxy->fd_ssl = fd; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
501 proxy->fd_plain = sfd[0]; |
1235 | 502 proxy->ip = *ip; |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
503 SSL_set_ex_data(ssl, extdata_index, proxy); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
504 |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
505 ssl_proxy_count++; |
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
506 DLLIST_PREPEND(&ssl_proxies, proxy); |
1544
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
507 |
4827
966f7b3fb03c
Call ssl_step() at startup instead of ssl_handshake(). If the first input
Timo Sirainen <tss@iki.fi>
parents:
4783
diff
changeset
|
508 ssl_step(proxy); |
4474
1ff1603403de
Second try with SSL proxy rewrite. Did some fixes since last try.
Timo Sirainen <tss@iki.fi>
parents:
4471
diff
changeset
|
509 main_ref(); |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
510 |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
511 *proxy_r = proxy; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
512 return sfd[1]; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
513 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
514 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7508
diff
changeset
|
515 bool ssl_proxy_has_valid_client_cert(const struct ssl_proxy *proxy) |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
516 { |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
517 return proxy->cert_received && !proxy->cert_broken; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
518 } |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
519 |
3635
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
520 const char *ssl_proxy_get_peer_name(struct ssl_proxy *proxy) |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
521 { |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
522 X509 *x509; |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
523 char buf[1024]; |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
524 const char *name; |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
525 |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
526 if (!ssl_proxy_has_valid_client_cert(proxy)) |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
527 return NULL; |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
528 |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
529 x509 = SSL_get_peer_certificate(proxy->ssl); |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
530 if (x509 == NULL) |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
531 return NULL; /* we should have had it.. */ |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
532 |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
533 if (X509_NAME_get_text_by_NID(X509_get_subject_name(x509), |
6364
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
534 ssl_username_nid, buf, sizeof(buf)) < 0) |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
535 name = ""; |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
536 else |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
537 name = t_strndup(buf, sizeof(buf)); |
3635
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
538 X509_free(x509); |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
539 |
3635
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
540 return *name == '\0' ? NULL : name; |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
541 } |
c12df370e1b2
Added ssl_username_from_cert setting. Not actually tested yet..
Timo Sirainen <tss@iki.fi>
parents:
3584
diff
changeset
|
542 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7508
diff
changeset
|
543 bool ssl_proxy_is_handshaked(const struct ssl_proxy *proxy) |
4570
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
4549
diff
changeset
|
544 { |
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
4549
diff
changeset
|
545 return proxy->handshaked; |
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
4549
diff
changeset
|
546 } |
cbbe2377f591
If SSL/TLS handshake didn't finish, show "TLS handshaking" instead of "TLS"
Timo Sirainen <tss@iki.fi>
parents:
4549
diff
changeset
|
547 |
7912
81806d402514
Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents:
7508
diff
changeset
|
548 const char *ssl_proxy_get_last_error(const struct ssl_proxy *proxy) |
7374
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
549 { |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
550 return proxy->last_error; |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
551 } |
0bb3fc72a74f
If TLS connection closes with anything except a clean disconnection, log the
Timo Sirainen <tss@iki.fi>
parents:
7346
diff
changeset
|
552 |
8122
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
553 const char *ssl_proxy_get_security_string(struct ssl_proxy *proxy) |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
554 { |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
555 SSL_CIPHER *cipher; |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
556 int bits, alg_bits; |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
557 |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
558 if (!proxy->handshaked) |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
559 return ""; |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
560 |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
561 cipher = SSL_get_current_cipher(proxy->ssl); |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
562 bits = SSL_CIPHER_get_bits(cipher, &alg_bits); |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
563 return t_strdup_printf("%s with cipher %s (%d/%d bits)", |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
564 SSL_get_version(proxy->ssl), |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
565 SSL_CIPHER_get_name(cipher), |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
566 bits, alg_bits); |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
567 } |
3917bf9cf311
login_log_format_elements: Added %k to show SSL protocol/cipher information.
Timo Sirainen <tss@iki.fi>
parents:
7912
diff
changeset
|
568 |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
569 void ssl_proxy_free(struct ssl_proxy *proxy) |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
570 { |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
571 ssl_proxy_unref(proxy); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
572 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
573 |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3635
diff
changeset
|
574 static void ssl_proxy_unref(struct ssl_proxy *proxy) |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
575 { |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
576 if (--proxy->refcount > 0) |
3863
55df57c028d4
Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents:
3635
diff
changeset
|
577 return; |
1490 | 578 i_assert(proxy->refcount == 0); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
579 |
2302
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
580 SSL_free(proxy->ssl); |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
581 i_free(proxy); |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
582 |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
583 main_unref(); |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
584 } |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
585 |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
586 static void ssl_proxy_destroy(struct ssl_proxy *proxy) |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
587 { |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
588 if (proxy->destroyed) |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
589 return; |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
590 proxy->destroyed = TRUE; |
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
591 |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
592 ssl_proxy_count--; |
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
593 DLLIST_REMOVE(&ssl_proxies, proxy); |
1230
e6d2b8c78519
Keep list of the SSL proxies, so they're deinitialized properly if we have
Timo Sirainen <tss@iki.fi>
parents:
1215
diff
changeset
|
594 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
595 if (proxy->io_ssl_read != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
596 io_remove(&proxy->io_ssl_read); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
597 if (proxy->io_ssl_write != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
598 io_remove(&proxy->io_ssl_write); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
599 if (proxy->io_plain_read != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
600 io_remove(&proxy->io_plain_read); |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
601 if (proxy->io_plain_write != NULL) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
602 io_remove(&proxy->io_plain_write); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
603 |
7346 | 604 (void)SSL_shutdown(proxy->ssl); |
605 | |
3960
aeb424e64f24
Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
606 (void)net_disconnect(proxy->fd_ssl); |
aeb424e64f24
Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
607 (void)net_disconnect(proxy->fd_plain); |
aeb424e64f24
Call io_remove() before closing the fd. It's required by kqueue.
Timo Sirainen <tss@iki.fi>
parents:
3889
diff
changeset
|
608 |
2302
8438064ddf08
Refcounting fixes. Unexpectedly destroyed SSL connection could have left
Timo Sirainen <tss@iki.fi>
parents:
2027
diff
changeset
|
609 ssl_proxy_unref(proxy); |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
610 |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
611 main_listen_start(); |
1458
98362534b2c7
Unexpected SSL connection errors sometimes crashed
Timo Sirainen <tss@iki.fi>
parents:
1457
diff
changeset
|
612 } |
98362534b2c7
Unexpected SSL connection errors sometimes crashed
Timo Sirainen <tss@iki.fi>
parents:
1457
diff
changeset
|
613 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6364
diff
changeset
|
614 static RSA *ssl_gen_rsa_key(SSL *ssl ATTR_UNUSED, |
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6364
diff
changeset
|
615 int is_export ATTR_UNUSED, int keylength) |
1492
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
616 { |
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
617 return RSA_generate_key(keylength, RSA_F4, NULL, NULL); |
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
618 } |
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
619 |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6364
diff
changeset
|
620 static DH *ssl_tmp_dh_callback(SSL *ssl ATTR_UNUSED, |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
621 int is_export, int keylength) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
622 { |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
623 /* Well, I'm not exactly sure why the logic in here is this. |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
624 It's the same as in Postfix, so it can't be too wrong. */ |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
625 if (is_export && keylength == 512 && ssl_params.dh_512 != NULL) |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
626 return ssl_params.dh_512; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
627 |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
628 return ssl_params.dh_1024; |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
629 } |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
630 |
4471
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
631 static void ssl_info_callback(const SSL *ssl, int where, int ret) |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
632 { |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
633 struct ssl_proxy *proxy; |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
634 |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
635 proxy = SSL_get_ex_data(ssl, extdata_index); |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
636 |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
637 if ((where & SSL_CB_ALERT) != 0) { |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
638 i_warning("SSL alert: where=0x%x, ret=%d: %s %s [%s]", |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
639 where, ret, SSL_alert_type_string_long(ret), |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
640 SSL_alert_desc_string_long(ret), |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
641 net_ip2addr(&proxy->ip)); |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
642 } else { |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
643 i_warning("SSL BIO failed: where=0x%x, ret=%d: %s [%s]", |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
644 where, ret, SSL_state_string_long(ssl), |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
645 net_ip2addr(&proxy->ip)); |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
646 } |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
647 } |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
648 |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
649 static int ssl_verify_client_cert(int preverify_ok, X509_STORE_CTX *ctx) |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
650 { |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
651 SSL *ssl; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
652 struct ssl_proxy *proxy; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
653 |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
654 ssl = X509_STORE_CTX_get_ex_data(ctx, |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
655 SSL_get_ex_data_X509_STORE_CTX_idx()); |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
656 proxy = SSL_get_ex_data(ssl, extdata_index); |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
657 proxy->cert_received = TRUE; |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
658 |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
659 if (verbose_ssl || (verbose_auth && !preverify_ok)) { |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
660 char buf[1024]; |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
661 X509_NAME *subject; |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
662 |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
663 subject = X509_get_subject_name(ctx->current_cert); |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
664 (void)X509_NAME_oneline(subject, buf, sizeof(buf)); |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
665 buf[sizeof(buf)-1] = '\0'; /* just in case.. */ |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
666 if (!preverify_ok) |
4695
07afd19bc53e
Updates to ssl_ca_file and ssl_username_from_cert comments in
Timo Sirainen <tss@iki.fi>
parents:
4664
diff
changeset
|
667 i_info("Invalid certificate: %s: %s", X509_verify_cert_error_string(ctx->error),buf); |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
668 else |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
669 i_info("Valid certificate: %s", buf); |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
670 } |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
671 if (!preverify_ok) |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
672 proxy->cert_broken = TRUE; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
673 |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
674 /* Return success anyway, because if ssl_require_client_cert=no we |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
675 could still allow authentication. */ |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
676 return 1; |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
677 } |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
678 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
679 static int |
6411
6a64e64fa3a3
Renamed __attr_*__ to ATTR_*. Renamed __attrs_used__ to ATTRS_DEFINED.
Timo Sirainen <tss@iki.fi>
parents:
6364
diff
changeset
|
680 pem_password_callback(char *buf, int size, int rwflag ATTR_UNUSED, |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
681 void *userdata) |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
682 { |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
683 if (userdata == NULL) { |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
684 i_error("SSL private key file is password protected, " |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
685 "but password isn't given"); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
686 return 0; |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
687 } |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
688 |
6422
18173a52f721
Renamed strocpy() to i_strocpy().
Timo Sirainen <tss@iki.fi>
parents:
6417
diff
changeset
|
689 if (i_strocpy(buf, userdata, size) < 0) |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
690 return 0; |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
691 return strlen(buf); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
692 } |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
693 |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
694 unsigned int ssl_proxy_get_count(void) |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
695 { |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
696 return ssl_proxy_count; |
4538
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
697 } |
9d9e72374164
Fixes to login process handling, especially with
Timo Sirainen <tss@iki.fi>
parents:
4506
diff
changeset
|
698 |
5361
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
699 static void *ssl_clean_malloc(size_t size) |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
700 { |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
701 return p_malloc(system_clean_pool, size); |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
702 } |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
703 |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
704 static void *ssl_clean_realloc(void *ptr, size_t size) |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
705 { |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
706 return p_realloc(system_clean_pool, ptr, (size_t)-1, size); |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
707 } |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
708 |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
709 static void ssl_clean_free(void *ptr) |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
710 { |
6495
94501a17dcd0
Don't return void values from void functions.
Timo Sirainen <tss@iki.fi>
parents:
6475
diff
changeset
|
711 p_free(system_clean_pool, ptr); |
5361
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
712 } |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
713 |
8224
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
714 static bool is_pem_key_file(const char *path) |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
715 { |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
716 char buf[4096]; |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
717 int fd, ret; |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
718 |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
719 /* this code is used only for giving a better error message, |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
720 so it needs to catch only the normal key files */ |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
721 fd = open(path, O_RDONLY); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
722 if (fd == -1) |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
723 return FALSE; |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
724 ret = read(fd, buf, sizeof(buf)-1); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
725 close(fd); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
726 if (ret <= 0) |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
727 return FALSE; |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
728 buf[ret] = '\0'; |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
729 return strstr(buf, "PRIVATE KEY---") != NULL; |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
730 } |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
731 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
732 void ssl_proxy_init(void) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
733 { |
5335
79ea613496aa
Replace some string literals with non-const static buffers to avoid compiler
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
734 static char dovecot[] = "dovecot"; |
6364
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
735 const char *cafile, *certfile, *keyfile, *cipher_list, *username_field; |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
736 char *password; |
2629
6ba9dcff11b9
Compiler warning fixes and cleanups
Timo Sirainen <tss@iki.fi>
parents:
2335
diff
changeset
|
737 unsigned char buf; |
8224
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
738 unsigned long err; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
739 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
740 memset(&ssl_params, 0, sizeof(ssl_params)); |
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
741 |
1907
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
742 cafile = getenv("SSL_CA_FILE"); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
743 certfile = getenv("SSL_CERT_FILE"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
744 keyfile = getenv("SSL_KEY_FILE"); |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
745 ssl_params.fname = getenv("SSL_PARAM_FILE"); |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
746 password = getenv("SSL_KEY_PASSWORD"); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
747 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
748 if (certfile == NULL || keyfile == NULL || ssl_params.fname == NULL) { |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
749 /* SSL support is disabled */ |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
750 return; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
751 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
752 |
5361
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
753 CRYPTO_set_mem_functions(ssl_clean_malloc, ssl_clean_realloc, |
bde589bd09d4
Make OpenSSL memory allocations go through system_clean_pool.
Timo Sirainen <tss@iki.fi>
parents:
5360
diff
changeset
|
754 ssl_clean_free); |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
755 SSL_library_init(); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
756 SSL_load_error_strings(); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
757 |
5335
79ea613496aa
Replace some string literals with non-const static buffers to avoid compiler
Timo Sirainen <tss@iki.fi>
parents:
4907
diff
changeset
|
758 extdata_index = SSL_get_ex_new_index(0, dovecot, NULL, NULL, NULL); |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
759 |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
760 if ((ssl_ctx = SSL_CTX_new(SSLv23_server_method())) == NULL) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
761 i_fatal("SSL_CTX_new() failed"); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
762 |
1544
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
763 SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL); |
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
764 |
1996 | 765 cipher_list = getenv("SSL_CIPHER_LIST"); |
766 if (cipher_list == NULL) | |
767 cipher_list = DOVECOT_SSL_DEFAULT_CIPHER_LIST; | |
768 if (SSL_CTX_set_cipher_list(ssl_ctx, cipher_list) != 1) { | |
1544
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
769 i_fatal("Can't set cipher list to '%s': %s", |
1996 | 770 cipher_list, ssl_last_error()); |
1544
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
771 } |
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
772 |
1907
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
773 if (cafile != NULL) { |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
774 if (SSL_CTX_load_verify_locations(ssl_ctx, cafile, NULL) != 1) { |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
775 i_fatal("Can't load CA file %s: %s", |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
776 cafile, ssl_last_error()); |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
777 } |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
778 } |
190f1d315ce6
Added setting ssl_ca_file, patch by Zach Bagnall
Timo Sirainen <tss@iki.fi>
parents:
1897
diff
changeset
|
779 |
1544
ac6ee442376d
OpenSSL proxy changes - hopefully fixes something. Also don't crash with
Timo Sirainen <tss@iki.fi>
parents:
1492
diff
changeset
|
780 if (SSL_CTX_use_certificate_chain_file(ssl_ctx, certfile) != 1) { |
8224
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
781 err = ERR_peek_error(); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
782 if (ERR_GET_LIB(err) != ERR_LIB_PEM || |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
783 ERR_GET_REASON(err) != PEM_R_NO_START_LINE) { |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
784 i_fatal("Can't load certificate file %s: %s", |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
785 certfile, ssl_last_error()); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
786 } else if (is_pem_key_file(certfile)) { |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
787 i_fatal("Can't load certificate file %s: " |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
788 "The file contains a private key " |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
789 "(you've mixed ssl_cert_file and ssl_key_file settings)", |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
790 certfile); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
791 } else { |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
792 i_fatal("Can't load certificate file %s: " |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
793 "The file doesn't contain a certificate.", |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
794 certfile); |
7ac86b33ad64
Log a better error message if ssl_cert_file doesn't point to a valid certificate.
Timo Sirainen <tss@iki.fi>
parents:
8122
diff
changeset
|
795 } |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
796 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
797 |
3889
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
798 SSL_CTX_set_default_passwd_cb(ssl_ctx, pem_password_callback); |
c7462001227b
Added support for password protected SSL private keys. The password can be
Timo Sirainen <tss@iki.fi>
parents:
3888
diff
changeset
|
799 SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, password); |
3584
b686c8bbcd6f
Don't require private key to be RSA
Timo Sirainen <tss@iki.fi>
parents:
3580
diff
changeset
|
800 if (SSL_CTX_use_PrivateKey_file(ssl_ctx, keyfile, |
b686c8bbcd6f
Don't require private key to be RSA
Timo Sirainen <tss@iki.fi>
parents:
3580
diff
changeset
|
801 SSL_FILETYPE_PEM) != 1) { |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
802 i_fatal("Can't load private key file %s: %s", |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
803 keyfile, ssl_last_error()); |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
804 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
805 |
1492
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
806 if (SSL_CTX_need_tmp_RSA(ssl_ctx)) |
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
807 SSL_CTX_set_tmp_rsa_callback(ssl_ctx, ssl_gen_rsa_key); |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
808 SSL_CTX_set_tmp_dh_callback(ssl_ctx, ssl_tmp_dh_callback); |
1492
383d87166963
Generate temporary RSA key when requested. Could be slow, should do some
Timo Sirainen <tss@iki.fi>
parents:
1490
diff
changeset
|
809 |
4471
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
810 if (verbose_ssl) |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
811 SSL_CTX_set_info_callback(ssl_ctx, ssl_info_callback); |
a939ee143a96
If verbose_ssl=yes set ssl_info_callback and print any alerts and BIO
Timo Sirainen <tss@iki.fi>
parents:
4352
diff
changeset
|
812 |
1997
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
813 if (getenv("SSL_VERIFY_CLIENT_CERT") != NULL) { |
4352
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
814 #if OPENSSL_VERSION_NUMBER >= 0x00907000L |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
815 X509_STORE *store; |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
816 |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
817 store = SSL_CTX_get_cert_store(ssl_ctx); |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
818 X509_STORE_set_flags(store, X509_V_FLAG_CRL_CHECK | |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
819 X509_V_FLAG_CRL_CHECK_ALL); |
d57c83c64b20
Updates to ssl_verify_client_cert: Check CRLs. If auth_verbose=yes, log
Timo Sirainen <tss@iki.fi>
parents:
4131
diff
changeset
|
820 #endif |
1997
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
821 SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER | |
2027
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
822 SSL_VERIFY_CLIENT_ONCE, |
dc5d0da1abe9
Added ssl_require_client_cert auth-specific setting. Hide
Timo Sirainen <tss@iki.fi>
parents:
2007
diff
changeset
|
823 ssl_verify_client_cert); |
5528
bad62bc7bafc
Send list of CA names to client when using ssl_verify_client_cert=yes.
Timo Sirainen <tss@iki.fi>
parents:
5361
diff
changeset
|
824 SSL_CTX_set_client_CA_list(ssl_ctx, |
bad62bc7bafc
Send list of CA names to client when using ssl_verify_client_cert=yes.
Timo Sirainen <tss@iki.fi>
parents:
5361
diff
changeset
|
825 SSL_load_client_CA_file(cafile)); |
1997
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
826 } |
1d0985f6bdd9
Added ssl_verify_client_cert setting.
Timo Sirainen <tss@iki.fi>
parents:
1996
diff
changeset
|
827 |
6364
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
828 username_field = getenv("SSL_CERT_USERNAME_FIELD"); |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
829 if (username_field == NULL) |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
830 ssl_username_nid = NID_commonName; |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
831 else { |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
832 ssl_username_nid = OBJ_txt2nid(username_field); |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
833 if (ssl_username_nid == NID_undef) { |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
834 i_fatal("Invalid ssl_cert_username_field: %s", |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
835 username_field); |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
836 } |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
837 } |
7ad61f00ee55
Added ssl_cert_username_field setting.
Timo Sirainen <tss@iki.fi>
parents:
5528
diff
changeset
|
838 |
1556
545f6b150e2c
Make sure PRNG gets initialized before chrooting so it can open /dev/urandom.
Timo Sirainen <tss@iki.fi>
parents:
1544
diff
changeset
|
839 /* PRNG initialization might want to use /dev/urandom, make sure it |
2007
3dd9d3165bff
Don't require initializing RAND_bytes() to return cryptographically strong
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
840 does it before chrooting. We might not have enough entropy at |
3dd9d3165bff
Don't require initializing RAND_bytes() to return cryptographically strong
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
841 the first try, so this function may fail. It's still been |
3dd9d3165bff
Don't require initializing RAND_bytes() to return cryptographically strong
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
842 initialized though. */ |
3dd9d3165bff
Don't require initializing RAND_bytes() to return cryptographically strong
Timo Sirainen <tss@iki.fi>
parents:
1997
diff
changeset
|
843 (void)RAND_bytes(&buf, 1); |
1556
545f6b150e2c
Make sure PRNG gets initialized before chrooting so it can open /dev/urandom.
Timo Sirainen <tss@iki.fi>
parents:
1544
diff
changeset
|
844 |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
845 ssl_proxy_count = 0; |
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
846 ssl_proxies = NULL; |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
847 ssl_initialized = TRUE; |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
848 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
849 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
850 void ssl_proxy_deinit(void) |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
851 { |
1230
e6d2b8c78519
Keep list of the SSL proxies, so they're deinitialized properly if we have
Timo Sirainen <tss@iki.fi>
parents:
1215
diff
changeset
|
852 if (!ssl_initialized) |
e6d2b8c78519
Keep list of the SSL proxies, so they're deinitialized properly if we have
Timo Sirainen <tss@iki.fi>
parents:
1215
diff
changeset
|
853 return; |
e6d2b8c78519
Keep list of the SSL proxies, so they're deinitialized properly if we have
Timo Sirainen <tss@iki.fi>
parents:
1215
diff
changeset
|
854 |
7119
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
855 while (ssl_proxies != NULL) |
8c6a7af67e8c
Replaced clients hash with a linked list.
Timo Sirainen <tss@iki.fi>
parents:
7086
diff
changeset
|
856 ssl_proxy_destroy(ssl_proxies); |
1232
f7da7d46e3f2
destroy proxies before destroying ssl context
Timo Sirainen <tss@iki.fi>
parents:
1231
diff
changeset
|
857 |
3888
650701d41cdf
Generate DH parameters and use them. Changed default regeneration time to 1
Timo Sirainen <tss@iki.fi>
parents:
3879
diff
changeset
|
858 ssl_free_parameters(&ssl_params); |
1232
f7da7d46e3f2
destroy proxies before destroying ssl context
Timo Sirainen <tss@iki.fi>
parents:
1231
diff
changeset
|
859 SSL_CTX_free(ssl_ctx); |
7500 | 860 EVP_cleanup(); |
861 ERR_free_strings(); | |
1049
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
862 } |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
863 |
c41787e8c3f4
Moved common login process code to login-common, created pop3-login.
Timo Sirainen <tss@iki.fi>
parents:
diff
changeset
|
864 #endif |