Skip to content

Commit 846f57a

Browse files
[client] Introduce security coverage entity (#1018)
Co-authored-by: Julien Richard <[email protected]>
1 parent e1adae4 commit 846f57a

File tree

8 files changed

+405
-22
lines changed

8 files changed

+405
-22
lines changed

pycti/api/opencti_api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
from pycti.entities.opencti_opinion import Opinion
5353
from pycti.entities.opencti_report import Report
5454
from pycti.entities.opencti_role import Role
55+
from pycti.entities.opencti_security_coverage import SecurityCoverage
5556
from pycti.entities.opencti_settings import Settings
5657
from pycti.entities.opencti_stix import Stix
5758
from pycti.entities.opencti_stix_core_object import StixCoreObject
@@ -223,6 +224,7 @@ def __init__(
223224
self.narrative = Narrative(self)
224225
self.language = Language(self)
225226
self.vulnerability = Vulnerability(self)
227+
self.security_coverage = SecurityCoverage(self)
226228
self.attack_pattern = AttackPattern(self)
227229
self.course_of_action = CourseOfAction(self)
228230
self.data_component = DataComponent(self)

pycti/connector/opencti_connector.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(
4343
auto: bool,
4444
only_contextual: bool,
4545
playbook_compatible: bool,
46+
auto_update: bool,
47+
enrichment_resolution: str,
4648
listen_callback_uri=None,
4749
):
4850
self.id = connector_id
@@ -55,6 +57,8 @@ def __init__(
5557
else:
5658
self.scope = []
5759
self.auto = auto
60+
self.auto_update = auto_update
61+
self.enrichment_resolution = enrichment_resolution
5862
self.only_contextual = only_contextual
5963
self.playbook_compatible = playbook_compatible
6064
self.listen_callback_uri = listen_callback_uri
@@ -72,6 +76,8 @@ def to_input(self) -> dict:
7276
"type": self.type.name,
7377
"scope": self.scope,
7478
"auto": self.auto,
79+
"auto_update": self.auto_update,
80+
"enrichment_resolution": self.enrichment_resolution,
7581
"only_contextual": self.only_contextual,
7682
"playbook_compatible": self.playbook_compatible,
7783
"listen_callback_uri": self.listen_callback_uri,

pycti/connector/opencti_connector_helper.py

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,16 @@ def _data_handler(self, json_data) -> None:
365365
event_data = json_data["event"]
366366
entity_id = event_data.get("entity_id")
367367
entity_type = event_data.get("entity_type")
368+
stix_entity = (
369+
json.loads(event_data.get("stix_entity"))
370+
if event_data.get("stix_entity")
371+
else None
372+
)
373+
stix_objects = (
374+
json.loads(event_data.get("stix_objects"))
375+
if event_data.get("stix_objects")
376+
else None
377+
)
368378
validation_mode = event_data.get("validation_mode", "workbench")
369379
force_validation = event_data.get("force_validation", False)
370380
# Set the API headers
@@ -430,17 +440,18 @@ def _data_handler(self, json_data) -> None:
430440
else:
431441
# If not playbook but enrichment, compute object on enrichment_entity
432442
opencti_entity = event_data["enrichment_entity"]
433-
stix_objects = self.helper.api.stix2.prepare_export(
434-
entity=self.helper.api.stix2.generate_export(
435-
copy.copy(opencti_entity)
443+
if stix_objects is None:
444+
stix_objects = self.helper.api.stix2.prepare_export(
445+
entity=self.helper.api.stix2.generate_export(
446+
copy.copy(opencti_entity)
447+
)
436448
)
437-
)
438-
stix_entity = [
439-
e
440-
for e in stix_objects
441-
if e["id"] == opencti_entity["standard_id"]
442-
or e["id"] == "x-opencti-" + opencti_entity["standard_id"]
443-
][0]
449+
stix_entity = [
450+
e
451+
for e in stix_objects
452+
if e["id"] == opencti_entity["standard_id"]
453+
or e["id"] == "x-opencti-" + opencti_entity["standard_id"]
454+
][0]
444455
event_data["stix_objects"] = stix_objects
445456
event_data["stix_entity"] = stix_entity
446457
# Handle organization propagation
@@ -1116,6 +1127,15 @@ def __init__(self, config: Dict, playbook_compatible=False) -> None:
11161127
self.connect_auto = get_config_variable(
11171128
"CONNECTOR_AUTO", ["connector", "auto"], config, default=False
11181129
)
1130+
self.connect_auto_update = get_config_variable(
1131+
"CONNECTOR_AUTO_UPDATE", ["connector", "auto_update"], config, default=False
1132+
)
1133+
self.connect_enrichment_resolution = get_config_variable(
1134+
"CONNECTOR_ENRICHMENT_RESOLUTION",
1135+
["connector", "enrichment_resolution"],
1136+
config,
1137+
default="none",
1138+
)
11191139
self.bundle_send_to_queue = get_config_variable(
11201140
"CONNECTOR_SEND_TO_QUEUE",
11211141
["connector", "send_to_queue"],
@@ -1231,14 +1251,16 @@ def __init__(self, config: Dict, playbook_compatible=False) -> None:
12311251
)
12321252
# Register the connector in OpenCTI
12331253
self.connector = OpenCTIConnector(
1234-
self.connect_id,
1235-
self.connect_name,
1236-
self.connect_type,
1237-
self.connect_scope,
1238-
self.connect_auto,
1239-
self.connect_only_contextual,
1240-
playbook_compatible,
1241-
(
1254+
connector_id=self.connect_id,
1255+
connector_name=self.connect_name,
1256+
connector_type=self.connect_type,
1257+
scope=self.connect_scope,
1258+
auto=self.connect_auto,
1259+
only_contextual=self.connect_only_contextual,
1260+
playbook_compatible=playbook_compatible,
1261+
auto_update=self.connect_auto_update,
1262+
enrichment_resolution=self.connect_enrichment_resolution,
1263+
listen_callback_uri=(
12421264
self.listen_protocol_api_uri + self.listen_protocol_api_path
12431265
if self.listen_protocol == "API"
12441266
else None

0 commit comments

Comments
 (0)