diff --git a/README.md b/README.md index 98a8c6b0b888063c9ffd447641f55a0d5339a191..0cd7989af96e9851126932c253e8385c3f9ea8d7 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ client --password user1-password --ndf ndf.json -l client1.log -s user1session - client --password user2-password --ndf ndf.json -l client2.log -s user2session --writeContact user2-contact.json --unsafe -m "Hi" # Send E2E Messages -client --password user1-password --ndf ndf.json -l client1.log -s user1session --destfile user2-contact.json --unsafe-channel-creation -m "Hi User 2, from User 1 with E2E Encryption" & +client --password user1-password --ndf ndf.json -l client1.log -s user1session --destfile user1-contact.json --unsafe-channel-creation -m "Hi User 2, from User 1 with E2E Encryption" & client --password user2-password --ndf ndf.json -l client2.log -s user2session --destfile user1-contact.json --unsafe-channel-creation -m "Hi User 1, from User 2 with E2E Encryption" & ``` diff --git a/api/client.go b/api/client.go index ae87fdc6dc36a974875f5a73ddea87ed52fbded1..2f2387b9033296c92c2b924d8d87b28cc72d77f6 100644 --- a/api/client.go +++ b/api/client.go @@ -8,6 +8,7 @@ package api import ( + "gitlab.com/xx_network/comms/connect" "gitlab.com/xx_network/primitives/id" "time" @@ -199,7 +200,7 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie } u := c.storage.GetUser() - jww.INFO.Printf("Client Logged in: \n\tTransmisstionID: %s " + + jww.INFO.Printf("Client Logged in: \n\tTransmisstionID: %s "+ "\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID) //Attach the services interface @@ -226,6 +227,13 @@ func Login(storageDir string, password []byte, parameters params.Network) (*Clie "or track network.") } + if def.Notification.Address != "" { + _, err = c.comms.AddHost(&id.NotificationBot, def.Notification.Address, []byte(def.Notification.TlsCertificate), connect.GetDefaultHostParams()) + if err != nil { + jww.WARN.Printf("Failed adding host for notifications: %+v", err) + } + } + // Initialize network and link it to context c.network, err = network.NewManager(c.storage, c.switchboard, c.rng, c.comms, parameters, def) @@ -381,7 +389,7 @@ func (c *Client) initPermissioning(def *ndf.NetworkDefinition) error { // Handles both auth confirm and requests func (c *Client) StartNetworkFollower() (<-chan interfaces.ClientError, error) { u := c.GetUser() - jww.INFO.Printf("StartNetworkFollower() \n\tTransmisstionID: %s " + + jww.INFO.Printf("StartNetworkFollower() \n\tTransmisstionID: %s "+ "\n\tReceptionID: %s", u.TransmissionID, u.ReceptionID) c.clientErrorChannel = make(chan interfaces.ClientError, 1000) @@ -526,13 +534,13 @@ func (c *Client) GetNodeRegistrationStatus() (int, int, error) { cmixStore := c.storage.Cmix() var numRegistered int - for i, n := range nodes{ + for i, n := range nodes { nid, err := id.Unmarshal(n.ID) - if err!=nil{ - return 0,0, errors.Errorf("Failed to unmarshal node ID %v " + + if err != nil { + return 0, 0, errors.Errorf("Failed to unmarshal node ID %v "+ "(#%d): %s", n.ID, i, err.Error()) } - if cmixStore.Has(nid){ + if cmixStore.Has(nid) { numRegistered++ } } diff --git a/api/notifications.go b/api/notifications.go index 2aaed501ebcda3eb7bf5d09939c009574cc9639a..1fe7bfb4811cb276ebd3e49f405af2348e5372f8 100644 --- a/api/notifications.go +++ b/api/notifications.go @@ -8,6 +8,7 @@ package api import ( + "fmt" "github.com/pkg/errors" jww "github.com/spf13/jwalterweatherman" "gitlab.com/elixxir/comms/mixmessages" @@ -25,6 +26,7 @@ import ( // risk to the user. func (c *Client) RegisterForNotifications(token []byte) error { jww.INFO.Printf("RegisterForNotifications(%s)", token) + fmt.Println("RegisterforNotifications") // Pull the host from the manage notificationBotHost, ok := c.comms.GetHost(&id.NotificationBot) if !ok { @@ -34,14 +36,16 @@ func (c *Client) RegisterForNotifications(token []byte) error { if err != nil { return err } + fmt.Println("Sending message") // Send the register message _, err = c.comms.RegisterForNotifications(notificationBotHost, &mixmessages.NotificationRegisterRequest{ - Token: token, - IntermediaryId: intermediaryReceptionID, - TransmissionRsa: rsa.CreatePublicKeyPem(c.GetUser().TransmissionRSA.GetPublic()), - TransmissionRsaSig: sig, - TransmissionSalt: c.GetUser().TransmissionSalt, + Token: token, + IntermediaryId: intermediaryReceptionID, + TransmissionRsa: rsa.CreatePublicKeyPem(c.GetUser().TransmissionRSA.GetPublic()), + TransmissionRsaSig: sig, + TransmissionSalt: c.GetUser().TransmissionSalt, + IIDTransmissionRsaSig: []byte("temp"), }) if err != nil { err := errors.Errorf( diff --git a/bindings/notifications.go b/bindings/notifications.go index db1073292a9d8869aea16029e1aadbf4ab2ad65d..6676c28e7f6b21df553c9a90bda1df83ab8c91f2 100644 --- a/bindings/notifications.go +++ b/bindings/notifications.go @@ -7,6 +7,30 @@ package bindings +import ( + "encoding/base64" + "github.com/pkg/errors" + "gitlab.com/elixxir/crypto/fingerprint" + "gitlab.com/xx_network/primitives/id" +) + +// Check if a notification received is for me +func NotificationForMe(messageHash, idFP string, receptionId []byte) (bool, error) { + messageHashBytes, err := base64.StdEncoding.DecodeString(messageHash) + if err != nil { + return false, errors.WithMessage(err, "Failed to decode message ID") + } + idFpBytes, err := base64.StdEncoding.DecodeString(idFP) + if err != nil { + return false, errors.WithMessage(err, "Failed to decode identity fingerprint") + } + rid, err := id.Unmarshal(receptionId) + if err != nil { + return false, errors.WithMessage(err, "Failed to unmartial reception ID") + } + return fingerprint.CheckIdentityFpFromMessageHash(idFpBytes, messageHashBytes, rid), nil +} + // Register for notifications, accepts firebase messaging token func (c *Client) RegisterForNotifications(token []byte) error { return c.api.RegisterForNotifications(token) diff --git a/bindings/notifications_test.go b/bindings/notifications_test.go new file mode 100644 index 0000000000000000000000000000000000000000..c30e6e175566905a59b60ef4a570adcca77af3f9 --- /dev/null +++ b/bindings/notifications_test.go @@ -0,0 +1,23 @@ +package bindings + +import ( + "encoding/base64" + "gitlab.com/elixxir/crypto/fingerprint" + "gitlab.com/xx_network/primitives/id" + "testing" +) + +func TestNotificationForMe(t *testing.T) { + payload := []byte("I'm a payload") + hash := fingerprint.GetMessageHash(payload) + rid := id.NewIdFromString("zezima", id.User, t) + fp := fingerprint.IdentityFP(payload, rid) + + ok, err := NotificationForMe(base64.StdEncoding.EncodeToString(hash), base64.StdEncoding.EncodeToString(fp), rid.Bytes()) + if err != nil { + t.Errorf("Failed to check notification: %+v", err) + } + if !ok { + t.Error("Should have gotten ok response") + } +} diff --git a/cmd/root.go b/cmd/root.go index 9ff887dad0dbb4d3d6e22a649f4ca43e5039a32e..7cce8968388d0f9e8baf80d8aae2a18857530dc9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -62,6 +62,7 @@ var rootCmd = &cobra.Command{ recipientID, isPrecanPartner = parseRecipient( viper.GetString("destid")) } + fmt.Println(isPrecanPartner) // Set it to myself if recipientID == nil { @@ -115,6 +116,11 @@ var rootCmd = &cobra.Command{ client.GetHealth().AddChannel(connected) waitUntilConnected(connected) + //err = client.RegisterForNotifications([]byte("dJwuGGX3KUyKldWK5PgQH8:APA91bFjuvimRc4LqOyMDiy124aLedifA8DhldtaB_b76ggphnFYQWJc_fq0hzQ-Jk4iYp2wPpkwlpE1fsOjs7XWBexWcNZoU-zgMiM0Mso9vTN53RhbXUferCbAiEylucEOacy9pniN")) + //if err != nil { + // jww.FATAL.Panicf("Failed to register for notifications: %+v", err) + //} + // After connection, make sure we have registered with at least // 85% of the nodes numReg := 1 @@ -249,6 +255,7 @@ var rootCmd = &cobra.Command{ } } fmt.Printf("Received %d\n", receiveCnt) + err = client.StopNetworkFollower(5 * time.Second) if err != nil { jww.WARN.Printf( @@ -322,12 +329,12 @@ func createClient() *api.Client { } else { if userIDprefix != "" { err = api.NewVanityClient(string(ndfJSON), storeDir, - []byte(pass), regCode, userIDprefix) + []byte(pass), regCode, userIDprefix) } else { err = api.NewClient(string(ndfJSON), storeDir, - []byte(pass), regCode) + []byte(pass), regCode) } - + } if err != nil {