36#define HASH_STRING_LEN (AV_HASH_MAX_SIZE * 2 + 1)
39 int key_len,
char **dest,
int *dest_len)
42 if (!strncmp(
key,
"realm=", key_len)) {
44 *dest_len =
sizeof(
state->realm);
49 int key_len,
char **dest,
int *dest_len)
54 if (!strncmp(
key,
"realm=", key_len)) {
56 *dest_len =
sizeof(
state->realm);
57 }
else if (!strncmp(
key,
"nonce=", key_len)) {
58 *dest = digest->
nonce;
59 *dest_len =
sizeof(digest->
nonce);
60 }
else if (!strncmp(
key,
"opaque=", key_len)) {
62 *dest_len =
sizeof(digest->
opaque);
63 }
else if (!strncmp(
key,
"algorithm=", key_len)) {
66 }
else if (!strncmp(
key,
"qop=", key_len)) {
68 *dest_len =
sizeof(digest->
qop);
69 }
else if (!strncmp(
key,
"stale=", key_len)) {
70 *dest = digest->
stale;
71 *dest_len =
sizeof(digest->
stale);
76 int key_len,
char **dest,
int *dest_len)
81 if (!strncmp(
key,
"nextnonce=", key_len)) {
82 *dest = digest->
nonce;
83 *dest_len =
sizeof(digest->
nonce);
89 char *ptr = strstr(qop,
"auth");
90 char *end = ptr + strlen(
"auth");
92 if (ptr && (!*end ||
av_isspace(*end) || *end ==
',') &&
93 (ptr == qop ||
av_isspace(ptr[-1]) || ptr[-1] ==
',')) {
119 sizeof(
state->digest_params.qop));
132 va_start(vl, hashctx);
134 const char* str = va_arg(vl,
const char*);
144 const char *password,
const char *uri,
149 uint32_t cnonce_buf[2];
156 const char* algorithm =
NULL;
157 bool is_session =
false;
162 snprintf(nc,
sizeof(nc),
"%08x", digest->
nc);
164 if (!strcmp(digest->
algorithm,
"")) { algorithm =
"MD5"; }
165 else if (!strcmp(digest->
algorithm,
"MD5")) { algorithm =
"MD5"; }
166 else if (!strcmp(digest->
algorithm,
"MD5-sess")) { algorithm =
"MD5"; is_session =
true; }
167 else if (!strcmp(digest->
algorithm,
"SHA-256")) { algorithm =
"SHA256"; }
168 else if (!strcmp(digest->
algorithm,
"SHA-256-sess")) { algorithm =
"SHA256"; is_session =
true; }
169 else if (!strcmp(digest->
algorithm,
"SHA-512-256")) { algorithm =
"SHA512/256"; }
170 else if (!strcmp(digest->
algorithm,
"SHA-512-256-sess")){ algorithm =
"SHA512/256"; is_session =
true; }
177 for (
i = 0;
i < 2;
i++)
179 ff_data_to_hex(cnonce, (
const uint8_t*) cnonce_buf,
sizeof(cnonce_buf), 1);
205 if (!strcmp(digest->
qop,
"auth") || !strcmp(digest->
qop,
"auth-int")) {
214 if (!strcmp(digest->
qop,
"") || !strcmp(digest->
qop,
"auth")) {
215 }
else if (!strcmp(digest->
qop,
"auth-int")) {
223 len = strlen(username) + strlen(
state->realm) + strlen(digest->
nonce) +
224 strlen(uri) + strlen(response) + strlen(digest->
algorithm) +
225 strlen(digest->
opaque) + strlen(digest->
qop) + strlen(cnonce) +
231 snprintf(authstr,
len,
"Authorization: Digest ");
246 if (digest->
qop[0]) {
258 const char *path,
const char *method)
260 char *authstr =
NULL;
265 if (!auth || !strchr(auth,
':'))
269 int auth_b64_len,
len;
276 len = auth_b64_len + 30;
284 snprintf(authstr,
len,
"Authorization: Basic ");
285 ptr = authstr + strlen(authstr);
295 if ((password = strchr(username,
':'))) {
static uint8_t hash[HASH_SIZE]
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
#define i(width, name, range_min, range_max)
static struct @346255127015250356166251341105367306144006377143 state
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
void av_hash_freep(AVHashContext **ctx)
Free hash context and set hash context pointer to NULL.
void av_hash_init(AVHashContext *ctx)
Initialize or reset a hash context.
void av_hash_update(AVHashContext *ctx, const uint8_t *src, size_t len)
Update a hash context with additional data.
int av_hash_alloc(AVHashContext **ctx, const char *name)
Allocate a hash context for the algorithm specified by name.
void av_hash_final(AVHashContext *ctx, uint8_t *dst)
Finalize a hash context and compute the actual hash value.
#define AV_HASH_MAX_SIZE
Maximum value that av_hash_get_size() will currently return.
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,...
int av_strcasecmp(const char *a, const char *b)
Locale-independent case-insensitive compare.
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.
static av_const int av_isspace(int c)
Locale-independent conversion of ASCII isspace.
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.
int av_hash_get_size(const AVHashContext *ctx)
#define HASH_STRING_LEN
Maximum length of a hash string in hexadecimal, with a string terminator.
char * ff_http_auth_create_response(HTTPAuthState *state, const char *auth, const char *path, const char *method)
static void update_hash_strings(struct AVHashContext *hashctx,...)
static void choose_qop(char *qop, int size)
static void handle_basic_params(void *context, const char *key, int key_len, char **dest, int *dest_len)
static void handle_digest_params(void *context, const char *key, int key_len, char **dest, int *dest_len)
static void handle_digest_update(void *context, const char *key, int key_len, char **dest, int *dest_len)
static char * make_digest_auth(HTTPAuthState *state, const char *username, const char *password, const char *uri, const char *method)
void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, const char *value)
@ HTTP_AUTH_DIGEST
HTTP 1.1 Digest auth from RFC 2617.
@ HTTP_AUTH_BASIC
HTTP 1.0 Basic auth from RFC 1945 (also in RFC 2617)
Memory handling functions.
char algorithm[sizeof("SHA-512-256-sess")]
Server specified digest algorithm.
int nc
Nonce count, the number of earlier replies where this particular nonce has been used.
char stale[10]
The server indicated that the auth was ok, but needs to be redone with a new, non-stale nonce.
char qop[30]
Quality of protection, containing the one that we've chosen to use, from the alternatives that the se...
char nonce[300]
Server specified nonce.
char opaque[300]
A server-specified string that should be included in authentication responses, not included in the ac...
HTTP Authentication state structure.
char * ff_urldecode(const char *url, int decode_plus_sign)
Decodes an URL from its percent-encoded form back into normal representation.