Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot starttls on an existing used connection via node:tls #26685

Closed
singpolyma opened this issue Nov 2, 2024 · 0 comments · Fixed by #27125
Closed

Cannot starttls on an existing used connection via node:tls #26685

singpolyma opened this issue Nov 2, 2024 · 0 comments · Fixed by #27125
Labels
bug Something isn't working correctly node API Related to various "node:*" modules APIs

Comments

@singpolyma
Copy link

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");
    });
  }
});
@bartlomieju bartlomieju added bug Something isn't working correctly node API Related to various "node:*" modules APIs labels Nov 2, 2024
bartlomieju pushed a commit that referenced this issue Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly node API Related to various "node:*" modules APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants