Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mastodon style relays #109

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TheNoim
Copy link

@TheNoim TheNoim commented Feb 15, 2025

In this PR I try to add mastodon style relays conforming to FEP-ae0c.

Todos

  • Testing with AodeRelay
  • Testing with FediBuzz
    • At the moment I simply lookup @[email protected], but this doesn't work for FediBuzz. Sadly the spec isn't clear how to get the relay server actor from the inbox url. Most relay softwares simply have @[email protected], but not softwares with custom inboxes for different feeds. Do we actually need the relay server actor? I may only added this, to fill out the id property of Recipient when calling sendActivity. Maybe the inbox url is enough?
  • Find more relay softwares to test
  • relay.toot.io not working. Implementation: https://github.com/yukimochi/Activity-Relay
    • fedify lookup https://relay.toot.io/actor -d ----> Failed to parse JSON-LD document: TypeError: Invalid PEM-SPKI format.
  • relay.intahnet.co.uk also not working
    • Failed to verify the request's HTTP Signatures and Failed to verify; key 'https://relay.intahnet.co.uk/actor' returned an invalid object.
    • fedify lookup https://relay.intahnet.co.uk/actor -d shows Failed to parse JSON-LD document: TypeError: Invalid PEM-SPKI format.
  • Consider disabled and enabled state for relays to temporary disable a relay. Mastodon has this feature.
  • How to fix the unwanted transformation from https://www.w3.org/ns/activitystreams#Public to as:public
  • Open issue of AodeRelay to support spec conform Unfollow https://git.asonix.dog/asonix/relay/issues/7
    • If you follow the spec, you can simply use the follow request id as object. But AodeRelay only accepts the full object.
  • oAuth2 screen shows relay actor
  • Make sure that we only forward activities ment to be forwarded to the relay
  • Add relays to docs
  • feat: add mastodon style relays #109 (comment)
  • Remove outbox messages after relay remove

* "id": "https://client.example/6ae15297",
* "type": "Follow",
* "actor": "https://client.example/actor",
* "object": "https://www.w3.org/ns/activitystreams#Public"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He the relay should actually understand both, as they're semantically the same, I'd file a bug with the relay implementation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this.

The object of the Follow request MUST be the fully expanded URI of the Public pseudo-collection (https://www.w3.org/ns/activitystreams#Public).

As far as I understand, but you can correct me:

  • https://www.w3.org/ns/activitystreams#Public fully expanded
  • as:public not fully expanded

Imagine building a new relay software: I would look at the spec and see that the object property should be equal to https://www.w3.org/ns/activitystreams#Public. So I would just check for this. This is why I think using https://www.w3.org/ns/activitystreams#Public would make it more compatible with more relay softwares. But at this point I only tested one software.

Copy link
Member

@dahlia dahlia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your amazing work, @TheNoim! I'm really looking forward to shipping this feature!

I left several review comments. Could you address them?

@ThisIsMissEm
Copy link
Contributor

Would probably also make sense to abstract out functions for determining "should this be relayed" and "forward this to a relay"

@TheNoim
Copy link
Author

TheNoim commented Feb 16, 2025

@dahlia can you look into the verify key issue? You can use https://relay2.bergsman.de/actor for testing.

@dahlia
Copy link
Member

dahlia commented Feb 17, 2025

@dahlia can you look into the verify key issue? You can use https://relay2.bergsman.de/actor for testing.

It seems that Fedify fails to parse its public key is because it's encoded in PEM-PKCS#1 whereas Fedify expects PEM-SPKI, which is much more common in the fediverse (as far as I know). Hmm… should Fedify accept PEM-PKCS#1 as well? 🤔

@TheNoim
Copy link
Author

TheNoim commented Feb 17, 2025

@dahlia can you look into the verify key issue? You can use https://relay2.bergsman.de/actor for testing.

It seems that Fedify fails to parse its public key is because it's encoded in PEM-PKCS#1 whereas Fedify expects PEM-SPKI, which is much more common in the fediverse (as far as I know). Hmm… should Fedify accept PEM-PKCS#1 as well? 🤔

I think, yes 🙃 As far as I know, it is not against the spec. Even though I think this is not the only issue with the tested relay software. But this would bring it one step further. I naively tried to patch fedify yesterday, but what I did was 100% wrong 🥲

@dahlia
Copy link
Member

dahlia commented Feb 18, 2025

Now Fedify accepts PEM-PKCS#1-encoded RSA public keys (besides PEM-SPKI-encoded ones), and it will be shipped in Fedify v1.5.0, the next minor release. Until then, you could give it a try Fedify v1.5.0-dev.654+b5166915, which is an unstable release.

@TheNoim
Copy link
Author

TheNoim commented Feb 19, 2025

The next issue I found. This is the http signature:

keyId="https://relay2.bergsman.de/actor",algorithm="rsa-sha256",headers="(request-target) host date digest content-type",signature="gavImwimAZcFMcLiCPhmg87I5n5fsAnBDSUNSaiPhnSvev5A0bgxaXnMlu2PL3kB1Ru5eWxAPiFEMPmoYicJZkN9sCgVd/CSEVCP3dnbeHH5HsT+G43MhHZcd3Ofg4xtO0yziXNQkwVoBhsN63iXSfxxqwipIKg5yp/3o3YDWUWKf6mGd/ykO95Dq5lpgQmd5WpRJ3udYggjITBtJ5bNA+kGWgWJxHq2NPixiEhQcwld1J3o7BW/5UjOS64lbP1/p2I3LAOCnLe8sBD4zj72NPdLaXLnSG4x3pfloLo4xAV5xJl4eScbfrzSNeWp+D2YiTr9tc5l3VQl4kZKP93aHg=="

The keyId is set to https://relay2.bergsman.de/actor. Fedify fetches the key from https://relay2.bergsman.de/actor, but will not find the key there. The key there has the id https://relay2.bergsman.de/actor#main-key which is obviously != https://relay2.bergsman.de/actor. See https://github.com/fedify-dev/fedify/blob/4eb092ee66e5b66a5760b8178b3e1272bb4c7abf/src/sig/key.ts#L330

I am not sure if this is also an incorrect behavior of fedify. https://swicg.github.io/activitypub-http-signature/#how-to-obtain-a-signature-s-public-key

If it has a fragment, discard it.

Maybe the spec is meant this way: Fetch the key from keyId. If keyId specifies a specific key, use it. Otherwise, use first.

Damn, activity pub is harder than I could have ever imagined 😁 Respect for implementing fedify.

@dahlia
Copy link
Member

dahlia commented Feb 20, 2025

I am not sure if this is also an incorrect behavior of fedify. https://swicg.github.io/activitypub-http-signature/#how-to-obtain-a-signature-s-public-key

If it has a fragment, discard it.

Maybe the spec is meant this way: Fetch the key from keyId. If keyId specifies a specific key, use it. Otherwise, use first.

Whether it is Fedify's fault or not, Fedify should behave as liberal as possible in accordance with the robustness principlebe conservative in what you do, be liberal in what you accept from others. So I just filed an issue: fedify-dev/fedify#211.

@dahlia
Copy link
Member

dahlia commented Feb 20, 2025

Fedify now does the best to find the appropriate public key. If there is no fragment in keyId and the actor has only one public key, it chooses that key. It will be shipped in Fedify 1.5.0, the next minor release, but you can try it with Fedify 1.5.0-dev.672+6a6ed659, an unstable release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants