Golang : Use TLS version 1.2 and enforce server security configuration over client
Problem:
You want to force your Golang program to use TLS(Transport Layer Security) protocol version 1.2 only and use server TLS configuration instead of client. How to do that?
Solution:
Set the MinVersion, MaxVersion parameters to tls.VersionTLS12
and PreferServerCipherSuites to true
. Setting PreferServerCipherSuites will force client to use server TLS configuration.
config.MinVersion = tls.VersionTLS12
config.MaxVersion = tls.VersionTLS12
config.PreferServerCipherSuites = true
For example:
config := tls.Config{Certificates : []tls.Certificate{certificate}, ClientAuth: tls.RequireAnyClientCert}
config.CipherSuites = []uint16{
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256}
config.MinVersion = tls.VersionTLS12
config.MaxVersion = tls.VersionTLS12
config.PreferServerCipherSuites = true
References:
See also : Golang : Use modern ciphers only in secure connection
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+8.7k Golang : Accept any number of function arguments with three dots(...)
+8.4k Golang : Ackermann function example
+5.9k Golang : Missing Subversion command
+11.2k Golang : Post data with url.Values{}
+12.2k Golang : How to check if a string starts or ends with certain characters or words?
+5.1k Golang : Calculate half life decay example
+3.3k Golang : Fix go-cron set time not working issue
+8k Android Studio : Rating bar example
+22.4k Golang : Convert Unix timestamp to UTC timestamp
+21.4k Golang : Encrypt and decrypt data with TripleDES
+8.2k Golang: Prevent over writing file with md5 hash
+5.9k Golang : Compound interest over time example