kopia lustrzana https://github.com/snarfed/bridgy-fed
rodzic
b4d5ab15ef
commit
ae25baba8c
|
@ -279,7 +279,6 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
||||||
# these can use urandom() and do nontrivial math, so they can take time
|
# these can use urandom() and do nontrivial math, so they can take time
|
||||||
# depending on the amount of randomness available and compute needed.
|
# depending on the amount of randomness available and compute needed.
|
||||||
if cls.LABEL != 'activitypub':
|
if cls.LABEL != 'activitypub':
|
||||||
# originally from django_salmon.magicsigs
|
|
||||||
key = RSA.generate(KEY_BITS, randfunc=random.randbytes if DEBUG else None)
|
key = RSA.generate(KEY_BITS, randfunc=random.randbytes if DEBUG else None)
|
||||||
user.mod = long_to_base64(key.n)
|
user.mod = long_to_base64(key.n)
|
||||||
user.public_exponent = long_to_base64(key.e)
|
user.public_exponent = long_to_base64(key.e)
|
||||||
|
@ -375,9 +374,6 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
||||||
"""Returns handle if we know it, otherwise id."""
|
"""Returns handle if we know it, otherwise id."""
|
||||||
return self.handle or self.key.id()
|
return self.handle or self.key.id()
|
||||||
|
|
||||||
def href(self):
|
|
||||||
return f'data:application/magic-public-key,RSA.{self.mod}.{self.public_exponent}'
|
|
||||||
|
|
||||||
def public_pem(self):
|
def public_pem(self):
|
||||||
"""Returns: bytes"""
|
"""Returns: bytes"""
|
||||||
rsa = RSA.construct((base64_to_long(str(self.mod)),
|
rsa = RSA.construct((base64_to_long(str(self.mod)),
|
||||||
|
|
|
@ -104,12 +104,6 @@ class UserTest(TestCase):
|
||||||
|
|
||||||
self.assertEqual('y.z', Fake.get_or_create('a.b').key.id())
|
self.assertEqual('y.z', Fake.get_or_create('a.b').key.id())
|
||||||
|
|
||||||
def test_href(self):
|
|
||||||
href = g.user.href()
|
|
||||||
self.assertTrue(href.startswith('data:application/magic-public-key,RSA.'), href)
|
|
||||||
self.assertIn(g.user.mod, href)
|
|
||||||
self.assertIn(g.user.public_exponent, href)
|
|
||||||
|
|
||||||
def test_public_pem(self):
|
def test_public_pem(self):
|
||||||
pem = g.user.public_pem()
|
pem = g.user.public_pem()
|
||||||
self.assertTrue(pem.decode().startswith('-----BEGIN PUBLIC KEY-----\n'), pem)
|
self.assertTrue(pem.decode().startswith('-----BEGIN PUBLIC KEY-----\n'), pem)
|
||||||
|
|
Ładowanie…
Reference in New Issue