Skip to content

Commit b7fde80

Browse files
committed
Prevent go vet errors.
1 parent 1fd798c commit b7fde80

4 files changed

Lines changed: 28 additions & 17 deletions

File tree

config.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ type PerHostConfig struct {
7070
}
7171

7272
type MITMConfig struct {
73-
ServerTLSConfigTemplate tls.Config
74-
ClientTLSConfigTemplate tls.Config
73+
ServerTLSConfigTemplate *tls.Config
74+
ClientTLSConfigTemplate *tls.Config
7575
SigningCertificateKeyPair struct {
7676
Certificate *x509.Certificate
7777
PrivateKey crypto.PrivateKey
@@ -85,7 +85,7 @@ type ProxyConfig struct {
8585
HTTPSProxy *url.URL
8686
IncludedHosts []HostPortPair
8787
ExcludedHosts []HostPortPair
88-
TLSConfig tls.Config
88+
TLSConfig *tls.Config
8989
}
9090

9191
type Config struct {
@@ -348,6 +348,8 @@ func (ctx *ConfigReaderContext) extractProxyConfig(configMap map[string]interfac
348348
if err != nil {
349349
return
350350
}
351+
} else {
352+
retval.TLSConfig = new(tls.Config)
351353
}
352354
}
353355
envUsed := false
@@ -689,7 +691,8 @@ func (ctx *ConfigReaderContext) extractCertPrivateKeyPairs(certConfigMap map[int
689691
return
690692
}
691693

692-
func (ctx *ConfigReaderContext) extractTLSConfig(tlsConfigMap map[interface{}]interface{}, path string, client bool) (retval tls.Config, err error) {
694+
func (ctx *ConfigReaderContext) extractTLSConfig(tlsConfigMap map[interface{}]interface{}, path string, client bool) (retval *tls.Config, err error) {
695+
retval = new(tls.Config)
693696
_cipherSuites, ok := tlsConfigMap["ciphers"]
694697
if ok {
695698
cipherSuites, ok := _cipherSuites.([]interface{})
@@ -848,6 +851,8 @@ func (ctx *ConfigReaderContext) extractMITMConfig(configMap map[string]interface
848851
if err != nil {
849852
return
850853
}
854+
} else {
855+
retval.ClientTLSConfigTemplate = new(tls.Config)
851856
}
852857
__server, ok := _tls["server"]
853858
if ok {
@@ -860,6 +865,8 @@ func (ctx *ConfigReaderContext) extractMITMConfig(configMap map[string]interface
860865
if err != nil {
861866
return
862867
}
868+
} else {
869+
retval.ServerTLSConfigTemplate = new(tls.Config)
863870
}
864871
__ca, ok := _tls["ca"]
865872
if !ok {

httpx/transport.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -780,14 +780,14 @@ func (t *Transport) DoDial(cm ConnectMethod) (conn net.Conn, isProxy bool, err e
780780
return nil, false, err
781781
}
782782
} else {
783-
proxyTLSConfigTemlate := cm.ProxyTLSConfig
783+
proxyTLSConfigTemplate := cm.ProxyTLSConfig
784784
tlsProxy := cm.ProxyURL != nil && cm.ProxyURL.Scheme == "https"
785785
if tlsProxy {
786-
if proxyTLSConfigTemlate == nil {
786+
if proxyTLSConfigTemplate == nil {
787787
if t.DialTLS != nil {
788788
conn, err = t.DialTLS("tcp", cm.addr())
789789
} else {
790-
proxyTLSConfigTemlate = t.TLSClientConfig
790+
proxyTLSConfigTemplate = t.TLSClientConfig
791791
}
792792
}
793793
}
@@ -800,8 +800,10 @@ func (t *Transport) DoDial(cm ConnectMethod) (conn net.Conn, isProxy bool, err e
800800
return nil, false, err
801801
}
802802
if tlsProxy {
803-
proxyTLSConfig := new(tls.Config)
804-
*proxyTLSConfig = *proxyTLSConfigTemlate
803+
if proxyTLSConfigTemplate == nil {
804+
return nil, false, fmt.Errorf("http: no client TLS configuration template is available")
805+
}
806+
proxyTLSConfig := proxyTLSConfigTemplate.Clone()
805807
host, _, err := net.SplitHostPort(cm.ProxyURL.Host)
806808
if err == nil {
807809
proxyTLSConfig.ServerName = host

main.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,13 @@ func (ctx *DevProxy) getProxyUrlForRequest(req *http.Request) (*url.URL, *tls.Co
142142
}
143143
if req.URL.Scheme == "https" {
144144
if ctx.Config.Proxy.HTTPSProxy != nil {
145-
return ctx.Config.Proxy.HTTPSProxy, &ctx.Config.Proxy.TLSConfig, nil
145+
return ctx.Config.Proxy.HTTPSProxy, ctx.Config.Proxy.TLSConfig, nil
146146
}
147147
}
148148
// falls back to http
149149
if req.URL.Scheme == "https" || req.URL.Scheme == "http" {
150150
if ctx.Config.Proxy.HTTPProxy != nil {
151-
return ctx.Config.Proxy.HTTPProxy, &ctx.Config.Proxy.TLSConfig, nil
151+
return ctx.Config.Proxy.HTTPProxy, ctx.Config.Proxy.TLSConfig, nil
152152
}
153153
}
154154
return nil, nil, nil
@@ -160,14 +160,17 @@ func (ctx *DevProxy) newTLSConfigFactory() TLSConfigFactory {
160160
}
161161
return func(hostPortPairStr string, proxyCtx *OurProxyCtx) (*tls.Config, error) {
162162
pair := splitHostPort(hostPortPairStr)
163-
config := ctx.Config.MITM.ServerTLSConfigTemplate
163+
if ctx.Config.MITM.ServerTLSConfigTemplate == nil {
164+
return nil, errors.Errorf("no TLS configuration template is available")
165+
}
166+
config := ctx.Config.MITM.ServerTLSConfigTemplate.Clone()
164167
ctx.Logger.Infof("Obtaining temporary certificate for %s", pair.Host)
165168
cert, err := ctx.prepareMITMCertificate([]string{pair.Host})
166169
if err != nil {
167170
return nil, errors.Wrapf(err, "cannot sign host certificate with provided CA")
168171
}
169172
config.Certificates = append(config.Certificates, *cert)
170-
return &config, nil
173+
return config, nil
171174
}
172175
}
173176

@@ -179,7 +182,7 @@ func (ctx *DevProxy) newProxyURLBuilder() func(*http.Request) (*url.URL, *tls.Co
179182

180183
func (ctx *DevProxy) newHttpTransport() *httpx.Transport {
181184
transport := &httpx.Transport{
182-
TLSClientConfig: &ctx.Config.MITM.ClientTLSConfigTemplate,
185+
TLSClientConfig: ctx.Config.MITM.ClientTLSConfigTemplate,
183186
Proxy2: ctx.newProxyURLBuilder(),
184187
}
185188
transport.RegisterProtocol("fastcgi", &fastCGIRoundTripper{Logger: ctx.Logger})

server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (proxyCtx *OurProxyCtx) DoRequest(req *http.Request, respW http.ResponseWri
294294

295295
if isWebSocketReq(req) {
296296
proxyCtx.Logger.Debugf("Handling WebSocket Handshake: %v", req.URL)
297-
cm, err := proxyCtx.Tr.ConnectMethodForRequest(&httpx.TransportRequest{req, nil})
297+
cm, err := proxyCtx.Tr.ConnectMethodForRequest(&httpx.TransportRequest{Request: req, Extra: nil})
298298
if err != nil {
299299
return nil, errors.Wrapf(err, "failed to create a ConnectMethod struct")
300300
}
@@ -580,8 +580,7 @@ func (proxy *OurProxyHttpServer) doDialTLS(addr HostPortPair, tlsConfigTemplate
580580
if err != nil {
581581
return nil, errors.Wrapf(err, "failed to connect to %v", addr)
582582
}
583-
tlsConfig := new(tls.Config)
584-
*tlsConfig = *tlsConfigTemplate
583+
tlsConfig := tlsConfigTemplate.Clone()
585584
tlsConfig.ServerName = addr.Host
586585
return tls.Client(conn, tlsConfig), nil
587586
}

0 commit comments

Comments
 (0)