View Issue Details

IDProjectCategoryView StatusLast Update
0002061libmicrohttpddigest authentication (HTTP)public2012-01-23 13:21
Reportertclaveirole Assigned ToChristian Grothoff Due Date
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version0.9.17 
Target Version0.9.18Fixed in Version0.9.18 
Summary0002061: digest authentication expect nonce count in base 10, RFC says base is 16
DescriptionHello,

I found a bug with libmicrohttpd's digest authentication. In digestauth.c, line 554, in MHD_digest_auth_check(), the call to strtoul() uses base 10 to parse the nonce counter value from the HTTP Authorization header (nc=...).

However, RFC 2617 states one should use base 16 (section 3.2.2, The Authorization Request Header). This is clear from the grammar, and the description for nonce-count clearly states: "The nc-value is the hexadecimal count of the number of requests [...]"

I did some tests using libcurl, and libcurl indeed uses hexadecimal values. When the counter reaches 10, valid authentication requests get rejected because MHD_digest_auth_check() cannot parse the nonce counter correctly (the value being 0000000a, and not 00000010).
Steps To ReproduceSetup a minimalist HTTP server with digest authentication using libmicrohttpd. Make ten valid requests to the server using the same nonce (thus increasing the nonce counter from 1 to 10). Even though it is valid, the server replies to the last request with 401 Unauthorized.
Additional InformationAttached is a (trivial) patch to solve the issue.
TagsNo tags attached.
Attached Files
base16-nonce-counter.patch (557 bytes)   
Index: src/daemon/digestauth.c
===================================================================
--- src/daemon/digestauth.c	(revision 19034)
+++ src/daemon/digestauth.c	(working copy)
@@ -551,7 +551,7 @@
 	 (0 == lookup_sub_value(nc, sizeof (nc), header, "nc"))  ||
 	 (0 == lookup_sub_value(response, sizeof (response), header, "response")) )
       return MHD_NO;
-    nci = strtoul (nc, &end, 10);
+    nci = strtoul (nc, &end, 16);
     if ( ('\0' != *end) ||
 	 ( (LONG_MAX == nci) && (errno == ERANGE) ) )
       return MHD_NO; /* invalid nonce */
base16-nonce-counter.patch (557 bytes)   

Activities

Christian Grothoff

2012-01-07 16:33

manager   ~0005252

Fixed in SVN 19047.

Issue History

Date ModifiedUsernameFieldChange
2012-01-06 15:26tclaveiroleNew Issue
2012-01-06 15:26tclaveiroleFile Added: base16-nonce-counter.patch
2012-01-07 13:37Christian GrothoffAssigned To => Christian Grothoff
2012-01-07 13:37Christian GrothoffStatusnew => assigned
2012-01-07 16:33Christian GrothoffNote Added: 0005252
2012-01-07 16:33Christian GrothoffStatusassigned => resolved
2012-01-07 16:33Christian GrothoffFixed in Version => 0.9.18
2012-01-07 16:33Christian GrothoffResolutionopen => fixed
2012-01-07 16:47Christian GrothoffTarget Version => 0.9.18
2012-01-23 13:21Christian GrothoffStatusresolved => closed
2013-05-06 10:52Christian GrothoffCategorydigest authentication => digest authentication (HTTP)