Skip to content

Commit

Permalink
Rename topic -> sharedsecret
Browse files Browse the repository at this point in the history
  • Loading branch information
cammellos committed May 31, 2019
1 parent 15ee4e1 commit e432061
Show file tree
Hide file tree
Showing 16 changed files with 120 additions and 121 deletions.
1 change: 0 additions & 1 deletion services/shhext/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ func (api *PublicAPI) SendDirectMessage(ctx context.Context, msg chat.SendDirect

// This is transport layer-agnostic
var protocolMessage *protobuf.ProtocolMessage
// The negotiated secret
var msgSpec *chat.ProtocolMessageSpec
var partitionedTopicSupported bool
var topic []byte
Expand Down
60 changes: 30 additions & 30 deletions services/shhext/chat/db/migrations/bindata.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions services/shhext/chat/encryption_multi_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"

"github.com/status-im/status-go/services/shhext/chat/multidevice"
"github.com/status-im/status-go/services/shhext/chat/topic"
"github.com/status-im/status-go/services/shhext/chat/sharedsecret"
)

const (
Expand Down Expand Up @@ -53,24 +53,24 @@ func setupUser(user string, s *EncryptionServiceMultiDeviceSuite, n int) error {
if err != nil {
return err
}
// Initialize topics
// Initialize sharedsecret
multideviceConfig := &multidevice.Config{
MaxInstallations: n - 1,
InstallationID: installationID,
ProtocolVersion: 1,
}

topicService := topic.NewService(persistence.GetTopicStorage())
sharedSecretService := sharedsecret.NewService(persistence.GetSharedSecretStorage())
multideviceService := multidevice.New(multideviceConfig, persistence.GetMultideviceStorage())

protocol := NewProtocolService(
NewEncryptionService(
persistence,
DefaultEncryptionServiceConfig(installationID)),
topicService,
sharedSecretService,
multideviceService,
func(s []multidevice.IdentityAndIDPair) {},
func(s []*topic.Secret) {},
func(s []*sharedsecret.Secret) {},
)

s.services[user].services[i] = protocol
Expand Down
14 changes: 7 additions & 7 deletions services/shhext/chat/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/status-im/status-go/services/shhext/chat/multidevice"
"github.com/status-im/status-go/services/shhext/chat/protobuf"
"github.com/status-im/status-go/services/shhext/chat/topic"
"github.com/status-im/status-go/services/shhext/chat/sharedsecret"
"github.com/stretchr/testify/suite"
)

Expand Down Expand Up @@ -73,15 +73,15 @@ func (s *EncryptionServiceTestSuite) initDatabases(baseConfig *EncryptionService
baseConfig.InstallationID = aliceInstallationID
aliceEncryptionService := NewEncryptionService(alicePersistence, *baseConfig)

aliceTopicService := topic.NewService(alicePersistence.GetTopicStorage())
aliceSharedSecretService := sharedsecret.NewService(alicePersistence.GetSharedSecretStorage())
aliceMultideviceService := multidevice.New(aliceMultideviceConfig, alicePersistence.GetMultideviceStorage())

s.alice = NewProtocolService(
aliceEncryptionService,
aliceTopicService,
aliceSharedSecretService,
aliceMultideviceService,
func(s []multidevice.IdentityAndIDPair) {},
func(s []*topic.Secret) {},
func(s []*sharedsecret.Secret) {},
)

bobPersistence, err := NewSQLLitePersistence(bobDBPath, bobDBKey)
Expand All @@ -97,17 +97,17 @@ func (s *EncryptionServiceTestSuite) initDatabases(baseConfig *EncryptionService

bobMultideviceService := multidevice.New(bobMultideviceConfig, bobPersistence.GetMultideviceStorage())

bobTopicService := topic.NewService(bobPersistence.GetTopicStorage())
bobSharedSecretService := sharedsecret.NewService(bobPersistence.GetSharedSecretStorage())

baseConfig.InstallationID = bobInstallationID
bobEncryptionService := NewEncryptionService(bobPersistence, *baseConfig)

s.bob = NewProtocolService(
bobEncryptionService,
bobTopicService,
bobSharedSecretService,
bobMultideviceService,
func(s []multidevice.IdentityAndIDPair) {},
func(s []*topic.Secret) {},
func(s []*sharedsecret.Secret) {},
)

}
Expand Down
44 changes: 22 additions & 22 deletions services/shhext/chat/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,34 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/status-im/status-go/services/shhext/chat/multidevice"
"github.com/status-im/status-go/services/shhext/chat/protobuf"
"github.com/status-im/status-go/services/shhext/chat/topic"
"github.com/status-im/status-go/services/shhext/chat/sharedsecret"
)

const ProtocolVersion = 1
const topicNegotiationVersion = 1
const sharedSecretNegotiationVersion = 1
const partitionedTopicMinVersion = 1

type ProtocolService struct {
log log.Logger
encryption *EncryptionService
topic *topic.Service
multidevice *multidevice.Service
addedBundlesHandler func([]multidevice.IdentityAndIDPair)
onNewTopicHandler func([]*topic.Secret)
Enabled bool
log log.Logger
encryption *EncryptionService
secret *sharedsecret.Service
multidevice *multidevice.Service
addedBundlesHandler func([]multidevice.IdentityAndIDPair)
onNewSharedSecretHandler func([]*sharedsecret.Secret)
Enabled bool
}

var ErrNotProtocolMessage = errors.New("Not a protocol message")

// NewProtocolService creates a new ProtocolService instance
func NewProtocolService(encryption *EncryptionService, topic *topic.Service, multidevice *multidevice.Service, addedBundlesHandler func([]multidevice.IdentityAndIDPair), onNewTopicHandler func([]*topic.Secret)) *ProtocolService {
func NewProtocolService(encryption *EncryptionService, secret *sharedsecret.Service, multidevice *multidevice.Service, addedBundlesHandler func([]multidevice.IdentityAndIDPair), onNewSharedSecretHandler func([]*sharedsecret.Secret)) *ProtocolService {
return &ProtocolService{
log: log.New("package", "status-go/services/sshext.chat"),
encryption: encryption,
topic: topic,
multidevice: multidevice,
addedBundlesHandler: addedBundlesHandler,
onNewTopicHandler: onNewTopicHandler,
log: log.New("package", "status-go/services/sshext.chat"),
encryption: encryption,
secret: secret,
multidevice: multidevice,
addedBundlesHandler: addedBundlesHandler,
onNewSharedSecretHandler: onNewSharedSecretHandler,
}
}

Expand Down Expand Up @@ -129,23 +129,23 @@ func (p *ProtocolService) BuildDirectMessage(myIdentityKey *ecdsa.PrivateKey, pu
// Check who we are sending the message to, and see if we have a shared secret
// across devices
var installationIDs []string
var sharedSecret *topic.Secret
var sharedSecret *sharedsecret.Secret
var agreed bool
for installationID := range protocolMessage.GetDirectMessage() {
if installationID != noInstallationID {
installationIDs = append(installationIDs, installationID)
}
}
if len(installationIDs) != 0 {
sharedSecret, agreed, err = p.topic.Send(myIdentityKey, p.encryption.config.InstallationID, publicKey, installationIDs)
sharedSecret, agreed, err = p.secret.Send(myIdentityKey, p.encryption.config.InstallationID, publicKey, installationIDs)
if err != nil {
return nil, err
}
}

// Call handler
if sharedSecret != nil {
p.onNewTopicHandler([]*topic.Secret{sharedSecret})
p.onNewSharedSecretHandler([]*sharedsecret.Secret{sharedSecret})
}
response := &ProtocolMessageSpec{
Message: msg,
Expand Down Expand Up @@ -273,14 +273,14 @@ func (p *ProtocolService) HandleMessage(myIdentityKey *ecdsa.PrivateKey, theirPu
p.log.Info("Checking version")
// Handle protocol negotiation for compatible clients
version := getProtocolVersion(protocolMessage.GetBundles(), protocolMessage.GetInstallationId())
if version >= topicNegotiationVersion {
if version >= sharedSecretNegotiationVersion {
p.log.Info("Version greater than 1 negotianting")
sharedSecret, err := p.topic.Receive(myIdentityKey, theirPublicKey, protocolMessage.GetInstallationId())
sharedSecret, err := p.secret.Receive(myIdentityKey, theirPublicKey, protocolMessage.GetInstallationId())
if err != nil {
return nil, err
}

p.onNewTopicHandler([]*topic.Secret{sharedSecret})
p.onNewSharedSecretHandler([]*sharedsecret.Secret{sharedSecret})

}
return message, nil
Expand Down
Loading

0 comments on commit e432061

Please sign in to comment.