From 336f1b5e4bcfec4d0d8b32f96129796997c8373c Mon Sep 17 00:00:00 2001
From: Heinrich Ko <1000089004@buzzkill-ubuntu.(none)>
Date: Thu, 18 Nov 2010 14:07:57 -0800
Subject: [PATCH] ossl_connect_common() now checks whether or not 'struct connectdata->state' is equal
 'ssl_connection_complete' and if so, will return CURLE_OK with 'done' set to 'TRUE'.
 This check prevents ossl_connect_common() from creating a new ssl connection
 on an existing ssl session which causes openssl to fail when it tries to parse an
 encrypted TLS packet since the cipher data was effectively thrown away when the new
 ssl connection was created.

---
 lib/ssluse.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/lib/ssluse.c b/lib/ssluse.c
index 8cf834b..da664df 100644
--- a/lib/ssluse.c
+++ b/lib/ssluse.c
@@ -2302,6 +2302,12 @@ ossl_connect_common(struct connectdata *conn,
   long timeout_ms;
   int what;
 
+  /* check if the connection has already been established */
+  if(ssl_connection_complete == connssl->state) {
+    *done = TRUE;
+    return CURLE_OK;
+  }
+
   if(ssl_connect_1==connssl->connecting_state) {
     /* Find out how much more time we're allowed */
     timeout_ms = Curl_timeleft(conn, NULL, TRUE);
-- 
1.7.1

