mirror of
https://github.com/bettercap/bettercap
synced 2025-08-19 21:13:18 -07:00
fix: api.rest and https.server certificates are now correctly generated with IsCA to false
This commit is contained in:
parent
070708c307
commit
8257d25ff3
23 changed files with 8876 additions and 14 deletions
|
@ -74,7 +74,7 @@ func CertConfigFromModule(prefix string, m session.SessionModule) (err error, cf
|
|||
return nil, cfg
|
||||
}
|
||||
|
||||
func CreateCertificate(cfg CertConfig) (error, *rsa.PrivateKey, []byte) {
|
||||
func CreateCertificate(cfg CertConfig, ca bool) (error, *rsa.PrivateKey, []byte) {
|
||||
priv, err := rsa.GenerateKey(rand.Reader, cfg.Bits)
|
||||
if err != nil {
|
||||
return err, nil, nil
|
||||
|
@ -103,7 +103,7 @@ func CreateCertificate(cfg CertConfig) (error, *rsa.PrivateKey, []byte) {
|
|||
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign,
|
||||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth},
|
||||
BasicConstraintsValid: true,
|
||||
IsCA: true,
|
||||
IsCA: ca,
|
||||
}
|
||||
|
||||
cert, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
|
||||
|
@ -114,7 +114,7 @@ func CreateCertificate(cfg CertConfig) (error, *rsa.PrivateKey, []byte) {
|
|||
return nil, priv, cert
|
||||
}
|
||||
|
||||
func Generate(cfg CertConfig, certPath string, keyPath string) error {
|
||||
func Generate(cfg CertConfig, certPath string, keyPath string, ca bool) error {
|
||||
keyFile, err := os.Create(keyPath)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -127,7 +127,7 @@ func Generate(cfg CertConfig, certPath string, keyPath string) error {
|
|||
}
|
||||
defer certFile.Close()
|
||||
|
||||
err, priv, cert := CreateCertificate(cfg)
|
||||
err, priv, cert := CreateCertificate(cfg, ca)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue