ditch CachedPublicKeyRing, and some cleanup
This commit is contained in:
@@ -34,11 +34,10 @@ import android.widget.ImageView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.operations.results.CertifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
@@ -47,7 +46,6 @@ import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
public class CertifyKeyFragment
|
||||
@@ -68,15 +66,10 @@ public class CertifyKeyFragment
|
||||
long certifyKeyId = getActivity().getIntent()
|
||||
.getLongExtra(CertifyKeyActivity.EXTRA_CERTIFY_KEY_ID, Constants.key.none);
|
||||
if (certifyKeyId != Constants.key.none) {
|
||||
try {
|
||||
CachedPublicKeyRing key = (KeyRepository
|
||||
.create(getContext()))
|
||||
.getCachedPublicKeyRing(certifyKeyId);
|
||||
if (key.canCertify()) {
|
||||
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);
|
||||
}
|
||||
} catch (NotFoundException e) {
|
||||
Timber.e(e, "certify certify check failed");
|
||||
KeyRepository keyRepository = KeyRepository.create(getContext());
|
||||
UnifiedKeyInfo unifiedKeyInfo = keyRepository.getUnifiedKeyInfo(certifyKeyId);
|
||||
if (unifiedKeyInfo != null && unifiedKeyInfo.can_certify()) {
|
||||
mCertifyKeySpinner.setPreSelectedKeyId(certifyKeyId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.sufficientlysecure.keychain.operations.results.EditKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.service.ChangeUnlockParcel;
|
||||
@@ -414,8 +413,8 @@ public class CreateKeyFinalFragment extends Fragment {
|
||||
|
||||
SaveKeyringParcel.Builder builder;
|
||||
try {
|
||||
CachedPublicKeyRing key = keyRepository.getCachedPublicKeyRing(saveKeyResult.mMasterKeyId);
|
||||
builder = SaveKeyringParcel.buildChangeKeyringParcel(saveKeyResult.mMasterKeyId, key.getFingerprint());
|
||||
byte[] fingerprint = keyRepository.getFingerprintByKeyId(saveKeyResult.mMasterKeyId);
|
||||
builder = SaveKeyringParcel.buildChangeKeyringParcel(saveKeyResult.mMasterKeyId, fingerprint);
|
||||
} catch (NotFoundException e) {
|
||||
Timber.e("Key that should be moved to Security Token not found in database!");
|
||||
return;
|
||||
|
||||
@@ -31,8 +31,8 @@ import android.widget.ViewAnimator;
|
||||
import com.tokenautocomplete.TokenCompleteTextView.TokenListener;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter.KeyItem;
|
||||
@@ -136,16 +136,12 @@ public class EncryptModeAsymmetricFragment extends EncryptModeFragment {
|
||||
*/
|
||||
private void preselectKeys(Long signatureKeyId, long[] encryptionKeyIds) {
|
||||
if (signatureKeyId != null) {
|
||||
try {
|
||||
CachedPublicKeyRing keyring = mKeyRepository.getCachedPublicKeyRing(signatureKeyId);
|
||||
if (keyring.hasAnySecret()) {
|
||||
mSignKeySpinner.setPreSelectedKeyId(signatureKeyId);
|
||||
}
|
||||
} catch (NotFoundException e) {
|
||||
Timber.e(e, "key not found for signing!");
|
||||
Notify.create(getActivity(), getString(R.string.error_preselect_sign_key,
|
||||
KeyFormattingUtils.beautifyKeyId(signatureKeyId)),
|
||||
Style.ERROR).show();
|
||||
UnifiedKeyInfo unifiedKeyInfo = mKeyRepository.getUnifiedKeyInfo(signatureKeyId);
|
||||
if (unifiedKeyInfo == null) {
|
||||
String beautifyKeyId = KeyFormattingUtils.beautifyKeyId(signatureKeyId);
|
||||
Notify.create(getActivity(), getString(R.string.error_preselect_sign_key, beautifyKeyId), Style.ERROR).show();
|
||||
} else if (unifiedKeyInfo.has_any_secret()) {
|
||||
mSignKeySpinner.setPreSelectedKeyId(signatureKeyId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,13 +52,13 @@ import android.widget.ViewAnimator;
|
||||
import org.openintents.openpgp.util.OpenPgpUtils;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||
@@ -285,11 +285,14 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
|
||||
KeyRepository keyRepository = KeyRepository.create(getContext());
|
||||
Long masterKeyId = keyRepository.getMasterKeyIdBySubkeyId(subKeyId);
|
||||
CachedPublicKeyRing cachedPublicKeyRing = keyRepository.getCachedPublicKeyRing(masterKeyId);
|
||||
UnifiedKeyInfo unifiedKeyInfo = keyRepository.getUnifiedKeyInfo(masterKeyId);
|
||||
if (unifiedKeyInfo == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
// yes the inner try/catch block is necessary, otherwise the final variable
|
||||
// above can't be statically verified to have been set in all cases because
|
||||
// the catch clause doesn't return.
|
||||
String mainUserId = cachedPublicKeyRing.getPrimaryUserIdWithFallback();
|
||||
String mainUserId = unifiedKeyInfo.user_id();
|
||||
OpenPgpUtils.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId);
|
||||
if (mainUserIdSplit.name != null) {
|
||||
userId = mainUserIdSplit.name;
|
||||
@@ -314,14 +317,10 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
throw new AssertionError("Unhandled SecretKeyType (should not happen)");
|
||||
}
|
||||
}
|
||||
} catch (KeyRepository.NotFoundException e) {
|
||||
} catch (NotFoundException e) {
|
||||
alert.setTitle(R.string.title_key_not_found);
|
||||
alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId()));
|
||||
alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
alert.setPositiveButton(android.R.string.ok, (dialog, which) -> dismiss());
|
||||
alert.setCancelable(false);
|
||||
return alert.create();
|
||||
}
|
||||
@@ -595,13 +594,9 @@ public class PassphraseDialogActivity extends FragmentActivity {
|
||||
} else {
|
||||
Timber.d("Caching entered passphrase");
|
||||
|
||||
try {
|
||||
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
||||
unlockedKey.getRing().getMasterKeyId(), unlockedKey.getKeyId(), passphrase,
|
||||
unlockedKey.getRing().getPrimaryUserIdWithFallback(), timeToLiveSeconds);
|
||||
} catch (PgpKeyNotFoundException e) {
|
||||
Timber.e(e, "adding of a passphrase failed");
|
||||
}
|
||||
PassphraseCacheService.addCachedPassphrase(getActivity(),
|
||||
unlockedKey.getRing().getMasterKeyId(), unlockedKey.getKeyId(), passphrase,
|
||||
unlockedKey.getRing().getPrimaryUserIdWithFallback(), timeToLiveSeconds);
|
||||
}
|
||||
|
||||
finishCaching(passphrase, unlockedKey.getKeyId());
|
||||
|
||||
@@ -58,7 +58,6 @@ import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey;
|
||||
import org.sufficientlysecure.keychain.pgp.SshPublicKey;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.TemporaryFileProvider;
|
||||
import org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.ViewKeyAdvViewModel;
|
||||
@@ -140,14 +139,13 @@ public class ViewKeyAdvShareFragment extends Fragment {
|
||||
}
|
||||
|
||||
private String getShareKeyContent(boolean asSshKey)
|
||||
throws PgpKeyNotFoundException, KeyRepository.NotFoundException, IOException, PgpGeneralException,
|
||||
NoSuchAlgorithmException {
|
||||
throws KeyRepository.NotFoundException, IOException, PgpGeneralException, NoSuchAlgorithmException {
|
||||
|
||||
KeyRepository keyRepository = KeyRepository.create(requireContext());
|
||||
|
||||
String content;
|
||||
if (asSshKey) {
|
||||
long authSubKeyId = keyRepository.getCachedPublicKeyRing(unifiedKeyInfo.master_key_id()).getAuthenticationId();
|
||||
long authSubKeyId = unifiedKeyInfo.has_auth_key_int();
|
||||
CanonicalizedPublicKey publicKey = keyRepository.getCanonicalizedPublicKeyRing(unifiedKeyInfo.master_key_id())
|
||||
.getPublicKey(authSubKeyId);
|
||||
SshPublicKey sshPublicKey = new SshPublicKey(publicKey);
|
||||
@@ -224,7 +222,7 @@ public class ViewKeyAdvShareFragment extends Fragment {
|
||||
} catch (PgpGeneralException | IOException | NoSuchAlgorithmException e) {
|
||||
Timber.e(e, "error processing key!");
|
||||
Notify.create(activity, R.string.error_key_processing, Notify.Style.ERROR).show();
|
||||
} catch (PgpKeyNotFoundException | KeyRepository.NotFoundException e) {
|
||||
} catch (KeyRepository.NotFoundException e) {
|
||||
Timber.e(e, "key not found!");
|
||||
Notify.create(activity, R.string.error_key_not_found, Notify.Style.ERROR).show();
|
||||
}
|
||||
|
||||
@@ -44,8 +44,6 @@ import org.sufficientlysecure.keychain.operations.ImportOperation;
|
||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing.VerificationStatus;
|
||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper;
|
||||
@@ -88,16 +86,15 @@ public class ImportKeysAdapter extends RecyclerView.Adapter<ImportKeysAdapter.Vi
|
||||
KeyState keyState = new KeyState();
|
||||
long keyId = KeyFormattingUtils.convertKeyIdHexToKeyId(entry.getKeyIdHex());
|
||||
try {
|
||||
KeyRing keyRing;
|
||||
VerificationStatus verified;
|
||||
if (entry.isSecretKey()) {
|
||||
keyRing = mKeyRepository.getCanonicalizedSecretKeyRing(keyId);
|
||||
verified = mKeyRepository.getCanonicalizedSecretKeyRing(keyId).getVerified();
|
||||
} else {
|
||||
keyRing = mKeyRepository.getCachedPublicKeyRing(keyId);
|
||||
verified = mKeyRepository.getUnifiedKeyInfo(keyId).verified();
|
||||
}
|
||||
keyState.mAlreadyPresent = true;
|
||||
VerificationStatus verified = keyRing.getVerified();
|
||||
keyState.mVerified = verified != null && verified != VerificationStatus.UNVERIFIED;
|
||||
} catch (KeyRepository.NotFoundException | PgpKeyNotFoundException ignored) {
|
||||
} catch (KeyRepository.NotFoundException ignored) {
|
||||
}
|
||||
|
||||
mKeyStates[i] = keyState;
|
||||
|
||||
@@ -382,7 +382,7 @@ public class LinkedIdViewFragment extends CryptoOperationFragment implements OnB
|
||||
|
||||
byte[] fingerprint;
|
||||
try {
|
||||
fingerprint = KeyRepository.create(activity).getCachedPublicKeyRing(masterKeyId).getFingerprint();
|
||||
fingerprint = KeyRepository.create(activity).getFingerprintByKeyId(masterKeyId);
|
||||
} catch (NotFoundException e) {
|
||||
throw new IllegalStateException("Key to verify linked id for must exist in db!");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user