hc
2025-02-14 bbb9540dc49f70f6b703d1c8d1b85fa5f602d86e
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
#/user/bin/env python
"this is a test module for getting unlock challenge"
import sys
import  os
from hashlib import sha256
 
def challenge_verify():
   if (len(sys.argv) != 3) :
       print "Usage: rkpublickey.py [challenge_file] [product_id_file]"
       return
   if ((sys.argv[1] == "-h") or (sys.argv[1] == "--h")):
       print "Usage: rkpublickey.py [challenge_file] [product_id_file]"
       return
   try:
       challenge_file = open(sys.argv[1], 'rb')
       product_id_file = open(sys.argv[2], 'rb')
       challenge_random_file = open('unlock_challenge.bin', 'wb')
       challenge_data = challenge_file.read(52)
       product_id_data = product_id_file.read(16)
       product_id_hash = sha256(product_id_data).digest()
       print("The challege version is %d" %ord(challenge_data[0]))
       if (product_id_hash != challenge_data[4:36]) :
           print("Product id verify error!")
           return
       challenge_random_file.write(challenge_data[36:52])
       print("Success!")
 
   finally:
       if challenge_file:
           challenge_file.close()
       if product_id_file:
           product_id_file.close()
       if challenge_random_file:
           challenge_random_file.close()
 
if __name__ == '__main__':
   challenge_verify()