connCtx.tlsHandshake

addon-dailer
lqqyt2423 2 years ago
parent 896ea2997f
commit fade639367

@ -160,7 +160,7 @@ func (connCtx *ConnContext) initHttpsServerConn() {
} }
} }
func (connCtx *ConnContext) getCertificate(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { func (connCtx *ConnContext) tlsHandshake(clientHello *tls.ClientHelloInfo) error {
cfg := &tls.Config{ cfg := &tls.Config{
InsecureSkipVerify: connCtx.proxy.Opts.SslInsecure, InsecureSkipVerify: connCtx.proxy.Opts.SslInsecure,
KeyLogWriter: getTlsKeyLogWriter(), KeyLogWriter: getTlsKeyLogWriter(),
@ -189,7 +189,7 @@ func (connCtx *ConnContext) getCertificate(clientHello *tls.ClientHelloInfo) (*t
if err != nil { if err != nil {
connCtx.ServerConn.tlsHandshakeErr = err connCtx.ServerConn.tlsHandshakeErr = err
close(connCtx.ServerConn.tlsHandshaked) close(connCtx.ServerConn.tlsHandshaked)
return nil, err return err
} }
connCtx.ServerConn.tlsConn = tlsConn connCtx.ServerConn.tlsConn = tlsConn
@ -197,8 +197,7 @@ func (connCtx *ConnContext) getCertificate(clientHello *tls.ClientHelloInfo) (*t
connCtx.ServerConn.tlsState = &tlsState connCtx.ServerConn.tlsState = &tlsState
close(connCtx.ServerConn.tlsHandshaked) close(connCtx.ServerConn.tlsHandshaked)
// todo: change here return nil
return connCtx.proxy.interceptor.(*middle).ca.GetCert(clientHello.ServerName)
} }
// wrap tcpConn for remote client // wrap tcpConn for remote client

@ -122,7 +122,10 @@ func newMiddle(proxy *Proxy) (interceptor, error) {
SessionTicketsDisabled: true, // 设置此值为 true ,确保每次都会调用下面的 GetCertificate 方法 SessionTicketsDisabled: true, // 设置此值为 true ,确保每次都会调用下面的 GetCertificate 方法
GetCertificate: func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) { GetCertificate: func(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
connCtx := clientHello.Context().Value(connContextKey).(*ConnContext) connCtx := clientHello.Context().Value(connContextKey).(*ConnContext)
return connCtx.getCertificate(clientHello) if err := connCtx.tlsHandshake(clientHello); err != nil {
return nil, err
}
return ca.GetCert(clientHello.ServerName)
}, },
}, },
} }

Loading…
Cancel
Save