xref: /freebsd/crypto/heimdal/lib/krb5/krb5.h (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
1 /*
2  * Copyright (c) 1997 - 2007 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden).
4  * All rights reserved.
5  *
6  * Portions Copyright (c) 2009 Apple Inc. All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the Institute nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 
36 /* $Id$ */
37 
38 #ifndef __KRB5_H__
39 #define __KRB5_H__
40 
41 #include <time.h>
42 #include <krb5-types.h>
43 
44 #include <asn1_err.h>
45 #include <krb5_err.h>
46 #include <heim_err.h>
47 #include <k524_err.h>
48 
49 #include <krb5_asn1.h>
50 
51 /* name confusion with MIT */
52 #ifndef KRB5KDC_ERR_KEY_EXP
53 #define KRB5KDC_ERR_KEY_EXP KRB5KDC_ERR_KEY_EXPIRED
54 #endif
55 
56 #ifdef _WIN32
57 #define KRB5_CALLCONV __stdcall
58 #else
59 #define KRB5_CALLCONV
60 #endif
61 
62 /* simple constants */
63 
64 #ifndef TRUE
65 #define TRUE  1
66 #define FALSE 0
67 #endif
68 
69 typedef int krb5_boolean;
70 
71 typedef int32_t krb5_error_code;
72 
73 typedef int32_t krb5_kvno;
74 
75 typedef uint32_t krb5_flags;
76 
77 typedef void *krb5_pointer;
78 typedef const void *krb5_const_pointer;
79 
80 struct krb5_crypto_data;
81 typedef struct krb5_crypto_data *krb5_crypto;
82 
83 struct krb5_get_creds_opt_data;
84 typedef struct krb5_get_creds_opt_data *krb5_get_creds_opt;
85 
86 struct krb5_digest_data;
87 typedef struct krb5_digest_data *krb5_digest;
88 struct krb5_ntlm_data;
89 typedef struct krb5_ntlm_data *krb5_ntlm;
90 
91 struct krb5_pac_data;
92 typedef struct krb5_pac_data *krb5_pac;
93 
94 typedef struct krb5_rd_req_in_ctx_data *krb5_rd_req_in_ctx;
95 typedef struct krb5_rd_req_out_ctx_data *krb5_rd_req_out_ctx;
96 
97 typedef CKSUMTYPE krb5_cksumtype;
98 
99 typedef Checksum krb5_checksum;
100 
101 typedef ENCTYPE krb5_enctype;
102 
103 typedef struct krb5_get_init_creds_ctx *krb5_init_creds_context;
104 
105 typedef heim_octet_string krb5_data;
106 
107 /* PKINIT related forward declarations */
108 struct ContentInfo;
109 struct krb5_pk_identity;
110 struct krb5_pk_cert;
111 
112 /* krb5_enc_data is a mit compat structure */
113 typedef struct krb5_enc_data {
114     krb5_enctype enctype;
115     krb5_kvno kvno;
116     krb5_data ciphertext;
117 } krb5_enc_data;
118 
119 /* alternative names */
120 enum {
121     ENCTYPE_NULL		= KRB5_ENCTYPE_NULL,
122     ENCTYPE_DES_CBC_CRC		= KRB5_ENCTYPE_DES_CBC_CRC,
123     ENCTYPE_DES_CBC_MD4		= KRB5_ENCTYPE_DES_CBC_MD4,
124     ENCTYPE_DES_CBC_MD5		= KRB5_ENCTYPE_DES_CBC_MD5,
125     ENCTYPE_DES3_CBC_MD5	= KRB5_ENCTYPE_DES3_CBC_MD5,
126     ENCTYPE_OLD_DES3_CBC_SHA1	= KRB5_ENCTYPE_OLD_DES3_CBC_SHA1,
127     ENCTYPE_SIGN_DSA_GENERATE	= KRB5_ENCTYPE_SIGN_DSA_GENERATE,
128     ENCTYPE_ENCRYPT_RSA_PRIV	= KRB5_ENCTYPE_ENCRYPT_RSA_PRIV,
129     ENCTYPE_ENCRYPT_RSA_PUB	= KRB5_ENCTYPE_ENCRYPT_RSA_PUB,
130     ENCTYPE_DES3_CBC_SHA1	= KRB5_ENCTYPE_DES3_CBC_SHA1,
131     ENCTYPE_AES128_CTS_HMAC_SHA1_96 = KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96,
132     ENCTYPE_AES256_CTS_HMAC_SHA1_96 = KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96,
133     ENCTYPE_ARCFOUR_HMAC	= KRB5_ENCTYPE_ARCFOUR_HMAC_MD5,
134     ENCTYPE_ARCFOUR_HMAC_MD5	= KRB5_ENCTYPE_ARCFOUR_HMAC_MD5,
135     ENCTYPE_ARCFOUR_HMAC_MD5_56	= KRB5_ENCTYPE_ARCFOUR_HMAC_MD5_56,
136     ENCTYPE_ENCTYPE_PK_CROSS	= KRB5_ENCTYPE_ENCTYPE_PK_CROSS,
137     ENCTYPE_DES_CBC_NONE	= KRB5_ENCTYPE_DES_CBC_NONE,
138     ENCTYPE_DES3_CBC_NONE	= KRB5_ENCTYPE_DES3_CBC_NONE,
139     ENCTYPE_DES_CFB64_NONE	= KRB5_ENCTYPE_DES_CFB64_NONE,
140     ENCTYPE_DES_PCBC_NONE	= KRB5_ENCTYPE_DES_PCBC_NONE,
141     ETYPE_NULL			= KRB5_ENCTYPE_NULL,
142     ETYPE_DES_CBC_CRC		= KRB5_ENCTYPE_DES_CBC_CRC,
143     ETYPE_DES_CBC_MD4		= KRB5_ENCTYPE_DES_CBC_MD4,
144     ETYPE_DES_CBC_MD5		= KRB5_ENCTYPE_DES_CBC_MD5,
145     ETYPE_DES3_CBC_MD5		= KRB5_ENCTYPE_DES3_CBC_MD5,
146     ETYPE_OLD_DES3_CBC_SHA1	= KRB5_ENCTYPE_OLD_DES3_CBC_SHA1,
147     ETYPE_SIGN_DSA_GENERATE	= KRB5_ENCTYPE_SIGN_DSA_GENERATE,
148     ETYPE_ENCRYPT_RSA_PRIV	= KRB5_ENCTYPE_ENCRYPT_RSA_PRIV,
149     ETYPE_ENCRYPT_RSA_PUB	= KRB5_ENCTYPE_ENCRYPT_RSA_PUB,
150     ETYPE_DES3_CBC_SHA1		= KRB5_ENCTYPE_DES3_CBC_SHA1,
151     ETYPE_AES128_CTS_HMAC_SHA1_96	= KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96,
152     ETYPE_AES256_CTS_HMAC_SHA1_96	= KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96,
153     ETYPE_ARCFOUR_HMAC_MD5	= KRB5_ENCTYPE_ARCFOUR_HMAC_MD5,
154     ETYPE_ARCFOUR_HMAC_MD5_56	= KRB5_ENCTYPE_ARCFOUR_HMAC_MD5_56,
155     ETYPE_ENCTYPE_PK_CROSS	= KRB5_ENCTYPE_ENCTYPE_PK_CROSS,
156     ETYPE_ARCFOUR_MD4		= KRB5_ENCTYPE_ARCFOUR_MD4,
157     ETYPE_ARCFOUR_HMAC_OLD	= KRB5_ENCTYPE_ARCFOUR_HMAC_OLD,
158     ETYPE_ARCFOUR_HMAC_OLD_EXP	= KRB5_ENCTYPE_ARCFOUR_HMAC_OLD_EXP,
159     ETYPE_DES_CBC_NONE		= KRB5_ENCTYPE_DES_CBC_NONE,
160     ETYPE_DES3_CBC_NONE		= KRB5_ENCTYPE_DES3_CBC_NONE,
161     ETYPE_DES_CFB64_NONE	= KRB5_ENCTYPE_DES_CFB64_NONE,
162     ETYPE_DES_PCBC_NONE		= KRB5_ENCTYPE_DES_PCBC_NONE,
163     ETYPE_DIGEST_MD5_NONE	= KRB5_ENCTYPE_DIGEST_MD5_NONE,
164     ETYPE_CRAM_MD5_NONE		= KRB5_ENCTYPE_CRAM_MD5_NONE
165 
166 };
167 
168 /* PDU types */
169 typedef enum krb5_pdu {
170     KRB5_PDU_ERROR = 0,
171     KRB5_PDU_TICKET = 1,
172     KRB5_PDU_AS_REQUEST = 2,
173     KRB5_PDU_AS_REPLY = 3,
174     KRB5_PDU_TGS_REQUEST = 4,
175     KRB5_PDU_TGS_REPLY = 5,
176     KRB5_PDU_AP_REQUEST = 6,
177     KRB5_PDU_AP_REPLY = 7,
178     KRB5_PDU_KRB_SAFE = 8,
179     KRB5_PDU_KRB_PRIV = 9,
180     KRB5_PDU_KRB_CRED = 10,
181     KRB5_PDU_NONE = 11 /* See krb5_get_permitted_enctypes() */
182 } krb5_pdu;
183 
184 typedef PADATA_TYPE krb5_preauthtype;
185 
186 typedef enum krb5_key_usage {
187     KRB5_KU_PA_ENC_TIMESTAMP = 1,
188     /* AS-REQ PA-ENC-TIMESTAMP padata timestamp, encrypted with the
189        client key (section 5.4.1) */
190     KRB5_KU_TICKET = 2,
191     /* AS-REP Ticket and TGS-REP Ticket (includes tgs session key or
192        application session key), encrypted with the service key
193        (section 5.4.2) */
194     KRB5_KU_AS_REP_ENC_PART = 3,
195     /* AS-REP encrypted part (includes tgs session key or application
196        session key), encrypted with the client key (section 5.4.2) */
197     KRB5_KU_TGS_REQ_AUTH_DAT_SESSION = 4,
198     /* TGS-REQ KDC-REQ-BODY AuthorizationData, encrypted with the tgs
199        session key (section 5.4.1) */
200     KRB5_KU_TGS_REQ_AUTH_DAT_SUBKEY = 5,
201     /* TGS-REQ KDC-REQ-BODY AuthorizationData, encrypted with the tgs
202           authenticator subkey (section 5.4.1) */
203     KRB5_KU_TGS_REQ_AUTH_CKSUM = 6,
204     /* TGS-REQ PA-TGS-REQ padata AP-REQ Authenticator cksum, keyed
205        with the tgs session key (sections 5.3.2, 5.4.1) */
206     KRB5_KU_TGS_REQ_AUTH = 7,
207     /* TGS-REQ PA-TGS-REQ padata AP-REQ Authenticator (includes tgs
208        authenticator subkey), encrypted with the tgs session key
209        (section 5.3.2) */
210     KRB5_KU_TGS_REP_ENC_PART_SESSION = 8,
211     /* TGS-REP encrypted part (includes application session key),
212        encrypted with the tgs session key (section 5.4.2) */
213     KRB5_KU_TGS_REP_ENC_PART_SUB_KEY = 9,
214     /* TGS-REP encrypted part (includes application session key),
215        encrypted with the tgs authenticator subkey (section 5.4.2) */
216     KRB5_KU_AP_REQ_AUTH_CKSUM = 10,
217     /* AP-REQ Authenticator cksum, keyed with the application session
218        key (section 5.3.2) */
219     KRB5_KU_AP_REQ_AUTH = 11,
220     /* AP-REQ Authenticator (includes application authenticator
221        subkey), encrypted with the application session key (section
222        5.3.2) */
223     KRB5_KU_AP_REQ_ENC_PART = 12,
224     /* AP-REP encrypted part (includes application session subkey),
225        encrypted with the application session key (section 5.5.2) */
226     KRB5_KU_KRB_PRIV = 13,
227     /* KRB-PRIV encrypted part, encrypted with a key chosen by the
228        application (section 5.7.1) */
229     KRB5_KU_KRB_CRED = 14,
230     /* KRB-CRED encrypted part, encrypted with a key chosen by the
231        application (section 5.8.1) */
232     KRB5_KU_KRB_SAFE_CKSUM = 15,
233     /* KRB-SAFE cksum, keyed with a key chosen by the application
234        (section 5.6.1) */
235     KRB5_KU_OTHER_ENCRYPTED = 16,
236     /* Data which is defined in some specification outside of
237        Kerberos to be encrypted using an RFC1510 encryption type. */
238     KRB5_KU_OTHER_CKSUM = 17,
239     /* Data which is defined in some specification outside of
240        Kerberos to be checksummed using an RFC1510 checksum type. */
241     KRB5_KU_KRB_ERROR = 18,
242     /* Krb-error checksum */
243     KRB5_KU_AD_KDC_ISSUED = 19,
244     /* AD-KDCIssued checksum */
245     KRB5_KU_MANDATORY_TICKET_EXTENSION = 20,
246     /* Checksum for Mandatory Ticket Extensions */
247     KRB5_KU_AUTH_DATA_TICKET_EXTENSION = 21,
248     /* Checksum in Authorization Data in Ticket Extensions */
249     KRB5_KU_USAGE_SEAL = 22,
250     /* seal in GSSAPI krb5 mechanism */
251     KRB5_KU_USAGE_SIGN = 23,
252     /* sign in GSSAPI krb5 mechanism */
253     KRB5_KU_USAGE_SEQ = 24,
254     /* SEQ in GSSAPI krb5 mechanism */
255     KRB5_KU_USAGE_ACCEPTOR_SEAL = 22,
256     /* acceptor sign in GSSAPI CFX krb5 mechanism */
257     KRB5_KU_USAGE_ACCEPTOR_SIGN = 23,
258     /* acceptor seal in GSSAPI CFX krb5 mechanism */
259     KRB5_KU_USAGE_INITIATOR_SEAL = 24,
260     /* initiator sign in GSSAPI CFX krb5 mechanism */
261     KRB5_KU_USAGE_INITIATOR_SIGN = 25,
262     /* initiator seal in GSSAPI CFX krb5 mechanism */
263     KRB5_KU_PA_SERVER_REFERRAL_DATA = 22,
264     /* encrypted server referral data */
265     KRB5_KU_SAM_CHECKSUM = 25,
266     /* Checksum for the SAM-CHECKSUM field */
267     KRB5_KU_SAM_ENC_TRACK_ID = 26,
268     /* Encryption of the SAM-TRACK-ID field */
269     KRB5_KU_PA_SERVER_REFERRAL = 26,
270     /* Keyusage for the server referral in a TGS req */
271     KRB5_KU_SAM_ENC_NONCE_SAD = 27,
272     /* Encryption of the SAM-NONCE-OR-SAD field */
273     KRB5_KU_PA_PKINIT_KX = 44,
274     /* Encryption type of the kdc session contribution in pk-init */
275     KRB5_KU_AS_REQ = 56,
276     /* Checksum of over the AS-REQ send by the KDC in PA-REQ-ENC-PA-REP */
277     KRB5_KU_DIGEST_ENCRYPT = -18,
278     /* Encryption key usage used in the digest encryption field */
279     KRB5_KU_DIGEST_OPAQUE = -19,
280     /* Checksum key usage used in the digest opaque field */
281     KRB5_KU_KRB5SIGNEDPATH = -21,
282     /* Checksum key usage on KRB5SignedPath */
283     KRB5_KU_CANONICALIZED_NAMES = -23
284     /* Checksum key usage on PA-CANONICALIZED */
285 } krb5_key_usage;
286 
287 typedef krb5_key_usage krb5_keyusage;
288 
289 typedef enum krb5_salttype {
290     KRB5_PW_SALT = KRB5_PADATA_PW_SALT,
291     KRB5_AFS3_SALT = KRB5_PADATA_AFS3_SALT
292 }krb5_salttype;
293 
294 typedef struct krb5_salt {
295     krb5_salttype salttype;
296     krb5_data saltvalue;
297 } krb5_salt;
298 
299 typedef ETYPE_INFO krb5_preauthinfo;
300 
301 typedef struct {
302     krb5_preauthtype type;
303     krb5_preauthinfo info; /* list of preauthinfo for this type */
304 } krb5_preauthdata_entry;
305 
306 typedef struct krb5_preauthdata {
307     unsigned len;
308     krb5_preauthdata_entry *val;
309 }krb5_preauthdata;
310 
311 typedef enum krb5_address_type {
312     KRB5_ADDRESS_INET     =   2,
313     KRB5_ADDRESS_NETBIOS  =  20,
314     KRB5_ADDRESS_INET6    =  24,
315     KRB5_ADDRESS_ADDRPORT = 256,
316     KRB5_ADDRESS_IPPORT   = 257
317 } krb5_address_type;
318 
319 enum {
320   AP_OPTS_USE_SESSION_KEY = 1,
321   AP_OPTS_MUTUAL_REQUIRED = 2,
322   AP_OPTS_USE_SUBKEY = 4		/* library internal */
323 };
324 
325 typedef HostAddress krb5_address;
326 
327 typedef HostAddresses krb5_addresses;
328 
329 typedef krb5_enctype krb5_keytype;
330 
331 enum krb5_keytype_old {
332     KEYTYPE_NULL	= ETYPE_NULL,
333     KEYTYPE_DES		= ETYPE_DES_CBC_CRC,
334     KEYTYPE_DES3	= ETYPE_OLD_DES3_CBC_SHA1,
335     KEYTYPE_AES128	= ETYPE_AES128_CTS_HMAC_SHA1_96,
336     KEYTYPE_AES256	= ETYPE_AES256_CTS_HMAC_SHA1_96,
337     KEYTYPE_ARCFOUR	= ETYPE_ARCFOUR_HMAC_MD5,
338     KEYTYPE_ARCFOUR_56	= ETYPE_ARCFOUR_HMAC_MD5_56
339 };
340 
341 typedef EncryptionKey krb5_keyblock;
342 
343 typedef AP_REQ krb5_ap_req;
344 
345 struct krb5_cc_ops;
346 
347 #ifdef _WIN32
348 #define KRB5_USE_PATH_TOKENS 1
349 #endif
350 
351 #ifdef KRB5_USE_PATH_TOKENS
352 #define KRB5_DEFAULT_CCFILE_ROOT "%{TEMP}/krb5cc_"
353 #else
354 #define KRB5_DEFAULT_CCFILE_ROOT "/tmp/krb5cc_"
355 #endif
356 
357 #define KRB5_DEFAULT_CCROOT "FILE:" KRB5_DEFAULT_CCFILE_ROOT
358 
359 #define KRB5_ACCEPT_NULL_ADDRESSES(C) 					 \
360     krb5_config_get_bool_default((C), NULL, TRUE, 			 \
361 				 "libdefaults", "accept_null_addresses", \
362 				 NULL)
363 
364 typedef void *krb5_cc_cursor;
365 typedef struct krb5_cccol_cursor_data *krb5_cccol_cursor;
366 
367 typedef struct krb5_ccache_data {
368     const struct krb5_cc_ops *ops;
369     krb5_data data;
370 }krb5_ccache_data;
371 
372 typedef struct krb5_ccache_data *krb5_ccache;
373 
374 typedef struct krb5_context_data *krb5_context;
375 
376 typedef Realm krb5_realm;
377 typedef const char *krb5_const_realm; /* stupid language */
378 
379 #define krb5_realm_length(r) strlen(r)
380 #define krb5_realm_data(r) (r)
381 
382 typedef Principal krb5_principal_data;
383 typedef struct Principal *krb5_principal;
384 typedef const struct Principal *krb5_const_principal;
385 typedef struct Principals *krb5_principals;
386 
387 typedef time_t krb5_deltat;
388 typedef time_t krb5_timestamp;
389 
390 typedef struct krb5_times {
391   krb5_timestamp authtime;
392   krb5_timestamp starttime;
393   krb5_timestamp endtime;
394   krb5_timestamp renew_till;
395 } krb5_times;
396 
397 typedef union {
398     TicketFlags b;
399     krb5_flags i;
400 } krb5_ticket_flags;
401 
402 /* options for krb5_get_in_tkt() */
403 #define KDC_OPT_FORWARDABLE		(1 << 1)
404 #define KDC_OPT_FORWARDED		(1 << 2)
405 #define KDC_OPT_PROXIABLE		(1 << 3)
406 #define KDC_OPT_PROXY			(1 << 4)
407 #define KDC_OPT_ALLOW_POSTDATE		(1 << 5)
408 #define KDC_OPT_POSTDATED		(1 << 6)
409 #define KDC_OPT_RENEWABLE		(1 << 8)
410 #define KDC_OPT_REQUEST_ANONYMOUS	(1 << 14)
411 #define KDC_OPT_DISABLE_TRANSITED_CHECK	(1 << 26)
412 #define KDC_OPT_RENEWABLE_OK		(1 << 27)
413 #define KDC_OPT_ENC_TKT_IN_SKEY		(1 << 28)
414 #define KDC_OPT_RENEW			(1 << 30)
415 #define KDC_OPT_VALIDATE		(1 << 31)
416 
417 typedef union {
418     KDCOptions b;
419     krb5_flags i;
420 } krb5_kdc_flags;
421 
422 /* flags for krb5_verify_ap_req */
423 
424 #define KRB5_VERIFY_AP_REQ_IGNORE_INVALID	(1 << 0)
425 
426 #define KRB5_GC_CACHED			(1U << 0)
427 #define KRB5_GC_USER_USER		(1U << 1)
428 #define KRB5_GC_EXPIRED_OK		(1U << 2)
429 #define KRB5_GC_NO_STORE		(1U << 3)
430 #define KRB5_GC_FORWARDABLE		(1U << 4)
431 #define KRB5_GC_NO_TRANSIT_CHECK	(1U << 5)
432 #define KRB5_GC_CONSTRAINED_DELEGATION	(1U << 6)
433 #define KRB5_GC_CANONICALIZE		(1U << 7)
434 
435 /* constants for compare_creds (and cc_retrieve_cred) */
436 #define KRB5_TC_DONT_MATCH_REALM	(1U << 31)
437 #define KRB5_TC_MATCH_KEYTYPE		(1U << 30)
438 #define KRB5_TC_MATCH_KTYPE		KRB5_TC_MATCH_KEYTYPE    /* MIT name */
439 #define KRB5_TC_MATCH_SRV_NAMEONLY	(1 << 29)
440 #define KRB5_TC_MATCH_FLAGS_EXACT	(1 << 28)
441 #define KRB5_TC_MATCH_FLAGS		(1 << 27)
442 #define KRB5_TC_MATCH_TIMES_EXACT	(1 << 26)
443 #define KRB5_TC_MATCH_TIMES		(1 << 25)
444 #define KRB5_TC_MATCH_AUTHDATA		(1 << 24)
445 #define KRB5_TC_MATCH_2ND_TKT		(1 << 23)
446 #define KRB5_TC_MATCH_IS_SKEY		(1 << 22)
447 
448 /* constants for get_flags and set_flags */
449 #define KRB5_TC_OPENCLOSE 0x00000001
450 #define KRB5_TC_NOTICKET  0x00000002
451 
452 typedef AuthorizationData krb5_authdata;
453 
454 typedef KRB_ERROR krb5_error;
455 
456 typedef struct krb5_creds {
457     krb5_principal client;
458     krb5_principal server;
459     krb5_keyblock session;
460     krb5_times times;
461     krb5_data ticket;
462     krb5_data second_ticket;
463     krb5_authdata authdata;
464     krb5_addresses addresses;
465     krb5_ticket_flags flags;
466 } krb5_creds;
467 
468 typedef struct krb5_cc_cache_cursor_data *krb5_cc_cache_cursor;
469 
470 #define KRB5_CC_OPS_VERSION 3
471 
472 typedef struct krb5_cc_ops {
473     int version;
474     const char *prefix;
475     const char* (KRB5_CALLCONV * get_name)(krb5_context, krb5_ccache);
476     krb5_error_code (KRB5_CALLCONV * resolve)(krb5_context, krb5_ccache *, const char *);
477     krb5_error_code (KRB5_CALLCONV * gen_new)(krb5_context, krb5_ccache *);
478     krb5_error_code (KRB5_CALLCONV * init)(krb5_context, krb5_ccache, krb5_principal);
479     krb5_error_code (KRB5_CALLCONV * destroy)(krb5_context, krb5_ccache);
480     krb5_error_code (KRB5_CALLCONV * close)(krb5_context, krb5_ccache);
481     krb5_error_code (KRB5_CALLCONV * store)(krb5_context, krb5_ccache, krb5_creds*);
482     krb5_error_code (KRB5_CALLCONV * retrieve)(krb5_context, krb5_ccache,
483 					       krb5_flags, const krb5_creds*, krb5_creds *);
484     krb5_error_code (KRB5_CALLCONV * get_princ)(krb5_context, krb5_ccache, krb5_principal*);
485     krb5_error_code (KRB5_CALLCONV * get_first)(krb5_context, krb5_ccache, krb5_cc_cursor *);
486     krb5_error_code (KRB5_CALLCONV * get_next)(krb5_context, krb5_ccache,
487 					       krb5_cc_cursor*, krb5_creds*);
488     krb5_error_code (KRB5_CALLCONV * end_get)(krb5_context, krb5_ccache, krb5_cc_cursor*);
489     krb5_error_code (KRB5_CALLCONV * remove_cred)(krb5_context, krb5_ccache,
490 						  krb5_flags, krb5_creds*);
491     krb5_error_code (KRB5_CALLCONV * set_flags)(krb5_context, krb5_ccache, krb5_flags);
492     int (KRB5_CALLCONV * get_version)(krb5_context, krb5_ccache);
493     krb5_error_code (KRB5_CALLCONV * get_cache_first)(krb5_context, krb5_cc_cursor *);
494     krb5_error_code (KRB5_CALLCONV * get_cache_next)(krb5_context, krb5_cc_cursor,
495 						     krb5_ccache *);
496     krb5_error_code (KRB5_CALLCONV * end_cache_get)(krb5_context, krb5_cc_cursor);
497     krb5_error_code (KRB5_CALLCONV * move)(krb5_context, krb5_ccache, krb5_ccache);
498     krb5_error_code (KRB5_CALLCONV * get_default_name)(krb5_context, char **);
499     krb5_error_code (KRB5_CALLCONV * set_default)(krb5_context, krb5_ccache);
500     krb5_error_code (KRB5_CALLCONV * lastchange)(krb5_context, krb5_ccache, krb5_timestamp *);
501     krb5_error_code (KRB5_CALLCONV * set_kdc_offset)(krb5_context, krb5_ccache, krb5_deltat);
502     krb5_error_code (KRB5_CALLCONV * get_kdc_offset)(krb5_context, krb5_ccache, krb5_deltat *);
503 } krb5_cc_ops;
504 
505 struct krb5_log_facility;
506 
507 struct krb5_config_binding {
508     enum { krb5_config_string, krb5_config_list } type;
509     char *name;
510     struct krb5_config_binding *next;
511     union {
512 	char *string;
513 	struct krb5_config_binding *list;
514 	void *generic;
515     } u;
516 };
517 
518 typedef struct krb5_config_binding krb5_config_binding;
519 
520 typedef krb5_config_binding krb5_config_section;
521 
522 typedef struct krb5_ticket {
523     EncTicketPart ticket;
524     krb5_principal client;
525     krb5_principal server;
526 } krb5_ticket;
527 
528 typedef Authenticator krb5_authenticator_data;
529 
530 typedef krb5_authenticator_data *krb5_authenticator;
531 
532 struct krb5_rcache_data;
533 typedef struct krb5_rcache_data *krb5_rcache;
534 typedef Authenticator krb5_donot_replay;
535 
536 #define KRB5_STORAGE_HOST_BYTEORDER			0x01 /* old */
537 #define KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS	0x02
538 #define KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE		0x04
539 #define KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE		0x08
540 #define KRB5_STORAGE_BYTEORDER_MASK			0x60
541 #define KRB5_STORAGE_BYTEORDER_BE			0x00 /* default */
542 #define KRB5_STORAGE_BYTEORDER_LE			0x20
543 #define KRB5_STORAGE_BYTEORDER_HOST			0x40
544 #define KRB5_STORAGE_CREDS_FLAGS_WRONG_BITORDER		0x80
545 
546 struct krb5_storage_data;
547 typedef struct krb5_storage_data krb5_storage;
548 
549 typedef struct krb5_keytab_entry {
550     krb5_principal principal;
551     krb5_kvno vno;
552     krb5_keyblock keyblock;
553     uint32_t timestamp;
554     uint32_t flags;
555     krb5_principals aliases;
556 } krb5_keytab_entry;
557 
558 typedef struct krb5_kt_cursor {
559     int fd;
560     krb5_storage *sp;
561     void *data;
562 } krb5_kt_cursor;
563 
564 struct krb5_keytab_data;
565 
566 typedef struct krb5_keytab_data *krb5_keytab;
567 
568 #define KRB5_KT_PREFIX_MAX_LEN	30
569 
570 struct krb5_keytab_data {
571     const char *prefix;
572     krb5_error_code (KRB5_CALLCONV * resolve)(krb5_context, const char*, krb5_keytab);
573     krb5_error_code (KRB5_CALLCONV * get_name)(krb5_context, krb5_keytab, char*, size_t);
574     krb5_error_code (KRB5_CALLCONV * close)(krb5_context, krb5_keytab);
575     krb5_error_code (KRB5_CALLCONV * destroy)(krb5_context, krb5_keytab);
576     krb5_error_code (KRB5_CALLCONV * get)(krb5_context, krb5_keytab, krb5_const_principal,
577 					  krb5_kvno, krb5_enctype, krb5_keytab_entry*);
578     krb5_error_code (KRB5_CALLCONV * start_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*);
579     krb5_error_code (KRB5_CALLCONV * next_entry)(krb5_context, krb5_keytab,
580 						 krb5_keytab_entry*, krb5_kt_cursor*);
581     krb5_error_code (KRB5_CALLCONV * end_seq_get)(krb5_context, krb5_keytab, krb5_kt_cursor*);
582     krb5_error_code (KRB5_CALLCONV * add)(krb5_context, krb5_keytab, krb5_keytab_entry*);
583     krb5_error_code (KRB5_CALLCONV * remove)(krb5_context, krb5_keytab, krb5_keytab_entry*);
584     void *data;
585     int32_t version;
586 };
587 
588 typedef struct krb5_keytab_data krb5_kt_ops;
589 
590 struct krb5_keytab_key_proc_args {
591     krb5_keytab keytab;
592     krb5_principal principal;
593 };
594 
595 typedef struct krb5_keytab_key_proc_args krb5_keytab_key_proc_args;
596 
597 typedef struct krb5_replay_data {
598     krb5_timestamp timestamp;
599     int32_t usec;
600     uint32_t seq;
601 } krb5_replay_data;
602 
603 /* flags for krb5_auth_con_setflags */
604 enum {
605     KRB5_AUTH_CONTEXT_DO_TIME      		= 1,
606     KRB5_AUTH_CONTEXT_RET_TIME     		= 2,
607     KRB5_AUTH_CONTEXT_DO_SEQUENCE  		= 4,
608     KRB5_AUTH_CONTEXT_RET_SEQUENCE 		= 8,
609     KRB5_AUTH_CONTEXT_PERMIT_ALL   		= 16,
610     KRB5_AUTH_CONTEXT_USE_SUBKEY   		= 32,
611     KRB5_AUTH_CONTEXT_CLEAR_FORWARDED_CRED	= 64
612 };
613 
614 /* flags for krb5_auth_con_genaddrs */
615 enum {
616     KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR       = 1,
617     KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR  = 3,
618     KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR      = 4,
619     KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR = 12
620 };
621 
622 typedef struct krb5_auth_context_data {
623     unsigned int flags;
624 
625     krb5_address *local_address;
626     krb5_address *remote_address;
627     int16_t local_port;
628     int16_t remote_port;
629     krb5_keyblock *keyblock;
630     krb5_keyblock *local_subkey;
631     krb5_keyblock *remote_subkey;
632 
633     uint32_t local_seqnumber;
634     uint32_t remote_seqnumber;
635 
636     krb5_authenticator authenticator;
637 
638     krb5_pointer i_vector;
639 
640     krb5_rcache rcache;
641 
642     krb5_keytype keytype;	/* ¿requested key type ? */
643     krb5_cksumtype cksumtype;	/* ¡requested checksum type! */
644 
645 }krb5_auth_context_data, *krb5_auth_context;
646 
647 typedef struct {
648     KDC_REP kdc_rep;
649     EncKDCRepPart enc_part;
650     KRB_ERROR error;
651 } krb5_kdc_rep;
652 
653 extern const char *heimdal_version, *heimdal_long_version;
654 
655 typedef void (KRB5_CALLCONV * krb5_log_log_func_t)(const char*, const char*, void*);
656 typedef void (KRB5_CALLCONV * krb5_log_close_func_t)(void*);
657 
658 typedef struct krb5_log_facility {
659     char *program;
660     int len;
661     struct facility *val;
662 } krb5_log_facility;
663 
664 typedef EncAPRepPart krb5_ap_rep_enc_part;
665 
666 #define KRB5_RECVAUTH_IGNORE_VERSION 1
667 
668 #define KRB5_SENDAUTH_VERSION "KRB5_SENDAUTH_V1.0"
669 
670 #define KRB5_TGS_NAME_SIZE (6)
671 #define KRB5_TGS_NAME ("krbtgt")
672 #define KRB5_WELLKNOWN_NAME ("WELLKNOWN")
673 #define KRB5_ANON_NAME ("ANONYMOUS")
674 #define KRB5_DIGEST_NAME ("digest")
675 
676 typedef enum {
677     KRB5_PROMPT_TYPE_PASSWORD		= 0x1,
678     KRB5_PROMPT_TYPE_NEW_PASSWORD	= 0x2,
679     KRB5_PROMPT_TYPE_NEW_PASSWORD_AGAIN = 0x3,
680     KRB5_PROMPT_TYPE_PREAUTH		= 0x4,
681     KRB5_PROMPT_TYPE_INFO		= 0x5
682 } krb5_prompt_type;
683 
684 typedef struct _krb5_prompt {
685     const char *prompt;
686     int hidden;
687     krb5_data *reply;
688     krb5_prompt_type type;
689 } krb5_prompt;
690 
691 typedef int (KRB5_CALLCONV * krb5_prompter_fct)(krb5_context /*context*/,
692 						void * /*data*/,
693 						const char * /*name*/,
694 						const char * /*banner*/,
695 						int /*num_prompts*/,
696 						krb5_prompt /*prompts*/[]);
697 typedef krb5_error_code (KRB5_CALLCONV * krb5_key_proc)(krb5_context /*context*/,
698 							krb5_enctype /*type*/,
699 							krb5_salt /*salt*/,
700 							krb5_const_pointer /*keyseed*/,
701 							krb5_keyblock ** /*key*/);
702 typedef krb5_error_code (KRB5_CALLCONV * krb5_decrypt_proc)(krb5_context /*context*/,
703 							    krb5_keyblock * /*key*/,
704 							    krb5_key_usage /*usage*/,
705 							    krb5_const_pointer /*decrypt_arg*/,
706 							    krb5_kdc_rep * /*dec_rep*/);
707 typedef krb5_error_code (KRB5_CALLCONV * krb5_s2k_proc)(krb5_context /*context*/,
708 							krb5_enctype /*type*/,
709 							krb5_const_pointer /*keyseed*/,
710 							krb5_salt /*salt*/,
711 							krb5_data * /*s2kparms*/,
712 							krb5_keyblock ** /*key*/);
713 
714 struct _krb5_get_init_creds_opt_private;
715 
716 struct _krb5_get_init_creds_opt {
717     krb5_flags flags;
718     krb5_deltat tkt_life;
719     krb5_deltat renew_life;
720     int forwardable;
721     int proxiable;
722     int anonymous;
723     krb5_enctype *etype_list;
724     int etype_list_length;
725     krb5_addresses *address_list;
726     /* XXX the next three should not be used, as they may be
727        removed later */
728     krb5_preauthtype *preauth_list;
729     int preauth_list_length;
730     krb5_data *salt;
731     struct _krb5_get_init_creds_opt_private *opt_private;
732 };
733 
734 typedef struct _krb5_get_init_creds_opt krb5_get_init_creds_opt;
735 
736 #define KRB5_GET_INIT_CREDS_OPT_TKT_LIFE	0x0001
737 #define KRB5_GET_INIT_CREDS_OPT_RENEW_LIFE	0x0002
738 #define KRB5_GET_INIT_CREDS_OPT_FORWARDABLE	0x0004
739 #define KRB5_GET_INIT_CREDS_OPT_PROXIABLE	0x0008
740 #define KRB5_GET_INIT_CREDS_OPT_ETYPE_LIST	0x0010
741 #define KRB5_GET_INIT_CREDS_OPT_ADDRESS_LIST	0x0020
742 #define KRB5_GET_INIT_CREDS_OPT_PREAUTH_LIST	0x0040
743 #define KRB5_GET_INIT_CREDS_OPT_SALT		0x0080 /* no supported */
744 #define KRB5_GET_INIT_CREDS_OPT_ANONYMOUS	0x0100
745 #define KRB5_GET_INIT_CREDS_OPT_DISABLE_TRANSITED_CHECK	0x0200
746 
747 /* krb5_init_creds_step flags argument */
748 #define KRB5_INIT_CREDS_STEP_FLAG_CONTINUE	0x0001
749 
750 typedef struct _krb5_verify_init_creds_opt {
751     krb5_flags flags;
752     int ap_req_nofail;
753 } krb5_verify_init_creds_opt;
754 
755 #define KRB5_VERIFY_INIT_CREDS_OPT_AP_REQ_NOFAIL	0x0001
756 
757 typedef struct krb5_verify_opt {
758     unsigned int flags;
759     krb5_ccache ccache;
760     krb5_keytab keytab;
761     krb5_boolean secure;
762     const char *service;
763 } krb5_verify_opt;
764 
765 #define KRB5_VERIFY_LREALMS		1
766 #define KRB5_VERIFY_NO_ADDRESSES	2
767 
768 #define KRB5_KPASSWD_VERS_CHANGEPW      1
769 #define KRB5_KPASSWD_VERS_SETPW         0xff80
770 
771 #define KRB5_KPASSWD_SUCCESS	0
772 #define KRB5_KPASSWD_MALFORMED	1
773 #define KRB5_KPASSWD_HARDERROR	2
774 #define KRB5_KPASSWD_AUTHERROR	3
775 #define KRB5_KPASSWD_SOFTERROR	4
776 #define KRB5_KPASSWD_ACCESSDENIED 5
777 #define KRB5_KPASSWD_BAD_VERSION 6
778 #define KRB5_KPASSWD_INITIAL_FLAG_NEEDED 7
779 
780 #define KPASSWD_PORT 464
781 
782 /* types for the new krbhst interface */
783 struct krb5_krbhst_data;
784 typedef struct krb5_krbhst_data *krb5_krbhst_handle;
785 
786 #define KRB5_KRBHST_KDC		1
787 #define KRB5_KRBHST_ADMIN	2
788 #define KRB5_KRBHST_CHANGEPW	3
789 #define KRB5_KRBHST_KRB524	4
790 #define KRB5_KRBHST_KCA		5
791 
792 typedef struct krb5_krbhst_info {
793     enum { KRB5_KRBHST_UDP,
794 	   KRB5_KRBHST_TCP,
795 	   KRB5_KRBHST_HTTP } proto;
796     unsigned short port;
797     unsigned short def_port;
798     struct addrinfo *ai;
799     struct krb5_krbhst_info *next;
800     char hostname[1]; /* has to come last */
801 } krb5_krbhst_info;
802 
803 /* flags for krb5_krbhst_init_flags (and krb5_send_to_kdc_flags) */
804 enum {
805     KRB5_KRBHST_FLAGS_MASTER      = 1,
806     KRB5_KRBHST_FLAGS_LARGE_MSG	  = 2
807 };
808 
809 typedef krb5_error_code
810 (KRB5_CALLCONV * krb5_send_to_kdc_func)(krb5_context, void *, krb5_krbhst_info *, time_t,
811 					const krb5_data *, krb5_data *);
812 
813 /** flags for krb5_parse_name_flags */
814 enum {
815     KRB5_PRINCIPAL_PARSE_NO_REALM = 1, /**< Require that there are no realm */
816     KRB5_PRINCIPAL_PARSE_REQUIRE_REALM = 2, /**< Require a realm present */
817     KRB5_PRINCIPAL_PARSE_ENTERPRISE = 4 /**< Parse as a NT-ENTERPRISE name */
818 };
819 
820 /** flags for krb5_unparse_name_flags */
821 enum {
822     KRB5_PRINCIPAL_UNPARSE_SHORT = 1, /**< No realm if it is the default realm */
823     KRB5_PRINCIPAL_UNPARSE_NO_REALM = 2, /**< No realm */
824     KRB5_PRINCIPAL_UNPARSE_DISPLAY = 4 /**< No quoting */
825 };
826 
827 typedef struct krb5_sendto_ctx_data *krb5_sendto_ctx;
828 
829 #define KRB5_SENDTO_DONE	0
830 #define KRB5_SENDTO_RESTART	1
831 #define KRB5_SENDTO_CONTINUE	2
832 
833 typedef krb5_error_code
834 (KRB5_CALLCONV * krb5_sendto_ctx_func)(krb5_context, krb5_sendto_ctx, void *,
835 				       const krb5_data *, int *);
836 
837 struct krb5_plugin;
838 enum krb5_plugin_type {
839     PLUGIN_TYPE_DATA = 1,
840     PLUGIN_TYPE_FUNC
841 };
842 
843 struct credentials; /* this is to keep the compiler happy */
844 struct getargs;
845 struct sockaddr;
846 
847 /**
848  * Semi private, not stable yet
849  */
850 
851 typedef struct krb5_crypto_iov {
852     unsigned int flags;
853     /* ignored */
854 #define KRB5_CRYPTO_TYPE_EMPTY		0
855     /* OUT krb5_crypto_length(KRB5_CRYPTO_TYPE_HEADER) */
856 #define KRB5_CRYPTO_TYPE_HEADER		1
857     /* IN and OUT */
858 #define KRB5_CRYPTO_TYPE_DATA		2
859     /* IN */
860 #define KRB5_CRYPTO_TYPE_SIGN_ONLY	3
861    /* (only for encryption) OUT krb5_crypto_length(KRB5_CRYPTO_TYPE_TRAILER) */
862 #define KRB5_CRYPTO_TYPE_PADDING	4
863    /* OUT krb5_crypto_length(KRB5_CRYPTO_TYPE_TRAILER) */
864 #define KRB5_CRYPTO_TYPE_TRAILER	5
865    /* OUT krb5_crypto_length(KRB5_CRYPTO_TYPE_CHECKSUM) */
866 #define KRB5_CRYPTO_TYPE_CHECKSUM	6
867     krb5_data data;
868 } krb5_crypto_iov;
869 
870 
871 /* Glue for MIT */
872 
873 typedef struct {
874     int32_t lr_type;
875     krb5_timestamp value;
876 } krb5_last_req_entry;
877 
878 typedef krb5_error_code
879 (KRB5_CALLCONV * krb5_gic_process_last_req)(krb5_context, krb5_last_req_entry **, void *);
880 
881 /*
882  *
883  */
884 
885 struct hx509_certs_data;
886 
887 #include <krb5-protos.h>
888 
889 /* variables */
890 
891 extern KRB5_LIB_VARIABLE const char *krb5_config_file;
892 extern KRB5_LIB_VARIABLE const char *krb5_defkeyname;
893 
894 
895 extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_acc_ops;
896 extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_fcc_ops;
897 extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_mcc_ops;
898 extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_kcm_ops;
899 extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_akcm_ops;
900 extern KRB5_LIB_VARIABLE const krb5_cc_ops krb5_scc_ops;
901 
902 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_fkt_ops;
903 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_wrfkt_ops;
904 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_javakt_ops;
905 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_mkt_ops;
906 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_akf_ops;
907 extern KRB5_LIB_VARIABLE const krb5_kt_ops krb5_any_ops;
908 
909 extern KRB5_LIB_VARIABLE const char *krb5_cc_type_api;
910 extern KRB5_LIB_VARIABLE const char *krb5_cc_type_file;
911 extern KRB5_LIB_VARIABLE const char *krb5_cc_type_memory;
912 extern KRB5_LIB_VARIABLE const char *krb5_cc_type_kcm;
913 extern KRB5_LIB_VARIABLE const char *krb5_cc_type_scc;
914 
915 #endif /* __KRB5_H__ */
916 
917 /* clang analyzer workarounds */
918 
919 #ifdef __clang_analyzer__
920 /*
921  * The clang analyzer (lint) can't know that krb5_enomem() always returns
922  * non-zero, so code like:
923  *
924  *      if ((x = malloc(...)) == NULL)
925  *          ret = krb5_enomem(context)
926  *      if (ret == 0)
927  *          *x = ...;
928  *
929  * causes false positives.
930  *
931  * The fix is to make krb5_enomem() a macro that always evaluates to ENOMEM.
932  */
933 #define krb5_enomem(c) (krb5_enomem(c), ENOMEM)
934 #endif
935 
936