Skip to content

Commit

Permalink
uac_auth(): Fix corner-case with missing "algorithm=" in 401
Browse files Browse the repository at this point in the history
Make sure to convert ALG_UNSPEC to ALG_MD5 before doing the bitmask
conversion, as otherwise the matching will fail!
  • Loading branch information
liviuchircu committed Oct 3, 2024
1 parent 3fa1be8 commit 42fa1db
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion lib/digest_auth/digest_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ int dauth_algorithm_check(const struct authenticate_body *auth,
if (!digest_algorithm_available(auth->algorithm))
return (0);
damp = (const struct dauth_algorithm_match *)mdp->argp;
return (ALG2ALGFLG(auth->algorithm) & damp->algmask);
return (ALG2ALGFLG(auth->algorithm==ALG_UNSPEC ? ALG_MD5:auth->algorithm)
& damp->algmask);
}

int dauth_fixup_algorithms(void** param)
Expand Down
2 changes: 1 addition & 1 deletion lib/digest_auth/digest_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ struct digest_auth_credential {
};

struct dauth_algorithm_match {
int algmask;
unsigned algmask;
};

#define DAUTH_ALGMATCH_ALL (const struct dauth_algorithm_match){.algmask = ~0}
Expand Down
4 changes: 2 additions & 2 deletions modules/uac/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static int uac_auth_dlg_leg(struct dlg_cell *dlg, str *tag)
return callee_idx(dlg);
}

int uac_auth( struct sip_msg *msg, int algmask)
int uac_auth( struct sip_msg *msg, unsigned algmask)
{
struct authenticate_body *auth = NULL;
str msg_body;
Expand Down Expand Up @@ -307,7 +307,7 @@ int uac_auth( struct sip_msg *msg, int algmask)
}

if (auth == NULL) {
LM_ERR("Unable to extract authentication info\n");
LM_ERR("Unable to extract a compatible authentication challenge\n");
goto error;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/uac_auth/uac_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct authenticate_nc_cnonce {
};


int uac_auth( struct sip_msg *msg, int algmask);
int uac_auth( struct sip_msg *msg, unsigned algmask);
int do_uac_auth(str *msg_body, str *method, str *uri, struct uac_credential *crd,
struct authenticate_body *auth, struct authenticate_nc_cnonce *auth_nc_cnonce,
struct digest_auth_response *response) __attribute__ ((warn_unused_result));;
Expand Down

0 comments on commit 42fa1db

Please sign in to comment.