Skip to content
Snippets Groups Projects
Commit 1b0e0604 authored by Jonah Husson's avatar Jonah Husson
Browse files

revive register/unregister for notifications

parent 68809d20
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,15 @@
package api
import jww "github.com/spf13/jwalterweatherman"
import (
"github.com/pkg/errors"
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/comms/mixmessages"
"gitlab.com/elixxir/crypto/hash"
"gitlab.com/xx_network/crypto/signature/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
)
// RegisterForNotifications allows a client to register for push
// notifications.
......@@ -17,22 +25,29 @@ import jww "github.com/spf13/jwalterweatherman"
// risk to the user.
func (c *Client) RegisterForNotifications(token []byte) error {
jww.INFO.Printf("RegisterForNotifications(%s)", token)
// // Pull the host from the manage
// notificationBotHost, ok := cl.receptionManager.Comms.GetHost(&id.NotificationBot)
// if !ok {
// return errors.New("Failed to retrieve host for notification bot")
// }
// // Send the register message
// _, err := cl.receptionManager.Comms.RegisterForNotifications(notificationBotHost,
// &mixmessages.NotificationToken{
// Token: notificationToken,
// })
// if err != nil {
// err := errors.Errorf(
// "RegisterForNotifications: Unable to register for notifications! %s", err)
// return err
// }
// Pull the host from the manage
notificationBotHost, ok := c.comms.GetHost(&id.NotificationBot)
if !ok {
return errors.New("RegisterForNotifications: Failed to retrieve host for notification bot")
}
intermediaryReceptionID, sig, err := c.getIidAndSig()
if err != nil {
return err
}
// 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,
})
if err != nil {
err := errors.Errorf(
"RegisterForNotifications: Unable to register for notifications! %s", err)
return err
}
return nil
}
......@@ -40,19 +55,46 @@ func (c *Client) RegisterForNotifications(token []byte) error {
// UnregisterForNotifications turns of notifications for this client
func (c *Client) UnregisterForNotifications() error {
jww.INFO.Printf("UnregisterForNotifications()")
// // Pull the host from the manage
// notificationBotHost, ok := cl.receptionManager.Comms.GetHost(&id.NotificationBot)
// if !ok {
// return errors.New("Failed to retrieve host for notification bot")
// }
// // Send the unregister message
// _, err := cl.receptionManager.Comms.UnregisterForNotifications(notificationBotHost)
// if err != nil {
// err := errors.Errorf(
// "RegisterForNotifications: Unable to register for notifications! %s", err)
// return err
// }
// Pull the host from the manage
notificationBotHost, ok := c.comms.GetHost(&id.NotificationBot)
if !ok {
return errors.New("Failed to retrieve host for notification bot")
}
intermediaryReceptionID, sig, err := c.getIidAndSig()
if err != nil {
return err
}
// Send the unregister message
_, err = c.comms.UnregisterForNotifications(notificationBotHost, &mixmessages.NotificationUnregisterRequest{
IntermediaryId: intermediaryReceptionID,
IIDTransmissionRsaSig: sig,
})
if err != nil {
err := errors.Errorf(
"RegisterForNotifications: Unable to register for notifications! %s", err)
return err
}
return nil
}
func (c *Client) getIidAndSig() ([]byte, []byte, error) {
intermediaryReceptionID, err := ephemeral.GetIntermediaryId(c.GetUser().ReceptionID)
if err != nil {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to form intermediary ID")
}
h, err := hash.NewCMixHash()
if err != nil {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to create cmix hash")
}
_, err = h.Write(intermediaryReceptionID)
if err != nil {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to write intermediary ID to hash")
}
sig, err := rsa.Sign(c.rng.GetStream(), c.GetUser().TransmissionRSA, hash.CMixHash, h.Sum(nil), nil)
if err != nil {
return nil, nil, errors.WithMessage(err, "RegisterForNotifications: Failed to sign intermediary ID")
}
return intermediaryReceptionID, sig, nil
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment