mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-25 08:28:50 -05:00
implement upload of keyring after certification, check that option by default
This commit is contained in:
parent
108b35cb50
commit
510ef40f55
@ -2,6 +2,9 @@ package org.sufficientlysecure.keychain.operations;
|
|||||||
|
|
||||||
import android.content.Context;
|
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.CanonicalizedPublicKeyRing;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey;
|
||||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKeyRing;
|
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.OperationResult.OperationLog;
|
||||||
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
import org.sufficientlysecure.keychain.operations.results.SaveKeyringResult;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
@ -36,7 +40,7 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
super(context, providerHelper, progressable, cancelled);
|
super(context, providerHelper, progressable, cancelled);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CertifyResult certify(CertifyActionsParcel parcel) {
|
public CertifyResult certify(CertifyActionsParcel parcel, String keyServerUri) {
|
||||||
|
|
||||||
OperationLog log = new OperationLog();
|
OperationLog log = new OperationLog();
|
||||||
log.add(LogType.MSG_CRT, 0);
|
log.add(LogType.MSG_CRT, 0);
|
||||||
@ -72,7 +76,7 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
|
|
||||||
log.add(LogType.MSG_CRT_CERTIFYING, 1);
|
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
|
// Work through all requested certifications
|
||||||
for (CertifyAction action : parcel.mCertifyActions) {
|
for (CertifyAction action : parcel.mCertifyActions) {
|
||||||
@ -118,13 +122,20 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
return new CertifyResult(CertifyResult.RESULT_CANCELLED, log);
|
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
|
// Write all certified keys into the database
|
||||||
for (UncachedKeyRing certifiedKey : certifiedKeys) {
|
for (UncachedKeyRing certifiedKey : certifiedKeys) {
|
||||||
|
|
||||||
// Check if we were cancelled
|
// Check if we were cancelled
|
||||||
if (checkCancelled()) {
|
if (checkCancelled()) {
|
||||||
log.add(LogType.MSG_OPERATION_CANCELLED, 0);
|
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,
|
log.add(LogType.MSG_CRT_SAVE, 2,
|
||||||
@ -133,6 +144,17 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
mProviderHelper.clearLog();
|
mProviderHelper.clearLog();
|
||||||
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey);
|
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()) {
|
if (result.success()) {
|
||||||
certifyOk += 1;
|
certifyOk += 1;
|
||||||
} else {
|
} else {
|
||||||
@ -145,11 +167,11 @@ public class CertifyOperation extends BaseOperation {
|
|||||||
|
|
||||||
if (certifyOk == 0) {
|
if (certifyOk == 0) {
|
||||||
log.add(LogType.MSG_CRT_ERROR_NOTHING, 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);
|
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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,6 +94,10 @@ public class ImportExportOperation extends BaseOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring) throws AddKeyException {
|
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();
|
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||||
ArmoredOutputStream aos = null;
|
ArmoredOutputStream aos = null;
|
||||||
try {
|
try {
|
||||||
|
@ -36,16 +36,18 @@ import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
|||||||
|
|
||||||
public class CertifyResult extends OperationResult {
|
public class CertifyResult extends OperationResult {
|
||||||
|
|
||||||
int mCertifyOk, mCertifyError;
|
int mCertifyOk, mCertifyError, mUploadOk, mUploadError;
|
||||||
|
|
||||||
public CertifyResult(int result, OperationLog log) {
|
public CertifyResult(int result, OperationLog log) {
|
||||||
super(result, 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);
|
this(result, log);
|
||||||
mCertifyOk = certifyOk;
|
mCertifyOk = certifyOk;
|
||||||
mCertifyError = certifyError;
|
mCertifyError = certifyError;
|
||||||
|
mUploadOk = uploadOk;
|
||||||
|
mUploadError = uploadError;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Construct from a parcel - trivial because we have no extra data. */
|
/** Construct from a parcel - trivial because we have no extra data. */
|
||||||
@ -53,6 +55,8 @@ public class CertifyResult extends OperationResult {
|
|||||||
super(source);
|
super(source);
|
||||||
mCertifyOk = source.readInt();
|
mCertifyOk = source.readInt();
|
||||||
mCertifyError = source.readInt();
|
mCertifyError = source.readInt();
|
||||||
|
mUploadOk = source.readInt();
|
||||||
|
mUploadError = source.readInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -60,6 +64,8 @@ public class CertifyResult extends OperationResult {
|
|||||||
super.writeToParcel(dest, flags);
|
super.writeToParcel(dest, flags);
|
||||||
dest.writeInt(mCertifyOk);
|
dest.writeInt(mCertifyOk);
|
||||||
dest.writeInt(mCertifyError);
|
dest.writeInt(mCertifyError);
|
||||||
|
dest.writeInt(mUploadOk);
|
||||||
|
dest.writeInt(mUploadError);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Creator<CertifyResult> CREATOR = new Creator<CertifyResult>() {
|
public static Creator<CertifyResult> CREATOR = new Creator<CertifyResult>() {
|
||||||
|
@ -121,6 +121,10 @@ public class UncachedKeyRing {
|
|||||||
return mRing.getEncoded();
|
return mRing.getEncoded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void encode(OutputStream out) throws IOException {
|
||||||
|
mRing.encode(out);
|
||||||
|
}
|
||||||
|
|
||||||
public byte[] getFingerprint() {
|
public byte[] getFingerprint() {
|
||||||
return mRing.getPublicKey().getFingerprint();
|
return mRing.getPublicKey().getFingerprint();
|
||||||
}
|
}
|
||||||
|
@ -239,10 +239,11 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
// Input
|
// Input
|
||||||
CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
|
CertifyActionsParcel parcel = data.getParcelable(CERTIFY_PARCEL);
|
||||||
|
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
CertifyOperation op = new CertifyOperation(this, providerHelper, this, mActionCanceled);
|
CertifyOperation op = new CertifyOperation(this, providerHelper, this, mActionCanceled);
|
||||||
CertifyResult result = op.certify(parcel);
|
CertifyResult result = op.certify(parcel, keyServerUri);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
|
sendMessageToHandler(KeychainIntentServiceHandler.MESSAGE_OKAY, result);
|
||||||
|
@ -61,6 +61,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify;
|
|||||||
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
|
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
|
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
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;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,6 +360,10 @@ public class MultiCertifyKeyFragment extends LoaderFragment
|
|||||||
|
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putParcelable(KeychainIntentService.CERTIFY_PARCEL, parcel);
|
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);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after signing is done in KeychainIntentService
|
// Message is received after signing is done in KeychainIntentService
|
||||||
@ -371,15 +381,8 @@ public class MultiCertifyKeyFragment extends LoaderFragment
|
|||||||
Intent intent = new Intent();
|
Intent intent = new Intent();
|
||||||
intent.putExtra(CertifyResult.EXTRA_RESULT, result);
|
intent.putExtra(CertifyResult.EXTRA_RESULT, result);
|
||||||
mActivity.setResult(Activity.RESULT_OK, intent);
|
mActivity.setResult(Activity.RESULT_OK, intent);
|
||||||
|
|
||||||
// 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();
|
mActivity.finish();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
android:id="@+id/sign_key_upload_checkbox"
|
android:id="@+id/sign_key_upload_checkbox"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:checked="false"
|
android:checked="true"
|
||||||
android:text="@string/label_send_key"
|
android:text="@string/label_send_key"
|
||||||
android:paddingTop="12dp"
|
android:paddingTop="12dp"
|
||||||
android:paddingBottom="12dp"/>
|
android:paddingBottom="12dp"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user