parse_key_file.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. /*
  2. * Copyright (C) 2011-2017 Intel Corporation. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. *
  8. * * Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * * Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in
  12. * the documentation and/or other materials provided with the
  13. * distribution.
  14. * * Neither the name of Intel Corporation nor the names of its
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  22. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  24. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  25. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  26. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  28. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. */
  31. /**
  32. * File:
  33. * parse_key_file.cpp
  34. * Description:
  35. * Parse the RSA key file that user inputs
  36. * to get the key type and rsa structure.
  37. */
  38. #include "parse_key_file.h"
  39. #include "se_trace.h"
  40. #include "arch.h"
  41. #include "util_st.h"
  42. #include <stdio.h>
  43. #include <stdlib.h>
  44. #include <string.h>
  45. #include <assert.h>
  46. #include <limits.h>
  47. #include <string>
  48. #include <algorithm>
  49. #include <fstream>
  50. //N_SIZE+E_SIZE+D_SIZE+P_SIZE+Q_SIZE+DMP1_SIZE+DMQ1_SIZE+sizeof(inverseQ)
  51. #define PRI_COMPONENTS_SIZE (N_SIZE_IN_BYTES + E_SIZE_IN_BYTES + D_SIZE_IN_BYTES + P_SIZE_IN_BYTES *5)
  52. #define PUB_CONPONENTS_SIZE (N_SIZE_IN_BYTES + E_SIZE_IN_BYTES) //N_SIZE+E_SIZE
  53. #define SEQUENCE_TAG_VALUE 0x30
  54. #define INTEGER_TAG_VALUE 0x02
  55. #define BIT_STRING_TAG_VALUE 0x03
  56. #define NULL_TAG_VALUE 0x05
  57. #define OID_TAG_VALUE 0x06
  58. #define CHECK_RETRUN(value) {if(0 == (value)) return 0;}
  59. //base64Decode
  60. // to decode the base64 string and put it to the result.
  61. //Parameters
  62. // [IN] aSrc: the source string coded in base64
  63. // srcLen: length of the source string
  64. // [OUT] result: point to the decoded string
  65. //Return Value
  66. // int---The length of the decoded string
  67. static int base64_decode(const unsigned char* aSrc, size_t srcLen, unsigned char* result)
  68. { //two reason will cause the function return 0: 1- The input parameters are wrong, 2- srcLen<4
  69. static char index_64[256] = {
  70. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  71. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  72. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63,
  73. 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64,
  74. 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
  75. 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64,
  76. 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
  77. 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64,
  78. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  79. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  80. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  81. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  82. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  83. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  84. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
  85. 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64
  86. };
  87. CHECK_RETRUN(aSrc);
  88. CHECK_RETRUN(srcLen);
  89. CHECK_RETRUN(result);
  90. unsigned char ch1 = 0, ch2 = 0, ch3 = 0, ch4 = 0;
  91. unsigned char *ptr = result;
  92. for (unsigned int i = 0; i < srcLen; ++i)
  93. {
  94. ch1 = index_64[aSrc[i]];
  95. if(ch1 == 64)
  96. continue;
  97. ch2 = index_64[aSrc[++i]];
  98. if(ch2 == 64)
  99. continue;
  100. *(ptr++) = (unsigned char)(ch1<<2 | ch2>>4);
  101. ch3 = index_64[aSrc[++i]];
  102. if(aSrc[i] == '=' || ch3 == 64)
  103. continue;
  104. *(ptr++) = (unsigned char)(ch2<<4 | ch3>>2);
  105. ch4 = index_64[aSrc[++i]];
  106. if(aSrc[i] == '=' || ch4 == 64)
  107. continue;
  108. *(ptr++) = (unsigned char)(ch3<<6 | ch4);
  109. }
  110. return (int)(ptr - result);
  111. }
  112. static void convert_string(unsigned char *str, int len)
  113. {
  114. assert(str != NULL&&len>0);
  115. char temp = 0;
  116. for(int i=0; i<len/2; i++)
  117. {
  118. temp = str[i];
  119. str[i] = str[len-1-i];
  120. str[len-1-i] = temp;
  121. }
  122. }
  123. static bool parse_tag_and_length(const unsigned char *begin, const unsigned char *end, uint8_t expect_tag, size_t *len_bytes, size_t *value_bytes)
  124. {
  125. assert(NULL != begin && NULL != end && NULL != len_bytes && NULL != value_bytes);
  126. if (begin[0] != expect_tag)
  127. return false;
  128. size_t tvb = 0, tlb = 0; // 'temporary value bytes' and 'temporary length bytes'
  129. const unsigned char *lbegin = begin + 1;
  130. if (!(lbegin[0] & 0x80))
  131. {
  132. // Value bytes <= 127
  133. tvb = lbegin[0];
  134. tlb += 1; // length is only one bytes
  135. }
  136. else if (lbegin[0] == 0x81)
  137. {
  138. tlb += (lbegin[0] & 0x7F) + 1; // + 1byte Length + 1byte to contain the value bytes
  139. if (tlb != 2)
  140. return false;
  141. tvb = lbegin[1];
  142. }
  143. else if (lbegin[0] == 0x82)
  144. {
  145. tlb += (lbegin[0] & 0x7F) + 1; // + 1byte Length + 2bytes to contain the value bytes
  146. if (tlb != 3)
  147. return false;
  148. tvb = (lbegin[1] << 8) + lbegin[2];
  149. }
  150. else
  151. {
  152. // Only the 3072bits RSA key is acceptable, for which we only need 2bytes to store the value bytes.
  153. // Therefore, return failure if the length of the value bytes is greater than 2bytes.
  154. return false;
  155. }
  156. if ((tlb < UINT_MAX - tvb) && (size_t)(lbegin + tvb + tlb) > tvb + tlb)
  157. {
  158. // In the input begin/end, the key_header/end has been removed.
  159. // Therefore, we should not check the entire key length.
  160. if (expect_tag != SEQUENCE_TAG_VALUE && lbegin + tvb + tlb > end)
  161. return false;
  162. else
  163. {
  164. *value_bytes = tvb;
  165. *len_bytes = tlb + 1; // + size of tag
  166. return true;
  167. }
  168. }
  169. return false;
  170. }
  171. static bool parse_tlv_integer(const unsigned char **begin, const unsigned char *end, unsigned int *values, size_t values_length)
  172. {
  173. assert(NULL != begin && NULL != *begin && NULL != end && NULL != values && values_length > 0);
  174. size_t value_bytes = 0, len_bytes = 0;
  175. const unsigned char *psrc = *begin;
  176. if (parse_tag_and_length(psrc, end, INTEGER_TAG_VALUE, &len_bytes, &value_bytes) == false)
  177. return false;
  178. psrc += len_bytes;
  179. if (value_bytes < values_length)
  180. return false;
  181. else if (value_bytes > values_length)
  182. {
  183. for (unsigned int i = 0; i < value_bytes - values_length; i++)
  184. {
  185. if (*(psrc + i) != 0x00)
  186. return false;
  187. }
  188. // There are some padding 0x00s which need to skip
  189. psrc += value_bytes - values_length;
  190. }
  191. if (values != NULL)
  192. {
  193. memcpy_s(values, values_length, psrc, values_length);
  194. }
  195. psrc += values_length;
  196. *begin = psrc;
  197. return true;
  198. }
  199. static bool convert_from_pri_key(const unsigned char *psrc, unsigned int slen, rsa_params_t *rsa)
  200. {
  201. assert(NULL != psrc && NULL != rsa);
  202. if(slen<PRI_COMPONENTS_SIZE)
  203. {
  204. return false;
  205. }
  206. size_t value_bytes = 0, len_bytes = 0;
  207. const unsigned char *end = psrc + slen;
  208. if (parse_tag_and_length(psrc, end, SEQUENCE_TAG_VALUE, &len_bytes, &value_bytes) == false)
  209. {
  210. return false;
  211. }
  212. psrc += len_bytes;
  213. // Version
  214. if (parse_tag_and_length(psrc, end, INTEGER_TAG_VALUE, &len_bytes, &value_bytes) == false)
  215. {
  216. return false;
  217. }
  218. psrc += len_bytes;
  219. if (value_bytes != 0x01 || *psrc != 0x00) // Version should be 0x00
  220. {
  221. return false;
  222. }
  223. psrc += value_bytes;
  224. memset(rsa, 0, sizeof(rsa_params_t));
  225. // N
  226. if (parse_tlv_integer(&psrc, end, rsa->n, N_SIZE_IN_BYTES) == false)
  227. {
  228. return false;
  229. }
  230. convert_string((unsigned char *)rsa->n, sizeof(rsa->n));
  231. // E
  232. if (parse_tlv_integer(&psrc, end, rsa->e, E_SIZE_IN_UINT) == false)
  233. {
  234. return false;
  235. }
  236. if (rsa->e[0] != 0x03)
  237. {
  238. se_trace(SE_TRACE_ERROR, "Only '3' is accepted as the Exponent value.\n");
  239. return false;
  240. }
  241. // D
  242. if (parse_tlv_integer(&psrc, end, rsa->d, D_SIZE_IN_BYTES) == false)
  243. {
  244. return false;
  245. }
  246. convert_string((unsigned char *)rsa->d, sizeof(rsa->d));
  247. // P
  248. if (parse_tlv_integer(&psrc, end, rsa->p, P_SIZE_IN_BYTES) == false)
  249. {
  250. return false;
  251. }
  252. convert_string((unsigned char *)rsa->p, sizeof(rsa->p));
  253. // Q
  254. if (parse_tlv_integer(&psrc, end, rsa->q, Q_SIZE_IN_BYTES) == false)
  255. {
  256. return false;
  257. }
  258. convert_string((unsigned char *)rsa->q, sizeof(rsa->q));
  259. // DMP1
  260. if (parse_tlv_integer(&psrc, end, rsa->dmp1, DMP1_SIZE_IN_BYTES) == false)
  261. {
  262. return false;
  263. }
  264. convert_string((unsigned char *)rsa->dmp1, sizeof(rsa->dmp1));
  265. // DMQ1
  266. if (parse_tlv_integer(&psrc, end, rsa->dmq1, DMQ1_SIZE_IN_BYTES) == false)
  267. {
  268. return false;
  269. }
  270. convert_string((unsigned char *)rsa->dmq1, sizeof(rsa->dmq1));
  271. // IQMP
  272. if (parse_tlv_integer(&psrc, end, rsa->iqmp, IQMP_SIZE_IN_BYTES) == false)
  273. {
  274. return false;
  275. }
  276. convert_string((unsigned char *)rsa->iqmp, sizeof(rsa->iqmp));
  277. return true;
  278. }
  279. static bool convert_from_pub_key(const unsigned char *psrc, unsigned int slen, rsa_params_t *rsa)
  280. {
  281. assert(NULL != psrc && NULL != rsa);
  282. if(slen<PUB_CONPONENTS_SIZE)
  283. {
  284. return false;
  285. }
  286. const unsigned char *end = psrc + slen;
  287. size_t len_bytes = 0, value_bytes = 0;
  288. unsigned char OID_str[] = { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 };
  289. // SEQUENCE
  290. if (parse_tag_and_length(psrc, end, SEQUENCE_TAG_VALUE, &len_bytes, &value_bytes) == false)
  291. {
  292. return false;
  293. }
  294. psrc += len_bytes;
  295. // SEQUENCE
  296. if (parse_tag_and_length(psrc, end, SEQUENCE_TAG_VALUE, &len_bytes, &value_bytes) == false)
  297. return false;
  298. psrc += len_bytes;
  299. // OBJECT_ID
  300. if (parse_tag_and_length(psrc, end, OID_TAG_VALUE, &len_bytes, &value_bytes) == false)
  301. return false;
  302. psrc += len_bytes;
  303. if (value_bytes != sizeof(OID_str) || memcmp(psrc, OID_str, sizeof(OID_str)) != 0)
  304. return false;
  305. psrc += value_bytes;
  306. // NULL
  307. if (parse_tag_and_length(psrc, end, NULL_TAG_VALUE, &len_bytes, &value_bytes) == false || value_bytes != 0)
  308. return false;
  309. psrc += len_bytes;
  310. // BIT STRING
  311. if (parse_tag_and_length(psrc, end, BIT_STRING_TAG_VALUE, &len_bytes, &value_bytes) == false)
  312. return false;
  313. psrc += len_bytes;
  314. if (*psrc == 0) // Specifies the number of unused bits that exist in the last content byte
  315. psrc++;
  316. // SEQUENCE
  317. if (parse_tag_and_length(psrc, end, SEQUENCE_TAG_VALUE, &len_bytes, &value_bytes) == false)
  318. return false;
  319. psrc += len_bytes;
  320. memset(rsa, 0, sizeof(rsa_params_t));
  321. // N
  322. if (parse_tlv_integer(&psrc, end, rsa->n, N_SIZE_IN_BYTES) == false)
  323. {
  324. return false;
  325. }
  326. convert_string((unsigned char *)rsa->n, sizeof(rsa->n));
  327. // E
  328. if (parse_tlv_integer(&psrc, end, rsa->e, E_SIZE_IN_UINT) == false)
  329. {
  330. return false;
  331. }
  332. if (rsa->e[0] != 0x03)
  333. {
  334. se_trace(SE_TRACE_ERROR, "Only '3' is accepted as the Exponent value.\n");
  335. return false;
  336. }
  337. return true;
  338. }
  339. static unsigned char* decode_key_body(unsigned char *buffer, size_t slen, int *key_type, int *rlen)
  340. {
  341. assert(buffer!=NULL && key_type!=NULL && rlen!=NULL);
  342. const char pri_key_header[] = "-----BEGINRSAPRIVATEKEY-----" ;
  343. const char pri_key_end[] = "-----ENDRSAPRIVATEKEY-----\n";
  344. const char pub_key_header[] = "-----BEGINPUBLICKEY-----";
  345. const char pub_key_end[] = "-----ENDPUBLICKEY-----\n";
  346. int ktype = UNIDENTIFIABLE_KEY;
  347. int offset_pri = (int)(slen - strlen(pri_key_end));
  348. int offset_pub = (int)(slen - strlen(pub_key_end));
  349. if(offset_pub<=0 || offset_pri<=0)
  350. {
  351. se_trace(SE_TRACE_ERROR, KEY_FORMAT_ERROR);
  352. *key_type = UNIDENTIFIABLE_KEY;
  353. return NULL;
  354. }
  355. //check the file header and footer to get the key type
  356. if(!strncmp((const char *)buffer, pri_key_header, strlen(pri_key_header)))
  357. {
  358. //make sure the key file isn't an emcrypted PEM private key file.
  359. if((!strncmp((const char *)(buffer+offset_pri), pri_key_end, strlen(pri_key_end))) &&
  360. !strstr((const char *)buffer, "Proc-Type: 4, ENCRYPTED"))
  361. {
  362. *(buffer+offset_pri-1) = '\0'; //remove the pri_key_end string
  363. ktype = PRIVATE_KEY;
  364. }
  365. else
  366. {
  367. ktype = UNIDENTIFIABLE_KEY;
  368. }
  369. }
  370. else if(!strncmp((const char *)buffer, pub_key_header, strlen(pub_key_header)))
  371. {
  372. if(!strncmp((const char *)(buffer+offset_pub), pub_key_end, strlen(pub_key_end)))
  373. {
  374. *(buffer + offset_pub-1) = '\0';
  375. ktype = PUBLIC_KEY;
  376. }
  377. else
  378. {
  379. ktype = UNIDENTIFIABLE_KEY;
  380. }
  381. }
  382. else
  383. {
  384. ktype = UNIDENTIFIABLE_KEY;
  385. }
  386. //get the body contents of the key file
  387. size_t body_size = 0, body_offset = 0;
  388. if(ktype == PRIVATE_KEY)
  389. {
  390. body_size = strlen((const char *)buffer) - strlen(pri_key_header);
  391. body_offset = strlen(pri_key_header)+1;
  392. }
  393. else if(ktype == PUBLIC_KEY)
  394. {
  395. body_size = strlen((const char *)buffer) - strlen(pub_key_header);
  396. body_offset = strlen(pub_key_header)+1;
  397. }
  398. else
  399. {
  400. se_trace(SE_TRACE_ERROR, KEY_FORMAT_ERROR);
  401. *key_type = ktype;
  402. return NULL;
  403. }
  404. unsigned char *decoded_string = (unsigned char *)malloc(sizeof(char)*body_size);
  405. if(!decoded_string)
  406. {
  407. se_trace(SE_TRACE_ERROR, NO_MEMORY_ERROR);
  408. *key_type = ktype;
  409. return NULL;
  410. }
  411. memset(decoded_string, 0, body_size);
  412. int retlen = base64_decode(buffer+body_offset, body_size, decoded_string);
  413. if(retlen == 0)
  414. {
  415. se_trace(SE_TRACE_ERROR, KEY_FORMAT_ERROR);
  416. *key_type = ktype;
  417. free(decoded_string);
  418. return NULL;
  419. }
  420. *key_type = ktype;
  421. *rlen = retlen;
  422. return decoded_string;
  423. }
  424. //read_key_file
  425. // read the input file line by line and trim the blank characters for each line
  426. //Parameters
  427. // [IN] key_path: the file required to be read
  428. static std::string read_key_file(const char *key_path)
  429. {
  430. assert(key_path != NULL);
  431. std::ifstream ifs(key_path, std::ios::in | std::ios::binary);
  432. if(!ifs.good())
  433. {
  434. se_trace(SE_TRACE_ERROR, READ_FILE_ERROR, key_path);
  435. return "";
  436. }
  437. std::string file_content;
  438. std::string str;
  439. while(std::getline(ifs, str))
  440. {
  441. str.erase(std::remove_if(str.begin(), str.end(), ::isspace), str.end());
  442. if(str.length() != 0)
  443. {
  444. file_content += str;
  445. file_content += "\n"; // Add '\n' for each line
  446. }
  447. }
  448. ifs.close();
  449. return file_content;
  450. }
  451. //parse_key_file():
  452. // parse the RSA key file
  453. //Parameters:
  454. // [IN] key_path: the key file name user inputs
  455. // [OUT] prsa: the rsa structure parsed from the key file
  456. // pkey_type: the key type
  457. //Return Value:
  458. // true: success
  459. // false: fail
  460. bool parse_key_file(const char *key_path, rsa_params_t *prsa, int *pkey_type)
  461. {
  462. assert(prsa != NULL && pkey_type != NULL);
  463. if(key_path == NULL)
  464. {
  465. *pkey_type = NO_KEY;
  466. return false;
  467. }
  468. //read and trim the file content
  469. std::string file_content = read_key_file(key_path);
  470. if(file_content.empty() == true)
  471. {
  472. *pkey_type = UNIDENTIFIABLE_KEY;
  473. return false;
  474. }
  475. const unsigned char *buffer = (const unsigned char *)file_content.c_str();
  476. //decode the buffer to decoded_string
  477. size_t result = strlen((const char *)buffer);
  478. int retlen = 0;
  479. int key_type = UNIDENTIFIABLE_KEY;
  480. unsigned char *decoded_string = decode_key_body(const_cast<unsigned char*>(buffer), result, &key_type, &retlen);
  481. if(!decoded_string)
  482. {
  483. *pkey_type = key_type;
  484. return false;
  485. }
  486. //get RSA from the decoded string
  487. bool ret = false;
  488. if(key_type == PRIVATE_KEY)
  489. {
  490. ret = convert_from_pri_key(decoded_string, retlen, prsa);
  491. }
  492. else
  493. {
  494. ret = convert_from_pub_key(decoded_string, retlen, prsa);
  495. }
  496. if(ret == false)
  497. {
  498. se_trace(SE_TRACE_ERROR, KEY_FORMAT_ERROR);
  499. free(decoded_string);
  500. *pkey_type = key_type;
  501. return false;
  502. }
  503. else
  504. {
  505. se_trace(SE_TRACE_DEBUG, "Parsing key file is OK.\n");
  506. }
  507. *pkey_type = key_type;
  508. free(decoded_string);
  509. return true;
  510. }