Пример #1
0
        // update  more info For The Certificate
        public int UpdateCertificateInfo(string Cert, int reqid)
        {
            StreamWriter objFile = null;

            try
            {
                objFile = File.CreateText("c:\\" + reqid + ".cer");
                objFile.Write(Cert);
                objFile.Close();
                X509Certificate2 cert = new X509Certificate2("c:\\" + reqid + ".cer");
                File.Delete("c:\\" + reqid + ".cer");

                using (caProjectEntities context = new caProjectEntities())
                {
                    cert cetificate = context.certs.FirstOrDefault(r => r.RequestId == reqid);
                    cetificate.ExpiredDate  = Convert.ToDateTime(cert.NotAfter.ToString("yyyy/MM/dd hh:mm:ss tt"));
                    cetificate.Issuedby     = cert.Issuer.ToString();
                    cetificate.serialnumber = cert.GetSerialNumberString();
                    context.SaveChanges();
                }
                return(0);
            }
            catch (Exception ex)
            {
                if (objFile != null)
                {
                    objFile.Close();
                }
                Console.Write(ex.Message);
                return(-1);
            }
        }
Пример #2
0
 public cert ReturnCertificateInformation(string hostname)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         cert cetificate = context.certs.FirstOrDefault(r => r.HostName == hostname);
         return(cetificate);
     }
 }
Пример #3
0
 //delete cert record for expired certificate
 public void DeleteCertificateRecordFromDb(int reqid)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         cert cetificate = context.certs.FirstOrDefault(r => r.RequestId == reqid);
         context.certs.Remove(cetificate);
         context.SaveChanges();
     }
 }
Пример #4
0
 //update certFlag for unlock
 public void UnlockCetificate(string hostname)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         cert cetificate = context.certs.FirstOrDefault(r => r.HostName == hostname);
         cetificate.CertFlag = null;
         context.SaveChanges();
     }
 }
Пример #5
0
 //update Certification Status and cert Flag
 public void UpdateUnlockFlagAndStatus(int status, int reqid)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         cert cetificate = context.certs.FirstOrDefault(r => r.RequestId == reqid);
         cetificate.status = status;
         if (status == 3) //issued
         {
             cetificate.CertFlag = "true";
         }
         context.SaveChanges();
     }
 }
Пример #6
0
 // Inserts First info For The Certificate
 public void   InsertToCertificateTable(string hostname, int status, int reqid)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         cert cetificate = new cert()
         {
             CreationDate = DateTime.Now.ToString("yyyyMMdd", System.Globalization.CultureInfo.GetCultureInfo("en-US")),
             RequestId    = reqid,
             HostName     = hostname,
             status       = status
         };
         context.certs.Add(cetificate);
         context.SaveChanges();
     }
 }
Пример #7
0
 //checking if there is allready Request for the hostname
 public int CheckIfCertificateExists(string hostname)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         cert cetificate = context.certs.FirstOrDefault(r => r.HostName == hostname);
         if (cetificate != null)
         {
             if (cetificate.Issuedby == null)
             {
                 return(1);
             }
             return(2);
         }
         return(0);
     }
 }
Пример #8
0
 // Inserts Error Message
 public void InsertToErrorMessageTable(string hostname, int requestid, string errorMessage, string functionName)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         Error_Log erroLog = new Error_Log()
         {
             ErrorMessage = errorMessage,
             Request      = requestid,
             CreateDate   = DateTime.Now.ToString(),
             HostName     = hostname,
             functionName = functionName
         };
         context.Error_Logs.Add(erroLog);
         context.SaveChanges();
     }
 }
Пример #9
0
 // Inserts First info For The Certificate
 public void InsertToSigntureTable(string ClientId, string Hash, string Username)
 {
     using (caProjectEntities context = new caProjectEntities())
     {
         DateTime  dt        = DateTime.Now;
         signature signature = new signature()
         {
             hash      = Hash,
             uuid      = ClientId,
             username  = Username,
             timestamp = BitConverter.GetBytes(dt.Ticks),
             ldtdisk   = "N"
         };
         context.signatures.Add(signature);
         context.SaveChanges();
     }
 }
Пример #10
0
        //return all the expired certificates
        public List <cert> GetAllExpiredCertificates()
        {
            List <cert> result = null;

            try
            {
                using (caProjectEntities context = new caProjectEntities())
                {
                    result = context.certs.Where(certificate => certificate.ExpiredDate.HasValue && (certificate.ExpiredDate.Value < DateTime.Now)).ToList();
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return(null);
            }

            return(result);
        }
Пример #11
0
        //checking if there is allready Request for the hostname
        public bool CheckIfMachineExists(string hostid, string hase)
        {
            try
            {
                using (caProjectEntities context = new caProjectEntities())
                {
                    signature machine = context.signatures.FirstOrDefault(r => r.uuid == hostid);
                    if (machine != null && machine.hash == hase)
                    {
                        return(true);
                    }
                    return(false);
                }
            }

            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return(false);
            }
        }
Пример #12
0
        //check if the hostnameand redid belong to each other
        public bool CheckIfReqIDBelongToHost(int reqid, string hostname)
        {
            try
            {
                using (caProjectEntities context = new caProjectEntities())
                {
                    cert cetificate = context.certs.FirstOrDefault(r => r.RequestId == reqid);
                    if (cetificate != null && cetificate.HostName == hostname)
                    {
                        return(false);
                    }
                    return(true);
                }
            }

            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return(true);
            }
        }
Пример #13
0
        //check if the cerrtficate allready consumed
        public bool CheckIfCertificateConsumed(int reqid)
        {
            try
            {
                using (caProjectEntities context = new caProjectEntities())
                {
                    cert cetificate = context.certs.FirstOrDefault(r => r.RequestId == reqid);
                    if (cetificate.CertFlag == null)
                    {
                        return(false);
                    }
                    return(true);
                }
            }

            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return(false);
            }
        }