upload: re-add upload by bytes
This commit is contained in:
@@ -45,6 +45,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel.NfcSignOperationsBuilder;
|
||||
@@ -205,23 +206,9 @@ public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
|
||||
}
|
||||
|
||||
// these variables are used inside the following loop, but they need to be created only once
|
||||
HkpKeyserver keyServer = null;
|
||||
UploadOperation uploadOperation = null;
|
||||
Proxy proxy = null;
|
||||
if (parcel.keyServerUri != null) {
|
||||
keyServer = new HkpKeyserver(parcel.keyServerUri);
|
||||
uploadOperation = new UploadOperation(mContext, mProviderHelper, mProgressable);
|
||||
if (cryptoInput.getParcelableProxy() == null) {
|
||||
// explicit proxy not set
|
||||
if (!OrbotHelper.isOrbotInRequiredState(mContext)) {
|
||||
return new CertifyResult(null,
|
||||
RequiredInputParcel.createOrbotRequiredOperation(), cryptoInput);
|
||||
}
|
||||
proxy = Preferences.getPreferences(mContext).getProxyPrefs()
|
||||
.parcelableProxy.getProxy();
|
||||
} else {
|
||||
proxy = cryptoInput.getParcelableProxy().getProxy();
|
||||
}
|
||||
}
|
||||
|
||||
// Write all certified keys into the database
|
||||
@@ -241,10 +228,9 @@ public class CertifyOperation extends BaseOperation<CertifyActionsParcel> {
|
||||
SaveKeyringResult result = mProviderHelper.savePublicKeyRing(certifiedKey);
|
||||
|
||||
if (uploadOperation != null) {
|
||||
UploadResult uploadResult = uploadOperation.uploadKeyRingToServer(
|
||||
keyServer,
|
||||
certifiedKey,
|
||||
proxy);
|
||||
UploadKeyringParcel uploadInput =
|
||||
new UploadKeyringParcel(parcel.keyServerUri, certifiedKey.getMasterKeyId());
|
||||
UploadResult uploadResult = uploadOperation.execute(uploadInput, cryptoInput);
|
||||
log.add(uploadResult, 2);
|
||||
|
||||
if (uploadResult.success()) {
|
||||
|
||||
@@ -134,27 +134,18 @@ public class EditKeyOperation extends BaseOperation<SaveKeyringParcel> {
|
||||
// It's a success, so this must be non-null now
|
||||
UncachedKeyRing ring = modifyResult.getRing();
|
||||
|
||||
// Save the new keyring.
|
||||
SaveKeyringResult saveResult = mProviderHelper
|
||||
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100));
|
||||
log.add(saveResult, 1);
|
||||
|
||||
// If the save operation didn't succeed, exit here
|
||||
if (!saveResult.success()) {
|
||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||
}
|
||||
|
||||
if (saveParcel.isUpload()) {
|
||||
UncachedKeyRing publicKeyRing;
|
||||
byte[] keyringBytes;
|
||||
try {
|
||||
publicKeyRing = ring.extractPublicKeyRing();
|
||||
UncachedKeyRing publicKeyRing = ring.extractPublicKeyRing();
|
||||
keyringBytes = publicKeyRing.getEncoded();
|
||||
} catch (IOException e) {
|
||||
log.add(LogType.MSG_ED_ERROR_EXTRACTING_PUBLIC_UPLOAD, 1);
|
||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||
}
|
||||
|
||||
UploadKeyringParcel exportKeyringParcel =
|
||||
new UploadKeyringParcel(saveParcel.getUploadKeyserver(), ring.getMasterKeyId());
|
||||
new UploadKeyringParcel(saveParcel.getUploadKeyserver(), keyringBytes);
|
||||
|
||||
UploadResult uploadResult =
|
||||
new UploadOperation(mContext, mProviderHelper, mProgressable)
|
||||
@@ -173,6 +164,16 @@ public class EditKeyOperation extends BaseOperation<SaveKeyringParcel> {
|
||||
}
|
||||
}
|
||||
|
||||
// Save the new keyring.
|
||||
SaveKeyringResult saveResult = mProviderHelper
|
||||
.saveSecretKeyRing(ring, new ProgressScaler(mProgressable, 60, 95, 100));
|
||||
log.add(saveResult, 1);
|
||||
|
||||
// If the save operation didn't succeed, exit here
|
||||
if (!saveResult.success()) {
|
||||
return new EditKeyResult(EditKeyResult.RESULT_ERROR, log, null);
|
||||
}
|
||||
|
||||
// There is a new passphrase - cache it
|
||||
if (saveParcel.mNewUnlock != null && cryptoInput.mCachePassphrase) {
|
||||
log.add(LogType.MSG_ED_CACHING_NEW, 1);
|
||||
|
||||
@@ -36,9 +36,11 @@ import org.sufficientlysecure.keychain.keyimport.Keyserver.AddKeyException;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogType;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.OperationLog;
|
||||
import org.sufficientlysecure.keychain.operations.results.UploadResult;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||
import org.sufficientlysecure.keychain.pgp.UncachedKeyRing;
|
||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.service.UploadKeyringParcel;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
@@ -71,7 +73,7 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public UploadResult execute(UploadKeyringParcel exportInput, CryptoInputParcel cryptoInput) {
|
||||
public UploadResult execute(UploadKeyringParcel uploadInput, CryptoInputParcel cryptoInput) {
|
||||
Proxy proxy;
|
||||
if (cryptoInput.getParcelableProxy() == null) {
|
||||
// explicit proxy not set
|
||||
@@ -83,18 +85,37 @@ public class UploadOperation extends BaseOperation<UploadKeyringParcel> {
|
||||
proxy = cryptoInput.getParcelableProxy().getProxy();
|
||||
}
|
||||
|
||||
HkpKeyserver hkpKeyserver = new HkpKeyserver(exportInput.mKeyserver);
|
||||
HkpKeyserver hkpKeyserver = new HkpKeyserver(uploadInput.mKeyserver);
|
||||
try {
|
||||
CanonicalizedPublicKeyRing keyring = mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||
exportInput.mMasterKeyId);
|
||||
return uploadKeyRingToServer(hkpKeyserver, keyring.getUncachedKeyRing(), proxy);
|
||||
CanonicalizedPublicKeyRing keyring;
|
||||
if (uploadInput.mMasterKeyId != null) {
|
||||
keyring = mProviderHelper.getCanonicalizedPublicKeyRing(
|
||||
uploadInput.mMasterKeyId);
|
||||
} else if (uploadInput.mUncachedKeyringBytes != null) {
|
||||
CanonicalizedKeyRing canonicalizedRing =
|
||||
UncachedKeyRing.decodeFromData(uploadInput.mUncachedKeyringBytes)
|
||||
.canonicalize(new OperationLog(), 0, true);
|
||||
if ( ! CanonicalizedPublicKeyRing.class.isInstance(canonicalizedRing)) {
|
||||
throw new AssertionError("keyring bytes must contain public key ring!");
|
||||
}
|
||||
keyring = (CanonicalizedPublicKeyRing) canonicalizedRing;
|
||||
} else {
|
||||
throw new AssertionError("key id or bytes must be non-null!");
|
||||
}
|
||||
return uploadKeyRingToServer(hkpKeyserver, keyring, proxy);
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
Log.e(Constants.TAG, "error uploading key", e);
|
||||
return new UploadResult(UploadResult.RESULT_ERROR, new OperationLog());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return new UploadResult(UploadResult.RESULT_ERROR, new OperationLog());
|
||||
} catch (PgpGeneralException e) {
|
||||
e.printStackTrace();
|
||||
return new UploadResult(UploadResult.RESULT_ERROR, new OperationLog());
|
||||
}
|
||||
}
|
||||
|
||||
public UploadResult uploadKeyRingToServer(HkpKeyserver server, UncachedKeyRing keyring, Proxy proxy) {
|
||||
UploadResult uploadKeyRingToServer(HkpKeyserver server, CanonicalizedPublicKeyRing keyring, Proxy proxy) {
|
||||
|
||||
mProgressable.setProgress(R.string.progress_uploading, 0, 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user