mal-toolbox 1.0.4__tar.gz → 1.0.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. {mal_toolbox-1.0.4/mal_toolbox.egg-info → mal_toolbox-1.0.5}/PKG-INFO +12 -6
  2. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/README.md +8 -4
  3. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5/mal_toolbox.egg-info}/PKG-INFO +12 -6
  4. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/mal_toolbox.egg-info/requires.txt +3 -0
  5. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/__init__.py +2 -2
  6. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/attackgraph/attackgraph.py +4 -1
  7. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/attackgraph/node.py +1 -1
  8. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/language/languagegraph.py +12 -5
  9. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/model.py +29 -1
  10. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/pyproject.toml +8 -2
  11. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/tests/test_model.py +6 -0
  12. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/AUTHORS +0 -0
  13. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/LICENSE +0 -0
  14. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/mal_toolbox.egg-info/SOURCES.txt +0 -0
  15. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/mal_toolbox.egg-info/dependency_links.txt +0 -0
  16. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/mal_toolbox.egg-info/entry_points.txt +0 -0
  17. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/mal_toolbox.egg-info/top_level.txt +0 -0
  18. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/__main__.py +0 -0
  19. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/attackgraph/__init__.py +0 -0
  20. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/attackgraph/analyzers/__init__.py +0 -0
  21. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/exceptions.py +0 -0
  22. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/file_utils.py +0 -0
  23. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/language/__init__.py +0 -0
  24. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/language/compiler/__init__.py +0 -0
  25. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/language/compiler/mal_lexer.py +0 -0
  26. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/language/compiler/mal_parser.py +0 -0
  27. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/patternfinder/__init__.py +0 -0
  28. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/patternfinder/attackgraph_patterns.py +0 -0
  29. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/py.typed +0 -0
  30. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/translators/__init__.py +0 -0
  31. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/translators/securicad.py +0 -0
  32. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/translators/updater.py +0 -0
  33. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/visualization/__init__.py +0 -0
  34. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/maltoolbox/visualization/graphviz_utils.py +0 -0
  35. {mal_toolbox-1.0.4 → mal_toolbox-1.0.5}/setup.cfg +0 -0
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-toolbox
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
- Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Giuseppe Nebbione <nebbione@kth.se>
5
+ Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Giuseppe Nebbione <nebbione@kth.se>, Sandor Berglund <sandor@kth.se>
6
6
  License: Apache Software License
7
7
  Project-URL: Homepage, https://github.com/mal-lang/mal-toolbox
8
8
  Project-URL: Bug Tracker, https://github.com/mal-lang/mal-toolbox/issues
@@ -23,6 +23,8 @@ Requires-Dist: antlr4-tools
23
23
  Requires-Dist: antlr4-python3-runtime
24
24
  Requires-Dist: docopt
25
25
  Requires-Dist: PyYAML
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest; extra == "dev"
26
28
  Dynamic: license-file
27
29
 
28
30
  # MAL Toolbox overview
@@ -30,7 +32,7 @@ Dynamic: license-file
30
32
  MAL Toolbox is a collection of python modules to help developers create and work with
31
33
  MAL ([Meta Attack Language](https://mal-lang.org/)) models and attack graphs.
32
34
 
33
- Attack graphs can be used to run simulations (see MAL Simulator) or analysis.
35
+ Attack graphs can be used to run simulations in [MAL Simulator](https://github.com/mal-lang/mal-simulator) or run your own custom analysis on.
34
36
 
35
37
  [Documentation](https://mal-lang.org/mal-toolbox/index.html)(Work in progress)
36
38
 
@@ -124,19 +126,23 @@ You can use the maltoolbox cli to:
124
126
  Command-line interface for MAL toolbox operations
125
127
 
126
128
  Usage:
127
- maltoolbox attack-graph generate [options] <model_file> <lang_file>
128
129
  maltoolbox compile <lang_file> <output_file>
130
+ maltoolbox generate-attack-graph [--graphviz] <model_file> <lang_file>
129
131
  maltoolbox upgrade-model <model_file> <lang_file> <output_file>
132
+ maltoolbox visualize-model <model_file> <lang_file>
130
133
 
131
134
  Arguments:
132
135
  <model_file> Path to JSON instance model file.
133
136
  <lang_file> Path to .mar or .mal file containing MAL spec.
134
137
  <output_file> Path to write the result of the compilation (yml/json).
135
138
 
139
+ Options:
140
+ -h --help Show this screen.
141
+ -g --graphviz Visualize with graphviz
142
+
136
143
  Notes:
137
144
  - <lang_file> can be either a .mar file (generated by the older MAL
138
- compiler) or a .mal file containing the DSL written in MAL.
139
- ```
145
+ compiler) or a .mal file containing the DSL written in MAL.```
140
146
 
141
147
  ## Code examples / Tutorial
142
148
 
@@ -3,7 +3,7 @@
3
3
  MAL Toolbox is a collection of python modules to help developers create and work with
4
4
  MAL ([Meta Attack Language](https://mal-lang.org/)) models and attack graphs.
5
5
 
6
- Attack graphs can be used to run simulations (see MAL Simulator) or analysis.
6
+ Attack graphs can be used to run simulations in [MAL Simulator](https://github.com/mal-lang/mal-simulator) or run your own custom analysis on.
7
7
 
8
8
  [Documentation](https://mal-lang.org/mal-toolbox/index.html)(Work in progress)
9
9
 
@@ -97,19 +97,23 @@ You can use the maltoolbox cli to:
97
97
  Command-line interface for MAL toolbox operations
98
98
 
99
99
  Usage:
100
- maltoolbox attack-graph generate [options] <model_file> <lang_file>
101
100
  maltoolbox compile <lang_file> <output_file>
101
+ maltoolbox generate-attack-graph [--graphviz] <model_file> <lang_file>
102
102
  maltoolbox upgrade-model <model_file> <lang_file> <output_file>
103
+ maltoolbox visualize-model <model_file> <lang_file>
103
104
 
104
105
  Arguments:
105
106
  <model_file> Path to JSON instance model file.
106
107
  <lang_file> Path to .mar or .mal file containing MAL spec.
107
108
  <output_file> Path to write the result of the compilation (yml/json).
108
109
 
110
+ Options:
111
+ -h --help Show this screen.
112
+ -g --graphviz Visualize with graphviz
113
+
109
114
  Notes:
110
115
  - <lang_file> can be either a .mar file (generated by the older MAL
111
- compiler) or a .mal file containing the DSL written in MAL.
112
- ```
116
+ compiler) or a .mal file containing the DSL written in MAL.```
113
117
 
114
118
  ## Code examples / Tutorial
115
119
 
@@ -1,8 +1,8 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mal-toolbox
3
- Version: 1.0.4
3
+ Version: 1.0.5
4
4
  Summary: A collection of tools used to create MAL models and attack graphs.
5
- Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Giuseppe Nebbione <nebbione@kth.se>
5
+ Author-email: Andrei Buhaiu <buhaiu@kth.se>, Joakim Loxdal <loxdal@kth.se>, Nikolaos Kakouros <nkak@kth.se>, Jakob Nyberg <jaknyb@kth.se>, Giuseppe Nebbione <nebbione@kth.se>, Sandor Berglund <sandor@kth.se>
6
6
  License: Apache Software License
7
7
  Project-URL: Homepage, https://github.com/mal-lang/mal-toolbox
8
8
  Project-URL: Bug Tracker, https://github.com/mal-lang/mal-toolbox/issues
@@ -23,6 +23,8 @@ Requires-Dist: antlr4-tools
23
23
  Requires-Dist: antlr4-python3-runtime
24
24
  Requires-Dist: docopt
25
25
  Requires-Dist: PyYAML
26
+ Provides-Extra: dev
27
+ Requires-Dist: pytest; extra == "dev"
26
28
  Dynamic: license-file
27
29
 
28
30
  # MAL Toolbox overview
@@ -30,7 +32,7 @@ Dynamic: license-file
30
32
  MAL Toolbox is a collection of python modules to help developers create and work with
31
33
  MAL ([Meta Attack Language](https://mal-lang.org/)) models and attack graphs.
32
34
 
33
- Attack graphs can be used to run simulations (see MAL Simulator) or analysis.
35
+ Attack graphs can be used to run simulations in [MAL Simulator](https://github.com/mal-lang/mal-simulator) or run your own custom analysis on.
34
36
 
35
37
  [Documentation](https://mal-lang.org/mal-toolbox/index.html)(Work in progress)
36
38
 
@@ -124,19 +126,23 @@ You can use the maltoolbox cli to:
124
126
  Command-line interface for MAL toolbox operations
125
127
 
126
128
  Usage:
127
- maltoolbox attack-graph generate [options] <model_file> <lang_file>
128
129
  maltoolbox compile <lang_file> <output_file>
130
+ maltoolbox generate-attack-graph [--graphviz] <model_file> <lang_file>
129
131
  maltoolbox upgrade-model <model_file> <lang_file> <output_file>
132
+ maltoolbox visualize-model <model_file> <lang_file>
130
133
 
131
134
  Arguments:
132
135
  <model_file> Path to JSON instance model file.
133
136
  <lang_file> Path to .mar or .mal file containing MAL spec.
134
137
  <output_file> Path to write the result of the compilation (yml/json).
135
138
 
139
+ Options:
140
+ -h --help Show this screen.
141
+ -g --graphviz Visualize with graphviz
142
+
136
143
  Notes:
137
144
  - <lang_file> can be either a .mar file (generated by the older MAL
138
- compiler) or a .mal file containing the DSL written in MAL.
139
- ```
145
+ compiler) or a .mal file containing the DSL written in MAL.```
140
146
 
141
147
  ## Code examples / Tutorial
142
148
 
@@ -3,3 +3,6 @@ antlr4-tools
3
3
  antlr4-python3-runtime
4
4
  docopt
5
5
  PyYAML
6
+
7
+ [dev]
8
+ pytest
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # MAL Toolbox v1.0.4
2
+ # MAL Toolbox v1.0.5
3
3
  # Copyright 2025, Andrei Buhaiu.
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,7 @@ MAL-Toolbox Framework
21
21
  """
22
22
 
23
23
  __title__ = "maltoolbox"
24
- __version__ = "1.0.4"
24
+ __version__ = "1.0.5"
25
25
  __authors__ = [
26
26
  "Andrei Buhaiu",
27
27
  "Giuseppe Nebbione",
@@ -192,7 +192,10 @@ class AttackGraph():
192
192
  node_id = node_dict['id'],
193
193
  model_asset = node_asset,
194
194
  ttc_dist = node_dict['ttc'],
195
- existence_status = node_dict.get('existence_status', None)
195
+ existence_status = (
196
+ bool(node_dict['existence_status'])
197
+ if 'existence_status' in node_dict else None
198
+ )
196
199
  )
197
200
  ag_node.tags = list(node_dict.get('tags', []))
198
201
  ag_node.extras = node_dict.get('extras', {})
@@ -56,7 +56,7 @@ class AttackGraphNode:
56
56
  if self.model_asset is not None:
57
57
  node_dict['asset'] = str(self.model_asset.name)
58
58
  if self.existence_status is not None:
59
- node_dict['existence_status'] = str(self.existence_status)
59
+ node_dict['existence_status'] = self.existence_status
60
60
  if self.tags:
61
61
  node_dict['tags'] = list(self.tags)
62
62
  if self.extras:
@@ -10,7 +10,7 @@ import zipfile
10
10
 
11
11
  from dataclasses import dataclass, field
12
12
  from functools import cached_property
13
- from typing import Any, Optional
13
+ from typing import Any, Literal, Optional
14
14
 
15
15
  from maltoolbox.file_utils import (
16
16
  load_dict_from_yaml_file, load_dict_from_json_file,
@@ -222,7 +222,7 @@ class LanguageGraphAsset:
222
222
  return self_superassets.intersection(other_superassets)
223
223
 
224
224
 
225
- @dataclass
225
+ @dataclass(frozen=True)
226
226
  class LanguageGraphAssociationField:
227
227
  """A field in an association"""
228
228
  asset: LanguageGraphAsset
@@ -231,7 +231,7 @@ class LanguageGraphAssociationField:
231
231
  maximum: int
232
232
 
233
233
 
234
- @dataclass
234
+ @dataclass(frozen=True, eq=True)
235
235
  class LanguageGraphAssociation:
236
236
  """
237
237
  An association type between asset types as defined in the MAL language
@@ -239,7 +239,7 @@ class LanguageGraphAssociation:
239
239
  name: str
240
240
  left_field: LanguageGraphAssociationField
241
241
  right_field: LanguageGraphAssociationField
242
- info: dict = field(default_factory = dict)
242
+ info: dict = field(default_factory = dict, compare=False)
243
243
 
244
244
  def to_dict(self) -> dict:
245
245
  """Convert LanguageGraphAssociation to dictionary"""
@@ -356,7 +356,7 @@ class LanguageGraphAttackStep:
356
356
  An attack step belonging to an asset type in the MAL language
357
357
  """
358
358
  name: str
359
- type: str
359
+ type: Literal["or", "and", "defense", "exist", "notExist"]
360
360
  asset: LanguageGraphAsset
361
361
  ttc: Optional[dict] = field(default_factory = dict)
362
362
  overrides: bool = False
@@ -739,6 +739,13 @@ class LanguageGraph():
739
739
 
740
740
  return serialized_graph
741
741
 
742
+ @property
743
+ def associations(self) -> set[LanguageGraphAssociation]:
744
+ """
745
+ Return all associations in the language graph.
746
+ """
747
+ return {assoc for asset in self.assets.values() for assoc in asset.associations.values()}
748
+
742
749
  @staticmethod
743
750
  def _link_association_to_assets(
744
751
  assoc: LanguageGraphAssociation,
@@ -3,7 +3,6 @@ MAL-Toolbox Model Module
3
3
  """
4
4
 
5
5
  from __future__ import annotations
6
- from dataclasses import dataclass, field
7
6
  import json
8
7
  import logging
9
8
  from typing import TYPE_CHECKING
@@ -23,6 +22,7 @@ if TYPE_CHECKING:
23
22
  from .language import (
24
23
  LanguageGraph,
25
24
  LanguageGraphAsset,
25
+ LanguageGraphAssociation
26
26
  )
27
27
 
28
28
  logger = logging.getLogger(__name__)
@@ -361,6 +361,34 @@ class ModelAsset:
361
361
  return (f'ModelAsset(name: "{self.name}", id: {self.id}, '
362
362
  f'type: {self.type})')
363
363
 
364
+ def associations_with(
365
+ self, b: ModelAsset
366
+ ) -> set[LanguageGraphAssociation]:
367
+ """Returns all associations from self to `b`"""
368
+ assocs_in_common = set()
369
+ for assoc in self.lg_asset.associations.values():
370
+ assets_to_left = self.associated_assets.get(
371
+ assoc.left_field.fieldname, set()
372
+ )
373
+ assets_to_right = self.associated_assets.get(
374
+ assoc.right_field.fieldname, set()
375
+ )
376
+ if b in assets_to_left or b in assets_to_right:
377
+ assocs_in_common.add(assoc)
378
+
379
+ return assocs_in_common
380
+
381
+ def has_association_with(self, b: ModelAsset, assoc_name: str) -> bool:
382
+ """
383
+ Returns True if association `assoc_name` exists between self and `b`
384
+ """
385
+
386
+ for fieldname, associated_assets in self.associated_assets.items():
387
+ assoc = self.lg_asset.associations[fieldname]
388
+ if assoc.name == assoc_name and b in associated_assets:
389
+ return True
390
+
391
+ return False
364
392
 
365
393
  def validate_associated_assets(
366
394
  self, fieldname: str, assets_to_add: set[ModelAsset]
@@ -1,12 +1,13 @@
1
1
  [project]
2
2
  name = "mal-toolbox"
3
- version = "1.0.4"
3
+ version = "1.0.5"
4
4
  authors = [
5
5
  { name="Andrei Buhaiu", email="buhaiu@kth.se" },
6
6
  { name="Joakim Loxdal", email="loxdal@kth.se" },
7
7
  { name="Nikolaos Kakouros", email="nkak@kth.se" },
8
8
  { name="Jakob Nyberg", email="jaknyb@kth.se" },
9
- { name="Giuseppe Nebbione", email="nebbione@kth.se" }
9
+ { name="Giuseppe Nebbione", email="nebbione@kth.se" },
10
+ { name="Sandor Berglund", email="sandor@kth.se" }
10
11
  ]
11
12
  description = "A collection of tools used to create MAL models and attack graphs."
12
13
  readme = "README.md"
@@ -34,6 +35,11 @@ classifiers = [
34
35
  "Bug Tracker" = "https://github.com/mal-lang/mal-toolbox/issues"
35
36
  "Repository" = "https://github.com/mal-lang/mal-toolbox"
36
37
 
38
+ [project.optional-dependencies]
39
+ dev = [
40
+ "pytest",
41
+ ]
42
+
37
43
  [project.scripts]
38
44
  "maltoolbox" = "maltoolbox.__main__:main"
39
45
 
@@ -125,6 +125,12 @@ def test_model_add_associated_asset(model: Model):
125
125
  assert 'hostApp' in asset2.associated_assets
126
126
  assert asset1 in asset2.associated_assets['hostApp']
127
127
 
128
+ associations_in_common = asset1.associations_with(asset2)
129
+ assert associations_in_common
130
+
131
+ for assoc in associations_in_common:
132
+ assert asset1.has_association_with(asset2, assoc.name)
133
+
128
134
 
129
135
  def test_model_add_appexecution_association_two_assets(model: Model):
130
136
  """coreLang specifies that AppExecution only can have one 'left' asset"""
File without changes
File without changes
File without changes