xref: /onnv-gate/usr/src/common/openssl/crypto/store/str_lib.c (revision 2139:6243c3338933)
1*2139Sjp161948 /* crypto/store/str_lib.c -*- mode:C; c-file-style: "eay" -*- */
2*2139Sjp161948 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3*2139Sjp161948  * project 2003.
4*2139Sjp161948  */
5*2139Sjp161948 /* ====================================================================
6*2139Sjp161948  * Copyright (c) 2003 The OpenSSL Project.  All rights reserved.
7*2139Sjp161948  *
8*2139Sjp161948  * Redistribution and use in source and binary forms, with or without
9*2139Sjp161948  * modification, are permitted provided that the following conditions
10*2139Sjp161948  * are met:
11*2139Sjp161948  *
12*2139Sjp161948  * 1. Redistributions of source code must retain the above copyright
13*2139Sjp161948  *    notice, this list of conditions and the following disclaimer.
14*2139Sjp161948  *
15*2139Sjp161948  * 2. Redistributions in binary form must reproduce the above copyright
16*2139Sjp161948  *    notice, this list of conditions and the following disclaimer in
17*2139Sjp161948  *    the documentation and/or other materials provided with the
18*2139Sjp161948  *    distribution.
19*2139Sjp161948  *
20*2139Sjp161948  * 3. All advertising materials mentioning features or use of this
21*2139Sjp161948  *    software must display the following acknowledgment:
22*2139Sjp161948  *    "This product includes software developed by the OpenSSL Project
23*2139Sjp161948  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24*2139Sjp161948  *
25*2139Sjp161948  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26*2139Sjp161948  *    endorse or promote products derived from this software without
27*2139Sjp161948  *    prior written permission. For written permission, please contact
28*2139Sjp161948  *    openssl-core@openssl.org.
29*2139Sjp161948  *
30*2139Sjp161948  * 5. Products derived from this software may not be called "OpenSSL"
31*2139Sjp161948  *    nor may "OpenSSL" appear in their names without prior written
32*2139Sjp161948  *    permission of the OpenSSL Project.
33*2139Sjp161948  *
34*2139Sjp161948  * 6. Redistributions of any form whatsoever must retain the following
35*2139Sjp161948  *    acknowledgment:
36*2139Sjp161948  *    "This product includes software developed by the OpenSSL Project
37*2139Sjp161948  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38*2139Sjp161948  *
39*2139Sjp161948  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40*2139Sjp161948  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41*2139Sjp161948  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42*2139Sjp161948  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43*2139Sjp161948  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44*2139Sjp161948  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45*2139Sjp161948  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46*2139Sjp161948  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47*2139Sjp161948  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48*2139Sjp161948  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49*2139Sjp161948  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50*2139Sjp161948  * OF THE POSSIBILITY OF SUCH DAMAGE.
51*2139Sjp161948  * ====================================================================
52*2139Sjp161948  *
53*2139Sjp161948  * This product includes cryptographic software written by Eric Young
54*2139Sjp161948  * (eay@cryptsoft.com).  This product includes software written by Tim
55*2139Sjp161948  * Hudson (tjh@cryptsoft.com).
56*2139Sjp161948  *
57*2139Sjp161948  */
58*2139Sjp161948 
59*2139Sjp161948 #include <string.h>
60*2139Sjp161948 #include <openssl/bn.h>
61*2139Sjp161948 #include <openssl/err.h>
62*2139Sjp161948 #ifndef OPENSSL_NO_ENGINE
63*2139Sjp161948 #include <openssl/engine.h>
64*2139Sjp161948 #endif
65*2139Sjp161948 #include <openssl/sha.h>
66*2139Sjp161948 #include <openssl/x509.h>
67*2139Sjp161948 #include "str_locl.h"
68*2139Sjp161948 
69*2139Sjp161948 const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] =
70*2139Sjp161948 	{
71*2139Sjp161948 	0,
72*2139Sjp161948 	"X.509 Certificate",
73*2139Sjp161948 	"X.509 CRL",
74*2139Sjp161948 	"Private Key",
75*2139Sjp161948 	"Public Key",
76*2139Sjp161948 	"Number",
77*2139Sjp161948 	"Arbitrary Data"
78*2139Sjp161948 	};
79*2139Sjp161948 
80*2139Sjp161948 const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1] =
81*2139Sjp161948 	{
82*2139Sjp161948 	0,
83*2139Sjp161948 	sizeof(int),		/* EVP_TYPE */
84*2139Sjp161948 	sizeof(size_t),		/* BITS */
85*2139Sjp161948 	-1,			/* KEY_PARAMETERS */
86*2139Sjp161948 	0			/* KEY_NO_PARAMETERS */
87*2139Sjp161948 	};
88*2139Sjp161948 
89*2139Sjp161948 const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1] =
90*2139Sjp161948 	{
91*2139Sjp161948 	0,
92*2139Sjp161948 	-1,			/* FRIENDLYNAME:	C string */
93*2139Sjp161948 	SHA_DIGEST_LENGTH,	/* KEYID:		SHA1 digest, 160 bits */
94*2139Sjp161948 	SHA_DIGEST_LENGTH,	/* ISSUERKEYID:		SHA1 digest, 160 bits */
95*2139Sjp161948 	SHA_DIGEST_LENGTH,	/* SUBJECTKEYID:	SHA1 digest, 160 bits */
96*2139Sjp161948 	SHA_DIGEST_LENGTH,	/* ISSUERSERIALHASH:	SHA1 digest, 160 bits */
97*2139Sjp161948 	sizeof(X509_NAME *),	/* ISSUER:		X509_NAME * */
98*2139Sjp161948 	sizeof(BIGNUM *),	/* SERIAL:		BIGNUM * */
99*2139Sjp161948 	sizeof(X509_NAME *),	/* SUBJECT:		X509_NAME * */
100*2139Sjp161948 	SHA_DIGEST_LENGTH,	/* CERTHASH:		SHA1 digest, 160 bits */
101*2139Sjp161948 	-1,			/* EMAIL:		C string */
102*2139Sjp161948 	-1,			/* FILENAME:		C string */
103*2139Sjp161948 	};
104*2139Sjp161948 
STORE_new_method(const STORE_METHOD * method)105*2139Sjp161948 STORE *STORE_new_method(const STORE_METHOD *method)
106*2139Sjp161948 	{
107*2139Sjp161948 	STORE *ret;
108*2139Sjp161948 
109*2139Sjp161948 	if (method == NULL)
110*2139Sjp161948 		{
111*2139Sjp161948 		STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER);
112*2139Sjp161948 		return NULL;
113*2139Sjp161948 		}
114*2139Sjp161948 
115*2139Sjp161948 	ret=(STORE *)OPENSSL_malloc(sizeof(STORE));
116*2139Sjp161948 	if (ret == NULL)
117*2139Sjp161948 		{
118*2139Sjp161948 		STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
119*2139Sjp161948 		return NULL;
120*2139Sjp161948 		}
121*2139Sjp161948 
122*2139Sjp161948 	ret->meth=method;
123*2139Sjp161948 
124*2139Sjp161948 	CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE, ret, &ret->ex_data);
125*2139Sjp161948 	if (ret->meth->init && !ret->meth->init(ret))
126*2139Sjp161948 		{
127*2139Sjp161948 		STORE_free(ret);
128*2139Sjp161948 		ret = NULL;
129*2139Sjp161948 		}
130*2139Sjp161948 	return ret;
131*2139Sjp161948 	}
132*2139Sjp161948 
STORE_new_engine(ENGINE * engine)133*2139Sjp161948 STORE *STORE_new_engine(ENGINE *engine)
134*2139Sjp161948 	{
135*2139Sjp161948 	STORE *ret = NULL;
136*2139Sjp161948 	ENGINE *e = engine;
137*2139Sjp161948 	const STORE_METHOD *meth = 0;
138*2139Sjp161948 
139*2139Sjp161948 #ifdef OPENSSL_NO_ENGINE
140*2139Sjp161948 	e = NULL;
141*2139Sjp161948 #else
142*2139Sjp161948 	if (engine)
143*2139Sjp161948 		{
144*2139Sjp161948 		if (!ENGINE_init(engine))
145*2139Sjp161948 			{
146*2139Sjp161948 			STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB);
147*2139Sjp161948 			return NULL;
148*2139Sjp161948 			}
149*2139Sjp161948 		e = engine;
150*2139Sjp161948 		}
151*2139Sjp161948 	else
152*2139Sjp161948 		{
153*2139Sjp161948 		STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_PASSED_NULL_PARAMETER);
154*2139Sjp161948 		return NULL;
155*2139Sjp161948 		}
156*2139Sjp161948 	if(e)
157*2139Sjp161948 		{
158*2139Sjp161948 		meth = ENGINE_get_STORE(e);
159*2139Sjp161948 		if(!meth)
160*2139Sjp161948 			{
161*2139Sjp161948 			STOREerr(STORE_F_STORE_NEW_ENGINE,
162*2139Sjp161948 				ERR_R_ENGINE_LIB);
163*2139Sjp161948 			ENGINE_finish(e);
164*2139Sjp161948 			return NULL;
165*2139Sjp161948 			}
166*2139Sjp161948 		}
167*2139Sjp161948 #endif
168*2139Sjp161948 
169*2139Sjp161948 	ret = STORE_new_method(meth);
170*2139Sjp161948 	if (ret == NULL)
171*2139Sjp161948 		{
172*2139Sjp161948 		STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_STORE_LIB);
173*2139Sjp161948 		return NULL;
174*2139Sjp161948 		}
175*2139Sjp161948 
176*2139Sjp161948 	ret->engine = e;
177*2139Sjp161948 
178*2139Sjp161948 	return(ret);
179*2139Sjp161948 	}
180*2139Sjp161948 
STORE_free(STORE * store)181*2139Sjp161948 void STORE_free(STORE *store)
182*2139Sjp161948 	{
183*2139Sjp161948 	if (store == NULL)
184*2139Sjp161948 		return;
185*2139Sjp161948 	if (store->meth->clean)
186*2139Sjp161948 		store->meth->clean(store);
187*2139Sjp161948 	CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data);
188*2139Sjp161948 	OPENSSL_free(store);
189*2139Sjp161948 	}
190*2139Sjp161948 
STORE_ctrl(STORE * store,int cmd,long i,void * p,void (* f)(void))191*2139Sjp161948 int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void))
192*2139Sjp161948 	{
193*2139Sjp161948 	if (store == NULL)
194*2139Sjp161948 		{
195*2139Sjp161948 		STOREerr(STORE_F_STORE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
196*2139Sjp161948 		return 0;
197*2139Sjp161948 		}
198*2139Sjp161948 	if (store->meth->ctrl)
199*2139Sjp161948 		return store->meth->ctrl(store, cmd, i, p, f);
200*2139Sjp161948 	STOREerr(STORE_F_STORE_CTRL,STORE_R_NO_CONTROL_FUNCTION);
201*2139Sjp161948 	return 0;
202*2139Sjp161948 	}
203*2139Sjp161948 
204*2139Sjp161948 
STORE_get_ex_new_index(long argl,void * argp,CRYPTO_EX_new * new_func,CRYPTO_EX_dup * dup_func,CRYPTO_EX_free * free_func)205*2139Sjp161948 int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
206*2139Sjp161948 	     CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
207*2139Sjp161948         {
208*2139Sjp161948 	return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE, argl, argp,
209*2139Sjp161948 				new_func, dup_func, free_func);
210*2139Sjp161948         }
211*2139Sjp161948 
STORE_set_ex_data(STORE * r,int idx,void * arg)212*2139Sjp161948 int STORE_set_ex_data(STORE *r, int idx, void *arg)
213*2139Sjp161948 	{
214*2139Sjp161948 	return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
215*2139Sjp161948 	}
216*2139Sjp161948 
STORE_get_ex_data(STORE * r,int idx)217*2139Sjp161948 void *STORE_get_ex_data(STORE *r, int idx)
218*2139Sjp161948 	{
219*2139Sjp161948 	return(CRYPTO_get_ex_data(&r->ex_data,idx));
220*2139Sjp161948 	}
221*2139Sjp161948 
STORE_get_method(STORE * store)222*2139Sjp161948 const STORE_METHOD *STORE_get_method(STORE *store)
223*2139Sjp161948 	{
224*2139Sjp161948 	return store->meth;
225*2139Sjp161948 	}
226*2139Sjp161948 
STORE_set_method(STORE * store,const STORE_METHOD * meth)227*2139Sjp161948 const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth)
228*2139Sjp161948 	{
229*2139Sjp161948 	store->meth=meth;
230*2139Sjp161948 	return store->meth;
231*2139Sjp161948 	}
232*2139Sjp161948 
233*2139Sjp161948 
234*2139Sjp161948 /* API helpers */
235*2139Sjp161948 
236*2139Sjp161948 #define check_store(s,fncode,fnname,fnerrcode) \
237*2139Sjp161948 	do \
238*2139Sjp161948 		{ \
239*2139Sjp161948 		if ((s) == NULL || (s)->meth) \
240*2139Sjp161948 			{ \
241*2139Sjp161948 			STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
242*2139Sjp161948 			return 0; \
243*2139Sjp161948 			} \
244*2139Sjp161948 		if ((s)->meth->fnname == NULL) \
245*2139Sjp161948 			{ \
246*2139Sjp161948 			STOREerr((fncode), (fnerrcode)); \
247*2139Sjp161948 			return 0; \
248*2139Sjp161948 			} \
249*2139Sjp161948 		} \
250*2139Sjp161948 	while(0)
251*2139Sjp161948 
252*2139Sjp161948 /* API functions */
253*2139Sjp161948 
STORE_get_certificate(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])254*2139Sjp161948 X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
255*2139Sjp161948 	OPENSSL_ITEM parameters[])
256*2139Sjp161948 	{
257*2139Sjp161948 	STORE_OBJECT *object;
258*2139Sjp161948 	X509 *x;
259*2139Sjp161948 
260*2139Sjp161948 	check_store(s,STORE_F_STORE_GET_CERTIFICATE,
261*2139Sjp161948 		get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
262*2139Sjp161948 
263*2139Sjp161948 	object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
264*2139Sjp161948 		attributes, parameters);
265*2139Sjp161948 	if (!object || !object->data.x509.certificate)
266*2139Sjp161948 		{
267*2139Sjp161948 		STOREerr(STORE_F_STORE_GET_CERTIFICATE,
268*2139Sjp161948 			STORE_R_FAILED_GETTING_CERTIFICATE);
269*2139Sjp161948 		return 0;
270*2139Sjp161948 		}
271*2139Sjp161948 	CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
272*2139Sjp161948 #ifdef REF_PRINT
273*2139Sjp161948 	REF_PRINT("X509",data);
274*2139Sjp161948 #endif
275*2139Sjp161948 	x = object->data.x509.certificate;
276*2139Sjp161948 	STORE_OBJECT_free(object);
277*2139Sjp161948 	return x;
278*2139Sjp161948 	}
279*2139Sjp161948 
STORE_store_certificate(STORE * s,X509 * data,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])280*2139Sjp161948 int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
281*2139Sjp161948 	OPENSSL_ITEM parameters[])
282*2139Sjp161948 	{
283*2139Sjp161948 	STORE_OBJECT *object;
284*2139Sjp161948 	int i;
285*2139Sjp161948 
286*2139Sjp161948 	check_store(s,STORE_F_STORE_CERTIFICATE,
287*2139Sjp161948 		store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
288*2139Sjp161948 
289*2139Sjp161948 	object = STORE_OBJECT_new();
290*2139Sjp161948 	if (!object)
291*2139Sjp161948 		{
292*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
293*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
294*2139Sjp161948 		return 0;
295*2139Sjp161948 		}
296*2139Sjp161948 
297*2139Sjp161948 	CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509);
298*2139Sjp161948 #ifdef REF_PRINT
299*2139Sjp161948 	REF_PRINT("X509",data);
300*2139Sjp161948 #endif
301*2139Sjp161948 	object->data.x509.certificate = data;
302*2139Sjp161948 
303*2139Sjp161948 	i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
304*2139Sjp161948 		object, attributes, parameters);
305*2139Sjp161948 
306*2139Sjp161948 	STORE_OBJECT_free(object);
307*2139Sjp161948 
308*2139Sjp161948 	if (!i)
309*2139Sjp161948 		{
310*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
311*2139Sjp161948 			STORE_R_FAILED_STORING_CERTIFICATE);
312*2139Sjp161948 		return 0;
313*2139Sjp161948 		}
314*2139Sjp161948 	return 1;
315*2139Sjp161948 	}
316*2139Sjp161948 
STORE_modify_certificate(STORE * s,OPENSSL_ITEM search_attributes[],OPENSSL_ITEM add_attributes[],OPENSSL_ITEM modify_attributes[],OPENSSL_ITEM delete_attributes[],OPENSSL_ITEM parameters[])317*2139Sjp161948 int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
318*2139Sjp161948 	OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
319*2139Sjp161948 	OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
320*2139Sjp161948 	{
321*2139Sjp161948 	check_store(s,STORE_F_STORE_MODIFY_CERTIFICATE,
322*2139Sjp161948 		modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
323*2139Sjp161948 
324*2139Sjp161948 	if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
325*2139Sjp161948 		    search_attributes, add_attributes, modify_attributes,
326*2139Sjp161948 		    delete_attributes, parameters))
327*2139Sjp161948 		{
328*2139Sjp161948 		STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
329*2139Sjp161948 			STORE_R_FAILED_MODIFYING_CERTIFICATE);
330*2139Sjp161948 		return 0;
331*2139Sjp161948 		}
332*2139Sjp161948 	return 1;
333*2139Sjp161948 	}
334*2139Sjp161948 
STORE_revoke_certificate(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])335*2139Sjp161948 int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
336*2139Sjp161948 	OPENSSL_ITEM parameters[])
337*2139Sjp161948 	{
338*2139Sjp161948 	check_store(s,STORE_F_STORE_REVOKE_CERTIFICATE,
339*2139Sjp161948 		revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
340*2139Sjp161948 
341*2139Sjp161948 	if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
342*2139Sjp161948 		    attributes, parameters))
343*2139Sjp161948 		{
344*2139Sjp161948 		STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE,
345*2139Sjp161948 			STORE_R_FAILED_REVOKING_CERTIFICATE);
346*2139Sjp161948 		return 0;
347*2139Sjp161948 		}
348*2139Sjp161948 	return 1;
349*2139Sjp161948 	}
350*2139Sjp161948 
STORE_delete_certificate(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])351*2139Sjp161948 int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[],
352*2139Sjp161948 	OPENSSL_ITEM parameters[])
353*2139Sjp161948 	{
354*2139Sjp161948 	check_store(s,STORE_F_STORE_DELETE_CERTIFICATE,
355*2139Sjp161948 		delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
356*2139Sjp161948 
357*2139Sjp161948 	if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
358*2139Sjp161948 		    attributes, parameters))
359*2139Sjp161948 		{
360*2139Sjp161948 		STOREerr(STORE_F_STORE_DELETE_CERTIFICATE,
361*2139Sjp161948 			STORE_R_FAILED_DELETING_CERTIFICATE);
362*2139Sjp161948 		return 0;
363*2139Sjp161948 		}
364*2139Sjp161948 	return 1;
365*2139Sjp161948 	}
366*2139Sjp161948 
STORE_list_certificate_start(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])367*2139Sjp161948 void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[],
368*2139Sjp161948 	OPENSSL_ITEM parameters[])
369*2139Sjp161948 	{
370*2139Sjp161948 	void *handle;
371*2139Sjp161948 
372*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CERTIFICATE_START,
373*2139Sjp161948 		list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
374*2139Sjp161948 
375*2139Sjp161948 	handle = s->meth->list_object_start(s,
376*2139Sjp161948 		STORE_OBJECT_TYPE_X509_CERTIFICATE, attributes, parameters);
377*2139Sjp161948 	if (!handle)
378*2139Sjp161948 		{
379*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START,
380*2139Sjp161948 			STORE_R_FAILED_LISTING_CERTIFICATES);
381*2139Sjp161948 		return 0;
382*2139Sjp161948 		}
383*2139Sjp161948 	return handle;
384*2139Sjp161948 	}
385*2139Sjp161948 
STORE_list_certificate_next(STORE * s,void * handle)386*2139Sjp161948 X509 *STORE_list_certificate_next(STORE *s, void *handle)
387*2139Sjp161948 	{
388*2139Sjp161948 	STORE_OBJECT *object;
389*2139Sjp161948 	X509 *x;
390*2139Sjp161948 
391*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CERTIFICATE_NEXT,
392*2139Sjp161948 		list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
393*2139Sjp161948 
394*2139Sjp161948 	object = s->meth->list_object_next(s, handle);
395*2139Sjp161948 	if (!object || !object->data.x509.certificate)
396*2139Sjp161948 		{
397*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT,
398*2139Sjp161948 			STORE_R_FAILED_LISTING_CERTIFICATES);
399*2139Sjp161948 		return 0;
400*2139Sjp161948 		}
401*2139Sjp161948 	CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
402*2139Sjp161948 #ifdef REF_PRINT
403*2139Sjp161948 	REF_PRINT("X509",data);
404*2139Sjp161948 #endif
405*2139Sjp161948 	x = object->data.x509.certificate;
406*2139Sjp161948 	STORE_OBJECT_free(object);
407*2139Sjp161948 	return x;
408*2139Sjp161948 	}
409*2139Sjp161948 
STORE_list_certificate_end(STORE * s,void * handle)410*2139Sjp161948 int STORE_list_certificate_end(STORE *s, void *handle)
411*2139Sjp161948 	{
412*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CERTIFICATE_END,
413*2139Sjp161948 		list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
414*2139Sjp161948 
415*2139Sjp161948 	if (!s->meth->list_object_end(s, handle))
416*2139Sjp161948 		{
417*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END,
418*2139Sjp161948 			STORE_R_FAILED_LISTING_CERTIFICATES);
419*2139Sjp161948 		return 0;
420*2139Sjp161948 		}
421*2139Sjp161948 	return 1;
422*2139Sjp161948 	}
423*2139Sjp161948 
STORE_list_certificate_endp(STORE * s,void * handle)424*2139Sjp161948 int STORE_list_certificate_endp(STORE *s, void *handle)
425*2139Sjp161948 	{
426*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CERTIFICATE_ENDP,
427*2139Sjp161948 		list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
428*2139Sjp161948 
429*2139Sjp161948 	if (!s->meth->list_object_endp(s, handle))
430*2139Sjp161948 		{
431*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP,
432*2139Sjp161948 			STORE_R_FAILED_LISTING_CERTIFICATES);
433*2139Sjp161948 		return 0;
434*2139Sjp161948 		}
435*2139Sjp161948 	return 1;
436*2139Sjp161948 	}
437*2139Sjp161948 
STORE_generate_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])438*2139Sjp161948 EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[],
439*2139Sjp161948 	OPENSSL_ITEM parameters[])
440*2139Sjp161948 	{
441*2139Sjp161948 	STORE_OBJECT *object;
442*2139Sjp161948 	EVP_PKEY *pkey;
443*2139Sjp161948 
444*2139Sjp161948 	check_store(s,STORE_F_STORE_GENERATE_KEY,
445*2139Sjp161948 		generate_object,STORE_R_NO_GENERATE_OBJECT_FUNCTION);
446*2139Sjp161948 
447*2139Sjp161948 	object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
448*2139Sjp161948 		attributes, parameters);
449*2139Sjp161948 	if (!object || !object->data.key)
450*2139Sjp161948 		{
451*2139Sjp161948 		STOREerr(STORE_F_STORE_GENERATE_KEY,
452*2139Sjp161948 			STORE_R_FAILED_GENERATING_KEY);
453*2139Sjp161948 		return 0;
454*2139Sjp161948 		}
455*2139Sjp161948 	CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
456*2139Sjp161948 #ifdef REF_PRINT
457*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
458*2139Sjp161948 #endif
459*2139Sjp161948 	pkey = object->data.key;
460*2139Sjp161948 	STORE_OBJECT_free(object);
461*2139Sjp161948 	return pkey;
462*2139Sjp161948 	}
463*2139Sjp161948 
STORE_get_private_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])464*2139Sjp161948 EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
465*2139Sjp161948 	OPENSSL_ITEM parameters[])
466*2139Sjp161948 	{
467*2139Sjp161948 	STORE_OBJECT *object;
468*2139Sjp161948 	EVP_PKEY *pkey;
469*2139Sjp161948 
470*2139Sjp161948 	check_store(s,STORE_F_STORE_GET_PRIVATE_KEY,
471*2139Sjp161948 		get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
472*2139Sjp161948 
473*2139Sjp161948 	object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
474*2139Sjp161948 		attributes, parameters);
475*2139Sjp161948 	if (!object || !object->data.key || !object->data.key)
476*2139Sjp161948 		{
477*2139Sjp161948 		STOREerr(STORE_F_STORE_GET_PRIVATE_KEY,
478*2139Sjp161948 			STORE_R_FAILED_GETTING_KEY);
479*2139Sjp161948 		return 0;
480*2139Sjp161948 		}
481*2139Sjp161948 	CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
482*2139Sjp161948 #ifdef REF_PRINT
483*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
484*2139Sjp161948 #endif
485*2139Sjp161948 	pkey = object->data.key;
486*2139Sjp161948 	STORE_OBJECT_free(object);
487*2139Sjp161948 	return pkey;
488*2139Sjp161948 	}
489*2139Sjp161948 
STORE_store_private_key(STORE * s,EVP_PKEY * data,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])490*2139Sjp161948 int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
491*2139Sjp161948 	OPENSSL_ITEM parameters[])
492*2139Sjp161948 	{
493*2139Sjp161948 	STORE_OBJECT *object;
494*2139Sjp161948 	int i;
495*2139Sjp161948 
496*2139Sjp161948 	check_store(s,STORE_F_STORE_STORE_PRIVATE_KEY,
497*2139Sjp161948 		store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
498*2139Sjp161948 
499*2139Sjp161948 	object = STORE_OBJECT_new();
500*2139Sjp161948 	if (!object)
501*2139Sjp161948 		{
502*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
503*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
504*2139Sjp161948 		return 0;
505*2139Sjp161948 		}
506*2139Sjp161948 	object->data.key = EVP_PKEY_new();
507*2139Sjp161948 	if (!object->data.key)
508*2139Sjp161948 		{
509*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
510*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
511*2139Sjp161948 		return 0;
512*2139Sjp161948 		}
513*2139Sjp161948 
514*2139Sjp161948 	CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
515*2139Sjp161948 #ifdef REF_PRINT
516*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
517*2139Sjp161948 #endif
518*2139Sjp161948 	object->data.key = data;
519*2139Sjp161948 
520*2139Sjp161948 	i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object,
521*2139Sjp161948 		attributes, parameters);
522*2139Sjp161948 
523*2139Sjp161948 	STORE_OBJECT_free(object);
524*2139Sjp161948 
525*2139Sjp161948 	if (!i)
526*2139Sjp161948 		{
527*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
528*2139Sjp161948 			STORE_R_FAILED_STORING_KEY);
529*2139Sjp161948 		return 0;
530*2139Sjp161948 		}
531*2139Sjp161948 	return i;
532*2139Sjp161948 	}
533*2139Sjp161948 
STORE_modify_private_key(STORE * s,OPENSSL_ITEM search_attributes[],OPENSSL_ITEM add_attributes[],OPENSSL_ITEM modify_attributes[],OPENSSL_ITEM delete_attributes[],OPENSSL_ITEM parameters[])534*2139Sjp161948 int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
535*2139Sjp161948 	OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
536*2139Sjp161948 	OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
537*2139Sjp161948 	{
538*2139Sjp161948 	check_store(s,STORE_F_STORE_MODIFY_PRIVATE_KEY,
539*2139Sjp161948 		modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
540*2139Sjp161948 
541*2139Sjp161948 	if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
542*2139Sjp161948 		    search_attributes, add_attributes, modify_attributes,
543*2139Sjp161948 		    delete_attributes, parameters))
544*2139Sjp161948 		{
545*2139Sjp161948 		STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
546*2139Sjp161948 			STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
547*2139Sjp161948 		return 0;
548*2139Sjp161948 		}
549*2139Sjp161948 	return 1;
550*2139Sjp161948 	}
551*2139Sjp161948 
STORE_revoke_private_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])552*2139Sjp161948 int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
553*2139Sjp161948 	OPENSSL_ITEM parameters[])
554*2139Sjp161948 	{
555*2139Sjp161948 	int i;
556*2139Sjp161948 
557*2139Sjp161948 	check_store(s,STORE_F_STORE_REVOKE_PRIVATE_KEY,
558*2139Sjp161948 		revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
559*2139Sjp161948 
560*2139Sjp161948 	i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
561*2139Sjp161948 		attributes, parameters);
562*2139Sjp161948 
563*2139Sjp161948 	if (!i)
564*2139Sjp161948 		{
565*2139Sjp161948 		STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY,
566*2139Sjp161948 			STORE_R_FAILED_REVOKING_KEY);
567*2139Sjp161948 		return 0;
568*2139Sjp161948 		}
569*2139Sjp161948 	return i;
570*2139Sjp161948 	}
571*2139Sjp161948 
STORE_delete_private_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])572*2139Sjp161948 int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[],
573*2139Sjp161948 	OPENSSL_ITEM parameters[])
574*2139Sjp161948 	{
575*2139Sjp161948 	check_store(s,STORE_F_STORE_DELETE_PRIVATE_KEY,
576*2139Sjp161948 		delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
577*2139Sjp161948 
578*2139Sjp161948 	if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
579*2139Sjp161948 		    attributes, parameters))
580*2139Sjp161948 		{
581*2139Sjp161948 		STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY,
582*2139Sjp161948 			STORE_R_FAILED_DELETING_KEY);
583*2139Sjp161948 		return 0;
584*2139Sjp161948 		}
585*2139Sjp161948 	return 1;
586*2139Sjp161948 	}
587*2139Sjp161948 
STORE_list_private_key_start(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])588*2139Sjp161948 void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[],
589*2139Sjp161948 	OPENSSL_ITEM parameters[])
590*2139Sjp161948 	{
591*2139Sjp161948 	void *handle;
592*2139Sjp161948 
593*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_START,
594*2139Sjp161948 		list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
595*2139Sjp161948 
596*2139Sjp161948 	handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
597*2139Sjp161948 		attributes, parameters);
598*2139Sjp161948 	if (!handle)
599*2139Sjp161948 		{
600*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START,
601*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
602*2139Sjp161948 		return 0;
603*2139Sjp161948 		}
604*2139Sjp161948 	return handle;
605*2139Sjp161948 	}
606*2139Sjp161948 
STORE_list_private_key_next(STORE * s,void * handle)607*2139Sjp161948 EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle)
608*2139Sjp161948 	{
609*2139Sjp161948 	STORE_OBJECT *object;
610*2139Sjp161948 	EVP_PKEY *pkey;
611*2139Sjp161948 
612*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
613*2139Sjp161948 		list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
614*2139Sjp161948 
615*2139Sjp161948 	object = s->meth->list_object_next(s, handle);
616*2139Sjp161948 	if (!object || !object->data.key || !object->data.key)
617*2139Sjp161948 		{
618*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
619*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
620*2139Sjp161948 		return 0;
621*2139Sjp161948 		}
622*2139Sjp161948 	CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
623*2139Sjp161948 #ifdef REF_PRINT
624*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
625*2139Sjp161948 #endif
626*2139Sjp161948 	pkey = object->data.key;
627*2139Sjp161948 	STORE_OBJECT_free(object);
628*2139Sjp161948 	return pkey;
629*2139Sjp161948 	}
630*2139Sjp161948 
STORE_list_private_key_end(STORE * s,void * handle)631*2139Sjp161948 int STORE_list_private_key_end(STORE *s, void *handle)
632*2139Sjp161948 	{
633*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_END,
634*2139Sjp161948 		list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
635*2139Sjp161948 
636*2139Sjp161948 	if (!s->meth->list_object_end(s, handle))
637*2139Sjp161948 		{
638*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END,
639*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
640*2139Sjp161948 		return 0;
641*2139Sjp161948 		}
642*2139Sjp161948 	return 1;
643*2139Sjp161948 	}
644*2139Sjp161948 
STORE_list_private_key_endp(STORE * s,void * handle)645*2139Sjp161948 int STORE_list_private_key_endp(STORE *s, void *handle)
646*2139Sjp161948 	{
647*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
648*2139Sjp161948 		list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
649*2139Sjp161948 
650*2139Sjp161948 	if (!s->meth->list_object_endp(s, handle))
651*2139Sjp161948 		{
652*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
653*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
654*2139Sjp161948 		return 0;
655*2139Sjp161948 		}
656*2139Sjp161948 	return 1;
657*2139Sjp161948 	}
658*2139Sjp161948 
STORE_get_public_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])659*2139Sjp161948 EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
660*2139Sjp161948 	OPENSSL_ITEM parameters[])
661*2139Sjp161948 	{
662*2139Sjp161948 	STORE_OBJECT *object;
663*2139Sjp161948 	EVP_PKEY *pkey;
664*2139Sjp161948 
665*2139Sjp161948 	check_store(s,STORE_F_STORE_GET_PUBLIC_KEY,
666*2139Sjp161948 		get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
667*2139Sjp161948 
668*2139Sjp161948 	object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
669*2139Sjp161948 		attributes, parameters);
670*2139Sjp161948 	if (!object || !object->data.key || !object->data.key)
671*2139Sjp161948 		{
672*2139Sjp161948 		STOREerr(STORE_F_STORE_GET_PUBLIC_KEY,
673*2139Sjp161948 			STORE_R_FAILED_GETTING_KEY);
674*2139Sjp161948 		return 0;
675*2139Sjp161948 		}
676*2139Sjp161948 	CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
677*2139Sjp161948 #ifdef REF_PRINT
678*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
679*2139Sjp161948 #endif
680*2139Sjp161948 	pkey = object->data.key;
681*2139Sjp161948 	STORE_OBJECT_free(object);
682*2139Sjp161948 	return pkey;
683*2139Sjp161948 	}
684*2139Sjp161948 
STORE_store_public_key(STORE * s,EVP_PKEY * data,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])685*2139Sjp161948 int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
686*2139Sjp161948 	OPENSSL_ITEM parameters[])
687*2139Sjp161948 	{
688*2139Sjp161948 	STORE_OBJECT *object;
689*2139Sjp161948 	int i;
690*2139Sjp161948 
691*2139Sjp161948 	check_store(s,STORE_F_STORE_STORE_PUBLIC_KEY,
692*2139Sjp161948 		store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
693*2139Sjp161948 
694*2139Sjp161948 	object = STORE_OBJECT_new();
695*2139Sjp161948 	if (!object)
696*2139Sjp161948 		{
697*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
698*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
699*2139Sjp161948 		return 0;
700*2139Sjp161948 		}
701*2139Sjp161948 	object->data.key = EVP_PKEY_new();
702*2139Sjp161948 	if (!object->data.key)
703*2139Sjp161948 		{
704*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
705*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
706*2139Sjp161948 		return 0;
707*2139Sjp161948 		}
708*2139Sjp161948 
709*2139Sjp161948 	CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
710*2139Sjp161948 #ifdef REF_PRINT
711*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
712*2139Sjp161948 #endif
713*2139Sjp161948 	object->data.key = data;
714*2139Sjp161948 
715*2139Sjp161948 	i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object,
716*2139Sjp161948 		attributes, parameters);
717*2139Sjp161948 
718*2139Sjp161948 	STORE_OBJECT_free(object);
719*2139Sjp161948 
720*2139Sjp161948 	if (!i)
721*2139Sjp161948 		{
722*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
723*2139Sjp161948 			STORE_R_FAILED_STORING_KEY);
724*2139Sjp161948 		return 0;
725*2139Sjp161948 		}
726*2139Sjp161948 	return i;
727*2139Sjp161948 	}
728*2139Sjp161948 
STORE_modify_public_key(STORE * s,OPENSSL_ITEM search_attributes[],OPENSSL_ITEM add_attributes[],OPENSSL_ITEM modify_attributes[],OPENSSL_ITEM delete_attributes[],OPENSSL_ITEM parameters[])729*2139Sjp161948 int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
730*2139Sjp161948 	OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
731*2139Sjp161948 	OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
732*2139Sjp161948 	{
733*2139Sjp161948 	check_store(s,STORE_F_STORE_MODIFY_PUBLIC_KEY,
734*2139Sjp161948 		modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
735*2139Sjp161948 
736*2139Sjp161948 	if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
737*2139Sjp161948 		    search_attributes, add_attributes, modify_attributes,
738*2139Sjp161948 		    delete_attributes, parameters))
739*2139Sjp161948 		{
740*2139Sjp161948 		STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
741*2139Sjp161948 			STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
742*2139Sjp161948 		return 0;
743*2139Sjp161948 		}
744*2139Sjp161948 	return 1;
745*2139Sjp161948 	}
746*2139Sjp161948 
STORE_revoke_public_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])747*2139Sjp161948 int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
748*2139Sjp161948 	OPENSSL_ITEM parameters[])
749*2139Sjp161948 	{
750*2139Sjp161948 	int i;
751*2139Sjp161948 
752*2139Sjp161948 	check_store(s,STORE_F_STORE_REVOKE_PUBLIC_KEY,
753*2139Sjp161948 		revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
754*2139Sjp161948 
755*2139Sjp161948 	i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
756*2139Sjp161948 		attributes, parameters);
757*2139Sjp161948 
758*2139Sjp161948 	if (!i)
759*2139Sjp161948 		{
760*2139Sjp161948 		STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY,
761*2139Sjp161948 			STORE_R_FAILED_REVOKING_KEY);
762*2139Sjp161948 		return 0;
763*2139Sjp161948 		}
764*2139Sjp161948 	return i;
765*2139Sjp161948 	}
766*2139Sjp161948 
STORE_delete_public_key(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])767*2139Sjp161948 int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[],
768*2139Sjp161948 	OPENSSL_ITEM parameters[])
769*2139Sjp161948 	{
770*2139Sjp161948 	check_store(s,STORE_F_STORE_DELETE_PUBLIC_KEY,
771*2139Sjp161948 		delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
772*2139Sjp161948 
773*2139Sjp161948 	if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
774*2139Sjp161948 		    attributes, parameters))
775*2139Sjp161948 		{
776*2139Sjp161948 		STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY,
777*2139Sjp161948 			STORE_R_FAILED_DELETING_KEY);
778*2139Sjp161948 		return 0;
779*2139Sjp161948 		}
780*2139Sjp161948 	return 1;
781*2139Sjp161948 	}
782*2139Sjp161948 
STORE_list_public_key_start(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])783*2139Sjp161948 void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[],
784*2139Sjp161948 	OPENSSL_ITEM parameters[])
785*2139Sjp161948 	{
786*2139Sjp161948 	void *handle;
787*2139Sjp161948 
788*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_START,
789*2139Sjp161948 		list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
790*2139Sjp161948 
791*2139Sjp161948 	handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
792*2139Sjp161948 		attributes, parameters);
793*2139Sjp161948 	if (!handle)
794*2139Sjp161948 		{
795*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START,
796*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
797*2139Sjp161948 		return 0;
798*2139Sjp161948 		}
799*2139Sjp161948 	return handle;
800*2139Sjp161948 	}
801*2139Sjp161948 
STORE_list_public_key_next(STORE * s,void * handle)802*2139Sjp161948 EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle)
803*2139Sjp161948 	{
804*2139Sjp161948 	STORE_OBJECT *object;
805*2139Sjp161948 	EVP_PKEY *pkey;
806*2139Sjp161948 
807*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
808*2139Sjp161948 		list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
809*2139Sjp161948 
810*2139Sjp161948 	object = s->meth->list_object_next(s, handle);
811*2139Sjp161948 	if (!object || !object->data.key || !object->data.key)
812*2139Sjp161948 		{
813*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
814*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
815*2139Sjp161948 		return 0;
816*2139Sjp161948 		}
817*2139Sjp161948 	CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
818*2139Sjp161948 #ifdef REF_PRINT
819*2139Sjp161948 	REF_PRINT("EVP_PKEY",data);
820*2139Sjp161948 #endif
821*2139Sjp161948 	pkey = object->data.key;
822*2139Sjp161948 	STORE_OBJECT_free(object);
823*2139Sjp161948 	return pkey;
824*2139Sjp161948 	}
825*2139Sjp161948 
STORE_list_public_key_end(STORE * s,void * handle)826*2139Sjp161948 int STORE_list_public_key_end(STORE *s, void *handle)
827*2139Sjp161948 	{
828*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_END,
829*2139Sjp161948 		list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
830*2139Sjp161948 
831*2139Sjp161948 	if (!s->meth->list_object_end(s, handle))
832*2139Sjp161948 		{
833*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END,
834*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
835*2139Sjp161948 		return 0;
836*2139Sjp161948 		}
837*2139Sjp161948 	return 1;
838*2139Sjp161948 	}
839*2139Sjp161948 
STORE_list_public_key_endp(STORE * s,void * handle)840*2139Sjp161948 int STORE_list_public_key_endp(STORE *s, void *handle)
841*2139Sjp161948 	{
842*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
843*2139Sjp161948 		list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
844*2139Sjp161948 
845*2139Sjp161948 	if (!s->meth->list_object_endp(s, handle))
846*2139Sjp161948 		{
847*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
848*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
849*2139Sjp161948 		return 0;
850*2139Sjp161948 		}
851*2139Sjp161948 	return 1;
852*2139Sjp161948 	}
853*2139Sjp161948 
STORE_generate_crl(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])854*2139Sjp161948 X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
855*2139Sjp161948 	OPENSSL_ITEM parameters[])
856*2139Sjp161948 	{
857*2139Sjp161948 	STORE_OBJECT *object;
858*2139Sjp161948 	X509_CRL *crl;
859*2139Sjp161948 
860*2139Sjp161948 	check_store(s,STORE_F_STORE_GENERATE_CRL,
861*2139Sjp161948 		generate_object,STORE_R_NO_GENERATE_CRL_FUNCTION);
862*2139Sjp161948 
863*2139Sjp161948 	object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL,
864*2139Sjp161948 		attributes, parameters);
865*2139Sjp161948 	if (!object || !object->data.crl)
866*2139Sjp161948 		{
867*2139Sjp161948 		STOREerr(STORE_F_STORE_GENERATE_CRL,
868*2139Sjp161948 			STORE_R_FAILED_GENERATING_CRL);
869*2139Sjp161948 		return 0;
870*2139Sjp161948 		}
871*2139Sjp161948 	CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
872*2139Sjp161948 #ifdef REF_PRINT
873*2139Sjp161948 	REF_PRINT("X509_CRL",data);
874*2139Sjp161948 #endif
875*2139Sjp161948 	crl = object->data.crl;
876*2139Sjp161948 	STORE_OBJECT_free(object);
877*2139Sjp161948 	return crl;
878*2139Sjp161948 	}
879*2139Sjp161948 
STORE_get_crl(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])880*2139Sjp161948 X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
881*2139Sjp161948 	OPENSSL_ITEM parameters[])
882*2139Sjp161948 	{
883*2139Sjp161948 	STORE_OBJECT *object;
884*2139Sjp161948 	X509_CRL *crl;
885*2139Sjp161948 
886*2139Sjp161948 	check_store(s,STORE_F_STORE_GET_CRL,
887*2139Sjp161948 		get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
888*2139Sjp161948 
889*2139Sjp161948 	object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL,
890*2139Sjp161948 		attributes, parameters);
891*2139Sjp161948 	if (!object || !object->data.crl)
892*2139Sjp161948 		{
893*2139Sjp161948 		STOREerr(STORE_F_STORE_GET_CRL,
894*2139Sjp161948 			STORE_R_FAILED_GETTING_KEY);
895*2139Sjp161948 		return 0;
896*2139Sjp161948 		}
897*2139Sjp161948 	CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
898*2139Sjp161948 #ifdef REF_PRINT
899*2139Sjp161948 	REF_PRINT("X509_CRL",data);
900*2139Sjp161948 #endif
901*2139Sjp161948 	crl = object->data.crl;
902*2139Sjp161948 	STORE_OBJECT_free(object);
903*2139Sjp161948 	return crl;
904*2139Sjp161948 	}
905*2139Sjp161948 
STORE_store_crl(STORE * s,X509_CRL * data,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])906*2139Sjp161948 int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
907*2139Sjp161948 	OPENSSL_ITEM parameters[])
908*2139Sjp161948 	{
909*2139Sjp161948 	STORE_OBJECT *object;
910*2139Sjp161948 	int i;
911*2139Sjp161948 
912*2139Sjp161948 	check_store(s,STORE_F_STORE_STORE_CRL,
913*2139Sjp161948 		store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
914*2139Sjp161948 
915*2139Sjp161948 	object = STORE_OBJECT_new();
916*2139Sjp161948 	if (!object)
917*2139Sjp161948 		{
918*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_CRL,
919*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
920*2139Sjp161948 		return 0;
921*2139Sjp161948 		}
922*2139Sjp161948 
923*2139Sjp161948 	CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509_CRL);
924*2139Sjp161948 #ifdef REF_PRINT
925*2139Sjp161948 	REF_PRINT("X509_CRL",data);
926*2139Sjp161948 #endif
927*2139Sjp161948 	object->data.crl = data;
928*2139Sjp161948 
929*2139Sjp161948 	i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object,
930*2139Sjp161948 		attributes, parameters);
931*2139Sjp161948 
932*2139Sjp161948 	STORE_OBJECT_free(object);
933*2139Sjp161948 
934*2139Sjp161948 	if (!i)
935*2139Sjp161948 		{
936*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_CRL,
937*2139Sjp161948 			STORE_R_FAILED_STORING_KEY);
938*2139Sjp161948 		return 0;
939*2139Sjp161948 		}
940*2139Sjp161948 	return i;
941*2139Sjp161948 	}
942*2139Sjp161948 
STORE_modify_crl(STORE * s,OPENSSL_ITEM search_attributes[],OPENSSL_ITEM add_attributes[],OPENSSL_ITEM modify_attributes[],OPENSSL_ITEM delete_attributes[],OPENSSL_ITEM parameters[])943*2139Sjp161948 int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
944*2139Sjp161948 	OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
945*2139Sjp161948 	OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
946*2139Sjp161948 	{
947*2139Sjp161948 	check_store(s,STORE_F_STORE_MODIFY_CRL,
948*2139Sjp161948 		modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
949*2139Sjp161948 
950*2139Sjp161948 	if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
951*2139Sjp161948 		    search_attributes, add_attributes, modify_attributes,
952*2139Sjp161948 		    delete_attributes, parameters))
953*2139Sjp161948 		{
954*2139Sjp161948 		STOREerr(STORE_F_STORE_MODIFY_CRL,
955*2139Sjp161948 			STORE_R_FAILED_MODIFYING_CRL);
956*2139Sjp161948 		return 0;
957*2139Sjp161948 		}
958*2139Sjp161948 	return 1;
959*2139Sjp161948 	}
960*2139Sjp161948 
STORE_delete_crl(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])961*2139Sjp161948 int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
962*2139Sjp161948 	OPENSSL_ITEM parameters[])
963*2139Sjp161948 	{
964*2139Sjp161948 	check_store(s,STORE_F_STORE_DELETE_CRL,
965*2139Sjp161948 		delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
966*2139Sjp161948 
967*2139Sjp161948 	if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL,
968*2139Sjp161948 		    attributes, parameters))
969*2139Sjp161948 		{
970*2139Sjp161948 		STOREerr(STORE_F_STORE_DELETE_CRL,
971*2139Sjp161948 			STORE_R_FAILED_DELETING_KEY);
972*2139Sjp161948 		return 0;
973*2139Sjp161948 		}
974*2139Sjp161948 	return 1;
975*2139Sjp161948 	}
976*2139Sjp161948 
STORE_list_crl_start(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])977*2139Sjp161948 void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[],
978*2139Sjp161948 	OPENSSL_ITEM parameters[])
979*2139Sjp161948 	{
980*2139Sjp161948 	void *handle;
981*2139Sjp161948 
982*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CRL_START,
983*2139Sjp161948 		list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
984*2139Sjp161948 
985*2139Sjp161948 	handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL,
986*2139Sjp161948 		attributes, parameters);
987*2139Sjp161948 	if (!handle)
988*2139Sjp161948 		{
989*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CRL_START,
990*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
991*2139Sjp161948 		return 0;
992*2139Sjp161948 		}
993*2139Sjp161948 	return handle;
994*2139Sjp161948 	}
995*2139Sjp161948 
STORE_list_crl_next(STORE * s,void * handle)996*2139Sjp161948 X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
997*2139Sjp161948 	{
998*2139Sjp161948 	STORE_OBJECT *object;
999*2139Sjp161948 	X509_CRL *crl;
1000*2139Sjp161948 
1001*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CRL_NEXT,
1002*2139Sjp161948 		list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
1003*2139Sjp161948 
1004*2139Sjp161948 	object = s->meth->list_object_next(s, handle);
1005*2139Sjp161948 	if (!object || !object->data.crl)
1006*2139Sjp161948 		{
1007*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CRL_NEXT,
1008*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
1009*2139Sjp161948 		return 0;
1010*2139Sjp161948 		}
1011*2139Sjp161948 	CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
1012*2139Sjp161948 #ifdef REF_PRINT
1013*2139Sjp161948 	REF_PRINT("X509_CRL",data);
1014*2139Sjp161948 #endif
1015*2139Sjp161948 	crl = object->data.crl;
1016*2139Sjp161948 	STORE_OBJECT_free(object);
1017*2139Sjp161948 	return crl;
1018*2139Sjp161948 	}
1019*2139Sjp161948 
STORE_list_crl_end(STORE * s,void * handle)1020*2139Sjp161948 int STORE_list_crl_end(STORE *s, void *handle)
1021*2139Sjp161948 	{
1022*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CRL_END,
1023*2139Sjp161948 		list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
1024*2139Sjp161948 
1025*2139Sjp161948 	if (!s->meth->list_object_end(s, handle))
1026*2139Sjp161948 		{
1027*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CRL_END,
1028*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
1029*2139Sjp161948 		return 0;
1030*2139Sjp161948 		}
1031*2139Sjp161948 	return 1;
1032*2139Sjp161948 	}
1033*2139Sjp161948 
STORE_list_crl_endp(STORE * s,void * handle)1034*2139Sjp161948 int STORE_list_crl_endp(STORE *s, void *handle)
1035*2139Sjp161948 	{
1036*2139Sjp161948 	check_store(s,STORE_F_STORE_LIST_CRL_ENDP,
1037*2139Sjp161948 		list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
1038*2139Sjp161948 
1039*2139Sjp161948 	if (!s->meth->list_object_endp(s, handle))
1040*2139Sjp161948 		{
1041*2139Sjp161948 		STOREerr(STORE_F_STORE_LIST_CRL_ENDP,
1042*2139Sjp161948 			STORE_R_FAILED_LISTING_KEYS);
1043*2139Sjp161948 		return 0;
1044*2139Sjp161948 		}
1045*2139Sjp161948 	return 1;
1046*2139Sjp161948 	}
1047*2139Sjp161948 
STORE_store_number(STORE * s,BIGNUM * data,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])1048*2139Sjp161948 int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
1049*2139Sjp161948 	OPENSSL_ITEM parameters[])
1050*2139Sjp161948 	{
1051*2139Sjp161948 	STORE_OBJECT *object;
1052*2139Sjp161948 	int i;
1053*2139Sjp161948 
1054*2139Sjp161948 	check_store(s,STORE_F_STORE_STORE_NUMBER,
1055*2139Sjp161948 		store_object,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
1056*2139Sjp161948 
1057*2139Sjp161948 	object = STORE_OBJECT_new();
1058*2139Sjp161948 	if (!object)
1059*2139Sjp161948 		{
1060*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_NUMBER,
1061*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
1062*2139Sjp161948 		return 0;
1063*2139Sjp161948 		}
1064*2139Sjp161948 
1065*2139Sjp161948 	object->data.number = data;
1066*2139Sjp161948 
1067*2139Sjp161948 	i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object,
1068*2139Sjp161948 		attributes, parameters);
1069*2139Sjp161948 
1070*2139Sjp161948 	STORE_OBJECT_free(object);
1071*2139Sjp161948 
1072*2139Sjp161948 	if (!i)
1073*2139Sjp161948 		{
1074*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_NUMBER,
1075*2139Sjp161948 			STORE_R_FAILED_STORING_NUMBER);
1076*2139Sjp161948 		return 0;
1077*2139Sjp161948 		}
1078*2139Sjp161948 	return 1;
1079*2139Sjp161948 	}
1080*2139Sjp161948 
STORE_modify_number(STORE * s,OPENSSL_ITEM search_attributes[],OPENSSL_ITEM add_attributes[],OPENSSL_ITEM modify_attributes[],OPENSSL_ITEM delete_attributes[],OPENSSL_ITEM parameters[])1081*2139Sjp161948 int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
1082*2139Sjp161948 	OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1083*2139Sjp161948 	OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1084*2139Sjp161948 	{
1085*2139Sjp161948 	check_store(s,STORE_F_STORE_MODIFY_NUMBER,
1086*2139Sjp161948 		modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1087*2139Sjp161948 
1088*2139Sjp161948 	if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
1089*2139Sjp161948 		    search_attributes, add_attributes, modify_attributes,
1090*2139Sjp161948 		    delete_attributes, parameters))
1091*2139Sjp161948 		{
1092*2139Sjp161948 		STOREerr(STORE_F_STORE_MODIFY_NUMBER,
1093*2139Sjp161948 			STORE_R_FAILED_MODIFYING_NUMBER);
1094*2139Sjp161948 		return 0;
1095*2139Sjp161948 		}
1096*2139Sjp161948 	return 1;
1097*2139Sjp161948 	}
1098*2139Sjp161948 
STORE_get_number(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])1099*2139Sjp161948 BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
1100*2139Sjp161948 	OPENSSL_ITEM parameters[])
1101*2139Sjp161948 	{
1102*2139Sjp161948 	STORE_OBJECT *object;
1103*2139Sjp161948 	BIGNUM *n;
1104*2139Sjp161948 
1105*2139Sjp161948 	check_store(s,STORE_F_STORE_GET_NUMBER,
1106*2139Sjp161948 		get_object,STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION);
1107*2139Sjp161948 
1108*2139Sjp161948 	object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1109*2139Sjp161948 		parameters);
1110*2139Sjp161948 	if (!object || !object->data.number)
1111*2139Sjp161948 		{
1112*2139Sjp161948 		STOREerr(STORE_F_STORE_GET_NUMBER,
1113*2139Sjp161948 			STORE_R_FAILED_GETTING_NUMBER);
1114*2139Sjp161948 		return 0;
1115*2139Sjp161948 		}
1116*2139Sjp161948 	n = object->data.number;
1117*2139Sjp161948 	object->data.number = NULL;
1118*2139Sjp161948 	STORE_OBJECT_free(object);
1119*2139Sjp161948 	return n;
1120*2139Sjp161948 	}
1121*2139Sjp161948 
STORE_delete_number(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])1122*2139Sjp161948 int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
1123*2139Sjp161948 	OPENSSL_ITEM parameters[])
1124*2139Sjp161948 	{
1125*2139Sjp161948 	check_store(s,STORE_F_STORE_DELETE_NUMBER,
1126*2139Sjp161948 		delete_object,STORE_R_NO_DELETE_NUMBER_FUNCTION);
1127*2139Sjp161948 
1128*2139Sjp161948 	if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1129*2139Sjp161948 		    parameters))
1130*2139Sjp161948 		{
1131*2139Sjp161948 		STOREerr(STORE_F_STORE_DELETE_NUMBER,
1132*2139Sjp161948 			STORE_R_FAILED_DELETING_NUMBER);
1133*2139Sjp161948 		return 0;
1134*2139Sjp161948 		}
1135*2139Sjp161948 	return 1;
1136*2139Sjp161948 	}
1137*2139Sjp161948 
STORE_store_arbitrary(STORE * s,BUF_MEM * data,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])1138*2139Sjp161948 int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
1139*2139Sjp161948 	OPENSSL_ITEM parameters[])
1140*2139Sjp161948 	{
1141*2139Sjp161948 	STORE_OBJECT *object;
1142*2139Sjp161948 	int i;
1143*2139Sjp161948 
1144*2139Sjp161948 	check_store(s,STORE_F_STORE_STORE_ARBITRARY,
1145*2139Sjp161948 		store_object,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
1146*2139Sjp161948 
1147*2139Sjp161948 	object = STORE_OBJECT_new();
1148*2139Sjp161948 	if (!object)
1149*2139Sjp161948 		{
1150*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1151*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
1152*2139Sjp161948 		return 0;
1153*2139Sjp161948 		}
1154*2139Sjp161948 
1155*2139Sjp161948 	object->data.arbitrary = data;
1156*2139Sjp161948 
1157*2139Sjp161948 	i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object,
1158*2139Sjp161948 		attributes, parameters);
1159*2139Sjp161948 
1160*2139Sjp161948 	STORE_OBJECT_free(object);
1161*2139Sjp161948 
1162*2139Sjp161948 	if (!i)
1163*2139Sjp161948 		{
1164*2139Sjp161948 		STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1165*2139Sjp161948 			STORE_R_FAILED_STORING_ARBITRARY);
1166*2139Sjp161948 		return 0;
1167*2139Sjp161948 		}
1168*2139Sjp161948 	return 1;
1169*2139Sjp161948 	}
1170*2139Sjp161948 
STORE_modify_arbitrary(STORE * s,OPENSSL_ITEM search_attributes[],OPENSSL_ITEM add_attributes[],OPENSSL_ITEM modify_attributes[],OPENSSL_ITEM delete_attributes[],OPENSSL_ITEM parameters[])1171*2139Sjp161948 int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
1172*2139Sjp161948 	OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1173*2139Sjp161948 	OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1174*2139Sjp161948 	{
1175*2139Sjp161948 	check_store(s,STORE_F_STORE_MODIFY_ARBITRARY,
1176*2139Sjp161948 		modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1177*2139Sjp161948 
1178*2139Sjp161948 	if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1179*2139Sjp161948 		    search_attributes, add_attributes, modify_attributes,
1180*2139Sjp161948 		    delete_attributes, parameters))
1181*2139Sjp161948 		{
1182*2139Sjp161948 		STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
1183*2139Sjp161948 			STORE_R_FAILED_MODIFYING_ARBITRARY);
1184*2139Sjp161948 		return 0;
1185*2139Sjp161948 		}
1186*2139Sjp161948 	return 1;
1187*2139Sjp161948 	}
1188*2139Sjp161948 
STORE_get_arbitrary(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])1189*2139Sjp161948 BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1190*2139Sjp161948 	OPENSSL_ITEM parameters[])
1191*2139Sjp161948 	{
1192*2139Sjp161948 	STORE_OBJECT *object;
1193*2139Sjp161948 	BUF_MEM *b;
1194*2139Sjp161948 
1195*2139Sjp161948 	check_store(s,STORE_F_STORE_GET_ARBITRARY,
1196*2139Sjp161948 		get_object,STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION);
1197*2139Sjp161948 
1198*2139Sjp161948 	object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1199*2139Sjp161948 		attributes, parameters);
1200*2139Sjp161948 	if (!object || !object->data.arbitrary)
1201*2139Sjp161948 		{
1202*2139Sjp161948 		STOREerr(STORE_F_STORE_GET_ARBITRARY,
1203*2139Sjp161948 			STORE_R_FAILED_GETTING_ARBITRARY);
1204*2139Sjp161948 		return 0;
1205*2139Sjp161948 		}
1206*2139Sjp161948 	b = object->data.arbitrary;
1207*2139Sjp161948 	object->data.arbitrary = NULL;
1208*2139Sjp161948 	STORE_OBJECT_free(object);
1209*2139Sjp161948 	return b;
1210*2139Sjp161948 	}
1211*2139Sjp161948 
STORE_delete_arbitrary(STORE * s,OPENSSL_ITEM attributes[],OPENSSL_ITEM parameters[])1212*2139Sjp161948 int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1213*2139Sjp161948 	OPENSSL_ITEM parameters[])
1214*2139Sjp161948 	{
1215*2139Sjp161948 	check_store(s,STORE_F_STORE_DELETE_ARBITRARY,
1216*2139Sjp161948 		delete_object,STORE_R_NO_DELETE_ARBITRARY_FUNCTION);
1217*2139Sjp161948 
1218*2139Sjp161948 	if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes,
1219*2139Sjp161948 		    parameters))
1220*2139Sjp161948 		{
1221*2139Sjp161948 		STOREerr(STORE_F_STORE_DELETE_ARBITRARY,
1222*2139Sjp161948 			STORE_R_FAILED_DELETING_ARBITRARY);
1223*2139Sjp161948 		return 0;
1224*2139Sjp161948 		}
1225*2139Sjp161948 	return 1;
1226*2139Sjp161948 	}
1227*2139Sjp161948 
STORE_OBJECT_new(void)1228*2139Sjp161948 STORE_OBJECT *STORE_OBJECT_new(void)
1229*2139Sjp161948 	{
1230*2139Sjp161948 	STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT));
1231*2139Sjp161948 	if (object) memset(object, 0, sizeof(STORE_OBJECT));
1232*2139Sjp161948 	return object;
1233*2139Sjp161948 	}
STORE_OBJECT_free(STORE_OBJECT * data)1234*2139Sjp161948 void STORE_OBJECT_free(STORE_OBJECT *data)
1235*2139Sjp161948 	{
1236*2139Sjp161948 	if (!data) return;
1237*2139Sjp161948 	switch (data->type)
1238*2139Sjp161948 		{
1239*2139Sjp161948 	case STORE_OBJECT_TYPE_X509_CERTIFICATE:
1240*2139Sjp161948 		X509_free(data->data.x509.certificate);
1241*2139Sjp161948 		break;
1242*2139Sjp161948 	case STORE_OBJECT_TYPE_X509_CRL:
1243*2139Sjp161948 		X509_CRL_free(data->data.crl);
1244*2139Sjp161948 		break;
1245*2139Sjp161948 	case STORE_OBJECT_TYPE_PRIVATE_KEY:
1246*2139Sjp161948 	case STORE_OBJECT_TYPE_PUBLIC_KEY:
1247*2139Sjp161948 		EVP_PKEY_free(data->data.key);
1248*2139Sjp161948 		break;
1249*2139Sjp161948 	case STORE_OBJECT_TYPE_NUMBER:
1250*2139Sjp161948 		BN_free(data->data.number);
1251*2139Sjp161948 		break;
1252*2139Sjp161948 	case STORE_OBJECT_TYPE_ARBITRARY:
1253*2139Sjp161948 		BUF_MEM_free(data->data.arbitrary);
1254*2139Sjp161948 		break;
1255*2139Sjp161948 		}
1256*2139Sjp161948 	OPENSSL_free(data);
1257*2139Sjp161948 	}
1258*2139Sjp161948 
1259*2139Sjp161948 IMPLEMENT_STACK_OF(STORE_OBJECT*)
1260*2139Sjp161948 
1261*2139Sjp161948 
1262*2139Sjp161948 struct STORE_attr_info_st
1263*2139Sjp161948 	{
1264*2139Sjp161948 	unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
1265*2139Sjp161948 	union
1266*2139Sjp161948 		{
1267*2139Sjp161948 		char *cstring;
1268*2139Sjp161948 		unsigned char *sha1string;
1269*2139Sjp161948 		X509_NAME *dn;
1270*2139Sjp161948 		BIGNUM *number;
1271*2139Sjp161948 		void *any;
1272*2139Sjp161948 		} values[STORE_ATTR_TYPE_NUM+1];
1273*2139Sjp161948 	size_t value_sizes[STORE_ATTR_TYPE_NUM+1];
1274*2139Sjp161948 	};
1275*2139Sjp161948 
1276*2139Sjp161948 #define ATTR_IS_SET(a,i)	((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1277*2139Sjp161948 				&& ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1278*2139Sjp161948 #define SET_ATTRBIT(a,i)	((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1279*2139Sjp161948 #define CLEAR_ATTRBIT(a,i)	((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1280*2139Sjp161948 
STORE_ATTR_INFO_new(void)1281*2139Sjp161948 STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1282*2139Sjp161948 	{
1283*2139Sjp161948 	return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO));
1284*2139Sjp161948 	}
STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code)1285*2139Sjp161948 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1286*2139Sjp161948 	STORE_ATTR_TYPES code)
1287*2139Sjp161948 	{
1288*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1289*2139Sjp161948 		{
1290*2139Sjp161948 		switch(code)
1291*2139Sjp161948 			{
1292*2139Sjp161948 		case STORE_ATTR_FRIENDLYNAME:
1293*2139Sjp161948 		case STORE_ATTR_EMAIL:
1294*2139Sjp161948 		case STORE_ATTR_FILENAME:
1295*2139Sjp161948 			STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0);
1296*2139Sjp161948 			break;
1297*2139Sjp161948 		case STORE_ATTR_KEYID:
1298*2139Sjp161948 		case STORE_ATTR_ISSUERKEYID:
1299*2139Sjp161948 		case STORE_ATTR_SUBJECTKEYID:
1300*2139Sjp161948 		case STORE_ATTR_ISSUERSERIALHASH:
1301*2139Sjp161948 		case STORE_ATTR_CERTHASH:
1302*2139Sjp161948 			STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0);
1303*2139Sjp161948 			break;
1304*2139Sjp161948 		case STORE_ATTR_ISSUER:
1305*2139Sjp161948 		case STORE_ATTR_SUBJECT:
1306*2139Sjp161948 			STORE_ATTR_INFO_modify_dn(attrs, code, NULL);
1307*2139Sjp161948 			break;
1308*2139Sjp161948 		case STORE_ATTR_SERIAL:
1309*2139Sjp161948 			STORE_ATTR_INFO_modify_number(attrs, code, NULL);
1310*2139Sjp161948 			break;
1311*2139Sjp161948 		default:
1312*2139Sjp161948 			break;
1313*2139Sjp161948 			}
1314*2139Sjp161948 		}
1315*2139Sjp161948 	}
STORE_ATTR_INFO_free(STORE_ATTR_INFO * attrs)1316*2139Sjp161948 int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1317*2139Sjp161948 	{
1318*2139Sjp161948 	if (attrs)
1319*2139Sjp161948 		{
1320*2139Sjp161948 		STORE_ATTR_TYPES i;
1321*2139Sjp161948 		for(i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1322*2139Sjp161948 			STORE_ATTR_INFO_attr_free(attrs, i);
1323*2139Sjp161948 		OPENSSL_free(attrs);
1324*2139Sjp161948 		}
1325*2139Sjp161948 	return 1;
1326*2139Sjp161948 	}
STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code)1327*2139Sjp161948 char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1328*2139Sjp161948 	{
1329*2139Sjp161948 	if (!attrs)
1330*2139Sjp161948 		{
1331*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1332*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1333*2139Sjp161948 		return NULL;
1334*2139Sjp161948 		}
1335*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1336*2139Sjp161948 		return attrs->values[code].cstring;
1337*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1338*2139Sjp161948 		STORE_R_NO_VALUE);
1339*2139Sjp161948 	return NULL;
1340*2139Sjp161948 	}
STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code)1341*2139Sjp161948 unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
1342*2139Sjp161948 	STORE_ATTR_TYPES code)
1343*2139Sjp161948 	{
1344*2139Sjp161948 	if (!attrs)
1345*2139Sjp161948 		{
1346*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1347*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1348*2139Sjp161948 		return NULL;
1349*2139Sjp161948 		}
1350*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1351*2139Sjp161948 		return attrs->values[code].sha1string;
1352*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1353*2139Sjp161948 		STORE_R_NO_VALUE);
1354*2139Sjp161948 	return NULL;
1355*2139Sjp161948 	}
STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code)1356*2139Sjp161948 X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1357*2139Sjp161948 	{
1358*2139Sjp161948 	if (!attrs)
1359*2139Sjp161948 		{
1360*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1361*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1362*2139Sjp161948 		return NULL;
1363*2139Sjp161948 		}
1364*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1365*2139Sjp161948 		return attrs->values[code].dn;
1366*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1367*2139Sjp161948 		STORE_R_NO_VALUE);
1368*2139Sjp161948 	return NULL;
1369*2139Sjp161948 	}
STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code)1370*2139Sjp161948 BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1371*2139Sjp161948 	{
1372*2139Sjp161948 	if (!attrs)
1373*2139Sjp161948 		{
1374*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1375*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1376*2139Sjp161948 		return NULL;
1377*2139Sjp161948 		}
1378*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1379*2139Sjp161948 		return attrs->values[code].number;
1380*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1381*2139Sjp161948 		STORE_R_NO_VALUE);
1382*2139Sjp161948 	return NULL;
1383*2139Sjp161948 	}
STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,char * cstr,size_t cstr_size)1384*2139Sjp161948 int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1385*2139Sjp161948 	char *cstr, size_t cstr_size)
1386*2139Sjp161948 	{
1387*2139Sjp161948 	if (!attrs)
1388*2139Sjp161948 		{
1389*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1390*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1391*2139Sjp161948 		return 0;
1392*2139Sjp161948 		}
1393*2139Sjp161948 	if (!ATTR_IS_SET(attrs,code))
1394*2139Sjp161948 		{
1395*2139Sjp161948 		if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size)))
1396*2139Sjp161948 			return 1;
1397*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1398*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
1399*2139Sjp161948 		return 0;
1400*2139Sjp161948 		}
1401*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE);
1402*2139Sjp161948 	return 0;
1403*2139Sjp161948 	}
STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,unsigned char * sha1str,size_t sha1str_size)1404*2139Sjp161948 int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1405*2139Sjp161948 	unsigned char *sha1str, size_t sha1str_size)
1406*2139Sjp161948 	{
1407*2139Sjp161948 	if (!attrs)
1408*2139Sjp161948 		{
1409*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1410*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1411*2139Sjp161948 		return 0;
1412*2139Sjp161948 		}
1413*2139Sjp161948 	if (!ATTR_IS_SET(attrs,code))
1414*2139Sjp161948 		{
1415*2139Sjp161948 		if ((attrs->values[code].sha1string =
1416*2139Sjp161948 			    (unsigned char *)BUF_memdup(sha1str,
1417*2139Sjp161948 				    sha1str_size)))
1418*2139Sjp161948 			return 1;
1419*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1420*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
1421*2139Sjp161948 		return 0;
1422*2139Sjp161948 		}
1423*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, STORE_R_ALREADY_HAS_A_VALUE);
1424*2139Sjp161948 	return 0;
1425*2139Sjp161948 	}
STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,X509_NAME * dn)1426*2139Sjp161948 int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1427*2139Sjp161948 	X509_NAME *dn)
1428*2139Sjp161948 	{
1429*2139Sjp161948 	if (!attrs)
1430*2139Sjp161948 		{
1431*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1432*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1433*2139Sjp161948 		return 0;
1434*2139Sjp161948 		}
1435*2139Sjp161948 	if (!ATTR_IS_SET(attrs,code))
1436*2139Sjp161948 		{
1437*2139Sjp161948 		if ((attrs->values[code].dn = X509_NAME_dup(dn)))
1438*2139Sjp161948 			return 1;
1439*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1440*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
1441*2139Sjp161948 		return 0;
1442*2139Sjp161948 		}
1443*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE);
1444*2139Sjp161948 	return 0;
1445*2139Sjp161948 	}
STORE_ATTR_INFO_set_number(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,BIGNUM * number)1446*2139Sjp161948 int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1447*2139Sjp161948 	BIGNUM *number)
1448*2139Sjp161948 	{
1449*2139Sjp161948 	if (!attrs)
1450*2139Sjp161948 		{
1451*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1452*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1453*2139Sjp161948 		return 0;
1454*2139Sjp161948 		}
1455*2139Sjp161948 	if (!ATTR_IS_SET(attrs,code))
1456*2139Sjp161948 		{
1457*2139Sjp161948 		if ((attrs->values[code].number = BN_dup(number)))
1458*2139Sjp161948 			return 1;
1459*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1460*2139Sjp161948 			ERR_R_MALLOC_FAILURE);
1461*2139Sjp161948 		return 0;
1462*2139Sjp161948 		}
1463*2139Sjp161948 	STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE);
1464*2139Sjp161948 	return 0;
1465*2139Sjp161948 	}
STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,char * cstr,size_t cstr_size)1466*2139Sjp161948 int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1467*2139Sjp161948 	char *cstr, size_t cstr_size)
1468*2139Sjp161948 	{
1469*2139Sjp161948 	if (!attrs)
1470*2139Sjp161948 		{
1471*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR,
1472*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1473*2139Sjp161948 		return 0;
1474*2139Sjp161948 		}
1475*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1476*2139Sjp161948 		{
1477*2139Sjp161948 		OPENSSL_free(attrs->values[code].cstring);
1478*2139Sjp161948 		attrs->values[code].cstring = NULL;
1479*2139Sjp161948 		CLEAR_ATTRBIT(attrs, code);
1480*2139Sjp161948 		}
1481*2139Sjp161948 	return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size);
1482*2139Sjp161948 	}
STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,unsigned char * sha1str,size_t sha1str_size)1483*2139Sjp161948 int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1484*2139Sjp161948 	unsigned char *sha1str, size_t sha1str_size)
1485*2139Sjp161948 	{
1486*2139Sjp161948 	if (!attrs)
1487*2139Sjp161948 		{
1488*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR,
1489*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1490*2139Sjp161948 		return 0;
1491*2139Sjp161948 		}
1492*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1493*2139Sjp161948 		{
1494*2139Sjp161948 		OPENSSL_free(attrs->values[code].sha1string);
1495*2139Sjp161948 		attrs->values[code].sha1string = NULL;
1496*2139Sjp161948 		CLEAR_ATTRBIT(attrs, code);
1497*2139Sjp161948 		}
1498*2139Sjp161948 	return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size);
1499*2139Sjp161948 	}
STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,X509_NAME * dn)1500*2139Sjp161948 int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1501*2139Sjp161948 	X509_NAME *dn)
1502*2139Sjp161948 	{
1503*2139Sjp161948 	if (!attrs)
1504*2139Sjp161948 		{
1505*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN,
1506*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1507*2139Sjp161948 		return 0;
1508*2139Sjp161948 		}
1509*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1510*2139Sjp161948 		{
1511*2139Sjp161948 		OPENSSL_free(attrs->values[code].dn);
1512*2139Sjp161948 		attrs->values[code].dn = NULL;
1513*2139Sjp161948 		CLEAR_ATTRBIT(attrs, code);
1514*2139Sjp161948 		}
1515*2139Sjp161948 	return STORE_ATTR_INFO_set_dn(attrs, code, dn);
1516*2139Sjp161948 	}
STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO * attrs,STORE_ATTR_TYPES code,BIGNUM * number)1517*2139Sjp161948 int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1518*2139Sjp161948 	BIGNUM *number)
1519*2139Sjp161948 	{
1520*2139Sjp161948 	if (!attrs)
1521*2139Sjp161948 		{
1522*2139Sjp161948 		STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER,
1523*2139Sjp161948 			ERR_R_PASSED_NULL_PARAMETER);
1524*2139Sjp161948 		return 0;
1525*2139Sjp161948 		}
1526*2139Sjp161948 	if (ATTR_IS_SET(attrs,code))
1527*2139Sjp161948 		{
1528*2139Sjp161948 		OPENSSL_free(attrs->values[code].number);
1529*2139Sjp161948 		attrs->values[code].number = NULL;
1530*2139Sjp161948 		CLEAR_ATTRBIT(attrs, code);
1531*2139Sjp161948 		}
1532*2139Sjp161948 	return STORE_ATTR_INFO_set_number(attrs, code, number);
1533*2139Sjp161948 	}
1534*2139Sjp161948 
1535*2139Sjp161948 struct attr_list_ctx_st
1536*2139Sjp161948 	{
1537*2139Sjp161948 	OPENSSL_ITEM *attributes;
1538*2139Sjp161948 	};
STORE_parse_attrs_start(OPENSSL_ITEM * attributes)1539*2139Sjp161948 void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1540*2139Sjp161948 	{
1541*2139Sjp161948 	if (attributes)
1542*2139Sjp161948 		{
1543*2139Sjp161948 		struct attr_list_ctx_st *context =
1544*2139Sjp161948 			(struct attr_list_ctx_st *)OPENSSL_malloc(sizeof(struct attr_list_ctx_st));
1545*2139Sjp161948 		if (context)
1546*2139Sjp161948 			context->attributes = attributes;
1547*2139Sjp161948 		else
1548*2139Sjp161948 			STOREerr(STORE_F_STORE_PARSE_ATTRS_START,
1549*2139Sjp161948 				ERR_R_MALLOC_FAILURE);
1550*2139Sjp161948 		return context;
1551*2139Sjp161948 		}
1552*2139Sjp161948 	STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER);
1553*2139Sjp161948 	return 0;
1554*2139Sjp161948 	}
STORE_parse_attrs_next(void * handle)1555*2139Sjp161948 STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
1556*2139Sjp161948 	{
1557*2139Sjp161948 	struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1558*2139Sjp161948 
1559*2139Sjp161948 	if (context && context->attributes)
1560*2139Sjp161948 		{
1561*2139Sjp161948 		STORE_ATTR_INFO *attrs = NULL;
1562*2139Sjp161948 
1563*2139Sjp161948 		while(context->attributes
1564*2139Sjp161948 			&& context->attributes->code != STORE_ATTR_OR
1565*2139Sjp161948 			&& context->attributes->code != STORE_ATTR_END)
1566*2139Sjp161948 			{
1567*2139Sjp161948 			switch(context->attributes->code)
1568*2139Sjp161948 				{
1569*2139Sjp161948 			case STORE_ATTR_FRIENDLYNAME:
1570*2139Sjp161948 			case STORE_ATTR_EMAIL:
1571*2139Sjp161948 			case STORE_ATTR_FILENAME:
1572*2139Sjp161948 				if (!attrs) attrs = STORE_ATTR_INFO_new();
1573*2139Sjp161948 				if (attrs == NULL)
1574*2139Sjp161948 					{
1575*2139Sjp161948 					STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1576*2139Sjp161948 						ERR_R_MALLOC_FAILURE);
1577*2139Sjp161948 					goto err;
1578*2139Sjp161948 					}
1579*2139Sjp161948 				STORE_ATTR_INFO_set_cstr(attrs,
1580*2139Sjp161948 					context->attributes->code,
1581*2139Sjp161948 					context->attributes->value,
1582*2139Sjp161948 					context->attributes->value_size);
1583*2139Sjp161948 				break;
1584*2139Sjp161948 			case STORE_ATTR_KEYID:
1585*2139Sjp161948 			case STORE_ATTR_ISSUERKEYID:
1586*2139Sjp161948 			case STORE_ATTR_SUBJECTKEYID:
1587*2139Sjp161948 			case STORE_ATTR_ISSUERSERIALHASH:
1588*2139Sjp161948 			case STORE_ATTR_CERTHASH:
1589*2139Sjp161948 				if (!attrs) attrs = STORE_ATTR_INFO_new();
1590*2139Sjp161948 				if (attrs == NULL)
1591*2139Sjp161948 					{
1592*2139Sjp161948 					STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1593*2139Sjp161948 						ERR_R_MALLOC_FAILURE);
1594*2139Sjp161948 					goto err;
1595*2139Sjp161948 					}
1596*2139Sjp161948 				STORE_ATTR_INFO_set_sha1str(attrs,
1597*2139Sjp161948 					context->attributes->code,
1598*2139Sjp161948 					context->attributes->value,
1599*2139Sjp161948 					context->attributes->value_size);
1600*2139Sjp161948 				break;
1601*2139Sjp161948 			case STORE_ATTR_ISSUER:
1602*2139Sjp161948 			case STORE_ATTR_SUBJECT:
1603*2139Sjp161948 				if (!attrs) attrs = STORE_ATTR_INFO_new();
1604*2139Sjp161948 				if (attrs == NULL)
1605*2139Sjp161948 					{
1606*2139Sjp161948 					STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1607*2139Sjp161948 						ERR_R_MALLOC_FAILURE);
1608*2139Sjp161948 					goto err;
1609*2139Sjp161948 					}
1610*2139Sjp161948 				STORE_ATTR_INFO_modify_dn(attrs,
1611*2139Sjp161948 					context->attributes->code,
1612*2139Sjp161948 					context->attributes->value);
1613*2139Sjp161948 				break;
1614*2139Sjp161948 			case STORE_ATTR_SERIAL:
1615*2139Sjp161948 				if (!attrs) attrs = STORE_ATTR_INFO_new();
1616*2139Sjp161948 				if (attrs == NULL)
1617*2139Sjp161948 					{
1618*2139Sjp161948 					STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1619*2139Sjp161948 						ERR_R_MALLOC_FAILURE);
1620*2139Sjp161948 					goto err;
1621*2139Sjp161948 					}
1622*2139Sjp161948 				STORE_ATTR_INFO_modify_number(attrs,
1623*2139Sjp161948 					context->attributes->code,
1624*2139Sjp161948 					context->attributes->value);
1625*2139Sjp161948 				break;
1626*2139Sjp161948 				}
1627*2139Sjp161948 			context->attributes++;
1628*2139Sjp161948 			}
1629*2139Sjp161948 		if (context->attributes->code == STORE_ATTR_OR)
1630*2139Sjp161948 			context->attributes++;
1631*2139Sjp161948 		return attrs;
1632*2139Sjp161948 	err:
1633*2139Sjp161948 		while(context->attributes
1634*2139Sjp161948 			&& context->attributes->code != STORE_ATTR_OR
1635*2139Sjp161948 			&& context->attributes->code != STORE_ATTR_END)
1636*2139Sjp161948 			context->attributes++;
1637*2139Sjp161948 		if (context->attributes->code == STORE_ATTR_OR)
1638*2139Sjp161948 			context->attributes++;
1639*2139Sjp161948 		return NULL;
1640*2139Sjp161948 		}
1641*2139Sjp161948 	STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER);
1642*2139Sjp161948 	return NULL;
1643*2139Sjp161948 	}
STORE_parse_attrs_end(void * handle)1644*2139Sjp161948 int STORE_parse_attrs_end(void *handle)
1645*2139Sjp161948 	{
1646*2139Sjp161948 	struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1647*2139Sjp161948 
1648*2139Sjp161948 	if (context && context->attributes)
1649*2139Sjp161948 		{
1650*2139Sjp161948 #if 0
1651*2139Sjp161948 		OPENSSL_ITEM *attributes = context->attributes;
1652*2139Sjp161948 #endif
1653*2139Sjp161948 		OPENSSL_free(context);
1654*2139Sjp161948 		return 1;
1655*2139Sjp161948 		}
1656*2139Sjp161948 	STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1657*2139Sjp161948 	return 0;
1658*2139Sjp161948 	}
1659*2139Sjp161948 
STORE_parse_attrs_endp(void * handle)1660*2139Sjp161948 int STORE_parse_attrs_endp(void *handle)
1661*2139Sjp161948 	{
1662*2139Sjp161948 	struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1663*2139Sjp161948 
1664*2139Sjp161948 	if (context && context->attributes)
1665*2139Sjp161948 		{
1666*2139Sjp161948 		return context->attributes->code == STORE_ATTR_END;
1667*2139Sjp161948 		}
1668*2139Sjp161948 	STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER);
1669*2139Sjp161948 	return 0;
1670*2139Sjp161948 	}
1671*2139Sjp161948 
attr_info_compare_compute_range(unsigned char * abits,unsigned char * bbits,unsigned int * alowp,unsigned int * ahighp,unsigned int * blowp,unsigned int * bhighp)1672*2139Sjp161948 static int attr_info_compare_compute_range(
1673*2139Sjp161948 	unsigned char *abits, unsigned char *bbits,
1674*2139Sjp161948 	unsigned int *alowp, unsigned int *ahighp,
1675*2139Sjp161948 	unsigned int *blowp, unsigned int *bhighp)
1676*2139Sjp161948 	{
1677*2139Sjp161948 	unsigned int alow = (unsigned int)-1, ahigh = 0;
1678*2139Sjp161948 	unsigned int blow = (unsigned int)-1, bhigh = 0;
1679*2139Sjp161948 	int i, res = 0;
1680*2139Sjp161948 
1681*2139Sjp161948 	for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1682*2139Sjp161948 		{
1683*2139Sjp161948 		if (res == 0)
1684*2139Sjp161948 			{
1685*2139Sjp161948 			if (*abits < *bbits) res = -1;
1686*2139Sjp161948 			if (*abits > *bbits) res = 1;
1687*2139Sjp161948 			}
1688*2139Sjp161948 		if (*abits)
1689*2139Sjp161948 			{
1690*2139Sjp161948 			if (alow == (unsigned int)-1)
1691*2139Sjp161948 				{
1692*2139Sjp161948 				alow = i * 8;
1693*2139Sjp161948 				if (!(*abits & 0x01)) alow++;
1694*2139Sjp161948 				if (!(*abits & 0x02)) alow++;
1695*2139Sjp161948 				if (!(*abits & 0x04)) alow++;
1696*2139Sjp161948 				if (!(*abits & 0x08)) alow++;
1697*2139Sjp161948 				if (!(*abits & 0x10)) alow++;
1698*2139Sjp161948 				if (!(*abits & 0x20)) alow++;
1699*2139Sjp161948 				if (!(*abits & 0x40)) alow++;
1700*2139Sjp161948 				}
1701*2139Sjp161948 			ahigh = i * 8 + 7;
1702*2139Sjp161948 			if (!(*abits & 0x80)) ahigh++;
1703*2139Sjp161948 			if (!(*abits & 0x40)) ahigh++;
1704*2139Sjp161948 			if (!(*abits & 0x20)) ahigh++;
1705*2139Sjp161948 			if (!(*abits & 0x10)) ahigh++;
1706*2139Sjp161948 			if (!(*abits & 0x08)) ahigh++;
1707*2139Sjp161948 			if (!(*abits & 0x04)) ahigh++;
1708*2139Sjp161948 			if (!(*abits & 0x02)) ahigh++;
1709*2139Sjp161948 			}
1710*2139Sjp161948 		if (*bbits)
1711*2139Sjp161948 			{
1712*2139Sjp161948 			if (blow == (unsigned int)-1)
1713*2139Sjp161948 				{
1714*2139Sjp161948 				blow = i * 8;
1715*2139Sjp161948 				if (!(*bbits & 0x01)) blow++;
1716*2139Sjp161948 				if (!(*bbits & 0x02)) blow++;
1717*2139Sjp161948 				if (!(*bbits & 0x04)) blow++;
1718*2139Sjp161948 				if (!(*bbits & 0x08)) blow++;
1719*2139Sjp161948 				if (!(*bbits & 0x10)) blow++;
1720*2139Sjp161948 				if (!(*bbits & 0x20)) blow++;
1721*2139Sjp161948 				if (!(*bbits & 0x40)) blow++;
1722*2139Sjp161948 				}
1723*2139Sjp161948 			bhigh = i * 8 + 7;
1724*2139Sjp161948 			if (!(*bbits & 0x80)) bhigh++;
1725*2139Sjp161948 			if (!(*bbits & 0x40)) bhigh++;
1726*2139Sjp161948 			if (!(*bbits & 0x20)) bhigh++;
1727*2139Sjp161948 			if (!(*bbits & 0x10)) bhigh++;
1728*2139Sjp161948 			if (!(*bbits & 0x08)) bhigh++;
1729*2139Sjp161948 			if (!(*bbits & 0x04)) bhigh++;
1730*2139Sjp161948 			if (!(*bbits & 0x02)) bhigh++;
1731*2139Sjp161948 			}
1732*2139Sjp161948 		}
1733*2139Sjp161948 	if (ahigh + alow < bhigh + blow) res = -1;
1734*2139Sjp161948 	if (ahigh + alow > bhigh + blow) res = 1;
1735*2139Sjp161948 	if (alowp) *alowp = alow;
1736*2139Sjp161948 	if (ahighp) *ahighp = ahigh;
1737*2139Sjp161948 	if (blowp) *blowp = blow;
1738*2139Sjp161948 	if (bhighp) *bhighp = bhigh;
1739*2139Sjp161948 	return res;
1740*2139Sjp161948 	}
1741*2139Sjp161948 
STORE_ATTR_INFO_compare(STORE_ATTR_INFO * a,STORE_ATTR_INFO * b)1742*2139Sjp161948 int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1743*2139Sjp161948 	{
1744*2139Sjp161948 	if (a == b) return 0;
1745*2139Sjp161948 	if (!a) return -1;
1746*2139Sjp161948 	if (!b) return 1;
1747*2139Sjp161948 	return attr_info_compare_compute_range(a->set, b->set, 0, 0, 0, 0);
1748*2139Sjp161948 	}
STORE_ATTR_INFO_in_range(STORE_ATTR_INFO * a,STORE_ATTR_INFO * b)1749*2139Sjp161948 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1750*2139Sjp161948 	{
1751*2139Sjp161948 	unsigned int alow, ahigh, blow, bhigh;
1752*2139Sjp161948 
1753*2139Sjp161948 	if (a == b) return 1;
1754*2139Sjp161948 	if (!a) return 0;
1755*2139Sjp161948 	if (!b) return 0;
1756*2139Sjp161948 	attr_info_compare_compute_range(a->set, b->set,
1757*2139Sjp161948 		&alow, &ahigh, &blow, &bhigh);
1758*2139Sjp161948 	if (alow >= blow && ahigh <= bhigh)
1759*2139Sjp161948 		return 1;
1760*2139Sjp161948 	return 0;
1761*2139Sjp161948 	}
STORE_ATTR_INFO_in(STORE_ATTR_INFO * a,STORE_ATTR_INFO * b)1762*2139Sjp161948 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1763*2139Sjp161948 	{
1764*2139Sjp161948 	unsigned char *abits, *bbits;
1765*2139Sjp161948 	int i;
1766*2139Sjp161948 
1767*2139Sjp161948 	if (a == b) return 1;
1768*2139Sjp161948 	if (!a) return 0;
1769*2139Sjp161948 	if (!b) return 0;
1770*2139Sjp161948 	abits = a->set;
1771*2139Sjp161948 	bbits = b->set;
1772*2139Sjp161948 	for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1773*2139Sjp161948 		{
1774*2139Sjp161948 		if (*abits && (*bbits & *abits) != *abits)
1775*2139Sjp161948 			return 0;
1776*2139Sjp161948 		}
1777*2139Sjp161948 	return 1;
1778*2139Sjp161948 	}
STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO * a,STORE_ATTR_INFO * b)1779*2139Sjp161948 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1780*2139Sjp161948 	{
1781*2139Sjp161948 	STORE_ATTR_TYPES i;
1782*2139Sjp161948 
1783*2139Sjp161948 	if (a == b) return 1;
1784*2139Sjp161948 	if (!STORE_ATTR_INFO_in(a, b)) return 0;
1785*2139Sjp161948 	for (i = 1; i < STORE_ATTR_TYPE_NUM; i++)
1786*2139Sjp161948 		if (ATTR_IS_SET(a, i))
1787*2139Sjp161948 			{
1788*2139Sjp161948 			switch(i)
1789*2139Sjp161948 				{
1790*2139Sjp161948 			case STORE_ATTR_FRIENDLYNAME:
1791*2139Sjp161948 			case STORE_ATTR_EMAIL:
1792*2139Sjp161948 			case STORE_ATTR_FILENAME:
1793*2139Sjp161948 				if (strcmp(a->values[i].cstring,
1794*2139Sjp161948 					    b->values[i].cstring))
1795*2139Sjp161948 					return 0;
1796*2139Sjp161948 				break;
1797*2139Sjp161948 			case STORE_ATTR_KEYID:
1798*2139Sjp161948 			case STORE_ATTR_ISSUERKEYID:
1799*2139Sjp161948 			case STORE_ATTR_SUBJECTKEYID:
1800*2139Sjp161948 			case STORE_ATTR_ISSUERSERIALHASH:
1801*2139Sjp161948 			case STORE_ATTR_CERTHASH:
1802*2139Sjp161948 				if (memcmp(a->values[i].sha1string,
1803*2139Sjp161948 					    b->values[i].sha1string,
1804*2139Sjp161948 					    a->value_sizes[i]))
1805*2139Sjp161948 					return 0;
1806*2139Sjp161948 				break;
1807*2139Sjp161948 			case STORE_ATTR_ISSUER:
1808*2139Sjp161948 			case STORE_ATTR_SUBJECT:
1809*2139Sjp161948 				if (X509_NAME_cmp(a->values[i].dn,
1810*2139Sjp161948 					    b->values[i].dn))
1811*2139Sjp161948 					return 0;
1812*2139Sjp161948 				break;
1813*2139Sjp161948 			case STORE_ATTR_SERIAL:
1814*2139Sjp161948 				if (BN_cmp(a->values[i].number,
1815*2139Sjp161948 					    b->values[i].number))
1816*2139Sjp161948 					return 0;
1817*2139Sjp161948 				break;
1818*2139Sjp161948 			default:
1819*2139Sjp161948 				break;
1820*2139Sjp161948 				}
1821*2139Sjp161948 			}
1822*2139Sjp161948 
1823*2139Sjp161948 	return 1;
1824*2139Sjp161948 	}
1825