int warning_after = 30;
int error_after = 7;
+int verbose = 0;
#define LOG_LEVEL 0
/* Connect to server */
- int fd = tcp_open( hostname, service );
+ long fd = tcp_open( hostname, service );
if (fd == -1) {
state= S_UNREACHABLE;
gnutls_x509_crt_import( cert, &cert_list[0], GNUTLS_X509_FMT_DER );
expiration_time = gnutls_x509_crt_get_expiration_time( cert );
int expires_in = (expiration_time - today) / 86400;
+ struct tm * t = gmtime( &expiration_time );
if ((state == S_OK) && (expires_in <= warning_after)) {
state = S_WARNING;
- sprintf(errmsg, "Certificate will expire in %i days.", expires_in);
+ sprintf(errmsg, "Warning - Will expire in %i days (%i-%02i-%02i).", expires_in,
+ t->tm_year+1900, t->tm_mon+1, t->tm_mday );
}
if ((state <= S_WARNING) && (expires_in <= error_after)) {
state = S_ERROR;
- sprintf(errmsg, "Certificate will expire in %i days.", expires_in);
+ sprintf(errmsg, "Critical - Will expire in %i days (%i-%02i-%02i).", expires_in,
+ t->tm_year+1900, t->tm_mon+1, t->tm_mday );
+ }
+ if (state == S_OK) {
+ sprintf(errmsg, "OK - Will expire in %i days (%i-%02i-%02i).", expires_in,
+ t->tm_year+1900, t->tm_mon+1, t->tm_mday );
}
}
- printf("Got %i certs.", cert_list_size);
-
/* Clean up */
err = gnutls_bye( session, GNUTLS_SHUT_WR );
if (err < 0) gnutls_die(err);
case 'h':
print_help();
exit(0);
+ case 'v':
+ verbose++;
default: break;
}
}
}
void print_help() {
- printf("Help yourself.");
+ printf(
+ "Usage: cert-checker [options] -H hostname -p|s port|service\n"
+ " Where options could be: \n"
+ " -h this help\n"
+ " -w warning level (in days, default 30)\n"
+ " -c critical level (in days, default 7)\n"
+ " -v verbosity level\n"
+ );
}