"use strict"; import net from 'net'; import l from 'log'; import make_cert from 'make-cert'; import settings from '../../settings.mjs'; import sleep from '../../lib/async/sleep.mjs'; import starttls from '../../lib/transport/starttls.mjs'; import { encrypt, decrypt } from '../../lib/crypto/secretbox.mjs'; export default async function() { const test_key = "H7xKSxvJFoZoNjCKAfxn4E3qUzY3Y/4bjY+qIzxg+78="; const our_cert = make_cert("test_server.localhost"); const test_data = "hello, world"; l.notice(`TEST_DATA`, test_data); const encrypted = encrypt(test_key, test_data); l.notice(`ENCRYPTED`, encrypted); const decrypted = decrypt(test_key, encrypted); l.notice(`DECRYPTED`, decrypted); const socket = net.createConnection({ port: settings.cli.port }, () => { l.notice("connection established"); }); await starttls(socket, test_key, our_cert, false); socket.on("data", (chunk) => { l.notice(`<<< ${chunk.toString("utf-8")}`); }); socket.on("end", () => { l.notice("disconnected"); }); for(let i = 0; i < 100; i++) { await sleep(1000); l.notice(`>>> hello world ${i}`); socket.write(`hello world ${i}\n`); } }