34 #include "gss-extra.h"
45 struct gss_channel_bindings_struct
cb;
70 state->
context = GSS_C_NO_CONTEXT;
71 state->
token.length = 0;
72 state->
token.value = NULL;
77 state->
cb.initiator_addrtype = 0;
78 state->
cb.initiator_address.length = 0;
79 state->
cb.initiator_address.value = NULL;
80 state->
cb.acceptor_addrtype = 0;
81 state->
cb.acceptor_address.length = 0;
82 state->
cb.acceptor_address.value = NULL;
83 state->
cb.application_data.length = 0;
84 state->
cb.application_data.value = NULL;
95 escape_authzid (
const char *str)
97 char *out = malloc (strlen (str) * 3 + 1);
107 memcpy (p,
"=2C", 3);
110 else if (*str ==
'=')
112 memcpy (p,
"=3D", 3);
136 gss_buffer_desc bufdesc;
137 OM_uint32 maj_stat, min_stat;
144 bufdesc.length = asprintf ((
char **) &bufdesc.value,
"%s@%s",
146 if (bufdesc.length <= 0 || bufdesc.value == NULL)
149 maj_stat = gss_import_name (&min_stat, &bufdesc,
150 GSS_C_NT_HOSTBASED_SERVICE, &state->
service);
151 free (bufdesc.value);
152 if (GSS_ERROR (maj_stat))
157 char *escaped_authzid = escape_authzid (authzid);
159 if (!escaped_authzid)
162 state->
cb.application_data.length
163 = asprintf ((
char **) &state->
cb.application_data.value,
164 "n,a=%s,", escaped_authzid);
166 free (escaped_authzid);
170 state->
cb.application_data.value = strdup (
"n,,");
171 state->
cb.application_data.length = 3;
174 if (state->
cb.application_data.length <= 0
175 || state->
cb.application_data.value == NULL)
187 const gss_buffer_t
token,
char **output,
size_t *output_len)
189 OM_uint32 maj_stat, min_stat;
190 gss_buffer_desc bufdesc;
192 if (state->
step == 1)
196 maj_stat = gss_decapsulate_token (
token, state->
mech_oid, &bufdesc);
197 if (GSS_ERROR (maj_stat))
200 *output_len = state->
cb.application_data.length + bufdesc.length;
201 *output = malloc (*output_len);
204 gss_release_buffer (&min_stat, &bufdesc);
208 memcpy (*output, state->
cb.application_data.value,
209 state->
cb.application_data.length);
210 memcpy (*output + state->
cb.application_data.length,
211 bufdesc.value, bufdesc.length);
213 maj_stat = gss_release_buffer (&min_stat, &bufdesc);
214 if (GSS_ERROR (maj_stat))
219 *output_len =
token->length;
220 *output = malloc (*output_len);
224 memcpy (*output,
token->value,
token->length);
237 const char *input,
size_t input_len,
238 char **output,
size_t *output_len)
241 gss_buffer_desc bufdesc;
242 gss_buffer_t buf = GSS_C_NO_BUFFER;
243 OM_uint32 maj_stat, min_stat, ret_flags;
244 gss_OID actual_mech_type;
250 if (state->
step == 0)
252 res = prepare (sctx, state);
258 if (state->
step == 2)
260 bufdesc.length = input_len;
261 bufdesc.value = (
void *) input;
266 if (state->
token.value != NULL)
268 maj_stat = gss_release_buffer (&min_stat, &state->
token);
269 if (GSS_ERROR (maj_stat))
272 state->
token.value = NULL;
273 state->
token.length = 0;
276 maj_stat = gss_init_sec_context (&min_stat,
286 &state->
token, &ret_flags, NULL);
287 if (maj_stat != GSS_S_COMPLETE && maj_stat != GSS_S_CONTINUE_NEEDED)
290 if (state->
token.length > 0 && state->
token.value == NULL)
293 res = token2output (state, &state->
token, output, output_len);
297 if (maj_stat == GSS_S_CONTINUE_NEEDED)
303 if (!(ret_flags & GSS_C_MUTUAL_FLAG))
306 if (!gss_oid_equal (state->
mech_oid, actual_mech_type))
325 if (state->
token.value != NULL)
326 gss_release_buffer (&min_stat, &state->
token);
327 if (state->
service != GSS_C_NO_NAME)
328 gss_release_name (&min_stat, &state->
service);
329 if (state->
context != GSS_C_NO_CONTEXT)
330 gss_delete_sec_context (&min_stat, &state->
context, GSS_C_NO_BUFFER);
332 free (state->
cb.application_data.value);
void _gsasl_gs2_client_finish(Gsasl_session *sctx, void *mech_data)
int _gsasl_gs2_client_step(Gsasl_session *sctx, void *mech_data, const char *input, size_t input_len, char **output, size_t *output_len)
int _gsasl_gs2_client_start(Gsasl_session *sctx, void **mech_data)
int gs2_get_oid(Gsasl_session *sctx, gss_OID *mech_oid)
@ GSASL_GSSAPI_IMPORT_NAME_ERROR
@ GSASL_GSSAPI_RELEASE_BUFFER_ERROR
@ GSASL_AUTHENTICATION_ERROR
@ GSASL_GSSAPI_ENCAPSULATE_TOKEN_ERROR
@ GSASL_MECHANISM_CALLED_TOO_MANY_TIMES
@ GSASL_GSSAPI_INIT_SEC_CONTEXT_ERROR
_GSASL_API const char * gsasl_property_get(Gsasl_session *sctx, Gsasl_property prop)
struct gss_channel_bindings_struct cb