loadHTTPSTLSConfig loads TLS configuration from HTTPS settings (deprecated)
(cfg *struct {
Enable bool
Host string
Port int
Cert string
CaCert string
Key string
HttpRedirect bool
MinTLSVersionString string
MaxTLSVersionString string
MinTLSVersion uint16
MaxTLSVersion uint16
PreferServerCipher bool
MutualTLS bool
InsecureSkipVerify bool
ReadTimeout int
WriteTimeout int
IdleTimeout int
MaxRequestBodySize int
Concurrency int
DisableKeepalive bool
TCPKeepalive bool
TCPKeepalivePeriod int
})
| 197 | |
| 198 | // loadHTTPSTLSConfig loads TLS configuration from HTTPS settings (deprecated) |
| 199 | func loadHTTPSTLSConfig(cfg *struct { |
| 200 | Enable bool |
| 201 | Host string |
| 202 | Port int |
| 203 | Cert string |
| 204 | CaCert string |
| 205 | Key string |
| 206 | HttpRedirect bool |
| 207 | MinTLSVersionString string |
| 208 | MaxTLSVersionString string |
| 209 | MinTLSVersion uint16 |
| 210 | MaxTLSVersion uint16 |
| 211 | PreferServerCipher bool |
| 212 | MutualTLS bool |
| 213 | InsecureSkipVerify bool |
| 214 | ReadTimeout int |
| 215 | WriteTimeout int |
| 216 | IdleTimeout int |
| 217 | MaxRequestBodySize int |
| 218 | Concurrency int |
| 219 | DisableKeepalive bool |
| 220 | TCPKeepalive bool |
| 221 | TCPKeepalivePeriod int |
| 222 | }) (*tls.Config, error) { |
| 223 | if !cfg.Enable { |
| 224 | return nil, nil |
| 225 | } |
| 226 | |
| 227 | if cfg.Cert == "" || cfg.Key == "" { |
| 228 | return nil, fmt.Errorf("HTTPS certificate and key must be provided (cert=%q, key=%q)", cfg.Cert, cfg.Key) |
| 229 | } |
| 230 | |
| 231 | cwd, _ := os.Getwd() |
| 232 | logger.Info("HTTPS server: current working directory", "cwd", cwd) |
| 233 | |
| 234 | // Check if certificate files exist |
| 235 | logger.Info("HTTPS server: checking certificate file", "cert", cfg.Cert) |
| 236 | if _, err := os.Stat(cfg.Cert); os.IsNotExist(err) { |
| 237 | absPath, _ := filepath.Abs(cfg.Cert) |
| 238 | return nil, fmt.Errorf("HTTPS certificate file not found: %s (absolute: %s)", cfg.Cert, absPath) |
| 239 | } |
| 240 | logger.Info("HTTPS server: certificate file found", "cert", cfg.Cert) |
| 241 | |
| 242 | logger.Info("HTTPS server: checking key file", "key", cfg.Key) |
| 243 | if _, err := os.Stat(cfg.Key); os.IsNotExist(err) { |
| 244 | absPath, _ := filepath.Abs(cfg.Key) |
| 245 | return nil, fmt.Errorf("HTTPS key file not found: %s (absolute: %s)", cfg.Key, absPath) |
| 246 | } |
| 247 | logger.Info("HTTPS server: key file found", "key", cfg.Key) |
| 248 | |
| 249 | logger.Info("HTTPS server: loading certificate pair...") |
| 250 | // Load certificate |
| 251 | cert, err := tls.LoadX509KeyPair(cfg.Cert, cfg.Key) |
| 252 | if err != nil { |
| 253 | return nil, fmt.Errorf("failed to load HTTPS certificate from cert=%s key=%s: %w", cfg.Cert, cfg.Key, err) |
| 254 | } |
| 255 | logger.Info("HTTPS server: certificate pair loaded successfully") |
| 256 |
nothing calls this directly
no outgoing calls
no test coverage detected