Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 37f3b01c authored by Hsin-chen Chuang's avatar Hsin-chen Chuang
Browse files

floss: Introduce DisplayUuid to avoid logging full UUID

Bug: 342337056
Tag: #floss
Test: mmm packages/modules/Bluetooth
Test: manual FastPair / NearbyShare, verify the log
Flag: EXEMPT, Floss-only changes
Change-Id: Iae60ca04cd440d070829af403500d70a204511a3
parent 00b00d13
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
use bt_topshim::btif::{
    BtAddrType, BtBondState, BtConnectionState, BtDeviceType, BtDiscMode, BtPropertyType,
    BtSspVariant, BtStatus, BtTransport, BtVendorProductInfo, DisplayAddress, RawAddress, Uuid,
    BtSspVariant, BtStatus, BtTransport, BtVendorProductInfo, DisplayAddress, DisplayUuid,
    RawAddress, Uuid,
};
use bt_topshim::profiles::socket::SocketType;
use bt_topshim::profiles::ProfileConnectionState;
@@ -62,7 +63,7 @@ impl DBusArg for Uuid {
    }

    fn log(data: &Uuid) -> String {
        format!("{}", data)
        format!("{}", DisplayUuid(&data))
    }
}

+3 −3
Original line number Diff line number Diff line
@@ -4,8 +4,8 @@ use bt_topshim::btif::{
    BaseCallbacks, BaseCallbacksDispatcher, BluetoothInterface, BluetoothProperty, BtAclState,
    BtAddrType, BtBondState, BtConnectionDirection, BtConnectionState, BtDeviceType, BtDiscMode,
    BtDiscoveryState, BtHciErrorCode, BtPinCode, BtPropertyType, BtScanMode, BtSspVariant, BtState,
    BtStatus, BtThreadEvent, BtTransport, BtVendorProductInfo, DisplayAddress, RawAddress,
    ToggleableProfile, Uuid, INVALID_RSSI,
    BtStatus, BtThreadEvent, BtTransport, BtVendorProductInfo, DisplayAddress, DisplayUuid,
    RawAddress, ToggleableProfile, Uuid, INVALID_RSSI,
};
use bt_topshim::{
    controller, metrics,
@@ -3010,7 +3010,7 @@ impl BtifSdpCallbacks for Bluetooth {
            "Sdp search result found: Status={:?} Address={} Uuid={}",
            status,
            DisplayAddress(&address),
            uuid
            DisplayUuid(&uuid)
        );
    }
}
+11 −8
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
use btif_macros::{btif_callback, btif_callbacks_dispatcher};

use bt_topshim::btif::{
    BluetoothInterface, BtStatus, BtTransport, DisplayAddress, RawAddress, Uuid,
    BluetoothInterface, BtStatus, BtTransport, DisplayAddress, DisplayUuid, RawAddress, Uuid,
};
use bt_topshim::profiles::gatt::{
    ffi::RustAdvertisingTrackInfo, AdvertisingStatus, BtGattDbElement, BtGattNotifyParams,
@@ -901,7 +901,10 @@ impl BluetoothGattService {
            if !services.iter().any(|s| {
                s.instance_id == included_service.instance_id && s.uuid == included_service.uuid
            }) {
                log::error!("Included service with uuid {} not found", included_service.uuid);
                log::error!(
                    "Included service with uuid {} not found",
                    DisplayUuid(&included_service.uuid)
                );
                continue;
            }

@@ -3004,7 +3007,7 @@ impl BtifGattClientCallbacks for BluetoothGatt {
                );
            }
            None => {
                warn!("Warning: Client not registered for UUID {}", app_uuid);
                warn!("Warning: Client not registered for UUID {}", DisplayUuid(&app_uuid));
            }
        }
    }
@@ -3382,7 +3385,7 @@ impl BtifGattServerCallbacks for BluetoothGatt {
                }
            }
            None => {
                warn!("Warning: No callback found for UUID {}", app_uuid);
                warn!("Warning: No callback found for UUID {}", DisplayUuid(&app_uuid));
            }
        }
    }
@@ -3957,7 +3960,7 @@ impl BtifGattScannerCallbacks for BluetoothGatt {
    fn on_scanner_registered(&mut self, uuid: Uuid, scanner_id: u8, status: GattStatus) {
        log::debug!(
            "on_scanner_registered UUID = {}, scanner_id = {}, status = {}",
            uuid,
            DisplayUuid(&uuid),
            scanner_id,
            status
        );
@@ -3970,17 +3973,17 @@ impl BtifGattScannerCallbacks for BluetoothGatt {
            if let Some(cb) = self.scanner_callbacks.get_by_id_mut(info.callback_id) {
                cb.on_scanner_registered(uuid, scanner_id, status);
            } else {
                log::warn!("There is no callback for scanner UUID {}", uuid);
                log::warn!("There is no callback for scanner UUID {}", DisplayUuid(&uuid));
            }
        } else {
            log::warn!(
                "Scanner registered callback for non-existent scanner info, UUID = {}",
                uuid
                DisplayUuid(&uuid)
            );
        }

        if status != GattStatus::Success {
            log::error!("Error registering scanner UUID {}", uuid);
            log::error!("Error registering scanner UUID {}", DisplayUuid(&uuid));
            scanners_lock.remove(&uuid);
        }
    }
+9 −7
Original line number Diff line number Diff line
//! Implementation of the Socket API (IBluetoothSocketManager).

use bt_topshim::btif::{BluetoothInterface, BtStatus, DisplayAddress, RawAddress, Uuid};
use bt_topshim::btif::{
    BluetoothInterface, BtStatus, DisplayAddress, DisplayUuid, RawAddress, Uuid,
};
use bt_topshim::profiles::socket;
use log;
use nix::sys::socket::{recvmsg, ControlMessageOwned};
@@ -173,7 +175,7 @@ impl fmt::Display for BluetoothServerSocket {
            self.sock_type,
            self.name.as_ref().unwrap_or(&String::new()),
            match self.uuid {
                Some(u) => u.to_string(),
                Some(u) => DisplayUuid(&u).to_string(),
                None => "".to_string(),
            }
        )
@@ -256,7 +258,7 @@ impl fmt::Display for BluetoothSocket {
            self.port,
            self.sock_type,
            match self.uuid {
                Some(u) => u.to_string(),
                Some(u) => DisplayUuid(&u).to_string(),
                None => "".to_string(),
            }
        )
@@ -589,7 +591,7 @@ impl BluetoothSocketManager {
    ) -> SocketResult {
        if let Some(uuid) = socket_info.uuid {
            if !self.admin.lock().unwrap().is_service_allowed(uuid) {
                log::debug!("service {} is blocked by admin policy", uuid);
                log::debug!("service {} is blocked by admin policy", DisplayUuid(&uuid));
                return SocketResult::new(BtStatus::AuthRejected, INVALID_SOCKET_ID);
            }
            if self
@@ -597,7 +599,7 @@ impl BluetoothSocketManager {
                .iter()
                .any(|(_, v)| v.iter().any(|s| s.uuid.map_or(false, |u| u == uuid)))
            {
                log::warn!("Service {} already exists", uuid);
                log::warn!("Service {} already exists", DisplayUuid(&uuid));
                return SocketResult::new(BtStatus::Fail, INVALID_SOCKET_ID);
            }
        }
@@ -688,7 +690,7 @@ impl BluetoothSocketManager {
    ) -> SocketResult {
        if let Some(uuid) = socket_info.uuid {
            if !self.admin.lock().unwrap().is_service_allowed(uuid) {
                log::debug!("service {} is blocked by admin policy", uuid);
                log::debug!("service {} is blocked by admin policy", DisplayUuid(&uuid));
                return SocketResult::new(BtStatus::AuthRejected, INVALID_SOCKET_ID);
            }
        }
@@ -1218,7 +1220,7 @@ impl BluetoothSocketManager {
                log::debug!(
                    "socket id {} is not allowed by admin policy due to uuid {}, closing",
                    id,
                    uuid
                    DisplayUuid(&uuid)
                );
                let _ = tx.send(SocketRunnerActions::Close(id)).await;
            }
+19 −0
Original line number Diff line number Diff line
@@ -549,6 +549,25 @@ impl Display for Uuid {
    }
}

/// UUID that is safe to display in logs.
pub struct DisplayUuid<'a>(pub &'a Uuid);
impl<'a> Display for DisplayUuid<'a> {
    fn fmt(&self, f: &mut Formatter) -> Result {
        write!(
            f,
            "{:02x}{:02x}{:02x}{:02x}-xxxx-xxxx-xxxx-xxxx{:02x}{:02x}{:02x}{:02x}",
            self.0.uu[0],
            self.0.uu[1],
            self.0.uu[2],
            self.0.uu[3],
            self.0.uu[12],
            self.0.uu[13],
            self.0.uu[14],
            self.0.uu[15]
        )
    }
}

/// All supported Bluetooth properties after conversion.
#[derive(Debug, Clone)]
pub enum BluetoothProperty {