HaikuDepot: Some usage of the BKeyStore API

... completely untested and premature. The idea is that after a successful
login with the web-app, the password used is stored in the keyring. Then
HaikuDepot will restore just last the used username on next launch and retrieve
the password from the keyring. One could also register multiple accounts in
HaikuDepot and switch between them.
This commit is contained in:
Stephan Aßmus
2014-09-24 21:26:46 +02:00
parent 84e6fa8e2a
commit 89ec84a4cb
3 changed files with 31 additions and 4 deletions
+25 -1
View File
@@ -17,6 +17,7 @@
#include <Entry.h>
#include <FindDirectory.h>
#include <File.h>
#include <KeyStore.h>
#include <LocaleRoster.h>
#include <Message.h>
#include <Path.h>
@@ -26,6 +27,9 @@
#define B_TRANSLATION_CONTEXT "Model"
static const char* kHaikuDepotKeyring = "HaikuDepot";
// #pragma mark - PackageFilters
@@ -639,8 +643,28 @@ Model::StopPopulatingAllPackages()
void
Model::SetAuthorization(const BString& username, const BString& password)
Model::SetUser(const BString& username)
{
BPasswordKey key;
BKeyStore keyStore;
if (keyStore.GetKey(kHaikuDepotKeyring, B_KEY_TYPE_PASSWORD, username,
key) == B_OK) {
SetAuthorization(username, key.Password(), false);
}
}
void
Model::SetAuthorization(const BString& username, const BString& password,
bool storePassword)
{
if (storePassword) {
BPasswordKey key(password, B_KEY_PURPOSE_WEB, username);
BKeyStore keyStore;
keyStore.AddKeyring(kHaikuDepotKeyring);
keyStore.AddKey(kHaikuDepotKeyring, key);
}
BAutolock locker(&fLock);
fWebAppInterface.SetAuthorization(username, password);
}
+4 -1
View File
@@ -107,8 +107,10 @@ public:
const BString& PreferredLanguage() const
{ return fPreferredLanguage; }
void SetUser(const BString& username);
void SetAuthorization(const BString& username,
const BString& password);
const BString& password,
bool storePassword);
private:
static int32 _PopulateAllPackagesEntry(void* cookie);
@@ -172,6 +174,7 @@ private:
thread_id fPopulateAllPackagesThread;
volatile bool fStopPopulatingAllPackages;
BString fPreferredLanguage;
WebAppInterface fWebAppInterface;
+2 -2
View File
@@ -346,7 +346,7 @@ UserLoginWindow::_AuthenticateThread()
// the Token Bearer. See section 5.1.2 in the haiku-depot-web
// documentation.
error = "";
fModel.SetAuthorization(nickName, passwordClear);
fModel.SetAuthorization(nickName, passwordClear, true);
} else {
error = B_TRANSLATE("Authentication failed. The user does "
"not exist or the wrong password was supplied.");
@@ -508,7 +508,7 @@ UserLoginWindow::_CreateAccountThread()
fCaptchaToken = "";
_RequestCaptcha();
} else {
fModel.SetAuthorization(nickName, passwordClear);
fModel.SetAuthorization(nickName, passwordClear, true);
_SetWorkerThread(-1);
BMessenger(this).SendMessage(B_QUIT_REQUESTED);