From cfea6bdd44feb1d70bf85e24ebdad037ffd37229 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Mon, 18 Jun 2007 11:01:42 +0000 Subject: Fixed ticket #231: Add the ability to respond to any realms in SIP authentication git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1370 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip/src/pjsip/sip_auth_client.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/pjsip/src/pjsip/sip_auth_client.c b/pjsip/src/pjsip/sip_auth_client.c index 931d2ea3..7978da27 100644 --- a/pjsip/src/pjsip/sip_auth_client.c +++ b/pjsip/src/pjsip/sip_auth_client.c @@ -69,6 +69,7 @@ void pjsip_auth_create_digest( pj_str_t *result, const pj_str_t *cnonce, const pj_str_t *qop, const pj_str_t *uri, + const pj_str_t *realm, const pjsip_cred_info *cred_info, const pj_str_t *method) { @@ -88,7 +89,7 @@ void pjsip_auth_create_digest( pj_str_t *result, pj_md5_init(&pms); MD5_APPEND( &pms, cred_info->username.ptr, cred_info->username.slen); MD5_APPEND( &pms, ":", 1); - MD5_APPEND( &pms, cred_info->realm.ptr, cred_info->realm.slen); + MD5_APPEND( &pms, realm->ptr, realm->slen); MD5_APPEND( &pms, ":", 1); MD5_APPEND( &pms, cred_info->data.ptr, cred_info->data.slen); pj_md5_final(&pms, digest); @@ -221,7 +222,7 @@ static pj_status_t respond_digest( pj_pool_t *pool, /* Convert digest to string and store in chal->response. */ pjsip_auth_create_digest( &cred->response, &cred->nonce, NULL, NULL, - NULL, uri, cred_info, method); + NULL, uri, &chal->realm, cred_info, method); } else if (has_auth_qop(pool, &chal->qop)) { /* Server requires quality of protection. @@ -239,8 +240,8 @@ static pj_status_t respond_digest( pj_pool_t *pool, } pjsip_auth_create_digest( &cred->response, &cred->nonce, &cred->nc, - cnonce, &pjsip_AUTH_STR, uri, cred_info, - method ); + cnonce, &pjsip_AUTH_STR, uri, &chal->realm, + cred_info, method ); } else { /* Server requires quality protection that we don't support. */ @@ -328,11 +329,27 @@ static const pjsip_cred_info* auth_find_cred( const pjsip_auth_clt_sess *sess, const pj_str_t *auth_scheme) { unsigned i; + int wildcard = -1; + PJ_UNUSED_ARG(auth_scheme); + for (i=0; icred_cnt; ++i) { if (pj_stricmp(&sess->cred_info[i].realm, realm) == 0) return &sess->cred_info[i]; + else if (sess->cred_info[i].realm.slen == 1 && + sess->cred_info[i].realm.ptr[0] == '*') + { + wildcard = i; + } } + + /* No matching realm. See if we have credential with wildcard ('*') + * as the realm. + */ + if (wildcard != -1) + return &sess->cred_info[wildcard]; + + /* Nothing is suitable */ return NULL; } -- cgit v1.2.3