-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtv-mqtts-test.js
More file actions
117 lines (102 loc) · 3.08 KB
/
Copy pathtv-mqtts-test.js
File metadata and controls
117 lines (102 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Test MQTT over TLS with client cert options on Hisense VIDAA
const mqtt = require('mqtt');
const tls = require('tls');
const ip = process.argv[2] || '192.168.0.121';
// Approach 1: mqtts:// (MQTT over TLS)
console.log(`[1] Testing mqtts://${ip}:36669 (standard TLS)...`);
const client1 = mqtt.connect(`mqtts://${ip}:36669`, {
username: 'hisenseservice',
password: 'multimqttservice',
connectTimeout: 5000,
reconnectPeriod: 0,
rejectUnauthorized: false,
protocolVersion: 4,
});
const t1 = setTimeout(() => {
console.log('[1] Timeout');
client1.end(true);
tryWss();
}, 6000);
client1.on('connect', () => {
clearTimeout(t1);
console.log('[1] CONNECTED!');
client1.end();
process.exit(0);
});
client1.on('error', (err) => {
clearTimeout(t1);
console.log(`[1] Error: ${err.message || err.code}`);
client1.end(true);
tryWss();
});
// Approach 2: wss:// (MQTT over WebSocket over TLS — some VIDAA models)
function tryWss() {
console.log(`\n[2] Testing wss://${ip}:8443 (MQTT over WebSocket)...`);
const client2 = mqtt.connect(`wss://${ip}:8443`, {
username: 'hisenseservice',
password: 'multimqttservice',
connectTimeout: 5000,
reconnectPeriod: 0,
rejectUnauthorized: false,
protocolVersion: 4,
});
const t2 = setTimeout(() => {
console.log('[2] Timeout');
client2.end(true);
tryRaw();
}, 6000);
client2.on('connect', () => {
clearTimeout(t2);
console.log('[2] CONNECTED via WSS!');
client2.end();
process.exit(0);
});
client2.on('error', (err) => {
clearTimeout(t2);
console.log(`[2] Error: ${err.message || err.code}`);
client2.end(true);
tryRaw();
});
}
// Approach 3: Raw TLS socket to see what's actually listening
function tryRaw() {
console.log(`\n[3] Raw TLS probe on ${ip}:36669...`);
const socket = tls.connect({
host: ip,
port: 36669,
rejectUnauthorized: false,
timeout: 5000,
}, () => {
console.log('[3] TLS CONNECTED!');
console.log(` Protocol: ${socket.getProtocol()}`);
console.log(` Cipher: ${JSON.stringify(socket.getCipher())}`);
const cert = socket.getPeerCertificate();
if (cert) {
console.log(` Server CN: ${cert.subject?.CN || 'N/A'}`);
console.log(` Issuer: ${cert.issuer?.CN || 'N/A'}`);
}
socket.end();
process.exit(0);
});
socket.on('error', (err) => {
console.log(`[3] Error: ${err.message}`);
console.log('\n[4] Raw TLS probe on port 8443...');
const s2 = tls.connect({ host: ip, port: 8443, rejectUnauthorized: false, timeout: 5000 }, () => {
console.log('[4] TLS CONNECTED on 8443!');
console.log(` Protocol: ${s2.getProtocol()}`);
const cert = s2.getPeerCertificate();
if (cert?.subject) console.log(` Server CN: ${cert.subject.CN}`);
if (cert?.issuer) console.log(` Issuer: ${cert.issuer.CN}`);
s2.end();
process.exit(0);
});
s2.on('error', (e) => {
console.log(`[4] Error: ${e.message}`);
process.exit(1);
});
});
socket.setTimeout(5000, () => {
console.log('[3] Timeout');
socket.destroy();
});
}