Exemple #1
0
        /// <summary>
        /// Replicates generated certificate
        /// </summary>
        /// <param name="userName">Certificate file name</param>
        /// <param name="password">Password for .pvk file</param>
        private void Replicate(string userName, string password)
        {
            /// try-catch necessary if either the speficied file doesn't exist or password is incorrect
            try
            {
                X509Certificate2 certificate;
                if (password == "")
                {
                    certificate = new X509Certificate2(userName + ".cer");
                }
                else
                {
                    certificate = new X509Certificate2(userName + ".cer", password);
                }

                NetTcpBinding binding = new NetTcpBinding();
                InitializeWindowsAuthentication(binding);
                EndpointAddress address = new EndpointAddress(new Uri(ConfigurationSettings.AppSettings.Get("BackUp")));
                using (WCFBackupClient proxy = new WCFBackupClient(binding, address))
                {
                    message  = String.Format("Client {0} with certificate[Subject {1}] successfully replicated.", userName, certificate.Subject);
                    evntType = EventLogEntryType.SuccessAudit;
                    EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.ReplicateSuccess));
                    proxy.ReplicateCertificate(certificate.Subject + ", thumbprint: " + certificate.Thumbprint);
                }
            }
            catch (Exception e)
            {
                message  = String.Format("Error with replicating client {0} certificate.Error: {1}", userName, e.Message);
                evntType = EventLogEntryType.SuccessAudit;
                EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.ReplicateFailure));
                Console.WriteLine("Error while trying to replicate certificate {0}. ERROR = {1}", userName, e.Message);
            }
        }
Exemple #2
0
        private void AddToRevocationList(X509Certificate2 cert)
        {
            using (StreamWriter sw = new StreamWriter("RevocationList.txt", true))
            {
                sw.WriteLine(cert.Thumbprint);
            }
            NetTcpBinding binding = new NetTcpBinding();

            InitializeWindowsAuthentication(binding);
            EndpointAddress address = new EndpointAddress(new Uri(ConfigurationSettings.AppSettings.Get("BackUp")));

            try
            {
                using (WCFBackupClient proxy = new WCFBackupClient(binding, address))
                {
                    message  = String.Format("Revocation list successfully replicated.");
                    evntType = EventLogEntryType.SuccessAudit;
                    EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.ReplicateSuccess));
                    proxy.ReplicateRevokedCert(cert.Subject + ", thumbprint: " + cert.Thumbprint);
                }
            }
            catch (Exception e)
            {
                message  = String.Format("Error with replicating revocation list.Error: {0}", e.Message);
                evntType = EventLogEntryType.FailureAudit;
                EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.ReplicateFailure));
                Console.WriteLine("Error while trying to replicate certificate {0}. ERROR = {1}", cert.Subject, e.Message);
            }
        }
Exemple #3
0
        public void createRootCertificate(string root)
        {
            if (File.Exists(root + ".cer"))
            {
                Console.WriteLine("Self-signed certificate <{0}> already exists", root);
                return;
            }

            Process          p         = new Process();
            string           path      = (AppDomain.CurrentDomain.BaseDirectory + @"\makecert.exe");
            string           arguments = string.Format("-n \"CN = {0}\" -r -sv {0}.pvk {0}.cer", root);
            ProcessStartInfo info      = new ProcessStartInfo(path, arguments);

            p.StartInfo = info;
            try
            {
                p.Start();
            }
            catch (Exception e)
            {
                message  = String.Format("Root certificate {0} cannot be generated.Error: {1}", root, e.Message);
                evntType = EventLogEntryType.FailureAudit;
                EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.GenerateFailure));
                return;
            }
            message  = String.Format("Root certificate {0} generated.", root);
            evntType = EventLogEntryType.SuccessAudit;
            EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.GenerateSuccess));
            p.WaitForExit();
            p.Dispose();

            Console.WriteLine("Created new self-signed certificate");

            /// try-catch necessary if either the speficied file doesn't exist or password is incorrect
            try
            {
                X509Certificate2 certificate = new X509Certificate2(root + ".cer");
                NetTcpBinding    binding     = new NetTcpBinding();
                InitializeWindowsAuthentication(binding);
                EndpointAddress address = new EndpointAddress(new Uri(ConfigurationSettings.AppSettings.Get("BackUp")));
                using (WCFBackupClient proxy = new WCFBackupClient(binding, address))
                {
                    message  = String.Format("Root certificate {0} successfully replicated.", root);
                    evntType = EventLogEntryType.SuccessAudit;
                    EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.ReplicateSuccess));
                    proxy.ReplicateCertificate(certificate.Subject + ", thumbprint: " + certificate.Thumbprint);
                }
            }
            catch (Exception e)
            {
                message  = String.Format("Root certificate {0} failed to replicate.Error: {1}", root, e.Message);
                evntType = EventLogEntryType.FailureAudit;
                EventLogManager.WriteEntryCMS(message, evntType, Convert.ToInt32(IDType.ReplicateFailure));
                Console.WriteLine("Error while trying to replicate certificate {0}. ERROR = {1}", root, e.Message);
            }
        }