Skip to content

Commit

Permalink
add random characters to clientID
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Nov 15, 2024
1 parent cf600ac commit cc1f9e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/eclipse/paho.mqtt.golang v1.5.0
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/google/uuid v1.6.0
github.com/gopcua/opcua v0.5.3
github.com/kr/pretty v0.3.1 // indirect
github.com/kr/text v0.2.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-github/v50 v50.2.0/go.mod h1:VBY8FB6yPIjrtKhozXv4FQupxKLS6H4m6xFZlT43q8Q=
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gopcua/opcua v0.5.3 h1:K5QQhjK9KQxQW8doHL/Cd8oljUeXWnJJsNgP7mOGIhw=
github.com/gopcua/opcua v0.5.3/go.mod h1:nrVl4/Rs3SDQRhNQ50EbAiI5JSpDrTG6Frx3s4HLnw4=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
Expand Down
10 changes: 8 additions & 2 deletions modules/mqtt/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"sync"

paho "github.com/eclipse/paho.mqtt.golang"
"github.com/google/uuid"
"github.com/zmap/zgrab2"
)

Expand Down Expand Up @@ -59,8 +60,12 @@ func (s *scan) getBrokerURL() string {
}

func (s *scan) getClientOptions() (*paho.ClientOptions, error) {
// we may jump into the same host. Avoid weird issues
id := uuid.New()
uid := fmt.Sprintf("%s-%s", s.scanner.config.ClientID, id[:6])

opts := paho.NewClientOptions().
SetClientID(s.scanner.config.ClientID).
SetClientID(uid).
SetCleanSession(true).
SetAutoReconnect(true).
SetOrderMatters(false)
Expand Down Expand Up @@ -121,7 +126,8 @@ func (s *scan) makeMessageHandler() func(c paho.Client, m paho.Message) {
var handler = func(c paho.Client, m paho.Message) {
topic := m.Topic()
if isFull(topic) {
// ignore the message
// unsubscribe and ignore the message
c.Unsubscribe(topic)
return
}

Expand Down

0 comments on commit cc1f9e7

Please sign in to comment.