Exemple #1
0
void CPkiCard::WriteUncachedFile(const std::string & csPath,
    unsigned long ulOffset, const CByteArray & oData)
{
    CAutoLock autolock(this);

    tFileInfo fileInfo = SelectFile(csPath, true);

    const unsigned char *pucData = oData.GetBytes();
    unsigned long ulDataLen = oData.Size();
    for (unsigned long i = 0; i < ulDataLen; i += MAX_APDU_WRITE_LEN)
    {
        unsigned long ulLen = ulDataLen - i;
		if (ulLen > MAX_APDU_WRITE_LEN)
            ulLen = MAX_APDU_WRITE_LEN;

        CByteArray oResp = UpdateBinary(ulOffset + i, CByteArray(pucData + i, ulLen));
		unsigned long ulSW12 = getSW12(oResp);
		if (ulSW12 == 0x6982)
			throw CNotAuthenticatedException(
				EIDMW_ERR_NOT_AUTHENTICATED, fileInfo.lWritePINRef);
		else if (ulSW12 != 0x9000)
			throw CMWEXCEPTION(m_poContext->m_oPCSC.SW12ToErr(ulSW12));
    }

	MWLOG(LEV_INFO, MOD_CAL, L"Written file %ls to card", utilStringWiden(csPath).c_str());

}
Exemple #2
0
int main()
{
    int i = 0;
    Serializer<int>::serialize(i);
    Serializer<CByteArray>::serialize(CByteArray());
    Serializer<HLVariant>::serialize(HLVariant());
}
Exemple #3
0
CEmulationCard::CEmulationCard():
	m_lDefaultRet(0),
	m_oDefaultResponseAPDU(tucSW12FunctionNotSupported, sizeof(tucSW12FunctionNotSupported)),
	m_bEnforce(false)
{
	unsigned char tucDefaultATR[] =
		{0x3B,0x98,0x13,0x40,0x0A,0xA5,0x03,0x01,0x01,0x01,0xAD,0x13,0x11};
	m_oATR = CByteArray(tucDefaultATR, sizeof(tucDefaultATR));
}
/** Obtain the SIS-data via the plugin library
*/
CCard * SISPluginReadData(const char *csReader, SCARDHANDLE hCard,
	CContext *poContext, CPinpad *poPinpad,
	CDynamicLib &oCardPluginLib)
{
	CCard *poCard = NULL;

	if (!m_bPluginInfosOK)
		GetPluginInfos();

	for (size_t i = 0; poCard == NULL && i < PlugInCount(); i++)
	{
		if (!StartsWith(csReader, GetPlugInReader(i).c_str()))
			continue;

		std::string csPluginPath = GetPlugInPath(i);
		unsigned long ulErr = oCardPluginLib.Open(csPluginPath);
		if (ulErr != EIDMW_OK)
		{
			MWLOG(LEV_ERROR, MOD_CAL, L"Couldn't load SIS plugin \"%ls\", err = 0x%0x",
				utilStringWiden(csPluginPath).c_str(), ulErr);
			continue;
		}

		SISPLUGINREADCARD pSisPluginReadCard =
				(SISPLUGINREADCARD) oCardPluginLib.GetAddress("SISPluginReadCard");
		if (pSisPluginReadCard == NULL)
		{
			MWLOG(LEV_ERROR, MOD_CAL, L"Function \"SISPluginReadCard\" not found in \"%ls\"",
				utilStringWiden(csPluginPath).c_str(), ulErr);
			continue;
		}

		tPCSCfunctions xPCSCFunctions;
		GetPCSCFunctions(&poContext->m_oPCSC, &xPCSCFunctions);

		unsigned char tucData[500];
		SCARDHANDLE hCrd = hCard;
		long lErr = pSisPluginReadCard(SISPLUGIN_VERSION, &xPCSCFunctions,
			csReader, &hCrd, tucData, 0, NULL);
		hCard = (unsigned long) hCrd;

		if (lErr != 0)
		{
			MWLOG(LEV_ERROR, MOD_CAL, L"Function \"SISPluginReadCard\" in \"%ls\" returned 0x%0x (%d)",
				utilStringWiden(csPluginPath).c_str(), lErr, lErr);
			continue;
		}

		MWLOG(LEV_DEBUG, MOD_CAL, L"Using SIS plugin \"%ls\"",
			utilStringWiden(csPluginPath).c_str());
		poCard = new CSISCard(hCard, poContext, poPinpad, CByteArray(tucData, 404));

		break;
	}

	return poCard;;
}
Exemple #5
0
	bool CPixmap::load( const unsigned char* data, unsigned int len )
	{
	   TRACE_FUN( Frequently, "CPixmap::load( const unsigned char*, unsigned int )" );

		bool ret( false );

		ret = load( CByteArray( data, len ) );

		return ret;
	}
Exemple #6
0
CByteArray CByteArray::GetBytes(unsigned long ulOffset, unsigned long ulLen) const
{
    if (m_bMallocError)
        throw CMWEXCEPTION(EIDMW_ERR_MEMORY);

    if (ulOffset >= m_ulSize)
        throw CMWEXCEPTION(EIDMW_ERR_PARAM_RANGE); 

    if (ulLen == 0xFFFFFFFF || ulOffset + ulLen > m_ulSize)
        ulLen = m_ulSize - ulOffset;

    return CByteArray(&m_pucData[ulOffset],ulLen);
}
Exemple #7
0
 static typename std::enable_if<std::is_pod<U>::value, CByteArray>::type serialize(const U& /* value*/)
 {
     static_assert(std::is_pod<U>::value, "Not a POD type");
     return CByteArray();
 }
Exemple #8
0
 static CByteArray serialize(const HLVariant& value)
 {
     return CByteArray();
 }
Exemple #9
0
CCard * CardConnect(const std::string &csReader,
                    CContext *poContext, CPinpad *poPinpad, CDynamicLib &oCardPluginLib)
{
    CCard *poCard = NULL;
    long lErrCode = EIDMW_ERR_CHECK; // should never be returned
    const char *strReader = NULL;

    if (poContext->m_ulConnectionDelay != 0)
        CThread::SleepMillisecs(poContext->m_ulConnectionDelay);

    // Try if we can connect to the card via a normal SCardConnect()
    SCARDHANDLE hCard = 0;
    try
    {
        hCard = poContext->m_oPCSC.Connect(csReader);
        if (hCard == 0)
            goto done;
    }
    catch(CMWException &e)
    {
        if (e.GetError() == (long)EIDMW_ERR_NO_CARD)
            goto done;
        if (e.GetError() != (long)EIDMW_ERR_CANT_CONNECT && e.GetError() != (long)EIDMW_ERR_CARD_COMM)
            throw;
        lErrCode = e.GetError();
        hCard = 0;
    }

    // So a card is present, get the names of the available plugin libs
    if (!m_bPluginNamesOK)
        GetPluginNames();

    strReader = csReader.c_str();

    if (hCard != 0)
    {
        // 1. A card is present and we could connect to it via a normal SCardConnect()

        for (size_t i = 0; poCard == NULL && i < m_Plugins.size(); i++)
        {
            tPluginInfo &plugin = m_Plugins.at(i);
            if (plugin.csReader.size() != 0 && plugin.csReader.compare(0, string::npos, strReader, plugin.csReader.length()))
                continue;
            poCard = GetCardInstance(strReader, hCard, poContext, poPinpad, plugin.csPath, oCardPluginLib);
        }

#ifdef CAL_BEID
        if (poCard == NULL)
            poCard = BeidCardGetInstance(PLUGIN_VERSION, strReader, hCard, poContext, poPinpad);

        //if (poCard == NULL)
        //	poCard = SISPluginReadData(strReader, hCard, poContext, poPinpad, oCardPluginLib);

        /* SIS support no longer in the CardLayer�, only via the plugins */
#if SIS_IN_CAL

        if (poCard == NULL && StartsWith(csReader.c_str(), "ACS ACR38"))
        {
#ifdef __APPLE__
            poContext->m_oPCSC.Disconnect(hCard, DISCONNECT_RESET_CARD);
            poCard = SISCardConnectGetInstance(PLUGIN_VERSION, strReader, poContext, poPinpad);
#else
            poCard = SISCardGetInstance(PLUGIN_VERSION, strReader, hCard, poContext, poPinpad);
#endif
        }
#ifdef CAL_EMULATION
        // Emulated reader doesn't start with "ACS ACR38"
        if (poCard == NULL)
            poCard = SISCardGetInstance(PLUGIN_VERSION, strReader, hCard, poContext, poPinpad);
#endif

#endif // SIS_IN_CAL

#endif // CAL_BEID

#ifndef __APPLE__
        // If no other CCard subclass could be found
        if (poCard == NULL)
            poCard = new CUnknownCard(hCard, poContext, poPinpad, CByteArray());
#else
        // On Mac OS X, SCardConnect() always works when reading a SIS card on an ACR38U,
        // but not the following SCardTransmit() to read out the data. So we set hCard
        // to 0 which will cause SISCardConnectGetInstance() below to first switch to
        // the correct mode to read out the SIS card.
        hCard = 0;
#endif
    }

    if (hCard == 0)
    {
        // 2. A card is present, but connecting to it is reader-specific (e.g. synchron. cards)

        strReader = csReader.c_str();
        for (size_t i = 0; poCard == NULL && i < m_Plugins.size(); i++)
        {
            tPluginInfo &plugin = m_Plugins.at(i);
            if (!plugin.bFull || (plugin.csReader.size() != 0 && plugin.csReader.compare(0, string::npos, strReader, plugin.csReader.length())))
                continue;
            poCard = ConnectGetCardInstance(strReader, poContext, poPinpad,
                                            plugin.csPath, oCardPluginLib);
        }

#ifdef CAL_BEID
//		if (poCard == NULL)
//			poCard = SISPluginReadData(strReader, hCard, poContext, poPinpad, oCardPluginLib);

        if (poCard == NULL)
            poCard = new CUnknownCard(hCard, poContext, poPinpad, CByteArray());

        /* SIS support no longer in the CardLayer�, only via the plugins */
#if SIS_IN_CAL
        if (poCard == NULL  && StartsWith(csReader.c_str(), "ACS ACR38"))
            poCard = SISCardConnectGetInstance(PLUGIN_VERSION, strReader, poContext, poPinpad);
#endif // SIS_IN_CAL

#endif // CAL_BEID

        // If the card is still not recognized here, then it may as well
        // be an badly inserted card, so we'll throw the exception that we
        // caught in the beginnin of this function
        if (poCard == NULL)
            throw CMWEXCEPTION(lErrCode);
    }

done:
    return poCard;
}
Exemple #10
0
CByteArray CSerializer::data() const
{
	return CByteArray(byte_array_, 0, write_seeker_);
}
Exemple #11
0
CByteArray CSerializer::data_last_read() const
{
	return CByteArray(byte_array_, read_seeker_, write_seeker_-read_seeker_);
}
Exemple #12
0
void CSerializer::Clear()
{
	write_seeker_ = 0;
	read_seeker_ = 0;
	byte_array_ = CByteArray();
}
#include "ISCPacketCreator.h"


CByteArray IISCPacketCreator::ms_packet = CByteArray();

void IISCPacketCreator::cleanup()
{
	ms_packet.destroy();
}

const CByteArray &IISCPacketCreator::auth(E_ISC_CLIENT_TYPE _type, const char *_password,
										  const char *_name, const char *_thisip, ID _extid, s32 _additional)
{
	_start(ISCC_AUTH);

	ms_packet.addInt(_type);
	ms_packet.addString(_password);
	ms_packet.addString(_name);
	ms_packet.addString(_thisip);
	ms_packet.addInt(_extid);
	ms_packet.addInt(_additional);

	_finish();

	return ms_packet;
}

const CByteArray &IISCPacketCreator::logout(ID _sid)
{
	_start(ISCC_LOGOUT);