From af90db96a5d05bb37985afa7d01246fe963674f0 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 10:51:12 +0200 Subject: [PATCH 1/7] new PassphraseCache, storing UserIDs as well --- .../service/PassphraseCacheService.java | 58 +++++++++++++++---- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 28f230f71..9a68b8367 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -37,6 +37,7 @@ import android.support.v4.util.LongSparseArray; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; +import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.util.Log; @@ -54,6 +55,8 @@ public class PassphraseCacheService extends Service { + "PASSPHRASE_CACHE_ADD"; public static final String ACTION_PASSPHRASE_CACHE_GET = Constants.INTENT_PREFIX + "PASSPHRASE_CACHE_GET"; + public static final String ACTION_PASSPHRASE_CACHE_PURGE = Constants.INTENT_PREFIX + + "PASSPHRASE_CACHE_PURGE"; public static final String BROADCAST_ACTION_PASSPHRASE_CACHE_SERVICE = Constants.INTENT_PREFIX + "PASSPHRASE_CACHE_BROADCAST"; @@ -62,13 +65,14 @@ public class PassphraseCacheService extends Service { public static final String EXTRA_KEY_ID = "key_id"; public static final String EXTRA_PASSPHRASE = "passphrase"; public static final String EXTRA_MESSENGER = "messenger"; + public static final String EXTRA_USERID = "userid"; private static final int REQUEST_ID = 0; private static final long DEFAULT_TTL = 15; private BroadcastReceiver mIntentReceiver; - private LongSparseArray mPassphraseCache = new LongSparseArray(); + private LongSparseArray mPassphraseCache = new LongSparseArray(); Context mContext; @@ -81,14 +85,17 @@ public class PassphraseCacheService extends Service { * @param keyId * @param passphrase */ - public static void addCachedPassphrase(Context context, long keyId, String passphrase) { + public static void addCachedPassphrase(Context context, long keyId, String passphrase, + String primaryUserId) { Log.d(Constants.TAG, "PassphraseCacheService.cacheNewPassphrase() for " + keyId); Intent intent = new Intent(context, PassphraseCacheService.class); intent.setAction(ACTION_PASSPHRASE_CACHE_ADD); + intent.putExtra(EXTRA_TTL, Preferences.getPreferences(context).getPassphraseCacheTtl()); intent.putExtra(EXTRA_PASSPHRASE, passphrase); intent.putExtra(EXTRA_KEY_ID, keyId); + intent.putExtra(EXTRA_USERID, primaryUserId); context.startService(intent); } @@ -159,11 +166,11 @@ public class PassphraseCacheService extends Service { // passphrase for symmetric encryption? if (keyId == Constants.key.symmetric) { Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphraseImpl() for symmetric encryption"); - String cachedPassphrase = mPassphraseCache.get(Constants.key.symmetric); + String cachedPassphrase = mPassphraseCache.get(Constants.key.symmetric).getPassphrase(); if (cachedPassphrase == null) { return null; } - addCachedPassphrase(this, Constants.key.symmetric, cachedPassphrase); + addCachedPassphrase(this, Constants.key.symmetric, cachedPassphrase, "Password"); return cachedPassphrase; } @@ -176,13 +183,17 @@ public class PassphraseCacheService extends Service { if (!key.hasPassphrase()) { Log.d(Constants.TAG, "Key has no passphrase! Caches and returns empty passphrase!"); - addCachedPassphrase(this, keyId, ""); + try { + addCachedPassphrase(this, keyId, "", key.getPrimaryUserId()); + } catch (PgpGeneralException e) { + Log.d(Constants.TAG, "PgpGeneralException occured"); + } return ""; } // get cached passphrase - String cachedPassphrase = mPassphraseCache.get(keyId); - if (cachedPassphrase == null) { + CachedPassphrase cachedPassphrase = mPassphraseCache.get(keyId); + if (cachedPassphrase == null && cachedPassphrase.getPassphrase() != null) { Log.d(Constants.TAG, "PassphraseCacheService Passphrase not (yet) cached, returning null"); // not really an error, just means the passphrase is not cached but not empty either return null; @@ -190,8 +201,8 @@ public class PassphraseCacheService extends Service { // set it again to reset the cache life cycle Log.d(Constants.TAG, "PassphraseCacheService Cache passphrase again when getting it!"); - addCachedPassphrase(this, keyId, cachedPassphrase); - return cachedPassphrase; + addCachedPassphrase(this, keyId, cachedPassphrase.getPassphrase(), cachedPassphrase.getPrimaryUserID()); + return cachedPassphrase.getPassphrase(); } catch (ProviderHelper.NotFoundException e) { Log.e(Constants.TAG, "PassphraseCacheService Passphrase for unknown key was requested!"); @@ -256,14 +267,16 @@ public class PassphraseCacheService extends Service { if (ACTION_PASSPHRASE_CACHE_ADD.equals(intent.getAction())) { long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL); long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1); + String passphrase = intent.getStringExtra(EXTRA_PASSPHRASE); + String primaryUserID = intent.getStringExtra(EXTRA_USERID); Log.d(Constants.TAG, "PassphraseCacheService Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with keyId: " + keyId + ", ttl: " + ttl); // add keyId and passphrase to memory - mPassphraseCache.put(keyId, passphrase); + mPassphraseCache.put(keyId, new CachedPassphrase(passphrase, primaryUserID)); if (ttl > 0) { // register new alarm with keyId for this passphrase @@ -341,4 +354,27 @@ public class PassphraseCacheService extends Service { private final IBinder mBinder = new PassphraseCacheBinder(); -} + public class CachedPassphrase { + private String primaryUserID = ""; + private String passphrase = ""; + + public CachedPassphrase(String passphrase, String primaryUserID) { + setPassphrase(passphrase); + setPrimaryUserID(primaryUserID); + } + + public String getPrimaryUserID() { + return primaryUserID; + } + public String getPassphrase() { + return passphrase; + } + + public void setPrimaryUserID(String primaryUserID) { + this.primaryUserID = primaryUserID; + } + public void setPassphrase(String passphrase) { + this.passphrase = passphrase; + } + } +} \ No newline at end of file From cf40517eaca2c852a0a0022b93c46e7a41766d80 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 12:27:19 +0200 Subject: [PATCH 2/7] Implemented Notification, no fallback yet --- .../service/KeychainIntentService.java | 3 +- .../service/PassphraseCacheService.java | 72 ++++++++++++++++++- .../ui/dialog/PassphraseDialogFragment.java | 15 +++- 3 files changed, 83 insertions(+), 7 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index c4c31bdad..10faa8786 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -44,6 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; import org.sufficientlysecure.keychain.pgp.Progressable; import org.sufficientlysecure.keychain.pgp.UncachedKeyRing; +import org.sufficientlysecure.keychain.pgp.WrappedPublicKey; import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.WrappedSecretKey; import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; @@ -351,7 +352,7 @@ public class KeychainIntentService extends IntentService // cache new passphrase if (saveParcel.newPassphrase != null) { PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(), - saveParcel.newPassphrase); + saveParcel.newPassphrase, ring.getPublicKey().getPrimaryUserId()); } } catch (ProviderHelper.NotFoundException e) { sendErrorToHandler(e); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 9a68b8367..9d998f18f 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -20,6 +20,7 @@ package org.sufficientlysecure.keychain.service; import android.app.AlarmManager; import android.app.PendingIntent; import android.app.Service; +import android.app.NotificationManager; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; @@ -32,9 +33,12 @@ import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; + import android.support.v4.util.LongSparseArray; +import android.support.v4.app.NotificationCompat; import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.helper.Preferences; import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; @@ -70,6 +74,8 @@ public class PassphraseCacheService extends Service { private static final int REQUEST_ID = 0; private static final long DEFAULT_TTL = 15; + private static final int NOTIFICATION_ID = 1; + private BroadcastReceiver mIntentReceiver; private LongSparseArray mPassphraseCache = new LongSparseArray(); @@ -193,7 +199,7 @@ public class PassphraseCacheService extends Service { // get cached passphrase CachedPassphrase cachedPassphrase = mPassphraseCache.get(keyId); - if (cachedPassphrase == null && cachedPassphrase.getPassphrase() != null) { + if (cachedPassphrase == null) { Log.d(Constants.TAG, "PassphraseCacheService Passphrase not (yet) cached, returning null"); // not really an error, just means the passphrase is not cached but not empty either return null; @@ -273,9 +279,9 @@ public class PassphraseCacheService extends Service { Log.d(Constants.TAG, "PassphraseCacheService Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with keyId: " - + keyId + ", ttl: " + ttl); + + keyId + ", ttl: " + ttl + ", usrId: " + primaryUserID); - // add keyId and passphrase to memory + // add keyId, passphrase and primary user id to memory mPassphraseCache.put(keyId, new CachedPassphrase(passphrase, primaryUserID)); if (ttl > 0) { @@ -284,6 +290,9 @@ public class PassphraseCacheService extends Service { AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, keyId)); } + + updateNotifications(); + } else if (ACTION_PASSPHRASE_CACHE_GET.equals(intent.getAction())) { long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1); Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER); @@ -299,6 +308,17 @@ public class PassphraseCacheService extends Service { } catch (RemoteException e) { Log.e(Constants.TAG, "PassphraseCacheService Sending message failed", e); } + } else if (ACTION_PASSPHRASE_CACHE_PURGE.equals(intent.getAction())) { + AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); + + // Stop all ttl alarms + for(int i = 0; i < mPassphraseCache.size(); i++) { + am.cancel(buildIntent(this, mPassphraseCache.keyAt(i))); + } + + mPassphraseCache.clear(); + + updateNotifications(); } else { Log.e(Constants.TAG, "PassphraseCacheService Intent or Intent Action not supported!"); } @@ -324,6 +344,52 @@ public class PassphraseCacheService extends Service { Log.d(Constants.TAG, "PassphraseCacheServic No passphrases remaining in memory, stopping service!"); stopSelf(); } + + updateNotifications(); + } + + private void updateNotifications() { + NotificationManager notificationManager = + (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + + if(mPassphraseCache.size() > 0) { + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + + builder.setSmallIcon(R.drawable.ic_launcher) + .setContentTitle("Open Keychain") + .setContentText("Open Keychain has cached " + mPassphraseCache.size() + " keys."); + + NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); + + inboxStyle.setBigContentTitle("Cached Passphrases:"); + + // Moves events into the big view + for (int i = 0; i < mPassphraseCache.size(); i++) { + inboxStyle.addLine(mPassphraseCache.valueAt(i).getPrimaryUserID()); + } + + // Moves the big view style object into the notification object. + builder.setStyle(inboxStyle); + + // Add purging action + Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); + intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); + builder.addAction( + R.drawable.abc_ic_clear_normal, + "Purge Cache", + PendingIntent.getService( + getApplicationContext(), + 0, + intent, + PendingIntent.FLAG_UPDATE_CURRENT + ) + ); + + notificationManager.notify(NOTIFICATION_ID, builder.build()); + + } else { + notificationManager.cancel(NOTIFICATION_ID); + } } @Override diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 59e4d8dee..5bbbf20a7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -189,7 +189,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // Early breakout if we are dealing with a symmetric key if (secretRing == null) { - PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, passphrase); + PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, + passphrase, "Password"); // also return passphrase back to activity Bundle data = new Bundle(); data.putString(MESSAGE_DATA_PASSPHRASE, passphrase); @@ -228,10 +229,18 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // cache the new passphrase Log.d(Constants.TAG, "Everything okay! Caching entered passphrase"); - PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase); + + try { + PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase, + secretRing.getPrimaryUserId()); + } catch(PgpGeneralException e) { + Log.e(Constants.TAG, e.getMessage()); + } + if (unlockedSecretKey.getKeyId() != masterKeyId) { PassphraseCacheService.addCachedPassphrase( - activity, unlockedSecretKey.getKeyId(), passphrase); + activity, unlockedSecretKey.getKeyId(), passphrase, + unlockedSecretKey.getPrimaryUserId()); } // also return passphrase back to activity From 2568ea4b2edaa1a13b15395d1951e7f941fba073 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 12:42:48 +0200 Subject: [PATCH 3/7] Added Purging for Android < 4.1 --- .../service/PassphraseCacheService.java | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 9d998f18f..84ad441cb 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -26,6 +26,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.os.Binder; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; @@ -353,40 +354,62 @@ public class PassphraseCacheService extends Service { (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); if(mPassphraseCache.size() > 0) { - NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); - builder.setSmallIcon(R.drawable.ic_launcher) - .setContentTitle("Open Keychain") - .setContentText("Open Keychain has cached " + mPassphraseCache.size() + " keys."); + builder.setSmallIcon(R.drawable.ic_launcher) + .setContentTitle("Open Keychain") + .setContentText("Open Keychain has cached " + mPassphraseCache.size() + " keys."); - NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); + NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); - inboxStyle.setBigContentTitle("Cached Passphrases:"); + inboxStyle.setBigContentTitle("Cached Passphrases:"); - // Moves events into the big view - for (int i = 0; i < mPassphraseCache.size(); i++) { - inboxStyle.addLine(mPassphraseCache.valueAt(i).getPrimaryUserID()); + // Moves events into the big view + for (int i = 0; i < mPassphraseCache.size(); i++) { + inboxStyle.addLine(mPassphraseCache.valueAt(i).getPrimaryUserID()); + } + + // Moves the big view style object into the notification object. + builder.setStyle(inboxStyle); + + // Add purging action + Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); + intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); + builder.addAction( + R.drawable.abc_ic_clear_normal, + "Purge Cache", + PendingIntent.getService( + getApplicationContext(), + 0, + intent, + PendingIntent.FLAG_UPDATE_CURRENT + ) + ); + + notificationManager.notify(NOTIFICATION_ID, builder.build()); + } else { // Fallback, since expandable notifications weren't available back then + NotificationCompat.Builder builder = new NotificationCompat.Builder(this); + + builder.setSmallIcon(R.drawable.ic_launcher) + .setContentTitle("Open Keychain has cached " + mPassphraseCache.size() + " keys.") + .setContentText("Click to purge the cache"); + + Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); + intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); + + builder.setContentIntent( + PendingIntent.getService( + getApplicationContext(), + 0, + intent, + PendingIntent.FLAG_UPDATE_CURRENT + ) + ); + + notificationManager.notify(NOTIFICATION_ID, builder.build()); } - // Moves the big view style object into the notification object. - builder.setStyle(inboxStyle); - - // Add purging action - Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); - intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); - builder.addAction( - R.drawable.abc_ic_clear_normal, - "Purge Cache", - PendingIntent.getService( - getApplicationContext(), - 0, - intent, - PendingIntent.FLAG_UPDATE_CURRENT - ) - ); - - notificationManager.notify(NOTIFICATION_ID, builder.build()); - } else { notificationManager.cancel(NOTIFICATION_ID); } From 7a3fe61a1f497ba431ed5fe3c68b11ed9578eaba Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 12:52:44 +0200 Subject: [PATCH 4/7] Put text into strings.xml, for internationalization --- .../keychain/service/PassphraseCacheService.java | 12 ++++++------ OpenKeychain/src/main/res/values/strings.xml | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 84ad441cb..9b868c859 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -358,12 +358,12 @@ public class PassphraseCacheService extends Service { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher) - .setContentTitle("Open Keychain") - .setContentText("Open Keychain has cached " + mPassphraseCache.size() + " keys."); + .setContentTitle(getString(R.string.app_name)) + .setContentText(String.format(getString(R.string.passp_cache_notif_n_keys, mPassphraseCache.size()))); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); - inboxStyle.setBigContentTitle("Cached Passphrases:"); + inboxStyle.setBigContentTitle(getString(R.string.passp_cache_notif_keys)); // Moves events into the big view for (int i = 0; i < mPassphraseCache.size(); i++) { @@ -378,7 +378,7 @@ public class PassphraseCacheService extends Service { intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); builder.addAction( R.drawable.abc_ic_clear_normal, - "Purge Cache", + getString(R.string.passp_cache_notif_purge), PendingIntent.getService( getApplicationContext(), 0, @@ -392,8 +392,8 @@ public class PassphraseCacheService extends Service { NotificationCompat.Builder builder = new NotificationCompat.Builder(this); builder.setSmallIcon(R.drawable.ic_launcher) - .setContentTitle("Open Keychain has cached " + mPassphraseCache.size() + " keys.") - .setContentText("Click to purge the cache"); + .setContentTitle(String.format(getString(R.string.passp_cache_notif_n_keys, mPassphraseCache.size()))) + .setContentText(getString(R.string.passp_cache_notif_click_to_purge)); Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 274309fd0..456a22086 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -660,6 +660,12 @@ Error unlocking keyring! Unlocking keyring + + Click to purge cached passphrases + OpenKeychain has cached %i keys + Cached Keys: + Purge Cache + Certifier Certificate Details From 079194abe5b48c2b6a5cf943b45a67b956937435 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 18:12:03 +0200 Subject: [PATCH 5/7] Fixed issues discussed in #713 --- .../service/PassphraseCacheService.java | 20 +++++++++---------- .../ui/dialog/PassphraseDialogFragment.java | 4 ++-- OpenKeychain/src/main/res/values/strings.xml | 5 +++-- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index 9b868c859..fb1da28fc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -60,8 +60,8 @@ public class PassphraseCacheService extends Service { + "PASSPHRASE_CACHE_ADD"; public static final String ACTION_PASSPHRASE_CACHE_GET = Constants.INTENT_PREFIX + "PASSPHRASE_CACHE_GET"; - public static final String ACTION_PASSPHRASE_CACHE_PURGE = Constants.INTENT_PREFIX - + "PASSPHRASE_CACHE_PURGE"; + public static final String ACTION_PASSPHRASE_CACHE_CLEAR = Constants.INTENT_PREFIX + + "PASSPHRASE_CACHE_CLEAR"; public static final String BROADCAST_ACTION_PASSPHRASE_CACHE_SERVICE = Constants.INTENT_PREFIX + "PASSPHRASE_CACHE_BROADCAST"; @@ -177,7 +177,7 @@ public class PassphraseCacheService extends Service { if (cachedPassphrase == null) { return null; } - addCachedPassphrase(this, Constants.key.symmetric, cachedPassphrase, "Password"); + addCachedPassphrase(this, Constants.key.symmetric, cachedPassphrase, getString(R.string.passp_cache_notif_pwd)); return cachedPassphrase; } @@ -309,7 +309,7 @@ public class PassphraseCacheService extends Service { } catch (RemoteException e) { Log.e(Constants.TAG, "PassphraseCacheService Sending message failed", e); } - } else if (ACTION_PASSPHRASE_CACHE_PURGE.equals(intent.getAction())) { + } else if (ACTION_PASSPHRASE_CACHE_CLEAR.equals(intent.getAction())) { AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); // Stop all ttl alarms @@ -375,10 +375,10 @@ public class PassphraseCacheService extends Service { // Add purging action Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); - intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); + intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR); builder.addAction( R.drawable.abc_ic_clear_normal, - getString(R.string.passp_cache_notif_purge), + getString(R.string.passp_cache_notif_clear), PendingIntent.getService( getApplicationContext(), 0, @@ -393,10 +393,10 @@ public class PassphraseCacheService extends Service { builder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle(String.format(getString(R.string.passp_cache_notif_n_keys, mPassphraseCache.size()))) - .setContentText(getString(R.string.passp_cache_notif_click_to_purge)); + .setContentText(getString(R.string.passp_cache_notif_click_to_clear)); Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class); - intent.setAction(ACTION_PASSPHRASE_CACHE_PURGE); + intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR); builder.setContentIntent( PendingIntent.getService( @@ -444,8 +444,8 @@ public class PassphraseCacheService extends Service { private final IBinder mBinder = new PassphraseCacheBinder(); public class CachedPassphrase { - private String primaryUserID = ""; - private String passphrase = ""; + private String primaryUserID; + private String passphrase; public CachedPassphrase(String passphrase, String primaryUserID) { setPassphrase(passphrase); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java index 5bbbf20a7..4d0b73d30 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/PassphraseDialogFragment.java @@ -190,7 +190,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor // Early breakout if we are dealing with a symmetric key if (secretRing == null) { PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, - passphrase, "Password"); + passphrase, getString(R.string.passp_cache_notif_pwd)); // also return passphrase back to activity Bundle data = new Bundle(); data.putString(MESSAGE_DATA_PASSPHRASE, passphrase); @@ -234,7 +234,7 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor PassphraseCacheService.addCachedPassphrase(activity, masterKeyId, passphrase, secretRing.getPrimaryUserId()); } catch(PgpGeneralException e) { - Log.e(Constants.TAG, e.getMessage()); + Log.e(Constants.TAG, "adding of a passhrase failed", e); } if (unlockedSecretKey.getKeyId() != masterKeyId) { diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 456a22086..1adecad01 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -661,10 +661,11 @@ Unlocking keyring - Click to purge cached passphrases + Click to clear cached passphrases OpenKeychain has cached %i keys Cached Keys: - Purge Cache + Clear Cache + Password Certifier From 066591dab1efa9d0bd75056fe06ecd6d8278fefa Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 18:53:52 +0200 Subject: [PATCH 6/7] Wello there, That's Java, not C^^ --- OpenKeychain/src/main/res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenKeychain/src/main/res/values/strings.xml b/OpenKeychain/src/main/res/values/strings.xml index 1adecad01..5f04aa6e6 100644 --- a/OpenKeychain/src/main/res/values/strings.xml +++ b/OpenKeychain/src/main/res/values/strings.xml @@ -662,7 +662,7 @@ Click to clear cached passphrases - OpenKeychain has cached %i keys + OpenKeychain has cached %d keys Cached Keys: Clear Cache Password From bd909375c2cac5f1b50838a9591eebbddc007b61 Mon Sep 17 00:00:00 2001 From: Daniel Albert Date: Sat, 12 Jul 2014 19:24:51 +0200 Subject: [PATCH 7/7] Fixed misplaced bracket --- .../keychain/service/PassphraseCacheService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java index fb1da28fc..72c1a8f67 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/PassphraseCacheService.java @@ -359,7 +359,7 @@ public class PassphraseCacheService extends Service { builder.setSmallIcon(R.drawable.ic_launcher) .setContentTitle(getString(R.string.app_name)) - .setContentText(String.format(getString(R.string.passp_cache_notif_n_keys, mPassphraseCache.size()))); + .setContentText(String.format(getString(R.string.passp_cache_notif_n_keys), mPassphraseCache.size())); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();