1#/user/bin/env python 2"this is a test module for getting unlock challenge" 3import sys 4import os 5from hashlib import sha256 6 7def challenge_verify(): 8 if (len(sys.argv) != 3) : 9 print "Usage: rkpublickey.py [challenge_file] [product_id_file]" 10 return 11 if ((sys.argv[1] == "-h") or (sys.argv[1] == "--h")): 12 print "Usage: rkpublickey.py [challenge_file] [product_id_file]" 13 return 14 try: 15 challenge_file = open(sys.argv[1], 'rb') 16 product_id_file = open(sys.argv[2], 'rb') 17 challenge_random_file = open('unlock_challenge.bin', 'wb') 18 challenge_data = challenge_file.read(52) 19 product_id_data = product_id_file.read(16) 20 product_id_hash = sha256(product_id_data).digest() 21 print("The challege version is %d" %ord(challenge_data[0])) 22 if (product_id_hash != challenge_data[4:36]) : 23 print("Product id verify error!") 24 return 25 challenge_random_file.write(challenge_data[36:52]) 26 print("Success!") 27 28 finally: 29 if challenge_file: 30 challenge_file.close() 31 if product_id_file: 32 product_id_file.close() 33 if challenge_random_file: 34 challenge_random_file.close() 35 36if __name__ == '__main__': 37 challenge_verify() 38