Esempio n. 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);
}
Esempio n. 2
0
static void
authenticate (SoupSession *session, SoupMessage *msg,
	      SoupAuth *auth, gboolean retrying, gpointer data)
{
	if (msg->status_code == SOUP_STATUS_UNAUTHORIZED) {
		if (soup_auth_is_for_proxy (auth)) {
			debug_printf (1, "  got proxy auth object for 401!\n");
			errors++;
		}
	} else if (msg->status_code == SOUP_STATUS_PROXY_UNAUTHORIZED) {
		if (!soup_auth_is_for_proxy (auth)) {
			debug_printf (1, "  got regular auth object for 407!\n");
			errors++;
		}
	} else {
		debug_printf (1, "  got authenticate signal with status %d\n",
			      msg->status_code);
		errors++;
	}

	if (!retrying)
		soup_auth_authenticate (auth, "user1", "realm1");
}
static ProtectionSpace protectionSpaceFromSoupAuthAndMessage(SoupAuth* soupAuth, SoupMessage* message)
{
    const char* schemeName = soup_auth_get_scheme_name(soupAuth);
    ProtectionSpaceAuthenticationScheme scheme;
    if (!g_ascii_strcasecmp(schemeName, "basic"))
        scheme = ProtectionSpaceAuthenticationSchemeHTTPBasic;
    else if (!g_ascii_strcasecmp(schemeName, "digest"))
        scheme = ProtectionSpaceAuthenticationSchemeHTTPDigest;
    else if (!g_ascii_strcasecmp(schemeName, "ntlm"))
        scheme = ProtectionSpaceAuthenticationSchemeNTLM;
    else if (!g_ascii_strcasecmp(schemeName, "negotiate"))
        scheme = ProtectionSpaceAuthenticationSchemeNegotiate;
    else
        scheme = ProtectionSpaceAuthenticationSchemeUnknown;

    SoupURI* soupURI = soup_message_get_uri(message);
    return ProtectionSpace(String::fromUTF8(soup_uri_get_host(soupURI)), soup_uri_get_port(soupURI),
        protectionSpaceServerTypeFromURI(soupURI, soup_auth_is_for_proxy(soupAuth)),
        String::fromUTF8(soup_auth_get_realm(soupAuth)), scheme);
}
Esempio n. 4
0
static char *
soup_auth_digest_get_authorization (SoupAuth *auth, SoupMessage *msg)
{
	SoupAuthDigestPrivate *priv = SOUP_AUTH_DIGEST_GET_PRIVATE (auth);
	char response[33], *token;
	char *url, *algorithm;
	GString *out;
	SoupURI *uri;

	uri = soup_message_get_uri (msg);
	g_return_val_if_fail (uri != NULL, NULL);
	url = soup_uri_to_string (uri, TRUE);

	soup_auth_digest_compute_response (msg->method, url, priv->hex_a1,
					   priv->qop, priv->nonce,
					   priv->cnonce, priv->nc,
					   response);

	out = g_string_new ("Digest ");

	soup_header_g_string_append_param_quoted (out, "username", priv->user);
	g_string_append (out, ", ");
	soup_header_g_string_append_param_quoted (out, "realm", auth->realm);
	g_string_append (out, ", ");
	soup_header_g_string_append_param_quoted (out, "nonce", priv->nonce);
	g_string_append (out, ", ");
	soup_header_g_string_append_param_quoted (out, "uri", url);
	g_string_append (out, ", ");
	algorithm = soup_auth_digest_get_algorithm (priv->algorithm);
	g_string_append_printf (out, "algorithm=%s", algorithm);
	g_free (algorithm);
	g_string_append (out, ", ");
	soup_header_g_string_append_param_quoted (out, "response", response);

	if (priv->opaque) {
		g_string_append (out, ", ");
		soup_header_g_string_append_param_quoted (out, "opaque", priv->opaque);
	}

	if (priv->qop) {
		char *qop = soup_auth_digest_get_qop (priv->qop);

		g_string_append (out, ", ");
		soup_header_g_string_append_param_quoted (out, "cnonce", priv->cnonce);
		g_string_append_printf (out, ", nc=%.8x, qop=%s",
					priv->nc, qop);
		g_free (qop);
	}

	g_free (url);

	priv->nc++;

	token = g_string_free (out, FALSE);

	soup_message_add_header_handler (msg,
					 "got_headers",
					 soup_auth_is_for_proxy (auth) ?
					 "Proxy-Authentication-Info" :
					 "Authentication-Info",
					 G_CALLBACK (authentication_info_cb),
					 auth);
	return token;
}
Esempio n. 5
0
authenticate (SoupSession *session,
		SoupMessage *msg,
		SoupAuth *auth,
		gboolean retrying,
		gpointer data)
#endif
{
	SoupURI *proxy_uri;
	gchar *user, *pass;
	RSS_AUTH *auth_info = g_new0(RSS_AUTH, 1);

	if (msg->status_code == SOUP_STATUS_PROXY_UNAUTHORIZED) {
		d("proxy:%d\n", soup_auth_is_for_proxy(auth));
	g_object_get (G_OBJECT(session),
				"proxy-uri", &proxy_uri,
				NULL);
	//proxy_auth_dialog("Proxy Authentication", proxy_uri->user, proxy_uri->password);
	//g_object_set (G_OBJECT (session), SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
	return;
	}

	user = g_hash_table_lookup(rf->hruser, data);
	pass = g_hash_table_lookup(rf->hrpass, data);
	d("data:%s, user:%s, pass:%s\n", (gchar *)data, user, pass);

	if (user && pass) {
#if LIBSOUP_VERSION < 2003000
		*username = g_strdup(user);
		*password = g_strdup(pass);
#else
	if (!retrying)
		soup_auth_authenticate (auth, user, pass);
	else {
		if (!rf->autoupdate)
			goto authpop;
	}
#endif
	} else {
		read_up(data);
		user = g_hash_table_lookup(rf->hruser, data);
		pass = g_hash_table_lookup(rf->hrpass, data);
		if (user && pass) {
#if LIBSOUP_VERSION < 2003000
			*username = g_strdup(user);
			*password = g_strdup(pass);
#else
			if (!retrying)
				soup_auth_authenticate (auth, user, pass);
			return;
#endif
		}
		//we test for autofetching in progresss because it seems
		//preety annoying to pop the authentication popup in front
		//of the user every time feeds are automatically fetched
		if (!rf->autoupdate) {
			//we will continue after user has made a decision on
			//web auth dialog
			//Bug 522147 – need to be able to pause synchronous I/O
authpop:		if (G_OBJECT_TYPE(session) == SOUP_TYPE_SESSION_ASYNC) {
				soup_session_pause_message(session, msg);
			}
			auth_info->url = data;
			auth_info->soup_auth = auth;
			auth_info->retrying = retrying;
			auth_info->session = session;
			auth_info->message = msg;
			web_auth_dialog(auth_info);
			return;
		}
	}
}