示例#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 (InvalidKeyIdException e)
                {
                    throw new Exception(e.Message);
                }
                catch (InvalidKeyException e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
        /**
         * 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 (InvalidKeyIdException e)
                {
                    throw new Exception(e.Message);
                }
                catch (InvalidKeyException e)
                {
                    throw new Exception(e.Message);
                }
            }
        }
 /**
  * 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);
     }
 }
示例#4
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);
     }
 }
示例#5
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 SenderKeyRecord loadSenderKey(SenderKeyName senderKeyName)
        {
            try
            {
                SenderKeyRecord record;
                store.TryGetValue(senderKeyName, out record);

                if (record == null)
                {
                    return new SenderKeyRecord();
                }
                else
                {
                    return new SenderKeyRecord(record.serialize());
                }
            }
            catch (IOException e)
            {
                throw new Exception(e.Message);
            }
        }
示例#7
0
 public GroupCipher(SenderKeyStore senderKeyStore, SenderKeyName senderKeyId)
 {
     this.senderKeyStore = senderKeyStore;
     this.senderKeyId    = senderKeyId;
 }
 public void storeSenderKey(SenderKeyName senderKeyName, SenderKeyRecord record)
 {
     store[senderKeyName] = record;
 }
 public GroupCipher(SenderKeyStore senderKeyStore, SenderKeyName senderKeyId)
 {
     this.senderKeyStore = senderKeyStore;
     this.senderKeyId = senderKeyId;
 }