1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-01 09:13:54 +00:00

Clean up some logs and comments

This commit is contained in:
Isaiah Inuwa
2025-11-13 14:03:48 -06:00
parent 0f6a02d250
commit 828c0753df
6 changed files with 50 additions and 134 deletions

View File

@@ -11,7 +11,7 @@ use crate::ipc2::{
PasskeyAssertionRequest, PasskeyAssertionResponse, Position, TimedCallback, UserVerification,
WindowsProviderClient,
};
use crate::util::{debug_log, delay_load, wstr_to_string};
use crate::util::{delay_load, wstr_to_string};
use crate::webauthn::WEBAUTHN_CREDENTIAL_LIST;
use crate::{
com_provider::{
@@ -223,17 +223,11 @@ unsafe fn create_get_assertion_response(
// Encode to CBOR with error handling
let mut cbor_data = Vec::new();
if let Err(e) = ciborium::ser::into_writer(&cbor_value, &mut cbor_data) {
debug_log(&format!(
"ERROR: Failed to encode CBOR assertion response: {:?}",
e
));
tracing::debug!("ERROR: Failed to encode CBOR assertion response: {:?}", e);
return Err(HRESULT(-1));
}
debug_log(&format!(
"Formatted CBOR assertion response: {:?}",
cbor_data
));
tracing::debug!("Formatted CBOR assertion response: {:?}", cbor_data);
let response_len = cbor_data.len();
@@ -284,10 +278,7 @@ pub unsafe fn plugin_get_assertion(
let transaction_id = format!("{:?}", req.transaction_id);
let coords = req.window_coordinates().unwrap_or((400, 400));
debug_log(&format!(
"Get assertion request - Transaction: {}",
transaction_id
));
tracing::debug!("Get assertion request - Transaction: {}", transaction_id);
if req.encoded_request_byte_count == 0 || req.encoded_request_pointer.is_null() {
tracing::error!("No encoded request data provided");

View File

@@ -9,7 +9,6 @@ use windows_core::{implement, interface, IInspectable, IUnknown, Interface, HRES
use crate::assert::plugin_get_assertion;
use crate::ipc2::{TimedCallback, WindowsProviderClient};
use crate::make_credential::plugin_make_credential;
use crate::util::debug_log;
use crate::webauthn::WEBAUTHN_CREDENTIAL_LIST;
/// Plugin request type enum as defined in the IDL
@@ -102,10 +101,10 @@ pub unsafe fn parse_credential_list(credential_list: &WEBAUTHN_CREDENTIAL_LIST)
return allowed_credentials;
}
debug_log(&format!(
tracing::debug!(
"Parsing {} credentials from credential list",
credential_list.cCredentials
));
);
// ppCredentials is an array of pointers to WEBAUTHN_CREDENTIAL_EX
let credentials_array = std::slice::from_raw_parts(
@@ -122,10 +121,7 @@ pub unsafe fn parse_credential_list(credential_list: &WEBAUTHN_CREDENTIAL_LIST)
let credential = &*credential_ptr;
if credential.cbId == 0 || credential.pbId.is_null() {
debug_log(&format!(
"WARNING: Credential {} has invalid ID, skipping",
i
));
tracing::debug!("WARNING: Credential {} has invalid ID, skipping", i);
continue;
}
// Extract credential ID bytes
@@ -133,17 +129,19 @@ pub unsafe fn parse_credential_list(credential_list: &WEBAUTHN_CREDENTIAL_LIST)
let credential_id_slice =
std::slice::from_raw_parts(credential.pbId, credential.cbId as usize);
debug_log(&format!(
tracing::debug!(
"Parsed credential {}: {} bytes, {:?}",
i, credential.cbId, &credential_id_slice,
));
i,
credential.cbId,
&credential_id_slice,
);
allowed_credentials.push(credential_id_slice.to_vec());
}
debug_log(&format!(
tracing::debug!(
"Successfully parsed {} allowed credentials",
allowed_credentials.len()
));
);
allowed_credentials
}

View File

@@ -13,7 +13,7 @@ use crate::ipc2::{
PasskeyRegistrationRequest, PasskeyRegistrationResponse, Position, TimedCallback,
UserVerification, WindowsProviderClient,
};
use crate::util::{debug_log, delay_load, wstr_to_string, WindowsString};
use crate::util::{delay_load, wstr_to_string, WindowsString};
use crate::webauthn::WEBAUTHN_CREDENTIAL_LIST;
// Windows API types for WebAuthn (from webauthn.h.sample)
@@ -285,10 +285,10 @@ unsafe fn decode_make_credential_request(
// Check if the call succeeded (following C++ THROW_IF_FAILED pattern)
if result.is_err() {
debug_log(&format!(
tracing::debug!(
"ERROR: WebAuthNDecodeMakeCredentialRequest failed with HRESULT: 0x{:08x}",
result.0
));
);
return Err(format!(
"Windows API call failed with HRESULT: 0x{:08x}",
result.0
@@ -311,8 +311,8 @@ fn send_registration_request(
ipc_client: &WindowsProviderClient,
request: PasskeyRegistrationRequest,
) -> Result<PasskeyRegistrationResponse, String> {
debug_log(&format!("Registration request data - RP ID: {}, User ID: {} bytes, User name: {}, Client data hash: {} bytes, Algorithms: {:?}, Excluded credentials: {}",
request.rp_id, request.user_handle.len(), request.user_name, request.client_data_hash.len(), request.supported_algorithms, request.excluded_credentials.len()));
tracing::debug!("Registration request data - RP ID: {}, User ID: {} bytes, User name: {}, Client data hash: {} bytes, Algorithms: {:?}, Excluded credentials: {}",
request.rp_id, request.user_handle.len(), request.user_name, request.client_data_hash.len(), request.supported_algorithms, request.excluded_credentials.len());
let request_json = serde_json::to_string(&request)
.map_err(|err| format!("Failed to serialize registration request: {err}"))?;
@@ -346,24 +346,6 @@ unsafe fn create_make_credential_response(
.map(|(k, v)| (k.as_text().unwrap(), v))
.collect();
/*
let ctap_attestation_response = ciborium::Value::Map(vec![
(Value::Integer(1.into()), webauthn_att_obj["fmt"].clone()),
(
Value::Integer(2.into()),
webauthn_att_obj["authData"].clone(),
),
(
Value::Integer(3.into()),
webauthn_att_obj["attStmt"].clone(),
),
]);
// Write data into CBOR
// let mut response = Vec::new();
// ciborium::into_writer(&ctap_attestation_response, &mut response).map_err(|_| HRESULT(-1))?;
*/
let webauthn_encode_make_credential_response =
delay_load::<WebAuthNEncodeMakeCredentialResponseFn>(
s!("webauthn.dll"),
@@ -426,35 +408,6 @@ unsafe fn create_make_credential_response(
let response = Vec::from_raw_parts(response_ptr, response_len as usize, response_len as usize);
Ok(response)
/*
// Allocate memory for the response data
let layout = Layout::from_size_align(response_len as usize, 1).map_err(|_| HRESULT(-1))?;
let response_ptr = alloc(layout);
if response_ptr.is_null() {
return Err(HRESULT(-1));
}
// Copy response data
ptr::copy_nonoverlapping(response, response_ptr, response.len());
// Allocate memory for the response structure
let response_layout = Layout::new::<WebAuthnPluginOperationResponse>();
let operation_response_ptr = alloc(response_layout) as *mut WebAuthnPluginOperationResponse;
if operation_response_ptr.is_null() {
return Err(HRESULT(-1));
}
// Initialize the response
ptr::write(
operation_response_ptr,
WebAuthnPluginOperationResponse {
encoded_response_byte_count: response.len() as u32,
encoded_response_pointer: response_ptr,
},
);
tracing::debug!("CTAP-encoded attestation object: {response:?}");
Ok(operation_response_ptr)
*/
}
/// Implementation of PluginMakeCredential moved from com_provider.rs
@@ -490,16 +443,11 @@ pub unsafe fn plugin_make_credential(
req.encoded_request_byte_count as usize,
);
debug_log(&format!(
"Encoded request: {} bytes",
encoded_request_slice.len()
));
tracing::debug!("Encoded request: {} bytes", encoded_request_slice.len());
// Try to decode the request using Windows API
let decoded_wrapper = decode_make_credential_request(encoded_request_slice).map_err(|err| {
debug_log(&format!(
"ERROR: Failed to decode make credential request: {err}"
));
tracing::debug!("ERROR: Failed to decode make credential request: {err}");
HRESULT(-1)
})?;
let decoded_request = decoded_wrapper.as_ref();
@@ -621,10 +569,10 @@ pub unsafe fn plugin_make_credential(
// Extract excluded credentials from credential list
let excluded_credentials = parse_credential_list(&decoded_request.CredentialList);
if !excluded_credentials.is_empty() {
debug_log(&format!(
tracing::debug!(
"Found {} excluded credentials for make credential",
excluded_credentials.len()
));
);
}
let transaction_id = req.transaction_id.to_u128().to_le_bytes().to_vec();
@@ -646,10 +594,11 @@ pub unsafe fn plugin_make_credential(
context: transaction_id,
};
debug_log(&format!(
tracing::debug!(
"Make credential request - RP: {}, User: {}",
rpid, registration_request.user_name
));
rpid,
registration_request.user_name
);
// Send registration request
let passkey_response =
@@ -657,10 +606,7 @@ pub unsafe fn plugin_make_credential(
tracing::error!("Registration request failed: {err}");
HRESULT(-1)
})?;
debug_log(&format!(
"Registration response received: {:?}",
passkey_response
));
tracing::debug!("Registration response received: {:?}", passkey_response);
// Create proper WebAuthn response from passkey_response
tracing::debug!("Creating WebAuthn make credential response");
@@ -669,9 +615,7 @@ pub unsafe fn plugin_make_credential(
tracing::error!("Failed to create WebAuthn response: {err}");
HRESULT(-1)
})?;
debug_log(&format!(
"Successfully created WebAuthn response: {webauthn_response:?}"
));
tracing::debug!("Successfully created WebAuthn response: {webauthn_response:?}");
(*response).encoded_response_byte_count = webauthn_response.len() as u32;
(*response).encoded_response_pointer = webauthn_response.as_mut_ptr();
tracing::debug!("Set pointer, returning HRESULT(0)");
@@ -698,18 +642,6 @@ mod tests {
163, 99, 102, 109, 116, 100, 110, 111, 110, 101, 103, 97, 116, 116, 83, 116, 109, 116,
160, 104, 97, 117, 116, 104, 68, 97, 116, 97, 68, 1, 2, 3, 4,
];
/*
148, 116, 166, 234, 146, 19, 201,
156, 47, 116, 178, 36, 146, 179, 32, 207, 64, 38, 42, 148, 193, 169, 80, 160, 57, 127,
41, 37, 11, 96, 132, 30, 240, 93, 0, 0, 0, 0, 213, 72, 130, 110, 121, 180, 219, 64,
163, 216, 17, 17, 111, 126, 131, 73, 0, 16, 41, 58, 58, 242, 229, 31, 75, 22, 168, 253,
151, 122, 177, 155, 237, 89, 165, 1, 2, 3, 38, 32, 1, 33, 88, 32, 154, 18, 243, 88, 48,
112, 84, 3, 82, 219, 172, 210, 76, 151, 246, 101, 189, 86, 147, 114, 248, 43, 231, 192,
202, 190, 92, 37, 216, 45, 202, 250, 34, 88, 32, 28, 36, 149, 44, 106, 229, 243, 164,
190, 234, 102, 125, 168, 224, 155, 182, 190, 178, 218, 158, 98, 11, 57, 187, 41, 10,
218, 58, 80, 124, 254, 119,
];
*/
let ctap_att_obj = unsafe { create_make_credential_response(webauthn_att_obj).unwrap() };
println!("{ctap_att_obj:?}");
let expected = vec![163, 1, 100, 110, 111, 110, 101, 2, 68, 1, 2, 3, 4, 3, 160];

View File

@@ -77,11 +77,6 @@ pub fn file_log(msg: &str) {
}
}
pub fn debug_log(message: &str) {
tracing::debug!(message);
file_log(message)
}
// Helper function to convert Windows wide string (UTF-16) to Rust String
pub unsafe fn wstr_to_string(
wstr_ptr: *const u16,

View File

@@ -8,7 +8,7 @@
use windows_core::*;
use crate::com_buffer::ComBuffer;
use crate::util::{debug_log, delay_load, WindowsString};
use crate::util::{delay_load, WindowsString};
/// Windows WebAuthn Authenticator Options structure
/// Header File Name: _WEBAUTHN_CTAPCBOR_AUTHENTICATOR_OPTIONS
@@ -135,7 +135,7 @@ pub fn add_credentials(
clsid_guid: GUID,
credentials: Vec<WebAuthnPluginCredentialDetails>,
) -> std::result::Result<(), String> {
debug_log("Loading WebAuthNPluginAuthenticatorAddCredentials function...");
tracing::debug!("Loading WebAuthNPluginAuthenticatorAddCredentials function...");
let result = unsafe {
delay_load::<WebAuthNPluginAuthenticatorAddCredentialsFnDeclaration>(
@@ -146,8 +146,8 @@ pub fn add_credentials(
match result {
Some(api) => {
debug_log("Function loaded successfully, calling API...");
debug_log(&format!("Adding {} credentials", credentials.len()));
tracing::debug!("Function loaded successfully, calling API...");
tracing::debug!("Adding {} credentials", credentials.len());
let credential_count = credentials.len() as u32;
let credentials_ptr = if credentials.is_empty() {
@@ -160,18 +160,18 @@ pub fn add_credentials(
if result.is_err() {
let error_code = result.0;
debug_log(&format!("API call failed with HRESULT: 0x{:x}", error_code));
tracing::debug!("API call failed with HRESULT: 0x{:x}", error_code);
return Err(format!(
"Error: Error response from WebAuthNPluginAuthenticatorAddCredentials()\nHRESULT: 0x{:x}\n{}",
error_code, result.message()
));
}
debug_log("API call succeeded");
tracing::debug!("API call succeeded");
Ok(())
}
None => {
debug_log("Failed to load WebAuthNPluginAuthenticatorAddCredentials function from webauthn.dll");
tracing::debug!("Failed to load WebAuthNPluginAuthenticatorAddCredentials function from webauthn.dll");
Err(String::from("Error: Can't complete add_credentials(), as the function WebAuthNPluginAuthenticatorAddCredentials can't be loaded."))
}
}
@@ -181,7 +181,7 @@ pub fn remove_credentials(
clsid_guid: GUID,
credentials: Vec<WebAuthnPluginCredentialDetails>,
) -> std::result::Result<(), String> {
debug_log("Loading WebAuthNPluginAuthenticatorRemoveCredentials function...");
tracing::debug!("Loading WebAuthNPluginAuthenticatorRemoveCredentials function...");
let result = unsafe {
delay_load::<WebAuthNPluginAuthenticatorRemoveCredentialsFnDeclaration>(
@@ -192,7 +192,7 @@ pub fn remove_credentials(
match result {
Some(api) => {
debug_log(&format!("Removing {} credentials", credentials.len()));
tracing::debug!("Removing {} credentials", credentials.len());
let credential_count = credentials.len() as u32;
let credentials_ptr = if credentials.is_empty() {
@@ -232,7 +232,7 @@ pub struct OwnedCredentialDetails {
pub fn get_all_credentials(
clsid_guid: GUID,
) -> std::result::Result<Vec<OwnedCredentialDetails>, String> {
debug_log("Loading WebAuthNPluginAuthenticatorGetAllCredentials function...");
tracing::debug!("Loading WebAuthNPluginAuthenticatorGetAllCredentials function...");
let result = unsafe {
delay_load::<WebAuthNPluginAuthenticatorGetAllCredentialsFnDeclaration>(
@@ -256,7 +256,7 @@ pub fn get_all_credentials(
}
if credentials_array_ptr.is_null() || credential_count == 0 {
debug_log("No credentials returned");
tracing::debug!("No credentials returned");
return Ok(Vec::new());
}
@@ -333,7 +333,7 @@ pub fn get_all_credentials(
// Free the array using the Windows API - this frees everything including strings
free_credential_details_array(credential_count, credentials_array_ptr);
debug_log(&format!("Retrieved {} credentials", owned_credentials.len()));
tracing::debug!("Retrieved {} credentials", owned_credentials.len());
Ok(owned_credentials)
},
None => {
@@ -360,12 +360,14 @@ fn free_credential_details_array(
if let Some(api) = result {
unsafe { api(credential_count, credentials_array) };
} else {
debug_log("Warning: Could not load WebAuthNPluginAuthenticatorFreeCredentialDetailsArray");
tracing::debug!(
"Warning: Could not load WebAuthNPluginAuthenticatorFreeCredentialDetailsArray"
);
}
}
pub fn remove_all_credentials(clsid_guid: GUID) -> std::result::Result<(), String> {
debug_log("Loading WebAuthNPluginAuthenticatorRemoveAllCredentials function...");
tracing::debug!("Loading WebAuthNPluginAuthenticatorRemoveAllCredentials function...");
let result = unsafe {
delay_load::<WebAuthNPluginAuthenticatorRemoveAllCredentialsFnDeclaration>(
@@ -376,13 +378,13 @@ pub fn remove_all_credentials(clsid_guid: GUID) -> std::result::Result<(), Strin
match result {
Some(api) => {
debug_log("Function loaded successfully, calling API...");
tracing::debug!("Function loaded successfully, calling API...");
let result = unsafe { api(&clsid_guid) };
if result.is_err() {
let error_code = result.0;
debug_log(&format!("API call failed with HRESULT: 0x{:x}", error_code));
tracing::debug!("API call failed with HRESULT: 0x{:x}", error_code);
return Err(format!(
"Error: Error response from WebAuthNPluginAuthenticatorRemoveAllCredentials()\nHRESULT: 0x{:x}\n{}",
@@ -390,11 +392,11 @@ pub fn remove_all_credentials(clsid_guid: GUID) -> std::result::Result<(), Strin
));
}
debug_log("API call succeeded");
tracing::debug!("API call succeeded");
Ok(())
}
None => {
debug_log("Failed to load WebAuthNPluginAuthenticatorRemoveAllCredentials function from webauthn.dll");
tracing::debug!("Failed to load WebAuthNPluginAuthenticatorRemoveAllCredentials function from webauthn.dll");
Err(String::from("Error: Can't complete remove_all_credentials(), as the function WebAuthNPluginAuthenticatorRemoveAllCredentials can't be loaded."))
}
}

View File

@@ -130,8 +130,6 @@ export class Main {
}
this.logService = new ElectronLogMainService(null, app.getPath("userData"));
this.logService.info("IS THIS THING ON?")
this.logService.debug("IS THIS THING ON? [debug]")
const storageDefaults: any = {};
this.storageService = new ElectronStorageService(app.getPath("userData"), storageDefaults);
@@ -310,7 +308,7 @@ export class Main {
app
.whenReady()
.then(async () => {
this.logService.debug("ATTEMPTING TO INITIALIZE NATIVE AUTOFILL")
this.logService.debug("Initializing native autofill")
await this.nativeAutofillMain.init();
})