我使用这个 Flutter 数据通道示例将我的 Android 应用程序连接到我本地网络上的CoTURN 服务器。CoTURN 日志显示 Android 应用程序成功连接到 CoTURN 服务器,但未显示任何用户名。我想确保在不使用长期凭据的情况下无法访问我的 CoTURN 服务器。
我的 CoTURN 服务器版本在 Debian Linux Stable (10 Buster) 上是 4.5.1.1-1.1。已lt-cred-mech
在 CoTURN 服务器配置中设置,no-auth
但未设置(已注释)。我verbose
用来检查日志。我在我的 MySQL 数据库中创建了一个用于长期凭据的用户。在安全端口上使用此命令进行验证:
turnutils_uclient -p 5349 -u myuser -w mypassword 192.168.188.28
它在 coturn 日志中导致以下内容:
1992: handle_udp_packet: New UDP endpoint: local addr 192.168.188.28:5349, remote addr 192.168.188.28:58256
1992: session 002000000000000002: realm <myrealm> user <>: incoming packet message processed, error 401: Unauthorized
1992: IPv4. Local relay addr: 192.168.188.28:64632
1992: IPv4. Local reserved relay addr: 192.168.188.28:64633
1992: session 002000000000000002: new, realm=<myrealm>, username=<myuser>, lifetime=777
1992: session 002000000000000002: realm <myrealm> user <myuser>: incoming packet ALLOCATE processed, success
1992: session 002000000000000002: refreshed, realm=<myrealm>, username=<myuser>, lifetime=777
1992: session 002000000000000002: realm <myrealm> user <myuser>: incoming packet REFRESH processed, success
...
2007: session 003000000000000003: delete: realm=<myrealm>, username=<myuser>
2007: session 003000000000000003: peer 0.0.0.0:3481 deleted
2008: session 001000000000000008: usage: realm=<myrealm>, username=<myuser>, rp=13, rb=1360, sp=8, sb=768
2008: session 001000000000000008: closed (2nd stage), user <myuser> realm <myrealm> origin <>, local 192.168.188.28:5349, remote 192.168.188.28:48266, reason: allocation timeout
2008: session 001000000000000008: delete: realm=<myrealm>, username=<myuser>
2008: session 001000000000000008: peer 0.0.0.0:3481 deleted
如果我对故意无效的用户尝试相同的命令,我会在服务器日志中得到预期的以下结果:
2227: handle_udp_packet: New UDP endpoint: local addr 192.168.188.28:5349, remote addr 192.168.188.28:40431
2227: session 002000000000000003: realm <myrealm> user <>: incoming packet message processed, error 401: Unauthorized
2227: check_stun_auth: Cannot find credentials of user <myuserfaulty>
2227: session 002000000000000003: realm <myrealm> user <myuserfaulty>: incoming packet message processed, error 401: Unauthorized
2227: check_stun_auth: Cannot find credentials of user <myuserfaulty>
...
因此,这意味着 CoTURN 服务器确实检查了凭据。
但是,当我如下向 Flutter 应用程序添加凭据时,我得到的服务器日志似乎没有显示任何用户。最糟糕的是,如果用户故意犯错,它什么也不会改变。这是改编的代码部分:
...
Map<String, dynamic> configuration = {
"iceServers": [
{"url": "stun:192.168.188.28:5349"},
{"username": "myuserfaulty"},
{"credential": "mypassword"},
]
};
...
请注意,我从以下文件中猜测了配置中的username
和条目:credential
https://github.com/cloudwebrtc/flutter-webrtc/blob/master/ios/Classes/FlutterWebRTCPlugin.m
以下是使用 Flutter 故意错误凭据时的 CoTURN 日志:
2945: handle_udp_packet: New UDP endpoint: local addr 192.168.188.28:5349, remote addr 192.168.188.31:58350
2945: session 002000000000000004: realm <myrealm> user <>: incoming packet BINDING processed, success
2955: session 002000000000000004: realm <myrealm> user <>: incoming packet BINDING processed, success
2965: session 002000000000000004: realm <myrealm> user <>: incoming packet BINDING processed, success
2975: session 002000000000000004: realm <myrealm> user <>: incoming packet BINDING processed, success
2985: session 002000000000000004: realm <myrealm> user <>: incoming packet BINDING processed, success
2995: session 002000000000000004: realm <myrealm> user <>: incoming packet BINDING processed, success
3005: session 002000000000000004: usage: realm=<myrealm>, username=<>, rp=6, rb=120, sp=6, sb=528
3005: session 002000000000000004: closed (2nd stage), user <> realm <myrealm> origin <>, local 192.168.188.28:5349, remote 192.168.188.31:58350, reason: allocation watchdog determined stale session state
3005: handle_udp_packet: New UDP endpoint: local addr 192.168.188.28:5349, remote addr 192.168.188.31:58350
3005: session 002000000000000005: realm <myrealm> user <>: incoming packet BINDING processed, success
3015: session 002000000000000005: realm <myrealm> user <>: incoming packet BINDING processed, success
...
所以,我有以下问题:
如何确保我的 CoTURN 服务器在没有授权的长期凭据的情况下无法使用?
为什么 Flutter 应用程序不受相同的凭据验证的约束
turnutils_uclient
?我是否猜对了在 Flutter 应用程序中通过在配置中添加
username
和credential
条目来指定凭据的方式?