Commit graph

39 commits

Author SHA1 Message Date
f133e9ca11
Implement sending follow activities
I moved around a lot of files to fix import cycles
2022-10-21 21:06:59 +00:00
f9d9019720
Fix Comment permission checking 2022-09-23 17:30:44 +00:00
117463ba78
Change Ta180m/activitypub to xy/activitypub 2022-09-16 08:38:55 -05:00
f0269889c0
Fix build errors 2022-09-05 16:37:56 -05:00
73284dbf0b
Add authorize_interaction case for Tickets 2022-08-22 12:29:16 -05:00
ee85f7d957
Use the Repository AttributedTo to get owner IRI 2022-08-22 12:09:26 -05:00
Gusted
819e495dc0
Make gofmt happy 2022-08-22 18:48:17 +02:00
b3c065ce80
Refactor RepoInbox to use On functions instead of type assertions 2022-08-21 10:22:42 -05:00
27cda2fcd4
Implement JSONLoad, To, and On functions for ForgeFed types 2022-08-20 23:07:11 -05:00
6a6c6b3481
Merge remote-tracking branch 'upstream/main' 2022-08-19 17:46:12 -05:00
Lunny Xiao
86c85c19b6
Refactor AssertExistsAndLoadBean to use generics (#20797)
* Refactor AssertExistsAndLoadBean to use generics

* Fix tests

Co-authored-by: zeripath <art27@cantab.net>
2022-08-16 10:22:25 +08:00
6b73c097ed
Download avatar from URL and set it with user_service.UploadAvatar 2022-08-15 12:00:14 -05:00
0b97c6aa69
Cache remote user public keys 2022-08-15 11:14:48 -05:00
71b2b4d815
Implement FederatedRepoNew 2022-07-27 14:43:01 -05:00
c94a891aad
Process Like activities for starring repos 2022-07-27 14:18:30 -05:00
d909c97da9
Move models/forgefed to modules/forgefed 2022-07-27 10:25:40 -05:00
f0cded88bf
Start cleaning up fork.go 2022-07-27 10:24:04 -05:00
38a687c60e
Replace GetID() with GetLink()
See https://lists.sr.ht/~mariusor/activitypub-go/%3CNXRUnlucUSX8FL9I57dimPx4dpMKz01JDjKXqeHC8V9Z7pSTnjoZyV8ukearYJOq4IDogmpDLoEK-ScPDKs_egPnFGcAAO4XqHbj2rTUm-E%3D%40proton.me%3E for more details
2022-07-25 15:45:15 -05:00
30b431da49
Set ap.ItemTyperFunc to correctly unmarshal JSON 2022-07-25 15:43:20 -05:00
bffb682117
Fix a bunch of lint errors (still 10 more to fix 🙁) 2022-07-23 22:12:09 -05:00
ab540d07be
Create new federated users in reqsignature.go 2022-07-23 21:27:20 -05:00
763f98b517
Create user at /authorize_interaction?uri= endpoint 2022-07-23 16:34:06 -05:00
85abd9cfe0
Fix typo in follow.go 2022-07-21 20:07:17 -05:00
c8a8e1ec91
Check err in Follow() to avoid crash and don't check FederatedUserNew error 2022-07-20 18:16:49 -05:00
0925235a96
Fix federated following/unfollowing regression 2022-07-20 14:42:39 -05:00
c100b8e1e0
Apply suggestions from code review 2022-07-17 11:19:48 -05:00
0609d7175c
Add more TODO notes 2022-07-13 22:11:24 -05:00
56717396fd
Big refactor: Improve inbox handling logic, move some IRI stuff to iri.go 2022-07-13 22:10:03 -05:00
63aa270a2e
Initial implementation of federated pull requests 2022-07-13 12:14:14 -05:00
1b39e39fc1
Add basic implementation of federated commenting 2022-07-11 18:24:15 -05:00
79a59bd75b
Use a replace in go.mod to point to Ta180m/activitypub fork instead of modifying the include everywhere 2022-07-11 17:27:57 -05:00
d016dbbe70
Switch to using gitea.com/Ta180m/activitypub fork of the go-ap/activitypub module since we need more Write and Load functions exported 2022-07-11 12:45:00 -05:00
fa72294f64
Fix build errors and start working on constructing outbox activities for the various action types 2022-07-07 13:11:59 -05:00
786ee03f57
Merge remote-tracking branch 'upstream/main' 2022-06-25 21:41:59 -05:00
Wim
cb50375e2b
Add more linters to improve code readability (#19989)
Add nakedret, unconvert, wastedassign, stylecheck and nolintlint linters to improve code readability

- nakedret - https://github.com/alexkohler/nakedret - nakedret is a Go static analysis tool to find naked returns in functions greater than a specified function length.
- unconvert - https://github.com/mdempsky/unconvert - Remove unnecessary type conversions
- wastedassign - https://github.com/sanposhiho/wastedassign -  wastedassign finds wasted assignment statements.
- notlintlint -  Reports ill-formed or insufficient nolint directives
- stylecheck - https://staticcheck.io/docs/checks/#ST - keep style consistent
  - excluded: [ST1003 - Poorly chosen identifier](https://staticcheck.io/docs/checks/#ST1003) and [ST1005 - Incorrectly formatted error string](https://staticcheck.io/docs/checks/#ST1005)
2022-06-20 12:02:49 +02:00
d12fd434ba
Add Person and Repository ActivityPub endpoints 2022-06-19 10:39:22 -05:00
e86f18a05a
User keypairs and HTTP signatures for ActivityPub federation using go-ap (#19133)
* go.mod: add go-fed/{httpsig,activity/pub,activity/streams} dependency

go get github.com/go-fed/activity/streams@master
go get github.com/go-fed/activity/pub@master
go get github.com/go-fed/httpsig@master

* activitypub: implement /api/v1/activitypub/user/{username} (#14186)

Return informations regarding a Person (as defined in ActivityStreams
https://www.w3.org/TR/activitystreams-vocabulary/#dfn-person).

Refs: https://github.com/go-gitea/gitea/issues/14186

Signed-off-by: Loïc Dachary <loic@dachary.org>

* activitypub: add the public key to Person (#14186)

Refs: https://github.com/go-gitea/gitea/issues/14186

Signed-off-by: Loïc Dachary <loic@dachary.org>

* activitypub: go-fed conformant Clock instance

Signed-off-by: Loïc Dachary <loic@dachary.org>

* activitypub: signing http client

Signed-off-by: Loïc Dachary <loic@dachary.org>

* activitypub: implement the ReqSignature middleware

Signed-off-by: Loïc Dachary <loic@dachary.org>

* activitypub: hack_16834

Signed-off-by: Loïc Dachary <loic@dachary.org>

* Fix CI checks-backend errors with go mod tidy

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Change 2021 to 2022, properly format package imports

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Run make fmt and make generate-swagger

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Use Gitea JSON library, add assert for pkp

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Run make fmt again, fix err var redeclaration

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Remove LogSQL from ActivityPub person test

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Assert if json.Unmarshal succeeds

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Cleanup, handle invalid usernames for ActivityPub person GET request

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Rename hack_16834 to user_settings

Signed-off-by: Anthony Wang <ta180m@pm.me>

* Use the httplib module instead of http for GET requests

* Clean up whitespace with make fmt

* Use time.RFC1123 and make the http.Client proxy-aware

* Check if digest algo is supported in setting module

* Clean up some variable declarations

* Remove unneeded copy

* Use system timezone instead of setting.DefaultUILocation

* Use named constant for httpsigExpirationTime

* Make pubKey IRI #main-key instead of /#main-key

* Move /#main-key to #main-key in tests

* Implemented Webfinger endpoint.

* Add visible check.

* Add user profile as alias.

* Add actor IRI and remote interaction URL to WebFinger response

* fmt

* Fix lint errors

* Use go-ap instead of go-fed

* Run go mod tidy to fix missing modules in go.mod and go.sum

* make fmt

* Convert remaining code to go-ap

* Clean up go.sum

* Fix JSON unmarshall error

* Fix CI errors by adding @context to Person() and making sure types match

* Correctly decode JSON in api_activitypub_person_test.go

* Force CI rerun

* Fix TestActivityPubPersonInbox segfault

* Fix lint error

* Use @mariusor's suggestions for idiomatic go-ap usage

* Correctly add inbox/outbox IRIs to person

* Code cleanup

* Remove another LogSQL from ActivityPub person test

* Move httpsig algos slice to an init() function

* Add actor IRI and remote interaction URL to WebFinger response

* Update TestWebFinger to check for ActivityPub IRI in aliases

* make fmt

* Force CI rerun

* WebFinger: Add CORS header and fix Href -> Template for remote interactions

The CORS header is needed due to https://datatracker.ietf.org/doc/html/rfc7033#section-5 and fixes some Peertube <-> Gitea federation issues

* make lint-backend

* Make sure Person endpoint has Content-Type application/activity+json and includes PreferredUsername, URL, and Icon

Setting the correct Content-Type is essential for federating with Mastodon

* Use UTC instead of GMT

* Rename pkey to pubKey

* Make sure HTTP request Date in GMT

* make fmt

* dont drop err

* Make sure API responses always refer to username in original case

Copied from what I wrote on #19133 discussion: Handling username case is a very tricky issue and I've already encountered a Mastodon <-> Gitea federation bug due to Gitea considering Ta180m and ta180m to be the same user while Mastodon thinks they are two different users. I think the best way forward is for Gitea to only use the original case version of the username for federation so other AP software don't get confused.

* Move httpsig algs constant slice to modules/setting/federation.go

* Add new federation settings to app.example.ini and config-cheat-sheet

* Return if marshalling error

* Make sure Person IRIs are generated correctly

This commit ensures that if the setting.AppURL is something like "http://127.0.0.1:42567" (like in the integration tests), a trailing slash will be added after that URL.

* If httpsig verification fails, fix Host header and try again

This fixes a very rare bug when Gitea and another AP server (confirmed to happen with Mastodon) are running on the same machine, Gitea fails to verify incoming HTTP signatures. This is because the other AP server creates the sig with the public Gitea domain as the Host. However, when Gitea receives the request, the Host header is instead localhost, so the signature verification fails. Manually changing the host header to the correct value and trying the veification again fixes the bug.


* Revert "If httpsig verification fails, fix Host header and try again"

This reverts commit f53e46c721.

The bug was actually caused by nginx messing up the Host header when reverse-proxying since I didn't have the line `proxy_set_header Host $host;` in my nginx config for Gitea.

* Go back to using ap.IRI to generate inbox and outbox IRIs

* use const for key values

* Update routers/web/webfinger.go

* Use ctx.JSON in Person response to make code cleaner

* Revert "Use ctx.JSON in Person response to make code cleaner"

This doesn't work because the ctx.JSON() function already sends the response out and it's too late to edit the headers.

This reverts commit 95aad98897.

* Use activitypub.ActivityStreamsContentType for Person response Content Type

* Limit maximum ActivityPub request and response sizes to a configurable setting

* Move setting key constants to models/user/setting_keys.go

* Fix failing ActivityPubPerson integration test by checking the correct field for username

* Add a warning about changing settings that can break federation

* Add better comments

* Don't multiply Federation.MaxSize by 1<<20 twice

* Add more better comments

* Fix failing ActivityPubMissingPerson test

We now use ctx.ContextUser so the message printed out when a user does not exist is slightly different

* make generate-swagger

For some reason I didn't realize that /templates/swagger/v1_json.tmpl was machine-generated by make generate-swagger... I've been editing it by hand for three months! 🤦

* Move getting the RFC 2616 time to a separate function

* More code cleanup

* Update go-ap to fix empty liked collection and removed unneeded HTTP headers

* go mod tidy

* Add ed25519 to httpsig algorithms

* Use go-ap/jsonld to add @context and marshal JSON

* Change Gitea user agent from the default to Gitea/Version

* Use ctx.ServerError and remove all remote interaction code from webfinger.go
2022-06-19 07:25:12 +02:00
6543
54e9ee37a7
format with gofumpt (#18184)
* gofumpt -w -l .

* gofumpt -w -l -extra .

* Add linter

* manual fix

* change make fmt
2022-01-20 18:46:10 +01:00
techknowlogick
e9a9c20d52
Create pub/priv keypair for federation (#17071)
* add logic for creating pub/priv keypair for federation

* Apply suggestions from code review

Co-authored-by: delvh <dev.lh@web.de>

* make fmt

* Update modules/activitypub/keypair.go

Co-authored-by: delvh <dev.lh@web.de>

* add tests

* fix revert

* more tests

* Apply suggestions from code review

Co-authored-by: delvh <dev.lh@web.de>

* make fmt

Co-authored-by: delvh <dev.lh@web.de>
Co-authored-by: 6543 <6543@obermui.de>
2021-09-28 15:19:22 -04:00