Path: blob/main/crypto/krb5/src/plugins/preauth/pkinit/pkinit.h
34923 views
/*1* COPYRIGHT (C) 2006,20072* THE REGENTS OF THE UNIVERSITY OF MICHIGAN3* ALL RIGHTS RESERVED4*5* Permission is granted to use, copy, create derivative works6* and redistribute this software and such derivative works7* for any purpose, so long as the name of The University of8* Michigan is not used in any advertising or publicity9* pertaining to the use of distribution of this software10* without specific, written prior authorization. If the11* above copyright notice or any other identification of the12* University of Michigan is included in any copy of any13* portion of this software, then the disclaimer below must14* also be included.15*16* THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION17* FROM THE UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY18* PURPOSE, AND WITHOUT WARRANTY BY THE UNIVERSITY OF19* MICHIGAN OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING20* WITHOUT LIMITATION THE IMPLIED WARRANTIES OF21* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE22* REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE LIABLE23* FOR ANY DAMAGES, INCLUDING SPECIAL, INDIRECT, INCIDENTAL, OR24* CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM ARISING25* OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN26* IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF27* SUCH DAMAGES.28*/2930#ifndef _PKINIT_H31#define _PKINIT_H3233#include <k5-platform.h>34#include <krb5/krb5.h>35#include <krb5/preauth_plugin.h>36#include <k5-int-pkinit.h>37#include <profile.h>38#include "pkinit_accessor.h"39#include "pkinit_trace.h"4041#ifndef WITHOUT_PKCS1142#include "pkcs11.h"4344#define PK_SIGLEN_GUESS 100045#define PK_NOSLOT 99999946#endif4748#define DH_PROTOCOL 149#define RSA_PROTOCOL 25051#define TD_TRUSTED_CERTIFIERS 10452#define TD_INVALID_CERTIFICATES 10553#define TD_DH_PARAMETERS 1095455#define PKINIT_CTX_MAGIC 0x0555121256#define PKINIT_REQ_CTX_MAGIC 0xdeadbeef57#define PKINIT_DEFERRED_ID_MAGIC 0x3ca20d215859#define PKINIT_DEFAULT_DH_MIN_BITS 204860#define PKINIT_DH_MIN_CONFIG_BITS 102461/* Rough finite-field bit strength equivalents for the elliptic curve groups */62#define PKINIT_DH_P256_BITS 307263#define PKINIT_DH_P384_BITS 768064#define PKINIT_DH_P521_BITS 153606566#define KRB5_CONF_KDCDEFAULTS "kdcdefaults"67#define KRB5_CONF_LIBDEFAULTS "libdefaults"68#define KRB5_CONF_REALMS "realms"69#define KRB5_CONF_PKINIT_ALLOW_UPN "pkinit_allow_upn"70#define KRB5_CONF_PKINIT_ANCHORS "pkinit_anchors"71#define KRB5_CONF_PKINIT_INDICATOR "pkinit_indicator"72#define KRB5_CONF_PKINIT_CERT_MATCH "pkinit_cert_match"73#define KRB5_CONF_PKINIT_DH_MIN_BITS "pkinit_dh_min_bits"74#define KRB5_CONF_PKINIT_EKU_CHECKING "pkinit_eku_checking"75#define KRB5_CONF_PKINIT_IDENTITIES "pkinit_identities"76#define KRB5_CONF_PKINIT_IDENTITY "pkinit_identity"77#define KRB5_CONF_PKINIT_KDC_HOSTNAME "pkinit_kdc_hostname"78/* pkinit_kdc_ocsp has been removed */79#define KRB5_CONF_PKINIT_KDC_OCSP "pkinit_kdc_ocsp"80#define KRB5_CONF_PKINIT_POOL "pkinit_pool"81#define KRB5_CONF_PKINIT_REQUIRE_CRL_CHECKING "pkinit_require_crl_checking"82#define KRB5_CONF_PKINIT_REQUIRE_FRESHNESS "pkinit_require_freshness"83#define KRB5_CONF_PKINIT_REVOKE "pkinit_revoke"8485/* Make pkiDebug(fmt,...) print, or not. */86#ifdef DEBUG87#define pkiDebug printf88#else89/* Still evaluates for side effects. */90static inline void pkiDebug (const char *fmt, ...) { }91/* This is better if the compiler doesn't inline variadic functions92well, but gcc will warn about "left-hand operand of comma93expression has no effect". Still evaluates for side effects. */94/* #define pkiDebug (void) */95#endif9697/* Solaris compiler doesn't grok __FUNCTION__98* hack for now. Fix all the uses eventually. */99#ifndef _WIN32100#define __FUNCTION__ __func__101#endif102103/* Macros to deal with converting between various data types... */104#define PADATA_TO_KRB5DATA(pad, k5d) \105(k5d)->length = (pad)->length; (k5d)->data = (char *)(pad)->contents;106#define OCTETDATA_TO_KRB5DATA(octd, k5d) \107(k5d)->length = (octd)->length; (k5d)->data = (char *)(octd)->data;108109/*110* notes about crypto contexts:111*112* the basic idea is that there are crypto contexts that live at113* both the plugin level and request level. the identity context (that114* keeps info about your own certs and such) is separate because115* it is needed at different levels for the kdc and and the client.116* (the kdc's identity is at the plugin level, the client's identity117* information could change per-request.)118* the identity context is meant to have the entity's cert,119* a list of trusted and intermediate cas, a list of crls, and any120* pkcs11 information. the req context is meant to have the121* received certificate and the DH related information. the plugin122* context is meant to have global crypto information, i.e., OIDs123* and constant DH parameter information.124*/125126/*127* plugin crypto context should keep plugin common information,128* eg., OIDs, known DHparams129*/130typedef struct _pkinit_plg_crypto_context *pkinit_plg_crypto_context;131132/*133* request crypto context should keep reqyest common information,134* eg., received credentials, DH parameters of this request135*/136typedef struct _pkinit_req_crypto_context *pkinit_req_crypto_context;137138/*139* identity context should keep information about credentials140* for the request, eg., my credentials, trusted ca certs,141* intermediate ca certs, crls, pkcs11 info142*/143typedef struct _pkinit_identity_crypto_context *pkinit_identity_crypto_context;144145/*146* this structure keeps information about the config options147*/148typedef struct _pkinit_plg_opts {149int require_eku; /* require EKU checking (default is true) */150int accept_secondary_eku;/* accept secondary EKU (default is false) */151int allow_upn; /* allow UPN-SAN instead of pkinit-SAN */152int require_crl_checking; /* require CRL for a CA (default is false) */153int require_freshness; /* require freshness token (default is false) */154int disable_freshness; /* disable freshness token on client for testing */155int dh_min_bits; /* minimum DH modulus size allowed */156} pkinit_plg_opts;157158/*159* this structure keeps options used for a given request160*/161typedef struct _pkinit_req_opts {162int require_eku;163int accept_secondary_eku;164int allow_upn;165int require_crl_checking;166int dh_size; /* initial request DH modulus size (default=1024) */167int require_hostname_match;168int disable_freshness;169} pkinit_req_opts;170171/*172* information about identity from config file or command line173*/174175typedef struct _pkinit_identity_opts {176char *identity;177char **identity_alt;178char **anchors;179char **intermediates;180char **crls;181int idtype;182char *cert_filename;183char *key_filename;184#ifndef WITHOUT_PKCS11185char *p11_module_name;186CK_SLOT_ID slotid;187char *token_label;188char *cert_id_string;189char *cert_label;190#endif191} pkinit_identity_opts;192193194/*195* Client's plugin context196*/197struct _pkinit_context {198int magic;199pkinit_plg_crypto_context cryptoctx;200pkinit_plg_opts *opts;201pkinit_identity_opts *idopts;202};203typedef struct _pkinit_context *pkinit_context;204205/*206* Client's per-request context207*/208struct _pkinit_req_context {209unsigned int magic;210pkinit_req_crypto_context cryptoctx;211pkinit_req_opts *opts;212pkinit_identity_crypto_context idctx;213pkinit_identity_opts *idopts;214int do_identity_matching;215krb5_preauthtype pa_type;216int rfc6112_kdc;217int identity_initialized;218int identity_prompted;219krb5_error_code identity_prompt_retval;220krb5_data *freshness_token;221};222typedef struct _pkinit_req_context *pkinit_req_context;223224/*225* KDC's (per-realm) plugin context226*/227struct _pkinit_kdc_context {228int magic;229pkinit_plg_crypto_context cryptoctx;230pkinit_plg_opts *opts;231pkinit_identity_crypto_context idctx;232pkinit_identity_opts *idopts;233char *realmname;234unsigned int realmname_len;235char **auth_indicators;236};237typedef struct _pkinit_kdc_context *pkinit_kdc_context;238239/*240* KDC's per-request context241*/242struct _pkinit_kdc_req_context {243int magic;244pkinit_req_crypto_context cryptoctx;245krb5_auth_pack *rcv_auth_pack;246krb5_preauthtype pa_type;247};248typedef struct _pkinit_kdc_req_context *pkinit_kdc_req_context;249250/*251* Functions in pkinit_lib.c252*/253254krb5_error_code pkinit_init_req_opts(pkinit_req_opts **);255void pkinit_fini_req_opts(pkinit_req_opts *);256257krb5_error_code pkinit_init_plg_opts(pkinit_plg_opts **);258void pkinit_fini_plg_opts(pkinit_plg_opts *);259260krb5_error_code pkinit_init_identity_opts(pkinit_identity_opts **idopts);261void pkinit_fini_identity_opts(pkinit_identity_opts *idopts);262krb5_error_code pkinit_dup_identity_opts(pkinit_identity_opts *src_opts,263pkinit_identity_opts **dest_opts);264265/*266* Functions in pkinit_identity.c267*/268char * idtype2string(int idtype);269char * catype2string(int catype);270271krb5_error_code pkinit_identity_initialize272(krb5_context context, /* IN */273pkinit_plg_crypto_context plg_cryptoctx, /* IN */274pkinit_req_crypto_context req_cryptoctx, /* IN */275pkinit_identity_opts *idopts, /* IN */276pkinit_identity_crypto_context id_cryptoctx, /* IN/OUT */277krb5_clpreauth_callbacks cb, /* IN/OUT */278krb5_clpreauth_rock rock, /* IN/OUT */279krb5_principal princ); /* IN (optional) */280281krb5_error_code pkinit_identity_prompt282(krb5_context context, /* IN */283pkinit_plg_crypto_context plg_cryptoctx, /* IN */284pkinit_req_crypto_context req_cryptoctx, /* IN */285pkinit_identity_opts *idopts, /* IN */286pkinit_identity_crypto_context id_cryptoctx, /* IN/OUT */287krb5_clpreauth_callbacks cb, /* IN/OUT */288krb5_clpreauth_rock rock, /* IN/OUT */289int do_matching, /* IN */290krb5_principal princ); /* IN (optional) */291292krb5_error_code pkinit_cert_matching293(krb5_context context,294pkinit_plg_crypto_context plg_cryptoctx,295pkinit_req_crypto_context req_cryptoctx,296pkinit_identity_crypto_context id_cryptoctx,297krb5_principal princ);298299krb5_error_code pkinit_client_cert_match300(krb5_context context,301pkinit_plg_crypto_context plgctx,302pkinit_req_crypto_context reqctx,303const char *match_rule,304krb5_boolean *matched);305306/*307* Client's list of identities for which it needs PINs or passwords308*/309struct _pkinit_deferred_id {310int magic;311char *identity;312unsigned long ck_flags;313char *password;314};315typedef struct _pkinit_deferred_id *pkinit_deferred_id;316317krb5_error_code pkinit_set_deferred_id318(pkinit_deferred_id **identities, const char *identity,319unsigned long ck_flags, const char *password);320const char * pkinit_find_deferred_id321(pkinit_deferred_id *identities, const char *identity);322unsigned long pkinit_get_deferred_id_flags323(pkinit_deferred_id *identities, const char *identity);324void pkinit_free_deferred_ids(pkinit_deferred_id *identities);325326/*327* initialization and free functions328*/329void init_krb5_pa_pk_as_req(krb5_pa_pk_as_req **in);330void init_krb5_reply_key_pack(krb5_reply_key_pack **in);331332void init_krb5_pa_pk_as_rep(krb5_pa_pk_as_rep **in);333334void free_krb5_pa_pk_as_req(krb5_pa_pk_as_req **in);335void free_krb5_reply_key_pack(krb5_reply_key_pack **in);336void free_krb5_auth_pack(krb5_auth_pack **in);337void free_krb5_pa_pk_as_rep(krb5_pa_pk_as_rep **in);338void free_krb5_external_principal_identifier(krb5_external_principal_identifier ***in);339void free_krb5_algorithm_identifiers(krb5_algorithm_identifier ***in);340void free_krb5_algorithm_identifier(krb5_algorithm_identifier *in);341void free_krb5_kdc_dh_key_info(krb5_kdc_dh_key_info **in);342void free_pachecksum2(krb5_context context, krb5_pachecksum2 **in);343krb5_error_code pkinit_copy_krb5_data(krb5_data *dst, const krb5_data *src);344345346/*347* Functions in pkinit_profile.c348*/349krb5_error_code pkinit_kdcdefault_strings350(krb5_context context, const char *realmname, const char *option,351char ***ret_value);352krb5_error_code pkinit_kdcdefault_string353(krb5_context context, const char *realmname, const char *option,354char **ret_value);355krb5_error_code pkinit_kdcdefault_boolean356(krb5_context context, const char *realmname, const char *option,357int default_value, int *ret_value);358krb5_error_code pkinit_kdcdefault_integer359(krb5_context context, const char *realmname, const char *option,360int default_value, int *ret_value);361362363krb5_error_code pkinit_libdefault_strings364(krb5_context context, const krb5_data *realm,365const char *option, char ***ret_value);366krb5_error_code pkinit_libdefault_string367(krb5_context context, const krb5_data *realm,368const char *option, char **ret_value);369krb5_error_code pkinit_libdefault_boolean370(krb5_context context, const krb5_data *realm, const char *option,371int default_value, int *ret_value);372krb5_error_code pkinit_libdefault_integer373(krb5_context context, const krb5_data *realm, const char *option,374int default_value, int *ret_value);375376/*377* debugging functions378*/379void print_buffer(const unsigned char *, unsigned int);380void print_buffer_bin(unsigned char *, unsigned int, char *);381382/*383* Now get crypto function declarations384*/385#include "pkinit_crypto.h"386387#endif /* _PKINIT_H */388389390