【问题标题】:Manually insert TURN users (Coturn) into a database手动将 TURN 用户 (Coturn) 插入数据库
【发布时间】:2016-12-12 13:45:03
【问题描述】:

我正在尝试为使用 Coturn 的项目设置 TURN 服务器,但我发现文档充其量只是粗略...

我知道有一个turnadmin 工具可以为您完成这项工作,但我更愿意直接在我的数据库上运行查询。这是一个可能有许多用户的应用程序,他们的共享密钥(turnusers_lt 中的hmackey)可能会更改(为了不与应用程序共享密码,该应用程序使用“假”密码,该密码是某些易失性的哈希不那么秘密的用户参数)。

我可以从很少的文档中收集到 hmackey 是使用领域、用户名和密码计算出来的:

$ turnadmin -k -u myusername -r my.realm.org -p my-password
> e.g. 0x7a69b0e2b747a4560045f79d171b78c0

鉴于我的代码会知道这三个参数,我该如何构建 hmac 哈希?例如。在 PHP 我有

string hash_hmac ( string $algo , string $data , string $key [, bool $raw_output = false ] )

$algo 这里应该是 SHA1,但是什么值会进入 $data(例如用户/密码的 concat)和 $key(例如领域)?

还有一个turn_secret 表列出了一个领域的“值”,我猜这应该用作上面示例中的$key,但是当我调用时添加和修改键仍然会给出相同的结果转管理员。

本质上,我想做的是(伪代码):

// user registers
// pseudo-code, this is of course computed using php's password_hash function
$hashed_pw = hash($pw);
$db->query('insert into usertable (name, pass) values ($name, $hashed_pw)');

// this is implemented somewhere...
$coturn_pw = get_secret_hash($name);

// this needs implementing...
$HAMC = calc_hmac($name, $coturn_pw, 'my.realm.com');

$turndb->query('insert into turnusers_lt values (...)');

// on update, delete also update turnusers_lt

...然后在客户端中,我现在应该能够使用$name$coturn_pw 作为my.realm.com 的凭据连接到TURN 服务器。

还是我想太多了,我应该只为我的应用使用一个通用用户,硬编码密码,然后让 Coturn 弄清楚谁在和谁说话?

【问题讨论】:

    标签: stun turn coturn


    【解决方案1】:

    如何构建 HMAC 密钥在 RFC 5389 中描述:

    key = MD5(username ":" realm ":" SASLprep(password))

    MD5 在RFC 1321 中定义,SASLprep() 在RFC 4013 中定义

    您需要更新的唯一表是turnusers_ltturn_secret 表和 SHA1 算法用于生成time-limited credentials

    INSERT INTO turnusers_lt (realm, name, hmackey) VALUES (:realm, :username, :key);
    

    当然,使用准备好的语句而不是手动构建 SQL 字符串。

    【讨论】:

      【解决方案2】:

      OrangeDog 的答案是正确的。

      使用 node.js:

      const crypto= require("crypto");
      
      const username= "foo";
      const realm= "here";
      const password= "secret";
      
      const hmac = crypto
              .createHash("md5")
              .update(`${username}:${realm}:${password}`)
              .digest("hex")
      ;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-06-16
        • 2019-12-15
        • 1970-01-01
        • 2017-10-23
        • 2018-09-09
        • 1970-01-01
        • 2022-01-20
        • 1970-01-01
        相关资源
        最近更新 更多