GNServer 0.0.0.0.33__tar.gz → 0.0.0.0.35__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.
@@ -36,7 +36,7 @@ DEALINGS IN THE SOFTWARE.
36
36
  from ._app import App
37
37
 
38
38
  from gnobjects.net.objects import Url, GNRequest, GNResponse, CommandObject, CORSObject, FileObject, TemplateObject, GNProtocol
39
- from gnobjects.net.objects import AllGNFastCommands as requests
39
+ from gnobjects.net.objects import AllGNFastCommands as responses
40
40
 
41
41
 
42
42
  from ._client import AsyncClient
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import time
2
3
  import httpx
3
4
  import asyncio
@@ -75,13 +76,15 @@ class GNExceptions:
75
76
 
76
77
 
77
78
  from KeyisBTools import TTLDict
78
- from KeyisBTools.cryptography.sign import S1
79
+ from KeyisBTools.cryptography.sign import s2
80
+ from KeyisBTools.cryptography import m1
81
+ from KeyisBTools.cryptography.bytes import hash
82
+ from KeyisBTools.models.serialization import serialize, deserialize
79
83
  from gnobjects.net.objects import GNRequest, GNResponse, Url
80
84
 
81
85
  from ._crt import crt_client
82
86
 
83
87
 
84
- s1 = S1()
85
88
 
86
89
 
87
90
  async def chain_async(first_item, rest: AsyncIterable) -> AsyncGenerator:
@@ -92,7 +95,7 @@ async def chain_async(first_item, rest: AsyncIterable) -> AsyncGenerator:
92
95
 
93
96
 
94
97
  class AsyncClient:
95
- def __init__(self):
98
+ def __init__(self, server_key: Optional[Union[bytes, str]] = None):
96
99
  self.__dns_core__ipv4 = '51.250.85.38:52943'
97
100
  self.__dns_gn__ipv4: Optional[str] = None
98
101
 
@@ -105,11 +108,25 @@ class AsyncClient:
105
108
  self.__dns_client: Optional[AsyncClient] = None
106
109
  self._dns_cache: TTLDict = TTLDict()
107
110
 
108
- async def getCoreDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
111
+ if server_key:
112
+ if isinstance(server_key, bytes):
113
+ self.__server_key = server_key
114
+ else:
115
+ if not os.path.exists(server_key):
116
+ raise Exception(f'Path not found: {server_key}')
117
+
118
+ self.__server_key = open(server_key, 'rb').read()
119
+ else:
120
+ self.__server_key = None
121
+
122
+ async def getCoreDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
109
123
  if use_cache:
110
124
  resuilt = self._dns_cache.get(domain)
111
125
  if resuilt is not None:
112
126
  return resuilt
127
+
128
+ if domain == 'api.dns.core':
129
+ return self.__dns_core__ipv4
113
130
 
114
131
  if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
115
132
  return domain
@@ -118,8 +135,10 @@ class AsyncClient:
118
135
  if self.__dns_client is None:
119
136
  self.__dns_client = AsyncClient()
120
137
 
121
- if token is not None:
122
- payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(token)}}
138
+ if self.__server_key is not None:
139
+ s = s2.sign(self.__server_key)
140
+ data = m1.encrypt(s, domain.encode(), serialize({'domain': domain}), hash(self.__server_key))
141
+ payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s}, 'data': data}
123
142
  else:
124
143
  payload = None
125
144
 
@@ -144,7 +163,7 @@ class AsyncClient:
144
163
  except:
145
164
  raise GNExceptions.ConnectionError.dns.connection
146
165
 
147
- async def getGNDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
166
+ async def getGNDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
148
167
  if use_cache:
149
168
  resuilt = self._dns_cache.get(domain)
150
169
  if resuilt is not None:
@@ -160,8 +179,8 @@ class AsyncClient:
160
179
  if self.__dns_client is None:
161
180
  self.__dns_client = AsyncClient()
162
181
 
163
- if token is not None:
164
- payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(token)}}
182
+ if self.__server_key is not None:
183
+ payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(self.__server_key)}}
165
184
  else:
166
185
  payload = None
167
186
 
@@ -187,11 +206,11 @@ class AsyncClient:
187
206
  except:
188
207
  raise GNExceptions.ConnectionError.dns.connection
189
208
 
190
- async def getDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False):
209
+ async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False):
191
210
  if domain.endswith(('.core', '.gw', '.gn', '.cdn', '.sys', '.gwis', '.abs')):
192
211
  return await self.getCoreDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
193
212
  else:
194
- return await self.getGNDNS(domain=domain, token=token, use_cache=use_cache, keep_alive=keep_alive)
213
+ return await self.getGNDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
195
214
 
196
215
  def addRequestCallback(self, callback: Callable, name: str):
197
216
  self.__request_callbacks[name] = callback
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GNServer
3
- Version: 0.0.0.0.33
3
+ Version: 0.0.0.0.35
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: GNServer
3
- Version: 0.0.0.0.33
3
+ Version: 0.0.0.0.35
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -5,7 +5,7 @@ filesName = 'GNServer'
5
5
 
6
6
  setup(
7
7
  name=name,
8
- version='0.0.0.0.33',
8
+ version='0.0.0.0.35',
9
9
  author="KeyisB",
10
10
  author_email="keyisb.pip@gmail.com",
11
11
  description=name,
File without changes
File without changes
File without changes