summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2013-11-18 18:01:16 +0100
committerGravatar Nikias Bassen2013-11-18 18:01:16 +0100
commite5bbb647163e69d4ac0cc09eecfe65eac0f63704 (patch)
tree14625a6173bad6ab8568e50c2e43ba1bf6655ba6 /src
parentde4fc4c8d1d60d01d910dd2e0ae1305aab2131e9 (diff)
downloadlibirecovery-e5bbb647163e69d4ac0cc09eecfe65eac0f63704.tar.gz
libirecovery-e5bbb647163e69d4ac0cc09eecfe65eac0f63704.tar.bz2
change irecv_get_nonce to a more general irecv_get_nonce_with_tag
Diffstat (limited to 'src')
-rw-r--r--src/libirecovery.c48
1 files changed, 41 insertions, 7 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index 7ba2dd9..f189838 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -1310,11 +1310,15 @@ irecv_error_t irecv_get_imei(irecv_client_t client, char* imei) {
1310 return IRECV_E_SUCCESS; 1310 return IRECV_E_SUCCESS;
1311} 1311}
1312 1312
1313irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int* nonce_size) { 1313irecv_error_t irecv_get_nonce_with_tag(irecv_client_t client, const char* tag, unsigned char** nonce, int* nonce_size) {
1314 if (check_context(client) != IRECV_E_SUCCESS) 1314 if (check_context(client) != IRECV_E_SUCCESS)
1315 return IRECV_E_NO_DEVICE; 1315 return IRECV_E_NO_DEVICE;
1316 1316
1317 unsigned char buf[255]; 1317 if (tag == NULL) {
1318 return IRECV_E_INVALID_INPUT;
1319 }
1320
1321 char buf[255];
1318 int len; 1322 int len;
1319 1323
1320 *nonce = NULL; 1324 *nonce = NULL;
@@ -1327,15 +1331,45 @@ irecv_error_t irecv_get_nonce(irecv_client_t client, unsigned char** nonce, int*
1327 } 1331 }
1328 1332
1329 buf[len] = 0; 1333 buf[len] = 0;
1330 debug("%s: buf='%s'\n", __func__, buf); 1334 debug("%s: buf='%s' tag='%s'\n", __func__, buf, tag);
1335
1336 int taglen = strlen(tag);
1337 int nlen = 0;
1338 char* nonce_string = NULL;
1339 char* p = buf;
1340 char* colon = NULL;
1341 do {
1342 colon = strchr(p, ':');
1343 if (!colon)
1344 break;
1345 if (colon-taglen < p) {
1346 break;
1347 }
1348 char *space = strchr(colon, ' ');
1349 if (strncmp(colon-taglen, tag, taglen) == 0) {
1350 p = colon+1;
1351 if (!space) {
1352 nlen = strlen(p);
1353 } else {
1354 nlen = space-p;
1355 }
1356 nonce_string = p;
1357 nlen/=2;
1358 break;
1359 } else {
1360 if (!space) {
1361 break;
1362 } else {
1363 p = space+1;
1364 }
1365 }
1366 } while (colon);
1331 1367
1332 char* nonce_string = strstr((char*)buf, "NONC:"); 1368 if (nlen == 0) {
1333 if (nonce_string == NULL) { 1369 debug("%s: ERROR: couldn't find tag %s in string %s\n", __func__, tag, buf);
1334 return IRECV_E_UNKNOWN_ERROR; 1370 return IRECV_E_UNKNOWN_ERROR;
1335 } 1371 }
1336 nonce_string+=5;
1337 1372
1338 int nlen = (len - ((unsigned char*)nonce_string - &buf[0])) / 2;
1339 unsigned char *nn = malloc(nlen); 1373 unsigned char *nn = malloc(nlen);
1340 if (!nn) { 1374 if (!nn) {
1341 return IRECV_E_OUT_OF_MEMORY; 1375 return IRECV_E_OUT_OF_MEMORY;