From f3ac723ed83bd4f80bcee4157ad23ec00839a574 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Wed, 30 Aug 2023 16:03:50 +0800 Subject: [PATCH 1/4] feat(web): ssl ALPN protocol support --- web/src/types/global.d.ts | 1 + web/src/utils/mqttUtils.ts | 6 ++++++ web/src/views/connections/ConnectionForm.vue | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/web/src/types/global.d.ts b/web/src/types/global.d.ts index b4813a701..93738b8cb 100644 --- a/web/src/types/global.d.ts +++ b/web/src/types/global.d.ts @@ -246,6 +246,7 @@ declare global { interface SSLPath { rejectUnauthorized?: boolean + ALPNProtocols?: string | null ca: string cert: string key: string diff --git a/web/src/utils/mqttUtils.ts b/web/src/utils/mqttUtils.ts index a3e464103..bcfdae5e6 100644 --- a/web/src/utils/mqttUtils.ts +++ b/web/src/utils/mqttUtils.ts @@ -40,6 +40,7 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => { reconnectPeriod, // reconnectPeriod = 0 disabled automatic reconnection in the client will, rejectUnauthorized, + ALPNProtocols, clientIdWithTime, } = record const protocolVersion = mqttVersionDict[mqttVersion] @@ -76,6 +77,10 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => { // SSL if (ssl) { options.rejectUnauthorized = rejectUnauthorized === undefined ? true : rejectUnauthorized + if (ALPNProtocols) { + console.log(ALPNProtocols.replace(/[\[\] ]/g, '').split(',')) + options.ALPNProtocols = ALPNProtocols.replace(/[\[\] ]/g, '').split(',') + } if (certType === 'self') { const sslRes: SSLContent | undefined = getSSLFile({ ca: record.ca, @@ -158,6 +163,7 @@ export const getDefaultRecord = (): ConnectionModel => { ssl: false, certType: '', rejectUnauthorized: true, + ALPNProtocols: '', ca: '', cert: '', key: '', diff --git a/web/src/views/connections/ConnectionForm.vue b/web/src/views/connections/ConnectionForm.vue index dfcbfc4a2..851c67f4e 100644 --- a/web/src/views/connections/ConnectionForm.vue +++ b/web/src/views/connections/ConnectionForm.vue @@ -163,6 +163,12 @@ + + + + + + @@ -563,8 +569,6 @@ export default class ConnectionCreate extends Vue { path: [{ required: true, message: this.$t('common.inputRequired') }], host: [{ required: true, message: this.$t('common.inputRequired') }], port: [{ required: true, message: this.$t('common.inputRequired') }], - certType: [{ required: true, message: this.$t('common.selectRequired') }], - ca: [{ required: true, message: this.$t('common.inputRequired') }], } } From 22327316be67c92f121b6cae1dff8f27949056f6 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Wed, 30 Aug 2023 17:03:59 +0800 Subject: [PATCH 2/4] feat(cli): ssl ALPN protocol support --- cli/src/index.ts | 7 +++++++ cli/src/lib/pub.ts | 1 + cli/src/types/global.d.ts | 1 + cli/src/utils/parse.ts | 5 +++++ 4 files changed, 14 insertions(+) diff --git a/cli/src/index.ts b/cli/src/index.ts index 4c183f23c..b400fa2c6 100755 --- a/cli/src/index.ts +++ b/cli/src/index.ts @@ -59,6 +59,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', @@ -152,6 +153,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', @@ -249,6 +251,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', @@ -325,6 +328,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', @@ -423,6 +427,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', @@ -510,6 +515,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', @@ -610,6 +616,7 @@ export class Commander { .option('--cert ', 'path to the cert file') .option('--ca ', 'path to the ca certificate') .option('--insecure', 'do not verify the server certificate') + .option('--alpn ', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols') .option( '-rp, --reconnect-period ', 'interval between two reconnections, disable auto reconnect by setting to 0', diff --git a/cli/src/lib/pub.ts b/cli/src/lib/pub.ts index 8390dc3b2..d4cb4a335 100644 --- a/cli/src/lib/pub.ts +++ b/cli/src/lib/pub.ts @@ -10,6 +10,7 @@ import delay from '../utils/delay' import { saveConfig, loadConfig } from '../utils/config' import { loadSimulator } from '../utils/simulate' import { serializeProtobufToBuffer } from '../utils/protobuf' + const send = ( config: boolean | string | undefined, connOpts: IClientOptions, diff --git a/cli/src/types/global.d.ts b/cli/src/types/global.d.ts index 068620f13..609ab26af 100644 --- a/cli/src/types/global.d.ts +++ b/cli/src/types/global.d.ts @@ -28,6 +28,7 @@ declare global { cert?: string ca?: string insecure?: boolean + alpn?: string[] reconnectPeriod: number maximumReconnectTimes: number // properties of MQTT 5.0 diff --git a/cli/src/utils/parse.ts b/cli/src/utils/parse.ts index 5cbbcb62e..aa7cbbc48 100644 --- a/cli/src/utils/parse.ts +++ b/cli/src/utils/parse.ts @@ -161,6 +161,7 @@ const parseConnectOptions = ( cert, ca, insecure, + alpn, reconnectPeriod, sessionExpiryInterval, receiveMaximum, @@ -215,6 +216,10 @@ const parseConnectOptions = ( connectOptions.rejectUnauthorized = false } + if (alpn) { + connectOptions.ALPNProtocols = alpn + } + if (willTopic) { const will = { topic: willTopic, From 60555dcaa1d2d1d46240f0cfe1c4aabb74b1a9c7 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Wed, 30 Aug 2023 17:29:48 +0800 Subject: [PATCH 3/4] docs(readme): update cli readme --- cli/README.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/cli/README.md b/cli/README.md index 9ec797338..71032fc74 100644 --- a/cli/README.md +++ b/cli/README.md @@ -36,14 +36,14 @@ To install the latest MQTTX CLI stable release on **macOS** using **binary downl #### Intel Chip ```shell -curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.3/mqttx-cli-macos-x64 +curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.5/mqttx-cli-macos-x64 sudo install ./mqttx-cli-macos-x64 /usr/local/bin/mqttx ``` #### Apple Silicon ```shell -curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.3/mqttx-cli-macos-arm64 +curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.5/mqttx-cli-macos-arm64 sudo install ./mqttx-cli-macos-arm64 /usr/local/bin/mqttx ``` @@ -62,14 +62,14 @@ To install the latest MQTTX CLI stable release on **Linux** using **binary downl #### x86-64 ```shell -curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.3/mqttx-cli-linux-x64 +curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.5/mqttx-cli-linux-x64 sudo install ./mqttx-cli-linux-x64 /usr/local/bin/mqttx ``` #### ARM64 ```shell -curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.3/mqttx-cli-linux-arm64 +curl -LO https://www.emqx.com/en/downloads/MQTTX/v1.9.5/mqttx-cli-linux-arm64 sudo install ./mqttx-cli-linux-arm64 /usr/local/bin/mqttx ``` @@ -191,6 +191,7 @@ mqttx conn --help | --cert | path to the cert file | | --ca | path to the ca certificate | | --insecure | do not verify the server certificate | +| --alpn | set one or multiple ALPN (Application Layer Protocol Negotiation) protocols | | -rp, --reconnect-period | interval between two reconnections, disable auto reconnect by setting to 0 (default: 1000ms) | | --maximum-reconnect-times | the maximum reconnect times (default: 10) | | -up, --user-properties | the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli") | @@ -242,6 +243,7 @@ mqttx sub --help | --cert | path to the cert file | | --ca | path to the ca certificate | | --insecure | do not verify the server certificate | +| --alpn | set one or multiple ALPN (Application Layer Protocol Negotiation) protocols | | -rp, --reconnect-period | interval between two reconnections, disable auto reconnect by setting to 0 (default: 1000ms) | | --maximum-reconnect-times | the maximum reconnect times (default: 10) | | -up, --user-properties | the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli") | @@ -301,6 +303,7 @@ mqttx pub --help | --cert | path to the cert file | | --ca | path to the ca certificate | | --insecure | do not verify the server certificate | +| --alpn | set one or multiple ALPN (Application Layer Protocol Negotiation) protocols | | -rp, --reconnect-period | interval between two reconnections, disable auto reconnect by setting to 0 (default: 1000ms) | | --maximum-reconnect-times | the maximum reconnect times (default: 10) | | -up, --user-properties | the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli") | From fb99b59407f5bc96a053b5fcc2ba204c6b306b30 Mon Sep 17 00:00:00 2001 From: YuShifan <894402575bt@gmail.com> Date: Thu, 31 Aug 2023 10:28:08 +0800 Subject: [PATCH 4/4] fix(mqtt): remove console log --- web/src/utils/mqttUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/web/src/utils/mqttUtils.ts b/web/src/utils/mqttUtils.ts index bcfdae5e6..97f01bc4b 100644 --- a/web/src/utils/mqttUtils.ts +++ b/web/src/utils/mqttUtils.ts @@ -78,7 +78,6 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => { if (ssl) { options.rejectUnauthorized = rejectUnauthorized === undefined ? true : rejectUnauthorized if (ALPNProtocols) { - console.log(ALPNProtocols.replace(/[\[\] ]/g, '').split(',')) options.ALPNProtocols = ALPNProtocols.replace(/[\[\] ]/g, '').split(',') } if (certType === 'self') {