Merge branch 'master' of github.com:open-keychain/open-keychain
This commit is contained in:
@@ -381,6 +381,10 @@ public class PgpKeyOperation {
|
|||||||
* This is a natural workflow since pgp keyrings are immutable data structures: Old semantics
|
* This is a natural workflow since pgp keyrings are immutable data structures: Old semantics
|
||||||
* are changed by adding new certificates, which implicitly override older certificates.
|
* are changed by adding new certificates, which implicitly override older certificates.
|
||||||
*
|
*
|
||||||
|
* Note that this method does not care about any "special" type of master key. If unlocking
|
||||||
|
* with a passphrase fails, the operation will fail with an unlocking error. More specific
|
||||||
|
* handling of errors should be done in UI code!
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public EditKeyResult modifySecretKeyRing(CanonicalizedSecretKeyRing wsKR, SaveKeyringParcel saveParcel,
|
public EditKeyResult modifySecretKeyRing(CanonicalizedSecretKeyRing wsKR, SaveKeyringParcel saveParcel,
|
||||||
String passphrase) {
|
String passphrase) {
|
||||||
|
|||||||
@@ -427,6 +427,12 @@ public class OperationResultParcel implements Parcelable {
|
|||||||
MSG_CON_SUCCESS (R.string.msg_con_success),
|
MSG_CON_SUCCESS (R.string.msg_con_success),
|
||||||
MSG_CON_WARN_DELETE_PUBLIC (R.string.msg_con_warn_delete_public),
|
MSG_CON_WARN_DELETE_PUBLIC (R.string.msg_con_warn_delete_public),
|
||||||
MSG_CON_WARN_DELETE_SECRET (R.string.msg_con_warn_delete_secret),
|
MSG_CON_WARN_DELETE_SECRET (R.string.msg_con_warn_delete_secret),
|
||||||
|
|
||||||
|
// messages used in UI code
|
||||||
|
MSG_EK_ERROR_DIVERT (R.string.msg_ek_error_divert),
|
||||||
|
MSG_EK_ERROR_DUMMY (R.string.msg_ek_error_dummy),
|
||||||
|
MSG_EK_ERROR_NOT_FOUND (R.string.msg_ek_error_not_found),
|
||||||
|
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int mMsgId;
|
private final int mMsgId;
|
||||||
|
|||||||
@@ -33,13 +33,69 @@ import com.github.johnpersano.supertoasts.util.Style;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
|
||||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||||
|
|
||||||
public abstract class OperationResults {
|
public abstract class OperationResults {
|
||||||
|
|
||||||
|
/** This is a simple subclass meant to contain only a single log message. This log
|
||||||
|
* message is also shown without a log button in the createNotify SuperToast. */
|
||||||
|
public static class SingletonResult extends OperationResultParcel {
|
||||||
|
|
||||||
|
/** Construct from a parcel - trivial because we have no extra data. */
|
||||||
|
public SingletonResult(Parcel source) {
|
||||||
|
super(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingletonResult(int result, LogLevel level, LogType reason) {
|
||||||
|
super(result, new OperationLog());
|
||||||
|
// Prepare the log
|
||||||
|
mLog.add(level, reason, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SuperCardToast createNotify(final Activity activity) {
|
||||||
|
|
||||||
|
// there is exactly one error msg - use that one
|
||||||
|
String str = activity.getString(mLog.iterator().next().mType.getMsgId());
|
||||||
|
int color;
|
||||||
|
|
||||||
|
// Determine color by result type
|
||||||
|
if (cancelled()) {
|
||||||
|
color = Style.RED;
|
||||||
|
} else if (success()) {
|
||||||
|
if (getLog().containsWarnings()) {
|
||||||
|
color = Style.ORANGE;
|
||||||
|
} else {
|
||||||
|
color = Style.GREEN;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
color = Style.RED;
|
||||||
|
}
|
||||||
|
|
||||||
|
SuperCardToast toast = new SuperCardToast(activity, SuperToast.Type.STANDARD,
|
||||||
|
Style.getStyle(color, SuperToast.Animations.POPUP));
|
||||||
|
toast.setText(str);
|
||||||
|
toast.setDuration(SuperToast.Duration.EXTRA_LONG);
|
||||||
|
toast.setIndeterminate(false);
|
||||||
|
toast.setSwipeToDismiss(true);
|
||||||
|
return toast;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Creator<SingletonResult> CREATOR = new Creator<SingletonResult>() {
|
||||||
|
public SingletonResult createFromParcel(final Parcel source) {
|
||||||
|
return new SingletonResult(source);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingletonResult[] newArray(final int size) {
|
||||||
|
return new SingletonResult[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static class ImportKeyResult extends OperationResultParcel {
|
public static class ImportKeyResult extends OperationResultParcel {
|
||||||
|
|
||||||
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ import android.view.View.OnClickListener;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@@ -46,9 +45,13 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
|||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||||
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.provider.ProviderHelper.NotFoundException;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
||||||
import org.sufficientlysecure.keychain.service.OperationResultParcel;
|
import org.sufficientlysecure.keychain.service.OperationResultParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogLevel;
|
||||||
|
import org.sufficientlysecure.keychain.service.OperationResultParcel.LogType;
|
||||||
|
import org.sufficientlysecure.keychain.service.OperationResults.SingletonResult;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
|
||||||
@@ -169,15 +172,26 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
Uri secretUri = KeychainContract.KeyRings.buildUnifiedKeyRingUri(mDataUri);
|
||||||
CachedPublicKeyRing keyRing =
|
CachedPublicKeyRing keyRing =
|
||||||
new ProviderHelper(getActivity()).getCachedPublicKeyRing(secretUri);
|
new ProviderHelper(getActivity()).getCachedPublicKeyRing(secretUri);
|
||||||
|
long masterKeyId = keyRing.getMasterKeyId();
|
||||||
|
|
||||||
mSaveKeyringParcel = new SaveKeyringParcel(keyRing.getMasterKeyId(),
|
// check if this is a master secret key we can work with
|
||||||
keyRing.getFingerprint());
|
switch (keyRing.getSecretKeyType(masterKeyId)) {
|
||||||
|
case GNU_DUMMY:
|
||||||
|
finishWithError(LogType.MSG_EK_ERROR_DUMMY);
|
||||||
|
return;
|
||||||
|
case DIVERT_TO_CARD:
|
||||||
|
finishWithError(LogType.MSG_EK_ERROR_DIVERT);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
mSaveKeyringParcel = new SaveKeyringParcel(masterKeyId, keyRing.getFingerprint());
|
||||||
mPrimaryUserId = keyRing.getPrimaryUserIdWithFallback();
|
mPrimaryUserId = keyRing.getPrimaryUserIdWithFallback();
|
||||||
|
|
||||||
|
} catch (NotFoundException e) {
|
||||||
|
finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND);
|
||||||
|
return;
|
||||||
} catch (PgpGeneralException e) {
|
} catch (PgpGeneralException e) {
|
||||||
Log.e(Constants.TAG, "PgpGeneralException", e);
|
finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND);
|
||||||
Toast.makeText(getActivity(), R.string.error_no_secret_key_found, Toast.LENGTH_SHORT).show();
|
|
||||||
getActivity().finish();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,9 +199,7 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
mCurrentPassphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
mCurrentPassphrase = PassphraseCacheService.getCachedPassphrase(getActivity(),
|
||||||
mSaveKeyringParcel.mMasterKeyId);
|
mSaveKeyringParcel.mMasterKeyId);
|
||||||
} catch (PassphraseCacheService.KeyNotFoundException e) {
|
} catch (PassphraseCacheService.KeyNotFoundException e) {
|
||||||
Log.e(Constants.TAG, "Key not found!", e);
|
finishWithError(LogType.MSG_EK_ERROR_NOT_FOUND);
|
||||||
Toast.makeText(getActivity(), R.string.error_no_secret_key_found, Toast.LENGTH_SHORT).show();
|
|
||||||
getActivity().finish();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,4 +576,18 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
getActivity().startService(intent);
|
getActivity().startService(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Closes this activity, returning a result parcel with a single error log entry. */
|
||||||
|
void finishWithError(LogType reason) {
|
||||||
|
|
||||||
|
// Prepare an intent with an EXTRA_RESULT
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra(OperationResultParcel.EXTRA_RESULT,
|
||||||
|
new SingletonResult(SingletonResult.RESULT_ERROR, LogLevel.ERROR, reason));
|
||||||
|
|
||||||
|
// Finish with result
|
||||||
|
getActivity().setResult(EditKeyActivity.RESULT_OK, intent);
|
||||||
|
getActivity().finish();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -756,6 +756,11 @@
|
|||||||
<string name="msg_con_warn_delete_public">"Exception deleting public cache file"</string>
|
<string name="msg_con_warn_delete_public">"Exception deleting public cache file"</string>
|
||||||
<string name="msg_con_warn_delete_secret">"Exception deleting secret cache file"</string>
|
<string name="msg_con_warn_delete_secret">"Exception deleting secret cache file"</string>
|
||||||
|
|
||||||
|
<!-- Other messages used in OperationLogs -->
|
||||||
|
<string name="msg_ek_error_divert">"Editing of nfc keys is not (yet) supported!"</string>
|
||||||
|
<string name="msg_ek_error_dummy">"Cannot edit keyring with stripped master key!"</string>
|
||||||
|
<string name="msg_ek_error_not_found">"Key not found!"</string>
|
||||||
|
|
||||||
<!-- PassphraseCache -->
|
<!-- PassphraseCache -->
|
||||||
<string name="passp_cache_notif_click_to_clear">"Click to clear cached passphrases"</string>
|
<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_n_keys">"OpenKeychain has cached %d passphrases"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user