add a command line option to the example client to export a key log file

This commit is contained in:
Marten Seemann 2020-02-11 13:22:11 +07:00
parent 9ac52c5a0c
commit b412ed6d30

View file

@ -8,6 +8,7 @@ import (
"io" "io"
"log" "log"
"net/http" "net/http"
"os"
"sync" "sync"
"github.com/lucas-clemente/quic-go/http3" "github.com/lucas-clemente/quic-go/http3"
@ -18,6 +19,7 @@ import (
func main() { func main() {
verbose := flag.Bool("v", false, "verbose") verbose := flag.Bool("v", false, "verbose")
quiet := flag.Bool("q", false, "don't print the data") quiet := flag.Bool("q", false, "don't print the data")
keyLogFile := flag.String("keylog", "", "key log file")
insecure := flag.Bool("insecure", false, "skip certificate verification") insecure := flag.Bool("insecure", false, "skip certificate verification")
flag.Parse() flag.Parse()
urls := flag.Args() urls := flag.Args()
@ -31,6 +33,16 @@ func main() {
} }
logger.SetLogTimeFormat("") logger.SetLogTimeFormat("")
var keyLog *os.File
if len(*keyLogFile) > 0 {
var err error
keyLog, err = os.Create(*keyLogFile)
if err != nil {
log.Fatal(err)
}
defer keyLog.Close()
}
pool, err := x509.SystemCertPool() pool, err := x509.SystemCertPool()
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -40,6 +52,7 @@ func main() {
TLSClientConfig: &tls.Config{ TLSClientConfig: &tls.Config{
RootCAs: pool, RootCAs: pool,
InsecureSkipVerify: *insecure, InsecureSkipVerify: *insecure,
KeyLogWriter: keyLog,
}, },
} }
defer roundTripper.Close() defer roundTripper.Close()