#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() #include "catch.hpp" #include #include #include #include "device_proto.h" #include "log.h" //#include "stick10_commands.h" #include "stick20_commands.h" using namespace std; using namespace nitrokey::device; using namespace nitrokey::proto; using namespace nitrokey::proto::stick20; using namespace nitrokey::log; using namespace nitrokey::misc; template void execute_password_command(Device &stick, const char *password, const char kind = 'P') { auto p = get_payload(); if (kind == 'P'){ p.set_kind_user(); } else { p.set_kind_admin(); } strcpyT(p.password, password); CMDTYPE::CommandTransaction::run(stick, p); this_thread::sleep_for(1000ms); } TEST_CASE("test", "[test]") { Stick20 stick; bool connected = stick.connect(); REQUIRE(connected == true); Log::instance().set_loglevel(Loglevel::DEBUG_L2); stick10::LockDevice::CommandTransaction::run(stick); // execute_password_command(stick, "123456"); // execute_password_command(stick, "123456"); this_thread::sleep_for(1000ms); execute_password_command(stick, "123456"); this_thread::sleep_for(4000ms); bool passed = false; for(int i=0; i<5; i++){ try { execute_password_command(stick, "123123123"); CHECK(true); passed=true; break; } catch (CommandFailedException &e){ this_thread::sleep_for(2000ms); } } if(!passed){ CHECK(false); } execute_password_command(stick, "123123123"); execute_password_command(stick, "123456"); execute_password_command(stick, "123456"); execute_password_command(stick, "12345678", 'A'); stick20::GetDeviceStatus::CommandTransaction::run(stick); this_thread::sleep_for(1000ms); // execute_password_command(stick, "123123123"); //CAUTION // execute_password_command(stick, "123123123"); //CAUTION FIRMWARE PIN execute_password_command(stick, "12345678", 'A'); // execute_password_command(stick, "12345678", 'A'); stick10::LockDevice::CommandTransaction::run(stick); }