参考文章:详解 WebRTC 传输安全机制:一文读懂 DTLS 协议 - 知乎

SRTP:rtp头没有加密,payload加密了。
a=setup:active:作为客户端,主动发送协商。
a=setup:passive:作为服务端,等待协商。
a=setup:actpass:作为客户端,主动发送协商。作为服务端,等待协商。
客户端的sdp是a=setup:actpass,sdp type是offer。
服务器janus的sdp是a=setup:active,sdp type是answer,音视频一样。
服务器janus先发Client Hello,作为DTLS Client,主动发送协商。

Server Hello中重要的字段:Cipher Suite、use_srtp的类型。



- //material就是srtp密钥?
- SSL_export_keying_material(dtls->ssl, material, master_length*2, "EXTRACTOR-dtls_srtp", 19, NULL, 0, 0)
- srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&(dtls->remote_policy.rtp));
-
- memcpy(dtls->remote_policy.key, remote_key, key_length);
- memcpy(dtls->remote_policy.key + key_length, remote_salt, salt_length);
- srtp_create(&(dtls->srtp_in), &(dtls->remote_policy));
- //libsrtp主要函数:
- srtp_err_status_t res = srtp_create(&srtp_ctx->ctx, policy);
- //加密:把音视频数据拷贝到sbuf
- srtp_protect(rtp_forward->srtp_ctx->ctx, &rtp_forward->srtp_ctx->sbuf, &protected);
-
- srtp_unprotect(pc->dtls->srtp_in, buf, &buflen);//解密
NAT:把内网IP转换成公网IP+端口。
ICE是一个框架,整合了STUN和TRUN。分tcp和udp、host、replay。
TRUN:在STUN上,加了中继功能,即转发功能。
janus用的libnice库,mediasoup自己实现的。
sdp的ice-ufrag、ice-pwd。
nice_agent_set_remote_credentials(handle->agent, handle->stream_id, ruser, rpass)。
fingerprint判断是否相等。一个是sdp带的,另一个是stun包中。
1 先SDP协商、2 发stun包—bind request、response、绑定ip和port。
3 dtls:Client Hello、Server Hello等、4 srtp包--使用绑定ip和port。