Rotate a key into a new row, and list every closure (section 32.8 points 5 and 6)

This commit is contained in:
ai-bot committed 2026-10-24 10:37:25 +00:00
1 parent 76f33b04b0
commit f10db5e712
1 file changed
+43 -26
+43 -26
View File
@@ -45,6 +45,7 @@ from database import (
list_keys, list_keys,
list_previous_values, list_previous_values,
list_wallet_software, list_wallet_software,
rotate_key,
save_alert_acknowledgement, save_alert_acknowledgement,
save_app_settings, save_app_settings,
save_health_check, save_health_check,
@@ -171,12 +172,13 @@ def cloud_key_names(keys):
def closed_alerts(acknowledgements): def closed_alerts(acknowledgements):
"""Return the closures that belong to a key, ready for the history view. """Return the closures of one check, ready for the history view.
A closure is shown when it carries a key id: a rotation, a replaced hardware, Every closure is shown, whether it belongs to a key or to a software entry in
an updated contact, and an ignored alert whose source is a key. A closure of the settings list: a closure hangs on the check it closed through its
a software alert is left out, because it belongs to the settings list rather ``check_id``, so a rotation, a replaced hardware, an updated contact, an
than to the checked key (section 27). ignored key alert, and a software alert closed by removing it are all listed
with the action and the date (sections 27 and 32.8 point 6).
""" """
return [ return [
{ {
@@ -186,7 +188,6 @@ def closed_alerts(acknowledgements):
"acknowledged_at": entry["acknowledged_at"], "acknowledged_at": entry["acknowledged_at"],
} }
for entry in acknowledgements for entry in acknowledgements
if entry.get("key_id") is not None
] ]
@@ -694,7 +695,8 @@ class AppHandler(BaseHTTPRequestHandler):
key's identity, so it may only be changed while the key has no saved key's identity, so it may only be changed while the key has no saved
check, and it may never belong to another key (sections 25.1, 25.2, 26.2 check, and it may never belong to another key (sections 25.1, 25.2, 26.2
and 31.5). The type is never part of the payload, because only a rotation and 31.5). The type is never part of the payload, because only a rotation
replaces the key (section 28). replaces the key (section 28). This writes the active row in place, so it
is a rename; a rotation inserts a new row instead (section 32.8 point 5).
""" """
try: try:
payload = self._read_json_body() payload = self._read_json_body()
@@ -804,12 +806,16 @@ class AppHandler(BaseHTTPRequestHandler):
The rotation replaces the key, so it requires a new, unique address path: The rotation replaces the key, so it requires a new, unique address path:
the old path is refused, and no earlier check is changed (sections 26.2 the old path is refused, and no earlier check is changed (sections 26.2
and 26.3). The replacement may also carry the other type, because a and 26.3). The replacement is a **new row** for the same multisig slot
rotation is what replaces the key, and the type is part of its identity and the old row is retired, so the checks that were recorded for the old
(section 28). The model is a label, so it is written when the payload key keep the snapshot they carry and the history is frozen
carries one and the stored value is kept otherwise (section 31 point 5). (section 32.8 point 5). The replacement may also carry the other type,
The acknowledgement carries the key, so a rotation that changes the name because a rotation is what replaces the key, and the type is part of its
still keeps the closed alerts closed (section 27). identity (section 28). The model is a label, so it is written when the
payload carries one and the stored value is kept otherwise (section 31
point 5). The acknowledgements are written against the **old** key id,
the row the alerts and the checks they came from belong to, so a rotation
that changes the name still keeps the closed alerts closed (section 27).
""" """
try: try:
payload = self._read_json_body() payload = self._read_json_body()
@@ -840,7 +846,9 @@ class AppHandler(BaseHTTPRequestHandler):
# The model is only a label, so a rotation that does not mention it # The model is only a label, so a rotation that does not mention it
# keeps the stored one (section 31 point 5). # keeps the stored one (section 31 point 5).
model = rotation["model"] if "model" in payload else key.get("model") model = rotation["model"] if "model" in payload else key.get("model")
save_key_settings( # The rotation inserts a new active row and retires the old one, so
# the key the user sees gets a new id (section 32.8 point 5).
rotate_key(
key["id"], key["id"],
rotation["name"] or key["name"], rotation["name"] or key["name"],
rotation["address_path"], rotation["address_path"],
@@ -849,6 +857,8 @@ class AppHandler(BaseHTTPRequestHandler):
model=model, model=model,
) )
for code, source in targets: for code, source in targets:
# The closure belongs to the row the alert came from, which is
# the retired one, so it is written against the old key id.
save_alert_acknowledgement( save_alert_acknowledgement(
code, code,
source, source,
@@ -1024,25 +1034,30 @@ class AppHandler(BaseHTTPRequestHandler):
"""Return every saved check, newest first, with what needs follow-up. """Return every saved check, newest first, with what needs follow-up.
Each summary keeps the fields ``list_health_checks`` returns and adds two Each summary keeps the fields ``list_health_checks`` returns and adds two
of its own (section 32.2 point 14). ``key_names`` is the name each key of of its own (section 32.2 point 14). ``key_names`` is the name each key was
the check has now, in the same order as ``key_numbers``, so the history recorded with on that check, in the same order as ``key_numbers``: the
card can name the key. ``needs_follow_up`` says whether that check raised name is read from the snapshot the check carries, so a rotation or a
anything to follow up, read from the same alert rules the dashboard uses; rename cannot rewrite an older summary (section 32.8 point 5).
it is a property of the saved check itself, so it does not change when ``needs_follow_up`` says whether that check raised anything to follow up,
the user closes an alert later. Both fields are additive, so the existing read from the same alert rules the dashboard uses; it is a property of the
names and types are unchanged. saved check itself, so it does not change when the user closes an alert
later. Both fields are additive, so the existing names and types are
unchanged.
""" """
database_path = get_database_path() database_path = get_database_path()
try: try:
keys = list_keys(database_path) keys = list_keys(database_path)
names = {key["key_number"]: key["name"] for key in keys}
cloud_names = cloud_key_names(keys) cloud_names = cloud_key_names(keys)
summaries = list_health_checks(database_path) summaries = list_health_checks(database_path)
for summary in summaries: for summary in summaries:
record = get_health_check(summary["id"], database_path)
names = {
entry["key_number"]: entry["name"]
for entry in (record.get("key_checks") if record else None) or ()
}
summary["key_names"] = [ summary["key_names"] = [
names.get(number, "") for number in summary.get("key_numbers", []) names.get(number, "") for number in summary.get("key_numbers", [])
] ]
record = get_health_check(summary["id"], database_path)
summary["needs_follow_up"] = bool(record) and bool( summary["needs_follow_up"] = bool(record) and bool(
build_alerts(record, cloud_names) build_alerts(record, cloud_names)
) )
@@ -1109,9 +1124,11 @@ class AppHandler(BaseHTTPRequestHandler):
def _send_health_check(self, health_check_id): def _send_health_check(self, health_check_id):
"""Return one saved check with its related rows and the closures it has. """Return one saved check with its related rows and the closures it has.
A closure that belongs to a key is shown in the history, so the user can Every closure of the check is shown in the history, so the user can see
see what was closed on this check, with the action and the date what was closed on it, with the action and the date. A closure that
(section 27). belongs to a software entry in the settings list is listed as well, since
it hangs on the same check through its ``check_id``
(sections 27 and 32.8 point 6).
""" """
database_path = get_database_path() database_path = get_database_path()
try: try: