Ignore:
Timestamp:
Jan 23, 2008 8:39:07 PM (16 years ago)
Author:
bennylp
Message:

Ticket #61: Implement SRTP support in PJMEDIA and PJSUA-LIB, and updated applications because of the changes. This is a major modification back ported from SRTP branch. See ticket #61 for changelog detail of this commit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c

    r1717 r1735  
    256256} 
    257257 
     258static pj_bool_t pj_stristr(const pj_str_t *str, const pj_str_t *substr) 
     259{ 
     260    int i; 
     261 
     262    for (i=0; i<(str->slen-substr->slen); ++i) { 
     263        pj_str_t s; 
     264        s.ptr = str->ptr+i; 
     265        s.slen = substr->slen; 
     266 
     267        if (pj_stricmp(&s, substr)==0) 
     268            return PJ_TRUE; 
     269    } 
     270    return PJ_FALSE; 
     271} 
     272 
     273/* Get signaling secure level. 
     274 * Return: 
     275 *  0: if signaling is not secure 
     276 *  1: if TLS transport is used for immediate hop 
     277 *  2: if end-to-end signaling is secure. 
     278 * 
     279 * NOTE: 
     280 *  THIS IS WRONG. It should take into account the route-set. 
     281 */ 
     282static int get_secure_level(const pj_str_t *dst_uri) 
     283{ 
     284    const pj_str_t tls = pj_str(";transport=tls"); 
     285    const pj_str_t sips = pj_str("sips:"); 
     286 
     287    PJ_TODO(Fix_get_secure_level); 
     288 
     289    if (pj_stristr(dst_uri, &sips)) 
     290        return 2; 
     291    if (pj_stristr(dst_uri, &tls)) 
     292        return 1; 
     293    return 0; 
     294} 
     295 
    258296/* 
    259297 * Make outgoing call to the specified URI using the specified account. 
     
    363401 
    364402    /* Init media channel */ 
    365     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     403    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC,  
     404                                      get_secure_level(dest_uri)); 
    366405    if (status != PJ_SUCCESS) { 
    367406        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    373412    offer = NULL; 
    374413#else 
    375     status = pjsua_media_channel_create_sdp(call->index, dlg->pool, &offer); 
     414    status = pjsua_media_channel_create_sdp(call->index, dlg->pool, NULL, &offer); 
    376415    if (status != PJ_SUCCESS) { 
    377416        pjsua_perror(THIS_FILE, "pjmedia unable to create SDP", status); 
     
    520559    pjsua_call *call; 
    521560    int call_id = -1; 
    522     pjmedia_sdp_session *answer; 
     561    int secure_level; 
     562    pjmedia_sdp_session *offer, *answer; 
    523563    pj_status_t status; 
    524564 
     
    615655    } 
    616656 
    617  
    618     /* Init media channel */ 
    619     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS); 
    620     if (status != PJ_SUCCESS) { 
    621         pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 
    622                                       NULL, NULL); 
    623         PJSUA_UNLOCK(); 
    624         return PJ_TRUE; 
    625     } 
    626  
    627  
    628     /* Get media capability from media endpoint: */ 
    629     status = pjsua_media_channel_create_sdp(call->index, rdata->tp_info.pool, &answer); 
    630     if (status != PJ_SUCCESS) { 
    631         pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 
    632                                       NULL, NULL); 
    633         pjsua_media_channel_deinit(call->index); 
    634         PJSUA_UNLOCK(); 
    635         return PJ_TRUE; 
    636     } 
    637  
    638657    /*  
    639658     * Get which account is most likely to be associated with this incoming 
     
    643662    acc_id = call->acc_id = pjsua_acc_find_for_incoming(rdata); 
    644663 
     664#if defined(PJMEDIA_HAS_SRTP) && (PJMEDIA_HAS_SRTP != 0) 
     665    /* Get signaling security level, only when required by SRTP */ 
     666    if (pjsua_var.acc[acc_id].cfg.srtp_secure_signaling < 2) { 
     667        secure_level = PJSIP_TRANSPORT_IS_SECURE(rdata->tp_info.transport)!=0; 
     668    } else  
     669#endif 
     670 
     671    { 
     672        char *uri; 
     673        int uri_len; 
     674        pj_str_t dst; 
     675 
     676        uri = pj_pool_alloc(rdata->tp_info.pool, PJSIP_MAX_URL_SIZE); 
     677        uri_len = pjsip_uri_print(PJSIP_URI_IN_REQ_URI, 
     678                                  rdata->msg_info.msg->line.req.uri, 
     679                                  uri, PJSIP_MAX_URL_SIZE); 
     680        if (uri_len < 1) { 
     681            pjsua_perror(THIS_FILE, "Error analyzing dst URI",  
     682                         PJSIP_EURITOOLONG); 
     683            uri_len = 0; 
     684        } 
     685 
     686        dst.ptr = uri; 
     687        dst.slen = uri_len; 
     688 
     689        secure_level = get_secure_level(&dst); 
     690    } 
     691 
     692    /* Init media channel */ 
     693    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS,  
     694                                      secure_level); 
     695    if (status != PJ_SUCCESS) { 
     696        pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 
     697                                      NULL, NULL); 
     698        PJSUA_UNLOCK(); 
     699        return PJ_TRUE; 
     700    } 
     701 
     702    /* Parse SDP from incoming request */ 
     703    if (rdata->msg_info.msg->body) { 
     704        status = pjmedia_sdp_parse(rdata->tp_info.pool,  
     705                                   rdata->msg_info.msg->body->data, 
     706                                   rdata->msg_info.msg->body->len, &offer); 
     707        if (status != PJ_SUCCESS) { 
     708            pjsua_perror(THIS_FILE, "Error parsing SDP in incoming INVITE", status); 
     709            pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 400, NULL, 
     710                                          NULL, NULL); 
     711            pjsua_media_channel_deinit(call->index); 
     712            PJSUA_UNLOCK(); 
     713            return PJ_TRUE; 
     714        } 
     715    } else { 
     716        offer = NULL; 
     717    } 
     718 
     719    /* Get media capability from media endpoint: */ 
     720    status = pjsua_media_channel_create_sdp(call->index, rdata->tp_info.pool,  
     721                                            offer, &answer); 
     722    if (status != PJ_SUCCESS) { 
     723        pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 
     724                                      NULL, NULL); 
     725        pjsua_media_channel_deinit(call->index); 
     726        PJSUA_UNLOCK(); 
     727        return PJ_TRUE; 
     728    } 
     729 
    645730    /* Verify that we can handle the request. */ 
    646731    options |= PJSIP_INV_SUPPORT_100REL; 
     
    648733        options |= PJSIP_INV_REQUIRE_100REL; 
    649734 
    650     status = pjsip_inv_verify_request(rdata, &options, answer, NULL, 
    651                                       pjsua_var.endpt, &response); 
     735    status = pjsip_inv_verify_request2(rdata, &options, offer, answer, NULL, 
     736                                       pjsua_var.endpt, &response); 
    652737    if (status != PJ_SUCCESS) { 
    653738 
     
    13391424 
    13401425    /* Init media channel */ 
    1341     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     1426    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
     1427                                      get_secure_level(&dlg->remote.info_str)); 
    13421428    if (status != PJ_SUCCESS) { 
    13431429        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    13491435    PJ_UNUSED_ARG(unhold); 
    13501436    PJ_TODO(create_active_inactive_sdp_based_on_unhold_arg); 
    1351     status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, &sdp); 
     1437    status = pjsua_media_channel_create_sdp(call->index, call->inv->pool,  
     1438                                            NULL, &sdp); 
    13521439    if (status != PJ_SUCCESS) { 
    13531440        pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint",  
     
    14071494 
    14081495    /* Init media channel */ 
    1409     status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     1496    status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
     1497                                      get_secure_level(&dlg->remote.info_str)); 
    14101498    if (status != PJ_SUCCESS) { 
    14111499        pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    14151503 
    14161504    /* Create SDP */ 
    1417     status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, &sdp); 
     1505    status = pjsua_media_channel_create_sdp(call->index, call->inv->pool,  
     1506                                            NULL, &sdp); 
    14181507    if (status != PJ_SUCCESS) { 
    14191508        pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint",  
     
    23562445{ 
    23572446    pjsua_call *call; 
    2358     const pjmedia_sdp_session *local_sdp; 
     2447    const pjmedia_sdp_session *c_local; 
     2448    pjmedia_sdp_session *local_sdp; 
    23592449    const pjmedia_sdp_session *remote_sdp; 
    23602450 
     
    23852475 
    23862476    /* Get local and remote SDP */ 
    2387     status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &local_sdp); 
     2477    status = pjmedia_sdp_neg_get_active_local(call->inv->neg, &c_local); 
    23882478    if (status != PJ_SUCCESS) { 
    23892479        pjsua_perror(THIS_FILE,  
     
    23942484        return; 
    23952485    } 
     2486    local_sdp = (pjmedia_sdp_session*) c_local; 
    23962487 
    23972488    status = pjmedia_sdp_neg_get_active_remote(call->inv->neg, &remote_sdp); 
     
    25252616        status = create_inactive_sdp( call, &answer ); 
    25262617    } else { 
     2618        int secure_level; 
    25272619 
    25282620        PJ_LOG(4,(THIS_FILE, "Call %d: received updated media offer", 
     
    25302622 
    25312623        /* Init media channel */ 
    2532         status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS); 
     2624        secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 
     2625        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAS, 
     2626                                          secure_level); 
    25332627        if (status != PJ_SUCCESS) { 
    25342628            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    25372631        } 
    25382632 
    2539         status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, &answer); 
     2633        status = pjsua_media_channel_create_sdp(call->index, call->inv->pool,  
     2634                                                offer, &answer); 
    25402635    } 
    25412636 
     
    25772672        status = create_inactive_sdp( call, offer ); 
    25782673    } else { 
     2674        int secure_level; 
    25792675 
    25802676        PJ_LOG(4,(THIS_FILE, "Call %d: asked to send a new offer", 
     
    25822678 
    25832679        /* Init media channel */ 
    2584         status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC); 
     2680        secure_level = get_secure_level(&call->inv->dlg->remote.info_str); 
     2681        status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC, 
     2682                                          secure_level); 
    25852683        if (status != PJ_SUCCESS) { 
    25862684            pjsua_perror(THIS_FILE, "Error initializing media channel", status); 
     
    25892687        } 
    25902688 
    2591         status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, offer); 
     2689        status = pjsua_media_channel_create_sdp(call->index, call->inv->pool,  
     2690                                                NULL, offer); 
    25922691    } 
    25932692 
Note: See TracChangeset for help on using the changeset viewer.