Merge pull request #445 from gogowitczak/rwrsa-branch

Disabled possibility to generate weak RSA keys (512 and 1024 bit)
This commit is contained in:
Dominik Schürmann 2014-03-19 09:40:28 +01:00
commit 3416e51f84
3 changed files with 31 additions and 16 deletions

View File

@ -25,6 +25,7 @@ import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import org.sufficientlysecure.keychain.Id;
@ -113,21 +114,8 @@ public class CreateKeyDialogFragment extends DialogFragment {
public void onClick(DialogInterface di, int id) {
di.dismiss();
try {
int nKeyIndex = keySize.getSelectedItemPosition();
switch (nKeyIndex) {
case 0:
mNewKeySize = 512;
break;
case 1:
mNewKeySize = 1024;
break;
case 2:
mNewKeySize = 2048;
break;
case 3:
mNewKeySize = 4096;
break;
}
final String selectedItem = (String) keySize.getSelectedItem();
mNewKeySize = Integer.parseInt(selectedItem);
} catch (NumberFormatException e) {
mNewKeySize = 0;
}
@ -145,7 +133,26 @@ public class CreateKeyDialogFragment extends DialogFragment {
}
});
return dialog.create();
final AlertDialog alertDialog = dialog.create();
final AdapterView.OnItemSelectedListener weakRsaListener = new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final Choice selectedAlgorithm = (Choice)algorithm.getSelectedItem();
final int selectedKeySize = Integer.parseInt((String)keySize.getSelectedItem());
final boolean isWeakRsa = (selectedAlgorithm.getId() == Id.choice.algorithm.rsa && selectedKeySize <= 1024);
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(!isWeakRsa);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
};
keySize.setOnItemSelectedListener(weakRsaListener);
algorithm.setOnItemSelectedListener(weakRsaListener);
return alertDialog;
}
}

View File

@ -17,6 +17,13 @@
android:padding="4dp"
android:text="@string/key_creation_el_gamal_info" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="4dp"
android:text="@string/key_creation_weak_rsa_info" />
<TableRow>
<TextView

View File

@ -244,6 +244,7 @@
<string name="keys_exported">Successfully exported %d keys.</string>
<string name="no_keys_exported">No keys exported.</string>
<string name="key_creation_el_gamal_info">Note: only subkeys support ElGamal, and for ElGamal the nearest keysize of 1536, 2048, 3072, 4096, or 8192 will be used.</string>
<string name="key_creation_weak_rsa_info">Note: generating RSA key with length 1024-bit and less is considered unsafe and it\'s disabled for generating new keys.</string>
<string name="key_not_found">Couldn\'t find key %08X.</string>
<plurals name="keys_found">