2004-09-10 14:16:06 +00:00
|
|
|
/*
|
2005-04-26 09:20:45 +00:00
|
|
|
Copyright 2005 Red Hat, Inc.
|
2004-09-10 14:22:53 +00:00
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2004-09-10 14:22:53 +00:00
|
|
|
In addition, as a special exception, Red Hat, Inc. gives permission
|
|
|
|
to link the code of this program with the OpenSSL library (or with
|
|
|
|
modified versions of OpenSSL that use the same license as OpenSSL),
|
|
|
|
and distribute linked combinations including the two. You must obey
|
|
|
|
the GNU General Public License in all respects for all of the code
|
|
|
|
used other than OpenSSL. If you modify this file, you may extend
|
|
|
|
this exception to your version of the file, but you are not
|
|
|
|
obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version.
|
2004-09-10 14:16:06 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is the Netscape security libraries.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1994-2000
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
|
2004-11-10 14:16:02 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
/* Certificate expiry warning generation code, based on code from
|
|
|
|
* Stronghold. Joe Orton <jorton@redhat.com> */
|
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* Replaced usage of OpenSSL with NSS.
|
|
|
|
* Elio Maldonado <emaldona@redhat.com> */
|
|
|
|
|
|
|
|
#include <nspr.h>
|
|
|
|
#include <nss.h>
|
|
|
|
#include <cert.h>
|
|
|
|
#include <certt.h>
|
|
|
|
#include <prlong.h>
|
|
|
|
#include <prtime.h>
|
|
|
|
#include <pk11func.h>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <secmod.h>
|
|
|
|
#include <base64.h>
|
|
|
|
#include <seccomon.h>
|
2008-12-24 22:19:24 +00:00
|
|
|
#include <certt.h>
|
2004-09-10 14:16:06 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2005-04-26 09:20:45 +00:00
|
|
|
#include <getopt.h>
|
2005-05-26 08:08:46 +00:00
|
|
|
#include <time.h>
|
2005-04-26 09:20:45 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
#define TIME_BUF_SIZE 100
|
|
|
|
|
2008-12-24 22:19:24 +00:00
|
|
|
/* Return a certificate structure from a pem-encoded cert in a file;
|
2008-05-01 01:25:10 +00:00
|
|
|
* or NULL on failure. Semantics similar to the OpenSSL call
|
|
|
|
* PEM_read_X509(fp, NULL, NULL, NULL);
|
|
|
|
*/
|
2008-12-24 22:19:24 +00:00
|
|
|
extern CERTCertificate *
|
2008-05-01 01:25:10 +00:00
|
|
|
PEMUTIL_PEM_read_X509(const char *filename);
|
|
|
|
|
|
|
|
/* size big enough for formatting time buffer */
|
|
|
|
#define TIME_SIZE 30
|
|
|
|
|
2005-04-26 09:20:45 +00:00
|
|
|
static int warn_period = 30;
|
|
|
|
static char *warn_address = "root";
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-12-24 22:19:24 +00:00
|
|
|
/* Uses the password passed in the -f(pwfile) argument of the command line.
|
2008-05-01 01:25:10 +00:00
|
|
|
* After use once, null it out otherwise PKCS11 calls us forever.?
|
2008-12-24 22:19:24 +00:00
|
|
|
*
|
2008-05-01 01:25:10 +00:00
|
|
|
* Code based on SECU_GetModulePassword from the Mozilla NSS secutils
|
2008-12-24 22:19:24 +00:00
|
|
|
* internal library.
|
2008-05-01 01:25:10 +00:00
|
|
|
*/
|
|
|
|
static char *GetModulePassword(PK11SlotInfo *slot, PRBool retry, void *arg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char phrase[200];
|
|
|
|
PRFileDesc *fd;
|
|
|
|
PRInt32 nb;
|
|
|
|
char *pwFile = arg;
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
if (!pwFile) return 0;
|
2008-12-24 22:19:24 +00:00
|
|
|
if (retry) return 0; /* no good retrying - file contents will be the same */
|
2008-05-01 01:25:10 +00:00
|
|
|
if (!(fd = PR_Open(pwFile, PR_RDONLY, 0))) return 0;
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
nb = PR_Read(fd, phrase, sizeof(phrase));
|
|
|
|
PR_Close(fd);
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* handle the Windows EOL case */
|
|
|
|
i = 0;
|
|
|
|
while (phrase[i] != '\r' && phrase[i] != '\n' && i < nb) i++;
|
|
|
|
phrase[i] = '\0';
|
|
|
|
if (nb == 0) return NULL;
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
return (char*) PORT_Strdup((char*)phrase);
|
|
|
|
}
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* Format a PRTime value into a buffer with format "%a %b %d %H:%M:%S %Y";
|
|
|
|
* semantics are those of ctime_r(). */
|
|
|
|
char *pr_ctime(PRTime time, char *buf, int size)
|
|
|
|
{
|
|
|
|
PRUint32 bytesCopied;
|
|
|
|
PRExplodedTime et;
|
|
|
|
PR_ExplodeTime(time, PR_GMTParameters, &et);
|
|
|
|
bytesCopied = PR_FormatTime(buf, size, "%a %b %d %H:%M:%S %Y", &et);
|
|
|
|
if (!bytesCopied) return NULL;
|
|
|
|
return buf;
|
2004-09-10 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-24 22:19:24 +00:00
|
|
|
|
|
|
|
/* A year is leap iff is divisible by 4 but not by 100 or is divisible by 400 */
|
|
|
|
static int leap_year(int year) {
|
|
|
|
return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Computes the day difference among two PRTime's */
|
|
|
|
static int diff_time_days(PRTime aT, PRTime bT)
|
|
|
|
{
|
|
|
|
PRTime am1, one;
|
|
|
|
PRExplodedTime a, b;
|
|
|
|
int years, days = 0;
|
|
|
|
|
|
|
|
LL_I2L(one, 1);
|
|
|
|
|
|
|
|
do {
|
|
|
|
PR_ExplodeTime(aT, PR_GMTParameters, &a);
|
|
|
|
PR_ExplodeTime(bT, PR_GMTParameters, &b);
|
|
|
|
|
|
|
|
years = a.tm_year - b.tm_year;
|
|
|
|
if (years < 0) break;
|
|
|
|
|
|
|
|
if (years == 0) {
|
|
|
|
days += (a.tm_yday - b.tm_yday);
|
|
|
|
} else if (a.tm_year == b.tm_year + 1) {
|
|
|
|
days += (365 + leap_year(b.tm_year) - b.tm_yday + a.tm_yday);
|
|
|
|
} else {
|
|
|
|
LL_SUB(am1, aT, one);
|
|
|
|
aT = am1;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (0);
|
|
|
|
|
|
|
|
return days;
|
|
|
|
}
|
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
/* Print a warning message that the certificate in 'filename', issued
|
|
|
|
* to hostname 'hostname', will expire (or has expired). */
|
|
|
|
static int warning(FILE *out, const char *filename, const char *hostname,
|
2008-12-24 22:19:24 +00:00
|
|
|
SECCertTimeValidity validity,
|
2008-05-01 01:25:10 +00:00
|
|
|
PRTime start, PRTime end, PRTime now, int quiet)
|
2004-09-10 14:16:06 +00:00
|
|
|
{
|
2008-05-01 01:25:10 +00:00
|
|
|
/* Note that filename can be the cert nickname. */
|
|
|
|
int renew = 1;
|
2004-09-10 14:16:06 +00:00
|
|
|
char subj[50];
|
2008-12-24 22:19:24 +00:00
|
|
|
|
|
|
|
switch (validity) {
|
|
|
|
case secCertTimeNotValidYet:
|
2004-09-10 14:16:06 +00:00
|
|
|
strcpy(subj, "is not yet valid");
|
|
|
|
renew = 0;
|
2008-12-24 22:19:24 +00:00
|
|
|
break;
|
|
|
|
case secCertTimeExpired:
|
|
|
|
sprintf(subj, "has expired");
|
|
|
|
break;
|
|
|
|
case secCertTimeValid:
|
|
|
|
{
|
|
|
|
/* days till expiry */
|
|
|
|
int days = diff_time_days(end, now);
|
|
|
|
if (days == 0) {
|
|
|
|
strcpy(subj, "will expire today");
|
|
|
|
} else if (days == 1) {
|
|
|
|
sprintf(subj, "will expire tomorrow");
|
|
|
|
} else if (days < warn_period) {
|
|
|
|
sprintf(subj, "will expire in %d days", days);
|
|
|
|
} else {
|
|
|
|
return 0; /* nothing to warn about. */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case secCertTimeUndetermined:
|
|
|
|
default:
|
|
|
|
/* it will never get here if caller checks validity */
|
|
|
|
strcpy(subj, "validity could not be decoded from the cert");
|
|
|
|
renew = 0;
|
|
|
|
break;
|
2004-09-10 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (quiet) return 1;
|
|
|
|
|
2005-04-26 09:20:45 +00:00
|
|
|
fprintf(out, "To: %s\n", warn_address);
|
2004-09-10 14:16:06 +00:00
|
|
|
fprintf(out, "Subject: The certificate for %s %s\n", hostname, subj);
|
|
|
|
fputs("\n", out);
|
2008-12-24 22:19:24 +00:00
|
|
|
|
|
|
|
fprintf(out,
|
2004-09-10 14:16:06 +00:00
|
|
|
" ################# SSL Certificate Warning ################\n\n");
|
|
|
|
|
2008-12-24 22:19:24 +00:00
|
|
|
fprintf(out,
|
2008-05-01 01:25:10 +00:00
|
|
|
" Certificate for hostname '%s', in file (or by nickname):\n"
|
2005-04-26 09:20:45 +00:00
|
|
|
" %s\n\n",
|
|
|
|
hostname, filename);
|
2004-09-10 14:16:06 +00:00
|
|
|
|
|
|
|
if (renew) {
|
|
|
|
fputs(" The certificate needs to be renewed; this can be done\n"
|
2004-10-19 10:15:57 +00:00
|
|
|
" using the 'genkey' program.\n\n"
|
2004-09-10 14:16:06 +00:00
|
|
|
" Browsers will not be able to correctly connect to this\n"
|
|
|
|
" web site using SSL until the certificate is renewed.\n",
|
|
|
|
out);
|
|
|
|
} else {
|
2008-05-01 01:25:10 +00:00
|
|
|
char until[TIME_SIZE];
|
|
|
|
char *result = pr_ctime(start, until, TIME_SIZE);
|
|
|
|
assert(result == until);
|
|
|
|
if (strlen(until) < sizeof(until)) until[strlen(until)] = '\0';
|
2008-12-24 22:19:24 +00:00
|
|
|
fprintf(out,
|
2004-09-10 14:16:06 +00:00
|
|
|
" The certificate is not valid until %s.\n\n"
|
|
|
|
" Browsers will not be able to correctly connect to this\n"
|
2008-12-24 22:19:24 +00:00
|
|
|
" web site using SSL until the certificate becomes valid.\n",
|
2004-09-10 14:16:06 +00:00
|
|
|
until);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("\n"
|
|
|
|
" ##########################################################\n"
|
2004-09-17 13:53:54 +00:00
|
|
|
" Generated by certwatch(1)\n\n",
|
2004-09-10 14:16:06 +00:00
|
|
|
out);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the common name of 'cert' into 'buf'. */
|
2008-05-01 01:25:10 +00:00
|
|
|
static int get_common_name(CERTCertificate *cert, char *buf, size_t bufsiz)
|
2004-09-10 14:16:06 +00:00
|
|
|
{
|
2008-05-01 01:25:10 +00:00
|
|
|
/* FIXME --- truncating names with spaces */
|
|
|
|
size_t namelen;
|
|
|
|
char *name = CERT_GetCommonName(&cert->subject);
|
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
if (!name) return -1;
|
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
namelen = strlen(name);
|
|
|
|
if (bufsiz < namelen+1) return -1;
|
|
|
|
|
|
|
|
strncpy(buf, name, namelen);
|
|
|
|
buf[namelen] = '\0';
|
|
|
|
PORT_Free(name);
|
|
|
|
|
|
|
|
return 0;
|
2004-09-10 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* Check whether the certificate in filename 'name' has expired;
|
2004-09-10 14:16:06 +00:00
|
|
|
* issue a warning message if 'quiet' is zero. If quiet is non-zero,
|
|
|
|
* returns one to indicate that a warning would have been issued, zero
|
|
|
|
* to indicate no warning would be issued, or -1 if an error
|
2008-12-24 22:19:24 +00:00
|
|
|
* occurred.
|
2008-05-01 01:25:10 +00:00
|
|
|
*
|
|
|
|
* When byNickname is 1 then 'name' is a nickname to search
|
|
|
|
* for in the database otherwise it's the certificate file.
|
|
|
|
*/
|
2008-12-24 22:19:24 +00:00
|
|
|
static int check_cert(const char *name, int byNickname, int quiet)
|
2004-09-10 14:16:06 +00:00
|
|
|
{
|
2008-05-01 01:25:10 +00:00
|
|
|
CERTCertificate *cert;
|
|
|
|
SECCertTimeValidity validity;
|
|
|
|
PRTime notBefore, notAfter;
|
2004-09-10 14:16:06 +00:00
|
|
|
char cname[128];
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
int doWarning = 0;
|
2004-09-10 14:16:06 +00:00
|
|
|
|
|
|
|
/* parse the cert */
|
2008-12-24 22:19:24 +00:00
|
|
|
cert = byNickname
|
2008-05-03 22:54:55 +00:00
|
|
|
? CERT_FindCertByNickname(CERT_GetDefaultCertDB(), (char *)name)
|
|
|
|
: PEMUTIL_PEM_read_X509(name);
|
2004-09-10 14:16:06 +00:00
|
|
|
if (cert == NULL) return -1;
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
/* determine the validity period of the cert. */
|
2008-05-01 01:25:10 +00:00
|
|
|
validity = CERT_CheckCertValidTimes(cert, PR_Now(), PR_FALSE);
|
|
|
|
if (validity == secCertTimeUndetermined) goto cleanup;
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* get times out of the cert */
|
|
|
|
if (CERT_GetCertTimes(cert, ¬Before, ¬After)
|
|
|
|
!= SECSuccess) goto cleanup;
|
|
|
|
|
2004-09-10 14:16:06 +00:00
|
|
|
/* find the subject's commonName attribute */
|
|
|
|
if (get_common_name(cert, cname, sizeof cname))
|
2008-05-01 01:25:10 +00:00
|
|
|
goto cleanup;
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* don't warn about the automatically generated certificate */
|
2004-09-10 14:16:06 +00:00
|
|
|
if (strcmp(cname, "localhost") == 0 ||
|
|
|
|
strcmp(cname, "localhost.localdomain") == 0)
|
2008-05-01 01:25:10 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
doWarning = 1; /* ok so far, may do the warning */
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (cert) CERT_DestroyCertificate(cert);
|
|
|
|
if (!doWarning) return -1;
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-12-24 22:19:24 +00:00
|
|
|
return warning(stdout, name, cname, validity,
|
2008-05-03 22:54:55 +00:00
|
|
|
notBefore, notAfter, PR_Now(), quiet);
|
2004-09-10 14:16:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2005-04-26 09:20:45 +00:00
|
|
|
int optc, quiet = 0;
|
|
|
|
static const struct option options[] = {
|
|
|
|
{ "quiet", no_argument, NULL, 'q' },
|
|
|
|
{ "period", required_argument, NULL, 'p' },
|
|
|
|
{ "address", required_argument, NULL, 'a' },
|
2008-05-01 01:25:10 +00:00
|
|
|
{ "configdir", required_argument, NULL, 'd' },
|
|
|
|
{ "passwordfile", required_argument, NULL, 'w' },
|
2008-05-06 16:15:36 +00:00
|
|
|
{ "certdbprefix", required_argument, NULL, 'c' },
|
|
|
|
{ "keydbprexix", required_argument, NULL, 'k' },
|
2005-04-26 09:20:45 +00:00
|
|
|
{ NULL }
|
|
|
|
};
|
2008-12-24 22:19:24 +00:00
|
|
|
const char *opts = "qp:a:d:w:c:k:";
|
|
|
|
char *certDBPrefix = "";
|
2008-05-01 01:25:10 +00:00
|
|
|
char *keyDBPrefix = "";
|
|
|
|
|
|
|
|
char *configdir = NULL; /* contains the cert database */
|
|
|
|
char *passwordfile = NULL; /* module password file */
|
|
|
|
int byNickname = 0; /* whether to search by nickname */
|
|
|
|
|
2005-05-26 08:08:46 +00:00
|
|
|
/* The 'timezone' global is needed to adjust local times from
|
|
|
|
* mktime() back to UTC: */
|
|
|
|
tzset();
|
2008-12-24 22:19:24 +00:00
|
|
|
|
|
|
|
while ((optc = getopt_long(argc, argv, opts, options, NULL)) != -1) {
|
2005-04-26 09:20:45 +00:00
|
|
|
switch (optc) {
|
|
|
|
case 'q':
|
|
|
|
quiet = 1;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
warn_period = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'a':
|
|
|
|
warn_address = strdup(optarg);
|
|
|
|
break;
|
2008-05-01 01:25:10 +00:00
|
|
|
case 'd':
|
|
|
|
configdir = strdup(optarg);
|
|
|
|
byNickname = 1;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
passwordfile = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
certDBPrefix = strdup(optarg);
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
keyDBPrefix = strdup(optarg);
|
|
|
|
break;
|
2005-04-26 09:20:45 +00:00
|
|
|
default:
|
|
|
|
exit(2);
|
2007-08-23 10:11:54 +00:00
|
|
|
break;
|
2005-04-26 09:20:45 +00:00
|
|
|
}
|
|
|
|
}
|
2008-12-24 22:19:24 +00:00
|
|
|
|
2008-05-01 01:25:10 +00:00
|
|
|
/* NSS initialization */
|
|
|
|
|
|
|
|
if (byNickname) {
|
|
|
|
/* cert in database */
|
2008-12-24 22:19:24 +00:00
|
|
|
if (NSS_Initialize(configdir, certDBPrefix, keyDBPrefix,
|
2008-05-01 01:25:10 +00:00
|
|
|
SECMOD_DB, NSS_INIT_READONLY) != SECSuccess) {
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
/* in case module requires a password */
|
|
|
|
if (passwordfile) {
|
2008-12-24 22:19:24 +00:00
|
|
|
PK11_SetPasswordFunc(GetModulePassword);
|
2008-05-01 01:25:10 +00:00
|
|
|
}
|
|
|
|
} else {
|
2008-05-03 22:54:55 +00:00
|
|
|
/* cert in a pem file */
|
2008-05-01 01:25:10 +00:00
|
|
|
char *certDir = getenv("SSL_DIR"); /* Look in $SSL_DIR */
|
|
|
|
if (!certDir) {
|
|
|
|
certDir = "/etc/pki/nssdb";
|
|
|
|
}
|
2008-12-24 22:19:24 +00:00
|
|
|
if (NSS_Initialize(certDir, certDBPrefix, keyDBPrefix,
|
2008-05-01 01:25:10 +00:00
|
|
|
SECMOD_DB, NSS_INIT_READONLY) != SECSuccess) {
|
2008-05-03 22:54:55 +00:00
|
|
|
printf("NSS_Init(\"%s\") failed\n", certDir);
|
2008-05-01 01:25:10 +00:00
|
|
|
return EXIT_FAILURE;
|
2008-05-03 22:54:55 +00:00
|
|
|
}
|
2008-05-01 01:25:10 +00:00
|
|
|
}
|
2004-09-10 14:16:06 +00:00
|
|
|
|
2008-12-24 22:19:24 +00:00
|
|
|
/* When byNickname is 1 argv[optind] is a nickname otherwise a filename. */
|
|
|
|
return check_cert(argv[optind], byNickname, quiet) == 1
|
|
|
|
? EXIT_SUCCESS : EXIT_FAILURE;
|
2004-09-10 14:16:06 +00:00
|
|
|
}
|