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 #ifndef OPENSSL_NO_ENGINE
63 #include <openssl/engine.h>
65 #include <openssl/sha.h>
66 #include <openssl/x509.h>
69 const char * const STORE_object_type_string
[STORE_OBJECT_TYPE_NUM
+1] =
80 const int STORE_param_sizes
[STORE_PARAM_TYPE_NUM
+1] =
83 sizeof(int), /* EVP_TYPE */
84 sizeof(size_t), /* BITS */
85 -1, /* KEY_PARAMETERS */
86 0 /* KEY_NO_PARAMETERS */
89 const int STORE_attr_sizes
[STORE_ATTR_TYPE_NUM
+1] =
92 -1, /* FRIENDLYNAME: C string */
93 SHA_DIGEST_LENGTH
, /* KEYID: SHA1 digest, 160 bits */
94 SHA_DIGEST_LENGTH
, /* ISSUERKEYID: SHA1 digest, 160 bits */
95 SHA_DIGEST_LENGTH
, /* SUBJECTKEYID: SHA1 digest, 160 bits */
96 SHA_DIGEST_LENGTH
, /* ISSUERSERIALHASH: SHA1 digest, 160 bits */
97 sizeof(X509_NAME
*), /* ISSUER: X509_NAME * */
98 sizeof(BIGNUM
*), /* SERIAL: BIGNUM * */
99 sizeof(X509_NAME
*), /* SUBJECT: X509_NAME * */
100 SHA_DIGEST_LENGTH
, /* CERTHASH: SHA1 digest, 160 bits */
101 -1, /* EMAIL: C string */
102 -1, /* FILENAME: C string */
105 STORE
*STORE_new_method(const STORE_METHOD
*method
)
111 STOREerr(STORE_F_STORE_NEW_METHOD
,ERR_R_PASSED_NULL_PARAMETER
);
115 ret
=(STORE
*)OPENSSL_malloc(sizeof(STORE
));
118 STOREerr(STORE_F_STORE_NEW_METHOD
,ERR_R_MALLOC_FAILURE
);
124 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE
, ret
, &ret
->ex_data
);
125 if (ret
->meth
->init
&& !ret
->meth
->init(ret
))
133 STORE
*STORE_new_engine(ENGINE
*engine
)
137 const STORE_METHOD
*meth
= 0;
139 #ifdef OPENSSL_NO_ENGINE
144 if (!ENGINE_init(engine
))
146 STOREerr(STORE_F_STORE_NEW_ENGINE
, ERR_R_ENGINE_LIB
);
153 STOREerr(STORE_F_STORE_NEW_ENGINE
,ERR_R_PASSED_NULL_PARAMETER
);
158 meth
= ENGINE_get_STORE(e
);
161 STOREerr(STORE_F_STORE_NEW_ENGINE
,
169 ret
= STORE_new_method(meth
);
172 STOREerr(STORE_F_STORE_NEW_ENGINE
,ERR_R_STORE_LIB
);
181 void STORE_free(STORE
*store
)
185 if (store
->meth
->clean
)
186 store
->meth
->clean(store
);
187 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE
, store
, &store
->ex_data
);
191 int STORE_ctrl(STORE
*store
, int cmd
, long i
, void *p
, void (*f
)(void))
195 STOREerr(STORE_F_STORE_CTRL
,ERR_R_PASSED_NULL_PARAMETER
);
198 if (store
->meth
->ctrl
)
199 return store
->meth
->ctrl(store
, cmd
, i
, p
, f
);
200 STOREerr(STORE_F_STORE_CTRL
,STORE_R_NO_CONTROL_FUNCTION
);
205 int STORE_get_ex_new_index(long argl
, void *argp
, CRYPTO_EX_new
*new_func
,
206 CRYPTO_EX_dup
*dup_func
, CRYPTO_EX_free
*free_func
)
208 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE
, argl
, argp
,
209 new_func
, dup_func
, free_func
);
212 int STORE_set_ex_data(STORE
*r
, int idx
, void *arg
)
214 return(CRYPTO_set_ex_data(&r
->ex_data
,idx
,arg
));
217 void *STORE_get_ex_data(STORE
*r
, int idx
)
219 return(CRYPTO_get_ex_data(&r
->ex_data
,idx
));
222 const STORE_METHOD
*STORE_get_method(STORE
*store
)
227 const STORE_METHOD
*STORE_set_method(STORE
*store
, const STORE_METHOD
*meth
)
236 #define check_store(s,fncode,fnname,fnerrcode) \
239 if ((s) == NULL || (s)->meth == NULL) \
241 STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
244 if ((s)->meth->fnname == NULL) \
246 STOREerr((fncode), (fnerrcode)); \
254 X509
*STORE_get_certificate(STORE
*s
, OPENSSL_ITEM attributes
[],
255 OPENSSL_ITEM parameters
[])
257 STORE_OBJECT
*object
;
260 check_store(s
,STORE_F_STORE_GET_CERTIFICATE
,
261 get_object
,STORE_R_NO_GET_OBJECT_FUNCTION
);
263 object
= s
->meth
->get_object(s
, STORE_OBJECT_TYPE_X509_CERTIFICATE
,
264 attributes
, parameters
);
265 if (!object
|| !object
->data
.x509
.certificate
)
267 STOREerr(STORE_F_STORE_GET_CERTIFICATE
,
268 STORE_R_FAILED_GETTING_CERTIFICATE
);
271 CRYPTO_add(&object
->data
.x509
.certificate
->references
,1,CRYPTO_LOCK_X509
);
273 REF_PRINT("X509",data
);
275 x
= object
->data
.x509
.certificate
;
276 STORE_OBJECT_free(object
);
280 int STORE_store_certificate(STORE
*s
, X509
*data
, OPENSSL_ITEM attributes
[],
281 OPENSSL_ITEM parameters
[])
283 STORE_OBJECT
*object
;
286 check_store(s
,STORE_F_STORE_CERTIFICATE
,
287 store_object
,STORE_R_NO_STORE_OBJECT_FUNCTION
);
289 object
= STORE_OBJECT_new();
292 STOREerr(STORE_F_STORE_STORE_CERTIFICATE
,
293 ERR_R_MALLOC_FAILURE
);
297 CRYPTO_add(&data
->references
,1,CRYPTO_LOCK_X509
);
299 REF_PRINT("X509",data
);
301 object
->data
.x509
.certificate
= data
;
303 i
= s
->meth
->store_object(s
, STORE_OBJECT_TYPE_X509_CERTIFICATE
,
304 object
, attributes
, parameters
);
306 STORE_OBJECT_free(object
);
310 STOREerr(STORE_F_STORE_STORE_CERTIFICATE
,
311 STORE_R_FAILED_STORING_CERTIFICATE
);
317 int STORE_modify_certificate(STORE
*s
, OPENSSL_ITEM search_attributes
[],
318 OPENSSL_ITEM add_attributes
[], OPENSSL_ITEM modify_attributes
[],
319 OPENSSL_ITEM delete_attributes
[], OPENSSL_ITEM parameters
[])
321 check_store(s
,STORE_F_STORE_MODIFY_CERTIFICATE
,
322 modify_object
,STORE_R_NO_MODIFY_OBJECT_FUNCTION
);
324 if (!s
->meth
->modify_object(s
, STORE_OBJECT_TYPE_X509_CERTIFICATE
,
325 search_attributes
, add_attributes
, modify_attributes
,
326 delete_attributes
, parameters
))
328 STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE
,
329 STORE_R_FAILED_MODIFYING_CERTIFICATE
);
335 int STORE_revoke_certificate(STORE
*s
, OPENSSL_ITEM attributes
[],
336 OPENSSL_ITEM parameters
[])
338 check_store(s
,STORE_F_STORE_REVOKE_CERTIFICATE
,
339 revoke_object
,STORE_R_NO_REVOKE_OBJECT_FUNCTION
);
341 if (!s
->meth
->revoke_object(s
, STORE_OBJECT_TYPE_X509_CERTIFICATE
,
342 attributes
, parameters
))
344 STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE
,
345 STORE_R_FAILED_REVOKING_CERTIFICATE
);
351 int STORE_delete_certificate(STORE
*s
, OPENSSL_ITEM attributes
[],
352 OPENSSL_ITEM parameters
[])
354 check_store(s
,STORE_F_STORE_DELETE_CERTIFICATE
,
355 delete_object
,STORE_R_NO_DELETE_OBJECT_FUNCTION
);
357 if (!s
->meth
->delete_object(s
, STORE_OBJECT_TYPE_X509_CERTIFICATE
,
358 attributes
, parameters
))
360 STOREerr(STORE_F_STORE_DELETE_CERTIFICATE
,
361 STORE_R_FAILED_DELETING_CERTIFICATE
);
367 void *STORE_list_certificate_start(STORE
*s
, OPENSSL_ITEM attributes
[],
368 OPENSSL_ITEM parameters
[])
372 check_store(s
,STORE_F_STORE_LIST_CERTIFICATE_START
,
373 list_object_start
,STORE_R_NO_LIST_OBJECT_START_FUNCTION
);
375 handle
= s
->meth
->list_object_start(s
,
376 STORE_OBJECT_TYPE_X509_CERTIFICATE
, attributes
, parameters
);
379 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START
,
380 STORE_R_FAILED_LISTING_CERTIFICATES
);
386 X509
*STORE_list_certificate_next(STORE
*s
, void *handle
)
388 STORE_OBJECT
*object
;
391 check_store(s
,STORE_F_STORE_LIST_CERTIFICATE_NEXT
,
392 list_object_next
,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION
);
394 object
= s
->meth
->list_object_next(s
, handle
);
395 if (!object
|| !object
->data
.x509
.certificate
)
397 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT
,
398 STORE_R_FAILED_LISTING_CERTIFICATES
);
401 CRYPTO_add(&object
->data
.x509
.certificate
->references
,1,CRYPTO_LOCK_X509
);
403 REF_PRINT("X509",data
);
405 x
= object
->data
.x509
.certificate
;
406 STORE_OBJECT_free(object
);
410 int STORE_list_certificate_end(STORE
*s
, void *handle
)
412 check_store(s
,STORE_F_STORE_LIST_CERTIFICATE_END
,
413 list_object_end
,STORE_R_NO_LIST_OBJECT_END_FUNCTION
);
415 if (!s
->meth
->list_object_end(s
, handle
))
417 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END
,
418 STORE_R_FAILED_LISTING_CERTIFICATES
);
424 int STORE_list_certificate_endp(STORE
*s
, void *handle
)
426 check_store(s
,STORE_F_STORE_LIST_CERTIFICATE_ENDP
,
427 list_object_endp
,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION
);
429 if (!s
->meth
->list_object_endp(s
, handle
))
431 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP
,
432 STORE_R_FAILED_LISTING_CERTIFICATES
);
438 EVP_PKEY
*STORE_generate_key(STORE
*s
, OPENSSL_ITEM attributes
[],
439 OPENSSL_ITEM parameters
[])
441 STORE_OBJECT
*object
;
444 check_store(s
,STORE_F_STORE_GENERATE_KEY
,
445 generate_object
,STORE_R_NO_GENERATE_OBJECT_FUNCTION
);
447 object
= s
->meth
->generate_object(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
,
448 attributes
, parameters
);
449 if (!object
|| !object
->data
.key
)
451 STOREerr(STORE_F_STORE_GENERATE_KEY
,
452 STORE_R_FAILED_GENERATING_KEY
);
455 CRYPTO_add(&object
->data
.key
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
457 REF_PRINT("EVP_PKEY",data
);
459 pkey
= object
->data
.key
;
460 STORE_OBJECT_free(object
);
464 EVP_PKEY
*STORE_get_private_key(STORE
*s
, OPENSSL_ITEM attributes
[],
465 OPENSSL_ITEM parameters
[])
467 STORE_OBJECT
*object
;
470 check_store(s
,STORE_F_STORE_GET_PRIVATE_KEY
,
471 get_object
,STORE_R_NO_GET_OBJECT_FUNCTION
);
473 object
= s
->meth
->get_object(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
,
474 attributes
, parameters
);
475 if (!object
|| !object
->data
.key
|| !object
->data
.key
)
477 STOREerr(STORE_F_STORE_GET_PRIVATE_KEY
,
478 STORE_R_FAILED_GETTING_KEY
);
481 CRYPTO_add(&object
->data
.key
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
483 REF_PRINT("EVP_PKEY",data
);
485 pkey
= object
->data
.key
;
486 STORE_OBJECT_free(object
);
490 int STORE_store_private_key(STORE
*s
, EVP_PKEY
*data
, OPENSSL_ITEM attributes
[],
491 OPENSSL_ITEM parameters
[])
493 STORE_OBJECT
*object
;
496 check_store(s
,STORE_F_STORE_STORE_PRIVATE_KEY
,
497 store_object
,STORE_R_NO_STORE_OBJECT_FUNCTION
);
499 object
= STORE_OBJECT_new();
502 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY
,
503 ERR_R_MALLOC_FAILURE
);
506 object
->data
.key
= EVP_PKEY_new();
507 if (!object
->data
.key
)
509 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY
,
510 ERR_R_MALLOC_FAILURE
);
514 CRYPTO_add(&data
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
516 REF_PRINT("EVP_PKEY",data
);
518 object
->data
.key
= data
;
520 i
= s
->meth
->store_object(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
, object
,
521 attributes
, parameters
);
523 STORE_OBJECT_free(object
);
527 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY
,
528 STORE_R_FAILED_STORING_KEY
);
534 int STORE_modify_private_key(STORE
*s
, OPENSSL_ITEM search_attributes
[],
535 OPENSSL_ITEM add_attributes
[], OPENSSL_ITEM modify_attributes
[],
536 OPENSSL_ITEM delete_attributes
[], OPENSSL_ITEM parameters
[])
538 check_store(s
,STORE_F_STORE_MODIFY_PRIVATE_KEY
,
539 modify_object
,STORE_R_NO_MODIFY_OBJECT_FUNCTION
);
541 if (!s
->meth
->modify_object(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
,
542 search_attributes
, add_attributes
, modify_attributes
,
543 delete_attributes
, parameters
))
545 STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY
,
546 STORE_R_FAILED_MODIFYING_PRIVATE_KEY
);
552 int STORE_revoke_private_key(STORE
*s
, OPENSSL_ITEM attributes
[],
553 OPENSSL_ITEM parameters
[])
557 check_store(s
,STORE_F_STORE_REVOKE_PRIVATE_KEY
,
558 revoke_object
,STORE_R_NO_REVOKE_OBJECT_FUNCTION
);
560 i
= s
->meth
->revoke_object(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
,
561 attributes
, parameters
);
565 STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY
,
566 STORE_R_FAILED_REVOKING_KEY
);
572 int STORE_delete_private_key(STORE
*s
, OPENSSL_ITEM attributes
[],
573 OPENSSL_ITEM parameters
[])
575 check_store(s
,STORE_F_STORE_DELETE_PRIVATE_KEY
,
576 delete_object
,STORE_R_NO_DELETE_OBJECT_FUNCTION
);
578 if (!s
->meth
->delete_object(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
,
579 attributes
, parameters
))
581 STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY
,
582 STORE_R_FAILED_DELETING_KEY
);
588 void *STORE_list_private_key_start(STORE
*s
, OPENSSL_ITEM attributes
[],
589 OPENSSL_ITEM parameters
[])
593 check_store(s
,STORE_F_STORE_LIST_PRIVATE_KEY_START
,
594 list_object_start
,STORE_R_NO_LIST_OBJECT_START_FUNCTION
);
596 handle
= s
->meth
->list_object_start(s
, STORE_OBJECT_TYPE_PRIVATE_KEY
,
597 attributes
, parameters
);
600 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START
,
601 STORE_R_FAILED_LISTING_KEYS
);
607 EVP_PKEY
*STORE_list_private_key_next(STORE
*s
, void *handle
)
609 STORE_OBJECT
*object
;
612 check_store(s
,STORE_F_STORE_LIST_PRIVATE_KEY_NEXT
,
613 list_object_next
,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION
);
615 object
= s
->meth
->list_object_next(s
, handle
);
616 if (!object
|| !object
->data
.key
|| !object
->data
.key
)
618 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT
,
619 STORE_R_FAILED_LISTING_KEYS
);
622 CRYPTO_add(&object
->data
.key
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
624 REF_PRINT("EVP_PKEY",data
);
626 pkey
= object
->data
.key
;
627 STORE_OBJECT_free(object
);
631 int STORE_list_private_key_end(STORE
*s
, void *handle
)
633 check_store(s
,STORE_F_STORE_LIST_PRIVATE_KEY_END
,
634 list_object_end
,STORE_R_NO_LIST_OBJECT_END_FUNCTION
);
636 if (!s
->meth
->list_object_end(s
, handle
))
638 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END
,
639 STORE_R_FAILED_LISTING_KEYS
);
645 int STORE_list_private_key_endp(STORE
*s
, void *handle
)
647 check_store(s
,STORE_F_STORE_LIST_PRIVATE_KEY_ENDP
,
648 list_object_endp
,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION
);
650 if (!s
->meth
->list_object_endp(s
, handle
))
652 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP
,
653 STORE_R_FAILED_LISTING_KEYS
);
659 EVP_PKEY
*STORE_get_public_key(STORE
*s
, OPENSSL_ITEM attributes
[],
660 OPENSSL_ITEM parameters
[])
662 STORE_OBJECT
*object
;
665 check_store(s
,STORE_F_STORE_GET_PUBLIC_KEY
,
666 get_object
,STORE_R_NO_GET_OBJECT_FUNCTION
);
668 object
= s
->meth
->get_object(s
, STORE_OBJECT_TYPE_PUBLIC_KEY
,
669 attributes
, parameters
);
670 if (!object
|| !object
->data
.key
|| !object
->data
.key
)
672 STOREerr(STORE_F_STORE_GET_PUBLIC_KEY
,
673 STORE_R_FAILED_GETTING_KEY
);
676 CRYPTO_add(&object
->data
.key
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
678 REF_PRINT("EVP_PKEY",data
);
680 pkey
= object
->data
.key
;
681 STORE_OBJECT_free(object
);
685 int STORE_store_public_key(STORE
*s
, EVP_PKEY
*data
, OPENSSL_ITEM attributes
[],
686 OPENSSL_ITEM parameters
[])
688 STORE_OBJECT
*object
;
691 check_store(s
,STORE_F_STORE_STORE_PUBLIC_KEY
,
692 store_object
,STORE_R_NO_STORE_OBJECT_FUNCTION
);
694 object
= STORE_OBJECT_new();
697 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY
,
698 ERR_R_MALLOC_FAILURE
);
701 object
->data
.key
= EVP_PKEY_new();
702 if (!object
->data
.key
)
704 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY
,
705 ERR_R_MALLOC_FAILURE
);
709 CRYPTO_add(&data
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
711 REF_PRINT("EVP_PKEY",data
);
713 object
->data
.key
= data
;
715 i
= s
->meth
->store_object(s
, STORE_OBJECT_TYPE_PUBLIC_KEY
, object
,
716 attributes
, parameters
);
718 STORE_OBJECT_free(object
);
722 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY
,
723 STORE_R_FAILED_STORING_KEY
);
729 int STORE_modify_public_key(STORE
*s
, OPENSSL_ITEM search_attributes
[],
730 OPENSSL_ITEM add_attributes
[], OPENSSL_ITEM modify_attributes
[],
731 OPENSSL_ITEM delete_attributes
[], OPENSSL_ITEM parameters
[])
733 check_store(s
,STORE_F_STORE_MODIFY_PUBLIC_KEY
,
734 modify_object
,STORE_R_NO_MODIFY_OBJECT_FUNCTION
);
736 if (!s
->meth
->modify_object(s
, STORE_OBJECT_TYPE_PUBLIC_KEY
,
737 search_attributes
, add_attributes
, modify_attributes
,
738 delete_attributes
, parameters
))
740 STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY
,
741 STORE_R_FAILED_MODIFYING_PUBLIC_KEY
);
747 int STORE_revoke_public_key(STORE
*s
, OPENSSL_ITEM attributes
[],
748 OPENSSL_ITEM parameters
[])
752 check_store(s
,STORE_F_STORE_REVOKE_PUBLIC_KEY
,
753 revoke_object
,STORE_R_NO_REVOKE_OBJECT_FUNCTION
);
755 i
= s
->meth
->revoke_object(s
, STORE_OBJECT_TYPE_PUBLIC_KEY
,
756 attributes
, parameters
);
760 STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY
,
761 STORE_R_FAILED_REVOKING_KEY
);
767 int STORE_delete_public_key(STORE
*s
, OPENSSL_ITEM attributes
[],
768 OPENSSL_ITEM parameters
[])
770 check_store(s
,STORE_F_STORE_DELETE_PUBLIC_KEY
,
771 delete_object
,STORE_R_NO_DELETE_OBJECT_FUNCTION
);
773 if (!s
->meth
->delete_object(s
, STORE_OBJECT_TYPE_PUBLIC_KEY
,
774 attributes
, parameters
))
776 STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY
,
777 STORE_R_FAILED_DELETING_KEY
);
783 void *STORE_list_public_key_start(STORE
*s
, OPENSSL_ITEM attributes
[],
784 OPENSSL_ITEM parameters
[])
788 check_store(s
,STORE_F_STORE_LIST_PUBLIC_KEY_START
,
789 list_object_start
,STORE_R_NO_LIST_OBJECT_START_FUNCTION
);
791 handle
= s
->meth
->list_object_start(s
, STORE_OBJECT_TYPE_PUBLIC_KEY
,
792 attributes
, parameters
);
795 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START
,
796 STORE_R_FAILED_LISTING_KEYS
);
802 EVP_PKEY
*STORE_list_public_key_next(STORE
*s
, void *handle
)
804 STORE_OBJECT
*object
;
807 check_store(s
,STORE_F_STORE_LIST_PUBLIC_KEY_NEXT
,
808 list_object_next
,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION
);
810 object
= s
->meth
->list_object_next(s
, handle
);
811 if (!object
|| !object
->data
.key
|| !object
->data
.key
)
813 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT
,
814 STORE_R_FAILED_LISTING_KEYS
);
817 CRYPTO_add(&object
->data
.key
->references
,1,CRYPTO_LOCK_EVP_PKEY
);
819 REF_PRINT("EVP_PKEY",data
);
821 pkey
= object
->data
.key
;
822 STORE_OBJECT_free(object
);
826 int STORE_list_public_key_end(STORE
*s
, void *handle
)
828 check_store(s
,STORE_F_STORE_LIST_PUBLIC_KEY_END
,
829 list_object_end
,STORE_R_NO_LIST_OBJECT_END_FUNCTION
);
831 if (!s
->meth
->list_object_end(s
, handle
))
833 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END
,
834 STORE_R_FAILED_LISTING_KEYS
);
840 int STORE_list_public_key_endp(STORE
*s
, void *handle
)
842 check_store(s
,STORE_F_STORE_LIST_PUBLIC_KEY_ENDP
,
843 list_object_endp
,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION
);
845 if (!s
->meth
->list_object_endp(s
, handle
))
847 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP
,
848 STORE_R_FAILED_LISTING_KEYS
);
854 X509_CRL
*STORE_generate_crl(STORE
*s
, OPENSSL_ITEM attributes
[],
855 OPENSSL_ITEM parameters
[])
857 STORE_OBJECT
*object
;
860 check_store(s
,STORE_F_STORE_GENERATE_CRL
,
861 generate_object
,STORE_R_NO_GENERATE_CRL_FUNCTION
);
863 object
= s
->meth
->generate_object(s
, STORE_OBJECT_TYPE_X509_CRL
,
864 attributes
, parameters
);
865 if (!object
|| !object
->data
.crl
)
867 STOREerr(STORE_F_STORE_GENERATE_CRL
,
868 STORE_R_FAILED_GENERATING_CRL
);
871 CRYPTO_add(&object
->data
.crl
->references
,1,CRYPTO_LOCK_X509_CRL
);
873 REF_PRINT("X509_CRL",data
);
875 crl
= object
->data
.crl
;
876 STORE_OBJECT_free(object
);
880 X509_CRL
*STORE_get_crl(STORE
*s
, OPENSSL_ITEM attributes
[],
881 OPENSSL_ITEM parameters
[])
883 STORE_OBJECT
*object
;
886 check_store(s
,STORE_F_STORE_GET_CRL
,
887 get_object
,STORE_R_NO_GET_OBJECT_FUNCTION
);
889 object
= s
->meth
->get_object(s
, STORE_OBJECT_TYPE_X509_CRL
,
890 attributes
, parameters
);
891 if (!object
|| !object
->data
.crl
)
893 STOREerr(STORE_F_STORE_GET_CRL
,
894 STORE_R_FAILED_GETTING_KEY
);
897 CRYPTO_add(&object
->data
.crl
->references
,1,CRYPTO_LOCK_X509_CRL
);
899 REF_PRINT("X509_CRL",data
);
901 crl
= object
->data
.crl
;
902 STORE_OBJECT_free(object
);
906 int STORE_store_crl(STORE
*s
, X509_CRL
*data
, OPENSSL_ITEM attributes
[],
907 OPENSSL_ITEM parameters
[])
909 STORE_OBJECT
*object
;
912 check_store(s
,STORE_F_STORE_STORE_CRL
,
913 store_object
,STORE_R_NO_STORE_OBJECT_FUNCTION
);
915 object
= STORE_OBJECT_new();
918 STOREerr(STORE_F_STORE_STORE_CRL
,
919 ERR_R_MALLOC_FAILURE
);
923 CRYPTO_add(&data
->references
,1,CRYPTO_LOCK_X509_CRL
);
925 REF_PRINT("X509_CRL",data
);
927 object
->data
.crl
= data
;
929 i
= s
->meth
->store_object(s
, STORE_OBJECT_TYPE_X509_CRL
, object
,
930 attributes
, parameters
);
932 STORE_OBJECT_free(object
);
936 STOREerr(STORE_F_STORE_STORE_CRL
,
937 STORE_R_FAILED_STORING_KEY
);
943 int STORE_modify_crl(STORE
*s
, OPENSSL_ITEM search_attributes
[],
944 OPENSSL_ITEM add_attributes
[], OPENSSL_ITEM modify_attributes
[],
945 OPENSSL_ITEM delete_attributes
[], OPENSSL_ITEM parameters
[])
947 check_store(s
,STORE_F_STORE_MODIFY_CRL
,
948 modify_object
,STORE_R_NO_MODIFY_OBJECT_FUNCTION
);
950 if (!s
->meth
->modify_object(s
, STORE_OBJECT_TYPE_X509_CRL
,
951 search_attributes
, add_attributes
, modify_attributes
,
952 delete_attributes
, parameters
))
954 STOREerr(STORE_F_STORE_MODIFY_CRL
,
955 STORE_R_FAILED_MODIFYING_CRL
);
961 int STORE_delete_crl(STORE
*s
, OPENSSL_ITEM attributes
[],
962 OPENSSL_ITEM parameters
[])
964 check_store(s
,STORE_F_STORE_DELETE_CRL
,
965 delete_object
,STORE_R_NO_DELETE_OBJECT_FUNCTION
);
967 if (!s
->meth
->delete_object(s
, STORE_OBJECT_TYPE_X509_CRL
,
968 attributes
, parameters
))
970 STOREerr(STORE_F_STORE_DELETE_CRL
,
971 STORE_R_FAILED_DELETING_KEY
);
977 void *STORE_list_crl_start(STORE
*s
, OPENSSL_ITEM attributes
[],
978 OPENSSL_ITEM parameters
[])
982 check_store(s
,STORE_F_STORE_LIST_CRL_START
,
983 list_object_start
,STORE_R_NO_LIST_OBJECT_START_FUNCTION
);
985 handle
= s
->meth
->list_object_start(s
, STORE_OBJECT_TYPE_X509_CRL
,
986 attributes
, parameters
);
989 STOREerr(STORE_F_STORE_LIST_CRL_START
,
990 STORE_R_FAILED_LISTING_KEYS
);
996 X509_CRL
*STORE_list_crl_next(STORE
*s
, void *handle
)
998 STORE_OBJECT
*object
;
1001 check_store(s
,STORE_F_STORE_LIST_CRL_NEXT
,
1002 list_object_next
,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION
);
1004 object
= s
->meth
->list_object_next(s
, handle
);
1005 if (!object
|| !object
->data
.crl
)
1007 STOREerr(STORE_F_STORE_LIST_CRL_NEXT
,
1008 STORE_R_FAILED_LISTING_KEYS
);
1011 CRYPTO_add(&object
->data
.crl
->references
,1,CRYPTO_LOCK_X509_CRL
);
1013 REF_PRINT("X509_CRL",data
);
1015 crl
= object
->data
.crl
;
1016 STORE_OBJECT_free(object
);
1020 int STORE_list_crl_end(STORE
*s
, void *handle
)
1022 check_store(s
,STORE_F_STORE_LIST_CRL_END
,
1023 list_object_end
,STORE_R_NO_LIST_OBJECT_END_FUNCTION
);
1025 if (!s
->meth
->list_object_end(s
, handle
))
1027 STOREerr(STORE_F_STORE_LIST_CRL_END
,
1028 STORE_R_FAILED_LISTING_KEYS
);
1034 int STORE_list_crl_endp(STORE
*s
, void *handle
)
1036 check_store(s
,STORE_F_STORE_LIST_CRL_ENDP
,
1037 list_object_endp
,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION
);
1039 if (!s
->meth
->list_object_endp(s
, handle
))
1041 STOREerr(STORE_F_STORE_LIST_CRL_ENDP
,
1042 STORE_R_FAILED_LISTING_KEYS
);
1048 int STORE_store_number(STORE
*s
, BIGNUM
*data
, OPENSSL_ITEM attributes
[],
1049 OPENSSL_ITEM parameters
[])
1051 STORE_OBJECT
*object
;
1054 check_store(s
,STORE_F_STORE_STORE_NUMBER
,
1055 store_object
,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION
);
1057 object
= STORE_OBJECT_new();
1060 STOREerr(STORE_F_STORE_STORE_NUMBER
,
1061 ERR_R_MALLOC_FAILURE
);
1065 object
->data
.number
= data
;
1067 i
= s
->meth
->store_object(s
, STORE_OBJECT_TYPE_NUMBER
, object
,
1068 attributes
, parameters
);
1070 STORE_OBJECT_free(object
);
1074 STOREerr(STORE_F_STORE_STORE_NUMBER
,
1075 STORE_R_FAILED_STORING_NUMBER
);
1081 int STORE_modify_number(STORE
*s
, OPENSSL_ITEM search_attributes
[],
1082 OPENSSL_ITEM add_attributes
[], OPENSSL_ITEM modify_attributes
[],
1083 OPENSSL_ITEM delete_attributes
[], OPENSSL_ITEM parameters
[])
1085 check_store(s
,STORE_F_STORE_MODIFY_NUMBER
,
1086 modify_object
,STORE_R_NO_MODIFY_OBJECT_FUNCTION
);
1088 if (!s
->meth
->modify_object(s
, STORE_OBJECT_TYPE_NUMBER
,
1089 search_attributes
, add_attributes
, modify_attributes
,
1090 delete_attributes
, parameters
))
1092 STOREerr(STORE_F_STORE_MODIFY_NUMBER
,
1093 STORE_R_FAILED_MODIFYING_NUMBER
);
1099 BIGNUM
*STORE_get_number(STORE
*s
, OPENSSL_ITEM attributes
[],
1100 OPENSSL_ITEM parameters
[])
1102 STORE_OBJECT
*object
;
1105 check_store(s
,STORE_F_STORE_GET_NUMBER
,
1106 get_object
,STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION
);
1108 object
= s
->meth
->get_object(s
, STORE_OBJECT_TYPE_NUMBER
, attributes
,
1110 if (!object
|| !object
->data
.number
)
1112 STOREerr(STORE_F_STORE_GET_NUMBER
,
1113 STORE_R_FAILED_GETTING_NUMBER
);
1116 n
= object
->data
.number
;
1117 object
->data
.number
= NULL
;
1118 STORE_OBJECT_free(object
);
1122 int STORE_delete_number(STORE
*s
, OPENSSL_ITEM attributes
[],
1123 OPENSSL_ITEM parameters
[])
1125 check_store(s
,STORE_F_STORE_DELETE_NUMBER
,
1126 delete_object
,STORE_R_NO_DELETE_NUMBER_FUNCTION
);
1128 if (!s
->meth
->delete_object(s
, STORE_OBJECT_TYPE_NUMBER
, attributes
,
1131 STOREerr(STORE_F_STORE_DELETE_NUMBER
,
1132 STORE_R_FAILED_DELETING_NUMBER
);
1138 int STORE_store_arbitrary(STORE
*s
, BUF_MEM
*data
, OPENSSL_ITEM attributes
[],
1139 OPENSSL_ITEM parameters
[])
1141 STORE_OBJECT
*object
;
1144 check_store(s
,STORE_F_STORE_STORE_ARBITRARY
,
1145 store_object
,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION
);
1147 object
= STORE_OBJECT_new();
1150 STOREerr(STORE_F_STORE_STORE_ARBITRARY
,
1151 ERR_R_MALLOC_FAILURE
);
1155 object
->data
.arbitrary
= data
;
1157 i
= s
->meth
->store_object(s
, STORE_OBJECT_TYPE_ARBITRARY
, object
,
1158 attributes
, parameters
);
1160 STORE_OBJECT_free(object
);
1164 STOREerr(STORE_F_STORE_STORE_ARBITRARY
,
1165 STORE_R_FAILED_STORING_ARBITRARY
);
1171 int STORE_modify_arbitrary(STORE
*s
, OPENSSL_ITEM search_attributes
[],
1172 OPENSSL_ITEM add_attributes
[], OPENSSL_ITEM modify_attributes
[],
1173 OPENSSL_ITEM delete_attributes
[], OPENSSL_ITEM parameters
[])
1175 check_store(s
,STORE_F_STORE_MODIFY_ARBITRARY
,
1176 modify_object
,STORE_R_NO_MODIFY_OBJECT_FUNCTION
);
1178 if (!s
->meth
->modify_object(s
, STORE_OBJECT_TYPE_ARBITRARY
,
1179 search_attributes
, add_attributes
, modify_attributes
,
1180 delete_attributes
, parameters
))
1182 STOREerr(STORE_F_STORE_MODIFY_ARBITRARY
,
1183 STORE_R_FAILED_MODIFYING_ARBITRARY
);
1189 BUF_MEM
*STORE_get_arbitrary(STORE
*s
, OPENSSL_ITEM attributes
[],
1190 OPENSSL_ITEM parameters
[])
1192 STORE_OBJECT
*object
;
1195 check_store(s
,STORE_F_STORE_GET_ARBITRARY
,
1196 get_object
,STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION
);
1198 object
= s
->meth
->get_object(s
, STORE_OBJECT_TYPE_ARBITRARY
,
1199 attributes
, parameters
);
1200 if (!object
|| !object
->data
.arbitrary
)
1202 STOREerr(STORE_F_STORE_GET_ARBITRARY
,
1203 STORE_R_FAILED_GETTING_ARBITRARY
);
1206 b
= object
->data
.arbitrary
;
1207 object
->data
.arbitrary
= NULL
;
1208 STORE_OBJECT_free(object
);
1212 int STORE_delete_arbitrary(STORE
*s
, OPENSSL_ITEM attributes
[],
1213 OPENSSL_ITEM parameters
[])
1215 check_store(s
,STORE_F_STORE_DELETE_ARBITRARY
,
1216 delete_object
,STORE_R_NO_DELETE_ARBITRARY_FUNCTION
);
1218 if (!s
->meth
->delete_object(s
, STORE_OBJECT_TYPE_ARBITRARY
, attributes
,
1221 STOREerr(STORE_F_STORE_DELETE_ARBITRARY
,
1222 STORE_R_FAILED_DELETING_ARBITRARY
);
1228 STORE_OBJECT
*STORE_OBJECT_new(void)
1230 STORE_OBJECT
*object
= OPENSSL_malloc(sizeof(STORE_OBJECT
));
1231 if (object
) memset(object
, 0, sizeof(STORE_OBJECT
));
1234 void STORE_OBJECT_free(STORE_OBJECT
*data
)
1239 case STORE_OBJECT_TYPE_X509_CERTIFICATE
:
1240 X509_free(data
->data
.x509
.certificate
);
1242 case STORE_OBJECT_TYPE_X509_CRL
:
1243 X509_CRL_free(data
->data
.crl
);
1245 case STORE_OBJECT_TYPE_PRIVATE_KEY
:
1246 case STORE_OBJECT_TYPE_PUBLIC_KEY
:
1247 EVP_PKEY_free(data
->data
.key
);
1249 case STORE_OBJECT_TYPE_NUMBER
:
1250 BN_free(data
->data
.number
);
1252 case STORE_OBJECT_TYPE_ARBITRARY
:
1253 BUF_MEM_free(data
->data
.arbitrary
);
1259 IMPLEMENT_STACK_OF(STORE_OBJECT
*)
1262 struct STORE_attr_info_st
1264 unsigned char set
[(STORE_ATTR_TYPE_NUM
+ 8) / 8];
1268 unsigned char *sha1string
;
1272 } values
[STORE_ATTR_TYPE_NUM
+1];
1273 size_t value_sizes
[STORE_ATTR_TYPE_NUM
+1];
1276 #define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1277 && ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1278 #define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1279 #define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1281 STORE_ATTR_INFO
*STORE_ATTR_INFO_new(void)
1283 return (STORE_ATTR_INFO
*)OPENSSL_malloc(sizeof(STORE_ATTR_INFO
));
1285 static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO
*attrs
,
1286 STORE_ATTR_TYPES code
)
1288 if (ATTR_IS_SET(attrs
,code
))
1292 case STORE_ATTR_FRIENDLYNAME
:
1293 case STORE_ATTR_EMAIL
:
1294 case STORE_ATTR_FILENAME
:
1295 STORE_ATTR_INFO_modify_cstr(attrs
, code
, NULL
, 0);
1297 case STORE_ATTR_KEYID
:
1298 case STORE_ATTR_ISSUERKEYID
:
1299 case STORE_ATTR_SUBJECTKEYID
:
1300 case STORE_ATTR_ISSUERSERIALHASH
:
1301 case STORE_ATTR_CERTHASH
:
1302 STORE_ATTR_INFO_modify_sha1str(attrs
, code
, NULL
, 0);
1304 case STORE_ATTR_ISSUER
:
1305 case STORE_ATTR_SUBJECT
:
1306 STORE_ATTR_INFO_modify_dn(attrs
, code
, NULL
);
1308 case STORE_ATTR_SERIAL
:
1309 STORE_ATTR_INFO_modify_number(attrs
, code
, NULL
);
1316 int STORE_ATTR_INFO_free(STORE_ATTR_INFO
*attrs
)
1321 for(i
= 0; i
++ < STORE_ATTR_TYPE_NUM
;)
1322 STORE_ATTR_INFO_attr_free(attrs
, i
);
1323 OPENSSL_free(attrs
);
1327 char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
)
1331 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR
,
1332 ERR_R_PASSED_NULL_PARAMETER
);
1335 if (ATTR_IS_SET(attrs
,code
))
1336 return attrs
->values
[code
].cstring
;
1337 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR
,
1341 unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO
*attrs
,
1342 STORE_ATTR_TYPES code
)
1346 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR
,
1347 ERR_R_PASSED_NULL_PARAMETER
);
1350 if (ATTR_IS_SET(attrs
,code
))
1351 return attrs
->values
[code
].sha1string
;
1352 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR
,
1356 X509_NAME
*STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
)
1360 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN
,
1361 ERR_R_PASSED_NULL_PARAMETER
);
1364 if (ATTR_IS_SET(attrs
,code
))
1365 return attrs
->values
[code
].dn
;
1366 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN
,
1370 BIGNUM
*STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
)
1374 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER
,
1375 ERR_R_PASSED_NULL_PARAMETER
);
1378 if (ATTR_IS_SET(attrs
,code
))
1379 return attrs
->values
[code
].number
;
1380 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER
,
1384 int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1385 char *cstr
, size_t cstr_size
)
1389 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR
,
1390 ERR_R_PASSED_NULL_PARAMETER
);
1393 if (!ATTR_IS_SET(attrs
,code
))
1395 if ((attrs
->values
[code
].cstring
= BUF_strndup(cstr
, cstr_size
)))
1397 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR
,
1398 ERR_R_MALLOC_FAILURE
);
1401 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR
, STORE_R_ALREADY_HAS_A_VALUE
);
1404 int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1405 unsigned char *sha1str
, size_t sha1str_size
)
1409 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR
,
1410 ERR_R_PASSED_NULL_PARAMETER
);
1413 if (!ATTR_IS_SET(attrs
,code
))
1415 if ((attrs
->values
[code
].sha1string
=
1416 (unsigned char *)BUF_memdup(sha1str
,
1419 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR
,
1420 ERR_R_MALLOC_FAILURE
);
1423 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR
, STORE_R_ALREADY_HAS_A_VALUE
);
1426 int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1431 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN
,
1432 ERR_R_PASSED_NULL_PARAMETER
);
1435 if (!ATTR_IS_SET(attrs
,code
))
1437 if ((attrs
->values
[code
].dn
= X509_NAME_dup(dn
)))
1439 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN
,
1440 ERR_R_MALLOC_FAILURE
);
1443 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN
, STORE_R_ALREADY_HAS_A_VALUE
);
1446 int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1451 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER
,
1452 ERR_R_PASSED_NULL_PARAMETER
);
1455 if (!ATTR_IS_SET(attrs
,code
))
1457 if ((attrs
->values
[code
].number
= BN_dup(number
)))
1459 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER
,
1460 ERR_R_MALLOC_FAILURE
);
1463 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER
, STORE_R_ALREADY_HAS_A_VALUE
);
1466 int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1467 char *cstr
, size_t cstr_size
)
1471 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR
,
1472 ERR_R_PASSED_NULL_PARAMETER
);
1475 if (ATTR_IS_SET(attrs
,code
))
1477 OPENSSL_free(attrs
->values
[code
].cstring
);
1478 attrs
->values
[code
].cstring
= NULL
;
1479 CLEAR_ATTRBIT(attrs
, code
);
1481 return STORE_ATTR_INFO_set_cstr(attrs
, code
, cstr
, cstr_size
);
1483 int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1484 unsigned char *sha1str
, size_t sha1str_size
)
1488 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR
,
1489 ERR_R_PASSED_NULL_PARAMETER
);
1492 if (ATTR_IS_SET(attrs
,code
))
1494 OPENSSL_free(attrs
->values
[code
].sha1string
);
1495 attrs
->values
[code
].sha1string
= NULL
;
1496 CLEAR_ATTRBIT(attrs
, code
);
1498 return STORE_ATTR_INFO_set_sha1str(attrs
, code
, sha1str
, sha1str_size
);
1500 int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1505 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN
,
1506 ERR_R_PASSED_NULL_PARAMETER
);
1509 if (ATTR_IS_SET(attrs
,code
))
1511 OPENSSL_free(attrs
->values
[code
].dn
);
1512 attrs
->values
[code
].dn
= NULL
;
1513 CLEAR_ATTRBIT(attrs
, code
);
1515 return STORE_ATTR_INFO_set_dn(attrs
, code
, dn
);
1517 int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO
*attrs
, STORE_ATTR_TYPES code
,
1522 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER
,
1523 ERR_R_PASSED_NULL_PARAMETER
);
1526 if (ATTR_IS_SET(attrs
,code
))
1528 OPENSSL_free(attrs
->values
[code
].number
);
1529 attrs
->values
[code
].number
= NULL
;
1530 CLEAR_ATTRBIT(attrs
, code
);
1532 return STORE_ATTR_INFO_set_number(attrs
, code
, number
);
1535 struct attr_list_ctx_st
1537 OPENSSL_ITEM
*attributes
;
1539 void *STORE_parse_attrs_start(OPENSSL_ITEM
*attributes
)
1543 struct attr_list_ctx_st
*context
=
1544 (struct attr_list_ctx_st
*)OPENSSL_malloc(sizeof(struct attr_list_ctx_st
));
1546 context
->attributes
= attributes
;
1548 STOREerr(STORE_F_STORE_PARSE_ATTRS_START
,
1549 ERR_R_MALLOC_FAILURE
);
1552 STOREerr(STORE_F_STORE_PARSE_ATTRS_START
, ERR_R_PASSED_NULL_PARAMETER
);
1555 STORE_ATTR_INFO
*STORE_parse_attrs_next(void *handle
)
1557 struct attr_list_ctx_st
*context
= (struct attr_list_ctx_st
*)handle
;
1559 if (context
&& context
->attributes
)
1561 STORE_ATTR_INFO
*attrs
= NULL
;
1563 while(context
->attributes
1564 && context
->attributes
->code
!= STORE_ATTR_OR
1565 && context
->attributes
->code
!= STORE_ATTR_END
)
1567 switch(context
->attributes
->code
)
1569 case STORE_ATTR_FRIENDLYNAME
:
1570 case STORE_ATTR_EMAIL
:
1571 case STORE_ATTR_FILENAME
:
1572 if (!attrs
) attrs
= STORE_ATTR_INFO_new();
1575 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT
,
1576 ERR_R_MALLOC_FAILURE
);
1579 STORE_ATTR_INFO_set_cstr(attrs
,
1580 context
->attributes
->code
,
1581 context
->attributes
->value
,
1582 context
->attributes
->value_size
);
1584 case STORE_ATTR_KEYID
:
1585 case STORE_ATTR_ISSUERKEYID
:
1586 case STORE_ATTR_SUBJECTKEYID
:
1587 case STORE_ATTR_ISSUERSERIALHASH
:
1588 case STORE_ATTR_CERTHASH
:
1589 if (!attrs
) attrs
= STORE_ATTR_INFO_new();
1592 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT
,
1593 ERR_R_MALLOC_FAILURE
);
1596 STORE_ATTR_INFO_set_sha1str(attrs
,
1597 context
->attributes
->code
,
1598 context
->attributes
->value
,
1599 context
->attributes
->value_size
);
1601 case STORE_ATTR_ISSUER
:
1602 case STORE_ATTR_SUBJECT
:
1603 if (!attrs
) attrs
= STORE_ATTR_INFO_new();
1606 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT
,
1607 ERR_R_MALLOC_FAILURE
);
1610 STORE_ATTR_INFO_modify_dn(attrs
,
1611 context
->attributes
->code
,
1612 context
->attributes
->value
);
1614 case STORE_ATTR_SERIAL
:
1615 if (!attrs
) attrs
= STORE_ATTR_INFO_new();
1618 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT
,
1619 ERR_R_MALLOC_FAILURE
);
1622 STORE_ATTR_INFO_modify_number(attrs
,
1623 context
->attributes
->code
,
1624 context
->attributes
->value
);
1627 context
->attributes
++;
1629 if (context
->attributes
->code
== STORE_ATTR_OR
)
1630 context
->attributes
++;
1633 while(context
->attributes
1634 && context
->attributes
->code
!= STORE_ATTR_OR
1635 && context
->attributes
->code
!= STORE_ATTR_END
)
1636 context
->attributes
++;
1637 if (context
->attributes
->code
== STORE_ATTR_OR
)
1638 context
->attributes
++;
1641 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT
, ERR_R_PASSED_NULL_PARAMETER
);
1644 int STORE_parse_attrs_end(void *handle
)
1646 struct attr_list_ctx_st
*context
= (struct attr_list_ctx_st
*)handle
;
1648 if (context
&& context
->attributes
)
1651 OPENSSL_ITEM
*attributes
= context
->attributes
;
1653 OPENSSL_free(context
);
1656 STOREerr(STORE_F_STORE_PARSE_ATTRS_END
, ERR_R_PASSED_NULL_PARAMETER
);
1660 int STORE_parse_attrs_endp(void *handle
)
1662 struct attr_list_ctx_st
*context
= (struct attr_list_ctx_st
*)handle
;
1664 if (context
&& context
->attributes
)
1666 return context
->attributes
->code
== STORE_ATTR_END
;
1668 STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP
, ERR_R_PASSED_NULL_PARAMETER
);
1672 static int attr_info_compare_compute_range(
1673 const unsigned char *abits
, const unsigned char *bbits
,
1674 unsigned int *alowp
, unsigned int *ahighp
,
1675 unsigned int *blowp
, unsigned int *bhighp
)
1677 unsigned int alow
= (unsigned int)-1, ahigh
= 0;
1678 unsigned int blow
= (unsigned int)-1, bhigh
= 0;
1681 for (i
= 0; i
< (STORE_ATTR_TYPE_NUM
+ 8) / 8; i
++, abits
++, bbits
++)
1685 if (*abits
< *bbits
) res
= -1;
1686 if (*abits
> *bbits
) res
= 1;
1690 if (alow
== (unsigned int)-1)
1693 if (!(*abits
& 0x01)) alow
++;
1694 if (!(*abits
& 0x02)) alow
++;
1695 if (!(*abits
& 0x04)) alow
++;
1696 if (!(*abits
& 0x08)) alow
++;
1697 if (!(*abits
& 0x10)) alow
++;
1698 if (!(*abits
& 0x20)) alow
++;
1699 if (!(*abits
& 0x40)) alow
++;
1702 if (!(*abits
& 0x80)) ahigh
++;
1703 if (!(*abits
& 0x40)) ahigh
++;
1704 if (!(*abits
& 0x20)) ahigh
++;
1705 if (!(*abits
& 0x10)) ahigh
++;
1706 if (!(*abits
& 0x08)) ahigh
++;
1707 if (!(*abits
& 0x04)) ahigh
++;
1708 if (!(*abits
& 0x02)) ahigh
++;
1712 if (blow
== (unsigned int)-1)
1715 if (!(*bbits
& 0x01)) blow
++;
1716 if (!(*bbits
& 0x02)) blow
++;
1717 if (!(*bbits
& 0x04)) blow
++;
1718 if (!(*bbits
& 0x08)) blow
++;
1719 if (!(*bbits
& 0x10)) blow
++;
1720 if (!(*bbits
& 0x20)) blow
++;
1721 if (!(*bbits
& 0x40)) blow
++;
1724 if (!(*bbits
& 0x80)) bhigh
++;
1725 if (!(*bbits
& 0x40)) bhigh
++;
1726 if (!(*bbits
& 0x20)) bhigh
++;
1727 if (!(*bbits
& 0x10)) bhigh
++;
1728 if (!(*bbits
& 0x08)) bhigh
++;
1729 if (!(*bbits
& 0x04)) bhigh
++;
1730 if (!(*bbits
& 0x02)) bhigh
++;
1733 if (ahigh
+ alow
< bhigh
+ blow
) res
= -1;
1734 if (ahigh
+ alow
> bhigh
+ blow
) res
= 1;
1735 if (alowp
) *alowp
= alow
;
1736 if (ahighp
) *ahighp
= ahigh
;
1737 if (blowp
) *blowp
= blow
;
1738 if (bhighp
) *bhighp
= bhigh
;
1742 int STORE_ATTR_INFO_compare(const STORE_ATTR_INFO
* const *a
,
1743 const STORE_ATTR_INFO
* const *b
)
1745 if (a
== b
) return 0;
1748 return attr_info_compare_compute_range((*a
)->set
, (*b
)->set
, 0, 0, 0, 0);
1751 int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO
*a
, STORE_ATTR_INFO
*b
)
1753 unsigned int alow
, ahigh
, blow
, bhigh
;
1755 if (a
== b
) return 1;
1758 attr_info_compare_compute_range(a
->set
, b
->set
,
1759 &alow
, &ahigh
, &blow
, &bhigh
);
1760 if (alow
>= blow
&& ahigh
<= bhigh
)
1765 int STORE_ATTR_INFO_in(STORE_ATTR_INFO
*a
, STORE_ATTR_INFO
*b
)
1767 unsigned char *abits
, *bbits
;
1770 if (a
== b
) return 1;
1775 for (i
= 0; i
< (STORE_ATTR_TYPE_NUM
+ 8) / 8; i
++, abits
++, bbits
++)
1777 if (*abits
&& (*bbits
& *abits
) != *abits
)
1783 int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO
*a
, STORE_ATTR_INFO
*b
)
1787 if (a
== b
) return 1;
1788 if (!STORE_ATTR_INFO_in(a
, b
)) return 0;
1789 for (i
= 1; i
< STORE_ATTR_TYPE_NUM
; i
++)
1790 if (ATTR_IS_SET(a
, i
))
1794 case STORE_ATTR_FRIENDLYNAME
:
1795 case STORE_ATTR_EMAIL
:
1796 case STORE_ATTR_FILENAME
:
1797 if (strcmp(a
->values
[i
].cstring
,
1798 b
->values
[i
].cstring
))
1801 case STORE_ATTR_KEYID
:
1802 case STORE_ATTR_ISSUERKEYID
:
1803 case STORE_ATTR_SUBJECTKEYID
:
1804 case STORE_ATTR_ISSUERSERIALHASH
:
1805 case STORE_ATTR_CERTHASH
:
1806 if (memcmp(a
->values
[i
].sha1string
,
1807 b
->values
[i
].sha1string
,
1811 case STORE_ATTR_ISSUER
:
1812 case STORE_ATTR_SUBJECT
:
1813 if (X509_NAME_cmp(a
->values
[i
].dn
,
1817 case STORE_ATTR_SERIAL
:
1818 if (BN_cmp(a
->values
[i
].number
,
1819 b
->values
[i
].number
))