aboutsummaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2019-11-25 18:03:53 +0200
committerDavid Goulet <dgoulet@torproject.org>2019-12-03 09:22:17 -0500
commit8ed8707f0ab78e9c954dad870f0529369c01c518 (patch)
tree815d9b42f9ea7a4e03e39fdab5669e106d595f82 /src/feature
parent763f33729062ba015b10369dc767db3408733ad4 (diff)
downloadtor-8ed8707f0ab78e9c954dad870f0529369c01c518.tar.gz
tor-8ed8707f0ab78e9c954dad870f0529369c01c518.zip
hsv3: Abstract parts of hs_config_client_authorization() into func.
Now we have a function that reads a file and returns a credential. We need that for the REMOVE control port command.
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/hs/hs_client.c78
1 files changed, 46 insertions, 32 deletions
diff --git a/src/feature/hs/hs_client.c b/src/feature/hs/hs_client.c
index 0247a01998..cb902290f9 100644
--- a/src/feature/hs/hs_client.c
+++ b/src/feature/hs/hs_client.c
@@ -1569,6 +1569,50 @@ hs_client_register_auth_credentials(hs_client_service_authorization_t *creds)
return retval;
}
+/** Load a client authorization file with <b>filename</b> that is stored under
+ * the global client auth directory, and return a newly-allocated credentials
+ * object if it parsed well. Otherwise, return NULL.
+ */
+static hs_client_service_authorization_t *
+get_creds_from_client_auth_filename(const char *filename,
+ const or_options_t *options)
+{
+ hs_client_service_authorization_t *auth = NULL;
+ char *client_key_file_path = NULL;
+ char *client_key_str = NULL;
+
+ log_info(LD_REND, "Loading a client authorization key file %s...",
+ filename);
+
+ if (!auth_key_filename_is_valid(filename)) {
+ log_notice(LD_REND, "Client authorization unrecognized filename %s. "
+ "File must end in .auth_private. Ignoring.",
+ filename);
+ goto err;
+ }
+
+ /* Create a full path for a file. */
+ client_key_file_path = hs_path_from_filename(options->ClientOnionAuthDir,
+ filename);
+
+ client_key_str = read_file_to_str(client_key_file_path, 0, NULL);
+ if (!client_key_str) {
+ log_warn(LD_REND, "The file %s cannot be read.", filename);
+ goto err;
+ }
+
+ auth = parse_auth_file_content(client_key_str);
+ if (!auth) {
+ goto err;
+ }
+
+ err:
+ tor_free(client_key_str);
+ tor_free(client_key_file_path);
+
+ return auth;
+}
+
/** Remove client auth credentials for the service <b>hs_address</b>. */
hs_client_removal_auth_status_t
hs_client_remove_auth_credentials(const char *hsaddress)
@@ -1958,8 +2002,6 @@ hs_config_client_authorization(const or_options_t *options,
int ret = -1;
digest256map_t *auths = digest256map_new();
smartlist_t *file_list = NULL;
- char *client_key_str = NULL;
- char *client_key_file_path = NULL;
tor_assert(options);
@@ -1982,37 +2024,11 @@ hs_config_client_authorization(const or_options_t *options,
goto end;
}
- SMARTLIST_FOREACH_BEGIN(file_list, char *, filename) {
-
+ SMARTLIST_FOREACH_BEGIN(file_list, const char *, filename) {
hs_client_service_authorization_t *auth = NULL;
ed25519_public_key_t identity_pk;
- log_info(LD_REND, "Loading a client authorization key file %s...",
- filename);
-
- if (!auth_key_filename_is_valid(filename)) {
- log_notice(LD_REND, "Client authorization unrecognized filename %s. "
- "File must end in .auth_private. Ignoring.",
- filename);
- continue;
- }
-
- /* Create a full path for a file. */
- client_key_file_path = hs_path_from_filename(options->ClientOnionAuthDir,
- filename);
- client_key_str = read_file_to_str(client_key_file_path, 0, NULL);
- /* Free the file path immediately after using it. */
- tor_free(client_key_file_path);
-
- /* If we cannot read the file, continue with the next file. */
- if (!client_key_str) {
- log_warn(LD_REND, "The file %s cannot be read.", filename);
- continue;
- }
-
- auth = parse_auth_file_content(client_key_str);
- /* Free immediately after using it. */
- tor_free(client_key_str);
+ auth = get_creds_from_client_auth_filename(filename, options);
if (!auth) {
continue;
}
@@ -2044,8 +2060,6 @@ hs_config_client_authorization(const or_options_t *options,
ret = 0;
end:
- tor_free(client_key_str);
- tor_free(client_key_file_path);
if (file_list) {
SMARTLIST_FOREACH(file_list, char *, s, tor_free(s));
smartlist_free(file_list);