TURN服务器,以实现WebRTC使用REST API认证 [英] TURN server for WebRTC with REST API authentication

查看:4051
本文介绍了TURN服务器,以实现WebRTC使用REST API认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从的此处
(:MY_PASSWORD my_user_name)我使用的是 turnuserdb.conf 文件,其中我有我的用户名和密码是能够通过这个TURN服务器成功转发我的视频。
而在网络客户端我用:

 iceServers:{[
    URL:转:my_user_name,@ turn_server_ip
    凭据:MY_PASSWORD
}]

我试图使用与TURN服务器来避免通过网络发送密码,或将其存储在客户端的REST API功能。
我跟着该规范并的下的REST API这样的解释

然而不幸的是我得到的 401 ,我不能进行身份验证。

下面是我所做的正是:


  1. 我创建了一个秘密my_secret,我跑交替服务器是这样的:

      turnserver -v --syslog -a -L xx.xxx.xx.xx -X yy.yyy.yyy.yy -E zz.zzz.zz.zzz --max -bps = 3000000 -f -m 3 --min端口= 32355 --max端口= 65535 --use-auth的秘密--static-auth的秘密= my_secret --realm = north.gov --cert = turn_server_cert.pem --pkey = turn_server_pkey.pem --log文件=标准输出-q 100 -Q 300 --cipher列表= ALL

    (我刚刚替换 xx.xxx.xx.xx yy.yyy.yyy.yy zz.zzz.zz.zzz


  2. 后来,我产生一个时间戳,这将是现在+ 1小时,使我跑的NodeJS:

      Date.now()+ 1000 * 60 * 60; //输出1433895918506。

    我产生在本网站
    用我的秘密,并得到了结果 0ca57806bdc696b3129d4cad83746945b00af77b


  3. 我带codeD密码的的base64


  4. 现在我试图登录与Web客户端使用临时用户名之交服务器进行通信: 1433895918506:my_user_name 和密码: MGNhNTc4MDZiZGM2OTZiMzEyOWQ0Y2FkODM3NDY5NDViMDBhZjc3Yg == ,Web客户端上,现在我用

    <$p$p><$c$c>\"iceServers\":\"url\":\"turn:1433895918506:my_user_name@turn_server_ip\",\"credential\":\"MGNhNTc4MDZiZGM2OTZiMzEyOWQ0Y2FkODM3NDY5NDViMDBhZjc3Yg==\"}]


但它不工作,我得到:

  401用户LT; 1433895918506:my_user_name&GT;处理传入的数据包信息,错误401:未经授权。

您可以帮我找出什么是错的?


解决方案

当我产生的凭证与您的姓名和秘密,我的 1Dj9XZ5fwvKS6YoQZOoORcFnXaI = 不是 MGNhNTc4MDZiZGM2OTZiMzEyOWQ0Y2FkODM3NDY5NDViMDBhZjc3Yg == ,请检查你的算法/ code错误。

和时间在 Unix时间戳,所以在几秒钟内,而不是毫秒像你一样(虽然这应该不会影响,但只是使您的凭据永不过期)

检查您的系统并在TURN服务器所运行的系统,时钟是同步的(除了至少不是天),而在一般情况下,为了避免时钟问题同步不是,最好使用TTL为24小时,让你的时间戳:

 时间戳= parseInt函数(Date.now()/ 1000)+ 24 * 3600

在code产生TURN凭据:

  VAR密码=要求('密码');功能getTURNCredentials(姓名,密码){    VAR unixTimeStamp = parseInt函数(Date.now()/ 1000)+ 24 * 3600,
        用户名= [unixTimeStamp,名字]。加入(':'),
        密码,
        HMAC = crypto.createHmac(SHA1,秘密);
    hmac.setEncoding('的base64');
    hmac.write(用户名);
    hmac.end();
    密码= hmac.read();
    返回{
        用户名:用​​户名,
        密码:密码
    };
}

I'm trying to set up the rfc5766-turn-server TURN server for webRTC from here. I was able to successfully relay my video through this TURN server using a turnuserdb.conf file where I have my username and password (my_user_name:my_password). And on the web client side I used:

"iceServers":{[
    "url": "turn:my_user_name,@turn_server_ip",
    "credential":"my_password"
}]

I'm trying to use the REST API feature that comes with the TURN server to avoid sending the password over the network or storing it on the client side. I followed this spec and this explanation under the Rest API

However unfortunately I get a 401 and I cannot authenticate.

Here's what I did exactly:

  1. I created a secret "my_secret" and I ran the turn server like this:

    turnserver -v --syslog -a -L xx.xxx.xx.xx -X yy.yyy.yyy.yy -E zz.zzz.zz.zzz --max-bps=3000000 -f -m 3 --min-port=32355 --max-port=65535 --use-auth-secret --static-auth-secret=my_secret --realm=north.gov --cert=turn_server_cert.pem --pkey=turn_server_pkey.pem --log-file=stdout -q 100 -Q 300 --cipher-list=ALL
    

    (I just replaced the IP address with xx.xxx.xx.xx yy.yyy.yyy.yy zz.zzz.zz.zzz)

  2. Later I generated a timestamp that would be now + 1 hour so I ran on nodejs:

    Date.now()+1000*60*60;      // output 1433895918506.
    

    I generated the temporary password on this website, Using my secret, and got a result 0ca57806bdc696b3129d4cad83746945b00af77b

  3. I encoded the password to base64.

  4. Now I tried to log communicate with the turn server from the web client using the temporary username : 1433895918506:my_user_name and password: MGNhNTc4MDZiZGM2OTZiMzEyOWQ0Y2FkODM3NDY5NDViMDBhZjc3Yg==, on the web client now I use

    "iceServers":"url":"turn:1433895918506:my_user_name@turn_server_ip","credential":"MGNhNTc4MDZiZGM2OTZiMzEyOWQ0Y2FkODM3NDY5NDViMDBhZjc3Yg=="}]
    

But it doesn't work, I get:

401 user <1433895918506:my_user_name>  incoming packet message processed, error 401: Unauthorised.

Can you help me figure out what's wrong?

解决方案

when I generated credential with your name and secret, I got 1Dj9XZ5fwvKS6YoQZOoORcFnXaI= not MGNhNTc4MDZiZGM2OTZiMzEyOWQ0Y2FkODM3NDY5NDViMDBhZjc3Yg==, check your algorithm/code for errors.

and the time is in Unix Timestamp, so in seconds and not milliseconds as you did( though this should not affect, but just makes your credentials never expire)

check if your system and the system where the TURN server is running, the clocks are in sync( at least not days apart), and in general, to avoid issue of clocks not being in sync, better to use ttl as 24 hours, so your timestamp:

timestamp=  parseInt(Date.now()/1000) + 24*3600

the code for generating TURN credential:

var crypto = require('crypto');

function getTURNCredentials(name, secret){    

    var unixTimeStamp = parseInt(Date.now()/1000) + 24*3600,
        username = [unixTimeStamp, name].join(':'),
        password,
        hmac = crypto.createHmac('sha1', secret);
    hmac.setEncoding('base64');
    hmac.write(username);
    hmac.end();
    password = hmac.read();
    return {
        username: username,
        password: password
    };
}

这篇关于TURN服务器,以实现WebRTC使用REST API认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆