mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-12-03 17:23:37 +00:00
The proxy token seed is created on startup and never stored.
This commit is contained in:
parent
50fa2ae0e6
commit
19b9998f8c
4 changed files with 7 additions and 14 deletions
17
data.c
17
data.c
|
@ -165,21 +165,12 @@ int srv_open(const char *basedir, int auto_upgrade)
|
|||
write_default_css();
|
||||
}
|
||||
|
||||
/* if proxy_media is set but there is no token seed, create one */
|
||||
if (xs_is_true(xs_dict_get(srv_config, "proxy_media")) &&
|
||||
xs_is_null(xs_dict_get(srv_config, "proxy_token_seed"))) {
|
||||
/* create the proxy token seed */
|
||||
{
|
||||
char rnd[16];
|
||||
xs_rnd_buf(rnd, sizeof(rnd));
|
||||
xs *pts = xs_hex_enc(rnd, sizeof(rnd));
|
||||
|
||||
xs_dict_set(srv_config, "proxy_token_seed", pts);
|
||||
|
||||
if ((f = fopen(cfg_file, "w")) != NULL) {
|
||||
xs_json_dump(srv_config, 4, f);
|
||||
fclose(f);
|
||||
|
||||
srv_log(xs_fmt("Created proxy_token_seed"));
|
||||
}
|
||||
srv_proxy_token_seed = xs_hex_enc(rnd, sizeof(rnd));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -3679,7 +3670,7 @@ xs_str *make_url(const char *href, const char *proxy, int by_token)
|
|||
xs *p = NULL;
|
||||
|
||||
if (by_token) {
|
||||
xs *tks = xs_fmt("%s:%s", xs_dict_get(srv_config, "proxy_token_seed"), proxy);
|
||||
xs *tks = xs_fmt("%s:%s", srv_proxy_token_seed, proxy);
|
||||
xs *tk = xs_md5_hex(tks, strlen(tks));
|
||||
|
||||
p = xs_fmt("%s/y/%s/", proxy, tk);
|
||||
|
|
2
html.c
2
html.c
|
@ -3208,7 +3208,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
|
|||
}
|
||||
else {
|
||||
/* proxy usage authorized by proxy_token */
|
||||
xs *tks = xs_fmt("%s:%s", xs_dict_get(srv_config, "proxy_token_seed"), snac.actor);
|
||||
xs *tks = xs_fmt("%s:%s", srv_proxy_token_seed, snac.actor);
|
||||
xs *tk = xs_md5_hex(tks, strlen(tks));
|
||||
xs *p = xs_fmt("y/%s/", tk);
|
||||
|
||||
|
|
1
snac.c
1
snac.c
|
@ -33,6 +33,7 @@
|
|||
xs_str *srv_basedir = NULL;
|
||||
xs_dict *srv_config = NULL;
|
||||
xs_str *srv_baseurl = NULL;
|
||||
xs_str *srv_proxy_token_seed = NULL;
|
||||
|
||||
int dbglevel = 0;
|
||||
|
||||
|
|
1
snac.h
1
snac.h
|
@ -26,6 +26,7 @@ extern double disk_layout;
|
|||
extern xs_str *srv_basedir;
|
||||
extern xs_dict *srv_config;
|
||||
extern xs_str *srv_baseurl;
|
||||
extern xs_str *srv_proxy_token_seed;
|
||||
|
||||
extern int dbglevel;
|
||||
|
||||
|
|
Loading…
Reference in a new issue