diff options
author | Vincent Breitmoser <valodim@mugenguild.com> | 2014-10-26 01:50:48 +0200 |
---|---|---|
committer | Vincent Breitmoser <valodim@mugenguild.com> | 2014-10-26 01:50:48 +0200 |
commit | 510ef40f556e59c37f42578ba8cb243f17f7e4e4 (patch) | |
tree | 4e17693b7b0d2cac0b0e8842ba2b2526abef1d97 /OpenKeychain | |
parent | 108b35cb50d3074e02812e2b333779466a1bf824 (diff) | |
download | open-keychain-510ef40f556e59c37f42578ba8cb243f17f7e4e4.tar.gz open-keychain-510ef40f556e59c37f42578ba8cb243f17f7e4e4.tar.bz2 open-keychain-510ef40f556e59c37f42578ba8cb243f17f7e4e4.zip |
implement upload of keyring after certification, check that option by default
Diffstat (limited to 'OpenKeychain')
7 files changed, 57 insertions, 17 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java index 2eb4c955c..9af6713ba 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/CertifyOperation.java @@ -2,6 +2,9 @@ package org.sufficientlysecure.keychain.operations; import android.content.Context; +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.keyimport.HkpKeyserver; +import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException; import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey; import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing; @@ -17,6 +20,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult.LogTyp import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog; import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.util.Log; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; @@ -36,7 +40,7 @@ public class CertifyOperation extends BaseOperation { super(context, providerHelper, progressable, cancelled); } - public CertifyResult certify(CertifyActionsParcel parcel) { + public CertifyResult certify(CertifyActionsParcel parcel, String keyServerUri) { OperationLog log = new OperationLog(); log.add(LogType.MSG_CRT, 0); @@ -72,7 +76,7 @@ public class CertifyOperation extends BaseOperation { log.add(LogType.MSG_CRT_CERTIFYING, 1); - int certifyOk = 0, certifyError = 0; + int certifyOk = 0, certifyError = 0, uploadOk = 0, uploadError = 0; // Work through all requested certifications for (CertifyAction action : parcel.mCertifyActions) { @@ -118,13 +122,20 @@ public class CertifyOperation extends BaseOperation { return new CertifyResult(CertifyResult.RESULT_CANCELLED, log); } + HkpKeyserver keyServer = null; + ImportExportOperation importExportOperation = null; + if (keyServerUri != null) { + keyServer = new HkpKeyserver(keyServerUri); + importExportOperation = new ImportExportOperation(mContext, mProviderHelper, mProgressable); + } + // Write all certified keys into the database for (UncachedKeyRing certifiedKey : certifiedKeys) { // Check if we were cancelled if (checkCancelled()) { log.add(LogType.MSG_OPERATION_CANCELLED, 0); - return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError); + return new CertifyResult(CertifyResult.RESULT_CANCELLED, log, certifyOk, certifyError, uploadOk, uploadError); } log.add(LogType.MSG_CRT_SAVE, 2, @@ -133,6 +144,17 @@ public class CertifyOperation extends BaseOperation { mProviderHelper.clearLog(); SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey); + if (importExportOperation != null) { + // TODO use subresult, get rid of try/catch! + try { + importExportOperation.uploadKeyRingToServer(keyServer, certifiedKey); + uploadOk += 1; + } catch (AddKeyException e) { + Log.e(Constants.TAG, "error uploading key", e); + uploadError += 1; + } + } + if (result.success()) { certifyOk += 1; } else { @@ -145,11 +167,11 @@ public class CertifyOperation extends BaseOperation { if (certifyOk == 0) { log.add(LogType.MSG_CRT_ERROR_NOTHING, 0); - return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError); + return new CertifyResult(CertifyResult.RESULT_ERROR, log, certifyOk, certifyError, uploadOk, uploadError); } log.add(LogType.MSG_CRT_SUCCESS, 0); - return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError); + return new CertifyResult(CertifyResult.RESULT_OK, log, certifyOk, certifyError, uploadOk, uploadError); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java index 6178b92d0..6dfac8429 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/ImportExportOperation.java @@ -94,6 +94,10 @@ public class ImportExportOperation extends BaseOperation { } public void uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring) throws AddKeyException { + uploadKeyRingToServer(server, keyring.getUncachedKeyRing()); + } + + public void uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring) throws AddKeyException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ArmoredOutputStream aos = null; try { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java index 49e3d0346..7b38cd244 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/operations/results/CertifyResult.java @@ -36,16 +36,18 @@ import org.sufficientlysecure.keychain.ui.LogDisplayFragment; public class CertifyResult extends OperationResult { - int mCertifyOk, mCertifyError; + int mCertifyOk, mCertifyError, mUploadOk, mUploadError; public CertifyResult(int result, OperationLog log) { super(result, log); } - public CertifyResult(int result, OperationLog log, int certifyOk, int certifyError) { + public CertifyResult(int result, OperationLog log, int certifyOk, int certifyError, int uploadOk, int uploadError) { this(result, log); mCertifyOk = certifyOk; mCertifyError = certifyError; + mUploadOk = uploadOk; + mUploadError = uploadError; } /** Construct from a parcel - trivial because we have no extra data. */ @@ -53,6 +55,8 @@ public class CertifyResult extends OperationResult { super(source); mCertifyOk = source.readInt(); mCertifyError = source.readInt(); + mUploadOk = source.readInt(); + mUploadError = source.readInt(); } @Override @@ -60,6 +64,8 @@ public class CertifyResult extends OperationResult { super.writeToParcel(dest, flags); dest.writeInt(mCertifyOk); dest.writeInt(mCertifyError); + dest.writeInt(mUploadOk); + dest.writeInt(mUploadError); } public static Creator<CertifyResult> CREATOR = new Creator<CertifyResult>() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java index 7bef2e828..8856da8b0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/pgp/UncachedKeyRing.java @@ -121,6 +121,10 @@ public class UncachedKeyRing { return mRing.getEncoded(); } + public void encode(OutputStream out) throws IOException { + mRing.encode(out); + } + public byte[] getFingerprint() { return mRing.getPublicKey().getFingerprint(); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java index 51a0acf7a..044656a31 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/KeychainIntentService.java @@ -239,10 +239,11 @@ public class KeychainIntentService extends IntentService implements Progressable // Input CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL); + String keyServerUri = data.getString(UPLOAD_KEY_SERVER); // Operation CertifyOperation op = new CertifyOperation(this, providerHelper, this, mActionCanceled); - CertifyResult result = op.certify(parcel); + CertifyResult result = op.certify(parcel, keyServerUri); // Result sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java index d2a3e632c..1691f23fe 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MultiCertifyKeyFragment.java @@ -61,6 +61,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.ui.widget.KeySpinner; import org.sufficientlysecure.keychain.util.Log; +import org.sufficientlysecure.keychain.util.Preferences; import java.util.ArrayList; @@ -174,6 +175,11 @@ public class MultiCertifyKeyFragment extends LoaderFragment } }); + // If this is a debug build, don't upload by default + if (Constants.DEBUG) { + mUploadKeyCheckbox.setChecked(false); + } + return root; } @@ -354,6 +360,10 @@ public class MultiCertifyKeyFragment extends LoaderFragment Bundle data = new Bundle(); data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel); + if (mUploadKeyCheckbox.isChecked()) { + String keyserver = Preferences.getPreferences(getActivity()).getPreferredKeyserver(); + data.putString(KeychainIntentService.UPLOAD_KEY_SERVER, keyserver); + } intent.putExtra(KeychainIntentService.EXTRA_DATA, data); // Message is received after signing is done in KeychainIntentService @@ -371,15 +381,8 @@ public class MultiCertifyKeyFragment extends LoaderFragment Intent intent = new Intent(); intent.putExtra(CertifyResult.EXTRA_RESULT, result); mActivity.setResult(Activity.RESULT_OK, intent); + mActivity.finish(); - // check if we need to send the key to the server or not - if (mUploadKeyCheckbox.isChecked()) { - // upload the newly signed key to the keyserver - // TODO implement - // uploadKey(); - } else { - mActivity.finish(); - } } } }; diff --git a/OpenKeychain/src/main/res/layout/multi_certify_key_fragment.xml b/OpenKeychain/src/main/res/layout/multi_certify_key_fragment.xml index 851464dd3..a55a8ea0c 100644 --- a/OpenKeychain/src/main/res/layout/multi_certify_key_fragment.xml +++ b/OpenKeychain/src/main/res/layout/multi_certify_key_fragment.xml @@ -61,7 +61,7 @@ android:id="@+id/sign_key_upload_checkbox" android:layout_width="match_parent" android:layout_height="wrap_content" - android:checked="false" + android:checked="true" android:text="@string/label_send_key" android:paddingTop="12dp" android:paddingBottom="12dp"/> |