Path: blob/main/crypto/heimdal/lib/hx509/hx_locl.h
34878 views
/*1* Copyright (c) 2004 - 2006 Kungliga Tekniska Högskolan2* (Royal Institute of Technology, Stockholm, Sweden).3* All rights reserved.4*5* Redistribution and use in source and binary forms, with or without6* modification, are permitted provided that the following conditions7* are met:8*9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11*12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* 3. Neither the name of the Institute nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*/3233/* $Id$ */3435#include <config.h>3637#include <stdio.h>38#include <stdlib.h>39#include <ctype.h>40#include <errno.h>41#ifdef HAVE_STRINGS_H42#include <strings.h>43#endif44#include <assert.h>45#include <stdarg.h>46#include <err.h>47#include <limits.h>4849#include <roken.h>5051#include <getarg.h>52#include <base64.h>53#include <hex.h>54#include <com_err.h>55#include <parse_units.h>56#include <parse_bytes.h>5758#include <krb5-types.h>5960#include <rfc2459_asn1.h>61#include <cms_asn1.h>62#include <pkcs8_asn1.h>63#include <pkcs9_asn1.h>64#include <pkcs12_asn1.h>65#include <ocsp_asn1.h>66#include <pkcs10_asn1.h>67#include <asn1_err.h>68#include <pkinit_asn1.h>6970#include <der.h>7172#define HC_DEPRECATED_CRYPTO73#include "crypto-headers.h"7475struct hx509_keyset_ops;76struct hx509_collector;77struct hx509_generate_private_context;78typedef struct hx509_path hx509_path;7980#include <hx509.h>8182typedef void (*_hx509_cert_release_func)(struct hx509_cert_data *, void *);838485#include "sel.h"8687#include <hx509-private.h>88#include <hx509_err.h>8990struct hx509_peer_info {91hx509_cert cert;92AlgorithmIdentifier *val;93size_t len;94};9596#define HX509_CERTS_FIND_SERIALNUMBER 197#define HX509_CERTS_FIND_ISSUER 298#define HX509_CERTS_FIND_SUBJECT 499#define HX509_CERTS_FIND_ISSUER_KEY_ID 8100#define HX509_CERTS_FIND_SUBJECT_KEY_ID 16101102struct hx509_name_data {103Name der_name;104};105106struct hx509_path {107size_t len;108hx509_cert *val;109};110111struct hx509_query_data {112int match;113#define HX509_QUERY_FIND_ISSUER_CERT 0x000001114#define HX509_QUERY_MATCH_SERIALNUMBER 0x000002115#define HX509_QUERY_MATCH_ISSUER_NAME 0x000004116#define HX509_QUERY_MATCH_SUBJECT_NAME 0x000008117#define HX509_QUERY_MATCH_SUBJECT_KEY_ID 0x000010118#define HX509_QUERY_MATCH_ISSUER_ID 0x000020119#define HX509_QUERY_PRIVATE_KEY 0x000040120#define HX509_QUERY_KU_ENCIPHERMENT 0x000080121#define HX509_QUERY_KU_DIGITALSIGNATURE 0x000100122#define HX509_QUERY_KU_KEYCERTSIGN 0x000200123#define HX509_QUERY_KU_CRLSIGN 0x000400124#define HX509_QUERY_KU_NONREPUDIATION 0x000800125#define HX509_QUERY_KU_KEYAGREEMENT 0x001000126#define HX509_QUERY_KU_DATAENCIPHERMENT 0x002000127#define HX509_QUERY_ANCHOR 0x004000128#define HX509_QUERY_MATCH_CERTIFICATE 0x008000129#define HX509_QUERY_MATCH_LOCAL_KEY_ID 0x010000130#define HX509_QUERY_NO_MATCH_PATH 0x020000131#define HX509_QUERY_MATCH_FRIENDLY_NAME 0x040000132#define HX509_QUERY_MATCH_FUNCTION 0x080000133#define HX509_QUERY_MATCH_KEY_HASH_SHA1 0x100000134#define HX509_QUERY_MATCH_TIME 0x200000135#define HX509_QUERY_MATCH_EKU 0x400000136#define HX509_QUERY_MATCH_EXPR 0x800000137#define HX509_QUERY_MASK 0xffffff138Certificate *subject;139Certificate *certificate;140heim_integer *serial;141heim_octet_string *subject_id;142heim_octet_string *local_key_id;143Name *issuer_name;144Name *subject_name;145hx509_path *path;146char *friendlyname;147int (*cmp_func)(hx509_context, hx509_cert, void *);148void *cmp_func_ctx;149heim_octet_string *keyhash_sha1;150time_t timenow;151heim_oid *eku;152struct hx_expr *expr;153};154155struct hx509_keyset_ops {156const char *name;157int flags;158int (*init)(hx509_context, hx509_certs, void **,159int, const char *, hx509_lock);160int (*store)(hx509_context, hx509_certs, void *, int, hx509_lock);161int (*free)(hx509_certs, void *);162int (*add)(hx509_context, hx509_certs, void *, hx509_cert);163int (*query)(hx509_context, hx509_certs, void *,164const hx509_query *, hx509_cert *);165int (*iter_start)(hx509_context, hx509_certs, void *, void **);166int (*iter)(hx509_context, hx509_certs, void *, void *, hx509_cert *);167int (*iter_end)(hx509_context, hx509_certs, void *, void *);168int (*printinfo)(hx509_context, hx509_certs,169void *, int (*)(void *, const char *), void *);170int (*getkeys)(hx509_context, hx509_certs, void *, hx509_private_key **);171int (*addkey)(hx509_context, hx509_certs, void *, hx509_private_key);172};173174struct _hx509_password {175size_t len;176char **val;177};178179extern hx509_lock _hx509_empty_lock;180181struct hx509_context_data {182struct hx509_keyset_ops **ks_ops;183int ks_num_ops;184int flags;185#define HX509_CTX_VERIFY_MISSING_OK 1186int ocsp_time_diff;187#define HX509_DEFAULT_OCSP_TIME_DIFF (5*60)188hx509_error error;189struct et_list *et_list;190char *querystat;191hx509_certs default_trust_anchors;192};193194/* _hx509_calculate_path flag field */195#define HX509_CALCULATE_PATH_NO_ANCHOR 1196197/* environment */198struct hx509_env_data {199enum { env_string, env_list } type;200char *name;201struct hx509_env_data *next;202union {203char *string;204struct hx509_env_data *list;205} u;206};207208209extern const AlgorithmIdentifier * _hx509_crypto_default_sig_alg;210extern const AlgorithmIdentifier * _hx509_crypto_default_digest_alg;211extern const AlgorithmIdentifier * _hx509_crypto_default_secret_alg;212213/*214* Configurable options215*/216217#ifdef __APPLE__218#define HX509_DEFAULT_ANCHORS "KEYCHAIN:system-anchors"219#endif220221222