void YubikoOtpKeyConfig::setSecretKey(const std::string& pKey) {
	BOOST_LOG_NAMED_SCOPE(
			"YubikoOtpKeyConfig::setSecretKey( const std::string& pKey)");
	string mySecretKey(pKey);
	trim(mySecretKey);
	if (mySecretKey.size() != K_SEC_KEY_SZ) {
		throw WrongConfigValue(WrongConfigValue::EYbkSecretKey, K_SEC_KEY_SZ,
				mySecretKey);
	}
	if (getSecretKey() != pKey) {
		yubikey_hex_decode(reinterpret_cast<char*>(itsKey.data()),
				mySecretKey.c_str(),
				YUBIKEY_KEY_SIZE);
		itsChangedFlag = true;
	}
}
/**
 * Save the key data in a JSON like format. The filename is specified in
 * constructor YubikoOtpKeyConfig::YubikoOtpKeyConfig(const string& )
 */
void YubikoOtpKeyConfig::save() {
	BOOST_LOG_NAMED_SCOPE("YubikoOtpKeyConfig::save");
	const string myOutFile = checkFileName(true);
	ptree myTree;
	myTree.put(K_NM_DOC_PRIV_ID /*--->*/, getPrivateId());
	myTree.put(K_NM_DOC_PUB_ID /*---->*/, getPublicId());
	myTree.put(K_NM_DOC_SEC_KEY /*--->*/, getSecretKey());
	myTree.put(K_NM_DOC_TIMESTAMP /*->*/, getTimestamp().tstp_int);
	myTree.put(K_NM_DOC_SES_CNTR /*-->*/, getCounter());
	myTree.put(K_NM_DOC_CRC /*------->*/, getCrc());
	myTree.put(K_NM_DOC_RANDOM /*---->*/, getRandom());
	myTree.put(K_NM_DOC_USE_CNTR /*-->*/, getUseCounter());
	myTree.put(K_NM_DOC_DESC /*------>*/, getDescription());
	myTree.put(K_NM_DOC_SYS_USER /*-->*/, getSysUser());
	myTree.put(K_NM_DOC_VERS /*------>*/, K_VL_VERS);
	write_json(myOutFile, myTree);
	itsChangedFlag = false;
}
Esempio n. 3
0
bool extractPrivateKey(ThreadParams *params) {
    PFC *pfc = params->pfc;
    clock_t begin_time, begin_time1;
    float enc_time, enc_time1, dec_time, dec_time1, dec_time2, ext_time;

    G2 P;
    G2 Ppub;
    G1 Qpriv, Qid;
    G1 D;

    Big order = pfc->order();

    // Specify the ids of the dkgs to contact
    //int dkgIds[THRESHOLD] = {1, 2, 3};
    //int dkgIds2[THRESHOLD] = {3, 4, 5};
    int dkgIds[THRESHOLD];
    for(int i = 0; i < THRESHOLD; i++) {
        dkgIds[i] = i+1;
    }
    //TODO: Change this to an id from the scramble extension

    /*
    ifstream infile("test.txt");
    string readoutId;
    if (infile.good())
    {
        getline(infile, readoutId);
        cout << "The read out ID is:" << endl << readoutId << endl;
    }
    infile.close();*/

    const char * id = "-3114599686203605494";
    //const char * id = readoutId.c_str();
    string urls[THRESHOLD];
    for (int i = 0; i < THRESHOLD; i++) {
        stringstream ss;
        ss << DKG_BASE_ADDR << dkgIds[i] << "/";
        urls[i] = ss.str();
    }
    vector <G1> Qprivs;
    vector <G2> Ppubs;
    DkgResult retParams;

    begin_time = clock();
    // Before doing the check, concatenate the expiration date
    string idString = "";
    idString = idString + id;
    idString = mapToDate(idString);
    (*pfc).hash_and_map(Qid, (char*)idString.c_str());

    for (int i = 0; i < THRESHOLD; i++) {
        retParams = scrapeDkg(urls[i], (char*)id);
        // Get Ppub, P and Qpriv from the PKG's XML message
        P = retParams.P;

        Qpriv = retParams.Qpriv;
        Qprivs.push_back(Qpriv);

        Ppub = retParams.Ppub;
        Ppubs.push_back(Ppub);

        // Verify if the DKG are being honest
        GT QprivP = (*pfc).pairing(P, Qpriv);
        GT QidPpub = (*pfc).pairing(Ppub, Qid);
        if (QprivP != QidPpub) {
            cout << "Server " << dkgIds[i] << " is dishonest. Select another DKG to continue the extraction process." << endl;
            return false;
        }
    }

    D = getSecretKey(dkgIds, Qprivs, order, pfc);
    Ppub = getPpub(dkgIds, Ppubs, order, pfc);

    ext_time = getExecutionTime(begin_time);
    cout << "Extraction time was " << ext_time << endl << endl;
    params->P = P;
    params->Ppub = Ppub;
    params->D = D;
    return true;
}