From 22ad754779170fbed162d3bd0ed8f1ddfd947fec Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Sun, 8 Sep 2019 22:52:08 -0700 Subject: [PATCH] print out the base58 encoding of an identity's public key so that it can be loaded into the server to be authorized... --- ui/cli.py | 22 +++++++++++++++++++++- ui/requirements.txt | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ui/cli.py b/ui/cli.py index b0cb4eb..1fc6962 100644 --- a/ui/cli.py +++ b/ui/cli.py @@ -7,6 +7,7 @@ from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey, \ from cryptography.hazmat.primitives.serialization import Encoding, \ PrivateFormat, PublicFormat, NoEncryption +import base58 import copy import datetime import hashlib @@ -479,13 +480,15 @@ def main(): default=False, help='update the identity') parser.add_option('-l', action='store_true', dest='list', default=False, help='list metadata') + parser.add_option('-p', action='store_true', dest='printpub', + default=False, help='Print the public key of the identity') options, args = parser.parse_args() # this is shared between generateident and add addprops = map(lambda x: x.split('=', 1), options.add) - if options.generateident or options.updateident: + if options.generateident or options.updateident or options.printpub: identfname = os.path.expanduser('~/.medashare_identity.pasn1') if options.generateident and os.path.exists(identfname): @@ -498,6 +501,10 @@ def main(): else: persona = Persona.load(identfname) + if options.printpub: + print base58.b58encode_check(persona.get_identity().pubkey) + return + persona.new_version(*addprops) persona.store(identfname) return @@ -902,6 +909,19 @@ class _TestCases(unittest.TestCase): # and that the old Persona can verify the new one self.assertTrue(persona.verify(nident)) + # that when asked to print the public key + with nested(mock.patch('sys.stdout', + StringIO.StringIO()), mock.patch('sys.argv', + [ 'progname', '-p' ])) as (stdout, argv): + main() + + # the correct key is printed + self.assertEqual(stdout.getvalue(), + '%s\n' % base58.b58encode_check(pident.pubkey)) + + # and looked up the correct file + eu.assert_called_with('~/.medashare_identity.pasn1') + with nested(mock.patch('sys.stdout', StringIO.StringIO()), mock.patch('sys.argv', [ 'progname', '-l', testfname ])) as (stdout, argv): diff --git a/ui/requirements.txt b/ui/requirements.txt index eedeccc..81ca6d5 100644 --- a/ui/requirements.txt +++ b/ui/requirements.txt @@ -4,3 +4,4 @@ coverage mock klein cryptography +base58