File tree 3 files changed +30
-0
lines changed
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)
243
243
// This option requires ConnectionSettings::setTlsClientCertificateFile() and
244
244
// ConnectionSettings::setTlsClientCertificateKeyFile() to be used as well.
245
245
->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);
246
250
```
247
251
248
252
## Features
Original file line number Diff line number Diff line change @@ -37,6 +37,7 @@ class ConnectionSettings
37
37
private ?string $ tlsClientCertificateFile = null ;
38
38
private ?string $ tlsClientCertificateKeyFile = null ;
39
39
private ?string $ tlsClientCertificateKeyPassphrase = null ;
40
+ private ?string $ tlsAlpn = null ;
40
41
41
42
/**
42
43
* The username used for authentication when connecting to the broker.
@@ -531,4 +532,25 @@ public function getTlsClientCertificateKeyPassphrase(): ?string
531
532
{
532
533
return $ this ->tlsClientCertificateKeyPassphrase ;
533
534
}
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
+
534
556
}
Original file line number Diff line number Diff line change @@ -197,6 +197,10 @@ protected function establishSocketConnection(): void
197
197
$ tlsOptions ['passphrase ' ] = $ this ->settings ->getTlsClientCertificateKeyPassphrase ();
198
198
}
199
199
200
+ if ($ this ->settings ->getTlsAlpn () !== null ) {
201
+ $ tlsOptions ['alpn_protocols ' ] = $ this ->settings ->getTlsAlpn ();
202
+ }
203
+
200
204
$ contextOptions ['ssl ' ] = $ tlsOptions ;
201
205
}
202
206
You can’t perform that action at this time.
0 commit comments