Skip to content

Commit 2f97bd1

Browse files
Deprecating RSA supports
1 parent 6a24297 commit 2f97bd1

File tree

6 files changed

+10
-57
lines changed

6 files changed

+10
-57
lines changed

.github/workflows/python-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
run:
1717
runs-on: ${{ matrix.os }}
1818
env:
19-
VERSION: 0.2.3
19+
VERSION: 0.2.4
2020
strategy:
2121
matrix:
2222
python-version: [3.7, 3.8, 3.9, "3.10"]

pysrc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from . import mixin_api
22
from . import mixin_bot_api
3-
__VERSION__ = '0.2.3'
3+
__VERSION__ = '0.2.4'
44

55
default_api = mixin_api.MixinApi()
66

pysrc/mixin_bot_api.py

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,9 @@
1717
import json
1818

1919
import jwt
20-
import Crypto
21-
from Crypto.PublicKey import RSA
22-
from Crypto.Cipher import PKCS1_OAEP
23-
from Crypto.Signature import PKCS1_v1_5
24-
from Crypto import Random
25-
from Crypto.Cipher import AES
2620
from urllib.parse import urlencode
2721

2822
from cryptography.hazmat.primitives.asymmetric import ed25519
29-
from cryptography.hazmat.primitives import serialization
3023

3124
from .message_types import ButtonMessage
3225
from . import mixin_api
@@ -46,14 +39,14 @@ def __init__(self, mixin_config):
4639
self.private_key_base64 = self.private_key
4740

4841
if self.private_key.find('RSA PRIVATE KEY') >= 0:
42+
raise Exception("RSA private key supports has been deprecated, use ed25519 instead!")
4943
self.algorithm='RS512'
5044
else:
5145
self.algorithm = 'EdDSA'
5246
self.private_key = self.decode_ed25519(self.private_key)
5347

5448
self.client = httpx.AsyncClient()
5549

56-
self.keyForAES = ""
5750
# mixin api base url
5851
self.api_base_url = 'https://api.mixin.one'
5952
#self.api_base_url = 'https://mixin-api.zeromesh.net'
@@ -89,17 +82,6 @@ def gen_get_jwt_token(self, uristring, bodystring, jti):
8982

9083
return encoded
9184

92-
def gen_get_listen_signed_token(self, uristring, bodystring, jti):
93-
jwtSig = self.gen_get_sig(uristring, bodystring)
94-
iat = datetime.datetime.utcnow()
95-
exp = datetime.datetime.utcnow() + datetime.timedelta(seconds=200)
96-
encoded = jwt.encode({'uid':self.client_id, 'sid':self.pay_session_id,'iat':iat,'exp': exp, 'jti':jti,'sig':jwtSig}, self.private_key, algorithm=self.algorithm)
97-
privKeyObj = RSA.importKey(self.private_key)
98-
signer = PKCS1_v1_5.new(privKeyObj)
99-
signature = signer.sign(encoded)
100-
return signature
101-
102-
10385
def gen_post_jwt_token(self, uristring, bodystring, jti):
10486
jwtSig = self.genPOSTSig(uristring, bodystring)
10587
iat = datetime.datetime.utcnow()
@@ -108,38 +90,8 @@ def gen_post_jwt_token(self, uristring, bodystring, jti):
10890
return encoded
10991

11092
def gen_encrypted_pin(self, iterString = None):
111-
if self.algorithm == 'EdDSA':
112-
return mixin_api.encrypt_ed25519_pin(self.pay_pin, self.pin_token, self.pay_session_id, self.private_key_base64, int(time.time()*1e9))
113-
114-
if self.keyForAES == "":
115-
privKeyObj = RSA.importKey(self.private_key)
116-
decoded_result = base64.b64decode(self.pin_token)
117-
cipher = PKCS1_OAEP.new(key=privKeyObj, hashAlgo=Crypto.Hash.SHA256, label=self.pay_session_id.encode("utf-8"))
118-
decrypted_msg = cipher.decrypt(decoded_result)
119-
self.keyForAES = decrypted_msg
120-
121-
tsstring = int(time.time()) # unix time
122-
tsstring = tsstring.to_bytes(8, 'little')
123-
124-
if iterString is None:
125-
iterator = int(time.time() * 1e9) # unix nano
126-
iterator = iterator.to_bytes(8, 'little')
127-
toEncryptContent = self.pay_pin.encode('utf8') + tsstring + iterator
128-
else:
129-
toEncryptContent = self.pay_pin.encode('utf8') + tsstring + iterString
130-
131-
toPadCount = AES.block_size - len(toEncryptContent) % AES.block_size
132-
toEncryptContent = toEncryptContent + int.to_bytes(toPadCount, 1, 'little') * toPadCount
133-
134-
iv = Random.new().read(AES.block_size)
135-
136-
cipher = AES.new(self.keyForAES, AES.MODE_CBC,iv)
137-
encrypted_result = cipher.encrypt(toEncryptContent)
138-
139-
msg = iv + encrypted_result
140-
encrypted_pin = base64.b64encode(msg)
141-
142-
return encrypted_pin.decode()
93+
assert self.algorithm == 'EdDSA', "mixin bot only support ed25519 crypto now!"
94+
return mixin_api.encrypt_ed25519_pin(self.pay_pin, self.pin_token, self.pay_session_id, self.private_key_base64, int(time.time()*1e9))
14395

14496
def __genUrl(self, path):
14597
"""

release.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
Release v0.2.3
1+
Release v0.2.4
2+
3+
1. Deprecating RSA supports

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
setup(
2626
name="mixin-python",
27-
version="0.2.3",
27+
version="0.2.4",
2828
description="Mixin Binding Project",
2929
author='learnforpractice',
3030
url="https://github.com/learnforpractice/mixin-python",
@@ -36,7 +36,6 @@
3636
scripts=[],
3737
install_requires=[
3838
"pycparser>=2.19",
39-
"pycryptodome>=3.7.2",
4039
"PyJWT>=2.1.0",
4140
"python-dateutil>=2.7.5",
4241
"requests>=2.21.0",

tag.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.2.3
1+
VERSION=v0.2.4
22
git push origin :refs/tags/$VERSION
33
git tag -d $VERSION
44
git tag $VERSION -F release.txt

0 commit comments

Comments
 (0)