Esempio n. 1
0
int main(int ac, char **av)
{
    using namespace logicalaccess;

    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = pcsc_test_init();

    PRINT_TIME("Chip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));
    PRINT_TIME("Chip type = " << chip->getCardType());

    //LLA_ASSERT(chip->getCardType() == "GENERIC_T_CL",
//               "Chip is not GENERIC_T_CL");

    LLA_ASSERT(chip->getCommands(), "No command object.");

    using namespace logicalaccess;
    auto mpu = std::dynamic_pointer_cast<MifarePlusSL0Commands>(chip->getCommands());
    assert(mpu);
    PRINT_TIME("Boap: " << mpu->detectSecurityLevel());

    pcsc_test_shutdown(readerUnit);

    return EXIT_SUCCESS;
}
int main(int ac, char **av)
{
    using namespace logicalaccess;

    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = lla_test_init();

    PRINT_TIME(
        "Chip identifier: " << BufferHelper::getHex(chip->getChipIdentifier()));

    std::shared_ptr<AccessControlCardService> acs =
        std::dynamic_pointer_cast<AccessControlCardService>(
            chip->getService(CST_ACCESS_CONTROL));

    std::array<uint8_t, 64> buffer = {0};

    auto ret = acs->readFormat(std::make_shared<Wiegand26Format>(),
                               std::make_shared<ProxLocation>(), nullptr);
    ret->getLinearData(&buffer[0], buffer.size());

    std::cout << "Format: " << std::vector<uint8_t>(buffer.begin(), buffer.end())
              << std::endl;

    pcsc_test_shutdown(readerUnit);
    return 0;
}
int main(int ac, char **av)
{
    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = pcsc_test_init();

    PRINT_TIME("Chip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));
    PRINT_TIME("Chip type = " << chip->getCardType());

    auto mfp_sl1_cmd = std::dynamic_pointer_cast<MifarePlusSL1Commands>(chip->getCommands());
    LLA_ASSERT(mfp_sl1_cmd, "No (or invalid) command object.");

    std::shared_ptr<AES128Key> aes_key = std::make_shared<AES128Key>();
	//aes_key->fromString("ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff");
    aes_key->fromString("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00");

   // LLA_ASSERT(mfp_sl1_cmd->AESAuthenticateSL1(aes_key), "AES Authentication failed");
    aes_key->fromString("00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F");

    //LLA_ASSERT(mfp_sl1_cmd->switchLevel2(aes_key), "Failed to switch to level 2");
	LLA_ASSERT(mfp_sl1_cmd->switchLevel3(aes_key), "Failed to switch to level 3");
    LLA_SUBTEST_PASSED("AES_Auth");

    pcsc_test_shutdown(readerUnit);
    return EXIT_SUCCESS;
}
Esempio n. 4
0
void Drawer::drawMap( ) {
	PlayPtr play = Play::getTask( );
	ChipPtr chip = play->getChipPtr( );
	for ( int i = 0; i < Map::MAP_MAX; i++ ) {
		chip->drawChip( i, -3 );
	}
	for ( int i = 0; i < Map::MAP_MAX; i++ ) {
		if ( chip->getChip( i ).status != STATUS::STATUS_NONE ) {
			chip->drawChip( i, 3 );
		}
	}
}
Esempio n. 5
0
int main(int ac, char **av)
{
    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = lla_test_init();

    PRINT_TIME("CHip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));

    LLA_ASSERT(chip->getCardType() == "ISO15693",
               "Chip is not a ISO15693, but is " + chip->getCardType() + " instead.");

    auto cmd = std::dynamic_pointer_cast<ISO15693Commands>(chip->getCommands());
    LLA_ASSERT(cmd, "Cannot retrieve correct command object");


    auto sysinfo = cmd->getSystemInformation();
    // Our unittest card is supposed to have the blocksize/nbblock available.
    // However, this doesn't work with OK5427 and doesn't work with OK5321 on Linux.
    if (pcsc_reader_unit_name(readerUnit) == "OKXX21" && get_os_name() == "Win")
    {
        LLA_ASSERT(sysinfo.hasVICCMemorySize, "Doesn't have VICCMemorySize information");
        LLA_ASSERT(sysinfo.blockSize == 4, "Unexpected block size");
        LLA_ASSERT(sysinfo.nbBlocks == 40, "Unexpected block number");
        LLA_SUBTEST_PASSED("SystemInformation");
    }

    if ((get_os_name() == "Win" && pcsc_reader_unit_name(readerUnit) == "OKXX21") ||
        pcsc_reader_unit_name(readerUnit) == "OKXX27")
    {
        write_read_test(readerUnit, cmd);
    }

    pcsc_test_shutdown(readerUnit);

    return EXIT_SUCCESS;
}
Esempio n. 6
0
int main(int ac, char **av)
{
    using namespace logicalaccess;
    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = init();

    PRINT_TIME("CHip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));

    LLA_ASSERT(chip->getCardType() == "MifareUltralightC",
               "Chip is not an MifareUltralight(C), but is " + chip->getCardType() + " instead.");
    auto cmd = std::dynamic_pointer_cast<logicalaccess::MifareUltralightCommands>(
            chip->getCommands());
    LLA_ASSERT(cmd, "Cannot get command from chip");

    auto cmdUltraC = std::dynamic_pointer_cast<logicalaccess::MifareUltralightCCommands>(
            chip->getCommands());
    LLA_ASSERT(cmdUltraC, "Cannot cast command to MifareUltralightCCommands");
    auto profile = std::dynamic_pointer_cast<logicalaccess::MifareUltralightCProfile>(
            chip->getProfile());

    LLA_ASSERT(profile, "Cannot fetch profile from chip");
    //std::shared_ptr<logicalaccess::TripleDESKey> key(new logicalaccess::TripleDESKey("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"));
    std::shared_ptr<logicalaccess::TripleDESKey> key;
    cmdUltraC->authenticate(key);
    LLA_SUBTEST_PASSED("Authenticate");

    std::vector<unsigned char> data(4), tmp;
    data[0] = 0x11;
    data[3] = 0xff;
    cmd->writePage(10, data);
    LLA_SUBTEST_PASSED("WritePage");

    tmp = cmd->readPage(10);
    LLA_SUBTEST_PASSED("ReadPage");


    LLA_ASSERT(std::equal(data.begin(), data.end(), tmp.begin()),
               "read and write data are different!");
    LLA_SUBTEST_PASSED("WriteRead");


    pcsc_test_shutdown(readerUnit);

    return EXIT_SUCCESS;
}
int main(int ac, char **av)
{
    using namespace logicalaccess;

    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = lla_test_init();

    PRINT_TIME("Chip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));

   // LLA_ASSERT(chip->getCardType() == "Mifare1K",
//               "Chip is not a Mifare1K, but is " + chip->getCardType() +
//               " instead.");

    auto storage = std::dynamic_pointer_cast<logicalaccess::StorageCardService>(
            chip->getService(logicalaccess::CST_STORAGE));

    std::shared_ptr<logicalaccess::Location> location;
    std::shared_ptr<logicalaccess::AccessInfo> aiToUse;
    std::shared_ptr<logicalaccess::AccessInfo> aiToWrite;

    // We want to write data on sector 1.
    std::shared_ptr<logicalaccess::MifareLocation> mlocation(
            new logicalaccess::MifareLocation());
    mlocation->sector = 4;
    mlocation->block = 0;
    location = mlocation;

    // Key to use for sector authentication
    std::shared_ptr<logicalaccess::MifareAccessInfo> maiToUse(
            new logicalaccess::MifareAccessInfo());
    maiToUse->keyA->fromString("00 00 00 00 00 00");      // Default key
    maiToUse->keyB->fromString("00 00 00 00 00 00");
    maiToUse->sab.setAReadBWriteConfiguration();
    aiToUse = maiToUse;

    // Change the sector key with the following key
    std::shared_ptr<logicalaccess::MifareAccessInfo> maiToWrite(
            new logicalaccess::MifareAccessInfo());
    maiToWrite->keyA->fromString("00 00 00 00 00 00");
    maiToWrite->keyB->fromString("00 00 00 00 00 00");
    maiToWrite->sab.setAReadBWriteConfiguration(); // Configure the sector access bits
    aiToWrite = maiToWrite;

    // Data to write
    std::vector<uint8_t> writedata(16, 'e');

    // Data read
    std::vector<uint8_t> readdata;

    // Write data on the specified location with the specified key
    storage->writeData(location, aiToUse, aiToWrite, writedata, logicalaccess::CB_DEFAULT);
    using namespace logicalaccess; // required for overload of std::ostrean(vector &)
    PRINT_TIME("Wrote: " << writedata);
    LLA_SUBTEST_PASSED("WriteService")


    const int mifare_block_size = 16;
    // We read the data on the same location. Remember, the key is now changed.
    readdata = storage
            ->readData(location, aiToWrite, mifare_block_size, logicalaccess::CB_DEFAULT);
    PRINT_TIME("Read: " << readdata);
    LLA_SUBTEST_PASSED("ReadService")

    LLA_ASSERT(std::equal(writedata.begin(), writedata.end(), readdata.begin()),
               "Data read is not what we wrote.");
    LLA_SUBTEST_PASSED("CorrectWriteRead");

    pcsc_test_shutdown(readerUnit);
    return 0;
}
int main(int ac, char **av)
{
    prologue(ac, av);
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = lla_test_init("EPass");

    PRINT_TIME("Chip identifier: " <<
                   logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));

    LLA_ASSERT(chip->getCardType() == "EPass",
               "Chip is not a EPass, but is " + chip->getCardType() + " instead.");

    auto srv = std::dynamic_pointer_cast<IdentityCardService>(chip->getService(CST_IDENTITY));
    LLA_ASSERT(srv, "Cannot retrieve identity service from the chip");
    // Prepare the service.
    auto ai = std::make_shared<EPassAccessInfo>();
    ai->mrz_ = "W7GCH9ZY24UTO7904107F2006187<<<<<<<<<<<<<<<2";
    srv->setAccessInfo(ai);


    std::string name;
    LLA_ASSERT(srv->get(IdentityCardService::MetaData::NAME, name), "Failed to fetch name");
    LLA_ASSERT("ANDERSON  JANE" == name, "Name doesn't match.");
    LLA_SUBTEST_PASSED("GetName");

    ByteVector picture_data;
    LLA_ASSERT(srv->get(IdentityCardService::MetaData::PICTURE, picture_data), "Failed to"
        "get picture bytes");

    // We check the hash of the picture rather than the full picture bytes. Easier for tests.
    LLA_ASSERT(openssl::SHA1Hash(picture_data) == BufferHelper::fromHexString("9cb474bfb578a9c8defa8eb6fe9ea2cd643be308"),
               "Retrieved image picture doesn't match expected picture.");
    LLA_SUBTEST_PASSED("GetPicture");

    std::string nationality;
    LLA_ASSERT(srv->get(IdentityCardService::MetaData::NATIONALITY, nationality),
               "Failed to fetch nationality");
    LLA_ASSERT("UTO" == nationality, "Nationality doesn't match.");
    LLA_SUBTEST_PASSED("GetNationality");


    std::string docno;
    LLA_ASSERT(srv->get(IdentityCardService::MetaData::DOC_NO, docno),
               "Failed to fetch document number.");
    LLA_ASSERT(docno == "W7GCH9ZY2", "Document number doesn't match.");
    LLA_SUBTEST_PASSED("GetDocNo");


    std::chrono::system_clock::time_point tp;
    LLA_ASSERT(srv->get(IdentityCardService::MetaData::BIRTHDATE, tp), "Failed to "
        "fetch birthdate");
    std::time_t tp_t = std::chrono::system_clock::to_time_t(tp);
    std::tm tm = *std::localtime(&tp_t);

    char buff[512];
    std::strftime(buff, sizeof(buff), "%c", &tm);
    PRINT_TIME("Birthdate: " << buff);

    pcsc_test_shutdown(readerUnit);

    return EXIT_SUCCESS;
}
Esempio n. 9
0
int main(int, char **)
{
    introduction();
    ReaderProviderPtr provider;
    ReaderUnitPtr readerUnit;
    ChipPtr chip;
    std::tie(provider, readerUnit, chip) = pcsc_test_init();

    PRINT_TIME("CHip identifier: " <<
               logicalaccess::BufferHelper::getHex(chip->getChipIdentifier()));

    LLA_ASSERT(chip->getCardType() == "DESFireEV1",
               "Chip is not an DESFireEV1, but is " + chip->getCardType() +
               " instead.");

    auto location_root_node = chip->getRootLocationNode();

    auto cmd = std::dynamic_pointer_cast<logicalaccess::DESFireISO7816Commands>(
            chip->getCommands());
    auto cmdev1 = std::dynamic_pointer_cast<logicalaccess::DESFireEV1ISO7816Commands>(
            chip->getCommands());
    LLA_ASSERT(cmd && cmdev1, "Cannot get correct command object from chip.");

    cmd->selectApplication(0x00);
    cmd->authenticate(0);

    cmd->erase();
    cmdev1->createApplication(0x521, logicalaccess::DESFireKeySettings::KS_DEFAULT, 3,
                              logicalaccess::DESFireKeyType::DF_KEY_AES,
                              logicalaccess::FIDS_NO_ISO_FID, 0, std::vector<unsigned char>());

    cmd->selectApplication(0x521);
    std::shared_ptr<logicalaccess::DESFireKey> key(new logicalaccess::DESFireKey());
    key->setKeyType(logicalaccess::DESFireKeyType::DF_KEY_AES);
    cmd->authenticate(0, key);
    LLA_SUBTEST_PASSED("Authenticate");

    logicalaccess::DESFireAccessRights ar;
    ar.readAccess = logicalaccess::TaskAccessRights::AR_KEY2;
    ar.writeAccess = logicalaccess::TaskAccessRights::AR_KEY1;
    ar.readAndWriteAccess = logicalaccess::TaskAccessRights::AR_KEY1;
    ar.changeAccess = logicalaccess::TaskAccessRights::AR_KEY1;
    cmdev1->createStdDataFile(0x00, logicalaccess::EncryptionMode::CM_ENCRYPT, ar, 4, 0);


    cmd->authenticate(1, key);
    std::vector<unsigned char> data = {0x01, 0x02, 0x03, 0x04}, tmp;
    cmdev1->writeData(0, 0, data, logicalaccess::EncryptionMode::CM_ENCRYPT);

    cmd->authenticate(2, key);
    tmp = cmdev1->readData(0, 0, 4, logicalaccess::EncryptionMode::CM_ENCRYPT);
    LLA_ASSERT(std::equal(data.begin(), data.end(), tmp.begin()),
               "read and write data are different!");
    LLA_SUBTEST_PASSED("WriteRead");

    cmd->authenticate(0x00, key);
    cmd->deleteFile(0x00);

    cmd->authenticate(0x00, key);
    std::shared_ptr<logicalaccess::DESFireKey> newkey(
            new logicalaccess::DESFireKey("00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03"));
    cmd->changeKey(0x00, newkey);
    LLA_SUBTEST_PASSED("ChangeKey");

    cmd->selectApplication(0x00);
    cmd->authenticate(0);
    cmd->deleteApplication(0x521);

    auto service = std::dynamic_pointer_cast<logicalaccess::AccessControlCardService>(
            chip->getService(logicalaccess::CardServiceType::CST_ACCESS_CONTROL));
    LLA_ASSERT(service, "Cannot retrieve access control service from chip.");

    auto location = std::make_shared<logicalaccess::DESFireLocation>();
    location->aid = 0x522;
    location->file = 0;
    auto ai = std::make_shared<logicalaccess::DESFireAccessInfo>();
    auto format = std::make_shared<logicalaccess::Wiegand26Format>();
    format->setUid(1000);
    format->setFacilityCode(67);

    service->writeFormat(format, location, ai, ai);
    auto formattmp = std::make_shared<logicalaccess::Wiegand26Format>();
    auto rformat = std::dynamic_pointer_cast<logicalaccess::Wiegand26Format>(
            service->readFormat(formattmp, location, ai));

    if (!rformat || rformat->getUid() != 1000 || rformat->getFacilityCode() != 67)
    THROW_EXCEPTION_WITH_LOG(std::runtime_error, "Bad format");
    LLA_SUBTEST_PASSED("ReadFormat");

    pcsc_test_shutdown(readerUnit);

    return EXIT_SUCCESS;
}