|
@@ -45,11 +45,9 @@ def load_single_https_ruleset(filepath):
|
45
|
45
|
# get root node
|
46
|
46
|
root = tree.getroot()
|
47
|
47
|
|
48
|
|
- #print(etree.tostring(tree))
|
49
|
|
-
|
50
|
48
|
# check if root is a node with the name ruleset
|
51
|
49
|
# TODO improve parsing
|
52
|
|
- if root.tag != 'ruleset':
|
|
50
|
+ if root.tag != 'ruleset':
|
53
|
51
|
return ()
|
54
|
52
|
|
55
|
53
|
# check if rule is deactivated by default
|
|
@@ -68,36 +66,39 @@ def load_single_https_ruleset(filepath):
|
68
|
66
|
for ruleset in root:
|
69
|
67
|
# this child define a target
|
70
|
68
|
if ruleset.tag == 'target':
|
71
|
|
- # check if required tags available
|
|
69
|
+ # check if required tags available
|
72
|
70
|
if not ruleset.attrib.get('host'):
|
73
|
71
|
continue
|
74
|
72
|
|
75
|
73
|
# convert host-rule to valid regex
|
76
|
|
- host = ruleset.attrib.get('host').replace('.', '\.').replace('*', '.*')
|
|
74
|
+ host = ruleset.attrib.get('host')\
|
|
75
|
+ .replace('.', '\.').replace('*', '.*')
|
77
|
76
|
|
78
|
77
|
# append to host list
|
79
|
78
|
hosts.append(host)
|
80
|
79
|
|
81
|
80
|
# this child define a rule
|
82
|
81
|
elif ruleset.tag == 'rule':
|
83
|
|
- # check if required tags available
|
|
82
|
+ # check if required tags available
|
84
|
83
|
if not ruleset.attrib.get('from')\
|
85
|
84
|
or not ruleset.attrib.get('to'):
|
86
|
85
|
continue
|
87
|
86
|
|
88
|
|
- # TODO hack, which convert a javascript regex group into a valid python regex group
|
|
87
|
+ # TODO hack, which convert a javascript regex group
|
|
88
|
+ # into a valid python regex group
|
89
|
89
|
rule_from = ruleset.attrib.get('from').replace('$', '\\')
|
90
|
90
|
rule_to = ruleset.attrib.get('to').replace('$', '\\')
|
91
|
91
|
|
92
|
|
- # TODO, not working yet because of the hack above, currently doing that in webapp.py
|
93
|
|
- #rule_from_rgx = re.compile(rule_from, re.I)
|
|
92
|
+ # TODO, not working yet because of the hack above,
|
|
93
|
+ # currently doing that in webapp.py
|
|
94
|
+ # rule_from_rgx = re.compile(rule_from, re.I)
|
94
|
95
|
|
95
|
96
|
# append rule
|
96
|
97
|
rules.append((rule_from, rule_to))
|
97
|
98
|
|
98
|
99
|
# this child define an exclusion
|
99
|
100
|
elif ruleset.tag == 'exclusion':
|
100
|
|
- # check if required tags available
|
|
101
|
+ # check if required tags available
|
101
|
102
|
if not ruleset.attrib.get('pattern'):
|
102
|
103
|
continue
|
103
|
104
|
|
|
@@ -124,7 +125,9 @@ def load_https_rules(rules_path):
|
124
|
125
|
rules_path += '/'
|
125
|
126
|
|
126
|
127
|
# search all xml files which are stored in the https rule directory
|
127
|
|
- xml_files = [ join(rules_path,f) for f in listdir(rules_path) if isfile(join(rules_path,f)) and f[-4:] == '.xml' ]
|
|
128
|
+ xml_files = [join(rules_path, f)
|
|
129
|
+ for f in listdir(rules_path)
|
|
130
|
+ if isfile(join(rules_path, f)) and f[-4:] == '.xml']
|
128
|
131
|
|
129
|
132
|
# load xml-files
|
130
|
133
|
for ruleset_file in xml_files:
|
|
@@ -137,5 +140,5 @@ def load_https_rules(rules_path):
|
137
|
140
|
|
138
|
141
|
# append ruleset
|
139
|
142
|
https_rules.append(ruleset)
|
140
|
|
-
|
|
143
|
+
|
141
|
144
|
print(' * {n} https-rules loaded'.format(n=len(https_rules)))
|