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.

305 lines
6.5 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. // Flags, use wininet.w defined ones, so we don't collide.
  19. //
  20. #define CERTCACHE_FLAG_FOUND_CERT INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS
  21. #define CERTCACHE_FLAG_IGNORE_CERT_CN_INVALID_SEND INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP
  22. //
  23. // SECURITY_INFO_LIST_ENTRY - contains all security info
  24. // pertaining to all connections to a server.
  25. //
  26. class SECURITY_CACHE_LIST_ENTRY {
  27. friend class SECURITY_CACHE_LIST;
  28. private:
  29. //
  30. // _List - Generic List entry structure.
  31. //
  32. LIST_ENTRY _List;
  33. //
  34. // _cRef - Reference count for this element.
  35. //
  36. LONG _cRef;
  37. //
  38. // _CertInfo - Certificate and other security
  39. // attributes for the connection to
  40. // this machine.
  41. //
  42. INTERNET_SECURITY_INFO _CertInfo;
  43. //
  44. // _dwSecurityFlags - Overrides for warnings.
  45. //
  46. DWORD _dwSecurityFlags;
  47. //
  48. // _ServerName - The name of the server
  49. //
  50. ICSTRING _ServerName;
  51. //
  52. // _pCertChainList - If there is Client Authentication do be done with this server,
  53. // then we'll cache it and remeber it later.
  54. //
  55. CERT_CONTEXT_ARRAY *_pCertContextArray;
  56. //
  57. // _fInCache - indicates this element is held by the cache
  58. //
  59. BOOL _fInCache;
  60. //
  61. // _fForceNewSession - indicates a new session needs to be negotiated
  62. //
  63. BOOL _fForceNewSession;
  64. //
  65. //
  66. // _fValidateAll - easy way out to mark if all cert errors
  67. // except revocation are being checked
  68. //
  69. BOOL _fValidateAll;
  70. #if INET_DEBUG
  71. DWORD m_Signature;
  72. #endif
  73. public:
  74. LONG AddRef(VOID);
  75. LONG Release(VOID);
  76. //
  77. // Cleans up object, so it can be reused
  78. //
  79. BOOL InCache() { return _fInCache; }
  80. VOID
  81. Clear();
  82. VOID
  83. SetForceNewSession(BOOL fForce) { _fForceNewSession = fForce; }
  84. BOOL
  85. GetForceNewSession(VOID) { return _fForceNewSession; }
  86. VOID
  87. SetFullyValidated(BOOL fValidateAll) { _fValidateAll = fValidateAll; }
  88. BOOL
  89. GetFullyValidated() { return _fValidateAll; }
  90. SECURITY_CACHE_LIST_ENTRY(
  91. IN LPSTR lpszHostName
  92. );
  93. ~SECURITY_CACHE_LIST_ENTRY();
  94. //
  95. // Copy CERT_INFO IN Method -
  96. // copies a structure into our object.
  97. //
  98. SECURITY_CACHE_LIST_ENTRY& operator=(LPINTERNET_SECURITY_INFO Cert)
  99. {
  100. if(_CertInfo.pCertificate)
  101. {
  102. CertFreeCertificateContext(_CertInfo.pCertificate);
  103. }
  104. _CertInfo.dwSize = sizeof(_CertInfo);
  105. _CertInfo.pCertificate = CertDuplicateCertificateContext(Cert->pCertificate);
  106. _CertInfo.dwProtocol = Cert->dwProtocol;
  107. _CertInfo.aiCipher = Cert->aiCipher;
  108. _CertInfo.dwCipherStrength = Cert->dwCipherStrength;
  109. _CertInfo.aiHash = Cert->aiHash;
  110. _CertInfo.dwHashStrength = Cert->dwHashStrength;
  111. _CertInfo.aiExch = Cert->aiExch;
  112. _CertInfo.dwExchStrength = Cert->dwExchStrength;
  113. return *this;
  114. }
  115. //
  116. // Copy CERT_INFO OUT Method -
  117. // need to copy ourselves out.
  118. //
  119. VOID
  120. CopyOut(INTERNET_SECURITY_INFO &Cert)
  121. {
  122. Cert.dwSize = sizeof(Cert);
  123. Cert.pCertificate = CertDuplicateCertificateContext(_CertInfo.pCertificate);
  124. Cert.dwProtocol = _CertInfo.dwProtocol;
  125. Cert.aiCipher = _CertInfo.aiCipher;
  126. Cert.dwCipherStrength = _CertInfo.dwCipherStrength;
  127. Cert.aiHash = _CertInfo.aiHash;
  128. Cert.dwHashStrength = _CertInfo.dwHashStrength;
  129. Cert.aiExch = _CertInfo.aiExch;
  130. Cert.dwExchStrength = _CertInfo.dwExchStrength;
  131. }
  132. //
  133. // Sets and Gets the Client Authentication CertChain -
  134. // we piggy back this pointer into the cache so we can cache
  135. // previously generated and selected client auth certs.
  136. //
  137. VOID SetCertContextArray(CERT_CONTEXT_ARRAY *pCertContextArray) {
  138. if (_pCertContextArray) {
  139. delete _pCertContextArray;
  140. }
  141. _pCertContextArray = pCertContextArray;
  142. }
  143. CERT_CONTEXT_ARRAY * GetCertContextArray() {
  144. return _pCertContextArray;
  145. }
  146. DWORD GetSecureFlags() {
  147. return _dwSecurityFlags;
  148. }
  149. VOID SetSecureFlags(DWORD dwFlags) {
  150. _dwSecurityFlags |= dwFlags;
  151. }
  152. VOID ClearSecureFlags(DWORD dwFlags) {
  153. _dwSecurityFlags &= (~dwFlags);
  154. }
  155. LPSTR GetHostName(VOID) {
  156. return _ServerName.StringAddress();
  157. }
  158. };
  159. class SECURITY_CACHE_LIST {
  160. private:
  161. //
  162. // _List - serialized list of SECURITY_CACHE_LIST_ENTRY objects
  163. //
  164. SERIALIZED_LIST _List;
  165. #if INET_DEBUG
  166. DWORD m_Signature;
  167. #endif
  168. public:
  169. SECURITY_CACHE_LIST_ENTRY *
  170. Find(
  171. IN LPSTR lpszHostname
  172. );
  173. VOID Remove(
  174. IN LPSTR lpszHostname
  175. );
  176. VOID Initialize(VOID) {
  177. InitializeSerializedList(&_List);
  178. #if INET_DEBUG
  179. m_Signature = 0x4c436553; // "SeCL"
  180. #endif
  181. }
  182. VOID Terminate(VOID) {
  183. DEBUG_ENTER((DBG_OBJECTS,
  184. None,
  185. "SECURITY_CACHE_LIST::Terminate",
  186. "{%#x}",
  187. this
  188. ));
  189. ClearList();
  190. TerminateSerializedList(&_List);
  191. DEBUG_LEAVE(0);
  192. }
  193. VOID
  194. ClearList(
  195. VOID
  196. );
  197. DWORD
  198. Add(
  199. IN SECURITY_CACHE_LIST_ENTRY * entry
  200. );
  201. VOID
  202. ClearClientAuthCertChains(
  203. VOID
  204. );
  205. #if 0
  206. BOOL
  207. IsCertInCache(
  208. IN LPSTR lpszHostname
  209. )
  210. {
  211. SECURITY_CACHE_LIST_ENTRY *entry =
  212. Find(lpszHostname);
  213. if ( entry )
  214. return TRUE;
  215. return FALSE;
  216. }
  217. #endif
  218. };