mirror of
https://github.com/librekeys/picoforge.git
synced 2026-07-28 08:01:19 -07:00
feat: Fido2 pin configuration and device info for pico-key
- Added more infomration about the pico-key on the home page. - Added config option to change the pin of the pico-fido key. - Improved the UI of Home and Confifuration.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
"fmt": {
|
||||
"useTabs": false,
|
||||
"indentWidth": 2,
|
||||
"lineWidth": 120,
|
||||
"lineWidth": 140,
|
||||
|
||||
"include": ["src"],
|
||||
|
||||
|
||||
@@ -1,6 +1,33 @@
|
||||
use ctap_hid_fido2::{Cfg, FidoKeyHidFactory};
|
||||
use crate::types::FidoDeviceInfo;
|
||||
use std::collections::HashMap;
|
||||
// use ctap_hid_fido2::fidokey::FidoKeyHid;
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) fn get_fido_info() -> Result<FidoDeviceInfo, String> {
|
||||
let cfg = Cfg::init();
|
||||
|
||||
let device = FidoKeyHidFactory::create(&cfg)
|
||||
.map_err(|_| "Could not connect to FIDO device. Is it plugged in?".to_string())?;
|
||||
|
||||
let info = device
|
||||
.get_info()
|
||||
.map_err(|e| format!("Error reading device info: {:?}", e))?;
|
||||
|
||||
let options_map: HashMap<String, bool> = info.options.into_iter().collect();
|
||||
|
||||
Ok(FidoDeviceInfo {
|
||||
versions: info.versions,
|
||||
extensions: info.extensions,
|
||||
aaguid: hex::encode_upper(info.aaguid),
|
||||
options: options_map,
|
||||
max_msg_size: info.max_msg_size,
|
||||
pin_protocols: info.pin_uv_auth_protocols,
|
||||
min_pin_length: info.min_pin_length,
|
||||
firmware_version: format!("0x{:X}", info.firmware_version),
|
||||
})
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub(crate) fn change_fido_pin(
|
||||
current_pin: Option<String>,
|
||||
|
||||
@@ -17,6 +17,7 @@ pub fn run() {
|
||||
rescue::read_device_details,
|
||||
rescue::get_device_info,
|
||||
rescue::write_config,
|
||||
fido::get_fido_info,
|
||||
fido::change_fido_pin,
|
||||
fido::set_min_pin_length,
|
||||
rescue::enable_secure_boot
|
||||
|
||||
@@ -78,6 +78,24 @@ pub struct FullDeviceStatus {
|
||||
pub secure_lock: bool,
|
||||
}
|
||||
|
||||
// Fido stuff:
|
||||
|
||||
#[derive(Serialize)]
|
||||
pub struct FidoDeviceInfo {
|
||||
pub versions: Vec<String>,
|
||||
pub extensions: Vec<String>,
|
||||
pub aaguid: String,
|
||||
pub options: std::collections::HashMap<String, bool>,
|
||||
pub max_msg_size: i32,
|
||||
pub pin_protocols: Vec<u32>,
|
||||
// pub remaining_disc_creds: u32,
|
||||
pub min_pin_length: u32,
|
||||
pub firmware_version: String,
|
||||
}
|
||||
|
||||
|
||||
// Error stuff:
|
||||
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum AppError {
|
||||
#[error("PCSC Error: {0}")]
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
import { logger } from "$lib/utils/log.svelte";
|
||||
import { DEFAULT_CONFIG, DEFAULT_DEVICE_INFO, VENDORS } from "$lib/device/constants.svelte";
|
||||
import type { DeviceConfig, DeviceInfo, SecurityState } from "$lib/device/types.svelte";
|
||||
import type { DeviceConfig, DeviceInfo, FidoInfo, SecurityState } from "$lib/device/types.svelte";
|
||||
|
||||
class DeviceManager {
|
||||
loading = $state(false);
|
||||
connected = $state(false);
|
||||
fidoInfo: FidoInfo | null = $state(null);
|
||||
|
||||
config: DeviceConfig = $state({ ...DEFAULT_CONFIG });
|
||||
info: DeviceInfo = $state({ ...DEFAULT_DEVICE_INFO });
|
||||
@@ -60,6 +61,19 @@ class DeviceManager {
|
||||
confirmed: false,
|
||||
};
|
||||
|
||||
const fido: any = await invoke("get_fido_info");
|
||||
this.fidoInfo = {
|
||||
versions: fido.versions,
|
||||
extensions: fido.extensions,
|
||||
aaguid: fido.aaguid,
|
||||
options: fido.options,
|
||||
maxMsgSize: fido.max_msg_size,
|
||||
pinProtocols: fido.pin_protocols,
|
||||
// remainingDiscCreds: fido.remaining_disc_creds,
|
||||
minPinLength: fido.min_pin_length,
|
||||
firmwareVersion: fido.firmware_version,
|
||||
};
|
||||
|
||||
if (!this.connected) {
|
||||
logger.add(
|
||||
`Device Connected! Serial: ${this.info.serial}, FW: v${this.info.firmwareVersion}`,
|
||||
@@ -162,6 +176,29 @@ class DeviceManager {
|
||||
logger.add(`Selected vendor preset: ${v.label}`, "info");
|
||||
}
|
||||
}
|
||||
|
||||
async changePin(current: string | null, next: string) {
|
||||
try {
|
||||
const res = await invoke("change_fido_pin", { currentPin: current, newPin: next });
|
||||
logger.add(res as string, "success");
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
logger.add(`PIN Error: ${err}`, "error");
|
||||
return { success: false, msg: err };
|
||||
}
|
||||
}
|
||||
|
||||
async updateMinPinLength(currentPin: string, length: number) {
|
||||
try {
|
||||
const res = await invoke("set_min_pin_length", { currentPin, minPinLength: length });
|
||||
logger.add(res as string, "success");
|
||||
await this.refresh();
|
||||
return { success: true };
|
||||
} catch (err) {
|
||||
logger.add(`Min PIN Error: ${err}`, "error");
|
||||
return { success: false, msg: err };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const device = new DeviceManager();
|
||||
|
||||
@@ -24,3 +24,15 @@ export interface SecurityState {
|
||||
secureLock: boolean;
|
||||
confirmed: boolean;
|
||||
}
|
||||
|
||||
export interface FidoInfo {
|
||||
versions: string[];
|
||||
extensions: string[];
|
||||
aaguid: string;
|
||||
options: Record<string, boolean>;
|
||||
maxMsgSize: number;
|
||||
pinProtocols: number[];
|
||||
// remainingDiscCreds: number;
|
||||
minPinLength: number;
|
||||
firmwareVersion: string;
|
||||
}
|
||||
|
||||
+1023
-731
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user