我正在尝试使用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 (例如user/pass的连接)和$key (例如realm)中会包含什么值呢?
还有一个turn_secret表列出了一个领域的“值”,我猜这应该用作上面例子中的$key,但是添加和修改键仍然会在我调用turnadmin时得到相同的结果。
本质上,我想做的是(伪代码):
// 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找出谁在和谁说话?
发布于 2017-06-02 18:49:58
在RFC 5389中描述了如何构建HMAC密钥。
领域密钥=MD5(用户名":“
":”SASLprep(密码))
其中MD5在RFC 1321中定义,SASLprep()在RFC 4013中定义
您唯一需要更新的表是turnusers_lt。使用turn_secret表和SHA1算法生成time-limited credentials。
INSERT INTO turnusers_lt (realm, name, hmackey) VALUES (:realm, :username, :key);当然,请使用准备好的语句,而不是手动构建SQL字符串。
发布于 2018-10-12 00:22:02
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")
;https://stackoverflow.com/questions/38801156
复制相似问题