-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a error handler to ConnectAction
This allows the users to client handle connect errors related to certificates, useful, as in the example, when some clients are using certificate pinning to allow them to connect without mitm
- Loading branch information
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"net/http" | ||
"sync" | ||
|
||
"github.com/elazarl/goproxy" | ||
) | ||
|
||
func main() { | ||
verbose := flag.Bool("v", false, "should every proxy request be logged to stdout") | ||
addr := flag.String("addr", ":8080", "proxy listen address") | ||
flag.Parse() | ||
proxy := goproxy.NewProxyHttpServer() | ||
var mitmErrorHosts []string | ||
var mitmErrorHostsLock sync.Mutex | ||
proxy.OnRequest().HandleConnectFunc(func(host string, ctx *goproxy.ProxyCtx) (*goproxy.ConnectAction, string) { | ||
mitmErrorHostsLock.Lock() | ||
defer mitmErrorHostsLock.Unlock() | ||
for _, errorHost := range mitmErrorHosts { | ||
if errorHost == host { | ||
return goproxy.OkConnect, host | ||
} | ||
} | ||
|
||
return &goproxy.ConnectAction{Action: goproxy.ConnectMitm, TLSConfig: goproxy.MitmConnect.TLSConfig, MitmError: func(req *http.Request, ctx *goproxy.ProxyCtx, err error) { | ||
log.Printf("Adding host to mitm error: %s", host) | ||
mitmErrorHostsLock.Lock() | ||
defer mitmErrorHostsLock.Unlock() | ||
mitmErrorHosts = append(mitmErrorHosts, host) | ||
}}, host | ||
}) | ||
proxy.Verbose = *verbose | ||
log.Fatal(http.ListenAndServe(*addr, proxy)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters