Exemple #1
0
void ICard::debug_CAPDU(const char *label, const CAPDU& capdu) const
{
	eCardCore_info(DEBUG_LEVEL_APDU, "%s%sC-APDU:  CLA=%02X  INS=%02X  P1=%02X  P2=%02X  Nc=%-5u  Ne=%u",
			label, label ? " " : "", capdu.getCLA(), capdu.getINS(), capdu.getP1(),
			capdu.getP2(), capdu.getData().size(), capdu.getNe());
	hexdump(DEBUG_LEVEL_APDU, NULL,
			DATA(capdu.getData()), capdu.getData().size());
}
Exemple #2
0
RAPDU ICard::transceive(const CAPDU &cmd)
{
	debug_CAPDU("Outgoing", cmd);
	
	RAPDU rapdu(m_subSystem->transceive(cmd.asBuffer()));
	debug_RAPDU("Incoming", rapdu);

	return rapdu;
}
Exemple #3
0
CAPDU ePACard::applySM(const CAPDU &capdu)
{
	std::vector<unsigned char> do87_, do8E_, do97_, Le, sm_data;

	debug_CAPDU("Unencrypted", capdu);

	CAPDU sm_apdu = CAPDU(capdu.getCLA() | CAPDU::CLA_SM,
						  capdu.getINS(), capdu.getP1(), capdu.getP2());

	m_ssc++;

	if (!capdu.getData().empty()) {
		do87_ = buildDO87_AES(m_kEnc, capdu.getData(), m_ssc);
	}

	Le = capdu.encodedLe();

	if (!Le.empty()) {
		if (Le.size() > 2) {
			Le.erase(Le.begin());
		}
		do97_ = TLV_encode(0x97, Le);
	}

	/* here, sm_apdu is still a case 1 APDU with header only. */
	do8E_ = buildDO8E_AES(m_kMac, sm_apdu.asBuffer(), do87_, do97_, m_ssc);
	sm_data = do87_;
	sm_data.insert(sm_data.end(), do97_.begin(), do97_.end());
	sm_data.insert(sm_data.end(), do8E_.begin(), do8E_.end());
	sm_apdu.setData(sm_data);

	if (sm_apdu.isExtended() || capdu.isExtended())
		sm_apdu.setNe(CAPDU::DATA_EXTENDED_MAX);

	else
		sm_apdu.setNe(CAPDU::DATA_SHORT_MAX);

	return sm_apdu;
}