void YubikoOtpKeyConfig::copyAndSaveToken(const yubikey_token_st& pToken) { setCounter(pToken.ctr); setUseCounter(pToken.use); getToken().tstph = pToken.tstph; getToken().tstpl = pToken.tstpl; computeCrc(); save(); }
/** * @param pPswd2check modhex encoded */ bool YubikoOtpKeyConfig::checkOtp(const std::string& pPswd2check) { BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::checkPassword"); yubikey_token_st myToken; yubikey_parse(reinterpret_cast<const uint8_t*>(pPswd2check.c_str()), this->getSecretKeyArray().data(), &myToken); BOOST_LOG_TRIVIAL(debug)<< "Key token:"; logDebug_token(getToken()); BOOST_LOG_TRIVIAL(debug)<< "Decrypted token:"; logDebug_token(myToken); if (strncmp(reinterpret_cast<const char*>(&getToken().uid), reinterpret_cast<char*>(&myToken.uid), YUBIKEY_UID_SIZE) == 0) { BOOST_LOG_TRIVIAL(debug)<< "UID is same."; uint16_t myComputedCrc = computeCrc(myToken); if(myToken.crc!=myComputedCrc) { BOOST_LOG_TRIVIAL(debug)<< "Decrypted CRC is wrong: " << myComputedCrc <<"!=" << myToken.crc; return false; } if(myToken.ctr > getToken().ctr) { BOOST_LOG_TRIVIAL(debug)<< "Decrypted counter is bigger than stored value: " << int(myToken.ctr) <<">" << int(getToken().ctr) << " reseting use counter & clock."; getToken().use= myToken.use; copyAndSaveToken(myToken); BOOST_LOG_TRIVIAL(debug)<< "OTP OK (use counter reset)!"; return true; } else { if(myToken.ctr < getToken().ctr) { BOOST_LOG_TRIVIAL(debug)<< "Decrypted counter is smaller than stored value: " << int(myToken.ctr) <<"<" << int(getToken().ctr) << " returning false."; return false; } } BOOST_LOG_TRIVIAL(debug)<< "Counter is "<< int(myToken.ctr)<<"."; if(myToken.use <= getToken().use) { BOOST_LOG_TRIVIAL(debug)<< "Decrypted use counter is wrong: " << int(myToken.use) <<"<=" << int(getToken().use); return false; } UTimestamp myTstmp; myTstmp.tstp.tstph=myToken.tstph; myTstmp.tstp.tstpl=myToken.tstpl; if(myTstmp.tstp_int<=getTimestamp().tstp_int) { BOOST_LOG_TRIVIAL(debug)<< "Decrypted timer is smaller than stored value: " << myTstmp.tstp_int <<"<=" << getTimestamp().tstp_int << " returning false."; return false; } else { BOOST_LOG_TRIVIAL(debug)<< "Decrypted timer int value: " << myTstmp.tstp_int <<"."; } copyAndSaveToken(myToken); BOOST_LOG_TRIVIAL(debug)<< "OTP OK!"; return true; } return false; }
QPUserId::QPUserId() { quint32 seed = QDateTime::currentDateTime().toTime_t(); computeCrc(seed); mCounter = (seed ^ 0x9602c9bf) ^ mCrc; }