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") | 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, 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..97f01bc4b 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,9 @@ const getClientOptions = (record: ConnectionModel): IClientOptions => { // SSL if (ssl) { options.rejectUnauthorized = rejectUnauthorized === undefined ? true : rejectUnauthorized + if (ALPNProtocols) { + options.ALPNProtocols = ALPNProtocols.replace(/[\[\] ]/g, '').split(',') + } if (certType === 'self') { const sslRes: SSLContent | undefined = getSSLFile({ ca: record.ca, @@ -158,6 +162,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') }], } }