Skip to content

Commit

Permalink
feat(cli): ssl ALPN protocol support
Browse files Browse the repository at this point in the history
  • Loading branch information
ysfscream committed Aug 30, 2023
1 parent f3ac723 commit 2232731
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
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

0 comments on commit 2232731

Please sign in to comment.