Added TLS support within CIRA, WSMAN stack improvements.
Ylian Saint-Hilaire committed
Oct 14, 2020 at 12:01 UTC
fd6e0f99128e10a7582a8bff5f6707436c9b2c8d
8 files changed
+171
-300
amt/amt-ider-module.js
+25
-4
@@ -1,9 +1,30 @@
1
-/**
2
-* @description IDER Handling Module
3
-* @author Ylian Saint-Hilaire
4
-* @version v0.0.2
1
+/*
2
+Copyright 2020 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+@description Intel AMT IDER module
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
21
+/*jslint node: true */
22
+/*jshint node: true */
23
+/*jshint strict:false */
24
+/*jshint -W097 */
25
+/*jshint esversion: 6 */
26
+"use strict";
27
+
28
// Construct a Intel AMT IDER object
29
module.exports.CreateAmtRemoteIder = function (webserver, meshcentral) {
30
const fs = require('fs');
amt/amt-ider.js
+18
-6
@@ -1,9 +1,21 @@
1
-/**
2
-* @description MeshCentral Server IDER handler
3
-* @author Ylian Saint-Hilaire & Bryan Roe
4
-* @copyright Intel Corporation 2018-2020
5
-* @license Apache-2.0
6
-* @version v0.0.1
1
+/*
2
+Copyright 2020 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+@description MeshCentral Server IDER handler
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
21
/*jslint node: true */
amt/amt-redir-mesh.js
+25
-4
@@ -1,9 +1,30 @@
1
-/**
2
-* @description Intel AMT Redirection Transport Module - using Node
3
-* @author Ylian Saint-Hilaire
4
-* @version v0.0.1f
1
+/*
2
+Copyright 2020 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+@description Intel AMT redirection stack
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
21
+/*jslint node: true */
22
+/*jshint node: true */
23
+/*jshint strict:false */
24
+/*jshint -W097 */
25
+/*jshint esversion: 6 */
26
+"use strict";
27
+
28
// Construct a MeshServer object
29
module.exports.CreateAmtRedirect = function (module, domain, user, webserver, meshcentral) {
30
var obj = {};
amt/amt-wsman-comm.js
+44
-257
@@ -1,10 +1,31 @@
1
-/** m
2
-* @description Intel(r) AMT WSMAN communication using Node.js TLS
3
-* @author Ylian Saint-Hilaire/Joko Sastriawan
4
-* @version v0.2.0b
1
+/*
2
+Copyright 2020 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+
16
+@description Intel AMT WSMAN communication module for NodeJS
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
7
-// Construct a MeshServer object
21
+/*jslint node: true */
22
+/*jshint node: true */
23
+/*jshint strict:false */
24
+/*jshint -W097 */
25
+/*jshint esversion: 6 */
26
+"use strict";
27
+
28
+// Construct a WSMAN stack communication object
29
var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraConnection) {
30
//console.log('CreateWsmanComm', host, port, user, pass, tls, tlsoptions);
31
@@ -84,8 +105,8 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
105
// Private method
106
obj.PerformAjaxEx = function (postdata, callback, tag, url, action) {
107
if (obj.FailAllError != 0) { obj.gotNextMessagesError({ status: obj.FailAllError }, 'error', null, [postdata, callback, tag, url, action]); return; }
87
- if (!postdata) postdata = "";
88
- //obj.Debug("SEND: " + postdata); // DEBUG
108
+ if (!postdata) postdata = '';
109
+ //obj.Debug('SEND: ' + postdata); // DEBUG
110
111
obj.ActiveAjaxCount++;
112
return obj.PerformAjaxExNodeJS(postdata, callback, tag, url, action);
@@ -113,11 +134,11 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
134
135
// NODE.js specific private method
136
obj.sendRequest = function (postdata, url, action) {
116
- url = url ? url : "/wsman";
117
- action = action ? action : "POST";
118
- var h = action + " " + url + " HTTP/1.1\r\n";
137
+ url = url ? url : '/wsman';
138
+ action = action ? action : 'POST';
139
+ var h = action + ' ' + url + ' HTTP/1.1\r\n';
140
if (obj.challengeParams != null) {
120
- obj.digestRealm = obj.challengeParams["realm"];
141
+ obj.digestRealm = obj.challengeParams['realm'];
142
if (obj.digestRealmMatch && (obj.digestRealm != obj.digestRealmMatch)) {
143
obj.FailAllError = 997; // Cause all new responses to be silent. 997 = Digest Realm check error
144
obj.CancelAllQueries(997);
@@ -143,13 +164,13 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
164
obj.kerberosDone = 1;
165
}
166
} else if (obj.challengeParams != null) {
146
- var response = hex_md5(hex_md5(obj.user + ':' + obj.challengeParams["realm"] + ':' + obj.pass) + ':' + obj.challengeParams["nonce"] + ':' + obj.noncecounter + ':' + obj.cnonce + ':' + obj.challengeParams["qop"] + ':' + hex_md5(action + ':' + url));
147
- h += 'Authorization: ' + obj.renderDigest({ "username": obj.user, "realm": obj.challengeParams["realm"], "nonce": obj.challengeParams["nonce"], "uri": url, "qop": obj.challengeParams["qop"], "response": response, "nc": obj.noncecounter++, "cnonce": obj.cnonce }) + '\r\n';
167
+ var response = hex_md5(hex_md5(obj.user + ':' + obj.challengeParams['realm'] + ':' + obj.pass) + ':' + obj.challengeParams['nonce'] + ':' + obj.noncecounter + ':' + obj.cnonce + ':' + obj.challengeParams['qop'] + ':' + hex_md5(action + ':' + url));
168
+ h += 'Authorization: ' + obj.renderDigest({ 'username': obj.user, 'realm': obj.challengeParams['realm'], 'nonce': obj.challengeParams['nonce'], 'uri': url, 'qop': obj.challengeParams['qop'], 'response': response, 'nc': obj.noncecounter++, 'cnonce': obj.cnonce }) + '\r\n';
169
}
170
h += 'Host: ' + obj.host + ':' + obj.port + '\r\nContent-Length: ' + postdata.length + '\r\n\r\n' + postdata; // Use Content-Length
171
//h += 'Host: ' + obj.host + ':' + obj.port + '\r\nTransfer-Encoding: chunked\r\n\r\n' + postdata.length.toString(16).toUpperCase() + '\r\n' + postdata + '\r\n0\r\n\r\n'; // Use Chunked-Encoding
172
obj.xxSend(h);
152
- //console.log("SEND: " + h); // Display send packet
173
+ //console.log('SEND: ' + h); // Display send packet
174
}
175
176
// NODE.js specific private method
@@ -331,7 +352,7 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
352
353
// NODE.js specific private method
354
obj.xxOnSocketData = function (data) {
334
- //console.log("RECV:"+data);
355
+ //console.log('RECV: ' + data);
356
obj.xtlsDataReceived = true;
357
if (typeof data === 'object') {
358
// This is an ArrayBuffer, convert it to a string array (used in IE)
@@ -345,10 +366,10 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
366
while (true) {
367
//console.log('ACC(' + obj.socketAccumulator + '): ' + obj.socketAccumulator);
368
if (obj.socketParseState == 0) {
348
- var headersize = obj.socketAccumulator.indexOf("\r\n\r\n");
369
+ var headersize = obj.socketAccumulator.indexOf('\r\n\r\n');
370
if (headersize < 0) return;
371
//obj.Debug("Header: "+obj.socketAccumulator.substring(0, headersize)); // Display received HTTP header
351
- obj.socketHeader = obj.socketAccumulator.substring(0, headersize).split("\r\n");
372
+ obj.socketHeader = obj.socketAccumulator.substring(0, headersize).split('\r\n');
373
if (obj.amtVersion == null) { for (var i in obj.socketHeader) { if (obj.socketHeader[i].indexOf('Server: Intel(R) Active Management Technology ') == 0) { obj.amtVersion = obj.socketHeader[i].substring(46); } } }
374
obj.socketAccumulator = obj.socketAccumulator.substring(headersize + 4);
375
obj.socketParseState = 1;
@@ -363,12 +384,12 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
384
}
385
if (obj.socketParseState == 1) {
386
var csize = -1;
366
- if ((obj.socketXHeader["connection"] != undefined) && (obj.socketXHeader["connection"].toLowerCase() == 'close') && ((obj.socketXHeader["transfer-encoding"] == undefined) || (obj.socketXHeader["transfer-encoding"].toLowerCase() != 'chunked'))) {
387
+ if ((obj.socketXHeader['connection'] != undefined) && (obj.socketXHeader['connection'].toLowerCase() == 'close') && ((obj.socketXHeader["transfer-encoding"] == undefined) || (obj.socketXHeader["transfer-encoding"].toLowerCase() != 'chunked'))) {
388
// The body ends with a close, in this case, we will only process the header
389
csize = 0;
369
- } else if (obj.socketXHeader["content-length"] != undefined) {
390
+ } else if (obj.socketXHeader['content-length'] != undefined) {
391
// The body length is specified by the content-length
371
- csize = parseInt(obj.socketXHeader["content-length"]);
392
+ csize = parseInt(obj.socketXHeader['content-length']);
393
if (obj.socketAccumulator.length < csize) return;
394
var data = obj.socketAccumulator.substring(0, csize);
395
obj.socketAccumulator = obj.socketAccumulator.substring(csize);
@@ -376,7 +397,7 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
397
csize = 0;
398
} else {
399
// The body is chunked
379
- var clen = obj.socketAccumulator.indexOf("\r\n");
400
+ var clen = obj.socketAccumulator.indexOf('\r\n');
401
if (clen < 0) return; // Chunk length not found, exit now and get more data.
402
// Chunk length if found, lets see if we can get the data.
403
csize = parseInt(obj.socketAccumulator.substring(0, clen), 16);
@@ -479,243 +500,9 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, ciraCon
500
try { callArgs[1](obj, null, { Header: { HttpError: request.status } }, request.status, callArgs[2]); } catch (ex) { console.error(ex); }
501
}
502
482
- /*
483
- * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
484
- * Digest Algorithm, as defined in RFC 1321.
485
- * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
486
- * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
487
- * Distributed under the BSD License
488
- * See http://pajhome.org.uk/crypt/md5 for more info.
489
- */
490
-
491
- /*
492
- * Configurable variables. You may need to tweak these to be compatible with
493
- * the server-side, but the defaults work in most cases.
494
- */
495
- var hexcase = 0; /* hex output format. 0 - lowercase; 1 - uppercase */
496
- var b64pad = ""; /* base-64 pad character. "=" for strict RFC compliance */
497
- var chrsz = 8; /* bits per input character. 8 - ASCII; 16 - Unicode */
498
-
499
- /*
500
- * These are the functions you'll usually want to call
501
- * They take string arguments and return either hex or base-64 encoded strings
502
- */
503
- function hex_md5(s) { return binl2hex(core_md5(str2binl(s), s.length * chrsz)); }
504
- function b64_md5(s) { return binl2b64(core_md5(str2binl(s), s.length * chrsz)); }
505
- function str_md5(s) { return binl2str(core_md5(str2binl(s), s.length * chrsz)); }
506
- function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
507
- function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
508
- function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }
509
-
510
- /*
511
- * Perform a simple self-test to see if the VM is working
512
- */
513
- function md5_vm_test() {
514
- return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
515
- }
516
-
517
- /*
518
- * Calculate the MD5 of an array of little-endian words, and a bit length
519
- */
520
- function core_md5(x, len) {
521
- /* append padding */
522
- x[len >> 5] |= 0x80 << ((len) % 32);
523
- x[(((len + 64) >>> 9) << 4) + 14] = len;
524
-
525
- var a = 1732584193;
526
- var b = -271733879;
527
- var c = -1732584194;
528
- var d = 271733878;
529
-
530
- for (var i = 0; i < x.length; i += 16) {
531
- var olda = a;
532
- var oldb = b;
533
- var oldc = c;
534
- var oldd = d;
535
-
536
- a = md5_ff(a, b, c, d, x[i + 0], 7, -680876936);
537
- d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
538
- c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
539
- b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
540
- a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
541
- d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
542
- c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
543
- b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
544
- a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
545
- d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
546
- c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
547
- b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
548
- a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
549
- d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
550
- c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
551
- b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
552
-
553
- a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
554
- d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
555
- c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
556
- b = md5_gg(b, c, d, a, x[i + 0], 20, -373897302);
557
- a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
558
- d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
559
- c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
560
- b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
561
- a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
562
- d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
563
- c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
564
- b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
565
- a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
566
- d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
567
- c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
568
- b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
569
-
570
- a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
571
- d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
572
- c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
573
- b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
574
- a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
575
- d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
576
- c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
577
- b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
578
- a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
579
- d = md5_hh(d, a, b, c, x[i + 0], 11, -358537222);
580
- c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
581
- b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
582
- a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
583
- d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
584
- c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
585
- b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
586
-
587
- a = md5_ii(a, b, c, d, x[i + 0], 6, -198630844);
588
- d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
589
- c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
590
- b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
591
- a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
592
- d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
593
- c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
594
- b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
595
- a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
596
- d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
597
- c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
598
- b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
599
- a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
600
- d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
601
- c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
602
- b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
603
-
604
- a = safe_add(a, olda);
605
- b = safe_add(b, oldb);
606
- c = safe_add(c, oldc);
607
- d = safe_add(d, oldd);
608
- }
609
- return Array(a, b, c, d);
610
-
611
- }
612
-
613
- /*
614
- * These functions implement the four basic operations the algorithm uses.
615
- */
616
- function md5_cmn(q, a, b, x, s, t) {
617
- return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
618
- }
619
- function md5_ff(a, b, c, d, x, s, t) {
620
- return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
621
- }
622
- function md5_gg(a, b, c, d, x, s, t) {
623
- return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
624
- }
625
- function md5_hh(a, b, c, d, x, s, t) {
626
- return md5_cmn(b ^ c ^ d, a, b, x, s, t);
627
- }
628
- function md5_ii(a, b, c, d, x, s, t) {
629
- return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
630
- }
631
-
632
- /*
633
- * Calculate the HMAC-MD5, of a key and some data
634
- */
635
- function core_hmac_md5(key, data) {
636
- var bkey = str2binl(key);
637
- if (bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);
638
-
639
- var ipad = Array(16), opad = Array(16);
640
- for (var i = 0; i < 16; i++) {
641
- ipad[i] = bkey[i] ^ 0x36363636;
642
- opad[i] = bkey[i] ^ 0x5C5C5C5C;
643
- }
644
-
645
- var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
646
- return core_md5(opad.concat(hash), 512 + 128);
647
- }
648
-
649
- /*
650
- * Add integers, wrapping at 2^32. This uses 16-bit operations internally
651
- * to work around bugs in some JS interpreters.
652
- */
653
- function safe_add(x, y) {
654
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
655
- var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
656
- return (msw << 16) | (lsw & 0xFFFF);
657
- }
658
-
659
- /*
660
- * Bitwise rotate a 32-bit number to the left.
661
- */
662
- function bit_rol(num, cnt) {
663
- return (num << cnt) | (num >>> (32 - cnt));
664
- }
665
-
666
- /*
667
- * Convert a string to an array of little-endian words
668
- * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
669
- */
670
- function str2binl(str) {
671
- var bin = Array();
672
- var mask = (1 << chrsz) - 1;
673
- for (var i = 0; i < str.length * chrsz; i += chrsz)
674
- bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
675
- return bin;
676
- }
503
+ // MD5 digest hash
504
+ function hex_md5(str) { return obj.crypto.createHash('md5').update(str).digest('hex'); }
505
678
- /*
679
- * Convert an array of little-endian words to a string
680
- */
681
- function binl2str(bin) {
682
- var str = "";
683
- var mask = (1 << chrsz) - 1;
684
- for (var i = 0; i < bin.length * 32; i += chrsz)
685
- str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
686
- return str;
687
- }
688
-
689
- /*
690
- * Convert an array of little-endian words to a hex string.
691
- */
692
- function binl2hex(binarray) {
693
- var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
694
- var str = "";
695
- for (var i = 0; i < binarray.length * 4; i++) {
696
- str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) +
697
- hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
698
- }
699
- return str;
700
- }
701
-
702
- /*
703
- * Convert an array of little-endian words to a base-64 string
704
- */
705
- function binl2b64(binarray) {
706
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
707
- var str = "";
708
- for (var i = 0; i < binarray.length * 4; i += 3) {
709
- var triplet = (((binarray[i >> 2] >> 8 * (i % 4)) & 0xFF) << 16)
710
- | (((binarray[i + 1 >> 2] >> 8 * ((i + 1) % 4)) & 0xFF) << 8)
711
- | ((binarray[i + 2 >> 2] >> 8 * ((i + 2) % 4)) & 0xFF);
712
- for (var j = 0; j < 4; j++) {
713
- if (i * 8 + j * 6 > binarray.length * 32) str += b64pad;
714
- else str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
715
- }
716
- }
717
- return str;
718
- }
506
return obj;
507
}
508
amt/amt-wsman.js
+12
-8
@@ -1,5 +1,5 @@
1
/*
2
-Copyright 2018 Intel Corporation
2
+Copyright 2020 Intel Corporation
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
@@ -12,16 +12,20 @@ distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
-*/
15
17
-/**
18
-* @description Intel(r) AMT WSMAN Stack
19
-* @author Ylian Saint-Hilaire/Joko Sastriawan
20
-* @version v0.2.0
16
+@description Intel AMT WSMAN Stack
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
23
-// Construct a MeshServer object
24
-//function WsmanStackCreateService(comm, host, port, user, pass, tls, extra, parent, mode)
21
+/*jslint node: true */
22
+/*jshint node: true */
23
+/*jshint strict:false */
24
+/*jshint -W097 */
25
+/*jshint esversion: 6 */
26
+"use strict";
27
+
28
+// Construct a WSMAN stack object
29
function WsmanStackCreateService(comm)
30
{
31
var obj = {_ObjectID: 'WSMAN'};
amt/amt-xml.js
+11
-6
@@ -1,5 +1,5 @@
1
/*
2
-Copyright 2018 Intel Corporation
2
+Copyright 2020 Intel Corporation
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
@@ -12,14 +12,19 @@ distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
-*/
15
17
-/**
18
-* @description Parse XML
19
-* @author Ylian Saint-Hilaire
20
-* @version v0.2.0
16
+@description Intel AMT XML parsing module
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
21
+/*jslint node: true */
22
+/*jshint node: true */
23
+/*jshint strict:false */
24
+/*jshint -W097 */
25
+/*jshint esversion: 6 */
26
+"use strict";
27
+
28
// Parse XML and return JSON
29
module.exports.ParseWsman = function (xml) {
30
try {
amt/amt.js
+11
-6
@@ -1,5 +1,5 @@
1
/*
2
-Copyright 2018 Intel Corporation
2
+Copyright 2020 Intel Corporation
3
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
@@ -12,14 +12,19 @@ distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
-*/
15
17
-/**
18
-* @fileoverview Intel(r) AMT Communication StackXX
19
-* @author Ylian Saint-Hilaire
20
-* @version v0.2.0b
16
+@description Intel AMT Communication Stack
17
+@author Ylian Saint-Hilaire
18
+@version v0.3.0
19
*/
20
21
+/*jslint node: true */
22
+/*jshint node: true */
23
+/*jshint strict:false */
24
+/*jshint -W097 */
25
+/*jshint esversion: 6 */
26
+"use strict";
27
+
28
/**
29
* Construct a AmtStackCreateService object, this is the main Intel AMT communication stack.
30
* @constructor
mpsserver.js
+25
-9
@@ -775,8 +775,8 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
775
if (cirachannel.onSendOk) { cirachannel.onSendOk(cirachannel); }
776
} else {
777
// Send a part of the pending buffer
778
- SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.substring(0, cirachannel.sendcredits));
779
- cirachannel.sendBuffer = cirachannel.sendBuffer.substring(cirachannel.sendcredits);
778
+ SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.slice(0, cirachannel.sendcredits));
779
+ cirachannel.sendBuffer = cirachannel.sendBuffer.slice(cirachannel.sendcredits);
780
cirachannel.sendcredits = 0;
781
}
782
}
@@ -837,8 +837,8 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
837
if (cirachannel.onSendOk) { cirachannel.onSendOk(cirachannel); }
838
} else {
839
// Send a part of the pending buffer
840
- SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.substring(0, cirachannel.sendcredits));
841
- cirachannel.sendBuffer = cirachannel.sendBuffer.substring(cirachannel.sendcredits);
840
+ SendChannelData(cirachannel.socket, cirachannel.amtchannelid, cirachannel.sendBuffer.slice(0, cirachannel.sendcredits));
841
+ cirachannel.sendBuffer = cirachannel.sendBuffer.slice(cirachannel.sendcredits);
842
cirachannel.sendcredits = 0;
843
}
844
}
@@ -959,9 +959,15 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
959
Write(socket, String.fromCharCode(APFProtocol.CHANNEL_CLOSE) + common.IntToStr(channelid));
960
}
961
962
+ // Send a buffer to a given channel
963
function SendChannelData(socket, channelid, data) {
963
- parent.debug('mpscmddata', '<-- CHANNEL_DATA', channelid, data.length, Buffer.from(data, 'binary').toString('hex'));
964
- Write(socket, String.fromCharCode(APFProtocol.CHANNEL_DATA) + common.IntToStr(channelid) + common.IntToStr(data.length) + ((typeof data == 'string') ? data : data.toString('binary')));
964
+ parent.debug('mpscmddata', '<-- CHANNEL_DATA', channelid, data.length);
965
+ const buf = Buffer.alloc(9 + data.length);
966
+ buf[0] = APFProtocol.CHANNEL_DATA; // CHANNEL_DATA
967
+ buf.writeInt32BE(channelid, 1); // ChannelID
968
+ buf.writeInt32BE(data.length, 5); // Data Length
969
+ data.copy(buf, 9, 0);
970
+ WriteBuffer(socket, buf);
971
}
972
973
function SendChannelWindowAdjust(socket, channelid, bytestoadd) {
@@ -986,6 +992,7 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
992
Write(socket, String.fromCharCode(APFProtocol.USERAUTH_SUCCESS));
993
}
994
995
+ // Send a string or buffer
996
function Write(socket, data) {
997
try {
998
if (args.mpsdebug) {
@@ -999,6 +1006,14 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
1006
} catch (ex) { }
1007
}
1008
1009
+ // Send a buffer
1010
+ function WriteBuffer(socket, data) {
1011
+ try {
1012
+ if (args.mpsdebug) { console.log('MPS <-- (' + buf.length + '):' + data.toString('hex')); } // Print out sent bytes
1013
+ if (socket.websocket == 1) { socket.send(data); } else { socket.write(data); }
1014
+ } catch (ex) { }
1015
+ }
1016
+
1017
// Returns a CIRA/Relay/LMS connection to a nodeid, use the best possible connection, CIRA first, Relay second, LMS third.
1018
// if oob is set to true, don't allow an LMS connection.
1019
obj.GetConnectionToNode = function (nodeid, targetport, oob) {
@@ -1033,9 +1048,10 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
1048
// This function writes data to this CIRA channel
1049
cirachannel.write = function (data) {
1050
if (cirachannel.state == 0) return false;
1051
+ if (typeof data == 'string') { data = Buffer.from(data, 'binary'); } // Make sure we always handle buffers when sending data.
1052
if (cirachannel.state == 1 || cirachannel.sendcredits == 0 || cirachannel.sendBuffer != null) {
1053
// Channel is connected, but we are out of credits. Add the data to the outbound buffer.
1038
- if (cirachannel.sendBuffer == null) { cirachannel.sendBuffer = data; } else { cirachannel.sendBuffer += data; }
1054
+ if (cirachannel.sendBuffer == null) { cirachannel.sendBuffer = data; } else { cirachannel.sendBuffer = Buffer.concat([ cirachannel.sendBuffer, data ]); }
1055
return true;
1056
}
1057
// Compute how much data we can send
@@ -1046,8 +1062,8 @@ module.exports.CreateMpsServer = function (parent, db, args, certificates) {
1062
return true;
1063
}
1064
// Send a part of the message
1049
- cirachannel.sendBuffer = data.toString('binary').substring(cirachannel.sendcredits);
1050
- SendChannelData(cirachannel.socket, cirachannel.amtchannelid, data.toString('binary').substring(0, cirachannel.sendcredits));
1065
+ cirachannel.sendBuffer = data.slice(cirachannel.sendcredits);
1066
+ SendChannelData(cirachannel.socket, cirachannel.amtchannelid, data.slice(0, cirachannel.sendcredits));
1067
cirachannel.sendcredits = 0;
1068
return false;
1069
};