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
18 * Portions created by the Initial Developer are
19 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
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_pl_ocspcertid.c
40 * Certificate ID Object for OCSP
44 #include "pkix_pl_ocspcertid.h"
46 /* --Private-Cert-Functions------------------------------------- */
49 * FUNCTION: pkix_pl_OcspCertID_Destroy
50 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
53 pkix_pl_OcspCertID_Destroy(
54 PKIX_PL_Object
*object
,
57 PKIX_PL_OcspCertID
*certID
= NULL
;
59 PKIX_ENTER(OCSPCERTID
, "pkix_pl_OcspCertID_Destroy");
61 PKIX_NULLCHECK_ONE(object
);
63 PKIX_CHECK(pkix_CheckType(object
, PKIX_OCSPCERTID_TYPE
, plContext
),
64 PKIX_OBJECTNOTOCSPCERTID
);
66 certID
= (PKIX_PL_OcspCertID
*)object
;
68 if (!certID
->certIDWasConsumed
) {
69 CERT_DestroyOCSPCertID(certID
->certID
);
74 PKIX_RETURN(OCSPCERTID
);
78 * FUNCTION: pkix_pl_OcspCertID_RegisterSelf
80 * Registers PKIX_PUBLICKEY_TYPE and its related functions
81 * with systemClasses[]
83 * Not Thread Safe - for performance and complexity reasons
85 * Since this function is only called by PKIX_PL_Initialize, which should
86 * only be called once, it is acceptable that this function is not
90 pkix_pl_OcspCertID_RegisterSelf(void *plContext
)
92 extern pkix_ClassTable_Entry systemClasses
[PKIX_NUMTYPES
];
93 pkix_ClassTable_Entry entry
;
95 PKIX_ENTER(OCSPCERTID
, "pkix_pl_OcspCertID_RegisterSelf");
97 entry
.description
= "OcspCertID";
99 entry
.typeObjectSize
= sizeof(PKIX_PL_OcspCertID
);
100 entry
.destructor
= pkix_pl_OcspCertID_Destroy
;
101 entry
.equalsFunction
= NULL
;
102 entry
.hashcodeFunction
= NULL
;
103 entry
.toStringFunction
= NULL
;
104 entry
.comparator
= NULL
;
105 entry
.duplicateFunction
= pkix_duplicateImmutable
;
106 systemClasses
[PKIX_OCSPCERTID_TYPE
] = entry
;
108 PKIX_RETURN(OCSPCERTID
);
111 /* --Public-Functions------------------------------------------------------- */
114 * FUNCTION: PKIX_PL_OcspCertID_Create
117 * This function creates an OcspCertID for a given certificate,
118 * to be used with OCSP transactions.
120 * If a Date is provided in "validity" it may be used in the search for the
121 * issuer of "cert" but has no effect on the request itself.
125 * Address of the Cert for which an OcspCertID is to be created. Must be
128 * Address of the Date for which the Cert's validity is to be determined.
131 * Address at which the result is stored. Must be non-NULL.
133 * Platform-specific context pointer.
135 * Thread Safe (see Thread Safety Definitions in Programmer's Guide)
137 * Returns NULL if the function succeeds.
138 * Returns an OcspCertID Error if the function fails in a non-fatal way.
139 * Returns a Fatal Error if the function fails in an unrecoverable way.
142 PKIX_PL_OcspCertID_Create(
144 PKIX_PL_Date
*validity
,
145 PKIX_PL_OcspCertID
**object
,
148 PKIX_PL_OcspCertID
*cid
= NULL
;
151 PKIX_ENTER(DATE
, "PKIX_PL_OcspCertID_Create");
152 PKIX_NULLCHECK_TWO(cert
, object
);
154 PKIX_CHECK(PKIX_PL_Object_Alloc
155 (PKIX_OCSPCERTID_TYPE
,
156 sizeof (PKIX_PL_OcspCertID
),
157 (PKIX_PL_Object
**)&cid
,
159 PKIX_COULDNOTCREATEOBJECT
);
161 cid
->certIDWasConsumed
= PR_FALSE
;
163 if (validity
!= NULL
) {
164 PKIX_CHECK(pkix_pl_Date_GetPRTime(validity
, &time
, plContext
),
165 PKIX_DATEGETPRTIMEFAILED
);
170 cid
->certID
= CERT_CreateOCSPCertID(cert
->nssCert
, time
);
172 PKIX_ERROR(PKIX_COULDNOTCREATEOBJECT
);
179 PKIX_RETURN(OCSPCERTID
);
183 * FUNCTION: PKIX_PL_OcspCertID_GetFreshCacheStatus
186 * This function may return cached OCSP results for the provided
187 * certificate, but only if stored information is still considered to be
192 * A certificate ID as used by OCSP
194 * Optional date parameter to request validity for a specifc time.
196 * Output parameter, if the function successed to find fresh cached
197 * information, this will be set to true. Must be non-NULL.
199 * The good/bad result stored in the cache. Must be non-NULL.
200 * "missingResponseError"
201 * If OCSP status is "bad", this variable may indicate the exact
202 * reason why the previous OCSP request had failed.
204 * Platform-specific context pointer.
206 * Returns NULL if the function succeeds.
207 * Returns an OcspCertID Error if the function fails in a non-fatal way.
208 * Returns a Fatal Error if the function fails in an unrecoverable way.
211 PKIX_PL_OcspCertID_GetFreshCacheStatus(
212 PKIX_PL_OcspCertID
*cid
,
213 PKIX_PL_Date
*validity
,
214 PKIX_Boolean
*hasFreshStatus
,
215 PKIX_Boolean
*statusIsGood
,
216 SECErrorCodes
*missingResponseError
,
223 PKIX_ENTER(DATE
, "PKIX_PL_OcspCertID_GetFreshCacheStatus");
224 PKIX_NULLCHECK_THREE(cid
, hasFreshStatus
, statusIsGood
);
226 if (validity
!= NULL
) {
227 PKIX_CHECK(pkix_pl_Date_GetPRTime(validity
, &time
, plContext
),
228 PKIX_DATEGETPRTIMEFAILED
);
233 rv
= ocsp_GetCachedOCSPResponseStatusIfFresh(
234 cid
->certID
, time
, PR_TRUE
, /*ignoreGlobalOcspFailureSetting*/
235 &rvOcsp
, missingResponseError
);
237 *hasFreshStatus
= (rv
== SECSuccess
);
238 if (*hasFreshStatus
) {
239 *statusIsGood
= (rvOcsp
== SECSuccess
);
242 PKIX_RETURN(OCSPCERTID
);
246 * FUNCTION: PKIX_PL_OcspCertID_RememberOCSPProcessingFailure
249 * Information about the current failure associated to the given certID
250 * will be remembered in the cache, potentially allowing future calls
251 * to prevent repetitive OCSP requests.
252 * After this function got called, it may no longer be safe to
253 * use the provided cid parameter, because ownership might have been
254 * transfered to the cache. This status will be recorded inside the
259 * The certificate ID associated to a failed OCSP processing.
261 * Platform-specific context pointer.
263 * Returns NULL if the function succeeds.
264 * Returns an OcspCertID Error if the function fails in a non-fatal way.
265 * Returns a Fatal Error if the function fails in an unrecoverable way.
268 PKIX_PL_OcspCertID_RememberOCSPProcessingFailure(
269 PKIX_PL_OcspCertID
*cid
,
272 PKIX_ENTER(DATE
, "PKIX_PL_OcspCertID_RememberOCSPProcessingFailure");
274 cert_RememberOCSPProcessingFailure(cid
->certID
, &cid
->certIDWasConsumed
);
276 PKIX_RETURN(OCSPCERTID
);