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

chore: add more client-certificates debug logging #32022

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,14 @@ class SocksProxyConnection {
}

async connect() {
debugLogger.log('client-certificates', `Connecting to ${this.host}:${this.port}`);
this.target = await createSocket(rewriteToLocalhostIfNeeded(this.host), this.port);
this.target.on('close', this._targetCloseEventListener);
this.target.on('error', error => this.socksProxy._socksProxy.sendSocketError({ uid: this.uid, error: error.message }));
this.target.on('error', error => {
debugLogger.log('client-certificates', `error when connecting to target: ${error.message.replaceAll('\n', ' ')}`);
this.socksProxy._socksProxy.sendSocketError({ uid: this.uid, error: error.message });
});
debugLogger.log('client-certificates', `Connected to ${this.host}:${this.port}`);
this.socksProxy._socksProxy.socketConnected({
uid: this.uid,
host: this.target.localAddress!,
Expand All @@ -113,10 +118,13 @@ class SocksProxyConnection {
if (!this.firstPackageReceived) {
this.firstPackageReceived = true;
// 0x16 is SSLv3/TLS "handshake" content type: https://en.wikipedia.org/wiki/Transport_Layer_Security#TLS_record
if (data[0] === 0x16)
if (data[0] === 0x16) {
debugLogger.log('client-certificates', `Proxy->Target ${this.host}:${this.port} chooses TLS`);
this._attachTLSListeners();
else
} else {
debugLogger.log('client-certificates', `Proxy->Target ${this.host}:${this.port} chooses HTTP`);
this.target.on('data', data => this.socksProxy._socksProxy.sendSocketData({ uid: this.uid, data }));
}
}
if (this.internal)
this.internal.push(data);
Expand Down Expand Up @@ -151,7 +159,7 @@ class SocksProxyConnection {

const handleError = (error: Error) => {
error = rewriteOpenSSLErrorIfNeeded(error);
debugLogger.log('client-certificates', `error when connecting to target: ${error.message.replaceAll('\n', ' ')}`);
debugLogger.log('client-certificates', `Proxy->Target ${this.host}:${this.port} TLS error: ${error.message}`);
const responseBody = escapeHTML('Playwright client-certificate error: ' + error.message)
.replaceAll('\n', ' <br>');
if (internalTLS?.alpnProtocol === 'h2') {
Expand Down Expand Up @@ -209,6 +217,7 @@ class SocksProxyConnection {
targetTLS = tls.connect(tlsOptions);

targetTLS.on('secureConnect', () => {
debugLogger.log('client-certificates', `Proxy->Target ${this.host}:${this.port} secure connection established`);
internalTLS.pipe(targetTLS);
targetTLS.pipe(internalTLS);
});
Expand Down
Loading