USBGuard
Software framework that protects your computer against rogue USB devices by implementing basic whitelisting and blacklisting capabilities.
|
Determines whether USB device mathing specified criteria should be authorized, deauthorized or removed. More...
#include <Rule.hpp>
Classes | |
class | Attribute |
Specifies which devices to match or what condition have to be met for the rule to be aplicable. More... | |
Public Types | |
enum | Target { Target::Allow = 0, Target::Block = 1, Target::Reject = 2, Target::Match = 3, Target::Unknown = 4, Target::Device = 5, Target::Empty = 6, Target::Invalid = 7 } |
Enumeration of possible rule targets. More... | |
enum | SetOperator { SetOperator::AllOf, SetOperator::OneOf, SetOperator::NoneOf, SetOperator::Equals, SetOperator::EqualsOrdered, SetOperator::Match } |
Defines set operators that can be used in the rules. More... | |
Public Member Functions | |
Rule () | |
Construct a default rule. More... | |
~Rule () | |
Default destructor. | |
Rule (const Rule &rhs) | |
Constructs rule based on rhs. More... | |
const Rule & | operator= (const Rule &rhs) |
Assignes rhs rule to this. More... | |
void | setRuleID (uint32_t rule_id) |
Sets rule ID. More... | |
uint32_t | getRuleID () const |
Returns rule ID. More... | |
void | setTarget (Rule::Target target) |
Sets rule target. More... | |
Target | getTarget () const |
Returns rule target. More... | |
void | setDeviceID (const USBDeviceID &value) |
Sets USB Device ID attribute. More... | |
const USBDeviceID & | getDeviceID () const |
Returns USB device ID. More... | |
const Attribute< USBDeviceID > & | attributeDeviceID () const |
Returns imutable USB device ID attribute. More... | |
Attribute< USBDeviceID > & | attributeDeviceID () |
Returns mutable USB device ID attribute. More... | |
void | setSerial (const std::string &value) |
Sets serial number attribute. More... | |
const std::string & | getSerial () const |
Returns serial number. More... | |
const Attribute< std::string > & | attributeSerial () const |
Returns imutable serial number attribute. More... | |
Attribute< std::string > & | attributeSerial () |
Returns mutable serial number attribute. More... | |
void | setLabel (const std::string &value) |
Sets rule label attribute. More... | |
const std::string & | getLabel () const |
Returns rule label. More... | |
const Attribute< std::string > & | attributeLabel () const |
Returns imutable rule label attribute. More... | |
Attribute< std::string > & | attributeLabel () |
Returns mutable rule label attribute. More... | |
void | setWithConnectType (const std::string &value) |
Sets with-connect-type attribute. More... | |
const std::string & | getWithConnectType () const |
Returns type of conncetion USB device uses. More... | |
const Attribute< std::string > & | attributeWithConnectType () const |
Returns imutable with-connect-type attribute. More... | |
Attribute< std::string > & | attributeWithConnectType () |
Returns mutable with-connect-type attribute. More... | |
void | setName (const std::string &value) |
Sets device name attribute. More... | |
const std::string & | getName () const |
Returns device name. More... | |
const Attribute< std::string > & | attributeName () const |
Returns imutable device name attribute. More... | |
Attribute< std::string > & | attributeName () |
Returns mutable device name attribute. More... | |
void | setHash (const std::string &value) |
Sets device hash attribute. More... | |
const std::string & | getHash () const |
Returns device hash. More... | |
const Attribute< std::string > & | attributeHash () const |
Returns imutable device hash attribute. More... | |
Attribute< std::string > & | attributeHash () |
Returns mutable device hash attribute. More... | |
void | setParentHash (const std::string &value) |
Sets parent hash attribute. More... | |
const std::string & | getParentHash () const |
Returns parent hash. More... | |
const Rule::Attribute< std::string > & | attributeParentHash () const |
Returns imutable parent hash attribute. More... | |
Rule::Attribute< std::string > & | attributeParentHash () |
Returns mutable parent hash attribute. More... | |
void | setViaPort (const std::string &value) |
Sets via-port attribute. More... | |
const std::string & | getViaPort () const |
Returns USB port through which the device is connected. More... | |
const Attribute< std::string > & | attributeViaPort () const |
Returns imutable via-port attribute. More... | |
Attribute< std::string > & | attributeViaPort () |
Returns mutable via-port attribute. More... | |
const Attribute< USBInterfaceType > & | attributeWithInterface () const |
Returns imutable with-interface attribute. More... | |
Attribute< USBInterfaceType > & | attributeWithInterface () |
Returns mutable with-interface attribute. More... | |
const Attribute< RuleCondition > & | attributeConditions () const |
Returns imutable rule conditions attribute. More... | |
Attribute< RuleCondition > & | attributeConditions () |
Returns mutable rule conditions attribute. More... | |
bool | appliesTo (std::shared_ptr< const Rule > rhs) const |
Checks whether this rule applies to rhs rule. More... | |
bool | appliesTo (const Rule &rhs) const |
Checks whether this rule applies to rhs rule. More... | |
bool | appliesTo (const Rule &rhs) |
Checks whether this rule applies to rhs rule and updates last evaluated meta-data counter. More... | |
bool | isImplicit () const |
Checks whether the rule is implicit (rule has default rule ID). More... | |
operator bool () const | |
Returns true if rule target is neither unknown nor invalid nor empty. More... | |
std::string | toString (bool invalid=false, bool hide_serial=false) const |
Returns string representation of this rule. More... | |
void | updateMetaDataCounters (bool applied=true, bool evaluated=false) |
Updates meta-data last applied and last evaluated counters. More... | |
std::unique_ptr< RulePrivate > & | internal () |
Returns reference to mutable RulePrivate object of this rule. More... | |
const std::unique_ptr< RulePrivate > & | internal () const |
Returns reference to imutable RulePrivate object of this rule. More... | |
Static Public Member Functions | |
static const std::string | targetToString (Target target) |
Converts given rule target to its string representation. More... | |
static Target | targetFromString (const std::string &target_string) |
Converts given string into rule target. More... | |
static uint32_t | targetToInteger (Target target) |
Converts rule target to its integer representation. More... | |
static Target | targetFromInteger (uint32_t target_integer) |
Converts integer into rule target. More... | |
static const std::string | setOperatorToString (const Rule::SetOperator &op) |
Converts given set operator to its string representation. More... | |
static SetOperator | setOperatorFromString (const std::string &set_operator_string) |
Converts string into set operator. More... | |
static Rule | fromString (const std::string &rule_string) |
Parses given rule_string and returns Rule object. More... | |
Static Public Attributes | |
static const uint32_t | RootID = std::numeric_limits<uint32_t>::min() |
Sequence number of the (fake) root rule. | |
static const uint32_t | DefaultID = std::numeric_limits<uint32_t>::max() |
Sequence number assigned to default constructed rules. Cannot be used for searching. | |
static const uint32_t | LastID = std::numeric_limits<uint32_t>::max() - 2 |
Sequence number for specifying that the last rule in the ruleset should be used in context of the operation. | |
static const uint32_t | ImplicitID = std::numeric_limits<uint32_t>::max() - 1 |
Sequence number of the implicit target rule. | |
Determines whether USB device mathing specified criteria should be authorized, deauthorized or removed.
|
strong |
Defines set operators that can be used in the rules.
|
strong |
Enumeration of possible rule targets.
The target of a rule specifies whether the device will be authorized for use or not.
usbguard::Rule::Rule | ( | ) |
Construct a default rule.
This rule matches only a default rule and cannot be converted to a string representation.
usbguard::Rule::Rule | ( | const Rule & | rhs | ) |
Constructs rule based on rhs.
rhs | Rule to copy. |
bool usbguard::Rule::appliesTo | ( | std::shared_ptr< const Rule > | rhs | ) | const |
Checks whether this rule applies to rhs rule.
rhs | Rule to apply to. |
bool usbguard::Rule::appliesTo | ( | const Rule & | rhs | ) | const |
Checks whether this rule applies to rhs rule.
rhs | Rule to apply to. |
bool usbguard::Rule::appliesTo | ( | const Rule & | rhs | ) |
Checks whether this rule applies to rhs rule and updates last evaluated meta-data counter.
rhs | Rule to apply to. |
const Rule::Attribute< RuleCondition > & usbguard::Rule::attributeConditions | ( | ) | const |
Returns imutable rule conditions attribute.
Rule::Attribute< RuleCondition > & usbguard::Rule::attributeConditions | ( | ) |
Returns mutable rule conditions attribute.
const Rule::Attribute< USBDeviceID > & usbguard::Rule::attributeDeviceID | ( | ) | const |
Returns imutable USB device ID attribute.
Rule::Attribute< USBDeviceID > & usbguard::Rule::attributeDeviceID | ( | ) |
Returns mutable USB device ID attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeHash | ( | ) | const |
Returns imutable device hash attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeHash | ( | ) |
Returns mutable device hash attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeLabel | ( | ) | const |
Returns imutable rule label attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeLabel | ( | ) |
Returns mutable rule label attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeName | ( | ) | const |
Returns imutable device name attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeName | ( | ) |
Returns mutable device name attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeParentHash | ( | ) | const |
Returns imutable parent hash attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeParentHash | ( | ) |
Returns mutable parent hash attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeSerial | ( | ) | const |
Returns imutable serial number attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeSerial | ( | ) |
Returns mutable serial number attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeViaPort | ( | ) | const |
Returns imutable via-port attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeViaPort | ( | ) |
Returns mutable via-port attribute.
const Rule::Attribute< std::string > & usbguard::Rule::attributeWithConnectType | ( | ) | const |
Returns imutable with-connect-type attribute.
Rule::Attribute< std::string > & usbguard::Rule::attributeWithConnectType | ( | ) |
Returns mutable with-connect-type attribute.
const Rule::Attribute< USBInterfaceType > & usbguard::Rule::attributeWithInterface | ( | ) | const |
Returns imutable with-interface attribute.
Rule::Attribute< USBInterfaceType > & usbguard::Rule::attributeWithInterface | ( | ) |
Returns mutable with-interface attribute.
|
static |
Parses given rule_string and returns Rule object.
rule_string | String to parse. |
const USBDeviceID & usbguard::Rule::getDeviceID | ( | ) | const |
const std::string & usbguard::Rule::getHash | ( | ) | const |
const std::string & usbguard::Rule::getLabel | ( | ) | const |
const std::string & usbguard::Rule::getName | ( | ) | const |
const std::string & usbguard::Rule::getParentHash | ( | ) | const |
uint32_t usbguard::Rule::getRuleID | ( | ) | const |
Returns rule ID.
const std::string & usbguard::Rule::getSerial | ( | ) | const |
Rule::Target usbguard::Rule::getTarget | ( | ) | const |
Returns rule target.
const std::string & usbguard::Rule::getViaPort | ( | ) | const |
Returns USB port through which the device is connected.
const std::string & usbguard::Rule::getWithConnectType | ( | ) | const |
Returns type of conncetion USB device uses.
std::unique_ptr< RulePrivate > & usbguard::Rule::internal | ( | ) |
Returns reference to mutable RulePrivate object of this rule.
const std::unique_ptr< RulePrivate > & usbguard::Rule::internal | ( | ) | const |
Returns reference to imutable RulePrivate object of this rule.
bool usbguard::Rule::isImplicit | ( | ) | const |
Checks whether the rule is implicit (rule has default rule ID).
usbguard::Rule::operator bool | ( | ) | const |
Returns true if rule target is neither unknown nor invalid nor empty.
Assignes rhs rule to this.
rhs | Rule to assign. |
void usbguard::Rule::setDeviceID | ( | const USBDeviceID & | value | ) |
void usbguard::Rule::setHash | ( | const std::string & | value | ) |
void usbguard::Rule::setLabel | ( | const std::string & | value | ) |
Sets rule label attribute.
Label assosiates an arbitrary string with a rule. This string can, for instance, be used to store the origin of the rule or some contextual information about it. It is not used when testing if a rule applies to a device.
value | Label to set. |
void usbguard::Rule::setName | ( | const std::string & | value | ) |
|
static |
Converts string into set operator.
set_operator_string | String to convert. |
runtime_error | If given string does not contain valid set operator. |
|
static |
Converts given set operator to its string representation.
op | Set operator to convert. |
runtime_error | If string representation for given set operator does not exist. |
void usbguard::Rule::setParentHash | ( | const std::string & | value | ) |
void usbguard::Rule::setRuleID | ( | uint32_t | rule_id | ) |
Sets rule ID.
rule_id | Rule ID to set. |
void usbguard::Rule::setSerial | ( | const std::string & | value | ) |
void usbguard::Rule::setTarget | ( | Rule::Target | target | ) |
Sets rule target.
In other words, sets whether USB device will be authorized for use or not.
target | Rule target to set. |
void usbguard::Rule::setViaPort | ( | const std::string & | value | ) |
Sets via-port attribute.
Describes through which USB port the device is connected.
value | Port to set. |
void usbguard::Rule::setWithConnectType | ( | const std::string & | value | ) |
Sets with-connect-type attribute.
Describes what type of connection USB device uses. Helps to distinguish between internal (hardwired) and external (hotplug) ports.
value | With-connect-type to set. |
|
static |
Converts integer into rule target.
target_integer | Integer to convert. |
runtime_error | If given integer can not be converted into rule target. |
|
static |
Converts given string into rule target.
target_string | String to convert. |
runtime_error | If string does not contain valid rule target. |
|
static |
Converts rule target to its integer representation.
target | Rule target to convert. |
|
static |
Converts given rule target to its string representation.
target | Rule target to convert. |
runtime_error | If no string representation for given rule target has been found. |
std::string usbguard::Rule::toString | ( | bool | invalid = false , |
bool | hide_serial = false |
||
) | const |
Returns string representation of this rule.
invalid | If rule target is invalid and this option is set to true, then no exception will be thrown but string "<invalid>" will be put instead of rule target into the string. |
hide_serial | If true, serial number and any PII (Personally identifiable information) will not be included in the string. |
void usbguard::Rule::updateMetaDataCounters | ( | bool | applied = true , |
bool | evaluated = false |
||
) |
Updates meta-data last applied and last evaluated counters.
RulePrivate object contains three meta-data counters:
applied | If true, last applied counter is updated to current time. |
evaluated | If true, last evaluated counter is updated to current time. |