Diff

Differences From Artifact [884439a73b]:

To Artifact [941bf5cf9b]:


    22     22   #endif
    23     23   #ifdef HAVE_STRING_H
    24     24   #  include <string.h>
    25     25   #endif
    26     26   #ifdef HAVE_PTHREAD_H
    27     27   #  include <pthread.h>
    28     28   #endif
           29  +#ifdef HAVE_ZLIB_H
           30  +#  ifdef HAVE_LIBZ
           31  +#    include <zlib.h>
           32  +#  endif
           33  +#else
           34  +#  ifdef HAVE_LIBZ
           35  +#    undef HAVE_LIBZ
           36  +#  endif
           37  +#endif
    29     38   
    30     39   #define CK_PTR *
    31     40   #define CK_DEFINE_FUNCTION(returnType, name) returnType name
    32     41   #define CK_DECLARE_FUNCTION(returnType, name) returnType name
    33     42   #define CK_DECLARE_FUNCTION_POINTER(returnType, name) returnType (* name)
    34     43   #define CK_CALLBACK_FUNCTION(returnType, name) returnType (* name)
    35     44   #ifndef NULL_PTR
................................................................................
  1361   1370   	unsigned char vlen_buf[2], vval_buf[8192], *vval;
  1362   1371   	unsigned char *tmpbuf;
  1363   1372   	ssize_t tlen, vlen;
  1364   1373   	ssize_t read_ret;
  1365   1374   	size_t offset_t = 0, offset_v = 0;
  1366   1375   	unsigned char tag;
  1367   1376   	size_t length;
         1377  +	uLongf tmpbuflen;
         1378  +	int uncompress_ret;
  1368   1379   
  1369   1380   	CACKEY_DEBUG_PRINTF("Called.");
  1370   1381   
  1371   1382   	read_ret = cackey_read_buffer(slot, tlen_buf, sizeof(tlen_buf), 1, offset_t);
  1372   1383   	if (read_ret != sizeof(tlen_buf)) {
  1373   1384   		CACKEY_DEBUG_PRINTF("Read failed, returning in failure");
  1374   1385   
................................................................................
  1384   1395   		return(NULL);
  1385   1396   	}
  1386   1397   
  1387   1398   	vlen = (vlen_buf[1] << 8) | vlen_buf[0];
  1388   1399   
  1389   1400   	CACKEY_DEBUG_PRINTF("Tag Length = %i, Value Length = %i", tlen, vlen);
  1390   1401   
  1391         -	tlen -= 2;
  1392   1402   	offset_t += 2;
  1393         -
  1394         -	vlen -= 2;
  1395   1403   	offset_v += 2;
  1396   1404   
  1397   1405   	if (tlen > sizeof(tval_buf)) {
  1398   1406   		CACKEY_DEBUG_PRINTF("Tag length is too large, returning in failure");
  1399   1407   
  1400   1408   		return(NULL);
  1401   1409   	}
................................................................................
  1435   1443   			length = *tval;
  1436   1444   			tval++;
  1437   1445   			tlen--;
  1438   1446   		}
  1439   1447   
  1440   1448   		CACKEY_DEBUG_PRINTF("Tag: %s (%02x)", CACKEY_DEBUG_FUNC_TAG_TO_STR(tag), (unsigned int) tag);
  1441   1449   		CACKEY_DEBUG_PRINTBUF("Value:", vval, length);
  1442         -		vval += length;
  1443         -		vlen -= length;
  1444   1450   
  1445   1451   		curr_entity = NULL;
  1446   1452   		switch (tag) {
  1447   1453   			case GSCIS_TAG_CARDURL:
  1448   1454   				curr_entity = malloc(sizeof(*curr_entity));
  1449   1455   				curr_entity->value_cardurl = malloc(sizeof(*curr_entity->value_cardurl));
  1450   1456   
................................................................................
  1467   1473   				curr_entity->length = length;
  1468   1474   				curr_entity->value = tmpbuf;
  1469   1475   				curr_entity->_next = NULL;
  1470   1476   
  1471   1477   				break;
  1472   1478   			case GSCIS_TAG_CERTIFICATE:
  1473   1479   				curr_entity = malloc(sizeof(*curr_entity));
  1474         -				tmpbuf = malloc(length);
  1475   1480   
         1481  +				tmpbuflen = length * 2;
         1482  +				tmpbuf = malloc(tmpbuflen);
         1483  +
         1484  +#ifdef HAVE_LIBZ
         1485  +				CACKEY_DEBUG_PRINTBUF("Decompressing:", vval, length);
         1486  +				uncompress_ret = uncompress(tmpbuf, &tmpbuflen, vval, length);
         1487  +				if (uncompress_ret != Z_OK) {
         1488  +					CACKEY_DEBUG_PRINTF("Failed to decompress, uncompress() returned %i -- resorting to direct copy", uncompress_ret);
         1489  +
         1490  +					tmpbuflen = length;
         1491  +					memcpy(tmpbuf, vval, length);
         1492  +				}
         1493  +
         1494  +				CACKEY_DEBUG_PRINTBUF("Decompressed to:", tmpbuf, tmpbuflen);
         1495  +#else
         1496  +				CACKEY_DEBUG_PRINTF("Missing ZLIB Support, this certificate is likely useless...");
         1497  +
         1498  +				tmpbuflen = length;
  1476   1499   				memcpy(tmpbuf, vval, length);
         1500  +#endif
  1477   1501   
  1478   1502   				curr_entity->tag = tag;
  1479         -				curr_entity->length = length;
         1503  +				curr_entity->length = tmpbuflen;
  1480   1504   				curr_entity->value = tmpbuf;
  1481   1505   				curr_entity->_next = NULL;
  1482   1506   
  1483   1507   				break;
  1484   1508   			case GSCIS_TAG_PKCS15:
  1485   1509   				curr_entity = malloc(sizeof(*curr_entity));
  1486   1510   
  1487   1511   				curr_entity->tag = tag;
  1488   1512   				curr_entity->value_byte = vval[0];
  1489   1513   				curr_entity->_next = NULL;
  1490   1514   
  1491   1515   				break;
  1492   1516   		}
         1517  +
         1518  +		vval += length;
         1519  +		vlen -= length;
  1493   1520   
  1494   1521   		if (curr_entity != NULL) {
  1495   1522   			if (root == NULL) {
  1496   1523   				root = curr_entity;
  1497   1524   			}
  1498   1525   
  1499   1526   			if (last != NULL) {