Commit graph libervia-backend/sat/plugins/plugin_comp_ap_gateway
Author SHA1 Message Date
Goffi
f8387a7291 plugin AP gateway: fix exception on HEAD requests 2023-03-18 15:01:55 +01:00
Goffi
3994b8d40a component AP gateway (http/outbox): return data when no RSM is available 2023-03-16 15:56:11 +01:00
Goffi
4454753049 component AP gateway: reset stream position after getting payload:
the stream position needs to be reset, as the body may be read again to compute signature
hash.
2023-03-16 12:28:52 +01:00
Goffi
187369d1ca component AP gateway (http_server): use log.exception instead of log.error 2023-03-02 12:39:16 +01:00
Goffi
efb13e64b2 component AP gateway: fix missing argument when calling APOutboxPageRequest 2023-02-10 17:37:37 +01:00
Goffi
52f7a2b11f component AP gateway: don't percent-encode @:
Mastodon doesn't like when "@" is percent-encoded (because it doesn't do it, and it checks
that the URL matches the ID without taking care of percent-encoding).
2023-02-10 17:20:02 +01:00
Goffi
6459ef59bc component AP gateway: fix bad condition 2022-11-25 16:34:09 +01:00
Goffi
9560a23f78 component AP gateway: fix header checking for redirection 2022-11-25 16:14:10 +01:00
Goffi
faf5e43527 component AP gateway: ignore actor delection notifications:
When a `Delete` activity was received and the object was the emitting actor itself, the
signature checking was failing if the actor was unknown (due to the impossibility to
retrieve the actor public key, as it is no more accessible).

To avoid that, those notifications are ignored for now. In the future they should clean
the cache linked to this actor.
2022-11-15 18:15:16 +01:00
Goffi
b30a558f13 component AP gateway: properly close the HTTP connection on checkSignature exception:
if something is going wrong during `checkSignature` (other than signature verification
failing), a `500 Internal Server Error` code is returned, and the connection is properly
closed.
2022-11-15 18:10:33 +01:00
Goffi
4d14a623fc component AP gateway: parse body immediately on POST request:
the body is parsed immediately during a `POST` request: this avoids duplication of code,
and allows to check the body data before continuing (will be used to filter some requests
in a future patch).
2022-11-15 18:07:34 +01:00
Goffi
d6f710bd0b component AP gateway: fix pubsub attachment plugin call following renaming. 2022-11-15 18:03:07 +01:00
Goffi
c8326e24d2 component AP gateway: log at debug level instead of warning when no client is set 2022-11-15 18:02:16 +01:00
Goffi
020da52ddd component AP gateway: HTML redirection:
when a request is done on AP endpoint and `Accept` header is not set to
`application/json`, the request can now be redirected to a configurable URL.
2022-11-11 13:51:20 +01:00
Goffi
adea3770de component AP gateway: events:
- XMPP Events <=> AP Events conversion
- `Join`/`Leave` activities are converted to RSVP attachments and vice versa
- fix caching/notification on item published on a virtual pubsub node
- add Ad-Hoc command to convert XMPP Jid/Node to virtual AP Account
- handle `Update` activity
- on `convertAndPostItems`, `Update` activity is used instead of `Create` if a version of
  the item is already present in cache
- `events` field is added to actor data (and to `endpoints`), it links the `outbox` of the
  actor mapping the same JID with the Events node (i.e. it links to the Events node of the
  entity)
- fix subscription to nodes which are not the microblog one

rel 372
2022-09-22 00:01:41 +02:00
Goffi
5e3d4ca581 component AP gateway: AP <=> XMPP reactions conversions:
- Pubsub Attachments plugin has been renamed to XEP-0470 following publication
- XEP-0470 has been updated to follow 0.2 changes
- AP reactions (as implemented in Pleroma) are converted to XEP-0470
- XEP-0470 events are converted to AP reactions (again, using "EmojiReact" from Pleroma)
- AP activities related to attachments (like/reactions) are cached in Libervia because
  it's not possible to retrieve them from Pleroma instances once they have been emitted
  (doing an HTTP get on their ID returns a 404). For now those cache are not flushed, this
  should be improved in the future.
- `sharedInbox` is used when available. Pleroma returns a 500 HTTP error when ``to`` or
  ``cc`` are used in a direct inbox.
- reactions and like are not currently used for direct messages, because they can't be
  emitted from Pleroma in this case, thus there is no point in implementing them for the
  moment.

rel 371
2022-08-31 17:07:03 +02:00
Goffi
1f03f3ee14 component AP gateway: work around encoding bug in Mastodon:
Mastodon in wrongly unquoting URL path in `(request-target)`, and thus Libervia was doing
the same to check signature. However that doesn't work with Pleroma which is using the
path value used in the request (percent-encoded), and thus Pleroma signature were
rejected.

To work around that, signature is first checked without unquoting, and if this fails a new
check is done with unquoting.

Bug has been reported at https://github.com/mastodon/mastodon/issues/18871

rel 371
2022-08-31 17:07:03 +02:00
Goffi
30774ae9ad component AP gateway: fix headers case in signature:
headers where not lower-cased in `headers` field of signature data, resulting in signature
being rejected by Pleroma (but it was working with Mastodon).

Also add `Content-Type` header.


rel 371
2022-08-31 17:07:03 +02:00
Goffi
d8a55dbcba component AP gateway: add aliases to webfinger data 2022-08-31 17:07:03 +02:00
Goffi
eb797103e6 component AP gateway: better verbose logging:
gather data to show according to verbosity and log it all at once with a small `<<<` or
`>>>` indicating the direction. With a verbosity of 3, headers are also shown.
2022-08-31 17:07:03 +02:00
Goffi
c437424053 component AP gateway: raise exceptions on apGet + fix exceptions catching in apGetLocalObject:
new `exceptions.ExternalRequestError` is raised when request done `apGet` has a return
code >= 300.

Fix wrong exception catched in `apGetLocalObject`.
2022-08-31 17:07:01 +02:00
Goffi
2cee9c9519 component AP gateway: fix item ID for XMPP items on Announce:
if an Announced item is from XMPP, the AP id must be parsed to retrieve the XMPP original
ID.

rel 370
2022-07-22 15:42:59 +02:00
Goffi
9089a6494e component AP gateway: handle Like and Undo/Like activities:
rel 370
2022-07-21 18:07:35 +02:00
Goffi
a945d3cb67 component AP gateway (pubsub): only emit a Follow activity for microblog subscription:
this avoid to emit Follow subscription when an entity wants to subscribe to attachments
or other special nodes.

rel 370
2022-07-21 18:05:20 +02:00
Goffi
d841a51a1a component AP gateway: handle XMPP attachments -> AP likes conversion:
convert `noticed` attachments coming from XMPP to suitable `Like` activities. Virtual node
is created in cache when necessary, and virtual items published to virtual JID mapping AP
accounts are cached too.

rel 370
2022-07-20 17:53:12 +02:00
Goffi
51f786bc21 component AP gateway: when a repeated blog post is retracted, it converted to suitable Activity:
when a retract item is received, the former item is now retrieve from cache, and if it was
a "repeat" blog post, it is converted to the suitable `Undo` of `Announce` activity
(instead of the default `Delete` activity).

rel 370
2022-07-14 12:55:30 +02:00
Goffi
ee898b120d component AP gateway: "repeat" to "Announce" conversion:
when an XMPP blog post is marked as repeated, it is converted to an AP Announce activity

rel 370
2022-07-14 12:55:30 +02:00
Goffi
e73d4ebeff component AP gateway: fix wrong exception + use of mb_data["xml"] when it may be absent 2022-07-14 12:55:30 +02:00
Goffi
eb5b89d113 component AP gateway: we need to use actor and not attributedTo for activities:
`attributedTo` may not be filled, notably when the object is a string URL
2022-07-14 12:55:30 +02:00
Goffi
9a5801fedd component AP gateway: get items when not found in cache in apGetLocalObject:
rel 370
2022-07-14 12:55:30 +02:00
Goffi
9f6d69c75d component AP gateway: use the new priority argument of addManagedNode:
priority is needed because we'll need to inspect former items on retract to check the
Acitivy to use (it may be an `Undo` activity is some cases), and this must be done before
the cache is updated by pubsub cache plugin.

rel 370
2022-07-14 12:55:30 +02:00
Goffi
cd9d1d27e3 component AP gateway: new verbose attribute in AP gateway to activate debug logs:
when verbose is not null, object posted or returned on GET request are logged. Check
comments for vebosity level
2022-07-14 12:55:30 +02:00
Goffi
f4af47a929 component AP gateway: return item when item URL is used:
a request on an `item` type URL will return the suitable cached item.

rel 370
2022-07-14 12:55:30 +02:00
Goffi
7bd01dd06c component AP gateway: use createActivity in mbdata2APitem 2022-07-14 12:55:30 +02:00
Goffi
6e74e19c73 component AP gateway: Announce activity implementation:
`Announce` and `Undo` of `Announce` are now implemented and converted to suitable XEP-0277
"repeat" items, or retract.

rel 370
2022-07-14 12:55:30 +02:00
Goffi
575c3fe768 component AP gateway: getAPAccountFromId now works with local IDs:
rel 370
2022-07-14 12:55:30 +02:00
Goffi
fe4dc35f5c component AP gateway: apGetObject and apGetList now work with local object:
When a local item is linked, it is found from database instead of doing an HTTP request.

rel 370
2022-07-14 12:55:30 +02:00
Goffi
9e2f4571f6 component AP gateway: convert XMPP mentions to AP:
When a XEP-0372 mention is received, the linked pubsub item is looked after in cache, and
if found, it is send to mentioned entity with `mention` tag added.

However, this doesn't work in some cases (see incoming doc for details). To work around
that, `@user@server.tld` type mention are also scanned in body, and mentions are added
when found (this can be disabled with `auto_mentions` setting).

Mention are only scanned in "public" messages, i.e. for pubsub items, and not direct
messages.

rel 369
2022-07-10 16:15:06 +02:00
Goffi
2c654e017d component AP gateway: convert AP mention to XEP-0372 mentions:
when a mentions are found in AP items (either with people specified directly as target, of
with `mention` tags as in
https://www.w3.org/TR/activitystreams-vocabulary/#microsyntaxes), they are converted to
XEP-0372 `mention` references.

This is only done for Pubsub items (i.e. not for private messages).

rel 369
2022-07-10 15:16:15 +02:00
Goffi
a5381c8c86 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
rel 368
2022-06-29 14:06:33 +02:00
Goffi
68c627570d component AP: convert AP identity data to XMPP:
metadata are converted to vCard4 (XEP-0292).
Avatar is converted to User Avatar (XEP-0084), it is downloaded, resized, converted and
cached on first request.

If avatar is bigger than 5 Mio, it won't be used.

rel 368
2022-06-29 12:12:09 +02:00
Goffi
303e25f72e component AP: XMPP identity => AP actor data converstion:
XMPP identity data (coming from various XEPs, notably XEP-0292 (vCard4) and XEP-0084 (User
Avatar)) are now used to complete actor data.

Avatar files can now be delivered with the `avatar` type in URL.

rel 368
2022-06-29 12:06:21 +02:00
Goffi
c02dcf3d94 component AP gateway typing + remove unused activity arg from newAPDeleteItem
rel 367
2022-06-17 15:50:34 +02:00
Goffi
bfd9168449 component AP gateway: AP delete activity => message retract:
handle retractation of messages. As it is not possible to know from the AP item alone if
we need to to a message retractation (XEP-0424) or a pubsub retractation (XEP-0060), we
now cache sent message, and decide which method to use according to how the item is cached
(i.e. in message history or in pubsub cache).

rel 367
2022-06-17 14:15:23 +02:00
Goffi
8869b1b05d component AP gateway: message retractation => AP deletion
Convert XEP-0424 message retractation request to suitable AP delete activity.

The message workflow and its triggers are now used instead of a direct observer, as it is
now possible to do so with component, and this let other plugin to parse and eventually
update metadata.

rel 367
2022-06-17 14:15:23 +02:00
Goffi
7d3e66dc28 component AP gateway: set POST default response code to 202 (accepted) 2022-06-17 14:15:23 +02:00
Goffi
408dc04ee6 component AP gateway: convert Delete AP activities to corresponding Pubsub retract:
when a `Delete` actity is received, the item is removed from cache, and the corresponding
item `retract` is sent to local XMPP subscribers.

rel 367
2022-06-17 14:15:23 +02:00
Goffi
4e0c1fe7bf comp AP gateway: convert pubsub item retractation to AP Delete activity:
when an item `retract` is received from a node from which an AP actor is subscribed, a
corresponding `Delete` activity is created and sent to AP followers.

Trying to retract an item from a virtual node of the gateway pubsub service now return a
`forbidden` stanza error (those nodes are handled on AP side and thus are not owned by
XMPP entities).

rel 367
2022-06-17 14:15:23 +02:00
Goffi
fa81d96d79 comp AP gateway: message conversion:
Convert direct AP items to XMPP `<message>` stanzas, and vice versa.
Documentation will follow soon to explain the behaviour.

rel 366
2022-05-24 17:57:36 +02:00
Goffi
0114769fa4 comp AP gateway: publish, (un)subscribe/(un)follow, public subscription/following/followers:
this patch implements those major features:

- `publish` is implemented on virtual pubsub service, thus XMPP entities can now publish
  to AP using this service
- replies to XMPP items are managed
- `inReplyTo` is filled when converting XMPP items to AP objects
- `follow` and `unfollow` (actually an `undo` activity) are implemented and mapped to
  XMPP's (un)subscribe. On subscription, AP actor's `outbox` collection is converted to
  XMPP and put in cache. Subscriptions are always public.
- `following` and `followers` collections are mapped to XMPP's Public Pubsub Subscription
  (which should be XEP-0465, but the XEP is not yet published at the time of commit), in
  both directions.
- new helper methods to check if an URL is local and to get JID from actor ID

doc will follow to explain behaviour

rel 365
2022-05-13 19:12:33 +02:00