27 #define GSS_C_NT_HOSTBASED_SERVICE gss_nt_service_name
30 #ifndef CURL_DISABLE_HTTP
45 #define _MPRINTF_REPLACE
54 get_gss_name(
struct connectdata *conn, gss_name_t *server)
56 struct negotiatedata *neg_ctx = &conn->
data->
state.negotiate;
57 OM_uint32 major_status, minor_status;
58 gss_buffer_desc token = GSS_C_EMPTY_BUFFER;
74 token.length = strlen(service) + 1 + strlen(conn->
hostname) + 1;
75 if (token.length + 1 >
sizeof(name))
79 token.value = (
void *) name;
80 major_status = gss_import_name(&minor_status,
82 GSS_C_NT_HOSTBASED_SERVICE,
85 return GSS_ERROR(major_status) ? -1 : 0;
89 log_gss_error(
struct connectdata *conn, OM_uint32 error_status,
char *prefix)
91 OM_uint32 maj_stat, min_stat;
92 OM_uint32 msg_ctx = 0;
93 gss_buffer_desc status_string;
97 snprintf(buf,
sizeof(buf),
"%s", prefix);
100 maj_stat = gss_display_status (&min_stat,
106 if (
sizeof(buf) > len + status_string.length + 1) {
107 sprintf(buf + len,
": %s", (
char*) status_string.value);
108 len += status_string.length;
110 gss_release_buffer(&min_stat, &status_string);
111 }
while (!GSS_ERROR(maj_stat) && msg_ctx != 0);
116 int Curl_input_negotiate(
struct connectdata *conn,
char *header)
118 struct negotiatedata *neg_ctx = &conn->
data->
state.negotiate;
119 OM_uint32 major_status, minor_status, minor_status2;
120 gss_buffer_desc input_token = GSS_C_EMPTY_BUFFER;
121 gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER;
125 const char* protocol;
127 while(*header && isspace((
int)*header))
130 protocol =
"GSS-Negotiate";
134 protocol =
"Negotiate";
140 if (neg_ctx->context) {
141 if (neg_ctx->gss != gss) {
146 neg_ctx->protocol = protocol;
150 if (neg_ctx->context && neg_ctx->status == GSS_S_COMPLETE) {
154 Curl_cleanup_negotiate(conn->
data);
158 if (neg_ctx->server_name ==
NULL &&
159 (ret = get_gss_name(conn, &neg_ctx->server_name)))
162 header += strlen(neg_ctx->protocol);
163 while(*header && isspace((
int)*header))
166 len = strlen(header);
169 input_token.length = (len+3)/4 * 3;
170 input_token.value = malloc(input_token.length);
171 if (input_token.value ==
NULL)
176 input_token.length = rawlen;
180 ASN1_OBJECT *
object =
NULL;
182 unsigned char * spnegoToken =
NULL;
183 size_t spnegoTokenLength = 0;
184 unsigned char * mechToken =
NULL;
185 size_t mechTokenLength = 0;
187 spnegoToken = malloc(input_token.length);
188 if (input_token.value ==
NULL)
190 spnegoTokenLength = input_token.length;
192 object = OBJ_txt2obj (
"1.2.840.113554.1.2.2", 1);
193 if (!parseSpnegoTargetToken(spnegoToken,
203 infof(conn->
data,
"Parse SPNEGO Target Token failed\n");
206 free(input_token.value);
207 input_token.value =
NULL;
208 input_token.value = malloc(mechTokenLength);
209 memcpy(input_token.value, mechToken,mechTokenLength);
210 input_token.length = mechTokenLength;
213 infof(conn->
data,
"Parse SPNEGO Target Token succeded\n");
219 major_status = gss_init_sec_context(&minor_status,
222 neg_ctx->server_name,
226 GSS_C_NO_CHANNEL_BINDINGS,
232 if (input_token.length > 0)
233 gss_release_buffer(&minor_status2, &input_token);
234 neg_ctx->status = major_status;
235 if (GSS_ERROR(major_status)) {
237 log_gss_error(conn, minor_status,
238 (
char *)
"gss_init_sec_context() failed: ");
242 if (output_token.length == 0) {
246 neg_ctx->output_token = output_token;
255 struct negotiatedata *neg_ctx = &conn->
data->
state.negotiate;
256 OM_uint32 minor_status;
257 char *encoded =
NULL;
262 ASN1_OBJECT *
object =
NULL;
264 unsigned char * spnegoToken =
NULL;
265 size_t spnegoTokenLength = 0;
266 unsigned char * responseToken =
NULL;
267 size_t responseTokenLength = 0;
269 responseToken = malloc(neg_ctx->output_token.length);
270 if ( responseToken ==
NULL)
272 memcpy(responseToken, neg_ctx->output_token.value,
273 neg_ctx->output_token.length);
274 responseTokenLength = neg_ctx->output_token.length;
276 object=OBJ_txt2obj (
"1.2.840.113554.1.2.2", 1);
277 if (!makeSpnegoInitialToken (
object,
281 &spnegoTokenLength)) {
283 responseToken =
NULL;
284 infof(conn->
data,
"Make SPNEGO Initial Token failed\n");
287 free(neg_ctx->output_token.value);
288 responseToken =
NULL;
289 neg_ctx->output_token.value = malloc(spnegoTokenLength);
290 memcpy(neg_ctx->output_token.value, spnegoToken,spnegoTokenLength);
291 neg_ctx->output_token.length = spnegoTokenLength;
294 infof(conn->
data,
"Make SPNEGO Initial Token succeded\n");
299 neg_ctx->output_token.length,
306 aprintf(
"Authorization: %s %s\r\n", neg_ctx->protocol, encoded);
308 gss_release_buffer(&minor_status, &neg_ctx->output_token);
314 OM_uint32 minor_status;
315 struct negotiatedata *neg_ctx = &data->
state.negotiate;
317 if (neg_ctx->context != GSS_C_NO_CONTEXT)
318 gss_delete_sec_context(&minor_status, &neg_ctx->context, GSS_C_NO_BUFFER);
320 if (neg_ctx->output_token.length != 0)
321 gss_release_buffer(&minor_status, &neg_ctx->output_token);
323 if (neg_ctx->server_name != GSS_C_NO_NAME)
324 gss_release_name(&minor_status, &neg_ctx->server_name);
326 memset(neg_ctx, 0,
sizeof(*neg_ctx));
size_t Curl_base64_encode(const char *inp, size_t insize, char **outptr)
size_t Curl_base64_decode(const char *src, char *dest)
GLsizei GLsizei GLenum GLenum const GLvoid * data
struct SessionHandle * data
#define checkprefix(a, b)
struct connectdata::dynamically_allocated_data allocptr
int sprintf(idStr &string, const char *fmt,...)