@@ -1333,16 +1333,8 @@ wxSecretString MyFrameMain::bookmarks_load_one(int index) {
13331333 /*
13341334 Read values from secretstore
13351335 */
1336- wxSecretValue password;
1337- #if wxUSE_SECRETSTORE
1338- wxSecretStore store = wxSecretStore::GetDefault ();
1339- if (store.IsOk ()) {
1340- wxString username; // this will not be used
1341- store.Load (" MultiVNC/Bookmarks/" + (user.IsEmpty () ? " " : user + " @" ) + host + " :" + port,
1342- username,
1343- password); // if Load() fails, password will still be empty
1344- }
1345- #endif
1336+ wxSecretValue password, sshPassword, sshPrivKeyPassword;
1337+ bookmarks_secrets_load (str, password, sshPassword, sshPrivKeyPassword);
13461338
13471339 wxSecretString uri (" vnc://" );
13481340 uri += (host + " :" + port);
@@ -1351,7 +1343,9 @@ wxSecretString MyFrameMain::bookmarks_load_one(int index) {
13511343 uri += (" &SshHost=" + ssh_host);
13521344 uri += (" &SshPort=" + ssh_port);
13531345 uri += (" &SshUsername=" + ssh_user);
1346+ uri += (" &SshPassword=" + sshPassword.GetAsString ());
13541347 uri += (" &SshPrivKeyFilename=" + ssh_priv_key_filename);
1348+ uri += (" &SshPrivKeyPassword=" + sshPrivKeyPassword.GetAsString ());
13551349
13561350 return uri;
13571351}
@@ -1913,13 +1907,7 @@ void MyFrameMain::bookmarks_add(wxCommandEvent &event)
19131907 cfg->Write (K_BOOKMARKS_SSH_USER, c->getSshUserName ());
19141908 cfg->Write ( K_BOOKMARKS_SSH_PRIV_KEY_FILENAME, c->getSshPrivKeyFilename ());
19151909
1916- #if wxUSE_SECRETSTORE
1917- wxSecretStore store = wxSecretStore::GetDefault ();
1918- if (store.IsOk () && c->getPassword ().IsOk ()) { // check if destination and source are ok
1919- if (!store.Save (" MultiVNC/Bookmarks/" + wxString (c->getUserName ().IsEmpty () ? " " : c->getUserName () + " @" ) + c->getServerHost () + " :" + c->getServerPort (), c->getUserName (), c->getPassword ()))
1920- wxLogWarning (_ (" Failed to save credentials to the system secret store." ));
1921- }
1922- #endif
1910+ bookmarks_secrets_save (name, c->getPassword (), c->getSshPassword (), c->getSshPrivKeyPassword ());
19231911
19241912 // reset path
19251913 cfg->SetPath (wxT (" /" ));
@@ -1949,11 +1937,17 @@ void MyFrameMain::bookmarks_edit(wxCommandEvent &event)
19491937
19501938 wxConfigBase *cfg = wxConfigBase::Get ();
19511939
1940+ wxSecretValue password, sshPassword, sshPrivKeyPassword;
1941+ bookmarks_secrets_load (sel, password, sshPassword, sshPrivKeyPassword);
1942+ bookmarks_secrets_delete (sel);
1943+
19521944 cfg->SetPath (G_BOOKMARKS);
19531945 cfg->RenameGroup (sel, newname);
19541946 // reset path
19551947 cfg->SetPath (wxT (" /" ));
1956-
1948+
1949+ bookmarks_secrets_save (newname, password, sshPassword, sshPrivKeyPassword);
1950+
19571951 // and load into listbox
19581952 bookmarks_load_to_list ();
19591953}
@@ -1970,18 +1964,7 @@ void MyFrameMain::bookmarks_delete(wxCommandEvent &event)
19701964 return ;
19711965 }
19721966
1973- #if wxUSE_SECRETSTORE
1974- int sel = list_box_bookmarks->GetSelection ();
1975- if (sel != wxNOT_FOUND) {
1976- wxURI uri (bookmarks_load_one (sel));
1977- wxString host = uri.GetServer ();
1978- wxString port = uri.GetPort ();
1979- wxString user = getQueryValue (uri, " VncUsername" ); // RFC 7869
1980- wxSecretStore store = wxSecretStore::GetDefault ();
1981- if (store.IsOk ())
1982- store.Delete (" MultiVNC/Bookmarks/" + (user.IsEmpty () ? " " : user + " @" ) + host + " :" + port);
1983- }
1984- #endif
1967+ bookmarks_secrets_delete (name);
19851968
19861969 wxConfigBase *cfg = wxConfigBase::Get ();
19871970 if (!cfg->DeleteGroup (G_BOOKMARKS + name))
@@ -1992,7 +1975,112 @@ void MyFrameMain::bookmarks_delete(wxCommandEvent &event)
19921975}
19931976
19941977
1978+ void MyFrameMain::bookmarks_secrets_save (const wxString& bookmarkName,
1979+ const wxSecretValue& password,
1980+ const wxSecretValue& sshPassword,
1981+ const wxSecretValue& sshPrivKeyPassword) {
1982+ #if wxUSE_SECRETSTORE
1983+ wxSecretStore store = wxSecretStore::GetDefault ();
1984+ if (store.IsOk ()) {
1985+ if (password.IsOk ()) {
1986+ if (!store.Save (" MultiVNC/Bookmarks/" + bookmarkName + " VncPassword" , wxEmptyString, password)) {
1987+ wxLogWarning (_ (" Failed to save credentials to the system secret store." ));
1988+ }
1989+ }
1990+
1991+ if (sshPassword.IsOk ()) {
1992+ if (!store.Save (" MultiVNC/Bookmarks/" + bookmarkName + " SshPassword" , wxEmptyString, sshPassword)) {
1993+ wxLogWarning (_ (" Failed to save credentials to the system secret store." ));
1994+ }
1995+ }
1996+
1997+ if (sshPrivKeyPassword.IsOk ()) {
1998+ if (!store.Save (" MultiVNC/Bookmarks/" + bookmarkName + " SshPrivKeyPassword" , wxEmptyString, sshPrivKeyPassword)) {
1999+ wxLogWarning (_ (" Failed to save credentials to the system secret store." ));
2000+ }
2001+ }
2002+ }
2003+ #endif
2004+ }
2005+
19952006
2007+ void MyFrameMain::bookmarks_secrets_load (const wxString& bookmarkName,
2008+ wxSecretValue& password,
2009+ wxSecretValue& sshPassword,
2010+ wxSecretValue& sshPrivKeyPassword) {
2011+ /*
2012+ Read stuff for pre-0.11 versions TODO remove with 0.12
2013+ */
2014+ wxConfigBase *cfg = wxConfigBase::Get ();
2015+ wxString host, port, user;
2016+ cfg->SetPath (G_BOOKMARKS + bookmarkName);
2017+ if (!cfg->Read (K_BOOKMARKS_HOST, &host)) {
2018+ wxLogError (_ (" Error reading hostname of bookmark '%s'!" ), bookmarkName);
2019+ cfg->SetPath (" /" );
2020+ return ;
2021+ }
2022+ if (!cfg->Read (K_BOOKMARKS_PORT, &port)) {
2023+ wxLogError (_ (" Error reading port of bookmark '%s'!" ), bookmarkName);
2024+ cfg->SetPath (" /" );
2025+ return ;
2026+ }
2027+ // user is optional
2028+ cfg->Read (K_BOOKMARKS_USER, &user);
2029+ // done reading cfg
2030+ cfg->SetPath (" /" );
2031+
2032+ #if wxUSE_SECRETSTORE
2033+ wxSecretStore store = wxSecretStore::GetDefault ();
2034+ if (store.IsOk ()) {
2035+ wxString username; // this will not be used
2036+ store.Load (" MultiVNC/Bookmarks/" + bookmarkName + " VncPassword" , username, password);
2037+ store.Load (" MultiVNC/Bookmarks/" + bookmarkName + " SshPassword" , username, sshPassword);
2038+ store.Load (" MultiVNC/Bookmarks/" + bookmarkName + " SshPrivKeyPassword" , username, sshPrivKeyPassword);
2039+
2040+ // still load saves from pre-0.11 versions TODO remove with 0.12
2041+ if (!password.IsOk ()) {
2042+ store.Load (" MultiVNC/Bookmarks/" + (user.IsEmpty () ? " " : user + " @" ) + host + " :" + port,
2043+ username,
2044+ password); // if Load() fails, password will still be empty
2045+ }
2046+ }
2047+ #endif
2048+
2049+ }
2050+
2051+ void MyFrameMain::bookmarks_secrets_delete (const wxString& bookmarkName) {
2052+ /*
2053+ Read stuff for pre-0.11 versions TODO remove with 0.12
2054+ */
2055+ wxConfigBase *cfg = wxConfigBase::Get ();
2056+ wxString host, port, user;
2057+ cfg->SetPath (G_BOOKMARKS + bookmarkName);
2058+ if (!cfg->Read (K_BOOKMARKS_HOST, &host)) {
2059+ wxLogError (_ (" Error reading hostname of bookmark '%s'!" ), bookmarkName);
2060+ cfg->SetPath (" /" );
2061+ return ;
2062+ }
2063+ if (!cfg->Read (K_BOOKMARKS_PORT, &port)) {
2064+ wxLogError (_ (" Error reading port of bookmark '%s'!" ), bookmarkName);
2065+ cfg->SetPath (" /" );
2066+ return ;
2067+ }
2068+ // user is optional
2069+ cfg->Read (K_BOOKMARKS_USER, &user);
2070+ // done reading cfg
2071+ cfg->SetPath (" /" );
2072+
2073+ #if wxUSE_SECRETSTORE
2074+ wxSecretStore store = wxSecretStore::GetDefault ();
2075+ if (store.IsOk ()) {
2076+ store.Delete (" MultiVNC/Bookmarks/" + bookmarkName + " VncPassword" );
2077+ store.Delete (" MultiVNC/Bookmarks/" + bookmarkName + " SshPassword" );
2078+ store.Delete (" MultiVNC/Bookmarks/" + bookmarkName + " SshPrivKeyPassword" );
2079+ // still delete saves from pre-0.11 versions TODO remove with 0.12
2080+ store.Delete (" MultiVNC/Bookmarks/" + (user.IsEmpty () ? " " : user + " @" ) + host + " :" + port);
2081+ }
2082+ #endif
2083+ }
19962084
19972085
19982086void MyFrameMain::help_about (wxCommandEvent &event)
0 commit comments