-
-
Save giridharmb/2ce4e81fcd2caa992bbbcab9734a4e32 to your computer and use it in GitHub Desktop.
golang tls connection with TLS 1.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package onboarding_test | |
| import ( | |
| "crypto/tls" | |
| "log" | |
| "net" | |
| "net/http" | |
| "testing" | |
| ) | |
| func TestTls(t *testing.T) { | |
| var ( | |
| conn *tls.Conn | |
| err error | |
| ) | |
| // tlsConfig := http.DefaultTransport.(*http.Transport).TLSClientConfig | |
| tlsConfig := &tls.Config{ | |
| MaxVersion: tls.VersionTLS12, | |
| } | |
| // tlsConfig.MaxVersion = tls.VersionTLS12 | |
| c := &http.Client{ | |
| Transport: &http.Transport{ | |
| DialTLS: func(network, addr string) (net.Conn, error) { | |
| conn, err = tls.Dial(network, addr, tlsConfig) | |
| return conn, err | |
| }, | |
| }, | |
| } | |
| res, err := c.Get("https://edesoft.com") | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| versions := map[uint16]string{ | |
| tls.VersionSSL30: "SSL", | |
| tls.VersionTLS10: "TLS 1.0", | |
| tls.VersionTLS11: "TLS 1.1", | |
| tls.VersionTLS12: "TLS 1.2", | |
| tls.VersionTLS13: "TLS 1.3", | |
| } | |
| t.Log(res.Request.URL) | |
| t.Log(res.Status) | |
| v := conn.ConnectionState().Version | |
| t.Logf("version: %d", v) | |
| t.Log(versions[v]) | |
| res.Body.Close() | |
| } | |
| // Output: | |
| // https://edesoft.com | |
| // 200 OK | |
| // version: 771 | |
| // TLS 1.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment