Skip to content

Commit

Permalink
http_proxy: enable getting MITM CA cert
Browse files Browse the repository at this point in the history
  • Loading branch information
mmatczuk committed Sep 27, 2023
1 parent d6ea3fc commit 8442986
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions http_proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"bufio"
"context"
"crypto/tls"
"crypto/x509"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -128,14 +129,15 @@ func (c *HTTPProxyConfig) Validate() error {
}

type HTTPProxy struct {
config HTTPProxyConfig
pac PACResolver
creds *CredentialsMatcher
transport http.RoundTripper
log log.Logger
proxy *martian.Proxy
proxyFunc ProxyFunc
listener net.Listener
config HTTPProxyConfig
pac PACResolver
creds *CredentialsMatcher
transport http.RoundTripper
log log.Logger
proxy *martian.Proxy
mitmCACert *x509.Certificate
proxyFunc ProxyFunc
listener net.Listener

TLSConfig *tls.Config
}
Expand Down Expand Up @@ -229,6 +231,7 @@ func (hp *HTTPProxy) configureProxy() error {
return fmt.Errorf("mitm: %w", err)
}
hp.proxy.SetMITM(mc)
hp.mitmCACert = mc.CACert()

if hp.config.MITMDomains != nil {
hp.proxy.MITMFilter = func(req *http.Request) bool {
Expand Down Expand Up @@ -527,6 +530,10 @@ func setEmptyUserAgent(req *http.Request) error {
return nil
}

func (hp *HTTPProxy) MITMCACert() *x509.Certificate {
return hp.mitmCACert
}

func (hp *HTTPProxy) ProxyFunc() ProxyFunc {
return hp.proxyFunc
}
Expand Down

0 comments on commit 8442986

Please sign in to comment.