ARTICLE DETAIL

资讯详情

深耕网站SEO优化与搜索引擎排名提升的一线实战洞察。

DTLS、ICE--用janus举例

DTLS、ICE--用janus举例 参考文章详解 WebRTC 传输安全机制一文读懂 DTLS 协议 - 知乎一 DTLSudp上的tls传输音视频用的用的libsrtp库。SRTPrtp头没有加密payload加密了。asetup:active作为DTLS客户端主动发起协商即client hello。asetup:passive作为DTLS服务端等待协商。asetup:actpass由对端决定谁active谁passive。客户端的sdp是asetup:actpasssdp type是offer。服务器janus的sdp是asetup:passivesdp type是answer音视频一样。客户端先发Client Hello作为DTLS Client主动发送协商。二 SRTP的密钥怎么算跟类型、Server的pubkey、Client的pubkey有关。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);//解密三 ICENat穿透相关。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带的另一个是DTLS握手中的Certificate的x.509证书。本地计算出证书的SHA256 fingerprint再比较。四 顺序1 信令交换sdp、2ICE连通检测-stun包—bind request、response、绑定ip和port。3 在ICE已打通的udp端口进行DTLS握手Client Hello、Server Hello等、4 srtp包--使用绑定ip和port。
返回列表