14#include "keyple/card/calypso/SecureSymmetricCryptoTransactionManagerAdapter.hpp"
22#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
23#include "keyple/card/calypso/CalypsoCardConstant.hpp"
24#include "keyple/card/calypso/CommandChangeKey.hpp"
25#include "keyple/card/calypso/CommandChangePin.hpp"
26#include "keyple/card/calypso/CommandCloseSecureSession.hpp"
27#include "keyple/card/calypso/CommandGetChallenge.hpp"
28#include "keyple/card/calypso/CommandInvalidate.hpp"
29#include "keyple/card/calypso/CommandManageSession.hpp"
30#include "keyple/card/calypso/CommandOpenSecureSession.hpp"
31#include "keyple/card/calypso/CommandRatification.hpp"
32#include "keyple/card/calypso/CommandRehabilitate.hpp"
33#include "keyple/card/calypso/CommandSvDebitOrUndebit.hpp"
34#include "keyple/card/calypso/CommandSvGet.hpp"
35#include "keyple/card/calypso/CommandSvReload.hpp"
36#include "keyple/card/calypso/CommandVerifyPin.hpp"
37#include "keyple/core/plugin/CardIOException.hpp"
38#include "keyple/core/util/KeypleAssert.hpp"
39#include "keyple/core/util/cpp/exception/IllegalArgumentException.hpp"
40#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
41#include "keyple/core/util/cpp/exception/RuntimeException.hpp"
42#include "keyple/core/util/cpp/exception/UnsupportedOperationException.hpp"
43#include "keypop/calypso/card/transaction/CryptoIOException.hpp"
44#include "keypop/calypso/card/transaction/SessionBufferOverflowException.hpp"
45#include "keypop/calypso/card/transaction/UnexpectedCommandStatusException.hpp"
46#include "keypop/calypso/crypto/asymmetric/AsymmetricCryptoException.hpp"
47#include "keypop/calypso/crypto/legacysam/transaction/ReaderIOException.hpp"
48#include "keypop/calypso/crypto/symmetric/SymmetricCryptoException.hpp"
49#include "keypop/calypso/crypto/symmetric/SymmetricCryptoIOException.hpp"
50#include "keypop/reader/CardCommunicationException.hpp"
51#include "keypop/reader/CardReader.hpp"
52#include "keypop/reader/ReaderCommunicationException.hpp"
53#include "keypop/reader/selection/InvalidCardResponseException.hpp"
59using keyple::card::calypso::CalypsoCardConstant;
60using keyple::core::plugin::CardIOException;
61using keyple::core::util::Assert;
62using keyple::core::util::cpp::exception::IllegalArgumentException;
63using keyple::core::util::cpp::exception::IllegalStateException;
64using keyple::core::util::cpp::exception::RuntimeException;
65using keyple::core::util::cpp::exception::UnsupportedOperationException;
66using keypop::calypso::card::transaction::CryptoIOException;
67using keypop::calypso::card::transaction::SessionBufferOverflowException;
68using keypop::calypso::card::transaction::UnexpectedCommandStatusException;
69using keypop::calypso::crypto::asymmetric::AsymmetricCryptoException;
70using keypop::calypso::crypto::legacysam::transaction::ReaderIOException;
71using keypop::calypso::crypto::symmetric::SymmetricCryptoException;
72using keypop::calypso::crypto::symmetric::SymmetricCryptoIOException;
73using keypop::reader::CardCommunicationException;
74using keypop::reader::CardReader;
75using keypop::reader::ReaderCommunicationException;
76using keypop::reader::selection::InvalidCardResponseException;
80 SecureSymmetricCryptoTransactionManagerAdapter<T>::MSG_PIN_NOT_AVAILABLE
81 =
"PIN is not available for this card";
83const int SecureSymmetricCryptoTransactionManagerAdapter<
84 T>::SESSION_BUFFER_CMD_ADDITIONAL_COST = 6;
86const int SecureSymmetricCryptoTransactionManagerAdapter<T>::APDU_HEADER_LENGTH
90SecureSymmetricCryptoTransactionManagerAdapter<T>::
91 SecureSymmetricCryptoTransactionManagerAdapter(
92 std::shared_ptr<ProxyReaderApi> cardReader,
93 std::shared_ptr<CalypsoCardAdapter> card,
94 std::shared_ptr<SymmetricCryptoSecuritySettingAdapter>
95 symmetricCryptoSecuritySetting)
96: TransactionManagerAdapter<T>(cardReader, card)
97, SecureTransactionManagerAdapter<T>(cardReader, card)
98, mSymmetricCryptoSecuritySetting(symmetricCryptoSecuritySetting)
100 std::shared_ptr<SymmetricCryptoCardTransactionManagerFactorySpi>
101 cryptoFactory = symmetricCryptoSecuritySetting
102 ->getCryptoCardTransactionManagerFactorySpi();
105 mIsExtendedMode = card->isExtendedModeSupported()
106 && cryptoFactory->isExtendedModeSupported();
109 mIsEncryptionActive =
false;
112 mModificationsCounter = card->getModificationsCounter();
113 mNbPostponedData = 0;
115 mSvOperation = SvOperation::RELOAD;
116 mSvAction = SvAction::DO;
117 mIsSvOperationInSecureSession =
false;
119 if (!mIsExtendedMode) {
120 SecureTransactionManagerAdapter<T>::disablePreOpenMode();
124 mPayloadCapacity = std::min(
125 static_cast<int>(card->getPayloadCapacity()),
126 cryptoFactory->getMaxCardApduLengthSupported() - APDU_HEADER_LENGTH);
129 mSymmetricCryptoCardTransactionManagerSpi
130 = cryptoFactory->createCardTransactionManager(
131 card->getCalypsoSerialNumberFull(),
133 SecureTransactionManagerAdapter<T>::getTransactionAuditData());
136 = std::dynamic_pointer_cast<CardTransactionCryptoExtension>(
137 mSymmetricCryptoCardTransactionManagerSpi);
139 mTransactionContext = std::make_shared<DtoAdapters::TransactionContextDto>(
140 card, mSymmetricCryptoCardTransactionManagerSpi);
142 mModificationsCounter = card->getModificationsCounter();
146std::shared_ptr<DtoAdapters::TransactionContextDto>
147SecureSymmetricCryptoTransactionManagerAdapter<T>::getTransactionContext()
const
149 return mTransactionContext;
153std::shared_ptr<DtoAdapters::CommandContextDto>
154SecureSymmetricCryptoTransactionManagerAdapter<T>::getCommandContext()
const
156 return std::make_shared<DtoAdapters::CommandContextDto>(
157 SecureTransactionManagerAdapter<T>::mIsSecureSessionOpen,
158 mIsEncryptionActive);
163SecureSymmetricCryptoTransactionManagerAdapter<T>::resetCommandContext()
165 SecureTransactionManagerAdapter<T>::mIsSecureSessionOpen =
false;
166 mIsEncryptionActive =
false;
171SecureSymmetricCryptoTransactionManagerAdapter<T>::getPayloadCapacity()
const
173 return mPayloadCapacity;
178SecureSymmetricCryptoTransactionManagerAdapter<T>::resetTransaction()
180 resetCommandContext();
182 mModificationsCounter
183 = SecureTransactionManagerAdapter<T>::mCard->getModificationsCounter();
184 mNbPostponedData = 0;
185 mSvPostponedDataIndex = -1;
187 mSvOperation = SvOperation::RELOAD;
189 mIsSvOperationInSecureSession =
false;
191 SecureTransactionManagerAdapter<T>::disablePreOpenMode();
193 SecureTransactionManagerAdapter<T>::mCommands.clear();
195 if (mTransactionContext->isSecureSessionOpen()) {
197 auto cancelSecureSessionCommand
198 = std::make_shared<CommandCloseSecureSession>(
199 mTransactionContext, getCommandContext(),
true);
200 cancelSecureSessionCommand->finalizeRequest();
202 std::vector<std::shared_ptr<Command>> commands;
203 commands.push_back(cancelSecureSessionCommand);
204 SecureTransactionManagerAdapter<T>::executeCardCommands(
205 commands, ChannelControl::KEEP_OPEN);
207 }
catch (
const RuntimeException& e) {
209 "Failed to abort secure session [reason=%]\n", e.getMessage());
213 SecureTransactionManagerAdapter<T>::mCard->restoreFiles();
214 mTransactionContext->setSecureSessionOpen(
false);
220SecureSymmetricCryptoTransactionManagerAdapter<
221 T>::prepareNewSecureSessionIfNeeded(
const std::shared_ptr<Command>& command)
223 if (!SecureTransactionManagerAdapter<T>::mIsSecureSessionOpen) {
227 mModificationsCounter -= computeCommandSessionBufferSize(command);
228 if (mModificationsCounter < 0) {
229 checkMultipleSessionEnabled(command);
230 SecureTransactionManagerAdapter<T>::mCommands.push_back(
231 std::make_shared<CommandCloseSecureSession>(
235 mSvPostponedDataIndex));
237 SecureTransactionManagerAdapter<T>::disablePreOpenMode();
239 SecureTransactionManagerAdapter<T>::mCommands.push_back(
240 std::make_shared<CommandOpenSecureSession>(
243 mSymmetricCryptoSecuritySetting,
247 if (mIsEncryptionActive) {
248 auto session = std::make_shared<CommandManageSession>(
249 mTransactionContext, getCommandContext());
250 session->setEncryptionRequested(
true);
251 SecureTransactionManagerAdapter<T>::mCommands.push_back(session);
254 mModificationsCounter = SecureTransactionManagerAdapter<T>::mCard
255 ->getModificationsCounter();
256 mModificationsCounter -= computeCommandSessionBufferSize(command);
257 mNbPostponedData = 0;
258 mSvPostponedDataIndex = -1;
259 mIsSvOperationInSecureSession =
false;
265SecureSymmetricCryptoTransactionManagerAdapter<
266 T>::computeCommandSessionBufferSize(
const std::shared_ptr<Command>& command)
269 return SecureTransactionManagerAdapter<T>::mCard
270 ->isModificationsCounterInBytes()
271 ?
static_cast<int>(command->getApduRequest()->getApdu().size())
272 + SESSION_BUFFER_CMD_ADDITIONAL_COST - APDU_HEADER_LENGTH
278SecureSymmetricCryptoTransactionManagerAdapter<T>::checkMultipleSessionEnabled(
279 const std::shared_ptr<Command>& command)
const
286 if (!mSymmetricCryptoSecuritySetting->isMultipleSessionEnabled()) {
287 throw SessionBufferOverflowException(
288 std::string(
"Multiple session is not allowed. A command would ")
289 +
"overflow the card modifications buffer. Command: "
291 + SecureTransactionManagerAdapter<
292 T>::getTransactionAuditDataAsString(),
299SecureSymmetricCryptoTransactionManagerAdapter<
300 T>::canConfigureReadOnOpenSecureSession()
const
302 return SecureTransactionManagerAdapter<T>::mIsSecureSessionOpen
303 && !mSymmetricCryptoSecuritySetting->isReadOnSessionOpeningDisabled()
304 && SecureTransactionManagerAdapter<T>::mCard
305 ->getPreOpenWriteAccessLevel()
306 == WriteAccessLevel::UNKOWN
307 && !SecureTransactionManagerAdapter<T>::mCommands.empty()
308 && SecureTransactionManagerAdapter<T>::mCommands
309 [SecureTransactionManagerAdapter<T>::mCommands.size() - 1]
311 == CardCommandRef::OPEN_SECURE_SESSION
312 && !std::dynamic_pointer_cast<CommandOpenSecureSession>(
313 SecureTransactionManagerAdapter<T>::mCommands
314 [SecureTransactionManagerAdapter<T>::mCommands.size()
316 ->isReadModeConfigured();
321SecureSymmetricCryptoTransactionManagerAdapter<T>::
322 prepareIncreaseOrDecreaseCounter(
323 bool isDecreaseCommand,
328 SecureTransactionManagerAdapter<T>::prepareIncreaseOrDecreaseCounter(
329 isDecreaseCommand, sfi, counterNumber, incDecValue);
331 return dynamic_cast<T&
>(*this);
356SecureSymmetricCryptoTransactionManagerAdapter<T>::processCommands(
357 ChannelControl channelControl)
359 if (SecureTransactionManagerAdapter<T>::mCommands.empty()) {
360 processCryptoPreparedCommands();
361 return dynamic_cast<T&
>(*this);
365 std::vector<std::shared_ptr<Command>> cardRequestCommands;
367 for (
const auto& command :
368 SecureTransactionManagerAdapter<T>::mCommands) {
369 if (command->isCryptoServiceRequiredToFinalizeRequest()
370 && (!synchronizeCryptoServiceBeforeCardProcessing(
371 cardRequestCommands))) {
372 SecureTransactionManagerAdapter<T>::executeCardCommands(
373 cardRequestCommands, ChannelControl::KEEP_OPEN);
374 cardRequestCommands.clear();
377 command->finalizeRequest();
378 cardRequestCommands.push_back(command);
381 SecureTransactionManagerAdapter<T>::executeCardCommands(
382 cardRequestCommands, channelControl);
383 processCryptoPreparedCommands();
389 SecureTransactionManagerAdapter<T>::mCommands.clear();
391 && !SecureTransactionManagerAdapter<T>::mCard
392 ->isExtendedModeSupported()) {
393 mIsExtendedMode =
false;
400 SecureTransactionManagerAdapter<T>::mCommands.clear();
402 && !SecureTransactionManagerAdapter<T>::mCard
403 ->isExtendedModeSupported()) {
404 mIsExtendedMode =
false;
407 return dynamic_cast<T&
>(*this);
412SecureSymmetricCryptoTransactionManagerAdapter<T>::handleCommandPostProcessing(
413 int commandIndex,
const std::vector<std::shared_ptr<Command>>& commands)
417 const auto isCounterValuePostponed
418 = mTransactionContext->getCard()->getIsCounterValuePostponed();
420 if (isCounterValuePostponed ==
nullptr || !*isCounterValuePostponed) {
424 CardCommandRef commandRef = commands[commandIndex]->getCommandRef();
426 if (commandRef != CardCommandRef::INCREASE
427 && commandRef != CardCommandRef::DECREASE) {
432 if (commandIndex ==
static_cast<int>(commands.size() - 1)) {
438 for (
int i = commandIndex + 1; i < static_cast<int>(commands.size()); i++) {
439 commandRef = commands[i]->getCommandRef();
440 if (commandRef == CardCommandRef::SV_RELOAD
441 || commandRef == CardCommandRef::SV_DEBIT
442 || commandRef == CardCommandRef::SV_UNDEBIT) {
445 }
else if (commandRef == CardCommandRef::CLOSE_SECURE_SESSION) {
448 = std::dynamic_pointer_cast<CommandCloseSecureSession>(
451 if (session !=
nullptr) {
452 session->incrementSvPostponedDataIndex();
462SecureSymmetricCryptoTransactionManagerAdapter<T>::
463 synchronizeCryptoServiceBeforeCardProcessing(
464 const std::vector<std::shared_ptr<Command>>& commands)
466 for (
const auto& command : commands) {
467 if (!command->synchronizeCryptoServiceBeforeCardProcessing()) {
477SecureSymmetricCryptoTransactionManagerAdapter<
478 T>::processCryptoPreparedCommands()
480 if (mSymmetricCryptoCardTransactionManagerSpi !=
nullptr) {
482 mSymmetricCryptoCardTransactionManagerSpi->synchronize();
484 }
catch (
const SymmetricCryptoException& e) {
485 throw CryptoException(e.what(), e);
487 }
catch (
const SymmetricCryptoIOException& e) {
488 throw CryptoIOException(e.what(), e);
495SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareVerifyPin(
496 const std::vector<std::uint8_t>& pin)
499 Assert::getInstance().isEqual(
500 pin.size(), CalypsoCardConstant::PIN_LENGTH,
"PIN length");
502 if (!SecureTransactionManagerAdapter<T>::mCard
503 ->isPinFeatureAvailable()) {
504 throw UnsupportedOperationException(MSG_PIN_NOT_AVAILABLE);
507 if (mSymmetricCryptoSecuritySetting ==
nullptr
508 || mSymmetricCryptoSecuritySetting
509 ->isPinPlainTransmissionEnabled()) {
510 SecureTransactionManagerAdapter<T>::mCommands.push_back(
511 std::unique_ptr<CommandVerifyPin>(
new CommandVerifyPin(
512 getTransactionContext(), getCommandContext(), pin)));
519 SecureTransactionManagerAdapter<T>::mCommands.push_back(
520 std::make_shared<CommandGetChallenge>(
521 getTransactionContext(), getCommandContext()));
522 SecureTransactionManagerAdapter<T>::mCommands.push_back(
523 std::make_shared<CommandVerifyPin>(
524 getTransactionContext(),
527 *mSymmetricCryptoSecuritySetting
528 ->getPinVerificationCipheringKif(),
529 *mSymmetricCryptoSecuritySetting
530 ->getPinVerificationCipheringKvc()));
538 return dynamic_cast<T&
>(*this);
543SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareChangePin(
544 const std::vector<std::uint8_t>& newPin)
547 Assert::getInstance().isEqual(
548 newPin.size(), CalypsoCardConstant::PIN_LENGTH,
"PIN length");
550 if (!SecureTransactionManagerAdapter<T>::mCard
551 ->isPinFeatureAvailable()) {
552 throw UnsupportedOperationException(MSG_PIN_NOT_AVAILABLE);
555 SecureTransactionManagerAdapter<T>::checkNoSecureSession();
558 if (mSymmetricCryptoSecuritySetting ==
nullptr
559 || mSymmetricCryptoSecuritySetting
560 ->isPinPlainTransmissionEnabled()) {
561 SecureTransactionManagerAdapter<T>::mCommands.push_back(
562 std::make_shared<CommandChangePin>(
563 getTransactionContext(), getCommandContext(), newPin));
567 SecureTransactionManagerAdapter<T>::mCommands.push_back(
568 std::make_shared<CommandGetChallenge>(
569 getTransactionContext(), getCommandContext()));
570 SecureTransactionManagerAdapter<T>::mCommands.push_back(
571 std::make_shared<CommandChangePin>(
572 getTransactionContext(),
575 *mSymmetricCryptoSecuritySetting
576 ->getPinModificationCipheringKif(),
577 *mSymmetricCryptoSecuritySetting
578 ->getPinModificationCipheringKvc()));
586 return dynamic_cast<T&
>(*this);
590std::shared_ptr<CardTransactionCryptoExtension>
591SecureSymmetricCryptoTransactionManagerAdapter<T>::getCryptoExtension()
593 return mCryptoExtension;
598SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareOpenSecureSession(
599 WriteAccessLevel writeAccessLevel)
602 SecureTransactionManagerAdapter<T>::checkNoSecureSession();
604 if (SecureTransactionManagerAdapter<T>::mCard
605 ->getPreOpenWriteAccessLevel()
606 != WriteAccessLevel::UNKOWN
607 && SecureTransactionManagerAdapter<T>::mCard
608 ->getPreOpenWriteAccessLevel()
609 != writeAccessLevel) {
611 std::string(
"Pre-open mode cancelled because writeAccessLevel")
612 +
"mismatches writeAccessLevel used for pre-open mode "
613 +
"[writeAccessLevel=%, preOpenWriteAccessLevel=%]\n",
614 std::to_string(
static_cast<int>(writeAccessLevel)),
616 static_cast<int>(SecureTransactionManagerAdapter<T>::mCard
617 ->getPreOpenWriteAccessLevel())));
619 SecureTransactionManagerAdapter<T>::disablePreOpenMode();
622 SecureTransactionManagerAdapter<T>::mCommands.push_back(
623 std::make_shared<CommandOpenSecureSession>(
626 mSymmetricCryptoSecuritySetting,
630 mWriteAccessLevel = writeAccessLevel;
631 SecureTransactionManagerAdapter<T>::mIsSecureSessionOpen =
true;
632 mIsEncryptionActive =
false;
633 mModificationsCounter = SecureTransactionManagerAdapter<T>::mCard
634 ->getModificationsCounter();
635 mNbPostponedData = 0;
636 mSvPostponedDataIndex = -1;
637 mIsSvOperationInSecureSession =
false;
644 return dynamic_cast<T&
>(*this);
649SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareCloseSecureSession()
652 SecureTransactionManagerAdapter<T>::checkSecureSession();
654 auto reader = std::dynamic_pointer_cast<CardReader>(
655 SecureTransactionManagerAdapter<T>::mCardReader);
656 if (mSymmetricCryptoSecuritySetting->isRatificationMechanismEnabled()
657 && reader !=
nullptr && reader->isContactless()) {
663 SecureTransactionManagerAdapter<T>::mCommands.push_back(
664 std::unique_ptr<CommandCloseSecureSession>(
665 new CommandCloseSecureSession(
666 getTransactionContext(),
669 mSvPostponedDataIndex)));
670 SecureTransactionManagerAdapter<T>::mCommands.push_back(
671 std::unique_ptr<CommandRatification>(
new CommandRatification(
672 getTransactionContext(), getCommandContext())));
675 SecureTransactionManagerAdapter<T>::mCommands.push_back(
676 std::unique_ptr<CommandCloseSecureSession>(
677 new CommandCloseSecureSession(
678 getTransactionContext(),
681 mSvPostponedDataIndex)));
688 resetCommandContext();
689 SecureTransactionManagerAdapter<T>::disablePreOpenMode();
695 resetCommandContext();
696 SecureTransactionManagerAdapter<T>::disablePreOpenMode();
698 return dynamic_cast<T&
>(*this);
703SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareSvGet(
704 SvOperation svOperation, SvAction svAction)
707 if (!SecureTransactionManagerAdapter<T>::mCard
708 ->isSvFeatureAvailable()) {
709 throw UnsupportedOperationException(
710 "Stored Value is not available for this card");
713 if (mSymmetricCryptoSecuritySetting->isSvLoadAndDebitLogEnabled()
714 && !mIsExtendedMode) {
721 SvOperation operation1 = svOperation == SvOperation::RELOAD
723 : SvOperation::RELOAD;
725 SecureTransactionManagerAdapter<T>::mCommands.push_back(
726 std::unique_ptr<CommandSvGet>(
new CommandSvGet(
733 SecureTransactionManagerAdapter<T>::mCommands.push_back(
734 std::unique_ptr<CommandSvGet>(
new CommandSvGet(
741 mSvOperation = svOperation;
742 mSvAction = svAction;
749 return dynamic_cast<T&
>(*this);
754SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareSvReload(
756 const std::vector<std::uint8_t>& date,
757 const std::vector<std::uint8_t>& time,
758 const std::vector<std::uint8_t>& free)
769 if (amount < CalypsoCardConstant::SV_LOAD_MIN_VALUE
770 || amount > CalypsoCardConstant::SV_LOAD_MAX_VALUE) {
771 throw IllegalArgumentException(
772 "Argument [amount] has a value [" + std::to_string(amount)
774 + std::to_string(CalypsoCardConstant::SV_LOAD_MIN_VALUE) +
".."
775 + std::to_string(CalypsoCardConstant::SV_LOAD_MAX_VALUE)
779 Assert::getInstance()
780 .isEqual(date.size(), 2,
"date")
781 .isEqual(time.size(), 2,
"time")
782 .isEqual(free.size(), 2,
"free");
784 checkSvModifyingCommandPreconditions(SvOperation::RELOAD);
786 auto command = std::make_shared<CommandSvReload>(
795 prepareNewSecureSessionIfNeeded(command);
796 SecureTransactionManagerAdapter<T>::mCommands.push_back(command);
803 return dynamic_cast<T&
>(*this);
808SecureSymmetricCryptoTransactionManagerAdapter<
809 T>::checkSvModifyingCommandPreconditions(SvOperation svOperation)
816 throw IllegalStateException(
817 "SV modifying command must follow an SV Get command");
821 if (svOperation != mSvOperation) {
822 throw IllegalStateException(
823 std::string(
"SV operation is inconsistent with previous SV Get")
824 +
" command. Expected: "
825 + std::to_string(
static_cast<int>(mSvOperation))
826 +
", Actual: " + std::to_string(
static_cast<int>(svOperation)));
830 if (SecureTransactionManagerAdapter<T>::mIsSecureSessionOpen) {
831 if (mIsSvOperationInSecureSession) {
832 throw IllegalStateException(
833 "Only one SV modifying command is allowed per Secure Session");
836 mIsSvOperationInSecureSession =
true;
837 mSvPostponedDataIndex = mNbPostponedData;
844SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareSvReload(
int amount)
846 const std::vector<std::uint8_t> zero = {0x00, 0x00};
847 prepareSvReload(amount, zero, zero, zero);
849 return dynamic_cast<T&
>(*this);
854SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareSvDebit(
856 const std::vector<std::uint8_t>& date,
857 const std::vector<std::uint8_t>& time)
863 Assert::getInstance()
866 CalypsoCardConstant::SV_DEBIT_MIN_VALUE,
867 CalypsoCardConstant::SV_DEBIT_MAX_VALUE,
869 .isEqual(date.size(), 2,
"date")
870 .isEqual(time.size(), 2,
"time");
872 checkSvModifyingCommandPreconditions(SvOperation::DEBIT);
874 auto command = std::make_shared<CommandSvDebitOrUndebit>(
875 mSvAction == SvAction::DO,
882 mSymmetricCryptoSecuritySetting->isSvNegativeBalanceAuthorized());
884 prepareNewSecureSessionIfNeeded(command);
885 SecureTransactionManagerAdapter<T>::mCommands.push_back(command);
892 return dynamic_cast<T&
>(*this);
897SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareSvDebit(
int amount)
899 const std::vector<std::uint8_t> zero = {0x00, 0x00};
901 prepareSvDebit(amount, zero, zero);
903 return dynamic_cast<T&
>(*this);
908SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareInvalidate()
911 if (SecureTransactionManagerAdapter<T>::mCard->isDfInvalidated()) {
912 throw IllegalStateException(
"Card is already invalidated");
915 auto command = std::make_shared<CommandInvalidate>(
916 mTransactionContext, getCommandContext());
918 prepareNewSecureSessionIfNeeded(command);
919 SecureTransactionManagerAdapter<T>::mCommands.push_back(command);
926 return dynamic_cast<T&
>(*this);
931SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareRehabilitate()
934 if (!SecureTransactionManagerAdapter<T>::mCard->isDfInvalidated()) {
935 throw IllegalStateException(
"Card is not invalidated");
938 auto command = std::make_shared<CommandRehabilitate>(
939 mTransactionContext, getCommandContext());
941 prepareNewSecureSessionIfNeeded(command);
942 SecureTransactionManagerAdapter<T>::mCommands.push_back(command);
949 return dynamic_cast<T&
>(*this);
954SecureSymmetricCryptoTransactionManagerAdapter<T>::prepareChangeKey(
958 std::uint8_t issuerKif,
959 std::uint8_t issuerKvc)
962 if (SecureTransactionManagerAdapter<T>::mCard->getProductType()
963 == CalypsoCard::ProductType::BASIC) {
964 throw UnsupportedOperationException(
965 "'Change Key' command is not available for this card");
968 SecureTransactionManagerAdapter<T>::checkNoSecureSession();
969 Assert::getInstance().isInRange(keyIndex, 1, 3,
"keyIndex");
972 SecureTransactionManagerAdapter<T>::mCommands.push_back(
973 std::unique_ptr<CommandGetChallenge>(
new CommandGetChallenge(
974 mTransactionContext, getCommandContext())));
975 SecureTransactionManagerAdapter<T>::mCommands.push_back(
976 std::unique_ptr<CommandChangeKey>(
new CommandChangeKey(
979 static_cast<std::uint8_t
>(keyIndex),
990 return dynamic_cast<T&
>(*this);
998#include "keypop/calypso/card/cpp/SecureExtendedModeTransactionManagerBase.hpp"
999#include "keypop/calypso/card/cpp/SecureRegularModeTransactionManagerBase.hpp"
1001template class keyple::card::calypso::
1002 SecureSymmetricCryptoTransactionManagerAdapter<
1003 keypop::calypso::card::cpp::SecureExtendedModeTransactionManagerBase>;
1005template class keyple::card::calypso::
1006 SecureSymmetricCryptoTransactionManagerAdapter<
1007 keypop::calypso::card::cpp::SecureRegularModeTransactionManagerBase>;