HEIMDAL: move code from source4/heimdal* to third_party/heimdal*
[samba.git] / third_party / heimdal / lib / gssapi / sanon / external.c
1 /*
2  * Copyright (c) 2006-2020 Kungliga Tekniska Högskolan
3  * (Royal Institute of Technology, Stockholm, Sweden).
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * 3. Neither the name of the Institute nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #include "sanon_locl.h"
35
36 static uint8_t anonymous_identity;
37 gss_name_t
38 _gss_sanon_anonymous_identity = (gss_name_t)&anonymous_identity;
39 gss_cred_id_t
40 _gss_sanon_anonymous_cred = (gss_cred_id_t)&anonymous_identity;
41
42 static uint8_t non_anonymous_identity;
43 gss_name_t
44 _gss_sanon_non_anonymous_identity = (gss_name_t)&non_anonymous_identity;
45 gss_cred_id_t
46 _gss_sanon_non_anonymous_cred = (gss_cred_id_t)&non_anonymous_identity;
47
48 static gss_buffer_desc wellknown_user_name = {
49     SANON_WELLKNOWN_USER_NAME_LEN,
50     SANON_WELLKNOWN_USER_NAME
51 };
52 gss_buffer_t
53 _gss_sanon_wellknown_user_name = &wellknown_user_name;
54
55 static gss_buffer_desc wellknown_service_name = {
56     SANON_WELLKNOWN_SERVICE_NAME_LEN,
57     SANON_WELLKNOWN_SERVICE_NAME
58 };
59 gss_buffer_t
60 _gss_sanon_wellknown_service_name = &wellknown_service_name;
61
62 static gss_mo_desc sanon_mo[] = {
63     {
64         GSS_C_MA_MECH_NAME,
65         GSS_MO_MA,
66         "Mechanism name",
67         rk_UNCONST("SANON-X25519"),
68         _gss_mo_get_ctx_as_string,
69         NULL
70     },
71     {
72         GSS_C_MA_MECH_DESCRIPTION,
73         GSS_MO_MA,
74         "Mechanism description",
75         rk_UNCONST("Heimdal Simple Anonymous (X25519) Mechanism"),
76         _gss_mo_get_ctx_as_string,
77         NULL
78     },
79     {
80         GSS_C_MA_MECH_CONCRETE,
81         GSS_MO_MA,
82         NULL,
83         NULL,
84         NULL,
85         NULL
86     },
87     {
88         GSS_C_MA_ITOK_FRAMED,
89         GSS_MO_MA,
90         NULL,
91         NULL,
92         NULL,
93         NULL
94     },
95     {
96         GSS_C_MA_AUTH_INIT_ANON,
97         GSS_MO_MA,
98         NULL,
99         NULL,
100         NULL,
101         NULL
102     },
103     {
104         GSS_C_MA_AUTH_TARG_ANON,
105         GSS_MO_MA,
106         NULL,
107         NULL,
108         NULL,
109         NULL
110     },
111     {
112         GSS_C_MA_INTEG_PROT,
113         GSS_MO_MA,
114         NULL,
115         NULL,
116         NULL,
117         NULL
118     },
119     {
120         GSS_C_MA_CONF_PROT,
121         GSS_MO_MA,
122         NULL,
123         NULL,
124         NULL,
125         NULL
126     },
127     {
128         GSS_C_MA_MIC,
129         GSS_MO_MA,
130         NULL,
131         NULL,
132         NULL,
133         NULL
134     },
135     {
136         GSS_C_MA_WRAP,
137         GSS_MO_MA,
138         NULL,
139         NULL,
140         NULL,
141         NULL
142     },
143     {
144         GSS_C_MA_REPLAY_DET,
145         GSS_MO_MA,
146         NULL,
147         NULL,
148         NULL,
149         NULL
150     },
151     {
152         GSS_C_MA_OOS_DET,
153         GSS_MO_MA,
154         NULL,
155         NULL,
156         NULL,
157         NULL
158     },
159     {
160         GSS_C_MA_CBINDINGS,
161         GSS_MO_MA,
162         NULL,
163         NULL,
164         NULL,
165         NULL
166     },
167     {
168         GSS_C_MA_PFS,
169         GSS_MO_MA,
170         NULL,
171         NULL,
172         NULL,
173         NULL
174     },
175     {
176         GSS_C_MA_CTX_TRANS,
177         GSS_MO_MA,
178         NULL,
179         NULL,
180         NULL,
181         NULL
182     },
183     {
184         GSS_C_MA_NEGOEX_AND_SPNEGO,
185         GSS_MO_MA,
186         NULL,
187         NULL,
188         NULL,
189         NULL
190     }
191 };
192
193 static gssapi_mech_interface_desc sanon_mech = {
194     GMI_VERSION,
195     "sanon-x25519",
196     { 10, rk_UNCONST("\x2b\x06\x01\x04\x01\xa9\x4a\x1a\x01\x6e") },
197     0,
198     NULL,
199     _gss_sanon_release_cred,
200     _gss_sanon_init_sec_context,
201     _gss_sanon_accept_sec_context,
202     _gss_sanon_process_context_token,
203     _gss_sanon_delete_sec_context,
204     _gss_sanon_context_time,
205     _gss_sanon_get_mic,
206     _gss_sanon_verify_mic,
207     _gss_sanon_wrap,
208     _gss_sanon_unwrap,
209     _gss_sanon_display_status,
210     NULL, /* gm_indicate_mechs */
211     _gss_sanon_compare_name,
212     _gss_sanon_display_name,
213     _gss_sanon_import_name,
214     _gss_sanon_export_name,
215     _gss_sanon_release_name,
216     _gss_sanon_inquire_cred,
217     _gss_sanon_inquire_context,
218     _gss_sanon_wrap_size_limit,
219     NULL, /* gm_add_cred */
220     _gss_sanon_inquire_cred_by_mech,
221     _gss_sanon_export_sec_context,
222     _gss_sanon_import_sec_context,
223     _gss_sanon_inquire_names_for_mech,
224     _gss_sanon_inquire_mechs_for_name,
225     _gss_sanon_canonicalize_name,
226     _gss_sanon_duplicate_name,
227     _gss_sanon_inquire_sec_context_by_oid,
228     NULL, /* gm_inquire_cred_by_oid */
229     NULL, /* gm_set_sec_context_option */
230     NULL, /* gm_set_cred_option */
231     _gss_sanon_pseudo_random,
232     _gss_sanon_wrap_iov,
233     _gss_sanon_unwrap_iov,
234     _gss_sanon_wrap_iov_length,
235     NULL, /* gm_store_cred */
236     _gss_sanon_export_cred,
237     _gss_sanon_import_cred,
238     _gss_sanon_acquire_cred_from,
239     NULL, /* gm_acquire_cred_impersonate_name */
240     NULL,
241     NULL,
242     NULL,
243     NULL,
244     NULL,
245     NULL,
246     sanon_mo,
247     sizeof(sanon_mo) / sizeof(sanon_mo[0]),
248     NULL, /* gm_localname */
249     NULL, /* gm_authorize_localname */
250     NULL, /* gm_display_name_ext */
251     NULL, /* gm_inquire_name */
252     NULL, /* gm_get_name_attribute */
253     NULL, /* gm_set_name_attribute */
254     NULL, /* gm_delete_name_attribute */
255     NULL, /* gm_export_name_composite */
256     _gss_sanon_duplicate_cred,
257     _gss_sanon_add_cred_from,
258     NULL, /* gm_store_cred_into */
259     _gssspi_sanon_query_mechanism_info,
260     _gssspi_sanon_query_meta_data,
261     _gssspi_sanon_exchange_meta_data,
262     NULL, /* gm_store_cred_into2 */
263     NULL, /* gm_compat */
264 };
265
266 gssapi_mech_interface
267 __gss_sanon_initialize(void)
268 {
269     return &sanon_mech;
270 }