Пример #1
0
static CCard *GetCardInstance(const char *csReader, SCARDHANDLE hCard,
                              CContext *poContext, CPinpad *poPinpad,
                              const std::string &csPluginPath, CDynamicLib &oCardPluginLib)
{
    CCard * poCard = NULL;

    unsigned long ulErr = oCardPluginLib.Open(csPluginPath);
    if (ulErr != EIDMW_OK)
    {
        MWLOG(LEV_ERROR, MOD_CAL, L"Couldn't load card plugin \"%ls\", err = 0x%0x",
              utilStringWiden(csPluginPath).c_str(), ulErr);
    }
    else
    {
        GETCARDINSTANCE pGetCardInstance =
            (GETCARDINSTANCE) oCardPluginLib.GetAddress(csGetCardInstanceName);
        if (pGetCardInstance == NULL)
        {
            MWLOG(LEV_ERROR, MOD_CAL, L"Function \"GetCardInstance\" not found in \"%ls\"",
                  utilStringWiden(csPluginPath).c_str());
        }
        else
        {
            poCard = pGetCardInstance(PLUGIN_VERSION, csReader, hCard, poContext, poPinpad);
            if (poCard)
            {
                MWLOG(LEV_DEBUG, MOD_CAL, L"    CardFactory: using plugin \"%ls\"",
                      utilStringWiden(csPluginPath).c_str());
            }
        }
    }

    return poCard;
}
Пример #2
0
/** 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;;
}
Пример #3
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());

}
Пример #4
0
// MWLOG(tLevel level, tModule mod, CMWEXCEPTION theException)
bool MWLOG(tLevel level, tModule mod, CMWException theException)
{

#ifdef DO_LOGGING

	//char buffer[256];
	//sprintf_s(buffer,sizeof(buffer), "Exception thrown at file = %s, line = %s", theException.GetFile(), theException.GetLine());
	//return MWLOG(level, mod, "  %s", buffer); 
	try
	{
		CLog &log=MapModule(mod);

		if (theException.GetLine()==0)
		{
			log.write(MapLevel(level),L"Exception 0x%0x thrown", theException.GetError());
		}
		else
		{
			int line = (int) theException.GetLine();
			log.write(MapLevel(level),line,utilStringWiden(theException.GetFile()).c_str(),L"Exception 0x%0x thrown",theException.GetError());
		}
	}
	catch(CMWException &e)
	{
		if(e.GetError()!=(long)EIDMW_ERR_LOGGER_APPLEAVING)
			throw e;

		return false;
	}

#endif

	return true;
} 
Пример #5
0
static CCard *ConnectGetCardInstance(const char *csReader,
                                     CContext *poContext, CPinpad *poPinpad,
                                     const std::string &csPluginPath, CDynamicLib &oCardPluginLib)
{
    CCard * poCard = NULL;

    try
    {
        unsigned long ulErr = oCardPluginLib.Open(csPluginPath);
        if (ulErr != EIDMW_OK)
        {
            MWLOG(LEV_ERROR, MOD_CAL, L"Couldn't load reader specific plugin \"%ls\", err = 0x%0x",
                  utilStringWiden(csPluginPath).c_str(), ulErr);
        }
        else
        {
            CONNECTGETCARDINSTANCE pConnectGetCardInstance =
                (CONNECTGETCARDINSTANCE) oCardPluginLib.GetAddress(csConnectGetCardInstanceName);
            if (pConnectGetCardInstance == NULL)
            {
                MWLOG(LEV_ERROR, MOD_CAL, L"Function \"ConnectGetCardInstance\" not found in \"%ls\"",
                      utilStringWiden(csPluginPath).c_str());
            }
            else
                poCard = pConnectGetCardInstance(PLUGIN_VERSION, csReader, poContext, poPinpad);
            if (poCard)
            {
                MWLOG(LEV_DEBUG, MOD_CAL, L"    CardFactory: connected via plugin \"%ls\"",
                      utilStringWiden(csPluginPath).c_str());
            }
        }
    }
    catch(CMWException &e)
    {
        MWLOG(LEV_ERROR, MOD_CAL, L"Exception in ConnectGetCardInstance(): err = 0x%0x\n", e.GetError());
    }
    catch (...)
    {
        MWLOG(LEV_ERROR, MOD_CAL, L"Unknown error in ConnectGetCardInstance()");
    }

    return poCard;
}
Пример #6
0
CReader::CReader(const std::string & csReader, CContext *poContext) :
	m_poCard(NULL), m_oPKCS15(poContext)
{
    m_csReader = csReader;
    m_wsReader = utilStringWiden(csReader);
    m_poContext = poContext;
    m_poCard = NULL;
    m_bIgnoreRemoval = false;
    m_oPinpad = new CPinpad(m_poContext, m_csReader); 	
}
Пример #7
0
void APL_CryptoFwk::resetProxy()
{
	APL_Config conf_pac(CConfig::EIDMW_CONFIG_PARAM_PROXY_PACFILE);     
	m_proxy_pac = conf_pac.getString();

	APL_Config conf_host(CConfig::EIDMW_CONFIG_PARAM_PROXY_HOST);     
	m_proxy_host = conf_host.getString();

	APL_Config conf_port(CConfig::EIDMW_CONFIG_PARAM_PROXY_PORT); 
	char buffer[10];
	sprintf_s(buffer,sizeof(buffer),"%ld",conf_port.getLong());
	m_proxy_port = buffer;

	MWLOG(LEV_INFO, MOD_SSL, L"Proxy settings: pac='%ls', host='%ls' and port=%ls",utilStringWiden(m_proxy_pac).c_str(),utilStringWiden(m_proxy_host).c_str(),utilStringWiden(m_proxy_port).c_str());
}
Пример #8
0
bool CPkiCard::AskPinRetry(tPinOperation operation, const tPin & Pin,
													 unsigned long ulRemaining, const tPrivKey *pKey)
{
	bool bRetry = false;
	bool bUsePinpad = m_poPinpad->UsePinpad(operation);

	// Bad PIN: show a dialog to ask the user to try again
	// PIN blocked: show a dialog to tell the user
	if (!bUsePinpad)
	{
		DlgPinUsage usage = PinUsage2Dlg(Pin, pKey);
		DlgRet dlgret = DlgBadPin(usage, utilStringWiden(Pin.csLabel).c_str(), ulRemaining);
		if (0 != ulRemaining && DLG_RETRY == dlgret)
			bRetry = true;
	}
	return bRetry;
}
Пример #9
0
CByteArray CPkiCard::ReadUncachedFile(const std::string & csPath,
    unsigned long ulOffset, unsigned long ulMaxLen)
{
    CByteArray oData(ulMaxLen);

	CAutoLock autolock(this);

    tFileInfo fileInfo = SelectFile(csPath, true);

    // Loop until we've read ulMaxLen bytes or until EOF (End Of File)
    bool bEOF = false;
    for (unsigned long i = 0; i < ulMaxLen && !bEOF; i += MAX_APDU_READ_LEN)
    {
        unsigned long ulLen = ulMaxLen - i <= MAX_APDU_READ_LEN ?
            ulMaxLen - i : MAX_APDU_READ_LEN;

        CByteArray oResp = ReadBinary(ulOffset + i, ulLen);

        unsigned long ulSW12 = getSW12(oResp);
		// If the file is a multiple of the block read size, you will get
		// an SW12 = 6B00 (at least with BE eID) but that OK then..
        if (ulSW12 == 0x9000 || (i != 0 && ulSW12 == 0x6B00))
            oData.Append(oResp.GetBytes(), oResp.Size() - 2);
		else if (ulSW12 == 0x6982) {
			throw CNotAuthenticatedException(
				EIDMW_ERR_NOT_AUTHENTICATED, fileInfo.lReadPINRef);
		}
		else if (ulSW12 == 0x6B00)
			throw CMWEXCEPTION(EIDMW_ERR_PARAM_RANGE);
		else if (ulSW12 == 0x6D00)
			throw CMWEXCEPTION(EIDMW_ERR_NOT_ACTIVATED);
		else
            throw CMWEXCEPTION(m_poContext->m_oPCSC.SW12ToErr(ulSW12));

        // If the driver/reader itself did the 6CXX handling,
        // we assume we're at the EOF
        if (oResp.Size() < MAX_APDU_READ_LEN)
            bEOF = true;
    }

	MWLOG(LEV_INFO, MOD_CAL, L"   Read file %ls (%d bytes) from card",
		utilStringWiden(csPath).c_str(), oData.Size());

    return oData;
}
Пример #10
0
void EIDCardType_Processor::process( const XMLCh *const  chars
	, const unsigned int  length 
	, DataStorage&		  dataStorage
	)
{
	displayName();

	std::wstring w_chars = FromXMLCh(chars);
	if ( 0 == w_chars.compare( utilStringWiden(CARDTYPE_NAME_PTEID_EID) ) )
	{
		((EID_DataStorage&)dataStorage).m_CardType = APL_CARDTYPE_PTEID_IAS101;
	}
	else
	{
		((EID_DataStorage&)dataStorage).m_CardType = APL_CARDTYPE_UNKNOWN;
	}

}
Пример #11
0
/*****************************************************************************************
---------------------------------------- EID_DataStorage --------------------------------------------
*****************************************************************************************/
EID_DataStorage::EID_DataStorage( void )
	: m_CardType( APL_CARDTYPE_UNKNOWN )
{
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_ID).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_IDSIGN).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_ADDR).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_ADDRSIGN).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_PHOTO).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_CARDINFO).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_TOKENINFO).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_CHALLENGE).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_CHALLENGE_RESPONSE).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_CERTS).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_CERTS_P15).c_str());
	m_EIDStoreFields.push_back(utilStringWiden(PTEID_XML_PATH_FILE_PINS_P15).c_str());
}
Пример #12
0
bool CPkiCard::PinCmd(tPinOperation operation, const tPin & Pin,
        const std::string & csPin1, const std::string & csPin2,
        unsigned long & ulRemaining, const tPrivKey *pKey)
{
	// No standard for Logoff, so each card has to implement
	// it's own command here.
	if (operation == PIN_OP_LOGOFF )
		return LogOff(Pin);

	bool bRet = false;
	std::string csReadPin1, csReadPin2;
	const std::string *pcsPin1 = &csPin1;
	const std::string *pcsPin2 = &csPin2;
	bool bAskPIN = csPin1.empty();
	bool bUsePinpad = bAskPIN ? m_poPinpad->UsePinpad(operation) : false;

bad_pin:
     //If no Pin(s) provided and it's no Pinpad reader -> ask Pins
    if (bAskPIN && !bUsePinpad)
	{
        showPinDialog(operation, Pin, csReadPin1, csReadPin2, pKey);
		pcsPin1 = &csReadPin1;
		pcsPin2 = &csReadPin2;
	}

    CByteArray oPinBuf = MakePinBuf(Pin, *pcsPin1, bUsePinpad);
    if (operation != PIN_OP_VERIFY)
        oPinBuf.Append(MakePinBuf(Pin, *pcsPin2, bUsePinpad));

    CByteArray oAPDU = MakePinCmd(operation, Pin); // add CLA, INS, P1, P2
    oAPDU.Append((unsigned char) oPinBuf.Size());  // add P3
    oAPDU.Append(oPinBuf);

	CByteArray oResp;
	bool bSelected = false;

	// Don't remove these brackets!!
	{
		CAutoLock autolock(this);

		// Select the path where the Pin is, if necessary
		if (!Pin.csPath.empty() && !bSelected && Pin.csPath != "3F00")
		{
			SelectFile(Pin.csPath);
			bSelected = true;
		}

		// Send the command
		if (csPin1.empty() && bUsePinpad)
			oResp = m_poPinpad->PinCmd(operation, Pin,
			PinUsage2Pinpad(Pin, pKey), oAPDU, ulRemaining);
		else
			oResp = SendAPDU(oAPDU);
	}

    unsigned long ulSW12 = getSW12(oResp);
    if (ulSW12 == 0x9000)
        bRet = true;
    else if (ulSW12 == 0x6983)
        ulRemaining = 0;
    else if (ulSW12 / 16 == 0x63C)
        ulRemaining = ulSW12 % 16;
	else
		throw CMWEXCEPTION(m_poContext->m_oPCSC.SW12ToErr(ulSW12));

#ifndef NO_DIALOGS
	// Bad PIN: show a dialog to ask the user to try again
	// PIN blocked: show a dialog to tell the user
	if (bAskPIN && !bRet)
	{
		DlgPinUsage usage = PinUsage2Dlg(Pin, pKey);
		DlgRet dlgret = DlgBadPin(usage, utilStringWiden(Pin.csLabel).c_str(), ulRemaining);
		if (0 != ulRemaining && DLG_RETRY == dlgret)
			goto bad_pin;
	}
#endif

	// If PIN command OK and no SSO, then state that we have now
	// verified this PIN, this info is needed in the Sign() method
	if (bRet && !m_poContext->m_bSSO)
	{
		bool bFound = false;
		for (size_t i = 0; i < m_verifiedPINs.size() && !bFound; i++)
			bFound = (m_verifiedPINs[i] == Pin.ulID);
		if (!bFound)
			m_verifiedPINs.push_back(Pin.ulID);
	}

	return bRet;
}
Пример #13
0
std::wstring CByteArray::ToWString(bool bAddSpace, bool bOneLine,
                                 unsigned long ulOffset, unsigned long ulLen) const
{
	return utilStringWiden(ToString(bAddSpace,bOneLine,ulOffset,ulLen));
}
Пример #14
0
tCardFileStatus APL_CardFile::LoadData(bool bForceReload)
{
	CAutoMutex autoMutex(&m_Mutex);		//We lock for only one instantiation

	std::wstring strPath = utilStringWiden(m_path);
	const wchar_t *wsPath= strPath.c_str();

	if(m_card!=NULL && (m_status==CARDFILESTATUS_UNREAD || bForceReload))
	{
		try
		{
			//Fill the m_data with the content of the file
			MWLOG(LEV_INFO, MOD_APL, L"LoadData: Ask for file %ls", wsPath);	//TODO replace by DEBUG
			ReadFile();
			MWLOG(LEV_INFO, MOD_APL, L"LoadData: Read file %ls ok", wsPath);	//TODO replace by DEBUG
		}
		catch(CMWException& e)
		{
			unsigned long err = e.GetError();
			if (err == EIDMW_ERR_FILE_NOT_FOUND)
			{
				MWLOG(LEV_INFO, MOD_APL, L"LoadData: File %ls not found", wsPath);
				m_status=CARDFILESTATUS_ERROR_NOFILE;
				return m_status;
			}

			if (err == EIDMW_ERR_CARD_COMM)
			{
				MWLOG(LEV_WARN, MOD_APL, L"LoadData: Could not read file : %ls - Error : 0x%x", wsPath,e.GetError());
				m_status=CARDFILESTATUS_ERROR_NOFILE;
				return m_status;
			}

			if (err == EIDMW_ERR_NOT_ACTIVATED)
			{
				MWLOG(LEV_WARN, MOD_APL, L"LoadData: Could not read file : %ls - Error : 0x%x", wsPath,e.GetError());
				m_status=CARDFILESTATUS_ERROR_NOFILE;
				return m_status;
			}

			MWLOG(LEV_ERROR, MOD_APL, L"LoadData: Could not read file : %ls - Error : 0x%x", wsPath,e.GetError());
			throw e;
		}
	}

	//Get the status
	//m_status=VerifyFile();
	m_status=CARDFILESTATUS_OK;

	//If Status ok, map the fields
	if(m_status==CARDFILESTATUS_OK)
		if(!MapFields())
			m_status=CARDFILESTATUS_ERROR_FORMAT;

	if(m_status!=CARDFILESTATUS_OK)
	{
		EmptyFields();
		if(!m_keepdata)
			m_data.ClearContents();
	}

	MWLOG(LEV_INFO, MOD_APL, L"LoadData: File : %ls - status : 0x%x", wsPath,m_status);

	return m_status;
}
Пример #15
0
void CLogger::init(const char *directory,const char *prefix,long filesize,long filenr,tLOG_Level maxlevel,bool groupinnewfile) 
{ 
	init(utilStringWiden(directory).c_str(),utilStringWiden(prefix).c_str(),filesize,filenr,maxlevel,groupinnewfile);
}
Пример #16
0
CLog &CLogger::getLogA(const char *group)
{
	return getLogW(utilStringWiden(group).c_str());
}
Пример #17
0
size_t EIDMW_XMLParser::getDataSize(const char* pPath)
{
	std::wstring wPath = utilStringWiden(std::string(pPath));
	return m_DataStorage.getDataSize(wPath);
}
Пример #18
0
const CByteArray* EIDMW_XMLParser::getData(const char* pPath, size_t idx)
{
	std::wstring wPath = utilStringWiden(std::string(pPath));
	return m_DataStorage.get(wPath,idx);
}