Example #1
0
 public async Task SubmitCertificate()
 {
     await AutoCaller(
         this.Model.CanSubmitCertificate,
         this.Model.AutoSubmitCertificate,
         this.Model.AutoSubmitCertificateRetry,
         this.Model.AutoSubmitCertificateTimer,
         async() =>
     {
         if (this.Model.CurrentAuthState.Value.Status == "valid")
         {
             var certificateInfo = new GetCertificate {
                 CertificateRef = this.Model.Certificate.Value
             }.GetValue <CertificateInfo>();
             // NOTE: If you have existing keys you can use them as well, this is good to do if you want to use HPKP
             // new NewCertificate { IdentifierRef = idref, Alias = "cert1", KeyPemFile = "path\\to\\key.pem", CsrPemFile = "path\\to\\csr.pem" }.Run();
             //certificateInfo = new SubmitCertificate { PkiTool = BouncyCastleProvider.PROVIDER_NAME, CertificateRef = "cert1" }.GetValue<CertificateInfo>();
             if (certificateInfo.CertificateRequest == null)
             {
                 this.Model.CurrentCertificate.Value =
                     new SubmitCertificate
                 {
                     CertificateRef = this.Model.Certificate.Value,
                     Force          = SwitchParameter.Present
                 }
             }
 /// IDataErrorInfo
 public string this[string propertyName] {
     get {
         string result = String.Empty;
         if (propertyName == "ServerPath")
         {
             result = ServerPathValidation();
         }
         if (propertyName == "AgentPath")
         {
             result = AgentPathValidation();
         }
         if (propertyName == "BackupPath")
         {
             result = BackupPathValidation();
         }
         if (propertyName == "Hostname")
         {
             if (string.IsNullOrEmpty(Hostname))
             {
                 return("Enter valid hostname");
             }
             if (_hostname != GetCertificate.GetCertIssuedTo())
             {
                 return("Hostname doesn't match certificate");
             }
         }
         if (propertyName == "DexServerPort")
         {
             if (string.IsNullOrEmpty(_dexServerPort))
             {
                 return(result);
             }
             var isNumeric = int.TryParse(_dexServerPort, out int n);
             if (!isNumeric)
             {
                 result = "Must be valid port";
             }
         }
         if (propertyName == "CertThumbprint")
         {
             return(CertThumbprintValidation());
         }
         if (propertyName == "BackupState")
         {
             //if (string.IsNullOrEmpty(backupState))
             //{
             //    result = "needs backup";
             //}
         }
         return(result);
     }
 }
        public string CertThumbprintValidation()
        {
            var result = string.Empty;

            if (string.IsNullOrEmpty(certThumbprint))
            {
                return("Enter Thumbprint");
            }
            else if (!CertThumbprintIsValid(certThumbprint))
            {
                return("Enter valid thumbprint");
            }

            else if (!GetCertificate.CertificateFound(certThumbprint))
            {
                result = "Cert not found in Trusted Root";
            }
            GetCertificate.SetCertificateWithThumbprint(certThumbprint);
            Hostname = GetCertificate.GetCertIssuedTo();

            return(result);
        }
        private async void btnComplete_Click(object sender, EventArgs e)
        {
            string sURL        = this.txtChallenge.Text;
            bool   onceMessage = false;

            if (!string.IsNullOrEmpty(sURL))
            {
                while (true)
                {
                    var wrGETURL = WebRequest.Create(sURL + "/index.html") as HttpWebRequest;
                    //WebProxy myProxy = new WebProxy("myproxy", 80);
                    //myProxy.BypassProxyOnLocal = true;
                    //wrGETURL.Proxy = myProxy;
                    wrGETURL.Proxy = WebRequest.GetSystemWebProxy();

                    HttpWebResponse response;
                    try
                    {
                        response = wrGETURL.GetResponse() as HttpWebResponse;
                    }
                    catch (WebException ex)
                    {
                        response = ex.Response as HttpWebResponse;
                    }

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        using (Stream objStream = response.GetResponseStream())
                        {
                            var objReader = new StreamReader(objStream);
                            var str       = objReader.ReadToEnd();

                            if (str == this.txtKey.Text)
                            {
                                break;
                            }
                        }
                    }

                    await Task.Delay(1000);

                    if (!onceMessage)
                    {
                        this.listBox1.Items.Add("Waiting for file to be uploaded.");
                    }
                    onceMessage = true;
                }
            }

            var idref = Registrator.GetIdentifier(this.txtDomain.Text);
            var state = new UpdateIdentifier {
                IdentifierRef = idref
            }.GetValue <AuthorizationState>();

            if (state.Status != "valid")
            {
                state =
                    new SubmitChallenge {
                    IdentifierRef = idref, ChallengeType = "http-01"
                }.GetValue <AuthorizationState>();
                int countPending = 0;
                while (state.Status == "pending")
                {
                    this.listBox1.Items.Add("Status is still 'pending', waiting for it to change...");
                    await Task.Delay((countPending + 1) * 1000);

                    state = new UpdateIdentifier {
                        IdentifierRef = idref
                    }.GetValue <AuthorizationState>();
                    countPending++;
                }
            }

            if (state.Status == "valid")
            {
                var certificateInfo = new GetCertificate {
                    CertificateRef = "cert1"
                }.GetValue <CertificateInfo>();

                if (certificateInfo == null)
                {
                    new NewCertificate {
                        IdentifierRef = idref, Alias = "cert1", Generate = SwitchParameter.Present
                    }
                }