clientcert.aspx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!-- you need an updated XSP to handle this correctly -->
  2. <%@ Page language="c#" %>
  3. <html>
  4. <head>
  5. <script runat="server">
  6. string GetValue (byte[] data)
  7. {
  8. if ((data == null) || (data.Length == 0))
  9. return "(empty)";
  10. return BitConverter.ToString (data);
  11. }
  12. void Page_Load (object sender, EventArgs e)
  13. {
  14. System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  15. HttpClientCertificate hcc = Request.ClientCertificate;
  16. if (hcc.IsPresent) {
  17. sb.Append ("Client certificate retrieved.");
  18. sb.AppendFormat ("\n<br>BinaryIssuer: {0}", GetValue (hcc.BinaryIssuer));
  19. sb.AppendFormat ("\n<br>CertEncoding: {0}", hcc.CertEncoding);
  20. sb.AppendFormat ("\n<br>Certificate: {0}", GetValue (hcc.Certificate));
  21. sb.AppendFormat ("\n<br>Cookie: {0}", hcc.Cookie);
  22. sb.AppendFormat ("\n<br>Flags: {0}", hcc.Flags);
  23. sb.AppendFormat ("\n<br>IsValid: {0}", hcc.IsValid);
  24. sb.AppendFormat ("\n<br>KeySize: {0}", hcc.KeySize);
  25. sb.AppendFormat ("\n<br>PublicKey: {0}", GetValue (hcc.PublicKey));
  26. sb.AppendFormat ("\n<br>SecretKeySize: {0}", hcc.SecretKeySize);
  27. sb.AppendFormat ("\n<br>SerialNumber: {0}", hcc.SerialNumber);
  28. sb.AppendFormat ("\n<br>ServerIssuer: {0}", hcc.ServerIssuer);
  29. sb.AppendFormat ("\n<br>ServerSubject: {0}", hcc.ServerSubject);
  30. sb.AppendFormat ("\n<br>Subject: {0}", hcc.Subject);
  31. sb.AppendFormat ("\n<br>ValidFrom: {0}", hcc.ValidFrom);
  32. sb.AppendFormat ("\n<br>ValidUntil: {0}", hcc.ValidUntil);
  33. System.Security.Cryptography.X509Certificates.X509Certificate cert = new System.Security.Cryptography.X509Certificates.X509Certificate (hcc.Certificate);
  34. sb.AppendFormat ("\n<br>X509Certificate: {0}", cert.ToString (true).Replace ("\n", "\n<br>"));
  35. } else {
  36. sb.Append ("No client certificate");
  37. if (Request.IsSecureConnection) {
  38. sb.Append (" was sent during negotiation.");
  39. } else {
  40. sb.Append (", and this can't work unless you use HTTPS!");
  41. }
  42. }
  43. info.Text = sb.ToString ();
  44. }
  45. </script>
  46. </head>
  47. <body>
  48. <form runat="server">
  49. <asp:Label id="info" runat="server" />
  50. </form>
  51. </body>
  52. </html>