You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1000 B

import ssl
from hashlib import sha256
class ProofError(Exception):
def get_https_fingerprint(url):
pem = ssl.get_server_certificate((url, 443), ca_certs=None)
# not the correct way to get fingerprint
return sha256(pem).hexdigest()
def construct_proof(url, fingerprint, nodeid):
"""The variable `nodeid` serves as a nonce and should perhaps be
substituted for a random integer?
The idea here is to calculate a unique hash that requires actually
checking the server certificate.
return sha256(fingerprint + url + nodeid).hexdigest()
def proof_of_check(url, nodeid):
fingerprint = get_https_fingerprint(url)
proof = construct_proof(url, fingerprint, nodeid)
return fingerprint, proof
def verify_proof(url, fingerprint, nodeid, claimed_proof):
if get_https_fingerprint(url) != fingerprint:
return False
elif construct_proof(url, fingerprint, nodeid) != claimed_proof:
return False
return True