rubkey_login 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 taha ansarianpour
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: rubkey_login
3
+ Version: 1.0.0
4
+ Summary: The rubkey_login library for getting your account information in Rubika.
5
+ Home-page: https://github.com/codetansarian
6
+ Author: taha ansarianpour
7
+ Author-email: codetansarian@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.7
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Requires-Python: >=3.7
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: requests>=2.25.0
22
+ Requires-Dist: pycryptodome>=3.10.0
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: license
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ from rubkey_login import RubkeyLogin
36
+
37
+ client = RubkeyLogin()
38
+ client.login()
39
+
40
+ info = client.get_account_info()
41
+
42
+ print("=" * 50)
43
+ print("ACCOUNT INFORMATION")
44
+ print("=" * 50)
45
+ print(f"Phone: {info['phone']}")
46
+ print(f"User GUID: {info['user_guid']}")
47
+ print(f"First Name: {info['first_name']}")
48
+ print(f"Last Name: {info['last_name']}")
49
+ print(f"Username: {info['username']}")
50
+ print(f"Auth: {info['auth']}")
51
+ print(f"Private Key: {info['private_key']}")
52
+ print("=" * 50)
53
+
54
+ print(client.get_account_name())
55
+ print(client.get_auth())
56
+ print(client.get_guid())
@@ -0,0 +1,22 @@
1
+ from rubkey_login import RubkeyLogin
2
+
3
+ client = RubkeyLogin()
4
+ client.login()
5
+
6
+ info = client.get_account_info()
7
+
8
+ print("=" * 50)
9
+ print("ACCOUNT INFORMATION")
10
+ print("=" * 50)
11
+ print(f"Phone: {info['phone']}")
12
+ print(f"User GUID: {info['user_guid']}")
13
+ print(f"First Name: {info['first_name']}")
14
+ print(f"Last Name: {info['last_name']}")
15
+ print(f"Username: {info['username']}")
16
+ print(f"Auth: {info['auth']}")
17
+ print(f"Private Key: {info['private_key']}")
18
+ print("=" * 50)
19
+
20
+ print(client.get_account_name())
21
+ print(client.get_auth())
22
+ print(client.get_guid())
@@ -0,0 +1,7 @@
1
+ from .client import RubkeyLogin
2
+ from .exceptions import *
3
+ from .plugins import Plugin, PluginManager
4
+
5
+ __version__ = "1.0.0"
6
+ __author__ = "taha ansarianpour"
7
+ __license__ = "MIT"
@@ -0,0 +1,172 @@
1
+ import requests
2
+ import secrets
3
+ import time
4
+ import re
5
+ import os
6
+ import json
7
+ from .crypto import Crypto
8
+ from .exceptions import *
9
+ from .plugins import PluginManager
10
+
11
+
12
+ class RubkeyLogin:
13
+ ANDROID_PLATFORM = {
14
+ "app_name": "Main",
15
+ "app_version": "3.5.7",
16
+ "platform": "Android",
17
+ "package": "app.rbmain.a",
18
+ "lang_code": "fa"
19
+ }
20
+
21
+ PWA_PLATFORM = {
22
+ "app_name": "Main",
23
+ "app_version": "2.4.6",
24
+ "platform": "PWA",
25
+ "package": "m.rubika.ir",
26
+ "lang_code": "fa"
27
+ }
28
+
29
+ def __init__(self):
30
+ self.auth = None
31
+ self.private_key = None
32
+ self.user_guid = None
33
+ self.phone = None
34
+ self.first_name = None
35
+ self.last_name = None
36
+ self.username = None
37
+ self.plugin_manager = PluginManager()
38
+
39
+ def _request_tmp(self, tmp_key, method, input_data, platform):
40
+ enc_key = Crypto.secret(tmp_key)
41
+ inner = {"method": method, "input": input_data, "client": platform}
42
+ data_enc = Crypto.encrypt(json.dumps(inner), enc_key)
43
+ data = {"api_version": "6", "tmp_session": tmp_key, "data_enc": data_enc}
44
+
45
+ for dc in [3, 2, 1, 4, 5]:
46
+ try:
47
+ resp = requests.post(f"https://messengerg2c{dc}.iranlms.ir/", json=data, timeout=10)
48
+ if resp.status_code == 200:
49
+ result = resp.json()
50
+ if "data_enc" in result:
51
+ return Crypto.decrypt(result["data_enc"], enc_key)
52
+ except:
53
+ continue
54
+ return None
55
+
56
+ def _request_main(self, auth, key, private_key, method, input_data, platform):
57
+ inner = {"method": method, "input": input_data, "client": platform}
58
+ data_enc = Crypto.encrypt(json.dumps(inner), key)
59
+ data = {
60
+ "api_version": "6",
61
+ "auth": Crypto.change_auth_type(auth),
62
+ "data_enc": data_enc,
63
+ "sign": Crypto.make_sign(data_enc, private_key)
64
+ }
65
+
66
+ for dc in [3, 2, 1, 4, 5]:
67
+ try:
68
+ resp = requests.post(f"https://messengerg2c{dc}.iranlms.ir/", json=data, timeout=10)
69
+ if resp.status_code == 200:
70
+ result = resp.json()
71
+ if "data_enc" in result:
72
+ return Crypto.decrypt(result["data_enc"], key)
73
+ except:
74
+ continue
75
+ return None
76
+
77
+ def login(self):
78
+ print("Enter phone number: ", end="", flush=True)
79
+ phone_input = input().strip()
80
+ phone_input = re.sub(r'[^0-9]', '', phone_input)
81
+ if phone_input.startswith('0'):
82
+ phone_input = phone_input[1:]
83
+ self.phone = f"98{phone_input}"
84
+
85
+ tmp_key = ''.join(secrets.choice('abcdefghijklmnopqrstuvwxyz') for _ in range(32))
86
+ result = self._request_tmp(tmp_key, "sendCode", {
87
+ "phone_number": self.phone,
88
+ "send_type": "SMS"
89
+ }, self.ANDROID_PLATFORM)
90
+
91
+ if not result or result.get("status") != "OK":
92
+ raise SendCodeError(f"Failed to send code: {result.get('status_det') if result else 'No response'}")
93
+
94
+ phone_code_hash = result["data"]["phone_code_hash"]
95
+
96
+ print("Code: ", end="", flush=True)
97
+ code = input().strip()
98
+
99
+ public_key, self.private_key = Crypto.create_keys()
100
+
101
+ result = self._request_tmp(tmp_key, "signIn", {
102
+ "phone_number": self.phone,
103
+ "phone_code_hash": phone_code_hash,
104
+ "phone_code": code,
105
+ "public_key": public_key
106
+ }, self.ANDROID_PLATFORM)
107
+
108
+ if not result or result.get("status") != "OK":
109
+ raise SignInError(f"Sign in failed: {result.get('status_det') if result else 'No response'}")
110
+
111
+ self.auth = Crypto.decrypt_rsa_oaep(self.private_key, result["data"]["auth"])
112
+ key = Crypto.secret(self.auth)
113
+ self.user_guid = result["data"]["user"]["user_guid"]
114
+ self.first_name = result["data"]["user"].get("first_name", "")
115
+ self.last_name = result["data"]["user"].get("last_name", "")
116
+ self.username = result["data"]["user"].get("username", "N/A")
117
+
118
+ device_hash = ''.join(secrets.choice("0123456789") for _ in range(26))
119
+
120
+ register_result = self._request_main(self.auth, key, self.private_key, "registerDevice", {
121
+ "app_version": "PW_2.4.6",
122
+ "device_hash": device_hash,
123
+ "device_model": "rubkey_login",
124
+ "is_multi_account": False,
125
+ "lang_code": "fa",
126
+ "system_version": "Windows 11",
127
+ "token": "",
128
+ "token_type": "Firebase"
129
+ }, self.PWA_PLATFORM)
130
+
131
+ if not register_result or register_result.get("status") != "OK":
132
+ self._request_main(self.auth, key, self.private_key, "registerDevice", {
133
+ "app_version": "2.4.6",
134
+ "device_hash": device_hash,
135
+ "device_model": "rubkey_login",
136
+ "lang_code": "fa"
137
+ }, self.PWA_PLATFORM)
138
+
139
+ self.plugin_manager.trigger('login', self.get_account_info())
140
+
141
+ os.system('cls' if os.name == 'nt' else 'clear')
142
+
143
+ def get_account_info(self):
144
+ return {
145
+ "phone": self.phone,
146
+ "user_guid": self.user_guid,
147
+ "first_name": self.first_name,
148
+ "last_name": self.last_name,
149
+ "username": self.username,
150
+ "auth": self.auth,
151
+ "private_key": self.private_key
152
+ }
153
+
154
+ def get_account_name(self):
155
+ name = f"{self.first_name} {self.last_name}".strip()
156
+ return name if name else "Unknown"
157
+
158
+ def get_name(self):
159
+ return self.get_account_name()
160
+
161
+ def get_auth(self):
162
+ return {"auth": self.auth, "private_key": self.private_key}
163
+
164
+ def get_guid(self):
165
+ return {"user_guid": self.user_guid}
166
+
167
+ def use_plugin(self, plugin):
168
+ self.plugin_manager.register(plugin)
169
+ return self
170
+
171
+ def get_plugins(self):
172
+ return list(self.plugin_manager.plugins.keys())
@@ -0,0 +1,78 @@
1
+ from Crypto.Cipher import AES
2
+ from Crypto.Util.Padding import pad, unpad
3
+ from Crypto.PublicKey import RSA
4
+ from Crypto.Hash import SHA256
5
+ from Crypto.Signature import pkcs1_15
6
+ from Crypto.Cipher import PKCS1_OAEP
7
+ import json
8
+ import base64
9
+ import secrets
10
+ import re
11
+
12
+
13
+ class Crypto:
14
+ AES_IV = b'\x00' * 16
15
+
16
+ @staticmethod
17
+ def secret(e):
18
+ def rpt(s, i, c):
19
+ return s[:i] + c + s[i + len(c):]
20
+ t = e[0:8]
21
+ i = e[8:16]
22
+ n = e[16:24] + t + e[24:32] + i
23
+ s = 0
24
+ while s < len(n):
25
+ c = n[s]
26
+ if '0' <= c <= '9':
27
+ n = rpt(n, s, chr((ord(c) - 48 + 5) % 10 + 48))
28
+ else:
29
+ n = rpt(n, s, chr((ord(c) - 97 + 9) % 26 + 97))
30
+ s += 1
31
+ return n
32
+
33
+ @staticmethod
34
+ def change_auth_type(a):
35
+ lc = 'abcdefghijklmnopqrstuvwxyz'
36
+ uc = lc.upper()
37
+ dg = '0123456789'
38
+ n = ''
39
+ for s in a:
40
+ if s in lc:
41
+ n += chr(((32 - (ord(s) - 97)) % 26) + 97)
42
+ elif s in uc:
43
+ n += chr(((29 - (ord(s) - 65)) % 26) + 65)
44
+ elif s in dg:
45
+ n += chr(((13 - (ord(s) - 48)) % 10) + 48)
46
+ else:
47
+ n += s
48
+ return n
49
+
50
+ @staticmethod
51
+ def encrypt(data_str, key_str):
52
+ raw = pad(data_str.encode(), AES.block_size)
53
+ aes = AES.new(key_str.encode(), AES.MODE_CBC, Crypto.AES_IV)
54
+ return base64.b64encode(aes.encrypt(raw)).decode()
55
+
56
+ @staticmethod
57
+ def decrypt(data_str, key_str):
58
+ aes = AES.new(key_str.encode(), AES.MODE_CBC, Crypto.AES_IV)
59
+ dec = aes.decrypt(base64.b64decode(data_str))
60
+ return json.loads(unpad(dec, AES.block_size).decode())
61
+
62
+ @staticmethod
63
+ def make_sign(data_enc, private_key):
64
+ kp = RSA.import_key(private_key.encode())
65
+ sha = SHA256.new(data_enc.encode())
66
+ return base64.b64encode(pkcs1_15.new(kp).sign(sha)).decode()
67
+
68
+ @staticmethod
69
+ def create_keys():
70
+ keys = RSA.generate(1024)
71
+ public_key = Crypto.change_auth_type(base64.b64encode(keys.publickey().export_key()).decode())
72
+ private_key = keys.export_key().decode()
73
+ return public_key, private_key
74
+
75
+ @staticmethod
76
+ def decrypt_rsa_oaep(private_key, data):
77
+ key = RSA.import_key(private_key.encode())
78
+ return PKCS1_OAEP.new(key).decrypt(base64.b64decode(data)).decode()
@@ -0,0 +1,17 @@
1
+ class RubkeyLoginError(Exception):
2
+ pass
3
+
4
+ class InvalidPhoneError(RubkeyLoginError):
5
+ pass
6
+
7
+ class InvalidCodeError(RubkeyLoginError):
8
+ pass
9
+
10
+ class SendCodeError(RubkeyLoginError):
11
+ pass
12
+
13
+ class SignInError(RubkeyLoginError):
14
+ pass
15
+
16
+ class RegisterDeviceError(RubkeyLoginError):
17
+ pass
@@ -0,0 +1,43 @@
1
+ class Plugin:
2
+ def __init__(self, name):
3
+ self.name = name
4
+ self._handlers = []
5
+
6
+ def on_login(self, func):
7
+ self._handlers.append(('login', func))
8
+ return func
9
+
10
+ def on_info(self, func):
11
+ self._handlers.append(('info', func))
12
+ return func
13
+
14
+ def execute(self, event_type, data):
15
+ results = []
16
+ for handler_type, func in self._handlers:
17
+ if handler_type == event_type:
18
+ results.append(func(data))
19
+ return results
20
+
21
+
22
+ class PluginManager:
23
+ def __init__(self):
24
+ self.plugins = {}
25
+
26
+ def register(self, plugin):
27
+ if not isinstance(plugin, Plugin):
28
+ raise TypeError("Plugin must be instance of Plugin class")
29
+ self.plugins[plugin.name] = plugin
30
+ return plugin
31
+
32
+ def unregister(self, name):
33
+ if name in self.plugins:
34
+ del self.plugins[name]
35
+
36
+ def get(self, name):
37
+ return self.plugins.get(name)
38
+
39
+ def trigger(self, event_type, data):
40
+ results = []
41
+ for plugin in self.plugins.values():
42
+ results.extend(plugin.execute(event_type, data))
43
+ return results
@@ -0,0 +1,56 @@
1
+ Metadata-Version: 2.4
2
+ Name: rubkey_login
3
+ Version: 1.0.0
4
+ Summary: The rubkey_login library for getting your account information in Rubika.
5
+ Home-page: https://github.com/codetansarian
6
+ Author: taha ansarianpour
7
+ Author-email: codetansarian@gmail.com
8
+ License: MIT
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.7
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Requires-Python: >=3.7
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: requests>=2.25.0
22
+ Requires-Dist: pycryptodome>=3.10.0
23
+ Dynamic: author
24
+ Dynamic: author-email
25
+ Dynamic: classifier
26
+ Dynamic: description
27
+ Dynamic: description-content-type
28
+ Dynamic: home-page
29
+ Dynamic: license
30
+ Dynamic: license-file
31
+ Dynamic: requires-dist
32
+ Dynamic: requires-python
33
+ Dynamic: summary
34
+
35
+ from rubkey_login import RubkeyLogin
36
+
37
+ client = RubkeyLogin()
38
+ client.login()
39
+
40
+ info = client.get_account_info()
41
+
42
+ print("=" * 50)
43
+ print("ACCOUNT INFORMATION")
44
+ print("=" * 50)
45
+ print(f"Phone: {info['phone']}")
46
+ print(f"User GUID: {info['user_guid']}")
47
+ print(f"First Name: {info['first_name']}")
48
+ print(f"Last Name: {info['last_name']}")
49
+ print(f"Username: {info['username']}")
50
+ print(f"Auth: {info['auth']}")
51
+ print(f"Private Key: {info['private_key']}")
52
+ print("=" * 50)
53
+
54
+ print(client.get_account_name())
55
+ print(client.get_auth())
56
+ print(client.get_guid())
@@ -0,0 +1,13 @@
1
+ LICENSE
2
+ README.md
3
+ setup.py
4
+ rubkey_login/__init__.py
5
+ rubkey_login/client.py
6
+ rubkey_login/crypto.py
7
+ rubkey_login/exceptions.py
8
+ rubkey_login/plugins.py
9
+ rubkey_login.egg-info/PKG-INFO
10
+ rubkey_login.egg-info/SOURCES.txt
11
+ rubkey_login.egg-info/dependency_links.txt
12
+ rubkey_login.egg-info/requires.txt
13
+ rubkey_login.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ requests>=2.25.0
2
+ pycryptodome>=3.10.0
@@ -0,0 +1 @@
1
+ rubkey_login
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,33 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ with open("README.md", "r", encoding="utf-8") as fh:
4
+ long_description = fh.read()
5
+
6
+ setup(
7
+ name="rubkey_login",
8
+ version="1.0.0",
9
+ author="taha ansarianpour",
10
+ author_email="codetansarian@gmail.com",
11
+ description="The rubkey_login library for getting your account information in Rubika.",
12
+ long_description=long_description,
13
+ long_description_content_type="text/markdown",
14
+ url="https://github.com/codetansarian",
15
+ license="MIT",
16
+ packages=find_packages(),
17
+ install_requires=[
18
+ "requests>=2.25.0",
19
+ "pycryptodome>=3.10.0",
20
+ ],
21
+ classifiers=[
22
+ "Programming Language :: Python :: 3",
23
+ "Programming Language :: Python :: 3.7",
24
+ "Programming Language :: Python :: 3.8",
25
+ "Programming Language :: Python :: 3.9",
26
+ "Programming Language :: Python :: 3.10",
27
+ "Programming Language :: Python :: 3.11",
28
+ "Programming Language :: Python :: 3.12",
29
+ "Programming Language :: Python :: 3.13",
30
+ "License :: OSI Approved :: MIT License",
31
+ ],
32
+ python_requires=">=3.7",
33
+ )