mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-05 00:35:08 -05:00
Merge ACTION_DOWNLOAD_AND_IMPORT_KEYS and ACTION_IMPORT_KEYBASE_KEYS
This commit is contained in:
parent
d4cdc36448
commit
34b97cb136
@ -40,6 +40,7 @@ import org.sufficientlysecure.keychain.helper.FileHelper;
|
||||
import org.sufficientlysecure.keychain.helper.OtherHelper;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.keyimport.HkpKeyserver;
|
||||
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpConversionHelper;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
|
||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyResult;
|
||||
@ -742,68 +743,28 @@ public class KeychainIntentService extends IntentService
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
} else if (ACTION_IMPORT_KEYBASE_KEYS.equals(action)) {
|
||||
ArrayList<ImportKeysListEntry> entries = data.getParcelableArrayList(DOWNLOAD_KEY_LIST);
|
||||
|
||||
try {
|
||||
KeybaseKeyserver server = new KeybaseKeyserver();
|
||||
for (ImportKeysListEntry entry : entries) {
|
||||
// the keybase handle is in userId(1)
|
||||
String keybaseId = entry.getExtraData();
|
||||
byte[] downloadedKeyBytes = server.get(keybaseId).getBytes();
|
||||
|
||||
// create PGPKeyRing object based on downloaded armored key
|
||||
PGPKeyRing downloadedKey = null;
|
||||
BufferedInputStream bufferedInput =
|
||||
new BufferedInputStream(new ByteArrayInputStream(downloadedKeyBytes));
|
||||
if (bufferedInput.available() > 0) {
|
||||
InputStream in = PGPUtil.getDecoderStream(bufferedInput);
|
||||
PGPObjectFactory objectFactory = new PGPObjectFactory(in);
|
||||
|
||||
// get first object in block
|
||||
Object obj;
|
||||
if ((obj = objectFactory.nextObject()) != null) {
|
||||
|
||||
if (obj instanceof PGPKeyRing) {
|
||||
downloadedKey = (PGPKeyRing) obj;
|
||||
} else {
|
||||
throw new PgpGeneralException("Object not recognized as PGPKeyRing!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// save key bytes in entry object for doing the
|
||||
// actual import afterwards
|
||||
entry.setBytes(downloadedKey.getEncoded());
|
||||
}
|
||||
|
||||
Intent importIntent = new Intent(this, KeychainIntentService.class);
|
||||
importIntent.setAction(ACTION_IMPORT_KEYRING);
|
||||
Bundle importData = new Bundle();
|
||||
importData.putParcelableArrayList(IMPORT_KEY_LIST, entries);
|
||||
importIntent.putExtra(EXTRA_DATA, importData);
|
||||
importIntent.putExtra(EXTRA_MESSENGER, mMessenger);
|
||||
|
||||
// now import it with this service
|
||||
onHandleIntent(importIntent);
|
||||
|
||||
// result is handled in ACTION_IMPORT_KEYRING
|
||||
} catch (Exception e) {
|
||||
sendErrorToHandler(e);
|
||||
}
|
||||
} else if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action)) {
|
||||
} else if (ACTION_DOWNLOAD_AND_IMPORT_KEYS.equals(action) || ACTION_IMPORT_KEYBASE_KEYS.equals(action)) {
|
||||
try {
|
||||
ArrayList<ImportKeysListEntry> entries = data.getParcelableArrayList(DOWNLOAD_KEY_LIST);
|
||||
String keyServer = data.getString(DOWNLOAD_KEY_SERVER);
|
||||
|
||||
// this downloads the keys and places them into the ImportKeysListEntry entries
|
||||
for (ImportKeysListEntry entry : entries) {
|
||||
|
||||
// this downloads the keys and places them into the ImportKeysListEntry entries
|
||||
HkpKeyserver server = new HkpKeyserver(entry.getOrigin() != null ? entry.getOrigin() : keyServer);
|
||||
Keyserver server;
|
||||
if (entry.getOrigin() == null) {
|
||||
server = new HkpKeyserver(keyServer);
|
||||
} else if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
|
||||
server = new KeybaseKeyserver();
|
||||
} else {
|
||||
server = new HkpKeyserver(entry.getOrigin());
|
||||
}
|
||||
|
||||
// if available use complete fingerprint for get request
|
||||
byte[] downloadedKeyBytes;
|
||||
if (entry.getFingerprintHex() != null) {
|
||||
if (KeybaseKeyserver.ORIGIN.equals(entry.getOrigin())) {
|
||||
downloadedKeyBytes = server.get(entry.getExtraData()).getBytes();
|
||||
} else if (entry.getFingerprintHex() != null) {
|
||||
downloadedKeyBytes = server.get("0x" + entry.getFingerprintHex()).getBytes();
|
||||
} else {
|
||||
downloadedKeyBytes = server.get(entry.getKeyIdHex()).getBytes();
|
||||
@ -833,7 +794,7 @@ public class KeychainIntentService extends IntentService
|
||||
if (entry.getFingerprintHex() != null) {
|
||||
String downloadedKeyFp = PgpKeyHelper.convertFingerprintToHex(
|
||||
downloadedKey.getPublicKey().getFingerprint());
|
||||
if (downloadedKeyFp.equals(entry.getFingerprintHex())) {
|
||||
if (downloadedKeyFp.equalsIgnoreCase(entry.getFingerprintHex())) {
|
||||
Log.d(Constants.TAG, "fingerprint of downloaded key is the same as " +
|
||||
"the requested fingerprint!");
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user