Skip to content

Commit 10ba580

Browse files
authored
Merge pull request #3 from jet2jet/feature/update_libraries
Update OpenSSL (to 3.6.0) and libssh2 (to 1.11.1)
2 parents f30dd52 + f6d1d65 commit 10ba580

8 files changed

Lines changed: 84 additions & 24 deletions

File tree

.github/lib-versions.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
OPENSSL_BRANCH=OpenSSL_1_1_1w
2-
LIBSSH2_VERSION=1.9.0
1+
OPENSSL_BRANCH=openssl-3.6.0
2+
LIBSSH2_VERSION=1.11.1

.github/workflows/build-libs.yml

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ on:
55
workflow_dispatch:
66

77
env:
8+
JOM_DOWNLOAD_URL: http://download.qt.io/official_releases/jom/jom.zip
89
OPENSSL_REPO: https://github.com/openssl/openssl.git
9-
LIBSSH2_REPO: https://github.com/libssh2/libssh2.git
10+
LIBSSH2_URL: https://github.com/libssh2/libssh2
1011

1112
jobs:
1213
build-libs:
@@ -32,6 +33,15 @@ jobs:
3233
- name: Install NASM
3334
uses: ilammy/setup-nasm@v1
3435

36+
- name: Install jom
37+
shell: cmd
38+
run: |
39+
curl.exe -LO "%JOM_DOWNLOAD_URL%"
40+
set "JOM_DIR=%HOMEDRIVE%%HOMEPATH%\jom"
41+
md "%JOM_DIR%" 2>NUL || type NUL
42+
tar.exe xz -C "%JOM_DIR%" -f jom.zip
43+
echo %JOM_DIR%>>%GITHUB_PATH%
44+
3545
- name: Setup MSBuild
3646
uses: microsoft/setup-msbuild@v2
3747
with:
@@ -75,11 +85,15 @@ jobs:
7585

7686
$opensslPrefix = "$env:GITHUB_WORKSPACE\deps\openssl\$arch"
7787

78-
cmd /c "`"$vcvars`" $vc && cd openssl-$arch && perl Configure $targetOpenSSL no-shared no-tests --prefix=$opensslPrefix && nmake && nmake install" `
88+
cmd /c "`"$vcvars`" $vc && cd openssl-$arch && perl Configure $targetOpenSSL no-shared no-tests --prefix=$opensslPrefix /FS && jom /J 8 && jom install" `
7989
2>&1 | Tee-Object "logs\openssl-$arch.log"
8090

8191
# --- libssh2 ---
82-
git clone --depth=1 --branch "libssh2-$($env:LIBSSH2_VERSION)" $env:LIBSSH2_REPO "libssh2-$arch"
92+
curl.exe -LO "$($env:LIBSSH2_URL)/releases/download/libssh2-$($env:LIBSSH2_VERSION)/libssh2-$($env:LIBSSH2_VERSION).zip"
93+
Set-PSDebug -Off
94+
Expand-Archive ".\libssh2-$($env:LIBSSH2_VERSION).zip" -DestinationPath .
95+
Rename-Item "libssh2-$($env:LIBSSH2_VERSION)" "libssh2-$arch"
96+
Set-PSDebug -Trace 1
8397
Push-Location "libssh2-$arch"
8498

8599
$libssh2Prefix = "$env:GITHUB_WORKSPACE\deps\libssh2\$arch"

ShellDLL/Auth.cpp

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,10 @@ bool CAuthentication::CanRetry(IEasySFTPAuthentication* pAuth)
351351

352352
if (!pAuthSession->lpPageantKeyList)
353353
return false;
354+
355+
if (AssignAgentFlags(pAuthSession))
356+
return true;
357+
354358
pAuthSession->dwKeyIndex++;
355359
if (pAuthSession->dwKeyIndex >= pAuthSession->dwKeyCount)
356360
{
@@ -363,6 +367,33 @@ bool CAuthentication::CanRetry(IEasySFTPAuthentication* pAuth)
363367
pAuthSession->lpCurrentKey += dw + 4;
364368
dw = ConvertEndian(*reinterpret_cast<DWORD*>(pAuthSession->lpCurrentKey));
365369
pAuthSession->lpCurrentKey += dw + 4;
370+
pAuthSession->nPrevFlags = -1;
371+
return AssignAgentFlags(pAuthSession);
372+
}
373+
374+
bool CAuthentication::AssignAgentFlags(CAuthSession* pAuthSession)
375+
{
376+
if (pAuthSession->nPrevFlags == 0)
377+
return false;
378+
// get key type data (in the head of blob data)
379+
DWORD dwKeyTypeLen = ConvertEndian(*((DWORD*)(pAuthSession->lpCurrentKey + 4)));
380+
LPCSTR lpszKeyType = (LPCSTR)(pAuthSession->lpCurrentKey + 8);
381+
382+
if ((dwKeyTypeLen == 7 && memcmp(lpszKeyType, "ssh-rsa", dwKeyTypeLen) == 0) ||
383+
(dwKeyTypeLen == 28 && memcmp(lpszKeyType, "ssh-rsa-cert-v01@openssh.com", dwKeyTypeLen) == 0))
384+
{
385+
// both rsa-sha2-512 and rsa-sha2-256 are supported, so use rsa-sha2-512
386+
if (pAuthSession->nPrevFlags < 0)
387+
pAuthSession->nPrevFlags = SSH_AGENT_RSA_SHA2_512;
388+
else if (pAuthSession->nPrevFlags == SSH_AGENT_RSA_SHA2_512)
389+
pAuthSession->nPrevFlags = SSH_AGENT_RSA_SHA2_256;
390+
else
391+
pAuthSession->nPrevFlags = 0;
392+
}
393+
else
394+
{
395+
pAuthSession->nPrevFlags = 0;
396+
}
366397
return true;
367398
}
368399

@@ -403,47 +434,49 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
403434
pAuthSession->dwKeyCount = ConvertEndian(*((DWORD*)lpKeyList));
404435
pAuthSession->dwKeyIndex = 0;
405436
pAuthSession->lpCurrentKey = lpKeyList + 4;
437+
pAuthSession->nPrevFlags = -1;
406438
if (FAILED(pAuth->put_AuthSession(reinterpret_cast<__int3264>(pAuthSession))))
407439
{
408440
delete pAuthSession;
409441
return AuthReturnType::Error;
410442
}
443+
AssignAgentFlags(pAuthSession);
411444
}
412445
LPBYTE p = pAuthSession->lpCurrentKey;
413446

414-
LPCSTR lpszKeyType;
415447
LPCBYTE pBlob;
416448
size_t nBlobLen;
417449

418-
// get key type data (in the head of blob data)
419-
DWORD dwKeyTypeLen = ConvertEndian(*((DWORD*)(p + 4)));
420-
lpszKeyType = (LPCSTR)(p + 8);
421-
422450
nBlobLen = (size_t)ConvertEndian(*((DWORD*)p));
423451
pBlob = (p + 4);
424452
p += nBlobLen + 4;
425453

426-
// get the comment of key
427454
{
455+
DWORD dwKeyTypeLen = ConvertEndian(*((DWORD*)(pBlob)));
456+
LPCSTR lpszKeyType = (LPCSTR)(pBlob + 4);
457+
458+
// get the comment of key
428459
DWORD dwCommentLen = ConvertEndian(*((DWORD*)p));
429460
CMyStringW str;
430461
str.SetUTF8String((LPCBYTE)(p + 4), static_cast<size_t>(dwCommentLen));
431462
p += dwCommentLen + 4;
432-
CMyStringW strType(lpszKeyType), strDebug;
463+
CMyStringW strType, strDebug;
464+
strType.SetString(lpszKeyType, dwKeyTypeLen);
433465
strDebug.Format(L"trying key '%s' (type: %s)", str.operator LPCWSTR(), strType.operator LPCWSTR());
434466
theApp.Log(EasySFTPLogLevel::Debug, strDebug, S_OK);
435467
}
436468

437469
void* abstract = pAuthSession;
438470
auto ret = libssh2_userauth_publickey(pSession, lpszUser, pBlob, nBlobLen,
439-
[](LIBSSH2_SESSION*, LPBYTE* sig, size_t* sig_len, LPCBYTE data, size_t data_len, void** abstract) -> int
471+
[](LIBSSH2_SESSION* session, LPBYTE* sig, size_t* sig_len, LPCBYTE data, size_t data_len, void** abstract) -> int
440472
{
441473
*sig = NULL;
442474
*sig_len = 0;
443475
CAuthSession* pAuthSession = static_cast<CAuthSession*>(*abstract);
444476
LPBYTE lpCurrentKey = pAuthSession->lpCurrentKey;
477+
445478
size_t nSignedLen;
446-
auto buff = pAuthSession->pAgent->SignSSH2Key(lpCurrentKey, data, data_len, &nSignedLen);
479+
auto buff = pAuthSession->pAgent->SignSSH2Key(lpCurrentKey, pAuthSession->nPrevFlags, data, data_len, &nSignedLen);
447480
LPBYTE pSignedData = static_cast<LPBYTE>(buff);
448481
if (nSignedLen < 4 || !buff)
449482
{
@@ -505,7 +538,12 @@ AuthReturnType CAuthentication::SSHAuthenticateWithAgent(IEasySFTPAuthentication
505538
return AuthReturnType::Again;
506539

507540
if (ret != 0)
541+
{
542+
// trying any flags only needed when error is 'unverified'
543+
if (ret != LIBSSH2_ERROR_PUBLICKEY_UNVERIFIED)
544+
pAuthSession->nPrevFlags = 0;
508545
return AuthReturnType::Error;
546+
}
509547

510548
delete pAuthSession;
511549
pAuth->put_AuthSession(reinterpret_cast<__int3264>(nullptr));

ShellDLL/Auth.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct CAuthSession
3737
LPBYTE lpCurrentKey;
3838
DWORD dwKeyCount;
3939
DWORD dwKeyIndex;
40+
int nPrevFlags;
4041

4142
~CAuthSession();
4243
};
@@ -69,6 +70,7 @@ class CAuthentication : public CDispatchImplT<IEasySFTPAuthentication2>
6970
static bool CanRetry(IEasySFTPAuthentication* pAuth);
7071

7172
private:
73+
static bool AssignAgentFlags(CAuthSession* pAuthSession);
7274
static AuthReturnType SSHAuthenticateWithAgent(IEasySFTPAuthentication* pAuth, CMyStringW& strUserName, LIBSSH2_SESSION* pSession, LPCSTR lpszService, CSSHAgent* (* CreateAgent)());
7375

7476
public:

ShellDLL/SSHAgent.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int CSSHAgent::GetKeyList2(LPBYTE* ppKeyList)
6262
return static_cast<int>(nResponseLen) - 5;
6363
}
6464

65-
void* CSSHAgent::SignSSH2Key(LPCBYTE pszPubKey, LPCBYTE pszData, size_t nDataLen, size_t* pnOutLen)
65+
void* CSSHAgent::SignSSH2Key(LPCBYTE pszPubKey, int flags, LPCBYTE pszData, size_t nDataLen, size_t* pnOutLen)
6666
{
6767
void* ret;
6868

@@ -85,7 +85,7 @@ void* CSSHAgent::SignSSH2Key(LPCBYTE pszPubKey, LPCBYTE pszData, size_t nDataLen
8585
// sign data (length + data)
8686
request.AppendToBufferWithLenCE(pszData, nDataLen);
8787
// flags
88-
request.AppendToBufferCE(static_cast<DWORD>(0));
88+
request.AppendToBufferCE(static_cast<DWORD>(flags));
8989

9090
retval = Query(request, nReqLen, (void**)&pResponse, &nResponseLen);
9191
if (!retval)

ShellDLL/SSHAgent.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#pragma once
22

3+
/* Signature request methods */
4+
#define SSH_AGENT_RSA_SHA2_256 2
5+
#define SSH_AGENT_RSA_SHA2_512 4
6+
37
class __declspec(novtable) CSSHAgent
48
{
59
public:
@@ -8,6 +12,6 @@ class __declspec(novtable) CSSHAgent
812

913
public:
1014
int GetKeyList2(LPBYTE* ppKeyList);
11-
void* SignSSH2Key(LPCBYTE pszPubKey, LPCBYTE pszData, size_t nDataLen, size_t* pnOutLen);
15+
void* SignSSH2Key(LPCBYTE pszPubKey, int flags, LPCBYTE pszData, size_t nDataLen, size_t* pnOutLen);
1216
void FreeKeyList(LPBYTE pKeyList);
1317
};

ShellDLL/ShellDLL.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ ITypeInfo* GetTypeInfo(const GUID& guid)
5353

5454
////////////////////////////////////////////////////////////////////////////////
5555

56+
// workaround (related: https://github.com/openssl/openssl/issues/27701 )
57+
#if !defined(WIN64)
58+
extern "C" unsigned _int64 _dtoul3_legacy(double v) { return (unsigned _int64)llround(v); }
59+
#endif
60+
61+
////////////////////////////////////////////////////////////////////////////////
62+
5663
#if !defined(NTDDI_WIN7) || (NTDDI_VERSION < NTDDI_WIN7)
5764
#define INITGUID
5865
#include <guiddef.h>
@@ -1232,9 +1239,6 @@ bool CMainDLL::InitInstance()
12321239

12331240
// for SSL library
12341241
SSL_library_init();
1235-
ERR_load_BIO_strings();
1236-
ERR_load_CRYPTO_strings();
1237-
ERR_load_SSL_strings();
12381242

12391243
::srand((unsigned int) (time(NULL) * GetTickCount()));
12401244

@@ -1661,13 +1665,9 @@ int CMainDLL::ExitInstance()
16611665
::DeleteCriticalSection(&m_csHosts);
16621666
::DeleteCriticalSection(&m_csRootRefs);
16631667

1664-
::ERR_remove_state(0);
16651668
//::ENGINE_cleanup();
16661669
//::CONF_modules_unload();
16671670
//::RAND_cleanup();
1668-
ERR_free_strings();
1669-
EVP_cleanup();
1670-
CRYPTO_cleanup_all_ex_data();
16711671
libssh2_exit();
16721672

16731673
m_TimerThread.Finalize();

ShellDLL/stdafx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ typedef IDataObjectAsyncCapability IAsyncOperation;
7474
#include <openssl/rand.h>
7575

7676
// libssh2
77+
// woraround definition (related: https://github.com/libssh2/libssh2/issues/1578 )
78+
#define LIBSSH2_API
7779
#include <libssh2.h>
7880
#include <libssh2_sftp.h>
7981

0 commit comments

Comments
 (0)