Mark passwords as sensitive when copy to clipboard

This commit is contained in:
Arieh Schneier
2022-12-13 02:28:05 +11:00
parent 748bd493c4
commit 5f836c381f
4 changed files with 22 additions and 13 deletions

View File

@@ -982,7 +982,7 @@ namespace keepass2android
popupKey,
container,
anchor);
popupItems.Add(new CopyToClipboardPopupMenuIcon(this, _stringViews[fieldKey]));
popupItems.Add(new CopyToClipboardPopupMenuIcon(this, _stringViews[fieldKey], isProtected));
if (isProtected)
{
var valueView = container.FindViewById<TextView>(fieldKey == PwDefs.PasswordField ? Resource.Id.entry_password : Resource.Id.entry_extra);

View File

@@ -10,12 +10,13 @@ namespace keepass2android
{
private readonly Context _context;
private readonly IStringView _stringView;
private readonly bool _isProtected;
public CopyToClipboardPopupMenuIcon(Context context, IStringView stringView)
public CopyToClipboardPopupMenuIcon(Context context, IStringView stringView, bool isProtected)
{
_context = context;
_stringView = stringView;
_isProtected = isProtected;
}
public Drawable Icon
@@ -33,7 +34,7 @@ namespace keepass2android
public void HandleClick()
{
CopyToClipboardService.CopyValueToClipboardWithTimeout(_context, _stringView.Text);
CopyToClipboardService.CopyValueToClipboardWithTimeout(_context, _stringView.Text, _isProtected);
}
}
}

View File

@@ -200,9 +200,15 @@ namespace keepass2android
return "";
}
public static void CopyToClipboard(Context context, String text) {
public static void CopyToClipboard(Context context, String text, bool isProtected) {
Android.Content.ClipboardManager clipboardManager = (ClipboardManager)context.GetSystemService(Context.ClipboardService);
ClipData clipData = Android.Content.ClipData.NewPlainText("KP2A", text);
if (isProtected)
{
var extras = clipData.Description.Extras ?? new Android.OS.PersistableBundle();
extras.PutBoolean("android.content.extra.IS_SENSITIVE", true);
clipData.Description.Extras = extras;
}
clipboardManager.PrimaryClip = clipData;
if (text == "")
{

View File

@@ -262,11 +262,12 @@ namespace keepass2android
public const int NotifyCombined = 5;
public const int NotifyTotp = 6;
static public void CopyValueToClipboardWithTimeout(Context ctx, string text)
static public void CopyValueToClipboardWithTimeout(Context ctx, string text, bool isProtected)
{
Intent i = new Intent(ctx, typeof(CopyToClipboardService));
i.SetAction(Intents.CopyStringToClipboard);
i.PutExtra(_stringtocopy, text);
i.PutExtra(_stringisprotected, isProtected);
ctx.StartService(i);
}
@@ -377,7 +378,7 @@ namespace keepass2android
if (intent.Action == Intents.CopyStringToClipboard)
{
TimeoutCopyToClipboard(intent.GetStringExtra(_stringtocopy));
TimeoutCopyToClipboard(intent.GetStringExtra(_stringtocopy), intent.GetBooleanExtra(_stringisprotected, false));
}
if (intent.Action == Intents.ActivateKeyboard)
{
@@ -673,9 +674,9 @@ namespace keepass2android
private readonly Timer _timer = new Timer();
internal void TimeoutCopyToClipboard(String text)
internal void TimeoutCopyToClipboard(String text, bool isProtected)
{
Util.CopyToClipboard(this, text);
Util.CopyToClipboard(this, text, isProtected);
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
String sClipClear = prefs.GetString(GetString(Resource.String.clipboard_timeout_key), GetString(Resource.String.clipboard_timeout_default));
@@ -711,7 +712,7 @@ namespace keepass2android
DoPostClear();
if (currentClip.Equals(_clearText))
{
Util.CopyToClipboard(_service, "");
Util.CopyToClipboard(_service, "", false);
DoPostWarn();
}
}
@@ -747,6 +748,7 @@ namespace keepass2android
readonly Handler _uiThreadCallback = new Handler();
private ClearClipboardTask _clearClipboardTask;
private const string _stringtocopy = "StringToCopy";
private const string _stringisprotected = "StringIsProtected";
@@ -942,7 +944,7 @@ namespace keepass2android
String username = App.Kp2a.LastOpenedEntry.OutputStrings.ReadSafe(PwDefs.UserNameField);
if (username.Length > 0)
{
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, username);
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, username, false);
}
context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
}
@@ -951,7 +953,7 @@ namespace keepass2android
String password = App.Kp2a.LastOpenedEntry.OutputStrings.ReadSafe(PwDefs.PasswordField);
if (password.Length > 0)
{
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, password);
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, password, true);
}
context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
}
@@ -960,7 +962,7 @@ namespace keepass2android
String totp = App.Kp2a.LastOpenedEntry.OutputStrings.ReadSafe(UpdateTotpTimerTask.TotpKey);
if (totp.Length > 0)
{
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, totp);
CopyToClipboardService.CopyValueToClipboardWithTimeout(context, totp, true);
}
context.SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); //close notification drawer
}