aboutsummaryrefslogtreecommitdiff
path: root/src/feature/hs/hs_config.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2018-08-22 11:38:28 -0400
committerDavid Goulet <dgoulet@torproject.org>2018-08-22 11:38:28 -0400
commit61ad81c36e46d7b05b66601520c7ff42469f24d7 (patch)
tree937fcc490cee35171f4d4296ed5d458b9d95a1a3 /src/feature/hs/hs_config.c
parentcb466ee7d6f7f475783847a7201eaa6a3e1c711b (diff)
downloadtor-61ad81c36e46d7b05b66601520c7ff42469f24d7.tar.gz
tor-61ad81c36e46d7b05b66601520c7ff42469f24d7.zip
hs: Learn service version by trying to load the keys
In order to switch the default HS version from 2 to 3, we need tor to be smart and be able to decide on the version by trying to load the service keys during configuration validation. Part of #27215 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/hs/hs_config.c')
-rw-r--r--src/feature/hs/hs_config.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/feature/hs/hs_config.c b/src/feature/hs/hs_config.c
index 2c25a168a2..e972576482 100644
--- a/src/feature/hs/hs_config.c
+++ b/src/feature/hs/hs_config.c
@@ -143,6 +143,24 @@ helper_parse_uint64(const char *opt, const char *value, uint64_t min,
return ret;
}
+/* Return the service version by trying to learn it from the key on disk if
+ * any. If nothing is found, the current service configured version is
+ * returned. */
+static int
+config_learn_service_version(hs_service_t *service)
+{
+ int version;
+
+ tor_assert(service);
+
+ version = hs_service_get_version_from_key(service);
+ if (version < 0) {
+ version = service->config.version;
+ }
+
+ return version;
+}
+
/* Return true iff the given options starting at line_ for a hidden service
* contains at least one invalid option. Each hidden service option don't
* apply to all versions so this function can find out. The line_ MUST start
@@ -490,6 +508,12 @@ config_service(const config_line_t *line, const or_options_t *options,
0) < 0) {
goto err;
}
+ /* We'll try to learn the service version here by loading the key(s) if
+ * present. Depending on the key format, we can figure out the service
+ * version. If we can't find a key, the configuration version will be used
+ * which has been set previously. */
+ service->config.version = config_learn_service_version(service);
+
/* Different functions are in charge of specific options for a version. We
* start just after the service directory line so once we hit another
* directory line, the function knows that it has to stop parsing. */