- Timestamp:
- Jul 27, 2018 6:16:26 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_srtp_dtls.c
r5823 r5847 107 107 pj_bool_t use_ice; 108 108 pj_bool_t nego_started; 109 pj_bool_t nego_completed; 109 110 pj_str_t rem_fingerprint; /* Remote fingerprint in SDP */ 110 111 pj_status_t rem_fprint_status; /* Fingerprint verif. status */ … … 229 230 status = ERR_GET_REASON(err); 230 231 231 status += PJ_SSL_ERRNO_START; 232 if (status != PJ_SUCCESS) 233 status += PJ_SSL_ERRNO_START; 234 232 235 ds->last_err = err; 233 236 return status; … … 642 645 } 643 646 644 /* Check if handshake has been completed */ 645 if (!SSL_is_init_finished(ds->ossl_ssl)) 647 /* Just return if handshake completion procedure (key parsing, fingerprint 648 * verification, etc) has been done or handshake is still in progress. 649 */ 650 if (ds->nego_completed || !SSL_is_init_finished(ds->ossl_ssl)) 646 651 return PJ_SUCCESS; 647 652 648 653 /* Yes, SSL handshake is done! */ 654 ds->nego_completed = PJ_TRUE; 649 655 PJ_LOG(2,(ds->base.name, "DTLS-SRTP negotiation completed!")); 650 656 651 /* Stop the retrans clock */ 657 /* Stop the retransmission clock. Note that the clock may not be stopped 658 * if this function is called from clock thread context. We'll try again 659 * later in socket context. 660 */ 652 661 if (ds->clock) 653 662 pjmedia_clock_stop(ds->clock); … … 963 972 dtls_srtp *ds = (dtls_srtp*)tp; 964 973 974 /* Destroy the retransmission clock if handshake has been completed. */ 975 if (ds->clock && ds->nego_completed) { 976 pjmedia_clock_destroy(ds->clock); 977 ds->clock = NULL; 978 } 979 965 980 if (size < 1 || !IS_DTLS_PKT(pkt, size)) 966 981 return PJ_EIGNORED; … … 970 985 #endif 971 986 972 /* This is DTLS packet, let's process it */ 987 /* This is DTLS packet, let's process it. Note that if DTLS nego has 988 * been completed, this may be a retransmission (e.g: remote didn't 989 * receive our last handshake packet) or just a stray. 990 */ 973 991 974 992 /* Check remote address info, reattach member tp if changed */ 975 if (!ds->use_ice ) {993 if (!ds->use_ice && !ds->nego_completed) { 976 994 pjmedia_transport_info info; 977 995 pjmedia_transport_get_info(ds->srtp->member_tp, &info); … … 999 1017 1000 1018 pjmedia_transport_attach2(&ds->srtp->base, &ap); 1019 1020 #if DTLS_DEBUG 1021 { 1022 char addr[PJ_INET6_ADDRSTRLEN]; 1023 PJ_LOG(2,(ds->base.name, "Re-attached transport to update " 1024 "remote addr=%s:%d", 1025 pj_sockaddr_print(&ap.rem_addr, addr, 1026 sizeof(addr), 2), 1027 pj_sockaddr_get_port(&ap.rem_addr))); 1028 } 1029 #endif 1001 1030 } 1002 1031 } … … 1005 1034 * so let's update setup to PASSIVE and initiate DTLS handshake. 1006 1035 */ 1007 if (ds->setup == DTLS_SETUP_ACTPASS || ds->setup == DTLS_SETUP_PASSIVE) 1036 if (!ds->nego_started && 1037 (ds->setup == DTLS_SETUP_ACTPASS || ds->setup == DTLS_SETUP_PASSIVE)) 1008 1038 { 1009 1039 pj_status_t status; … … 1167 1197 ssl_destroy(ds); 1168 1198 ds->nego_started = PJ_FALSE; 1199 ds->nego_completed = PJ_FALSE; 1169 1200 ds->got_keys = PJ_FALSE; 1170 1201 ds->rem_fprint_status = PJ_EPENDING; … … 1198 1229 } 1199 1230 1200 if (ds->got_keys) { 1201 /* This is subsequent SDP offer/answer and we already got SRTP keys */ 1231 if (ds->nego_completed) { 1232 /* This is subsequent SDP offer/answer and no DTLS re-nego has been 1233 * signalled. 1234 */ 1202 1235 goto on_return; 1203 1236 } … … 1247 1280 */ 1248 1281 udp_member_transport_media_start(ds); 1282 1283 #if DTLS_DEBUG 1284 { 1285 char addr[PJ_INET6_ADDRSTRLEN]; 1286 PJ_LOG(2,(ds->base.name, "Attached transport, remote addr=%s:%d", 1287 pj_sockaddr_print(&ap.rem_addr, addr, sizeof(addr), 2), 1288 pj_sockaddr_get_port(&ap.rem_addr))); 1289 } 1290 #endif 1249 1291 } 1250 1292 … … 1317 1359 ssl_destroy(ds); 1318 1360 ds->nego_started = PJ_FALSE; 1361 ds->nego_completed = PJ_FALSE; 1319 1362 ds->got_keys = PJ_FALSE; 1320 1363 ds->rem_fprint_status = PJ_EPENDING; … … 1401 1444 if (status != PJ_SUCCESS) 1402 1445 goto on_return; 1446 #if DTLS_DEBUG 1447 { 1448 char addr[PJ_INET6_ADDRSTRLEN]; 1449 PJ_LOG(2,(ds->base.name, "Attached transport, " 1450 "remote addr=%s:%d", 1451 pj_sockaddr_print(&ap.rem_addr, addr, 1452 sizeof(addr), 2), 1453 pj_sockaddr_get_port(&ap.rem_addr))); 1454 } 1455 #endif 1403 1456 1404 1457 status = ssl_handshake(ds); … … 1518 1571 goto on_return; 1519 1572 1573 #if DTLS_DEBUG 1574 { 1575 char addr[PJ_INET6_ADDRSTRLEN]; 1576 PJ_LOG(2,(ds->base.name, "Attached transport, remote addr=%s:%d", 1577 pj_sockaddr_print(&ap.rem_addr, addr, sizeof(addr), 2), 1578 pj_sockaddr_get_port(&ap.rem_addr))); 1579 } 1580 #endif 1581 1520 1582 /* Start DTLS handshake */ 1521 1583 pj_bzero(&srtp->rx_policy_neg, sizeof(srtp->rx_policy_neg));
Note: See TracChangeset
for help on using the changeset viewer.