Show default PIN/PUK in ManagePinPukDialog.

This commit is contained in:
Elias Bonnici 2024-02-09 11:04:54 +01:00
parent 4e43ed81ee
commit 19404b5ce0
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
8 changed files with 78 additions and 22 deletions

View File

@ -274,6 +274,10 @@
"name": {} "name": {}
} }
}, },
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"l_default_pin_used": null,
"l_default_puk_used": null,
"@_passwords": {}, "@_passwords": {},
"s_password": "Passwort", "s_password": "Passwort",
@ -310,8 +314,6 @@
"s_generate_random": null, "s_generate_random": null,
"s_use_default": null, "s_use_default": null,
"l_warning_default_key": null, "l_warning_default_key": null,
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"s_protect_key": null, "s_protect_key": null,
"l_pin_protected_key": null, "l_pin_protected_key": null,
"l_wrong_key": null, "l_wrong_key": null,

View File

@ -274,6 +274,10 @@
"name": {} "name": {}
} }
}, },
"l_warning_default_pin": "Warning: Default PIN used",
"l_warning_default_puk": "Warning: Default PUK used",
"l_default_pin_used": "Default PIN used",
"l_default_puk_used": "Default PUK used",
"@_passwords": {}, "@_passwords": {},
"s_password": "Password", "s_password": "Password",
@ -310,8 +314,6 @@
"s_generate_random": "Generate random", "s_generate_random": "Generate random",
"s_use_default": "Use default", "s_use_default": "Use default",
"l_warning_default_key": "Warning: Default key used", "l_warning_default_key": "Warning: Default key used",
"l_warning_default_pin": "Warning: Default PIN used",
"l_warning_default_puk": "Warning: Default PUK used",
"s_protect_key": "Protect with PIN", "s_protect_key": "Protect with PIN",
"l_pin_protected_key": "PIN can be used instead", "l_pin_protected_key": "PIN can be used instead",
"l_wrong_key": "Wrong key", "l_wrong_key": "Wrong key",

View File

@ -274,6 +274,10 @@
"name": {} "name": {}
} }
}, },
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"l_default_pin_used": null,
"l_default_puk_used": null,
"@_passwords": {}, "@_passwords": {},
"s_password": "Mot de passe", "s_password": "Mot de passe",
@ -310,8 +314,6 @@
"s_generate_random": "Génération aléatoire", "s_generate_random": "Génération aléatoire",
"s_use_default": "Utiliser la valeur par défaut", "s_use_default": "Utiliser la valeur par défaut",
"l_warning_default_key": "Attention: Clé par défaut utilisée", "l_warning_default_key": "Attention: Clé par défaut utilisée",
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"s_protect_key": "Protection par PIN", "s_protect_key": "Protection par PIN",
"l_pin_protected_key": "Un PIN peut être utilisé à la place", "l_pin_protected_key": "Un PIN peut être utilisé à la place",
"l_wrong_key": "Mauvaise clé", "l_wrong_key": "Mauvaise clé",

View File

@ -274,6 +274,10 @@
"name": {} "name": {}
} }
}, },
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"l_default_pin_used": null,
"l_default_puk_used": null,
"@_passwords": {}, "@_passwords": {},
"s_password": "パスワード", "s_password": "パスワード",
@ -310,8 +314,6 @@
"s_generate_random": "ランダムに生成する", "s_generate_random": "ランダムに生成する",
"s_use_default": "デフォルトの使用", "s_use_default": "デフォルトの使用",
"l_warning_default_key": "警告: デフォルトのキーが使用されています", "l_warning_default_key": "警告: デフォルトのキーが使用されています",
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"s_protect_key": "PINで保護する", "s_protect_key": "PINで保護する",
"l_pin_protected_key": "代わりにPINを使用できます", "l_pin_protected_key": "代わりにPINを使用できます",
"l_wrong_key": "間違ったキー", "l_wrong_key": "間違ったキー",

View File

@ -274,6 +274,10 @@
"name": {} "name": {}
} }
}, },
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"l_default_pin_used": null,
"l_default_puk_used": null,
"@_passwords": {}, "@_passwords": {},
"s_password": "Hasło", "s_password": "Hasło",
@ -310,8 +314,6 @@
"s_generate_random": "Generuj losowo", "s_generate_random": "Generuj losowo",
"s_use_default": "Użyj domyślnego", "s_use_default": "Użyj domyślnego",
"l_warning_default_key": "Uwaga: Używany jest klucz domyślny", "l_warning_default_key": "Uwaga: Używany jest klucz domyślny",
"l_warning_default_pin": null,
"l_warning_default_puk": null,
"s_protect_key": "Zabezpiecz kodem PIN", "s_protect_key": "Zabezpiecz kodem PIN",
"l_pin_protected_key": "Zamiast tego można użyć kodu PIN", "l_pin_protected_key": "Zamiast tego można użyć kodu PIN",
"l_wrong_key": "Błędny klucz", "l_wrong_key": "Błędny klucz",

View File

@ -26,6 +26,8 @@ const defaultManagementKey = '010203040506070801020304050607080102030405060708';
const defaultManagementKeyType = ManagementKeyType.tdes; const defaultManagementKeyType = ManagementKeyType.tdes;
const defaultKeyType = KeyType.eccp256; const defaultKeyType = KeyType.eccp256;
const defaultGenerateType = GenerateType.certificate; const defaultGenerateType = GenerateType.certificate;
const defaultPin = '123456';
const defaultPuk = '12345678';
enum GenerateType { enum GenerateType {
publicKey, publicKey,

View File

@ -76,6 +76,7 @@ Widget pivBuildActions(BuildContext context, DevicePath devicePath,
context: context, context: context,
builder: (context) => ManagePinPukDialog( builder: (context) => ManagePinPukDialog(
devicePath, devicePath,
pivState,
target: pinBlocked target: pinBlocked
? ManageTarget.unblock ? ManageTarget.unblock
: ManageTarget.pin, : ManageTarget.pin,
@ -103,7 +104,8 @@ Widget pivBuildActions(BuildContext context, DevicePath devicePath,
Navigator.of(context).popUntil((route) => route.isFirst); Navigator.of(context).popUntil((route) => route.isFirst);
showBlurDialog( showBlurDialog(
context: context, context: context,
builder: (context) => ManagePinPukDialog(devicePath, builder: (context) => ManagePinPukDialog(
devicePath, pivState,
target: ManageTarget.puk), target: ManageTarget.puk),
); );
} }

View File

@ -24,14 +24,16 @@ import '../../widgets/app_input_decoration.dart';
import '../../widgets/app_text_field.dart'; import '../../widgets/app_text_field.dart';
import '../../widgets/responsive_dialog.dart'; import '../../widgets/responsive_dialog.dart';
import '../keys.dart' as keys; import '../keys.dart' as keys;
import '../models.dart';
import '../state.dart'; import '../state.dart';
enum ManageTarget { pin, puk, unblock } enum ManageTarget { pin, puk, unblock }
class ManagePinPukDialog extends ConsumerStatefulWidget { class ManagePinPukDialog extends ConsumerStatefulWidget {
final DevicePath path; final DevicePath path;
final PivState pivState;
final ManageTarget target; final ManageTarget target;
const ManagePinPukDialog(this.path, const ManagePinPukDialog(this.path, this.pivState,
{super.key, this.target = ManageTarget.pin}); {super.key, this.target = ManageTarget.pin});
@override @override
@ -40,7 +42,7 @@ class ManagePinPukDialog extends ConsumerStatefulWidget {
} }
class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> { class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
String _currentPin = ''; final _currentPinController = TextEditingController();
String _newPin = ''; String _newPin = '';
String _confirmPin = ''; String _confirmPin = '';
bool _currentIsWrong = false; bool _currentIsWrong = false;
@ -48,13 +50,40 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
bool _isObscureCurrent = true; bool _isObscureCurrent = true;
bool _isObscureNew = true; bool _isObscureNew = true;
bool _isObscureConfirm = true; bool _isObscureConfirm = true;
late bool _defaultPinUsed;
late bool _defaultPukUsed;
@override
void initState() {
super.initState();
_defaultPinUsed =
widget.pivState.metadata?.pinMetadata.defaultValue ?? false;
_defaultPukUsed =
widget.pivState.metadata?.pukMetadata.defaultValue ?? false;
if (widget.target == ManageTarget.pin && _defaultPinUsed) {
_currentPinController.text = defaultPin;
}
if (widget.target != ManageTarget.pin && _defaultPukUsed) {
_currentPinController.text = defaultPuk;
}
}
@override
void dispose() {
_currentPinController.dispose();
super.dispose();
}
_submit() async { _submit() async {
final notifier = ref.read(pivStateProvider(widget.path).notifier); final notifier = ref.read(pivStateProvider(widget.path).notifier);
final result = await switch (widget.target) { final result = await switch (widget.target) {
ManageTarget.pin => notifier.changePin(_currentPin, _newPin), ManageTarget.pin =>
ManageTarget.puk => notifier.changePuk(_currentPin, _newPin), notifier.changePin(_currentPinController.text, _newPin),
ManageTarget.unblock => notifier.unblockPin(_currentPin, _newPin), ManageTarget.puk =>
notifier.changePuk(_currentPinController.text, _newPin),
ManageTarget.unblock =>
notifier.unblockPin(_currentPinController.text, _newPin),
}; };
result.when(success: () { result.when(success: () {
@ -71,16 +100,17 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
setState(() { setState(() {
_attemptsRemaining = attemptsRemaining; _attemptsRemaining = attemptsRemaining;
_currentIsWrong = true; _currentIsWrong = true;
_currentPin = '';
}); });
_currentPinController.clear();
}); });
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context)!; final l10n = AppLocalizations.of(context)!;
final currentPin = _currentPinController.text;
final isValid = final isValid =
_newPin.isNotEmpty && _newPin == _confirmPin && _currentPin.isNotEmpty; _newPin.isNotEmpty && _newPin == _confirmPin && currentPin.isNotEmpty;
final titleText = switch (widget.target) { final titleText = switch (widget.target) {
ManageTarget.pin => l10n.s_change_pin, ManageTarget.pin => l10n.s_change_pin,
@ -88,6 +118,11 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
ManageTarget.unblock => l10n.s_unblock_pin, ManageTarget.unblock => l10n.s_unblock_pin,
}; };
final showDefaultPinUsed =
widget.target == ManageTarget.pin && _defaultPinUsed;
final showDefaultPukUsed =
widget.target != ManageTarget.pin && _defaultPukUsed;
return ResponsiveDialog( return ResponsiveDialog(
title: Text(titleText), title: Text(titleText),
actions: [ actions: [
@ -107,13 +142,20 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
? l10n.p_enter_current_pin_or_reset ? l10n.p_enter_current_pin_or_reset
: l10n.p_enter_current_puk_or_reset), : l10n.p_enter_current_puk_or_reset),
AppTextField( AppTextField(
autofocus: true, autofocus: !(showDefaultPinUsed || showDefaultPukUsed),
obscureText: _isObscureCurrent, obscureText: _isObscureCurrent,
maxLength: 8, maxLength: 8,
autofillHints: const [AutofillHints.password], autofillHints: const [AutofillHints.password],
key: keys.pinPukField, key: keys.pinPukField,
readOnly: showDefaultPinUsed || showDefaultPukUsed,
controller: _currentPinController,
decoration: AppInputDecoration( decoration: AppInputDecoration(
border: const OutlineInputBorder(), border: const OutlineInputBorder(),
helperText: showDefaultPinUsed
? l10n.l_default_pin_used
: showDefaultPukUsed
? l10n.l_default_puk_used
: null,
labelText: widget.target == ManageTarget.pin labelText: widget.target == ManageTarget.pin
? l10n.s_current_pin ? l10n.s_current_pin
: l10n.s_current_puk, : l10n.s_current_puk,
@ -144,7 +186,6 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
onChanged: (value) { onChanged: (value) {
setState(() { setState(() {
_currentIsWrong = false; _currentIsWrong = false;
_currentPin = value;
}); });
}, },
), ),
@ -152,6 +193,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
widget.target == ManageTarget.puk ? l10n.s_puk : l10n.s_pin)), widget.target == ManageTarget.puk ? l10n.s_puk : l10n.s_pin)),
AppTextField( AppTextField(
key: keys.newPinPukField, key: keys.newPinPukField,
autofocus: showDefaultPinUsed || showDefaultPukUsed,
obscureText: _isObscureNew, obscureText: _isObscureNew,
maxLength: 8, maxLength: 8,
autofillHints: const [AutofillHints.newPassword], autofillHints: const [AutofillHints.newPassword],
@ -174,7 +216,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
: (_isObscureNew ? l10n.s_show_puk : l10n.s_hide_puk), : (_isObscureNew ? l10n.s_show_puk : l10n.s_hide_puk),
), ),
// Old YubiKeys allowed a 4 digit PIN // Old YubiKeys allowed a 4 digit PIN
enabled: _currentPin.length >= 4, enabled: currentPin.length >= 4,
), ),
textInputAction: TextInputAction.next, textInputAction: TextInputAction.next,
onChanged: (value) { onChanged: (value) {
@ -212,7 +254,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
? (_isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin) ? (_isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin)
: (_isObscureConfirm ? l10n.s_show_puk : l10n.s_hide_puk), : (_isObscureConfirm ? l10n.s_show_puk : l10n.s_hide_puk),
), ),
enabled: _currentPin.length >= 4 && _newPin.length >= 6, enabled: currentPin.length >= 4 && _newPin.length >= 6,
), ),
textInputAction: TextInputAction.done, textInputAction: TextInputAction.done,
onChanged: (value) { onChanged: (value) {