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.

1525 lines
45 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows NT Security
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: urlprov.cpp
  7. //
  8. // Contents: CryptGetObjectUrl provider implementation
  9. //
  10. // History: 16-Sep-97 kirtd Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <global.hxx>
  14. //+---------------------------------------------------------------------------
  15. //
  16. // Function: CertificateIssuerGetObjectUrl
  17. //
  18. // Synopsis: get certificate issuer URL
  19. //
  20. //----------------------------------------------------------------------------
  21. BOOL WINAPI
  22. CertificateIssuerGetObjectUrl (
  23. IN LPCSTR pszUrlOid,
  24. IN LPVOID pvPara,
  25. IN DWORD dwFlags,
  26. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  27. IN OUT DWORD* pcbUrlArray,
  28. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  29. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  30. IN OPTIONAL LPVOID pvReserved
  31. )
  32. {
  33. return( ObjectContextUrlFromInfoAccess(
  34. CONTEXT_OID_CERTIFICATE,
  35. pvPara,
  36. (DWORD) -1L,
  37. szOID_AUTHORITY_INFO_ACCESS,
  38. dwFlags,
  39. szOID_PKIX_CA_ISSUERS,
  40. pUrlArray,
  41. pcbUrlArray,
  42. pUrlInfo,
  43. pcbUrlInfo,
  44. pvReserved
  45. ) );
  46. }
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Function: CertificateCrlDistPointGetObjectUrl
  50. //
  51. // Synopsis: get certificate CRL URL
  52. //
  53. //----------------------------------------------------------------------------
  54. BOOL WINAPI
  55. CertificateCrlDistPointGetObjectUrl (
  56. IN LPCSTR pszUrlOid,
  57. IN LPVOID pvPara,
  58. IN DWORD dwFlags,
  59. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  60. IN OUT DWORD* pcbUrlArray,
  61. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  62. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  63. IN LPVOID pvReserved
  64. )
  65. {
  66. return( ObjectContextUrlFromCrlDistPoint(
  67. CONTEXT_OID_CERTIFICATE,
  68. pvPara,
  69. (DWORD) -1L,
  70. dwFlags,
  71. szOID_CRL_DIST_POINTS,
  72. pUrlArray,
  73. pcbUrlArray,
  74. pUrlInfo,
  75. pcbUrlInfo,
  76. pvReserved
  77. ) );
  78. }
  79. //+---------------------------------------------------------------------------
  80. //
  81. // Function: CertificateFreshestCrlGetObjectUrl
  82. //
  83. // Synopsis: get certificate freshest CRL URL
  84. //
  85. //----------------------------------------------------------------------------
  86. BOOL WINAPI
  87. CertificateFreshestCrlGetObjectUrl(
  88. IN LPCSTR pszUrlOid,
  89. IN LPVOID pvPara,
  90. IN DWORD dwFlags,
  91. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  92. IN OUT DWORD* pcbUrlArray,
  93. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  94. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  95. IN OPTIONAL LPVOID pvReserved
  96. )
  97. {
  98. return( ObjectContextUrlFromCrlDistPoint(
  99. CONTEXT_OID_CERTIFICATE,
  100. pvPara,
  101. (DWORD) -1L,
  102. dwFlags,
  103. szOID_FRESHEST_CRL,
  104. pUrlArray,
  105. pcbUrlArray,
  106. pUrlInfo,
  107. pcbUrlInfo,
  108. pvReserved
  109. ) );
  110. }
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Function: CrlFreshestCrlGetObjectUrl
  114. //
  115. // Synopsis: get freshest CRL URL from the certificate's base CRL
  116. //
  117. //----------------------------------------------------------------------------
  118. BOOL WINAPI
  119. CrlFreshestCrlGetObjectUrl(
  120. IN LPCSTR pszUrlOid,
  121. IN LPVOID pvPara,
  122. IN DWORD dwFlags,
  123. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  124. IN OUT DWORD* pcbUrlArray,
  125. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  126. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  127. IN OPTIONAL LPVOID pvReserved
  128. )
  129. {
  130. PCCERT_CRL_CONTEXT_PAIR pCertCrlPair = (PCCERT_CRL_CONTEXT_PAIR) pvPara;
  131. return( ObjectContextUrlFromCrlDistPoint(
  132. CONTEXT_OID_CRL,
  133. (LPVOID) pCertCrlPair->pCrlContext,
  134. (DWORD) -1L,
  135. dwFlags,
  136. szOID_FRESHEST_CRL,
  137. pUrlArray,
  138. pcbUrlArray,
  139. pUrlInfo,
  140. pcbUrlInfo,
  141. pvReserved
  142. ) );
  143. }
  144. //+---------------------------------------------------------------------------
  145. //
  146. // Function: CtlIssuerGetObjectUrl
  147. //
  148. // Synopsis: get CTL issuer URL
  149. //
  150. //----------------------------------------------------------------------------
  151. BOOL WINAPI
  152. CtlIssuerGetObjectUrl (
  153. IN LPCSTR pszUrlOid,
  154. IN LPVOID pvPara,
  155. IN DWORD dwFlags,
  156. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  157. IN OUT DWORD* pcbUrlArray,
  158. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  159. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  160. IN LPVOID pvReserved
  161. )
  162. {
  163. PURL_OID_CTL_ISSUER_PARAM pParam = (PURL_OID_CTL_ISSUER_PARAM)pvPara;
  164. return( ObjectContextUrlFromInfoAccess(
  165. CONTEXT_OID_CTL,
  166. (LPVOID)pParam->pCtlContext,
  167. pParam->SignerIndex,
  168. szOID_AUTHORITY_INFO_ACCESS,
  169. CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE |
  170. CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE,
  171. szOID_PKIX_CA_ISSUERS,
  172. pUrlArray,
  173. pcbUrlArray,
  174. pUrlInfo,
  175. pcbUrlInfo,
  176. pvReserved
  177. ) );
  178. }
  179. //+---------------------------------------------------------------------------
  180. //
  181. // Function: CtlNextUpdateGetObjectUrl
  182. //
  183. // Synopsis: get CTL renewal URL
  184. //
  185. //----------------------------------------------------------------------------
  186. BOOL WINAPI
  187. CtlNextUpdateGetObjectUrl (
  188. IN LPCSTR pszUrlOid,
  189. IN LPVOID pvPara,
  190. IN DWORD dwFlags,
  191. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  192. IN OUT DWORD* pcbUrlArray,
  193. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  194. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  195. IN LPVOID pvReserved
  196. )
  197. {
  198. LPVOID* apv = (LPVOID *)pvPara;
  199. return( ObjectContextUrlFromNextUpdateLocation(
  200. CONTEXT_OID_CTL,
  201. apv[0],
  202. (DWORD)(DWORD_PTR)apv[1],
  203. dwFlags,
  204. pUrlArray,
  205. pcbUrlArray,
  206. pUrlInfo,
  207. pcbUrlInfo,
  208. pvReserved
  209. ) );
  210. }
  211. //+---------------------------------------------------------------------------
  212. //
  213. // Function: CrlIssuerGetObjectUrl
  214. //
  215. // Synopsis: get CRL issuer URL
  216. //
  217. //----------------------------------------------------------------------------
  218. BOOL WINAPI
  219. CrlIssuerGetObjectUrl (
  220. IN LPCSTR pszUrlOid,
  221. IN LPVOID pvPara,
  222. IN DWORD dwFlags,
  223. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  224. IN OUT DWORD* pcbUrlArray,
  225. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  226. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  227. IN LPVOID pvReserved
  228. )
  229. {
  230. return( ObjectContextUrlFromInfoAccess(
  231. CONTEXT_OID_CRL,
  232. pvPara,
  233. (DWORD) -1L,
  234. szOID_AUTHORITY_INFO_ACCESS,
  235. dwFlags,
  236. szOID_PKIX_CA_ISSUERS,
  237. pUrlArray,
  238. pcbUrlArray,
  239. pUrlInfo,
  240. pcbUrlInfo,
  241. pvReserved
  242. ) );
  243. }
  244. //+---------------------------------------------------------------------------
  245. //
  246. // Function: ObjectContextUrlFromInfoAccess
  247. //
  248. // Synopsis: get the URLs specified by the access method OID from the given
  249. // context and format it as a CRYPT_URL_ARRAY
  250. //
  251. //----------------------------------------------------------------------------
  252. BOOL WINAPI
  253. ObjectContextUrlFromInfoAccess (
  254. IN LPCSTR pszContextOid,
  255. IN LPVOID pvContext,
  256. IN DWORD Index,
  257. IN LPCSTR pszInfoAccessOid,
  258. IN DWORD dwFlags,
  259. IN LPCSTR pszAccessMethodOid,
  260. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  261. IN OUT DWORD* pcbUrlArray,
  262. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  263. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  264. IN LPVOID pvReserved
  265. )
  266. {
  267. BOOL fResult = FALSE;
  268. CRYPT_RAW_URL_DATA RawData[MAX_RAW_URL_DATA];
  269. ULONG cRawData = MAX_RAW_URL_DATA;
  270. fResult = ObjectContextGetRawUrlData(
  271. pszContextOid,
  272. pvContext,
  273. Index,
  274. dwFlags,
  275. pszInfoAccessOid,
  276. RawData,
  277. &cRawData
  278. );
  279. if ( fResult == TRUE )
  280. {
  281. fResult = GetUrlArrayAndInfoFromInfoAccess(
  282. cRawData,
  283. RawData,
  284. pszAccessMethodOid,
  285. pUrlArray,
  286. pcbUrlArray,
  287. pUrlInfo,
  288. pcbUrlInfo
  289. );
  290. ObjectContextFreeRawUrlData( cRawData, RawData );
  291. }
  292. return( fResult );
  293. }
  294. //+---------------------------------------------------------------------------
  295. //
  296. // Function: ObjectContextUrlFromCrlDistPoint
  297. //
  298. // Synopsis: get the URLs from the CRL distribution point on the object and
  299. // format as a CRYPT_URL_ARRAY
  300. //
  301. //----------------------------------------------------------------------------
  302. BOOL WINAPI
  303. ObjectContextUrlFromCrlDistPoint (
  304. IN LPCSTR pszContextOid,
  305. IN LPVOID pvContext,
  306. IN DWORD Index,
  307. IN DWORD dwFlags,
  308. IN LPCSTR pszSourceOid,
  309. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  310. IN OUT DWORD* pcbUrlArray,
  311. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  312. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  313. IN LPVOID pvReserved
  314. )
  315. {
  316. BOOL fResult = FALSE;
  317. CRYPT_RAW_URL_DATA RawData[MAX_RAW_URL_DATA];
  318. ULONG cRawData = MAX_RAW_URL_DATA;
  319. fResult = ObjectContextGetRawUrlData(
  320. pszContextOid,
  321. pvContext,
  322. Index,
  323. dwFlags,
  324. pszSourceOid,
  325. RawData,
  326. &cRawData
  327. );
  328. if ( fResult == TRUE )
  329. {
  330. fResult = GetUrlArrayAndInfoFromCrlDistPoint(
  331. cRawData,
  332. RawData,
  333. pUrlArray,
  334. pcbUrlArray,
  335. pUrlInfo,
  336. pcbUrlInfo
  337. );
  338. ObjectContextFreeRawUrlData( cRawData, RawData );
  339. }
  340. return( fResult );
  341. }
  342. //+---------------------------------------------------------------------------
  343. //
  344. // Function: ObjectContextUrlFromNextUpdateLocation
  345. //
  346. // Synopsis: get the URLs from the next update location
  347. //
  348. //----------------------------------------------------------------------------
  349. BOOL WINAPI
  350. ObjectContextUrlFromNextUpdateLocation (
  351. IN LPCSTR pszContextOid,
  352. IN LPVOID pvContext,
  353. IN DWORD Index,
  354. IN DWORD dwFlags,
  355. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  356. IN OUT DWORD* pcbUrlArray,
  357. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  358. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  359. IN LPVOID pvReserved
  360. )
  361. {
  362. BOOL fResult = FALSE;
  363. CRYPT_RAW_URL_DATA RawData[MAX_RAW_URL_DATA];
  364. ULONG cRawData = MAX_RAW_URL_DATA;
  365. fResult = ObjectContextGetRawUrlData(
  366. pszContextOid,
  367. pvContext,
  368. Index,
  369. dwFlags,
  370. szOID_NEXT_UPDATE_LOCATION,
  371. RawData,
  372. &cRawData
  373. );
  374. if ( fResult == TRUE )
  375. {
  376. fResult = GetUrlArrayAndInfoFromNextUpdateLocation(
  377. cRawData,
  378. RawData,
  379. pUrlArray,
  380. pcbUrlArray,
  381. pUrlInfo,
  382. pcbUrlInfo
  383. );
  384. ObjectContextFreeRawUrlData( cRawData, RawData );
  385. }
  386. return( fResult );
  387. }
  388. //+---------------------------------------------------------------------------
  389. //
  390. // Function: InitializeDefaultUrlInfo
  391. //
  392. // Synopsis: initialize default URL info
  393. //
  394. //----------------------------------------------------------------------------
  395. VOID WINAPI
  396. InitializeDefaultUrlInfo (
  397. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  398. IN OUT DWORD* pcbUrlInfo
  399. )
  400. {
  401. if ( pUrlInfo == NULL )
  402. {
  403. *pcbUrlInfo = sizeof( CRYPT_URL_INFO );
  404. return;
  405. }
  406. if (*pcbUrlInfo >= sizeof( CRYPT_URL_INFO ))
  407. {
  408. *pcbUrlInfo = sizeof( CRYPT_URL_INFO );
  409. memset( pUrlInfo, 0, sizeof( CRYPT_URL_INFO ) );
  410. pUrlInfo->cbSize = sizeof( CRYPT_URL_INFO );
  411. }
  412. else if (*pcbUrlInfo >= sizeof( DWORD ))
  413. {
  414. *pcbUrlInfo = sizeof( DWORD );
  415. pUrlInfo->cbSize = sizeof( DWORD );
  416. }
  417. }
  418. //+---------------------------------------------------------------------------
  419. //
  420. // Function: ObjectContextGetRawUrlData
  421. //
  422. // Synopsis: Raw URL data is a decoded extension, property or attribute
  423. // specified by a source OID that contains locator information.
  424. // This API retrieves and decodes such data
  425. //
  426. //----------------------------------------------------------------------------
  427. BOOL WINAPI
  428. ObjectContextGetRawUrlData (
  429. IN LPCSTR pszContextOid,
  430. IN LPVOID pvContext,
  431. IN DWORD Index,
  432. IN DWORD dwFlags,
  433. IN LPCSTR pszSourceOid,
  434. OUT PCRYPT_RAW_URL_DATA aRawUrlData,
  435. IN OUT DWORD* pcRawUrlData
  436. )
  437. {
  438. BOOL fResult = TRUE;
  439. DWORD cCount;
  440. DWORD cError = 0;
  441. DWORD cRawData = 0;
  442. CRYPT_RAW_URL_DATA RawData[MAX_RAW_URL_DATA];
  443. CRYPT_DATA_BLOB DataBlob = {0, NULL};
  444. BOOL fFreeDataBlob = FALSE;
  445. DWORD cbDecoded;
  446. LPBYTE pbDecoded = NULL;
  447. PCRYPT_ATTRIBUTE pAttr = NULL;
  448. DWORD cbAttr;
  449. if ( dwFlags & CRYPT_GET_URL_FROM_PROPERTY )
  450. {
  451. RawData[cRawData].dwFlags = CRYPT_GET_URL_FROM_PROPERTY;
  452. RawData[cRawData].pvData = NULL;
  453. cRawData += 1;
  454. }
  455. if ( dwFlags & CRYPT_GET_URL_FROM_EXTENSION )
  456. {
  457. RawData[cRawData].dwFlags = CRYPT_GET_URL_FROM_EXTENSION;
  458. RawData[cRawData].pvData = NULL;
  459. cRawData += 1;
  460. }
  461. if ( dwFlags & CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE )
  462. {
  463. RawData[cRawData].dwFlags = CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE;
  464. RawData[cRawData].pvData = NULL;
  465. cRawData += 1;
  466. }
  467. if ( dwFlags & CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE )
  468. {
  469. RawData[cRawData].dwFlags = CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE;
  470. RawData[cRawData].pvData = NULL;
  471. cRawData += 1;
  472. }
  473. if ( *pcRawUrlData < cRawData )
  474. {
  475. SetLastError( (DWORD) E_INVALIDARG );
  476. return( FALSE );
  477. }
  478. for ( cCount = 0; cCount < cRawData; cCount++ )
  479. {
  480. switch ( RawData[cCount].dwFlags )
  481. {
  482. case CRYPT_GET_URL_FROM_PROPERTY:
  483. {
  484. DWORD PropId;
  485. fResult = MapOidToPropertyId( pszSourceOid, &PropId );
  486. if ( fResult == TRUE )
  487. {
  488. fResult = ObjectContextGetProperty(
  489. pszContextOid,
  490. pvContext,
  491. PropId,
  492. NULL,
  493. &DataBlob.cbData
  494. );
  495. }
  496. if ( fResult == TRUE )
  497. {
  498. DataBlob.pbData = new BYTE [ DataBlob.cbData ];
  499. if ( DataBlob.pbData != NULL )
  500. {
  501. fFreeDataBlob = TRUE;
  502. fResult = ObjectContextGetProperty(
  503. pszContextOid,
  504. pvContext,
  505. PropId,
  506. DataBlob.pbData,
  507. &DataBlob.cbData
  508. );
  509. }
  510. else
  511. {
  512. fResult = FALSE;
  513. SetLastError( (DWORD) E_OUTOFMEMORY );
  514. }
  515. }
  516. }
  517. break;
  518. case CRYPT_GET_URL_FROM_EXTENSION:
  519. {
  520. PCERT_EXTENSION pExt;
  521. pExt = ObjectContextFindExtension(
  522. pszContextOid,
  523. pvContext,
  524. pszSourceOid
  525. );
  526. if ( pExt != NULL )
  527. {
  528. DataBlob.cbData = pExt->Value.cbData;
  529. DataBlob.pbData = pExt->Value.pbData;
  530. fResult = TRUE;
  531. }
  532. else
  533. {
  534. fResult = FALSE;
  535. }
  536. }
  537. break;
  538. case CRYPT_GET_URL_FROM_UNAUTH_ATTRIBUTE:
  539. case CRYPT_GET_URL_FROM_AUTH_ATTRIBUTE:
  540. {
  541. fResult = ObjectContextGetAttribute(
  542. pszContextOid,
  543. pvContext,
  544. Index,
  545. RawData[cCount].dwFlags,
  546. pszSourceOid,
  547. NULL,
  548. &cbAttr
  549. );
  550. if ( fResult == TRUE )
  551. {
  552. pAttr = (PCRYPT_ATTRIBUTE)new BYTE [cbAttr];
  553. if ( pAttr != NULL )
  554. {
  555. fResult = ObjectContextGetAttribute(
  556. pszContextOid,
  557. pvContext,
  558. Index,
  559. RawData[cCount].dwFlags,
  560. pszSourceOid,
  561. pAttr,
  562. &cbAttr
  563. );
  564. }
  565. else
  566. {
  567. fResult = FALSE;
  568. SetLastError( (DWORD) E_OUTOFMEMORY );
  569. }
  570. }
  571. if ( fResult == TRUE )
  572. {
  573. // We only deal with single valued attributes
  574. DataBlob.cbData = pAttr->rgValue[0].cbData;
  575. DataBlob.pbData = pAttr->rgValue[0].pbData;
  576. }
  577. }
  578. break;
  579. }
  580. if ( fResult == TRUE )
  581. {
  582. fResult = CryptDecodeObject(
  583. X509_ASN_ENCODING,
  584. pszSourceOid,
  585. DataBlob.pbData,
  586. DataBlob.cbData,
  587. 0,
  588. NULL,
  589. &cbDecoded
  590. );
  591. if ( fResult == TRUE )
  592. {
  593. pbDecoded = new BYTE [ cbDecoded ];
  594. if ( pbDecoded != NULL )
  595. {
  596. fResult = CryptDecodeObject(
  597. X509_ASN_ENCODING,
  598. pszSourceOid,
  599. DataBlob.pbData,
  600. DataBlob.cbData,
  601. 0,
  602. pbDecoded,
  603. &cbDecoded
  604. );
  605. }
  606. else
  607. {
  608. fResult = FALSE;
  609. }
  610. }
  611. }
  612. if ( fResult == TRUE )
  613. {
  614. RawData[cCount].pvData = (LPVOID)pbDecoded;
  615. }
  616. else
  617. {
  618. if ( pbDecoded != NULL )
  619. {
  620. delete [] pbDecoded;
  621. }
  622. cError += 1;
  623. }
  624. pbDecoded = NULL;
  625. if ( fFreeDataBlob == TRUE )
  626. {
  627. delete [] DataBlob.pbData;
  628. fFreeDataBlob = FALSE;
  629. }
  630. if ( pAttr != NULL )
  631. {
  632. delete [] (BYTE *)pAttr;
  633. pAttr = NULL;
  634. }
  635. }
  636. if ( cError != cRawData )
  637. {
  638. memcpy( aRawUrlData, RawData, cRawData * sizeof( CRYPT_RAW_URL_DATA ) );
  639. *pcRawUrlData = cRawData;
  640. fResult = TRUE;
  641. }
  642. else
  643. {
  644. SetLastError( (DWORD) CRYPT_E_NOT_FOUND );
  645. fResult = FALSE;
  646. }
  647. return( fResult );
  648. }
  649. //+---------------------------------------------------------------------------
  650. //
  651. // Function: ObjectContextFreeRawUrlData
  652. //
  653. // Synopsis: free the raw URL data
  654. //
  655. //----------------------------------------------------------------------------
  656. VOID WINAPI
  657. ObjectContextFreeRawUrlData (
  658. IN DWORD cRawUrlData,
  659. IN PCRYPT_RAW_URL_DATA aRawUrlData
  660. )
  661. {
  662. DWORD cCount;
  663. for ( cCount = 0; cCount < cRawUrlData; cCount++ )
  664. {
  665. delete [] (BYTE *) aRawUrlData[cCount].pvData;
  666. }
  667. }
  668. //+---------------------------------------------------------------------------
  669. //
  670. // Function: GetUrlArrayAndInfoFromAuthInfoAccess
  671. //
  672. // Synopsis: get URL data using decoded info access data
  673. //
  674. //----------------------------------------------------------------------------
  675. BOOL WINAPI
  676. GetUrlArrayAndInfoFromInfoAccess (
  677. IN DWORD cRawUrlData,
  678. IN PCRYPT_RAW_URL_DATA aRawUrlData,
  679. IN LPCSTR pszAccessMethodOid,
  680. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  681. IN OUT DWORD* pcbUrlArray,
  682. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  683. IN OUT OPTIONAL DWORD* pcbUrlInfo
  684. )
  685. {
  686. BOOL fResult = FALSE;
  687. PCERT_AUTHORITY_INFO_ACCESS pAuthInfoAccess = NULL;
  688. PCERT_ACCESS_DESCRIPTION rgAccDescr = NULL;
  689. DWORD cRaw;
  690. DWORD cCount;
  691. BOOL fAnyFound = FALSE;
  692. CCryptUrlArray cua( 1, 5, fResult );
  693. for ( cRaw = 0; ( fResult == TRUE ) && ( cRaw < cRawUrlData ); cRaw++ )
  694. {
  695. pAuthInfoAccess = (PCERT_AUTHORITY_INFO_ACCESS)aRawUrlData[cRaw].pvData;
  696. if ( pAuthInfoAccess != NULL )
  697. {
  698. rgAccDescr = pAuthInfoAccess->rgAccDescr;
  699. for ( cCount = 0;
  700. ( cCount < pAuthInfoAccess->cAccDescr ) &&
  701. ( fResult == TRUE );
  702. cCount++ )
  703. {
  704. if ( !strcmp(
  705. pszAccessMethodOid,
  706. rgAccDescr[cCount].pszAccessMethod
  707. ) )
  708. {
  709. if ( rgAccDescr[cCount].AccessLocation.dwAltNameChoice ==
  710. CERT_ALT_NAME_URL )
  711. {
  712. fResult = cua.AddUrl(
  713. rgAccDescr[cCount].AccessLocation.pwszURL,
  714. TRUE
  715. );
  716. fAnyFound = TRUE;
  717. }
  718. }
  719. }
  720. }
  721. }
  722. if ( ( fAnyFound == FALSE ) && ( fResult == TRUE ) )
  723. {
  724. SetLastError( (DWORD) CRYPT_E_NOT_FOUND );
  725. fResult = FALSE;
  726. }
  727. if ( fResult == TRUE )
  728. {
  729. PCRYPT_URL_ARRAY* ppUrlArray = NULL;
  730. if ( pUrlArray != NULL )
  731. {
  732. ppUrlArray = &pUrlArray;
  733. }
  734. fResult = cua.GetArrayInSingleBufferEncodedForm(
  735. ppUrlArray,
  736. pcbUrlArray
  737. );
  738. }
  739. if ( ( fResult == TRUE ) && ( pcbUrlInfo != NULL ) )
  740. {
  741. InitializeDefaultUrlInfo( pUrlInfo, pcbUrlInfo );
  742. }
  743. cua.FreeArray( TRUE );
  744. return( fResult );
  745. }
  746. #define DIR_NAME_LDAP_URL_PREFIX L"ldap://"
  747. #define URL_OID_CDP_DIR_NAME_LDAP_HOST_PORTS_VALUE_NAME \
  748. L"DirectoryNameLdapHostPorts"
  749. #define URL_OID_CDP_DIR_NAME_LDAP_SUFFIX_VALUE_NAME \
  750. L"DirectoryNameLdapSuffix"
  751. LPCWSTR pwszDefaultCDPDirNameLdapUrlHostPorts = L"\0\0";
  752. LPCWSTR pwszDefaultCDPDirNameLdapUrlSuffix=
  753. L"?certificateRevocationList;binary,authorityRevocationList;binary,deltaRevocationList;binary";
  754. LPWSTR WINAPI
  755. GetCDPOIDFunctionValue(
  756. IN LPCWSTR pwszValueName
  757. )
  758. {
  759. BOOL fResult;
  760. DWORD dwType;
  761. DWORD cchValue;
  762. DWORD cbValue = 0;
  763. LPWSTR pwszValue = NULL;
  764. fResult = CryptGetOIDFunctionValue(
  765. X509_ASN_ENCODING,
  766. URL_OID_GET_OBJECT_URL_FUNC,
  767. URL_OID_CERTIFICATE_CRL_DIST_POINT,
  768. pwszValueName,
  769. &dwType,
  770. NULL,
  771. &cbValue
  772. );
  773. cchValue = cbValue / sizeof(WCHAR);
  774. if (!fResult || 0 == cchValue ||
  775. !(REG_MULTI_SZ == dwType || REG_SZ == dwType ||
  776. REG_EXPAND_SZ == dwType))
  777. goto ErrorReturn;
  778. pwszValue = new WCHAR [cchValue + 2];
  779. if (NULL == pwszValue)
  780. goto OutOfMemory;
  781. fResult = CryptGetOIDFunctionValue(
  782. X509_ASN_ENCODING,
  783. URL_OID_GET_OBJECT_URL_FUNC,
  784. URL_OID_CERTIFICATE_CRL_DIST_POINT,
  785. pwszValueName,
  786. &dwType,
  787. (BYTE *) pwszValue,
  788. &cbValue
  789. );
  790. if (!fResult)
  791. goto ErrorReturn;
  792. // Ensure the value has two null terminators
  793. pwszValue[cchValue] = L'\0';
  794. pwszValue[cchValue + 1] = L'\0';
  795. CommonReturn:
  796. return pwszValue;
  797. ErrorReturn:
  798. if (pwszValue) {
  799. delete [] pwszValue;
  800. pwszValue = NULL;
  801. }
  802. goto CommonReturn;
  803. OutOfMemory:
  804. SetLastError( (DWORD) E_OUTOFMEMORY );
  805. goto ErrorReturn;
  806. }
  807. // For an error or no found registry value,
  808. // returns pwszDefaultCDPDirNameLdapUrlHostPorts
  809. LPWSTR WINAPI
  810. GetCDPDirNameLdapUrlHostPorts()
  811. {
  812. LPWSTR pwszHostPorts;
  813. pwszHostPorts = GetCDPOIDFunctionValue(
  814. URL_OID_CDP_DIR_NAME_LDAP_HOST_PORTS_VALUE_NAME);
  815. if (NULL == pwszHostPorts)
  816. pwszHostPorts = (LPWSTR) pwszDefaultCDPDirNameLdapUrlHostPorts;
  817. return pwszHostPorts;
  818. }
  819. // For an error or no found registry value,
  820. // returns pwszDefaultCDPDirNameLdapUrlSuffix
  821. LPWSTR WINAPI
  822. GetCDPDirNameLdapUrlSuffix()
  823. {
  824. LPWSTR pwszSuffix = NULL;
  825. pwszSuffix = GetCDPOIDFunctionValue(
  826. URL_OID_CDP_DIR_NAME_LDAP_SUFFIX_VALUE_NAME);
  827. if (NULL == pwszSuffix)
  828. pwszSuffix = (LPWSTR) pwszDefaultCDPDirNameLdapUrlSuffix;
  829. return pwszSuffix;
  830. }
  831. BOOL WINAPI
  832. AddUrlsFromCDPDirectoryName (
  833. IN PCERT_NAME_BLOB pDirNameBlob,
  834. IN OUT CCryptUrlArray *pcua
  835. )
  836. {
  837. BOOL fResult;
  838. LPWSTR pwszHP;
  839. LPWSTR pwszHostPorts;
  840. LPWSTR pwszSuffix;
  841. LPWSTR pwszDirName = NULL;
  842. DWORD cchDirName;
  843. pwszHostPorts = GetCDPDirNameLdapUrlHostPorts();
  844. pwszSuffix = GetCDPDirNameLdapUrlSuffix();
  845. assert(NULL != pwszHostPorts && NULL != pwszSuffix);
  846. cchDirName = CertNameToStrW(
  847. X509_ASN_ENCODING,
  848. pDirNameBlob,
  849. CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG,
  850. NULL, // pwsz
  851. 0 // cch
  852. );
  853. if (1 >= cchDirName)
  854. goto ErrorReturn;
  855. pwszDirName = new WCHAR [cchDirName];
  856. if (NULL == pwszDirName)
  857. goto OutOfMemory;
  858. cchDirName = CertNameToStrW(
  859. X509_ASN_ENCODING,
  860. pDirNameBlob,
  861. CERT_X500_NAME_STR | CERT_NAME_STR_REVERSE_FLAG,
  862. pwszDirName,
  863. cchDirName
  864. );
  865. if (1 >= cchDirName)
  866. goto ErrorReturn;
  867. cchDirName--; // exclude trailing L'\0'
  868. pwszHP = pwszHostPorts;
  869. while (TRUE) {
  870. DWORD cchHP;
  871. LPWSTR pwszUrl;
  872. DWORD cchUrl;
  873. // Skip past any spaces in the HostPort
  874. while (L' ' == *pwszHP)
  875. pwszHP++;
  876. cchHP = wcslen(pwszHP);
  877. cchUrl = wcslen(DIR_NAME_LDAP_URL_PREFIX);
  878. cchUrl += cchHP;
  879. cchUrl += 1; // L'/'
  880. cchUrl += cchDirName;
  881. cchUrl += wcslen(pwszSuffix);
  882. cchUrl += 1; // L'\0'
  883. pwszUrl = new WCHAR [cchUrl];
  884. if (NULL == pwszUrl)
  885. goto OutOfMemory;
  886. wcscpy(pwszUrl, DIR_NAME_LDAP_URL_PREFIX);
  887. wcscat(pwszUrl, pwszHP);
  888. wcscat(pwszUrl, L"/");
  889. wcscat(pwszUrl, pwszDirName);
  890. wcscat(pwszUrl, pwszSuffix);
  891. fResult = pcua->AddUrl(pwszUrl, TRUE);
  892. delete [] pwszUrl;
  893. if (!fResult)
  894. goto ErrorReturn;
  895. pwszHP += cchHP + 1;
  896. if (L'\0' == *pwszHP)
  897. break;
  898. }
  899. fResult = TRUE;
  900. CommonReturn:
  901. if (pwszDirName)
  902. delete [] pwszDirName;
  903. if (pwszHostPorts != pwszDefaultCDPDirNameLdapUrlHostPorts)
  904. delete [] pwszHostPorts;
  905. if (pwszSuffix != pwszDefaultCDPDirNameLdapUrlSuffix)
  906. delete [] pwszSuffix;
  907. return fResult;
  908. ErrorReturn:
  909. fResult = FALSE;
  910. goto CommonReturn;
  911. OutOfMemory:
  912. SetLastError( (DWORD) E_OUTOFMEMORY );
  913. goto ErrorReturn;
  914. }
  915. //+---------------------------------------------------------------------------
  916. //
  917. // Function: GetUrlArrayAndInfoFromCrlDistPoint
  918. //
  919. // Synopsis: get URL data using decoded CRL distribution point info
  920. //
  921. //----------------------------------------------------------------------------
  922. BOOL WINAPI
  923. GetUrlArrayAndInfoFromCrlDistPoint (
  924. IN DWORD cRawUrlData,
  925. IN PCRYPT_RAW_URL_DATA aRawUrlData,
  926. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  927. IN OUT DWORD* pcbUrlArray,
  928. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  929. IN OUT OPTIONAL DWORD* pcbUrlInfo
  930. )
  931. {
  932. BOOL fResult = FALSE;
  933. PCRL_DIST_POINTS_INFO pDistPointsInfo;
  934. PCRL_DIST_POINT rgDistPoint;
  935. PCRL_DIST_POINT_NAME pDistPointName;
  936. PCERT_ALT_NAME_ENTRY rgAltEntry;
  937. DWORD cRaw;
  938. DWORD cCount;
  939. DWORD cEntry;
  940. BOOL fAnyFound = FALSE;
  941. CCryptUrlArray cua( 1, 5, fResult );
  942. for ( cRaw = 0; ( fResult == TRUE ) && ( cRaw < cRawUrlData ); cRaw++ )
  943. {
  944. pDistPointsInfo = (PCRL_DIST_POINTS_INFO)aRawUrlData[cRaw].pvData;
  945. if ( pDistPointsInfo != NULL )
  946. {
  947. rgDistPoint = pDistPointsInfo->rgDistPoint;
  948. for ( cCount = 0;
  949. ( cCount < pDistPointsInfo->cDistPoint ) &&
  950. ( fResult == TRUE );
  951. cCount++ )
  952. {
  953. // Assumption:: don't support partial reasons
  954. // For now, will ignore CRL issuers, they might
  955. // be the same as the cert's issuer. That was the case
  956. // with a Netscape CDP
  957. if (rgDistPoint[cCount].ReasonFlags.cbData)
  958. continue;
  959. pDistPointName = &rgDistPoint[cCount].DistPointName;
  960. if ( pDistPointName->dwDistPointNameChoice ==
  961. CRL_DIST_POINT_FULL_NAME )
  962. {
  963. rgAltEntry = pDistPointName->FullName.rgAltEntry;
  964. for ( cEntry = 0;
  965. ( fResult == TRUE ) &&
  966. ( cEntry < pDistPointName->FullName.cAltEntry );
  967. cEntry++ )
  968. {
  969. switch (rgAltEntry[cEntry].dwAltNameChoice) {
  970. case CERT_ALT_NAME_URL:
  971. fResult = cua.AddUrl(
  972. rgAltEntry[cEntry].pwszURL,
  973. TRUE
  974. );
  975. fAnyFound = TRUE;
  976. break;
  977. case CERT_ALT_NAME_DIRECTORY_NAME:
  978. fResult = AddUrlsFromCDPDirectoryName(
  979. &rgAltEntry[cEntry].DirectoryName,
  980. &cua
  981. );
  982. fAnyFound = TRUE;
  983. break;
  984. default:
  985. break;
  986. }
  987. }
  988. }
  989. }
  990. }
  991. }
  992. if ( ( fAnyFound == FALSE ) && ( fResult == TRUE ) )
  993. {
  994. SetLastError( (DWORD) CRYPT_E_NOT_FOUND );
  995. fResult = FALSE;
  996. }
  997. if ( fResult == TRUE )
  998. {
  999. PCRYPT_URL_ARRAY* ppUrlArray = NULL;
  1000. if ( pUrlArray != NULL )
  1001. {
  1002. ppUrlArray = &pUrlArray;
  1003. }
  1004. fResult = cua.GetArrayInSingleBufferEncodedForm(
  1005. ppUrlArray,
  1006. pcbUrlArray
  1007. );
  1008. }
  1009. if ( ( fResult == TRUE ) && ( pcbUrlInfo != NULL ) )
  1010. {
  1011. InitializeDefaultUrlInfo( pUrlInfo, pcbUrlInfo );
  1012. }
  1013. cua.FreeArray( TRUE );
  1014. return( fResult );
  1015. }
  1016. //+---------------------------------------------------------------------------
  1017. //
  1018. // Function: GetUrlArrayAndInfoFromNextUpdateLocation
  1019. //
  1020. // Synopsis: get URL data using decoded next update location data
  1021. //
  1022. //----------------------------------------------------------------------------
  1023. BOOL WINAPI
  1024. GetUrlArrayAndInfoFromNextUpdateLocation (
  1025. IN DWORD cRawUrlData,
  1026. IN PCRYPT_RAW_URL_DATA aRawUrlData,
  1027. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  1028. IN OUT DWORD* pcbUrlArray,
  1029. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  1030. IN OUT OPTIONAL DWORD* pcbUrlInfo
  1031. )
  1032. {
  1033. BOOL fResult = FALSE;
  1034. PCERT_ALT_NAME_INFO pAltNameInfo;
  1035. PCERT_ALT_NAME_ENTRY rgAltEntry;
  1036. DWORD cRaw;
  1037. DWORD cEntry;
  1038. BOOL fAnyFound = FALSE;
  1039. CCryptUrlArray cua( 1, 5, fResult );
  1040. for ( cRaw = 0; ( fResult == TRUE ) && ( cRaw < cRawUrlData ); cRaw++ )
  1041. {
  1042. pAltNameInfo = (PCERT_ALT_NAME_INFO)aRawUrlData[cRaw].pvData;
  1043. if ( pAltNameInfo != NULL )
  1044. {
  1045. rgAltEntry = pAltNameInfo->rgAltEntry;
  1046. for ( cEntry = 0;
  1047. ( cEntry < pAltNameInfo->cAltEntry ) &&
  1048. ( fResult == TRUE );
  1049. cEntry++ )
  1050. {
  1051. if ( rgAltEntry[cEntry].dwAltNameChoice == CERT_ALT_NAME_URL )
  1052. {
  1053. fResult = cua.AddUrl( rgAltEntry[cEntry].pwszURL, TRUE );
  1054. fAnyFound = TRUE;
  1055. }
  1056. }
  1057. }
  1058. }
  1059. if ( ( fAnyFound == FALSE ) && ( fResult == TRUE ) )
  1060. {
  1061. SetLastError( (DWORD) CRYPT_E_NOT_FOUND );
  1062. fResult = FALSE;
  1063. }
  1064. if ( fResult == TRUE )
  1065. {
  1066. PCRYPT_URL_ARRAY* ppUrlArray = NULL;
  1067. if ( pUrlArray != NULL )
  1068. {
  1069. ppUrlArray = &pUrlArray;
  1070. }
  1071. fResult = cua.GetArrayInSingleBufferEncodedForm(
  1072. ppUrlArray,
  1073. pcbUrlArray
  1074. );
  1075. }
  1076. if ( ( fResult == TRUE ) && ( pcbUrlInfo != NULL ) )
  1077. {
  1078. InitializeDefaultUrlInfo( pUrlInfo, pcbUrlInfo );
  1079. }
  1080. cua.FreeArray( TRUE );
  1081. return( fResult );
  1082. }
  1083. //+---------------------------------------------------------------------------
  1084. //
  1085. // Function: CopyUrlArray
  1086. //
  1087. // Synopsis: copy URL array
  1088. //
  1089. //----------------------------------------------------------------------------
  1090. BOOL WINAPI
  1091. CopyUrlArray (
  1092. IN PCRYPT_URL_ARRAY pDest,
  1093. IN PCRYPT_URL_ARRAY pSource,
  1094. IN DWORD cbDest
  1095. )
  1096. {
  1097. DWORD cCount;
  1098. DWORD cb;
  1099. DWORD cbStruct;
  1100. DWORD cbPointers;
  1101. DWORD cbUrl;
  1102. cbStruct = sizeof( CRYPT_URL_ARRAY );
  1103. cbPointers = pSource->cUrl * sizeof( LPWSTR );
  1104. if (cbDest < (cbStruct + cbPointers))
  1105. {
  1106. SetLastError( (DWORD) E_INVALIDARG );
  1107. return FALSE;
  1108. }
  1109. pDest->cUrl = pSource->cUrl;
  1110. pDest->rgwszUrl = (LPWSTR *)( (LPBYTE)pDest + cbStruct );
  1111. for ( cCount = 0, cb = 0; cCount < pSource->cUrl; cCount++ )
  1112. {
  1113. pDest->rgwszUrl[cCount] = (LPWSTR)((LPBYTE)pDest+cbStruct+cbPointers+cb);
  1114. cbUrl = ( wcslen( pSource->rgwszUrl[cCount] ) + 1 ) * sizeof( WCHAR );
  1115. if (cbDest < (cbStruct + cbPointers + cb + cbUrl))
  1116. {
  1117. SetLastError( (DWORD) E_INVALIDARG );
  1118. return FALSE;
  1119. }
  1120. memcpy( pDest->rgwszUrl[cCount], pSource->rgwszUrl[cCount], cbUrl );
  1121. cb += cbUrl;
  1122. }
  1123. return TRUE;
  1124. }
  1125. //+---------------------------------------------------------------------------
  1126. //
  1127. // Function: GetUrlArrayIndex
  1128. //
  1129. // Synopsis: get index of an URL in the URL array
  1130. //
  1131. //----------------------------------------------------------------------------
  1132. VOID WINAPI
  1133. GetUrlArrayIndex (
  1134. IN PCRYPT_URL_ARRAY pUrlArray,
  1135. IN LPWSTR pwszUrl,
  1136. IN DWORD DefaultIndex,
  1137. OUT DWORD* pUrlIndex,
  1138. OUT BOOL* pfHintInArray
  1139. )
  1140. {
  1141. DWORD cCount;
  1142. if ( pUrlIndex != NULL )
  1143. {
  1144. *pUrlIndex = DefaultIndex;
  1145. }
  1146. if ( pfHintInArray != NULL )
  1147. {
  1148. *pfHintInArray = FALSE;
  1149. }
  1150. if ( pwszUrl == NULL )
  1151. {
  1152. return;
  1153. }
  1154. for ( cCount = 0; cCount < pUrlArray->cUrl; cCount++ )
  1155. {
  1156. if ( wcscmp( pUrlArray->rgwszUrl[cCount], pwszUrl ) == 0 )
  1157. {
  1158. if ( pUrlIndex != NULL )
  1159. {
  1160. *pUrlIndex = cCount;
  1161. }
  1162. if ( pfHintInArray != NULL )
  1163. {
  1164. *pfHintInArray = TRUE;
  1165. }
  1166. break;
  1167. }
  1168. }
  1169. }
  1170. //+---------------------------------------------------------------------------
  1171. //
  1172. // Function: GetUrlArrayAndInfoFromCrossCertDistPoint
  1173. //
  1174. // Synopsis: get URL data using decoded Cross Cert distribution point info
  1175. //
  1176. //----------------------------------------------------------------------------
  1177. BOOL WINAPI
  1178. GetUrlArrayAndInfoFromCrossCertDistPoint (
  1179. IN DWORD cRawUrlData,
  1180. IN PCRYPT_RAW_URL_DATA aRawUrlData,
  1181. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  1182. IN OUT DWORD* pcbUrlArray,
  1183. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  1184. IN OUT OPTIONAL DWORD* pcbUrlInfo
  1185. )
  1186. {
  1187. BOOL fResult = FALSE;
  1188. PCROSS_CERT_DIST_POINTS_INFO pDistPointsInfo;
  1189. PCERT_ALT_NAME_INFO rgDistPoint;
  1190. PCERT_ALT_NAME_ENTRY rgAltEntry;
  1191. DWORD cRaw;
  1192. DWORD cCount;
  1193. DWORD cEntry;
  1194. BOOL fAnyFound = FALSE;
  1195. CCryptUrlArray cua( 1, 5, fResult );
  1196. DWORD dwSyncDeltaTime = 0;
  1197. DWORD cMaxGroup = 0;
  1198. DWORD cGroup = 0;
  1199. DWORD *pcGroupEntry = NULL;
  1200. DWORD cGroupEntry;
  1201. DWORD cbUrlInfo;
  1202. // Get maximum number of groups
  1203. for ( cRaw = 0; cRaw < cRawUrlData; cRaw++ )
  1204. {
  1205. pDistPointsInfo =
  1206. (PCROSS_CERT_DIST_POINTS_INFO)aRawUrlData[cRaw].pvData;
  1207. if ( pDistPointsInfo != NULL )
  1208. {
  1209. cMaxGroup += pDistPointsInfo->cDistPoint;
  1210. }
  1211. }
  1212. if (cMaxGroup > 0)
  1213. {
  1214. pcGroupEntry = new DWORD [cMaxGroup];
  1215. if ( pcGroupEntry == NULL)
  1216. {
  1217. fResult = FALSE;
  1218. SetLastError( (DWORD) E_OUTOFMEMORY );
  1219. }
  1220. }
  1221. for ( cRaw = 0; ( fResult == TRUE ) && ( cRaw < cRawUrlData ); cRaw++ )
  1222. {
  1223. pDistPointsInfo =
  1224. (PCROSS_CERT_DIST_POINTS_INFO)aRawUrlData[cRaw].pvData;
  1225. if ( pDistPointsInfo != NULL )
  1226. {
  1227. if ( dwSyncDeltaTime == 0 )
  1228. {
  1229. dwSyncDeltaTime = pDistPointsInfo->dwSyncDeltaTime;
  1230. }
  1231. rgDistPoint = pDistPointsInfo->rgDistPoint;
  1232. for ( cCount = 0;
  1233. ( cCount < pDistPointsInfo->cDistPoint ) &&
  1234. ( fResult == TRUE );
  1235. cCount++ )
  1236. {
  1237. rgAltEntry = rgDistPoint[cCount].rgAltEntry;
  1238. cGroupEntry = 0;
  1239. for ( cEntry = 0;
  1240. ( fResult == TRUE ) &&
  1241. ( cEntry < rgDistPoint[cCount].cAltEntry );
  1242. cEntry++ )
  1243. {
  1244. switch (rgAltEntry[cEntry].dwAltNameChoice) {
  1245. case CERT_ALT_NAME_URL:
  1246. fResult = cua.AddUrl(
  1247. rgAltEntry[cEntry].pwszURL,
  1248. TRUE
  1249. );
  1250. fAnyFound = TRUE;
  1251. cGroupEntry++;
  1252. break;
  1253. default:
  1254. break;
  1255. }
  1256. }
  1257. if ( cGroupEntry > 0 )
  1258. {
  1259. if (cGroup < cMaxGroup)
  1260. {
  1261. pcGroupEntry[cGroup] = cGroupEntry;
  1262. cGroup++;
  1263. }
  1264. else
  1265. {
  1266. fResult = FALSE;
  1267. SetLastError( (DWORD) E_UNEXPECTED );
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. if ( ( fAnyFound == FALSE ) && ( fResult == TRUE ) )
  1274. {
  1275. SetLastError( (DWORD) CRYPT_E_NOT_FOUND );
  1276. fResult = FALSE;
  1277. }
  1278. if ( fResult == TRUE )
  1279. {
  1280. PCRYPT_URL_ARRAY* ppUrlArray = NULL;
  1281. if ( pUrlArray != NULL )
  1282. {
  1283. ppUrlArray = &pUrlArray;
  1284. }
  1285. fResult = cua.GetArrayInSingleBufferEncodedForm(
  1286. ppUrlArray,
  1287. pcbUrlArray
  1288. );
  1289. }
  1290. if ( ( fResult == TRUE ) && ( pcbUrlInfo != NULL ) )
  1291. {
  1292. cbUrlInfo = sizeof( CRYPT_URL_INFO ) + cGroup * sizeof(DWORD);
  1293. if ( pUrlInfo != NULL )
  1294. {
  1295. if (*pcbUrlInfo < cbUrlInfo)
  1296. {
  1297. fResult = FALSE;
  1298. SetLastError( (DWORD) E_INVALIDARG );
  1299. }
  1300. else
  1301. {
  1302. pUrlInfo->cbSize = sizeof( CRYPT_URL_INFO );
  1303. pUrlInfo->dwSyncDeltaTime = dwSyncDeltaTime;
  1304. pUrlInfo->cGroup = cGroup;
  1305. if ( cGroup > 0 )
  1306. {
  1307. pUrlInfo->rgcGroupEntry = (DWORD *) &pUrlInfo[ 1 ];
  1308. memcpy(pUrlInfo->rgcGroupEntry, pcGroupEntry,
  1309. cGroup * sizeof(DWORD));
  1310. }
  1311. else
  1312. {
  1313. pUrlInfo->rgcGroupEntry = NULL;
  1314. }
  1315. }
  1316. }
  1317. *pcbUrlInfo = cbUrlInfo;
  1318. }
  1319. cua.FreeArray( TRUE );
  1320. if (pcGroupEntry)
  1321. {
  1322. delete [] pcGroupEntry;
  1323. }
  1324. return( fResult );
  1325. }
  1326. //+---------------------------------------------------------------------------
  1327. //
  1328. // Function: CertificateCrossCertDistPointGetObjectUrl
  1329. //
  1330. // Synopsis: get certificate cross certificate URL
  1331. //
  1332. //----------------------------------------------------------------------------
  1333. BOOL WINAPI
  1334. CertificateCrossCertDistPointGetObjectUrl(
  1335. IN LPCSTR pszUrlOid,
  1336. IN LPVOID pvPara,
  1337. IN DWORD dwFlags,
  1338. OUT OPTIONAL PCRYPT_URL_ARRAY pUrlArray,
  1339. IN OUT DWORD* pcbUrlArray,
  1340. OUT OPTIONAL PCRYPT_URL_INFO pUrlInfo,
  1341. IN OUT OPTIONAL DWORD* pcbUrlInfo,
  1342. IN LPVOID pvReserved
  1343. )
  1344. {
  1345. BOOL fResult = FALSE;
  1346. CRYPT_RAW_URL_DATA RawData[MAX_RAW_URL_DATA];
  1347. ULONG cRawData = MAX_RAW_URL_DATA;
  1348. fResult = ObjectContextGetRawUrlData(
  1349. CONTEXT_OID_CERTIFICATE,
  1350. pvPara,
  1351. (DWORD) -1L, // Index
  1352. dwFlags,
  1353. szOID_CROSS_CERT_DIST_POINTS,
  1354. RawData,
  1355. &cRawData
  1356. );
  1357. if ( fResult == TRUE )
  1358. {
  1359. fResult = GetUrlArrayAndInfoFromCrossCertDistPoint(
  1360. cRawData,
  1361. RawData,
  1362. pUrlArray,
  1363. pcbUrlArray,
  1364. pUrlInfo,
  1365. pcbUrlInfo
  1366. );
  1367. ObjectContextFreeRawUrlData( cRawData, RawData );
  1368. }
  1369. return( fResult );
  1370. }