Skip to content

Commit

Permalink
Fix in tls.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Boris committed Dec 6, 2022
1 parent e423de2 commit 6b6d9b6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/flant/elasticsearch-extractor
go 1.14

require (
github.com/jteeuwen/go-bindata v3.0.7+incompatible // indirect
github.com/uzhinskiy/lib.go v0.1.3
gopkg.in/yaml.v2 v2.3.0
)
9 changes: 2 additions & 7 deletions modules/router/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ func createTLSConfig(pemFile, pemCertFile, pemPrivateKeyFile string, insecureSki
tlsConfig.RootCAs = rootCerts
}
if len(pemCertFile) > 0 && len(pemPrivateKeyFile) > 0 {
// Load files once to catch configuration error early.
_, err := loadPrivateKeyFrom(pemCertFile, pemPrivateKeyFile)
certs, err := tls.LoadX509KeyPair(pemCertFile, pemPrivateKeyFile)
if err != nil {
log.Fatalf("Couldn't setup client authentication. Got %s.", err)
return nil
}
// Define a function to load certificate and key lazily at TLS handshake to
// ensure that the latest files are used in case they have been rotated.
tlsConfig.GetClientCertificate = func(*tls.CertificateRequestInfo) (*tls.Certificate, error) {
return loadPrivateKeyFrom(pemCertFile, pemPrivateKeyFile)
}
tlsConfig.Certificates = []tls.Certificate{certs}
}
return &tlsConfig
}
Expand Down

0 comments on commit 6b6d9b6

Please sign in to comment.