Unverified 提交 31909cfc authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

SRTP: add support for AEAD_AES_256_GCM and AEAD_AES_128_GCM (#322)

上级 3a98f2a9
...@@ -13,7 +13,9 @@ namespace RTC ...@@ -13,7 +13,9 @@ namespace RTC
{ {
NONE = 0, NONE = 0,
AES_CM_128_HMAC_SHA1_80 = 1, AES_CM_128_HMAC_SHA1_80 = 1,
AES_CM_128_HMAC_SHA1_32 AES_CM_128_HMAC_SHA1_32,
AEAD_AES_256_GCM,
AEAD_AES_128_GCM
}; };
public: public:
......
...@@ -60,13 +60,21 @@ namespace RTC ...@@ -60,13 +60,21 @@ namespace RTC
{ {
/* Static. */ /* Static. */
// clang-format off
static constexpr int DtlsMtu{ 1350 }; static constexpr int DtlsMtu{ 1350 };
static constexpr int SslReadBufferSize{ 65536 }; static constexpr int SslReadBufferSize{ 65536 };
// NOTE: Those values are hardcoded as we just use AES_CM_128_HMAC_SHA1_80 and // AES-HMAC: http://tools.ietf.org/html/rfc3711
// AES_CM_128_HMAC_SHA1_32 which share same length values for key and salt.
static constexpr size_t SrtpMasterKeyLength{ 16 }; static constexpr size_t SrtpMasterKeyLength{ 16 };
static constexpr size_t SrtpMasterSaltLength{ 14 }; static constexpr size_t SrtpMasterSaltLength{ 14 };
static constexpr size_t SrtpMasterLength{ SrtpMasterKeyLength + SrtpMasterSaltLength }; static constexpr size_t SrtpMasterLength{ SrtpMasterKeyLength + SrtpMasterSaltLength };
// AES-GCM: http://tools.ietf.org/html/rfc7714
static constexpr size_t SrtpAesGcm256MasterKeyLength{ 32 };
static constexpr size_t SrtpAesGcm256MasterSaltLength{ 12 };
static constexpr size_t SrtpAesGcm256MasterLength{ SrtpAesGcm256MasterKeyLength + SrtpAesGcm256MasterSaltLength };
static constexpr size_t SrtpAesGcm128MasterKeyLength{ 16 };
static constexpr size_t SrtpAesGcm128MasterSaltLength{ 12 };
static constexpr size_t SrtpAesGcm128MasterLength{ SrtpAesGcm128MasterKeyLength + SrtpAesGcm128MasterSaltLength };
// clang-format on
/* Class variables. */ /* Class variables. */
...@@ -102,6 +110,8 @@ namespace RTC ...@@ -102,6 +110,8 @@ namespace RTC
// clang-format off // clang-format off
std::vector<DtlsTransport::SrtpProfileMapEntry> DtlsTransport::srtpProfiles = std::vector<DtlsTransport::SrtpProfileMapEntry> DtlsTransport::srtpProfiles =
{ {
{ RTC::SrtpSession::Profile::AEAD_AES_256_GCM, "SRTP_AEAD_AES_256_GCM" },
{ RTC::SrtpSession::Profile::AEAD_AES_128_GCM, "SRTP_AEAD_AES_128_GCM" },
{ RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" }, { RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" },
{ RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" } { RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_32, "SRTP_AES128_CM_SHA1_32" }
}; };
...@@ -1226,17 +1236,57 @@ namespace RTC ...@@ -1226,17 +1236,57 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
uint8_t srtpMaterial[SrtpMasterLength * 2]; size_t srtpKeyLength{ 0 };
size_t srtpSaltLength{ 0 };
size_t srtpMasterLength{ 0 };
switch (srtpProfile)
{
case RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_80:
case RTC::SrtpSession::Profile::AES_CM_128_HMAC_SHA1_32:
{
srtpKeyLength = SrtpMasterKeyLength;
srtpSaltLength = SrtpMasterSaltLength;
srtpMasterLength = SrtpMasterLength;
break;
}
case RTC::SrtpSession::Profile::AEAD_AES_256_GCM:
{
srtpKeyLength = SrtpAesGcm256MasterKeyLength;
srtpSaltLength = SrtpAesGcm256MasterSaltLength;
srtpMasterLength = SrtpAesGcm256MasterLength;
break;
}
case RTC::SrtpSession::Profile::AEAD_AES_128_GCM:
{
srtpKeyLength = SrtpAesGcm128MasterKeyLength;
srtpSaltLength = SrtpAesGcm128MasterSaltLength;
srtpMasterLength = SrtpAesGcm128MasterLength;
break;
}
default:
{
MS_ABORT("unknown SRTP profile");
}
}
uint8_t srtpMaterial[srtpMasterLength * 2];
uint8_t* srtpLocalKey; uint8_t* srtpLocalKey;
uint8_t* srtpLocalSalt; uint8_t* srtpLocalSalt;
uint8_t* srtpRemoteKey; uint8_t* srtpRemoteKey;
uint8_t* srtpRemoteSalt; uint8_t* srtpRemoteSalt;
uint8_t srtpLocalMasterKey[SrtpMasterLength]; uint8_t srtpLocalMasterKey[srtpMasterLength];
uint8_t srtpRemoteMasterKey[SrtpMasterLength]; uint8_t srtpRemoteMasterKey[srtpMasterLength];
int ret; int ret;
ret = SSL_export_keying_material( ret = SSL_export_keying_material(
this->ssl, srtpMaterial, SrtpMasterLength * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0); this->ssl, srtpMaterial, srtpMasterLength * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0);
MS_ASSERT(ret != 0, "SSL_export_keying_material() failed"); MS_ASSERT(ret != 0, "SSL_export_keying_material() failed");
...@@ -1245,9 +1295,9 @@ namespace RTC ...@@ -1245,9 +1295,9 @@ namespace RTC
case Role::SERVER: case Role::SERVER:
{ {
srtpRemoteKey = srtpMaterial; srtpRemoteKey = srtpMaterial;
srtpLocalKey = srtpRemoteKey + SrtpMasterKeyLength; srtpLocalKey = srtpRemoteKey + srtpKeyLength;
srtpRemoteSalt = srtpLocalKey + SrtpMasterKeyLength; srtpRemoteSalt = srtpLocalKey + srtpKeyLength;
srtpLocalSalt = srtpRemoteSalt + SrtpMasterSaltLength; srtpLocalSalt = srtpRemoteSalt + srtpSaltLength;
break; break;
} }
...@@ -1255,9 +1305,9 @@ namespace RTC ...@@ -1255,9 +1305,9 @@ namespace RTC
case Role::CLIENT: case Role::CLIENT:
{ {
srtpLocalKey = srtpMaterial; srtpLocalKey = srtpMaterial;
srtpRemoteKey = srtpLocalKey + SrtpMasterKeyLength; srtpRemoteKey = srtpLocalKey + srtpKeyLength;
srtpLocalSalt = srtpRemoteKey + SrtpMasterKeyLength; srtpLocalSalt = srtpRemoteKey + srtpKeyLength;
srtpRemoteSalt = srtpLocalSalt + SrtpMasterSaltLength; srtpRemoteSalt = srtpLocalSalt + srtpSaltLength;
break; break;
} }
...@@ -1269,11 +1319,11 @@ namespace RTC ...@@ -1269,11 +1319,11 @@ namespace RTC
} }
// Create the SRTP local master key. // Create the SRTP local master key.
std::memcpy(srtpLocalMasterKey, srtpLocalKey, SrtpMasterKeyLength); std::memcpy(srtpLocalMasterKey, srtpLocalKey, srtpKeyLength);
std::memcpy(srtpLocalMasterKey + SrtpMasterKeyLength, srtpLocalSalt, SrtpMasterSaltLength); std::memcpy(srtpLocalMasterKey + srtpKeyLength, srtpLocalSalt, srtpSaltLength);
// Create the SRTP remote master key. // Create the SRTP remote master key.
std::memcpy(srtpRemoteMasterKey, srtpRemoteKey, SrtpMasterKeyLength); std::memcpy(srtpRemoteMasterKey, srtpRemoteKey, srtpKeyLength);
std::memcpy(srtpRemoteMasterKey + SrtpMasterKeyLength, srtpRemoteSalt, SrtpMasterSaltLength); std::memcpy(srtpRemoteMasterKey + srtpKeyLength, srtpRemoteSalt, srtpSaltLength);
// Set state and notify the listener. // Set state and notify the listener.
this->state = DtlsState::CONNECTED; this->state = DtlsState::CONNECTED;
...@@ -1281,9 +1331,9 @@ namespace RTC ...@@ -1281,9 +1331,9 @@ namespace RTC
this, this,
srtpProfile, srtpProfile,
srtpLocalMasterKey, srtpLocalMasterKey,
SrtpMasterLength, srtpMasterLength,
srtpRemoteMasterKey, srtpRemoteMasterKey,
SrtpMasterLength, srtpMasterLength,
this->remoteCert); this->remoteCert);
} }
......
...@@ -66,17 +66,42 @@ namespace RTC ...@@ -66,17 +66,42 @@ namespace RTC
switch (profile) switch (profile)
{ {
case Profile::AES_CM_128_HMAC_SHA1_80: case Profile::AES_CM_128_HMAC_SHA1_80:
{
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break; break;
}
case Profile::AES_CM_128_HMAC_SHA1_32: case Profile::AES_CM_128_HMAC_SHA1_32:
{
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp); srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // NOTE: Must be 80 for RTCP!. // NOTE: Must be 80 for RTCP.
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp);
break; break;
}
case Profile::AEAD_AES_256_GCM:
{
srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_256_16_auth(&policy.rtcp);
break;
}
case Profile::AEAD_AES_128_GCM:
{
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtp);
srtp_crypto_policy_set_aes_gcm_128_16_auth(&policy.rtcp);
break;
}
default: default:
MS_ABORT("unknown SRTP suite"); {
MS_ABORT("unknown SRTP profile");
}
} }
MS_ASSERT( MS_ASSERT(
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论