aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <git@the-compiler.org>2018-08-24 16:51:06 +0200
committerFlorian Bruhin <git@the-compiler.org>2018-08-24 16:51:06 +0200
commit202abc67bd27e44af98211783225c428185905cf (patch)
tree1579ae84d08cfacd0a66b5987c02c4d43f579594
downloadhsrvpn-202abc67bd27e44af98211783225c428185905cf.tar.gz
hsrvpn-202abc67bd27e44af98211783225c428185905cf.zip
Initial commit
-rwxr-xr-xhsrvpn16
-rwxr-xr-xhsrvpn-gettokens37
2 files changed, 53 insertions, 0 deletions
diff --git a/hsrvpn b/hsrvpn
new file mode 100755
index 0000000..b592efd
--- /dev/null
+++ b/hsrvpn
@@ -0,0 +1,16 @@
+#!/bin/bash
+
+username=fbruhin
+host=vpn.hsr.ch/swivel-test
+
+password=$(keyring get openhsr-connect $username)
+secrets=( $(keyring get hsrvpn-secrets $username) )
+
+secret=${secrets[0]}
+unset -v 'secrets[0]'
+
+echo "${secrets[@]}" | keyring set hsrvpn-secrets $username
+
+echo "$secret"
+
+printf '%s\n' "$password" "$secret" | sudo openconnect "$host" -u "$username"
diff --git a/hsrvpn-gettokens b/hsrvpn-gettokens
new file mode 100755
index 0000000..550593c
--- /dev/null
+++ b/hsrvpn-gettokens
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+
+from xml.etree import ElementTree
+
+import requests
+import keyring
+
+user = 'fbruhin'
+secret = keyring.get_password('hsrvpn-gettokens', user)
+debug = False
+
+# Yes, they really throw XML in as form-encoded because it just happens to have a = in it...
+data = {"<?xml version": "'1.0' ?><SASRequest><Version>3.1</Version><Action>SecurityStrings</Action><Id>{}</Id></SASRequest>".format(secret)}
+user_agent = 'Mozilla/5.0 (Linux; Android 8.1.0; TA-1004 Build/OPR1.170623.026; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/68.0.3440.91 Mobile Safari/537.36'
+headers = {
+ 'User-Agent': user_agent,
+ 'Origin': 'file://', # yes, really
+ # let's invent our own header which is an user agent because we put bullshit in the user agent data
+ 'X-Requested-With': 'com.authcontrolmobile',
+}
+proxies = {'https': 'http://localhost:8080'} if debug else {}
+verify = not debug
+
+response = requests.post('https://sidv3611virt.hsr.ch/proxy/AgentXML', data=data, headers=headers, proxies=proxies, verify=verify)
+response.raise_for_status()
+
+print(response.text)
+
+tree = ElementTree.fromstring(response.text)
+assert tree.find('Version').text == '3.6'
+assert tree.find('Result').text == 'PASS'
+
+codes = tree.find('SecurityStrings').text.strip(';').split(';')
+
+output = ' '.join('{}{:02}'.format(idx, code) for code, idx in enumerate(codes))
+print(output)
+keyring.set_password('hsrvpn-secrets', user, output)