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.

1384 lines
42 KiB

  1. //+-------------------------------------------------------------------------
  2. // Microsoft Windows
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995 - 1997
  5. //
  6. // File: textstor.cpp
  7. //
  8. // Contents: Test External Certificate Store Provider
  9. //
  10. // Functions: DllRegisterServer
  11. // DllUnregisterServer
  12. // DllMain
  13. // DllCanUnloadNow
  14. // I_CertDllOpenTestExtStoreProvW
  15. //
  16. // History: 09-Sep-97 philh created
  17. //--------------------------------------------------------------------------
  18. #include "global.hxx"
  19. #include <dbgdef.h>
  20. // # of bytes for a hash. Such as, SHA (20) or MD5 (16)
  21. #define MAX_HASH_LEN 20
  22. static HMODULE hMyModule;
  23. #define sz_CERT_STORE_PROV_TEST_EXT "TestExt"
  24. #define TEST_EXT_OPEN_STORE_PROV_FUNC "I_CertDllOpenTestExtStoreProvW"
  25. //+-------------------------------------------------------------------------
  26. // External Store Provider handle information
  27. //--------------------------------------------------------------------------
  28. typedef struct _FIND_EXT_INFO FIND_EXT_INFO, *PFIND_EXT_INFO;
  29. struct _FIND_EXT_INFO {
  30. DWORD dwContextType;
  31. void *pvContext;
  32. };
  33. typedef struct _EXT_STORE {
  34. HCERTSTORE hExtCertStore;
  35. } EXT_STORE, *PEXT_STORE;
  36. //+-------------------------------------------------------------------------
  37. // External Store Provider Functions.
  38. //--------------------------------------------------------------------------
  39. static void WINAPI ExtStoreProvClose(
  40. IN HCERTSTOREPROV hStoreProv,
  41. IN DWORD dwFlags
  42. );
  43. static BOOL WINAPI ExtStoreProvReadCert(
  44. IN HCERTSTOREPROV hStoreProv,
  45. IN PCCERT_CONTEXT pStoreCertContext,
  46. IN DWORD dwFlags,
  47. OUT PCCERT_CONTEXT *ppProvCertContext
  48. );
  49. static BOOL WINAPI ExtStoreProvWriteCert(
  50. IN HCERTSTOREPROV hStoreProv,
  51. IN PCCERT_CONTEXT pCertContext,
  52. IN DWORD dwFlags
  53. );
  54. static BOOL WINAPI ExtStoreProvDeleteCert(
  55. IN HCERTSTOREPROV hStoreProv,
  56. IN PCCERT_CONTEXT pCertContext,
  57. IN DWORD dwFlags
  58. );
  59. static BOOL WINAPI ExtStoreProvSetCertProperty(
  60. IN HCERTSTOREPROV hStoreProv,
  61. IN PCCERT_CONTEXT pCertContext,
  62. IN DWORD dwPropId,
  63. IN DWORD dwFlags,
  64. IN const void *pvData
  65. );
  66. static BOOL WINAPI ExtStoreProvReadCrl(
  67. IN HCERTSTOREPROV hStoreProv,
  68. IN PCCRL_CONTEXT pStoreCrlContext,
  69. IN DWORD dwFlags,
  70. OUT PCCRL_CONTEXT *ppProvCrlContext
  71. );
  72. static BOOL WINAPI ExtStoreProvWriteCrl(
  73. IN HCERTSTOREPROV hStoreProv,
  74. IN PCCRL_CONTEXT pCrlContext,
  75. IN DWORD dwFlags
  76. );
  77. static BOOL WINAPI ExtStoreProvDeleteCrl(
  78. IN HCERTSTOREPROV hStoreProv,
  79. IN PCCRL_CONTEXT pCrlContext,
  80. IN DWORD dwFlags
  81. );
  82. static BOOL WINAPI ExtStoreProvSetCrlProperty(
  83. IN HCERTSTOREPROV hStoreProv,
  84. IN PCCRL_CONTEXT pCrlContext,
  85. IN DWORD dwPropId,
  86. IN DWORD dwFlags,
  87. IN const void *pvData
  88. );
  89. static BOOL WINAPI ExtStoreProvReadCtl(
  90. IN HCERTSTOREPROV hStoreProv,
  91. IN PCCTL_CONTEXT pStoreCtlContext,
  92. IN DWORD dwFlags,
  93. OUT PCCTL_CONTEXT *ppProvCtlContext
  94. );
  95. static BOOL WINAPI ExtStoreProvWriteCtl(
  96. IN HCERTSTOREPROV hStoreProv,
  97. IN PCCTL_CONTEXT pCtlContext,
  98. IN DWORD dwFlags
  99. );
  100. static BOOL WINAPI ExtStoreProvDeleteCtl(
  101. IN HCERTSTOREPROV hStoreProv,
  102. IN PCCTL_CONTEXT pCtlContext,
  103. IN DWORD dwFlags
  104. );
  105. static BOOL WINAPI ExtStoreProvSetCtlProperty(
  106. IN HCERTSTOREPROV hStoreProv,
  107. IN PCCTL_CONTEXT pCtlContext,
  108. IN DWORD dwPropId,
  109. IN DWORD dwFlags,
  110. IN const void *pvData
  111. );
  112. static BOOL WINAPI ExtStoreProvControl(
  113. IN HCERTSTOREPROV hStoreProv,
  114. IN DWORD dwFlags,
  115. IN DWORD dwCtrlType,
  116. IN void const *pvCtrlPara
  117. );
  118. static BOOL WINAPI ExtStoreProvFindCert(
  119. IN HCERTSTOREPROV hStoreProv,
  120. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  121. IN PCCERT_CONTEXT pPrevCertContext,
  122. IN DWORD dwFlags,
  123. IN OUT void **ppvStoreProvFindInfo,
  124. OUT PCCERT_CONTEXT *ppProvCertContext
  125. );
  126. static BOOL WINAPI ExtStoreProvFreeFindCert(
  127. IN HCERTSTOREPROV hStoreProv,
  128. IN PCCERT_CONTEXT pCertContext,
  129. IN void *pvStoreProvFindInfo,
  130. IN DWORD dwFlags
  131. );
  132. static BOOL WINAPI ExtStoreProvGetCertProperty(
  133. IN HCERTSTOREPROV hStoreProv,
  134. IN PCCERT_CONTEXT pCertContext,
  135. IN DWORD dwPropId,
  136. IN DWORD dwFlags,
  137. OUT void *pvData,
  138. IN OUT DWORD *pcbData
  139. );
  140. static BOOL WINAPI ExtStoreProvFindCrl(
  141. IN HCERTSTOREPROV hStoreProv,
  142. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  143. IN PCCRL_CONTEXT pPrevCrlContext,
  144. IN DWORD dwFlags,
  145. IN OUT void **ppvStoreProvFindInfo,
  146. OUT PCCRL_CONTEXT *ppProvCrlContext
  147. );
  148. static BOOL WINAPI ExtStoreProvFreeFindCrl(
  149. IN HCERTSTOREPROV hStoreProv,
  150. IN PCCRL_CONTEXT pCrlContext,
  151. IN void *pvStoreProvFindInfo,
  152. IN DWORD dwFlags
  153. );
  154. static BOOL WINAPI ExtStoreProvGetCrlProperty(
  155. IN HCERTSTOREPROV hStoreProv,
  156. IN PCCRL_CONTEXT pCrlContext,
  157. IN DWORD dwPropId,
  158. IN DWORD dwFlags,
  159. OUT void *pvData,
  160. IN OUT DWORD *pcbData
  161. );
  162. static BOOL WINAPI ExtStoreProvFindCtl(
  163. IN HCERTSTOREPROV hStoreProv,
  164. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  165. IN PCCTL_CONTEXT pPrevCtlContext,
  166. IN DWORD dwFlags,
  167. IN OUT void **ppvStoreProvFindInfo,
  168. OUT PCCTL_CONTEXT *ppProvCtlContext
  169. );
  170. static BOOL WINAPI ExtStoreProvFreeFindCtl(
  171. IN HCERTSTOREPROV hStoreProv,
  172. IN PCCTL_CONTEXT pCtlContext,
  173. IN void *pvStoreProvFindInfo,
  174. IN DWORD dwFlags
  175. );
  176. static BOOL WINAPI ExtStoreProvGetCtlProperty(
  177. IN HCERTSTOREPROV hStoreProv,
  178. IN PCCTL_CONTEXT pCtlContext,
  179. IN DWORD dwPropId,
  180. IN DWORD dwFlags,
  181. OUT void *pvData,
  182. IN OUT DWORD *pcbData
  183. );
  184. static void * const rgpvExtStoreProvFunc[] = {
  185. // CERT_STORE_PROV_CLOSE_FUNC 0
  186. ExtStoreProvClose,
  187. // CERT_STORE_PROV_READ_CERT_FUNC 1
  188. ExtStoreProvReadCert,
  189. // CERT_STORE_PROV_WRITE_CERT_FUNC 2
  190. ExtStoreProvWriteCert,
  191. // CERT_STORE_PROV_DELETE_CERT_FUNC 3
  192. ExtStoreProvDeleteCert,
  193. // CERT_STORE_PROV_SET_CERT_PROPERTY_FUNC 4
  194. ExtStoreProvSetCertProperty,
  195. // CERT_STORE_PROV_READ_CRL_FUNC 5
  196. ExtStoreProvReadCrl,
  197. // CERT_STORE_PROV_WRITE_CRL_FUNC 6
  198. ExtStoreProvWriteCrl,
  199. // CERT_STORE_PROV_DELETE_CRL_FUNC 7
  200. ExtStoreProvDeleteCrl,
  201. // CERT_STORE_PROV_SET_CRL_PROPERTY_FUNC 8
  202. ExtStoreProvSetCrlProperty,
  203. // CERT_STORE_PROV_READ_CTL_FUNC 9
  204. ExtStoreProvReadCtl,
  205. // CERT_STORE_PROV_WRITE_CTL_FUNC 10
  206. ExtStoreProvWriteCtl,
  207. // CERT_STORE_PROV_DELETE_CTL_FUNC 11
  208. ExtStoreProvDeleteCtl,
  209. // CERT_STORE_PROV_SET_CTL_PROPERTY_FUNC 12
  210. ExtStoreProvSetCtlProperty,
  211. // CERT_STORE_PROV_CONTROL_FUNC 13
  212. ExtStoreProvControl,
  213. // CERT_STORE_PROV_FIND_CERT_FUNC 14
  214. ExtStoreProvFindCert,
  215. // CERT_STORE_PROV_FREE_FIND_CERT_FUNC 15
  216. ExtStoreProvFreeFindCert,
  217. // CERT_STORE_PROV_GET_CERT_PROPERTY_FUNC 16
  218. ExtStoreProvGetCertProperty,
  219. // CERT_STORE_PROV_FIND_CRL_FUNC 17
  220. ExtStoreProvFindCrl,
  221. // CERT_STORE_PROV_FREE_FIND_CRL_FUNC 18
  222. ExtStoreProvFreeFindCrl,
  223. // CERT_STORE_PROV_GET_CRL_PROPERTY_FUNC 19
  224. ExtStoreProvGetCrlProperty,
  225. // CERT_STORE_PROV_FIND_CTL_FUNC 20
  226. ExtStoreProvFindCtl,
  227. // CERT_STORE_PROV_FREE_FIND_CTL_FUNC 21
  228. ExtStoreProvFreeFindCtl,
  229. // CERT_STORE_PROV_GET_CTL_PROPERTY_FUNC 22
  230. ExtStoreProvGetCtlProperty
  231. };
  232. #define EXT_STORE_PROV_FUNC_COUNT (sizeof(rgpvExtStoreProvFunc) / \
  233. sizeof(rgpvExtStoreProvFunc[0]))
  234. //+-------------------------------------------------------------------------
  235. // CertStore allocation and free functions
  236. //--------------------------------------------------------------------------
  237. static void *CSAlloc(
  238. IN size_t cbBytes
  239. )
  240. {
  241. void *pv;
  242. pv = malloc(cbBytes);
  243. if (pv == NULL)
  244. SetLastError((DWORD) E_OUTOFMEMORY);
  245. return pv;
  246. }
  247. static void *CSRealloc(
  248. IN void *pvOrg,
  249. IN size_t cbBytes
  250. )
  251. {
  252. void *pv;
  253. if (NULL == (pv = pvOrg ? realloc(pvOrg, cbBytes) : malloc(cbBytes)))
  254. SetLastError((DWORD) E_OUTOFMEMORY);
  255. return pv;
  256. }
  257. static void CSFree(
  258. IN void *pv
  259. )
  260. {
  261. if (pv)
  262. free(pv);
  263. }
  264. //+-------------------------------------------------------------------------
  265. // Create, add, remove and free external store find info functions
  266. //--------------------------------------------------------------------------
  267. static PFIND_EXT_INFO CreateExtInfo(
  268. IN DWORD dwContextType,
  269. IN void *pvContext // already AddRef'ed
  270. )
  271. {
  272. PFIND_EXT_INFO pFindExtInfo;
  273. if (pFindExtInfo = (PFIND_EXT_INFO) CSAlloc(sizeof(FIND_EXT_INFO))) {
  274. pFindExtInfo->dwContextType = dwContextType;
  275. pFindExtInfo->pvContext = pvContext;
  276. }
  277. return pFindExtInfo;
  278. }
  279. static void FreeExtInfo(
  280. IN PFIND_EXT_INFO pFindExtInfo
  281. )
  282. {
  283. void *pvContext;
  284. if (NULL == pFindExtInfo)
  285. return;
  286. pvContext = pFindExtInfo->pvContext;
  287. if (pvContext) {
  288. switch (pFindExtInfo->dwContextType) {
  289. case (CERT_STORE_CERTIFICATE_CONTEXT - 1):
  290. CertFreeCertificateContext((PCCERT_CONTEXT) pvContext);
  291. break;
  292. case (CERT_STORE_CRL_CONTEXT - 1):
  293. CertFreeCRLContext((PCCRL_CONTEXT) pvContext);
  294. break;
  295. case (CERT_STORE_CTL_CONTEXT - 1):
  296. CertFreeCTLContext((PCCTL_CONTEXT) pvContext);
  297. break;
  298. default:
  299. assert(pFindExtInfo->dwContextType < CERT_STORE_CTL_CONTEXT);
  300. }
  301. }
  302. CSFree(pFindExtInfo);
  303. }
  304. //+-------------------------------------------------------------------------
  305. // Dll initialization
  306. //--------------------------------------------------------------------------
  307. BOOL
  308. WINAPI
  309. DllMain(
  310. HMODULE hModule,
  311. ULONG ulReason,
  312. LPVOID lpReserved)
  313. {
  314. switch (ulReason) {
  315. case DLL_PROCESS_ATTACH:
  316. hMyModule = hModule;
  317. break;
  318. case DLL_PROCESS_DETACH:
  319. case DLL_THREAD_DETACH:
  320. break;
  321. default:
  322. break;
  323. }
  324. return TRUE;
  325. }
  326. STDAPI DllCanUnloadNow(void)
  327. {
  328. // Return S_FALSE inhibit unloading.
  329. // return S_FALSE;
  330. return S_OK;
  331. }
  332. static HRESULT HError()
  333. {
  334. DWORD dw = GetLastError();
  335. HRESULT hr;
  336. if ( dw <= 0xFFFF )
  337. hr = HRESULT_FROM_WIN32 ( dw );
  338. else
  339. hr = dw;
  340. if ( ! FAILED ( hr ) )
  341. {
  342. // somebody failed a call without properly setting an error condition
  343. hr = E_UNEXPECTED;
  344. }
  345. return hr;
  346. }
  347. static HRESULT GetDllFilename(
  348. OUT WCHAR wszModule[_MAX_PATH]
  349. )
  350. {
  351. char szModule[_MAX_PATH];
  352. LPSTR pszModule;
  353. int cchModule;
  354. // Get name of this DLL.
  355. if (0 == GetModuleFileNameA(hMyModule, szModule, _MAX_PATH))
  356. return HError();
  357. // Strip off the Dll filename's directory components
  358. cchModule = strlen(szModule);
  359. pszModule = szModule + cchModule;
  360. while (cchModule-- > 0) {
  361. pszModule--;
  362. if ('\\' == *pszModule || ':' == *pszModule) {
  363. pszModule++;
  364. break;
  365. }
  366. }
  367. if (0 >= MultiByteToWideChar(
  368. CP_ACP,
  369. 0, // dwFlags
  370. pszModule,
  371. -1, // null terminated
  372. wszModule,
  373. _MAX_PATH))
  374. return HError();
  375. return S_OK;
  376. }
  377. //+-------------------------------------------------------------------------
  378. // DllRegisterServer
  379. //--------------------------------------------------------------------------
  380. STDAPI DllRegisterServer(void)
  381. {
  382. HRESULT hr;
  383. WCHAR wszModule[_MAX_PATH];
  384. if (FAILED(hr = GetDllFilename(wszModule)))
  385. return hr;
  386. if (!CryptRegisterOIDFunction(
  387. 0, // dwEncodingType
  388. CRYPT_OID_OPEN_STORE_PROV_FUNC,
  389. sz_CERT_STORE_PROV_TEST_EXT,
  390. wszModule,
  391. TEST_EXT_OPEN_STORE_PROV_FUNC
  392. )) {
  393. if (ERROR_FILE_EXISTS != GetLastError())
  394. return HError();
  395. }
  396. return S_OK;
  397. }
  398. //+-------------------------------------------------------------------------
  399. // DllUnregisterServer
  400. //--------------------------------------------------------------------------
  401. STDAPI DllUnregisterServer(void)
  402. {
  403. HRESULT hr;
  404. WCHAR wszModule[_MAX_PATH];
  405. if (FAILED(hr = GetDllFilename(wszModule)))
  406. return hr;
  407. if (!CryptUnregisterOIDFunction(
  408. 0, // dwEncodingType
  409. CRYPT_OID_OPEN_STORE_PROV_FUNC,
  410. sz_CERT_STORE_PROV_TEST_EXT
  411. )) {
  412. if (ERROR_FILE_NOT_FOUND != GetLastError())
  413. return HError();
  414. }
  415. return S_OK;
  416. }
  417. //+-------------------------------------------------------------------------
  418. // Implement the "test" external store by opening the corresponding system
  419. // registry store.
  420. //--------------------------------------------------------------------------
  421. BOOL
  422. WINAPI
  423. I_CertDllOpenTestExtStoreProvW(
  424. IN LPCSTR lpszStoreProvider,
  425. IN DWORD dwEncodingType,
  426. IN HCRYPTPROV hCryptProv,
  427. IN DWORD dwFlags,
  428. IN const void *pvPara,
  429. IN HCERTSTORE hCertStore,
  430. IN OUT PCERT_STORE_PROV_INFO pStoreProvInfo
  431. )
  432. {
  433. BOOL fResult;
  434. PEXT_STORE pExtStore = NULL;
  435. if (0 == (dwFlags & CERT_SYSTEM_STORE_LOCATION_MASK))
  436. dwFlags |= CERT_SYSTEM_STORE_CURRENT_USER;
  437. dwFlags |= CERT_STORE_NO_CRYPT_RELEASE_FLAG;
  438. if (dwFlags & CERT_STORE_DELETE_FLAG) {
  439. CertOpenStore(
  440. CERT_STORE_PROV_SYSTEM_W,
  441. dwEncodingType,
  442. hCryptProv,
  443. dwFlags,
  444. pvPara
  445. );
  446. pStoreProvInfo->dwStoreProvFlags |= CERT_STORE_PROV_DELETED_FLAG;
  447. if (0 == GetLastError())
  448. return TRUE;
  449. else
  450. return FALSE;
  451. }
  452. if (NULL == (pExtStore = (PEXT_STORE) CSAlloc(sizeof(EXT_STORE))))
  453. goto OutOfMemory;
  454. memset(pExtStore, 0, sizeof(EXT_STORE));
  455. if (NULL == (pExtStore->hExtCertStore = CertOpenStore(
  456. CERT_STORE_PROV_SYSTEM_W,
  457. dwEncodingType,
  458. hCryptProv,
  459. dwFlags,
  460. pvPara
  461. )))
  462. goto OpenStoreError;
  463. pStoreProvInfo->cStoreProvFunc = EXT_STORE_PROV_FUNC_COUNT;
  464. pStoreProvInfo->rgpvStoreProvFunc = (void **) rgpvExtStoreProvFunc;
  465. pStoreProvInfo->hStoreProv = (HCERTSTOREPROV) pExtStore;
  466. pStoreProvInfo->dwStoreProvFlags |= CERT_STORE_PROV_EXTERNAL_FLAG;
  467. fResult = TRUE;
  468. CommonReturn:
  469. return fResult;
  470. ErrorReturn:
  471. ExtStoreProvClose((HCERTSTOREPROV) pExtStore, 0);
  472. fResult = FALSE;
  473. goto CommonReturn;
  474. TRACE_ERROR(OutOfMemory)
  475. TRACE_ERROR(OpenStoreError)
  476. }
  477. //+-------------------------------------------------------------------------
  478. // Close the registry's store by closing its opened registry subkeys
  479. //--------------------------------------------------------------------------
  480. static void WINAPI ExtStoreProvClose(
  481. IN HCERTSTOREPROV hStoreProv,
  482. IN DWORD dwFlags
  483. )
  484. {
  485. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  486. if (pExtStore) {
  487. if (pExtStore->hExtCertStore)
  488. CertCloseStore(pExtStore->hExtCertStore, 0);
  489. CSFree(pExtStore);
  490. }
  491. }
  492. //+---------------------------------------------------------------------------
  493. // Find certificate in system store corresponding to pCertContext
  494. //----------------------------------------------------------------------------
  495. static PCCERT_CONTEXT FindCorrespondingCertificate (
  496. IN HCERTSTORE hExtCertStore,
  497. IN PCCERT_CONTEXT pCertContext
  498. )
  499. {
  500. DWORD cbHash = MAX_HASH_LEN;
  501. BYTE aHash[MAX_HASH_LEN];
  502. CRYPT_HASH_BLOB HashBlob;
  503. if ( CertGetCertificateContextProperty(
  504. pCertContext,
  505. CERT_HASH_PROP_ID,
  506. aHash,
  507. &cbHash
  508. ) == FALSE )
  509. {
  510. return( NULL );
  511. }
  512. HashBlob.cbData = cbHash;
  513. HashBlob.pbData = aHash;
  514. return( CertFindCertificateInStore(
  515. hExtCertStore,
  516. X509_ASN_ENCODING,
  517. 0,
  518. CERT_FIND_HASH,
  519. &HashBlob,
  520. NULL
  521. ) );
  522. }
  523. //+---------------------------------------------------------------------------
  524. // Find CRL in system store corresponding to pCrlContext
  525. //----------------------------------------------------------------------------
  526. static PCCRL_CONTEXT FindCorrespondingCrl (
  527. IN HCERTSTORE hExtCertStore,
  528. IN PCCRL_CONTEXT pCrlContext
  529. )
  530. {
  531. DWORD cbHash = MAX_HASH_LEN;
  532. BYTE aHash[MAX_HASH_LEN];
  533. DWORD cbFindHash = MAX_HASH_LEN;
  534. BYTE aFindHash[MAX_HASH_LEN];
  535. PCCRL_CONTEXT pFindCrl = NULL;
  536. DWORD dwFlags = 0;
  537. if ( CertGetCRLContextProperty(
  538. pCrlContext,
  539. CERT_HASH_PROP_ID,
  540. aHash,
  541. &cbHash
  542. ) == FALSE )
  543. {
  544. return( NULL );
  545. }
  546. while ( ( pFindCrl = CertGetCRLFromStore(
  547. hExtCertStore,
  548. NULL,
  549. pFindCrl,
  550. &dwFlags
  551. ) ) != NULL )
  552. {
  553. if ( CertGetCRLContextProperty(
  554. pFindCrl,
  555. CERT_HASH_PROP_ID,
  556. aFindHash,
  557. &cbFindHash
  558. ) == TRUE )
  559. {
  560. if ( cbHash == cbFindHash )
  561. {
  562. if ( memcmp( aHash, aFindHash, cbHash ) == 0 )
  563. {
  564. return( pFindCrl );
  565. }
  566. }
  567. }
  568. }
  569. return( NULL );
  570. }
  571. //+---------------------------------------------------------------------------
  572. // Find CTL in system store corresponding to pCtlContext
  573. //----------------------------------------------------------------------------
  574. static PCCTL_CONTEXT FindCorrespondingCtl (
  575. IN HCERTSTORE hExtCertStore,
  576. IN PCCTL_CONTEXT pCtlContext
  577. )
  578. {
  579. DWORD cbHash = MAX_HASH_LEN;
  580. BYTE aHash[MAX_HASH_LEN];
  581. CRYPT_HASH_BLOB HashBlob;
  582. if ( CertGetCTLContextProperty(
  583. pCtlContext,
  584. CERT_SHA1_HASH_PROP_ID,
  585. aHash,
  586. &cbHash
  587. ) == FALSE )
  588. {
  589. return( NULL );
  590. }
  591. HashBlob.cbData = cbHash;
  592. HashBlob.pbData = aHash;
  593. return( CertFindCTLInStore(
  594. hExtCertStore,
  595. X509_ASN_ENCODING,
  596. 0,
  597. CTL_FIND_SHA1_HASH,
  598. &HashBlob,
  599. NULL
  600. ) );
  601. }
  602. //+-------------------------------------------------------------------------
  603. // Read the serialized copy of the certificate and its properties from
  604. // the registry and create a new certificate context.
  605. //--------------------------------------------------------------------------
  606. static BOOL WINAPI ExtStoreProvReadCert(
  607. IN HCERTSTOREPROV hStoreProv,
  608. IN PCCERT_CONTEXT pStoreCertContext,
  609. IN DWORD dwFlags,
  610. OUT PCCERT_CONTEXT *ppProvCertContext
  611. )
  612. {
  613. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  614. PCCERT_CONTEXT pProvCertContext;
  615. assert(pExtStore && pExtStore->hExtCertStore);
  616. pProvCertContext = FindCorrespondingCertificate(
  617. pExtStore->hExtCertStore, pStoreCertContext);
  618. *ppProvCertContext = pProvCertContext;
  619. return NULL != pProvCertContext;
  620. }
  621. //+-------------------------------------------------------------------------
  622. // Serialize the encoded certificate and its properties and write to
  623. // the registry.
  624. //
  625. // Called before the certificate is written to the store.
  626. //--------------------------------------------------------------------------
  627. static BOOL WINAPI ExtStoreProvWriteCert(
  628. IN HCERTSTOREPROV hStoreProv,
  629. IN PCCERT_CONTEXT pCertContext,
  630. IN DWORD dwFlags
  631. )
  632. {
  633. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  634. DWORD dwAddDisposition;
  635. assert(pExtStore && pExtStore->hExtCertStore);
  636. if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG)
  637. dwAddDisposition = (dwFlags >> 16) & 0xFFFF;
  638. else
  639. dwAddDisposition = 0;
  640. return CertAddCertificateContextToStore(
  641. pExtStore->hExtCertStore,
  642. pCertContext,
  643. dwAddDisposition,
  644. NULL // ppStoreContext
  645. );
  646. }
  647. //+-------------------------------------------------------------------------
  648. // Delete the specified certificate from the registry.
  649. //
  650. // Called before the certificate is deleted from the store.
  651. //+-------------------------------------------------------------------------
  652. static BOOL WINAPI ExtStoreProvDeleteCert(
  653. IN HCERTSTOREPROV hStoreProv,
  654. IN PCCERT_CONTEXT pCertContext,
  655. IN DWORD dwFlags
  656. )
  657. {
  658. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  659. PCCERT_CONTEXT pExtContext;
  660. assert(pExtStore && pExtStore->hExtCertStore);
  661. if (pExtContext = FindCorrespondingCertificate(
  662. pExtStore->hExtCertStore, pCertContext))
  663. return CertDeleteCertificateFromStore(pExtContext);
  664. else
  665. return FALSE;
  666. }
  667. //+-------------------------------------------------------------------------
  668. // Read the specified certificate from the registry and update its
  669. // property.
  670. //
  671. // Note, ignore the CERT_SHA1_HASH_PROP_ID property which is implicitly
  672. // set before we write the certificate to the registry. If we don't ignore,
  673. // we will have indefinite recursion.
  674. //
  675. // Called before setting the property of the certificate in the store.
  676. //--------------------------------------------------------------------------
  677. static BOOL WINAPI ExtStoreProvSetCertProperty(
  678. IN HCERTSTOREPROV hStoreProv,
  679. IN PCCERT_CONTEXT pCertContext,
  680. IN DWORD dwPropId,
  681. IN DWORD dwFlags,
  682. IN const void *pvData
  683. )
  684. {
  685. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  686. PCCERT_CONTEXT pExtContext;
  687. assert(pExtStore && pExtStore->hExtCertStore);
  688. if (pExtContext = FindCorrespondingCertificate(
  689. pExtStore->hExtCertStore, pCertContext)) {
  690. BOOL fResult;
  691. fResult = CertSetCertificateContextProperty(
  692. pExtContext,
  693. dwPropId,
  694. dwFlags,
  695. pvData
  696. );
  697. CertFreeCertificateContext(pExtContext);
  698. return fResult;
  699. } else
  700. return FALSE;
  701. }
  702. //+-------------------------------------------------------------------------
  703. // Read the serialized copy of the CRL and its properties from
  704. // the registry and create a new CRL context.
  705. //--------------------------------------------------------------------------
  706. static BOOL WINAPI ExtStoreProvReadCrl(
  707. IN HCERTSTOREPROV hStoreProv,
  708. IN PCCRL_CONTEXT pStoreCrlContext,
  709. IN DWORD dwFlags,
  710. OUT PCCRL_CONTEXT *ppProvCrlContext
  711. )
  712. {
  713. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  714. PCCRL_CONTEXT pProvCrlContext;
  715. assert(pExtStore && pExtStore->hExtCertStore);
  716. pProvCrlContext = FindCorrespondingCrl(
  717. pExtStore->hExtCertStore, pStoreCrlContext);
  718. *ppProvCrlContext = pProvCrlContext;
  719. return NULL != pProvCrlContext;
  720. }
  721. //+-------------------------------------------------------------------------
  722. // Serialize the encoded CRL and its properties and write to
  723. // the registry.
  724. //
  725. // Called before the CRL is written to the store.
  726. //--------------------------------------------------------------------------
  727. static BOOL WINAPI ExtStoreProvWriteCrl(
  728. IN HCERTSTOREPROV hStoreProv,
  729. IN PCCRL_CONTEXT pCrlContext,
  730. IN DWORD dwFlags
  731. )
  732. {
  733. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  734. DWORD dwAddDisposition;
  735. assert(pExtStore && pExtStore->hExtCertStore);
  736. if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG)
  737. dwAddDisposition = (dwFlags >> 16) & 0xFFFF;
  738. else
  739. dwAddDisposition = 0;
  740. return CertAddCRLContextToStore(
  741. pExtStore->hExtCertStore,
  742. pCrlContext,
  743. dwAddDisposition,
  744. NULL // ppStoreContext
  745. );
  746. }
  747. //+-------------------------------------------------------------------------
  748. // Delete the specified CRL from the registry.
  749. //
  750. // Called before the CRL is deleted from the store.
  751. //+-------------------------------------------------------------------------
  752. static BOOL WINAPI ExtStoreProvDeleteCrl(
  753. IN HCERTSTOREPROV hStoreProv,
  754. IN PCCRL_CONTEXT pCrlContext,
  755. IN DWORD dwFlags
  756. )
  757. {
  758. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  759. PCCRL_CONTEXT pExtContext;
  760. assert(pExtStore && pExtStore->hExtCertStore);
  761. if (pExtContext = FindCorrespondingCrl(
  762. pExtStore->hExtCertStore, pCrlContext))
  763. return CertDeleteCRLFromStore(pExtContext);
  764. else
  765. return FALSE;
  766. }
  767. //+-------------------------------------------------------------------------
  768. // Read the specified CRL from the registry and update its
  769. // property.
  770. //
  771. // Note, ignore the CERT_SHA1_HASH_PROP_ID property which is implicitly
  772. // set before we write the CRL to the registry. If we don't ignore,
  773. // we will have indefinite recursion.
  774. //
  775. // Called before setting the property of the CRL in the store.
  776. //--------------------------------------------------------------------------
  777. static BOOL WINAPI ExtStoreProvSetCrlProperty(
  778. IN HCERTSTOREPROV hStoreProv,
  779. IN PCCRL_CONTEXT pCrlContext,
  780. IN DWORD dwPropId,
  781. IN DWORD dwFlags,
  782. IN const void *pvData
  783. )
  784. {
  785. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  786. PCCRL_CONTEXT pExtContext;
  787. assert(pExtStore && pExtStore->hExtCertStore);
  788. if (pExtContext = FindCorrespondingCrl(
  789. pExtStore->hExtCertStore, pCrlContext)) {
  790. BOOL fResult;
  791. fResult = CertSetCRLContextProperty(
  792. pExtContext,
  793. dwPropId,
  794. dwFlags,
  795. pvData
  796. );
  797. CertFreeCRLContext(pExtContext);
  798. return fResult;
  799. } else
  800. return FALSE;
  801. }
  802. //+-------------------------------------------------------------------------
  803. // Read the serialized copy of the CTL and its properties from
  804. // the registry and create a new CTL context.
  805. //--------------------------------------------------------------------------
  806. static BOOL WINAPI ExtStoreProvReadCtl(
  807. IN HCERTSTOREPROV hStoreProv,
  808. IN PCCTL_CONTEXT pStoreCtlContext,
  809. IN DWORD dwFlags,
  810. OUT PCCTL_CONTEXT *ppProvCtlContext
  811. )
  812. {
  813. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  814. PCCTL_CONTEXT pProvCtlContext;
  815. assert(pExtStore && pExtStore->hExtCertStore);
  816. pProvCtlContext = FindCorrespondingCtl(
  817. pExtStore->hExtCertStore, pStoreCtlContext);
  818. *ppProvCtlContext = pProvCtlContext;
  819. return NULL != pProvCtlContext;
  820. }
  821. //+-------------------------------------------------------------------------
  822. // Serialize the encoded CTL and its properties and write to
  823. // the registry.
  824. //
  825. // Called before the CTL is written to the store.
  826. //--------------------------------------------------------------------------
  827. static BOOL WINAPI ExtStoreProvWriteCtl(
  828. IN HCERTSTOREPROV hStoreProv,
  829. IN PCCTL_CONTEXT pCtlContext,
  830. IN DWORD dwFlags
  831. )
  832. {
  833. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  834. DWORD dwAddDisposition;
  835. assert(pExtStore && pExtStore->hExtCertStore);
  836. if (dwFlags & CERT_STORE_PROV_WRITE_ADD_FLAG)
  837. dwAddDisposition = (dwFlags >> 16) & 0xFFFF;
  838. else
  839. dwAddDisposition = 0;
  840. return CertAddCTLContextToStore(
  841. pExtStore->hExtCertStore,
  842. pCtlContext,
  843. dwAddDisposition,
  844. NULL // ppStoreContext
  845. );
  846. }
  847. //+-------------------------------------------------------------------------
  848. // Delete the specified CTL from the registry.
  849. //
  850. // Called before the CTL is deleted from the store.
  851. //+-------------------------------------------------------------------------
  852. static BOOL WINAPI ExtStoreProvDeleteCtl(
  853. IN HCERTSTOREPROV hStoreProv,
  854. IN PCCTL_CONTEXT pCtlContext,
  855. IN DWORD dwFlags
  856. )
  857. {
  858. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  859. PCCTL_CONTEXT pExtContext;
  860. assert(pExtStore && pExtStore->hExtCertStore);
  861. if (pExtContext = FindCorrespondingCtl(
  862. pExtStore->hExtCertStore, pCtlContext))
  863. return CertDeleteCTLFromStore(pExtContext);
  864. else
  865. return FALSE;
  866. }
  867. //+-------------------------------------------------------------------------
  868. // Read the specified CTL from the registry and update its
  869. // property.
  870. //
  871. // Note, ignore the CERT_SHA1_HASH_PROP_ID property which is implicitly
  872. // set before we write the CTL to the registry. If we don't ignore,
  873. // we will have indefinite recursion.
  874. //
  875. // Called before setting the property of the CTL in the store.
  876. //--------------------------------------------------------------------------
  877. static BOOL WINAPI ExtStoreProvSetCtlProperty(
  878. IN HCERTSTOREPROV hStoreProv,
  879. IN PCCTL_CONTEXT pCtlContext,
  880. IN DWORD dwPropId,
  881. IN DWORD dwFlags,
  882. IN const void *pvData
  883. )
  884. {
  885. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  886. PCCTL_CONTEXT pExtContext;
  887. assert(pExtStore && pExtStore->hExtCertStore);
  888. if (pExtContext = FindCorrespondingCtl(
  889. pExtStore->hExtCertStore, pCtlContext)) {
  890. BOOL fResult;
  891. fResult = CertSetCTLContextProperty(
  892. pExtContext,
  893. dwPropId,
  894. dwFlags,
  895. pvData
  896. );
  897. CertFreeCTLContext(pExtContext);
  898. return fResult;
  899. } else
  900. return FALSE;
  901. }
  902. static BOOL WINAPI ExtStoreProvControl(
  903. IN HCERTSTOREPROV hStoreProv,
  904. IN DWORD dwFlags,
  905. IN DWORD dwCtrlType,
  906. IN void const *pvCtrlPara
  907. )
  908. {
  909. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  910. assert(pExtStore && pExtStore->hExtCertStore);
  911. return CertControlStore(
  912. pExtStore->hExtCertStore,
  913. dwFlags,
  914. dwCtrlType,
  915. pvCtrlPara
  916. );
  917. }
  918. static BOOL WINAPI ExtStoreProvFindCert(
  919. IN HCERTSTOREPROV hStoreProv,
  920. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  921. IN PCCERT_CONTEXT pPrevCertContext,
  922. IN DWORD dwFlags,
  923. IN OUT void **ppvStoreProvFindInfo,
  924. OUT PCCERT_CONTEXT *ppProvCertContext
  925. )
  926. {
  927. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  928. PFIND_EXT_INFO pFindExtInfo = (PFIND_EXT_INFO) *ppvStoreProvFindInfo;
  929. PCCERT_CONTEXT pPrevExtContext;
  930. PCCERT_CONTEXT pProvCertContext;
  931. if (pFindExtInfo) {
  932. assert((CERT_STORE_CERTIFICATE_CONTEXT - 1) ==
  933. pFindExtInfo->dwContextType);
  934. pPrevExtContext = (PCCERT_CONTEXT) pFindExtInfo->pvContext;
  935. pFindExtInfo->pvContext = NULL;
  936. } else
  937. pPrevExtContext = NULL;
  938. assert(pExtStore);
  939. assert(pPrevCertContext == pPrevExtContext);
  940. if (pProvCertContext = CertFindCertificateInStore(
  941. pExtStore->hExtCertStore,
  942. pFindInfo->dwMsgAndCertEncodingType,
  943. pFindInfo->dwFindFlags,
  944. pFindInfo->dwFindType,
  945. pFindInfo->pvFindPara,
  946. pPrevExtContext
  947. )) {
  948. if (pFindExtInfo)
  949. // Re-use existing Find Info
  950. pFindExtInfo->pvContext = (void *) CertDuplicateCertificateContext(
  951. pProvCertContext);
  952. else {
  953. if (pFindExtInfo = CreateExtInfo(
  954. CERT_STORE_CERTIFICATE_CONTEXT - 1,
  955. (void *) pProvCertContext
  956. ))
  957. pProvCertContext = CertDuplicateCertificateContext(
  958. pProvCertContext);
  959. else {
  960. CertFreeCertificateContext(pProvCertContext);
  961. pProvCertContext = NULL;
  962. }
  963. }
  964. } else if (pFindExtInfo) {
  965. ExtStoreProvFreeFindCert(
  966. hStoreProv,
  967. pPrevCertContext,
  968. pFindExtInfo,
  969. 0 // dwFlags
  970. );
  971. pFindExtInfo = NULL;
  972. }
  973. *ppProvCertContext = pProvCertContext;
  974. *ppvStoreProvFindInfo = pFindExtInfo;
  975. return NULL != pProvCertContext;
  976. }
  977. static BOOL WINAPI ExtStoreProvFreeFindCert(
  978. IN HCERTSTOREPROV hStoreProv,
  979. IN PCCERT_CONTEXT pCertContext,
  980. IN void *pvStoreProvFindInfo,
  981. IN DWORD dwFlags
  982. )
  983. {
  984. PFIND_EXT_INFO pFindExtInfo = (PFIND_EXT_INFO) pvStoreProvFindInfo;
  985. assert(pFindExtInfo);
  986. if (pFindExtInfo) {
  987. assert((CERT_STORE_CERTIFICATE_CONTEXT - 1) ==
  988. pFindExtInfo->dwContextType);
  989. FreeExtInfo(pFindExtInfo);
  990. }
  991. return TRUE;
  992. }
  993. static BOOL WINAPI ExtStoreProvGetCertProperty(
  994. IN HCERTSTOREPROV hStoreProv,
  995. IN PCCERT_CONTEXT pCertContext,
  996. IN DWORD dwPropId,
  997. IN DWORD dwFlags,
  998. OUT void *pvData,
  999. IN OUT DWORD *pcbData
  1000. )
  1001. {
  1002. *pcbData = 0;
  1003. SetLastError((DWORD) CRYPT_E_NOT_FOUND);
  1004. return FALSE;
  1005. }
  1006. static PCCRL_CONTEXT WINAPI FindCrlInStore(
  1007. IN HCERTSTORE hCertStore,
  1008. IN DWORD dwCertEncodingType,
  1009. IN DWORD dwFindFlags,
  1010. IN DWORD dwFindType,
  1011. IN const void *pvFindPara,
  1012. IN PCCRL_CONTEXT pPrevCrlContext
  1013. )
  1014. {
  1015. DWORD dwFlags = 0;
  1016. switch (dwFindType) {
  1017. case CRL_FIND_ANY:
  1018. return CertGetCRLFromStore(
  1019. hCertStore,
  1020. NULL, // pIssuerContext,
  1021. pPrevCrlContext,
  1022. &dwFlags
  1023. );
  1024. break;
  1025. case CRL_FIND_ISSUED_BY:
  1026. {
  1027. PCCERT_CONTEXT pIssuer = (PCCERT_CONTEXT) pvFindPara;
  1028. return CertGetCRLFromStore(
  1029. hCertStore,
  1030. pIssuer,
  1031. pPrevCrlContext,
  1032. &dwFlags
  1033. );
  1034. }
  1035. break;
  1036. case CRL_FIND_EXISTING:
  1037. {
  1038. PCCRL_CONTEXT pCrl = pPrevCrlContext;
  1039. while (pCrl = CertGetCRLFromStore(
  1040. hCertStore,
  1041. NULL, // pIssuerContext,
  1042. pCrl,
  1043. &dwFlags)) {
  1044. PCCRL_CONTEXT pNew = (PCCRL_CONTEXT) pvFindPara;
  1045. if (pNew->dwCertEncodingType == pCrl->dwCertEncodingType &&
  1046. CertCompareCertificateName(
  1047. pNew->dwCertEncodingType,
  1048. &pCrl->pCrlInfo->Issuer,
  1049. &pNew->pCrlInfo->Issuer))
  1050. return pCrl;
  1051. }
  1052. return NULL;
  1053. }
  1054. break;
  1055. default:
  1056. SetLastError((DWORD) ERROR_NOT_SUPPORTED);
  1057. return NULL;
  1058. }
  1059. }
  1060. static BOOL WINAPI ExtStoreProvFindCrl(
  1061. IN HCERTSTOREPROV hStoreProv,
  1062. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  1063. IN PCCRL_CONTEXT pPrevCrlContext,
  1064. IN DWORD dwFlags,
  1065. IN OUT void **ppvStoreProvFindInfo,
  1066. OUT PCCRL_CONTEXT *ppProvCrlContext
  1067. )
  1068. {
  1069. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  1070. PFIND_EXT_INFO pFindExtInfo = (PFIND_EXT_INFO) *ppvStoreProvFindInfo;
  1071. PCCRL_CONTEXT pPrevExtContext;
  1072. PCCRL_CONTEXT pProvCrlContext;
  1073. if (pFindExtInfo) {
  1074. assert((CERT_STORE_CRL_CONTEXT - 1) ==
  1075. pFindExtInfo->dwContextType);
  1076. pPrevExtContext = (PCCRL_CONTEXT) pFindExtInfo->pvContext;
  1077. pFindExtInfo->pvContext = NULL;
  1078. } else
  1079. pPrevExtContext = NULL;
  1080. assert(pExtStore);
  1081. assert(pPrevCrlContext == pPrevExtContext);
  1082. if (pProvCrlContext = FindCrlInStore(
  1083. pExtStore->hExtCertStore,
  1084. pFindInfo->dwMsgAndCertEncodingType,
  1085. pFindInfo->dwFindFlags,
  1086. pFindInfo->dwFindType,
  1087. pFindInfo->pvFindPara,
  1088. pPrevExtContext
  1089. )) {
  1090. if (pFindExtInfo)
  1091. // Re-use existing Find Info
  1092. pFindExtInfo->pvContext = (void *) CertDuplicateCRLContext(
  1093. pProvCrlContext);
  1094. else {
  1095. if (pFindExtInfo = CreateExtInfo(
  1096. CERT_STORE_CRL_CONTEXT - 1,
  1097. (void *) pProvCrlContext
  1098. ))
  1099. pProvCrlContext = CertDuplicateCRLContext(
  1100. pProvCrlContext);
  1101. else {
  1102. CertFreeCRLContext(pProvCrlContext);
  1103. pProvCrlContext = NULL;
  1104. }
  1105. }
  1106. } else if (pFindExtInfo) {
  1107. ExtStoreProvFreeFindCrl(
  1108. hStoreProv,
  1109. pPrevCrlContext,
  1110. pFindExtInfo,
  1111. 0 // dwFlags
  1112. );
  1113. pFindExtInfo = NULL;
  1114. }
  1115. *ppProvCrlContext = pProvCrlContext;
  1116. *ppvStoreProvFindInfo = pFindExtInfo;
  1117. return NULL != pProvCrlContext;
  1118. }
  1119. static BOOL WINAPI ExtStoreProvFreeFindCrl(
  1120. IN HCERTSTOREPROV hStoreProv,
  1121. IN PCCRL_CONTEXT pCrlContext,
  1122. IN void *pvStoreProvFindInfo,
  1123. IN DWORD dwFlags
  1124. )
  1125. {
  1126. PFIND_EXT_INFO pFindExtInfo = (PFIND_EXT_INFO) pvStoreProvFindInfo;
  1127. assert(pFindExtInfo);
  1128. if (pFindExtInfo) {
  1129. assert((CERT_STORE_CRL_CONTEXT - 1) ==
  1130. pFindExtInfo->dwContextType);
  1131. FreeExtInfo(pFindExtInfo);
  1132. }
  1133. return TRUE;
  1134. }
  1135. static BOOL WINAPI ExtStoreProvGetCrlProperty(
  1136. IN HCERTSTOREPROV hStoreProv,
  1137. IN PCCRL_CONTEXT pCrlContext,
  1138. IN DWORD dwPropId,
  1139. IN DWORD dwFlags,
  1140. OUT void *pvData,
  1141. IN OUT DWORD *pcbData
  1142. )
  1143. {
  1144. *pcbData = 0;
  1145. SetLastError((DWORD) CRYPT_E_NOT_FOUND);
  1146. return FALSE;
  1147. }
  1148. static BOOL WINAPI ExtStoreProvFindCtl(
  1149. IN HCERTSTOREPROV hStoreProv,
  1150. IN PCCERT_STORE_PROV_FIND_INFO pFindInfo,
  1151. IN PCCTL_CONTEXT pPrevCtlContext,
  1152. IN DWORD dwFlags,
  1153. IN OUT void **ppvStoreProvFindInfo,
  1154. OUT PCCTL_CONTEXT *ppProvCtlContext
  1155. )
  1156. {
  1157. PEXT_STORE pExtStore = (PEXT_STORE) hStoreProv;
  1158. PFIND_EXT_INFO pFindExtInfo = (PFIND_EXT_INFO) *ppvStoreProvFindInfo;
  1159. PCCTL_CONTEXT pPrevExtContext;
  1160. PCCTL_CONTEXT pProvCtlContext;
  1161. if (pFindExtInfo) {
  1162. assert((CERT_STORE_CTL_CONTEXT - 1) ==
  1163. pFindExtInfo->dwContextType);
  1164. pPrevExtContext = (PCCTL_CONTEXT) pFindExtInfo->pvContext;
  1165. pFindExtInfo->pvContext = NULL;
  1166. } else
  1167. pPrevExtContext = NULL;
  1168. assert(pExtStore);
  1169. assert(pPrevCtlContext == pPrevExtContext);
  1170. if (pProvCtlContext = CertFindCTLInStore(
  1171. pExtStore->hExtCertStore,
  1172. pFindInfo->dwMsgAndCertEncodingType,
  1173. pFindInfo->dwFindFlags,
  1174. pFindInfo->dwFindType,
  1175. pFindInfo->pvFindPara,
  1176. pPrevExtContext
  1177. )) {
  1178. if (pFindExtInfo)
  1179. // Re-use existing Find Info
  1180. pFindExtInfo->pvContext = (void *) CertDuplicateCTLContext(
  1181. pProvCtlContext);
  1182. else {
  1183. if (pFindExtInfo = CreateExtInfo(
  1184. CERT_STORE_CTL_CONTEXT - 1,
  1185. (void *) pProvCtlContext
  1186. ))
  1187. pProvCtlContext = CertDuplicateCTLContext(pProvCtlContext);
  1188. else {
  1189. CertFreeCTLContext(pProvCtlContext);
  1190. pProvCtlContext = NULL;
  1191. }
  1192. }
  1193. } else if (pFindExtInfo) {
  1194. ExtStoreProvFreeFindCtl(
  1195. hStoreProv,
  1196. pPrevCtlContext,
  1197. pFindExtInfo,
  1198. 0 // dwFlags
  1199. );
  1200. pFindExtInfo = NULL;
  1201. }
  1202. *ppProvCtlContext = pProvCtlContext;
  1203. *ppvStoreProvFindInfo = pFindExtInfo;
  1204. return NULL != pProvCtlContext;
  1205. }
  1206. static BOOL WINAPI ExtStoreProvFreeFindCtl(
  1207. IN HCERTSTOREPROV hStoreProv,
  1208. IN PCCTL_CONTEXT pCtlContext,
  1209. IN void *pvStoreProvFindInfo,
  1210. IN DWORD dwFlags
  1211. )
  1212. {
  1213. PFIND_EXT_INFO pFindExtInfo = (PFIND_EXT_INFO) pvStoreProvFindInfo;
  1214. assert(pFindExtInfo);
  1215. if (pFindExtInfo) {
  1216. assert((CERT_STORE_CTL_CONTEXT - 1) ==
  1217. pFindExtInfo->dwContextType);
  1218. FreeExtInfo(pFindExtInfo);
  1219. }
  1220. return TRUE;
  1221. }
  1222. static BOOL WINAPI ExtStoreProvGetCtlProperty(
  1223. IN HCERTSTOREPROV hStoreProv,
  1224. IN PCCTL_CONTEXT pCtlContext,
  1225. IN DWORD dwPropId,
  1226. IN DWORD dwFlags,
  1227. OUT void *pvData,
  1228. IN OUT DWORD *pcbData
  1229. )
  1230. {
  1231. *pcbData = 0;
  1232. SetLastError((DWORD) CRYPT_E_NOT_FOUND);
  1233. return FALSE;
  1234. }