Keyple Card Calypso C++ Library - 3.2.2
Component of the Keyple C++ middleware
CommandGetChallenge.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2025 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional *
5 * information regarding copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the *
8 * terms of the Eclipse Public License 2.0 which is available at *
9 * http://www.eclipse.org/legal/epl-2.0 *
10 * *
11 * SPDX-License-Identifier: EPL-2.0 *
12 ******************************************************************************/
13
14#include "keyple/card/calypso/CommandGetChallenge.hpp"
15
16#include <memory>
17#include <string>
18#include <vector>
19
20#include "keyple/card/calypso/CalypsoCardAdapter.hpp"
21#include "keyple/core/util/ApduUtil.hpp"
22
23namespace keyple {
24namespace card {
25namespace calypso {
26
27using keyple::core::util::ApduUtil;
28
29CommandGetChallenge::CommandGetChallenge(
30 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
31 transactionContext,
32 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext)
33: Command(
34 CardCommandRef::GET_CHALLENGE,
35 std::unique_ptr<int>(new int(8)),
36 transactionContext,
37 commandContext)
38{
39 /* APDU Case 2 */
40 setApduRequest(
41 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
42 getTransactionContext()->getCard()->getCardClass().getValue(),
43 getCommandRef().getInstructionByte(),
44 0x00,
45 0x00,
46 static_cast<std::uint8_t>(8))));
47}
48
49void
50CommandGetChallenge::finalizeRequest()
51{
52 encryptRequestAndUpdateTerminalSessionMacIfNeeded();
53}
54
55bool
56CommandGetChallenge::isCryptoServiceRequiredToFinalizeRequest() const
57{
58 return getCommandContext()->isEncryptionActive();
59}
60
61bool
62CommandGetChallenge::synchronizeCryptoServiceBeforeCardProcessing()
63{
64 /* Need to synchronize the card image with the challenge. */
65 return false;
66}
67
68void
69CommandGetChallenge::parseResponse(
70 std::shared_ptr<ApduResponseApi> apduResponse)
71{
72 decryptResponseAndUpdateTerminalSessionMacIfNeeded(apduResponse);
73 Command::setApduResponseAndCheckStatus(apduResponse);
74 getTransactionContext()->getCard()->setChallenge(
75 getApduResponse()->getDataOut());
76 updateTerminalSessionIfNeeded();
77}
78
79} /* namespace calypso */
80} /* namespace card */
81} /* namespace keyple */