Skip to content

Commit fee5cf2

Browse files
committed
Only decode server trust root once
1 parent 84601c5 commit fee5cf2

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
1515
github.com/stretchr/testify v1.8.4
1616
github.com/tidwall/gjson v1.17.0
17-
go.mau.fi/util v0.2.2-0.20231229201527-e01ca03301e9
17+
go.mau.fi/util v0.2.2-0.20240107131103-852f29430a02
1818
golang.org/x/crypto v0.17.0
1919
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
2020
golang.org/x/net v0.19.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
6565
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
6666
github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68=
6767
github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
68-
go.mau.fi/util v0.2.2-0.20231229201527-e01ca03301e9 h1:sYi2qn5XYnWyHjzBj04/ZeyqMMK31qPM1l2v7aWeiA0=
69-
go.mau.fi/util v0.2.2-0.20231229201527-e01ca03301e9/go.mod h1:9dGsBCCbZJstx16YgnVMVi3O2bOizELoKpugLD4FoGs=
68+
go.mau.fi/util v0.2.2-0.20240107131103-852f29430a02 h1:jREUBe6TF4a2HCGowTLzcvOFg44QDZ0xgoo+YJK3ugc=
69+
go.mau.fi/util v0.2.2-0.20240107131103-852f29430a02/go.mod h1:9dGsBCCbZJstx16YgnVMVi3O2bOizELoKpugLD4FoGs=
7070
go.mau.fi/zeroconfig v0.1.2 h1:DKOydWnhPMn65GbXZOafgkPm11BvFashZWLct0dGFto=
7171
go.mau.fi/zeroconfig v0.1.2/go.mod h1:NcSJkf180JT+1IId76PcMuLTNa1CzsFFZ0nBygIQM70=
7272
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=

pkg/signalmeow/receiving.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"github.com/google/uuid"
2828
"github.com/rs/zerolog"
29+
"go.mau.fi/util/exerrors"
2930
"google.golang.org/protobuf/proto"
3031
"google.golang.org/protobuf/reflect/protoreflect"
3132

@@ -860,18 +861,14 @@ type DecryptionResult struct {
860861
SealedSender bool
861862
}
862863

863-
func serverTrustRootKey() *libsignalgo.PublicKey {
864-
// TODO: put this server's trust root in the config or DB or something
865-
serverTrustRoot := "BXu6QIKVz5MA8gstzfOgRQGqyLqOwNKHL6INkv3IHWMF"
866-
serverTrustRootBytes, err := base64.StdEncoding.DecodeString(serverTrustRoot)
867-
if err != nil {
868-
panic(fmt.Errorf("DecodeString error: %w", err))
869-
}
870-
serverTrustRootKey, err := libsignalgo.DeserializePublicKey(serverTrustRootBytes)
871-
if err != nil {
872-
panic(fmt.Errorf("DeserializePublicKey error: %w", err))
873-
}
874-
return serverTrustRootKey
864+
const prodServerTrustRootStr = "BXu6QIKVz5MA8gstzfOgRQGqyLqOwNKHL6INkv3IHWMF"
865+
866+
var prodServerTrustRootBytes = exerrors.Must(base64.StdEncoding.DecodeString(prodServerTrustRootStr))
867+
var prodServerTrustRootKey = exerrors.Must(libsignalgo.DeserializePublicKey(prodServerTrustRootBytes))
868+
869+
func init() {
870+
// It's never going to be freed anyway
871+
prodServerTrustRootKey.CancelFinalizer()
875872
}
876873

877874
func (cli *Client) sealedSenderDecrypt(ctx context.Context, envelope *signalpb.Envelope) (*DecryptionResult, error) {
@@ -885,7 +882,7 @@ func (cli *Client) sealedSenderDecrypt(ctx context.Context, envelope *signalpb.E
885882
ctx,
886883
envelope.Content,
887884
localAddress,
888-
serverTrustRootKey(),
885+
prodServerTrustRootKey,
889886
timestamp,
890887
cli.Store.SessionStore,
891888
cli.Store.IdentityStore,

0 commit comments

Comments
 (0)