From f2db473b0d682facfd285aab646b7a5599d3f6fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Sun, 13 Mar 2022 09:18:54 +0100 Subject: [PATCH 01/94] 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 --- go.mod | 2 ++ go.sum | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/go.mod b/go.mod index e859e24c6e10f..3a34388db9bda 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,8 @@ require ( github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.0 github.com/go-enry/go-enry/v2 v2.8.0 + github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 // indirect + github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e // indirect github.com/go-git/go-billy/v5 v5.3.1 github.com/go-git/go-git/v5 v5.4.3-0.20210630082519-b4368b2a2ca4 github.com/go-ldap/ldap/v3 v3.4.2 diff --git a/go.sum b/go.sum index cec6e231ab992..cfd953bacc972 100644 --- a/go.sum +++ b/go.sum @@ -356,6 +356,7 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8= +github.com/dave/jennifer v1.3.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -464,6 +465,12 @@ github.com/go-enry/go-enry/v2 v2.8.0 h1:KMW4mSG+8uUF6FaD3iPkFqyfC5tF8gRrsYImq6yh github.com/go-enry/go-enry/v2 v2.8.0/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ= github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo= github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4= +github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 h1:rV8Mp/ChJLd0ZUrS6xMwiP6ZIFpSomffrQOjf4Xyd3M= +github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0/go.mod h1:v4QoPaAzjWZ8zN2VFVGL5ep9C02mst0hQYHUpQwso4Q= +github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5 h1:WLvFZqoXnuVTBKA6U/1FnEHNQ0Rq0QM0rGhY8Tx6R1g= +github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5/go.mod h1:T56HUNYZUQ1AGUzhAYPugZfp36sKApVnGBgKlIY+aIE= +github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e h1:oRq/fiirun5HqlEWMLIcDmLpIELlG4iGbd0s8iqgPi8= +github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= github.com/go-git/gcfg v1.5.0/go.mod h1:5m20vg6GwYabIxaOonVkTdrILxQMpEShl1xiMF4ua+E= github.com/go-git/go-billy/v5 v5.2.0/go.mod h1:pmpqyWchKfYfrkb/UVH4otLvyi/5gJlGI4Hb3ZqZ3W0= @@ -608,6 +615,7 @@ github.com/go-swagger/go-swagger v0.29.0/go.mod h1:Z4GJzI+bHKKkGB2Ji1rawpi3/ldXX github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0= github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-testfixtures/testfixtures/v3 v3.6.1 h1:n4Fv95Exp0D05G6l6CAZv22Ck1EJK0pa0TfPqE4ncSs= github.com/go-testfixtures/testfixtures/v3 v3.6.1/go.mod h1:Bsb2MoHAfHnNsPpSwAjtOs102mqDuM+1u3nE2OCi0N0= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= @@ -1642,6 +1650,7 @@ go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= gocloud.dev v0.19.0/go.mod h1:SmKwiR8YwIMMJvQBKLsC3fHNyMwXLw3PMDO+VVteJMI= golang.org/x/crypto v0.0.0-20180501155221-613d6eafa307/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20180527072434-ab813273cd59/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1838,6 +1847,7 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= From 4951af4d994d134b63d58a61ace9a71b7fa770e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Tue, 26 Oct 2021 15:59:14 -1000 Subject: [PATCH 02/94] activitypub: implement /api/v1/activitypub/user/{username} (#14186) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- integrations/api_activitypub_person_test.go | 63 +++++++++++++++++++++ modules/structs/activitypub.go | 9 +++ routers/api/v1/activitypub/person.go | 62 ++++++++++++++++++++ routers/api/v1/api.go | 6 ++ routers/api/v1/swagger/activitypub.go | 16 ++++++ templates/swagger/v1_json.tmpl | 39 +++++++++++++ 6 files changed, 195 insertions(+) create mode 100644 integrations/api_activitypub_person_test.go create mode 100644 modules/structs/activitypub.go create mode 100644 routers/api/v1/activitypub/person.go create mode 100644 routers/api/v1/swagger/activitypub.go diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go new file mode 100644 index 0000000000000..2efa82f0259c5 --- /dev/null +++ b/integrations/api_activitypub_person_test.go @@ -0,0 +1,63 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/url" + "testing" + + "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/streams" + "github.com/go-fed/activity/streams/vocab" + + "github.com/stretchr/testify/assert" +) + +func TestActivityPubPerson(t *testing.T) { + onGiteaRun(t, func(*testing.T, *url.URL) { + setting.Federation.Enabled = true + defer func() { + setting.Federation.Enabled = false + }() + + username := "user2" + req := NewRequestf(t, "GET", fmt.Sprintf("/api/v1/activitypub/user/%s", username)) + resp := MakeRequest(t, req, http.StatusOK) + assert.Contains(t, string(resp.Body.Bytes()), "@context") + var m map[string]interface{} + _ = json.Unmarshal(resp.Body.Bytes(), &m) + + var person vocab.ActivityStreamsPerson + resolver, _ := streams.NewJSONResolver(func(c context.Context, p vocab.ActivityStreamsPerson) error { + person = p + return nil + }) + ctx := context.Background() + err := resolver.Resolve(ctx, m) + assert.Equal(t, err, nil) + assert.Equal(t, person.GetTypeName(), "Person") + assert.Equal(t, person.GetActivityStreamsName().Begin().GetXMLSchemaString(), username) + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), person.GetJSONLDId().GetIRI().String()) + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.GetActivityStreamsOutbox().GetIRI().String()) + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.GetActivityStreamsInbox().GetIRI().String()) + }) +} + +func TestActivityPubMissingPerson(t *testing.T) { + onGiteaRun(t, func(*testing.T, *url.URL) { + setting.Federation.Enabled = true + defer func() { + setting.Federation.Enabled = false + }() + + req := NewRequestf(t, "GET", "/api/v1/activitypub/user/nonexistentuser") + resp := MakeRequest(t, req, http.StatusNotFound) + assert.Contains(t, string(resp.Body.Bytes()), "GetUserByName") + }) +} diff --git a/modules/structs/activitypub.go b/modules/structs/activitypub.go new file mode 100644 index 0000000000000..e1e2ec46a10ba --- /dev/null +++ b/modules/structs/activitypub.go @@ -0,0 +1,9 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package structs + +type ActivityPub struct { + Context string `json:"@context"` +} diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go new file mode 100644 index 0000000000000..ae1a8a7bbde00 --- /dev/null +++ b/routers/api/v1/activitypub/person.go @@ -0,0 +1,62 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "net/http" + "net/url" + "strings" + + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/routers/api/v1/user" + "github.com/go-fed/activity/streams" +) + +func Person(ctx *context.APIContext) { + // swagger:operation GET /activitypub/user/{username} information + // --- + // summary: Returns the person + // produces: + // - application/json + // parameters: + // - name: username + // in: path + // description: username of the user + // type: string + // required: true + // responses: + // "200": + // "$ref": "#/responses/ActivityPub" + + user.GetUserByParamsName(ctx, "username") + username := ctx.Params("username") + + person := streams.NewActivityStreamsPerson() + + id := streams.NewJSONLDIdProperty() + link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/") + url_object, _ := url.Parse(link) + id.SetIRI(url_object) + person.SetJSONLDId(id) + + name := streams.NewActivityStreamsNameProperty() + name.AppendXMLSchemaString(username) + person.SetActivityStreamsName(name) + + ibox := streams.NewActivityStreamsInboxProperty() + url_object, _ = url.Parse(link + "/inbox") + ibox.SetIRI(url_object) + person.SetActivityStreamsInbox(ibox) + + obox := streams.NewActivityStreamsOutboxProperty() + url_object, _ = url.Parse(link + "/outbox") + obox.SetIRI(url_object) + person.SetActivityStreamsOutbox(obox) + + var jsonmap map[string]interface{} + jsonmap, _ = streams.Serialize(person) + ctx.JSON(http.StatusOK, jsonmap) +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index d4891daef0f76..3fde7c34ee3f5 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -79,6 +79,7 @@ import ( "code.gitea.io/gitea/modules/setting" api "code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/routers/api/v1/activitypub" "code.gitea.io/gitea/routers/api/v1/admin" "code.gitea.io/gitea/routers/api/v1/misc" "code.gitea.io/gitea/routers/api/v1/notify" @@ -597,6 +598,11 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Get("/version", misc.Version) if setting.Federation.Enabled { m.Get("/nodeinfo", misc.NodeInfo) + m.Group("/activitypub", func() { + m.Group("/user/{username}", func() { + m.Get("", activitypub.Person) + }) + }) } m.Get("/signing-key.gpg", misc.SigningKey) m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown) diff --git a/routers/api/v1/swagger/activitypub.go b/routers/api/v1/swagger/activitypub.go new file mode 100644 index 0000000000000..3576439f43a00 --- /dev/null +++ b/routers/api/v1/swagger/activitypub.go @@ -0,0 +1,16 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package swagger + +import ( + api "code.gitea.io/gitea/modules/structs" +) + +// ActivityPub +// swagger:response ActivityPub +type swaggerResponseActivityPub struct { + // in:body + Body api.ActivityPub `json:"body"` +} diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 3bc6158183e02..c4ecf0f2e9998 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -23,6 +23,29 @@ }, "basePath": "{{AppSubUrl | JSEscape | Safe}}/api/v1", "paths": { + "/activitypub/user/{username}": { + "get": { + "produces": [ + "application/json" + ], + "summary": "Returns the person", + "operationId": "information", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "$ref": "#/responses/ActivityPub" + } + } + } + }, "/admin/cron": { "get": { "produces": [ @@ -12700,6 +12723,16 @@ }, "x-go-package": "code.gitea.io/gitea/modules/structs" }, + "ActivityPub": { + "type": "object", + "properties": { + "@context": { + "type": "string", + "x-go-name": "Context" + } + }, + "x-go-package": "code.gitea.io/gitea/modules/structs" + }, "AddCollaboratorOption": { "description": "AddCollaboratorOption options when adding a user as a collaborator of a repository", "type": "object", @@ -18235,6 +18268,12 @@ } } }, + "ActivityPub": { + "description": "ActivityPub", + "schema": { + "$ref": "#/definitions/ActivityPub" + } + }, "AnnotatedTag": { "description": "AnnotatedTag", "schema": { From 678a56fbf81f6568ba82b6236c534ce10ab18fea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Thu, 28 Oct 2021 17:13:24 -1000 Subject: [PATCH 03/94] activitypub: add the public key to Person (#14186) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs: https://github.com/go-gitea/gitea/issues/14186 Signed-off-by: Loïc Dachary --- integrations/api_activitypub_person_test.go | 39 ++++++++++++-- routers/api/v1/activitypub/person.go | 58 +++++++++++++++++++-- 2 files changed, 90 insertions(+), 7 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 2efa82f0259c5..e031e886dc2e6 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -13,6 +13,7 @@ import ( "testing" "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" "github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams/vocab" @@ -22,8 +23,10 @@ import ( func TestActivityPubPerson(t *testing.T) { onGiteaRun(t, func(*testing.T, *url.URL) { setting.Federation.Enabled = true + setting.Database.LogSQL = true defer func() { setting.Federation.Enabled = false + setting.Database.LogSQL = false }() username := "user2" @@ -41,11 +44,41 @@ func TestActivityPubPerson(t *testing.T) { ctx := context.Background() err := resolver.Resolve(ctx, m) assert.Equal(t, err, nil) - assert.Equal(t, person.GetTypeName(), "Person") - assert.Equal(t, person.GetActivityStreamsName().Begin().GetXMLSchemaString(), username) - assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), person.GetJSONLDId().GetIRI().String()) + assert.Equal(t, "Person", person.GetTypeName()) + assert.Equal(t, username, person.GetActivityStreamsName().Begin().GetXMLSchemaString()) + keyId := person.GetJSONLDId().GetIRI().String() + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyId) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.GetActivityStreamsOutbox().GetIRI().String()) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.GetActivityStreamsInbox().GetIRI().String()) + + pkp := person.GetW3IDSecurityV1PublicKey() + publicKeyId := keyId + "/#main-key" + var pkpFound vocab.W3IDSecurityV1PublicKey + for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { + if !pkpIter.IsW3IDSecurityV1PublicKey() { + continue + } + pkValue := pkpIter.Get() + var pkId *url.URL + pkId, err = pub.GetId(pkValue) + if err != nil { + return + } + assert.Equal(t, pkId.String(), publicKeyId) + if pkId.String() != publicKeyId { + continue + } + pkpFound = pkValue + break + } + assert.NotNil(t, pkpFound) + + pkPemProp := pkpFound.GetW3IDSecurityV1PublicKeyPem() + assert.NotNil(t, pkPemProp) + assert.True(t, pkPemProp.IsXMLSchemaString()) + + pubKeyPem := pkPemProp.Get() + assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----", pubKeyPem) }) } diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index ae1a8a7bbde00..326629f8b27de 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -9,12 +9,38 @@ import ( "net/url" "strings" + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/api/v1/user" "github.com/go-fed/activity/streams" ) +// hack waiting on https://github.com/go-gitea/gitea/pull/16834 +func GetPublicKey(user *models.User) (string, error) { + if settings, err := models.GetUserSetting(user.ID, []string{"activitypub_pubPem"}); err != nil { + return "", err + } else if len(settings) == 0 { + if priv, pub, err := activitypub.GenerateKeyPair(); err != nil { + return "", err + } else { + privPem := &models.UserSetting{UserID: user.ID, Name: "activitypub_privPem", Value: priv} + if err := models.SetUserSetting(privPem); err != nil { + return "", err + } + pubPem := &models.UserSetting{UserID: user.ID, Name: "activitypub_pubPem", Value: pub} + if err := models.SetUserSetting(pubPem); err != nil { + return "", err + } + return pubPem.Value, nil + } + } else { + return settings[0].Value, nil + } +} + +// NodeInfo returns the NodeInfo for the Gitea instance to allow for federation func Person(ctx *context.APIContext) { // swagger:operation GET /activitypub/user/{username} information // --- @@ -31,15 +57,15 @@ func Person(ctx *context.APIContext) { // "200": // "$ref": "#/responses/ActivityPub" - user.GetUserByParamsName(ctx, "username") + user := user.GetUserByParamsName(ctx, "username") username := ctx.Params("username") person := streams.NewActivityStreamsPerson() id := streams.NewJSONLDIdProperty() link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/") - url_object, _ := url.Parse(link) - id.SetIRI(url_object) + idIRI, _ := url.Parse(link) + id.SetIRI(idIRI) person.SetJSONLDId(id) name := streams.NewActivityStreamsNameProperty() @@ -47,7 +73,7 @@ func Person(ctx *context.APIContext) { person.SetActivityStreamsName(name) ibox := streams.NewActivityStreamsInboxProperty() - url_object, _ = url.Parse(link + "/inbox") + url_object, _ := url.Parse(link + "/inbox") ibox.SetIRI(url_object) person.SetActivityStreamsInbox(ibox) @@ -56,6 +82,30 @@ func Person(ctx *context.APIContext) { obox.SetIRI(url_object) person.SetActivityStreamsOutbox(obox) + publicKeyProp := streams.NewW3IDSecurityV1PublicKeyProperty() + + publicKeyType := streams.NewW3IDSecurityV1PublicKey() + + pubKeyIdProp := streams.NewJSONLDIdProperty() + pubKeyIRI, _ := url.Parse(link + "/#main-key") + pubKeyIdProp.SetIRI(pubKeyIRI) + publicKeyType.SetJSONLDId(pubKeyIdProp) + + ownerProp := streams.NewW3IDSecurityV1OwnerProperty() + ownerProp.SetIRI(idIRI) + publicKeyType.SetW3IDSecurityV1Owner(ownerProp) + + publicKeyPemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty() + if publicKeyPem, err := GetPublicKey(user); err != nil { + ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) + } else { + publicKeyPemProp.Set(publicKeyPem) + } + publicKeyType.SetW3IDSecurityV1PublicKeyPem(publicKeyPemProp) + + publicKeyProp.AppendW3IDSecurityV1PublicKey(publicKeyType) + person.SetW3IDSecurityV1PublicKey(publicKeyProp) + var jsonmap map[string]interface{} jsonmap, _ = streams.Serialize(person) ctx.JSON(http.StatusOK, jsonmap) From e8907c3c9edbb57dfdfe5f5078b01415f4d54fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Tue, 9 Nov 2021 08:35:27 +0100 Subject: [PATCH 04/94] activitypub: go-fed conformant Clock instance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Dachary --- modules/activitypub/clock.go | 28 ++++++++++++++++++++++++++++ modules/activitypub/clock_test.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 modules/activitypub/clock.go create mode 100644 modules/activitypub/clock_test.go diff --git a/modules/activitypub/clock.go b/modules/activitypub/clock.go new file mode 100644 index 0000000000000..88bd888e2838b --- /dev/null +++ b/modules/activitypub/clock.go @@ -0,0 +1,28 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "time" + + "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" +) + +var _ pub.Clock = &Clock{} + +// Clock struct +type Clock struct{} + +// NewClock function +func NewClock() (c *Clock, err error) { + c = &Clock{} + return +} + +// Now function +func (c *Clock) Now() time.Time { + return time.Now().In(setting.DefaultUILocation) +} diff --git a/modules/activitypub/clock_test.go b/modules/activitypub/clock_test.go new file mode 100644 index 0000000000000..55b0cbb293708 --- /dev/null +++ b/modules/activitypub/clock_test.go @@ -0,0 +1,30 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "regexp" + "testing" + "time" + + "code.gitea.io/gitea/modules/setting" + + "github.com/stretchr/testify/assert" +) + +func TestClock(t *testing.T) { + DefaultUILocation := setting.DefaultUILocation + defer func() { + setting.DefaultUILocation = DefaultUILocation + }() + c, err := NewClock() + assert.NoError(t, err) + setting.DefaultUILocation, err = time.LoadLocation("UTC") + assert.NoError(t, err) + assert.Regexp(t, regexp.MustCompile(`\+0000$`), c.Now().Format(time.Layout)) + setting.DefaultUILocation, err = time.LoadLocation("Europe/Paris") + assert.NoError(t, err) + assert.Regexp(t, regexp.MustCompile(`\+0[21]00$`), c.Now().Format(time.Layout)) +} From 15c1f6218c407b236a52eef71ca8ec286d702958 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Tue, 9 Nov 2021 08:36:23 +0100 Subject: [PATCH 05/94] activitypub: signing http client MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Dachary --- modules/activitypub/client.go | 117 +++++++++++++++++++++++++++++ modules/activitypub/client_test.go | 49 ++++++++++++ modules/activitypub/main_test.go | 16 ++++ modules/setting/federation.go | 12 ++- 4 files changed, 192 insertions(+), 2 deletions(-) create mode 100644 modules/activitypub/client.go create mode 100644 modules/activitypub/client_test.go create mode 100644 modules/activitypub/main_test.go diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go new file mode 100644 index 0000000000000..c3c1d9e9507ef --- /dev/null +++ b/modules/activitypub/client.go @@ -0,0 +1,117 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "bytes" + "crypto/rsa" + "crypto/x509" + "encoding/pem" + "fmt" + "net/http" + + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" + "github.com/go-fed/httpsig" +) + +const ( + activityStreamsContentType = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" +) + +func containsRequiredHttpHeaders(method string, headers []string) error { + var hasRequestTarget, hasDate, hasDigest bool + for _, header := range headers { + hasRequestTarget = hasRequestTarget || header == httpsig.RequestTarget + hasDate = hasDate || header == "Date" + hasDigest = method == "GET" || hasDigest || header == "Digest" + } + if !hasRequestTarget { + return fmt.Errorf("missing http header for %s: %s", method, httpsig.RequestTarget) + } else if !hasDate { + return fmt.Errorf("missing http header for %s: Date", method) + } else if !hasDigest { + return fmt.Errorf("missing http header for %s: Digest", method) + } + return nil +} + +type Client struct { + clock pub.Clock + client *http.Client + algs []httpsig.Algorithm + digestAlg httpsig.DigestAlgorithm + getHeaders []string + postHeaders []string + priv *rsa.PrivateKey + pubId string +} + +func NewClient(user *user_model.User, pubId string) (c *Client, err error) { + if err = containsRequiredHttpHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil { + return + } else if err = containsRequiredHttpHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil { + return + } else if !httpsig.IsSupportedDigestAlgorithm(setting.Federation.DigestAlgorithm) { + err = fmt.Errorf("unsupported digest algorithm: %s", setting.Federation.DigestAlgorithm) + return + } + algos := make([]httpsig.Algorithm, len(setting.Federation.Algorithms)) + for i, algo := range setting.Federation.Algorithms { + algos[i] = httpsig.Algorithm(algo) + } + clock, err := NewClock() + if err != nil { + return + } + + priv, err := GetPrivateKey(user) + if err != nil { + return + } + privPem, _ := pem.Decode([]byte(priv)) + privParsed, err := x509.ParsePKCS1PrivateKey(privPem.Bytes) + if err != nil { + return + } + + c = &Client{ + clock: clock, + client: &http.Client{}, + algs: algos, + digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm), + getHeaders: setting.Federation.GetHeaders, + postHeaders: setting.Federation.PostHeaders, + priv: privParsed, + pubId: pubId, + } + return +} + +func (c *Client) Post(b []byte, to string) (resp *http.Response, err error) { + byteCopy := make([]byte, len(b)) + copy(byteCopy, b) + buf := bytes.NewBuffer(byteCopy) + var req *http.Request + req, err = http.NewRequest(http.MethodPost, to, buf) + if err != nil { + return + } + req.Header.Add("Content-Type", activityStreamsContentType) + req.Header.Add("Accept-Charset", "utf-8") + req.Header.Add("Date", fmt.Sprintf("%s GMT", c.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05"))) + + signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, 60) + if err != nil { + return + } + err = signer.SignRequest(c.priv, c.pubId, req, b) + if err != nil { + return + } + resp, err = c.client.Do(req) + return +} diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go new file mode 100644 index 0000000000000..e29117ea131f9 --- /dev/null +++ b/modules/activitypub/client_test.go @@ -0,0 +1,49 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "fmt" + "io" + "io/ioutil" + "net/http" + "net/http/httptest" + "regexp" + "testing" + + _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/setting" + + "github.com/stretchr/testify/assert" +) + +func TestActivityPubSignedPost(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) + pubId := "https://example.com/pubId" + c, err := NewClient(user, pubId) + assert.NoError(t, err) + + expected := "BODY" + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Regexp(t, regexp.MustCompile("^"+setting.Federation.DigestAlgorithm), r.Header.Get("Digest")) + assert.Contains(t, r.Header.Get("Signature"), pubId) + assert.Equal(t, r.Header.Get("Content-Type"), activityStreamsContentType) + body, err := ioutil.ReadAll(r.Body) + assert.NoError(t, err) + assert.Equal(t, expected, string(body)) + fmt.Fprintf(w, expected) + })) + defer srv.Close() + + r, err := c.Post([]byte(expected), srv.URL) + assert.NoError(t, err) + defer r.Body.Close() + body, err := io.ReadAll(r.Body) + assert.NoError(t, err) + assert.Equal(t, expected, string(body)) +} diff --git a/modules/activitypub/main_test.go b/modules/activitypub/main_test.go new file mode 100644 index 0000000000000..c2be6f661e750 --- /dev/null +++ b/modules/activitypub/main_test.go @@ -0,0 +1,16 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "path/filepath" + "testing" + + "code.gitea.io/gitea/models/unittest" +) + +func TestMain(m *testing.M) { + unittest.MainTest(m, filepath.Join("..", "..")) +} diff --git a/modules/setting/federation.go b/modules/setting/federation.go index c3000607894e7..12330c6cf3b6f 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -9,9 +9,17 @@ import "code.gitea.io/gitea/modules/log" // Federation settings var ( Federation = struct { - Enabled bool + Enabled bool + Algorithms []string + DigestAlgorithm string + GetHeaders []string + PostHeaders []string }{ - Enabled: true, + Enabled: true, + Algorithms: []string{"rsa-sha256", "rsa-sha512"}, + DigestAlgorithm: "SHA-256", + GetHeaders: []string{"(request-target)", "Date"}, + PostHeaders: []string{"(request-target)", "Date", "Digest"}, } ) From 97fedf26169bca28cb310014e73be494d495a650 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Wed, 10 Nov 2021 13:35:02 +0100 Subject: [PATCH 06/94] activitypub: implement the ReqSignature middleware MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Dachary --- integrations/api_activitypub_person_test.go | 55 +++++-- modules/activitypub/client.go | 33 ++-- modules/activitypub/client_test.go | 11 +- modules/structs/activitypub.go | 1 + routers/api/v1/activitypub/person.go | 65 ++++---- routers/api/v1/activitypub/reqsignature.go | 158 ++++++++++++++++++++ routers/api/v1/api.go | 1 + templates/swagger/v1_json.tmpl | 31 +++- 8 files changed, 293 insertions(+), 62 deletions(-) create mode 100644 routers/api/v1/activitypub/reqsignature.go diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index e031e886dc2e6..4f131fe4e05f9 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -9,9 +9,12 @@ import ( "encoding/json" "fmt" "net/http" + "net/http/httptest" "net/url" "testing" + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/setting" "github.com/go-fed/activity/pub" "github.com/go-fed/activity/streams" @@ -32,7 +35,7 @@ func TestActivityPubPerson(t *testing.T) { username := "user2" req := NewRequestf(t, "GET", fmt.Sprintf("/api/v1/activitypub/user/%s", username)) resp := MakeRequest(t, req, http.StatusOK) - assert.Contains(t, string(resp.Body.Bytes()), "@context") + assert.Contains(t, resp.Body.String(), "@context") var m map[string]interface{} _ = json.Unmarshal(resp.Body.Bytes(), &m) @@ -46,26 +49,26 @@ func TestActivityPubPerson(t *testing.T) { assert.Equal(t, err, nil) assert.Equal(t, "Person", person.GetTypeName()) assert.Equal(t, username, person.GetActivityStreamsName().Begin().GetXMLSchemaString()) - keyId := person.GetJSONLDId().GetIRI().String() - assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyId) + keyID := person.GetJSONLDId().GetIRI().String() + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.GetActivityStreamsOutbox().GetIRI().String()) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.GetActivityStreamsInbox().GetIRI().String()) pkp := person.GetW3IDSecurityV1PublicKey() - publicKeyId := keyId + "/#main-key" + publicKeyID := keyID + "/#main-key" var pkpFound vocab.W3IDSecurityV1PublicKey for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { if !pkpIter.IsW3IDSecurityV1PublicKey() { continue } pkValue := pkpIter.Get() - var pkId *url.URL - pkId, err = pub.GetId(pkValue) + var pkID *url.URL + pkID, err = pub.GetId(pkValue) if err != nil { return } - assert.Equal(t, pkId.String(), publicKeyId) - if pkId.String() != publicKeyId { + assert.Equal(t, pkID.String(), publicKeyID) + if pkID.String() != publicKeyID { continue } pkpFound = pkValue @@ -91,6 +94,40 @@ func TestActivityPubMissingPerson(t *testing.T) { req := NewRequestf(t, "GET", "/api/v1/activitypub/user/nonexistentuser") resp := MakeRequest(t, req, http.StatusNotFound) - assert.Contains(t, string(resp.Body.Bytes()), "GetUserByName") + assert.Contains(t, resp.Body.String(), "GetUserByName") + }) +} + +func TestActivityPubPersonInbox(t *testing.T) { + srv := httptest.NewServer(c) + defer srv.Close() + + onGiteaRun(t, func(*testing.T, *url.URL) { + appURL := setting.AppURL + setting.Federation.Enabled = true + setting.Database.LogSQL = true + setting.AppURL = srv.URL + defer func() { + setting.Federation.Enabled = false + setting.Database.LogSQL = false + setting.AppURL = appURL + }() + username1 := "user1" + user1, err := user_model.GetUserByName(username1) + assert.NoError(t, err) + user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s/#main-key", srv.URL, username1) + c, err := activitypub.NewClient(user1, user1url) + assert.NoError(t, err) + username2 := "user2" + user2inboxurl := fmt.Sprintf("%s/api/v1/activitypub/user/%s/inbox", srv.URL, username2) + + // Signed request succeeds + resp, err := c.Post([]byte{}, user2inboxurl) + assert.NoError(t, err) + assert.Equal(t, 204, resp.StatusCode) + + // Unsigned request fails + req := NewRequest(t, "POST", user2inboxurl) + MakeRequest(t, req, 500) }) } diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index c3c1d9e9507ef..83d5ab72a11a4 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -19,10 +19,11 @@ import ( ) const ( - activityStreamsContentType = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" + // ActivityStreamsContentType const + ActivityStreamsContentType = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" ) -func containsRequiredHttpHeaders(method string, headers []string) error { +func containsRequiredHTTPHeaders(method string, headers []string) error { var hasRequestTarget, hasDate, hasDigest bool for _, header := range headers { hasRequestTarget = hasRequestTarget || header == httpsig.RequestTarget @@ -39,6 +40,7 @@ func containsRequiredHttpHeaders(method string, headers []string) error { return nil } +// Client struct type Client struct { clock pub.Clock client *http.Client @@ -47,13 +49,14 @@ type Client struct { getHeaders []string postHeaders []string priv *rsa.PrivateKey - pubId string + pubID string } -func NewClient(user *user_model.User, pubId string) (c *Client, err error) { - if err = containsRequiredHttpHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil { +// NewClient function +func NewClient(user *user_model.User, pubID string) (c *Client, err error) { + if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil { return - } else if err = containsRequiredHttpHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil { + } else if err = containsRequiredHTTPHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil { return } else if !httpsig.IsSupportedDigestAlgorithm(setting.Federation.DigestAlgorithm) { err = fmt.Errorf("unsupported digest algorithm: %s", setting.Federation.DigestAlgorithm) @@ -86,21 +89,21 @@ func NewClient(user *user_model.User, pubId string) (c *Client, err error) { getHeaders: setting.Federation.GetHeaders, postHeaders: setting.Federation.PostHeaders, priv: privParsed, - pubId: pubId, + pubID: pubID, } return } -func (c *Client) Post(b []byte, to string) (resp *http.Response, err error) { +// NewRequest function +func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) { byteCopy := make([]byte, len(b)) copy(byteCopy, b) buf := bytes.NewBuffer(byteCopy) - var req *http.Request req, err = http.NewRequest(http.MethodPost, to, buf) if err != nil { return } - req.Header.Add("Content-Type", activityStreamsContentType) + req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Accept-Charset", "utf-8") req.Header.Add("Date", fmt.Sprintf("%s GMT", c.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05"))) @@ -108,8 +111,14 @@ func (c *Client) Post(b []byte, to string) (resp *http.Response, err error) { if err != nil { return } - err = signer.SignRequest(c.priv, c.pubId, req, b) - if err != nil { + err = signer.SignRequest(c.priv, c.pubID, req, b) + return +} + +// Post function +func (c *Client) Post(b []byte, to string) (resp *http.Response, err error) { + var req *http.Request + if req, err = c.NewRequest(b, to); err != nil { return } resp, err = c.client.Do(req) diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index e29117ea131f9..29a286d489c21 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -7,7 +7,6 @@ package activitypub import ( "fmt" "io" - "io/ioutil" "net/http" "net/http/httptest" "regexp" @@ -24,16 +23,16 @@ import ( func TestActivityPubSignedPost(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) - pubId := "https://example.com/pubId" - c, err := NewClient(user, pubId) + pubID := "https://example.com/pubID" + c, err := NewClient(user, pubID) assert.NoError(t, err) expected := "BODY" srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Regexp(t, regexp.MustCompile("^"+setting.Federation.DigestAlgorithm), r.Header.Get("Digest")) - assert.Contains(t, r.Header.Get("Signature"), pubId) - assert.Equal(t, r.Header.Get("Content-Type"), activityStreamsContentType) - body, err := ioutil.ReadAll(r.Body) + assert.Contains(t, r.Header.Get("Signature"), pubID) + assert.Equal(t, r.Header.Get("Content-Type"), ActivityStreamsContentType) + body, err := io.ReadAll(r.Body) assert.NoError(t, err) assert.Equal(t, expected, string(body)) fmt.Fprintf(w, expected) diff --git a/modules/structs/activitypub.go b/modules/structs/activitypub.go index e1e2ec46a10ba..65db69ee2055e 100644 --- a/modules/structs/activitypub.go +++ b/modules/structs/activitypub.go @@ -4,6 +4,7 @@ package structs +// ActivityPub type type ActivityPub struct { Context string `json:"@context"` } diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 326629f8b27de..60d0143ea266d 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -9,7 +9,6 @@ import ( "net/url" "strings" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" @@ -17,32 +16,9 @@ import ( "github.com/go-fed/activity/streams" ) -// hack waiting on https://github.com/go-gitea/gitea/pull/16834 -func GetPublicKey(user *models.User) (string, error) { - if settings, err := models.GetUserSetting(user.ID, []string{"activitypub_pubPem"}); err != nil { - return "", err - } else if len(settings) == 0 { - if priv, pub, err := activitypub.GenerateKeyPair(); err != nil { - return "", err - } else { - privPem := &models.UserSetting{UserID: user.ID, Name: "activitypub_privPem", Value: priv} - if err := models.SetUserSetting(privPem); err != nil { - return "", err - } - pubPem := &models.UserSetting{UserID: user.ID, Name: "activitypub_pubPem", Value: pub} - if err := models.SetUserSetting(pubPem); err != nil { - return "", err - } - return pubPem.Value, nil - } - } else { - return settings[0].Value, nil - } -} - -// NodeInfo returns the NodeInfo for the Gitea instance to allow for federation +// Person function func Person(ctx *context.APIContext) { - // swagger:operation GET /activitypub/user/{username} information + // swagger:operation GET /activitypub/user/{username} activitypub activitypubPerson // --- // summary: Returns the person // produces: @@ -73,30 +49,30 @@ func Person(ctx *context.APIContext) { person.SetActivityStreamsName(name) ibox := streams.NewActivityStreamsInboxProperty() - url_object, _ := url.Parse(link + "/inbox") - ibox.SetIRI(url_object) + urlObject, _ := url.Parse(link + "/inbox") + ibox.SetIRI(urlObject) person.SetActivityStreamsInbox(ibox) obox := streams.NewActivityStreamsOutboxProperty() - url_object, _ = url.Parse(link + "/outbox") - obox.SetIRI(url_object) + urlObject, _ = url.Parse(link + "/outbox") + obox.SetIRI(urlObject) person.SetActivityStreamsOutbox(obox) publicKeyProp := streams.NewW3IDSecurityV1PublicKeyProperty() publicKeyType := streams.NewW3IDSecurityV1PublicKey() - pubKeyIdProp := streams.NewJSONLDIdProperty() + pubKeyIDProp := streams.NewJSONLDIdProperty() pubKeyIRI, _ := url.Parse(link + "/#main-key") - pubKeyIdProp.SetIRI(pubKeyIRI) - publicKeyType.SetJSONLDId(pubKeyIdProp) + pubKeyIDProp.SetIRI(pubKeyIRI) + publicKeyType.SetJSONLDId(pubKeyIDProp) ownerProp := streams.NewW3IDSecurityV1OwnerProperty() ownerProp.SetIRI(idIRI) publicKeyType.SetW3IDSecurityV1Owner(ownerProp) publicKeyPemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty() - if publicKeyPem, err := GetPublicKey(user); err != nil { + if publicKeyPem, err := activitypub.GetPublicKey(user); err != nil { ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) } else { publicKeyPemProp.Set(publicKeyPem) @@ -110,3 +86,24 @@ func Person(ctx *context.APIContext) { jsonmap, _ = streams.Serialize(person) ctx.JSON(http.StatusOK, jsonmap) } + +// PersonInbox function +func PersonInbox(ctx *context.APIContext) { + // swagger:operation POST /activitypub/user/{username}/inbox activitypub activitypubPersonInbox + // --- + // summary: Send to the inbox + // produces: + // - application/json + // parameters: + // - name: username + // in: path + // description: username of the user + // type: string + // required: true + // responses: + // responses: + // "204": + // "$ref": "#/responses/empty" + + ctx.Status(http.StatusNoContent) +} diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go new file mode 100644 index 0000000000000..d422d26fac82a --- /dev/null +++ b/routers/api/v1/activitypub/reqsignature.go @@ -0,0 +1,158 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "context" + "crypto" + "crypto/x509" + "encoding/pem" + "fmt" + "io" + "net/http" + "net/url" + + "code.gitea.io/gitea/modules/activitypub" + gitea_context "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/json" + "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" + "github.com/go-fed/activity/streams" + "github.com/go-fed/activity/streams/vocab" + "github.com/go-fed/httpsig" +) + +type publicKeyer interface { + GetW3IDSecurityV1PublicKey() vocab.W3IDSecurityV1PublicKeyProperty +} + +func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p crypto.PublicKey, err error) { + m := make(map[string]interface{}) + err = json.Unmarshal(b, &m) + if err != nil { + return + } + var t vocab.Type + t, err = streams.ToType(ctx, m) + if err != nil { + return + } + pker, ok := t.(publicKeyer) + if !ok { + err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %T", t) + return + } + pkp := pker.GetW3IDSecurityV1PublicKey() + if pkp == nil { + err = fmt.Errorf("publicKey property is not provided") + return + } + var pkpFound vocab.W3IDSecurityV1PublicKey + for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { + if !pkpIter.IsW3IDSecurityV1PublicKey() { + continue + } + pkValue := pkpIter.Get() + var pkID *url.URL + pkID, err = pub.GetId(pkValue) + if err != nil { + return + } + if pkID.String() != keyID.String() { + continue + } + pkpFound = pkValue + break + } + if pkpFound == nil { + err = fmt.Errorf("cannot find publicKey with id: %s in %s", keyID, b) + return + } + pkPemProp := pkpFound.GetW3IDSecurityV1PublicKeyPem() + if pkPemProp == nil || !pkPemProp.IsXMLSchemaString() { + err = fmt.Errorf("publicKeyPem property is not provided or it is not embedded as a value") + return + } + pubKeyPem := pkPemProp.Get() + var block *pem.Block + block, _ = pem.Decode([]byte(pubKeyPem)) + if block == nil || block.Type != "PUBLIC KEY" { + err = fmt.Errorf("could not decode publicKeyPem to PUBLIC KEY pem block type") + return + } + p, err = x509.ParsePKIXPublicKey(block.Bytes) + return +} + +func fetch(iri *url.URL) (b []byte, err error) { + var req *http.Request + req, err = http.NewRequest(http.MethodGet, iri.String(), nil) + if err != nil { + return + } + req.Header.Add("Accept", activitypub.ActivityStreamsContentType) + req.Header.Add("Accept-Charset", "utf-8") + clock, err := activitypub.NewClock() + if err != nil { + return + } + req.Header.Add("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05"))) + var resp *http.Response + client := &http.Client{} + resp, err = client.Do(req) + if err != nil { + return + } + defer resp.Body.Close() + + if resp.StatusCode != http.StatusOK { + err = fmt.Errorf("url IRI fetch [%s] failed with status (%d): %s", iri, resp.StatusCode, resp.Status) + return + } + b, err = io.ReadAll(resp.Body) + return +} + +func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, err error) { + r := ctx.Req + + // 1. Figure out what key we need to verify + var v httpsig.Verifier + v, err = httpsig.NewVerifier(r) + if err != nil { + return + } + ID := v.KeyId() + var idIRI *url.URL + idIRI, err = url.Parse(ID) + if err != nil { + return + } + // 2. Fetch the public key of the other actor + var b []byte + b, err = fetch(idIRI) + if err != nil { + return + } + pKey, err := getPublicKeyFromResponse(*ctx, b, idIRI) + if err != nil { + return + } + // 3. Verify the other actor's key + algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) + authenticated = nil == v.Verify(pKey, algo) + return +} + +// ReqSignature function +func ReqSignature() func(ctx *gitea_context.APIContext) { + return func(ctx *gitea_context.APIContext) { + if authenticated, err := verifyHTTPSignatures(ctx); err != nil { + ctx.Error(http.StatusInternalServerError, "verifyHttpSignatures", err) + } else if !authenticated { + ctx.Error(http.StatusForbidden, "reqSignature", "request signature verification failed") + } + } +} diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 3fde7c34ee3f5..4eeefface88b2 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -602,6 +602,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { m.Group("/user/{username}", func() { m.Get("", activitypub.Person) }) + m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) }) } m.Get("/signing-key.gpg", misc.SigningKey) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index c4ecf0f2e9998..390441cde7081 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -28,8 +28,11 @@ "produces": [ "application/json" ], + "tags": [ + "activitypub" + ], "summary": "Returns the person", - "operationId": "information", + "operationId": "activitypubPerson", "parameters": [ { "type": "string", @@ -46,6 +49,32 @@ } } }, + "/activitypub/user/{username}/inbox": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "activitypub" + ], + "summary": "Send to the inbox", + "operationId": "activitypubPersonInbox", + "parameters": [ + { + "type": "string", + "description": "username of the user", + "name": "username", + "in": "path", + "required": true + } + ], + "responses": { + "204": { + "$ref": "#/responses/empty" + } + } + } + }, "/admin/cron": { "get": { "produces": [ From b342241abcdac28adc3bb4f03eb75f44f3f16150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Fri, 24 Dec 2021 16:47:43 +0100 Subject: [PATCH 07/94] activitypub: hack_16834 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Loïc Dachary --- modules/activitypub/hack_16834.go | 44 ++++++++++++++++++++++++++ modules/activitypub/hack_16834_test.go | 27 ++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 modules/activitypub/hack_16834.go create mode 100644 modules/activitypub/hack_16834_test.go diff --git a/modules/activitypub/hack_16834.go b/modules/activitypub/hack_16834.go new file mode 100644 index 0000000000000..b3537c6d32c99 --- /dev/null +++ b/modules/activitypub/hack_16834.go @@ -0,0 +1,44 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + user_model "code.gitea.io/gitea/models/user" +) + +// GetKeyPair function +func GetKeyPair(user *user_model.User) (pub, priv string, err error) { + var settings map[string]*user_model.Setting + if settings, err = user_model.GetUserSettings(user.ID, []string{"activitypub_privpem", "activitypub_pubpem"}); err != nil { + return + } else if len(settings) == 0 { + if priv, pub, err = GenerateKeyPair(); err != nil { + return + } + if err = user_model.SetUserSetting(user.ID, "activitypub_privpem", priv); err != nil { + return + } + if err = user_model.SetUserSetting(user.ID, "activitypub_pubpem", pub); err != nil { + return + } + return + } else { + priv = settings["activitypub_privpem"].SettingValue + pub = settings["activitypub_pubpem"].SettingValue + return + } +} + +// GetPublicKey function +func GetPublicKey(user *user_model.User) (pub string, err error) { + pub, _, err = GetKeyPair(user) + return +} + +// GetPrivateKey function +func GetPrivateKey(user *user_model.User) (priv string, err error) { + _, priv, err = GetKeyPair(user) + return +} diff --git a/modules/activitypub/hack_16834_test.go b/modules/activitypub/hack_16834_test.go new file mode 100644 index 0000000000000..8982afb7b6ade --- /dev/null +++ b/modules/activitypub/hack_16834_test.go @@ -0,0 +1,27 @@ +// Copyright 2021 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package activitypub + +import ( + "testing" + + _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 + "code.gitea.io/gitea/models/unittest" + user_model "code.gitea.io/gitea/models/user" + "github.com/stretchr/testify/assert" +) + +func TestHack16834(t *testing.T) { + assert.NoError(t, unittest.PrepareTestDatabase()) + user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) + pub, priv, err := GetKeyPair(user1) + assert.NoError(t, err) + pub1, err := GetPublicKey(user1) + assert.NoError(t, err) + assert.Equal(t, pub, pub1) + priv1, err := GetPrivateKey(user1) + assert.NoError(t, err) + assert.Equal(t, priv, priv1) +} From 2a8864fe43996e0bf5a6c89e1a4365174761fc67 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 19 Mar 2022 08:54:32 -0500 Subject: [PATCH 08/94] Fix CI checks-backend errors with go mod tidy Signed-off-by: Anthony Wang --- go.mod | 4 ++-- go.sum | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 3a34388db9bda..d744908c77a95 100644 --- a/go.mod +++ b/go.mod @@ -40,8 +40,8 @@ require ( github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.0 github.com/go-enry/go-enry/v2 v2.8.0 - github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 // indirect - github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e // indirect + github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 + github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e github.com/go-git/go-billy/v5 v5.3.1 github.com/go-git/go-git/v5 v5.4.3-0.20210630082519-b4368b2a2ca4 github.com/go-ldap/ldap/v3 v3.4.2 diff --git a/go.sum b/go.sum index cfd953bacc972..6016617e5954d 100644 --- a/go.sum +++ b/go.sum @@ -467,7 +467,6 @@ github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCc github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4= github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 h1:rV8Mp/ChJLd0ZUrS6xMwiP6ZIFpSomffrQOjf4Xyd3M= github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0/go.mod h1:v4QoPaAzjWZ8zN2VFVGL5ep9C02mst0hQYHUpQwso4Q= -github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5 h1:WLvFZqoXnuVTBKA6U/1FnEHNQ0Rq0QM0rGhY8Tx6R1g= github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5/go.mod h1:T56HUNYZUQ1AGUzhAYPugZfp36sKApVnGBgKlIY+aIE= github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e h1:oRq/fiirun5HqlEWMLIcDmLpIELlG4iGbd0s8iqgPi8= github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= @@ -615,6 +614,7 @@ github.com/go-swagger/go-swagger v0.29.0/go.mod h1:Z4GJzI+bHKKkGB2Ji1rawpi3/ldXX github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0= github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= +github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg= github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-testfixtures/testfixtures/v3 v3.6.1 h1:n4Fv95Exp0D05G6l6CAZv22Ck1EJK0pa0TfPqE4ncSs= github.com/go-testfixtures/testfixtures/v3 v3.6.1/go.mod h1:Bsb2MoHAfHnNsPpSwAjtOs102mqDuM+1u3nE2OCi0N0= From b480c52f602fe0234089e0bb80292ecc8c1db3fd Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 19 Mar 2022 08:55:58 -0500 Subject: [PATCH 09/94] Change 2021 to 2022, properly format package imports Signed-off-by: Anthony Wang --- integrations/api_activitypub_person_test.go | 4 ++-- modules/activitypub/client.go | 2 +- modules/activitypub/client_test.go | 2 +- modules/activitypub/clock.go | 2 +- modules/activitypub/clock_test.go | 2 +- modules/activitypub/hack_16834.go | 2 +- modules/activitypub/hack_16834_test.go | 2 +- modules/activitypub/main_test.go | 2 +- modules/structs/activitypub.go | 2 +- routers/api/v1/activitypub/person.go | 2 +- routers/api/v1/activitypub/reqsignature.go | 2 +- routers/api/v1/swagger/activitypub.go | 2 +- 12 files changed, 13 insertions(+), 13 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 4f131fe4e05f9..c204e6211cd18 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. @@ -16,10 +16,10 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" "github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams/vocab" - "github.com/stretchr/testify/assert" ) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 83d5ab72a11a4..bb969f2c3c753 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index 29a286d489c21..095cd43086518 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/activitypub/clock.go b/modules/activitypub/clock.go index 88bd888e2838b..d697c62d9ab06 100644 --- a/modules/activitypub/clock.go +++ b/modules/activitypub/clock.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/activitypub/clock_test.go b/modules/activitypub/clock_test.go index 55b0cbb293708..e5b0c1de81429 100644 --- a/modules/activitypub/clock_test.go +++ b/modules/activitypub/clock_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/activitypub/hack_16834.go b/modules/activitypub/hack_16834.go index b3537c6d32c99..553ea535f9a06 100644 --- a/modules/activitypub/hack_16834.go +++ b/modules/activitypub/hack_16834.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/activitypub/hack_16834_test.go b/modules/activitypub/hack_16834_test.go index 8982afb7b6ade..c1638f6f01c95 100644 --- a/modules/activitypub/hack_16834_test.go +++ b/modules/activitypub/hack_16834_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/activitypub/main_test.go b/modules/activitypub/main_test.go index c2be6f661e750..4410fca27b9f6 100644 --- a/modules/activitypub/main_test.go +++ b/modules/activitypub/main_test.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/modules/structs/activitypub.go b/modules/structs/activitypub.go index 65db69ee2055e..86681bf9d75aa 100644 --- a/modules/structs/activitypub.go +++ b/modules/structs/activitypub.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 60d0143ea266d..3bb54f7790374 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index d422d26fac82a..a7b1d23d94df4 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. diff --git a/routers/api/v1/swagger/activitypub.go b/routers/api/v1/swagger/activitypub.go index 3576439f43a00..afc0c05057d60 100644 --- a/routers/api/v1/swagger/activitypub.go +++ b/routers/api/v1/swagger/activitypub.go @@ -1,4 +1,4 @@ -// Copyright 2021 The Gitea Authors. All rights reserved. +// Copyright 2022 The Gitea Authors. All rights reserved. // Use of this source code is governed by a MIT-style // license that can be found in the LICENSE file. From f9e33d97cccf4de527567e93ff19a3d9d2223abb Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 19 Mar 2022 09:14:08 -0500 Subject: [PATCH 10/94] Run make fmt and make generate-swagger Signed-off-by: Anthony Wang --- modules/activitypub/client.go | 1 + modules/activitypub/client_test.go | 3 ++- modules/activitypub/clock.go | 1 + modules/activitypub/hack_16834_test.go | 4 +++- routers/api/v1/activitypub/person.go | 1 + routers/api/v1/activitypub/reqsignature.go | 1 + templates/swagger/v1_json.tmpl | 1 + 7 files changed, 10 insertions(+), 2 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index bb969f2c3c753..fc87c32f495d8 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -14,6 +14,7 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" "github.com/go-fed/httpsig" ) diff --git a/modules/activitypub/client_test.go b/modules/activitypub/client_test.go index 095cd43086518..b93ef5ac988ab 100644 --- a/modules/activitypub/client_test.go +++ b/modules/activitypub/client_test.go @@ -12,11 +12,12 @@ import ( "regexp" "testing" - _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" + _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 + "github.com/stretchr/testify/assert" ) diff --git a/modules/activitypub/clock.go b/modules/activitypub/clock.go index d697c62d9ab06..fff6c17c3c41f 100644 --- a/modules/activitypub/clock.go +++ b/modules/activitypub/clock.go @@ -8,6 +8,7 @@ import ( "time" "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" ) diff --git a/modules/activitypub/hack_16834_test.go b/modules/activitypub/hack_16834_test.go index c1638f6f01c95..76892a410a20e 100644 --- a/modules/activitypub/hack_16834_test.go +++ b/modules/activitypub/hack_16834_test.go @@ -7,9 +7,11 @@ package activitypub import ( "testing" - _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + + _ "code.gitea.io/gitea/models" // https://discourse.gitea.io/t/testfixtures-could-not-clean-table-access-no-such-table-access/4137/4 + "github.com/stretchr/testify/assert" ) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 3bb54f7790374..6218286f7c0df 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/api/v1/user" + "github.com/go-fed/activity/streams" ) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index a7b1d23d94df4..7be505d8e5717 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -18,6 +18,7 @@ import ( gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" + "github.com/go-fed/activity/pub" "github.com/go-fed/activity/streams" "github.com/go-fed/activity/streams/vocab" diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 390441cde7081..c068612f5171b 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -12753,6 +12753,7 @@ "x-go-package": "code.gitea.io/gitea/modules/structs" }, "ActivityPub": { + "description": "ActivityPub type", "type": "object", "properties": { "@context": { From ea4129e88825e05a1c1cb803190f0351af7c6f60 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 19 Mar 2022 16:36:44 -0500 Subject: [PATCH 11/94] Use Gitea JSON library, add assert for pkp Signed-off-by: Anthony Wang --- integrations/api_activitypub_person_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index c204e6211cd18..6d15ede0e05c5 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -6,13 +6,13 @@ package integrations import ( "context" - "encoding/json" "fmt" "net/http" "net/http/httptest" "net/url" "testing" + "code.gitea.io/gitea/modules/json" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/setting" @@ -37,7 +37,7 @@ func TestActivityPubPerson(t *testing.T) { resp := MakeRequest(t, req, http.StatusOK) assert.Contains(t, resp.Body.String(), "@context") var m map[string]interface{} - _ = json.Unmarshal(resp.Body.Bytes(), &m) + err := json.Unmarshal(resp.Body.Bytes(), &m) var person vocab.ActivityStreamsPerson resolver, _ := streams.NewJSONResolver(func(c context.Context, p vocab.ActivityStreamsPerson) error { @@ -55,6 +55,7 @@ func TestActivityPubPerson(t *testing.T) { assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.GetActivityStreamsInbox().GetIRI().String()) pkp := person.GetW3IDSecurityV1PublicKey() + assert.NotNil(t, pkp) publicKeyID := keyID + "/#main-key" var pkpFound vocab.W3IDSecurityV1PublicKey for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { From 456ed42d3e2069b50e5e99ca2280dc0d2236c150 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 19 Mar 2022 21:25:42 -0500 Subject: [PATCH 12/94] Run make fmt again, fix err var redeclaration Signed-off-by: Anthony Wang --- integrations/api_activitypub_person_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 6d15ede0e05c5..a56852a7a0299 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -12,9 +12,9 @@ import ( "net/url" "testing" - "code.gitea.io/gitea/modules/json" user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/activitypub" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" "github.com/go-fed/activity/pub" @@ -45,7 +45,7 @@ func TestActivityPubPerson(t *testing.T) { return nil }) ctx := context.Background() - err := resolver.Resolve(ctx, m) + err = resolver.Resolve(ctx, m) assert.Equal(t, err, nil) assert.Equal(t, "Person", person.GetTypeName()) assert.Equal(t, username, person.GetActivityStreamsName().Begin().GetXMLSchemaString()) From d75809aeee4984ca520ffb79a6ff28ed62a777db Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 20 Mar 2022 10:09:46 -0500 Subject: [PATCH 13/94] Remove LogSQL from ActivityPub person test Signed-off-by: Anthony Wang --- integrations/api_activitypub_person_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index a56852a7a0299..a3681ca85553d 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -26,10 +26,8 @@ import ( func TestActivityPubPerson(t *testing.T) { onGiteaRun(t, func(*testing.T, *url.URL) { setting.Federation.Enabled = true - setting.Database.LogSQL = true defer func() { setting.Federation.Enabled = false - setting.Database.LogSQL = false }() username := "user2" From ebef7697039f258996eb360ed0ae33b8563fc04a Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 20 Mar 2022 10:51:11 -0500 Subject: [PATCH 14/94] Assert if json.Unmarshal succeeds Signed-off-by: Anthony Wang --- integrations/api_activitypub_person_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index a3681ca85553d..75daf0d81e8d3 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -36,6 +36,7 @@ func TestActivityPubPerson(t *testing.T) { assert.Contains(t, resp.Body.String(), "@context") var m map[string]interface{} err := json.Unmarshal(resp.Body.Bytes(), &m) + assert.Equal(t, err, nil) var person vocab.ActivityStreamsPerson resolver, _ := streams.NewJSONResolver(func(c context.Context, p vocab.ActivityStreamsPerson) error { From 46973f99fac0febd73d04b7a3d8030740a28dc70 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 24 Mar 2022 18:44:44 -0500 Subject: [PATCH 15/94] Cleanup, handle invalid usernames for ActivityPub person GET request Signed-off-by: Anthony Wang --- routers/api/v1/activitypub/person.go | 3 +++ routers/api/v1/activitypub/reqsignature.go | 3 ++- routers/api/v1/api.go | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 6218286f7c0df..5d919df91238e 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -35,6 +35,9 @@ func Person(ctx *context.APIContext) { // "$ref": "#/responses/ActivityPub" user := user.GetUserByParamsName(ctx, "username") + if user == nil { + return + } username := ctx.Params("username") person := streams.NewActivityStreamsPerson() diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 7be505d8e5717..d04225a76d56b 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -13,6 +13,7 @@ import ( "io" "net/http" "net/url" + "time" "code.gitea.io/gitea/modules/activitypub" gitea_context "code.gitea.io/gitea/modules/context" @@ -99,7 +100,7 @@ func fetch(iri *url.URL) (b []byte, err error) { if err != nil { return } - req.Header.Add("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05"))) + req.Header.Add("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format(time.RFC1123))) var resp *http.Response client := &http.Client{} resp, err = client.Do(req) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 4eeefface88b2..fb1af75ec5645 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -599,9 +599,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route { if setting.Federation.Enabled { m.Get("/nodeinfo", misc.NodeInfo) m.Group("/activitypub", func() { - m.Group("/user/{username}", func() { - m.Get("", activitypub.Person) - }) + m.Get("/user/{username}", activitypub.Person) m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) }) } From 3ed4a71a4c78ab559c3c7b8374ba302367fb0825 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 25 Mar 2022 11:53:16 -0500 Subject: [PATCH 16/94] Rename hack_16834 to user_settings Signed-off-by: Anthony Wang --- modules/activitypub/{hack_16834.go => user_settings.go} | 0 .../activitypub/{hack_16834_test.go => user_settings_test.go} | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename modules/activitypub/{hack_16834.go => user_settings.go} (100%) rename modules/activitypub/{hack_16834_test.go => user_settings_test.go} (95%) diff --git a/modules/activitypub/hack_16834.go b/modules/activitypub/user_settings.go similarity index 100% rename from modules/activitypub/hack_16834.go rename to modules/activitypub/user_settings.go diff --git a/modules/activitypub/hack_16834_test.go b/modules/activitypub/user_settings_test.go similarity index 95% rename from modules/activitypub/hack_16834_test.go rename to modules/activitypub/user_settings_test.go index 76892a410a20e..90c6f680f993e 100644 --- a/modules/activitypub/hack_16834_test.go +++ b/modules/activitypub/user_settings_test.go @@ -15,7 +15,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestHack16834(t *testing.T) { +func TestUserSettings(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) user1 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}).(*user_model.User) pub, priv, err := GetKeyPair(user1) From 21c56f8e94660beb8af05ac472d399ce70023ab0 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 27 Mar 2022 12:25:27 -0500 Subject: [PATCH 17/94] Use the httplib module instead of http for GET requests --- routers/api/v1/activitypub/reqsignature.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index d04225a76d56b..fc51410fd3e3d 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/activitypub" gitea_context "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/httplib" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" @@ -89,21 +90,17 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p } func fetch(iri *url.URL) (b []byte, err error) { - var req *http.Request - req, err = http.NewRequest(http.MethodGet, iri.String(), nil) - if err != nil { - return - } - req.Header.Add("Accept", activitypub.ActivityStreamsContentType) - req.Header.Add("Accept-Charset", "utf-8") + var req *httplib.Request + req = httplib.NewRequest(iri.String(), http.MethodGet) + req.Header("Accept", activitypub.ActivityStreamsContentType) + req.Header("Accept-Charset", "utf-8") clock, err := activitypub.NewClock() if err != nil { return } - req.Header.Add("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format(time.RFC1123))) + req.Header("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format(time.RFC1123))) var resp *http.Response - client := &http.Client{} - resp, err = client.Do(req) + resp, err = req.Response() if err != nil { return } From 373a84a8e29ebb893839de6e3f1a6c7c6cd9da85 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 27 Mar 2022 12:25:56 -0500 Subject: [PATCH 18/94] Clean up whitespace with make fmt --- routers/api/v1/activitypub/person.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 5d919df91238e..638ea2ae4e800 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -36,7 +36,7 @@ func Person(ctx *context.APIContext) { user := user.GetUserByParamsName(ctx, "username") if user == nil { - return + return } username := ctx.Params("username") From d1a53f7d6ad7651ed05732aed1c76a7ebad85d6c Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 28 Mar 2022 12:37:52 -0500 Subject: [PATCH 19/94] Use time.RFC1123 and make the http.Client proxy-aware --- modules/activitypub/client.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index fc87c32f495d8..254cec0f83690 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -11,8 +11,10 @@ import ( "encoding/pem" "fmt" "net/http" + "time" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/proxy" "code.gitea.io/gitea/modules/setting" "github.com/go-fed/activity/pub" @@ -84,7 +86,11 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { c = &Client{ clock: clock, - client: &http.Client{}, + client: &http.Client{ + Transport: &http.Transport{ + Proxy: proxy.Proxy(), + }, + }, algs: algos, digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm), getHeaders: setting.Federation.GetHeaders, @@ -106,7 +112,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) } req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("Date", fmt.Sprintf("%s GMT", c.clock.Now().UTC().Format("Mon, 02 Jan 2006 15:04:05"))) + req.Header.Add("Date", fmt.Sprintf("%s GMT", c.clock.Now().UTC().Format(time.RFC1123))) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, 60) if err != nil { From 65016b26645d6fdcf0e7c47fc1214bd8b8e723a2 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 29 Mar 2022 16:38:27 -0500 Subject: [PATCH 20/94] Check if digest algo is supported in setting module --- modules/activitypub/client.go | 7 ++----- modules/setting/federation.go | 9 ++++++++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 254cec0f83690..5c9ea2dd3f165 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -61,9 +61,6 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { return } else if err = containsRequiredHTTPHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil { return - } else if !httpsig.IsSupportedDigestAlgorithm(setting.Federation.DigestAlgorithm) { - err = fmt.Errorf("unsupported digest algorithm: %s", setting.Federation.DigestAlgorithm) - return } algos := make([]httpsig.Algorithm, len(setting.Federation.Algorithms)) for i, algo := range setting.Federation.Algorithms { @@ -85,8 +82,8 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { } c = &Client{ - clock: clock, - client: &http.Client{ + clock: clock, + client: &http.Client{ Transport: &http.Transport{ Proxy: proxy.Proxy(), }, diff --git a/modules/setting/federation.go b/modules/setting/federation.go index 12330c6cf3b6f..8aa481cd981e8 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -4,7 +4,11 @@ package setting -import "code.gitea.io/gitea/modules/log" +import ( + "code.gitea.io/gitea/modules/log" + + "github.com/go-fed/httpsig" +) // Federation settings var ( @@ -26,5 +30,8 @@ var ( func newFederationService() { if err := Cfg.Section("federation").MapTo(&Federation); err != nil { log.Fatal("Failed to map Federation settings: %v", err) + } else if !httpsig.IsSupportedDigestAlgorithm(Federation.DigestAlgorithm) { + log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm) + return } } From 1da0d49de771aa7be917a76fe01d66e79283c5a0 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 30 Mar 2022 15:52:52 -0500 Subject: [PATCH 21/94] Clean up some variable declarations --- integrations/api_activitypub_person_test.go | 12 +++++------- modules/activitypub/client.go | 6 +++--- routers/api/v1/activitypub/person.go | 7 +++++-- routers/api/v1/activitypub/reqsignature.go | 18 ++++++------------ 4 files changed, 19 insertions(+), 24 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 75daf0d81e8d3..107ea10bf0517 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -14,7 +14,6 @@ import ( user_model "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/activitypub" - "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" "github.com/go-fed/activity/pub" @@ -35,8 +34,7 @@ func TestActivityPubPerson(t *testing.T) { resp := MakeRequest(t, req, http.StatusOK) assert.Contains(t, resp.Body.String(), "@context") var m map[string]interface{} - err := json.Unmarshal(resp.Body.Bytes(), &m) - assert.Equal(t, err, nil) + DecodeJSON(t, resp, &m) var person vocab.ActivityStreamsPerson resolver, _ := streams.NewJSONResolver(func(c context.Context, p vocab.ActivityStreamsPerson) error { @@ -44,8 +42,8 @@ func TestActivityPubPerson(t *testing.T) { return nil }) ctx := context.Background() - err = resolver.Resolve(ctx, m) - assert.Equal(t, err, nil) + err := resolver.Resolve(ctx, m) + assert.NoError(t, err) assert.Equal(t, "Person", person.GetTypeName()) assert.Equal(t, username, person.GetActivityStreamsName().Begin().GetXMLSchemaString()) keyID := person.GetJSONLDId().GetIRI().String() @@ -124,10 +122,10 @@ func TestActivityPubPersonInbox(t *testing.T) { // Signed request succeeds resp, err := c.Post([]byte{}, user2inboxurl) assert.NoError(t, err) - assert.Equal(t, 204, resp.StatusCode) + assert.Equal(t, http.StatusNoContent, resp.StatusCode) // Unsigned request fails req := NewRequest(t, "POST", user2inboxurl) - MakeRequest(t, req, 500) + MakeRequest(t, req, http.StatusInternalServerError) }) } diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 5c9ea2dd3f165..0720909126e72 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -23,7 +23,7 @@ import ( const ( // ActivityStreamsContentType const - ActivityStreamsContentType = "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" + ActivityStreamsContentType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"` ) func containsRequiredHTTPHeaders(method string, headers []string) error { @@ -31,13 +31,13 @@ func containsRequiredHTTPHeaders(method string, headers []string) error { for _, header := range headers { hasRequestTarget = hasRequestTarget || header == httpsig.RequestTarget hasDate = hasDate || header == "Date" - hasDigest = method == "GET" || hasDigest || header == "Digest" + hasDigest = hasDigest || header == "Digest" } if !hasRequestTarget { return fmt.Errorf("missing http header for %s: %s", method, httpsig.RequestTarget) } else if !hasDate { return fmt.Errorf("missing http header for %s: Date", method) - } else if !hasDigest { + } else if !hasDigest && method != http.MethodGet { return fmt.Errorf("missing http header for %s: Digest", method) } return nil diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 638ea2ae4e800..4be076a9ce835 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -78,6 +78,7 @@ func Person(ctx *context.APIContext) { publicKeyPemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty() if publicKeyPem, err := activitypub.GetPublicKey(user); err != nil { ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) + return } else { publicKeyPemProp.Set(publicKeyPem) } @@ -86,8 +87,10 @@ func Person(ctx *context.APIContext) { publicKeyProp.AppendW3IDSecurityV1PublicKey(publicKeyType) person.SetW3IDSecurityV1PublicKey(publicKeyProp) - var jsonmap map[string]interface{} - jsonmap, _ = streams.Serialize(person) + jsonmap, err := streams.Serialize(person) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Serialize", err) + } ctx.JSON(http.StatusOK, jsonmap) } diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index fc51410fd3e3d..b9f665da104f5 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -79,8 +79,7 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p return } pubKeyPem := pkPemProp.Get() - var block *pem.Block - block, _ = pem.Decode([]byte(pubKeyPem)) + block, _ := pem.Decode([]byte(pubKeyPem)) if block == nil || block.Type != "PUBLIC KEY" { err = fmt.Errorf("could not decode publicKeyPem to PUBLIC KEY pem block type") return @@ -90,8 +89,7 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p } func fetch(iri *url.URL) (b []byte, err error) { - var req *httplib.Request - req = httplib.NewRequest(iri.String(), http.MethodGet) + req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") clock, err := activitypub.NewClock() @@ -99,8 +97,7 @@ func fetch(iri *url.URL) (b []byte, err error) { return } req.Header("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format(time.RFC1123))) - var resp *http.Response - resp, err = req.Response() + resp, err := req.Response() if err != nil { return } @@ -118,20 +115,17 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er r := ctx.Req // 1. Figure out what key we need to verify - var v httpsig.Verifier - v, err = httpsig.NewVerifier(r) + v, err := httpsig.NewVerifier(r) if err != nil { return } ID := v.KeyId() - var idIRI *url.URL - idIRI, err = url.Parse(ID) + idIRI, err := url.Parse(ID) if err != nil { return } // 2. Fetch the public key of the other actor - var b []byte - b, err = fetch(idIRI) + b, err := fetch(idIRI) if err != nil { return } From fdae736f2217df294f190f272bc0cd6eeb3c405b Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 30 Mar 2022 16:29:47 -0500 Subject: [PATCH 22/94] Remove unneeded copy --- modules/activitypub/client.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 0720909126e72..9cd9f0dc38187 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -100,9 +100,7 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { // NewRequest function func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) { - byteCopy := make([]byte, len(b)) - copy(byteCopy, b) - buf := bytes.NewBuffer(byteCopy) + buf := bytes.NewBuffer(b) req, err = http.NewRequest(http.MethodPost, to, buf) if err != nil { return From 7ea5e108a58540a07390a26d40d9e36db8781ec2 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 30 Mar 2022 17:51:06 -0500 Subject: [PATCH 23/94] Use system timezone instead of setting.DefaultUILocation --- modules/activitypub/clock.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/modules/activitypub/clock.go b/modules/activitypub/clock.go index fff6c17c3c41f..f8970102e7813 100644 --- a/modules/activitypub/clock.go +++ b/modules/activitypub/clock.go @@ -7,8 +7,6 @@ package activitypub import ( "time" - "code.gitea.io/gitea/modules/setting" - "github.com/go-fed/activity/pub" ) @@ -25,5 +23,5 @@ func NewClock() (c *Clock, err error) { // Now function func (c *Clock) Now() time.Time { - return time.Now().In(setting.DefaultUILocation) + return time.Now().Local() } From 5139b3dc194fa2cd6f36cf9fbbf62d75d7bd1f55 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 13 Apr 2022 09:05:24 -0500 Subject: [PATCH 24/94] Use named constant for httpsigExpirationTime --- modules/activitypub/client.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 9cd9f0dc38187..a11284dbcec49 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -24,6 +24,7 @@ import ( const ( // ActivityStreamsContentType const ActivityStreamsContentType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"` + httpsigExpirationTime = 60 ) func containsRequiredHTTPHeaders(method string, headers []string) error { @@ -109,7 +110,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) req.Header.Add("Accept-Charset", "utf-8") req.Header.Add("Date", fmt.Sprintf("%s GMT", c.clock.Now().UTC().Format(time.RFC1123))) - signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, 60) + signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { return } From 7931e210e5ce37c4f9aa16033fd8b64b52fcfeb5 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 13 Apr 2022 11:19:17 -0500 Subject: [PATCH 25/94] Make pubKey IRI #main-key instead of /#main-key --- routers/api/v1/activitypub/person.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 4be076a9ce835..9df834dd4d8fa 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -67,7 +67,7 @@ func Person(ctx *context.APIContext) { publicKeyType := streams.NewW3IDSecurityV1PublicKey() pubKeyIDProp := streams.NewJSONLDIdProperty() - pubKeyIRI, _ := url.Parse(link + "/#main-key") + pubKeyIRI, _ := url.Parse(link + "#main-key") pubKeyIDProp.SetIRI(pubKeyIRI) publicKeyType.SetJSONLDId(pubKeyIDProp) From 702a9633080a276b0cf4db9da9c72ade8825eb46 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 13 Apr 2022 21:34:12 -0500 Subject: [PATCH 26/94] Move /#main-key to #main-key in tests --- integrations/api_activitypub_person_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 107ea10bf0517..14eec69250fc2 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -53,7 +53,7 @@ func TestActivityPubPerson(t *testing.T) { pkp := person.GetW3IDSecurityV1PublicKey() assert.NotNil(t, pkp) - publicKeyID := keyID + "/#main-key" + publicKeyID := keyID + "#main-key" var pkpFound vocab.W3IDSecurityV1PublicKey for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { if !pkpIter.IsW3IDSecurityV1PublicKey() { @@ -113,7 +113,7 @@ func TestActivityPubPersonInbox(t *testing.T) { username1 := "user1" user1, err := user_model.GetUserByName(username1) assert.NoError(t, err) - user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s/#main-key", srv.URL, username1) + user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s#main-key", srv.URL, username1) c, err := activitypub.NewClient(user1, user1url) assert.NoError(t, err) username2 := "user2" From 523ca3d89b4185494a7f66b4646fd3c14aba7bcc Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 20 Apr 2022 21:03:00 +0100 Subject: [PATCH 27/94] Implemented Webfinger endpoint. --- routers/web/web.go | 1 + routers/web/webfinger.go | 112 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 routers/web/webfinger.go diff --git a/routers/web/web.go b/routers/web/web.go index 9faa61e560560..53304dac90caf 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -242,6 +242,7 @@ func RegisterRoutes(m *web.Route) { m.Get("/openid-configuration", auth.OIDCWellKnown) if setting.Federation.Enabled { m.Get("/nodeinfo", NodeInfoLinks) + m.Get("/webfinger", WebfingerQuery) } m.Get("/change-password", func(w http.ResponseWriter, req *http.Request) { http.Redirect(w, req, "/user/settings/account", http.StatusTemporaryRedirect) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go new file mode 100644 index 0000000000000..22008765fabee --- /dev/null +++ b/routers/web/webfinger.go @@ -0,0 +1,112 @@ +// Copyright 2022 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package web + +import ( + "fmt" + "net/http" + "net/url" + "regexp" + "strings" + + user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/log" + "code.gitea.io/gitea/modules/setting" +) + +var webfingerRessourcePattern = regexp.MustCompile(`(?i)\A([a-z^:]+):(.*)\z`) + +// https://datatracker.ietf.org/doc/html/draft-ietf-appsawg-webfinger-14#section-4.4 + +type webfingerJRD struct { + Subject string `json:"subject,omitempty"` + Aliases []string `json:"aliases,omitempty"` + Properties map[string]interface{} `json:"properties,omitempty"` + Links []*webfingerLink `json:"links,omitempty"` +} + +type webfingerLink struct { + Rel string `json:"rel,omitempty"` + Type string `json:"type,omitempty"` + Href string `json:"href,omitempty"` + Titles map[string]string `json:"titles,omitempty"` + Properties map[string]interface{} `json:"properties,omitempty"` +} + +// WebfingerQuery returns informations about a resource +// https://datatracker.ietf.org/doc/html/rfc7565 +func WebfingerQuery(ctx *context.Context) { + resource := ctx.FormTrim("resource") + + scheme := "acct" + uri := resource + + match := webfingerRessourcePattern.FindStringSubmatch(resource) + if match != nil { + scheme = match[1] + uri = match[2] + } + + appURL, _ := url.Parse(setting.AppURL) + + var u *user_model.User + var err error + + switch scheme { + case "acct": + // allow only the current host + parts := strings.SplitN(uri, "@", 2) + if len(parts) != 2 { + ctx.Error(http.StatusBadRequest) + return + } + if parts[1] != appURL.Host { + ctx.Error(http.StatusBadRequest) + return + } + + u, err = user_model.GetUserByNameCtx(ctx, parts[0]) + case "mailto": + u, err = user_model.GetUserByEmailContext(ctx, uri) + default: + ctx.Error(http.StatusBadRequest) + return + } + if err != nil { + if user_model.IsErrUserNotExist(err) { + ctx.Error(http.StatusNotFound) + } else { + log.Error("Error getting user: %v", err) + ctx.Error(http.StatusInternalServerError) + } + return + } + + // Should we check IsUserVisibleToViewer here? + + aliases := make([]string, 0, 1) + if !u.KeepEmailPrivate { + aliases = append(aliases, fmt.Sprintf("mailto:%s", u.Email)) + } + + links := []*webfingerLink{ + { + Rel: "http://webfinger.net/rel/profile-page", + Type: "text/html", + Href: u.HTMLURL(), + }, + { + Rel: "http://webfinger.net/rel/avatar", + Href: u.AvatarLink(), + }, + } + + ctx.JSON(http.StatusOK, &webfingerJRD{ + Subject: fmt.Sprintf("acct:%s@%s", url.QueryEscape(u.Name), appURL.Host), + Aliases: aliases, + Links: links, + }) +} From 0d120f8a8dae9482cc3813eeb06108e5b76a80f4 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 22 Apr 2022 13:55:58 +0000 Subject: [PATCH 28/94] Add visible check. --- routers/web/webfinger.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 22008765fabee..c6f915a6e46a1 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -85,7 +85,10 @@ func WebfingerQuery(ctx *context.Context) { return } - // Should we check IsUserVisibleToViewer here? + if !user_model.IsUserVisibleToViewer(u, ctx.Doer) { + ctx.Error(http.StatusNotFound) + return + } aliases := make([]string, 0, 1) if !u.KeepEmailPrivate { From 5d61e5955be348d6d448de5c4ed102c2468ca93b Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Fri, 22 Apr 2022 13:56:17 +0000 Subject: [PATCH 29/94] Add user profile as alias. --- routers/web/webfinger.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index c6f915a6e46a1..3e8f4078490ea 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -90,7 +90,9 @@ func WebfingerQuery(ctx *context.Context) { return } - aliases := make([]string, 0, 1) + aliases := []string{ + u.HTMLURL(), + } if !u.KeepEmailPrivate { aliases = append(aliases, fmt.Sprintf("mailto:%s", u.Email)) } From aa962c6ee93f9e6e3bb95a64287baad665f48a3a Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 22 Apr 2022 11:10:26 -0500 Subject: [PATCH 30/94] Add actor IRI and remote interaction URL to WebFinger response --- routers/web/webfinger.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 3e8f4078490ea..02cbe1af21fbc 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -92,6 +92,7 @@ func WebfingerQuery(ctx *context.Context) { aliases := []string{ u.HTMLURL(), + appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), } if !u.KeepEmailPrivate { aliases = append(aliases, fmt.Sprintf("mailto:%s", u.Email)) @@ -107,6 +108,15 @@ func WebfingerQuery(ctx *context.Context) { Rel: "http://webfinger.net/rel/avatar", Href: u.AvatarLink(), }, + { + Rel: "self", + Type: "application/activity+json", + Href: appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), + }, + { + Rel: "http://ostatus.org/schema/1.0/subscribe", + Href: appURL.String() + "api/v1/authorize_interaction?uri={uri}", + }, } ctx.JSON(http.StatusOK, &webfingerJRD{ From 55c5e930dbe8ddc335f5cdd47085443abe1d1a10 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 9 May 2022 19:48:10 +0200 Subject: [PATCH 31/94] fmt --- modules/activitypub/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index a11284dbcec49..0e4998234a27c 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -24,7 +24,7 @@ import ( const ( // ActivityStreamsContentType const ActivityStreamsContentType = `application/ld+json; profile="https://www.w3.org/ns/activitystreams"` - httpsigExpirationTime = 60 + httpsigExpirationTime = 60 ) func containsRequiredHTTPHeaders(method string, headers []string) error { From 364838c11bb52aac5a13942088ef42b0d9fcaeb1 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 9 May 2022 19:10:45 -0500 Subject: [PATCH 32/94] Fix lint errors --- modules/activitypub/main_test.go | 3 ++- routers/api/v1/activitypub/person.go | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/activitypub/main_test.go b/modules/activitypub/main_test.go index 4410fca27b9f6..289bc9f32b119 100644 --- a/modules/activitypub/main_test.go +++ b/modules/activitypub/main_test.go @@ -12,5 +12,6 @@ import ( ) func TestMain(m *testing.M) { - unittest.MainTest(m, filepath.Join("..", "..")) + testOps := unittest.TestOptions{GiteaRootPath: filepath.Join("..", "..")} + unittest.MainTest(m, &testOps) } diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 9df834dd4d8fa..7b9b238177eb5 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -76,12 +76,12 @@ func Person(ctx *context.APIContext) { publicKeyType.SetW3IDSecurityV1Owner(ownerProp) publicKeyPemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty() - if publicKeyPem, err := activitypub.GetPublicKey(user); err != nil { + publicKeyPem, err := activitypub.GetPublicKey(user) + if err != nil { ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) return - } else { - publicKeyPemProp.Set(publicKeyPem) } + publicKeyPemProp.Set(publicKeyPem) publicKeyType.SetW3IDSecurityV1PublicKeyPem(publicKeyPemProp) publicKeyProp.AppendW3IDSecurityV1PublicKey(publicKeyType) From becdf5e1f17a8176b3e36db487f547b3179a6350 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 23 May 2022 11:43:59 -0500 Subject: [PATCH 33/94] Use go-ap instead of go-fed --- go.mod | 5 +- go.sum | 16 +++--- integrations/api_activitypub_person_test.go | 4 +- modules/activitypub/client.go | 9 +-- modules/activitypub/clock.go | 27 --------- modules/activitypub/clock_test.go | 30 ---------- routers/api/v1/activitypub/person.go | 58 ++++++------------- routers/api/v1/activitypub/reqsignature.go | 62 +++------------------ 8 files changed, 38 insertions(+), 173 deletions(-) delete mode 100644 modules/activitypub/clock.go delete mode 100644 modules/activitypub/clock_test.go diff --git a/go.mod b/go.mod index ceefebceea225..d2375544ce77c 100644 --- a/go.mod +++ b/go.mod @@ -26,10 +26,10 @@ require ( github.com/emirpasic/gods v1.12.0 github.com/ethantkoenig/rupture v1.0.1 github.com/gliderlabs/ssh v0.3.3 + github.com/go-ap/activitypub v0.0.0-20220420091113-4837641dc83b github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.0 github.com/go-enry/go-enry/v2 v2.8.0 - github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e github.com/go-git/go-billy/v5 v5.3.1 github.com/go-git/go-git/v5 v5.4.3-0.20210630082519-b4368b2a2ca4 @@ -106,6 +106,7 @@ require ( require ( cloud.google.com/go v0.99.0 // indirect + git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20200411073322-f0bcc40f0bf2 // indirect github.com/Azure/go-ntlmssp v0.0.0-20211209120228-48547f28849e // indirect github.com/Microsoft/go-winio v0.5.2 // indirect github.com/ProtonMail/go-crypto v0.0.0-20220113124808-70ae35bab23f // indirect @@ -158,6 +159,7 @@ require ( github.com/fsnotify/fsnotify v1.5.1 // indirect github.com/fullstorydev/grpcurl v1.8.1 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect + github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 // indirect github.com/go-asn1-ber/asn1-ber v1.5.3 // indirect github.com/go-enry/go-oniguruma v1.2.1 // indirect github.com/go-git/gcfg v1.5.0 // indirect @@ -251,6 +253,7 @@ require ( github.com/toqueteos/webbrowser v1.2.0 // indirect github.com/ulikunitz/xz v0.5.10 // indirect github.com/unknwon/com v1.0.1 // indirect + github.com/valyala/fastjson v1.6.3 // indirect github.com/x448/float16 v0.8.4 // indirect github.com/xanzy/ssh-agent v0.3.1 // indirect github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect diff --git a/go.sum b/go.sum index 40a4cbbb051e9..ff16c0a201602 100644 --- a/go.sum +++ b/go.sum @@ -69,6 +69,8 @@ contrib.go.opencensus.io/exporter/stackdriver v0.13.5/go.mod h1:aXENhDJ1Y4lIg4EU contrib.go.opencensus.io/integrations/ocsql v0.1.4/go.mod h1:8DsSdjz3F+APR+0z0WkU1aRorQCFfRxvqjUUPMbF3fE= contrib.go.opencensus.io/resource v0.1.1/go.mod h1:F361eGI91LCmW1I/Saf+rX0+OFcigGlFvXwEGEnkRLA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20200411073322-f0bcc40f0bf2 h1:2OrsyJYZp7J6nyAsKi2q1SELYRaIc0aQmcQ/EQqPfk8= +git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20200411073322-f0bcc40f0bf2/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs= gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs= gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc= gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0= @@ -356,7 +358,6 @@ github.com/creack/pty v1.1.11/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY= github.com/daaku/go.zipexe v1.0.0/go.mod h1:z8IiR6TsVLEYKwXAoE/I+8ys/sDkgTzSL0CLnGVd57E= github.com/daaku/go.zipexe v1.0.1/go.mod h1:5xWogtqlYnfBXkSB1o9xysukNP9GTvaNkqzUZbt3Bw8= -github.com/dave/jennifer v1.3.0/go.mod h1:fIb+770HOpJ2fmN9EPPKOqm1vMGhB+TwXKMZhrIygKg= github.com/davecgh/go-spew v0.0.0-20161028175848-04cdfd42973b/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -452,6 +453,10 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= +github.com/go-ap/activitypub v0.0.0-20220420091113-4837641dc83b h1:Hh6VfXJpz8yIj9X+L7I/sbMYyg/yxzq0n/5gpiptd/k= +github.com/go-ap/activitypub v0.0.0-20220420091113-4837641dc83b/go.mod h1:MB3P8x1tiEf6sOEfXnHEep23Zp+onx2HcD8G4eILAkM= +github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 h1:AUG8+r0Q/zbNUAi5CWVBK5oUhOZDX3Kkr+oWURaJIfU= +github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= github.com/go-asn1-ber/asn1-ber v1.5.1/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= github.com/go-asn1-ber/asn1-ber v1.5.3 h1:u7utq56RUFiynqUzgVMFDymapcOtQ/MZkh3H4QYkxag= github.com/go-asn1-ber/asn1-ber v1.5.3/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= @@ -465,9 +470,6 @@ github.com/go-enry/go-enry/v2 v2.8.0 h1:KMW4mSG+8uUF6FaD3iPkFqyfC5tF8gRrsYImq6yh github.com/go-enry/go-enry/v2 v2.8.0/go.mod h1:GVzIiAytiS5uT/QiuakK7TF1u4xDab87Y8V5EJRpsIQ= github.com/go-enry/go-oniguruma v1.2.1 h1:k8aAMuJfMrqm/56SG2lV9Cfti6tC4x8673aHCcBk+eo= github.com/go-enry/go-oniguruma v1.2.1/go.mod h1:bWDhYP+S6xZQgiRL7wlTScFYBe023B6ilRZbCAD5Hf4= -github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0 h1:rV8Mp/ChJLd0ZUrS6xMwiP6ZIFpSomffrQOjf4Xyd3M= -github.com/go-fed/activity v1.0.1-0.20220119073622-b14b50eecad0/go.mod h1:v4QoPaAzjWZ8zN2VFVGL5ep9C02mst0hQYHUpQwso4Q= -github.com/go-fed/httpsig v0.1.1-0.20190914113940-c2de3672e5b5/go.mod h1:T56HUNYZUQ1AGUzhAYPugZfp36sKApVnGBgKlIY+aIE= github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e h1:oRq/fiirun5HqlEWMLIcDmLpIELlG4iGbd0s8iqgPi8= github.com/go-fed/httpsig v1.1.1-0.20201223112313-55836744818e/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/go-git/gcfg v1.5.0 h1:Q5ViNfGF8zFgyJWPqYwA7qGFoMTEiBmdlkcfRmpIMa4= @@ -614,8 +616,6 @@ github.com/go-swagger/go-swagger v0.29.0/go.mod h1:Z4GJzI+bHKKkGB2Ji1rawpi3/ldXX github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0= github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-test/deep v1.0.1 h1:UQhStjbkDClarlmv0am7OXXO4/GaPdCGiUiMTvi28sg= -github.com/go-test/deep v1.0.1/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/go-testfixtures/testfixtures/v3 v3.6.1 h1:n4Fv95Exp0D05G6l6CAZv22Ck1EJK0pa0TfPqE4ncSs= github.com/go-testfixtures/testfixtures/v3 v3.6.1/go.mod h1:Bsb2MoHAfHnNsPpSwAjtOs102mqDuM+1u3nE2OCi0N0= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= @@ -1519,6 +1519,8 @@ github.com/urfave/cli v1.22.4/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= +github.com/valyala/fastjson v1.6.3 h1:tAKFnnwmeMGPbwJ7IwxcTPCNr3uIzoIj3/Fh90ra4xc= +github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY= github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8= github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw= github.com/weppos/publicsuffix-go v0.13.1-0.20210123135404-5fd73613514e/go.mod h1:HYux0V0Zi04bHNwOHy4cXJVz/TQjYonnF6aoYhj+3QE= @@ -1651,7 +1653,6 @@ go.uber.org/zap v1.21.0 h1:WefMeulhovoZ2sYXz7st6K0sLj7bBhpiFaud4r4zST8= go.uber.org/zap v1.21.0/go.mod h1:wjWOCqI0f2ZZrJF/UufIOkiC8ii6tm1iqIsLo76RfJw= gocloud.dev v0.19.0/go.mod h1:SmKwiR8YwIMMJvQBKLsC3fHNyMwXLw3PMDO+VVteJMI= golang.org/x/crypto v0.0.0-20180501155221-613d6eafa307/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= -golang.org/x/crypto v0.0.0-20180527072434-ab813273cd59/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -1848,7 +1849,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20180525142821-c11f84a56e43/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 14eec69250fc2..f3479e65c8bfb 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -16,9 +16,7 @@ import ( "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/setting" - "github.com/go-fed/activity/pub" - "github.com/go-fed/activity/streams" - "github.com/go-fed/activity/streams/vocab" + "github.com/go-ap/activitypub" "github.com/stretchr/testify/assert" ) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 0e4998234a27c..bbc0d3de218f0 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -17,7 +17,6 @@ import ( "code.gitea.io/gitea/modules/proxy" "code.gitea.io/gitea/modules/setting" - "github.com/go-fed/activity/pub" "github.com/go-fed/httpsig" ) @@ -46,7 +45,6 @@ func containsRequiredHTTPHeaders(method string, headers []string) error { // Client struct type Client struct { - clock pub.Clock client *http.Client algs []httpsig.Algorithm digestAlg httpsig.DigestAlgorithm @@ -67,10 +65,6 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { for i, algo := range setting.Federation.Algorithms { algos[i] = httpsig.Algorithm(algo) } - clock, err := NewClock() - if err != nil { - return - } priv, err := GetPrivateKey(user) if err != nil { @@ -83,7 +77,6 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { } c = &Client{ - clock: clock, client: &http.Client{ Transport: &http.Transport{ Proxy: proxy.Proxy(), @@ -108,7 +101,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) } req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("Date", fmt.Sprintf("%s GMT", c.clock.Now().UTC().Format(time.RFC1123))) + req.Header.Add("Date", fmt.Sprintf("%s GMT", time.Now().UTC().Format(time.RFC1123))) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { diff --git a/modules/activitypub/clock.go b/modules/activitypub/clock.go deleted file mode 100644 index f8970102e7813..0000000000000 --- a/modules/activitypub/clock.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2022 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package activitypub - -import ( - "time" - - "github.com/go-fed/activity/pub" -) - -var _ pub.Clock = &Clock{} - -// Clock struct -type Clock struct{} - -// NewClock function -func NewClock() (c *Clock, err error) { - c = &Clock{} - return -} - -// Now function -func (c *Clock) Now() time.Time { - return time.Now().Local() -} diff --git a/modules/activitypub/clock_test.go b/modules/activitypub/clock_test.go deleted file mode 100644 index e5b0c1de81429..0000000000000 --- a/modules/activitypub/clock_test.go +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 The Gitea Authors. All rights reserved. -// Use of this source code is governed by a MIT-style -// license that can be found in the LICENSE file. - -package activitypub - -import ( - "regexp" - "testing" - "time" - - "code.gitea.io/gitea/modules/setting" - - "github.com/stretchr/testify/assert" -) - -func TestClock(t *testing.T) { - DefaultUILocation := setting.DefaultUILocation - defer func() { - setting.DefaultUILocation = DefaultUILocation - }() - c, err := NewClock() - assert.NoError(t, err) - setting.DefaultUILocation, err = time.LoadLocation("UTC") - assert.NoError(t, err) - assert.Regexp(t, regexp.MustCompile(`\+0000$`), c.Now().Format(time.Layout)) - setting.DefaultUILocation, err = time.LoadLocation("Europe/Paris") - assert.NoError(t, err) - assert.Regexp(t, regexp.MustCompile(`\+0[21]00$`), c.Now().Format(time.Layout)) -} diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 7b9b238177eb5..d829888cc2cd7 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -6,7 +6,6 @@ package activitypub import ( "net/http" - "net/url" "strings" "code.gitea.io/gitea/modules/activitypub" @@ -14,7 +13,7 @@ import ( "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/api/v1/user" - "github.com/go-fed/activity/streams" + ap "github.com/go-ap/activitypub" ) // Person function @@ -39,59 +38,34 @@ func Person(ctx *context.APIContext) { return } username := ctx.Params("username") - - person := streams.NewActivityStreamsPerson() - - id := streams.NewJSONLDIdProperty() + link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/") - idIRI, _ := url.Parse(link) - id.SetIRI(idIRI) - person.SetJSONLDId(id) - - name := streams.NewActivityStreamsNameProperty() - name.AppendXMLSchemaString(username) - person.SetActivityStreamsName(name) - - ibox := streams.NewActivityStreamsInboxProperty() - urlObject, _ := url.Parse(link + "/inbox") - ibox.SetIRI(urlObject) - person.SetActivityStreamsInbox(ibox) + person := ap.PersonNew(ap.IRI(link)) - obox := streams.NewActivityStreamsOutboxProperty() - urlObject, _ = url.Parse(link + "/outbox") - obox.SetIRI(urlObject) - person.SetActivityStreamsOutbox(obox) + name := ap.NaturalLanguageValuesNew() + name.Set("en", ap.Content(username)) + person.Name = name - publicKeyProp := streams.NewW3IDSecurityV1PublicKeyProperty() + person.Inbox = ap.Item(ap.IRI(link + "/inbox")) + person.Outbox = ap.Item(ap.IRI(link + "/outbox")) - publicKeyType := streams.NewW3IDSecurityV1PublicKey() - - pubKeyIDProp := streams.NewJSONLDIdProperty() - pubKeyIRI, _ := url.Parse(link + "#main-key") - pubKeyIDProp.SetIRI(pubKeyIRI) - publicKeyType.SetJSONLDId(pubKeyIDProp) - - ownerProp := streams.NewW3IDSecurityV1OwnerProperty() - ownerProp.SetIRI(idIRI) - publicKeyType.SetW3IDSecurityV1Owner(ownerProp) - - publicKeyPemProp := streams.NewW3IDSecurityV1PublicKeyPemProperty() + person.PublicKey.ID = ap.IRI(link + "#main-key") + person.PublicKey.Owner = ap.IRI(link) + publicKeyPem, err := activitypub.GetPublicKey(user) if err != nil { ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) return } - publicKeyPemProp.Set(publicKeyPem) - publicKeyType.SetW3IDSecurityV1PublicKeyPem(publicKeyPemProp) - - publicKeyProp.AppendW3IDSecurityV1PublicKey(publicKeyType) - person.SetW3IDSecurityV1PublicKey(publicKeyProp) + person.PublicKey.PublicKeyPem = publicKeyPem - jsonmap, err := streams.Serialize(person) + binary, err := person.MarshalJSON() if err != nil { ctx.Error(http.StatusInternalServerError, "Serialize", err) } - ctx.JSON(http.StatusOK, jsonmap) + ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8") + ctx.Write(binary) + ctx.Status(http.StatusOK) } // PersonInbox function diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index b9f665da104f5..6c4d289c48fc9 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -18,67 +18,25 @@ import ( "code.gitea.io/gitea/modules/activitypub" gitea_context "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/httplib" - "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" - "github.com/go-fed/activity/pub" - "github.com/go-fed/activity/streams" - "github.com/go-fed/activity/streams/vocab" + ap "github.com/go-ap/activitypub" "github.com/go-fed/httpsig" ) -type publicKeyer interface { - GetW3IDSecurityV1PublicKey() vocab.W3IDSecurityV1PublicKeyProperty -} - func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p crypto.PublicKey, err error) { - m := make(map[string]interface{}) - err = json.Unmarshal(b, &m) - if err != nil { - return - } - var t vocab.Type - t, err = streams.ToType(ctx, m) + person := ap.PersonNew(ap.IRI(keyID.String())) + err = person.UnmarshalJSON(b) if err != nil { + err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %T", b) return } - pker, ok := t.(publicKeyer) - if !ok { - err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %T", t) - return - } - pkp := pker.GetW3IDSecurityV1PublicKey() - if pkp == nil { - err = fmt.Errorf("publicKey property is not provided") - return - } - var pkpFound vocab.W3IDSecurityV1PublicKey - for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { - if !pkpIter.IsW3IDSecurityV1PublicKey() { - continue - } - pkValue := pkpIter.Get() - var pkID *url.URL - pkID, err = pub.GetId(pkValue) - if err != nil { - return - } - if pkID.String() != keyID.String() { - continue - } - pkpFound = pkValue - break - } - if pkpFound == nil { + pkey := person.PublicKey + if pkey.ID.String() != keyID.String() { err = fmt.Errorf("cannot find publicKey with id: %s in %s", keyID, b) return } - pkPemProp := pkpFound.GetW3IDSecurityV1PublicKeyPem() - if pkPemProp == nil || !pkPemProp.IsXMLSchemaString() { - err = fmt.Errorf("publicKeyPem property is not provided or it is not embedded as a value") - return - } - pubKeyPem := pkPemProp.Get() + pubKeyPem := pkey.PublicKeyPem block, _ := pem.Decode([]byte(pubKeyPem)) if block == nil || block.Type != "PUBLIC KEY" { err = fmt.Errorf("could not decode publicKeyPem to PUBLIC KEY pem block type") @@ -92,11 +50,7 @@ func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") - clock, err := activitypub.NewClock() - if err != nil { - return - } - req.Header("Date", fmt.Sprintf("%s GMT", clock.Now().UTC().Format(time.RFC1123))) + req.Header("Date", fmt.Sprintf("%s GMT", time.Now().UTC().Format(time.RFC1123))) resp, err := req.Response() if err != nil { return From 67e0fcdd76b7f07fdc3b87bb4115ab38f75326df Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 9 Jun 2022 17:22:59 -0500 Subject: [PATCH 34/94] Run go mod tidy to fix missing modules in go.mod and go.sum --- go.mod | 2 ++ go.sum | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 11f7282c93124..ed26b607473d5 100644 --- a/go.mod +++ b/go.mod @@ -27,6 +27,7 @@ require ( github.com/emirpasic/gods v1.18.1 github.com/ethantkoenig/rupture v1.0.1 github.com/gliderlabs/ssh v0.3.4 + github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068 github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.1 github.com/go-enry/go-enry/v2 v2.8.2 @@ -160,6 +161,7 @@ require ( github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/fullstorydev/grpcurl v1.8.1 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect + github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369 // indirect github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect github.com/go-enry/go-oniguruma v1.2.1 // indirect diff --git a/go.sum b/go.sum index 047331143f28b..233314aa1e8d5 100644 --- a/go.sum +++ b/go.sum @@ -199,6 +199,7 @@ github.com/aws/aws-sdk-go v1.23.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi github.com/aws/aws-sdk-go v1.25.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= +github.com/aws/aws-sdk-go v1.43.21/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= @@ -283,6 +284,7 @@ github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s= github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= @@ -326,11 +328,13 @@ github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkE github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= +github.com/coreos/go-oidc v2.2.1+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= +github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= @@ -349,6 +353,7 @@ github.com/couchbase/goutils v0.0.0-20210118111533-e33d3ffb5401 h1:4KDlx3vjalrHD github.com/couchbase/goutils v0.0.0-20210118111533-e33d3ffb5401/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= github.com/couchbase/moss v0.1.0/go.mod h1:9MaHIaRuy9pvLPUJxB8sh8OrLfyDczECVL37grCIubs= github.com/couchbase/moss v0.2.0/go.mod h1:9MaHIaRuy9pvLPUJxB8sh8OrLfyDczECVL37grCIubs= +github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -460,8 +465,10 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= -github.com/go-ap/activitypub v0.0.0-20220420091113-4837641dc83b h1:Hh6VfXJpz8yIj9X+L7I/sbMYyg/yxzq0n/5gpiptd/k= -github.com/go-ap/activitypub v0.0.0-20220420091113-4837641dc83b/go.mod h1:MB3P8x1tiEf6sOEfXnHEep23Zp+onx2HcD8G4eILAkM= +github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068 h1:Xzxc/HjHFAwJTieEWcC1SjBHVBq+Y1xPgk7WWcG3sjs= +github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068/go.mod h1:h5U5YGW+z4mVF3XH6bKfBmsJinRVuKpS23uYqJfGSbo= +github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369 h1:z09Qf9XB5lU3NBZnrsN9VJqrIgwKLrsBVUgrir4zL9A= +github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369/go.mod h1:yENIaXEY5AiFL/qGTBBcPuk40I5SLyZzwrQj2ID5PHQ= github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 h1:AUG8+r0Q/zbNUAi5CWVBK5oUhOZDX3Kkr+oWURaJIfU= github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= github.com/go-asn1-ber/asn1-ber v1.5.4 h1:vXT6d/FNDiELJnLb6hGNa309LMsrCoYFvpwHDF0+Y1A= @@ -500,6 +507,8 @@ github.com/go-ldap/ldap/v3 v3.4.3/go.mod h1:7LdHfVt6iIOESVEe3Bs4Jp2sHEKgDeduAhgM github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= @@ -604,6 +613,7 @@ github.com/go-openapi/validate v0.20.1/go.mod h1:b60iJT+xNNLfaQJUqLI7946tYiFEOuE github.com/go-openapi/validate v0.20.3 h1:GZPPhhKSZrE8HjB4eEkoYAZmoWA4+tCemSgINH1/vKw= github.com/go-openapi/validate v0.20.3/go.mod h1:goDdqVGiigM3jChcrYJxD2joalke3ZXeftD16byIjA4= github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= +github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-redis/redis/v8 v8.4.0/go.mod h1:A1tbYoHSa1fXwN+//ljcCYYJeLmVrwL9hbQN45Jdy0M= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= @@ -619,6 +629,8 @@ github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP github.com/go-swagger/go-swagger v0.29.0 h1:z3YoZtLvS1Y8TE/PCat1VypcZxM0IgKLt0NvZxQyNl8= github.com/go-swagger/go-swagger v0.29.0/go.mod h1:Z4GJzI+bHKKkGB2Ji1rawpi3/ldXX8CkzGIa9HAC5EE= github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0= +github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-testfixtures/testfixtures/v3 v3.6.1 h1:n4Fv95Exp0D05G6l6CAZv22Ck1EJK0pa0TfPqE4ncSs= github.com/go-testfixtures/testfixtures/v3 v3.6.1/go.mod h1:Bsb2MoHAfHnNsPpSwAjtOs102mqDuM+1u3nE2OCi0N0= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= @@ -743,6 +755,7 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= +github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM= github.com/google/go-github/v45 v45.0.0 h1:LU0WBjYidxIVyx7PZeWb+FP4JZJ3Wh3FQgdumnGqiLs= github.com/google/go-github/v45 v45.0.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28= @@ -772,6 +785,7 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= @@ -844,6 +858,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= github.com/hashicorp/consul/api v1.11.0/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= +github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= @@ -863,6 +878,7 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= +github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= @@ -898,6 +914,7 @@ github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73t github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/imdario/mergo v0.3.4/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -1029,12 +1046,17 @@ github.com/kisom/goutils v1.4.3/go.mod h1:Lp5qrquG7yhYnWzZCI/68Pa/GpFynw//od6EkG github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= +github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.3 h1:wmfu2iqj9q22SyMINp1uQ8C2/V4M1phJdmH9fG4nba0= github.com/klauspost/compress v1.15.3/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= +github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s= +github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= +github.com/klauspost/cpuid/v2 v2.0.11/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE= @@ -1153,14 +1175,17 @@ github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= +github.com/miekg/dns v1.1.46/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ= github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= +github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/minio-go/v7 v7.0.26 h1:D0HK+8793etZfRY/vHhDmFaP+vmT41K3K4JV9vmZCBQ= github.com/minio/minio-go/v7 v7.0.26/go.mod h1:x81+AX5gHSfCSqw7jxRKHvxUXMlE5uKX0Vb75Xk5yYg= +github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -1224,6 +1249,7 @@ github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9l github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= @@ -1242,13 +1268,18 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= +github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= +github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= +github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= @@ -1278,6 +1309,7 @@ github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= +github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE= @@ -1296,6 +1328,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= github.com/pquerna/otp v1.3.0 h1:oJV/SkzR33anKXwQU3Of42rL4wbrffP4uvUf1SvS5Xs= github.com/pquerna/otp v1.3.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -1367,12 +1400,14 @@ github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= +github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig= +github.com/sagikazarmark/crypt v0.4.0/go.mod h1:ALv2SRj7GxYV4HO9elxH9nS6M9gW+xDNxqmyJ6RfDFM= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 h1:TToq11gyfNlrMFZiYujSekIsPd9AmsA2Bj/iv+s4JHE= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= @@ -1405,12 +1440,14 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/assertions v1.1.1 h1:T/YLemO5Yp7KPzS+lVtu+WsHn8yoSwTfItdAd1r3cck= +github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs= +github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= @@ -1543,7 +1580,9 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.5/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= +github.com/yuin/goldmark v1.4.6/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0= github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 h1:yHfZyN55+5dp1wG7wDKv8HQ044moxkyGq12KFFMFDxg= @@ -1562,6 +1601,7 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= +go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw= go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= @@ -1612,6 +1652,8 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/otel v0.14.0/go.mod h1:vH5xEuwy7Rts0GNtsCW3HYQoZDY+OmBJ6t1bFGGlxgw= +go.opentelemetry.io/otel v1.5.0/go.mod h1:Jm/m+rNp/z0eqJc74H7LPwQ3G87qkU/AnnAydAjSAHk= +go.opentelemetry.io/otel/trace v1.5.0/go.mod h1:sq55kfhjXYr1zVSyexg0w1mpa03AYXR5eyTkB9NPPdE= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -1677,7 +1719,11 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8= @@ -1783,6 +1829,7 @@ golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5o golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= +golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -1791,7 +1838,9 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -1903,6 +1952,7 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1936,8 +1986,11 @@ golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -2040,6 +2093,7 @@ golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -2050,6 +2104,7 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= +golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -2098,6 +2153,7 @@ google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdr google.golang.org/api v0.59.0/go.mod h1:sT2boj7M9YJxZzgeZqXogmhfmRWDtPzT31xkieUbuZU= google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I= google.golang.org/api v0.62.0/go.mod h1:dKmwPCydfsad4qCH08MSdgWjfHOyfpd4VtDGgRFdavw= +google.golang.org/api v0.63.0/go.mod h1:gs4ij2ffTRXwuzzgJl/56BdwJaA194ijkfn++9tDuPo= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -2258,11 +2314,14 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkp gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/ini.v1 v1.44.2/go.mod h1:M3Cogqpuv0QCi3ExAY5V4uOt4qb/R3xZubo9m8lK5wg= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= +gopkg.in/ini.v1 v1.66.3/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4= gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= +gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= From 57e6b67095c562a1073dfa2e0c4ac2d7311837ab Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 9 Jun 2022 17:43:54 -0500 Subject: [PATCH 35/94] make fmt --- routers/api/v1/activitypub/person.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index d829888cc2cd7..361889ec47a58 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -38,7 +38,7 @@ func Person(ctx *context.APIContext) { return } username := ctx.Params("username") - + link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/") person := ap.PersonNew(ap.IRI(link)) @@ -51,7 +51,7 @@ func Person(ctx *context.APIContext) { person.PublicKey.ID = ap.IRI(link + "#main-key") person.PublicKey.Owner = ap.IRI(link) - + publicKeyPem, err := activitypub.GetPublicKey(user) if err != nil { ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) From a8cb4a80bf24d86fdb51e209b449cd0dd9b38b6b Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 9 Jun 2022 17:59:43 -0500 Subject: [PATCH 36/94] Convert remaining code to go-ap --- integrations/api_activitypub_person_test.go | 58 ++++++--------------- routers/api/v1/activitypub/person.go | 18 +++++-- 2 files changed, 31 insertions(+), 45 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index f3479e65c8bfb..d6aff2079f2b3 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -16,7 +16,7 @@ import ( "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/setting" - "github.com/go-ap/activitypub" + ap "github.com/go-ap/activitypub" "github.com/stretchr/testify/assert" ) @@ -34,49 +34,24 @@ func TestActivityPubPerson(t *testing.T) { var m map[string]interface{} DecodeJSON(t, resp, &m) - var person vocab.ActivityStreamsPerson - resolver, _ := streams.NewJSONResolver(func(c context.Context, p vocab.ActivityStreamsPerson) error { - person = p - return nil - }) - ctx := context.Background() - err := resolver.Resolve(ctx, m) + var person ap.Person + err := person.UnmarshalJSON(resp.Body.Bytes()) assert.NoError(t, err) - assert.Equal(t, "Person", person.GetTypeName()) - assert.Equal(t, username, person.GetActivityStreamsName().Begin().GetXMLSchemaString()) - keyID := person.GetJSONLDId().GetIRI().String() + + assert.Equal(t, "Person", person.Type) + assert.Equal(t, username, person.Name) + keyID := person.ID.String() assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID) - assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.GetActivityStreamsOutbox().GetIRI().String()) - assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.GetActivityStreamsInbox().GetIRI().String()) + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.Outbox.GetID().String()) + assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.Inbox.GetID().String()) - pkp := person.GetW3IDSecurityV1PublicKey() - assert.NotNil(t, pkp) + pkey := person.PublicKey + assert.NotNil(t, pkey) publicKeyID := keyID + "#main-key" - var pkpFound vocab.W3IDSecurityV1PublicKey - for pkpIter := pkp.Begin(); pkpIter != pkp.End(); pkpIter = pkpIter.Next() { - if !pkpIter.IsW3IDSecurityV1PublicKey() { - continue - } - pkValue := pkpIter.Get() - var pkID *url.URL - pkID, err = pub.GetId(pkValue) - if err != nil { - return - } - assert.Equal(t, pkID.String(), publicKeyID) - if pkID.String() != publicKeyID { - continue - } - pkpFound = pkValue - break - } - assert.NotNil(t, pkpFound) - - pkPemProp := pkpFound.GetW3IDSecurityV1PublicKeyPem() - assert.NotNil(t, pkPemProp) - assert.True(t, pkPemProp.IsXMLSchemaString()) - - pubKeyPem := pkPemProp.Get() + assert.Equal(t, pkey.ID.String(), publicKeyID) + + pubKeyPem := pkey.PublicKeyPem + assert.NotNil(t, pubKeyPem) assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----", pubKeyPem) }) } @@ -109,7 +84,8 @@ func TestActivityPubPersonInbox(t *testing.T) { setting.AppURL = appURL }() username1 := "user1" - user1, err := user_model.GetUserByName(username1) + var ctx context.Context + user1, err := user_model.GetUserByName(ctx, username1) assert.NoError(t, err) user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s#main-key", srv.URL, username1) c, err := activitypub.NewClient(user1, user1url) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 361889ec47a58..4a29bca29f45a 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/api/v1/user" @@ -43,7 +44,11 @@ func Person(ctx *context.APIContext) { person := ap.PersonNew(ap.IRI(link)) name := ap.NaturalLanguageValuesNew() - name.Set("en", ap.Content(username)) + err := name.Set("en", ap.Content(username)) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Set name", err) + return + } person.Name = name person.Inbox = ap.Item(ap.IRI(link + "/inbox")) @@ -63,9 +68,14 @@ func Person(ctx *context.APIContext) { if err != nil { ctx.Error(http.StatusInternalServerError, "Serialize", err) } - ctx.Resp.Header().Set("Content-Type", "application/json;charset=utf-8") - ctx.Write(binary) - ctx.Status(http.StatusOK) + + var jsonmap map[string]interface{} + err = json.Unmarshal(binary, jsonmap) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Unmarshall", err) + } + + ctx.JSON(http.StatusOK, jsonmap) } // PersonInbox function From 94fbd80b7b4b1f09149c6045798e292ff2edf37b Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 9 Jun 2022 18:56:43 -0500 Subject: [PATCH 37/94] Clean up go.sum --- go.sum | 57 --------------------------------------------------------- 1 file changed, 57 deletions(-) diff --git a/go.sum b/go.sum index 233314aa1e8d5..db7044c1a7b93 100644 --- a/go.sum +++ b/go.sum @@ -199,7 +199,6 @@ github.com/aws/aws-sdk-go v1.23.20/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpi github.com/aws/aws-sdk-go v1.25.11/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo= github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48= -github.com/aws/aws-sdk-go v1.43.21/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo= github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g= github.com/aybabtme/rgbterm v0.0.0-20170906152045-cc83f3b3ce59/go.mod h1:q/89r3U2H7sSsE2t6Kca0lfwTK8JdoNGS/yzM/4iH5I= github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk= @@ -284,7 +283,6 @@ github.com/census-instrumentation/opencensus-proto v0.3.0/go.mod h1:f6KPmirojxKA github.com/certifi/gocertifi v0.0.0-20191021191039-0944d244cd40/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d h1:S2NE3iHSwP0XV47EEXL8mWmRdEfGscSJ+7EgePNgt0s= github.com/certifi/gocertifi v0.0.0-20210507211836-431795d63e8d/go.mod h1:sGbDF6GwGcLpkNXPUTkMRoywsNa/ol15pxFe6ERfguA= -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= @@ -328,13 +326,11 @@ github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkE github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= -github.com/coreos/go-oidc v2.2.1+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-semver v0.3.0 h1:wkHLiw0WNATZnSG7epLsujiMCgPAc9xhjJ4tgnAxmfM= github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f h1:JOrtw2xFKzlg+cbHpyrpLDmnN1HqhBfnX7WDiW7eG2c= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.1.0/go.mod h1:xO0FLkIi5MaZafQlIrOotqXZ90ih+1atmu1JpKERPPk= github.com/coreos/go-systemd/v22 v22.3.2 h1:D9/bQk5vlXQFZ6Kwuu6zaiXJ9oTPe68++AzAJc1DzSI= @@ -353,7 +349,6 @@ github.com/couchbase/goutils v0.0.0-20210118111533-e33d3ffb5401 h1:4KDlx3vjalrHD github.com/couchbase/goutils v0.0.0-20210118111533-e33d3ffb5401/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs= github.com/couchbase/moss v0.1.0/go.mod h1:9MaHIaRuy9pvLPUJxB8sh8OrLfyDczECVL37grCIubs= github.com/couchbase/moss v0.2.0/go.mod h1:9MaHIaRuy9pvLPUJxB8sh8OrLfyDczECVL37grCIubs= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -507,8 +502,6 @@ github.com/go-ldap/ldap/v3 v3.4.3/go.mod h1:7LdHfVt6iIOESVEe3Bs4Jp2sHEKgDeduAhgM github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A= -github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/go-openapi/analysis v0.0.0-20180825180245-b006789cd277/go.mod h1:k70tL6pCuVxPJOHXQ+wIac1FUrvNkHolPie/cLEU6hI= github.com/go-openapi/analysis v0.17.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= github.com/go-openapi/analysis v0.18.0/go.mod h1:IowGgpVeD0vNm45So8nr+IcQ3pxVtpRoBWb8PVZO0ik= @@ -613,7 +606,6 @@ github.com/go-openapi/validate v0.20.1/go.mod h1:b60iJT+xNNLfaQJUqLI7946tYiFEOuE github.com/go-openapi/validate v0.20.3 h1:GZPPhhKSZrE8HjB4eEkoYAZmoWA4+tCemSgINH1/vKw= github.com/go-openapi/validate v0.20.3/go.mod h1:goDdqVGiigM3jChcrYJxD2joalke3ZXeftD16byIjA4= github.com/go-redis/redis v6.15.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= -github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-redis/redis/v8 v8.4.0/go.mod h1:A1tbYoHSa1fXwN+//ljcCYYJeLmVrwL9hbQN45Jdy0M= github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= @@ -629,8 +621,6 @@ github.com/go-stack/stack v1.8.1/go.mod h1:dcoOX6HbPZSZptuspn9bctJ+N/CnF5gGygcUP github.com/go-swagger/go-swagger v0.29.0 h1:z3YoZtLvS1Y8TE/PCat1VypcZxM0IgKLt0NvZxQyNl8= github.com/go-swagger/go-swagger v0.29.0/go.mod h1:Z4GJzI+bHKKkGB2Ji1rawpi3/ldXX8CkzGIa9HAC5EE= github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013 h1:l9rI6sNaZgNC0LnF3MiE+qTmyBA/tZAg1rtyrGbUMK0= -github.com/go-swagger/scan-repo-boundary v0.0.0-20180623220736-973b3573c013/go.mod h1:b65mBPzqzZWxOZGxSWrqs4GInLIn+u99Q9q7p+GKni0= -github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-testfixtures/testfixtures/v3 v3.6.1 h1:n4Fv95Exp0D05G6l6CAZv22Ck1EJK0pa0TfPqE4ncSs= github.com/go-testfixtures/testfixtures/v3 v3.6.1/go.mod h1:Bsb2MoHAfHnNsPpSwAjtOs102mqDuM+1u3nE2OCi0N0= github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0= @@ -755,7 +745,6 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-github/v28 v28.1.1/go.mod h1:bsqJWQX05omyWVmc00nEUql9mhQyv38lDZ8kPZcQVoM= github.com/google/go-github/v45 v45.0.0 h1:LU0WBjYidxIVyx7PZeWb+FP4JZJ3Wh3FQgdumnGqiLs= github.com/google/go-github/v45 v45.0.0/go.mod h1:FObaZJEDSTa/WGCzZ2Z3eoCDXWJKMenWWTrd8jrta28= @@ -785,7 +774,6 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210122040257-d980be63207e/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210601050228-01bbb1931b22/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210609004039-a478d1d731e9/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= @@ -858,7 +846,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q= github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE= github.com/hashicorp/consul/api v1.11.0/go.mod h1:XjsvQN+RJGWI2TWy1/kqaE16HrR2J/FWgkYjdZQsX9M= -github.com/hashicorp/consul/api v1.12.0/go.mod h1:6pVBMo0ebnYdt2S3H87XhekM/HHrUoTD2XXb/VrZVy0= github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8= github.com/hashicorp/consul/sdk v0.8.0/go.mod h1:GBvyrGALthsZObzUGsfgHZQDXjg4lOjagTIwIR1vPms= @@ -878,7 +865,6 @@ github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHh github.com/hashicorp/go-multierror v1.1.0/go.mod h1:spPvp8C1qA32ftKqdAHm4hHTbPw+vmowP0z+KUhOZdA= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-retryablehttp v0.6.4/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= -github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-retryablehttp v0.7.1 h1:sUiuQAnLlbvmExtFQs72iFW/HXeUn8Z1aJLQ4LJJbTQ= github.com/hashicorp/go-retryablehttp v0.7.1/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= @@ -914,7 +900,6 @@ github.com/iancoleman/strcase v0.0.0-20180726023541-3605ed457bf7/go.mod h1:SK73t github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= -github.com/ianlancetaylor/demangle v0.0.0-20210905161508-09a460cdf81d/go.mod h1:aYm2/VgdVmcIU8iMfdMvDMsRAQjcfZSKFby6HOFvi/w= github.com/imdario/mergo v0.3.4/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= @@ -1046,17 +1031,12 @@ github.com/kisom/goutils v1.4.3/go.mod h1:Lp5qrquG7yhYnWzZCI/68Pa/GpFynw//od6EkG github.com/klauspost/compress v1.4.1/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.11.4/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= -github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/compress v1.15.3 h1:wmfu2iqj9q22SyMINp1uQ8C2/V4M1phJdmH9fG4nba0= github.com/klauspost/compress v1.15.3/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= -github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s= -github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4= github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.0.11/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/cpuid/v2 v2.0.12 h1:p9dKCg8i4gmOxtv35DvrYoWqYzQrvEVdjQ762Y0OqZE= github.com/klauspost/cpuid/v2 v2.0.12/go.mod h1:g2LTdtYhdyuGPqyWyv7qRAmj1WBqxuObKfj5c0PQa7c= github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE= @@ -1175,17 +1155,14 @@ github.com/microcosm-cc/bluemonday v1.0.18/go.mod h1:Z0r70sCuXHig8YpBzCc5eGHAap2 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg= github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso= github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI= -github.com/miekg/dns v1.1.46/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/miekg/dns v1.1.48 h1:Ucfr7IIVyMBz4lRE8qmGUuZ4Wt3/ZGu9hmcMT3Uu4tQ= github.com/miekg/dns v1.1.48/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME= github.com/miekg/pkcs11 v1.0.2/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= github.com/miekg/pkcs11 v1.0.3/go.mod h1:XsNlhZGX73bx86s2hdc/FuaLm2CPZJemRLMA+WTFxgs= -github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34= github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM= github.com/minio/minio-go/v7 v7.0.26 h1:D0HK+8793etZfRY/vHhDmFaP+vmT41K3K4JV9vmZCBQ= github.com/minio/minio-go/v7 v7.0.26/go.mod h1:x81+AX5gHSfCSqw7jxRKHvxUXMlE5uKX0Vb75Xk5yYg= -github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM= github.com/minio/sha256-simd v1.0.0 h1:v1ta+49hkWZyvaKwrQB8elexRqm6Y0aMLjCNsrYxo6g= github.com/minio/sha256-simd v1.0.0/go.mod h1:OuYzVNI5vcoYIAmbIvHPl3N3jUzVedXbKy5RFepssQM= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= @@ -1249,7 +1226,6 @@ github.com/nwaples/rardecode v1.1.3 h1:cWCaZwfM5H7nAD6PyEdcVnczzV8i/JtotnyW/dD9l github.com/nwaples/rardecode v1.1.3/go.mod h1:5DzqNKiOdpKKBH87u8VlvAnPZMXcGRhxWkRpHbbfGS0= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= -github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4= @@ -1268,18 +1244,13 @@ github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= -github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.0.0/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.10.3/go.mod h1:V9xEwhxec5O8UDM77eCW8vLymOMltsqPVYWrpDsH8xc= -github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY= github.com/onsi/gomega v1.18.1 h1:M1GfJqGRrBrrGGsbxzV5dqM2U2ApXefZCQpkukxYRLE= -github.com/onsi/gomega v1.18.1/go.mod h1:0q+aL8jAiMXy9hbwj2mr5GziHiwhAIQpFmmtT5hitRs= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opentracing-contrib/go-observer v0.0.0-20170622124052-a52f23424492/go.mod h1:Ngi6UdF0k5OKD5t5wlmGhe/EDKPoUM3BXZSSfIuJbis= github.com/opentracing/basictracer-go v1.0.0/go.mod h1:QfBfYuafItcjQuMwinw9GhYKwFXS9KnPs5lxoYwgW74= @@ -1309,7 +1280,6 @@ github.com/pelletier/go-toml v1.9.4/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCko github.com/performancecopilot/speed v3.0.0+incompatible/go.mod h1:/CLtqpZ5gBg1M9iaPbIdPPGyKcA8hKdoy6hAWba7Yac= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= -github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4/v4 v4.1.2/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pierrec/lz4/v4 v4.1.14 h1:+fL8AQEZtz/ijeNnpduH0bROTu0O3NZAlPjQxGn8LwE= @@ -1328,7 +1298,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI= github.com/pquerna/otp v1.3.0 h1:oJV/SkzR33anKXwQU3Of42rL4wbrffP4uvUf1SvS5Xs= github.com/pquerna/otp v1.3.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= @@ -1400,14 +1369,12 @@ github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/sagikazarmark/crypt v0.3.0/go.mod h1:uD/D+6UF4SrIR1uGEv7bBNkNqLGqUr43MRiaGWX1Nig= -github.com/sagikazarmark/crypt v0.4.0/go.mod h1:ALv2SRj7GxYV4HO9elxH9nS6M9gW+xDNxqmyJ6RfDFM= github.com/samuel/go-zookeeper v0.0.0-20190923202752-2cc03de413da/go.mod h1:gi+0XIa01GRL2eRQVjQkKGqKF3SF9vZR/HnPullcV2E= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 h1:TToq11gyfNlrMFZiYujSekIsPd9AmsA2Bj/iv+s4JHE= github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= @@ -1440,14 +1407,12 @@ github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1 github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= github.com/smartystreets/assertions v1.0.0/go.mod h1:kHHU4qYBaI3q23Pp3VPrmWhuIUrLW/7eUrw0BU5VaoM= github.com/smartystreets/assertions v1.1.1 h1:T/YLemO5Yp7KPzS+lVtu+WsHn8yoSwTfItdAd1r3cck= -github.com/smartystreets/assertions v1.1.1/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo= github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM= github.com/smartystreets/goconvey v0.0.0-20181108003508-044398e4856c/go.mod h1:XDJAKZRPZ1CvBcN2aX5YOUTYGHki24fSF0Iv48Ibg0s= github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s= github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= github.com/smartystreets/gunit v1.0.0/go.mod h1:qwPWnhz6pn0NnRBP++URONOVyNkPyr4SauJk4cUOwJs= -github.com/smartystreets/gunit v1.4.2/go.mod h1:ZjM1ozSIMJlAz/ay4SG8PeKF00ckUp+zMHZXV9/bvak= github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.5-0.20210205191134-5ec6847320e5/go.mod h1:T7TcVDs9LWfQgPlPsdngu6I6QIoyIFZDDC6sNE1GqG0= github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js= @@ -1580,9 +1545,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/yuin/goldmark v1.4.5/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= -github.com/yuin/goldmark v1.4.6/go.mod h1:rmuwmfZ0+bvzB24eSC//bk1R1Zp3hM0OXYv/G2LIilg= github.com/yuin/goldmark v1.4.12 h1:6hffw6vALvEDqJ19dOJvJKOoAOKe4NDaTqvd2sktGN0= github.com/yuin/goldmark v1.4.12/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= github.com/yuin/goldmark-highlighting v0.0.0-20220208100518-594be1970594 h1:yHfZyN55+5dp1wG7wDKv8HQ044moxkyGq12KFFMFDxg= @@ -1601,7 +1564,6 @@ go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ= go.etcd.io/bbolt v1.3.6 h1:/ecaJf0sk1l4l6V4awd65v2C3ILy7MSj+s/x1ADCIMU= go.etcd.io/bbolt v1.3.6/go.mod h1:qXsaaIqmgQH0T+OPdb99Bf+PKfBBQVAdyD6TY9G8XM4= -go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738 h1:VcrIfasaLFkyjk6KNlXQSzO+B0fZcnECiDrKJsfxka0= go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg= go.etcd.io/etcd/api/v3 v3.5.0-alpha.0/go.mod h1:mPcW6aZJukV6Aa81LSKpBjQXTWlXB5r74ymPoSWa3Sw= go.etcd.io/etcd/api/v3 v3.5.1 h1:v28cktvBq+7vGyJXF8G+rWJmj+1XUmMtqcLnH8hDocM= @@ -1652,8 +1614,6 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/otel v0.14.0/go.mod h1:vH5xEuwy7Rts0GNtsCW3HYQoZDY+OmBJ6t1bFGGlxgw= -go.opentelemetry.io/otel v1.5.0/go.mod h1:Jm/m+rNp/z0eqJc74H7LPwQ3G87qkU/AnnAydAjSAHk= -go.opentelemetry.io/otel/trace v1.5.0/go.mod h1:sq55kfhjXYr1zVSyexg0w1mpa03AYXR5eyTkB9NPPdE= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= @@ -1719,11 +1679,7 @@ golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5 golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220112180741-5e0467b6c7ce/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220507011949-2cf3adece122 h1:NvGWuYG8dkDHFSKksI1P9faiVJ9rayE6l0+ouWVIDs8= @@ -1829,7 +1785,6 @@ golang.org/x/net v0.0.0-20210326060303-6b1517762897/go.mod h1:uSPa2vr4CLtc/ILN5o golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210410081132-afb366fc7cd1/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= golang.org/x/net v0.0.0-20210421230115-4e50805a0758/go.mod h1:72T/g9IO56b78aLF+1Kcs5dz7/ng1VjMUvfKvpfy+jM= -golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/net v0.0.0-20210503060351-7fd8e65b6420/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210510120150-4163338589ed/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= @@ -1838,9 +1793,7 @@ golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220121210141-e204ce36a2ba/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= @@ -1952,7 +1905,6 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201126233918-771906719818/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210104204734-6f8348627aad/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -1986,11 +1938,8 @@ golang.org/x/sys v0.0.0-20210902050250-f475640dd07b/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210908233432-aa78b53d3365/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211117180635-dee7805ff2e1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211210111614-af8b64212486/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= @@ -2093,7 +2042,6 @@ golang.org/x/tools v0.0.0-20201110124207-079ba7bd75cd/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20201124115921-2c860bdd6e78/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= @@ -2104,7 +2052,6 @@ golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.4/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.6-0.20210726203631-07bc1bf47fb2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU= golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= @@ -2153,7 +2100,6 @@ google.golang.org/api v0.57.0/go.mod h1:dVPlbZyBo2/OjBpmvNdpn2GRm6rPy75jyU7bmhdr google.golang.org/api v0.59.0/go.mod h1:sT2boj7M9YJxZzgeZqXogmhfmRWDtPzT31xkieUbuZU= google.golang.org/api v0.61.0/go.mod h1:xQRti5UdCmoCEqFxcz93fTl338AVqDgyaDRuOZ3hg9I= google.golang.org/api v0.62.0/go.mod h1:dKmwPCydfsad4qCH08MSdgWjfHOyfpd4VtDGgRFdavw= -google.golang.org/api v0.63.0/go.mod h1:gs4ij2ffTRXwuzzgJl/56BdwJaA194ijkfn++9tDuPo= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= @@ -2314,14 +2260,11 @@ gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df/go.mod h1:LRQQ+SO6ZHR7tOkp gopkg.in/inconshreveable/log15.v2 v2.0.0-20180818164646-67afb5ed74ec/go.mod h1:aPpfJ7XW+gOuirDoZ8gHhLh3kZ1B08FtV2bbmy7Jv3s= gopkg.in/ini.v1 v1.44.2/go.mod h1:M3Cogqpuv0QCi3ExAY5V4uOt4qb/R3xZubo9m8lK5wg= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.57.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.62.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.66.2/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= -gopkg.in/ini.v1 v1.66.3/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4= gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= -gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= gopkg.in/src-d/go-billy.v4 v4.3.2/go.mod h1:nDjArDMp+XMs1aFAESLRjfGSgfvoYN0hDfzEk0GjC98= gopkg.in/src-d/go-git-fixtures.v3 v3.5.0/go.mod h1:dLBcvytrw/TYZsNTWCnkNF2DSIlzWYqTe3rJR56Ac7g= gopkg.in/src-d/go-git.v4 v4.13.1/go.mod h1:nx5NYcxdKxq5fpltdHnPa2Exj4Sx0EclMWZQbYDu2z8= From 46cab80ef4812cde254d36825eff0b39ed8dac77 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 10 Jun 2022 10:37:55 -0500 Subject: [PATCH 38/94] Fix JSON unmarshall error --- routers/api/v1/activitypub/person.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 4a29bca29f45a..4bd77c0b476b9 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -70,7 +70,7 @@ func Person(ctx *context.APIContext) { } var jsonmap map[string]interface{} - err = json.Unmarshal(binary, jsonmap) + err = json.Unmarshal(binary, &jsonmap) if err != nil { ctx.Error(http.StatusInternalServerError, "Unmarshall", err) } From 86a3221563aca3bdf4cbcad57a92dbf461025879 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 10 Jun 2022 11:04:07 -0500 Subject: [PATCH 39/94] Fix CI errors by adding @context to Person() and making sure types match --- integrations/api_activitypub_person_test.go | 6 +++--- routers/api/v1/activitypub/person.go | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index d6aff2079f2b3..c7c4be5ee6dbb 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -38,9 +38,9 @@ func TestActivityPubPerson(t *testing.T) { err := person.UnmarshalJSON(resp.Body.Bytes()) assert.NoError(t, err) - assert.Equal(t, "Person", person.Type) - assert.Equal(t, username, person.Name) - keyID := person.ID.String() + assert.Equal(t, ap.ActivityVocabularyType("Person"), person.Type) + assert.Equal(t, username, person.Name.String()) + keyID := person.GetID().String() assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.Outbox.GetID().String()) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.Inbox.GetID().String()) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 4bd77c0b476b9..a6a8b7a20e4e6 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -75,6 +75,8 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Unmarshall", err) } + jsonmap["@context"] = "https://www.w3.org/ns/activitystreams" + ctx.JSON(http.StatusOK, jsonmap) } From d487a765721a4fda0362af92bb047c0e34936284 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 10 Jun 2022 11:19:23 -0500 Subject: [PATCH 40/94] Correctly decode JSON in api_activitypub_person_test.go --- integrations/api_activitypub_person_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index c7c4be5ee6dbb..c158fbc256663 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -30,12 +30,13 @@ func TestActivityPubPerson(t *testing.T) { username := "user2" req := NewRequestf(t, "GET", fmt.Sprintf("/api/v1/activitypub/user/%s", username)) resp := MakeRequest(t, req, http.StatusOK) - assert.Contains(t, resp.Body.String(), "@context") + body := resp.Body.Bytes() + assert.Contains(t, string(body), "@context") var m map[string]interface{} DecodeJSON(t, resp, &m) var person ap.Person - err := person.UnmarshalJSON(resp.Body.Bytes()) + err := person.UnmarshalJSON(body) assert.NoError(t, err) assert.Equal(t, ap.ActivityVocabularyType("Person"), person.Type) From fc58ab6b254015a5cff1b62992ef60370f30fc0b Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 10 Jun 2022 11:29:39 -0500 Subject: [PATCH 41/94] Force CI rerun From 7428ff07363534004298e8ec8a587d26f6bd61f8 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 10 Jun 2022 12:30:13 -0500 Subject: [PATCH 42/94] Fix TestActivityPubPersonInbox segfault --- integrations/api_activitypub_person_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index c158fbc256663..2599b381ca07f 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -85,7 +85,7 @@ func TestActivityPubPersonInbox(t *testing.T) { setting.AppURL = appURL }() username1 := "user1" - var ctx context.Context + ctx := context.Context() user1, err := user_model.GetUserByName(ctx, username1) assert.NoError(t, err) user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s#main-key", srv.URL, username1) From 66b1761738974a1c2e14b4eed1ab786968133916 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 10 Jun 2022 13:28:50 -0500 Subject: [PATCH 43/94] Fix lint error --- integrations/api_activitypub_person_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 2599b381ca07f..818793d4a440b 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -85,7 +85,7 @@ func TestActivityPubPersonInbox(t *testing.T) { setting.AppURL = appURL }() username1 := "user1" - ctx := context.Context() + ctx := context.Background() user1, err := user_model.GetUserByName(ctx, username1) assert.NoError(t, err) user1url := fmt.Sprintf("%s/api/v1/activitypub/user/%s#main-key", srv.URL, username1) From cf6aed386dfddd3f8f1a8ec3b362e98a039c0e29 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 11 Jun 2022 11:00:45 -0500 Subject: [PATCH 44/94] Use @mariusor's suggestions for idiomatic go-ap usage --- integrations/api_activitypub_person_test.go | 2 +- routers/api/v1/activitypub/person.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 818793d4a440b..024e0240667ab 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -39,7 +39,7 @@ func TestActivityPubPerson(t *testing.T) { err := person.UnmarshalJSON(body) assert.NoError(t, err) - assert.Equal(t, ap.ActivityVocabularyType("Person"), person.Type) + assert.Equal(t, ap.PersonType, person.Type) assert.Equal(t, username, person.Name.String()) keyID := person.GetID().String() assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index a6a8b7a20e4e6..ced0955236d89 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -51,8 +51,8 @@ func Person(ctx *context.APIContext) { } person.Name = name - person.Inbox = ap.Item(ap.IRI(link + "/inbox")) - person.Outbox = ap.Item(ap.IRI(link + "/outbox")) + ap.Inbox.AddTo(person) + ap.Outbox.AddTo(person) person.PublicKey.ID = ap.IRI(link + "#main-key") person.PublicKey.Owner = ap.IRI(link) From 528c282d686f9ced4b6e26b73cdf2c0e5b97bfce Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 11 Jun 2022 12:40:10 -0500 Subject: [PATCH 45/94] Correctly add inbox/outbox IRIs to person --- routers/api/v1/activitypub/person.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index ced0955236d89..1358e01020dfe 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -51,8 +51,10 @@ func Person(ctx *context.APIContext) { } person.Name = name - ap.Inbox.AddTo(person) - ap.Outbox.AddTo(person) + person.Inbox = nil + person.Inbox, _ = ap.Inbox.AddTo(person) + person.Outbox = nil + person.Outbox, _ = ap.Outbox.AddTo(person) person.PublicKey.ID = ap.IRI(link + "#main-key") person.PublicKey.Owner = ap.IRI(link) From 607422237719e2a4b3c0ea38884a89134655ef9d Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 11 Jun 2022 21:15:45 -0500 Subject: [PATCH 46/94] Code cleanup --- integrations/api_activitypub_person_test.go | 2 -- routers/api/v1/activitypub/reqsignature.go | 6 +++--- routers/api/v1/api.go | 6 ++++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 024e0240667ab..0bfe6d2a95fe3 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -32,8 +32,6 @@ func TestActivityPubPerson(t *testing.T) { resp := MakeRequest(t, req, http.StatusOK) body := resp.Body.Bytes() assert.Contains(t, string(body), "@context") - var m map[string]interface{} - DecodeJSON(t, resp, &m) var person ap.Person err := person.UnmarshalJSON(body) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 6c4d289c48fc9..5a15a5d5aa353 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -28,7 +28,7 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p person := ap.PersonNew(ap.IRI(keyID.String())) err = person.UnmarshalJSON(b) if err != nil { - err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %T", b) + err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %v", err) return } pkey := person.PublicKey @@ -50,7 +50,7 @@ func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") - req.Header("Date", fmt.Sprintf("%s GMT", time.Now().UTC().Format(time.RFC1123))) + req.Header("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) resp, err := req.Response() if err != nil { return @@ -89,7 +89,7 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er } // 3. Verify the other actor's key algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) - authenticated = nil == v.Verify(pKey, algo) + authenticated = v.Verify(pKey, algo) == nil return } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index e1d13cd2ddc17..fb1b0453e2306 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -645,8 +645,10 @@ func Routes() *web.Route { if setting.Federation.Enabled { m.Get("/nodeinfo", misc.NodeInfo) m.Group("/activitypub", func() { - m.Get("/user/{username}", activitypub.Person) - m.Post("/user/{username}/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) + m.Group("/user/{username}", func() { + m.Get("", activitypub.Person) + m.Post("/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) + }) }) } m.Get("/signing-key.gpg", misc.SigningKey) From 76f06cee3143408dd7ca9d90c93f9bbfb5a79dbd Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 11 Jun 2022 21:18:15 -0500 Subject: [PATCH 47/94] Remove another LogSQL from ActivityPub person test --- integrations/api_activitypub_person_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 0bfe6d2a95fe3..830c9cc888a46 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -75,7 +75,6 @@ func TestActivityPubPersonInbox(t *testing.T) { onGiteaRun(t, func(*testing.T, *url.URL) { appURL := setting.AppURL setting.Federation.Enabled = true - setting.Database.LogSQL = true setting.AppURL = srv.URL defer func() { setting.Federation.Enabled = false From d1f14ff2c7560e66cf4eecd753bd67781d39c05d Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 12 Jun 2022 14:24:47 -0500 Subject: [PATCH 48/94] Move httpsig algos slice to an init() function --- modules/activitypub/client.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index bbc0d3de218f0..c23f3b18f7036 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -54,6 +54,15 @@ type Client struct { pubID string } +var algos []httpsig.Algorithm + +func init() { + algos = make([]httpsig.Algorithm, len(setting.Federation.Algorithms)) + for i, algo := range setting.Federation.Algorithms { + algos[i] = httpsig.Algorithm(algo) + } +} + // NewClient function func NewClient(user *user_model.User, pubID string) (c *Client, err error) { if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil { @@ -61,10 +70,6 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { } else if err = containsRequiredHTTPHeaders(http.MethodPost, setting.Federation.PostHeaders); err != nil { return } - algos := make([]httpsig.Algorithm, len(setting.Federation.Algorithms)) - for i, algo := range setting.Federation.Algorithms { - algos[i] = httpsig.Algorithm(algo) - } priv, err := GetPrivateKey(user) if err != nil { From 5823d8150af26d08118cb299d4a756abeffcae6f Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 22 Apr 2022 11:10:26 -0500 Subject: [PATCH 49/94] Add actor IRI and remote interaction URL to WebFinger response --- routers/web/webfinger.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 8402967867e59..80f464e0ed867 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -86,6 +86,7 @@ func WebfingerQuery(ctx *context.Context) { aliases := []string{ u.HTMLURL(), + appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), } if !u.KeepEmailPrivate { aliases = append(aliases, fmt.Sprintf("mailto:%s", u.Email)) @@ -101,6 +102,15 @@ func WebfingerQuery(ctx *context.Context) { Rel: "http://webfinger.net/rel/avatar", Href: u.AvatarLink(), }, + { + Rel: "self", + Type: "application/activity+json", + Href: appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), + }, + { + Rel: "http://ostatus.org/schema/1.0/subscribe", + Href: appURL.String() + "api/v1/authorize_interaction?uri={uri}", + }, } ctx.JSON(http.StatusOK, &webfingerJRD{ From d91c61f8fa692ca2ce9d04722152c35bad76c32a Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sun, 12 Jun 2022 21:10:44 -0500 Subject: [PATCH 50/94] Update TestWebFinger to check for ActivityPub IRI in aliases --- integrations/webfinger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/webfinger_test.go b/integrations/webfinger_test.go index 8ba93c3f204b8..f3dd110c92d14 100644 --- a/integrations/webfinger_test.go +++ b/integrations/webfinger_test.go @@ -52,7 +52,7 @@ func TestWebfinger(t *testing.T) { var jrd webfingerJRD DecodeJSON(t, resp, &jrd) assert.Equal(t, "acct:user2@"+appURL.Host, jrd.Subject) - assert.ElementsMatch(t, []string{user.HTMLURL()}, jrd.Aliases) + assert.ElementsMatch(t, []string{user.HTMLURL(), appURL.String()+"api/v1/activitypub/user/"+user.Name}, jrd.Aliases) req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", user.LowerName, "unknown.host")) MakeRequest(t, req, http.StatusBadRequest) From d7b81f551da513a987d33f3e72f3b6e95cdc384f Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 09:03:10 -0500 Subject: [PATCH 51/94] make fmt --- integrations/webfinger_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/webfinger_test.go b/integrations/webfinger_test.go index f3dd110c92d14..98f12bee11ca0 100644 --- a/integrations/webfinger_test.go +++ b/integrations/webfinger_test.go @@ -52,7 +52,7 @@ func TestWebfinger(t *testing.T) { var jrd webfingerJRD DecodeJSON(t, resp, &jrd) assert.Equal(t, "acct:user2@"+appURL.Host, jrd.Subject) - assert.ElementsMatch(t, []string{user.HTMLURL(), appURL.String()+"api/v1/activitypub/user/"+user.Name}, jrd.Aliases) + assert.ElementsMatch(t, []string{user.HTMLURL(), appURL.String() + "api/v1/activitypub/user/" + user.Name}, jrd.Aliases) req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", user.LowerName, "unknown.host")) MakeRequest(t, req, http.StatusBadRequest) From a5b00ec4a5cd03205437ac9887c130ec261fa7f0 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 09:16:42 -0500 Subject: [PATCH 52/94] Force CI rerun From b6b7fe27b6c058529552d6748519ce415c55612c Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 15:39:20 -0500 Subject: [PATCH 53/94] 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 --- routers/web/webfinger.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 80f464e0ed867..0b65c2eb69407 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -29,6 +29,7 @@ type webfingerLink struct { Rel string `json:"rel,omitempty"` Type string `json:"type,omitempty"` Href string `json:"href,omitempty"` + Template string `json:"template,omitempty"` Titles map[string]string `json:"titles,omitempty"` Properties map[string]interface{} `json:"properties,omitempty"` } @@ -109,10 +110,11 @@ func WebfingerQuery(ctx *context.Context) { }, { Rel: "http://ostatus.org/schema/1.0/subscribe", - Href: appURL.String() + "api/v1/authorize_interaction?uri={uri}", + Template: appURL.String() + "api/v1/authorize_interaction?uri={uri}", }, } + ctx.Resp.Header().Add("Access-Control-Allow-Origin", "*") ctx.JSON(http.StatusOK, &webfingerJRD{ Subject: fmt.Sprintf("acct:%s@%s", url.QueryEscape(u.Name), appURL.Host), Aliases: aliases, From ed2a6f53483ad2f875f493a1add7c8d5bf753d37 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 16:53:17 -0500 Subject: [PATCH 54/94] make lint-backend --- routers/web/webfinger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 0b65c2eb69407..92f6f3106a5e1 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -109,7 +109,7 @@ func WebfingerQuery(ctx *context.Context) { Href: appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), }, { - Rel: "http://ostatus.org/schema/1.0/subscribe", + Rel: "http://ostatus.org/schema/1.0/subscribe", Template: appURL.String() + "api/v1/authorize_interaction?uri={uri}", }, } From f88979326c7a074ea2d3eba2a7cc5a830c2bc672 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 17:14:41 -0500 Subject: [PATCH 55/94] 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 --- routers/api/v1/activitypub/person.go | 29 ++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 1358e01020dfe..22f00c01e0136 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -43,13 +43,27 @@ func Person(ctx *context.APIContext) { link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/") person := ap.PersonNew(ap.IRI(link)) - name := ap.NaturalLanguageValuesNew() - err := name.Set("en", ap.Content(username)) + person.Name = ap.NaturalLanguageValuesNew() + err := person.Name.Set("en", ap.Content(user.FullName)) if err != nil { - ctx.Error(http.StatusInternalServerError, "Set name", err) + ctx.Error(http.StatusInternalServerError, "Set Name", err) return } - person.Name = name + + person.PreferredUsername = ap.NaturalLanguageValuesNew() + err = person.PreferredUsername.Set("en", ap.Content(username)) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err) + return + } + + person.URL = ap.IRI(setting.AppURL + username) + + person.Icon = ap.Image{ + Type: ap.ImageType, + MediaType: "image/png", + URL: ap.IRI(user.AvatarLink()), + } person.Inbox = nil person.Inbox, _ = ap.Inbox.AddTo(person) @@ -77,9 +91,12 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Unmarshall", err) } - jsonmap["@context"] = "https://www.w3.org/ns/activitystreams" + jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} - ctx.JSON(http.StatusOK, jsonmap) + ctx.Resp.Header().Add("Content-Type", "application/activity+json") + ctx.Resp.WriteHeader(http.StatusOK) + binary, _ = json.Marshal(jsonmap) + ctx.Resp.Write(binary) } // PersonInbox function From 3e9a69c8d3d291c6bd5140985eadbc0f969ac582 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 19:09:09 -0500 Subject: [PATCH 56/94] Use UTC instead of GMT --- modules/activitypub/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index c23f3b18f7036..2e872d2dbe932 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -106,7 +106,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) } req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("Date", fmt.Sprintf("%s GMT", time.Now().UTC().Format(time.RFC1123))) + req.Header.Add("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { From d749f8ff4f429d3fdbd7915dd587f6cfe7f41e2e Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 20:51:49 -0500 Subject: [PATCH 57/94] Rename pkey to pubKey --- integrations/api_activitypub_person_test.go | 8 ++++---- routers/api/v1/activitypub/reqsignature.go | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 830c9cc888a46..70f1134fa52d7 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -44,12 +44,12 @@ func TestActivityPubPerson(t *testing.T) { assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.Outbox.GetID().String()) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/inbox$", username), person.Inbox.GetID().String()) - pkey := person.PublicKey - assert.NotNil(t, pkey) + pubKey := person.PublicKey + assert.NotNil(t, pubKey) publicKeyID := keyID + "#main-key" - assert.Equal(t, pkey.ID.String(), publicKeyID) + assert.Equal(t, pubKey.ID.String(), publicKeyID) - pubKeyPem := pkey.PublicKeyPem + pubKeyPem := pubKey.PublicKeyPem assert.NotNil(t, pubKeyPem) assert.Regexp(t, "^-----BEGIN PUBLIC KEY-----", pubKeyPem) }) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 5a15a5d5aa353..906be714da368 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -31,12 +31,12 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p err = fmt.Errorf("ActivityStreams type cannot be converted to one known to have publicKey property: %v", err) return } - pkey := person.PublicKey - if pkey.ID.String() != keyID.String() { + pubKey := person.PublicKey + if pubKey.ID.String() != keyID.String() { err = fmt.Errorf("cannot find publicKey with id: %s in %s", keyID, b) return } - pubKeyPem := pkey.PublicKeyPem + pubKeyPem := pubKey.PublicKeyPem block, _ := pem.Decode([]byte(pubKeyPem)) if block == nil || block.Type != "PUBLIC KEY" { err = fmt.Errorf("could not decode publicKeyPem to PUBLIC KEY pem block type") @@ -83,13 +83,13 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er if err != nil { return } - pKey, err := getPublicKeyFromResponse(*ctx, b, idIRI) + pubKey, err := getPublicKeyFromResponse(*ctx, b, idIRI) if err != nil { return } // 3. Verify the other actor's key algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) - authenticated = v.Verify(pKey, algo) == nil + authenticated = v.Verify(pubKey, algo) == nil return } From 08eebffb0eaae4872172608f99f6ca732fa361a8 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Mon, 13 Jun 2022 23:10:36 -0500 Subject: [PATCH 58/94] Make sure HTTP request Date in GMT --- modules/activitypub/client.go | 3 ++- routers/api/v1/activitypub/person.go | 10 +++++----- routers/api/v1/activitypub/reqsignature.go | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 2e872d2dbe932..bcd248e21a7f2 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -11,6 +11,7 @@ import ( "encoding/pem" "fmt" "net/http" + "strings" "time" user_model "code.gitea.io/gitea/models/user" @@ -106,7 +107,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) } req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) + req.Header.Add("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT")) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 22f00c01e0136..bb3b2b23e319c 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -56,13 +56,13 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err) return } - + person.URL = ap.IRI(setting.AppURL + username) person.Icon = ap.Image{ - Type: ap.ImageType, + Type: ap.ImageType, MediaType: "image/png", - URL: ap.IRI(user.AvatarLink()), + URL: ap.IRI(user.AvatarLink()), } person.Inbox = nil @@ -91,12 +91,12 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Unmarshall", err) } - jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} + jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} ctx.Resp.Header().Add("Content-Type", "application/activity+json") ctx.Resp.WriteHeader(http.StatusOK) binary, _ = json.Marshal(jsonmap) - ctx.Resp.Write(binary) + _, _ = ctx.Resp.Write(binary) } // PersonInbox function diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 906be714da368..ffc69aa8de71e 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -13,6 +13,7 @@ import ( "io" "net/http" "net/url" + "strings" "time" "code.gitea.io/gitea/modules/activitypub" @@ -50,7 +51,7 @@ func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") - req.Header("Date", fmt.Sprintf("%s UTC", time.Now().UTC().Format(time.RFC1123))) + req.Header("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT")) resp, err := req.Response() if err != nil { return From 900ceb2dfde76927f89792ca795b3a635cc5cb5d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 14 Jun 2022 14:12:00 +0200 Subject: [PATCH 59/94] make fmt --- models/git/main_test.go | 3 ++- models/issues/main_test.go | 7 ++++--- routers/api/v1/activitypub/person.go | 8 ++++---- services/gitdiff/main_test.go | 3 ++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/models/git/main_test.go b/models/git/main_test.go index dc30dfaad7e15..41e6ac4704289 100644 --- a/models/git/main_test.go +++ b/models/git/main_test.go @@ -8,8 +8,9 @@ import ( "path/filepath" "testing" - _ "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + + _ "code.gitea.io/gitea/models" ) func TestMain(m *testing.M) { diff --git a/models/issues/main_test.go b/models/issues/main_test.go index e34bef62cacf6..89f9e1c9997ff 100644 --- a/models/issues/main_test.go +++ b/models/issues/main_test.go @@ -8,13 +8,14 @@ import ( "path/filepath" "testing" - _ "code.gitea.io/gitea/models" issues_model "code.gitea.io/gitea/models/issues" - _ "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" - _ "code.gitea.io/gitea/models/user" "code.gitea.io/gitea/modules/setting" + _ "code.gitea.io/gitea/models" + _ "code.gitea.io/gitea/models/repo" + _ "code.gitea.io/gitea/models/user" + "github.com/stretchr/testify/assert" ) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 22f00c01e0136..c74feadb89fc4 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -56,13 +56,13 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err) return } - + person.URL = ap.IRI(setting.AppURL + username) person.Icon = ap.Image{ - Type: ap.ImageType, + Type: ap.ImageType, MediaType: "image/png", - URL: ap.IRI(user.AvatarLink()), + URL: ap.IRI(user.AvatarLink()), } person.Inbox = nil @@ -91,7 +91,7 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Unmarshall", err) } - jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} + jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} ctx.Resp.Header().Add("Content-Type", "application/activity+json") ctx.Resp.WriteHeader(http.StatusOK) diff --git a/services/gitdiff/main_test.go b/services/gitdiff/main_test.go index 17d0da6276cee..0d36a600f64c8 100644 --- a/services/gitdiff/main_test.go +++ b/services/gitdiff/main_test.go @@ -8,8 +8,9 @@ import ( "path/filepath" "testing" - _ "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/unittest" + + _ "code.gitea.io/gitea/models" ) func TestMain(m *testing.M) { From 3f2d8b015f36b649c8af51571856845d100177ff Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Tue, 14 Jun 2022 14:26:41 +0200 Subject: [PATCH 60/94] dont drop err --- routers/api/v1/activitypub/person.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index c74feadb89fc4..ce7f0eecdf0fe 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -11,6 +11,7 @@ import ( "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" + "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/routers/api/v1/user" @@ -95,8 +96,13 @@ func Person(ctx *context.APIContext) { ctx.Resp.Header().Add("Content-Type", "application/activity+json") ctx.Resp.WriteHeader(http.StatusOK) - binary, _ = json.Marshal(jsonmap) - ctx.Resp.Write(binary) + binary, err = json.Marshal(jsonmap) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Marshal", err) + } + if _, err = ctx.Resp.Write(binary); err != nil { + log.Error("write to resp err: %v", err) + } } // PersonInbox function From e60158c70b831c0c45aa147c3571d8a6a870e27c Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 12:01:41 -0500 Subject: [PATCH 61/94] 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. --- integrations/webfinger_test.go | 2 +- routers/api/v1/activitypub/person.go | 24 ++++++++-------------- routers/api/v1/activitypub/reqsignature.go | 7 +++---- routers/api/v1/api.go | 2 +- routers/web/webfinger.go | 4 ++-- 5 files changed, 16 insertions(+), 23 deletions(-) diff --git a/integrations/webfinger_test.go b/integrations/webfinger_test.go index 98f12bee11ca0..07bf58b509fe7 100644 --- a/integrations/webfinger_test.go +++ b/integrations/webfinger_test.go @@ -52,7 +52,7 @@ func TestWebfinger(t *testing.T) { var jrd webfingerJRD DecodeJSON(t, resp, &jrd) assert.Equal(t, "acct:user2@"+appURL.Host, jrd.Subject) - assert.ElementsMatch(t, []string{user.HTMLURL(), appURL.String() + "api/v1/activitypub/user/" + user.Name}, jrd.Aliases) + assert.ElementsMatch(t, []string{user.HTMLURL(), appURL.String() + "api/v1/activitypub/user/" + url.PathEscape(user.Name)}, jrd.Aliases) req = NewRequest(t, "GET", fmt.Sprintf("/.well-known/webfinger?resource=acct:%s@%s", user.LowerName, "unknown.host")) MakeRequest(t, req, http.StatusBadRequest) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index ce7f0eecdf0fe..9b18dc118b86e 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -6,14 +6,12 @@ package activitypub import ( "net/http" - "strings" "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/routers/api/v1/user" ap "github.com/go-ap/activitypub" ) @@ -35,35 +33,29 @@ func Person(ctx *context.APIContext) { // "200": // "$ref": "#/responses/ActivityPub" - user := user.GetUserByParamsName(ctx, "username") - if user == nil { - return - } - username := ctx.Params("username") - - link := strings.TrimSuffix(setting.AppURL, "/") + strings.TrimSuffix(ctx.Req.URL.EscapedPath(), "/") + link := setting.AppURL + "api/v1/activitypub/user/" + ctx.ContextUser.Name person := ap.PersonNew(ap.IRI(link)) person.Name = ap.NaturalLanguageValuesNew() - err := person.Name.Set("en", ap.Content(user.FullName)) + err := person.Name.Set("en", ap.Content(ctx.ContextUser.FullName)) if err != nil { ctx.Error(http.StatusInternalServerError, "Set Name", err) return } person.PreferredUsername = ap.NaturalLanguageValuesNew() - err = person.PreferredUsername.Set("en", ap.Content(username)) + err = person.PreferredUsername.Set("en", ap.Content(ctx.ContextUser.Name)) if err != nil { ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err) return } - person.URL = ap.IRI(setting.AppURL + username) + person.URL = ap.IRI(ctx.ContextUser.HTMLURL()) person.Icon = ap.Image{ Type: ap.ImageType, MediaType: "image/png", - URL: ap.IRI(user.AvatarLink()), + URL: ap.IRI(ctx.ContextUser.AvatarLink()), } person.Inbox = nil @@ -74,7 +66,7 @@ func Person(ctx *context.APIContext) { person.PublicKey.ID = ap.IRI(link + "#main-key") person.PublicKey.Owner = ap.IRI(link) - publicKeyPem, err := activitypub.GetPublicKey(user) + publicKeyPem, err := activitypub.GetPublicKey(ctx.ContextUser) if err != nil { ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) return @@ -84,12 +76,14 @@ func Person(ctx *context.APIContext) { binary, err := person.MarshalJSON() if err != nil { ctx.Error(http.StatusInternalServerError, "Serialize", err) + return } var jsonmap map[string]interface{} err = json.Unmarshal(binary, &jsonmap) if err != nil { - ctx.Error(http.StatusInternalServerError, "Unmarshall", err) + ctx.Error(http.StatusInternalServerError, "Unmarshal", err) + return } jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index ffc69aa8de71e..f080f4e20110e 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -5,7 +5,6 @@ package activitypub import ( - "context" "crypto" "crypto/x509" "encoding/pem" @@ -25,7 +24,7 @@ import ( "github.com/go-fed/httpsig" ) -func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p crypto.PublicKey, err error) { +func getPublicKeyFromResponse(b []byte, keyID *url.URL) (p crypto.PublicKey, err error) { person := ap.PersonNew(ap.IRI(keyID.String())) err = person.UnmarshalJSON(b) if err != nil { @@ -34,7 +33,7 @@ func getPublicKeyFromResponse(ctx context.Context, b []byte, keyID *url.URL) (p } pubKey := person.PublicKey if pubKey.ID.String() != keyID.String() { - err = fmt.Errorf("cannot find publicKey with id: %s in %s", keyID, b) + err = fmt.Errorf("cannot find publicKey with id: %s in %s", keyID, string(b)) return } pubKeyPem := pubKey.PublicKeyPem @@ -84,7 +83,7 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er if err != nil { return } - pubKey, err := getPublicKeyFromResponse(*ctx, b, idIRI) + pubKey, err := getPublicKeyFromResponse(b, idIRI) if err != nil { return } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index fb1b0453e2306..cecf6513cba14 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -648,7 +648,7 @@ func Routes() *web.Route { m.Group("/user/{username}", func() { m.Get("", activitypub.Person) m.Post("/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) - }) + }, context_service.UserAssignmentAPI()) }) } m.Get("/signing-key.gpg", misc.SigningKey) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 92f6f3106a5e1..b52c1879a9967 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -87,7 +87,7 @@ func WebfingerQuery(ctx *context.Context) { aliases := []string{ u.HTMLURL(), - appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), + appURL.String() + "api/v1/activitypub/user/" + url.PathEscape(u.Name), } if !u.KeepEmailPrivate { aliases = append(aliases, fmt.Sprintf("mailto:%s", u.Email)) @@ -106,7 +106,7 @@ func WebfingerQuery(ctx *context.Context) { { Rel: "self", Type: "application/activity+json", - Href: appURL.String() + "api/v1/activitypub/user/" + strings.ToLower(u.Name), + Href: appURL.String() + "api/v1/activitypub/user/" + url.PathEscape(u.Name), }, { Rel: "http://ostatus.org/schema/1.0/subscribe", From a4403e4e80092c83a9e0cdb371192deeb4905ea7 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 12:16:32 -0500 Subject: [PATCH 62/94] Move httpsig algs constant slice to modules/setting/federation.go --- modules/activitypub/client.go | 11 +---------- modules/setting/federation.go | 8 ++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index bcd248e21a7f2..b04706dd090bd 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -55,15 +55,6 @@ type Client struct { pubID string } -var algos []httpsig.Algorithm - -func init() { - algos = make([]httpsig.Algorithm, len(setting.Federation.Algorithms)) - for i, algo := range setting.Federation.Algorithms { - algos[i] = httpsig.Algorithm(algo) - } -} - // NewClient function func NewClient(user *user_model.User, pubID string) (c *Client, err error) { if err = containsRequiredHTTPHeaders(http.MethodGet, setting.Federation.GetHeaders); err != nil { @@ -88,7 +79,7 @@ func NewClient(user *user_model.User, pubID string) (c *Client, err error) { Proxy: proxy.Proxy(), }, }, - algs: algos, + algs: setting.HttpsigAlgs, digestAlg: httpsig.DigestAlgorithm(setting.Federation.DigestAlgorithm), getHeaders: setting.Federation.GetHeaders, postHeaders: setting.Federation.PostHeaders, diff --git a/modules/setting/federation.go b/modules/setting/federation.go index 2fca3c2882711..cba1851dfd76d 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -29,6 +29,9 @@ var ( } ) +// Constant slice of httpsig algorithm objects +var HttpsigAlgs []httpsig.Algorithm + func newFederationService() { if err := Cfg.Section("federation").MapTo(&Federation); err != nil { log.Fatal("Failed to map Federation settings: %v", err) @@ -36,4 +39,9 @@ func newFederationService() { log.Fatal("unsupported digest algorithm: %s", Federation.DigestAlgorithm) return } + + HttpsigAlgs = make([]httpsig.Algorithm, len(Federation.Algorithms)) + for i, alg := range Federation.Algorithms { + HttpsigAlgs[i] = httpsig.Algorithm(alg) + } } From faf2855244ea267d1526d3f12f08370fe4a2e983 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 12:23:20 -0500 Subject: [PATCH 63/94] Add new federation settings to app.example.ini and config-cheat-sheet --- custom/conf/app.example.ini | 12 ++++++++++++ .../content/doc/advanced/config-cheat-sheet.en-us.md | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 5814c0d69d9ff..07c1f92273904 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2248,6 +2248,18 @@ PATH = ;; ;; Enable/Disable user statistics for nodeinfo if federation is enabled ; SHARE_USER_STATISTICS = true +;; +;; HTTP signature algorithms +; ALGORITHMS = rsa-sha256, rsa-sha512 +;; +;; HTTP signature digest algorithm +; DIGEST_ALGORITHM = SHA-256 +;; +;; GET headers for federation requests +; GET_HEADERS = (request-target), Date +;; +;; POST headers for federation requests +; POST_HEADERS = (request-target), Date, Digest ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 3981dc5fab725..5a5cad3a4624b 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -1087,6 +1087,10 @@ Task queue configuration has been moved to `queue.task`. However, the below conf - `ENABLED`: **true**: Enable/Disable federation capabilities - `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled +- `ALGORITHMS`: **rsa-sha256, rsa-sha512**: HTTP signature algorithms +- `DIGEST_ALGORITHM`: **SHA-256**: HTTP signature digest algorithm +- `GET_HEADERS`: **(request-target), Date**: GET headers for federation requests +- `POST_HEADERS`: **(request-target), Date, Digest**: POST headers for federation requests ## Packages (`packages`) From d06772b3765571c01be8b6e9eff91ceb84adb6f8 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 12:26:06 -0500 Subject: [PATCH 64/94] Return if marshalling error --- routers/api/v1/activitypub/person.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 9b18dc118b86e..663493312ff59 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -93,6 +93,7 @@ func Person(ctx *context.APIContext) { binary, err = json.Marshal(jsonmap) if err != nil { ctx.Error(http.StatusInternalServerError, "Marshal", err) + return } if _, err = ctx.Resp.Write(binary); err != nil { log.Error("write to resp err: %v", err) From a3120079a5dd4376c7c85584bdc5f6290cf5b84e Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 12:30:36 -0500 Subject: [PATCH 65/94] 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. --- routers/api/v1/activitypub/person.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 663493312ff59..f5c24ce917c63 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -6,6 +6,7 @@ package activitypub import ( "net/http" + "strings" "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" @@ -33,7 +34,7 @@ func Person(ctx *context.APIContext) { // "200": // "$ref": "#/responses/ActivityPub" - link := setting.AppURL + "api/v1/activitypub/user/" + ctx.ContextUser.Name + link := strings.TrimSuffix(setting.AppURL, "/") + "/api/v1/activitypub/user/" + ctx.ContextUser.Name person := ap.PersonNew(ap.IRI(link)) person.Name = ap.NaturalLanguageValuesNew() From f53e46c721a037c55facb9200106a6b491bf834c Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 16:23:08 -0500 Subject: [PATCH 66/94] 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 verification again fixes the bug. --- routers/api/v1/activitypub/reqsignature.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index f080f4e20110e..68f034350d175 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -90,6 +90,16 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er // 3. Verify the other actor's key algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) authenticated = v.Verify(pubKey, algo) == nil + if authenticated { + return + } + // 4. When Gitea and the other ActivityPub server are running on the same machine, the Host header is sometimes incorrect + r.Header["Host"] = []string{setting.Domain} + v, err = httpsig.NewVerifier(r) + if err != nil { + return + } + authenticated = v.Verify(pubKey, algo) == nil return } From f8ad1a832f54ff12a2120fb2449cb2e85b3be4b2 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 15 Jun 2022 03:19:34 +0200 Subject: [PATCH 67/94] Apply suggestions from code review Co-authored-by: KN4CK3R --- routers/api/v1/activitypub/person.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index f5c24ce917c63..dca22c1a38f7b 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -59,9 +59,7 @@ func Person(ctx *context.APIContext) { URL: ap.IRI(ctx.ContextUser.AvatarLink()), } - person.Inbox = nil person.Inbox, _ = ap.Inbox.AddTo(person) - person.Outbox = nil person.Outbox, _ = ap.Outbox.AddTo(person) person.PublicKey.ID = ap.IRI(link + "#main-key") From 14cfd8de230787e5547b818b845464174b9e5d6f Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 21:05:16 -0500 Subject: [PATCH 68/94] Revert "If httpsig verification fails, fix Host header and try again" This reverts commit f53e46c721a037c55facb9200106a6b491bf834c. 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. --- routers/api/v1/activitypub/reqsignature.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 68f034350d175..f080f4e20110e 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -90,16 +90,6 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er // 3. Verify the other actor's key algo := httpsig.Algorithm(setting.Federation.Algorithms[0]) authenticated = v.Verify(pubKey, algo) == nil - if authenticated { - return - } - // 4. When Gitea and the other ActivityPub server are running on the same machine, the Host header is sometimes incorrect - r.Header["Host"] = []string{setting.Domain} - v, err = httpsig.NewVerifier(r) - if err != nil { - return - } - authenticated = v.Verify(pubKey, algo) == nil return } From f48115f5f0638bfc28a4b138f27acf136b4041a6 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Tue, 14 Jun 2022 21:34:37 -0500 Subject: [PATCH 69/94] Go back to using ap.IRI to generate inbox and outbox IRIs --- routers/api/v1/activitypub/person.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index dca22c1a38f7b..7b1212fa73a19 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -59,8 +59,8 @@ func Person(ctx *context.APIContext) { URL: ap.IRI(ctx.ContextUser.AvatarLink()), } - person.Inbox, _ = ap.Inbox.AddTo(person) - person.Outbox, _ = ap.Outbox.AddTo(person) + person.Inbox = ap.IRI(link + "/inbox") + person.Outbox = ap.IRI(link + "/outbox") person.PublicKey.ID = ap.IRI(link + "#main-key") person.PublicKey.Owner = ap.IRI(link) From 172c39f78181a3e4ef6c1f4eeaebe8ed97880058 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 15 Jun 2022 08:47:32 +0200 Subject: [PATCH 70/94] use const for key values --- modules/activitypub/user_settings.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go index 553ea535f9a06..3289d45c53f6c 100644 --- a/modules/activitypub/user_settings.go +++ b/modules/activitypub/user_settings.go @@ -8,25 +8,30 @@ import ( user_model "code.gitea.io/gitea/models/user" ) +const ( + userActivitypubPrivpem = "activitypub_privpem" + userActivitypubPubpem = "activitypub_pubpem" +) + // GetKeyPair function func GetKeyPair(user *user_model.User) (pub, priv string, err error) { var settings map[string]*user_model.Setting - if settings, err = user_model.GetUserSettings(user.ID, []string{"activitypub_privpem", "activitypub_pubpem"}); err != nil { + if settings, err = user_model.GetUserSettings(user.ID, []string{userActivitypubPrivpem, userActivitypubPubpem}); err != nil { return } else if len(settings) == 0 { if priv, pub, err = GenerateKeyPair(); err != nil { return } - if err = user_model.SetUserSetting(user.ID, "activitypub_privpem", priv); err != nil { + if err = user_model.SetUserSetting(user.ID, userActivitypubPrivpem, priv); err != nil { return } - if err = user_model.SetUserSetting(user.ID, "activitypub_pubpem", pub); err != nil { + if err = user_model.SetUserSetting(user.ID, userActivitypubPubpem, pub); err != nil { return } return } else { - priv = settings["activitypub_privpem"].SettingValue - pub = settings["activitypub_pubpem"].SettingValue + priv = settings[userActivitypubPrivpem].SettingValue + pub = settings[userActivitypubPubpem].SettingValue return } } From 58401634d8e8d76b674b34a8be916ebac0e0922d Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 15 Jun 2022 08:50:26 +0200 Subject: [PATCH 71/94] Update routers/web/webfinger.go --- routers/web/webfinger.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index b52c1879a9967..49c538aafbb98 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -108,10 +108,6 @@ func WebfingerQuery(ctx *context.Context) { Type: "application/activity+json", Href: appURL.String() + "api/v1/activitypub/user/" + url.PathEscape(u.Name), }, - { - Rel: "http://ostatus.org/schema/1.0/subscribe", - Template: appURL.String() + "api/v1/authorize_interaction?uri={uri}", - }, } ctx.Resp.Header().Add("Access-Control-Allow-Origin", "*") From 95aad988975be3393c76094864ed6ba962157e0c Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 15 Jun 2022 20:22:05 -0500 Subject: [PATCH 72/94] Use ctx.JSON in Person response to make code cleaner --- routers/api/v1/activitypub/person.go | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 7b1212fa73a19..71b646dbb568e 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -84,19 +84,9 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Unmarshal", err) return } - jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} - - ctx.Resp.Header().Add("Content-Type", "application/activity+json") - ctx.Resp.WriteHeader(http.StatusOK) - binary, err = json.Marshal(jsonmap) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Marshal", err) - return - } - if _, err = ctx.Resp.Write(binary); err != nil { - log.Error("write to resp err: %v", err) - } + ctx.JSON(http.StatusOK, jsonmap) + ctx.Resp.Header().Set("Content-Type", activitypub.ActivityStreamsContentType) } // PersonInbox function From 3fe44596deeb66affa45312a340435a66f32106d Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 15 Jun 2022 20:26:47 -0500 Subject: [PATCH 73/94] 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 95aad988975be3393c76094864ed6ba962157e0c. --- routers/api/v1/activitypub/person.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 71b646dbb568e..7b1212fa73a19 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -84,9 +84,19 @@ func Person(ctx *context.APIContext) { ctx.Error(http.StatusInternalServerError, "Unmarshal", err) return } + jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} - ctx.JSON(http.StatusOK, jsonmap) - ctx.Resp.Header().Set("Content-Type", activitypub.ActivityStreamsContentType) + + ctx.Resp.Header().Add("Content-Type", "application/activity+json") + ctx.Resp.WriteHeader(http.StatusOK) + binary, err = json.Marshal(jsonmap) + if err != nil { + ctx.Error(http.StatusInternalServerError, "Marshal", err) + return + } + if _, err = ctx.Resp.Write(binary); err != nil { + log.Error("write to resp err: %v", err) + } } // PersonInbox function From e9e8a03e0825d0affd48babaa512bc780795e8fb Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 15 Jun 2022 20:29:01 -0500 Subject: [PATCH 74/94] Use activitypub.ActivityStreamsContentType for Person response Content Type --- routers/api/v1/activitypub/person.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 7b1212fa73a19..7e09a5050af77 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -87,7 +87,7 @@ func Person(ctx *context.APIContext) { jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} - ctx.Resp.Header().Add("Content-Type", "application/activity+json") + ctx.Resp.Header().Add("Content-Type", activitypub.ActivityStreamsContentType) ctx.Resp.WriteHeader(http.StatusOK) binary, err = json.Marshal(jsonmap) if err != nil { From a2d5202d4e6e0e02c2188e54d7c710b9b19685e4 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 15 Jun 2022 20:43:19 -0500 Subject: [PATCH 75/94] Limit maximum ActivityPub request and response sizes to a configurable setting --- custom/conf/app.example.ini | 3 +++ docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + modules/setting/federation.go | 2 ++ routers/api/v1/activitypub/reqsignature.go | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 2fb2c1a561a70..5a38a5200e5aa 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2249,6 +2249,9 @@ PATH = ;; Enable/Disable user statistics for nodeinfo if federation is enabled ; SHARE_USER_STATISTICS = true ;; +;; Maximum ActivityPub request and response size (MB) +; MAX_SIZE = 4 +;; ;; HTTP signature algorithms ; ALGORITHMS = rsa-sha256, rsa-sha512 ;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 314ecf478bbea..bb610a7227e2b 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -1087,6 +1087,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf - `ENABLED`: **true**: Enable/Disable federation capabilities - `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled +- `MAX_SIZE`: **4**: Maximum ActivityPub request and response size (MB) - `ALGORITHMS`: **rsa-sha256, rsa-sha512**: HTTP signature algorithms - `DIGEST_ALGORITHM`: **SHA-256**: HTTP signature digest algorithm - `GET_HEADERS`: **(request-target), Date**: GET headers for federation requests diff --git a/modules/setting/federation.go b/modules/setting/federation.go index cba1851dfd76d..db81eaebbf620 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -15,6 +15,7 @@ var ( Federation = struct { Enabled bool ShareUserStatistics bool + MaxSize int64 Algorithms []string DigestAlgorithm string GetHeaders []string @@ -22,6 +23,7 @@ var ( }{ Enabled: true, ShareUserStatistics: true, + MaxSize: 4, Algorithms: []string{"rsa-sha256", "rsa-sha512"}, DigestAlgorithm: "SHA-256", GetHeaders: []string{"(request-target)", "Date"}, diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index f080f4e20110e..e734da89dacc9 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -61,7 +61,7 @@ func fetch(iri *url.URL) (b []byte, err error) { err = fmt.Errorf("url IRI fetch [%s] failed with status (%d): %s", iri, resp.StatusCode, resp.Status) return } - b, err = io.ReadAll(resp.Body) + b, err = io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize*(1<<20))) return } From fb1f551153676e4d390f0fe7615102fde3646d40 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 15 Jun 2022 20:56:50 -0500 Subject: [PATCH 76/94] Move setting key constants to models/user/setting_keys.go --- custom/conf/app.example.ini | 2 +- .../doc/advanced/config-cheat-sheet.en-us.md | 2 +- models/user/setting_keys.go | 4 ++++ modules/activitypub/user_settings.go | 16 ++++++---------- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 5a38a5200e5aa..ad46d3af8d447 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2249,7 +2249,7 @@ PATH = ;; Enable/Disable user statistics for nodeinfo if federation is enabled ; SHARE_USER_STATISTICS = true ;; -;; Maximum ActivityPub request and response size (MB) +;; Maximum federation request and response size (MB) ; MAX_SIZE = 4 ;; ;; HTTP signature algorithms diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index bb610a7227e2b..95317b2a2c6f3 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -1087,7 +1087,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf - `ENABLED`: **true**: Enable/Disable federation capabilities - `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled -- `MAX_SIZE`: **4**: Maximum ActivityPub request and response size (MB) +- `MAX_SIZE`: **4**: Maximum federation request and response size (MB) - `ALGORITHMS`: **rsa-sha256, rsa-sha512**: HTTP signature algorithms - `DIGEST_ALGORITHM`: **SHA-256**: HTTP signature digest algorithm - `GET_HEADERS`: **(request-target), Date**: GET headers for federation requests diff --git a/models/user/setting_keys.go b/models/user/setting_keys.go index 109b5dd916365..d48ac930527a6 100644 --- a/models/user/setting_keys.go +++ b/models/user/setting_keys.go @@ -9,4 +9,8 @@ const ( SettingsKeyHiddenCommentTypes = "issue.hidden_comment_types" // SettingsKeyDiffWhitespaceBehavior is the setting key for whitespace behavior of diff SettingsKeyDiffWhitespaceBehavior = "diff.whitespace_behaviour" + // UserActivityPubPrivPem is user's private key + UserActivityPubPrivPem = "activitypub.priv_pem" + // UserActivityPubPubPem is user's public key + UserActivityPubPubPem = "activitypub.pub_pem" ) diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go index 3289d45c53f6c..a0da6f68f9044 100644 --- a/modules/activitypub/user_settings.go +++ b/modules/activitypub/user_settings.go @@ -8,30 +8,26 @@ import ( user_model "code.gitea.io/gitea/models/user" ) -const ( - userActivitypubPrivpem = "activitypub_privpem" - userActivitypubPubpem = "activitypub_pubpem" -) - // GetKeyPair function func GetKeyPair(user *user_model.User) (pub, priv string, err error) { var settings map[string]*user_model.Setting - if settings, err = user_model.GetUserSettings(user.ID, []string{userActivitypubPrivpem, userActivitypubPubpem}); err != nil { + settings, err = user_model.GetUserSettings(user.ID, []string{user_model.UserActivityPubPrivPem, user_model.UserActivityPubPubPem}) + if err != nil { return } else if len(settings) == 0 { if priv, pub, err = GenerateKeyPair(); err != nil { return } - if err = user_model.SetUserSetting(user.ID, userActivitypubPrivpem, priv); err != nil { + if err = user_model.SetUserSetting(user.ID, user_model.UserActivityPubPrivPem, priv); err != nil { return } - if err = user_model.SetUserSetting(user.ID, userActivitypubPubpem, pub); err != nil { + if err = user_model.SetUserSetting(user.ID, user_model.UserActivityPubPubPem, pub); err != nil { return } return } else { - priv = settings[userActivitypubPrivpem].SettingValue - pub = settings[userActivitypubPubpem].SettingValue + priv = settings[user_model.UserActivityPubPrivPem].SettingValue + pub = settings[user_model.UserActivityPubPubPem].SettingValue return } } From ad62049f0b5ba4badf21a68cefcbaecdbacea703 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Wed, 15 Jun 2022 20:59:57 -0500 Subject: [PATCH 77/94] Fix failing ActivityPubPerson integration test by checking the correct field for username --- integrations/api_activitypub_person_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index 70f1134fa52d7..b6e4c069e8976 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -38,7 +38,7 @@ func TestActivityPubPerson(t *testing.T) { assert.NoError(t, err) assert.Equal(t, ap.PersonType, person.Type) - assert.Equal(t, username, person.Name.String()) + assert.Equal(t, username, person.PreferredUsername.String()) keyID := person.GetID().String() assert.Regexp(t, fmt.Sprintf("activitypub/user/%s$", username), keyID) assert.Regexp(t, fmt.Sprintf("activitypub/user/%s/outbox$", username), person.Outbox.GetID().String()) From db13e1d6a115f37afcda5c34672af293cee6db44 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 10:53:18 -0500 Subject: [PATCH 78/94] Add a warning about changing settings that can break federation --- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 95317b2a2c6f3..54a0ef901dc42 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -1088,6 +1088,9 @@ Task queue configuration has been moved to `queue.task`. However, the below conf - `ENABLED`: **true**: Enable/Disable federation capabilities - `SHARE_USER_STATISTICS`: **true**: Enable/Disable user statistics for nodeinfo if federation is enabled - `MAX_SIZE`: **4**: Maximum federation request and response size (MB) + + WARNING: Changing the settings below can break federation. + - `ALGORITHMS`: **rsa-sha256, rsa-sha512**: HTTP signature algorithms - `DIGEST_ALGORITHM`: **SHA-256**: HTTP signature digest algorithm - `GET_HEADERS`: **(request-target), Date**: GET headers for federation requests From 6336ba2e830f6d9b0cc2fd3edb1b9a74b8e5ff73 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 10:59:36 -0500 Subject: [PATCH 79/94] Add better comments --- modules/setting/federation.go | 3 +++ routers/api/v1/activitypub/person.go | 6 +++--- routers/api/v1/activitypub/reqsignature.go | 4 ++-- routers/api/v1/api.go | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modules/setting/federation.go b/modules/setting/federation.go index db81eaebbf620..53a83fa845e7f 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -42,6 +42,9 @@ func newFederationService() { return } + // Get MaxSize in bytes instead of MiB + Federation.MaxSize = 1 << 20 * Federation.MaxSize + HttpsigAlgs = make([]httpsig.Algorithm, len(Federation.Algorithms)) for i, alg := range Federation.Algorithms { HttpsigAlgs[i] = httpsig.Algorithm(alg) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 7e09a5050af77..0e123881aa86e 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -17,11 +17,11 @@ import ( ap "github.com/go-ap/activitypub" ) -// Person function +// Person function returns the Person actor for a user func Person(ctx *context.APIContext) { // swagger:operation GET /activitypub/user/{username} activitypub activitypubPerson // --- - // summary: Returns the person + // summary: Returns the Person actor for a user // produces: // - application/json // parameters: @@ -99,7 +99,7 @@ func Person(ctx *context.APIContext) { } } -// PersonInbox function +// PersonInbox function handles the incoming data for a user inbox func PersonInbox(ctx *context.APIContext) { // swagger:operation POST /activitypub/user/{username}/inbox activitypub activitypubPersonInbox // --- diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index e734da89dacc9..5897765d9b3e5 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -93,8 +93,8 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er return } -// ReqSignature function -func ReqSignature() func(ctx *gitea_context.APIContext) { +// ReqHTTPSignature function +func ReqHTTPSignature() func(ctx *gitea_context.APIContext) { return func(ctx *gitea_context.APIContext) { if authenticated, err := verifyHTTPSignatures(ctx); err != nil { ctx.Error(http.StatusInternalServerError, "verifyHttpSignatures", err) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index cecf6513cba14..c93606ae88308 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -647,7 +647,7 @@ func Routes() *web.Route { m.Group("/activitypub", func() { m.Group("/user/{username}", func() { m.Get("", activitypub.Person) - m.Post("/inbox", activitypub.ReqSignature(), activitypub.PersonInbox) + m.Post("/inbox", activitypub.ReqHTTPSignature(), activitypub.PersonInbox) }, context_service.UserAssignmentAPI()) }) } From 0c49fea641e074ab3d1b329dea6035d76d8fb174 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 11:00:24 -0500 Subject: [PATCH 80/94] Don't multiply Federation.MaxSize by 1<<20 twice --- routers/api/v1/activitypub/reqsignature.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 5897765d9b3e5..c90ed6d4b8599 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -61,7 +61,7 @@ func fetch(iri *url.URL) (b []byte, err error) { err = fmt.Errorf("url IRI fetch [%s] failed with status (%d): %s", iri, resp.StatusCode, resp.Status) return } - b, err = io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize*(1<<20))) + b, err = io.ReadAll(io.LimitReader(resp.Body, setting.Federation.MaxSize)) return } From 6602fd136ee721dee427e49faa011114cb151649 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 11:03:53 -0500 Subject: [PATCH 81/94] Add more better comments --- modules/activitypub/user_settings.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/activitypub/user_settings.go b/modules/activitypub/user_settings.go index a0da6f68f9044..2144e7b47fb3b 100644 --- a/modules/activitypub/user_settings.go +++ b/modules/activitypub/user_settings.go @@ -8,7 +8,7 @@ import ( user_model "code.gitea.io/gitea/models/user" ) -// GetKeyPair function +// GetKeyPair function returns a user's private and public keys func GetKeyPair(user *user_model.User) (pub, priv string, err error) { var settings map[string]*user_model.Setting settings, err = user_model.GetUserSettings(user.ID, []string{user_model.UserActivityPubPrivPem, user_model.UserActivityPubPubPem}) @@ -32,13 +32,13 @@ func GetKeyPair(user *user_model.User) (pub, priv string, err error) { } } -// GetPublicKey function +// GetPublicKey function returns a user's public key func GetPublicKey(user *user_model.User) (pub string, err error) { pub, _, err = GetKeyPair(user) return } -// GetPrivateKey function +// GetPrivateKey function returns a user's private key func GetPrivateKey(user *user_model.User) (priv string, err error) { _, priv, err = GetKeyPair(user) return From 3a8b8408b4c12ddc845f035e96e3fc291e2bf860 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 11:08:24 -0500 Subject: [PATCH 82/94] Fix failing ActivityPubMissingPerson test We now use ctx.ContextUser so the message printed out when a user does not exist is slightly different --- integrations/api_activitypub_person_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/api_activitypub_person_test.go b/integrations/api_activitypub_person_test.go index b6e4c069e8976..4898d5e01d8ef 100644 --- a/integrations/api_activitypub_person_test.go +++ b/integrations/api_activitypub_person_test.go @@ -64,7 +64,7 @@ func TestActivityPubMissingPerson(t *testing.T) { req := NewRequestf(t, "GET", "/api/v1/activitypub/user/nonexistentuser") resp := MakeRequest(t, req, http.StatusNotFound) - assert.Contains(t, resp.Body.String(), "GetUserByName") + assert.Contains(t, resp.Body.String(), "user redirect does not exist") }) } From 2a013b8fe449ad5e73a259822b8092c980da1c59 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 11:11:57 -0500 Subject: [PATCH 83/94] make generate-swagger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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! 🤦 --- templates/swagger/v1_json.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 071020ecc6bdc..2daf85586f127 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -31,7 +31,7 @@ "tags": [ "activitypub" ], - "summary": "Returns the person", + "summary": "Returns the Person actor for a user", "operationId": "activitypubPerson", "parameters": [ { From c118dacde73bd1e8a10e9bc171001e5b4d3a59e2 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 11:17:05 -0500 Subject: [PATCH 84/94] Move getting the RFC 2616 time to a separate function --- modules/activitypub/client.go | 8 ++++++-- routers/api/v1/activitypub/reqsignature.go | 4 +--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index b04706dd090bd..8c2854f71f611 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -27,6 +27,11 @@ const ( httpsigExpirationTime = 60 ) +// Gets the current time as an RFC 2616 formatted string +func CurrentTime() string { + return strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT") +} + func containsRequiredHTTPHeaders(method string, headers []string) error { var hasRequestTarget, hasDate, hasDigest bool for _, header := range headers { @@ -98,8 +103,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) } req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Accept-Charset", "utf-8") - req.Header.Add("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT")) - + req.Header.Add("Date", CurrentTime()) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { return diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index c90ed6d4b8599..316d66cd8ea18 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -12,8 +12,6 @@ import ( "io" "net/http" "net/url" - "strings" - "time" "code.gitea.io/gitea/modules/activitypub" gitea_context "code.gitea.io/gitea/modules/context" @@ -50,7 +48,7 @@ func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) req.Header("Accept-Charset", "utf-8") - req.Header("Date", strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT")) + req.Header("Date", activitypub.CurrentTime()) resp, err := req.Response() if err != nil { return From 7a214dd212c7835e424b9113bdcb33d984f0500b Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Thu, 16 Jun 2022 14:18:30 -0500 Subject: [PATCH 85/94] More code cleanup --- custom/conf/app.example.ini | 2 ++ modules/activitypub/client.go | 1 + modules/activitypub/main_test.go | 5 +++-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 5b8d505374608..4b258d5698b88 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2255,6 +2255,8 @@ PATH = ;; Maximum federation request and response size (MB) ; MAX_SIZE = 4 ;; +;; WARNING: Changing the settings below can break federation. +;; ;; HTTP signature algorithms ; ALGORITHMS = rsa-sha256, rsa-sha512 ;; diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 8c2854f71f611..46b8c675bd9d2 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -28,6 +28,7 @@ const ( ) // Gets the current time as an RFC 2616 formatted string +// RFC 2616 requires RFC 1123 dates but with GMT instead of UTC func CurrentTime() string { return strings.ReplaceAll(time.Now().UTC().Format(time.RFC1123), "UTC", "GMT") } diff --git a/modules/activitypub/main_test.go b/modules/activitypub/main_test.go index 289bc9f32b119..7fa2b09265cec 100644 --- a/modules/activitypub/main_test.go +++ b/modules/activitypub/main_test.go @@ -12,6 +12,7 @@ import ( ) func TestMain(m *testing.M) { - testOps := unittest.TestOptions{GiteaRootPath: filepath.Join("..", "..")} - unittest.MainTest(m, &testOps) + unittest.MainTest(m, &unittest.TestOptions{ + GiteaRootPath: filepath.Join("..", ".."), + }) } From 8e6f3fbf4650ac7e9100ff8096719d6698266794 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 17 Jun 2022 11:10:51 -0500 Subject: [PATCH 86/94] Update go-ap to fix empty liked collection and removed unneeded HTTP headers --- go.mod | 6 +++--- go.sum | 6 ++++++ modules/activitypub/client.go | 1 - routers/api/v1/activitypub/reqsignature.go | 2 -- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 8e5871cfb0bcd..5a133ce7fa191 100644 --- a/go.mod +++ b/go.mod @@ -27,7 +27,7 @@ require ( github.com/emirpasic/gods v1.18.1 github.com/ethantkoenig/rupture v1.0.1 github.com/gliderlabs/ssh v0.3.4 - github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068 + github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.1 github.com/go-enry/go-enry/v2 v2.8.2 @@ -161,8 +161,8 @@ require ( github.com/fsnotify/fsnotify v1.5.4 // indirect github.com/fullstorydev/grpcurl v1.8.1 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect - github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369 // indirect - github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 // indirect + github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f // indirect + github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect github.com/go-enry/go-oniguruma v1.2.1 // indirect github.com/go-git/gcfg v1.5.0 // indirect diff --git a/go.sum b/go.sum index db7044c1a7b93..9dbb77b430fba 100644 --- a/go.sum +++ b/go.sum @@ -462,10 +462,16 @@ github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068 h1:Xzxc/HjHFAwJTieEWcC1SjBHVBq+Y1xPgk7WWcG3sjs= github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068/go.mod h1:h5U5YGW+z4mVF3XH6bKfBmsJinRVuKpS23uYqJfGSbo= +github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b h1:+RjYfEfoZdM3wHFs752dlOpGaoRhwRRyQxjajg08LcQ= +github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b/go.mod h1:DE3vvc6Didgfd3k7M1Mos6qMDFNmMrxJmYVMHG9h9Io= github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369 h1:z09Qf9XB5lU3NBZnrsN9VJqrIgwKLrsBVUgrir4zL9A= github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369/go.mod h1:yENIaXEY5AiFL/qGTBBcPuk40I5SLyZzwrQj2ID5PHQ= +github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f h1:kJhGo4NApJP0Lt9lkJnfmuTnRWVFbCynY0kiTxpPUR4= +github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f/go.mod h1:KHkKFKZvc05lr79+RGoq/zG8YjWi3+FK60Bxd+mpCew= github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 h1:AUG8+r0Q/zbNUAi5CWVBK5oUhOZDX3Kkr+oWURaJIfU= github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= +github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d h1:Z/oRXMlZHjvjIqDma1FrIGL3iE5YL7MUI0bwYEZ6qbA= +github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= github.com/go-asn1-ber/asn1-ber v1.5.4 h1:vXT6d/FNDiELJnLb6hGNa309LMsrCoYFvpwHDF0+Y1A= github.com/go-asn1-ber/asn1-ber v1.5.4/go.mod h1:hEBeB/ic+5LoWskz+yKT7vGhhPYkProFKoKdwZRWMe0= github.com/go-chi/chi/v5 v5.0.1/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8= diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 46b8c675bd9d2..923bc4ea4813c 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -103,7 +103,6 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) return } req.Header.Add("Content-Type", ActivityStreamsContentType) - req.Header.Add("Accept-Charset", "utf-8") req.Header.Add("Date", CurrentTime()) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 316d66cd8ea18..08e6b57e27767 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -47,8 +47,6 @@ func getPublicKeyFromResponse(b []byte, keyID *url.URL) (p crypto.PublicKey, err func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) - req.Header("Accept-Charset", "utf-8") - req.Header("Date", activitypub.CurrentTime()) resp, err := req.Response() if err != nil { return From 7446583a0d760605bb6cfb12a6a5890ea58adec3 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 17 Jun 2022 11:38:56 -0500 Subject: [PATCH 87/94] go mod tidy --- go.sum | 6 ------ 1 file changed, 6 deletions(-) diff --git a/go.sum b/go.sum index 9dbb77b430fba..cf311199c6097 100644 --- a/go.sum +++ b/go.sum @@ -460,16 +460,10 @@ github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0 github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q= github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/goconvey v0.0.0-20190410193231-58a59202ab31/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24= -github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068 h1:Xzxc/HjHFAwJTieEWcC1SjBHVBq+Y1xPgk7WWcG3sjs= -github.com/go-ap/activitypub v0.0.0-20220606130025-d23c21aea068/go.mod h1:h5U5YGW+z4mVF3XH6bKfBmsJinRVuKpS23uYqJfGSbo= github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b h1:+RjYfEfoZdM3wHFs752dlOpGaoRhwRRyQxjajg08LcQ= github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b/go.mod h1:DE3vvc6Didgfd3k7M1Mos6qMDFNmMrxJmYVMHG9h9Io= -github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369 h1:z09Qf9XB5lU3NBZnrsN9VJqrIgwKLrsBVUgrir4zL9A= -github.com/go-ap/errors v0.0.0-20220529131844-4c7dbeabb369/go.mod h1:yENIaXEY5AiFL/qGTBBcPuk40I5SLyZzwrQj2ID5PHQ= github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f h1:kJhGo4NApJP0Lt9lkJnfmuTnRWVFbCynY0kiTxpPUR4= github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f/go.mod h1:KHkKFKZvc05lr79+RGoq/zG8YjWi3+FK60Bxd+mpCew= -github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660 h1:AUG8+r0Q/zbNUAi5CWVBK5oUhOZDX3Kkr+oWURaJIfU= -github.com/go-ap/jsonld v0.0.0-20200327122108-fafac2de2660/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d h1:Z/oRXMlZHjvjIqDma1FrIGL3iE5YL7MUI0bwYEZ6qbA= github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= github.com/go-asn1-ber/asn1-ber v1.5.4 h1:vXT6d/FNDiELJnLb6hGNa309LMsrCoYFvpwHDF0+Y1A= From 47011db720aee616f91ab6afea3a7ae530e7f287 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Fri, 17 Jun 2022 13:43:26 -0500 Subject: [PATCH 88/94] Add ed25519 to httpsig algorithms --- custom/conf/app.example.ini | 2 +- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 2 +- modules/setting/federation.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index 4b258d5698b88..fb7770a4a86fa 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2258,7 +2258,7 @@ PATH = ;; WARNING: Changing the settings below can break federation. ;; ;; HTTP signature algorithms -; ALGORITHMS = rsa-sha256, rsa-sha512 +; ALGORITHMS = rsa-sha256, rsa-sha512, ed25519 ;; ;; HTTP signature digest algorithm ; DIGEST_ALGORITHM = SHA-256 diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 75c1c401450f6..4710fdbe9ec7c 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -1094,7 +1094,7 @@ Task queue configuration has been moved to `queue.task`. However, the below conf WARNING: Changing the settings below can break federation. -- `ALGORITHMS`: **rsa-sha256, rsa-sha512**: HTTP signature algorithms +- `ALGORITHMS`: **rsa-sha256, rsa-sha512, ed25519**: HTTP signature algorithms - `DIGEST_ALGORITHM`: **SHA-256**: HTTP signature digest algorithm - `GET_HEADERS`: **(request-target), Date**: GET headers for federation requests - `POST_HEADERS`: **(request-target), Date, Digest**: POST headers for federation requests diff --git a/modules/setting/federation.go b/modules/setting/federation.go index 53a83fa845e7f..b06d0a9219097 100644 --- a/modules/setting/federation.go +++ b/modules/setting/federation.go @@ -24,7 +24,7 @@ var ( Enabled: true, ShareUserStatistics: true, MaxSize: 4, - Algorithms: []string{"rsa-sha256", "rsa-sha512"}, + Algorithms: []string{"rsa-sha256", "rsa-sha512", "ed25519"}, DigestAlgorithm: "SHA-256", GetHeaders: []string{"(request-target)", "Date"}, PostHeaders: []string{"(request-target)", "Date", "Digest"}, From 37d2d01f8f3273e169e771ade6a843c68e5f7d16 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 12:27:11 -0500 Subject: [PATCH 89/94] Use go-ap/jsonld to add @context and marshal JSON --- routers/api/v1/activitypub/person.go | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 0e123881aa86e..1cc5be8e11175 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -10,11 +10,11 @@ import ( "code.gitea.io/gitea/modules/activitypub" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/json" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" ap "github.com/go-ap/activitypub" + "github.com/go-ap/jsonld" ) // Person function returns the Person actor for a user @@ -72,28 +72,13 @@ func Person(ctx *context.APIContext) { } person.PublicKey.PublicKeyPem = publicKeyPem - binary, err := person.MarshalJSON() + binary, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI), jsonld.IRI(ap.SecurityContextURI)).Marshal(person) if err != nil { - ctx.Error(http.StatusInternalServerError, "Serialize", err) + ctx.Error(http.StatusInternalServerError, "MarshalJSON", err) return } - - var jsonmap map[string]interface{} - err = json.Unmarshal(binary, &jsonmap) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Unmarshal", err) - return - } - - jsonmap["@context"] = []string{"https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"} - ctx.Resp.Header().Add("Content-Type", activitypub.ActivityStreamsContentType) ctx.Resp.WriteHeader(http.StatusOK) - binary, err = json.Marshal(jsonmap) - if err != nil { - ctx.Error(http.StatusInternalServerError, "Marshal", err) - return - } if _, err = ctx.Resp.Write(binary); err != nil { log.Error("write to resp err: %v", err) } From 7c10ab9fde6b2b2360e5968aa0172b1565bca161 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 13:08:00 -0500 Subject: [PATCH 90/94] Change Gitea user agent from the default to Gitea/Version --- modules/activitypub/client.go | 1 + routers/api/v1/activitypub/reqsignature.go | 1 + 2 files changed, 2 insertions(+) diff --git a/modules/activitypub/client.go b/modules/activitypub/client.go index 923bc4ea4813c..738b1e47372bb 100644 --- a/modules/activitypub/client.go +++ b/modules/activitypub/client.go @@ -104,6 +104,7 @@ func (c *Client) NewRequest(b []byte, to string) (req *http.Request, err error) } req.Header.Add("Content-Type", ActivityStreamsContentType) req.Header.Add("Date", CurrentTime()) + req.Header.Add("User-Agent", "Gitea/"+setting.AppVer) signer, _, err := httpsig.NewSigner(c.algs, c.digestAlg, c.postHeaders, httpsig.Signature, httpsigExpirationTime) if err != nil { return diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 08e6b57e27767..4603685522a98 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -47,6 +47,7 @@ func getPublicKeyFromResponse(b []byte, keyID *url.URL) (p crypto.PublicKey, err func fetch(iri *url.URL) (b []byte, err error) { req := httplib.NewRequest(iri.String(), http.MethodGet) req.Header("Accept", activitypub.ActivityStreamsContentType) + req.Header("User-Agent", "Gitea/"+setting.AppVer) resp, err := req.Response() if err != nil { return From 0231dad17343127cd6a66b081e5ec9d580391bfc Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 13:20:36 -0500 Subject: [PATCH 91/94] go mod tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 1f9bd12b257c2..e9b4194c79936 100644 --- a/go.mod +++ b/go.mod @@ -29,6 +29,7 @@ require ( github.com/felixge/fgprof v0.9.2 github.com/gliderlabs/ssh v0.3.4 github.com/go-ap/activitypub v0.0.0-20220615144428-48208c70483b + github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d github.com/go-chi/chi/v5 v5.0.7 github.com/go-chi/cors v1.2.1 github.com/go-enry/go-enry/v2 v2.8.2 @@ -163,7 +164,6 @@ require ( github.com/fullstorydev/grpcurl v1.8.1 // indirect github.com/fxamacker/cbor/v2 v2.4.0 // indirect github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f // indirect - github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d // indirect github.com/go-asn1-ber/asn1-ber v1.5.4 // indirect github.com/go-enry/go-oniguruma v1.2.1 // indirect github.com/go-git/gcfg v1.5.0 // indirect From 4ffb6b64bc95e32027f6d59c182f3cb33416858e Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 16:30:30 -0500 Subject: [PATCH 92/94] Use ctx.ServerError and remove all remote interaction code from webfinger.go --- FEDERATION.md | 25 +++++++++++++++++++++++++ go.work | 5 +++++ go.work.sum | 10 ++++++++++ routers/api/v1/activitypub/person.go | 8 ++++---- routers/web/webfinger.go | 1 - 5 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 FEDERATION.md create mode 100644 go.work create mode 100644 go.work.sum diff --git a/FEDERATION.md b/FEDERATION.md new file mode 100644 index 0000000000000..5622fdb4e65c5 --- /dev/null +++ b/FEDERATION.md @@ -0,0 +1,25 @@ +# Federation + +Gitea is federated using [ActivityPub](https://www.w3.org/TR/activitypub/) and the [ForgeFed extension](https://forgefed.org/) so you can interact with users and repositories from other instances as if they were on your own instance. By using the standardized ActivityPub protocol, users on any fediverse software such as [Mastodon](https://joinmastodon.org/) can follow Gitea users, receive activity updates, and comment on issues. + +Currently, only S2S ActivityPub is supported. + +## Actors + +Following the ForgeFed specification, users (`Person` type), organizations (`Group` type), and repositories (`Repository` type) are the ActivityPub actors in Gitea. + +### Users + +Users are represented using the `Person` type and can be found at `/api/v1/activitypub/user/{username}`. + +### Organizations + +Organizations are represented using the `Group` type and can be found at `/api/v1/activitypub/user/{orgname}`. + +### Repositories + +Repositories are represented using the `Repository` type and can be found at `/api/v1/activitypub/repo/{username}/{reponame}`. + +## Changing your username, organization name, or repository name + +Do we want to support this? If so, Gitea will send out a `Move` activity. diff --git a/go.work b/go.work new file mode 100644 index 0000000000000..bf84738c07cc3 --- /dev/null +++ b/go.work @@ -0,0 +1,5 @@ +go 1.18 + +use . + +replace github.com/go-ap/activitypub => /home/ta180m/Code/activitypub diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 0000000000000..27d33cf48f669 --- /dev/null +++ b/go.work.sum @@ -0,0 +1,10 @@ +github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= +github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= +github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f h1:kJhGo4NApJP0Lt9lkJnfmuTnRWVFbCynY0kiTxpPUR4= +github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f/go.mod h1:KHkKFKZvc05lr79+RGoq/zG8YjWi3+FK60Bxd+mpCew= +github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d h1:Z/oRXMlZHjvjIqDma1FrIGL3iE5YL7MUI0bwYEZ6qbA= +github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= +github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= +github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s= +github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= +github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= diff --git a/routers/api/v1/activitypub/person.go b/routers/api/v1/activitypub/person.go index 1cc5be8e11175..7290f1cbd9842 100644 --- a/routers/api/v1/activitypub/person.go +++ b/routers/api/v1/activitypub/person.go @@ -40,14 +40,14 @@ func Person(ctx *context.APIContext) { person.Name = ap.NaturalLanguageValuesNew() err := person.Name.Set("en", ap.Content(ctx.ContextUser.FullName)) if err != nil { - ctx.Error(http.StatusInternalServerError, "Set Name", err) + ctx.ServerError("Set Name", err) return } person.PreferredUsername = ap.NaturalLanguageValuesNew() err = person.PreferredUsername.Set("en", ap.Content(ctx.ContextUser.Name)) if err != nil { - ctx.Error(http.StatusInternalServerError, "Set PreferredUsername", err) + ctx.ServerError("Set PreferredUsername", err) return } @@ -67,14 +67,14 @@ func Person(ctx *context.APIContext) { publicKeyPem, err := activitypub.GetPublicKey(ctx.ContextUser) if err != nil { - ctx.Error(http.StatusInternalServerError, "GetPublicKey", err) + ctx.ServerError("GetPublicKey", err) return } person.PublicKey.PublicKeyPem = publicKeyPem binary, err := jsonld.WithContext(jsonld.IRI(ap.ActivityBaseURI), jsonld.IRI(ap.SecurityContextURI)).Marshal(person) if err != nil { - ctx.Error(http.StatusInternalServerError, "MarshalJSON", err) + ctx.ServerError("MarshalJSON", err) return } ctx.Resp.Header().Add("Content-Type", activitypub.ActivityStreamsContentType) diff --git a/routers/web/webfinger.go b/routers/web/webfinger.go index 49c538aafbb98..c4808fbfd2419 100644 --- a/routers/web/webfinger.go +++ b/routers/web/webfinger.go @@ -29,7 +29,6 @@ type webfingerLink struct { Rel string `json:"rel,omitempty"` Type string `json:"type,omitempty"` Href string `json:"href,omitempty"` - Template string `json:"template,omitempty"` Titles map[string]string `json:"titles,omitempty"` Properties map[string]interface{} `json:"properties,omitempty"` } From 28fd3e796e6fdd22d63fdd649cd3f053f3522ff3 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 16:33:12 -0500 Subject: [PATCH 93/94] Remove accidently added files --- FEDERATION.md | 25 ------------------------- go.work | 5 ----- go.work.sum | 10 ---------- 3 files changed, 40 deletions(-) delete mode 100644 FEDERATION.md delete mode 100644 go.work delete mode 100644 go.work.sum diff --git a/FEDERATION.md b/FEDERATION.md deleted file mode 100644 index 5622fdb4e65c5..0000000000000 --- a/FEDERATION.md +++ /dev/null @@ -1,25 +0,0 @@ -# Federation - -Gitea is federated using [ActivityPub](https://www.w3.org/TR/activitypub/) and the [ForgeFed extension](https://forgefed.org/) so you can interact with users and repositories from other instances as if they were on your own instance. By using the standardized ActivityPub protocol, users on any fediverse software such as [Mastodon](https://joinmastodon.org/) can follow Gitea users, receive activity updates, and comment on issues. - -Currently, only S2S ActivityPub is supported. - -## Actors - -Following the ForgeFed specification, users (`Person` type), organizations (`Group` type), and repositories (`Repository` type) are the ActivityPub actors in Gitea. - -### Users - -Users are represented using the `Person` type and can be found at `/api/v1/activitypub/user/{username}`. - -### Organizations - -Organizations are represented using the `Group` type and can be found at `/api/v1/activitypub/user/{orgname}`. - -### Repositories - -Repositories are represented using the `Repository` type and can be found at `/api/v1/activitypub/repo/{username}/{reponame}`. - -## Changing your username, organization name, or repository name - -Do we want to support this? If so, Gitea will send out a `Move` activity. diff --git a/go.work b/go.work deleted file mode 100644 index bf84738c07cc3..0000000000000 --- a/go.work +++ /dev/null @@ -1,5 +0,0 @@ -go 1.18 - -use . - -replace github.com/go-ap/activitypub => /home/ta180m/Code/activitypub diff --git a/go.work.sum b/go.work.sum deleted file mode 100644 index 27d33cf48f669..0000000000000 --- a/go.work.sum +++ /dev/null @@ -1,10 +0,0 @@ -github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko= -github.com/cpuguy83/go-md2man v1.0.10 h1:BSKMNlYxDvnunlTymqtgONjNnaRV1sTpcovwwjF22jk= -github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f h1:kJhGo4NApJP0Lt9lkJnfmuTnRWVFbCynY0kiTxpPUR4= -github.com/go-ap/errors v0.0.0-20220615144307-e8bc4a40ae9f/go.mod h1:KHkKFKZvc05lr79+RGoq/zG8YjWi3+FK60Bxd+mpCew= -github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d h1:Z/oRXMlZHjvjIqDma1FrIGL3iE5YL7MUI0bwYEZ6qbA= -github.com/go-ap/jsonld v0.0.0-20220615144122-1d862b15410d/go.mod h1:jyveZeGw5LaADntW+UEsMjl3IlIwk+DxlYNsbofQkGA= -github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= -github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s= -github.com/pierrec/lz4 v2.0.5+incompatible h1:2xWsjqPFWcplujydGg4WmhC/6fZqK42wMM8aXeqhl0I= -github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo= From f602958f3c170c6b84b4ba0ece53568fddb56010 Mon Sep 17 00:00:00 2001 From: Anthony Wang Date: Sat, 18 Jun 2022 17:04:02 -0500 Subject: [PATCH 94/94] Use ctx.ServerError in reqsignature.go --- routers/api/v1/activitypub/reqsignature.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/activitypub/reqsignature.go b/routers/api/v1/activitypub/reqsignature.go index 4603685522a98..b870d1c0f9ee4 100644 --- a/routers/api/v1/activitypub/reqsignature.go +++ b/routers/api/v1/activitypub/reqsignature.go @@ -94,7 +94,7 @@ func verifyHTTPSignatures(ctx *gitea_context.APIContext) (authenticated bool, er func ReqHTTPSignature() func(ctx *gitea_context.APIContext) { return func(ctx *gitea_context.APIContext) { if authenticated, err := verifyHTTPSignatures(ctx); err != nil { - ctx.Error(http.StatusInternalServerError, "verifyHttpSignatures", err) + ctx.ServerError("verifyHttpSignatures", err) } else if !authenticated { ctx.Error(http.StatusForbidden, "reqSignature", "request signature verification failed") }