Compare commits
2 Commits
df06b39e88
...
2fa2bbc856
Author | SHA1 | Date | |
---|---|---|---|
2fa2bbc856 | |||
97c8149e92 |
21
index.js
21
index.js
@ -9,6 +9,8 @@ const port = process.argv[3] || 23;
|
|||||||
const hostname = process.argv[2] || (process.pkg ? "dom.ht-dev.de" : "localhost");
|
const hostname = process.argv[2] || (process.pkg ? "dom.ht-dev.de" : "localhost");
|
||||||
let delayMs = process.argv[4] || 100; // Command delay in milliseconds
|
let delayMs = process.argv[4] || 100; // Command delay in milliseconds
|
||||||
|
|
||||||
|
const advancedFeatures = false; // Enable advanced features
|
||||||
|
|
||||||
// Diffie-Hellman parameters
|
// Diffie-Hellman parameters
|
||||||
const keyCurve = "prime256v1"; // key exchange curve, make this negotiable in the future
|
const keyCurve = "prime256v1"; // key exchange curve, make this negotiable in the future
|
||||||
|
|
||||||
@ -24,6 +26,7 @@ class MemoryStream extends Transform {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const writer = new MemoryStream();
|
const writer = new MemoryStream();
|
||||||
|
let initialized = false; // Initialization status, do not modify directly, runtime only
|
||||||
let encrypted = false; // Encryption status, do not modify directly, runtime only
|
let encrypted = false; // Encryption status, do not modify directly, runtime only
|
||||||
let privateKey; // Private key, do not modify directly, runtime only
|
let privateKey; // Private key, do not modify directly, runtime only
|
||||||
const key = createECDH(keyCurve);
|
const key = createECDH(keyCurve);
|
||||||
@ -155,7 +158,7 @@ process.stdin.on('data', async (key) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.on("data", (data) => {
|
socket.on("data", (data) => {
|
||||||
if (!encrypted) {
|
if (!encrypted || !initialized) {
|
||||||
if (data.equals(PAUSE)) {
|
if (data.equals(PAUSE)) {
|
||||||
process.stdin.pause();
|
process.stdin.pause();
|
||||||
} else if (data.equals(RESUME)) {
|
} else if (data.equals(RESUME)) {
|
||||||
@ -189,6 +192,8 @@ socket.on("data", (data) => {
|
|||||||
} else {
|
} else {
|
||||||
process.stdout.write(data);
|
process.stdout.write(data);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// decrypt data
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -203,18 +208,22 @@ socket.on("connect", async () => {
|
|||||||
await delay(delayMs);
|
await delay(delayMs);
|
||||||
socket.write(Buffer.concat([IAC, DO, ECHO])); // Echo
|
socket.write(Buffer.concat([IAC, DO, ECHO])); // Echo
|
||||||
await delay(delayMs);
|
await delay(delayMs);
|
||||||
socket.write(Buffer.concat([IAC, WILL, CUSTOM_CLIENT_INIT])); // Custom Client Initialization
|
if (advancedFeatures) {
|
||||||
await delay(delayMs);
|
socket.write(Buffer.concat([IAC, WILL, CUSTOM_CLIENT_INIT])); // Custom Client Initialization
|
||||||
// socket.write(Buffer.from([0x0d, 0x0a])); // Line Feed
|
await delay(delayMs);
|
||||||
|
}
|
||||||
|
socket.write(Buffer.from([0x0d, 0x0a])); // Line Feed
|
||||||
if (encrypted) {
|
if (encrypted) {
|
||||||
// increase delay for encryption
|
// increase delay for encryption
|
||||||
delayMs += 500;
|
delayMs += 200;
|
||||||
}
|
}
|
||||||
// from here on encryption is enabled, do not use socket.write() directly anymore
|
// from here on encryption is enabled, do not use socket.write() directly anymore
|
||||||
await delay(delayMs);
|
await delay(delayMs);
|
||||||
|
console.debug("Initialization complete");
|
||||||
|
initialized = true;
|
||||||
// initialization complete
|
// initialization complete
|
||||||
|
|
||||||
// await send("help");
|
await send("help");
|
||||||
await delay(500);
|
await delay(500);
|
||||||
process.stdout.write("\rCtrl+X for client side commands\r\nCtrl+C to exit, Ctrl+D to force close\r\n> ");
|
process.stdout.write("\rCtrl+X for client side commands\r\nCtrl+C to exit, Ctrl+D to force close\r\n> ");
|
||||||
process.stdin.resume(); // Resume input
|
process.stdin.resume(); // Resume input
|
||||||
|
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "telnet-client",
|
"name": "telnet-client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "telnet-client",
|
"name": "telnet-client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"telnet-client": "file:"
|
"telnet-client": "file:"
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "telnet-client",
|
"name": "telnet-client",
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"description": "To be used with HTDev BBS Server for encrypted communication and extended functionality.",
|
"description": "To be used with HTDev BBS Server for encrypted communication and extended functionality.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": "index.js",
|
"bin": "index.js",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user