diff options
author | AlexSm <alex@ydb.tech> | 2024-01-18 11:28:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-18 11:28:56 +0100 |
commit | 9d0a3761b3201e0d9db879a7adf91876ebdb0564 (patch) | |
tree | 541d11ac878c18efd7ebca81e35112aa0fef995b /library/cpp/http/fetch | |
parent | 404ef8886ecc9736bc58ade6da2fbd83b486a408 (diff) | |
download | ydb-9d0a3761b3201e0d9db879a7adf91876ebdb0564.tar.gz |
Library import 8 (#1074)
* Library import 8
* Add contrib/libs/cxxsupp/libcxx/include/__verbose_abort
Diffstat (limited to 'library/cpp/http/fetch')
-rw-r--r-- | library/cpp/http/fetch/exthttpcodes.h | 1 | ||||
-rw-r--r-- | library/cpp/http/fetch/http_digest.cpp | 41 | ||||
-rw-r--r-- | library/cpp/http/fetch/http_digest.h | 10 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpagent.h | 6 | ||||
-rw-r--r-- | library/cpp/http/fetch/httpload.cpp | 5 |
5 files changed, 27 insertions, 36 deletions
diff --git a/library/cpp/http/fetch/exthttpcodes.h b/library/cpp/http/fetch/exthttpcodes.h index 49e7e5e62d..764e637fee 100644 --- a/library/cpp/http/fetch/exthttpcodes.h +++ b/library/cpp/http/fetch/exthttpcodes.h @@ -50,6 +50,7 @@ enum ExtHttpCodes { HTTP_FETCHER_MB_ERROR = 1041, HTTP_SSL_CERT_ERROR = 1042, HTTP_FIREWALL_REJECT = 1043, + HTTP_INTERNAL_DNS_ERROR = 1047, HTTP_PROXY_REQUEST_CANCELED = 1051, // Custom (replace HTTP 200/304) diff --git a/library/cpp/http/fetch/http_digest.cpp b/library/cpp/http/fetch/http_digest.cpp index 4dff4b047d..5adf391709 100644 --- a/library/cpp/http/fetch/http_digest.cpp +++ b/library/cpp/http/fetch/http_digest.cpp @@ -47,21 +47,19 @@ const char* httpDigestHandler::getHeaderInstruction() const { } /************************************************************/ -void httpDigestHandler::generateCNonce(char* outCNonce) { - if (!*outCNonce) - sprintf(outCNonce, "%ld", (long)time(nullptr)); -} - -/************************************************************/ -inline void addMD5(MD5& ctx, const char* value) { +Y_FORCE_INLINE void addMD5(MD5& ctx, const char* value) { ctx.Update((const unsigned char*)(value), strlen(value)); } -inline void addMD5(MD5& ctx, const char* value, int len) { +Y_FORCE_INLINE void addMD5(MD5& ctx, const char* value, int len) { ctx.Update((const unsigned char*)(value), len); } -inline void addMD5Sep(MD5& ctx) { +Y_FORCE_INLINE void addMD5(MD5& ctx, std::string_view str) { + ctx.Update(str); +} + +Y_FORCE_INLINE void addMD5Sep(MD5& ctx) { addMD5(ctx, ":", 1); } @@ -69,7 +67,7 @@ inline void addMD5Sep(MD5& ctx) { /* calculate H(A1) as per spec */ void httpDigestHandler::digestCalcHA1(const THttpAuthHeader& hd, char* outSessionKey, - char* outCNonce) { + const std::string& outCNonce) { MD5 ctx; ctx.Init(); addMD5(ctx, User_); @@ -82,8 +80,6 @@ void httpDigestHandler::digestCalcHA1(const THttpAuthHeader& hd, unsigned char digest[16]; ctx.Final(digest); - generateCNonce(outCNonce); - ctx.Init(); ctx.Update(digest, 16); addMD5Sep(ctx); @@ -103,7 +99,7 @@ void httpDigestHandler::digestCalcResponse(const THttpAuthHeader& hd, const char* method, const char* nonceCount, char* outResponse, - char* outCNonce) { + const std::string& outCNonce) { char HA1[33]; digestCalcHA1(hd, HA1, outCNonce); @@ -123,9 +119,6 @@ void httpDigestHandler::digestCalcResponse(const THttpAuthHeader& hd, addMD5Sep(ctx); if (hd.qop_auth) { - if (!*outCNonce) - generateCNonce(outCNonce); - addMD5(ctx, nonceCount, 8); addMD5Sep(ctx); addMD5(ctx, outCNonce); @@ -141,7 +134,7 @@ void httpDigestHandler::digestCalcResponse(const THttpAuthHeader& hd, bool httpDigestHandler::processHeader(const THttpAuthHeader* header, const char* path, const char* method, - const char* cnonce) { + const char* cnonceIn) { if (!User_ || !header || !header->use_auth || !header->realm || !header->nonce) return false; @@ -161,16 +154,12 @@ bool httpDigestHandler::processHeader(const THttpAuthHeader* header, NonceCount_++; char nonceCount[20]; - sprintf(nonceCount, "%08d", NonceCount_); + snprintf(nonceCount, sizeof(nonceCount), "%08d", NonceCount_); - char CNonce[50]; - if (cnonce) - strcpy(CNonce, cnonce); - else - CNonce[0] = 0; + std::string cNonce = cnonceIn ? std::string(cnonceIn) : std::to_string(time(nullptr)); char response[33]; - digestCalcResponse(*header, path, method, nonceCount, response, CNonce); + digestCalcResponse(*header, path, method, nonceCount, response, cNonce); //digest-response = 1#( username | realm | nonce | digest-uri // | response | [ algorithm ] | [cnonce] | @@ -189,8 +178,8 @@ bool httpDigestHandler::processHeader(const THttpAuthHeader* header, if (header->qop_auth) out << ", qop=auth"; out << ", nc=" << nonceCount; - if (CNonce[0]) - out << ", cnonce=\"" << CNonce << "\""; + if (!cNonce.empty()) + out << ", cnonce=\"" << cNonce << "\""; out << ", response=\"" << response << "\""; if (header->opaque) out << ", opaque=\"" << header->opaque << "\""; diff --git a/library/cpp/http/fetch/http_digest.h b/library/cpp/http/fetch/http_digest.h index 3b1872d70b..e5ffa3c69e 100644 --- a/library/cpp/http/fetch/http_digest.h +++ b/library/cpp/http/fetch/http_digest.h @@ -2,11 +2,13 @@ #include "httpheader.h" +#include <string> + #include <util/system/compat.h> #include <library/cpp/http/misc/httpcodes.h> class httpDigestHandler { -protected: +private: const char* User_; const char* Password_; char* Nonce_; @@ -15,18 +17,16 @@ protected: void clear(); - void generateCNonce(char* outCNonce); - void digestCalcHA1(const THttpAuthHeader& hd, char* outSessionKey, - char* outCNonce); + const std::string& outCNonce); void digestCalcResponse(const THttpAuthHeader& hd, const char* method, const char* path, const char* nonceCount, char* outResponse, - char* outCNonce); + const std::string& outCNonce); public: httpDigestHandler(); diff --git a/library/cpp/http/fetch/httpagent.h b/library/cpp/http/fetch/httpagent.h index c66af00ced..18f10c160e 100644 --- a/library/cpp/http/fetch/httpagent.h +++ b/library/cpp/http/fetch/httpagent.h @@ -172,9 +172,9 @@ public: Hostheader = (char*)malloc((HostheaderLen = reqHostheaderLen)); } if (port == 80) - sprintf(Hostheader, "Host: %s\r\n", hostname); + snprintf(Hostheader, HostheaderLen, "Host: %s\r\n", hostname); else - sprintf(Hostheader, "Host: %s:%u\r\n", hostname, port); + snprintf(Hostheader, HostheaderLen, "Host: %s:%u\r\n", hostname, port); pHostBeg = strchr(Hostheader, ' ') + 1; pHostEnd = strchr(pHostBeg, '\r'); // convert hostname to lower case since some web server don't like @@ -195,7 +195,7 @@ public: delete[] Hostheader; Hostheader = new char[(HostheaderLen = reqHostheaderLen)]; } - sprintf(Hostheader, "Host: %s\r\n", host); + snprintf(Hostheader, HostheaderLen, "Host: %s\r\n", host); } void SetSocket(SOCKET fd) { diff --git a/library/cpp/http/fetch/httpload.cpp b/library/cpp/http/fetch/httpload.cpp index f3f6c5245e..65631203e5 100644 --- a/library/cpp/http/fetch/httpload.cpp +++ b/library/cpp/http/fetch/httpload.cpp @@ -259,9 +259,10 @@ bool httpLoadAgent::doSetHost(const TAddrList& addrs) { return false; if (RealHost_) { + size_t reqHostheaderLen = strlen(RealHost_) + 20; free(Hostheader); - Hostheader = (char*)malloc(strlen(RealHost_) + 20); - sprintf(Hostheader, "Host: %s\r\n", RealHost_); + Hostheader = (char*)malloc((HostheaderLen = reqHostheaderLen)); + snprintf(Hostheader, HostheaderLen, "Host: %s\r\n", RealHost_); } if (!URL_.IsNull(THttpURL::FlagAuth)) { |