Skip to content
This repository has been archived by the owner on May 16, 2024. It is now read-only.

Commit

Permalink
Disable PinPAD when env variable is set
Browse files Browse the repository at this point in the history
WE2-640

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored and mrts committed Oct 11, 2022
1 parent 8c6bfdc commit d85c1f3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ target_compile_options(${PROJECT_NAME} PUBLIC
)

target_compile_definitions(${PROJECT_NAME} PUBLIC
$<$<CXX_COMPILER_ID:MSVC>:WIN32_LEAN_AND_MEAN;UNICODE>
$<$<CXX_COMPILER_ID:MSVC>:WIN32_LEAN_AND_MEAN;UNICODE;_CRT_SECURE_NO_WARNINGS>
)

target_link_libraries(${PROJECT_NAME} PRIVATE
Expand Down
14 changes: 6 additions & 8 deletions include/pcsc-cpp/pcsc-cpp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ struct ResponseApdu
WRONG_LE_LENGTH = 0x6c
};

byte_vector::value_type sw1;
byte_vector::value_type sw2;
byte_vector::value_type sw1 {};
byte_vector::value_type sw2 {};

byte_vector data;

Expand Down Expand Up @@ -148,9 +148,8 @@ struct CommandApdu
if (useLe) {
return CommandApdu {bytes[0], bytes[1], bytes[2],
bytes[3], byte_vector(), bytes[4]};
} else {
throw std::invalid_argument("Command APDU size 5 is invalid without LE");
}
throw std::invalid_argument("Command APDU size 5 is invalid without LE");
}

if (bytes.size() == 6 && useLe) {
Expand All @@ -168,10 +167,9 @@ struct CommandApdu
bytes[3],
byte_vector(dataStart, bytes.cend() - 1),
*(bytes.cend() - 1)};
} else {
return CommandApdu {bytes[0], bytes[1], bytes[2], bytes[3],
byte_vector(dataStart, bytes.cend())};
}
return CommandApdu {bytes[0], bytes[1], bytes[2], bytes[3],
byte_vector(dataStart, bytes.cend())};
}

byte_vector toBytes() const
Expand Down Expand Up @@ -230,7 +228,7 @@ class SmartCard
bool& inProgress;
};

SmartCard(const ContextPtr& context, const string_t& readerName, const byte_vector& atr);
SmartCard(const ContextPtr& context, const string_t& readerName, byte_vector atr);
~SmartCard();

// The rule of five.
Expand Down
23 changes: 16 additions & 7 deletions src/SmartCard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <arpa/inet.h>
#endif

#include <array>
#include <map>
#include <utility>

Expand Down Expand Up @@ -81,10 +82,10 @@ class CardImpl
// TODO: debug("Protocol: " + to_string(protocol()));
try {
DWORD size = 0;
BYTE feature[256];
SCard(Control, cardHandle, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0u, feature,
DWORD(sizeof(feature)), &size);
for (unsigned char* p = feature; DWORD(p - feature) < size;) {
std::array<BYTE, 256> feature {};
SCard(Control, cardHandle, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0U,
feature.data(), DWORD(feature.size()), &size);
for (auto p = feature.cbegin(); DWORD(std::distance(feature.cbegin(), p)) < size;) {
unsigned int tag = *p++;
unsigned int len = *p++;
unsigned int value = 0;
Expand All @@ -108,8 +109,16 @@ class CardImpl
}
}

// The rule of five (C++ Core guidelines C.21).
CardImpl(const CardImpl& other) = delete;
CardImpl(CardImpl&& other) noexcept = delete;
CardImpl& operator=(const CardImpl& other) = delete;
CardImpl& operator=(CardImpl&& other) noexcept = delete;

bool readerHasPinPad() const
{
if (getenv("SMARTCARDPP_NOPINPAD"))
return false;
return features.find(FEATURE_VERIFY_PIN_START) != features.cend()
|| features.find(FEATURE_VERIFY_PIN_DIRECT) != features.cend();
}
Expand Down Expand Up @@ -169,7 +178,7 @@ class CardImpl
if (features.find(FEATURE_VERIFY_PIN_FINISH) != features.cend()) {
DWORD finish = features.at(FEATURE_VERIFY_PIN_FINISH);
responseLength = DWORD(responseBytes.size());
SCard(Control, cardHandle, finish, nullptr, 0u, LPVOID(responseBytes.data()),
SCard(Control, cardHandle, finish, nullptr, 0U, LPVOID(responseBytes.data()),
DWORD(responseBytes.size()), &responseLength);
}

Expand Down Expand Up @@ -257,9 +266,9 @@ SmartCard::TransactionGuard::~TransactionGuard()
}
}

SmartCard::SmartCard(const ContextPtr& contex, const string_t& readerName, const byte_vector& atr) :
SmartCard::SmartCard(const ContextPtr& contex, const string_t& readerName, byte_vector atr) :
card(std::make_unique<CardImpl>(connectToCard(contex->handle(), readerName))),
_protocol(convertToSmartCardProtocol(card->protocol())), _atr(atr)
_protocol(convertToSmartCardProtocol(card->protocol())), _atr(std::move(atr))
{
// TODO: debug("Card ATR -> " + bytes2hexstr(atr));
}
Expand Down

0 comments on commit d85c1f3

Please sign in to comment.