Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
6938a76d
提交
6938a76d
authored
2月 27, 2020
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PipeTransport with SRTP may be done (testing needed!)
上级
010c66c6
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
136 行增加
和
45 行删除
+136
-45
PipeTransport.hpp
worker/include/RTC/PipeTransport.hpp
+4
-0
PipeTransport.cpp
worker/src/RTC/PipeTransport.cpp
+109
-11
PlainRtpTransport.cpp
worker/src/RTC/PlainRtpTransport.cpp
+4
-10
WebRtcTransport.cpp
worker/src/RTC/WebRtcTransport.cpp
+19
-24
没有找到文件。
worker/include/RTC/PipeTransport.hpp
浏览文件 @
6938a76d
#ifndef MS_RTC_PIPE_TRANSPORT_HPP
#ifndef MS_RTC_PIPE_TRANSPORT_HPP
#define MS_RTC_PIPE_TRANSPORT_HPP
#define MS_RTC_PIPE_TRANSPORT_HPP
#include "RTC/SrtpSession.hpp"
#include "RTC/Transport.hpp"
#include "RTC/Transport.hpp"
#include "RTC/TransportTuple.hpp"
#include "RTC/TransportTuple.hpp"
#include "RTC/UdpSocket.hpp"
#include "RTC/UdpSocket.hpp"
...
@@ -26,6 +27,7 @@ namespace RTC
...
@@ -26,6 +27,7 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
)
override
;
void
HandleRequest
(
Channel
::
Request
*
request
)
override
;
private
:
private
:
bool
HasSrtp
()
const
;
bool
IsConnected
()
const
override
;
bool
IsConnected
()
const
override
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
=
nullptr
)
override
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
=
nullptr
)
override
;
void
SendRtcpPacket
(
RTC
::
RTCP
::
Packet
*
packet
)
override
;
void
SendRtcpPacket
(
RTC
::
RTCP
::
Packet
*
packet
)
override
;
...
@@ -45,6 +47,8 @@ namespace RTC
...
@@ -45,6 +47,8 @@ namespace RTC
// Allocated by this.
// Allocated by this.
RTC
::
UdpSocket
*
udpSocket
{
nullptr
};
RTC
::
UdpSocket
*
udpSocket
{
nullptr
};
RTC
::
TransportTuple
*
tuple
{
nullptr
};
RTC
::
TransportTuple
*
tuple
{
nullptr
};
RTC
::
SrtpSession
*
srtpRecvSession
{
nullptr
};
RTC
::
SrtpSession
*
srtpSendSession
{
nullptr
};
// Others.
// Others.
ListenIp
listenIp
;
ListenIp
listenIp
;
bool
rtx
{
false
};
bool
rtx
{
false
};
...
...
worker/src/RTC/PipeTransport.cpp
浏览文件 @
6938a76d
...
@@ -5,12 +5,15 @@
...
@@ -5,12 +5,15 @@
#include "Logger.hpp"
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "Utils.hpp"
#include <cstring> // std::memcpy()
namespace
RTC
namespace
RTC
{
{
/* Static. */
/* Static. */
// If SRTP is enabled we mandate AES_CM_128_HMAC_SHA1_80.
// AES-HMAC: http://tools.ietf.org/html/rfc3711
// AES-HMAC: http://tools.ietf.org/html/rfc3711
static
RTC
::
SrtpSession
::
Profile
SrtpProfile
{
RTC
::
SrtpSession
::
Profile
::
AES_CM_128_HMAC_SHA1_80
};
static
constexpr
size_t
SrtpMasterLength
{
30
};
static
constexpr
size_t
SrtpMasterLength
{
30
};
/* Instance methods. */
/* Instance methods. */
...
@@ -93,6 +96,12 @@ namespace RTC
...
@@ -93,6 +96,12 @@ namespace RTC
delete
this
->
tuple
;
delete
this
->
tuple
;
this
->
tuple
=
nullptr
;
this
->
tuple
=
nullptr
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
}
}
void
PipeTransport
::
FillJson
(
json
&
jsonObject
)
const
void
PipeTransport
::
FillJson
(
json
&
jsonObject
)
const
...
@@ -106,7 +115,7 @@ namespace RTC
...
@@ -106,7 +115,7 @@ namespace RTC
jsonObject
[
"rtx"
]
=
this
->
rtx
;
jsonObject
[
"rtx"
]
=
this
->
rtx
;
// Add srtpKey.
// Add srtpKey.
if
(
!
this
->
srtpKey
.
empty
())
if
(
HasSrtp
())
jsonObject
[
"srtpKey"
]
=
this
->
srtpKey
;
jsonObject
[
"srtpKey"
]
=
this
->
srtpKey
;
// Add tuple.
// Add tuple.
...
@@ -203,13 +212,13 @@ namespace RTC
...
@@ -203,13 +212,13 @@ namespace RTC
auto
jsonSrtpKeyIt
=
request
->
data
.
find
(
"srtpKey"
);
auto
jsonSrtpKeyIt
=
request
->
data
.
find
(
"srtpKey"
);
if
(
this
->
srtpKey
.
empty
()
&&
jsonSrtpKeyIt
!=
request
->
data
.
end
())
if
(
!
HasSrtp
()
&&
jsonSrtpKeyIt
!=
request
->
data
.
end
())
{
{
MS_THROW_TYPE_ERROR
(
"invalid srtpKey (SRTP not enabled locally)"
);
MS_THROW_TYPE_ERROR
(
"invalid srtpKey (SRTP not enabled locally)"
);
}
}
// clang-format off
// clang-format off
else
if
(
else
if
(
!
this
->
srtpKey
.
empty
()
&&
HasSrtp
()
&&
(
jsonSrtpKeyIt
==
request
->
data
.
end
()
||
!
jsonSrtpKeyIt
->
is_string
())
(
jsonSrtpKeyIt
==
request
->
data
.
end
()
||
!
jsonSrtpKeyIt
->
is_string
())
)
)
// clang-format on
// clang-format on
...
@@ -217,12 +226,47 @@ namespace RTC
...
@@ -217,12 +226,47 @@ namespace RTC
MS_THROW_TYPE_ERROR
(
"missing srtpKey (SRTP enabled locally)"
);
MS_THROW_TYPE_ERROR
(
"missing srtpKey (SRTP enabled locally)"
);
}
}
if
(
!
this
->
srtpKey
.
empty
())
if
(
HasSrtp
())
{
{
auto
remoteS
rtpKey
=
jsonSrtpKeyIt
->
get
<
std
::
string
>
();
auto
s
rtpKey
=
jsonSrtpKeyIt
->
get
<
std
::
string
>
();
if
(
remoteS
rtpKey
.
size
()
!=
SrtpMasterLength
)
if
(
s
rtpKey
.
size
()
!=
SrtpMasterLength
)
MS_THROW_TYPE_ERROR
(
"invalid srtpKey length"
);
MS_THROW_TYPE_ERROR
(
"invalid srtpKey length"
);
auto
*
srtpLocalKey
=
new
uint8_t
[
SrtpMasterLength
];
auto
*
srtpRemoteKey
=
new
uint8_t
[
SrtpMasterLength
];
std
::
memcpy
(
srtpLocalKey
,
this
->
srtpKey
.
c_str
(),
SrtpMasterLength
);
std
::
memcpy
(
srtpRemoteKey
,
srtpKey
.
c_str
(),
SrtpMasterLength
);
try
{
this
->
srtpSendSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
SrtpProfile
,
srtpLocalKey
,
SrtpMasterLength
);
}
catch
(
const
MediaSoupError
&
error
)
{
delete
[]
srtpLocalKey
;
delete
[]
srtpRemoteKey
;
MS_THROW_ERROR
(
"error creating SRTP sending session: %s"
,
error
.
what
());
}
try
{
this
->
srtpRecvSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
INBOUND
,
SrtpProfile
,
srtpRemoteKey
,
SrtpMasterLength
);
}
catch
(
const
MediaSoupError
&
error
)
{
delete
[]
srtpLocalKey
;
delete
[]
srtpRemoteKey
;
MS_THROW_ERROR
(
"error creating SRTP receiving session: %s"
,
error
.
what
());
}
delete
[]
srtpLocalKey
;
delete
[]
srtpRemoteKey
;
}
}
int
err
;
int
err
;
...
@@ -270,11 +314,14 @@ namespace RTC
...
@@ -270,11 +314,14 @@ namespace RTC
}
}
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
if
(
this
->
tuple
!=
nullptr
)
delete
this
->
srtpSendSession
;
{
this
->
srtpSendSession
=
nullptr
;
delete
this
->
tuple
;
this
->
tuple
=
nullptr
;
delete
this
->
srtpRecvSession
;
}
this
->
srtpRecvSession
=
nullptr
;
delete
this
->
tuple
;
this
->
tuple
=
nullptr
;
throw
;
throw
;
}
}
...
@@ -301,6 +348,11 @@ namespace RTC
...
@@ -301,6 +348,11 @@ namespace RTC
}
}
}
}
inline
bool
PipeTransport
::
HasSrtp
()
const
{
return
!
this
->
srtpKey
.
empty
();
}
inline
bool
PipeTransport
::
IsConnected
()
const
inline
bool
PipeTransport
::
IsConnected
()
const
{
{
return
this
->
tuple
!=
nullptr
;
return
this
->
tuple
!=
nullptr
;
...
@@ -325,6 +377,18 @@ namespace RTC
...
@@ -325,6 +377,18 @@ namespace RTC
const
uint8_t
*
data
=
packet
->
GetData
();
const
uint8_t
*
data
=
packet
->
GetData
();
size_t
len
=
packet
->
GetSize
();
size_t
len
=
packet
->
GetSize
();
if
(
HasSrtp
()
&&
!
this
->
srtpSendSession
->
EncryptRtp
(
&
data
,
&
len
))
{
if
(
cb
)
{
(
*
cb
)(
false
);
delete
cb
;
}
return
;
}
this
->
tuple
->
Send
(
data
,
len
,
cb
);
this
->
tuple
->
Send
(
data
,
len
,
cb
);
// Increase send transmission.
// Increase send transmission.
...
@@ -341,6 +405,9 @@ namespace RTC
...
@@ -341,6 +405,9 @@ namespace RTC
const
uint8_t
*
data
=
packet
->
GetData
();
const
uint8_t
*
data
=
packet
->
GetData
();
size_t
len
=
packet
->
GetSize
();
size_t
len
=
packet
->
GetSize
();
if
(
HasSrtp
()
&&
!
this
->
srtpSendSession
->
EncryptRtcp
(
&
data
,
&
len
))
return
;
this
->
tuple
->
Send
(
data
,
len
);
this
->
tuple
->
Send
(
data
,
len
);
// Increase send transmission.
// Increase send transmission.
...
@@ -357,6 +424,9 @@ namespace RTC
...
@@ -357,6 +424,9 @@ namespace RTC
const
uint8_t
*
data
=
packet
->
GetData
();
const
uint8_t
*
data
=
packet
->
GetData
();
size_t
len
=
packet
->
GetSize
();
size_t
len
=
packet
->
GetSize
();
if
(
HasSrtp
()
&&
!
this
->
srtpSendSession
->
EncryptRtcp
(
&
data
,
&
len
))
return
;
this
->
tuple
->
Send
(
data
,
len
);
this
->
tuple
->
Send
(
data
,
len
);
// Increase send transmission.
// Increase send transmission.
...
@@ -419,6 +489,30 @@ namespace RTC
...
@@ -419,6 +489,30 @@ namespace RTC
return
;
return
;
}
}
// Decrypt the SRTP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
{
RTC
::
RtpPacket
*
packet
=
RTC
::
RtpPacket
::
Parse
(
data
,
len
);
if
(
!
packet
)
{
MS_WARN_TAG
(
srtp
,
"DecryptSrtp() failed due to an invalid RTP packet"
);
}
else
{
MS_WARN_TAG
(
srtp
,
"DecryptSrtp() failed [ssrc:%"
PRIu32
", payloadType:%"
PRIu8
", seq:%"
PRIu16
"]"
,
packet
->
GetSsrc
(),
packet
->
GetPayloadType
(),
packet
->
GetSequenceNumber
());
delete
packet
;
}
return
;
}
RTC
::
RtpPacket
*
packet
=
RTC
::
RtpPacket
::
Parse
(
data
,
len
);
RTC
::
RtpPacket
*
packet
=
RTC
::
RtpPacket
::
Parse
(
data
,
len
);
if
(
packet
==
nullptr
)
if
(
packet
==
nullptr
)
...
@@ -448,6 +542,10 @@ namespace RTC
...
@@ -448,6 +542,10 @@ namespace RTC
return
;
return
;
}
}
// Decrypt the SRTCP packet.
if
(
HasSrtp
()
&&
!
this
->
srtpRecvSession
->
DecryptSrtcp
(
const_cast
<
uint8_t
*>
(
data
),
&
len
))
return
;
RTC
::
RTCP
::
Packet
*
packet
=
RTC
::
RTCP
::
Packet
::
Parse
(
data
,
len
);
RTC
::
RTCP
::
Packet
*
packet
=
RTC
::
RTCP
::
Packet
::
Parse
(
data
,
len
);
if
(
packet
==
nullptr
)
if
(
packet
==
nullptr
)
...
...
worker/src/RTC/PlainRtpTransport.cpp
浏览文件 @
6938a76d
...
@@ -384,17 +384,11 @@ namespace RTC
...
@@ -384,17 +384,11 @@ namespace RTC
}
}
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
if
(
this
->
tuple
!=
nullptr
)
delete
this
->
tuple
;
{
this
->
tuple
=
nullptr
;
delete
this
->
tuple
;
this
->
tuple
=
nullptr
;
}
if
(
this
->
rtcpTuple
!=
nullptr
)
delete
this
->
rtcpTuple
;
{
this
->
rtcpTuple
=
nullptr
;
delete
this
->
rtcpTuple
;
this
->
rtcpTuple
=
nullptr
;
}
throw
;
throw
;
}
}
...
...
worker/src/RTC/WebRtcTransport.cpp
浏览文件 @
6938a76d
...
@@ -247,11 +247,11 @@ namespace RTC
...
@@ -247,11 +247,11 @@ namespace RTC
this
->
iceCandidates
.
clear
();
this
->
iceCandidates
.
clear
();
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
delete
this
->
srtpSendSession
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
}
}
void
WebRtcTransport
::
FillJson
(
json
&
jsonObject
)
const
void
WebRtcTransport
::
FillJson
(
json
&
jsonObject
)
const
...
@@ -1205,16 +1205,11 @@ namespace RTC
...
@@ -1205,16 +1205,11 @@ namespace RTC
MS_DEBUG_TAG
(
dtls
,
"DTLS connected"
);
MS_DEBUG_TAG
(
dtls
,
"DTLS connected"
);
// Close it if it was already set and update it.
// Close it if it was already set and update it.
if
(
this
->
srtpSendSession
)
delete
this
->
srtpSendSession
;
{
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpRecvSession
;
}
this
->
srtpRecvSession
=
nullptr
;
if
(
this
->
srtpRecvSession
)
{
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
}
try
try
{
{
...
@@ -1230,6 +1225,17 @@ namespace RTC
...
@@ -1230,6 +1225,17 @@ namespace RTC
{
{
this
->
srtpRecvSession
=
new
RTC
::
SrtpSession
(
this
->
srtpRecvSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
INBOUND
,
srtpProfile
,
srtpRemoteKey
,
srtpRemoteKeyLen
);
RTC
::
SrtpSession
::
Type
::
INBOUND
,
srtpProfile
,
srtpRemoteKey
,
srtpRemoteKeyLen
);
// Notify the Node WebRtcTransport.
json
data
=
json
::
object
();
data
[
"dtlsState"
]
=
"connected"
;
data
[
"dtlsRemoteCert"
]
=
remoteCert
;
Channel
::
Notifier
::
Emit
(
this
->
id
,
"dtlsstatechange"
,
data
);
// Tell the parent class.
RTC
::
Transport
::
Connected
();
}
}
catch
(
const
MediaSoupError
&
error
)
catch
(
const
MediaSoupError
&
error
)
{
{
...
@@ -1238,17 +1244,6 @@ namespace RTC
...
@@ -1238,17 +1244,6 @@ namespace RTC
delete
this
->
srtpSendSession
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
this
->
srtpSendSession
=
nullptr
;
}
}
// Notify the Node WebRtcTransport.
json
data
=
json
::
object
();
data
[
"dtlsState"
]
=
"connected"
;
data
[
"dtlsRemoteCert"
]
=
remoteCert
;
Channel
::
Notifier
::
Emit
(
this
->
id
,
"dtlsstatechange"
,
data
);
// Tell the parent class.
RTC
::
Transport
::
Connected
();
}
}
inline
void
WebRtcTransport
::
OnDtlsTransportFailed
(
const
RTC
::
DtlsTransport
*
/*dtlsTransport*/
)
inline
void
WebRtcTransport
::
OnDtlsTransportFailed
(
const
RTC
::
DtlsTransport
*
/*dtlsTransport*/
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论