38 |
|
|
39 |
#define DH_BITS 768 |
#define DH_BITS 768 |
40 |
gnutls_dh_params dh_params; |
gnutls_dh_params dh_params; |
41 |
|
|
42 |
/* FIXME: should they belong to struct secure_struct? */ |
/* FIXME: should they belong to struct secure_struct? */ |
43 |
static gnutls_certificate_client_credentials xcred; |
static gnutls_certificate_client_credentials xcred; |
44 |
static gnutls_certificate_server_credentials x509_cred; |
static gnutls_certificate_server_credentials x509_cred; |
79 |
if (rc >= 0) { |
if (rc >= 0) { |
80 |
*nbytes = rc; |
*nbytes = rc; |
81 |
return 0; |
return 0; |
82 |
} |
} |
83 |
return rc; |
return rc; |
84 |
} |
} |
85 |
|
|
107 |
gnutls_certificate_free_credentials(x509_cred); |
gnutls_certificate_free_credentials(x509_cred); |
108 |
} |
} |
109 |
|
|
110 |
|
static ssize_t |
111 |
|
_tls_fd_pull(gnutls_transport_ptr fd, void *buf, size_t size) |
112 |
|
{ |
113 |
|
int rc; |
114 |
|
do { |
115 |
|
rc = read(fd, buf, size); |
116 |
|
} while (rc == -1 && errno == EAGAIN); |
117 |
|
return rc; |
118 |
|
} |
119 |
|
|
120 |
|
static ssize_t |
121 |
|
_tls_fd_push(gnutls_transport_ptr fd, const void *buf, size_t size) |
122 |
|
{ |
123 |
|
int rc; |
124 |
|
do { |
125 |
|
rc = write(fd, buf, size); |
126 |
|
} while (rc == -1 && errno == EAGAIN); |
127 |
|
return rc; |
128 |
|
} |
129 |
|
|
130 |
void |
void |
131 |
init_ssl_libs(void) |
init_ssl_libs(void) |
132 |
{ |
{ |
142 |
gnutls_session session = 0; |
gnutls_session session = 0; |
143 |
const int protocol_priority[] = {GNUTLS_TLS1, GNUTLS_SSL3, 0}; |
const int protocol_priority[] = {GNUTLS_TLS1, GNUTLS_SSL3, 0}; |
144 |
const int kx_priority[] = {GNUTLS_KX_RSA, 0}; |
const int kx_priority[] = {GNUTLS_KX_RSA, 0}; |
145 |
const int cipher_priority[] = {GNUTLS_CIPHER_3DES_CBC, GNUTLS_CIPHER_ARCFOUR_128, 0}; |
const int cipher_priority[] = {GNUTLS_CIPHER_3DES_CBC, |
146 |
|
GNUTLS_CIPHER_ARCFOUR_128, |
147 |
|
0}; |
148 |
const int comp_priority[] = {GNUTLS_COMP_NULL, 0}; |
const int comp_priority[] = {GNUTLS_COMP_NULL, 0}; |
149 |
const int mac_priority[] = {GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0}; |
const int mac_priority[] = {GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0}; |
150 |
|
|
172 |
|
|
173 |
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred); |
gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE, xcred); |
174 |
atexit(_tls_cleanup_xcred); |
atexit(_tls_cleanup_xcred); |
175 |
|
|
176 |
|
if (topt & T_LOCAL_MTA) { |
177 |
|
gnutls_transport_set_pull_function(session, _tls_fd_pull); |
178 |
|
gnutls_transport_set_push_function(session, _tls_fd_push); |
179 |
|
} |
180 |
gnutls_transport_set_ptr(session, sd_server); |
gnutls_transport_set_ptr(session, sd_server); |
181 |
|
|
182 |
rs = gnutls_handshake(session); |
rs = gnutls_handshake(session); |
258 |
|
|
259 |
session = initialize_tls_session(); |
session = initialize_tls_session(); |
260 |
|
|
261 |
|
if (topt & T_STDINOUT) { |
262 |
|
gnutls_transport_set_pull_function(session, _tls_fd_pull); |
263 |
|
gnutls_transport_set_push_function(session, _tls_fd_push); |
264 |
|
} |
265 |
gnutls_transport_set_ptr(session, sd_client); |
gnutls_transport_set_ptr(session, sd_client); |
266 |
rs = gnutls_handshake(session); |
rs = gnutls_handshake(session); |
267 |
if (rs < 0) { |
if (rs < 0) { |