Skip to content

Commit

Permalink
Correctly update 'regcount' and 'active' when a device is registered
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Snyman <git@jsnyman.com>
  • Loading branch information
stringlytyped committed Feb 15, 2024
1 parent 45a1362 commit 3c8f202
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion keylime/models/registrar/registrar_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@ def _prepare_iak_idevid(self):
def _prepare_status_flags(self):
self.virtual = self.ekcert == "virtual"

if ("ek_tpm", "ekcert", "aik_tpm", "iak_tpm", "idevid_tpm") in self.changes:
if any(field in ("ek_tpm", "ekcert", "aik_tpm", "iak_tpm", "idevid_tpm") for field in self.changes):
self.active = False

def _prepare_regcount(self):
if self.regcount == None:
self.regcount = 0

if any(field in ("ek_tpm", "ekcert", "aik_tpm", "iak_tpm", "idevid_tpm") for field in self.changes):
self.regcount += 1

def update(self, data):
# Bind key-value pairs ('data') to those fields which are meant to be externally changeable
self.cast_changes(
Expand All @@ -91,6 +98,8 @@ def update(self, data):
self._prepare_iak_idevid()
# Determine and set 'virtual' and 'active' flags
self._prepare_status_flags()
# Increment number of registrations
self._prepare_regcount()

# Validate values
self.validate_required(["ek_tpm", "aik_tpm"])
Expand Down
2 changes: 1 addition & 1 deletion keylime/web/registrar/agents_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def delete(self, agent_id, **params):
agent.delete()
self.respond(200, "Success")

# POST /v2[.:minor]/agents/:agent_id/activate/
# POST /v2[.:minor]/agents/:agent_id/[activate]
def activate(self, agent_id, auth_tag, **params):
agent = RegistrarAgent.get(agent_id)

Expand Down

0 comments on commit 3c8f202

Please sign in to comment.