CefX509Certificate.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. namespace Xilium.CefGlue
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Runtime.InteropServices;
  7. using Xilium.CefGlue.Interop;
  8. /// <summary>
  9. /// Class representing a X.509 certificate.
  10. /// </summary>
  11. public sealed unsafe partial class CefX509Certificate
  12. {
  13. /// <summary>
  14. /// Returns the subject of the X.509 certificate. For HTTPS server
  15. /// certificates this represents the web server. The common name of the
  16. /// subject should match the host name of the web server.
  17. /// </summary>
  18. public CefX509CertPrincipal GetSubject()
  19. {
  20. return CefX509CertPrincipal.FromNative(
  21. cef_x509certificate_t.get_subject(_self)
  22. );
  23. }
  24. /// <summary>
  25. /// Returns the issuer of the X.509 certificate.
  26. /// </summary>
  27. public CefX509CertPrincipal GetIssuer()
  28. {
  29. return CefX509CertPrincipal.FromNative(
  30. cef_x509certificate_t.get_issuer(_self)
  31. );
  32. }
  33. /// <summary>
  34. /// Returns the DER encoded serial number for the X.509 certificate. The value
  35. /// possibly includes a leading 00 byte.
  36. /// </summary>
  37. public CefBinaryValue GetSerialNumber()
  38. {
  39. var n_result = cef_x509certificate_t.get_serial_number(_self);
  40. return CefBinaryValue.FromNative(n_result);
  41. }
  42. /// <summary>
  43. /// Returns the date before which the X.509 certificate is invalid.
  44. /// CefTime.GetTimeT() will return 0 if no date was specified.
  45. /// </summary>
  46. public DateTime GetValidStart()
  47. {
  48. var n_result = cef_x509certificate_t.get_valid_start(_self);
  49. return cef_time_t.ToDateTime(&n_result);
  50. }
  51. /// <summary>
  52. /// Returns the date after which the X.509 certificate is invalid.
  53. /// CefTime.GetTimeT() will return 0 if no date was specified.
  54. /// </summary>
  55. public DateTime GetValidExpiry()
  56. {
  57. var n_result = cef_x509certificate_t.get_valid_expiry(_self);
  58. return cef_time_t.ToDateTime(&n_result);
  59. }
  60. /// <summary>
  61. /// Returns the DER encoded data for the X.509 certificate.
  62. /// </summary>
  63. public CefBinaryValue GetDerEncoded()
  64. {
  65. var n_result = cef_x509certificate_t.get_derencoded(_self);
  66. return CefBinaryValue.FromNative(n_result);
  67. }
  68. /// <summary>
  69. /// Returns the PEM encoded data for the X.509 certificate.
  70. /// </summary>
  71. public CefBinaryValue GetPemEncoded()
  72. {
  73. var n_result = cef_x509certificate_t.get_pemencoded(_self);
  74. return CefBinaryValue.FromNative(n_result);
  75. }
  76. /// <summary>
  77. /// Returns the number of certificates in the issuer chain.
  78. /// If 0, the certificate is self-signed.
  79. /// </summary>
  80. public long GetIssuerChainSize()
  81. {
  82. return (long)cef_x509certificate_t.get_issuer_chain_size(_self);
  83. }
  84. /// <summary>
  85. /// Returns the DER encoded data for the certificate issuer chain.
  86. /// If we failed to encode a certificate in the chain it is still
  87. /// present in the array but is an empty string.
  88. /// </summary>
  89. public void GetDerEncodedIssuerChain(out long chainCount, out CefBinaryValue chain)
  90. {
  91. UIntPtr n_chainCount;
  92. cef_binary_value_t* n_chain;
  93. cef_x509certificate_t.get_derencoded_issuer_chain(_self, &n_chainCount, &n_chain);
  94. chainCount = (long)n_chainCount;
  95. chain = CefBinaryValue.FromNative(n_chain);
  96. }
  97. /// <summary>
  98. /// Returns the PEM encoded data for the certificate issuer chain.
  99. /// If we failed to encode a certificate in the chain it is still
  100. /// present in the array but is an empty string.
  101. /// </summary>
  102. public void GetPEMEncodedIssuerChain(out long chainCount, out CefBinaryValue chain)
  103. {
  104. UIntPtr n_chainCount;
  105. cef_binary_value_t* n_chain;
  106. cef_x509certificate_t.get_pemencoded_issuer_chain(_self, &n_chainCount, &n_chain);
  107. chainCount = (long)n_chainCount;
  108. chain = CefBinaryValue.FromNative(n_chain);
  109. }
  110. }
  111. }