Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I wrote a identification web page a while back that looked for a client certificate and if found would display the certificate information. I believe that is what you are looking for... Here is the page:</p> <pre><code>&lt;%@ Page Language="C#" Trace="false" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;%@ Import Namespace="System.Security.Cryptography.X509Certificates" %&gt; &lt;%@ Import Namespace="System.Security.Cryptography" %&gt; &lt;script runat="server"&gt; //protected void Page_Load(object sender, EventArgs e) //{ } void LoadCertInfo() { string para = "&lt;div style='margin: 10px 0 0 0; font-weight: bold'&gt;{0}&lt;/div&gt;"; string subpara = "&lt;div style='margin-left: 15px; font-size: 90%'&gt;{0}&lt;/div&gt;"; if (Page.Request.ClientCertificate.IsPresent) { Response.Write("&lt;hr /&gt;&lt;div style='width: 500px; margin: 20px auto'&gt;"); Response.Write("&lt;h3 style='width: 500px; margin: 20px auto'&gt;Client Certificate Information&lt;/h3&gt;"); try { X509Certificate2 x509Cert2 = new X509Certificate2(Page.Request.ClientCertificate.Certificate); Response.Write(string.Format(para, "Issued To:")); Response.Write(string.Format(subpara, x509Cert2.Subject)); Response.Write(string.Format(para, "Issued By:")); Response.Write(string.Format(subpara, x509Cert2.Issuer)); Response.Write(string.Format(para, "Friendly Name:")); Response.Write(string.Format(subpara, string.IsNullOrEmpty(x509Cert2.FriendlyName) ? "(None Specified)" : x509Cert2.FriendlyName)); Response.Write(string.Format(para, "Valid Dates:")); Response.Write(string.Format(subpara, "From: " + x509Cert2.GetEffectiveDateString())); Response.Write(string.Format(subpara, "To: " + x509Cert2.GetExpirationDateString())); Response.Write(string.Format(para, "Thumbprint:")); Response.Write(string.Format(subpara, x509Cert2.Thumbprint)); //Response.Write(string.Format(para, "Public Key:")); //Response.Write(string.Format(subpara, x509Cert2.GetPublicKeyString())); #region EKU Section - Retrieve EKU info and write out each OID X509EnhancedKeyUsageExtension ekuExtension = (X509EnhancedKeyUsageExtension)x509Cert2.Extensions["Enhanced Key Usage"]; if (ekuExtension != null) { Response.Write(string.Format(para, "Enhanced Key Usages (" + ekuExtension.EnhancedKeyUsages.Count.ToString() + " found)")); OidCollection ekuOids = ekuExtension.EnhancedKeyUsages; foreach (Oid ekuOid in ekuOids) Response.Write(string.Format(subpara, ekuOid.FriendlyName + " (OID: " + ekuOid.Value + ")")); } else { Response.Write(string.Format(para, "No EKU Section Data")); } #endregion // EKU Section #region Subject Alternative Name Section X509Extension sanExtension = (X509Extension)x509Cert2.Extensions["Subject Alternative Name"]; if (sanExtension != null) { Response.Write(string.Format(para, "Subject Alternative Name:")); Response.Write(string.Format(subpara, sanExtension.Format(true))); } else { Response.Write(string.Format(para, "No Subject Alternative Name Data")); } #endregion // Subject Alternative Name Section #region Certificate Policies Section X509Extension policyExtension = (X509Extension)x509Cert2.Extensions["Certificate Policies"]; if (policyExtension != null) { Response.Write(string.Format(para, "Certificate Policies:")); Response.Write(string.Format(subpara, policyExtension.Format(true))); } else { Response.Write(string.Format(para, "No Certificate Policies Data")); } #endregion //Certificate Policies Section // Example on how to enumerate all extensions //foreach (X509Extension extension in x509Cert2.Extensions) // Response.Write(string.Format(para, extension.Oid.FriendlyName + "(" + extension.Oid.Value + ")")); } catch (Exception ex) { Response.Write(string.Format(para, "An error occured:")); Response.Write(string.Format(subpara, ex.Message)); Response.Write(string.Format(subpara, ex.StackTrace)); } finally { Response.Write("&lt;/div&gt;"); } } } &lt;/script&gt; &lt;html&gt; &lt;head runat="server"&gt; &lt;title&gt;&lt;% Page.Response.Write(System.Environment.MachineName); %&gt;&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;% LoadCertInfo(); %&gt; &lt;/body&gt; &lt;/html&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload