ditch CachedPublicKeyRing, and some cleanup
This commit is contained in:
@@ -52,6 +52,7 @@ import org.openintents.openpgp.OpenPgpSignatureResult;
|
||||
import org.openintents.openpgp.OpenPgpSignatureResult.AutocryptPeerResult;
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.operations.BackupOperation;
|
||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||
@@ -68,7 +69,6 @@ import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.SecurityProblem;
|
||||
import org.sufficientlysecure.keychain.provider.ApiAppDao;
|
||||
import org.sufficientlysecure.keychain.provider.AutocryptPeerDao;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainExternalContract.AutocryptStatus;
|
||||
@@ -742,17 +742,16 @@ public class OpenPgpService extends Service {
|
||||
result.putExtra(OpenPgpApi.RESULT_SIGN_KEY_ID, signKeyId);
|
||||
|
||||
if (signKeyId != Constants.key.none) {
|
||||
try {
|
||||
CachedPublicKeyRing cachedPublicKeyRing = mKeyRepository.getCachedPublicKeyRing(signKeyId);
|
||||
String userId = cachedPublicKeyRing.getPrimaryUserId();
|
||||
long creationTime = cachedPublicKeyRing.getCreationTime() * 1000;
|
||||
|
||||
result.putExtra(OpenPgpApi.RESULT_PRIMARY_USER_ID, userId);
|
||||
result.putExtra(OpenPgpApi.RESULT_KEY_CREATION_TIME, creationTime);
|
||||
} catch (NotFoundException e) {
|
||||
Timber.e(e, "Error loading key info");
|
||||
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||
UnifiedKeyInfo unifiedKeyInfo = mKeyRepository.getUnifiedKeyInfo(signKeyId);
|
||||
if (unifiedKeyInfo == null) {
|
||||
Timber.e("Error loading key info");
|
||||
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, "Signing key not found!");
|
||||
}
|
||||
String userId = unifiedKeyInfo.user_id();
|
||||
long creationTime = unifiedKeyInfo.creation() * 1000;
|
||||
|
||||
result.putExtra(OpenPgpApi.RESULT_PRIMARY_USER_ID, userId);
|
||||
result.putExtra(OpenPgpApi.RESULT_KEY_CREATION_TIME, creationTime);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -40,13 +40,13 @@ import org.openintents.ssh.authentication.response.PublicKeyResponse;
|
||||
import org.openintents.ssh.authentication.response.SigningResponse;
|
||||
import org.openintents.ssh.authentication.response.SshPublicKeyResponse;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel;
|
||||
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.ApiAppDao;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
@@ -368,18 +368,19 @@ public class SshAuthenticationService extends Service {
|
||||
|
||||
private CanonicalizedPublicKey getPublicKey(long masterKeyId) throws NotFoundException {
|
||||
KeyRepository keyRepository = KeyRepository.create(getApplicationContext());
|
||||
long authSubKeyId = keyRepository.getCachedPublicKeyRing(masterKeyId)
|
||||
.getAuthenticationId();
|
||||
return keyRepository.getCanonicalizedPublicKeyRing(masterKeyId)
|
||||
.getPublicKey(authSubKeyId);
|
||||
UnifiedKeyInfo unifiedKeyInfo = keyRepository.getUnifiedKeyInfo(masterKeyId);
|
||||
if (unifiedKeyInfo == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return keyRepository.getCanonicalizedPublicKeyRing(masterKeyId).getPublicKey(unifiedKeyInfo.has_auth_key_int());
|
||||
}
|
||||
|
||||
private String getDescription(long masterKeyId) throws NotFoundException {
|
||||
CachedPublicKeyRing cachedPublicKeyRing = mKeyRepository.getCachedPublicKeyRing(masterKeyId);
|
||||
UnifiedKeyInfo unifiedKeyInfo = mKeyRepository.getUnifiedKeyInfo(masterKeyId);
|
||||
|
||||
String description = "";
|
||||
long authSubKeyId = mKeyRepository.getSecretAuthenticationId(masterKeyId);
|
||||
description += cachedPublicKeyRing.getPrimaryUserId();
|
||||
description += unifiedKeyInfo.user_id();
|
||||
description += " (" + Long.toHexString(authSubKeyId) + ")";
|
||||
|
||||
return description;
|
||||
|
||||
@@ -152,8 +152,8 @@ public class RequestKeyPermissionActivity extends FragmentActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayKeyInfo(UserId userId) {
|
||||
keyUserIdView.setText(userId.name);
|
||||
public void displayKeyInfo(String userIdName) {
|
||||
keyUserIdView.setText(userIdName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -25,12 +25,11 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpUtils.UserId;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.model.SubKey.UnifiedKeyInfo;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
||||
import org.sufficientlysecure.keychain.provider.ApiAppDao;
|
||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||
import org.sufficientlysecure.keychain.remote.ApiPermissionHelper;
|
||||
@@ -94,18 +93,16 @@ class RequestKeyPermissionPresenter {
|
||||
}
|
||||
|
||||
private void setRequestedMasterKeyId(long[] subKeyIds) throws PgpKeyNotFoundException {
|
||||
CachedPublicKeyRing secretKeyRingOrPublicFallback = findSecretKeyRingOrPublicFallback(subKeyIds);
|
||||
UnifiedKeyInfo secretKeyRingOrPublicFallback = findSecretKeyRingOrPublicFallback(subKeyIds);
|
||||
|
||||
if (secretKeyRingOrPublicFallback == null) {
|
||||
throw new PgpKeyNotFoundException("No key found among requested!");
|
||||
}
|
||||
|
||||
this.masterKeyId = secretKeyRingOrPublicFallback.getMasterKeyId();
|
||||
masterKeyId = secretKeyRingOrPublicFallback.master_key_id();
|
||||
view.displayKeyInfo(secretKeyRingOrPublicFallback.name());
|
||||
|
||||
UserId userId = secretKeyRingOrPublicFallback.getSplitPrimaryUserIdWithFallback();
|
||||
view.displayKeyInfo(userId);
|
||||
|
||||
if (secretKeyRingOrPublicFallback.hasAnySecret()) {
|
||||
if (secretKeyRingOrPublicFallback.has_any_secret()) {
|
||||
view.switchToLayoutRequestKeyChoice();
|
||||
} else {
|
||||
view.switchToLayoutNoSecret();
|
||||
@@ -113,22 +110,22 @@ class RequestKeyPermissionPresenter {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private CachedPublicKeyRing findSecretKeyRingOrPublicFallback(long[] subKeyIds) {
|
||||
CachedPublicKeyRing publicFallbackRing = null;
|
||||
private UnifiedKeyInfo findSecretKeyRingOrPublicFallback(long[] subKeyIds) {
|
||||
UnifiedKeyInfo publicFallbackRing = null;
|
||||
for (long candidateSubKeyId : subKeyIds) {
|
||||
try {
|
||||
Long masterKeyId = keyRepository.getMasterKeyIdBySubkeyId(candidateSubKeyId);
|
||||
if (masterKeyId == null) {
|
||||
continue;
|
||||
}
|
||||
CachedPublicKeyRing cachedPublicKeyRing = keyRepository.getCachedPublicKeyRing(masterKeyId);
|
||||
UnifiedKeyInfo unifiedKeyInfo = keyRepository.getUnifiedKeyInfo(masterKeyId);
|
||||
|
||||
SecretKeyType secretKeyType = keyRepository.getSecretKeyType(candidateSubKeyId);
|
||||
if (secretKeyType.isUsable()) {
|
||||
return cachedPublicKeyRing;
|
||||
return unifiedKeyInfo;
|
||||
}
|
||||
if (publicFallbackRing == null) {
|
||||
publicFallbackRing = cachedPublicKeyRing;
|
||||
publicFallbackRing = unifiedKeyInfo;
|
||||
}
|
||||
} catch (NotFoundException e) {
|
||||
// no matter
|
||||
@@ -180,7 +177,7 @@ class RequestKeyPermissionPresenter {
|
||||
void setTitleText(String text);
|
||||
void setTitleClientIcon(Drawable drawable);
|
||||
|
||||
void displayKeyInfo(UserId userId);
|
||||
void displayKeyInfo(String userIdName);
|
||||
|
||||
void finish();
|
||||
void finishAsCancelled();
|
||||
|
||||
Reference in New Issue
Block a user