【问题标题】:Why the coturn server returning 401: Unauthorized为什么 coturn 服务器返回 401:未经授权
【发布时间】:2021-02-20 14:15:36
【问题描述】:

我在 ubunto 16 上安装了 Coturn 服务器 目前我正在检查它

function checkTURNServer(turnConfig, timeout){ 

  return new Promise(function(resolve, reject){

    setTimeout(function(){
        if(promiseResolved) return;
        resolve(false);
        promiseResolved = true;
    }, timeout || 5000);

    var promiseResolved = false
      , myPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection   //compatibility for firefox and chrome
      , pc = new myPeerConnection({iceServers:[turnConfig]})
      , noop = function(){};
    pc.createDataChannel("");    //create a bogus data channel
    pc.createOffer(function(sdp){
      if(sdp.sdp.indexOf('typ relay') > -1){ // sometimes sdp contains the ice candidates...
        promiseResolved = true;
        resolve(true);
      }
      pc.setLocalDescription(sdp, noop, noop);
    }, noop);    // create offer and set local description
    pc.onicecandidate = function(ice){  //listen for candidate events
      if(promiseResolved || !ice || !ice.candidate || !ice.candidate.candidate || !(ice.candidate.candidate.indexOf('typ relay')>-1))  return;
      promiseResolved = true;
      resolve(true);
    };
  });   
}

const USERNAME="user"
const PASSWORD="password"
const PORT=3478
const IP="my_Coturn_server_ip" // you will have to change this

console.log('TURN server reachable on TCP?', await checkTURNServer( {
    url: `turn:${IP}:${PORT}?transport=tcp`,
    username: USERNAME,
    credential: PASSWORD,
}))

console.log('TURN server reachable on UDP?', await checkTURNServer( {
    url: `turn:${IP}:${PORT}?transport=udp`,
    username: USERNAME,
    credential: PASSWORD,
}))

每次我尝试检查时我都会在服务器中得到这个

14:会话 001000000000000001:领域用户 :传入数据包 BINDING 进程 ed,成功 14:会话 001000000000000001:领域用户 :传入数据包消息处理,错误 401:未经授权 14:IPv4。本地中继地址:my_Coturn_server_ip:57906 14:会话 001000000000000001:新,领域 =,用户名 =,生命周期 = 600 14:会话 001000000000000001:领域用户:传入数据包分配已处理,成功 24:会话 000000000000000001:领域用户:传入数据包绑定处理,成功

为什么返回 401 ? 我如何在没有身份验证的情况下向公众开放服务器?

【问题讨论】:

    标签: ubuntu realm coturn


    【解决方案1】:

    401 只是摘要认证的一部分:客户端发送的第一个 Allocate 请求没有认证数据。

    服务器使用 401 挑战分配请求,提供领域和随机数。

    客户端然后使用领域、随机数、用户名和密码来计算身份验证密钥并再次发送分配请求,得到分配成功响应。

    完整流程在https://www.rfc-editor.org/rfc/rfc8656中解释

    一般而言,未经身份验证的 TURN 服务器不会向公众开放使用,因为它们的使用是资源密集型的并且可能变得非常昂贵。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-19
      • 2012-02-23
      • 2016-01-17
      • 2012-03-14
      • 2022-11-08
      • 2023-03-09
      相关资源
      最近更新 更多