Changeset 5621 for pjproject/trunk/pjsip-apps/src/samples/streamutil.c
- Timestamp:
- Jul 5, 2017 5:37:24 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip-apps/src/samples/streamutil.c
r5618 r5621 88 88 " AES_CM_128_HMAC_SHA1_32 \n" 89 89 " Use this option along with the TX & RX keys, \n" 90 " formated of 60 hex digits (e.g: E148DA..) 90 " formated of 60 hex digits (e.g: E148DA..) \n" 91 91 " --srtp-tx-key SRTP key for transmiting \n" 92 92 " --srtp-rx-key SRTP key for receiving \n" 93 " --srtp-dtls-client Use DTLS for SRTP keying, as DTLS client \n" 94 " --srtp-dtls-server Use DTLS for SRTP keying, as DTLS server \n" 93 95 #endif 94 96 … … 147 149 const pj_str_t *srtp_tx_key, 148 150 const pj_str_t *srtp_rx_key, 151 pj_bool_t is_dtls_client, 152 pj_bool_t is_dtls_server, 149 153 #endif 150 154 pjmedia_stream **p_stream ) … … 287 291 /* Check if SRTP enabled */ 288 292 if (use_srtp) { 289 pjmedia_srtp_crypto tx_plc, rx_plc;290 291 293 status = pjmedia_transport_srtp_create(med_endpt, transport, 292 294 NULL, &srtp_tp); … … 294 296 return status; 295 297 296 pj_bzero(&tx_plc, sizeof(pjmedia_srtp_crypto)); 297 pj_bzero(&rx_plc, sizeof(pjmedia_srtp_crypto)); 298 299 tx_plc.key = *srtp_tx_key; 300 tx_plc.name = *crypto_suite; 301 rx_plc.key = *srtp_rx_key; 302 rx_plc.name = *crypto_suite; 303 304 status = pjmedia_transport_srtp_start(srtp_tp, &tx_plc, &rx_plc); 305 if (status != PJ_SUCCESS) 306 return status; 298 if (is_dtls_client || is_dtls_server) { 299 char fp[128]; 300 pj_size_t fp_len = sizeof(fp); 301 pjmedia_srtp_dtls_nego_param dtls_param; 302 303 pjmedia_transport_srtp_dtls_get_fingerprint(srtp_tp, "SHA-256", fp, &fp_len); 304 PJ_LOG(3, (THIS_FILE, "Local cert fingerprint: %s", fp)); 305 306 pj_bzero(&dtls_param, sizeof(dtls_param)); 307 pj_sockaddr_cp(&dtls_param.rem_addr, rem_addr); 308 pj_sockaddr_cp(&dtls_param.rem_rtcp, rem_addr); 309 dtls_param.is_role_active = is_dtls_client; 310 311 status = pjmedia_transport_srtp_dtls_start_nego(srtp_tp, &dtls_param); 312 if (status != PJ_SUCCESS) 313 return status; 314 } else { 315 pjmedia_srtp_crypto tx_plc, rx_plc; 316 317 pj_bzero(&tx_plc, sizeof(pjmedia_srtp_crypto)); 318 pj_bzero(&rx_plc, sizeof(pjmedia_srtp_crypto)); 319 320 tx_plc.key = *srtp_tx_key; 321 tx_plc.name = *crypto_suite; 322 rx_plc.key = *srtp_rx_key; 323 rx_plc.name = *crypto_suite; 324 325 status = pjmedia_transport_srtp_start(srtp_tp, &tx_plc, &rx_plc); 326 if (status != PJ_SUCCESS) 327 return status; 328 } 307 329 308 330 transport = srtp_tp; … … 362 384 pj_str_t srtp_rx_key = {NULL, 0}; 363 385 pj_str_t srtp_crypto_suite = {NULL, 0}; 386 pj_bool_t is_dtls_client = PJ_FALSE; 387 pj_bool_t is_dtls_server = PJ_FALSE; 364 388 int tmp_key_len; 365 389 #endif … … 392 416 OPT_SRTP_TX_KEY = 'x', 393 417 OPT_SRTP_RX_KEY = 'y', 418 OPT_SRTP_DTLS_CLIENT = 'd', 419 OPT_SRTP_DTLS_SERVER = 'D', 394 420 OPT_HELP = 'h', 395 421 }; … … 409 435 { "srtp-tx-key", 1, 0, OPT_SRTP_TX_KEY }, 410 436 { "srtp-rx-key", 1, 0, OPT_SRTP_RX_KEY }, 437 { "srtp-dtls-client", 0, 0, OPT_SRTP_DTLS_CLIENT }, 438 { "srtp-dtls-server", 0, 0, OPT_SRTP_DTLS_SERVER }, 411 439 #endif 412 440 { "help", 0, 0, OPT_HELP }, … … 510 538 pj_strset(&srtp_rx_key, tmp_rx_key, tmp_key_len/2); 511 539 break; 540 case OPT_SRTP_DTLS_CLIENT: 541 is_dtls_client = PJ_TRUE; 542 if (is_dtls_server) { 543 printf("Error: Cannot be as both DTLS server & client\n"); 544 return 1; 545 } 546 break; 547 case OPT_SRTP_DTLS_SERVER: 548 is_dtls_server = PJ_TRUE; 549 if (is_dtls_client) { 550 printf("Error: Cannot be as both DTLS server & client\n"); 551 return 1; 552 } 553 break; 512 554 #endif 513 555 … … 525 567 526 568 /* Verify arguments. */ 527 if (dir & PJMEDIA_DIR_ENCODING ) {569 if (dir & PJMEDIA_DIR_ENCODING || is_dtls_client || is_dtls_server) { 528 570 if (remote_addr.sin_addr.s_addr == 0) { 529 571 printf("Error: remote address must be set\n"); … … 540 582 /* SRTP validation */ 541 583 if (use_srtp) { 542 if (!srtp_tx_key.slen || !srtp_rx_key.slen) 584 if (!is_dtls_client && !is_dtls_server && 585 (!srtp_tx_key.slen || !srtp_rx_key.slen)) 543 586 { 544 587 printf("Error: Key for each SRTP stream direction must be set\n"); … … 596 639 use_srtp, &srtp_crypto_suite, 597 640 &srtp_tx_key, &srtp_rx_key, 641 is_dtls_client, is_dtls_server, 598 642 #endif 599 643 &stream);
Note: See TracChangeset
for help on using the changeset viewer.