From 1f7a7e336f0d2d0d4c67ee45478bf9b759e0dda8 Mon Sep 17 00:00:00 2001 From: Tihomir Culjaga Date: Sun, 25 Dec 2016 16:30:54 -0600 Subject: [PATCH] FS-9873 mod_verto a1-hash - squashed --- src/mod/endpoints/mod_verto/mod_verto.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_verto/mod_verto.c b/src/mod/endpoints/mod_verto/mod_verto.c index aa7678739b..e31e2894a2 100644 --- a/src/mod/endpoints/mod_verto/mod_verto.c +++ b/src/mod/endpoints/mod_verto/mod_verto.c @@ -890,6 +890,9 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * const char *passwd = NULL; const char *login = NULL; cJSON *json_ptr = NULL; + char *input = NULL; + char *a1_hash = NULL; + char a1_hash_buff[33] = ""; if (!params) { *code = CODE_AUTH_FAILED; @@ -1008,6 +1011,13 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * use_passwd = val; } else if (!strcasecmp(var, "jsonrpc-password")) { use_passwd = val; + } else if (!strcasecmp(var, "a1-hash")) { + use_passwd = val; + input = switch_mprintf("%s:%s:%s", id, domain, passwd); + switch_md5_string(a1_hash_buff, (void *) input, strlen(input)); + a1_hash = a1_hash_buff; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"a1-hash-plain = '%s' a1-hash-md5 = '%s'\n", input, a1_hash); + switch_safe_free(input); } else if (!strcasecmp(var, "verto-context")) { verto_context = val; } else if (!strcasecmp(var, "verto-dialplan")) { @@ -1035,17 +1045,21 @@ static switch_bool_t check_auth(jsock_t *jsock, cJSON *params, int *code, char * jsock->context = switch_core_strdup(jsock->pool, verto_context); } - if (zstr(use_passwd) || strcmp(passwd, use_passwd)) { + + if (zstr(use_passwd) || strcmp(a1_hash ? a1_hash : passwd, use_passwd)) { r = SWITCH_FALSE; *code = CODE_AUTH_FAILED; switch_snprintf(message, mlen, "Authentication Failure"); jsock->uid = NULL; login_fire_custom_event(jsock, params, 0, "Authentication Failure"); } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,"auth using %s\n",a1_hash ? "a1-hash" : "username & password"); r = SWITCH_TRUE; check_permissions(jsock, x_user, params); } + + switch_xml_free(x_user); }