CertificateDetailControl.xaml.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Runtime.CompilerServices;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using ComPDFKit.Controls.Helper;
  18. using ComPDFKit.DigitalSign;
  19. namespace ComPDFKit.Controls.PDFControl
  20. {
  21. public partial class CertificateDetailControl : UserControl,INotifyPropertyChanged
  22. {
  23. private string version;
  24. public string Version
  25. {
  26. get => version;
  27. set => UpdateProper(ref version, value);
  28. }
  29. private string algorithm;
  30. public string Algorithm
  31. {
  32. get => algorithm;
  33. set => UpdateProper(ref algorithm, value);
  34. }
  35. private string subject;
  36. public string Subject
  37. {
  38. get => subject;
  39. set => UpdateProper(ref subject, value);
  40. }
  41. private string issuer;
  42. public string Issuer
  43. {
  44. get => issuer;
  45. set => UpdateProper(ref issuer, value);
  46. }
  47. private string serialNumber;
  48. public string SerialNumber
  49. {
  50. get => serialNumber;
  51. set => UpdateProper(ref serialNumber, value);
  52. }
  53. private string validityFrom;
  54. public string ValidityFrom
  55. {
  56. get => validityFrom;
  57. set => UpdateProper(ref validityFrom, value);
  58. }
  59. private string validityTo;
  60. public string ValidityTo
  61. {
  62. get => validityTo;
  63. set => UpdateProper(ref validityTo, value);
  64. }
  65. private string certificatePolicy;
  66. public string CertificatePolicy
  67. {
  68. get => certificatePolicy;
  69. set => UpdateProper(ref certificatePolicy, value);
  70. }
  71. private string crlDistributionPoint;
  72. public string CrlDistributionPoint
  73. {
  74. get => crlDistributionPoint;
  75. set => UpdateProper(ref crlDistributionPoint, value);
  76. }
  77. private string authorityInfoAccess;
  78. public string AuthorityInfoAccess
  79. {
  80. get => authorityInfoAccess;
  81. set => UpdateProper(ref authorityInfoAccess, value);
  82. }
  83. private string authorityKeyIdentifier;
  84. public string AuthorityKeyIdentifier
  85. {
  86. get => authorityKeyIdentifier;
  87. set => UpdateProper(ref authorityKeyIdentifier, value);
  88. }
  89. private string subjectKeyIdentifier;
  90. public string SubjectKeyIdentifier
  91. {
  92. get => subjectKeyIdentifier;
  93. set => UpdateProper(ref subjectKeyIdentifier, value);
  94. }
  95. private string basicConstraints;
  96. public string BasicConstraints
  97. {
  98. get => basicConstraints;
  99. set => UpdateProper(ref basicConstraints, value);
  100. }
  101. private string keyUsage;
  102. public string KeyUsage
  103. {
  104. get => keyUsage;
  105. set => UpdateProper(ref keyUsage, value);
  106. }
  107. private string publicKey;
  108. public string PublicKey
  109. {
  110. get => publicKey;
  111. set => UpdateProper(ref publicKey, value);
  112. }
  113. private string x509Data;
  114. public string X509Data
  115. {
  116. get => x509Data;
  117. set => UpdateProper(ref x509Data, value);
  118. }
  119. private string sha1Abstract;
  120. public string SHA1Digest
  121. {
  122. get => sha1Abstract;
  123. set => UpdateProper(ref sha1Abstract, value);
  124. }
  125. private string md5Digest;
  126. public string MD5Digest
  127. {
  128. get => md5Digest;
  129. set => UpdateProper(ref md5Digest, value);
  130. }
  131. public CertificateDetailControl()
  132. {
  133. InitializeComponent();
  134. DataContext = this;
  135. }
  136. public void LoadDetailInfo(CPDFSignatureCertificate certificate)
  137. {
  138. string certificatePolicyText = string.Empty;
  139. string crlDistributionPointText = string.Empty;
  140. string authorityInfoAccessText = string.Empty;
  141. string keyUsageText = string.Empty;
  142. var usageList = DictionaryValueConverter.GetUsage(certificate);
  143. foreach (var policy in certificate.CertificatePolicies)
  144. {
  145. certificatePolicyText += policy + "\n";
  146. }
  147. foreach (var access in certificate.AuthorityInfoAccess)
  148. {
  149. authorityInfoAccess += access + "\n";
  150. }
  151. foreach (var crl in certificate.CRLDistributionPoints)
  152. {
  153. crlDistributionPointText += crl + "\n";
  154. }
  155. for(int i = 0; i < usageList.Count; i++)
  156. {
  157. keyUsageText += usageList[i];
  158. keyUsageText += (i == usageList.Count - 1) ? "" : ", ";
  159. }
  160. Version = certificate.Version.ToString();
  161. Algorithm = certificate.SignatureAlgorithmType.ToString().Substring(26) + "(" + certificate.SignatureAlgorithmOID + ")";
  162. Subject = certificate.Subject;
  163. Issuer = certificate.Issuer;
  164. SerialNumber = certificate.SerialNumber;
  165. ValidityFrom = CommonHelper.GetExactDateFromString(certificate.ValidityStarts);
  166. ValidityTo = CommonHelper.GetExactDateFromString(certificate.ValidityEnds);
  167. CertificatePolicy = certificatePolicyText;
  168. CrlDistributionPoint = crlDistributionPointText;
  169. X509Data = certificate.X509Data;
  170. AuthorityInfoAccess = authorityInfoAccess;
  171. AuthorityKeyIdentifier = certificate.AuthorityKeyIdentifier;
  172. SubjectKeyIdentifier = certificate.SubjectKeyIdentifier;
  173. BasicConstraints = certificate.BasicConstraints;
  174. KeyUsage = keyUsageText;
  175. PublicKey = certificate.PublicKey;
  176. SHA1Digest = certificate.SHA1Digest;
  177. MD5Digest = certificate.MD5Digest;
  178. }
  179. public event PropertyChangedEventHandler PropertyChanged;
  180. protected void UpdateProper<T>(ref T properValue,
  181. T newValue,
  182. [CallerMemberName] string properName = "")
  183. {
  184. if (object.Equals(properValue, newValue))
  185. return;
  186. properValue = newValue;
  187. OnPropertyChanged(properName);
  188. }
  189. protected void OnPropertyChanged([CallerMemberName] string propertyName = "") =>
  190. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  191. }
  192. }