~ubuntu-branches/ubuntu/vivid/libav/vivid

« back to all changes in this revision

Viewing changes to libavformat/httpauth.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2013-10-22 23:24:08 UTC
  • mfrom: (1.3.36 sid)
  • Revision ID: package-import@ubuntu.com-20131022232408-b8tvvn4pyzri9mi3
Tags: 6:9.10-1ubuntu1
* Build all -extra flavors from this source package, as libav got demoted
  from main to universe, cf LP: #1243235
* Simplify debian/rules to follow exactly the code that debian executes
* New upstream (LP: #1180288) fixes lots of security issues (LP: #1242802)
* Merge from unstable, remaining changes:
  - build-depend on libtiff5-dev rather than libtiff4-dev,
    avoids FTBFS caused by imlib
  - follow the regular debian codepaths

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include "internal.h"
26
26
#include "libavutil/random_seed.h"
27
27
#include "libavutil/md5.h"
 
28
#include "urldecode.h"
28
29
#include "avformat.h"
29
30
#include <ctype.h>
30
31
 
57
58
    } else if (!strncmp(key, "qop=", key_len)) {
58
59
        *dest     =        digest->qop;
59
60
        *dest_len = sizeof(digest->qop);
 
61
    } else if (!strncmp(key, "stale=", key_len)) {
 
62
        *dest     =        digest->stale;
 
63
        *dest_len = sizeof(digest->stale);
60
64
    }
61
65
}
62
66
 
93
97
            state->auth_type <= HTTP_AUTH_BASIC) {
94
98
            state->auth_type = HTTP_AUTH_BASIC;
95
99
            state->realm[0] = 0;
 
100
            state->stale = 0;
96
101
            ff_parse_key_value(p, (ff_parse_key_val_cb) handle_basic_params,
97
102
                               state);
98
103
        } else if (av_stristart(value, "Digest ", &p) &&
100
105
            state->auth_type = HTTP_AUTH_DIGEST;
101
106
            memset(&state->digest_params, 0, sizeof(DigestParams));
102
107
            state->realm[0] = 0;
 
108
            state->stale = 0;
103
109
            ff_parse_key_value(p, (ff_parse_key_val_cb) handle_digest_params,
104
110
                               state);
105
111
            choose_qop(state->digest_params.qop,
106
112
                       sizeof(state->digest_params.qop));
 
113
            if (!av_strcasecmp(state->digest_params.stale, "true"))
 
114
                state->stale = 1;
107
115
        }
108
116
    } else if (!strcmp(key, "Authentication-Info")) {
109
117
        ff_parse_key_value(value, (ff_parse_key_val_cb) handle_digest_update,
151
159
    ff_data_to_hex(cnonce, (const uint8_t*) cnonce_buf, sizeof(cnonce_buf), 1);
152
160
    cnonce[2*sizeof(cnonce_buf)] = 0;
153
161
 
154
 
    md5ctx = av_malloc(av_md5_size);
 
162
    md5ctx = av_md5_alloc();
155
163
    if (!md5ctx)
156
164
        return NULL;
157
165
 
237
245
{
238
246
    char *authstr = NULL;
239
247
 
 
248
    /* Clear the stale flag, we assume the auth is ok now. It is reset
 
249
     * by the server headers if there's a new issue. */
 
250
    state->stale = 0;
240
251
    if (!auth || !strchr(auth, ':'))
241
252
        return NULL;
242
253
 
243
254
    if (state->auth_type == HTTP_AUTH_BASIC) {
244
 
        int auth_b64_len = AV_BASE64_SIZE(strlen(auth));
245
 
        int len = auth_b64_len + 30;
246
 
        char *ptr;
 
255
        int auth_b64_len, len;
 
256
        char *ptr, *decoded_auth = ff_urldecode(auth);
 
257
 
 
258
        if (!decoded_auth)
 
259
            return NULL;
 
260
 
 
261
        auth_b64_len = AV_BASE64_SIZE(strlen(decoded_auth));
 
262
        len = auth_b64_len + 30;
 
263
 
247
264
        authstr = av_malloc(len);
248
 
        if (!authstr)
 
265
        if (!authstr) {
 
266
            av_free(decoded_auth);
249
267
            return NULL;
 
268
        }
 
269
 
250
270
        snprintf(authstr, len, "Authorization: Basic ");
251
271
        ptr = authstr + strlen(authstr);
252
 
        av_base64_encode(ptr, auth_b64_len, auth, strlen(auth));
 
272
        av_base64_encode(ptr, auth_b64_len, decoded_auth, strlen(decoded_auth));
253
273
        av_strlcat(ptr, "\r\n", len - (ptr - authstr));
 
274
        av_free(decoded_auth);
254
275
    } else if (state->auth_type == HTTP_AUTH_DIGEST) {
255
 
        char *username = av_strdup(auth), *password;
 
276
        char *username = ff_urldecode(auth), *password;
256
277
 
257
278
        if (!username)
258
279
            return NULL;
265
286
    }
266
287
    return authstr;
267
288
}
268