Browse Source

print out the base58 encoding of an identity's public key so that

it can be loaded into the server to be authorized...
main
John-Mark Gurney 5 years ago
parent
commit
22ad754779
2 changed files with 22 additions and 1 deletions
  1. +21
    -1
      ui/cli.py
  2. +1
    -0
      ui/requirements.txt

+ 21
- 1
ui/cli.py View File

@@ -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):


+ 1
- 0
ui/requirements.txt View File

@@ -4,3 +4,4 @@ coverage
mock
klein
cryptography
base58

Loading…
Cancel
Save