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.

3047 lines
87 KiB

  1. #include "precomp.h"
  2. DEBUG_FILEZONE(ZONE_T120_GCCNC);
  3. /*
  4. * password.cpp
  5. *
  6. * Copyright (c) 1995 by DataBeam Corporation, Lexington, KY
  7. *
  8. * Abstract:
  9. * This is the implementation file for the class CPassword. This class
  10. * manages the data associated with a Password. Passwords are used to
  11. * restrict access to conferences. A password can be one of two basic
  12. * types. The simple type consists of either a simple numeric password or
  13. * a simple textual password, or both. The "PDU" type "Password" is a
  14. * structure which must contain the numeric form of the password and may
  15. * optionally contain the textual part as well. The "PDU" type
  16. * "PasswordSelector" is a union of the numeric and textual forms of a
  17. * password and is therefore always one or the other but not both. When
  18. * the password is not the simple type it assumes the form of a
  19. * "PasswordChallengeRequestResponse". This complex structure allows a
  20. * challenge-response scheme to be used to control access to conferences.
  21. *
  22. * Protected Instance Variables:
  23. * m_fSimplePassword
  24. * Flag indicating this password does not contain "challenge" data.
  25. * m_fClearPassword
  26. * Flag used when the password assumes the "challenge" form indicating
  27. * that this password is "in the clear" meaning no true challenge
  28. * data is present.
  29. * m_pszNumeric
  30. * String holding the numeric portion of the simple password.
  31. * Text_String_Ptr
  32. * String holding the textual portion of the simple password.
  33. * m_pInternalRequest
  34. * Structure holding the data associated with a password challenge
  35. * request.
  36. * m_pInternalResponse
  37. * Structure holding the data associated with a password challenge
  38. * response.
  39. * m_pChallengeResponse
  40. * Structure holding the "API" form of a challenge password.
  41. * m_pPassword
  42. * Structure holding the "API" form of a simple password.
  43. * m_pUserDataMemory
  44. * Memory container holding the user data associated with a
  45. * challenge password.
  46. * m_pChallengeItemListMemory
  47. * Memory container holding the list of pointers to challenge items
  48. * associated with a password challenge request.
  49. * m_pObjectKeyMemory
  50. * Memory container holding the object key data associated with the
  51. * non-standard challenge response algorithm.
  52. * m_ChallengeItemMemoryList
  53. * Memory container holding the data for the challenge items
  54. * associated with a password challenge request.
  55. * m_ChallengeResponsePDU
  56. * Storage for the "PDU" form of the challenge password.
  57. * m_fValidChallengeResponsePDU
  58. * Flag indicating that memory has been allocated to hold the internal
  59. * "PDU" password.
  60. *
  61. * Caveats:
  62. * None.
  63. *
  64. * Author:
  65. * blp/jbo
  66. */
  67. #include "password.h"
  68. #include "userdata.h"
  69. /*
  70. * CPassword()
  71. *
  72. * Public Function Description:
  73. * This constructor for the CPassword class is used when creating a
  74. * CPassword object with an "API" GCCPassword structure. It saves the
  75. * password data in the internal structures.
  76. */
  77. CPassword::CPassword(PGCCPassword password,
  78. PGCCError return_value)
  79. :
  80. CRefCount(MAKE_STAMP_ID('P','a','s','w')),
  81. m_fValidChallengeResponsePDU(FALSE),
  82. m_pInternalRequest(NULL),
  83. m_pInternalResponse(NULL),
  84. m_pChallengeResponse(NULL),
  85. m_pPassword(NULL),
  86. m_pChallengeItemListMemory(NULL),
  87. m_pUserDataMemory(NULL),
  88. m_pObjectKeyMemory(NULL),
  89. m_pszNumeric(NULL),
  90. m_pwszText(NULL)
  91. {
  92. *return_value = GCC_NO_ERROR;
  93. /*
  94. * Set the flag indicating that this is a "simple" password, without the
  95. * challenge request-response information. The "clear" flag is also
  96. * initialized here but should only be needed when the password is not
  97. * "simple".
  98. */
  99. m_fSimplePassword = TRUE;
  100. m_fClearPassword = TRUE;
  101. /*
  102. * Save the numeric part of the password in the internal numeric string.
  103. */
  104. if (password->numeric_string != NULL)
  105. {
  106. if (NULL == (m_pszNumeric = ::My_strdupA(password->numeric_string)))
  107. {
  108. ERROR_OUT(("CPassword::CPassword: can't create numeric string"));
  109. *return_value = GCC_ALLOCATION_FAILURE;
  110. }
  111. }
  112. else
  113. {
  114. ERROR_OUT(("CPassword::CPassword: No valid numeric password"));
  115. *return_value = GCC_INVALID_PASSWORD;
  116. }
  117. /*
  118. * Check to see if the textual part of the password is present. If so,
  119. * save it in the internal UnicodeString. If not, set the text pointer
  120. * to NULL.
  121. */
  122. if ((password->text_string != NULL) && (*return_value == GCC_NO_ERROR))
  123. {
  124. if (NULL == (m_pwszText = ::My_strdupW(password->text_string)))
  125. {
  126. ERROR_OUT(("CPassword::CPassword: Error creating text string"));
  127. *return_value = GCC_ALLOCATION_FAILURE;
  128. }
  129. }
  130. else
  131. m_pwszText = NULL;
  132. }
  133. /*
  134. * CPassword()
  135. *
  136. * Public Function Description:
  137. * This constructor is used when a CPassword object is being created
  138. * with a "ChallengeRequestResponse" "API" structure. The password data
  139. * is saved in the internal structures.
  140. */
  141. CPassword::CPassword(PGCCChallengeRequestResponse challenge_response_data,
  142. PGCCError return_value)
  143. :
  144. CRefCount(MAKE_STAMP_ID('P','a','s','w')),
  145. m_fValidChallengeResponsePDU(FALSE),
  146. m_pInternalRequest(NULL),
  147. m_pInternalResponse(NULL),
  148. m_pChallengeResponse(NULL),
  149. m_pPassword(NULL),
  150. m_pChallengeItemListMemory(NULL),
  151. m_pUserDataMemory(NULL),
  152. m_pObjectKeyMemory(NULL),
  153. m_pszNumeric(NULL),
  154. m_pwszText(NULL)
  155. {
  156. *return_value = GCC_NO_ERROR;
  157. /*
  158. * Set the flag indicating that this is not a "simple" password, meaning
  159. * that it contains challenge request-response information. If the password
  160. * is "clear" there is no need to create the internal "Challenge" structure
  161. * used to hold the challenge request-response information.
  162. */
  163. m_fSimplePassword = FALSE;
  164. /*
  165. * Check to see if a "clear" challenge password exists or if this is a
  166. * true challenge request-response password.
  167. */
  168. if (challenge_response_data->password_challenge_type ==
  169. GCC_PASSWORD_IN_THE_CLEAR)
  170. {
  171. /*
  172. * A "clear" password is being sent so set the flag indicating so.
  173. * Also set the password type and save the numeric part of the password,
  174. * if it exists. Note that since the "clear" password contained in the
  175. * challenge is a PasswordSelector type, either the numeric or the text
  176. * form of the password should exist, but not both.
  177. */
  178. m_fClearPassword = TRUE;
  179. if (challenge_response_data->u.password_in_the_clear.
  180. numeric_string != NULL)
  181. {
  182. if (NULL == (m_pszNumeric = ::My_strdupA(
  183. challenge_response_data->u.password_in_the_clear.numeric_string)))
  184. {
  185. ERROR_OUT(("CPassword::CPassword: can't create numeric string"));
  186. *return_value = GCC_ALLOCATION_FAILURE;
  187. }
  188. }
  189. else
  190. {
  191. m_pszNumeric = NULL;
  192. }
  193. /*
  194. * Check to see if the textual part of the password is present. If it
  195. * is, save it in the internal UnicodeString.
  196. */
  197. if ((challenge_response_data->u.password_in_the_clear.
  198. text_string != NULL) && (*return_value == GCC_NO_ERROR))
  199. {
  200. if (NULL == (m_pwszText = ::My_strdupW(
  201. challenge_response_data->u.password_in_the_clear.text_string)))
  202. {
  203. ERROR_OUT(("CPassword::CPassword: Error creating text string"));
  204. *return_value = GCC_ALLOCATION_FAILURE;
  205. }
  206. }
  207. else
  208. {
  209. m_pwszText = NULL;
  210. }
  211. /*
  212. * Check to make sure at least one form (text or numeric) of the
  213. * "clear" password was saved. Report an error if neither was created.
  214. */
  215. if ((*return_value == GCC_NO_ERROR) && (m_pszNumeric == NULL)
  216. && (m_pwszText == NULL))
  217. {
  218. ERROR_OUT(("CPassword::CPassword: Error creating password"));
  219. *return_value = GCC_INVALID_PASSWORD;
  220. }
  221. }
  222. else
  223. {
  224. /*
  225. * This is a true challenge request-response password. Set the flag
  226. * indicating that the password is not "clear" and create the
  227. * "challenge" data structures to hold the password data internally.
  228. */
  229. m_fClearPassword = FALSE;
  230. /*
  231. * Check to see if a challenge request is present.
  232. */
  233. if (challenge_response_data->u.challenge_request_response.
  234. challenge_request != NULL)
  235. {
  236. /*
  237. * Create a RequestInfo stucture to hold the request data
  238. * and copy the challenge request structure internally.
  239. */
  240. DBG_SAVE_FILE_LINE
  241. m_pInternalRequest = new RequestInfo;
  242. if (m_pInternalRequest != NULL)
  243. {
  244. *return_value = ConvertAPIChallengeRequest (
  245. challenge_response_data->u.
  246. challenge_request_response.challenge_request);
  247. }
  248. else
  249. {
  250. ERROR_OUT(("CPassword::CPassword: Error creating new RequestInfo"));
  251. *return_value = GCC_ALLOCATION_FAILURE;
  252. }
  253. }
  254. /*
  255. * Check to see if a challenge response is present.
  256. */
  257. if ((challenge_response_data->u.challenge_request_response.
  258. challenge_response != NULL) &&
  259. (*return_value == GCC_NO_ERROR))
  260. {
  261. /*
  262. * Create a ResponseInfo stucture to hold the response data
  263. * and copy the challenge response structure internally.
  264. */
  265. DBG_SAVE_FILE_LINE
  266. m_pInternalResponse = new ResponseInfo;
  267. if (m_pInternalResponse != NULL)
  268. {
  269. *return_value = ConvertAPIChallengeResponse (
  270. challenge_response_data->u.
  271. challenge_request_response.challenge_response);
  272. }
  273. else
  274. {
  275. ERROR_OUT(("CPassword::CPassword: Error creating new ResponseInfo"));
  276. *return_value = GCC_ALLOCATION_FAILURE;
  277. }
  278. }
  279. }
  280. }
  281. /*
  282. * CPassword()
  283. *
  284. * Public Function Description
  285. * This constructor for the CPassword class is used when creating a
  286. * CPassword object with a "PDU" Password structure. It saves the
  287. * password data in the internal structures.
  288. */
  289. CPassword::CPassword(PPassword password_pdu,
  290. PGCCError return_value)
  291. :
  292. CRefCount(MAKE_STAMP_ID('P','a','s','w')),
  293. m_fValidChallengeResponsePDU(FALSE),
  294. m_pInternalRequest(NULL),
  295. m_pInternalResponse(NULL),
  296. m_pChallengeResponse(NULL),
  297. m_pPassword(NULL),
  298. m_pChallengeItemListMemory(NULL),
  299. m_pUserDataMemory(NULL),
  300. m_pObjectKeyMemory(NULL),
  301. m_pszNumeric(NULL),
  302. m_pwszText(NULL)
  303. {
  304. *return_value = GCC_NO_ERROR;
  305. /*
  306. * Set the flag indicating that this is a "simple" password, without the
  307. * challenge request-response information. The "clear" flag is also
  308. * initialized here but should only be needed when the password is not
  309. * "simple".
  310. */
  311. m_fSimplePassword = TRUE;
  312. m_fClearPassword = TRUE;
  313. /*
  314. * Save the numeric part of the password. The numeric portion of the
  315. * password is required to be present so report an error if it is not.
  316. */
  317. if (password_pdu->numeric != NULL)
  318. {
  319. if (NULL == (m_pszNumeric = ::My_strdupA(password_pdu->numeric)))
  320. {
  321. ERROR_OUT(("CPassword::CPassword: can't create numeric string"));
  322. *return_value = GCC_ALLOCATION_FAILURE;
  323. }
  324. }
  325. else
  326. {
  327. ERROR_OUT(("CPassword::CPassword: Error no valid numeric password in PDU"));
  328. *return_value = GCC_INVALID_PASSWORD;
  329. m_pszNumeric = NULL;
  330. }
  331. /*
  332. * Check to see if the textual part of the password is present.
  333. */
  334. if ((password_pdu->bit_mask & PASSWORD_TEXT_PRESENT) &&
  335. (*return_value == GCC_NO_ERROR))
  336. {
  337. if (NULL == (m_pwszText = ::My_strdupW2(
  338. password_pdu->password_text.length,
  339. password_pdu->password_text.value)))
  340. {
  341. ERROR_OUT(("CPassword::CPassword: Error creating password text"));
  342. *return_value = GCC_ALLOCATION_FAILURE;
  343. }
  344. }
  345. else
  346. m_pwszText = NULL;
  347. }
  348. /*
  349. * CPassword()
  350. *
  351. * Public Function Description:
  352. * This constructor for the CPassword class is used when creating a
  353. * CPassword object with a "PDU" PasswordSelector structure. It saves
  354. * the password data in it's internal structures but does not require
  355. * saving any "challenge request-response" data.
  356. */
  357. CPassword::CPassword(PPasswordSelector password_selector_pdu,
  358. PGCCError return_value)
  359. :
  360. CRefCount(MAKE_STAMP_ID('P','a','s','w')),
  361. m_fValidChallengeResponsePDU(FALSE),
  362. m_pInternalRequest(NULL),
  363. m_pInternalResponse(NULL),
  364. m_pChallengeResponse(NULL),
  365. m_pPassword(NULL),
  366. m_pChallengeItemListMemory(NULL),
  367. m_pUserDataMemory(NULL),
  368. m_pObjectKeyMemory(NULL),
  369. m_pszNumeric(NULL),
  370. m_pwszText(NULL)
  371. {
  372. *return_value = GCC_NO_ERROR;
  373. /*
  374. * Set the flag indicating that this is a "simple" password, without the
  375. * challenge request-response information.
  376. */
  377. m_fSimplePassword = TRUE;
  378. m_fClearPassword = TRUE;
  379. /*
  380. * The password selector contains either the numeric password or the
  381. * textual password but not both. Check to see if the textual password
  382. * is chosen.
  383. */
  384. if (password_selector_pdu->choice == PASSWORD_SELECTOR_TEXT_CHOSEN)
  385. {
  386. if (NULL == (m_pwszText = ::My_strdupW2(
  387. password_selector_pdu->u.password_selector_text.length,
  388. password_selector_pdu->u.password_selector_text.value)))
  389. {
  390. ERROR_OUT(("CPassword::CPassword: Error creating password selector text"));
  391. *return_value = GCC_ALLOCATION_FAILURE;
  392. }
  393. }
  394. else
  395. m_pwszText = NULL;
  396. /*
  397. * Check to see if the numeric password is chosen.
  398. */
  399. if (password_selector_pdu->choice == PASSWORD_SELECTOR_NUMERIC_CHOSEN)
  400. {
  401. if (NULL == (m_pszNumeric = ::My_strdupA(
  402. password_selector_pdu->u.password_selector_numeric)))
  403. {
  404. ERROR_OUT(("CPassword::CPassword: can't create numeric string"));
  405. *return_value = GCC_ALLOCATION_FAILURE;
  406. }
  407. }
  408. else
  409. m_pszNumeric = NULL;
  410. /*
  411. * Check to make sure at least one form (text or numeric) of the
  412. * password was saved. Report an error if neither was created.
  413. */
  414. if ((*return_value == GCC_NO_ERROR) && (m_pszNumeric == NULL)
  415. && (m_pwszText == NULL))
  416. {
  417. ERROR_OUT(("CPassword::CPassword: Error creating password selector"));
  418. *return_value = GCC_INVALID_PASSWORD;
  419. }
  420. }
  421. /*
  422. * CPassword()
  423. *
  424. * Public Function Description:
  425. * This constructor for the CPassword class is used when creating a
  426. * CPassword object with a "PDU" Challenge Request-Response structure.
  427. * The password data is saved in the internal structures.
  428. */
  429. CPassword::CPassword(PPasswordChallengeRequestResponse pdu_challenge_data,
  430. PGCCError return_value)
  431. :
  432. CRefCount(MAKE_STAMP_ID('P','a','s','w')),
  433. m_fValidChallengeResponsePDU(FALSE),
  434. m_pInternalRequest(NULL),
  435. m_pInternalResponse(NULL),
  436. m_pChallengeResponse(NULL),
  437. m_pPassword(NULL),
  438. m_pChallengeItemListMemory(NULL),
  439. m_pUserDataMemory(NULL),
  440. m_pObjectKeyMemory(NULL),
  441. m_pszNumeric(NULL),
  442. m_pwszText(NULL)
  443. {
  444. *return_value = GCC_NO_ERROR;
  445. /*
  446. * Set the flag indicating that this is not "simple" password, meaning that
  447. * it contains challenge request-response information. If the password is
  448. * "clear" there is no need to create the internal "Challenge" structure
  449. * used to hold the challenge request-response information.
  450. */
  451. m_fSimplePassword = FALSE;
  452. /*
  453. * Check to see if a "clear" challenge password exists or if this is a
  454. * true challenge request-response password.
  455. */
  456. if (pdu_challenge_data->choice == CHALLENGE_CLEAR_PASSWORD_CHOSEN)
  457. {
  458. /*
  459. * A "clear" password is being sent so set the flag indicating so.
  460. * Also set the password type and save the numeric part of the password,
  461. * if it is present.
  462. */
  463. m_fClearPassword = TRUE;
  464. if (pdu_challenge_data->u.challenge_clear_password.choice ==
  465. PASSWORD_SELECTOR_NUMERIC_CHOSEN)
  466. {
  467. if (NULL == (m_pszNumeric = ::My_strdupA(
  468. pdu_challenge_data->u.challenge_clear_password.u.password_selector_numeric)))
  469. {
  470. ERROR_OUT(("CPassword::CPassword: can't create numeric string"));
  471. *return_value = GCC_ALLOCATION_FAILURE;
  472. }
  473. }
  474. else
  475. {
  476. m_pszNumeric = NULL;
  477. }
  478. /*
  479. * Check to see if the textual part of the password is present. If it
  480. * is, save it in the internal structure.
  481. */
  482. if (pdu_challenge_data->u.challenge_clear_password.choice ==
  483. PASSWORD_SELECTOR_TEXT_CHOSEN)
  484. {
  485. if (NULL == (m_pwszText = ::My_strdupW2(
  486. pdu_challenge_data->u.challenge_clear_password.
  487. u.password_selector_text.length,
  488. pdu_challenge_data->u.challenge_clear_password.
  489. u.password_selector_text.value)))
  490. {
  491. ERROR_OUT(("CPassword::CPassword: Error creating password selector text"));
  492. *return_value = GCC_ALLOCATION_FAILURE;
  493. }
  494. }
  495. else
  496. {
  497. m_pwszText = NULL;
  498. }
  499. /*
  500. * Check to make sure at least one form (text or numeric) of the
  501. * "clear" password was saved. Report an error if neither was created.
  502. */
  503. if ((*return_value == GCC_NO_ERROR) && (m_pszNumeric == NULL)
  504. && (m_pwszText == NULL))
  505. {
  506. ERROR_OUT(("CPassword::CPassword: Error creating password"));
  507. *return_value = GCC_INVALID_PASSWORD;
  508. }
  509. }
  510. else
  511. {
  512. /*
  513. * This is a true challenge request-response password. Set the flag
  514. * indicating that the password is not "clear" and create a
  515. * "challenge data" structure to hold the password data internally.
  516. */
  517. m_fClearPassword = FALSE;
  518. /*
  519. * Check to see if a challenge request is present.
  520. */
  521. if (pdu_challenge_data->u.challenge_request_response.
  522. bit_mask & CHALLENGE_REQUEST_PRESENT)
  523. {
  524. /*
  525. * Create a RequestInfo stucture to hold the request data
  526. * and copy the challenge request structure internally.
  527. */
  528. DBG_SAVE_FILE_LINE
  529. m_pInternalRequest = new RequestInfo;
  530. if (m_pInternalRequest != NULL)
  531. {
  532. *return_value = ConvertPDUChallengeRequest (
  533. &pdu_challenge_data->u.challenge_request_response.
  534. challenge_request);
  535. }
  536. else
  537. {
  538. ERROR_OUT(("CPassword::CPassword: Error creating new RequestInfo"));
  539. *return_value = GCC_ALLOCATION_FAILURE;
  540. }
  541. }
  542. /*
  543. * Check to see if a challenge response is present.
  544. */
  545. if ((pdu_challenge_data->u.challenge_request_response.
  546. bit_mask & CHALLENGE_RESPONSE_PRESENT) &&
  547. (*return_value == GCC_NO_ERROR))
  548. {
  549. /*
  550. * Create a ResponseInfo stucture to hold the response data
  551. * and copy the challenge response structure internally.
  552. */
  553. DBG_SAVE_FILE_LINE
  554. m_pInternalResponse = new ResponseInfo;
  555. if (m_pInternalResponse != NULL)
  556. {
  557. *return_value = ConvertPDUChallengeResponse (
  558. &pdu_challenge_data->u.challenge_request_response.
  559. challenge_response);
  560. }
  561. else
  562. {
  563. ERROR_OUT(("CPassword::CPassword: Error creating new ResponseInfo"));
  564. *return_value = GCC_ALLOCATION_FAILURE;
  565. }
  566. }
  567. }
  568. }
  569. /*
  570. * ~CPassword()
  571. *
  572. * Public Function Description:
  573. * This is the destructor for the CPassword class. It will free up
  574. * any memory allocated during the life of this object.
  575. */
  576. CPassword::~CPassword(void)
  577. {
  578. PChallengeItemInfo challenge_item_info_ptr;
  579. delete m_pszNumeric;
  580. delete m_pwszText;
  581. /*
  582. * If "PDU" data has been allocated for this object, free it now.
  583. */
  584. if (m_fValidChallengeResponsePDU)
  585. {
  586. FreePasswordChallengeResponsePDU();
  587. }
  588. /*
  589. * Delete the memory associated with the "API" "simple" password
  590. * data structure.
  591. */
  592. delete m_pPassword;
  593. /*
  594. * Free any data allocated for the "API" challenge password. This would be
  595. * left around if "UnLock" was not called. Note that if the "challenge"
  596. * password is "clear", the numeric and text pointers above would contain
  597. * the "API" data so now we just need to delete the "challenge" password
  598. * structure.
  599. */
  600. if (m_pChallengeResponse != NULL)
  601. {
  602. if (m_fClearPassword == FALSE)
  603. {
  604. FreeAPIPasswordData();
  605. }
  606. else
  607. {
  608. delete m_pChallengeResponse;
  609. }
  610. }
  611. /*
  612. * Free any internal memory allocated for the challenge request information.
  613. * Iterate through the list of challenge items associated with the
  614. * challenge request, if it exists.
  615. */
  616. if (m_pInternalRequest != NULL)
  617. {
  618. m_pInternalRequest->ChallengeItemList.Reset();
  619. while (NULL != (challenge_item_info_ptr = m_pInternalRequest->ChallengeItemList.Iterate()))
  620. {
  621. /*
  622. * Delete any memory being referenced in the ChallengeItemInfo
  623. * structure.
  624. */
  625. if (NULL != challenge_item_info_ptr->algorithm.object_key)
  626. {
  627. challenge_item_info_ptr->algorithm.object_key->Release();
  628. }
  629. delete challenge_item_info_ptr->algorithm.poszOctetString;
  630. if (NULL!= challenge_item_info_ptr->challenge_data_list)
  631. {
  632. challenge_item_info_ptr->challenge_data_list->Release();
  633. }
  634. /*
  635. * Delete the challenge item contained in the list.
  636. */
  637. delete challenge_item_info_ptr;
  638. }
  639. /*
  640. * Delete the request structure.
  641. */
  642. delete m_pInternalRequest;
  643. }
  644. /*
  645. * Delete any memory allocated for the challenge response information.
  646. */
  647. if (m_pInternalResponse != NULL)
  648. {
  649. if (NULL != m_pInternalResponse->algorithm.object_key)
  650. {
  651. m_pInternalResponse->algorithm.object_key->Release();
  652. }
  653. delete m_pInternalResponse->algorithm.poszOctetString;
  654. if (NULL != m_pInternalResponse->challenge_response_item.password)
  655. {
  656. m_pInternalResponse->challenge_response_item.password->Release();
  657. }
  658. if (NULL != m_pInternalResponse->challenge_response_item.response_data_list)
  659. {
  660. m_pInternalResponse->challenge_response_item.response_data_list->Release();
  661. }
  662. delete m_pInternalResponse;
  663. }
  664. }
  665. /*
  666. * LockPasswordData ()
  667. *
  668. * Public Function Description:
  669. * This routine is called to "Lock" the password data. The first time this
  670. * routine is called, the lock count will be zero and this will result
  671. * in the password data being copied from the internal structures into an
  672. * "API" structure of the proper form. Subsequent calls to this routine
  673. * will result in the lock count being incremented.
  674. */
  675. GCCError CPassword::LockPasswordData(void)
  676. {
  677. GCCError rc;
  678. if (Lock() == 1)
  679. {
  680. rc = GCC_ALLOCATION_FAILURE;
  681. /*
  682. * Check to see whether or not the password contains "challenge"
  683. * information. Fill in the appropriate internal structure.
  684. */
  685. if (m_fSimplePassword)
  686. {
  687. if (m_pszNumeric == NULL)
  688. {
  689. ERROR_OUT(("CPassword::LockPasswordData: No valid numeric password data exists"));
  690. goto MyExit;
  691. }
  692. DBG_SAVE_FILE_LINE
  693. if (NULL == (m_pPassword = new GCCPassword))
  694. {
  695. ERROR_OUT(("CPassword::LockPasswordData: can't create GCCPassword"));
  696. goto MyExit;
  697. }
  698. /*
  699. * Fill in the numeric password string which must exist.
  700. */
  701. m_pPassword->numeric_string = (GCCNumericString) m_pszNumeric;
  702. /*
  703. * Fill in the textual password string.
  704. */
  705. m_pPassword->text_string = m_pwszText;
  706. }
  707. else
  708. {
  709. /*
  710. * The password contains challenge information so create the
  711. * structure to pass back the necessary information.
  712. */
  713. DBG_SAVE_FILE_LINE
  714. m_pChallengeResponse = new GCCChallengeRequestResponse;
  715. if (m_pChallengeResponse == NULL)
  716. {
  717. ERROR_OUT(("CPassword::LockPasswordData: can't create GCCChallengeRequestResponse"));
  718. goto MyExit;
  719. }
  720. ::ZeroMemory(m_pChallengeResponse, sizeof(GCCChallengeRequestResponse));
  721. /*
  722. * Fill in the "API" password challenge structure after
  723. * determining what type exists.
  724. */
  725. if (m_fClearPassword)
  726. {
  727. /*
  728. * This password contains no "challenge" information.
  729. */
  730. m_pChallengeResponse->password_challenge_type = GCC_PASSWORD_IN_THE_CLEAR;
  731. /*
  732. * This "clear" part of the password is a "selector" which
  733. * means the form is either numeric or text. The check to
  734. * verify that at least one form exists was done on
  735. * construction.
  736. */
  737. m_pChallengeResponse->u.password_in_the_clear.numeric_string = m_pszNumeric;
  738. m_pChallengeResponse->u.password_in_the_clear.text_string = m_pwszText;
  739. }
  740. else
  741. {
  742. /*
  743. * This password contains real "challenge" information.
  744. */
  745. m_pChallengeResponse->password_challenge_type = GCC_PASSWORD_CHALLENGE;
  746. /*
  747. * Check to see if a challenge request exists. If so,
  748. * create a GCCChallengeRequest to hold the "API" data and
  749. * fill in that structure.
  750. */
  751. if (m_pInternalRequest != NULL)
  752. {
  753. DBG_SAVE_FILE_LINE
  754. m_pChallengeResponse->u.challenge_request_response.
  755. challenge_request = new GCCChallengeRequest;
  756. if (m_pChallengeResponse->u.challenge_request_response.
  757. challenge_request == NULL)
  758. {
  759. ERROR_OUT(("CPassword::LockPasswordData: can't create GCCChallengeRequest"));
  760. goto MyExit;
  761. }
  762. if (GetGCCChallengeRequest(m_pChallengeResponse->u.
  763. challenge_request_response.challenge_request) != GCC_NO_ERROR)
  764. {
  765. ERROR_OUT(("CPassword::LockPasswordData: can't gett GCCChallengeRequest"));
  766. goto MyExit;
  767. }
  768. }
  769. else
  770. {
  771. m_pChallengeResponse->u.challenge_request_response.challenge_request = NULL;
  772. }
  773. /*
  774. * Check to see if a challenge response exists. If so,
  775. * create a GCCChallengeResponse to hold the "API" data and
  776. * fill in that structure.
  777. */
  778. if (m_pInternalResponse != NULL)
  779. {
  780. DBG_SAVE_FILE_LINE
  781. m_pChallengeResponse->u.challenge_request_response.
  782. challenge_response = new GCCChallengeResponse;
  783. if (m_pChallengeResponse->u.challenge_request_response.
  784. challenge_response == NULL)
  785. {
  786. ERROR_OUT(("CPassword::LockPasswordData: can't create new GCCChallengeResponse"));
  787. goto MyExit;
  788. }
  789. if (GetGCCChallengeResponse(m_pChallengeResponse->u.
  790. challenge_request_response.challenge_response) != GCC_NO_ERROR)
  791. {
  792. ERROR_OUT(("CPassword::LockPasswordData: can't get GCCChallengeResponse"));
  793. goto MyExit;
  794. }
  795. }
  796. else
  797. {
  798. m_pChallengeResponse->u.challenge_request_response.
  799. challenge_response = NULL;
  800. }
  801. }
  802. }
  803. }
  804. rc = GCC_NO_ERROR;
  805. MyExit:
  806. if (GCC_NO_ERROR != rc)
  807. {
  808. if (! m_fSimplePassword)
  809. {
  810. if (NULL != m_pChallengeResponse)
  811. {
  812. delete m_pChallengeResponse->u.challenge_request_response.challenge_request;
  813. delete m_pChallengeResponse->u.challenge_request_response.challenge_response;
  814. delete m_pChallengeResponse;
  815. m_pChallengeResponse = NULL;
  816. }
  817. }
  818. }
  819. return rc;
  820. }
  821. /*
  822. * GetPasswordData ()
  823. *
  824. * Public Function Description:
  825. * This routine is used to retrieve the password data in the form of
  826. * the "API" structure "GCCPassword". No "challenge" information is
  827. * returned.
  828. */
  829. GCCError CPassword::GetPasswordData(PGCCPassword *gcc_password)
  830. {
  831. GCCError return_value = GCC_NO_ERROR;
  832. /*
  833. * If the pointer to the "API" password data is valid, set the output
  834. * parameter to return a pointer to the "API" password data. Otherwise,
  835. * report that the password data has yet to be locked into the "API" form.
  836. */
  837. if (m_pPassword != NULL)
  838. {
  839. *gcc_password = m_pPassword;
  840. }
  841. else
  842. {
  843. *gcc_password = NULL;
  844. return_value = GCC_ALLOCATION_FAILURE;
  845. ERROR_OUT(("CPassword::GetPasswordData: Error Data Not Locked"));
  846. }
  847. return (return_value);
  848. }
  849. /*
  850. * GetPasswordChallengeData ()
  851. *
  852. * Public Function Description:
  853. * This routine is used to retrieve the password data in the form of
  854. * the "API" structure "GCCChallengeRequestResponse".
  855. */
  856. GCCError CPassword::GetPasswordChallengeData(PGCCChallengeRequestResponse *gcc_challenge_password)
  857. {
  858. GCCError return_value = GCC_NO_ERROR;
  859. /*
  860. * If the pointer to the "API" password challenge data is valid, set the
  861. * output parameter to return a pointer to the "API" password challenge
  862. * data. Otherwise, report that the password data has yet to be locked
  863. * into the "API" form.
  864. */
  865. if (m_pChallengeResponse != NULL)
  866. {
  867. *gcc_challenge_password = m_pChallengeResponse;
  868. }
  869. else
  870. {
  871. *gcc_challenge_password = NULL;
  872. return_value = GCC_ALLOCATION_FAILURE;
  873. ERROR_OUT(("CPassword::GetPasswordData: Error Data Not Locked"));
  874. }
  875. return (return_value);
  876. }
  877. /*
  878. * UnLockPasswordData ()
  879. *
  880. * Public Function Description
  881. * This routine decrements the lock count and frees the memory associated
  882. * with "API" password data when the lock count reaches zero.
  883. */
  884. void CPassword::UnLockPasswordData(void)
  885. {
  886. if (Unlock(FALSE) == 0)
  887. {
  888. /*
  889. * Delete the memory associated with the "API" "simple" password
  890. * data structure.
  891. */
  892. delete m_pPassword;
  893. m_pPassword = NULL;
  894. /*
  895. * Delete the memory associated with the "API" "challenge" password
  896. * data structure.
  897. */
  898. if (m_pChallengeResponse != NULL)
  899. {
  900. if (m_fClearPassword == FALSE)
  901. {
  902. FreeAPIPasswordData();
  903. }
  904. else
  905. {
  906. delete m_pChallengeResponse;
  907. m_pChallengeResponse = NULL;
  908. }
  909. }
  910. }
  911. // we have to call Release() because we used Unlock(FALSE)
  912. Release();
  913. }
  914. /*
  915. * GetPasswordPDU ()
  916. *
  917. * Public Function Description:
  918. * This routine is used to retrieve the password data in the "PDU" form
  919. * of a "Password" structure.
  920. */
  921. GCCError CPassword::GetPasswordPDU(PPassword pdu_password)
  922. {
  923. GCCError return_value = GCC_NO_ERROR;
  924. pdu_password->bit_mask = 0;
  925. /*
  926. * Fill in the numeric portion of the password which must always exist.
  927. */
  928. if (m_pszNumeric != NULL)
  929. {
  930. ::lstrcpyA(pdu_password->numeric, m_pszNumeric);
  931. }
  932. else
  933. return_value = GCC_ALLOCATION_FAILURE;
  934. /*
  935. * Fill in the optional textual portion of the password if it is present.
  936. * Set the bitmask in the PDU structure to indicate that the text exists.
  937. */
  938. if (m_pwszText != NULL)
  939. {
  940. pdu_password->bit_mask |= PASSWORD_TEXT_PRESENT;
  941. pdu_password->password_text.value = m_pwszText;
  942. pdu_password->password_text.length= ::lstrlenW(m_pwszText);
  943. }
  944. return (return_value);
  945. }
  946. /*
  947. * GetPasswordSelectorPDU ()
  948. *
  949. * Public Function Description:
  950. * This routine is used to retrieve the password data in the "PDU" form
  951. * of a "PasswordSelector" structure. In a "PasswordSelector" either the
  952. * numeric or the text version of the password exists, but not both.
  953. */
  954. GCCError CPassword::GetPasswordSelectorPDU(PPasswordSelector password_selector_pdu)
  955. {
  956. GCCError return_value = GCC_NO_ERROR;
  957. /*
  958. * Fill in the version of the password which exists and set
  959. * the "choice" to indicate what type of password this is.
  960. */
  961. if (m_pszNumeric != NULL)
  962. {
  963. password_selector_pdu->choice = PASSWORD_SELECTOR_NUMERIC_CHOSEN;
  964. ::lstrcpyA(password_selector_pdu->u.password_selector_numeric, m_pszNumeric);
  965. }
  966. else if (m_pwszText != NULL)
  967. {
  968. password_selector_pdu->choice = PASSWORD_SELECTOR_TEXT_CHOSEN;
  969. password_selector_pdu->u.password_selector_text.value = m_pwszText;
  970. password_selector_pdu->u.password_selector_text.length = ::lstrlenW(m_pwszText);
  971. }
  972. else
  973. {
  974. ERROR_OUT(("CPassword::GetPasswordSelectorPDU: No valid data"));
  975. return_value = GCC_INVALID_PASSWORD;
  976. }
  977. return (return_value);
  978. }
  979. /*
  980. * GetPasswordChallengeResponsePDU ()
  981. *
  982. * Public Function Description:
  983. * This routine fills in a password challenge request-response "PDU"
  984. * structure with the password data.
  985. */
  986. GCCError CPassword::GetPasswordChallengeResponsePDU(PPasswordChallengeRequestResponse challenge_pdu)
  987. {
  988. GCCError return_value = GCC_NO_ERROR;
  989. /*
  990. * Check to see if this is a "simple" password. If it is, then this routine
  991. * has been called in error.
  992. */
  993. if ((challenge_pdu == NULL) || m_fSimplePassword)
  994. {
  995. ERROR_OUT(("CPassword::GetPasswordChallengeResponsePDU: no challenge data"));
  996. return (GCC_INVALID_PARAMETER);
  997. }
  998. /*
  999. * If this is the first time that PDU data has been requested then we must
  1000. * fill in the internal PDU structure and copy it into the structure pointed
  1001. * to by the output parameter. On subsequent calls to "GetPDU" we can just
  1002. * copy the internal PDU structure into the structure pointed to by the
  1003. * output parameter.
  1004. */
  1005. if (m_fValidChallengeResponsePDU == FALSE)
  1006. {
  1007. m_fValidChallengeResponsePDU = TRUE;
  1008. /*
  1009. * Fill in the password challenge PDU structure.
  1010. */
  1011. if (m_fClearPassword)
  1012. {
  1013. /*
  1014. * If this is a clear password then fill in the text or
  1015. * numeric string as well as the choice. Only one form of the
  1016. * password exists for PasswordSelectors such as this.
  1017. */
  1018. m_ChallengeResponsePDU.choice = CHALLENGE_CLEAR_PASSWORD_CHOSEN;
  1019. if (m_pszNumeric != NULL)
  1020. {
  1021. m_ChallengeResponsePDU.u.challenge_clear_password.choice =
  1022. PASSWORD_SELECTOR_NUMERIC_CHOSEN;
  1023. ::lstrcpyA(m_ChallengeResponsePDU.u.challenge_clear_password.u.password_selector_numeric,
  1024. m_pszNumeric);
  1025. }
  1026. else if (m_pwszText != NULL)
  1027. {
  1028. m_ChallengeResponsePDU.u.challenge_clear_password.choice =
  1029. PASSWORD_SELECTOR_TEXT_CHOSEN;
  1030. m_ChallengeResponsePDU.u.challenge_clear_password.u.
  1031. password_selector_text.value = m_pwszText;
  1032. m_ChallengeResponsePDU.u.challenge_clear_password.u.
  1033. password_selector_text.length = ::lstrlenW(m_pwszText);
  1034. }
  1035. else
  1036. {
  1037. ERROR_OUT(("CPassword::GetPwordChallengeResPDU: No valid data"));
  1038. return_value = GCC_INVALID_PASSWORD;
  1039. }
  1040. }
  1041. else
  1042. {
  1043. /*
  1044. * The challenge password contains challenge information. Fill in
  1045. * the request and response structures if they exist.
  1046. */
  1047. m_ChallengeResponsePDU.choice = CHALLENGE_REQUEST_RESPONSE_CHOSEN;
  1048. m_ChallengeResponsePDU.u.challenge_request_response.bit_mask = 0;
  1049. /*
  1050. * Check to see if a "request" exists.
  1051. */
  1052. if (m_pInternalRequest != NULL)
  1053. {
  1054. m_ChallengeResponsePDU.u.challenge_request_response.bit_mask |=
  1055. CHALLENGE_REQUEST_PRESENT;
  1056. /*
  1057. * Call the routine which fills in the PDU form of the
  1058. * request structure.
  1059. */
  1060. return_value = GetChallengeRequestPDU (&m_ChallengeResponsePDU.
  1061. u.challenge_request_response.challenge_request);
  1062. }
  1063. /*
  1064. * Check to see if a "response" exists.
  1065. */
  1066. if ((m_pInternalResponse != NULL) && (return_value == GCC_NO_ERROR))
  1067. {
  1068. m_ChallengeResponsePDU.u.challenge_request_response.bit_mask |=
  1069. CHALLENGE_RESPONSE_PRESENT;
  1070. /*
  1071. * Call the routine which fills in the PDU form of the
  1072. * response structure.
  1073. */
  1074. return_value = GetChallengeResponsePDU (&m_ChallengeResponsePDU.
  1075. u.challenge_request_response.challenge_response);
  1076. }
  1077. }
  1078. }
  1079. /*
  1080. * Copy the internal PDU structure into the structure pointed to by the
  1081. * output parameter.
  1082. */
  1083. *challenge_pdu = m_ChallengeResponsePDU;
  1084. return (return_value);
  1085. }
  1086. /*
  1087. * FreePasswordChallengeResponsePDU ()
  1088. *
  1089. * Public Function Description:
  1090. * This routine is used to free any memory allocated to hold "PDU" data
  1091. * associated with the PasswordChallengeRequestResponse.
  1092. */
  1093. void CPassword::FreePasswordChallengeResponsePDU(void)
  1094. {
  1095. /*
  1096. * Check to see if there has been any "PDU" memory allocated which now
  1097. * needs to be freed.
  1098. */
  1099. if (m_fValidChallengeResponsePDU)
  1100. {
  1101. /*
  1102. * Set the flag indicating that PDU password data is no longer
  1103. * allocated.
  1104. */
  1105. m_fValidChallengeResponsePDU = FALSE;
  1106. /*
  1107. * Check to see what type of password PDU is to be freed. If this is a
  1108. * clear password then no data was allocated which now must be freed.
  1109. */
  1110. if (m_ChallengeResponsePDU.choice == CHALLENGE_REQUEST_RESPONSE_CHOSEN)
  1111. {
  1112. /*
  1113. * This is a challenge password so free any data which was allocated
  1114. * to hold the challenge information. Check the PDU structure
  1115. * bitmask which indicates what form of challenge exists.
  1116. */
  1117. if (m_ChallengeResponsePDU.u.challenge_request_response.bit_mask &
  1118. CHALLENGE_REQUEST_PRESENT)
  1119. {
  1120. FreeChallengeRequestPDU ();
  1121. }
  1122. if (m_ChallengeResponsePDU.u.challenge_request_response.
  1123. bit_mask & CHALLENGE_RESPONSE_PRESENT)
  1124. {
  1125. FreeChallengeResponsePDU ();
  1126. }
  1127. }
  1128. }
  1129. }
  1130. /*
  1131. * GCCError ConvertAPIChallengeRequest(
  1132. * PGCCChallengeRequest challenge_request)
  1133. *
  1134. * Private member function of CPassword.
  1135. *
  1136. * Function Description:
  1137. * This routine is used to copy an "API" challenge request structure into
  1138. * the internal structure.
  1139. *
  1140. * Formal Parameters:
  1141. * challenge_request (i) The API structure to copy internally.
  1142. *
  1143. * Return Value:
  1144. * GCC_NO_ERROR - No error.
  1145. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1146. * "new" operator.
  1147. * GCC_INVALID_PASSWORD - An invalid password passed in.
  1148. *
  1149. * Side Effects:
  1150. * None.
  1151. *
  1152. * Caveats:
  1153. * None.
  1154. */
  1155. GCCError CPassword::ConvertAPIChallengeRequest(PGCCChallengeRequest challenge_request)
  1156. {
  1157. GCCError return_value = GCC_NO_ERROR;
  1158. GCCError error_value;
  1159. Int i;
  1160. PGCCChallengeItem challenge_item_ptr;
  1161. PChallengeItemInfo challenge_item_info_ptr;
  1162. /*
  1163. * Save the challenge tag and number of challenge items in the internal
  1164. * structure.
  1165. */
  1166. m_pInternalRequest->challenge_tag = challenge_request->challenge_tag;
  1167. /*
  1168. * Save the list of challenge items in the internal Rogue Wave List.
  1169. */
  1170. for (i = 0; i < challenge_request->number_of_challenge_items; i++)
  1171. {
  1172. DBG_SAVE_FILE_LINE
  1173. challenge_item_info_ptr = new ChallengeItemInfo;
  1174. if (challenge_item_info_ptr != NULL)
  1175. {
  1176. /*
  1177. * Initialize the pointers in the challenge item info structure
  1178. * to NULL.
  1179. */
  1180. challenge_item_info_ptr->algorithm.object_key = NULL;
  1181. challenge_item_info_ptr->algorithm.poszOctetString = NULL;
  1182. challenge_item_info_ptr->challenge_data_list = NULL;
  1183. /*
  1184. * Insert the pointer to the new challenge item structure into the
  1185. * internal list.
  1186. */
  1187. m_pInternalRequest->ChallengeItemList.Append(challenge_item_info_ptr);
  1188. /*
  1189. * Retrieve the pointer to the challenge item from the input list.
  1190. */
  1191. challenge_item_ptr = challenge_request->challenge_item_list[i];
  1192. /*
  1193. * Copy the challenge response algorithm to the internal structure.
  1194. */
  1195. return_value = CopyResponseAlgorithm (
  1196. &(challenge_item_ptr->response_algorithm),
  1197. &(challenge_item_info_ptr->algorithm));
  1198. if (return_value != GCC_NO_ERROR)
  1199. {
  1200. ERROR_OUT(("Password::ConvertAPIChallengeRequest: Error copying Response Algorithm."));
  1201. break;
  1202. }
  1203. /*
  1204. * Copy the challenge data.
  1205. */
  1206. if ((challenge_item_ptr->number_of_challenge_data_members != 0) &&
  1207. (challenge_item_ptr->challenge_data_list != NULL))
  1208. {
  1209. DBG_SAVE_FILE_LINE
  1210. challenge_item_info_ptr->challenge_data_list = new CUserDataListContainer(
  1211. challenge_item_ptr->number_of_challenge_data_members,
  1212. challenge_item_ptr->challenge_data_list,
  1213. &error_value);
  1214. if ((challenge_item_info_ptr == NULL) ||
  1215. (error_value != GCC_NO_ERROR))
  1216. {
  1217. ERROR_OUT(("Password::ConvertAPIChallengeRequest: can't create CUserDataListContainer."));
  1218. return_value = GCC_ALLOCATION_FAILURE;
  1219. break;
  1220. }
  1221. }
  1222. else
  1223. {
  1224. challenge_item_info_ptr->challenge_data_list = NULL;
  1225. ERROR_OUT(("Password::ConvertAPIChallengeRequest: Error no valid user data."));
  1226. return_value = GCC_INVALID_PASSWORD;
  1227. break;
  1228. }
  1229. }
  1230. else
  1231. {
  1232. ERROR_OUT(("Password::ConvertAPIChallengeRequest: Error creating "
  1233. "new ChallengeItemInfo."));
  1234. return_value = GCC_ALLOCATION_FAILURE;
  1235. break;
  1236. }
  1237. }
  1238. return (return_value);
  1239. }
  1240. /*
  1241. * GCCError ConvertAPIChallengeResponse(
  1242. * PGCCChallengeResponse challenge_response)
  1243. *
  1244. * Private member function of CPassword.
  1245. *
  1246. * Function Description:
  1247. * This routine is used to copy an "API" challenge response structure into
  1248. * the internal structure.
  1249. *
  1250. * Formal Parameters:
  1251. * challenge_response (i) The API structure to copy internally.
  1252. *
  1253. * Return Value:
  1254. * GCC_NO_ERROR - No error.
  1255. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1256. * "new" operator.
  1257. * GCC_INVALID_PASSWORD - An invalid password passed in.
  1258. *
  1259. * Side Effects:
  1260. * None.
  1261. *
  1262. * Caveats:
  1263. * None.
  1264. */
  1265. GCCError CPassword::ConvertAPIChallengeResponse(PGCCChallengeResponse challenge_response)
  1266. {
  1267. GCCError return_value = GCC_NO_ERROR;
  1268. GCCError error_value;
  1269. /*
  1270. * Initialize the challenge response info structure pointers to NULL.
  1271. */
  1272. m_pInternalResponse->challenge_response_item.password = NULL;
  1273. m_pInternalResponse->challenge_response_item.response_data_list = NULL;
  1274. /*
  1275. * Save the challenge tag in the internal structure.
  1276. */
  1277. m_pInternalResponse->challenge_tag = challenge_response->challenge_tag;
  1278. /*
  1279. * Copy the challenge response algorithm to the internal structure.
  1280. */
  1281. return_value = CopyResponseAlgorithm (
  1282. &(challenge_response->response_algorithm),
  1283. &(m_pInternalResponse->algorithm));
  1284. if (return_value != GCC_NO_ERROR)
  1285. {
  1286. ERROR_OUT(("Password::ConvertAPIChallengeResponse: Error copying Response Algorithm."));
  1287. }
  1288. /*
  1289. * Copy the challenge response item into the internal info structure.
  1290. * The challenge response item will consist of either a password string
  1291. * or else a response user data list.
  1292. */
  1293. if (return_value == GCC_NO_ERROR)
  1294. {
  1295. if (challenge_response->response_algorithm.password_algorithm_type ==
  1296. GCC_IN_THE_CLEAR_ALGORITHM)
  1297. {
  1298. if (challenge_response->response_item.password_string != NULL)
  1299. {
  1300. DBG_SAVE_FILE_LINE
  1301. m_pInternalResponse->challenge_response_item.password = new
  1302. CPassword(challenge_response->response_item.password_string, &error_value);
  1303. if ((m_pInternalResponse->challenge_response_item.password ==
  1304. NULL)|| (error_value != GCC_NO_ERROR))
  1305. {
  1306. ERROR_OUT(("Password::ConvertAPIChallengeResp: Error creating new CPassword."));
  1307. return_value = GCC_ALLOCATION_FAILURE;
  1308. }
  1309. }
  1310. else
  1311. return_value = GCC_INVALID_PASSWORD;
  1312. }
  1313. else
  1314. {
  1315. if ((challenge_response->response_item.
  1316. number_of_response_data_members != 0) &&
  1317. (challenge_response->response_item.response_data_list != NULL))
  1318. {
  1319. /*
  1320. * Save the response data list in a CUserDataListContainer object.
  1321. */
  1322. DBG_SAVE_FILE_LINE
  1323. m_pInternalResponse->challenge_response_item.response_data_list =
  1324. new CUserDataListContainer(challenge_response->response_item.number_of_response_data_members,
  1325. challenge_response->response_item.response_data_list,
  1326. &error_value);
  1327. if ((m_pInternalResponse->challenge_response_item.response_data_list == NULL) ||
  1328. (error_value != GCC_NO_ERROR))
  1329. {
  1330. ERROR_OUT(("Password::ConvertAPIChallengeResponse: can't create CUserDataListContainer."));
  1331. return_value = GCC_ALLOCATION_FAILURE;
  1332. }
  1333. }
  1334. else
  1335. return_value = GCC_INVALID_PASSWORD;
  1336. }
  1337. }
  1338. /*
  1339. * Check to make sure one type of response item was saved.
  1340. */
  1341. if ((return_value == GCC_NO_ERROR) &&
  1342. (m_pInternalResponse->challenge_response_item.password == NULL) &&
  1343. (m_pInternalResponse->challenge_response_item.response_data_list ==
  1344. NULL))
  1345. {
  1346. ERROR_OUT(("Password::ConvertAPIChallengeResponse: Error no valid response item saved."));
  1347. return_value = GCC_ALLOCATION_FAILURE;
  1348. }
  1349. return (return_value);
  1350. }
  1351. /*
  1352. * GCCError CopyResponseAlgorithm(
  1353. * PGCCChallengeResponseAlgorithm source_algorithm,
  1354. * PResponseAlgorithmInfo destination_algorithm)
  1355. *
  1356. * Private member function of CPassword.
  1357. *
  1358. * Function Description:
  1359. * This routine is used to copy an "API" response algorithm into the
  1360. * internal storage structure.
  1361. *
  1362. * Formal Parameters:
  1363. * source_algorithm (i) The API algorithm structure to copy
  1364. * internally.
  1365. * destination_algorithm (o) Pointer to the internal algorithm structure
  1366. * which will hold the converted item.
  1367. *
  1368. * Return Value:
  1369. * GCC_NO_ERROR - No error.
  1370. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1371. * "new" operator.
  1372. * GCC_INVALID_PASSWORD - An invalid password passed in.
  1373. *
  1374. * Side Effects:
  1375. * None.
  1376. *
  1377. * Caveats:
  1378. * None.
  1379. */
  1380. GCCError CPassword::CopyResponseAlgorithm(
  1381. PGCCChallengeResponseAlgorithm source_algorithm,
  1382. PResponseAlgorithmInfo destination_algorithm)
  1383. {
  1384. GCCError return_value = GCC_NO_ERROR;
  1385. GCCError error_value;
  1386. /*
  1387. * Copy the challenge response algorithm.
  1388. */
  1389. destination_algorithm->algorithm_type = source_algorithm->
  1390. password_algorithm_type;
  1391. if (destination_algorithm->algorithm_type == GCC_NON_STANDARD_ALGORITHM)
  1392. {
  1393. /*
  1394. * Create a new CObjectKeyContainer object to hold the algorithm's object key
  1395. * internally.
  1396. */
  1397. DBG_SAVE_FILE_LINE
  1398. destination_algorithm->object_key = new CObjectKeyContainer(
  1399. &source_algorithm->non_standard_algorithm->object_key,
  1400. &error_value);
  1401. if (destination_algorithm->object_key == NULL)
  1402. {
  1403. ERROR_OUT(("CPassword::CopyResponseAlgorithm: Error creating new CObjectKeyContainer"));
  1404. return_value = GCC_ALLOCATION_FAILURE;
  1405. }
  1406. else if (error_value != GCC_NO_ERROR)
  1407. {
  1408. ERROR_OUT(("CPassword::CopyResponseAlgorithm: Error creating new CObjectKeyContainer"));
  1409. return_value = GCC_INVALID_PASSWORD;
  1410. }
  1411. if (return_value == GCC_NO_ERROR)
  1412. {
  1413. /*
  1414. * Create a new Rogue Wave string to hold the algorithm's octet
  1415. * string internally.
  1416. */
  1417. if (NULL == (destination_algorithm->poszOctetString = ::My_strdupO2(
  1418. source_algorithm->non_standard_algorithm->parameter_data.value,
  1419. source_algorithm->non_standard_algorithm->parameter_data.length)))
  1420. {
  1421. ERROR_OUT(("CPassword::CopyResponseAlgorithm: can't create octet string in algorithm"));
  1422. return_value = GCC_ALLOCATION_FAILURE;
  1423. }
  1424. }
  1425. else
  1426. destination_algorithm->poszOctetString = NULL;
  1427. }
  1428. else
  1429. {
  1430. /*
  1431. * The algorithm is a standard type so initialize to NULL the pointers
  1432. * used to hold the data associated with a non-standard algorithm.
  1433. */
  1434. destination_algorithm->object_key = NULL;
  1435. destination_algorithm->poszOctetString = NULL;
  1436. }
  1437. return (return_value);
  1438. }
  1439. /*
  1440. * GCCError ConvertPDUChallengeRequest (
  1441. * PChallengeRequest challenge_request);
  1442. *
  1443. * Private member function of CPassword.
  1444. *
  1445. * Function Description:
  1446. * This routine is used to copy a "PDU" challenge request structure into
  1447. * the internal storage structure.
  1448. *
  1449. * Formal Parameters:
  1450. * challenge_request (i) The API structure to copy internally.
  1451. *
  1452. * Return Value:
  1453. * GCC_NO_ERROR - No error.
  1454. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1455. * "new" operator.
  1456. * GCC_INVALID_PASSWORD - An invalid password passed in.
  1457. *
  1458. * Side Effects:
  1459. * None.
  1460. *
  1461. * Caveats:
  1462. * None.
  1463. */
  1464. GCCError CPassword::ConvertPDUChallengeRequest(PChallengeRequest challenge_request)
  1465. {
  1466. GCCError return_value = GCC_NO_ERROR;
  1467. PSetOfChallengeItems current_challenge_item_set;
  1468. PSetOfChallengeItems next_challenge_item_set;
  1469. /*
  1470. * Save the challenge tag in the internal structure.
  1471. */
  1472. m_pInternalRequest->challenge_tag = challenge_request->challenge_tag;
  1473. if (challenge_request->set_of_challenge_items != NULL)
  1474. {
  1475. /*
  1476. * Loop through the PDU set of challenge items, converting each into
  1477. * the internal form.
  1478. */
  1479. current_challenge_item_set = challenge_request->set_of_challenge_items;
  1480. while (1)
  1481. {
  1482. next_challenge_item_set = current_challenge_item_set->next;
  1483. /*
  1484. * The routine which converts the challenge items saves the internal
  1485. * form in a Rogue Wave list.
  1486. */
  1487. if (ConvertPDUChallengeItem (&current_challenge_item_set->value) !=
  1488. GCC_NO_ERROR)
  1489. {
  1490. return_value = GCC_ALLOCATION_FAILURE;
  1491. break;
  1492. }
  1493. if (next_challenge_item_set != NULL)
  1494. current_challenge_item_set = next_challenge_item_set;
  1495. else
  1496. break;
  1497. }
  1498. }
  1499. return (return_value);
  1500. }
  1501. /*
  1502. * GCCError ConvertPDUChallengeItem (
  1503. * PChallengeItem challenge_item_ptr);
  1504. *
  1505. * Private member function of CPassword.
  1506. *
  1507. * Function Description:
  1508. * This routine is used to copy a "PDU" ChallengeItem structure into
  1509. * the internal ChallengeItemInfo storage structure.
  1510. *
  1511. * Formal Parameters:
  1512. * challenge_item_ptr (i) The PDU structure to copy internally.
  1513. *
  1514. * Return Value:
  1515. * GCC_NO_ERROR - No error.
  1516. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1517. * "new" operator.
  1518. * GCC_INVALID_PASSWORD - An invalid password passed in.
  1519. *
  1520. * Side Effects:
  1521. * None.
  1522. *
  1523. * Caveats:
  1524. * None.
  1525. */
  1526. GCCError CPassword::ConvertPDUChallengeItem(PChallengeItem challenge_item_ptr)
  1527. {
  1528. PChallengeItemInfo challenge_item_info_ptr;
  1529. GCCError return_value = GCC_NO_ERROR;
  1530. GCCError error_value = GCC_NO_ERROR;
  1531. /*
  1532. * Create a new challenge item and save it in the internal Rogue Wave List.
  1533. */
  1534. DBG_SAVE_FILE_LINE
  1535. challenge_item_info_ptr = new ChallengeItemInfo;
  1536. if (challenge_item_info_ptr != NULL)
  1537. {
  1538. /*
  1539. * Insert the pointer to the new challenge item structure into the
  1540. * internal Rogue Wave list.
  1541. */
  1542. challenge_item_info_ptr->challenge_data_list = NULL;
  1543. m_pInternalRequest->ChallengeItemList.Append(challenge_item_info_ptr);
  1544. /*
  1545. * Convert the challenge response algorithm to the internal structure.
  1546. */
  1547. if (ConvertPDUResponseAlgorithm(
  1548. &(challenge_item_ptr->response_algorithm),
  1549. &(challenge_item_info_ptr->algorithm)) != GCC_NO_ERROR)
  1550. {
  1551. ERROR_OUT(("Password::ConvertAPIChallengeItem: Error converting Response Algorithm."));
  1552. return_value = GCC_ALLOCATION_FAILURE;
  1553. }
  1554. /*
  1555. * Convert the challenge data to internal form.
  1556. */
  1557. if ((return_value == GCC_NO_ERROR) &&
  1558. (challenge_item_ptr->set_of_challenge_data != NULL))
  1559. {
  1560. DBG_SAVE_FILE_LINE
  1561. challenge_item_info_ptr->challenge_data_list = new CUserDataListContainer(
  1562. challenge_item_ptr->set_of_challenge_data,
  1563. &error_value);
  1564. if ((challenge_item_info_ptr->challenge_data_list == NULL) ||
  1565. (error_value != GCC_NO_ERROR))
  1566. {
  1567. ERROR_OUT(("Password::ConvertAPIChallengeItem: can't create CUserDataListContainer."));
  1568. return_value = GCC_ALLOCATION_FAILURE;
  1569. }
  1570. }
  1571. else
  1572. {
  1573. ERROR_OUT(("Password::ConvertAPIChallengeItem: Error no valid user data"));
  1574. return_value = GCC_INVALID_PASSWORD;
  1575. }
  1576. }
  1577. else
  1578. {
  1579. ERROR_OUT(("Password::ConvertAPIChallengeItem: Error creating "
  1580. "new ChallengeItemInfo."));
  1581. return_value = GCC_ALLOCATION_FAILURE;
  1582. }
  1583. return (return_value);
  1584. }
  1585. /*
  1586. * GCCError ConvertPDUChallengeResponse (
  1587. * PChallengeResponse challenge_response)
  1588. *
  1589. * Private member function of CPassword.
  1590. *
  1591. * Function Description:
  1592. * This routine is used to copy a "PDU" challenge response structure into
  1593. * the internal structure.
  1594. *
  1595. * Formal Parameters:
  1596. * challenge_response (i) The API structure to copy internally.
  1597. *
  1598. * Return Value:
  1599. * GCC_NO_ERROR - No error.
  1600. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1601. * "new" operator.
  1602. *
  1603. * Side Effects:
  1604. * None.
  1605. *
  1606. * Caveats:
  1607. * None.
  1608. */
  1609. GCCError CPassword::ConvertPDUChallengeResponse(PChallengeResponse challenge_response)
  1610. {
  1611. GCCError return_value = GCC_NO_ERROR;
  1612. GCCError error_value = GCC_NO_ERROR;
  1613. /*
  1614. * Save the challenge tag in the internal structure.
  1615. */
  1616. m_pInternalResponse->challenge_tag = challenge_response->challenge_tag;
  1617. /*
  1618. * Convert the challenge response algorithm to the internal structure.
  1619. */
  1620. if (ConvertPDUResponseAlgorithm(
  1621. &(challenge_response->response_algorithm),
  1622. &(m_pInternalResponse->algorithm)) != GCC_NO_ERROR)
  1623. {
  1624. ERROR_OUT(("Password::ConvertPDUChallengeResponse: Error converting Response Algorithm."));
  1625. return_value = GCC_ALLOCATION_FAILURE;
  1626. }
  1627. /*
  1628. * Check to see what form the challenge response item has taken. Create
  1629. * the necessary object to hold the item internally.
  1630. */
  1631. if ((challenge_response->response_item.choice == PASSWORD_STRING_CHOSEN) &&
  1632. (return_value == GCC_NO_ERROR))
  1633. {
  1634. DBG_SAVE_FILE_LINE
  1635. m_pInternalResponse->challenge_response_item.password = new CPassword(
  1636. &challenge_response->response_item.u.password_string,
  1637. &error_value);
  1638. if ((m_pInternalResponse->challenge_response_item.password == NULL) ||
  1639. (error_value != GCC_NO_ERROR))
  1640. {
  1641. ERROR_OUT(("Password::ConvertPDUChallengeResponse: Error creating new CPassword."));
  1642. return_value = GCC_ALLOCATION_FAILURE;
  1643. }
  1644. }
  1645. else
  1646. m_pInternalResponse->challenge_response_item.password = NULL;
  1647. if ((challenge_response->response_item.choice ==
  1648. SET_OF_RESPONSE_DATA_CHOSEN) && (return_value == GCC_NO_ERROR))
  1649. {
  1650. DBG_SAVE_FILE_LINE
  1651. m_pInternalResponse->challenge_response_item.response_data_list =
  1652. new CUserDataListContainer(challenge_response->response_item.u.set_of_response_data,
  1653. &error_value);
  1654. if ((m_pInternalResponse->challenge_response_item.
  1655. response_data_list == NULL) || (error_value != GCC_NO_ERROR))
  1656. {
  1657. ERROR_OUT(("Password::ConvertPDUChallengeResponse: can't create CUserDataListContainer."));
  1658. return_value = GCC_ALLOCATION_FAILURE;
  1659. }
  1660. }
  1661. else
  1662. {
  1663. m_pInternalResponse->challenge_response_item.response_data_list = NULL;
  1664. }
  1665. return (return_value);
  1666. }
  1667. /*
  1668. * GCCError ConvertPDUResponseAlgorithm (
  1669. * PChallengeResponseAlgorithm source_algorithm,
  1670. * PResponseAlgorithmInfo destination_algorithm);
  1671. *
  1672. * Private member function of CPassword.
  1673. *
  1674. * Function Description:
  1675. * This routine is used to convert a "PDU" response algorithm
  1676. * structure into the internal form.
  1677. *
  1678. * Formal Parameters:
  1679. * source_algorithm (i) The PDU algorithm structure to copy
  1680. * internally.
  1681. * destination_algorithm (o) Pointer to the internal structure which will
  1682. * hold the converted item.
  1683. *
  1684. * Return Value:
  1685. * GCC_NO_ERROR - No error.
  1686. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1687. * "new" operator.
  1688. * GCC_INVALID_PARAMETER - A NULL pointer was passed in or
  1689. * the algorithm has invalid type.
  1690. * GCC_INVALID_PASSWORD - An invalid password was passed in.
  1691. *
  1692. * Side Effects:
  1693. * None.
  1694. *
  1695. * Caveats:
  1696. * None.
  1697. */
  1698. GCCError CPassword::ConvertPDUResponseAlgorithm(
  1699. PChallengeResponseAlgorithm source_algorithm,
  1700. PResponseAlgorithmInfo destination_algorithm)
  1701. {
  1702. GCCError return_value = GCC_NO_ERROR;
  1703. GCCError error_value;;
  1704. if (source_algorithm != NULL)
  1705. {
  1706. /*
  1707. * Convert the challenge response algorithm type.
  1708. */
  1709. if (source_algorithm->choice == ALGORITHM_CLEAR_PASSWORD_CHOSEN)
  1710. destination_algorithm->algorithm_type = GCC_IN_THE_CLEAR_ALGORITHM;
  1711. else if (source_algorithm->choice == NON_STANDARD_ALGORITHM_CHOSEN)
  1712. destination_algorithm->algorithm_type = GCC_NON_STANDARD_ALGORITHM;
  1713. else
  1714. {
  1715. ERROR_OUT(("CPassword::ConvertPDUResponseAlgorithm: Error: invalid password type"));
  1716. return_value = GCC_INVALID_PARAMETER;
  1717. }
  1718. }
  1719. else
  1720. {
  1721. ERROR_OUT(("CPassword::ConvertPDUResponseAlgorithm: Error: NULL source pointer."));
  1722. return_value = GCC_INVALID_PARAMETER;
  1723. }
  1724. if ((return_value == GCC_NO_ERROR) &&
  1725. (source_algorithm->choice == NON_STANDARD_ALGORITHM_CHOSEN))
  1726. {
  1727. /*
  1728. * Create a new CObjectKeyContainer object to hold the algorithm's object key
  1729. * internally.
  1730. */
  1731. DBG_SAVE_FILE_LINE
  1732. destination_algorithm->object_key = new CObjectKeyContainer(
  1733. &source_algorithm->u.non_standard_algorithm.key,
  1734. &error_value);
  1735. if (destination_algorithm->object_key == NULL)
  1736. {
  1737. ERROR_OUT(("CPassword::ConvertPDUResponseAlgorithm: Error creating new CObjectKeyContainer"));
  1738. return_value = GCC_ALLOCATION_FAILURE;
  1739. }
  1740. else if (error_value != GCC_NO_ERROR)
  1741. {
  1742. ERROR_OUT(("CPassword::ConvertPDUResponseAlgorithm: Error creating new CObjectKeyContainer"));
  1743. return_value = GCC_INVALID_PASSWORD;
  1744. }
  1745. else
  1746. {
  1747. /*
  1748. * Create a new Rogue Wave string to hold the algorithm's octet
  1749. * string internally.
  1750. */
  1751. if (NULL == (destination_algorithm->poszOctetString = ::My_strdupO2(
  1752. source_algorithm->u.non_standard_algorithm.data.value,
  1753. source_algorithm->u.non_standard_algorithm.data.length)))
  1754. {
  1755. ERROR_OUT(("CPassword::ConvertPDUResponseAlgorithm: can't create octet string in algorithm"));
  1756. return_value = GCC_ALLOCATION_FAILURE;
  1757. }
  1758. }
  1759. }
  1760. else
  1761. {
  1762. /*
  1763. * The algorithm is a standard type so initialize to NULL the pointers
  1764. * used to hold the data associated with a non-standard algorithm.
  1765. */
  1766. destination_algorithm->poszOctetString = NULL;
  1767. destination_algorithm->object_key = NULL;
  1768. }
  1769. return (return_value);
  1770. }
  1771. /*
  1772. * GCCError GetGCCChallengeRequest (
  1773. * PGCCChallengeRequest challenge_request)
  1774. *
  1775. * Private member function of CPassword.
  1776. *
  1777. * Function Description:
  1778. * This routine is used to fill in the internal "API" challenge request
  1779. * structure from the internal storage structures. This is done on a
  1780. * "lock" in order to make data available which is suitable for being
  1781. * passed back up through the API.
  1782. *
  1783. * Formal Parameters:
  1784. * challenge_request (i) The API structure to fill in with the "API"
  1785. * challenge request data.
  1786. *
  1787. * Return Value:
  1788. * GCC_NO_ERROR - No error.
  1789. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  1790. * "new" operator.
  1791. *
  1792. * Side Effects:
  1793. * None.
  1794. *
  1795. * Caveats:
  1796. * None.
  1797. */
  1798. GCCError CPassword::GetGCCChallengeRequest(PGCCChallengeRequest challenge_request)
  1799. {
  1800. GCCError return_value = GCC_NO_ERROR;
  1801. UInt i = 0;
  1802. Int j = 0;
  1803. PGCCChallengeItem api_challenge_item_ptr;
  1804. PChallengeItemInfo internal_challenge_item_ptr;
  1805. PChallengeItemMemoryInfo internal_challenge_item_memory_ptr;
  1806. UINT object_key_length;
  1807. UINT user_data_length;
  1808. /*
  1809. * Save the challenge tag and retrieve the number of challenge items.
  1810. */
  1811. challenge_request->challenge_tag = m_pInternalRequest->challenge_tag;
  1812. challenge_request->number_of_challenge_items =
  1813. (USHORT) m_pInternalRequest->ChallengeItemList.GetCount();
  1814. if (m_pInternalRequest->ChallengeItemList.GetCount() != 0)
  1815. {
  1816. /*
  1817. * Allocate the space needed for the list of pointers to GCC challenge
  1818. * items.
  1819. */
  1820. DBG_SAVE_FILE_LINE
  1821. m_pChallengeItemListMemory = new BYTE[sizeof(PGCCChallengeItem) * m_pInternalRequest->ChallengeItemList.GetCount()];
  1822. if (m_pChallengeItemListMemory != NULL)
  1823. {
  1824. PChallengeItemInfo lpChItmInfo;
  1825. /*
  1826. * Retrieve the actual pointer to memory from the Memory object
  1827. * and save it in the internal API Challenge Item list.
  1828. */
  1829. challenge_request->challenge_item_list = (GCCChallengeItem **)
  1830. m_pChallengeItemListMemory;
  1831. /*
  1832. * Initialize the pointers in the list to NULL.
  1833. */
  1834. for (i=0; i < m_pInternalRequest->ChallengeItemList.GetCount(); i++)
  1835. challenge_request->challenge_item_list[i] = NULL;
  1836. /*
  1837. * Copy the data from the internal list of "ChallengeItemInfo"
  1838. * structures into the "API" form which is a list of pointers
  1839. * to GCCChallengeItem structures.
  1840. */
  1841. m_pInternalRequest->ChallengeItemList.Reset();
  1842. while (NULL != (lpChItmInfo = m_pInternalRequest->ChallengeItemList.Iterate()))
  1843. {
  1844. /*
  1845. * Get a pointer to a new GCCChallengeItem structure.
  1846. */
  1847. DBG_SAVE_FILE_LINE
  1848. api_challenge_item_ptr = new GCCChallengeItem;
  1849. if (api_challenge_item_ptr != NULL)
  1850. {
  1851. /*
  1852. * Go ahead and put the pointer in the list and
  1853. * post-increment the loop counter.
  1854. */
  1855. challenge_request->challenge_item_list[j++] =
  1856. api_challenge_item_ptr;
  1857. /*
  1858. * Retrieve the ChallengeItemInfo structure from the Rogue
  1859. * Wave list.
  1860. */
  1861. internal_challenge_item_ptr = lpChItmInfo;
  1862. /*
  1863. * Fill in the algorithm type for the challenge response
  1864. * algorithm.
  1865. */
  1866. api_challenge_item_ptr->response_algorithm.
  1867. password_algorithm_type =
  1868. internal_challenge_item_ptr->
  1869. algorithm.algorithm_type;
  1870. /*
  1871. * The memory for the response algorithm's object key data
  1872. * and the challenge item's used data are stored in
  1873. * a ChallengeItemMemoryInfo structure so create one
  1874. * here. If the response algorithm is "clear" then the
  1875. * object key data element will not be used. The challenge
  1876. * item user data should always exist.
  1877. */
  1878. DBG_SAVE_FILE_LINE
  1879. internal_challenge_item_memory_ptr = new ChallengeItemMemoryInfo;
  1880. if (internal_challenge_item_memory_ptr != NULL)
  1881. {
  1882. /*
  1883. * Initialize the pointers in the challenge item
  1884. * memory info structure to NULL.
  1885. */
  1886. internal_challenge_item_memory_ptr->user_data_list_memory = NULL;
  1887. internal_challenge_item_memory_ptr->object_key_memory = NULL;
  1888. /*
  1889. * Insert the pointer to the new challenge item
  1890. * memory structure into the internal Rogue Wave
  1891. * list.
  1892. */
  1893. m_ChallengeItemMemoryList.Append(internal_challenge_item_memory_ptr);
  1894. }
  1895. else
  1896. {
  1897. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error creating new ChallengeItemMemoryInfo"));
  1898. return_value = GCC_ALLOCATION_FAILURE;
  1899. break;
  1900. }
  1901. if (api_challenge_item_ptr->response_algorithm.password_algorithm_type ==
  1902. GCC_NON_STANDARD_ALGORITHM)
  1903. {
  1904. /*
  1905. * Create a new GCCNonStandardParameter to put in the
  1906. * ResponseAlgorithm structure.
  1907. */
  1908. DBG_SAVE_FILE_LINE
  1909. api_challenge_item_ptr->response_algorithm.non_standard_algorithm =
  1910. new GCCNonStandardParameter;
  1911. if (api_challenge_item_ptr->response_algorithm.non_standard_algorithm == NULL)
  1912. {
  1913. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error creating new GCCNonStdParameter"));
  1914. return_value = GCC_ALLOCATION_FAILURE;
  1915. break;
  1916. }
  1917. /*
  1918. * Retrieve the API object key from the CObjectKeyContainer
  1919. * object in the ResponseAlgorithmInfo structure and
  1920. * fill in the GCCObjectKey in the non-standard
  1921. * algorithm. The CObjectKeyContainer object must be locked
  1922. * before getting the data.
  1923. */
  1924. object_key_length = internal_challenge_item_ptr->
  1925. algorithm.object_key->LockObjectKeyData ();
  1926. DBG_SAVE_FILE_LINE
  1927. internal_challenge_item_memory_ptr->object_key_memory =
  1928. new BYTE[object_key_length];
  1929. if (internal_challenge_item_memory_ptr->object_key_memory != NULL)
  1930. {
  1931. internal_challenge_item_ptr->algorithm.object_key->GetGCCObjectKeyData(
  1932. &(api_challenge_item_ptr->response_algorithm.non_standard_algorithm->object_key),
  1933. internal_challenge_item_memory_ptr->object_key_memory);
  1934. }
  1935. else
  1936. {
  1937. ERROR_OUT(("CPassword::GetGCCChallengeReq: Error Allocating Memory"));
  1938. return_value = GCC_ALLOCATION_FAILURE;
  1939. break;
  1940. }
  1941. /*
  1942. * Fill in the parameter data for the non-standard
  1943. * algorithm. This includes the octet string pointer
  1944. * and length.
  1945. */
  1946. api_challenge_item_ptr->response_algorithm.non_standard_algorithm->
  1947. parameter_data.value =
  1948. internal_challenge_item_ptr->algorithm.poszOctetString->value;
  1949. api_challenge_item_ptr->response_algorithm.non_standard_algorithm->
  1950. parameter_data.length =
  1951. internal_challenge_item_ptr->algorithm.poszOctetString->length;
  1952. }
  1953. else
  1954. {
  1955. /*
  1956. * The algorithm is not a non-standard type so set the
  1957. * non-standard pointer to NULL.
  1958. */
  1959. api_challenge_item_ptr->response_algorithm.non_standard_algorithm = NULL;
  1960. }
  1961. /*
  1962. * Retrieve the API challenge data from the CUserDataListContainer
  1963. * object. The call to GetUserDataList also returns the
  1964. * number of user data members. The CUserDataListContainer object
  1965. * must be locked before getting the data in order to
  1966. * determine how much memory to allocate to hold the data.
  1967. */
  1968. if (internal_challenge_item_ptr->challenge_data_list != NULL)
  1969. {
  1970. user_data_length = internal_challenge_item_ptr->
  1971. challenge_data_list->LockUserDataList ();
  1972. /*
  1973. * The memory for the user data is stored in the
  1974. * ChallengeItemMemoryInfo structure created above.
  1975. */
  1976. DBG_SAVE_FILE_LINE
  1977. internal_challenge_item_memory_ptr->user_data_list_memory =
  1978. new BYTE[user_data_length];
  1979. if (internal_challenge_item_memory_ptr->user_data_list_memory != NULL)
  1980. {
  1981. /*
  1982. * Retrieve the actual pointer to memory from the
  1983. * Memory object and save it in the internal user
  1984. * data memory.
  1985. */
  1986. internal_challenge_item_ptr->challenge_data_list->GetUserDataList(
  1987. &api_challenge_item_ptr->number_of_challenge_data_members,
  1988. &api_challenge_item_ptr->challenge_data_list,
  1989. internal_challenge_item_memory_ptr->user_data_list_memory);
  1990. }
  1991. else
  1992. {
  1993. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error Allocating Memory"));
  1994. return_value = GCC_ALLOCATION_FAILURE;
  1995. break;
  1996. }
  1997. }
  1998. else
  1999. {
  2000. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error no valid user data"));
  2001. return_value = GCC_ALLOCATION_FAILURE;
  2002. break;
  2003. }
  2004. }
  2005. else
  2006. {
  2007. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error creating new GCCChallengeItem"));
  2008. return_value = GCC_ALLOCATION_FAILURE;
  2009. break;
  2010. }
  2011. /*
  2012. * This is the end of the challenge item iterator loop.
  2013. */
  2014. }
  2015. }
  2016. else
  2017. {
  2018. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error Allocating Memory"));
  2019. return_value = GCC_ALLOCATION_FAILURE;
  2020. }
  2021. }
  2022. else
  2023. {
  2024. /*
  2025. * There are no challenge items in the list so set the list pointer
  2026. * to NULL.
  2027. */
  2028. challenge_request->challenge_item_list = NULL;
  2029. }
  2030. return (return_value);
  2031. }
  2032. /*
  2033. * GCCError GetGCCChallengeResponse (
  2034. * PGCCChallengeResponse challenge_response);
  2035. *
  2036. * Private member function of CPassword.
  2037. *
  2038. * Function Description:
  2039. * This routine is used to fill in the internal "API" challenge response
  2040. * structure from the internal storage structures. This is done on a
  2041. * "lock" in order to make data available which is suitable for being
  2042. * passed back up through the API.
  2043. *
  2044. * Formal Parameters:
  2045. * challenge_response (i) The API structure to fill in with the "API"
  2046. * challenge response data.
  2047. *
  2048. * Return Value:
  2049. * GCC_NO_ERROR - No error.
  2050. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  2051. * "new" operator.
  2052. *
  2053. * Side Effects:
  2054. * None.
  2055. *
  2056. * Caveats:
  2057. * None.
  2058. */
  2059. GCCError CPassword::GetGCCChallengeResponse(PGCCChallengeResponse challenge_response)
  2060. {
  2061. GCCError return_value = GCC_NO_ERROR;
  2062. UINT object_key_length;
  2063. UINT user_data_length;
  2064. challenge_response->challenge_tag = m_pInternalResponse->challenge_tag;
  2065. /*
  2066. * Fill in the algorithm type for the challenge response algorithm.
  2067. */
  2068. challenge_response->response_algorithm.password_algorithm_type =
  2069. m_pInternalResponse->algorithm.algorithm_type;
  2070. /*
  2071. * If the response algorithm is of non-standard type, create a new
  2072. * GCCNonStandardParameter to put in the ResponseAlgorithm structure.
  2073. */
  2074. if (challenge_response->response_algorithm.password_algorithm_type ==
  2075. GCC_NON_STANDARD_ALGORITHM)
  2076. {
  2077. DBG_SAVE_FILE_LINE
  2078. challenge_response->response_algorithm.non_standard_algorithm =
  2079. new GCCNonStandardParameter;
  2080. if (challenge_response->response_algorithm.non_standard_algorithm ==
  2081. NULL)
  2082. {
  2083. ERROR_OUT(("CPassword::GetGCCChallengeResponse: Error creating new GCCNonStandardParameter"));
  2084. return_value = GCC_ALLOCATION_FAILURE;
  2085. }
  2086. else
  2087. {
  2088. /*
  2089. * Retrieve the API object key from the CObjectKeyContainer object in the
  2090. * ResponseAlgorithmInfo structure and fill in the GCCObjectKey in
  2091. * the non-standard algorithm. The CObjectKeyContainer object must be
  2092. * locked before getting the data.
  2093. */
  2094. object_key_length = m_pInternalResponse->algorithm.object_key->
  2095. LockObjectKeyData ();
  2096. DBG_SAVE_FILE_LINE
  2097. m_pObjectKeyMemory = new BYTE[object_key_length];
  2098. if (m_pObjectKeyMemory != NULL)
  2099. {
  2100. m_pInternalResponse->algorithm.object_key->
  2101. GetGCCObjectKeyData (&(challenge_response->
  2102. response_algorithm.non_standard_algorithm->
  2103. object_key),
  2104. m_pObjectKeyMemory);
  2105. }
  2106. else
  2107. {
  2108. ERROR_OUT(("CPassword::GetGCCChallengeResponse: Error Allocating Memory"));
  2109. return_value = GCC_ALLOCATION_FAILURE;
  2110. }
  2111. /*
  2112. * Fill in the parameter data for the non-standard algorithm.
  2113. */
  2114. if (return_value == GCC_NO_ERROR)
  2115. {
  2116. /*
  2117. * Fill in the octet string pointer and length.
  2118. */
  2119. challenge_response->response_algorithm.non_standard_algorithm->
  2120. parameter_data.value =
  2121. m_pInternalResponse->algorithm.poszOctetString->value;
  2122. challenge_response->response_algorithm.non_standard_algorithm->
  2123. parameter_data.length =
  2124. m_pInternalResponse->algorithm.poszOctetString->length;
  2125. }
  2126. else
  2127. {
  2128. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error getting GCCObjectKeyData"));
  2129. return_value = GCC_ALLOCATION_FAILURE;
  2130. }
  2131. }
  2132. }
  2133. else
  2134. {
  2135. /*
  2136. * The algorithm in not non-standard so set the non-standard algorithm
  2137. * pointer to NULL.
  2138. */
  2139. challenge_response->response_algorithm.non_standard_algorithm = NULL;
  2140. }
  2141. /*
  2142. * Now fill in the challenge response item in the challenge response
  2143. * structure.
  2144. */
  2145. if (return_value == GCC_NO_ERROR)
  2146. {
  2147. /*
  2148. * Check to see whether the challenge response item consists of a
  2149. * password string or a set of user data. Fill in the appropriate
  2150. * part.
  2151. */
  2152. if (m_pInternalResponse->challenge_response_item.password != NULL)
  2153. {
  2154. /*
  2155. * Set the number of user data members to zero to avoid any
  2156. * confusion at the application. This should match up with the
  2157. * algorithm being set to "in the clear".
  2158. */
  2159. challenge_response->response_item.
  2160. number_of_response_data_members = 0;
  2161. challenge_response->response_item.
  2162. response_data_list = NULL;
  2163. /*
  2164. * Retrieve the API GCCPassword from the CPassword object. The
  2165. * CPassword object must be locked before getting the data.
  2166. */
  2167. if (m_pInternalResponse->challenge_response_item.
  2168. password->LockPasswordData () == GCC_NO_ERROR)
  2169. {
  2170. return_value = m_pInternalResponse->challenge_response_item.
  2171. password->GetPasswordData (&(challenge_response->
  2172. response_item.password_string));
  2173. }
  2174. else
  2175. {
  2176. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error locking CPassword"));
  2177. return_value = GCC_ALLOCATION_FAILURE;
  2178. }
  2179. }
  2180. else if (m_pInternalResponse->challenge_response_item.response_data_list != NULL)
  2181. {
  2182. /*
  2183. * Set the password string to NULL to avoid any confusion at the
  2184. * application. This should match up with the algorithm set to
  2185. * non-standard.
  2186. */
  2187. challenge_response->response_item.password_string = NULL;
  2188. /*
  2189. * Retrieve the API challenge data from the CUserDataListContainer
  2190. * object. The call to GetUserDataList also returns the
  2191. * number of user data members. The CUserDataListContainer object
  2192. * must be locked before getting the data in order to
  2193. * determine how much memory to allocate to hold the data.
  2194. */
  2195. user_data_length = m_pInternalResponse->challenge_response_item.
  2196. response_data_list->LockUserDataList ();
  2197. DBG_SAVE_FILE_LINE
  2198. m_pUserDataMemory = new BYTE[user_data_length];
  2199. if (m_pUserDataMemory != NULL)
  2200. {
  2201. /*
  2202. * Retrieve the actual pointer to memory from the Memory
  2203. * object and save it in the internal user data memory.
  2204. */
  2205. m_pInternalResponse->challenge_response_item.response_data_list->
  2206. GetUserDataList (
  2207. &challenge_response->response_item.
  2208. number_of_response_data_members,
  2209. &challenge_response->response_item.
  2210. response_data_list,
  2211. m_pUserDataMemory);
  2212. }
  2213. else
  2214. {
  2215. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error allocating memory"));
  2216. return_value = GCC_ALLOCATION_FAILURE;
  2217. }
  2218. }
  2219. else
  2220. {
  2221. ERROR_OUT(("CPassword::GetGCCChallengeRequest: Error saving response item"));
  2222. return_value = GCC_ALLOCATION_FAILURE;
  2223. }
  2224. }
  2225. return (return_value);
  2226. }
  2227. /*
  2228. * GCCError GetChallengeRequestPDU (
  2229. * PChallengeRequest challenge_request);
  2230. *
  2231. * Private member function of CPassword.
  2232. *
  2233. * Function Description:
  2234. * This routine converts internal challenge request data to "PDU" form.
  2235. *
  2236. * Formal Parameters:
  2237. * challenge_request (i) The PDU structure to fill in with the
  2238. * challenge request data.
  2239. *
  2240. * Return Value:
  2241. * GCC_NO_ERROR - No error.
  2242. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  2243. * "new" operator.
  2244. * GCC_INVALID_PARAMETER - The algorithm type was not set
  2245. * properly.
  2246. *
  2247. * Side Effects:
  2248. * None.
  2249. *
  2250. * Caveats:
  2251. * None.
  2252. */
  2253. GCCError CPassword::GetChallengeRequestPDU(PChallengeRequest challenge_request)
  2254. {
  2255. GCCError return_value = GCC_NO_ERROR;
  2256. PSetOfChallengeItems new_set_of_challenge_items;
  2257. PSetOfChallengeItems old_set_of_challenge_items;
  2258. DWORD number_of_items;
  2259. PChallengeItemInfo internal_challenge_item_ptr;
  2260. /*
  2261. * Fill in the challenge tag.
  2262. */
  2263. challenge_request->challenge_tag = m_pInternalRequest->challenge_tag;
  2264. /*
  2265. * Initialize the set pointers to NULL in order to detect the first time
  2266. * through the iterator loop.
  2267. */
  2268. challenge_request->set_of_challenge_items = NULL;
  2269. old_set_of_challenge_items = NULL;
  2270. /*
  2271. * Retrieve the number of challenge items in the internal list.
  2272. */
  2273. number_of_items = m_pInternalRequest->ChallengeItemList.GetCount();
  2274. if (number_of_items > 0)
  2275. {
  2276. PChallengeItemInfo lpChItmInfo;
  2277. /*
  2278. * Iterate through the internal list of challenge items, creating a
  2279. * new "PDU" SetOfChallengeItems for each and filling it in.
  2280. */
  2281. m_pInternalRequest->ChallengeItemList.Reset();
  2282. while (NULL != (lpChItmInfo = m_pInternalRequest->ChallengeItemList.Iterate()))
  2283. {
  2284. DBG_SAVE_FILE_LINE
  2285. new_set_of_challenge_items = new SetOfChallengeItems;
  2286. /*
  2287. * If an allocation failure occurs, call the routine which will
  2288. * iterate through the list freeing any data which had been
  2289. * allocated.
  2290. */
  2291. if (new_set_of_challenge_items == NULL)
  2292. {
  2293. ERROR_OUT(("CPassword::GetChallengeRequestPDU: Allocation error, cleaning up"));
  2294. return_value = GCC_ALLOCATION_FAILURE;
  2295. FreeChallengeRequestPDU ();
  2296. break;
  2297. }
  2298. /*
  2299. * The first time through, set the PDU structure pointer equal
  2300. * to the first SetOfChallengeItems created. On subsequent loops,
  2301. * set the structure's "next" pointer equal to the new structure.
  2302. */
  2303. if (challenge_request->set_of_challenge_items == NULL)
  2304. {
  2305. challenge_request->set_of_challenge_items =
  2306. new_set_of_challenge_items;
  2307. }
  2308. else
  2309. old_set_of_challenge_items->next = new_set_of_challenge_items;
  2310. /*
  2311. * Save the newly created set and initialize the new "next"
  2312. * pointer to NULL in case this is the last time through the loop.
  2313. */
  2314. old_set_of_challenge_items = new_set_of_challenge_items;
  2315. new_set_of_challenge_items->next = NULL;
  2316. /*
  2317. * Retrieve the ChallengeItemInfo structure from the Rogue
  2318. * Wave list and fill in the "PDU" challenge item structure from
  2319. * the internal challenge item structure.
  2320. */
  2321. internal_challenge_item_ptr = lpChItmInfo;
  2322. return_value = ConvertInternalChallengeItemToPDU (
  2323. internal_challenge_item_ptr,
  2324. &new_set_of_challenge_items->value);
  2325. /*
  2326. * Cleanup if an error has occurred.
  2327. */
  2328. if (return_value != GCC_NO_ERROR)
  2329. {
  2330. FreeChallengeRequestPDU ();
  2331. }
  2332. }
  2333. }
  2334. else
  2335. {
  2336. ERROR_OUT(("CPassword::GetChallengeRequestPDU: Error no items"));
  2337. }
  2338. return (return_value);
  2339. }
  2340. /*
  2341. * GCCError ConvertInternalChallengeItemToPDU(
  2342. * PChallengeItemInfo internal_challenge_item,
  2343. * PChallengeItem pdu_challenge_item)
  2344. *
  2345. * Private member function of CPassword.
  2346. *
  2347. * Function Description:
  2348. * This routine converts an internal ChallengeItemInfo structure into
  2349. * the "PDU" form of a ChallengeItem structure.
  2350. *
  2351. * Formal Parameters:
  2352. * internal_challenge_item (i) The internal challenge item to convert.
  2353. * pdu_challenge_item (o) The output PDU form of the challenge
  2354. * item.
  2355. *
  2356. * Return Value:
  2357. * GCC_NO_ERROR - No error.
  2358. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  2359. * "new" operator.
  2360. * GCC_INVALID_PARAMETER - The algorithm type was not set
  2361. * properly.
  2362. *
  2363. * Side Effects:
  2364. * None.
  2365. *
  2366. * Caveats:
  2367. * None.
  2368. */
  2369. GCCError CPassword::ConvertInternalChallengeItemToPDU(
  2370. PChallengeItemInfo internal_challenge_item,
  2371. PChallengeItem pdu_challenge_item)
  2372. {
  2373. GCCError return_value = GCC_NO_ERROR;
  2374. /*
  2375. * First convert the algorithm.
  2376. */
  2377. if (internal_challenge_item->algorithm.algorithm_type ==
  2378. GCC_IN_THE_CLEAR_ALGORITHM)
  2379. {
  2380. pdu_challenge_item->response_algorithm.choice =
  2381. ALGORITHM_CLEAR_PASSWORD_CHOSEN;
  2382. }
  2383. else if (internal_challenge_item->algorithm.algorithm_type ==
  2384. GCC_NON_STANDARD_ALGORITHM)
  2385. {
  2386. pdu_challenge_item->response_algorithm.choice =
  2387. NON_STANDARD_ALGORITHM_CHOSEN;
  2388. /*
  2389. * Retrieve the "PDU" object key data from the internal CObjectKeyContainer
  2390. * object.
  2391. */
  2392. if (internal_challenge_item->algorithm.object_key->
  2393. GetObjectKeyDataPDU (
  2394. &pdu_challenge_item->response_algorithm.u.
  2395. non_standard_algorithm.key) == GCC_NO_ERROR)
  2396. {
  2397. /*
  2398. * Retrieve the non-standard parameter data from the internal
  2399. * algorithm octet string.
  2400. */
  2401. pdu_challenge_item->response_algorithm.u.non_standard_algorithm.data.value =
  2402. internal_challenge_item->algorithm.poszOctetString->value;
  2403. pdu_challenge_item->response_algorithm.u.non_standard_algorithm.data.length =
  2404. internal_challenge_item->algorithm.poszOctetString->length;
  2405. }
  2406. else
  2407. {
  2408. ERROR_OUT(("CPassword::ConvertInternalChallengeItemToPDU: Error getting ObjKeyData"));
  2409. return_value = GCC_ALLOCATION_FAILURE;
  2410. }
  2411. }
  2412. else
  2413. {
  2414. ERROR_OUT(("CPassword::ConvertInternalChallengeItemToPDU: Error bad algorithm type"));
  2415. return_value = GCC_INVALID_PARAMETER;
  2416. }
  2417. /*
  2418. * Now retrieve the set of user data.
  2419. */
  2420. if (return_value == GCC_NO_ERROR)
  2421. {
  2422. return_value = internal_challenge_item->challenge_data_list->
  2423. GetUserDataPDU (&pdu_challenge_item->set_of_challenge_data);
  2424. }
  2425. return (return_value);
  2426. }
  2427. /*
  2428. * GCCError GetChallengeResponsePDU (
  2429. * PChallengeResponse challenge_response);
  2430. *
  2431. * Private member function of CPassword.
  2432. *
  2433. * Function Description:
  2434. * This routine converts internal challenge response data to "PDU" form.
  2435. *
  2436. * Formal Parameters:
  2437. * challenge_response (i) The PDU structure to fill in with the
  2438. * challenge response data.
  2439. *
  2440. * Return Value:
  2441. * GCC_NO_ERROR - No error.
  2442. * GCC_ALLOCATION_FAILURE - Error creating an object using the
  2443. * "new" operator.
  2444. * GCC_INVALID_PASSWORD - The form of the password is not
  2445. * valid.
  2446. * GCC_INVALID_PARAMETER - The algorithm type was not set
  2447. * properly.
  2448. *
  2449. * Side Effects:
  2450. * None.
  2451. *
  2452. * Caveats:
  2453. * None.
  2454. */
  2455. GCCError CPassword::GetChallengeResponsePDU(PChallengeResponse challenge_response)
  2456. {
  2457. GCCError return_value = GCC_NO_ERROR;
  2458. /*
  2459. * Fill in the challenge tag.
  2460. */
  2461. challenge_response->challenge_tag = m_pInternalResponse->challenge_tag;
  2462. /*
  2463. * Fill in the response algorithm.
  2464. */
  2465. if (m_pInternalResponse->algorithm.algorithm_type ==
  2466. GCC_IN_THE_CLEAR_ALGORITHM)
  2467. {
  2468. challenge_response->response_algorithm.choice =
  2469. ALGORITHM_CLEAR_PASSWORD_CHOSEN;
  2470. /*
  2471. * Now convert the challenge response item. The challenge response item
  2472. * will consist of either a password string or a set of user data.
  2473. */
  2474. if (m_pInternalResponse->challenge_response_item.password != NULL)
  2475. {
  2476. /*
  2477. * If the password string exists, set the "PDU" choice and retrieve
  2478. * the password selector data from the internal CPassword object.
  2479. */
  2480. challenge_response->response_item.choice = PASSWORD_STRING_CHOSEN;
  2481. return_value= m_pInternalResponse->challenge_response_item.password->
  2482. GetPasswordSelectorPDU (&challenge_response->response_item.
  2483. u.password_string);
  2484. }
  2485. else
  2486. return_value = GCC_INVALID_PASSWORD;
  2487. }
  2488. else if (m_pInternalResponse->algorithm.algorithm_type ==
  2489. GCC_NON_STANDARD_ALGORITHM)
  2490. {
  2491. challenge_response->response_algorithm.choice =
  2492. NON_STANDARD_ALGORITHM_CHOSEN;
  2493. /*
  2494. * Retrieve the "PDU" object key data from the internal CObjectKeyContainer
  2495. * object.
  2496. */
  2497. if (m_pInternalResponse->algorithm.object_key->
  2498. GetObjectKeyDataPDU (
  2499. &challenge_response->response_algorithm.u.
  2500. non_standard_algorithm.key) == GCC_NO_ERROR)
  2501. {
  2502. /*
  2503. * Retrieve the non-standard parameter data from the internal
  2504. * algorithm octet string.
  2505. */
  2506. challenge_response->response_algorithm.u.non_standard_algorithm.data.value =
  2507. m_pInternalResponse->algorithm.poszOctetString->value;
  2508. challenge_response->response_algorithm.u.non_standard_algorithm.data.length =
  2509. m_pInternalResponse->algorithm.poszOctetString->length;
  2510. if (m_pInternalResponse->challenge_response_item.response_data_list != NULL)
  2511. {
  2512. /*
  2513. * If the response data list exists, set the "PDU" choice and
  2514. * retrieve the response data from the internal
  2515. * CUserDataListContainer object.
  2516. */
  2517. challenge_response->response_item.choice =
  2518. SET_OF_RESPONSE_DATA_CHOSEN;
  2519. return_value = m_pInternalResponse->challenge_response_item.
  2520. response_data_list->GetUserDataPDU (
  2521. &challenge_response->response_item.u.
  2522. set_of_response_data);
  2523. }
  2524. else
  2525. return_value = GCC_INVALID_PASSWORD;
  2526. }
  2527. else
  2528. {
  2529. return_value = GCC_ALLOCATION_FAILURE;
  2530. ERROR_OUT(("CPassword::GetChallengeResponsePDU: Error getting ObjKeyData"));
  2531. }
  2532. }
  2533. else
  2534. {
  2535. ERROR_OUT(("CPassword::GetChallengeResponsePDU: Error bad algorithm type"));
  2536. return_value = GCC_INVALID_PARAMETER;
  2537. }
  2538. return (return_value);
  2539. }
  2540. /*
  2541. * void FreeChallengeRequestPDU ();
  2542. *
  2543. * Private member function of CPassword.
  2544. *
  2545. * Function Description:
  2546. * This routine is used to free any "PDU" data allocated for the
  2547. * challenge request structure.
  2548. *
  2549. * Formal Parameters:
  2550. * None.
  2551. *
  2552. * Return Value:
  2553. * None.
  2554. *
  2555. * Side Effects:
  2556. * None.
  2557. *
  2558. * Caveats:
  2559. * None.
  2560. */
  2561. void CPassword::FreeChallengeRequestPDU(void)
  2562. {
  2563. PSetOfChallengeItems set_of_challenge_items;
  2564. PSetOfChallengeItems next_set_of_challenge_items;
  2565. PChallengeItemInfo challenge_item_ptr;
  2566. PChallengeRequest challenge_request;
  2567. /*
  2568. * Retrieve the challenge request pointer from the internally maintained
  2569. * PasswordChallengeRequestResponse structure and delete each set of
  2570. * challenge items which was created.
  2571. */
  2572. challenge_request = &m_ChallengeResponsePDU.u.challenge_request_response.
  2573. challenge_request;
  2574. if (challenge_request != NULL)
  2575. {
  2576. if (challenge_request->set_of_challenge_items == NULL)
  2577. {
  2578. ERROR_OUT(("CPassword::FreeChallengeRequestPDU: NULL ptr passed"));
  2579. }
  2580. else
  2581. {
  2582. set_of_challenge_items = challenge_request->set_of_challenge_items;
  2583. while (1)
  2584. {
  2585. if (set_of_challenge_items == NULL)
  2586. break;
  2587. next_set_of_challenge_items = set_of_challenge_items->next;
  2588. delete set_of_challenge_items;
  2589. set_of_challenge_items = next_set_of_challenge_items;
  2590. }
  2591. }
  2592. }
  2593. else
  2594. {
  2595. WARNING_OUT(("CPassword::FreeChallengeRequestPDU: NULL pointer passed"));
  2596. }
  2597. /*
  2598. * Loop through the internal list of challenge items, freeing the data
  2599. * associated with each challenge item structure contained in the list.
  2600. */
  2601. m_pInternalRequest->ChallengeItemList.Reset();
  2602. while (NULL != (challenge_item_ptr = m_pInternalRequest->ChallengeItemList.Iterate()))
  2603. {
  2604. /*
  2605. * Retrieve the ChallengeItemInfo structure from the Rogue
  2606. * Wave list and use the CUserDataListContainer object contained in the
  2607. * structure to free the PDU user data. Also use the CObjectKeyContainer
  2608. * object contained in the algorithm structure to free the PDU
  2609. * data associated with the object key.
  2610. */
  2611. if (challenge_item_ptr != NULL)
  2612. {
  2613. if (challenge_item_ptr->algorithm.object_key != NULL)
  2614. {
  2615. challenge_item_ptr->algorithm.object_key->FreeObjectKeyDataPDU();
  2616. }
  2617. if (challenge_item_ptr->challenge_data_list != NULL)
  2618. {
  2619. challenge_item_ptr->challenge_data_list->FreeUserDataListPDU();
  2620. }
  2621. }
  2622. }
  2623. }
  2624. /*
  2625. * void FreeChallengeResponsePDU ();
  2626. *
  2627. * Private member function of CPassword.
  2628. *
  2629. * Function Description:
  2630. * This routine is used to free any "PDU" data allocated for the
  2631. * challenge response structure.
  2632. *
  2633. * Formal Parameters:
  2634. * None.
  2635. *
  2636. * Return Value:
  2637. * None.
  2638. *
  2639. * Side Effects:
  2640. * None.
  2641. *
  2642. * Caveats:
  2643. * None.
  2644. */
  2645. void CPassword::FreeChallengeResponsePDU(void)
  2646. {
  2647. PChallengeResponse challenge_response;
  2648. /*
  2649. * Retrieve the challenge response pointer from the internally maintained
  2650. * PasswordChallengeRequestResponse structure. If it is not equal to NULL
  2651. * then we know PDU response data has been allocated which must be freed.
  2652. */
  2653. challenge_response = &m_ChallengeResponsePDU.u.challenge_request_response.
  2654. challenge_response;
  2655. if ((challenge_response != NULL) && (m_pInternalResponse != NULL))
  2656. {
  2657. if (m_pInternalResponse->algorithm.object_key != NULL)
  2658. m_pInternalResponse->algorithm.object_key->FreeObjectKeyDataPDU ();
  2659. if (m_pInternalResponse->challenge_response_item.password != NULL)
  2660. {
  2661. m_pInternalResponse->challenge_response_item.
  2662. password->FreePasswordChallengeResponsePDU ();
  2663. }
  2664. if (m_pInternalResponse->challenge_response_item.
  2665. response_data_list != NULL)
  2666. {
  2667. m_pInternalResponse->challenge_response_item.
  2668. response_data_list->FreeUserDataListPDU ();
  2669. }
  2670. }
  2671. }
  2672. /*
  2673. * void FreeAPIPasswordData ();
  2674. *
  2675. * Private member function of CPassword.
  2676. *
  2677. * Function Description:
  2678. * This routine is used to free any data allocated by this container to
  2679. * hold "API" data.
  2680. *
  2681. * Formal Parameters:
  2682. * None.
  2683. *
  2684. * Return Value:
  2685. * None.
  2686. *
  2687. * Side Effects:
  2688. * None.
  2689. *
  2690. * Caveats:
  2691. * None.
  2692. */
  2693. void CPassword::FreeAPIPasswordData(void)
  2694. {
  2695. PGCCChallengeItem challenge_item_ptr;
  2696. PChallengeItemInfo challenge_item_info_ptr;
  2697. PChallengeItemMemoryInfo challenge_item_memory_info;
  2698. USHORT i;
  2699. /*
  2700. * Delete any "API" memory associated with the challenge request if
  2701. * it exists.
  2702. */
  2703. if (m_pChallengeResponse->u.challenge_request_response.
  2704. challenge_request != NULL)
  2705. {
  2706. for (i=0; i<m_pChallengeResponse->u.
  2707. challenge_request_response.challenge_request->
  2708. number_of_challenge_items; i++)
  2709. {
  2710. challenge_item_ptr = m_pChallengeResponse->u.
  2711. challenge_request_response.challenge_request->
  2712. challenge_item_list[i];
  2713. if (challenge_item_ptr != NULL)
  2714. {
  2715. /*
  2716. * Delete the non-standard algorithm memory.
  2717. */
  2718. delete challenge_item_ptr->response_algorithm.non_standard_algorithm;
  2719. delete challenge_item_ptr;
  2720. }
  2721. }
  2722. delete m_pChallengeResponse->u.challenge_request_response.
  2723. challenge_request;
  2724. }
  2725. /*
  2726. * Unlock any memory locked for the challenge request information.
  2727. */
  2728. if (m_pInternalRequest != NULL)
  2729. {
  2730. /*
  2731. * Set up an iterator in order to loop through the list of challenge
  2732. * items, freeing up any allocated memory.
  2733. */
  2734. m_pInternalRequest->ChallengeItemList.Reset();
  2735. while (NULL != (challenge_item_info_ptr = m_pInternalRequest->ChallengeItemList.Iterate()))
  2736. {
  2737. /*
  2738. * Unlock any memory being referenced in the ChallengeItemInfo
  2739. * structure.
  2740. */
  2741. if (challenge_item_info_ptr->algorithm.object_key != NULL)
  2742. {
  2743. challenge_item_info_ptr->algorithm.object_key->
  2744. UnLockObjectKeyData ();
  2745. }
  2746. if (challenge_item_info_ptr->challenge_data_list != NULL)
  2747. {
  2748. challenge_item_info_ptr->challenge_data_list->
  2749. UnLockUserDataList ();
  2750. }
  2751. }
  2752. }
  2753. /*
  2754. * Call the Memory Manager to free the memory allocated to hold the
  2755. * challenge request data.
  2756. */
  2757. while (NULL != (challenge_item_memory_info = m_ChallengeItemMemoryList.Get()))
  2758. {
  2759. delete challenge_item_memory_info->user_data_list_memory;
  2760. delete challenge_item_memory_info->object_key_memory;
  2761. delete challenge_item_memory_info;
  2762. }
  2763. /*
  2764. * Delete any memory associated with the challenge response if
  2765. * it exists.
  2766. */
  2767. if (m_pChallengeResponse->u.challenge_request_response.
  2768. challenge_response != NULL)
  2769. {
  2770. /*
  2771. * Delete any memory associated with the non-standard algorithm and
  2772. * then delete the challenge response structure.
  2773. */
  2774. delete m_pChallengeResponse->u.challenge_request_response.
  2775. challenge_response->response_algorithm.non_standard_algorithm;
  2776. delete m_pChallengeResponse->u.challenge_request_response.
  2777. challenge_response;
  2778. }
  2779. /*
  2780. * Unlock any memory allocated for the challenge response information.
  2781. */
  2782. if (m_pInternalResponse != NULL)
  2783. {
  2784. if (m_pInternalResponse->algorithm.object_key != NULL)
  2785. {
  2786. m_pInternalResponse->algorithm.object_key->UnLockObjectKeyData();
  2787. }
  2788. if (m_pInternalResponse->challenge_response_item.password != NULL)
  2789. {
  2790. m_pInternalResponse->challenge_response_item.password->
  2791. UnLockPasswordData ();
  2792. }
  2793. if (m_pInternalResponse->challenge_response_item.
  2794. response_data_list != NULL)
  2795. {
  2796. m_pInternalResponse->challenge_response_item.response_data_list->
  2797. UnLockUserDataList ();
  2798. }
  2799. }
  2800. /*
  2801. * Call the Memory Manager to free the memory allocated to hold the
  2802. * challenge response data.
  2803. */
  2804. delete m_pUserDataMemory;
  2805. m_pUserDataMemory = NULL;
  2806. delete m_pObjectKeyMemory;
  2807. m_pObjectKeyMemory = NULL;
  2808. /*
  2809. * Call the Memory Manager to free the memory allocated to hold the
  2810. * challenge request challenge item pointers.
  2811. */
  2812. delete m_pChallengeItemListMemory;
  2813. m_pChallengeItemListMemory = NULL;
  2814. /*
  2815. * Delete the challenge password structure and set the pointer to NULL.
  2816. */
  2817. delete m_pChallengeResponse;
  2818. m_pChallengeResponse = NULL;
  2819. }