perun.proxy.utils 3.2.0__tar.gz → 3.3.0__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.
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/PKG-INFO +1 -1
- perun_proxy_utils-3.3.0/perun/proxy/utils/nagios/check_oidc_rp.py +532 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/PKG-INFO +1 -1
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/SOURCES.txt +1 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/setup.cfg +1 -1
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/LICENSE +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/README.md +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/__init__.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/metadata_expiration.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/__init__.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_custom_command.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_dockers.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_exabgp_propagation.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_ldap.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_ldap_syncrepl.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_mongodb.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_nginx.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_oidc_login.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_pgsql.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_php_syntax.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_privacyidea.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_rpc_status.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_saml.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_user_logins.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/webserver_availability.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/oracle2postgresql.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/print_docker_versions.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/run_probes.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/run_version_script.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/separate_oidc_logs.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/separate_ssp_logs.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/sync_usable_token_types.py +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/dependency_links.txt +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/entry_points.txt +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/requires.txt +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/top_level.txt +0 -0
- {perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/setup.py +0 -0
|
@@ -0,0 +1,532 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
make a full roundtrip test for SAML based SSO
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import argparse
|
|
8
|
+
import base64
|
|
9
|
+
import hmac
|
|
10
|
+
import http.cookiejar
|
|
11
|
+
import os
|
|
12
|
+
import re
|
|
13
|
+
import ssl
|
|
14
|
+
import struct
|
|
15
|
+
import sys
|
|
16
|
+
import tempfile
|
|
17
|
+
import time
|
|
18
|
+
import urllib.error
|
|
19
|
+
import urllib.parse
|
|
20
|
+
import urllib.request
|
|
21
|
+
from html.parser import HTMLParser
|
|
22
|
+
|
|
23
|
+
STATUS = {"OK": 0, "WARNING": 1, "CRITICAL": 2, "UNKNOWN": 3}
|
|
24
|
+
|
|
25
|
+
DEFAULT_HEADERS = {
|
|
26
|
+
"Accept": "text/html,application/xhtml+xml,"
|
|
27
|
+
+ "application/xml;q=0.9,image/webp,*/*;q=0.8",
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
CACHE_REGEX = ".*_(OK|WARNING|CRITICAL|UNKNOWN)_.*"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# https://github.com/susam/mintotp/blob/master/mintotp.py
|
|
34
|
+
def hotp(key, counter, digits=6, digest="sha1"):
|
|
35
|
+
key = base64.b32decode(key.upper() + "=" * ((8 - len(key)) % 8))
|
|
36
|
+
counter = struct.pack(">Q", counter)
|
|
37
|
+
mac = hmac.new(key, counter, digest).digest()
|
|
38
|
+
offset = mac[-1] & 0x0F
|
|
39
|
+
endoffset = offset + 4
|
|
40
|
+
binary = struct.unpack(">L", mac[offset:endoffset])[0] & 0x7FFFFFFF
|
|
41
|
+
return str(binary)[-digits:].zfill(digits)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def totp(key, time_step=30, digits=6, digest="sha1"):
|
|
45
|
+
return hotp(key, int(time.time() / time_step), digits, digest)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
class FormParser(HTMLParser):
|
|
49
|
+
form_action = None
|
|
50
|
+
form_data = {}
|
|
51
|
+
_form_in_progress = False
|
|
52
|
+
|
|
53
|
+
def __init__(self, *args, **kwargs):
|
|
54
|
+
self.form_action = None
|
|
55
|
+
self.form_data = {}
|
|
56
|
+
self._form_in_progress = False
|
|
57
|
+
super(FormParser, self).__init__(*args, **kwargs)
|
|
58
|
+
|
|
59
|
+
def handle_starttag(self, tag, attrs):
|
|
60
|
+
if tag.lower() == "form":
|
|
61
|
+
self._form_in_progress = True
|
|
62
|
+
for name, value in attrs:
|
|
63
|
+
if name.lower() == "action" and self.form_action is None:
|
|
64
|
+
self.form_action = value
|
|
65
|
+
elif tag.lower() == "input":
|
|
66
|
+
input_name = None
|
|
67
|
+
input_value = None
|
|
68
|
+
for name, value in attrs:
|
|
69
|
+
if name.lower() == "name":
|
|
70
|
+
input_name = value
|
|
71
|
+
elif name.lower() == "value":
|
|
72
|
+
input_value = value
|
|
73
|
+
if input_name and input_value:
|
|
74
|
+
self.form_data[input_name] = input_value
|
|
75
|
+
|
|
76
|
+
def handle_endtag(self, tag):
|
|
77
|
+
if tag.lower() == "form":
|
|
78
|
+
self._form_in_progress = False
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def parse_form(html):
|
|
82
|
+
parser = FormParser()
|
|
83
|
+
parser.feed(html)
|
|
84
|
+
return parser.form_action, parser.form_data
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def get_host_from_url(url):
|
|
88
|
+
return urllib.parse.urlparse(url).hostname
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def get_args():
|
|
92
|
+
"""
|
|
93
|
+
Supports the command-line arguments listed below.
|
|
94
|
+
"""
|
|
95
|
+
parser = argparse.ArgumentParser(description="SAML authentication check")
|
|
96
|
+
parser._optionals.title = "Options"
|
|
97
|
+
parser.add_argument(
|
|
98
|
+
"--username",
|
|
99
|
+
required=True,
|
|
100
|
+
help="username for IdP",
|
|
101
|
+
)
|
|
102
|
+
parser.add_argument(
|
|
103
|
+
"--password",
|
|
104
|
+
required=True,
|
|
105
|
+
help="password for IdP",
|
|
106
|
+
)
|
|
107
|
+
parser.add_argument(
|
|
108
|
+
"--url",
|
|
109
|
+
help="URL that starts authentication",
|
|
110
|
+
default="https://inet.muni.cz/sys/servertest",
|
|
111
|
+
)
|
|
112
|
+
parser.add_argument(
|
|
113
|
+
"--string",
|
|
114
|
+
help="string to expect after successful authentication",
|
|
115
|
+
default="OSCIS",
|
|
116
|
+
)
|
|
117
|
+
parser.add_argument(
|
|
118
|
+
"--logout-url",
|
|
119
|
+
help="URL to trigger logout",
|
|
120
|
+
default="https://inet.muni.cz/pub/appctl/logout",
|
|
121
|
+
)
|
|
122
|
+
parser.add_argument(
|
|
123
|
+
"--postlogout-string",
|
|
124
|
+
help="String to expect after successful logout",
|
|
125
|
+
default="successfully signed out",
|
|
126
|
+
)
|
|
127
|
+
parser.add_argument(
|
|
128
|
+
"--skip-logout-check",
|
|
129
|
+
action="store_true",
|
|
130
|
+
help="skip logout check",
|
|
131
|
+
)
|
|
132
|
+
parser.add_argument("--idp-host", help="hostname of IdP", default="id.muni.cz")
|
|
133
|
+
parser.add_argument(
|
|
134
|
+
"--hosts",
|
|
135
|
+
nargs="*",
|
|
136
|
+
default=[],
|
|
137
|
+
help="space separated list of hostname:ip or hostname:hostname pairs "
|
|
138
|
+
+ "for replacing in all URLs",
|
|
139
|
+
)
|
|
140
|
+
parser.add_argument(
|
|
141
|
+
"--warn-time",
|
|
142
|
+
type=int,
|
|
143
|
+
help="warning threshold in seconds",
|
|
144
|
+
default=5,
|
|
145
|
+
)
|
|
146
|
+
parser.add_argument(
|
|
147
|
+
"--critical-time",
|
|
148
|
+
type=int,
|
|
149
|
+
help="critical threshold in seconds",
|
|
150
|
+
default=15,
|
|
151
|
+
)
|
|
152
|
+
parser.add_argument(
|
|
153
|
+
"--insecure",
|
|
154
|
+
action="store_true",
|
|
155
|
+
help="ignore server name in SSL/TLS certificates",
|
|
156
|
+
)
|
|
157
|
+
parser.add_argument(
|
|
158
|
+
"--username-field",
|
|
159
|
+
help="name of the username field on the login page",
|
|
160
|
+
default="username",
|
|
161
|
+
)
|
|
162
|
+
parser.add_argument(
|
|
163
|
+
"--password-field",
|
|
164
|
+
help="name of the password field on the login page",
|
|
165
|
+
default="password",
|
|
166
|
+
)
|
|
167
|
+
parser.add_argument(
|
|
168
|
+
"--totp",
|
|
169
|
+
help="secret key (seed) for TOTP in Base32 encoding",
|
|
170
|
+
default="ZYTYYE5FOAGW5ML7LRWUL4WTZLNJAMZS",
|
|
171
|
+
)
|
|
172
|
+
parser.add_argument(
|
|
173
|
+
"--verbose",
|
|
174
|
+
"-v",
|
|
175
|
+
action="count",
|
|
176
|
+
default=0,
|
|
177
|
+
help="verbose mode (for debugging)",
|
|
178
|
+
)
|
|
179
|
+
parser.add_argument(
|
|
180
|
+
"--remember-me",
|
|
181
|
+
action="store_true",
|
|
182
|
+
help="check the Remember me option when logging in",
|
|
183
|
+
)
|
|
184
|
+
parser.add_argument(
|
|
185
|
+
"--security-text-check",
|
|
186
|
+
action="store_true",
|
|
187
|
+
help="perform security text check (implies --remember-me)",
|
|
188
|
+
)
|
|
189
|
+
parser.add_argument(
|
|
190
|
+
"--cache-timeout",
|
|
191
|
+
type=int,
|
|
192
|
+
help="specify the time after which the cache will be wiped",
|
|
193
|
+
default=0,
|
|
194
|
+
)
|
|
195
|
+
parser.add_argument(
|
|
196
|
+
"--cache-file",
|
|
197
|
+
default="check_saml_cache",
|
|
198
|
+
help="name of the file used for the cache",
|
|
199
|
+
)
|
|
200
|
+
parser.add_argument(
|
|
201
|
+
"--basic-oidc-check",
|
|
202
|
+
action="store_true",
|
|
203
|
+
help="check for presence of state and code parameters in the result",
|
|
204
|
+
)
|
|
205
|
+
|
|
206
|
+
args = parser.parse_args()
|
|
207
|
+
if args.security_text_check:
|
|
208
|
+
args.remember_me = True
|
|
209
|
+
|
|
210
|
+
return args
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def replace_host_in_url(hosts, url, headers):
|
|
214
|
+
host = get_host_from_url(url)
|
|
215
|
+
headers["Host"] = host
|
|
216
|
+
if host in hosts:
|
|
217
|
+
parsed = urllib.parse.urlparse(url)
|
|
218
|
+
url = parsed._replace(netloc=hosts[host]).geturl()
|
|
219
|
+
headers["Host"] = host
|
|
220
|
+
return url, headers
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class ResolvingHTTPRedirectHandler(urllib.request.HTTPRedirectHandler):
|
|
224
|
+
def __init__(self, hosts, verbose=0):
|
|
225
|
+
self.hosts = hosts
|
|
226
|
+
self.verbose = verbose
|
|
227
|
+
|
|
228
|
+
def redirect_request(self, req, fp, code, msg, headers, newurl):
|
|
229
|
+
"""Check whether the host should be replaced with an IP"""
|
|
230
|
+
referrer = req.headers["Referer"] if "Referer" in req.headers else None
|
|
231
|
+
newurl, newheaders = replace_host_in_url(self.hosts, newurl, DEFAULT_HEADERS)
|
|
232
|
+
req.headers = newheaders
|
|
233
|
+
if referrer:
|
|
234
|
+
req.headers["Referer"] = referrer
|
|
235
|
+
if self.verbose >= 1:
|
|
236
|
+
print("Redirecting to {}".format(newurl))
|
|
237
|
+
return super().redirect_request(req, fp, code, msg, headers, newurl)
|
|
238
|
+
|
|
239
|
+
def http_error_308(self, req, fp, code, msg, hdrs):
|
|
240
|
+
return self.http_error_301(req, fp, 301, msg, hdrs)
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
class SAMLChecker:
|
|
244
|
+
def curl(self, url, data=None, referrer=None):
|
|
245
|
+
url, headers = replace_host_in_url(self.hosts, url, DEFAULT_HEADERS)
|
|
246
|
+
if referrer:
|
|
247
|
+
headers["Referer"], _ = replace_host_in_url(
|
|
248
|
+
dict(map(reversed, self.hosts.items())),
|
|
249
|
+
urllib.parse.urlparse(referrer)
|
|
250
|
+
._replace(fragment="")
|
|
251
|
+
._replace(query="")
|
|
252
|
+
.geturl(),
|
|
253
|
+
{},
|
|
254
|
+
)
|
|
255
|
+
if self.args.verbose >= 1:
|
|
256
|
+
print("curl: {}".format(url))
|
|
257
|
+
if "Referer" in headers:
|
|
258
|
+
print("Referrer: {}".format(headers["Referer"]))
|
|
259
|
+
req = urllib.request.Request(
|
|
260
|
+
url=url,
|
|
261
|
+
data=urllib.parse.urlencode(data).encode("ascii") if data else None,
|
|
262
|
+
headers=headers,
|
|
263
|
+
)
|
|
264
|
+
if self.args.verbose >= 1:
|
|
265
|
+
print("")
|
|
266
|
+
response = None
|
|
267
|
+
try:
|
|
268
|
+
response = self.opener.open(req)
|
|
269
|
+
return response
|
|
270
|
+
except urllib.error.URLError as e:
|
|
271
|
+
if self.args.verbose >= 1:
|
|
272
|
+
print(e)
|
|
273
|
+
if self.args.verbose >= 2:
|
|
274
|
+
print(response)
|
|
275
|
+
self.finish(e.reason, "CRITICAL")
|
|
276
|
+
|
|
277
|
+
def js_form_redirect(self, html, url, force=False):
|
|
278
|
+
if (
|
|
279
|
+
force
|
|
280
|
+
or "document.getElementsByTagName('input')[0].click();" in html
|
|
281
|
+
or "document.forms[0].submit()" in html
|
|
282
|
+
or "javascript:DoSubmit();" in html
|
|
283
|
+
):
|
|
284
|
+
form_action, form_data = parse_form(html)
|
|
285
|
+
return self.send_form(url, form_action, form_data)
|
|
286
|
+
return None, None
|
|
287
|
+
|
|
288
|
+
def initial_request(self, url):
|
|
289
|
+
response = self.curl(url)
|
|
290
|
+
response_html = response.read().decode("utf-8")
|
|
291
|
+
response_url = response.url
|
|
292
|
+
|
|
293
|
+
try_response_html, try_response_url = self.js_form_redirect(
|
|
294
|
+
response_html, response_url
|
|
295
|
+
)
|
|
296
|
+
if try_response_html is None:
|
|
297
|
+
if self.args.verbose >= 1:
|
|
298
|
+
print("JS redirect not found on initial page")
|
|
299
|
+
else:
|
|
300
|
+
if self.args.verbose >= 1:
|
|
301
|
+
print("JS redirect found on initial page")
|
|
302
|
+
response_html = try_response_html
|
|
303
|
+
response_url = try_response_url
|
|
304
|
+
return response_html, response_url
|
|
305
|
+
|
|
306
|
+
def send_form(self, url, action, data):
|
|
307
|
+
target_url = urllib.parse.urljoin(url, action)
|
|
308
|
+
response = self.curl(target_url, data, url)
|
|
309
|
+
return response.read().decode("utf-8"), response.url
|
|
310
|
+
|
|
311
|
+
def send_credentials(self, login_form_url, login_form_action, login_form_data):
|
|
312
|
+
login_form_data[self.args.username_field] = self.args.username
|
|
313
|
+
login_form_data[self.args.password_field] = self.args.password
|
|
314
|
+
if self.args.remember_me:
|
|
315
|
+
login_form_data["remember_me"] = "Yes"
|
|
316
|
+
response_html, response_url = self.send_form(
|
|
317
|
+
login_form_url, login_form_action, login_form_data
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
if self.args.verbose >= 1:
|
|
321
|
+
print(response_url)
|
|
322
|
+
if self.args.verbose >= 3:
|
|
323
|
+
print(response_html)
|
|
324
|
+
|
|
325
|
+
return response_html, response_url
|
|
326
|
+
|
|
327
|
+
def js_form_redirect_all(self, html, url):
|
|
328
|
+
for _ in range(10):
|
|
329
|
+
try_html, try_url = self.js_form_redirect(html, url)
|
|
330
|
+
if try_html is not None and try_url is not None:
|
|
331
|
+
html = try_html
|
|
332
|
+
url = try_url
|
|
333
|
+
else:
|
|
334
|
+
return (html, url)
|
|
335
|
+
return (html, url)
|
|
336
|
+
|
|
337
|
+
def finish(
|
|
338
|
+
self,
|
|
339
|
+
message,
|
|
340
|
+
status="OK",
|
|
341
|
+
cache_time=time.time(),
|
|
342
|
+
from_cache=False,
|
|
343
|
+
auth_time=None,
|
|
344
|
+
):
|
|
345
|
+
if auth_time is not None and isinstance(auth_time, float):
|
|
346
|
+
message = "{}|authtime={:.2f};{};{};;".format(
|
|
347
|
+
message, auth_time, self.args.warn_time, self.args.critical_time
|
|
348
|
+
)
|
|
349
|
+
if auth_time is None and from_cache is False:
|
|
350
|
+
message = "{}|authtime=;{};{};;".format(
|
|
351
|
+
message, self.args.warn_time, self.args.critical_time
|
|
352
|
+
)
|
|
353
|
+
if self.args.cache_timeout > 0:
|
|
354
|
+
try:
|
|
355
|
+
file_path = tempfile.gettempdir() + "/" + self.args.cache_file
|
|
356
|
+
f = open(file_path, "w")
|
|
357
|
+
f.write("{}_{}_{}".format(cache_time, status, message))
|
|
358
|
+
f.close()
|
|
359
|
+
except (OSError, ValueError):
|
|
360
|
+
pass
|
|
361
|
+
if from_cache:
|
|
362
|
+
message = "Cached: " + message
|
|
363
|
+
print("{} - {}".format(status, message))
|
|
364
|
+
sys.exit(STATUS[status])
|
|
365
|
+
|
|
366
|
+
def check_cache(self):
|
|
367
|
+
try:
|
|
368
|
+
tempdir = tempfile.gettempdir()
|
|
369
|
+
file_path = tempdir + "/" + self.args.cache_file
|
|
370
|
+
if os.path.isfile(file_path):
|
|
371
|
+
with open(file_path, "r") as f:
|
|
372
|
+
res_b = f.read()
|
|
373
|
+
if not re.match(CACHE_REGEX, res_b):
|
|
374
|
+
raise ValueError("Bad cache content!")
|
|
375
|
+
res = res_b.split("_")
|
|
376
|
+
cached_time = float(res[0])
|
|
377
|
+
status = res[1]
|
|
378
|
+
message = res[2]
|
|
379
|
+
actual_time = time.time()
|
|
380
|
+
time_diff = actual_time - float(cached_time)
|
|
381
|
+
if time_diff < self.args.cache_timeout:
|
|
382
|
+
self.finish(
|
|
383
|
+
message=message,
|
|
384
|
+
status=status,
|
|
385
|
+
cache_time=cached_time,
|
|
386
|
+
from_cache=True,
|
|
387
|
+
)
|
|
388
|
+
except (OSError, ValueError):
|
|
389
|
+
pass
|
|
390
|
+
|
|
391
|
+
def main(self):
|
|
392
|
+
"""
|
|
393
|
+
CMD Line tool
|
|
394
|
+
"""
|
|
395
|
+
|
|
396
|
+
if self.args.cache_timeout > 0:
|
|
397
|
+
self.check_cache()
|
|
398
|
+
|
|
399
|
+
start_time = time.time()
|
|
400
|
+
|
|
401
|
+
# 1. start authentication
|
|
402
|
+
login_form_html, login_form_url = self.initial_request(self.args.url)
|
|
403
|
+
if self.args.verbose >= 3:
|
|
404
|
+
print(login_form_html)
|
|
405
|
+
|
|
406
|
+
# 2. log in and post response back
|
|
407
|
+
login_form_action, login_form_data = parse_form(login_form_html)
|
|
408
|
+
html, response_url = self.send_credentials(
|
|
409
|
+
login_form_url, login_form_action, login_form_data
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
if self.args.string not in html:
|
|
413
|
+
if self.args.verbose >= 2:
|
|
414
|
+
print(html)
|
|
415
|
+
self.finish(
|
|
416
|
+
"Missing the testing string {} in the response.".format(
|
|
417
|
+
self.args.string
|
|
418
|
+
),
|
|
419
|
+
"CRITICAL",
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
if self.args.verbose >= 3:
|
|
423
|
+
print(html)
|
|
424
|
+
|
|
425
|
+
elapsed_seconds = time.time() - start_time
|
|
426
|
+
status = "OK"
|
|
427
|
+
if elapsed_seconds >= self.args.critical_time:
|
|
428
|
+
status = "CRITICAL"
|
|
429
|
+
if elapsed_seconds >= self.args.warn_time:
|
|
430
|
+
status = "WARNING"
|
|
431
|
+
|
|
432
|
+
if self.args.remember_me:
|
|
433
|
+
# logout from SP and IdP but keep username cookie
|
|
434
|
+
self.cookiejar.clear_session_cookies()
|
|
435
|
+
self.cookiejar.clear(get_host_from_url(self.args.url))
|
|
436
|
+
self.cookiejar.clear(
|
|
437
|
+
(
|
|
438
|
+
self.hosts[self.args.idp_host]
|
|
439
|
+
if self.args.idp_host in self.hosts
|
|
440
|
+
else self.args.idp_host
|
|
441
|
+
),
|
|
442
|
+
"/",
|
|
443
|
+
"SimpleSAMLAuthToken",
|
|
444
|
+
)
|
|
445
|
+
self.cookiejar.clear(
|
|
446
|
+
(
|
|
447
|
+
self.hosts[self.args.idp_host]
|
|
448
|
+
if self.args.idp_host in self.hosts
|
|
449
|
+
else self.args.idp_host
|
|
450
|
+
),
|
|
451
|
+
"/",
|
|
452
|
+
"SimpleSAMLSessionID",
|
|
453
|
+
)
|
|
454
|
+
login_form_html, login_form_url = self.initial_request(self.args.url)
|
|
455
|
+
if self.args.verbose >= 3:
|
|
456
|
+
print(login_form_html)
|
|
457
|
+
if (
|
|
458
|
+
self.args.security_text_check
|
|
459
|
+
and 'class="security-text"' not in login_form_html
|
|
460
|
+
):
|
|
461
|
+
self.finish(
|
|
462
|
+
"Missing security text on the login page.",
|
|
463
|
+
"CRITICAL",
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
if self.args.username not in login_form_html:
|
|
467
|
+
self.finish(
|
|
468
|
+
"Missing remembered username on the login page.",
|
|
469
|
+
"WARNING",
|
|
470
|
+
)
|
|
471
|
+
|
|
472
|
+
if self.args.basic_oidc_check:
|
|
473
|
+
mandatory_parameters = ["code=", "state="]
|
|
474
|
+
for param in mandatory_parameters:
|
|
475
|
+
if param not in response_url:
|
|
476
|
+
if self.args.verbose >= 3:
|
|
477
|
+
print(response_url)
|
|
478
|
+
self.finish(
|
|
479
|
+
f"Missing mandatory parameter '{param}' in response url.",
|
|
480
|
+
"CRITICAL",
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
if not self.args.skip_logout_check:
|
|
484
|
+
# test logout
|
|
485
|
+
logout_html, logout_url = self.initial_request(self.args.logout_url)
|
|
486
|
+
if self.args.verbose >= 3:
|
|
487
|
+
print(logout_html)
|
|
488
|
+
if self.args.postlogout_string not in logout_html:
|
|
489
|
+
self.finish(
|
|
490
|
+
"Missing the testing string {} in the logout response.".format(
|
|
491
|
+
self.args.postlogout_string
|
|
492
|
+
),
|
|
493
|
+
"CRITICAL",
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
self.finish(
|
|
497
|
+
"Authentication took {:.2f} seconds".format(elapsed_seconds),
|
|
498
|
+
status,
|
|
499
|
+
auth_time=elapsed_seconds,
|
|
500
|
+
)
|
|
501
|
+
|
|
502
|
+
def __init__(self, args):
|
|
503
|
+
self.args = args
|
|
504
|
+
self.hosts = {
|
|
505
|
+
host.split(":", 1)[0]: host.split(":", 1)[1]
|
|
506
|
+
for host in (
|
|
507
|
+
self.args.hosts[0].strip("\"'").split(" ")
|
|
508
|
+
if self.args.hosts and " " in self.args.hosts[0]
|
|
509
|
+
else self.args.hosts
|
|
510
|
+
)
|
|
511
|
+
}
|
|
512
|
+
self.cookiejar = http.cookiejar.CookieJar()
|
|
513
|
+
if self.args.insecure:
|
|
514
|
+
self.opener = urllib.request.build_opener(
|
|
515
|
+
urllib.request.HTTPCookieProcessor(self.cookiejar),
|
|
516
|
+
ResolvingHTTPRedirectHandler(self.hosts, self.args.verbose),
|
|
517
|
+
urllib.request.HTTPSHandler(context=ssl.SSLContext()),
|
|
518
|
+
)
|
|
519
|
+
else:
|
|
520
|
+
self.opener = urllib.request.build_opener(
|
|
521
|
+
urllib.request.HTTPCookieProcessor(self.cookiejar),
|
|
522
|
+
ResolvingHTTPRedirectHandler(self.hosts, self.args.verbose),
|
|
523
|
+
)
|
|
524
|
+
|
|
525
|
+
|
|
526
|
+
def main():
|
|
527
|
+
checker = SAMLChecker(get_args())
|
|
528
|
+
checker.main()
|
|
529
|
+
|
|
530
|
+
|
|
531
|
+
if __name__ == "__main__":
|
|
532
|
+
main()
|
|
@@ -20,6 +20,7 @@ perun/proxy/utils/nagios/check_ldap_syncrepl.py
|
|
|
20
20
|
perun/proxy/utils/nagios/check_mongodb.py
|
|
21
21
|
perun/proxy/utils/nagios/check_nginx.py
|
|
22
22
|
perun/proxy/utils/nagios/check_oidc_login.py
|
|
23
|
+
perun/proxy/utils/nagios/check_oidc_rp.py
|
|
23
24
|
perun/proxy/utils/nagios/check_pgsql.py
|
|
24
25
|
perun/proxy/utils/nagios/check_php_syntax.py
|
|
25
26
|
perun/proxy/utils/nagios/check_privacyidea.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/metadata_expiration.py
RENAMED
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_custom_command.py
RENAMED
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_dockers.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_ldap_syncrepl.py
RENAMED
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_mongodb.py
RENAMED
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_oidc_login.py
RENAMED
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_php_syntax.py
RENAMED
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_privacyidea.py
RENAMED
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_rpc_status.py
RENAMED
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/nagios/check_user_logins.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/print_docker_versions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun/proxy/utils/sync_usable_token_types.py
RENAMED
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
{perun_proxy_utils-3.2.0 → perun_proxy_utils-3.3.0}/perun_proxy_utils.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|