diff options
Diffstat (limited to 'daemon/digest.c')
-rw-r--r-- | daemon/digest.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/daemon/digest.c b/daemon/digest.c index dc0cfb9..1c68366 100644 --- a/daemon/digest.c +++ b/daemon/digest.c @@ -32,6 +32,11 @@ /* A globally unique counter used to guarantee uniqueness of nonces */ static unsigned int g_digest_unique = 0; +/* All the various HTTP methods to try when ignoring the method */ +static const char* g_http_methods[] = { + "GET", "HEAD", "POST", "PUT", "DELETE", "TRACE", "CONNECT", NULL +}; + typedef struct internal_nonce { unsigned char hash[MD5_LEN]; @@ -242,7 +247,7 @@ int digest_check(digest_context_t* dg, const ha_context_t* opts, ha_buffer_t* bu r = digest_pre_check(dg, opts, buf); if(r == HA_OK) - r = digest_complete_check(dg, buf); + r = digest_complete_check(dg, opts, buf); return r; } @@ -396,7 +401,7 @@ int digest_pre_check(digest_context_t* dg, const ha_context_t* opts, ha_buffer_t } -int digest_complete_check(digest_context_t* dg, ha_buffer_t* buf) +static int internal_check(digest_context_t* dg, const char* http_method, ha_buffer_t* buf) { unsigned char hash[MD5_LEN]; md5_ctx_t md5; @@ -419,7 +424,7 @@ int digest_complete_check(digest_context_t* dg, ha_buffer_t* buf) /* Encode ha2 */ md5_init(&md5); - md5_update(&md5, dg->server_method, strlen(dg->server_method)); + md5_update(&md5, http_method, strlen(http_method)); md5_update(&md5, ":", 1); md5_update(&md5, dg->client.uri, strlen(dg->client.uri)); md5_final(hash, &md5); @@ -479,6 +484,30 @@ int digest_complete_check(digest_context_t* dg, ha_buffer_t* buf) return HA_OK; } +int digest_complete_check(digest_context_t* dg, const ha_context_t* opts, ha_buffer_t* buf) +{ + const char** m; + int ret; + + if(opts->digest_ignoremethod) + { + /* Try out each and every method in HTTP */ + for(m = g_http_methods; *m; ++m) + { + ret = internal_check (dg, *m, buf); + if(ret != HA_FALSE) + break; + } + } + else + { + /* Use the method sent to us */ + ret = internal_check (dg, dg->server_method, buf); + } + + return ret; +} + const char* digest_respond(digest_context_t* dg, ha_buffer_t* buf, unsigned char* next) { |