Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a https request with bad certificate?

Tags:

https

ssl

go

Say I want to get https://golang.org programatically. Currently golang.org (ssl) has a bad certificate which is issued to *.appspot.com So when I run this:

package main  import (     "log"     "net/http" )  func main() {     _, err := http.Get("https://golang.org/")     if err != nil {         log.Fatal(err)     } } 

I get (as I expected)

Get https://golang.org/: certificate is valid for *.appspot.com, *.*.appspot.com, appspot.com, not golang.org 

Now, I want to trust this certificate myself (imagine a self-issued certificate where I can validate fingerprint etc.): how can I make a request and validate/trust the certificate?

I probably need to use openssl to download the certificate, load it into my file and fill tls.Config struct !?

like image 873
topskip Avatar asked Aug 25 '12 12:08

topskip


People also ask

Can you use https without a certificate?

Nope. What you're doing when using HTTPS is telling the browser to connect via a different port (443) whereas normally you connect via (80). Without a certificate, the server would refuse the connection. HTTPS is simply not possible without a certificate.


1 Answers

Security note: Disabling security checks is dangerous and should be avoided

You can disable security checks globally for all requests of the default client:

package main  import (     "fmt"     "net/http"     "crypto/tls" )  func main() {     http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}     _, err := http.Get("https://golang.org/")     if err != nil {         fmt.Println(err)     } } 

You can disable security check for a client:

package main  import (     "fmt"     "net/http"     "crypto/tls" )  func main() {     tr := &http.Transport{         TLSClientConfig: &tls.Config{InsecureSkipVerify: true},     }     client := &http.Client{Transport: tr}     _, err := client.Get("https://golang.org/")     if err != nil {         fmt.Println(err)     } } 
like image 95
cyberdelia Avatar answered Oct 13 '22 00:10

cyberdelia