show more generic "Enter password" if asking for multiple

This commit is contained in:
Vincent Breitmoser
2017-11-23 22:23:43 +01:00
parent 04efa9e66d
commit 3bfb04f990
2 changed files with 37 additions and 31 deletions

View File

@@ -232,40 +232,45 @@ public class PassphraseDialogActivity extends FragmentActivity {
hint = getString(R.string.label_passphrase); hint = getString(R.string.label_passphrase);
} else { } else {
try { try {
long subKeyId = mRequiredInput.getSubKeyId(); long[] subKeyIds = mRequiredInput.getSubKeyIds();
if (subKeyIds.length > 1) {
KeyRepository helper = message = getString(R.string.passphrase_for_any);
KeyRepository.create(getContext()); hint = getString(R.string.label_passphrase);
CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing(
KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
// yes the inner try/catch block is necessary, otherwise the final variable
// above can't be statically verified to have been set in all cases because
// the catch clause doesn't return.
String mainUserId = cachedPublicKeyRing.getPrimaryUserIdWithFallback();
OpenPgpUtils.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId);
if (mainUserIdSplit.name != null) {
userId = mainUserIdSplit.name;
} else { } else {
userId = getString(R.string.user_id_no_name); long subKeyId = subKeyIds[0];
}
keyType = cachedPublicKeyRing.getSecretKeyType(subKeyId); KeyRepository helper =
switch (keyType) { KeyRepository.create(getContext());
case PASSPHRASE: CachedPublicKeyRing cachedPublicKeyRing = helper.getCachedPublicKeyRing(
message = getString(R.string.passphrase_for, userId); KeychainContract.KeyRings.buildUnifiedKeyRingsFindBySubkeyUri(subKeyId));
hint = getString(R.string.label_passphrase); // yes the inner try/catch block is necessary, otherwise the final variable
break; // above can't be statically verified to have been set in all cases because
case DIVERT_TO_CARD: // the catch clause doesn't return.
message = getString(R.string.security_token_pin_for, userId); String mainUserId = cachedPublicKeyRing.getPrimaryUserIdWithFallback();
hint = getString(R.string.label_pin); OpenPgpUtils.UserId mainUserIdSplit = KeyRing.splitUserId(mainUserId);
break; if (mainUserIdSplit.name != null) {
// special case: empty passphrase just returns the empty passphrase userId = mainUserIdSplit.name;
case PASSPHRASE_EMPTY: } else {
finishCaching(new Passphrase(""), subKeyId); userId = getString(R.string.user_id_no_name);
default: }
throw new AssertionError("Unhandled SecretKeyType (should not happen)");
}
keyType = cachedPublicKeyRing.getSecretKeyType(subKeyId);
switch (keyType) {
case PASSPHRASE:
message = getString(R.string.passphrase_for, userId);
hint = getString(R.string.label_passphrase);
break;
case DIVERT_TO_CARD:
message = getString(R.string.security_token_pin_for, userId);
hint = getString(R.string.label_pin);
break;
// special case: empty passphrase just returns the empty passphrase
case PASSPHRASE_EMPTY:
finishCaching(new Passphrase(""), subKeyId);
default:
throw new AssertionError("Unhandled SecretKeyType (should not happen)");
}
}
} catch (PgpKeyNotFoundException | KeyRepository.NotFoundException e) { } catch (PgpKeyNotFoundException | KeyRepository.NotFoundException e) {
alert.setTitle(R.string.title_key_not_found); alert.setTitle(R.string.title_key_not_found);
alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId())); alert.setMessage(getString(R.string.key_not_found, mRequiredInput.getSubKeyId()));

View File

@@ -332,6 +332,7 @@
<string name="passphrase_for_symmetric_encryption">"Enter password"</string> <string name="passphrase_for_symmetric_encryption">"Enter password"</string>
<string name="passphrase_for_backup">"Enter backup code"</string> <string name="passphrase_for_backup">"Enter backup code"</string>
<string name="passphrase_for">"Enter password for '%s'"</string> <string name="passphrase_for">"Enter password for '%s'"</string>
<string name="passphrase_for_any">"Enter password"</string>
<string name="passphrase_keyboard_hint_alpha">"Switch to alphabetic keyboard"</string> <string name="passphrase_keyboard_hint_alpha">"Switch to alphabetic keyboard"</string>
<string name="passphrase_keyboard_hint_numeric">"Switch to numeric keyboard"</string> <string name="passphrase_keyboard_hint_numeric">"Switch to numeric keyboard"</string>
<string name="pin_for">"Enter PIN for '%s'"</string> <string name="pin_for">"Enter PIN for '%s'"</string>