ssl-proxy.c revision 664c7007d4a0116be2cce62295cd9fb9cd33eee0
/* Copyright (C) 2002 Timo Sirainen */
#include "common.h"
#include "ioloop.h"
#include "network.h"
#include "ssl-proxy.h"
int ssl_initialized = FALSE;
#ifdef HAVE_SSL
#include <stdlib.h>
typedef struct {
int refcount;
int io_ssl_dir;
unsigned char outbuf_plain[1024];
unsigned int outbuf_pos_plain;
} SSLProxy;
#define DH_BITS 1024
const int protocol_priority[] =
{ GNUTLS_TLS1, GNUTLS_SSL3, 0 };
const int kx_priority[] =
{ GNUTLS_KX_RSA, GNUTLS_KX_DHE_RSA, 0 };
const int cipher_priority[] =
const int comp_priority[] =
{ GNUTLS_COMP_ZLIB, GNUTLS_COMP_NULL, 0 };
const int mac_priority[] =
{ GNUTLS_MAC_SHA, GNUTLS_MAC_MD5, 0 };
static GNUTLS_DH_PARAMS dh_params;
{
int rcvd;
if (rcvd > 0)
return rcvd;
/* disconnected, either by nicely telling us that we'll
close the connection, or by simply killing the
connection which gives us the packet length error. */
return -1;
}
if (!gnutls_error_is_fatal(rcvd))
return 0;
/* fatal error occured */
return -1;
}
{
int sent;
if (sent >= 0)
return sent;
if (!gnutls_error_is_fatal(sent))
return 0;
if (sent == GNUTLS_E_PUSH_ERROR) {
/* disconnected */
return -1;
}
/* error occured */
return -1;
}
{
return TRUE;
return FALSE;
}
{
int sent;
if (sent < 0) {
/* disconnected */
return;
}
if (proxy->send_left_plain > 0)
return;
/* everything is sent, start reading again */
}
{
sizeof(proxy->outbuf_plain));
if (rcvd <= 0)
return;
return;
if (sent < 0) {
/* disconnected */
return;
}
/* everything wasn't sent - don't read anything until we've
sent it all */
proxy->outbuf_pos_plain = 0;
}
{
int sent;
/* FIXME: (void*) 1 is horrible kludge, but there's no need for us
to store the data as gnutls does it already, maybe it needes an
api change or some clarification how to do it better.. */
if (sent <= 0)
return;
if (proxy->send_left_ssl > 0)
return;
/* everything is sent, start reading again */
}
{
char buf[1024];
if (rcvd < 0) {
/* disconnected */
return;
}
return;
/* everything wasn't sent - don't read anything until we've
sent it all */
}
static GNUTLS_STATE initialize_state(void)
{
/*gnutls_certificate_server_set_request(state, GNUTLS_CERT_REQUEST);*/
return state;
}
{
if (ret >= 0) {
/* handshake done, now we can start reading */
plain_input, proxy);
return;
}
if (gnutls_error_is_fatal(ret)) {
return;
}
/* i/o interrupted */
}
}
int ssl_proxy_new(int fd)
{
int sfd[2];
if (!ssl_initialized)
return -1;
state = initialize_state();
i_error("socketpair() failed: %m");
return -1;
}
if (!ssl_proxy_destroy(proxy))
return -1;
return sfd[1];
}
static void generate_dh_primes(void)
{
int ret;
/* Generate Diffie Hellman parameters - for use with DHE
kx algorithms. These should be discarded and regenerated
once a day, once a week or once a month. Depends on the
security requirements. */
i_fatal("gnutls_dh_params_init() failed: %s",
}
if (ret < 0) {
i_fatal("gnutls_dh_params_generate() failed: %s",
}
if (ret < 0) {
i_fatal("gnutls_dh_params_set() failed: %s",
}
}
void ssl_proxy_init(void)
{
int ret;
/* SSL support is disabled */
return;
}
if ((ret = gnutls_global_init() < 0)) {
i_fatal("gnu_tls_global_init() failed: %s",
}
i_fatal("gnutls_certificate_allocate_cred() failed: %s",
}
if (ret < 0) {
i_fatal("Can't load certificate files %s and %s: %s",
}
}
void ssl_proxy_deinit(void)
{
}
#else
/* no SSL support */
void ssl_proxy_init(void) {}
void ssl_proxy_deinit(void) {}
#endif