1
|
2 |
|
from __future__ import absolute_import |
|
|
|
|
2
|
2 |
|
from __future__ import print_function |
3
|
|
|
|
4
|
2 |
|
import re |
5
|
|
|
|
6
|
2 |
|
from .constants import XCCDF11_NS |
7
|
|
|
|
8
|
|
|
|
9
|
2 |
|
def get_content_ref_if_exists_and_not_remote(check): |
|
|
|
|
10
|
|
|
""" |
11
|
|
|
Given an OVAL check element, examine the ``xccdf_ns:check-content-ref`` |
12
|
|
|
|
13
|
|
|
If it exists and it isn't remote, pass it as the return value. |
14
|
|
|
Otherwise, return None. |
15
|
|
|
|
16
|
|
|
..see-also:: is_content_href_remote |
17
|
|
|
""" |
18
|
|
|
checkcontentref = check.find("./{%s}check-content-ref" % XCCDF11_NS) |
19
|
|
|
if checkcontentref is None: |
20
|
|
|
return None |
21
|
|
|
if is_content_href_remote(checkcontentref): |
22
|
|
|
return None |
23
|
|
|
return checkcontentref |
24
|
|
|
|
25
|
|
|
|
26
|
2 |
|
def is_content_href_remote(check_content_ref): |
27
|
|
|
""" |
28
|
|
|
Given an OVAL check-content-ref element, examine the 'href' attribute. |
29
|
|
|
|
30
|
|
|
If it starts with 'http://' or 'https://', return True, otherwise |
31
|
|
|
return False. |
32
|
|
|
|
33
|
|
|
Raises RuntimeError if the ``href`` element doesn't exist. |
34
|
|
|
""" |
35
|
|
|
hrefattr = check_content_ref.get("href") |
36
|
|
|
if hrefattr is None: |
37
|
|
|
# @href attribute of <check-content-ref> is required by XCCDF standard |
38
|
|
|
msg = "Invalid OVAL <check-content-ref> detected - missing the " \ |
39
|
|
|
"'href' attribute!" |
40
|
|
|
raise RuntimeError(msg) |
41
|
|
|
|
42
|
|
|
return hrefattr.startswith("http://") or hrefattr.startswith("https://") |
43
|
|
|
|
44
|
|
|
|
45
|
2 |
|
def is_cce_valid(cceid): |
46
|
|
|
""" |
47
|
|
|
IF CCE ID IS IN VALID FORM (either 'CCE-XXXX-X' or 'CCE-XXXXX-X' |
48
|
|
|
where each X is a digit, and the final X is a check-digit) |
49
|
|
|
based on Requirement A17: |
50
|
|
|
|
51
|
|
|
http://people.redhat.com/swells/nist-scap-validation/scap-val-requirements-1.2.html |
52
|
|
|
""" |
53
|
2 |
|
match = re.match(r'^CCE-\d{4,5}-\d$', cceid) |
54
|
|
|
return match is not None |
55
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.