コード例 #1
0
        public DatabaseConnection()
        {
            try
            {
                Core core = new Core(Server.passphrase, false);

                connectionstring = String.Format("server={0};uid={1};pwd={2};database={3}", core.GetXmlNodeInnerText("server"), core.GetXmlNodeInnerText("uid"), core.GetXmlNodeInnerText("pwd"), core.GetXmlNodeInnerText("dbase"));
                conn = new MySqlConnection(connectionstring);
                conn.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                throw e;
            }
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: cbguder/practises
        /*private void GetCertificate(String domainName)
        {
            //String cert = rootServer.GetCertificate(domainName);
            //String[] certFields = cert.Split(',');
            //Console.WriteLine(cert);
            byte[] rawCertData = rootServer.GetCertificate(domainName);
            if (rawCertData != null)
            {
                Certificate.OpenCertificate();
                Certificate.AddCertificate(rawCertData);
                //Console.WriteLine(Convert.ToBase64String(rawCertData));
                Console.WriteLine("Certificate has been downloaded successfully.");
            }
        }*/
        static void Main(string[] args)
        {
            RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);

            ServerObject serverobj = new ServerObject();
            //serverobj.KeyObt("*****@*****.**", DateTime.Now);

            Console.Write("Enter passphrase: ");
            passphrase = Console.ReadLine();
            passphrase.Trim();
            Core core = new Core(passphrase);
            core.ReadSettingsFile();

            Server server = new Server();
            server.Connect(core.GetXmlNodeInnerText("root_server"));

            DatabaseConnection connection = new DatabaseConnection();
            String publicKey = core.PublicKey;
            String dbPublicKey = connection.getPublicKey("server");
            connection.close();
            StreamWriter writer = new StreamWriter(core.ActionLogFile, true);
            if (publicKey != dbPublicKey)
            {
                writer.Write(DateTime.Now.ToString() + Core.space);
                writer.WriteLine("Server's old public key:");
                writer.WriteLine();
                writer.WriteLine(dbPublicKey);
                writer.WriteLine();

                //connection = new DatabaseConnection();
                //connection.setPublicKey("server", "server", publicKey);
                connection.updatePublicKey("server", "server", publicKey);
                Console.Write(DateTime.Now.ToString() + Core.space);
                Console.WriteLine("New key pair is set.");
            }
            connection.close();
            writer.Write(DateTime.Now.ToString() + Core.space);
            writer.WriteLine("Server's public key:");
            writer.WriteLine();
            writer.WriteLine(publicKey);
            writer.WriteLine();

            writer.Write(DateTime.Now.ToString() + Core.space);
            writer.WriteLine("Server started");
            writer.Close();

            Console.Write(DateTime.Now.ToString() + Core.space);
            Console.WriteLine("PractiSES Server started.");

            HttpServerChannel channel = new HttpServerChannel(80);
            ChannelServices.RegisterChannel(channel,false);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(PractiSES.ServerObject),
                "PractiSES",
                WellKnownObjectMode.SingleCall);
            System.Console.ReadLine();
        }
コード例 #3
0
        /*private void GetCertificate(String domainName)
         * {
         *  //String cert = rootServer.GetCertificate(domainName);
         *  //String[] certFields = cert.Split(',');
         *  //Console.WriteLine(cert);
         *  byte[] rawCertData = rootServer.GetCertificate(domainName);
         *  if (rawCertData != null)
         *  {
         *      Certificate.OpenCertificate();
         *      Certificate.AddCertificate(rawCertData);
         *      //Console.WriteLine(Convert.ToBase64String(rawCertData));
         *      Console.WriteLine("Certificate has been downloaded successfully.");
         *  }
         * }*/

        static void Main(string[] args)
        {
            RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);

            ServerObject serverobj = new ServerObject();

            //serverobj.KeyObt("*****@*****.**", DateTime.Now);


            Console.Write("Enter passphrase: ");
            passphrase = Console.ReadLine();
            passphrase.Trim();
            Core core = new Core(passphrase);

            core.ReadSettingsFile();

            Server server = new Server();

            server.Connect(core.GetXmlNodeInnerText("root_server"));

            DatabaseConnection connection  = new DatabaseConnection();
            String             publicKey   = core.PublicKey;
            String             dbPublicKey = connection.getPublicKey("server");

            connection.close();
            StreamWriter writer = new StreamWriter(core.ActionLogFile, true);

            if (publicKey != dbPublicKey)
            {
                writer.Write(DateTime.Now.ToString() + Core.space);
                writer.WriteLine("Server's old public key:");
                writer.WriteLine();
                writer.WriteLine(dbPublicKey);
                writer.WriteLine();

                //connection = new DatabaseConnection();
                //connection.setPublicKey("server", "server", publicKey);
                connection.updatePublicKey("server", "server", publicKey);
                Console.Write(DateTime.Now.ToString() + Core.space);
                Console.WriteLine("New key pair is set.");
            }
            connection.close();
            writer.Write(DateTime.Now.ToString() + Core.space);
            writer.WriteLine("Server's public key:");
            writer.WriteLine();
            writer.WriteLine(publicKey);
            writer.WriteLine();

            writer.Write(DateTime.Now.ToString() + Core.space);
            writer.WriteLine("Server started");
            writer.Close();

            Console.Write(DateTime.Now.ToString() + Core.space);
            Console.WriteLine("PractiSES Server started.");


            HttpServerChannel channel = new HttpServerChannel(80);

            ChannelServices.RegisterChannel(channel, false);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(PractiSES.ServerObject),
                "PractiSES",
                WellKnownObjectMode.SingleCall);
            System.Console.ReadLine();
        }
コード例 #4
0
ファイル: ServerObject.cs プロジェクト: mergun/practises
        public String KeyObt(String email, DateTime date) //get public key of a user ( complete )
        {
            ActionLog_Write(email + ": KeyObt");

            Console.WriteLine(beginProtocol);
            Console.WriteLine(email + ": KeyObt");

            int    index      = email.IndexOf('@');
            String domainName = email.Substring(index, email.Length - index);
            String publicKey  = null;
            Core   core       = new Core(Server.passphrase);

            if (core.GetXmlNodeInnerText("domain") == domainName)
            {
                DatabaseConnection connection = new DatabaseConnection();
                publicKey = connection.getPublicKey(email, date);
                connection.close();
            }
            else
            {
                byte[] rawCertData = Certificate.SearchCertificate(domainName);
                if (rawCertData == null)
                {
                    if (ConnectRootServer(core.GetXmlNodeInnerText("root_server")))
                    {
                        if (GetCertificate(domainName))
                        {
                            rawCertData = Certificate.SearchCertificate(domainName);
                        }
                    }
                }
                byte[] foreignServerCertPK = Certificate.GetPublicKey(rawCertData);
                String foreignServerXmlPK  = Crypto.CertToXMLKey(foreignServerCertPK);
                Console.WriteLine("Public key of " + domainName + ":\n" + foreignServerXmlPK);
                String foreignServerHost = Certificate.GetHostName(rawCertData);

                ActionLog_Write("Connecting to foreign PractiSES server (" + foreignServerHost + ")...");
                Console.WriteLine("Connecting to foreign PractiSES server ({0})...", foreignServerHost);

                IServer foreignServer   = (IServer)Activator.GetObject(typeof(IServer), "http://" + foreignServerHost + "/PractiSES");
                String  signedPublicKey = foreignServer.KeyObt(email, date);
                if (signedPublicKey != null)
                {
                    Message foreignmessage = new Message(signedPublicKey);
                    //****************
                    if (foreignmessage.Verify(foreignServerXmlPK))
                    {
                        publicKey = foreignmessage.getCleartext();
                    }
                    //****************
                }
            }
            if (publicKey == null)
            {
                ActionLog_Write("Error - " + email + ": Email does not exist!");
                Console.WriteLine("Error - " + email + ": Email does not exist!");
                throw new Exception("Invalid user");
            }
            Message message = new Message(publicKey);

            message.AddComment("Email", email);
            message.Sign(core.PrivateKey);
            String result = message.ToString();

            return(result);
        }
コード例 #5
0
        public DatabaseConnection()
        {
            try
            {
                Core core = new Core(Server.passphrase, false);

                connectionstring = String.Format("server={0};uid={1};pwd={2};database={3}", core.GetXmlNodeInnerText("server"), core.GetXmlNodeInnerText("uid"), core.GetXmlNodeInnerText("pwd"), core.GetXmlNodeInnerText("dbase"));
                conn             = new MySqlConnection(connectionstring);
                conn.Open();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
                throw e;
            }
        }
コード例 #6
0
ファイル: ServerObject.cs プロジェクト: cbguder/practises
        //get public key of a user ( complete )
        public String KeyObt(String email, DateTime date)
        {
            ActionLog_Write(email + ": KeyObt");

            Console.WriteLine(beginProtocol);
            Console.WriteLine(email + ": KeyObt");

            int index = email.IndexOf('@');
            String domainName = email.Substring(index, email.Length - index);
            String publicKey = null;
            Core core = new Core(Server.passphrase);
            if (core.GetXmlNodeInnerText("domain") == domainName)
            {
                DatabaseConnection connection = new DatabaseConnection();
                publicKey = connection.getPublicKey(email, date);
                connection.close();
            }
            else
            {
                byte[] rawCertData = Certificate.SearchCertificate(domainName);
                if (rawCertData == null)
                {
                    if (ConnectRootServer(core.GetXmlNodeInnerText("root_server")))
                    {
                        if (GetCertificate(domainName))
                        {
                            rawCertData = Certificate.SearchCertificate(domainName);
                        }
                    }
                }
                byte[] foreignServerCertPK = Certificate.GetPublicKey(rawCertData);
                String foreignServerXmlPK = Crypto.CertToXMLKey(foreignServerCertPK);
                Console.WriteLine("Public key of " + domainName + ":\n" + foreignServerXmlPK);
                String foreignServerHost = Certificate.GetHostName(rawCertData);

                ActionLog_Write("Connecting to foreign PractiSES server (" + foreignServerHost + ")...");
                Console.WriteLine("Connecting to foreign PractiSES server ({0})...", foreignServerHost);

                IServer foreignServer = (IServer)Activator.GetObject(typeof(IServer), "http://" + foreignServerHost + "/PractiSES");
                String signedPublicKey = foreignServer.KeyObt(email, date);
                if (signedPublicKey != null)
                {
                    Message foreignmessage = new Message(signedPublicKey);
                    //****************
                    if (foreignmessage.Verify(foreignServerXmlPK))
                    {
                        publicKey = foreignmessage.getCleartext();
                    }
                    //****************
                }
            }
            if (publicKey == null)
            {
                ActionLog_Write("Error - " + email + ": Email does not exist!");
                Console.WriteLine("Error - " + email + ": Email does not exist!");
                throw new Exception("Invalid user");
            }
            Message message = new Message(publicKey);
            message.AddComment("Email",email);
            message.Sign(core.PrivateKey);
            String result = message.ToString();
            return result;
        }