token-import: look up keys locally by all fingerprints
This commit is contained in:
@@ -922,7 +922,8 @@ public abstract class OperationResult implements Parcelable {
|
|||||||
MSG_RET_LOCAL_SEARCH(LogLevel.DEBUG, R.string.msg_ret_local_search),
|
MSG_RET_LOCAL_SEARCH(LogLevel.DEBUG, R.string.msg_ret_local_search),
|
||||||
MSG_RET_LOCAL_FP_MATCH (LogLevel.DEBUG, R.string.msg_ret_local_fp_match),
|
MSG_RET_LOCAL_FP_MATCH (LogLevel.DEBUG, R.string.msg_ret_local_fp_match),
|
||||||
MSG_RET_LOCAL_FP_MISMATCH (LogLevel.ERROR, R.string.msg_ret_local_fp_mismatch),
|
MSG_RET_LOCAL_FP_MISMATCH (LogLevel.ERROR, R.string.msg_ret_local_fp_mismatch),
|
||||||
MSG_RET_LOCAL_NOT_FOUND (LogLevel.ERROR, R.string.msg_ret_local_not_found),
|
MSG_RET_LOCAL_NOT_FOUND (LogLevel.DEBUG, R.string.msg_ret_local_not_found),
|
||||||
|
MSG_RET_LOCAL_NONE_FOUND (LogLevel.ERROR, R.string.msg_ret_local_none_found),
|
||||||
MSG_RET_LOCAL_OK (LogLevel.OK, R.string.msg_ret_local_ok),
|
MSG_RET_LOCAL_OK (LogLevel.OK, R.string.msg_ret_local_ok),
|
||||||
MSG_RET_LOCAL_SECRET (LogLevel.INFO, R.string.msg_ret_local_secret),
|
MSG_RET_LOCAL_SECRET (LogLevel.INFO, R.string.msg_ret_local_secret),
|
||||||
MSG_RET_LOCAL_START (LogLevel.START, R.string.msg_ret_local_start),
|
MSG_RET_LOCAL_START (LogLevel.START, R.string.msg_ret_local_start),
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
|||||||
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
import org.sufficientlysecure.keychain.provider.CachedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
import org.sufficientlysecure.keychain.provider.KeyRepository;
|
||||||
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
import org.sufficientlysecure.keychain.provider.KeyRepository.NotFoundException;
|
||||||
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.ui.token.PublicKeyRetrievalLoader.KeyRetrievalResult;
|
import org.sufficientlysecure.keychain.ui.token.PublicKeyRetrievalLoader.KeyRetrievalResult;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
@@ -102,44 +103,55 @@ public abstract class PublicKeyRetrievalLoader extends AsyncTaskLoader<KeyRetrie
|
|||||||
@Override
|
@Override
|
||||||
public KeyRetrievalResult loadInBackground() {
|
public KeyRetrievalResult loadInBackground() {
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
try {
|
log.add(LogType.MSG_RET_LOCAL_START, 0);
|
||||||
log.add(LogType.MSG_RET_LOCAL_START, 0);
|
|
||||||
|
|
||||||
// TODO check other fingerprints
|
for (byte[] fingerprint : fingerprints) {
|
||||||
long masterKeyId = KeyFormattingUtils.getKeyIdFromFingerprint(fingerprints[0]);
|
long keyId = KeyFormattingUtils.getKeyIdFromFingerprint(fingerprint);
|
||||||
log.add(LogType.MSG_RET_LOCAL_SEARCH, 1, KeyFormattingUtils.convertKeyIdToHex(masterKeyId));
|
if (keyId == 0L) {
|
||||||
CachedPublicKeyRing cachedPublicKeyRing = keyRepository.getCachedPublicKeyRing(masterKeyId);
|
continue;
|
||||||
|
|
||||||
if (!Arrays.equals(fingerprints[0], cachedPublicKeyRing.getFingerprint())) {
|
|
||||||
log.add(LogType.MSG_RET_LOCAL_FP_MISMATCH, 1);
|
|
||||||
return KeyRetrievalResult.createWithError(log);
|
|
||||||
} else {
|
|
||||||
log.add(LogType.MSG_RET_LOCAL_FP_MATCH, 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (cachedPublicKeyRing.getSecretKeyType(masterKeyId)) {
|
log.add(LogType.MSG_RET_LOCAL_SEARCH, 1, KeyFormattingUtils.convertKeyIdToHex(keyId));
|
||||||
case PASSPHRASE:
|
try {
|
||||||
case PASSPHRASE_EMPTY: {
|
CachedPublicKeyRing cachedPublicKeyRing = keyRepository.getCachedPublicKeyRing(
|
||||||
log.add(LogType.MSG_RET_LOCAL_SECRET, 1);
|
KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(keyId)
|
||||||
log.add(LogType.MSG_RET_LOCAL_OK, 1);
|
);
|
||||||
return KeyRetrievalResult.createWithMasterKeyIdAndSecretAvailable(log, masterKeyId);
|
|
||||||
}
|
|
||||||
|
|
||||||
case GNU_DUMMY:
|
long masterKeyId = cachedPublicKeyRing.getMasterKeyId();
|
||||||
case DIVERT_TO_CARD:
|
// TODO check fingerprint
|
||||||
case UNAVAILABLE: {
|
// if (!Arrays.equals(fingerprints, cachedPublicKeyRing.getFingerprint())) {
|
||||||
log.add(LogType.MSG_RET_LOCAL_OK, 1);
|
// log.add(LogType.MSG_RET_LOCAL_FP_MISMATCH, 1);
|
||||||
return KeyRetrievalResult.createWithMasterKeyId(log, masterKeyId);
|
// return KeyRetrievalResult.createWithError(log);
|
||||||
}
|
// } else {
|
||||||
|
// log.add(LogType.MSG_RET_LOCAL_FP_MATCH, 1);
|
||||||
|
// }
|
||||||
|
|
||||||
default: {
|
switch (cachedPublicKeyRing.getSecretKeyType(keyId)) {
|
||||||
throw new IllegalStateException("Unhandled SecretKeyType!");
|
case PASSPHRASE:
|
||||||
|
case PASSPHRASE_EMPTY: {
|
||||||
|
log.add(LogType.MSG_RET_LOCAL_SECRET, 1);
|
||||||
|
log.add(LogType.MSG_RET_LOCAL_OK, 1);
|
||||||
|
return KeyRetrievalResult.createWithMasterKeyIdAndSecretAvailable(log, masterKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
case GNU_DUMMY:
|
||||||
|
case DIVERT_TO_CARD:
|
||||||
|
case UNAVAILABLE: {
|
||||||
|
log.add(LogType.MSG_RET_LOCAL_OK, 1);
|
||||||
|
return KeyRetrievalResult.createWithMasterKeyId(log, masterKeyId);
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
throw new IllegalStateException("Unhandled SecretKeyType!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (PgpKeyNotFoundException | NotFoundException e) {
|
||||||
|
log.add(LogType.MSG_RET_LOCAL_NOT_FOUND, 2);
|
||||||
}
|
}
|
||||||
} catch (PgpKeyNotFoundException | NotFoundException e) {
|
|
||||||
log.add(LogType.MSG_RET_LOCAL_NOT_FOUND, 1);
|
|
||||||
return KeyRetrievalResult.createWithError(log);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.add(LogType.MSG_RET_LOCAL_NONE_FOUND, 1);
|
||||||
|
return KeyRetrievalResult.createWithError(log);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1977,7 +1977,8 @@
|
|||||||
<string name="msg_ret_local_search">"Searching for key: %s"</string>
|
<string name="msg_ret_local_search">"Searching for key: %s"</string>
|
||||||
<string name="msg_ret_local_fp_match">"Local key's fingerprint matches"</string>
|
<string name="msg_ret_local_fp_match">"Local key's fingerprint matches"</string>
|
||||||
<string name="msg_ret_local_fp_mismatch">"Local key's fingerprint doesn't match!"</string>
|
<string name="msg_ret_local_fp_mismatch">"Local key's fingerprint doesn't match!"</string>
|
||||||
<string name="msg_ret_local_not_found">"No key found"</string>
|
<string name="msg_ret_local_not_found">"Key not found"</string>
|
||||||
|
<string name="msg_ret_local_none_found">"No matching key found"</string>
|
||||||
<string name="msg_ret_local_ok">"Key found"</string>
|
<string name="msg_ret_local_ok">"Key found"</string>
|
||||||
<string name="msg_ret_local_secret">"Local key contains secret key material"</string>
|
<string name="msg_ret_local_secret">"Local key contains secret key material"</string>
|
||||||
<string name="msg_ret_local_start">"Looking for key in local key list…"</string>
|
<string name="msg_ret_local_start">"Looking for key in local key list…"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user