Skip to content

Commit

Permalink
feat: 新增 unVerifySsl 拦截器
Browse files Browse the repository at this point in the history
  • Loading branch information
wangliang181230 committed Nov 27, 2024
1 parent de70b08 commit 9e27eb4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 6 deletions.
17 changes: 14 additions & 3 deletions packages/mitmproxy/src/lib/interceptor/impl/req/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,22 @@ module.exports = {
rOptions.agent = rOptions.agent.unVerifySslAgent
unVerifySsl = true
}
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}, sni: ${interceptOpt.sni}${unVerifySsl ? ', unVerifySsl' : ''}`)
log.info('proxy intercept: hostname:', originHostname, ', target:', proxyTarget, ', sni replace servername:', rOptions.servername, (unVerifySsl ? ', unVerifySsl' : ''))

const unVerifySslStr = unVerifySsl ? ', unVerifySsl' : ''
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}, sni: ${interceptOpt.sni}${unVerifySslStr}`)
log.info(`proxy intercept: hostname: ${originHostname}, target: ${proxyTarget}, sni replace servername: ${rOptions.servername}${unVerifySslStr}`)
} else if (interceptOpt.unVerifySsl === true) {
if (rOptions.agent.options.rejectUnauthorized && rOptions.agent.unVerifySslAgent) {
rOptions.agent = rOptions.agent.unVerifySslAgent
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}, unVerifySsl`)
log.info(`proxy intercept: hostname: ${originHostname}, target: ${proxyTarget}, unVerifySsl`)
} else {
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}, already unVerifySsl`)
log.info(`proxy intercept: hostname: ${originHostname}, target: ${proxyTarget}, already unVerifySsl`)
}
} else {
res.setHeader('DS-Interceptor', `proxy: ${proxyTarget}`)
log.info('proxy intercept: hostname:', originHostname, ', target:', proxyTarget)
log.info(`proxy intercept: hostname: ${originHostname}, target:${proxyTarget}`)
}

return true
Expand Down
6 changes: 4 additions & 2 deletions packages/mitmproxy/src/lib/interceptor/impl/req/sni.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ module.exports = {
rOptions.agent = rOptions.agent.unVerifySslAgent
unVerifySsl = true
}
res.setHeader('DS-Interceptor', `sni: ${interceptOpt.sni}${unVerifySsl ? ', unVerifySsl' : ''}`)

log.info('sni intercept: sni replace servername:', rOptions.hostname, '➜', rOptions.servername, (unVerifySsl ? ', unVerifySsl' : ''))
const unVerifySslStr = unVerifySsl ? ', unVerifySsl' : ''
res.setHeader('DS-Interceptor', `sni: ${interceptOpt.sni}${unVerifySslStr}`)

log.info(`sni intercept: sni replace servername: ${rOptions.hostname}${rOptions.servername}${unVerifySslStr}`)
return true
},
is (interceptOpt) {
Expand Down
21 changes: 21 additions & 0 deletions packages/mitmproxy/src/lib/interceptor/impl/req/unVerifySsl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
name: 'unVerifySsl',
priority: 123,
requestIntercept (context, interceptOpt, req, res, ssl, next) {
const { rOptions, log } = context

if (rOptions.agent.options.rejectUnauthorized && rOptions.agent.unVerifySslAgent) {
rOptions.agent = rOptions.agent.unVerifySslAgent
log.info(`unVerifySsl intercept: ${rOptions.hostname}, unVerifySsl`)
res.setHeader('DS-Interceptor', 'unVerifySsl')
} else {
log.info(`unVerifySsl intercept: ${rOptions.hostname}, already unVerifySsl`)
res.setHeader('DS-Interceptor', 'already unVerifySsl')
}

return true
},
is (interceptOpt) {
return interceptOpt.unVerifySsl === true
},
}
3 changes: 2 additions & 1 deletion packages/mitmproxy/src/lib/interceptor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const requestReplace = require('./impl/req/requestReplace')

const proxy = require('./impl/req/proxy')
const sni = require('./impl/req/sni')
const unVerifySsl = require('./impl/req/unVerifySsl')

const baiduOcr = require('./impl/req/baiduOcr')

Expand All @@ -25,7 +26,7 @@ module.exports = [
OPTIONS,
success, redirect, abort, cacheReq,
requestReplace,
proxy, sni,
proxy, sni, unVerifySsl,
baiduOcr,

// response interceptor impls
Expand Down

0 comments on commit 9e27eb4

Please sign in to comment.