From d90619564be6e197a46b49b09e06512ab6d4396a Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 6 Aug 2024 07:37:09 +0200 Subject: [PATCH] chore: add more client-certificates debug logging --- .../socksClientCertificatesInterceptor.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts index 99b6c1f6ad3db..b5484a4e804bf 100644 --- a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts +++ b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts @@ -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!, @@ -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); @@ -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', '
'); if (internalTLS?.alpnProtocol === 'h2') { @@ -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); });