Ignore:
Timestamp:
Feb 26, 2018 7:50:18 AM (3 years ago)
Author:
nanang
Message:

Fixe #2096:

  • Fixed re-INVITE scenario: always generate SRTP attr in SDP re-offer/answer as both offerer/answerer (as long as SRTP is not disabled of course), currently it does not generate SRTP attr if active session does not use SRTP.
  • Fixed bug in retrieving video stream info from SDP that caused DTLS transport (UDP/TLS/RTP/SAVP) getting rejected.
  • Added pjsua app param '--srtp-keying=0/1' to choose SRTP keying to be used in the outgoing offer (0=SDES (default), 1=DTLS-SRTP).
  • Few minors, e.g: adding transport_srtp_dtls/sdes.c to pjmedia MSVC2015 project.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c

    r5725 r5746  
    120120#endif 
    121121 
     122/* Maximum number of SRTP keying method */ 
     123#define MAX_KEYING                  2 
     124 
    122125static const pj_str_t ID_RTP_AVP  = { "RTP/AVP", 7 }; 
    123126static const pj_str_t ID_RTP_SAVP = { "RTP/SAVP", 8 }; 
     
    284287     * method, any other keying methods will be stopped and destroyed. 
    285288     */ 
     289    unsigned             all_keying_cnt; 
     290    pjmedia_transport   *all_keying[MAX_KEYING]; 
     291 
     292    /* Current active SRTP keying methods. */ 
    286293    unsigned             keying_cnt; 
    287     pjmedia_transport   *keying[2]; 
     294    pjmedia_transport   *keying[MAX_KEYING]; 
    288295 
    289296    /* If not zero, keying nego is ongoing (async-ly, e.g: by DTLS-SRTP). 
     
    718725 
    719726    /* Initialize SRTP keying method. */ 
    720     for (i = 0; i < srtp->setting.keying_count; ++i) { 
     727    for (i = 0; i < srtp->setting.keying_count && i < MAX_KEYING; ++i) { 
    721728        switch(srtp->setting.keying[i]) { 
    722729 
    723730        case PJMEDIA_SRTP_KEYING_SDES: 
    724731#if defined(PJMEDIA_SRTP_HAS_SDES) && (PJMEDIA_SRTP_HAS_SDES != 0) 
    725             sdes_create(srtp, &srtp->keying[srtp->keying_cnt++]); 
     732            sdes_create(srtp, &srtp->all_keying[srtp->all_keying_cnt++]); 
    726733#endif 
    727734            break; 
     
    729736        case PJMEDIA_SRTP_KEYING_DTLS_SRTP: 
    730737#if defined(PJMEDIA_SRTP_HAS_DTLS) && (PJMEDIA_SRTP_HAS_DTLS != 0) 
    731             dtls_create(srtp, &srtp->keying[srtp->keying_cnt++]); 
     738            dtls_create(srtp, &srtp->all_keying[srtp->all_keying_cnt++]); 
    732739#endif 
    733740            break; 
     
    10391046              sizeof(srtp_info)); 
    10401047 
    1041     /* Invoke get_info() of all keying methods */ 
     1048    /* Invoke get_info() from any active keying method */ 
    10421049    for (i=0; i < srtp->keying_cnt; i++) 
    10431050        pjmedia_transport_get_info(srtp->keying[i], info); 
     
    13721379    struct transport_srtp *srtp = (struct transport_srtp*) tp; 
    13731380    unsigned member_tp_option; 
    1374     pj_status_t last_err_st = PJ_EBUG; 
     1381    pj_status_t keying_status = PJ_SUCCESS; 
    13751382    pj_status_t status; 
    13761383    unsigned i; 
     
    13841391    srtp->offerer_side = (sdp_remote == NULL); 
    13851392 
    1386     if (srtp->offerer_side && srtp->setting.use == PJMEDIA_SRTP_DISABLED) 
     1393    if (srtp->offerer_side && srtp->setting.use == PJMEDIA_SRTP_DISABLED) { 
    13871394        srtp->bypass_srtp = PJ_TRUE; 
    1388     else 
     1395        srtp->keying_cnt = 0; 
     1396    } else { 
     1397        srtp->bypass_srtp = PJ_FALSE; 
     1398        srtp->keying_cnt = srtp->all_keying_cnt; 
     1399        for (i = 0; i < srtp->all_keying_cnt; ++i) 
     1400            srtp->keying[i] = srtp->all_keying[i]; 
     1401 
    13891402        member_tp_option |= PJMEDIA_TPMED_NO_TRANSPORT_CHECKING; 
     1403    } 
    13901404 
    13911405    status = pjmedia_transport_media_create(srtp->member_tp, sdp_pool, 
    13921406                                            member_tp_option, sdp_remote, 
    13931407                                            media_index); 
    1394     if (status != PJ_SUCCESS || srtp->bypass_srtp) 
     1408    if (status != PJ_SUCCESS) 
    13951409        return status; 
    13961410 
     
    14061420                           srtp->keying_cnt, i); 
    14071421            srtp->keying_cnt--; 
    1408             last_err_st = st; 
     1422            keying_status = st; 
    14091423            continue; 
    14101424        } else if (srtp->offerer_side) { 
     
    14201434    /* All keying method failed to process remote SDP? */ 
    14211435    if (srtp->keying_cnt == 0) 
    1422         return last_err_st; 
     1436        return keying_status; 
    14231437 
    14241438    return PJ_SUCCESS; 
     
    14321446{ 
    14331447    struct transport_srtp *srtp = (struct transport_srtp*) tp; 
    1434     pj_status_t last_err_st = PJ_EBUG; 
     1448    pj_status_t keying_status = PJ_SUCCESS; 
    14351449    pj_status_t status; 
    14361450    unsigned i; 
     
    14451459    status = pjmedia_transport_encode_sdp(srtp->member_tp, sdp_pool, 
    14461460                                          sdp_local, sdp_remote, media_index); 
    1447     if (status != PJ_SUCCESS || srtp->bypass_srtp) 
     1461    if (status != PJ_SUCCESS) 
    14481462        return status; 
    14491463 
     
    14591473                           srtp->keying_cnt, i); 
    14601474            srtp->keying_cnt--; 
    1461             last_err_st = st; 
     1475            keying_status = st; 
    14621476            continue; 
    14631477        } 
     
    14831497    /* All keying method failed to process remote SDP? */ 
    14841498    if (srtp->keying_cnt == 0) 
    1485         return last_err_st; 
     1499        return keying_status; 
    14861500 
    14871501    return PJ_SUCCESS; 
     
    14961510{ 
    14971511    struct transport_srtp *srtp = (struct transport_srtp*) tp; 
    1498     pj_status_t last_err_st = PJ_EBUG; 
     1512    pj_status_t keying_status = PJ_SUCCESS; 
    14991513    pj_status_t status; 
    15001514    unsigned i; 
     
    15051519                                           sdp_local, sdp_remote, 
    15061520                                           media_index); 
    1507     if (status != PJ_SUCCESS || srtp->bypass_srtp) 
     1521    if (status != PJ_SUCCESS) 
    15081522        return status; 
    15091523 
     
    15181532                           srtp->keying_cnt, i); 
    15191533            srtp->keying_cnt--; 
    1520             last_err_st = status; 
     1534            keying_status = status; 
    15211535            continue; 
    15221536        } 
     
    15421556    /* All keying method failed to process remote SDP? */ 
    15431557    if (srtp->keying_cnt == 0) 
    1544         return last_err_st; 
     1558        return keying_status; 
    15451559 
    15461560    /* If SRTP key is being negotiated, just return now. 
     
    16241638 
    16251639#endif 
    1626  
    1627  
Note: See TracChangeset for help on using the changeset viewer.