8000 feat: Support dumping TLS keylog in NSS format for debugging · symfony-cli/symfony-cli@f655a2d · GitHub
[go: up one dir, main page]

Skip to content

Commit f655a2d

Browse files
committed
feat: Support dumping TLS keylog in NSS format for debugging
1 parent e1ba1a9 commit f655a2d

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

commands/local_server_start.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ var localServerStartCmd = &console.Command{
6868
&console.StringFlag{Name: "p12", Usage: "Name of the file containing the TLS certificate to use in p12 format"},
6969
&console.BoolFlag{Name: "no-tls", Usage: "Use HTTP instead of HTTPS"},
7070
&console.BoolFlag{Name: "use-gzip", Usage: "Use GZIP"},
71+
&console.StringFlag{
72+
Name: "tls-key-log-file",
73+
Usage: "Destination for TLS master secrets in NSS key log format",
74+
},
7175
},
7276
Action: func(c *console.Context) error {
7377
ui := terminal.SymfonyStyle(terminal.Stdout, terminal.Stdin)

local/http/http.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package http
2222
import (
2323
"crypto/tls"
2424
"fmt"
25+
"io"
2526
"net"
2627
"net/http"
2728
"os"
@@ -53,6 +54,7 @@ type Server struct {
5354
Logger zerolog.Logger
5455
Appversion string
5556
UseGzip bool
57+
TlsKeyLogFile string
5658

5759
httpserver *http.Server
5860
httpsserver *http.Server
@@ -111,13 +113,24 @@ func (s *Server) Start(errChan chan error) (int, error) {
111113
return port, errors.WithStack(err)
112114
}
113115

116+
var keyLogWriter io.Writer
117+
if s.TlsKeyLogFile != "" {
118+
w, err := os.OpenFile(s.TlsKeyLogFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
119+
if err != nil {
120+
return port, errors.WithStack(err)
121+
}
122+
123+
keyLogWriter = w
124+
}
125+
114126
s.httpsserver = &http.Server{
115127
Handler: proxyHandler,
116128
TLSConfig: &tls.Config{
117129
PreferServerCipherSuites: true,
118130
CurvePreferences: []tls.CurveID{tls.CurveP521, tls.CurveP384, tls.CurveP256},
119131
Certificates: []tls.Certificate{cert},
120132
NextProtos: []string{"h2", "http/1.1"},
133+
KeyLogWriter: keyLogWriter,
121134
},
122135
}
123136

local/project/config.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ type Config struct {
4141
PKCS12 string `yaml:"p12"`
4242
Logger zerolog.Logger
4343
AppVersion string
44-
AllowHTTP bool `yaml:"allow_http"`
45-
NoTLS bool `yaml:"no_tls"`
46-
Daemon bool `yaml:"daemon"`
47-
UseGzip bool `yaml:"use_gzip"`
44+
AllowHTTP bool `yaml:"allow_http"`
45+
NoTLS bool `yaml:"no_tls"`
46+
Daemon bool `yaml:"daemon"`
47+
UseGzip bool `yaml:"use_gzip"`
48+
TlsKeyLogFile string `yaml:"tls_key_log_file"`
4849
}
4950

5051
type FileConfig struct {
@@ -104,10 +105,12 @@ func NewConfigFromContext(c *console.Context, projectDir string) (*Config, *File
104105
if c.IsSet("daemon") {
105106
config.Daemon = c.Bool("daemon")
106107
}
107-
108108
if c.IsSet("use-gzip") {
109109
config.UseGzip = c.Bool("use-gzip")
110110
}
111+
if c.IsSet("tls-key-log-file") {
112+
config.TlsKeyLogFile = c.String("tls-key-log-file")
113+
}
111114

112115
return config, fileConfig, nil
113116
}

local/project/project.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func New(c *Config) (*Project, error) {
6262
AllowHTTP: c.AllowHTTP,
6363
UseGzip: c.UseGzip,
6464
Appversion: c.AppVersion,
65+
TlsKeyLogFile: c.TlsKeyLogFile,
6566
},
6667
}
6768
if err != nil {

0 commit comments

Comments
 (0)
0