package roomserver import ( "context" "fmt" "github.com/dariuszjaniak/warp/server/internal/matrix/event" "github.com/dariuszjaniak/warp/server/internal/matrix/signing" ) // localVerifier checks an event's signature against this server's own key. // // One authorisation rule needs somebody else's signature verified: a join // under the restricted join rule is authorised by a third party named in // content.join_authorised_via_users_server, and the event must carry a // signature from *that user's* server. While federation is off the only // such server that can appear is this one, and its key is already in hand — // so the rule can be applied in full, locally, without a key fetcher. // // Phase 5 replaces this with a verifier that can fetch and cache another // server's keys. Until then a join authorised via a remote user is refused // rather than waved through, which is the same answer the federation switch // gives everywhere else. type localVerifier struct { serverName string key *signing.KeyPair } // verifier returns the Verifier the authorisation rules are given. func (r *API) verifier() *localVerifier { return &localVerifier{serverName: r.serverName, key: r.signingKey} } // VerifyEventSignature implements auth.Verifier. func (v *localVerifier) VerifyEventSignature(_ context.Context, serverName string, e *event.Event) error { if serverName != v.serverName { return fmt.Errorf("%w: cannot verify a signature from %s", ErrFederationDisabled, serverName) } return e.VerifySignature(v.serverName, v.key.KeyID(), v.key.Public) }