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_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
191 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
193 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE, argl, argp,
194 new_func, dup_func, free_func);
197 int STORE_set_ex_data(STORE *r, int idx, void *arg)
199 return (CRYPTO_set_ex_data(&r->ex_data, idx, arg));
202 void *STORE_get_ex_data(STORE *r, int idx)
204 return (CRYPTO_get_ex_data(&r->ex_data, idx));
207 const STORE_METHOD *STORE_get_method(STORE *store)
212 const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth)
220 #define check_store(s,fncode,fnname,fnerrcode) \
223 if ((s) == NULL || (s)->meth == NULL) \
225 STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
228 if ((s)->meth->fnname == NULL) \
230 STOREerr((fncode), (fnerrcode)); \
238 X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
239 OPENSSL_ITEM parameters[])
241 STORE_OBJECT *object;
244 check_store(s, STORE_F_STORE_GET_CERTIFICATE,
245 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
247 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
248 attributes, parameters);
249 if (!object || !object->data.x509.certificate) {
250 STOREerr(STORE_F_STORE_GET_CERTIFICATE,
251 STORE_R_FAILED_GETTING_CERTIFICATE);
254 X509_up_ref(object->data.x509.certificate);
256 REF_PRINT("X509", data);
258 x = object->data.x509.certificate;
259 STORE_OBJECT_free(object);
263 int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
264 OPENSSL_ITEM parameters[])
266 STORE_OBJECT *object;
269 check_store(s, STORE_F_STORE_STORE_CERTIFICATE,
270 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
272 object = STORE_OBJECT_new();
273 if (object == NULL) {
274 STOREerr(STORE_F_STORE_STORE_CERTIFICATE, ERR_R_MALLOC_FAILURE);
280 REF_PRINT("X509", data);
282 object->data.x509.certificate = data;
284 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
285 object, attributes, parameters);
287 STORE_OBJECT_free(object);
290 STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
291 STORE_R_FAILED_STORING_CERTIFICATE);
297 int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
298 OPENSSL_ITEM add_attributes[],
299 OPENSSL_ITEM modify_attributes[],
300 OPENSSL_ITEM delete_attributes[],
301 OPENSSL_ITEM parameters[])
303 check_store(s, STORE_F_STORE_MODIFY_CERTIFICATE,
304 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
306 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
307 search_attributes, add_attributes,
308 modify_attributes, delete_attributes,
310 STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
311 STORE_R_FAILED_MODIFYING_CERTIFICATE);
317 int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
318 OPENSSL_ITEM parameters[])
320 check_store(s, STORE_F_STORE_REVOKE_CERTIFICATE,
321 revoke_object, STORE_R_NO_REVOKE_OBJECT_FUNCTION);
323 if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
324 attributes, parameters)) {
325 STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE,
326 STORE_R_FAILED_REVOKING_CERTIFICATE);
332 int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[],
333 OPENSSL_ITEM parameters[])
335 check_store(s, STORE_F_STORE_DELETE_CERTIFICATE,
336 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
338 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
339 attributes, parameters)) {
340 STOREerr(STORE_F_STORE_DELETE_CERTIFICATE,
341 STORE_R_FAILED_DELETING_CERTIFICATE);
347 void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[],
348 OPENSSL_ITEM parameters[])
352 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_START,
353 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
355 handle = s->meth->list_object_start(s,
356 STORE_OBJECT_TYPE_X509_CERTIFICATE,
357 attributes, parameters);
359 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START,
360 STORE_R_FAILED_LISTING_CERTIFICATES);
366 X509 *STORE_list_certificate_next(STORE *s, void *handle)
368 STORE_OBJECT *object;
371 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_NEXT,
372 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
374 object = s->meth->list_object_next(s, handle);
375 if (!object || !object->data.x509.certificate) {
376 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT,
377 STORE_R_FAILED_LISTING_CERTIFICATES);
380 X509_up_ref(object->data.x509.certificate);
382 REF_PRINT("X509", data);
384 x = object->data.x509.certificate;
385 STORE_OBJECT_free(object);
389 int STORE_list_certificate_end(STORE *s, void *handle)
391 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_END,
392 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
394 if (!s->meth->list_object_end(s, handle)) {
395 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END,
396 STORE_R_FAILED_LISTING_CERTIFICATES);
402 int STORE_list_certificate_endp(STORE *s, void *handle)
404 check_store(s, STORE_F_STORE_LIST_CERTIFICATE_ENDP,
405 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
407 if (!s->meth->list_object_endp(s, handle)) {
408 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP,
409 STORE_R_FAILED_LISTING_CERTIFICATES);
415 EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[],
416 OPENSSL_ITEM parameters[])
418 STORE_OBJECT *object;
421 check_store(s, STORE_F_STORE_GENERATE_KEY,
422 generate_object, STORE_R_NO_GENERATE_OBJECT_FUNCTION);
424 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
425 attributes, parameters);
426 if (!object || !object->data.key) {
427 STOREerr(STORE_F_STORE_GENERATE_KEY, STORE_R_FAILED_GENERATING_KEY);
430 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
432 REF_PRINT("EVP_PKEY", data);
434 pkey = object->data.key;
435 STORE_OBJECT_free(object);
439 EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
440 OPENSSL_ITEM parameters[])
442 STORE_OBJECT *object;
445 check_store(s, STORE_F_STORE_GET_PRIVATE_KEY,
446 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
448 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
449 attributes, parameters);
450 if (!object || !object->data.key || !object->data.key) {
451 STOREerr(STORE_F_STORE_GET_PRIVATE_KEY, STORE_R_FAILED_GETTING_KEY);
454 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
456 REF_PRINT("EVP_PKEY", data);
458 pkey = object->data.key;
459 STORE_OBJECT_free(object);
463 int STORE_store_private_key(STORE *s, EVP_PKEY *data,
464 OPENSSL_ITEM attributes[],
465 OPENSSL_ITEM parameters[])
467 STORE_OBJECT *object;
470 check_store(s, STORE_F_STORE_STORE_PRIVATE_KEY,
471 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
473 object = STORE_OBJECT_new();
474 if (object == NULL) {
475 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE);
478 object->data.key = EVP_PKEY_new();
479 if (object->data.key == NULL) {
480 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, ERR_R_MALLOC_FAILURE);
484 CRYPTO_add(&data->references, 1, CRYPTO_LOCK_EVP_PKEY);
486 REF_PRINT("EVP_PKEY", data);
488 object->data.key = data;
490 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object,
491 attributes, parameters);
493 STORE_OBJECT_free(object);
496 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY, STORE_R_FAILED_STORING_KEY);
502 int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
503 OPENSSL_ITEM add_attributes[],
504 OPENSSL_ITEM modify_attributes[],
505 OPENSSL_ITEM delete_attributes[],
506 OPENSSL_ITEM parameters[])
508 check_store(s, STORE_F_STORE_MODIFY_PRIVATE_KEY,
509 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
511 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
512 search_attributes, add_attributes,
513 modify_attributes, delete_attributes,
515 STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
516 STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
522 int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
523 OPENSSL_ITEM parameters[])
527 check_store(s, STORE_F_STORE_REVOKE_PRIVATE_KEY,
528 revoke_object, STORE_R_NO_REVOKE_OBJECT_FUNCTION);
530 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
531 attributes, parameters);
534 STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY,
535 STORE_R_FAILED_REVOKING_KEY);
541 int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[],
542 OPENSSL_ITEM parameters[])
544 check_store(s, STORE_F_STORE_DELETE_PRIVATE_KEY,
545 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
547 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
548 attributes, parameters)) {
549 STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY,
550 STORE_R_FAILED_DELETING_KEY);
556 void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[],
557 OPENSSL_ITEM parameters[])
561 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_START,
562 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
564 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
565 attributes, parameters);
567 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START,
568 STORE_R_FAILED_LISTING_KEYS);
574 EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle)
576 STORE_OBJECT *object;
579 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
580 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
582 object = s->meth->list_object_next(s, handle);
583 if (!object || !object->data.key || !object->data.key) {
584 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
585 STORE_R_FAILED_LISTING_KEYS);
588 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
590 REF_PRINT("EVP_PKEY", data);
592 pkey = object->data.key;
593 STORE_OBJECT_free(object);
597 int STORE_list_private_key_end(STORE *s, void *handle)
599 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_END,
600 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
602 if (!s->meth->list_object_end(s, handle)) {
603 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END,
604 STORE_R_FAILED_LISTING_KEYS);
610 int STORE_list_private_key_endp(STORE *s, void *handle)
612 check_store(s, STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
613 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
615 if (!s->meth->list_object_endp(s, handle)) {
616 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
617 STORE_R_FAILED_LISTING_KEYS);
623 EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
624 OPENSSL_ITEM parameters[])
626 STORE_OBJECT *object;
629 check_store(s, STORE_F_STORE_GET_PUBLIC_KEY,
630 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
632 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
633 attributes, parameters);
634 if (!object || !object->data.key || !object->data.key) {
635 STOREerr(STORE_F_STORE_GET_PUBLIC_KEY, STORE_R_FAILED_GETTING_KEY);
638 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
640 REF_PRINT("EVP_PKEY", data);
642 pkey = object->data.key;
643 STORE_OBJECT_free(object);
647 int STORE_store_public_key(STORE *s, EVP_PKEY *data,
648 OPENSSL_ITEM attributes[],
649 OPENSSL_ITEM parameters[])
651 STORE_OBJECT *object;
654 check_store(s, STORE_F_STORE_STORE_PUBLIC_KEY,
655 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
657 object = STORE_OBJECT_new();
658 if (object == NULL) {
659 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE);
662 object->data.key = EVP_PKEY_new();
663 if (object->data.key == NULL) {
664 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, ERR_R_MALLOC_FAILURE);
668 CRYPTO_add(&data->references, 1, CRYPTO_LOCK_EVP_PKEY);
670 REF_PRINT("EVP_PKEY", data);
672 object->data.key = data;
674 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object,
675 attributes, parameters);
677 STORE_OBJECT_free(object);
680 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY, STORE_R_FAILED_STORING_KEY);
686 int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
687 OPENSSL_ITEM add_attributes[],
688 OPENSSL_ITEM modify_attributes[],
689 OPENSSL_ITEM delete_attributes[],
690 OPENSSL_ITEM parameters[])
692 check_store(s, STORE_F_STORE_MODIFY_PUBLIC_KEY,
693 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
695 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
696 search_attributes, add_attributes,
697 modify_attributes, delete_attributes,
699 STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
700 STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
706 int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
707 OPENSSL_ITEM parameters[])
711 check_store(s, STORE_F_STORE_REVOKE_PUBLIC_KEY,
712 revoke_object, STORE_R_NO_REVOKE_OBJECT_FUNCTION);
714 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
715 attributes, parameters);
718 STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY,
719 STORE_R_FAILED_REVOKING_KEY);
725 int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[],
726 OPENSSL_ITEM parameters[])
728 check_store(s, STORE_F_STORE_DELETE_PUBLIC_KEY,
729 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
731 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
732 attributes, parameters)) {
733 STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY,
734 STORE_R_FAILED_DELETING_KEY);
740 void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[],
741 OPENSSL_ITEM parameters[])
745 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_START,
746 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
748 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
749 attributes, parameters);
751 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START,
752 STORE_R_FAILED_LISTING_KEYS);
758 EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle)
760 STORE_OBJECT *object;
763 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
764 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
766 object = s->meth->list_object_next(s, handle);
767 if (!object || !object->data.key || !object->data.key) {
768 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
769 STORE_R_FAILED_LISTING_KEYS);
772 CRYPTO_add(&object->data.key->references, 1, CRYPTO_LOCK_EVP_PKEY);
774 REF_PRINT("EVP_PKEY", data);
776 pkey = object->data.key;
777 STORE_OBJECT_free(object);
781 int STORE_list_public_key_end(STORE *s, void *handle)
783 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_END,
784 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
786 if (!s->meth->list_object_end(s, handle)) {
787 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END,
788 STORE_R_FAILED_LISTING_KEYS);
794 int STORE_list_public_key_endp(STORE *s, void *handle)
796 check_store(s, STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
797 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
799 if (!s->meth->list_object_endp(s, handle)) {
800 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
801 STORE_R_FAILED_LISTING_KEYS);
807 X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
808 OPENSSL_ITEM parameters[])
810 STORE_OBJECT *object;
813 check_store(s, STORE_F_STORE_GENERATE_CRL,
814 generate_object, STORE_R_NO_GENERATE_CRL_FUNCTION);
816 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL,
817 attributes, parameters);
818 if (!object || !object->data.crl) {
819 STOREerr(STORE_F_STORE_GENERATE_CRL, STORE_R_FAILED_GENERATING_CRL);
822 X509_CRL_up_ref(object->data.crl);
824 REF_PRINT("X509_CRL", data);
826 crl = object->data.crl;
827 STORE_OBJECT_free(object);
831 X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
832 OPENSSL_ITEM parameters[])
834 STORE_OBJECT *object;
837 check_store(s, STORE_F_STORE_GET_CRL,
838 get_object, STORE_R_NO_GET_OBJECT_FUNCTION);
840 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL,
841 attributes, parameters);
842 if (!object || !object->data.crl) {
843 STOREerr(STORE_F_STORE_GET_CRL, STORE_R_FAILED_GETTING_KEY);
846 X509_CRL_up_ref(object->data.crl);
848 REF_PRINT("X509_CRL", data);
850 crl = object->data.crl;
851 STORE_OBJECT_free(object);
855 int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
856 OPENSSL_ITEM parameters[])
858 STORE_OBJECT *object;
861 check_store(s, STORE_F_STORE_STORE_CRL,
862 store_object, STORE_R_NO_STORE_OBJECT_FUNCTION);
864 object = STORE_OBJECT_new();
865 if (object == NULL) {
866 STOREerr(STORE_F_STORE_STORE_CRL, ERR_R_MALLOC_FAILURE);
870 X509_CRL_up_ref(data);
872 REF_PRINT("X509_CRL", data);
874 object->data.crl = data;
876 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object,
877 attributes, parameters);
879 STORE_OBJECT_free(object);
882 STOREerr(STORE_F_STORE_STORE_CRL, STORE_R_FAILED_STORING_KEY);
888 int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
889 OPENSSL_ITEM add_attributes[],
890 OPENSSL_ITEM modify_attributes[],
891 OPENSSL_ITEM delete_attributes[],
892 OPENSSL_ITEM parameters[])
894 check_store(s, STORE_F_STORE_MODIFY_CRL,
895 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
897 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
898 search_attributes, add_attributes,
899 modify_attributes, delete_attributes,
901 STOREerr(STORE_F_STORE_MODIFY_CRL, STORE_R_FAILED_MODIFYING_CRL);
907 int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
908 OPENSSL_ITEM parameters[])
910 check_store(s, STORE_F_STORE_DELETE_CRL,
911 delete_object, STORE_R_NO_DELETE_OBJECT_FUNCTION);
913 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL,
914 attributes, parameters)) {
915 STOREerr(STORE_F_STORE_DELETE_CRL, STORE_R_FAILED_DELETING_KEY);
921 void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[],
922 OPENSSL_ITEM parameters[])
926 check_store(s, STORE_F_STORE_LIST_CRL_START,
927 list_object_start, STORE_R_NO_LIST_OBJECT_START_FUNCTION);
929 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL,
930 attributes, parameters);
932 STOREerr(STORE_F_STORE_LIST_CRL_START, STORE_R_FAILED_LISTING_KEYS);
938 X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
940 STORE_OBJECT *object;
943 check_store(s, STORE_F_STORE_LIST_CRL_NEXT,
944 list_object_next, STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
946 object = s->meth->list_object_next(s, handle);
947 if (!object || !object->data.crl) {
948 STOREerr(STORE_F_STORE_LIST_CRL_NEXT, STORE_R_FAILED_LISTING_KEYS);
951 X509_CRL_up_ref(object->data.crl);
953 REF_PRINT("X509_CRL", data);
955 crl = object->data.crl;
956 STORE_OBJECT_free(object);
960 int STORE_list_crl_end(STORE *s, void *handle)
962 check_store(s, STORE_F_STORE_LIST_CRL_END,
963 list_object_end, STORE_R_NO_LIST_OBJECT_END_FUNCTION);
965 if (!s->meth->list_object_end(s, handle)) {
966 STOREerr(STORE_F_STORE_LIST_CRL_END, STORE_R_FAILED_LISTING_KEYS);
972 int STORE_list_crl_endp(STORE *s, void *handle)
974 check_store(s, STORE_F_STORE_LIST_CRL_ENDP,
975 list_object_endp, STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
977 if (!s->meth->list_object_endp(s, handle)) {
978 STOREerr(STORE_F_STORE_LIST_CRL_ENDP, STORE_R_FAILED_LISTING_KEYS);
984 int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
985 OPENSSL_ITEM parameters[])
987 STORE_OBJECT *object;
990 check_store(s, STORE_F_STORE_STORE_NUMBER,
991 store_object, STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
993 object = STORE_OBJECT_new();
994 if (object == NULL) {
995 STOREerr(STORE_F_STORE_STORE_NUMBER, ERR_R_MALLOC_FAILURE);
999 object->data.number = data;
1001 i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object,
1002 attributes, parameters);
1004 STORE_OBJECT_free(object);
1007 STOREerr(STORE_F_STORE_STORE_NUMBER, STORE_R_FAILED_STORING_NUMBER);
1013 int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
1014 OPENSSL_ITEM add_attributes[],
1015 OPENSSL_ITEM modify_attributes[],
1016 OPENSSL_ITEM delete_attributes[],
1017 OPENSSL_ITEM parameters[])
1019 check_store(s, STORE_F_STORE_MODIFY_NUMBER,
1020 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1022 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
1023 search_attributes, add_attributes,
1024 modify_attributes, delete_attributes,
1026 STOREerr(STORE_F_STORE_MODIFY_NUMBER,
1027 STORE_R_FAILED_MODIFYING_NUMBER);
1033 BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
1034 OPENSSL_ITEM parameters[])
1036 STORE_OBJECT *object;
1039 check_store(s, STORE_F_STORE_GET_NUMBER,
1040 get_object, STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION);
1042 object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1044 if (!object || !object->data.number) {
1045 STOREerr(STORE_F_STORE_GET_NUMBER, STORE_R_FAILED_GETTING_NUMBER);
1048 n = object->data.number;
1049 object->data.number = NULL;
1050 STORE_OBJECT_free(object);
1054 int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
1055 OPENSSL_ITEM parameters[])
1057 check_store(s, STORE_F_STORE_DELETE_NUMBER,
1058 delete_object, STORE_R_NO_DELETE_NUMBER_FUNCTION);
1060 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1062 STOREerr(STORE_F_STORE_DELETE_NUMBER, STORE_R_FAILED_DELETING_NUMBER);
1068 int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
1069 OPENSSL_ITEM parameters[])
1071 STORE_OBJECT *object;
1074 check_store(s, STORE_F_STORE_STORE_ARBITRARY,
1075 store_object, STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
1077 object = STORE_OBJECT_new();
1078 if (object == NULL) {
1079 STOREerr(STORE_F_STORE_STORE_ARBITRARY, ERR_R_MALLOC_FAILURE);
1083 object->data.arbitrary = data;
1085 i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object,
1086 attributes, parameters);
1088 STORE_OBJECT_free(object);
1091 STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1092 STORE_R_FAILED_STORING_ARBITRARY);
1098 int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
1099 OPENSSL_ITEM add_attributes[],
1100 OPENSSL_ITEM modify_attributes[],
1101 OPENSSL_ITEM delete_attributes[],
1102 OPENSSL_ITEM parameters[])
1104 check_store(s, STORE_F_STORE_MODIFY_ARBITRARY,
1105 modify_object, STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1107 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1108 search_attributes, add_attributes,
1109 modify_attributes, delete_attributes,
1111 STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
1112 STORE_R_FAILED_MODIFYING_ARBITRARY);
1118 BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1119 OPENSSL_ITEM parameters[])
1121 STORE_OBJECT *object;
1124 check_store(s, STORE_F_STORE_GET_ARBITRARY,
1125 get_object, STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION);
1127 object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1128 attributes, parameters);
1129 if (!object || !object->data.arbitrary) {
1130 STOREerr(STORE_F_STORE_GET_ARBITRARY,
1131 STORE_R_FAILED_GETTING_ARBITRARY);
1134 b = object->data.arbitrary;
1135 object->data.arbitrary = NULL;
1136 STORE_OBJECT_free(object);
1140 int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1141 OPENSSL_ITEM parameters[])
1143 check_store(s, STORE_F_STORE_DELETE_ARBITRARY,
1144 delete_object, STORE_R_NO_DELETE_ARBITRARY_FUNCTION);
1146 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes,
1148 STOREerr(STORE_F_STORE_DELETE_ARBITRARY,
1149 STORE_R_FAILED_DELETING_ARBITRARY);
1155 STORE_OBJECT *STORE_OBJECT_new(void)
1157 STORE_OBJECT *object = OPENSSL_zalloc(sizeof(*object));
1161 void STORE_OBJECT_free(STORE_OBJECT *data)
1165 switch (data->type) {
1166 case STORE_OBJECT_TYPE_X509_CERTIFICATE:
1167 X509_free(data->data.x509.certificate);
1169 case STORE_OBJECT_TYPE_X509_CRL:
1170 X509_CRL_free(data->data.crl);
1172 case STORE_OBJECT_TYPE_PRIVATE_KEY:
1173 case STORE_OBJECT_TYPE_PUBLIC_KEY:
1174 EVP_PKEY_free(data->data.key);
1176 case STORE_OBJECT_TYPE_NUMBER:
1177 BN_free(data->data.number);
1179 case STORE_OBJECT_TYPE_ARBITRARY:
1180 BUF_MEM_free(data->data.arbitrary);
1186 struct STORE_attr_info_st {
1187 unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
1190 unsigned char *sha1string;
1194 } values[STORE_ATTR_TYPE_NUM + 1];
1195 size_t value_sizes[STORE_ATTR_TYPE_NUM + 1];
1198 #define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1199 && ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1200 #define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1201 #define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1203 STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1205 STORE_ATTR_INFO *p = OPENSSL_malloc(sizeof(*p));
1210 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1211 STORE_ATTR_TYPES code)
1213 if (ATTR_IS_SET(attrs, code)) {
1215 case STORE_ATTR_FRIENDLYNAME:
1216 case STORE_ATTR_EMAIL:
1217 case STORE_ATTR_FILENAME:
1218 STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0);
1220 case STORE_ATTR_KEYID:
1221 case STORE_ATTR_ISSUERKEYID:
1222 case STORE_ATTR_SUBJECTKEYID:
1223 case STORE_ATTR_ISSUERSERIALHASH:
1224 case STORE_ATTR_CERTHASH:
1225 STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0);
1227 case STORE_ATTR_ISSUER:
1228 case STORE_ATTR_SUBJECT:
1229 STORE_ATTR_INFO_modify_dn(attrs, code, NULL);
1231 case STORE_ATTR_SERIAL:
1232 STORE_ATTR_INFO_modify_number(attrs, code, NULL);
1240 int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1244 for (i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1245 STORE_ATTR_INFO_attr_free(attrs, i);
1246 OPENSSL_free(attrs);
1251 char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1254 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1255 ERR_R_PASSED_NULL_PARAMETER);
1258 if (ATTR_IS_SET(attrs, code))
1259 return attrs->values[code].cstring;
1260 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR, STORE_R_NO_VALUE);
1264 unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
1265 STORE_ATTR_TYPES code)
1268 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1269 ERR_R_PASSED_NULL_PARAMETER);
1272 if (ATTR_IS_SET(attrs, code))
1273 return attrs->values[code].sha1string;
1274 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR, STORE_R_NO_VALUE);
1278 X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs,
1279 STORE_ATTR_TYPES code)
1282 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1283 ERR_R_PASSED_NULL_PARAMETER);
1286 if (ATTR_IS_SET(attrs, code))
1287 return attrs->values[code].dn;
1288 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN, STORE_R_NO_VALUE);
1292 BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs,
1293 STORE_ATTR_TYPES code)
1296 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1297 ERR_R_PASSED_NULL_PARAMETER);
1300 if (ATTR_IS_SET(attrs, code))
1301 return attrs->values[code].number;
1302 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER, STORE_R_NO_VALUE);
1306 int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1307 char *cstr, size_t cstr_size)
1310 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1311 ERR_R_PASSED_NULL_PARAMETER);
1314 if (!ATTR_IS_SET(attrs, code)) {
1315 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size)))
1317 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, ERR_R_MALLOC_FAILURE);
1320 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE);
1324 int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1325 unsigned char *sha1str, size_t sha1str_size)
1328 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1329 ERR_R_PASSED_NULL_PARAMETER);
1332 if (!ATTR_IS_SET(attrs, code)) {
1333 if ((attrs->values[code].sha1string =
1334 (unsigned char *)BUF_memdup(sha1str, sha1str_size)))
1336 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, ERR_R_MALLOC_FAILURE);
1339 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1340 STORE_R_ALREADY_HAS_A_VALUE);
1344 int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1348 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, ERR_R_PASSED_NULL_PARAMETER);
1351 if (!ATTR_IS_SET(attrs, code)) {
1352 if ((attrs->values[code].dn = X509_NAME_dup(dn)))
1354 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, ERR_R_MALLOC_FAILURE);
1357 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE);
1361 int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1365 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1366 ERR_R_PASSED_NULL_PARAMETER);
1369 if (!ATTR_IS_SET(attrs, code)) {
1370 if ((attrs->values[code].number = BN_dup(number)))
1372 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, ERR_R_MALLOC_FAILURE);
1375 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE);
1379 int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1380 char *cstr, size_t cstr_size)
1383 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR,
1384 ERR_R_PASSED_NULL_PARAMETER);
1387 if (ATTR_IS_SET(attrs, code)) {
1388 OPENSSL_free(attrs->values[code].cstring);
1389 attrs->values[code].cstring = NULL;
1390 CLEAR_ATTRBIT(attrs, code);
1392 return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size);
1395 int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs,
1396 STORE_ATTR_TYPES code,
1397 unsigned char *sha1str,
1398 size_t sha1str_size)
1401 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR,
1402 ERR_R_PASSED_NULL_PARAMETER);
1405 if (ATTR_IS_SET(attrs, code)) {
1406 OPENSSL_free(attrs->values[code].sha1string);
1407 attrs->values[code].sha1string = NULL;
1408 CLEAR_ATTRBIT(attrs, code);
1410 return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size);
1413 int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1417 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN,
1418 ERR_R_PASSED_NULL_PARAMETER);
1421 if (ATTR_IS_SET(attrs, code)) {
1422 OPENSSL_free(attrs->values[code].dn);
1423 attrs->values[code].dn = NULL;
1424 CLEAR_ATTRBIT(attrs, code);
1426 return STORE_ATTR_INFO_set_dn(attrs, code, dn);
1429 int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs,
1430 STORE_ATTR_TYPES code, BIGNUM *number)
1433 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER,
1434 ERR_R_PASSED_NULL_PARAMETER);
1437 if (ATTR_IS_SET(attrs, code)) {
1438 OPENSSL_free(attrs->values[code].number);
1439 attrs->values[code].number = NULL;
1440 CLEAR_ATTRBIT(attrs, code);
1442 return STORE_ATTR_INFO_set_number(attrs, code, number);
1445 struct attr_list_ctx_st {
1446 OPENSSL_ITEM *attributes;
1448 void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1451 struct attr_list_ctx_st *context = OPENSSL_malloc(sizeof(*context));
1452 if (context != NULL)
1453 context->attributes = attributes;
1455 STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_MALLOC_FAILURE);
1458 STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER);
1462 STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
1464 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1466 if (context && context->attributes) {
1467 STORE_ATTR_INFO *attrs = NULL;
1469 while (context->attributes
1470 && context->attributes->code != STORE_ATTR_OR
1471 && context->attributes->code != STORE_ATTR_END) {
1472 switch (context->attributes->code) {
1473 case STORE_ATTR_FRIENDLYNAME:
1474 case STORE_ATTR_EMAIL:
1475 case STORE_ATTR_FILENAME:
1477 attrs = STORE_ATTR_INFO_new();
1478 if (attrs == NULL) {
1479 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1480 ERR_R_MALLOC_FAILURE);
1483 STORE_ATTR_INFO_set_cstr(attrs,
1484 context->attributes->code,
1485 context->attributes->value,
1486 context->attributes->value_size);
1488 case STORE_ATTR_KEYID:
1489 case STORE_ATTR_ISSUERKEYID:
1490 case STORE_ATTR_SUBJECTKEYID:
1491 case STORE_ATTR_ISSUERSERIALHASH:
1492 case STORE_ATTR_CERTHASH:
1494 attrs = STORE_ATTR_INFO_new();
1495 if (attrs == NULL) {
1496 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1497 ERR_R_MALLOC_FAILURE);
1500 STORE_ATTR_INFO_set_sha1str(attrs,
1501 context->attributes->code,
1502 context->attributes->value,
1503 context->attributes->value_size);
1505 case STORE_ATTR_ISSUER:
1506 case STORE_ATTR_SUBJECT:
1508 attrs = STORE_ATTR_INFO_new();
1509 if (attrs == NULL) {
1510 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1511 ERR_R_MALLOC_FAILURE);
1514 STORE_ATTR_INFO_modify_dn(attrs,
1515 context->attributes->code,
1516 context->attributes->value);
1518 case STORE_ATTR_SERIAL:
1520 attrs = STORE_ATTR_INFO_new();
1521 if (attrs == NULL) {
1522 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1523 ERR_R_MALLOC_FAILURE);
1526 STORE_ATTR_INFO_modify_number(attrs,
1527 context->attributes->code,
1528 context->attributes->value);
1531 context->attributes++;
1533 if (context->attributes->code == STORE_ATTR_OR)
1534 context->attributes++;
1537 while (context->attributes
1538 && context->attributes->code != STORE_ATTR_OR
1539 && context->attributes->code != STORE_ATTR_END)
1540 context->attributes++;
1541 if (context->attributes->code == STORE_ATTR_OR)
1542 context->attributes++;
1545 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER);
1549 int STORE_parse_attrs_end(void *handle)
1551 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1553 if (context && context->attributes) {
1555 OPENSSL_ITEM *attributes = context->attributes;
1557 OPENSSL_free(context);
1560 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1564 int STORE_parse_attrs_endp(void *handle)
1566 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1568 if (context && context->attributes) {
1569 return context->attributes->code == STORE_ATTR_END;
1571 STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER);
1575 static int attr_info_compare_compute_range(const unsigned char *abits,
1576 const unsigned char *bbits,
1577 unsigned int *alowp,
1578 unsigned int *ahighp,
1579 unsigned int *blowp,
1580 unsigned int *bhighp)
1582 unsigned int alow = (unsigned int)-1, ahigh = 0;
1583 unsigned int blow = (unsigned int)-1, bhigh = 0;
1586 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++) {
1588 if (*abits < *bbits)
1590 if (*abits > *bbits)
1594 if (alow == (unsigned int)-1) {
1596 if (!(*abits & 0x01))
1598 if (!(*abits & 0x02))
1600 if (!(*abits & 0x04))
1602 if (!(*abits & 0x08))
1604 if (!(*abits & 0x10))
1606 if (!(*abits & 0x20))
1608 if (!(*abits & 0x40))
1612 if (!(*abits & 0x80))
1614 if (!(*abits & 0x40))
1616 if (!(*abits & 0x20))
1618 if (!(*abits & 0x10))
1620 if (!(*abits & 0x08))
1622 if (!(*abits & 0x04))
1624 if (!(*abits & 0x02))
1628 if (blow == (unsigned int)-1) {
1630 if (!(*bbits & 0x01))
1632 if (!(*bbits & 0x02))
1634 if (!(*bbits & 0x04))
1636 if (!(*bbits & 0x08))
1638 if (!(*bbits & 0x10))
1640 if (!(*bbits & 0x20))
1642 if (!(*bbits & 0x40))
1646 if (!(*bbits & 0x80))
1648 if (!(*bbits & 0x40))
1650 if (!(*bbits & 0x20))
1652 if (!(*bbits & 0x10))
1654 if (!(*bbits & 0x08))
1656 if (!(*bbits & 0x04))
1658 if (!(*bbits & 0x02))
1662 if (ahigh + alow < bhigh + blow)
1664 if (ahigh + alow > bhigh + blow)
1677 int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO *const *a,
1678 const STORE_ATTR_INFO *const *b)
1686 return attr_info_compare_compute_range((*a)->set, (*b)->set, 0, 0, 0, 0);
1689 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1691 unsigned int alow, ahigh, blow, bhigh;
1699 attr_info_compare_compute_range(a->set, b->set,
1700 &alow, &ahigh, &blow, &bhigh);
1701 if (alow >= blow && ahigh <= bhigh)
1706 int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1708 unsigned char *abits, *bbits;
1719 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++) {
1720 if (*abits && (*bbits & *abits) != *abits)
1726 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1732 if (!STORE_ATTR_INFO_in(a, b))
1734 for (i = 1; i < STORE_ATTR_TYPE_NUM; i++)
1735 if (ATTR_IS_SET(a, i)) {
1737 case STORE_ATTR_FRIENDLYNAME:
1738 case STORE_ATTR_EMAIL:
1739 case STORE_ATTR_FILENAME:
1740 if (strcmp(a->values[i].cstring, b->values[i].cstring))
1743 case STORE_ATTR_KEYID:
1744 case STORE_ATTR_ISSUERKEYID:
1745 case STORE_ATTR_SUBJECTKEYID:
1746 case STORE_ATTR_ISSUERSERIALHASH:
1747 case STORE_ATTR_CERTHASH:
1748 if (memcmp(a->values[i].sha1string,
1749 b->values[i].sha1string, a->value_sizes[i]))
1752 case STORE_ATTR_ISSUER:
1753 case STORE_ATTR_SUBJECT:
1754 if (X509_NAME_cmp(a->values[i].dn, b->values[i].dn))
1757 case STORE_ATTR_SERIAL:
1758 if (BN_cmp(a->values[i].number, b->values[i].number))