Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set tls version via chisel env vars #241

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ func NewClient(c *Config) (*Client, error) {
Outbound: hasReverse,
Socks: hasReverse && hasSocks,
})

tlsMin := settings.EnvTlsVersion("TLS_MIN_VER")
if tlsMin != 0 {
client.Infof("Setting tlsConfig.MinVersion to 0x%X", tlsMin)
client.tlsConfig.MinVersion = tlsMin
}

tlsMax := settings.EnvTlsVersion("TLS_MAX_VER")
if tlsMax != 0 {
client.Infof("Setting tlsConfig.MaxVersion to 0x%X", tlsMax)
client.tlsConfig.MaxVersion = tlsMax
}
return client, nil
}

Expand Down
11 changes: 11 additions & 0 deletions share/settings/env.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package settings

import (
"math"
"os"
"strconv"
"time"
Expand All @@ -26,3 +27,13 @@ func EnvDuration(name string, def time.Duration) time.Duration {
}
return def
}

//EnvTlsVersion returns a tls version protocol number
func EnvTlsVersion(name string) uint16 {
version := Env(name)
if n, err := strconv.ParseFloat(version, 64); err == nil {
version_number := math.Round(n*10) - 10
return uint16(0x301 + version_number) // conversion to TLS_VERSION (0x030x)
}
return 0
}