mirror of
https://github.com/bettercap/bettercap
synced 2025-08-21 14:03:17 -07:00
new: single https certificate / authority fields can now be customized via dedicated module parameters ( http.server, https.proxy and api.rest )
This commit is contained in:
parent
3d852a0fae
commit
7a08366516
4 changed files with 123 additions and 25 deletions
|
@ -63,6 +63,8 @@ func NewRestAPI(s *session.Session) *RestAPI {
|
|||
"",
|
||||
"API TLS certificate."))
|
||||
|
||||
tls.CertConfigToModule("api.rest", &api.SessionModule, tls.DefaultLegitConfig)
|
||||
|
||||
api.AddParam(session.NewStringParameter("api.rest.key",
|
||||
"~/.bcap-api.rest.key.pem",
|
||||
"",
|
||||
|
@ -132,10 +134,18 @@ func (api *RestAPI) Configure() error {
|
|||
return err
|
||||
} else if err, api.useWebsocket = api.BoolParam("api.rest.websocket"); err != nil {
|
||||
return err
|
||||
} else if !core.Exists(api.certFile) || !core.Exists(api.keyFile) {
|
||||
}
|
||||
|
||||
if !core.Exists(api.certFile) || !core.Exists(api.keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("api.rest", api.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug("%+v", cfg)
|
||||
log.Info("Generating TLS key to %s", api.keyFile)
|
||||
log.Info("Generating TLS certificate to %s", api.certFile)
|
||||
if err := tls.Generate(api.certFile, api.keyFile); err != nil {
|
||||
if err := tls.Generate(cfg, api.certFile, api.keyFile); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -50,6 +50,8 @@ func NewHttpServer(s *session.Session) *HttpServer {
|
|||
"",
|
||||
"TLS key file, if not empty will configure this as a HTTPS server (will be auto generated if filled but not existing)."))
|
||||
|
||||
tls.CertConfigToModule("http.server", &httpd.SessionModule, tls.DefaultLegitConfig)
|
||||
|
||||
httpd.AddHandler(session.NewModuleHandler("http.server on", "",
|
||||
"Start httpd server.",
|
||||
func(args []string) error {
|
||||
|
@ -131,9 +133,15 @@ func (httpd *HttpServer) Configure() error {
|
|||
|
||||
if certFile != "" && keyFile != "" {
|
||||
if !core.Exists(certFile) || !core.Exists(keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("http.server", httpd.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug("%+v", cfg)
|
||||
log.Info("Generating server TLS key to %s", keyFile)
|
||||
log.Info("Generating server TLS certificate to %s", certFile)
|
||||
if err := tls.Generate(certFile, keyFile); err != nil {
|
||||
if err := tls.Generate(cfg, certFile, keyFile); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -50,6 +50,8 @@ func NewHttpsProxy(s *session.Session) *HttpsProxy {
|
|||
"",
|
||||
"HTTPS proxy certification authority TLS key file."))
|
||||
|
||||
tls.CertConfigToModule("https.proxy", &p.SessionModule, tls.DefaultSpoofConfig)
|
||||
|
||||
p.AddParam(session.NewStringParameter("https.proxy.script",
|
||||
"",
|
||||
"",
|
||||
|
@ -118,9 +120,15 @@ func (p *HttpsProxy) Configure() error {
|
|||
}
|
||||
|
||||
if !core.Exists(certFile) || !core.Exists(keyFile) {
|
||||
err, cfg := tls.CertConfigFromModule("https.proxy", p.SessionModule)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debug("%+v", cfg)
|
||||
log.Info("Generating proxy certification authority TLS key to %s", keyFile)
|
||||
log.Info("Generating proxy certification authority TLS certificate to %s", certFile)
|
||||
if err := tls.Generate(certFile, keyFile); err != nil {
|
||||
if err := tls.Generate(cfg, certFile, keyFile); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue