Beispiel #1
0
        /**
         * Creates a self-sign X509 certificate based on user parameters.
         * @param uid unique user identifier.
         * @param name user name.
         * @param pcid PC identifier.
         * @param version SocialVPN version.
         * @param country user country.
         * @param certDir the path for the certificate directory
         * @param keyPath the path to the private RSA key
         * @return X509 Certificate.
         */
        public static Certificate CreateCertificate(string uid, string name,
                                                    string pcid, string version,
                                                    string country,
                                                    string address,
                                                    string certDir,
                                                    string keyPath)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            CertificateMaker         cm  = new CertificateMaker(country, version, pcid,
                                                                name, uid, rsa, address);
            Certificate cert = cm.Sign(cm, rsa);

            string lc_path = Path.Combine(certDir, "lc.cert");
            string ca_path = Path.Combine(certDir, "ca.cert");

            if (!Directory.Exists(certDir))
            {
                Directory.CreateDirectory(certDir);
            }
            WriteToFile(rsa.ExportCspBlob(true), keyPath);
            WriteToFile(cert.X509.RawData, lc_path);
            WriteToFile(cert.X509.RawData, ca_path);

            return(cert);
        }
Beispiel #2
0
        public void SetUid(string uid, string pcid)
        {
            if (_user.Value != null)
            {
                return;
            }

            string country = "US";
            string version = "0.4";
            string name    = uid;

            if (pcid == null || pcid == String.Empty)
            {
                pcid = System.Net.Dns.GetHostName();
            }

            CertificateMaker cm = new CertificateMaker(country, version, pcid,
                                                       name, uid, _rsa,
                                                       this.Address);
            Certificate cert        = cm.Sign(cm, _rsa);
            string      certificate = Convert.ToBase64String(cert.X509.RawData);
            SocialUser  user        = new SocialUser(certificate, this.IP, null);

            _user.Value = user;

            Bso.CertificateHandler.AddCACertificate(user.X509);
            Bso.CertificateHandler.AddSignedCertificate(user.X509);
        }
        private void buttonCreateCertificate_Click(object sender, EventArgs e)
        {
            if (m_opt.Validate())
            {
                using (var dlg = new SaveFileDialog())
                {
                    dlg.Filter = "Key File|*.pfx";
                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        using (var cert = CertificateMaker.GenerateSelfSignedCertificate(m_opt.KeyType, m_opt.CommonName, m_opt.StartDate, m_opt.EndDate))
                        {
                            File.WriteAllBytes(dlg.FileName, cert.Export(X509ContentType.Pkcs12, txtPassword.Text));
                            CertFile = Path.ChangeExtension(dlg.FileName, ".cer");
                            File.WriteAllBytes(CertFile, cert.Export(X509ContentType.Cert));
                        }
                        MessageBox.Show("Done!");
                    }
                }

                DialogResult = DialogResult.OK;
                Close();
            }
            else
            {
                MessageBox.Show("Invalid");
            }
        }
        protected X509Certificate CreateCert(string username)
        {
            RSACryptoServiceProvider pub = new RSACryptoServiceProvider();
            CertificateMaker         cm  = new CertificateMaker("US", "UFL", "ACIS", username,
                                                                "*****@*****.**", pub, _remote_id);

            return(cm.Sign(_ca_cert, _private_key).X509);
        }
        public GroupCertificateVerificationTest()
        {
            _private_key = new RSACryptoServiceProvider(512);
            byte[] blob = _private_key.ExportCspBlob(false);
            RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();

            rsa_pub.ImportCspBlob(blob);
            CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
                                                       "*****@*****.**", rsa_pub, "davidiw");

            _ca_cert = cm.Sign(cm, _private_key);
        }
Beispiel #6
0
        static DtlsOverlordClientServer()
        {
            _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;
        }
Beispiel #7
0
        public Simulator(Parameters parameters, bool do_not_start)
        {
            _parameters         = parameters;
            StartingNetworkSize = parameters.Size;
            CurrentNetworkSize  = 0;
            Nodes               = new SortedList <Address, NodeMapping>();
            TakenIDs            = new SortedList <int, NodeMapping>();
            SimBroadcastHandler = new SimpleFilter();

            if (parameters.Seed != -1)
            {
                _rand = new Random(parameters.Seed);
            }
            else
            {
                _rand = new Random();
            }

            BrunetNamespace = "testing" + _rand.Next();
            _broken         = parameters.Broken;
            _secure_edges   = parameters.SecureEdges;
            _secure_senders = parameters.SecureSenders;
            _pathing        = parameters.Pathing;
            _dtls           = parameters.Dtls;
            if (_secure_edges || _secure_senders)
            {
                _se_key = new RSACryptoServiceProvider();
                byte[] blob = _se_key.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, _se_key);
                _ca_cert = cert;
            }

            if (parameters.LatencyMap != null)
            {
                SimulationEdgeListener.LatencyMap = parameters.LatencyMap;
            }

            _start = parameters.Evaluation;
            if (!do_not_start)
            {
                Start();
            }
            _start = false;
        }
Beispiel #8
0
        public GroupVPNClient(string username, string group, string secret,
                              string server_uri, string node_address, RSACryptoServiceProvider public_key)
        {
            _username = username;
            _group    = group;
            _secret   = secret;
            _state    = States.Waiting;

            _group_vpn     = (IGroupVPNServer)XmlRpcProxyGen.Create(typeof(IGroupVPNServer));
            _group_vpn.Url = server_uri;

            CertificateMaker cm = new CertificateMaker(string.Empty, string.Empty,
                                                       string.Empty, string.Empty, string.Empty, public_key, node_address);

            _unsigned_cert = cm.UnsignedData;
        }
Beispiel #9
0
        public Simulator(Parameters parameters)
        {
            StartingNetworkSize = parameters.Size;
            CurrentNetworkSize  = 0;
            Nodes    = new SortedList();
            TakenIDs = new SortedList();

            if (parameters.Seed != -1)
            {
                _rand = new Random(parameters.Seed);
            }
            else
            {
                _rand = new Random(parameters.Seed);
            }

            BrunetNamespace = "testing" + _rand.Next();
            _broken         = 0;
            _secure_edges   = parameters.SecureEdges;
            _secure_senders = parameters.SecureSenders;
            if (_secure_edges || _secure_senders)
            {
                _se_key = new RSACryptoServiceProvider();
                byte[] blob = _se_key.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, _se_key);
                _ca_cert = cert;
            }

            if (parameters.LatencyMap != null)
            {
                SimulationEdgeListener.LatencyMap = parameters.LatencyMap;
            }

            for (int i = 0; i < parameters.Size; i++)
            {
                AddNode();
            }
        }
Beispiel #10
0
        public void ValidityTest()
        {
            var osch = new OpenSslCertificateHandler();
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);

            byte[] blob = rsa.ExportCspBlob(false);
            RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();

            rsa_pub.ImportCspBlob(blob);
            string           ID = "brunet:node:PXYSWDL5SZDHDDXJKZCLFENOP2KZDMBU";
            CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
                                                       "*****@*****.**", rsa_pub, ID);
            Certificate cert_0 = cm.Sign(cm, rsa);

            osch.AddSignedCertificate(cert_0.X509);
            osch.AddCACertificate(cert_0.X509);
            var ocert = OpenSslCertificateHandler.OpenSslX509ToMonoX509(osch.LocalCertificate);

            Assert.AreEqual(cert_0.X509.RawData, ocert.RawData, "local check");
            Assert.IsTrue(CertificateHandler.Verify(ocert, ID), "Valid");
        }
Beispiel #11
0
        protected PeerSecOverlord 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);
            }
            Random        rand = new Random();
            ReqrepManager rrm  = new ReqrepManager("so" + name + rand.Next());

            _timeout += rrm.TimeoutChecker;

            PeerSecOverlord so = new PeerSecOverlord(rsa_safe, ch, rrm);

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

            rrm.Subscribe(so, null);
            so.Subscribe(rdh, null);
            rdh.Subscribe(rrm, null);
            return(so);
        }
 public void ValidityTest() {
   CertificateHandler ch = new CertificateHandler();
   RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
   byte[] blob = rsa.ExportCspBlob(false);
   RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
   rsa_pub.ImportCspBlob(blob);
   string ID = "brunet:node:PXYSWDL5SZDHDDXJKZCLFENOP2KZDMBU";
   CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
       "*****@*****.**", rsa_pub, ID);
   Certificate cert_0 = cm.Sign(cm, rsa);
   ch.AddSignedCertificate(cert_0.X509);
   ch.AddCACertificate(cert_0.X509);
   rsa = new RSACryptoServiceProvider(1024);
   rsa_pub.ImportCspBlob(rsa.ExportCspBlob(false));
   cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
       "*****@*****.**", rsa_pub, ID);
   Certificate cert_1 = cm.Sign(cm, rsa);
   Assert.IsTrue(ch.Verify(cert_0.X509, ID), "Valid");
   bool success = false;
   try {
     success = ch.Verify(cert_1.X509, ID);
   } catch { }
   Assert.IsTrue(!success, "Valid cert2");
 }
Beispiel #13
0
        protected virtual StructuredNode PrepareNode(int id, AHAddress address)
        {
            if (TakenIDs.ContainsKey(id))
            {
                throw new Exception("ID already taken");
            }

            StructuredNode node = new StructuredNode(address, BrunetNamespace);

            NodeMapping nm = new NodeMapping();

            nm.ID        = id;
            TakenIDs[id] = nm;
            nm.Node      = node;
            Nodes.Add((Address)address, nm);

            EdgeListener el = CreateEdgeListener(nm.ID);

            if (_secure_edges || _secure_senders)
            {
                byte[] blob = _se_key.ExportCspBlob(true);
                RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
                rsa_copy.ImportCspBlob(blob);

                string           username = address.ToString().Replace('=', '0');
                CertificateMaker cm       = new CertificateMaker("United States", "UFL",
                                                                 "ACIS", username, "*****@*****.**", rsa_copy,
                                                                 address.ToString());
                Certificate cert = cm.Sign(_ca_cert, _se_key);

                CertificateHandler ch = null;
                if (_dtls)
                {
                    ch = new OpenSslCertificateHandler();
                }
                else
                {
                    ch = new CertificateHandler();
                }
                ch.AddCACertificate(_ca_cert.X509);
                ch.AddSignedCertificate(cert.X509);

                if (_dtls)
                {
                    nm.SO = new DtlsOverlord(rsa_copy, ch, PeerSecOverlord.Security);
                }
                else
                {
                    nm.Sso = new SymphonySecurityOverlord(node, rsa_copy, ch, node.Rrm);
                    nm.SO  = nm.Sso;
                }

                var brh = new BroadcastRevocationHandler(_ca_cert, nm.SO);
                node.GetTypeSource(BroadcastRevocationHandler.PType).Subscribe(brh, null);
                ch.AddCertificateVerification(brh);
                nm.SO.Subscribe(node, null);
                node.GetTypeSource(PeerSecOverlord.Security).Subscribe(nm.SO, null);
            }

            if (_pathing)
            {
                nm.PathEM = new PathELManager(el, nm.Node);
                nm.PathEM.Start();
                el = nm.PathEM.CreatePath();
                PType path_p = PType.Protocol.Pathing;
                nm.Node.DemuxHandler.GetTypeSource(path_p).Subscribe(nm.PathEM, path_p);
            }

            if (_secure_edges)
            {
                node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                el = new SecureEdgeListener(el, nm.SO);
            }

            node.AddEdgeListener(el);

            if (!_start)
            {
                node.RemoteTAs = GetRemoteTAs();
            }

            IRelayOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                ito = new NCRelayOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleRelayOverlap();
            }

            if (_broken != 0)
            {
                el = new Relay.RelayEdgeListener(node, ito);
                if (_secure_edges)
                {
                    el = new SecureEdgeListener(el, nm.SO);
                }
                node.AddEdgeListener(el);
            }

            BroadcastHandler bhandler = new BroadcastHandler(node as StructuredNode);

            node.DemuxHandler.GetTypeSource(BroadcastSender.PType).Subscribe(bhandler, null);
            node.DemuxHandler.GetTypeSource(SimBroadcastPType).Subscribe(SimBroadcastHandler, null);

            // Enables Dht data store
            new TableServer(node);
            nm.Dht      = new Dht(node, 3, 20);
            nm.DhtProxy = new RpcDhtProxy(nm.Dht, node);
            return(node);
        }
Beispiel #14
0
    /// <summary>Creates an ApplicationNode and prepares it for connection to
    /// the overlay.  For historical reasons it is linked to _node, _dht,
    /// _rpc_dht, and _bso.</summary>
    public virtual ApplicationNode CreateNode(NodeConfig node_config) {
      // Get a Node ID for the new Node
      AHAddress address = null;
      try {
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
      } catch {
        address = Utils.GenerateAHAddress();
      }

      // Create the Node state
      StructuredNode node = new StructuredNode(address, node_config.BrunetNamespace);
      _shutdown.OnExit += node.Disconnect;
      IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind);

      SecurityOverlord so = null;
      // Enable Security if requested
      if(node_config.Security.Enabled) {
        if(node_config.Security.SelfSignedCertificates) {
          SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
              SecurityPolicy.DefaultAuthenticator, true);
        }

        byte[] blob = null;
        using(FileStream fs = File.Open(node_config.Security.KeyPath, FileMode.Open)) {
          blob = new byte[fs.Length];
          fs.Read(blob, 0, blob.Length);
        }

        RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
        rsa_private.ImportCspBlob(blob);

        CertificateHandler ch = null;
        if(node_config.Security.Dtls) {
          ch = new OpenSslCertificateHandler(node_config.Security.CertificatePath,
              address.ToString());
        } else {
          ch = new CertificateHandler(node_config.Security.CertificatePath,
              address.ToString());
        }


        if(node_config.Security.SecureEdges) {
          node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        }

        // A hack to enable a test for security that doesn't require each peer
        // to exchange certificates
        if(node_config.Security.TestEnable) {
          blob = rsa_private.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 cacert = cm.Sign(cm, rsa_private);

          cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              address.ToString());
          Certificate cert = cm.Sign(cacert, rsa_private);
          ch.AddCACertificate(cacert.X509);
          ch.AddSignedCertificate(cert.X509);
        }

        if(node_config.Security.Dtls) {
          OpenSslCertificateHandler ssl_ch = ch as OpenSslCertificateHandler;
          so = new DtlsOverlord(rsa_private, ssl_ch, new PType(20));
          node.GetTypeSource(new PType(20)).Subscribe(so, null);
        } else {
          so = new SymphonySecurityOverlord(node, rsa_private, ch, node.Rrm);
          node.GetTypeSource(PeerSecOverlord.Security).Subscribe(so, null);
        }
        so.Subscribe(node, null);
      }

      // Add Dht
      new TableServer(node);
      IDht dht = new Dht(node, 3, 20);
      RpcDhtProxy dht_proxy = new RpcDhtProxy(dht, node);

      // Setup Vivaldi if requested
      IRelayOverlap ito = null;
      NCService ncservice = null;
      if(node_config.NCService.Enabled) {
        ncservice = new NCService(node, node_config.NCService.Checkpoint);

        if (node_config.NCService.OptimizeShortcuts) {
          node.Ssco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
        }
        ito = new NCRelayOverlap(ncservice);
      } else {
        ito = new SimpleRelayOverlap();
      }

      // Create the ApplicationNode
      ApplicationNode app_node = new ApplicationNode(node, dht, dht_proxy, ncservice, so);

      // Add Edge listeners
      EdgeListener el = null;
      foreach(NodeConfig.EdgeListener item in node_config.EdgeListeners) {
        el = CreateEdgeListener(item, app_node, addresses);
        if(node_config.Security.SecureEdgesEnabled) {
          el = new SecureEdgeListener(el, so);
        }
        node.AddEdgeListener(el);
      }

      // Create the tunnel and potentially wrap it in a SecureEL
      el = new Relay.RelayEdgeListener(node, ito);
      if(node_config.Security.SecureEdgesEnabled) {
        el = new SecureEdgeListener(el, so);
      }
      node.AddEdgeListener(el);

      List<TransportAddress> RemoteTAs = null;
      if(node_config.RemoteTAs != null) {
        RemoteTAs = new List<TransportAddress>();
        foreach(String ta in node_config.RemoteTAs) {
          RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
        }
        node.RemoteTAs = RemoteTAs;
      }

      // Add XmlRpc
      if(node_config.XmlRpcManager.Enabled) {
        if(_xrm == null) {
          _xrm = new XmlRpcManagerServer(node_config.XmlRpcManager.Port);
        }
        _xrm.Add(node, GetXmlRpcUri(app_node));
        new RpcDht(dht, node);
      }

      if(node_config.PrivateNodeConfig != null &&
          node_config.PrivateNodeConfig.Enabled)
      {
        CreatePrivateNode(app_node, NodeConfig.GetPrivateNodeConfig(node_config));
      }
      return app_node;
    }
Beispiel #15
0
        public static int Main(string[] args)
        {
            Dictionary <string, string> arguments = ArgumentsParser.parse(args);

            if (arguments.ContainsKey("/help"))
            {
                PrintHelp();
                return(0);
            }

            string wsusConfig = (string)Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\", "WUServer", null);

            string wsusHost = null;

            if (wsusConfig != null)
            {
                Uri wsusURI = new Uri(wsusConfig);
                wsusHost = wsusURI.Host;

                X509Certificate2 cert = null;
                if (wsusURI.Scheme == "https" && arguments.ContainsKey("/enabletls"))
                {
                    Console.WriteLine("The WSUS Server is using HTTPS. Adding a self-signed certificate to store");
                    cert = CertificateMaker.MakeCertificate(wsusHost);
                    Console.WriteLine("Prompting user to add the certificate. Please wait.");
                    CertificateMaker.AddToTrustStore(cert);
                }
                else if (wsusURI.Scheme == "https")
                {
                    Console.WriteLine("The WSUS Server is using HTTPS and we are not configured to accept TLS connections.");
                    Console.WriteLine("Exiting now.");
                    return(0);
                }

                Console.WriteLine(String.Format("Detected WSUS Server - {0}", wsusHost));

                byte[] payloadFile = File.ReadAllBytes(arguments["/exe"]);

                HttpServer serv = null;
                if (arguments.ContainsKey("/downloadport"))
                {
                    // We are configured to deliver the payload via a self-hosted server. Lets start it
                    serv = new HttpServer(int.Parse(arguments["/downloadport"]), payloadFile);
                    serv.Start();
                }

                using (WsusProxy proxy = new WsusProxy(wsusHost, payloadFile, Path.GetFileName(arguments["/exe"]), arguments["/command"], arguments.ContainsKey("/debug"), (arguments.ContainsKey("/downloadport") ? String.Format("localhost:{0}", arguments["/downloadport"]) : null), cert))
                {
                    proxy.Start(int.Parse(arguments["/proxyport"]));

                    Console.WriteLine("Hit any key to exit..");

                    if (arguments.ContainsKey("/autoinstall"))
                    {
                        WindowsUpdateLauncher.StartUpdates();
                    }

                    Console.WriteLine();
                    Console.Read();
                }

                // We advice people to cleanup the cert that we added into the store
                if (wsusURI.Scheme == "https" && arguments.ContainsKey("/enabletls"))
                {
                    Console.WriteLine("Consider removing the self-signed certificate from the store (Warning: it will prompt the user again).");
                }

                // We cleanup the payload delivery server just in case (if any)
                if (serv != null)
                {
                    serv.Stop();
                }
            }
            else
            {
                Console.WriteLine("No WSUS Server detected.");
                Console.WriteLine("Stopping now.");
            }
            return(0);
        }
Beispiel #16
0
    public void SetUid(string uid, string pcid) {

      if(_user.Value != null) {
        return;
      }

      string country = "US";
      string version = "0.4";
      string name = uid;

      if(pcid == null || pcid == String.Empty) {
        pcid = System.Net.Dns.GetHostName();
      }

      CertificateMaker cm = new CertificateMaker(country, version, pcid,
                                                 name, uid, _rsa, 
                                                 this.Address);
      Certificate cert = cm.Sign(cm, _rsa);
      string certificate = Convert.ToBase64String(cert.X509.RawData);
      SocialUser user = new SocialUser(certificate, this.IP, null);
      _user.Value = user;

      Bso.CertificateHandler.AddCACertificate(user.X509);
      Bso.CertificateHandler.AddSignedCertificate(user.X509);
    }
Beispiel #17
0
    /// <summary>Creates a Brunet.Node, the resulting node will be available in
    /// the class as _node.</summary>
    /// <remarks>The steps to creating a node are first constructing it with a
    /// namespace, optionally adding local ip addresses to bind to, specifying
    /// local end points, specifying remote end points, and finally registering
    /// the dht.</remarks>
    public virtual void CreateNode() {
      AHAddress address = null;
      try {
        address = (AHAddress) AddressParser.Parse(_node_config.NodeAddress);
      } catch {
        address = Utils.GenerateAHAddress();
      }

      _node = new StructuredNode(address, _node_config.BrunetNamespace);
      IEnumerable addresses = IPAddresses.GetIPAddresses(_node_config.DevicesToBind);

      if(_node_config.Security.Enabled) {
        if(_node_config.Security.SelfSignedCertificates) {
          SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
              SecurityPolicy.DefaultAuthenticator, true);
        }

        byte[] blob = null;
        using(FileStream fs = File.Open(_node_config.Security.KeyPath, FileMode.Open)) {
          blob = new byte[fs.Length];
          fs.Read(blob, 0, blob.Length);
        }

        RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
        rsa_private.ImportCspBlob(blob);

        CertificateHandler ch = new CertificateHandler(_node_config.Security.CertificatePath);
        _bso = new ProtocolSecurityOverlord(_node, rsa_private, _node.Rrm, ch);
        _bso.Subscribe(_node, null);

        _node.GetTypeSource(SecurityOverlord.Security).Subscribe(_bso, null);
        _node.HeartBeatEvent += _bso.Heartbeat;

        if(_node_config.Security.TestEnable) {
          blob = rsa_private.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 cacert = cm.Sign(cm, rsa_private);

          cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              address.ToString());
          Certificate cert = cm.Sign(cacert, rsa_private);
          ch.AddCACertificate(cacert.X509);
          ch.AddSignedCertificate(cert.X509);
        }
      }

      EdgeListener el = null;
      foreach(NodeConfig.EdgeListener item in _node_config.EdgeListeners) {
        int port = item.port;
        if(item.type == "tcp") {
          try {
            el = new TcpEdgeListener(port, addresses);
          }
          catch {
            el = new TcpEdgeListener(0, addresses);
          }
        } else if(item.type == "udp") {
          try {
            el = new UdpEdgeListener(port, addresses);
          }
          catch {
            el = new UdpEdgeListener(0, addresses);
          }
        } else if(item.type == "function") {
          port = port == 0 ? (new Random()).Next(1024, 65535) : port;
          el = new FunctionEdgeListener(port, 0, null);
        } else {
          throw new Exception("Unrecognized transport: " + item.type);
        }
        if(_node_config.Security.SecureEdgesEnabled) {
          el = new SecureEdgeListener(el, _bso);
        }
        _node.AddEdgeListener(el);
      }

      ArrayList RemoteTAs = null;
      if(_node_config.RemoteTAs != null) {
        RemoteTAs = new ArrayList();
        foreach(String ta in _node_config.RemoteTAs) {
          RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
        }
        _node.RemoteTAs = RemoteTAs;
      }

      ITunnelOverlap ito = null;
      /*
      if(_node_config.NCService.Enabled) {
        _ncservice = new NCService(_node, _node_config.NCService.Checkpoint);

        if (_node_config.NCService.OptimizeShortcuts) {
          _node.Ssco.TargetSelector = new VivaldiTargetSelector(_node, _ncservice);
        }
        ito = new NCTunnelOverlap(_ncservice);
      } else {
        ito = new SimpleTunnelOverlap();
      }
      */
      el = new Tunnel.TunnelEdgeListener(_node, ito);
      if(_node_config.Security.SecureEdgesEnabled) {
        _node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        el = new SecureEdgeListener(el, _bso);
      }
      _node.AddEdgeListener(el);


      new TableServer(_node);
      _dht = new Dht(_node, 3, 20);
      _dht_proxy = new RpcDhtProxy(_dht, _node);
    }
Beispiel #18
0
    public void AddBadLocalCert() {
      CertificateHandler ch = new CertificateHandler("certs", "12345");
      RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
      byte[] blob = rsa.ExportCspBlob(false);
      RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
      rsa_pub.ImportCspBlob(blob);
      string ID = "brunet:node:PXYSWDL5SZDHDDXJKZCLFENOP2KZDMBU";
      CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
          "*****@*****.**", rsa_pub, ID);
      Certificate cert_0 = cm.Sign(cm, rsa);
      ch.AddCACertificate(cert_0.X509);
      try {
        ch.AddSignedCertificate(cert_0.X509);
        Assert.IsTrue(false, "Shouldn't add this certificate!");
      } catch {
      }

      CertificateMaker cm0 = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
          "*****@*****.**", rsa_pub, "12345");
      Certificate cert_1 = cm0.Sign(cm, rsa);
      ch.AddSignedCertificate(cert_1.X509);
    }
 protected X509Certificate CreateCert(string username)
 {
     RSACryptoServiceProvider pub = new RSACryptoServiceProvider();
       CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", username,
       "*****@*****.**", pub, _remote_id);
       return cm.Sign(_ca_cert, _private_key).X509;
 }
 public static void SecureStartup() {
   if(SEKey != null) {
     return;
   }
   SEKey = new RSACryptoServiceProvider();
   byte[] blob = SEKey.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, SEKey);
   CACert = cert;
 }
Beispiel #21
0
    /**
    <summary>Creates a Brunet.Node, the resulting node will be available in
    the class as _node.</summary>
    <remarks>The steps to creating a node are first constructing it with a
    namespace, optionally adding local ip addresses to bind to, specifying
    local end points, specifying remote end points, and finally registering
    the dht.</remarks>
    */
    public virtual void CreateNode(string type) {
      NodeConfig node_config = null;
      StructuredNode current_node = null;
      AHAddress address = null;
      ProtocolSecurityOverlord bso;

      if (type == "cache") {
        node_config = _c_node_config; //Node configuration file: the description of service that node provides
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
        current_node = new StructuredNode(address, node_config.BrunetNamespace); // DeetooNode consists of two Structured Nodes
        bso = _c_bso;
      }
      else if ( type == "query" ) {
        node_config = _q_node_config;
        address = (AHAddress) AddressParser.Parse(node_config.NodeAddress);
        current_node = new StructuredNode(address, node_config.BrunetNamespace);
        bso = _q_bso;
      }
      else {
        throw new Exception("Unrecognized node type: " + type);
      }
      IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind);

      if(node_config.Security.Enabled) {
        if(node_config.Security.SelfSignedCertificates) {
          SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
              SecurityPolicy.DefaultAuthenticator, true);
        }

        byte[] blob = null;
        using(FileStream fs = File.Open(node_config.Security.KeyPath, FileMode.Open)) {
          blob = new byte[fs.Length];
          fs.Read(blob, 0, blob.Length);
        }

        RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
        rsa_private.ImportCspBlob(blob);

        CertificateHandler ch = new CertificateHandler(node_config.Security.CertificatePath);
        bso = new ProtocolSecurityOverlord(current_node, rsa_private, current_node.Rrm, ch);
        bso.Subscribe(current_node, null);

        current_node.GetTypeSource(SecurityOverlord.Security).Subscribe(bso, null);
        current_node.HeartBeatEvent += bso.Heartbeat;

        if(node_config.Security.TestEnable) {
          blob = rsa_private.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 cacert = cm.Sign(cm, rsa_private);

          cm = new CertificateMaker("United States", "UFL", 
              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
              address.ToString());
          Certificate cert = cm.Sign(cacert, rsa_private);
          ch.AddCACertificate(cacert.X509);
          ch.AddSignedCertificate(cert.X509);
        }
      }

      EdgeListener el = null;
      foreach(NodeConfig.EdgeListener item in node_config.EdgeListeners) {
        int port = item.port;
        if (item.type =="tcp") {
          try {
            el = new TcpEdgeListener(port, addresses);
          }
          catch {
            el = new TcpEdgeListener(0, addresses);
          }
        }
        else if (item.type == "udp") {
          try {
            el = new UdpEdgeListener(port, addresses);
          }
          catch {
            el = new UdpEdgeListener(0, addresses);
          }
        }
        else if(item.type == "function") {
          port = port == 0 ? (new Random()).Next(1024, 65535) : port;
          el = new FunctionEdgeListener(port, 0, null);
        }
        else {
          throw new Exception("Unrecognized transport: " + item.type);
        }
        if (node_config.Security.SecureEdgesEnabled) {
          el = new SecureEdgeListener(el, bso);
        }
        current_node.AddEdgeListener(el);
      }

      ArrayList RemoteTAs = null;
      if(node_config.RemoteTAs != null) {
        RemoteTAs = new ArrayList();
        foreach(String ta in node_config.RemoteTAs) {
          RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
        }
        current_node.RemoteTAs = RemoteTAs;
      }
      ITunnelOverlap ito = null;
      ito = new SimpleTunnelOverlap();

      el = new Tunnel.TunnelEdgeListener(current_node, ito);
      if(node_config.Security.SecureEdgesEnabled) {
        current_node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
        el = new SecureEdgeListener(el, bso);
      }      
      current_node.AddEdgeListener(el);

      new TableServer(current_node);
      if (type == "cache") {
        _c_dht = new Dht(current_node, 3, 20);
        _c_dht_proxy = new RpcDhtProxy(_c_dht, current_node);
        _cs = new CacheList(current_node);
	//_cll = new ClusterList(current_node);
        //current_node.MapReduce.SubscribeTask(new MapReduceClusterCache(current_node, _cll));
        current_node.MapReduce.SubscribeTask(new MapReduceCache(current_node,_cs));
        Console.WriteLine("MapReduceCacheTask is subscribed at {0}", current_node.Address);
        _c_node = current_node;
      }
      else {
        _q_dht = new Dht(current_node, 3, 20);
        _q_dht_proxy = new RpcDhtProxy(_c_dht, current_node);
        CacheList q_cs = new CacheList(current_node);
        //current_node.MapReduce.SubscribeTask(new MapReduceClusterQuery(current_node, _cll));
        current_node.MapReduce.SubscribeTask(new MapReduceQuery(current_node,_cs));
        Console.WriteLine("MapReduceQueryTask is subscribed at {0}", current_node.Address);
        _q_node = current_node;
      }
    }
    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;
    }
Beispiel #23
0
        protected virtual StructuredNode PrepareNode(int id, AHAddress address)
        {
            if (TakenIDs.Contains(id))
            {
                throw new Exception("ID already taken");
            }

            StructuredNode node = new StructuredNode(address, BrunetNamespace);

            NodeMapping nm = new NodeMapping();

            TakenIDs[id] = nm.ID = id;
            nm.Node      = node;
            Nodes.Add((Address)address, nm);

            EdgeListener el = CreateEdgeListener(nm.ID);

            if (_secure_edges || _secure_senders)
            {
                byte[] blob = _se_key.ExportCspBlob(true);
                RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
                rsa_copy.ImportCspBlob(blob);

                CertificateMaker cm = new CertificateMaker("United States", "UFL",
                                                           "ACIS", "David Wolinsky", "*****@*****.**", rsa_copy,
                                                           address.ToString());
                Certificate cert = cm.Sign(_ca_cert, _se_key);

                CertificateHandler ch = new CertificateHandler();
                ch.AddCACertificate(_ca_cert.X509);
                ch.AddSignedCertificate(cert.X509);

                ProtocolSecurityOverlord so = new ProtocolSecurityOverlord(node, rsa_copy, node.Rrm, ch);
                so.Subscribe(node, null);
                node.GetTypeSource(SecurityOverlord.Security).Subscribe(so, null);
                nm.BSO = so;
                node.HeartBeatEvent += so.Heartbeat;
            }

            if (_secure_edges)
            {
                node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                el = new SecureEdgeListener(el, nm.BSO);
            }

            node.AddEdgeListener(el);

            node.RemoteTAs = GetRemoteTAs();

            ITunnelOverlap ito = null;

            if (NCEnable)
            {
                nm.NCService = new NCService(node, new Point());
// My evaluations show that when this is enabled the system sucks
//        (node as StructuredNode).Sco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                ito = new NCTunnelOverlap(nm.NCService);
            }
            else
            {
                ito = new SimpleTunnelOverlap();
            }

            if (_broken != 0)
            {
                el = new Tunnel.TunnelEdgeListener(node, ito);
                node.AddEdgeListener(el);
            }
            // Enables Dht data store
            new TableServer(node);
            return(node);
        }
Beispiel #24
0
        /// <summary>Creates an ApplicationNode and prepares it for connection to
        /// the overlay.  For historical reasons it is linked to _node, _dht,
        /// _rpc_dht, and _bso.</summary>
        public virtual ApplicationNode CreateNode(NodeConfig node_config)
        {
            // Get a Node ID for the new Node
            AHAddress address = null;

            try {
                address = (AHAddress)AddressParser.Parse(node_config.NodeAddress);
            } catch {
                address = Utils.GenerateAHAddress();
            }

            // Create the Node state
            StructuredNode node = new StructuredNode(address, node_config.BrunetNamespace);

            _shutdown.OnExit += node.Disconnect;
            IEnumerable addresses = IPAddresses.GetIPAddresses(node_config.DevicesToBind);

            SecurityOverlord so = null;

            // Enable Security if requested
            if (node_config.Security.Enabled)
            {
                if (node_config.Security.SelfSignedCertificates)
                {
                    SecurityPolicy.SetDefaultSecurityPolicy(SecurityPolicy.DefaultEncryptor,
                                                            SecurityPolicy.DefaultAuthenticator, true);
                }

                byte[] blob = null;
                using (FileStream fs = File.Open(node_config.Security.KeyPath, FileMode.Open)) {
                    blob = new byte[fs.Length];
                    fs.Read(blob, 0, blob.Length);
                }

                RSACryptoServiceProvider rsa_private = new RSACryptoServiceProvider();
                rsa_private.ImportCspBlob(blob);

                CertificateHandler ch = null;
                if (node_config.Security.Dtls)
                {
                    ch = new OpenSslCertificateHandler(node_config.Security.CertificatePath,
                                                       address.ToString());
                }
                else
                {
                    ch = new CertificateHandler(node_config.Security.CertificatePath,
                                                address.ToString());
                }


                if (node_config.Security.SecureEdges)
                {
                    node.EdgeVerifyMethod = EdgeVerify.AddressInSubjectAltName;
                }

                // A hack to enable a test for security that doesn't require each peer
                // to exchange certificates
                if (node_config.Security.TestEnable)
                {
                    blob = rsa_private.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 cacert = cm.Sign(cm, rsa_private);

                    cm = new CertificateMaker("United States", "UFL",
                                              "ACIS", "David Wolinsky", "*****@*****.**", rsa_pub,
                                              address.ToString());
                    Certificate cert = cm.Sign(cacert, rsa_private);
                    ch.AddCACertificate(cacert.X509);
                    ch.AddSignedCertificate(cert.X509);
                }

                if (node_config.Security.Dtls)
                {
                    OpenSslCertificateHandler ssl_ch = ch as OpenSslCertificateHandler;
                    so = new DtlsOverlord(rsa_private, ssl_ch, new PType(20));
                    node.GetTypeSource(new PType(20)).Subscribe(so, null);
                }
                else
                {
                    so = new SymphonySecurityOverlord(node, rsa_private, ch, node.Rrm);
                    node.GetTypeSource(PeerSecOverlord.Security).Subscribe(so, null);
                }
                so.Subscribe(node, null);
            }

            // Add Dht
            new TableServer(node);
            IDht        dht       = new Dht(node, 3, 20);
            RpcDhtProxy dht_proxy = new RpcDhtProxy(dht, node);

            // Setup Vivaldi if requested
            IRelayOverlap ito       = null;
            NCService     ncservice = null;

            if (node_config.NCService.Enabled)
            {
                ncservice = new NCService(node, node_config.NCService.Checkpoint);

                if (node_config.NCService.OptimizeShortcuts)
                {
                    node.Ssco.TargetSelector = new VivaldiTargetSelector(node, ncservice);
                }
                ito = new NCRelayOverlap(ncservice);
            }
            else
            {
                ito = new SimpleRelayOverlap();
            }

            // Create the ApplicationNode
            ApplicationNode app_node = new ApplicationNode(node, dht, dht_proxy, ncservice, so);

            // Add Edge listeners
            EdgeListener el = null;

            foreach (NodeConfig.EdgeListener item in node_config.EdgeListeners)
            {
                el = CreateEdgeListener(item, app_node, addresses);
                if (node_config.Security.SecureEdgesEnabled)
                {
                    el = new SecureEdgeListener(el, so);
                }
                node.AddEdgeListener(el);
            }

            // Create the tunnel and potentially wrap it in a SecureEL
            el = new Relay.RelayEdgeListener(node, ito);
            if (node_config.Security.SecureEdgesEnabled)
            {
                el = new SecureEdgeListener(el, so);
            }
            node.AddEdgeListener(el);

            List <TransportAddress> RemoteTAs = null;

            if (node_config.RemoteTAs != null)
            {
                RemoteTAs = new List <TransportAddress>();
                foreach (String ta in node_config.RemoteTAs)
                {
                    RemoteTAs.Add(TransportAddressFactory.CreateInstance(ta));
                }
                node.RemoteTAs = RemoteTAs;
            }

            // Add XmlRpc
            if (node_config.XmlRpcManager.Enabled)
            {
                if (_xrm == null)
                {
                    _xrm = new XmlRpcManagerServer(node_config.XmlRpcManager.Port);
                }
                _xrm.Add(node, GetXmlRpcUri(app_node));
                new RpcDht(dht, node);
            }

            if (node_config.PrivateNodeConfig != null &&
                node_config.PrivateNodeConfig.Enabled)
            {
                CreatePrivateNode(app_node, NodeConfig.GetPrivateNodeConfig(node_config));
            }
            return(app_node);
        }
    public void FindCertificateTest() {
      CertificateHandler ch = new CertificateHandler();

      RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(512);
      byte[] blob = rsa.ExportCspBlob(false);
      RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
      rsa_pub.ImportCspBlob(blob);

      List<MemBlock> supported = new List<MemBlock>();
      List<MemBlock> unsupported = new List<MemBlock>();

      for(int i = 0; i < 20; i++) {
        CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
            "*****@*****.**" + i, rsa_pub, i.ToString());
        Certificate cert = cm.Sign(cm, rsa);
        if(i % 2 == 0) {
          ch.AddCACertificate(cert.X509);
          ch.AddSignedCertificate(cert.X509);
          supported.Add(cert.SerialNumber);
        } else {
          unsupported.Add(cert.SerialNumber);
        }
      }

      Assert.IsNotNull(ch.FindCertificate(supported), "Should find a certificate");

      bool success = false;
      try {
        success = ch.FindCertificate(unsupported) != null;
      } catch { }

      Assert.IsTrue(!success, "Should not find a certificate");

      List<MemBlock> mixed = new List<MemBlock>(unsupported);
      mixed.Insert(4 ,supported[1]);
      Assert.AreEqual(supported[1],
          MemBlock.Reference(ch.FindCertificate(mixed).SerialNumber),
          "Only one supported");
    }
    public void Test() {
      RSACryptoServiceProvider 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");
      Assert.AreEqual("C=United States, O=UFL, OU=ACIS, CN=David Wolinsky, [email protected]", cm.Subject.DN, "DN test 1");
      cm = new CertificateMaker(cm.UnsignedData);
      Assert.AreEqual("C=United States, O=UFL, OU=ACIS, CN=David Wolinsky, [email protected]", cm.Subject.DN, "DN test 2");

      Certificate cert = cm.Sign(cm, rsa);

      Assert.IsTrue(cert.Signature != null, "Signature");
      Assert.AreEqual(cm.Subject.DN, cert.Issuer.DN, "Issuer = Subject");
      Assert.AreEqual("brunet:node:abcdefghijklmnopqrs", cert.NodeAddress , "Node address");

      Mono.Math.BigInteger rsa_pub_bi = new Mono.Math.BigInteger(rsa_pub.ExportCspBlob(false));
      Mono.Math.BigInteger cert_pub_bi = new Mono.Math.BigInteger(cert.PublicKey.ExportCspBlob(false));
      Assert.AreEqual(rsa_pub_bi, cert_pub_bi, "Key");

      SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
      Assert.AreEqual(MemBlock.Reference(cert.SerialNumber),
          MemBlock.Reference(sha1.ComputeHash(cert.UnsignedData)),
          "SerialNumber == hash of unsigned data");

    }
Beispiel #27
0
    public GroupVPNClient(string username, string group, string secret,
        string server_uri, string node_address, RSACryptoServiceProvider public_key)
    {
      _username = username;
      _group = group;
      _secret = secret;
      _state = States.Waiting;

      _group_vpn = (IGroupVPNServer) XmlRpcProxyGen.Create(typeof(IGroupVPNServer));
      _group_vpn.Url = server_uri;

      CertificateMaker cm = new CertificateMaker(string.Empty, string.Empty,
          string.Empty, string.Empty, string.Empty, public_key, node_address);
      _unsigned_cert = cm.UnsignedData;
    }
 public GroupCertificateVerificationTest()
 {
     _private_key = new RSACryptoServiceProvider(512);
       byte[] blob = _private_key.ExportCspBlob(false);
       RSACryptoServiceProvider rsa_pub = new RSACryptoServiceProvider();
       rsa_pub.ImportCspBlob(blob);
       CertificateMaker cm = new CertificateMaker("US", "UFL", "ACIS", "David Wolinsky",
       "*****@*****.**", rsa_pub, "davidiw");
       _ca_cert = cm.Sign(cm, _private_key);
 }
    // adds a node to the pool
    protected static void add_node(bool output) {
      AHAddress address = new AHAddress(new RNGCryptoServiceProvider());
      Node node = new StructuredNode(address, brunet_namespace);
      NodeMapping nm = new NodeMapping();
      nm.Node = node;
      nodes.Add((Address) address, nm);

      nm.Port = TakenPorts.Count;
      while(TakenPorts.Contains(nm.Port)) {
        nm.Port = rand.Next(0, 65535);
      }

      TAAuthorizer auth = null;
      if(broken != 0) {
        auth = new BrokenTAAuth(broken);
      }

      EdgeListener el = new SimulationEdgeListener(nm.Port, 0, auth, true);

      if(secure_edges || secure_senders) {
        byte[] blob = SEKey.ExportCspBlob(true);
        RSACryptoServiceProvider rsa_copy = new RSACryptoServiceProvider();
        rsa_copy.ImportCspBlob(blob);

        CertificateMaker cm = new CertificateMaker("United States", "UFL", 
          "ACIS", "David Wolinsky", "*****@*****.**", rsa_copy,
          address.ToString());
        Certificate cert = cm.Sign(CACert, SEKey);

        CertificateHandler ch = new CertificateHandler();
        ch.AddCACertificate(CACert.X509);
        ch.AddSignedCertificate(cert.X509);

        BrunetSecurityOverlord so = new BrunetSecurityOverlord(node, rsa_copy, node.Rrm, ch);
        so.Subscribe(node, null);
        node.GetTypeSource(SecurityOverlord.Security).Subscribe(so, null);
        nm.BSO = so;
        node.HeartBeatEvent += so.Heartbeat;
      }
      if(secure_edges) {
        el = new SecureEdgeListener(el, nm.BSO);
      }

      node.AddEdgeListener(el);

      if(broken != 0) {
        el = new TunnelEdgeListener(node);
        node.AddEdgeListener(el);
      }

      ArrayList RemoteTAs = new ArrayList();
      for(int i = 0; i < 5 && i < TakenPorts.Count; i++) {
        int rport = (int) TakenPorts.GetByIndex(rand.Next(0, TakenPorts.Count));
        RemoteTAs.Add(TransportAddressFactory.CreateInstance("brunet.function://127.0.0.1:" + rport));
      }
      node.RemoteTAs = RemoteTAs;

      TakenPorts[nm.Port] = nm.Port;

      if(output) {
        Console.WriteLine("Adding: " + nm.Node.Address);
      }
      node.Connect();
      network_size++;
    }