gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] branch master updated (05f582d4 -> 5fdb9eff)


From: gnunet
Subject: [libmicrohttpd] branch master updated (05f582d4 -> 5fdb9eff)
Date: Fri, 13 May 2022 14:19:51 +0200

This is an automated email from the git hooks/post-receive script.

karlson2k pushed a change to branch master
in repository libmicrohttpd.

    from 05f582d4 Fixed leaks of mutexes.
     new 0d78994d test_set_panic: fixed compiler warnings
     new 58d1aef7 digestauth: fixed wrong results of client data check
     new 3c63be90 digestauth: cosmetics
     new 5fdb9eff digestauth: added detection for possibly fabricated nonces

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/include/microhttpd.h        |  10 +-
 src/microhttpd/digestauth.c     | 398 ++++++++++++++++++++++++++++------------
 src/microhttpd/test_set_panic.c |  13 +-
 3 files changed, 293 insertions(+), 128 deletions(-)

diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h
index f209587b..6bf594cc 100644
--- a/src/include/microhttpd.h
+++ b/src/include/microhttpd.h
@@ -96,7 +96,7 @@ extern "C"
  * they are parsed as decimal numbers.
  * Example: 0x01093001 = 1.9.30-1.
  */
-#define MHD_VERSION 0x00097511
+#define MHD_VERSION 0x00097512
 
 /* If generic headers don't work on your platform, include headers
    which define 'va_list', 'size_t', 'ssize_t', 'intptr_t', 'off_t',
@@ -4374,7 +4374,7 @@ enum MHD_DigestAuthAlgorithm
  *      invalid in seconds
  * @param algo digest algorithms allowed for verification
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @note Available since #MHD_VERSION 0x00096200
  * @ingroup authentication
  */
@@ -4401,7 +4401,7 @@ MHD_digest_auth_check2 (struct MHD_Connection *connection,
  * @param nonce_timeout The amount of time for a nonce to be
  *      invalid in seconds
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @ingroup authentication
  * @deprecated use MHD_digest_auth_check2()
  */
@@ -4427,7 +4427,7 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
  *      invalid in seconds
  * @param algo digest algorithms allowed for verification
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @note Available since #MHD_VERSION 0x00096200
  * @ingroup authentication
  */
@@ -4455,7 +4455,7 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection 
*connection,
  * @param nonce_timeout The amount of time for a nonce to be
  *      invalid in seconds
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @note Available since #MHD_VERSION 0x00096000
  * @ingroup authentication
  * @deprecated use #MHD_digest_auth_check_digest2()
diff --git a/src/microhttpd/digestauth.c b/src/microhttpd/digestauth.c
index a92d99ed..c7d13866 100644
--- a/src/microhttpd/digestauth.c
+++ b/src/microhttpd/digestauth.c
@@ -50,6 +50,12 @@
  */
 #define REUSE_TIMEOUT 30
 
+/**
+ * The maximum value of artificial timestamp difference to avoid clashes.
+ * The value must be suitable for bitwise AND operation.
+ */
+#define DAUTH_JUMPBACK_MAX (0x7F)
+
 
 /**
  * 48 bit value in bytes
@@ -147,6 +153,87 @@
  */
 #define _MHD_SESS_TOKEN "-sess"
 
+
+/**
+ * The result of digest authentication of the client.
+ */
+enum MHD_DigestAuthResult
+{
+  /**
+   * Authentication OK
+   */
+  MHD_DAUTH_OK = 1,
+
+  /**
+   * General error, like "out of memory"
+   */
+  MHD_DAUTH_ERROR = 0,
+
+  /**
+   * No "Authorization" header or wrong format of the header.
+   */
+  MHD_DAUTH_WRONG_HEADER = -1,
+
+  /**
+   * Wrong 'username'.
+   */
+  MHD_DAUTH_WRONG_USERNAME = -2,
+
+  /**
+   * Wrong 'realm'.
+   */
+  MHD_DAUTH_WRONG_REALM = -3,
+
+  /**
+   * Wrong 'URI' (or URI parameters).
+   */
+  MHD_DAUTH_WRONG_URI = -4,
+
+  /* The different form of naming is intentionally used for the results below,
+   * as they are more important */
+
+  /**
+   * The 'nonce' is too old. Suggest the client to retry with the same
+   * username and password to get the fresh 'nonce'.
+   * The validity of the 'nonce' may not be checked.
+   */
+  MHD_DAUTH_NONCE_STALE = -16,
+
+  /**
+   * The 'nonce' is wrong. May indicate an attack attempt.
+   */
+  MHD_DAUTH_NONCE_WRONG = -32,
+
+  /**
+   * The 'response' is wrong. May indicate an attack attempt.
+   */
+  MHD_DAUTH_RESPONSE_WRONG = -33,
+};
+
+/**
+ * The result of nonce-nc map array check.
+ */
+enum MHD_CheckNonceNC_
+{
+  /**
+   * The nonce and NC are OK (valid and NC was not used before).
+   */
+  MHD_DAUTH_NONCENC_OK = MHD_DAUTH_OK,
+
+  /**
+   * The 'nonce' was overwritten with newer 'nonce' in the same slot or
+   * NC was already used.
+   * The validity of the 'nonce' was not be checked.
+   */
+  MHD_DAUTH_NONCENC_STALE = MHD_DAUTH_NONCE_STALE,
+
+  /**
+   * The 'nonce' is wrong, it was not generated before.
+   */
+  MHD_DAUTH_NONCENC_WRONG = MHD_DAUTH_NONCE_WRONG,
+};
+
+
 /**
  * Context passed to functions that need to calculate
  * a digest but are orthogonal to the specific
@@ -528,6 +615,36 @@ lookup_sub_value (char *dest,
 }
 
 
+/**
+ * Extract timestamp from the given nonce.
+ * @param nonce the nonce to check
+ * @param noncelen the lenght of the nonce, zero for autodetect
+ * @param[out] ptimestamp the pointer to store extracted timestamp
+ * @return true if timestamp was extracted,
+ *         false if nonce does not have valid timestamp.
+ */
+static bool
+get_nonce_timestamp (const char *const nonce,
+                     size_t noncelen,
+                     uint64_t *const ptimestamp)
+{
+  mhd_assert ((0 == noncelen) || (strlen (nonce) == noncelen));
+  if (0 == noncelen)
+    noncelen = strlen (nonce);
+
+  if ( (NONCE_STD_LEN (SHA256_DIGEST_SIZE) != noncelen) &&
+       (NONCE_STD_LEN (MD5_DIGEST_SIZE) != noncelen) )
+    return false;
+
+  if (TIMESTAMP_CHARS_LEN !=
+      MHD_strx_to_uint64_n_ (nonce + noncelen - TIMESTAMP_CHARS_LEN,
+                             TIMESTAMP_CHARS_LEN,
+                             ptimestamp))
+    return false;
+  return true;
+}
+
+
 /**
  * Super-fast xor-based "hash" function
  *
@@ -575,51 +692,96 @@ get_nonce_nc_idx (size_t arr_size,
 
 
 /**
- * Check nonce-nc map array with either new nonce counter
- * or a whole new nonce.
+ * Check nonce-nc map array with the new nonce counter.
  *
  * @param connection The MHD connection structure
  * @param nonce A pointer that referenced a zero-terminated array of nonce
- * @param noncelen the lenth of @a nonce, in characters
- * @param nc The nonce counter, zero to add the nonce to the array
- * @return #MHD_YES if successful, #MHD_NO if invalid (or we have no NC array)
+ * @param noncelen the length of @a nonce, in characters
+ * @param nc The nonce counter
+ * @return #MHD_DAUTH_NONCENC_OK if successful,
+ *         #MHD_DAUTH_NONCENC_STALE if nonce is stale (or no nonce-nc array
+ *         is available),
+ *         #MHD_DAUTH_NONCENC_WRONG if nonce was not recodered in nonce-nc map
+ *         array, while it should.
  */
-static bool
+static enum MHD_CheckNonceNC_
 check_nonce_nc (struct MHD_Connection *connection,
                 const char *nonce,
                 size_t noncelen,
+                uint64_t nonce_time,
                 uint64_t nc)
 {
   struct MHD_Daemon *daemon = MHD_get_master (connection->daemon);
   struct MHD_NonceNc *nn;
   uint32_t mod;
-  bool ret;
+  enum MHD_CheckNonceNC_ ret;
 
-  mhd_assert (noncelen == strlen (nonce));
+  mhd_assert (strlen (nonce) == noncelen);
   mhd_assert (0 != nc);
   if (MAX_NONCE_LENGTH < noncelen)
-    return false; /* This should be impossible, but static analysis
+    return MHD_DAUTH_NONCENC_WRONG; /* This should be impossible, but static 
analysis
                       tools have a hard time with it *and* this also
                       protects against unsafe modifications that may
                       happen in the future... */
   mod = daemon->nonce_nc_size;
   if (0 == mod)
-    return false;  /* no array! */
+    return MHD_DAUTH_NONCENC_STALE;  /* no array! */
   if (nc + 64 < nc)
-    return false;  /* Overflow, unrealistically high value */
+    return MHD_DAUTH_NONCENC_STALE;  /* Overflow, unrealistically high value */
 
-  /*
-   * Look for the nonce, if it does exist and its corresponding
-   * nonce counter is less than the current nonce counter by 1,
-   * then only increase the nonce counter by one.
-   */
   nn = &daemon->nnc[get_nonce_nc_idx (mod, nonce, noncelen)];
 
   MHD_mutex_lock_chk_ (&daemon->nnc_lock);
 
+  mhd_assert (0 == nn->nonce[noncelen]); /* The old value must be valid */
+
   if ( (0 != memcmp (nn->nonce, nonce, noncelen)) ||
        (0 != nn->nonce[noncelen]) )
-    ret = false;     /* Nonce does not match, fail */
+  { /* The nonce in the slot does not match nonce from the client */
+    if (0 == nn->nonce[0])
+    { /* The slot was never used, while the client's nonce value should be
+       * recorded when it was generated by MHD */
+      ret = MHD_DAUTH_NONCENC_WRONG;
+    }
+    else if (0 != nn->nonce[noncelen])
+    { /* The value is the slot is wrong */
+      ret =  MHD_DAUTH_NONCENC_STALE;
+    }
+    else
+    {
+      uint64_t slot_ts; /**< The timestamp in the slot */
+      if (! get_nonce_timestamp (nn->nonce, 0, &slot_ts))
+      {
+        mhd_assert (0); /* The value is the slot is wrong */
+        ret = MHD_DAUTH_NONCENC_STALE;
+      }
+      else
+      {
+        /* Unsigned value, will be large if nonce_time is less than slot_ts */
+        const uint64_t ts_diff = TRIM_TO_TIMESTAMP (nonce_time - slot_ts);
+        if ((REUSE_TIMEOUT * 1000) >= ts_diff)
+        {
+          /* The nonce from the client may not have been placed in the slot
+           * because another nonce in that slot has not yet expired. */
+          ret = MHD_DAUTH_NONCENC_STALE;
+        }
+        else if (TRIM_TO_TIMESTAMP (UINT64_MAX) / 2 >= ts_diff)
+        {
+          /* Too large value means that nonce_time is less than slot_ts.
+           * The nonce from the client may have been overwritten by the newer
+           * nonce. */
+          ret = MHD_DAUTH_NONCENC_STALE;
+        }
+        else
+        {
+          /* The nonce from the client should be generated after the nonce
+           * in the slot has been expired, the nonce must be recorded, but
+           * it's not. */
+          ret = MHD_DAUTH_NONCENC_WRONG;
+        }
+      }
+    }
+  }
   else if (nc > nn->nc)
   {
     /* 'nc' is larger, shift bitmask and bump limit */
@@ -636,7 +798,7 @@ check_nonce_nc (struct MHD_Connection *connection,
     else
       nn->nmask = 0;                /* big jump, unset all bits in the mask */
     nn->nc = nc;
-    ret = true;
+    ret = MHD_DAUTH_NONCENC_OK;
   }
   else if (nc < nn->nc)
   {
@@ -647,23 +809,18 @@ check_nonce_nc (struct MHD_Connection *connection,
     {
       /* Out-of-order nonce, but within 64-bit bitmask, set bit */
       nn->nmask |= (UINT64_C (1) << (nn->nc - nc - 1));
-      ret = true;
+      ret = MHD_DAUTH_NONCENC_OK;
     }
     else
       /* 'nc' was already used or too old (more then 64 values ago) */
-      ret = false;
+      ret = MHD_DAUTH_NONCENC_STALE;
   }
   else /* if (nc == nn->nc) */
     /* 'nc' was already used */
-    ret = false;
+    ret = MHD_DAUTH_NONCENC_STALE;
 
   MHD_mutex_unlock_chk_ (&daemon->nnc_lock);
-#ifdef HAVE_MESSAGES
-  if (! ret)
-    MHD_DLOG (daemon,
-              _ ("Stale nonce received. If this happens a lot, you should "
-                 "probably increase the size of the nonce array.\n"));
-#endif
+
   return ret;
 }
 
@@ -788,36 +945,6 @@ calculate_nonce (uint64_t nonce_time,
 }
 
 
-/**
- * Extract timestamp from the given nonce.
- * @param nonce the nonce to check
- * @param noncelen the lenght of the nonce, zero for autodetect
- * @param[out] ptimestamp the pointer to store extracted timestamp
- * @return true if timestamp was extracted,
- *         false if nonce does not have valid timestamp.
- */
-static bool
-get_nonce_timestamp (const char *const nonce,
-                     size_t noncelen,
-                     uint64_t *const ptimestamp)
-{
-  mhd_assert ((0 == noncelen) || (strlen (nonce) == noncelen));
-  if (0 == noncelen)
-    noncelen = strlen (nonce);
-
-  if ( (NONCE_STD_LEN (SHA256_DIGEST_SIZE) != noncelen) &&
-       (NONCE_STD_LEN (MD5_DIGEST_SIZE) != noncelen) )
-    return false;
-
-  if (TIMESTAMP_CHARS_LEN !=
-      MHD_strx_to_uint64_n_ (nonce + noncelen - TIMESTAMP_CHARS_LEN,
-                             TIMESTAMP_CHARS_LEN,
-                             ptimestamp))
-    return false;
-  return true;
-}
-
-
 /**
  * Check whether it is possible to use slot in nonce-nc map array.
  *
@@ -991,7 +1118,8 @@ calculate_add_nonce_with_retry (struct MHD_Connection 
*const connection,
       base2 = _MHD_ROTL32 (base2, (((base4 >> 4) ^ base4) % 32));
       base3 = ((uint16_t) (base2 >> 16)) ^ ((uint16_t) base2);
       base4 = ((uint8_t) (base3 >> 8)) ^ ((uint8_t) base3);
-      timestamp2 -= (base4 & 0x7f); /* Use up to 127 ms difference */
+      /* Use up to 127 ms difference */
+      timestamp2 -= (base4 & DAUTH_JUMPBACK_MAX);
       if (timestamp1 == timestamp2)
         timestamp2 -= 2;
     }
@@ -1129,11 +1257,11 @@ check_argument_match (struct MHD_Connection *connection,
  *     (must contain "da->digest_size" bytes or be NULL)
  * @param nonce_timeout The amount of time for a nonce to be
  *      invalid in seconds
- * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ * @return #MHD_DAUTH_OK if authenticated,
+ *         error code otherwise.
  * @ingroup authentication
  */
-static int
+static enum MHD_DigestAuthResult
 digest_auth_check_all (struct MHD_Connection *connection,
                        struct DigestAlgorithm *da,
                        const char *realm,
@@ -1169,14 +1297,15 @@ digest_auth_check_all (struct MHD_Connection 
*connection,
                                                  
MHD_HTTP_HEADER_AUTHORIZATION),
                                                &header,
                                                NULL))
-    return MHD_NO;
+    return MHD_DAUTH_WRONG_HEADER;
   if (0 != strncmp (header,
                     _BASE,
                     MHD_STATICSTR_LEN_ (_BASE)))
-    return MHD_NO;
+    return MHD_DAUTH_WRONG_HEADER;
   header += MHD_STATICSTR_LEN_ (_BASE);
   left = strlen (header);
 
+  if (1)
   {
     char un[MAX_USERNAME_LENGTH];
 
@@ -1184,13 +1313,15 @@ digest_auth_check_all (struct MHD_Connection 
*connection,
                             sizeof (un),
                             header,
                             "username");
-    if ( (0 == len) ||
-         (0 != strcmp (username,
-                       un)) )
-      return MHD_NO;
+    if (0 == len)
+      return MHD_DAUTH_WRONG_HEADER;
+    if (0 != strcmp (username,
+                     un))
+      return MHD_DAUTH_WRONG_USERNAME;
     left -= strlen ("username") + len;
   }
 
+  if (1)
   {
     char r[MAX_REALM_LENGTH];
 
@@ -1198,10 +1329,11 @@ digest_auth_check_all (struct MHD_Connection 
*connection,
                             sizeof (r),
                             header,
                             "realm");
-    if ( (0 == len) ||
-         (0 != strcmp (realm,
-                       r)) )
-      return MHD_NO;
+    if (0 == len)
+      return MHD_DAUTH_WRONG_HEADER;
+    if (0 != strcmp (realm,
+                     r))
+      return MHD_DAUTH_WRONG_REALM;
     left -= strlen ("realm") + len;
   }
 
@@ -1209,7 +1341,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
                                     sizeof (nonce),
                                     header,
                                     "nonce")))
-    return MHD_NO;
+    return MHD_DAUTH_WRONG_HEADER;
   nonce_len = len;
   left -= strlen ("nonce") + len;
   if (left > 32 * 1024)
@@ -1221,7 +1353,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
        #MHD_OPTION_CONNECTION_MEMORY_LIMIT might be very large
        and would thus permit sending a >32k authorization
        header value. */
-    return MHD_NO;
+    return MHD_DAUTH_WRONG_HEADER;
   }
   if (! get_nonce_timestamp (nonce, nonce_len, &nonce_time))
   {
@@ -1229,7 +1361,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
     MHD_DLOG (daemon,
               _ ("Authentication failed, invalid timestamp format.\n"));
 #endif
-    return MHD_NO;
+    return MHD_DAUTH_WRONG_HEADER;
   }
 
   t = MHD_monotonic_msec_counter ();
@@ -1241,7 +1373,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
   if (TRIM_TO_TIMESTAMP (t - nonce_time) > (nonce_timeout * 1000))
   {
     /* too old */
-    return MHD_INVALID_NONCE;
+    return MHD_DAUTH_NONCE_STALE;
   }
 
   calculate_nonce (nonce_time,
@@ -1264,7 +1396,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
   if (0 != strcmp (nonce,
                    noncehashexp))
   {
-    return MHD_INVALID_NONCE;
+    return MHD_DAUTH_NONCE_WRONG;
   }
   if ( (0 == lookup_sub_value (cnonce,
                                sizeof (cnonce),
@@ -1291,7 +1423,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
     MHD_DLOG (daemon,
               _ ("Authentication failed, invalid format.\n"));
 #endif
-    return MHD_NO;
+    return MHD_DAUTH_WRONG_HEADER;
   }
   if (len != MHD_strx_to_uint64_n_ (nc,
                                     len,
@@ -1301,7 +1433,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
     MHD_DLOG (daemon,
               _ ("Authentication failed, invalid nc format.\n"));
 #endif
-    return MHD_NO;   /* invalid nonce format */
+    return MHD_DAUTH_WRONG_HEADER;   /* invalid nonce format */
   }
   if (0 == nci)
   {
@@ -1309,22 +1441,44 @@ digest_auth_check_all (struct MHD_Connection 
*connection,
     MHD_DLOG (daemon,
               _ ("Authentication failed, invalid 'nc' value.\n"));
 #endif
-    return MHD_NO;   /* invalid nc value */
+    return MHD_DAUTH_WRONG_HEADER;   /* invalid nc value */
   }
 
-  /*
-   * Checking if that combination of nonce and nc is sound
-   * and not a replay attack attempt. Refuse if nonce was not
-   * generated previously.
-   */
-  if (! check_nonce_nc (connection,
-                        nonce,
-                        nonce_len,
-                        nci))
+  if (1)
   {
-    return MHD_NO;
+    enum MHD_CheckNonceNC_ nonce_nc_check;
+    /*
+     * Checking if that combination of nonce and nc is sound
+     * and not a replay attack attempt. Refuse if nonce was not
+     * generated previously.
+     */
+    nonce_nc_check = check_nonce_nc (connection,
+                                     nonce,
+                                     nonce_len,
+                                     nonce_time,
+                                     nci);
+    if (MHD_DAUTH_NONCENC_STALE == nonce_nc_check)
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Stale nonce received. If this happens a lot, you should "
+                   "probably increase the size of the nonce array.\n"));
+#endif
+      return MHD_DAUTH_NONCE_STALE;
+    }
+    else if (MHD_DAUTH_NONCENC_WRONG == nonce_nc_check)
+    {
+#ifdef HAVE_MESSAGES
+      MHD_DLOG (daemon,
+                _ ("Received nonce that technically valid, but was not "
+                   "generated by MHD. This may indicate an attack 
attempt.\n"));
+#endif
+      return MHD_DAUTH_NONCE_WRONG;
+    }
+    mhd_assert (MHD_DAUTH_NONCENC_OK == nonce_nc_check);
   }
 
+  if (1)
   {
     char *uri;
 
@@ -1335,7 +1489,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
       MHD_DLOG (daemon,
                 _ ("Failed to allocate memory for auth header processing.\n"));
 #endif /* HAVE_MESSAGES */
-      return MHD_NO;
+      return MHD_DAUTH_ERROR;
     }
     if (0 == lookup_sub_value (uri,
                                left + 1,
@@ -1343,7 +1497,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
                                "uri"))
     {
       free (uri);
-      return MHD_NO;
+      return MHD_DAUTH_WRONG_HEADER;
     }
     if (NULL != digest)
     {
@@ -1396,9 +1550,10 @@ digest_auth_check_all (struct MHD_Connection *connection,
                 _ ("Authentication failed, URI does not match.\n"));
 #endif
       free (uri);
-      return MHD_NO;
+      return MHD_DAUTH_WRONG_URI;
     }
 
+    if (1)
     {
       const char *args = qmark;
 
@@ -1415,15 +1570,15 @@ digest_auth_check_all (struct MHD_Connection 
*connection,
                   _ ("Authentication failed, arguments do not match.\n"));
 #endif
         free (uri);
-        return MHD_NO;
+        return MHD_DAUTH_WRONG_URI;
       }
     }
     free (uri);
-    return (0 == strcmp (response,
-                         da->sessionkey))
-           ? MHD_YES
-           : MHD_NO;
   }
+  return (0 == strcmp (response,
+                       da->sessionkey))
+         ? MHD_DAUTH_OK
+         : MHD_DAUTH_RESPONSE_WRONG;
 }
 
 
@@ -1441,7 +1596,7 @@ digest_auth_check_all (struct MHD_Connection *connection,
  * @param nonce_timeout The amount of time for a nonce to be
  *      invalid in seconds
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @ingroup authentication
  */
 _MHD_EXTERN int
@@ -1520,7 +1675,7 @@ MHD_digest_auth_check (struct MHD_Connection *connection,
  *      invalid in seconds
  * @param algo digest algorithms allowed for verification
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @ingroup authentication
  */
 _MHD_EXTERN int
@@ -1531,18 +1686,25 @@ MHD_digest_auth_check2 (struct MHD_Connection 
*connection,
                         unsigned int nonce_timeout,
                         enum MHD_DigestAuthAlgorithm algo)
 {
+  enum MHD_DigestAuthResult res;
   SETUP_DA (algo, da);
 
   mhd_assert (NULL != password);
   if (0 == da.digest_size)
     MHD_PANIC (_ ("Wrong algo value.\n")); /* API violation! */
-  return digest_auth_check_all (connection,
-                                &da,
-                                realm,
-                                username,
-                                password,
-                                NULL,
-                                nonce_timeout);
+  res = digest_auth_check_all (connection,
+                               &da,
+                               realm,
+                               username,
+                               password,
+                               NULL,
+                               nonce_timeout);
+  if (MHD_DAUTH_OK == res)
+    return MHD_YES;
+  else if ((MHD_DAUTH_NONCE_STALE == res) || (MHD_DAUTH_NONCE_WRONG == res))
+    return MHD_INVALID_NONCE;
+  return MHD_NO;
+
 }
 
 
@@ -1560,7 +1722,7 @@ MHD_digest_auth_check2 (struct MHD_Connection *connection,
  *      invalid in seconds
  * @param algo digest algorithms allowed for verification
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @ingroup authentication
  */
 _MHD_EXTERN int
@@ -1572,18 +1734,24 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection 
*connection,
                                unsigned int nonce_timeout,
                                enum MHD_DigestAuthAlgorithm algo)
 {
+  enum MHD_DigestAuthResult res;
   SETUP_DA (algo, da);
 
   mhd_assert (NULL != digest);
   if ((da.digest_size != digest_size) || (0 == digest_size))
     MHD_PANIC (_ ("Digest size mismatch.\n")); /* API violation! */
-  return digest_auth_check_all (connection,
-                                &da,
-                                realm,
-                                username,
-                                NULL,
-                                digest,
-                                nonce_timeout);
+  res = digest_auth_check_all (connection,
+                               &da,
+                               realm,
+                               username,
+                               NULL,
+                               digest,
+                               nonce_timeout);
+  if (MHD_DAUTH_OK == res)
+    return MHD_YES;
+  else if ((MHD_DAUTH_NONCE_STALE == res) || (MHD_DAUTH_NONCE_WRONG == res))
+    return MHD_INVALID_NONCE;
+  return MHD_NO;
 }
 
 
@@ -1601,7 +1769,7 @@ MHD_digest_auth_check_digest2 (struct MHD_Connection 
*connection,
  * @param nonce_timeout The amount of time for a nonce to be
  *      invalid in seconds
  * @return #MHD_YES if authenticated, #MHD_NO if not,
- *      #MHD_INVALID_NONCE if nonce is invalid
+ *         #MHD_INVALID_NONCE if nonce is invalid or stale
  * @ingroup authentication
  */
 _MHD_EXTERN int
diff --git a/src/microhttpd/test_set_panic.c b/src/microhttpd/test_set_panic.c
index b1a24000..935312a7 100644
--- a/src/microhttpd/test_set_panic.c
+++ b/src/microhttpd/test_set_panic.c
@@ -213,6 +213,8 @@ _mhdErrorExit_func (const char *errDesc, const char 
*funcName, int lineNum)
 }
 
 
+#ifndef MHD_POSIX_SOCKETS
+
 /**
  * Pause execution for specified number of milliseconds.
  * @param ms the number of milliseconds to sleep
@@ -253,6 +255,8 @@ _MHD_sleep (uint32_t ms)
 }
 
 
+#endif /* ! MHD_POSIX_SOCKETS */
+
 /* Global parameters */
 static int verbose;                 /**< Be verbose */
 static uint16_t global_port;        /**< MHD daemons listen port number */
@@ -1121,12 +1125,6 @@ struct simpleQueryParams
   /* Non-zero to use chunked encoding for request body */
   int chunked;
 
-  /* Max size of data for single 'send()' call */
-  size_t step_size;
-
-  /* Limit for total amount of sent data */
-  size_t total_send_max;
-
   /* HTTP query result error flag */
   volatile int queryError;
 
@@ -1311,7 +1309,7 @@ doClientQueryInThread (struct MHD_Daemon *d,
   c = _MHD_dumbClient_create (p->queryPort, p->method, p->queryPath,
                               p->headers, p->req_body, p->req_body_size,
                               p->chunked);
-  _MHD_dumbClient_set_send_limits (c, p->step_size, p->total_send_max);
+  _MHD_dumbClient_set_send_limits (c, 1, 0);
 
   /* 'internal' polling should not be used in this test */
   mhd_assert (use_external_poll);
@@ -1347,7 +1345,6 @@ performTestQueries (struct MHD_Daemon *d, uint16_t d_port,
   qParam.req_body = (const uint8_t *) REQ_BODY;
   qParam.req_body_size = MHD_STATICSTR_LEN_ (REQ_BODY);
   qParam.chunked = 0;
-  qParam.step_size = 0;
 
   ahc_param->rq_url = EXPECTED_URI_BASE_PATH;
   ahc_param->rq_method = MHD_HTTP_METHOD_PUT;

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]