| 1 |
/* |
| 2 |
* Copyright (c) 1997-2016 Kungliga Tekniska Högskolan |
| 3 |
* (Royal Institute of Technology, Stockholm, Sweden). |
| 4 |
* All rights reserved. |
| 5 |
* |
| 6 |
* Portions Copyright (c) 2009 Apple Inc. All rights reserved. |
| 7 |
* |
| 8 |
* Redistribution and use in source and binary forms, with or without |
| 9 |
* modification, are permitted provided that the following conditions |
| 10 |
* are met: |
| 11 |
* |
| 12 |
* 1. Redistributions of source code must retain the above copyright |
| 13 |
* notice, this list of conditions and the following disclaimer. |
| 14 |
* |
| 15 |
* 2. Redistributions in binary form must reproduce the above copyright |
| 16 |
* notice, this list of conditions and the following disclaimer in the |
| 17 |
* documentation and/or other materials provided with the distribution. |
| 18 |
* |
| 19 |
* 3. Neither the name of the Institute nor the names of its contributors |
| 20 |
* may be used to endorse or promote products derived from this software |
| 21 |
* without specific prior written permission. |
| 22 |
* |
| 23 |
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND |
| 24 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 25 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 26 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE |
| 27 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 28 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 29 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 31 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 32 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 33 |
* SUCH DAMAGE. |
| 34 |
*/ |
| 35 |
|
| 36 |
/* $Id$ */ |
| 37 |
|
| 38 |
#ifndef __KRB5_LOCL_H__ |
| 39 |
#define __KRB5_LOCL_H__ |
| 40 |
|
| 41 |
#include <config.h> |
| 42 |
#include <roken.h> |
| 43 |
|
| 44 |
#include <ctype.h> |
| 45 |
|
| 46 |
#ifdef HAVE_POLL_H |
| 47 |
#include <sys/poll.h> |
| 48 |
#endif |
| 49 |
|
| 50 |
#include <krb5-types.h> |
| 51 |
|
| 52 |
#ifdef HAVE_SYS_TYPES_H |
| 53 |
#include <sys/types.h> |
| 54 |
#endif |
| 55 |
#ifdef HAVE_SYS_MMAN_H |
| 56 |
#include <sys/mman.h> |
| 57 |
#endif |
| 58 |
|
| 59 |
#if defined(HAVE_SYS_IOCTL_H) && SunOS != 40 |
| 60 |
#include <sys/ioctl.h> |
| 61 |
#endif |
| 62 |
#ifdef HAVE_PWD_H |
| 63 |
#undef _POSIX_PTHREAD_SEMANTICS |
| 64 |
/* This gets us the 5-arg getpwnam_r on Solaris 9. */ |
| 65 |
#define _POSIX_PTHREAD_SEMANTICS |
| 66 |
#include <pwd.h> |
| 67 |
#endif |
| 68 |
|
| 69 |
#ifdef HAVE_SYS_SELECT_H |
| 70 |
#include <sys/select.h> |
| 71 |
#endif |
| 72 |
#ifdef _AIX |
| 73 |
struct mbuf; |
| 74 |
#endif |
| 75 |
#ifdef HAVE_SYS_FILIO_H |
| 76 |
#include <sys/filio.h> |
| 77 |
#endif |
| 78 |
#ifdef HAVE_SYS_FILE_H |
| 79 |
#include <sys/file.h> |
| 80 |
#endif |
| 81 |
|
| 82 |
#include <com_err.h> |
| 83 |
|
| 84 |
#include <heimbase.h> |
| 85 |
|
| 86 |
#define HEIMDAL_TEXTDOMAIN "heimdal_krb5" |
| 87 |
|
| 88 |
#ifdef LIBINTL |
| 89 |
#include <libintl.h> |
| 90 |
#define N_(x,y) dgettext(HEIMDAL_TEXTDOMAIN, x) |
| 91 |
#else |
| 92 |
#define N_(x,y) (x) |
| 93 |
#define bindtextdomain(package, localedir) |
| 94 |
#endif |
| 95 |
|
| 96 |
|
| 97 |
#ifdef HAVE_CRYPT_H |
| 98 |
#undef des_encrypt |
| 99 |
#define des_encrypt wingless_pigs_mostly_fail_to_fly |
| 100 |
#include <crypt.h> |
| 101 |
#undef des_encrypt |
| 102 |
#endif |
| 103 |
|
| 104 |
#ifdef HAVE_DOOR_CREATE |
| 105 |
#include <door.h> |
| 106 |
#endif |
| 107 |
|
| 108 |
#include <parse_time.h> |
| 109 |
#include <base64.h> |
| 110 |
|
| 111 |
#include <wind.h> |
| 112 |
|
| 113 |
/* |
| 114 |
* We use OpenSSL for EC, but to do this we need to disable cross-references |
| 115 |
* between OpenSSL and hcrypto bn.h and such. Source files that use OpenSSL EC |
| 116 |
* must define HEIM_NO_CRYPTO_HDRS before including this file. |
| 117 |
*/ |
| 118 |
#define HC_DEPRECATED_CRYPTO |
| 119 |
#ifndef HEIM_NO_CRYPTO_HDRS |
| 120 |
#include "crypto-headers.h" |
| 121 |
#endif |
| 122 |
|
| 123 |
|
| 124 |
#include <krb5_asn1.h> |
| 125 |
#include <pkinit_asn1.h> |
| 126 |
|
| 127 |
struct send_to_kdc; |
| 128 |
|
| 129 |
/* XXX glue for pkinit */ |
| 130 |
struct hx509_certs_data; |
| 131 |
struct krb5_pk_identity; |
| 132 |
struct krb5_pk_cert; |
| 133 |
struct ContentInfo; |
| 134 |
struct AlgorithmIdentifier; |
| 135 |
typedef struct krb5_pk_init_ctx_data *krb5_pk_init_ctx; |
| 136 |
struct krb5_dh_moduli; |
| 137 |
|
| 138 |
/* v4 glue */ |
| 139 |
struct _krb5_krb_auth_data; |
| 140 |
|
| 141 |
#include <der.h> |
| 142 |
|
| 143 |
#include <krb5.h> |
| 144 |
#include <krb5_err.h> |
| 145 |
#include <asn1_err.h> |
| 146 |
#ifdef PKINIT |
| 147 |
#include <hx509.h> |
| 148 |
#endif |
| 149 |
|
| 150 |
#include "crypto.h" |
| 151 |
|
| 152 |
#include <krb5-private.h> |
| 153 |
|
| 154 |
#include "heim_threads.h" |
| 155 |
|
| 156 |
#define ALLOC(X, N) (X) = calloc((N), sizeof(*(X))) |
| 157 |
#define ALLOC_SEQ(X, N) do { (X)->len = (N); ALLOC((X)->val, (N)); } while(0) |
| 158 |
|
| 159 |
#ifndef __func__ |
| 160 |
#define __func__ "unknown-function" |
| 161 |
#endif |
| 162 |
|
| 163 |
#define krb5_einval(context, argnum) _krb5_einval((context), __func__, (argnum)) |
| 164 |
|
| 165 |
#ifndef PATH_SEP |
| 166 |
#define PATH_SEP ":" |
| 167 |
#endif |
| 168 |
|
| 169 |
/* should this be public? */ |
| 170 |
#define KEYTAB_DEFAULT "FILE:" SYSCONFDIR "/krb5.keytab" |
| 171 |
#define KEYTAB_DEFAULT_MODIFY "FILE:" SYSCONFDIR "/krb5.keytab" |
| 172 |
|
| 173 |
|
| 174 |
#define MODULI_FILE SYSCONFDIR "/krb5.moduli" |
| 175 |
|
| 176 |
#ifndef O_BINARY |
| 177 |
#define O_BINARY 0 |
| 178 |
#endif |
| 179 |
|
| 180 |
#ifndef O_CLOEXEC |
| 181 |
#define O_CLOEXEC 0 |
| 182 |
#endif |
| 183 |
|
| 184 |
#ifndef SOCK_CLOEXEC |
| 185 |
#define SOCK_CLOEXEC 0 |
| 186 |
#endif |
| 187 |
|
| 188 |
|
| 189 |
#define KRB5_BUFSIZ 2048 |
| 190 |
|
| 191 |
typedef enum { |
| 192 |
KRB5_INIT_CREDS_TRISTATE_UNSET = 0, |
| 193 |
KRB5_INIT_CREDS_TRISTATE_TRUE, |
| 194 |
KRB5_INIT_CREDS_TRISTATE_FALSE |
| 195 |
} krb5_get_init_creds_tristate; |
| 196 |
|
| 197 |
struct _krb5_get_init_creds_opt_private { |
| 198 |
int refcount; |
| 199 |
/* ENC_TIMESTAMP */ |
| 200 |
const char *password; |
| 201 |
krb5_s2k_proc key_proc; |
| 202 |
/* PA_PAC_REQUEST */ |
| 203 |
krb5_get_init_creds_tristate req_pac; |
| 204 |
/* PKINIT */ |
| 205 |
krb5_pk_init_ctx pk_init_ctx; |
| 206 |
krb5_get_init_creds_tristate addressless; |
| 207 |
int flags; |
| 208 |
#define KRB5_INIT_CREDS_CANONICALIZE 1 |
| 209 |
#define KRB5_INIT_CREDS_NO_C_CANON_CHECK 2 |
| 210 |
#define KRB5_INIT_CREDS_NO_C_NO_EKU_CHECK 4 |
| 211 |
#define KRB5_INIT_CREDS_PKINIT_KX_VALID 32 |
| 212 |
#define KRB5_INIT_CREDS_PKINIT_NO_KRBTGT_OTHERNAME_CHECK 64 |
| 213 |
struct { |
| 214 |
krb5_gic_process_last_req func; |
| 215 |
void *ctx; |
| 216 |
} lr; |
| 217 |
}; |
| 218 |
|
| 219 |
typedef uint32_t krb5_enctype_set; |
| 220 |
|
| 221 |
typedef struct krb5_context_data { |
| 222 |
krb5_enctype *etypes; |
| 223 |
krb5_enctype *cfg_etypes; |
| 224 |
krb5_enctype *etypes_des;/* deprecated */ |
| 225 |
krb5_enctype *as_etypes; |
| 226 |
krb5_enctype *tgs_etypes; |
| 227 |
krb5_enctype *permitted_enctypes; |
| 228 |
char **default_realms; |
| 229 |
time_t max_skew; |
| 230 |
time_t kdc_timeout; |
| 231 |
time_t host_timeout; |
| 232 |
unsigned max_retries; |
| 233 |
int32_t kdc_sec_offset; |
| 234 |
int32_t kdc_usec_offset; |
| 235 |
krb5_config_section *cf; |
| •236 |
size_t config_include_depth; |
| 237 |
struct et_list *et_list; |
| 238 |
struct krb5_log_facility *warn_dest; |
| 239 |
struct krb5_log_facility *debug_dest; |
| 240 |
const krb5_cc_ops **cc_ops; |
| 241 |
int num_cc_ops; |
| 242 |
const char *http_proxy; |
| 243 |
const char *time_fmt; |
| 244 |
krb5_boolean log_utc; |
| 245 |
const char *default_keytab; |
| 246 |
const char *default_keytab_modify; |
| 247 |
krb5_boolean use_admin_kdc; |
| 248 |
krb5_addresses *extra_addresses; |
| 249 |
krb5_boolean scan_interfaces; /* `ifconfig -a' */ |
| 250 |
krb5_boolean srv_lookup; /* do SRV lookups */ |
| 251 |
krb5_boolean srv_try_txt; /* try TXT records also */ |
| 252 |
int32_t fcache_vno; /* create cache files w/ this |
| 253 |
version */ |
| 254 |
int num_kt_types; /* # of registered keytab types */ |
| 255 |
struct krb5_keytab_data *kt_types; /* registered keytab types */ |
| 256 |
const char *date_fmt; |
| 257 |
char *error_string; |
| 258 |
krb5_error_code error_code; |
| 259 |
krb5_addresses *ignore_addresses; |
| 260 |
char *default_cc_name; |
| 261 |
char *default_cc_name_env; |
| 262 |
int default_cc_name_set; |
| 263 |
HEIMDAL_MUTEX mutex; /* protects error_string */ |
| 264 |
int large_msg_size; |
| 265 |
int max_msg_size; |
| 266 |
int tgs_negative_timeout; /* timeout for TGS negative cache */ |
| 267 |
int flags; |
| 268 |
#define KRB5_CTX_F_DNS_CANONICALIZE_HOSTNAME 1 |
| 269 |
#define KRB5_CTX_F_CHECK_PAC 2 |
| 270 |
#define KRB5_CTX_F_HOMEDIR_ACCESS 4 |
| 271 |
#define KRB5_CTX_F_SOCKETS_INITIALIZED 8 |
| 272 |
#define KRB5_CTX_F_RD_REQ_IGNORE 16 |
| 273 |
#define KRB5_CTX_F_FCACHE_STRICT_CHECKING 32 |
| 274 |
struct send_to_kdc *send_to_kdc; |
| 275 |
#ifdef PKINIT |
| 276 |
hx509_context hx509ctx; |
| 277 |
#endif |
| 278 |
unsigned int num_kdc_requests; |
| 279 |
krb5_name_canon_rule name_canon_rules; |
| 280 |
} krb5_context_data; |
| 281 |
|
| 282 |
#ifndef KRB5_USE_PATH_TOKENS |
| 283 |
#define KRB5_DEFAULT_CCNAME_FILE "FILE:/tmp/krb5cc_%{uid}" |
| 284 |
#define KRB5_DEFAULT_CCNAME_DIR "DIR:/tmp/krb5cc_%{uid}_dir/" |
| 285 |
#else |
| 286 |
#define KRB5_DEFAULT_CCNAME_FILE "FILE:%{TEMP}/krb5cc_%{uid}" |
| 287 |
#define KRB5_DEFAULT_CCNAME_DIR "DIR:%{TEMP}/krb5cc_%{uid}_dir/" |
| 288 |
#endif |
| 289 |
#define KRB5_DEFAULT_CCNAME_API "API:" |
| 290 |
#define KRB5_DEFAULT_CCNAME_KCM_KCM "KCM:%{uid}" |
| 291 |
#define KRB5_DEFAULT_CCNAME_KCM_API "API:%{uid}" |
| 292 |
|
| 293 |
#define EXTRACT_TICKET_ALLOW_CNAME_MISMATCH 1 |
| 294 |
#define EXTRACT_TICKET_ALLOW_SERVER_MISMATCH 2 |
| 295 |
#define EXTRACT_TICKET_MATCH_REALM 4 |
| 296 |
#define EXTRACT_TICKET_AS_REQ 8 |
| 297 |
#define EXTRACT_TICKET_TIMESYNC 16 |
| 298 |
#define EXTRACT_TICKET_MATCH_ANON 32 |
| 299 |
|
| 300 |
/* |
| 301 |
* Configurable options |
| 302 |
*/ |
| 303 |
|
| 304 |
#ifndef KRB5_DEFAULT_CCTYPE |
| 305 |
#ifdef __APPLE__ |
| 306 |
#define KRB5_DEFAULT_CCTYPE (&krb5_acc_ops) |
| 307 |
#else |
| 308 |
#define KRB5_DEFAULT_CCTYPE (&krb5_fcc_ops) |
| 309 |
#endif |
| 310 |
#endif |
| 311 |
|
| 312 |
#ifndef KRB5_ADDRESSLESS_DEFAULT |
| 313 |
#define KRB5_ADDRESSLESS_DEFAULT TRUE |
| 314 |
#endif |
| 315 |
|
| 316 |
#ifndef KRB5_FORWARDABLE_DEFAULT |
| 317 |
#define KRB5_FORWARDABLE_DEFAULT TRUE |
| 318 |
#endif |
| 319 |
|
| 320 |
#ifndef KRB5_CONFIGURATION_CHANGE_NOTIFY_NAME |
| 321 |
#define KRB5_CONFIGURATION_CHANGE_NOTIFY_NAME "org.h5l.Kerberos.configuration-changed" |
| 322 |
#endif |
| 323 |
|
| 324 |
#ifndef KRB5_FALLBACK_DEFAULT |
| 325 |
#define KRB5_FALLBACK_DEFAULT TRUE |
| 326 |
#endif |
| 327 |
|
| 328 |
#ifndef KRB5_TKT_LIFETIME_DEFAULT |
| 329 |
# define KRB5_TKT_LIFETIME_DEFAULT 15778800 /* seconds */ |
| 330 |
#endif |
| 331 |
|
| 332 |
#ifndef KRB5_TKT_RENEW_LIFETIME_DEFAULT |
| 333 |
# define KRB5_TKT_RENEW_LIFETIME_DEFAULT 15778800 /* seconds */ |
| 334 |
#endif |
| 335 |
|
| 336 |
#ifdef PKINIT |
| 337 |
|
| 338 |
struct krb5_pk_identity { |
| 339 |
hx509_verify_ctx verify_ctx; |
| 340 |
hx509_certs certs; |
| 341 |
hx509_cert cert; |
| 342 |
hx509_certs anchors; |
| 343 |
hx509_certs certpool; |
| 344 |
hx509_revoke_ctx revokectx; |
| 345 |
int flags; |
| 346 |
#define PKINIT_BTMM 1 |
| 347 |
}; |
| 348 |
|
| 349 |
enum krb5_pk_type { |
| 350 |
PKINIT_WIN2K = 1, |
| 351 |
PKINIT_27 = 2 |
| 352 |
}; |
| 353 |
|
| 354 |
enum keyex_enum { USE_RSA, USE_DH, USE_ECDH }; |
| 355 |
|
| 356 |
struct krb5_pk_init_ctx_data { |
| 357 |
struct krb5_pk_identity *id; |
| 358 |
enum keyex_enum keyex; |
| 359 |
union { |
| 360 |
DH *dh; |
| 361 |
void *eckey; |
| 362 |
} u; |
| 363 |
krb5_data *clientDHNonce; |
| 364 |
struct krb5_dh_moduli **m; |
| 365 |
hx509_peer_info peer; |
| 366 |
enum krb5_pk_type type; |
| 367 |
unsigned int require_binding:1; |
| 368 |
unsigned int require_eku:1; |
| 369 |
unsigned int require_krbtgt_otherName:1; |
| 370 |
unsigned int require_hostname_match:1; |
| 371 |
unsigned int trustedCertifiers:1; |
| 372 |
unsigned int anonymous:1; |
| 373 |
}; |
| 374 |
|
| 375 |
#endif /* PKINIT */ |
| 376 |
|
| 377 |
#define ISTILDE(x) (x == '~') |
| 378 |
#ifdef _WIN32 |
| 379 |
# define ISPATHSEP(x) (x == '/' || x =='\\') |
| 380 |
#else |
| 381 |
# define ISPATHSEP(x) (x == '/') |
| 382 |
#endif |
| 383 |
|
| 384 |
#endif /* __KRB5_LOCL_H__ */ |