按需修改

addon-dailer
ZhouYixun 3 years ago
parent 8522ebedb0
commit 87d9c93f0b

@ -70,20 +70,6 @@ func NewCA(path string) (*CA, error) {
return ca, nil return ca, nil
} }
func CopyFile(dstName, srcName string) (written int64, err error) {
src, err := os.Open(srcName)
if err != nil {
return
}
defer src.Close()
dst, err := os.OpenFile(dstName, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
return
}
defer dst.Close()
return io.Copy(dst, src)
}
func getStorePath(path string) (string, error) { func getStorePath(path string) (string, error) {
if path == "" { if path == "" {
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
@ -261,15 +247,19 @@ func (ca *CA) saveCert() error {
} }
defer file.Close() defer file.Close()
err = ca.saveCertTo(file) err = ca.saveCertTo(file)
if err != nil {
return err
}
cerFile, err := os.Create(ca.caCertCerFile()) cerFile, err := os.Create(ca.caCertCerFile())
if err != nil { if err != nil {
return err return err
} }
defer cerFile.Close() defer cerFile.Close()
err = ca.saveCertTo(cerFile)
CopyFile(cerFile.Name(), file.Name()) if err != nil {
return err
}
return err return err
} }

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

@ -19,6 +19,7 @@ type Options struct {
Addr string Addr string
StreamLargeBodies int64 StreamLargeBodies int64
SslInsecure bool SslInsecure bool
CaRootPath string
} }
type Proxy struct { type Proxy struct {
@ -30,7 +31,7 @@ type Proxy struct {
Addons []addon.Addon Addons []addon.Addon
} }
func NewProxy(opts *Options,path string) (*Proxy, error) { func NewProxy(opts *Options) (*Proxy, error) {
proxy := new(Proxy) proxy := new(Proxy)
proxy.Version = "0.1.5" proxy.Version = "0.1.5"
@ -65,7 +66,7 @@ func NewProxy(opts *Options,path string) (*Proxy, error) {
}, },
} }
interceptor, err := NewMiddle(proxy,path) interceptor, err := NewMiddle(proxy, opts.CaRootPath)
if err != nil { if err != nil {
return nil, err return nil, err
} }

Loading…
Cancel
Save