Move SSLKEYLOGFILE logic to caller (main)

This commit is contained in:
Igor Wiedler 2021-09-20 14:34:07 +02:00
parent e6c26914d4
commit afb789f147
2 changed files with 12 additions and 11 deletions

View File

@ -408,12 +408,21 @@ func main() {
}
var creds credentials.TransportCredentials
if !*plaintext {
var err error
creds, err = grpcurl.ClientTransportCredentials(*insecure, *cacert, *cert, *key)
tlsConf, err := grpcurl.ClientTLSConfig(*insecure, *cacert, *cert, *key)
if err != nil {
fail(err, "Failed to configure transport credentials")
fail(err, "Failed to configure TLS config")
}
if os.Getenv("SSLKEYLOGFILE") != "" {
w, err := os.OpenFile(os.Getenv("SSLKEYLOGFILE"), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
fail(err, "Could not open SSLKEYLOGFILE: %v")
}
tlsConf.KeyLogWriter = w
}
creds := credentials.NewTLS(tlsConf)
// can use either -servername or -authority; but not both
if *serverName != "" && *authority != "" {
if *serverName == *authority {

View File

@ -554,14 +554,6 @@ func ClientTLSConfig(insecureSkipVerify bool, cacertFile, clientCertFile, client
tlsConf.RootCAs = certPool
}
if os.Getenv("SSLKEYLOGFILE") != "" {
w, err := os.OpenFile(os.Getenv("SSLKEYLOGFILE"), os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600)
if err != nil {
return nil, fmt.Errorf("could not open SSLKEYLOGFILE: %v", err)
}
tlsConf.KeyLogWriter = w
}
return &tlsConf, nil
}