Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omnikey 5427 - get card tag in human readable form? #161

Closed
xvoidee opened this issue Oct 14, 2018 · 5 comments
Closed

Omnikey 5427 - get card tag in human readable form? #161

xvoidee opened this issue Oct 14, 2018 · 5 comments

Comments

@xvoidee
Copy link

xvoidee commented Oct 14, 2018

Hello,

I'm using HID Omnikey 5427 under Ubuntu 14.04.5 amd64.
Everything is fine except that I am not able to get card ID (it is 6 digits written on the card - 658399).
Card class is HID iCLASS Seos Px H8Y.

This is my sandbox code (modified examples). Which part of API should I use in order to get this ID value?
When I run code I always see that card serial number is changing:
Card Serial Number : 08E8D0A1
Card Serial Number : 08DDEA85
Card Serial Number : 08FFFFFF

Card ATR is
3B 80 80 01 01

Any info is welcome. Thanks!

@xvoidee
Copy link
Author

xvoidee commented Oct 14, 2018

#include "logicalaccess/dynlibrary/idynlibrary.hpp"
#include "logicalaccess/dynlibrary/librarymanager.hpp"
#include "logicalaccess/readerproviders/readerconfiguration.hpp"
#include "logicalaccess/services/storage/storagecardservice.hpp"
#include "logicalaccess/services/accesscontrol/accesscontrolcardservice.hpp"
#include "logicalaccess/services/accesscontrol/formats/wiegand26format.hpp"
#include "logicalaccess/services/nfctag/nfctagcardservice.hpp"
#include "logicalaccess/cards/locationnode.hpp"

#include <pcsc/readers/omnikey5427readerunitconfiguration.hpp>
#include <pcsc/readers/omnikeyxx22readerunit.hpp>
#include <pcsc/readers/omnikeyxx23readerunit.hpp>
#include <pcsc/readers/omnikeyxx25readerunit.hpp>
#include <pcsc/readers/acsacrreaderunit.hpp>

#include
#include
#include
#include
#include <stdlib.h>

int main(int , char**)
{
try
{
std::vectorstd::string readerList = logicalaccess::LibraryManager::getInstance()->getAvailableReaders();
std::cout << "Available reader plug-ins ("<< readerList.size() <<"):" << std::endl;
for (std::vectorstd::string::iterator it = readerList.begin(); it != readerList.end(); ++it)
{
std::cout << "\t" << (*it) << std::endl;
}

    std::vector<std::string> cardList = logicalaccess::LibraryManager::getInstance()->getAvailableCards();
    std::cout << "Available card plug-ins ("<< cardList.size() <<"):" << std::endl;
    for (std::vector<std::string>::iterator it = cardList.begin(); it != cardList.end(); ++it)
    {
        std::cout << "\t" << (*it) << std::endl;
    }

    // Reader configuration object to store reader provider and reader unit selection.
    std::shared_ptr<logicalaccess::ReaderConfiguration> readerConfig(new logicalaccess::ReaderConfiguration());

    // PC/SC
    std::string rpstr = "PCSC";
    std::cout << "Please type the reader plug-in to use:" << std::endl;
    //std::cin >> rpstr;

    readerConfig->setReaderProvider(logicalaccess::LibraryManager::getInstance()->getReaderProvider(rpstr));

    if (readerConfig->getReaderProvider()->getRPType() == "PCSC" && readerConfig->getReaderProvider()->getReaderList().size() == 0)
    {
        std::cerr << "No readers on this system." << std::endl;
        return EXIT_FAILURE;
    }
    std::cout << readerConfig->getReaderProvider()->getReaderList().size() << " readers on this system." << std::endl;

    // List available reader units
    int ruindex = 0;
    const logicalaccess::ReaderList readers = readerConfig->getReaderProvider()->getReaderList();
    std::cout << "Please select index of the reader unit to use:" << std::endl;
    for (int i = 0; i < readers.size(); ++i)
    {
        std::cout << "\t" << i << ". " << readers.at(i)->getName() << std::endl;
    }
    //std::cin >> ruindex;

    if (ruindex < 0 || ruindex >= readers.size())
    {
        std::cerr << "Selected reader unit outside range." << std::endl;
        return EXIT_FAILURE;
    }

    readerConfig->setReaderUnit(readers.at(ruindex));
    std::cout << "Waiting 15 seconds for a card insertion..." << std::endl;

    while (1)
    {
        readerConfig->getReaderUnit()->connectToReader();

        bool fail = false;

        auto unit = std::dynamic_pointer_cast<logicalaccess::PCSCReaderUnit>(readerConfig->getReaderUnit());
        if(!unit) {
            std::cerr << "Not ReaderUnit" << std::endl;
            fail = true;
        }
        
        auto config = std::dynamic_pointer_cast<logicalaccess::Omnikey5427ReaderUnitConfiguration>(unit->getPCSCConfiguration());
        if(!config) {
            std::cerr << "Not a 5427 conf\n";
            fail = true;
        }

        if(fail) {
            std::cout << "EPIC FAIL!!!\n";
            //return EXIT_FAILURE;
        }

        //auto c = r->getOmnikeyXX21Configuration();
        //c->setUseSecureMode(false);

        // Force card type here if you want to
        //readerConfig->getReaderUnit()->setCardType(CT_DESFIRE_EV1);

        std::cout << "Time start : " << time(NULL) << std::endl;
        if (readerConfig->getReaderUnit()->waitInsertion(15000))
        {
            
            if (readerConfig->getReaderUnit()->connect())
            {
                std::cout << "Card inserted on reader \"" << readerConfig->getReaderUnit()->getConnectedName() << "\"." << std::endl;

                std::shared_ptr<logicalaccess::Chip> chip = readerConfig->getReaderUnit()->getSingleChip();
                std::cout << "Card type          : " << chip->getCardType() << std::endl;
                std::cout << "Card generic type  : " << chip->getGenericCardType() << std::endl;

                std::vector<unsigned char> csn = readerConfig->getReaderUnit()->getNumber(chip);
                std::cout << "Card Serial Number : " << logicalaccess::BufferHelper::getHex(csn) << std::endl;
                std::cout << "Card reader SN     : " << readerConfig->getReaderUnit()->getReaderSerialNumber() << std::endl;
                std::cout << "Card Buffers       : "
                    << logicalaccess::BufferHelper::getStdString(csn)
                    << std::endl;
                std::cout << "Unit type          : " << unit->getPCSCType() << std::endl;

                std::shared_ptr<logicalaccess::LocationNode> node = chip->getRootLocationNode();
                if (node)
                {
                    std::cout << "Root Location Node : " << node->getName() << std::endl;
                    std::cout << "Auth need          : " << node->getNeedAuthentication() << std::endl;
                    std::cout << "Node length        : " << node->getLength() << std::endl;
                    std::cout << "Node childrens     : " << node->getChildrens().size() << std::endl;
                    std::cout << "Node properties    : " << node->getHasProperties() << std::endl;
                    
                    auto location = node->getLocation();
                    if(location) {
                        std::cout << "location get\n";
                        //auto storage = std::dynamic_pointer_cast<logicalaccess::StorageCardService>(chip->getService(logicalaccess::CST_STORAGE));
                        std::shared_ptr<logicalaccess::AccessInfo> aiToUse;
                        std::shared_ptr<logicalaccess::Wiegand26Format> format(new logicalaccess::Wiegand26Format());
                        auto acService = std::dynamic_pointer_cast<logicalaccess::AccessControlCardService>(chip->getService(logicalaccess::CST_ACCESS_CONTROL));
                        auto f = acService->readFormat(format, location, aiToUse);
                        auto id = f->getIdentifier();
                        std::cout << logicalaccess::BufferHelper::getHex(id) << std::endl;
                    } else {
                        std::cout << "Location not get\n";
                    }
                }

                std::cout << "Complete chip list:" << std::endl;
                std::vector<std::shared_ptr<logicalaccess::Chip>> chipList = readerConfig->getReaderUnit()->getChipList();
                for(std::vector<std::shared_ptr<logicalaccess::Chip>>::iterator i = chipList.begin(); i != chipList.end(); ++i)
                {
                    std::cout << "\t" << logicalaccess::BufferHelper::getHex(readerConfig->getReaderUnit()->getNumber((*i))) << std::endl;
                }

                // DO SOMETHING HERE
				// DO SOMETHING HERE
				// DO SOMETHING HERE

                readerConfig->getReaderUnit()->disconnect();
            }
            else
            {
                std::cout << "Error: cannot connect to the card." << std::endl;
            }

            std::cout << "Logical automatic card removal in 15 seconds..." << std::endl;

            if (!readerConfig->getReaderUnit()->waitRemoval(15000))
            {
                std::cerr << "Card removal forced." << std::endl;
            }

            std::cout << "Card removed." << std::endl;
        } else
        {
            std::cout << "No card inserted." << std::endl;
        }
    }
}
catch (std::exception& ex)
{
    std::cout << "Exception: " << ex.what() << std::endl;
}

return EXIT_SUCCESS;

}

@Liryna
Copy link
Contributor

Liryna commented Oct 15, 2018

Hi @xvoidee ,

This card is currently not supported in the public repository unfortunately for NDA reason.

@xvoidee
Copy link
Author

xvoidee commented Oct 15, 2018

Thank you @Liryna,

How can we use private repository? It is mentioned in wiki, that iclass cards are available on private repo. Is it paid service?

@Liryna
Copy link
Contributor

Liryna commented Oct 23, 2018

Hi @xvoidee ,

Yes, it is a paid service that we can only start to propose for companies regarding the needs. If that’s the case, could you send a mail to [email protected] and describe your usage.

@Liryna
Copy link
Contributor

Liryna commented May 17, 2019

Closing for inactivity.

@Liryna Liryna closed this as completed May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants