Jelajahi Sumber

downloader: Support digest auth in emscripten version of HTTPClient

Now that we have our own md5 implementation this feature no longer requires OpenSSL
rdb 2 tahun lalu
induk
melakukan
34a7506c1c

+ 0 - 2
panda/src/downloader/httpClient_emscripten.cxx

@@ -388,12 +388,10 @@ generate_auth(const URLSpec &url, const string &challenge) {
   PT(HTTPAuthorization) auth;
   HTTPAuthorization::AuthenticationSchemes::iterator si;
 
-#ifdef HAVE_OPENSSL
   si = schemes.find("digest");
   if (si != schemes.end()) {
     auth = new HTTPDigestAuthorization((*si).second, url, false);
   }
-#endif
 
   if (auth == nullptr || !auth->is_valid()) {
     si = schemes.find("basic");

+ 7 - 18
panda/src/downloader/httpDigestAuthorization.cxx

@@ -13,13 +13,12 @@
 
 #include "httpDigestAuthorization.h"
 
-#ifdef HAVE_OPENSSL
+#if defined(HAVE_OPENSSL) || defined(__EMSCRIPTEN__)
 
-#include "httpChannel.h"
+#include "hashVal.h"
 #include "string_utils.h"
-#include "openSSLWrapper.h"  // must be included before any other openssl.
-#include <openssl/ssl.h>
-#include <openssl/md5.h>
+#include "urlSpec.h"
+
 #include <time.h>
 
 using std::ostream;
@@ -292,19 +291,9 @@ get_hex_nonce_count() const {
  */
 string HTTPDigestAuthorization::
 calc_md5(const string &source) {
-  unsigned char binary[MD5_DIGEST_LENGTH];
-
-  MD5((const unsigned char *)source.data(), source.length(), binary);
-
-  string result;
-  result.reserve(MD5_DIGEST_LENGTH * 2);
-
-  for (int i = 0; i < MD5_DIGEST_LENGTH; i++) {
-    result += hexdigit((binary[i] >> 4) & 0xf);
-    result += hexdigit(binary[i] & 0xf);
-  }
-
-  return result;
+  HashVal hv;
+  hv.hash_string(source);
+  return hv.as_hex();
 }
 
 ostream &

+ 1 - 1
panda/src/downloader/httpDigestAuthorization.h

@@ -20,7 +20,7 @@
 // use any OpenSSL code, because it is a support module for HTTPChannel, which
 // *does* use OpenSSL code.
 
-#ifdef HAVE_OPENSSL
+#if defined(HAVE_OPENSSL) || defined(__EMSCRIPTEN__)
 
 #include "httpAuthorization.h"