From 981d787acf5f598f185d0d0ce8091b4e202f4d86 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Tue, 29 Oct 2019 09:15:49 +0100 Subject: [PATCH] uac: optional param for uac_auth() to specify auth mode - if mode is set to 1, then the password is provided in ha1 format --- src/modules/uac/auth.c | 20 +++++++++++++++----- src/modules/uac/auth.h | 5 ++++- src/modules/uac/uac.c | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/modules/uac/auth.c b/src/modules/uac/auth.c index a412dae9758..0f5e6d4a9b6 100644 --- a/src/modules/uac/auth.c +++ b/src/modules/uac/auth.c @@ -375,9 +375,10 @@ static inline int apply_urihdr_changes( struct sip_msg *req, return -1; } - - -int uac_auth(sip_msg_t *msg) +/** + * + */ +int uac_auth_mode(sip_msg_t *msg, int mode) { static struct authenticate_body auth; struct uac_credential *crd; @@ -451,6 +452,10 @@ int uac_auth(sip_msg_t *msg) goto error; } + if(mode & UACAUTH_MODE_HA1) { + crd->aflags |= UAC_FLCRED_HA1; + } + /* do authentication */ do_uac_auth( &msg->first_line.u.request.method, &t->uac[branch].uri, crd, &auth, response); @@ -489,5 +494,10 @@ int uac_auth(sip_msg_t *msg) return -1; } - - +/** + * + */ +int uac_auth(sip_msg_t *msg) +{ + return uac_auth_mode(msg, 0); +} \ No newline at end of file diff --git a/src/modules/uac/auth.h b/src/modules/uac/auth.h index 274b32e85d1..67d6406b7a3 100644 --- a/src/modules/uac/auth.h +++ b/src/modules/uac/auth.h @@ -47,6 +47,8 @@ typedef struct authenticate_body { str *cnonce; } uac_authenticate_body_t; +#define UACAUTH_MODE_HA1 (1<<0) + #define AUTHENTICATE_MD5 (1<<0) #define AUTHENTICATE_MD5SESS (1<<1) #define AUTHENTICATE_STALE (1<<2) @@ -67,7 +69,8 @@ void destroy_credentials(void); struct hdr_field *get_autenticate_hdr(struct sip_msg *rpl, int rpl_code); -int uac_auth( struct sip_msg *msg); +int uac_auth(sip_msg_t *msg); +int uac_auth_mode(sip_msg_t *msg, int mode); void do_uac_auth(str *method, str *uri, struct uac_credential *crd, diff --git a/src/modules/uac/uac.c b/src/modules/uac/uac.c index 7692600b0fe..3212960f4ef 100644 --- a/src/modules/uac/uac.c +++ b/src/modules/uac/uac.c @@ -98,6 +98,7 @@ static int w_restore_from(struct sip_msg* msg, char* p1, char* p2); static int w_replace_to(struct sip_msg* msg, char* p1, char* p2); static int w_restore_to(struct sip_msg* msg, char* p1, char* p2); static int w_uac_auth(struct sip_msg* msg, char* str, char* str2); +static int w_uac_auth_mode(struct sip_msg* msg, char* pmode, char* str2); static int w_uac_reg_lookup(struct sip_msg* msg, char* src, char* dst); static int w_uac_reg_status(struct sip_msg* msg, char* src, char* dst); static int w_uac_reg_request_to(struct sip_msg* msg, char* src, char* mode_s); @@ -132,6 +133,8 @@ static cmd_export_t cmds[]={ REQUEST_ROUTE | BRANCH_ROUTE }, {"uac_restore_to", (cmd_function)w_restore_to, 0, 0, 0, REQUEST_ROUTE }, {"uac_auth", (cmd_function)w_uac_auth, 0, 0, 0, FAILURE_ROUTE }, + {"uac_auth_mode", (cmd_function)w_uac_auth_mode, 1, + fixup_igp_null, fixup_free_igp_null, FAILURE_ROUTE }, {"uac_req_send", (cmd_function)w_uac_req_send, 0, 0, 0, ANY_ROUTE}, {"uac_reg_lookup", (cmd_function)w_uac_reg_lookup, 2, fixup_spve_pvar, fixup_free_spve_pvar, ANY_ROUTE }, @@ -615,6 +618,22 @@ static int ki_uac_auth(struct sip_msg* msg) return (uac_auth(msg)==0)?1:-1; } +static int w_uac_auth_mode(struct sip_msg* msg, char* pmode, char* str2) +{ + int imode = 0; + + if(fixup_get_ivalue(msg, (gparam_t*)pmode, &imode)<0) { + LM_ERR("failed to get the mode parameter\n"); + return -1; + } + return (uac_auth_mode(msg, imode)==0)?1:-1; +} + +static int ki_uac_auth_mode(sip_msg_t* msg, int mode) +{ + return (uac_auth_mode(msg, mode)==0)?1:-1; +} + static int w_uac_reg_lookup(struct sip_msg* msg, char* src, char* dst) { pv_spec_t *dpv; @@ -757,6 +776,11 @@ static sr_kemi_t sr_kemi_uac_exports[] = { { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } }, + { str_init("uac"), str_init("uac_auth_mode"), + SR_KEMIP_INT, ki_uac_auth_mode, + { SR_KEMIP_INT, SR_KEMIP_NONE, SR_KEMIP_NONE, + SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE } + }, { str_init("uac"), str_init("uac_req_send"), SR_KEMIP_INT, ki_uac_req_send, { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,