Added AMT startConfigurationHBased() MEI call.
Ylian Saint-Hilaire committed
Mar 3, 2021 at 15:52 UTC
cfb9af86098d60f8187ffa1a82e79e8c0bda20d9
2 files changed
+49
-17
agents/modules_meshcmd/amt-mei.js
+30
@@ -419,6 +419,36 @@ function amt_heci() {
419
420
}, this, callback, optional);
421
}
422
+ this.startConfigurationHBased = function startConfigurationHBased(certHash, hostVpn, dnsSuffixList, callback) {
423
+ if ((certHash == null) || ((certHash.length != 32) && (certHash.length != 48))) { throw "Bad certHash"; }
424
+
425
+ var optional = [];
426
+ for (var i = 4; i < arguments.length; ++i) { optional.push(arguments[i]); }
427
+
428
+ // Format the command
429
+ var data = Buffer.alloc(4 + 64 + 4 + 4 + 320);
430
+ data.writeUInt32LE((certHash.length == 48) ? 3 : 2, 0); // Write certificate hash type: SHA256 = 2, SHA384 = 3
431
+ certHash.copy(data, 4); // Write the hash
432
+ data.writeUInt32LE(hostVpn ? 1 : 0, 68); // Write is HostVPN is enabled
433
+ if (dnsSuffixList != null) {
434
+ data.writeUInt32LE(dnsSuffixList.length, 72); // Write the number of DNS Suffix, from 0 to 4
435
+ var ptr = 76;
436
+ for (var i = 0; i < dnsSuffixList.length; i++) { ptr += data.write(dnsSuffixList[i], ptr) + 1; } // Write up to 4 DNS Suffix with null seperation.
437
+ }
438
+
439
+ // Send the command
440
+ this.sendCommand(139, data, function (header, fn, opt) {
441
+ if (header.Status == 0) {
442
+ var amtHash = null;
443
+ if (header.Data[0] == 2) { amtHash = header.Data.slice(1, 33); } // SHA256
444
+ if (header.Data[0] == 3) { amtHash = header.Data.slice(1, 49); } // SHA384
445
+ opt.unshift({ status: header.Status, hash: amtHash });
446
+ } else {
447
+ opt.unshift({ status: header.Status });
448
+ }
449
+ fn.apply(this, opt);
450
+ }, callback, optional);
451
+ }
452
}
453
454
module.exports = amt_heci;
\ No newline at end of file
agents/modules_meshcore/amt-mei.js
+19
-17
@@ -420,30 +420,32 @@ function amt_heci() {
420
}, this, callback, optional);
421
}
422
this.startConfigurationHBased = function startConfigurationHBased(certHash, hostVpn, dnsSuffixList, callback) {
423
+ if ((certHash == null) || ((certHash.length != 32) && (certHash.length != 48))) { throw "Bad certHash"; }
424
+
425
var optional = [];
426
for (var i = 4; i < arguments.length; ++i) { optional.push(arguments[i]); }
427
428
+ // Format the command
429
var data = Buffer.alloc(4 + 64 + 4 + 4 + 320);
427
- data.writeUInt32LE((certHash.length == 48) ? 3 : 2, 0); // Write certificate hash: SHA256 = 2, SHA384 = 3
428
- data.write(certHash, 4); // Write the hash
429
- data.writeUInt32LE(hostVpn ? 1 : 0, 68);
430
- data.writeUInt32LE(0, 72); // dnsSuffixList.length
431
- // TODO: Write up to 4 DNS Suffix with null seperation.
432
-
433
- console.log('Sending', data.toString('hex'));
430
+ data.writeUInt32LE((certHash.length == 48) ? 3 : 2, 0); // Write certificate hash type: SHA256 = 2, SHA384 = 3
431
+ certHash.copy(data, 4); // Write the hash
432
+ data.writeUInt32LE(hostVpn ? 1 : 0, 68); // Write is HostVPN is enabled
433
+ if (dnsSuffixList != null) {
434
+ data.writeUInt32LE(dnsSuffixList.length, 72); // Write the number of DNS Suffix, from 0 to 4
435
+ var ptr = 76;
436
+ for (var i = 0; i < dnsSuffixList.length; i++) { ptr += data.write(dnsSuffixList[i], ptr) + 1; } // Write up to 4 DNS Suffix with null seperation.
437
+ }
438
439
+ // Send the command
440
this.sendCommand(139, data, function (header, fn, opt) {
436
- console.log('Status', header.Status);
437
- console.log('DataLength', header.Data.length);
438
- console.log('Data', header.Data.toString('hex'));
439
- /*
440
- if (header.Status == 0 && header.Data.length == 68) {
441
- opt.unshift({ user: trim(header.Data.slice(0, 33).toString()), pass: trim(header.Data.slice(33, 67).toString()), raw: header.Data });
442
- }
443
- else {
444
- opt.unshift(null);
441
+ if (header.Status == 0) {
442
+ var amtHash = null;
443
+ if (header.Data[0] == 2) { amtHash = header.Data.slice(1, 33); } // SHA256
444
+ if (header.Data[0] == 3) { amtHash = header.Data.slice(1, 49); } // SHA384
445
+ opt.unshift({ status: header.Status, hash: amtHash });
446
+ } else {
447
+ opt.unshift({ status: header.Status });
448
}
446
- */
449
fn.apply(this, opt);
450
}, callback, optional);
451
}