diff --git a/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/CardReaderObserver.cpp b/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/CardReaderObserver.cpp index 375419f..79fd295 100644 --- a/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/CardReaderObserver.cpp +++ b/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/CardReaderObserver.cpp @@ -151,7 +151,7 @@ CardReaderObserver::onReaderEvent( } catch (const std::exception& e) { mLogger->error( - "%Transaction failed with exception: %%\n", + "%Transaction failed with exception: % %\n", ANSI_RED, e.what(), ANSI_RESET); @@ -188,8 +188,8 @@ CardReaderObserver::onReaderObservationError( const std::string& readerName, const std::shared_ptr e) { mLogger->error( - "An exception occurred in plugin '%', reader '%'\n", + "An exception occurred in plugin '%', reader '%': %\n", pluginName, readerName, - e); + e ? e->what() : "unknown"); } diff --git a/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/Main_SessionTrace_TN313_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/Main_SessionTrace_TN313_Pcsc.cpp index 54da9ce..8c44251 100644 --- a/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/Main_SessionTrace_TN313_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase10_SessionTrace_TN313/Main_SessionTrace_TN313_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -28,10 +29,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp" @@ -58,10 +58,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCardSelectionExtension; @@ -96,7 +95,7 @@ static std::string cardReaderRegex = CARD_READER_NAME_REGEX; static std::string samReaderRegex = SAM_READER_NAME_REGEX; /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; static std::string cardAid = AID; @@ -128,7 +127,7 @@ displayUsageAndExit() { << AID << "\" -c=\"" << CARD_READER_NAME_REGEX << "\" -s=\"" << SAM_READER_NAME_REGEX << "\")" << std::endl; std::cout << " -a, --aid=\"APPLICATION_AID\" between 5 and 16 hex " - "bytes (e.g. \"315449432E49434131\")" + "bytes (e.g. \"A000000291FF9101\")" << std::endl; std::cout << " -c, --card=\"CARD_READER_REGEX\" regular expression " "matching the card reader name (e.g. \"ASK Logo.*\")" @@ -218,7 +217,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ISO_CARD_PROTOCOL); } @@ -233,7 +232,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), SAM_PROTOCOL); } @@ -303,8 +302,8 @@ initSecuritySetting() { symmetricCryptoSecuritySetting->initCryptoContextForNextTransaction(); } -int -main(int argc, char** argv) { +static int +runExample(int argc, char** argv) { parseCommandLine(argc, argv); logger->info( @@ -381,3 +380,14 @@ main(int argc, char** argv) { return 0; } + +int +main(int argc, char** argv) { + try { + return runExample(argc, argv); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase11_DataSigning/Main_DataSigning_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase11_DataSigning/Main_DataSigning_Pcsc.cpp index 45038f8..7d77f0b 100644 --- a/Example_Card_Calypso/src/main/UseCase11_DataSigning/Main_DataSigning_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase11_DataSigning/Main_DataSigning_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -457,8 +458,8 @@ getInput() { return static_cast(getchar()); } -int -main() { +static int +runExample() { /* Initialize the context */ initKeypleService(); initLegacySamExtensionService(); @@ -497,3 +498,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase12_PerformanceMeasurement_EmbeddedValidation/Main_PerformanceMeasurement_EmbeddedValidation_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase12_PerformanceMeasurement_EmbeddedValidation/Main_PerformanceMeasurement_EmbeddedValidation_Pcsc.cpp index 5afb321..0066d2c 100644 --- a/Example_Card_Calypso/src/main/UseCase12_PerformanceMeasurement_EmbeddedValidation/Main_PerformanceMeasurement_EmbeddedValidation_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase12_PerformanceMeasurement_EmbeddedValidation/Main_PerformanceMeasurement_EmbeddedValidation_Pcsc.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -29,10 +30,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -64,10 +64,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -108,7 +107,7 @@ static const std::string samReaderRegex = ConfigurationUtil::SAM_READER_NAME_REGEX; /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string cardAid = "315449432E49434131"; +static const std::string cardAid = "A000000291FF9101"; static const int counterDecrement = 1; static const std::vector newEventRecord( @@ -162,7 +161,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -177,7 +176,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -275,8 +274,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "%=============== Performance measurement: validation transaction " "===============\n", @@ -423,7 +422,7 @@ main() { ->initCryptoContextForNextTransaction(); } catch (const std::exception& e) { logger->info( - "%Transaction failed with exception: %s %\n", + "%Transaction failed with exception: % %\n", ANSI_RED, e.what(), ANSI_RESET); @@ -437,3 +436,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase13_PerformanceMeasurement_DistributedReloading/Main_PerformanceMeasurement_DistributedReloading_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase13_PerformanceMeasurement_DistributedReloading/Main_PerformanceMeasurement_DistributedReloading_Pcsc.cpp index de5ccc6..3a15ac5 100644 --- a/Example_Card_Calypso/src/main/UseCase13_PerformanceMeasurement_DistributedReloading/Main_PerformanceMeasurement_DistributedReloading_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase13_PerformanceMeasurement_DistributedReloading/Main_PerformanceMeasurement_DistributedReloading_Pcsc.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -29,10 +30,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -64,10 +64,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -109,7 +108,7 @@ static const std::string samReaderRegex = ConfigurationUtil::SAM_READER_NAME_REGEX; /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string cardAid = "315449432E49434131"; +static const std::string cardAid = "A000000291FF9101"; static const int counterIncrement = 1; static const std::vector newContractListRecord( @@ -165,7 +164,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -180,7 +179,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -278,8 +277,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "%=============== Performance measurement: validation transaction " "===============\n", @@ -415,7 +414,7 @@ main() { ANSI_RESET); } catch (const std::exception& e) { logger->info( - "%Transaction failed with exception: %s %\n", + "%Transaction failed with exception: % %\n", ANSI_RED, e.what(), ANSI_RESET); @@ -429,3 +428,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Pcsc.cpp index 3216169..c481904 100644 --- a/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -24,9 +25,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" #include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp" @@ -47,9 +48,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::card::CalypsoCard; using keypop::calypso::card::card::CalypsoCardSelectionExtension; @@ -86,7 +87,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_ExplicitSelectionAid_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* File identifiers */ static const std::uint8_t SFI_ENVIRONMENT_AND_HOLDER = 0x07; @@ -132,7 +133,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -148,8 +149,8 @@ initCalypsoCardExtensionService() { calypsoCardApiFactory = calypsoExtensionService->getCalypsoCardApiFactory(); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #1: AID based explicit selection " "==================\n"); @@ -210,3 +211,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Stub.cpp b/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Stub.cpp index 5f61383..1a199a4 100644 --- a/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Stub.cpp +++ b/Example_Card_Calypso/src/main/UseCase1_ExplicitSelectionAid/Main_ExplicitSelectionAid_Stub.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -156,8 +157,8 @@ initCalypsoCardExtensionService() { calypsoCardApiFactory = calypsoExtensionService->getCalypsoCardApiFactory(); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #1: AID based explicit selection " "==================\n"); @@ -223,3 +224,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/CardReaderObserver.cpp b/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/CardReaderObserver.cpp index 6fe1e76..82df0b7 100644 --- a/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/CardReaderObserver.cpp +++ b/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/CardReaderObserver.cpp @@ -88,8 +88,8 @@ CardReaderObserver::onReaderObservationError( const std::string& readerName, const std::shared_ptr e) { mLogger->error( - "An exception occurred in plugin '%', reader '%'\n", + "An exception occurred in plugin '%', reader '%': %\n", pluginName, readerName, - e); + e ? e->what() : "unknown"); } diff --git a/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp index 9eab46f..cc1d8dc 100644 --- a/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -23,9 +24,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/Thread.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp" #include "keypop/reader/CardReader.hpp" @@ -44,9 +45,9 @@ using keyple::core::service::SmartCardServiceProvider; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::Thread; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::card::CalypsoCardSelectionExtension; using keypop::reader::CardReader; @@ -71,7 +72,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_ScheduledSelection_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* File identifiers */ static const std::uint8_t SFI_ENVIRONMENT_AND_HOLDER = 0x07; @@ -114,7 +115,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -130,8 +131,8 @@ initCalypsoCardExtensionService() { calypsoCardApiFactory = calypsoExtensionService->getCalypsoCardApiFactory(); } -int -main() { +static int +runExample() { logger->info( "= UseCase Generic #2: scheduled selection ==================\n"); @@ -200,3 +201,14 @@ main() { Thread::sleep(100); } } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Stub.cpp b/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Stub.cpp index 4eae008..047178a 100644 --- a/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Stub.cpp +++ b/Example_Card_Calypso/src/main/UseCase2_ScheduledSelection/Main_ScheduledSelection_Stub.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -153,8 +154,8 @@ initCalypsoCardExtensionService() { calypsoCardApiFactory = calypsoExtensionService->getCalypsoCardApiFactory(); } -int -main() { +static int +runExample() { logger->info( "= UseCase Generic #2: scheduled selection ==================\n"); @@ -223,3 +224,14 @@ main() { Thread::sleep(100); } } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase3_Rev1Selection/Main_Rev1Selection_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase3_Rev1Selection/Main_Rev1Selection_Pcsc.cpp index dd608c5..a74ae9c 100644 --- a/Example_Card_Calypso/src/main/UseCase3_Rev1Selection/Main_Rev1Selection_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase3_Rev1Selection/Main_Rev1Selection_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -26,7 +27,7 @@ #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" #include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp" @@ -51,7 +52,7 @@ using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::card::CalypsoCard; using keypop::calypso::card::card::CalypsoCardSelectionExtension; @@ -115,7 +116,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::INNOVATRON_B_PRIME_CARD.getName(), + PcscCardCommunicationProtocol::INNOVATRON_B_PRIME.getName(), ConfigurationUtil::INNOVATRON_CARD_PROTOCOL); } @@ -131,8 +132,8 @@ initCalypsoCardExtensionService() { calypsoCardApiFactory = calypsoExtensionService->getCalypsoCardApiFactory(); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #3: selection of a rev1 card " "==================\n"); @@ -215,3 +216,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc.cpp index ecbda78..ab2f4ed 100644 --- a/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -26,10 +27,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -59,10 +59,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -99,7 +98,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_CardAuthentication_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* File identifiers */ static const std::uint8_t SFI_ENVIRONMENT_AND_HOLDER = 0x07; @@ -148,7 +147,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -163,7 +162,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -271,8 +270,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #4: Calypso card authentication " "==================\n"); @@ -333,3 +332,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc_SamResourceService.cpp b/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc_SamResourceService.cpp index 05a6705..d69447e 100644 --- a/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc_SamResourceService.cpp +++ b/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Pcsc_SamResourceService.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -35,9 +36,9 @@ #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/Exception.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -77,9 +78,9 @@ using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::Exception; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -111,7 +112,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger( typeid(Main_CardAuthentication_Pcsc_SamResourceService)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* File identifiers */ static const std::uint8_t SFI_ENVIRONMENT_AND_HOLDER = 0x07; @@ -239,7 +240,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -365,8 +366,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #4: Calypso card authentication (Card Resource " "Service) ==================\n"); @@ -418,3 +419,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Stub.cpp b/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Stub.cpp index 6247814..9939133 100644 --- a/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Stub.cpp +++ b/Example_Card_Calypso/src/main/UseCase4_CardAuthentication/Main_CardAuthentication_Stub.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -324,8 +325,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #4: Calypso card authentication (Stub, Card " "Resource Service) ==================\n"); @@ -386,3 +387,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase5_MultipleSession/Main_MultipleSession_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase5_MultipleSession/Main_MultipleSession_Pcsc.cpp index 15f90a9..c07b8bf 100644 --- a/Example_Card_Calypso/src/main/UseCase5_MultipleSession/Main_MultipleSession_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase5_MultipleSession/Main_MultipleSession_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -27,10 +28,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -60,10 +60,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -96,7 +95,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_MultipleSession_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* File identifiers */ static const std::uint8_t SFI_EVENT_LOG = 0x08; @@ -144,7 +143,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -159,7 +158,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -254,8 +253,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #5: multiple sessions ==================\n"); @@ -339,3 +338,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase6_VerifyPin/Main_VerifyPin_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase6_VerifyPin/Main_VerifyPin_Pcsc.cpp index 144f0a2..329113c 100644 --- a/Example_Card_Calypso/src/main/UseCase6_VerifyPin/Main_VerifyPin_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase6_VerifyPin/Main_VerifyPin_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -27,10 +28,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -50,6 +50,7 @@ #include "keypop/reader/selection/IsoCardSelector.hpp" #include "keypop/reader/selection/spi/SmartCard.hpp" +#include "../common/CalypsoConstants.h" #include "../common/ConfigurationUtil.hpp" using keyple::card::calypso::CalypsoExtensionService; @@ -62,10 +63,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -96,12 +96,8 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_VerifyPin_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; -static const std::vector PIN_OK = {0x30, 0x30, 0x30, 0x30}; -static const std::vector PIN_KO = {0x30, 0x30, 0x30, 0x31}; -static const std::uint8_t PIN_VERIFICATION_CIPHERING_KEY_KIF = 0x30; -static const std::uint8_t PIN_VERIFICATION_CIPHERING_KEY_KVC = 0x79; /* The plugin used to manage the readers. */ static std::shared_ptr plugin; @@ -143,7 +139,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -158,7 +154,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -253,8 +249,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #6: Calypso card Verify PIN ==================\n"); @@ -286,14 +282,15 @@ main() { cardReader, calypsoCard)); /* Verify the PIN in plain mode without initiating a secure session */ - freeTransactionManager->prepareVerifyPin(PIN_OK).processCommands( - ChannelControl::KEEP_OPEN); + freeTransactionManager->prepareVerifyPin(CalypsoConstants::PIN_OK) + .processCommands(ChannelControl::KEEP_OPEN); logger->info( "Remaining attempts #1: %\n", calypsoCard->getPinAttemptRemaining()); /* Add the key identifiers needed for ciphering the PIN */ symmetricCryptoSecuritySetting->setPinVerificationCipheringKey( - PIN_VERIFICATION_CIPHERING_KEY_KIF, PIN_VERIFICATION_CIPHERING_KEY_KVC); + CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KIF, + CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KVC); /* * Instantiate a Secure Regular Mode Transaction Manager to handle @@ -317,7 +314,8 @@ main() { secureRegularModeTransactionManagerBase.get()); /* Verify the PIN in encrypted mode, outside a secure session */ - secureRegularModeTransactionManager->prepareVerifyPin(PIN_OK) + secureRegularModeTransactionManager + ->prepareVerifyPin(CalypsoConstants::PIN_OK) .processCommands(ChannelControl::KEEP_OPEN); /* Log the current counter value (should be 3) */ @@ -331,7 +329,8 @@ main() { secureRegularModeTransactionManager->prepareOpenSecureSession( WriteAccessLevel::DEBIT); try { - secureRegularModeTransactionManager->prepareVerifyPin(PIN_KO) + secureRegularModeTransactionManager + ->prepareVerifyPin(CalypsoConstants::PIN_KO) .processCommands(ChannelControl::KEEP_OPEN); } catch (const InvalidPinException& ex) { logger->error("PIN Exception: %\n", ex.what()); @@ -354,7 +353,8 @@ main() { logger->info( "Remaining attempts #4: %\n", calypsoCard->getPinAttemptRemaining()); - secureRegularModeTransactionManager->prepareVerifyPin(PIN_OK) + secureRegularModeTransactionManager + ->prepareVerifyPin(CalypsoConstants::PIN_OK) .prepareCloseSecureSession() .processCommands(ChannelControl::CLOSE_AFTER); @@ -370,3 +370,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase7_StoredValue_SimpleReloading/Main_StoredValue_SimpleReloading_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase7_StoredValue_SimpleReloading/Main_StoredValue_SimpleReloading_Pcsc.cpp index ce168fc..87fd4be 100644 --- a/Example_Card_Calypso/src/main/UseCase7_StoredValue_SimpleReloading/Main_StoredValue_SimpleReloading_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase7_StoredValue_SimpleReloading/Main_StoredValue_SimpleReloading_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -26,10 +27,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" #include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp" @@ -60,10 +60,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::card::CalypsoCard; using keypop::calypso::card::card::CalypsoCardSelectionExtension; @@ -95,7 +94,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_StoredValue_SimpleReloading_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* The plugin used to manage the readers. */ static std::shared_ptr plugin; @@ -137,7 +136,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -152,7 +151,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -247,8 +246,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #7: Stored Value reloading ==================\n"); @@ -317,3 +316,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase8_StoredValue_DebitInSession/Main_StoredValue_DebitInSession_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase8_StoredValue_DebitInSession/Main_StoredValue_DebitInSession_Pcsc.cpp index cc05483..cc6865e 100644 --- a/Example_Card_Calypso/src/main/UseCase8_StoredValue_DebitInSession/Main_StoredValue_DebitInSession_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase8_StoredValue_DebitInSession/Main_StoredValue_DebitInSession_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -26,10 +27,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/WriteAccessLevel.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" @@ -61,10 +61,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::WriteAccessLevel; using keypop::calypso::card::card::CalypsoCard; @@ -96,7 +95,7 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_StoredValue_DebitInSession_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; /* The plugin used to manage the readers. */ static std::shared_ptr plugin; @@ -138,7 +137,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -153,7 +152,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -248,8 +247,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #8: Stored Value debit ==================\n"); @@ -324,3 +323,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/UseCase9_ChangePin/Main_ChangePin_Pcsc.cpp b/Example_Card_Calypso/src/main/UseCase9_ChangePin/Main_ChangePin_Pcsc.cpp index 1790adf..c2ce62d 100644 --- a/Example_Card_Calypso/src/main/UseCase9_ChangePin/Main_ChangePin_Pcsc.cpp +++ b/Example_Card_Calypso/src/main/UseCase9_ChangePin/Main_ChangePin_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -30,10 +31,9 @@ #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/Thread.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactProtocol.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/calypso/card/CalypsoCardApiFactory.hpp" #include "keypop/calypso/card/card/CalypsoCard.hpp" #include "keypop/calypso/card/card/CalypsoCardSelectionExtension.hpp" @@ -49,6 +49,7 @@ #include "keypop/reader/selection/IsoCardSelector.hpp" #include "keypop/reader/selection/spi/SmartCard.hpp" +#include "../common/CalypsoConstants.h" #include "../common/ConfigurationUtil.hpp" using keyple::card::calypso::CalypsoExtensionService; @@ -62,10 +63,9 @@ using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::Thread; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; -using keyple::plugin::pcsc::PcscSupportedContactProtocol; using keypop::calypso::card::CalypsoCardApiFactory; using keypop::calypso::card::card::CalypsoCard; using keypop::calypso::card::card::CalypsoCardSelectionExtension; @@ -95,12 +95,8 @@ static std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_ChangePin_Pcsc)); /** AID: Keyple test kit profile 1, Application 2 */ -static const std::string AID = "315449432E49434131"; +static const std::string AID = "A000000291FF9101"; -static const std::uint8_t PIN_MODIFICATION_CIPHERING_KEY_KIF = 0x21; -static const std::uint8_t PIN_MODIFICATION_CIPHERING_KEY_KVC = 0x79; -static const std::uint8_t PIN_VERIFICATION_CIPHERING_KEY_KIF = 0x30; -static const std::uint8_t PIN_VERIFICATION_CIPHERING_KEY_KVC = 0x79; /* The plugin used to manage the readers. */ static std::shared_ptr plugin; @@ -142,7 +138,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::SHARED, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } @@ -157,7 +153,7 @@ initSamReader() { false, PcscReader::IsoProtocol::ANY, PcscReader::SharingMode::SHARED, - PcscSupportedContactProtocol::ISO_7816_3_T0.getName(), + PcscCardCommunicationProtocol::ISO_7816_3.getName(), ConfigurationUtil::SAM_PROTOCOL); } @@ -252,8 +248,8 @@ selectCard(std::shared_ptr reader, const std::string& aid) { return std::dynamic_pointer_cast(card); } -int -main() { +static int +runExample() { logger->info( "= UseCase Calypso #9: Calypso card Change PIN ==================\n"); @@ -281,11 +277,11 @@ main() { /* Add the key identifiers needed for ciphering the PIN */ symmetricCryptoSecuritySetting ->setPinVerificationCipheringKey( - PIN_VERIFICATION_CIPHERING_KEY_KIF, - PIN_VERIFICATION_CIPHERING_KEY_KVC) + CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KIF, + CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KVC) .setPinModificationCipheringKey( - PIN_MODIFICATION_CIPHERING_KEY_KIF, - PIN_MODIFICATION_CIPHERING_KEY_KVC); + CalypsoConstants::PIN_MODIFICATION_CIPHERING_KEY_KIF, + CalypsoConstants::PIN_MODIFICATION_CIPHERING_KEY_KVC); /* * Instantiate a Secure Regular Mode Transaction Manager to handle @@ -330,3 +326,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Card_Calypso/src/main/common/CalypsoConstants.cpp b/Example_Card_Calypso/src/main/common/CalypsoConstants.cpp index 61edb0d..55d1ccc 100644 --- a/Example_Card_Calypso/src/main/common/CalypsoConstants.cpp +++ b/Example_Card_Calypso/src/main/common/CalypsoConstants.cpp @@ -12,7 +12,7 @@ #include "CalypsoConstants.h" -const std::string CalypsoConstants::AID = "315449432E49434131"; +const std::string CalypsoConstants::AID = "A000000291FF9101"; const uint8_t CalypsoConstants::RECORD_SIZE = 29; const uint8_t CalypsoConstants::RECORD_NUMBER_1 = 1; @@ -35,7 +35,7 @@ const std::string CalypsoConstants::SAM_PROFILE_NAME = "SAM C1"; const uint8_t CalypsoConstants::PIN_MODIFICATION_CIPHERING_KEY_KIF = 0x21; const uint8_t CalypsoConstants::PIN_MODIFICATION_CIPHERING_KEY_KVC = 0x79; const uint8_t CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KIF = 0x30; -const uint8_t CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KVC = 0x79; +const uint8_t CalypsoConstants::PIN_VERIFICATION_CIPHERING_KEY_KVC = 0x74; const std::vector CalypsoConstants::PIN_OK = {0x30, 0x30, 0x30, 0x30}; const std::vector CalypsoConstants::PIN_KO = {0x30, 0x30, 0x30, 0x31}; diff --git a/Example_Card_Calypso/src/main/common/ConfigurationUtil.cpp b/Example_Card_Calypso/src/main/common/ConfigurationUtil.cpp index 38194e8..91a5155 100644 --- a/Example_Card_Calypso/src/main/common/ConfigurationUtil.cpp +++ b/Example_Card_Calypso/src/main/common/ConfigurationUtil.cpp @@ -16,8 +16,10 @@ #include #include +#include "keyple/core/util/cpp/exception/IllegalStateException.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" +using keyple::core::util::cpp::exception::IllegalStateException; using keypop::reader::ConfigurableCardReader; const std::string ConfigurationUtil::ISO_CARD_PROTOCOL = "ISO_14443_4_CARD"; @@ -41,6 +43,11 @@ ConfigurationUtil::getReader( const std::string& logicalProtocolName) { std::shared_ptr reader(plugin->findReader(readerNameRegex)); + if (reader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + readerNameRegex + "' was found"); + } + std::dynamic_pointer_cast( plugin->getReaderExtension(typeid(PcscReader), reader->getName())) ->setContactless(isContactless) diff --git a/Example_Plugin_PCSC/src/main/UseCase1_ReaderTypeAutoIdentification/Main_ReaderTypeAutoIdentification_Pcsc.cpp b/Example_Plugin_PCSC/src/main/UseCase1_ReaderTypeAutoIdentification/Main_ReaderTypeAutoIdentification_Pcsc.cpp index 7e467be..2574d99 100644 --- a/Example_Plugin_PCSC/src/main/UseCase1_ReaderTypeAutoIdentification/Main_ReaderTypeAutoIdentification_Pcsc.cpp +++ b/Example_Plugin_PCSC/src/main/UseCase1_ReaderTypeAutoIdentification/Main_ReaderTypeAutoIdentification_Pcsc.cpp @@ -11,6 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include + #include "keyple/core/service/Plugin.hpp" #include "keyple/core/service/SmartCardService.hpp" #include "keyple/core/service/SmartCardServiceProvider.hpp" @@ -75,8 +77,8 @@ static const std::string contactFilter = ".*Identive.*|" ".*00 00.*|" ".*5x21 0.*"; -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService = SmartCardServiceProvider::getService(); @@ -103,3 +105,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Plugin_PCSC/src/main/UseCase2_ExplicitReaderType/Main_ExplicitReaderType_Pcsc.cpp b/Example_Plugin_PCSC/src/main/UseCase2_ExplicitReaderType/Main_ExplicitReaderType_Pcsc.cpp index 4c75ac0..b5de508 100644 --- a/Example_Plugin_PCSC/src/main/UseCase2_ExplicitReaderType/Main_ExplicitReaderType_Pcsc.cpp +++ b/Example_Plugin_PCSC/src/main/UseCase2_ExplicitReaderType/Main_ExplicitReaderType_Pcsc.cpp @@ -11,6 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include + #include "keyple/core/service/Plugin.hpp" #include "keyple/core/service/SmartCardService.hpp" #include "keyple/core/service/SmartCardServiceProvider.hpp" @@ -62,8 +64,8 @@ class Main_ExplicitReaderType_Pcsc { }; static const std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_ExplicitReaderType_Pcsc)); -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService = SmartCardServiceProvider::getService(); @@ -97,3 +99,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Plugin_PCSC/src/main/UseCase3_ChangeProtocolRules/Main_ChangeProtocolRules_Pcsc.cpp b/Example_Plugin_PCSC/src/main/UseCase3_ChangeProtocolRules/Main_ChangeProtocolRules_Pcsc.cpp index 476f403..8e6683f 100644 --- a/Example_Plugin_PCSC/src/main/UseCase3_ChangeProtocolRules/Main_ChangeProtocolRules_Pcsc.cpp +++ b/Example_Plugin_PCSC/src/main/UseCase3_ChangeProtocolRules/Main_ChangeProtocolRules_Pcsc.cpp @@ -11,6 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include + #include "keyple/card/generic/GenericExtensionService.hpp" #include "keyple/core/common/KeypleCardExtension.hpp" #include "keyple/core/service/Plugin.hpp" @@ -73,8 +75,8 @@ static const std::string READER_PROTOCOL_MIFARE_CLASSIC_4_K = "MIFARE_CLASSIC_4K"; static const std::string CARD_PROTOCOL_MIFARE_CLASSIC_4_K = "MIFARE_CLASSIC_4K"; -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ auto smartCardService(SmartCardServiceProvider::getService()); @@ -156,3 +158,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Plugin_PCSC/src/main/UseCase4_TransmitControl/Main_TransmitControl_Pcsc.cpp b/Example_Plugin_PCSC/src/main/UseCase4_TransmitControl/Main_TransmitControl_Pcsc.cpp index 59d9be8..aca8489 100644 --- a/Example_Plugin_PCSC/src/main/UseCase4_TransmitControl/Main_TransmitControl_Pcsc.cpp +++ b/Example_Plugin_PCSC/src/main/UseCase4_TransmitControl/Main_TransmitControl_Pcsc.cpp @@ -12,6 +12,7 @@ ******************************************************************************/ #include +#include #include #include #include @@ -184,18 +185,18 @@ class CardObserver final : public CardReaderObserverSpi, const std::string& readerName, const std::shared_ptr e) override { logger->error( - "An exception occurred in plugin '%', reader '%'\n", + "An exception occurred in plugin '%', reader '%': %\n", pluginName, readerName, - e); + e ? e->what() : "unknown"); } private: std::shared_ptr mPcscReader; }; -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService( SmartCardServiceProvider::getService()); @@ -282,3 +283,14 @@ main() { while (1) { } } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase1_BasicSelection/Main_BasicSelection_Pcsc.cpp b/Example_Service/src/main/UseCase1_BasicSelection/Main_BasicSelection_Pcsc.cpp index 3891cfa..c95a59b 100644 --- a/Example_Service/src/main/UseCase1_BasicSelection/Main_BasicSelection_Pcsc.cpp +++ b/Example_Service/src/main/UseCase1_BasicSelection/Main_BasicSelection_Pcsc.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include "keyple/card/generic/ChannelControl.hpp" @@ -21,9 +22,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/reader/CardReader.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" #include "keypop/reader/ReaderApiFactory.hpp" @@ -38,9 +39,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::reader::CardReader; using keypop::reader::ConfigurableCardReader; using keypop::reader::ReaderApiFactory; @@ -141,6 +142,11 @@ getReader( const std::string& logicalProtocolName) { const auto reader(_plugin->findReader(readerNameRegex)); + if (reader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + readerNameRegex + "' was found"); + } + auto pcscReader(std::dynamic_pointer_cast( _plugin->getReaderExtension(typeid(PcscReader), reader->getName()))); @@ -168,7 +174,7 @@ initCardReader() { true, PcscReader::IsoProtocol::T1, PcscReader::SharingMode::EXCLUSIVE, - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ISO_CARD_PROTOCOL); } @@ -202,8 +208,8 @@ selectCard(std::shared_ptr reader) { return selectionResult->getActiveSmartCard(); } -int -main() { +static int +runExample() { Logger::setLoggerLevel(Logger::Level::logTrace); logger->info("= UseCase Generic #1: basic card selection ==============\n"); @@ -237,3 +243,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase2_ProtocolBasedSelection/Main_ProtocolBasedSelection_Pcsc.cpp b/Example_Service/src/main/UseCase2_ProtocolBasedSelection/Main_ProtocolBasedSelection_Pcsc.cpp index d7ea631..0bf4e17 100644 --- a/Example_Service/src/main/UseCase2_ProtocolBasedSelection/Main_ProtocolBasedSelection_Pcsc.cpp +++ b/Example_Service/src/main/UseCase2_ProtocolBasedSelection/Main_ProtocolBasedSelection_Pcsc.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include @@ -22,6 +23,7 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" #include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" @@ -37,6 +39,7 @@ using keyple::core::service::SmartCardServiceProvider; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; @@ -136,6 +139,11 @@ getReader( const PcscReader::SharingMode sharingMode) { const auto reader(_plugin->findReader(readerNameRegex)); + if (reader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + readerNameRegex + "' was found"); + } + auto pcscReader(std::dynamic_pointer_cast( _plugin->getReaderExtension(typeid(PcscReader), reader->getName()))); @@ -144,7 +152,7 @@ getReader( .setSharingMode(sharingMode); std::dynamic_pointer_cast(reader)->activateProtocol( - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ISO_CARD_PROTOCOL); std::dynamic_pointer_cast(reader)->activateProtocol( @@ -201,8 +209,8 @@ selectCard(std::shared_ptr reader) { return selectionResult->getActiveSmartCard(); } -int -main() { +static int +runExample() { logger->info("= UseCase Generic #2: protocol based card selection " "==================\n"); @@ -231,3 +239,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase3_AidBasedSelection/Main_AidBasedSelection_Pcsc.cpp b/Example_Service/src/main/UseCase3_AidBasedSelection/Main_AidBasedSelection_Pcsc.cpp index 9300f0b..1192e42 100644 --- a/Example_Service/src/main/UseCase3_AidBasedSelection/Main_AidBasedSelection_Pcsc.cpp +++ b/Example_Service/src/main/UseCase3_AidBasedSelection/Main_AidBasedSelection_Pcsc.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include "common/ConfigurationUtil.hpp" @@ -24,9 +25,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/reader/CardReader.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" #include "keypop/reader/ReaderApiFactory.hpp" @@ -44,9 +45,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::reader::CardReader; using keypop::reader::ConfigurableCardReader; using keypop::reader::ReaderApiFactory; @@ -82,8 +83,8 @@ class Main_AidBasedSelection_Pcsc { }; const std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_AidBasedSelection_Pcsc)); -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService( SmartCardServiceProvider::getService()); @@ -109,6 +110,13 @@ main() { std::shared_ptr cardReader( plugin->findReader(ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX)); + if (cardReader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + + ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX + + "' was found"); + } + /* * Configure the reader with parameters suitable for contactless operations. */ @@ -119,7 +127,7 @@ main() { .setSharingMode(PcscReader::SharingMode::SHARED); std::dynamic_pointer_cast(cardReader) ->activateProtocol( - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); logger->info("=============== " @@ -180,3 +188,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase4_ScheduledSelection/CardReaderObserver.cpp b/Example_Service/src/main/UseCase4_ScheduledSelection/CardReaderObserver.cpp index 2cf9b50..b7dcf70 100644 --- a/Example_Service/src/main/UseCase4_ScheduledSelection/CardReaderObserver.cpp +++ b/Example_Service/src/main/UseCase4_ScheduledSelection/CardReaderObserver.cpp @@ -76,8 +76,8 @@ CardReaderObserver::onReaderObservationError( const std::string& readerName, const std::shared_ptr e) { mLogger->error( - "An exception occurred in plugin '%', reader '%'\n", + "An exception occurred in plugin '%', reader '%': %\n", pluginName, readerName, - e); + e ? e->what() : "unknown"); } diff --git a/Example_Service/src/main/UseCase4_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp b/Example_Service/src/main/UseCase4_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp index 2002137..ab6495e 100644 --- a/Example_Service/src/main/UseCase4_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp +++ b/Example_Service/src/main/UseCase4_ScheduledSelection/Main_ScheduledSelection_Pcsc.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include "CardReaderObserver.hpp" @@ -22,9 +23,10 @@ #include "keyple/core/service/SmartCardServiceProvider.hpp" #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" +#include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" #include "keypop/reader/ObservableCardReader.hpp" #include "keypop/reader/ReaderApiFactory.hpp" @@ -37,9 +39,10 @@ using keyple::core::service::SmartCardService; using keyple::core::service::SmartCardServiceProvider; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; +using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::reader::ConfigurableCardReader; using keypop::reader::ObservableCardReader; using keypop::reader::ReaderApiFactory; @@ -73,8 +76,8 @@ class Main_ScheduledSelection_Pcsc { }; const std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_ScheduledSelection_Pcsc)); -int -main() { +static int +runExample() { logger->setLoggerLevel(Logger::Level::logTrace); /* Get the instance of the SmartCardService (singleton pattern) */ @@ -102,6 +105,13 @@ main() { auto observableCardReader = std::dynamic_pointer_cast( plugin->findReader(ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX)); + if (observableCardReader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + + ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX + + "' was found"); + } + /* * Configure the reader with parameters suitable for contactless operations. */ @@ -114,7 +124,7 @@ main() { std::dynamic_pointer_cast(observableCardReader) ->activateProtocol( - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); logger->info("=============== " @@ -167,3 +177,14 @@ main() { while (true); } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase5_SequentialMultiSelection/Main_SequentialMultiSelection_Pcsc.cpp b/Example_Service/src/main/UseCase5_SequentialMultiSelection/Main_SequentialMultiSelection_Pcsc.cpp index f667ce3..164c791 100644 --- a/Example_Service/src/main/UseCase5_SequentialMultiSelection/Main_SequentialMultiSelection_Pcsc.cpp +++ b/Example_Service/src/main/UseCase5_SequentialMultiSelection/Main_SequentialMultiSelection_Pcsc.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include "common/ConfigurationUtil.hpp" @@ -24,9 +25,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/reader/CardReader.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" #include "keypop/reader/ReaderApiFactory.hpp" @@ -45,9 +46,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::reader::CardReader; using keypop::reader::ConfigurableCardReader; using keypop::reader::ReaderApiFactory; @@ -130,8 +131,8 @@ doAndAnalyseSelection( } } -int -main() { +static int +runExample() { logger->setLoggerLevel(Logger::Level::logTrace); /* Get the instance of the SmartCardService (singleton pattern) */ @@ -159,6 +160,13 @@ main() { std::shared_ptr cardReader( plugin->findReader(ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX)); + if (cardReader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + + ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX + + "' was found"); + } + /* * Configure the reader with parameters suitable for contactless operations. */ @@ -169,7 +177,7 @@ main() { .setSharingMode(PcscReader::SharingMode::SHARED); std::dynamic_pointer_cast(cardReader) ->activateProtocol( - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); logger->info("=============== " @@ -239,3 +247,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase6_GroupedMultiSelection/Main_GroupedMultiSelection_Pcsc.cpp b/Example_Service/src/main/UseCase6_GroupedMultiSelection/Main_GroupedMultiSelection_Pcsc.cpp index 595d540..09dfb69 100644 --- a/Example_Service/src/main/UseCase6_GroupedMultiSelection/Main_GroupedMultiSelection_Pcsc.cpp +++ b/Example_Service/src/main/UseCase6_GroupedMultiSelection/Main_GroupedMultiSelection_Pcsc.cpp @@ -11,6 +11,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include "common/ConfigurationUtil.hpp" @@ -24,9 +25,9 @@ #include "keyple/core/util/cpp/Logger.hpp" #include "keyple/core/util/cpp/LoggerFactory.hpp" #include "keyple/core/util/cpp/exception/IllegalStateException.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscPluginFactoryBuilder.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/reader/CardReader.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" #include "keypop/reader/ReaderApiFactory.hpp" @@ -45,9 +46,9 @@ using keyple::core::util::HexUtil; using keyple::core::util::cpp::Logger; using keyple::core::util::cpp::LoggerFactory; using keyple::core::util::cpp::exception::IllegalStateException; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscPluginFactoryBuilder; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::reader::CardReader; using keypop::reader::ConfigurableCardReader; using keypop::reader::ReaderApiFactory; @@ -88,8 +89,8 @@ class Main_GroupedMultiSelection_Pcsc { }; const std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_GroupedMultiSelection_Pcsc)); -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService( SmartCardServiceProvider::getService()); @@ -115,6 +116,13 @@ main() { std::shared_ptr cardReader( plugin->findReader(ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX)); + if (cardReader == nullptr) { + throw IllegalStateException( + "No reader matching the regex '" + + ConfigurationUtil::CONTACTLESS_READER_NAME_REGEX + + "' was found"); + } + /* * Configure the reader with parameters suitable for contactless operations. */ @@ -125,7 +133,7 @@ main() { .setSharingMode(PcscReader::SharingMode::SHARED); std::dynamic_pointer_cast(cardReader) ->activateProtocol( - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); logger->info("=============== " @@ -213,3 +221,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase7_PluginAndReaderObservation/Main_PluginAndReaderObservation_Pcsc.cpp b/Example_Service/src/main/UseCase7_PluginAndReaderObservation/Main_PluginAndReaderObservation_Pcsc.cpp index a87e3d3..09c8cb3 100644 --- a/Example_Service/src/main/UseCase7_PluginAndReaderObservation/Main_PluginAndReaderObservation_Pcsc.cpp +++ b/Example_Service/src/main/UseCase7_PluginAndReaderObservation/Main_PluginAndReaderObservation_Pcsc.cpp @@ -11,6 +11,8 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include + #include "PluginObserver.hpp" #include "keyple/core/service/ObservablePlugin.hpp" @@ -48,8 +50,8 @@ class Main_PluginAndReaderObservation_Pcsc { }; const std::unique_ptr logger = LoggerFactory::getLogger(typeid(Main_PluginAndReaderObservation_Pcsc)); -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService( SmartCardServiceProvider::getService()); @@ -85,3 +87,14 @@ main() { while (true); } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +} diff --git a/Example_Service/src/main/UseCase7_PluginAndReaderObservation/PluginObserver.cpp b/Example_Service/src/main/UseCase7_PluginAndReaderObservation/PluginObserver.cpp index 2b9b66c..4788fc9 100644 --- a/Example_Service/src/main/UseCase7_PluginAndReaderObservation/PluginObserver.cpp +++ b/Example_Service/src/main/UseCase7_PluginAndReaderObservation/PluginObserver.cpp @@ -20,14 +20,14 @@ #include "common/ConfigurationUtil.hpp" #include "keyple/core/common/KeypleReaderExtension.hpp" +#include "keyple/plugin/pcsc/PcscCardCommunicationProtocol.hpp" #include "keyple/plugin/pcsc/PcscReader.hpp" -#include "keyple/plugin/pcsc/PcscSupportedContactlessProtocol.hpp" #include "keypop/reader/ConfigurableCardReader.hpp" #include "keypop/reader/ObservableCardReader.hpp" using keyple::core::common::KeypleReaderExtension; +using keyple::plugin::pcsc::PcscCardCommunicationProtocol; using keyple::plugin::pcsc::PcscReader; -using keyple::plugin::pcsc::PcscSupportedContactlessProtocol; using keypop::reader::ConfigurableCardReader; using keypop::reader::ObservableCardReader; @@ -135,7 +135,7 @@ PluginObserver::setupReader(std::shared_ptr cardReader) { auto configurable = std::dynamic_pointer_cast(cardReader); configurable->activateProtocol( - PcscSupportedContactlessProtocol::ISO_14443_4.getName(), + PcscCardCommunicationProtocol::ISO_14443_4.getName(), ConfigurationUtil::ISO_CARD_PROTOCOL); } diff --git a/Example_Service/src/main/UseCase7_PluginAndReaderObservation/ReaderObserver.cpp b/Example_Service/src/main/UseCase7_PluginAndReaderObservation/ReaderObserver.cpp index d3c4328..9840546 100644 --- a/Example_Service/src/main/UseCase7_PluginAndReaderObservation/ReaderObserver.cpp +++ b/Example_Service/src/main/UseCase7_PluginAndReaderObservation/ReaderObserver.cpp @@ -30,7 +30,13 @@ ReaderObserver::onReaderEvent(const std::shared_ptr event) { event->getReaderName(), event->getType()); - if (event->getType() != CardReaderEvent::Type::CARD_REMOVED) { + /* + * UNAVAILABLE means the reader itself is gone: there is nothing left to + * finalize, and finalizing would restart a monitoring job on a reader that + * is being unregistered and is about to be destroyed. + */ + if (event->getType() != CardReaderEvent::Type::CARD_REMOVED + && event->getType() != CardReaderEvent::Type::UNAVAILABLE) { std::dynamic_pointer_cast( smartCardService->getPlugin(pluginName) ->getReader(event->getReaderName())) diff --git a/Example_Service_Resource/src/main/UseCase1_CardResourceService/Main_CardResourceService_Stub.cpp b/Example_Service_Resource/src/main/UseCase1_CardResourceService/Main_CardResourceService_Stub.cpp index 3be42c2..d3d1c81 100644 --- a/Example_Service_Resource/src/main/UseCase1_CardResourceService/Main_CardResourceService_Stub.cpp +++ b/Example_Service_Resource/src/main/UseCase1_CardResourceService/Main_CardResourceService_Stub.cpp @@ -13,6 +13,7 @@ * SPDX-License-Identifier: BSD-3-Clause * ******************************************************************************/ +#include #include #include #include @@ -226,8 +227,8 @@ getInput() { return static_cast(getchar()); } -int -main() { +static int +runExample() { /* Get the instance of the SmartCardService (singleton pattern) */ std::shared_ptr smartCardService = SmartCardServiceProvider::getService(); @@ -429,3 +430,14 @@ main() { return 0; } + +int +main() { + try { + return runExample(); + + } catch (const std::exception& e) { + logger->error("Example terminated on exception: %\n", e.what()); + return 1; + } +}