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>
65 const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] =
76 const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1] =
79 sizeof(int), /* EVP_TYPE */
80 sizeof(size_t), /* BITS */
81 -1, /* KEY_PARAMETERS */
82 0 /* KEY_NO_PARAMETERS */
85 const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1] =
88 -1, /* FRIENDLYNAME: C string */
89 SHA_DIGEST_LENGTH, /* KEYID: SHA1 digest, 160 bits */
90 SHA_DIGEST_LENGTH, /* ISSUERKEYID: SHA1 digest, 160 bits */
91 SHA_DIGEST_LENGTH, /* SUBJECTKEYID: SHA1 digest, 160 bits */
92 SHA_DIGEST_LENGTH, /* ISSUERSERIALHASH: SHA1 digest, 160 bits */
93 sizeof(X509_NAME *), /* ISSUER: X509_NAME * */
94 sizeof(BIGNUM *), /* SERIAL: BIGNUM * */
95 sizeof(X509_NAME *), /* SUBJECT: X509_NAME * */
96 SHA_DIGEST_LENGTH, /* CERTHASH: SHA1 digest, 160 bits */
97 -1, /* EMAIL: C string */
98 -1, /* FILENAME: C string */
101 STORE *STORE_new_method(const STORE_METHOD *method)
107 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER);
111 ret=(STORE *)OPENSSL_malloc(sizeof(STORE));
114 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
120 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE, ret, &ret->ex_data);
121 if (ret->meth->init && !ret->meth->init(ret))
129 STORE *STORE_new_engine(ENGINE *engine)
133 const STORE_METHOD *meth = 0;
135 #ifdef OPENSSL_NO_ENGINE
140 if (!ENGINE_init(engine))
142 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB);
149 STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_PASSED_NULL_PARAMETER);
154 meth = ENGINE_get_STORE(e);
157 STOREerr(STORE_F_STORE_NEW_ENGINE,
165 ret = STORE_new_method(meth);
168 STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_STORE_LIB);
177 void STORE_free(STORE *store)
181 if (store->meth->clean)
182 store->meth->clean(store);
183 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data);
187 int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void))
191 STOREerr(STORE_F_CTRL,ERR_R_PASSED_NULL_PARAMETER);
194 if (store->meth->ctrl)
195 return store->meth->ctrl(store, cmd, i, p, f);
196 STOREerr(STORE_F_STORE_CTRL,STORE_R_NO_CONTROL_FUNCTION);
201 int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
202 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
204 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE, argl, argp,
205 new_func, dup_func, free_func);
208 int STORE_set_ex_data(STORE *r, int idx, void *arg)
210 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
213 void *STORE_get_ex_data(STORE *r, int idx)
215 return(CRYPTO_get_ex_data(&r->ex_data,idx));
218 const STORE_METHOD *STORE_get_method(STORE *store)
223 const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth)
232 #define check_store(s,fncode,fnname,fnerrcode) \
235 if ((s) == NULL || (s)->meth) \
237 STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
240 if ((s)->meth->fnname == NULL) \
242 STOREerr((fncode), (fnerrcode)); \
250 X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
251 OPENSSL_ITEM parameters[])
253 STORE_OBJECT *object;
256 check_store(s,STORE_F_STORE_GET_CERTIFICATE,
257 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
259 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
260 attributes, parameters);
261 if (!object || !object->data.x509.certificate)
263 STOREerr(STORE_F_STORE_GET_CERTIFICATE,
264 STORE_R_FAILED_GETTING_CERTIFICATE);
267 CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
269 REF_PRINT("X509",data);
271 x = object->data.x509.certificate;
272 STORE_OBJECT_free(object);
276 int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
277 OPENSSL_ITEM parameters[])
279 STORE_OBJECT *object;
282 check_store(s,STORE_F_STORE_CERTIFICATE,
283 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
285 object = STORE_OBJECT_new();
288 STOREerr(STORE_F_STORE_CERTIFICATE,
289 ERR_R_MALLOC_FAILURE);
293 CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509);
295 REF_PRINT("X509",data);
297 object->data.x509.certificate = data;
299 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
300 object, attributes, parameters);
302 STORE_OBJECT_free(object);
306 STOREerr(STORE_F_STORE_CERTIFICATE,
307 STORE_R_FAILED_STORING_CERTIFICATE);
313 int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
314 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
315 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
317 check_store(s,STORE_F_STORE_MODIFY_CERTIFICATE,
318 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
320 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
321 search_attributes, add_attributes, modify_attributes,
322 delete_attributes, parameters))
324 STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
325 STORE_R_FAILED_MODIFYING_CERTIFICATE);
331 int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
332 OPENSSL_ITEM parameters[])
334 check_store(s,STORE_F_STORE_REVOKE_CERTIFICATE,
335 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
337 if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
338 attributes, parameters))
340 STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE,
341 STORE_R_FAILED_REVOKING_CERTIFICATE);
347 int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[],
348 OPENSSL_ITEM parameters[])
350 check_store(s,STORE_F_STORE_DELETE_CERTIFICATE,
351 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
353 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
354 attributes, parameters))
356 STOREerr(STORE_F_STORE_DELETE_CERTIFICATE,
357 STORE_R_FAILED_DELETING_CERTIFICATE);
363 void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[],
364 OPENSSL_ITEM parameters[])
368 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_START,
369 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
371 handle = s->meth->list_object_start(s,
372 STORE_OBJECT_TYPE_X509_CERTIFICATE, attributes, parameters);
375 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START,
376 STORE_R_FAILED_LISTING_CERTIFICATES);
382 X509 *STORE_list_certificate_next(STORE *s, void *handle)
384 STORE_OBJECT *object;
387 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_NEXT,
388 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
390 object = s->meth->list_object_next(s, handle);
391 if (!object || !object->data.x509.certificate)
393 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT,
394 STORE_R_FAILED_LISTING_CERTIFICATES);
397 CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
399 REF_PRINT("X509",data);
401 x = object->data.x509.certificate;
402 STORE_OBJECT_free(object);
406 int STORE_list_certificate_end(STORE *s, void *handle)
408 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_END,
409 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
411 if (!s->meth->list_object_end(s, handle))
413 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END,
414 STORE_R_FAILED_LISTING_CERTIFICATES);
420 int STORE_list_certificate_endp(STORE *s, void *handle)
422 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_ENDP,
423 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
425 if (!s->meth->list_object_endp(s, handle))
427 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP,
428 STORE_R_FAILED_LISTING_CERTIFICATES);
434 EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[],
435 OPENSSL_ITEM parameters[])
437 STORE_OBJECT *object;
440 check_store(s,STORE_F_STORE_GENERATE_KEY,
441 generate_object,STORE_R_NO_GENERATE_OBJECT_FUNCTION);
443 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
444 attributes, parameters);
445 if (!object || !object->data.key)
447 STOREerr(STORE_F_STORE_GENERATE_KEY,
448 STORE_R_FAILED_GENERATING_KEY);
451 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
453 REF_PRINT("EVP_PKEY",data);
455 pkey = object->data.key;
456 STORE_OBJECT_free(object);
460 EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
461 OPENSSL_ITEM parameters[])
463 STORE_OBJECT *object;
466 check_store(s,STORE_F_STORE_GET_PRIVATE_KEY,
467 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
469 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
470 attributes, parameters);
471 if (!object || !object->data.key || !object->data.key)
473 STOREerr(STORE_F_STORE_GET_PRIVATE_KEY,
474 STORE_R_FAILED_GETTING_KEY);
477 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
479 REF_PRINT("EVP_PKEY",data);
481 pkey = object->data.key;
482 STORE_OBJECT_free(object);
486 int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
487 OPENSSL_ITEM parameters[])
489 STORE_OBJECT *object;
492 check_store(s,STORE_F_STORE_PRIVATE_KEY,
493 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
495 object = STORE_OBJECT_new();
498 STOREerr(STORE_F_STORE_PRIVATE_KEY,
499 ERR_R_MALLOC_FAILURE);
502 object->data.key = EVP_PKEY_new();
503 if (!object->data.key)
505 STOREerr(STORE_F_STORE_PRIVATE_KEY,
506 ERR_R_MALLOC_FAILURE);
510 CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
512 REF_PRINT("EVP_PKEY",data);
514 object->data.key = data;
516 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object,
517 attributes, parameters);
519 STORE_OBJECT_free(object);
523 STOREerr(STORE_F_STORE_PRIVATE_KEY,
524 STORE_R_FAILED_STORING_KEY);
530 int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
531 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
532 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
534 check_store(s,STORE_F_STORE_MODIFY_PRIVATE_KEY,
535 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
537 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
538 search_attributes, add_attributes, modify_attributes,
539 delete_attributes, parameters))
541 STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
542 STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
548 int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
549 OPENSSL_ITEM parameters[])
553 check_store(s,STORE_F_STORE_REVOKE_PRIVATE_KEY,
554 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
556 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
557 attributes, parameters);
561 STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY,
562 STORE_R_FAILED_REVOKING_KEY);
568 int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[],
569 OPENSSL_ITEM parameters[])
571 check_store(s,STORE_F_STORE_DELETE_PRIVATE_KEY,
572 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
574 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
575 attributes, parameters))
577 STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY,
578 STORE_R_FAILED_DELETING_KEY);
584 void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[],
585 OPENSSL_ITEM parameters[])
589 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_START,
590 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
592 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
593 attributes, parameters);
596 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START,
597 STORE_R_FAILED_LISTING_KEYS);
603 EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle)
605 STORE_OBJECT *object;
608 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
609 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
611 object = s->meth->list_object_next(s, handle);
612 if (!object || !object->data.key || !object->data.key)
614 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
615 STORE_R_FAILED_LISTING_KEYS);
618 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
620 REF_PRINT("EVP_PKEY",data);
622 pkey = object->data.key;
623 STORE_OBJECT_free(object);
627 int STORE_list_private_key_end(STORE *s, void *handle)
629 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_END,
630 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
632 if (!s->meth->list_object_end(s, handle))
634 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END,
635 STORE_R_FAILED_LISTING_KEYS);
641 int STORE_list_private_key_endp(STORE *s, void *handle)
643 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
644 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
646 if (!s->meth->list_object_endp(s, handle))
648 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
649 STORE_R_FAILED_LISTING_KEYS);
655 EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
656 OPENSSL_ITEM parameters[])
658 STORE_OBJECT *object;
661 check_store(s,STORE_F_STORE_GET_PUBLIC_KEY,
662 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
664 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
665 attributes, parameters);
666 if (!object || !object->data.key || !object->data.key)
668 STOREerr(STORE_F_STORE_GET_PUBLIC_KEY,
669 STORE_R_FAILED_GETTING_KEY);
672 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
674 REF_PRINT("EVP_PKEY",data);
676 pkey = object->data.key;
677 STORE_OBJECT_free(object);
681 int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
682 OPENSSL_ITEM parameters[])
684 STORE_OBJECT *object;
687 check_store(s,STORE_F_STORE_PUBLIC_KEY,
688 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
690 object = STORE_OBJECT_new();
693 STOREerr(STORE_F_STORE_PUBLIC_KEY,
694 ERR_R_MALLOC_FAILURE);
697 object->data.key = EVP_PKEY_new();
698 if (!object->data.key)
700 STOREerr(STORE_F_STORE_PUBLIC_KEY,
701 ERR_R_MALLOC_FAILURE);
705 CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
707 REF_PRINT("EVP_PKEY",data);
709 object->data.key = data;
711 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object,
712 attributes, parameters);
714 STORE_OBJECT_free(object);
718 STOREerr(STORE_F_STORE_PUBLIC_KEY,
719 STORE_R_FAILED_STORING_KEY);
725 int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
726 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
727 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
729 check_store(s,STORE_F_STORE_MODIFY_PUBLIC_KEY,
730 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
732 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
733 search_attributes, add_attributes, modify_attributes,
734 delete_attributes, parameters))
736 STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
737 STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
743 int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
744 OPENSSL_ITEM parameters[])
748 check_store(s,STORE_F_STORE_REVOKE_PUBLIC_KEY,
749 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
751 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
752 attributes, parameters);
756 STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY,
757 STORE_R_FAILED_REVOKING_KEY);
763 int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[],
764 OPENSSL_ITEM parameters[])
766 check_store(s,STORE_F_STORE_DELETE_PUBLIC_KEY,
767 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
769 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
770 attributes, parameters))
772 STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY,
773 STORE_R_FAILED_DELETING_KEY);
779 void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[],
780 OPENSSL_ITEM parameters[])
784 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_START,
785 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
787 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
788 attributes, parameters);
791 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START,
792 STORE_R_FAILED_LISTING_KEYS);
798 EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle)
800 STORE_OBJECT *object;
803 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
804 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
806 object = s->meth->list_object_next(s, handle);
807 if (!object || !object->data.key || !object->data.key)
809 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
810 STORE_R_FAILED_LISTING_KEYS);
813 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
815 REF_PRINT("EVP_PKEY",data);
817 pkey = object->data.key;
818 STORE_OBJECT_free(object);
822 int STORE_list_public_key_end(STORE *s, void *handle)
824 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_END,
825 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
827 if (!s->meth->list_object_end(s, handle))
829 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END,
830 STORE_R_FAILED_LISTING_KEYS);
836 int STORE_list_public_key_endp(STORE *s, void *handle)
838 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
839 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
841 if (!s->meth->list_object_endp(s, handle))
843 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
844 STORE_R_FAILED_LISTING_KEYS);
850 X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
851 OPENSSL_ITEM parameters[])
853 STORE_OBJECT *object;
856 check_store(s,STORE_F_STORE_GENERATE_CRL,
857 generate_object,STORE_R_NO_GENERATE_CRL_FUNCTION);
859 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL,
860 attributes, parameters);
861 if (!object || !object->data.crl)
863 STOREerr(STORE_F_STORE_GENERATE_CRL,
864 STORE_R_FAILED_GENERATING_CRL);
867 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
869 REF_PRINT("X509_CRL",data);
871 crl = object->data.crl;
872 STORE_OBJECT_free(object);
876 X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
877 OPENSSL_ITEM parameters[])
879 STORE_OBJECT *object;
882 check_store(s,STORE_F_STORE_GET_CRL,
883 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
885 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL,
886 attributes, parameters);
887 if (!object || !object->data.crl)
889 STOREerr(STORE_F_STORE_GET_CRL,
890 STORE_R_FAILED_GETTING_KEY);
893 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
895 REF_PRINT("X509_CRL",data);
897 crl = object->data.crl;
898 STORE_OBJECT_free(object);
902 int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
903 OPENSSL_ITEM parameters[])
905 STORE_OBJECT *object;
908 check_store(s,STORE_F_STORE_CRL,
909 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
911 object = STORE_OBJECT_new();
914 STOREerr(STORE_F_STORE_CRL,
915 ERR_R_MALLOC_FAILURE);
919 CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509_CRL);
921 REF_PRINT("X509_CRL",data);
923 object->data.crl = data;
925 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object,
926 attributes, parameters);
928 STORE_OBJECT_free(object);
932 STOREerr(STORE_F_STORE_CRL,
933 STORE_R_FAILED_STORING_KEY);
939 int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
940 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
941 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
943 check_store(s,STORE_F_STORE_MODIFY_CRL,
944 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
946 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
947 search_attributes, add_attributes, modify_attributes,
948 delete_attributes, parameters))
950 STOREerr(STORE_F_STORE_MODIFY_CRL,
951 STORE_R_FAILED_MODIFYING_CRL);
957 int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
958 OPENSSL_ITEM parameters[])
960 check_store(s,STORE_F_STORE_DELETE_CRL,
961 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
963 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL,
964 attributes, parameters))
966 STOREerr(STORE_F_STORE_DELETE_CRL,
967 STORE_R_FAILED_DELETING_KEY);
973 void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[],
974 OPENSSL_ITEM parameters[])
978 check_store(s,STORE_F_STORE_LIST_CRL_START,
979 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
981 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL,
982 attributes, parameters);
985 STOREerr(STORE_F_STORE_LIST_CRL_START,
986 STORE_R_FAILED_LISTING_KEYS);
992 X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
994 STORE_OBJECT *object;
997 check_store(s,STORE_F_STORE_LIST_CRL_NEXT,
998 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
1000 object = s->meth->list_object_next(s, handle);
1001 if (!object || !object->data.crl)
1003 STOREerr(STORE_F_STORE_LIST_CRL_NEXT,
1004 STORE_R_FAILED_LISTING_KEYS);
1007 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
1009 REF_PRINT("X509_CRL",data);
1011 crl = object->data.crl;
1012 STORE_OBJECT_free(object);
1016 int STORE_list_crl_end(STORE *s, void *handle)
1018 check_store(s,STORE_F_STORE_LIST_CRL_END,
1019 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
1021 if (!s->meth->list_object_end(s, handle))
1023 STOREerr(STORE_F_STORE_LIST_CRL_END,
1024 STORE_R_FAILED_LISTING_KEYS);
1030 int STORE_list_crl_endp(STORE *s, void *handle)
1032 check_store(s,STORE_F_STORE_LIST_CRL_ENDP,
1033 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
1035 if (!s->meth->list_object_endp(s, handle))
1037 STOREerr(STORE_F_STORE_LIST_CRL_ENDP,
1038 STORE_R_FAILED_LISTING_KEYS);
1044 int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
1045 OPENSSL_ITEM parameters[])
1047 STORE_OBJECT *object;
1050 check_store(s,STORE_F_STORE_NUMBER,
1051 store_object,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
1053 object = STORE_OBJECT_new();
1056 STOREerr(STORE_F_STORE_NUMBER,
1057 ERR_R_MALLOC_FAILURE);
1061 object->data.number = data;
1063 i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object,
1064 attributes, parameters);
1066 STORE_OBJECT_free(object);
1070 STOREerr(STORE_F_STORE_NUMBER,
1071 STORE_R_FAILED_STORING_NUMBER);
1077 int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
1078 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1079 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1081 check_store(s,STORE_F_STORE_MODIFY_NUMBER,
1082 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1084 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
1085 search_attributes, add_attributes, modify_attributes,
1086 delete_attributes, parameters))
1088 STOREerr(STORE_F_STORE_MODIFY_NUMBER,
1089 STORE_R_FAILED_MODIFYING_NUMBER);
1095 BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
1096 OPENSSL_ITEM parameters[])
1098 STORE_OBJECT *object;
1101 check_store(s,STORE_F_STORE_GET_NUMBER,
1102 get_object,STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION);
1104 object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1106 if (!object || !object->data.number)
1108 STOREerr(STORE_F_STORE_GET_NUMBER,
1109 STORE_R_FAILED_GETTING_NUMBER);
1112 n = object->data.number;
1113 object->data.number = NULL;
1114 STORE_OBJECT_free(object);
1118 int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
1119 OPENSSL_ITEM parameters[])
1121 check_store(s,STORE_F_STORE_DELETE_NUMBER,
1122 delete_object,STORE_R_NO_DELETE_NUMBER_FUNCTION);
1124 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1127 STOREerr(STORE_F_STORE_DELETE_NUMBER,
1128 STORE_R_FAILED_DELETING_NUMBER);
1134 int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
1135 OPENSSL_ITEM parameters[])
1137 STORE_OBJECT *object;
1140 check_store(s,STORE_F_STORE_ARBITRARY,
1141 store_object,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
1143 object = STORE_OBJECT_new();
1146 STOREerr(STORE_F_STORE_ARBITRARY,
1147 ERR_R_MALLOC_FAILURE);
1151 object->data.arbitrary = data;
1153 i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object,
1154 attributes, parameters);
1156 STORE_OBJECT_free(object);
1160 STOREerr(STORE_F_STORE_ARBITRARY,
1161 STORE_R_FAILED_STORING_ARBITRARY);
1167 int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
1168 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1169 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1171 check_store(s,STORE_F_STORE_MODIFY_ARBITRARY,
1172 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1174 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1175 search_attributes, add_attributes, modify_attributes,
1176 delete_attributes, parameters))
1178 STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
1179 STORE_R_FAILED_MODIFYING_ARBITRARY);
1185 BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1186 OPENSSL_ITEM parameters[])
1188 STORE_OBJECT *object;
1191 check_store(s,STORE_F_STORE_GET_ARBITRARY,
1192 get_object,STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION);
1194 object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1195 attributes, parameters);
1196 if (!object || !object->data.arbitrary)
1198 STOREerr(STORE_F_STORE_GET_ARBITRARY,
1199 STORE_R_FAILED_GETTING_ARBITRARY);
1202 b = object->data.arbitrary;
1203 object->data.arbitrary = NULL;
1204 STORE_OBJECT_free(object);
1208 int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1209 OPENSSL_ITEM parameters[])
1211 check_store(s,STORE_F_STORE_DELETE_ARBITRARY,
1212 delete_object,STORE_R_NO_DELETE_ARBITRARY_FUNCTION);
1214 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes,
1217 STOREerr(STORE_F_STORE_DELETE_ARBITRARY,
1218 STORE_R_FAILED_DELETING_ARBITRARY);
1224 STORE_OBJECT *STORE_OBJECT_new(void)
1226 STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT));
1227 if (object) memset(object, 0, sizeof(STORE_OBJECT));
1230 void STORE_OBJECT_free(STORE_OBJECT *data)
1235 case STORE_OBJECT_TYPE_X509_CERTIFICATE:
1236 X509_free(data->data.x509.certificate);
1238 case STORE_OBJECT_TYPE_X509_CRL:
1239 X509_CRL_free(data->data.crl);
1241 case STORE_OBJECT_TYPE_PRIVATE_KEY:
1242 case STORE_OBJECT_TYPE_PUBLIC_KEY:
1243 EVP_PKEY_free(data->data.key);
1245 case STORE_OBJECT_TYPE_NUMBER:
1246 BN_free(data->data.number);
1248 case STORE_OBJECT_TYPE_ARBITRARY:
1249 BUF_MEM_free(data->data.arbitrary);
1255 IMPLEMENT_STACK_OF(STORE_OBJECT*)
1258 struct STORE_attr_info_st
1260 unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
1264 unsigned char *sha1string;
1268 } values[STORE_ATTR_TYPE_NUM+1];
1269 size_t value_sizes[STORE_ATTR_TYPE_NUM+1];
1272 #define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1273 && ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1274 #define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1275 #define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1277 STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1279 return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO));
1281 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1282 STORE_ATTR_TYPES code)
1284 if (ATTR_IS_SET(attrs,code))
1288 case STORE_ATTR_FRIENDLYNAME:
1289 case STORE_ATTR_EMAIL:
1290 case STORE_ATTR_FILENAME:
1291 STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0);
1293 case STORE_ATTR_KEYID:
1294 case STORE_ATTR_ISSUERKEYID:
1295 case STORE_ATTR_SUBJECTKEYID:
1296 case STORE_ATTR_ISSUERSERIALHASH:
1297 case STORE_ATTR_CERTHASH:
1298 STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0);
1300 case STORE_ATTR_ISSUER:
1301 case STORE_ATTR_SUBJECT:
1302 STORE_ATTR_INFO_modify_dn(attrs, code, NULL);
1304 case STORE_ATTR_SERIAL:
1305 STORE_ATTR_INFO_modify_number(attrs, code, NULL);
1312 int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1317 for(i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1318 STORE_ATTR_INFO_attr_free(attrs, i);
1319 OPENSSL_free(attrs);
1323 char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1327 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1328 ERR_R_PASSED_NULL_PARAMETER);
1331 if (ATTR_IS_SET(attrs,code))
1332 return attrs->values[code].cstring;
1333 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1337 unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
1338 STORE_ATTR_TYPES code)
1342 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1343 ERR_R_PASSED_NULL_PARAMETER);
1346 if (ATTR_IS_SET(attrs,code))
1347 return attrs->values[code].sha1string;
1348 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1352 X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1356 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1357 ERR_R_PASSED_NULL_PARAMETER);
1360 if (ATTR_IS_SET(attrs,code))
1361 return attrs->values[code].dn;
1362 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1366 BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1370 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1371 ERR_R_PASSED_NULL_PARAMETER);
1374 if (ATTR_IS_SET(attrs,code))
1375 return attrs->values[code].number;
1376 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1380 int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1381 char *cstr, size_t cstr_size)
1385 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1386 ERR_R_PASSED_NULL_PARAMETER);
1389 if (!ATTR_IS_SET(attrs,code))
1391 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size)))
1393 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1394 ERR_R_MALLOC_FAILURE);
1397 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE);
1400 int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1401 unsigned char *sha1str, size_t sha1str_size)
1405 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1406 ERR_R_PASSED_NULL_PARAMETER);
1409 if (!ATTR_IS_SET(attrs,code))
1411 if ((attrs->values[code].sha1string =
1412 (unsigned char *)BUF_memdup(sha1str,
1415 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1416 ERR_R_MALLOC_FAILURE);
1419 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, STORE_R_ALREADY_HAS_A_VALUE);
1422 int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1427 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1428 ERR_R_PASSED_NULL_PARAMETER);
1431 if (!ATTR_IS_SET(attrs,code))
1433 if ((attrs->values[code].dn = X509_NAME_dup(dn)))
1435 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1436 ERR_R_MALLOC_FAILURE);
1439 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE);
1442 int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1447 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1448 ERR_R_PASSED_NULL_PARAMETER);
1451 if (!ATTR_IS_SET(attrs,code))
1453 if ((attrs->values[code].number = BN_dup(number)))
1455 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1456 ERR_R_MALLOC_FAILURE);
1459 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE);
1462 int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1463 char *cstr, size_t cstr_size)
1467 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR,
1468 ERR_R_PASSED_NULL_PARAMETER);
1471 if (ATTR_IS_SET(attrs,code))
1473 OPENSSL_free(attrs->values[code].cstring);
1474 attrs->values[code].cstring = NULL;
1475 CLEAR_ATTRBIT(attrs, code);
1477 return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size);
1479 int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1480 unsigned char *sha1str, size_t sha1str_size)
1484 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR,
1485 ERR_R_PASSED_NULL_PARAMETER);
1488 if (ATTR_IS_SET(attrs,code))
1490 OPENSSL_free(attrs->values[code].sha1string);
1491 attrs->values[code].sha1string = NULL;
1492 CLEAR_ATTRBIT(attrs, code);
1494 return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size);
1496 int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1501 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN,
1502 ERR_R_PASSED_NULL_PARAMETER);
1505 if (ATTR_IS_SET(attrs,code))
1507 OPENSSL_free(attrs->values[code].dn);
1508 attrs->values[code].dn = NULL;
1509 CLEAR_ATTRBIT(attrs, code);
1511 return STORE_ATTR_INFO_set_dn(attrs, code, dn);
1513 int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1518 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER,
1519 ERR_R_PASSED_NULL_PARAMETER);
1522 if (ATTR_IS_SET(attrs,code))
1524 OPENSSL_free(attrs->values[code].number);
1525 attrs->values[code].number = NULL;
1526 CLEAR_ATTRBIT(attrs, code);
1528 return STORE_ATTR_INFO_set_number(attrs, code, number);
1531 struct attr_list_ctx_st
1533 OPENSSL_ITEM *attributes;
1535 void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1539 struct attr_list_ctx_st *context =
1540 (struct attr_list_ctx_st *)OPENSSL_malloc(sizeof(struct attr_list_ctx_st));
1542 context->attributes = attributes;
1544 STOREerr(STORE_F_STORE_PARSE_ATTRS_END,
1545 ERR_R_MALLOC_FAILURE);
1548 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1551 STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
1553 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1555 if (context && context->attributes)
1557 STORE_ATTR_INFO *attrs = NULL;
1559 while(context->attributes
1560 && context->attributes->code != STORE_ATTR_OR
1561 && context->attributes->code != STORE_ATTR_END)
1563 switch(context->attributes->code)
1565 case STORE_ATTR_FRIENDLYNAME:
1566 case STORE_ATTR_EMAIL:
1567 case STORE_ATTR_FILENAME:
1568 if (!attrs) attrs = STORE_ATTR_INFO_new();
1571 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1572 ERR_R_MALLOC_FAILURE);
1575 STORE_ATTR_INFO_set_cstr(attrs,
1576 context->attributes->code,
1577 context->attributes->value,
1578 context->attributes->value_size);
1580 case STORE_ATTR_KEYID:
1581 case STORE_ATTR_ISSUERKEYID:
1582 case STORE_ATTR_SUBJECTKEYID:
1583 case STORE_ATTR_ISSUERSERIALHASH:
1584 case STORE_ATTR_CERTHASH:
1585 if (!attrs) attrs = STORE_ATTR_INFO_new();
1588 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1589 ERR_R_MALLOC_FAILURE);
1592 STORE_ATTR_INFO_set_sha1str(attrs,
1593 context->attributes->code,
1594 context->attributes->value,
1595 context->attributes->value_size);
1597 case STORE_ATTR_ISSUER:
1598 case STORE_ATTR_SUBJECT:
1599 if (!attrs) attrs = STORE_ATTR_INFO_new();
1602 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1603 ERR_R_MALLOC_FAILURE);
1606 STORE_ATTR_INFO_modify_dn(attrs,
1607 context->attributes->code,
1608 context->attributes->value);
1610 case STORE_ATTR_SERIAL:
1611 if (!attrs) attrs = STORE_ATTR_INFO_new();
1614 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1615 ERR_R_MALLOC_FAILURE);
1618 STORE_ATTR_INFO_modify_number(attrs,
1619 context->attributes->code,
1620 context->attributes->value);
1623 context->attributes++;
1625 if (context->attributes->code == STORE_ATTR_OR)
1626 context->attributes++;
1629 while(context->attributes
1630 && context->attributes->code != STORE_ATTR_OR
1631 && context->attributes->code != STORE_ATTR_END)
1632 context->attributes++;
1633 if (context->attributes->code == STORE_ATTR_OR)
1634 context->attributes++;
1637 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER);
1640 int STORE_parse_attrs_end(void *handle)
1642 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1644 if (context && context->attributes)
1647 OPENSSL_ITEM *attributes = context->attributes;
1649 OPENSSL_free(context);
1652 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1656 int STORE_parse_attrs_endp(void *handle)
1658 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1660 if (context && context->attributes)
1662 return context->attributes->code == STORE_ATTR_END;
1664 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1668 static int attr_info_compare_compute_range(
1669 unsigned char *abits, unsigned char *bbits,
1670 unsigned int *alowp, unsigned int *ahighp,
1671 unsigned int *blowp, unsigned int *bhighp)
1673 unsigned int alow = (unsigned int)-1, ahigh = 0;
1674 unsigned int blow = (unsigned int)-1, bhigh = 0;
1677 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1681 if (*abits < *bbits) res = -1;
1682 if (*abits > *bbits) res = 1;
1686 if (alow == (unsigned int)-1)
1689 if (!(*abits & 0x01)) alow++;
1690 if (!(*abits & 0x02)) alow++;
1691 if (!(*abits & 0x04)) alow++;
1692 if (!(*abits & 0x08)) alow++;
1693 if (!(*abits & 0x10)) alow++;
1694 if (!(*abits & 0x20)) alow++;
1695 if (!(*abits & 0x40)) alow++;
1698 if (!(*abits & 0x80)) ahigh++;
1699 if (!(*abits & 0x40)) ahigh++;
1700 if (!(*abits & 0x20)) ahigh++;
1701 if (!(*abits & 0x10)) ahigh++;
1702 if (!(*abits & 0x08)) ahigh++;
1703 if (!(*abits & 0x04)) ahigh++;
1704 if (!(*abits & 0x02)) ahigh++;
1708 if (blow == (unsigned int)-1)
1711 if (!(*bbits & 0x01)) blow++;
1712 if (!(*bbits & 0x02)) blow++;
1713 if (!(*bbits & 0x04)) blow++;
1714 if (!(*bbits & 0x08)) blow++;
1715 if (!(*bbits & 0x10)) blow++;
1716 if (!(*bbits & 0x20)) blow++;
1717 if (!(*bbits & 0x40)) blow++;
1720 if (!(*bbits & 0x80)) bhigh++;
1721 if (!(*bbits & 0x40)) bhigh++;
1722 if (!(*bbits & 0x20)) bhigh++;
1723 if (!(*bbits & 0x10)) bhigh++;
1724 if (!(*bbits & 0x08)) bhigh++;
1725 if (!(*bbits & 0x04)) bhigh++;
1726 if (!(*bbits & 0x02)) bhigh++;
1729 if (ahigh + alow < bhigh + blow) res = -1;
1730 if (ahigh + alow > bhigh + blow) res = 1;
1731 if (alowp) *alowp = alow;
1732 if (ahighp) *ahighp = ahigh;
1733 if (blowp) *blowp = blow;
1734 if (bhighp) *bhighp = bhigh;
1738 int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1740 if (a == b) return 0;
1743 return attr_info_compare_compute_range(a->set, b->set, 0, 0, 0, 0);
1745 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1747 unsigned int alow, ahigh, blow, bhigh;
1749 if (a == b) return 1;
1752 attr_info_compare_compute_range(a->set, b->set,
1753 &alow, &ahigh, &blow, &bhigh);
1754 if (alow >= blow && ahigh <= bhigh)
1758 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1760 unsigned char *abits, *bbits;
1763 if (a == b) return 1;
1768 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1770 if (*abits && (*bbits & *abits) != *abits)
1775 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1779 if (a == b) return 1;
1780 if (!STORE_ATTR_INFO_in(a, b)) return 0;
1781 for (i = 1; i < STORE_ATTR_TYPE_NUM; i++)
1782 if (ATTR_IS_SET(a, i))
1786 case STORE_ATTR_FRIENDLYNAME:
1787 case STORE_ATTR_EMAIL:
1788 case STORE_ATTR_FILENAME:
1789 if (strcmp(a->values[i].cstring,
1790 b->values[i].cstring))
1793 case STORE_ATTR_KEYID:
1794 case STORE_ATTR_ISSUERKEYID:
1795 case STORE_ATTR_SUBJECTKEYID:
1796 case STORE_ATTR_ISSUERSERIALHASH:
1797 case STORE_ATTR_CERTHASH:
1798 if (memcmp(a->values[i].sha1string,
1799 b->values[i].sha1string,
1803 case STORE_ATTR_ISSUER:
1804 case STORE_ATTR_SUBJECT:
1805 if (X509_NAME_cmp(a->values[i].dn,
1809 case STORE_ATTR_SERIAL:
1810 if (BN_cmp(a->values[i].number,
1811 b->values[i].number))