@@ -3,6 +3,7 @@ package http
3
3
import (
4
4
"context"
5
5
"crypto/tls"
6
+ "crypto/x509"
6
7
"fmt"
7
8
"io"
8
9
"io/ioutil"
@@ -130,7 +131,7 @@ func (m *Monitor) Configure(conf *Config) (err error) {
130
131
}
131
132
}
132
133
} else {
133
- logger .WithError (err ).Error ("Failed gathering all HTTP stats, ignore TLS stats and push what we've successfully collected " )
134
+ logger .WithError (err ).Error ("Failed gathering HTTP stats, ignore other stats" )
134
135
}
135
136
136
137
for i := range dps {
@@ -213,20 +214,15 @@ func (m *Monitor) getTLSStats(site *url.URL, logger *logrus.Entry) (dps []*datap
213
214
serverName = host
214
215
}
215
216
216
- dimensions := map [string ]string {
217
- "server_name" : host ,
218
- "sni_server_name" : serverName ,
219
- }
220
-
221
217
ipConn , err := net .Dial ("tcp" , host + ":" + port )
222
218
if err != nil {
223
- logger .WithError (err ).Error ("connection failed to host during TLS stat collection" )
224
219
return
225
220
}
226
221
defer ipConn .Close ()
227
222
228
223
tlsCfg := & tls.Config {
229
- ServerName : serverName ,
224
+ InsecureSkipVerify : m .conf .SkipVerify ,
225
+ ServerName : serverName ,
230
226
}
231
227
232
228
if _ , err := auth .TLSConfig (tlsCfg , m .conf .CACertPath , m .conf .ClientCertPath , m .conf .ClientKeyPath ); err != nil {
@@ -241,11 +237,34 @@ func (m *Monitor) getTLSStats(site *url.URL, logger *logrus.Entry) (dps []*datap
241
237
242
238
err = conn .Handshake ()
243
239
if err != nil {
244
- logger .WithError (err ).Debug ( "cert verification failed during handshake" )
240
+ logger .WithError (err ).Error ( " failed during handshake" )
245
241
valid = 0
246
- } else {
247
- cert := conn .ConnectionState ().PeerCertificates [0 ]
248
- secondsLeft = time .Until (cert .NotAfter ).Seconds ()
242
+ }
243
+
244
+ certs := conn .ConnectionState ().PeerCertificates
245
+ for i , cert := range certs {
246
+ opts := x509.VerifyOptions {
247
+ Intermediates : x509 .NewCertPool (),
248
+ }
249
+ if i == 0 {
250
+ opts .DNSName = serverName
251
+ for j , cert := range certs {
252
+ if j != 0 {
253
+ opts .Intermediates .AddCert (cert )
254
+ }
255
+ }
256
+ secondsLeft = time .Until (cert .NotAfter ).Seconds ()
257
+ }
258
+ _ , err := cert .Verify (opts )
259
+ if err != nil {
260
+ logger .WithError (err ).Debug ("failed verify certificate" )
261
+ valid = 0
262
+ }
263
+ }
264
+
265
+ dimensions := map [string ]string {
266
+ "server_name" : host ,
267
+ "sni_server_name" : serverName ,
249
268
}
250
269
251
270
dps = append (dps ,
0 commit comments