提交 4a22ba54 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Work in DTLSAgent.

上级 05d5447c
......@@ -2,26 +2,43 @@
#define MS_RTC_DTLS_AGENT_H
#include "common.h"
#include "RTC/SRTPSession.h"
#include "handles/Timer.h"
#include "RTC/DTLSRole.h"
#include "RTC/FingerprintHash.h"
#include "RTC/SRTPProfile.h"
#include <string>
#include <map>
#include <vector>
#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/x509.h>
#include <json/json.h>
namespace RTC
{
class DTLSAgent :
public Timer::Listener
{
public:
enum class DTLSRole
{
NONE = 0,
SERVER = 1,
CLIENT
};
public:
enum class FingerprintHash
{
NONE = 0,
SHA1 = 1,
SHA224,
SHA256,
SHA384,
SHA512
};
private:
struct SrtpProfileMapEntry
{
SRTPProfile profile;
RTC::SRTPSession::SRTPProfile profile;
const char* name;
};
......@@ -37,15 +54,15 @@ namespace RTC
virtual void onDTLSConnected(DTLSAgent* dtlsAgent) = 0;
virtual void onDTLSDisconnected(DTLSAgent* dtlsAgent) = 0;
virtual void onDTLSFailed(DTLSAgent* dtlsAgent) = 0;
virtual void onSRTPKeyMaterial(DTLSAgent* dtlsAgent, RTC::SRTPProfile srtp_profile, MS_BYTE* srtp_local_key, size_t srtp_local_key_len, MS_BYTE* srtp_remote_key, size_t srtp_remote_key_len) = 0;
virtual void onSRTPKeyMaterial(DTLSAgent* dtlsAgent, RTC::SRTPSession::SRTPProfile srtp_profile, MS_BYTE* srtp_local_key, size_t srtp_local_key_len, MS_BYTE* srtp_remote_key, size_t srtp_remote_key_len) = 0;
virtual void onDTLSApplicationData(DTLSAgent* dtlsAgent, const MS_BYTE* data, size_t len) = 0;
};
public:
static void ClassInit();
static void ClassDestroy();
static Json::Value& GetLocalFingerprints();
static bool IsDTLS(const MS_BYTE* data, size_t len);
static const std::string& GetFingerprint(RTC::FingerprintHash hash);
private:
static void GenerateCertificateAndPrivateKey();
......@@ -57,8 +74,7 @@ namespace RTC
static X509* certificate;
static EVP_PKEY* privateKey;
static SSL_CTX* sslCtx;
typedef std::map<RTC::FingerprintHash, std::string> Fingerprints;
static Fingerprints fingerprints;
static Json::Value localFingerprints;
typedef std::vector<SrtpProfileMapEntry> SRTPProfiles;
static SRTPProfiles srtpProfiles;
static MS_BYTE sslReadBuffer[];
......@@ -67,8 +83,8 @@ namespace RTC
DTLSAgent(Listener* listener);
virtual ~DTLSAgent();
void Run(RTC::DTLSRole role);
void SetRemoteFingerprint(RTC::FingerprintHash hash, std::string& fingerprint);
void Run(DTLSRole role);
void SetRemoteFingerprint(FingerprintHash hash, std::string& fingerprint);
void Reset();
void Close();
void ProcessDTLSData(const MS_BYTE* data, size_t len);
......@@ -83,8 +99,8 @@ namespace RTC
void SetTimeout();
void ProcessHandshake();
bool CheckRemoteFingerprint();
RTC::SRTPProfile GetNegotiatedSRTPProfile();
void ExtractSRTPKeys(RTC::SRTPProfile srtp_profile);
RTC::SRTPSession::SRTPProfile GetNegotiatedSRTPProfile();
void ExtractSRTPKeys(RTC::SRTPSession::SRTPProfile srtp_profile);
/* Callbacks fired by OpenSSL events. */
public:
......@@ -103,8 +119,8 @@ namespace RTC
BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes.
Timer* timer = nullptr;
// Others.
RTC::DTLSRole role;
RTC::FingerprintHash remoteFingerprintHash = RTC::FingerprintHash::NONE;
DTLSRole role = DTLSRole::NONE;
FingerprintHash remoteFingerprintHash = FingerprintHash::NONE;
std::string remoteFingerprint;
bool isRunning = false;
bool isHandshakeDone = false;
......
#ifndef MS_RTC_DTLS_ROLE_H
#define MS_RTC_DTLS_ROLE_H
namespace RTC
{
enum class DTLSRole
{
NONE = 0,
SERVER = 1,
CLIENT
};
}
#endif
#ifndef MS_RTC_FINGERPRINT_HASH_H
#define MS_RTC_FINGERPRINT_HASH_H
namespace RTC
{
enum class FingerprintHash
{
NONE = 0,
SHA1 = 1,
SHA224,
SHA256,
SHA384,
SHA512
};
}
#endif
#ifndef MS_RTC_SRTP_PROFILE_H
#define MS_RTC_SRTP_PROFILE_H
namespace RTC
{
enum class SRTPProfile
{
NONE = 0,
AES_CM_128_HMAC_SHA1_80 = 1,
AES_CM_128_HMAC_SHA1_32
};
}
#endif
......@@ -3,13 +3,20 @@
#include "common.h"
#include "DepLibSRTP.h"
#include "RTC/SRTPProfile.h"
#include <srtp/srtp.h>
namespace RTC
{
class SRTPSession
{
public:
enum class SRTPProfile
{
NONE = 0,
AES_CM_128_HMAC_SHA1_80 = 1,
AES_CM_128_HMAC_SHA1_32
};
public:
enum class Type
{
......@@ -27,7 +34,7 @@ namespace RTC
static MS_BYTE encryptBuffer[];
public:
SRTPSession(Type type, RTC::SRTPProfile profile, MS_BYTE* key, size_t key_len);
SRTPSession(Type type, SRTPProfile profile, MS_BYTE* key, size_t key_len);
~SRTPSession();
bool EncryptRTP(const MS_BYTE** data, size_t* len);
......
......@@ -4,6 +4,7 @@
#include "common.h"
#include "RTC/IceCandidate.h"
#include "RTC/IceServer.h"
#include "RTC/DTLSAgent.h"
#include "RTC/STUNMessage.h"
#include "RTC/TransportSource.h"
#include "RTC/UDPSocket.h"
......
#define MS_CLASS "RTC::Peer"
#include "RTC/Peer.h"
#include "RTC/DTLSRole.h"
#include "MediaSoupError.h"
#include "Logger.h"
......
......@@ -56,7 +56,7 @@ namespace RTC
/* Instance methods. */
SRTPSession::SRTPSession(Type type, RTC::SRTPProfile profile, MS_BYTE* key, size_t key_len)
SRTPSession::SRTPSession(Type type, SRTPProfile profile, MS_BYTE* key, size_t key_len)
{
MS_TRACE();
......@@ -68,11 +68,11 @@ namespace RTC
switch (profile)
{
case RTC::SRTPProfile::AES_CM_128_HMAC_SHA1_80:
case SRTPProfile::AES_CM_128_HMAC_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 RTC::SRTPProfile::AES_CM_128_HMAC_SHA1_32:
case SRTPProfile::AES_CM_128_HMAC_SHA1_32:
crypto_policy_set_aes_cm_128_hmac_sha1_32(&policy.rtp);
crypto_policy_set_aes_cm_128_hmac_sha1_80(&policy.rtcp); // NOTE: Must be 80 for RTCP!.
break;
......
......@@ -235,24 +235,30 @@ namespace RTC
static const Json::StaticString k_iceLocalCandidates("iceLocalCandidates");
static const Json::StaticString v_RTP("RTP");
static const Json::StaticString v_RTCP("RTCP");
static const Json::StaticString k_dtlsLocalFingerprints("dtlsLocalFingerprints");
Json::Value data;
// Add `iceComponent`.
if (this->iceComponent == IceComponent::RTP)
data[k_iceComponent] = v_RTP;
else
data[k_iceComponent] = v_RTCP;
// Add `iceLocalParameters`.
data[k_iceLocalParameters][k_usernameFragment] = this->iceServer->GetUsernameFragment();
data[k_iceLocalParameters][k_password] = this->iceServer->GetPassword();
// Add `iceLocalCandidates`.
data[k_iceLocalCandidates] = Json::arrayValue;
for (auto iceCandidate : this->iceLocalCandidates)
{
data[k_iceLocalCandidates].append(iceCandidate.toJson());
}
// Add `dtlsLocalFingerprints`.
data[k_dtlsLocalFingerprints] = RTC::DTLSAgent::GetLocalFingerprints();
return data;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论