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

translate.googleapis.com | PEM_read_bio:no start line

Open jacob-cross99 opened this issue 7 years ago • 1 comments

I'm working on a proxy that removes ads from the users browser. I've noticed that whenever I visit a site that translates google requests the proxy crashes with the error PEN_read_bio:no start line and there's no .pem data in the certs folder.

Ex: http://www.prodisney.ru/index.php?page=clones.php

import Proxy from 'http-mitm-proxy'

import { PROXY_HOST, PROXY_PORT } from '../config'
import { hasMiddleware, runMiddleware } from '../middleware'

const proxy = Proxy()

proxy
	.use(Proxy.gunzip)
	.onRequest((ctx, callback) => {
		const { url, method, headers } = ctx.clientToProxyRequest

		let chunks = []
		let path
		
		if(headers && headers.host)
			path = headers.host.toLowerCase() + url.toLowerCase()

		runMiddleware(path, method, ctx, undefined, () => {
			ctx
				.onResponseData((ctx, chunk, callback) => {
					if(!hasMiddleware(path))
						return callback(null, chunk)

					chunks.push(chunk)
					callback(null, null)
				})
				.onResponseEnd((ctx, callback) => {
					if(!hasMiddleware(path))
						return callback()
					
					runMiddleware(path, method, ctx, Buffer.concat(chunks).toString(), () => ctx.proxyToClientResponse.end(Buffer.concat(chunks)))
				})

			callback()
		})
	})

export default function listen() {
	proxy.listen({
		host: PROXY_HOST,
		port: PROXY_PORT,
		sslCaDir: process.cwd() + '/hosts'
	})
}

jacob-cross99 avatar Nov 23 '18 06:11 jacob-cross99

this should be resolved now, upgrade to >=0.9.0

theRemix avatar Aug 05 '21 01:08 theRemix