Merge pull request #12 from SonicCloudOrg/p_dev

新增自定义证书路径与cer文件生成
addon-dailer
liqiang 3 years ago committed by GitHub
commit f55cb599cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
.gitignore vendored

@ -2,5 +2,5 @@
.env
/go-mitmproxy
/dummycert
/.idea
dist/

@ -54,6 +54,8 @@ Usage of go-mitmproxy:
show version
-web_addr string
web interface listen addr (default ":9081")
-cert_path string
path of generate cert files
```
## Usage as package

@ -54,6 +54,8 @@ Usage of go-mitmproxy:
show version
-web_addr string
web interface listen addr (default ":9081")
-cert_path string
path of generate cert files
```
## 作为包引入

@ -67,7 +67,6 @@ func NewCA(path string) (*CA, error) {
return nil, err
}
log.Debug("create root ca")
return ca, nil
}
@ -117,6 +116,10 @@ func (ca *CA) caCertFile() string {
return filepath.Join(ca.StorePath, "mitmproxy-ca-cert.pem")
}
func (ca *CA) caCertCerFile() string {
return filepath.Join(ca.StorePath, "mitmproxy-ca-cert.cer")
}
func (ca *CA) load() error {
caFile := ca.caFile()
stat, err := os.Stat(caFile)
@ -234,7 +237,6 @@ func (ca *CA) save() error {
return err
}
defer file.Close()
return ca.saveTo(file)
}
@ -244,8 +246,21 @@ func (ca *CA) saveCert() error {
return err
}
defer file.Close()
err = ca.saveCertTo(file)
if err != nil {
return err
}
return ca.saveCertTo(file)
cerFile, err := os.Create(ca.caCertCerFile())
if err != nil {
return err
}
defer cerFile.Close()
err = ca.saveCertTo(cerFile)
if err != nil {
return err
}
return err
}
func (ca *CA) GetCert(commonName string) (*tls.Certificate, error) {

@ -16,7 +16,8 @@ import (
)
type Config struct {
version bool
version bool
certPath string
addr string
webAddr string
@ -38,6 +39,7 @@ func loadConfig() *Config {
flag.StringVar(&config.dump, "dump", "", "dump filename")
flag.IntVar(&config.dumpLevel, "dump_level", 0, "dump level: 0 - header, 1 - header + body")
flag.StringVar(&config.mapperDir, "mapper_dir", "", "mapper files dirpath")
flag.StringVar(&config.certPath, "cert_path", "", "path of generate cert files")
flag.Parse()
return config
@ -61,6 +63,7 @@ func main() {
Addr: config.addr,
StreamLargeBodies: 1024 * 1024 * 5,
SslInsecure: config.ssl_insecure,
CaRootPath: config.certPath,
}
p, err := proxy.NewProxy(opts)

@ -73,8 +73,8 @@ type Middle struct {
Server *http.Server
}
func NewMiddle(proxy *Proxy) (Interceptor, error) {
ca, err := cert.NewCA("")
func NewMiddle(proxy *Proxy,caPath string) (Interceptor, error) {
ca, err := cert.NewCA(caPath)
if err != nil {
return nil, err
}

@ -19,6 +19,7 @@ type Options struct {
Addr string
StreamLargeBodies int64
SslInsecure bool
CaRootPath string
}
type Proxy struct {
@ -65,7 +66,7 @@ func NewProxy(opts *Options) (*Proxy, error) {
},
}
interceptor, err := NewMiddle(proxy)
interceptor, err := NewMiddle(proxy, opts.CaRootPath)
if err != nil {
return nil, err
}

Loading…
Cancel
Save