Пример #1
0
// static
bool OTKeyring::Gnome_StoreSecret(const OTString& strUser,
                                  const OTPassword& thePassword,
                                  const std::string& str_display)
{
    OT_ASSERT(strUser.Exists());
    OT_ASSERT(thePassword.getMemorySize() > 0);

    OTData theData(thePassword.getMemory(), thePassword.getMemorySize());
    OTASCIIArmor ascData(theData);
    theData.zeroMemory(); // security reasons.

    OTString strOutput;
    const bool bSuccess =
        ascData.Exists() &&
        ascData.WriteArmoredString(strOutput, "DERIVED KEY"); // There's no
                                                              // default, to
                                                              // force you to
                                                              // enter the right
                                                              // string.
    ascData.zeroMemory();

    GnomeKeyringResult theResult = GNOME_KEYRING_RESULT_IO_ERROR;

    if (bSuccess && strOutput.Exists()) {
        theResult = gnome_keyring_store_password_sync(
            GNOME_KEYRING_NETWORK_PASSWORD,
            GNOME_KEYRING_DEFAULT, // GNOME_KEYRING_SESSION,
            str_display.c_str(), strOutput.Get(), "user", strUser.Get(),
            "protocol", "opentxs", // todo: hardcoding.
            nullptr);
        strOutput.zeroMemory();

        bool bResult = false;

        if (theResult == GNOME_KEYRING_RESULT_OK)
            bResult = true;
        else
            otErr << "OTKeyring::Gnome_StoreSecret: "
                  << "Failure in gnome_keyring_store_password_sync: "
                  << gnome_keyring_result_to_message(theResult) << '\n';

        return bResult;
    }

    otOut << "OTKeyring::Gnome_StoreSecret: No secret to store.\n";

    return false;
}
Пример #2
0
// static
bool OTKeyring::KWallet_StoreSecret(const OTString& strUser,
                                    const OTPassword& thePassword,
                                    const std::string& str_display)
{
    OT_ASSERT(strUser.Exists());
    OT_ASSERT(thePassword.getMemorySize() > 0);

    KWallet::Wallet* pWallet = OTKeyring::OpenKWallet();

    if (nullptr != pWallet) {
        const QString qstrKey(strUser.Get());

        OTData theData(thePassword.getMemory(), thePassword.getMemorySize());
        OTASCIIArmor ascData(theData);
        theData.zeroMemory(); // security reasons.

        OTString strOutput;
        const bool bSuccess =
            ascData.Exists() &&
            ascData.WriteArmoredString(
                strOutput, "DERIVED KEY"); // There's no default, to force you
                                           // to enter the right string.
        ascData.zeroMemory();

        // Set the password
        //
        bool bReturnVal = false;

        if (bSuccess && strOutput.Exists() &&
            pWallet->writePassword(qstrKey,
                                   QString::fromUtf8(strOutput.Get())) == 0)
            bReturnVal = true;
        else
            otErr << "OTKeyring::KWallet_StoreSecret: Failed trying to store "
                     "secret into KWallet.\n";

        strOutput.zeroMemory();

        return bReturnVal;
    }

    otErr << "OTKeyring::KWallet_StoreSecret: Unable to open kwallet.\n";

    return false;
}