1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is the PKIX-C library.
16 * The Initial Developer of the Original Code is
17 * Sun Microsystems, Inc.
18 * Portions created by the Initial Developer are
19 * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
22 * Sun Microsystems, Inc.
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 * pkix_expirationchecker.c
40 * Functions for expiration validation
45 #include "pkix_expirationchecker.h"
47 /* --Private-Functions-------------------------------------------- */
50 * FUNCTION: pkix_ExpirationChecker_Check
51 * (see comments for PKIX_CertChainChecker_CheckCallback in pkix_checker.h)
54 pkix_ExpirationChecker_Check(
55 PKIX_CertChainChecker *checker,
57 PKIX_List *unresolvedCriticalExtensions,
61 PKIX_PL_Date *testDate = NULL;
63 PKIX_ENTER(CERTCHAINCHECKER, "pkix_ExpirationChecker_Check");
64 PKIX_NULLCHECK_THREE(checker, cert, pNBIOContext);
66 *pNBIOContext = NULL; /* we never block on pending I/O */
68 PKIX_CHECK(PKIX_CertChainChecker_GetCertChainCheckerState
69 (checker, (PKIX_PL_Object **)&testDate, plContext),
70 PKIX_CERTCHAINCHECKERGETCERTCHAINCHECKERSTATEFAILED);
72 PKIX_CHECK(PKIX_PL_Cert_CheckValidity(cert, testDate, plContext),
73 PKIX_CERTCHECKVALIDITYFAILED);
77 PKIX_DECREF(testDate);
79 PKIX_RETURN(CERTCHAINCHECKER);
84 * FUNCTION: pkix_ExpirationChecker_Initialize
87 * Creates a new CertChainChecker and stores it at "pChecker", where it will
88 * used by pkix_ExpirationChecker_Check to check that the certificate has not
89 * expired with respect to the Date pointed to by "testDate." If "testDate"
90 * is NULL, then the CertChainChecker will check that a certificate has not
91 * expired with respect to the current date and time.
95 * Address of Date representing the point in time at which the cert is to
96 * be validated. If "testDate" is NULL, the current date and time is used.
98 * Address where object pointer will be stored. Must be non-NULL.
100 * Platform-specific context pointer.
102 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
104 * Returns NULL if the function succeeds.
105 * Returns a CertChainChecker Error if the function fails in a non-fatal way.
106 * Returns a Fatal Error if the function fails in an unrecoverable way.
109 pkix_ExpirationChecker_Initialize(
110 PKIX_PL_Date *testDate,
111 PKIX_CertChainChecker **pChecker,
114 PKIX_PL_Date *myDate = NULL;
115 PKIX_PL_Date *nowDate = NULL;
117 PKIX_ENTER(CERTCHAINCHECKER, "pkix_ExpirationChecker_Initialize");
118 PKIX_NULLCHECK_ONE(pChecker);
120 /* if testDate is NULL, we use the current time */
122 PKIX_CHECK(PKIX_PL_Date_Create_UTCTime
123 (NULL, &nowDate, plContext),
124 PKIX_DATECREATEUTCTIMEFAILED);
130 PKIX_CHECK(PKIX_CertChainChecker_Create
131 (pkix_ExpirationChecker_Check,
135 (PKIX_PL_Object *)myDate,
138 PKIX_CERTCHAINCHECKERCREATEFAILED);
142 PKIX_DECREF(nowDate);
144 PKIX_RETURN(CERTCHAINCHECKER);