All of these answers are incorrect! Do not use InsecureSkipVerify to work with a CN that does not match the host name. Go developers were unreasonable, not refusing to verify the host name (which has legitimate uses - tunnels, nats, general cluster certificates, etc.), and also have something similar, but actually completely ignore certificate verification. You must know that the certificate is valid and signed by a certificate that you trust. But in common scenarios, you know that CN will not match the host name you are associated with. For them, set ServerName to tls.Config. If tls.Config.ServerName == remoteServerCN, then certificate verification will be successful. Is this what you want. InsecureSkipVerify means no authentication; and he is ripe for Man-in-the-Middle; defeating the goal of using TLS.
There is one legitimate use for InsecureSkipVerify ... Use it to connect to the host and obtain its certificate, and then disconnect it immediately. If you configure your code to use InsecureSkipVerify, this is usually because you did not set the server_name correctly (it will need to switch from env var or something else - do not be afraid of this requirement ... do it right).
In particular, if you use client certificates and rely on them for authentication, you basically have a fake login that is no longer registered. The failure code that InsecureSkipVerify does, or you'll find out what's not so difficult with it!
Rob Nov 08 '17 at 1:12
source share