mirror of
https://github.com/token2/fido2-manage.git
synced 2026-04-09 10:45:39 +00:00
Update gui1.py
This commit is contained in:
177
gui1.py
177
gui1.py
@@ -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
|
|
||||||
if PIN is None:
|
device_digit = match.group(1)
|
||||||
get_pin()
|
|
||||||
|
# Prompt for PIN if not already set
|
||||||
# Check again if PIN was entered
|
if PIN is None:
|
||||||
if PIN is None:
|
get_pin()
|
||||||
messagebox.showwarning("PIN Required", "PIN is required to manage passkeys.")
|
|
||||||
return
|
# Check again if PIN was entered
|
||||||
|
if PIN is None:
|
||||||
# Execute the command to get resident keys
|
messagebox.showwarning("PIN Required", "PIN is required to manage passkeys.")
|
||||||
command = [
|
return
|
||||||
FIDO_COMMAND,
|
|
||||||
"-residentKeys",
|
# Execute the command to get resident keys
|
||||||
"-pin",
|
command = [
|
||||||
PIN,
|
FIDO_COMMAND,
|
||||||
"-device",
|
"-residentKeys",
|
||||||
device_digit,
|
"-pin",
|
||||||
]
|
PIN,
|
||||||
try:
|
"-device",
|
||||||
result = subprocess.run(command, capture_output=True, text=True)
|
device_digit,
|
||||||
if result.returncode == 0:
|
]
|
||||||
# Parse the domains from the output
|
try:
|
||||||
domains = []
|
result = subprocess.run(command, capture_output=True, text=True)
|
||||||
for line in result.stdout.splitlines():
|
if result.returncode == 0:
|
||||||
match = re.search(r"= (.+)$", line)
|
# Parse the domains from the output
|
||||||
if match:
|
domains = []
|
||||||
domains.append(match.group(1))
|
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 for each domain
|
||||||
cumulated_output = []
|
cumulated_output = []
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
|
|
||||||
domain_command = [
|
domain_command = [
|
||||||
FIDO_COMMAND,
|
FIDO_COMMAND,
|
||||||
"-residentKeys",
|
"-residentKeys",
|
||||||
"-domain",
|
"-domain",
|
||||||
domain,
|
domain,
|
||||||
"-pin",
|
"-pin",
|
||||||
PIN,
|
PIN,
|
||||||
"-device",
|
"-device",
|
||||||
device_digit,
|
device_digit,
|
||||||
]
|
]
|
||||||
domain_result = subprocess.run(
|
domain_result = subprocess.run(
|
||||||
domain_command, capture_output=True, text=True
|
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():
|
||||||
|
|||||||
Reference in New Issue
Block a user