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.

286 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. certcach.hxx
  5. Abstract:
  6. Contains class definition for certificate cache object.
  7. The class acts a container for common certificates.
  8. Contents:
  9. SECURITY_CACHE_LIST
  10. SECURITY_CACHE_LIST_ENTRY
  11. Author:
  12. Arthur L Bierer (arthurbi) 20-Apr-1996
  13. Revision History:
  14. 20-Apr-1996 arthurbi
  15. Created
  16. --*/
  17. //
  18. // SECURITY_INFO_LIST_ENTRY - contains all security info
  19. // pertaining to all connections to a server.
  20. //
  21. class SECURITY_CACHE_LIST_ENTRY {
  22. friend class SECURITY_CACHE_LIST;
  23. private:
  24. //
  25. // _List - Generic List entry structure.
  26. //
  27. LIST_ENTRY _List;
  28. //
  29. // _cRef - Reference count for this element.
  30. //
  31. LONG _cRef;
  32. //
  33. // _CertInfo - Certificate and other security
  34. // attributes for the connection to
  35. // this machine.
  36. //
  37. INTERNET_SECURITY_INFO _CertInfo;
  38. //
  39. // _dwSecurityFlags - Overrides for warnings.
  40. //
  41. DWORD _dwSecurityFlags;
  42. //
  43. // _dwStatusFlags - Tracker for all secure connection failure flags.
  44. //
  45. DWORD _dwStatusFlags;
  46. //
  47. // _ServerName - The name of the server
  48. //
  49. ICSTRING _ServerName;
  50. //
  51. // _pCertChainList - If there is Client Authentication do be done with this server,
  52. // then we'll cache it and remeber it later.
  53. //
  54. CERT_CONTEXT_ARRAY *_pCertContextArray;
  55. //
  56. // _fInCache - indicates this element is held by the cache
  57. //
  58. BOOL _fInCache;
  59. #if INET_DEBUG
  60. DWORD m_Signature;
  61. #endif
  62. public:
  63. LONG AddRef(VOID);
  64. LONG Release(VOID);
  65. //
  66. // Cleans up object, so it can be reused
  67. //
  68. BOOL InCache() { return _fInCache; }
  69. VOID
  70. Clear();
  71. SECURITY_CACHE_LIST_ENTRY(
  72. IN LPSTR lpszHostName
  73. );
  74. ~SECURITY_CACHE_LIST_ENTRY();
  75. //
  76. // Copy CERT_INFO IN Method -
  77. // copies a structure into our object.
  78. //
  79. SECURITY_CACHE_LIST_ENTRY& operator=(LPINTERNET_SECURITY_INFO Cert)
  80. {
  81. if(_CertInfo.pCertificate)
  82. {
  83. WRAP_REVERT_USER_VOID(CertFreeCertificateContext,
  84. (_CertInfo.pCertificate));
  85. }
  86. _CertInfo.dwSize = sizeof(_CertInfo);
  87. WRAP_REVERT_USER(CertDuplicateCertificateContext,
  88. (Cert->pCertificate),
  89. _CertInfo.pCertificate);
  90. _CertInfo.dwProtocol = Cert->dwProtocol;
  91. _CertInfo.aiCipher = Cert->aiCipher;
  92. _CertInfo.dwCipherStrength = Cert->dwCipherStrength;
  93. _CertInfo.aiHash = Cert->aiHash;
  94. _CertInfo.dwHashStrength = Cert->dwHashStrength;
  95. _CertInfo.aiExch = Cert->aiExch;
  96. _CertInfo.dwExchStrength = Cert->dwExchStrength;
  97. return *this;
  98. }
  99. //
  100. // Copy CERT_INFO OUT Method -
  101. // need to copy ourselves out.
  102. //
  103. VOID
  104. CopyOut(INTERNET_SECURITY_INFO &Cert)
  105. {
  106. Cert.dwSize = sizeof(Cert);
  107. WRAP_REVERT_USER(CertDuplicateCertificateContext,
  108. (_CertInfo.pCertificate),
  109. Cert.pCertificate);
  110. Cert.dwProtocol = _CertInfo.dwProtocol;
  111. Cert.aiCipher = _CertInfo.aiCipher;
  112. Cert.dwCipherStrength = _CertInfo.dwCipherStrength;
  113. Cert.aiHash = _CertInfo.aiHash;
  114. Cert.dwHashStrength = _CertInfo.dwHashStrength;
  115. Cert.aiExch = _CertInfo.aiExch;
  116. Cert.dwExchStrength = _CertInfo.dwExchStrength;
  117. }
  118. //
  119. // Sets and Gets the Client Authentication CertChain -
  120. // we piggy back this pointer into the cache so we can cache
  121. // previously generated and selected client auth certs.
  122. //
  123. VOID SetCertContextArray(CERT_CONTEXT_ARRAY *pCertContextArray) {
  124. if (_pCertContextArray) {
  125. delete _pCertContextArray;
  126. }
  127. _pCertContextArray = pCertContextArray;
  128. }
  129. CERT_CONTEXT_ARRAY * GetCertContextArray() {
  130. return _pCertContextArray;
  131. }
  132. DWORD GetSecureFlags() {
  133. return _dwSecurityFlags;
  134. }
  135. VOID SetSecureFlags(DWORD dwFlags) {
  136. _dwSecurityFlags |= dwFlags;
  137. }
  138. VOID ClearSecureFlags(DWORD dwFlags) {
  139. _dwSecurityFlags &= (~dwFlags);
  140. }
  141. DWORD GetStatusFlags(VOID)
  142. {
  143. return _dwStatusFlags;
  144. }
  145. VOID SetStatusFlags(DWORD dwFlags)
  146. {
  147. _dwStatusFlags |= dwFlags;
  148. }
  149. VOID ClearStatusFlags(DWORD dwFlags)
  150. {
  151. _dwStatusFlags &= (~dwFlags);
  152. }
  153. };
  154. class SECURITY_CACHE_LIST {
  155. private:
  156. //
  157. // _List - serialized list of SECURITY_CACHE_LIST_ENTRY objects
  158. //
  159. SERIALIZED_LIST _List;
  160. #if INET_DEBUG
  161. DWORD m_Signature;
  162. #endif
  163. public:
  164. SECURITY_CACHE_LIST_ENTRY *
  165. Find(
  166. IN LPSTR lpszHostname
  167. );
  168. VOID Initialize(VOID) {
  169. InitializeSerializedList(&_List);
  170. #if INET_DEBUG
  171. m_Signature = 0x4c436553; // "SeCL"
  172. #endif
  173. }
  174. VOID Terminate(VOID) {
  175. DEBUG_ENTER((DBG_OBJECTS,
  176. None,
  177. "SECURITY_CACHE_LIST::Terminate",
  178. "{%#x}",
  179. this
  180. ));
  181. ClearList();
  182. TerminateSerializedList(&_List);
  183. DEBUG_LEAVE(0);
  184. }
  185. VOID
  186. ClearList(
  187. VOID
  188. );
  189. DWORD
  190. Add(
  191. IN SECURITY_CACHE_LIST_ENTRY * entry
  192. );
  193. #if 0
  194. BOOL
  195. IsCertInCache(
  196. IN LPSTR lpszHostname
  197. )
  198. {
  199. SECURITY_CACHE_LIST_ENTRY *entry =
  200. Find(lpszHostname);
  201. if ( entry )
  202. return TRUE;
  203. return FALSE;
  204. }
  205. #endif
  206. };