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.

159 lines
3.3 KiB

  1. #ifndef _CERTCONTEXT_HXX_
  2. #define _CERTCONTEXT_HXX_
  3. /*++
  4. Copyright (c) 2000 Microsoft Corporation
  5. Module Name :
  6. certcontext.hxx
  7. Abstract:
  8. Simple wrapper of a certificate blob.
  9. Used co conveniently access client certificate
  10. information passed to worker process from http.sys
  11. Author:
  12. Bilal Alam (balam) 5-Sept-2000
  13. Environment:
  14. Win32 - User Mode
  15. Project:
  16. ULW3.DLL
  17. --*/
  18. #include <wincrypt.h>
  19. #define HEX_DIGIT( nDigit ) \
  20. (CHAR)((nDigit) > 9 ? \
  21. (nDigit) - 10 + 'a' \
  22. : (nDigit) + '0')
  23. class CERTIFICATE_CONTEXT
  24. {
  25. public:
  26. CERTIFICATE_CONTEXT(
  27. HTTP_SSL_CLIENT_CERT_INFO * pClientCertInfo
  28. );
  29. virtual ~CERTIFICATE_CONTEXT();
  30. VOID
  31. QueryEncodedCertificate(
  32. PVOID * ppvData,
  33. DWORD * pcbData
  34. )
  35. {
  36. DBG_ASSERT( ppvData != NULL );
  37. DBG_ASSERT( pcbData != NULL );
  38. *ppvData = _pClientCertInfo->pCertEncoded;
  39. *pcbData = _pClientCertInfo->CertEncodedSize;
  40. }
  41. DWORD
  42. QueryCertError(
  43. VOID
  44. ) const
  45. {
  46. return _pClientCertInfo->CertFlags;
  47. }
  48. HANDLE
  49. QueryImpersonationToken(
  50. VOID
  51. ) const
  52. {
  53. return _pClientCertInfo->Token;
  54. }
  55. HRESULT
  56. GetSerialNumber(
  57. STRA * pstrSerialNumber
  58. );
  59. HRESULT
  60. GetCookie(
  61. STRA * pstrCookie
  62. );
  63. HRESULT
  64. GetIssuer(
  65. STRA * pstrIssuer
  66. );
  67. HRESULT
  68. GetSubject(
  69. STRA * pstrIssuer
  70. );
  71. VOID *
  72. operator new(
  73. #if DBG
  74. size_t size
  75. #else
  76. size_t
  77. #endif
  78. )
  79. {
  80. DBG_ASSERT( size == sizeof( CERTIFICATE_CONTEXT ) );
  81. DBG_ASSERT( sm_pachCertContexts != NULL );
  82. return sm_pachCertContexts->Alloc();
  83. }
  84. VOID
  85. operator delete(
  86. VOID * pCertContext
  87. )
  88. {
  89. DBG_ASSERT( pCertContext != NULL );
  90. DBG_ASSERT( sm_pachCertContexts != NULL );
  91. DBG_REQUIRE( sm_pachCertContexts->Free( pCertContext ) );
  92. }
  93. static
  94. HRESULT
  95. Initialize(
  96. VOID
  97. );
  98. static
  99. VOID
  100. Terminate(
  101. VOID
  102. );
  103. private:
  104. CERT_INFO *
  105. QueryCertInfo(
  106. VOID
  107. )
  108. {
  109. return (CERT_INFO*) _buffCertInfo.QueryPtr();
  110. }
  111. HRESULT
  112. DecodeCert(
  113. VOID
  114. );
  115. // Client cert info provided to worker process by http.sys
  116. HTTP_SSL_CLIENT_CERT_INFO * _pClientCertInfo;
  117. // internal flag if cert decoding was done
  118. // if TRUE then QueryCertInfo() returns valid structure
  119. BOOL _fCertDecoded;
  120. // buffer to store CERT INFO
  121. BUFFER _buffCertInfo;
  122. // default inline buffer for _buffCertInfo
  123. CERT_INFO _CertInfo;
  124. // we need Crypto provider for MD5 hash calculation (CertCookie)
  125. static HCRYPTPROV sm_CryptProvider;
  126. // acache
  127. static ALLOC_CACHE_HANDLER * sm_pachCertContexts;
  128. };
  129. #endif