Browse Source

Bug 2018: TLS session resumption is not working for subsequent FTP transfers with TLS 1.3 when the server requires reuse of the session of the previous transfer

https://winscp.net/tracker/2018

Source commit: 6cae14d95212b5de26a9ce611e258d6d7516c69b
Martin Prikryl 4 years ago
parent
commit
1f32f22044
1 changed files with 15 additions and 0 deletions
  1. 15 0
      source/filezilla/AsyncSslSocketLayer.cpp

+ 15 - 0
source/filezilla/AsyncSslSocketLayer.cpp

@@ -667,6 +667,21 @@ bool CAsyncSslSocketLayer::HandleSession(SSL_SESSION * Session)
         LogSocketMessageRaw(FZ_LOG_INFO, L"Session ID changed");
       }
       m_sessionid = Session;
+      // Some TLS 1.3 servers require reuse of the session of the previous data connection, not of the main session.
+      // It seems that it's safe to do this even for older TLS versions, but let's not for now.
+      // Once we do, we can simply always use main session's m_sessionid field in the code above.
+      if ((SSL_version(m_ssl) >= TLS1_3_VERSION) && (m_Main != NULL))
+      {
+        if (m_Main->m_sessionid != NULL)
+        {
+          SSL_SESSION_free(m_Main->m_sessionid);
+        }
+        m_Main->m_sessionid = Session;
+        if (Session != NULL)
+        {
+          SSL_SESSION_up_ref(Session);
+        }
+      }
       Result = true;
     }
   }