Keyple Card Calypso C++ Library 2.1.0
Reference Terminal Reader API for C++
CalypsoCardAdapter.cpp
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#include "CalypsoCardAdapter.h"
14
15/* Calypsonet Terminal Calypso */
16#include "FileHeader.h"
17
18/* Keyple Core Util */
19#include "ByteArrayUtil.h"
20#include "IllegalArgumentException.h"
21#include "IllegalStateException.h"
22#include "KeypleStd.h"
23#include "System.h"
24
25/* Keyple Core Calypso */
26#include "CalypsoCardConstant.h"
27#include "CmdCardGetDataFci.h"
30
31namespace keyple {
32namespace card {
33namespace calypso {
34
35using namespace calypsonet::terminal::calypso;
36using namespace keyple::core::util;
37using namespace keyple::core::util::cpp;
38using namespace keyple::core::util::cpp::exception;
39
40const std::string CalypsoCardAdapter::PATTERN_1_BYTE_HEX = "%02Xh";
41const std::string CalypsoCardAdapter::PATTERN_2_BYTES_HEX = "%04Xh";
42
43const int CalypsoCardAdapter::CARD_REV1_ATR_LENGTH = 20;
44const int CalypsoCardAdapter::REV1_CARD_DEFAULT_WRITE_OPERATIONS_NUMBER_SUPPORTED_PER_SESSION = 3;
45const int CalypsoCardAdapter::REV2_CARD_DEFAULT_WRITE_OPERATIONS_NUMBER_SUPPORTED_PER_SESSION = 6;
46const int CalypsoCardAdapter::SI_BUFFER_SIZE_INDICATOR = 0;
47const int CalypsoCardAdapter::SI_PLATFORM = 1;
48const int CalypsoCardAdapter::SI_APPLICATION_TYPE = 2;
49const int CalypsoCardAdapter::SI_APPLICATION_SUBTYPE = 3;
50const int CalypsoCardAdapter::SI_SOFTWARE_ISSUER = 4;
51const int CalypsoCardAdapter::SI_SOFTWARE_VERSION = 5;
52const int CalypsoCardAdapter::SI_SOFTWARE_REVISION = 6;
53const uint8_t CalypsoCardAdapter::PAY_LOAD_CAPACITY = 250;
54
55const uint8_t CalypsoCardAdapter::APP_TYPE_WITH_CALYPSO_PIN = 0x01;
56const uint8_t CalypsoCardAdapter::APP_TYPE_WITH_CALYPSO_SV = 0x02;
57const uint8_t CalypsoCardAdapter::APP_TYPE_RATIFICATION_COMMAND_REQUIRED = 0x04;
58const uint8_t CalypsoCardAdapter::APP_TYPE_CALYPSO_REV_32_MODE = 0x08;
59const uint8_t CalypsoCardAdapter::APP_TYPE_WITH_PUBLIC_AUTHENTICATION = 0x10;
60
61const std::vector<int> CalypsoCardAdapter::BUFFER_SIZE_INDICATOR_TO_BUFFER_SIZE = {
62 0, 0, 0, 0, 0, 0, 215, 256, 304, 362, 430, 512, 608, 724, 861, 1024, 1217, 1448, 1722, 2048,
63 2435, 2896, 3444, 4096, 4870, 5792, 6888, 8192, 9741, 11585, 13777, 16384, 19483, 23170,
64 27554, 32768, 38967, 46340, 55108, 65536, 77935, 92681, 110217, 131072, 155871, 185363,
65 220435, 262144, 311743, 370727, 440871, 524288, 623487, 741455, 881743, 1048576
66};
67
69: mIsExtendedModeSupported(false),
70 mIsRatificationOnDeselectSupported(false),
71 mIsSvFeatureAvailable(false),
72 mIsPinFeatureAvailable(false),
73 mIsPkiModeSupported(false),
74 mIsDfInvalidated(false),
75 mCalypsoCardClass(CalypsoCardClass::UNKNOWN),
76 mProductType(ProductType::UNKNOWN),
77 mModificationsCounterMax(0),
78 mIsModificationCounterInBytes(true),
79 mCurrentSfi(0),
80 mCurrentLid(0),
81 mSvLastTNum(0),
82 mIsHce(false),
83 mSvKvc(0),
84 mApplicationSubType(0),
85 mApplicationType(0),
86 mSessionModification(0) {}
87
88void CalypsoCardAdapter::initializeWithPowerOnData(const std::string& powerOnData)
89{
90 mPowerOnData = powerOnData;
91
92 /*
93 * FCI is not provided: we consider it is Calypso card rev 1, it's serial number is provided in
94 * the ATR.
95 */
96 const std::vector<uint8_t> atr = ByteArrayUtil::fromHex(powerOnData);
97
98 /* Basic check: we expect to be here following a selection based on the ATR */
99 if (atr.size() != CARD_REV1_ATR_LENGTH) {
100 throw IllegalArgumentException("Unexpected ATR length: " + powerOnData);
101 }
102
103 mDfName.clear();
104 mCalypsoSerialNumber = std::vector<uint8_t>(8);
105
106 /*
107 * Old cards have their modification counter in number of commands the array is initialized with
108 * 0 (cf. default value for primitive types).
109 */
110 System::arraycopy(atr, 12, mCalypsoSerialNumber, 4, 4);
111 mModificationsCounterMax = REV1_CARD_DEFAULT_WRITE_OPERATIONS_NUMBER_SUPPORTED_PER_SESSION;
112
113 mStartupInfo = std::vector<uint8_t>(7);
114
115 /* Create buffer size indicator */
116 mStartupInfo[0] = static_cast<uint8_t>(mModificationsCounterMax);
117
118 /* Create the startup info with the 6 bytes of the ATR from position 6 */
119 System::arraycopy(atr, 6, mStartupInfo, 1, 6);
120
121 mIsRatificationOnDeselectSupported = true;
122
123 mProductType = ProductType::PRIME_REVISION_1;
124 mCalypsoCardClass = CalypsoCardClass::LEGACY;
125}
126
128 const std::shared_ptr<ApduResponseApi> selectApplicationResponse)
129{
130 mSelectApplicationResponse = selectApplicationResponse;
131
132 if (selectApplicationResponse->getDataOut().size() == 0) {
133 /* No FCI provided. May be filled later with a Get Data response */
134 return;
135 }
136
137 /*
138 * Parse card FCI - to retrieve DF Name (AID), Serial Number, &amp; StartupInfo
139 * CL-SEL-TLVSTRUC.1
140 */
141 auto cardGetDataFci = std::make_shared<CmdCardGetDataFci>();
142 const auto& cmdCardGetDataFci = cardGetDataFci->setApduResponse(selectApplicationResponse);
143
144 if (!cmdCardGetDataFci.isValidCalypsoFCI()) {
145 throw IllegalArgumentException("Bad FCI format.");
146 }
147
148 mIsDfInvalidated = cmdCardGetDataFci.isDfInvalidated();
149
150 /* CL-SEL-DATA.1 */
151 mDfName = cmdCardGetDataFci.getDfName();
152 mCalypsoSerialNumber = cmdCardGetDataFci.getApplicationSerialNumber();
153
154 /* CL-SI-OTHER.1 */
155 mStartupInfo = cmdCardGetDataFci.getDiscretionaryData();
156
157 /*
158 * CL-SI-ATRFU.1
159 * CL-SI-ATPRIME.1
160 * CL-SI-ATB6B5.1
161 * CL-SI-ATLIGHT.1
162 * CL-SI-ATBASIC.1
163 */
164 mApplicationType = mStartupInfo[SI_APPLICATION_TYPE];
165 mProductType = computeProductType(mApplicationType & 0xFF);
166
167 /* CL-SI-ASRFU.1 */
168 mApplicationSubType = mStartupInfo[SI_APPLICATION_SUBTYPE];
169 if (mApplicationSubType == 0x00 || mApplicationSubType == 0xFF) {
170 throw IllegalArgumentException("Unexpected application subtype: " +
171 std::to_string(mApplicationSubType));
172 }
173
174 mSessionModification = mStartupInfo[SI_BUFFER_SIZE_INDICATOR];
175
176 if (mProductType == ProductType::PRIME_REVISION_2) {
177 mCalypsoCardClass = CalypsoCardClass::LEGACY;
178
179 /* Old cards have their modification counter in number of commands */
180 mIsModificationCounterInBytes = false;
181 mModificationsCounterMax = REV2_CARD_DEFAULT_WRITE_OPERATIONS_NUMBER_SUPPORTED_PER_SESSION;
182
183 } else if (mProductType == ProductType::BASIC) {
184 /* CL-SI-SMBASIC.1 */
185 if (mSessionModification < 0x04 || mSessionModification > 0x37) {
186 throw IllegalArgumentException("Wrong session modification value for a Basic type " \
187 "(should be between 04h and 37h): " +
188 std::to_string(mSessionModification));
189 }
190
191 mCalypsoCardClass = CalypsoCardClass::ISO;
192 mIsModificationCounterInBytes = false;
193 mModificationsCounterMax = 3; // TODO Verify this
194 } else {
195 mCalypsoCardClass = CalypsoCardClass::ISO;
196
197 /*
198 * Session buffer size
199 * CL-SI-SM.1
200 */
201 if (mSessionModification < 0x06 || mSessionModification > 0x37) {
202 throw IllegalArgumentException("Session modifications byte should be in range 06h to" \
203 " 47h. Was: " +
204 std::to_string(mSessionModification));
205 }
206
207 mModificationsCounterMax = BUFFER_SIZE_INDICATOR_TO_BUFFER_SIZE[mSessionModification];
208 }
209
210 /* CL-SI-ATOPT.1 */
211 if (mProductType == ProductType::PRIME_REVISION_3) {
212 mIsExtendedModeSupported = (mApplicationType & APP_TYPE_CALYPSO_REV_32_MODE) != 0;
213 mIsRatificationOnDeselectSupported =
214 (mApplicationType & APP_TYPE_RATIFICATION_COMMAND_REQUIRED) == 0;
215 mIsPkiModeSupported = (mApplicationType & APP_TYPE_WITH_PUBLIC_AUTHENTICATION) != 0;
216 }
217
218 if (mProductType == ProductType::PRIME_REVISION_3 ||
219 mProductType == ProductType::PRIME_REVISION_2) {
220 mIsSvFeatureAvailable = (mApplicationType & APP_TYPE_WITH_CALYPSO_SV) != 0;
221 mIsPinFeatureAvailable = (mApplicationType & APP_TYPE_WITH_CALYPSO_PIN) != 0;
222 }
223
224 mIsHce = (mCalypsoSerialNumber[3] & 0x80) == 0x80;
225}
226
227CalypsoCard::ProductType CalypsoCardAdapter::computeProductType(const int applicationType) const
228{
229 if (applicationType == 0) {
230 throw IllegalArgumentException("Invalid application type 00h");
231 } else if (applicationType == 0xFF) {
232 return ProductType::UNKNOWN;
233 } else if (applicationType <= 0x1F) {
234 return ProductType::PRIME_REVISION_2;
235 } else if (applicationType >= 0x90 && applicationType <= 0x97) {
236 return ProductType::LIGHT;
237 } else if (applicationType >= 0x98 && applicationType <= 0x9F) {
238 return ProductType::BASIC;
239 }
240
241 return ProductType::PRIME_REVISION_3;
242}
243
245{
246 return mProductType;
247}
248
250{
251 return mIsHce;
252}
253
254const std::vector<uint8_t>& CalypsoCardAdapter::getDfName() const
255{
256 return mDfName;
257}
258
259const std::vector<uint8_t>& CalypsoCardAdapter::getCalypsoSerialNumberFull() const
260{
261 return mCalypsoSerialNumber;
262}
263
264const std::vector<uint8_t> CalypsoCardAdapter::getApplicationSerialNumber() const
265{
266 std::vector<uint8_t> applicationSerialNumber = mCalypsoSerialNumber;
267 applicationSerialNumber[0] = 0;
268 applicationSerialNumber[1] = 0;
269
270 return applicationSerialNumber;
271}
272
273const std::vector<uint8_t>& CalypsoCardAdapter::getStartupInfoRawData() const
274{
275 return mStartupInfo;
276}
277
279{
280 // TODO make this value dependent on the type of card identified
281 return PAY_LOAD_CAPACITY;
282}
283
285{
286 return mIsModificationCounterInBytes;
287}
288
290{
291 return mModificationsCounterMax;
292}
293
295{
296 return mStartupInfo[SI_PLATFORM];
297}
298
300{
301 return mApplicationType;
302}
303
305{
306 return mIsExtendedModeSupported;
307}
308
310{
311 return mIsRatificationOnDeselectSupported;
312}
313
315{
316 return mIsSvFeatureAvailable;
317}
318
320{
321 return mIsPinFeatureAvailable;
322}
323
325{
326 return mIsPkiModeSupported;
327}
328
330{
331 return mApplicationSubType;
332}
333
335{
336 return mStartupInfo[SI_SOFTWARE_ISSUER];
337}
338
340{
341 return mStartupInfo[SI_SOFTWARE_VERSION];
342}
343
345{
346 return mStartupInfo[SI_SOFTWARE_REVISION];
347}
348
350{
351 return mSessionModification;
352}
353
354const std::vector<uint8_t> CalypsoCardAdapter::getTraceabilityInformation() const
355{
356 /* Java code: return traceabilityInformation != null ? traceabilityInformation : new byte[0]; */
357 return mTraceabilityInformation;
358}
359
361{
362 return mIsDfInvalidated;
363}
364
366{
367 if (mIsDfRatified != nullptr) {
368 return *mIsDfRatified.get();
369 }
370
371 throw IllegalStateException("Unable to determine the ratification status. No session was " \
372 "opened.");
373}
374
375void CalypsoCardAdapter::setSvData(const uint8_t svKvc,
376 const std::vector<uint8_t>& svGetHeader,
377 const std::vector<uint8_t>& svGetData,
378 const int svBalance,
379 const int svLastTNum,
380 const std::shared_ptr<SvLoadLogRecord> svLoadLogRecord,
381 const std::shared_ptr<SvDebitLogRecord> svDebitLogRecord)
382{
383 mSvKvc = svKvc;
384 mSvGetHeader = svGetHeader;
385 mSvGetData = svGetData;
386 mSvBalance = std::make_shared<int>(svBalance);
387 mSvLastTNum = svLastTNum;
388
389 /* Update logs, do not overwrite existing values (case of double reading) */
390 if (mSvLoadLogRecord == nullptr) {
391 mSvLoadLogRecord = svLoadLogRecord;
392 }
393
394 if (mSvDebitLogRecord == nullptr) {
395 mSvDebitLogRecord = svDebitLogRecord;
396 }
397}
398
400{
401 if (mSvBalance == nullptr) {
402 throw IllegalStateException("No SV Get command has been executed.");
403 }
404
405 return *mSvBalance.get();
406}
407
409{
410 if (mSvBalance == nullptr) {
411 new IllegalStateException("No SV Get command has been executed.");
412 }
413
414 return mSvLastTNum;
415}
416
417const std::shared_ptr<SvLoadLogRecord> CalypsoCardAdapter::getSvLoadLogRecord()
418{
419 if (mSvLoadLogRecord == nullptr) {
420 /* Try to get it from the file data */
421 const std::shared_ptr<ElementaryFile> ef =
423 if (ef != nullptr) {
424 const std::vector<uint8_t> logRecord = ef->getData()->getContent();
425 mSvLoadLogRecord = std::make_shared<SvLoadLogRecordAdapter>(logRecord, 0);
426 }
427 }
428
429 return mSvLoadLogRecord;
430}
431
432const std::shared_ptr<SvDebitLogRecord> CalypsoCardAdapter::getSvDebitLogLastRecord()
433{
434 if (mSvDebitLogRecord == nullptr) {
435 /* Try to get it from the file data */
436 const std::vector<std::shared_ptr<SvDebitLogRecord>> svDebitLogRecords =
438 mSvDebitLogRecord = svDebitLogRecords[0];
439 }
440
441 return mSvDebitLogRecord;
442}
443
444const std::vector<std::shared_ptr<SvDebitLogRecord>> CalypsoCardAdapter::getSvDebitLogAllRecords()
445 const
446{
447 std::vector<std::shared_ptr<SvDebitLogRecord>> svDebitLogRecords;
448
449 /* Get the logs from the file data */
450 const std::shared_ptr<ElementaryFile> ef =
452 if (ef == nullptr) {
453 return svDebitLogRecords;
454 }
455
456 const std::map<const uint8_t, std::vector<uint8_t>>& logRecords =
457 ef->getData()->getAllRecordsContent();
458 for (const auto& entry : logRecords) {
459 svDebitLogRecords.push_back(std::make_shared<SvDebitLogRecordAdapter>(entry.second, 0));
460 }
461
462 return svDebitLogRecords;
463}
464
465void CalypsoCardAdapter::setDfRatified(const bool dfRatified)
466{
467 mIsDfRatified = std::make_shared<bool>(dfRatified);
468}
469
471{
472 return mCalypsoCardClass;
473}
474
475const std::shared_ptr<DirectoryHeader> CalypsoCardAdapter::getDirectoryHeader() const
476{
477 return mDirectoryHeader;
478}
479
481 const std::shared_ptr<DirectoryHeader> directoryHeader)
482{
483 mDirectoryHeader = directoryHeader;
484 mIsDfInvalidated = (directoryHeader->getDfStatus() & 0x01) != 0;
485
486 return *this;
487}
488
489const std::shared_ptr<ElementaryFile> CalypsoCardAdapter::getFileBySfi(const uint8_t sfi) const
490{
491 if (sfi == 0) {
492 return nullptr;
493 }
494
495 for (const auto& ef : mFiles) {
496 if (ef->getSfi() == sfi) {
497 return ef;
498 }
499 }
500
501 mLogger->warn("EF with SFI % is not found\n", sfi);
502
503 return nullptr;
504}
505
506const std::shared_ptr<ElementaryFile> CalypsoCardAdapter::getFileByLid(const uint16_t lid) const
507{
508 for (const auto& ef : mFiles) {
509 if (ef->getHeader() != nullptr && ef->getHeader()->getLid() == lid) {
510 return ef;
511 }
512 }
513
514 mLogger->warn("EF with LID % is not found\n", lid);
515
516 return nullptr;
517}
518
519const std::map<const uint8_t, const std::shared_ptr<ElementaryFile>>
521{
522 std::map<const uint8_t, const std::shared_ptr<ElementaryFile>> res;
523 for (const auto& ef : mFiles) {
524 if (ef->getSfi() != 0) {
525 res.insert({ef->getSfi(), ef});
526 }
527 }
528
529 return res;
530}
531
532const std::vector<std::shared_ptr<ElementaryFile>>& CalypsoCardAdapter::getFiles() const
533{
534 return mFiles;
535}
536
537void CalypsoCardAdapter::updateCurrentSfi(const uint8_t sfi)
538{
539 if (sfi != 0) {
540 mCurrentSfi = sfi;
541 }
542}
543
544void CalypsoCardAdapter::updateCurrentLid(const uint16_t lid)
545{
546 if (lid != 0) {
547 mCurrentLid = lid;
548 }
549}
550
551const std::shared_ptr<ElementaryFileAdapter> CalypsoCardAdapter::getOrCreateFile()
552{
553 if (mCurrentSfi != 0) {
554 /* Search by SFI */
555 for (const auto& ef : mFiles) {
556 if (ef->getSfi() == mCurrentSfi) {
557 return std::dynamic_pointer_cast<ElementaryFileAdapter>(ef);
558 }
559 }
560 } else if (mCurrentLid != 0) {
561 /* Search by LID */
562 for (const auto& ef : mFiles) {
563 if (ef->getHeader() != nullptr && ef->getHeader()->getLid() == mCurrentLid) {
564 return std::dynamic_pointer_cast<ElementaryFileAdapter>(ef);
565 }
566 }
567 }
568
569 /* Create a new EF with the provided SFI */
570 const auto ef = std::make_shared<ElementaryFileAdapter>(mCurrentSfi);
571 mFiles.push_back(ef);
572
573 return ef;
574}
575
577{
578 return getPinAttemptRemaining() == 0;
579}
580
582{
583 if (mPinAttemptCounter == nullptr) {
584 throw IllegalStateException("PIN status has not been checked.");
585 }
586
587 return *mPinAttemptCounter.get();
588}
589
590void CalypsoCardAdapter::setPinAttemptRemaining(const int pinAttemptCounter)
591{
592 mPinAttemptCounter = std::make_shared<int>(pinAttemptCounter);
593}
594
596 const std::shared_ptr<FileHeaderAdapter> header)
597{
598 updateCurrentSfi(sfi);
599 updateCurrentLid(header->getLid());
600
601 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
602 if (ef->getHeader() == nullptr) {
603 ef->setHeader(header);
604 } else {
605 std::dynamic_pointer_cast<FileHeaderAdapter>(ef->getHeader())
606 ->updateMissingInfoFrom(header);
607 }
608}
609
610void CalypsoCardAdapter::setContent(const uint8_t sfi,
611 const uint8_t numRecord,
612 const std::vector<uint8_t>& content)
613{
614 updateCurrentSfi(sfi);
615 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
616 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())->setContent(numRecord, content);
617}
618
619void CalypsoCardAdapter::setCounter(const uint8_t sfi,
620 const uint8_t numCounter,
621 const std::vector<uint8_t>& content)
622{
623 updateCurrentSfi(sfi);
624 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
625 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())->setCounter(numCounter, content);
626}
627
628void CalypsoCardAdapter::setContent(const uint8_t sfi,
629 const uint8_t numRecord,
630 const std::vector<uint8_t>& content,
631 const uint8_t offset)
632{
633 updateCurrentSfi(sfi);
634 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
635 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())
636 ->setContent(numRecord, content, offset);
637}
638
639void CalypsoCardAdapter::fillContent(const uint8_t sfi,
640 const uint8_t numRecord,
641 const std::vector<uint8_t>& content,
642 const uint8_t offset)
643{
644 updateCurrentSfi(sfi);
645 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
646 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())
647 ->fillContent(numRecord, content, offset);
648}
649
650void CalypsoCardAdapter::addCyclicContent(const uint8_t sfi, const std::vector<uint8_t> content)
651{
652 updateCurrentSfi(sfi);
653 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
654 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())->addCyclicContent(content);
655}
656
658{
659 copyFiles(mFiles, mFilesBackup);
660}
661
663{
664 copyFiles(mFilesBackup, mFiles);
665}
666
667void CalypsoCardAdapter::copyFiles(const std::vector<std::shared_ptr<ElementaryFile>>& src,
668 std::vector<std::shared_ptr<ElementaryFile>>& dest)
669{
670 dest.clear();
671 for (const auto& file : src) {
672 dest.push_back(std::make_shared<ElementaryFileAdapter>(file));
673 }
674}
675
676const std::string& CalypsoCardAdapter::getPowerOnData() const
677{
678 return mPowerOnData;
679}
680
681const std::vector<uint8_t> CalypsoCardAdapter::getSelectApplicationResponse() const
682{
683 if (mSelectApplicationResponse == nullptr) {
684 return std::vector<uint8_t>();
685 }
686
687 return mSelectApplicationResponse->getApdu();
688}
689
690void CalypsoCardAdapter::setCardChallenge(const std::vector<uint8_t>& cardChallenge)
691{
692 mCardChallenge = cardChallenge;
693}
694
696 const std::vector<uint8_t>& traceabilityInformation)
697{
698 mTraceabilityInformation = traceabilityInformation;
699}
700
701void CalypsoCardAdapter::setSvOperationSignature(const std::vector<uint8_t>& svOperationSignature)
702{
703 mSvOperationSignature = svOperationSignature;
704}
705
706const std::vector<uint8_t>& CalypsoCardAdapter::getCardChallenge() const
707{
708 return mCardChallenge;
709}
710
712{
713 return mSvKvc;
714}
715
716const std::vector<uint8_t>& CalypsoCardAdapter::getSvGetHeader() const
717{
718 if (mSvGetHeader.empty()) {
719 throw IllegalStateException("SV Get Header not available.");
720 }
721
722 return mSvGetHeader;
723}
724
725const std::vector<uint8_t>& CalypsoCardAdapter::getSvGetData() const
726{
727 if (mSvGetData.empty()) {
728 throw new IllegalStateException("SV Get Data not available.");
729 }
730
731 return mSvGetData;
732}
733
734const std::vector<uint8_t>& CalypsoCardAdapter::getSvOperationSignature() const
735{
736 return mSvOperationSignature;
737}
738
739std::ostream& operator<<(std::ostream& os, const CalypsoCardAdapter& cca)
740{
741 os << "CALYPSO_CARD_ADAPTER: {"
742 << "SELECT_APPLICATION_RESPONSE: " << cca.mSelectApplicationResponse << ", "
743 << "POWER_ON_DATA: " << cca.mPowerOnData << ", "
744 << "IS_EXTENDED_MODE_SUPPORTED: " << cca.mIsExtendedModeSupported << ", "
745 << "IS_RATIFICATION_ON_DESELECT_SUPPORTED: " << cca.mIsRatificationOnDeselectSupported <<", "
746 << "IS_SV_FEATURE_AVAILABLE: " << cca.mIsSvFeatureAvailable << ", "
747 << "IS_PIN_FEATURE_AVAILABLE: " << cca.mIsPinFeatureAvailable << ", "
748 << "IS_PKI_MODE_SUPPORTED:" << cca.mIsPkiModeSupported << ", "
749 << "IS_DF_INVALIDATED:" << cca.mIsDfInvalidated << ", "
750 << "CALYPSO_CARD_CLASS: " << cca.mCalypsoCardClass << ", "
751 << "CALYPSO_SERIAL_NUMBER: " << cca.mCalypsoSerialNumber << ", "
752 << "STARTUP_INFO:" << cca.mStartupInfo << ", "
753 << "PRODUCT_TYPE: " << cca.mProductType << ", "
754 << "DF_NAME: " << cca.mDfName << ", "
755 << "MODIFICATIONS_COUNTER_MAX: " << cca.mModificationsCounterMax << ", "
756 << "IS_MODIFICATION_COUNTER_IN_BYTES: " << cca.mIsModificationCounterInBytes << ", "
757 << "DIRECTORY_HEADER: " << cca.mDirectoryHeader << ", "
758 << "FILES: " << cca.mFiles << ", "
759 << "FILES_BACKUP: " << cca.mFilesBackup << ", "
760 << "CURRENT_SFI: " << cca.mCurrentSfi << ", "
761 << "CURRENT_LID: " << cca.mCurrentLid << ", "
762 << "ID_DF_RATIFIED: " << cca.mIsDfRatified << ", "
763 << "PIN_ATTEMPT_COUNTER: " << cca.mPinAttemptCounter << ", "
764 << "SV_BALANCE: " << cca.mSvBalance << ", "
765 << "SV_LAST_T_NUM: " << cca.mSvLastTNum << ", "
766 << "SV_LOAD_LOG_RECORD: " << cca.mSvLoadLogRecord << ", "
767 << "SV_DEBIT_LOG_RECORD: " << cca.mSvDebitLogRecord << ", "
768 << "IS_HCE: " << cca.mIsHce << ", "
769 << "CARD_CHALLENGE: " << cca.mCardChallenge << ", "
770 << "TRACEABILITY_INFORMATION: " << cca.mTraceabilityInformation << ", "
771 << "SV_KVC: " << cca.mSvKvc << ", "
772 << "SV_GET_HEADER: " << cca.mSvGetHeader << ", "
773 << "SV_GET_DATA: " << cca.mSvGetData << ", "
774 << "SV_OPERATION_SIGNATURE: " << cca.mSvOperationSignature << ", "
775 << "APPLICATION_SUB_TYPE: " << cca.mApplicationSubType << ", "
776 << "APPLICATION_TYPE: " << cca.mApplicationType << ", "
777 << "SESSION_MODIFICATION: " << cca.mSessionModification
778 << "}";
779
780 return os;
781}
782
783std::ostream& operator<<(std::ostream& os, const std::shared_ptr<CalypsoCardAdapter> cca)
784{
785 if (cca == nullptr) {
786 os << "CALYPSO_CARD_ADAPTER: null";
787 } else {
788 os << *cca.get();
789 }
790
791 return os;
792}
793
794}
795}
796}
CalypsoCard & setDirectoryHeader(const std::shared_ptr< DirectoryHeader > directoryHeader)
const std::vector< uint8_t > & getStartupInfoRawData() const override
const std::shared_ptr< SvDebitLogRecord > getSvDebitLogLastRecord() override
const std::vector< std::shared_ptr< ElementaryFile > > & getFiles() const override
const std::shared_ptr< ElementaryFile > getFileBySfi(const uint8_t sfi) const override
const CalypsoCard::ProductType & getProductType() const override
const std::map< const uint8_t, const std::shared_ptr< ElementaryFile > > getAllFiles() const override
const std::vector< uint8_t > getApplicationSerialNumber() const override
const std::string & getPowerOnData() const override
void setTraceabilityInformation(const std::vector< uint8_t > &traceabilityInformation)
void fillContent(const uint8_t sfi, const uint8_t numRecord, const std::vector< uint8_t > &content, const uint8_t offset)
const std::vector< uint8_t > & getDfName() const override
void setPinAttemptRemaining(const int pinAttemptCounter)
const std::shared_ptr< DirectoryHeader > getDirectoryHeader() const override
const std::shared_ptr< ElementaryFile > getFileByLid(const uint16_t lid) const override
const std::vector< uint8_t > & getSvGetData() const
void setSvOperationSignature(const std::vector< uint8_t > &svOperationSignature)
const std::shared_ptr< SvLoadLogRecord > getSvLoadLogRecord() override
void addCyclicContent(const uint8_t sfi, const std::vector< uint8_t > content)
void setContent(const uint8_t sfi, const uint8_t numRecord, const std::vector< uint8_t > &content)
const std::vector< uint8_t > & getSvOperationSignature() const
const std::vector< std::shared_ptr< SvDebitLogRecord > > getSvDebitLogAllRecords() const override
void setCardChallenge(const std::vector< uint8_t > &cardChallenge)
const std::vector< uint8_t > & getSvGetHeader() const
const std::vector< uint8_t > getSelectApplicationResponse() const override
void initializeWithFci(const std::shared_ptr< ApduResponseApi > selectApplicationResponse)
void setSvData(const uint8_t svKvc, const std::vector< uint8_t > &svGetHeader, const std::vector< uint8_t > &svGetData, const int svBalance, const int svLastTNum, const std::shared_ptr< SvLoadLogRecord > svLoadLogRecord, const std::shared_ptr< SvDebitLogRecord > svDebitLogRecord)
void setFileHeader(const uint8_t sfi, const std::shared_ptr< FileHeaderAdapter > header)
void initializeWithPowerOnData(const std::string &powerOnData)
const std::vector< uint8_t > & getCardChallenge() const
const std::vector< uint8_t > & getCalypsoSerialNumberFull() const
void setCounter(const uint8_t sfi, const uint8_t numCounter, const std::vector< uint8_t > &content)
const std::vector< uint8_t > getTraceabilityInformation() const override
static const CalypsoCardClass LEGACY
static const CalypsoCardClass ISO
CalypsoSam::ProductType ProductType
std::ostream & operator<<(std::ostream &os, const std::shared_ptr< ApduRequestAdapter > ara)