Changeset 1774


Ignore:
Timestamp:
Feb 2, 2008 5:07:18 PM (16 years ago)
Author:
bennylp
Message:

More ticket #61: fixed signaling security level calculation for SRTP

Location:
pjproject/trunk/pjsip
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/include/pjsua-lib/pjsua_internal.h

    r1742 r1774  
    4444    pj_time_val          dis_time;  /**< Disconnect time.                   */ 
    4545    pjsua_acc_id         acc_id;    /**< Account index being used.          */ 
     46    int                  secure_level;/**< Signaling security level.        */ 
    4647    pjsua_call_media_status media_st;/**< Media state.                      */ 
    4748    pjmedia_dir          media_dir; /**< Media direction.                   */ 
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r1757 r1774  
    261261 *  1: if TLS transport is used for immediate hop 
    262262 *  2: if end-to-end signaling is secure. 
    263  * 
    264  * NOTE: 
    265  *  THIS IS WRONG. It should take into account the route-set. 
    266  */ 
    267 static int get_secure_level(const pj_str_t *dst_uri) 
     263 */ 
     264static int get_secure_level(pjsua_acc_id acc_id, const pj_str_t *dst_uri) 
    268265{ 
    269266    const pj_str_t tls = pj_str(";transport=tls"); 
    270267    const pj_str_t sips = pj_str("sips:"); 
    271  
    272     PJ_TODO(Fix_get_secure_level); 
     268    pjsua_acc *acc = &pjsua_var.acc[acc_id]; 
    273269 
    274270    if (pj_stristr(dst_uri, &sips)) 
    275271        return 2; 
    276     if (pj_stristr(dst_uri, &tls)) 
    277         return 1; 
     272     
     273    if (!pj_list_empty(&acc->route_set)) { 
     274        pjsip_route_hdr *r = acc->route_set.next; 
     275        pjsip_uri *uri = r->name_addr.uri; 
     276        pjsip_sip_uri *sip_uri; 
     277         
     278        sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
     279        if (pj_stricmp2(&sip_uri->transport_param, "tls")==0) 
     280            return 1; 
     281 
     282    } else { 
     283        if (pj_stristr(dst_uri, &tls)) 
     284            return 1; 
     285    } 
     286 
    278287    return 0; 
    279288} 
     289 
     290static int call_get_secure_level(pjsua_call *call) 
     291{ 
     292    if (call->inv->dlg->secure) 
     293        return 2; 
     294 
     295    if (!pj_list_empty(&call->inv->dlg->route_set)) { 
     296        pjsip_route_hdr *r = call->inv->dlg->route_set.next; 
     297        pjsip_uri *uri = r->name_addr.uri; 
     298        pjsip_sip_uri *sip_uri; 
     299         
     300        sip_uri = (pjsip_sip_uri*)pjsip_uri_get_uri(uri); 
     301        if (pj_stricmp2(&sip_uri->transport_param, "tls")==0) 
     302            return 1; 
     303 
     304    } else { 
     305        pjsip_sip_uri *sip_uri; 
     306 
     307        if (PJSIP_URI_SCHEME_IS_SIPS(call->inv->dlg->target)) 
     308            return 2; 
     309        if (!PJSIP_URI_SCHEME_IS_SIP(call->inv->dlg->target)) 
     310            return 0; 
     311 
     312        sip_uri = (pjsip_sip_uri*) pjsip_uri_get_uri(call->inv->dlg->target); 
     313        if (pj_stricmp2(&sip_uri->transport_param, "tls")==0) 
     314            return 1; 
     315    } 
     316 
     317    return 0; 
     318} 
     319 
    280320 
    281321/* 
     
    385425    } 
    386426 
     427    /* Calculate call's secure level */ 
     428    call->secure_level = get_secure_level(acc_id, dest_uri); 
     429 
    387430    /* Init media channel */ 
    388431    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,  
    389                                       get_secure_level(dest_uri), NULL); 
     432                                      call->secure_level, NULL); 
    390433    if (status != PJ_SUCCESS) { 
    391434        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    545588    pjsua_call *call; 
    546589    int call_id = -1; 
    547     int secure_level, sip_err_code; 
     590    int sip_err_code; 
    548591    pjmedia_sdp_session *offer, *answer; 
    549592    pj_status_t status; 
     
    648691    acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata); 
    649692 
    650 #if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 
    651     /* Get signaling security level, only when required by SRTP */ 
    652     if (pjsua_var.acc[acc_id].cfg.srtp_secure_signaling < 2) { 
    653         secure_level = PJSIP_TRANSPORT_IS_SECURE(rdata->tp_info.transport)!=0; 
    654     } else  
    655 #endif 
    656  
    657     { 
    658         char *uri; 
    659         int uri_len; 
    660         pj_str_t dst; 
    661  
    662         uri = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); 
    663         uri_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 
    664                                   rdata->msg_info.msg->line.req.uri, 
    665                                   uri, PJSIP_MAX_URL_SIZE); 
    666         if (uri_len < 1) { 
    667             pjsua_perror(THIS_FILE, "Error analyzing dst URI",  
    668                          PJSIP_EURITOOLONG); 
    669             uri_len = 0; 
    670         } 
    671  
    672         dst.ptr = uri; 
    673         dst.slen = uri_len; 
    674  
    675         secure_level = get_secure_level(&dst); 
    676     } 
     693    /* Get call's secure level */ 
     694    if (PJSIP_URI_SCHEME_IS_SIPS(rdata->msg_info.msg->line.req.uri)) 
     695        call->secure_level = 2; 
     696    else if (PJSIP_TRANSPORT_IS_SECURE(rdata->tp_info.transport)) 
     697        call->secure_level = 1; 
     698    else 
     699        call->secure_level = 0; 
    677700 
    678701    /* Init media channel */ 
    679702    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS,  
    680                                       secure_level, &sip_err_code); 
     703                                      call->secure_level, &sip_err_code); 
    681704    if (status != PJ_SUCCESS) { 
    682705        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    14131436    } 
    14141437 
     1438    /* Update call secure level */ 
     1439    call->secure_level = call_get_secure_level(call); 
     1440 
    14151441    /* Init media channel */ 
    14161442    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
    1417                                       get_secure_level(&dlg->remote.info_str), 
    1418                                       NULL); 
     1443                                      call->secure_level, NULL); 
    14191444    if (status != PJ_SUCCESS) { 
    14201445        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    14841509        return status; 
    14851510 
     1511    /* Update call's secure level */ 
     1512    call->secure_level = call_get_secure_level(call); 
     1513 
    14861514    /* Init media channel */ 
    14871515    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
    1488                                       get_secure_level(&dlg->remote.info_str), 
    1489                                       NULL); 
     1516                                      call->secure_level, NULL); 
    14901517    if (status != PJ_SUCCESS) { 
    14911518        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    26082635        status = create_inactive_sdp( call, &answer ); 
    26092636    } else { 
    2610         int secure_level; 
    2611  
    26122637        PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer", 
    26132638                  call->index)); 
    26142639 
     2640        /* Update call's secure level */ 
     2641        call->secure_level = call_get_secure_level(call); 
     2642 
    26152643        /* Init media channel */ 
    2616         secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 
    26172644        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 
    2618                                           secure_level, NULL); 
     2645                                          call->secure_level, NULL); 
    26192646        if (status != PJ_SUCCESS) { 
    26202647            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    26642691        status = create_inactive_sdp( call, offer ); 
    26652692    } else { 
    2666         int secure_level; 
    2667  
    26682693        PJ_LOG(4,(THIS_FILE, "Call %d: asked to send a new offer", 
    26692694                  call->index)); 
    26702695 
     2696        /* Update call's secure level */ 
     2697        call->secure_level = call_get_secure_level(call); 
     2698 
    26712699        /* Init media channel */ 
    2672         secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 
    26732700        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
    2674                                           secure_level, NULL); 
     2701                                          call->secure_level, NULL); 
    26752702        if (status != PJ_SUCCESS) { 
    26762703            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
Note: See TracChangeset for help on using the changeset viewer.