mirror of
https://github.com/levinsv/pgadmin3.git
synced 2026-08-15 14:22:36 -06:00
Storing passwords in an encrypted vault.
Добавлена возможность сохранения паролей в зашифронном хранилище пользователя ОС. Для Linux это возможно если wxwidgets скомпилирован с библиотекой libsecret . Для выбора стратегии хранения паролей нужно создать параметр GetStoreTypePass со одним из значений 0,1,2. Где: 0 - стандартный способ (pgpass) 1 - pgpass + зашифрованное хранилище. 2 - зашифрованное хранилище. По умолчанию используется 0. При выборе 1 или 2 файл pgpass используется для копирования паролей в зашифрованное хранилище при подлючении к БД пароль к которой ещё не сохранён в хранилище, но есть в pgpass. Никакой экспорта/импорта нет.
This commit is contained in:
parent
9c65209d9c
commit
d1b657c455
2 changed files with 86 additions and 12 deletions
|
|
@ -847,6 +847,18 @@ public:
|
|||
Read(wxT("CompareDialogParam"), &i, 0);
|
||||
return i;
|
||||
}
|
||||
/*
|
||||
0 - pgpass
|
||||
1 - pgpass + secret
|
||||
2 - secret
|
||||
*/
|
||||
int GetStoreTypePass() const
|
||||
{
|
||||
int i;
|
||||
Read(wxT("GetStoreTypePass"), &i, 0);
|
||||
if ((i>2) || (i<0)) i=0;
|
||||
return i;
|
||||
}
|
||||
void SetCompareDialogParam(const int newval)
|
||||
{
|
||||
WriteInt(wxT("CompareDialogParam"), newval);
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#include <wx/dir.h>
|
||||
#include <wx/fileconf.h>
|
||||
#include <wx/wfstream.h>
|
||||
#include <wx/secretstore.h>
|
||||
|
||||
// App headers
|
||||
#include "ctl/ctlMenuToolbar.h"
|
||||
|
|
@ -570,7 +571,38 @@ wxString pgServer::passwordFilename()
|
|||
bool pgServer::GetPasswordIsStored()
|
||||
{
|
||||
wxString fname = passwordFilename();
|
||||
wxString seekStr = GetName() + wxT(":")
|
||||
+ NumToStr((long)GetPort()) + wxT(":*:")
|
||||
+ username + wxT(":") ;
|
||||
|
||||
wxString seekStr2 = wxString(GetName().mb_str(wxConvUTF8), wxConvLibc) + wxT(":")
|
||||
+ NumToStr((long)GetPort()) + wxT(":*:")
|
||||
+ wxString(username.mb_str(wxConvUTF8), wxConvLibc) + wxT(":") ;
|
||||
bool issecret=false;
|
||||
int type = settings->GetStoreTypePass();
|
||||
#ifdef wxUSE_SECRETSTORE
|
||||
if (type>0) {
|
||||
wxSecretStore store = wxSecretStore::GetDefault();
|
||||
wxString errmsg;
|
||||
if ( store.IsOk(&errmsg) )
|
||||
{
|
||||
wxString username2;
|
||||
wxSecretValue password2;
|
||||
issecret=true;
|
||||
if (type>0 && store.Load("pgadmin3/"+seekStr, username2, password2) ) {
|
||||
// store password in pgServer object
|
||||
password=password2.GetAsString();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (type>0)
|
||||
wxLogWarning("This system doesn't support storing passwords securely "
|
||||
"(%s).", errmsg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!wxFile::Exists(fname))
|
||||
return false;
|
||||
|
|
@ -584,22 +616,29 @@ bool pgServer::GetPasswordIsStored()
|
|||
|
||||
wxStringTokenizer lines(before, wxT("\n\r"));
|
||||
|
||||
wxString seekStr = GetName() + wxT(":")
|
||||
+ NumToStr((long)GetPort()) + wxT(":*:")
|
||||
+ username + wxT(":") ;
|
||||
|
||||
wxString seekStr2 = wxString(GetName().mb_str(wxConvUTF8), wxConvLibc) + wxT(":")
|
||||
+ NumToStr((long)GetPort()) + wxT(":*:")
|
||||
+ wxString(username.mb_str(wxConvUTF8), wxConvLibc) + wxT(":") ;
|
||||
|
||||
int seeklen=0;
|
||||
while (lines.HasMoreTokens())
|
||||
{
|
||||
wxString str = lines.GetNextToken();
|
||||
if (str.Left(seekStr.Length()) == seekStr)
|
||||
seeklen=seekStr.Length();
|
||||
else
|
||||
if (str.Left(seekStr2.Length()) == seekStr2)
|
||||
seeklen=seekStr2.Length();
|
||||
if (seeklen>0) {
|
||||
#ifdef wxUSE_SECRETSTORE
|
||||
if (type>0) {
|
||||
wxSecretStore store = wxSecretStore::GetDefault();
|
||||
if ( store.IsOk() )
|
||||
{
|
||||
wxSecretValue secret(str.substr(seeklen));
|
||||
if (issecret && !store.Save("pgadmin3/"+seekStr, username, secret) )
|
||||
wxLogWarning("Failed to save credentials to the system secret store.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
|
||||
if (str.Left(seekStr2.Length()) == seekStr2)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -609,8 +648,31 @@ bool pgServer::GetPasswordIsStored()
|
|||
|
||||
void pgServer::StorePassword()
|
||||
{
|
||||
wxString seekStr = GetName() + wxT(":")
|
||||
+ NumToStr((long)GetPort()) + wxT(":*:")
|
||||
+ username + wxT(":") ;
|
||||
bool issecret=false;
|
||||
int type = settings->GetStoreTypePass();
|
||||
#ifdef wxUSE_SECRETSTORE
|
||||
if (type>0) {
|
||||
wxSecretStore store = wxSecretStore::GetDefault();
|
||||
wxString errmsg;
|
||||
if ( store.IsOk(&errmsg) )
|
||||
{
|
||||
issecret=true;
|
||||
wxSecretValue secret(password);
|
||||
if (issecret && !store.Save("pgadmin3/"+seekStr, username, secret) )
|
||||
wxLogWarning("Failed to save credentials to the system secret store.");
|
||||
}
|
||||
else
|
||||
{
|
||||
wxLogWarning("This system doesn't support storing passwords securely "
|
||||
"(%s).", errmsg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (type==2) return;
|
||||
wxString fname = passwordFilename();
|
||||
|
||||
if (!wxFile::Exists(fname))
|
||||
{
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue