-
Notifications
You must be signed in to change notification settings - Fork 1
/
demoIssuerLambdaAuthSession.py
74 lines (65 loc) · 2.03 KB
/
demoIssuerLambdaAuthSession.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
from globals import *
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from urllib.parse import urlparse, parse_qs
import uuid, qrcode
pubKey = "GDC4LK7ZFPEHZ6JARW72XL6IIFS7YVAQZDSTQ43THYPJMZKUTGZ3JAKA"
secretKey = "SCVNEA3UKCQYHQ332QENKUINKHOTPOAADERSC6SKTUQCTD7NSH3PEXFX"
user = xlm.Keypair.from_secret(secretKey)
def main():
QRdata = getIssuerLoginQR()
token = getAuthTokenFromQRdata(QRdata)
signature = base64.b64encode(
user.sign(
token.encode()
)
).decode()
headers = {
"Authorization": json.dumps(
{
"token": token,
"sig": signature,
"PK": pubKey
}
)
}
print(f"Response header:")
pprint(headers)
response = requests.post(
"https://bt.issuer.link/session/validate",
headers = headers
).json()
return response
def getIssuerLoginQR():
exLoginData = requests.get("https://bt.issuer.link/session/new").json()
print(f"Got login data: {exLoginData}")
outputQRcode(exLoginData)
return exLoginData
def outputQRcode(data):
qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4)
qr.add_data(data)
qr.make()
img = qr.make_image(fill_color="black", back_color="white")
dir = f"{OUT_DIR}/issuerlink_login_qr_ex_{data[19:27]}.png"
img.save(dir)
print(f"Output login QR to: {dir}")
def getAuthTokenFromQRdata(data):
parsedURL = urlparse(data)
assert(parsedURL.scheme == "bt.issuer" and parsedURL.netloc == "link")
inputItems = parse_qs(parsedURL.query)
session = inputItems.get("s")[0]
linkIP = inputItems.get("ip")[0]
return json.dumps(
{
"session": session,
"linkIP": linkIP
}
)
def debugLocalCheckSignature(token, signature):
bytesToken = token.encode()
bytesSig = base64.b64decode(signature)
bytesPK = base64.b32decode(pubKey.encode())[1:-2]
Ed25519PublicKey.from_public_bytes(bytesPK).verify(bytesSig, bytesToken)
# py-xlm package equiv
verifier = xlm.Keypair.from_public_key(pubKey)
verifier.verify(bytesToken, bytesSig)
print(main())