mirror of https://github.com/docker/docs.git
				
				
				
			Merge pull request #538 from docker/add-docker-go-connections
Add the github.com/docker/go-connections/tlsconfig dependency to godeps
This commit is contained in:
		
						commit
						f744660f49
					
				|  | @ -1,6 +1,6 @@ | |||
| { | ||||
| 	"ImportPath": "github.com/docker/notary", | ||||
| 	"GoVersion": "go1.5.1", | ||||
| 	"GoVersion": "go1.5.2", | ||||
| 	"Packages": [ | ||||
| 		"./..." | ||||
| 	], | ||||
|  | @ -95,6 +95,16 @@ | |||
| 			"Comment": "v1.7.1", | ||||
| 			"Rev": "786b29d4db80a6175e72b47a794ee044918ba734" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/docker/go-connections/tlsconfig", | ||||
| 			"Comment": "v0.1.2-6-gd834a4d", | ||||
| 			"Rev": "d834a4de0c32df550d39ff9d5a66b741367a008a" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/docker/go/canonical/json", | ||||
| 			"Comment": "v1.5.1-1-1-gbaf439e", | ||||
| 			"Rev": "baf439e6c161bd2106346fc8022b74ac2444e311" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/docker/libtrust", | ||||
| 			"Rev": "fa567046d9b14f6aa788882a950d69651d230b21" | ||||
|  | @ -129,11 +139,6 @@ | |||
| 			"ImportPath": "github.com/inconshreveable/mousetrap", | ||||
| 			"Rev": "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/docker/go/canonical/json", | ||||
| 			"Comment": "v1.5.1-1-1-gbaf439e", | ||||
| 			"Rev": "baf439e6c161bd2106346fc8022b74ac2444e311" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/jinzhu/gorm", | ||||
| 			"Rev": "82d726bbfd8cefbe2dcdc7f7f0484551c0d40433" | ||||
|  | @ -166,10 +171,6 @@ | |||
| 			"ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil", | ||||
| 			"Rev": "d0c3fe89de86839aecf2e0579c40ba3bb336a453" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/miekg/pkcs11", | ||||
| 			"Rev": "88c9f842544e629ec046105d7fb50d5daafae737" | ||||
| 		}, | ||||
| 		{ | ||||
| 			"ImportPath": "github.com/mitchellh/go-homedir", | ||||
| 			"Rev": "df55a15e5ce646808815381b3db47a8c66ea62f4" | ||||
|  |  | |||
							
								
								
									
										127
									
								
								Godeps/_workspace/src/github.com/docker/go-connections/tlsconfig/config.go
								
								
									generated
								
								
									vendored
								
								
									Normal file
								
							
							
						
						
									
										127
									
								
								Godeps/_workspace/src/github.com/docker/go-connections/tlsconfig/config.go
								
								
									generated
								
								
									vendored
								
								
									Normal file
								
							|  | @ -0,0 +1,127 @@ | |||
| // Package tlsconfig provides primitives to retrieve secure-enough TLS configurations for both clients and servers.
 | ||||
| //
 | ||||
| // As a reminder from https://golang.org/pkg/crypto/tls/#Config:
 | ||||
| //	A Config structure is used to configure a TLS client or server. After one has been passed to a TLS function it must not be modified.
 | ||||
| //	A Config may be reused; the tls package will also not modify it.
 | ||||
| package tlsconfig | ||||
| 
 | ||||
| import ( | ||||
| 	"crypto/tls" | ||||
| 	"crypto/x509" | ||||
| 	"fmt" | ||||
| 	"io/ioutil" | ||||
| 	"os" | ||||
| 
 | ||||
| 	"github.com/Sirupsen/logrus" | ||||
| ) | ||||
| 
 | ||||
| // Options represents the information needed to create client and server TLS configurations.
 | ||||
| type Options struct { | ||||
| 	CAFile string | ||||
| 
 | ||||
| 	// If either CertFile or KeyFile is empty, Client() will not load them
 | ||||
| 	// preventing the client from authenticating to the server.
 | ||||
| 	// However, Server() requires them and will error out if they are empty.
 | ||||
| 	CertFile string | ||||
| 	KeyFile  string | ||||
| 
 | ||||
| 	// client-only option
 | ||||
| 	InsecureSkipVerify bool | ||||
| 	// server-only option
 | ||||
| 	ClientAuth tls.ClientAuthType | ||||
| } | ||||
| 
 | ||||
| // Extra (server-side) accepted CBC cipher suites - will phase out in the future
 | ||||
| var acceptedCBCCiphers = []uint16{ | ||||
| 	tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, | ||||
| 	tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, | ||||
| 	tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, | ||||
| 	tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, | ||||
| 	tls.TLS_RSA_WITH_AES_256_CBC_SHA, | ||||
| 	tls.TLS_RSA_WITH_AES_128_CBC_SHA, | ||||
| } | ||||
| 
 | ||||
| // DefaultServerAcceptedCiphers should be uses by code which already has a crypto/tls
 | ||||
| // options struct but wants to use a commonly accepted set of TLS cipher suites, with
 | ||||
| // known weak algorithms removed.
 | ||||
| var DefaultServerAcceptedCiphers = append(clientCipherSuites, acceptedCBCCiphers...) | ||||
| 
 | ||||
| // ServerDefault is a secure-enough TLS configuration for the server TLS configuration.
 | ||||
| var ServerDefault = tls.Config{ | ||||
| 	// Avoid fallback to SSL protocols < TLS1.0
 | ||||
| 	MinVersion:               tls.VersionTLS10, | ||||
| 	PreferServerCipherSuites: true, | ||||
| 	CipherSuites:             DefaultServerAcceptedCiphers, | ||||
| } | ||||
| 
 | ||||
| // ClientDefault is a secure-enough TLS configuration for the client TLS configuration.
 | ||||
| var ClientDefault = tls.Config{ | ||||
| 	// Prefer TLS1.2 as the client minimum
 | ||||
| 	MinVersion:   tls.VersionTLS12, | ||||
| 	CipherSuites: clientCipherSuites, | ||||
| } | ||||
| 
 | ||||
| // certPool returns an X.509 certificate pool from `caFile`, the certificate file.
 | ||||
| func certPool(caFile string) (*x509.CertPool, error) { | ||||
| 	// If we should verify the server, we need to load a trusted ca
 | ||||
| 	certPool := x509.NewCertPool() | ||||
| 	pem, err := ioutil.ReadFile(caFile) | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("Could not read CA certificate %q: %v", caFile, err) | ||||
| 	} | ||||
| 	if !certPool.AppendCertsFromPEM(pem) { | ||||
| 		return nil, fmt.Errorf("failed to append certificates from PEM file: %q", caFile) | ||||
| 	} | ||||
| 	s := certPool.Subjects() | ||||
| 	subjects := make([]string, len(s)) | ||||
| 	for i, subject := range s { | ||||
| 		subjects[i] = string(subject) | ||||
| 	} | ||||
| 	logrus.Debugf("Trusting certs with subjects: %v", subjects) | ||||
| 	return certPool, nil | ||||
| } | ||||
| 
 | ||||
| // Client returns a TLS configuration meant to be used by a client.
 | ||||
| func Client(options Options) (*tls.Config, error) { | ||||
| 	tlsConfig := ClientDefault | ||||
| 	tlsConfig.InsecureSkipVerify = options.InsecureSkipVerify | ||||
| 	if !options.InsecureSkipVerify && options.CAFile != "" { | ||||
| 		CAs, err := certPool(options.CAFile) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		tlsConfig.RootCAs = CAs | ||||
| 	} | ||||
| 
 | ||||
| 	if options.CertFile != "" || options.KeyFile != "" { | ||||
| 		tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile) | ||||
| 		if err != nil { | ||||
| 			return nil, fmt.Errorf("Could not load X509 key pair: %v. Make sure the key is not encrypted", err) | ||||
| 		} | ||||
| 		tlsConfig.Certificates = []tls.Certificate{tlsCert} | ||||
| 	} | ||||
| 
 | ||||
| 	return &tlsConfig, nil | ||||
| } | ||||
| 
 | ||||
| // Server returns a TLS configuration meant to be used by a server.
 | ||||
| func Server(options Options) (*tls.Config, error) { | ||||
| 	tlsConfig := ServerDefault | ||||
| 	tlsConfig.ClientAuth = options.ClientAuth | ||||
| 	tlsCert, err := tls.LoadX509KeyPair(options.CertFile, options.KeyFile) | ||||
| 	if err != nil { | ||||
| 		if os.IsNotExist(err) { | ||||
| 			return nil, fmt.Errorf("Could not load X509 key pair (cert: %q, key: %q): %v", options.CertFile, options.KeyFile, err) | ||||
| 		} | ||||
| 		return nil, fmt.Errorf("Error reading X509 key pair (cert: %q, key: %q): %v. Make sure the key is not encrypted.", options.CertFile, options.KeyFile, err) | ||||
| 	} | ||||
| 	tlsConfig.Certificates = []tls.Certificate{tlsCert} | ||||
| 	if options.ClientAuth >= tls.VerifyClientCertIfGiven { | ||||
| 		CAs, err := certPool(options.CAFile) | ||||
| 		if err != nil { | ||||
| 			return nil, err | ||||
| 		} | ||||
| 		tlsConfig.ClientCAs = CAs | ||||
| 	} | ||||
| 	return &tlsConfig, nil | ||||
| } | ||||
							
								
								
									
										17
									
								
								Godeps/_workspace/src/github.com/docker/go-connections/tlsconfig/config_client_ciphers.go
								
								
									generated
								
								
									vendored
								
								
									Normal file
								
							
							
						
						
									
										17
									
								
								Godeps/_workspace/src/github.com/docker/go-connections/tlsconfig/config_client_ciphers.go
								
								
									generated
								
								
									vendored
								
								
									Normal file
								
							|  | @ -0,0 +1,17 @@ | |||
| // +build go1.5
 | ||||
| 
 | ||||
| // Package tlsconfig provides primitives to retrieve secure-enough TLS configurations for both clients and servers.
 | ||||
| //
 | ||||
| package tlsconfig | ||||
| 
 | ||||
| import ( | ||||
| 	"crypto/tls" | ||||
| ) | ||||
| 
 | ||||
| // Client TLS cipher suites (dropping CBC ciphers for client preferred suite set)
 | ||||
| var clientCipherSuites = []uint16{ | ||||
| 	tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, | ||||
| 	tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, | ||||
| 	tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | ||||
| 	tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | ||||
| } | ||||
							
								
								
									
										15
									
								
								Godeps/_workspace/src/github.com/docker/go-connections/tlsconfig/config_legacy_client_ciphers.go
								
								
									generated
								
								
									vendored
								
								
									Normal file
								
							
							
						
						
									
										15
									
								
								Godeps/_workspace/src/github.com/docker/go-connections/tlsconfig/config_legacy_client_ciphers.go
								
								
									generated
								
								
									vendored
								
								
									Normal file
								
							|  | @ -0,0 +1,15 @@ | |||
| // +build !go1.5
 | ||||
| 
 | ||||
| // Package tlsconfig provides primitives to retrieve secure-enough TLS configurations for both clients and servers.
 | ||||
| //
 | ||||
| package tlsconfig | ||||
| 
 | ||||
| import ( | ||||
| 	"crypto/tls" | ||||
| ) | ||||
| 
 | ||||
| // Client TLS cipher suites (dropping CBC ciphers for client preferred suite set)
 | ||||
| var clientCipherSuites = []uint16{ | ||||
| 	tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, | ||||
| 	tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, | ||||
| } | ||||
		Loading…
	
		Reference in New Issue