USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
|
Represents USB device in USBGuard. More...
#include <Device.hpp>
Public Member Functions | |
Device (DeviceManager &manager) | |
Constructs new device object and sets its device manager. More... | |
virtual | ~Device () |
Default destructor. | |
Device (const Device &rhs) | |
Constructs device object based on rhs. More... | |
const Device & | operator= (const Device &rhs) |
Assigns rhs to this. More... | |
DeviceManager & | manager () const |
Returns device manager that is responsible for this device. More... | |
std::mutex & | refDeviceMutex () |
Returns reference to device mutex. More... | |
std::shared_ptr< Rule > | getDeviceRule (bool with_port=true, bool with_parent_hash=true, bool match_rule=false) |
Generates device rule for this USB device. More... | |
std::string | hashString (const std::string &value) const |
Hashes a given string and returns it. More... | |
void | initializeHash () |
Initialize hash for this device. More... | |
void | updateHash (const void *ptr, size_t size) |
Hashes given data and creates new hash value. More... | |
void | updateHash (std::istream &descriptor_stream, size_t expected_size) |
Hashes given descriptor stream and creates new hash value. More... | |
std::string | finalizeHash () |
Finalizes hash by encoding it into base64. More... | |
const std::string & | getHash () const |
Returns device hash. More... | |
void | setParentHash (const std::string &hash) |
Sets parent hash for this device. More... | |
void | setID (uint32_t id) |
Sets device ID. More... | |
uint32_t | getID () const |
Returns device ID. More... | |
void | setParentID (uint32_t id) |
Sets parent ID for this device. More... | |
uint32_t | getParentID () const |
Returns parent ID. More... | |
void | setTarget (Rule::Target target) |
Sets given target for this device. More... | |
Rule::Target | getTarget () const |
Returns rule target for this device. More... | |
void | setName (const std::string &name) |
Sets device name. More... | |
const std::string & | getName () const |
Returns device name. More... | |
void | setDeviceID (const USBDeviceID &device_id) |
Sets device ID. More... | |
const USBDeviceID & | getDeviceID () const |
Returns device ID. More... | |
void | setPort (const std::string &port) |
Sets port through which the device is connected. More... | |
const std::string & | getPort () const |
Returns port through which the device is connected. More... | |
void | setSerial (const std::string &serial_number) |
Sets device serial number. More... | |
const std::string & | getSerial () const |
Returns device serial number. More... | |
void | setConnectType (const std::string &connect_type) |
Sets device connection type. More... | |
const std::string & | getConnectType () const |
Returns device connection type. More... | |
std::vector< USBInterfaceType > & | refMutableInterfaceTypes () |
Returns reference to mutable vector of interface types of this USB device. More... | |
const std::vector< USBInterfaceType > & | getInterfaceTypes () const |
Returns reference to vector of interface types of this USB device. More... | |
virtual bool | isController () const =0 |
Checks whether this USB device is a controller or not. More... | |
virtual std::string | getSystemName () const =0 |
Returns absolute path of this USB device. More... | |
void | loadDeviceDescriptor (USBDescriptorParser *parser, const USBDescriptor *descriptor) |
Loads device descriptor using given USB descriptor parser. More... | |
void | loadConfigurationDescriptor (USBDescriptorParser *parser, const USBDescriptor *descriptor) |
Loads configuration descriptor using given USB descriptor parser. More... | |
void | loadInterfaceDescriptor (USBDescriptorParser *parser, const USBDescriptor *descriptor) |
Loads interface descriptor using given USB descriptor parser. More... | |
void | loadEndpointDescriptor (USBDescriptorParser *parser, const USBDescriptor *descriptor) |
Loads endpoint descriptor using given USB descriptor parser. More... | |
Represents USB device in USBGuard.
usbguard::Device::Device | ( | DeviceManager & | manager | ) |
Constructs new device object and sets its device manager.
Device ID is set to default, parent device ID is set to root ID and target rule is set to unknown.
manager | device manager that is responsible for this device. |
usbguard::Device::Device | ( | const Device & | rhs | ) |
Constructs device object based on rhs.
rhs | Device object to copy. |
std::string usbguard::Device::finalizeHash | ( | ) |
Finalizes hash by encoding it into base64.
const std::string & usbguard::Device::getConnectType | ( | ) | const |
Returns device connection type.
const USBDeviceID & usbguard::Device::getDeviceID | ( | ) | const |
Returns device ID.
std::shared_ptr< Rule > usbguard::Device::getDeviceRule | ( | bool | with_port = true , |
bool | with_parent_hash = true , |
||
bool | match_rule = false |
||
) |
Generates device rule for this USB device.
Generated device rule is composed of: ID, rule target, device ID, serial number, connection type, port (optional), interface types, device name, hash, parent hash (optional).
with_port | If true, port is included in generated rule. |
with_parent_hash | If true, parent hash is included in generated rule. |
match_rule | If true, sets rule target to match. |
runtime_error | If with_parent_hash is true and parent hash value is not available. |
const std::string & usbguard::Device::getHash | ( | ) | const |
Returns device hash.
USBGUARD_BUG | If device hash is not finalized. |
uint32_t usbguard::Device::getID | ( | ) | const |
Returns device ID.
const std::vector< USBInterfaceType > & usbguard::Device::getInterfaceTypes | ( | ) | const |
Returns reference to vector of interface types of this USB device.
const std::string & usbguard::Device::getName | ( | ) | const |
Returns device name.
uint32_t usbguard::Device::getParentID | ( | ) | const |
Returns parent ID.
const std::string & usbguard::Device::getPort | ( | ) | const |
Returns port through which the device is connected.
const std::string & usbguard::Device::getSerial | ( | ) | const |
Returns device serial number.
|
pure virtual |
Returns absolute path of this USB device.
Rule::Target usbguard::Device::getTarget | ( | ) | const |
std::string usbguard::Device::hashString | ( | const std::string & | value | ) | const |
Hashes a given string and returns it.
value | Value to hash. |
void usbguard::Device::initializeHash | ( | ) |
Initialize hash for this device.
Hash is initialized from name, vendor ID, product ID and serial number of the device.
Exception | If vendor or product ID is empty. |
|
pure virtual |
Checks whether this USB device is a controller or not.
void usbguard::Device::loadConfigurationDescriptor | ( | USBDescriptorParser * | parser, |
const USBDescriptor * | descriptor | ||
) |
Loads configuration descriptor using given USB descriptor parser.
parser | Parser that will parse the configuration descriptor. |
descriptor | Configuration descriptor. |
runtime_error | If parent device descriptor is missing while trying to load configuration descriptor. |
void usbguard::Device::loadDeviceDescriptor | ( | USBDescriptorParser * | parser, |
const USBDescriptor * | descriptor | ||
) |
Loads device descriptor using given USB descriptor parser.
parser | Parser that will parse the USB device descriptor. |
descriptor | USB Device descriptor. |
runtime_error | If there are multiple device descriptors for one device. |
void usbguard::Device::loadEndpointDescriptor | ( | USBDescriptorParser * | parser, |
const USBDescriptor * | descriptor | ||
) |
Loads endpoint descriptor using given USB descriptor parser.
parser | Parser that will parse the endpoint descriptor. |
descriptor | Endpoint descriptor. |
runtime_error | If parent interface descriptor is missing while trying to load enpoint descriptor. |
void usbguard::Device::loadInterfaceDescriptor | ( | USBDescriptorParser * | parser, |
const USBDescriptor * | descriptor | ||
) |
Loads interface descriptor using given USB descriptor parser.
parser | Parser that will parse the interface descriptor. |
descriptor | Interface descriptor. |
runtime_error | If parent configuration descriptor is missing while trying to load interface descriptor. |
DeviceManager & usbguard::Device::manager | ( | ) | const |
Returns device manager that is responsible for this device.
Assigns rhs to this.
rhs | Device object to assign. |
std::mutex & usbguard::Device::refDeviceMutex | ( | ) |
Returns reference to device mutex.
std::vector< USBInterfaceType > & usbguard::Device::refMutableInterfaceTypes | ( | ) |
Returns reference to mutable vector of interface types of this USB device.
void usbguard::Device::setConnectType | ( | const std::string & | connect_type | ) |
Sets device connection type.
connect_type | Connection type to set. |
runtime_error | If given connection_type is bigger then USB_GENERIC_STRING_MAX_LENGTH . |
void usbguard::Device::setDeviceID | ( | const USBDeviceID & | device_id | ) |
Sets device ID.
device_id | Device ID to set. |
void usbguard::Device::setID | ( | uint32_t | id | ) |
Sets device ID.
id | Device ID to set. |
void usbguard::Device::setName | ( | const std::string & | name | ) |
Sets device name.
name | Device name to set. |
Exception | If given name is bigger then USB_GENERIC_STRING_MAX_LENGTH . |
void usbguard::Device::setParentHash | ( | const std::string & | hash | ) |
Sets parent hash for this device.
hash | Parent hash to set. |
void usbguard::Device::setParentID | ( | uint32_t | id | ) |
Sets parent ID for this device.
id | Parent ID to set. |
void usbguard::Device::setPort | ( | const std::string & | port | ) |
Sets port through which the device is connected.
port | Port to set. |
runtime_error | If given port is bigger then USB_PORT_STRING_MAX_LENGTH . |
void usbguard::Device::setSerial | ( | const std::string & | serial_number | ) |
Sets device serial number.
serial_number | Serial number to set. |
runtime_error | If given serial_number is bigger then USB_GENERIC_STRING_MAX_LENGTH . |
void usbguard::Device::setTarget | ( | Rule::Target | target | ) |
void usbguard::Device::updateHash | ( | const void * | ptr, |
size_t | size | ||
) |
Hashes given data and creates new hash value.
ptr | Pointer to data to hash. |
size | Number of bytes to hash. |
void usbguard::Device::updateHash | ( | std::istream & | descriptor_stream, |
size_t | expected_size | ||
) |
Hashes given descriptor stream and creates new hash value.
descriptor_stream | Descriptor stream to hash. |
expected_size | Expected number of bytes to hash. |
Exception | If descriptor stream didnt return expected amount of data. |