|
|
@ -21,16 +21,14 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/golang/groupcache/lru"
|
|
|
|
"github.com/golang/groupcache/lru"
|
|
|
|
"github.com/golang/groupcache/singleflight"
|
|
|
|
"github.com/golang/groupcache/singleflight"
|
|
|
|
_log "github.com/sirupsen/logrus"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var log = _log.WithField("at", "cert")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// reference
|
|
|
|
// reference
|
|
|
|
// https://docs.mitmproxy.org/stable/concepts-certificates/
|
|
|
|
// https://docs.mitmproxy.org/stable/concepts-certificates/
|
|
|
|
// https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/certs.py
|
|
|
|
// https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/certs.py
|
|
|
|
|
|
|
|
|
|
|
|
var caErrNotFound = errors.New("ca not found")
|
|
|
|
var errCaNotFound = errors.New("ca not found")
|
|
|
|
|
|
|
|
|
|
|
|
type CA struct {
|
|
|
|
type CA struct {
|
|
|
|
rsa.PrivateKey
|
|
|
|
rsa.PrivateKey
|
|
|
@ -56,7 +54,7 @@ func NewCA(path string) (*CA, error) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if err := ca.load(); err != nil {
|
|
|
|
if err := ca.load(); err != nil {
|
|
|
|
if err != caErrNotFound {
|
|
|
|
if err != errCaNotFound {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -126,7 +124,7 @@ func (ca *CA) load() error {
|
|
|
|
stat, err := os.Stat(caFile)
|
|
|
|
stat, err := os.Stat(caFile)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return caErrNotFound
|
|
|
|
return errCaNotFound
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|