Explorar o código

Avoid redundant logging of known host keys

Source commit: 31f8a9b00711e88e14f2c41719202d24b850bc30
Martin Prikryl %!s(int64=3) %!d(string=hai) anos
pai
achega
d8d7fdec31
Modificáronse 2 ficheiros con 7 adicións e 1 borrados
  1. 6 1
      source/core/SecureShell.cpp
  2. 1 0
      source/core/SecureShell.h

+ 6 - 1
source/core/SecureShell.cpp

@@ -113,6 +113,7 @@ void __fastcall TSecureShell::ResetConnection()
   }
   FLogCtx = NULL;
   FClosed = false;
+  FLoggedKnownHostKeys.clear();
 }
 //---------------------------------------------------------------------------
 void __fastcall TSecureShell::ResetSessionInfo()
@@ -2676,9 +2677,13 @@ bool __fastcall TSecureShell::HaveHostKey(UnicodeString Host, int Port, const Un
     }
   }
 
-  if (Result)
+  if (Result &&
+      (FLoggedKnownHostKeys.find(KeyType) == FLoggedKnownHostKeys.end()))
   {
     LogEvent(FORMAT(L"Have a known host key of type %s", (KeyType)));
+    // This is called multiple times for the same cached key since PuTTY 0.76 (support for rsa-sha2*?).
+    // Avoid repeated log entries.
+    FLoggedKnownHostKeys.insert(KeyType);
   }
 
   return Result;

+ 1 - 0
source/core/SecureShell.h

@@ -76,6 +76,7 @@ private:
   ScpLogPolicy * FLogPolicy;
   ScpSeat * FSeat;
   LogContext * FLogCtx;
+  std::set<UnicodeString> FLoggedKnownHostKeys;
 
   void __fastcall Init();
   void __fastcall SetActive(bool value);