1 /* crypto/store/str_lib.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
60 #include <openssl/bn.h>
61 #include <openssl/err.h>
62 #include <openssl/engine.h>
63 #include <openssl/sha.h>
64 #include <openssl/x509.h>
67 const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] =
78 const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1] =
81 sizeof(int), /* EVP_TYPE */
82 sizeof(size_t), /* BITS */
83 -1, /* KEY_PARAMETERS */
84 0 /* KEY_NO_PARAMETERS */
87 const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1] =
90 -1, /* FRIENDLYNAME: C string */
91 SHA_DIGEST_LENGTH, /* KEYID: SHA1 digest, 160 bits */
92 SHA_DIGEST_LENGTH, /* ISSUERKEYID: SHA1 digest, 160 bits */
93 SHA_DIGEST_LENGTH, /* SUBJECTKEYID: SHA1 digest, 160 bits */
94 SHA_DIGEST_LENGTH, /* ISSUERSERIALHASH: SHA1 digest, 160 bits */
95 sizeof(X509_NAME *), /* ISSUER: X509_NAME * */
96 sizeof(BIGNUM *), /* SERIAL: BIGNUM * */
97 sizeof(X509_NAME *), /* SUBJECT: X509_NAME * */
98 SHA_DIGEST_LENGTH, /* CERTHASH: SHA1 digest, 160 bits */
99 -1, /* EMAIL: C string */
100 -1, /* FILENAME: C string */
103 STORE *STORE_new_method(const STORE_METHOD *method)
109 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER);
113 ret=(STORE *)OPENSSL_malloc(sizeof(STORE));
116 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
122 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE, ret, &ret->ex_data);
123 if (ret->meth->init && !ret->meth->init(ret))
131 STORE *STORE_new_engine(ENGINE *engine)
135 const STORE_METHOD *meth = 0;
137 #ifdef OPENSSL_NO_ENGINE
142 if (!ENGINE_init(engine))
144 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB);
151 STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_PASSED_NULL_PARAMETER);
156 meth = ENGINE_get_STORE(e);
159 STOREerr(STORE_F_STORE_NEW_ENGINE,
167 ret = STORE_new_method(meth);
170 STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_STORE_LIB);
179 void STORE_free(STORE *store)
183 if (store->meth->clean)
184 store->meth->clean(store);
185 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data);
189 int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void))
193 STOREerr(STORE_F_STORE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
196 if (store->meth->ctrl)
197 return store->meth->ctrl(store, cmd, i, p, f);
198 STOREerr(STORE_F_STORE_CTRL,STORE_R_NO_CONTROL_FUNCTION);
203 int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
204 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
206 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE, argl, argp,
207 new_func, dup_func, free_func);
210 int STORE_set_ex_data(STORE *r, int idx, void *arg)
212 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
215 void *STORE_get_ex_data(STORE *r, int idx)
217 return(CRYPTO_get_ex_data(&r->ex_data,idx));
220 const STORE_METHOD *STORE_get_method(STORE *store)
225 const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth)
234 #define check_store(s,fncode,fnname,fnerrcode) \
237 if ((s) == NULL || (s)->meth) \
239 STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
242 if ((s)->meth->fnname == NULL) \
244 STOREerr((fncode), (fnerrcode)); \
252 X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
253 OPENSSL_ITEM parameters[])
255 STORE_OBJECT *object;
258 check_store(s,STORE_F_STORE_GET_CERTIFICATE,
259 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
261 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
262 attributes, parameters);
263 if (!object || !object->data.x509.certificate)
265 STOREerr(STORE_F_STORE_GET_CERTIFICATE,
266 STORE_R_FAILED_GETTING_CERTIFICATE);
269 CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
271 REF_PRINT("X509",data);
273 x = object->data.x509.certificate;
274 STORE_OBJECT_free(object);
278 int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
279 OPENSSL_ITEM parameters[])
281 STORE_OBJECT *object;
284 check_store(s,STORE_F_STORE_CERTIFICATE,
285 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
287 object = STORE_OBJECT_new();
290 STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
291 ERR_R_MALLOC_FAILURE);
295 CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509);
297 REF_PRINT("X509",data);
299 object->data.x509.certificate = data;
301 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
302 object, attributes, parameters);
304 STORE_OBJECT_free(object);
308 STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
309 STORE_R_FAILED_STORING_CERTIFICATE);
315 int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
316 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
317 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
319 check_store(s,STORE_F_STORE_MODIFY_CERTIFICATE,
320 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
322 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
323 search_attributes, add_attributes, modify_attributes,
324 delete_attributes, parameters))
326 STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
327 STORE_R_FAILED_MODIFYING_CERTIFICATE);
333 int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
334 OPENSSL_ITEM parameters[])
336 check_store(s,STORE_F_STORE_REVOKE_CERTIFICATE,
337 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
339 if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
340 attributes, parameters))
342 STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE,
343 STORE_R_FAILED_REVOKING_CERTIFICATE);
349 int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[],
350 OPENSSL_ITEM parameters[])
352 check_store(s,STORE_F_STORE_DELETE_CERTIFICATE,
353 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
355 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
356 attributes, parameters))
358 STOREerr(STORE_F_STORE_DELETE_CERTIFICATE,
359 STORE_R_FAILED_DELETING_CERTIFICATE);
365 void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[],
366 OPENSSL_ITEM parameters[])
370 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_START,
371 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
373 handle = s->meth->list_object_start(s,
374 STORE_OBJECT_TYPE_X509_CERTIFICATE, attributes, parameters);
377 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START,
378 STORE_R_FAILED_LISTING_CERTIFICATES);
384 X509 *STORE_list_certificate_next(STORE *s, void *handle)
386 STORE_OBJECT *object;
389 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_NEXT,
390 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
392 object = s->meth->list_object_next(s, handle);
393 if (!object || !object->data.x509.certificate)
395 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT,
396 STORE_R_FAILED_LISTING_CERTIFICATES);
399 CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
401 REF_PRINT("X509",data);
403 x = object->data.x509.certificate;
404 STORE_OBJECT_free(object);
408 int STORE_list_certificate_end(STORE *s, void *handle)
410 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_END,
411 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
413 if (!s->meth->list_object_end(s, handle))
415 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END,
416 STORE_R_FAILED_LISTING_CERTIFICATES);
422 int STORE_list_certificate_endp(STORE *s, void *handle)
424 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_ENDP,
425 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
427 if (!s->meth->list_object_endp(s, handle))
429 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP,
430 STORE_R_FAILED_LISTING_CERTIFICATES);
436 EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[],
437 OPENSSL_ITEM parameters[])
439 STORE_OBJECT *object;
442 check_store(s,STORE_F_STORE_GENERATE_KEY,
443 generate_object,STORE_R_NO_GENERATE_OBJECT_FUNCTION);
445 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
446 attributes, parameters);
447 if (!object || !object->data.key)
449 STOREerr(STORE_F_STORE_GENERATE_KEY,
450 STORE_R_FAILED_GENERATING_KEY);
453 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
455 REF_PRINT("EVP_PKEY",data);
457 pkey = object->data.key;
458 STORE_OBJECT_free(object);
462 EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
463 OPENSSL_ITEM parameters[])
465 STORE_OBJECT *object;
468 check_store(s,STORE_F_STORE_GET_PRIVATE_KEY,
469 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
471 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
472 attributes, parameters);
473 if (!object || !object->data.key || !object->data.key)
475 STOREerr(STORE_F_STORE_GET_PRIVATE_KEY,
476 STORE_R_FAILED_GETTING_KEY);
479 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
481 REF_PRINT("EVP_PKEY",data);
483 pkey = object->data.key;
484 STORE_OBJECT_free(object);
488 int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
489 OPENSSL_ITEM parameters[])
491 STORE_OBJECT *object;
494 check_store(s,STORE_F_STORE_STORE_PRIVATE_KEY,
495 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
497 object = STORE_OBJECT_new();
500 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
501 ERR_R_MALLOC_FAILURE);
504 object->data.key = EVP_PKEY_new();
505 if (!object->data.key)
507 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
508 ERR_R_MALLOC_FAILURE);
512 CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
514 REF_PRINT("EVP_PKEY",data);
516 object->data.key = data;
518 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object,
519 attributes, parameters);
521 STORE_OBJECT_free(object);
525 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
526 STORE_R_FAILED_STORING_KEY);
532 int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
533 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
534 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
536 check_store(s,STORE_F_STORE_MODIFY_PRIVATE_KEY,
537 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
539 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
540 search_attributes, add_attributes, modify_attributes,
541 delete_attributes, parameters))
543 STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
544 STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
550 int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
551 OPENSSL_ITEM parameters[])
555 check_store(s,STORE_F_STORE_REVOKE_PRIVATE_KEY,
556 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
558 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
559 attributes, parameters);
563 STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY,
564 STORE_R_FAILED_REVOKING_KEY);
570 int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[],
571 OPENSSL_ITEM parameters[])
573 check_store(s,STORE_F_STORE_DELETE_PRIVATE_KEY,
574 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
576 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
577 attributes, parameters))
579 STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY,
580 STORE_R_FAILED_DELETING_KEY);
586 void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[],
587 OPENSSL_ITEM parameters[])
591 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_START,
592 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
594 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
595 attributes, parameters);
598 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START,
599 STORE_R_FAILED_LISTING_KEYS);
605 EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle)
607 STORE_OBJECT *object;
610 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
611 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
613 object = s->meth->list_object_next(s, handle);
614 if (!object || !object->data.key || !object->data.key)
616 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
617 STORE_R_FAILED_LISTING_KEYS);
620 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
622 REF_PRINT("EVP_PKEY",data);
624 pkey = object->data.key;
625 STORE_OBJECT_free(object);
629 int STORE_list_private_key_end(STORE *s, void *handle)
631 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_END,
632 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
634 if (!s->meth->list_object_end(s, handle))
636 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END,
637 STORE_R_FAILED_LISTING_KEYS);
643 int STORE_list_private_key_endp(STORE *s, void *handle)
645 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
646 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
648 if (!s->meth->list_object_endp(s, handle))
650 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
651 STORE_R_FAILED_LISTING_KEYS);
657 EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
658 OPENSSL_ITEM parameters[])
660 STORE_OBJECT *object;
663 check_store(s,STORE_F_STORE_GET_PUBLIC_KEY,
664 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
666 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
667 attributes, parameters);
668 if (!object || !object->data.key || !object->data.key)
670 STOREerr(STORE_F_STORE_GET_PUBLIC_KEY,
671 STORE_R_FAILED_GETTING_KEY);
674 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
676 REF_PRINT("EVP_PKEY",data);
678 pkey = object->data.key;
679 STORE_OBJECT_free(object);
683 int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
684 OPENSSL_ITEM parameters[])
686 STORE_OBJECT *object;
689 check_store(s,STORE_F_STORE_STORE_PUBLIC_KEY,
690 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
692 object = STORE_OBJECT_new();
695 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
696 ERR_R_MALLOC_FAILURE);
699 object->data.key = EVP_PKEY_new();
700 if (!object->data.key)
702 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
703 ERR_R_MALLOC_FAILURE);
707 CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
709 REF_PRINT("EVP_PKEY",data);
711 object->data.key = data;
713 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object,
714 attributes, parameters);
716 STORE_OBJECT_free(object);
720 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
721 STORE_R_FAILED_STORING_KEY);
727 int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
728 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
729 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
731 check_store(s,STORE_F_STORE_MODIFY_PUBLIC_KEY,
732 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
734 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
735 search_attributes, add_attributes, modify_attributes,
736 delete_attributes, parameters))
738 STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
739 STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
745 int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
746 OPENSSL_ITEM parameters[])
750 check_store(s,STORE_F_STORE_REVOKE_PUBLIC_KEY,
751 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
753 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
754 attributes, parameters);
758 STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY,
759 STORE_R_FAILED_REVOKING_KEY);
765 int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[],
766 OPENSSL_ITEM parameters[])
768 check_store(s,STORE_F_STORE_DELETE_PUBLIC_KEY,
769 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
771 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
772 attributes, parameters))
774 STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY,
775 STORE_R_FAILED_DELETING_KEY);
781 void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[],
782 OPENSSL_ITEM parameters[])
786 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_START,
787 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
789 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
790 attributes, parameters);
793 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START,
794 STORE_R_FAILED_LISTING_KEYS);
800 EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle)
802 STORE_OBJECT *object;
805 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
806 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
808 object = s->meth->list_object_next(s, handle);
809 if (!object || !object->data.key || !object->data.key)
811 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
812 STORE_R_FAILED_LISTING_KEYS);
815 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
817 REF_PRINT("EVP_PKEY",data);
819 pkey = object->data.key;
820 STORE_OBJECT_free(object);
824 int STORE_list_public_key_end(STORE *s, void *handle)
826 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_END,
827 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
829 if (!s->meth->list_object_end(s, handle))
831 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END,
832 STORE_R_FAILED_LISTING_KEYS);
838 int STORE_list_public_key_endp(STORE *s, void *handle)
840 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
841 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
843 if (!s->meth->list_object_endp(s, handle))
845 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
846 STORE_R_FAILED_LISTING_KEYS);
852 X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
853 OPENSSL_ITEM parameters[])
855 STORE_OBJECT *object;
858 check_store(s,STORE_F_STORE_GENERATE_CRL,
859 generate_object,STORE_R_NO_GENERATE_CRL_FUNCTION);
861 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL,
862 attributes, parameters);
863 if (!object || !object->data.crl)
865 STOREerr(STORE_F_STORE_GENERATE_CRL,
866 STORE_R_FAILED_GENERATING_CRL);
869 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
871 REF_PRINT("X509_CRL",data);
873 crl = object->data.crl;
874 STORE_OBJECT_free(object);
878 X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
879 OPENSSL_ITEM parameters[])
881 STORE_OBJECT *object;
884 check_store(s,STORE_F_STORE_GET_CRL,
885 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
887 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL,
888 attributes, parameters);
889 if (!object || !object->data.crl)
891 STOREerr(STORE_F_STORE_GET_CRL,
892 STORE_R_FAILED_GETTING_KEY);
895 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
897 REF_PRINT("X509_CRL",data);
899 crl = object->data.crl;
900 STORE_OBJECT_free(object);
904 int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
905 OPENSSL_ITEM parameters[])
907 STORE_OBJECT *object;
910 check_store(s,STORE_F_STORE_STORE_CRL,
911 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
913 object = STORE_OBJECT_new();
916 STOREerr(STORE_F_STORE_STORE_CRL,
917 ERR_R_MALLOC_FAILURE);
921 CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509_CRL);
923 REF_PRINT("X509_CRL",data);
925 object->data.crl = data;
927 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object,
928 attributes, parameters);
930 STORE_OBJECT_free(object);
934 STOREerr(STORE_F_STORE_STORE_CRL,
935 STORE_R_FAILED_STORING_KEY);
941 int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
942 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
943 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
945 check_store(s,STORE_F_STORE_MODIFY_CRL,
946 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
948 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
949 search_attributes, add_attributes, modify_attributes,
950 delete_attributes, parameters))
952 STOREerr(STORE_F_STORE_MODIFY_CRL,
953 STORE_R_FAILED_MODIFYING_CRL);
959 int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
960 OPENSSL_ITEM parameters[])
962 check_store(s,STORE_F_STORE_DELETE_CRL,
963 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
965 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL,
966 attributes, parameters))
968 STOREerr(STORE_F_STORE_DELETE_CRL,
969 STORE_R_FAILED_DELETING_KEY);
975 void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[],
976 OPENSSL_ITEM parameters[])
980 check_store(s,STORE_F_STORE_LIST_CRL_START,
981 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
983 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL,
984 attributes, parameters);
987 STOREerr(STORE_F_STORE_LIST_CRL_START,
988 STORE_R_FAILED_LISTING_KEYS);
994 X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
996 STORE_OBJECT *object;
999 check_store(s,STORE_F_STORE_LIST_CRL_NEXT,
1000 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
1002 object = s->meth->list_object_next(s, handle);
1003 if (!object || !object->data.crl)
1005 STOREerr(STORE_F_STORE_LIST_CRL_NEXT,
1006 STORE_R_FAILED_LISTING_KEYS);
1009 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
1011 REF_PRINT("X509_CRL",data);
1013 crl = object->data.crl;
1014 STORE_OBJECT_free(object);
1018 int STORE_list_crl_end(STORE *s, void *handle)
1020 check_store(s,STORE_F_STORE_LIST_CRL_END,
1021 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
1023 if (!s->meth->list_object_end(s, handle))
1025 STOREerr(STORE_F_STORE_LIST_CRL_END,
1026 STORE_R_FAILED_LISTING_KEYS);
1032 int STORE_list_crl_endp(STORE *s, void *handle)
1034 check_store(s,STORE_F_STORE_LIST_CRL_ENDP,
1035 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
1037 if (!s->meth->list_object_endp(s, handle))
1039 STOREerr(STORE_F_STORE_LIST_CRL_ENDP,
1040 STORE_R_FAILED_LISTING_KEYS);
1046 int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
1047 OPENSSL_ITEM parameters[])
1049 STORE_OBJECT *object;
1052 check_store(s,STORE_F_STORE_STORE_NUMBER,
1053 store_object,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
1055 object = STORE_OBJECT_new();
1058 STOREerr(STORE_F_STORE_STORE_NUMBER,
1059 ERR_R_MALLOC_FAILURE);
1063 object->data.number = data;
1065 i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object,
1066 attributes, parameters);
1068 STORE_OBJECT_free(object);
1072 STOREerr(STORE_F_STORE_STORE_NUMBER,
1073 STORE_R_FAILED_STORING_NUMBER);
1079 int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
1080 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1081 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1083 check_store(s,STORE_F_STORE_MODIFY_NUMBER,
1084 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1086 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
1087 search_attributes, add_attributes, modify_attributes,
1088 delete_attributes, parameters))
1090 STOREerr(STORE_F_STORE_MODIFY_NUMBER,
1091 STORE_R_FAILED_MODIFYING_NUMBER);
1097 BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
1098 OPENSSL_ITEM parameters[])
1100 STORE_OBJECT *object;
1103 check_store(s,STORE_F_STORE_GET_NUMBER,
1104 get_object,STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION);
1106 object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1108 if (!object || !object->data.number)
1110 STOREerr(STORE_F_STORE_GET_NUMBER,
1111 STORE_R_FAILED_GETTING_NUMBER);
1114 n = object->data.number;
1115 object->data.number = NULL;
1116 STORE_OBJECT_free(object);
1120 int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
1121 OPENSSL_ITEM parameters[])
1123 check_store(s,STORE_F_STORE_DELETE_NUMBER,
1124 delete_object,STORE_R_NO_DELETE_NUMBER_FUNCTION);
1126 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1129 STOREerr(STORE_F_STORE_DELETE_NUMBER,
1130 STORE_R_FAILED_DELETING_NUMBER);
1136 int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
1137 OPENSSL_ITEM parameters[])
1139 STORE_OBJECT *object;
1142 check_store(s,STORE_F_STORE_STORE_ARBITRARY,
1143 store_object,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
1145 object = STORE_OBJECT_new();
1148 STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1149 ERR_R_MALLOC_FAILURE);
1153 object->data.arbitrary = data;
1155 i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object,
1156 attributes, parameters);
1158 STORE_OBJECT_free(object);
1162 STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1163 STORE_R_FAILED_STORING_ARBITRARY);
1169 int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
1170 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1171 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1173 check_store(s,STORE_F_STORE_MODIFY_ARBITRARY,
1174 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1176 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1177 search_attributes, add_attributes, modify_attributes,
1178 delete_attributes, parameters))
1180 STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
1181 STORE_R_FAILED_MODIFYING_ARBITRARY);
1187 BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1188 OPENSSL_ITEM parameters[])
1190 STORE_OBJECT *object;
1193 check_store(s,STORE_F_STORE_GET_ARBITRARY,
1194 get_object,STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION);
1196 object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1197 attributes, parameters);
1198 if (!object || !object->data.arbitrary)
1200 STOREerr(STORE_F_STORE_GET_ARBITRARY,
1201 STORE_R_FAILED_GETTING_ARBITRARY);
1204 b = object->data.arbitrary;
1205 object->data.arbitrary = NULL;
1206 STORE_OBJECT_free(object);
1210 int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1211 OPENSSL_ITEM parameters[])
1213 check_store(s,STORE_F_STORE_DELETE_ARBITRARY,
1214 delete_object,STORE_R_NO_DELETE_ARBITRARY_FUNCTION);
1216 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes,
1219 STOREerr(STORE_F_STORE_DELETE_ARBITRARY,
1220 STORE_R_FAILED_DELETING_ARBITRARY);
1226 STORE_OBJECT *STORE_OBJECT_new(void)
1228 STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT));
1229 if (object) memset(object, 0, sizeof(STORE_OBJECT));
1232 void STORE_OBJECT_free(STORE_OBJECT *data)
1237 case STORE_OBJECT_TYPE_X509_CERTIFICATE:
1238 X509_free(data->data.x509.certificate);
1240 case STORE_OBJECT_TYPE_X509_CRL:
1241 X509_CRL_free(data->data.crl);
1243 case STORE_OBJECT_TYPE_PRIVATE_KEY:
1244 case STORE_OBJECT_TYPE_PUBLIC_KEY:
1245 EVP_PKEY_free(data->data.key);
1247 case STORE_OBJECT_TYPE_NUMBER:
1248 BN_free(data->data.number);
1250 case STORE_OBJECT_TYPE_ARBITRARY:
1251 BUF_MEM_free(data->data.arbitrary);
1257 IMPLEMENT_STACK_OF(STORE_OBJECT*)
1260 struct STORE_attr_info_st
1262 unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
1266 unsigned char *sha1string;
1270 } values[STORE_ATTR_TYPE_NUM+1];
1271 size_t value_sizes[STORE_ATTR_TYPE_NUM+1];
1274 #define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1275 && ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1276 #define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1277 #define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1279 STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1281 return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO));
1283 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1284 STORE_ATTR_TYPES code)
1286 if (ATTR_IS_SET(attrs,code))
1290 case STORE_ATTR_FRIENDLYNAME:
1291 case STORE_ATTR_EMAIL:
1292 case STORE_ATTR_FILENAME:
1293 STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0);
1295 case STORE_ATTR_KEYID:
1296 case STORE_ATTR_ISSUERKEYID:
1297 case STORE_ATTR_SUBJECTKEYID:
1298 case STORE_ATTR_ISSUERSERIALHASH:
1299 case STORE_ATTR_CERTHASH:
1300 STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0);
1302 case STORE_ATTR_ISSUER:
1303 case STORE_ATTR_SUBJECT:
1304 STORE_ATTR_INFO_modify_dn(attrs, code, NULL);
1306 case STORE_ATTR_SERIAL:
1307 STORE_ATTR_INFO_modify_number(attrs, code, NULL);
1314 int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1319 for(i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1320 STORE_ATTR_INFO_attr_free(attrs, i);
1321 OPENSSL_free(attrs);
1325 char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1329 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1330 ERR_R_PASSED_NULL_PARAMETER);
1333 if (ATTR_IS_SET(attrs,code))
1334 return attrs->values[code].cstring;
1335 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1339 unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
1340 STORE_ATTR_TYPES code)
1344 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1345 ERR_R_PASSED_NULL_PARAMETER);
1348 if (ATTR_IS_SET(attrs,code))
1349 return attrs->values[code].sha1string;
1350 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1354 X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1358 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1359 ERR_R_PASSED_NULL_PARAMETER);
1362 if (ATTR_IS_SET(attrs,code))
1363 return attrs->values[code].dn;
1364 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1368 BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1372 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1373 ERR_R_PASSED_NULL_PARAMETER);
1376 if (ATTR_IS_SET(attrs,code))
1377 return attrs->values[code].number;
1378 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1382 int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1383 char *cstr, size_t cstr_size)
1387 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1388 ERR_R_PASSED_NULL_PARAMETER);
1391 if (!ATTR_IS_SET(attrs,code))
1393 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size)))
1395 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1396 ERR_R_MALLOC_FAILURE);
1399 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE);
1402 int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1403 unsigned char *sha1str, size_t sha1str_size)
1407 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1408 ERR_R_PASSED_NULL_PARAMETER);
1411 if (!ATTR_IS_SET(attrs,code))
1413 if ((attrs->values[code].sha1string =
1414 (unsigned char *)BUF_memdup(sha1str,
1417 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1418 ERR_R_MALLOC_FAILURE);
1421 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, STORE_R_ALREADY_HAS_A_VALUE);
1424 int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1429 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1430 ERR_R_PASSED_NULL_PARAMETER);
1433 if (!ATTR_IS_SET(attrs,code))
1435 if ((attrs->values[code].dn = X509_NAME_dup(dn)))
1437 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1438 ERR_R_MALLOC_FAILURE);
1441 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE);
1444 int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1449 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1450 ERR_R_PASSED_NULL_PARAMETER);
1453 if (!ATTR_IS_SET(attrs,code))
1455 if ((attrs->values[code].number = BN_dup(number)))
1457 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1458 ERR_R_MALLOC_FAILURE);
1461 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE);
1464 int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1465 char *cstr, size_t cstr_size)
1469 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR,
1470 ERR_R_PASSED_NULL_PARAMETER);
1473 if (ATTR_IS_SET(attrs,code))
1475 OPENSSL_free(attrs->values[code].cstring);
1476 attrs->values[code].cstring = NULL;
1477 CLEAR_ATTRBIT(attrs, code);
1479 return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size);
1481 int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1482 unsigned char *sha1str, size_t sha1str_size)
1486 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR,
1487 ERR_R_PASSED_NULL_PARAMETER);
1490 if (ATTR_IS_SET(attrs,code))
1492 OPENSSL_free(attrs->values[code].sha1string);
1493 attrs->values[code].sha1string = NULL;
1494 CLEAR_ATTRBIT(attrs, code);
1496 return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size);
1498 int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1503 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN,
1504 ERR_R_PASSED_NULL_PARAMETER);
1507 if (ATTR_IS_SET(attrs,code))
1509 OPENSSL_free(attrs->values[code].dn);
1510 attrs->values[code].dn = NULL;
1511 CLEAR_ATTRBIT(attrs, code);
1513 return STORE_ATTR_INFO_set_dn(attrs, code, dn);
1515 int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1520 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER,
1521 ERR_R_PASSED_NULL_PARAMETER);
1524 if (ATTR_IS_SET(attrs,code))
1526 OPENSSL_free(attrs->values[code].number);
1527 attrs->values[code].number = NULL;
1528 CLEAR_ATTRBIT(attrs, code);
1530 return STORE_ATTR_INFO_set_number(attrs, code, number);
1533 struct attr_list_ctx_st
1535 OPENSSL_ITEM *attributes;
1537 void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1541 struct attr_list_ctx_st *context =
1542 (struct attr_list_ctx_st *)OPENSSL_malloc(sizeof(struct attr_list_ctx_st));
1544 context->attributes = attributes;
1546 STOREerr(STORE_F_STORE_PARSE_ATTRS_START,
1547 ERR_R_MALLOC_FAILURE);
1550 STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER);
1553 STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
1555 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1557 if (context && context->attributes)
1559 STORE_ATTR_INFO *attrs = NULL;
1561 while(context->attributes
1562 && context->attributes->code != STORE_ATTR_OR
1563 && context->attributes->code != STORE_ATTR_END)
1565 switch(context->attributes->code)
1567 case STORE_ATTR_FRIENDLYNAME:
1568 case STORE_ATTR_EMAIL:
1569 case STORE_ATTR_FILENAME:
1570 if (!attrs) attrs = STORE_ATTR_INFO_new();
1573 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1574 ERR_R_MALLOC_FAILURE);
1577 STORE_ATTR_INFO_set_cstr(attrs,
1578 context->attributes->code,
1579 context->attributes->value,
1580 context->attributes->value_size);
1582 case STORE_ATTR_KEYID:
1583 case STORE_ATTR_ISSUERKEYID:
1584 case STORE_ATTR_SUBJECTKEYID:
1585 case STORE_ATTR_ISSUERSERIALHASH:
1586 case STORE_ATTR_CERTHASH:
1587 if (!attrs) attrs = STORE_ATTR_INFO_new();
1590 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1591 ERR_R_MALLOC_FAILURE);
1594 STORE_ATTR_INFO_set_sha1str(attrs,
1595 context->attributes->code,
1596 context->attributes->value,
1597 context->attributes->value_size);
1599 case STORE_ATTR_ISSUER:
1600 case STORE_ATTR_SUBJECT:
1601 if (!attrs) attrs = STORE_ATTR_INFO_new();
1604 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1605 ERR_R_MALLOC_FAILURE);
1608 STORE_ATTR_INFO_modify_dn(attrs,
1609 context->attributes->code,
1610 context->attributes->value);
1612 case STORE_ATTR_SERIAL:
1613 if (!attrs) attrs = STORE_ATTR_INFO_new();
1616 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1617 ERR_R_MALLOC_FAILURE);
1620 STORE_ATTR_INFO_modify_number(attrs,
1621 context->attributes->code,
1622 context->attributes->value);
1625 context->attributes++;
1627 if (context->attributes->code == STORE_ATTR_OR)
1628 context->attributes++;
1631 while(context->attributes
1632 && context->attributes->code != STORE_ATTR_OR
1633 && context->attributes->code != STORE_ATTR_END)
1634 context->attributes++;
1635 if (context->attributes->code == STORE_ATTR_OR)
1636 context->attributes++;
1639 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER);
1642 int STORE_parse_attrs_end(void *handle)
1644 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1646 if (context && context->attributes)
1649 OPENSSL_ITEM *attributes = context->attributes;
1651 OPENSSL_free(context);
1654 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1658 int STORE_parse_attrs_endp(void *handle)
1660 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1662 if (context && context->attributes)
1664 return context->attributes->code == STORE_ATTR_END;
1666 STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER);
1670 static int attr_info_compare_compute_range(
1671 unsigned char *abits, unsigned char *bbits,
1672 unsigned int *alowp, unsigned int *ahighp,
1673 unsigned int *blowp, unsigned int *bhighp)
1675 unsigned int alow = (unsigned int)-1, ahigh = 0;
1676 unsigned int blow = (unsigned int)-1, bhigh = 0;
1679 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1683 if (*abits < *bbits) res = -1;
1684 if (*abits > *bbits) res = 1;
1688 if (alow == (unsigned int)-1)
1691 if (!(*abits & 0x01)) alow++;
1692 if (!(*abits & 0x02)) alow++;
1693 if (!(*abits & 0x04)) alow++;
1694 if (!(*abits & 0x08)) alow++;
1695 if (!(*abits & 0x10)) alow++;
1696 if (!(*abits & 0x20)) alow++;
1697 if (!(*abits & 0x40)) alow++;
1700 if (!(*abits & 0x80)) ahigh++;
1701 if (!(*abits & 0x40)) ahigh++;
1702 if (!(*abits & 0x20)) ahigh++;
1703 if (!(*abits & 0x10)) ahigh++;
1704 if (!(*abits & 0x08)) ahigh++;
1705 if (!(*abits & 0x04)) ahigh++;
1706 if (!(*abits & 0x02)) ahigh++;
1710 if (blow == (unsigned int)-1)
1713 if (!(*bbits & 0x01)) blow++;
1714 if (!(*bbits & 0x02)) blow++;
1715 if (!(*bbits & 0x04)) blow++;
1716 if (!(*bbits & 0x08)) blow++;
1717 if (!(*bbits & 0x10)) blow++;
1718 if (!(*bbits & 0x20)) blow++;
1719 if (!(*bbits & 0x40)) blow++;
1722 if (!(*bbits & 0x80)) bhigh++;
1723 if (!(*bbits & 0x40)) bhigh++;
1724 if (!(*bbits & 0x20)) bhigh++;
1725 if (!(*bbits & 0x10)) bhigh++;
1726 if (!(*bbits & 0x08)) bhigh++;
1727 if (!(*bbits & 0x04)) bhigh++;
1728 if (!(*bbits & 0x02)) bhigh++;
1731 if (ahigh + alow < bhigh + blow) res = -1;
1732 if (ahigh + alow > bhigh + blow) res = 1;
1733 if (alowp) *alowp = alow;
1734 if (ahighp) *ahighp = ahigh;
1735 if (blowp) *blowp = blow;
1736 if (bhighp) *bhighp = bhigh;
1740 int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1742 if (a == b) return 0;
1745 return attr_info_compare_compute_range(a->set, b->set, 0, 0, 0, 0);
1747 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1749 unsigned int alow, ahigh, blow, bhigh;
1751 if (a == b) return 1;
1754 attr_info_compare_compute_range(a->set, b->set,
1755 &alow, &ahigh, &blow, &bhigh);
1756 if (alow >= blow && ahigh <= bhigh)
1760 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1762 unsigned char *abits, *bbits;
1765 if (a == b) return 1;
1770 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1772 if (*abits && (*bbits & *abits) != *abits)
1777 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1781 if (a == b) return 1;
1782 if (!STORE_ATTR_INFO_in(a, b)) return 0;
1783 for (i = 1; i < STORE_ATTR_TYPE_NUM; i++)
1784 if (ATTR_IS_SET(a, i))
1788 case STORE_ATTR_FRIENDLYNAME:
1789 case STORE_ATTR_EMAIL:
1790 case STORE_ATTR_FILENAME:
1791 if (strcmp(a->values[i].cstring,
1792 b->values[i].cstring))
1795 case STORE_ATTR_KEYID:
1796 case STORE_ATTR_ISSUERKEYID:
1797 case STORE_ATTR_SUBJECTKEYID:
1798 case STORE_ATTR_ISSUERSERIALHASH:
1799 case STORE_ATTR_CERTHASH:
1800 if (memcmp(a->values[i].sha1string,
1801 b->values[i].sha1string,
1805 case STORE_ATTR_ISSUER:
1806 case STORE_ATTR_SUBJECT:
1807 if (X509_NAME_cmp(a->values[i].dn,
1811 case STORE_ATTR_SERIAL:
1812 if (BN_cmp(a->values[i].number,
1813 b->values[i].number))