drachtio-srf 4.5.37 → 4.5.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/digest-client.js +23 -14
- package/lib/drachtio-agent.js +3 -2
- package/package.json +1 -1
package/lib/digest-client.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
const crypto = require('crypto');
|
|
2
2
|
|
|
3
|
+
function parseTransportToken(sipString) {
|
|
4
|
+
if (sipString) {
|
|
5
|
+
const match = sipString.match(/;transport=([^;\s]+)/i);
|
|
6
|
+
if (match) return match[1].toLowerCase();
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
3
10
|
module.exports = class DigestClient {
|
|
4
11
|
|
|
5
12
|
constructor(res) {
|
|
@@ -31,17 +38,17 @@ module.exports = class DigestClient {
|
|
|
31
38
|
return callback(err);
|
|
32
39
|
}
|
|
33
40
|
|
|
34
|
-
|
|
35
|
-
|
|
41
|
+
const header = this.res.statusCode === 407 ? 'proxy-authenticate' : 'www-authenticate' ;
|
|
42
|
+
const challenge = this._parseChallenge(this.res.get(header));
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
const ha1 = crypto.createHash('md5');
|
|
38
45
|
ha1.update([username, challenge.realm, password].join(':'));
|
|
39
|
-
|
|
46
|
+
const ha2 = crypto.createHash('md5');
|
|
40
47
|
ha2.update([options.method, options.uri].join(':'));
|
|
41
48
|
|
|
42
49
|
// bump CSeq and preserve Call-Id
|
|
43
|
-
|
|
44
|
-
|
|
50
|
+
const headers = options.headers || {};
|
|
51
|
+
let seq = this.req.getParsedHeader('cseq').seq ;
|
|
45
52
|
seq++ ;
|
|
46
53
|
headers['CSeq'] = '' + seq + ' ' + this.req.method ;
|
|
47
54
|
headers['call-id'] = this.req.get('call-id') ;
|
|
@@ -52,18 +59,18 @@ module.exports = class DigestClient {
|
|
|
52
59
|
|
|
53
60
|
|
|
54
61
|
// Generate cnonce
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
let cnonce = false;
|
|
63
|
+
let nc = false;
|
|
57
64
|
if (typeof challenge.qop === 'string') {
|
|
58
|
-
|
|
65
|
+
const cnonceHash = crypto.createHash('md5');
|
|
59
66
|
cnonceHash.update(Math.random().toString(36));
|
|
60
|
-
cnonce = cnonceHash.digest('hex').
|
|
67
|
+
cnonce = cnonceHash.digest('hex').slice(0, 8);
|
|
61
68
|
nc = this._updateNC();
|
|
62
69
|
}
|
|
63
70
|
|
|
64
71
|
// Generate response hash
|
|
65
|
-
|
|
66
|
-
|
|
72
|
+
const response = crypto.createHash('md5');
|
|
73
|
+
const responseParams = [
|
|
67
74
|
ha1.digest('hex'),
|
|
68
75
|
challenge.nonce
|
|
69
76
|
];
|
|
@@ -80,7 +87,7 @@ module.exports = class DigestClient {
|
|
|
80
87
|
response.update(responseParams.join(':'));
|
|
81
88
|
|
|
82
89
|
// Setup response parameters
|
|
83
|
-
|
|
90
|
+
const authParams = {
|
|
84
91
|
username: username,
|
|
85
92
|
realm: challenge.realm,
|
|
86
93
|
nonce: challenge.nonce,
|
|
@@ -105,7 +112,9 @@ module.exports = class DigestClient {
|
|
|
105
112
|
// we want to send our credentialled request to the same server that challenged us
|
|
106
113
|
const originalUri = options.uri;
|
|
107
114
|
if (!originalUri.match(/sips?:[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)) {
|
|
108
|
-
const
|
|
115
|
+
const transport = parseTransportToken(options.proxy);
|
|
116
|
+
let proxy = originalUri.replace(/(sips*):[^;]*/, `$1:${this.res.source_address}:${this.res.source_port}`);
|
|
117
|
+
if (transport) proxy += `;transport=${transport}`;
|
|
109
118
|
Object.assign(options, {proxy});
|
|
110
119
|
}
|
|
111
120
|
this.agent.request(options, callback) ;
|
package/lib/drachtio-agent.js
CHANGED
|
@@ -526,16 +526,17 @@ class DrachtioAgent extends Emitter {
|
|
|
526
526
|
obj.ready = true ;
|
|
527
527
|
obj.hostport = response[1] ;
|
|
528
528
|
obj.serverVersion = response.length > 2 ? response[2] : null;
|
|
529
|
+
obj.localHostports = response.length > 3 ? response[3] : null;
|
|
529
530
|
debug('sucessfully authenticated, hostport is ', obj.hostport) ;
|
|
530
531
|
|
|
531
532
|
if (this.wp.isClient) {
|
|
532
533
|
this.routeVerbs(socket, obj) ;
|
|
533
534
|
setImmediate(() => {
|
|
534
|
-
this.emit('connect', null, obj.hostport, obj.serverVersion);
|
|
535
|
+
this.emit('connect', null, obj.hostport, obj.serverVersion, obj.localHostports);
|
|
535
536
|
});
|
|
536
537
|
}
|
|
537
538
|
else {
|
|
538
|
-
this.emit('connect', null, obj.hostport, obj.serverVersion);
|
|
539
|
+
this.emit('connect', null, obj.hostport, obj.serverVersion, obj.localHostports);
|
|
539
540
|
}
|
|
540
541
|
if (serverVersionAtLeast(obj.serverVersion, 'v0.8.2')) {
|
|
541
542
|
debug(`server version ${obj.serverVersion} supports pinging`);
|