ADD: SFTP - Show used encryption methods

(cherry picked from commit 4ed7362c07)
This commit is contained in:
Alexander Koblov 2022-09-10 13:28:11 +03:00
commit fdb07b3b5b
2 changed files with 22 additions and 0 deletions

View file

@ -14,6 +14,12 @@ const
LIBSSH2_HOSTKEY_HASH_SHA1 = 2;
LIBSSH2_HOSTKEY_HASH_SHA256 = 3;
//* Method constants */
LIBSSH2_METHOD_KEX = 0;
LIBSSH2_METHOD_HOSTKEY = 1;
LIBSSH2_METHOD_CRYPT_CS = 2;
LIBSSH2_METHOD_CRYPT_SC = 3;
//* Disconnect Codes (defined by SSH protocol) */
SSH_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT = 1;
SSH_DISCONNECT_PROTOCOL_ERROR = 2;
@ -203,6 +209,7 @@ var
abstract: Pointer): PLIBSSH2_SESSION; cdecl;
libssh2_session_handshake: function(session: PLIBSSH2_SESSION; sock: cint): cint; cdecl;
libssh2_hostkey_hash: function(session: PLIBSSH2_SESSION; hash_type: cint): PAnsiChar; cdecl;
libssh2_session_methods: function(session: PLIBSSH2_SESSION; method_type: cint): PAnsiChar; cdecl;
libssh2_session_disconnect_ex: function(session: PLIBSSH2_SESSION;
reason: cint;
const description: PAnsiChar;
@ -523,6 +530,7 @@ begin
libssh2_session_init_ex:= SafeGetProcAddress(libssh2, 'libssh2_session_init_ex');
libssh2_session_handshake:= SafeGetProcAddress(libssh2, 'libssh2_session_handshake');
libssh2_hostkey_hash:= SafeGetProcAddress(libssh2, 'libssh2_hostkey_hash');
libssh2_session_methods:= SafeGetProcAddress(libssh2, 'libssh2_session_methods');
libssh2_session_disconnect_ex:= SafeGetProcAddress(libssh2, 'libssh2_session_disconnect_ex');
libssh2_session_free:= SafeGetProcAddress(libssh2, 'libssh2_session_free');
libssh2_session_set_blocking:= SafeGetProcAddress(libssh2, 'libssh2_session_set_blocking');

View file

@ -315,6 +315,7 @@ var
S: String;
F: String = '';
SS: String = '';
CS, SC: PAnsiChar;
I, J, Finish: Integer;
Message: UnicodeString;
FingerPrint: PAnsiChar;
@ -344,6 +345,19 @@ begin
DoStatus(False, 'Connection established');
DoStatus(False, 'Key exchange method: ' + libssh2_session_methods(FSession, LIBSSH2_METHOD_KEX));
CS:= libssh2_session_methods(FSession, LIBSSH2_METHOD_CRYPT_CS);
SC:= libssh2_session_methods(FSession, LIBSSH2_METHOD_CRYPT_SC);
if Assigned(CS) and Assigned(SC) and (StrComp(SC, SC) = 0) then
DoStatus(False, 'Encryption method: ' + CS)
else begin
DoStatus(False, 'Encryption method (client to server): ' + CS);
DoStatus(False, 'Encryption method (server to client): ' + SC);
end;
DoStatus(False, 'Host key method: ' + libssh2_session_methods(FSession, LIBSSH2_METHOD_HOSTKEY));
if libssh2_version($010900) = nil then
Finish:= LIBSSH2_HOSTKEY_HASH_SHA1
else begin