@@ -2,7 +2,6 @@ package main
2
2
3
3
import (
4
4
"crypto/tls"
5
- "crypto/x509"
6
5
"flag"
7
6
"io/ioutil"
8
7
"net/http"
@@ -120,28 +119,6 @@ func main() {
120
119
log .Fatalf ("Couldn't parse connection timeout duration, err: %s" , err )
121
120
}
122
121
123
- var tlsClientCertificates []tls.Certificate
124
- if (* tlsClientKeyFile != "" ) != (* tlsClientCertFile != "" ) {
125
- log .Fatal ("TLS client key file and cert file should both be present" )
126
- }
127
- if * tlsClientKeyFile != "" && * tlsClientCertFile != "" {
128
- cert , err := tls .LoadX509KeyPair (* tlsClientCertFile , * tlsClientKeyFile )
129
- if err != nil {
130
- log .Fatalf ("Couldn't load TLS client key pair, err: %s" , err )
131
- }
132
- tlsClientCertificates = append (tlsClientCertificates , cert )
133
- }
134
-
135
- var tlsCaCertificates * x509.CertPool
136
- if * tlsCaCertFile != "" {
137
- caCert , err := ioutil .ReadFile (* tlsCaCertFile )
138
- if err != nil {
139
- log .Fatalf ("Couldn't load TLS Ca certificate, err: %s" , err )
140
- }
141
- tlsCaCertificates = x509 .NewCertPool ()
142
- tlsCaCertificates .AppendCertsFromPEM (caCert )
143
- }
144
-
145
122
passwordMap := make (map [string ]string )
146
123
if * redisPwd == "" && * redisPwdFile != "" {
147
124
passwordMap , err = exporter .LoadPwdFile (* redisPwdFile )
@@ -185,8 +162,9 @@ func main() {
185
162
ExportClientList : * exportClientList ,
186
163
ExportClientsInclPort : * exportClientPort ,
187
164
SkipTLSVerification : * skipTLSVerification ,
188
- ClientCertificates : tlsClientCertificates ,
189
- CaCertificates : tlsCaCertificates ,
165
+ ClientCertFile : * tlsClientCertFile ,
166
+ ClientKeyFile : * tlsClientKeyFile ,
167
+ CaCertFile : * tlsCaCertFile ,
190
168
ConnectionTimeouts : to ,
191
169
MetricsPath : * metricPath ,
192
170
RedisMetricsOnly : * redisMetricsOnly ,
@@ -203,11 +181,30 @@ func main() {
203
181
log .Fatal (err )
204
182
}
205
183
184
+ // Verify that initial client keypair and CA are accepted
185
+ if (* tlsClientCertFile != "" ) != (* tlsClientKeyFile != "" ) {
186
+ log .Fatal ("TLS client key file and cert file should both be present" )
187
+ }
188
+ _ , err = exp .CreateClientTLSConfig ()
189
+ if err != nil {
190
+ log .Fatal (err )
191
+ }
192
+
206
193
log .Infof ("Providing metrics at %s%s" , * listenAddress , * metricPath )
207
194
log .Debugf ("Configured redis addr: %#v" , * redisAddr )
208
195
if * tlsServerCertFile != "" && * tlsServerKeyFile != "" {
209
196
log .Debugf ("Bind as TLS using cert %s and key %s" , * tlsServerCertFile , * tlsServerKeyFile )
210
- log .Fatal (http .ListenAndServeTLS (* listenAddress , * tlsServerCertFile , * tlsServerKeyFile , exp ))
197
+
198
+ // Verify that the initial key pair is accepted
199
+ _ , err := exporter .LoadKeyPair (* tlsServerCertFile , * tlsServerKeyFile )
200
+ if err != nil {
201
+ log .Fatalf ("Couldn't load TLS server key pair, err: %s" , err )
202
+ }
203
+ server := & http.Server {
204
+ Addr : * listenAddress ,
205
+ TLSConfig : & tls.Config {GetCertificate : exporter .GetServerCertificateFunc (* tlsServerCertFile , * tlsServerKeyFile )},
206
+ Handler : exp }
207
+ log .Fatal (server .ListenAndServeTLS ("" , "" ))
211
208
} else {
212
209
log .Fatal (http .ListenAndServe (* listenAddress , exp ))
213
210
}
0 commit comments