提交 b13a9214 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

- Include mediasoup.extra module with user utils.

上级 3ebf4d12
......@@ -16,7 +16,7 @@
"maxparams": 6,
"maxdepth": 4,
"maxstatements": false,
"maxlen": 200,
"maxlen": 300,
"proto": true,
"sub": false,
"browser": false,
......
'use strict';
module.exports =
{
/**
* Generate a raw DTLS fingerprint
* @param {String} sdpFingerprint SDP fingerprint (uppercase with colons)
* @return {String} Raw fingerprint (lowercase without colons)
*/
dtlsFingerprintFromSDP: (sdpFingerprint) =>
{
if (typeof sdpFingerprint !== 'string' || !sdpFingerprint)
throw new TypeError('wrong argument');
return sdpFingerprint
.replace(/:/g, '')
.toLowerCase();
},
/**
* Generate a SDP DTLS fingerprint
* @param {String} rawFingerprint Raw fingerprint (lowercase without colons)
* @return {String} SDP fingerprint (uppercase with colons)
*/
dtlsFingerprintToSDP: (rawFingerprint) =>
{
if (typeof rawFingerprint !== 'string' || !rawFingerprint)
throw new TypeError('wrong argument');
return rawFingerprint
.replace(/../g, (xx) => xx + ':')
.toUpperCase()
.slice(0, -1);
}
};
......@@ -5,6 +5,7 @@ const process = require('process');
const logger = require('./logger')();
const utils = require('./utils');
const Server = require('./Server');
const extra = require('./extra');
// Set of Server instances
let servers = new Set();
......@@ -46,7 +47,12 @@ module.exports =
server.on('close', () => servers.delete(server));
return server;
}
},
/**
* Export the extra module
*/
extra: extra
};
// On process exit close all the Servers
......
'use strict';
const tap = require('tap');
const extra = require('../').extra;
const sdpFingerprint1 = '75:1B:81:93:B7:ED:27:7E:42:BE:D6:C4:8E:F7:04:3A:49:CE:3F:EE';
const rawFingerprint1 = '751b8193b7ed277e42bed6c48ef7043a49ce3fee';
const sdpFingerprint2 = '46:6D:6F:3D:09:A6:19:B2:27:C3:37:08:A7:CD:91:AE:0F:67:C4:BB:9A:A7:97:FD:40:BA:DF:3B:2C:C2:38:8A:38:5F:61:C2:A6:70:01:0C:7F:4D:C6:27:FF:31:5A:20:21:4B:F2:1D:B5:60:E2:4A:2E:67:31:B2:B0:2D:48:47';
const rawFingerprint2 = '466d6f3d09a619b227c33708a7cd91ae0f67c4bb9aa797fd40badf3b2cc2388a385f61c2a670010c7f4dc627ff315a20214bf21db560e24a2e6731b2b02d4847';
tap.test('extra.dtlsFingerprintFromSDP()', { timeout: 1000 }, (t) =>
{
t.equal(extra.dtlsFingerprintFromSDP(sdpFingerprint1), rawFingerprint1);
t.equal(extra.dtlsFingerprintFromSDP(sdpFingerprint2), rawFingerprint2);
t.end();
});
tap.test('extra.dtlsFingerprintToSDP()', { timeout: 1000 }, (t) =>
{
t.equal(extra.dtlsFingerprintToSDP(rawFingerprint1), sdpFingerprint1);
t.equal(extra.dtlsFingerprintToSDP(rawFingerprint2), sdpFingerprint2);
t.end();
});
......@@ -144,11 +144,10 @@ app.put('/test-transport', function(req)
am.candidates.push(ac);
});
// TODO: get it from transport
am.fingerprint =
{
hash : '00:56:63:99:13:26:02:50:DA:F4:46:79:F7:9D:66:82:5A:90:A8:B2:35:9F:19:14:8D:6C:D4:7C:17:C7:BF:70',
type : 'sha-256'
type : 'sha-256',
hash : mediasoup.extra.dtlsFingerprintToSDP(transport.dtlsLocalFingerprints['sha-256'])
};
am.setup = 'passive';
am.type = om.type;
......
......@@ -119,6 +119,7 @@ namespace RTC
BIO* sslBioToNetwork = nullptr; // The BIO in which ssl writes.
Timer* timer = nullptr;
// Others.
// TODO: rename to localRole
DTLSRole role = DTLSRole::NONE;
FingerprintHash remoteFingerprintHash = FingerprintHash::NONE;
std::string remoteFingerprint;
......
......@@ -4,7 +4,7 @@
/* Class variables. */
std::string Logger::id;
std::string Logger::id = "undefined";
Channel::UnixStreamSocket* Logger::channel = nullptr;
char Logger::buffer[MS_LOGGER_BUFFER_SIZE];
......
......@@ -63,7 +63,7 @@ namespace RTC
X509* DTLSAgent::certificate = nullptr;
EVP_PKEY* DTLSAgent::privateKey = nullptr;
SSL_CTX* DTLSAgent::sslCtx = nullptr;
Json::Value DTLSAgent::localFingerprints = Json::Value(Json::arrayValue);
Json::Value DTLSAgent::localFingerprints = Json::Value(Json::objectValue);
DTLSAgent::SRTPProfiles DTLSAgent::srtpProfiles =
{
{ RTC::SRTPSession::SRTPProfile::AES_CM_128_HMAC_SHA1_80, "SRTP_AES128_CM_SHA1_80" },
......@@ -423,10 +423,8 @@ namespace RTC
unsigned char binary_fingerprint[EVP_MAX_MD_SIZE];
unsigned int size = 0;
char hex_fingerprint[(EVP_MAX_MD_SIZE * 2) + 1];
char hex_fingerprint_sdp[(EVP_MAX_MD_SIZE * 3) + 1];
const EVP_MD* hash_function;
int ret;
Json::Value jsonFingerprint;
switch (hash)
{
......@@ -470,19 +468,8 @@ namespace RTC
MS_DEBUG("%-7s fingerprint: %s", hash_str.c_str(), hex_fingerprint);
// Convert to hexadecimal SDP format in uppercase with colons.
for (unsigned int i = 0; i < size; i++)
{
std::sprintf(hex_fingerprint_sdp + (i * 3), "%.2X:", binary_fingerprint[i]);
}
// NOTE: The -1 removes the last ":".
hex_fingerprint_sdp[(size * 3) - 1] = '\0';
// Store in the JSON.
jsonFingerprint["algorithm"] = hash_str;
jsonFingerprint["value"] = hex_fingerprint;
jsonFingerprint["valueForSDP"] = hex_fingerprint_sdp;
DTLSAgent::localFingerprints.append(jsonFingerprint);
DTLSAgent::localFingerprints[hash_str] = hex_fingerprint;
}
}
......@@ -974,7 +961,6 @@ namespace RTC
MS_ASSERT(this->remoteFingerprintHash != FingerprintHash::NONE, "remote fingerprint not set");
X509* certificate;
std::string hash_str;
unsigned char binary_fingerprint[EVP_MAX_MD_SIZE];
unsigned int size = 0;
char hex_fingerprint[(EVP_MAX_MD_SIZE * 2) + 1];
......@@ -992,23 +978,18 @@ namespace RTC
{
case FingerprintHash::SHA1:
hash_function = EVP_sha1();
hash_str = "sha-1";
break;
case FingerprintHash::SHA224:
hash_function = EVP_sha224();
hash_str = "sha-224";
break;
case FingerprintHash::SHA256:
hash_function = EVP_sha256();
hash_str = "sha-256";
break;
case FingerprintHash::SHA384:
hash_function = EVP_sha384();
hash_str = "sha-384";
break;
case FingerprintHash::SHA512:
hash_function = EVP_sha512();
hash_str = "sha-512";
break;
default:
MS_ABORT("unknown hash");
......@@ -1038,7 +1019,8 @@ namespace RTC
}
// TODO: remove
MS_DEBUG("valid remote %-7s fingerprint: %s", hash_str.c_str(), hex_fingerprint);
MS_DEBUG("valid remote fingerprint");
return true;
}
......
......@@ -203,6 +203,7 @@ namespace RTC
case Channel::Request::MethodId::transport_close:
case Channel::Request::MethodId::transport_dump:
case Channel::Request::MethodId::transport_start:
{
RTC::Transport* transport;
......
......@@ -289,6 +289,13 @@ namespace RTC
break;
}
case Channel::Request::MethodId::transport_start:
{
// TODO
break;
}
default:
{
MS_ABORT("unknown method");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论