ssl-proxy-gnutls.c revision cca4ba2a504d70a9fe9fee37f8433997359de52c
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen* Copyright (c) 2002-2013 Dovecot authors, see the included COPYING file */
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen { GNUTLS_KX_DHE_DSS, GNUTLS_KX_RSA, GNUTLS_KX_DHE_RSA, 0 };
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen { GNUTLS_CIPHER_RIJNDAEL_CBC, GNUTLS_CIPHER_3DES_CBC,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen GNUTLS_CIPHER_ARCFOUR_128, GNUTLS_CIPHER_ARCFOUR_40, 0 };
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen { GNUTLS_COMP_LZO, GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 };
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic gnutls_certificate_credentials x509_cred;
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic void ssl_input(struct ssl_proxy *proxy);
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic void plain_input(struct ssl_proxy *proxy);
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic bool ssl_proxy_destroy(struct ssl_proxy *proxy);
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic const char *get_alert_text(struct ssl_proxy *proxy)
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen return gnutls_alert_get_name(gnutls_alert_get(proxy->session));
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int handle_ssl_error(struct ssl_proxy *proxy, int error)
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen if (error == GNUTLS_E_WARNING_ALERT_RECEIVED) {
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen i_warning("Received SSL warning alert: %s [%s]",
209335fbc1a5fe68e662242ea91e236fdb2ba29dTimo Sirainen /* fatal error occurred */
209335fbc1a5fe68e662242ea91e236fdb2ba29dTimo Sirainen i_warning("Received SSL fatal alert: %s [%s]",
209335fbc1a5fe68e662242ea91e236fdb2ba29dTimo Sirainen i_warning("Error reading from SSL client: %s [%s]",
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen gnutls_alert_send_appropriate(proxy->session, error);
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int proxy_recv_ssl(struct ssl_proxy *proxy, void *data, size_t size)
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen rcvd = gnutls_record_recv(proxy->session, data, size);
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen if (rcvd == 0 || rcvd == GNUTLS_E_UNEXPECTED_PACKET_LENGTH) {
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen /* disconnected, either by nicely telling us that we'll
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen close the connection, or by simply killing the
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen connection which gives us the packet length error. */
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int proxy_send_ssl(struct ssl_proxy *proxy,
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen sent = gnutls_record_send(proxy->session, data, size);
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen if (sent == GNUTLS_E_PUSH_ERROR || sent == GNUTLS_E_INVALID_SESSION) {
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen /* don't warn about errors related to unexpected
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen disconnection */
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainenstatic int ssl_proxy_destroy(struct ssl_proxy *proxy)
6eb7938cd366fc087b39fc9a901e7de426131384Timo Sirainen proxy->outbuf_plain + proxy->outbuf_pos_plain,
a893aaa999856b1ba6e4541890016767aaa283c7Aki Tuomi /* disconnected */
if (rcvd <= 0)
if (sent < 0) {
int sent;
if (sent <= 0)
if (rcvd < 0) {
if (ret >= 0) {
return session;
if (!ssl_initialized) {
main_ref();
if (ret < 0)
fname);
if (ret < 0)
if (bits == 0)
if (ret < 0) {
gnutls_datum m, e, d, p, q, u;
int ret;
if (ret < 0) {
int fd;
T_BEGIN {
} T_END;
void ssl_proxy_init(void)
int ret;
if (ret < 0) {
void ssl_proxy_deinit(void)
if (!ssl_initialized)