aboutsummaryrefslogtreecommitdiff
path: root/internal/config/config_serverkey.go
blob: 788a2fa0560841bbc8169566347d45dc6aad4bf8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package config

import "github.com/matrix-org/gomatrixserverlib"

type ServerKeyAPI struct {
	Matrix *Global `yaml:"-"`

	InternalAPI InternalAPIOptions `yaml:"internal_api"`

	// The ServerKey database caches the public keys of remote servers.
	// It may be accessed by the FederationAPI, the ClientAPI, and the MediaAPI.
	Database DatabaseOptions `yaml:"database"`

	// Perspective keyservers, to use as a backup when direct key fetch
	// requests don't succeed
	KeyPerspectives KeyPerspectives `yaml:"key_perspectives"`

	// Should we prefer direct key fetches over perspective ones?
	PreferDirectFetch bool `yaml:"prefer_direct_fetch"`
}

func (c *ServerKeyAPI) Defaults() {
	c.InternalAPI.Listen = "http://localhost:7780"
	c.InternalAPI.Connect = "http://localhost:7780"
	c.Database.Defaults()
	c.Database.ConnectionString = "file:serverkeyapi.db"
}

func (c *ServerKeyAPI) Verify(configErrs *ConfigErrors, isMonolith bool) {
	checkURL(configErrs, "server_key_api.internal_api.listen", string(c.InternalAPI.Listen))
	checkURL(configErrs, "server_key_api.internal_api.bind", string(c.InternalAPI.Connect))
	checkNotEmpty(configErrs, "server_key_api.database.connection_string", string(c.Database.ConnectionString))
}

// KeyPerspectives are used to configure perspective key servers for
// retrieving server keys.
type KeyPerspectives []KeyPerspective

type KeyPerspective struct {
	// The server name of the perspective key server
	ServerName gomatrixserverlib.ServerName `yaml:"server_name"`
	// Server keys for the perspective user, used to verify the
	// keys have been signed by the perspective server
	Keys []KeyPerspectiveTrustKey `yaml:"keys"`
}

type KeyPerspectiveTrustKey struct {
	// The key ID, e.g. ed25519:auto
	KeyID gomatrixserverlib.KeyID `yaml:"key_id"`
	// The public key in base64 unpadded format
	PublicKey string `yaml:"public_key"`
}