Merge branch 'master' into backup-api
Conflicts: OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java extern/openpgp-api-lib
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||
* Copyright (C) 2014 Vincent Breitmoser <v.breitmoser@mugenguild.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
package org.sufficientlysecure.keychain.service;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
|
||||
public class ChangeUnlockParcel implements Parcelable {
|
||||
|
||||
// the master key id of keyring.
|
||||
public Long mMasterKeyId;
|
||||
// the key fingerprint, for safety.
|
||||
public byte[] mFingerprint;
|
||||
// The new passphrase to use
|
||||
public final Passphrase mNewPassphrase;
|
||||
|
||||
public ChangeUnlockParcel(Passphrase newPassphrase) {
|
||||
mNewPassphrase = newPassphrase;
|
||||
}
|
||||
|
||||
public ChangeUnlockParcel(Long masterKeyId, byte[] fingerprint, Passphrase newPassphrase) {
|
||||
if (newPassphrase == null) {
|
||||
throw new AssertionError("newPassphrase must be non-null. THIS IS A BUG!");
|
||||
}
|
||||
|
||||
mMasterKeyId = masterKeyId;
|
||||
mFingerprint = fingerprint;
|
||||
mNewPassphrase = newPassphrase;
|
||||
}
|
||||
|
||||
public ChangeUnlockParcel(Parcel source) {
|
||||
mMasterKeyId = source.readInt() != 0 ? source.readLong() : null;
|
||||
mFingerprint = source.createByteArray();
|
||||
mNewPassphrase = source.readParcelable(Passphrase.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel destination, int flags) {
|
||||
destination.writeInt(mMasterKeyId == null ? 0 : 1);
|
||||
if (mMasterKeyId != null) {
|
||||
destination.writeLong(mMasterKeyId);
|
||||
}
|
||||
destination.writeByteArray(mFingerprint);
|
||||
destination.writeParcelable(mNewPassphrase, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final Creator<ChangeUnlockParcel> CREATOR = new Creator<ChangeUnlockParcel>() {
|
||||
public ChangeUnlockParcel createFromParcel(final Parcel source) {
|
||||
return new ChangeUnlockParcel(source);
|
||||
}
|
||||
|
||||
public ChangeUnlockParcel[] newArray(final int size) {
|
||||
return new ChangeUnlockParcel[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String toString() {
|
||||
String out = "mMasterKeyId: " + mMasterKeyId + "\n";
|
||||
out += "passphrase (" + mNewPassphrase + ")";
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -143,6 +143,14 @@ public class ContactSyncAdapterService extends Service {
|
||||
}
|
||||
|
||||
public static void requestContactsSync() {
|
||||
// if user has disabled automatic sync, do nothing
|
||||
boolean isSyncEnabled = ContentResolver.getSyncAutomatically(new Account
|
||||
(Constants.ACCOUNT_NAME, Constants.ACCOUNT_TYPE), ContactsContract.AUTHORITY);
|
||||
|
||||
if (!isSyncEnabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
Bundle extras = new Bundle();
|
||||
// no need to wait, do it immediately
|
||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.sufficientlysecure.keychain.operations.BackupOperation;
|
||||
import org.sufficientlysecure.keychain.operations.ImportOperation;
|
||||
import org.sufficientlysecure.keychain.operations.KeybaseVerificationOperation;
|
||||
import org.sufficientlysecure.keychain.operations.InputDataOperation;
|
||||
import org.sufficientlysecure.keychain.operations.ChangeUnlockOperation;
|
||||
import org.sufficientlysecure.keychain.operations.PromoteKeyOperation;
|
||||
import org.sufficientlysecure.keychain.operations.RevokeOperation;
|
||||
import org.sufficientlysecure.keychain.operations.SignEncryptOperation;
|
||||
@@ -116,6 +117,8 @@ public class KeychainService extends Service implements Progressable {
|
||||
op = new PgpDecryptVerifyOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||
} else if (inputParcel instanceof SaveKeyringParcel) {
|
||||
op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||
} else if (inputParcel instanceof ChangeUnlockParcel) {
|
||||
op = new ChangeUnlockOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||
} else if (inputParcel instanceof RevokeKeyringParcel) {
|
||||
op = new RevokeOperation(outerThis, new ProviderHelper(outerThis), outerThis);
|
||||
} else if (inputParcel instanceof CertifyActionsParcel) {
|
||||
|
||||
@@ -11,11 +11,14 @@ import android.content.ContentProviderClient;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.PeriodicSync;
|
||||
import android.content.SyncResult;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
@@ -35,6 +38,7 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.receiver.NetworkReceiver;
|
||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||
@@ -68,7 +72,7 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
|
||||
private static final String ACTION_IGNORE_TOR = "ignore_tor";
|
||||
private static final String ACTION_UPDATE_ALL = "update_all";
|
||||
private static final String ACTION_SYNC_NOW = "sync_now";
|
||||
public static final String ACTION_SYNC_NOW = "sync_now";
|
||||
private static final String ACTION_DISMISS_NOTIFICATION = "cancel_sync";
|
||||
private static final String ACTION_START_ORBOT = "start_orbot";
|
||||
private static final String ACTION_CANCEL = "cancel";
|
||||
@@ -176,8 +180,25 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
@Override
|
||||
public void onPerformSync(Account account, Bundle extras, String authority,
|
||||
ContentProviderClient provider, SyncResult syncResult) {
|
||||
Log.d(Constants.TAG, "Performing a keyserver sync!");
|
||||
|
||||
Preferences prefs = Preferences.getPreferences(getContext());
|
||||
|
||||
// for a wifi-ONLY sync
|
||||
if (prefs.getWifiOnlySync()) {
|
||||
|
||||
ConnectivityManager connMgr = (ConnectivityManager)
|
||||
getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
NetworkInfo networkInfo = connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
boolean isNotOnWifi = !(networkInfo.getType() == ConnectivityManager.TYPE_WIFI);
|
||||
boolean isNotConnected = !(networkInfo.isConnected());
|
||||
|
||||
// if Wi-Fi connection doesn't exist then receiver is enabled
|
||||
if (isNotOnWifi && isNotConnected) {
|
||||
new NetworkReceiver().setWifiReceiverComponent(true, getContext());
|
||||
return;
|
||||
}
|
||||
}
|
||||
Log.d(Constants.TAG, "Performing a keyserver sync!");
|
||||
PowerManager pm = (PowerManager) KeyserverSyncAdapterService.this
|
||||
.getSystemService(Context.POWER_SERVICE);
|
||||
@SuppressWarnings("deprecation") // our min is API 15, deprecated only in 20
|
||||
@@ -509,6 +530,10 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a new sync if one does not exist, or updates an existing sync if the sync interval
|
||||
* has changed.
|
||||
*/
|
||||
public static void enableKeyserverSync(Context context) {
|
||||
Account account = KeychainApplication.createAccountIfNecessary(context);
|
||||
|
||||
@@ -519,12 +544,26 @@ public class KeyserverSyncAdapterService extends Service {
|
||||
|
||||
ContentResolver.setIsSyncable(account, Constants.PROVIDER_AUTHORITY, 1);
|
||||
ContentResolver.setSyncAutomatically(account, Constants.PROVIDER_AUTHORITY, true);
|
||||
ContentResolver.addPeriodicSync(
|
||||
account,
|
||||
Constants.PROVIDER_AUTHORITY,
|
||||
new Bundle(),
|
||||
SYNC_INTERVAL
|
||||
);
|
||||
|
||||
boolean intervalChanged = false;
|
||||
boolean syncExists = Preferences.getKeyserverSyncEnabled(context);
|
||||
|
||||
if (syncExists) {
|
||||
long oldInterval = ContentResolver.getPeriodicSyncs(
|
||||
account, Constants.PROVIDER_AUTHORITY).get(0).period;
|
||||
if (oldInterval != SYNC_INTERVAL) {
|
||||
intervalChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!syncExists || intervalChanged) {
|
||||
ContentResolver.addPeriodicSync(
|
||||
account,
|
||||
Constants.PROVIDER_AUTHORITY,
|
||||
new Bundle(),
|
||||
SYNC_INTERVAL
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isSyncEnabled() {
|
||||
|
||||
@@ -49,8 +49,6 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
// the key fingerprint, for safety. MUST be null for a new key.
|
||||
public byte[] mFingerprint;
|
||||
|
||||
public ChangeUnlockParcel mNewUnlock;
|
||||
|
||||
public ArrayList<String> mAddUserIds;
|
||||
public ArrayList<WrappedUserAttribute> mAddUserAttribute;
|
||||
public ArrayList<SubkeyAdd> mAddSubKeys;
|
||||
@@ -70,6 +68,9 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
private boolean mUploadAtomic;
|
||||
private String mKeyserver;
|
||||
|
||||
// private because we have to set other details like key id
|
||||
private ChangeUnlockParcel mNewUnlock;
|
||||
|
||||
public SaveKeyringParcel() {
|
||||
reset();
|
||||
}
|
||||
@@ -102,6 +103,18 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
mKeyserver = keysever;
|
||||
}
|
||||
|
||||
public void setNewUnlock(ChangeUnlockParcel parcel) {
|
||||
mNewUnlock = parcel;
|
||||
}
|
||||
|
||||
public ChangeUnlockParcel getChangeUnlockParcel() {
|
||||
if(mNewUnlock != null) {
|
||||
mNewUnlock.mMasterKeyId = mMasterKeyId;
|
||||
mNewUnlock.mFingerprint = mFingerprint;
|
||||
}
|
||||
return mNewUnlock;
|
||||
}
|
||||
|
||||
public boolean isUpload() {
|
||||
return mUpload;
|
||||
}
|
||||
@@ -344,64 +357,6 @@ public class SaveKeyringParcel implements Parcelable {
|
||||
// BRAINPOOL_P256, BRAINPOOL_P384, BRAINPOOL_P512
|
||||
}
|
||||
|
||||
/** This subclass contains information on how the passphrase should be changed.
|
||||
*
|
||||
* If no changes are to be made, this class should NOT be used!
|
||||
*
|
||||
* At this point, there must be *exactly one* non-null value here, which specifies the type
|
||||
* of unlocking mechanism to use.
|
||||
*
|
||||
*/
|
||||
public static class ChangeUnlockParcel implements Parcelable {
|
||||
|
||||
// The new passphrase to use
|
||||
public final Passphrase mNewPassphrase;
|
||||
// A new pin to use. Must only contain [0-9]+
|
||||
public final Passphrase mNewPin;
|
||||
|
||||
public ChangeUnlockParcel(Passphrase newPassphrase) {
|
||||
this(newPassphrase, null);
|
||||
}
|
||||
public ChangeUnlockParcel(Passphrase newPassphrase, Passphrase newPin) {
|
||||
if (newPassphrase == null && newPin == null) {
|
||||
throw new RuntimeException("Cannot set both passphrase and pin. THIS IS A BUG!");
|
||||
}
|
||||
mNewPassphrase = newPassphrase;
|
||||
mNewPin = newPin;
|
||||
}
|
||||
|
||||
public ChangeUnlockParcel(Parcel source) {
|
||||
mNewPassphrase = source.readParcelable(Passphrase.class.getClassLoader());
|
||||
mNewPin = source.readParcelable(Passphrase.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToParcel(Parcel destination, int flags) {
|
||||
destination.writeParcelable(mNewPassphrase, flags);
|
||||
destination.writeParcelable(mNewPin, flags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static final Creator<ChangeUnlockParcel> CREATOR = new Creator<ChangeUnlockParcel>() {
|
||||
public ChangeUnlockParcel createFromParcel(final Parcel source) {
|
||||
return new ChangeUnlockParcel(source);
|
||||
}
|
||||
|
||||
public ChangeUnlockParcel[] newArray(final int size) {
|
||||
return new ChangeUnlockParcel[size];
|
||||
}
|
||||
};
|
||||
|
||||
public String toString() {
|
||||
return mNewPassphrase != null
|
||||
? ("passphrase (" + mNewPassphrase + ")")
|
||||
: ("pin (" + mNewPin + ")");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@
|
||||
|
||||
package org.sufficientlysecure.keychain.service.input;
|
||||
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||
|
||||
import java.net.Proxy;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This is a base class for the input of crypto operations.
|
||||
*/
|
||||
|
||||
@@ -14,8 +14,8 @@ import java.util.Date;
|
||||
public class RequiredInputParcel implements Parcelable {
|
||||
|
||||
public enum RequiredInputType {
|
||||
PASSPHRASE, PASSPHRASE_SYMMETRIC, BACKUP_CODE, NFC_SIGN, NFC_DECRYPT,
|
||||
NFC_MOVE_KEY_TO_CARD, NFC_RESET_CARD, ENABLE_ORBOT, UPLOAD_FAIL_RETRY,
|
||||
PASSPHRASE, PASSPHRASE_SYMMETRIC, BACKUP_CODE, SECURITY_TOKEN_SIGN, SECURITY_TOKEN_DECRYPT,
|
||||
SECURITY_TOKEN_MOVE_KEY_TO_CARD, SECURITY_TOKEN_RESET_CARD, ENABLE_ORBOT, UPLOAD_FAIL_RETRY,
|
||||
}
|
||||
|
||||
public Date mSignatureTime;
|
||||
@@ -89,22 +89,22 @@ public class RequiredInputParcel implements Parcelable {
|
||||
return new RequiredInputParcel(RequiredInputType.ENABLE_ORBOT, null, null, null, 0L, 0L);
|
||||
}
|
||||
|
||||
public static RequiredInputParcel createNfcSignOperation(
|
||||
public static RequiredInputParcel createSecurityTokenSignOperation(
|
||||
long masterKeyId, long subKeyId,
|
||||
byte[] inputHash, int signAlgo, Date signatureTime) {
|
||||
return new RequiredInputParcel(RequiredInputType.NFC_SIGN,
|
||||
return new RequiredInputParcel(RequiredInputType.SECURITY_TOKEN_SIGN,
|
||||
new byte[][] { inputHash }, new int[] { signAlgo },
|
||||
signatureTime, masterKeyId, subKeyId);
|
||||
}
|
||||
|
||||
public static RequiredInputParcel createNfcDecryptOperation(
|
||||
public static RequiredInputParcel createSecurityTokenDecryptOperation(
|
||||
long masterKeyId, long subKeyId, byte[] encryptedSessionKey) {
|
||||
return new RequiredInputParcel(RequiredInputType.NFC_DECRYPT,
|
||||
return new RequiredInputParcel(RequiredInputType.SECURITY_TOKEN_DECRYPT,
|
||||
new byte[][] { encryptedSessionKey }, null, null, masterKeyId, subKeyId);
|
||||
}
|
||||
|
||||
public static RequiredInputParcel createNfcReset() {
|
||||
return new RequiredInputParcel(RequiredInputType.NFC_RESET_CARD,
|
||||
public static RequiredInputParcel createSecurityTokenReset() {
|
||||
return new RequiredInputParcel(RequiredInputType.SECURITY_TOKEN_RESET_CARD,
|
||||
null, null, null, null, null);
|
||||
}
|
||||
|
||||
@@ -188,14 +188,14 @@ public class RequiredInputParcel implements Parcelable {
|
||||
}
|
||||
};
|
||||
|
||||
public static class NfcSignOperationsBuilder {
|
||||
public static class SecurityTokenSignOperationsBuilder {
|
||||
Date mSignatureTime;
|
||||
ArrayList<Integer> mSignAlgos = new ArrayList<>();
|
||||
ArrayList<byte[]> mInputHashes = new ArrayList<>();
|
||||
long mMasterKeyId;
|
||||
long mSubKeyId;
|
||||
|
||||
public NfcSignOperationsBuilder(Date signatureTime, long masterKeyId, long subKeyId) {
|
||||
public SecurityTokenSignOperationsBuilder(Date signatureTime, long masterKeyId, long subKeyId) {
|
||||
mSignatureTime = signatureTime;
|
||||
mMasterKeyId = masterKeyId;
|
||||
mSubKeyId = subKeyId;
|
||||
@@ -209,7 +209,7 @@ public class RequiredInputParcel implements Parcelable {
|
||||
signAlgos[i] = mSignAlgos.get(i);
|
||||
}
|
||||
|
||||
return new RequiredInputParcel(RequiredInputType.NFC_SIGN,
|
||||
return new RequiredInputParcel(RequiredInputType.SECURITY_TOKEN_SIGN,
|
||||
inputHashes, signAlgos, mSignatureTime, mMasterKeyId, mSubKeyId);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ public class RequiredInputParcel implements Parcelable {
|
||||
if (!mSignatureTime.equals(input.mSignatureTime)) {
|
||||
throw new AssertionError("input times must match, this is a programming error!");
|
||||
}
|
||||
if (input.mType != RequiredInputType.NFC_SIGN) {
|
||||
if (input.mType != RequiredInputType.SECURITY_TOKEN_SIGN) {
|
||||
throw new AssertionError("operation types must match, this is a progrmming error!");
|
||||
}
|
||||
|
||||
@@ -238,13 +238,13 @@ public class RequiredInputParcel implements Parcelable {
|
||||
|
||||
}
|
||||
|
||||
public static class NfcKeyToCardOperationsBuilder {
|
||||
public static class SecurityTokenKeyToCardOperationsBuilder {
|
||||
ArrayList<byte[]> mSubkeysToExport = new ArrayList<>();
|
||||
Long mMasterKeyId;
|
||||
byte[] mPin;
|
||||
byte[] mAdminPin;
|
||||
|
||||
public NfcKeyToCardOperationsBuilder(Long masterKeyId) {
|
||||
public SecurityTokenKeyToCardOperationsBuilder(Long masterKeyId) {
|
||||
mMasterKeyId = masterKeyId;
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public class RequiredInputParcel implements Parcelable {
|
||||
ByteBuffer buf = ByteBuffer.wrap(mSubkeysToExport.get(0));
|
||||
|
||||
// We need to pass in a subkey here...
|
||||
return new RequiredInputParcel(RequiredInputType.NFC_MOVE_KEY_TO_CARD,
|
||||
return new RequiredInputParcel(RequiredInputType.SECURITY_TOKEN_MOVE_KEY_TO_CARD,
|
||||
inputData, null, null, mMasterKeyId, buf.getLong());
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ public class RequiredInputParcel implements Parcelable {
|
||||
if (!mMasterKeyId.equals(input.mMasterKeyId)) {
|
||||
throw new AssertionError("Master keys must match, this is a programming error!");
|
||||
}
|
||||
if (input.mType != RequiredInputType.NFC_MOVE_KEY_TO_CARD) {
|
||||
if (input.mType != RequiredInputType.SECURITY_TOKEN_MOVE_KEY_TO_CARD) {
|
||||
throw new AssertionError("Operation types must match, this is a programming error!");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user