Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions credentialsd-common/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ pub trait FlowController {
&self,
) -> impl Future<Output = Result<Vec<Device>, ()>> + Send;

fn get_hybrid_credential(&mut self) -> impl Future<Output = Result<(), ()>> + Send;
fn get_usb_credential(&mut self) -> impl Future<Output = Result<(), ()>> + Send;
fn get_nfc_credential(&mut self) -> impl Future<Output = Result<(), ()>> + Send;
fn start_discovery(&mut self) -> impl Future<Output = Result<(), ()>> + Send;
fn subscribe(
&mut self,
) -> impl Future<
Expand Down
20 changes: 11 additions & 9 deletions credentialsd-common/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ pub enum NfcState {
}

pub enum UserInteractedEvent {
/// Start discovery
DiscoveryRequested,
/*
/// Start Hybrid discovery
HybridDiscoveryRequested,

Expand All @@ -278,7 +281,7 @@ pub enum UserInteractedEvent {

/// Start USB discovery
UsbDiscoveryRequested,

*/
/// Send client PIN. Length of the PIN MUST not be greater than 63 bytes.
/// File descriptor must be memory-mapped to be read.
ClientPinEntered(OwnedFd),
Expand All @@ -292,17 +295,16 @@ pub enum UserInteractedEvent {
impl std::fmt::Debug for UserInteractedEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::HybridDiscoveryRequested => write!(f, "StartHybridDiscovery"),
Self::NfcDiscoveryRequested => write!(f, "StartNfcDiscovery"),
Self::UsbDiscoveryRequested => write!(f, "StartUsbDiscovery"),
Self::DiscoveryRequested => write!(f, stringify!(DiscoveryRequested)),
Self::ClientPinEntered(_) => f
.debug_tuple("EnterClientPin")
.debug_tuple(stringify!(ClientPinEntered))
.field(&"******".to_string())
.finish(),
Self::CredentialSelected(arg0) => {
f.debug_tuple("SelectCredential").field(arg0).finish()
}
Self::RequestCancelled => write!(f, "CancelRequest"),
Self::CredentialSelected(arg0) => f
.debug_tuple(stringify!(CredentialSelected))
.field(arg0)
.finish(),
Self::RequestCancelled => write!(f, stringify!(RequestCancelled)),
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions credentialsd-common/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ const BACKGROUND_EVENT_ERROR_CREDENTIAL_EXCLUDED: u32 = 0x80000006;
const BACKGROUND_EVENT_ERROR_PIN_ATTEMPTS_EXHAUSTED: u32 = 0x80000007;
const BACKGROUND_EVENT_ERROR_PIN_NOT_SET: u32 = 0x80000008;

/*
const USER_INTERACTED_EVENT_HYBRID_DISCOVERY_REQUESTED: u32 = 0x01;
const USER_INTERACTED_EVENT_NFC_DISCOVERY_REQUESTED: u32 = 0x02;
const USER_INTERACTED_EVENT_USB_DISCOVERY_REQUESTED: u32 = 0x03;
*/
const USER_INTERACTED_EVENT_DISCOVERY_REQUESTED: u32 = 0x01;
const USER_INTERACTED_EVENT_CLIENT_PIN_ENTERED: u32 = 0x04;
const USER_INTERACTED_EVENT_CREDENTIAL_SELECTED: u32 = 0x05;
const USER_INTERACTED_EVENT_REQUEST_CANCELLED: u32 = 0x06;
Expand Down Expand Up @@ -426,6 +429,10 @@ impl Type for UserInteractedEvent {
impl From<&UserInteractedEvent> for Structure<'_> {
fn from(value: &UserInteractedEvent) -> Self {
match value {
UserInteractedEvent::DiscoveryRequested => {
tag_value_to_struct(USER_INTERACTED_EVENT_DISCOVERY_REQUESTED, None)
}
/*
UserInteractedEvent::HybridDiscoveryRequested => {
tag_value_to_struct(USER_INTERACTED_EVENT_HYBRID_DISCOVERY_REQUESTED, None)
}
Expand All @@ -435,6 +442,7 @@ impl From<&UserInteractedEvent> for Structure<'_> {
UserInteractedEvent::UsbDiscoveryRequested => {
tag_value_to_struct(USER_INTERACTED_EVENT_USB_DISCOVERY_REQUESTED, None)
}
*/
UserInteractedEvent::ClientPinEntered(pin_fd) => tag_value_to_struct(
USER_INTERACTED_EVENT_CLIENT_PIN_ENTERED,
Some(Value::Fd(pin_fd.into())),
Expand All @@ -457,15 +465,17 @@ impl TryFrom<&Structure<'_>> for UserInteractedEvent {
let (tag, value) = parse_tag_value_struct(value)?;

match tag {
USER_INTERACTED_EVENT_HYBRID_DISCOVERY_REQUESTED => {
Ok(UserInteractedEvent::HybridDiscoveryRequested)
USER_INTERACTED_EVENT_DISCOVERY_REQUESTED => {
Ok(UserInteractedEvent::DiscoveryRequested)
}
/*
USER_INTERACTED_EVENT_NFC_DISCOVERY_REQUESTED => {
Ok(UserInteractedEvent::NfcDiscoveryRequested)
}
USER_INTERACTED_EVENT_USB_DISCOVERY_REQUESTED => {
Ok(UserInteractedEvent::UsbDiscoveryRequested)
}
*/
USER_INTERACTED_EVENT_CLIENT_PIN_ENTERED => {
let fd = value.downcast_ref::<Fd>()?;
let owned_fd = fd.try_to_owned()?;
Expand Down
42 changes: 42 additions & 0 deletions credentialsd-ui/data/resources/ui/window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,46 @@
<child>
<object class="GtkStack" id="stack">

<child>
<object class="GtkStackPage">
<property name="name">start_page</property>
<property name="title" translatable="yes">Choose device</property>
<property name="child">
<object class="GtkBox">
<property name="orientation">vertical</property>
<child>
<object class="GtkPicture" id="qr_code_pic">
<binding name="visible">
<lookup name="qr_code_visible">
<lookup name="view-model">
CredentialsUiWindow
</lookup>
</lookup>
</binding>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="label" translatable="yes">Scan the QR code above with another device, or tap or activate your security key</property>
</object>
</child>
<child>
<object class="GtkLabel">
<binding name="label">
<lookup name="prompt">
<lookup name="view-model">
CredentialsUiWindow
</lookup>
</lookup>
</binding>
</object>
</child>
</object>
</property>
</object>
</child>


<child>
<object class="GtkStackPage">
<property name="name">choose_device</property>
Expand Down Expand Up @@ -151,6 +191,7 @@
</binding>
</object>
</child>
<!--
<child>
<object class="GtkPicture" id="qr_code_pic">
<binding name="visible">
Expand All @@ -162,6 +203,7 @@
</binding>
</object>
</child>
-->
<child>
<object class="GtkLabel">
<binding name="label">
Expand Down
5 changes: 5 additions & 0 deletions credentialsd-ui/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ pub struct FlowControlClient {
}

impl FlowControlClient {
pub async fn discover_authenticators(&self) -> Result<(), ()> {
self.send(UserInteractedEvent::DiscoveryRequested).await
}
/*
pub async fn discover_hybrid_authenticators(&self) -> Result<(), ()> {
self.send(UserInteractedEvent::HybridDiscoveryRequested)
.await
Expand All @@ -36,6 +40,7 @@ impl FlowControlClient {
pub async fn discover_usb_authenticators(&mut self) -> Result<(), ()> {
self.send(UserInteractedEvent::UsbDiscoveryRequested).await
}
*/

pub async fn enter_client_pin(&mut self, pin: String) -> Result<(), ()> {
let fd = match write_secret(pin) {
Expand Down
2 changes: 2 additions & 0 deletions credentialsd-ui/src/gui/view_model/gtk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,11 @@ impl ViewModel {
button.connect_clicked(move |button| {
let id = button.widget_name().to_string();
let tx = tx.clone();
/*
glib::spawn_future_local(async move {
tx.send(ViewEvent::DeviceSelected(id)).await.unwrap();
});
*/
});
button.into()
});
Expand Down
37 changes: 34 additions & 3 deletions credentialsd-ui/src/gui/view_model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ impl ViewModel {
.unwrap();
}

pub(crate) async fn start_discovery(&self) {
let cred_service = self.flow_controller.lock().await;
(*cred_service).discover_authenticators().await.unwrap();
}

/*
pub(crate) async fn select_device(&mut self, id: &str) {
let device = self.devices.iter().find(|d| d.id == id).unwrap();
tracing::debug!("Device selected: {:?}", device);
Expand Down Expand Up @@ -176,6 +182,7 @@ impl ViewModel {
.await
.unwrap();
}
*/

pub(crate) async fn start_event_loop(&mut self) {
let view_events = self.rx_event.clone().map(Event::View);
Expand All @@ -189,11 +196,14 @@ impl ViewModel {
Event::View(ViewEvent::Initiated) => {
self.update_title().await;
self.update_devices(self.devices.clone()).await;
self.start_discovery().await;
}
/*
Event::View(ViewEvent::DeviceSelected(id)) => {
self.select_device(&id).await;
println!("Selected device {id}");
}
*/
Event::View(ViewEvent::PinEntered(pin)) => {
let mut cred_service = self.flow_controller.lock().await;
if cred_service.enter_client_pin(pin).await.is_err() {
Expand Down Expand Up @@ -228,7 +238,14 @@ impl ViewModel {
}

Event::Background(BackgroundEvent::UsbConnected) => {
info!("Found USB device")
info!("Found USB device");
self.tx_update
.send(ViewUpdate::WaitingForDevice(Device {
id: "TODO: bogus".to_string(),
transport: Transport::Usb,
}))
.await
.unwrap();
}
// TODO: Add this event
// Event::Background(BackgroundEvent::DevicesUpdated(devices)) => {
Expand Down Expand Up @@ -322,7 +339,14 @@ impl ViewModel {
.unwrap()
}
Event::Background(BackgroundEvent::NfcConnected) => {
info!("Found NFC device")
info!("Found NFC device");
self.tx_update
.send(ViewUpdate::WaitingForDevice(Device {
id: "TODO: bogus".to_string(),
transport: Transport::Nfc,
}))
.await
.unwrap();
}

Event::Background(BackgroundEvent::NfcIdle | BackgroundEvent::NfcWaiting) => {}
Expand All @@ -338,6 +362,13 @@ impl ViewModel {
}
Event::Background(BackgroundEvent::HybridConnecting) => {
self.hybrid_qr_code_data = None;
self.tx_update
.send(ViewUpdate::WaitingForDevice(Device {
id: "TODO: bogus".to_string(),
transport: Transport::HybridQr,
}))
.await
.unwrap();
self.tx_update
.send(ViewUpdate::HybridConnecting)
.await
Expand Down Expand Up @@ -366,7 +397,7 @@ impl ViewModel {
#[derive(Serialize, Deserialize)]
pub enum ViewEvent {
Initiated,
DeviceSelected(String),
// DeviceSelected(String),
CredentialSelected(String),
PinEntered(String),
UserCancelled,
Expand Down
1 change: 1 addition & 0 deletions credentialsd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ async-stream = "0.3.6"
async-trait = "0.1.89"
base64 = "0.22.1"
credentialsd-common = { path = "../credentialsd-common" }
futures = "0.3.32"
futures-lite.workspace = true
libc.workspace = true
libwebauthn = { version = "0.3.0", features = ["libnfc","pcsc"] }
Expand Down
Loading
Loading