From 8dfd657a4eea51e216316e5688f8de541611cf48 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Fri, 7 Feb 2025 08:56:09 +0200 Subject: [PATCH] Remove CardInfo Signed-off-by: Raul Metsma --- include/electronic-id/electronic-id.hpp | 21 +---- lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp | 9 ++- lib/libpcsc-cpp/src/SmartCard.cpp | 12 +-- src/availableSupportedCards.cpp | 19 +---- .../listMsCryptoApiElectronicIDs.cpp | 15 +--- .../listMsCryptoApiElectronicIDs.hpp | 2 +- tests/common/selectcard.hpp | 2 +- tests/integration/test-authenticate.cpp | 14 ++-- tests/integration/test-get-certificate.cpp | 6 +- tests/integration/test-signing.cpp | 17 ++--- tests/mock/test-autoselect-card.cpp | 8 +- tests/mock/test-get-certificate.cpp | 76 +++++++++---------- 12 files changed, 82 insertions(+), 119 deletions(-) diff --git a/include/electronic-id/electronic-id.hpp b/include/electronic-id/electronic-id.hpp index c5a6e88..006a47e 100644 --- a/include/electronic-id/electronic-id.hpp +++ b/include/electronic-id/electronic-id.hpp @@ -114,26 +114,9 @@ bool isCardSupported(const pcsc_cpp::byte_vector& atr); ElectronicID::ptr getElectronicID(const pcsc_cpp::Reader& reader); -/** Aggregates reader and electronic ID objects for communicating with and inspecting the eID card. - */ -class CardInfo -{ -public: - using ptr = std::shared_ptr; - - CardInfo(pcsc_cpp::Reader r, ElectronicID::ptr e) : _reader(std::move(r)), _eid(std::move(e)) {} - - const pcsc_cpp::Reader& reader() const { return _reader; } - const ElectronicID& eid() const { return *_eid; } - -private: - pcsc_cpp::Reader _reader; - ElectronicID::ptr _eid; -}; - -/** Automatic card selection that either returns a vector of card info pointers with available +/** Automatic card selection that either returns a vector of electronic ID pointers with available * supported cards or throws AutoSelectFailed. */ -std::vector availableSupportedCards(); +std::vector availableSupportedCards(); /** Base class for fatal errors in parameters or environment conditions that do not allow retrying. */ diff --git a/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp b/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp index 7ee3b09..377904d 100644 --- a/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp +++ b/lib/libpcsc-cpp/include/pcsc-cpp/pcsc-cpp.hpp @@ -225,7 +225,7 @@ class SmartCard { public: TransactionGuard(const CardImpl& CardImpl, bool& inProgress); - ~TransactionGuard(); + ~TransactionGuard() noexcept; PCSC_CPP_DISABLE_COPY_MOVE(TransactionGuard); private: @@ -233,9 +233,9 @@ class SmartCard bool& inProgress; }; - SmartCard(const ContextPtr& context, const string_t& readerName, byte_vector atr); + SmartCard(ContextPtr context, string_t readerName, byte_vector atr); SmartCard(); // Null object constructor. - ~SmartCard(); + ~SmartCard() noexcept; PCSC_CPP_DISABLE_COPY_MOVE(SmartCard); TransactionGuard beginTransaction(); @@ -245,9 +245,12 @@ class SmartCard Protocol protocol() const { return _protocol; } const byte_vector& atr() const { return _atr; } + const string_t& readerName() const { return _readerName; } private: + ContextPtr ctx; CardImplPtr card; + string_t _readerName; byte_vector _atr; Protocol _protocol = Protocol::UNDEFINED; bool transactionInProgress = false; diff --git a/lib/libpcsc-cpp/src/SmartCard.cpp b/lib/libpcsc-cpp/src/SmartCard.cpp index 7ac3baf..5bf327c 100644 --- a/lib/libpcsc-cpp/src/SmartCard.cpp +++ b/lib/libpcsc-cpp/src/SmartCard.cpp @@ -278,7 +278,7 @@ SmartCard::TransactionGuard::TransactionGuard(const CardImpl& card, bool& inProg inProgress = true; } -SmartCard::TransactionGuard::~TransactionGuard() +SmartCard::TransactionGuard::~TransactionGuard() noexcept { inProgress = false; try { @@ -288,15 +288,17 @@ SmartCard::TransactionGuard::~TransactionGuard() } } -SmartCard::SmartCard(const ContextPtr& contex, const string_t& readerName, byte_vector atr) : - card(std::make_unique(connectToCard(contex->handle(), readerName))), - _atr(std::move(atr)), _protocol(convertToSmartCardProtocol(card->protocol())) +SmartCard::SmartCard(ContextPtr context, string_t readerName, byte_vector atr) : + ctx(std::move(context)), + card(std::make_unique(connectToCard(ctx->handle(), readerName))), + _readerName(std::move(readerName)), _atr(std::move(atr)), + _protocol(convertToSmartCardProtocol(card->protocol())) { // TODO: debug("Card ATR -> " + bytes2hexstr(atr)) } SmartCard::SmartCard() = default; -SmartCard::~SmartCard() = default; +SmartCard::~SmartCard() noexcept = default; SmartCard::TransactionGuard SmartCard::beginTransaction() { diff --git a/src/availableSupportedCards.cpp b/src/availableSupportedCards.cpp index f8118f4..bf11dd4 100644 --- a/src/availableSupportedCards.cpp +++ b/src/availableSupportedCards.cpp @@ -26,28 +26,15 @@ #include "electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.hpp" #endif -namespace -{ - -using namespace electronic_id; - -inline CardInfo::ptr connectToCard(const pcsc_cpp::Reader& reader) -{ - auto eid = getElectronicID(reader); - return std::make_shared(reader, eid); -} - -} // namespace - namespace electronic_id { -std::vector availableSupportedCards() +std::vector availableSupportedCards() { std::vector readers; try { readers = pcsc_cpp::listReaders(); - std::vector cards; + std::vector cards; auto seenCard = false; // The list may be empty, but we cannot throw yet due to the listMsCryptoApiElectronicIDs() @@ -58,7 +45,7 @@ std::vector availableSupportedCards() } seenCard = true; if (isCardSupported(reader.cardAtr)) { - cards.push_back(connectToCard(reader)); + cards.push_back(getElectronicID(reader)); } } diff --git a/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.cpp b/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.cpp index 25d3202..0c64359 100644 --- a/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.cpp +++ b/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.cpp @@ -36,7 +36,7 @@ namespace electronic_id // Enumerates all certificates and converts the valid hardware-based ones to MsCryptoApiElectronicID // objects. -std::vector listMsCryptoApiElectronicIDs() +std::vector listMsCryptoApiElectronicIDs() { HCERTSTORE sys = CertOpenStore(CERT_STORE_PROV_SYSTEM, X509_ASN_ENCODING, 0, @@ -46,13 +46,7 @@ std::vector listMsCryptoApiElectronicIDs() } auto closeCertStore = stdext::make_scope_exit([=]() { CertCloseStore(sys, 0); }); - std::vector msCryptoApiElectronicIDs; - pcsc_cpp::Reader dummyReader { - nullptr, - L"Dummy reader for MS CryptoAPI tokens"s, - {}, - true, - }; + std::vector msCryptoApiElectronicIDs; PCCERT_CONTEXT cert = nullptr; while ((cert = CertEnumCertificatesInStore(sys, cert)) != nullptr) { @@ -121,8 +115,7 @@ std::vector listMsCryptoApiElectronicIDs() continue; // TODO: log. } algo.resize(size / 2 - 1); - // TODO: use algo.starts_with(L"EC") when migrating to C++20. - if (algo != L"RSA" && algo.rfind(L"EC", 0) != 0) { + if (algo != L"RSA" && !algo.starts_with(L"EC")) { // We only support RSA and ECC algorithms. continue; // TODO: log. } @@ -147,7 +140,7 @@ std::vector listMsCryptoApiElectronicIDs() std::move(certData), certType, algo == L"RSA", key, freeKey); - msCryptoApiElectronicIDs.push_back(std::make_shared(dummyReader, std::move(eid))); + msCryptoApiElectronicIDs.push_back(std::move(eid)); } // CertEnumCertificatesInStore() function frees the CERT_CONTEXT referenced by non-NULL values diff --git a/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.hpp b/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.hpp index 548f71d..1f1a1cb 100644 --- a/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.hpp +++ b/src/electronic-ids/ms-cryptoapi/listMsCryptoApiElectronicIDs.hpp @@ -27,6 +27,6 @@ namespace electronic_id { -std::vector listMsCryptoApiElectronicIDs(); +std::vector listMsCryptoApiElectronicIDs(); } diff --git a/tests/common/selectcard.hpp b/tests/common/selectcard.hpp index 171af07..892c753 100644 --- a/tests/common/selectcard.hpp +++ b/tests/common/selectcard.hpp @@ -4,7 +4,7 @@ #include -inline electronic_id::CardInfo::ptr autoSelectSupportedCard() { +inline electronic_id::ElectronicID::ptr autoSelectSupportedCard() { using namespace electronic_id; auto cardList = availableSupportedCards(); diff --git a/tests/integration/test-authenticate.cpp b/tests/integration/test-authenticate.cpp index 47b3ce9..88ab487 100644 --- a/tests/integration/test-authenticate.cpp +++ b/tests/integration/test-authenticate.cpp @@ -36,14 +36,14 @@ TEST(electronic_id_test, authenticate) EXPECT_TRUE(cardInfo); - std::cout << "Selected card: " << cardInfo->eid().name() << '\n'; + std::cout << "Selected card: " << cardInfo->name() << '\n'; - byte_vector cert = cardInfo->eid().getCertificate(CertificateType::AUTHENTICATION); + byte_vector cert = cardInfo->getCertificate(CertificateType::AUTHENTICATION); std::cout << "Does the reader have a PIN-pad? " - << (cardInfo->eid().smartcard().readerHasPinPad() ? "yes" : "no") << '\n'; + << (cardInfo->smartcard().readerHasPinPad() ? "yes" : "no") << '\n'; - switch (cardInfo->eid().authSignatureAlgorithm()) { + switch (cardInfo->authSignatureAlgorithm()) { case JsonWebSignatureAlgorithm::ES384: case JsonWebSignatureAlgorithm::RS256: case JsonWebSignatureAlgorithm::PS256: @@ -55,7 +55,7 @@ TEST(electronic_id_test, authenticate) "currently supported"); } - GTEST_ASSERT_GE(cardInfo->eid().authPinRetriesLeft().first, 0U); + GTEST_ASSERT_GE(cardInfo->authPinRetriesLeft().first, 0U); byte_vector pin {'1', '2', '3', '4'}; pin.reserve(64); @@ -64,9 +64,9 @@ TEST(electronic_id_test, authenticate) << std::string_view(reinterpret_cast(pin.data()), pin.size()) << '\n'; const byte_vector dataToSign {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'}; - const JsonWebSignatureAlgorithm hashAlgo = cardInfo->eid().authSignatureAlgorithm(); + const JsonWebSignatureAlgorithm hashAlgo = cardInfo->authSignatureAlgorithm(); const byte_vector hash = calculateDigest(hashAlgo.hashAlgorithm(), dataToSign); - auto signature = cardInfo->eid().signWithAuthKey(std::move(pin), hash); + auto signature = cardInfo->signWithAuthKey(std::move(pin), hash); std::cout << "Authentication signature: " << signature << '\n'; diff --git a/tests/integration/test-get-certificate.cpp b/tests/integration/test-get-certificate.cpp index 8de61a0..391b895 100644 --- a/tests/integration/test-get-certificate.cpp +++ b/tests/integration/test-get-certificate.cpp @@ -36,13 +36,13 @@ TEST(electronic_id_test, getCertificate) EXPECT_TRUE(cardInfo); - std::cout << "Selected card: " << cardInfo->eid().name() << '\n'; + std::cout << "Selected card: " << cardInfo->name() << '\n'; - auto certificate = cardInfo->eid().getCertificate(CertificateType::AUTHENTICATION); + auto certificate = cardInfo->getCertificate(CertificateType::AUTHENTICATION); std::cout << "Authentication certificate: " << certificate << '\n'; - certificate = cardInfo->eid().getCertificate(CertificateType::SIGNING); + certificate = cardInfo->getCertificate(CertificateType::SIGNING); std::cout << "Signing certificate: " << certificate << '\n'; } diff --git a/tests/integration/test-signing.cpp b/tests/integration/test-signing.cpp index 019c4d3..0b78585 100644 --- a/tests/integration/test-signing.cpp +++ b/tests/integration/test-signing.cpp @@ -37,25 +37,24 @@ static void signing(HashAlgorithm hashAlgo) EXPECT_TRUE(cardInfo); - std::cout << "Selected card: " << cardInfo->eid().name() << '\n'; + std::cout << "Selected card: " << cardInfo->name() << '\n'; - if (!cardInfo->eid().isSupportedSigningHashAlgorithm(hashAlgo)) { + if (!cardInfo->isSupportedSigningHashAlgorithm(hashAlgo)) { std::string skip = "Card does not support hashing algorithm: " + std::string(hashAlgo); GTEST_SUCCESS_(skip.c_str()); return; } - byte_vector cert = cardInfo->eid().getCertificate(CertificateType::SIGNING); + byte_vector cert = cardInfo->getCertificate(CertificateType::SIGNING); - GTEST_ASSERT_GE(cardInfo->eid().signingPinRetriesLeft().first, 0U); + GTEST_ASSERT_GE(cardInfo->signingPinRetriesLeft().first, 0U); byte_vector pin; - if (cardInfo->eid().name() == "EstEID IDEMIA v1") + if (cardInfo->name() == "EstEID IDEMIA v1") pin = {'1', '2', '3', '4', '5'}; // EstIDEMIA test card default PIN2 - else if (cardInfo->eid().name() == "LatEID IDEMIA v1" - || cardInfo->eid().name() == "LatEID IDEMIA v2") + else if (cardInfo->name() == "LatEID IDEMIA v1" || cardInfo->name() == "LatEID IDEMIA v2") pin = {'1', '2', '3', '4', '5', '6'}; // LatIDEMIA test card default PIN2 - else if (cardInfo->eid().name() == "FinEID v3" || cardInfo->eid().name() == "FinEID v4") + else if (cardInfo->name() == "FinEID v3" || cardInfo->name() == "FinEID v4") pin = {'1', '2', '3', '4', '5', '6'}; // FinEID custom PIN else throw std::runtime_error("TEST signing: Unknown card"); @@ -66,7 +65,7 @@ static void signing(HashAlgorithm hashAlgo) const byte_vector dataToSign {'H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd', '!'}; const byte_vector hash = calculateDigest(hashAlgo, dataToSign); - auto signature = cardInfo->eid().signWithSigningKey(std::move(pin), hash, hashAlgo); + auto signature = cardInfo->signWithSigningKey(std::move(pin), hash, hashAlgo); std::cout << "Signing signature: " << signature.first << '\n'; diff --git a/tests/mock/test-autoselect-card.cpp b/tests/mock/test-autoselect-card.cpp index 7e7f758..044c915 100644 --- a/tests/mock/test-autoselect-card.cpp +++ b/tests/mock/test-autoselect-card.cpp @@ -38,7 +38,7 @@ TEST(electronic_id_test, autoSelectSuccessWithSupportedCardEstIDEMIA) PcscMock::setAtr(ESTEID_IDEMIA_V1_ATR); auto result = autoSelectSupportedCard(); EXPECT_TRUE(result); - EXPECT_EQ(result->eid().name(), "EstEID IDEMIA v1"); + EXPECT_EQ(result->name(), "EstEID IDEMIA v1"); PcscMock::reset(); } @@ -47,7 +47,7 @@ TEST(electronic_id_test, autoSelectSuccessWithSupportedCardLatV2) PcscMock::setAtr(LATEID_IDEMIA_V2_ATR); auto result = autoSelectSupportedCard(); EXPECT_TRUE(result); - EXPECT_EQ(result->eid().name(), "LatEID IDEMIA v2"); + EXPECT_EQ(result->name(), "LatEID IDEMIA v2"); PcscMock::reset(); } @@ -56,7 +56,7 @@ TEST(electronic_id_test, autoSelectSuccessWithSupportedCardFinV3) PcscMock::setAtr(FINEID_V3_ATR); auto result = autoSelectSupportedCard(); EXPECT_TRUE(result); - EXPECT_EQ(result->eid().name(), "FinEID v3"); + EXPECT_EQ(result->name(), "FinEID v3"); PcscMock::reset(); } @@ -65,6 +65,6 @@ TEST(electronic_id_test, autoSelectSuccessWithSupportedCardFinV4) PcscMock::setAtr(FINEID_V4_ATR); auto result = autoSelectSupportedCard(); EXPECT_TRUE(result); - EXPECT_EQ(result->eid().name(), "FinEID v4"); + EXPECT_EQ(result->name(), "FinEID v4"); PcscMock::reset(); } diff --git a/tests/mock/test-get-certificate.cpp b/tests/mock/test-get-certificate.cpp index 33db2d0..c5fdf7a 100644 --- a/tests/mock/test-get-certificate.cpp +++ b/tests/mock/test-get-certificate.cpp @@ -40,17 +40,17 @@ TEST(electronic_id_test, selectCertificateEstIDEMIA) PcscMock::setAtr(ESTEID_IDEMIA_V1_ATR); auto cardInfo = autoSelectSupportedCard(); EXPECT_TRUE(cardInfo); - EXPECT_EQ(cardInfo->eid().name(), "EstEID IDEMIA v1"); + EXPECT_EQ(cardInfo->name(), "EstEID IDEMIA v1"); PcscMock::setApduScript(ESTEID_IDEMIA_V1_SELECT_AUTH_CERTIFICATE_AND_AUTHENTICATE); - auto certificateAuth = cardInfo->eid().getCertificate(CertificateType::AUTHENTICATION); + auto certificateAuth = cardInfo->getCertificate(CertificateType::AUTHENTICATION); EXPECT_EQ(certificateAuth.size(), 1031U); - auto authRetriesLeft = cardInfo->eid().authPinRetriesLeft(); + auto authRetriesLeft = cardInfo->authPinRetriesLeft(); EXPECT_EQ(authRetriesLeft.first, 3U); EXPECT_EQ(authRetriesLeft.second, 3); - const JsonWebSignatureAlgorithm authAlgo = cardInfo->eid().authSignatureAlgorithm(); + const JsonWebSignatureAlgorithm authAlgo = cardInfo->authSignatureAlgorithm(); EXPECT_EQ(authAlgo, JsonWebSignatureAlgorithm::ES384); const HashAlgorithm hashAlgo = authAlgo.hashAlgorithm(); @@ -58,25 +58,24 @@ TEST(electronic_id_test, selectCertificateEstIDEMIA) authPin.reserve(12); const auto hash = calculateDigest(hashAlgo, dataToSign); - const auto authSignature = cardInfo->eid().signWithAuthKey(std::move(authPin), hash); + const auto authSignature = cardInfo->signWithAuthKey(std::move(authPin), hash); if (!verify(hashAlgo, certificateAuth, dataToSign, authSignature, false)) { throw std::runtime_error("Signature is invalid"); } PcscMock::setApduScript(ESTEID_IDEMIA_V1_SELECT_SIGN_CERTIFICATE_AND_SIGNING); - auto certificateSign = cardInfo->eid().getCertificate(CertificateType::SIGNING); + auto certificateSign = cardInfo->getCertificate(CertificateType::SIGNING); EXPECT_EQ(certificateSign.size(), 1008U); - auto signingRetriesLeft = cardInfo->eid().signingPinRetriesLeft(); + auto signingRetriesLeft = cardInfo->signingPinRetriesLeft(); EXPECT_EQ(signingRetriesLeft.first, 3U); EXPECT_EQ(signingRetriesLeft.second, 3); pcsc_cpp::byte_vector signPin {'1', '2', '3', '4', '5'}; signPin.reserve(12); - EXPECT_EQ(cardInfo->eid().isSupportedSigningHashAlgorithm(hashAlgo), true); - const auto signSignature = - cardInfo->eid().signWithSigningKey(std::move(signPin), hash, hashAlgo); + EXPECT_EQ(cardInfo->isSupportedSigningHashAlgorithm(hashAlgo), true); + const auto signSignature = cardInfo->signWithSigningKey(std::move(signPin), hash, hashAlgo); EXPECT_EQ(signSignature.second, SignatureAlgorithm::ES384); if (!verify(hashAlgo, certificateSign, dataToSign, signSignature.first, false)) { throw std::runtime_error("Signature is invalid"); @@ -91,17 +90,17 @@ TEST(electronic_id_test, selectCertificateFinV3) auto cardInfo = autoSelectSupportedCard(); EXPECT_TRUE(cardInfo); - EXPECT_EQ(cardInfo->eid().name(), "FinEID v3"); + EXPECT_EQ(cardInfo->name(), "FinEID v3"); PcscMock::setApduScript(FINEID_V3_SELECT_AUTH_CERTIFICATE_AND_AUTHENTICATE); - auto certificateAuth = cardInfo->eid().getCertificate(CertificateType::AUTHENTICATION); + auto certificateAuth = cardInfo->getCertificate(CertificateType::AUTHENTICATION); EXPECT_EQ(certificateAuth.size(), 1664U); - auto authRetriesLeft = cardInfo->eid().authPinRetriesLeft(); + auto authRetriesLeft = cardInfo->authPinRetriesLeft(); EXPECT_EQ(authRetriesLeft.first, 5U); EXPECT_EQ(authRetriesLeft.second, 5); - const JsonWebSignatureAlgorithm authAlgo = cardInfo->eid().authSignatureAlgorithm(); + const JsonWebSignatureAlgorithm authAlgo = cardInfo->authSignatureAlgorithm(); EXPECT_EQ(authAlgo, JsonWebSignatureAlgorithm::PS256); const HashAlgorithm hashAlgo = authAlgo.hashAlgorithm(); @@ -109,25 +108,24 @@ TEST(electronic_id_test, selectCertificateFinV3) authPin.reserve(12); const auto hash = calculateDigest(hashAlgo, dataToSign); - const auto authSignature = cardInfo->eid().signWithAuthKey(std::move(authPin), hash); + const auto authSignature = cardInfo->signWithAuthKey(std::move(authPin), hash); if (!verify(hashAlgo, certificateAuth, dataToSign, authSignature, true)) { throw std::runtime_error("Signature is invalid"); } PcscMock::setApduScript(FINEID_V3_SELECT_SIGN_CERTIFICATE_AND_SIGNING); - auto certificateSign = cardInfo->eid().getCertificate(CertificateType::SIGNING); + auto certificateSign = cardInfo->getCertificate(CertificateType::SIGNING); EXPECT_EQ(certificateSign.size(), 1487U); - auto signingRetriesLeft = cardInfo->eid().signingPinRetriesLeft(); + auto signingRetriesLeft = cardInfo->signingPinRetriesLeft(); EXPECT_EQ(signingRetriesLeft.first, 5U); EXPECT_EQ(signingRetriesLeft.second, 5); pcsc_cpp::byte_vector signPin {'1', '2', '3', '4', '5', '6'}; signPin.reserve(12); - EXPECT_EQ(cardInfo->eid().isSupportedSigningHashAlgorithm(hashAlgo), true); - const auto signSignature = - cardInfo->eid().signWithSigningKey(std::move(signPin), hash, hashAlgo); + EXPECT_EQ(cardInfo->isSupportedSigningHashAlgorithm(hashAlgo), true); + const auto signSignature = cardInfo->signWithSigningKey(std::move(signPin), hash, hashAlgo); EXPECT_EQ(signSignature.second, SignatureAlgorithm::ES256); if (!verify(hashAlgo, certificateSign, dataToSign, signSignature.first, false)) { throw std::runtime_error("Signature is invalid"); @@ -142,17 +140,17 @@ TEST(electronic_id_test, selectCertificateFinV4) auto cardInfo = autoSelectSupportedCard(); EXPECT_TRUE(cardInfo); - EXPECT_EQ(cardInfo->eid().name(), "FinEID v4"); + EXPECT_EQ(cardInfo->name(), "FinEID v4"); PcscMock::setApduScript(FINEID_V4_SELECT_AUTH_CERTIFICATE_AND_AUTHENTICATE); - auto certificateAuth = cardInfo->eid().getCertificate(CertificateType::AUTHENTICATION); + auto certificateAuth = cardInfo->getCertificate(CertificateType::AUTHENTICATION); EXPECT_EQ(certificateAuth.size(), 1087U); - auto authRetriesLeft = cardInfo->eid().authPinRetriesLeft(); + auto authRetriesLeft = cardInfo->authPinRetriesLeft(); EXPECT_EQ(authRetriesLeft.first, 5U); EXPECT_EQ(authRetriesLeft.second, 5); - const JsonWebSignatureAlgorithm authAlgo = cardInfo->eid().authSignatureAlgorithm(); + const JsonWebSignatureAlgorithm authAlgo = cardInfo->authSignatureAlgorithm(); EXPECT_EQ(authAlgo, JsonWebSignatureAlgorithm::ES384); const HashAlgorithm hashAlgo = authAlgo.hashAlgorithm(); @@ -160,25 +158,24 @@ TEST(electronic_id_test, selectCertificateFinV4) authPin.reserve(12); const auto hash = calculateDigest(hashAlgo, dataToSign); - const auto authSignature = cardInfo->eid().signWithAuthKey(std::move(authPin), hash); + const auto authSignature = cardInfo->signWithAuthKey(std::move(authPin), hash); if (!verify(hashAlgo, certificateAuth, dataToSign, authSignature, true)) { throw std::runtime_error("Signature is invalid"); } PcscMock::setApduScript(FINEID_V4_SELECT_SIGN_CERTIFICATE_AND_SIGNING); - auto certificateSign = cardInfo->eid().getCertificate(CertificateType::SIGNING); + auto certificateSign = cardInfo->getCertificate(CertificateType::SIGNING); EXPECT_EQ(certificateSign.size(), 1144U); - auto signingRetriesLeft = cardInfo->eid().signingPinRetriesLeft(); + auto signingRetriesLeft = cardInfo->signingPinRetriesLeft(); EXPECT_EQ(signingRetriesLeft.first, 5U); EXPECT_EQ(signingRetriesLeft.second, 5); pcsc_cpp::byte_vector signPin {'1', '2', '3', '4', '5', '6'}; signPin.reserve(12); - EXPECT_EQ(cardInfo->eid().isSupportedSigningHashAlgorithm(hashAlgo), true); - const auto signSignature = - cardInfo->eid().signWithSigningKey(std::move(signPin), hash, hashAlgo); + EXPECT_EQ(cardInfo->isSupportedSigningHashAlgorithm(hashAlgo), true); + const auto signSignature = cardInfo->signWithSigningKey(std::move(signPin), hash, hashAlgo); EXPECT_EQ(signSignature.second, SignatureAlgorithm::ES384); if (!verify(hashAlgo, certificateSign, dataToSign, signSignature.first, false)) { throw std::runtime_error("Signature is invalid"); @@ -193,17 +190,17 @@ TEST(electronic_id_test, selectCertificateLatV2) auto cardInfo = autoSelectSupportedCard(); EXPECT_TRUE(cardInfo); - EXPECT_EQ(cardInfo->eid().name(), "LatEID IDEMIA v2"); + EXPECT_EQ(cardInfo->name(), "LatEID IDEMIA v2"); PcscMock::setApduScript(LATEID_IDEMIA_V2_SELECT_AUTH_CERTIFICATE_AND_AUTHENTICATE); - auto certificateAuth = cardInfo->eid().getCertificate(CertificateType::AUTHENTICATION); + auto certificateAuth = cardInfo->getCertificate(CertificateType::AUTHENTICATION); EXPECT_EQ(certificateAuth.size(), 1733U); - auto authRetriesLeft = cardInfo->eid().authPinRetriesLeft(); + auto authRetriesLeft = cardInfo->authPinRetriesLeft(); EXPECT_EQ(authRetriesLeft.first, 3U); EXPECT_EQ(authRetriesLeft.second, 3); - const JsonWebSignatureAlgorithm authAlgo = cardInfo->eid().authSignatureAlgorithm(); + const JsonWebSignatureAlgorithm authAlgo = cardInfo->authSignatureAlgorithm(); EXPECT_EQ(authAlgo, JsonWebSignatureAlgorithm::RS256); const HashAlgorithm hashAlgo = authAlgo.hashAlgorithm(); @@ -211,25 +208,24 @@ TEST(electronic_id_test, selectCertificateLatV2) authPin.reserve(12); const auto hash = calculateDigest(hashAlgo, dataToSign); - const auto authSignature = cardInfo->eid().signWithAuthKey(std::move(authPin), hash); + const auto authSignature = cardInfo->signWithAuthKey(std::move(authPin), hash); if (!verify(hashAlgo, certificateAuth, dataToSign, authSignature, false)) { throw std::runtime_error("Signature is invalid"); } PcscMock::setApduScript(LATEID_IDEMIA_V2_SELECT_SIGN_CERTIFICATE_AND_SIGNING); - auto certificateSign = cardInfo->eid().getCertificate(CertificateType::SIGNING); + auto certificateSign = cardInfo->getCertificate(CertificateType::SIGNING); EXPECT_EQ(certificateSign.size(), 2124U); - auto signingRetriesLeft = cardInfo->eid().signingPinRetriesLeft(); + auto signingRetriesLeft = cardInfo->signingPinRetriesLeft(); EXPECT_EQ(signingRetriesLeft.first, 3U); EXPECT_EQ(signingRetriesLeft.second, 3); pcsc_cpp::byte_vector signPin {'1', '2', '3', '4', '5', '6'}; signPin.reserve(12); - EXPECT_EQ(cardInfo->eid().isSupportedSigningHashAlgorithm(hashAlgo), true); - const auto signSignature = - cardInfo->eid().signWithSigningKey(std::move(signPin), hash, hashAlgo); + EXPECT_EQ(cardInfo->isSupportedSigningHashAlgorithm(hashAlgo), true); + const auto signSignature = cardInfo->signWithSigningKey(std::move(signPin), hash, hashAlgo); EXPECT_EQ(signSignature.second, SignatureAlgorithm::RS256); if (!verify(hashAlgo, certificateSign, dataToSign, signSignature.first, false)) { throw std::runtime_error("Signature is invalid");