基于身份验证机密,使用TURN REST API标志use-auth-secret进行WebRTC / Coturn身份验证

问题描述

我正在玩这个游戏,它能够使用Node / Javascript立即使它工作,花了一段时间使用Golang(这只是生成要发送给coturn的用户/密码。)在API JS / Go端。

coturn上的配置:/etc/turnserver.conf

listening-port=443
tls-listening-port=443
listening-ip=10.100.0.2
relay-ip=10.100.0.2
external-ip=123.456.78.9
min-port=10000
max-port=20000
verbose
fingerprint
lt-cred-mech
server-name=myserver
realm=myserver
cert=/etc/SSL/fullchain.pem
pkey=/etc/SSL/privkey.pem
log-file=/var/log/turnserver.log
use-auth-secret
static-auth-secret=MySecret

以下是Node / Js实施API(可从其他地方复制-可以使用):

var crypto = require('crypto');
var unixTimeStamp = parseInt(Date.now()/1000) + 24*3600,// this credential valid for 24 hours
    TempUser = [unixTimeStamp,"SomeUser"].join(':'),TempPassword,hmac = crypto.createHmac('sha1',"MySecret");
hmac.setEncoding('base64');
hmac.write(TempUser);
hmac.end();
TempPassword = hmac.read();

以下是GOLANG实施API(花了一段时间):

UserId := "SomeUser" 
// This worked,returned the exact seconds
timestamp := strconv.FormatInt(time.Now().UTC().Unix()+24*3600,10)
// Example: The above is 1602692130
secret := "MySecret"
TempUser := timestamp + ":" + UserId  // For API Auth,coturn expects this format,the timestamp is the expiry date of the final temp user/password.

// Create a new HMAC by defining the hash type and the key (as byte array)
//h := hmac.New(sha256.New,[]byte(secret))   // sha256 does not work,use sha1
h := hmac.New(sha1.New,[]byte(secret))    

h.Write([]byte(TempUser))

//sha := b64.URLEncoding.EncodeToString(h.Sum(nil))  // URLEncoding did not work
TempPassword := b64.StdEncoding.EncodeToString(h.Sum(nil)) // StdEncoding worked

Webrtc客户端上的JS。注意,我们在这里使用TempUser和TempPassword发送给Coturn。

    ...
 const stunUrl = 'stun:mystun_server',turnUsername = TempUser,turnPassword = TempPassword,...
        'iceServers': [
            { 'url': stunUrl },{
                'urls': turnUrl1,'username': turnUsername,'credential': turnPassword
            },

现在,coturn将使用上面的TempUser和TempPassword进行身份验证。希望有人会发现这个有用。谢谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...