keyple-card-calypso-crypto-legacysam-cpp-lib - 1.0.2
Component of the Keyple C++ middleware
CommandDigestInternalAuthenticate.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (c) 2019 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/crypto/legacysam/CommandDigestInternalAuthenticate.hpp"
15
16#include <map>
17#include <memory>
18#include <string>
19#include <vector>
20
21#include "keyple/card/calypso/crypto/legacysam/AccessForbiddenException.hpp"
22#include "keyple/card/calypso/crypto/legacysam/IllegalParameterException.hpp"
23#include "keyple/core/util/ApduUtil.hpp"
24
25namespace keyple {
26namespace card {
27namespace calypso {
28namespace crypto {
29namespace legacysam {
30
31using keyple::core::util::ApduUtil;
32
33const std::map<int, const std::shared_ptr<StatusProperties>>
34 CommandDigestInternalAuthenticate::STATUS_TABLE = [] {
35 std::map<int, const std::shared_ptr<StatusProperties>> m(
36 Command::STATUS_TABLE);
37
38 m.insert(
39 {{0x6985,
40 std::make_shared<StatusProperties>(
41 std::string("Preconditions not satisfied:\n")
42 + "- Session not in 'ongoing' state.\n"
43 + "- Session not opened in Extended mode.\n"
44 + "- Session opened in Verification mode.\n"
45 + "- Authentication not allowed by the key (not an AES "
46 "key).\n"
47 + "- 250th occurrence since session start",
48 typeid(AccessForbiddenException))},
49 {0x6B00,
50 std::make_shared<StatusProperties>(
51 "Incorrect P1", typeid(IllegalParameterException))}});
52 return m;
53 }();
54
55CommandDigestInternalAuthenticate::CommandDigestInternalAuthenticate(
56 const std::shared_ptr<CommandContextDto> context)
57: Command(CommandRef::DIGEST_INTERNAL_AUTHENTICATE, 8, context)
58{
59 setApduRequest(
60 std::make_shared<ApduRequestAdapter>(ApduUtil::build(
61 context->getTargetSam()->getClassByte(),
62 getCommandRef().getInstructionByte(),
63 0x80,
64 0x00,
65 8)));
66}
67
68const std::vector<uint8_t>&
69CommandDigestInternalAuthenticate::getTerminalSignature() const
70{
71 return mTerminalSignature;
72}
73
74void
75CommandDigestInternalAuthenticate::finalizeRequest()
76{
77 /* Nothing to do */
78}
79
80bool
81CommandDigestInternalAuthenticate::isControlSamRequiredToFinalizeRequest() const
82{
83 return false;
84}
85
86void
87CommandDigestInternalAuthenticate::parseResponse(
88 const std::shared_ptr<ApduResponseApi> apduResponse)
89{
90 setResponseAndCheckStatus(apduResponse);
91
92 mTerminalSignature = apduResponse->getDataOut();
93}
94
95const std::map<int, const std::shared_ptr<StatusProperties>>&
96CommandDigestInternalAuthenticate::getStatusTable() const
97{
98 return STATUS_TABLE;
99}
100
101} /* namespace legacysam */
102} /* namespace crypto */
103} /* namespace calypso */
104} /* namespace card */
105} /* namespace keyple */