14#include "keyple/card/calypso/CommandChangeKey.hpp"
21#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
22#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
23#include "keyple/card/calypso/CardIllegalParameterException.hpp"
24#include "keyple/card/calypso/CardSecurityContextException.hpp"
25#include "keyple/card/calypso/CardSecurityDataException.hpp"
26#include "keyple/card/calypso/CardTerminatedException.hpp"
27#include "keyple/core/util/ApduUtil.hpp"
28#include "keyple/core/util/HexUtil.hpp"
29#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
30#include "keypop/calypso/card/transaction/CryptoException.hpp"
31#include "keypop/calypso/card/transaction/CryptoIOException.hpp"
32#include "keypop/calypso/crypto/symmetric/SymmetricCryptoException.hpp"
33#include "keypop/calypso/crypto/symmetric/SymmetricCryptoIOException.hpp"
39using keyple::core::util::ApduUtil;
40using keyple::core::util::HexUtil;
41using keyple::core::util::cpp::exception::IllegalStateException;
42using keypop::calypso::card::transaction::CryptoException;
43using keypop::calypso::card::transaction::CryptoIOException;
44using keypop::calypso::crypto::symmetric::SymmetricCryptoException;
45using keypop::calypso::crypto::symmetric::SymmetricCryptoIOException;
47const std::map<int, const std::shared_ptr<Command::StatusProperties>>
48 CommandChangeKey::STATUS_TABLE = [] {
49 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
50 Command::STATUS_TABLE);
54 std::make_shared<StatusProperties>(
55 "Lc value not supported (not 04h, 10h, 18h, 20h)",
56 typeid(CardIllegalParameterException))},
58 std::make_shared<StatusProperties>(
59 "Transaction Counter is 0",
typeid(CardTerminatedException))},
61 std::make_shared<StatusProperties>(
62 std::string(
"Security conditions not satisfied (Get ")
63 +
"Challenge not done: challenge unavailable)",
64 typeid(CardSecurityContextException))},
66 std::make_shared<StatusProperties>(
67 "Access forbidden (a session is open or DF is invalidated)",
68 typeid(CardAccessForbiddenException))},
70 std::make_shared<StatusProperties>(
71 "Incorrect Cryptogram",
typeid(CardSecurityDataException))},
73 std::make_shared<StatusProperties>(
74 "Decrypted message incorrect (key algorithm not supported, "
75 "incorrect padding, etc.",
76 typeid(CardSecurityDataException))},
78 std::make_shared<StatusProperties>(
79 "Lc not compatible with P2",
80 typeid(CardIllegalParameterException))},
82 std::make_shared<StatusProperties>(
83 "Incorrect P1, P2",
typeid(CardIllegalParameterException))}});
87CommandChangeKey::CommandChangeKey(
88 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
90 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
91 std::uint8_t keyIndex,
94 std::uint8_t issuerKif,
95 std::uint8_t issuerKvc)
96: Command(CardCommandRef::CHANGE_KEY, 0, transactionContext, commandContext)
100, mIssuerKif(issuerKif)
101, mIssuerKvc(issuerKvc)
106CommandChangeKey::finalizeRequest()
108 std::vector<std::uint8_t> cipheredKey;
112 = getTransactionContext()
113 ->getSymmetricCryptoCardTransactionManagerSpi()
114 ->generateCipheredCardKey(
115 getTransactionContext()->getCard()->getChallenge(),
121 }
catch (
const SymmetricCryptoException& e) {
122 throw CryptoException(e.what(), e);
124 }
catch (
const SymmetricCryptoIOException& e) {
125 throw CryptoIOException(e.what(), e);
130 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
131 getTransactionContext()->getCard()->getCardClass().getValue(),
132 getCommandRef().getInstructionByte(),
139CommandChangeKey::isCryptoServiceRequiredToFinalizeRequest()
const
145CommandChangeKey::synchronizeCryptoServiceBeforeCardProcessing()
151CommandChangeKey::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
153 Command::setApduResponseAndCheckStatus(apduResponse);
156const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
157CommandChangeKey::getStatusTable()
const