encryption: add ability to control rotation settings

Signed-off-by: Sumner Evans <sumner@beeper.com>
This commit is contained in:
Sumner Evans
2022-06-22 07:56:13 -06:00
parent 303a6eb5fb
commit 66c39bc69d
5 changed files with 33 additions and 4 deletions

View File

@@ -47,6 +47,9 @@ func DoUpgrade(helper *up.Helper) {
helper.Copy(up.Bool, "bridge", "encryption", "key_sharing", "allow")
helper.Copy(up.Bool, "bridge", "encryption", "key_sharing", "require_cross_signing")
helper.Copy(up.Bool, "bridge", "encryption", "key_sharing", "require_verification")
helper.Copy(up.Bool, "bridge", "encryption", "rotation", "enable_custom")
helper.Copy(up.Int, "bridge", "encryption", "rotation", "milliseconds")
helper.Copy(up.Int, "bridge", "encryption", "rotation", "messages")
helper.Copy(up.Str, "bridge", "provisioning", "prefix")
if secret, ok := helper.Get(up.Str, "bridge", "provisioning", "shared_secret"); !ok || secret == "generate" {

View File

@@ -143,6 +143,23 @@ bridge:
# Require devices to be verified by the bridge?
# Verification by the bridge is not yet implemented.
require_verification: true
# Options for Megolm room key rotation. These options allow you to
# configure the m.room.encryption event content. See:
# https://spec.matrix.org/v1.3/client-server-api/#mroomencryption for
# more information about that event.
rotation:
# Enable custom Megolm room key rotation settings. Note that these
# settings will only apply to rooms created after this option is
# set.
enable_custom: false
# The maximum number of milliseconds a session should be used
# before changing it. The Matrix spec recommends 604800000 (a week)
# as the default.
milliseconds: 604800000
# The maximum number of messages that should be sent with a given a
# session before changing it. The Matrix spec recommends 100 as the
# default.
messages: 100
# Settings for provisioning API
provisioning:

2
go.mod
View File

@@ -11,7 +11,7 @@ require (
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/yuin/goldmark v1.4.12
maunium.net/go/maulogger/v2 v2.3.2
maunium.net/go/mautrix v0.11.1-0.20220531091243-d75452b1e36b
maunium.net/go/mautrix v0.11.1-0.20220621174128-b64dc2427d45
)
require (

4
go.sum
View File

@@ -58,5 +58,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/maulogger/v2 v2.3.2 h1:1XmIYmMd3PoQfp9J+PaHhpt80zpfmMqaShzUTC7FwY0=
maunium.net/go/maulogger/v2 v2.3.2/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
maunium.net/go/mautrix v0.11.1-0.20220531091243-d75452b1e36b h1:Ta+etLMqLdckOHtR087/2Y6uYTlz5EXfH8cIBDsHAys=
maunium.net/go/mautrix v0.11.1-0.20220531091243-d75452b1e36b/go.mod h1:CiKpMhAx5QZFHK03jpWb0iKI3sGU8x6+LfsOjDrcO8I=
maunium.net/go/mautrix v0.11.1-0.20220621174128-b64dc2427d45 h1:3ld9X4COzaeGrfAAUYD5f4is0siPGzodTFtX/+o8Q50=
maunium.net/go/mautrix v0.11.1-0.20220621174128-b64dc2427d45/go.mod h1:CiKpMhAx5QZFHK03jpWb0iKI3sGU8x6+LfsOjDrcO8I=

View File

@@ -278,6 +278,15 @@ func (portal *Portal) UpdateBridgeInfo() {
}
}
func (portal *Portal) GetEncryptionEventContent() (evt *event.EncryptionEventContent) {
evt = &event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1}
if rot := portal.bridge.Config.Bridge.Encryption.Rotation; rot.EnableCustom {
evt.RotationPeriodMillis = rot.Milliseconds
evt.RotationPeriodMessages = rot.Messages
}
return
}
func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) error {
portal.roomCreateLock.Lock()
defer portal.roomCreateLock.Unlock()
@@ -356,7 +365,7 @@ func (portal *Portal) CreateMatrixRoom(user *User, channel *discordgo.Channel) e
initialState = append(initialState, &event.Event{
Type: event.StateEncryption,
Content: event.Content{
Parsed: event.EncryptionEventContent{Algorithm: id.AlgorithmMegolmV1},
Parsed: portal.GetEncryptionEventContent(),
},
})
portal.Encrypted = true