tool_doswin: add stdin relay auth

Verify the peer with a random number in the background thread.

Closes #21467
This commit is contained in:
11soda11 2026-04-29 00:13:15 +02:00 committed by Daniel Stenberg
parent a53bae7922
commit 057b251358
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
8 changed files with 113 additions and 80 deletions

View file

@ -103,4 +103,24 @@ const char *curlx_winapi_strerror(DWORD err, char *buf, size_t buflen)
return buf;
}
#ifndef WITHOUT_LIBCURL
#include <bcrypt.h>
#ifndef STATUS_SUCCESS
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#endif
CURLcode curlx_win32_random(unsigned char *entropy, size_t length)
{
memset(entropy, 0, length);
if(BCryptGenRandom(NULL, entropy, (ULONG)length,
BCRYPT_USE_SYSTEM_PREFERRED_RNG) != STATUS_SUCCESS)
return CURLE_FAILED_INIT;
return CURLE_OK;
}
#endif /* WITHOUT_LIBCURL */
#endif /* _WIN32 */

View file

@ -28,6 +28,7 @@
#define WINAPI_ERROR_LEN 100
const char *curlx_get_winapi_error(DWORD err, char *buf, size_t buflen);
const char *curlx_winapi_strerror(DWORD err, char *buf, size_t buflen);
CURLcode curlx_win32_random(unsigned char *entropy, size_t length);
#endif
#endif /* HEADER_CURLX_WINAPI_H */

View file

@ -33,23 +33,7 @@
#include "rand.h"
#include "escape.h"
#ifdef _WIN32
#include <bcrypt.h>
#ifndef STATUS_SUCCESS
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
#endif
CURLcode Curl_win32_random(unsigned char *entropy, size_t length)
{
memset(entropy, 0, length);
if(BCryptGenRandom(NULL, entropy, (ULONG)length,
BCRYPT_USE_SYSTEM_PREFERRED_RNG) != STATUS_SUCCESS)
return CURLE_FAILED_INIT;
return CURLE_OK;
}
#endif
#include "curlx/winapi.h"
#ifndef USE_SSL
/* ---- possibly non-cryptographic version following ---- */
@ -64,7 +48,7 @@ static CURLcode weak_random(struct Curl_easy *data,
#ifdef _WIN32
(void)data;
{
CURLcode result = Curl_win32_random(entropy, length);
CURLcode result = curlx_win32_random(entropy, length);
if(result != CURLE_NOT_BUILT_IN)
return result;
}

View file

@ -49,10 +49,4 @@ CURLcode Curl_rand_hex(struct Curl_easy *data, unsigned char *rnd, size_t num);
CURLcode Curl_rand_alnum(struct Curl_easy *data, unsigned char *rnd,
size_t num);
#ifdef _WIN32
/* Random generator shared between the Schannel vtls and Curl_rand*()
functions */
CURLcode Curl_win32_random(unsigned char *entropy, size_t length);
#endif
#endif /* HEADER_CURL_RAND_H */

View file

@ -50,7 +50,7 @@
#include "vtls/x509asn1.h"
#include "system_win32.h"
#include "curlx/version_win32.h"
#include "rand.h"
#include "curlx/winapi.h"
#include "curlx/strparse.h"
#include "progress.h"
#include "curl_sha256.h"
@ -2637,7 +2637,7 @@ static CURLcode schannel_random(struct Curl_easy *data,
{
(void)data;
return Curl_win32_random(entropy, length);
return curlx_win32_random(entropy, length);
}
static CURLcode schannel_checksum(const unsigned char *input,