Started work on Intel AMT hello server.
Ylian Saint-Hilaire committed
Mar 10, 2021 at 19:01 UTC
92138327bfe395f98de782a203ae854f5dd82ab1
3 files changed
+120
-1
MeshCentralServer.njsproj
+1
-1
@@ -98,7 +98,7 @@
98
<Compile Include="amt\amt-xml.js" />
99
<Compile Include="amt\amt.js" />
100
<Compile Include="exeHandler.js" />
101
- <Compile Include="firebase.js" />
101
+ <Compile Include="amthelloserver.js" />
102
<Compile Include="letsencrypt.js" />
103
<Compile Include="mcrec.js" />
104
<Compile Include="meshaccelerator.js" />
amthelloserver.js
new
+114
@@ -0,0 +1,114 @@
1
+/**
2
+* @description MeshCentral Intel AMT Hello server
3
+* @author Ylian Saint-Hilaire
4
+* @copyright Intel Corporation 2018-2021
5
+* @license Apache-2.0
6
+* @version v0.0.1
7
+*/
8
+
9
+/*xjslint node: true */
10
+/*xjslint plusplus: true */
11
+/*xjslint maxlen: 256 */
12
+/*jshint node: true */
13
+/*jshint strict: false */
14
+/*jshint esversion: 6 */
15
+"use strict";
16
+
17
+// Construct the Intel AMT hello server. This is used for Intel AMT bare-metal activation on the local LAN.
18
+// This server can receive a notification from Intel AMT and attempt activation.
19
+module.exports.CreateAmtHelloServer = function (parent, config) {
20
+ var obj = {};
21
+
22
+ var port = 9971;
23
+ if (typeof config.port == 'number') { port = config.port; }
24
+ const net = require('net');
25
+ obj.server = net.createServer(function (socket) {
26
+ socket.ra = socket.remoteAddress;
27
+ socket.data = null;
28
+ socket.on('error', function (err) { })
29
+ socket.on('close', function () { if (this.data != null) { parseHelloData(this.data, this.ra); } delete this.ra; this.removeAllListeners(); })
30
+ socket.on('data', function (data) {
31
+ if (this.data == null) { this.data = data; } else { Buffer.concat([this.data, data]); }
32
+ var str = this.data.toString();
33
+ if (str.startsWith('GET ') && (str.indexOf('\r\n\r\n') >= 0)) {
34
+ this.data = null;
35
+ var content = "<!DOCTYPE html><html><head><meta charset=\"UTF-8\"><title>Intel® AMT Hello Server</title></head><body>Intel AMT hello server.<br />Intel® AMT devices should send notification to this port for activation.</body></html>";
36
+ try { socket.end('HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: ' + content.length + '\r\nConnection: close\r\n\r\n' + content); } catch (ex) {}
37
+ } else if (this.data.length > 16000) {
38
+ try { this.end(); } catch (ex) { };
39
+ }
40
+ })
41
+ });
42
+ obj.server.listen(port);
43
+ console.log('MeshCentral Intel AMT hello server running on port ' + port + '.');
44
+
45
+ function parseHelloData(data, addr) {
46
+ if (addr.startsWith('::ffff:')) { addr = addr.substring(7); }
47
+ console.log('parseHelloData', data.length);
48
+ console.log('Address', addr);
49
+ console.log('HEX', data.toString('hex'));
50
+ }
51
+
52
+ return obj;
53
+};
54
+
55
+
56
+
57
+/*
58
+[Serializable]
59
+public class AmtHello
60
+{
61
+ public byte[] Data;
62
+ public string Pid;
63
+ public byte[][] CertHash;
64
+ public DateTime ReceivedTime;
65
+ public IPEndPoint RemoteEndPoint;
66
+ public int Version;
67
+
68
+ public AmtHello(byte[] buf, IPEndPoint ep)
69
+ {
70
+ Data = buf;
71
+ ReceivedTime = DateTime.Now;
72
+ RemoteEndPoint = ep;
73
+ Version = buf[2];
74
+ if (buf.Length == 32) // One Touch PID
75
+ {
76
+ byte[] b = new byte[8];
77
+ Array.Copy(buf,24,b,0,8);
78
+ Pid = UTF8Encoding.UTF8.GetString(b);
79
+ if (Pid.Length == 8) Pid = Pid.Substring(0, 4) + "-" + Pid.Substring(4, 4);
80
+ }
81
+ if (Version == 3) // Zero-Touch Key Hash
82
+ {
83
+ int hashCount = buf[24];
84
+ CertHash = new byte[hashCount][];
85
+ int ptr = 26;
86
+ for (int i = 0; i < hashCount; i++)
87
+ {
88
+ CertHash[i] = new byte[buf[ptr]];
89
+ Array.Copy(buf, ptr + 1, CertHash[i], 0, buf[ptr]);
90
+ ptr += (buf[ptr] + 2);
91
+ }
92
+ }
93
+ }
94
+
95
+ public bool NetworkPasswordChanged
96
+ {
97
+ get {return BitConverter.ToInt16(Data, 0) != 0;}
98
+ }
99
+
100
+ public Guid GetGuid()
101
+ {
102
+ if (Data.Length < 24) return Guid.Empty;
103
+ byte[] b = new byte[16];
104
+ Array.Copy(Data, 8, b, 0, 16);
105
+ return new Guid(b);
106
+ }
107
+
108
+ public float GetVersion()
109
+ {
110
+ if (Data.Length < 4) return 0;
111
+ return (float)BitConverter.ToInt16(Data, 2);
112
+ }
113
+}
114
+*/
\ No newline at end of file
meshcentral.js
+5
@@ -1649,6 +1649,11 @@ function CreateMeshCentralServer(config, args) {
1649
}
1650
});
1651
1652
+ // Setup Intel AMT hello server
1653
+ if ((typeof config.settings.amthelloserver == 'object') && (typeof config.settings.amthelloserver.devicegroup == 'string')) {
1654
+ obj.amthelloserver = require('./amthelloserver').CreateAmtHelloServer(obj, config.settings.amthelloserver);
1655
+ }
1656
+
1657
// Start collecting server stats every 5 minutes
1658
setInterval(function () {
1659
obj.serverStatsCounter++;