void YubiKeyWriter::deleteConfig(int slot, const QString accCode) { bool error = false; YK_KEY *yk = NULL; YKP_CONFIG *cfg = ykp_alloc(); YubiKeyFinder::getInstance()->stop(); try { if (!(yk = yk_open_first_key())) { throw 0; } unsigned char accessCode[MAX_SIZE]; size_t accessCodeLen = 0; if(accCode.length() > 0) { int rc = encodeAccessCode(accCode, accessCode, &accessCodeLen); if (rc <= 0) { qDebug() << "Invalid access code: " << accCode; throw 0; } } // write NULL to delete config if (!yk_write_config(yk, NULL, slot, accessCodeLen > 0 ? accessCode : NULL)) { qDebug() << "Failed to delete."; throw 0; } emit configWritten(true, NULL); qDebug() << "successfully deleted slot " << slot; emit diagnostics(QString("Deleted slot %1").arg(slot)); } catch(...) { error = true; } if (cfg) { ykp_free_config(cfg); } if (yk && !yk_close_key(yk)) { error = true; } YubiKeyFinder::getInstance()->start(); if(error) { qDebug() << "Failed to delete configuration in slot" << slot; QString errMsg = reportError(); emit configWritten(false, errMsg); } }
/* Iterate through all possible access codes. * This could take a loooooooooong time. */ inline int bruteforce(unsigned char* t, int deep) { int id = 5 - deep; for(t[id]=0; t[id]<255; t[id]++) { if(deep > 0) if(bruteforce(t, deep - 1) == 0) return 0; if(!yk_write_config(yk, coreconfig, coreconfignum, t)) { print_access_code("Fail", t); } else { print_access_code("\aWin", t); return 0; } } return -1; }