Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSL ALPN protocol support (CLI & Web) #1403

Merged
merged 4 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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
```

Expand Down Expand Up @@ -191,6 +191,7 @@ mqttx conn --help
| --cert <PATH> | path to the cert file |
| --ca <PATH> | path to the ca certificate |
| --insecure | do not verify the server certificate |
| --alpn <PROTO...> | set one or multiple ALPN (Application Layer Protocol Negotiation) protocols |
| -rp, --reconnect-period <MILLISECONDS> | interval between two reconnections, disable auto reconnect by setting to 0 (default: 1000ms) |
| --maximum-reconnect-times <NUMBER> | the maximum reconnect times (default: 10) |
| -up, --user-properties <USERPROPERTIES...> | the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli") |
Expand Down Expand Up @@ -242,6 +243,7 @@ mqttx sub --help
| --cert <PATH> | path to the cert file |
| --ca | path to the ca certificate |
| --insecure | do not verify the server certificate |
| --alpn <PROTO...> | set one or multiple ALPN (Application Layer Protocol Negotiation) protocols |
| -rp, --reconnect-period <MILLISECONDS> | interval between two reconnections, disable auto reconnect by setting to 0 (default: 1000ms) |
| --maximum-reconnect-times <NUMBER> | the maximum reconnect times (default: 10) |
| -up, --user-properties <USERPROPERTIES...> | the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli") |
Expand Down Expand Up @@ -301,6 +303,7 @@ mqttx pub --help
| --cert <PATH> | path to the cert file |
| --ca | path to the ca certificate |
| --insecure | do not verify the server certificate |
| --alpn <PROTO...> | set one or multiple ALPN (Application Layer Protocol Negotiation) protocols |
| -rp, --reconnect-period <MILLISECONDS> | interval between two reconnections, disable auto reconnect by setting to 0 (default: 1000ms) |
| --maximum-reconnect-times <NUMBER> | the maximum reconnect times (default: 10) |
| -up, --user-properties <USERPROPERTIES...> | the user properties of MQTT 5.0 (e.g. -up "name: mqttx cli") |
Expand Down
7 changes: 7 additions & 0 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down Expand Up @@ -152,6 +153,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down Expand Up @@ -249,6 +251,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down Expand Up @@ -325,6 +328,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down Expand Up @@ -423,6 +427,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down Expand Up @@ -510,6 +515,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down Expand Up @@ -610,6 +616,7 @@ export class Commander {
.option('--cert <PATH>', 'path to the cert file')
.option('--ca <PATH>', 'path to the ca certificate')
.option('--insecure', 'do not verify the server certificate')
.option('--alpn <PROTO...>', 'set one or multiple ALPN (Application Layer Protocol Negotiation) protocols')
.option(
'-rp, --reconnect-period <MILLISECONDS>',
'interval between two reconnections, disable auto reconnect by setting to 0',
Expand Down
1 change: 1 addition & 0 deletions cli/src/lib/pub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions cli/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare global {
cert?: string
ca?: string
insecure?: boolean
alpn?: string[]
reconnectPeriod: number
maximumReconnectTimes: number
// properties of MQTT 5.0
Expand Down
5 changes: 5 additions & 0 deletions cli/src/utils/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ const parseConnectOptions = (
cert,
ca,
insecure,
alpn,
reconnectPeriod,
sessionExpiryInterval,
receiveMaximum,
Expand Down Expand Up @@ -215,6 +216,10 @@ const parseConnectOptions = (
connectOptions.rejectUnauthorized = false
}

if (alpn) {
connectOptions.ALPNProtocols = alpn
}

if (willTopic) {
const will = {
topic: willTopic,
Expand Down
1 change: 1 addition & 0 deletions web/src/types/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ declare global {

interface SSLPath {
rejectUnauthorized?: boolean
ALPNProtocols?: string | null
ca: string
cert: string
key: string
Expand Down
6 changes: 6 additions & 0 deletions web/src/utils/mqttUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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(','))
ysfscream marked this conversation as resolved.
Show resolved Hide resolved
options.ALPNProtocols = ALPNProtocols.replace(/[\[\] ]/g, '').split(',')
}
if (certType === 'self') {
const sslRes: SSLContent | undefined = getSSLFile({
ca: record.ca,
Expand Down Expand Up @@ -158,6 +163,7 @@ export const getDefaultRecord = (): ConnectionModel => {
ssl: false,
certType: '',
rejectUnauthorized: true,
ALPNProtocols: '',
ca: '',
cert: '',
key: '',
Expand Down
8 changes: 6 additions & 2 deletions web/src/views/connections/ConnectionForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@
</el-form-item>
</el-col>
<el-col :span="2"> </el-col>
<el-col :span="22">
<el-form-item label-width="93px" label="ALPN" prop="ALPNProtocols">
<el-input size="mini" clearable v-model.trim="record.ALPNProtocols"></el-input>
</el-form-item>
</el-col>
<el-col :span="2"></el-col>
</template>
</el-row>
</el-card>
Expand Down Expand Up @@ -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') }],
}
}

Expand Down