mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-12-24 07:58:50 -05:00
Select pub key when email could not be found
This commit is contained in:
parent
6fdae001cc
commit
4d1d3f6f5e
@ -1,17 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Encrypt User Id"
|
||||
android:text="Encrypt UserIds (split with ',')"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<EditText
|
||||
@ -22,7 +18,7 @@
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Message"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
@ -31,11 +27,13 @@
|
||||
android:id="@+id/crypto_provider_demo_message"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="150dip"
|
||||
android:scrollHorizontally="true"
|
||||
android:scrollbars="vertical"
|
||||
android:text="message"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Ciphertext"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
@ -47,10 +45,15 @@
|
||||
android:text="ciphertext"
|
||||
android:textAppearance="@android:style/TextAppearance.Small" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<Button
|
||||
android:id="@+id/crypto_provider_demo_encrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="encryptOnClick"
|
||||
android:text="Encrypt" />
|
||||
|
||||
@ -58,6 +61,7 @@
|
||||
android:id="@+id/crypto_provider_demo_sign"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="signOnClick"
|
||||
android:text="Sign" />
|
||||
|
||||
@ -65,6 +69,7 @@
|
||||
android:id="@+id/crypto_provider_demo_encrypt_and_sign"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="encryptAndSignOnClick"
|
||||
android:text="Encrypt and Sign" />
|
||||
|
||||
@ -72,8 +77,9 @@
|
||||
android:id="@+id/crypto_provider_demo_decrypt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:onClick="decryptOnClick"
|
||||
android:text="Decrypt" />
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
@ -35,12 +35,14 @@ import android.content.pm.ResolveInfo;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.RemoteException;
|
||||
import android.text.method.ScrollingMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.Scroller;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class CryptoProviderDemoActivity extends Activity {
|
||||
@ -48,7 +50,7 @@ public class CryptoProviderDemoActivity extends Activity {
|
||||
|
||||
EditText mMessage;
|
||||
EditText mCiphertext;
|
||||
EditText mEncryptUserId;
|
||||
EditText mEncryptUserIds;
|
||||
|
||||
private CryptoServiceConnection mCryptoServiceConnection;
|
||||
|
||||
@ -61,7 +63,7 @@ public class CryptoProviderDemoActivity extends Activity {
|
||||
|
||||
mMessage = (EditText) findViewById(R.id.crypto_provider_demo_message);
|
||||
mCiphertext = (EditText) findViewById(R.id.crypto_provider_demo_ciphertext);
|
||||
mEncryptUserId = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
|
||||
mEncryptUserIds = (EditText) findViewById(R.id.crypto_provider_demo_encrypt_user_id);
|
||||
|
||||
selectCryptoProvider();
|
||||
}
|
||||
@ -125,7 +127,7 @@ public class CryptoProviderDemoActivity extends Activity {
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().encrypt(inputBytes,
|
||||
new String[] { mEncryptUserId.getText().toString() }, encryptCallback);
|
||||
mEncryptUserIds.getText().toString().split(","), encryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
@ -146,7 +148,7 @@ public class CryptoProviderDemoActivity extends Activity {
|
||||
|
||||
try {
|
||||
mCryptoServiceConnection.getService().encryptAndSign(inputBytes,
|
||||
new String[] { mEncryptUserId.getText().toString() }, encryptCallback);
|
||||
mEncryptUserIds.getText().toString().split(","), encryptCallback);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(Constants.TAG, "CryptoProviderDemo", e);
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/api_select_pub_keys_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="8dp"
|
||||
android:paddingBottom="3dip"
|
||||
android:text="@string/api_select_pub_keys_text"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/api_select_pub_keys_fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
</LinearLayout>
|
@ -377,5 +377,6 @@
|
||||
<string name="api_register_allow">Allow access</string>
|
||||
<string name="api_register_disallow">Disallow access</string>
|
||||
<string name="api_register_error_select_key">Please select a key!</string>
|
||||
<string name="api_select_pub_keys_text">You have selected recipients (e.g. by selecting email addresses), which public keys could not be found. Please verify your selection!</string>
|
||||
|
||||
</resources>
|
@ -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,
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user