Ejemplo n.º 1
1
        private void btn_savepfx_Click(object sender, RoutedEventArgs e)
        {
            string passwd = txt_Pfxpasswd.Password;
            string caserver = txt_CAServer.Text;
            string dir = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();

            if (Certs.Count == 0)
            {
                MessageBox.Show("No Request(s) To Save");
                return;
            }

            foreach (Certificates c in Certs)
            {
                if (c.Status != "File Created!" && c.Status == "certificate issued")
                {

                CX509Enrollment objEnroll = new CX509EnrollmentClass();
                var objCertRequest = new CCertRequest();

                var iDisposition = objCertRequest.RetrievePending(Convert.ToInt32(c.ID), caserver);

                if (Convert.ToInt32(iDisposition) == 3)
                {
                    var cert = objCertRequest.GetCertificate(CR_OUT_BASE64 | CR_OUT_CHAIN);

                    objEnroll.Initialize(X509CertificateEnrollmentContext.ContextUser);
                    objEnroll.InstallResponse(
                        InstallResponseRestrictionFlags.AllowUntrustedRoot,
                        cert,
                        EncodingType.XCN_CRYPT_STRING_BASE64,
                        null
                    );

                    c.Status = "File Created!";

                    var fil = objEnroll.CreatePFX(passwd, PFXExportOptions.PFXExportChainWithRoot, EncodingType.XCN_CRYPT_STRING_BASE64);
                    System.IO.File.WriteAllText(dir + @"\" + c.FQDN + ".pfx", fil);
                }

            }

            }
        }
Ejemplo n.º 2
0
        public string RetrieveCertStatus(int id, string caServer)
        {
            int strDisposition;
            var msg = "";

            var objCertRequest = new CCertRequest();

            strDisposition = objCertRequest.RetrievePending(id, caServer);

            switch (strDisposition)
            {
            case (int)RequestDisposition.CR_DISP_INCOMPLETE:
                msg = "incomplete certificate";
                break;

            case (int)RequestDisposition.CR_DISP_DENIED:
                msg = "request denied";
                break;

            case (int)RequestDisposition.CR_DISP_ISSUED:
                msg = "certificate issued";
                break;

            case (int)RequestDisposition.CR_DISP_UNDER_SUBMISSION:
                msg = "request pending";
                break;

            case (int)RequestDisposition.CR_DISP_REVOKED:
                msg = "certificate revoked";
                break;
            }

            return(msg);
        }
Ejemplo n.º 3
0
        //get the certifacte status from the ca
        public int retrieveStatus(int requestID, string hostname)
        {
            int          iDisposition;
            string       strCAConfig;
            CCertConfig  objCertConfig  = new CCertConfig();
            CCertRequest objCertRequest = new CCertRequest();

            try
            {
                SqlLite sql = new SqlLite();
                /*Cheking if host name and req is belong to each other*/
                if (sql.checkHostnameWithreqID(requestID, hostname))
                {
                    return(-6);
                }
                if (sql.checkcertFlag(requestID)) //checking if the client allreay consumed the certificate
                {
                    return(-3);
                }



                strCAConfig  = objCertConfig.GetConfig(CC_DEFAULTCONFIG);              //connect to the ca
                iDisposition = objCertRequest.RetrievePending(requestID, strCAConfig); //retrive the certifcate status  from the ca
                sql.updateTable(iDisposition, requestID);                              //updat certificate table with more information about the cert
                return(iDisposition);                                                  //return cert status
            }

            catch (Exception ex)
            {
                Console.Write(ex.Message);
                return(-2);
            }
        }
Ejemplo n.º 4
0
        //get the issue Certificate from the ca
        public string GetCertificate(int requestID)
        {
            int      iDisposition;
            int      status = 0;
            string   strCAConfig;
            string   pstrCertificate;
            Database db = new Database();

            pstrCertificate = null;
            CCertConfig  objCertConfig  = new CCertConfig();
            CCertRequest objCertRequest = new CCertRequest();

            try
            {
                strCAConfig     = objCertConfig.GetConfig(CC_DEFAULTCONFIG);              //connect to the ca
                iDisposition    = objCertRequest.RetrievePending(requestID, strCAConfig); //getting certificate stauts must before getting the cert
                pstrCertificate = objCertRequest.GetCertificate(CR_OUT_BASE64);           //retrive the Certificate
                status          = db.UpdateCertificateInfo(pstrCertificate, requestID);   //update cert with more information
                if (status == 0)
                {
                    Certificate cert = new Certificate {
                        CertValue = pstrCertificate
                    };                                                                   //creatre cert with JSON type
                    string certJson = Newtonsoft.Json.JsonConvert.SerializeObject(cert); //creatre cert with JSON type
                    return(certJson);                                                    //return certificate
                }

                else
                {
                    return("error Update Certificate Table");
                }
            }

            catch (Exception ex)
            {
                db.InsertToErrorMessageTable("", requestID, ex.Message, "GetCertificate");//insert Error Message into The Error Table Log In The DataBase
                return("error" + ex.Message);
            }
        }
Ejemplo n.º 5
0
        //get the certifacte status from the ca
        public int RetrieveRequestStatus(int requestID, string hostname)
        {
            int          iDisposition;
            string       strCAConfig;
            CCertConfig  objCertConfig  = new CCertConfig();
            CCertRequest objCertRequest = new CCertRequest();

            try
            {
                Database db = new Database();
                /*Cheking if host name and req is belong to each other*/

                if (db.CheckIfReqIDBelongToHost(requestID, hostname))
                {
                    return(-6);
                }
                if (db.CheckIfCertificateConsumed(requestID)) //checking if the client allreay consumed the certificate
                {
                    return(-3);
                }



                strCAConfig  = objCertConfig.GetConfig(CC_DEFAULTCONFIG);              //connect to the ca
                iDisposition = objCertRequest.RetrievePending(requestID, strCAConfig); //retrive the certifcate status  from the ca
                db.UpdateUnlockFlagAndStatus(iDisposition, requestID);                 //updat certificate table with more information about the cert
                return(iDisposition);                                                  //return cert status
            }

            catch (Exception ex)
            {
                Database db = new Database();
                db.InsertToErrorMessageTable(hostname, requestID, ex.Message, "RetrieveRequestStatus");//insert Error Message into The Error Table Log In The DataBase
                return(-2);
            }
        }
Ejemplo n.º 6
0
        private void btn_savecer_Click(object sender, RoutedEventArgs e)
        {
            string caserver = txt_CAServer.Text;
            string dir = Directory.GetParent(Assembly.GetExecutingAssembly().Location).ToString();

            if (Certs.Count == 0)
            {
                MessageBox.Show("No Request(s) To Save");
                return;
            }

            foreach (Certificates c in Certs)
            {
                var objCertRequest = new CCertRequest();
                int reqid = Convert.ToInt32(c.ID);

                var iDisposition = objCertRequest.RetrievePending(reqid, caserver);
                if (Convert.ToInt32(iDisposition) == 3)
                {
                    string cert = objCertRequest.GetCertificate(0);
                    System.IO.File.WriteAllText(dir + @"\" + c.FQDN + ".cer", cert);

                    c.Status = "File Created!";
                }
            }
        }