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.

840 lines
23 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1996 - 1999
  6. //
  7. // File: cryptfix.cpp
  8. //
  9. // Contents: Crypto API, version 2. fix for certificate server
  10. //
  11. // CryptDecodeObject/CryptEncodeObject structures added
  12. // after SP3.
  13. //
  14. // Functions: CryptFixDllMain
  15. //
  16. // History: 13-Aug-96 kevinr created
  17. //
  18. //--------------------------------------------------------------------------
  19. #include "pch.cpp"
  20. #pragma hdrstop
  21. #include "crypttls.h"
  22. #include "unicode.h"
  23. extern "C" {
  24. #include "..\..\pki\certstor\ossx509.h"
  25. }
  26. #define __dwFILE__ __dwFILE_OCMSETUP_CRYPTFIX_CPP__
  27. //#include <dbgdef.h>
  28. // The CRYPTIE_STATIC prefixed variables and functions are defined in
  29. // ..\certstor\wincert.obj
  30. #define CRYPTIE_STATIC extern
  31. CRYPTIE_STATIC HCRYPTOSSGLOBAL hX509OssGlobal;
  32. CRYPTIE_STATIC HCRYPTOIDFUNCSET hX509EncodeFuncSet;
  33. CRYPTIE_STATIC HCRYPTOIDFUNCSET hX509DecodeFuncSet;
  34. #if DBG
  35. extern BOOL WINAPI DebugDllMain(HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  36. #endif
  37. extern BOOL WINAPI UnicodeDllMain(HMODULE hInstDLL, DWORD fdwReason, LPVOID lpvReserved);
  38. CRYPTIE_STATIC BOOL WINAPI OssX509KeygenRequestInfoEncode(
  39. IN DWORD dwCertEncodingType,
  40. IN LPCSTR lpszStructType,
  41. IN PCERT_KEYGEN_REQUEST_INFO pInfo,
  42. OUT BYTE *pbEncoded,
  43. IN OUT DWORD *pcbEncoded
  44. );
  45. CRYPTIE_STATIC BOOL WINAPI OssX509KeygenRequestInfoDecode(
  46. IN DWORD dwCertEncodingType,
  47. IN LPCSTR lpszStructType,
  48. IN const BYTE *pbEncoded,
  49. IN DWORD cbEncoded,
  50. IN DWORD dwFlags,
  51. OUT PCERT_KEYGEN_REQUEST_INFO pInfo,
  52. IN OUT DWORD *pcbInfo
  53. );
  54. CRYPTIE_STATIC BOOL WINAPI OssX509IntegerEncode(
  55. IN DWORD dwCertEncodingType,
  56. IN LPCSTR lpszStructType,
  57. IN int *pInfo,
  58. OUT BYTE *pbEncoded,
  59. IN OUT DWORD *pcbEncoded
  60. );
  61. CRYPTIE_STATIC BOOL WINAPI OssX509IntegerDecode(
  62. IN DWORD dwCertEncodingType,
  63. IN LPCSTR lpszStructType,
  64. IN const BYTE *pbEncoded,
  65. IN DWORD cbEncoded,
  66. IN DWORD dwFlags,
  67. OUT int *pInfo,
  68. IN OUT DWORD *pcbInfo
  69. );
  70. CRYPTIE_STATIC BOOL WINAPI OssX509ChoiceOfTimeEncode(
  71. IN DWORD dwCertEncodingType,
  72. IN LPCSTR lpszStructType,
  73. IN LPFILETIME pInfo,
  74. OUT BYTE *pbEncoded,
  75. IN OUT DWORD *pcbEncoded
  76. );
  77. CRYPTIE_STATIC BOOL WINAPI OssX509ChoiceOfTimeDecode(
  78. IN DWORD dwCertEncodingType,
  79. IN LPCSTR lpszStructType,
  80. IN const BYTE *pbEncoded,
  81. IN DWORD cbEncoded,
  82. IN DWORD dwFlags,
  83. OUT LPFILETIME pInfo,
  84. IN OUT DWORD *pcbInfo
  85. );
  86. CRYPTIE_STATIC BOOL WINAPI OssX509SequenceOfAnyEncode(
  87. IN DWORD dwCertEncodingType,
  88. IN LPCSTR lpszStructType,
  89. IN PCRYPT_SEQUENCE_OF_ANY pInfo,
  90. OUT BYTE *pbEncoded,
  91. IN OUT DWORD *pcbEncoded
  92. );
  93. CRYPTIE_STATIC BOOL WINAPI OssX509SequenceOfAnyDecode(
  94. IN DWORD dwCertEncodingType,
  95. IN LPCSTR lpszStructType,
  96. IN const BYTE *pbEncoded,
  97. IN DWORD cbEncoded,
  98. IN DWORD dwFlags,
  99. OUT PCRYPT_SEQUENCE_OF_ANY pInfo,
  100. IN OUT DWORD *pcbInfo
  101. );
  102. CRYPTIE_STATIC BOOL WINAPI OssX509CrlDistPointsEncode(
  103. IN DWORD dwCertEncodingType,
  104. IN LPCSTR lpszStructType,
  105. IN PCRL_DIST_POINTS_INFO pInfo,
  106. OUT BYTE *pbEncoded,
  107. IN OUT DWORD *pcbEncoded
  108. );
  109. CRYPTIE_STATIC BOOL WINAPI OssX509CrlDistPointsDecode(
  110. IN DWORD dwCertEncodingType,
  111. IN LPCSTR lpszStructType,
  112. IN const BYTE *pbEncoded,
  113. IN DWORD cbEncoded,
  114. IN DWORD dwFlags,
  115. OUT PCRL_DIST_POINTS_INFO pInfo,
  116. IN OUT DWORD *pcbInfo
  117. );
  118. CRYPTIE_STATIC BOOL WINAPI OssX509AuthorityKeyId2Encode(
  119. IN DWORD dwCertEncodingType,
  120. IN LPCSTR lpszStructType,
  121. IN PCERT_AUTHORITY_KEY_ID2_INFO pInfo,
  122. OUT BYTE *pbEncoded,
  123. IN OUT DWORD *pcbEncoded
  124. );
  125. CRYPTIE_STATIC BOOL WINAPI OssX509AuthorityKeyId2Decode(
  126. IN DWORD dwCertEncodingType,
  127. IN LPCSTR lpszStructType,
  128. IN const BYTE *pbEncoded,
  129. IN DWORD cbEncoded,
  130. IN DWORD dwFlags,
  131. OUT PCERT_AUTHORITY_KEY_ID2_INFO pInfo,
  132. IN OUT DWORD *pcbInfo
  133. );
  134. CRYPTIE_STATIC BOOL WINAPI OssX509OctetStringEncode(
  135. IN DWORD dwCertEncodingType,
  136. IN LPCSTR lpszStructType,
  137. IN PCRYPT_DATA_BLOB pInfo,
  138. OUT BYTE *pbEncoded,
  139. IN OUT DWORD *pcbEncoded
  140. );
  141. CRYPTIE_STATIC BOOL WINAPI OssX509OctetStringDecode(
  142. IN DWORD dwCertEncodingType,
  143. IN LPCSTR lpszStructType,
  144. IN const BYTE *pbEncoded,
  145. IN DWORD cbEncoded,
  146. IN DWORD dwFlags,
  147. OUT PCRYPT_DATA_BLOB pInfo,
  148. IN OUT DWORD *pcbInfo
  149. );
  150. CRYPTIE_STATIC BOOL WINAPI OssX509BitsEncode(
  151. IN DWORD dwCertEncodingType,
  152. IN LPCSTR lpszStructType,
  153. IN PCRYPT_BIT_BLOB pInfo,
  154. OUT BYTE *pbEncoded,
  155. IN OUT DWORD *pcbEncoded
  156. );
  157. CRYPTIE_STATIC BOOL WINAPI OssX509BitsDecode(
  158. IN DWORD dwCertEncodingType,
  159. IN LPCSTR lpszStructType,
  160. IN const BYTE *pbEncoded,
  161. IN DWORD cbEncoded,
  162. IN DWORD dwFlags,
  163. OUT PCRYPT_BIT_BLOB pInfo,
  164. IN OUT DWORD *pcbInfo
  165. );
  166. CRYPTIE_STATIC BOOL WINAPI OssX509AuthorityInfoAccessEncode(
  167. IN DWORD dwCertEncodingType,
  168. IN LPCSTR lpszStructType,
  169. IN PCERT_AUTHORITY_INFO_ACCESS pInfo,
  170. OUT BYTE *pbEncoded,
  171. IN OUT DWORD *pcbEncoded
  172. );
  173. CRYPTIE_STATIC BOOL WINAPI OssX509AuthorityInfoAccessDecode(
  174. IN DWORD dwCertEncodingType,
  175. IN LPCSTR lpszStructType,
  176. IN const BYTE *pbEncoded,
  177. IN DWORD cbEncoded,
  178. IN DWORD dwFlags,
  179. OUT PCERT_AUTHORITY_INFO_ACCESS pInfo,
  180. IN OUT DWORD *pcbInfo
  181. );
  182. CRYPTIE_STATIC BOOL WINAPI OssX509CtlUsageEncode(
  183. IN DWORD dwCertEncodingType,
  184. IN LPCSTR lpszStructType,
  185. IN PCTL_USAGE pInfo,
  186. OUT BYTE *pbEncoded,
  187. IN OUT DWORD *pcbEncoded
  188. );
  189. CRYPTIE_STATIC BOOL WINAPI OssX509CtlUsageDecode(
  190. IN DWORD dwCertEncodingType,
  191. IN LPCSTR lpszStructType,
  192. IN const BYTE *pbEncoded,
  193. IN DWORD cbEncoded,
  194. IN DWORD dwFlags,
  195. OUT PCTL_USAGE pInfo,
  196. IN OUT DWORD *pcbInfo
  197. );
  198. //+-------------------------------------------------------------------------
  199. // Encode / Decode the "UNICODE" Name Value
  200. //
  201. // from certstr.cpp
  202. //--------------------------------------------------------------------------
  203. extern BOOL WINAPI UnicodeNameValueEncode(
  204. IN DWORD dwCertEncodingType,
  205. IN LPCSTR lpszStructType,
  206. IN PCERT_NAME_VALUE pInfo,
  207. OUT BYTE *pbEncoded,
  208. IN OUT DWORD *pcbEncoded
  209. );
  210. extern BOOL WINAPI UnicodeNameValueDecode(
  211. IN DWORD dwCertEncodingType,
  212. IN LPCSTR lpszStructType,
  213. IN const BYTE *pbEncoded,
  214. IN DWORD cbEncoded,
  215. IN DWORD dwFlags,
  216. OUT PCERT_NAME_VALUE pInfo,
  217. IN OUT DWORD *pcbInfo
  218. );
  219. BOOL WINAPI CertDllKeygenRequestInfoEncode(
  220. IN DWORD dwCertEncodingType,
  221. IN LPCSTR lpszStructType,
  222. IN PCERT_KEYGEN_REQUEST_INFO pInfo,
  223. OUT BYTE *pbEncoded,
  224. IN OUT DWORD *pcbEncoded
  225. )
  226. {
  227. return OssX509KeygenRequestInfoEncode(
  228. dwCertEncodingType,
  229. lpszStructType,
  230. pInfo,
  231. pbEncoded,
  232. pcbEncoded
  233. );
  234. }
  235. BOOL WINAPI CertDllKeygenRequestInfoDecode(
  236. IN DWORD dwCertEncodingType,
  237. IN LPCSTR lpszStructType,
  238. IN const BYTE *pbEncoded,
  239. IN DWORD cbEncoded,
  240. IN DWORD dwFlags,
  241. OUT PCERT_KEYGEN_REQUEST_INFO pInfo,
  242. IN OUT DWORD *pcbInfo
  243. )
  244. {
  245. return OssX509KeygenRequestInfoDecode(
  246. dwCertEncodingType,
  247. lpszStructType,
  248. pbEncoded,
  249. cbEncoded,
  250. dwFlags,
  251. pInfo,
  252. pcbInfo
  253. );
  254. }
  255. BOOL WINAPI CertDllIntegerEncode(
  256. IN DWORD dwCertEncodingType,
  257. IN LPCSTR lpszStructType,
  258. IN int *pInfo,
  259. OUT BYTE *pbEncoded,
  260. IN OUT DWORD *pcbEncoded
  261. )
  262. {
  263. return OssX509IntegerEncode(
  264. dwCertEncodingType,
  265. lpszStructType,
  266. pInfo,
  267. pbEncoded,
  268. pcbEncoded
  269. );
  270. }
  271. BOOL WINAPI CertDllIntegerDecode(
  272. IN DWORD dwCertEncodingType,
  273. IN LPCSTR lpszStructType,
  274. IN const BYTE *pbEncoded,
  275. IN DWORD cbEncoded,
  276. IN DWORD dwFlags,
  277. OUT int *pInfo,
  278. IN OUT DWORD *pcbInfo
  279. )
  280. {
  281. return OssX509IntegerDecode(
  282. dwCertEncodingType,
  283. lpszStructType,
  284. pbEncoded,
  285. cbEncoded,
  286. dwFlags,
  287. pInfo,
  288. pcbInfo
  289. );
  290. }
  291. BOOL WINAPI CertDllChoiceOfTimeEncode(
  292. IN DWORD dwCertEncodingType,
  293. IN LPCSTR lpszStructType,
  294. IN LPFILETIME pInfo,
  295. OUT BYTE *pbEncoded,
  296. IN OUT DWORD *pcbEncoded
  297. )
  298. {
  299. return OssX509ChoiceOfTimeEncode(
  300. dwCertEncodingType,
  301. lpszStructType,
  302. pInfo,
  303. pbEncoded,
  304. pcbEncoded
  305. );
  306. }
  307. BOOL WINAPI CertDllChoiceOfTimeDecode(
  308. IN DWORD dwCertEncodingType,
  309. IN LPCSTR lpszStructType,
  310. IN const BYTE *pbEncoded,
  311. IN DWORD cbEncoded,
  312. IN DWORD dwFlags,
  313. OUT LPFILETIME pInfo,
  314. IN OUT DWORD *pcbInfo
  315. )
  316. {
  317. return OssX509ChoiceOfTimeDecode(
  318. dwCertEncodingType,
  319. lpszStructType,
  320. pbEncoded,
  321. cbEncoded,
  322. dwFlags,
  323. pInfo,
  324. pcbInfo
  325. );
  326. }
  327. BOOL WINAPI CertDllSequenceOfAnyEncode(
  328. IN DWORD dwCertEncodingType,
  329. IN LPCSTR lpszStructType,
  330. IN PCRYPT_SEQUENCE_OF_ANY pInfo,
  331. OUT BYTE *pbEncoded,
  332. IN OUT DWORD *pcbEncoded
  333. )
  334. {
  335. return OssX509SequenceOfAnyEncode(
  336. dwCertEncodingType,
  337. lpszStructType,
  338. pInfo,
  339. pbEncoded,
  340. pcbEncoded
  341. );
  342. }
  343. BOOL WINAPI CertDllSequenceOfAnyDecode(
  344. IN DWORD dwCertEncodingType,
  345. IN LPCSTR lpszStructType,
  346. IN const BYTE *pbEncoded,
  347. IN DWORD cbEncoded,
  348. IN DWORD dwFlags,
  349. OUT PCRYPT_SEQUENCE_OF_ANY pInfo,
  350. IN OUT DWORD *pcbInfo
  351. )
  352. {
  353. return OssX509SequenceOfAnyDecode(
  354. dwCertEncodingType,
  355. lpszStructType,
  356. pbEncoded,
  357. cbEncoded,
  358. dwFlags,
  359. pInfo,
  360. pcbInfo
  361. );
  362. }
  363. BOOL WINAPI CertDllCrlDistPointsEncode(
  364. IN DWORD dwCertEncodingType,
  365. IN LPCSTR lpszStructType,
  366. IN PCRL_DIST_POINTS_INFO pInfo,
  367. OUT BYTE *pbEncoded,
  368. IN OUT DWORD *pcbEncoded
  369. )
  370. {
  371. return OssX509CrlDistPointsEncode(
  372. dwCertEncodingType,
  373. lpszStructType,
  374. pInfo,
  375. pbEncoded,
  376. pcbEncoded
  377. );
  378. }
  379. BOOL WINAPI CertDllCrlDistPointsDecode(
  380. IN DWORD dwCertEncodingType,
  381. IN LPCSTR lpszStructType,
  382. IN const BYTE *pbEncoded,
  383. IN DWORD cbEncoded,
  384. IN DWORD dwFlags,
  385. OUT PCRL_DIST_POINTS_INFO pInfo,
  386. IN OUT DWORD *pcbInfo
  387. )
  388. {
  389. return OssX509CrlDistPointsDecode(
  390. dwCertEncodingType,
  391. lpszStructType,
  392. pbEncoded,
  393. cbEncoded,
  394. dwFlags,
  395. pInfo,
  396. pcbInfo
  397. );
  398. }
  399. BOOL WINAPI CertDllUnicodeNameValueEncode(
  400. IN DWORD dwCertEncodingType,
  401. IN LPCSTR lpszStructType,
  402. IN PCERT_NAME_VALUE pInfo,
  403. OUT BYTE *pbEncoded,
  404. IN OUT DWORD *pcbEncoded
  405. )
  406. {
  407. return UnicodeNameValueEncode(
  408. dwCertEncodingType,
  409. lpszStructType,
  410. pInfo,
  411. pbEncoded,
  412. pcbEncoded
  413. );
  414. }
  415. BOOL WINAPI CertDllUnicodeNameValueDecode(
  416. IN DWORD dwCertEncodingType,
  417. IN LPCSTR lpszStructType,
  418. IN const BYTE *pbEncoded,
  419. IN DWORD cbEncoded,
  420. IN DWORD dwFlags,
  421. OUT PCERT_NAME_VALUE pInfo,
  422. IN OUT DWORD *pcbInfo
  423. )
  424. {
  425. return UnicodeNameValueDecode(
  426. dwCertEncodingType,
  427. lpszStructType,
  428. pbEncoded,
  429. cbEncoded,
  430. dwFlags,
  431. pInfo,
  432. pcbInfo
  433. );
  434. }
  435. BOOL WINAPI CertDllAuthorityKeyId2Encode(
  436. IN DWORD dwCertEncodingType,
  437. IN LPCSTR lpszStructType,
  438. IN PCERT_AUTHORITY_KEY_ID2_INFO pInfo,
  439. OUT BYTE *pbEncoded,
  440. IN OUT DWORD *pcbEncoded
  441. )
  442. {
  443. return OssX509AuthorityKeyId2Encode(
  444. dwCertEncodingType,
  445. lpszStructType,
  446. pInfo,
  447. pbEncoded,
  448. pcbEncoded
  449. );
  450. }
  451. BOOL WINAPI CertDllAuthorityKeyId2Decode(
  452. IN DWORD dwCertEncodingType,
  453. IN LPCSTR lpszStructType,
  454. IN const BYTE *pbEncoded,
  455. IN DWORD cbEncoded,
  456. IN DWORD dwFlags,
  457. OUT PCERT_AUTHORITY_KEY_ID2_INFO pInfo,
  458. IN OUT DWORD *pcbInfo
  459. )
  460. {
  461. return OssX509AuthorityKeyId2Decode(
  462. dwCertEncodingType,
  463. lpszStructType,
  464. pbEncoded,
  465. cbEncoded,
  466. dwFlags,
  467. pInfo,
  468. pcbInfo
  469. );
  470. }
  471. BOOL WINAPI CertDllOctetStringEncode(
  472. IN DWORD dwCertEncodingType,
  473. IN LPCSTR lpszStructType,
  474. IN PCRYPT_DATA_BLOB pInfo,
  475. OUT BYTE *pbEncoded,
  476. IN OUT DWORD *pcbEncoded
  477. )
  478. {
  479. return OssX509OctetStringEncode(
  480. dwCertEncodingType,
  481. lpszStructType,
  482. pInfo,
  483. pbEncoded,
  484. pcbEncoded
  485. );
  486. }
  487. BOOL WINAPI CertDllOctetStringDecode(
  488. IN DWORD dwCertEncodingType,
  489. IN LPCSTR lpszStructType,
  490. IN const BYTE *pbEncoded,
  491. IN DWORD cbEncoded,
  492. IN DWORD dwFlags,
  493. OUT PCRYPT_DATA_BLOB pInfo,
  494. IN OUT DWORD *pcbInfo
  495. )
  496. {
  497. return OssX509OctetStringDecode(
  498. dwCertEncodingType,
  499. lpszStructType,
  500. pbEncoded,
  501. cbEncoded,
  502. dwFlags,
  503. pInfo,
  504. pcbInfo
  505. );
  506. }
  507. BOOL WINAPI CertDllBitsEncode(
  508. IN DWORD dwCertEncodingType,
  509. IN LPCSTR lpszStructType,
  510. IN PCRYPT_BIT_BLOB pInfo,
  511. OUT BYTE *pbEncoded,
  512. IN OUT DWORD *pcbEncoded
  513. )
  514. {
  515. return OssX509BitsEncode(
  516. dwCertEncodingType,
  517. lpszStructType,
  518. pInfo,
  519. pbEncoded,
  520. pcbEncoded
  521. );
  522. }
  523. BOOL WINAPI CertDllBitsDecode(
  524. IN DWORD dwCertEncodingType,
  525. IN LPCSTR lpszStructType,
  526. IN const BYTE *pbEncoded,
  527. IN DWORD cbEncoded,
  528. IN DWORD dwFlags,
  529. OUT PCRYPT_BIT_BLOB pInfo,
  530. IN OUT DWORD *pcbInfo
  531. )
  532. {
  533. return OssX509BitsDecode(
  534. dwCertEncodingType,
  535. lpszStructType,
  536. pbEncoded,
  537. cbEncoded,
  538. dwFlags,
  539. pInfo,
  540. pcbInfo
  541. );
  542. }
  543. BOOL WINAPI CertDllAuthorityInfoAccessEncode(
  544. IN DWORD dwCertEncodingType,
  545. IN LPCSTR lpszStructType,
  546. IN PCERT_AUTHORITY_INFO_ACCESS pInfo,
  547. OUT BYTE *pbEncoded,
  548. IN OUT DWORD *pcbEncoded
  549. )
  550. {
  551. return OssX509AuthorityInfoAccessEncode(
  552. dwCertEncodingType,
  553. lpszStructType,
  554. pInfo,
  555. pbEncoded,
  556. pcbEncoded
  557. );
  558. }
  559. BOOL WINAPI CertDllAuthorityInfoAccessDecode(
  560. IN DWORD dwCertEncodingType,
  561. IN LPCSTR lpszStructType,
  562. IN const BYTE *pbEncoded,
  563. IN DWORD cbEncoded,
  564. IN DWORD dwFlags,
  565. OUT PCERT_AUTHORITY_INFO_ACCESS pInfo,
  566. IN OUT DWORD *pcbInfo
  567. )
  568. {
  569. return OssX509AuthorityInfoAccessDecode(
  570. dwCertEncodingType,
  571. lpszStructType,
  572. pbEncoded,
  573. cbEncoded,
  574. dwFlags,
  575. pInfo,
  576. pcbInfo
  577. );
  578. }
  579. BOOL WINAPI CertDllCtlUsageEncode(
  580. IN DWORD dwCertEncodingType,
  581. IN LPCSTR lpszStructType,
  582. IN PCTL_USAGE pInfo,
  583. OUT BYTE *pbEncoded,
  584. IN OUT DWORD *pcbEncoded
  585. )
  586. {
  587. return OssX509CtlUsageEncode(
  588. dwCertEncodingType,
  589. lpszStructType,
  590. pInfo,
  591. pbEncoded,
  592. pcbEncoded
  593. );
  594. }
  595. BOOL WINAPI CertDllCtlUsageDecode(
  596. IN DWORD dwCertEncodingType,
  597. IN LPCSTR lpszStructType,
  598. IN const BYTE *pbEncoded,
  599. IN DWORD cbEncoded,
  600. IN DWORD dwFlags,
  601. OUT PCTL_USAGE pInfo,
  602. IN OUT DWORD *pcbInfo
  603. )
  604. {
  605. return OssX509CtlUsageDecode(
  606. dwCertEncodingType,
  607. lpszStructType,
  608. pbEncoded,
  609. cbEncoded,
  610. dwFlags,
  611. pInfo,
  612. pcbInfo
  613. );
  614. }
  615. typedef struct _OID_REG_ENTRY {
  616. LPCSTR pszOID;
  617. LPCSTR pszOverrideFuncName;
  618. } OID_REG_ENTRY, *POID_REG_ENTRY;
  619. static const OID_REG_ENTRY RegEncodeTable[] = {
  620. X509_KEYGEN_REQUEST_TO_BE_SIGNED, "CertDllKeygenRequestInfoEncode",
  621. X509_UNICODE_NAME_VALUE, "CertDllUnicodeNameValueEncode",
  622. X509_INTEGER, "CertDllIntegerEncode",
  623. X509_CHOICE_OF_TIME, "CertDllChoiceOfTimeEncode",
  624. X509_SEQUENCE_OF_ANY, "CertDllSequenceOfAnyEncode",
  625. X509_CRL_DIST_POINTS, "CertDllCrlDistPointsEncode",
  626. X509_AUTHORITY_KEY_ID2, "CertDllAuthorityKeyId2Encode",
  627. szOID_CRL_DIST_POINTS, "CertDllCrlDistPointsEncode",
  628. szOID_AUTHORITY_KEY_IDENTIFIER2, "CertDllAuthorityKeyId2Encode",
  629. X509_OCTET_STRING, "CertDllOctetStringEncode",
  630. X509_BITS, "CertDllBitsEncode",
  631. X509_AUTHORITY_INFO_ACCESS, "CertDllAuthorityInfoAccessEncode",
  632. szOID_AUTHORITY_INFO_ACCESS, "CertDllAuthorityInfoAccessEncode",
  633. X509_ENHANCED_KEY_USAGE, "CertDllCtlUsageEncode",
  634. szOID_ENHANCED_KEY_USAGE, "CertDllCtlUsageEncode",
  635. };
  636. #define REG_ENCODE_COUNT (sizeof(RegEncodeTable) / sizeof(RegEncodeTable[0]))
  637. static const OID_REG_ENTRY RegDecodeTable[] = {
  638. X509_KEYGEN_REQUEST_TO_BE_SIGNED, "CertDllKeygenRequestInfoDecode",
  639. X509_UNICODE_NAME_VALUE, "CertDllUnicodeNameValueDecode",
  640. X509_INTEGER, "CertDllIntegerDecode",
  641. X509_CHOICE_OF_TIME, "CertDllChoiceOfTimeDecode",
  642. X509_SEQUENCE_OF_ANY, "CertDllSequenceOfAnyDecode",
  643. X509_CRL_DIST_POINTS, "CertDllCrlDistPointsDecode",
  644. X509_AUTHORITY_KEY_ID2, "CertDllAuthorityKeyId2Decode",
  645. szOID_CRL_DIST_POINTS, "CertDllCrlDistPointsDecode",
  646. szOID_AUTHORITY_KEY_IDENTIFIER2, "CertDllAuthorityKeyId2Decode",
  647. X509_OCTET_STRING, "CertDllOctetStringDecode",
  648. X509_BITS, "CertDllBitsDecode",
  649. X509_AUTHORITY_INFO_ACCESS, "CertDllAuthorityInfoAccessDecode",
  650. szOID_AUTHORITY_INFO_ACCESS, "CertDllAuthorityInfoAccessDecode",
  651. X509_ENHANCED_KEY_USAGE, "CertDllCtlUsageDecode",
  652. szOID_ENHANCED_KEY_USAGE, "CertDllCtlUsageDecode",
  653. };
  654. #define REG_DECODE_COUNT (sizeof(RegDecodeTable) / sizeof(RegDecodeTable[0]))
  655. static const CRYPT_OID_FUNC_ENTRY X509EncodeFuncTable[] = {
  656. X509_KEYGEN_REQUEST_TO_BE_SIGNED, CertDllKeygenRequestInfoEncode,
  657. X509_UNICODE_NAME_VALUE, CertDllUnicodeNameValueEncode,
  658. X509_INTEGER, CertDllIntegerEncode,
  659. X509_CHOICE_OF_TIME, CertDllChoiceOfTimeEncode,
  660. X509_SEQUENCE_OF_ANY, CertDllSequenceOfAnyEncode,
  661. X509_CRL_DIST_POINTS, CertDllCrlDistPointsEncode,
  662. X509_AUTHORITY_KEY_ID2, CertDllAuthorityKeyId2Encode,
  663. szOID_CRL_DIST_POINTS, CertDllCrlDistPointsEncode,
  664. szOID_AUTHORITY_KEY_IDENTIFIER2, CertDllAuthorityKeyId2Encode,
  665. X509_OCTET_STRING, CertDllOctetStringEncode,
  666. X509_BITS, CertDllBitsEncode,
  667. X509_AUTHORITY_INFO_ACCESS, CertDllAuthorityInfoAccessEncode,
  668. szOID_AUTHORITY_INFO_ACCESS, CertDllAuthorityInfoAccessEncode,
  669. X509_ENHANCED_KEY_USAGE, CertDllCtlUsageEncode,
  670. szOID_ENHANCED_KEY_USAGE, CertDllCtlUsageEncode,
  671. };
  672. #define X509_ENCODE_FUNC_COUNT (sizeof(X509EncodeFuncTable) / \
  673. sizeof(X509EncodeFuncTable[0]))
  674. static const CRYPT_OID_FUNC_ENTRY X509DecodeFuncTable[] = {
  675. X509_KEYGEN_REQUEST_TO_BE_SIGNED, CertDllKeygenRequestInfoDecode,
  676. X509_UNICODE_NAME_VALUE, CertDllUnicodeNameValueDecode,
  677. X509_INTEGER, CertDllIntegerDecode,
  678. X509_CHOICE_OF_TIME, CertDllChoiceOfTimeDecode,
  679. X509_SEQUENCE_OF_ANY, CertDllSequenceOfAnyDecode,
  680. X509_CRL_DIST_POINTS, CertDllCrlDistPointsDecode,
  681. X509_AUTHORITY_KEY_ID2, CertDllAuthorityKeyId2Decode,
  682. szOID_CRL_DIST_POINTS, CertDllCrlDistPointsDecode,
  683. szOID_AUTHORITY_KEY_IDENTIFIER2, CertDllAuthorityKeyId2Decode,
  684. X509_OCTET_STRING, CertDllOctetStringDecode,
  685. X509_BITS, CertDllBitsDecode,
  686. X509_AUTHORITY_INFO_ACCESS, CertDllAuthorityInfoAccessDecode,
  687. szOID_AUTHORITY_INFO_ACCESS, CertDllAuthorityInfoAccessDecode,
  688. X509_ENHANCED_KEY_USAGE, CertDllCtlUsageDecode,
  689. szOID_ENHANCED_KEY_USAGE, CertDllCtlUsageDecode,
  690. };
  691. #define X509_DECODE_FUNC_COUNT (sizeof(X509DecodeFuncTable) / \
  692. sizeof(X509DecodeFuncTable[0]))
  693. //+-------------------------------------------------------------------------
  694. // Dll initialization
  695. //--------------------------------------------------------------------------
  696. BOOL WINAPI CryptFixDllMain(HMODULE hInst, ULONG ulReason, LPVOID lpReserved)
  697. {
  698. BOOL fRet;
  699. # if DBG
  700. #if 0
  701. //
  702. // Due to an apparent bug in the Win95 loader, the CRT gets unloaded
  703. // too early in some circumstances. In particular, it can get unloaded
  704. // before this routine executes at process detach time. This can cause
  705. // faults when executing this routine, and also when executing the rest
  706. // of CRYPT32:CRT_INIT, after this initroutine returns. Ergo, we do an
  707. // extra load of the CRT, to be sure it stays around long enough.
  708. //
  709. if ((ulReason == DLL_PROCESS_ATTACH) && (!(FIsWinNT())))
  710. {
  711. LoadLibrary( L"MSVCRTD.DLL");
  712. }
  713. #endif
  714. DebugDllMain(hInst, ulReason, lpReserved);
  715. # endif // DBG
  716. UnicodeDllMain(hInst, ulReason, lpReserved);
  717. switch (ulReason)
  718. {
  719. case DLL_PROCESS_ATTACH:
  720. if (0 == (hX509OssGlobal = I_CryptInstallOssGlobal(ossx509, 0, NULL)))
  721. {
  722. //goto CryptInstallOssGlobalError;
  723. goto ErrorReturn;
  724. }
  725. if (NULL == (hX509EncodeFuncSet = CryptInitOIDFunctionSet(
  726. CRYPT_OID_ENCODE_OBJECT_FUNC, 0)))
  727. {
  728. //goto CryptInitOIDFunctionSetError;
  729. goto ErrorReturn;
  730. }
  731. if (NULL == (hX509DecodeFuncSet = CryptInitOIDFunctionSet(
  732. CRYPT_OID_DECODE_OBJECT_FUNC, 0)))
  733. {
  734. //goto CryptInitOIDFunctionSetError;
  735. goto ErrorReturn;
  736. }
  737. if (!(CryptInstallOIDFunctionAddress( hInst,
  738. X509_ASN_ENCODING,
  739. CRYPT_OID_ENCODE_OBJECT_FUNC,
  740. X509_ENCODE_FUNC_COUNT,
  741. X509EncodeFuncTable,
  742. 0)))
  743. {
  744. //goto CryptInstallOIDFunctionAddressError;
  745. goto ErrorReturn;
  746. }
  747. if (!(CryptInstallOIDFunctionAddress( hInst,
  748. X509_ASN_ENCODING,
  749. CRYPT_OID_DECODE_OBJECT_FUNC,
  750. X509_DECODE_FUNC_COUNT,
  751. X509DecodeFuncTable,
  752. 0)))
  753. {
  754. //goto CryptInstallOIDFunctionAddressError;
  755. goto ErrorReturn;
  756. }
  757. break;
  758. case DLL_PROCESS_DETACH:
  759. case DLL_THREAD_DETACH:
  760. default:
  761. break;
  762. }
  763. fRet = TRUE;
  764. CommonReturn:
  765. return fRet;
  766. ErrorReturn:
  767. fRet = FALSE;
  768. goto CommonReturn;
  769. //TRACE_ERROR(CryptInstallOssGlobalError)
  770. //TRACE_ERROR(CryptInitOIDFunctionSetError)
  771. //TRACE_ERROR(CryptInstallOIDFunctionAddressError)
  772. }