mirror of
https://github.com/moparisthebest/keepass2android
synced 2024-11-11 20:15:04 -05:00
Fixes in PasswordActivity:
* correctly set keyfile when reloading * show toast in main thread Allow importing keyfile to internal folder
This commit is contained in:
parent
13ab33081d
commit
9279a3ae92
@ -326,5 +326,14 @@ namespace KeePassLib.Keys
|
||||
|
||||
sOut.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows to change the ioc value (without reloading the data, assuming it's the same content)
|
||||
/// </summary>
|
||||
/// <param name="newIoc"></param>
|
||||
public void ResetIoc(IOConnectionInfo newIoc)
|
||||
{
|
||||
m_ioc = newIoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -234,6 +234,18 @@ namespace keepass2android
|
||||
break;
|
||||
case KeePass.ExitLock:
|
||||
// The database has already been locked, and the quick unlock screen will be shown if appropriate
|
||||
|
||||
_rememberKeyfile = _prefs.GetBoolean(GetString(Resource.String.keyfile_key), Resources.GetBoolean(Resource.Boolean.keyfile_default)); //update value
|
||||
if ((KeyProviderType == KeyProviders.KeyFile) && (_rememberKeyfile))
|
||||
{
|
||||
//check if the keyfile was changed (by importing to internal directory)
|
||||
var newKeyFile = GetKeyFile(_ioConnection.Path);
|
||||
if (newKeyFile != _keyFileOrProvider)
|
||||
{
|
||||
_keyFileOrProvider = newKeyFile;
|
||||
UpdateKeyfileIocView();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case KeePass.ExitCloseAfterTaskComplete:
|
||||
// Do not lock the database
|
||||
@ -261,9 +273,8 @@ namespace keepass2android
|
||||
{
|
||||
|
||||
KcpKeyFile kcpKeyfile = (KcpKeyFile)App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof(KcpKeyFile));
|
||||
|
||||
FindViewById<TextView>(Resource.Id.label_keyfilename).Text =
|
||||
App.Kp2a.GetFileStorage(kcpKeyfile.Ioc).GetDisplayName(kcpKeyfile.Ioc);
|
||||
_keyFileOrProvider = IOConnectionInfo.SerializeToString(kcpKeyfile.Ioc);
|
||||
UpdateKeyfileIocView();
|
||||
|
||||
}
|
||||
}
|
||||
@ -929,7 +940,11 @@ namespace keepass2android
|
||||
true, () =>
|
||||
{
|
||||
CompositeKey compositeKey;
|
||||
if (!CreateCompositeKey(out compositeKey)) return (() => { });
|
||||
string errorMessage;
|
||||
if (!CreateCompositeKey(out compositeKey, out errorMessage)) return (() =>
|
||||
{
|
||||
Toast.MakeText(this, errorMessage, ToastLength.Long).Show();
|
||||
});
|
||||
return () => { PerformLoadDatabaseWithCompositeKey(compositeKey); };
|
||||
}).Execute();
|
||||
|
||||
@ -959,8 +974,9 @@ namespace keepass2android
|
||||
new ProgressTask(App.Kp2a, this, task).Run();
|
||||
}
|
||||
|
||||
private bool CreateCompositeKey(out CompositeKey compositeKey)
|
||||
private bool CreateCompositeKey(out CompositeKey compositeKey, out string errorMessage)
|
||||
{
|
||||
errorMessage = null;
|
||||
//no need to check for validity of password because if this method is called, the Ok button was enabled (i.e. there was a valid password)
|
||||
compositeKey = new CompositeKey();
|
||||
compositeKey.AddUserKey(new KcpPassword(_password));
|
||||
@ -980,13 +996,13 @@ namespace keepass2android
|
||||
catch (System.IO.FileNotFoundException e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
Toast.MakeText(this, App.Kp2a.GetResourceString(UiStringKey.keyfile_does_not_exist), ToastLength.Long).Show();
|
||||
errorMessage = App.Kp2a.GetResourceString(UiStringKey.keyfile_does_not_exist);
|
||||
return false;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
Toast.MakeText(this, e.Message, ToastLength.Long).Show();
|
||||
errorMessage = e.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -1001,7 +1017,7 @@ namespace keepass2android
|
||||
catch (Exception e)
|
||||
{
|
||||
Kp2aLog.Log(e.ToString());
|
||||
Toast.MakeText(this, GetString(Resource.String.OtpKeyError), ToastLength.Long).Show();
|
||||
errorMessage = GetString(Resource.String.OtpKeyError);
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1019,7 +1035,7 @@ namespace keepass2android
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.MakeText(this, Resource.String.CouldntParseOtpSecret, ToastLength.Long).Show();
|
||||
errorMessage = GetString(Resource.String.CouldntParseOtpSecret);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
1867
src/keepass2android/Resources/Resource.designer.cs
generated
1867
src/keepass2android/Resources/Resource.designer.cs
generated
File diff suppressed because it is too large
Load Diff
@ -45,7 +45,9 @@
|
||||
<string name="import_keyfile_prefs">Import key file to internal folder</string>
|
||||
<string name="OnlyAvailableForLocalFiles">Only available for local files.</string>
|
||||
<string name="FileIsInInternalDirectory">File is stored in internal directory.</string>
|
||||
<string name="DatabaseFileMoved">Database file was copied to internal folder. Press Ok to open from the new location. Note: Do not forget to regularly export/backup the database!</string>
|
||||
<string name="DatabaseFileMoved">Database file was copied to internal folder. Press Ok to open from the new location. Note: Do not forget to regularly export the database to a safe storage!</string>
|
||||
<string name="KeyfileMoved">Keyfile was copied to internal folder. Make sure you have a safe backup before deleting from the current location!</string>
|
||||
<string name="KeyfileMoveRequiresRememberKeyfile">Cannot use internal folder when key file location is not remembered. Change security preferences.</string>
|
||||
|
||||
<string name="brackets">Brackets</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
|
@ -24,6 +24,7 @@ using Android.Widget;
|
||||
using Android.Preferences;
|
||||
using Java.IO;
|
||||
using KeePassLib.Cryptography.Cipher;
|
||||
using KeePassLib.Keys;
|
||||
using KeePassLib.Serialization;
|
||||
using KeePassLib.Utility;
|
||||
using keepass2android.Io;
|
||||
@ -180,8 +181,90 @@ namespace keepass2android
|
||||
SetAlgorithm(db, algorithm);
|
||||
|
||||
UpdateImportDbPref();
|
||||
UpdateImportKeyfilePref();
|
||||
}
|
||||
|
||||
private void UpdateImportKeyfilePref()
|
||||
{
|
||||
var prefs = PreferenceManager.GetDefaultSharedPreferences(this);
|
||||
var rememberKeyfile = prefs.GetBoolean(GetString(Resource.String.keyfile_key), Resources.GetBoolean(Resource.Boolean.keyfile_default));
|
||||
|
||||
Preference importDb = FindPreference("import_keyfile_prefs");
|
||||
importDb.Summary = "";
|
||||
|
||||
if (!rememberKeyfile)
|
||||
{
|
||||
importDb.Summary = GetString(Resource.String.KeyfileMoveRequiresRememberKeyfile);
|
||||
importDb.Enabled = false;
|
||||
return;
|
||||
}
|
||||
CompositeKey masterKey = App.Kp2a.GetDb().KpDatabase.MasterKey;
|
||||
if (masterKey.ContainsType(typeof (KcpKeyFile)))
|
||||
{
|
||||
IOConnectionInfo iocKeyfile = ((KcpKeyFile)masterKey.GetUserKey(typeof (KcpKeyFile))).Ioc;
|
||||
if (iocKeyfile.IsLocalFile() && IoUtil.IsInInternalDirectory(iocKeyfile.Path, this))
|
||||
{
|
||||
importDb.Enabled = false;
|
||||
importDb.Summary = GetString(Resource.String.FileIsInInternalDirectory);
|
||||
}
|
||||
else
|
||||
{
|
||||
importDb.Enabled = true;
|
||||
importDb.PreferenceClick += (sender, args) => { MoveKeyfileToInternalFolder();};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
importDb.Enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveKeyfileToInternalFolder()
|
||||
{
|
||||
Func<Action> copyAndReturnPostExecute = () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
CompositeKey masterKey = App.Kp2a.GetDb().KpDatabase.MasterKey;
|
||||
var sourceIoc = ((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).Ioc;
|
||||
var newIoc = ImportFileToInternalDirectory(sourceIoc);
|
||||
((KcpKeyFile)masterKey.GetUserKey(typeof(KcpKeyFile))).ResetIoc(newIoc);
|
||||
var keyfileString = IOConnectionInfo.SerializeToString(newIoc);
|
||||
App.Kp2a.StoreOpenedFileAsRecent(App.Kp2a.GetDb().Ioc, keyfileString);
|
||||
return () =>
|
||||
{
|
||||
UpdateImportKeyfilePref();
|
||||
var builder = new AlertDialog.Builder(this);
|
||||
builder
|
||||
.SetMessage(Resource.String.KeyfileMoved);
|
||||
builder.SetPositiveButton(Android.Resource.String.Ok, (sender, args) => { });
|
||||
builder.Show();
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return () =>
|
||||
{
|
||||
Toast.MakeText(this, App.Kp2a.GetResourceString(UiStringKey.ErrorOcurred) + " " + e.Message, ToastLength.Long).Show();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
new SimpleLoadingDialog(this, GetString(Resource.String.CopyingFile), false,
|
||||
copyAndReturnPostExecute
|
||||
).Execute();
|
||||
|
||||
}
|
||||
private void UpdateImportDbPref()
|
||||
{
|
||||
//Import db/key file preferences:
|
||||
|
Loading…
Reference in New Issue
Block a user