Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tls.Dial returns "too many colons in address"

Tags:

go

I am trying to loop through an array of addresses, and check their tls cert status. I pieced together a program from various examples that do other things.

My first step in processing is

conn, err := tls.Dial("tcp", url, nil)

where 'url' is passed in from the array (I do import crypto/tls). Before I go on to pulling the cert, I check for errors:

if err != nil { 
    log.Printf("Unable to get %q - %s\n", url, err)
    return
}

Here is a snippet of the array (with only test addresses for now):

var urls = []string{
    "https://google.com:443",
    "https://expired.badssl.com:443",
    "[https://wrong.host.badssl.com]:443",
    "[https://self-signed.badssl.com]:443"
}

The first 2 return too many colons in address I found a suggestion to fix that using the brackets. The next 2 addresses, with the brackets, return no such host

Where is my error?

like image 396
Roger Creasy Avatar asked May 15 '18 10:05

Roger Creasy


1 Answers

It should be domain name, IPv4 or IPv6 address with port only, not URL.

conn, err := tls.Dial("tcp", "mail.google.com:443", &tls.Config{
    RootCAs: roots,
})
like image 85
Grzegorz Żur Avatar answered Nov 11 '22 00:11

Grzegorz Żur