Ignore:
Timestamp:
Oct 15, 2007 7:04:59 AM (17 years ago)
Author:
bennylp
Message:

Continuing ticket #396: tested digest AKAv1, implemented AKAv2, and some works in the authentication framework to support it

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsip/sip_auth_client.c

    r1489 r1500  
    4949 
    5050 
     51static void dup_bin(pj_pool_t *pool, pj_str_t *dst, const pj_str_t *src) 
     52{ 
     53    dst->slen = src->slen; 
     54 
     55    if (dst->slen) { 
     56        dst->ptr = (char*) pj_pool_alloc(pool, src->slen); 
     57        pj_memcpy(dst->ptr, src->ptr, src->slen); 
     58    } else { 
     59        dst->ptr = NULL; 
     60    } 
     61} 
     62 
    5163PJ_DEF(void) pjsip_cred_info_dup(pj_pool_t *pool, 
    5264                                 pjsip_cred_info *dst, 
     
    6173 
    6274    if ((dst->data_type & EXT_MASK) == PJSIP_CRED_DATA_EXT_AKA) { 
    63         pj_strdup(pool, &dst->ext.aka.k, &src->ext.aka.k); 
    64         pj_strdup(pool, &dst->ext.aka.op, &src->ext.aka.op); 
    65         pj_strdup(pool, &dst->ext.aka.amf, &src->ext.aka.amf); 
     75        dup_bin(pool, &dst->ext.aka.k, &src->ext.aka.k); 
     76        dup_bin(pool, &dst->ext.aka.op, &src->ext.aka.op); 
     77        dup_bin(pool, &dst->ext.aka.amf, &src->ext.aka.amf); 
    6678    } 
    6779} 
     
    223235                                   const pj_str_t *method) 
    224236{ 
    225     /* Check algorithm is supported. We only support MD5. */ 
    226     if (chal->algorithm.slen && pj_stricmp(&chal->algorithm, &pjsip_MD5_STR)) 
     237    const pj_str_t pjsip_AKAv1_MD5_STR = { "AKAv1-MD5", 9 }; 
     238 
     239    /* Check algorithm is supported. We support MD5 and AKAv1-MD5. */ 
     240    if (chal->algorithm.slen==0 || 
     241        (pj_stricmp(&chal->algorithm, &pjsip_MD5_STR) || 
     242         pj_stricmp(&chal->algorithm, &pjsip_AKAv1_MD5_STR))) 
    227243    { 
     244        ; 
     245    } 
     246    else { 
    228247        PJ_LOG(4,(THIS_FILE, "Unsupported digest algorithm \"%.*s\"", 
    229248                  chal->algorithm.slen, chal->algorithm.ptr)); 
     
    236255    pj_strdup(pool, &cred->nonce, &chal->nonce); 
    237256    pj_strdup(pool, &cred->uri, uri); 
    238     cred->algorithm = pjsip_MD5_STR; 
     257    pj_strdup(pool, &cred->algorithm, &chal->algorithm); 
    239258    pj_strdup(pool, &cred->opaque, &chal->opaque); 
    240      
     259 
    241260    /* Allocate memory. */ 
    242261    cred->response.ptr = (char*) pj_pool_alloc(pool, PJSIP_MD5STRLEN); 
     
    471490            if ((c[i].data_type & EXT_MASK) == PJSIP_CRED_DATA_EXT_AKA) { 
    472491 
    473 #if !PJSIP_HAS_DIGEST_AKAV1_AUTH 
    474                 pj_assert(!"PJSIP_HAS_DIGEST_AKAV1_AUTH is not enabled"); 
     492#if !PJSIP_HAS_DIGEST_AKA_AUTH 
     493                pj_assert(!"PJSIP_HAS_DIGEST_AKA_AUTH is not enabled"); 
    475494                return PJSIP_EAUTHINAKACRED; 
    476495#endif 
     
    480499 
    481500                /* Verify K len */ 
    482                 PJ_ASSERT_RETURN(c[i].ext.aka.k.slen == PJSIP_AKA_KLEN,  
     501                PJ_ASSERT_RETURN(c[i].ext.aka.k.slen <= PJSIP_AKA_KLEN,  
    483502                                 PJSIP_EAUTHINAKACRED); 
    484503 
    485504                /* Verify OP len */ 
    486                 PJ_ASSERT_RETURN(c[i].ext.aka.op.slen == PJSIP_AKA_OPLEN,  
     505                PJ_ASSERT_RETURN(c[i].ext.aka.op.slen <= PJSIP_AKA_OPLEN,  
    487506                                 PJSIP_EAUTHINAKACRED); 
    488507 
    489508                /* Verify AMF len */ 
    490                 PJ_ASSERT_RETURN(c[i].ext.aka.amf.slen == PJSIP_AKA_AMFLEN, 
     509                PJ_ASSERT_RETURN(c[i].ext.aka.amf.slen <= PJSIP_AKA_AMFLEN, 
    491510                                 PJSIP_EAUTHINAKACRED); 
    492511 
     
    793812                           &sent_auth->credential.common.realm )==0) 
    794813            { 
    795                 break; 
     814                /* If this authorization has empty response, remove it. */ 
     815                if (pj_stricmp(&sent_auth->scheme, &pjsip_DIGEST_STR)==0 && 
     816                    sent_auth->credential.digest.response.slen == 0) 
     817                { 
     818                    /* This is empty authorization, remove it. */ 
     819                    hdr = hdr->next; 
     820                    pj_list_erase(sent_auth); 
     821                    continue; 
     822                } else { 
     823                    /* Found previous authorization attempt */ 
     824                    break; 
     825                } 
    796826            } 
    797827        } 
Note: See TracChangeset for help on using the changeset viewer.