Changeset 1700


Ignore:
Timestamp:
Jan 17, 2008 8:37:38 PM (16 years ago)
Author:
nanang
Message:

Ticket #452:

  • change libsrtp on rand_source.c to disable rand_s which causing breakpoint assert
  • change pjsua_media.c:
    • allow RTP/SAVP transport
    • set srtp transport creation option to 0 (prev:auto destroy underlying transport is enabled)
  • new pjmedia errno: PJMEDIA_SRTP_ESDPREQSECTP: Secure transport required in SDP media descriptor. PJMEDIA_SRTP_ESDPAMBIGUEANS: SDP contains ambigue answer.
  • transport_srtp:
    • updating log & error code
    • bug fix: release pool after destroying other objects


Location:
pjproject/branches/users/nanang
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/users/nanang/pjmedia/include/pjmedia/errno.h

    r1639 r1700  
    527527 
    528528 
     529/************************************************************ 
     530 * SRTP TRANSPORT ERRORS 
     531 ***********************************************************/ 
     532/** 
     533 * @hideinitializer 
     534 * Secure transport required in SDP media descriptor. 
     535 */ 
     536#define PJMEDIA_SRTP_ESDPREQSECTP   (PJMEDIA_ERRNO_START+220)    /* 220220 */ 
     537/** 
     538 * @hideinitializer 
     539 * SDP contains ambigue answer. 
     540 */ 
     541#define PJMEDIA_SRTP_ESDPAMBIGUEANS (PJMEDIA_ERRNO_START+221)    /* 220221 */ 
     542 
     543 
     544 
    529545/** 
    530546 * Get error message for the specified error code. Note that this 
  • pjproject/branches/users/nanang/pjmedia/src/pjmedia/errno.c

    r1639 r1700  
    142142    PJ_BUILD_ERR( PJMEDIA_ESNDINDEVID,      "Invalid sound device ID" ), 
    143143    PJ_BUILD_ERR( PJMEDIA_ESNDINSAMPLEFMT,  "Invalid sample format for sound device" ), 
     144 
     145    /* SRTP transport errors: */ 
     146    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPREQSECTP,   "Secure transport required in SDP media descriptor" ), 
     147    PJ_BUILD_ERR( PJMEDIA_SRTP_ESDPAMBIGUEANS, "SDP contains ambigue answer" ), 
     148     
    144149}; 
    145150 
  • pjproject/branches/users/nanang/pjmedia/src/pjmedia/transport_srtp.c

    r1698 r1700  
    2222#include <pjlib-util/base64.h> 
    2323#include <pj/assert.h> 
     24#include <pj/lock.h> 
    2425#include <pj/log.h> 
    2526#include <pj/os.h> 
     
    7273    pjmedia_transport    base;      /**< Base transport interface. */ 
    7374    pj_pool_t           *pool; 
    74     pj_mutex_t          *mutex; 
     75    pj_lock_t           *mutex; 
    7576    char                 tx_buffer[MAX_BUFFER_LEN]; 
    7677    char                 rx_buffer[MAX_BUFFER_LEN]; 
     
    174175static pj_status_t pjmedia_srtp_init_lib(void) 
    175176{ 
    176     err_status_t err; 
    177177    static pj_bool_t initialized = PJ_FALSE; 
    178178 
    179179    if (initialized == PJ_FALSE) { 
     180        err_status_t err; 
    180181        err = srtp_init(); 
    181182        if (err != err_status_ok) {  
     183            PJ_LOG(4, (THIS_FILE, "Failed to init libsrtp.")); 
    182184            return SRTP_ERROR(err); 
    183185        } 
     
    208210    /* Init libsrtp. */ 
    209211    status = pjmedia_srtp_init_lib(); 
    210     if (status != PJ_SUCCESS) { 
     212    if (status != PJ_SUCCESS) 
    211213        return status; 
    212     } 
    213214 
    214215    pool = pjmedia_endpt_create_pool(endpt, "srtp%p", 1000, 1000); 
     
    220221    srtp->options = options; 
    221222 
    222     status = pj_mutex_create_recursive(pool, pool->obj_name, &srtp->mutex); 
     223    status = pj_lock_create_null_mutex(pool, pool->obj_name, &srtp->mutex); 
    223224    if (status != PJ_SUCCESS) { 
    224225        pj_pool_release(pool); 
     
    259260 
    260261    if (p_srtp->session_inited) { 
    261         return PJ_EEXISTS; 
     262        PJ_LOG(4, (THIS_FILE, "SRTP could not be re-init'd before deinit'd")); 
     263        return PJ_EINVALIDOP; 
    262264    } 
    263265 
     
    276278 
    277279    if ((cs_tx_idx == -1) || (cs_rx_idx == -1)) { 
     280        PJ_LOG(4, (THIS_FILE, "Crypto-suite specified is not supported.")); 
    278281        return PJ_ENOTSUP; 
    279282    } 
     
    330333    p_srtp->session_inited = PJ_TRUE; 
    331334 
    332     PJ_LOG(3, (THIS_FILE, "TX %s key=%s", crypto_suites[cs_tx_idx].name, 
     335    PJ_LOG(5, (THIS_FILE, "TX %s key=%s", crypto_suites[cs_tx_idx].name, 
    333336           octet_string_hex_string(policy_tx->key.ptr, policy_tx->key.slen))); 
    334     PJ_LOG(3, (THIS_FILE, "RX %s key=%s", crypto_suites[cs_rx_idx].name, 
     337    PJ_LOG(5, (THIS_FILE, "RX %s key=%s", crypto_suites[cs_rx_idx].name, 
    335338           octet_string_hex_string(policy_rx->key.ptr, policy_rx->key.slen))); 
    336339 
     
    352355    err = srtp_dealloc(p_srtp->srtp_rx_ctx); 
    353356    if (err != err_status_ok) { 
    354         PJ_TODO(LOG_ERROR_DEALLOC_RX); 
    355         //return SRTP_ERROR(err); 
     357        PJ_LOG(4, (THIS_FILE, "Failed to dealloc RX SRTP context")); 
    356358    } 
    357359    err = srtp_dealloc(p_srtp->srtp_tx_ctx); 
    358360    if (err != err_status_ok) { 
    359         PJ_TODO(LOG_ERROR_DEALLOC_TX); 
    360         //return SRTP_ERROR(err); 
     361        PJ_LOG(4, (THIS_FILE, "Failed to dealloc TX SRTP context")); 
    361362    } 
    362363 
     
    402403    status = pjmedia_transport_attach(srtp->real_tp, srtp, rem_addr, rem_rtcp, 
    403404                                      addr_len, &srtp_rtp_cb, &srtp_rtcp_cb); 
    404     if (status != PJ_SUCCESS) { 
    405         PJ_TODO(HANDLE_FAILURE); 
    406     } 
     405    if (status != PJ_SUCCESS) 
     406        return status; 
    407407 
    408408    /* Save the callbacks */ 
     
    443443    PJ_ASSERT_RETURN(size < sizeof(srtp->tx_buffer), PJ_ETOOBIG); 
    444444 
    445     pj_mutex_lock(srtp->mutex); 
     445    pj_lock_acquire(srtp->mutex); 
    446446    pj_memcpy(srtp->tx_buffer, pkt, size); 
    447447     
     
    453453    } 
    454454     
    455     pj_mutex_unlock(srtp->mutex); 
     455    pj_lock_release(srtp->mutex); 
    456456 
    457457    return status; 
     
    472472    PJ_ASSERT_RETURN((size) < sizeof(srtp->tx_buffer), PJ_ETOOBIG); 
    473473 
    474     pj_mutex_lock(srtp->mutex); 
     474    pj_lock_acquire(srtp->mutex); 
    475475    pj_memcpy(srtp->tx_buffer, pkt, size); 
    476476 
     
    483483    } 
    484484 
    485     pj_mutex_unlock(srtp->mutex); 
     485    pj_lock_release(srtp->mutex); 
    486486 
    487487    return status; 
     
    501501    transport_srtp *srtp = (transport_srtp *) tp; 
    502502    pj_status_t status; 
     503 
     504    pj_lock_destroy(srtp->mutex); 
    503505 
    504506    pjmedia_transport_detach(tp, NULL); 
     
    509511 
    510512    status = pjmedia_transport_srtp_deinit_session(tp); 
    511     if (status != PJ_SUCCESS) 
    512         return status; 
    513  
    514     pj_mutex_destroy(srtp->mutex); 
     513 
    515514    pj_pool_release(srtp->pool); 
    516515 
    517     return PJ_SUCCESS; 
     516    return status; 
    518517} 
    519518 
     
    531530    } 
    532531 
    533     pj_mutex_lock(srtp->mutex); 
     532    pj_lock_acquire(srtp->mutex); 
    534533    pj_memcpy(srtp->rx_buffer, pkt, size); 
    535534 
    536535    err = srtp_unprotect(srtp->srtp_rx_ctx, srtp->rx_buffer, &len); 
    537536     
    538     /* unprotect should returns less (or same, if auth disabled) size */ 
    539     PJ_TODO(CHECK_SIZE_AFTER_UNPROTECT); 
    540  
    541537    if (err == err_status_ok) { 
    542538        srtp->rtp_cb(srtp->user_data, srtp->rx_buffer, len); 
    543539    } else { 
    544         PJ_TODO(LOG_ERROR_UNPROTECT); 
    545     } 
    546  
    547     pj_mutex_unlock(srtp->mutex); 
     540        PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTP")); 
     541    } 
     542 
     543    pj_lock_release(srtp->mutex); 
    548544} 
    549545 
     
    561557    } 
    562558 
    563     pj_mutex_lock(srtp->mutex); 
     559    pj_lock_acquire(srtp->mutex); 
    564560    pj_memcpy(srtp->rx_buffer, pkt, size); 
    565561 
    566562    err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, srtp->rx_buffer, &len); 
    567  
    568     /* unprotect should returns less (or same, if auth disabled) size */ 
    569     PJ_TODO(CHECK_SIZE_AFTER_UNPROTECT); 
    570563 
    571564    if (err == err_status_ok) { 
    572565        srtp->rtcp_cb(srtp->user_data, srtp->rx_buffer, len); 
    573566    } else { 
    574         PJ_TODO(LOG_ERROR_UNPROTECT); 
     567        PJ_LOG(5, (THIS_FILE, "Failed to unprotect SRTCP")); 
    575568    } 
    576569     
    577     pj_mutex_unlock(srtp->mutex); 
     570    pj_lock_release(srtp->mutex); 
    578571} 
    579572 
     
    780773        pj_stricmp(&media_remote->desc.transport, &ID_RTP_SAVP)) 
    781774    { 
    782         return PJMEDIA_SDP_EINPROTO; 
     775        return PJMEDIA_SRTP_ESDPREQSECTP; 
    783776    } 
    784777 
     
    800793        for (i=0; i<media_remote->attr_count; ++i) { 
    801794            if (!pj_stricmp2(&media_local->attr[i]->name, "crypto")) { 
    802                 if (attr) 
    803                     return PJMEDIA_ERROR; 
     795                if (attr) { 
     796                    PJ_LOG(5,(THIS_FILE, "More than one crypto attr in " \ 
     797                                         "the SDP answer.")); 
     798                    return PJMEDIA_SRTP_ESDPAMBIGUEANS; 
     799                } 
    804800 
    805801                attr = media_local->attr[i]; 
     
    990986 
    991987    status = pjmedia_transport_srtp_deinit_session(tp); 
    992     if (status != PJ_SUCCESS) { 
    993         PJ_TODO(LOG_ERROR_DEINIT_SRTP); 
    994     } 
     988    if (status != PJ_SUCCESS) 
     989        PJ_LOG(4, (THIS_FILE, "Failed deinit session.")); 
    995990 
    996991    return pjmedia_transport_media_stop(srtp->real_tp); 
  • pjproject/branches/users/nanang/pjsip/src/pjsua-lib/pjsua_media.c

    r1698 r1700  
    538538        if (pjsua_var.media_cfg.enable_srtp) { 
    539539            pjmedia_transport *tp; 
    540             unsigned srtp_options =  
    541                                 PJMEDIA_SRTP_AUTO_CLOSE_UNDERLYING_TRANSPORT; 
     540            unsigned srtp_options = 0; 
    542541 
    543542            status = pjmedia_transport_udp_attach(pjsua_var.med_endpt, NULL, 
     
    928927    for (i=0; i < sess_info.stream_cnt; ++i) { 
    929928        if (sess_info.stream_info[i].type == PJMEDIA_TYPE_AUDIO && 
    930             sess_info.stream_info[i].proto == PJMEDIA_TP_PROTO_RTP_AVP) 
     929            (sess_info.stream_info[i].proto == PJMEDIA_TP_PROTO_RTP_AVP || 
     930             sess_info.stream_info[i].proto == PJMEDIA_TP_PROTO_RTP_SAVP)) 
    931931        { 
    932932            si = &sess_info.stream_info[i]; 
  • pjproject/branches/users/nanang/third_party/srtp/crypto/rng/rand_source.c

    r1697 r1700  
    109109  if (read(dev_random_fdes, dest, len) != len) 
    110110    return err_status_fail; 
    111 #elif (_MSC_VER >= 1400) 
     111#elif 0 && (_MSC_VER >= 1400) 
    112112  unsigned int *dst = dest; 
    113113  while (len) 
Note: See TracChangeset for help on using the changeset viewer.