Skip to content

Commit

Permalink
Merge pull request #15 from joshuastorch/feat/upstream-mqtts-no-cert
Browse files Browse the repository at this point in the history
Upstream MQTTS without client certificate
  • Loading branch information
windBlaze authored Aug 20, 2023
2 parents 023e9e6 + 91fc4a0 commit 6f1d0ff
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ioxy/mqtt-session.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,20 @@ func (session *Session) forwardHalf(way string, c1 net.Conn, c2 net.Conn) {
func (session *Session) DialOutbound() error {
addr := mqttBrokerHost + ":" + strconv.Itoa(mqttBrokerPort)
if mqttBrokerTLS {
cert, err := tls.X509KeyPair([]byte(mqttBrokerClientCert), []byte(mqttBrokerClientKey))
if err != nil {
log.Fatalf("server: loadkeys: %s", err)
return err
config := tls.Config{InsecureSkipVerify: true}
if mqttBrokerClientCert != "" && mqttBrokerClientKey != "" {
cert, err := tls.X509KeyPair([]byte(mqttBrokerClientCert), []byte(mqttBrokerClientKey))
if err != nil {
log.Fatalf("server: loadkeys: %s", err)
return err
}
config.Certificates = []tls.Certificate{cert}
} else {
log.Info("Establishing mqtts connection to upstream without client certificate")
}
var config tls.Config
if amazonMqttProtocol {
// Check if CA is needed
config = tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true, NextProtos: []string{"x-amzn-mqtt-ca"}}
} else {
config = tls.Config{Certificates: []tls.Certificate{cert}, InsecureSkipVerify: true}
config.NextProtos = []string{"x-amzn-mqtt-ca"}
}
client, err := tls.Dial("tcp", addr, &config)
if err != nil {
Expand Down

0 comments on commit 6f1d0ff

Please sign in to comment.