Keyple Card Calypso C++ Library 2.2.2
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 "HexUtil.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 = HexUtil::toByteArray(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 expressed in number of commands the array is
108 * initialized with 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 expressed 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
376{
377 if (mTransactionCounter == nullptr) {
378 throw IllegalStateException("Unable to determine the transaction counter. No session was " \
379 "opened.");
380 }
381
382 return *mTransactionCounter.get();
383}
384
385void CalypsoCardAdapter::setTransactionCounter(const int transactionCounter)
386{
387 mTransactionCounter = std::make_shared<int>(transactionCounter);
388}
389
390void CalypsoCardAdapter::setSvData(const uint8_t svKvc,
391 const std::vector<uint8_t>& svGetHeader,
392 const std::vector<uint8_t>& svGetData,
393 const int svBalance,
394 const int svLastTNum,
395 const std::shared_ptr<SvLoadLogRecord> svLoadLogRecord,
396 const std::shared_ptr<SvDebitLogRecord> svDebitLogRecord)
397{
398 mSvKvc = svKvc;
399 mSvGetHeader = svGetHeader;
400 mSvGetData = svGetData;
401 mSvBalance = std::make_shared<int>(svBalance);
402 mSvLastTNum = svLastTNum;
403
404 /* Update logs, do not overwrite existing values (case of double reading) */
405 if (mSvLoadLogRecord == nullptr) {
406 mSvLoadLogRecord = svLoadLogRecord;
407 }
408
409 if (mSvDebitLogRecord == nullptr) {
410 mSvDebitLogRecord = svDebitLogRecord;
411 }
412}
413
415{
416 if (mSvBalance == nullptr) {
417 throw IllegalStateException("No SV Get command has been executed.");
418 }
419
420 return *mSvBalance.get();
421}
422
424{
425 if (mSvBalance == nullptr) {
426 new IllegalStateException("No SV Get command has been executed.");
427 }
428
429 return mSvLastTNum;
430}
431
432const std::shared_ptr<SvLoadLogRecord> CalypsoCardAdapter::getSvLoadLogRecord()
433{
434 if (mSvLoadLogRecord == nullptr) {
435 /* Try to get it from the file data */
436 const std::shared_ptr<ElementaryFile> ef =
438 if (ef != nullptr) {
439 const std::vector<uint8_t> logRecord = ef->getData()->getContent();
440 mSvLoadLogRecord = std::make_shared<SvLoadLogRecordAdapter>(logRecord, 0);
441 }
442 }
443
444 return mSvLoadLogRecord;
445}
446
447const std::shared_ptr<SvDebitLogRecord> CalypsoCardAdapter::getSvDebitLogLastRecord()
448{
449 if (mSvDebitLogRecord == nullptr) {
450 /* Try to get it from the file data */
451 const std::vector<std::shared_ptr<SvDebitLogRecord>> svDebitLogRecords =
453 mSvDebitLogRecord = svDebitLogRecords[0];
454 }
455
456 return mSvDebitLogRecord;
457}
458
459const std::vector<std::shared_ptr<SvDebitLogRecord>> CalypsoCardAdapter::getSvDebitLogAllRecords()
460 const
461{
462 std::vector<std::shared_ptr<SvDebitLogRecord>> svDebitLogRecords;
463
464 /* Get the logs from the file data */
465 const std::shared_ptr<ElementaryFile> ef =
467 if (ef == nullptr) {
468 return svDebitLogRecords;
469 }
470
471 const std::map<const uint8_t, std::vector<uint8_t>>& logRecords =
472 ef->getData()->getAllRecordsContent();
473 for (const auto& entry : logRecords) {
474 svDebitLogRecords.push_back(std::make_shared<SvDebitLogRecordAdapter>(entry.second, 0));
475 }
476
477 return svDebitLogRecords;
478}
479
480void CalypsoCardAdapter::setDfRatified(const bool dfRatified)
481{
482 mIsDfRatified = std::make_shared<bool>(dfRatified);
483}
484
486{
487 return mCalypsoCardClass;
488}
489
490const std::shared_ptr<DirectoryHeader> CalypsoCardAdapter::getDirectoryHeader() const
491{
492 return mDirectoryHeader;
493}
494
496 const std::shared_ptr<DirectoryHeader> directoryHeader)
497{
498 mDirectoryHeader = directoryHeader;
499 mIsDfInvalidated = (directoryHeader->getDfStatus() & 0x01) != 0;
500
501 return *this;
502}
503
504const std::shared_ptr<ElementaryFile> CalypsoCardAdapter::getFileBySfi(const uint8_t sfi) const
505{
506 if (sfi == 0) {
507 return nullptr;
508 }
509
510 for (const auto& ef : mFiles) {
511 if (ef->getSfi() == sfi) {
512 return ef;
513 }
514 }
515
516 mLogger->warn("EF with SFI % is not found\n", sfi);
517
518 return nullptr;
519}
520
521const std::shared_ptr<ElementaryFile> CalypsoCardAdapter::getFileByLid(const uint16_t lid) const
522{
523 for (const auto& ef : mFiles) {
524 if (ef->getHeader() != nullptr && ef->getHeader()->getLid() == lid) {
525 return ef;
526 }
527 }
528
529 mLogger->warn("EF with LID % is not found\n", lid);
530
531 return nullptr;
532}
533
534const std::map<const uint8_t, const std::shared_ptr<ElementaryFile>>
536{
537 std::map<const uint8_t, const std::shared_ptr<ElementaryFile>> res;
538 for (const auto& ef : mFiles) {
539 if (ef->getSfi() != 0) {
540 res.insert({ef->getSfi(), ef});
541 }
542 }
543
544 return res;
545}
546
547const std::vector<std::shared_ptr<ElementaryFile>>& CalypsoCardAdapter::getFiles() const
548{
549 return mFiles;
550}
551
552void CalypsoCardAdapter::updateCurrentSfi(const uint8_t sfi)
553{
554 if (sfi != 0) {
555 mCurrentSfi = sfi;
556 }
557}
558
559void CalypsoCardAdapter::updateCurrentLid(const uint16_t lid)
560{
561 if (lid != 0) {
562 mCurrentLid = lid;
563 }
564}
565
566const std::shared_ptr<ElementaryFileAdapter> CalypsoCardAdapter::getOrCreateFile()
567{
568 if (mCurrentSfi != 0) {
569 /* Search by SFI */
570 for (const auto& ef : mFiles) {
571 if (ef->getSfi() == mCurrentSfi) {
572 return std::dynamic_pointer_cast<ElementaryFileAdapter>(ef);
573 }
574 }
575 } else if (mCurrentLid != 0) {
576 /* Search by LID */
577 for (const auto& ef : mFiles) {
578 if (ef->getHeader() != nullptr && ef->getHeader()->getLid() == mCurrentLid) {
579 return std::dynamic_pointer_cast<ElementaryFileAdapter>(ef);
580 }
581 }
582 }
583
584 /* Create a new EF with the provided SFI */
585 const auto ef = std::make_shared<ElementaryFileAdapter>(mCurrentSfi);
586 mFiles.push_back(ef);
587
588 return ef;
589}
590
592{
593 return getPinAttemptRemaining() == 0;
594}
595
597{
598 if (mPinAttemptCounter == nullptr) {
599 throw IllegalStateException("PIN status has not been checked.");
600 }
601
602 return *mPinAttemptCounter.get();
603}
604
605void CalypsoCardAdapter::setPinAttemptRemaining(const int pinAttemptCounter)
606{
607 mPinAttemptCounter = std::make_shared<int>(pinAttemptCounter);
608}
609
611 const std::shared_ptr<FileHeaderAdapter> header)
612{
613 updateCurrentSfi(sfi);
614 updateCurrentLid(header->getLid());
615
616 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
617 if (ef->getHeader() == nullptr) {
618 ef->setHeader(header);
619 } else {
620 std::dynamic_pointer_cast<FileHeaderAdapter>(ef->getHeader())
621 ->updateMissingInfoFrom(header);
622 }
623}
624
625void CalypsoCardAdapter::setContent(const uint8_t sfi,
626 const uint8_t numRecord,
627 const std::vector<uint8_t>& content)
628{
629 updateCurrentSfi(sfi);
630 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
631 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())->setContent(numRecord, content);
632}
633
634void CalypsoCardAdapter::setCounter(const uint8_t sfi,
635 const uint8_t numCounter,
636 const std::vector<uint8_t>& content)
637{
638 updateCurrentSfi(sfi);
639 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
640 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())->setCounter(numCounter, content);
641}
642
643void CalypsoCardAdapter::setContent(const uint8_t sfi,
644 const uint8_t numRecord,
645 const std::vector<uint8_t>& content,
646 const uint8_t offset)
647{
648 updateCurrentSfi(sfi);
649 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
650 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())
651 ->setContent(numRecord, content, offset);
652}
653
654void CalypsoCardAdapter::fillContent(const uint8_t sfi,
655 const uint8_t numRecord,
656 const std::vector<uint8_t>& content,
657 const uint8_t offset)
658{
659 updateCurrentSfi(sfi);
660 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
661 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())
662 ->fillContent(numRecord, content, offset);
663}
664
665void CalypsoCardAdapter::addCyclicContent(const uint8_t sfi, const std::vector<uint8_t> content)
666{
667 updateCurrentSfi(sfi);
668 std::shared_ptr<ElementaryFileAdapter> ef = getOrCreateFile();
669 std::dynamic_pointer_cast<FileDataAdapter>(ef->getData())->addCyclicContent(content);
670}
671
673{
674 copyFiles(mFiles, mFilesBackup);
675}
676
678{
679 copyFiles(mFilesBackup, mFiles);
680}
681
682void CalypsoCardAdapter::copyFiles(const std::vector<std::shared_ptr<ElementaryFile>>& src,
683 std::vector<std::shared_ptr<ElementaryFile>>& dest)
684{
685 dest.clear();
686 for (const auto& file : src) {
687 dest.push_back(std::make_shared<ElementaryFileAdapter>(file));
688 }
689}
690
691const std::string& CalypsoCardAdapter::getPowerOnData() const
692{
693 return mPowerOnData;
694}
695
696const std::vector<uint8_t> CalypsoCardAdapter::getSelectApplicationResponse() const
697{
698 if (mSelectApplicationResponse == nullptr) {
699 return std::vector<uint8_t>();
700 }
701
702 return mSelectApplicationResponse->getApdu();
703}
704
705void CalypsoCardAdapter::setCardChallenge(const std::vector<uint8_t>& cardChallenge)
706{
707 mCardChallenge = cardChallenge;
708}
709
711 const std::vector<uint8_t>& traceabilityInformation)
712{
713 mTraceabilityInformation = traceabilityInformation;
714}
715
716void CalypsoCardAdapter::setSvOperationSignature(const std::vector<uint8_t>& svOperationSignature)
717{
718 mSvOperationSignature = svOperationSignature;
719}
720
721const std::vector<uint8_t>& CalypsoCardAdapter::getCardChallenge() const
722{
723 return mCardChallenge;
724}
725
727{
728 return mSvKvc;
729}
730
731const std::vector<uint8_t>& CalypsoCardAdapter::getSvGetHeader() const
732{
733 if (mSvGetHeader.empty()) {
734 throw IllegalStateException("SV Get Header not available.");
735 }
736
737 return mSvGetHeader;
738}
739
740const std::vector<uint8_t>& CalypsoCardAdapter::getSvGetData() const
741{
742 if (mSvGetData.empty()) {
743 throw new IllegalStateException("SV Get Data not available.");
744 }
745
746 return mSvGetData;
747}
748
749const std::vector<uint8_t>& CalypsoCardAdapter::getSvOperationSignature() const
750{
751 return mSvOperationSignature;
752}
753
754std::ostream& operator<<(std::ostream& os, const CalypsoCardAdapter& cca)
755{
756 os << "CALYPSO_CARD_ADAPTER: {"
757 << "SELECT_APPLICATION_RESPONSE: " << cca.mSelectApplicationResponse << ", "
758 << "POWER_ON_DATA: " << cca.mPowerOnData << ", "
759 << "IS_EXTENDED_MODE_SUPPORTED: " << cca.mIsExtendedModeSupported << ", "
760 << "IS_RATIFICATION_ON_DESELECT_SUPPORTED: " << cca.mIsRatificationOnDeselectSupported <<", "
761 << "IS_SV_FEATURE_AVAILABLE: " << cca.mIsSvFeatureAvailable << ", "
762 << "IS_PIN_FEATURE_AVAILABLE: " << cca.mIsPinFeatureAvailable << ", "
763 << "IS_PKI_MODE_SUPPORTED:" << cca.mIsPkiModeSupported << ", "
764 << "IS_DF_INVALIDATED:" << cca.mIsDfInvalidated << ", "
765 << "CALYPSO_CARD_CLASS: " << cca.mCalypsoCardClass << ", "
766 << "CALYPSO_SERIAL_NUMBER: " << cca.mCalypsoSerialNumber << ", "
767 << "STARTUP_INFO:" << cca.mStartupInfo << ", "
768 << "PRODUCT_TYPE: " << cca.mProductType << ", "
769 << "DF_NAME: " << cca.mDfName << ", "
770 << "MODIFICATIONS_COUNTER_MAX: " << cca.mModificationsCounterMax << ", "
771 << "IS_MODIFICATION_COUNTER_IN_BYTES: " << cca.mIsModificationCounterInBytes << ", "
772 << "DIRECTORY_HEADER: " << cca.mDirectoryHeader << ", "
773 << "FILES: " << cca.mFiles << ", "
774 << "FILES_BACKUP: " << cca.mFilesBackup << ", "
775 << "CURRENT_SFI: " << cca.mCurrentSfi << ", "
776 << "CURRENT_LID: " << cca.mCurrentLid << ", "
777 << "ID_DF_RATIFIED: " << cca.mIsDfRatified << ", "
778 << "PIN_ATTEMPT_COUNTER: " << cca.mPinAttemptCounter << ", "
779 << "SV_BALANCE: " << cca.mSvBalance << ", "
780 << "SV_LAST_T_NUM: " << cca.mSvLastTNum << ", "
781 << "SV_LOAD_LOG_RECORD: " << cca.mSvLoadLogRecord << ", "
782 << "SV_DEBIT_LOG_RECORD: " << cca.mSvDebitLogRecord << ", "
783 << "IS_HCE: " << cca.mIsHce << ", "
784 << "CARD_CHALLENGE: " << cca.mCardChallenge << ", "
785 << "TRACEABILITY_INFORMATION: " << cca.mTraceabilityInformation << ", "
786 << "SV_KVC: " << cca.mSvKvc << ", "
787 << "SV_GET_HEADER: " << cca.mSvGetHeader << ", "
788 << "SV_GET_DATA: " << cca.mSvGetData << ", "
789 << "SV_OPERATION_SIGNATURE: " << cca.mSvOperationSignature << ", "
790 << "APPLICATION_SUB_TYPE: " << cca.mApplicationSubType << ", "
791 << "APPLICATION_TYPE: " << cca.mApplicationType << ", "
792 << "SESSION_MODIFICATION: " << cca.mSessionModification
793 << "}";
794
795 return os;
796}
797
798std::ostream& operator<<(std::ostream& os, const std::shared_ptr<CalypsoCardAdapter> cca)
799{
800 if (cca == nullptr) {
801 os << "CALYPSO_CARD_ADAPTER: null";
802 } else {
803 os << *cca.get();
804 }
805
806 return os;
807}
808
809}
810}
811}
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
void setTransactionCounter(const int transactionCounter)
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)