PIV: Fix file import for FW < 5.3.

This commit is contained in:
Dain Nilsson 2023-08-30 14:13:08 +02:00
parent 0ce2e31630
commit af18b4ba52
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
3 changed files with 28 additions and 4 deletions

View File

@ -405,7 +405,7 @@ class SlotNode(RpcNode):
self.session.put_key(self.slot, private_key, pin_policy, touch_policy)
try:
metadata = self.session.get_slot_metadata(self.slot)
except (ApduError, BadResponseError):
except (ApduError, BadResponseError, NotSupportedError):
pass
certificate = _choose_cert(certs)

View File

@ -428,6 +428,8 @@
"l_certificate_exported": "Certificate exported",
"l_import_file": "Import file",
"l_import_desc": "Import a key and/or certificate",
"l_importing_file": "Importing file\u2026",
"s_file_imported": "File imported",
"l_delete_certificate": "Delete certificate",
"l_delete_certificate_desc": "Remove the certificate from your YubiKey",
"s_issuer": "Issuer",

View File

@ -20,7 +20,9 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../app/message.dart';
import '../../app/models.dart';
import '../../app/state.dart';
import '../../widgets/responsive_dialog.dart';
import '../models.dart';
import '../state.dart';
@ -47,6 +49,7 @@ class _ImportFileDialogState extends ConsumerState<ImportFileDialog> {
PivExamineResult? _state;
String _password = '';
bool _passwordIsWrong = false;
bool _importing = false;
@override
void initState() {
@ -153,10 +156,10 @@ class _ImportFileDialogState extends ConsumerState<ImportFileDialog> {
actions: [
TextButton(
key: keys.unlockButton,
onPressed: (keyType == null && certInfo == null)
onPressed: (keyType == null && certInfo == null) || _importing
? null
: () async {
final navigator = Navigator.of(context);
final withContext = ref.read(withContextProvider);
if (!await confirmOverwrite(
context,
@ -167,18 +170,37 @@ class _ImportFileDialogState extends ConsumerState<ImportFileDialog> {
return;
}
setState(() {
_importing = true;
});
void Function()? close;
try {
close = await withContext<void Function()>(
(context) async => showMessage(
context,
l10n.l_importing_file,
duration: const Duration(seconds: 30),
));
await ref
.read(pivSlotsProvider(widget.devicePath).notifier)
.import(widget.pivSlot.slot, _data,
password:
_password.isNotEmpty ? _password : null);
navigator.pop(true);
await withContext(
(context) async {
Navigator.of(context).pop(true);
showMessage(context, l10n.s_file_imported);
},
);
} catch (err) {
// TODO: More error cases
setState(() {
_passwordIsWrong = true;
_importing = false;
});
} finally {
close?.call();
}
},
child: Text(l10n.s_import),