diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-11-18 13:24:02 +0000 |
---|---|---|
committer | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-11-18 13:24:02 +0000 |
commit | 8299da590542a982437ad9dd30115d23c3d9d075 (patch) | |
tree | e24ba6d33e4f551252150d42bcb43e1587e0aaec /setup | |
parent | a8e7ffc7ab147ebced766da8e0e1ebb1d75f846a (diff) |
Fix registration for virtual hosting
Diffstat (limited to 'setup')
-rw-r--r-- | setup/config/config.go | 2 | ||||
-rw-r--r-- | setup/config/config_global.go | 72 |
2 files changed, 43 insertions, 31 deletions
diff --git a/setup/config/config.go b/setup/config/config.go index 918bcbe3..7e7ed1aa 100644 --- a/setup/config/config.go +++ b/setup/config/config.go @@ -235,7 +235,7 @@ func loadConfig( if v.KeyValidityPeriod == 0 { v.KeyValidityPeriod = c.Global.KeyValidityPeriod } - if v.PrivateKeyPath == "" { + if v.PrivateKeyPath == "" || v.PrivateKey == nil || v.KeyID == "" { v.KeyID = c.Global.KeyID v.PrivateKey = c.Global.PrivateKey continue diff --git a/setup/config/config_global.go b/setup/config/config_global.go index 722230d9..801c6845 100644 --- a/setup/config/config_global.go +++ b/setup/config/config_global.go @@ -12,8 +12,9 @@ import ( ) type Global struct { - // The name of the server. This is usually the domain name, e.g 'matrix.org', 'localhost'. - ServerName gomatrixserverlib.ServerName `yaml:"server_name"` + // Signing identity contains the server name, private key and key ID of + // the deployment. + gomatrixserverlib.SigningIdentity `yaml:",inline"` // The secondary server names, used for virtual hosting. VirtualHosts []*VirtualHost `yaml:"virtual_hosts"` @@ -21,13 +22,6 @@ type Global struct { // Path to the private key which will be used to sign requests and events. PrivateKeyPath Path `yaml:"private_key"` - // The private key which will be used to sign requests and events. - PrivateKey ed25519.PrivateKey `yaml:"-"` - - // An arbitrary string used to uniquely identify the PrivateKey. Must start with the - // prefix "ed25519:". - KeyID gomatrixserverlib.KeyID `yaml:"-"` - // Information about old private keys that used to be used to sign requests and // events on this domain. They will not be used but will be advertised to other // servers that ask for them to help verify old events. @@ -151,6 +145,29 @@ func (c *Global) SplitLocalID(sigil byte, id string) (string, gomatrixserverlib. return u, s, nil } +func (c *Global) VirtualHost(serverName gomatrixserverlib.ServerName) *VirtualHost { + for _, v := range c.VirtualHosts { + if v.ServerName == serverName { + return v + } + } + return nil +} + +func (c *Global) VirtualHostForHTTPHost(serverName gomatrixserverlib.ServerName) *VirtualHost { + for _, v := range c.VirtualHosts { + if v.ServerName == serverName { + return v + } + for _, h := range v.MatchHTTPHosts { + if h == serverName { + return v + } + } + } + return nil +} + func (c *Global) SigningIdentityFor(serverName gomatrixserverlib.ServerName) (*gomatrixserverlib.SigningIdentity, error) { for _, id := range c.SigningIdentities() { if id.ServerName == serverName { @@ -162,32 +179,22 @@ func (c *Global) SigningIdentityFor(serverName gomatrixserverlib.ServerName) (*g func (c *Global) SigningIdentities() []*gomatrixserverlib.SigningIdentity { identities := make([]*gomatrixserverlib.SigningIdentity, 0, len(c.VirtualHosts)+1) - identities = append(identities, &gomatrixserverlib.SigningIdentity{ - ServerName: c.ServerName, - KeyID: c.KeyID, - PrivateKey: c.PrivateKey, - }) + identities = append(identities, &c.SigningIdentity) for _, v := range c.VirtualHosts { - identities = append(identities, v.SigningIdentity()) + identities = append(identities, &v.SigningIdentity) } return identities } type VirtualHost struct { - // The server name of the virtual host. - ServerName gomatrixserverlib.ServerName `yaml:"server_name"` - - // The key ID of the private key. If not specified, the default global key ID - // will be used instead. - KeyID gomatrixserverlib.KeyID `yaml:"key_id"` + // Signing identity contains the server name, private key and key ID of + // the virtual host. + gomatrixserverlib.SigningIdentity `yaml:",inline"` // Path to the private key. If not specified, the default global private key // will be used instead. PrivateKeyPath Path `yaml:"private_key"` - // The private key itself. - PrivateKey ed25519.PrivateKey `yaml:"-"` - // How long a remote server can cache our server key for before requesting it again. // Increasing this number will reduce the number of requests made by remote servers // for our key, but increases the period a compromised key will be considered valid @@ -201,19 +208,24 @@ type VirtualHost struct { MatchHTTPHosts []gomatrixserverlib.ServerName `yaml:"match_http_hosts"` // Is registration enabled on this virtual host? - AllowRegistration bool `json:"allow_registration"` + AllowRegistration bool `yaml:"allow_registration"` + + // Is guest registration enabled on this virtual host? + AllowGuests bool `yaml:"allow_guests"` } func (v *VirtualHost) Verify(configErrs *ConfigErrors) { checkNotEmpty(configErrs, "virtual_host.*.server_name", string(v.ServerName)) } -func (v *VirtualHost) SigningIdentity() *gomatrixserverlib.SigningIdentity { - return &gomatrixserverlib.SigningIdentity{ - ServerName: v.ServerName, - KeyID: v.KeyID, - PrivateKey: v.PrivateKey, +// RegistrationAllowed returns two bools, the first states whether registration +// is allowed for this virtual host and the second states whether guests are +// allowed for this virtual host. +func (v *VirtualHost) RegistrationAllowed() (bool, bool) { + if v == nil { + return false, false } + return v.AllowRegistration, v.AllowGuests } type OldVerifyKeys struct { |