• DTLS、ICE--用janus举例


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

    一 DTLS:udp上的tls,传输音视频用的,用的libsrtp库。

    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,主动发送协商。

    二 SRTP的密钥怎么算?跟类型、Server的pubkey、Client的pubkey有关。

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

    1. //material就是srtp密钥?
    2. SSL_export_keying_material(dtls->ssl, material, master_length*2, "EXTRACTOR-dtls_srtp", 19, NULL, 0, 0)
    3. srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&(dtls->remote_policy.rtp));
    4. memcpy(dtls->remote_policy.key, remote_key, key_length);
    5. memcpy(dtls->remote_policy.key + key_length, remote_salt, salt_length);
    6. srtp_create(&(dtls->srtp_in), &(dtls->remote_policy));
    1. //libsrtp主要函数:
    2. srtp_err_status_t res = srtp_create(&srtp_ctx->ctx, policy);
    3. //加密:把音视频数据拷贝到sbuf
    4. srtp_protect(rtp_forward->srtp_ctx->ctx, &rtp_forward->srtp_ctx->sbuf, &protected);
    5. srtp_unprotect(pc->dtls->srtp_in, buf, &buflen);//解密

    三 ICE:Nat穿透相关。

    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。

  • 相关阅读:
    首批 RISC-V 手机要来了,你准备好了吗?
    揭秘计算机奇迹:探索I/O设备的神秘世界!
    JavaWeb页面初体验
    【送书活动】揭秘分布式文件系统大规模元数据管理机制——以Alluxio文件系统为例
    【Python测试开发】断言
    Java项目之石头剪刀布
    前端状态码大全(200,404,503等)
    UE5和UE4版本更新重大改变汇总。
    Flow Problem hdu 3549 网络流模板题目
    SpringBoot整合Kafka
  • 原文地址:https://blog.csdn.net/chenquangobeijing/article/details/126750629