-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathupdate_optee_pubkey.py
executable file
·131 lines (122 loc) · 5.25 KB
/
update_optee_pubkey.py
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/python
deafult_ta_pub_key_modulus=[
0xa6, 0x5a, 0x18, 0xad, 0xc0, 0xb3, 0xce, 0xe3,
0x0c, 0x90, 0x2b, 0x7d, 0x40, 0x9b, 0xac, 0xbb,
0x5a, 0x49, 0x88, 0x42, 0x0a, 0xb1, 0xe0, 0x92,
0xc0, 0x86, 0x91, 0xe6, 0x9e, 0xef, 0xa0, 0xe1,
0xf1, 0x2f, 0x90, 0xf6, 0x66, 0xdd, 0xea, 0x15,
0x5a, 0xc0, 0x28, 0xb4, 0x9d, 0xdf, 0x52, 0x0c,
0x6e, 0xa5, 0xc6, 0x19, 0x43, 0xac, 0x69, 0xa8,
0xf2, 0x5f, 0xfe, 0x60, 0x00, 0xa5, 0xd2, 0x3a,
0xcc, 0x12, 0x01, 0xf3, 0x5b, 0xba, 0x0c, 0x51,
0x1c, 0x2c, 0xf4, 0xb0, 0x77, 0xb9, 0xd6, 0x72,
0x35, 0x1c, 0x0f, 0x73, 0xcd, 0x2f, 0x16, 0xf9,
0xba, 0x89, 0x84, 0xa0, 0x9b, 0xbf, 0x8b, 0x5b,
0x7f, 0xe8, 0x8b, 0x8b, 0x9f, 0xc8, 0x71, 0xea,
0x1c, 0x6c, 0x1f, 0x00, 0xa0, 0xee, 0xca, 0x3e,
0xbf, 0x18, 0x8e, 0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, 0x19, 0x91,
0x2e, 0x20, 0xb1, 0x04, 0x8c, 0x42, 0x86, 0xf9,
0x3f, 0x21, 0xaf, 0x8c, 0x33, 0x79, 0x0d, 0xe9,
0x3b, 0xbe, 0xdc, 0xb8, 0x1b, 0xf3, 0x05, 0x6e,
0xff, 0x94, 0x93, 0x76, 0x85, 0x9f, 0x6b, 0x0d,
]
def get_args():
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--in_file', required=True, \
help='Name of in file')
parser.add_argument('--out_file', required=True, \
help='Name of out file')
parser.add_argument('--key', required=True, help='Name of key file')
return parser.parse_args()
def main():
from Crypto.PublicKey import RSA
from Crypto.Util.number import long_to_bytes
args = get_args()
f = open(args.in_file,'rb')
raw = f.read()
f.close()
f = open(args.key, 'r')
key = RSA.importKey(f.read())
f.close
byteDef=bytearray(deafult_ta_pub_key_modulus)
newPubKey=bytearray(long_to_bytes(key.publickey().n))
firstMatch = raw.find(byteDef)
lastMatch = raw.rfind(byteDef)
if firstMatch != -1:
if firstMatch != lastMatch:
print("more than one match found")
exit(2)
else:
raw = raw.replace(byteDef,newPubKey)
f = open(args.out_file,'wb')
f.write(raw)
f.close()
exit(0)
else:
byteDef_v2=bytearray(deafult_ta_pub_key_modulus_v2)
newPubKey_v2=bytearray(long_to_bytes(key.publickey().n))
firstMatch_v2 = raw.find(byteDef_v2)
lastMatch_v2 = raw.rfind(byteDef_v2)
if firstMatch_v2 != -1:
if firstMatch_v2 != lastMatch_v2:
print("more than one match found")
exit(2)
else:
raw = raw.replace(byteDef_v2,newPubKey_v2)
f = open(args.out_file,'wb')
f.write(raw)
f.close()
exit(0)
else:
print("default pubkey not found")
exit(1)
if __name__ == "__main__":
main()