diff options
author | Dan Winship <danw@gnome.org> | 2011-10-20 17:27:34 -0400 |
---|---|---|
committer | Dan Winship <danw@gnome.org> | 2011-11-13 15:11:57 -0500 |
commit | d350aedcf06ae86de7b615e963d39cb699723230 (patch) | |
tree | 2f18c732e17e0915ed873c7594a705e8d6506a29 /libsoup | |
parent | ee85d6448a90cc0e4072414ca69e85078b1fc0f7 (diff) | |
download | libsoup-d350aedcf06ae86de7b615e963d39cb699723230.tar.gz |
SoupAuthBasic: allow (some) non-ASCII usernames/passwords
Convert the (assumed-UTF-8) username and password into ISO-8859-1
before encoding. This is what a few other browsers do.
Based on a patch from Joachim Breitner, sponsored by ITOMIG GmbH and
the City of Böblingen.
https://bugzilla.gnome.org/show_bug.cgi?id=576838
Diffstat (limited to 'libsoup')
-rw-r--r-- | libsoup/soup-auth-basic.c | 9 | ||||
-rw-r--r-- | libsoup/soup-logger.c | 13 |
2 files changed, 20 insertions, 2 deletions
diff --git a/libsoup/soup-auth-basic.c b/libsoup/soup-auth-basic.c index 4218f7e9..3705e6e3 100644 --- a/libsoup/soup-auth-basic.c +++ b/libsoup/soup-auth-basic.c @@ -103,10 +103,17 @@ static void authenticate (SoupAuth *auth, const char *username, const char *password) { SoupAuthBasicPrivate *priv = SOUP_AUTH_BASIC_GET_PRIVATE (auth); - char *user_pass; + char *user_pass, *user_pass_latin1; int len; user_pass = g_strdup_printf ("%s:%s", username, password); + user_pass_latin1 = g_convert (user_pass, -1, "ISO-8859-1", "UTF-8", + NULL, NULL, NULL); + if (user_pass_latin1) { + memset (user_pass, 0, strlen (user_pass)); + g_free (user_pass); + user_pass = user_pass_latin1; + } len = strlen (user_pass); if (priv->token) { diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c index ac901fc4..b159e678 100644 --- a/libsoup/soup-logger.c +++ b/libsoup/soup-logger.c @@ -422,10 +422,21 @@ soup_logger_print (SoupLogger *logger, SoupLoggerLogLevel level, static void soup_logger_print_basic_auth (SoupLogger *logger, const char *value) { - char *decoded, *p; + char *decoded, *decoded_utf8, *p; gsize len; decoded = (char *)g_base64_decode (value + 6, &len); + if (decoded && !g_utf8_validate (decoded, -1, NULL)) { + decoded_utf8 = g_convert_with_fallback (decoded, -1, + "UTF-8", "ISO-8859-1", + NULL, NULL, &len, + NULL); + if (decoded_utf8) { + g_free (decoded); + decoded = decoded_utf8; + } + } + if (!decoded) decoded = g_strdup (value); p = strchr (decoded, ':'); |