From 5423e908c9f5f12f599f6c9625ac9539be671695 Mon Sep 17 00:00:00 2001 From: Antti Seppälä Date: Wed, 25 Jul 2012 12:43:39 +0300 Subject: Support urlencoded http authentication credentials MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It should be possible to specify usernames in http requests containing urlencoded characters. This patch adds support for decoding the auth strings. Signed-off-by: Antti Seppälä Signed-off-by: Martin Storsjö --- libavformat/httpauth.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'libavformat/httpauth.c') diff --git a/libavformat/httpauth.c b/libavformat/httpauth.c index c1cf019eda..4ec8ac2599 100644 --- a/libavformat/httpauth.c +++ b/libavformat/httpauth.c @@ -25,6 +25,7 @@ #include "internal.h" #include "libavutil/random_seed.h" #include "libavutil/md5.h" +#include "urldecode.h" #include "avformat.h" #include @@ -251,18 +252,28 @@ char *ff_http_auth_create_response(HTTPAuthState *state, const char *auth, return NULL; if (state->auth_type == HTTP_AUTH_BASIC) { - int auth_b64_len = AV_BASE64_SIZE(strlen(auth)); - int len = auth_b64_len + 30; - char *ptr; + int auth_b64_len, len; + char *ptr, *decoded_auth = ff_urldecode(auth); + + if (!decoded_auth) + return NULL; + + auth_b64_len = AV_BASE64_SIZE(strlen(decoded_auth)); + len = auth_b64_len + 30; + authstr = av_malloc(len); - if (!authstr) + if (!authstr) { + av_free(decoded_auth); return NULL; + } + snprintf(authstr, len, "Authorization: Basic "); ptr = authstr + strlen(authstr); - av_base64_encode(ptr, auth_b64_len, auth, strlen(auth)); + av_base64_encode(ptr, auth_b64_len, decoded_auth, strlen(decoded_auth)); av_strlcat(ptr, "\r\n", len - (ptr - authstr)); + av_free(decoded_auth); } else if (state->auth_type == HTTP_AUTH_DIGEST) { - char *username = av_strdup(auth), *password; + char *username = ff_urldecode(auth), *password; if (!username) return NULL; -- cgit v1.2.3