|
|
|
@ -67,10 +67,23 @@ func NewCA(path string) (*CA, error) {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
log.Debug("create root ca")
|
|
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
if path == "" {
|
|
|
|
|
homeDir, err := os.UserHomeDir()
|
|
|
|
@ -117,6 +130,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 +251,6 @@ func (ca *CA) save() error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer file.Close()
|
|
|
|
|
|
|
|
|
|
return ca.saveTo(file)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -244,8 +260,17 @@ func (ca *CA) saveCert() error {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer file.Close()
|
|
|
|
|
err = ca.saveCertTo(file)
|
|
|
|
|
|
|
|
|
|
cerFile, err := os.Create(ca.caCertCerFile())
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
defer cerFile.Close()
|
|
|
|
|
|
|
|
|
|
return ca.saveCertTo(file)
|
|
|
|
|
CopyFile(cerFile.Name(), file.Name())
|
|
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (ca *CA) GetCert(commonName string) (*tls.Certificate, error) {
|
|
|
|
|