From 388843f772a20ced7efea7e1019fdc9413e52f78 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 6 Jan 2020 16:03:56 +0100 Subject: [PATCH] core/tools: make keyctl-proxy output nicer --- core/tools/keyctl-proxy | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/core/tools/keyctl-proxy b/core/tools/keyctl-proxy index 05cf02f36..5b49ba858 100755 --- a/core/tools/keyctl-proxy +++ b/core/tools/keyctl-proxy @@ -28,7 +28,7 @@ indexmap = { PATH = "10018h/{}h" -def make_commit(index, digest): +def make_commit(name, index, digest): path = PATH.format(index) address_n = parse_path(path) first_pass = True @@ -39,13 +39,20 @@ def make_commit(index, digest): t.clear_session() first_pass = False - click.echo(f"\n\n\nCommiting to hash {digest.hex()} with path {path}") + click.echo(f"\n\n\nCommiting to {click.style(name, bold=True)} hash:") + for partid in range(4): + digest_part = digest[partid * 8 : (partid + 1) * 8] + color = "red" if partid % 2 else "blue" + digest_str = click.style(digest_part.hex().upper(), fg=color) + click.echo(digest_str) + + click.echo(f"Using path: {click.style(path, bold=True)}") commit = cosi.commit(t, address_n, digest) return commit.pubkey, commit.commitment except Exception as e: - print(e) + click.echo(e) traceback.print_exc() - print("Trying again ...") + click.echo("Trying again ...") @Pyro4.expose @@ -58,13 +65,13 @@ class KeyctlProxy: def _check_name_digest(self, name, digest): if name != self.name or digest != self.digest: - print(f"ERROR! Remote wants to sign {name} with digest {digest.hex()}") - print(f"Expected: {self.name} with digest {self.digest.hex()}") + click.echo(f"ERROR! Remote wants to sign {name} with digest {digest.hex()}") + click.echo(f"Expected: {self.name} with digest {self.digest.hex()}") raise ValueError("Unexpected index/digest") def get_commit(self, name, digest): self._check_name_digest(name, digest) - print("Sending commitment!") + click.echo("Sending commitment!") return self.commit def get_signature(self, name, digest, global_R, global_pk): @@ -72,14 +79,14 @@ class KeyctlProxy: while True: try: t = get_default_client() - print("\n\n\nSigning...") + click.echo("\n\n\nSigning...") signature = cosi.sign(t, self.address_n, digest, global_R, global_pk) - print("Sending signature!") + click.echo("Sending signature!") return signature.signature except Exception as e: - print(e) + click.echo(e) traceback.print_exc() - print("Trying again ...") + click.echo("Trying again ...") @click.command()