Skip to content

Commit

Permalink
Attempt to detect TLS on non-standard ports in URL Publisher agent
Browse files Browse the repository at this point in the history
  • Loading branch information
michenriksen committed Jan 5, 2019
1 parent 0e70504 commit 517488d
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion agents/url_publisher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package agents

import (
"crypto/tls"
"fmt"
"net"
"time"

"github.com/michenriksen/aquatone/core"
)

Expand All @@ -24,6 +29,32 @@ func (a *URLPublisher) Register(s *core.Session) error {

func (a *URLPublisher) OnTCPPort(port int, host string) {
a.session.Out.Debug("[%s] Received new open port on %s: %d\n", a.ID(), host, port)
url := HostAndPortToURL(host, port, "")
var url string
if a.isTLS(port, host) {
url = HostAndPortToURL(host, port, "https")
} else {
url = HostAndPortToURL(host, port, "http")
}
a.session.EventBus.Publish(core.URL, url)
}

func (a *URLPublisher) isTLS(port int, host string) bool {
if port == 80 {
return false
}

if port == 443 {
return true
}

dialer := &net.Dialer{Timeout: time.Duration(*a.session.Options.HTTPTimeout) * time.Millisecond}
conf := &tls.Config{
InsecureSkipVerify: true,
}
conn, err := tls.DialWithDialer(dialer, "tcp", fmt.Sprintf("%s:%d", host, port), conf)
if err != nil {
return false
}
conn.Close()
return true
}

0 comments on commit 517488d

Please sign in to comment.