mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
Merge pull request #651 from alrs/tls-swap-err-returns
tls: Swap Error Returns
This commit is contained in:
commit
f9865299b3
4 changed files with 17 additions and 17 deletions
|
@ -213,7 +213,7 @@ func (mod *RestAPI) Configure() error {
|
|||
|
||||
if mod.isTLS() {
|
||||
if !fs.Exists(mod.certFile) || !fs.Exists(mod.keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("api.rest", mod.SessionModule)
|
||||
cfg, err := tls.CertConfigFromModule("api.rest", mod.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ func (mod *HttpsProxy) Configure() error {
|
|||
mod.proxy.Whitelist = str.Comma(whitelist)
|
||||
|
||||
if !fs.Exists(certFile) || !fs.Exists(keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("https.proxy", mod.SessionModule)
|
||||
cfg, err := tls.CertConfigFromModule("https.proxy", mod.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -129,7 +129,7 @@ func (mod *HttpsServer) Configure() error {
|
|||
}
|
||||
|
||||
if !fs.Exists(certFile) || !fs.Exists(keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("https.server", mod.SessionModule)
|
||||
cfg, err := tls.CertConfigFromModule("https.server", mod.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
28
tls/cert.go
28
tls/cert.go
|
@ -57,27 +57,27 @@ func CertConfigToModule(prefix string, m *session.SessionModule, defaults CertCo
|
|||
"Common Name field of the generated HTTPS certificate."))
|
||||
}
|
||||
|
||||
func CertConfigFromModule(prefix string, m session.SessionModule) (err error, cfg CertConfig) {
|
||||
func CertConfigFromModule(prefix string, m session.SessionModule) (cfg CertConfig, err error) {
|
||||
if err, cfg.Bits = m.IntParam(prefix + ".certificate.bits"); err != nil {
|
||||
return err, cfg
|
||||
return cfg, err
|
||||
} else if err, cfg.Country = m.StringParam(prefix + ".certificate.country"); err != nil {
|
||||
return err, cfg
|
||||
return cfg, err
|
||||
} else if err, cfg.Locality = m.StringParam(prefix + ".certificate.locality"); err != nil {
|
||||
return err, cfg
|
||||
return cfg, err
|
||||
} else if err, cfg.Organization = m.StringParam(prefix + ".certificate.organization"); err != nil {
|
||||
return err, cfg
|
||||
return cfg, err
|
||||
} else if err, cfg.OrganizationalUnit = m.StringParam(prefix + ".certificate.organizationalunit"); err != nil {
|
||||
return err, cfg
|
||||
return cfg, err
|
||||
} else if err, cfg.CommonName = m.StringParam(prefix + ".certificate.commonname"); err != nil {
|
||||
return err, cfg
|
||||
return cfg, err
|
||||
}
|
||||
return nil, cfg
|
||||
return cfg, err
|
||||
}
|
||||
|
||||
func CreateCertificate(cfg CertConfig, ca bool) (error, *rsa.PrivateKey, []byte) {
|
||||
func CreateCertificate(cfg CertConfig, ca bool) (*rsa.PrivateKey, []byte, error) {
|
||||
priv, err := rsa.GenerateKey(rand.Reader, cfg.Bits)
|
||||
if err != nil {
|
||||
return err, nil, nil
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
notBefore := time.Now()
|
||||
|
@ -86,7 +86,7 @@ func CreateCertificate(cfg CertConfig, ca bool) (error, *rsa.PrivateKey, []byte)
|
|||
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
|
||||
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
|
||||
if err != nil {
|
||||
return err, nil, nil
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
template := x509.Certificate{
|
||||
|
@ -108,10 +108,10 @@ func CreateCertificate(cfg CertConfig, ca bool) (error, *rsa.PrivateKey, []byte)
|
|||
|
||||
cert, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
|
||||
if err != nil {
|
||||
return err, nil, nil
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return nil, priv, cert
|
||||
return priv, cert, err
|
||||
}
|
||||
|
||||
func Generate(cfg CertConfig, certPath string, keyPath string, ca bool) error {
|
||||
|
@ -127,7 +127,7 @@ func Generate(cfg CertConfig, certPath string, keyPath string, ca bool) error {
|
|||
}
|
||||
defer certFile.Close()
|
||||
|
||||
err, priv, cert := CreateCertificate(cfg, ca)
|
||||
priv, cert, err := CreateCertificate(cfg, ca)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue