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);
} else {
try {
long subKeyId = mRequiredInput.getSubKeyId();
KeyRepository helper =
KeyRepository.create(getContext());
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;
long[] subKeyIds = mRequiredInput.getSubKeyIds();
if (subKeyIds.length > 1) {
message = getString(R.string.passphrase_for_any);
hint = getString(R.string.label_passphrase);
} else {
userId = getString(R.string.user_id_no_name);
}
long subKeyId = subKeyIds[0];
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)");
}
KeyRepository helper =
KeyRepository.create(getContext());
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 {
userId = getString(R.string.user_id_no_name);
}
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) {
alert.setTitle(R.string.title_key_not_found);
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_backup">"Enter backup code"</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_numeric">"Switch to numeric keyboard"</string>
<string name="pin_for">"Enter PIN for '%s'"</string>