Esempio n. 1
0
	bool DESFireProfile::getKey(size_t aid, unsigned char keyno, unsigned char* diversify, std::vector<unsigned char>& keydiv)
	{
		if (!checkKeyPos(aid, keyno, false))
		{
			keydiv.resize(16, 0x00);

			return false;
		}

		size_t posAid;
		getPosAid(aid, &posAid);

		size_t keyPos = 1 + posAid * 14 + keyno;
		
		if (!getKeyUsage(keyPos))
		{
			keydiv.resize(16, 0x00);

			return false;
		}

		DESFireCrypto::getKey(d_key[keyPos], diversify, keydiv);
		
		return true;
	}	
Esempio n. 2
0
bool FT_EDS_Door::checkKey(edsId id, uint8_t* data, uint16_t len)
{
	if(checkKeyPos(id, data, len) != 0)
		return true;

	return false;
}
Esempio n. 3
0
bool FT_EDS_Door::removeDE(edsId id, edsType type, uint8_t* data, uint16_t len)
{
    unsigned int pos = getPos(id);
    if(0==pos)
        return false;

	uint32_t offsetOld = read32(pos+6);
	if(0==offsetOld)
	{
		//Remove from nothing? ok I guess..?
		return true;
	}

	if(type != EDS_BYTE_ARRAY || read16(pos+2) != EDS_BYTE_ARRAY)
	{
		return false;
	}

	uint32_t rmKeyPos = checkKeyPos(id, data, len);
	if(0 == rmKeyPos)
	{
		//It's not there! so I guess its ok!
		return true;
	}

	uint16_t size  = read16(pos+4);
	uint32_t point = read32(pos+6);


	if(rmKeyPos == point)
	{
		//no need to copy, just move the pointer
	}
	else if(rmKeyPos <= point)
	{
		//this is just wrong!
		return false;
	}
	else
	{
		//The top byte in the last ok chunk
		rmKeyPos--;
		while(rmKeyPos>=point)
		{
			EEPROM.write(rmKeyPos+8, EEPROM.read(rmKeyPos));
			rmKeyPos--;
		}
	}

	point+=8;
	write32(pos+6, point);
	posFreeData = point;

	size-=8;
	write16(pos+4, size);

	return true;
}
Esempio n. 4
0
	bool DESFireProfile::checkKeyPos(size_t aid, unsigned char keyno, bool defvalue) const
	{
		if (!checkKeyPos(aid, defvalue) || keyno > 13)
		{
			return false;
		}

		return true;
	}
Esempio n. 5
0
	void DESFireProfile::setKey(size_t aid, unsigned char keyno, boost::shared_ptr<DESFireKey> key)
	{
		if (!checkKeyPos(aid, keyno, true))
		{
			return;
		}

		size_t posAid;
		if (!getPosAid(aid, &posAid))
		{
			posAid = addPosAid(aid);
		}

		size_t keyPos = 1 + posAid*14 + keyno;

		d_key[keyPos] = key;
	}
Esempio n. 6
0
	boost::shared_ptr<DESFireKey> DESFireProfile::getKey(size_t aid, unsigned char keyno) const
	{
		boost::shared_ptr<DESFireKey> key;

		if (checkKeyPos(aid, keyno, false))
		{
			size_t posAid;
			getPosAid(aid, &posAid);

			size_t keyPos = 1 + posAid * 14 + keyno;
		
			if (getKeyUsage(keyPos))
			{
				key = d_key[keyPos];
			}
		}

		if (!key)
		{
			key = DESFireProfile::getDefaultKey(DF_KEY_DES);
		}

		return key;
	}