LibLogicalAccess  2.5.0
An Open Source RFID Library
Loading...
Searching...
No Matches
desfireev1iso7816commands.hpp
Go to the documentation of this file.
1
7#ifndef LOGICALACCESS_DESFIREEV1ISO7816COMMANDS_HPP
8#define LOGICALACCESS_DESFIREEV1ISO7816COMMANDS_HPP
9
13#include <logicalaccess/plugins/readers/iso7816/lla_readers_iso7816_api.hpp>
14#include <string>
15#include <vector>
16#include <iostream>
17
18namespace logicalaccess
19{
20#define DESFIREEV1_CLEAR_DATA_LENGTH_CHUNK 60
21#define CMD_DESFIREEV1ISO7816 "DESFireEV1ISO7816"
22
26class LLA_READERS_ISO7816_API DESFireEV1ISO7816Commands : public DESFireISO7816Commands
27#ifndef SWIG
28 ,
30#endif
31{
32 public:
37
38 explicit DESFireEV1ISO7816Commands(std::string ct);
39
44
49 unsigned int getFreeMem() override;
50
55 std::vector<DFName> getDFNames() override;
56
62 std::vector<unsigned short> getISOFileIDs() override;
63#ifndef SWIG
64 using DESFireISO7816Commands::createApplication;
65#endif
66
73 void createApplication(unsigned int aid, DESFireKeySettings settings,
74 unsigned char maxNbKeys, DESFireKeyType cryptoMethod,
75 FidSupport fidSupported = FIDS_NO_ISO_FID,
76 unsigned short isoFID = 0x00,
77 ByteVector isoDFName = ByteVector()) override;
78#ifndef SWIG
79 using DESFireISO7816Commands::getKeySettings;
80#endif
81
88 void getKeySettings(DESFireKeySettings &settings, unsigned char &maxNbKeys,
89 DESFireKeyType &keyType) override;
90
95 ByteVector getCardUID() override;
96#ifndef SWIG
97 using DESFireISO7816Commands::createStdDataFile;
98#endif
99
107 void createStdDataFile(unsigned char fileno, EncryptionMode comSettings,
108 const DESFireAccessRights &accessRights, unsigned int fileSize,
109 unsigned short isoFID) override;
110#ifndef SWIG
111 using DESFireISO7816Commands::createBackupFile;
112#endif
113
121 void createBackupFile(unsigned char fileno, EncryptionMode comSettings,
122 const DESFireAccessRights &accessRights, unsigned int fileSize,
123 unsigned short isoFID) override;
124#ifndef SWIG
125 using DESFireISO7816Commands::createLinearRecordFile;
126#endif
127
136 void createLinearRecordFile(unsigned char fileno, EncryptionMode comSettings,
137 const DESFireAccessRights &accessRights,
138 unsigned int fileSize, unsigned int maxNumberOfRecords,
139 unsigned short isoFID) override;
140#ifndef SWIG
141 using DESFireISO7816Commands::createCyclicRecordFile;
142#endif
143
152 void createCyclicRecordFile(unsigned char fileno, EncryptionMode comSettings,
153 const DESFireAccessRights &accessRights,
154 unsigned int fileSize, unsigned int maxNumberOfRecords,
155 unsigned short isoFID) override;
156
165 virtual void iso_authenticate(std::shared_ptr<DESFireKey> key,
167 bool isMasterCardKey = true,
168 unsigned char keyno = 0x00);
169
170 // Only for AES PKCS key.
171 void pkcs_iso_authenticate(std::shared_ptr<DESFireKey> key,
172 bool isMasterCardKey = true, unsigned char keyno = 0x00);
173
179 void authenticate(unsigned char keyno, std::shared_ptr<DESFireKey> key) override;
180
186 void authenticateISO(unsigned char keyno,
187 DESFireISOAlgorithm algorithm = DF_ALG_2K3DES) override;
188
193 void authenticateAES(unsigned char keyno) override;
194 void iks_authenticateAES(std::shared_ptr<DESFireKey> key, uint8_t keyno);
195
204 ByteVector readData(unsigned char fileno, unsigned int offset, unsigned int length,
205 EncryptionMode mode) override;
206
216 ByteVector readRecords(unsigned char fileno, unsigned int offset, unsigned int length,
217 EncryptionMode mode) override;
218
226 void changeFileSettings(unsigned char fileno, EncryptionMode comSettings,
227 const DESFireAccessRights &accessRights, bool plain) override;
228
233 void changeKeySettings(DESFireKeySettings settings) override;
234
240 void changeKey(unsigned char keyno, std::shared_ptr<DESFireKey> key) override;
241
246 DESFireCardVersion getVersion() override;
247
252 std::vector<unsigned int> getApplicationIDs() override;
253
259 ByteVector getFileIDs() override;
260
267 int32_t getValue(unsigned char fileno, EncryptionMode mode) override;
268
274 void setConfiguration(bool formatCardEnabled, bool randomIdEnabled) override;
275
280 void setConfiguration(std::shared_ptr<DESFireKey> defaultKey) override;
281
286 void setConfiguration(const ByteVector &ats) override;
287
288 virtual void sam_iso_authenticate(std::shared_ptr<DESFireKey> key,
289 DESFireISOAlgorithm algorithm, bool isMasterCardKey,
290 unsigned char keyno);
291
297 virtual void iks_iso_authenticate(std::shared_ptr<DESFireKey> key,
298 bool isMasterCardKey, uint8_t keyno);
299
300 MyDivInfo extract_iks_div_info(std::shared_ptr<Key> key, uint8_t keyno);
301
302 void selectApplication(unsigned int aid) override;
303
308 std::shared_ptr<Chip> getChip() const override
309 {
310 return DESFireISO7816Commands::getChip();
311 }
312
317 std::shared_ptr<ReaderCardAdapter> getReaderCardAdapter() const override
318 {
319 return DESFireISO7816Commands::getReaderCardAdapter();
320 }
321
322 std::shared_ptr<ISO7816Commands> getISO7816Commands() const override
323 {
324 auto command = std::make_shared<ISO7816ISO7816Commands>();
325 command->setChip(getChip());
326 command->setReaderCardAdapter(getReaderCardAdapter());
327 return command;
328 }
329
338 SignatureResult IKS_getLastReadSignature() const override;
339
340 protected:
348 virtual ISO7816Response handleReadCmd(unsigned char cmd, const ByteVector &data,
349 EncryptionMode mode);
350
359 ByteVector handleReadData(unsigned char err, const ByteVector &firstMsg,
360 unsigned int length, EncryptionMode mode) override;
361
369 void handleWriteData(unsigned char cmd, const ByteVector &parameters,
370 const ByteVector &data, EncryptionMode mode) override;
371
380 ISO7816Response transmit(unsigned char cmd, const ByteVector &buf = ByteVector(),
381 unsigned char lc = 0, bool forceLc = false) override;
382
389 virtual ISO7816Response transmit_plain(unsigned char cmd, unsigned char lc);
390
399 virtual ISO7816Response transmit_plain(unsigned char cmd,
400 const ByteVector &buf = ByteVector(),
401 unsigned char lc = 0, bool forceLc = false);
402
409 virtual ISO7816Response transmit_nomacv(unsigned char cmd, unsigned char lc);
410
419 virtual ISO7816Response transmit_nomacv(unsigned char cmd,
420 const ByteVector &buf = ByteVector(),
421 unsigned char lc = 0, bool forceLc = false);
422
426 void onAuthenticated();
427
428 protected:
430};
431}
432
433#endif /* LOGICALACCESS_DESFIREEV1ISO7816COMMANDS_HPP */
The DESFire EV1 base commands class.
Definition: desfireev1commands.hpp:76
The DESFire EV1 base commands class.
Definition: desfireev1iso7816commands.hpp:31
SignatureResult handle_read_data_last_sig_
Definition: desfireev1iso7816commands.hpp:429
std::shared_ptr< ReaderCardAdapter > getReaderCardAdapter() const override
Get the reader/card adapter.
Definition: desfireev1iso7816commands.hpp:317
std::shared_ptr< Chip > getChip() const override
Get the chip.
Definition: desfireev1iso7816commands.hpp:308
std::shared_ptr< ISO7816Commands > getISO7816Commands() const override
Definition: desfireev1iso7816commands.hpp:322
The DESFire base commands class.
Definition: desfireiso7816commands.hpp:30
A ISO7816 response message.
Definition: iso7816response.hpp:21
DESFire EV1 commands.
std::vector< uint8_t > ByteVector
Definition: lla_fwd.hpp:80
Definition: asn1.hpp:9
FidSupport
The FID Support for ISO 7816.
Definition: desfireev1commands.hpp:49
@ FIDS_NO_ISO_FID
Definition: desfireev1commands.hpp:49
EncryptionMode
The file communication mode (or encryption mode)
Definition: desfirelocation.hpp:18
DESFireKeySettings
The key settings.
Definition: desfirecommands.hpp:69
DESFireISOAlgorithm
The DESFire EV1 algorithm.
Definition: desfireev1commands.hpp:63
@ DF_ALG_2K3DES
Definition: desfireev1commands.hpp:65
DESFireKeyType
The DESFire key type.
Definition: desfirekey.hpp:33
Access rights on DESFire file.
Definition: desfirecommands.hpp:106
Card information about software and hardware version.
Definition: desfirecommands.hpp:212
Definition: RemoteCrypto.hpp:24
Definition: RemoteCrypto.hpp:9