Source code of Windows XP (NT5)
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.

943 lines
24 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <ntsecapi.h>
  6. #include <wincrypt.h>
  7. #include <userenv.h>
  8. #include <lmcons.h>
  9. #include <certca.h>
  10. #include "keysvc.h"
  11. #include "cryptui.h"
  12. #include "lenroll.h"
  13. #include "keysvcc.h"
  14. DWORD BindLocalKeyService(handle_t *hProxy);
  15. // key service stub functions
  16. ULONG s_KeyrOpenKeyService(
  17. /* [in] */ handle_t hRPCBinding,
  18. /* [in] */ KEYSVC_TYPE OwnerType,
  19. /* [in] */ PKEYSVC_UNICODE_STRING pOwnerName,
  20. /* [in] */ ULONG ulDesiredAccess,
  21. /* [in] */ PKEYSVC_BLOB pAuthentication,
  22. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  23. /* [out] */ KEYSVC_HANDLE *phKeySvc)
  24. {
  25. RPC_BINDING_HANDLE hProxy = NULL;
  26. RPC_STATUS RpcStatus = RPC_S_OK;
  27. RpcStatus = RpcImpersonateClient(hRPCBinding);
  28. if (RPC_S_OK != RpcStatus)
  29. {
  30. return RpcStatus;
  31. }
  32. RpcStatus = BindLocalKeyService(&hProxy);
  33. if(RPC_S_OK != RpcStatus)
  34. {
  35. goto error;
  36. }
  37. __try
  38. {
  39. RpcStatus = s_KeyrOpenKeyService(
  40. hProxy,
  41. OwnerType,
  42. pOwnerName,
  43. ulDesiredAccess,
  44. pAuthentication,
  45. ppReserved,
  46. phKeySvc);
  47. }
  48. __except ( EXCEPTION_EXECUTE_HANDLER )
  49. {
  50. RpcStatus = _exception_code();
  51. }
  52. error:
  53. if(hProxy)
  54. {
  55. RpcBindingFree(&hProxy);
  56. }
  57. RpcRevertToSelf();
  58. return RpcStatus;
  59. }
  60. ULONG s_KeyrEnumerateProviders(
  61. /* [in] */ handle_t hRPCBinding,
  62. /* [in] */ KEYSVC_HANDLE hKeySvc,
  63. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  64. /* [in, out] */ ULONG *pcProviderCount,
  65. /* [in, out][size_is(,*pcProviderCount)] */
  66. PKEYSVC_PROVIDER_INFO *ppProviders)
  67. {
  68. RPC_BINDING_HANDLE hProxy = NULL;
  69. RPC_STATUS RpcStatus = RPC_S_OK;
  70. RpcStatus = RpcImpersonateClient(hRPCBinding);
  71. if (RPC_S_OK != RpcStatus)
  72. {
  73. return RpcStatus;
  74. }
  75. RpcStatus = BindLocalKeyService(&hProxy);
  76. if(RPC_S_OK != RpcStatus)
  77. {
  78. goto error;
  79. }
  80. __try
  81. {
  82. RpcStatus = s_KeyrEnumerateProviders(
  83. hProxy,
  84. hKeySvc,
  85. ppReserved,
  86. pcProviderCount,
  87. ppProviders);
  88. }
  89. __except ( EXCEPTION_EXECUTE_HANDLER )
  90. {
  91. RpcStatus = _exception_code();
  92. }
  93. error:
  94. if(hProxy)
  95. {
  96. RpcBindingFree(&hProxy);
  97. }
  98. RpcRevertToSelf();
  99. return RpcStatus;
  100. }
  101. ULONG s_KeyrEnumerateProviderTypes(
  102. /* [in] */ handle_t hRPCBinding,
  103. /* [in] */ KEYSVC_HANDLE hKeySvc,
  104. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  105. /* [in, out] */ ULONG *pcProviderCount,
  106. /* [in, out][size_is(,*pcProviderCount)] */
  107. PKEYSVC_PROVIDER_INFO *ppProviders)
  108. {
  109. RPC_BINDING_HANDLE hProxy = NULL;
  110. RPC_STATUS RpcStatus = RPC_S_OK;
  111. RpcStatus = RpcImpersonateClient(hRPCBinding);
  112. if (RPC_S_OK != RpcStatus)
  113. {
  114. return RpcStatus;
  115. }
  116. RpcStatus = BindLocalKeyService(&hProxy);
  117. if(RPC_S_OK != RpcStatus)
  118. {
  119. goto error;
  120. }
  121. __try
  122. {
  123. RpcStatus = s_KeyrEnumerateProviderTypes(
  124. hProxy,
  125. hKeySvc,
  126. ppReserved,
  127. pcProviderCount,
  128. ppProviders);
  129. }
  130. __except ( EXCEPTION_EXECUTE_HANDLER )
  131. {
  132. RpcStatus = _exception_code();
  133. }
  134. error:
  135. if(hProxy)
  136. {
  137. RpcBindingFree(&hProxy);
  138. }
  139. RpcRevertToSelf();
  140. return RpcStatus;
  141. }
  142. ULONG s_KeyrEnumerateProvContainers(
  143. /* [in] */ handle_t hRPCBinding,
  144. /* [in] */ KEYSVC_HANDLE hKeySvc,
  145. /* [in] */ KEYSVC_PROVIDER_INFO Provider,
  146. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  147. /* [in, out] */ ULONG *pcContainerCount,
  148. /* [in, out][size_is(,*pcContainerCount)] */
  149. PKEYSVC_UNICODE_STRING *ppContainers)
  150. {
  151. RPC_BINDING_HANDLE hProxy = NULL;
  152. RPC_STATUS RpcStatus = RPC_S_OK;
  153. RpcStatus = RpcImpersonateClient(hRPCBinding);
  154. if (RPC_S_OK != RpcStatus)
  155. {
  156. return RpcStatus;
  157. }
  158. RpcStatus = BindLocalKeyService(&hProxy);
  159. if(RPC_S_OK != RpcStatus)
  160. {
  161. goto error;
  162. }
  163. __try
  164. {
  165. RpcStatus = s_KeyrEnumerateProvContainers(
  166. hProxy,
  167. hKeySvc,
  168. Provider,
  169. ppReserved,
  170. pcContainerCount,
  171. ppContainers);
  172. }
  173. __except ( EXCEPTION_EXECUTE_HANDLER )
  174. {
  175. RpcStatus = _exception_code();
  176. }
  177. error:
  178. if(hProxy)
  179. {
  180. RpcBindingFree(&hProxy);
  181. }
  182. RpcRevertToSelf();
  183. return RpcStatus;
  184. }
  185. ULONG s_KeyrCloseKeyService(
  186. /* [in] */ handle_t hRPCBinding,
  187. /* [in] */ KEYSVC_HANDLE hKeySvc,
  188. /* [in, out] */ PKEYSVC_BLOB *ppReserved)
  189. {
  190. RPC_BINDING_HANDLE hProxy = NULL;
  191. RPC_STATUS RpcStatus = RPC_S_OK;
  192. RpcStatus = RpcImpersonateClient(hRPCBinding);
  193. if (RPC_S_OK != RpcStatus)
  194. {
  195. return RpcStatus;
  196. }
  197. RpcStatus = BindLocalKeyService(&hProxy);
  198. if(RPC_S_OK != RpcStatus)
  199. {
  200. goto error;
  201. }
  202. __try
  203. {
  204. RpcStatus = s_KeyrCloseKeyService(
  205. hProxy,
  206. hKeySvc,
  207. ppReserved);
  208. }
  209. __except ( EXCEPTION_EXECUTE_HANDLER )
  210. {
  211. RpcStatus = _exception_code();
  212. }
  213. error:
  214. if(hProxy)
  215. {
  216. RpcBindingFree(&hProxy);
  217. }
  218. RpcRevertToSelf();
  219. return RpcStatus;
  220. }
  221. ULONG s_KeyrGetDefaultProvider(
  222. /* [in] */ handle_t hRPCBinding,
  223. /* [in] */ KEYSVC_HANDLE hKeySvc,
  224. /* [in] */ ULONG ulProvType,
  225. /* [in] */ ULONG ulFlags,
  226. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  227. /* [out] */ ULONG *pulDefType,
  228. /* [out] */ PKEYSVC_PROVIDER_INFO *ppProvider)
  229. {
  230. RPC_BINDING_HANDLE hProxy = NULL;
  231. RPC_STATUS RpcStatus = RPC_S_OK;
  232. RpcStatus = RpcImpersonateClient(hRPCBinding);
  233. if (RPC_S_OK != RpcStatus)
  234. {
  235. return RpcStatus;
  236. }
  237. RpcStatus = BindLocalKeyService(&hProxy);
  238. if(RPC_S_OK != RpcStatus)
  239. {
  240. goto error;
  241. }
  242. __try
  243. {
  244. RpcStatus = s_KeyrGetDefaultProvider(
  245. hProxy,
  246. hKeySvc,
  247. ulProvType,
  248. ulFlags,
  249. ppReserved,
  250. pulDefType,
  251. ppProvider);
  252. }
  253. __except ( EXCEPTION_EXECUTE_HANDLER )
  254. {
  255. RpcStatus = _exception_code();
  256. }
  257. error:
  258. if(hProxy)
  259. {
  260. RpcBindingFree(&hProxy);
  261. }
  262. RpcRevertToSelf();
  263. return RpcStatus;
  264. }
  265. ULONG s_KeyrSetDefaultProvider(
  266. /* [in] */ handle_t hRPCBinding,
  267. /* [in] */ KEYSVC_HANDLE hKeySvc,
  268. /* [in] */ ULONG ulFlags,
  269. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  270. /* [in] */ KEYSVC_PROVIDER_INFO Provider)
  271. {
  272. RPC_BINDING_HANDLE hProxy = NULL;
  273. RPC_STATUS RpcStatus = RPC_S_OK;
  274. RpcStatus = RpcImpersonateClient(hRPCBinding);
  275. if (RPC_S_OK != RpcStatus)
  276. {
  277. return RpcStatus;
  278. }
  279. RpcStatus = BindLocalKeyService(&hProxy);
  280. if(RPC_S_OK != RpcStatus)
  281. {
  282. goto error;
  283. }
  284. __try
  285. {
  286. RpcStatus = s_KeyrSetDefaultProvider(
  287. hProxy,
  288. hKeySvc,
  289. ulFlags,
  290. ppReserved,
  291. Provider);
  292. }
  293. __except ( EXCEPTION_EXECUTE_HANDLER )
  294. {
  295. RpcStatus = _exception_code();
  296. }
  297. error:
  298. if(hProxy)
  299. {
  300. RpcBindingFree(&hProxy);
  301. }
  302. RpcRevertToSelf();
  303. return RpcStatus;
  304. }
  305. ULONG s_KeyrEnroll(
  306. /* [in] */ handle_t hRPCBinding,
  307. /* [in] */ BOOL fKeyService,
  308. /* [in] */ ULONG ulPurpose,
  309. /* [in] */ PKEYSVC_UNICODE_STRING pAcctName,
  310. /* [in] */ PKEYSVC_UNICODE_STRING pCALocation,
  311. /* [in] */ PKEYSVC_UNICODE_STRING pCAName,
  312. /* [in] */ BOOL fNewKey,
  313. /* [in] */ PKEYSVC_CERT_REQUEST_PVK_NEW pKeyNew,
  314. /* [in] */ PKEYSVC_BLOB __RPC_FAR pCert,
  315. /* [in] */ PKEYSVC_CERT_REQUEST_PVK_NEW pRenewKey,
  316. /* [in] */ PKEYSVC_UNICODE_STRING pHashAlg,
  317. /* [in] */ PKEYSVC_UNICODE_STRING pDesStore,
  318. /* [in] */ ULONG ulStoreFlags,
  319. /* [in] */ PKEYSVC_CERT_ENROLL_INFO pRequestInfo,
  320. /* [in] */ ULONG ulFlags,
  321. /* [out][in] */ PKEYSVC_BLOB __RPC_FAR *ppReserved,
  322. /* [out] */ PKEYSVC_BLOB __RPC_FAR *ppPKCS7Blob,
  323. /* [out] */ PKEYSVC_BLOB __RPC_FAR *ppHashBlob,
  324. /* [out] */ ULONG __RPC_FAR *pulStatus)
  325. {
  326. RPC_BINDING_HANDLE hProxy = NULL;
  327. RPC_STATUS RpcStatus = RPC_S_OK;
  328. RpcStatus = RpcImpersonateClient(hRPCBinding);
  329. if (RPC_S_OK != RpcStatus)
  330. {
  331. return RpcStatus;
  332. }
  333. RpcStatus = BindLocalKeyService(&hProxy);
  334. if(RPC_S_OK != RpcStatus)
  335. {
  336. goto error;
  337. }
  338. __try
  339. {
  340. RpcStatus = s_KeyrEnroll(
  341. hProxy,
  342. fKeyService,
  343. ulPurpose,
  344. pAcctName,
  345. pCALocation,
  346. pCAName,
  347. fNewKey,
  348. pKeyNew,
  349. pCert,
  350. pRenewKey,
  351. pHashAlg,
  352. pDesStore,
  353. ulStoreFlags,
  354. pRequestInfo,
  355. ulFlags,
  356. ppReserved,
  357. ppPKCS7Blob,
  358. ppHashBlob,
  359. pulStatus);
  360. }
  361. __except ( EXCEPTION_EXECUTE_HANDLER )
  362. {
  363. RpcStatus = _exception_code();
  364. }
  365. error:
  366. if(hProxy)
  367. {
  368. RpcBindingFree(&hProxy);
  369. }
  370. RpcRevertToSelf();
  371. return RpcStatus;
  372. }
  373. ULONG s_KeyrExportCert(
  374. /* [in] */ handle_t hRPCBinding,
  375. /* [in] */ KEYSVC_HANDLE hKeySvc,
  376. /* [in] */ PKEYSVC_UNICODE_STRING pPassword,
  377. /* [in] */ PKEYSVC_UNICODE_STRING pCertStore,
  378. /* [in] */ ULONG cHashCount,
  379. /* [size_is][in] */
  380. KEYSVC_CERT_HASH *pHashes,
  381. /* [in] */ ULONG ulFlags,
  382. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  383. /* [out] */ PKEYSVC_BLOB *ppPFXBlob)
  384. {
  385. RPC_BINDING_HANDLE hProxy = NULL;
  386. RPC_STATUS RpcStatus = RPC_S_OK;
  387. RpcStatus = RpcImpersonateClient(hRPCBinding);
  388. if (RPC_S_OK != RpcStatus)
  389. {
  390. return RpcStatus;
  391. }
  392. RpcStatus = BindLocalKeyService(&hProxy);
  393. if(RPC_S_OK != RpcStatus)
  394. {
  395. goto error;
  396. }
  397. __try
  398. {
  399. RpcStatus = s_KeyrExportCert(
  400. hProxy,
  401. hKeySvc,
  402. pPassword,
  403. pCertStore,
  404. cHashCount,
  405. pHashes,
  406. ulFlags,
  407. ppReserved,
  408. ppPFXBlob);
  409. }
  410. __except ( EXCEPTION_EXECUTE_HANDLER )
  411. {
  412. RpcStatus = _exception_code();
  413. }
  414. error:
  415. if(hProxy)
  416. {
  417. RpcBindingFree(&hProxy);
  418. }
  419. RpcRevertToSelf();
  420. return RpcStatus;
  421. }
  422. ULONG s_KeyrImportCert(
  423. /* [in] */ handle_t hRPCBinding,
  424. /* [in] */ KEYSVC_HANDLE hKeySvc,
  425. /* [in] */ PKEYSVC_UNICODE_STRING pPassword,
  426. /* [in] */ KEYSVC_UNICODE_STRING *pCertStore,
  427. /* [in] */ PKEYSVC_BLOB pPFXBlob,
  428. /* [in] */ ULONG ulFlags,
  429. /* [in, out] */ PKEYSVC_BLOB *ppReserved)
  430. {
  431. RPC_BINDING_HANDLE hProxy = NULL;
  432. RPC_STATUS RpcStatus = RPC_S_OK;
  433. RpcStatus = RpcImpersonateClient(hRPCBinding);
  434. if (RPC_S_OK != RpcStatus)
  435. {
  436. return RpcStatus;
  437. }
  438. RpcStatus = BindLocalKeyService(&hProxy);
  439. if(RPC_S_OK != RpcStatus)
  440. {
  441. goto error;
  442. }
  443. __try
  444. {
  445. RpcStatus = s_KeyrImportCert(
  446. hProxy,
  447. hKeySvc,
  448. pPassword,
  449. pCertStore,
  450. pPFXBlob,
  451. ulFlags,
  452. ppReserved);
  453. }
  454. __except ( EXCEPTION_EXECUTE_HANDLER )
  455. {
  456. RpcStatus = _exception_code();
  457. }
  458. error:
  459. if(hProxy)
  460. {
  461. RpcBindingFree(&hProxy);
  462. }
  463. RpcRevertToSelf();
  464. return RpcStatus;
  465. }
  466. ULONG s_KeyrEnumerateAvailableCertTypes(
  467. /* [in] */ handle_t hRPCBinding,
  468. /* [in] */ KEYSVC_HANDLE hKeySvc,
  469. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  470. /* [out][in] */ ULONG *pcCertTypeCount,
  471. /* [in, out][size_is(,*pcCertTypeCount)] */
  472. PKEYSVC_UNICODE_STRING *ppCertTypes)
  473. {
  474. RPC_BINDING_HANDLE hProxy = NULL;
  475. RPC_STATUS RpcStatus = RPC_S_OK;
  476. RpcStatus = RpcImpersonateClient(hRPCBinding);
  477. if (RPC_S_OK != RpcStatus)
  478. {
  479. return RpcStatus;
  480. }
  481. RpcStatus = BindLocalKeyService(&hProxy);
  482. if(RPC_S_OK != RpcStatus)
  483. {
  484. goto error;
  485. }
  486. __try
  487. {
  488. RpcStatus = s_KeyrEnumerateAvailableCertTypes(
  489. hProxy,
  490. hKeySvc,
  491. ppReserved,
  492. pcCertTypeCount,
  493. ppCertTypes);
  494. }
  495. __except ( EXCEPTION_EXECUTE_HANDLER )
  496. {
  497. RpcStatus = _exception_code();
  498. }
  499. error:
  500. if(hProxy)
  501. {
  502. RpcBindingFree(&hProxy);
  503. }
  504. RpcRevertToSelf();
  505. return RpcStatus;
  506. }
  507. ULONG s_KeyrEnumerateCAs(
  508. /* [in] */ handle_t hRPCBinding,
  509. /* [in] */ KEYSVC_HANDLE hKeySvc,
  510. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  511. /* [in] */ ULONG ulFlags,
  512. /* [out][in] */ ULONG *pcCACount,
  513. /* [in, out][size_is(,*pcCACount)] */
  514. PKEYSVC_UNICODE_STRING *ppCAs)
  515. {
  516. RPC_BINDING_HANDLE hProxy = NULL;
  517. RPC_STATUS RpcStatus = RPC_S_OK;
  518. RpcStatus = RpcImpersonateClient(hRPCBinding);
  519. if (RPC_S_OK != RpcStatus)
  520. {
  521. return RpcStatus;
  522. }
  523. RpcStatus = BindLocalKeyService(&hProxy);
  524. if(RPC_S_OK != RpcStatus)
  525. {
  526. goto error;
  527. }
  528. __try
  529. {
  530. RpcStatus = s_KeyrEnumerateCAs(
  531. hProxy,
  532. hKeySvc,
  533. ppReserved,
  534. ulFlags,
  535. pcCACount,
  536. ppCAs);
  537. }
  538. __except ( EXCEPTION_EXECUTE_HANDLER )
  539. {
  540. RpcStatus = _exception_code();
  541. }
  542. error:
  543. if(hProxy)
  544. {
  545. RpcBindingFree(&hProxy);
  546. }
  547. RpcRevertToSelf();
  548. return RpcStatus;
  549. }
  550. DWORD BindLocalKeyService(handle_t *hProxy)
  551. {
  552. WCHAR *pStringBinding = NULL;
  553. *hProxy = NULL;
  554. RPC_STATUS RpcStatus = RPC_S_OK;
  555. RpcStatus = RpcStringBindingComposeW(
  556. NULL,
  557. KEYSVC_LOCAL_PROT_SEQ,
  558. NULL,
  559. KEYSVC_LOCAL_ENDPOINT,
  560. NULL,
  561. &pStringBinding);
  562. if (RPC_S_OK != RpcStatus)
  563. {
  564. goto error;
  565. }
  566. RpcStatus = RpcBindingFromStringBindingW(
  567. pStringBinding,
  568. hProxy);
  569. if (RPC_S_OK != RpcStatus)
  570. {
  571. goto error;
  572. }
  573. RpcStatus = RpcEpResolveBinding(
  574. *hProxy,
  575. IKeySvc_v1_0_c_ifspec);
  576. if (RPC_S_OK != RpcStatus)
  577. {
  578. if(*hProxy)
  579. {
  580. RpcBindingFree(hProxy);
  581. *hProxy = NULL;
  582. }
  583. goto error;
  584. }
  585. error:
  586. if (NULL != pStringBinding)
  587. {
  588. RpcStringFreeW(&pStringBinding);
  589. }
  590. return RpcStatus;
  591. }
  592. ULONG s_KeyrEnroll_V2
  593. (/* [in] */ handle_t hRPCBinding,
  594. /* [in] */ BOOL fKeyService,
  595. /* [in] */ ULONG ulPurpose,
  596. /* [in] */ ULONG ulFlags,
  597. /* [in] */ PKEYSVC_UNICODE_STRING pAcctName,
  598. /* [in] */ PKEYSVC_UNICODE_STRING pCALocation,
  599. /* [in] */ PKEYSVC_UNICODE_STRING pCAName,
  600. /* [in] */ BOOL fNewKey,
  601. /* [in] */ PKEYSVC_CERT_REQUEST_PVK_NEW_V2 pKeyNew,
  602. /* [in] */ PKEYSVC_BLOB __RPC_FAR pCert,
  603. /* [in] */ PKEYSVC_CERT_REQUEST_PVK_NEW_V2 pRenewKey,
  604. /* [in] */ PKEYSVC_UNICODE_STRING pHashAlg,
  605. /* [in] */ PKEYSVC_UNICODE_STRING pDesStore,
  606. /* [in] */ ULONG ulStoreFlags,
  607. /* [in] */ PKEYSVC_CERT_ENROLL_INFO pRequestInfo,
  608. /* [in] */ ULONG ulReservedFlags,
  609. /* [out][in] */ PKEYSVC_BLOB __RPC_FAR *ppReserved,
  610. /* [out][in] */ PKEYSVC_BLOB __RPC_FAR *ppRequest,
  611. /* [out] */ PKEYSVC_BLOB __RPC_FAR *ppPKCS7Blob,
  612. /* [out] */ PKEYSVC_BLOB __RPC_FAR *ppHashBlob,
  613. /* [out] */ ULONG __RPC_FAR *pulStatus)
  614. {
  615. RPC_BINDING_HANDLE hProxy = NULL;
  616. RPC_STATUS RpcStatus = RPC_S_OK;
  617. RpcStatus = RpcImpersonateClient(hRPCBinding);
  618. if (RPC_S_OK != RpcStatus)
  619. {
  620. return RpcStatus;
  621. }
  622. RpcStatus = BindLocalKeyService(&hProxy);
  623. if(RPC_S_OK != RpcStatus)
  624. {
  625. goto error;
  626. }
  627. __try
  628. {
  629. RpcStatus = s_KeyrEnroll_V2(
  630. hProxy,
  631. fKeyService,
  632. ulPurpose,
  633. ulFlags,
  634. pAcctName,
  635. pCALocation,
  636. pCAName,
  637. fNewKey,
  638. pKeyNew,
  639. pCert,
  640. pRenewKey,
  641. pHashAlg,
  642. pDesStore,
  643. ulStoreFlags,
  644. pRequestInfo,
  645. ulReservedFlags,
  646. ppReserved,
  647. ppRequest,
  648. ppPKCS7Blob,
  649. ppHashBlob,
  650. pulStatus);
  651. }
  652. __except ( EXCEPTION_EXECUTE_HANDLER )
  653. {
  654. RpcStatus = _exception_code();
  655. }
  656. error:
  657. if(hProxy)
  658. {
  659. RpcBindingFree(&hProxy);
  660. }
  661. RpcRevertToSelf();
  662. return RpcStatus;
  663. }
  664. ULONG s_KeyrQueryRequestStatus
  665. (/* [in] */ handle_t hRPCBinding,
  666. /* [in] */ unsigned __int64 u64Request,
  667. /* [out, ref] */ KEYSVC_QUERY_CERT_REQUEST_INFO *pQueryInfo)
  668. {
  669. RPC_BINDING_HANDLE hProxy = NULL;
  670. RPC_STATUS RpcStatus = RPC_S_OK;
  671. RpcStatus = RpcImpersonateClient(hRPCBinding);
  672. if (RPC_S_OK != RpcStatus)
  673. {
  674. return RpcStatus;
  675. }
  676. RpcStatus = BindLocalKeyService(&hProxy);
  677. if(RPC_S_OK != RpcStatus)
  678. {
  679. goto error;
  680. }
  681. __try
  682. {
  683. RpcStatus = s_KeyrQueryRequestStatus(
  684. hProxy,
  685. u64Request,
  686. pQueryInfo);
  687. }
  688. __except ( EXCEPTION_EXECUTE_HANDLER )
  689. {
  690. RpcStatus = _exception_code();
  691. }
  692. error:
  693. if(hProxy)
  694. {
  695. RpcBindingFree(&hProxy);
  696. }
  697. RpcRevertToSelf();
  698. return RpcStatus;
  699. }
  700. ULONG s_RKeyrPFXInstall
  701. (/* [in] */ handle_t hRPCBinding,
  702. /* [in] */ PKEYSVC_BLOB pPFX,
  703. /* [in] */ PKEYSVC_UNICODE_STRING pPassword,
  704. /* [in] */ ULONG ulFlags)
  705. {
  706. RPC_BINDING_HANDLE hProxy = NULL;
  707. RPC_STATUS RpcStatus = RPC_S_OK;
  708. RpcStatus = RpcImpersonateClient(hRPCBinding);
  709. if (RPC_S_OK != RpcStatus)
  710. {
  711. return RpcStatus;
  712. }
  713. RpcStatus = BindLocalKeyService(&hProxy);
  714. if(RPC_S_OK != RpcStatus)
  715. {
  716. goto error;
  717. }
  718. __try
  719. {
  720. RpcStatus = s_RKeyrPFXInstall(
  721. hProxy,
  722. pPFX,
  723. pPassword,
  724. ulFlags);
  725. }
  726. __except ( EXCEPTION_EXECUTE_HANDLER )
  727. {
  728. RpcStatus = _exception_code();
  729. }
  730. error:
  731. if(hProxy)
  732. {
  733. RpcBindingFree(&hProxy);
  734. }
  735. RpcRevertToSelf();
  736. return RpcStatus;
  737. }
  738. ULONG s_RKeyrOpenKeyService(
  739. /* [in] */ handle_t hRPCBinding,
  740. /* [in] */ KEYSVC_TYPE OwnerType,
  741. /* [in] */ PKEYSVC_UNICODE_STRING pOwnerName,
  742. /* [in] */ ULONG ulDesiredAccess,
  743. /* [in] */ PKEYSVC_BLOB pAuthentication,
  744. /* [in, out] */ PKEYSVC_BLOB *ppReserved,
  745. /* [out] */ KEYSVC_HANDLE *phKeySvc)
  746. {
  747. return s_KeyrOpenKeyService
  748. (hRPCBinding,
  749. OwnerType,
  750. pOwnerName,
  751. ulDesiredAccess,
  752. pAuthentication,
  753. ppReserved,
  754. phKeySvc);
  755. }
  756. ULONG s_RKeyrCloseKeyService(
  757. /* [in] */ handle_t hRPCBinding,
  758. /* [in] */ KEYSVC_HANDLE hKeySvc,
  759. /* [in, out] */ PKEYSVC_BLOB *ppReserved)
  760. {
  761. return s_KeyrCloseKeyService
  762. (hRPCBinding,
  763. hKeySvc,
  764. ppReserved);
  765. }