Пример #1
0
static long TestPteidCtrl(CReader & oReader, unsigned char ucVersion)
{
	long lErrors = 0;

	printf("\nTesting Ctrl()\n");

	// CTRL_PTEID_GETCARDDATA
	CByteArray oCardInfo = oReader.GetInfo();
	CByteArray oUnsignedCardData = oReader.Ctrl(CTRL_PTEID_GETCARDDATA, CByteArray());
	if (!oCardInfo.Equals(oUnsignedCardData))
		ERR_LOG("ERR: Ctrl(CTRL_PTEID_GETCARDDATA) != GetInfo()\n", lErrors);

	// CTRL_PTEID_GETSIGNEDCARDDATA
	if (ucVersion >= 0x20)
	{
		CByteArray oSignedCardData = oReader.Ctrl(CTRL_PTEID_GETSIGNEDCARDDATA, CByteArray());

		if (oSignedCardData.Size() != oUnsignedCardData.Size() + 128)
			ERR_LOG("ERR: signed and unsigned card data should differ in size by 128 bytes\n", lErrors);

		oSignedCardData.Chop(128);
		if (!oUnsignedCardData.Equals(oSignedCardData))
			ERR_LOG("ERR: start of unsigned card data should be the same as for unsigned card data\n", lErrors);
	}

	// CTRL_PTEID_GETSIGNEDPINSTATUS
	if (ucVersion >= 0x20)
	{
		tPin pin = oReader.GetPin(0);

		CByteArray oData(1);
		oData.Append((unsigned char) pin.ulPinRef);
		CByteArray oSignedPinStatus = oReader.Ctrl(CTRL_PTEID_GETSIGNEDPINSTATUS, oData);

		if (oSignedPinStatus.Size() != 129)
			ERR_LOG("ERR: signed pin status response should be (1 + 128) bytes\n", lErrors);
		else if (oSignedPinStatus.GetByte(0) != oReader.PinStatus(pin))
			ERR_LOG("ERR: signed pin status differs from unsigned PIN status\n", lErrors);
	}

	// CTRL_PTEID_INTERNAL_AUTH
	CByteArray oData(21); // Key ref (1 byte) + challenge(20 bytes)
	oData.Append(0x81);
	for (int i = 0; i < 20; i++)
		oData.Append((unsigned char) rand());
	CByteArray oResp1 = oReader.Ctrl(CTRL_PTEID_INTERNAL_AUTH, oData);
	if (oResp1.Size() != 128)
		ERR_LOG("ERR: Internal Auth. didn't return 128 bytes\n", lErrors);
	CByteArray oResp2 = oReader.Ctrl(CTRL_PTEID_INTERNAL_AUTH, oData);
	if (!oResp1.Equals(oResp2))
		ERR_LOG("ERR: Internal Auth. on the same data returns a different result\n", lErrors);
	oData.SetByte(oData.GetByte(5) + 0x01, 5);
	CByteArray oResp3 = oReader.Ctrl(CTRL_PTEID_INTERNAL_AUTH, oData);
	if (oResp1.Equals(oResp3))
		ERR_LOG("ERR: Internal Auth. on the different data returns the same result\n", lErrors);

	return lErrors;
}
Пример #2
0
/**
 * csPath should be the path to a big file that can be cached
 * Best do this test first, because anything is cached.
 */
static long TestCache(CReader & oReader, const std::string & csPath)
{
	long lErrors = 0;

	printf("\nTesting caching functionality (using file %s)\n", csPath.c_str());

	CByteArray oMaybeFromDisk = oReader.ReadFile(csPath);

	bool bDeleted = g_oCardLayer.DeleteFromCache(oReader.GetSerialNr());
	if (!bDeleted)
	{
		ERR_LOG("ERR: CCardLayer::DeleteFromCache() seems to fail\n", lErrors);
		printf("  (File %s should have been cached, but isn't deleted)\n", csPath.c_str());
	}

	CByteArray oFromCard = oReader.ReadFile(csPath);
	//diffFromCard = fromCard2 - fromCard1;

	CByteArray oFromMem = oReader.ReadFile(csPath);
	//diffFromMem = fromMem2 - fromMem1;

	/*
	if (2 * diffFromMem > diffFromCard)
	{
		printf("WARNING: reading %d bytes from the card (%d msec) isn't much\n",
			oFromCard.Size(), diffFromCard);
		printf("  faster then reading it from cach (%d msec)\n", diffFromMem);
	}
	*/

	if (!oFromCard.Equals(oFromMem))
		ERR_LOG("ERR: cached file contents (from memory) differ from those on the card\n", lErrors);
	else if (!oFromCard.Equals(oMaybeFromDisk))
		ERR_LOG("ERR: cached file contents (from disk) differ from those on the card\n", lErrors);

	oFromCard = oReader.ReadFile(csPath, 10, 20);
	oFromMem = oReader.ReadFile(csPath, 10, 20);
	if (!oFromCard.Equals(oFromMem))
		ERR_LOG("ERR: reading part of the cached contents fails\n", lErrors);

	return lErrors;
}