hashswf.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Copyright (C) 2009-2010 Howard Chu
  3. *
  4. * This file is part of librtmp.
  5. *
  6. * librtmp is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as
  8. * published by the Free Software Foundation; either version 2.1,
  9. * or (at your option) any later version.
  10. *
  11. * librtmp is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with librtmp see the file COPYING. If not, write to
  18. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  19. * Boston, MA 02110-1301, USA.
  20. * http://www.gnu.org/copyleft/lgpl.html
  21. */
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <ctype.h>
  26. #include <time.h>
  27. #include "rtmp_sys.h"
  28. #include "log.h"
  29. #include "http.h"
  30. #ifdef CRYPTO
  31. #ifdef USE_POLARSSL
  32. #include <polarssl/sha2.h>
  33. #ifndef SHA256_DIGEST_LENGTH
  34. #define SHA256_DIGEST_LENGTH 32
  35. #endif
  36. #define HMAC_CTX sha2_context
  37. #define HMAC_setup(ctx, key, len) sha2_hmac_starts(&ctx, (unsigned char *)key, len, 0)
  38. #define HMAC_crunch(ctx, buf, len) sha2_hmac_update(&ctx, buf, len)
  39. #define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; sha2_hmac_finish(&ctx, dig)
  40. #define HMAC_close(ctx)
  41. #elif defined(USE_GNUTLS)
  42. #include <nettle/hmac.h>
  43. #ifndef SHA256_DIGEST_LENGTH
  44. #define SHA256_DIGEST_LENGTH 32
  45. #endif
  46. #undef HMAC_CTX
  47. #define HMAC_CTX struct hmac_sha256_ctx
  48. #define HMAC_setup(ctx, key, len) hmac_sha256_set_key(&ctx, len, key)
  49. #define HMAC_crunch(ctx, buf, len) hmac_sha256_update(&ctx, len, buf)
  50. #define HMAC_finish(ctx, dig, dlen) dlen = SHA256_DIGEST_LENGTH; hmac_sha256_digest(&ctx, SHA256_DIGEST_LENGTH, dig)
  51. #define HMAC_close(ctx)
  52. #else /* USE_OPENSSL */
  53. #include <openssl/ssl.h>
  54. #include <openssl/sha.h>
  55. #include <openssl/hmac.h>
  56. #include <openssl/rc4.h>
  57. #define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char *)key, len, EVP_sha256(), 0)
  58. #define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, (unsigned char *)buf, len)
  59. #define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, (unsigned char *)dig, &dlen);
  60. #define HMAC_close(ctx) HMAC_CTX_cleanup(&ctx)
  61. #endif
  62. extern void RTMP_TLS_Init();
  63. extern TLS_CTX RTMP_TLS_ctx;
  64. #include <zlib.h>
  65. #endif /* CRYPTO */
  66. #define AGENT "Mozilla/5.0"
  67. HTTPResult
  68. HTTP_get(struct HTTP_ctx *http, const char *url, HTTP_read_callback *cb)
  69. {
  70. char *host, *path;
  71. char *p1, *p2;
  72. char hbuf[256];
  73. int port = 80;
  74. #ifdef CRYPTO
  75. int ssl = 0;
  76. #endif
  77. int hlen, flen = 0;
  78. int rc, i;
  79. int len_known;
  80. HTTPResult ret = HTTPRES_OK;
  81. struct sockaddr_in sa;
  82. RTMPSockBuf sb = {0};
  83. http->status = -1;
  84. memset(&sa, 0, sizeof(struct sockaddr_in));
  85. sa.sin_family = AF_INET;
  86. /* we only handle http here */
  87. if (strncasecmp(url, "http", 4))
  88. return HTTPRES_BAD_REQUEST;
  89. if (url[4] == 's')
  90. {
  91. #ifdef CRYPTO
  92. ssl = 1;
  93. port = 443;
  94. if (!RTMP_TLS_ctx)
  95. RTMP_TLS_Init();
  96. #else
  97. return HTTPRES_BAD_REQUEST;
  98. #endif
  99. }
  100. p1 = strchr(url + 4, ':');
  101. if (!p1 || strncmp(p1, "://", 3))
  102. return HTTPRES_BAD_REQUEST;
  103. host = p1 + 3;
  104. path = strchr(host, '/');
  105. hlen = path - host;
  106. strncpy(hbuf, host, hlen);
  107. hbuf[hlen] = '\0';
  108. host = hbuf;
  109. p1 = strrchr(host, ':');
  110. if (p1)
  111. {
  112. *p1++ = '\0';
  113. port = atoi(p1);
  114. }
  115. sa.sin_addr.s_addr = inet_addr(host);
  116. if (sa.sin_addr.s_addr == INADDR_NONE)
  117. {
  118. struct hostent *hp = gethostbyname(host);
  119. if (!hp || !hp->h_addr)
  120. return HTTPRES_LOST_CONNECTION;
  121. sa.sin_addr = *(struct in_addr *)hp->h_addr;
  122. }
  123. sa.sin_port = htons(port);
  124. sb.sb_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  125. if (sb.sb_socket == -1)
  126. return HTTPRES_LOST_CONNECTION;
  127. i =
  128. sprintf(sb.sb_buf,
  129. "GET %s HTTP/1.0\r\nUser-Agent: %s\r\nHost: %s\r\nReferer: %.*s\r\n",
  130. path, AGENT, host, (int)(path - url + 1), url);
  131. if (http->date[0])
  132. i += sprintf(sb.sb_buf + i, "If-Modified-Since: %s\r\n", http->date);
  133. i += sprintf(sb.sb_buf + i, "\r\n");
  134. if (connect
  135. (sb.sb_socket, (struct sockaddr *)&sa, sizeof(struct sockaddr)) < 0)
  136. {
  137. ret = HTTPRES_LOST_CONNECTION;
  138. goto leave;
  139. }
  140. #ifdef CRYPTO
  141. if (ssl)
  142. {
  143. #ifdef NO_SSL
  144. RTMP_Log(RTMP_LOGERROR, "%s, No SSL/TLS support", __FUNCTION__);
  145. ret = HTTPRES_BAD_REQUEST;
  146. goto leave;
  147. #else
  148. TLS_client(RTMP_TLS_ctx, sb.sb_ssl);
  149. TLS_setfd(sb.sb_ssl, sb.sb_socket);
  150. if (TLS_connect(sb.sb_ssl) < 0)
  151. {
  152. RTMP_Log(RTMP_LOGERROR, "%s, TLS_Connect failed", __FUNCTION__);
  153. ret = HTTPRES_LOST_CONNECTION;
  154. goto leave;
  155. }
  156. #endif
  157. }
  158. #endif
  159. RTMPSockBuf_Send(&sb, sb.sb_buf, i);
  160. /* set timeout */
  161. #define HTTP_TIMEOUT 5
  162. {
  163. SET_RCVTIMEO(tv, HTTP_TIMEOUT);
  164. if (setsockopt
  165. (sb.sb_socket, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)))
  166. {
  167. RTMP_Log(RTMP_LOGERROR, "%s, Setting socket timeout to %ds failed!",
  168. __FUNCTION__, HTTP_TIMEOUT);
  169. }
  170. }
  171. sb.sb_size = 0;
  172. sb.sb_timedout = FALSE;
  173. if (RTMPSockBuf_Fill(&sb) < 1)
  174. {
  175. ret = HTTPRES_LOST_CONNECTION;
  176. goto leave;
  177. }
  178. if (strncmp(sb.sb_buf, "HTTP/1", 6))
  179. {
  180. ret = HTTPRES_BAD_REQUEST;
  181. goto leave;
  182. }
  183. p1 = strchr(sb.sb_buf, ' ');
  184. rc = atoi(p1 + 1);
  185. http->status = rc;
  186. if (rc >= 300)
  187. {
  188. if (rc == 304)
  189. {
  190. ret = HTTPRES_OK_NOT_MODIFIED;
  191. goto leave;
  192. }
  193. else if (rc == 404)
  194. ret = HTTPRES_NOT_FOUND;
  195. else if (rc >= 500)
  196. ret = HTTPRES_SERVER_ERROR;
  197. else if (rc >= 400)
  198. ret = HTTPRES_BAD_REQUEST;
  199. else
  200. ret = HTTPRES_REDIRECTED;
  201. }
  202. p1 = memchr(sb.sb_buf, '\n', sb.sb_size);
  203. if (!p1)
  204. {
  205. ret = HTTPRES_BAD_REQUEST;
  206. goto leave;
  207. }
  208. sb.sb_start = p1 + 1;
  209. sb.sb_size -= sb.sb_start - sb.sb_buf;
  210. while ((p2 = memchr(sb.sb_start, '\r', sb.sb_size)))
  211. {
  212. if (*sb.sb_start == '\r')
  213. {
  214. sb.sb_start += 2;
  215. sb.sb_size -= 2;
  216. break;
  217. }
  218. else
  219. if (!strncasecmp
  220. (sb.sb_start, "Content-Length: ", sizeof("Content-Length: ") - 1))
  221. {
  222. flen = atoi(sb.sb_start + sizeof("Content-Length: ") - 1);
  223. }
  224. else
  225. if (!strncasecmp
  226. (sb.sb_start, "Last-Modified: ", sizeof("Last-Modified: ") - 1))
  227. {
  228. *p2 = '\0';
  229. strcpy(http->date, sb.sb_start + sizeof("Last-Modified: ") - 1);
  230. }
  231. p2 += 2;
  232. sb.sb_size -= p2 - sb.sb_start;
  233. sb.sb_start = p2;
  234. if (sb.sb_size < 1)
  235. {
  236. if (RTMPSockBuf_Fill(&sb) < 1)
  237. {
  238. ret = HTTPRES_LOST_CONNECTION;
  239. goto leave;
  240. }
  241. }
  242. }
  243. len_known = flen > 0;
  244. while ((!len_known || flen > 0) &&
  245. (sb.sb_size > 0 || RTMPSockBuf_Fill(&sb) > 0))
  246. {
  247. cb(sb.sb_start, 1, sb.sb_size, http->data);
  248. if (len_known)
  249. flen -= sb.sb_size;
  250. http->size += sb.sb_size;
  251. sb.sb_size = 0;
  252. }
  253. if (flen > 0)
  254. ret = HTTPRES_LOST_CONNECTION;
  255. leave:
  256. RTMPSockBuf_Close(&sb);
  257. return ret;
  258. }
  259. #ifdef CRYPTO
  260. #define CHUNK 16384
  261. struct info
  262. {
  263. z_stream *zs;
  264. HMAC_CTX ctx;
  265. int first;
  266. int zlib;
  267. int size;
  268. };
  269. static size_t
  270. swfcrunch(void *ptr, size_t size, size_t nmemb, void *stream)
  271. {
  272. struct info *i = stream;
  273. char *p = ptr;
  274. size_t len = size * nmemb;
  275. if (i->first)
  276. {
  277. i->first = 0;
  278. /* compressed? */
  279. if (!strncmp(p, "CWS", 3))
  280. {
  281. *p = 'F';
  282. i->zlib = 1;
  283. }
  284. HMAC_crunch(i->ctx, (unsigned char *)p, 8);
  285. p += 8;
  286. len -= 8;
  287. i->size = 8;
  288. }
  289. if (i->zlib)
  290. {
  291. unsigned char out[CHUNK];
  292. i->zs->next_in = (unsigned char *)p;
  293. i->zs->avail_in = len;
  294. do
  295. {
  296. i->zs->avail_out = CHUNK;
  297. i->zs->next_out = out;
  298. inflate(i->zs, Z_NO_FLUSH);
  299. len = CHUNK - i->zs->avail_out;
  300. i->size += len;
  301. HMAC_crunch(i->ctx, out, len);
  302. }
  303. while (i->zs->avail_out == 0);
  304. }
  305. else
  306. {
  307. i->size += len;
  308. HMAC_crunch(i->ctx, (unsigned char *)p, len);
  309. }
  310. return size * nmemb;
  311. }
  312. static int tzoff;
  313. static int tzchecked;
  314. #define JAN02_1980 318340800
  315. static const char *monthtab[12] = { "Jan", "Feb", "Mar",
  316. "Apr", "May", "Jun",
  317. "Jul", "Aug", "Sep",
  318. "Oct", "Nov", "Dec"
  319. };
  320. static const char *days[] =
  321. { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  322. /* Parse an HTTP datestamp into Unix time */
  323. static time_t
  324. make_unix_time(char *s)
  325. {
  326. struct tm time;
  327. int i, ysub = 1900, fmt = 0;
  328. char *month;
  329. char *n;
  330. time_t res;
  331. if (s[3] != ' ')
  332. {
  333. fmt = 1;
  334. if (s[3] != ',')
  335. ysub = 0;
  336. }
  337. for (n = s; *n; ++n)
  338. if (*n == '-' || *n == ':')
  339. *n = ' ';
  340. time.tm_mon = 0;
  341. n = strchr(s, ' ');
  342. if (fmt)
  343. {
  344. /* Day, DD-MMM-YYYY HH:MM:SS GMT */
  345. time.tm_mday = strtol(n + 1, &n, 0);
  346. month = n + 1;
  347. n = strchr(month, ' ');
  348. time.tm_year = strtol(n + 1, &n, 0);
  349. time.tm_hour = strtol(n + 1, &n, 0);
  350. time.tm_min = strtol(n + 1, &n, 0);
  351. time.tm_sec = strtol(n + 1, NULL, 0);
  352. }
  353. else
  354. {
  355. /* Unix ctime() format. Does not conform to HTTP spec. */
  356. /* Day MMM DD HH:MM:SS YYYY */
  357. month = n + 1;
  358. n = strchr(month, ' ');
  359. while (isspace(*n))
  360. n++;
  361. time.tm_mday = strtol(n, &n, 0);
  362. time.tm_hour = strtol(n + 1, &n, 0);
  363. time.tm_min = strtol(n + 1, &n, 0);
  364. time.tm_sec = strtol(n + 1, &n, 0);
  365. time.tm_year = strtol(n + 1, NULL, 0);
  366. }
  367. if (time.tm_year > 100)
  368. time.tm_year -= ysub;
  369. for (i = 0; i < 12; i++)
  370. if (!strncasecmp(month, monthtab[i], 3))
  371. {
  372. time.tm_mon = i;
  373. break;
  374. }
  375. time.tm_isdst = 0; /* daylight saving is never in effect in GMT */
  376. /* this is normally the value of extern int timezone, but some
  377. * braindead C libraries don't provide it.
  378. */
  379. if (!tzchecked)
  380. {
  381. struct tm *tc;
  382. time_t then = JAN02_1980;
  383. tc = localtime(&then);
  384. tzoff = (12 - tc->tm_hour) * 3600 + tc->tm_min * 60 + tc->tm_sec;
  385. tzchecked = 1;
  386. }
  387. res = mktime(&time);
  388. /* Unfortunately, mktime() assumes the input is in local time,
  389. * not GMT, so we have to correct it here.
  390. */
  391. if (res != -1)
  392. res += tzoff;
  393. return res;
  394. }
  395. /* Convert a Unix time to a network time string
  396. * Weekday, DD-MMM-YYYY HH:MM:SS GMT
  397. */
  398. static void
  399. strtime(time_t * t, char *s)
  400. {
  401. struct tm *tm;
  402. tm = gmtime((time_t *) t);
  403. sprintf(s, "%s, %02d %s %d %02d:%02d:%02d GMT",
  404. days[tm->tm_wday], tm->tm_mday, monthtab[tm->tm_mon],
  405. tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec);
  406. }
  407. #define HEX2BIN(a) (((a)&0x40)?((a)&0xf)+9:((a)&0xf))
  408. int
  409. RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
  410. int age)
  411. {
  412. FILE *f = NULL;
  413. char *path, date[64], cctim[64];
  414. long pos = 0;
  415. time_t ctim = -1, cnow;
  416. int i, got = 0, ret = 0;
  417. unsigned int hlen;
  418. struct info in = { 0 };
  419. struct HTTP_ctx http = { 0 };
  420. HTTPResult httpres;
  421. z_stream zs = { 0 };
  422. AVal home, hpre;
  423. date[0] = '\0';
  424. #ifdef _WIN32
  425. #ifdef XBMC4XBOX
  426. hpre.av_val = "Q:";
  427. hpre.av_len = 2;
  428. home.av_val = "\\UserData";
  429. #else
  430. hpre.av_val = getenv("HOMEDRIVE");
  431. hpre.av_len = strlen(hpre.av_val);
  432. home.av_val = getenv("HOMEPATH");
  433. #endif
  434. #define DIRSEP "\\"
  435. #else /* !_WIN32 */
  436. hpre.av_val = "";
  437. hpre.av_len = 0;
  438. home.av_val = getenv("HOME");
  439. #define DIRSEP "/"
  440. #endif
  441. if (!home.av_val)
  442. home.av_val = ".";
  443. home.av_len = strlen(home.av_val);
  444. /* SWF hash info is cached in a fixed-format file.
  445. * url: <url of SWF file>
  446. * ctim: HTTP datestamp of when we last checked it.
  447. * date: HTTP datestamp of the SWF's last modification.
  448. * size: SWF size in hex
  449. * hash: SWF hash in hex
  450. *
  451. * These fields must be present in this order. All fields
  452. * besides URL are fixed size.
  453. */
  454. path = malloc(hpre.av_len + home.av_len + sizeof(DIRSEP ".swfinfo"));
  455. sprintf(path, "%s%s" DIRSEP ".swfinfo", hpre.av_val, home.av_val);
  456. f = fopen(path, "r+");
  457. while (f)
  458. {
  459. char buf[4096], *file, *p;
  460. file = strchr(url, '/');
  461. if (!file)
  462. break;
  463. file += 2;
  464. file = strchr(file, '/');
  465. if (!file)
  466. break;
  467. file++;
  468. hlen = file - url;
  469. p = strrchr(file, '/');
  470. if (p)
  471. file = p;
  472. else
  473. file--;
  474. while (fgets(buf, sizeof(buf), f))
  475. {
  476. char *r1;
  477. got = 0;
  478. if (strncmp(buf, "url: ", 5))
  479. continue;
  480. if (strncmp(buf + 5, url, hlen))
  481. continue;
  482. r1 = strrchr(buf, '/');
  483. i = strlen(r1);
  484. r1[--i] = '\0';
  485. if (strncmp(r1, file, i))
  486. continue;
  487. pos = ftell(f);
  488. while (got < 4 && fgets(buf, sizeof(buf), f))
  489. {
  490. if (!strncmp(buf, "size: ", 6))
  491. {
  492. *size = strtol(buf + 6, NULL, 16);
  493. got++;
  494. }
  495. else if (!strncmp(buf, "hash: ", 6))
  496. {
  497. unsigned char *ptr = hash, *in = (unsigned char *)buf + 6;
  498. int l = strlen((char *)in) - 1;
  499. for (i = 0; i < l; i += 2)
  500. *ptr++ = (HEX2BIN(in[i]) << 4) | HEX2BIN(in[i + 1]);
  501. got++;
  502. }
  503. else if (!strncmp(buf, "date: ", 6))
  504. {
  505. buf[strlen(buf) - 1] = '\0';
  506. strncpy(date, buf + 6, sizeof(date));
  507. got++;
  508. }
  509. else if (!strncmp(buf, "ctim: ", 6))
  510. {
  511. buf[strlen(buf) - 1] = '\0';
  512. ctim = make_unix_time(buf + 6);
  513. got++;
  514. }
  515. else if (!strncmp(buf, "url: ", 5))
  516. break;
  517. }
  518. break;
  519. }
  520. break;
  521. }
  522. cnow = time(NULL);
  523. /* If we got a cache time, see if it's young enough to use directly */
  524. if (age && ctim > 0)
  525. {
  526. ctim = cnow - ctim;
  527. ctim /= 3600 * 24; /* seconds to days */
  528. if (ctim < age) /* ok, it's new enough */
  529. goto out;
  530. }
  531. in.first = 1;
  532. HMAC_setup(in.ctx, "Genuine Adobe Flash Player 001", 30);
  533. inflateInit(&zs);
  534. in.zs = &zs;
  535. http.date = date;
  536. http.data = &in;
  537. httpres = HTTP_get(&http, url, swfcrunch);
  538. inflateEnd(&zs);
  539. if (httpres != HTTPRES_OK && httpres != HTTPRES_OK_NOT_MODIFIED)
  540. {
  541. ret = -1;
  542. if (httpres == HTTPRES_LOST_CONNECTION)
  543. RTMP_Log(RTMP_LOGERROR, "%s: connection lost while downloading swfurl %s",
  544. __FUNCTION__, url);
  545. else if (httpres == HTTPRES_NOT_FOUND)
  546. RTMP_Log(RTMP_LOGERROR, "%s: swfurl %s not found", __FUNCTION__, url);
  547. else
  548. RTMP_Log(RTMP_LOGERROR, "%s: couldn't contact swfurl %s (HTTP error %d)",
  549. __FUNCTION__, url, http.status);
  550. }
  551. else
  552. {
  553. if (got && pos)
  554. fseek(f, pos, SEEK_SET);
  555. else
  556. {
  557. char *q;
  558. if (!f)
  559. f = fopen(path, "w");
  560. if (!f)
  561. {
  562. int err = errno;
  563. RTMP_Log(RTMP_LOGERROR,
  564. "%s: couldn't open %s for writing, errno %d (%s)",
  565. __FUNCTION__, path, err, strerror(err));
  566. ret = -1;
  567. goto out;
  568. }
  569. fseek(f, 0, SEEK_END);
  570. q = strchr(url, '?');
  571. if (q)
  572. i = q - url;
  573. else
  574. i = strlen(url);
  575. fprintf(f, "url: %.*s\n", i, url);
  576. }
  577. strtime(&cnow, cctim);
  578. fprintf(f, "ctim: %s\n", cctim);
  579. if (!in.first)
  580. {
  581. HMAC_finish(in.ctx, hash, hlen);
  582. *size = in.size;
  583. fprintf(f, "date: %s\n", date);
  584. fprintf(f, "size: %08x\n", in.size);
  585. fprintf(f, "hash: ");
  586. for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
  587. fprintf(f, "%02x", hash[i]);
  588. fprintf(f, "\n");
  589. }
  590. }
  591. HMAC_close(in.ctx);
  592. out:
  593. free(path);
  594. if (f)
  595. fclose(f);
  596. return ret;
  597. }
  598. #else
  599. int
  600. RTMP_HashSWF(const char *url, unsigned int *size, unsigned char *hash,
  601. int age)
  602. {
  603. return -1;
  604. }
  605. #endif