Ignore:
Timestamp:
Apr 25, 2017 2:13:56 PM (7 years ago)
Author:
riza
Message:

Re #1994 (misc): Related to r5500, when receiving an SDP answer for SRTP, process the tag correctly based on the offer. Thanks to Colin Morelli for the report.

File:
1 edited

Legend:

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

    r5586 r5588  
    16181618 
    16191619 
     1620static pj_status_t fill_local_crypto(pj_pool_t *pool, 
     1621                                     const pjmedia_sdp_media *m_loc,  
     1622                                     pjmedia_srtp_crypto loc_crypto[], 
     1623                                     int *count) 
     1624{ 
     1625    int i; 
     1626    int crypto_count = 0; 
     1627    pj_status_t status = PJ_SUCCESS; 
     1628     
     1629    for (i = 0; i < *count; ++i) { 
     1630        pj_bzero(&loc_crypto[i], sizeof(loc_crypto[i])); 
     1631    } 
     1632 
     1633    for (i = 0; i < (int)m_loc->attr_count; ++i) {       
     1634        pjmedia_srtp_crypto tmp_crypto; 
     1635        int loc_tag; 
     1636 
     1637        if (pj_stricmp(&m_loc->attr[i]->name, &ID_CRYPTO) != 0) 
     1638            continue; 
     1639 
     1640        status = parse_attr_crypto(pool, m_loc->attr[i], 
     1641                                   &tmp_crypto, &loc_tag); 
     1642        if (status != PJ_SUCCESS) 
     1643            return status; 
     1644 
     1645        if (loc_tag > *count) 
     1646            return PJMEDIA_SRTP_ESDPINCRYPTOTAG; 
     1647 
     1648        loc_crypto[loc_tag-1] = tmp_crypto; 
     1649        ++crypto_count; 
     1650    } 
     1651    *count = crypto_count; 
     1652    return status; 
     1653} 
     1654 
    16201655 
    16211656static pj_status_t transport_media_start(pjmedia_transport *tp, 
     
    16291664    pj_status_t status; 
    16301665    unsigned i; 
     1666    pjmedia_srtp_crypto loc_crypto[PJMEDIA_SRTP_MAX_CRYPTOS]; 
     1667    int loc_cryto_cnt = PJMEDIA_SRTP_MAX_CRYPTOS; 
    16311668 
    16321669    PJ_ASSERT_RETURN(tp && pool && sdp_local && sdp_remote, PJ_EINVAL); 
     
    16611698                //return PJMEDIA_SDP_EINPROTO; 
    16621699            //} 
     1700            fill_local_crypto(srtp->pool, m_loc, loc_crypto, &loc_cryto_cnt); 
    16631701        } else if (srtp->setting.use == PJMEDIA_SRTP_MANDATORY) { 
    16641702            if (pj_stricmp(&m_rem->desc.transport, &ID_RTP_SAVP)) { 
     
    16661704                return PJMEDIA_SDP_EINPROTO; 
    16671705            } 
     1706            fill_local_crypto(srtp->pool, m_loc, loc_crypto, &loc_cryto_cnt); 
    16681707        } 
    16691708    } 
     
    16741713        pj_bool_t has_crypto_attr = PJ_FALSE; 
    16751714        int rem_tag; 
     1715        int j; 
    16761716 
    16771717        for (i=0; i<m_rem->attr_count; ++i) { 
     
    16931733 
    16941734 
    1695             /* our offer tag is always ordered by setting */ 
    1696             if (rem_tag < 1 || rem_tag > (int)srtp->setting.crypto_count) { 
     1735            /* Tag range check, our tags in the offer must be in the SRTP  
     1736             * setting range, so does the remote answer's. The remote answer's  
     1737             * tag must not exceed the tag range of the local offer. 
     1738             */ 
     1739            if (rem_tag < 1 || rem_tag > (int)srtp->setting.crypto_count || 
     1740                rem_tag > loc_cryto_cnt)  
     1741             
     1742            { 
    16971743                DEACTIVATE_MEDIA(pool, m_loc); 
    16981744                return PJMEDIA_SRTP_ESDPINCRYPTOTAG; 
     
    17001746 
    17011747            /* match the crypto name */ 
    1702             if (pj_stricmp(&tmp_tx_crypto.name, 
    1703                 &srtp->setting.crypto[rem_tag-1].name) != 0) 
     1748            if (pj_stricmp(&tmp_tx_crypto.name,  
     1749                           &loc_crypto[rem_tag-1].name) != 0)            
    17041750            { 
    17051751                DEACTIVATE_MEDIA(pool, m_loc); 
     
    17071753            } 
    17081754 
    1709             srtp->tx_policy_neg = srtp->setting.crypto[rem_tag-1]; 
     1755            /* Find the crypto from the setting. */ 
     1756            for (j = 0; j < (int)srtp->setting.crypto_count; ++j) { 
     1757                if (pj_stricmp(&tmp_tx_crypto.name,  
     1758                               &srtp->setting.crypto[j].name) == 0)  
     1759                 
     1760                { 
     1761                    srtp->tx_policy_neg = srtp->setting.crypto[j]; 
     1762                    break; 
     1763                }                
     1764            } 
     1765             
    17101766            srtp->rx_policy_neg = tmp_tx_crypto; 
    17111767        } 
Note: See TracChangeset for help on using the changeset viewer.