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

Commit d85c1f3

Browse files
metsmamrts
authored andcommitted
Disable PinPAD when env variable is set
WE2-640 Signed-off-by: Raul Metsma <[email protected]>
1 parent 8c6bfdc commit d85c1f3

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ target_compile_options(${PROJECT_NAME} PUBLIC
3838
)
3939

4040
target_compile_definitions(${PROJECT_NAME} PUBLIC
41-
$<$<CXX_COMPILER_ID:MSVC>:WIN32_LEAN_AND_MEAN;UNICODE>
41+
$<$<CXX_COMPILER_ID:MSVC>:WIN32_LEAN_AND_MEAN;UNICODE;_CRT_SECURE_NO_WARNINGS>
4242
)
4343

4444
target_link_libraries(${PROJECT_NAME} PRIVATE

include/pcsc-cpp/pcsc-cpp.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ struct ResponseApdu
6262
WRONG_LE_LENGTH = 0x6c
6363
};
6464

65-
byte_vector::value_type sw1;
66-
byte_vector::value_type sw2;
65+
byte_vector::value_type sw1 {};
66+
byte_vector::value_type sw2 {};
6767

6868
byte_vector data;
6969

@@ -148,9 +148,8 @@ struct CommandApdu
148148
if (useLe) {
149149
return CommandApdu {bytes[0], bytes[1], bytes[2],
150150
bytes[3], byte_vector(), bytes[4]};
151-
} else {
152-
throw std::invalid_argument("Command APDU size 5 is invalid without LE");
153151
}
152+
throw std::invalid_argument("Command APDU size 5 is invalid without LE");
154153
}
155154

156155
if (bytes.size() == 6 && useLe) {
@@ -168,10 +167,9 @@ struct CommandApdu
168167
bytes[3],
169168
byte_vector(dataStart, bytes.cend() - 1),
170169
*(bytes.cend() - 1)};
171-
} else {
172-
return CommandApdu {bytes[0], bytes[1], bytes[2], bytes[3],
173-
byte_vector(dataStart, bytes.cend())};
174170
}
171+
return CommandApdu {bytes[0], bytes[1], bytes[2], bytes[3],
172+
byte_vector(dataStart, bytes.cend())};
175173
}
176174

177175
byte_vector toBytes() const
@@ -230,7 +228,7 @@ class SmartCard
230228
bool& inProgress;
231229
};
232230

233-
SmartCard(const ContextPtr& context, const string_t& readerName, const byte_vector& atr);
231+
SmartCard(const ContextPtr& context, const string_t& readerName, byte_vector atr);
234232
~SmartCard();
235233

236234
// The rule of five.

src/SmartCard.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#include <arpa/inet.h>
3232
#endif
3333

34+
#include <array>
3435
#include <map>
3536
#include <utility>
3637

@@ -81,10 +82,10 @@ class CardImpl
8182
// TODO: debug("Protocol: " + to_string(protocol()));
8283
try {
8384
DWORD size = 0;
84-
BYTE feature[256];
85-
SCard(Control, cardHandle, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0u, feature,
86-
DWORD(sizeof(feature)), &size);
87-
for (unsigned char* p = feature; DWORD(p - feature) < size;) {
85+
std::array<BYTE, 256> feature {};
86+
SCard(Control, cardHandle, DWORD(CM_IOCTL_GET_FEATURE_REQUEST), nullptr, 0U,
87+
feature.data(), DWORD(feature.size()), &size);
88+
for (auto p = feature.cbegin(); DWORD(std::distance(feature.cbegin(), p)) < size;) {
8889
unsigned int tag = *p++;
8990
unsigned int len = *p++;
9091
unsigned int value = 0;
@@ -108,8 +109,16 @@ class CardImpl
108109
}
109110
}
110111

112+
// The rule of five (C++ Core guidelines C.21).
113+
CardImpl(const CardImpl& other) = delete;
114+
CardImpl(CardImpl&& other) noexcept = delete;
115+
CardImpl& operator=(const CardImpl& other) = delete;
116+
CardImpl& operator=(CardImpl&& other) noexcept = delete;
117+
111118
bool readerHasPinPad() const
112119
{
120+
if (getenv("SMARTCARDPP_NOPINPAD"))
121+
return false;
113122
return features.find(FEATURE_VERIFY_PIN_START) != features.cend()
114123
|| features.find(FEATURE_VERIFY_PIN_DIRECT) != features.cend();
115124
}
@@ -169,7 +178,7 @@ class CardImpl
169178
if (features.find(FEATURE_VERIFY_PIN_FINISH) != features.cend()) {
170179
DWORD finish = features.at(FEATURE_VERIFY_PIN_FINISH);
171180
responseLength = DWORD(responseBytes.size());
172-
SCard(Control, cardHandle, finish, nullptr, 0u, LPVOID(responseBytes.data()),
181+
SCard(Control, cardHandle, finish, nullptr, 0U, LPVOID(responseBytes.data()),
173182
DWORD(responseBytes.size()), &responseLength);
174183
}
175184

@@ -257,9 +266,9 @@ SmartCard::TransactionGuard::~TransactionGuard()
257266
}
258267
}
259268

260-
SmartCard::SmartCard(const ContextPtr& contex, const string_t& readerName, const byte_vector& atr) :
269+
SmartCard::SmartCard(const ContextPtr& contex, const string_t& readerName, byte_vector atr) :
261270
card(std::make_unique<CardImpl>(connectToCard(contex->handle(), readerName))),
262-
_protocol(convertToSmartCardProtocol(card->protocol())), _atr(atr)
271+
_protocol(convertToSmartCardProtocol(card->protocol())), _atr(std::move(atr))
263272
{
264273
// TODO: debug("Card ATR -> " + bytes2hexstr(atr));
265274
}

0 commit comments

Comments
 (0)