Ignore:
Timestamp:
Aug 15, 2018 2:44:53 AM (6 years ago)
Author:
nanang
Message:

Re #2096: Answer with one SRTP keying only when offered both (thanks Wei-Wei for the feedback).

File:
1 edited

Legend:

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

    r5845 r5855  
    267267    pjmedia_transport   *member_tp; /**< Underlying transport.       */ 
    268268    pj_bool_t            member_tp_attached; 
     269    pj_bool_t            started; 
    269270 
    270271    /* SRTP usage policy of peer. This field is updated when media is starting. 
     
    10511052        if (status != PJ_SUCCESS) 
    10521053            return status; 
     1054 
     1055        PJ_LOG(4, (srtp->pool->obj_name, 
     1056                   "SRTP started, keying=%s, crypto=%s", 
     1057                   (srtp->keying[0]->type==PJMEDIA_SRTP_KEYING_SDES? 
     1058                    "SDES":"DTLS-SRTP"), 
     1059                   srtp->tx_policy.name.ptr)); 
    10531060    } 
    10541061 
     
    15791586    srtp->offerer_side = (sdp_remote == NULL); 
    15801587 
     1588    if (!srtp->offerer_side && srtp->started) { 
     1589        /* This is may be incoming reoffer that may change keying */ 
     1590        srtp->bypass_srtp = PJ_FALSE; 
     1591        srtp->keying_cnt = srtp->all_keying_cnt; 
     1592        for (i = 0; i < srtp->all_keying_cnt; ++i) 
     1593            srtp->keying[i] = srtp->all_keying[i]; 
     1594    } 
     1595 
    15811596    status = pjmedia_transport_encode_sdp(srtp->member_tp, sdp_pool, 
    15821597                                          sdp_local, sdp_remote, media_index); 
     
    16111626            keying_status = st; 
    16121627            continue; 
    1613         } 
    1614  
    1615         if (!srtp_crypto_empty(&srtp->tx_policy_neg) && 
    1616             !srtp_crypto_empty(&srtp->rx_policy_neg)) 
    1617         { 
    1618             /* SRTP nego is done */ 
     1628        } else if (!srtp->offerer_side) { 
     1629            /* Answer with one keying only */ 
     1630            srtp->keying[0] = srtp->keying[i]; 
    16191631            srtp->keying_cnt = 1; 
    1620             srtp->keying[0] = srtp->keying[i]; 
    1621             srtp->keying_pending_cnt = 0; 
    16221632            break; 
    16231633        } 
     
    16291639    if (srtp->keying_cnt == 0) 
    16301640        return keying_status; 
     1641 
     1642    /* Bypass SRTP & skip keying as SRTP is disabled and verification on 
     1643     * remote SDP has been done. 
     1644     */ 
     1645    if (srtp->setting.use == PJMEDIA_SRTP_DISABLED) { 
     1646        srtp->bypass_srtp = PJ_TRUE; 
     1647        srtp->keying_cnt = 0; 
     1648    } 
     1649 
     1650    if (srtp->keying_cnt != 0) { 
     1651        /* At this point for now, keying count should be 1 */ 
     1652        pj_assert(srtp->keying_cnt == 1); 
     1653        PJ_LOG(4, (srtp->pool->obj_name, "SRTP uses keying method %s", 
     1654                   (srtp->keying[0]->type==PJMEDIA_SRTP_KEYING_SDES? 
     1655                    "SDES":"DTLS-SRTP"))); 
     1656    } 
    16311657 
    16321658    return PJ_SUCCESS; 
     
    16461672 
    16471673    PJ_ASSERT_RETURN(tp, PJ_EINVAL); 
     1674 
     1675    /* At this point for now, keying count should be 0 or 1 */ 
     1676    pj_assert(srtp->keying_cnt <= 1); 
     1677 
     1678    srtp->started = PJ_TRUE; 
    16481679 
    16491680    status = pjmedia_transport_media_start(srtp->member_tp, pool, 
     
    17171748    PJ_ASSERT_RETURN(tp, PJ_EINVAL); 
    17181749 
     1750    srtp->started = PJ_FALSE; 
     1751 
    17191752    /* Invoke media_stop() of all keying methods */ 
    17201753    for (i=0; i < srtp->keying_cnt; ++i) { 
Note: See TracChangeset for help on using the changeset viewer.