Skip to content

Commit

Permalink
feat(web): 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 6d9a1db commit f3ac723
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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(','))
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

0 comments on commit f3ac723

Please sign in to comment.