Skip to content

Commit

Permalink
feat: implement OutOfStoreReceive and OutOfStoreSeal and move all pus…
Browse files Browse the repository at this point in the history
…h notification stuff in Berty

Signed-off-by: D4ryl00 <d4ryl00@gmail.com>
  • Loading branch information
D4ryl00 committed Jul 20, 2023
1 parent aa44f7d commit 035397f
Show file tree
Hide file tree
Showing 27 changed files with 1,249 additions and 7,389 deletions.
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://github.com/berty/weshnet/blame/main/.tool-versions

#-----
# This is simply the most recent version available to date of the lowest
# This is simply the most recent version available to date of the lowest
# major version of Go which is allowed by kubo.
# There is no contraindication for updating it.
#-----
Expand Down
14 changes: 0 additions & 14 deletions api/protocol/errcode/errcode.proto
Original file line number Diff line number Diff line change
Expand Up @@ -157,20 +157,6 @@ enum ErrCode {
ErrServicesDirectoryInvalidVerifiedCredential = 4205;
ErrServicesDirectoryExpiredVerifiedCredential = 4206;
ErrServicesDirectoryInvalidVerifiedCredentialID = 4207;

// Services Push

ErrPush = 6000;
ErrPushWrongAccount = 6001;
ErrPushUnableToDecrypt = 6002;
ErrPushInvalidPayload = 6003;
ErrPushInvalidServerConfig = 6004;
ErrPushMissingBundleID = 6005;
ErrPushUnknownDestination = 6006;
ErrPushProvider = 6007;
ErrPushUnknownProvider = 6008;
ErrNoProvidersConfigured = 6009;
ErrInvalidPrivateKey = 6010;
}

message ErrDetails { repeated ErrCode codes = 1; }
95 changes: 21 additions & 74 deletions api/protocol/protocoltypes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ syntax = "proto3";
package weshnet.protocol.v1;

import "gogoproto/gogo.proto";
import "pushtypes/pushtypes.proto";

option go_package = "berty.tech/weshnet/pkg/protocoltypes";

Expand Down Expand Up @@ -242,15 +241,6 @@ enum EventType {
// EventTypeGroupReplicating indicates that the group has been registered for replication on a server
EventTypeGroupReplicating = 403;

// EventTypePushMemberTokenUpdate
EventTypePushMemberTokenUpdate = 404;

// EventTypePushDeviceTokenRegistered
EventTypePushDeviceTokenRegistered = 405;

// EventTypePushDeviceServerRegistered
EventTypePushDeviceServerRegistered = 406;

// EventTypeAccountVerifiedCredentialRegistered
EventTypeAccountVerifiedCredentialRegistered = 500;

Expand Down Expand Up @@ -691,8 +681,6 @@ message ServiceGetConfiguration {
SettingState wifi_p2p_enabled = 7; // MultiPeerConnectivity for Darwin and Nearby for Android
SettingState mdns_enabled = 8;
SettingState relay_enabled = 9;
PushServiceReceiver device_push_token = 10;
PushServer device_push_server = 11;
}
}

Expand Down Expand Up @@ -1380,11 +1368,6 @@ message Progress {
uint64 delay = 6;
}

message MemberWithDevices {
bytes member_pk = 1 [(gogoproto.customname) = "MemberPK"];
repeated bytes devices_pks = 2 [(gogoproto.customname) = "DevicePKs"];
}

message OutOfStoreMessage {
bytes cid = 1 [(gogoproto.customname) = "CID"];
bytes device_pk = 2 [(gogoproto.customname) = "DevicePK"];
Expand All @@ -1395,63 +1378,10 @@ message OutOfStoreMessage {
bytes nonce = 7;
}

message PushServiceReceiver {
// token_type is the type of the token used, it allows us to act as a proxy to the appropriate push server
push.v1.PushServiceTokenType token_type = 1;

// bundle_id is the app identifier
string bundle_id = 2 [(gogoproto.customname) = "BundleID"];

// token is the device identifier used
bytes token = 3;

// recipient_public_key is the public key which will be used to encrypt the payload
bytes recipient_public_key = 4;
}

message PushServer {
bytes server_key = 1;
string service_addr = 2;
}

message PushDeviceTokenRegistered {
PushServiceReceiver token = 1;

// device_pk is the public key of the device sending the message
bytes device_pk = 2 [(gogoproto.customname) = "DevicePK"];
}

message PushDeviceServerRegistered {
PushServer server = 1;

// device_pk is the public key of the device sending the message
bytes device_pk = 2 [(gogoproto.customname) = "DevicePK"];
}

message AccountVerifiedCredentialRegistered {
// device_pk is the public key of the device sending the message
bytes device_pk = 1 [(gogoproto.customname) = "DevicePK"];

bytes signed_identity_public_key = 2;

string verified_credential = 3;

int64 registration_date = 4;

int64 expiration_date = 5;

string identifier = 6;

string issuer = 7;
}

message PushMemberTokenUpdate {
PushServer server = 1;

bytes token = 2;

// device_pk is the public key of the device sending the message
bytes device_pk = 3 [(gogoproto.customname) = "DevicePK"];
message OutOfStoreMessageEnvelope {
bytes nonce = 1;
bytes box = 2;
bytes group_reference = 3;
}

message OutOfStoreReceive {
Expand All @@ -1476,6 +1406,23 @@ message OutOfStoreSeal {
}
}

message AccountVerifiedCredentialRegistered {
// device_pk is the public key of the device sending the message
bytes device_pk = 1 [(gogoproto.customname) = "DevicePK"];

bytes signed_identity_public_key = 2;

string verified_credential = 3;

int64 registration_date = 4;

int64 expiration_date = 5;

string identifier = 6;

string issuer = 7;
}

message FirstLastCounters {
uint64 first = 1;
uint64 last = 2;
Expand Down
135 changes: 0 additions & 135 deletions api/protocol/pushtypes/pushtypes.proto

This file was deleted.

43 changes: 43 additions & 0 deletions api_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/base64"
"fmt"

"github.com/ipfs/go-cid"
"go.uber.org/zap"

"berty.tech/weshnet/pkg/errcode"
Expand Down Expand Up @@ -48,6 +49,48 @@ func (s *service) AppMessageSend(ctx context.Context, req *protocoltypes.AppMess
return &protocoltypes.AppMessageSend_Reply{CID: op.GetEntry().GetHash().Bytes()}, nil
}

// OutOfStoreReceive parses a payload received outside a synchronized store
func (s *service) OutOfStoreReceive(ctx context.Context, request *protocoltypes.OutOfStoreReceive_Request) (*protocoltypes.OutOfStoreReceive_Reply, error) {
outOfStoreMessage, group, clearPayload, alreadyDecrypted, err := s.secretStore.OpenOutOfStoreMessage(ctx, request.Payload)
if err != nil {
return nil, errcode.ErrCryptoDecrypt.Wrap(err)
}

return &protocoltypes.OutOfStoreReceive_Reply{
Message: outOfStoreMessage,
Cleartext: clearPayload,
GroupPublicKey: group.PublicKey,
AlreadyReceived: alreadyDecrypted,
}, nil
}

// OutOfStoreSeal creates a payload of a message present in store to be sent outside a synchronized store
func (s *service) OutOfStoreSeal(ctx context.Context, request *protocoltypes.OutOfStoreSeal_Request) (*protocoltypes.OutOfStoreSeal_Reply, error) {
gc, err := s.GetContextGroupForID(request.GroupPublicKey)
if err != nil {
return nil, err
}

_, c, err := cid.CidFromBytes(request.CID)
if err != nil {
return nil, errcode.ErrInvalidInput.Wrap(err)
}

sealedMessageEnvelope, err := gc.messageStore.GetOutOfStoreMessageEnvelope(ctx, c)
if err != nil {
return nil, errcode.ErrInternal.Wrap(err)
}

sealedMessageEnvelopeBytes, err := sealedMessageEnvelope.Marshal()
if err != nil {
return nil, errcode.ErrSerialization.Wrap(err)
}

return &protocoltypes.OutOfStoreSeal_Reply{
Encrypted: sealedMessageEnvelopeBytes,
}, nil
}

func tyberLogGroupContext(ctx context.Context, logger *zap.Logger, gc *GroupContext) {
memberPK, err := gc.MemberPubKey().Raw()
if err != nil {
Expand Down
12 changes: 5 additions & 7 deletions api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,10 @@ func (s *service) ServiceGetConfiguration(ctx context.Context, req *protocoltype
}

return &protocoltypes.ServiceGetConfiguration_Reply{
AccountPK: member,
DevicePK: device,
AccountGroupPK: accountGroup.Group().PublicKey,
PeerID: key.ID().Pretty(),
Listeners: listeners,
DevicePushToken: accountGroup.metadataStore.getCurrentDevicePushToken(),
DevicePushServer: accountGroup.metadataStore.getCurrentDevicePushServer(),
AccountPK: member,
DevicePK: device,
AccountGroupPK: accountGroup.Group().PublicKey,
PeerID: key.ID().Pretty(),
Listeners: listeners,
}, nil
}
4 changes: 4 additions & 0 deletions api_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ func (s *service) GroupMetadataList(req *protocoltypes.GroupMetadataList_Request
previousEvents <- protocoltypes.GroupMetadataEvent{EventContext: nil}
}

cg.logger.Debug("GroupMetadataList: previous events stream ended")

return
}

Expand Down Expand Up @@ -172,6 +174,8 @@ func (s *service) GroupMessageList(req *protocoltypes.GroupMessageList_Request,
previousEvents <- protocoltypes.GroupMessageEvent{EventContext: nil}
}

cg.logger.Debug("GroupMessageList: previous events stream ended")

return
}

Expand Down
Loading

0 comments on commit 035397f

Please sign in to comment.