mirror of
https://github.com/moparisthebest/open-keychain
synced 2025-02-25 16:01:52 -05:00
Merge remote-tracking branch 'origin/master' into external-test
Conflicts: OpenKeychain-Test/src/test/resources/extern/OpenPGP-Haskell OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java
This commit is contained in:
commit
858fe47d46
@ -44,6 +44,7 @@ import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
|
|||||||
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
|
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
|
||||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.WrappedPublicKey;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
|
import org.sufficientlysecure.keychain.pgp.WrappedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
|
import org.sufficientlysecure.keychain.pgp.WrappedSecretKey;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
|
||||||
@ -351,7 +352,7 @@ public class KeychainIntentService extends IntentService
|
|||||||
// cache new passphrase
|
// cache new passphrase
|
||||||
if (saveParcel.mNewPassphrase != null) {
|
if (saveParcel.mNewPassphrase != null) {
|
||||||
PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(),
|
PassphraseCacheService.addCachedPassphrase(this, ring.getMasterKeyId(),
|
||||||
saveParcel.mNewPassphrase);
|
saveParcel.mNewPassphrase, ring.getPublicKey().getPrimaryUserId());
|
||||||
}
|
}
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
sendErrorToHandler(e);
|
sendErrorToHandler(e);
|
||||||
|
@ -20,11 +20,13 @@ package org.sufficientlysecure.keychain.service;
|
|||||||
import android.app.AlarmManager;
|
import android.app.AlarmManager;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
@ -32,11 +34,15 @@ import android.os.IBinder;
|
|||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import android.support.v4.util.LongSparseArray;
|
import android.support.v4.util.LongSparseArray;
|
||||||
|
import android.support.v4.app.NotificationCompat;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||||
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
|
import org.sufficientlysecure.keychain.pgp.WrappedSecretKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -54,6 +60,8 @@ public class PassphraseCacheService extends Service {
|
|||||||
+ "PASSPHRASE_CACHE_ADD";
|
+ "PASSPHRASE_CACHE_ADD";
|
||||||
public static final String ACTION_PASSPHRASE_CACHE_GET = Constants.INTENT_PREFIX
|
public static final String ACTION_PASSPHRASE_CACHE_GET = Constants.INTENT_PREFIX
|
||||||
+ "PASSPHRASE_CACHE_GET";
|
+ "PASSPHRASE_CACHE_GET";
|
||||||
|
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
|
public static final String BROADCAST_ACTION_PASSPHRASE_CACHE_SERVICE = Constants.INTENT_PREFIX
|
||||||
+ "PASSPHRASE_CACHE_BROADCAST";
|
+ "PASSPHRASE_CACHE_BROADCAST";
|
||||||
@ -62,13 +70,16 @@ public class PassphraseCacheService extends Service {
|
|||||||
public static final String EXTRA_KEY_ID = "key_id";
|
public static final String EXTRA_KEY_ID = "key_id";
|
||||||
public static final String EXTRA_PASSPHRASE = "passphrase";
|
public static final String EXTRA_PASSPHRASE = "passphrase";
|
||||||
public static final String EXTRA_MESSENGER = "messenger";
|
public static final String EXTRA_MESSENGER = "messenger";
|
||||||
|
public static final String EXTRA_USERID = "userid";
|
||||||
|
|
||||||
private static final int REQUEST_ID = 0;
|
private static final int REQUEST_ID = 0;
|
||||||
private static final long DEFAULT_TTL = 15;
|
private static final long DEFAULT_TTL = 15;
|
||||||
|
|
||||||
|
private static final int NOTIFICATION_ID = 1;
|
||||||
|
|
||||||
private BroadcastReceiver mIntentReceiver;
|
private BroadcastReceiver mIntentReceiver;
|
||||||
|
|
||||||
private LongSparseArray<String> mPassphraseCache = new LongSparseArray<String>();
|
private LongSparseArray<CachedPassphrase> mPassphraseCache = new LongSparseArray<CachedPassphrase>();
|
||||||
|
|
||||||
Context mContext;
|
Context mContext;
|
||||||
|
|
||||||
@ -81,14 +92,17 @@ public class PassphraseCacheService extends Service {
|
|||||||
* @param keyId
|
* @param keyId
|
||||||
* @param passphrase
|
* @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);
|
Log.d(Constants.TAG, "PassphraseCacheService.cacheNewPassphrase() for " + keyId);
|
||||||
|
|
||||||
Intent intent = new Intent(context, PassphraseCacheService.class);
|
Intent intent = new Intent(context, PassphraseCacheService.class);
|
||||||
intent.setAction(ACTION_PASSPHRASE_CACHE_ADD);
|
intent.setAction(ACTION_PASSPHRASE_CACHE_ADD);
|
||||||
|
|
||||||
intent.putExtra(EXTRA_TTL, Preferences.getPreferences(context).getPassphraseCacheTtl());
|
intent.putExtra(EXTRA_TTL, Preferences.getPreferences(context).getPassphraseCacheTtl());
|
||||||
intent.putExtra(EXTRA_PASSPHRASE, passphrase);
|
intent.putExtra(EXTRA_PASSPHRASE, passphrase);
|
||||||
intent.putExtra(EXTRA_KEY_ID, keyId);
|
intent.putExtra(EXTRA_KEY_ID, keyId);
|
||||||
|
intent.putExtra(EXTRA_USERID, primaryUserId);
|
||||||
|
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
}
|
}
|
||||||
@ -159,11 +173,11 @@ public class PassphraseCacheService extends Service {
|
|||||||
// passphrase for symmetric encryption?
|
// passphrase for symmetric encryption?
|
||||||
if (keyId == Constants.key.symmetric) {
|
if (keyId == Constants.key.symmetric) {
|
||||||
Log.d(Constants.TAG, "PassphraseCacheService.getCachedPassphraseImpl() for symmetric encryption");
|
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) {
|
if (cachedPassphrase == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
addCachedPassphrase(this, Constants.key.symmetric, cachedPassphrase);
|
addCachedPassphrase(this, Constants.key.symmetric, cachedPassphrase, getString(R.string.passp_cache_notif_pwd));
|
||||||
return cachedPassphrase;
|
return cachedPassphrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,12 +190,16 @@ public class PassphraseCacheService extends Service {
|
|||||||
if (!key.hasPassphrase()) {
|
if (!key.hasPassphrase()) {
|
||||||
Log.d(Constants.TAG, "Key has no passphrase! Caches and returns empty passphrase!");
|
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 "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// get cached passphrase
|
// get cached passphrase
|
||||||
String cachedPassphrase = mPassphraseCache.get(keyId);
|
CachedPassphrase cachedPassphrase = mPassphraseCache.get(keyId);
|
||||||
if (cachedPassphrase == null) {
|
if (cachedPassphrase == null) {
|
||||||
Log.d(Constants.TAG, "PassphraseCacheService Passphrase not (yet) cached, returning 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
|
// not really an error, just means the passphrase is not cached but not empty either
|
||||||
@ -190,8 +208,8 @@ public class PassphraseCacheService extends Service {
|
|||||||
|
|
||||||
// set it again to reset the cache life cycle
|
// set it again to reset the cache life cycle
|
||||||
Log.d(Constants.TAG, "PassphraseCacheService Cache passphrase again when getting it!");
|
Log.d(Constants.TAG, "PassphraseCacheService Cache passphrase again when getting it!");
|
||||||
addCachedPassphrase(this, keyId, cachedPassphrase);
|
addCachedPassphrase(this, keyId, cachedPassphrase.getPassphrase(), cachedPassphrase.getPrimaryUserID());
|
||||||
return cachedPassphrase;
|
return cachedPassphrase.getPassphrase();
|
||||||
|
|
||||||
} catch (ProviderHelper.NotFoundException e) {
|
} catch (ProviderHelper.NotFoundException e) {
|
||||||
Log.e(Constants.TAG, "PassphraseCacheService Passphrase for unknown key was requested!");
|
Log.e(Constants.TAG, "PassphraseCacheService Passphrase for unknown key was requested!");
|
||||||
@ -256,14 +274,16 @@ public class PassphraseCacheService extends Service {
|
|||||||
if (ACTION_PASSPHRASE_CACHE_ADD.equals(intent.getAction())) {
|
if (ACTION_PASSPHRASE_CACHE_ADD.equals(intent.getAction())) {
|
||||||
long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL);
|
long ttl = intent.getLongExtra(EXTRA_TTL, DEFAULT_TTL);
|
||||||
long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
|
long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
|
||||||
|
|
||||||
String passphrase = intent.getStringExtra(EXTRA_PASSPHRASE);
|
String passphrase = intent.getStringExtra(EXTRA_PASSPHRASE);
|
||||||
|
String primaryUserID = intent.getStringExtra(EXTRA_USERID);
|
||||||
|
|
||||||
Log.d(Constants.TAG,
|
Log.d(Constants.TAG,
|
||||||
"PassphraseCacheService Received ACTION_PASSPHRASE_CACHE_ADD intent in onStartCommand() with keyId: "
|
"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, passphrase);
|
mPassphraseCache.put(keyId, new CachedPassphrase(passphrase, primaryUserID));
|
||||||
|
|
||||||
if (ttl > 0) {
|
if (ttl > 0) {
|
||||||
// register new alarm with keyId for this passphrase
|
// register new alarm with keyId for this passphrase
|
||||||
@ -271,6 +291,9 @@ public class PassphraseCacheService extends Service {
|
|||||||
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
|
AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
|
||||||
am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, keyId));
|
am.set(AlarmManager.RTC_WAKEUP, triggerTime, buildIntent(this, keyId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNotifications();
|
||||||
|
|
||||||
} else if (ACTION_PASSPHRASE_CACHE_GET.equals(intent.getAction())) {
|
} else if (ACTION_PASSPHRASE_CACHE_GET.equals(intent.getAction())) {
|
||||||
long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
|
long keyId = intent.getLongExtra(EXTRA_KEY_ID, -1);
|
||||||
Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER);
|
Messenger messenger = intent.getParcelableExtra(EXTRA_MESSENGER);
|
||||||
@ -286,6 +309,17 @@ public class PassphraseCacheService extends Service {
|
|||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(Constants.TAG, "PassphraseCacheService Sending message failed", e);
|
Log.e(Constants.TAG, "PassphraseCacheService Sending message failed", e);
|
||||||
}
|
}
|
||||||
|
} else if (ACTION_PASSPHRASE_CACHE_CLEAR.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 {
|
} else {
|
||||||
Log.e(Constants.TAG, "PassphraseCacheService Intent or Intent Action not supported!");
|
Log.e(Constants.TAG, "PassphraseCacheService Intent or Intent Action not supported!");
|
||||||
}
|
}
|
||||||
@ -311,6 +345,74 @@ public class PassphraseCacheService extends Service {
|
|||||||
Log.d(Constants.TAG, "PassphraseCacheServic No passphrases remaining in memory, stopping service!");
|
Log.d(Constants.TAG, "PassphraseCacheServic No passphrases remaining in memory, stopping service!");
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateNotifications();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNotifications() {
|
||||||
|
NotificationManager notificationManager =
|
||||||
|
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
|
if(mPassphraseCache.size() > 0) {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
|
||||||
|
|
||||||
|
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()));
|
||||||
|
|
||||||
|
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
|
||||||
|
|
||||||
|
inboxStyle.setBigContentTitle(getString(R.string.passp_cache_notif_keys));
|
||||||
|
|
||||||
|
// 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_CLEAR);
|
||||||
|
builder.addAction(
|
||||||
|
R.drawable.abc_ic_clear_normal,
|
||||||
|
getString(R.string.passp_cache_notif_clear),
|
||||||
|
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(String.format(getString(R.string.passp_cache_notif_n_keys, mPassphraseCache.size())))
|
||||||
|
.setContentText(getString(R.string.passp_cache_notif_click_to_clear));
|
||||||
|
|
||||||
|
Intent intent = new Intent(getApplicationContext(), PassphraseCacheService.class);
|
||||||
|
intent.setAction(ACTION_PASSPHRASE_CACHE_CLEAR);
|
||||||
|
|
||||||
|
builder.setContentIntent(
|
||||||
|
PendingIntent.getService(
|
||||||
|
getApplicationContext(),
|
||||||
|
0,
|
||||||
|
intent,
|
||||||
|
PendingIntent.FLAG_UPDATE_CURRENT
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
notificationManager.notify(NOTIFICATION_ID, builder.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
notificationManager.cancel(NOTIFICATION_ID);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -341,4 +443,27 @@ public class PassphraseCacheService extends Service {
|
|||||||
|
|
||||||
private final IBinder mBinder = new PassphraseCacheBinder();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -54,6 +54,7 @@ import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
|
|||||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ChangeExpiryDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||||
@ -61,6 +62,7 @@ import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
|||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
public class EditKeyFragment extends LoaderFragment implements
|
public class EditKeyFragment extends LoaderFragment implements
|
||||||
LoaderManager.LoaderCallbacks<Cursor> {
|
LoaderManager.LoaderCallbacks<Cursor> {
|
||||||
@ -357,13 +359,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
|
case EditSubkeyDialogFragment.MESSAGE_CHANGE_EXPIRY:
|
||||||
// toggle
|
editSubkeyExpiry(keyId);
|
||||||
// if (mSaveKeyringParcel.changePrimaryUserId != null
|
|
||||||
// && mSaveKeyringParcel.changePrimaryUserId.equals(userId)) {
|
|
||||||
// mSaveKeyringParcel.changePrimaryUserId = null;
|
|
||||||
// } else {
|
|
||||||
// mSaveKeyringParcel.changePrimaryUserId = userId;
|
|
||||||
// }
|
|
||||||
break;
|
break;
|
||||||
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
|
case EditSubkeyDialogFragment.MESSAGE_REVOKE:
|
||||||
// toggle
|
// toggle
|
||||||
@ -391,6 +387,38 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void editSubkeyExpiry(final long keyId) {
|
||||||
|
Handler returnHandler = new Handler() {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message message) {
|
||||||
|
switch (message.what) {
|
||||||
|
case ChangeExpiryDialogFragment.MESSAGE_NEW_EXPIRY_DATE:
|
||||||
|
// toggle
|
||||||
|
// if (mSaveKeyringParcel.changePrimaryUserId != null
|
||||||
|
// && mSaveKeyringParcel.changePrimaryUserId.equals(userId)) {
|
||||||
|
// mSaveKeyringParcel.changePrimaryUserId = null;
|
||||||
|
// } else {
|
||||||
|
// mSaveKeyringParcel.changePrimaryUserId = userId;
|
||||||
|
// }
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
getLoaderManager().getLoader(LOADER_ID_SUBKEYS).forceLoad();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
final Messenger messenger = new Messenger(returnHandler);
|
||||||
|
|
||||||
|
DialogFragmentWorkaround.INTERFACE.runnableRunDelayed(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
ChangeExpiryDialogFragment dialogFragment =
|
||||||
|
ChangeExpiryDialogFragment.newInstance(messenger, new Date(), new Date());
|
||||||
|
|
||||||
|
dialogFragment.show(getActivity().getSupportFragmentManager(), "editSubkeyExpiryDialog");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void addUserId() {
|
private void addUserId() {
|
||||||
mUserIdsAddedAdapter.add(new UserIdsAddedAdapter.UserIdModel());
|
mUserIdsAddedAdapter.add(new UserIdsAddedAdapter.UserIdModel());
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,187 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.ui.dialog;
|
||||||
|
|
||||||
|
import android.app.DatePickerDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.support.v4.app.DialogFragment;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
|
import android.widget.DatePicker;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
|
public class ChangeExpiryDialogFragment extends DialogFragment {
|
||||||
|
private static final String ARG_MESSENGER = "messenger";
|
||||||
|
private static final String ARG_CREATION_DATE = "creation_date";
|
||||||
|
private static final String ARG_EXPIRY_DATE = "expiry_date";
|
||||||
|
|
||||||
|
public static final int MESSAGE_NEW_EXPIRY_DATE = 1;
|
||||||
|
public static final String MESSAGE_DATA_EXPIRY_DATE = "expiry_date";
|
||||||
|
|
||||||
|
private Messenger mMessenger;
|
||||||
|
private Calendar mCreationCal;
|
||||||
|
private Calendar mExpiryCal;
|
||||||
|
|
||||||
|
private int mDatePickerResultCount = 0;
|
||||||
|
private DatePickerDialog.OnDateSetListener mExpiryDateSetListener =
|
||||||
|
new DatePickerDialog.OnDateSetListener() {
|
||||||
|
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
|
||||||
|
// Note: Ignore results after the first one - android sends multiples.
|
||||||
|
if (mDatePickerResultCount++ == 0) {
|
||||||
|
Calendar selectedCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
|
selectedCal.set(year, monthOfYear, dayOfMonth);
|
||||||
|
if (mExpiryCal != null) {
|
||||||
|
long numDays = (selectedCal.getTimeInMillis() / 86400000)
|
||||||
|
- (mExpiryCal.getTimeInMillis() / 86400000);
|
||||||
|
if (numDays > 0) {
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
data.putSerializable(MESSAGE_DATA_EXPIRY_DATE, selectedCal.getTime());
|
||||||
|
sendMessageToHandler(MESSAGE_NEW_EXPIRY_DATE, data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
data.putSerializable(MESSAGE_DATA_EXPIRY_DATE, selectedCal.getTime());
|
||||||
|
sendMessageToHandler(MESSAGE_NEW_EXPIRY_DATE, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public class ExpiryDatePickerDialog extends DatePickerDialog {
|
||||||
|
|
||||||
|
public ExpiryDatePickerDialog(Context context, OnDateSetListener callBack,
|
||||||
|
int year, int monthOfYear, int dayOfMonth) {
|
||||||
|
super(context, callBack, year, monthOfYear, dayOfMonth);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set permanent title
|
||||||
|
public void setTitle(CharSequence title) {
|
||||||
|
super.setTitle(getContext().getString(R.string.expiry_date_dialog_title));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new instance of this dialog fragment
|
||||||
|
*/
|
||||||
|
public static ChangeExpiryDialogFragment newInstance(Messenger messenger,
|
||||||
|
Date creationDate, Date expiryDate) {
|
||||||
|
ChangeExpiryDialogFragment frag = new ChangeExpiryDialogFragment();
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putParcelable(ARG_MESSENGER, messenger);
|
||||||
|
args.putSerializable(ARG_CREATION_DATE, creationDate);
|
||||||
|
args.putSerializable(ARG_EXPIRY_DATE, expiryDate);
|
||||||
|
|
||||||
|
frag.setArguments(args);
|
||||||
|
|
||||||
|
return frag;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates dialog
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
mMessenger = getArguments().getParcelable(ARG_MESSENGER);
|
||||||
|
Date creationDate = (Date) getArguments().getSerializable(ARG_CREATION_DATE);
|
||||||
|
Date expiryDate = (Date) getArguments().getSerializable(ARG_EXPIRY_DATE);
|
||||||
|
|
||||||
|
mCreationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
|
mCreationCal.setTime(creationDate);
|
||||||
|
mExpiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
|
||||||
|
mExpiryCal.setTime(expiryDate);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Using custom DatePickerDialog which overrides the setTitle because
|
||||||
|
* the DatePickerDialog title is buggy (unix warparound bug).
|
||||||
|
* See: https://code.google.com/p/android/issues/detail?id=49066
|
||||||
|
*/
|
||||||
|
DatePickerDialog dialog = new ExpiryDatePickerDialog(getActivity(),
|
||||||
|
mExpiryDateSetListener, mExpiryCal.get(Calendar.YEAR), mExpiryCal.get(Calendar.MONTH),
|
||||||
|
mExpiryCal.get(Calendar.DAY_OF_MONTH));
|
||||||
|
mDatePickerResultCount = 0;
|
||||||
|
dialog.setCancelable(true);
|
||||||
|
dialog.setButton(Dialog.BUTTON_NEGATIVE,
|
||||||
|
getActivity().getString(R.string.btn_no_date),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
// Note: Ignore results after the first one - android sends multiples.
|
||||||
|
if (mDatePickerResultCount++ == 0) {
|
||||||
|
// none expiry dates corresponds to a null message
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
data.putSerializable(MESSAGE_DATA_EXPIRY_DATE, null);
|
||||||
|
sendMessageToHandler(MESSAGE_NEW_EXPIRY_DATE, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// setCalendarViewShown() is supported from API 11 onwards.
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
// Hide calendarView in tablets because of the unix warparound bug.
|
||||||
|
dialog.getDatePicker().setCalendarViewShown(false);
|
||||||
|
}
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
|
||||||
|
// will crash with IllegalArgumentException if we set a min date
|
||||||
|
// that is not before expiry
|
||||||
|
if (mCreationCal != null && mCreationCal.before(mExpiryCal)) {
|
||||||
|
dialog.getDatePicker().setMinDate(mCreationCal.getTime().getTime()
|
||||||
|
+ DateUtils.DAY_IN_MILLIS);
|
||||||
|
} else {
|
||||||
|
// When created date isn't available
|
||||||
|
dialog.getDatePicker().setMinDate(mExpiryCal.getTime().getTime()
|
||||||
|
+ DateUtils.DAY_IN_MILLIS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send message back to handler which is initialized in a activity
|
||||||
|
*
|
||||||
|
* @param what Message integer you want to send
|
||||||
|
*/
|
||||||
|
private void sendMessageToHandler(Integer what, Bundle data) {
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
msg.what = what;
|
||||||
|
if (data != null) {
|
||||||
|
msg.setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMessenger.send(msg);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.w(Constants.TAG, "Messenger is null!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -189,7 +189,8 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
|
|
||||||
// Early breakout if we are dealing with a symmetric key
|
// Early breakout if we are dealing with a symmetric key
|
||||||
if (secretRing == null) {
|
if (secretRing == null) {
|
||||||
PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric, passphrase);
|
PassphraseCacheService.addCachedPassphrase(activity, Constants.key.symmetric,
|
||||||
|
passphrase, getString(R.string.passp_cache_notif_pwd));
|
||||||
// also return passphrase back to activity
|
// also return passphrase back to activity
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putString(MESSAGE_DATA_PASSPHRASE, passphrase);
|
data.putString(MESSAGE_DATA_PASSPHRASE, passphrase);
|
||||||
@ -228,10 +229,18 @@ public class PassphraseDialogFragment extends DialogFragment implements OnEditor
|
|||||||
|
|
||||||
// cache the new passphrase
|
// cache the new passphrase
|
||||||
Log.d(Constants.TAG, "Everything okay! Caching entered 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, "adding of a passhrase failed", e);
|
||||||
|
}
|
||||||
|
|
||||||
if (unlockedSecretKey.getKeyId() != masterKeyId) {
|
if (unlockedSecretKey.getKeyId() != masterKeyId) {
|
||||||
PassphraseCacheService.addCachedPassphrase(
|
PassphraseCacheService.addCachedPassphrase(
|
||||||
activity, unlockedSecretKey.getKeyId(), passphrase);
|
activity, unlockedSecretKey.getKeyId(), passphrase,
|
||||||
|
unlockedSecretKey.getPrimaryUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// also return passphrase back to activity
|
// also return passphrase back to activity
|
||||||
|
@ -673,6 +673,13 @@
|
|||||||
<string name="msg_mf_unlock_error">Error unlocking keyring!</string>
|
<string name="msg_mf_unlock_error">Error unlocking keyring!</string>
|
||||||
<string name="msg_mf_unlock">Unlocking keyring</string>
|
<string name="msg_mf_unlock">Unlocking keyring</string>
|
||||||
|
|
||||||
|
<!-- PassphraseCache -->
|
||||||
|
<string name="passp_cache_notif_click_to_clear">Click to clear cached passphrases</string>
|
||||||
|
<string name="passp_cache_notif_n_keys">OpenKeychain has cached %d passphrases</string>
|
||||||
|
<string name="passp_cache_notif_keys">Cached Passphrases:</string>
|
||||||
|
<string name="passp_cache_notif_clear">Clear Cache</string>
|
||||||
|
<string name="passp_cache_notif_pwd">Password</string>
|
||||||
|
|
||||||
<!-- unsorted -->
|
<!-- unsorted -->
|
||||||
<string name="section_certifier_id">Certifier</string>
|
<string name="section_certifier_id">Certifier</string>
|
||||||
<string name="section_cert">Certificate Details</string>
|
<string name="section_cert">Certificate Details</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user