|
1
|
|
|
# |
|
2
|
|
|
# Copyright (C) 2020 Red Hat, Inc. |
|
3
|
|
|
# |
|
4
|
|
|
# This copyrighted material is made available to anyone wishing to use, |
|
5
|
|
|
# modify, copy, or redistribute it subject to the terms and conditions of |
|
6
|
|
|
# the GNU General Public License v.2, or (at your option) any later version. |
|
7
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT |
|
8
|
|
|
# ANY WARRANTY expressed or implied, including the implied warranties of |
|
9
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
|
10
|
|
|
# Public License for more details. You should have received a copy of the |
|
11
|
|
|
# GNU General Public License along with this program; if not, write to the |
|
12
|
|
|
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
13
|
|
|
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the |
|
14
|
|
|
# source code or documentation are not subject to the GNU General Public |
|
15
|
|
|
# License and may only be used or replicated with the express permission of |
|
16
|
|
|
# Red Hat, Inc. |
|
17
|
|
|
# |
|
18
|
|
|
from dasbus.structure import DBusData |
|
19
|
|
|
from dasbus.typing import * # pylint: disable=wildcard-import |
|
20
|
|
|
|
|
21
|
|
|
from org_fedora_oscap import common |
|
22
|
|
|
|
|
23
|
|
|
__all__ = ["PolicyData"] |
|
24
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
class PolicyData(DBusData): |
|
27
|
|
|
"""The security policy data.""" |
|
28
|
|
|
|
|
29
|
|
|
def __init__(self): |
|
30
|
|
|
# values specifying the content |
|
31
|
|
|
self._content_type = "" |
|
32
|
|
|
self._content_url = "" |
|
33
|
|
|
self._datastream_id = "" |
|
34
|
|
|
self._xccdf_id = "" |
|
35
|
|
|
self._profile_id = "" |
|
36
|
|
|
self._content_path = "" |
|
37
|
|
|
self._cpe_path = "" |
|
38
|
|
|
self._tailoring_path = "" |
|
39
|
|
|
self._fingerprint = "" |
|
40
|
|
|
self._certificates = "" |
|
41
|
|
|
|
|
42
|
|
|
def update_from(self, rhs): |
|
43
|
|
|
self._content_type = rhs._content_type |
|
44
|
|
|
self._content_url = rhs._content_url |
|
45
|
|
|
self._datastream_id = rhs._datastream_id |
|
46
|
|
|
self._xccdf_id = rhs._xccdf_id |
|
47
|
|
|
self._profile_id = rhs._profile_id |
|
48
|
|
|
self._content_path = rhs._content_path |
|
49
|
|
|
self._cpe_path = rhs._cpe_path |
|
50
|
|
|
self._tailoring_path = rhs._tailoring_path |
|
51
|
|
|
self._fingerprint = rhs._fingerprint |
|
52
|
|
|
self._certificates = rhs._certificates |
|
53
|
|
|
|
|
54
|
|
|
@property |
|
55
|
|
|
def content_type(self) -> Str: |
|
56
|
|
|
"""Type of the security content. |
|
57
|
|
|
|
|
58
|
|
|
If the content type is scap-security-guide, the add-on |
|
59
|
|
|
will use content provided by the scap-security-guide. |
|
60
|
|
|
All other attributes except profile will have no effect. |
|
61
|
|
|
|
|
62
|
|
|
Supported values: |
|
63
|
|
|
|
|
64
|
|
|
datastream |
|
65
|
|
|
archive |
|
66
|
|
|
rpm |
|
67
|
|
|
scap-security-guide |
|
68
|
|
|
|
|
69
|
|
|
:return: a string |
|
70
|
|
|
""" |
|
71
|
|
|
return self._content_type |
|
72
|
|
|
|
|
73
|
|
|
@content_type.setter |
|
74
|
|
|
def content_type(self, value: Str): |
|
75
|
|
|
self._content_type = value |
|
76
|
|
|
|
|
77
|
|
|
@property |
|
78
|
|
|
def content_url(self) -> Str: |
|
79
|
|
|
"""Location of the security content. |
|
80
|
|
|
|
|
81
|
|
|
So far only http, https, and ftp URLs are supported. |
|
82
|
|
|
|
|
83
|
|
|
:return: an URL |
|
84
|
|
|
""" |
|
85
|
|
|
return self._content_url |
|
86
|
|
|
|
|
87
|
|
|
@content_url.setter |
|
88
|
|
|
def content_url(self, value: Str): |
|
89
|
|
|
self._content_url = value |
|
90
|
|
|
|
|
91
|
|
|
@property |
|
92
|
|
|
def datastream_id(self) -> Str: |
|
93
|
|
|
"""ID of the data stream. |
|
94
|
|
|
|
|
95
|
|
|
It is an ID of the data stream from a datastream |
|
96
|
|
|
collection referenced by the content url. Used only |
|
97
|
|
|
if the content type is datastream. |
|
98
|
|
|
|
|
99
|
|
|
:return: a string |
|
100
|
|
|
""" |
|
101
|
|
|
return self._datastream_id |
|
102
|
|
|
|
|
103
|
|
|
@datastream_id.setter |
|
104
|
|
|
def datastream_id(self, value: Str): |
|
105
|
|
|
self._datastream_id = value |
|
106
|
|
|
|
|
107
|
|
|
@property |
|
108
|
|
|
def xccdf_id(self) -> Str: |
|
109
|
|
|
"""ID of the benchmark that should be used. |
|
110
|
|
|
|
|
111
|
|
|
:return: a string |
|
112
|
|
|
""" |
|
113
|
|
|
return self._xccdf_id |
|
114
|
|
|
|
|
115
|
|
|
@xccdf_id.setter |
|
116
|
|
|
def xccdf_id(self, value: Str): |
|
117
|
|
|
self._xccdf_id = value |
|
118
|
|
|
|
|
119
|
|
|
@property |
|
120
|
|
|
def profile_id(self) -> Str: |
|
121
|
|
|
"""ID of the profile that should be applied. |
|
122
|
|
|
|
|
123
|
|
|
Use 'default' if the default profile should be used. |
|
124
|
|
|
|
|
125
|
|
|
:return: a string |
|
126
|
|
|
""" |
|
127
|
|
|
return self._profile_id |
|
128
|
|
|
|
|
129
|
|
|
@profile_id.setter |
|
130
|
|
|
def profile_id(self, value: Str): |
|
131
|
|
|
self._profile_id = value |
|
132
|
|
|
|
|
133
|
|
|
@property |
|
134
|
|
|
def content_path(self) -> Str: |
|
135
|
|
|
"""Path to the datastream or the XCCDF file which should be used. |
|
136
|
|
|
|
|
137
|
|
|
:return: a relative path in the archive |
|
138
|
|
|
""" |
|
139
|
|
|
return self._content_path |
|
140
|
|
|
|
|
141
|
|
|
@content_path.setter |
|
142
|
|
|
def content_path(self, value: Str): |
|
143
|
|
|
self._content_path = value |
|
144
|
|
|
|
|
145
|
|
|
@property |
|
146
|
|
|
def cpe_path(self) -> Str: |
|
147
|
|
|
"""Path to the datastream or the XCCDF file that should be used. |
|
148
|
|
|
|
|
149
|
|
|
:return: a relative path in the archive |
|
150
|
|
|
""" |
|
151
|
|
|
return self._cpe_path |
|
152
|
|
|
|
|
153
|
|
|
@cpe_path.setter |
|
154
|
|
|
def cpe_path(self, value: Str): |
|
155
|
|
|
self._cpe_path = value |
|
156
|
|
|
|
|
157
|
|
|
@property |
|
158
|
|
|
def tailoring_path(self) -> Str: |
|
159
|
|
|
"""Path of the tailoring file that should be used. |
|
160
|
|
|
|
|
161
|
|
|
:return: a relative path in the archive |
|
162
|
|
|
""" |
|
163
|
|
|
return self._tailoring_path |
|
164
|
|
|
|
|
165
|
|
|
@tailoring_path.setter |
|
166
|
|
|
def tailoring_path(self, value: Str): |
|
167
|
|
|
self._tailoring_path = value |
|
168
|
|
|
|
|
169
|
|
|
@property |
|
170
|
|
|
def fingerprint(self) -> Str: |
|
171
|
|
|
"""Checksum of the security content. |
|
172
|
|
|
|
|
173
|
|
|
It is an MD5, SHA1 or SHA2 fingerprint/hash/checksum |
|
174
|
|
|
of the content referred by the content url. |
|
175
|
|
|
|
|
176
|
|
|
:return: a string |
|
177
|
|
|
""" |
|
178
|
|
|
return self._fingerprint |
|
179
|
|
|
|
|
180
|
|
|
@fingerprint.setter |
|
181
|
|
|
def fingerprint(self, value: Str): |
|
182
|
|
|
self._fingerprint = value |
|
183
|
|
|
|
|
184
|
|
|
@property |
|
185
|
|
|
def certificates(self) -> Str: |
|
186
|
|
|
"""Path to a PEM file with CA certificate chain. |
|
187
|
|
|
|
|
188
|
|
|
:return: a path |
|
189
|
|
|
""" |
|
190
|
|
|
return self._certificates |
|
191
|
|
|
|
|
192
|
|
|
@certificates.setter |
|
193
|
|
|
def certificates(self, value: Str): |
|
194
|
|
|
self._certificates = value |
|
195
|
|
|
|
|
196
|
|
|
def clear_all(self): |
|
197
|
|
|
self.content_type = "" |
|
198
|
|
|
self.content_url = "" |
|
199
|
|
|
self.datastream_id = "" |
|
200
|
|
|
self.xccdf_id = "" |
|
201
|
|
|
self.profile_id = "" |
|
202
|
|
|
self.content_path = "" |
|
203
|
|
|
self.cpe_path = "" |
|
204
|
|
|
self.tailoring_path = "" |
|
205
|
|
|
self.fingerprint = "" |
|
206
|
|
|
self.certificates = "" |
|
207
|
|
|
|
|
208
|
|
|
def use_system_content(self): |
|
209
|
|
|
self.clear_all() |
|
210
|
|
|
self.content_type = "scap-security-guide" |
|
211
|
|
|
self.content_path = common.get_ssg_path() |
|
212
|
|
|
|
|
213
|
|
|
def use_downloaded_content(self, content): |
|
214
|
|
|
preferred_content = content.get_preferred_content(self.content_path) |
|
215
|
|
|
|
|
216
|
|
|
# We know that we have ended up with a datastream-like content, |
|
217
|
|
|
# but if we can't convert an archive to a datastream. |
|
218
|
|
|
# self.content_type = "datastream" |
|
219
|
|
|
content_type = self.content_type |
|
220
|
|
|
if content_type in ("archive", "rpm"): |
|
221
|
|
|
self.content_path = str(preferred_content.relative_to(content.root)) |
|
222
|
|
|
else: |
|
223
|
|
|
self.content_path = str(preferred_content) |
|
224
|
|
|
|
|
225
|
|
|
preferred_tailoring = content.get_preferred_tailoring(self.tailoring_path) |
|
226
|
|
|
if content.tailoring: |
|
227
|
|
|
if content_type in ("archive", "rpm"): |
|
228
|
|
|
self.tailoring_path = str(preferred_tailoring.relative_to(content.root)) |
|
229
|
|
|
else: |
|
230
|
|
|
self.tailoring_path = str(preferred_tailoring) |
|
231
|
|
|
|