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.

146 lines
5.2 KiB

  1. // CertificateExtensions..cpp -- Certificate Extensions class
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 2001. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #include <scuOsExc.h>
  8. #include <scuArrayP.h>
  9. #include "CertificateExtensions.h"
  10. using namespace std;
  11. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  12. /////////////////////////// PUBLIC /////////////////////////////////
  13. // Types
  14. // C'tors/D'tors
  15. CertificateExtensions::CertificateExtensions(Blob const &rblbCertificate)
  16. : m_pCertCtx(CertCreateCertificateContext(X509_ASN_ENCODING |
  17. PKCS_7_ASN_ENCODING,
  18. rblbCertificate.data(),
  19. rblbCertificate.size()))
  20. {
  21. if (!m_pCertCtx)
  22. throw scu::OsException(GetLastError());
  23. }
  24. CertificateExtensions::~CertificateExtensions()
  25. {
  26. try
  27. {
  28. if (m_pCertCtx)
  29. {
  30. CertFreeCertificateContext(m_pCertCtx);
  31. m_pCertCtx = 0;
  32. }
  33. }
  34. catch (...)
  35. {
  36. }
  37. }
  38. // Operators
  39. // Operations
  40. // Access
  41. // Predicates
  42. bool
  43. CertificateExtensions::HasEKU(char *szOID)
  44. {
  45. bool fFound = false;
  46. CERT_EXTENSION *pExtension = NULL;
  47. DWORD cbSize = 0;
  48. DWORD dwIndex = 0;
  49. CERT_ENHKEY_USAGE *pEnhKeyUsage=NULL;
  50. if (m_pCertCtx->pCertInfo)
  51. {
  52. //find the EKU extension
  53. pExtension =CertFindExtension(szOID_ENHANCED_KEY_USAGE,
  54. m_pCertCtx->pCertInfo->cExtension,
  55. m_pCertCtx->pCertInfo->rgExtension);
  56. if(pExtension)
  57. {
  58. if(CryptDecodeObject(X509_ASN_ENCODING,
  59. X509_ENHANCED_KEY_USAGE,
  60. pExtension->Value.pbData,
  61. pExtension->Value.cbData,
  62. 0,
  63. NULL,
  64. &cbSize))
  65. {
  66. scu::AutoArrayPtr<BYTE> aabEKU(new BYTE[cbSize]);
  67. pEnhKeyUsage=reinterpret_cast<CERT_ENHKEY_USAGE *>(aabEKU.Get());
  68. if(pEnhKeyUsage)
  69. {
  70. if(CryptDecodeObject(X509_ASN_ENCODING,
  71. X509_ENHANCED_KEY_USAGE,
  72. pExtension->Value.pbData,
  73. pExtension->Value.cbData,
  74. 0,
  75. aabEKU.Get(),
  76. &cbSize))
  77. {
  78. for(dwIndex=0; dwIndex < pEnhKeyUsage->cUsageIdentifier; dwIndex++)
  79. {
  80. if(0 == strcmp(szOID,
  81. (pEnhKeyUsage->rgpszUsageIdentifier)[dwIndex]))
  82. {
  83. //we find it
  84. fFound=TRUE;
  85. break;
  86. }
  87. }
  88. }
  89. }
  90. }
  91. }
  92. }
  93. /*
  94. PCERT_INFO const pCertInfo = m_pCertCtx->pCertInfo;
  95. for (DWORD dwExtension = 0;
  96. !fFound && (dwExtension < pCertInfo->cExtension);
  97. dwExtension++)
  98. {
  99. PCERT_EXTENSION const pCertExt =
  100. &pCertInfo->rgExtension[dwExtension];
  101. if (0 == strcmp(pCertExt->pszObjId, rsExt.c_str()))
  102. fFound = true;
  103. }
  104. */
  105. return fFound;
  106. }
  107. // Static Variables
  108. /////////////////////////// PROTECTED /////////////////////////////////
  109. // C'tors/D'tors
  110. // Operators
  111. // Operations
  112. // Access
  113. // Predicates
  114. // Static Variables
  115. /////////////////////////// PRIVATE /////////////////////////////////
  116. // C'tors/D'tors
  117. // Operators
  118. // Operations
  119. // Access
  120. // Predicates
  121. // Static Variables