-
-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathmatrix_crypto.go
61 lines (49 loc) · 1.28 KB
/
matrix_crypto.go
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
53
54
55
56
57
58
59
60
61
//go:build e2ee
// +build e2ee
package main
import (
"context"
_ "github.com/mattn/go-sqlite3"
"maunium.net/go/mautrix/crypto/cryptohelper"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
)
type Crypto struct {
helper *cryptohelper.CryptoHelper
}
func BuildTagsE2EE() {
buildTags = append(buildTags, "e2ee")
}
func MatrixE2EE() bool { return true }
func InitMatrixCrypto(d *MatrixDaemon) error {
d.Encryption = d.app.config.Section("matrix").Key("encryption").MustBool(false)
if !d.Encryption {
// return fmt.Errorf("encryption disabled")
return nil
}
dbPath := d.app.config.Section("files").Key("matrix_sql").String()
var err error
d.crypto = &Crypto{}
d.crypto.helper, err = cryptohelper.NewCryptoHelper(d.bot, []byte("jfa-go"), dbPath)
if err != nil {
return err
}
err = d.crypto.helper.Init(context.TODO())
if err != nil {
return err
}
d.bot.Crypto = d.crypto.helper
d.Encryption = true
return nil
}
func EncryptRoom(d *MatrixDaemon, roomID id.RoomID) error {
if !d.Encryption {
return nil
}
_, err := d.bot.SendStateEvent(context.TODO(), roomID, event.StateEncryption, "", event.EncryptionEventContent{
Algorithm: id.AlgorithmMegolmV1,
RotationPeriodMillis: 7 * 24 * 60 * 60 * 1000,
RotationPeriodMessages: 100,
})
return err
}