From 854ed0a58ad068faa570870d9f8e01208b1fc271 Mon Sep 17 00:00:00 2001 From: nnposter Date: Tue, 8 Feb 2022 00:37:36 +0000 Subject: [PATCH] Reject supported hash in Proxy-Authorization header This should not normally happen, as the hash is expected to match what Ncat offered in prior Proxy-Authenticate. Closes #2440 --- ncat/http.c | 2 +- ncat/http_digest.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/ncat/http.c b/ncat/http.c index 7115c3314..914ed546c 100644 --- a/ncat/http.c +++ b/ncat/http.c @@ -1456,7 +1456,7 @@ static const char *http_read_credentials(const char *s, if (str_equal_i(value, "MD5")) credentials->u.digest.algorithm = ALGORITHM_MD5; else - credentials->u.digest.algorithm = ALGORITHM_MD5; + credentials->u.digest.algorithm = ALGORITHM_UNKNOWN; } else if (str_equal_i(name, "qop")) { if (str_equal_i(value, "auth")) credentials->u.digest.qop = QOP_AUTH; diff --git a/ncat/http_digest.c b/ncat/http_digest.c index af74c3be7..427b11281 100644 --- a/ncat/http_digest.c +++ b/ncat/http_digest.c @@ -266,7 +266,8 @@ char *http_digest_proxy_authorization(const struct http_challenge *challenge, size_t size = 0, offset = 0; enum http_digest_qop qop; - if (challenge->scheme != AUTH_DIGEST || challenge->realm == NULL + if (challenge->scheme != AUTH_DIGEST + || challenge->realm == NULL || challenge->digest.nonce == NULL || challenge->digest.algorithm != ALGORITHM_MD5) return NULL; @@ -330,7 +331,8 @@ int http_digest_check_credentials(const char *username, const char *realm, || credentials->u.digest.realm == NULL || credentials->u.digest.nonce == NULL || credentials->u.digest.uri == NULL - || credentials->u.digest.response == NULL) { + || credentials->u.digest.response == NULL + || credentials->u.digest.algorithm != ALGORITHM_MD5) { return 0; } if (credentials->u.digest.qop != QOP_NONE && credentials->u.digest.qop != QOP_AUTH)