Skip to content

Commit

Permalink
Merge pull request #4 from Tristan971/add-sni-support
Browse files Browse the repository at this point in the history
Add SNI support
  • Loading branch information
tuladhar authored Dec 17, 2023
2 parents 3b6fb0b + dad0a20 commit 60ddb58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions internal/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ func (s *SSLHandshake) SetUsage() {
fmt.Println()
fmt.Println("Options:")
fmt.Printf(" -t <timeout> SSL handshake timeout in milliseconds (default: %d)\n", s.Config.Timeout)
fmt.Printf(" -n <name> Server name indication value (default: unset)\n")
fmt.Printf(" -c <count> Stop after <count> SSL handshakes (default: %d)\n", s.Config.StopCount)
fmt.Printf(" -i <interval> Wait <interval> milliseconds between SSL handshakes (default: %d)\n", s.Config.Interval)
fmt.Println()
fmt.Println("Examples:")
fmt.Printf(" %s tuladhar.github.com:443\n", s.Metadata.Name)
fmt.Printf(" %s -n dns.google 8.8.8.8:443\n", s.Metadata.Name)
fmt.Printf(" %s -c 3 -i 500 tuladhar.github.com:443\n", s.Metadata.Name)
fmt.Printf(" %s -t 500 imap.gmail.com:993\n", s.Metadata.Name)
}
Expand All @@ -30,6 +32,7 @@ func (s *SSLHandshake) ParseFlag() {
flag.Int64Var(&s.Config.Timeout, "t", s.Config.Timeout, "")
flag.Int64Var(&s.Config.StopCount, "c", s.Config.StopCount, "")
flag.Int64Var(&s.Config.Interval, "i", s.Config.Interval, "")
flag.StringVar(&s.Config.ServerName, "n", "", "")

flag.Parse()
if len(flag.Args()) != 1 {
Expand Down
12 changes: 8 additions & 4 deletions internal/sslhandshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ type SSLHandshakeMetadata struct {
}

type SSLHandshakeConfig struct {
Endpoint string
Interval int64
Timeout int64
StopCount int64
Endpoint string
Interval int64
ServerName string
StopCount int64
Timeout int64
}

type SSLHandshakeState struct {
Expand Down Expand Up @@ -53,6 +54,9 @@ func (s *SSLHandshake) DoHandshake() (int64, uint16, int64, error) {
tlsConfig := tls.Config{
InsecureSkipVerify: true,
}
if s.Config.ServerName != "" {
tlsConfig.ServerName = s.Config.ServerName
}

tcpConn, tcpTime, tcpErr := s.EstablishTcp()
if tcpErr != nil {
Expand Down
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ func main() {
URL: "https://github.com/tuladhar/ssl-handshake",
},
Config: &sslhandshake.SSLHandshakeConfig{
Endpoint: "",
Interval: 1000,
Timeout: 5000,
StopCount: 0,
Endpoint: "",
Interval: 1000,
ServerName: "",
StopCount: 0,
Timeout: 5000,
},
State: &sslhandshake.SSLHandshakeState{},
}
Expand Down

0 comments on commit 60ddb58

Please sign in to comment.