简体   繁体   English

如何通过Paho MQQT JS客户端强制进行非安全连接?

[英]How to force non secure connection via paho mqqt js client?

I get this error in staging but not in development when the browser tries to connect to my mosquitto server in Firefox: 当浏览器尝试连接到Firefox中的mosquitto服务器时,我在暂存中收到此错误,但在开发中却没有:

SecurityError: The operation is insecure. SecurityError:操作不安全。

I'm not running the system with ssl and I know I should fix this but for the time been I would like to make this work. 我没有使用ssl运行系统,我知道我应该解决此问题,但暂时我想完成这项工作。

  function mqtt() {
    // Create a client instance
    client = new Paho.MQTT.Client('localhost', 9091, "", "tablet_1");
    // set callback handlers
    client.onConnectionLost = onConnectionLost;
    client.onMessageArrived = onMessageArrived;
    client.reconnect = true
    willMessage = new Paho.MQTT.Message("Rescue me");
    connectOptions = {
        userName: 'server',
        password: '1234',
        // willMessage: willMessage,
        onSuccess:onConnect,
        cleanSession: true,
        reconnect: true,
        useSSL: false
    }
    // connect the client
    client.connect(connectOptions);
  }

This are my port configurations in mosquitto: 这是我在mosquitto中的端口配置:

listener 1883
listener 8883
cafile ca.crt
certfile server.crt
keyfile server.key
tls_version tlsv1.2

listener 9091
protocol websockets

As hashed out in the comments, this is the browser blocking none secure content when the host page is loaded over https. 如评论中所散列的,这是当通过https加载主机页面时,浏览器不会阻止任何安全内容。

You can force mixed content by clicking on the shield in the URL bar, but this is not the right approach. 您可以通过单击URL栏中的屏蔽来强制混合内容,但这不是正确的方法。

The correct solution to this is to run HTTPS/TLS everywhere (even in dev/staging). 正确的解决方案是在所有位置(甚至在开发/登台中)运行HTTPS / TLS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM