Created
September 5, 2020 22:09
-
-
Save thotypous/c710127c5822643d487f9e0e55d6e4eb to your computer and use it in GitHub Desktop.
Check if combined public key was correcly computed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import requests | |
import sys | |
import os | |
import re | |
election_uuid = sys.argv[1] | |
base_url = 'https://votacao.ufscar.br' | |
login_url = '{}/auth/ldap/login'.format(base_url) | |
election_url = '{}/helios/elections/{}'.format(base_url, election_uuid) | |
s = requests.session() | |
r = s.get(login_url) | |
r.raise_for_status() | |
m = re.search(r'<input type="hidden" name="csrf_token" value="(.*?)" />', r.text) | |
csrf_token = m.group(1) | |
r = s.post(login_url, {'csrf_token': csrf_token, | |
'username': os.getenv('HELIOS_USERNAME'), | |
'password': os.getenv('HELIOS_PASSWORD')}) | |
r.raise_for_status() | |
r = s.get(election_url) | |
r.raise_for_status() | |
election = r.json() | |
r = s.get(election_url + '/trustees') | |
r.raise_for_status() | |
trustees = r.json() | |
pk = trustees[0]['public_key'] | |
for trustee in trustees[1:]: | |
pkt = trustee['public_key'] | |
assert pkt['p'] == pk['p'] | |
assert pkt['q'] == pk['q'] | |
assert pkt['g'] == pk['g'] | |
pk['y'] = str((int(pk['y']) * int(pkt['y'])) % int(pk['p'])) | |
assert pk == election['public_key'] | |
print(pk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment