Warn when NIP-11 pubkey is in incorrect format (#52)

This commit is contained in:
Doug Hoyte
2023-07-20 18:03:40 -04:00
parent 0d21dc3255
commit 42d5101316
3 changed files with 26 additions and 8 deletions

View File

@ -52,15 +52,18 @@ void RelayServer::runWebsocket(ThreadPool<MsgWebsocket>::Thread &thr) {
auto getServerInfoHttpResponse = [&supportedNips, ver = uint64_t(0), rendered = std::string("")]() mutable { auto getServerInfoHttpResponse = [&supportedNips, ver = uint64_t(0), rendered = std::string("")]() mutable {
if (ver != cfg().version()) { if (ver != cfg().version()) {
rendered = preGenerateHttpResponse("application/json", tao::json::to_string(tao::json::value({ tao::json::value nip11 = tao::json::value({
{ "name", cfg().relay__info__name },
{ "description", cfg().relay__info__description },
{ "pubkey", cfg().relay__info__pubkey },
{ "contact", cfg().relay__info__contact },
{ "supported_nips", supportedNips }, { "supported_nips", supportedNips },
{ "software", "git+https://github.com/hoytech/strfry.git" }, { "software", "git+https://github.com/hoytech/strfry.git" },
{ "version", APP_GIT_VERSION }, { "version", APP_GIT_VERSION },
}))); });
if (cfg().relay__info__name.size()) nip11["name"] = cfg().relay__info__name;
if (cfg().relay__info__description.size()) nip11["description"] = cfg().relay__info__description;
if (cfg().relay__info__contact.size()) nip11["contact"] = cfg().relay__info__contact;
if (cfg().relay__info__pubkey.size()) nip11["pubkey"] = cfg().relay__info__pubkey;
rendered = preGenerateHttpResponse("application/json", tao::json::to_string(nip11));
ver = cfg().version(); ver = cfg().version();
} }

View File

@ -5,6 +5,18 @@
static void checkConfig() {
if (cfg().relay__info__pubkey.size()) {
try {
auto p = from_hex(cfg().relay__info__pubkey);
if (p.size() != 32) throw herr("bad size");
} catch (std::exception &e) {
LW << "Your relay.info.pubkey is incorrectly formatted. It should be 64 hex digits.";
}
}
}
void cmd_relay(const std::vector<std::string> &subArgs) { void cmd_relay(const std::vector<std::string> &subArgs) {
RelayServer s; RelayServer s;
s.run(); s.run();
@ -53,12 +65,15 @@ void RelayServer::run() {
// Monitor for config file reloads // Monitor for config file reloads
checkConfig();
auto configFileChangeWatcher = hoytech::file_change_monitor(configFile); auto configFileChangeWatcher = hoytech::file_change_monitor(configFile);
configFileChangeWatcher.setDebounce(100); configFileChangeWatcher.setDebounce(100);
configFileChangeWatcher.run([&](){ configFileChangeWatcher.run([&](){
loadConfig(configFile); loadConfig(configFile);
checkConfig();
}); });

View File

@ -57,10 +57,10 @@ relay {
description = "This is a strfry instance." description = "This is a strfry instance."
# NIP-11: Administrative nostr pubkey, for contact purposes # NIP-11: Administrative nostr pubkey, for contact purposes
pubkey = "unset" pubkey = ""
# NIP-11: Alternative administrative contact (email, website, etc) # NIP-11: Alternative administrative contact (email, website, etc)
contact = "unset" contact = ""
} }
# Maximum accepted incoming websocket frame size (should be larger than max event) (restart required) # Maximum accepted incoming websocket frame size (should be larger than max event) (restart required)