Skip to content

Commit 3da7058

Browse files
committed
Include UNF URL in server_show_public_settings
1 parent 25f6624 commit 3da7058

File tree

6 files changed

+22
-12
lines changed

6 files changed

+22
-12
lines changed

irrd/mirroring/nrtm4/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
UPDATE_NOTIFICATION_FILENAME = "update-notification-file.jose"

irrd/mirroring/nrtm4/nrtm4_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from ...utils.process_support import get_lockfile
2929
from ..retrieval import file_hash_sha256
30+
from . import UPDATE_NOTIFICATION_FILENAME
3031
from .jsonseq import jsonseq_encode, jsonseq_encode_one
3132
from .nrtm4_types import (
3233
NRTM4DeltaHeader,
@@ -250,7 +251,7 @@ def _write_unf(self) -> None:
250251
private_key = eckey_from_config(f"sources.{self.source}.nrtm4_server_private_key")
251252
assert private_key
252253
unf_serialized = jws_serialize(unf_content, private_key)
253-
with open(self.path / "update-notification-file.json", "w") as unf_file:
254+
with open(self.path / UPDATE_NOTIFICATION_FILENAME, "w") as unf_file:
254255
unf_file.write(unf_serialized)
255256
self.status.last_update_notification_file_update = unf.timestamp
256257

irrd/mirroring/nrtm4/tests/test_nrtm4_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
from joserfc import jws
77

8+
from irrd.mirroring.nrtm4 import UPDATE_NOTIFICATION_FILENAME
89
from irrd.mirroring.nrtm4.jsonseq import jsonseq_encode
910
from irrd.mirroring.nrtm4.nrtm4_client import NRTM4Client, NRTM4ClientError
1011
from irrd.mirroring.nrtm4.tests import (
@@ -21,8 +22,7 @@
2122
MOCK_SNAPSHOT_URL = "https://example.com/snapshot.2.json"
2223
MOCK_DELTA3_URL = "https://example.com/delta.3.json"
2324
MOCK_DELTA4_URL = "https://example.com/delta.4.json"
24-
MOCK_UNF_URL = "https://example.com/update-notification-file.json"
25-
MOCK_UNF_SIG_URL = "https://example.com/update-notification-file-signature-hash.json"
25+
MOCK_UNF_URL = "https://example.com/" + UPDATE_NOTIFICATION_FILENAME
2626

2727
MOCK_UNF = {
2828
"nrtm_version": 4,

irrd/mirroring/nrtm4/tests/test_nrtm4_server.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unittest.mock import create_autospec
88

99
from irrd.conf import NRTM4_SERVER_DELTA_EXPIRY_TIME, PASSWORD_HASH_DUMMY_VALUE
10+
from irrd.mirroring.nrtm4 import UPDATE_NOTIFICATION_FILENAME
1011
from irrd.mirroring.nrtm4.jsonseq import jsonseq_decode
1112
from irrd.mirroring.nrtm4.nrtm4_server import NRTM4Server, NRTM4ServerWriter
1213
from irrd.mirroring.nrtm4.tests import MOCK_UNF_PRIVATE_KEY, MOCK_UNF_PRIVATE_KEY_STR
@@ -74,8 +75,7 @@ def test_nrtm4_server(self, tmpdir, config_override):
7475

7576
delta_dangling_path = nrtm_path / "nrtm-delta.aaaaa.json.gz"
7677
snapshot_outdated_path = nrtm_path / "nrtm-snapshot.aaaaa.json.gz"
77-
unf_signature_outdated_path = nrtm_path / "update-notification-file-signature-aaaaa.sig"
78-
for path in delta_dangling_path, snapshot_outdated_path, unf_signature_outdated_path:
78+
for path in delta_dangling_path, snapshot_outdated_path:
7979
path.touch()
8080
os.utime(path, (time.time() - 3600, time.time() - 3600))
8181

@@ -249,7 +249,7 @@ def test_nrtm4_server(self, tmpdir, config_override):
249249
assert not mock_dh.other_calls
250250

251251
def _load_unf(self, nrtm_path):
252-
with open(nrtm_path / "update-notification-file.json", "rb") as f:
252+
with open(nrtm_path / UPDATE_NOTIFICATION_FILENAME, "rb") as f:
253253
unf_content = f.read()
254254
unf_payload = jws_deserialize(unf_content, MOCK_UNF_PRIVATE_KEY)
255255
unf = json.loads(unf_payload.payload)

irrd/scripts/irrd_control.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import click
1010
from joserfc.rfc7518.ec_key import ECKey
1111

12+
from irrd.mirroring.nrtm4 import UPDATE_NOTIFICATION_FILENAME
1213
from irrd.utils.crypto import (
1314
eckey_from_config,
1415
eckey_private_key_as_str,
@@ -192,17 +193,23 @@ def generate_private_key():
192193

193194
@nrtm4.command()
194195
@click.argument("source")
195-
def server_show_public_key(source: str):
196+
def server_show_public_settings(source: str):
196197
"""
197-
Show the public key(s) matching the currently configured private keys.
198+
Show the public parameters matching the current configuration for an NRTMv4 server.
198199
"""
199200
private_key = eckey_from_config(f"sources.{source}.nrtm4_server_private_key", permit_empty=True)
200201
if not private_key:
201202
raise click.ClickException(f"Source {source} is not configured as an NRTMv4 server")
202203
public_key_str = eckey_public_key_as_str(private_key)
204+
unf_url = (
205+
get_setting(f"sources.{source}.nrtm4_server_base_url").rstrip("/")
206+
+ "/"
207+
+ UPDATE_NOTIFICATION_FILENAME
208+
)
203209

204210
click.echo(
205-
f"Source {source} NRTMv4 server public keys (base64):\n"
211+
f"Settings for {source} NRTMv4 server:\n"
212+
f"Update Notification File URL: {unf_url}\n"
206213
f"Current public key (from nrtm4_server_private_key):\n{public_key_str}\n"
207214
)
208215

irrd/scripts/tests/test_irrd_control.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
cli,
77
client_clear_known_keys,
88
generate_private_key,
9-
server_show_public_key,
9+
server_show_public_settings,
1010
user_change_override,
1111
user_mfa_clear,
1212
)
@@ -240,17 +240,18 @@ def test_valid(self, config_override):
240240
"TEST": {
241241
"nrtm4_server_private_key": private_key_str,
242242
"nrtm4_server_private_key_next": private_key_str,
243+
"nrtm4_server_base_url": "https://url/",
243244
}
244245
}
245246
}
246247
)
247248
runner = CliRunner()
248-
result = runner.invoke(server_show_public_key, args=["TEST"])
249+
result = runner.invoke(server_show_public_settings, args=["TEST"])
249250
assert result.exit_code == 0
250251
assert public_key_str in result.output
251252

252253
def test_not_configured(self):
253254
runner = CliRunner()
254-
result = runner.invoke(server_show_public_key, args=["TEST"])
255+
result = runner.invoke(server_show_public_settings, args=["TEST"])
255256
assert result.exit_code == 1, result.output
256257
assert "not configured as an NRTMv4 server" in result.output

0 commit comments

Comments
 (0)