Exemplo n.º 1
0
        public SenderKeyDistributionMessage Create(SenderKeyName senderKeyName)
        {
            lock (GroupCipher.LOCK)
            {
                try {
                    var senderKeyRecord = _senderKeyStore.LoadSenderKey(senderKeyName);

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

                    SenderKeyState state = senderKeyRecord.GetSenderKeyState();

                    return new SenderKeyDistributionMessage(state.KeyId,
                                                            state.SenderChainKey.Iteration,
                                                            state.SenderChainKey.Seed,
                                                            state.SigningKeyPublic);

                } catch (Exception e) {
                    throw new Exception("GroupSessuinBuilder ex: " + e);
                }
            }
        }
 public void StoreSenderKey(SenderKeyName senderKeyName, SenderKeyRecord record)
 {
     if (store.ContainsKey (senderKeyName)) {
         store [senderKeyName] = record;
     } else {
         store.Add (senderKeyName, record);
     }
 }
 public SenderKeyRecord LoadSenderKey(SenderKeyName senderKeyName)
 {
     try {
         if (store.ContainsKey(senderKeyName)) {
             var record = store[senderKeyName];
             return new SenderKeyRecord(record.Serialize());
         } else {
             return new SenderKeyRecord();
         }
     } catch (Exception e) {
         throw new InvalidOperationException("Assertion error", e);
     }
 }
Exemplo n.º 4
0
        public void Process(SenderKeyName senderKeyName, SenderKeyDistributionMessage senderKeyDistributionMessage)
        {
            lock (GroupCipher.LOCK)
            {
                var senderKeyRecord = _senderKeyStore.LoadSenderKey(senderKeyName);
                senderKeyRecord.AddSenderKeyState(senderKeyDistributionMessage.Id,
                                                  senderKeyDistributionMessage.Iteration,
                                                  senderKeyDistributionMessage.ChainKey,
                                                  senderKeyDistributionMessage.SignatureKey);

                _senderKeyStore.StoreSenderKey(senderKeyName, senderKeyRecord);
            }
        }
Exemplo n.º 5
0
 public GroupCipher(ISenderKeyStore senderKeyStore, SenderKeyName senderKeyId)
 {
     _senderKeyStore = senderKeyStore;
     _senderKeyId = senderKeyId;
 }