]> granicus.if.org Git - postgresql/commitdiff
The second was that renegotiation was just plain broken. I can't
authorBruce Momjian <bruce@momjian.us>
Wed, 8 Jan 2003 23:18:35 +0000 (23:18 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 8 Jan 2003 23:18:35 +0000 (23:18 +0000)
believe I didn't notice this before -- once 64k was sent to/from the
server the client would crash.  Basicly, in 7.3 the server SSL code set
the initial state to "about to renegotiate" without actually starting
the renegotiation.  In addition, the server and client didn't properly
handle the SSL_ERROR_WANT_(READ|WRITE) error.  This is fixed in the
second patch.

Nathan Mueller

src/backend/libpq/be-secure.c
src/interfaces/libpq/fe-secure.c

index 98661e44b7c8ae34608aa345d898cdb9bf079137..a277cad00bde72efdc5cb5ed286a730f21a2c844 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.15.2.6 2003/01/08 22:57:05 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/backend/libpq/be-secure.c,v 1.15.2.7 2003/01/08 23:18:34 momjian Exp $
  *
  *       Since the server static private key ($DataDir/server.key)
  *       will normally be stored unencrypted so that the database
@@ -273,12 +273,6 @@ secure_read(Port *port, void *ptr, size_t len)
 #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))
                {
@@ -286,6 +280,7 @@ secure_read(Port *port, void *ptr, size_t len)
                                port->count += n;
                                break;
                        case SSL_ERROR_WANT_READ:
+                               n = secure_read(port, ptr, len);
                                break;
                        case SSL_ERROR_SYSCALL:
                                if (n == -1)
@@ -325,7 +320,15 @@ secure_write(Port *port, const void *ptr, size_t len)
        {
                if (port->count > RENEGOTIATION_LIMIT)
                {
-                       SSL_renegotiate(port->ssl);
+                       SSL_set_session_id_context(port->ssl, (void *)&SSL_context, sizeof(SSL_context));
+
+                       if (SSL_renegotiate(port->ssl) <= 0)
+                         elog(COMMERROR, "SSL renegotiation failure");
+                       if (SSL_do_handshake(port->ssl) <= 0)
+                         elog(COMMERROR, "SSL renegotiation failure");
+                       port->ssl->state=SSL_ST_ACCEPT;
+                       if (SSL_do_handshake(port->ssl) <= 0)
+                         elog(COMMERROR, "SSL renegotiation failure");
                        port->count = 0;
                }
 
@@ -336,6 +339,7 @@ secure_write(Port *port, const void *ptr, size_t len)
                                port->count += n;
                                break;
                        case SSL_ERROR_WANT_WRITE:
+                               n = secure_read(port, ptr, len);
                                break;
                        case SSL_ERROR_SYSCALL:
                                if (n == -1)
index 67e461b4dac7137b65a0a207d509ccd8911d10df..9c239253ef183b18c73e4c6c1e1847a963bb0567 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.15.2.3 2003/01/08 22:57:05 momjian Exp $
+ *       $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-secure.c,v 1.15.2.4 2003/01/08 23:18:35 momjian Exp $
  *
  * NOTES
  *       The client *requires* a valid server certificate.  Since
@@ -268,6 +268,7 @@ pqsecure_read(PGconn *conn, void *ptr, size_t len)
                        case SSL_ERROR_NONE:
                                break;
                        case SSL_ERROR_WANT_READ:
+                               n = pqsecure_read(conn, ptr, len);
                                break;
                        case SSL_ERROR_SYSCALL:
                                printfPQExpBuffer(&conn->errorMessage,
@@ -313,6 +314,7 @@ pqsecure_write(PGconn *conn, const void *ptr, size_t len)
                        case SSL_ERROR_NONE:
                                break;
                        case SSL_ERROR_WANT_WRITE:
+                               n = pqsecure_write(conn, ptr, len);
                                break;
                        case SSL_ERROR_SYSCALL:
                                printfPQExpBuffer(&conn->errorMessage,