1 /* 2 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5 6 /* 7 * Copyright (C) 1989,1990,1991,1992,1993,1994,1995,2000,2001, 2003,2006 by the Massachusetts Institute of Technology, 8 * Cambridge, MA, USA. All Rights Reserved. 9 * 10 * This software is being provided to you, the LICENSEE, by the 11 * Massachusetts Institute of Technology (M.I.T.) under the following 12 * license. By obtaining, using and/or copying this software, you agree 13 * that you have read, understood, and will comply with these terms and 14 * conditions: 15 * 16 * Export of this software from the United States of America may 17 * require a specific license from the United States Government. 18 * It is the responsibility of any person or organization contemplating 19 * export to obtain such a license before exporting. 20 * 21 * WITHIN THAT CONSTRAINT, permission to use, copy, modify and distribute 22 * this software and its documentation for any purpose and without fee or 23 * royalty is hereby granted, provided that you agree to comply with the 24 * following copyright notice and statements, including the disclaimer, and 25 * that the same appear on ALL copies of the software and documentation, 26 * including modifications that you make for internal use or for 27 * distribution: 28 * 29 * THIS SOFTWARE IS PROVIDED "AS IS", AND M.I.T. MAKES NO REPRESENTATIONS 30 * OR WARRANTIES, EXPRESS OR IMPLIED. By way of example, but not 31 * limitation, M.I.T. MAKES NO REPRESENTATIONS OR WARRANTIES OF 32 * MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF 33 * THE LICENSED SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD PARTY 34 * PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS. 35 * 36 * The name of the Massachusetts Institute of Technology or M.I.T. may NOT 37 * be used in advertising or publicity pertaining to distribution of the 38 * software. Title to copyright in this software and any associated 39 * documentation shall at all times remain with M.I.T., and USER agrees to 40 * preserve same. 41 * 42 * Furthermore if you modify this software you must label 43 * your software as modified software and not distribute it in such a 44 * fashion that it might be confused with the original M.I.T. software. 45 46 */ 47 /* 48 * Copyright (C) 1998 by the FundsXpress, INC. 49 * 50 * All rights reserved. 51 * 52 * Export of this software from the United States of America may require 53 * a specific license from the United States Government. It is the 54 * responsibility of any person or organization contemplating export to 55 * obtain such a license before exporting. 56 * 57 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and 58 * distribute this software and its documentation for any purpose and 59 * without fee is hereby granted, provided that the above copyright 60 * notice appear in all copies and that both that copyright notice and 61 * this permission notice appear in supporting documentation, and that 62 * the name of FundsXpress. not be used in advertising or publicity pertaining 63 * to distribution of the software without specific, written prior 64 * permission. FundsXpress makes no representations about the suitability of 65 * this software for any purpose. It is provided "as is" without express 66 * or implied warranty. 67 * 68 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 69 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 70 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 71 */ 72 73 /* 74 * This prototype for k5-int.h (Krb5 internals include file) 75 * includes the user-visible definitions from krb5.h and then 76 * includes other definitions that are not user-visible but are 77 * required for compiling Kerberos internal routines. 78 * 79 * John Gilmore, Cygnus Support, Sat Jan 21 22:45:52 PST 1995 80 */ 81 82 #ifndef _KRB5_INT_H 83 #define _KRB5_INT_H 84 85 #pragma ident "%Z%%M% %I% %E% SMI" 86 87 #ifndef _KERNEL 88 #include <osconf.h> 89 #include <security/cryptoki.h> 90 #else 91 #include <sys/crypto/common.h> 92 #include <sys/crypto/api.h> 93 #endif 94 95 #ifdef DEBUG 96 #if !defined(KRB5_DEBUG) 97 #define KRB5_DEBUG 98 #endif 99 #ifndef KRB5_LOG_LVL 100 #define KRB5_LOG_LVL KRB5_ERR 101 #endif 102 #endif /* DEBUG */ 103 104 #ifdef _KERNEL 105 106 #ifdef DEBUG 107 #include <sys/types.h> 108 #include <sys/cmn_err.h> 109 extern void prom_printf(); 110 #endif /* DEBUG */ 111 112 #else /* !_KERNEL */ 113 114 #define prom_printf printf 115 116 #endif /* !_KERNEL */ 117 118 #ifdef KRB5_LOG_LVL 119 120 /* krb5_log is used to set the logging level to determine what class of messages 121 * are output by the mech. Note, more than one logging level can be used by 122 * bit or'ing the log values together. 123 * 124 * All log messages are captured by syslog. 125 */ 126 127 extern unsigned int krb5_log; 128 129 /* Note, these defines should be mutually exclusive bit fields */ 130 #define KRB5_ERR 1 /* Use this debug log level for error path logging. */ 131 #define KRB5_INFO 2 /* Use this debug log level for informational messages. */ 132 133 #ifdef _KERNEL 134 135 #define KRB5_LOG1(A, B, C, D) \ 136 ((void)((krb5_log) && (krb5_log & (A)) && (printf((B), (C), (D)), TRUE))) 137 #define KRB5_LOG(A, B, C) \ 138 ((void)((krb5_log) && (krb5_log & (A)) && (printf((B), (C)), TRUE))) 139 #define KRB5_LOG0(A, B) \ 140 ((void)((krb5_log) && (krb5_log & (A)) && (printf((B)), TRUE))) 141 142 #else /* !_KERNEL */ 143 144 #include <syslog.h> 145 146 #define KRB5_LOG1(A, B, C, D) \ 147 ((void)((krb5_log) && (krb5_log & (A)) && \ 148 (syslog(LOG_DEBUG, (B), (C), (D)), TRUE))) 149 #define KRB5_LOG(A, B, C) \ 150 ((void)((krb5_log) && (krb5_log & (A)) && \ 151 (syslog(LOG_DEBUG, (B), (C)), TRUE))) 152 #define KRB5_LOG0(A, B) \ 153 ((void)((krb5_log) && (krb5_log & (A)) && \ 154 (syslog(LOG_DEBUG, B), TRUE))) 155 156 #endif /* _KERNEL */ 157 158 #else /* ! KRB5_LOG_LVL */ 159 160 #define KRB5_LOG1(A, B, C, D) 161 #define KRB5_LOG(A, B, C) 162 #define KRB5_LOG0(A, B) 163 164 #endif /* KRB5_LOG_LVL */ 165 166 #ifdef POSIX_TYPES 167 #define timetype time_t 168 #else 169 #define timetype long 170 #endif 171 172 /* 173 * Begin "k5-config.h" 174 */ 175 #ifndef KRB5_CONFIG__ 176 #define KRB5_CONFIG__ 177 178 /* 179 * Machine-type definitions: PC Clone 386 running Microsoft Windows 180 */ 181 182 #if defined(_MSDOS) || defined(_WIN32) 183 #include "win-mac.h" 184 185 /* Kerberos Windows initialization file */ 186 #define KERBEROS_INI "kerberos.ini" 187 #define INI_FILES "Files" 188 #define INI_KRB_CCACHE "krb5cc" /* Location of the ccache */ 189 #define INI_KRB5_CONF "krb5.ini" /* Location of krb5.conf file */ 190 #define ANSI_STDIO 191 #endif 192 193 #ifndef _KERNEL 194 #ifndef KRB5_AUTOCONF__ 195 #define KRB5_AUTOCONF__ 196 #include <autoconf.h> 197 #endif 198 #endif /* !_KERNEL */ 199 200 #ifndef KRB5_SYSTYPES__ 201 #define KRB5_SYSTYPES__ 202 203 #ifdef HAVE_SYS_TYPES_H /* From autoconf.h */ 204 #include <sys/types.h> 205 #else /* HAVE_SYS_TYPES_H */ 206 #endif /* HAVE_SYS_TYPES_H */ 207 #endif /* KRB5_SYSTYPES__ */ 208 209 /* #include "k5-platform.h" SUNW XXX */ 210 /* not used in krb5.h (yet) */ 211 typedef uint64_t krb5_ui_8; 212 typedef int64_t krb5_int64; 213 214 #define DEFAULT_PWD_STRING1 "Enter password:" 215 #define DEFAULT_PWD_STRING2 "Re-enter password for verification:" 216 217 #define KRB5_KDB_MAX_LIFE (60*60*24) /* one day */ 218 #define KRB5_KDB_MAX_RLIFE (60*60*24*365) /* one year */ 219 #define KRB5_KDB_EXPIRATION 2145830400 /* Thu Jan 1 00:00:00 2038 UTC */ 220 #define KRB5_DEFAULT_LIFE 60*60*10 /* 10 hours */ 221 #define KRB5_DEFAULT_RENEW_LIFE 7*24*60*60 /* 7 Days */ 222 223 /* 224 * Windows requires a different api interface to each function. Here 225 * just define it as NULL. 226 */ 227 #ifndef KRB5_CALLCONV 228 #define KRB5_CALLCONV 229 #define KRB5_CALLCONV_C 230 #endif 231 #ifndef O_BINARY 232 #define O_BINARY 0 233 #endif 234 235 #endif /* KRB5_CONFIG__ */ 236 237 /* 238 * End "k5-config.h" 239 */ 240 241 /* 242 * After loading the configuration definitions, load the Kerberos definitions. 243 */ 244 #ifndef _KERNEL 245 #include <errno.h> 246 #include "profile.h" 247 #endif 248 249 #include <krb5.h> 250 251 #ifndef _KERNEL 252 #if 1 /* def NEED_SOCKETS */ 253 #include <port-sockets.h> 254 #include <socket-utils.h> 255 #else 256 #ifndef SOCK_DGRAM 257 struct sockaddr; 258 #endif 259 #endif 260 #endif 261 262 /* Get mutex support; currently used only for the replay cache. */ 263 #include "k5-thread.h" 264 265 /* 266 * Solaris Kerberos: 267 * Define whether or not to do a reverse lookup when looking up a host in DNS. 268 */ 269 #define REV_LOOKUP 1 270 #define NO_REV_LOOKUP 0 271 272 273 /* krb5/krb5.h includes many other .h files in the krb5 subdirectory. 274 The ones that it doesn't include, we include below. */ 275 276 /* 277 * Begin "k5-errors.h" 278 */ 279 #ifndef KRB5_ERRORS__ 280 #define KRB5_ERRORS__ 281 282 283 /* Error codes used in KRB_ERROR protocol messages. 284 Return values of library routines are based on a different error table 285 (which allows non-ambiguous error codes between subsystems) */ 286 287 /* KDC errors */ 288 #define KDC_ERR_NONE 0 /* No error */ 289 #define KDC_ERR_NAME_EXP 1 /* Client's entry in DB expired */ 290 #define KDC_ERR_SERVICE_EXP 2 /* Server's entry in DB expired */ 291 #define KDC_ERR_BAD_PVNO 3 /* Requested pvno not supported */ 292 #define KDC_ERR_C_OLD_MAST_KVNO 4 /* C's key encrypted in old master */ 293 #define KDC_ERR_S_OLD_MAST_KVNO 5 /* S's key encrypted in old master */ 294 #define KDC_ERR_C_PRINCIPAL_UNKNOWN 6 /* Client not found in Kerberos DB */ 295 #define KDC_ERR_S_PRINCIPAL_UNKNOWN 7 /* Server not found in Kerberos DB */ 296 #define KDC_ERR_PRINCIPAL_NOT_UNIQUE 8 /* Multiple entries in Kerberos DB */ 297 #define KDC_ERR_NULL_KEY 9 /* The C or S has a null key */ 298 #define KDC_ERR_CANNOT_POSTDATE 10 /* Tkt ineligible for postdating */ 299 #define KDC_ERR_NEVER_VALID 11 /* Requested starttime > endtime */ 300 #define KDC_ERR_POLICY 12 /* KDC policy rejects request */ 301 #define KDC_ERR_BADOPTION 13 /* KDC can't do requested opt. */ 302 #define KDC_ERR_ENCTYPE_NOSUPP 14 /* No support for encryption type */ 303 #define KDC_ERR_SUMTYPE_NOSUPP 15 /* No support for checksum type */ 304 #define KDC_ERR_PADATA_TYPE_NOSUPP 16 /* No support for padata type */ 305 #define KDC_ERR_TRTYPE_NOSUPP 17 /* No support for transited type */ 306 #define KDC_ERR_CLIENT_REVOKED 18 /* C's creds have been revoked */ 307 #define KDC_ERR_SERVICE_REVOKED 19 /* S's creds have been revoked */ 308 #define KDC_ERR_TGT_REVOKED 20 /* TGT has been revoked */ 309 #define KDC_ERR_CLIENT_NOTYET 21 /* C not yet valid */ 310 #define KDC_ERR_SERVICE_NOTYET 22 /* S not yet valid */ 311 #define KDC_ERR_KEY_EXP 23 /* Password has expired */ 312 #define KDC_ERR_PREAUTH_FAILED 24 /* Preauthentication failed */ 313 #define KDC_ERR_PREAUTH_REQUIRED 25 /* Additional preauthentication */ 314 /* required */ 315 #define KDC_ERR_SERVER_NOMATCH 26 /* Requested server and */ 316 /* ticket don't match*/ 317 /* Application errors */ 318 #define KRB_AP_ERR_BAD_INTEGRITY 31 /* Decrypt integrity check failed */ 319 #define KRB_AP_ERR_TKT_EXPIRED 32 /* Ticket expired */ 320 #define KRB_AP_ERR_TKT_NYV 33 /* Ticket not yet valid */ 321 #define KRB_AP_ERR_REPEAT 34 /* Request is a replay */ 322 #define KRB_AP_ERR_NOT_US 35 /* The ticket isn't for us */ 323 #define KRB_AP_ERR_BADMATCH 36 /* Ticket/authenticator don't match */ 324 #define KRB_AP_ERR_SKEW 37 /* Clock skew too great */ 325 #define KRB_AP_ERR_BADADDR 38 /* Incorrect net address */ 326 #define KRB_AP_ERR_BADVERSION 39 /* Protocol version mismatch */ 327 #define KRB_AP_ERR_MSG_TYPE 40 /* Invalid message type */ 328 #define KRB_AP_ERR_MODIFIED 41 /* Message stream modified */ 329 #define KRB_AP_ERR_BADORDER 42 /* Message out of order */ 330 #define KRB_AP_ERR_BADKEYVER 44 /* Key version is not available */ 331 #define KRB_AP_ERR_NOKEY 45 /* Service key not available */ 332 #define KRB_AP_ERR_MUT_FAIL 46 /* Mutual authentication failed */ 333 #define KRB_AP_ERR_BADDIRECTION 47 /* Incorrect message direction */ 334 #define KRB_AP_ERR_METHOD 48 /* Alternative authentication */ 335 /* method required */ 336 #define KRB_AP_ERR_BADSEQ 49 /* Incorrect sequence numnber */ 337 /* in message */ 338 #define KRB_AP_ERR_INAPP_CKSUM 50 /* Inappropriate type of */ 339 /* checksum in message */ 340 #define KRB_AP_PATH_NOT_ACCEPTED 51 /* Policy rejects transited path */ 341 #define KRB_ERR_RESPONSE_TOO_BIG 52 /* Response too big for UDP, */ 342 /* retry with TCP */ 343 344 /* other errors */ 345 #define KRB_ERR_GENERIC 60 /* Generic error (description */ 346 /* in e-text) */ 347 #define KRB_ERR_FIELD_TOOLONG 61 /* Field is too long for impl. */ 348 349 #endif /* KRB5_ERRORS__ */ 350 /* 351 * End "k5-errors.h" 352 */ 353 354 /* 355 * This structure is returned in the e-data field of the KRB-ERROR 356 * message when the error calling for an alternative form of 357 * authentication is returned, KRB_AP_METHOD. 358 */ 359 typedef struct _krb5_alt_method { 360 krb5_magic magic; 361 krb5_int32 method; 362 unsigned int length; 363 krb5_octet *data; 364 } krb5_alt_method; 365 366 /* 367 * A null-terminated array of this structure is returned by the KDC as 368 * the data part of the ETYPE_INFO preauth type. It informs the 369 * client which encryption types are supported. 370 * The same data structure is used by both etype-info and etype-info2 371 * but s2kparams must be null when encoding etype-info. 372 */ 373 typedef struct _krb5_etype_info_entry { 374 krb5_magic magic; 375 krb5_enctype etype; 376 unsigned int length; 377 krb5_octet *salt; 378 krb5_data s2kparams; 379 } krb5_etype_info_entry; 380 381 /* 382 * This is essentially -1 without sign extension which can screw up 383 * comparisons on 64 bit machines. If the length is this value, then 384 * the salt data is not present. This is to distinguish between not 385 * being set and being of 0 length. 386 */ 387 #define KRB5_ETYPE_NO_SALT VALID_UINT_BITS 388 389 typedef krb5_etype_info_entry ** krb5_etype_info; 390 391 /* 392 * a sam_challenge is returned for alternate preauth 393 */ 394 /* 395 SAMFlags ::= BIT STRING { 396 use-sad-as-key[0], 397 send-encrypted-sad[1], 398 must-pk-encrypt-sad[2] 399 } 400 */ 401 /* 402 PA-SAM-CHALLENGE ::= SEQUENCE { 403 sam-type[0] INTEGER, 404 sam-flags[1] SAMFlags, 405 sam-type-name[2] GeneralString OPTIONAL, 406 sam-track-id[3] GeneralString OPTIONAL, 407 sam-challenge-label[4] GeneralString OPTIONAL, 408 sam-challenge[5] GeneralString OPTIONAL, 409 sam-response-prompt[6] GeneralString OPTIONAL, 410 sam-pk-for-sad[7] EncryptionKey OPTIONAL, 411 sam-nonce[8] INTEGER OPTIONAL, 412 sam-cksum[9] Checksum OPTIONAL 413 } 414 */ 415 /* sam_type values -- informational only */ 416 #define PA_SAM_TYPE_ENIGMA 1 /* Enigma Logic */ 417 #define PA_SAM_TYPE_DIGI_PATH 2 /* Digital Pathways */ 418 #define PA_SAM_TYPE_SKEY_K0 3 /* S/key where KDC has key 0 */ 419 #define PA_SAM_TYPE_SKEY 4 /* Traditional S/Key */ 420 #define PA_SAM_TYPE_SECURID 5 /* Security Dynamics */ 421 #define PA_SAM_TYPE_CRYPTOCARD 6 /* CRYPTOCard */ 422 #if 1 /* XXX need to figure out who has which numbers assigned */ 423 #define PA_SAM_TYPE_ACTIVCARD_DEC 6 /* ActivCard decimal mode */ 424 #define PA_SAM_TYPE_ACTIVCARD_HEX 7 /* ActivCard hex mode */ 425 #define PA_SAM_TYPE_DIGI_PATH_HEX 8 /* Digital Pathways hex mode */ 426 #endif 427 #define PA_SAM_TYPE_EXP_BASE 128 /* experimental */ 428 #define PA_SAM_TYPE_GRAIL (PA_SAM_TYPE_EXP_BASE+0) /* testing */ 429 #define PA_SAM_TYPE_SECURID_PREDICT (PA_SAM_TYPE_EXP_BASE+1) /* special */ 430 431 typedef struct _krb5_predicted_sam_response { 432 krb5_magic magic; 433 krb5_keyblock sam_key; 434 krb5_flags sam_flags; /* Makes key munging easier */ 435 krb5_timestamp stime; /* time on server, for replay detection */ 436 krb5_int32 susec; 437 krb5_principal client; 438 krb5_data msd; /* mechanism specific data */ 439 } krb5_predicted_sam_response; 440 441 typedef struct _krb5_sam_challenge { 442 krb5_magic magic; 443 krb5_int32 sam_type; /* information */ 444 krb5_flags sam_flags; /* KRB5_SAM_* values */ 445 krb5_data sam_type_name; 446 krb5_data sam_track_id; 447 krb5_data sam_challenge_label; 448 krb5_data sam_challenge; 449 krb5_data sam_response_prompt; 450 krb5_data sam_pk_for_sad; 451 krb5_int32 sam_nonce; 452 krb5_checksum sam_cksum; 453 } krb5_sam_challenge; 454 455 typedef struct _krb5_sam_key { /* reserved for future use */ 456 krb5_magic magic; 457 krb5_keyblock sam_key; 458 } krb5_sam_key; 459 460 typedef struct _krb5_enc_sam_response_enc { 461 krb5_magic magic; 462 krb5_int32 sam_nonce; 463 krb5_timestamp sam_timestamp; 464 krb5_int32 sam_usec; 465 krb5_data sam_sad; 466 } krb5_enc_sam_response_enc; 467 468 typedef struct _krb5_sam_response { 469 krb5_magic magic; 470 krb5_int32 sam_type; /* informational */ 471 krb5_flags sam_flags; /* KRB5_SAM_* values */ 472 krb5_data sam_track_id; /* copied */ 473 krb5_enc_data sam_enc_key; /* krb5_sam_key - future use */ 474 krb5_enc_data sam_enc_nonce_or_ts; /* krb5_enc_sam_response_enc */ 475 krb5_int32 sam_nonce; 476 krb5_timestamp sam_patimestamp; 477 } krb5_sam_response; 478 479 typedef struct _krb5_sam_challenge_2 { 480 krb5_data sam_challenge_2_body; 481 krb5_checksum **sam_cksum; /* Array of checksums */ 482 } krb5_sam_challenge_2; 483 484 typedef struct _krb5_sam_challenge_2_body { 485 krb5_magic magic; 486 krb5_int32 sam_type; /* information */ 487 krb5_flags sam_flags; /* KRB5_SAM_* values */ 488 krb5_data sam_type_name; 489 krb5_data sam_track_id; 490 krb5_data sam_challenge_label; 491 krb5_data sam_challenge; 492 krb5_data sam_response_prompt; 493 krb5_data sam_pk_for_sad; 494 krb5_int32 sam_nonce; 495 krb5_enctype sam_etype; 496 } krb5_sam_challenge_2_body; 497 498 typedef struct _krb5_sam_response_2 { 499 krb5_magic magic; 500 krb5_int32 sam_type; /* informational */ 501 krb5_flags sam_flags; /* KRB5_SAM_* values */ 502 krb5_data sam_track_id; /* copied */ 503 krb5_enc_data sam_enc_nonce_or_sad; /* krb5_enc_sam_response_enc */ 504 krb5_int32 sam_nonce; 505 } krb5_sam_response_2; 506 507 typedef struct _krb5_enc_sam_response_enc_2 { 508 krb5_magic magic; 509 krb5_int32 sam_nonce; 510 krb5_data sam_sad; 511 } krb5_enc_sam_response_enc_2; 512 513 /* 514 * Begin "dbm.h" 515 */ 516 #ifndef _KERNEL 517 518 /* 519 * Since we are always using db, use the db-ndbm include header file. 520 */ 521 522 #include "db-ndbm.h" 523 524 #endif /* !KERNEL */ 525 /* 526 * End "dbm.h" 527 */ 528 529 /* 530 * Begin "ext-proto.h" 531 */ 532 #ifndef KRB5_EXT_PROTO__ 533 #define KRB5_EXT_PROTO__ 534 535 #ifndef _KERNEL 536 #include <stdlib.h> 537 #include <string.h> 538 #endif /* !_KERNEL */ 539 540 #ifndef HAVE_STRDUP 541 extern char *strdup (const char *); 542 #endif 543 544 #ifndef _KERNEL 545 #ifdef HAVE_UNISTD_H 546 #include <unistd.h> 547 #endif 548 #endif /* !_KERNEL */ 549 550 #endif /* KRB5_EXT_PROTO__ */ 551 /* 552 * End "ext-proto.h" 553 */ 554 555 /* 556 * Begin "sysincl.h" 557 */ 558 #ifndef KRB5_SYSINCL__ 559 #define KRB5_SYSINCL__ 560 561 #ifndef KRB5_SYSTYPES__ 562 #define KRB5_SYSTYPES__ 563 /* needed for much of the rest -- but already handled in krb5.h? */ 564 /* #include <sys/types.h> */ 565 #endif /* KRB5_SYSTYPES__ */ 566 567 #ifdef _KERNEL 568 #include <sys/time.h> 569 #else 570 #ifdef HAVE_SYS_TIME_H 571 #include <sys/time.h> 572 #ifdef TIME_WITH_SYS_TIME 573 #include <time.h> 574 #endif 575 #else 576 #include <time.h> 577 #endif 578 #endif /* _KERNEL */ 579 580 #ifdef HAVE_SYS_STAT_H 581 #include <sys/stat.h> /* struct stat, stat() */ 582 #endif 583 584 #ifdef HAVE_SYS_PARAM_H 585 #include <sys/param.h> /* MAXPATHLEN */ 586 #endif 587 588 #ifdef HAVE_SYS_FILE_H 589 #include <sys/file.h> /* prototypes for file-related 590 syscalls; flags for open & 591 friends */ 592 #endif 593 594 #ifdef _KERNEL 595 #include <sys/fcntl.h> 596 #else 597 #include <fcntl.h> 598 #endif 599 600 #endif /* KRB5_SYSINCL__ */ 601 /* 602 * End "sysincl.h" 603 */ 604 605 /* 606 * Begin "los-proto.h" 607 */ 608 #ifndef KRB5_LIBOS_PROTO__ 609 #define KRB5_LIBOS_PROTO__ 610 611 #ifndef _KERNEL 612 #include <stdio.h> 613 614 struct addrlist; 615 #endif 616 617 /* libos.spec */ 618 krb5_error_code krb5_lock_file 619 (krb5_context, int, int); 620 621 krb5_error_code krb5_unlock_file 622 (krb5_context, int); 623 624 int krb5_net_read 625 (krb5_context, int , char *, int); 626 627 int krb5_net_write 628 (krb5_context, int , const char *, int); 629 630 krb5_error_code krb5_sendto_kdc 631 (krb5_context, const krb5_data *, const krb5_data *, 632 krb5_data *, int *, int); 633 634 krb5_error_code krb5_get_krbhst 635 (krb5_context, const krb5_data *, char ***); 636 637 krb5_error_code krb5_free_krbhst 638 (krb5_context, char * const *); 639 640 krb5_error_code krb5_gen_replay_name 641 (krb5_context, const krb5_address *, const char *, char **); 642 643 krb5_error_code krb5_create_secure_file 644 (krb5_context, const char * pathname); 645 646 #ifndef _KERNEL 647 krb5_error_code krb5_sync_disk_file 648 (krb5_context, FILE *fp); 649 650 krb5_error_code 651 krb5_open_pkcs11_session(CK_SESSION_HANDLE *); 652 653 654 krb5_error_code krb5_read_message 655 (krb5_context, krb5_pointer, krb5_data *); 656 657 krb5_error_code krb5_write_message 658 (krb5_context, krb5_pointer, krb5_data *); 659 660 krb5_error_code 661 krb5int_sendto (krb5_context context, const krb5_data *message, 662 const struct addrlist *addrs, krb5_data *reply, 663 struct sockaddr_storage *localaddr, socklen_t *localaddrlen, 664 int *addr_used); 665 666 krb5_error_code krb5int_get_fq_local_hostname (char *, size_t); 667 #endif 668 669 /* 670 * Solaris Kerberos 671 * The following two functions are needed for better realm 672 * determination based on the DNS domain name. 673 */ 674 krb5_error_code krb5int_lookup_host(int , const char *, char **); 675 676 krb5_error_code krb5int_domain_get_realm(krb5_context, const char *, 677 char **); 678 krb5_error_code krb5int_fqdn_get_realm(krb5_context, const char *, 679 char **); 680 681 krb5_error_code krb5int_init_context_kdc(krb5_context *); 682 683 krb5_error_code krb5_os_init_context 684 (krb5_context, krb5_boolean); 685 686 void krb5_os_free_context (krb5_context); 687 688 /* This function is needed by KfM's KerberosPreferences API 689 * because it needs to be able to specify "secure" */ 690 #ifndef _KERNEL 691 krb5_error_code os_get_default_config_files 692 (profile_filespec_t **pfiles, krb5_boolean secure); 693 #endif 694 695 krb5_error_code krb5_find_config_files(void); 696 697 krb5_error_code krb5_os_hostaddr 698 (krb5_context, const char *, krb5_address ***); 699 700 #ifndef _KERNEL 701 /* N.B.: You need to include fake-addrinfo.h *before* k5-int.h if you're 702 * going to use this structure. */ 703 struct addrlist { 704 struct addrinfo **addrs; 705 int naddrs; 706 int space; 707 }; 708 709 #define ADDRLIST_INIT { 0, 0, 0 } 710 extern void krb5int_free_addrlist (struct addrlist *); 711 extern int krb5int_grow_addrlist (struct addrlist *, int); 712 extern int krb5int_add_host_to_list (struct addrlist *, const char *, 713 int, int, int, int); 714 715 krb5_error_code 716 krb5int_locate_server (krb5_context, 717 const krb5_data *realm, 718 struct addrlist *, 719 /* Only meaningful for kdc, really... */ 720 int want_masters, 721 /* look up [realms]->$realm->$name in krb5.conf */ 722 const char *profilename, 723 /* SRV record lookup */ 724 const char *dnsname, 725 int is_stream_service, 726 /* Port numbers, in network order! For profile 727 version only, DNS code gets port numbers 728 itself. Use 0 for dflport2 if there's no 729 secondary port (most common, except kdc 730 case). */ 731 int dflport1, int dflport2, 732 int family); 733 734 #endif /* _KERNEL */ 735 736 #endif /* KRB5_LIBOS_PROTO__ */ 737 738 /* new encryption provider api */ 739 740 struct krb5_enc_provider { 741 742 /* keybytes is the input size to make_key; 743 keylength is the output size */ 744 size_t block_size, keybytes, keylength; 745 746 /* cipher-state == 0 fresh state thrown away at end */ 747 krb5_error_code (*encrypt) ( 748 krb5_context context, 749 krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec, 750 krb5_const krb5_data *input, krb5_data *output); 751 752 krb5_error_code (*decrypt) ( 753 krb5_context context, 754 krb5_const krb5_keyblock *key, krb5_const krb5_data *ivec, 755 krb5_const krb5_data *input, krb5_data *output); 756 757 krb5_error_code (*make_key) 758 (krb5_context, krb5_const krb5_data *, krb5_keyblock *); 759 760 krb5_error_code (*init_state) (krb5_context, 761 const krb5_keyblock *, 762 krb5_keyusage, krb5_data *); 763 krb5_error_code (*free_state) (krb5_context, krb5_data *); 764 765 }; 766 767 struct krb5_hash_provider { 768 size_t hashsize, blocksize; 769 770 /* this takes multiple inputs to avoid lots of copying. */ 771 krb5_error_code (*hash) (krb5_context context, 772 unsigned int icount, krb5_const krb5_data *input, 773 krb5_data *output); 774 }; 775 776 struct krb5_keyhash_provider { 777 size_t hashsize; 778 779 krb5_error_code (*hash) ( 780 krb5_context context, 781 krb5_const krb5_keyblock *key, 782 krb5_keyusage keyusage, 783 krb5_const krb5_data *ivec, 784 krb5_const krb5_data *input, krb5_data *output); 785 786 krb5_error_code (*verify) ( 787 krb5_context context, 788 krb5_const krb5_keyblock *key, 789 krb5_keyusage keyusage, 790 krb5_const krb5_data *ivec, 791 krb5_const krb5_data *input, 792 krb5_const krb5_data *hash, 793 krb5_boolean *valid); 794 795 }; 796 797 typedef void (*krb5_encrypt_length_func) ( 798 krb5_const struct krb5_enc_provider *enc, 799 krb5_const struct krb5_hash_provider *hash, 800 size_t inputlen, size_t *length); 801 802 typedef krb5_error_code (*krb5_crypt_func) ( 803 krb5_context context, 804 krb5_const struct krb5_enc_provider *enc, 805 krb5_const struct krb5_hash_provider *hash, 806 krb5_const krb5_keyblock *key, krb5_keyusage usage, 807 krb5_const krb5_data *ivec, 808 krb5_const krb5_data *input, krb5_data *output); 809 810 #ifndef _KERNEL 811 typedef krb5_error_code (*krb5_str2key_func) ( 812 krb5_context context, 813 krb5_const struct krb5_enc_provider *enc, krb5_const krb5_data *string, 814 krb5_const krb5_data *salt, krb5_const krb5_data *params, 815 krb5_keyblock *key); 816 #endif /* _KERNEL */ 817 818 struct krb5_keytypes { 819 krb5_enctype etype; 820 char *in_string; 821 char *out_string; 822 const struct krb5_enc_provider *enc; 823 const struct krb5_hash_provider *hash; 824 krb5_encrypt_length_func encrypt_len; 825 krb5_crypt_func encrypt; 826 krb5_crypt_func decrypt; 827 krb5_cksumtype required_ctype; 828 #ifndef _KERNEL 829 /* Solaris Kerberos: strings to key conversion not done in the kernel */ 830 krb5_str2key_func str2key; 831 #else /* _KERNEL */ 832 char *mt_e_name; 833 char *mt_h_name; 834 crypto_mech_type_t kef_cipher_mt; 835 crypto_mech_type_t kef_hash_mt; 836 #endif /* _KERNEL */ 837 }; 838 839 840 struct krb5_cksumtypes { 841 krb5_cksumtype ctype; 842 unsigned int flags; 843 char *in_string; 844 char *out_string; 845 /* if the hash is keyed, this is the etype it is keyed with. 846 Actually, it can be keyed by any etype which has the same 847 enc_provider as the specified etype. DERIVE checksums can 848 be keyed with any valid etype. */ 849 krb5_enctype keyed_etype; 850 /* I can't statically initialize a union, so I'm just going to use 851 two pointers here. The keyhash is used if non-NULL. If NULL, 852 then HMAC/hash with derived keys is used if the relevant flag 853 is set. Otherwise, a non-keyed hash is computed. This is all 854 kind of messy, but so is the krb5 api. */ 855 const struct krb5_keyhash_provider *keyhash; 856 const struct krb5_hash_provider *hash; 857 /* This just gets uglier and uglier. In the key derivation case, 858 we produce an hmac. To make the hmac code work, we can't hack 859 the output size indicated by the hash provider, but we may want 860 a truncated hmac. If we want truncation, this is the number of 861 bytes we truncate to; it should be 0 otherwise. */ 862 unsigned int trunc_size; 863 #ifdef _KERNEL 864 char *mt_c_name; 865 crypto_mech_type_t kef_cksum_mt; 866 #endif /* _KERNEL */ 867 }; 868 869 #define KRB5_CKSUMFLAG_DERIVE 0x0001 870 #define KRB5_CKSUMFLAG_NOT_COLL_PROOF 0x0002 871 872 krb5_error_code krb5int_des_init_state( 873 krb5_context, 874 const krb5_keyblock *, 875 krb5_keyusage, krb5_data *); 876 877 krb5_error_code krb5int_c_mandatory_cksumtype( 878 krb5_context, 879 krb5_enctype, 880 krb5_cksumtype *); 881 882 /* 883 * normally to free a cipher_state you can just memset the length to zero and 884 * free it. 885 */ 886 krb5_error_code krb5int_default_free_state(krb5_context, krb5_data *); 887 888 /* 889 * Combine two keys (normally used by the hardware preauth mechanism) 890 */ 891 krb5_error_code krb5int_c_combine_keys 892 (krb5_context context, krb5_keyblock *key1, krb5_keyblock *key2, 893 krb5_keyblock *outkey); 894 /* 895 * in here to deal with stuff from lib/crypto 896 */ 897 898 void krb5_nfold (int inbits, krb5_const unsigned char *in, 899 int outbits, unsigned char *out); 900 901 #ifdef _KERNEL 902 903 int k5_ef_crypto( 904 const char *, char *, 905 long, krb5_keyblock *, 906 const krb5_data *, int); 907 908 krb5_error_code 909 krb5_hmac(krb5_context, const krb5_keyblock *, 910 krb5_const krb5_data *, krb5_data *); 911 912 #else 913 krb5_error_code krb5_hmac 914 (krb5_context, 915 krb5_const struct krb5_hash_provider *, 916 krb5_const krb5_keyblock *, krb5_const unsigned int, 917 krb5_const krb5_data *, krb5_data *); 918 919 #endif /* _KERNEL */ 920 921 krb5_error_code krb5int_pbkdf2_hmac_sha1 (krb5_context, 922 const krb5_data *, 923 unsigned long, 924 krb5_enctype, 925 const krb5_data *, 926 const krb5_data *); 927 928 /* Make this a function eventually? */ 929 #ifdef WIN32 930 # define krb5int_zap_data(ptr, len) SecureZeroMemory(ptr, len) 931 #else 932 # define krb5int_zap_data(ptr, len) memset((void *)ptr, 0, len) 933 # if defined(__GNUC__) && defined(__GLIBC__) 934 /* GNU libc generates multiple bogus initialization warnings if we 935 pass memset a volatile pointer. The compiler should do well enough 936 with memset even without GNU libc's attempt at optimization. */ 937 # undef memset 938 # endif 939 #endif /* WIN32 */ 940 #define zap(p,l) krb5int_zap_data(p,l) 941 942 943 /* 944 * These declarations are here, so both krb5 and k5crypto 945 * can get to them. 946 * krb5 needs to get to them so it can make them available to libgssapi. 947 */ 948 extern const struct krb5_enc_provider krb5int_enc_arcfour; 949 extern const struct krb5_hash_provider krb5int_hash_md5; 950 951 952 /* #ifdef KRB5_OLD_CRYPTO XXX SUNW14resync */ 953 954 krb5_error_code krb5_crypto_us_timeofday 955 (krb5_int32 *, krb5_int32 *); 956 957 #ifndef _KERNEL 958 /* Solaris kerberos: for convenience */ 959 time_t gmt_mktime (struct tm *); 960 #endif /* ! _KERNEL */ 961 962 /* #endif KRB5_OLD_CRYPTO */ 963 964 /* this helper fct is in libkrb5, but it makes sense declared here. */ 965 966 krb5_error_code krb5_encrypt_helper 967 (krb5_context context, krb5_const krb5_keyblock *key, 968 krb5_keyusage usage, krb5_const krb5_data *plain, 969 krb5_enc_data *cipher); 970 971 /* 972 * End "los-proto.h" 973 */ 974 975 /* 976 * Begin "libos.h" 977 */ 978 #ifndef KRB5_LIBOS__ 979 #define KRB5_LIBOS__ 980 981 typedef struct _krb5_os_context { 982 krb5_magic magic; 983 krb5_int32 time_offset; 984 krb5_int32 usec_offset; 985 krb5_int32 os_flags; 986 char * default_ccname; 987 } *krb5_os_context; 988 989 /* 990 * Flags for the os_flags field 991 * 992 * KRB5_OS_TOFFSET_VALID means that the time offset fields are valid. 993 * The intention is that this facility to correct the system clocks so 994 * that they reflect the "real" time, for systems where for some 995 * reason we can't set the system clock. Instead we calculate the 996 * offset between the system time and real time, and store the offset 997 * in the os context so that we can correct the system clock as necessary. 998 * 999 * KRB5_OS_TOFFSET_TIME means that the time offset fields should be 1000 * returned as the time by the krb5 time routines. This should only 1001 * be used for testing purposes (obviously!) 1002 */ 1003 #define KRB5_OS_TOFFSET_VALID 1 1004 #define KRB5_OS_TOFFSET_TIME 2 1005 1006 /* lock mode flags */ 1007 #define KRB5_LOCKMODE_SHARED 0x0001 1008 #define KRB5_LOCKMODE_EXCLUSIVE 0x0002 1009 #define KRB5_LOCKMODE_DONTBLOCK 0x0004 1010 #define KRB5_LOCKMODE_UNLOCK 0x0008 1011 1012 #endif /* KRB5_LIBOS__ */ 1013 /* 1014 * End "libos.h" 1015 */ 1016 1017 /* 1018 * Define our view of the size of a DES key. 1019 */ 1020 #define KRB5_MIT_DES_KEYSIZE 8 1021 1022 /* 1023 * Define a couple of SHA1 constants 1024 */ 1025 #define SHS_DATASIZE 64 1026 #define SHS_DIGESTSIZE 20 1027 1028 /* 1029 * Check if des_int.h has been included before us. If so, then check to see 1030 * that our view of the DES key size is the same as des_int.h's. 1031 */ 1032 #ifdef MIT_DES_KEYSIZE 1033 #if MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE 1034 error(MIT_DES_KEYSIZE does not equal KRB5_MIT_DES_KEYSIZE) 1035 #endif /* MIT_DES_KEYSIZE != KRB5_MIT_DES_KEYSIZE */ 1036 #endif /* MIT_DES_KEYSIZE */ 1037 1038 #ifndef _KERNEL 1039 /* Solaris Kerberos: only define PROVIDE_DES3_CBC_SHA if the following are 1040 * defined. 1041 */ 1042 #define PROVIDE_DES3_CBC_SHA 1 1043 #define PROVIDE_NIST_SHA 1 1044 1045 #endif /* !_KERNEL */ 1046 1047 /* 1048 * Begin "preauth.h" 1049 * 1050 * (Originally written by Glen Machin at Sandia Labs.) 1051 */ 1052 /* 1053 * Sandia National Laboratories also makes no representations about the 1054 * suitability of the modifications, or additions to this software for 1055 * any purpose. It is provided "as is" without express or implied warranty. 1056 * 1057 */ 1058 #ifndef KRB5_PREAUTH__ 1059 #define KRB5_PREAUTH__ 1060 1061 typedef struct _krb5_pa_enc_ts { 1062 krb5_timestamp patimestamp; 1063 krb5_int32 pausec; 1064 } krb5_pa_enc_ts; 1065 1066 typedef krb5_error_code (*krb5_preauth_obtain_proc) 1067 (krb5_context, 1068 krb5_pa_data *, 1069 krb5_etype_info, 1070 krb5_keyblock *, 1071 krb5_error_code ( * )(krb5_context, 1072 krb5_const krb5_enctype, 1073 krb5_data *, 1074 krb5_const_pointer, 1075 krb5_keyblock **), 1076 krb5_const_pointer, 1077 krb5_creds *, 1078 krb5_kdc_req *, 1079 krb5_pa_data **); 1080 1081 typedef krb5_error_code (*krb5_preauth_process_proc) 1082 (krb5_context, 1083 krb5_pa_data *, 1084 krb5_kdc_req *, 1085 krb5_kdc_rep *, 1086 krb5_error_code ( * )(krb5_context, 1087 krb5_const krb5_enctype, 1088 krb5_data *, 1089 krb5_const_pointer, 1090 krb5_keyblock **), 1091 krb5_const_pointer, 1092 krb5_error_code ( * )(krb5_context, 1093 krb5_const krb5_keyblock *, 1094 krb5_const_pointer, 1095 krb5_kdc_rep * ), 1096 krb5_keyblock **, 1097 krb5_creds *, 1098 krb5_int32 *, 1099 krb5_int32 *); 1100 1101 typedef struct _krb5_preauth_ops { 1102 krb5_magic magic; 1103 int type; 1104 int flags; 1105 krb5_preauth_obtain_proc obtain; 1106 krb5_preauth_process_proc process; 1107 } krb5_preauth_ops; 1108 1109 void krb5_free_etype_info (krb5_context, krb5_etype_info); 1110 1111 /* 1112 * Preauthentication property flags 1113 */ 1114 #define KRB5_PREAUTH_FLAGS_ENCRYPT 0x00000001 1115 #define KRB5_PREAUTH_FLAGS_HARDWARE 0x00000002 1116 1117 #endif /* KRB5_PREAUTH__ */ 1118 /* 1119 * End "preauth.h" 1120 */ 1121 1122 krb5_error_code 1123 krb5int_copy_data_contents (krb5_context, const krb5_data *, krb5_data *); 1124 1125 #ifndef _KERNEL /* needed for lib/krb5/krb/ */ 1126 typedef krb5_error_code (*krb5_gic_get_as_key_fct) 1127 (krb5_context, 1128 krb5_principal, 1129 krb5_enctype, 1130 krb5_prompter_fct, 1131 void *prompter_data, 1132 krb5_data *salt, 1133 krb5_data *s2kparams, 1134 krb5_keyblock *as_key, 1135 void *gak_data); 1136 1137 krb5_error_code KRB5_CALLCONV 1138 krb5_get_init_creds 1139 (krb5_context context, 1140 krb5_creds *creds, 1141 krb5_principal client, 1142 krb5_prompter_fct prompter, 1143 void *prompter_data, 1144 krb5_deltat start_time, 1145 char *in_tkt_service, 1146 krb5_get_init_creds_opt *options, 1147 krb5_gic_get_as_key_fct gak, 1148 void *gak_data, 1149 int *master, 1150 krb5_kdc_rep **as_reply); 1151 1152 void krb5int_populate_gic_opt ( 1153 krb5_context, krb5_get_init_creds_opt *, 1154 krb5_flags options, krb5_address * const *addrs, krb5_enctype *ktypes, 1155 krb5_preauthtype *pre_auth_types, krb5_creds *creds); 1156 1157 krb5_error_code krb5_do_preauth 1158 (krb5_context, krb5_kdc_req *, 1159 krb5_pa_data **, krb5_pa_data ***, 1160 krb5_data *, krb5_data *, krb5_enctype *, 1161 krb5_keyblock *, 1162 krb5_prompter_fct, void *, 1163 krb5_gic_get_as_key_fct, void *); 1164 #endif /* _KERNEL */ 1165 1166 void KRB5_CALLCONV krb5_free_sam_challenge 1167 (krb5_context, krb5_sam_challenge * ); 1168 void KRB5_CALLCONV krb5_free_sam_challenge_2 1169 (krb5_context, krb5_sam_challenge_2 * ); 1170 void KRB5_CALLCONV krb5_free_sam_challenge_2_body 1171 (krb5_context, krb5_sam_challenge_2_body *); 1172 void KRB5_CALLCONV krb5_free_sam_response 1173 (krb5_context, krb5_sam_response * ); 1174 void KRB5_CALLCONV krb5_free_sam_response_2 1175 (krb5_context, krb5_sam_response_2 * ); 1176 void KRB5_CALLCONV krb5_free_predicted_sam_response 1177 (krb5_context, krb5_predicted_sam_response * ); 1178 void KRB5_CALLCONV krb5_free_enc_sam_response_enc 1179 (krb5_context, krb5_enc_sam_response_enc * ); 1180 void KRB5_CALLCONV krb5_free_enc_sam_response_enc_2 1181 (krb5_context, krb5_enc_sam_response_enc_2 * ); 1182 void KRB5_CALLCONV krb5_free_sam_challenge_contents 1183 (krb5_context, krb5_sam_challenge * ); 1184 void KRB5_CALLCONV krb5_free_sam_challenge_2_contents 1185 (krb5_context, krb5_sam_challenge_2 * ); 1186 void KRB5_CALLCONV krb5_free_sam_challenge_2_body_contents 1187 (krb5_context, krb5_sam_challenge_2_body * ); 1188 void KRB5_CALLCONV krb5_free_sam_response_contents 1189 (krb5_context, krb5_sam_response * ); 1190 void KRB5_CALLCONV krb5_free_sam_response_2_contents 1191 (krb5_context, krb5_sam_response_2 *); 1192 void KRB5_CALLCONV krb5_free_predicted_sam_response_contents 1193 (krb5_context, krb5_predicted_sam_response * ); 1194 void KRB5_CALLCONV krb5_free_enc_sam_response_enc_contents 1195 (krb5_context, krb5_enc_sam_response_enc * ); 1196 void KRB5_CALLCONV krb5_free_enc_sam_response_enc_2_contents 1197 (krb5_context, krb5_enc_sam_response_enc_2 * ); 1198 1199 void KRB5_CALLCONV krb5_free_pa_enc_ts 1200 (krb5_context, krb5_pa_enc_ts *); 1201 1202 /* #include "krb5/wordsize.h" -- comes in through base-defs.h. */ 1203 #ifndef _KERNEL 1204 #include "com_err.h" 1205 #include <krb5/k5-plugin.h> 1206 #endif /* _KERNEL */ 1207 1208 /* 1209 * Solaris Kerberos: moved from sendto_kdc.c so other code can reference 1210 */ 1211 #define DEFAULT_UDP_PREF_LIMIT 1465 1212 1213 #ifndef _KERNEL 1214 #include "profile.h" 1215 #include <strings.h> 1216 #endif /* _KERNEL */ 1217 1218 #define KEY_CHANGED(k1, k2) \ 1219 (k1 == NULL || \ 1220 k1 != k2 || \ 1221 k1->enctype != k2->enctype || \ 1222 k1->length != k2->length || \ 1223 bcmp(k1->contents, k2->contents, k1->length)) 1224 1225 #ifndef _KERNEL 1226 typedef struct _arcfour_ctx { 1227 CK_SESSION_HANDLE eSession; /* encrypt session handle */ 1228 CK_SESSION_HANDLE dSession; /* decrypt session handle */ 1229 CK_OBJECT_HANDLE eKey; /* encrypt key object */ 1230 CK_OBJECT_HANDLE dKey; /* decrype key object */ 1231 uchar_t initialized; 1232 }arcfour_ctx_rec; 1233 1234 #endif /* !_KERNEL */ 1235 1236 struct _krb5_context { 1237 krb5_magic magic; 1238 krb5_enctype *in_tkt_ktypes; 1239 int in_tkt_ktype_count; 1240 krb5_enctype *tgs_ktypes; 1241 int tgs_ktype_count; 1242 /* This used to be a void*, but since we always allocate them 1243 together (though in different source files), and the types 1244 are declared in the same header, might as well just combine 1245 them. 1246 1247 The array[1] is so the existing code treating the field as 1248 a pointer will still work. For cleanliness, it should 1249 eventually get changed to a single element instead of an 1250 array. */ 1251 struct _krb5_os_context os_context[1]; 1252 char *default_realm; 1253 int ser_ctx_count; 1254 krb5_boolean profile_secure; 1255 void *ser_ctx; 1256 #ifndef _KERNEL 1257 profile_t profile; 1258 void *db_context; 1259 void *kdblog_context; 1260 /* allowable clock skew */ 1261 krb5_deltat clockskew; 1262 krb5_cksumtype kdc_req_sumtype; 1263 krb5_cksumtype default_ap_req_sumtype; 1264 krb5_cksumtype default_safe_sumtype; 1265 krb5_flags kdc_default_options; 1266 krb5_flags library_options; 1267 int fcc_default_format; 1268 int scc_default_format; 1269 krb5_prompt_type *prompt_types; 1270 /* Message size above which we'll try TCP first in send-to-kdc 1271 type code. Aside from the 2**16 size limit, we put no 1272 absolute limit on the UDP packet size. */ 1273 int udp_pref_limit; 1274 1275 /* This is the tgs_ktypes list as read from the profile, or 1276 set to compiled-in defaults. The application code cannot 1277 override it. This is used for session keys for 1278 intermediate ticket-granting tickets used to acquire the 1279 requested ticket (the session key of which may be 1280 constrained by tgs_ktypes above). */ 1281 krb5_enctype *conf_tgs_ktypes; 1282 int conf_tgs_ktypes_count; 1283 1284 /* Use the _configured version? */ 1285 krb5_boolean use_conf_ktypes; 1286 #ifdef KRB5_DNS_LOOKUP 1287 krb5_boolean profile_in_memory; 1288 #endif /* KRB5_DNS_LOOKUP */ 1289 1290 pid_t pid; /* fork safety: PID of process that did last PKCS11 init */ 1291 1292 /* Solaris Kerberos: handles for PKCS#11 crypto */ 1293 /* 1294 * Warning, do not access hSession directly as this is not fork() safe. 1295 * Instead use the krb_ctx_hSession() macro below. 1296 */ 1297 CK_SESSION_HANDLE hSession; 1298 int cryptoki_initialized; 1299 1300 /* arcfour_ctx: used only for rcmd stuff so no fork safety issues apply */ 1301 arcfour_ctx_rec arcfour_ctx; 1302 1303 /* error detail info */ 1304 struct errinfo err; 1305 #else /* ! KERNEL */ 1306 crypto_mech_type_t kef_cipher_mt; 1307 crypto_mech_type_t kef_hash_mt; 1308 crypto_mech_type_t kef_cksum_mt; 1309 #endif /* ! KERNEL */ 1310 }; 1311 1312 #ifndef _KERNEL 1313 extern pid_t __krb5_current_pid; 1314 1315 CK_SESSION_HANDLE krb5_reinit_ef_handle(krb5_context); 1316 1317 /* 1318 * fork safety: barring the ef_init code, every other function must use the 1319 * krb_ctx_hSession() macro to access the hSession field in a krb context. 1320 * Note, if the pid of the krb ctx == the current global pid then it is safe to 1321 * use the ctx hSession otherwise it needs to be re-inited before it is returned 1322 * to the caller. 1323 */ 1324 #define krb_ctx_hSession(ctx) \ 1325 ((ctx)->pid == __krb5_current_pid) ? (ctx)->hSession : krb5_reinit_ef_handle((ctx)) 1326 #endif 1327 1328 #define MD5_CKSUM_LENGTH 16 1329 #define RSA_MD5_CKSUM_LENGTH 16 1330 #define MD5_BLOCKSIZE 64 1331 1332 1333 /* 1334 * Solaris Kerberos: 1335 * This next section of prototypes and constants 1336 * are all unique to the Solaris Kerberos implementation. 1337 * Because Solaris uses the native encryption framework 1338 * to provide crypto support, the following routines 1339 * are needed to support this system. 1340 */ 1341 1342 /* 1343 * Begin Solaris Crypto Prototypes 1344 */ 1345 1346 /* 1347 * define constants that are used for creating the constant 1348 * which is used to make derived keys. 1349 */ 1350 #define DK_ENCR_KEY_BYTE 0xAA 1351 #define DK_HASH_KEY_BYTE 0x55 1352 #define DK_CKSUM_KEY_BYTE 0x99 1353 1354 int init_derived_keydata(krb5_context, const struct krb5_enc_provider *, 1355 krb5_keyblock *, krb5_keyusage, 1356 krb5_keyblock **, krb5_keyblock **); 1357 1358 krb5_error_code add_derived_key(krb5_keyblock *, krb5_keyusage, uchar_t, 1359 krb5_keyblock *); 1360 1361 krb5_keyblock *find_derived_key(krb5_keyusage, uchar_t, krb5_keyblock *); 1362 krb5_keyblock *krb5_create_derived_keyblock(int); 1363 1364 #ifdef _KERNEL 1365 int k5_ef_hash(krb5_context, int, const krb5_data *, krb5_data *); 1366 1367 int k5_ef_mac(krb5_context, krb5_keyblock *, krb5_data *, 1368 const krb5_data *, krb5_data *); 1369 1370 void make_kef_key(krb5_keyblock *); 1371 int init_key_kef(crypto_mech_type_t, krb5_keyblock *); 1372 int update_key_template(krb5_keyblock *); 1373 void setup_kef_keytypes(); 1374 void setup_kef_cksumtypes(); 1375 crypto_mech_type_t get_cipher_mech_type(krb5_context, krb5_keyblock *); 1376 crypto_mech_type_t get_hash_mech_type(krb5_context, krb5_keyblock *); 1377 1378 #else 1379 /* 1380 * This structure is used to map Kerberos supported OID's, 1381 * to PKCS11 mechanisms 1382 */ 1383 #define USE_ENCR 0x01 1384 #define USE_HASH 0x02 1385 1386 typedef struct krb5_mech_2_pkcs { 1387 uchar_t flags; 1388 CK_MECHANISM_TYPE enc_algo; 1389 CK_MECHANISM_TYPE hash_algo; 1390 CK_MECHANISM_TYPE str2key_algo; 1391 } KRB5_MECH_TO_PKCS; 1392 1393 #define ENC_DEFINED(x) (((x).flags & USE_ENCR)) 1394 #define HASH_DEFINED(x) (((x).flags & USE_HASH)) 1395 1396 extern CK_RV get_algo(krb5_enctype etype, KRB5_MECH_TO_PKCS * algos); 1397 extern CK_RV get_key_type (krb5_enctype etype, CK_KEY_TYPE * keyType); 1398 extern krb5_error_code slot_supports_krb5 (CK_SLOT_ID_PTR slotid); 1399 1400 krb5_error_code init_key_uef(CK_SESSION_HANDLE, krb5_keyblock *); 1401 1402 krb5_error_code k5_ef_hash(krb5_context, CK_MECHANISM *, 1403 unsigned int, const krb5_data *, krb5_data *); 1404 1405 krb5_error_code k5_ef_mac(krb5_context context, 1406 krb5_keyblock *key, krb5_data *ivec, 1407 krb5_const krb5_data *input, krb5_data *output); 1408 1409 #endif /* !_KERNEL */ 1410 1411 krb5_error_code 1412 derive_3des_keys(krb5_context, struct krb5_enc_provider *, 1413 krb5_keyblock *, krb5_keyusage, 1414 krb5_keyblock *, krb5_keyblock *); 1415 1416 /* 1417 * End Solaris Crypto Prototypes 1418 */ 1419 1420 #define KRB5_LIBOPT_SYNC_KDCTIME 0x0001 1421 1422 /* internal message representations */ 1423 1424 typedef struct _krb5_safe { 1425 krb5_magic magic; 1426 krb5_data user_data; /* user data */ 1427 krb5_timestamp timestamp; /* client time, optional */ 1428 krb5_int32 usec; /* microsecond portion of time, 1429 optional */ 1430 krb5_ui_4 seq_number; /* sequence #, optional */ 1431 krb5_address *s_address; /* sender address */ 1432 krb5_address *r_address; /* recipient address, optional */ 1433 krb5_checksum *checksum; /* data integrity checksum */ 1434 } krb5_safe; 1435 1436 typedef struct _krb5_priv { 1437 krb5_magic magic; 1438 krb5_enc_data enc_part; /* encrypted part */ 1439 } krb5_priv; 1440 1441 typedef struct _krb5_priv_enc_part { 1442 krb5_magic magic; 1443 krb5_data user_data; /* user data */ 1444 krb5_timestamp timestamp; /* client time, optional */ 1445 krb5_int32 usec; /* microsecond portion of time, opt. */ 1446 krb5_ui_4 seq_number; /* sequence #, optional */ 1447 krb5_address *s_address; /* sender address */ 1448 krb5_address *r_address; /* recipient address, optional */ 1449 } krb5_priv_enc_part; 1450 1451 void KRB5_CALLCONV krb5_free_safe 1452 (krb5_context, krb5_safe * ); 1453 void KRB5_CALLCONV krb5_free_priv 1454 (krb5_context, krb5_priv * ); 1455 void KRB5_CALLCONV krb5_free_priv_enc_part 1456 (krb5_context, krb5_priv_enc_part * ); 1457 1458 /* 1459 * Begin "asn1.h" 1460 */ 1461 #ifndef KRB5_ASN1__ 1462 #define KRB5_ASN1__ 1463 1464 /* ASN.1 encoding knowledge; KEEP IN SYNC WITH ASN.1 defs! */ 1465 /* here we use some knowledge of ASN.1 encodings */ 1466 /* 1467 Ticket is APPLICATION 1. 1468 Authenticator is APPLICATION 2. 1469 AS_REQ is APPLICATION 10. 1470 AS_REP is APPLICATION 11. 1471 TGS_REQ is APPLICATION 12. 1472 TGS_REP is APPLICATION 13. 1473 AP_REQ is APPLICATION 14. 1474 AP_REP is APPLICATION 15. 1475 KRB_SAFE is APPLICATION 20. 1476 KRB_PRIV is APPLICATION 21. 1477 KRB_CRED is APPLICATION 22. 1478 EncASRepPart is APPLICATION 25. 1479 EncTGSRepPart is APPLICATION 26. 1480 EncAPRepPart is APPLICATION 27. 1481 EncKrbPrivPart is APPLICATION 28. 1482 EncKrbCredPart is APPLICATION 29. 1483 KRB_ERROR is APPLICATION 30. 1484 */ 1485 /* allow either constructed or primitive encoding, so check for bit 6 1486 set or reset */ 1487 #define krb5_is_krb_ticket(dat)\ 1488 ((dat) && (dat)->length && ((dat)->data[0] == 0x61 ||\ 1489 (dat)->data[0] == 0x41)) 1490 #define krb5_is_krb_authenticator(dat)\ 1491 ((dat) && (dat)->length && ((dat)->data[0] == 0x62 ||\ 1492 (dat)->data[0] == 0x42)) 1493 #define krb5_is_as_req(dat)\ 1494 ((dat) && (dat)->length && ((dat)->data[0] == 0x6a ||\ 1495 (dat)->data[0] == 0x4a)) 1496 #define krb5_is_as_rep(dat)\ 1497 ((dat) && (dat)->length && ((dat)->data[0] == 0x6b ||\ 1498 (dat)->data[0] == 0x4b)) 1499 #define krb5_is_tgs_req(dat)\ 1500 ((dat) && (dat)->length && ((dat)->data[0] == 0x6c ||\ 1501 (dat)->data[0] == 0x4c)) 1502 #define krb5_is_tgs_rep(dat)\ 1503 ((dat) && (dat)->length && ((dat)->data[0] == 0x6d ||\ 1504 (dat)->data[0] == 0x4d)) 1505 #define krb5_is_ap_req(dat)\ 1506 ((dat) && (dat)->length && ((dat)->data[0] == 0x6e ||\ 1507 (dat)->data[0] == 0x4e)) 1508 #define krb5_is_ap_rep(dat)\ 1509 ((dat) && (dat)->length && ((dat)->data[0] == 0x6f ||\ 1510 (dat)->data[0] == 0x4f)) 1511 #define krb5_is_krb_safe(dat)\ 1512 ((dat) && (dat)->length && ((dat)->data[0] == 0x74 ||\ 1513 (dat)->data[0] == 0x54)) 1514 #define krb5_is_krb_priv(dat)\ 1515 ((dat) && (dat)->length && ((dat)->data[0] == 0x75 ||\ 1516 (dat)->data[0] == 0x55)) 1517 #define krb5_is_krb_cred(dat)\ 1518 ((dat) && (dat)->length && ((dat)->data[0] == 0x76 ||\ 1519 (dat)->data[0] == 0x56)) 1520 #define krb5_is_krb_enc_as_rep_part(dat)\ 1521 ((dat) && (dat)->length && ((dat)->data[0] == 0x79 ||\ 1522 (dat)->data[0] == 0x59)) 1523 #define krb5_is_krb_enc_tgs_rep_part(dat)\ 1524 ((dat) && (dat)->length && ((dat)->data[0] == 0x7a ||\ 1525 (dat)->data[0] == 0x5a)) 1526 #define krb5_is_krb_enc_ap_rep_part(dat)\ 1527 ((dat) && (dat)->length && ((dat)->data[0] == 0x7b ||\ 1528 (dat)->data[0] == 0x5b)) 1529 #define krb5_is_krb_enc_krb_priv_part(dat)\ 1530 ((dat) && (dat)->length && ((dat)->data[0] == 0x7c ||\ 1531 (dat)->data[0] == 0x5c)) 1532 #define krb5_is_krb_enc_krb_cred_part(dat)\ 1533 ((dat) && (dat)->length && ((dat)->data[0] == 0x7d ||\ 1534 (dat)->data[0] == 0x5d)) 1535 #define krb5_is_krb_error(dat)\ 1536 ((dat) && (dat)->length && ((dat)->data[0] == 0x7e ||\ 1537 (dat)->data[0] == 0x5e)) 1538 1539 /************************************************************************* 1540 * Prototypes for krb5_encode.c 1541 *************************************************************************/ 1542 1543 /* 1544 krb5_error_code encode_krb5_structure(const krb5_structure *rep, 1545 krb5_data **code); 1546 modifies *code 1547 effects Returns the ASN.1 encoding of *rep in **code. 1548 Returns ASN1_MISSING_FIELD if a required field is emtpy in *rep. 1549 Returns ENOMEM if memory runs out. 1550 */ 1551 1552 krb5_error_code encode_krb5_authenticator 1553 (const krb5_authenticator *rep, krb5_data **code); 1554 1555 krb5_error_code encode_krb5_ticket 1556 (const krb5_ticket *rep, krb5_data **code); 1557 1558 krb5_error_code encode_krb5_encryption_key 1559 (const krb5_keyblock *rep, krb5_data **code); 1560 1561 krb5_error_code encode_krb5_enc_tkt_part 1562 (const krb5_enc_tkt_part *rep, krb5_data **code); 1563 1564 krb5_error_code encode_krb5_enc_kdc_rep_part 1565 (const krb5_enc_kdc_rep_part *rep, krb5_data **code); 1566 1567 /* yes, the translation is identical to that used for KDC__REP */ 1568 krb5_error_code encode_krb5_as_rep 1569 (const krb5_kdc_rep *rep, krb5_data **code); 1570 1571 /* yes, the translation is identical to that used for KDC__REP */ 1572 krb5_error_code encode_krb5_tgs_rep 1573 (const krb5_kdc_rep *rep, krb5_data **code); 1574 1575 krb5_error_code encode_krb5_ap_req 1576 (const krb5_ap_req *rep, krb5_data **code); 1577 1578 krb5_error_code encode_krb5_ap_rep 1579 (const krb5_ap_rep *rep, krb5_data **code); 1580 1581 krb5_error_code encode_krb5_ap_rep_enc_part 1582 (const krb5_ap_rep_enc_part *rep, krb5_data **code); 1583 1584 krb5_error_code encode_krb5_as_req 1585 (const krb5_kdc_req *rep, krb5_data **code); 1586 1587 krb5_error_code encode_krb5_tgs_req 1588 (const krb5_kdc_req *rep, krb5_data **code); 1589 1590 krb5_error_code encode_krb5_kdc_req_body 1591 (const krb5_kdc_req *rep, krb5_data **code); 1592 1593 krb5_error_code encode_krb5_safe 1594 (const krb5_safe *rep, krb5_data **code); 1595 1596 krb5_error_code encode_krb5_safe_with_body 1597 (const krb5_safe *rep, const krb5_data *body, krb5_data **code); 1598 1599 krb5_error_code encode_krb5_priv 1600 (const krb5_priv *rep, krb5_data **code); 1601 1602 krb5_error_code encode_krb5_enc_priv_part 1603 (const krb5_priv_enc_part *rep, krb5_data **code); 1604 1605 krb5_error_code encode_krb5_cred 1606 (const krb5_cred *rep, krb5_data **code); 1607 1608 krb5_error_code encode_krb5_enc_cred_part 1609 (const krb5_cred_enc_part *rep, krb5_data **code); 1610 1611 krb5_error_code encode_krb5_error 1612 (const krb5_error *rep, krb5_data **code); 1613 1614 krb5_error_code encode_krb5_authdata 1615 (const krb5_authdata **rep, krb5_data **code); 1616 1617 krb5_error_code encode_krb5_pwd_sequence 1618 (const passwd_phrase_element *rep, krb5_data **code); 1619 1620 krb5_error_code encode_krb5_pwd_data 1621 (const krb5_pwd_data *rep, krb5_data **code); 1622 1623 krb5_error_code encode_krb5_padata_sequence 1624 (const krb5_pa_data ** rep, krb5_data **code); 1625 1626 krb5_error_code encode_krb5_alt_method 1627 (const krb5_alt_method *, krb5_data **code); 1628 1629 krb5_error_code encode_krb5_etype_info 1630 (const krb5_etype_info_entry **, krb5_data **code); 1631 1632 krb5_error_code encode_krb5_etype_info2 1633 (const krb5_etype_info_entry **, krb5_data **code); 1634 1635 krb5_error_code encode_krb5_enc_data 1636 (const krb5_enc_data *, krb5_data **); 1637 1638 krb5_error_code encode_krb5_pa_enc_ts 1639 (const krb5_pa_enc_ts *, krb5_data **); 1640 1641 krb5_error_code encode_krb5_sam_challenge 1642 (const krb5_sam_challenge * , krb5_data **); 1643 1644 krb5_error_code encode_krb5_sam_key 1645 (const krb5_sam_key * , krb5_data **); 1646 1647 krb5_error_code encode_krb5_enc_sam_response_enc 1648 (const krb5_enc_sam_response_enc * , krb5_data **); 1649 1650 krb5_error_code encode_krb5_sam_response 1651 (const krb5_sam_response * , krb5_data **); 1652 1653 krb5_error_code encode_krb5_predicted_sam_response 1654 (const krb5_predicted_sam_response * , krb5_data **); 1655 1656 krb5_error_code encode_krb5_sam_challenge_2 1657 (const krb5_sam_challenge_2 * , krb5_data **); 1658 1659 krb5_error_code encode_krb5_sam_challenge_2_body 1660 (const krb5_sam_challenge_2_body * , krb5_data **); 1661 1662 krb5_error_code encode_krb5_enc_sam_response_enc_2 1663 (const krb5_enc_sam_response_enc_2 * , krb5_data **); 1664 1665 krb5_error_code encode_krb5_sam_response_2 1666 (const krb5_sam_response_2 * , krb5_data **); 1667 1668 krb5_error_code encode_krb5_setpw_req 1669 (const krb5_principal target, char *password, krb5_data **code); 1670 1671 /************************************************************************* 1672 * End of prototypes for krb5_encode.c 1673 *************************************************************************/ 1674 1675 /************************************************************************* 1676 * Prototypes for krb5_decode.c 1677 *************************************************************************/ 1678 1679 /* 1680 krb5_error_code decode_krb5_structure(const krb5_data *code, 1681 krb5_structure **rep); 1682 1683 requires Expects **rep to not have been allocated; 1684 a new *rep is allocated regardless of the old value. 1685 effects Decodes *code into **rep. 1686 Returns ENOMEM if memory is exhausted. 1687 Returns asn1 and krb5 errors. 1688 */ 1689 1690 krb5_error_code decode_krb5_authenticator 1691 (const krb5_data *code, krb5_authenticator **rep); 1692 1693 krb5_error_code decode_krb5_ticket 1694 (const krb5_data *code, krb5_ticket **rep); 1695 1696 krb5_error_code decode_krb5_encryption_key 1697 (const krb5_data *output, krb5_keyblock **rep); 1698 1699 krb5_error_code decode_krb5_enc_tkt_part 1700 (const krb5_data *output, krb5_enc_tkt_part **rep); 1701 1702 krb5_error_code decode_krb5_enc_kdc_rep_part 1703 (const krb5_data *output, krb5_enc_kdc_rep_part **rep); 1704 1705 krb5_error_code decode_krb5_as_rep 1706 (const krb5_data *output, krb5_kdc_rep **rep); 1707 1708 krb5_error_code decode_krb5_tgs_rep 1709 (const krb5_data *output, krb5_kdc_rep **rep); 1710 1711 krb5_error_code decode_krb5_ap_req 1712 (const krb5_data *output, krb5_ap_req **rep); 1713 1714 krb5_error_code decode_krb5_ap_rep 1715 (const krb5_data *output, krb5_ap_rep **rep); 1716 1717 krb5_error_code decode_krb5_ap_rep_enc_part 1718 (const krb5_data *output, krb5_ap_rep_enc_part **rep); 1719 1720 krb5_error_code decode_krb5_as_req 1721 (const krb5_data *output, krb5_kdc_req **rep); 1722 1723 krb5_error_code decode_krb5_tgs_req 1724 (const krb5_data *output, krb5_kdc_req **rep); 1725 1726 krb5_error_code decode_krb5_kdc_req_body 1727 (const krb5_data *output, krb5_kdc_req **rep); 1728 1729 krb5_error_code decode_krb5_safe 1730 (const krb5_data *output, krb5_safe **rep); 1731 1732 krb5_error_code decode_krb5_safe_with_body 1733 (const krb5_data *output, krb5_safe **rep, krb5_data *body); 1734 1735 krb5_error_code decode_krb5_priv 1736 (const krb5_data *output, krb5_priv **rep); 1737 1738 krb5_error_code decode_krb5_enc_priv_part 1739 (const krb5_data *output, krb5_priv_enc_part **rep); 1740 1741 krb5_error_code decode_krb5_cred 1742 (const krb5_data *output, krb5_cred **rep); 1743 1744 krb5_error_code decode_krb5_enc_cred_part 1745 (const krb5_data *output, krb5_cred_enc_part **rep); 1746 1747 krb5_error_code decode_krb5_error 1748 (const krb5_data *output, krb5_error **rep); 1749 1750 krb5_error_code decode_krb5_authdata 1751 (const krb5_data *output, krb5_authdata ***rep); 1752 1753 krb5_error_code decode_krb5_pwd_sequence 1754 (const krb5_data *output, passwd_phrase_element **rep); 1755 1756 krb5_error_code decode_krb5_pwd_data 1757 (const krb5_data *output, krb5_pwd_data **rep); 1758 1759 krb5_error_code decode_krb5_padata_sequence 1760 (const krb5_data *output, krb5_pa_data ***rep); 1761 1762 krb5_error_code decode_krb5_alt_method 1763 (const krb5_data *output, krb5_alt_method **rep); 1764 1765 krb5_error_code decode_krb5_etype_info 1766 (const krb5_data *output, krb5_etype_info_entry ***rep); 1767 1768 krb5_error_code decode_krb5_etype_info2 1769 (const krb5_data *output, krb5_etype_info_entry ***rep); 1770 1771 krb5_error_code decode_krb5_enc_data 1772 (const krb5_data *output, krb5_enc_data **rep); 1773 1774 krb5_error_code decode_krb5_pa_enc_ts 1775 (const krb5_data *output, krb5_pa_enc_ts **rep); 1776 1777 krb5_error_code decode_krb5_sam_challenge 1778 (const krb5_data *, krb5_sam_challenge **); 1779 1780 krb5_error_code decode_krb5_sam_key 1781 (const krb5_data *, krb5_sam_key **); 1782 1783 krb5_error_code decode_krb5_enc_sam_response_enc 1784 (const krb5_data *, krb5_enc_sam_response_enc **); 1785 1786 krb5_error_code decode_krb5_sam_response 1787 (const krb5_data *, krb5_sam_response **); 1788 1789 krb5_error_code decode_krb5_predicted_sam_response 1790 (const krb5_data *, krb5_predicted_sam_response **); 1791 1792 krb5_error_code decode_krb5_sam_challenge_2 1793 (const krb5_data *, krb5_sam_challenge_2 **); 1794 1795 krb5_error_code decode_krb5_sam_challenge_2_body 1796 (const krb5_data *, krb5_sam_challenge_2_body **); 1797 1798 krb5_error_code decode_krb5_enc_sam_response_enc_2 1799 (const krb5_data *, krb5_enc_sam_response_enc_2 **); 1800 1801 krb5_error_code decode_krb5_sam_response_2 1802 (const krb5_data *, krb5_sam_response_2 **); 1803 1804 struct _krb5_key_data; /* kdb.h */ 1805 krb5_error_code 1806 krb5int_ldap_encode_sequence_of_keys (struct _krb5_key_data *key_data, 1807 krb5_int16 n_key_data, 1808 krb5_int32 mkvno, 1809 krb5_data **code); 1810 1811 krb5_error_code 1812 krb5int_ldap_decode_sequence_of_keys (krb5_data *in, 1813 struct _krb5_key_data **out, 1814 krb5_int16 *n_key_data, 1815 int *mkvno); 1816 1817 /************************************************************************* 1818 * End of prototypes for krb5_decode.c 1819 *************************************************************************/ 1820 1821 #endif /* KRB5_ASN1__ */ 1822 /* 1823 * End "asn1.h" 1824 */ 1825 1826 1827 /* 1828 * Internal krb5 library routines 1829 */ 1830 krb5_error_code krb5_encrypt_tkt_part 1831 (krb5_context, 1832 krb5_const krb5_keyblock *, 1833 krb5_ticket *); 1834 1835 1836 krb5_error_code krb5_encode_kdc_rep 1837 (krb5_context, 1838 krb5_const krb5_msgtype, 1839 krb5_const krb5_enc_kdc_rep_part *, 1840 int using_subkey, 1841 krb5_const krb5_keyblock *, 1842 krb5_kdc_rep *, 1843 krb5_data ** ); 1844 1845 krb5_error_code krb5_validate_times 1846 (krb5_context, krb5_ticket_times *); 1847 1848 krb5_boolean krb5int_auth_con_chkseqnum 1849 (krb5_context ctx, krb5_auth_context ac, krb5_ui_4 in_seq); 1850 1851 /* 1852 * [De]Serialization Handle and operations. 1853 */ 1854 struct __krb5_serializer { 1855 krb5_magic odtype; 1856 krb5_error_code (*sizer) (krb5_context, 1857 krb5_pointer, 1858 size_t *); 1859 krb5_error_code (*externalizer) (krb5_context, 1860 krb5_pointer, 1861 krb5_octet **, 1862 size_t *); 1863 krb5_error_code (*internalizer) (krb5_context, 1864 krb5_pointer *, 1865 krb5_octet **, 1866 size_t *); 1867 }; 1868 typedef struct __krb5_serializer * krb5_ser_handle; 1869 typedef struct __krb5_serializer krb5_ser_entry; 1870 1871 krb5_ser_handle krb5_find_serializer 1872 (krb5_context, 1873 krb5_magic); 1874 krb5_error_code krb5_register_serializer 1875 (krb5_context, 1876 const krb5_ser_entry *); 1877 1878 /* Determine the external size of a particular opaque structure */ 1879 krb5_error_code KRB5_CALLCONV krb5_size_opaque 1880 (krb5_context, 1881 krb5_magic, 1882 krb5_pointer, 1883 size_t *); 1884 1885 /* Serialize the structure into a buffer */ 1886 krb5_error_code KRB5_CALLCONV krb5_externalize_opaque 1887 (krb5_context, 1888 krb5_magic, 1889 krb5_pointer, 1890 krb5_octet * *, 1891 size_t *); 1892 1893 /* Deserialize the structure from a buffer */ 1894 krb5_error_code KRB5_CALLCONV krb5_internalize_opaque 1895 (krb5_context, 1896 krb5_magic, 1897 krb5_pointer *, 1898 krb5_octet **, 1899 size_t *); 1900 1901 /* Serialize data into a buffer */ 1902 krb5_error_code krb5_externalize_data 1903 (krb5_context, 1904 krb5_pointer, 1905 krb5_octet **, 1906 size_t *); 1907 /* 1908 * Initialization routines. 1909 */ 1910 1911 /* Initialize serialization for krb5_[os_]context */ 1912 krb5_error_code KRB5_CALLCONV krb5_ser_context_init 1913 (krb5_context); 1914 1915 /* Initialize serialization for krb5_auth_context */ 1916 krb5_error_code KRB5_CALLCONV krb5_ser_auth_context_init 1917 (krb5_context); 1918 1919 /* Initialize serialization for krb5_keytab */ 1920 krb5_error_code KRB5_CALLCONV krb5_ser_keytab_init 1921 (krb5_context); 1922 1923 /* Initialize serialization for krb5_ccache */ 1924 krb5_error_code KRB5_CALLCONV krb5_ser_ccache_init 1925 (krb5_context); 1926 1927 /* Initialize serialization for krb5_rcache */ 1928 krb5_error_code KRB5_CALLCONV krb5_ser_rcache_init 1929 (krb5_context); 1930 1931 /* [De]serialize 4-byte integer */ 1932 krb5_error_code KRB5_CALLCONV krb5_ser_pack_int32 1933 (krb5_int32, 1934 krb5_octet **, 1935 size_t *); 1936 krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int32 1937 (krb5_int32 *, 1938 krb5_octet **, 1939 size_t *); 1940 /* [De]serialize 8-byte integer */ 1941 krb5_error_code KRB5_CALLCONV krb5_ser_pack_int64 1942 (krb5_int64, krb5_octet * *, size_t *); 1943 krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int64 1944 (krb5_int64 *, krb5_octet **, size_t *); 1945 /* [De]serialize byte string */ 1946 krb5_error_code KRB5_CALLCONV krb5_ser_pack_bytes 1947 (krb5_octet *, 1948 size_t, 1949 krb5_octet **, 1950 size_t *); 1951 krb5_error_code KRB5_CALLCONV krb5_ser_unpack_bytes 1952 (krb5_octet *, 1953 size_t, 1954 krb5_octet **, 1955 size_t *); 1956 1957 1958 krb5_error_code KRB5_CALLCONV krb5int_cc_default 1959 (krb5_context, krb5_ccache *); 1960 1961 krb5_error_code KRB5_CALLCONV krb5_cc_retrieve_cred_default 1962 (krb5_context, krb5_ccache, krb5_flags, krb5_creds *, krb5_creds *); 1963 1964 void krb5int_set_prompt_types 1965 (krb5_context, krb5_prompt_type *); 1966 1967 krb5_error_code 1968 krb5int_generate_and_save_subkey (krb5_context, krb5_auth_context, 1969 krb5_keyblock * /* Old keyblock, not new! */); 1970 1971 /* set and change password helpers */ 1972 1973 krb5_error_code krb5int_mk_chpw_req 1974 (krb5_context context, krb5_auth_context auth_context, 1975 krb5_data *ap_req, char *passwd, krb5_data *packet); 1976 krb5_error_code krb5int_rd_chpw_rep 1977 (krb5_context context, krb5_auth_context auth_context, 1978 krb5_data *packet, int *result_code, 1979 krb5_data *result_data); 1980 krb5_error_code KRB5_CALLCONV krb5_chpw_result_code_string 1981 (krb5_context context, int result_code, 1982 char **result_codestr); 1983 krb5_error_code krb5int_mk_setpw_req 1984 (krb5_context context, krb5_auth_context auth_context, 1985 krb5_data *ap_req, krb5_principal targetprinc, char *passwd, krb5_data *packet); 1986 krb5_error_code krb5int_rd_setpw_rep 1987 (krb5_context context, krb5_auth_context auth_context, 1988 krb5_data *packet, int *result_code, 1989 krb5_data *result_data); 1990 1991 krb5_error_code krb5int_setpw_result_code_string 1992 (krb5_context context, int result_code, 1993 const char **result_codestr); 1994 1995 struct srv_dns_entry { 1996 struct srv_dns_entry *next; 1997 int priority; 1998 int weight; 1999 unsigned short port; 2000 char *host; 2001 }; 2002 2003 krb5_error_code 2004 krb5int_make_srv_query_realm(const krb5_data *realm, 2005 const char *service, 2006 const char *protocol, 2007 struct srv_dns_entry **answers); 2008 void krb5int_free_srv_dns_data(struct srv_dns_entry *); 2009 2010 /* 2011 * Convenience function for structure magic number 2012 */ 2013 #define KRB5_VERIFY_MAGIC(structure,magic_number) \ 2014 if ((structure)->magic != (magic_number)) return (magic_number); 2015 2016 2017 /* SUNW14resync XXX - see k5-util.h */ 2018 #if 0 2019 int krb5_seteuid (int); 2020 #endif 2021 2022 char * krb5_getenv(const char *); 2023 int krb5_setenv (const char *, const char *, int); 2024 void krb5_unsetenv (const char *); 2025 2026 2027 /* SUNW14resync - (from here to EOF) not sure if we need this but will add it 2028 for future resync sake */ 2029 2030 /* To keep happy libraries which are (for now) accessing internal stuff */ 2031 2032 /* Make sure to increment by one when changing the struct */ 2033 #define KRB5INT_ACCESS_STRUCT_VERSION 9 2034 2035 #ifndef ANAME_SZ 2036 struct ktext; /* from krb.h, for krb524 support */ 2037 #endif 2038 typedef struct _krb5int_access { 2039 /* crypto stuff */ 2040 const struct krb5_hash_provider *md5_hash_provider; 2041 const struct krb5_enc_provider *arcfour_enc_provider; 2042 krb5_error_code (* krb5_hmac) (krb5_context, 2043 const struct krb5_hash_provider *hash, 2044 const krb5_keyblock *key, 2045 unsigned int icount, const krb5_data *input, 2046 krb5_data *output); 2047 /* service location and communication */ 2048 #ifndef _KERNEL 2049 krb5_error_code (*locate_server) (krb5_context, const krb5_data *, 2050 struct addrlist *, int, 2051 const char *, const char *, 2052 int, int, int, int); 2053 krb5_error_code (*sendto_udp) (krb5_context, const krb5_data *msg, 2054 const struct addrlist *, krb5_data *reply, 2055 struct sockaddr_storage *, socklen_t *, int *); 2056 krb5_error_code (*add_host_to_list)(struct addrlist *lp, 2057 const char *hostname, 2058 int port, int secport, 2059 int socktype, int family); 2060 void (*free_addrlist) (struct addrlist *); 2061 #endif /* _KERNEL */ 2062 2063 2064 krb5_error_code (*make_srv_query_realm)(const krb5_data *realm, 2065 const char *service, 2066 const char *protocol, 2067 struct srv_dns_entry **answers); 2068 void (*free_srv_dns_data)(struct srv_dns_entry *); 2069 int (*use_dns_kdc)(krb5_context); 2070 2071 /* krb4 compatibility stuff -- may be null if not enabled */ 2072 krb5_int32 (*krb_life_to_time)(krb5_int32, int); 2073 int (*krb_time_to_life)(krb5_int32, krb5_int32); 2074 int (*krb524_encode_v4tkt)(struct ktext *, char *, unsigned int *); 2075 krb5_error_code (*krb5int_c_mandatory_cksumtype) 2076 (krb5_context, krb5_enctype, krb5_cksumtype *); 2077 krb5_error_code (KRB5_CALLCONV *krb5_ser_pack_int64) 2078 (krb5_int64, krb5_octet **, size_t *); 2079 krb5_error_code (KRB5_CALLCONV *krb5_ser_unpack_int64) 2080 (krb5_int64 *, krb5_octet **, size_t *); 2081 2082 /* Used for KDB LDAP back end. */ 2083 krb5_error_code 2084 (*asn1_ldap_encode_sequence_of_keys) (struct _krb5_key_data *key_data, 2085 krb5_int16 n_key_data, 2086 krb5_int32 mkvno, 2087 krb5_data **code); 2088 2089 krb5_error_code 2090 (*asn1_ldap_decode_sequence_of_keys) (krb5_data *in, 2091 struct _krb5_key_data **out, 2092 krb5_int16 *n_key_data, 2093 int *mkvno); 2094 } krb5int_access; 2095 2096 #define KRB5INT_ACCESS_VERSION \ 2097 (((krb5_int32)((sizeof(krb5int_access) & 0xFFFF) | \ 2098 (KRB5INT_ACCESS_STRUCT_VERSION << 16))) & 0xFFFFFFFF) 2099 2100 krb5_error_code KRB5_CALLCONV krb5int_accessor 2101 (krb5int_access*, krb5_int32); 2102 2103 /* Ick -- some krb524 and krb4 support placed in the krb5 library, 2104 because AFS (and potentially other applications?) use the krb4 2105 object as an opaque token, which (in some implementations) is not 2106 in fact a krb4 ticket, so we don't want to drag in the krb4 support 2107 just to enable this. */ 2108 2109 #define KRB524_SERVICE "krb524" 2110 #define KRB524_PORT 4444 2111 2112 /* v4lifetime.c */ 2113 extern krb5_int32 krb5int_krb_life_to_time(krb5_int32, int); 2114 extern int krb5int_krb_time_to_life(krb5_int32, krb5_int32); 2115 2116 /* conv_creds.c */ 2117 int krb5int_encode_v4tkt 2118 (struct ktext *v4tkt, char *buf, unsigned int *encoded_len); 2119 2120 /* send524.c */ 2121 int krb5int_524_sendto_kdc 2122 (krb5_context context, const krb5_data * message, 2123 const krb5_data * realm, krb5_data * reply, 2124 struct sockaddr *, socklen_t *); 2125 2126 /* temporary -- this should be under lib/krb5/ccache somewhere */ 2127 2128 struct _krb5_ccache { 2129 krb5_magic magic; 2130 const struct _krb5_cc_ops *ops; 2131 krb5_pointer data; 2132 }; 2133 2134 struct _krb5_cc_ops { 2135 krb5_magic magic; 2136 char *prefix; 2137 const char * (KRB5_CALLCONV *get_name) (krb5_context, krb5_ccache); 2138 krb5_error_code (KRB5_CALLCONV *resolve) (krb5_context, krb5_ccache *, 2139 const char *); 2140 krb5_error_code (KRB5_CALLCONV *gen_new) (krb5_context, krb5_ccache *); 2141 krb5_error_code (KRB5_CALLCONV *init) (krb5_context, krb5_ccache, 2142 krb5_principal); 2143 krb5_error_code (KRB5_CALLCONV *destroy) (krb5_context, krb5_ccache); 2144 krb5_error_code (KRB5_CALLCONV *close) (krb5_context, krb5_ccache); 2145 krb5_error_code (KRB5_CALLCONV *store) (krb5_context, krb5_ccache, 2146 krb5_creds *); 2147 krb5_error_code (KRB5_CALLCONV *retrieve) (krb5_context, krb5_ccache, 2148 krb5_flags, krb5_creds *, 2149 krb5_creds *); 2150 krb5_error_code (KRB5_CALLCONV *get_princ) (krb5_context, krb5_ccache, 2151 krb5_principal *); 2152 krb5_error_code (KRB5_CALLCONV *get_first) (krb5_context, krb5_ccache, 2153 krb5_cc_cursor *); 2154 krb5_error_code (KRB5_CALLCONV *get_next) (krb5_context, krb5_ccache, 2155 krb5_cc_cursor *, krb5_creds *); 2156 krb5_error_code (KRB5_CALLCONV *end_get) (krb5_context, krb5_ccache, 2157 krb5_cc_cursor *); 2158 krb5_error_code (KRB5_CALLCONV *remove_cred) (krb5_context, krb5_ccache, 2159 krb5_flags, krb5_creds *); 2160 krb5_error_code (KRB5_CALLCONV *set_flags) (krb5_context, krb5_ccache, 2161 krb5_flags); 2162 }; 2163 2164 extern const krb5_cc_ops *krb5_cc_dfl_ops; 2165 2166 typedef struct _krb5_donot_replay { 2167 krb5_magic magic; 2168 krb5_ui_4 hash; 2169 char *server; /* null-terminated */ 2170 char *client; /* null-terminated */ 2171 krb5_int32 cusec; 2172 krb5_timestamp ctime; 2173 } krb5_donot_replay; 2174 2175 krb5_error_code krb5_rc_default 2176 (krb5_context, 2177 krb5_rcache *); 2178 krb5_error_code krb5_rc_resolve_type 2179 (krb5_context, 2180 krb5_rcache *,char *); 2181 krb5_error_code krb5_rc_resolve_full 2182 (krb5_context, 2183 krb5_rcache *,char *); 2184 char * krb5_rc_get_type 2185 (krb5_context, 2186 krb5_rcache); 2187 char * krb5_rc_default_type 2188 (krb5_context); 2189 char * krb5_rc_default_name 2190 (krb5_context); 2191 krb5_error_code krb5_auth_to_rep 2192 (krb5_context, 2193 krb5_tkt_authent *, 2194 krb5_donot_replay *); 2195 2196 krb5_error_code KRB5_CALLCONV krb5_rc_initialize 2197 (krb5_context, krb5_rcache,krb5_deltat); 2198 krb5_error_code KRB5_CALLCONV krb5_rc_recover_or_initialize 2199 (krb5_context, krb5_rcache,krb5_deltat); 2200 krb5_error_code KRB5_CALLCONV krb5_rc_recover 2201 (krb5_context, krb5_rcache); 2202 krb5_error_code KRB5_CALLCONV krb5_rc_destroy 2203 (krb5_context, krb5_rcache); 2204 krb5_error_code KRB5_CALLCONV krb5_rc_close 2205 (krb5_context, krb5_rcache); 2206 krb5_error_code KRB5_CALLCONV krb5_rc_store 2207 (krb5_context, krb5_rcache,krb5_donot_replay *); 2208 krb5_error_code KRB5_CALLCONV krb5_rc_expunge 2209 (krb5_context, krb5_rcache); 2210 krb5_error_code KRB5_CALLCONV krb5_rc_get_lifespan 2211 (krb5_context, krb5_rcache,krb5_deltat *); 2212 char *KRB5_CALLCONV krb5_rc_get_name 2213 (krb5_context, krb5_rcache); 2214 krb5_error_code KRB5_CALLCONV krb5_rc_resolve 2215 (krb5_context, krb5_rcache, char *); 2216 2217 typedef struct _krb5_kt_ops { 2218 krb5_magic magic; 2219 char *prefix; 2220 /* routines always present */ 2221 krb5_error_code (KRB5_CALLCONV *resolve) 2222 (krb5_context, 2223 const char *, 2224 krb5_keytab *); 2225 krb5_error_code (KRB5_CALLCONV *get_name) 2226 (krb5_context, 2227 krb5_keytab, 2228 char *, 2229 unsigned int); 2230 krb5_error_code (KRB5_CALLCONV *close) 2231 (krb5_context, 2232 krb5_keytab); 2233 krb5_error_code (KRB5_CALLCONV *get) 2234 (krb5_context, 2235 krb5_keytab, 2236 krb5_const_principal, 2237 krb5_kvno, 2238 krb5_enctype, 2239 krb5_keytab_entry *); 2240 krb5_error_code (KRB5_CALLCONV *start_seq_get) 2241 (krb5_context, 2242 krb5_keytab, 2243 krb5_kt_cursor *); 2244 krb5_error_code (KRB5_CALLCONV *get_next) 2245 (krb5_context, 2246 krb5_keytab, 2247 krb5_keytab_entry *, 2248 krb5_kt_cursor *); 2249 krb5_error_code (KRB5_CALLCONV *end_get) 2250 (krb5_context, 2251 krb5_keytab, 2252 krb5_kt_cursor *); 2253 /* routines to be included on extended version (write routines) */ 2254 krb5_error_code (KRB5_CALLCONV *add) 2255 (krb5_context, 2256 krb5_keytab, 2257 krb5_keytab_entry *); 2258 krb5_error_code (KRB5_CALLCONV *remove) 2259 (krb5_context, 2260 krb5_keytab, 2261 krb5_keytab_entry *); 2262 2263 /* Handle for serializer */ 2264 const krb5_ser_entry *serializer; 2265 } krb5_kt_ops; 2266 2267 extern const krb5_kt_ops krb5_kt_dfl_ops; 2268 2269 extern krb5_error_code krb5int_translate_gai_error (int); 2270 2271 /* Not sure it's ready for exposure just yet. */ 2272 extern krb5_error_code 2273 krb5int_c_mandatory_cksumtype (krb5_context, krb5_enctype, krb5_cksumtype *); 2274 2275 extern int krb5int_crypto_init (void); 2276 extern int krb5int_prng_init(void); 2277 2278 /* 2279 * SUNW14resync 2280 * Hack (?) to neuter C99 "inline" which causes warnings w/our build. 2281 */ 2282 #define inline 2283 2284 /* Solaris kerberos */ 2285 krb5_boolean KRB5_CALLCONV is_in_keytype 2286 (krb5_const krb5_enctype *keytype, 2287 int numkeytypes, krb5_enctype enctype); 2288 2289 /* 2290 * Solaris Kerberos 2291 * Use krb5_getuid() to select the mechanism to obtain the uid. 2292 */ 2293 extern uid_t krb5_getuid(); 2294 2295 /* 2296 * Referral definitions, debugging hooks, and subfunctions. 2297 */ 2298 #define KRB5_REFERRAL_MAXHOPS 5 2299 /* #define DEBUG_REFERRALS */ 2300 2301 #ifdef DEBUG_REFERRALS 2302 void krb5int_dbgref_dump_principal(char *, krb5_principal); 2303 #endif 2304 2305 /* Common hostname-parsing code. */ 2306 krb5_error_code KRB5_CALLCONV krb5int_clean_hostname 2307 (krb5_context, 2308 const char *, 2309 char *, 2310 size_t); 2311 2312 #endif /* _KRB5_INT_H */ 2313