Skip to content

Commit fe614ae

Browse files
committed
res_phreaknet: Reload keys prior to 'keys fetch' operation.
If keys have been removed from disk when a key reload occurs, then ast_key_get will return the key even though it no longer exists. Reload keys beforehand so that keys are processed as newly created keys rather than updated ones.
1 parent f0f8087 commit fe614ae

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

phreaknet.sh

+4-1
Original file line numberDiff line numberDiff line change
@@ -4185,7 +4185,10 @@ elif [ "$cmd" = "keygen" ]; then
41854185
else
41864186
printf "%s\n" "No InterLinked API key and/or CLLI on file, skipping upload of public key..."
41874187
fi
4188-
touch $AST_CONFIG_DIR/iax-phreaknet-rsa-in.conf
4188+
if [ ! -f $AST_CONFIG_DIR/iax-phreaknet-rsa-in.conf ]; then
4189+
# Instantiate the file with an empty 'inkeys' setting, so that any config modifications of iax.conf will put the keys there instead of in iax.conf
4190+
echo "inkeys = " > $AST_CONFIG_DIR/iax-phreaknet-rsa-in.conf
4191+
fi
41894192
# touch $AST_CONFIG_DIR/iax-phreaknet-rsa-out.conf # no longer necessary for >= 18.9
41904193
# Determine what user Asterisk is running as.
41914194
# cut on ; before = so that we properly handled commented out lines.

res/res_phreaknet.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ static struct ast_str *curl_get(const char *url, const char *data)
337337
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code);
338338
curl_easy_cleanup(curl);
339339

340-
ast_debug(3, "Response: %s\n", ast_str_buffer(str));
340+
ast_debug(5, "Response: %s\n", ast_str_buffer(str));
341341
if (http_code / 100 != 2) {
342342
ast_log(LOG_ERROR, "Failed to retrieve URL '%s': HTTP response code %ld\n", url, http_code);
343343
ast_free(str);
@@ -804,6 +804,12 @@ static int update_rsa_pubkeys(void)
804804
return -1;
805805
}
806806

807+
/* Reload keys before making the API request and calling ast_key_get to see if the key exists.
808+
* This way, if a key was removed manually since keys were last loaded,
809+
* ast_key_get will no longer return that the key exists,
810+
* and we'll process a key creation, rather than an update. */
811+
ast_module_reload("res_crypto");
812+
807813
ast_debug(1, "Synchronizing RSA public keys\n");
808814

809815
snprintf(url, sizeof(url), "https://api.phreaknet.org/v1/rsa?key=%s&fetchall&version=%s", interlinked_api_key, ast_get_version());
@@ -894,6 +900,7 @@ static int update_rsa_pubkeys(void)
894900
}
895901
fprintf(fp, "%s", key);
896902
fclose(fp);
903+
/* close() not needed here, fclose() will also close fd */
897904
unlink(tmp_filename);
898905

899906
/* XXX Future improvement would be to delete public keys that no longer exist (and remove from chan_iax2 config) */

0 commit comments

Comments
 (0)