File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed
Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -243,6 +243,10 @@ $connectionSettings = (new \PhpMqtt\Client\ConnectionSettings)
243243 // This option requires ConnectionSettings::setTlsClientCertificateFile() and
244244 // ConnectionSettings::setTlsClientCertificateKeyFile() to be used as well.
245245 ->setTlsClientCertificateKeyPassphrase(null);
246+
247+ // The TLS ALPN is used to establish a TLS encrypted mqtt connection on port 443,
248+ // which usually is reserved for TLS encrypted HTTP traffic.
249+ ->setTlsAlpn(null);
246250```
247251
248252## Features
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class ConnectionSettings
3737 private ?string $ tlsClientCertificateFile = null ;
3838 private ?string $ tlsClientCertificateKeyFile = null ;
3939 private ?string $ tlsClientCertificateKeyPassphrase = null ;
40+ private ?string $ tlsAlpn = null ;
4041
4142 /**
4243 * The username used for authentication when connecting to the broker.
@@ -531,4 +532,25 @@ public function getTlsClientCertificateKeyPassphrase(): ?string
531532 {
532533 return $ this ->tlsClientCertificateKeyPassphrase ;
533534 }
535+
536+ /**
537+ * The TLS ALPN is used to establish a TLS encrypted mqtt connection on port 443,
538+ * which usually is reserved for TLS encrypted HTTP traffic.
539+ *
540+ * @return ConnectionSettings A copy of the original object with the new setting applied.
541+ */
542+ public function setTlsAlpn (?string $ tlsAlpn ): ConnectionSettings
543+ {
544+ $ copy = clone $ this ;
545+
546+ $ copy ->tlsAlpn = $ tlsAlpn ;
547+
548+ return $ copy ;
549+ }
550+
551+ public function getTlsAlpn (): ?string
552+ {
553+ return $ this ->tlsAlpn ;
554+ }
555+
534556}
Original file line number Diff line number Diff line change @@ -197,6 +197,10 @@ protected function establishSocketConnection(): void
197197 $ tlsOptions ['passphrase ' ] = $ this ->settings ->getTlsClientCertificateKeyPassphrase ();
198198 }
199199
200+ if ($ this ->settings ->getTlsAlpn () !== null ) {
201+ $ tlsOptions ['alpn_protocols ' ] = $ this ->settings ->getTlsAlpn ();
202+ }
203+
200204 $ contextOptions ['ssl ' ] = $ tlsOptions ;
201205 }
202206
You can’t perform that action at this time.
0 commit comments