Coder Social home page Coder Social logo

Support TLS/SSL connections? about mqtt HOT 5 OPEN

sskaje avatar sskaje commented on June 26, 2024
Support TLS/SSL connections?

from mqtt.

Comments (5)

sskaje avatar sskaje commented on June 26, 2024

https://github.com/sskaje/mqtt/blob/master/test/tls1.2/connect.php
is this what you want?

from mqtt.

shenfeng07 avatar shenfeng07 commented on June 26, 2024

yes。thank you。

from mqtt.

shenfeng07 avatar shenfeng07 commented on June 26, 2024

请问ssl的证书要在哪里设置?看test上好像没有配置证书的路径。

from mqtt.

sskaje avatar sskaje commented on June 26, 2024

http://php.net/stream_context_create
http://php.net/manual/en/context.ssl.php

from mqtt.

btry avatar btry commented on June 26, 2024

Hi

A small contribution to this issue.

Here is how I use TLS with this library, and it works. The code below is reactored to drop specificies of my project and make it more understandable.

   /**
    * Builds a MQTT
    * @param string $socketAddress
    * @param integer $port
    * @param boolean $isTls
    * @return sskaje\mqtt\MQTT an instance of a MQTT client
    */
   protected function buildMqtt($socketAddress, $port, $isTls) {
      $protocol = $isTls ? "ssl://" : "tcp://";
      $mqtt = new sskaje\mqtt\MQTT("$protocol$socketAddress:$port");
      if ($isTls) {
         $mqtt->setSocketContext(stream_context_create([
               'ssl' => [
                   'cafile'                => '/path/to/CACert-mqtt.crt',
                   'verify_peer'           => false,
                   'verify_peer_name'      => false,
                   'disable_compression'   => true,
                   'ciphers'               => 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK',
                   'crypto_method'         => STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT | STREAM_CRYPTO_METHOD_SSLv23_CLIENT,
                   'SNI_enabled'           => true,
                   'allow_self_signed'     => true
               ]
            ]
         ));
      }
      $mqtt->setKeepalive(50);

      return $mqtt;
   }

from mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.