@@ -28,11 +28,7 @@ def _debprint(*args): # pragma: no cover
#import pdb, sys; mypdb = pdb.Pdb(stdout=sys.stderr); mypdb.set_trace()
from cryptography.hazmat.primitives.asymmetric.ed448 import Ed448PrivateKey, \
Ed448PublicKey
from cryptography.hazmat.primitives.serialization import Encoding, \
PrivateFormat, PublicFormat, NoEncryption
from edgold.ed448 import EDDSA448
from unittest import mock
from .hostid import hostuuid
@@ -128,8 +124,7 @@ class Persona(object):
if 'pubkey' in self._identity:
pubkeybytes = self._identity.pubkey
self._pubkey = Ed448PublicKey.from_public_bytes(
pubkeybytes)
self._pubkey = EDDSA448(pub=pubkeybytes)
self._created_by_ref = self._identity.uuid
@@ -188,7 +183,7 @@ class Persona(object):
idobj = self._identity
pubstr = _asn1coder.dumps([ idobj.uuid, idobj.pubkey ])
return base58.b58encode_check(pubstr)
return base58.b58encode_check(pubstr).decode('ascii')
def new_version(self, *args):
'''Update the Persona's Identity object.'''
@@ -207,8 +202,7 @@ class Persona(object):
}
if self._key is not None:
obj['key'] = \
self._key.private_bytes(Encoding.Raw,
PrivateFormat.Raw, NoEncryption())
self._key.export_key('raw')
fp.write(_asn1coder.dumps(obj))
@@ -221,8 +215,7 @@ class Persona(object):
kwargs = {}
if 'key' in objs:
kwargs['key'] = Ed448PrivateKey.from_private_bytes(
objs['key'])
kwargs['key'] = EDDSA448(objs['key'])
return cls(Identity(objs['identity']), **kwargs)
@@ -234,10 +227,9 @@ class Persona(object):
if self._key:
raise RuntimeError('a key already exists')
self._key = Ed448PrivateKey .generate()
self._key = EDDSA448 .generate()
self._pubkey = self._key.public_key()
pubkey = self._pubkey.public_bytes(Encoding.Raw,
PublicFormat.Raw)
pubkey = self._pubkey.export_key('raw')
self._identity = self.sign(self._identity.new_version(('pubkey',
pubkey)))
@@ -264,8 +256,7 @@ class Persona(object):
def verify(self, obj):
sigbytes = self._makesigbytes(obj)
pubkey = self._pubkey.public_bytes(Encoding.Raw,
PublicFormat.Raw)
pubkey = self._pubkey.export_key('raw')
self._pubkey.verify(obj['sig'], sigbytes)
return True
@@ -872,7 +863,7 @@ def cmd_pubkey(options):
persona = Persona.load(identfname)
print(persona.get_pubkey().decode('ascii') )
print(persona.get_pubkey())
@init_datastructs
def cmd_modify(options, persona, objstr, cache):
@@ -1721,6 +1712,22 @@ class _TestCases(unittest.TestCase):
# that it does have a common property
self.assertIn('type', odict)
def test_cryptography_persona(self):
# Verify that a persona generated by cryptography still works
persona = Persona.load(self.fixtures / 'cryptography.persona.pasn1')
realpubkey = 'nFyLw6kB15DrM46ni9eEBRb6QD4rsPuco3ymj3mvz5YM8j3hY6chcjewU7FvqDpWALTSZ3E212SxCNErdYzPjgbxTnrYNyzeYTM2k58krEcKvWW6h'
pubkey = persona.get_pubkey()
self.assertEqual(realpubkey, pubkey)
vpersona = Persona.from_pubkey(realpubkey)
ident = persona.get_identity()
vpersona.verify(ident)
self.assertEqual(ident.uuid, uuid.UUID('52f1a92b-0c92-41e3-b647-356db89fb49c'))
def test_persona(self):
# that a newly created persona
persona = Persona()
@@ -1741,7 +1748,7 @@ class _TestCases(unittest.TestCase):
# that get_pubkey returns the correct thing
pubstr = _asn1coder.dumps([ idobj.uuid, idobj['pubkey'] ])
self.assertEqual(persona.get_pubkey(),
base58.b58encode_check(pubstr))
base58.b58encode_check(pubstr).decode('ascii') )
# and that there is a signature
self.assertIsInstance(idobj['sig'], bytes)