Skip to content

Commit 4977c5e

Browse files
committed
chore: remove RekeyCompatibility
It is safe to remove now. It improves how community encryption keys are distributed.
1 parent 5825d1c commit 4977c5e

File tree

3 files changed

+4
-144
lines changed

3 files changed

+4
-144
lines changed

messaging/api.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717

1818
"github.com/status-im/status-go/connection"
1919
"github.com/status-im/status-go/messaging/adapters"
20-
"github.com/status-im/status-go/messaging/common"
2120
"github.com/status-im/status-go/messaging/layers/encryption"
2221
"github.com/status-im/status-go/messaging/layers/transport"
2322
"github.com/status-im/status-go/messaging/types"
@@ -469,10 +468,6 @@ func CommunityShardInfoTopicPrefix() string {
469468
return transport.CommunityShardInfoTopicPrefix()
470469
}
471470

472-
func SetRekeyCompatibility(compatibility bool) {
473-
common.RekeyCompatibility = compatibility
474-
}
475-
476471
func GenerateInstallationID() string {
477472
return uuid.New().String()
478473
}

messaging/common/message_sender.go

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ const (
3737
maxMessageSenderEphemeralKeys = 3
3838
)
3939

40-
// RekeyCompatibility indicates whether we should be sending
41-
// keys in 1-to-1 messages as well as in the newer format
42-
var RekeyCompatibility = true
43-
4440
type MessageSender struct {
4541
identity *ecdsa.PrivateKey
4642
transport *transport.Transport
@@ -299,10 +295,8 @@ func (s *MessageSender) sendCommunity(
299295
// Check if it's a key exchange message. In this case we send it
300296
// to all the recipients
301297
if rawMessage.CommunityKeyExMsgType != messagingtypes.KeyExMsgNone {
302-
// If rekeycompatibility is on, we always
303-
// want to execute below, otherwise we execute
304-
// only when we want to fill up old keys to a given user
305-
if RekeyCompatibility || !forceRekey {
298+
// we want to fill up old keys to a given user
299+
if !forceRekey {
306300
keyExMessageSpecs, err := s.protocol.GetKeyExMessageSpecs(rawMessage.HashRatchetGroupID, s.identity, rawMessage.Recipients, forceRekey)
307301
if err != nil {
308302
return nil, err
@@ -526,18 +520,8 @@ func (s *MessageSender) dispatchCommunityChatMessage(ctx context.Context, rawMes
526520
payload := wrappedMessage
527521
var err error
528522
if rekey && len(rawMessage.HashRatchetGroupID) != 0 {
529-
530-
var ratchet *encryption.HashRatchetKeyCompatibility
531-
// We have just rekeyed, pull the latest
532-
if RekeyCompatibility {
533-
ratchet, err = s.protocol.GetCurrentKeyForGroup(rawMessage.HashRatchetGroupID)
534-
if err != nil {
535-
return nil, nil, err
536-
}
537-
538-
}
539523
// We send the message over the community topic
540-
spec, err := s.protocol.BuildHashRatchetReKeyGroupMessage(s.identity, rawMessage.Recipients, rawMessage.HashRatchetGroupID, wrappedMessage, ratchet)
524+
spec, err := s.protocol.BuildHashRatchetReKeyGroupMessage(s.identity, rawMessage.Recipients, rawMessage.HashRatchetGroupID, wrappedMessage, nil)
541525
if err != nil {
542526
return nil, nil, err
543527
}
@@ -969,24 +953,8 @@ func (s *MessageSender) sendPrivateRawMessage(ctx context.Context, rawMessage *m
969953
func (s *MessageSender) dispatchCommunityMessage(ctx context.Context, publicKey *ecdsa.PublicKey, wrappedMessage []byte, pubsubTopic string, rekey bool, rawMessage *messagingtypes.RawMessage) ([][]byte, []*wakutypes.NewMessage, error) {
970954
payload := wrappedMessage
971955
if rekey && len(rawMessage.HashRatchetGroupID) != 0 {
972-
973-
var ratchet *encryption.HashRatchetKeyCompatibility
974-
var err error
975-
// We have just rekeyed, pull the latest
976-
if RekeyCompatibility {
977-
ratchet, err = s.protocol.GetCurrentKeyForGroup(rawMessage.HashRatchetGroupID)
978-
if err != nil {
979-
return nil, nil, err
980-
}
981-
982-
}
983-
keyID, err := ratchet.GetKeyID()
984-
if err != nil {
985-
return nil, nil, err
986-
}
987-
s.logger.Debug("adding key id to message", zap.String("keyid", cryptotypes.Bytes2Hex(keyID)))
988956
// We send the message over the community topic
989-
spec, err := s.protocol.BuildHashRatchetReKeyGroupMessage(s.identity, rawMessage.Recipients, rawMessage.HashRatchetGroupID, wrappedMessage, ratchet)
957+
spec, err := s.protocol.BuildHashRatchetReKeyGroupMessage(s.identity, rawMessage.Recipients, rawMessage.HashRatchetGroupID, wrappedMessage, nil)
990958
if err != nil {
991959
return nil, nil, err
992960
}

protocol/communities_messenger_test.go

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,109 +3880,6 @@ func (s *MessengerCommunitiesSuite) TestCommunityRekeyAfterBan() {
38803880
s.Require().NoError(err)
38813881
}
38823882

3883-
func (s *MessengerCommunitiesSuite) TestCommunityRekeyAfterBanDisableCompatibility() {
3884-
messaging.SetRekeyCompatibility(false)
3885-
s.owner.communitiesManager.RekeyInterval = 500 * time.Minute
3886-
3887-
// Create a new community
3888-
response, err := s.owner.CreateCommunity(
3889-
&requests.CreateCommunity{
3890-
Membership: protobuf.CommunityPermissions_AUTO_ACCEPT,
3891-
Name: "status",
3892-
Color: "#57a7e5",
3893-
Description: "status community description",
3894-
},
3895-
true,
3896-
)
3897-
s.Require().NoError(err)
3898-
s.Require().NotNil(response)
3899-
s.Require().Len(response.Communities(), 1)
3900-
3901-
// Check community is present in the DB and has default values we care about
3902-
c, err := s.owner.GetCommunityByID(response.Communities()[0].ID())
3903-
s.Require().NoError(err)
3904-
s.Require().False(c.Encrypted())
3905-
// TODO some check that there are no keys for the community. Alt for s.Require().Zero(c.RekeyedAt().Unix())
3906-
3907-
_, err = s.owner.CreateCommunityTokenPermission(&requests.CreateCommunityTokenPermission{
3908-
CommunityID: c.ID(),
3909-
Type: protobuf.CommunityTokenPermission_BECOME_MEMBER,
3910-
TokenCriteria: []*protobuf.TokenCriteria{{
3911-
ContractAddresses: map[uint64]string{3: "0x933"},
3912-
Type: protobuf.CommunityTokenType_ERC20,
3913-
Symbol: "STT",
3914-
Name: "Status Test Token",
3915-
AmountInWei: "10000000000000000000",
3916-
Decimals: 18,
3917-
}},
3918-
})
3919-
s.Require().NoError(err)
3920-
3921-
c, err = s.owner.GetCommunityByID(c.ID())
3922-
s.Require().NoError(err)
3923-
s.Require().True(c.Encrypted())
3924-
3925-
s.advertiseCommunityTo(c, s.owner, s.bob)
3926-
s.advertiseCommunityTo(c, s.owner, s.alice)
3927-
3928-
s.mockPermissionCheckerForAllMessenger()
3929-
3930-
s.joinCommunity(c, s.owner, s.bob)
3931-
s.joinCommunity(c, s.owner, s.alice)
3932-
3933-
// Check the Alice and Bob are members of the community
3934-
c, err = s.owner.GetCommunityByID(c.ID())
3935-
s.Require().NoError(err)
3936-
s.Require().True(c.HasMember(&s.alice.identity.PublicKey))
3937-
s.Require().True(c.HasMember(&s.bob.identity.PublicKey))
3938-
3939-
// Make sure at least one key makes it to alice
3940-
response, err = WaitOnMessengerResponse(s.alice,
3941-
func(r *MessengerResponse) bool {
3942-
keysCount, err := messaging.TestUtils{API: s.alice.messaging}.GetKeysForGroupCount(response.Communities()[0].ID())
3943-
if err != nil || keysCount != 1 {
3944-
return false
3945-
}
3946-
return true
3947-
3948-
},
3949-
"alice does not have enough keys",
3950-
)
3951-
s.Require().NoError(err)
3952-
3953-
response, err = s.owner.BanUserFromCommunity(context.Background(), &requests.BanUserFromCommunity{
3954-
CommunityID: c.ID(),
3955-
User: crypto.PubkeyToHexBytes(&s.bob.identity.PublicKey),
3956-
})
3957-
s.Require().NoError(err)
3958-
s.Require().Len(response.Communities(), 1)
3959-
3960-
s.Require().False(response.Communities()[0].HasMember(&s.bob.identity.PublicKey))
3961-
3962-
// Check bob has been banned
3963-
response, err = WaitOnMessengerResponse(s.alice,
3964-
func(r *MessengerResponse) bool {
3965-
return len(r.Communities()) == 1 && !r.Communities()[0].HasMember(&s.bob.identity.PublicKey)
3966-
3967-
},
3968-
"alice didn't receive updated description",
3969-
)
3970-
s.Require().NoError(err)
3971-
3972-
response, err = WaitOnMessengerResponse(s.alice,
3973-
func(r *MessengerResponse) bool {
3974-
keysCount, err := messaging.TestUtils{API: s.alice.messaging}.GetKeysForGroupCount(response.Communities()[0].ID())
3975-
if err != nil || keysCount < 2 {
3976-
return false
3977-
}
3978-
return true
3979-
3980-
},
3981-
"alice hasn't received updated key",
3982-
)
3983-
s.Require().NoError(err)
3984-
}
3985-
39863883
func (s *MessengerCommunitiesSuite) TestRetrieveBigCommunity() {
39873884
bigEmoji := make([]byte, 4*1024*1024) // 4 MB
39883885
description := &requests.CreateCommunity{

0 commit comments

Comments
 (0)