Skip to content

Commit

Permalink
Issue 2250 – Configurable FTP TLS shutdown procedure
Browse files Browse the repository at this point in the history
https://winscp.net/tracker/2250

Source commit: 509a6c3b0efed21c398810e7ead00bd9235ee35d
  • Loading branch information
martinprikryl committed Jan 15, 2024
1 parent 1cb620c commit c97a8ab
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
15 changes: 11 additions & 4 deletions source/core/FtpFileSystem.cpp
Expand Up @@ -2862,10 +2862,17 @@ int __fastcall TFTPFileSystem::GetOptionVal(int OptionID) const
break;

case OPTION_MPEXT_COMPLETE_TLS_SHUTDOWN:
// As of FileZilla Server 1.6.1 this does not seem to be needed. It's still needed with 1.5.1.
// It was possibly fixed by 1.6.0 (2022-12-06) change:
// Fixed an issue in the networking code when dealing with TLS close_notify alerts
Result = FFileZilla ? FALSE : TRUE;
if (Data->CompleteTlsShutdown == asAuto)
{
// As of FileZilla Server 1.6.1 this does not seem to be needed. It's still needed with 1.5.1.
// It was possibly fixed by 1.6.0 (2022-12-06) change:
// Fixed an issue in the networking code when dealing with TLS close_notify alerts
Result = FFileZilla ? -1 : 0;
}
else
{
Result = (Data->CompleteTlsShutdown == asOn) ? 1 : -1;
}
break;

case OPTION_MPEXT_WORK_FROM_CWD:
Expand Down
9 changes: 9 additions & 0 deletions source/core/SessionData.cpp
Expand Up @@ -336,6 +336,7 @@ void __fastcall TSessionData::DefaultSettings()
Ftps = ftpsNone;
MinTlsVersion = tlsDefaultMin;
MaxTlsVersion = tlsMax;
CompleteTlsShutdown = asAuto;
FtpListAll = asAuto;
FtpHost = asAuto;
FtpWorkFromCwd = asAuto;
Expand Down Expand Up @@ -524,6 +525,7 @@ void __fastcall TSessionData::NonPersistant()
\
PROPERTY(MinTlsVersion); \
PROPERTY(MaxTlsVersion); \
PROPERTY(CompleteTlsShutdown); \
\
PROPERTY(WinTitle); \
\
Expand Down Expand Up @@ -927,6 +929,7 @@ void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyI

MinTlsVersion = static_cast<TTlsVersion>(Storage->ReadInteger(L"MinTlsVersion", MinTlsVersion));
MaxTlsVersion = static_cast<TTlsVersion>(Storage->ReadInteger(L"MaxTlsVersion", MaxTlsVersion));
CompleteTlsShutdown = Storage->ReadEnum(L"CompleteTlsShutdown", CompleteTlsShutdown, AutoSwitchMapping);

LOAD_PASSWORD(EncryptKey, L"EncryptKeyPlain");

Expand Down Expand Up @@ -1234,6 +1237,7 @@ void __fastcall TSessionData::DoSave(THierarchicalStorage * Storage,

WRITE_DATA(Integer, MinTlsVersion);
WRITE_DATA(Integer, MaxTlsVersion);
WRITE_DATA(Integer, CompleteTlsShutdown);

WRITE_DATA(Bool, WebDavLiberalEscaping);
WRITE_DATA(Bool, WebDavAuthLegacy);
Expand Down Expand Up @@ -4496,6 +4500,11 @@ void __fastcall TSessionData::SetLogicalHostName(UnicodeString value)
{
SET_SESSION_PROPERTY(LogicalHostName);
}
//---------------------------------------------------------------------------
void TSessionData::SetCompleteTlsShutdown(TAutoSwitch value)
{
SET_SESSION_PROPERTY(CompleteTlsShutdown);
}
//---------------------------------------------------------------------
void __fastcall TSessionData::SetFtpListAll(TAutoSwitch value)
{
Expand Down
3 changes: 3 additions & 0 deletions source/core/SessionData.h
Expand Up @@ -228,6 +228,7 @@ friend class TStoredSessionList;
TFtps FFtps;
TTlsVersion FMinTlsVersion;
TTlsVersion FMaxTlsVersion;
TAutoSwitch FCompleteTlsShutdown;
TAutoSwitch FNotUtf;
int FInternalEditorEncoding;
UnicodeString FS3DefaultRegion;
Expand Down Expand Up @@ -421,6 +422,7 @@ friend class TStoredSessionList;
void __fastcall SetFtps(TFtps value);
void __fastcall SetMinTlsVersion(TTlsVersion value);
void __fastcall SetMaxTlsVersion(TTlsVersion value);
void SetCompleteTlsShutdown(TAutoSwitch value);
void __fastcall SetNotUtf(TAutoSwitch value);
void __fastcall SetInternalEditorEncoding(int value);
void __fastcall SetS3DefaultRegion(UnicodeString value);
Expand Down Expand Up @@ -705,6 +707,7 @@ friend class TStoredSessionList;
__property TFtps Ftps = { read = FFtps, write = SetFtps };
__property TTlsVersion MinTlsVersion = { read = FMinTlsVersion, write = SetMinTlsVersion };
__property TTlsVersion MaxTlsVersion = { read = FMaxTlsVersion, write = SetMaxTlsVersion };
__property TAutoSwitch CompleteTlsShutdown = { read = FCompleteTlsShutdown, write = SetCompleteTlsShutdown };
__property UnicodeString LogicalHostName = { read = FLogicalHostName, write = SetLogicalHostName };
__property TAutoSwitch NotUtf = { read = FNotUtf, write = SetNotUtf };
__property int InternalEditorEncoding = { read = FInternalEditorEncoding, write = SetInternalEditorEncoding };
Expand Down
5 changes: 3 additions & 2 deletions source/filezilla/AsyncSslSocketLayer.cpp
Expand Up @@ -1015,8 +1015,9 @@ BOOL CAsyncSslSocketLayer::ShutDown(int nHow /*=sends*/)
// Without bi-directional shutdown, file uploads are incomplete on some servers
res = SSL_shutdown(m_ssl);

if ((SSL_version(m_ssl) <= TLS1_2_VERSION) ||
!GetSocketOptionVal(OPTION_MPEXT_COMPLETE_TLS_SHUTDOWN))
int completeShutdown = GetSocketOptionVal(OPTION_MPEXT_COMPLETE_TLS_SHUTDOWN);
if ((completeShutdown < 0) ||
((completeShutdown == 0) && (SSL_version(m_ssl) <= TLS1_2_VERSION)))
{
LogSocketMessageRaw(FZ_LOG_INFO, L"Not waiting for complete TLS shutdown");
res = 0;
Expand Down

0 comments on commit c97a8ab

Please sign in to comment.