node-http-mitm-proxy icon indicating copy to clipboard operation
node-http-mitm-proxy copied to clipboard

ECONNRESET google example

Open 7twin opened this issue 7 years ago • 11 comments

Similar to #90 I tried to get the example working, both from the readme and the examples page for the google modifying example, trusted the certificate both on windows and android, but the second I point my phone towards the proxy, it exits out with:

https server started for playatoms-pa.googleapis.com on 59988
HTTPS_CLIENT_ERROR on : Error: 11960:error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert
certificate unknown:openssl\ssl\record\rec_layer_s3.c:1407:SSL alert number 46

events.js:167
      throw er; // Unhandled 'error' event
      ^

Error: read ECONNRESET
    at TCP.onread (net.js:659:25)
Emitted 'error' event at:
    at Socket.onerror (_stream_readable.js:696:12)
    at Socket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
    at process._tickCallback (internal/process/next_tick.js:174:19)

Windows 10 (I added the cert via certutil -addstore "My" .\ca.pem) Android 7

7twin avatar Jun 21 '18 02:06 7twin

Are you running Node.js 10.x by chance? I saw a very similar error, but was able to work around it by downgrading to Node.js 8.x.

Possibly related to https://github.com/nodejs/node/issues/20418.

okwolf avatar Aug 23 '18 06:08 okwolf

I can confirm that switching from Node 10.9 to 8.5 got rid of the error in this example

yar-sh avatar Aug 29 '18 07:08 yar-sh

@okwolf @HaselLoyance Can confirm downgrading to 8 LTS - fixes it, though now that it works all pages display broken https - do you experience the same?

7twin avatar Aug 29 '18 18:08 7twin

@7twin I'm not exactly sure what do you mean by broken https. Do you mean invalid SSL certificate errors like this one?

screenshot from 2018-08-29 14-39-56

If so, then you need to import the ssl certificate that http-mitm-proxy generates into your browser OR it can be installed on your system. It'll be located in your project folder .http-mitm-proxy/certs/ca.pem

yar-sh avatar Aug 29 '18 19:08 yar-sh

@HaselLoyance Yeah - that but basically on android - I did install the .pem systemwide though

7twin avatar Aug 29 '18 19:08 7twin

@7twin Sadly, installing certificates on android didn't work for me etiher. Even though I got the message that the certificate was successfully installed I still had insecure https connections

Though it's weird that you were able to install .pem certificate. Usually, android only allows .der. Maybe try converting it to .der and seeing if that'll change anything?

yar-sh avatar Aug 29 '18 19:08 yar-sh

@HaselLoyance apparently I had to install it as "APP and VPN" certificate, just the encoding seems off with the default example now

Encoding

7twin avatar Aug 29 '18 20:08 7twin

I found a workaround to this problem to make it work on Node v10:

    ctx.onResponse(function(ctx, callback) {
      ctx.proxyToServerRequest.socket.once('close', () => {
        clientToProxyRequest.socket.destroy()
      })
      return callback()

You need to add this code at the start of the proxy.onRequest handler.

You can find the reasoning (which I didn't totally understand) here: https://stackoverflow.com/questions/51792579/how-to-prevent-the-econnreset-when-tunnelling-https-request-and-the-remote-serve

It works fine for me and now I'm back in business!

giltayar avatar Nov 21 '18 11:11 giltayar

@giltayar That is very interesting. Though I had the same error occur when I was using proxy.onConnect(req,socket,etc...). But even after I've added "close" and "end" event handlers to the socket it still was throwing the same error. The funny part is that the error was occuring randomly at different requests

yar-sh avatar Nov 22 '18 05:11 yar-sh

I ran into a similar error with proxying https traffic and have been able to mitigate by enabling keepAlive. See #177

freewil avatar Dec 17 '18 03:12 freewil

Crazily enough, the latest version of Node 10 has this problem resolved! I don't need my hack anymore. I use Node v10.12.0.

giltayar avatar Dec 18 '18 09:12 giltayar