Skip to content

Commit

Permalink
fix for AP2 password
Browse files Browse the repository at this point in the history
  • Loading branch information
vapormusic committed Jan 26, 2023
1 parent 544bbdb commit be3e126
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/rtsp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' +
Expand All @@ -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 + '", ' +
Expand All @@ -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() {
Expand Down Expand Up @@ -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'
Expand All @@ -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 = ''
//}
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down

0 comments on commit be3e126

Please sign in to comment.