mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 12:32:17 -05:00
put return values into the Id class as well, changed encrypt file layout to use symmetric OR asymmetric again, layout and string adjustments
This commit is contained in:
parent
e83a5311ae
commit
88fc659ff6
@ -60,6 +60,12 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="1dip"
|
||||||
|
android:background="?android:attr/listDivider"
|
||||||
|
android:layout_marginBottom="5dip"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -112,6 +118,42 @@
|
|||||||
android:background="?android:attr/listDivider"
|
android:background="?android:attr/listDivider"
|
||||||
android:layout_marginBottom="5dip"/>
|
android:layout_marginBottom="5dip"/>
|
||||||
|
|
||||||
|
<RadioGroup
|
||||||
|
android:id="@+id/encryption_mode"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/use_asymmetric"
|
||||||
|
android:text="@string/use_asymmetric"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_gravity="center_vertical"/>
|
||||||
|
|
||||||
|
<RadioButton
|
||||||
|
android:id="@+id/use_symmetric"
|
||||||
|
android:text="@string/use_symmetric"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:layout_gravity="center_vertical"/>
|
||||||
|
|
||||||
|
</RadioGroup>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="1dip"
|
||||||
|
android:background="?android:attr/listDivider"
|
||||||
|
android:layout_marginBottom="5dip"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/layout_asymmetric"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -182,38 +224,10 @@
|
|||||||
android:layout_gravity="center_vertical"/>
|
android:layout_gravity="center_vertical"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<View
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="1dip"
|
|
||||||
android:background="?android:attr/listDivider"
|
|
||||||
android:layout_marginBottom="5dip"/>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/label_use_pass_phrase"
|
|
||||||
android:text="@string/label_use_pass_phrase"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:layout_gravity="center_vertical"
|
|
||||||
android:paddingRight="10dip"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="0dip"
|
|
||||||
android:layout_weight="1"/>
|
|
||||||
|
|
||||||
<CheckBox
|
|
||||||
android:id="@+id/use_pass_phrase"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_gravity="center_vertical"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<TableLayout
|
<TableLayout
|
||||||
android:id="@+id/layout_pass_phrase"
|
android:id="@+id/layout_symmetric"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:stretchColumns="1">
|
android:stretchColumns="1">
|
||||||
@ -223,6 +237,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/label_pass_phrase"
|
android:id="@+id/label_pass_phrase"
|
||||||
android:text="@string/label_pass_phrase"
|
android:text="@string/label_pass_phrase"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
@ -241,6 +256,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/label_pass_phrase_again"
|
android:id="@+id/label_pass_phrase_again"
|
||||||
android:text="@string/label_pass_phrase_again"
|
android:text="@string/label_pass_phrase_again"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
@ -256,6 +272,12 @@
|
|||||||
|
|
||||||
</TableLayout>
|
</TableLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="1dip"
|
||||||
|
android:background="?android:attr/listDivider"
|
||||||
|
android:layout_marginBottom="5dip"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
@ -65,11 +65,13 @@
|
|||||||
<string name="label_algorithm">Algorithm</string>
|
<string name="label_algorithm">Algorithm</string>
|
||||||
<string name="label_ascii_armour">ASCII Armour</string>
|
<string name="label_ascii_armour">ASCII Armour</string>
|
||||||
<string name="label_select_public_keys">Public Key(s)</string>
|
<string name="label_select_public_keys">Public Key(s)</string>
|
||||||
<string name="label_use_pass_phrase">Use Pass Phrase</string>
|
|
||||||
|
|
||||||
<string name="label_encryption_algorithm">Encryption Algorithm</string>
|
<string name="label_encryption_algorithm">Encryption Algorithm</string>
|
||||||
<string name="label_hash_algorithm">Hash Algorithm</string>
|
<string name="label_hash_algorithm">Hash Algorithm</string>
|
||||||
|
|
||||||
|
<string name="use_asymmetric">Public Key</string>
|
||||||
|
<string name="use_symmetric">Pass Phrase</string>
|
||||||
|
|
||||||
<string name="section_defaults">Defaults</string>
|
<string name="section_defaults">Defaults</string>
|
||||||
|
|
||||||
<string name="sign_only">Sign only</string>
|
<string name="sign_only">Sign only</string>
|
||||||
|
@ -138,11 +138,6 @@ public class Apg {
|
|||||||
|
|
||||||
protected static boolean mInitialized = false;
|
protected static boolean mInitialized = false;
|
||||||
|
|
||||||
protected static final int RETURN_NO_MASTER_KEY = -2;
|
|
||||||
protected static final int RETURN_ERROR = -1;
|
|
||||||
protected static final int RETURN_OK = 0;
|
|
||||||
protected static final int RETURN_UPDATED = 1;
|
|
||||||
|
|
||||||
protected static HashMap<Long, Integer> mSecretKeyIdToIdMap;
|
protected static HashMap<Long, Integer> mSecretKeyIdToIdMap;
|
||||||
protected static HashMap<Long, PGPSecretKeyRing> mSecretKeyIdToKeyRingMap;
|
protected static HashMap<Long, PGPSecretKeyRing> mSecretKeyIdToKeyRingMap;
|
||||||
protected static HashMap<Long, Integer> mPublicKeyIdToIdMap;
|
protected static HashMap<Long, Integer> mPublicKeyIdToIdMap;
|
||||||
@ -586,14 +581,14 @@ public class Apg {
|
|||||||
|
|
||||||
PGPPublicKey masterKey = getMasterKey(keyRing);
|
PGPPublicKey masterKey = getMasterKey(keyRing);
|
||||||
if (masterKey == null) {
|
if (masterKey == null) {
|
||||||
return RETURN_NO_MASTER_KEY;
|
return Id.return_value.no_master_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keyRing.encode(out);
|
keyRing.encode(out);
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return RETURN_ERROR;
|
return Id.return_value.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
values.put(PublicKeys.KEY_ID, masterKey.getKeyID());
|
values.put(PublicKeys.KEY_ID, masterKey.getKeyID());
|
||||||
@ -603,10 +598,10 @@ public class Apg {
|
|||||||
Cursor cursor = context.managedQuery(uri, PUBLIC_KEY_PROJECTION, null, null, null);
|
Cursor cursor = context.managedQuery(uri, PUBLIC_KEY_PROJECTION, null, null, null);
|
||||||
if (cursor != null && cursor.getCount() > 0) {
|
if (cursor != null && cursor.getCount() > 0) {
|
||||||
context.getContentResolver().update(uri, values, null, null);
|
context.getContentResolver().update(uri, values, null, null);
|
||||||
return RETURN_UPDATED;
|
return Id.return_value.updated;
|
||||||
} else {
|
} else {
|
||||||
context.getContentResolver().insert(PublicKeys.CONTENT_URI, values);
|
context.getContentResolver().insert(PublicKeys.CONTENT_URI, values);
|
||||||
return RETURN_OK;
|
return Id.return_value.ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -616,14 +611,14 @@ public class Apg {
|
|||||||
|
|
||||||
PGPSecretKey masterKey = getMasterKey(keyRing);
|
PGPSecretKey masterKey = getMasterKey(keyRing);
|
||||||
if (masterKey == null) {
|
if (masterKey == null) {
|
||||||
return RETURN_NO_MASTER_KEY;
|
return Id.return_value.no_master_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
keyRing.encode(out);
|
keyRing.encode(out);
|
||||||
out.close();
|
out.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return RETURN_ERROR;
|
return Id.return_value.error;
|
||||||
}
|
}
|
||||||
|
|
||||||
values.put(SecretKeys.KEY_ID, masterKey.getKeyID());
|
values.put(SecretKeys.KEY_ID, masterKey.getKeyID());
|
||||||
@ -633,10 +628,10 @@ public class Apg {
|
|||||||
Cursor cursor = context.managedQuery(uri, SECRET_KEY_PROJECTION, null, null, null);
|
Cursor cursor = context.managedQuery(uri, SECRET_KEY_PROJECTION, null, null, null);
|
||||||
if (cursor != null && cursor.getCount() > 0) {
|
if (cursor != null && cursor.getCount() > 0) {
|
||||||
context.getContentResolver().update(uri, values, null, null);
|
context.getContentResolver().update(uri, values, null, null);
|
||||||
return RETURN_UPDATED;
|
return Id.return_value.updated;
|
||||||
} else {
|
} else {
|
||||||
context.getContentResolver().insert(SecretKeys.CONTENT_URI, values);
|
context.getContentResolver().insert(SecretKeys.CONTENT_URI, values);
|
||||||
return RETURN_OK;
|
return Id.return_value.ok;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -690,13 +685,13 @@ public class Apg {
|
|||||||
retValue = saveKeyRing(context, publicKeyRing);
|
retValue = saveKeyRing(context, publicKeyRing);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retValue == RETURN_ERROR) {
|
if (retValue == Id.return_value.error) {
|
||||||
throw new GeneralException("error saving some key(s)");
|
throw new GeneralException("error saving some key(s)");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (retValue == RETURN_UPDATED) {
|
if (retValue == Id.return_value.updated) {
|
||||||
++oldKeys;
|
++oldKeys;
|
||||||
} else if (retValue == RETURN_OK) {
|
} else if (retValue == Id.return_value.ok) {
|
||||||
++newKeys;
|
++newKeys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,11 @@ import android.widget.Button;
|
|||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
|
import android.widget.RadioGroup;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import android.widget.RadioGroup.OnCheckedChangeListener;
|
||||||
|
|
||||||
public class EncryptFileActivity extends BaseActivity {
|
public class EncryptFileActivity extends BaseActivity {
|
||||||
private EditText mFilename = null;
|
private EditText mFilename = null;
|
||||||
@ -65,8 +67,9 @@ public class EncryptFileActivity extends BaseActivity {
|
|||||||
private EditText mPassPhrase = null;
|
private EditText mPassPhrase = null;
|
||||||
private EditText mPassPhraseAgain = null;
|
private EditText mPassPhraseAgain = null;
|
||||||
private CheckBox mAsciiArmour = null;
|
private CheckBox mAsciiArmour = null;
|
||||||
private CheckBox mUsePassPhrase = null;
|
private RadioGroup mEncryptionMode = null;
|
||||||
private ViewGroup mPassPhraseLayout = null;
|
private ViewGroup mAsymmetricLayout = null;
|
||||||
|
private ViewGroup mSymmetricLayout = null;
|
||||||
private Button mEncryptButton = null;
|
private Button mEncryptButton = null;
|
||||||
private Button mSelectKeysButton = null;
|
private Button mSelectKeysButton = null;
|
||||||
|
|
||||||
@ -145,28 +148,36 @@ public class EncryptFileActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mUsePassPhrase = (CheckBox) findViewById(R.id.use_pass_phrase);
|
mEncryptionMode = (RadioGroup) findViewById(R.id.encryption_mode);
|
||||||
mPassPhraseLayout = (ViewGroup) findViewById(R.id.layout_pass_phrase);
|
mAsymmetricLayout = (ViewGroup) findViewById(R.id.layout_asymmetric);
|
||||||
|
mSymmetricLayout = (ViewGroup) findViewById(R.id.layout_symmetric);
|
||||||
mPassPhrase = (EditText) findViewById(R.id.pass_phrase);
|
mPassPhrase = (EditText) findViewById(R.id.pass_phrase);
|
||||||
mPassPhraseAgain = (EditText) findViewById(R.id.pass_phrase_again);
|
mPassPhraseAgain = (EditText) findViewById(R.id.pass_phrase_again);
|
||||||
|
|
||||||
mUsePassPhrase.setOnClickListener(new OnClickListener() {
|
mEncryptionMode.check(R.id.use_asymmetric);
|
||||||
|
mEncryptionMode.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onCheckedChanged(RadioGroup group, int checkedId) {
|
||||||
CheckBox checkBox = (CheckBox) v;
|
if (checkedId == R.id.use_symmetric) {
|
||||||
if (checkBox.isChecked()) {
|
mAsymmetricLayout.setVisibility(ViewGroup.GONE);
|
||||||
mPassPhraseLayout.setVisibility(ViewGroup.VISIBLE);
|
mSymmetricLayout.setVisibility(ViewGroup.VISIBLE);
|
||||||
|
mEncryptionKeyIds = null;
|
||||||
|
setSecretKeyId(0);
|
||||||
} else {
|
} else {
|
||||||
|
mAsymmetricLayout.setVisibility(ViewGroup.VISIBLE);
|
||||||
|
mSymmetricLayout.setVisibility(ViewGroup.GONE);
|
||||||
mPassPhrase.setText("");
|
mPassPhrase.setText("");
|
||||||
mPassPhraseAgain.setText("");
|
mPassPhraseAgain.setText("");
|
||||||
mPassPhraseLayout.setVisibility(ViewGroup.GONE);
|
|
||||||
}
|
}
|
||||||
|
updateView();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (mUsePassPhrase.isChecked()) {
|
if (mEncryptionMode.getCheckedRadioButtonId() == R.id.use_symmetric) {
|
||||||
mPassPhraseLayout.setVisibility(ViewGroup.VISIBLE);
|
mAsymmetricLayout.setVisibility(ViewGroup.GONE);
|
||||||
|
mSymmetricLayout.setVisibility(ViewGroup.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
mPassPhraseLayout.setVisibility(ViewGroup.GONE);
|
mAsymmetricLayout.setVisibility(ViewGroup.VISIBLE);
|
||||||
|
mSymmetricLayout.setVisibility(ViewGroup.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
mEncryptButton.setOnClickListener(new OnClickListener() {
|
mEncryptButton.setOnClickListener(new OnClickListener() {
|
||||||
@ -258,8 +269,8 @@ public class EncryptFileActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// symmetric encryption
|
// symmetric encryption
|
||||||
|
if (mEncryptionMode.getCheckedRadioButtonId() == R.id.use_symmetric) {
|
||||||
boolean gotPassPhrase = false;
|
boolean gotPassPhrase = false;
|
||||||
if (mUsePassPhrase.isChecked()) {
|
|
||||||
String passPhrase = mPassPhrase.getText().toString();
|
String passPhrase = mPassPhrase.getText().toString();
|
||||||
String passPhraseAgain = mPassPhraseAgain.getText().toString();
|
String passPhraseAgain = mPassPhraseAgain.getText().toString();
|
||||||
if (!passPhrase.equals(passPhraseAgain)) {
|
if (!passPhrase.equals(passPhraseAgain)) {
|
||||||
@ -274,12 +285,11 @@ public class EncryptFileActivity extends BaseActivity {
|
|||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
|
||||||
boolean encryptIt = mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0;
|
boolean encryptIt = mEncryptionKeyIds != null && mEncryptionKeyIds.length > 0;
|
||||||
// for now require at least one form of encryption
|
// for now require at least one form of encryption
|
||||||
if (!encryptIt && !gotPassPhrase) {
|
if (!encryptIt) {
|
||||||
Toast.makeText(this, "Select at least one encryption key or a pass phrase.",
|
Toast.makeText(this, "Select at least one encryption key.",
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -288,6 +298,7 @@ public class EncryptFileActivity extends BaseActivity {
|
|||||||
showDialog(Id.dialog.pass_phrase);
|
showDialog(Id.dialog.pass_phrase);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
askForOutputFilename();
|
askForOutputFilename();
|
||||||
}
|
}
|
||||||
@ -324,10 +335,13 @@ public class EncryptFileActivity extends BaseActivity {
|
|||||||
InputStream in = new FileInputStream(mInputFilename);
|
InputStream in = new FileInputStream(mInputFilename);
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
|
|
||||||
String passPhrase = mPassPhrase.getText().toString();
|
String passPhrase = null;
|
||||||
|
if (mEncryptionMode.getCheckedRadioButtonId() == R.id.use_symmetric) {
|
||||||
|
passPhrase = mPassPhrase.getText().toString();
|
||||||
if (passPhrase.length() == 0) {
|
if (passPhrase.length() == 0) {
|
||||||
passPhrase = null;
|
passPhrase = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Apg.encrypt(in, out, mAsciiArmour.isChecked(),
|
Apg.encrypt(in, out, mAsciiArmour.isChecked(),
|
||||||
mEncryptionKeyIds, getSecretKeyId(),
|
mEncryptionKeyIds, getSecretKeyId(),
|
||||||
Apg.getPassPhrase(), this,
|
Apg.getPassPhrase(), this,
|
||||||
|
@ -95,4 +95,11 @@ public final class Id {
|
|||||||
public static final int sign_and_encrypt = 0x21070003;
|
public static final int sign_and_encrypt = 0x21070003;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final class return_value {
|
||||||
|
public static final int ok = 0;
|
||||||
|
public static final int error = -1;
|
||||||
|
public static final int no_master_key = -2;
|
||||||
|
public static final int updated = 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user