Imported Upstream version 1.17
[platform/upstream/krb5.git] / src / lib / gssapi / generic / gssapi_ext.h
1 /*
2  * Copyright 2008 by the Massachusetts Institute of Technology.
3  * All Rights Reserved.
4  *
5  * Export of this software from the United States of America may
6  *   require a specific license from the United States Government.
7  *   It is the responsibility of any person or organization contemplating
8  *   export to obtain such a license before exporting.
9  *
10  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
11  * distribute this software and its documentation for any purpose and
12  * without fee is hereby granted, provided that the above copyright
13  * notice appear in all copies and that both that copyright notice and
14  * this permission notice appear in supporting documentation, and that
15  * the name of M.I.T. not be used in advertising or publicity pertaining
16  * to distribution of the software without specific, written prior
17  * permission.  Furthermore if you modify this software you must label
18  * your software as modified software and not distribute it in such a
19  * fashion that it might be confused with the original M.I.T. software.
20  * M.I.T. makes no representations about the suitability of
21  * this software for any purpose.  It is provided "as is" without express
22  * or implied warranty.
23  */
24
25 #ifndef GSSAPI_EXT_H_
26 #define GSSAPI_EXT_H_
27
28 #include <gssapi/gssapi.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif /* __cplusplus */
33
34 /*
35  * Solaris extensions
36  */
37 #ifndef _WIN32
38 OM_uint32 KRB5_CALLCONV
39 gss_pname_to_uid
40         (OM_uint32 *minor,
41          const gss_name_t name,
42          const gss_OID mech_type,
43          uid_t *uidOut);
44 #endif
45
46 /**
47  * Provides a platform-specific name for a GSSAPI name as interpreted by a
48  * given mechanism.
49  *
50  * @param [out] minor      Minor status code
51  * @param [in] name        The gss name resulting from accept_sec_context
52  * @param [in] mech_type   The mechanism that will be asked to map @a name to a
53  *                         local name
54  * @param [out] localname  Caller-allocated buffer to be filled in with the
55  *                         local name on success
56  */
57 OM_uint32 KRB5_CALLCONV
58 gss_localname
59         (OM_uint32 *minor,
60          const gss_name_t name,
61          gss_const_OID mech_type,
62          gss_buffer_t localname);
63
64 /**
65  * Determine whether a mechanism name is authorized to act as a username.
66  *
67  * @param [in] name      Mechanism name
68  * @param [in] username  System username
69  *
70  * This is a simple wrapper around gss_authorize_localname().  It only supports
71  * system usernames as local names, and cannot distinguish between lack of
72  * authorization and other errors.
73  *
74  * @retval 1 @a name is authorized to act as @a username
75  * @retval 0 @a name is not authorized or an error occurred
76  */
77 int KRB5_CALLCONV
78 gss_userok(const gss_name_t name,
79            const char *username);
80
81 /**
82  *  Determine whether a mechanism name is authorized to act as a local name.
83  *
84  * @param [out] minor  Minor status code
85  * @param [in] name    Mechanism name
86  * @param [in] user    Local name
87  *
88  * @a name is a mechanism name, typically the result of a completed
89  * gss_accept_sec_context().  @a user is an internal name representing a local
90  * name, such as a name imported by gss_import_name() with an @a
91  * input_name_type of @c GSS_C_NT_USER_NAME.
92  *
93  * @return Return GSS_S_COMPLETE if @a name is authorized to act as @a user,
94  * GSS_S_UNAUTHORIZED if not, or an appropriate GSS error code if an error
95  * occured.
96  *
97  * @sa gss_userok
98  */
99 OM_uint32 KRB5_CALLCONV
100 gss_authorize_localname(OM_uint32 *minor,
101                         const gss_name_t name,
102                         const gss_name_t user);
103
104 OM_uint32 KRB5_CALLCONV
105 gss_acquire_cred_with_password(
106     OM_uint32 *,        /* minor_status */
107     const gss_name_t,   /* desired_name */
108     const gss_buffer_t, /* password */
109     OM_uint32,          /* time_req */
110     const gss_OID_set,  /* desired_mechs */
111     gss_cred_usage_t,   /* cred_usage */
112     gss_cred_id_t *,    /* output_cred_handle */
113     gss_OID_set *,      /* actual_mechs */
114     OM_uint32 *);       /* time_rec */
115
116 OM_uint32 KRB5_CALLCONV
117 gss_add_cred_with_password(
118     OM_uint32 *,        /* minor_status */
119     const gss_cred_id_t,/* input_cred_handle */
120     const gss_name_t,   /* desired_name */
121     const gss_OID,      /* desired_mech */
122     const gss_buffer_t, /* password */
123     gss_cred_usage_t,   /* cred_usage */
124     OM_uint32,          /* initiator_time_req */
125     OM_uint32,          /* acceptor_time_req */
126     gss_cred_id_t *,    /* output_cred_handle */
127     gss_OID_set *,      /* actual_mechs */
128     OM_uint32 *,        /* initiator_time_rec */
129     OM_uint32 *);       /* acceptor_time_rec */
130
131 /*
132  * GGF extensions
133  */
134 typedef struct gss_buffer_set_desc_struct {
135     size_t count;
136     gss_buffer_desc *elements;
137 } gss_buffer_set_desc, *gss_buffer_set_t;
138
139 #define GSS_C_NO_BUFFER_SET ((gss_buffer_set_t) 0)
140
141 OM_uint32 KRB5_CALLCONV gss_create_empty_buffer_set
142         (OM_uint32 * /*minor_status*/,
143          gss_buffer_set_t * /*buffer_set*/);
144
145 OM_uint32 KRB5_CALLCONV gss_add_buffer_set_member
146         (OM_uint32 * /*minor_status*/,
147          const gss_buffer_t /*member_buffer*/,
148          gss_buffer_set_t * /*buffer_set*/);
149
150 OM_uint32 KRB5_CALLCONV gss_release_buffer_set
151         (OM_uint32 * /*minor_status*/,
152          gss_buffer_set_t * /*buffer_set*/);
153
154 OM_uint32 KRB5_CALLCONV gss_inquire_sec_context_by_oid
155         (OM_uint32 * /*minor_status*/,
156          const gss_ctx_id_t /*context_handle*/,
157          const gss_OID /*desired_object*/,
158          gss_buffer_set_t * /*data_set*/);
159
160 OM_uint32 KRB5_CALLCONV gss_inquire_cred_by_oid
161         (OM_uint32 * /*minor_status*/,
162          const gss_cred_id_t /*cred_handle*/,
163          const gss_OID /*desired_object*/,
164          gss_buffer_set_t * /*data_set*/);
165
166 OM_uint32 KRB5_CALLCONV gss_set_sec_context_option
167         (OM_uint32 * /*minor_status*/,
168          gss_ctx_id_t * /*cred_handle*/,
169          const gss_OID /*desired_object*/,
170          const gss_buffer_t /*value*/);
171
172 /*
173  * Export import cred extensions from GGF, but using Heimdal's signatures
174  */
175 OM_uint32 KRB5_CALLCONV gss_export_cred
176         (OM_uint32 * /* minor_status */,
177          gss_cred_id_t /* cred_handle */,
178          gss_buffer_t /* token */);
179
180 OM_uint32 KRB5_CALLCONV gss_import_cred
181         (OM_uint32 * /* minor_status */,
182          gss_buffer_t /* token */,
183          gss_cred_id_t * /* cred_handle */);
184
185 /*
186  * Heimdal extension
187  */
188 OM_uint32 KRB5_CALLCONV gss_set_cred_option
189         (OM_uint32 * /*minor_status*/,
190          gss_cred_id_t * /*cred*/,
191          const gss_OID /*desired_object*/,
192          const gss_buffer_t /*value*/);
193
194 /*
195  * Call the given method on the given mechanism
196  */
197 OM_uint32 KRB5_CALLCONV gssspi_mech_invoke
198         (OM_uint32 * /*minor_status*/,
199          const gss_OID /*desired_mech*/,
200          const gss_OID /*desired_object*/,
201          gss_buffer_t /*value*/);
202
203 /*
204  * AEAD extensions
205  */
206
207 OM_uint32 KRB5_CALLCONV gss_wrap_aead
208         (OM_uint32 * /*minor_status*/,
209          gss_ctx_id_t /*context_handle*/,
210          int /*conf_req_flag*/,
211          gss_qop_t /*qop_req*/,
212          gss_buffer_t /*input_assoc_buffer*/,
213          gss_buffer_t /*input_payload_buffer*/,
214          int * /*conf_state*/,
215          gss_buffer_t /*output_message_buffer*/);
216
217 OM_uint32 KRB5_CALLCONV gss_unwrap_aead
218         (OM_uint32 * /*minor_status*/,
219          gss_ctx_id_t /*context_handle*/,
220          gss_buffer_t /*input_message_buffer*/,
221          gss_buffer_t /*input_assoc_buffer*/,
222          gss_buffer_t /*output_payload_buffer*/,
223          int * /*conf_state*/,
224          gss_qop_t * /*qop_state*/);
225
226 /*
227  * SSPI extensions
228  */
229 #define GSS_C_DCE_STYLE                 0x1000
230 #define GSS_C_IDENTIFY_FLAG             0x2000
231 #define GSS_C_EXTENDED_ERROR_FLAG       0x4000
232
233 /*
234  * Returns a buffer set with the first member containing the
235  * session key for SSPI compatibility. The optional second
236  * member contains an OID identifying the session key type.
237  */
238 GSS_DLLIMP extern gss_OID GSS_C_INQ_SSPI_SESSION_KEY;
239
240 OM_uint32 KRB5_CALLCONV gss_complete_auth_token
241         (OM_uint32 *minor_status,
242          const gss_ctx_id_t context_handle,
243          gss_buffer_t input_message_buffer);
244
245 typedef struct gss_iov_buffer_desc_struct {
246     OM_uint32 type;
247     gss_buffer_desc buffer;
248 } gss_iov_buffer_desc, *gss_iov_buffer_t;
249
250 #define GSS_C_NO_IOV_BUFFER                 ((gss_iov_buffer_t)0)
251
252 #define GSS_IOV_BUFFER_TYPE_EMPTY           0
253 #define GSS_IOV_BUFFER_TYPE_DATA            1   /* Packet data */
254 #define GSS_IOV_BUFFER_TYPE_HEADER          2   /* Mechanism header */
255 #define GSS_IOV_BUFFER_TYPE_MECH_PARAMS     3   /* Mechanism specific parameters */
256 #define GSS_IOV_BUFFER_TYPE_TRAILER         7   /* Mechanism trailer */
257 #define GSS_IOV_BUFFER_TYPE_PADDING         9   /* Padding */
258 #define GSS_IOV_BUFFER_TYPE_STREAM          10  /* Complete wrap token */
259 #define GSS_IOV_BUFFER_TYPE_SIGN_ONLY       11  /* Sign only packet data */
260 #define GSS_IOV_BUFFER_TYPE_MIC_TOKEN       12  /* MIC token destination */
261
262 #define GSS_IOV_BUFFER_FLAG_MASK            0xFFFF0000
263 #define GSS_IOV_BUFFER_FLAG_ALLOCATE        0x00010000  /* indicates GSS should allocate */
264 #define GSS_IOV_BUFFER_FLAG_ALLOCATED       0x00020000  /* indicates caller should free */
265
266 #define GSS_IOV_BUFFER_TYPE(_type)          ((_type) & ~(GSS_IOV_BUFFER_FLAG_MASK))
267 #define GSS_IOV_BUFFER_FLAGS(_type)         ((_type) & GSS_IOV_BUFFER_FLAG_MASK)
268
269 /*
270  * Sign and optionally encrypt a sequence of buffers. The buffers
271  * shall be ordered HEADER | DATA | PADDING | TRAILER. Suitable
272  * space for the header, padding and trailer should be provided
273  * by calling gss_wrap_iov_length(), or the ALLOCATE flag should
274  * be set on those buffers.
275  *
276  * Encryption is in-place. SIGN_ONLY buffers are untouched. Only
277  * a single PADDING buffer should be provided. The order of the
278  * buffers in memory does not matter. Buffers in the IOV should
279  * be arranged in the order above, and in the case of multiple
280  * DATA buffers the sender and receiver should agree on the
281  * order.
282  *
283  * With GSS_C_DCE_STYLE it is acceptable to not provide PADDING
284  * and TRAILER, but the caller must guarantee the plaintext data
285  * being encrypted is correctly padded, otherwise an error will
286  * be returned.
287  *
288  * While applications that have knowledge of the underlying
289  * cryptosystem may request a specific configuration of data
290  * buffers, the only generally supported configurations are:
291  *
292  *  HEADER | DATA | PADDING | TRAILER
293  *
294  * which will emit GSS_Wrap() compatible tokens, and:
295  *
296  *  HEADER | SIGN_ONLY | DATA | PADDING | TRAILER
297  *
298  * for AEAD.
299  *
300  * The typical (special cased) usage for DCE is as follows:
301  *
302  *  SIGN_ONLY_1 | DATA | SIGN_ONLY_2 | HEADER
303  */
304 OM_uint32 KRB5_CALLCONV gss_wrap_iov
305 (
306     OM_uint32 *,        /* minor_status */
307     gss_ctx_id_t,       /* context_handle */
308     int,                /* conf_req_flag */
309     gss_qop_t,          /* qop_req */
310     int *,              /* conf_state */
311     gss_iov_buffer_desc *,    /* iov */
312     int);               /* iov_count */
313
314 /*
315  * Verify and optionally decrypt a sequence of buffers. To process
316  * a GSS-API message without separate buffer, pass STREAM | DATA.
317  * Upon return DATA will contain the decrypted or integrity
318  * protected message. Only a single DATA buffer may be provided
319  * with this usage. DATA by default will point into STREAM, but if
320  * the ALLOCATE flag is set a copy will be returned.
321  *
322  * Otherwise, decryption is in-place. SIGN_ONLY buffers are
323  * untouched.
324  */
325 OM_uint32 KRB5_CALLCONV gss_unwrap_iov
326 (
327     OM_uint32 *,        /* minor_status */
328     gss_ctx_id_t,       /* context_handle */
329     int *,              /* conf_state */
330     gss_qop_t *,        /* qop_state */
331     gss_iov_buffer_desc *,    /* iov */
332     int);               /* iov_count */
333
334 /*
335  * Query HEADER, PADDING and TRAILER buffer lengths. DATA buffers
336  * should be provided so the correct padding length can be determined.
337  */
338 OM_uint32 KRB5_CALLCONV gss_wrap_iov_length
339 (
340     OM_uint32 *,        /* minor_status */
341     gss_ctx_id_t,       /* context_handle */
342     int,                /* conf_req_flag */
343     gss_qop_t,          /* qop_req */
344     int *,              /* conf_state */
345     gss_iov_buffer_desc *, /* iov */
346     int);               /* iov_count */
347
348 /*
349  * Produce a GSSAPI MIC token for a sequence of buffers.  All SIGN_ONLY and
350  * DATA buffers will be signed, in the order they appear.  One MIC_TOKEN buffer
351  * must be included for the result.  Suitable space should be provided for the
352  * MIC_TOKEN buffer by calling gss_get_mic_iov_length, or the ALLOCATE flag
353  * should be set on that buffer.  If the ALLOCATE flag is used, use
354  * gss_release_iov_buffer to free the allocated buffer within the iov list when
355  * it is no longer needed.
356  */
357 OM_uint32 KRB5_CALLCONV gss_get_mic_iov
358 (
359     OM_uint32 *,        /* minor_status */
360     gss_ctx_id_t,       /* context_handle */
361     gss_qop_t,          /* qop_req */
362     gss_iov_buffer_desc *, /* iov */
363     int);               /* iov_count */
364
365 /*
366  * Query the MIC_TOKEN buffer length within the iov list.
367  */
368 OM_uint32 KRB5_CALLCONV gss_get_mic_iov_length(
369     OM_uint32 *,        /* minor_status */
370     gss_ctx_id_t,       /* context_handle */
371     gss_qop_t,          /* qop_req */
372     gss_iov_buffer_desc *, /* iov */
373     int);               /* iov_count */
374
375 /*
376  * Verify the MIC_TOKEN buffer within the iov list against the SIGN_ONLY and
377  * DATA buffers in the order they appear.  Return values are the same as for
378  * gss_verify_mic.
379  */
380 OM_uint32 KRB5_CALLCONV gss_verify_mic_iov
381 (
382     OM_uint32 *,        /* minor_status */
383     gss_ctx_id_t,       /* context_handle */
384     gss_qop_t *,        /* qop_state */
385     gss_iov_buffer_desc *, /* iov */
386     int);               /* iov_count */
387
388 /*
389  * Release buffers that have the ALLOCATED flag set.
390  */
391 OM_uint32 KRB5_CALLCONV gss_release_iov_buffer
392 (
393     OM_uint32 *,        /* minor_status */
394     gss_iov_buffer_desc *, /* iov */
395     int);               /* iov_count */
396
397 /*
398  * Protocol transition
399  */
400 OM_uint32 KRB5_CALLCONV
401 gss_acquire_cred_impersonate_name(
402     OM_uint32 *,            /* minor_status */
403     const gss_cred_id_t,    /* impersonator_cred_handle */
404     const gss_name_t,       /* desired_name */
405     OM_uint32,              /* time_req */
406     const gss_OID_set,      /* desired_mechs */
407     gss_cred_usage_t,       /* cred_usage */
408     gss_cred_id_t *,        /* output_cred_handle */
409     gss_OID_set *,          /* actual_mechs */
410     OM_uint32 *);           /* time_rec */
411
412 OM_uint32 KRB5_CALLCONV
413 gss_add_cred_impersonate_name(
414     OM_uint32 *,            /* minor_status */
415     gss_cred_id_t,          /* input_cred_handle */
416     const gss_cred_id_t,    /* impersonator_cred_handle */
417     const gss_name_t,       /* desired_name */
418     const gss_OID,          /* desired_mech */
419     gss_cred_usage_t,       /* cred_usage */
420     OM_uint32,              /* initiator_time_req */
421     OM_uint32,              /* acceptor_time_req */
422     gss_cred_id_t *,        /* output_cred_handle */
423     gss_OID_set *,          /* actual_mechs */
424     OM_uint32 *,            /* initiator_time_rec */
425     OM_uint32 *);           /* acceptor_time_rec */
426
427 /*
428  * Naming extensions
429  */
430 GSS_DLLIMP extern gss_buffer_t GSS_C_ATTR_LOCAL_LOGIN_USER;
431 GSS_DLLIMP extern gss_OID GSS_C_NT_COMPOSITE_EXPORT;
432
433 OM_uint32 KRB5_CALLCONV gss_display_name_ext
434 (
435     OM_uint32 *,        /* minor_status */
436     gss_name_t,         /* name */
437     gss_OID,            /* display_as_name_type */
438     gss_buffer_t        /* display_name */
439 );
440
441 OM_uint32 KRB5_CALLCONV gss_inquire_name
442 (
443     OM_uint32 *,        /* minor_status */
444     gss_name_t,         /* name */
445     int *,              /* name_is_MN */
446     gss_OID *,          /* MN_mech */
447     gss_buffer_set_t *  /* attrs */
448 );
449
450 OM_uint32 KRB5_CALLCONV gss_get_name_attribute
451 (
452     OM_uint32 *,        /* minor_status */
453     gss_name_t,         /* name */
454     gss_buffer_t,       /* attr */
455     int *,              /* authenticated */
456     int *,              /* complete */
457     gss_buffer_t,       /* value */
458     gss_buffer_t,       /* display_value */
459     int *               /* more */
460 );
461
462 OM_uint32 KRB5_CALLCONV gss_set_name_attribute
463 (
464     OM_uint32 *,        /* minor_status */
465     gss_name_t,         /* name */
466     int,                /* complete */
467     gss_buffer_t,       /* attr */
468     gss_buffer_t        /* value */
469 );
470
471 OM_uint32 KRB5_CALLCONV gss_delete_name_attribute
472 (
473     OM_uint32 *,        /* minor_status */
474     gss_name_t,         /* name */
475     gss_buffer_t        /* attr */
476 );
477
478 OM_uint32 KRB5_CALLCONV gss_export_name_composite
479 (
480     OM_uint32 *,        /* minor_status */
481     gss_name_t,         /* name */
482     gss_buffer_t        /* exp_composite_name */
483 );
484
485 typedef struct gss_any *gss_any_t;
486
487 OM_uint32 KRB5_CALLCONV gss_map_name_to_any
488 (
489     OM_uint32 *,        /* minor_status */
490     gss_name_t,         /* name */
491     int,                /* authenticated */
492     gss_buffer_t,       /* type_id */
493     gss_any_t *         /* output */
494 );
495
496 OM_uint32 KRB5_CALLCONV gss_release_any_name_mapping
497 (
498     OM_uint32 *,        /* minor_status */
499     gss_name_t,         /* name */
500     gss_buffer_t,       /* type_id */
501     gss_any_t *         /* input */
502 );
503
504 /* draft-josefsson-gss-capsulate */
505 OM_uint32 KRB5_CALLCONV gss_encapsulate_token
506 (
507     gss_const_buffer_t, /* input_token */
508     gss_const_OID,      /* token_oid */
509     gss_buffer_t        /* output_token */
510 );
511
512 OM_uint32 KRB5_CALLCONV gss_decapsulate_token
513 (
514     gss_const_buffer_t, /* input_token */
515     gss_const_OID,      /* token_oid */
516     gss_buffer_t        /* output_token */
517 );
518
519 int KRB5_CALLCONV gss_oid_equal
520 (
521     gss_const_OID,      /* first_oid */
522     gss_const_OID       /* second_oid */
523 );
524
525 /* Credential store extensions */
526
527 struct gss_key_value_element_struct {
528     const char *key;
529     const char *value;
530 };
531 typedef struct gss_key_value_element_struct gss_key_value_element_desc;
532
533 struct gss_key_value_set_struct {
534     OM_uint32 count;
535     gss_key_value_element_desc *elements;
536 };
537 typedef struct gss_key_value_set_struct gss_key_value_set_desc;
538 typedef const gss_key_value_set_desc *gss_const_key_value_set_t;
539
540 #define GSS_C_NO_CRED_STORE ((gss_const_key_value_set_t) 0)
541
542 OM_uint32 KRB5_CALLCONV
543 gss_acquire_cred_from(
544     OM_uint32 *,               /* minor_status */
545     gss_name_t,                /* desired_name */
546     OM_uint32,                 /* time_req */
547     gss_OID_set,               /* desired_mechs */
548     gss_cred_usage_t,          /* cred_usage */
549     gss_const_key_value_set_t, /* cred_store */
550     gss_cred_id_t *,           /* output_cred_handle */
551     gss_OID_set *,             /* actual_mechs */
552     OM_uint32 *);              /* time_rec */
553
554 OM_uint32 KRB5_CALLCONV
555 gss_add_cred_from(
556     OM_uint32 *,               /* minor_status */
557     gss_cred_id_t,             /* input_cred_handle */
558     gss_name_t,                /* desired_name */
559     gss_OID,                   /* desired_mech */
560     gss_cred_usage_t,          /* cred_usage */
561     OM_uint32,                 /* initiator_time_req */
562     OM_uint32,                 /* acceptor_time_req */
563     gss_const_key_value_set_t, /* cred_store */
564     gss_cred_id_t *,           /* output_cred_handle */
565     gss_OID_set *,             /* actual_mechs */
566     OM_uint32 *,               /* initiator_time_rec */
567     OM_uint32 *);              /* acceptor_time_rec */
568
569 OM_uint32 KRB5_CALLCONV
570 gss_store_cred_into(
571     OM_uint32 *,               /* minor_status */
572     gss_cred_id_t,             /* input_cred_handle */
573     gss_cred_usage_t,          /* input_usage */
574     gss_OID,                   /* desired_mech */
575     OM_uint32,                 /* overwrite_cred */
576     OM_uint32,                 /* default_cred */
577     gss_const_key_value_set_t, /* cred_store */
578     gss_OID_set *,             /* elements_stored */
579     gss_cred_usage_t *);       /* cred_usage_stored */
580
581 #ifdef __cplusplus
582 }
583 #endif
584
585 /*
586  * When used with gss_inquire_sec_context_by_oid(), return a buffer set with
587  * the first member containing an unsigned 32-bit integer in network byte
588  * order.  This is the Security Strength Factor (SSF) associated with the
589  * secure channel established by the security context.  NOTE: This value is
590  * made available solely as an indication for use by APIs like Cyrus SASL that
591  * classify the strength of a secure channel via this number.  The strength of
592  * a channel cannot necessarily be represented by a simple number.
593  */
594 GSS_DLLIMP extern gss_OID GSS_C_SEC_CONTEXT_SASL_SSF;
595
596 #endif /* GSSAPI_EXT_H_ */