The web application located here validates API queries using an ECDSA signature before executing the commands in the query string. To validate the token, the web server parses the full query as:
query = token=token_string&rest_of_query_string
and then checks whether token_string is a valid ECDSA signature over the SHA256 hash of rest_of_query_string using the NIST p256 public key.
Unfortunately for this server, it didn't use a very good random number generator when generating the ECDSA signatures, and accidentally repeated the signature nonce k. Here is another valid token/query combo. Your task is to recover the server's secret signing key and forge a valid ECDSA signature on the query string user=admin&get_file=hw7.pdf that will allow you to download the rest of your homework.
Repeated DSA and ECDSA nonces have been found many times in the wild, including for Bitcoin (2013 and 2016) and other cryptocurrencies as well as in protocols like SSH.
You may discuss this assignment in small groups with classmates, but please code and write up your solutions yourself. Please credit any collaborators you discussed with and any references you used.
The autograder...
#!/usr/bin/env python3 import ecdsa import hashlib import binascii pubkey = b'a89e372866cd3f76b74edfa2b2e11549df8da056f6784d84905b5ac3fee063ee5b53c649c969668c7732c35e85ed29dac850b73fc6136e1d133a182a2c43fe6a' signature = b'ecf1c3dc7453222791b80c1656fa196b8339062aa1c22fdbf105513a5a62d95475423b581fca4092f49b596fa692abbb8b16e76ce3520d8f74f767cb8d6b52ef' query_string = b'user=admin&get_file=kitten.jpg' vk = ecdsa.VerifyingKey.from_string(binascii.unhexlify(pubkey),curve=ecdsa.NIST256p) vk.verify(binascii.unhexlify(signature),query_string,hashfunc=hashlib.sha256)