Beispiel #1
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();
        }
        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;
            }
        }
        private void preNext()
        {
            currentPanel.Enabled = false;

            core = new Core("", false);

            if (File.Exists(Path.Combine(core.ApplicationDataFolder, "server.key")))
            {
                if (File.Exists(core.KeyFile))
                {
                    if (
                        MessageBox.Show("Are you ABSOLUTELY sure that you want to delete your existing keys FOREVER?",
                                        "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                        DialogResult.Yes)
                    {
                        File.Delete(core.KeyFile);
                    }
                    else
                    {
                        currentPanel.Enabled = true;
                        return;
                    }
                }

                SetStatus("Reading Server Key...");
                serverKey = File.ReadAllText(Path.Combine(core.ApplicationDataFolder, "server.key"));

                SetStatus("Initializing Keys...");
                String passphrase = "";

                if (currentPanel == initializationPanel)
                    passphrase = Passphrase.Text;
                else if (currentPanel == passphrasePanel)
                    passphrase = genericPassphrase.Text;

                core.InitializeKeys(passphrase);

                if (currentPanel == initializationPanel)
                {
                    SetStatus("Writing Identity...");
                    username = Username.Text;
                    email = Email.Text;

                    StreamWriter sw = new StreamWriter(Path.Combine(core.ApplicationDataFolder, "identity"));
                    sw.WriteLine(username);
                    sw.WriteLine(email);
                    sw.Close();
                }
                else if(currentPanel == passphrasePanel)
                {
                    SetStatus("Reading Identity...");
                    StreamReader sr = new StreamReader(Path.Combine(core.ApplicationDataFolder, "identity"));
                    username = sr.ReadLine();
                    email = sr.ReadLine();
                    sr.Close();
                }

                SetStatus("Connecting to Server...");
                server = (IServer)Activator.GetObject(typeof(IServer), "http://" + serverURL + "/PractiSES");
            }
            else
            {
                MessageBox.Show("Server key not installed. Please download server key and install it.", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                currentPanel.Enabled = true;
                return;
            }
        }
Beispiel #4
0
 public Client(String host)
 {
     this.host = host;
     core = new Core("", false);
     serverKey = File.ReadAllText(Path.Combine(core.ApplicationDataFolder, "server.key"));
 }
Beispiel #5
0
        //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;
        }
Beispiel #6
0
 private void ErrorLog_Write(String logMessage)
 {
     Core core = new Core(Server.passphrase, false);
     StreamWriter writer = new StreamWriter(core.ErrorLogFile, true);
     writer.WriteLine(beginProtocol);
     writer.Write(DateTime.Now.ToString() + Core.space);
     String[] logMessageArray = logMessage.Split('\n');
     foreach (String element in logMessageArray)
     {
         writer.WriteLine(element);
     }
     //writer.WriteLine(logMessage);
     writer.Close();
 }
Beispiel #7
0
        private bool EnvelopeAnswers(String userID, String email, String answersEnveloped, String bodyMsg)
        {
            DatabaseConnection connection = new DatabaseConnection();
            String dbUserid = connection.getUserID(email);
            //connection.close();
            if (userID == null)
            {
                ErrorLog_Write(email + ": Email does not exist!");
                Console.WriteLine(email + ": Email does not exist!");
                throw new Exception("Invalid user");
            }
            if (userID != dbUserid)
            {
                ErrorLog_Write(email + ": User id does not exist!");
                Console.WriteLine(email + ": User id does not exist!");
                throw new Exception("Invalid user");
            }
            Core core = new Core(Server.passphrase);
            String privateKey = core.PrivateKey;

            Rijndael aes = Rijndael.Create();
            AESInfo aesInfo = Crypto.Destruct(answersEnveloped, privateKey);
            String answers = Encoding.UTF8.GetString(Crypto.AESDecrypt(aesInfo.message, aes.CreateDecryptor(aesInfo.key, aesInfo.IV)));

            //  connection = new DatabaseConnection();
            String dbAnswers = connection.getAnswers(email);
            connection.close();
            if (answers == dbAnswers)
            {
                SendMail(email, aesInfo, bodyMsg);
                return true;
            }
            else
            {
                //protocol stops and socket is closed.
                ErrorMail(email);
                ErrorLog_Write("Error - " + email + ": Answers are not correct!");
                Console.WriteLine("Error - " + email + ": Answers are not correct!");
                throw new Exception("Answers are not correct");
            }
        }
Beispiel #8
0
        private String AskQuestions(String userID, String email)
        {
            Core core = new Core(Server.passphrase);
            DatabaseConnection connection = new DatabaseConnection();
            String dbUserid = connection.getUserID(email);
            connection.close();

            if (userID == null)
            {
                ErrorLog_Write(email + ": Email does not exist!");
                Console.WriteLine(email + ": Email does not exist!");
                throw new Exception("Invalid user");
            }
            if (userID != dbUserid)
            {
                ErrorLog_Write(email + ": User id does not exist!");
                Console.WriteLine(email + ": User id does not exist!");
                throw new Exception("Invalid user");
            }
            String questions = core.ReadSettingsFile();
            Message result = new Message(questions);
            result.Sign(core.PrivateKey);
            return result.ToString();
        }