Keyple Card Calypso C++ Library 2.2.2
Reference Terminal Reader API for C++
CardControlSamTransactionManagerAdapter.h
Go to the documentation of this file.
1/**************************************************************************************************
2 * Copyright (c) 2022 Calypso Networks Association https://calypsonet.org/ *
3 * *
4 * See the NOTICE file(s) distributed with this work for additional information regarding *
5 * copyright ownership. *
6 * *
7 * This program and the accompanying materials are made available under the terms of the Eclipse *
8 * Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0 *
9 * *
10 * SPDX-License-Identifier: EPL-2.0 *
11 **************************************************************************************************/
12
13#pragma once
14
15/* Calypsonet Terminal Calypso */
16#include "WriteAccessLevel.h"
17
18/* Keyple Card Calypso */
19#include "CalypsoCardAdapter.h"
21#include "CmdSamCardCipherPin.h"
23#include "CmdSamDigestClose.h"
24#include "CmdSamGetChallenge.h"
26#include "CmdSamSvPrepareLoad.h"
27#include "CmdCardSvReload.h"
30
31namespace keyple {
32namespace card {
33namespace calypso {
34
35using namespace calypsonet::terminal::calypso;
36using namespace keyple::core::util::cpp;
37
45: public CommonControlSamTransactionManagerAdapter<CardSecuritySettingAdapter> {
46public:
57 const std::shared_ptr<CalypsoCardAdapter> targetCard,
58 const std::shared_ptr<CardSecuritySettingAdapter> securitySetting,
59 const std::vector<std::vector<uint8_t>>& transactionAuditData);
60
70 std::shared_ptr<uint8_t> computeKvc(const WriteAccessLevel writeAccessLevel,
71 const std::shared_ptr<uint8_t> kvc) const;
72
83 std::shared_ptr<uint8_t> computeKif(const WriteAccessLevel writeAccessLevel,
84 const std::shared_ptr<uint8_t> kif,
85 const std::shared_ptr<uint8_t> kvc) const;
86
92 SamTransactionManager& processCommands() override;
93
101 std::shared_ptr<CmdSamGetChallenge> prepareGetChallenge();
102
109 void prepareGiveRandom();
110
122 const std::shared_ptr<CmdSamCardGenerateKey> prepareCardGenerateKey(
123 const uint8_t cipheringKif,
124 const uint8_t cipheringKvc,
125 const uint8_t sourceKif,
126 const uint8_t sourceKvc);
127
137 const std::shared_ptr<CmdSamCardCipherPin> prepareCardCipherPin(
138 const std::vector<uint8_t>& currentPin,
139 const std::vector<uint8_t>& newPin);
140
151 const std::shared_ptr<CmdSamSvPrepareLoad> prepareSvPrepareLoad(
152 const std::vector<uint8_t>& svGetHeader,
153 const std::vector<uint8_t>& svGetData,
154 const std::shared_ptr<CmdCardSvReload> cmdCardSvReload);
155
167 const std::shared_ptr<CmdSamSvPrepareDebitOrUndebit> prepareSvPrepareDebitOrUndebit(
168 const bool isDebitCommand,
169 const std::vector<uint8_t>& svGetHeader,
170 const std::vector<uint8_t>& svGetData,
171 const std::shared_ptr<CmdCardSvDebitOrUndebit> cmdCardSvDebitOrUndebit);
172
180 void prepareSvCheck(const std::vector<uint8_t>& svOperationData);
181
196 const std::vector<uint8_t>& openSecureSessionDataOut,
197 const uint8_t kif,
198 const uint8_t kvc,
199 const bool isSessionEncrypted,
200 const bool isVerificationMode);
201
211 void updateSession(const std::vector<std::shared_ptr<ApduRequestSpi>>& requests,
212 const std::vector<std::shared_ptr<ApduResponseApi>>& responses,
213 const int startIndex);
214
222 const std::shared_ptr<CmdSamDigestClose> prepareSessionClosing();
223
231 void prepareDigestAuthenticate(const std::vector<uint8_t>& cardSignatureLo);
232
233private:
238 class DigestManager {
239 public:
243 const uint8_t mSessionKif;
244
248 const uint8_t mSessionKvc;
249
253 bool mIsDigestInitDone = false;
254
258 const std::vector<uint8_t> mOpenSecureSessionDataOut;
259
263 const bool mIsSessionEncrypted;
264
268 const bool mIsVerificationMode;
269
273 std::vector<std::vector<uint8_t>> mCardApdus;
274
279
290 DigestManager(CardControlSamTransactionManagerAdapter* parent,
291 const std::vector<uint8_t>& openSecureSessionDataOut,
292 const uint8_t kif,
293 const uint8_t kvc,
294 const bool isSessionEncrypted,
295 const bool isVerificationMode);
296
305 void updateSession(const std::vector<std::shared_ptr<ApduRequestSpi>>& requests,
306 const std::vector<std::shared_ptr<ApduResponseApi>>& responses,
307 const int startIndex);
308
313 void prepareCommands();
314
319 void prepareDigestInit();
320
325 void prepareDigestUpdate();
326
331 void prepareDigestClose();
332 };
333
337 std::shared_ptr<CalypsoSamAdapter> mControlSam = nullptr;
338
342 const std::shared_ptr<CalypsoCardAdapter> mTargetCard;
343
347 const std::shared_ptr<CardSecuritySettingAdapter> mCardSecuritySetting;
348
352 std::shared_ptr<DigestManager> mDigestManager;
353};
354
355}
356}
357}
358
const std::shared_ptr< CmdSamSvPrepareDebitOrUndebit > prepareSvPrepareDebitOrUndebit(const bool isDebitCommand, const std::vector< uint8_t > &svGetHeader, const std::vector< uint8_t > &svGetData, const std::shared_ptr< CmdCardSvDebitOrUndebit > cmdCardSvDebitOrUndebit)
const std::shared_ptr< CmdSamSvPrepareLoad > prepareSvPrepareLoad(const std::vector< uint8_t > &svGetHeader, const std::vector< uint8_t > &svGetData, const std::shared_ptr< CmdCardSvReload > cmdCardSvReload)
void updateSession(const std::vector< std::shared_ptr< ApduRequestSpi > > &requests, const std::vector< std::shared_ptr< ApduResponseApi > > &responses, const int startIndex)
const std::shared_ptr< CmdSamCardGenerateKey > prepareCardGenerateKey(const uint8_t cipheringKif, const uint8_t cipheringKvc, const uint8_t sourceKif, const uint8_t sourceKvc)
CardControlSamTransactionManagerAdapter(const std::shared_ptr< CalypsoCardAdapter > targetCard, const std::shared_ptr< CardSecuritySettingAdapter > securitySetting, const std::vector< std::vector< uint8_t > > &transactionAuditData)
std::shared_ptr< uint8_t > computeKif(const WriteAccessLevel writeAccessLevel, const std::shared_ptr< uint8_t > kif, const std::shared_ptr< uint8_t > kvc) const
void initializeSession(const std::vector< uint8_t > &openSecureSessionDataOut, const uint8_t kif, const uint8_t kvc, const bool isSessionEncrypted, const bool isVerificationMode)
std::shared_ptr< uint8_t > computeKvc(const WriteAccessLevel writeAccessLevel, const std::shared_ptr< uint8_t > kvc) const
const std::shared_ptr< CmdSamCardCipherPin > prepareCardCipherPin(const std::vector< uint8_t > &currentPin, const std::vector< uint8_t > &newPin)