Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed DTLS SRTP keys for DTLS_SRTP_ROLE_CLIENT #190

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/dtls_srtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,15 +270,31 @@ static int dtls_srtp_key_derivation(DtlsSrtp* dtls_srtp, const unsigned char* ma
printf("\n");
#endif

const uint8_t* client_key = key_material;
const uint8_t* server_key = client_key + SRTP_MASTER_KEY_LENGTH;
const uint8_t* client_salt = server_key + SRTP_MASTER_KEY_LENGTH;
const uint8_t* server_salt = client_salt + SRTP_MASTER_SALT_LENGTH;
uint8_t *local_key, *remote_key, *local_salt, *remote_salt;
if (dtls_srtp->role == DTLS_SRTP_ROLE_SERVER) {
local_key = server_key;
local_salt = server_salt;
remote_key = client_key;
remote_salt = client_salt;
} else {
local_key = client_key;
local_salt = client_salt;
remote_key = server_key;
remote_salt = server_salt;
}
// derive inbounds keys

memset(&dtls_srtp->remote_policy, 0, sizeof(dtls_srtp->remote_policy));

srtp_crypto_policy_set_rtp_default(&dtls_srtp->remote_policy.rtp);
srtp_crypto_policy_set_rtcp_default(&dtls_srtp->remote_policy.rtcp);

memcpy(dtls_srtp->remote_policy_key, key_material, SRTP_MASTER_KEY_LENGTH);
memcpy(dtls_srtp->remote_policy_key + SRTP_MASTER_KEY_LENGTH, key_material + SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_KEY_LENGTH, SRTP_MASTER_SALT_LENGTH);
memcpy(dtls_srtp->remote_policy_key, remote_key, SRTP_MASTER_KEY_LENGTH);
memcpy(dtls_srtp->remote_policy_key + SRTP_MASTER_KEY_LENGTH, remote_salt, SRTP_MASTER_SALT_LENGTH);

dtls_srtp->remote_policy.ssrc.type = ssrc_any_inbound;
dtls_srtp->remote_policy.key = dtls_srtp->remote_policy_key;
Expand All @@ -297,8 +313,8 @@ static int dtls_srtp_key_derivation(DtlsSrtp* dtls_srtp, const unsigned char* ma
srtp_crypto_policy_set_rtp_default(&dtls_srtp->local_policy.rtp);
srtp_crypto_policy_set_rtcp_default(&dtls_srtp->local_policy.rtcp);

memcpy(dtls_srtp->local_policy_key, key_material + SRTP_MASTER_KEY_LENGTH, SRTP_MASTER_KEY_LENGTH);
memcpy(dtls_srtp->local_policy_key + SRTP_MASTER_KEY_LENGTH, key_material + SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_KEY_LENGTH + SRTP_MASTER_SALT_LENGTH, SRTP_MASTER_SALT_LENGTH);
memcpy(dtls_srtp->local_policy_key, local_key, SRTP_MASTER_KEY_LENGTH);
memcpy(dtls_srtp->local_policy_key + SRTP_MASTER_KEY_LENGTH, local_salt, SRTP_MASTER_SALT_LENGTH);

dtls_srtp->local_policy.ssrc.type = ssrc_any_outbound;
dtls_srtp->local_policy.key = dtls_srtp->local_policy_key;
Expand Down
Loading