Skip to content

Commit

Permalink
ToolAdapter and other more logical class names
Browse files Browse the repository at this point in the history
  • Loading branch information
raulikak committed May 15, 2024
1 parent 13f9eef commit 4a2af02
Show file tree
Hide file tree
Showing 17 changed files with 48 additions and 47 deletions.
4 changes: 2 additions & 2 deletions tcsfw/android_manifest_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from tcsfw.event_interface import PropertyEvent, EventInterface
from tcsfw.model import IoTSystem, NodeComponent
from tcsfw.property import Properties, PropertyKey
from tcsfw.tools import ComponentCheckTool
from tcsfw.tools import NodeComponentTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.verdict import Verdict


class AndroidManifestScan(ComponentCheckTool):
class AndroidManifestScan(NodeComponentTool):
"""Android manifest XML tool"""
def __init__(self, system: IoTSystem):
super().__init__("android", ".xml", system)
Expand Down
6 changes: 3 additions & 3 deletions tcsfw/censys_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
from tcsfw.event_interface import PropertyAddressEvent, EventInterface
from tcsfw.model import IoTSystem, NetworkNode, Host
from tcsfw.property import Properties
from tcsfw.tools import EndpointCheckTool
from tcsfw.tools import EndpointTool
from tcsfw.traffic import EvidenceSource, ServiceScan, Evidence, HostScan
from tcsfw.verdict import Verdict


class CensysScan(EndpointCheckTool):
class CensysScan(EndpointTool):
"""Censys scan tool"""
def __init__(self, system: IoTSystem):
super().__init__("censys", ".json", system)
Expand All @@ -26,7 +26,7 @@ def __init__(self, system: IoTSystem):
def filter_node(self, node: NetworkNode) -> bool:
return isinstance(node, Host)

def process_endpoint(self, endpoint: AnyAddress, stream: BytesIO, interface: EventInterface,
def process_endpoint(self, endpoint: AnyAddress, stream: BytesIO, interface: EventInterface,
source: EvidenceSource):
raw = json.load(stream)

Expand Down
4 changes: 2 additions & 2 deletions tcsfw/har_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from tcsfw.event_interface import PropertyAddressEvent, PropertyEvent, EventInterface
from tcsfw.model import Host, IoTSystem, NetworkNode
from tcsfw.property import PropertyKey, Properties
from tcsfw.tools import NodeCheckTool
from tcsfw.tools import NetworkNodeTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.verdict import Verdict


class HARScan(NodeCheckTool):
class HARScan(NetworkNodeTool):
"""HAR JSON tool"""
def __init__(self, system: IoTSystem):
super().__init__("har", ".json", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/mitm_log_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from tcsfw.model import IoTSystem
from tcsfw.property import Properties
from tcsfw.services import NameEvent
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import EvidenceSource, Evidence, IPFlow
from tcsfw.verdict import Verdict


class MITMLogReader(BaseFileCheckTool):
class MITMLogReader(SystemWideTool):
"""Read MITM log created the tls_check MITMproxy add-on"""
def __init__(self, system: IoTSystem):
super().__init__("mitm", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/nmap_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from tcsfw.address import IPAddress, HWAddress, EndpointAddress, Protocol
from tcsfw.event_interface import EventInterface
from tcsfw.model import IoTSystem, Host
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import EvidenceSource, Evidence, ServiceScan, HostScan


class NMAPScan(BaseFileCheckTool):
class NMAPScan(SystemWideTool):
"""Parse Nmap scan XML output"""
def __init__(self, system: IoTSystem):
super().__init__("nmap", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/pcap_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
from tcsfw.event_interface import EventInterface
from tcsfw.model import Connection, IoTSystem
from tcsfw.services import NameEvent, DNSService
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import IPFlow, EvidenceSource, Evidence, EthernetFlow, Flow


class PCAPReader(BaseFileCheckTool):
class PCAPReader(SystemWideTool):
"""PCAP reading tool"""
def __init__(self, system: IoTSystem, name="PCAP reader"):
super().__init__("pcap", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/ping_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from tcsfw.event_interface import EventInterface, PropertyAddressEvent
from tcsfw.model import IoTSystem
from tcsfw.property import Properties
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import Evidence, EvidenceSource
from tcsfw.verdict import Verdict


class PingCommand(BaseFileCheckTool):
class PingCommand(SystemWideTool):
"""Ping command"""
def __init__(self, system: IoTSystem):
super().__init__("ping", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/releases.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from tcsfw.components import Software
from tcsfw.event_interface import EventInterface, PropertyEvent
from tcsfw.model import IoTSystem, NetworkNode, NodeComponent
from tcsfw.tools import ComponentCheckTool
from tcsfw.tools import NodeComponentTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.release_info import ReleaseInfo


class ReleaseReader(ComponentCheckTool):
class ReleaseReader(NodeComponentTool):
"""Read release data aquired from GitHub API"""
def __init__(self, system: IoTSystem):
super().__init__("github-releases", ".json", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/spdx_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from tcsfw.event_interface import PropertyEvent, EventInterface
from tcsfw.model import IoTSystem, NodeComponent
from tcsfw.property import Properties, PropertyKey
from tcsfw.tools import ComponentCheckTool
from tcsfw.tools import NodeComponentTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.verdict import Verdict


class SPDXReader(ComponentCheckTool):
class SPDXReader(NodeComponentTool):
"""Read SPDX component description for a software"""
def __init__(self, system: IoTSystem):
super().__init__("spdx", ".json", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/ssh_audit_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from tcsfw.event_interface import PropertyAddressEvent, EventInterface
from tcsfw.model import Service, IoTSystem, NetworkNode
from tcsfw.property import Properties, PropertyKey
from tcsfw.tools import EndpointCheckTool
from tcsfw.tools import EndpointTool
from tcsfw.traffic import Evidence, EvidenceSource
from tcsfw.verdict import Verdict


class SSHAuditScan(EndpointCheckTool):
class SSHAuditScan(EndpointTool):
"""Ssh-audit output reading tool"""
def __init__(self, system: IoTSystem):
super().__init__("ssh-audit", ".json", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/testsslsh_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from tcsfw.event_interface import EventInterface, PropertyAddressEvent
from tcsfw.model import Service, IoTSystem, NetworkNode
from tcsfw.property import PropertyKey, Properties
from tcsfw.tools import EndpointCheckTool
from tcsfw.tools import EndpointTool
from tcsfw.traffic import Evidence, EvidenceSource
from tcsfw.verdict import Verdict


class TestSSLScan(EndpointCheckTool):
class TestSSLScan(EndpointTool):
"""Testssl.sh output reading tool"""
def __init__(self, system: IoTSystem):
super().__init__("testssl", ".json", system)
Expand Down
9 changes: 5 additions & 4 deletions tcsfw/tool_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from tcsfw.spdx_reader import SPDXReader
from tcsfw.ssh_audit_scan import SSHAuditScan
from tcsfw.testsslsh_scan import TestSSLScan
from tcsfw.tools import CheckTool, SimpleFlowTool
from tcsfw.tools import ToolAdapter, SimpleFlowTool
from tcsfw.tshark_reader import TSharkReader
from tcsfw.vulnerability_reader import VulnerabilityReader
from tcsfw.web_checker import WebChecker
Expand All @@ -22,11 +22,12 @@

class ToolDepiction:
"""Tool depiction"""
def __init__(self, file_type: Union[str|List[str]], tool_class: Union[Type[CheckTool], Dict[str, Type[CheckTool]]],
def __init__(self, file_type: Union[str|List[str]],
tool_class: Union[Type[ToolAdapter], Dict[str, Type[ToolAdapter]]],
extension=""):
file_types = file_type if isinstance(file_type, list) else [file_type]
self.file_type = file_types[0] # primary
self.tools: Dict[str, Type[CheckTool]] = {}
self.tools: Dict[str, Type[ToolAdapter]] = {}
if isinstance(tool_class, dict):
assert not extension
self.tools = tool_class
Expand All @@ -41,7 +42,7 @@ def filter_files_itself(self) -> bool:
"""Does the tool filter files itself?"""
return len(self.tools) == 1 and "" in self.tools

def create_tool(self, system: IoTSystem, file_extension="") -> Optional[CheckTool]:
def create_tool(self, system: IoTSystem, file_extension="") -> Optional[ToolAdapter]:
"""Create tool, optionally by data file extension"""
if file_extension:
file_extension = file_extension.lower()
Expand Down
24 changes: 12 additions & 12 deletions tcsfw/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from tcsfw.basics import Status


class CheckTool:
"""A security check tool"""
class ToolAdapter:
"""Security tool adapter base class"""
def __init__(self, tool_label: str, system: IoTSystem):
self.tool_label = tool_label
self.tool = Tool(tool_label) # human readable
Expand Down Expand Up @@ -47,15 +47,15 @@ def get_file_by_endpoint(self, address: AnyAddress) -> Optional[str]:
return n


class BaseFileCheckTool(CheckTool):
"""Check tool which scans set of files, no way to specify entries directly"""
class SystemWideTool(ToolAdapter):
"""Apply tool output to system as output indicates"""

def process_file(self, data: BytesIO, file_name: str, interface: EventInterface, source: EvidenceSource) -> bool:
raise NotImplementedError()


class EndpointCheckTool(CheckTool):
"""Check a service endpoint"""
class EndpointTool(ToolAdapter):
"""Tool applies to endpoints"""
def __init__(self, tool_label: str, data_file_suffix: str, system: IoTSystem):
super().__init__(tool_label, system)
# map from file names into addressable entities
Expand All @@ -67,7 +67,7 @@ def filter_node(self, _node: NetworkNode) -> bool:
"""Filter checked endpoints by the corresponding node"""
return True

def process_endpoint(self, endpoint: AnyAddress, stream: BytesIO, interface: EventInterface,
def process_endpoint(self, endpoint: AnyAddress, stream: BytesIO, interface: EventInterface,
source: EvidenceSource):
"""Process result file for specific endpoint"""
raise NotImplementedError()
Expand Down Expand Up @@ -108,8 +108,8 @@ def map_addressable(self, entity: Addressable):
self.file_name_map[a_file_name] = a


class NodeCheckTool(CheckTool):
"""Network node check tool"""
class NetworkNodeTool(ToolAdapter):
"""Tool applies to network nodes"""
def __init__(self, tool_label: str, data_file_suffix: str, system: IoTSystem):
super().__init__(tool_label, system)
self.data_file_suffix = data_file_suffix
Expand Down Expand Up @@ -145,8 +145,8 @@ def check_component(node: NetworkNode):
check_component(self.system)


class ComponentCheckTool(CheckTool):
"""Software check tool"""
class NodeComponentTool(ToolAdapter):
"""Tool applies to node components"""
def __init__(self, tool_label: str, data_file_suffix: str, system: IoTSystem):
super().__init__(tool_label, system)
self.data_file_suffix = data_file_suffix
Expand Down Expand Up @@ -185,7 +185,7 @@ def check_component(node: NetworkNode):
check_component(self.system)


class SimpleFlowTool(BaseFileCheckTool):
class SimpleFlowTool(SystemWideTool):
"""Simple flow tool powered by list of flows"""
def __init__(self, system: IoTSystem):
super().__init__("flow", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/tshark_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
from tcsfw.event_interface import EventInterface
from tcsfw.inspector import Inspector
from tcsfw.model import IoTSystem
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import EvidenceSource, BLEAdvertisementFlow, Evidence


class TSharkReader(BaseFileCheckTool):
class TSharkReader(SystemWideTool):
"""Read in TShark JSON input"""
def __init__(self, system: IoTSystem):
super().__init__("pcap-tshark", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/vulnerability_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from tcsfw.event_interface import PropertyEvent, EventInterface
from tcsfw.model import IoTSystem, NodeComponent
from tcsfw.property import Properties, PropertyKey
from tcsfw.tools import ComponentCheckTool
from tcsfw.tools import NodeComponentTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.verdict import Verdict


class VulnerabilityReader(ComponentCheckTool):
class VulnerabilityReader(NodeComponentTool):
"""Vulnerability-data CSV-file reader"""
def __init__(self, system: IoTSystem):
super().__init__("vulnz", ".csv", system)
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/web_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
from tcsfw.event_interface import PropertyEvent, EventInterface
from tcsfw.model import IoTSystem
from tcsfw.property import Properties
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.verdict import Verdict


class WebChecker(BaseFileCheckTool):
class WebChecker(SystemWideTool):
"""Check web pages tool"""
def __init__(self, system: IoTSystem):
super().__init__("web", system) # no extension really
Expand Down
4 changes: 2 additions & 2 deletions tcsfw/zed_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from tcsfw.event_interface import EventInterface, PropertyAddressEvent
from tcsfw.model import IoTSystem
from tcsfw.property import Properties, PropertyKey
from tcsfw.tools import BaseFileCheckTool
from tcsfw.tools import SystemWideTool
from tcsfw.traffic import EvidenceSource, Evidence
from tcsfw.verdict import Verdict


class ZEDReader(BaseFileCheckTool):
class ZEDReader(SystemWideTool):
"""Read ZED attack proxy scanning results for a software"""
def __init__(self, system: IoTSystem):
super().__init__("zed", system)
Expand Down

0 comments on commit 4a2af02

Please sign in to comment.