~lastrosade/MNC

1c4824eb0f056ae9aef33c5727276816da80d9c5 — Jeremy Lee Shields 4 years ago d9b7f45 master
Added options for specifying ssl ports
7 files changed, 112 insertions(+), 22 deletions(-)

M README.md
A certificate.pem
M index.js
A key.pem
A p1.stunnel
A p2.stunnel
M settings.json.template
M README.md => README.md +14 -8
@@ 20,19 20,23 @@ npm and node

## Usage

```-d``` Dev mode, Verbose
```-h [Host]``` Specify the host

```-1 [Port]``` Specify the reading server port

```-h host``` Specify the host
```-2 [Port]``` Specify the writing server port

```-1 port``` Specify the reading server port
```-3 [Port]``` Specify an alternative reading port for ssl

```-2 port``` Specify the writing server port
```-4 [Port]``` Specify an alternative writing port for ssl

```-m length``` Specify the maximum message length

```-d``` Dev mode, Verbose

then netcat or telnet to the reading and writing server

eg: ```netcat localhost 44033```
eg: ```netcat localhost 44031```

## Built With



@@ 53,7 57,8 @@ Generate a certificate
Create Stunnel config files

p1.stunnel
```

```Ini
; TLS front-end to a web server
fips=no



@@ 65,7 70,8 @@ key=/path/to/key.pem
```

p2.stunnel
```

```Ini
; TLS front-end to a web server
fips=no



@@ 106,4 112,4 @@ This project is licensed under the BSD 3-Clause License - see the [LICENSE](LICE

The windows telnet client is broken, instead of sending buffers of data, it send each and every keystrokes back to the server by default,

So for windows users I recommend using putty in raw mode.
\ No newline at end of file
So for windows users I recommend using putty in raw mode.

A certificate.pem => certificate.pem +22 -0
@@ 0,0 1,22 @@
-----BEGIN CERTIFICATE-----
MIIDpTCCAo2gAwIBAgIUCGPeX3d/gB8A9CKzNC8U2y94G0EwDQYJKoZIhvcNAQEL
BQAwYjELMAkGA1UEBhMCRlIxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDEbMBkGA1UEAwwSamVyZW15bGVlLnNo
OjMzMDM0MB4XDTE5MDgxNDAyNDIwOVoXDTIwMDgxMzAyNDIwOVowYjELMAkGA1UE
BhMCRlIxEzARBgNVBAgMCl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option('-1, --port1 [Port]', 'Reading server port')
    .option('-2, --port2 [Port]', 'Writing server port')
    .option('-3, --port3 [Port]', 'Alternative ssl Reading server port')
    .option('-4, --port4 [Port]', 'Alternative ssl Writing server port')
    .option('-m, --maxlen [Length]', 'Maximum messages length')
    .option('-d, --dev'         , 'Dev mode') // Dev mode prints stuff
    .option('-d, --dev', 'Dev mode') // Dev mode prints stuff
    .parse(process.argv);


const host  = program.host  || settings.host  || "localhost";
const port1 = program.port1 || settings.port1 || 44033;
const port2 = program.port2 || settings.port2 || 44044;
const port1 = program.port1 || settings.port1 || 44031;
const port2 = program.port2 || settings.port2 || 44032;
const port3 = program.port3 || settings.port3;
const port4 = program.port4 || settings.port4;
const max_len = program.maxlen || settings.maxlen || 256;
const dev = program.dev || settings.dev;

// Salt to use when hashing IPs
// Salt = CRC32([1 9999])CRC32([1 99999])
const salt = crc32(Math.floor(Math.random()*Math.floor(9999)).toString()) + crc32(Math.floor(Math.random() * Math.floor(99999)).toString());
hash = (str) => { var addr = crc32(str+salt).toString(16); return addr + " :: " + addr; }

// Important arrays
var readers = [];


@@ 48,9 53,13 @@ var writers = [];
// Reading server
var read = net.createServer((reader) => {
    readers.push(reader);
    reader.name = crc32(reader.remoteAddress+salt).toString(16) + " :: " + reader.remotePort;
    reader.name = hash()

    reader.write("Welcome ! this is a tcp chat reader,\r\n You can write at adress: "+host+", port "+port2+"\r\n\r\n");
    var message = "Welcome ! this is a tcp chat reader on "+port1;
    if (port3) { message+=" And SSL reader on "+port3 }
    message += ",\r\n You can write at port: "+port2;
    if (port4) { message+=" And on "+port4+" with SSL" }
    reader.write(message+"\r\n\r\n");

    broadcast(readers, reader.name + " joined as reader\n", reader);



@@ 63,17 72,18 @@ var read = net.createServer((reader) => {
});
read.listen(port1, host);



// Writing Server
var write = net.createServer((writer) => {
    writers.push(writer);
    writer.name = crc32(writer.remoteAddress+salt).toString(16) + " :: " + writer.remotePort;
    broadcast(readers, writer.name + " joined as writer\n", writer);

    writer.write(
    "Welcome ! This is a tcp chat writer,\r\n" +
    "You can read at adress: "+host+", port "+port1+"\r\n\r\n" +
    var message = "Welcome ! This is a tcp chat writer on "+port2;
    if (port4) { message+=" And SSL reader on "+port4 }
    message += ",\r\n You can read at port: "+port1;
    if (port3) { message+=" And on "+port3+" with SSL" }
    writer.write(message+
    "\r\n\r\n" +
    "  Some commands:\r\n" +
    "  !rename str : Changes your name with 10 char max. \r\n" +
    "  !help [str] : For more commands. \r\n" +


@@ 88,7 98,6 @@ var write = net.createServer((writer) => {
            data = data.substring(0, max_len);
        }


        // Get commands
        var s1 = data.split(' ')[0], s2 = data.split(' ')[1];


A key.pem => key.pem +28 -0
@@ 0,0 1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDydG/p5uQb0bDB
DqRLOnCCDJA13qFLOe3l1nofq5Ord9jYqsoGQ4jNETobkW+kQA2BORXN5ByZTFtF
w3CCcsvXA4WyMgpGVE5RNKoKXwYUv4IVsNGgnSdgeB/gQiaXJKmT2pSfb2hzYBIy
ZQx9afxV5D3QqcfLQ7pW5uYhVYyxwWpePYdEbQxWUx/tnFcyoHk5SVQLUj+swEZl
cKs5s2sjz2P3+vX2YF7NAJmVAvYkuR7IxfBNFsiv9fDlHq+9t53rZE/mvX/2pyTr
DHJ3V979BYOtXIFP9GN5of9HRiqjlfkdRUv5fQ1iskR7c3THLJSSve3v5IAc6KAw
9iB0inmpAgMBAAECggEAIDU7kLTtZIyskFjjlmLDA2Or3JwgjR+67KdbPc3LJiIb
mlzFzaM3DxbUw0jErescYCg3L0y4R90O2uuljI63aW68Wfmvx7v3U25NkGcjJapz
G3KLxmxaCMSsZ1wiSD3EkTGeQLfKBlmi0TL/P8HOlZJma8vCEMyEenrd41u7/vjS
eQ/hnUAm26sipaFrvpKU0G5vMFqxJvCJ2ejGQT+uqhI+fo3I0nir2BAXDoyOQ4fi
vJtxsbSaumoPHN3S/5tMNpbdD///n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/path/to/certificate.pem
key=/path/to/key.pem
\ No newline at end of file

A p2.stunnel => p2.stunnel +14 -0
@@ 0,0 1,14 @@
; TLS front-end to a web server
debug=info
log=append

fips=no
#compression=zlib

[https]
accept=44045
connect=44044
cert=/root/projects/MNC/certificate.pem
key=/root/projects/MNC/key.pem

#openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
\ No newline at end of file

M settings.json.template => settings.json.template +6 -3
@@ 2,12 2,15 @@
    "//": "TCP server settings",

        "host": "localhost",
        "port1": "44033",
        "port2": "44044",
        "port1": "44031",
        "port2": "44032",
        "port3": false,
        "port4": false,
        "tls": true;

    "//": "Dev mode",

        "dev": "false"
        "dev": false

    "//": "Chat settings",