Skip to content

Commit 1821abd

Browse files
committed
fix digest selection for safari and add option to allow unsafe digest
1 parent 4ab0e84 commit 1821abd

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/datum_api.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,36 +417,38 @@ bool datum_api_check_admin_password_only(struct MHD_Connection * const connectio
417417
return false;
418418
}
419419

420-
static enum MHD_DigestAuthAlgorithm datum_api_pick_digest_algo(struct MHD_Connection * const connection, const bool nonce_is_stale) {
420+
static enum MHD_DigestAuthAlgorithm datum_api_pick_digest_algo(struct MHD_Connection * const connection) {
421421
const char * const ua = MHD_lookup_connection_value(connection, MHD_HEADER_KIND, "User-Agent");
422-
if (strstr(ua, "AppleWebKit/") && !(strstr(ua, "Chrome/") || strstr(ua, "Brave/") || strstr(ua, "Edge/"))) {
423-
static bool safari_warned = false;
424-
if (!(nonce_is_stale && safari_warned)) {
425-
DLOG_WARN("Detected login request from Apple Safari. For some reason, this browser only supports obsolete and insecure MD5 digest authentication. Login at your own risk!");
426-
safari_warned = true;
422+
if (datum_config.api_allow_insecure_auth) {
423+
if (strstr(ua, "AppleWebKit/") && !(strstr(ua, "Chrome/") || strstr(ua, "Brave/") || strstr(ua, "Edge/"))) {
424+
return MHD_DIGEST_ALG_MD5;
427425
}
428-
return MHD_DIGEST_ALG_MD5;
429426
}
430427
return MHD_DIGEST_ALG_SHA256;
431428
}
432429

433430
bool datum_api_check_admin_password_httponly(struct MHD_Connection * const connection, const create_response_func_t auth_failure_response_creator) {
434431
int ret;
432+
static bool safari_warned = false;
435433

436434
char * const username = MHD_digest_auth_get_username(connection);
435+
const enum MHD_DigestAuthAlgorithm algo = datum_api_pick_digest_algo(connection);
437436
const char * const realm = "DATUM Gateway";
438437
if (username) {
439-
ret = MHD_digest_auth_check2(connection, realm, username, datum_config.api_admin_password, 300, MHD_DIGEST_ALG_AUTO);
438+
ret = MHD_digest_auth_check2(connection, realm, username, datum_config.api_admin_password, 300, algo);
440439
free(username);
441440
} else {
442441
ret = MHD_NO;
443442
}
443+
if (algo == MHD_DIGEST_ALG_MD5 && ret == MHD_NO && !safari_warned) {
444+
DLOG_WARN("Detected login request from Apple Safari. For some reason, this browser only supports obsolete and insecure MD5 digest authentication. Login at your own risk!");
445+
safari_warned = true;
446+
}
444447
if (ret != MHD_YES) {
445448
const bool nonce_is_stale = (ret == MHD_INVALID_NONCE);
446449
if (username && !nonce_is_stale) {
447450
DLOG_DEBUG("Wrong password in HTTP authentication");
448451
}
449-
const enum MHD_DigestAuthAlgorithm algo = datum_api_pick_digest_algo(connection, nonce_is_stale);
450452
struct MHD_Response * const response = auth_failure_response_creator();
451453
ret = MHD_queue_auth_fail_response2(connection, realm, datum_config.api_csrf_token, response, nonce_is_stale ? MHD_YES : MHD_NO, algo);
452454
MHD_destroy_response(response);

src/datum_conf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ const T_DATUM_CONFIG_ITEM datum_config_options[] = {
108108
.required = false, .ptr = datum_config.api_admin_password, .default_string[0] = "", .max_string_len = sizeof(datum_config.api_admin_password) },
109109
{ .var_type = DATUM_CONF_INT, .category = "api", .name = "listen_port", .description = "Port to listen for API/dashboard requests (0=disabled)",
110110
.required = false, .ptr = &datum_config.api_listen_port, .default_int = 0 },
111+
{ .var_type = DATUM_CONF_BOOL, .category = "api", .name = "allow_insecure_auth", .description = "Allow insecure authentication (required for Safari)",
112+
.required = false, .ptr = &datum_config.api_allow_insecure_auth, .default_bool = false },
111113

112114
// extra block submissions list
113115
{ .var_type = DATUM_CONF_STRING_ARRAY, .category = "extra_block_submissions", .name = "urls", .description = "Array of bitcoind RPC URLs to submit our blocks to directly. Include auth info: http://user:pass@IP",

src/datum_conf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ typedef struct {
9898
size_t api_admin_password_len;
9999
char api_csrf_token[65];
100100
int api_listen_port;
101+
bool api_allow_insecure_auth;
101102

102103
int extra_block_submissions_count;
103104
char extra_block_submissions_urls[DATUM_MAX_BLOCK_SUBMITS][DATUM_CONFIG_MAX_STRING_ARRAY_LEN];

0 commit comments

Comments
 (0)