14#include "keyple/card/calypso/SecureExtendedModeTransactionManagerAdapter.hpp"
19#include "keyple/card/calypso/CardCommandRef.hpp"
20#include "keyple/card/calypso/CommandManageSession.hpp"
21#include "keyple/core/util/cpp/exception/IllegalStateException.hpp"
22#include "keyple/core/util/cpp/exception/RuntimeException.hpp"
23#include "keyple/core/util/cpp/exception/UnsupportedOperationException.hpp"
29using keyple::core::util::cpp::exception::IllegalStateException;
30using keyple::core::util::cpp::exception::RuntimeException;
31using keyple::core::util::cpp::exception::UnsupportedOperationException;
34 SecureExtendedModeTransactionManagerAdapter::MSG_MSS_COMMAND_NOT_SUPPORTED
35 = std::string(
"'Manage Secure Session' command is not available for this ")
36 +
"context (Card and/or SAM does not support extended mode)";
38 SecureExtendedModeTransactionManagerAdapter::MSG_ENCRYPTION_ALREADY_ACTIVE
39 =
"Encryption is already active";
41 SecureExtendedModeTransactionManagerAdapter::MSG_ENCRYPTION_NOT_ACTIVE
42 =
"Encryption is not active";
44SecureExtendedModeTransactionManagerAdapter::
45 SecureExtendedModeTransactionManagerAdapter(
46 std::shared_ptr<ProxyReaderApi> cardReader,
47 std::shared_ptr<CalypsoCardAdapter> card,
48 std::shared_ptr<SymmetricCryptoSecuritySettingAdapter>
49 symmetricCryptoSecuritySetting)
52 TransactionManagerAdapter<SecureExtendedModeTransactionManagerBase>(
54, SecureSymmetricCryptoTransactionManagerAdapter<
55 SecureExtendedModeTransactionManager>(
56 cardReader, card, symmetricCryptoSecuritySetting)
60SecureExtendedModeTransactionManager&
61SecureExtendedModeTransactionManagerAdapter::prepareEarlyMutualAuthentication()
64 if (!mIsExtendedMode) {
65 throw UnsupportedOperationException(MSG_MSS_COMMAND_NOT_SUPPORTED);
73 if (!mCommands.empty()
74 && mCommands[mCommands.size() - 1]->getCommandRef()
75 == CardCommandRef::MANAGE_SECURE_SESSION) {
76 auto& command = mCommands[mCommands.size() - 1];
78 = std::dynamic_pointer_cast<CommandManageSession>(command);
79 session->setMutualAuthenticationRequested(
true);
82 auto session = std::make_shared<CommandManageSession>(
83 mTransactionContext, getCommandContext());
84 session->setMutualAuthenticationRequested(
true)
85 .setEncryptionRequested(mIsEncryptionActive);
86 mCommands.push_back(session);
97SecureExtendedModeTransactionManager&
98SecureExtendedModeTransactionManagerAdapter::prepareActivateEncryption()
101 if (!mIsExtendedMode) {
102 throw UnsupportedOperationException(MSG_MSS_COMMAND_NOT_SUPPORTED);
105 checkSecureSession();
107 if (mIsEncryptionActive) {
108 throw IllegalStateException(MSG_ENCRYPTION_ALREADY_ACTIVE);
114 if (!mCommands.empty()
115 && mCommands[mCommands.size() - 1]->getCommandRef()
116 == CardCommandRef::MANAGE_SECURE_SESSION) {
117 auto command = mCommands[mCommands.size() - 1];
119 = std::dynamic_pointer_cast<CommandManageSession>(command);
120 session->setEncryptionRequested(
true);
123 auto session = std::make_shared<CommandManageSession>(
124 mTransactionContext, getCommandContext());
125 session->setEncryptionRequested(mIsEncryptionActive);
126 mCommands.push_back(session);
129 mIsEncryptionActive =
true;
139SecureExtendedModeTransactionManager&
140SecureExtendedModeTransactionManagerAdapter::prepareDeactivateEncryption()
143 if (!mIsExtendedMode) {
144 throw UnsupportedOperationException(MSG_MSS_COMMAND_NOT_SUPPORTED);
147 checkSecureSession();
149 if (!mIsEncryptionActive) {
150 throw IllegalStateException(MSG_ENCRYPTION_NOT_ACTIVE);
156 if (!mCommands.empty()
157 && mCommands[mCommands.size() - 1]->getCommandRef()
158 == CardCommandRef::MANAGE_SECURE_SESSION) {
159 auto command = mCommands[mCommands.size() - 1];
161 = std::dynamic_pointer_cast<CommandManageSession>(command);
162 session->setEncryptionRequested(
false);
165 auto session = std::make_shared<CommandManageSession>(
166 mTransactionContext, getCommandContext());
167 session->setEncryptionRequested(
false);
168 mCommands.push_back(session);
171 mIsEncryptionActive =
false;