federation

package
v0.19.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2024 License: MPL-2.0 Imports: 13 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GetQueryKeysResponse

type GetQueryKeysResponse struct {
	ServerKeys []*ServerKeyResponse `json:"server_keys"`
}

GetQueryKeysResponse is the response body for the `GET /_matrix/key/v2/query/{serverName}` endpoint

type KeyServer

type KeyServer struct {
	KeyProvider     ServerKeyProvider
	Version         ServerVersion
	WellKnownTarget string
}

KeyServer implements a basic Matrix key server that can serve its own keys, plus the federation version endpoint.

It does not implement querying keys of other servers, nor any other federation endpoints.

func (*KeyServer) GetQueryKeys

func (ks *KeyServer) GetQueryKeys(w http.ResponseWriter, r *http.Request)

GetQueryKeys implements the `GET /_matrix/key/v2/query/{serverName}` endpoint

https://spec.matrix.org/v1.9/server-server-api/#get_matrixkeyv2queryservername

func (*KeyServer) GetServerKey

func (ks *KeyServer) GetServerKey(w http.ResponseWriter, r *http.Request)

GetServerKey implements the `GET /_matrix/key/v2/server` endpoint.

https://spec.matrix.org/v1.9/server-server-api/#get_matrixkeyv2server

func (*KeyServer) GetServerVersion

func (ks *KeyServer) GetServerVersion(w http.ResponseWriter, r *http.Request)

GetServerVersion implements the `GET /_matrix/federation/v1/version` endpoint

https://spec.matrix.org/v1.9/server-server-api/#get_matrixfederationv1version

func (*KeyServer) GetWellKnown

func (ks *KeyServer) GetWellKnown(w http.ResponseWriter, r *http.Request)

GetWellKnown implements the `GET /.well-known/matrix/server` endpoint

https://spec.matrix.org/v1.9/server-server-api/#get_well-knownmatrixserver

func (*KeyServer) PostQueryKeys

func (ks *KeyServer) PostQueryKeys(w http.ResponseWriter, r *http.Request)

PostQueryKeys implements the `POST /_matrix/key/v2/query` endpoint

https://spec.matrix.org/v1.9/server-server-api/#post_matrixkeyv2query

func (*KeyServer) Register

func (ks *KeyServer) Register(r *mux.Router)

Register registers the key server endpoints to the given router.

type OldVerifyKey

type OldVerifyKey struct {
	Key       id.SigningKey      `json:"key"`
	ExpiredTS jsontime.UnixMilli `json:"expired_ts"`
}

type PostQueryKeysResponse

type PostQueryKeysResponse struct {
	ServerKeys map[string]*ServerKeyResponse `json:"server_keys"`
}

PostQueryKeysResponse is the response body for the `POST /_matrix/key/v2/query` endpoint

type QueryKeysCriteria

type QueryKeysCriteria struct {
	MinimumValidUntilTS jsontime.UnixMilli `json:"minimum_valid_until_ts"`
}

type ReqQueryKeys

type ReqQueryKeys struct {
	ServerKeys map[string]map[id.KeyID]QueryKeysCriteria `json:"server_keys"`
}

ReqQueryKeys is the request body for the `POST /_matrix/key/v2/query` endpoint

type RespServerVersion

type RespServerVersion struct {
	Server ServerVersion `json:"server"`
}

RespServerVersion is the response body for the `GET /_matrix/federation/v1/version` endpoint

type RespWellKnown

type RespWellKnown struct {
	Server string `json:"m.server"`
}

RespWellKnown is the response body for the `GET /.well-known/matrix/server` endpoint.

type ServerKeyProvider

type ServerKeyProvider interface {
	Get(r *http.Request) (serverName string, key *SigningKey)
}

ServerKeyProvider is an interface that returns private server keys for server key requests.

type ServerKeyResponse

type ServerKeyResponse struct {
	ServerName    string                         `json:"server_name"`
	VerifyKeys    map[id.KeyID]ServerVerifyKey   `json:"verify_keys"`
	OldVerifyKeys map[id.KeyID]OldVerifyKey      `json:"old_verify_keys,omitempty"`
	Signatures    map[string]map[id.KeyID]string `json:"signatures,omitempty"`
	ValidUntilTS  jsontime.UnixMilli             `json:"valid_until_ts"`
}

ServerKeyResponse is the response body for the `GET /_matrix/key/v2/server` endpoint. It's also used inside the query endpoint response structs.

type ServerVerifyKey

type ServerVerifyKey struct {
	Key id.SigningKey `json:"key"`
}

type ServerVersion

type ServerVersion struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

type SigningKey

type SigningKey struct {
	ID   id.KeyID
	Pub  id.SigningKey
	Priv ed25519.PrivateKey
}

SigningKey is a Matrix federation signing key pair.

func GenerateSigningKey

func GenerateSigningKey() *SigningKey

GenerateSigningKey generates a new random signing key.

func ParseSynapseKey

func ParseSynapseKey(key string) (*SigningKey, error)

ParseSynapseKey parses a Synapse-compatible private key string into a SigningKey.

func (*SigningKey) GenerateKeyResponse

func (sk *SigningKey) GenerateKeyResponse(serverName string, oldVerifyKeys map[id.KeyID]OldVerifyKey) *ServerKeyResponse

GenerateKeyResponse generates a key response signed by this key with the given server name and optionally some old verify keys.

func (*SigningKey) SignJSON

func (sk *SigningKey) SignJSON(data any) ([]byte, error)

func (*SigningKey) SignRawJSON

func (sk *SigningKey) SignRawJSON(data json.RawMessage) []byte

func (*SigningKey) SynapseString

func (sk *SigningKey) SynapseString() string

SynapseString returns a string representation of the private key compatible with Synapse's .signing.key file format.

The output of this function can be parsed back into a SigningKey using the ParseSynapseKey function.

type StaticServerKey

type StaticServerKey struct {
	ServerName string
	Key        *SigningKey
}

StaticServerKey is an implementation of ServerKeyProvider that always returns the same server name and key.

func (*StaticServerKey) Get

func (ssk *StaticServerKey) Get(r *http.Request) (serverName string, key *SigningKey)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL