Skip to content

Commit e38a822

Browse files
committed
hacks
1 parent 1d3af79 commit e38a822

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

gp-okta.py

+19-3
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
THE SOFTWARE.
3131
"""
3232
from __future__ import print_function
33-
import argparse, base64, getpass, io, os, re, shlex, signal, subprocess, sys, tempfile, time, traceback
33+
import argparse, base64, getpass, io, os, re, shlex, signal, subprocess, sys, ssl, tempfile, time, traceback
3434
import requests
35+
import requests.adapters
3536
from lxml import etree
3637

3738
if sys.version_info >= (3,):
@@ -153,8 +154,11 @@ def err(s):
153154
print('[ERROR] {0}'.format(s), file=sys.stderr)
154155
sys.exit(1)
155156

156-
def _remx(c, v): return re.search(r'\s*' + v + r'\s*"?[=:]\s*(?:"((?:[^"\\]|\\.)*)"|\'((?:[^\'\\]|\\.)*)\')', c)
157-
_refx = lambda mx: to_b(mx.group(1)).decode('unicode_escape').strip()
157+
def _remx(c, v):
158+
return re.search(r'\s*' + v + r'\s*"?[=:]\s*(?:"((?:[^"\\]|\\.)*)"|\'((?:[^\'\\]|\\.)*)\')', c)
159+
160+
def _refx(mx):
161+
return to_b(mx.group(1) or mx.group(2)).decode('unicode_escape').strip()
158162

159163
def parse_xml(xml):
160164
# type: (str) -> etree._Element
@@ -195,6 +199,14 @@ def parse_form(html, current_url=None):
195199
data[k] = v
196200
return url, data
197201

202+
class InsecureHTTPAdapter(requests.adapters.HTTPAdapter):
203+
def __init__(self, *, ssl_context, **kwargs):
204+
self._ssl_context = ssl_context
205+
super().__init__(**kwargs)
206+
207+
def init_poolmanager(self, connections, maxsize, **kwargs):
208+
super().init_poolmanager(connections, maxsize, **kwargs, ssl_context=self._ssl_context)
209+
198210
class Conf(object):
199211
def __init__(self):
200212
# type: () -> None
@@ -327,6 +339,9 @@ def from_data(cls, content):
327339
setattr(conf, k, conf._store[k].strip())
328340
conf.debug = conf._store.get('debug', '').lower() in ['1', 'true']
329341
s = requests.Session()
342+
ctx = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
343+
ctx.options |= 0x4
344+
s.mount('https://', InsecureHTTPAdapter(ssl_context=ctx))
330345
s.headers['User-Agent'] = 'PAN GlobalProtect'
331346
conf._session = s
332347
return conf
@@ -1103,6 +1118,7 @@ def run_openconnect(conf, do_portal_auth, urls, saml_username, cookies):
11031118
if conf.get_bool('execute'):
11041119
ecmd = [os.path.expandvars(os.path.expanduser(x)) for x in shlex.split(cmd)]
11051120
pp = subprocess.Popen(shlex.split(pcmd), stdout=subprocess.PIPE)
1121+
print(f"Command: {ecmd}")
11061122
cp = subprocess.Popen(ecmd, stdin=pp.stdout, stdout=sys.stdout)
11071123
if pp.stdout is not None:
11081124
pp.stdout.close()

0 commit comments

Comments
 (0)