Keyple Card Calypso C++ Library - 3.2.2
Component of the Keyple C++ middleware
CommandGenerateAsymmetricKeyPair.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/CommandGenerateAsymmetricKeyPair.hpp"
15
16#include <map>
17#include <memory>
18#include <string>
19
20#include "keyple/card/calypso/CardAccessForbiddenException.hpp"
21#include "keyple/card/calypso/CardDataAccessException.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 "keyple/core/util/HexUtil.hpp"
28#include "keypop/calypso/card/transaction/CryptoException.hpp"
29#include "keypop/calypso/card/transaction/CryptoIOException.hpp"
30#include "keypop/calypso/card/transaction/InvalidPinException.hpp"
31#include "keypop/calypso/crypto/symmetric/SymmetricCryptoException.hpp"
32#include "keypop/calypso/crypto/symmetric/SymmetricCryptoIOException.hpp"
33
34namespace keyple {
35namespace card {
36namespace calypso {
37
38using keyple::core::util::ApduUtil;
39using keyple::core::util::HexUtil;
40using keypop::calypso::card::transaction::CryptoException;
41using keypop::calypso::card::transaction::CryptoIOException;
42using keypop::calypso::card::transaction::InvalidPinException;
43using keypop::calypso::crypto::symmetric::SymmetricCryptoException;
44using keypop::calypso::crypto::symmetric::SymmetricCryptoIOException;
45
46const std::string CommandGenerateAsymmetricKeyPair::SECP256R1_OID
47 = "06082A8648CE3D030107";
48
49const std::map<int, const std::shared_ptr<Command::StatusProperties>>
50 CommandGenerateAsymmetricKeyPair::STATUS_TABLE = [] {
51 std::map<int, const std::shared_ptr<Command::StatusProperties>> m(
52 Command::STATUS_TABLE);
53
54 m.insert(
55 {{0x6700,
56 std::make_shared<StatusProperties>(
57 "Lc value not supported", typeid(CardDataAccessException))},
58 {0x6985,
59 std::make_shared<StatusProperties>(
60 "Conditions of use not satisfied: a secure session is "
61 "running or a card key pair already available",
62 typeid(CardAccessForbiddenException))},
63 {0x6986,
64 std::make_shared<StatusProperties>(
65 "Incorrect file type: the current DF is not an autonomous "
66 "PKI application",
67 typeid(CardDataAccessException))},
68 {0x6A80,
69 std::make_shared<StatusProperties>(
70 "Incorrect incoming data",
71 typeid(CardIllegalParameterException))},
72 {0x6D00,
73 std::make_shared<StatusProperties>(
74 "PKI mode not available",
75 typeid(CardIllegalParameterException))}});
76 return m;
77 }();
78
79CommandGenerateAsymmetricKeyPair::CommandGenerateAsymmetricKeyPair(
80 const std::shared_ptr<DtoAdapters::TransactionContextDto>&
81 transactionContext,
82 const std::shared_ptr<DtoAdapters::CommandContextDto>& commandContext)
83: Command(
84 CardCommandRef::GENERATE_ASYMMETRIC_KEY_PAIR,
85 std::unique_ptr<int>(new int(0)),
86 transactionContext,
87 commandContext)
88{
89 /* APDU Case 3 */
90 setApduRequest(
91 std::make_shared<DtoAdapters::ApduRequestAdapter>(ApduUtil::build(
92 getTransactionContext()->getCard()->getCardClass().getValue(),
93 getCommandRef().getInstructionByte(),
94 0x00,
95 0x00,
96 HexUtil::toByteArray(SECP256R1_OID))));
97}
98
99void
100CommandGenerateAsymmetricKeyPair::finalizeRequest()
101{
102 /* nothing to do */
103}
104
105bool
106CommandGenerateAsymmetricKeyPair::isCryptoServiceRequiredToFinalizeRequest()
107 const
108{
109 return false;
110}
111
112bool
113CommandGenerateAsymmetricKeyPair::synchronizeCryptoServiceBeforeCardProcessing()
114{
115 /* Need to synchronize the card image */
116 return false;
117}
118
119void
120CommandGenerateAsymmetricKeyPair::parseResponse(
121 std::shared_ptr<ApduResponseApi> apduResponse)
122{
123 Command::setApduResponseAndCheckStatus(apduResponse);
124}
125
126const std::map<int, const std::shared_ptr<Command::StatusProperties>>&
127CommandGenerateAsymmetricKeyPair::getStatusTable() const
128{
129 return STATUS_TABLE;
130}
131
132} /* namespace calypso */
133} /* namespace card */
134} /* namespace keyple */