Fixed Web Power Switch nonce counter

This commit is contained in:
Ylian Saint-Hilaire 2022-01-06 15:21:55 -08:00
parent c10964d892
commit 606c8d2d7b

View File

@ -756,6 +756,7 @@ function CreateWebPowerSwitch(parent, hostname, port, username, password) {
var retryTimer = null; var retryTimer = null;
var challenge = null; var challenge = null;
var challengeRetry = 0; var challengeRetry = 0;
var nonceCounter = 1;
obj.state = 0; // 0 = Disconnected, 1 = Connecting, 2 = Connected obj.state = 0; // 0 = Disconnected, 1 = Connecting, 2 = Connected
obj.ports = []; obj.ports = [];
@ -872,7 +873,7 @@ function CreateWebPowerSwitch(parent, hostname, port, username, password) {
if (challenge != null) { if (challenge != null) {
const buf = Buffer.alloc(10); const buf = Buffer.alloc(10);
challenge.cnonce = crypto.randomFillSync(buf).toString('hex'); challenge.cnonce = crypto.randomFillSync(buf).toString('hex');
challenge.nc = '00000001'; challenge.nc = nonceCounter++;
const ha1 = crypto.createHash('md5'); const ha1 = crypto.createHash('md5');
ha1.update([username, challenge.realm, password].join(':')); ha1.update([username, challenge.realm, password].join(':'));
var xha1 = ha1.digest('hex') var xha1 = ha1.digest('hex')
@ -886,7 +887,7 @@ function CreateWebPowerSwitch(parent, hostname, port, username, password) {
"realm": challenge.realm, "realm": challenge.realm,
"nonce": challenge.nonce, "nonce": challenge.nonce,
"uri": options.path, "uri": options.path,
"response": response.digest("hex"), "response": response.digest('hex'),
"cnonce": challenge.cnonce, "cnonce": challenge.cnonce,
"opaque": challenge.opaque "opaque": challenge.opaque
}; };