swicg / activitypub-http-signature

Repository for a SocialCG report on how HTTP Signature is used with ActivityPub
https://swicg.github.io/activitypub-http-signature/
11 stars 1 forks source link

2.3 algorithm should always check id==keyId, and should absolutize `publicKey.id` before this check #59

Open trwnh opened 5 days ago

trwnh commented 5 days ago

https://swicg.github.io/activitypub-http-signature/#how-to-obtain-a-signature-s-public-key

the way it's written, handling a key document in step 5 has you jumping back to step 2 with an actor id, and then step 4 skips ahead to step 7

what you want to be doing is verifying that the actor's publicKey includes an id matching the http-sig's keyId you started with, not to throw away the key in the interim

step 7 should make it clear that the key in publicKey may be referenced by id, and that you should either a) have this key in-memory while this algorithm is processing, or b) that you need to refetch it from cache (step 2) or from network (step 3, but you should already have it from your first pass of the algorithm...)

i understand what the intent is with the "go back and run this algorithm with an actor" bit, but as written it's inefficient.

there is also an implication in step 1 that you should be discarding url fragments, despite this being unnecessary and also needing the url fragment later on in step 7.

furthermore the id==keyId comparison needs to make sure that the publicKey.id is converted to an absolute URI first, since it could be relative or absolute


a more correct algorithm should be:

TallTed commented 3 days ago

@trwnh — Your suggested algorithm (including the sub-steps) would be better as an ordered list, than as the current unordered, as bullets should be executable in any order, which is not usually the case for an algorithm.

snarfed commented 3 days ago

This is great, thank you for the details @trwnh! And @TallTed, true, but @trwnh's algorithm is pretty clearly intended to be ordered in spirit, I think we can give them the benefit of the doubt here.

I'm all for resolving ambiguities here. Fragment handling is a good example, I can definitely change the language to clarify that you keep it for comparing against ids like in step 7.

I am a bit reluctant to make it quite this detailed and in the weeds though. This new algorithm reads more like pseudocode than prose, and I don't know if I want to go quite that far. It is an algorithm, agreed, but it's not a normative standard, and it leans heavily on existing standards and other established patterns like caching, array vs object handling, fetching objects by id if they're not inlined, etc.

Regardless, I'll take another pass at it and incorporate a lot of this. Thank you!

trwnh commented 2 days ago

yeah, the list is intended to be ordered but while typing it on my phone it was too inconvenient to use numbers. (also my pronouns are they/them :x)

re: taking another pass and incorporating stuff, i think the important bits are: