diff --git a/little_boxes/activitypub.py b/little_boxes/activitypub.py index a214da2..27e12cc 100644 --- a/little_boxes/activitypub.py +++ b/little_boxes/activitypub.py @@ -127,6 +127,9 @@ class ActivityType(Enum): # Used by Prismo PAGE = "Page" + # Misskey uses standalone Key object + KEY = "Key" + ACTOR_TYPES = [ ActivityType.PERSON, diff --git a/little_boxes/httpsig.py b/little_boxes/httpsig.py index b526371..86b244f 100644 --- a/little_boxes/httpsig.py +++ b/little_boxes/httpsig.py @@ -17,6 +17,7 @@ from Crypto.Signature import PKCS1_v1_5 from requests.auth import AuthBase from .activitypub import get_backend +from .activitypub import _has_type from .errors import ActivityNotFoundError from .errors import ActivityGoneError from .key import Key @@ -63,11 +64,16 @@ def _body_digest(body: str) -> str: def _get_public_key(key_id: str) -> Key: actor = get_backend().fetch_iri(key_id) - k = Key(actor["id"], key_id) - k.load_pub(actor["publicKey"]["publicKeyPem"]) + if _has_type(actor["type"], "Key"): + # The Key is not embedded in the Person + k = Key(actor["owner"], actor["id"]) + k.load_pub(actor["publicKeyPem"]) + else: + k = Key(actor["id"], actor["publicKey"]["id"]) + k.load_pub(actor["publicKey"]["publicKeyPem"]) # Ensure the right key was fetch - if key_id != actor["publicKey"]["id"]: + if key_id != k.key_id(): raise ValueError( f"failed to fetch requested key {key_id}: got {actor['publicKey']['id']}" )