From 7697f4a61687d1eddb9345fc7a7205337ac8f7d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20=C3=85berg?= Date: Tue, 8 Jul 2025 11:03:30 +0200 Subject: [PATCH] Unusued cleanup --- .../passkey_authenticator_internal/windows.rs | 5 +- .../src/com_provider.rs | 32 +++----- .../src/com_registration.rs | 80 ++----------------- .../windows_plugin_authenticator/src/lib.rs | 3 - .../src/webauthn.rs | 5 -- 5 files changed, 16 insertions(+), 109 deletions(-) diff --git a/apps/desktop/desktop_native/napi/src/passkey_authenticator_internal/windows.rs b/apps/desktop/desktop_native/napi/src/passkey_authenticator_internal/windows.rs index 5dcc9d1b576..5138358af60 100644 --- a/apps/desktop/desktop_native/napi/src/passkey_authenticator_internal/windows.rs +++ b/apps/desktop/desktop_native/napi/src/passkey_authenticator_internal/windows.rs @@ -1,10 +1,7 @@ use anyhow::{anyhow, Result}; use napi::{ bindgen_prelude::Promise, - threadsafe_function::{ - ErrorStrategy::CalleeHandled, ThreadsafeFunction, ThreadsafeFunctionCallMode, - }, - JsObject, + threadsafe_function::{ErrorStrategy::CalleeHandled, ThreadsafeFunction}, }; use serde_json; use tokio::sync::mpsc; diff --git a/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_provider.rs b/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_provider.rs index 5680b3042e1..ce7fc05a562 100644 --- a/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_provider.rs +++ b/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_provider.rs @@ -202,11 +202,11 @@ impl EXPERIMENTAL_IPluginAuthenticator_Impl for PluginAuthenticatorComObject_Imp } }; - let rp_name = if rp_info.pwszName.is_null() { - String::new() - } else { - wstr_to_string(rp_info.pwszName).unwrap_or_default() - }; + // let rp_name = if rp_info.pwszName.is_null() { + // String::new() + // } else { + // wstr_to_string(rp_info.pwszName).unwrap_or_default() + // }; // Extract user information if decoded_request.pUserInformation.is_null() { @@ -259,18 +259,6 @@ impl EXPERIMENTAL_IPluginAuthenticator_Impl for PluginAuthenticatorComObject_Imp hash_slice.to_vec() }; - // Extract RP ID raw bytes for authenticator data - let rpid_bytes = if decoded_request.cbRpId > 0 && !decoded_request.pbRpId.is_null() - { - let rpid_slice = std::slice::from_raw_parts( - decoded_request.pbRpId, - decoded_request.cbRpId as usize, - ); - rpid_slice.to_vec() - } else { - rpid.as_bytes().to_vec() - }; - // Extract supported algorithms let supported_algorithms = if decoded_request .WebAuthNCredentialParameters @@ -345,10 +333,10 @@ impl EXPERIMENTAL_IPluginAuthenticator_Impl for PluginAuthenticatorComObject_Imp // Create proper WebAuthn response from passkey_response match passkey_response { PasskeyResponse::RegistrationResponse { - credential_id, + credential_id: _, attestation_object, - rp_id, - client_data_hash, + rp_id: _, + client_data_hash: _, } => { util::message("Creating WebAuthn make credential response"); @@ -512,8 +500,8 @@ impl EXPERIMENTAL_IPluginAuthenticator_Impl for PluginAuthenticatorComObject_Imp authenticator_data, signature, user_handle, - rp_id, - client_data_hash, + rp_id: _, + client_data_hash: _, } => { util::message("Creating WebAuthn get assertion response"); diff --git a/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_registration.rs b/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_registration.rs index 6d82576fb63..660b571fd21 100644 --- a/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_registration.rs +++ b/apps/desktop/desktop_native/windows_plugin_authenticator/src/com_registration.rs @@ -1,15 +1,12 @@ -use std::ffi::OsString; -use std::os::windows::ffi::OsStrExt; use std::ffi::c_uchar; use std::ptr; -use windows::Win32::Foundation::*; use windows::Win32::System::Com::*; -use windows_core::{s, HRESULT, PCWSTR, ComObjectInterface, GUID, HSTRING}; +use windows_core::{s, ComObjectInterface, GUID, HRESULT, HSTRING, PCWSTR}; -use crate::utils::{WindowsString, delay_load, message}; -use crate::webauthn::*; use crate::com_provider; +use crate::utils::delay_load; +use crate::webauthn::*; use hex; const AUTHENTICATOR_NAME: &str = "Bitwarden Desktop Authenticator"; @@ -73,74 +70,6 @@ pub fn register_com_library() -> std::result::Result<(), String> { } } -// testing wide encoding -pub fn add_authenticator_using_wide_encoding() -> std::result::Result<(), String> { - // let (authenticator_name_pointer, authenticator_name_bytes) = String::from(AUTHENTICATOR_NAME).into_win_utf16_wide(); - let mut authenticator_name: Vec = OsString::from(AUTHENTICATOR_NAME).encode_wide().collect(); - //authenticator_name.push(0); - let authenticator_name_pointer = authenticator_name.as_mut_ptr(); - - // let (clsid_pointer, clsid_bytes) = String::from(CLSID).into_win_utf16_wide(); - let mut clsid: Vec = OsString::from(CLSID).encode_wide().collect(); - //clsid.push(0); - let clsid_pointer = clsid.as_mut_ptr(); - - // let (rpid_pointer, rpid_bytes) = String::from(RPID).into_win_utf16_wide(); - let mut rpid: Vec = OsString::from(RPID).encode_wide().collect(); - //rpid.push(0); - let rpid_pointer = rpid.as_mut_ptr(); - - // Example authenticator info blob - let cbor_authenticator_info = "A60182684649444F5F325F30684649444F5F325F310282637072666B686D61632D7365637265740350D548826E79B4DB40A3D811116F7E834904A362726BF5627570F5627576F5098168696E7465726E616C0A81A263616C672664747970656A7075626C69632D6B6579"; - let mut authenticator_info_bytes = hex::decode(cbor_authenticator_info).unwrap(); - - let add_authenticator_options = ExperimentalWebAuthnPluginAddAuthenticatorOptions { - authenticator_name: authenticator_name_pointer, - plugin_clsid: clsid_pointer, - rpid: rpid_pointer, - light_theme_logo: ptr::null(), - dark_theme_logo: ptr::null(), - cbor_authenticator_info_byte_count: authenticator_info_bytes.len() as u32, - cbor_authenticator_info: authenticator_info_bytes.as_mut_ptr(), - }; - - let plugin_signing_public_key_byte_count: u32 = 0; - let mut plugin_signing_public_key: c_uchar = 0; - let plugin_signing_public_key_ptr = &mut plugin_signing_public_key; - - let mut add_response = ExperimentalWebAuthnPluginAddAuthenticatorResponse { - plugin_operation_signing_key_byte_count: plugin_signing_public_key_byte_count, - plugin_operation_signing_key: plugin_signing_public_key_ptr, - }; - let mut add_response_ptr: *mut ExperimentalWebAuthnPluginAddAuthenticatorResponse = - &mut add_response; - - let result = unsafe { - delay_load::( - s!("webauthn.dll"), - s!("EXPERIMENTAL_WebAuthNPluginAddAuthenticator"), - ) - }; - - match result { - Some(api) => { - let result = unsafe { api(&add_authenticator_options, &mut add_response_ptr) }; - - if result.is_err() { - return Err(format!( - "Error: Error response from EXPERIMENTAL_WebAuthNPluginAddAuthenticator()\n{}", - result.message() - )); - } - - Ok(()) - }, - None => { - Err(String::from("Error: Can't complete add_authenticator(), as the function EXPERIMENTAL_WebAuthNPluginAddAuthenticator can't be found.")) - } - } -} - /// Adds Bitwarden as a plugin authenticator. pub fn add_authenticator() -> std::result::Result<(), String> { let authenticator_name: HSTRING = AUTHENTICATOR_NAME.into(); @@ -209,4 +138,5 @@ pub fn add_authenticator() -> std::result::Result<(), String> { type EXPERIMENTAL_WebAuthNPluginAddAuthenticatorFnDeclaration = unsafe extern "cdecl" fn( pPluginAddAuthenticatorOptions: *const ExperimentalWebAuthnPluginAddAuthenticatorOptions, ppPluginAddAuthenticatorResponse: *mut *mut ExperimentalWebAuthnPluginAddAuthenticatorResponse, -) -> HRESULT; \ No newline at end of file +) + -> HRESULT; diff --git a/apps/desktop/desktop_native/windows_plugin_authenticator/src/lib.rs b/apps/desktop/desktop_native/windows_plugin_authenticator/src/lib.rs index 7967a7f3904..72060413dfb 100644 --- a/apps/desktop/desktop_native/windows_plugin_authenticator/src/lib.rs +++ b/apps/desktop/desktop_native/windows_plugin_authenticator/src/lib.rs @@ -2,10 +2,7 @@ #![allow(non_snake_case)] #![allow(non_camel_case_types)] -use std::ffi::{c_uchar, c_ulong, OsString}; -use std::os::windows::ffi::OsStrExt; use std::{thread, time::Duration}; -use windows_core::*; // New modular structure mod assert; diff --git a/apps/desktop/desktop_native/windows_plugin_authenticator/src/webauthn.rs b/apps/desktop/desktop_native/windows_plugin_authenticator/src/webauthn.rs index c9a31223317..ff68dec7381 100644 --- a/apps/desktop/desktop_native/windows_plugin_authenticator/src/webauthn.rs +++ b/apps/desktop/desktop_native/windows_plugin_authenticator/src/webauthn.rs @@ -5,11 +5,6 @@ https://github.com/microsoft/webauthn/blob/master/experimental/webauthn.h */ -use std::ffi::c_uchar; -use std::ptr; -use windows::Win32::Foundation::*; -use windows::Win32::System::Com::*; -use windows::Win32::System::LibraryLoader::*; use windows_core::*; use crate::util::*;