digest_sspi.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2014 - 2016, Steve Holme, <steve_holme@hotmail.com>.
  9. * Copyright (C) 2015 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
  10. *
  11. * This software is licensed as described in the file COPYING, which
  12. * you should have received as part of this distribution. The terms
  13. * are also available at https://curl.haxx.se/docs/copyright.html.
  14. *
  15. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  16. * copies of the Software, and permit persons to whom the Software is
  17. * furnished to do so, under the terms of the COPYING file.
  18. *
  19. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  20. * KIND, either express or implied.
  21. *
  22. * RFC2831 DIGEST-MD5 authentication
  23. *
  24. ***************************************************************************/
  25. #include "curl_setup.h"
  26. #if defined(USE_WINDOWS_SSPI) && !defined(CURL_DISABLE_CRYPTO_AUTH)
  27. #include <curl/curl.h>
  28. #include "vauth/vauth.h"
  29. #include "vauth/digest.h"
  30. #include "urldata.h"
  31. #include "curl_base64.h"
  32. #include "warnless.h"
  33. #include "curl_multibyte.h"
  34. #include "sendf.h"
  35. #include "strdup.h"
  36. #include "strcase.h"
  37. /* The last #include files should be: */
  38. #include "curl_memory.h"
  39. #include "memdebug.h"
  40. /*
  41. * Curl_auth_is_digest_supported()
  42. *
  43. * This is used to evaluate if DIGEST is supported.
  44. *
  45. * Parameters: None
  46. *
  47. * Returns TRUE if DIGEST is supported by Windows SSPI.
  48. */
  49. bool Curl_auth_is_digest_supported(void)
  50. {
  51. PSecPkgInfo SecurityPackage;
  52. SECURITY_STATUS status;
  53. /* Query the security package for Digest */
  54. status = s_pSecFn->QuerySecurityPackageInfo((TCHAR *) TEXT(SP_NAME_DIGEST),
  55. &SecurityPackage);
  56. return (status == SEC_E_OK ? TRUE : FALSE);
  57. }
  58. /*
  59. * Curl_auth_create_digest_md5_message()
  60. *
  61. * This is used to generate an already encoded DIGEST-MD5 response message
  62. * ready for sending to the recipient.
  63. *
  64. * Parameters:
  65. *
  66. * data [in] - The session handle.
  67. * chlg64 [in] - The base64 encoded challenge message.
  68. * userp [in] - The user name in the format User or Domain\User.
  69. * passdwp [in] - The user's password.
  70. * service [in] - The service type such as http, smtp, pop or imap.
  71. * outptr [in/out] - The address where a pointer to newly allocated memory
  72. * holding the result will be stored upon completion.
  73. * outlen [out] - The length of the output message.
  74. *
  75. * Returns CURLE_OK on success.
  76. */
  77. CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
  78. const char *chlg64,
  79. const char *userp,
  80. const char *passwdp,
  81. const char *service,
  82. char **outptr, size_t *outlen)
  83. {
  84. CURLcode result = CURLE_OK;
  85. TCHAR *spn = NULL;
  86. size_t chlglen = 0;
  87. size_t token_max = 0;
  88. unsigned char *input_token = NULL;
  89. unsigned char *output_token = NULL;
  90. CredHandle credentials;
  91. CtxtHandle context;
  92. PSecPkgInfo SecurityPackage;
  93. SEC_WINNT_AUTH_IDENTITY identity;
  94. SEC_WINNT_AUTH_IDENTITY *p_identity;
  95. SecBuffer chlg_buf;
  96. SecBuffer resp_buf;
  97. SecBufferDesc chlg_desc;
  98. SecBufferDesc resp_desc;
  99. SECURITY_STATUS status;
  100. unsigned long attrs;
  101. TimeStamp expiry; /* For Windows 9x compatibility of SSPI calls */
  102. /* Decode the base-64 encoded challenge message */
  103. if(strlen(chlg64) && *chlg64 != '=') {
  104. result = Curl_base64_decode(chlg64, &input_token, &chlglen);
  105. if(result)
  106. return result;
  107. }
  108. /* Ensure we have a valid challenge message */
  109. if(!input_token) {
  110. infof(data, "DIGEST-MD5 handshake failure (empty challenge message)\n");
  111. return CURLE_BAD_CONTENT_ENCODING;
  112. }
  113. /* Query the security package for DigestSSP */
  114. status = s_pSecFn->QuerySecurityPackageInfo((TCHAR *) TEXT(SP_NAME_DIGEST),
  115. &SecurityPackage);
  116. if(status != SEC_E_OK) {
  117. free(input_token);
  118. return CURLE_NOT_BUILT_IN;
  119. }
  120. token_max = SecurityPackage->cbMaxToken;
  121. /* Release the package buffer as it is not required anymore */
  122. s_pSecFn->FreeContextBuffer(SecurityPackage);
  123. /* Allocate our response buffer */
  124. output_token = malloc(token_max);
  125. if(!output_token) {
  126. free(input_token);
  127. return CURLE_OUT_OF_MEMORY;
  128. }
  129. /* Generate our SPN */
  130. spn = Curl_auth_build_spn(service, data->easy_conn->host.name, NULL);
  131. if(!spn) {
  132. free(output_token);
  133. free(input_token);
  134. return CURLE_OUT_OF_MEMORY;
  135. }
  136. if(userp && *userp) {
  137. /* Populate our identity structure */
  138. result = Curl_create_sspi_identity(userp, passwdp, &identity);
  139. if(result) {
  140. free(spn);
  141. free(output_token);
  142. free(input_token);
  143. return result;
  144. }
  145. /* Allow proper cleanup of the identity structure */
  146. p_identity = &identity;
  147. }
  148. else
  149. /* Use the current Windows user */
  150. p_identity = NULL;
  151. /* Acquire our credentials handle */
  152. status = s_pSecFn->AcquireCredentialsHandle(NULL,
  153. (TCHAR *) TEXT(SP_NAME_DIGEST),
  154. SECPKG_CRED_OUTBOUND, NULL,
  155. p_identity, NULL, NULL,
  156. &credentials, &expiry);
  157. if(status != SEC_E_OK) {
  158. Curl_sspi_free_identity(p_identity);
  159. free(spn);
  160. free(output_token);
  161. free(input_token);
  162. return CURLE_LOGIN_DENIED;
  163. }
  164. /* Setup the challenge "input" security buffer */
  165. chlg_desc.ulVersion = SECBUFFER_VERSION;
  166. chlg_desc.cBuffers = 1;
  167. chlg_desc.pBuffers = &chlg_buf;
  168. chlg_buf.BufferType = SECBUFFER_TOKEN;
  169. chlg_buf.pvBuffer = input_token;
  170. chlg_buf.cbBuffer = curlx_uztoul(chlglen);
  171. /* Setup the response "output" security buffer */
  172. resp_desc.ulVersion = SECBUFFER_VERSION;
  173. resp_desc.cBuffers = 1;
  174. resp_desc.pBuffers = &resp_buf;
  175. resp_buf.BufferType = SECBUFFER_TOKEN;
  176. resp_buf.pvBuffer = output_token;
  177. resp_buf.cbBuffer = curlx_uztoul(token_max);
  178. /* Generate our response message */
  179. status = s_pSecFn->InitializeSecurityContext(&credentials, NULL, spn,
  180. 0, 0, 0, &chlg_desc, 0,
  181. &context, &resp_desc, &attrs,
  182. &expiry);
  183. if(status == SEC_I_COMPLETE_NEEDED ||
  184. status == SEC_I_COMPLETE_AND_CONTINUE)
  185. s_pSecFn->CompleteAuthToken(&credentials, &resp_desc);
  186. else if(status != SEC_E_OK && status != SEC_I_CONTINUE_NEEDED) {
  187. s_pSecFn->FreeCredentialsHandle(&credentials);
  188. Curl_sspi_free_identity(p_identity);
  189. free(spn);
  190. free(output_token);
  191. free(input_token);
  192. return CURLE_RECV_ERROR;
  193. }
  194. /* Base64 encode the response */
  195. result = Curl_base64_encode(data, (char *) output_token, resp_buf.cbBuffer,
  196. outptr, outlen);
  197. /* Free our handles */
  198. s_pSecFn->DeleteSecurityContext(&context);
  199. s_pSecFn->FreeCredentialsHandle(&credentials);
  200. /* Free the identity structure */
  201. Curl_sspi_free_identity(p_identity);
  202. /* Free the SPN */
  203. free(spn);
  204. /* Free the response buffer */
  205. free(output_token);
  206. /* Free the decoded challenge message */
  207. free(input_token);
  208. return result;
  209. }
  210. /*
  211. * Curl_override_sspi_http_realm()
  212. *
  213. * This is used to populate the domain in a SSPI identity structure
  214. * The realm is extracted from the challenge message and used as the
  215. * domain if it is not already explicitly set.
  216. *
  217. * Parameters:
  218. *
  219. * chlg [in] - The challenge message.
  220. * identity [in/out] - The identity structure.
  221. *
  222. * Returns CURLE_OK on success.
  223. */
  224. CURLcode Curl_override_sspi_http_realm(const char *chlg,
  225. SEC_WINNT_AUTH_IDENTITY *identity)
  226. {
  227. xcharp_u domain, dup_domain;
  228. /* If domain is blank or unset, check challenge message for realm */
  229. if(!identity->Domain || !identity->DomainLength) {
  230. for(;;) {
  231. char value[DIGEST_MAX_VALUE_LENGTH];
  232. char content[DIGEST_MAX_CONTENT_LENGTH];
  233. /* Pass all additional spaces here */
  234. while(*chlg && ISSPACE(*chlg))
  235. chlg++;
  236. /* Extract a value=content pair */
  237. if(Curl_auth_digest_get_pair(chlg, value, content, &chlg)) {
  238. if(strcasecompare(value, "realm")) {
  239. /* Setup identity's domain and length */
  240. domain.tchar_ptr = Curl_convert_UTF8_to_tchar((char *) content);
  241. if(!domain.tchar_ptr)
  242. return CURLE_OUT_OF_MEMORY;
  243. dup_domain.tchar_ptr = _tcsdup(domain.tchar_ptr);
  244. if(!dup_domain.tchar_ptr) {
  245. Curl_unicodefree(domain.tchar_ptr);
  246. return CURLE_OUT_OF_MEMORY;
  247. }
  248. free(identity->Domain);
  249. identity->Domain = dup_domain.tbyte_ptr;
  250. identity->DomainLength = curlx_uztoul(_tcslen(dup_domain.tchar_ptr));
  251. dup_domain.tchar_ptr = NULL;
  252. Curl_unicodefree(domain.tchar_ptr);
  253. }
  254. else {
  255. /* Unknown specifier, ignore it! */
  256. }
  257. }
  258. else
  259. break; /* We're done here */
  260. /* Pass all additional spaces here */
  261. while(*chlg && ISSPACE(*chlg))
  262. chlg++;
  263. /* Allow the list to be comma-separated */
  264. if(',' == *chlg)
  265. chlg++;
  266. }
  267. }
  268. return CURLE_OK;
  269. }
  270. /*
  271. * Curl_auth_decode_digest_http_message()
  272. *
  273. * This is used to decode a HTTP DIGEST challenge message into the separate
  274. * attributes.
  275. *
  276. * Parameters:
  277. *
  278. * chlg [in] - The challenge message.
  279. * digest [in/out] - The digest data struct being used and modified.
  280. *
  281. * Returns CURLE_OK on success.
  282. */
  283. CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
  284. struct digestdata *digest)
  285. {
  286. size_t chlglen = strlen(chlg);
  287. /* We had an input token before so if there's another one now that means we
  288. provided bad credentials in the previous request or it's stale. */
  289. if(digest->input_token) {
  290. bool stale = false;
  291. const char *p = chlg;
  292. /* Check for the 'stale' directive */
  293. for(;;) {
  294. char value[DIGEST_MAX_VALUE_LENGTH];
  295. char content[DIGEST_MAX_CONTENT_LENGTH];
  296. while(*p && ISSPACE(*p))
  297. p++;
  298. if(!Curl_auth_digest_get_pair(p, value, content, &p))
  299. break;
  300. if(strcasecompare(value, "stale") &&
  301. strcasecompare(content, "true")) {
  302. stale = true;
  303. break;
  304. }
  305. while(*p && ISSPACE(*p))
  306. p++;
  307. if(',' == *p)
  308. p++;
  309. }
  310. if(stale)
  311. Curl_auth_digest_cleanup(digest);
  312. else
  313. return CURLE_LOGIN_DENIED;
  314. }
  315. /* Store the challenge for use later */
  316. digest->input_token = (BYTE *) Curl_memdup(chlg, chlglen + 1);
  317. if(!digest->input_token)
  318. return CURLE_OUT_OF_MEMORY;
  319. digest->input_token_len = chlglen;
  320. return CURLE_OK;
  321. }
  322. /*
  323. * Curl_auth_create_digest_http_message()
  324. *
  325. * This is used to generate a HTTP DIGEST response message ready for sending
  326. * to the recipient.
  327. *
  328. * Parameters:
  329. *
  330. * data [in] - The session handle.
  331. * userp [in] - The user name in the format User or Domain\User.
  332. * passdwp [in] - The user's password.
  333. * request [in] - The HTTP request.
  334. * uripath [in] - The path of the HTTP uri.
  335. * digest [in/out] - The digest data struct being used and modified.
  336. * outptr [in/out] - The address where a pointer to newly allocated memory
  337. * holding the result will be stored upon completion.
  338. * outlen [out] - The length of the output message.
  339. *
  340. * Returns CURLE_OK on success.
  341. */
  342. CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
  343. const char *userp,
  344. const char *passwdp,
  345. const unsigned char *request,
  346. const unsigned char *uripath,
  347. struct digestdata *digest,
  348. char **outptr, size_t *outlen)
  349. {
  350. size_t token_max;
  351. char *resp;
  352. BYTE *output_token;
  353. size_t output_token_len = 0;
  354. PSecPkgInfo SecurityPackage;
  355. SecBuffer chlg_buf[5];
  356. SecBufferDesc chlg_desc;
  357. SECURITY_STATUS status;
  358. (void) data;
  359. /* Query the security package for DigestSSP */
  360. status = s_pSecFn->QuerySecurityPackageInfo((TCHAR *) TEXT(SP_NAME_DIGEST),
  361. &SecurityPackage);
  362. if(status != SEC_E_OK)
  363. return CURLE_NOT_BUILT_IN;
  364. token_max = SecurityPackage->cbMaxToken;
  365. /* Release the package buffer as it is not required anymore */
  366. s_pSecFn->FreeContextBuffer(SecurityPackage);
  367. /* Allocate the output buffer according to the max token size as indicated
  368. by the security package */
  369. output_token = malloc(token_max);
  370. if(!output_token) {
  371. return CURLE_OUT_OF_MEMORY;
  372. }
  373. /* If the user/passwd that was used to make the identity for http_context
  374. has changed then delete that context. */
  375. if((userp && !digest->user) || (!userp && digest->user) ||
  376. (passwdp && !digest->passwd) || (!passwdp && digest->passwd) ||
  377. (userp && digest->user && strcmp(userp, digest->user)) ||
  378. (passwdp && digest->passwd && strcmp(passwdp, digest->passwd))) {
  379. if(digest->http_context) {
  380. s_pSecFn->DeleteSecurityContext(digest->http_context);
  381. Curl_safefree(digest->http_context);
  382. }
  383. Curl_safefree(digest->user);
  384. Curl_safefree(digest->passwd);
  385. }
  386. if(digest->http_context) {
  387. chlg_desc.ulVersion = SECBUFFER_VERSION;
  388. chlg_desc.cBuffers = 5;
  389. chlg_desc.pBuffers = chlg_buf;
  390. chlg_buf[0].BufferType = SECBUFFER_TOKEN;
  391. chlg_buf[0].pvBuffer = NULL;
  392. chlg_buf[0].cbBuffer = 0;
  393. chlg_buf[1].BufferType = SECBUFFER_PKG_PARAMS;
  394. chlg_buf[1].pvBuffer = (void *) request;
  395. chlg_buf[1].cbBuffer = curlx_uztoul(strlen((const char *) request));
  396. chlg_buf[2].BufferType = SECBUFFER_PKG_PARAMS;
  397. chlg_buf[2].pvBuffer = (void *) uripath;
  398. chlg_buf[2].cbBuffer = curlx_uztoul(strlen((const char *) uripath));
  399. chlg_buf[3].BufferType = SECBUFFER_PKG_PARAMS;
  400. chlg_buf[3].pvBuffer = NULL;
  401. chlg_buf[3].cbBuffer = 0;
  402. chlg_buf[4].BufferType = SECBUFFER_PADDING;
  403. chlg_buf[4].pvBuffer = output_token;
  404. chlg_buf[4].cbBuffer = curlx_uztoul(token_max);
  405. status = s_pSecFn->MakeSignature(digest->http_context, 0, &chlg_desc, 0);
  406. if(status == SEC_E_OK)
  407. output_token_len = chlg_buf[4].cbBuffer;
  408. else { /* delete the context so a new one can be made */
  409. infof(data, "digest_sspi: MakeSignature failed, error 0x%08lx\n",
  410. (long)status);
  411. s_pSecFn->DeleteSecurityContext(digest->http_context);
  412. Curl_safefree(digest->http_context);
  413. }
  414. }
  415. if(!digest->http_context) {
  416. CredHandle credentials;
  417. SEC_WINNT_AUTH_IDENTITY identity;
  418. SEC_WINNT_AUTH_IDENTITY *p_identity;
  419. SecBuffer resp_buf;
  420. SecBufferDesc resp_desc;
  421. unsigned long attrs;
  422. TimeStamp expiry; /* For Windows 9x compatibility of SSPI calls */
  423. TCHAR *spn;
  424. /* free the copy of user/passwd used to make the previous identity */
  425. Curl_safefree(digest->user);
  426. Curl_safefree(digest->passwd);
  427. if(userp && *userp) {
  428. /* Populate our identity structure */
  429. if(Curl_create_sspi_identity(userp, passwdp, &identity)) {
  430. free(output_token);
  431. return CURLE_OUT_OF_MEMORY;
  432. }
  433. /* Populate our identity domain */
  434. if(Curl_override_sspi_http_realm((const char *) digest->input_token,
  435. &identity)) {
  436. free(output_token);
  437. return CURLE_OUT_OF_MEMORY;
  438. }
  439. /* Allow proper cleanup of the identity structure */
  440. p_identity = &identity;
  441. }
  442. else
  443. /* Use the current Windows user */
  444. p_identity = NULL;
  445. if(userp) {
  446. digest->user = strdup(userp);
  447. if(!digest->user) {
  448. free(output_token);
  449. return CURLE_OUT_OF_MEMORY;
  450. }
  451. }
  452. if(passwdp) {
  453. digest->passwd = strdup(passwdp);
  454. if(!digest->passwd) {
  455. free(output_token);
  456. Curl_safefree(digest->user);
  457. return CURLE_OUT_OF_MEMORY;
  458. }
  459. }
  460. /* Acquire our credentials handle */
  461. status = s_pSecFn->AcquireCredentialsHandle(NULL,
  462. (TCHAR *) TEXT(SP_NAME_DIGEST),
  463. SECPKG_CRED_OUTBOUND, NULL,
  464. p_identity, NULL, NULL,
  465. &credentials, &expiry);
  466. if(status != SEC_E_OK) {
  467. Curl_sspi_free_identity(p_identity);
  468. free(output_token);
  469. return CURLE_LOGIN_DENIED;
  470. }
  471. /* Setup the challenge "input" security buffer if present */
  472. chlg_desc.ulVersion = SECBUFFER_VERSION;
  473. chlg_desc.cBuffers = 3;
  474. chlg_desc.pBuffers = chlg_buf;
  475. chlg_buf[0].BufferType = SECBUFFER_TOKEN;
  476. chlg_buf[0].pvBuffer = digest->input_token;
  477. chlg_buf[0].cbBuffer = curlx_uztoul(digest->input_token_len);
  478. chlg_buf[1].BufferType = SECBUFFER_PKG_PARAMS;
  479. chlg_buf[1].pvBuffer = (void *) request;
  480. chlg_buf[1].cbBuffer = curlx_uztoul(strlen((const char *) request));
  481. chlg_buf[2].BufferType = SECBUFFER_PKG_PARAMS;
  482. chlg_buf[2].pvBuffer = NULL;
  483. chlg_buf[2].cbBuffer = 0;
  484. /* Setup the response "output" security buffer */
  485. resp_desc.ulVersion = SECBUFFER_VERSION;
  486. resp_desc.cBuffers = 1;
  487. resp_desc.pBuffers = &resp_buf;
  488. resp_buf.BufferType = SECBUFFER_TOKEN;
  489. resp_buf.pvBuffer = output_token;
  490. resp_buf.cbBuffer = curlx_uztoul(token_max);
  491. spn = Curl_convert_UTF8_to_tchar((char *) uripath);
  492. if(!spn) {
  493. s_pSecFn->FreeCredentialsHandle(&credentials);
  494. Curl_sspi_free_identity(p_identity);
  495. free(output_token);
  496. return CURLE_OUT_OF_MEMORY;
  497. }
  498. /* Allocate our new context handle */
  499. digest->http_context = calloc(1, sizeof(CtxtHandle));
  500. if(!digest->http_context)
  501. return CURLE_OUT_OF_MEMORY;
  502. /* Generate our response message */
  503. status = s_pSecFn->InitializeSecurityContext(&credentials, NULL,
  504. spn,
  505. ISC_REQ_USE_HTTP_STYLE, 0, 0,
  506. &chlg_desc, 0,
  507. digest->http_context,
  508. &resp_desc, &attrs, &expiry);
  509. Curl_unicodefree(spn);
  510. if(status == SEC_I_COMPLETE_NEEDED ||
  511. status == SEC_I_COMPLETE_AND_CONTINUE)
  512. s_pSecFn->CompleteAuthToken(&credentials, &resp_desc);
  513. else if(status != SEC_E_OK && status != SEC_I_CONTINUE_NEEDED) {
  514. s_pSecFn->FreeCredentialsHandle(&credentials);
  515. Curl_sspi_free_identity(p_identity);
  516. free(output_token);
  517. Curl_safefree(digest->http_context);
  518. return CURLE_OUT_OF_MEMORY;
  519. }
  520. output_token_len = resp_buf.cbBuffer;
  521. s_pSecFn->FreeCredentialsHandle(&credentials);
  522. Curl_sspi_free_identity(p_identity);
  523. }
  524. resp = malloc(output_token_len + 1);
  525. if(!resp) {
  526. free(output_token);
  527. return CURLE_OUT_OF_MEMORY;
  528. }
  529. /* Copy the generated response */
  530. memcpy(resp, output_token, output_token_len);
  531. resp[output_token_len] = 0;
  532. /* Return the response */
  533. *outptr = resp;
  534. *outlen = output_token_len;
  535. /* Free the response buffer */
  536. free(output_token);
  537. return CURLE_OK;
  538. }
  539. /*
  540. * Curl_auth_digest_cleanup()
  541. *
  542. * This is used to clean up the digest specific data.
  543. *
  544. * Parameters:
  545. *
  546. * digest [in/out] - The digest data struct being cleaned up.
  547. *
  548. */
  549. void Curl_auth_digest_cleanup(struct digestdata *digest)
  550. {
  551. /* Free the input token */
  552. Curl_safefree(digest->input_token);
  553. /* Reset any variables */
  554. digest->input_token_len = 0;
  555. /* Delete security context */
  556. if(digest->http_context) {
  557. s_pSecFn->DeleteSecurityContext(digest->http_context);
  558. Curl_safefree(digest->http_context);
  559. }
  560. /* Free the copy of user/passwd used to make the identity for http_context */
  561. Curl_safefree(digest->user);
  562. Curl_safefree(digest->passwd);
  563. }
  564. #endif /* USE_WINDOWS_SSPI && !CURL_DISABLE_CRYPTO_AUTH */