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