Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyLogWriter不生效 #387

Closed
1992w opened this issue Sep 21, 2024 · 2 comments
Closed

KeyLogWriter不生效 #387

1992w opened this issue Sep 21, 2024 · 2 comments

Comments

@1992w
Copy link

1992w commented Sep 21, 2024

使用基础库的http client通过设置KeyLogWriter可以用来保存密钥,像下面这样:

	client := http.Client{
		Transport: &http.Transport{
			TLSClientConfig: &tls.Config{
				KeyLogWriter: file,
			},
		},
	}

使用req.Client设置KeyLogWriter,密钥不会保存到文件中:

	tc := c.GetTLSClientConfig()
	tc.KeyLogWriter = file
	c.SetTLSClientConfig(tc)
@1992w
Copy link
Author

1992w commented Sep 21, 2024

看了下源码,是设置指纹时没有设置KeyLogWriter这个参数,加上就正常了:

func (c *Client) SetTLSFingerprint(clientHelloID utls.ClientHelloID) *Client {
	fn := func(ctx context.Context, addr string, plainConn net.Conn) (conn net.Conn, tlsState *tls.ConnectionState, err error) {
		colonPos := strings.LastIndex(addr, ":")
		if colonPos == -1 {
			colonPos = len(addr)
		}
		hostname := addr[:colonPos]
		utlsConfig := &utls.Config{
			ServerName:         hostname,
			RootCAs:            c.GetTLSClientConfig().RootCAs,
			NextProtos:         c.GetTLSClientConfig().NextProtos,
			InsecureSkipVerify: c.GetTLSClientConfig().InsecureSkipVerify,
			KeyLogWriter:       c.GetTLSClientConfig().KeyLogWriter, //这里加上就好了
		}
		uconn := &uTLSConn{utls.UClient(plainConn, utlsConfig, clientHelloID)}
		err = uconn.HandshakeContext(ctx)
		if err != nil {
			return
		}
		cs := uconn.Conn.ConnectionState()
		conn = uconn
		tlsState = &tls.ConnectionState{
			Version:                     cs.Version,
			HandshakeComplete:           cs.HandshakeComplete,
			DidResume:                   cs.DidResume,
			CipherSuite:                 cs.CipherSuite,
			NegotiatedProtocol:          cs.NegotiatedProtocol,
			NegotiatedProtocolIsMutual:  cs.NegotiatedProtocolIsMutual,
			ServerName:                  cs.ServerName,
			PeerCertificates:            cs.PeerCertificates,
			VerifiedChains:              cs.VerifiedChains,
			SignedCertificateTimestamps: cs.SignedCertificateTimestamps,
			OCSPResponse:                cs.OCSPResponse,
			TLSUnique:                   cs.TLSUnique,
		}
		return
	}
	c.Transport.SetTLSHandshake(fn)
	return c
}

@imroc imroc closed this as completed in 8d3a134 Sep 21, 2024
@imroc
Copy link
Owner

imroc commented Sep 21, 2024

v3.46.1 已修复

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants