checkmate5 4.0.67__py3-none-any.whl

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 (116) hide show
  1. checkmate/__init__.py +21 -0
  2. checkmate/__main__.py +25 -0
  3. checkmate/contrib/__init__.py +21 -0
  4. checkmate/contrib/plugins/__init__.py +0 -0
  5. checkmate/contrib/plugins/all/gptanalyzer/__init__.py +0 -0
  6. checkmate/contrib/plugins/all/gptanalyzer/analyzer.py +99 -0
  7. checkmate/contrib/plugins/all/gptanalyzer/issues_data.py +6 -0
  8. checkmate/contrib/plugins/all/gptanalyzer/setup.py +13 -0
  9. checkmate/contrib/plugins/cve/__init__.py +0 -0
  10. checkmate/contrib/plugins/cve/text4shell/__init__.py +0 -0
  11. checkmate/contrib/plugins/cve/text4shell/analyzer.py +64 -0
  12. checkmate/contrib/plugins/cve/text4shell/issues_data.py +8 -0
  13. checkmate/contrib/plugins/cve/text4shell/setup.py +13 -0
  14. checkmate/contrib/plugins/git/__init__.py +0 -0
  15. checkmate/contrib/plugins/git/commands/__init__.py +6 -0
  16. checkmate/contrib/plugins/git/commands/analyze.py +364 -0
  17. checkmate/contrib/plugins/git/commands/base.py +16 -0
  18. checkmate/contrib/plugins/git/commands/diff.py +199 -0
  19. checkmate/contrib/plugins/git/commands/init.py +59 -0
  20. checkmate/contrib/plugins/git/commands/update_stats.py +41 -0
  21. checkmate/contrib/plugins/git/hooks/__init__.py +0 -0
  22. checkmate/contrib/plugins/git/hooks/project.py +19 -0
  23. checkmate/contrib/plugins/git/lib/__init__.py +1 -0
  24. checkmate/contrib/plugins/git/lib/repository.py +557 -0
  25. checkmate/contrib/plugins/git/lib/repository_pygit2.py +531 -0
  26. checkmate/contrib/plugins/git/models.py +178 -0
  27. checkmate/contrib/plugins/git/setup.py +27 -0
  28. checkmate/contrib/plugins/golang/__init__.py +0 -0
  29. checkmate/contrib/plugins/golang/gostaticcheck/__init__.py +0 -0
  30. checkmate/contrib/plugins/golang/gostaticcheck/analyzer.py +94 -0
  31. checkmate/contrib/plugins/golang/gostaticcheck/issues_data.py +1246 -0
  32. checkmate/contrib/plugins/golang/gostaticcheck/setup.py +13 -0
  33. checkmate/contrib/plugins/iac/__init__.py +0 -0
  34. checkmate/contrib/plugins/iac/kubescape/__init__.py +0 -0
  35. checkmate/contrib/plugins/iac/kubescape/analyzer.py +115 -0
  36. checkmate/contrib/plugins/iac/kubescape/issues_data.py +636 -0
  37. checkmate/contrib/plugins/iac/kubescape/setup.py +14 -0
  38. checkmate/contrib/plugins/iac/tfsec/__init__.py +0 -0
  39. checkmate/contrib/plugins/iac/tfsec/analyzer.py +92 -0
  40. checkmate/contrib/plugins/iac/tfsec/issues_data.py +1917 -0
  41. checkmate/contrib/plugins/iac/tfsec/setup.py +13 -0
  42. checkmate/contrib/plugins/java/__init__.py +0 -0
  43. checkmate/contrib/plugins/java/semgrepjava/__init__.py +0 -0
  44. checkmate/contrib/plugins/java/semgrepjava/analyzer.py +96 -0
  45. checkmate/contrib/plugins/java/semgrepjava/issues_data.py +5 -0
  46. checkmate/contrib/plugins/java/semgrepjava/setup.py +13 -0
  47. checkmate/contrib/plugins/javascript/__init__.py +0 -0
  48. checkmate/contrib/plugins/javascript/semgrepeslint/__init__.py +0 -0
  49. checkmate/contrib/plugins/javascript/semgrepeslint/analyzer.py +95 -0
  50. checkmate/contrib/plugins/javascript/semgrepeslint/issues_data.py +6 -0
  51. checkmate/contrib/plugins/javascript/semgrepeslint/setup.py +13 -0
  52. checkmate/contrib/plugins/perl/__init__.py +0 -0
  53. checkmate/contrib/plugins/perl/graudit/__init__.py +0 -0
  54. checkmate/contrib/plugins/perl/graudit/analyzer.py +70 -0
  55. checkmate/contrib/plugins/perl/graudit/issues_data.py +8 -0
  56. checkmate/contrib/plugins/perl/graudit/setup.py +13 -0
  57. checkmate/contrib/plugins/python/__init__.py +0 -0
  58. checkmate/contrib/plugins/python/bandit/__init__.py +0 -0
  59. checkmate/contrib/plugins/python/bandit/analyzer.py +74 -0
  60. checkmate/contrib/plugins/python/bandit/issues_data.py +426 -0
  61. checkmate/contrib/plugins/python/bandit/setup.py +13 -0
  62. checkmate/contrib/plugins/ruby/__init__.py +0 -0
  63. checkmate/contrib/plugins/ruby/brakeman/__init__.py +0 -0
  64. checkmate/contrib/plugins/ruby/brakeman/analyzer.py +96 -0
  65. checkmate/contrib/plugins/ruby/brakeman/issues_data.py +518 -0
  66. checkmate/contrib/plugins/ruby/brakeman/setup.py +13 -0
  67. checkmate/helpers/__init__.py +0 -0
  68. checkmate/helpers/facts.py +26 -0
  69. checkmate/helpers/hashing.py +68 -0
  70. checkmate/helpers/issue.py +101 -0
  71. checkmate/helpers/settings.py +14 -0
  72. checkmate/lib/__init__.py +1 -0
  73. checkmate/lib/analysis/__init__.py +3 -0
  74. checkmate/lib/analysis/base.py +103 -0
  75. checkmate/lib/code/__init__.py +3 -0
  76. checkmate/lib/code/environment.py +809 -0
  77. checkmate/lib/models.py +515 -0
  78. checkmate/lib/stats/__init__.py +1 -0
  79. checkmate/lib/stats/helpers.py +19 -0
  80. checkmate/lib/stats/mapreduce.py +29 -0
  81. checkmate/management/__init__.py +1 -0
  82. checkmate/management/commands/__init__.py +18 -0
  83. checkmate/management/commands/alembic.py +32 -0
  84. checkmate/management/commands/analyze.py +42 -0
  85. checkmate/management/commands/analyzers.py +1 -0
  86. checkmate/management/commands/base.py +66 -0
  87. checkmate/management/commands/compare.py +0 -0
  88. checkmate/management/commands/export.py +0 -0
  89. checkmate/management/commands/info.py +0 -0
  90. checkmate/management/commands/init.py +103 -0
  91. checkmate/management/commands/issues.py +478 -0
  92. checkmate/management/commands/props/__init__.py +1 -0
  93. checkmate/management/commands/props/delete.py +29 -0
  94. checkmate/management/commands/props/get.py +30 -0
  95. checkmate/management/commands/props/set.py +29 -0
  96. checkmate/management/commands/reset.py +53 -0
  97. checkmate/management/commands/shell.py +19 -0
  98. checkmate/management/commands/snapshots.py +22 -0
  99. checkmate/management/commands/stats.py +21 -0
  100. checkmate/management/commands/summary.py +19 -0
  101. checkmate/management/commands/sync.py +63 -0
  102. checkmate/management/commands/trend.py +1 -0
  103. checkmate/management/commands/watch.py +27 -0
  104. checkmate/management/decorators.py +1 -0
  105. checkmate/management/helpers.py +140 -0
  106. checkmate/scripts/__init__.py +18 -0
  107. checkmate/scripts/manage.py +121 -0
  108. checkmate/settings/__init__.py +2 -0
  109. checkmate/settings/base.py +127 -0
  110. checkmate/settings/defaults.py +133 -0
  111. checkmate5-4.0.67.dist-info/LICENSE.txt +4095 -0
  112. checkmate5-4.0.67.dist-info/METADATA +15 -0
  113. checkmate5-4.0.67.dist-info/RECORD +116 -0
  114. checkmate5-4.0.67.dist-info/WHEEL +5 -0
  115. checkmate5-4.0.67.dist-info/entry_points.txt +2 -0
  116. checkmate5-4.0.67.dist-info/top_level.txt +1 -0
@@ -0,0 +1,178 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ from checkmate.helpers.hashing import Hasher
5
+ from .lib.repository import Repository
6
+ from checkmate.lib.models import (Snapshot,
7
+ Project,
8
+ BaseDocument,
9
+ FileRevision,
10
+ Diff,
11
+ IssueOccurrence)
12
+ from blitzdb.fields import (DateTimeField,
13
+ CharField,
14
+ IntegerField,
15
+ ForeignKeyField,
16
+ EnumField,
17
+ TextField,
18
+ ManyToManyField)
19
+ import os
20
+ import uuid
21
+ import time
22
+ import datetime
23
+ import logging
24
+ import copy
25
+ import traceback
26
+ import random
27
+ from secrets import choice
28
+ import string
29
+
30
+ logger = logging.getLogger(__name__)
31
+
32
+
33
+ class GitRepository(BaseDocument):
34
+
35
+ path_ = CharField(indexed=True)
36
+ project = ForeignKeyField('Project', backref='git', unique=True)
37
+ default_branch = CharField(indexed=True)
38
+
39
+ @property
40
+ def path(self):
41
+ return self.path_
42
+
43
+ @path.setter
44
+ def path(self, path):
45
+ self.path_ = path
46
+
47
+ def get_settings(self):
48
+ default_branch = self.get_default_branch()
49
+ if default_branch is None:
50
+ return
51
+ branches = self.repository.get_branches()
52
+ if default_branch in branches:
53
+ latest_commit = self.repository.get_commits(
54
+ default_branch, limit=1)[0]
55
+ try:
56
+ checkmate_file_content = self.repository\
57
+ .get_file_content(latest_commit['sha'], '.checkmate.yml')
58
+ try:
59
+ checkmate_settings = yaml.load(checkmate_file_content)
60
+ return checkmate_settings
61
+ except:
62
+ raise ValueError("Cannot parse checkmate YML file!")
63
+ except:
64
+ #logger.warning("No .checkmate.yml file found!")
65
+ pass
66
+ return
67
+
68
+ @property
69
+ def repository(self):
70
+ if not hasattr(self, '_repository'):
71
+ self._repository = Repository(self.path)
72
+ return self._repository
73
+
74
+ def get_snapshots(self, **kwargs):
75
+ """
76
+ Returns a list of snapshots in a given repository.
77
+ """
78
+ commits = self.repository.get_commits(**kwargs)
79
+ snapshots = []
80
+ for commit in commits:
81
+ for key in ('committer_date', 'author_date'):
82
+ commit[key] = datetime.datetime.fromtimestamp(
83
+ commit[key+'_ts'])
84
+ snapshot = GitSnapshot(commit)
85
+ hasher = Hasher()
86
+ hasher.add(snapshot.sha)
87
+ snapshot.hash = hasher.digest.hexdigest()
88
+ snapshot.project = self.project
89
+ snapshot.pk = uuid.uuid4().hex
90
+ snapshots.append(snapshot)
91
+ return snapshots
92
+
93
+ def get_file_revisions(self, commit_sha, filters=None):
94
+
95
+ pck_mngr = [ "buildscript-gradle.lockfile", "Cargo.lock", "composer.lock",
96
+ "Gemfile.lock", "go.mod", "gradle.lockfile", "mix.lock", "package-lock.json",
97
+ "packages.lock.json", "Pipfile.lock", "pnpm-lock.yaml", "poetry.lock",
98
+ "pom.xml", "pubspec.lock", "requirements.txt", "yarn.lock" ]
99
+ files = self.repository.get_files_in_commit(commit_sha)
100
+
101
+ if filters:
102
+ for filter_func in filters:
103
+ files = [f for f in files if f['path']
104
+ in filter_func([ff['path'] for ff in files])]
105
+
106
+ file_revisions = []
107
+ for file_obj in files:
108
+
109
+ hasher = Hasher()
110
+ file_revision = FileRevision(file_obj)
111
+
112
+ if not (file_revision.path == ".checkmate/config.json" or file_revision.path == ".checkmate/db.sqlite" \
113
+ or file_revision.path == "report.html" or file_revision.path == "report.json" \
114
+ or file_revision.path == "report.sarif" or file_revision.path == "style.css"):
115
+ hasher.add(file_revision.path)
116
+ hasher.add(file_revision.sha)
117
+
118
+ file_revision.project = self.project
119
+ if(file_revision.path in pck_mngr):
120
+ logger.info("No state for package databases - always scanning package database for vulnerabilities %s", file_revision.path)
121
+ hasher.add(''.join(random.choices(string.ascii_uppercase + string.digits, k=64)))
122
+ file_revision.hash = hasher.digest.hexdigest()
123
+ else:
124
+ file_revision.hash = hasher.digest.hexdigest()
125
+ file_revision.pk = uuid.uuid4().hex
126
+ file_revision._file_content = lambda commit_sha = commit_sha, file_revision = file_revision: self.repository.get_file_content(
127
+ commit_sha, file_revision.path)
128
+ file_revisions.append(file_revision)
129
+
130
+
131
+ return file_revisions
132
+
133
+ def get_default_branch(self):
134
+ branches = self.repository.get_branches()
135
+ if self.default_branch in branches:
136
+ return self.default_branch
137
+ elif 'origin/master' in branches:
138
+ return 'origin/master'
139
+ elif branches:
140
+ return branches[0]
141
+ else:
142
+ return
143
+
144
+
145
+ class GitSnapshot(BaseDocument):
146
+
147
+ """
148
+ """
149
+
150
+ project = ForeignKeyField('Project', unique=False, backref='git_snapshots')
151
+ snapshot = ForeignKeyField('Snapshot', unique=True, backref='git_snapshot')
152
+ sha = CharField(indexed=True, length=40)
153
+ hash = CharField(indexed=True, length=64)
154
+ committer_date = DateTimeField(indexed=True)
155
+ author_date = DateTimeField(indexed=True)
156
+ author_name = CharField(length=100)
157
+ committer_date_ts = IntegerField(indexed=True)
158
+ author_date_ts = IntegerField(indexed=True)
159
+ tree_sha = CharField(indexed=True, length=40)
160
+ log = TextField(indexed=False)
161
+
162
+ class Meta(BaseDocument.Meta):
163
+
164
+ unique_together = [('project', 'sha')]
165
+
166
+
167
+ class GitBranch(BaseDocument):
168
+
169
+ project = ForeignKeyField('Project', backref='git_branches')
170
+ name = CharField(indexed=True, length=100)
171
+ hash = CharField(indexed=True, length=64)
172
+ remote = CharField(indexed=True, length=100)
173
+ last_analyzed_snapshot = ForeignKeyField('GitSnapshot')
174
+ head_snapshot = ForeignKeyField('GitSnapshot')
175
+
176
+ class Meta(BaseDocument.Meta):
177
+
178
+ unique_together = [('project', 'name')]
@@ -0,0 +1,27 @@
1
+ from .commands.analyze import Command as AnalyzeCommand
2
+ from .commands.diff import Command as DiffCommand
3
+ from .commands.update_stats import Command as UpdateStatsCommand
4
+ from .commands.init import Command as InitCommand
5
+
6
+ from .models import GitSnapshot, GitBranch, GitRepository
7
+ from .hooks.project import before_project_save, before_project_reset
8
+
9
+ commands = {
10
+ 'init': InitCommand,
11
+ 'analyze': AnalyzeCommand,
12
+ 'diff': DiffCommand,
13
+ 'update_stats': UpdateStatsCommand
14
+ }
15
+
16
+ models = {
17
+ 'GitSnapshot': GitSnapshot,
18
+ 'GitBranch': GitBranch,
19
+ 'GitRepository': GitRepository,
20
+ }
21
+
22
+ hooks = {
23
+ 'project.save.before': before_project_save,
24
+ 'project.reset.before': before_project_reset
25
+ }
26
+
27
+ top_level_commands = {}
File without changes
@@ -0,0 +1,94 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+
4
+ from checkmate.lib.analysis.base import BaseAnalyzer
5
+
6
+ import logging
7
+ import os
8
+ import tempfile
9
+ import json
10
+ import subprocess
11
+
12
+
13
+ logger = logging.getLogger(__name__)
14
+
15
+
16
+ class GostaticcheckAnalyzer(BaseAnalyzer):
17
+
18
+ def __init__(self, *args, **kwargs):
19
+ super(GostaticcheckAnalyzer, self).__init__(*args, **kwargs)
20
+
21
+ def summarize(self, items):
22
+ pass
23
+
24
+ def analyze(self, file_revision):
25
+ issues = []
26
+ tmpdir = "/tmp/"+file_revision.project.pk
27
+
28
+ if not os.path.exists(os.path.dirname(tmpdir+"/"+file_revision.path)):
29
+ try:
30
+ os.makedirs(os.path.dirname(tmpdir+"/"+file_revision.path))
31
+ except OSError as exc: # Guard against race condition
32
+ if exc.errno != errno.EEXIST:
33
+ raise
34
+
35
+ result = subprocess.check_output(["rsync -r . "+tmpdir+" --exclude .git"],shell=True).strip()
36
+
37
+ f = open(tmpdir+"/"+file_revision.path, "wb")
38
+
39
+ result = {}
40
+ try:
41
+ with f:
42
+ try:
43
+ f.write(file_revision.get_file_content())
44
+ except UnicodeDecodeError:
45
+ pass
46
+ os.chdir(tmpdir)
47
+ os.environ["PATH"] = "/root/.go/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/:/usr/local/go/bin/"
48
+
49
+ try:
50
+ result = subprocess.check_output(["/root/bin/staticcheck",
51
+ "-f", "json",
52
+ f.name],
53
+ stderr=subprocess.DEVNULL).strip()
54
+ except subprocess.CalledProcessError as e:
55
+ if e.returncode == 2:
56
+ result = e.output
57
+ elif e.returncode == 1:
58
+ result = e.output
59
+ pass
60
+ else:
61
+ result = []
62
+
63
+ for line in result.splitlines():
64
+ try:
65
+ json_result = json.loads(line)
66
+ except ValueError:
67
+ json_result = []
68
+ pass
69
+ try:
70
+ issue = json_result
71
+ value = issue['location']['line']
72
+
73
+ location = (((value,None),
74
+ (value,None)),)
75
+
76
+
77
+
78
+ if ".go" in file_revision.path:
79
+ issues.append({
80
+ 'code': issue['code'],
81
+ 'location': location,
82
+ 'data': issue['message'],
83
+ 'file': file_revision.path,
84
+ 'line': value,
85
+ 'fingerprint': self.get_fingerprint_from_code(file_revision, location, extra_data=issue['message'])
86
+ })
87
+
88
+ except:
89
+ pass
90
+
91
+ finally:
92
+ pass
93
+ return {'issues': issues}
94
+