Add SHA256 support for digest auth

https://tools.ietf.org/html/rfc7616
This commit is contained in:
Deomid "rojer" Ryabkov authored and Deomid Ryabkov committed 2021-06-12 01:56:29 +01:00
1 parent 6fa305e36d
commit a350208f35
7 files changed
+364 -172

No files matched your search

+31
View File
@@ -139,6 +139,14 @@ size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name,
int mg_get_http_var(const struct mg_str *buf, const char *name, char *dst,
size_t dst_len);
/*
* Supported digest auth algorithms.
*/
enum mg_auth_algo {
MG_AUTH_ALGO_MD5 = 0,
MG_AUTH_ALGO_SHA256 = 1,
};
#if MG_ENABLE_FILESYSTEM
/*
* This structure defines how `mg_serve_http()` works.
@@ -175,6 +183,11 @@ struct mg_serve_http_opts {
*/
const char *global_auth_file;
/*
* Password hashing algorithm used by the password files.
*/
enum mg_auth_algo auth_algo;
/* Set to "no" to disable directory listing. Enabled by default. */
const char *enable_directory_listing;
@@ -426,6 +439,7 @@ struct mg_http_endpoint_opts {
/* Authorization domain (realm) */
const char *auth_domain;
const char *auth_file;
enum mg_auth_algo auth_algo;
};
void mg_register_http_endpoint_opt(struct mg_connection *nc,
@@ -433,12 +447,23 @@ void mg_register_http_endpoint_opt(struct mg_connection *nc,
mg_event_handler_t handler,
struct mg_http_endpoint_opts opts);
/*
* Sends 401 Unauthorized response.
*/
void mg_http_send_digest_auth_request(struct mg_connection *c,
const char *domain);
void mg_http_send_digest_auth_request_algo(struct mg_connection *c,
const char *domain,
enum mg_auth_algo algo);
/*
* Authenticates a HTTP request against an opened password file.
* Returns 1 if authenticated, 0 otherwise.
*/
int mg_http_check_digest_auth(struct http_message *hm, const char *auth_domain,
FILE *fp);
int mg_http_check_digest_auth_algo(struct http_message *hm, const char *auth_domain,
enum mg_auth_algo fp_algo, FILE *fp);
/*
* Authenticates given response params against an opened password file.
@@ -451,6 +476,12 @@ int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
struct mg_str response, struct mg_str qop,
struct mg_str nc, struct mg_str nonce,
struct mg_str auth_domain, FILE *fp);
int mg_check_digest_auth_algo(struct mg_str method, struct mg_str uri,
struct mg_str username, struct mg_str cnonce,
struct mg_str response, struct mg_str qop,
struct mg_str nc, struct mg_str nonce,
struct mg_str auth_domain, enum mg_auth_algo algo,
FILE *fp);
/*
* Sends buffer `buf` of size `len` to the client using chunked HTTP encoding.