|
@@ -7,6 +7,7 @@ from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey, \ |
|
|
from cryptography.hazmat.primitives.serialization import Encoding, \ |
|
|
from cryptography.hazmat.primitives.serialization import Encoding, \ |
|
|
PrivateFormat, PublicFormat, NoEncryption |
|
|
PrivateFormat, PublicFormat, NoEncryption |
|
|
|
|
|
|
|
|
|
|
|
import base58 |
|
|
import copy |
|
|
import copy |
|
|
import datetime |
|
|
import datetime |
|
|
import hashlib |
|
|
import hashlib |
|
@@ -479,13 +480,15 @@ def main(): |
|
|
default=False, help='update the identity') |
|
|
default=False, help='update the identity') |
|
|
parser.add_option('-l', action='store_true', dest='list', |
|
|
parser.add_option('-l', action='store_true', dest='list', |
|
|
default=False, help='list metadata') |
|
|
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() |
|
|
options, args = parser.parse_args() |
|
|
|
|
|
|
|
|
# this is shared between generateident and add |
|
|
# this is shared between generateident and add |
|
|
addprops = map(lambda x: x.split('=', 1), options.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') |
|
|
identfname = os.path.expanduser('~/.medashare_identity.pasn1') |
|
|
|
|
|
|
|
|
if options.generateident and os.path.exists(identfname): |
|
|
if options.generateident and os.path.exists(identfname): |
|
@@ -498,6 +501,10 @@ def main(): |
|
|
else: |
|
|
else: |
|
|
persona = Persona.load(identfname) |
|
|
persona = Persona.load(identfname) |
|
|
|
|
|
|
|
|
|
|
|
if options.printpub: |
|
|
|
|
|
print base58.b58encode_check(persona.get_identity().pubkey) |
|
|
|
|
|
return |
|
|
|
|
|
|
|
|
persona.new_version(*addprops) |
|
|
persona.new_version(*addprops) |
|
|
persona.store(identfname) |
|
|
persona.store(identfname) |
|
|
return |
|
|
return |
|
@@ -902,6 +909,19 @@ class _TestCases(unittest.TestCase): |
|
|
# and that the old Persona can verify the new one |
|
|
# and that the old Persona can verify the new one |
|
|
self.assertTrue(persona.verify(nident)) |
|
|
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', |
|
|
with nested(mock.patch('sys.stdout', |
|
|
StringIO.StringIO()), mock.patch('sys.argv', |
|
|
StringIO.StringIO()), mock.patch('sys.argv', |
|
|
[ 'progname', '-l', testfname ])) as (stdout, argv): |
|
|
[ 'progname', '-l', testfname ])) as (stdout, argv): |
|
|