Ejemplo n.º 1
0
        protected void FriendPing(string address)
        {
            Address addr = AddressParser.Parse(address);
            Channel q    = new Channel();

            q.CloseAfterEnqueue();
            q.CloseEvent += delegate(object obj, EventArgs eargs) {
                try {
                    RpcResult res      = (RpcResult)q.Dequeue();
                    string    result   = (string)res.Result;
                    string[]  parts    = result.Split(DELIM);
                    string    dht_key  = parts[0];
                    string    response = parts[1];
                    if (response == "online")
                    {
                        SocialUser friend = _friends[dht_key];
                        friend.Time = DateTime.Now.ToString();
                    }
                    ProtocolLog.Write(SocialLog.SVPNLog, "PING FRIEND REPLY: " +
                                      result);
                } catch (Exception e) {
                    ProtocolLog.Write(SocialLog.SVPNLog, e.Message);
                    ProtocolLog.Write(SocialLog.SVPNLog, "PING FRIEND FAILURE: " +
                                      address);
                }
            };
            ISender sender = new AHExactSender(_node, addr);

            _rpc.Invoke(sender, q, "SocialVPN.FriendPing", _local_user.DhtKey);
        }
Ejemplo n.º 2
0
        public void DrupalNetworkTest()
        {
            string uid     = "*****@*****.**";
            string name    = "Pierre St Juste";
            string pcid    = "pdesktop";
            string version = "SVPN_0.3.0";
            string country = "US";

            SocialUtils.CreateCertificate(uid, name, pcid, version, country,
                                          "address1234", "certificates",
                                          "private_key");

            string cert_path = System.IO.Path.Combine("certificates", "lc.cert");

            byte[]     cert_data = SocialUtils.ReadFileBytes(cert_path);
            SocialUser user      = new SocialUser(cert_data);

            /*
             * DrupalNetwork drupal = new DrupalNetwork(user);
             * drupal.Login("pierre", "stjuste");
             *
             * List<string> friends = drupal.GetFriends();
             *
             * foreach(string friend in friends) {
             * Console.WriteLine(friend);
             * List<string> fprs = drupal.GetFingerprints(friend);
             * foreach(string fpr in fprs) {
             *  Console.WriteLine(friend + " " + fpr);
             * }
             * }
             * drupal.StoreFingerprint();
             * drupal.Logout();
             */
        }
Ejemplo n.º 3
0
        public JabberNetwork(SocialUser user, byte[] certData, 
      BlockingQueue queue, string jabber_port)
        {
            _local_user = user;
              _queue = queue;
              _friends = new Dictionary<string, List<string>>();
              _online = false;
              _auth_pending = false;
              _pres_sent = false;
              _jclient = new JabberClient();

              _jclient.Port = Int32.Parse(jabber_port);
              _jclient.AutoReconnect = 30F;
              _jclient.AutoStartTLS = true;
              _jclient.KeepAlive = 30F;
              _jclient.AutoPresence = false;
              _jclient.AutoRoster = false;
              _jclient.LocalCertificate = null;
              _jclient.Resource = SVPNRESOURCE +
            _local_user.Fingerprint.Substring(0, 10);

              _jclient.OnError += HandleOnError;
              _jclient.OnAuthError += HandleOnAuthError;

            #if SVPN_NUNIT
              _jclient.OnReadText += HandleOnReadText;
              _jclient.OnWriteText += HandleOnWriteText;
            #endif
              _jclient.OnAuthenticate += HandleOnAuthenticate;
              _jclient.OnPresence += HandleOnPresence;
              _jclient.OnIQ += HandleOnIQ;
              _jclient.OnInvalidCertificate += HandleInvalidCert;
        }
Ejemplo n.º 4
0
        /*
         * Removes a friend from socialvpn.
         * @param friend the friend to be removed.
         */
        public void RemoveFriend(SocialUser friend)
        {
            Address addr = AddressParser.Parse(friend.Address);

            _node.ManagedCO.RemoveAddress(addr);
            _rarad.UnregisterMapping(friend.Alias);
            friend.Access = SocialUser.AccessTypes.Block.ToString();
        }
Ejemplo n.º 5
0
        /*
         * Add a friend from socialvpn.
         * @param friend the friend to be added.
         */
        public void AddFriend(SocialUser friend)
        {
            Address addr = AddressParser.Parse(friend.Address);

            friend.IP = _rarad.RegisterMapping(friend.Alias, addr);
            _node.ManagedCO.AddAddress(addr);
            friend.Access = SocialUser.AccessTypes.Allow.ToString();
        }
Ejemplo n.º 6
0
        /**
         * Adds a certificate to the socialvpn system.
         * @param certString a base64 encoding string representing certificate.
         */
        protected void AddCertificate(string certString)
        {
            certString = certString.Replace("\n", "");
            byte[]     certData = Convert.FromBase64String(certString);
            SocialUser friend   = new SocialUser(certData);

            _snode.AddCertificate(certData, friend.DhtKey);
        }
Ejemplo n.º 7
0
 public DrupalNetwork(SocialUser user)
 {
     _drupal       = XmlRpcProxyGen.Create <IDrupalXmlRpc>();
     _local_user   = user;
     _email_to_uid = new Dictionary <string, string>();
     _uid_mismatch = false;
     _key_found    = false;
 }
Ejemplo n.º 8
0
 public DrupalNetwork(SocialUser user)
 {
     _drupal = XmlRpcProxyGen.Create<IDrupalXmlRpc>();
       _local_user = user;
       _email_to_uid = new Dictionary<string,string>();
       _uid_mismatch = false;
       _key_found = false;
 }
Ejemplo n.º 9
0
 public SocialNetworkProvider(Dht dht, SocialUser user)
 {
     _local_user = user;
     _dht        = dht;
     _provider   = _drupal;
     _network    = _drupal;
     _drupal     = new DrupalNetwork(user);
     _online     = false;
 }
Ejemplo n.º 10
0
 public SocialRpcHandler(StructuredNode node, SocialUser localUser,
                         Dictionary <string, SocialUser> friends)
 {
     _node = node;
     _rpc  = node.Rpc;
     _rpc.AddHandler("SocialVPN", this);
     _local_user = localUser;
     _friends    = friends;
 }
Ejemplo n.º 11
0
 public SocialRpcHandler(StructuredNode node, SocialUser localUser,
                    Dictionary<string, SocialUser> friends)
 {
     _node = node;
       _rpc = node.Rpc;
       _rpc.AddHandler("SocialVPN", this);
       _local_user = localUser;
       _friends = friends;
 }
Ejemplo n.º 12
0
 public SocialNetworkProvider(Dht dht, SocialUser user)
 {
     _local_user = user;
       _dht = dht;
       _provider = _drupal;
       _network = _drupal;
       _drupal = new DrupalNetwork(user);
       _online = false;
 }
Ejemplo n.º 13
0
 public void PingFriend(SocialUser friend)
 {
     if (friend.Time != SocialUser.TIMEDEFAULT)
     {
         DateTime past         = DateTime.Parse(friend.Time);
         TimeSpan last_checked = DateTime.Now - past;
         if (last_checked.Minutes < 5)
         {
             return;
         }
         ;
     }
     FriendPing(friend.Address);
 }
Ejemplo n.º 14
0
        /**
         * Saves an X509 certificate to the file system.
         * @param cert the X509 certificate
         */
        public static void SaveCertificate(Certificate cert, string certDir)
        {
            SocialUser friend  = new SocialUser(cert);
            string     address = friend.Address.Substring(12);
            string     ca_path = Path.Combine(certDir, "ca" + address + ".cert");

            if (!Directory.Exists(certDir))
            {
                Directory.CreateDirectory(certDir);
            }
            if (!File.Exists(ca_path))
            {
                WriteToFile(cert.X509.RawData, ca_path);
            }
        }
Ejemplo n.º 15
0
        /**
         * Add a friend to socialvpn from an X509 certificate.
         * @param certData the X509 certificate as a byte array.
         * @param key the dht_key containing fingerprint.
         */
        public void AddCertificate(byte[] certData, string key)
        {
            Certificate cert   = new Certificate(certData);
            SocialUser  friend = new SocialUser(cert);

            string[] parts       = key.Split(':');
            string   uid         = parts[1];
            string   fingerprint = parts[2];

            // Verification on the certificate by email and fingerprint
            if (friend.DhtKey == _local_user.DhtKey ||
                _friends.ContainsKey(friend.DhtKey))
            {
                ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY FOUND: " +
                                  key);
            }
            else if (fingerprint != friend.Fingerprint || uid != friend.Uid)
            {
                ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY MISMATCH: " +
                                  key + " " + friend.DhtKey);
            }
            else
            {
                friend.Alias = CreateAlias(friend.Uid, friend.PCID);

                // Save certificate to file system
                SocialUtils.SaveCertificate(cert, _cert_dir);

                // Add certificates to handler
                _bso.CertificateHandler.AddCACertificate(cert.X509);

                // Add friend to list
                _friends.Add(friend.DhtKey, friend);

                // Temporary
                AddFriend(friend);

                // RPC ping to newly added friend
                _srh.PingFriend(friend);

                ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY SUCCESS: " +
                                  friend.DhtKey + " " + friend.IP + " " +
                                  friend.Alias);
            }
        }
Ejemplo n.º 16
0
        /**
         * Constructor.
         * @param brunetConfig configuration file for Brunet P2P library.
         * @param ipopConfig configuration file for IP over P2P app.
         */
        public SocialNode(string brunetConfig, string ipopConfig,
                          string certDir, string port) :
            base(brunetConfig, ipopConfig)
        {
            _friends  = new Dictionary <string, SocialUser>();
            _cert_dir = certDir;
            string cert_path = Path.Combine(certDir, CERTFILENAME);

            _local_cert     = new Certificate(SocialUtils.ReadFileBytes(cert_path));
            _local_user     = new SocialUser(_local_cert);
            _local_cert_b64 = Convert.ToBase64String(_local_cert.X509.RawData);
            _bso.CertificateHandler.AddCACertificate(_local_cert.X509);
            _bso.CertificateHandler.AddSignedCertificate(_local_cert.X509);
            _snp = new SocialNetworkProvider(this.Dht, _local_user);
            _srh = new SocialRpcHandler(_node, _local_user, _friends);
            _scm = new SocialConnectionManager(this, _snp, _snp, port, _friends,
                                               _srh);
        }
Ejemplo n.º 17
0
        public void SocialUserTest()
        {
            string uid     = "*****@*****.**";
            string name    = "Pierre St Juste";
            string pcid    = "pdesktop";
            string version = "SVPN_0.3.0";
            string country = "US";

            Certificate cert = SocialUtils.CreateCertificate(uid, name, pcid,
                                                             version, country,
                                                             "address1234",
                                                             "certificates",
                                                             "private_key");

            SocialUser user = new SocialUser(cert.X509.RawData);

            Assert.AreEqual(uid, user.Uid);
            Assert.AreEqual(name, user.Name);
            Assert.AreEqual(pcid, user.PCID);
            Assert.AreEqual(version, user.Version);
            Assert.AreEqual(country, user.Country);
        }
Ejemplo n.º 18
0
        public void TestNetworkTest()
        {
            string uid     = "*****@*****.**";
            string name    = "Pierre St Juste";
            string pcid    = "pdesktop";
            string version = "SVPN_0.3.0";
            string country = "US";

            SocialUtils.CreateCertificate(uid, name, pcid, version, country,
                                          "address1234", "certificates",
                                          "private_key");


            string cert_path = System.IO.Path.Combine("certificates", "lc.cert");

            byte[]     cert_data = SocialUtils.ReadFileBytes(cert_path);
            SocialUser user      = new SocialUser(cert_data);

            TestNetwork backend = new TestNetwork(user);

            backend.SayHello();
            backend.GetFingerprints("uid");
        }
Ejemplo n.º 19
0
 /*
  * Add a friend from socialvpn.
  * @param friend the friend to be added.
  */
 public void AddFriend(SocialUser friend)
 {
     Address addr = AddressParser.Parse(friend.Address);
       friend.IP = _rarad.RegisterMapping(friend.Alias, addr);
       _node.ManagedCO.AddAddress(addr);
       friend.Access = SocialUser.AccessTypes.Allow.ToString();
 }
Ejemplo n.º 20
0
        /**
         * Add a friend to socialvpn from an X509 certificate.
         * @param certData the X509 certificate as a byte array.
         * @param key the dht_key containing fingerprint.
         */
        public void AddCertificate(byte[] certData, string key)
        {
            Certificate cert = new Certificate(certData);
              SocialUser friend = new SocialUser(cert);
              string[] parts = key.Split(':');
              string uid = parts[1];
              string fingerprint = parts[2];

              // Verification on the certificate by email and fingerprint
              if(friend.DhtKey == _local_user.DhtKey ||
             _friends.ContainsKey(friend.DhtKey)) {
            ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY FOUND: " +
                          key);
              }
              else if(fingerprint != friend.Fingerprint || uid != friend.Uid) {
            ProtocolLog.Write(SocialLog.SVPNLog, "ADD CERT KEY MISMATCH: " +
                       key + " " + friend.DhtKey);
              }
              else {
            friend.Alias = CreateAlias(friend.Uid, friend.PCID);

            // Save certificate to file system
            SocialUtils.SaveCertificate(cert, _cert_dir);

            // Add certificates to handler
            _bso.CertificateHandler.AddCACertificate(cert.X509);

            // Add friend to list
            _friends.Add(friend.DhtKey, friend);

            // Temporary
            AddFriend(friend);

            // RPC ping to newly added friend
            _srh.PingFriend(friend);

            ProtocolLog.Write(SocialLog.SVPNLog,"ADD CERT KEY SUCCESS: " +
                          friend.DhtKey + " " + friend.IP + " " +
                          friend.Alias);
              }
        }
Ejemplo n.º 21
0
 /**
  * Constructor.
  * @param brunetConfig configuration file for Brunet P2P library.
  * @param ipopConfig configuration file for IP over P2P app.
  */
 public SocialNode(string brunetConfig, string ipopConfig, 
               string certDir, string port)
     : base(brunetConfig, ipopConfig)
 {
     _friends = new Dictionary<string, SocialUser>();
       _cert_dir = certDir;
       string cert_path = Path.Combine(certDir, CERTFILENAME);
       _local_cert = new Certificate(SocialUtils.ReadFileBytes(cert_path));
       _local_user = new SocialUser(_local_cert);
       _local_cert_b64 = Convert.ToBase64String(_local_cert.X509.RawData);
       _bso.CertificateHandler.AddCACertificate(_local_cert.X509);
       _bso.CertificateHandler.AddSignedCertificate(_local_cert.X509);
       _snp = new SocialNetworkProvider(this.Dht, _local_user);
       _srh = new SocialRpcHandler(_node, _local_user, _friends);
       _scm = new SocialConnectionManager(this, _snp, _snp, port, _friends,
                                  _srh);
 }
Ejemplo n.º 22
0
 public void PingFriend(SocialUser friend)
 {
     if(friend.Time != SocialUser.TIMEDEFAULT) {
     DateTime past = DateTime.Parse(friend.Time);
     TimeSpan last_checked = DateTime.Now - past;
     if(last_checked.Minutes < 5) {
       return;
     };
       }
       FriendPing(friend.Address);
 }
Ejemplo n.º 23
0
 /*
  * Add a friend from socialvpn.
  * @param friend the friend to be added.
  */
 protected void AddFriend(SocialUser friend)
 {
     Address addr = AddressParser.Parse(friend.Address);
       friend.IP = _marad.RegisterMapping(friend.Alias, addr);
       _node.ManagedCO.AddAddress(addr);
       friend.Access = SocialUser.AccessTypes.Allow.ToString();
       _srh.PingFriend(friend);
       GetState(true);
 }
Ejemplo n.º 24
0
 public TestNetwork(SocialUser user)
 {
     _backend    = XmlRpcProxyGen.Create <IPythonXmlRpc>();
     _local_user = user;
 }
Ejemplo n.º 25
0
 /**
  * Constructor.
  * @param brunetConfig configuration file for Brunet P2P library.
  * @param ipopConfig configuration file for IP over P2P app.
  */
 public SocialNode(NodeConfig brunetConfig, IpopConfig ipopConfig, 
               string certDir, string http_port, string jabber_port,
               string global_access)
     : base(brunetConfig, ipopConfig)
 {
     _friends = new Dictionary<string, SocialUser>();
       _aliases = new Dictionary<string, string>();
       _addr_to_key = new Dictionary<string, string>();
       _cert_dir = certDir;
       _http_port = http_port;
       string cert_path = Path.Combine(certDir, CERTFILENAME);
       _local_cert = new Certificate(SocialUtils.ReadFileBytes(cert_path));
       _local_user = new SocialUser(_local_cert);
       _local_cert_b64 = Convert.ToBase64String(_local_cert.X509.RawData);
       _bso.CertificateHandler.AddCACertificate(_local_cert.X509);
       _bso.CertificateHandler.AddSignedCertificate(_local_cert.X509);
       _queue = new BlockingQueue();
       _snp = new SocialNetworkProvider(this.Dht, _local_user,
                                _local_cert.X509.RawData, _queue,
                                jabber_port);
       _sdm = new SocialDnsManager(this, _local_user);
       _srh = new SocialRpcHandler(_node, _local_user, _friends, _queue, _sdm);
       _scm = new SocialConnectionManager(this, _snp, _srh, http_port, _queue,
                                  _sdm);
       _cert_published = false;
       _node.ConnectionTable.ConnectionEvent += ConnectHandler;
       _node.HeartBeatEvent += _scm.HeartBeatHandler;
       Shutdown.OnExit += _scm.Stop;
       _local_user.IP = _marad.LocalIP;
       CreateAlias(_local_user);
       _marad.MapLocalDNS(_local_user.Alias);
       _scm.GlobalAccess = (global_access == "on");
       LoadCertificates();
 }
Ejemplo n.º 26
0
        public void TestNetworkTest()
        {
            ///*
              string uid = "*****@*****.**";
              string name = "Pierre St Juste";
              string pcid = "pdesktop";
              string version = "SVPN_0.3.0";
              string country = "US";
              string address =
            Brunet.Applications.Utils.GenerateAHAddress().ToString();
              SocialUtils.CreateCertificate(uid, name, pcid, version, country,
                                    address, "certificates", "private_key");
              //*/
              string cert_path = System.IO.Path.Combine("certificates", "local.cert");
              byte[] cert_data = SocialUtils.ReadFileBytes(cert_path);
              SocialUser user = new SocialUser(cert_data);

              Console.WriteLine(user);
              TestNetwork backend = new TestNetwork(user, cert_data);
              //backend.StoreFingerprint();
              string[] friends = backend.GetFriends().ToArray();
              foreach(string friend in friends) {
            Console.WriteLine(friend);
              }
              string[] fprs = backend.GetFingerprints(friends).ToArray();
              foreach(string fpr in fprs) {
            Console.WriteLine(fpr);
              }
        }
Ejemplo n.º 27
0
 /**
  * Validates a certificate
  * @param user the user object.
  * @param certData the certificate data.
  * @return boolean indicating success.
  */
 public bool ValidateCertificate(SocialUser user, byte[] certData)
 {
     foreach(IProvider provider in _providers.Values) {
     if(provider.ValidateCertificate(user, certData)) {
       return true;
     }
       }
       if(_friends.ContainsKey(user.Uid) &&
      _friends[user.Uid].Contains(user.DhtKey)) {
     return true;
       }
       return false;
 }
Ejemplo n.º 28
0
   /**
    * Constructor.
    * @param dht the dht object.
    * @param user the local user object.
    * @param certData the local certificate data.
    */
   public SocialNetworkProvider(IDht dht, SocialUser user, byte[] certData,
 BlockingQueue queue, string jabber_port)
   {
       _local_user = user;
         _dht = dht;
         _queue = queue;
         _providers = new Dictionary<string, IProvider>();
         _networks = new Dictionary<string,ISocialNetwork>();
         _local_cert_data = certData;
         _friends = new Dictionary<string, List<string>>();
         _certificates = new List<byte[]>();
         _jabber_port = jabber_port;
         RegisterBackends();
   }
Ejemplo n.º 29
0
 public void JabberNetworkTest()
 {
     string userid = "pierre@pdebian64";
       Certificate cert = SocialUtils.CreateCertificate(userid,
     "Pierre St Juste", "testpc", "version", "country", "address",
     "certdir", "path");
       SocialUser user = new SocialUser(cert.X509.RawData);
       BlockingQueue queue = new BlockingQueue();
       JabberNetwork jnetwork = new JabberNetwork(user, cert.X509.RawData,
       queue, "5222");
       jnetwork.Login("jabber", userid,"stjuste");
       Console.WriteLine("Waiting 5 seconds for resuls");
       System.Threading.Thread.Sleep(5000);
       Console.WriteLine("Done waiting for results");
       foreach(string friend in jnetwork.GetFriends()) Console.WriteLine(friend);
       jnetwork.GetFingerprints(new string[] {userid});
       jnetwork.StoreFingerprint();
       jnetwork.Logout();
 }
Ejemplo n.º 30
0
        public void TestNetworkTest()
        {
            string uid = "*****@*****.**";
              string name = "Pierre St Juste";
              string pcid = "pdesktop";
              string version = "SVPN_0.3.0";
              string country = "US";

              SocialUtils.CreateCertificate(uid, name, pcid, version, country,
                                    "address1234", "certificates",
                                    "private_key");

              string cert_path = System.IO.Path.Combine("certificates", "lc.cert");
              byte[] cert_data = SocialUtils.ReadFileBytes(cert_path);
              SocialUser user = new SocialUser(cert_data);

              TestNetwork backend = new TestNetwork(user);
              backend.SayHello();
              backend.GetFingerprints("uid");
        }
Ejemplo n.º 31
0
 /**
  * Loads certificates from the file system.
  */
 protected void LoadCertificates()
 {
     string[] cert_files = null;
       try {
     cert_files = System.IO.Directory.GetFiles(_cert_dir);
     SocialState state = Utils.ReadConfig<SocialState>(STATEPATH);
     foreach(string cert_file in cert_files) {
       byte[] cert_data = SocialUtils.ReadFileBytes(cert_file);
       SocialUser user = new SocialUser(cert_data);
       _snp.AddFriends(new string[] {user.Uid + " " + user.DhtKey});
       AddCertificate(cert_data, true);
     }
     foreach(SocialUser friend in state.Friends) {
       if(friend.Access == SocialUser.AccessTypes.Block.ToString()) {
     RemoveFriend(friend.DhtKey);
       }
     }
       } catch (Exception e) {
     ProtocolLog.WriteIf(SocialLog.SVPNLog, e.Message);
     ProtocolLog.WriteIf(SocialLog.SVPNLog, "LOAD CERTIFICATES FAILURE");
       }
 }
Ejemplo n.º 32
0
 /*
  * Removes a friend from socialvpn.
  * @param friend the friend to be removed.
  */
 public void RemoveFriend(SocialUser friend)
 {
     Address addr = AddressParser.Parse(friend.Address);
       _node.ManagedCO.RemoveAddress(addr);
       _rarad.UnregisterMapping(friend.Alias);
       friend.Access = SocialUser.AccessTypes.Block.ToString();
 }
Ejemplo n.º 33
0
 public TestNetwork(SocialUser user, byte[] certData)
 {
     _local_user = user;
       _fingerprints = new List<string>();
       _url = "http://socialvpntest.appspot.com/api/";
 }
Ejemplo n.º 34
0
        public void SocialUserTest()
        {
            string uid = "*****@*****.**";
              string name = "Pierre St Juste";
              string pcid = "pdesktop";
              string version = "SVPN_0.3.0";
              string country = "US";

              Certificate cert = SocialUtils.CreateCertificate(uid, name, pcid,
                                                       version, country,
                                                       "address1234",
                                                       "certificates",
                                                       "private_key");

              SocialUser user = new SocialUser(cert.X509.RawData);

              Assert.AreEqual(uid, user.Uid);
              Assert.AreEqual(name, user.Name);
              Assert.AreEqual(pcid, user.PCID);
              Assert.AreEqual(version, user.Version);
              Assert.AreEqual(country, user.Country);
        }
Ejemplo n.º 35
0
 public TestNetwork(SocialUser user)
 {
     _backend = XmlRpcProxyGen.Create<IPythonXmlRpc>();
       _local_user = user;
 }
Ejemplo n.º 36
0
        /**
         * Add a friend to socialvpn from an X509 certificate.
         * @param certData the X509 certificate as a byte array.
         * @param access determines to give user network access.
         */
        public void AddCertificate(byte[] certData, bool access)
        {
            Certificate cert = new Certificate(certData);
              SocialUser friend = new SocialUser(cert);

              // Verification on the certificate by email and fingerprint
              if(friend.DhtKey == _local_user.DhtKey ||
             _friends.ContainsKey(friend.DhtKey)) {
            ProtocolLog.WriteIf(SocialLog.SVPNLog,
                            String.Format("ADD CERT KEY FOUND: {0} {1}",
                            DateTime.Now.TimeOfDay, friend.DhtKey));
              }
              else if(_snp.ValidateCertificate(friend, certData)) {
            CreateAlias(friend);
            string path = System.IO.Path.Combine(_cert_dir, friend.Alias +
                      CERTSUFFIX);
            SocialUtils.WriteToFile(certData, path);
            _bso.CertificateHandler.AddCACertificate(cert.X509);
            _friends.Add(friend.DhtKey, friend);
            _addr_to_key.Add(friend.Address, friend.DhtKey);
            AddFriend(friend);
            _srh.PingFriend(friend);

            // Block access
            if(!access) {
              RemoveFriend(friend);
            }

            ProtocolLog.WriteIf(SocialLog.SVPNLog,
                            String.Format("ADD CERT KEY SUCCESS: {0} {1} {2}",
                            DateTime.Now.TimeOfDay, friend.DhtKey,
                            friend.Address));
              }
              else {
            ProtocolLog.WriteIf(SocialLog.SVPNLog,
                            String.Format("ADD CERT KEY INVALID: {0} {1} {2}",
                            DateTime.Now.TimeOfDay, friend.DhtKey,
                            friend.Address));
              }
        }
Ejemplo n.º 37
0
 public bool ValidateCertificate(SocialUser user, byte[] certData)
 {
     return true;
 }
Ejemplo n.º 38
0
 /**
  * Create a unique alias for a user resource.
  * @param user the object representing the user.
  */
 protected virtual void CreateAlias(SocialUser friend)
 {
     char[] delims = new char[] {'@','.'};
       string[] parts = friend.Uid.Split(delims);
       string user = String.Empty;
       for(int i = 0; i < parts.Length-1; i++) {
     user += parts[i] + ".";
       }
       string alias = (friend.PCID + "." + user + DNSSUFFIX).ToLower();
       int counter = 1;
       // If alias already exists, remove old friend with alias
       while(_aliases.ContainsKey(alias)) {
     alias = (friend.PCID + counter + "." + user + DNSSUFFIX).ToLower();
     counter++;
       }
       _aliases[alias] = friend.DhtKey;
       friend.Alias = alias;
 }
Ejemplo n.º 39
0
        public void DrupalNetworkTest()
        {
            string uid = "*****@*****.**";
              string name = "Pierre St Juste";
              string pcid = "pdesktop";
              string version = "SVPN_0.3.0";
              string country = "US";

              SocialUtils.CreateCertificate(uid, name, pcid, version, country,
                                    "address1234", "certificates",
                                    "private_key");

              string cert_path = System.IO.Path.Combine("certificates", "lc.cert");
              byte[] cert_data = SocialUtils.ReadFileBytes(cert_path);
              SocialUser user = new SocialUser(cert_data);
              /*
              DrupalNetwork drupal = new DrupalNetwork(user);
              drupal.Login("pierre", "stjuste");

              List<string> friends = drupal.GetFriends();

              foreach(string friend in friends) {
            Console.WriteLine(friend);
            List<string> fprs = drupal.GetFingerprints(friend);
            foreach(string fpr in fprs) {
              Console.WriteLine(friend + " " + fpr);
            }
              }
              drupal.StoreFingerprint();
              drupal.Logout();
              */
        }
Ejemplo n.º 40
0
 /**
  * Removes (block access) a friend from socialvpn.
  * @param friend the friend to be removed.
  */
 protected void RemoveFriend(SocialUser friend)
 {
     Address addr = AddressParser.Parse(friend.Address);
       _node.ManagedCO.RemoveAddress(addr);
       _marad.UnregisterMapping(friend.Alias);
       friend.Access = SocialUser.AccessTypes.Block.ToString();
       GetState(true);
 }
Ejemplo n.º 41
0
 /**
  * Constructor.
  * @param node the p2p node.
  * @param localUser the local user object.
  * @param friends the list of friends.
  */
 public SocialRpcHandler(StructuredNode node, SocialUser localUser,
                    Dictionary<string, SocialUser> friends,
                    BlockingQueue queue, SocialDnsManager sdm)
 {
     _node = node;
       _rpc = node.Rpc;
       _rpc.AddHandler("SocialVPN", this);
       _local_user = localUser;
       _friends = friends;
       _queue = queue;
       _sdm = sdm;
 }
Ejemplo n.º 42
0
 /**
  * Adds a certificate to the socialvpn system.
  * @param certString a base64 encoding string representing certificate.
  */
 protected void AddCertificate(string certString)
 {
     certString = certString.Replace("\n", "");
       byte[] certData = Convert.FromBase64String(certString);
       SocialUser friend = new SocialUser(certData);
       _snode.AddCertificate(certData, friend.DhtKey);
 }
Ejemplo n.º 43
0
 public bool ValidateCertificate(SocialUser user, byte[] certData)
 {
     if(_friends.ContainsKey(user.Uid) &&
      _friends[user.Uid].Contains(user.DhtKey)) {
     return true;
       }
       return false;
 }