kopia lustrzana https://github.com/tsileo/little-boxes
Improve HTTP sig (for misskey)
rodzic
aa66280bb6
commit
ddb7261764
|
@ -127,6 +127,9 @@ class ActivityType(Enum):
|
||||||
# Used by Prismo
|
# Used by Prismo
|
||||||
PAGE = "Page"
|
PAGE = "Page"
|
||||||
|
|
||||||
|
# Misskey uses standalone Key object
|
||||||
|
KEY = "Key"
|
||||||
|
|
||||||
|
|
||||||
ACTOR_TYPES = [
|
ACTOR_TYPES = [
|
||||||
ActivityType.PERSON,
|
ActivityType.PERSON,
|
||||||
|
|
|
@ -17,6 +17,7 @@ from Crypto.Signature import PKCS1_v1_5
|
||||||
from requests.auth import AuthBase
|
from requests.auth import AuthBase
|
||||||
|
|
||||||
from .activitypub import get_backend
|
from .activitypub import get_backend
|
||||||
|
from .activitypub import _has_type
|
||||||
from .errors import ActivityNotFoundError
|
from .errors import ActivityNotFoundError
|
||||||
from .errors import ActivityGoneError
|
from .errors import ActivityGoneError
|
||||||
from .key import Key
|
from .key import Key
|
||||||
|
@ -63,11 +64,16 @@ def _body_digest(body: str) -> str:
|
||||||
|
|
||||||
def _get_public_key(key_id: str) -> Key:
|
def _get_public_key(key_id: str) -> Key:
|
||||||
actor = get_backend().fetch_iri(key_id)
|
actor = get_backend().fetch_iri(key_id)
|
||||||
k = Key(actor["id"], key_id)
|
if _has_type(actor["type"], "Key"):
|
||||||
k.load_pub(actor["publicKey"]["publicKeyPem"])
|
# 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
|
# Ensure the right key was fetch
|
||||||
if key_id != actor["publicKey"]["id"]:
|
if key_id != k.key_id():
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"failed to fetch requested key {key_id}: got {actor['publicKey']['id']}"
|
f"failed to fetch requested key {key_id}: got {actor['publicKey']['id']}"
|
||||||
)
|
)
|
||||||
|
|
Ładowanie…
Reference in New Issue