~juju-qa/ubuntu/xenial/juju/xenial-2.0-beta3

« back to all changes in this revision

Viewing changes to src/github.com/lxc/lxd/shared/network.go

  • Committer: Martin Packman
  • Date: 2016-03-30 19:31:08 UTC
  • mfrom: (1.1.41)
  • Revision ID: martin.packman@canonical.com-20160330193108-h9iz3ak334uk0z5r
Merge new upstream source 2.0~beta3

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
        "io"
9
9
        "io/ioutil"
10
10
        "net"
11
 
        "net/http"
12
11
        "time"
13
12
 
14
13
        "github.com/gorilla/websocket"
34
33
        return nil, fmt.Errorf("Unable to connect to: " + address)
35
34
}
36
35
 
37
 
func GetRemoteCertificate(address string) (*x509.Certificate, error) {
38
 
        // Setup a permissive TLS config
39
 
        tlsConfig, err := GetTLSConfig("", "", nil)
40
 
        if err != nil {
41
 
                return nil, err
42
 
        }
43
 
 
44
 
        tlsConfig.InsecureSkipVerify = true
45
 
        tr := &http.Transport{
46
 
                TLSClientConfig: tlsConfig,
47
 
                Dial:            RFC3493Dialer,
48
 
                Proxy:           http.ProxyFromEnvironment,
49
 
        }
50
 
 
51
 
        // Connect
52
 
        client := &http.Client{Transport: tr}
53
 
        resp, err := client.Get(address)
54
 
        if err != nil {
55
 
                return nil, err
56
 
        }
57
 
 
58
 
        // Retrieve the certificate
59
 
        if resp.TLS == nil || len(resp.TLS.PeerCertificates) == 0 {
60
 
                return nil, fmt.Errorf("Unable to read remote TLS certificate")
61
 
        }
62
 
 
63
 
        return resp.TLS.PeerCertificates[0], nil
64
 
}
65
 
 
66
36
func initTLSConfig() *tls.Config {
67
37
        return &tls.Config{
68
38
                MinVersion: tls.VersionTLS12,