Skip to content

Commit a856a90

Browse files
notrojclaude
andcommitted
* modules/aaa/mod_auth_digest.c: Remove "weird" override of AuthName
directive, which adds complexity for little benefit (avoids putting 20 bytes through SHA1 for each auth attempt). (set_realm): Remove function. (gen_nonce_hash): Create the nonce hash here from scratch. (create_digest_dir_config): Always allocate a config struct. Remove unused dir_name field from digest_config_rec. (set_qop): Fix inverted condition which rejected qop "auth" (the only valid value) instead of rejecting non-"auth" values. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c3e3fd3 commit a856a90

1 file changed

Lines changed: 5 additions & 52 deletions

File tree

modules/aaa/mod_auth_digest.c

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@
8383
/* struct to hold the configuration info */
8484

8585
typedef struct digest_config_struct {
86-
const char *dir_name;
8786
authn_provider_list *providers;
8887
apr_time_t nonce_lifetime;
8988
int check_nc;
@@ -462,52 +461,14 @@ static void initialize_child(apr_pool_t *p, server_rec *s)
462461

463462
static void *create_digest_dir_config(apr_pool_t *p, char *dir)
464463
{
465-
digest_config_rec *conf;
466-
467-
if (dir == NULL) {
468-
return NULL;
469-
}
464+
digest_config_rec *conf = apr_pcalloc(p, sizeof *conf);
470465

471-
conf = (digest_config_rec *) apr_pcalloc(p, sizeof(digest_config_rec));
472-
if (conf) {
473-
conf->nonce_lifetime = DFLT_NONCE_LIFE;
474-
conf->dir_name = apr_pstrdup(p, dir);
475-
conf->algorithm = DFLT_ALGORITHM;
476-
}
466+
conf->nonce_lifetime = DFLT_NONCE_LIFE;
467+
conf->algorithm = DFLT_ALGORITHM;
477468

478469
return conf;
479470
}
480471

481-
482-
/*
483-
* The realm is no longer precomputed because it may be an expression, which
484-
* makes this hooking of AuthName quite weird.
485-
*/
486-
static const char *set_realm(cmd_parms *cmd, void *config, const char *realm)
487-
{
488-
digest_config_rec *conf = (digest_config_rec *) config;
489-
#ifdef AP_DEBUG
490-
int i;
491-
492-
/* check that we got random numbers */
493-
for (i = 0; i < SECRET_LEN; i++) {
494-
if (secret[i] != 0)
495-
break;
496-
}
497-
ap_assert(i < SECRET_LEN);
498-
#endif
499-
500-
/* we precompute the part of the nonce hash that is constant (well,
501-
* the host:port would be too, but that varies for .htaccess files
502-
* and directives outside a virtual host section)
503-
*/
504-
apr_sha1_init(&conf->nonce_ctx);
505-
apr_sha1_update_binary(&conf->nonce_ctx, secret, SECRET_LEN);
506-
507-
508-
return DECLINE_CMD;
509-
}
510-
511472
static const char *add_authn_provider(cmd_parms *cmd, void *config,
512473
const char *arg)
513474
{
@@ -663,8 +624,6 @@ static const char *set_shmem_size(cmd_parms *cmd, void *config,
663624

664625
static const command_rec digest_cmds[] =
665626
{
666-
AP_INIT_TAKE1("AuthName", set_realm, NULL, OR_AUTHCFG,
667-
"The authentication realm (e.g. \"Members Only\")"),
668627
AP_INIT_ITERATE("AuthDigestProvider", add_authn_provider, NULL, OR_AUTHCFG,
669628
"specify the auth providers for a directory or location"),
670629
AP_INIT_ITERATE("AuthDigestQop", set_qop, NULL, OR_AUTHCFG,
@@ -1060,14 +1019,8 @@ static void gen_nonce_hash(char hash[NONCE_HASH_LEN+1], const char *timestr, con
10601019
unsigned char sha1[APR_SHA1_DIGESTSIZE];
10611020
apr_sha1_ctx_t ctx;
10621021

1063-
memcpy(&ctx, &conf->nonce_ctx, sizeof(ctx));
1064-
/*
1065-
apr_sha1_update_binary(&ctx, (const unsigned char *) server->server_hostname,
1066-
strlen(server->server_hostname));
1067-
apr_sha1_update_binary(&ctx, (const unsigned char *) &server->port,
1068-
sizeof(server->port));
1069-
*/
1070-
1022+
apr_sha1_init(&ctx);
1023+
apr_sha1_update_binary(&ctx, secret, SECRET_LEN);
10711024
apr_sha1_update_binary(&ctx, (const unsigned char *) realm, strlen(realm));
10721025

10731026
apr_sha1_update_binary(&ctx, (const unsigned char *) timestr, strlen(timestr));

0 commit comments

Comments
 (0)