derp/derphttp: support standard-ish SSLKEYLOGFILE environment variable

For debugging.
This commit is contained in:
Brad Fitzpatrick 2020-08-18 19:23:29 -07:00
parent 862d223c39
commit 287522730d
1 changed files with 10 additions and 0 deletions

View File

@ -18,9 +18,11 @@ import (
"fmt"
"io"
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"os"
"sync"
"time"
@ -365,6 +367,14 @@ func (c *Client) tlsClient(nc net.Conn, node *tailcfg.DERPNode) *tls.Conn {
tlsdial.SetConfigExpectedCert(tlsConf, node.CertName)
}
}
if n := os.Getenv("SSLKEYLOGFILE"); n != "" {
f, err := os.OpenFile(n, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600)
if err != nil {
log.Fatal(err)
}
log.Printf("WARNING: writing to SSLKEYLOGFILE %v", n)
tlsConf.KeyLogWriter = f
}
return tls.Client(nc, tlsConf)
}