mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 09:12:16 -05:00
corrected indentation
This commit is contained in:
parent
6bc40d12ad
commit
ebba24cbd8
@ -196,351 +196,358 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
Runnable actionRunnable = new Runnable(){@Override public void run() {
|
Runnable actionRunnable = new Runnable() {
|
||||||
// We have not been cancelled! (yet)
|
@Override
|
||||||
mActionCanceled.set(false);
|
public void run() {
|
||||||
|
// We have not been cancelled! (yet)
|
||||||
|
mActionCanceled.set(false);
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
if (extras == null) {
|
if (extras == null) {
|
||||||
Log.e(Constants.TAG, "Extras bundle is null!");
|
Log.e(Constants.TAG, "Extras bundle is null!");
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || (intent
|
|
||||||
.getAction() == null))) {
|
|
||||||
Log.e(Constants.TAG,
|
|
||||||
"Extra bundle must contain a messenger, a data bundle, and an action!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Uri dataUri = intent.getData();
|
|
||||||
|
|
||||||
mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
|
|
||||||
Bundle data = extras.getBundle(EXTRA_DATA);
|
|
||||||
if (data == null) {
|
|
||||||
Log.e(Constants.TAG, "data extra is null!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.logDebugBundle(data, "EXTRA_DATA");
|
|
||||||
|
|
||||||
ProviderHelper providerHelper = new ProviderHelper(mKeychainService);
|
|
||||||
|
|
||||||
String action = intent.getAction();
|
|
||||||
|
|
||||||
// executeServiceMethod action from extra bundle
|
|
||||||
switch (action) {
|
|
||||||
case ACTION_CERTIFY_KEYRING: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
|
|
||||||
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
|
||||||
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
CertifyOperation op = new CertifyOperation(mKeychainService, providerHelper, mKeychainService,
|
|
||||||
mActionCanceled);
|
|
||||||
CertifyResult result = op.certify(parcel, cryptoInput, keyServerUri);
|
|
||||||
|
|
||||||
// Result
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_CONSOLIDATE: {
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
ConsolidateResult result;
|
|
||||||
if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
|
|
||||||
result = providerHelper.consolidateDatabaseStep2(mKeychainService);
|
|
||||||
} else {
|
|
||||||
result = providerHelper.consolidateDatabaseStep1(mKeychainService);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Result
|
if (!(extras.containsKey(EXTRA_MESSENGER) || extras.containsKey(EXTRA_DATA) || (intent
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
.getAction() == null))) {
|
||||||
|
Log.e(Constants.TAG,
|
||||||
|
"Extra bundle must contain a messenger, a data bundle, and an action!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
Uri dataUri = intent.getData();
|
||||||
}
|
|
||||||
case ACTION_DECRYPT_METADATA: {
|
mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
|
||||||
|
Bundle data = extras.getBundle(EXTRA_DATA);
|
||||||
|
if (data == null) {
|
||||||
|
Log.e(Constants.TAG, "data extra is null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log.logDebugBundle(data, "EXTRA_DATA");
|
||||||
|
|
||||||
|
ProviderHelper providerHelper = new ProviderHelper(mKeychainService);
|
||||||
|
|
||||||
|
String action = intent.getAction();
|
||||||
|
|
||||||
|
// executeServiceMethod action from extra bundle
|
||||||
|
switch (action) {
|
||||||
|
case ACTION_CERTIFY_KEYRING: {
|
||||||
|
|
||||||
|
// Input
|
||||||
|
CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
|
||||||
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
|
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
CertifyOperation op = new CertifyOperation(mKeychainService, providerHelper, mKeychainService,
|
||||||
|
mActionCanceled);
|
||||||
|
CertifyResult result = op.certify(parcel, cryptoInput, keyServerUri);
|
||||||
|
|
||||||
|
// Result
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_CONSOLIDATE: {
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
ConsolidateResult result;
|
||||||
|
if (data.containsKey(CONSOLIDATE_RECOVERY) && data.getBoolean(CONSOLIDATE_RECOVERY)) {
|
||||||
|
result = providerHelper.consolidateDatabaseStep2(mKeychainService);
|
||||||
|
} else {
|
||||||
|
result = providerHelper.consolidateDatabaseStep1(mKeychainService);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Result
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_DECRYPT_METADATA: {
|
||||||
|
|
||||||
/* Input */
|
/* Input */
|
||||||
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
PgpDecryptVerifyInputParcel input = data.getParcelable(DECRYPT_VERIFY_PARCEL);
|
PgpDecryptVerifyInputParcel input = data.getParcelable(DECRYPT_VERIFY_PARCEL);
|
||||||
|
|
||||||
// this action is here for compatibility only
|
// this action is here for compatibility only
|
||||||
input.setDecryptMetadataOnly(true);
|
input.setDecryptMetadataOnly(true);
|
||||||
|
|
||||||
/* Operation */
|
/* Operation */
|
||||||
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
|
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
|
||||||
DecryptVerifyResult decryptVerifyResult = op.execute(input, cryptoInput);
|
DecryptVerifyResult decryptVerifyResult = op.execute(input, cryptoInput);
|
||||||
|
|
||||||
/* Result */
|
/* Result */
|
||||||
sendMessageToHandler(MessageStatus.OKAY, decryptVerifyResult);
|
sendMessageToHandler(MessageStatus.OKAY, decryptVerifyResult);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case ACTION_VERIFY_KEYBASE_PROOF: {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Proof proof = new Proof(new JSONObject(data.getString(KEYBASE_PROOF)));
|
|
||||||
setProgress(R.string.keybase_message_fetching_data, 0, 100);
|
|
||||||
|
|
||||||
Prover prover = Prover.findProverFor(proof);
|
|
||||||
|
|
||||||
if (prover == null) {
|
|
||||||
sendProofError(getString(R.string.keybase_no_prover_found) + ": " + proof
|
|
||||||
.getPrettyName());
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
case ACTION_VERIFY_KEYBASE_PROOF: {
|
||||||
|
|
||||||
if (!prover.fetchProofData()) {
|
try {
|
||||||
sendProofError(prover.getLog(), getString(R.string.keybase_problem_fetching_evidence));
|
Proof proof = new Proof(new JSONObject(data.getString(KEYBASE_PROOF)));
|
||||||
return;
|
setProgress(R.string.keybase_message_fetching_data, 0, 100);
|
||||||
}
|
|
||||||
String requiredFingerprint = data.getString(KEYBASE_REQUIRED_FINGERPRINT);
|
|
||||||
if (!prover.checkFingerprint(requiredFingerprint)) {
|
|
||||||
sendProofError(getString(R.string.keybase_key_mismatch));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String domain = prover.dnsTxtCheckRequired();
|
Prover prover = Prover.findProverFor(proof);
|
||||||
if (domain != null) {
|
|
||||||
DNSMessage dnsQuery = new Client().query(new Question(domain, Record.TYPE.TXT));
|
if (prover == null) {
|
||||||
if (dnsQuery == null) {
|
sendProofError(getString(R.string.keybase_no_prover_found) + ": " + proof
|
||||||
sendProofError(prover.getLog(), getString(R.string.keybase_dns_query_failure));
|
.getPrettyName());
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
Record[] records = dnsQuery.getAnswers();
|
|
||||||
List<List<byte[]>> extents = new ArrayList<List<byte[]>>();
|
|
||||||
for (Record r : records) {
|
|
||||||
Data d = r.getPayload();
|
|
||||||
if (d instanceof TXT) {
|
|
||||||
extents.add(((TXT) d).getExtents());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!prover.fetchProofData()) {
|
||||||
|
sendProofError(prover.getLog(), getString(R.string.keybase_problem_fetching_evidence));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String requiredFingerprint = data.getString(KEYBASE_REQUIRED_FINGERPRINT);
|
||||||
|
if (!prover.checkFingerprint(requiredFingerprint)) {
|
||||||
|
sendProofError(getString(R.string.keybase_key_mismatch));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String domain = prover.dnsTxtCheckRequired();
|
||||||
|
if (domain != null) {
|
||||||
|
DNSMessage dnsQuery = new Client().query(new Question(domain, Record.TYPE.TXT));
|
||||||
|
if (dnsQuery == null) {
|
||||||
|
sendProofError(prover.getLog(), getString(R.string.keybase_dns_query_failure));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Record[] records = dnsQuery.getAnswers();
|
||||||
|
List<List<byte[]>> extents = new ArrayList<List<byte[]>>();
|
||||||
|
for (Record r : records) {
|
||||||
|
Data d = r.getPayload();
|
||||||
|
if (d instanceof TXT) {
|
||||||
|
extents.add(((TXT) d).getExtents());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!prover.checkDnsTxt(extents)) {
|
||||||
|
sendProofError(prover.getLog(), null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] messageBytes = prover.getPgpMessage().getBytes();
|
||||||
|
if (prover.rawMessageCheckRequired()) {
|
||||||
|
InputStream messageByteStream = PGPUtil.getDecoderStream(new ByteArrayInputStream
|
||||||
|
(messageBytes));
|
||||||
|
if (!prover.checkRawMessageBytes(messageByteStream)) {
|
||||||
|
sendProofError(prover.getLog(), null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper,
|
||||||
|
mKeychainService);
|
||||||
|
|
||||||
|
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes)
|
||||||
|
.setSignedLiteralData(true)
|
||||||
|
.setRequiredSignerFingerprint(requiredFingerprint);
|
||||||
|
|
||||||
|
DecryptVerifyResult decryptVerifyResult = op.execute(input, new CryptoInputParcel());
|
||||||
|
|
||||||
|
if (!decryptVerifyResult.success()) {
|
||||||
|
OperationLog log = decryptVerifyResult.getLog();
|
||||||
|
OperationResult.LogEntryParcel lastEntry = null;
|
||||||
|
for (OperationResult.LogEntryParcel entry : log) {
|
||||||
|
lastEntry = entry;
|
||||||
|
}
|
||||||
|
sendProofError(getString(lastEntry.mType.getMsgId()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!prover.validate(new String(decryptVerifyResult.getOutputBytes()))) {
|
||||||
|
sendProofError(getString(R.string.keybase_message_payload_mismatch));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bundle resultData = new Bundle();
|
||||||
|
resultData.putString(ServiceProgressHandler.DATA_MESSAGE, "OK");
|
||||||
|
|
||||||
|
// these help the handler construct a useful human-readable message
|
||||||
|
resultData.putString(ServiceProgressHandler.KEYBASE_PROOF_URL, prover.getProofUrl());
|
||||||
|
resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_URL, prover.getPresenceUrl());
|
||||||
|
resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_LABEL, prover
|
||||||
|
.getPresenceLabel());
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, resultData);
|
||||||
|
} catch (Exception e) {
|
||||||
|
sendErrorToHandler(e);
|
||||||
}
|
}
|
||||||
if (!prover.checkDnsTxt(extents)) {
|
|
||||||
sendProofError(prover.getLog(), null);
|
break;
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
case ACTION_DECRYPT_VERIFY: {
|
||||||
byte[] messageBytes = prover.getPgpMessage().getBytes();
|
|
||||||
if (prover.rawMessageCheckRequired()) {
|
|
||||||
InputStream messageByteStream = PGPUtil.getDecoderStream(new ByteArrayInputStream
|
|
||||||
(messageBytes));
|
|
||||||
if (!prover.checkRawMessageBytes(messageByteStream)) {
|
|
||||||
sendProofError(prover.getLog(), null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
|
|
||||||
|
|
||||||
PgpDecryptVerifyInputParcel input = new PgpDecryptVerifyInputParcel(messageBytes)
|
|
||||||
.setSignedLiteralData(true)
|
|
||||||
.setRequiredSignerFingerprint(requiredFingerprint);
|
|
||||||
|
|
||||||
DecryptVerifyResult decryptVerifyResult = op.execute(input, new CryptoInputParcel());
|
|
||||||
|
|
||||||
if (!decryptVerifyResult.success()) {
|
|
||||||
OperationLog log = decryptVerifyResult.getLog();
|
|
||||||
OperationResult.LogEntryParcel lastEntry = null;
|
|
||||||
for (OperationResult.LogEntryParcel entry : log) {
|
|
||||||
lastEntry = entry;
|
|
||||||
}
|
|
||||||
sendProofError(getString(lastEntry.mType.getMsgId()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!prover.validate(new String(decryptVerifyResult.getOutputBytes()))) {
|
|
||||||
sendProofError(getString(R.string.keybase_message_payload_mismatch));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle resultData = new Bundle();
|
|
||||||
resultData.putString(ServiceProgressHandler.DATA_MESSAGE, "OK");
|
|
||||||
|
|
||||||
// these help the handler construct a useful human-readable message
|
|
||||||
resultData.putString(ServiceProgressHandler.KEYBASE_PROOF_URL, prover.getProofUrl());
|
|
||||||
resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_URL, prover.getPresenceUrl());
|
|
||||||
resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_LABEL, prover
|
|
||||||
.getPresenceLabel());
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, resultData);
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendErrorToHandler(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_DECRYPT_VERIFY: {
|
|
||||||
|
|
||||||
/* Input */
|
/* Input */
|
||||||
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
PgpDecryptVerifyInputParcel input = data.getParcelable(DECRYPT_VERIFY_PARCEL);
|
PgpDecryptVerifyInputParcel input = data.getParcelable(DECRYPT_VERIFY_PARCEL);
|
||||||
|
|
||||||
// for compatibility
|
// for compatibility
|
||||||
// TODO merge with ACTION_DECRYPT_METADATA
|
// TODO merge with ACTION_DECRYPT_METADATA
|
||||||
input.setDecryptMetadataOnly(false);
|
input.setDecryptMetadataOnly(false);
|
||||||
|
|
||||||
/* Operation */
|
/* Operation */
|
||||||
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
|
PgpDecryptVerify op = new PgpDecryptVerify(mKeychainService, providerHelper, mKeychainService);
|
||||||
DecryptVerifyResult decryptVerifyResult = op.execute(input, cryptoInput);
|
DecryptVerifyResult decryptVerifyResult = op.execute(input, cryptoInput);
|
||||||
|
|
||||||
/* Output */
|
/* Output */
|
||||||
sendMessageToHandler(MessageStatus.OKAY, decryptVerifyResult);
|
sendMessageToHandler(MessageStatus.OKAY, decryptVerifyResult);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
case ACTION_DELETE: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
long[] masterKeyIds = data.getLongArray(DELETE_KEY_LIST);
|
|
||||||
boolean isSecret = data.getBoolean(DELETE_IS_SECRET);
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
DeleteOperation op = new DeleteOperation(mKeychainService, providerHelper, mKeychainService);
|
|
||||||
DeleteResult result = op.execute(masterKeyIds, isSecret);
|
|
||||||
|
|
||||||
// Result
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_EDIT_KEYRING: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
SaveKeyringParcel saveParcel = data.getParcelable(EDIT_KEYRING_PARCEL);
|
|
||||||
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
EditKeyOperation op = new EditKeyOperation(mKeychainService, providerHelper,
|
|
||||||
mKeychainService, mActionCanceled);
|
|
||||||
OperationResult result = op.execute(saveParcel, cryptoInput);
|
|
||||||
|
|
||||||
// Result
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_PROMOTE_KEYRING: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
long keyRingId = data.getLong(PROMOTE_MASTER_KEY_ID);
|
|
||||||
byte[] cardAid = data.getByteArray(PROMOTE_CARD_AID);
|
|
||||||
long[] subKeyIds = data.getLongArray(PROMOTE_SUBKEY_IDS);
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
PromoteKeyOperation op = new PromoteKeyOperation(
|
|
||||||
mKeychainService, providerHelper, mKeychainService,
|
|
||||||
mActionCanceled);
|
|
||||||
PromoteKeyResult result = op.execute(keyRingId, cardAid, subKeyIds);
|
|
||||||
|
|
||||||
// Result
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_EXPORT_KEYRING: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
boolean exportSecret = data.getBoolean(EXPORT_SECRET, false);
|
|
||||||
String outputFile = data.getString(EXPORT_FILENAME);
|
|
||||||
Uri outputUri = data.getParcelable(EXPORT_URI);
|
|
||||||
|
|
||||||
boolean exportAll = data.getBoolean(EXPORT_ALL);
|
|
||||||
long[] masterKeyIds = exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
|
|
||||||
|
|
||||||
// Operation
|
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
|
||||||
mKeychainService, providerHelper, mKeychainService);
|
|
||||||
ExportResult result;
|
|
||||||
if (outputFile != null) {
|
|
||||||
result = importExportOperation.exportToFile(masterKeyIds, exportSecret, outputFile);
|
|
||||||
} else {
|
|
||||||
result = importExportOperation.exportToUri(masterKeyIds, exportSecret, outputUri);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Result
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ACTION_IMPORT_KEYRING: {
|
|
||||||
|
|
||||||
// Input
|
|
||||||
String keyServer = data.getString(IMPORT_KEY_SERVER);
|
|
||||||
ArrayList<ParcelableKeyRing> keyList = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
|
||||||
|
|
||||||
// either keyList or cache must be null, no guarantees otherwise
|
|
||||||
if (keyList == null) {// import from file, do serially
|
|
||||||
serialKeyImport(null, keyServer, providerHelper);
|
|
||||||
} else {
|
|
||||||
// if there is more than one key with the same fingerprint, we do a serial import to prevent
|
|
||||||
// https://github.com/open-keychain/open-keychain/issues/1221
|
|
||||||
HashSet<String> keyFingerprintSet = new HashSet<>();
|
|
||||||
for (int i = 0; i < keyList.size(); i++) {
|
|
||||||
keyFingerprintSet.add(keyList.get(i).mExpectedFingerprint);
|
|
||||||
}
|
}
|
||||||
if (keyFingerprintSet.size() == keyList.size()) {
|
case ACTION_DELETE: {
|
||||||
// all keys have unique fingerprints
|
|
||||||
multiThreadedKeyImport(keyList.iterator(), keyList.size(), keyServer);
|
// Input
|
||||||
} else {
|
long[] masterKeyIds = data.getLongArray(DELETE_KEY_LIST);
|
||||||
serialKeyImport(keyList, keyServer, providerHelper);
|
boolean isSecret = data.getBoolean(DELETE_IS_SECRET);
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
DeleteOperation op = new DeleteOperation(mKeychainService, providerHelper, mKeychainService);
|
||||||
|
DeleteResult result = op.execute(masterKeyIds, isSecret);
|
||||||
|
|
||||||
|
// Result
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
case ACTION_EDIT_KEYRING: {
|
||||||
|
|
||||||
break;
|
// Input
|
||||||
}
|
SaveKeyringParcel saveParcel = data.getParcelable(EDIT_KEYRING_PARCEL);
|
||||||
case ACTION_SIGN_ENCRYPT: {
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
|
|
||||||
// Input
|
// Operation
|
||||||
SignEncryptParcel inputParcel = data.getParcelable(SIGN_ENCRYPT_PARCEL);
|
EditKeyOperation op = new EditKeyOperation(mKeychainService, providerHelper,
|
||||||
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
mKeychainService, mActionCanceled);
|
||||||
|
OperationResult result = op.execute(saveParcel, cryptoInput);
|
||||||
|
|
||||||
// Operation
|
// Result
|
||||||
SignEncryptOperation op = new SignEncryptOperation(
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
mKeychainService, providerHelper, mKeychainService, mActionCanceled);
|
|
||||||
SignEncryptResult result = op.execute(inputParcel, cryptoInput);
|
|
||||||
|
|
||||||
// Result
|
break;
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
}
|
||||||
|
case ACTION_PROMOTE_KEYRING: {
|
||||||
|
|
||||||
break;
|
// Input
|
||||||
}
|
long keyRingId = data.getLong(PROMOTE_MASTER_KEY_ID);
|
||||||
case ACTION_UPLOAD_KEYRING: {
|
byte[] cardAid = data.getByteArray(PROMOTE_CARD_AID);
|
||||||
try {
|
long[] subKeyIds = data.getLongArray(PROMOTE_SUBKEY_IDS);
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
PromoteKeyOperation op = new PromoteKeyOperation(
|
||||||
|
mKeychainService, providerHelper, mKeychainService,
|
||||||
|
mActionCanceled);
|
||||||
|
PromoteKeyResult result = op.execute(keyRingId, cardAid, subKeyIds);
|
||||||
|
|
||||||
|
// Result
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_EXPORT_KEYRING: {
|
||||||
|
|
||||||
|
// Input
|
||||||
|
boolean exportSecret = data.getBoolean(EXPORT_SECRET, false);
|
||||||
|
String outputFile = data.getString(EXPORT_FILENAME);
|
||||||
|
Uri outputUri = data.getParcelable(EXPORT_URI);
|
||||||
|
|
||||||
|
boolean exportAll = data.getBoolean(EXPORT_ALL);
|
||||||
|
long[] masterKeyIds = exportAll ? null : data.getLongArray(EXPORT_KEY_RING_MASTER_KEY_ID);
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||||
|
mKeychainService, providerHelper, mKeychainService);
|
||||||
|
ExportResult result;
|
||||||
|
if (outputFile != null) {
|
||||||
|
result = importExportOperation.exportToFile(masterKeyIds, exportSecret, outputFile);
|
||||||
|
} else {
|
||||||
|
result = importExportOperation.exportToUri(masterKeyIds, exportSecret, outputUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Result
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_IMPORT_KEYRING: {
|
||||||
|
|
||||||
|
// Input
|
||||||
|
String keyServer = data.getString(IMPORT_KEY_SERVER);
|
||||||
|
ArrayList<ParcelableKeyRing> keyList = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
||||||
|
|
||||||
|
// either keyList or cache must be null, no guarantees otherwise
|
||||||
|
if (keyList == null) {// import from file, do serially
|
||||||
|
serialKeyImport(null, keyServer, providerHelper);
|
||||||
|
} else {
|
||||||
|
// if there is more than one key with the same fingerprint, we do a serial import to prevent
|
||||||
|
// https://github.com/open-keychain/open-keychain/issues/1221
|
||||||
|
HashSet<String> keyFingerprintSet = new HashSet<>();
|
||||||
|
for (int i = 0; i < keyList.size(); i++) {
|
||||||
|
keyFingerprintSet.add(keyList.get(i).mExpectedFingerprint);
|
||||||
|
}
|
||||||
|
if (keyFingerprintSet.size() == keyList.size()) {
|
||||||
|
// all keys have unique fingerprints
|
||||||
|
multiThreadedKeyImport(keyList.iterator(), keyList.size(), keyServer);
|
||||||
|
} else {
|
||||||
|
serialKeyImport(keyList, keyServer, providerHelper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_SIGN_ENCRYPT: {
|
||||||
|
|
||||||
|
// Input
|
||||||
|
SignEncryptParcel inputParcel = data.getParcelable(SIGN_ENCRYPT_PARCEL);
|
||||||
|
CryptoInputParcel cryptoInput = data.getParcelable(EXTRA_CRYPTO_INPUT);
|
||||||
|
|
||||||
|
// Operation
|
||||||
|
SignEncryptOperation op = new SignEncryptOperation(
|
||||||
|
mKeychainService, providerHelper, mKeychainService, mActionCanceled);
|
||||||
|
SignEncryptResult result = op.execute(inputParcel, cryptoInput);
|
||||||
|
|
||||||
|
// Result
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case ACTION_UPLOAD_KEYRING: {
|
||||||
|
try {
|
||||||
|
|
||||||
/* Input */
|
/* Input */
|
||||||
String keyServer = data.getString(UPLOAD_KEY_SERVER);
|
String keyServer = data.getString(UPLOAD_KEY_SERVER);
|
||||||
// and dataUri!
|
// and dataUri!
|
||||||
|
|
||||||
/* Operation */
|
/* Operation */
|
||||||
HkpKeyserver server = new HkpKeyserver(keyServer);
|
HkpKeyserver server = new HkpKeyserver(keyServer);
|
||||||
|
|
||||||
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
CanonicalizedPublicKeyRing keyring = providerHelper.getCanonicalizedPublicKeyRing(dataUri);
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(mKeychainService,
|
ImportExportOperation importExportOperation = new ImportExportOperation(mKeychainService,
|
||||||
providerHelper, mKeychainService);
|
providerHelper, mKeychainService);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
importExportOperation.uploadKeyRingToServer(server, keyring);
|
importExportOperation.uploadKeyRingToServer(server, keyring);
|
||||||
} catch (Keyserver.AddKeyException e) {
|
} catch (Keyserver.AddKeyException e) {
|
||||||
throw new PgpGeneralException("Unable to export key to selected server");
|
throw new PgpGeneralException("Unable to export key to selected server");
|
||||||
|
}
|
||||||
|
|
||||||
|
sendMessageToHandler(MessageStatus.OKAY);
|
||||||
|
} catch (Exception e) {
|
||||||
|
sendErrorToHandler(e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY);
|
|
||||||
} catch (Exception e) {
|
|
||||||
sendErrorToHandler(e);
|
|
||||||
}
|
}
|
||||||
break;
|
if (!intent.getAction().equals(ACTION_IMPORT_KEYRING)) {
|
||||||
|
// import keyring handles stopping service on its own
|
||||||
|
stopSelf();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
if (!intent.getAction().equals(ACTION_IMPORT_KEYRING)) {
|
|
||||||
// import keyring handles stopping service on its own
|
|
||||||
stopSelf();
|
|
||||||
} }};
|
|
||||||
Thread actionThread = new Thread(actionRunnable);
|
Thread actionThread = new Thread(actionRunnable);
|
||||||
actionThread.start();
|
actionThread.start();
|
||||||
|
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user