ssl-proxy-openssl.c revision 8222ce68120b51353a3b31d3073b5f845d0e9f53
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "network.h"
#include "hash.h"
#include "ssl-proxy.h"
#ifdef HAVE_OPENSSL
#define DOVECOT_SSL_DEFAULT_CIPHER_LIST "ALL:!LOW"
enum ssl_io_action {
};
struct ssl_proxy {
int refcount;
unsigned char plainout_buf[1024];
unsigned int plainout_size;
unsigned char sslout_buf[1024];
unsigned int sslout_size;
unsigned int handshaked:1;
unsigned int destroyed:1;
unsigned int cert_received:1;
unsigned int cert_broken:1;
};
static int extdata_index;
static struct hash_table *ssl_proxies;
static void plain_read(void *context);
static void plain_write(void *context);
{
switch (action) {
case SSL_ADD_INPUT:
break;
break;
case SSL_REMOVE_INPUT:
}
break;
case SSL_ADD_OUTPUT:
break;
break;
case SSL_REMOVE_OUTPUT:
}
break;
}
}
{
if (block) {
}
} else {
plain_read, proxy);
}
}
}
static void plain_read(void *context)
{
/* buffer full, block input until it's written */
return;
}
sizeof(proxy->sslout_buf) -
proxy->sslout_size);
if (ret <= 0) {
if (ret < 0)
break;
} else {
}
}
}
static void plain_write(void *context)
{
if (ret < 0)
else {
if (proxy->plainout_size > 0) {
plain_write, proxy);
}
} else {
}
}
}
}
static const char *ssl_last_error(void)
{
unsigned long err;
char *buf;
err = ERR_get_error();
if (err == 0)
return buf;
}
{
const char *errstr;
int err;
switch (err) {
case SSL_ERROR_WANT_READ:
break;
case SSL_ERROR_WANT_WRITE:
break;
case SSL_ERROR_SYSCALL:
/* eat up the error queue */
if (verbose_ssl) {
if (ERR_peek_error() != 0)
errstr = ssl_last_error();
else {
if (ret == 0)
errstr = "EOF";
else
}
i_warning("%s syscall failed: %s [%s]",
}
break;
case SSL_ERROR_ZERO_RETURN:
/* clean connection closing */
break;
case SSL_ERROR_SSL:
if (verbose_ssl) {
}
break;
default:
i_warning("%s failed: unknown failure %d (%s) [%s]",
break;
}
}
{
int ret;
if (ret != 1)
else {
}
}
{
int ret;
sizeof(proxy->plainout_buf) -
if (ret <= 0) {
break;
} else {
}
}
}
{
int ret;
if (ret <= 0)
else {
proxy->sslout_size);
}
}
{
if (!proxy->handshaked)
if (proxy->handshaked) {
else
if (proxy->sslout_size == 0)
else
}
}
{
int sfd[2];
if (!ssl_initialized)
return -1;
return -1;
}
return -1;
}
i_error("socketpair() failed: %m");
return -1;
}
main_ref();
return sfd[1];
}
{
}
{
}
{
return TRUE;
main_unref();
return FALSE;
}
{
}
}
{
}
{
if (!preverify_ok)
return 1;
}
void ssl_proxy_init(void)
{
char buf;
/* SSL support is disabled */
return;
}
i_fatal("SSL_CTX_new() failed");
if (cipher_list == NULL)
i_fatal("Can't set cipher list to '%s': %s",
}
i_fatal("Can't load CA file %s: %s",
cafile, ssl_last_error());
}
}
i_fatal("Can't load certificate file %s: %s",
certfile, ssl_last_error());
}
SSL_FILETYPE_PEM) != 1) {
i_fatal("Can't load private key file %s: %s",
keyfile, ssl_last_error());
}
if (SSL_CTX_need_tmp_RSA(ssl_ctx))
}
does it before chrooting. We might not have enough entropy at
the first try, so this function may fail. It's still been
initialized though. */
}
void ssl_proxy_deinit(void)
{
struct hash_iterate_context *iter;
if (!ssl_initialized)
return;
}
#endif