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

Not work tls in MQTT.js ? #19978

Closed
Octo8080X opened this issue Jul 29, 2023 · 1 comment · Fixed by #20120
Closed

Not work tls in MQTT.js ? #19978

Octo8080X opened this issue Jul 29, 2023 · 1 comment · Fixed by #20120
Assignees
Labels
bug Something isn't working correctly node compat

Comments

@Octo8080X
Copy link

When MQTT.js is used with Deno, TLS may not be used correctly.

For example.

import mqtt from "npm:mqtt";

const client = mqtt.connect({
  port: 8883,
  host: "host",
  key:  Deno.readTextFileSync("keyfile"),
  cert:  Deno.readTextFileSync("clientfile"),
  rejectUnauthorized: false,
  ca: Deno.readTextFileSync("cacertfile"),
  protocol: 'mqtts'
});

client.on("connect", () => {
  client.subscribe("topic");
});

client.on("message", (topic, paylo) => {
  console.log([topic, new TextDecoder().decode(payload)]);
});

setInterval(async () => {
  await client.publish("topic", "payload");
}, 2000);

On the broker server, openssl is causing an error.
I can confirm that Node.js works with similar code.
Is it possible to improve compatibility here?

@Octo8080X Octo8080X changed the title not work tls in MQTT.js not work tls in MQTT.js ? Jul 29, 2023
@Octo8080X Octo8080X changed the title not work tls in MQTT.js ? Not work tls in MQTT.js ? Jul 29, 2023
@bartlomieju bartlomieju added bug Something isn't working correctly node compat labels Jul 31, 2023
@littledivy
Copy link
Member

Another reproduction without a local MQTT broker:

import mqtt from "npm:mqtt";
import fs from "node:fs";

const client = mqtt.connect({
  port: 8884,
  host: "test.mosquitto.org",
  key:  fs.readFileSync("client.key"),
  cert: fs.readFileSync("client.crt"),
  ca: fs.readFileSync("mosquitto.org.crt"),
  protocol: 'mqtts'
});

client.on("connect", () => {
  console.log("Connected");
  client.subscribe("topic");
});

client.on("message", (topic, payload) => {
  console.log([topic, new TextDecoder().decode(payload)]);
});

setInterval(async () => {
  console.log(await client.publish("topic", "payload"));
}, 2000);

Generate certificates from https://test.mosquitto.org/ssl/

littledivy added a commit that referenced this issue Aug 11, 2023
littledivy added a commit to littledivy/deno that referenced this issue Aug 21, 2023
littledivy added a commit that referenced this issue Aug 21, 2023
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 compat
Projects
None yet
3 participants