【问题标题】:how to authenticate coturn with rest api如何使用rest api对coturn进行身份验证
【发布时间】:2020-10-02 13:03:17
【问题描述】:

我正在本地主机上的 ubuntu 中运行 coturn 服务器 这是我的turnserver.conf

verbose
listening-ip=127.0.0.1
realm=test.demo
static-auth-secret=fb1d5d356dff13e709980e2a07dfcef130a713d53e4c6701efe4b770f27e17d4
use-auth-secret

启动服务器

service coturn start
service coturn status

返回

● coturn.service - LSB: coturn TURN Server
   Loaded: loaded (/etc/init.d/coturn; generated)
   Active: active (running) since Fri 2020-10-02 17:28:08 PKT; 3s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18905 ExecStop=/etc/init.d/coturn stop (code=exited, status=0/SUCCESS)
  Process: 18912 ExecStart=/etc/init.d/coturn start (code=exited, status=0/SUCCESS)
    Tasks: 15 (limit: 4915)
   CGroup: /system.slice/coturn.service
           └─18934 /usr/bin/turnserver -c /etc/turnserver.conf -o -v

Oct 02 17:28:08 user-Inspiron-7773 systemd[1]: Starting LSB: coturn TURN Server...
Oct 02 17:28:08 user-Inspiron-7773 coturn[18912]:  * Starting coturn  turnserver
Oct 02 17:28:08 user-Inspiron-7773 coturn[18912]:    ...done.
Oct 02 17:28:08 user-Inspiron-7773 systemd[1]: Started LSB: coturn TURN Server.

sudo netstat -npta | grep turnserver 给了

tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    
tcp        0      0 127.0.0.1:3478          0.0.0.0:*               LISTEN      18934/turnserver    

我已经生成了临时用户名和密码

val secretKey = "fb1d5d356dff13e709980e2a07dfcef130a713d53e4c6701efe4b770f27e17d4"
val userId= "abcd1234"
val ttl:Long = 3600 * 6
val unixTimeStamp =System.currentTimeMillis()/1000L + ttl
val userName = unixTimeStamp +":"+ userId
val secret = new SecretKeySpec(secretKey.getBytes, "HmacSHA1")
val mac = Mac.getInstance("HmacSHA1")
mac.init(secret)
val result: Array[Byte] = mac.doFinal(userName.getBytes)
val hashStr= new String(result.map(_.toChar))
val password = Base64.getEncoder.encodeToString(hashStr.getBytes())

它产生输出 用户名:1​​601663142:abcd1234 密码:Wi4H776QJCoFbe+/hgrvv7Pvv5te77+m776L776K776N77+Y77+UUQ==

我已经通过两种方式对此进行了测试 首先在chrome控制台下面的代码抛出异常

var iceConfiguration = {
    iceServers: [
        {
            urls: 'turn:127.0.0.1:3478',
            username: '1601663142:abcd1234',
            credentials: 'Wi4H776QJCoFbe+/hgrvv7Pvv5te77+m776L776K776N77+Y77+UUQ=='
        }

    ]
}

var peerConnection = new RTCPeerConnection(iceConfiguration);

Uncaught DOMException: Failed to construct 'RTCPeerConnection': Both username and credential are required when the URL scheme is "turn" or "turns".
    at <anonymous>:12:22
(anonymous) @ VM41:12

Tricle Ice

我怎样才能让它工作

【问题讨论】:

    标签: webrtc turn coturn rfc5766turnserver


    【解决方案1】:

    我认为答案很简单,您指定了credentials,错误是缺少credential,因此请删除s 并重试。

    【讨论】:

      猜你喜欢
      • 2018-09-11
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 2012-08-29
      • 2013-01-05
      • 2018-08-27
      相关资源
      最近更新 更多