Select pub key when email could not be found
This commit is contained in:
@@ -735,14 +735,14 @@ public class PgpMain {
|
||||
*/
|
||||
public static void encryptAndSign(Context context, ProgressDialogUpdater progress,
|
||||
InputData data, OutputStream outStream, boolean useAsciiArmor, int compression,
|
||||
ArrayList<Long> encryptionKeyIds, String encryptionPassphrase,
|
||||
long[] encryptionKeyIds, String encryptionPassphrase,
|
||||
int symmetricEncryptionAlgorithm, long signatureKeyId, int signatureHashAlgorithm,
|
||||
boolean signatureForceV3, String signaturePassphrase) throws IOException,
|
||||
PgpGeneralException, PGPException, NoSuchProviderException, NoSuchAlgorithmException,
|
||||
SignatureException {
|
||||
|
||||
if (encryptionKeyIds == null) {
|
||||
encryptionKeyIds = new ArrayList<Long>();
|
||||
encryptionKeyIds = new long[0];
|
||||
}
|
||||
|
||||
ArmoredOutputStream armorOut = null;
|
||||
@@ -759,7 +759,7 @@ public class PgpMain {
|
||||
PGPSecretKeyRing signingKeyRing = null;
|
||||
PGPPrivateKey signaturePrivateKey = null;
|
||||
|
||||
if (encryptionKeyIds.size() == 0 && encryptionPassphrase == null) {
|
||||
if (encryptionKeyIds.length == 0 && encryptionPassphrase == null) {
|
||||
throw new PgpGeneralException(
|
||||
context.getString(R.string.error_noEncryptionKeysOrPassPhrase));
|
||||
}
|
||||
@@ -795,7 +795,7 @@ public class PgpMain {
|
||||
|
||||
PGPEncryptedDataGenerator cPk = new PGPEncryptedDataGenerator(encryptorBuilder);
|
||||
|
||||
if (encryptionKeyIds.size() == 0) {
|
||||
if (encryptionKeyIds.length == 0) {
|
||||
// Symmetric encryption
|
||||
Log.d(Constants.TAG, "encryptionKeyIds length is 0 -> symmetric encryption");
|
||||
|
||||
|
||||
@@ -112,7 +112,7 @@ public class CryptoService extends Service {
|
||||
* @param encryptionUserIds
|
||||
* @return
|
||||
*/
|
||||
private ArrayList<Long> getKeyIdsFromEmails(String[] encryptionUserIds) {
|
||||
private long[] getKeyIdsFromEmails(String[] encryptionUserIds, long ownKeyId) {
|
||||
// find key ids to given emails in database
|
||||
boolean manySameUserIds = false;
|
||||
boolean missingUserIds = false;
|
||||
@@ -133,9 +133,22 @@ public class CryptoService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: show selection activity on missingUserIds or manySameUserIds
|
||||
// also encrypt to our self (so that we can decrypt it later!)
|
||||
keyIds.add(ownKeyId);
|
||||
|
||||
return keyIds;
|
||||
// convert o long[]
|
||||
long[] keyIdsArray = new long[keyIds.size()];
|
||||
for (int i = 0; i < keyIdsArray.length; i++) {
|
||||
keyIdsArray[i] = keyIds.get(i);
|
||||
}
|
||||
|
||||
if (missingUserIds || manySameUserIds) {
|
||||
Bundle extras = new Bundle();
|
||||
extras.putLongArray(CryptoServiceActivity.EXTRA_SELECTED_MASTER_KEY_IDS, keyIdsArray);
|
||||
pauseQueueAndStartServiceActivity(CryptoServiceActivity.ACTION_SELECT_PUB_KEYS, extras);
|
||||
}
|
||||
|
||||
return keyIdsArray;
|
||||
}
|
||||
|
||||
private synchronized void encryptAndSignSafe(byte[] inputBytes, String[] encryptionUserIds,
|
||||
@@ -154,10 +167,7 @@ public class CryptoService extends Service {
|
||||
|
||||
OutputStream outputStream = new ByteArrayOutputStream();
|
||||
|
||||
ArrayList<Long> keyIds = getKeyIdsFromEmails(encryptionUserIds);
|
||||
|
||||
// also encrypt to our self (so that we can decrypt it later!)
|
||||
keyIds.add(appSettings.getKeyId());
|
||||
long[] keyIds = getKeyIdsFromEmails(encryptionUserIds, appSettings.getKeyId());
|
||||
|
||||
if (sign) {
|
||||
PgpMain.encryptAndSign(mContext, null, inputData, outputStream,
|
||||
@@ -384,7 +394,7 @@ public class CryptoService extends Service {
|
||||
@Override
|
||||
public void onSelectedPublicKeys(long[] keyIds) throws RemoteException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -21,9 +21,9 @@ import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.Id;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.ActionBarHelper;
|
||||
import org.sufficientlysecure.keychain.helper.OtherHelper;
|
||||
import org.sufficientlysecure.keychain.helper.PgpMain;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.ui.SelectPublicKeyFragment;
|
||||
import org.sufficientlysecure.keychain.ui.dialog.PassphraseDialogFragment;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
@@ -37,13 +37,9 @@ import android.os.IBinder;
|
||||
import android.os.Message;
|
||||
import android.os.Messenger;
|
||||
import android.os.RemoteException;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.actionbarsherlock.app.ActionBar;
|
||||
import com.actionbarsherlock.app.SherlockFragmentActivity;
|
||||
|
||||
public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
@@ -56,12 +52,15 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
|
||||
public static final String EXTRA_SECRET_KEY_ID = "secretKeyId";
|
||||
public static final String EXTRA_PACKAGE_NAME = "packageName";
|
||||
public static final String EXTRA_SELECTED_MASTER_KEY_IDS = "masterKeyIds";
|
||||
|
||||
private IServiceActivityCallback mServiceCallback;
|
||||
private boolean mServiceBound;
|
||||
|
||||
// register view
|
||||
AppSettingsFragment settingsFragment;
|
||||
AppSettingsFragment mSettingsFragment;
|
||||
// select pub key view
|
||||
SelectPublicKeyFragment mSelectFragment;
|
||||
|
||||
private ServiceConnection mServiceActivityConnection = new ServiceConnection() {
|
||||
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||
@@ -116,7 +115,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
// bind to our own crypto service
|
||||
bindToService();
|
||||
|
||||
handleActions(getIntent());
|
||||
handleActions(getIntent(), savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -129,7 +128,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleActions(Intent intent) {
|
||||
protected void handleActions(Intent intent, Bundle savedInstanceState) {
|
||||
String action = intent.getAction();
|
||||
Bundle extras = intent.getExtras();
|
||||
|
||||
@@ -151,13 +150,13 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
// Allow
|
||||
|
||||
// user needs to select a key!
|
||||
if (settingsFragment.getAppSettings().getKeyId() == Id.key.none) {
|
||||
if (mSettingsFragment.getAppSettings().getKeyId() == Id.key.none) {
|
||||
Toast.makeText(CryptoServiceActivity.this,
|
||||
R.string.api_register_error_select_key, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
} else {
|
||||
ProviderHelper.insertApiApp(CryptoServiceActivity.this,
|
||||
settingsFragment.getAppSettings());
|
||||
mSettingsFragment.getAppSettings());
|
||||
|
||||
try {
|
||||
mServiceCallback.onRegistered(true, packageName);
|
||||
@@ -183,11 +182,11 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
|
||||
setContentView(R.layout.api_app_register_activity);
|
||||
|
||||
settingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById(
|
||||
mSettingsFragment = (AppSettingsFragment) getSupportFragmentManager().findFragmentById(
|
||||
R.id.api_app_settings_fragment);
|
||||
|
||||
AppSettings settings = new AppSettings(packageName);
|
||||
settingsFragment.setAppSettings(settings);
|
||||
mSettingsFragment.setAppSettings(settings);
|
||||
|
||||
// TODO: handle if app is already registered
|
||||
// LinearLayout layoutRegister = (LinearLayout)
|
||||
@@ -211,6 +210,7 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
|
||||
showPassphraseDialog(secretKeyId);
|
||||
} else if (ACTION_SELECT_PUB_KEYS.equals(action)) {
|
||||
long[] selectedMasterKeyIds = intent.getLongArrayExtra(EXTRA_SELECTED_MASTER_KEY_IDS);
|
||||
|
||||
// Inflate a "Done"/"Cancel" custom action bar view
|
||||
ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_okay,
|
||||
@@ -219,15 +219,51 @@ public class CryptoServiceActivity extends SherlockFragmentActivity {
|
||||
public void onClick(View v) {
|
||||
// ok
|
||||
|
||||
try {
|
||||
mServiceCallback.onSelectedPublicKeys(mSelectFragment
|
||||
.getSelectedMasterKeyIds());
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "ServiceActivity");
|
||||
}
|
||||
finish();
|
||||
}
|
||||
}, R.string.btn_doNotSave, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
// cancel
|
||||
|
||||
// TODO: currently does the same as OK...
|
||||
try {
|
||||
mServiceCallback.onSelectedPublicKeys(mSelectFragment
|
||||
.getSelectedMasterKeyIds());
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "ServiceActivity");
|
||||
}
|
||||
finish();
|
||||
}
|
||||
});
|
||||
|
||||
setContentView(R.layout.api_app_select_pub_keys_activity);
|
||||
|
||||
// Check that the activity is using the layout version with
|
||||
// the fragment_container FrameLayout
|
||||
if (findViewById(R.id.api_select_pub_keys_fragment_container) != null) {
|
||||
|
||||
// However, if we're being restored from a previous state,
|
||||
// then we don't need to do anything and should return or else
|
||||
// we could end up with overlapping fragments.
|
||||
if (savedInstanceState != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create an instance of the fragment
|
||||
mSelectFragment = SelectPublicKeyFragment.newInstance(selectedMasterKeyIds);
|
||||
|
||||
// Add the fragment to the 'fragment_container' FrameLayout
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.add(R.id.api_select_pub_keys_fragment_container, mSelectFragment).commit();
|
||||
}
|
||||
|
||||
} else {
|
||||
Log.e(Constants.TAG, "Wrong action!");
|
||||
finish();
|
||||
|
||||
@@ -27,28 +27,26 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRing;
|
||||
import org.spongycastle.openpgp.PGPSecretKey;
|
||||
import org.spongycastle.openpgp.PGPSecretKeyRing;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.Id;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.helper.FileHelper;
|
||||
import org.sufficientlysecure.keychain.helper.OtherHelper;
|
||||
import org.sufficientlysecure.keychain.helper.PgpConversionHelper;
|
||||
import org.sufficientlysecure.keychain.helper.PgpMain;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.helper.PgpMain.PgpGeneralException;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.helper.Preferences;
|
||||
import org.sufficientlysecure.keychain.provider.KeychainContract.DataStream;
|
||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||
import org.sufficientlysecure.keychain.util.HkpKeyServer;
|
||||
import org.sufficientlysecure.keychain.util.InputData;
|
||||
import org.sufficientlysecure.keychain.util.KeyServer.KeyInfo;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
|
||||
import org.sufficientlysecure.keychain.util.KeyServer.KeyInfo;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
|
||||
import android.app.IntentService;
|
||||
import android.content.Context;
|
||||
@@ -316,11 +314,6 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
}
|
||||
|
||||
/* Operation */
|
||||
// convert to arraylist
|
||||
ArrayList<Long> keyIdsList = new ArrayList<Long>(encryptionKeyIds.length);
|
||||
for (long n : encryptionKeyIds)
|
||||
keyIdsList.add(n);
|
||||
|
||||
if (generateSignature) {
|
||||
Log.d(Constants.TAG, "generating signature...");
|
||||
PgpMain.generateSignature(this, this, inputData, outStream, useAsciiArmor,
|
||||
@@ -337,7 +330,7 @@ public class KeychainIntentService extends IntentService implements ProgressDial
|
||||
} else {
|
||||
Log.d(Constants.TAG, "encrypt...");
|
||||
PgpMain.encryptAndSign(this, this, inputData, outStream, useAsciiArmor,
|
||||
compressionId, keyIdsList, encryptionPassphrase, Preferences
|
||||
compressionId, encryptionKeyIds, encryptionPassphrase, Preferences
|
||||
.getPreferences(this).getDefaultEncryptionAlgorithm(),
|
||||
secretKeyId,
|
||||
Preferences.getPreferences(this).getDefaultHashAlgorithm(), Preferences
|
||||
|
||||
Reference in New Issue
Block a user