Update gui1.py

This commit is contained in:
Token2
2026-01-08 19:37:47 +01:00
committed by GitHub
parent d448a77973
commit f979437958

171
gui1.py
View File

@@ -1,3 +1,26 @@
def execute_info_command_no_pin(device_digit):
"""Execute info command without PIN - just show basic device info"""
tree.delete(*tree.get_children())
# Execute info command without PIN
info_command = [FIDO_COMMAND, "-info", "-device", device_digit]
try:
result = subprocess.run(info_command, capture_output=True, text=True)
if result.returncode == 0:
for line in result.stdout.splitlines():
if ": " in line:
key, value = line.split(": ", 1)
tree.insert("", tk.END, values=(key, value))
else:
raise subprocess.CalledProcessError(result.returncode, info_command)
except Exception as e:
messagebox.showerror(
"Error", f"Command execution failed: {e}\nOutput: {result.stderr}"
)
return True
import os import os
import re import re
import subprocess import subprocess
@@ -115,7 +138,7 @@ def execute_info_command(device_digit):
"Warning", "Warning",
"No PIN set for this key. You must set a PIN before managing passkeys." "No PIN set for this key. You must set a PIN before managing passkeys."
) )
pin_button.config(text="Set PIN", state=tk.ACTIVE, command=set_pin) change_pin_button.config(text="Set PIN", state=tk.ACTIVE, command=set_pin)
return False return False
if result.stderr.find("FIDO_ERR_INVALID_CBOR") != -1: if result.stderr.find("FIDO_ERR_INVALID_CBOR") != -1:
@@ -178,19 +201,11 @@ def on_device_selected(event):
# Function to check if the "passkeys" button should be enabled # Function to check if the "passkeys" button should be enabled
def check_passkeys_button_state(): def check_passkeys_button_state():
passkeys_button_state = tk.DISABLED # Enable passkeys button if device is selected
for child in tree.get_children(): if device_var.get():
values = tree.item(child, "values") passkeys_button.config(state=tk.NORMAL)
if values and len(values) == 2 and values[0] == "existing rk(s)": else:
try: passkeys_button.config(state=tk.DISABLED)
rk_count = int(values[1])
if rk_count > 0:
passkeys_button_state = tk.NORMAL
break
except ValueError:
pass
passkeys_button.config(state=passkeys_button_state)
# Function to check if the change PIN button should be enabled # Function to check if the change PIN button should be enabled
@@ -213,78 +228,80 @@ def check_changepin_button_state():
# Function to handle "passkeys" button click # Function to handle "passkeys" button click
def on_passkeys_button_click(): def on_passkeys_button_click():
global PIN global PIN
# Get the selected device and PIN
# Get the selected device
selected_device = device_var.get() selected_device = device_var.get()
match = re.search(r"\[(\d+)\]", selected_device) match = re.search(r"\[(\d+)\]", selected_device)
if match: if not match:
device_digit = match.group(1) messagebox.showinfo("Device Selected", "No digit found in the selected device")
return
# Prompt for PIN if not already set device_digit = match.group(1)
if PIN is None:
get_pin()
# Check again if PIN was entered # Prompt for PIN if not already set
if PIN is None: if PIN is None:
messagebox.showwarning("PIN Required", "PIN is required to manage passkeys.") get_pin()
return
# Execute the command to get resident keys # Check again if PIN was entered
command = [ if PIN is None:
FIDO_COMMAND, messagebox.showwarning("PIN Required", "PIN is required to manage passkeys.")
"-residentKeys", return
"-pin",
PIN,
"-device",
device_digit,
]
try:
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode == 0:
# Parse the domains from the output
domains = []
for line in result.stdout.splitlines():
match = re.search(r"= (.+)$", line)
if match:
domains.append(match.group(1))
# Execute the command for each domain # Execute the command to get resident keys
cumulated_output = [] command = [
for domain in domains: FIDO_COMMAND,
"-residentKeys",
"-pin",
PIN,
"-device",
device_digit,
]
try:
result = subprocess.run(command, capture_output=True, text=True)
if result.returncode == 0:
# Parse the domains from the output
domains = []
for line in result.stdout.splitlines():
match = re.search(r"= (.+)$", line)
if match:
domains.append(match.group(1))
domain_command = [ # Execute the command for each domain
FIDO_COMMAND, cumulated_output = []
"-residentKeys", for domain in domains:
"-domain",
domain, domain_command = [
"-pin", FIDO_COMMAND,
PIN, "-residentKeys",
"-device", "-domain",
device_digit, domain,
] "-pin",
domain_result = subprocess.run( PIN,
domain_command, capture_output=True, text=True "-device",
device_digit,
]
domain_result = subprocess.run(
domain_command, capture_output=True, text=True
)
if domain_result.returncode == 0:
cumulated_output.append(
f"Domain: {domain}\n{domain_result.stdout}"
)
else:
raise subprocess.CalledProcessError(
domain_result.returncode, domain_command
) )
if domain_result.returncode == 0: # Show the cumulated output in a new window
cumulated_output.append( cumulated_output_str = "\n\n".join(cumulated_output)
f"Domain: {domain}\n{domain_result.stdout}" show_output_in_new_window(cumulated_output_str, device_digit)
) else:
else: raise subprocess.CalledProcessError(result.returncode, command)
raise subprocess.CalledProcessError( except Exception as e:
domain_result.returncode, domain_command messagebox.showerror(
) "Error", f"Command execution failed: {e}\nOutput: {result.stderr}"
)
# Show the cumulated output in a new window
cumulated_output_str = "\n\n".join(cumulated_output)
show_output_in_new_window(cumulated_output_str, device_digit)
else:
raise subprocess.CalledProcessError(result.returncode, command)
except Exception as e:
messagebox.showerror(
"Error", f"Command execution failed: {e}\nOutput: {result.stderr}"
)
else:
messagebox.showinfo("Device Selected", "No digit found in the selected device")
def set_pin(): def set_pin():