Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
M
mediasoup
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
聂卓夫
mediasoup
Commits
5dd9a605
提交
5dd9a605
authored
2月 29, 2020
作者:
Iñaki Baz Castillo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Working on SRTP for PlainRtpTransport
上级
68fa78ca
隐藏空白字符变更
内嵌
并排
正在显示
21 个修改的文件
包含
557 行增加
和
174 行删除
+557
-174
PipeTransport.d.ts
lib/PipeTransport.d.ts
+1
-1
PlainRtpTransport.d.ts
lib/PlainRtpTransport.d.ts
+17
-1
PlainRtpTransport.d.ts.map
lib/PlainRtpTransport.d.ts.map
+2
-2
PlainRtpTransport.js
lib/PlainRtpTransport.js
+14
-3
Router.d.ts
lib/Router.d.ts
+1
-1
Router.d.ts.map
lib/Router.d.ts.map
+2
-2
Router.js
lib/Router.js
+4
-2
PipeTransport.ts
src/PipeTransport.ts
+1
-1
PlainRtpTransport.ts
src/PlainRtpTransport.ts
+31
-3
Router.ts
src/Router.ts
+5
-1
test-PlainRtpTransport.js
test/test-PlainRtpTransport.js
+135
-0
DtlsTransport.hpp
worker/include/RTC/DtlsTransport.hpp
+6
-6
PipeTransport.hpp
worker/include/RTC/PipeTransport.hpp
+7
-3
PlainRtpTransport.hpp
worker/include/RTC/PlainRtpTransport.hpp
+15
-0
SrtpSession.hpp
worker/include/RTC/SrtpSession.hpp
+2
-2
WebRtcTransport.hpp
worker/include/RTC/WebRtcTransport.hpp
+1
-1
DtlsTransport.cpp
worker/src/RTC/DtlsTransport.cpp
+46
-42
PipeTransport.cpp
worker/src/RTC/PipeTransport.cpp
+48
-39
PlainRtpTransport.cpp
worker/src/RTC/PlainRtpTransport.cpp
+209
-0
SrtpSession.cpp
worker/src/RTC/SrtpSession.cpp
+7
-7
WebRtcTransport.cpp
worker/src/RTC/WebRtcTransport.cpp
+3
-57
没有找到文件。
lib/PipeTransport.d.ts
浏览文件 @
5dd9a605
...
...
@@ -30,7 +30,7 @@ export declare type PipeTransportOptions = {
/**
* Enable SRTP. Useful to protect the RTP and RTCP traffic if both Routers
* are located in different hosts. For this to work, connect() must be called
* with remote SRTP parameters. Defau
i
t false.
* with remote SRTP parameters. Defau
l
t false.
*/
enableSrtp
?:
boolean
;
/**
...
...
lib/PlainRtpTransport.d.ts
浏览文件 @
5dd9a605
...
...
@@ -2,6 +2,7 @@ import { EnhancedEventEmitter } from './EnhancedEventEmitter';
import
{
Transport
,
TransportListenIp
,
TransportTuple
,
SctpState
}
from
'./Transport'
;
import
{
Consumer
,
ConsumerOptions
}
from
'./Consumer'
;
import
{
SctpParameters
,
NumSctpStreams
}
from
'./SctpParameters'
;
import
{
SrtpParameters
,
SrtpCryptoSuite
}
from
'./SrtpParameters'
;
export
declare
type
PlainRtpTransportOptions
=
{
/**
* Listening IP address.
...
...
@@ -36,6 +37,16 @@ export declare type PlainRtpTransportOptions = {
* Default 262144.
*/
maxSctpMessageSize
?:
number
;
/**
* Enable SRTP. For this to work, connect() must be called
* with remote SRTP parameters. Default false.
*/
enableSrtp
?:
boolean
;
/**
* The SRTP crypto suite to be used if enableSrtp is set. Default
* 'AES_CM_128_HMAC_SHA1_80'.
*/
srtpCryptoSuite
?:
SrtpCryptoSuite
;
/**
* Custom application data.
*/
...
...
@@ -94,6 +105,10 @@ export declare class PlainRtpTransport extends Transport {
* SCTP state.
*/
get
sctpState
():
SctpState
;
/**
* SRTP parameters.
*/
get
srtpParameters
():
SrtpParameters
|
undefined
;
/**
* Observer.
*
...
...
@@ -131,10 +146,11 @@ export declare class PlainRtpTransport extends Transport {
*
* @override
*/
connect
({
ip
,
port
,
rtcpPort
}:
{
connect
({
ip
,
port
,
rtcpPort
,
srtpParameters
}:
{
ip
:
string
;
port
:
number
;
rtcpPort
?:
number
;
srtpParameters
?:
SrtpParameters
;
}):
Promise
<
void
>
;
/**
* Override Transport.consume() method to reject it if multiSource is set.
...
...
lib/PlainRtpTransport.d.ts.map
浏览文件 @
5dd9a605
{"version":3,"file":"PlainRtpTransport.d.ts","sourceRoot":"","sources":["../src/PlainRtpTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,cAAc,EAEd,SAAS,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElE,oBAAY,wBAAwB,GACpC;IACC;;OAEG;IACH,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;CACd,CAAA;AAED,oBAAY,qBAAqB,GACjC;IAEC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAA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E,EACF,IAAI,EACJ,QAAQ,EACR,EACD;QACC,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB,GACC,OAAO,CAAC,IAAI,CAAC;IAchB;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQzD,OAAO,CAAC,0BAA0B;CAuClC"}
\ No newline at end of file
{"version":3,"file":"PlainRtpTransport.d.ts","sourceRoot":"","sources":["../src/PlainRtpTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EACN,SAAS,EACT,iBAAiB,EACjB,cAAc,EAEd,SAAS,EACT,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnE,oBAAY,wBAAwB,GACpC;IACC;;OAEG;IACH,QAAQ,EAAE,iBAAiB,GAAG,MAAM,CAAC;IAErC;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;OAEG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;;OAGG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;IAElC;;OAEG;IACH,OAAO,CAAC,EAAE,GAAG,CAAC;C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IAED;;OAEG;IACH,IAAI,cAAc,IAAI,cAAc,GAAG,SAAS,CAG/C;IAED;;;;;;;;;;;OAWG;IACH,IAAI,QAAQ,IAAI,oBAAoB,CAGnC;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI;IAWb;;;;;OAKG;IACH,YAAY,IAAI,IAAI;IAWpB;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAOlD;;;;OAIG;IACG,OAAO,CACZ,EACC,EAAE,EACF,IAAI,EACJ,QAAQ,EACR,cAAc,EACd,EACD;QACC,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,cAAc,CAAC,EAAE,cAAc,CAAC;KAChC,GACC,OAAO,CAAC,IAAI,CAAC;IAehB;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAQzD,OAAO,CAAC,0BAA0B;CAuClC"}
\ No newline at end of file
lib/PlainRtpTransport.js
浏览文件 @
5dd9a605
...
...
@@ -26,6 +26,9 @@ class PlainRtpTransport extends Transport_1.Transport {
// - .MIS
// - .maxMessageSize
// - .sctpState
// - .srtpParameters
// - .cryptoSuite
// - .keyBase64
/**
* @private
* @emits sctpstatechange - (sctpState: SctpState)
...
...
@@ -40,7 +43,8 @@ class PlainRtpTransport extends Transport_1.Transport {
tuple
:
data
.
tuple
,
rtcpTuple
:
data
.
rtcpTuple
,
sctpParameters
:
data
.
sctpParameters
,
sctpState
:
data
.
sctpState
sctpState
:
data
.
sctpState
,
srtpParameters
:
data
.
srtpParameters
};
this
.
_handleWorkerNotifications
();
}
...
...
@@ -68,6 +72,12 @@ class PlainRtpTransport extends Transport_1.Transport {
get
sctpState
()
{
return
this
.
_data
.
sctpState
;
}
/**
* SRTP parameters.
*/
get
srtpParameters
()
{
return
this
.
_data
.
srtpParameters
;
}
/**
* Observer.
*
...
...
@@ -122,13 +132,14 @@ class PlainRtpTransport extends Transport_1.Transport {
*
* @override
*/
async
connect
({
ip
,
port
,
rtcpPort
})
{
async
connect
({
ip
,
port
,
rtcpPort
,
srtpParameters
})
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
,
rtcpPort
};
const
reqData
=
{
ip
,
port
,
rtcpPort
,
srtpParameters
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
this
.
_data
.
srtpParameters
=
data
.
srtpParameters
;
}
/**
* Override Transport.consume() method to reject it if multiSource is set.
...
...
lib/Router.d.ts
浏览文件 @
5dd9a605
...
...
@@ -138,7 +138,7 @@ export declare class Router extends EnhancedEventEmitter {
/**
* Create a PlainRtpTransport.
*/
createPlainRtpTransport
({
listenIp
,
rtcpMux
,
comedia
,
multiSource
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
appData
}:
PlainRtpTransportOptions
):
Promise
<
PlainRtpTransport
>
;
createPlainRtpTransport
({
listenIp
,
rtcpMux
,
comedia
,
multiSource
,
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
enableSrtp
,
srtpCryptoSuite
,
appData
}:
PlainRtpTransportOptions
):
Promise
<
PlainRtpTransport
>
;
/**
* Create a PipeTransport.
*/
...
...
lib/Router.d.ts.map
浏览文件 @
5dd9a605
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAa,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,wBAAw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AS,EACT,SAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,SAAiB,EACjB,+BAAwC,EACxC,UAAkB,EAClB,cAAwC,EACxC,kBAA2B,EAC3B,OAAY,EACZ,EAAE,sBAAsB,GACvB,OAAO,CAAC,eAAe,CAAC;IA6E3B;;OAEG;IACG,uBAAuB,CAC5B,EACC,QAAQ,EACR,OAAc,EACd,OAAe,EACf,WAAmB,EACnB,UAAkB,EAClB,cAAwC,EACxC,kBAA2B,EAC3B,OAAY,EACZ,EAAE,wBAAwB,GACzB,OAAO,CAAC,iBAAiB,CAAC;IAyE7B;;OAEG;IACG,mBAAmB,CACxB,EACC,QAAQ,EACR,UAAkB,EAClB,cAAwC,EACxC,kBAA+B,EAC/B,SAAiB,EACjB,UAAkB,EAClB,OAAY,EACZ,EAAE,oBAAoB,GACrB,OAAO,CAAC,aAAa,CAAC;IAwEzB;;OAEG;IACG,YAAY,CACjB,EACC,UAAU,EACV,cAAc,EACd,MAAM,EACN,QAAsB,EACtB,UAAiB,EACjB,cAAwC,EACxC,EAAE,mBAAmB,GACpB,OAAO,CAAC,kBAAkB,CAAC;IAwM9B;;OAEG;IACG,wBAAwB,CAC7B,EACC,UAAc,EACd,SAAe,EACf,QAAe,EACf,OAAY,EACZ,GAAE,yBAA8B,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAkC9B;;OAEG;IACH,UAAU,CACT,EACC,UAAU,EACV,eAAe,EACf,EACD;QACC,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,eAAe,CAAC;KACjC,GACC,OAAO;CAuBV"}
\ No newline at end of file
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../src/Router.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAa,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,eAAe,E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,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;IAO1B;;OAEG;IACG,qBAAqB,CAC1B,EACC,SAAS,EACT,SAAgB,EAChB,SAAiB,EACjB,SAAiB,EACjB,SAAiB,EACjB,+BAAwC,EACxC,UAAkB,EAClB,cAAwC,EACxC,kBAA2B,EAC3B,OAAY,EACZ,EAAE,sBAAsB,GACvB,OAAO,CAAC,eAAe,CAAC;IA6E3B;;OAEG;IACG,uBAAuB,CAC5B,EACC,QAAQ,EACR,OAAc,EACd,OAAe,EACf,WAAmB,EACnB,UAAkB,EAClB,cAAwC,EACxC,kBAA2B,EAC3B,UAAkB,EAClB,eAA2C,EAC3C,OAAY,EACZ,EAAE,wBAAwB,GACzB,OAAO,CAAC,iBAAiB,CAAC;IA2E7B;;OAEG;IACG,mBAAmB,CACxB,EACC,QAAQ,EACR,UAAkB,EAClB,cAAwC,EACxC,kBAA+B,EAC/B,SAAiB,EACjB,UAAkB,EAClB,OAAY,EACZ,EAAE,oBAAoB,GACrB,OAAO,CAAC,aAAa,CAAC;IAwEzB;;OAEG;IACG,YAAY,CACjB,EACC,UAAU,EACV,cAAc,EACd,MAAM,EACN,QAAsB,EACtB,UAAiB,EACjB,cAAwC,EACxC,EAAE,mBAAmB,GACpB,OAAO,CAAC,kBAAkB,CAAC;IAwM9B;;OAEG;IACG,wBAAwB,CAC7B,EACC,UAAc,EACd,SAAe,EACf,QAAe,EACf,OAAY,EACZ,GAAE,yBAA8B,GAC/B,OAAO,CAAC,kBAAkB,CAAC;IAkC9B;;OAEG;IACH,UAAU,CACT,EACC,UAAU,EACV,eAAe,EACf,EACD;QACC,UAAU,EAAE,MAAM,CAAC;QACnB,eAAe,EAAE,eAAe,CAAC;KACjC,GACC,OAAO;CAuBV"}
\ No newline at end of file
lib/Router.js
浏览文件 @
5dd9a605
...
...
@@ -216,7 +216,7 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
/**
* Create a PlainRtpTransport.
*/
async
createPlainRtpTransport
({
listenIp
,
rtcpMux
=
true
,
comedia
=
false
,
multiSource
=
false
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
appData
=
{}
})
{
async
createPlainRtpTransport
({
listenIp
,
rtcpMux
=
true
,
comedia
=
false
,
multiSource
=
false
,
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
enableSrtp
=
false
,
srtpCryptoSuite
=
'AES_CM_128_HMAC_SHA1_80'
,
appData
=
{}
})
{
logger
.
debug
(
'createPlainRtpTransport()'
);
if
(
!
listenIp
)
throw
new
TypeError
(
'missing listenIp'
);
...
...
@@ -244,7 +244,9 @@ class Router extends EnhancedEventEmitter_1.EnhancedEventEmitter {
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
false
isDataChannel
:
false
,
enableSrtp
,
srtpCryptoSuite
};
const
data
=
await
this
.
_channel
.
request
(
'router.createPlainRtpTransport'
,
internal
,
reqData
);
const
transport
=
new
PlainRtpTransport_1
.
PlainRtpTransport
({
...
...
src/PipeTransport.ts
浏览文件 @
5dd9a605
...
...
@@ -46,7 +46,7 @@ export type PipeTransportOptions =
/**
* Enable SRTP. Useful to protect the RTP and RTCP traffic if both Routers
* are located in different hosts. For this to work, connect() must be called
* with remote SRTP parameters. Defau
i
t false.
* with remote SRTP parameters. Defau
l
t false.
*/
enableSrtp
?:
boolean
;
...
...
src/PlainRtpTransport.ts
浏览文件 @
5dd9a605
...
...
@@ -9,6 +9,7 @@ import {
}
from
'./Transport'
;
import
{
Consumer
,
ConsumerOptions
}
from
'./Consumer'
;
import
{
SctpParameters
,
NumSctpStreams
}
from
'./SctpParameters'
;
import
{
SrtpParameters
,
SrtpCryptoSuite
}
from
'./SrtpParameters'
;
export
type
PlainRtpTransportOptions
=
{
...
...
@@ -52,6 +53,18 @@ export type PlainRtpTransportOptions =
*/
maxSctpMessageSize
?:
number
;
/**
* Enable SRTP. For this to work, connect() must be called
* with remote SRTP parameters. Default false.
*/
enableSrtp
?:
boolean
;
/**
* The SRTP crypto suite to be used if enableSrtp is set. Default
* 'AES_CM_128_HMAC_SHA1_80'.
*/
srtpCryptoSuite
?:
SrtpCryptoSuite
;
/**
* Custom application data.
*/
...
...
@@ -119,6 +132,9 @@ export class PlainRtpTransport extends Transport
// - .MIS
// - .maxMessageSize
// - .sctpState
// - .srtpParameters
// - .cryptoSuite
// - .keyBase64
/**
* @private
...
...
@@ -138,7 +154,8 @@ export class PlainRtpTransport extends Transport
tuple
:
data
.
tuple
,
rtcpTuple
:
data
.
rtcpTuple
,
sctpParameters
:
data
.
sctpParameters
,
sctpState
:
data
.
sctpState
sctpState
:
data
.
sctpState
,
srtpParameters
:
data
.
srtpParameters
};
this
.
_handleWorkerNotifications
();
...
...
@@ -176,6 +193,14 @@ export class PlainRtpTransport extends Transport
return
this
.
_data
.
sctpState
;
}
/**
* SRTP parameters.
*/
get
srtpParameters
():
SrtpParameters
|
undefined
{
return
this
.
_data
.
srtpParameters
;
}
/**
* Observer.
*
...
...
@@ -247,18 +272,20 @@ export class PlainRtpTransport extends Transport
{
ip
,
port
,
rtcpPort
rtcpPort
,
srtpParameters
}:
{
ip
:
string
;
port
:
number
;
rtcpPort
?:
number
;
srtpParameters
?:
SrtpParameters
;
}
):
Promise
<
void
>
{
logger
.
debug
(
'connect()'
);
const
reqData
=
{
ip
,
port
,
rtcpPort
};
const
reqData
=
{
ip
,
port
,
rtcpPort
,
srtpParameters
};
const
data
=
await
this
.
_channel
.
request
(
'transport.connect'
,
this
.
_internal
,
reqData
);
...
...
@@ -266,6 +293,7 @@ export class PlainRtpTransport extends Transport
// Update data.
this
.
_data
.
tuple
=
data
.
tuple
;
this
.
_data
.
rtcpTuple
=
data
.
rtcpTuple
;
this
.
_data
.
srtpParameters
=
data
.
srtpParameters
;
}
/**
...
...
src/Router.ts
浏览文件 @
5dd9a605
...
...
@@ -417,6 +417,8 @@ export class Router extends EnhancedEventEmitter
enableSctp
=
false
,
numSctpStreams
=
{
OS
:
1024
,
MIS
:
1024
},
maxSctpMessageSize
=
262144
,
enableSrtp
=
false
,
srtpCryptoSuite
=
'AES_CM_128_HMAC_SHA1_80'
,
appData
=
{}
}:
PlainRtpTransportOptions
):
Promise
<
PlainRtpTransport
>
...
...
@@ -454,7 +456,9 @@ export class Router extends EnhancedEventEmitter
enableSctp
,
numSctpStreams
,
maxSctpMessageSize
,
isDataChannel
:
false
isDataChannel
:
false
,
enableSrtp
,
srtpCryptoSuite
};
const
data
=
...
...
test/test-PlainRtpTransport.js
浏览文件 @
5dd9a605
...
...
@@ -98,6 +98,7 @@ test('router.createPlainRtpTransport() succeeds', async () =>
isDataChannel
:
false
});
expect
(
transport1
.
sctpState
).
toBe
(
'new'
);
expect
(
transport1
.
srtpParameters
).
toBeUndefined
();
const
data1
=
await
transport1
.
dump
();
...
...
@@ -169,6 +170,125 @@ test('router.createPlainRtpTransport() with wrong arguments rejects with TypeErr
.
toThrow
(
TypeError
);
},
2000
);
test
(
'router.createPlainRtpTransport() with enableSrtp succeeds'
,
async
()
=>
{
const
transport1
=
await
router
.
createPlainRtpTransport
(
{
listenIp
:
'127.0.0.1'
,
enableSrtp
:
true
});
expect
(
transport1
.
id
).
toBeType
(
'string'
);
expect
(
transport1
.
srtpParameters
).
toBeType
(
'object'
);
expect
(
transport1
.
srtpParameters
.
cryptoSuite
).
toBe
(
'AES_CM_128_HMAC_SHA1_80'
);
expect
(
transport1
.
srtpParameters
.
keyBase64
.
length
).
toBe
(
40
);
// Missing srtpParameters.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
}))
.
rejects
.
toThrow
(
TypeError
);
// Invalid srtpParameters.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
1
}))
.
rejects
.
toThrow
(
TypeError
);
// Missing srtpParameters.cryptoSuite.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
{
keyBase64
:
'ZnQ3eWJraDg0d3ZoYzM5cXN1Y2pnaHU5NWxrZTVv'
}
}))
.
rejects
.
toThrow
(
TypeError
);
// Missing srtpParameters.keyBase64.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
{
cryptoSuite
:
'AES_CM_128_HMAC_SHA1_80'
}
}))
.
rejects
.
toThrow
(
TypeError
);
// Invalid srtpParameters.cryptoSuite.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
{
cryptoSuite
:
'FOO'
,
keyBase64
:
'ZnQ3eWJraDg0d3ZoYzM5cXN1Y2pnaHU5NWxrZTVv'
}
}))
.
rejects
.
toThrow
(
TypeError
);
// Invalid srtpParameters.cryptoSuite.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
{
cryptoSuite
:
123
,
keyBase64
:
'ZnQ3eWJraDg0d3ZoYzM5cXN1Y2pnaHU5NWxrZTVv'
}
}))
.
rejects
.
toThrow
(
TypeError
);
// Invalid srtpParameters.keyBase64.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
{
cryptoSuite
:
'AES_CM_128_HMAC_SHA1_80'
,
keyBase64
:
[]
}
}))
.
rejects
.
toThrow
(
TypeError
);
// Valid srtpParameters. And let's update the crypto suite.
await
expect
(
transport1
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9999
,
srtpParameters
:
{
cryptoSuite
:
'AES_CM_128_HMAC_SHA1_32'
,
keyBase64
:
'ZnQ3eWJraDg0d3ZoYzM5cXN1Y2pnaHU5NWxrZTVv'
}
}))
.
resolves
.
toBeUndefined
();
expect
(
transport1
.
srtpParameters
.
cryptoSuite
).
toBe
(
'AES_CM_128_HMAC_SHA1_32'
);
transport1
.
close
();
},
2000
);
test
(
'router.createPlainRtpTransport() with non bindable IP rejects with Error'
,
async
()
=>
{
await
expect
(
router
.
createPlainRtpTransport
({
listenIp
:
'8.8.8.8'
}))
...
...
@@ -210,6 +330,21 @@ test('plaintRtpTransport.getStats() succeeds', async () =>
test
(
'plaintRtpTransport.connect() succeeds'
,
async
()
=>
{
// No SRTP enabled so passing srtpParameters must fail.
await
expect
(
transport
.
connect
(
{
ip
:
'127.0.0.2'
,
port
:
9998
,
rtcpPort
:
9999
,
srtpParameters
:
{
cryptoSuite
:
'AES_CM_128_HMAC_SHA1_80'
,
keyBase64
:
'ZnQ3eWJraDg0d3ZoYzM5cXN1Y2pnaHU5NWxrZTVv'
}
}))
.
rejects
.
toThrow
(
TypeError
);
await
expect
(
transport
.
connect
({
ip
:
'1.2.3.4'
,
port
:
1234
,
rtcpPort
:
1235
}))
.
resolves
.
toBeUndefined
();
...
...
worker/include/RTC/DtlsTransport.hpp
浏览文件 @
5dd9a605
...
...
@@ -53,9 +53,9 @@ namespace RTC
};
private
:
struct
Srtp
Profil
eMapEntry
struct
Srtp
CryptoSuit
eMapEntry
{
RTC
::
SrtpSession
::
Profile
profil
e
;
RTC
::
SrtpSession
::
CryptoSuite
cryptoSuit
e
;
const
char
*
name
;
};
...
...
@@ -72,7 +72,7 @@ namespace RTC
// NOTE: The caller MUST NOT call any method during this callback.
virtual
void
OnDtlsTransportConnected
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
RTC
::
SrtpSession
::
Profile
srtpProfil
e
,
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuit
e
,
uint8_t
*
srtpLocalKey
,
size_t
srtpLocalKeyLen
,
uint8_t
*
srtpRemoteKey
,
...
...
@@ -114,7 +114,7 @@ namespace RTC
static
std
::
map
<
std
::
string
,
FingerprintAlgorithm
>
string2FingerprintAlgorithm
;
static
std
::
map
<
FingerprintAlgorithm
,
std
::
string
>
fingerprintAlgorithm2String
;
static
std
::
vector
<
Fingerprint
>
localFingerprints
;
static
std
::
vector
<
Srtp
ProfileMapEntry
>
srtpProfil
es
;
static
std
::
vector
<
Srtp
CryptoSuiteMapEntry
>
srtpCryptoSuit
es
;
public
:
explicit
DtlsTransport
(
Listener
*
listener
);
...
...
@@ -138,8 +138,8 @@ namespace RTC
bool
SetTimeout
();
bool
ProcessHandshake
();
bool
CheckRemoteFingerprint
();
void
ExtractSrtpKeys
(
RTC
::
SrtpSession
::
Profile
srtpProfil
e
);
RTC
::
SrtpSession
::
Profile
GetNegotiatedSrtpProfil
e
();
void
ExtractSrtpKeys
(
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuit
e
);
RTC
::
SrtpSession
::
CryptoSuite
GetNegotiatedSrtpCryptoSuit
e
();
/* Callbacks fired by OpenSSL events. */
public
:
...
...
worker/include/RTC/PipeTransport.hpp
浏览文件 @
5dd9a605
...
...
@@ -17,6 +17,11 @@ namespace RTC
std
::
string
announcedIp
;
};
private
:
static
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuite
;
static
std
::
string
srtpCryptoSuiteString
;
static
size_t
srtpMasterLength
;
public
:
PipeTransport
(
const
std
::
string
&
id
,
RTC
::
Transport
::
Listener
*
listener
,
json
&
data
);
~
PipeTransport
()
override
;
...
...
@@ -27,8 +32,8 @@ namespace RTC
void
HandleRequest
(
Channel
::
Request
*
request
)
override
;
private
:
bool
HasSrtp
()
const
;
bool
IsConnected
()
const
override
;
bool
HasSrtp
()
const
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
=
nullptr
)
override
;
void
SendRtcpPacket
(
RTC
::
RTCP
::
Packet
*
packet
)
override
;
void
SendRtcpCompoundPacket
(
RTC
::
RTCP
::
CompoundPacket
*
packet
)
override
;
...
...
@@ -51,11 +56,10 @@ namespace RTC
RTC
::
SrtpSession
*
srtpSendSession
{
nullptr
};
// Others.
ListenIp
listenIp
;
struct
sockaddr_storage
remoteAddrStorage
;
bool
rtx
{
false
};
std
::
string
srtpCryptoSuite
;
std
::
string
srtpKey
;
std
::
string
srtpKeyBase64
;
struct
sockaddr_storage
remoteAddrStorage
;
};
}
// namespace RTC
...
...
worker/include/RTC/PlainRtpTransport.hpp
浏览文件 @
5dd9a605
#ifndef MS_RTC_PLAIN_RTP_TRANSPORT_HPP
#define MS_RTC_PLAIN_RTP_TRANSPORT_HPP
#include "RTC/SrtpSession.hpp"
#include "RTC/Transport.hpp"
#include "RTC/TransportTuple.hpp"
#include "RTC/UdpSocket.hpp"
#include <map>
namespace
RTC
{
...
...
@@ -16,6 +18,11 @@ namespace RTC
std
::
string
announcedIp
;
};
private
:
static
std
::
map
<
std
::
string
,
RTC
::
SrtpSession
::
CryptoSuite
>
string2SrtpCryptoSuite
;
static
std
::
map
<
RTC
::
SrtpSession
::
CryptoSuite
,
std
::
string
>
srtpCryptoSuite2String
;
static
size_t
srtpMasterLength
;
public
:
PlainRtpTransport
(
const
std
::
string
&
id
,
RTC
::
Transport
::
Listener
*
listener
,
json
&
data
);
~
PlainRtpTransport
()
override
;
...
...
@@ -27,6 +34,7 @@ namespace RTC
private
:
bool
IsConnected
()
const
override
;
bool
HasSrtp
()
const
;
void
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
=
nullptr
)
override
;
void
SendRtcpPacket
(
RTC
::
RTCP
::
Packet
*
packet
)
override
;
void
SendRtcpCompoundPacket
(
RTC
::
RTCP
::
CompoundPacket
*
packet
)
override
;
...
...
@@ -47,6 +55,8 @@ namespace RTC
RTC
::
UdpSocket
*
rtcpUdpSocket
{
nullptr
};
RTC
::
TransportTuple
*
tuple
{
nullptr
};
RTC
::
TransportTuple
*
rtcpTuple
{
nullptr
};
RTC
::
SrtpSession
*
srtpRecvSession
{
nullptr
};
RTC
::
SrtpSession
*
srtpSendSession
{
nullptr
};
// Others.
ListenIp
listenIp
;
bool
rtcpMux
{
true
};
...
...
@@ -54,6 +64,11 @@ namespace RTC
bool
multiSource
{
false
};
struct
sockaddr_storage
remoteAddrStorage
;
struct
sockaddr_storage
rtcpRemoteAddrStorage
;
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuite
{
RTC
::
SrtpSession
::
CryptoSuite
::
AES_CM_128_HMAC_SHA1_80
};
std
::
string
srtpKey
;
std
::
string
srtpKeyBase64
;
};
}
// namespace RTC
...
...
worker/include/RTC/SrtpSession.hpp
浏览文件 @
5dd9a605
...
...
@@ -9,7 +9,7 @@ namespace RTC
class
SrtpSession
{
public
:
enum
class
Profil
e
enum
class
CryptoSuit
e
{
NONE
=
0
,
AES_CM_128_HMAC_SHA1_80
=
1
,
...
...
@@ -32,7 +32,7 @@ namespace RTC
static
void
OnSrtpEvent
(
srtp_event_data_t
*
data
);
public
:
SrtpSession
(
Type
type
,
Profile
profil
e
,
uint8_t
*
key
,
size_t
keyLen
);
SrtpSession
(
Type
type
,
CryptoSuite
cryptoSuit
e
,
uint8_t
*
key
,
size_t
keyLen
);
~
SrtpSession
();
public
:
...
...
worker/include/RTC/WebRtcTransport.hpp
浏览文件 @
5dd9a605
...
...
@@ -81,7 +81,7 @@ namespace RTC
void
OnDtlsTransportConnecting
(
const
RTC
::
DtlsTransport
*
dtlsTransport
)
override
;
void
OnDtlsTransportConnected
(
const
RTC
::
DtlsTransport
*
dtlsTransport
,
RTC
::
SrtpSession
::
Profile
srtpProfil
e
,
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuit
e
,
uint8_t
*
srtpLocalKey
,
size_t
srtpLocalKeyLen
,
uint8_t
*
srtpRemoteKey
,
...
...
worker/src/RTC/DtlsTransport.cpp
浏览文件 @
5dd9a605
...
...
@@ -106,12 +106,12 @@ namespace RTC
{
"server"
,
DtlsTransport
::
Role
::
SERVER
}
};
std
::
vector
<
DtlsTransport
::
Fingerprint
>
DtlsTransport
::
localFingerprints
;
std
::
vector
<
DtlsTransport
::
Srtp
ProfileMapEntry
>
DtlsTransport
::
srtpProfil
es
=
std
::
vector
<
DtlsTransport
::
Srtp
CryptoSuiteMapEntry
>
DtlsTransport
::
srtpCryptoSuit
es
=
{
{
RTC
::
SrtpSession
::
Profil
e
::
AEAD_AES_256_GCM
,
"SRTP_AEAD_AES_256_GCM"
},
{
RTC
::
SrtpSession
::
Profil
e
::
AEAD_AES_128_GCM
,
"SRTP_AEAD_AES_128_GCM"
},
{
RTC
::
SrtpSession
::
Profil
e
::
AES_CM_128_HMAC_SHA1_80
,
"SRTP_AES128_CM_SHA1_80"
},
{
RTC
::
SrtpSession
::
Profil
e
::
AES_CM_128_HMAC_SHA1_32
,
"SRTP_AES128_CM_SHA1_32"
}
{
RTC
::
SrtpSession
::
CryptoSuit
e
::
AEAD_AES_256_GCM
,
"SRTP_AEAD_AES_256_GCM"
},
{
RTC
::
SrtpSession
::
CryptoSuit
e
::
AEAD_AES_128_GCM
,
"SRTP_AEAD_AES_128_GCM"
},
{
RTC
::
SrtpSession
::
CryptoSuit
e
::
AES_CM_128_HMAC_SHA1_80
,
"SRTP_AES128_CM_SHA1_80"
},
{
RTC
::
SrtpSession
::
CryptoSuit
e
::
AES_CM_128_HMAC_SHA1_32
,
"SRTP_AES128_CM_SHA1_32"
}
};
// clang-format on
...
...
@@ -370,7 +370,7 @@ namespace RTC
{
MS_TRACE
();
std
::
string
dtlsSrtp
Profil
es
;
std
::
string
dtlsSrtp
CryptoSuit
es
;
EC_KEY
*
ecdh
{
nullptr
};
int
ret
;
...
...
@@ -487,23 +487,26 @@ namespace RTC
#endif
// Set the "use_srtp" DTLS extension.
for
(
auto
it
=
DtlsTransport
::
srtpProfiles
.
begin
();
it
!=
DtlsTransport
::
srtpProfiles
.
end
();
++
it
)
for
(
auto
it
=
DtlsTransport
::
srtpCryptoSuites
.
begin
();
it
!=
DtlsTransport
::
srtpCryptoSuites
.
end
();
++
it
)
{
if
(
it
!=
DtlsTransport
::
srtp
Profil
es
.
begin
())
dtlsSrtp
Profil
es
+=
":"
;
if
(
it
!=
DtlsTransport
::
srtp
CryptoSuit
es
.
begin
())
dtlsSrtp
CryptoSuit
es
+=
":"
;
Srtp
ProfileMapEntry
*
profil
eEntry
=
std
::
addressof
(
*
it
);
dtlsSrtp
Profiles
+=
profil
eEntry
->
name
;
Srtp
CryptoSuiteMapEntry
*
cryptoSuit
eEntry
=
std
::
addressof
(
*
it
);
dtlsSrtp
CryptoSuites
+=
cryptoSuit
eEntry
->
name
;
}
MS_DEBUG_2TAGS
(
dtls
,
srtp
,
"setting SRTP
profiles for DTLS: %s"
,
dtlsSrtpProfil
es
.
c_str
());
MS_DEBUG_2TAGS
(
dtls
,
srtp
,
"setting SRTP
cryptoSuites for DTLS: %s"
,
dtlsSrtpCryptoSuit
es
.
c_str
());
// NOTE: This function returns 0 on success.
ret
=
SSL_CTX_set_tlsext_use_srtp
(
DtlsTransport
::
sslCtx
,
dtlsSrtp
Profil
es
.
c_str
());
ret
=
SSL_CTX_set_tlsext_use_srtp
(
DtlsTransport
::
sslCtx
,
dtlsSrtp
CryptoSuit
es
.
c_str
());
if
(
ret
!=
0
)
{
MS_ERROR
(
"SSL_CTX_set_tlsext_use_srtp() failed when entering '%s'"
,
dtlsSrtpProfiles
.
c_str
());
MS_ERROR
(
"SSL_CTX_set_tlsext_use_srtp() failed when entering '%s'"
,
dtlsSrtpCryptoSuites
.
c_str
());
LOG_OPENSSL_ERROR
(
"SSL_CTX_set_tlsext_use_srtp() failed"
);
goto
error
;
...
...
@@ -1141,20 +1144,20 @@ namespace RTC
return
false
;
}
// Get the negotiated SRTP
profil
e.
RTC
::
SrtpSession
::
Profile
srtpProfile
=
GetNegotiatedSrtpProfil
e
();
// Get the negotiated SRTP
crypto suit
e.
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuite
=
GetNegotiatedSrtpCryptoSuit
e
();
if
(
srtp
Profile
!=
RTC
::
SrtpSession
::
Profil
e
::
NONE
)
if
(
srtp
CryptoSuite
!=
RTC
::
SrtpSession
::
CryptoSuit
e
::
NONE
)
{
// Extract the SRTP keys (will notify the listener with them).
ExtractSrtpKeys
(
srtp
Profil
e
);
ExtractSrtpKeys
(
srtp
CryptoSuit
e
);
return
true
;
}
// NOTE: We assume that "use_srtp" DTLS extension is required even if
// there is no audio/video.
MS_WARN_2TAGS
(
dtls
,
srtp
,
"SRTP
profil
e not negotiated"
);
MS_WARN_2TAGS
(
dtls
,
srtp
,
"SRTP
crypto suit
e not negotiated"
);
Reset
();
...
...
@@ -1291,7 +1294,7 @@ namespace RTC
return
true
;
}
inline
void
DtlsTransport
::
ExtractSrtpKeys
(
RTC
::
SrtpSession
::
Profile
srtpProfil
e
)
inline
void
DtlsTransport
::
ExtractSrtpKeys
(
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuit
e
)
{
MS_TRACE
();
...
...
@@ -1299,10 +1302,10 @@ namespace RTC
size_t
srtpSaltLength
{
0
};
size_t
srtpMasterLength
{
0
};
switch
(
srtp
Profil
e
)
switch
(
srtp
CryptoSuit
e
)
{
case
RTC
:
:
SrtpSession
::
Profil
e
::
AES_CM_128_HMAC_SHA1_80
:
case
RTC
:
:
SrtpSession
::
Profil
e
::
AES_CM_128_HMAC_SHA1_32
:
case
RTC
:
:
SrtpSession
::
CryptoSuit
e
::
AES_CM_128_HMAC_SHA1_80
:
case
RTC
:
:
SrtpSession
::
CryptoSuit
e
::
AES_CM_128_HMAC_SHA1_32
:
{
srtpKeyLength
=
SrtpMasterKeyLength
;
srtpSaltLength
=
SrtpMasterSaltLength
;
...
...
@@ -1311,7 +1314,7 @@ namespace RTC
break
;
}
case
RTC
:
:
SrtpSession
::
Profil
e
::
AEAD_AES_256_GCM
:
case
RTC
:
:
SrtpSession
::
CryptoSuit
e
::
AEAD_AES_256_GCM
:
{
srtpKeyLength
=
SrtpAesGcm256MasterKeyLength
;
srtpSaltLength
=
SrtpAesGcm256MasterSaltLength
;
...
...
@@ -1320,7 +1323,7 @@ namespace RTC
break
;
}
case
RTC
:
:
SrtpSession
::
Profil
e
::
AEAD_AES_128_GCM
:
case
RTC
:
:
SrtpSession
::
CryptoSuit
e
::
AEAD_AES_128_GCM
:
{
srtpKeyLength
=
SrtpAesGcm128MasterKeyLength
;
srtpSaltLength
=
SrtpAesGcm128MasterSaltLength
;
...
...
@@ -1331,7 +1334,7 @@ namespace RTC
default
:
{
MS_ABORT
(
"unknown SRTP
profil
e"
);
MS_ABORT
(
"unknown SRTP
crypto suit
e"
);
}
}
...
...
@@ -1388,7 +1391,7 @@ namespace RTC
this
->
state
=
DtlsState
::
CONNECTED
;
this
->
listener
->
OnDtlsTransportConnected
(
this
,
srtp
Profil
e
,
srtp
CryptoSuit
e
,
srtpLocalMasterKey
,
srtpMasterLength
,
srtpRemoteMasterKey
,
...
...
@@ -1400,36 +1403,37 @@ namespace RTC
delete
[]
srtpRemoteMasterKey
;
}
inline
RTC
::
SrtpSession
::
Profile
DtlsTransport
::
GetNegotiatedSrtpProfil
e
()
inline
RTC
::
SrtpSession
::
CryptoSuite
DtlsTransport
::
GetNegotiatedSrtpCryptoSuit
e
()
{
MS_TRACE
();
RTC
::
SrtpSession
::
Profile
negotiatedSrtpProfile
=
RTC
::
SrtpSession
::
Profil
e
::
NONE
;
RTC
::
SrtpSession
::
CryptoSuite
negotiatedSrtpCryptoSuite
=
RTC
::
SrtpSession
::
CryptoSuit
e
::
NONE
;
// Ensure that the SRTP profile has been negotiated.
SRTP_PROTECTION_PROFILE
*
sslSrtpProfile
=
SSL_get_selected_srtp_profile
(
this
->
ssl
);
// Ensure that the SRTP crypto suite has been negotiated.
// NOTE: This is a OpenSSL type.
SRTP_PROTECTION_PROFILE
*
sslSrtpCryptoSuite
=
SSL_get_selected_srtp_profile
(
this
->
ssl
);
if
(
!
sslSrtp
Profil
e
)
return
negotiatedSrtp
Profil
e
;
if
(
!
sslSrtp
CryptoSuit
e
)
return
negotiatedSrtp
CryptoSuit
e
;
// Get the negotiated SRTP
profil
e.
for
(
auto
&
srtp
Profile
:
DtlsTransport
::
srtpProfil
es
)
// Get the negotiated SRTP
crypto suit
e.
for
(
auto
&
srtp
CryptoSuite
:
DtlsTransport
::
srtpCryptoSuit
es
)
{
Srtp
ProfileMapEntry
*
profileEntry
=
std
::
addressof
(
srtpProfil
e
);
Srtp
CryptoSuiteMapEntry
*
cryptoSuiteEntry
=
std
::
addressof
(
srtpCryptoSuit
e
);
if
(
std
::
strcmp
(
sslSrtp
Profile
->
name
,
profil
eEntry
->
name
)
==
0
)
if
(
std
::
strcmp
(
sslSrtp
CryptoSuite
->
name
,
cryptoSuit
eEntry
->
name
)
==
0
)
{
MS_DEBUG_2TAGS
(
dtls
,
srtp
,
"chosen SRTP
profile: %s"
,
profil
eEntry
->
name
);
MS_DEBUG_2TAGS
(
dtls
,
srtp
,
"chosen SRTP
crypto suite: %s"
,
cryptoSuit
eEntry
->
name
);
negotiatedSrtp
Profile
=
profileEntry
->
profil
e
;
negotiatedSrtp
CryptoSuite
=
cryptoSuiteEntry
->
cryptoSuit
e
;
}
}
MS_ASSERT
(
negotiatedSrtp
Profile
!=
RTC
::
SrtpSession
::
Profil
e
::
NONE
,
"chosen SRTP
profil
e is not an available one"
);
negotiatedSrtp
CryptoSuite
!=
RTC
::
SrtpSession
::
CryptoSuit
e
::
NONE
,
"chosen SRTP
crypto suit
e is not an available one"
);
return
negotiatedSrtp
Profil
e
;
return
negotiatedSrtp
CryptoSuit
e
;
}
inline
void
DtlsTransport
::
OnSslInfo
(
int
where
,
int
ret
)
...
...
worker/src/RTC/PipeTransport.cpp
浏览文件 @
5dd9a605
...
...
@@ -11,11 +11,12 @@ namespace RTC
{
/* Static. */
// NOTE: We just use AES_CM_128_HMAC_SHA1_80 as SRTP crypto suite in
// PipeTransport.
static
RTC
::
SrtpSession
::
Profile
SrtpProfile
{
RTC
::
SrtpSession
::
Profile
::
AES_CM_128_HMAC_SHA1_80
};
static
const
std
::
string
SrtpProfileStr
{
"AES_CM_128_HMAC_SHA1_80"
};
static
constexpr
size_t
SrtpMasterLength
{
30
};
// NOTE: PipeTransport just allows AES_CM_128_HMAC_SHA1_80 SRTP crypto suite.
RTC
::
SrtpSession
::
CryptoSuite
PipeTransport
::
srtpCryptoSuite
{
RTC
::
SrtpSession
::
CryptoSuite
::
AES_CM_128_HMAC_SHA1_80
};
std
::
string
PipeTransport
::
srtpCryptoSuiteString
{
"AES_CM_128_HMAC_SHA1_80"
};
size_t
PipeTransport
::
srtpMasterLength
{
30
};
/* Instance methods. */
...
...
@@ -69,9 +70,8 @@ namespace RTC
)
// clang-format on
{
this
->
srtpCryptoSuite
=
SrtpProfileStr
;
this
->
srtpKey
=
Utils
::
Crypto
::
GetRandomString
(
SrtpMasterLength
);
this
->
srtpKeyBase64
=
Utils
::
String
::
Base64Encode
(
this
->
srtpKey
);
this
->
srtpKey
=
Utils
::
Crypto
::
GetRandomString
(
PipeTransport
::
srtpMasterLength
);
this
->
srtpKeyBase64
=
Utils
::
String
::
Base64Encode
(
this
->
srtpKey
);
}
try
...
...
@@ -114,19 +114,6 @@ namespace RTC
// Call the parent method.
RTC
::
Transport
::
FillJson
(
jsonObject
);
// Add rtx.
jsonObject
[
"rtx"
]
=
this
->
rtx
;
// Add srtpParameters.
if
(
HasSrtp
())
{
jsonObject
[
"srtpParameters"
]
=
json
::
object
();
auto
jsonSrtpParametersIt
=
jsonObject
.
find
(
"srtpParameters"
);
(
*
jsonSrtpParametersIt
)[
"cryptoSuite"
]
=
this
->
srtpCryptoSuite
;
(
*
jsonSrtpParametersIt
)[
"keyBase64"
]
=
this
->
srtpKeyBase64
;
}
// Add tuple.
if
(
this
->
tuple
!=
nullptr
)
{
...
...
@@ -145,6 +132,19 @@ namespace RTC
(
*
jsonTupleIt
)[
"localPort"
]
=
this
->
udpSocket
->
GetLocalPort
();
(
*
jsonTupleIt
)[
"protocol"
]
=
"udp"
;
}
// Add rtx.
jsonObject
[
"rtx"
]
=
this
->
rtx
;
// Add srtpParameters.
if
(
HasSrtp
())
{
jsonObject
[
"srtpParameters"
]
=
json
::
object
();
auto
jsonSrtpParametersIt
=
jsonObject
.
find
(
"srtpParameters"
);
(
*
jsonSrtpParametersIt
)[
"cryptoSuite"
]
=
PipeTransport
::
srtpCryptoSuiteString
;
(
*
jsonSrtpParametersIt
)[
"keyBase64"
]
=
this
->
srtpKeyBase64
;
}
}
void
PipeTransport
::
FillJsonStats
(
json
&
jsonArray
)
...
...
@@ -195,7 +195,7 @@ namespace RTC
{
std
::
string
ip
;
uint16_t
port
{
0u
};
std
::
string
srtpKey
;
std
::
string
srtpKey
Base64
;
auto
jsonIpIt
=
request
->
data
.
find
(
"ip"
);
...
...
@@ -253,8 +253,10 @@ namespace RTC
// NOTE: We just use AES_CM_128_HMAC_SHA1_80 as SRTP crypto suite in
// PipeTransport.
if
(
jsonCryptoSuiteIt
->
get
<
std
::
string
>
()
!=
SrtpProfileStr
)
MS_THROW_TYPE_ERROR
(
"invalid srtpParameters.cryptoSuite"
);
if
(
jsonCryptoSuiteIt
->
get
<
std
::
string
>
()
!=
PipeTransport
::
srtpCryptoSuiteString
)
{
MS_THROW_TYPE_ERROR
(
"invalid/unsupported srtpParameters.cryptoSuite"
);
}
auto
jsonKeyBase64It
=
jsonSrtpParametersIt
->
find
(
"keyBase64"
);
...
...
@@ -268,24 +270,28 @@ namespace RTC
MS_THROW_TYPE_ERROR
(
"missing srtpParameters.keyBase64)"
);
}
auto
srtpKeyBase64
=
jsonKeyBase64It
->
get
<
std
::
string
>
();
srtpKeyBase64
=
jsonKeyBase64It
->
get
<
std
::
string
>
();
size_t
outLen
;
// This may throw.
auto
*
srtpKey
=
Utils
::
String
::
Base64Decode
(
srtpKeyBase64
,
outLen
);
if
(
outLen
!=
S
rtpMasterLength
)
if
(
outLen
!=
PipeTransport
::
s
rtpMasterLength
)
MS_THROW_TYPE_ERROR
(
"invalid decoded SRTP key length"
);
auto
*
srtpLocalKey
=
new
uint8_t
[
S
rtpMasterLength
];
auto
*
srtpRemoteKey
=
new
uint8_t
[
S
rtpMasterLength
];
auto
*
srtpLocalKey
=
new
uint8_t
[
PipeTransport
::
s
rtpMasterLength
];
auto
*
srtpRemoteKey
=
new
uint8_t
[
PipeTransport
::
s
rtpMasterLength
];
std
::
memcpy
(
srtpLocalKey
,
this
->
srtpKey
.
c_str
(),
S
rtpMasterLength
);
std
::
memcpy
(
srtpRemoteKey
,
srtpKey
,
S
rtpMasterLength
);
std
::
memcpy
(
srtpLocalKey
,
this
->
srtpKey
.
c_str
(),
PipeTransport
::
s
rtpMasterLength
);
std
::
memcpy
(
srtpRemoteKey
,
srtpKey
,
PipeTransport
::
s
rtpMasterLength
);
try
{
this
->
srtpSendSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
SrtpProfile
,
srtpLocalKey
,
SrtpMasterLength
);
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
PipeTransport
::
srtpCryptoSuite
,
srtpLocalKey
,
PipeTransport
::
srtpMasterLength
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -298,7 +304,10 @@ namespace RTC
try
{
this
->
srtpRecvSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
INBOUND
,
SrtpProfile
,
srtpRemoteKey
,
SrtpMasterLength
);
RTC
::
SrtpSession
::
Type
::
INBOUND
,
PipeTransport
::
srtpCryptoSuite
,
srtpRemoteKey
,
PipeTransport
::
srtpMasterLength
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -357,15 +366,15 @@ namespace RTC
}
catch
(
const
MediaSoupError
&
error
)
{
delete
this
->
tuple
;
this
->
tuple
=
nullptr
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
delete
this
->
tuple
;
this
->
tuple
=
nullptr
;
throw
;
}
...
...
@@ -391,14 +400,14 @@ namespace RTC
}
}
inline
bool
PipeTransport
::
HasSrtp
()
const
inline
bool
PipeTransport
::
IsConnected
()
const
{
return
!
this
->
srtpKey
.
empty
()
;
return
this
->
tuple
!=
nullptr
;
}
inline
bool
PipeTransport
::
IsConnected
()
const
inline
bool
PipeTransport
::
HasSrtp
()
const
{
return
this
->
tuple
!=
nullptr
;
return
!
this
->
srtpKey
.
empty
()
;
}
void
PipeTransport
::
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
)
...
...
worker/src/RTC/PlainRtpTransport.cpp
浏览文件 @
5dd9a605
...
...
@@ -8,6 +8,24 @@
namespace
RTC
{
/* Static. */
// NOTE: PlainRtpTransport allows AES_CM_128_HMAC_SHA1_80 and
// AES_CM_128_HMAC_SHA1_32 SRTP crypto suites.
// clang-format off
std
::
map
<
std
::
string
,
RTC
::
SrtpSession
::
CryptoSuite
>
PlainRtpTransport
::
string2SrtpCryptoSuite
=
{
{
"AES_CM_128_HMAC_SHA1_80"
,
RTC
::
SrtpSession
::
CryptoSuite
::
AES_CM_128_HMAC_SHA1_80
},
{
"AES_CM_128_HMAC_SHA1_32"
,
RTC
::
SrtpSession
::
CryptoSuite
::
AES_CM_128_HMAC_SHA1_32
}
};
std
::
map
<
RTC
::
SrtpSession
::
CryptoSuite
,
std
::
string
>
PlainRtpTransport
::
srtpCryptoSuite2String
=
{
{
RTC
::
SrtpSession
::
CryptoSuite
::
AES_CM_128_HMAC_SHA1_80
,
"AES_CM_128_HMAC_SHA1_80"
},
{
RTC
::
SrtpSession
::
CryptoSuite
::
AES_CM_128_HMAC_SHA1_32
,
"AES_CM_128_HMAC_SHA1_32"
}
};
// clang-format on
size_t
PlainRtpTransport
::
srtpMasterLength
{
30
};
/* Instance methods. */
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init)
...
...
@@ -83,6 +101,34 @@ namespace RTC
}
}
auto
jsonEnableSrtpIt
=
data
.
find
(
"enableSrtp"
);
// clang-format off
if
(
jsonEnableSrtpIt
!=
data
.
end
()
&&
jsonEnableSrtpIt
->
is_boolean
()
&&
jsonEnableSrtpIt
->
get
<
bool
>
()
)
// clang-format on
{
auto
jsonSrtpCryptoSuiteIt
=
data
.
find
(
"srtpCryptoSuite"
);
if
(
jsonSrtpCryptoSuiteIt
==
data
.
end
()
||
!
jsonSrtpCryptoSuiteIt
->
is_string
())
MS_THROW_TYPE_ERROR
(
"missing srtpCryptoSuite)"
);
// Ensure it's a crypto suite supported by us.
auto
it
=
PlainRtpTransport
::
string2SrtpCryptoSuite
.
find
(
jsonSrtpCryptoSuiteIt
->
get
<
std
::
string
>
());
if
(
it
==
PlainRtpTransport
::
string2SrtpCryptoSuite
.
end
())
MS_THROW_TYPE_ERROR
(
"invalid/unsupported srtpCryptoSuite"
);
// NOTE: The SRTP crypto suite may change later on connect().
this
->
srtpCryptoSuite
=
it
->
second
;
this
->
srtpKey
=
Utils
::
Crypto
::
GetRandomString
(
PlainRtpTransport
::
srtpMasterLength
);
this
->
srtpKeyBase64
=
Utils
::
String
::
Base64Encode
(
this
->
srtpKey
);
}
try
{
// This may throw.
...
...
@@ -121,6 +167,12 @@ namespace RTC
delete
this
->
rtcpTuple
;
this
->
rtcpTuple
=
nullptr
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
}
void
PlainRtpTransport
::
FillJson
(
json
&
jsonObject
)
const
...
...
@@ -179,6 +231,17 @@ namespace RTC
(
*
jsonRtcpTupleIt
)[
"protocol"
]
=
"udp"
;
}
}
// Add srtpParameters.
if
(
HasSrtp
())
{
jsonObject
[
"srtpParameters"
]
=
json
::
object
();
auto
jsonSrtpParametersIt
=
jsonObject
.
find
(
"srtpParameters"
);
(
*
jsonSrtpParametersIt
)[
"cryptoSuite"
]
=
PlainRtpTransport
::
srtpCryptoSuite2String
[
this
->
srtpCryptoSuite
];
(
*
jsonSrtpParametersIt
)[
"keyBase64"
]
=
this
->
srtpKeyBase64
;
}
}
void
PlainRtpTransport
::
FillJsonStats
(
json
&
jsonArray
)
...
...
@@ -250,6 +313,7 @@ namespace RTC
std
::
string
ip
;
uint16_t
port
{
0u
};
uint16_t
rtcpPort
{
0u
};
std
::
string
srtpKeyBase64
;
auto
jsonIpIt
=
request
->
data
.
find
(
"ip"
);
...
...
@@ -295,6 +359,109 @@ namespace RTC
MS_THROW_TYPE_ERROR
(
"missing rtcpPort (required with rtcpMux disabled)"
);
}
auto
jsonSrtpParametersIt
=
request
->
data
.
find
(
"srtpParameters"
);
if
(
!
HasSrtp
()
&&
jsonSrtpParametersIt
!=
request
->
data
.
end
())
{
MS_THROW_TYPE_ERROR
(
"invalid srtpParameters (SRTP not enabled)"
);
}
else
if
(
HasSrtp
())
{
// clang-format off
if
(
jsonSrtpParametersIt
==
request
->
data
.
end
()
||
!
jsonSrtpParametersIt
->
is_object
()
)
// clang-format on
{
MS_THROW_TYPE_ERROR
(
"missing srtpParameters (SRTP enabled)"
);
}
auto
jsonCryptoSuiteIt
=
jsonSrtpParametersIt
->
find
(
"cryptoSuite"
);
// clang-format off
if
(
jsonCryptoSuiteIt
==
jsonSrtpParametersIt
->
end
()
||
!
jsonCryptoSuiteIt
->
is_string
()
)
// clang-format on
{
MS_THROW_TYPE_ERROR
(
"missing srtpParameters.cryptoSuite)"
);
}
// Ensure it's a crypto suite supported by us.
auto
it
=
PlainRtpTransport
::
string2SrtpCryptoSuite
.
find
(
jsonCryptoSuiteIt
->
get
<
std
::
string
>
());
if
(
it
==
PlainRtpTransport
::
string2SrtpCryptoSuite
.
end
())
MS_THROW_TYPE_ERROR
(
"invalid/unsupported srtpParameters.cryptoSuite"
);
// Update out SRTP crypto suite wuth the one used by the remote.
this
->
srtpCryptoSuite
=
it
->
second
;
auto
jsonKeyBase64It
=
jsonSrtpParametersIt
->
find
(
"keyBase64"
);
// clang-format off
if
(
jsonKeyBase64It
==
jsonSrtpParametersIt
->
end
()
||
!
jsonKeyBase64It
->
is_string
()
)
// clang-format on
{
MS_THROW_TYPE_ERROR
(
"missing srtpParameters.keyBase64)"
);
}
srtpKeyBase64
=
jsonKeyBase64It
->
get
<
std
::
string
>
();
size_t
outLen
;
// This may throw.
auto
*
srtpKey
=
Utils
::
String
::
Base64Decode
(
srtpKeyBase64
,
outLen
);
if
(
outLen
!=
PlainRtpTransport
::
srtpMasterLength
)
MS_THROW_TYPE_ERROR
(
"invalid decoded SRTP key length"
);
auto
*
srtpLocalKey
=
new
uint8_t
[
PlainRtpTransport
::
srtpMasterLength
];
auto
*
srtpRemoteKey
=
new
uint8_t
[
PlainRtpTransport
::
srtpMasterLength
];
std
::
memcpy
(
srtpLocalKey
,
this
->
srtpKey
.
c_str
(),
PlainRtpTransport
::
srtpMasterLength
);
std
::
memcpy
(
srtpRemoteKey
,
srtpKey
,
PlainRtpTransport
::
srtpMasterLength
);
try
{
this
->
srtpSendSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
this
->
srtpCryptoSuite
,
srtpLocalKey
,
PlainRtpTransport
::
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
,
this
->
srtpCryptoSuite
,
srtpRemoteKey
,
PlainRtpTransport
::
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
;
switch
(
Utils
::
IP
::
GetFamily
(
ip
))
...
...
@@ -390,6 +557,12 @@ namespace RTC
delete
this
->
rtcpTuple
;
this
->
rtcpTuple
=
nullptr
;
delete
this
->
srtpSendSession
;
this
->
srtpSendSession
=
nullptr
;
delete
this
->
srtpRecvSession
;
this
->
srtpRecvSession
=
nullptr
;
throw
;
}
...
...
@@ -401,6 +574,16 @@ namespace RTC
if
(
!
this
->
rtcpMux
)
this
->
rtcpTuple
->
FillJson
(
data
[
"rtcpTuple"
]);
if
(
HasSrtp
())
{
data
[
"srtpParameters"
]
=
json
::
object
();
auto
jsonSrtpParametersIt
=
data
.
find
(
"srtpParameters"
);
(
*
jsonSrtpParametersIt
)[
"cryptoSuite"
]
=
PlainRtpTransport
::
srtpCryptoSuite2String
[
this
->
srtpCryptoSuite
];
(
*
jsonSrtpParametersIt
)[
"keyBase64"
]
=
this
->
srtpKeyBase64
;
}
request
->
Accept
(
data
);
// Assume we are connected (there is no much more we can do to know it)
...
...
@@ -423,6 +606,11 @@ namespace RTC
return
this
->
tuple
!=
nullptr
;
}
inline
bool
PlainRtpTransport
::
HasSrtp
()
const
{
return
!
this
->
srtpKey
.
empty
();
}
void
PlainRtpTransport
::
SendRtpPacket
(
RTC
::
RtpPacket
*
packet
,
RTC
::
Transport
::
onSendCallback
*
cb
)
{
MS_TRACE
();
...
...
@@ -442,6 +630,18 @@ namespace RTC
const
uint8_t
*
data
=
packet
->
GetData
();
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
);
// Increase send transmission.
...
...
@@ -458,6 +658,9 @@ namespace RTC
const
uint8_t
*
data
=
packet
->
GetData
();
size_t
len
=
packet
->
GetSize
();
if
(
HasSrtp
()
&&
!
this
->
srtpSendSession
->
EncryptRtcp
(
&
data
,
&
len
))
return
;
if
(
this
->
rtcpMux
)
this
->
tuple
->
Send
(
data
,
len
);
else
if
(
this
->
rtcpTuple
)
...
...
@@ -477,6 +680,9 @@ namespace RTC
const
uint8_t
*
data
=
packet
->
GetData
();
size_t
len
=
packet
->
GetSize
();
if
(
HasSrtp
()
&&
!
this
->
srtpSendSession
->
EncryptRtcp
(
&
data
,
&
len
))
return
;
if
(
this
->
rtcpMux
)
this
->
tuple
->
Send
(
data
,
len
);
else
if
(
this
->
rtcpTuple
)
...
...
@@ -533,6 +739,9 @@ namespace RTC
{
MS_TRACE
();
// TODO: Check SRTP and connect() called, but may be it was called just to provide
// us with the remote SRTP parameters, etc.
// If multiSource is set allow it without any checking.
if
(
this
->
multiSource
)
{
...
...
worker/src/RTC/SrtpSession.cpp
浏览文件 @
5dd9a605
...
...
@@ -54,7 +54,7 @@ namespace RTC
/* Instance methods. */
SrtpSession
::
SrtpSession
(
Type
type
,
Profile
profil
e
,
uint8_t
*
key
,
size_t
keyLen
)
SrtpSession
::
SrtpSession
(
Type
type
,
CryptoSuite
cryptoSuit
e
,
uint8_t
*
key
,
size_t
keyLen
)
{
MS_TRACE
();
...
...
@@ -63,9 +63,9 @@ namespace RTC
// Set all policy fields to 0.
std
::
memset
(
&
policy
,
0
,
sizeof
(
srtp_policy_t
));
switch
(
profil
e
)
switch
(
cryptoSuit
e
)
{
case
Profil
e
:
:
AES_CM_128_HMAC_SHA1_80
:
case
CryptoSuit
e
:
:
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
.
rtcp
);
...
...
@@ -73,7 +73,7 @@ namespace RTC
break
;
}
case
Profil
e
:
:
AES_CM_128_HMAC_SHA1_32
:
case
CryptoSuit
e
:
:
AES_CM_128_HMAC_SHA1_32
:
{
srtp_crypto_policy_set_aes_cm_128_hmac_sha1_32
(
&
policy
.
rtp
);
// NOTE: Must be 80 for RTCP.
...
...
@@ -82,7 +82,7 @@ namespace RTC
break
;
}
case
Profil
e
:
:
AEAD_AES_256_GCM
:
case
CryptoSuit
e
:
:
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
);
...
...
@@ -90,7 +90,7 @@ namespace RTC
break
;
}
case
Profil
e
:
:
AEAD_AES_128_GCM
:
case
CryptoSuit
e
:
:
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
);
...
...
@@ -100,7 +100,7 @@ namespace RTC
default
:
{
MS_ABORT
(
"unknown SRTP
profil
e"
);
MS_ABORT
(
"unknown SRTP
crypto suit
e"
);
}
}
...
...
worker/src/RTC/WebRtcTransport.cpp
浏览文件 @
5dd9a605
...
...
@@ -258,9 +258,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Call the parent method.
RTC
::
Transport
::
FillJson
(
jsonObject
);
...
...
@@ -373,9 +370,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Call the parent method.
RTC
::
Transport
::
FillJsonStats
(
jsonArray
);
...
...
@@ -602,9 +596,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// clang-format off
return
(
(
...
...
@@ -620,9 +611,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Do nothing if we have the same local DTLS role as the DTLS transport.
// NOTE: local role in DTLS transport can be NONE, but not ours.
if
(
this
->
dtlsTransport
->
GetLocalRole
()
==
this
->
dtlsRole
)
...
...
@@ -828,9 +816,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Increase receive transmission.
RTC
::
Transport
::
DataReceived
(
len
);
...
...
@@ -865,8 +850,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
RTC
::
StunPacket
*
packet
=
RTC
::
StunPacket
::
Parse
(
data
,
len
);
if
(
!
packet
)
...
...
@@ -887,9 +870,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Ensure it comes from a valid tuple.
if
(
!
this
->
iceServer
->
IsValidTuple
(
tuple
))
{
...
...
@@ -923,9 +903,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Ensure DTLS is connected.
if
(
this
->
dtlsTransport
->
GetState
()
!=
RTC
::
DtlsTransport
::
DtlsState
::
CONNECTED
)
{
...
...
@@ -995,9 +972,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Ensure DTLS is connected.
if
(
this
->
dtlsTransport
->
GetState
()
!=
RTC
::
DtlsTransport
::
DtlsState
::
CONNECTED
)
{
...
...
@@ -1086,8 +1060,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
/*
* RFC 5245 section 11.2 "Receiving Media":
*
...
...
@@ -1109,8 +1081,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_DEBUG_TAG
(
ice
,
"ICE connected"
);
// Notify the Node WebRtcTransport.
...
...
@@ -1132,8 +1102,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_DEBUG_TAG
(
ice
,
"ICE completed"
);
// Notify the Node WebRtcTransport.
...
...
@@ -1155,8 +1123,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_DEBUG_TAG
(
ice
,
"ICE disconnected"
);
// Notify the Node WebRtcTransport.
...
...
@@ -1175,9 +1141,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
MS_DEBUG_TAG
(
dtls
,
"DTLS connecting"
);
// Notify the Node WebRtcTransport.
...
...
@@ -1190,7 +1153,7 @@ namespace RTC
inline
void
WebRtcTransport
::
OnDtlsTransportConnected
(
const
RTC
::
DtlsTransport
*
/*dtlsTransport*/
,
RTC
::
SrtpSession
::
Profile
srtpProfil
e
,
RTC
::
SrtpSession
::
CryptoSuite
srtpCryptoSuit
e
,
uint8_t
*
srtpLocalKey
,
size_t
srtpLocalKeyLen
,
uint8_t
*
srtpRemoteKey
,
...
...
@@ -1199,9 +1162,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
MS_DEBUG_TAG
(
dtls
,
"DTLS connected"
);
// Close it if it was already set and update it.
...
...
@@ -1214,7 +1174,7 @@ namespace RTC
try
{
this
->
srtpSendSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
srtp
Profil
e
,
srtpLocalKey
,
srtpLocalKeyLen
);
RTC
::
SrtpSession
::
Type
::
OUTBOUND
,
srtp
CryptoSuit
e
,
srtpLocalKey
,
srtpLocalKeyLen
);
}
catch
(
const
MediaSoupError
&
error
)
{
...
...
@@ -1224,7 +1184,7 @@ namespace RTC
try
{
this
->
srtpRecvSession
=
new
RTC
::
SrtpSession
(
RTC
::
SrtpSession
::
Type
::
INBOUND
,
srtp
Profil
e
,
srtpRemoteKey
,
srtpRemoteKeyLen
);
RTC
::
SrtpSession
::
Type
::
INBOUND
,
srtp
CryptoSuit
e
,
srtpRemoteKey
,
srtpRemoteKeyLen
);
// Notify the Node WebRtcTransport.
json
data
=
json
::
object
();
...
...
@@ -1250,9 +1210,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
MS_WARN_TAG
(
dtls
,
"DTLS failed"
);
// Notify the Node WebRtcTransport.
...
...
@@ -1267,9 +1224,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
MS_WARN_TAG
(
dtls
,
"DTLS remotely closed"
);
// Notify the Node WebRtcTransport.
...
...
@@ -1288,11 +1242,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
if
(
!
this
->
iceServer
->
GetSelectedTuple
())
{
MS_WARN_TAG
(
dtls
,
"no selected tuple set, cannot send DTLS packet"
);
...
...
@@ -1311,9 +1260,6 @@ namespace RTC
{
MS_TRACE
();
MS_ASSERT
(
this
->
iceServer
,
"no iceServer"
);
MS_ASSERT
(
this
->
dtlsTransport
,
"no dtlsTransport"
);
// Pass it to the parent transport.
RTC
::
Transport
::
ReceiveSctpData
(
data
,
len
);
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论