Ignore:
Timestamp:
Jan 18, 2008 6:49:29 PM (14 years ago)
Author:
bennylp
Message:

More ticket #452: SRTP creation/destruction, added use_srtp and srtp_secure_signaling in pjsua_account_config, updated pjsua

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_call.c

    r1698 r1709  
    215215#define LATE_SDP    0 
    216216 
     217static pj_bool_t pj_stristr(const pj_str_t *str, const pj_str_t *substr) 
     218{ 
     219    int i; 
     220 
     221    for (i=0; i<(str->slen-substr->slen); ++i) { 
     222        pj_str_t s; 
     223        s.ptr = str->ptr+i; 
     224        s.slen = substr->slen; 
     225 
     226        if (pj_stricmp(&s, substr)==0) 
     227            return PJ_TRUE; 
     228    } 
     229    return PJ_FALSE; 
     230} 
     231 
     232/* Get signaling secure level. 
     233 * Return: 
     234 *  0: if signaling is not secure 
     235 *  1: if TLS transport is used for immediate hop 
     236 *  2: if end-to-end signaling is secure. 
     237 * 
     238 * NOTE: 
     239 *  THIS IS WRONG. It should take into account the route-set. 
     240 */ 
     241static int get_secure_level(const pj_str_t *dst_uri) 
     242{ 
     243    const pj_str_t tls = pj_str(";transport=tls"); 
     244    const pj_str_t sips = pj_str("sips:"); 
     245 
     246    PJ_TODO(Fix_get_secure_level); 
     247 
     248    if (pj_stristr(dst_uri, &sips)) 
     249        return 2; 
     250    if (pj_stristr(dst_uri, &tls)) 
     251        return 1; 
     252    return 0; 
     253} 
     254 
    217255/* 
    218256 * Make outgoing call to the specified URI using the specified account. 
     
    325363 
    326364    /* Init media channel */ 
    327     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     365    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,  
     366                                      get_secure_level(dest_uri)); 
    328367    if (status != PJ_SUCCESS) { 
    329368        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    482521    pjsua_call *call; 
    483522    int call_id = -1; 
     523    int secure_level; 
    484524    pjmedia_sdp_session *offer, *answer; 
    485525    pj_status_t status; 
     
    580620    } 
    581621 
     622    /*  
     623     * Get which account is most likely to be associated with this incoming 
     624     * call. We need the account to find which contact URI to put for 
     625     * the call. 
     626     */ 
     627    acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata); 
     628 
     629    /* Get signaling security level, only when required by SRTP */ 
     630    if (pjsua_var.acc[acc_id].cfg.srtp_secure_signaling < 2) { 
     631        secure_level = PJSIP_TRANSPORT_IS_SECURE(rdata->tp_info.transport)!=0; 
     632    } else { 
     633        char *uri; 
     634        int uri_len; 
     635        pj_str_t dst; 
     636 
     637        uri = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); 
     638        uri_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 
     639                                  rdata->msg_info.msg->line.req.uri, 
     640                                  uri, PJSIP_MAX_URL_SIZE); 
     641        if (uri_len < 1) { 
     642            pjsua_perror(THIS_FILE, "Error analyzing dst URI",  
     643                         PJSIP_EURITOOLONG); 
     644            uri_len = 0; 
     645        } 
     646 
     647        dst.ptr = uri; 
     648        dst.slen = uri_len; 
     649 
     650        secure_level = get_secure_level(&dst); 
     651    } 
    582652 
    583653    /* Init media channel */ 
    584     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS); 
     654    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS,  
     655                                      secure_level); 
    585656    if (status != PJ_SUCCESS) { 
    586657        pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 
     
    618689    } 
    619690 
    620     /*  
    621      * Get which account is most likely to be associated with this incoming 
    622      * call. We need the account to find which contact URI to put for 
    623      * the call. 
    624      */ 
    625     acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata); 
    626  
    627691    /* Verify that we can handle the request. */ 
    628692    options |= PJSIP_INV_SUPPORT_100REL; 
     
    13211385 
    13221386    /* Init media channel */ 
    1323     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     1387    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
     1388                                      get_secure_level(&dlg->remote.info_str)); 
    13241389    if (status != PJ_SUCCESS) { 
    13251390        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    13901455 
    13911456    /* Init media channel */ 
    1392     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     1457    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
     1458                                      get_secure_level(&dlg->remote.info_str)); 
    13931459    if (status != PJ_SUCCESS) { 
    13941460        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    25092575        status = create_inactive_sdp( call, &answer ); 
    25102576    } else { 
     2577        int secure_level; 
    25112578 
    25122579        PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer", 
     
    25142581 
    25152582        /* Init media channel */ 
    2516         status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS); 
     2583        secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 
     2584        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 
     2585                                          secure_level); 
    25172586        if (status != PJ_SUCCESS) { 
    25182587            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    25622631        status = create_inactive_sdp( call, offer ); 
    25632632    } else { 
     2633        int secure_level; 
    25642634 
    25652635        PJ_LOG(4,(THIS_FILE, "Call %d: asked to send a new offer", 
     
    25672637 
    25682638        /* Init media channel */ 
    2569         status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     2639        secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 
     2640        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
     2641                                          secure_level); 
    25702642        if (status != PJ_SUCCESS) { 
    25712643            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
Note: See TracChangeset for help on using the changeset viewer.