7 from kmsBase
import kmsBase
8 from kmsRequestV5
import kmsRequestV5
9 from structure
import Structure
11 class kmsRequestV6(kmsRequestV5
):
12 class DecryptedResponse(Structure
):
13 class Message(Structure
):
16 ('response', ':', kmsBase
.kmsResponseStruct
),
25 ('message', ':', Message
),
29 key
= bytearray([ 0xA9, 0x4A, 0x41, 0x95, 0xE2, 0x01, 0x43, 0x2D, 0x9B, 0xCB, 0x46, 0x04, 0x05, 0xD8, 0x4A, 0x21 ])
35 def encryptResponse(self
, request
, decrypted
, response
):
36 randomSalt
= self
.getRandomSalt()
37 sha256
= hashlib
.sha256()
38 sha256
.update(str(randomSalt
))
39 result
= sha256
.digest()
41 SaltC
= bytearray(request
['message']['salt'])
42 DSaltC
= bytearray(decrypted
['salt'])
44 randomStuff
= bytearray(16)
46 randomStuff
[i
] = (SaltC
[i
] ^ DSaltC
[i
] ^ randomSalt
[i
]) & 0xff
49 XorSalts
= bytearray(16)
50 for i
in range (0, 16):
51 XorSalts
[i
] = (SaltC
[i
] ^ DSaltC
[i
]) & 0xff
53 message
= self
.DecryptedResponse
.Message()
54 message
['response'] = response
55 message
['keys'] = str(randomStuff
)
56 message
['hash'] = result
57 message
['xorSalts'] = str(XorSalts
)
58 message
['hwid'] = self
.config
['hwid']
61 SaltS
= self
.getRandomSalt()
63 moo
= aes
.AESModeOfOperation()
65 d
= moo
.decrypt(SaltS
, 16, moo
.modeOfOperation
["CBC"], self
.key
, moo
.aes
.keySize
["SIZE_128"], SaltS
)
71 HMacMsg
= bytearray(16)
72 for i
in range (0, 16):
73 HMacMsg
[i
] = (SaltS
[i
] ^ DSaltS
[i
]) & 0xff
74 HMacMsg
.extend(str(message
))
77 requestTime
= decrypted
['request']['requestTime']
78 HMacKey
= self
.getMACKey(requestTime
)
79 HMac
= hmac
.new(HMacKey
, str(HMacMsg
), hashlib
.sha256
)
80 digest
= HMac
.digest()
82 responsedata
= self
.DecryptedResponse()
83 responsedata
['message'] = message
84 responsedata
['hmac'] = digest
[16:]
86 padded
= aes
.append_PKCS7_padding(str(responsedata
))
87 mode
, orig_len
, crypted
= moo
.encrypt(str(padded
), moo
.modeOfOperation
["CBC"], self
.key
, moo
.aes
.keySize
["SIZE_128"], SaltS
)
89 return str(SaltS
), str(bytearray(crypted
))
91 def getMACKey(self
, t
):
92 c1
= 0x00000022816889BD
93 c2
= 0x000000208CBAB5ED
94 c3
= 0x3156CD5AC628477A
96 i1
= (t
/ c1
) & 0xFFFFFFFFFFFFFFFF
97 i2
= (i1
* c2
) & 0xFFFFFFFFFFFFFFFF
98 seed
= (i2
+ c3
) & 0xFFFFFFFFFFFFFFFF
100 sha256
= hashlib
.sha256()
101 sha256
.update(struct
.pack("<Q", seed
))
102 digest
= sha256
.digest()