Skip to content

Fix genEncrypedPin #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 9 additions & 43 deletions mixin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,57 +100,23 @@ def genEncrypedPin(self, iterString = None):

self.keyForAES = decrypted_msg

ts = int(time.time())
tszero = ts % 0x100
tsone = (ts % 0x10000) >> 8
tstwo = (ts % 0x1000000) >> 16
tsthree = (ts % 0x100000000) >> 24
tsstring = int(time.time()) # unix time
tsstring = int.to_bytes(tsstring, 8, 'little')


tszero = chr(tszero).encode('latin1').decode('latin1')
tsone = chr(tsone)
tstwo = chr(tstwo)
tsthree = chr(tsthree)

tsstring = tszero + tsone + tstwo + tsthree + '\0\0\0\0'
if iterString is None:
ts = int(time.time() * 100000)
tszero = ts % 0x100
tsone = (ts % 0x10000) >> 8
tstwo = (ts % 0x1000000) >> 16
tsthree = (ts % 0x100000000) >> 24
tsfour= (ts % 0x10000000000) >> 32
tsfive= (ts % 0x10000000000) >> 40
tssix = (ts % 0x1000000000000) >> 48
tsseven= (ts % 0x1000000000000) >> 56


tszero = chr(tszero).encode('latin1').decode('latin1')
tsone = chr(tsone)
tstwo = chr(tstwo)
tsthree = chr(tsthree)
tsfour = chr(tsfour)
tsfive= chr(tsfive)
tssix = chr(tssix)
tsseven = chr(tsseven)
iterStringByTS = tszero + tsone + tstwo + tsthree + tsfour + tsfive + tssix + tsseven

toEncryptContent = self.pay_pin + tsstring + iterStringByTS
iterator = int(time.time() * 1e9) # unix nano
iterator = int.to_bytes(iterator, 8, 'little')
toEncryptContent = self.pay_pin.encode('utf8') + tsstring + iterator
else:
toEncryptContent = self.pay_pin + tsstring + iterString
toEncryptContent = self.pay_pin.encode('utf8') + tsstring + iterString

lenOfToEncryptContent = len(toEncryptContent)
toPadCount = 16 - lenOfToEncryptContent % 16
if toPadCount > 0:
paddedContent = toEncryptContent + chr(toPadCount) * toPadCount
else:
paddedContent = toEncryptContent
toPadCount = AES.block_size - len(toEncryptContent) % AES.block_size
toEncryptContent = toEncryptContent + int.to_bytes(toPadCount, 1, 'little') * toPadCount

iv = Random.new().read(AES.block_size)


cipher = AES.new(self.keyForAES, AES.MODE_CBC,iv)
encrypted_result = cipher.encrypt(paddedContent.encode('latin1'))
encrypted_result = cipher.encrypt(toEncryptContent)

msg = iv + encrypted_result
encrypted_pin = base64.b64encode(msg)
Expand Down
2 changes: 2 additions & 0 deletions test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

mixin_api = MIXIN_API(mixin_config)

mixin_api.verifyPin()




Expand Down