1*ebfedea0SLionel Sambuc /* $NetBSD: hx_locl.h,v 1.1.1.2 2011/04/14 14:08:56 elric Exp $ */ 2*ebfedea0SLionel Sambuc 3*ebfedea0SLionel Sambuc /* 4*ebfedea0SLionel Sambuc * Copyright (c) 2004 - 2006 Kungliga Tekniska Högskolan 5*ebfedea0SLionel Sambuc * (Royal Institute of Technology, Stockholm, Sweden). 6*ebfedea0SLionel Sambuc * All rights reserved. 7*ebfedea0SLionel Sambuc * 8*ebfedea0SLionel Sambuc * Redistribution and use in source and binary forms, with or without 9*ebfedea0SLionel Sambuc * modification, are permitted provided that the following conditions 10*ebfedea0SLionel Sambuc * are met: 11*ebfedea0SLionel Sambuc * 12*ebfedea0SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 13*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer. 14*ebfedea0SLionel Sambuc * 15*ebfedea0SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 16*ebfedea0SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 17*ebfedea0SLionel Sambuc * documentation and/or other materials provided with the distribution. 18*ebfedea0SLionel Sambuc * 19*ebfedea0SLionel Sambuc * 3. Neither the name of the Institute nor the names of its contributors 20*ebfedea0SLionel Sambuc * may be used to endorse or promote products derived from this software 21*ebfedea0SLionel Sambuc * without specific prior written permission. 22*ebfedea0SLionel Sambuc * 23*ebfedea0SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24*ebfedea0SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25*ebfedea0SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26*ebfedea0SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27*ebfedea0SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28*ebfedea0SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29*ebfedea0SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30*ebfedea0SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31*ebfedea0SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32*ebfedea0SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33*ebfedea0SLionel Sambuc * SUCH DAMAGE. 34*ebfedea0SLionel Sambuc */ 35*ebfedea0SLionel Sambuc 36*ebfedea0SLionel Sambuc /* Id */ 37*ebfedea0SLionel Sambuc 38*ebfedea0SLionel Sambuc #include <config.h> 39*ebfedea0SLionel Sambuc 40*ebfedea0SLionel Sambuc #include <stdio.h> 41*ebfedea0SLionel Sambuc #include <stdlib.h> 42*ebfedea0SLionel Sambuc #include <ctype.h> 43*ebfedea0SLionel Sambuc #include <errno.h> 44*ebfedea0SLionel Sambuc #ifdef HAVE_STRINGS_H 45*ebfedea0SLionel Sambuc #include <strings.h> 46*ebfedea0SLionel Sambuc #endif 47*ebfedea0SLionel Sambuc #include <assert.h> 48*ebfedea0SLionel Sambuc #include <stdarg.h> 49*ebfedea0SLionel Sambuc #include <err.h> 50*ebfedea0SLionel Sambuc #include <limits.h> 51*ebfedea0SLionel Sambuc 52*ebfedea0SLionel Sambuc #include <krb5/roken.h> 53*ebfedea0SLionel Sambuc 54*ebfedea0SLionel Sambuc #include <krb5/getarg.h> 55*ebfedea0SLionel Sambuc #include <krb5/base64.h> 56*ebfedea0SLionel Sambuc #include <krb5/hex.h> 57*ebfedea0SLionel Sambuc #include <krb5/com_err.h> 58*ebfedea0SLionel Sambuc #include <krb5/parse_units.h> 59*ebfedea0SLionel Sambuc #include <krb5/parse_bytes.h> 60*ebfedea0SLionel Sambuc 61*ebfedea0SLionel Sambuc #include <krb5/krb5-types.h> 62*ebfedea0SLionel Sambuc 63*ebfedea0SLionel Sambuc #include <krb5/rfc2459_asn1.h> 64*ebfedea0SLionel Sambuc #include <krb5/cms_asn1.h> 65*ebfedea0SLionel Sambuc #include <krb5/pkcs8_asn1.h> 66*ebfedea0SLionel Sambuc #include <krb5/pkcs9_asn1.h> 67*ebfedea0SLionel Sambuc #include <krb5/pkcs12_asn1.h> 68*ebfedea0SLionel Sambuc #include <krb5/ocsp_asn1.h> 69*ebfedea0SLionel Sambuc #include <krb5/pkcs10_asn1.h> 70*ebfedea0SLionel Sambuc #include <krb5/asn1_err.h> 71*ebfedea0SLionel Sambuc #include <krb5/pkinit_asn1.h> 72*ebfedea0SLionel Sambuc 73*ebfedea0SLionel Sambuc #include <krb5/der.h> 74*ebfedea0SLionel Sambuc 75*ebfedea0SLionel Sambuc #define HC_DEPRECATED_CRYPTO 76*ebfedea0SLionel Sambuc #include "crypto-headers.h" 77*ebfedea0SLionel Sambuc 78*ebfedea0SLionel Sambuc struct hx509_keyset_ops; 79*ebfedea0SLionel Sambuc struct hx509_collector; 80*ebfedea0SLionel Sambuc struct hx509_generate_private_context; 81*ebfedea0SLionel Sambuc typedef struct hx509_path hx509_path; 82*ebfedea0SLionel Sambuc 83*ebfedea0SLionel Sambuc #include <krb5/hx509.h> 84*ebfedea0SLionel Sambuc 85*ebfedea0SLionel Sambuc typedef void (*_hx509_cert_release_func)(struct hx509_cert_data *, void *); 86*ebfedea0SLionel Sambuc 87*ebfedea0SLionel Sambuc 88*ebfedea0SLionel Sambuc #include "sel.h" 89*ebfedea0SLionel Sambuc 90*ebfedea0SLionel Sambuc #include <hx509-private.h> 91*ebfedea0SLionel Sambuc #include <krb5/hx509_err.h> 92*ebfedea0SLionel Sambuc 93*ebfedea0SLionel Sambuc struct hx509_peer_info { 94*ebfedea0SLionel Sambuc hx509_cert cert; 95*ebfedea0SLionel Sambuc AlgorithmIdentifier *val; 96*ebfedea0SLionel Sambuc size_t len; 97*ebfedea0SLionel Sambuc }; 98*ebfedea0SLionel Sambuc 99*ebfedea0SLionel Sambuc #define HX509_CERTS_FIND_SERIALNUMBER 1 100*ebfedea0SLionel Sambuc #define HX509_CERTS_FIND_ISSUER 2 101*ebfedea0SLionel Sambuc #define HX509_CERTS_FIND_SUBJECT 4 102*ebfedea0SLionel Sambuc #define HX509_CERTS_FIND_ISSUER_KEY_ID 8 103*ebfedea0SLionel Sambuc #define HX509_CERTS_FIND_SUBJECT_KEY_ID 16 104*ebfedea0SLionel Sambuc 105*ebfedea0SLionel Sambuc struct hx509_name_data { 106*ebfedea0SLionel Sambuc Name der_name; 107*ebfedea0SLionel Sambuc }; 108*ebfedea0SLionel Sambuc 109*ebfedea0SLionel Sambuc struct hx509_path { 110*ebfedea0SLionel Sambuc size_t len; 111*ebfedea0SLionel Sambuc hx509_cert *val; 112*ebfedea0SLionel Sambuc }; 113*ebfedea0SLionel Sambuc 114*ebfedea0SLionel Sambuc struct hx509_query_data { 115*ebfedea0SLionel Sambuc int match; 116*ebfedea0SLionel Sambuc #define HX509_QUERY_FIND_ISSUER_CERT 0x000001 117*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_SERIALNUMBER 0x000002 118*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_ISSUER_NAME 0x000004 119*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_SUBJECT_NAME 0x000008 120*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_SUBJECT_KEY_ID 0x000010 121*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_ISSUER_ID 0x000020 122*ebfedea0SLionel Sambuc #define HX509_QUERY_PRIVATE_KEY 0x000040 123*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_ENCIPHERMENT 0x000080 124*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_DIGITALSIGNATURE 0x000100 125*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_KEYCERTSIGN 0x000200 126*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_CRLSIGN 0x000400 127*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_NONREPUDIATION 0x000800 128*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_KEYAGREEMENT 0x001000 129*ebfedea0SLionel Sambuc #define HX509_QUERY_KU_DATAENCIPHERMENT 0x002000 130*ebfedea0SLionel Sambuc #define HX509_QUERY_ANCHOR 0x004000 131*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_CERTIFICATE 0x008000 132*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_LOCAL_KEY_ID 0x010000 133*ebfedea0SLionel Sambuc #define HX509_QUERY_NO_MATCH_PATH 0x020000 134*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_FRIENDLY_NAME 0x040000 135*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_FUNCTION 0x080000 136*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_KEY_HASH_SHA1 0x100000 137*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_TIME 0x200000 138*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_EKU 0x400000 139*ebfedea0SLionel Sambuc #define HX509_QUERY_MATCH_EXPR 0x800000 140*ebfedea0SLionel Sambuc #define HX509_QUERY_MASK 0xffffff 141*ebfedea0SLionel Sambuc Certificate *subject; 142*ebfedea0SLionel Sambuc Certificate *certificate; 143*ebfedea0SLionel Sambuc heim_integer *serial; 144*ebfedea0SLionel Sambuc heim_octet_string *subject_id; 145*ebfedea0SLionel Sambuc heim_octet_string *local_key_id; 146*ebfedea0SLionel Sambuc Name *issuer_name; 147*ebfedea0SLionel Sambuc Name *subject_name; 148*ebfedea0SLionel Sambuc hx509_path *path; 149*ebfedea0SLionel Sambuc char *friendlyname; 150*ebfedea0SLionel Sambuc int (*cmp_func)(hx509_context, hx509_cert, void *); 151*ebfedea0SLionel Sambuc void *cmp_func_ctx; 152*ebfedea0SLionel Sambuc heim_octet_string *keyhash_sha1; 153*ebfedea0SLionel Sambuc time_t timenow; 154*ebfedea0SLionel Sambuc heim_oid *eku; 155*ebfedea0SLionel Sambuc struct hx_expr *expr; 156*ebfedea0SLionel Sambuc }; 157*ebfedea0SLionel Sambuc 158*ebfedea0SLionel Sambuc struct hx509_keyset_ops { 159*ebfedea0SLionel Sambuc const char *name; 160*ebfedea0SLionel Sambuc int flags; 161*ebfedea0SLionel Sambuc int (*init)(hx509_context, hx509_certs, void **, 162*ebfedea0SLionel Sambuc int, const char *, hx509_lock); 163*ebfedea0SLionel Sambuc int (*store)(hx509_context, hx509_certs, void *, int, hx509_lock); 164*ebfedea0SLionel Sambuc int (*free)(hx509_certs, void *); 165*ebfedea0SLionel Sambuc int (*add)(hx509_context, hx509_certs, void *, hx509_cert); 166*ebfedea0SLionel Sambuc int (*query)(hx509_context, hx509_certs, void *, 167*ebfedea0SLionel Sambuc const hx509_query *, hx509_cert *); 168*ebfedea0SLionel Sambuc int (*iter_start)(hx509_context, hx509_certs, void *, void **); 169*ebfedea0SLionel Sambuc int (*iter)(hx509_context, hx509_certs, void *, void *, hx509_cert *); 170*ebfedea0SLionel Sambuc int (*iter_end)(hx509_context, hx509_certs, void *, void *); 171*ebfedea0SLionel Sambuc int (*printinfo)(hx509_context, hx509_certs, 172*ebfedea0SLionel Sambuc void *, int (*)(void *, const char *), void *); 173*ebfedea0SLionel Sambuc int (*getkeys)(hx509_context, hx509_certs, void *, hx509_private_key **); 174*ebfedea0SLionel Sambuc int (*addkey)(hx509_context, hx509_certs, void *, hx509_private_key); 175*ebfedea0SLionel Sambuc }; 176*ebfedea0SLionel Sambuc 177*ebfedea0SLionel Sambuc struct _hx509_password { 178*ebfedea0SLionel Sambuc size_t len; 179*ebfedea0SLionel Sambuc char **val; 180*ebfedea0SLionel Sambuc }; 181*ebfedea0SLionel Sambuc 182*ebfedea0SLionel Sambuc extern hx509_lock _hx509_empty_lock; 183*ebfedea0SLionel Sambuc 184*ebfedea0SLionel Sambuc struct hx509_context_data { 185*ebfedea0SLionel Sambuc struct hx509_keyset_ops **ks_ops; 186*ebfedea0SLionel Sambuc int ks_num_ops; 187*ebfedea0SLionel Sambuc int flags; 188*ebfedea0SLionel Sambuc #define HX509_CTX_VERIFY_MISSING_OK 1 189*ebfedea0SLionel Sambuc int ocsp_time_diff; 190*ebfedea0SLionel Sambuc #define HX509_DEFAULT_OCSP_TIME_DIFF (5*60) 191*ebfedea0SLionel Sambuc hx509_error error; 192*ebfedea0SLionel Sambuc struct et_list *et_list; 193*ebfedea0SLionel Sambuc char *querystat; 194*ebfedea0SLionel Sambuc hx509_certs default_trust_anchors; 195*ebfedea0SLionel Sambuc }; 196*ebfedea0SLionel Sambuc 197*ebfedea0SLionel Sambuc /* _hx509_calculate_path flag field */ 198*ebfedea0SLionel Sambuc #define HX509_CALCULATE_PATH_NO_ANCHOR 1 199*ebfedea0SLionel Sambuc 200*ebfedea0SLionel Sambuc /* environment */ 201*ebfedea0SLionel Sambuc struct hx509_env_data { 202*ebfedea0SLionel Sambuc enum { env_string, env_list } type; 203*ebfedea0SLionel Sambuc char *name; 204*ebfedea0SLionel Sambuc struct hx509_env_data *next; 205*ebfedea0SLionel Sambuc union { 206*ebfedea0SLionel Sambuc char *string; 207*ebfedea0SLionel Sambuc struct hx509_env_data *list; 208*ebfedea0SLionel Sambuc } u; 209*ebfedea0SLionel Sambuc }; 210*ebfedea0SLionel Sambuc 211*ebfedea0SLionel Sambuc 212*ebfedea0SLionel Sambuc extern const AlgorithmIdentifier * _hx509_crypto_default_sig_alg; 213*ebfedea0SLionel Sambuc extern const AlgorithmIdentifier * _hx509_crypto_default_digest_alg; 214*ebfedea0SLionel Sambuc extern const AlgorithmIdentifier * _hx509_crypto_default_secret_alg; 215*ebfedea0SLionel Sambuc 216*ebfedea0SLionel Sambuc /* 217*ebfedea0SLionel Sambuc * Configurable options 218*ebfedea0SLionel Sambuc */ 219*ebfedea0SLionel Sambuc 220*ebfedea0SLionel Sambuc #ifdef __APPLE__ 221*ebfedea0SLionel Sambuc #define HX509_DEFAULT_ANCHORS "KEYCHAIN:system-anchors" 222*ebfedea0SLionel Sambuc #endif 223