From 4f2d1614018a330dcc84c06f3cf78b044fb00f9f Mon Sep 17 00:00:00 2001 From: Till Faelligen Date: Mon, 21 Feb 2022 17:09:25 +0100 Subject: [PATCH] Remove consentMux --- build/gobind-pinecone/monolith.go | 1 - build/gobind-yggdrasil/monolith.go | 1 - clientapi/clientapi.go | 3 +-- clientapi/routing/consent_tracking.go | 2 +- clientapi/routing/routing.go | 6 +++--- cmd/dendrite-demo-libp2p/main.go | 1 - cmd/dendrite-demo-pinecone/main.go | 1 - cmd/dendrite-demo-yggdrasil/main.go | 1 - cmd/dendrite-monolith-server/main.go | 1 - cmd/dendrite-polylith-multi/personalities/clientapi.go | 2 +- cmd/dendritejs-pinecone/main.go | 1 - cmd/dendritejs/main.go | 1 - internal/httputil/httpapi.go | 2 +- setup/base/base.go | 3 --- setup/config/config.go | 2 +- setup/monolith.go | 4 ++-- 16 files changed, 10 insertions(+), 22 deletions(-) diff --git a/build/gobind-pinecone/monolith.go b/build/gobind-pinecone/monolith.go index ed11ee749..aa8cc6e6e 100644 --- a/build/gobind-pinecone/monolith.go +++ b/build/gobind-pinecone/monolith.go @@ -348,7 +348,6 @@ func (m *DendriteMonolith) Start() { base.PublicWellKnownAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) httpRouter := mux.NewRouter().SkipClean(true).UseEncodedPath() diff --git a/build/gobind-yggdrasil/monolith.go b/build/gobind-yggdrasil/monolith.go index cac4512cb..8b9c88f2a 100644 --- a/build/gobind-yggdrasil/monolith.go +++ b/build/gobind-yggdrasil/monolith.go @@ -155,7 +155,6 @@ func (m *DendriteMonolith) Start() { base.PublicWellKnownAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) httpRouter := mux.NewRouter() diff --git a/clientapi/clientapi.go b/clientapi/clientapi.go index 45cc682ea..b1eb391f8 100644 --- a/clientapi/clientapi.go +++ b/clientapi/clientapi.go @@ -36,7 +36,6 @@ import ( func AddPublicRoutes( router *mux.Router, synapseAdminRouter *mux.Router, - consentAPIMux *mux.Router, cfg *config.ClientAPI, accountsDB userdb.Database, federation *gomatrixserverlib.FederationClient, @@ -58,7 +57,7 @@ func AddPublicRoutes( } routing.Setup( - router, synapseAdminRouter, consentAPIMux, cfg, eduInputAPI, rsAPI, asAPI, + router, synapseAdminRouter, cfg, eduInputAPI, rsAPI, asAPI, accountsDB, userAPI, federation, syncProducer, transactionsCache, fsAPI, keyAPI, extRoomsProvider, mscCfg, ) diff --git a/clientapi/routing/consent_tracking.go b/clientapi/routing/consent_tracking.go index 38a011db6..a52f62b39 100644 --- a/clientapi/routing/consent_tracking.go +++ b/clientapi/routing/consent_tracking.go @@ -208,7 +208,7 @@ func buildConsentURI(cfgClient *config.ClientAPI, userID string) (string, error) } userMAC := mac.Sum(nil) - return fmt.Sprintf("%s/_matrix/consent?u=%s&h=%s&v=%s", cfgClient.Matrix.UserConsentOptions.BaseURL, userID, userMAC, consentOpts.Version), nil + return fmt.Sprintf("%s/_matrix/client/consent?u=%s&h=%s&v=%s", cfgClient.Matrix.UserConsentOptions.BaseURL, userID, userMAC, consentOpts.Version), nil } func validHMAC(username, userHMAC, secret string) (bool, error) { diff --git a/clientapi/routing/routing.go b/clientapi/routing/routing.go index 51b75cb60..06243cd4b 100644 --- a/clientapi/routing/routing.go +++ b/clientapi/routing/routing.go @@ -48,7 +48,7 @@ import ( // applied: // nolint: gocyclo func Setup( - publicAPIMux, synapseAdminRouter, consentAPIMux *mux.Router, cfg *config.ClientAPI, + publicAPIMux, synapseAdminRouter *mux.Router, cfg *config.ClientAPI, eduAPI eduServerAPI.EDUServerInputAPI, rsAPI roomserverAPI.RoomserverInternalAPI, asAPI appserviceAPI.AppServiceQueryAPI, @@ -174,7 +174,7 @@ func Setup( // Note that 'apiversion' is chosen because it must not collide with a variable used in any of the routing! v3mux := publicAPIMux.PathPrefix("/{apiversion:(?:r0|v3)}/").Subrouter() - // unspecced consent tracking + // NOTSPEC: consent tracking if cfg.Matrix.UserConsentOptions.Enabled { if !cfg.Matrix.ServerNotices.Enabled { logrus.Warnf("Consent tracking is enabled, but server notes are not. No server notice will be sent to users") @@ -182,7 +182,7 @@ func Setup( // start a new go routine to send messages about consent go sendServerNoticeForConsent(userAPI, rsAPI, &cfg.Matrix.ServerNotices, cfg, serverNotificationSender, accountDB, asAPI) } - consentAPIMux.Handle("/consent", + publicAPIMux.Handle("/consent", httputil.MakeHTMLAPI("consent", func(writer http.ResponseWriter, request *http.Request) *util.JSONResponse { return consent(writer, request, userAPI, cfg) }), diff --git a/cmd/dendrite-demo-libp2p/main.go b/cmd/dendrite-demo-libp2p/main.go index d09f1cb55..78536901c 100644 --- a/cmd/dendrite-demo-libp2p/main.go +++ b/cmd/dendrite-demo-libp2p/main.go @@ -193,7 +193,6 @@ func main() { base.Base.PublicWellKnownAPIMux, base.Base.PublicMediaAPIMux, base.Base.SynapseAdminMux, - base.Base.PublicConsentAPIMux, ) if err := mscs.Enable(&base.Base, &monolith); err != nil { logrus.WithError(err).Fatalf("Failed to enable MSCs") diff --git a/cmd/dendrite-demo-pinecone/main.go b/cmd/dendrite-demo-pinecone/main.go index 18c047445..5810a7f18 100644 --- a/cmd/dendrite-demo-pinecone/main.go +++ b/cmd/dendrite-demo-pinecone/main.go @@ -221,7 +221,6 @@ func main() { base.PublicWellKnownAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) wsUpgrader := websocket.Upgrader{ diff --git a/cmd/dendrite-demo-yggdrasil/main.go b/cmd/dendrite-demo-yggdrasil/main.go index 544105c44..d16f0e9e5 100644 --- a/cmd/dendrite-demo-yggdrasil/main.go +++ b/cmd/dendrite-demo-yggdrasil/main.go @@ -156,7 +156,6 @@ func main() { base.PublicWellKnownAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) if err := mscs.Enable(base, &monolith); err != nil { logrus.WithError(err).Fatalf("Failed to enable MSCs") diff --git a/cmd/dendrite-monolith-server/main.go b/cmd/dendrite-monolith-server/main.go index 7d3e15af0..bb2685208 100644 --- a/cmd/dendrite-monolith-server/main.go +++ b/cmd/dendrite-monolith-server/main.go @@ -165,7 +165,6 @@ func main() { base.PublicWellKnownAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) if len(base.Cfg.MSCs.MSCs) > 0 { diff --git a/cmd/dendrite-polylith-multi/personalities/clientapi.go b/cmd/dendrite-polylith-multi/personalities/clientapi.go index 6c81bd889..bd9f7a109 100644 --- a/cmd/dendrite-polylith-multi/personalities/clientapi.go +++ b/cmd/dendrite-polylith-multi/personalities/clientapi.go @@ -33,7 +33,7 @@ func ClientAPI(base *basepkg.BaseDendrite, cfg *config.Dendrite) { keyAPI := base.KeyServerHTTPClient() clientapi.AddPublicRoutes( - base.PublicClientAPIMux, base.SynapseAdminMux, base.PublicConsentAPIMux, &base.Cfg.ClientAPI, accountDB, federation, + base.PublicClientAPIMux, base.SynapseAdminMux, &base.Cfg.ClientAPI, accountDB, federation, rsAPI, eduInputAPI, asQuery, transactions.New(), fsAPI, userAPI, keyAPI, nil, &cfg.MSCs, ) diff --git a/cmd/dendritejs-pinecone/main.go b/cmd/dendritejs-pinecone/main.go index 3c706a33d..664f644f3 100644 --- a/cmd/dendritejs-pinecone/main.go +++ b/cmd/dendritejs-pinecone/main.go @@ -223,7 +223,6 @@ func startup() { base.PublicWellKnownAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) httpRouter := mux.NewRouter().SkipClean(true).UseEncodedPath() diff --git a/cmd/dendritejs/main.go b/cmd/dendritejs/main.go index 42ce97b15..0ea41b4c4 100644 --- a/cmd/dendritejs/main.go +++ b/cmd/dendritejs/main.go @@ -235,7 +235,6 @@ func main() { base.PublicKeyAPIMux, base.PublicMediaAPIMux, base.SynapseAdminMux, - base.PublicConsentAPIMux, ) httpRouter := mux.NewRouter().SkipClean(true).UseEncodedPath() diff --git a/internal/httputil/httpapi.go b/internal/httputil/httpapi.go index d0fb71f7d..091c36c3b 100644 --- a/internal/httputil/httpapi.go +++ b/internal/httputil/httpapi.go @@ -160,7 +160,7 @@ func getConsentURL(username string, config config.UserConsentOptions) (string, e hmac := hex.EncodeToString(mac.Sum(nil)) return fmt.Sprintf( - "%s/_matrix/consent?u=%s&h=%s&v=%s", + "%s/_matrix/client/consent?u=%s&h=%s&v=%s", config.BaseURL, username, hmac, config.Version, ), nil } diff --git a/setup/base/base.go b/setup/base/base.go index 5b6d1c14b..4ab8769b6 100644 --- a/setup/base/base.go +++ b/setup/base/base.go @@ -73,7 +73,6 @@ type BaseDendrite struct { PublicKeyAPIMux *mux.Router PublicMediaAPIMux *mux.Router PublicWellKnownAPIMux *mux.Router - PublicConsentAPIMux *mux.Router InternalAPIMux *mux.Router SynapseAdminMux *mux.Router UseHTTPAPIs bool @@ -205,7 +204,6 @@ func NewBaseDendrite(cfg *config.Dendrite, componentName string, options ...Base PublicKeyAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicKeyPathPrefix).Subrouter().UseEncodedPath(), PublicMediaAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicMediaPathPrefix).Subrouter().UseEncodedPath(), PublicWellKnownAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.PublicWellKnownPrefix).Subrouter().UseEncodedPath(), - PublicConsentAPIMux: mux.NewRouter().SkipClean(true).PathPrefix("/_matrix").Subrouter().UseEncodedPath(), InternalAPIMux: mux.NewRouter().SkipClean(true).PathPrefix(httputil.InternalPathPrefix).Subrouter().UseEncodedPath(), SynapseAdminMux: mux.NewRouter().SkipClean(true).PathPrefix("/_synapse/").Subrouter().UseEncodedPath(), apiHttpClient: &apiClient, @@ -395,7 +393,6 @@ func (b *BaseDendrite) SetupAndServeHTTP( externalRouter.PathPrefix("/_synapse/").Handler(b.SynapseAdminMux) externalRouter.PathPrefix(httputil.PublicMediaPathPrefix).Handler(b.PublicMediaAPIMux) externalRouter.PathPrefix(httputil.PublicWellKnownPrefix).Handler(b.PublicWellKnownAPIMux) - externalRouter.PathPrefix("/_matrix").Handler(b.PublicConsentAPIMux) if internalAddr != NoListener && internalAddr != externalAddr { go func() { diff --git a/setup/config/config.go b/setup/config/config.go index 8559af23b..33c5fbd4c 100644 --- a/setup/config/config.go +++ b/setup/config/config.go @@ -289,7 +289,7 @@ func (config *Dendrite) Derive() error { // TODO: Add MSISDN auth type if config.Global.UserConsentOptions.Enabled && config.Global.UserConsentOptions.RequireAtRegistration { - uri := config.Global.UserConsentOptions.BaseURL + "/_matrix/consent?v=" + config.Global.UserConsentOptions.Version + uri := config.Global.UserConsentOptions.BaseURL + "/_matrix/client/consent?v=" + config.Global.UserConsentOptions.Version config.Derived.Registration.Params[authtypes.LoginTypeTerms] = Terms{ Policies: Policies{ PrivacyPolicy: PrivacyPolicy{ diff --git a/setup/monolith.go b/setup/monolith.go index d0325ee1e..61125e4a9 100644 --- a/setup/monolith.go +++ b/setup/monolith.go @@ -55,9 +55,9 @@ type Monolith struct { } // AddAllPublicRoutes attaches all public paths to the given router -func (m *Monolith) AddAllPublicRoutes(process *process.ProcessContext, csMux, ssMux, keyMux, wkMux, mediaMux, synapseMux, consentMux *mux.Router) { +func (m *Monolith) AddAllPublicRoutes(process *process.ProcessContext, csMux, ssMux, keyMux, wkMux, mediaMux, synapseMux *mux.Router) { clientapi.AddPublicRoutes( - csMux, synapseMux, consentMux, &m.Config.ClientAPI, m.AccountDB, + csMux, synapseMux, &m.Config.ClientAPI, m.AccountDB, m.FedClient, m.RoomserverAPI, m.EDUInternalAPI, m.AppserviceAPI, transactions.New(), m.FederationAPI, m.UserAPI, m.KeyAPI, m.ExtPublicRoomsProvider,