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 Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. 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_certchainchecker.c
40 * CertChainChecker Object Functions
44 #include "pkix_certchainchecker.h"
46 /* --Private-Functions-------------------------------------------- */
49 * FUNCTION: pkix_CertChainChecker_Destroy
50 * (see comments for PKIX_PL_DestructorCallback in pkix_pl_system.h)
53 pkix_CertChainChecker_Destroy(
54 PKIX_PL_Object
*object
,
57 PKIX_CertChainChecker
*checker
= NULL
;
59 PKIX_ENTER(CERTCHAINCHECKER
, "pkix_CertChainChecker_Destroy");
60 PKIX_NULLCHECK_ONE(object
);
62 /* Check that this object is a cert chain checker */
63 PKIX_CHECK(pkix_CheckType
64 (object
, PKIX_CERTCHAINCHECKER_TYPE
, plContext
),
65 PKIX_OBJECTNOTCERTCHAINCHECKER
);
67 checker
= (PKIX_CertChainChecker
*)object
;
69 PKIX_DECREF(checker
->extensions
);
70 PKIX_DECREF(checker
->state
);
74 PKIX_RETURN(CERTCHAINCHECKER
);
78 * FUNCTION: pkix_CertChainChecker_Duplicate
79 * (see comments for PKIX_PL_DuplicateCallback in pkix_pl_system.h)
82 pkix_CertChainChecker_Duplicate(
83 PKIX_PL_Object
*object
,
84 PKIX_PL_Object
**pNewObject
,
87 PKIX_CertChainChecker
*checker
= NULL
;
88 PKIX_CertChainChecker
*checkerDuplicate
= NULL
;
89 PKIX_List
*extensionsDuplicate
= NULL
;
90 PKIX_PL_Object
*stateDuplicate
= NULL
;
92 PKIX_ENTER(CERTCHAINCHECKER
, "pkix_CertChainChecker_Duplicate");
93 PKIX_NULLCHECK_TWO(object
, pNewObject
);
95 PKIX_CHECK(pkix_CheckType
96 (object
, PKIX_CERTCHAINCHECKER_TYPE
, plContext
),
97 PKIX_OBJECTNOTCERTCHAINCHECKER
);
99 checker
= (PKIX_CertChainChecker
*)object
;
101 if (checker
->extensions
){
102 PKIX_CHECK(PKIX_PL_Object_Duplicate
103 ((PKIX_PL_Object
*)checker
->extensions
,
104 (PKIX_PL_Object
**)&extensionsDuplicate
,
106 PKIX_OBJECTDUPLICATEFAILED
);
110 PKIX_CHECK(PKIX_PL_Object_Duplicate
111 ((PKIX_PL_Object
*)checker
->state
,
112 (PKIX_PL_Object
**)&stateDuplicate
,
114 PKIX_OBJECTDUPLICATEFAILED
);
117 PKIX_CHECK(PKIX_CertChainChecker_Create
118 (checker
->checkCallback
,
119 checker
->forwardChecking
,
120 checker
->isForwardDirectionExpected
,
125 PKIX_CERTCHAINCHECKERCREATEFAILED
);
127 *pNewObject
= (PKIX_PL_Object
*)checkerDuplicate
;
131 PKIX_DECREF(extensionsDuplicate
);
132 PKIX_DECREF(stateDuplicate
);
134 PKIX_RETURN(CERTCHAINCHECKER
);
138 * FUNCTION: pkix_CertChainChecker_RegisterSelf
140 * Registers PKIX_CERTCHAINCHECKER_TYPE and its related functions with
143 * Not Thread Safe - for performance and complexity reasons
145 * Since this function is only called by PKIX_PL_Initialize, which should
146 * only be called once, it is acceptable that this function is not
150 pkix_CertChainChecker_RegisterSelf(void *plContext
)
152 extern pkix_ClassTable_Entry systemClasses
[PKIX_NUMTYPES
];
153 pkix_ClassTable_Entry entry
;
155 PKIX_ENTER(CERTCHAINCHECKER
, "pkix_CertChainChecker_RegisterSelf");
157 entry
.description
= "CertChainChecker";
158 entry
.destructor
= pkix_CertChainChecker_Destroy
;
159 entry
.equalsFunction
= NULL
;
160 entry
.hashcodeFunction
= NULL
;
161 entry
.toStringFunction
= NULL
;
162 entry
.comparator
= NULL
;
163 entry
.duplicateFunction
= pkix_CertChainChecker_Duplicate
;
165 systemClasses
[PKIX_CERTCHAINCHECKER_TYPE
] = entry
;
167 PKIX_RETURN(CERTCHAINCHECKER
);
170 /* --Public-Functions--------------------------------------------- */
174 * FUNCTION: PKIX_CertChainChecker_Create (see comments in pkix_checker.h)
177 PKIX_CertChainChecker_Create(
178 PKIX_CertChainChecker_CheckCallback callback
,
179 PKIX_Boolean forwardCheckingSupported
,
180 PKIX_Boolean isForwardDirectionExpected
,
181 PKIX_List
*list
, /* list of PKIX_PL_OID */
182 PKIX_PL_Object
*initialState
,
183 PKIX_CertChainChecker
**pChecker
,
186 PKIX_CertChainChecker
*checker
= NULL
;
188 PKIX_ENTER(CERTCHAINCHECKER
, "PKIX_CertChainChecker_Create");
189 PKIX_NULLCHECK_ONE(pChecker
);
191 PKIX_CHECK(PKIX_PL_Object_Alloc
192 (PKIX_CERTCHAINCHECKER_TYPE
,
193 sizeof (PKIX_CertChainChecker
),
194 (PKIX_PL_Object
**)&checker
,
196 PKIX_COULDNOTCREATECERTCHAINCHECKEROBJECT
);
198 /* initialize fields */
199 checker
->checkCallback
= callback
;
200 checker
->forwardChecking
= forwardCheckingSupported
;
201 checker
->isForwardDirectionExpected
= isForwardDirectionExpected
;
204 checker
->extensions
= list
;
206 PKIX_INCREF(initialState
);
207 checker
->state
= initialState
;
213 PKIX_RETURN(CERTCHAINCHECKER
);
218 * FUNCTION: PKIX_CertChainChecker_GetCheckCallback
219 * (see comments in pkix_checker.h)
222 PKIX_CertChainChecker_GetCheckCallback(
223 PKIX_CertChainChecker
*checker
,
224 PKIX_CertChainChecker_CheckCallback
*pCallback
,
227 PKIX_ENTER(CERTCHAINCHECKER
, "PKIX_CertChainChecker_GetCheckCallback");
228 PKIX_NULLCHECK_TWO(checker
, pCallback
);
230 *pCallback
= checker
->checkCallback
;
232 PKIX_RETURN(CERTCHAINCHECKER
);
236 * FUNCTION: PKIX_CertChainChecker_IsForwardCheckingSupported
237 * (see comments in pkix_checker.h)
240 PKIX_CertChainChecker_IsForwardCheckingSupported(
241 PKIX_CertChainChecker
*checker
,
242 PKIX_Boolean
*pForwardCheckingSupported
,
247 "PKIX_CertChainChecker_IsForwardCheckingSupported");
248 PKIX_NULLCHECK_TWO(checker
, pForwardCheckingSupported
);
250 *pForwardCheckingSupported
= checker
->forwardChecking
;
252 PKIX_RETURN(CERTCHAINCHECKER
);
256 * FUNCTION: PKIX_CertChainChecker_IsForwardDirectionExpected
257 * (see comments in pkix_checker.h)
260 PKIX_CertChainChecker_IsForwardDirectionExpected(
261 PKIX_CertChainChecker
*checker
,
262 PKIX_Boolean
*pForwardDirectionExpected
,
267 "PKIX_CertChainChecker_IsForwardDirectionExpected");
268 PKIX_NULLCHECK_TWO(checker
, pForwardDirectionExpected
);
270 *pForwardDirectionExpected
= checker
->isForwardDirectionExpected
;
272 PKIX_RETURN(CERTCHAINCHECKER
);
276 * FUNCTION: PKIX_CertChainChecker_GetCertChainCheckerState
277 * (see comments in pkix_checker.h)
280 PKIX_CertChainChecker_GetCertChainCheckerState(
281 PKIX_CertChainChecker
*checker
,
282 PKIX_PL_Object
**pCertChainCheckerState
,
285 PKIX_ENTER(CERTCHAINCHECKER
,
286 "PKIX_CertChainChecker_GetCertChainCheckerState");
288 PKIX_NULLCHECK_TWO(checker
, pCertChainCheckerState
);
290 PKIX_INCREF(checker
->state
);
292 *pCertChainCheckerState
= checker
->state
;
294 PKIX_RETURN(CERTCHAINCHECKER
);
299 * FUNCTION: PKIX_CertChainChecker_SetCertChainCheckerState
300 * (see comments in pkix_checker.h)
303 PKIX_CertChainChecker_SetCertChainCheckerState(
304 PKIX_CertChainChecker
*checker
,
305 PKIX_PL_Object
*certChainCheckerState
,
308 PKIX_ENTER(CERTCHAINCHECKER
,
309 "PKIX_CertChainChecker_SetCertChainCheckerState");
311 PKIX_NULLCHECK_ONE(checker
);
313 /* DecRef old contents */
314 PKIX_DECREF(checker
->state
);
316 PKIX_INCREF(certChainCheckerState
);
317 checker
->state
= certChainCheckerState
;
319 PKIX_CHECK(PKIX_PL_Object_InvalidateCache
320 ((PKIX_PL_Object
*)checker
, plContext
),
321 PKIX_OBJECTINVALIDATECACHEFAILED
);
325 PKIX_RETURN(CERTCHAINCHECKER
);
329 * FUNCTION: PKIX_CertChainChecker_GetSupportedExtensions
330 * (see comments in pkix_checker.h)
333 PKIX_CertChainChecker_GetSupportedExtensions(
334 PKIX_CertChainChecker
*checker
,
335 PKIX_List
**pExtensions
, /* list of PKIX_PL_OID */
338 PKIX_ENTER(CERTCHAINCHECKER
,
339 "PKIX_CertChainChecker_GetSupportedExtensions");
341 PKIX_NULLCHECK_TWO(checker
, pExtensions
);
343 PKIX_INCREF(checker
->extensions
);
345 *pExtensions
= checker
->extensions
;
347 PKIX_RETURN(CERTCHAINCHECKER
);