From be3e1269c46d58f3728c073d03e6fc721f49670d Mon Sep 17 00:00:00 2001 From: vapormusic Date: Thu, 26 Jan 2023 22:37:03 +0700 Subject: [PATCH] fix for AP2 password --- lib/rtsp.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/rtsp.js b/lib/rtsp.js index 9953c8e..3aa056e 100644 --- a/lib/rtsp.js +++ b/lib/rtsp.js @@ -500,7 +500,7 @@ function md5norm(str) { return md5sum.digest('hex'); } -Client.prototype.makeHead = function(method, uri, di, clear = false) { +Client.prototype.makeHead = function(method, uri, di, clear = false, dimode = null) { var head = method + ' ' + uri + ' RTSP/1.0' + '\r\n' if (!clear){ head += 'CSeq: ' + this.nextCSeq() + '\r\n' + @@ -512,9 +512,14 @@ Client.prototype.makeHead = function(method, uri, di, clear = false) { }; if(di) { + if (dimode == 'airplay2') { + var ha1 = md5norm(di.username + ':' + di.realm + ':' + di.password); + var ha2 = md5norm(method + ':' + uri); + var diResponse = md5(ha1 + ':' + di.nonce + ':' + ha2); + } else { var ha1 = md5(di.username + ':' + di.realm + ':' + di.password); var ha2 = md5(method + ':' + uri); - var diResponse = md5(ha1 + ':' + di.nonce + ':' + ha2); + var diResponse = md5(ha1 + ':' + di.nonce + ':' + ha2);} head += 'Authorization: Digest ' + 'username="' + di.username + '", ' + @@ -527,8 +532,8 @@ Client.prototype.makeHead = function(method, uri, di, clear = false) { return head; } -Client.prototype.makeHeadWithURL = function(method, digestInfo) { - return this.makeHead(method, 'rtsp://' + this.socket.address().address + '/' + this.announceId, digestInfo); +Client.prototype.makeHeadWithURL = function(method, digestInfo, dimode) { + return this.makeHead(method, 'rtsp://' + this.socket.address().address + '/' + this.announceId, digestInfo, false, dimode); } Client.prototype.makeRtpInfo = function() { @@ -566,7 +571,7 @@ Client.prototype.sendNextRequest = async function(di) { // (this.status = PAIR_SETUP_1) // this.sendNextRequest(); // } else { - if (this.needPin || this.airplay2){ + if (this.needPin || (this.airplay2 != null && this.password == null)){ request += this.makeHead("POST","/pair-pin-start", "", true); if (this.airplay2){ request += 'User-Agent: AirPlay/409.16\r\n' @@ -576,8 +581,16 @@ Client.prototype.sendNextRequest = async function(di) { request += 'Content-Length:' + 0 + '\r\n\r\n'; this.socket.write(Buffer.from(request, 'utf-8'))} else { - this.emit('need_password'); - this.status = this.airplay2 ? INFO: PAIR_PIN_SETUP_1; + console.log("pass",this.password); + if (this.password) { + this.status = this.airplay2 ? PAIR_SETUP_1 : PAIR_PIN_SETUP_1; + console.log("pass2",this.password); + this.sendNextRequest(); + } else { + this.emit('need_password'); + this.status = this.airplay2 ? INFO: PAIR_PIN_SETUP_1; + this.sendNextRequest(); + } } request = '' //} @@ -899,7 +912,7 @@ Client.prototype.sendNextRequest = async function(di) { case SETUP_AP2_1: if (this.announceId == null) { this.announceId = nu.randomInt(10);} - request += this.makeHeadWithURL('SETUP', di); + request += this.makeHeadWithURL('SETUP', di, "airplay2"); request += 'Content-Type: application/x-apple-binary-plist\r\n' // request += 'CSeq: ' + this.nextCSeq() + '\r\n' ; // this.timingPort = 32325; @@ -914,6 +927,7 @@ Client.prototype.sendNextRequest = async function(di) { } ) ; + try{this.timingsocket.close();} catch(e){} this.timingsocket = dgram.createSocket('udp4'); var self = this; this.timingsocket.on('message', function(msg, rinfo) {