void YubiKeyWriter::writeConfig(YubiKeyConfig *ykConfig) { YubiKeyFinder::getInstance()->stop(); YK_KEY *yk = 0; YK_STATUS *ykst = YubiKeyFinder::getInstance()->status(); YKP_CONFIG *cfg = ykp_alloc(); bool error = false; qDebug() << "-------------------------"; qDebug() << "Starting write config"; qDebug() << "-------------------------"; try { if (!(yk = yk_open_first_key())) { throw 0; } else if (!yk_get_status(yk, ykst)) { throw 0; } ykp_configure_version(cfg, ykst); qDebug() << "writer:configuration slot:" << ykConfig->configSlot(); bool useAccessCode; unsigned char accessCode[MAX_SIZE]; if(!assembleConfig(ykConfig, cfg, &useAccessCode, accessCode)) { throw 0; } //Log configuration... qDebug() << "-------------------------"; qDebug() << "Config data to be written to key configuration..."; char conf_buf[1024]; ykp_export_config(cfg, conf_buf, 1024, YKP_FORMAT_LEGACY); qDebug() << conf_buf; qDebug() << "-------------------------"; // Write configuration... if (!yk_write_command(yk, ykp_core_config(cfg), ykp_command(cfg), useAccessCode ? accessCode : NULL)) { qDebug() << "Failure"; throw 0; } qDebug() << "Success... config written"; emit diagnostics(QString("Successfully wrote config to slot %1").arg(ykp_config_num(cfg))); YubiKeyLogger::logConfig(ykConfig); emit configWritten(true, NULL); } catch(...) { error = true; } if (cfg) { ykp_free_config(cfg); } if (yk && !yk_close_key(yk)) { error = true; } YubiKeyFinder::getInstance()->start(); if(error) { qDebug() << "Config not written"; QString errMsg = reportError(); emit configWritten(false, errMsg); } qDebug() << "-------------------------"; qDebug() << "Stopping write config"; qDebug() << "-------------------------"; }
int main(int argc, char** argv) { char showmessage = 1; if((argc == 2) && (strcmp(argv[1], "-y") == 0)) showmessage = 0; if(showmessage == 1) { puts("--------------------------------------------"); puts("Hi! You're going to crack the access code of"); puts("a Yubikey. As soon as the appropriate code "); puts("is found, the AES key will be set to zeros."); puts("Brute forcing the code can take a very long "); puts("time, and with long I mean like more than a "); puts("year."); puts("(By the way you can bypass this message by "); puts("passing the -y option to the program.) "); puts("--------------------------------------------"); puts("Type \"start\" to continue."); char acknowledge[256]; fgets(acknowledge, 256, stdin); if(strcmp(acknowledge, "start\n") != 0) { puts("Quitting."); return EXIT_SUCCESS; } } yk = 0; unsigned char access_code[6]; const char* aeshash="00000000000000000000000000000000"; YKP_CONFIG *cfg = ykp_create_config(); YK_STATUS *st = ykds_alloc(); if(!yk_init()) { fputs("Failed to init Yubikey.\n", stderr); return EXIT_FAILURE; } if(!(yk = yk_open_first_key())) { fputs("No Yubikey found.\n", stderr); return EXIT_FAILURE; } if(!yk_get_status(yk,st)) { fputs("Failed to get status of the Yubikey.\n", stderr); return EXIT_FAILURE; } printf("Found Yubikey. Version: %d.%d.%d Touch level: %d\n", ykds_version_major(st), ykds_version_minor(st), ykds_version_build(st), ykds_touch_level(st)); if(!ykp_configure_for(cfg, 1, st)) { printf("Can't set configuration to 1.\n"); return EXIT_FAILURE; } if(ykp_AES_key_from_hex(cfg, aeshash)) { fputs("Bad AES key. WTF did you do to my source?", stderr); return EXIT_FAILURE; } coreconfig = ykp_core_config(cfg); coreconfignum = ykp_config_num(cfg); bruteforce(access_code, 5); if(st) free(st); if(!yk_close_key(yk)) { fputs("Can't close Yubikey! What the hell are you doing over there?", stderr); return EXIT_FAILURE; } if(!yk_release()) { fputs("Can't release Yubikey.", stderr); return EXIT_FAILURE; } if(cfg) ykp_free_config(cfg); return EXIT_SUCCESS; }