2022-12-17 22:39:21 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import requests
|
|
|
|
from hashlib import sha256
|
|
|
|
import ecdsa
|
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
#private_key = '03486537091ceb021fb313e5cf3eb04d44ca2f19f72112a1'
|
|
|
|
private_key = '039e1c137aa296d7af0cd55b468018ad1020949c2731e5141d032b8371490f48'
|
2022-12-17 22:39:21 +02:00
|
|
|
|
|
|
|
# Generate SK from the private key
|
|
|
|
private_key_int = int(private_key, 16)
|
|
|
|
sk = ecdsa.SigningKey.from_secret_exponent(private_key_int, curve=ecdsa.SECP256k1)
|
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
## Get the server public key
|
|
|
|
url = 'http://localhost:5000/serverkey'
|
|
|
|
|
2022-12-17 22:39:21 +02:00
|
|
|
# sign the message
|
2022-12-29 17:59:25 +02:00
|
|
|
signature = sk.sign(url.encode('utf-8'))
|
2022-12-17 22:39:21 +02:00
|
|
|
signature_hex = signature.hex()
|
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
response = requests.get(url, headers={"auth":signature_hex})
|
2022-12-17 22:39:21 +02:00
|
|
|
print('>>> ', response.status_code)
|
|
|
|
print('>>> ', response.content)
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
## Get some kline data from the server
|
|
|
|
url = 'http://localhost:5000/?t=1672259440'
|
2022-12-17 22:39:21 +02:00
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
# sign the message
|
|
|
|
signature = sk.sign(url.encode('utf-8'))
|
|
|
|
signature_hex = signature.hex()
|
2022-12-17 22:39:21 +02:00
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
print('we signed: ', url)
|
|
|
|
print('We will send:')
|
|
|
|
print('to: ', url)
|
|
|
|
print('auth: ', signature_hex)
|
|
|
|
print('------------------------')
|
2022-12-17 22:39:21 +02:00
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
response = requests.get(url, headers={"auth":signature_hex})
|
|
|
|
print('>>> ', response.status_code)
|
|
|
|
print('>>> ', response.content)
|
2022-12-17 22:39:21 +02:00
|
|
|
|
2022-12-29 17:59:25 +02:00
|
|
|
##
|
|
|
|
##bytes_public_key = bytes.fromhex(ecdsa_public_key)
|
|
|
|
##
|
|
|
|
##bytes_signed_data = signature_hex.encode('utf-8')
|
|
|
|
##
|
|
|
|
##
|
|
|
|
##vk = ecdsa.VerifyingKey.from_string(bytes_public_key, curve=ecdsa.SECP256k1)
|
|
|
|
##
|
|
|
|
##if vk.verify(signature_hex, unsigned_data):
|
|
|
|
## response = "YES"
|
|
|
|
##else:
|
|
|
|
## response = "NO"
|
|
|
|
##
|
|
|
|
##
|
2022-12-17 22:39:21 +02:00
|
|
|
|
|
|
|
exit(0)
|