/** * Here we use server sync url without protocol prefix and * user account name as the key in the keyring. * * Also since the KWallet's API supports only storing (key,password) * or Map<QString,QString> , the former is used. */ bool KWalletLoadPasswordSlot(const InitStateTri &keyring, const std::string &passwordName, const std::string &descr, const ConfigPasswordKey &key, InitStateString &password) { if (!UseKWallet(keyring, GetLoadPasswordSignal().num_slots() - INTERNAL_LOAD_PASSWORD_SLOTS)) { return false; } QString walletPassword; QString walletKey = QString(key.user.c_str()) + ',' + QString(key.domain.c_str())+ ','+ QString(key.server.c_str())+','+ QString(key.object.c_str())+','+ QString(key.protocol.c_str())+','+ QString(key.authtype.c_str())+','+ QString::number(key.port); QString wallet_name = KWallet::Wallet::NetworkWallet(); //QString folder = QString::fromUtf8("Syncevolution"); const QLatin1String folder("Syncevolution"); if (!KWallet::Wallet::keyDoesNotExist(wallet_name, folder, walletKey)) { KWallet::Wallet *wallet = KWallet::Wallet::openWallet(wallet_name, -1, KWallet::Wallet::Synchronous); if (wallet && wallet->setFolder(folder) && wallet->readPassword(walletKey, walletPassword) == 0) { password = walletPassword.toStdString(); } } return true; }
QVector<SieveEditorUtil::SieveServerConfig> SieveEditorUtil::readServerSieveConfig() { QVector<SieveServerConfig> lstConfig; KSharedConfigPtr cfg = KSharedConfig::openConfig(); QRegularExpression re(QStringLiteral("^ServerSieve (.+)$")); const QStringList groups = cfg->groupList().filter(re); KWallet::Wallet *wallet = SieveServerSettings::self()->wallet(); if (wallet && !wallet->setFolder(QStringLiteral("sieveeditor"))) { wallet->createFolder(QStringLiteral("sieveeditor")); wallet->setFolder(QStringLiteral("sieveeditor")); } Q_FOREACH (const QString &conf, groups) { SieveServerConfig sieve; KConfigGroup group = cfg->group(conf); sieve.port = group.readEntry(QStringLiteral("Port"), 0); sieve.serverName = group.readEntry(QStringLiteral("ServerName")); sieve.userName = group.readEntry(QStringLiteral("UserName")); sieve.enabled = group.readEntry(QStringLiteral("Enabled"), true); const QString walletEntry = sieve.userName + QLatin1Char('@') + sieve.serverName; if (wallet && wallet->hasEntry(walletEntry)) { wallet->readPassword(walletEntry, sieve.password); } sieve.authenticationType = static_cast<MailTransport::Transport::EnumAuthenticationType::type>(group.readEntry(QStringLiteral("Authentication"), static_cast<int>(MailTransport::Transport::EnumAuthenticationType::PLAIN))); lstConfig.append(sieve); }
// static bool OTKeyring::KWallet_RetrieveSecret(const OTString& strUser, OTPassword& thePassword, const std::string& str_display) { OT_ASSERT(strUser.Exists()); KWallet::Wallet* pWallet = OTKeyring::OpenKWallet(); if (nullptr != pWallet) { const QString qstrKey(strUser.Get()); QString qstrPwd; // Get the password // if (pWallet->readPassword(qstrKey, qstrPwd) == 0) { const std::string str_password = qstrPwd.toStdString(); // todo security: notice str_password // isn't zero'd here. OTString strData(str_password); OTASCIIArmor ascData; const bool bLoaded = strData.Exists() && ascData.LoadFromString(strData); strData.zeroMemory(); if (!bLoaded) otErr << __FUNCTION__ << ": Failed trying to decode secret " "from KWallet contents.\n"; else { OTData thePayload(ascData); ascData.zeroMemory(); if (thePayload.IsEmpty()) otErr << __FUNCTION__ << ": Failed trying to decode secret " "OTData from OTASCIIArmor from " "KWallet contents.\n"; else { thePassword.setMemory(thePayload.GetPayloadPointer(), thePayload.GetSize()); thePayload.zeroMemory(); // for security. return true; } } } else otErr << __FUNCITON__ << ": Failed trying to retrieve secret from KWallet.\n"; } // Not an error: what if it just hasn't been set there yet? // otWarn << "OTKeyring::KWallet_RetrieveSecret: No secret found.\n"; return false; }
void EncryptedStore::findPasswordInKWallet() { Q_D(KOdfStore); /* About KWallet access * * The choice has been made to postfix every entry in a kwallet concerning passwords for opendocument files with /opendocument * This choice has been made since, at the time of this writing, the author could not find any reference to standardized * naming schemes for entries in the wallet. Since collision of passwords in entries should be avoided and is at least possible, * considering remote files might be both protected by a secured web-area (konqueror makes an entry) and a password (we make an * entry), it seems a good thing to make sure it won't happen. */ if (!m_filename.isNull() && !KWallet::Wallet::folderDoesNotExist(KWallet::Wallet::LocalWallet(), KWallet::Wallet::PasswordFolder()) && !KWallet::Wallet::keyDoesNotExist(KWallet::Wallet::LocalWallet(), KWallet::Wallet::PasswordFolder(), m_filename + "/opendocument")) { KWallet::Wallet *wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), d->window ? d->window->winId() : 0); if (wallet) { if (wallet->setFolder(KWallet::Wallet::PasswordFolder())) { QString pass; wallet->readPassword(m_filename + "/opendocument", pass); m_password = QCA::SecureArray(pass.toUtf8()); } delete wallet; } } }
/* Implementation of svn_auth__password_get_t that retrieves the password from KWallet. */ static svn_error_t * kwallet_password_get(svn_boolean_t *done, const char **password, apr_hash_t *creds, const char *realmstring, const char *username, apr_hash_t *parameters, svn_boolean_t non_interactive, apr_pool_t *pool) { QString wallet_name = get_wallet_name(parameters); *done = FALSE; if (! dbus_bus_get(DBUS_BUS_SESSION, NULL)) { return SVN_NO_ERROR; } if (non_interactive) { if (!KWallet::Wallet::isOpen(wallet_name)) return SVN_NO_ERROR; /* There is a race here: the wallet was open just now, but will it still be open when we come to use it below? */ } QCoreApplication *app; if (! qApp) { int argc = q_argc; app = new QCoreApplication(argc, q_argv); } KCmdLineArgs::init(q_argc, q_argv, get_application_name(parameters, pool), "subversion", ki18n(get_application_name(parameters, pool)), SVN_VER_NUMBER, ki18n("Version control system"), KCmdLineArgs::CmdLineArgKDE); KComponentData component_data(KCmdLineArgs::aboutData()); QString folder = QString::fromUtf8("Subversion"); QString key = QString::fromUtf8(username) + "@" + QString::fromUtf8(realmstring); if (! KWallet::Wallet::keyDoesNotExist(wallet_name, folder, key)) { KWallet::Wallet *wallet = get_wallet(wallet_name, parameters); if (wallet) { if (wallet->setFolder(folder)) { QString q_password; if (wallet->readPassword(key, q_password) == 0) { *password = apr_pstrmemdup(pool, q_password.toUtf8().data(), q_password.size()); *done = TRUE; } } } } return SVN_NO_ERROR; }