Esempio n. 1
0
        /**
         * Construct a group session for sending messages.
         *
         * @param senderKeyName The (groupId, senderId, deviceId) tuple.  In this case, 'senderId' should be the caller.
         * @return A SenderKeyDistributionMessage that is individually distributed to each member of the group.
         */
        public SenderKeyDistributionMessage Create(SenderKeyName senderKeyName)
        {
            lock (GroupCipher.Lock)
            {
                try
                {
                    SenderKeyRecord senderKeyRecord = _senderKeyStore.LoadSenderKey(senderKeyName);

                    if (senderKeyRecord.IsEmpty())
                    {
                        senderKeyRecord.SetSenderKeyState(KeyHelper.GenerateSenderKeyId(),
                                                          0,
                                                          KeyHelper.GenerateSenderKey(),
                                                          KeyHelper.GenerateSenderSigningKey());
                        _senderKeyStore.StoreSenderKey(senderKeyName, senderKeyRecord);
                    }

                    SenderKeyState state = senderKeyRecord.GetSenderKeyState();

                    return(new SenderKeyDistributionMessage(state.GetKeyId(),
                                                            state.GetSenderChainKey().GetIteration(),
                                                            state.GetSenderChainKey().GetSeed(),
                                                            state.GetSigningKeyPublic()));
                }
                catch (Exception e) when(e is InvalidKeyIdException || e is InvalidKeyException)
                {
                    throw new Exception(e.Message);
                }
            }
        }
Esempio n. 2
0
 /**
  * Construct a group session for receiving messages from senderKeyName.
  *
  * @param senderKeyName The (groupId, senderId, deviceId) tuple associated with the SenderKeyDistributionMessage.
  * @param senderKeyDistributionMessage A received SenderKeyDistributionMessage.
  */
 public void Process(SenderKeyName senderKeyName, SenderKeyDistributionMessage senderKeyDistributionMessage)
 {
     lock (GroupCipher.Lock)
     {
         SenderKeyRecord senderKeyRecord = _senderKeyStore.LoadSenderKey(senderKeyName);
         senderKeyRecord.AddSenderKeyState(senderKeyDistributionMessage.GetId(),
                                           senderKeyDistributionMessage.GetIteration(),
                                           senderKeyDistributionMessage.GetChainKey(),
                                           senderKeyDistributionMessage.GetSignatureKey());
         _senderKeyStore.StoreSenderKey(senderKeyName, senderKeyRecord);
     }
 }
Esempio n. 3
0
        public override bool Equals(Object other)
        {
            if (other == null)
            {
                return(false);
            }
            if (!(other is SenderKeyName))
            {
                return(false);
            }

            SenderKeyName that = (SenderKeyName)other;

            return
                (_groupId.Equals(that._groupId) &&
                 _sender.Equals(that._sender));
        }
 public GroupCipher(ISenderKeyStore senderKeyStore, SenderKeyName senderKeyId)
 {
     _senderKeyStore = senderKeyStore;
     _senderKeyId    = senderKeyId;
 }