Use one command for delete cert/key

This commit is contained in:
Elias Bonnici 2024-03-19 16:20:06 +01:00
parent ff6f72ae16
commit d70644e599
No known key found for this signature in database
GPG Key ID: 5EAC28EA3F980CCF
5 changed files with 23 additions and 38 deletions

View File

@ -389,13 +389,6 @@ class SlotNode(RpcNode):
self.certificate = certificate
self._refresh = refresh
def _require_version(self, major, minor, micro):
try:
require_version(self.session.version, (major, minor, micro))
return True
except NotSupportedError:
return False
def get_data(self):
return dict(
id=f"{int(self.slot):02x}",
@ -406,17 +399,20 @@ class SlotNode(RpcNode):
else None,
)
@action(condition=lambda self: self.certificate)
def delete_certificate(self, params, event, signal):
self.session.delete_certificate(self.slot)
self.session.put_object(OBJECT_ID.CHUID, generate_chuid())
self._refresh()
self.certificate = None
return dict()
@action(condition=lambda self: self.certificate or self.metadata)
def delete(self, params, event, signal):
delete_cert = params.pop("delete_cert", False)
delete_key = params.pop("delete_key", False)
@action(condition=lambda self: self.metadata and self._require_version(5, 7, 0))
def delete_key(self, params, event, signal):
self.session.delete_key(self.slot)
if not delete_cert and not delete_key:
raise ValueError("Missing delete option")
if delete_cert:
self.session.delete_certificate(self.slot)
self.session.put_object(OBJECT_ID.CHUID, generate_chuid())
self.certificate = None
if delete_key:
self.session.delete_key(self.slot)
self._refresh()
return dict()

View File

@ -317,14 +317,10 @@ class _DesktopPivSlotsNotifier extends PivSlotsNotifier {
}
@override
Future<void> deleteCertificate(SlotId slot) async {
await _session.command('delete_certificate', target: ['slots', slot.hexId]);
ref.invalidateSelf();
}
@override
Future<void> deleteKey(SlotId slot) async {
await _session.command('delete_key', target: ['slots', slot.hexId]);
Future<void> delete(SlotId slot, bool deleteCert, bool deleteKey) async {
await _session.command('delete',
target: ['slots', slot.hexId],
params: {'delete_cert': deleteCert, 'delete_key': deleteKey});
ref.invalidateSelf();
}

View File

@ -526,7 +526,7 @@
},
"l_generating_private_key": "Generating private key\u2026",
"s_private_key_generated": "Private key generated",
"p_select_what_to_delete": "Please select what to delete from the slot.",
"p_select_what_to_delete": "Select what to delete from the slot.",
"p_warning_delete_certificate": "Warning! This action will delete the certificate from your YubiKey.",
"p_warning_delete_key": "Warning! This action will delete the key from your YubiKey.",
"p_warning_delete_certificate_and_key": "Warning! This action will delete the certificate and key from your YubiKey.",

View File

@ -66,6 +66,5 @@ abstract class PivSlotsNotifier
PinPolicy pinPolicy = PinPolicy.dfault,
TouchPolicy touchPolicy = TouchPolicy.dfault,
});
Future<void> deleteCertificate(SlotId slot);
Future<void> deleteKey(SlotId slot);
Future<void> delete(SlotId slot, bool deleteCert, bool deleteKey);
}

View File

@ -71,16 +71,10 @@ class _DeleteCertificateDialogState
onPressed: _deleteKey || _deleteCertificate
? () async {
try {
if (_deleteCertificate) {
await ref
.read(pivSlotsProvider(widget.devicePath).notifier)
.deleteCertificate(widget.pivSlot.slot);
}
if (_deleteKey) {
await ref
.read(pivSlotsProvider(widget.devicePath).notifier)
.deleteKey(widget.pivSlot.slot);
}
await ref
.read(pivSlotsProvider(widget.devicePath).notifier)
.delete(widget.pivSlot.slot, _deleteCertificate,
_deleteKey);
await ref.read(withContextProvider)(
(context) async {