Skip to content

Commit

Permalink
HaikuDepot: Some usage of the BKeyStore API
Browse files Browse the repository at this point in the history
... 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.
  • Loading branch information
stippi committed Sep 24, 2014
1 parent 84e6fa8 commit 89ec84a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
26 changes: 25 additions & 1 deletion src/apps/haikudepot/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -26,6 +27,9 @@
#define B_TRANSLATION_CONTEXT "Model"


static const char* kHaikuDepotKeyring = "HaikuDepot";


// #pragma mark - PackageFilters


Expand Down Expand Up @@ -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);
}
Expand Down
5 changes: 4 additions & 1 deletion src/apps/haikudepot/Model.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class Model {
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);
Expand Down Expand Up @@ -172,6 +174,7 @@ class Model {

thread_id fPopulateAllPackagesThread;
volatile bool fStopPopulatingAllPackages;

BString fPreferredLanguage;

WebAppInterface fWebAppInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/apps/haikudepot/UserLoginWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 89ec84a

Please sign in to comment.