14#include "keyple/card/calypso/CommandChangePin.hpp"
21#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
22#include "keyple/card/calypso/CardIllegalParameterException.hpp"
23#include "keyple/card/calypso/CardSecurityContextException.hpp"
24#include "keyple/card/calypso/CardSecurityDataException.hpp"
25#include "keyple/card/calypso/CardTerminatedException.hpp"
26#include "keyple/core/util/ApduUtil.hpp"
27#include "keypop/calypso/card/transaction/CryptoException.hpp"
28#include "keypop/calypso/card/transaction/CryptoIOException.hpp"
29#include "keypop/calypso/card/transaction/InvalidPinException.hpp"
30#include "keypop/calypso/crypto/symmetric/SymmetricCryptoException.hpp"
31#include "keypop/calypso/crypto/symmetric/SymmetricCryptoIOException.hpp"
37using keyple::core::util::ApduUtil;
38using keypop::calypso::card::transaction::CryptoException;
39using keypop::calypso::card::transaction::CryptoIOException;
40using keypop::calypso::card::transaction::InvalidPinException;
41using keypop::calypso::crypto::symmetric::SymmetricCryptoException;
42using keypop::calypso::crypto::symmetric::SymmetricCryptoIOException;
44const std::map<int, const std::shared_ptr<Command::StatusProperties>>
45 CommandChangePin::STATUS_TABLE = [] {
46 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
47 Command::STATUS_TABLE);
51 std::make_shared<StatusProperties>(
52 "Lc value not supported (not 04h, 10h, 18h, 20h)",
53 typeid(CardIllegalParameterException))},
55 std::make_shared<StatusProperties>(
56 "Transaction Counter is 0",
typeid(CardTerminatedException))},
58 std::make_shared<StatusProperties>(
59 std::string(
"Security conditions not satisfied (Get ")
60 +
"Challenge not done: challenge unavailable)",
61 typeid(CardSecurityContextException))},
63 std::make_shared<StatusProperties>(
64 "Access forbidden (a session is open or DF is invalidated)",
65 typeid(CardAccessForbiddenException))},
67 std::make_shared<StatusProperties>(
68 "Incorrect Cryptogram",
typeid(CardSecurityDataException))},
70 std::make_shared<StatusProperties>(
71 "Decrypted message incorrect (key algorithm not supported, "
72 "incorrect padding, etc.",
73 typeid(CardSecurityDataException))},
75 std::make_shared<StatusProperties>(
76 "Lc not compatible with P2",
77 typeid(CardIllegalParameterException))},
79 std::make_shared<StatusProperties>(
80 "Incorrect P1, P2",
typeid(CardIllegalParameterException))}});
84CommandChangePin::CommandChangePin(
85 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
87 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
88 const std::vector<std::uint8_t>& pin)
89: Command(CardCommandRef::CHANGE_PIN, 0, transactionContext, commandContext)
91, mIsPinEncryptedMode(false)
97CommandChangePin::CommandChangePin(
98 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
100 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext,
101 const std::vector<std::uint8_t>& pin,
102 std::uint8_t cipheringKif,
103 std::uint8_t cipheringKvc)
104: Command(CardCommandRef::CHANGE_PIN, 0, transactionContext, commandContext)
106, mIsPinEncryptedMode(true)
107, mCipheringKif(cipheringKif)
108, mCipheringKvc(cipheringKvc)
113CommandChangePin::finalizeRequest()
115 if (mIsPinEncryptedMode) {
117 mPin = getTransactionContext()
118 ->getSymmetricCryptoCardTransactionManagerSpi()
119 ->cipherPinForModification(
120 getTransactionContext()->getCard()->getChallenge(),
121 std::vector<std::uint8_t>(4),
123 std::make_shared<std::uint8_t>(mCipheringKif),
124 std::make_shared<std::uint8_t>(mCipheringKvc));
126 }
catch (
const SymmetricCryptoException& e) {
127 throw CryptoException(e.what(), e);
129 }
catch (
const SymmetricCryptoIOException& e) {
130 throw CryptoIOException(e.what(), e);
136 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
137 getTransactionContext()->getCard()->getCardClass().getValue(),
138 getCommandRef().getInstructionByte(),
145CommandChangePin::isCryptoServiceRequiredToFinalizeRequest()
const
147 return mIsPinEncryptedMode;
151CommandChangePin::synchronizeCryptoServiceBeforeCardProcessing()
157CommandChangePin::parseResponse(std::shared_ptr<ApduResponseApi> apduResponse)
159 Command::setApduResponseAndCheckStatus(apduResponse);
164 getTransactionContext()->getCard()->setPinAttemptRemaining(3);
167const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
168CommandChangePin::getStatusTable()
const