Exemple #1
0
        public void TestRemoteRestart()
        {
            Timer t   = new Timer(Timeout, null, 0, 500);
            int   spi = 123333;

            new SecurityPolicy(spi, "Rijndael", "SHA1", true);
            SecurityOverlord so0 = CreateValidSO("valid0");
            SecurityOverlord so1 = CreateValidSO("valid1");

            MockSender ms0 = new MockSender(null, null, so1, 0);
            MockSender ms1 = new MockSender(ms0, null, so0, 0);

            ms0.ReturnPath = ms1;

            SecurityAssociation sa0 = so0.CreateSecurityAssociation(ms0, spi, true);
            SecurityAssociation sa1 = so1.CreateSecurityAssociation(ms1, spi, true);

            Assert.AreEqual(sa0.State, SecurityAssociation.SAState.Active, "sa0 should be active!");
            Assert.AreEqual(sa1.State, SecurityAssociation.SAState.Active, "sa1 should be active!");
            Assert.AreEqual(so0.SACount, 1, "so0 should contain just one!");
            Assert.AreEqual(so1.SACount, 1, "so1 should contain just one!");

            sa0.GarbageCollect();
            sa0.GarbageCollect();
            Assert.AreEqual(so0.SACount, 0, "so0 should contain just zero!");
            sa1.GarbageCollect();
            Assert.AreEqual(so1.SACount, 1, "so1 should contain just one!");
            sa1.Send(MemBlock.Reference(new byte[] { 0, 1, 2, 3 }));
            Assert.AreEqual(so0.SACount, 1, "so0 should contain just one!");
            Assert.AreEqual(so1.SACount, 1, "so1 should contain just one!");

            t.Dispose();
        }
Exemple #2
0
 public ApplicationNode(StructuredNode node, IDht dht, RpcDhtProxy dht_proxy,
     NCService ncservice, SecurityOverlord security_overlord, NodeConfig nc)
 {
   Config = nc;
   Node = node;
   Dht = dht;
   DhtProxy = dht_proxy;
   NCService = ncservice;
   SecurityOverlord = security_overlord;
   SymphonySecurityOverlord = security_overlord as SymphonySecurityOverlord;
 }
Exemple #3
0
        protected SecurityOverlord CreateInvalidSO(string name, int level)
        {
            if (rsa == null)
            {
                rsa = new RSACryptoServiceProvider();
                byte[] blob = rsa.ExportCspBlob(false);
                RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
                rsa_pub.ImportCspBlob(blob);
                CertificateMaker cm = new CertificateMaker("United States", "UFL",
                                                           "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
                                                           "brunet:node:abcdefghijklmnopqrs");
                Certificate cert = cm.Sign(cm, rsa);
                x509 = cert.X509;
            }

            CertificateHandler ch = new CertificateHandler();

            if (level == 2 || level == 0)
            {
                ch.AddCACertificate(x509);
            }
            if (level == 3 || level == 0)
            {
                ch.AddSignedCertificate(x509);
            }
            ReqrepManager rrm = new ReqrepManager("so" + name);

            _timeout += rrm.TimeoutChecker;
            SecurityOverlord so = new SecurityOverlord(rsa_safe, rrm, ch);

            so.AnnounceSA += AnnounceSA;
            RoutingDataHandler rdh = new RoutingDataHandler();

            rrm.Subscribe(so, null);
            so.Subscribe(rdh, null);
            rdh.Subscribe(rrm, null);
            return(so);
        }
Exemple #4
0
        public void TestWithPreExchangedKeys()
        {
            Timer t   = new Timer(Timeout, null, 0, 500);
            int   spi = 123333;

            new SecurityPolicy(spi, "Rijndael", "SHA1", true);
            SecurityOverlord so0 = CreateValidSO("valid0");
            SecurityOverlord so1 = CreateValidSO("valid1");

            MockSender ms0 = new MockSender(null, null, so1, 0);
            MockSender ms1 = new MockSender(ms0, null, so0, 0);

            ms0.ReturnPath = ms1;

            SecurityAssociation sa0 = so0.CreateSecurityAssociation(ms0, spi, true);
            SecurityAssociation sa1 = so1.CreateSecurityAssociation(ms1, spi, true);

            Assert.AreEqual(sa0.State, SecurityAssociation.SAState.Active, "sa0 should be active!");
            Assert.AreEqual(sa1.State, SecurityAssociation.SAState.Active, "sa1 should be active!");
            Assert.AreEqual(so0.SACount, 1, "so0 should contain just one!");
            Assert.AreEqual(so1.SACount, 1, "so1 should contain just one!");

            t.Dispose();
        }
 public BroadcastRevocationHandler(Certificate ca_cert, SecurityOverlord so)
 {
     _revoked_users = new Hashtable();
     _ca_cert       = ca_cert;
     _so            = so;
 }
 public SecureEdgeListener(EdgeListener el, SecurityOverlord so): base(el) {
   _so = so;
   _so.AnnounceSA += AnnounceSA;
 }
 public BroadcastRevocationHandler (Certificate ca_cert, SecurityOverlord so)
 {
   _revoked_users = new Hashtable();
   _ca_cert = ca_cert;
   _so = so;
 }
Exemple #8
0
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig,
                   string certificate) : base(brunetConfig, ipopConfig) {
   _friends = new Dictionary<string, SocialUser>();
   _bfriends = new List<string>();
   _sync = new object();
   _status = StatusTypes.Offline.ToString();
   _global_block = new WriteOnce<bool>();
   _local_user = new SocialUser();
   _local_user.Certificate = certificate;
   _local_user.IP = _marad.LocalIP;
   _marad.AddDnsMapping(_local_user.Alias, _local_user.IP, true);
   _bso = AppNode.SecurityOverlord;
   _bso.CertificateHandler.AddCACertificate(_local_user.GetCert().X509);
   _bso.CertificateHandler.AddSignedCertificate(_local_user.GetCert().X509);
 }
 public SecureEdgeListener(EdgeListener el, SecurityOverlord so): base(el) {
   _so = so;
   _so.AnnounceSA += AnnounceSA;
   _edge_to_sa = new Dictionary<Edge, SecurityAssociation>();
   _edge_to_inbound = new Dictionary<Edge, bool>();
 }
 public Information(StructuredNode node, String type, SecurityOverlord so) :
   this(node, type)
 {
   _so = so;
 }
Exemple #11
0
        public void Test()
        {
            Timer            t   = new Timer(Timeout, null, 0, 500);
            SecurityOverlord so0 = CreateValidSO("valid0");
            SecurityOverlord so1 = CreateValidSO("valid1");

            //Test block one
            {
                MockSender ms0 = new MockSender(null, null, so1, 0);
                MockSender ms1 = new MockSender(ms0, null, so0, 0);
                ms0.ReturnPath = ms1;

                SecurityAssociation sa0 = so0.CreateSecurityAssociation(ms0, true);
                SecurityAssociation sa1 = so1.CreateSecurityAssociation(ms1, true);
                Assert.AreEqual(sa0.State, SecurityAssociation.SAState.Active, "sa0 should be active!");
                Assert.AreEqual(sa1.State, SecurityAssociation.SAState.Active, "sa1 should be active!");
                Assert.AreEqual(so0.SACount, 1, "so0 should contain just one!");
                Assert.AreEqual(so1.SACount, 1, "so1 should contain just one!");

                Random rand = new Random();
                byte[] b    = new byte[128];
                rand.NextBytes(b);
                MemBlock mb = MemBlock.Reference(b);
                sa1.Send(mb);

                new SecurityPolicy(12345, "DES", "MD5");
                sa0 = so0.CreateSecurityAssociation(ms0, 12345, true);
                Assert.AreEqual(sa0.State, SecurityAssociation.SAState.Active, "sa0 should be active!");
                Assert.AreEqual(so0.SACount, 2, "so0 should contain just one!");
                Assert.AreEqual(so1.SACount, 2, "so1 should contain just one!");

                b = new byte[128];
                rand.NextBytes(b);
                mb = MemBlock.Reference(b);
                sa0.Send(mb);
            }

            // create ~250 valid SAs for one guy...
            for (int i = 2; i < 250; i++)
            {
                SecurityOverlord so  = CreateValidSO("valid" + i);
                MockSender       msa = new MockSender(null, null, so, 0);
                MockSender       msb = new MockSender(msa, null, so0, 0);
                msa.ReturnPath = msb;

                SecurityAssociation sab = so.CreateSecurityAssociation(msb, true);
                Assert.AreEqual(sab.State, SecurityAssociation.SAState.Active, "sab should be active! " + i);
                SecurityAssociation saa = so0.CreateSecurityAssociation(msa, true);
                Assert.AreEqual(saa.State, SecurityAssociation.SAState.Active, "saa should be active! " + i);

                MockDataHandler mdha = new MockDataHandler();
                saa.Subscribe(mdha, null);
                MockDataHandler mdhb = new MockDataHandler();
                sab.Subscribe(mdhb, null);

                Random rand = new Random();
                byte[] b    = new byte[128];
                rand.NextBytes(b);
                MemBlock mb = MemBlock.Reference(b);
                sab.Send(mb);
                Assert.IsTrue(mdha.Contains(mb), "mdhb Contains " + i);

                b = new byte[128];
                rand.NextBytes(b);
                mb = MemBlock.Reference(b);
                sab.Send(mb);
                Assert.IsTrue(mdha.Contains(mb), "mdha Contains " + i);
            }

            for (int i = 250; i < 500; i++)
            {
                int ij = (250 % 3) + 1;
                SecurityOverlord so  = CreateInvalidSO("valid" + i, ij);
                MockSender       msa = new MockSender(null, null, so, 0);
                MockSender       msb = new MockSender(msa, null, so0, 0);
                msa.ReturnPath = msb;

                SecurityAssociation sab = so.CreateSecurityAssociation(msb, true);
                SecurityAssociation saa = so0.CreateSecurityAssociation(msa, true);
                Assert.AreEqual(sab.State, SecurityAssociation.SAState.Waiting, "sab should be waiting! " + i);
                Assert.AreEqual(saa.State, SecurityAssociation.SAState.Waiting, "saa should be waiting! " + i);
            }

            // create ~250 valid SAs for one guy...
            for (int i = 500; i < 750; i++)
            {
                SecurityOverlord so  = CreateValidSO("valid" + i);
                MockSender       msa = new MockSender(null, null, so, 0);
                MockSender       msb = new MockSender(msa, null, so0, 0);
                msa.ReturnPath = msb;

                SecurityAssociation sab = so.CreateSecurityAssociation(msb, true);
                Assert.AreEqual(sab.State, SecurityAssociation.SAState.Active, "sab should be active! " + i);
                SecurityAssociation saa = so0.CreateSecurityAssociation(msa, true);
                Assert.AreEqual(saa.State, SecurityAssociation.SAState.Active, "saa should be active! " + i);

                MockDataHandler mdha = new MockDataHandler();
                saa.Subscribe(mdha, null);
                MockDataHandler mdhb = new MockDataHandler();
                sab.Subscribe(mdhb, null);

                Random rand = new Random();
                byte[] b    = new byte[128];
                rand.NextBytes(b);
                MemBlock mb = MemBlock.Reference(b);
                sab.Send(mb);
                Assert.IsTrue(mdha.Contains(mb), "mdhb Contains " + i);

                b = new byte[128];
                rand.NextBytes(b);
                mb = MemBlock.Reference(b);
                sab.Send(mb);
                Assert.IsTrue(mdha.Contains(mb), "mdha Contains " + i);
            }

            Random randr = new Random();

            byte[] br = new byte[128];
            randr.NextBytes(br);
            MemBlock mbr = MemBlock.Reference(br);

            foreach (Dictionary <ISender, SecurityAssociation> sender_to_sa in so0.SPI.Values)
            {
                foreach (SecurityAssociation sa in sender_to_sa.Values)
                {
                    sa.Send(mbr);
                }
            }

            Thread.Sleep(SecurityAssociation.TIMEOUT * 5);
            so0.SAGarbageCollect();
            Assert.AreEqual(500, so0.SACount, "Count!");

            so0.SAGarbageCollect();
            Assert.AreEqual(0, so0.SACount, "Count!");

            t.Dispose();
        }
    protected SecurityOverlord CreateInvalidSO(string name, int level) {
      if(rsa == null) {
        rsa = new RSACryptoServiceProvider();
        byte[] blob = rsa.ExportCspBlob(false);
        RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
        rsa_pub.ImportCspBlob(blob);
        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
            "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
            "brunet:node:abcdefghijklmnopqrs");
        Certificate cert = cm.Sign(cm, rsa);
        x509 = cert.X509;
      }

      CertificateHandler ch = new CertificateHandler();
      if(level == 2 || level == 0) {
        ch.AddCACertificate(x509);
      }
      if(level == 3 || level == 0) {
        ch.AddSignedCertificate(x509);
      }
      ReqrepManager rrm = new ReqrepManager("so" + name);
      _timeout += rrm.TimeoutChecker;
      SecurityOverlord so = new SecurityOverlord(rsa_safe, rrm, ch);
      so.AnnounceSA += AnnounceSA;
      RoutingDataHandler rdh = new RoutingDataHandler();
      rrm.Subscribe(so, null);
      so.Subscribe(rdh, null);
      rdh.Subscribe(rrm, null);
      return so;
    }