* added option to ignore duplicate uuids

* fixed issue with clearing entered passwords when leaving PasswordActivity (passwords were cleared when opening FS-Setup-Activity or NfcOtpActivity as well)
This commit is contained in:
Philipp Crocoll 2015-01-06 04:01:46 +01:00
parent 7cffa9a3c3
commit 687416d2bb
10 changed files with 1186 additions and 1123 deletions

View File

@ -100,6 +100,6 @@ namespace keepass2android
RemoteCertificateValidationCallback CertificateValidationCallback { get; } RemoteCertificateValidationCallback CertificateValidationCallback { get; }
bool CheckForDuplicateUuids { get; }
} }
} }

View File

@ -55,6 +55,7 @@ namespace keepass2android
FileIsReadOnly, FileIsReadOnly,
FileIsReadOnlyOnKitkat, FileIsReadOnlyOnKitkat,
CopyFileRequiredForEditing, CopyFileRequiredForEditing,
DuplicateUuidsError DuplicateUuidsError,
DuplicateUuidsErrorAdditional
} }
} }

View File

@ -174,8 +174,7 @@ namespace keepass2android
} }
private void PopulateGlobals(PwGroup currentGroup, bool checkForDuplicateUuids )
private void PopulateGlobals (PwGroup currentGroup)
{ {
var childGroups = currentGroup.Groups; var childGroups = currentGroup.Groups;
@ -183,22 +182,34 @@ namespace keepass2android
foreach (PwEntry e in childEntries) foreach (PwEntry e in childEntries)
{ {
if (Entries.ContainsKey(e.Uuid)) if (checkForDuplicateUuids)
{ {
throw new DuplicateUuidsException(); if (Entries.ContainsKey(e.Uuid))
{
throw new DuplicateUuidsException();
}
} }
Entries [e.Uuid] = e; Entries [e.Uuid] = e;
} }
foreach (PwGroup g in childGroups) foreach (PwGroup g in childGroups)
{ {
if (Groups.ContainsKey(g.Uuid)) if (checkForDuplicateUuids)
{ {
throw new DuplicateUuidsException();
if (Groups.ContainsKey(g.Uuid))
{
throw new DuplicateUuidsException();
}
} }
Groups[g.Uuid] = g; Groups[g.Uuid] = g;
PopulateGlobals(g); PopulateGlobals(g);
} }
} }
private void PopulateGlobals (PwGroup currentGroup)
{
PopulateGlobals(currentGroup, _app.CheckForDuplicateUuids);
}
public void Clear() { public void Clear() {
Groups.Clear(); Groups.Clear();

View File

@ -92,7 +92,7 @@ namespace keepass2android
catch (DuplicateUuidsException e) catch (DuplicateUuidsException e)
{ {
Kp2aLog.Log("Exception: " + e); Kp2aLog.Log("Exception: " + e);
Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError)); Finish(false, _app.GetResourceString(UiStringKey.DuplicateUuidsError)+" " + _app.GetResourceString(UiStringKey.DuplicateUuidsErrorAdditional));
return; return;
} }
catch (Exception e) catch (Exception e)

View File

@ -139,7 +139,8 @@ namespace keepass2android
private ActivityDesign _design; private ActivityDesign _design;
private bool _performingLoad; private bool _performingLoad;
private bool _keepPasswordInOnResume;
public PasswordActivity (IntPtr javaReference, JniHandleOwnership transfer) public PasswordActivity (IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer) : base(javaReference, transfer)
@ -213,7 +214,7 @@ namespace keepass2android
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
{ {
base.OnActivityResult(requestCode, resultCode, data); base.OnActivityResult(requestCode, resultCode, data);
_keepPasswordInOnResume = true;
Kp2aLog.Log("PasswordActivity.OnActivityResult "+resultCode+"/"+requestCode); Kp2aLog.Log("PasswordActivity.OnActivityResult "+resultCode+"/"+requestCode);
AppTask.TryGetFromActivityResult(data, ref AppTask); AppTask.TryGetFromActivityResult(data, ref AppTask);
@ -576,6 +577,7 @@ namespace keepass2android
else if ((action != null) && (action.Equals(Intents.StartWithOtp))) else if ((action != null) && (action.Equals(Intents.StartWithOtp)))
{ {
if (!GetIocFromOtpIntent(savedInstanceState, i)) return; if (!GetIocFromOtpIntent(savedInstanceState, i)) return;
_keepPasswordInOnResume = true;
} }
else else
{ {
@ -596,6 +598,10 @@ namespace keepass2android
{ {
_keyFileOrProvider = GetKeyFile(_ioConnection.Path); _keyFileOrProvider = GetKeyFile(_ioConnection.Path);
} }
if ((!string.IsNullOrEmpty(_keyFileOrProvider)) || (_password != ""))
{
_keepPasswordInOnResume = true;
}
} }
if (App.Kp2a.GetDb().Loaded && App.Kp2a.GetDb().Ioc != null && if (App.Kp2a.GetDb().Loaded && App.Kp2a.GetDb().Ioc != null &&
@ -1199,7 +1205,7 @@ namespace keepass2android
if ((intent != null) && (intent.HasExtra(Intents.OtpExtraKey))) if ((intent != null) && (intent.HasExtra(Intents.OtpExtraKey)))
{ {
string otp = intent.GetStringExtra(Intents.OtpExtraKey); string otp = intent.GetStringExtra(Intents.OtpExtraKey);
_keepPasswordInOnResume = true;
if (_otpInfo == null) if (_otpInfo == null)
{ {
//Entering OTPs not yet initialized: //Entering OTPs not yet initialized:
@ -1260,6 +1266,12 @@ namespace keepass2android
killButton.Visibility = ViewStates.Gone; killButton.Visibility = ViewStates.Gone;
} }
if (!_keepPasswordInOnResume)
{
ClearEnteredPassword();
}
_keepPasswordInOnResume = false;
MakePasswordMaskedOrVisible(); MakePasswordMaskedOrVisible();
UpdateOkButtonState(); UpdateOkButtonState();
@ -1347,11 +1359,6 @@ namespace keepass2android
} }
} }
protected override void OnPause()
{
base.OnPause();
ClearEnteredPassword(); //if the activity is left without opening the database, clear the password if entered
}
protected override void OnDestroy() protected override void OnDestroy()
{ {
@ -1437,7 +1444,18 @@ namespace keepass2android
GC.Collect(); // Ensure temporary memory used while loading is collected GC.Collect(); // Ensure temporary memory used while loading is collected
} }
DisplayMessage(_act); if ((Message != null) && (Message.Length > 150)) //show long messages as dialog
{
new AlertDialog.Builder(_act).SetMessage(Message)
.SetPositiveButton(Android.Resource.String.Ok,
(sender, args) => ((Dialog) sender).Dismiss())
.Show();
}
else
{
DisplayMessage(_act);
}
_act._performingLoad = false; _act._performingLoad = false;

File diff suppressed because it is too large Load Diff

View File

@ -106,6 +106,7 @@
<string name="UseOfflineCache_key">UseOfflineCache</string> <string name="UseOfflineCache_key">UseOfflineCache</string>
<string name="AcceptAllServerCertificates_key">AcceptAllServerCertificates</string> <string name="AcceptAllServerCertificates_key">AcceptAllServerCertificates</string>
<string name="CheckForFileChangesOnSave_key">CheckForFileChangesOnSave</string> <string name="CheckForFileChangesOnSave_key">CheckForFileChangesOnSave</string>
<string name="CheckForDuplicateUuids_key">CheckForDuplicateUuids_key</string>
<string name="about_prefs_key">about_prefs</string> <string name="about_prefs_key">about_prefs</string>

View File

@ -303,6 +303,9 @@
<string name="CheckForFileChangesOnSave_title">Check for modifications</string> <string name="CheckForFileChangesOnSave_title">Check for modifications</string>
<string name="CheckForFileChangesOnSave_summary">Check whether the file was modified externally before saving changes.</string> <string name="CheckForFileChangesOnSave_summary">Check whether the file was modified externally before saving changes.</string>
<string name="CheckForDuplicateUuids_title">Check for duplicate UUIDs</string>
<string name="CheckForDuplicateUuids_summary">Check whether the database file is corrupt by having multiple entries with the same ID. This might cause unexpected behavior.</string>
<string name="ShowCopyToClipboardNotification_title">Clipboard notifications</string> <string name="ShowCopyToClipboardNotification_title">Clipboard notifications</string>
<string name="ShowCopyToClipboardNotification_summary">Make username and password accessible through the notification bar and clipboard. Beware of password sniffers!</string> <string name="ShowCopyToClipboardNotification_summary">Make username and password accessible through the notification bar and clipboard. Beware of password sniffers!</string>
@ -387,6 +390,7 @@
<string name="ErrorOcurred">An error occured:</string> <string name="ErrorOcurred">An error occured:</string>
<string name="DuplicateUuidsError">Database is corrupt: Duplicate IDs found. (Did you save with Minikeepass?) Please re-import to a new database with Keepass 2 for PC and select \'Create new IDs\'.</string> <string name="DuplicateUuidsError">Database is corrupt: Duplicate IDs found. (Did you save with Minikeepass?) Please re-import to a new database with Keepass 2 for PC and select \'Create new IDs\'.</string>
<string name="DuplicateUuidsErrorAdditional">You can disable this error message in Settings/Application settings/File handling/Check for duplicate UUIDs. Please note that you might experience unexpected behavior. It is recommended to fix the database.</string>
<string name="synchronize_database_menu">Synchronize database…</string> <string name="synchronize_database_menu">Synchronize database…</string>

View File

@ -365,6 +365,13 @@
android:title="@string/TanExpiresOnUse_title" android:title="@string/TanExpiresOnUse_title"
android:summary="@string/TanExpiresOnUse_summary" android:summary="@string/TanExpiresOnUse_summary"
android:defaultValue="@bool/TanExpiresOnUse_default"/> android:defaultValue="@bool/TanExpiresOnUse_default"/>
<CheckBoxPreference
android:enabled="true"
android:persistent="true"
android:summary="@string/CheckForDuplicateUuids_summary"
android:defaultValue="true"
android:title="@string/CheckForDuplicateUuids_title"
android:key="@string/CheckForDuplicateUuids_key" />
</PreferenceScreen> </PreferenceScreen>
<PreferenceScreen <PreferenceScreen

View File

@ -514,6 +514,15 @@ namespace keepass2android
} }
public bool CheckForDuplicateUuids
{
get
{
var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
return prefs.GetBoolean(Application.Context.GetString(Resource.String.CheckForDuplicateUuids_key), true);
}
}
enum ValidationMode enum ValidationMode
{ {