/// <summary>Removes the specified SA from our database.</summary> override protected void RemoveSA(SecurityAssociation sa) { PeerSecAssociation psa = sa as PeerSecAssociation; if(psa == null) { throw new Exception("Invalid PeerSecAssociation: " + sa); } lock(_sync) { if(_spi.ContainsKey(psa.SPI)) { _spi[psa.SPI].Remove(psa.Sender); } } }
protected void AnnounceSA(SecurityAssociation sa, SecurityAssociation.States state) { // PeerSecAssociation sa = o as PeerSecAssociation; }
public void StateChange(SecurityAssociation sa, SecurityAssociation.States st) { state = st; }
protected void Setup(ref SecurityAssociation sa1, ref SecurityAssociation sa2) { sa1.Reset(); sa2.Reset(); sa1.RDHE.Value = sa2.LDHE; sa2.RDHE.Value = sa1.LDHE; Random rand = new Random(); byte[] b = new byte[128]; rand.NextBytes(b); MemBlock mb = MemBlock.Reference(b); sa1.DHEWithCertificateAndCAsOutHash.Value = mb; sa1.VerifyResponse(mb); b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); sa2.DHEWithCertificateHash.Value = mb; sa2.VerifyRequest(mb); sa1.Enable(); sa2.Enable(); // This is just for kicks sa1.Enable(); }
public void SHUpdateTest() { callback_count = 0; int spi = SecurityPolicy.DefaultSPI; MockSender sender1 = new MockSender(null, null, null, 2); MockSender sender2 = new MockSender(null, null, null, 2); SecurityAssociation sa1 = new SecurityAssociation(sender1, spi); sa1.StateChange += StateChange; sender2.Receiver = sa1; MockDataHandler mdh1 = new MockDataHandler(); sa1.Subscribe(mdh1, null); SecurityAssociation sa2 = new SecurityAssociation(sender2, spi); sender1.Receiver = sa2; MockDataHandler mdh2 = new MockDataHandler(); sa2.Subscribe(mdh2, null); Setup(ref sa1, ref sa2); sa1.RequestUpdate += Callback; sa2.RequestUpdate += Callback; byte[] b = null; Random rand = new Random(); MemBlock mb = null; int current_epoch = sa1.CurrentEpoch; for(int i = 0; i < 80; i++) { b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); sa1.Send(mb); Assert.IsTrue(mdh2.Contains(mb), "Contains" + i); if(i % 20 == 0 && i != 0) { Assert.AreEqual(callback_count, 1, "Callback count " + i); callback_count = 0; Thread.Sleep(SecurityAssociation.TIMEOUT * 2 + 5); Setup(ref sa1, ref sa2); } else { if(i % 20 == 1 && i != 1) { Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i); current_epoch = sa1.CurrentEpoch; } Assert.AreEqual(current_epoch, sa1.CurrentEpoch, "Current epoch " + i); } } }
public void Test() { int spi = SecurityPolicy.DefaultSPI; MockSender sender1 = new MockSender(null, null, null, 2); MockSender sender2 = new MockSender(null, null, null, 2); SecurityAssociation sa1 = new SecurityAssociation(sender1, spi); sa1.StateChange += StateChange; sender2.Receiver = sa1; MockDataHandler mdh1 = new MockDataHandler(); sa1.Subscribe(mdh1, null); SecurityAssociation sa2 = new SecurityAssociation(sender2, spi); sender1.Receiver = sa2; MockDataHandler mdh2 = new MockDataHandler(); sa2.Subscribe(mdh2, null); byte[] b = null; Random rand = new Random(); MemBlock mb = null; int current_epoch = sa1.CurrentEpoch; for(int i = 0; i < 5; i++) { Thread.Sleep(SecurityAssociation.TIMEOUT * 2 + 5); Setup(ref sa1, ref sa2); b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); sa1.Send(mb); Assert.IsTrue(mdh2.Contains(mb), "Contains" + i); Assert.AreEqual(state, sa1.State, "State == Active" + i); Assert.IsFalse(current_epoch == sa1.CurrentEpoch, "Current epoch " + i); current_epoch = sa1.CurrentEpoch; } sa1.GarbageCollect(); sa1.GarbageCollect(); b = new byte[128]; rand.NextBytes(b); mb = MemBlock.Reference(b); try { sa1.Send(mb); } catch {} Assert.IsTrue(!mdh2.Contains(mb), "Failed!"); Assert.AreEqual(state, sa1.State, "State == Failed"); }
public SecureEdge(Edge edge, SecurityAssociation sa): base(edge, false) { SA = sa; _closed = 0; }