Browse Source

Bug 1895: Support for SNI with FTP

https://winscp.net/tracker/1895

Source commit: 224eb8909cfb253bf3994d0f77e62adcc21f0e7a
Martin Prikryl 5 years ago
parent
commit
9fc806972c

+ 8 - 0
source/filezilla/AsyncSslSocketLayer.cpp

@@ -12,6 +12,7 @@
 
 #include <openssl/x509v3.h>
 #include <openssl/err.h>
+#include <openssl/tls1.h>
 
 /////////////////////////////////////////////////////////////////////////////
 // CAsyncSslSocketLayer
@@ -613,6 +614,7 @@ void CAsyncSslSocketLayer::Close()
 
 BOOL CAsyncSslSocketLayer::Connect(const SOCKADDR *lpSockAddr, int nSockAddrLen)
 {
+  m_HostName = CStringA();
   BOOL res = ConnectNext(lpSockAddr, nSockAddrLen);
   if (!res)
   {
@@ -626,6 +628,7 @@ BOOL CAsyncSslSocketLayer::Connect(const SOCKADDR *lpSockAddr, int nSockAddrLen)
 
 BOOL CAsyncSslSocketLayer::Connect(LPCTSTR lpszHostAddress, UINT nHostPort)
 {
+  m_HostName = AnsiString(lpszHostAddress).c_str();
   BOOL res = ConnectNext(lpszHostAddress, nHostPort);
   if (!res)
   {
@@ -753,6 +756,11 @@ int CAsyncSslSocketLayer::InitSSLConnection(bool clientMode,
     return SSL_FAILURE_INITSSL;
   }
 
+   if (clientMode && (m_HostName.GetLength() > 0))
+   {
+     SSL_set_tlsext_host_name(m_ssl, static_cast<const char *>(m_HostName));
+   }
+
 #ifdef _DEBUG
   if ((main == NULL) && LoggingSocketMessage(FZ_LOG_INFO))
   {

+ 1 - 0
source/filezilla/AsyncSslSocketLayer.h

@@ -191,6 +191,7 @@ private:
   CString m_CertStorage;
   int m_nVerificationResult;
   int m_nVerificationDepth;
+  CStringA m_HostName;
 
   static struct t_SslLayerList
   {

+ 3 - 3
source/filezilla/stdafx.h

@@ -35,10 +35,7 @@ class CFileFix;
 //---------------------------------------------------------------------------
 #include "MFC64bitFix.h"
 #include <ApiLog.h>
-#include <FileZillaApi.h>
-#include <FileZillaOpt.h>
 #include <TextsFileZilla.h>
-#include <structures.h>
 //---------------------------------------------------------------------------
 #include <oleauto.h>
 #include <afxdisp.h>
@@ -525,4 +522,7 @@ inline CStringA AFXAPI operator+(const CStringA & string1, char ch)
   return s;
 }
 //---------------------------------------------------------------------------
+#include <FileZillaApi.h>
+#include <FileZillaOpt.h>
+//---------------------------------------------------------------------------
 #endif