summaryrefslogtreecommitdiffstats
path: root/plugins/sslutils.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/sslutils.c')
-rw-r--r--plugins/sslutils.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/plugins/sslutils.c b/plugins/sslutils.c
index 4f9c793..14f6579 100644
--- a/plugins/sslutils.c
+++ b/plugins/sslutils.c
@@ -1,29 +1,29 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2*
3* Monitoring Plugins SSL utilities 3* Monitoring Plugins SSL utilities
4* 4*
5* License: GPL 5* License: GPL
6* Copyright (c) 2005-2010 Monitoring Plugins Development Team 6* Copyright (c) 2005-2010 Monitoring Plugins Development Team
7* 7*
8* Description: 8* Description:
9* 9*
10* This file contains common functions for plugins that require SSL. 10* This file contains common functions for plugins that require SSL.
11* 11*
12* 12*
13* This program is free software: you can redistribute it and/or modify 13* This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14* it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15* the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16* (at your option) any later version.
17* 17*
18* This program is distributed in the hope that it will be useful, 18* This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19* but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21* GNU General Public License for more details.
22* 22*
23* You should have received a copy of the GNU General Public License 23* You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24* along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25*
26* 26*
27*****************************************************************************/ 27*****************************************************************************/
28 28
29#define MAX_CN_LENGTH 256 29#define MAX_CN_LENGTH 256
@@ -48,7 +48,7 @@ int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int versi
48} 48}
49 49
50int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey) { 50int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey) {
51 SSL_METHOD *method = NULL; 51 const SSL_METHOD *method = NULL;
52 long options = 0; 52 long options = 0;
53 53
54 switch (version) { 54 switch (version) {
@@ -193,11 +193,22 @@ int np_net_ssl_read(void *buf, int num) {
193 193
194int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){ 194int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
195# ifdef USE_OPENSSL 195# ifdef USE_OPENSSL
196 X509 *certificate=NULL; 196 X509 *certificate = NULL;
197 certificate=SSL_get_peer_certificate(s);
198 return(np_net_ssl_check_certificate(certificate, days_till_exp_warn, days_till_exp_crit));
199# else /* ifndef USE_OPENSSL */
200 printf("%s\n", _("WARNING - Plugin does not support checking certificates."));
201 return STATE_WARNING;
202# endif /* USE_OPENSSL */
203}
204
205int np_net_ssl_check_certificate(X509 *certificate, int days_till_exp_warn, int days_till_exp_crit){
206# ifdef USE_OPENSSL
197 X509_NAME *subj=NULL; 207 X509_NAME *subj=NULL;
198 char timestamp[50] = ""; 208 char timestamp[50] = "";
199 char cn[MAX_CN_LENGTH]= ""; 209 char cn[MAX_CN_LENGTH]= "";
200 210 char *tz;
211
201 int cnlen =-1; 212 int cnlen =-1;
202 int status=STATE_UNKNOWN; 213 int status=STATE_UNKNOWN;
203 214
@@ -209,7 +220,6 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
209 int time_remaining; 220 int time_remaining;
210 time_t tm_t; 221 time_t tm_t;
211 222
212 certificate=SSL_get_peer_certificate(s);
213 if (!certificate) { 223 if (!certificate) {
214 printf("%s\n",_("CRITICAL - Cannot retrieve server certificate.")); 224 printf("%s\n",_("CRITICAL - Cannot retrieve server certificate."));
215 return STATE_CRITICAL; 225 return STATE_CRITICAL;
@@ -264,10 +274,18 @@ int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit){
264 (tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0'); 274 (tm->data[10 + offset] - '0') * 10 + (tm->data[11 + offset] - '0');
265 stamp.tm_isdst = -1; 275 stamp.tm_isdst = -1;
266 276
267 time_left = difftime(timegm(&stamp), time(NULL)); 277 tm_t = timegm(&stamp);
278 time_left = difftime(tm_t, time(NULL));
268 days_left = time_left / 86400; 279 days_left = time_left / 86400;
269 tm_t = mktime (&stamp); 280 tz = getenv("TZ");
270 strftime(timestamp, 50, "%c", localtime(&tm_t)); 281 setenv("TZ", "GMT", 1);
282 tzset();
283 strftime(timestamp, 50, "%c %z", localtime(&tm_t));
284 if (tz)
285 setenv("TZ", tz, 1);
286 else
287 unsetenv("TZ");
288 tzset();
271 289
272 if (days_left > 0 && days_left <= days_till_exp_warn) { 290 if (days_left > 0 && days_left <= days_till_exp_warn) {
273 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp); 291 printf (_("%s - Certificate '%s' expires in %d day(s) (%s).\n"), (days_left>days_till_exp_crit)?"WARNING":"CRITICAL", cn, days_left, timestamp);