132 size_t auth_object_count;
133 pjsip_www_authenticate_hdr *auth_hdr =
NULL;
134 pj_status_t res = PJ_SUCCESS;
135 pjsip_hdr_e search_type;
137 pjsip_cred_info *creds_array;
150 AST_VECTOR(cred_info, pjsip_cred_info) auth_creds;
153 if (search_type == PJSIP_H_OTHER) {
163 if (auth_object_count == 0) {
187 while ((auth_hdr = pjsip_msg_find_hdr(
challenge->msg_info.msg,
188 search_type, auth_hdr ? auth_hdr->next :
NULL))) {
189 int exact_match_index = -1;
190 int wildcard_match_index = -1;
192 pjsip_cred_info auth_cred;
195 memset(&auth_cred, 0,
sizeof(auth_cred));
210 ast_debug(3,
"Skipping header with realm '%.*s' and unsupported '%.*s' algorithm \n",
211 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr,
212 (
int)auth_hdr->challenge.digest.algorithm.slen, auth_hdr->challenge.digest.algorithm.ptr);
224 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr);
227 ast_debug(3,
"Searching auths to find matching ones for header with realm '%.*s' and algorithm '%.*s'\n",
228 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr,
229 (
int)auth_hdr->challenge.digest.algorithm.slen, auth_hdr->challenge.digest.algorithm.ptr);
240 for (i = 0; i < auth_object_count; ++i) {
250 if (pj_stricmp2(&auth_hdr->challenge.digest.realm, auth->
realm) == 0) {
253 exact_match_index = i;
269 if (wildcard_match_index < 0
272 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr);
273 wildcard_match_index = i;
277 if (exact_match_index < 0 && wildcard_match_index < 0) {
282 ast_debug(3,
"No auth matching realm or no wildcard found for realm '%.*s'\n",
283 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr);
287 if (exact_match_index >= 0) {
291 match_index = exact_match_index;
294 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr);
299 match_index = wildcard_match_index;
302 (
int)auth_hdr->challenge.digest.realm.slen, auth_hdr->challenge.digest.realm.ptr);
309 auth_cred.realm = auth_hdr->challenge.common.realm;
310 pj_cstr(&auth_cred.username, auth->
auth_user);
311 pj_cstr(&auth_cred.scheme,
"digest");
312 switch (auth->
type) {
314 pj_cstr(&auth_cred.data, auth->
auth_pass);
315 auth_cred.data_type = PJSIP_CRED_DATA_PLAIN_PASSWD;
318 pj_cstr(&auth_cred.data, auth->
md5_creds);
319 auth_cred.data_type = PJSIP_CRED_DATA_DIGEST;
326 "Trying to set artificial outbound auth credentials shouldn't happen.\n");
344 if (res != PJ_SUCCESS) {
362 res = PJSIP_ENOCREDENTIAL;
384 res = pjsip_auth_clt_set_credentials(auth_sess, cred_count, creds_array);
386 if (res == PJ_SUCCESS) {
387 ast_debug(3,
"Set %"PRIu64
" credentials in auth session\n", cred_count);
389 ast_log(
LOG_ERROR,
"Failed to set %"PRIu64
" credentials in auth session\n", cred_count);
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
const ast_string_field md5_creds
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
char * ast_str_truncate(struct ast_str *buf, ssize_t len)
Truncates the enclosed string to the given length.
#define ast_strlen_zero(foo)
#define ast_debug(level,...)
Log a DEBUG message.
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
const char * ast_sorcery_object_get_id(const void *object)
Get the unique identifier of a sorcery object.
static void challenge(const char *realm, pjsip_tx_data *tdata, const pjsip_rx_data *rdata, int is_stale)
astobj2 callback for adding digest challenges to responses
#define AST_VECTOR_STEAL_ELEMENTS(vec)
Steal the elements from a vector and reinitialize.
#define AST_VECTOR(name, type)
Define a vector structure.
static pjsip_hdr_e get_auth_search_type(pjsip_rx_data *challenge)
const ast_string_field realm
int ast_strings_equal(const char *str1, const char *str2)
Compare strings for equality checking for NULL.
const ast_string_field auth_pass
enum ast_sip_auth_type type
static void * cleanup(void *unused)
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
static int is_digest_algorithm_supported(pjsip_www_authenticate_hdr *auth_hdr)
const ast_string_field auth_user
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.