use panic to stopp handshake when verification fails
This commit is contained in:
parent
69f1dc5075
commit
a8977ddf46
29
ws.go
29
ws.go
@ -753,10 +753,9 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio
|
|||||||
header.Set("User-Agent", options.UserAgent)
|
header.Set("User-Agent", options.UserAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
var verifyErr error = nil
|
|
||||||
trace := &httptrace.ClientTrace{
|
trace := &httptrace.ClientTrace{
|
||||||
TLSHandshakeDone: func(state tls.ConnectionState, err error) {
|
TLSHandshakeDone: func(state tls.ConnectionState, err error) {
|
||||||
if tlsConfig.RootCAs == nil {
|
if tlsConfig.RootCAs == nil || err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -775,26 +774,32 @@ func websocketClientConn(url string, conn net.Conn, tlsConfig *tls.Config, optio
|
|||||||
opts.Intermediates.AddCert(cert)
|
opts.Intermediates.AddCert(cert)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = certs[0].Verify(opts)
|
_, e := certs[0].Verify(opts)
|
||||||
if err != nil {
|
if e != nil {
|
||||||
verifyErr = err
|
panic(e)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
ctx := httptrace.WithClientTrace(context.Background(), trace)
|
ctx := httptrace.WithClientTrace(context.Background(), trace)
|
||||||
|
|
||||||
c, resp, err := dialer.DialContext(ctx, url, header)
|
c, resp, err := func() (c *websocket.Conn, resp *http.Response, err error) {
|
||||||
|
defer func() {
|
||||||
|
if r := recover(); r != nil {
|
||||||
|
e, ok := r.(error)
|
||||||
|
if !ok {
|
||||||
|
panic(r)
|
||||||
|
} else {
|
||||||
|
c, resp, err = nil, nil, e
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return dialer.DialContext(ctx, url, header)
|
||||||
|
}()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
|
||||||
if verifyErr != nil {
|
|
||||||
c.Close()
|
|
||||||
return nil, verifyErr
|
|
||||||
}
|
|
||||||
|
|
||||||
return &websocketConn{conn: c}, nil
|
return &websocketConn{conn: c}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user