Exemple #1
0
 private void btnCertificateSelect_Click(object sender, EventArgs e)
 {
     ClientCert cert = new ClientCert();
     X509Certificate2 certificate = cert.Select(this, "クライアント証明書選択", "インターネット接続に使用するクライアント証明書を選択してください。", true);
     if (certificate != null)
     {
         string thumbprint = certificate.Thumbprint;
         cert.ValidDays(thumbprint);
         this.txbIssuerName.Text = cert.DisplayIssuerName(certificate);
         this.txbCertificateDate.Text = certificate.NotAfter.ToString("yyyy/MM/dd", DateTimeFormatInfo.InvariantInfo);
         this.CertHash = certificate.GetCertHashString();
     }
 }
Exemple #2
0
        private HttpResult SetClientCert()
        {
            try
            {
                ServicePointManager.ServerCertificateValidationCallback = null;
                if (this.mSettings.UseHttps)
                {
                    this.mTrace.WriteString(this.mTracekind, string.Format("# {0,-16} : status[{1}]", "SetClientCert", this.mStatus));
                    if (!string.IsNullOrEmpty(this.mSettings.ClientCertificateHash))
                    {
                        ClientCert cert = new ClientCert();
                        switch (cert.ValidDays(this.mSettings.ClientCertificateHash))
                        {
                            case -1:
                                return HttpResult.CertUnestablishedError;

                            case -2:
                                return HttpResult.CertSelectError;

                            case -3:
                                return HttpResult.CertValidError;
                        }
                        X509Certificate2 certificate = cert.Find(this.mSettings.ClientCertificateHash);
                        if (certificate == null)
                        {
                            return HttpResult.CertSelectError;
                        }
                        this.mRequest.ClientCertificates = new X509Certificate2Collection();
                        this.mRequest.ClientCertificates.Add(certificate);
                    }
                    ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(this.OnRemoteCertValidation);
                }
            }
            catch (Exception exception)
            {
                this.mTrace.WriteString(this.mTracekind, string.Format("! {0,-16} : {1} \r\n{2}", "SetClientCert", exception.GetType(), exception.Message));
                return HttpResult.CertException;
            }
            return HttpResult.None;
        }