-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_auth_cert.py
79 lines (55 loc) · 1.59 KB
/
test_auth_cert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import requests
import datetime
import hashlib
import os
import urllib3
urllib3.disable_warnings()
#from requests import *
USERNAME='[email protected]'
PASSWORD='test123'
API_URL = 'https://openhim.froidio.org:8008/authenticate'
CERT=os.getcwd() + '/my.cert'
REQ = API_URL + '/' + USERNAME
req = requests.get(REQ,
verify=CERT,
)
#print( req.status_code);
#print( req.text);
body = req.json()
salt=body['salt']
ts=body['ts']
#print("Salt:%s"%salt);
#print("ts:%s"%ts);
if not salt:
raise Exception(
"User %s has not been authenticated. Please use the .authenticate() function first"%USERNAME
)
sha = hashlib.sha512()
hashstring = salt + PASSWORD
#sha.update("{salt + PASSWORD}".encode('utf-8'))
sha.update(hashstring.encode('utf-8'))
password_hash = sha.hexdigest()
sha = hashlib.sha512()
now = str(datetime.datetime.utcnow())
sha_update = password_hash + salt + ts
sha.update( sha_update.encode('utf-8'))
#print("DEBUG:" f"{password_hash + salt + ts}".encode('utf-8'))
token = sha.hexdigest()
#print("Token %s"%token)
#
# curl -k -H "auth-username: $username" -H "auth-ts: $ts" -H "auth-salt: $salt" -H "auth-token: $token" $@;
#
headers = {"auth-username": USERNAME,
"auth-ts": ts,
"auth-salt": salt,
"auth-token": token}
channels = requests.get('https://openhim.froidio.org:8008/channels',
auth=(USERNAME, PASSWORD),
#auth=('[email protected]', 'test123'),
headers=headers,
#verify=False,
verify=CERT
)
#print(channels.status_code)
#print(channels.text)
print(channels.json())