예제 #1
0
static void
authentication_info_cb (SoupMessage *msg, gpointer data)
{
	SoupAuth *auth = data;
	SoupAuthDigestPrivate *priv = SOUP_AUTH_DIGEST_GET_PRIVATE (auth);
	const char *header;
	GHashTable *auth_params;
	char *nextnonce;

	if (auth != soup_message_get_auth (msg))
		return;

	header = soup_message_headers_get_one (msg->response_headers,
					       soup_auth_is_for_proxy (auth) ?
					       "Proxy-Authentication-Info" :
					       "Authentication-Info");
	g_return_if_fail (header != NULL);

	auth_params = soup_header_parse_param_list (header);
	if (!auth_params)
		return;

	nextnonce = g_strdup (g_hash_table_lookup (auth_params, "nextnonce"));
	if (nextnonce) {
		g_free (priv->nonce);
		priv->nonce = nextnonce;
	}

	soup_header_free_param_list (auth_params);
}
예제 #2
0
static void
auth_got_headers (SoupMessage *msg, gpointer manager)
{
	SoupAuthManagerPrivate *priv = SOUP_AUTH_MANAGER (manager)->priv;
	SoupAuth *auth, *prior_auth, *new_auth;
	gboolean prior_auth_failed = FALSE;

	g_mutex_lock (&priv->lock);

	/* See if we used auth last time */
	prior_auth = soup_message_get_auth (msg);
	if (prior_auth && check_auth (msg, prior_auth)) {
		auth = g_object_ref (prior_auth);
		if (!soup_auth_is_ready (auth, msg))
			prior_auth_failed = TRUE;
	} else {
		auth = create_auth (priv, msg);
		if (!auth) {
			g_mutex_unlock (&priv->lock);
			return;
		}
	}

	new_auth = record_auth_for_uri (priv, soup_message_get_uri (msg),
					auth, prior_auth_failed);
	g_object_unref (auth);

	/* If we need to authenticate, try to do it. */
	authenticate_auth (manager, new_auth, msg,
			   prior_auth_failed, FALSE, TRUE);
	g_mutex_unlock (&priv->lock);
}
예제 #3
0
static void
check_server_response (SoupMessage *msg, gpointer auth)
{
	gint ret;
	const char *auth_headers;
	GError *err = NULL;
	SoupAuthNegotiate *negotiate = auth;
	SoupAuthNegotiatePrivate *priv = SOUP_AUTH_NEGOTIATE_GET_PRIVATE (negotiate);
	SoupNegotiateConnectionState *conn = priv->conn_state;

	if (auth != soup_message_get_auth (msg))
		return;

	if (msg->status_code == SOUP_STATUS_UNAUTHORIZED)
		return;

	/* FIXME: need to check for proxy-auth too */
	auth_headers = soup_message_headers_get_one (msg->response_headers,
						     "WWW-Authenticate");
	if (!auth_headers || g_ascii_strncasecmp (auth_headers, "Negotiate ", 10) != 0) {
		g_warning ("Failed to parse auth header");
		conn->state = SOUP_NEGOTIATE_FAILED;
		goto out;
	}

	ret = soup_gss_client_step (conn, auth_headers + 10, &err);

	priv->is_authenticated = ret == AUTH_GSS_COMPLETE;

	if (ret == AUTH_GSS_CONTINUE) {
		conn->state = SOUP_NEGOTIATE_RECEIVED_CHALLENGE;
	} else if (ret == AUTH_GSS_ERROR) {
		if (err)
			g_warning ("%s", err->message);
		conn->state = SOUP_NEGOTIATE_FAILED;
	}
 out:
	g_clear_error (&err);
}