ElGamal support added, fix of some minor GUI bugs, added a bunch of safe primes for ElGamal key creation

This commit is contained in:
Thialfihar
2010-04-24 17:40:09 +00:00
parent e30a531229
commit 81cdd6b943
7 changed files with 287 additions and 40 deletions

View File

@@ -22,6 +22,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Vector;
import org.bouncycastle2.openpgp.PGPPublicKey;
import org.bouncycastle2.openpgp.PGPSecretKey;
import org.thialfihar.android.apg.Apg;
import org.thialfihar.android.apg.Id;
@@ -150,30 +151,42 @@ public class KeyEditor extends LinearLayout implements Editor, OnClickListener {
mKeyId.setText(keyId1Str + " " + keyId2Str);
Vector<Choice> choices = new Vector<Choice>();
choices.add(new Choice(Id.choice.usage.sign_only,
getResources().getString(R.string.sign_only)));
boolean isElGamalKey = (key.getPublicKey().getAlgorithm() == PGPPublicKey.ELGAMAL_ENCRYPT);
if (!isElGamalKey) {
choices.add(new Choice(Id.choice.usage.sign_only,
getResources().getString(R.string.sign_only)));
}
if (!mIsMasterKey) {
choices.add(new Choice(Id.choice.usage.encrypt_only,
getResources().getString(R.string.encrypt_only)));
}
choices.add(new Choice(Id.choice.usage.sign_and_encrypt,
getResources().getString(R.string.sign_and_encrypt)));
if (!isElGamalKey) {
choices.add(new Choice(Id.choice.usage.sign_and_encrypt,
getResources().getString(R.string.sign_and_encrypt)));
}
ArrayAdapter<Choice> adapter =
new ArrayAdapter<Choice>(getContext(),
android.R.layout.simple_spinner_item,
choices);
android.R.layout.simple_spinner_item, choices);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mUsage.setAdapter(adapter);
int selectId = 0;
if (Apg.isEncryptionKey(key)) {
if (Apg.isSigningKey(key)) {
mUsage.setSelection(2);
selectId = Id.choice.usage.sign_and_encrypt;
} else {
mUsage.setSelection(1);
selectId = Id.choice.usage.encrypt_only;
}
} else {
mUsage.setSelection(0);
selectId = Id.choice.usage.sign_only;
}
for (int i = 0; i < choices.size(); ++i) {
if (choices.get(i).getId() == selectId) {
mUsage.setSelection(i);
break;
}
}
GregorianCalendar cal = new GregorianCalendar();

View File

@@ -181,16 +181,23 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
View view = mInflater.inflate(R.layout.create_key, null);
dialog.setView(view);
dialog.setTitle("Create Key");
dialog.setMessage("Note: only subkeys support ElGamal, and for ElGamal will use " +
"the next smallest keysize of 1536, 2048, 3072, 4096, or 8192.");
boolean wouldBeMasterKey = (mEditors.getChildCount() == 0);
final Spinner algorithm = (Spinner) view.findViewById(R.id.algorithm);
Choice choices[] = {
new Choice(Id.choice.algorithm.dsa,
getResources().getString(R.string.dsa)),
/*new Choice(Id.choice.algorithm.elgamal,
getResources().getString(R.string.elgamal)),*/
new Choice(Id.choice.algorithm.rsa,
getResources().getString(R.string.rsa)),
};
Vector<Choice> choices = new Vector<Choice>();
choices.add(new Choice(Id.choice.algorithm.dsa,
getResources().getString(R.string.dsa)));
if (!wouldBeMasterKey) {
choices.add(new Choice(Id.choice.algorithm.elgamal,
getResources().getString(R.string.elgamal)));
}
choices.add(new Choice(Id.choice.algorithm.rsa,
getResources().getString(R.string.rsa)));
ArrayAdapter<Choice> adapter =
new ArrayAdapter<Choice>(getContext(),
android.R.layout.simple_spinner_item,
@@ -198,8 +205,8 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
algorithm.setAdapter(adapter);
// make RSA the default
for (int i = 0; i < choices.length; ++i) {
if (choices[i].getId() == Id.choice.algorithm.rsa) {
for (int i = 0; i < choices.size(); ++i) {
if (choices.get(i).getId() == Id.choice.algorithm.rsa) {
algorithm.setSelection(i);
break;
}
@@ -294,8 +301,12 @@ public class SectionView extends LinearLayout implements OnClickListener, Editor
public void run() {
String error = null;
try {
PGPSecretKey masterKey = null;
if (mEditors.getChildCount() > 0) {
masterKey = ((KeyEditor) mEditors.getChildAt(0)).getValue();
}
mNewKey = Apg.createKey(mNewKeyAlgorithmChoice.getId(),
mNewKeySize, Apg.getPassPhrase());
mNewKeySize, Apg.getPassPhrase(), masterKey);
} catch (NoSuchProviderException e) {
error = e.getMessage();
} catch (NoSuchAlgorithmException e) {