Factor out function to rehandshake SSL
authorFederico Mena Quintero <federico@novell.com>
Wed, 2 Jun 2010 20:02:23 +0000 (15:02 -0500)
committerFederico Mena Quintero <federico@novell.com>
Wed, 2 Jun 2010 22:51:32 +0000 (17:51 -0500)
Signed-off-by: Federico Mena Quintero <federico@novell.com>
camel/camel-tcp-stream-ssl.c

index 8400c90..24db04d 100644 (file)
@@ -1110,6 +1110,22 @@ tcp_socket_ssl_connect (CamelTcpStream *stream, struct addrinfo *host, gboolean
        return fd;
 }
 
+static gboolean
+rehandshake_ssl (PRFileDesc *fd)
+{
+       if (SSL_ResetHandshake (fd, FALSE) == SECFailure) {
+               set_errno (PR_GetError ());
+               return FALSE;
+       }
+
+       if (SSL_ForceHandshake (fd) == SECFailure) {
+               set_errno (PR_GetError ());
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
 static PRFileDesc *
 connect_to_socks4_proxy (CamelTcpStreamSSL *ssl, const gchar *proxy_host, gint proxy_port, struct addrinfo *connect_addr)
 {
@@ -1187,16 +1203,8 @@ connect_to_socks4_proxy (CamelTcpStreamSSL *ssl, const gchar *proxy_host, gint p
                        d (g_print ("  could not enable SSL\n"));
                        goto error;
                } else {
-                       d (g_print ("  SSL_ResetHandshake\n"));
-                       if (SSL_ResetHandshake (fd, FALSE) == SECFailure) {
-                               set_errno (PR_GetError ());
-                               d (g_print ("  failed\n"));
-                               goto error;
-                       }
-
-                       d (g_print ("  SSL_ForceHandshake\n"));
-                       if (SSL_ForceHandshake (fd) == SECFailure) {
-                               set_errno (PR_GetError ());
+                       d (g_print ("  re-handshaking SSL\n"));
+                       if (!rehandshake_ssl (fd)) {
                                d (g_print ("  failed\n"));
                                goto error;
                        }
@@ -1475,15 +1483,8 @@ camel_tcp_stream_ssl_enable_ssl (CamelTcpStreamSSL *ssl)
 
                ssl->priv->sockfd = fd;
 
-               if (SSL_ResetHandshake (fd, FALSE) == SECFailure) {
-                       set_errno (PR_GetError ());
-                       return -1;
-               }
-
-               if (SSL_ForceHandshake (fd) == SECFailure) {
-                       set_errno (PR_GetError ());
+               if (!rehandshake_ssl (fd))
                        return -1;
-               }
        }
 
        ssl->priv->ssl_mode = TRUE;