mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-12-23 10:11:52 +03:00
Show default PIN/PUK in ManagePinPukDialog
.
This commit is contained in:
parent
4e43ed81ee
commit
19404b5ce0
@ -274,6 +274,10 @@
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"l_warning_default_pin": null,
|
||||
"l_warning_default_puk": null,
|
||||
"l_default_pin_used": null,
|
||||
"l_default_puk_used": null,
|
||||
|
||||
"@_passwords": {},
|
||||
"s_password": "Passwort",
|
||||
@ -310,8 +314,6 @@
|
||||
"s_generate_random": null,
|
||||
"s_use_default": null,
|
||||
"l_warning_default_key": null,
|
||||
"l_warning_default_pin": null,
|
||||
"l_warning_default_puk": null,
|
||||
"s_protect_key": null,
|
||||
"l_pin_protected_key": null,
|
||||
"l_wrong_key": null,
|
||||
|
@ -274,6 +274,10 @@
|
||||
"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": {},
|
||||
"s_password": "Password",
|
||||
@ -310,8 +314,6 @@
|
||||
"s_generate_random": "Generate random",
|
||||
"s_use_default": "Use default",
|
||||
"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",
|
||||
"l_pin_protected_key": "PIN can be used instead",
|
||||
"l_wrong_key": "Wrong key",
|
||||
|
@ -274,6 +274,10 @@
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"l_warning_default_pin": null,
|
||||
"l_warning_default_puk": null,
|
||||
"l_default_pin_used": null,
|
||||
"l_default_puk_used": null,
|
||||
|
||||
"@_passwords": {},
|
||||
"s_password": "Mot de passe",
|
||||
@ -310,8 +314,6 @@
|
||||
"s_generate_random": "Génération aléatoire",
|
||||
"s_use_default": "Utiliser la valeur par défaut",
|
||||
"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",
|
||||
"l_pin_protected_key": "Un PIN peut être utilisé à la place",
|
||||
"l_wrong_key": "Mauvaise clé",
|
||||
|
@ -274,6 +274,10 @@
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"l_warning_default_pin": null,
|
||||
"l_warning_default_puk": null,
|
||||
"l_default_pin_used": null,
|
||||
"l_default_puk_used": null,
|
||||
|
||||
"@_passwords": {},
|
||||
"s_password": "パスワード",
|
||||
@ -310,8 +314,6 @@
|
||||
"s_generate_random": "ランダムに生成する",
|
||||
"s_use_default": "デフォルトの使用",
|
||||
"l_warning_default_key": "警告: デフォルトのキーが使用されています",
|
||||
"l_warning_default_pin": null,
|
||||
"l_warning_default_puk": null,
|
||||
"s_protect_key": "PINで保護する",
|
||||
"l_pin_protected_key": "代わりにPINを使用できます",
|
||||
"l_wrong_key": "間違ったキー",
|
||||
|
@ -274,6 +274,10 @@
|
||||
"name": {}
|
||||
}
|
||||
},
|
||||
"l_warning_default_pin": null,
|
||||
"l_warning_default_puk": null,
|
||||
"l_default_pin_used": null,
|
||||
"l_default_puk_used": null,
|
||||
|
||||
"@_passwords": {},
|
||||
"s_password": "Hasło",
|
||||
@ -310,8 +314,6 @@
|
||||
"s_generate_random": "Generuj losowo",
|
||||
"s_use_default": "Użyj domyślnego",
|
||||
"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",
|
||||
"l_pin_protected_key": "Zamiast tego można użyć kodu PIN",
|
||||
"l_wrong_key": "Błędny klucz",
|
||||
|
@ -26,6 +26,8 @@ const defaultManagementKey = '010203040506070801020304050607080102030405060708';
|
||||
const defaultManagementKeyType = ManagementKeyType.tdes;
|
||||
const defaultKeyType = KeyType.eccp256;
|
||||
const defaultGenerateType = GenerateType.certificate;
|
||||
const defaultPin = '123456';
|
||||
const defaultPuk = '12345678';
|
||||
|
||||
enum GenerateType {
|
||||
publicKey,
|
||||
|
@ -76,6 +76,7 @@ Widget pivBuildActions(BuildContext context, DevicePath devicePath,
|
||||
context: context,
|
||||
builder: (context) => ManagePinPukDialog(
|
||||
devicePath,
|
||||
pivState,
|
||||
target: pinBlocked
|
||||
? ManageTarget.unblock
|
||||
: ManageTarget.pin,
|
||||
@ -103,7 +104,8 @@ Widget pivBuildActions(BuildContext context, DevicePath devicePath,
|
||||
Navigator.of(context).popUntil((route) => route.isFirst);
|
||||
showBlurDialog(
|
||||
context: context,
|
||||
builder: (context) => ManagePinPukDialog(devicePath,
|
||||
builder: (context) => ManagePinPukDialog(
|
||||
devicePath, pivState,
|
||||
target: ManageTarget.puk),
|
||||
);
|
||||
}
|
||||
|
@ -24,14 +24,16 @@ import '../../widgets/app_input_decoration.dart';
|
||||
import '../../widgets/app_text_field.dart';
|
||||
import '../../widgets/responsive_dialog.dart';
|
||||
import '../keys.dart' as keys;
|
||||
import '../models.dart';
|
||||
import '../state.dart';
|
||||
|
||||
enum ManageTarget { pin, puk, unblock }
|
||||
|
||||
class ManagePinPukDialog extends ConsumerStatefulWidget {
|
||||
final DevicePath path;
|
||||
final PivState pivState;
|
||||
final ManageTarget target;
|
||||
const ManagePinPukDialog(this.path,
|
||||
const ManagePinPukDialog(this.path, this.pivState,
|
||||
{super.key, this.target = ManageTarget.pin});
|
||||
|
||||
@override
|
||||
@ -40,7 +42,7 @@ class ManagePinPukDialog extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
String _currentPin = '';
|
||||
final _currentPinController = TextEditingController();
|
||||
String _newPin = '';
|
||||
String _confirmPin = '';
|
||||
bool _currentIsWrong = false;
|
||||
@ -48,13 +50,40 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
bool _isObscureCurrent = true;
|
||||
bool _isObscureNew = 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 {
|
||||
final notifier = ref.read(pivStateProvider(widget.path).notifier);
|
||||
final result = await switch (widget.target) {
|
||||
ManageTarget.pin => notifier.changePin(_currentPin, _newPin),
|
||||
ManageTarget.puk => notifier.changePuk(_currentPin, _newPin),
|
||||
ManageTarget.unblock => notifier.unblockPin(_currentPin, _newPin),
|
||||
ManageTarget.pin =>
|
||||
notifier.changePin(_currentPinController.text, _newPin),
|
||||
ManageTarget.puk =>
|
||||
notifier.changePuk(_currentPinController.text, _newPin),
|
||||
ManageTarget.unblock =>
|
||||
notifier.unblockPin(_currentPinController.text, _newPin),
|
||||
};
|
||||
|
||||
result.when(success: () {
|
||||
@ -71,16 +100,17 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
setState(() {
|
||||
_attemptsRemaining = attemptsRemaining;
|
||||
_currentIsWrong = true;
|
||||
_currentPin = '';
|
||||
});
|
||||
_currentPinController.clear();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final currentPin = _currentPinController.text;
|
||||
final isValid =
|
||||
_newPin.isNotEmpty && _newPin == _confirmPin && _currentPin.isNotEmpty;
|
||||
_newPin.isNotEmpty && _newPin == _confirmPin && currentPin.isNotEmpty;
|
||||
|
||||
final titleText = switch (widget.target) {
|
||||
ManageTarget.pin => l10n.s_change_pin,
|
||||
@ -88,6 +118,11 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
ManageTarget.unblock => l10n.s_unblock_pin,
|
||||
};
|
||||
|
||||
final showDefaultPinUsed =
|
||||
widget.target == ManageTarget.pin && _defaultPinUsed;
|
||||
final showDefaultPukUsed =
|
||||
widget.target != ManageTarget.pin && _defaultPukUsed;
|
||||
|
||||
return ResponsiveDialog(
|
||||
title: Text(titleText),
|
||||
actions: [
|
||||
@ -107,13 +142,20 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
? l10n.p_enter_current_pin_or_reset
|
||||
: l10n.p_enter_current_puk_or_reset),
|
||||
AppTextField(
|
||||
autofocus: true,
|
||||
autofocus: !(showDefaultPinUsed || showDefaultPukUsed),
|
||||
obscureText: _isObscureCurrent,
|
||||
maxLength: 8,
|
||||
autofillHints: const [AutofillHints.password],
|
||||
key: keys.pinPukField,
|
||||
readOnly: showDefaultPinUsed || showDefaultPukUsed,
|
||||
controller: _currentPinController,
|
||||
decoration: AppInputDecoration(
|
||||
border: const OutlineInputBorder(),
|
||||
helperText: showDefaultPinUsed
|
||||
? l10n.l_default_pin_used
|
||||
: showDefaultPukUsed
|
||||
? l10n.l_default_puk_used
|
||||
: null,
|
||||
labelText: widget.target == ManageTarget.pin
|
||||
? l10n.s_current_pin
|
||||
: l10n.s_current_puk,
|
||||
@ -144,7 +186,6 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
onChanged: (value) {
|
||||
setState(() {
|
||||
_currentIsWrong = false;
|
||||
_currentPin = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
@ -152,6 +193,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
widget.target == ManageTarget.puk ? l10n.s_puk : l10n.s_pin)),
|
||||
AppTextField(
|
||||
key: keys.newPinPukField,
|
||||
autofocus: showDefaultPinUsed || showDefaultPukUsed,
|
||||
obscureText: _isObscureNew,
|
||||
maxLength: 8,
|
||||
autofillHints: const [AutofillHints.newPassword],
|
||||
@ -174,7 +216,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
: (_isObscureNew ? l10n.s_show_puk : l10n.s_hide_puk),
|
||||
),
|
||||
// Old YubiKeys allowed a 4 digit PIN
|
||||
enabled: _currentPin.length >= 4,
|
||||
enabled: currentPin.length >= 4,
|
||||
),
|
||||
textInputAction: TextInputAction.next,
|
||||
onChanged: (value) {
|
||||
@ -212,7 +254,7 @@ class _ManagePinPukDialogState extends ConsumerState<ManagePinPukDialog> {
|
||||
? (_isObscureConfirm ? l10n.s_show_pin : l10n.s_hide_pin)
|
||||
: (_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,
|
||||
onChanged: (value) {
|
||||
|
Loading…
Reference in New Issue
Block a user