deno
deno copied to clipboard
Cannot starttls on an existing used connection via node:tls
Version: Deno 2.0.4
This is a simplified example without any of my npm libraries or app code:
import net from "node:net";
import tls from "node:tls";
const socket = new net.Socket()
socket.connect(5222, "scarlet.mboa.dev", () => {
socket.write('<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="bdf7acd2-e3b1-4b0a-afc4-10bb69821433" xml:lang="en" version="1.0" to="bots.cheogram.com">');
});
var x = 0;
socket.on("data", (data) => {
x++;
if (x < 2) {
socket.write('<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>');
} else {
tls.connect({ socket: socket, host: "bots.cheogram.com" }, () => {
console.log("TLS ON");
});
}
})
I would expect to get TLS ON but instead I get Uncaught Error: Client network socket disconnected before secure TLS connection was established
This almost identical code works fine under nodejs:
import net from "net";
import tls from "tls";
const socket = new net.Socket()
socket.connect(5222, "scarlet.mboa.dev", () => {
socket.write('<stream:stream xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client" id="bdf7acd2-e3b1-4b0a-afc4-10bb69821433" xml:lang="en" version="1.0" to="bots.cheogram.com">');
});
var x = 0;
socket.on("data", (data) => {
x++;
if (x < 2) {
socket.write('<starttls xmlns="urn:ietf:params:xml:ns:xmpp-tls"/>');
} else {
tls.connect({ socket: socket, host: "bots.cheogram.com" }, () => {
console.log("TLS ON");
});
}
});