@@ -4704,13 +4704,16 @@ extern void mg_hash_md5_v(size_t num_msgs, const uint8_t *msgs[],
4704
4704
const size_t *msg_lens, uint8_t *digest);
4705
4705
extern void mg_hash_sha1_v (size_t num_msgs, const uint8_t *msgs[],
4706
4706
const size_t *msg_lens, uint8_t *digest);
4707
+ extern void mg_hash_sha256_v (size_t num_msgs, const uint8_t *msgs[],
4708
+ const size_t *msg_lens, uint8_t *digest);
4707
4709
4708
4710
/*
4709
4711
* Flags for `mg_http_is_authorized()`.
4710
4712
*/
4711
4713
#define MG_AUTH_FLAG_IS_DIRECTORY (1 << 0 )
4712
4714
#define MG_AUTH_FLAG_IS_GLOBAL_PASS_FILE (1 << 1 )
4713
4715
#define MG_AUTH_FLAG_ALLOW_MISSING_FILE (1 << 2 )
4716
+ #define MG_AUTH_FLAG_ALGO (algo ) ((((int ) algo) & 3 ) << 8 )
4714
4717
4715
4718
/*
4716
4719
* Checks whether an http request is authorized. `domain` is the authentication
@@ -4723,12 +4726,6 @@ int mg_http_is_authorized(struct http_message *hm, struct mg_str path,
4723
4726
const char *domain, const char *passwords_file,
4724
4727
int flags);
4725
4728
4726
- /*
4727
- * Sends 401 Unauthorized response.
4728
- */
4729
- void mg_http_send_digest_auth_request (struct mg_connection *c,
4730
- const char *domain);
4731
-
4732
4729
#ifdef __cplusplus
4733
4730
}
4734
4731
#endif /* __cplusplus */
@@ -4879,6 +4876,14 @@ size_t mg_parse_multipart(const char *buf, size_t buf_len, char *var_name,
4879
4876
int mg_get_http_var (const struct mg_str *buf, const char *name, char *dst,
4880
4877
size_t dst_len);
4881
4878
4879
+ /*
4880
+ * Supported digest auth algorithms.
4881
+ */
4882
+ enum mg_auth_algo {
4883
+ MG_AUTH_ALGO_MD5 = 0 ,
4884
+ MG_AUTH_ALGO_SHA256 = 1 ,
4885
+ };
4886
+
4882
4887
#if MG_ENABLE_FILESYSTEM
4883
4888
/*
4884
4889
* This structure defines how `mg_serve_http()` works.
@@ -4915,6 +4920,11 @@ struct mg_serve_http_opts {
4915
4920
*/
4916
4921
const char *global_auth_file;
4917
4922
4923
+ /*
4924
+ * Password hashing algorithm used by the password files.
4925
+ */
4926
+ enum mg_auth_algo auth_algo;
4927
+
4918
4928
/* Set to "no" to disable directory listing. Enabled by default. */
4919
4929
const char *enable_directory_listing;
4920
4930
@@ -5166,19 +5176,31 @@ struct mg_http_endpoint_opts {
5166
5176
/* Authorization domain (realm) */
5167
5177
const char *auth_domain;
5168
5178
const char *auth_file;
5179
+ enum mg_auth_algo auth_algo;
5169
5180
};
5170
5181
5171
5182
void mg_register_http_endpoint_opt (struct mg_connection *nc,
5172
5183
const char *uri_path,
5173
5184
mg_event_handler_t handler,
5174
5185
struct mg_http_endpoint_opts opts);
5175
5186
5187
+ /*
5188
+ * Sends 401 Unauthorized response.
5189
+ */
5190
+ void mg_http_send_digest_auth_request (struct mg_connection *c,
5191
+ const char *domain);
5192
+ void mg_http_send_digest_auth_request_algo (struct mg_connection *c,
5193
+ const char *domain,
5194
+ enum mg_auth_algo algo);
5195
+
5176
5196
/*
5177
5197
* Authenticates a HTTP request against an opened password file.
5178
5198
* Returns 1 if authenticated, 0 otherwise.
5179
5199
*/
5180
5200
int mg_http_check_digest_auth (struct http_message *hm, const char *auth_domain,
5181
5201
FILE *fp);
5202
+ int mg_http_check_digest_auth_algo (struct http_message *hm, const char *auth_domain,
5203
+ enum mg_auth_algo fp_algo, FILE *fp);
5182
5204
5183
5205
/*
5184
5206
* Authenticates given response params against an opened password file.
@@ -5191,6 +5213,12 @@ int mg_check_digest_auth(struct mg_str method, struct mg_str uri,
5191
5213
struct mg_str response, struct mg_str qop,
5192
5214
struct mg_str nc, struct mg_str nonce,
5193
5215
struct mg_str auth_domain, FILE *fp);
5216
+ int mg_check_digest_auth_algo (struct mg_str method, struct mg_str uri,
5217
+ struct mg_str username, struct mg_str cnonce,
5218
+ struct mg_str response, struct mg_str qop,
5219
+ struct mg_str nc, struct mg_str nonce,
5220
+ struct mg_str auth_domain, enum mg_auth_algo algo,
5221
+ FILE *fp);
5194
5222
5195
5223
/*
5196
5224
* Sends buffer `buf` of size `len` to the client using chunked HTTP encoding.
@@ -5360,6 +5388,12 @@ int mg_http_create_digest_auth_header(char *buf, size_t buf_len,
5360
5388
const char *method, const char *uri,
5361
5389
const char *auth_domain, const char *user,
5362
5390
const char *passwd, const char *nonce);
5391
+ int mg_http_create_digest_auth_header_algo (char *buf, size_t buf_len,
5392
+ const char *method, const char *uri,
5393
+ const char *auth_domain,
5394
+ const char *user, const char *passwd,
5395
+ const char *nonce,
5396
+ enum mg_auth_algo algo);
5363
5397
5364
5398
#ifdef __cplusplus
5365
5399
}
0 commit comments