gpt4 book ai didi

encryption - WebRTC SRTP解密

转载 作者:行者123 更新时间:2023-12-04 01:06:25 25 4
gpt4 key购买 nike

我正在尝试构建 SRTPRTP流转换器,我在获取 Master Key 时遇到问题来自 WebRTC peerconnection我正在创作。
据我了解,使用 DES exchange ,关键是通过 SDP 进行交换交换并显示在 a=crypto field 。所以,这种情况看起来很简单(如果我错了,请纠正我),但最终没用,因为 WebRTC标准化现在要求不应使用 DES(只有 Chrome 现在支持它,将来可能会被删除)。
对于DTLS SDP 中有指纹字段, 是 certificate desired 的哈希值吗?在 future 的交换中使用?[编辑:在阅读了一些内容后,我认为情况并非如此能够抢到Master Key解码 SRTP 流,但我碰壁了,因为我不知道在哪里看,甚至 100% 确定是否可能。
因此,简而言之,解码 WebRTC 是否可行(无需进入较低的 C++ API 并创建我自己的 SRTP 实现)使用 WebRTC PeerConnection 创建的提要在 ChromeFireFox (可能通过从 SDP 交换中收集的信息进行数据包嗅探)?[编辑:令人沮丧的是,似乎无法访问 key 的私有(private)部分(又名主 key )......如果我请更正我错了]

最佳答案

这是一些使用 openssl 和 libsrtp native api 的代码

#define SRTP_MASTER_KEY_KEY_LEN 16
#define SRTP_MASTER_KEY_SALT_LEN 14
static void dtls_srtp_init( struct transport_dtls *dtls )
{

/*
When SRTP mode is in effect, different keys are used for ordinary
DTLS record protection and SRTP packet protection. These keys are
generated using a TLS exporter [RFC5705] to generate

2 * (SRTPSecurityParams.master_key_len +
SRTPSecurityParams.master_salt_len) bytes of data

which are assigned as shown below. The per-association context value
is empty.

client_write_SRTP_master_key[SRTPSecurityParams.master_key_len];
server_write_SRTP_master_key[SRTPSecurityParams.master_key_len];
client_write_SRTP_master_salt[SRTPSecurityParams.master_salt_len];
server_write_SRTP_master_salt[SRTPSecurityParams.master_salt_len];
*/
int code;
err_status_t err;
srtp_policy_t policy;
char dtls_buffer[SRTP_MASTER_KEY_KEY_LEN * 2 + SRTP_MASTER_KEY_SALT_LEN * 2];
char client_write_key[SRTP_MASTER_KEY_KEY_LEN + SRTP_MASTER_KEY_SALT_LEN];
char server_write_key[SRTP_MASTER_KEY_KEY_LEN + SRTP_MASTER_KEY_SALT_LEN];
size_t offset = 0;

/*
The exporter label for this usage is "EXTRACTOR-dtls_srtp". (The
"EXTRACTOR" prefix is for historical compatibility.)
RFC 5764 4.2. Key Derivation
*/
const char * label = "EXTRACTOR-dtls_srtp";

SRTP_PROTECTION_PROFILE * srtp_profile= SSL_get_selected_srtp_profile( dtls->ssl );

/* SSL_export_keying_material exports a value derived from the master secret,
* as specified in RFC 5705. It writes |olen| bytes to |out| given a label and
* optional context. (Since a zero length context is allowed, the |use_context|
* flag controls whether a context is included.)
*
* It returns 1 on success and zero otherwise.
*/
code = SSL_export_keying_material(dtls->ssl,
dtls_buffer,
sizeof(dtls_buffer),
label,
strlen( label),
NULL,
0,
PJ_FALSE);

memcpy(&client_write_key[0], &dtls_buffer[offset], SRTP_MASTER_KEY_KEY_LEN);
offset += SRTP_MASTER_KEY_KEY_LEN;
memcpy(&server_write_key[0], &dtls_buffer[offset], SRTP_MASTER_KEY_KEY_LEN);
offset += SRTP_MASTER_KEY_KEY_LEN;
memcpy(&client_write_key[SRTP_MASTER_KEY_KEY_LEN], &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);
offset += SRTP_MASTER_KEY_SALT_LEN;
memcpy(&server_write_key[SRTP_MASTER_KEY_KEY_LEN], &dtls_buffer[offset], SRTP_MASTER_KEY_SALT_LEN);

switch( srtp_profile->id )
{
case SRTP_AES128_CM_SHA1_80:
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break;
case SRTP_AES128_CM_SHA1_32:
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); // rtp is 32,
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // rtcp still 80
break;
default:
assert(0);
}
policy.ssrc.value = 0;
policy.next = NULL;

/* Init transmit direction */
policy.ssrc.type = ssrc_any_outbound;
policy.key = client_write_key;

err = srtp_create(&dtls->srtp_ctx_rx, &policy);
if (err != err_status_ok) {
printf("not working\n");
}

/* Init receive direction */
policy.ssrc.type = ssrc_any_inbound;
policy.key = server_write_key;

err = srtp_create(&dtls->srtp_ctx_tx, &policy);
if (err != err_status_ok) {
printf("not working\n");
}

}

关于encryption - WebRTC SRTP解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22692109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com