Ejemplo 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;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
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;
}
Ejemplo n.º 5
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;
}