33 int key_len,
char **dest,
int *dest_len)
35 if (!strncmp(key,
"realm=", key_len)) {
37 *dest_len =
sizeof(state->
realm);
42 int key_len,
char **dest,
int *dest_len)
46 if (!strncmp(key,
"realm=", key_len)) {
48 *dest_len =
sizeof(state->
realm);
49 }
else if (!strncmp(key,
"nonce=", key_len)) {
50 *dest = digest->
nonce;
51 *dest_len =
sizeof(digest->
nonce);
52 }
else if (!strncmp(key,
"opaque=", key_len)) {
54 *dest_len =
sizeof(digest->
opaque);
55 }
else if (!strncmp(key,
"algorithm=", key_len)) {
58 }
else if (!strncmp(key,
"qop=", key_len)) {
60 *dest_len =
sizeof(digest->
qop);
61 }
else if (!strncmp(key,
"stale=", key_len)) {
62 *dest = digest->
stale;
63 *dest_len =
sizeof(digest->
stale);
68 int key_len,
char **dest,
int *dest_len)
72 if (!strncmp(key,
"nextnonce=", key_len)) {
73 *dest = digest->
nonce;
74 *dest_len =
sizeof(digest->
nonce);
80 char *ptr = strstr(qop,
"auth");
81 char *end = ptr + strlen(
"auth");
83 if (ptr && (!*end || isspace(*end) || *end ==
',') &&
84 (ptr == qop || isspace(ptr[-1]) || ptr[-1] ==
',')) {
94 if (!strcmp(key,
"WWW-Authenticate") || !strcmp(key,
"Proxy-Authenticate")) {
116 }
else if (!strcmp(key,
"Authentication-Info")) {
127 va_start(vl, md5ctx);
129 const char* str = va_arg(vl,
const char*);
139 const char *password,
const char *uri,
144 uint32_t cnonce_buf[2];
148 char A1hash[33], A2hash[33], response[33];
149 struct AVMD5 *md5ctx;
154 snprintf(nc,
sizeof(nc),
"%08x", digest->
nc);
157 for (i = 0; i < 2; i++)
160 cnonce[2*
sizeof(cnonce_buf)] = 0;
173 }
else if (!strcmp(digest->
algorithm,
"MD5-sess")) {
193 if (!strcmp(digest->
qop,
"auth") || !strcmp(digest->
qop,
"auth-int")) {
203 if (!strcmp(digest->
qop,
"") || !strcmp(digest->
qop,
"auth")) {
204 }
else if (!strcmp(digest->
qop,
"auth-int")) {
212 len = strlen(username) + strlen(state->
realm) + strlen(digest->
nonce) +
213 strlen(uri) + strlen(response) + strlen(digest->
algorithm) +
214 strlen(digest->
opaque) + strlen(digest->
qop) + strlen(cnonce) +
220 snprintf(authstr, len,
"Authorization: Digest ");
223 av_strlcatf(authstr, len,
"username=\"%s\"", username);
227 av_strlcatf(authstr, len,
",response=\"%s\"", response);
232 if (digest->
qop[0]) {
234 av_strlcatf(authstr, len,
",cnonce=\"%s\"", cnonce);
244 const char *path,
const char *method)
246 char *authstr =
NULL;
251 if (!auth || !strchr(auth,
':'))
255 int auth_b64_len,
len;
262 len = auth_b64_len + 30;
270 snprintf(authstr, len,
"Authorization: Basic ");
271 ptr = authstr + strlen(authstr);
273 av_strlcat(ptr,
"\r\n", len - (ptr - authstr));
281 if ((password = strchr(username,
':'))) {
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
char algorithm[10]
Server specified digest algorithm.
static int hash(int head, const int add)
Hash function adding character.
static void handle_basic_params(HTTPAuthState *state, const char *key, int key_len, char **dest, int *dest_len)
HTTP Authentication state structure.
int av_stristart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str independent of case.
struct AVMD5 * av_md5_alloc(void)
char opaque[300]
A server-specified string that should be included in authentication responses, not included in the ac...
HTTP 1.0 Basic auth from RFC 1945 (also in RFC 2617)
static void choose_qop(char *qop, int size)
void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes.
int av_strcasecmp(const char *a, const char *b)
static char * make_digest_auth(HTTPAuthState *state, const char *username, const char *password, const char *uri, const char *method)
int stale
Auth ok, but needs to be resent with a new nonce.
static void handle_digest_params(HTTPAuthState *state, const char *key, int key_len, char **dest, int *dest_len)
char realm[200]
Authentication realm.
void av_md5_init(AVMD5 *ctx)
HTTP 1.1 Digest auth from RFC 2617.
char qop[30]
Quality of protection, containing the one that we've chosen to use, from the alternatives that the se...
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
void av_md5_final(AVMD5 *ctx, uint8_t *dst)
char * ff_http_auth_create_response(HTTPAuthState *state, const char *auth, const char *path, const char *method)
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value)
static void handle_digest_update(HTTPAuthState *state, const char *key, int key_len, char **dest, int *dest_len)
char nonce[300]
Server specified nonce.
DigestParams digest_params
The parameters specifiec to digest authentication.
HTTPAuthType auth_type
The currently chosen auth type.
int nc
Nonce count, the number of earlier replies where this particular nonce has been used.
uint32_t av_get_random_seed(void)
Get random data.
char stale[10]
The server indicated that the auth was ok, but needs to be redone with a new, non-stale nonce...
static void update_md5_strings(struct AVMD5 *md5ctx,...)
char * ff_urldecode(const char *url)
Decodes an URL from its percent-encoded form back into normal representation.