/// <summary>
        /// Construct a group session for sending messages.
        /// </summary>
        /// <param name="senderKeyName">The (groupId, senderId, deviceId) tuple. In this case, 'senderId' should be the
        /// caller.</param>
        /// <returns>A SenderKeyDistributionMessage that is individually distributed to each member of the group.</returns>
        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);
                }
            }
        }
 /// <summary>
 /// Construct a group session for receiving messages from senderKeyName.
 /// </summary>
 /// <param name="senderKeyName">The (groupId, senderId, deviceId) tuple associated with the SenderKeyDistributionMessage.</param>
 /// <param name="senderKeyDistributionMessage">A received SenderKeyDistributionMessage.</param>
 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);
     }
 }
Exemple #3
0
        public override bool Equals(Object other)
        {
            if (other == null)
            {
                return(false);
            }
            if (!(other is SenderKeyName))
            {
                return(false);
            }

            SenderKeyName that = (SenderKeyName)other;

            return
                (this.groupId.Equals(that.groupId) &&
                 this.sender.Equals(that.sender));
        }
 public GroupCipher(SenderKeyStore senderKeyStore, SenderKeyName senderKeyId)
 {
     this.senderKeyStore = senderKeyStore;
     this.senderKeyId    = senderKeyId;
 }