45#define FUZZ_HARNESS_NAME "fuzz_auth_header"
62static const size_t pool_sizes[] = { 256, 512, 1024, 4096, 32768 };
76 char *r = (
char *) malloc (len + 1);
106 "%s: digest headers parsed=%lu rejected=%lu; "
107 "basic headers parsed=%lu rejected=%lu\n",
120 const char *upload_data,
121 size_t *upload_data_size,
124 (void) cls; (void) connection; (void) url; (void) method; (void) version;
125 (void) upload_data; (void) upload_data_size; (void) req_cls;
166check_param (
const struct MHD_RqDAuthParam *pm,
173 if (
NULL == pm->value.str)
175 if (0 != pm->value.len)
177 (void) snprintf (msg,
sizeof (msg),
178 "digest parameter '%s' has NULL string but "
179 "non-zero length", what);
184 if ( (pm->value.str < base) ||
185 (pm->value.str > base + base_len) ||
186 (pm->value.len > base_len) ||
187 (pm->value.str + pm->value.len > base + base_len) )
189 (void) snprintf (msg,
sizeof (msg),
190 "digest parameter '%s' points outside of the "
191 "Authorization header value", what);
207 struct MemoryPool *pool;
226 value = (
char *) malloc (vlen + 1);
229 memcpy (value,
data + 1, vlen);
239 memset (&c, 0,
sizeof (c));
240 memset (&h, 0,
sizeof (h));
253 if (0 == (sel & 0x01))
255 const struct MHD_RqDAuth *da;
257 da = MHD_get_rq_dauth_params_ (&c);
263 check_param (&da->nonce, value, vlen,
"nonce");
264 check_param (&da->opaque, value, vlen,
"opaque");
265 check_param (&da->response, value, vlen,
"response");
266 check_param (&da->username, value, vlen,
"username");
267 check_param (&da->username_ext, value, vlen,
"username*");
268 check_param (&da->realm, value, vlen,
"realm");
269 check_param (&da->uri, value, vlen,
"uri");
270 check_param (&da->qop_raw, value, vlen,
"qop");
271 check_param (&da->cnonce, value, vlen,
"cnonce");
272 check_param (&da->nc, value, vlen,
"nc");
274 if (da != MHD_get_rq_dauth_params_ (&c))
280 if (0 != (sel & 0x01))
284 ba = MHD_get_rq_bauth_params_ (&c);
295 "Authorization header value");
299 size_t need = MHD_base64_max_dec_size_ (ba->
token68.
len);
300 uint8_t *bin = (uint8_t *) malloc ((0 == need) ? 1 : need);
304 size_t r = MHD_base64_to_bin_n (ba->
token68.
str,
310 "MHD_base64_max_dec_size_()");
315 if (ba != MHD_get_rq_bauth_params_ (&c))
335 if (0 != (sel & 0x02))
352 algo3s[(sel >> 5) % (
sizeof (algo3s) /
sizeof (algo3s[0]))];
362 size_t o1 = vlen / 3;
363 size_t o2 = (2 * vlen) / 3;
365 char *realm =
fuzz_dup_n (value + o1, o2 - o1);
366 char *pass =
fuzz_dup_n (value + o2, vlen - o2);
368 if ( (
NULL != user) && (
NULL != realm) && (
NULL != pass) )
373 size_t claim = hs - (size_t) (
data[0] % (
unsigned int) (hs + 1u));
374 void *bin = malloc (claim);
385 size_t need = (0 != hs) ? (2 * hs + 1) : 1;
386 size_t claim = need - (size_t) (
data[0] % (
unsigned int) (need + 1u));
387 char *hex = (
char *) malloc (claim);
414 "username",
"username*",
"realm",
"nonce",
"uri",
"response",
"algorithm",
415 "qop",
"nc",
"cnonce",
"opaque",
"userhash",
"charset",
"domain",
416 "unknown",
"",
"USERNAME",
"user name"
420 "\"user\"",
"user",
"\"\"",
"\"a\\\"b\"",
"\"a\\\\\"",
"\"\\\"",
421 "UTF-8''a%20b",
"utf-8''%41",
"''",
"'",
"true",
"false",
"TRUE",
422 "auth",
"auth-int",
"auth,auth-int",
"\"auth\"",
"MD5",
"SHA-256",
423 "SHA-512-256",
"BOGUS",
"\"SHA-256\"",
"00000001",
"ffffffff",
424 "0123456789abcdef0123456789abcdef",
425 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
426 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
427 "\"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
428 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\""
438 unsigned int nparams;
445 buf[len++] = (uint8_t) ((
fuzz_byte (rng) & 0xFE) | (basic ? 1u : 0u));
451 const char *s_ = (s); \
452 size_t l_ = strlen (s_); \
453 if (len + l_ >= cap) \
455 memcpy (buf + len, s_, l_); \
465 for (i = 0; (i < n) && (len < cap); i++)
467 (uint8_t)
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
474 for (i = 0; i < nparams; i++)
480 /
sizeof (
char *)))]);
485 /
sizeof (
char *)))]);
502#define ASEED(t) { t, sizeof (t) - 1 }
505 ASEED (
"\x00" "Digest username=\"user\", realm=\"TestRealm\", "
506 "nonce=\"0123456789abcdef\", uri=\"/a\", qop=auth, nc=00000001, "
507 "cnonce=\"x\", algorithm=MD5, response=\"0123456789abcdef\""),
508 ASEED (
"\x00" "Digest algorithm=BOGUS"),
509 ASEED (
"\x00" "Digest algorithm="),
510 ASEED (
"\x00" "Digest username*=UTF-8''a%20b"),
511 ASEED (
"\x00" "Digest username*=''"),
512 ASEED (
"\x00" "Digest username=\"\\\""),
513 ASEED (
"\x00" "Digest userhash=true, username=\"aaaa\""),
514 ASEED (
"\x00" "Digest response=\""
515 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
516 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef\""),
517 ASEED (
"\x00" "Digest"),
518 ASEED (
"\x00" "Digest ,,,,,"),
519 ASEED (
"\x00" "Digest nc=\"ffffffffffffffffffffffff\""),
520 ASEED (
"\x01" "Basic dXNlcjpwYXNz"),
521 ASEED (
"\x01" "Basic "),
522 ASEED (
"\x01" "Basic ===="),
523 ASEED (
"\x01" "Basic QQ==QQ=="),
537 ASEED (
"\x02" "user:TestRealm:pass"),
538 ASEED (
"\x22" "user:TestRealm:pass"),
539 ASEED (
"\x42" "user:TestRealm:pass"),
540 ASEED (
"\xa2" "user:TestRealm:pass"),
545 ASEED (
"\x02" "Digest username=\"user\", realm=\"TestRealm\"")
556static const uint8_t *
561 return (
const uint8_t *)
ah_seeds[idx].txt;
Shared, header-only fuzzing driver for the MHD in-process fuzzers.
static FUZZ_UNUSED int fuzz_verbose
static FUZZ_UNUSED uint32_t fuzz_below(struct fuzz_rng *r, uint32_t n)
static FUZZ_UNUSED uint8_t fuzz_byte(struct fuzz_rng *r)
static FUZZ_UNUSED void fuzz_report_finding(const char *what)
static FUZZ_UNUSED int fuzz_chance(struct fuzz_rng *r, uint32_t n)
Declarations for HTTP authorisation general functions.
_MHD_EXTERN enum MHD_Result MHD_digest_auth_calc_userdigest(enum MHD_DigestAuthAlgo3 algo3, const char *username, const char *realm, const char *password, void *userdigest_bin, size_t bin_buf_size)
_MHD_EXTERN enum MHD_Result MHD_digest_auth_calc_userhash_hex(enum MHD_DigestAuthAlgo3 algo3, const char *username, const char *realm, char *userhash_hex, size_t hex_buf_size)
_MHD_EXTERN size_t MHD_digest_get_hash_size(enum MHD_DigestAuthAlgo3 algo3)
_MHD_EXTERN enum MHD_Result MHD_digest_auth_calc_userhash(enum MHD_DigestAuthAlgo3 algo3, const char *username, const char *realm, void *userhash_bin, size_t bin_buf_size)
_MHD_EXTERN void MHD_stop_daemon(struct MHD_Daemon *daemon)
_MHD_EXTERN struct MHD_Daemon * MHD_start_daemon(unsigned int flags, uint16_t port, MHD_AcceptPolicyCallback apc, void *apc_cls, MHD_AccessHandlerCallback dh, void *dh_cls,...)
MHD internal shared structures.
@ MHD_CONNECTION_HEADERS_PROCESSED
void MHD_pool_destroy(struct MemoryPool *pool)
struct MemoryPool * MHD_pool_create(size_t max)
memory pool; mostly used for efficient (de)allocation for each connection and bounding memory use for...
Header for string manipulating helpers.
#define MHD_STATICSTR_LEN_(macro)
@ MHD_DIGEST_AUTH_ALGO3_MD5_SESSION
@ MHD_DIGEST_AUTH_ALGO3_MD5
@ MHD_DIGEST_AUTH_ALGO3_SHA256
@ MHD_DIGEST_AUTH_ALGO3_SHA512_256_SESSION
@ MHD_DIGEST_AUTH_ALGO3_SHA256_SESSION
@ MHD_DIGEST_AUTH_ALGO3_SHA512_256
@ MHD_USE_NO_LISTEN_SOCKET
enum MHD_CONNECTION_STATE state
struct MHD_Daemon * daemon
struct MHD_HTTP_Req_Header * headers_received
struct MHD_HTTP_Req_Header * headers_received_tail
struct _MHD_str_w_len token68