1 /* crypto/store/str_lib.c -*- mode:C; c-file-style: "eay" -*- */
3 * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
6 /* ====================================================================
7 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@openssl.org.
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
35 * 6. Redistributions of any form whatsoever must retain the following
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
61 #include <openssl/bn.h>
62 #include <openssl/err.h>
63 #ifndef OPENSSL_NO_ENGINE
64 # include <openssl/engine.h>
66 #include <openssl/sha.h>
67 #include <openssl/x509.h>
70 const char *const STORE_object_type_string[STORE_OBJECT_TYPE_NUM + 1] = {
80 const int STORE_param_sizes[STORE_PARAM_TYPE_NUM + 1] = {
82 sizeof(int), /* EVP_TYPE */
83 sizeof(size_t), /* BITS */
84 -1, /* KEY_PARAMETERS */
85 0 /* KEY_NO_PARAMETERS */
88 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)
107 if (method == NULL) {
108 STOREerr(STORE_F_STORE_NEW_METHOD, ERR_R_PASSED_NULL_PARAMETER);
112 ret = OPENSSL_malloc(sizeof(*ret));
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)) {
128 STORE *STORE_new_engine(ENGINE *engine)
132 const STORE_METHOD *meth = 0;
134 #ifdef OPENSSL_NO_ENGINE
138 if (!ENGINE_init(engine)) {
139 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB);
144 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_PASSED_NULL_PARAMETER);
148 meth = ENGINE_get_STORE(e);
150 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB);
157 ret = STORE_new_method(meth);
159 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_STORE_LIB);
168 void STORE_free(STORE *store)
172 if (store->meth->clean)
173 store->meth->clean(store);
174 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data);
178 int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f) (void))
181 STOREerr(STORE_F_STORE_CTRL, ERR_R_PASSED_NULL_PARAMETER);
184 if (store->meth->ctrl)
185 return store->meth->ctrl(store, cmd, i, p, f);
186 STOREerr(STORE_F_STORE_CTRL, STORE_R_NO_CONTROL_FUNCTION);
190 int STORE_set_ex_data(STORE *r, int idx, void *arg)
192 return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
195 void *STORE_get_ex_data(STORE *r, int idx)
197 return (CRYPTO_get_ex_data(&r->ex_data, idx));
200 const STORE_METHOD *STORE_get_method(STORE *store)
205 const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth)
213 #define check_store(s,fncode,fnname,fnerrcode) \
216 if ((s) == NULL || (s)->meth == NULL) \
218 STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
221 if ((s)->meth->fnname == NULL) \
223 STOREerr((fncode), (fnerrcode)); \
231 X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
232 OPENSSL_ITEM parameters[])
234 STORE_OBJECT *object;
237 check_store(s, STORE_F_STORE_GET_CERTIFICATE,
238 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
240 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
241 attributes, parameters);
242 if (!object || !object->data.x509.certificate) {
243 STOREerr(STORE_F_STORE_GET_CERTIFICATE,
244 STORE_R_FAILED_GETTING_CERTIFICATE);
247 X509_up_ref(object->data.x509.certificate);
249 REF_PRINT("X509", data);
251 x = object->data.x509.certificate;
252 STORE_OBJECT_free(object);
256 int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
257 OPENSSL_ITEM parameters[])
259 STORE_OBJECT *object;
262 check_store(s, STORE_F_STORE_STORE_CERTIFICATE,
263 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
265 object = STORE_OBJECT_new();
266 if (object == NULL) {
267 STOREerr(STORE_F_STORE_STORE_CERTIFICATE, ERR_R_MALLOC_FAILURE);
273 REF_PRINT("X509", data);
275 object->data.x509.certificate = data;
277 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
278 object, attributes, parameters);
280 STORE_OBJECT_free(object);
283 STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
284 STORE_R_FAILED_STORING_CERTIFICATE);
290 int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
291 OPENSSL_ITEM add_attributes[],
292 OPENSSL_ITEM modify_attributes[],
293 OPENSSL_ITEM delete_attributes[],
294 OPENSSL_ITEM parameters[])
296 check_store(s, STORE_F_STORE_MODIFY_CERTIFICATE,
297 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
299 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
300 search_attributes, add_attributes,
301 modify_attributes, delete_attributes,
303 STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
304 STORE_R_FAILED_MODIFYING_CERTIFICATE);
310 int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
311 OPENSSL_ITEM parameters[])
313 check_store(s, STORE_F_STORE_REVOKE_CERTIFICATE,
314 revoke_object, STORE_R_NO_REVOKE_OBJECT_FUNCTION);
316 if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
317 attributes, parameters)) {
318 STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE,
319 STORE_R_FAILED_REVOKING_CERTIFICATE);
325 int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[],
326 OPENSSL_ITEM parameters[])
328 check_store(s, STORE_F_STORE_DELETE_CERTIFICATE,
329 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
331 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
332 attributes, parameters)) {
333 STOREerr(STORE_F_STORE_DELETE_CERTIFICATE,
334 STORE_R_FAILED_DELETING_CERTIFICATE);
340 void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[],
341 OPENSSL_ITEM parameters[])
345 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_START,
346 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
348 handle = s->meth->list_object_start(s,
349 STORE_OBJECT_TYPE_X509_CERTIFICATE,
350 attributes, parameters);
352 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START,
353 STORE_R_FAILED_LISTING_CERTIFICATES);
359 X509 *STORE_list_certificate_next(STORE *s, void *handle)
361 STORE_OBJECT *object;
364 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_NEXT,
365 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
367 object = s->meth->list_object_next(s, handle);
368 if (!object || !object->data.x509.certificate) {
369 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT,
370 STORE_R_FAILED_LISTING_CERTIFICATES);
373 X509_up_ref(object->data.x509.certificate);
375 REF_PRINT("X509", data);
377 x = object->data.x509.certificate;
378 STORE_OBJECT_free(object);
382 int STORE_list_certificate_end(STORE *s, void *handle)
384 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_END,
385 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
387 if (!s->meth->list_object_end(s, handle)) {
388 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END,
389 STORE_R_FAILED_LISTING_CERTIFICATES);
395 int STORE_list_certificate_endp(STORE *s, void *handle)
397 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_ENDP,
398 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
400 if (!s->meth->list_object_endp(s, handle)) {
401 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP,
402 STORE_R_FAILED_LISTING_CERTIFICATES);
408 EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[],
409 OPENSSL_ITEM parameters[])
411 STORE_OBJECT *object;
414 check_store(s, STORE_F_STORE_GENERATE_KEY,
415 generate_object, STORE_R_NO_GENERATE_OBJECT_FUNCTION);
417 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
418 attributes, parameters);
419 if (!object || !object->data.key) {
420 STOREerr(STORE_F_STORE_GENERATE_KEY, STORE_R_FAILED_GENERATING_KEY);
423 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
425 REF_PRINT("EVP_PKEY", data);
427 pkey = object->data.key;
428 STORE_OBJECT_free(object);
432 EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
433 OPENSSL_ITEM parameters[])
435 STORE_OBJECT *object;
438 check_store(s, STORE_F_STORE_GET_PRIVATE_KEY,
439 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
441 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
442 attributes, parameters);
443 if (!object || !object->data.key || !object->data.key) {
444 STOREerr(STORE_F_STORE_GET_PRIVATE_KEY, STORE_R_FAILED_GETTING_KEY);
447 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
449 REF_PRINT("EVP_PKEY", data);
451 pkey = object->data.key;
452 STORE_OBJECT_free(object);
456 int STORE_store_private_key(STORE *s, EVP_PKEY *data,
457 OPENSSL_ITEM attributes[],
458 OPENSSL_ITEM parameters[])
460 STORE_OBJECT *object;
463 check_store(s, STORE_F_STORE_STORE_PRIVATE_KEY,
464 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
466 object = STORE_OBJECT_new();
467 if (object == NULL) {
468 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE);
471 object->data.key = EVP_PKEY_new();
472 if (object->data.key == NULL) {
473 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE);
477 CRYPTO_add(&data->references, 1, CRYPTO_LOCK_EVP_PKEY);
479 REF_PRINT("EVP_PKEY", data);
481 object->data.key = data;
483 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object,
484 attributes, parameters);
486 STORE_OBJECT_free(object);
489 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, STORE_R_FAILED_STORING_KEY);
495 int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
496 OPENSSL_ITEM add_attributes[],
497 OPENSSL_ITEM modify_attributes[],
498 OPENSSL_ITEM delete_attributes[],
499 OPENSSL_ITEM parameters[])
501 check_store(s, STORE_F_STORE_MODIFY_PRIVATE_KEY,
502 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
504 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
505 search_attributes, add_attributes,
506 modify_attributes, delete_attributes,
508 STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
509 STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
515 int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
516 OPENSSL_ITEM parameters[])
520 check_store(s, STORE_F_STORE_REVOKE_PRIVATE_KEY,
521 revoke_object, STORE_R_NO_REVOKE_OBJECT_FUNCTION);
523 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
524 attributes, parameters);
527 STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY,
528 STORE_R_FAILED_REVOKING_KEY);
534 int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[],
535 OPENSSL_ITEM parameters[])
537 check_store(s, STORE_F_STORE_DELETE_PRIVATE_KEY,
538 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
540 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
541 attributes, parameters)) {
542 STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY,
543 STORE_R_FAILED_DELETING_KEY);
549 void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[],
550 OPENSSL_ITEM parameters[])
554 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_START,
555 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
557 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
558 attributes, parameters);
560 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START,
561 STORE_R_FAILED_LISTING_KEYS);
567 EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle)
569 STORE_OBJECT *object;
572 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
573 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
575 object = s->meth->list_object_next(s, handle);
576 if (!object || !object->data.key || !object->data.key) {
577 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
578 STORE_R_FAILED_LISTING_KEYS);
581 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
583 REF_PRINT("EVP_PKEY", data);
585 pkey = object->data.key;
586 STORE_OBJECT_free(object);
590 int STORE_list_private_key_end(STORE *s, void *handle)
592 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_END,
593 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
595 if (!s->meth->list_object_end(s, handle)) {
596 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END,
597 STORE_R_FAILED_LISTING_KEYS);
603 int STORE_list_private_key_endp(STORE *s, void *handle)
605 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
606 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
608 if (!s->meth->list_object_endp(s, handle)) {
609 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
610 STORE_R_FAILED_LISTING_KEYS);
616 EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
617 OPENSSL_ITEM parameters[])
619 STORE_OBJECT *object;
622 check_store(s, STORE_F_STORE_GET_PUBLIC_KEY,
623 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
625 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
626 attributes, parameters);
627 if (!object || !object->data.key || !object->data.key) {
628 STOREerr(STORE_F_STORE_GET_PUBLIC_KEY, STORE_R_FAILED_GETTING_KEY);
631 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
633 REF_PRINT("EVP_PKEY", data);
635 pkey = object->data.key;
636 STORE_OBJECT_free(object);
640 int STORE_store_public_key(STORE *s, EVP_PKEY *data,
641 OPENSSL_ITEM attributes[],
642 OPENSSL_ITEM parameters[])
644 STORE_OBJECT *object;
647 check_store(s, STORE_F_STORE_STORE_PUBLIC_KEY,
648 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
650 object = STORE_OBJECT_new();
651 if (object == NULL) {
652 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE);
655 object->data.key = EVP_PKEY_new();
656 if (object->data.key == NULL) {
657 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE);
661 CRYPTO_add(&data->references, 1, CRYPTO_LOCK_EVP_PKEY);
663 REF_PRINT("EVP_PKEY", data);
665 object->data.key = data;
667 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object,
668 attributes, parameters);
670 STORE_OBJECT_free(object);
673 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, STORE_R_FAILED_STORING_KEY);
679 int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
680 OPENSSL_ITEM add_attributes[],
681 OPENSSL_ITEM modify_attributes[],
682 OPENSSL_ITEM delete_attributes[],
683 OPENSSL_ITEM parameters[])
685 check_store(s, STORE_F_STORE_MODIFY_PUBLIC_KEY,
686 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
688 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
689 search_attributes, add_attributes,
690 modify_attributes, delete_attributes,
692 STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
693 STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
699 int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
700 OPENSSL_ITEM parameters[])
704 check_store(s, STORE_F_STORE_REVOKE_PUBLIC_KEY,
705 revoke_object, STORE_R_NO_REVOKE_OBJECT_FUNCTION);
707 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
708 attributes, parameters);
711 STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY,
712 STORE_R_FAILED_REVOKING_KEY);
718 int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[],
719 OPENSSL_ITEM parameters[])
721 check_store(s, STORE_F_STORE_DELETE_PUBLIC_KEY,
722 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
724 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
725 attributes, parameters)) {
726 STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY,
727 STORE_R_FAILED_DELETING_KEY);
733 void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[],
734 OPENSSL_ITEM parameters[])
738 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_START,
739 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
741 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
742 attributes, parameters);
744 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START,
745 STORE_R_FAILED_LISTING_KEYS);
751 EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle)
753 STORE_OBJECT *object;
756 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
757 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
759 object = s->meth->list_object_next(s, handle);
760 if (!object || !object->data.key || !object->data.key) {
761 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
762 STORE_R_FAILED_LISTING_KEYS);
765 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
767 REF_PRINT("EVP_PKEY", data);
769 pkey = object->data.key;
770 STORE_OBJECT_free(object);
774 int STORE_list_public_key_end(STORE *s, void *handle)
776 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_END,
777 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
779 if (!s->meth->list_object_end(s, handle)) {
780 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END,
781 STORE_R_FAILED_LISTING_KEYS);
787 int STORE_list_public_key_endp(STORE *s, void *handle)
789 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
790 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
792 if (!s->meth->list_object_endp(s, handle)) {
793 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
794 STORE_R_FAILED_LISTING_KEYS);
800 X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
801 OPENSSL_ITEM parameters[])
803 STORE_OBJECT *object;
806 check_store(s, STORE_F_STORE_GENERATE_CRL,
807 generate_object, STORE_R_NO_GENERATE_CRL_FUNCTION);
809 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL,
810 attributes, parameters);
811 if (!object || !object->data.crl) {
812 STOREerr(STORE_F_STORE_GENERATE_CRL, STORE_R_FAILED_GENERATING_CRL);
815 X509_CRL_up_ref(object->data.crl);
817 REF_PRINT("X509_CRL", data);
819 crl = object->data.crl;
820 STORE_OBJECT_free(object);
824 X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
825 OPENSSL_ITEM parameters[])
827 STORE_OBJECT *object;
830 check_store(s, STORE_F_STORE_GET_CRL,
831 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
833 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL,
834 attributes, parameters);
835 if (!object || !object->data.crl) {
836 STOREerr(STORE_F_STORE_GET_CRL, STORE_R_FAILED_GETTING_KEY);
839 X509_CRL_up_ref(object->data.crl);
841 REF_PRINT("X509_CRL", data);
843 crl = object->data.crl;
844 STORE_OBJECT_free(object);
848 int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
849 OPENSSL_ITEM parameters[])
851 STORE_OBJECT *object;
854 check_store(s, STORE_F_STORE_STORE_CRL,
855 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
857 object = STORE_OBJECT_new();
858 if (object == NULL) {
859 STOREerr(STORE_F_STORE_STORE_CRL, ERR_R_MALLOC_FAILURE);
863 X509_CRL_up_ref(data);
865 REF_PRINT("X509_CRL", data);
867 object->data.crl = data;
869 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object,
870 attributes, parameters);
872 STORE_OBJECT_free(object);
875 STOREerr(STORE_F_STORE_STORE_CRL, STORE_R_FAILED_STORING_KEY);
881 int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
882 OPENSSL_ITEM add_attributes[],
883 OPENSSL_ITEM modify_attributes[],
884 OPENSSL_ITEM delete_attributes[],
885 OPENSSL_ITEM parameters[])
887 check_store(s, STORE_F_STORE_MODIFY_CRL,
888 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
890 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
891 search_attributes, add_attributes,
892 modify_attributes, delete_attributes,
894 STOREerr(STORE_F_STORE_MODIFY_CRL, STORE_R_FAILED_MODIFYING_CRL);
900 int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
901 OPENSSL_ITEM parameters[])
903 check_store(s, STORE_F_STORE_DELETE_CRL,
904 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
906 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL,
907 attributes, parameters)) {
908 STOREerr(STORE_F_STORE_DELETE_CRL, STORE_R_FAILED_DELETING_KEY);
914 void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[],
915 OPENSSL_ITEM parameters[])
919 check_store(s, STORE_F_STORE_LIST_CRL_START,
920 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
922 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL,
923 attributes, parameters);
925 STOREerr(STORE_F_STORE_LIST_CRL_START, STORE_R_FAILED_LISTING_KEYS);
931 X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
933 STORE_OBJECT *object;
936 check_store(s, STORE_F_STORE_LIST_CRL_NEXT,
937 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
939 object = s->meth->list_object_next(s, handle);
940 if (!object || !object->data.crl) {
941 STOREerr(STORE_F_STORE_LIST_CRL_NEXT, STORE_R_FAILED_LISTING_KEYS);
944 X509_CRL_up_ref(object->data.crl);
946 REF_PRINT("X509_CRL", data);
948 crl = object->data.crl;
949 STORE_OBJECT_free(object);
953 int STORE_list_crl_end(STORE *s, void *handle)
955 check_store(s, STORE_F_STORE_LIST_CRL_END,
956 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
958 if (!s->meth->list_object_end(s, handle)) {
959 STOREerr(STORE_F_STORE_LIST_CRL_END, STORE_R_FAILED_LISTING_KEYS);
965 int STORE_list_crl_endp(STORE *s, void *handle)
967 check_store(s, STORE_F_STORE_LIST_CRL_ENDP,
968 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
970 if (!s->meth->list_object_endp(s, handle)) {
971 STOREerr(STORE_F_STORE_LIST_CRL_ENDP, STORE_R_FAILED_LISTING_KEYS);
977 int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
978 OPENSSL_ITEM parameters[])
980 STORE_OBJECT *object;
983 check_store(s, STORE_F_STORE_STORE_NUMBER,
984 store_object, STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
986 object = STORE_OBJECT_new();
987 if (object == NULL) {
988 STOREerr(STORE_F_STORE_STORE_NUMBER, ERR_R_MALLOC_FAILURE);
992 object->data.number = data;
994 i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object,
995 attributes, parameters);
997 STORE_OBJECT_free(object);
1000 STOREerr(STORE_F_STORE_STORE_NUMBER, STORE_R_FAILED_STORING_NUMBER);
1006 int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
1007 OPENSSL_ITEM add_attributes[],
1008 OPENSSL_ITEM modify_attributes[],
1009 OPENSSL_ITEM delete_attributes[],
1010 OPENSSL_ITEM parameters[])
1012 check_store(s, STORE_F_STORE_MODIFY_NUMBER,
1013 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1015 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
1016 search_attributes, add_attributes,
1017 modify_attributes, delete_attributes,
1019 STOREerr(STORE_F_STORE_MODIFY_NUMBER,
1020 STORE_R_FAILED_MODIFYING_NUMBER);
1026 BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
1027 OPENSSL_ITEM parameters[])
1029 STORE_OBJECT *object;
1032 check_store(s, STORE_F_STORE_GET_NUMBER,
1033 get_object, STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION);
1035 object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1037 if (!object || !object->data.number) {
1038 STOREerr(STORE_F_STORE_GET_NUMBER, STORE_R_FAILED_GETTING_NUMBER);
1041 n = object->data.number;
1042 object->data.number = NULL;
1043 STORE_OBJECT_free(object);
1047 int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
1048 OPENSSL_ITEM parameters[])
1050 check_store(s, STORE_F_STORE_DELETE_NUMBER,
1051 delete_object, STORE_R_NO_DELETE_NUMBER_FUNCTION);
1053 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1055 STOREerr(STORE_F_STORE_DELETE_NUMBER, STORE_R_FAILED_DELETING_NUMBER);
1061 int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
1062 OPENSSL_ITEM parameters[])
1064 STORE_OBJECT *object;
1067 check_store(s, STORE_F_STORE_STORE_ARBITRARY,
1068 store_object, STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
1070 object = STORE_OBJECT_new();
1071 if (object == NULL) {
1072 STOREerr(STORE_F_STORE_STORE_ARBITRARY, ERR_R_MALLOC_FAILURE);
1076 object->data.arbitrary = data;
1078 i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object,
1079 attributes, parameters);
1081 STORE_OBJECT_free(object);
1084 STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1085 STORE_R_FAILED_STORING_ARBITRARY);
1091 int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
1092 OPENSSL_ITEM add_attributes[],
1093 OPENSSL_ITEM modify_attributes[],
1094 OPENSSL_ITEM delete_attributes[],
1095 OPENSSL_ITEM parameters[])
1097 check_store(s, STORE_F_STORE_MODIFY_ARBITRARY,
1098 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1100 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1101 search_attributes, add_attributes,
1102 modify_attributes, delete_attributes,
1104 STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
1105 STORE_R_FAILED_MODIFYING_ARBITRARY);
1111 BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1112 OPENSSL_ITEM parameters[])
1114 STORE_OBJECT *object;
1117 check_store(s, STORE_F_STORE_GET_ARBITRARY,
1118 get_object, STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION);
1120 object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1121 attributes, parameters);
1122 if (!object || !object->data.arbitrary) {
1123 STOREerr(STORE_F_STORE_GET_ARBITRARY,
1124 STORE_R_FAILED_GETTING_ARBITRARY);
1127 b = object->data.arbitrary;
1128 object->data.arbitrary = NULL;
1129 STORE_OBJECT_free(object);
1133 int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1134 OPENSSL_ITEM parameters[])
1136 check_store(s, STORE_F_STORE_DELETE_ARBITRARY,
1137 delete_object, STORE_R_NO_DELETE_ARBITRARY_FUNCTION);
1139 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes,
1141 STOREerr(STORE_F_STORE_DELETE_ARBITRARY,
1142 STORE_R_FAILED_DELETING_ARBITRARY);
1148 STORE_OBJECT *STORE_OBJECT_new(void)
1150 STORE_OBJECT *object = OPENSSL_zalloc(sizeof(*object));
1154 void STORE_OBJECT_free(STORE_OBJECT *data)
1158 switch (data->type) {
1159 case STORE_OBJECT_TYPE_X509_CERTIFICATE:
1160 X509_free(data->data.x509.certificate);
1162 case STORE_OBJECT_TYPE_X509_CRL:
1163 X509_CRL_free(data->data.crl);
1165 case STORE_OBJECT_TYPE_PRIVATE_KEY:
1166 case STORE_OBJECT_TYPE_PUBLIC_KEY:
1167 EVP_PKEY_free(data->data.key);
1169 case STORE_OBJECT_TYPE_NUMBER:
1170 BN_free(data->data.number);
1172 case STORE_OBJECT_TYPE_ARBITRARY:
1173 BUF_MEM_free(data->data.arbitrary);
1179 struct STORE_attr_info_st {
1180 unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
1183 unsigned char *sha1string;
1187 } values[STORE_ATTR_TYPE_NUM + 1];
1188 size_t value_sizes[STORE_ATTR_TYPE_NUM + 1];
1191 #define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1192 && ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1193 #define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1194 #define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1196 STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1198 STORE_ATTR_INFO *p = OPENSSL_malloc(sizeof(*p));
1203 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1204 STORE_ATTR_TYPES code)
1206 if (ATTR_IS_SET(attrs, code)) {
1208 case STORE_ATTR_FRIENDLYNAME:
1209 case STORE_ATTR_EMAIL:
1210 case STORE_ATTR_FILENAME:
1211 STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0);
1213 case STORE_ATTR_KEYID:
1214 case STORE_ATTR_ISSUERKEYID:
1215 case STORE_ATTR_SUBJECTKEYID:
1216 case STORE_ATTR_ISSUERSERIALHASH:
1217 case STORE_ATTR_CERTHASH:
1218 STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0);
1220 case STORE_ATTR_ISSUER:
1221 case STORE_ATTR_SUBJECT:
1222 STORE_ATTR_INFO_modify_dn(attrs, code, NULL);
1224 case STORE_ATTR_SERIAL:
1225 STORE_ATTR_INFO_modify_number(attrs, code, NULL);
1233 int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1237 for (i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1238 STORE_ATTR_INFO_attr_free(attrs, i);
1239 OPENSSL_free(attrs);
1244 char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1247 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1248 ERR_R_PASSED_NULL_PARAMETER);
1251 if (ATTR_IS_SET(attrs, code))
1252 return attrs->values[code].cstring;
1253 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR, STORE_R_NO_VALUE);
1257 unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
1258 STORE_ATTR_TYPES code)
1261 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1262 ERR_R_PASSED_NULL_PARAMETER);
1265 if (ATTR_IS_SET(attrs, code))
1266 return attrs->values[code].sha1string;
1267 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR, STORE_R_NO_VALUE);
1271 X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs,
1272 STORE_ATTR_TYPES code)
1275 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1276 ERR_R_PASSED_NULL_PARAMETER);
1279 if (ATTR_IS_SET(attrs, code))
1280 return attrs->values[code].dn;
1281 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN, STORE_R_NO_VALUE);
1285 BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs,
1286 STORE_ATTR_TYPES code)
1289 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1290 ERR_R_PASSED_NULL_PARAMETER);
1293 if (ATTR_IS_SET(attrs, code))
1294 return attrs->values[code].number;
1295 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER, STORE_R_NO_VALUE);
1299 int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1300 char *cstr, size_t cstr_size)
1303 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1304 ERR_R_PASSED_NULL_PARAMETER);
1307 if (!ATTR_IS_SET(attrs, code)) {
1308 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size)))
1310 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_MALLOC_FAILURE);
1313 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE);
1317 int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1318 unsigned char *sha1str, size_t sha1str_size)
1321 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1322 ERR_R_PASSED_NULL_PARAMETER);
1325 if (!ATTR_IS_SET(attrs, code)) {
1326 if ((attrs->values[code].sha1string =
1327 (unsigned char *)BUF_memdup(sha1str, sha1str_size)))
1329 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, ERR_R_MALLOC_FAILURE);
1332 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1333 STORE_R_ALREADY_HAS_A_VALUE);
1337 int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1341 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, ERR_R_PASSED_NULL_PARAMETER);
1344 if (!ATTR_IS_SET(attrs, code)) {
1345 if ((attrs->values[code].dn = X509_NAME_dup(dn)))
1347 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, ERR_R_MALLOC_FAILURE);
1350 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE);
1354 int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1358 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1359 ERR_R_PASSED_NULL_PARAMETER);
1362 if (!ATTR_IS_SET(attrs, code)) {
1363 if ((attrs->values[code].number = BN_dup(number)))
1365 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, ERR_R_MALLOC_FAILURE);
1368 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE);
1372 int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1373 char *cstr, size_t cstr_size)
1376 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR,
1377 ERR_R_PASSED_NULL_PARAMETER);
1380 if (ATTR_IS_SET(attrs, code)) {
1381 OPENSSL_free(attrs->values[code].cstring);
1382 attrs->values[code].cstring = NULL;
1383 CLEAR_ATTRBIT(attrs, code);
1385 return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size);
1388 int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs,
1389 STORE_ATTR_TYPES code,
1390 unsigned char *sha1str,
1391 size_t sha1str_size)
1394 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR,
1395 ERR_R_PASSED_NULL_PARAMETER);
1398 if (ATTR_IS_SET(attrs, code)) {
1399 OPENSSL_free(attrs->values[code].sha1string);
1400 attrs->values[code].sha1string = NULL;
1401 CLEAR_ATTRBIT(attrs, code);
1403 return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size);
1406 int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1410 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN,
1411 ERR_R_PASSED_NULL_PARAMETER);
1414 if (ATTR_IS_SET(attrs, code)) {
1415 OPENSSL_free(attrs->values[code].dn);
1416 attrs->values[code].dn = NULL;
1417 CLEAR_ATTRBIT(attrs, code);
1419 return STORE_ATTR_INFO_set_dn(attrs, code, dn);
1422 int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs,
1423 STORE_ATTR_TYPES code, BIGNUM *number)
1426 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER,
1427 ERR_R_PASSED_NULL_PARAMETER);
1430 if (ATTR_IS_SET(attrs, code)) {
1431 OPENSSL_free(attrs->values[code].number);
1432 attrs->values[code].number = NULL;
1433 CLEAR_ATTRBIT(attrs, code);
1435 return STORE_ATTR_INFO_set_number(attrs, code, number);
1438 struct attr_list_ctx_st {
1439 OPENSSL_ITEM *attributes;
1441 void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1444 struct attr_list_ctx_st *context = OPENSSL_malloc(sizeof(*context));
1445 if (context != NULL)
1446 context->attributes = attributes;
1448 STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_MALLOC_FAILURE);
1451 STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER);
1455 STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
1457 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1459 if (context && context->attributes) {
1460 STORE_ATTR_INFO *attrs = NULL;
1462 while (context->attributes
1463 && context->attributes->code != STORE_ATTR_OR
1464 && context->attributes->code != STORE_ATTR_END) {
1465 switch (context->attributes->code) {
1466 case STORE_ATTR_FRIENDLYNAME:
1467 case STORE_ATTR_EMAIL:
1468 case STORE_ATTR_FILENAME:
1470 attrs = STORE_ATTR_INFO_new();
1471 if (attrs == NULL) {
1472 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1473 ERR_R_MALLOC_FAILURE);
1476 STORE_ATTR_INFO_set_cstr(attrs,
1477 context->attributes->code,
1478 context->attributes->value,
1479 context->attributes->value_size);
1481 case STORE_ATTR_KEYID:
1482 case STORE_ATTR_ISSUERKEYID:
1483 case STORE_ATTR_SUBJECTKEYID:
1484 case STORE_ATTR_ISSUERSERIALHASH:
1485 case STORE_ATTR_CERTHASH:
1487 attrs = STORE_ATTR_INFO_new();
1488 if (attrs == NULL) {
1489 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1490 ERR_R_MALLOC_FAILURE);
1493 STORE_ATTR_INFO_set_sha1str(attrs,
1494 context->attributes->code,
1495 context->attributes->value,
1496 context->attributes->value_size);
1498 case STORE_ATTR_ISSUER:
1499 case STORE_ATTR_SUBJECT:
1501 attrs = STORE_ATTR_INFO_new();
1502 if (attrs == NULL) {
1503 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1504 ERR_R_MALLOC_FAILURE);
1507 STORE_ATTR_INFO_modify_dn(attrs,
1508 context->attributes->code,
1509 context->attributes->value);
1511 case STORE_ATTR_SERIAL:
1513 attrs = STORE_ATTR_INFO_new();
1514 if (attrs == NULL) {
1515 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1516 ERR_R_MALLOC_FAILURE);
1519 STORE_ATTR_INFO_modify_number(attrs,
1520 context->attributes->code,
1521 context->attributes->value);
1524 context->attributes++;
1526 if (context->attributes->code == STORE_ATTR_OR)
1527 context->attributes++;
1530 while (context->attributes
1531 && context->attributes->code != STORE_ATTR_OR
1532 && context->attributes->code != STORE_ATTR_END)
1533 context->attributes++;
1534 if (context->attributes->code == STORE_ATTR_OR)
1535 context->attributes++;
1538 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER);
1542 int STORE_parse_attrs_end(void *handle)
1544 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1546 if (context && context->attributes) {
1548 OPENSSL_ITEM *attributes = context->attributes;
1550 OPENSSL_free(context);
1553 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1557 int STORE_parse_attrs_endp(void *handle)
1559 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1561 if (context && context->attributes) {
1562 return context->attributes->code == STORE_ATTR_END;
1564 STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER);
1568 static int attr_info_compare_compute_range(const unsigned char *abits,
1569 const unsigned char *bbits,
1570 unsigned int *alowp,
1571 unsigned int *ahighp,
1572 unsigned int *blowp,
1573 unsigned int *bhighp)
1575 unsigned int alow = (unsigned int)-1, ahigh = 0;
1576 unsigned int blow = (unsigned int)-1, bhigh = 0;
1579 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++) {
1581 if (*abits < *bbits)
1583 if (*abits > *bbits)
1587 if (alow == (unsigned int)-1) {
1589 if (!(*abits & 0x01))
1591 if (!(*abits & 0x02))
1593 if (!(*abits & 0x04))
1595 if (!(*abits & 0x08))
1597 if (!(*abits & 0x10))
1599 if (!(*abits & 0x20))
1601 if (!(*abits & 0x40))
1605 if (!(*abits & 0x80))
1607 if (!(*abits & 0x40))
1609 if (!(*abits & 0x20))
1611 if (!(*abits & 0x10))
1613 if (!(*abits & 0x08))
1615 if (!(*abits & 0x04))
1617 if (!(*abits & 0x02))
1621 if (blow == (unsigned int)-1) {
1623 if (!(*bbits & 0x01))
1625 if (!(*bbits & 0x02))
1627 if (!(*bbits & 0x04))
1629 if (!(*bbits & 0x08))
1631 if (!(*bbits & 0x10))
1633 if (!(*bbits & 0x20))
1635 if (!(*bbits & 0x40))
1639 if (!(*bbits & 0x80))
1641 if (!(*bbits & 0x40))
1643 if (!(*bbits & 0x20))
1645 if (!(*bbits & 0x10))
1647 if (!(*bbits & 0x08))
1649 if (!(*bbits & 0x04))
1651 if (!(*bbits & 0x02))
1655 if (ahigh + alow < bhigh + blow)
1657 if (ahigh + alow > bhigh + blow)
1670 int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO *const *a,
1671 const STORE_ATTR_INFO *const *b)
1679 return attr_info_compare_compute_range((*a)->set, (*b)->set, 0, 0, 0, 0);
1682 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1684 unsigned int alow, ahigh, blow, bhigh;
1692 attr_info_compare_compute_range(a->set, b->set,
1693 &alow, &ahigh, &blow, &bhigh);
1694 if (alow >= blow && ahigh <= bhigh)
1699 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1701 unsigned char *abits, *bbits;
1712 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++) {
1713 if (*abits && (*bbits & *abits) != *abits)
1719 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1725 if (!STORE_ATTR_INFO_in(a, b))
1727 for (i = 1; i < STORE_ATTR_TYPE_NUM; i++)
1728 if (ATTR_IS_SET(a, i)) {
1730 case STORE_ATTR_FRIENDLYNAME:
1731 case STORE_ATTR_EMAIL:
1732 case STORE_ATTR_FILENAME:
1733 if (strcmp(a->values[i].cstring, b->values[i].cstring))
1736 case STORE_ATTR_KEYID:
1737 case STORE_ATTR_ISSUERKEYID:
1738 case STORE_ATTR_SUBJECTKEYID:
1739 case STORE_ATTR_ISSUERSERIALHASH:
1740 case STORE_ATTR_CERTHASH:
1741 if (memcmp(a->values[i].sha1string,
1742 b->values[i].sha1string, a->value_sizes[i]))
1745 case STORE_ATTR_ISSUER:
1746 case STORE_ATTR_SUBJECT:
1747 if (X509_NAME_cmp(a->values[i].dn, b->values[i].dn))
1750 case STORE_ATTR_SERIAL:
1751 if (BN_cmp(a->values[i].number, b->values[i].number))