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(); */ }
/** * Generates an XML string representing state of the system. */ public string GetState() { SocialState state = new SocialState(); state.Certificate = _local_cert_b64; state.LocalUser = _local_user; state.Friends = new SocialUser[_friends.Count]; _friends.Values.CopyTo(state.Friends, 0); return(SocialUtils.ObjectToXml <SocialState>(state)); }
/** * Constructor that takes an X509 certificate. * @param cert X509 certificate. */ public SocialUser(Certificate cert) { Uid = cert.Subject.Email; Name = cert.Subject.Name; PCID = cert.Subject.OrganizationalUnit; Address = cert.NodeAddress; Version = cert.Subject.Organization; Fingerprint = SocialUtils.GetSHA256(cert.X509.RawData); DhtKey = "svpn:" + Uid + ":" + Fingerprint; Country = cert.Subject.Country; Access = AccessTypes.Block.ToString(); Time = TIMEDEFAULT; IP = IPDEFAULT; Alias = ALIASDEFAULT; Pic = PICDEFAULT; }
/** * 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); } }
/** * 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); }
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); }
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"); }
public static new void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("usage: SocialVPN.exe <brunet.config path> " + "<ipop.config path> <http port>"); return; } NodeConfig config = Utils.ReadConfig <NodeConfig>(args[0]); if (!System.IO.File.Exists(config.Security.KeyPath)) { Console.Write("Enter Name (First Last): "); string name = Console.ReadLine(); Console.Write("Enter Email Address: "); string uid = Console.ReadLine(); Console.Write("Enter a name for this PC: "); string pcid = Console.ReadLine(); string version = "SVPN_0.3.0"; string country = "US"; config.NodeAddress = (Utils.GenerateAHAddress()).ToString(); Utils.WriteConfig(args[0], config); SocialUtils.CreateCertificate(uid, name, pcid, version, country, config.NodeAddress, config.Security.CertificatePath, config.Security.KeyPath); } SocialNode node = new SocialNode(args[0], args[1], config.Security.CertificatePath, args[2]); node.Run(); }
/** * This method runs the interface. */ protected void Run() { while (_running) { HttpListenerContext context = null; try { context = _listener.GetContext(); } catch (HttpListenerException e) { if (!_running) { return; } Console.WriteLine(e); } HttpListenerRequest request = context.Request; HttpListenerResponse response = context.Response; string responseString = String.Empty; response.ContentType = "text/xml"; // Process api post request from the Javascript interface if (request.RawUrl == "/api") { StreamReader reader = new StreamReader(request.InputStream, request.ContentEncoding); string postData = reader.ReadToEnd(); request.InputStream.Close(); reader.Close(); Brunet.ProtocolLog.Write(SocialLog.SVPNLog, postData); responseString = Process(SocialUtils.DecodeUrl(postData)); } else if (request.RawUrl.StartsWith("/getapi")) { string getData = request.RawUrl.Substring(8); Brunet.ProtocolLog.Write(SocialLog.SVPNLog, getData); responseString = Process(SocialUtils.DecodeUrl(getData)); } // Cross-domain request made by Flash clients else if (request.RawUrl == "/crossdomain.xml") { responseString = CrossDomainXML; } else if (request.RawUrl == "/socialvpn.js") { using (StreamReader text = new StreamReader("socialvpn.js")) { responseString = text.ReadToEnd(); } response.ContentType = "text/javascript"; } else if (request.RawUrl == "/socialvpn.css") { using (StreamReader text = new StreamReader("socialvpn.css")) { responseString = text.ReadToEnd(); } response.ContentType = "text/css"; } // Return html content for page display else { responseString = HTMLText; response.ContentType = "text/html"; } byte[] buffer = System.Text.Encoding.UTF8.GetBytes(responseString); response.ContentLength64 = buffer.Length; response.AddHeader("Cache-Control", "No-cache"); System.IO.Stream output = response.OutputStream; output.Write(buffer, 0, buffer.Length); output.Close(); } }