*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.2 2002/06/14 04:31:49 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.3 2002/06/14 04:33:53 momjian Exp $
*
* Since the server static private key ($DataDir/server.key)
* will normally be stored unencrypted so that the database
* session. In this case you'll need to temporarily disable
* EDH by commenting out the callback.
*
+ * ...
+ *
+ * Because the risk of cryptanalysis increases as large
+ * amounts of data are sent with the same session key, the
+ * session keys are periodically renegotiated.
+ *
* PATCH LEVEL
* milestone 1: fix basic coding errors
* [*] existing SSL code pulled out of existing files.
* milestone 3: improve confidentially, support perfect forward secrecy
* [ ] use 'random' file, read from '/dev/urandom?'
* [*] emphermal DH keys, default values
- * [ ] periodic renegotiation
+ * [*] periodic renegotiation
* [ ] private key permissions
*
* milestone 4: provide endpoint authentication (client)
#endif
#ifdef USE_SSL
+/*
+ * How much data can be sent across a secure connection
+ * (total in both directions) before we require renegotiation.
+ */
+#define RENEGOTIATION_LIMIT (64 * 1024)
+
static SSL_CTX *SSL_context = NULL;
#endif
#ifdef USE_SSL
if (port->ssl)
{
+ if (port->count > RENEGOTIATION_LIMIT)
+ {
+ SSL_renegotiate(port->ssl);
+ port->count = 0;
+ }
+
n = SSL_read(port->ssl, ptr, len);
switch (SSL_get_error(port->ssl, n))
{
case SSL_ERROR_NONE:
+ port->count += n;
break;
case SSL_ERROR_WANT_READ:
break;
#ifdef USE_SSL
if (port->ssl)
{
+ if (port->count > RENEGOTIATION_LIMIT)
+ {
+ SSL_renegotiate(port->ssl);
+ port->count = 0;
+ }
+
n = SSL_write(port->ssl, ptr, len);
switch (SSL_get_error(port->ssl, n))
{
case SSL_ERROR_NONE:
+ port->count += n;
break;
case SSL_ERROR_WANT_WRITE:
break;
close_SSL(port);
return -1;
}
+ port->count = 0;
return 0;
}
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-be.h,v 1.29 2002/06/14 04:09:37 momjian Exp $
+ * $Id: libpq-be.h,v 1.30 2002/06/14 04:33:53 momjian Exp $
*
*-------------------------------------------------------------------------
*/
*/
#ifdef USE_SSL
SSL *ssl;
+ unsigned long count;
#endif
} Port;