14#include "keyple/card/calypso/CommandRehabilitate.hpp"
22#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
23#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
24#include "keyple/card/calypso/CardIllegalParameterException.hpp"
25#include "keyple/card/calypso/CardSecurityContextException.hpp"
26#include "keyple/card/calypso/CardSecurityDataException.hpp"
27#include "keyple/card/calypso/CardSessionBufferOverflowException.hpp"
28#include "keyple/core/util/ApduUtil.hpp"
29#include "keyple/core/util/HexUtil.hpp"
30#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
31#include "keyple/core/util/cpp/exception/UnsupportedOperationException.hpp"
32#include "keypop/calypso/card/transaction/CryptoException.hpp"
33#include "keypop/calypso/card/transaction/CryptoIOException.hpp"
34#include "keypop/calypso/card/transaction/InvalidCardSignatureException.hpp"
35#include "keypop/calypso/crypto/symmetric/SymmetricCryptoException.hpp"
36#include "keypop/calypso/crypto/symmetric/SymmetricCryptoIOException.hpp"
42using keyple::core::util::ApduUtil;
43using keyple::core::util::HexUtil;
44using keyple::core::util::cpp::exception::IllegalStateException;
45using keyple::core::util::cpp::exception::UnsupportedOperationException;
46using keypop::calypso::card::transaction::CryptoException;
47using keypop::calypso::card::transaction::CryptoIOException;
48using keypop::calypso::card::transaction::InvalidCardSignatureException;
49using keypop::calypso::crypto::symmetric::SymmetricCryptoException;
50using keypop::calypso::crypto::symmetric::SymmetricCryptoIOException;
52const std::map<int, const std::shared_ptr<Command::StatusProperties>>
53 CommandRehabilitate::STATUS_TABLE = [] {
54 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
55 Command::STATUS_TABLE);
59 std::make_shared<StatusProperties>(
60 "Too many modifications in session",
61 typeid(CardSessionBufferOverflowException))},
63 std::make_shared<StatusProperties>(
64 "Lc value not supported",
65 typeid(CardIllegalParameterException))},
67 std::make_shared<StatusProperties>(
68 "Security conditions not fulfilled (no session, wrong key)",
69 typeid(CardSecurityContextException))},
71 std::make_shared<StatusProperties>(
72 "Access forbidden (DF context is invalid)",
73 typeid(CardAccessForbiddenException))}});
77CommandRehabilitate::CommandRehabilitate(
78 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
80 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext)
81: Command(CardCommandRef::REHABILITATE, 0, transactionContext, commandContext)
85 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
86 getTransactionContext()->getCard()->getCardClass().getValue(),
87 getCommandRef().getInstructionByte(),
94CommandRehabilitate::finalizeRequest()
96 encryptRequestAndUpdateTerminalSessionMacIfNeeded();
99const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
100CommandRehabilitate::getStatusTable()
const
106CommandRehabilitate::isCryptoServiceRequiredToFinalizeRequest()
const
108 return getCommandContext()->isEncryptionActive();
112CommandRehabilitate::synchronizeCryptoServiceBeforeCardProcessing()
114 if (getCommandContext()->isEncryptionActive()) {
118 updateTerminalSessionIfNeeded(APDU_RESPONSE_9000);
124CommandRehabilitate::parseResponse(
125 std::shared_ptr<ApduResponseApi> apduResponse)
127 decryptResponseAndUpdateTerminalSessionMacIfNeeded(apduResponse);
128 Command::setApduResponseAndCheckStatus(apduResponse);
129 updateTerminalSessionIfNeeded();
135 getTransactionContext()->getCard()->setDfInvalidated(
true);