Skip to content

Commit

Permalink
Skip reading non eid-cards
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Charlier authored and Thomas Charlier committed May 13, 2024
1 parent a98e904 commit 168f89b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 18 deletions.
60 changes: 43 additions & 17 deletions cardcomm/pkcs11/src/cardlayer/card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -728,24 +728,35 @@ namespace eIDMW
SCARDHANDLE hCard, CPCSC * poPCSC, CPinpad * poPinpad)
{
CCard * poCard = NULL;

try
{
bool bIsBeidCard = BeidCardSelectApplet(poPCSC, hCard);

if (bIsBeidCard)
static int iFailingnCount = 0;
try
{
poCard = new CCard(hCard, poPCSC, poPinpad, TRY_SELECT_APPLET, CARD_BEID);
bool bIsBeidCard = BeidCardSelectApplet(poPCSC, hCard);
if (getReaderToSkip() != csReader || bIsBeidCard) {
if (bIsBeidCard)
{
UnlockReader();
poCard = new CCard(hCard, poPCSC, poPinpad, TRY_SELECT_APPLET, CARD_BEID);
}
else
{
//Let the chance to eid card to connect
if (iFailingnCount < 5)
{
iFailingnCount++;
}
else
{
LockReader(csReader);
}
poCard = new CCard(hCard, poPCSC, poPinpad, DONT_SELECT_APPLET, CARD_UNKNOWN);
}
}
}
else
catch (...)
{
poCard = new CCard(hCard, poPCSC, poPinpad, DONT_SELECT_APPLET, CARD_UNKNOWN);
MWLOG(LEV_ERROR, MOD_CAL, L"Exception in cardPluginBeid.CardGetInstance()");
}
}
catch (...)
{
MWLOG(LEV_ERROR, MOD_CAL, L"Exception in cardPluginBeid.CardGetInstance()");
}

return poCard;
}
Expand Down Expand Up @@ -1030,10 +1041,10 @@ namespace eIDMW

CByteArray oAPDU(7 + oData.Size());

oAPDU.Append(0x00); // CLA ‘00’ or ‘10’(chaining)
oAPDU.Append(0x88); // INS ‘88’ (Internal authenticate)
oAPDU.Append(0x00); // CLA ‘00’ or ‘10’(chaining)
oAPDU.Append(0x88); // INS ‘88’ (Internal authenticate)
oAPDU.Append(0x02); // P1 Algorithm reference(ECDSA SHA-2-384)
oAPDU.Append(0x81); // P2 Private key reference(‘81’(basic key)
oAPDU.Append(0x81); // P2 Private key reference(‘81’(basic key)
oAPDU.Append((unsigned char)oData.Size() + 2); // length of following bytes
oAPDU.Append(0x94); // Tag (for challenge is 0x94)
oAPDU.Append((unsigned char)oData.Size()); // Length of data
Expand Down Expand Up @@ -1602,6 +1613,21 @@ namespace eIDMW
return oBuf;
}

void LockReader(const char* csReader)
{
csReaderToSkip = csReader;
}

void UnlockReader()
{
csReaderToSkip = "";
}

const char* getReaderToSkip()
{
return csReaderToSkip;
}

////////////////////////////////////////////////////////////////:

CAutoLock::CAutoLock(CCard * poCard) :m_poCard(poCard), m_poPCSC(NULL), m_hCard(0)
Expand Down
8 changes: 7 additions & 1 deletion cardcomm/pkcs11/src/cardlayer/card.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ namespace eIDMW
const static tPin PinInvalid = { false, "", 0, 0, 0, 0, 0 };
const static tPin PinBeid = { true, "Basic PIN", 1, 0, 4, 12, 8 };

static const char* csReaderToSkip;

class CCard
{
public:
Expand Down Expand Up @@ -220,7 +222,7 @@ namespace eIDMW

void SetSecurityEnv(const tPrivKey & key, unsigned long algo, unsigned long ulInputLen);
CByteArray SignInternal(const tPrivKey & key, unsigned long algo, const CByteArray & oData,
const tPin * pPin = NULL);
const tPin * pPin = NULL);

CPCSC *m_poPCSC;
CPinpad *m_poPinpad;
Expand Down Expand Up @@ -276,6 +278,10 @@ namespace eIDMW

CCard *UnknownCardGetInstance(const char *csReader,
SCARDHANDLE hCard, CPCSC * poPCSC, CPinpad * poPinpad);

void LockReader(const char* csReader);
void UnlockReader();
const char* getReaderToSkip();
}

#endif

0 comments on commit 168f89b

Please sign in to comment.