Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997-2002.
  5. //
  6. // File: CRL.cpp
  7. //
  8. // Contents: implementation of the CCRL class.
  9. //
  10. //----------------------------------------------------------------------------
  11. #include "stdafx.h"
  12. #include "CRL.h"
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CCRL::CCRL(const PCCRL_CONTEXT pCRLContext, CCertStore& rCertStore) :
  17. CCertMgrCookie (CERTMGR_CRL),
  18. m_pCRLContext (::CertDuplicateCRLContext (pCRLContext)),
  19. m_rCertStore (rCertStore),
  20. m_pCRLInfo (0)
  21. {
  22. ASSERT (CERTMGR_CRL == m_objecttype);
  23. m_rCertStore.AddRef ();
  24. ASSERT (m_pCRLContext);
  25. if ( m_pCRLContext )
  26. m_pCRLInfo = m_pCRLContext->pCrlInfo;
  27. }
  28. CCRL::~CCRL()
  29. {
  30. ASSERT (CERTMGR_CRL == m_objecttype);
  31. m_rCertStore.Release ();
  32. if ( m_pCRLContext )
  33. ::CertFreeCRLContext (m_pCRLContext);
  34. }
  35. PCCRL_CONTEXT CCRL::GetCRLContext() const
  36. {
  37. ASSERT (CERTMGR_CRL == m_objecttype);
  38. return m_pCRLContext;
  39. }
  40. CCertStore& CCRL::GetCertStore() const
  41. {
  42. ASSERT (CERTMGR_CRL == m_objecttype);
  43. return m_rCertStore;
  44. }
  45. CString CCRL::GetIssuerName ()
  46. {
  47. ASSERT (CERTMGR_CRL == m_objecttype);
  48. ASSERT (m_pCRLInfo);
  49. if ( m_pCRLInfo )
  50. {
  51. // Decode issuer name if not already present
  52. if ( m_szIssuerName.IsEmpty () )
  53. {
  54. HRESULT hResult = ConvertNameBlobToString (m_pCRLInfo->Issuer,
  55. m_szIssuerName);
  56. if ( !SUCCEEDED (hResult) )
  57. return _T("");
  58. }
  59. }
  60. else
  61. return _T("");
  62. return m_szIssuerName;
  63. }
  64. CString CCRL::GetEffectiveDate()
  65. {
  66. ASSERT (CERTMGR_CRL == m_objecttype);
  67. ASSERT (m_pCRLInfo);
  68. if ( m_pCRLInfo )
  69. {
  70. // Format date/time string if not already present
  71. if ( m_szEffectiveDate.IsEmpty () )
  72. {
  73. HRESULT hResult = FormatDate (m_pCRLInfo->ThisUpdate, m_szEffectiveDate);
  74. if ( !SUCCEEDED (hResult) )
  75. m_szEffectiveDate = _T("");
  76. }
  77. }
  78. else
  79. m_szEffectiveDate = _T("");
  80. return m_szEffectiveDate;
  81. }
  82. CString CCRL::GetNextUpdate()
  83. {
  84. ASSERT (CERTMGR_CRL == m_objecttype);
  85. ASSERT (m_pCRLInfo);
  86. if ( m_pCRLInfo )
  87. {
  88. // Format date/time string if not already present
  89. if ( m_szNextUpdate.IsEmpty () )
  90. {
  91. HRESULT hResult = FormatDate (m_pCRLInfo->NextUpdate, m_szNextUpdate);
  92. if ( !SUCCEEDED (hResult) )
  93. m_szNextUpdate = _T("");
  94. }
  95. }
  96. else
  97. m_szNextUpdate = _T("");
  98. return m_szNextUpdate;
  99. }
  100. int CCRL::CompareEffectiveDate (const CCRL& crl) const
  101. {
  102. ASSERT (CERTMGR_CRL == m_objecttype);
  103. int compVal = 0;
  104. ASSERT (m_pCRLInfo && crl.m_pCRLInfo);
  105. if ( m_pCRLInfo && crl.m_pCRLInfo )
  106. {
  107. compVal = ::CompareFileTime (&m_pCRLInfo->ThisUpdate,
  108. &crl.m_pCRLInfo->ThisUpdate);
  109. }
  110. return compVal;
  111. }
  112. int CCRL::CompareNextUpdate (const CCRL& crl) const
  113. {
  114. ASSERT (CERTMGR_CRL == m_objecttype);
  115. int compVal = 0;
  116. ASSERT (m_pCRLInfo && crl.m_pCRLInfo);
  117. if ( m_pCRLInfo && crl.m_pCRLInfo )
  118. {
  119. compVal = ::CompareFileTime (&m_pCRLInfo->NextUpdate,
  120. &crl.m_pCRLInfo->NextUpdate);
  121. }
  122. return compVal;
  123. }
  124. void CCRL::Refresh()
  125. {
  126. m_szEffectiveDate = L"";
  127. m_szIssuerName = L"";
  128. m_szNextUpdate = L"";
  129. }
  130. BOOL CCRL::DeleteFromStore()
  131. {
  132. BOOL bResult = FALSE;
  133. ASSERT (m_pCRLContext);
  134. if ( m_pCRLContext )
  135. {
  136. bResult = ::CertDeleteCRLFromStore (
  137. ::CertDuplicateCRLContext (m_pCRLContext));
  138. if ( bResult )
  139. m_rCertStore.SetDirty ();
  140. }
  141. return bResult;
  142. }