Skip to content

Commit c26f1f3

Browse files
committed
Add rpc.auth_algo
1 parent dfbf4a0 commit c26f1f3

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

mos.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ config_schema:
2020
- ["rpc.acl_file", "s", "", {title: "File with RPC ACL JSON"}]
2121
- ["rpc.auth_domain", "s", "RPC", {title: "Realm to use for digest authentication"}]
2222
- ["rpc.auth_file", "s", "", {title: "File with user credentials in the htdigest format"}]
23+
- ["rpc.auth_algo", "i", 0, {title: "Password file hashing algorithm: 0 - MD5, 1 - SHA256"}]
2324

2425
libs:
2526
- origin: https://github.com/mongoose-os-libs/mongoose

src/mg_rpc_channel_http.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "frozen.h"
2929

3030
#include "mgos_hal.h"
31+
#include "mgos_sys_config.h"
3132

3233
static const char *s_headers =
3334
"Content-Type: application/json\r\n"
@@ -94,6 +95,7 @@ static bool mg_rpc_channel_http_get_authn_info(
9495
struct mg_str *hdr;
9596
char username_buf[50];
9697
char *username = username_buf;
98+
int algo = mgos_sys_config_get_rpc_auth_algo();
9799

98100
if (auth_domain == NULL || auth_file == NULL) {
99101
auth_domain = chd->default_auth_domain;
@@ -105,7 +107,8 @@ static bool mg_rpc_channel_http_get_authn_info(
105107
}
106108

107109
if (!mg_http_is_authorized(chd->hm, chd->hm->uri, auth_domain, auth_file,
108-
MG_AUTH_FLAG_IS_GLOBAL_PASS_FILE)) {
110+
(MG_AUTH_FLAG_IS_GLOBAL_PASS_FILE |
111+
MG_AUTH_FLAG_ALGO(algo)))) {
109112
goto clean;
110113
}
111114

@@ -152,9 +155,10 @@ static void mg_rpc_channel_http_send_not_authorized(struct mg_rpc_channel *ch,
152155
mg_printf(chd->nc, "Connection: %s\r\n", "close");
153156
mg_printf(chd->nc,
154157
"WWW-Authenticate: Digest "
155-
"qop=\"auth\", realm=\"%s\", nonce=\"%lx\"\r\n"
158+
"qop=\"auth\", realm=\"%s\", nonce=\"%lx\", algorithm=%s\r\n"
156159
"\r\n",
157-
auth_domain, (unsigned long) mg_time());
160+
auth_domain, (unsigned long) mg_time(),
161+
(mgos_sys_config_get_rpc_auth_algo() == MG_AUTH_ALGO_MD5 ? "MD5" : "SHA-256"));
158162

159163
/* We sent a response, the channel is no more. */
160164
chd->nc->flags |= MG_F_SEND_AND_CLOSE;

0 commit comments

Comments
 (0)