xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/dns/include/dst/gssapi.h (revision 4afad4b7fa6d4a0d3dedf41d1587a7250710ae54)
1*4afad4b7Schristos /*	$NetBSD: gssapi.h,v 1.1 2024/02/18 20:57:39 christos Exp $	*/
2*4afad4b7Schristos 
3*4afad4b7Schristos /*
4*4afad4b7Schristos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5*4afad4b7Schristos  *
6*4afad4b7Schristos  * SPDX-License-Identifier: MPL-2.0
7*4afad4b7Schristos  *
8*4afad4b7Schristos  * This Source Code Form is subject to the terms of the Mozilla Public
9*4afad4b7Schristos  * License, v. 2.0. If a copy of the MPL was not distributed with this
10*4afad4b7Schristos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11*4afad4b7Schristos  *
12*4afad4b7Schristos  * See the COPYRIGHT file distributed with this work for additional
13*4afad4b7Schristos  * information regarding copyright ownership.
14*4afad4b7Schristos  */
15*4afad4b7Schristos 
16*4afad4b7Schristos #ifndef DST_GSSAPI_H
17*4afad4b7Schristos #define DST_GSSAPI_H 1
18*4afad4b7Schristos 
19*4afad4b7Schristos /*! \file dst/gssapi.h */
20*4afad4b7Schristos 
21*4afad4b7Schristos #include <inttypes.h>
22*4afad4b7Schristos #include <stdbool.h>
23*4afad4b7Schristos 
24*4afad4b7Schristos #include <isc/formatcheck.h>
25*4afad4b7Schristos #include <isc/lang.h>
26*4afad4b7Schristos #include <isc/platform.h>
27*4afad4b7Schristos #include <isc/types.h>
28*4afad4b7Schristos 
29*4afad4b7Schristos #include <dns/types.h>
30*4afad4b7Schristos 
31*4afad4b7Schristos typedef void *dns_gss_cred_id_t;
32*4afad4b7Schristos typedef void *dns_gss_ctx_id_t;
33*4afad4b7Schristos 
34*4afad4b7Schristos ISC_LANG_BEGINDECLS
35*4afad4b7Schristos 
36*4afad4b7Schristos /***
37*4afad4b7Schristos  *** Types
38*4afad4b7Schristos  ***/
39*4afad4b7Schristos 
40*4afad4b7Schristos /***
41*4afad4b7Schristos  *** Functions
42*4afad4b7Schristos  ***/
43*4afad4b7Schristos 
44*4afad4b7Schristos isc_result_t
45*4afad4b7Schristos dst_gssapi_acquirecred(const dns_name_t *name, bool initiate,
46*4afad4b7Schristos 		       dns_gss_cred_id_t *cred);
47*4afad4b7Schristos /*
48*4afad4b7Schristos  *	Acquires GSS credentials.
49*4afad4b7Schristos  *
50*4afad4b7Schristos  *	Requires:
51*4afad4b7Schristos  * 	'name' 	    is a valid name, preferably one known by the GSS provider
52*4afad4b7Schristos  * 	'initiate'  indicates whether the credentials are for initiating or
53*4afad4b7Schristos  *		    accepting contexts
54*4afad4b7Schristos  *      'cred'      is a pointer to NULL, which will be allocated with the
55*4afad4b7Schristos  *		    credential handle.  Call dst_gssapi_releasecred to free
56*4afad4b7Schristos  *		    the memory.
57*4afad4b7Schristos  *
58*4afad4b7Schristos  *	Returns:
59*4afad4b7Schristos  *		ISC_R_SUCCESS msg was successfully updated to include the
60*4afad4b7Schristos  *				      query to be sent
61*4afad4b7Schristos  *		other		  an error occurred while building the message
62*4afad4b7Schristos  */
63*4afad4b7Schristos 
64*4afad4b7Schristos isc_result_t
65*4afad4b7Schristos dst_gssapi_releasecred(dns_gss_cred_id_t *cred);
66*4afad4b7Schristos /*
67*4afad4b7Schristos  *	Releases GSS credentials.  Calling this function does release the
68*4afad4b7Schristos  *  memory allocated for the credential in dst_gssapi_acquirecred()
69*4afad4b7Schristos  *
70*4afad4b7Schristos  *	Requires:
71*4afad4b7Schristos  *      'mctx'  is a valid memory context
72*4afad4b7Schristos  *      'cred'  is a pointer to the credential to be released
73*4afad4b7Schristos  *
74*4afad4b7Schristos  *	Returns:
75*4afad4b7Schristos  *		ISC_R_SUCCESS 	credential was released successfully
76*4afad4b7Schristos  *		other		an error occurred while releaseing
77*4afad4b7Schristos  *				the credential
78*4afad4b7Schristos  */
79*4afad4b7Schristos 
80*4afad4b7Schristos isc_result_t
81*4afad4b7Schristos dst_gssapi_initctx(const dns_name_t *name, isc_buffer_t *intoken,
82*4afad4b7Schristos 		   isc_buffer_t *outtoken, dns_gss_ctx_id_t *gssctx,
83*4afad4b7Schristos 		   isc_mem_t *mctx, char **err_message);
84*4afad4b7Schristos /*
85*4afad4b7Schristos  *	Initiates a GSS context.
86*4afad4b7Schristos  *
87*4afad4b7Schristos  *	Requires:
88*4afad4b7Schristos  * 	'name'     is a valid name, preferably one known by the GSS
89*4afad4b7Schristos  * 	provider
90*4afad4b7Schristos  * 	'intoken'  is a token received from the acceptor, or NULL if
91*4afad4b7Schristos  *		   there isn't one
92*4afad4b7Schristos  * 	'outtoken' is a buffer to receive the token generated by
93*4afad4b7Schristos  *		   gss_init_sec_context() to be sent to the acceptor
94*4afad4b7Schristos  *      'context'  is a pointer to a valid dns_gss_ctx_id_t
95*4afad4b7Schristos  *                 (which may have the value GSS_C_NO_CONTEXT)
96*4afad4b7Schristos  *
97*4afad4b7Schristos  *	Returns:
98*4afad4b7Schristos  *		ISC_R_SUCCESS   msg was successfully updated to include the
99*4afad4b7Schristos  * 				query to be sent
100*4afad4b7Schristos  *		other		an error occurred while building the message
101*4afad4b7Schristos  *		*err_message	optional error message
102*4afad4b7Schristos  */
103*4afad4b7Schristos 
104*4afad4b7Schristos isc_result_t
105*4afad4b7Schristos dst_gssapi_acceptctx(dns_gss_cred_id_t cred, const char *gssapi_keytab,
106*4afad4b7Schristos 		     isc_region_t *intoken, isc_buffer_t **outtoken,
107*4afad4b7Schristos 		     dns_gss_ctx_id_t *context, dns_name_t *principal,
108*4afad4b7Schristos 		     isc_mem_t *mctx);
109*4afad4b7Schristos /*
110*4afad4b7Schristos  *	Accepts a GSS context.
111*4afad4b7Schristos  *
112*4afad4b7Schristos  *	Requires:
113*4afad4b7Schristos  * 	'mctx'     is a valid memory context
114*4afad4b7Schristos  *      'cred'     is the acceptor's valid GSS credential handle
115*4afad4b7Schristos  * 	'intoken'  is a token received from the initiator
116*4afad4b7Schristos  * 	'outtoken' is a pointer a buffer pointer used to return the token
117*4afad4b7Schristos  *		   generated by gss_accept_sec_context() to be sent to the
118*4afad4b7Schristos  *		   initiator
119*4afad4b7Schristos  *      'context'  is a valid pointer to receive the generated context handle.
120*4afad4b7Schristos  *                 On the initial call, it should be a pointer to NULL, which
121*4afad4b7Schristos  *		   will be allocated as a dns_gss_ctx_id_t.  Subsequent calls
122*4afad4b7Schristos  *		   should pass in the handle generated on the first call.
123*4afad4b7Schristos  *		   Call dst_gssapi_releasecred to delete the context and free
124*4afad4b7Schristos  *		   the memory.
125*4afad4b7Schristos  *
126*4afad4b7Schristos  *	Requires:
127*4afad4b7Schristos  *		'outtoken' to != NULL && *outtoken == NULL.
128*4afad4b7Schristos  *
129*4afad4b7Schristos  *	Returns:
130*4afad4b7Schristos  *		ISC_R_SUCCESS   msg was successfully updated to include the
131*4afad4b7Schristos  * 				query to be sent
132*4afad4b7Schristos  *		DNS_R_CONTINUE	transaction still in progress
133*4afad4b7Schristos  *		other 		an error occurred while building the message
134*4afad4b7Schristos  */
135*4afad4b7Schristos 
136*4afad4b7Schristos isc_result_t
137*4afad4b7Schristos dst_gssapi_deletectx(isc_mem_t *mctx, dns_gss_ctx_id_t *gssctx);
138*4afad4b7Schristos /*
139*4afad4b7Schristos  *	Destroys a GSS context.  This function deletes the context from the GSS
140*4afad4b7Schristos  *  	provider and then frees the memory used by the context pointer.
141*4afad4b7Schristos  *
142*4afad4b7Schristos  *	Requires:
143*4afad4b7Schristos  *      'mctx'    is a valid memory context
144*4afad4b7Schristos  *	'context' is a valid GSS context
145*4afad4b7Schristos  *
146*4afad4b7Schristos  *	Returns:
147*4afad4b7Schristos  *		ISC_R_SUCCESS
148*4afad4b7Schristos  */
149*4afad4b7Schristos 
150*4afad4b7Schristos void
151*4afad4b7Schristos gss_log(int level, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3);
152*4afad4b7Schristos /*
153*4afad4b7Schristos  * Logging function for GSS.
154*4afad4b7Schristos  *
155*4afad4b7Schristos  *  Requires
156*4afad4b7Schristos  *      'level' is the log level to be used, as an integer
157*4afad4b7Schristos  *      'fmt'   is a printf format specifier
158*4afad4b7Schristos  */
159*4afad4b7Schristos 
160*4afad4b7Schristos char *
161*4afad4b7Schristos gss_error_tostring(uint32_t major, uint32_t minor, char *buf, size_t buflen);
162*4afad4b7Schristos /*
163*4afad4b7Schristos  *	Render a GSS major status/minor status pair into a string
164*4afad4b7Schristos  *
165*4afad4b7Schristos  *	Requires:
166*4afad4b7Schristos  *      'major' is a GSS major status code
167*4afad4b7Schristos  * 	'minor' is a GSS minor status code
168*4afad4b7Schristos  *
169*4afad4b7Schristos  *	Returns:
170*4afad4b7Schristos  *		A string containing the text representation of the error codes.
171*4afad4b7Schristos  *      	Users should copy the string if they wish to keep it.
172*4afad4b7Schristos  */
173*4afad4b7Schristos 
174*4afad4b7Schristos bool
175*4afad4b7Schristos dst_gssapi_identitymatchesrealmkrb5(const dns_name_t *signer,
176*4afad4b7Schristos 				    const dns_name_t *name,
177*4afad4b7Schristos 				    const dns_name_t *realm, bool subdomain);
178*4afad4b7Schristos /*
179*4afad4b7Schristos  *	Compare a "signer" (in the format of a Kerberos-format Kerberos5
180*4afad4b7Schristos  *	principal: host/example.com@EXAMPLE.COM) to the realm name stored
181*4afad4b7Schristos  *	in "name" (which represents the realm name).
182*4afad4b7Schristos  *
183*4afad4b7Schristos  */
184*4afad4b7Schristos 
185*4afad4b7Schristos bool
186*4afad4b7Schristos dst_gssapi_identitymatchesrealmms(const dns_name_t *signer,
187*4afad4b7Schristos 				  const dns_name_t *name,
188*4afad4b7Schristos 				  const dns_name_t *realm, bool subdomain);
189*4afad4b7Schristos /*
190*4afad4b7Schristos  *	Compare a "signer" (in the format of a Kerberos-format Kerberos5
191*4afad4b7Schristos  *	principal: host/example.com@EXAMPLE.COM) to the realm name stored
192*4afad4b7Schristos  *	in "name" (which represents the realm name).
193*4afad4b7Schristos  *
194*4afad4b7Schristos  */
195*4afad4b7Schristos 
196*4afad4b7Schristos ISC_LANG_ENDDECLS
197*4afad4b7Schristos 
198*4afad4b7Schristos #endif /* DST_GSSAPI_H */
199