Ignore:
Timestamp:
Jan 17, 2008 5:29:36 PM (16 years ago)
Author:
nanang
Message:

Ticket #452:

  • Add directory srtp to third_party/build directory
  • Add libsrtp project & integrate it to pjproject vs8 solution
  • Add transport_srtp.h & .c
  • Modify project dependencies to include libsrtp
  • Modify Samples-vc.mak, add libsrtp as third party library
  • Modify transport interface
  • Modify transport_ice & transport_udp to accomodate new transport interface
  • Modify other files that uses transport
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/users/nanang/pjsip-apps/src/samples/streamutil.c

    r1666 r1698  
    5656 "  --send-only           Set stream direction to send only             \n" 
    5757 "  --recv-only           Set stream direction to recv only (default)   \n" 
     58 "  --use-srtp[=NAME]     Enable SRTP with crypto suite NAME            \n" 
     59 "                        e.g: AES_CM_128_HMAC_SHA1_80 (default),       \n" 
     60 "                             AES_CM_128_HMAC_SHA1_32                  \n" 
     61 "                        Use this option along with the TX & RX keys,  \n" 
     62 "                        formated of 60 hex digits (e.g: E148DA..)      \n" 
     63 "  --srtp-tx-key         SRTP key for transmiting                      \n" 
     64 "  --srtp-rx-key         SRTP key for receiving                        \n" 
    5865 "\n" 
    5966; 
     
    6572#include <pjmedia.h> 
    6673#include <pjmedia-codec.h> 
     74#include <pjmedia/transport_srtp.h> 
    6775 
    6876#include <stdlib.h>     /* atoi() */ 
     
    7987static void print_stream_stat(pjmedia_stream *stream); 
    8088 
     89/* Prototype for LIBSRTP utility in file datatypes.c */ 
     90int hex_string_to_octet_string(char *raw, char *hex, int len); 
    8191 
    8292/*  
     
    123133                                  pj_uint16_t local_port, 
    124134                                  const pj_sockaddr_in *rem_addr, 
     135                                  pj_bool_t use_srtp, 
     136                                  const pj_str_t *crypto_suite, 
     137                                  const pj_str_t *srtp_tx_key, 
     138                                  const pj_str_t *srtp_rx_key, 
    125139                                  pjmedia_stream **p_stream ) 
    126140{ 
    127141    pjmedia_stream_info info; 
    128     pjmedia_transport *transport; 
     142    pjmedia_transport *transport = NULL; 
     143    pjmedia_transport *srtp_tp = NULL; 
    129144    pj_status_t status; 
    130145 
     
    159174        return status; 
    160175 
     176    /* Check if SRTP enabled */ 
     177    if (use_srtp) { 
     178        pjmedia_srtp_stream_policy tx_plc, rx_plc; 
     179 
     180        status = pjmedia_transport_srtp_create(med_endpt, transport,  
     181                            PJMEDIA_SRTP_AUTO_CLOSE_UNDERLYING_TRANSPORT, 
     182                            &srtp_tp); 
     183        if (status != PJ_SUCCESS) 
     184            return status; 
     185 
     186        pj_bzero(&tx_plc, sizeof(pjmedia_srtp_stream_policy)); 
     187        pj_bzero(&rx_plc, sizeof(pjmedia_srtp_stream_policy)); 
     188 
     189        tx_plc.key = *srtp_tx_key; 
     190        tx_plc.crypto_suite = *crypto_suite; 
     191        rx_plc.key = *srtp_rx_key; 
     192        rx_plc.crypto_suite = *crypto_suite; 
     193         
     194        status = pjmedia_transport_srtp_init_session(srtp_tp, &tx_plc, &rx_plc); 
     195        if (status != PJ_SUCCESS) 
     196            return status; 
     197    } 
    161198 
    162199    /* Now that the stream info is initialized, we can create the  
     
    165202 
    166203    status = pjmedia_stream_create( med_endpt, pool, &info,  
    167                                     transport, NULL, p_stream); 
     204                                    (use_srtp?srtp_tp:transport),  
     205                                    NULL, p_stream); 
    168206 
    169207    if (status != PJ_SUCCESS) { 
    170208        app_perror(THIS_FILE, "Error creating stream", status); 
    171         pjmedia_transport_udp_close(transport); 
     209        pjmedia_transport_close(transport); 
    172210        return status; 
    173211    } 
     
    202240    pj_status_t status;  
    203241 
     242    /* SRTP variables */ 
     243    pj_bool_t use_srtp = PJ_FALSE; 
     244    char tmp_tx_key[64]; 
     245    char tmp_rx_key[64]; 
     246    pj_str_t  srtp_tx_key = {NULL, 0}; 
     247    pj_str_t  srtp_rx_key = {NULL, 0}; 
     248    pj_str_t  srtp_crypto_suite = {NULL, 0}; 
     249    int tmp_key_len; 
    204250 
    205251    /* Default values */ 
     
    221267        OPT_SEND_ONLY   = 's', 
    222268        OPT_RECV_ONLY   = 'i', 
     269        OPT_USE_SRTP    = 'S', 
     270        OPT_SRTP_TX_KEY = 'x', 
     271        OPT_SRTP_RX_KEY = 'y', 
    223272        OPT_HELP        = 'h', 
    224273    }; 
     
    233282        { "send-only",      0, 0, OPT_SEND_ONLY }, 
    234283        { "recv-only",      0, 0, OPT_RECV_ONLY }, 
     284        { "use-srtp",       2, 0, OPT_USE_SRTP }, 
     285        { "srtp-tx-key",    1, 0, OPT_SRTP_TX_KEY }, 
     286        { "srtp-rx-key",    1, 0, OPT_SRTP_RX_KEY }, 
    235287        { "help",           0, 0, OPT_HELP }, 
    236288        { NULL, 0, 0, 0 }, 
     
    299351            break; 
    300352 
     353        case OPT_USE_SRTP: 
     354            use_srtp = PJ_TRUE; 
     355            if (pj_optarg) { 
     356                pj_strset(&srtp_crypto_suite, pj_optarg, strlen(pj_optarg)); 
     357            } else { 
     358                srtp_crypto_suite = pj_str("AES_CM_128_HMAC_SHA1_80"); 
     359            } 
     360            break; 
     361 
     362        case OPT_SRTP_TX_KEY: 
     363            tmp_key_len = hex_string_to_octet_string(tmp_tx_key, pj_optarg, strlen(pj_optarg)); 
     364            pj_strset(&srtp_tx_key, tmp_tx_key, tmp_key_len/2); 
     365            break; 
     366 
     367        case OPT_SRTP_RX_KEY: 
     368            tmp_key_len = hex_string_to_octet_string(tmp_rx_key, pj_optarg, strlen(pj_optarg)); 
     369            pj_strset(&srtp_rx_key, tmp_rx_key, tmp_key_len/2); 
     370            break; 
     371 
    301372        case OPT_HELP: 
    302373            usage(); 
     
    324395    } 
    325396 
     397    if (use_srtp) { 
     398        if (((dir & PJMEDIA_DIR_ENCODING) && !srtp_tx_key.slen) || 
     399            ((dir & PJMEDIA_DIR_DECODING) && !srtp_rx_key.slen)) 
     400        { 
     401            printf("Error: Key for each SRTP stream direction must be set\n"); 
     402            return 1; 
     403        } 
     404    } 
    326405 
    327406    /* Must create a pool factory before we can allocate any memory. */ 
     
    369448    /* Create stream based on program arguments */ 
    370449    status = create_stream(pool, med_endpt, codec_info, dir, local_port,  
    371                            &remote_addr, &stream); 
     450                           &remote_addr,  
     451                           use_srtp, &srtp_crypto_suite,  
     452                           &srtp_tx_key, &srtp_rx_key, 
     453                           &stream); 
    372454    if (status != PJ_SUCCESS) 
    373455        goto on_exit; 
     
    538620        tp = pjmedia_stream_get_transport(stream); 
    539621        pjmedia_stream_destroy(stream); 
    540         pjmedia_transport_udp_close(tp); 
     622         
     623        pjmedia_transport_close(tp); 
    541624    } 
    542625 
Note: See TracChangeset for help on using the changeset viewer.