@@ -41,6 +41,11 @@ type SSLCheck struct {
41
41
DaysCritical int
42
42
}
43
43
44
+ type ClientCert struct {
45
+ ClientCertFile string
46
+ PrivateKeyFile string
47
+ }
48
+
44
49
// Request
45
50
type Request struct {
46
51
Scheme string
@@ -57,6 +62,7 @@ type Request struct {
57
62
WarningTimeout int
58
63
CriticalTimeout int
59
64
NoSNI bool
65
+ ClientCert ClientCert
60
66
}
61
67
62
68
// Check params
@@ -122,7 +128,7 @@ func checkCerts(certs [][]*x509.Certificate, e *Expected) (string, int) {
122
128
}
123
129
124
130
// TLS config factory
125
- func getTLSConfig (r * Request ) * tls.Config {
131
+ func getTLSConfig (r * Request ) ( * tls.Config , error ) {
126
132
TLSConfig := & tls.Config {}
127
133
128
134
// InsecureSkipVerify
@@ -135,12 +141,27 @@ func getTLSConfig(r *Request) *tls.Config {
135
141
TLSConfig .ServerName = r .Host
136
142
}
137
143
138
- return TLSConfig
144
+ // Client cert
145
+ if r .ClientCert .ClientCertFile != "" && r .ClientCert .PrivateKeyFile != "" {
146
+ cert , err := tls .LoadX509KeyPair (r .ClientCert .ClientCertFile , r .ClientCert .PrivateKeyFile )
147
+ if err != nil {
148
+ return nil , err
149
+ }
150
+ TLSConfig .Certificates = []tls.Certificate {cert }
151
+ }
152
+
153
+ return TLSConfig , nil
139
154
}
140
155
141
156
// HTTP client factory
142
- func initHTTPClient (r * Request ) * http.Client {
143
- http .DefaultTransport .(* http.Transport ).TLSClientConfig = getTLSConfig (r )
157
+ func initHTTPClient (r * Request ) (* http.Client , error ) {
158
+ // Get TLS config
159
+ TLSConfig , err := getTLSConfig (r )
160
+ if err != nil {
161
+ return nil , err
162
+ }
163
+
164
+ http .DefaultTransport .(* http.Transport ).TLSClientConfig = TLSConfig
144
165
145
166
// Setup timeout
146
167
var timeout time.Duration
@@ -162,7 +183,7 @@ func initHTTPClient(r *Request) *http.Client {
162
183
},
163
184
}
164
185
165
- return client
186
+ return client , nil
166
187
}
167
188
168
189
// Adds custom User-Agent header
@@ -176,7 +197,11 @@ func Check(r *Request, e *Expected) (string, int, error) {
176
197
return "UNKNOWN - No host or IP address given" , EXIT_UNKNOWN , nil
177
198
}
178
199
179
- client := initHTTPClient (r )
200
+ client , err := initHTTPClient (r )
201
+ if err != nil {
202
+ return "CRITICAL" , EXIT_CRITICAL , err
203
+ }
204
+
180
205
url := r .GetURL ()
181
206
182
207
if r .Verbose {
@@ -203,9 +228,14 @@ func Check(r *Request, e *Expected) (string, int, error) {
203
228
204
229
// TODO - test
205
230
if r .Authentication .Type == AUTH_NTLM {
231
+ // Get TLS config
232
+ TLSConfig , err := getTLSConfig (r )
233
+ if err != nil {
234
+ return "CRITICAL" , EXIT_CRITICAL , err
235
+ }
206
236
transport := ntlmssp.Negotiator {
207
237
RoundTripper : & http.Transport {
208
- TLSClientConfig : getTLSConfig ( r ) ,
238
+ TLSClientConfig : TLSConfig ,
209
239
},
210
240
}
211
241
client .Transport = transport
@@ -286,7 +316,12 @@ func Check(r *Request, e *Expected) (string, int, error) {
286
316
287
317
// Detects auth type
288
318
func DetectAuthType (r * Request ) int {
289
- client := initHTTPClient (r )
319
+ client , err := initHTTPClient (r )
320
+ if err != nil {
321
+ // `Check` should handle all errors
322
+ return AUTH_NONE
323
+ }
324
+
290
325
url := r .GetURL ()
291
326
292
327
request , err := http .NewRequest ("GET" , url , nil )
0 commit comments