GNServer 0.0.0.0.33__py3-none-any.whl → 0.0.0.0.34__py3-none-any.whl

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.
GNServer/__init__.py CHANGED
@@ -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
GNServer/_client.py CHANGED
@@ -1,3 +1,4 @@
1
+ import os
1
2
  import time
2
3
  import httpx
3
4
  import asyncio
@@ -76,6 +77,8 @@ class GNExceptions:
76
77
 
77
78
  from KeyisBTools import TTLDict
78
79
  from KeyisBTools.cryptography.sign import S1
80
+ from KeyisBTools.cryptography import m1, hash
81
+ from KeyisBTools.models.serialization import serialize, deserialize
79
82
  from gnobjects.net.objects import GNRequest, GNResponse, Url
80
83
 
81
84
  from ._crt import crt_client
@@ -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,7 +108,18 @@ 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:
@@ -118,8 +132,10 @@ class AsyncClient:
118
132
  if self.__dns_client is None:
119
133
  self.__dns_client = AsyncClient()
120
134
 
121
- if token is not None:
122
- payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(token)}}
135
+ if self.__server_key is not None:
136
+ s = s1.sign(self.__server_key)
137
+ data = m1.encrypt(s, domain.encode(), serialize({'domain': domain}), hash(self.__server_key))
138
+ payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s}, 'data': data}
123
139
  else:
124
140
  payload = None
125
141
 
@@ -144,7 +160,7 @@ class AsyncClient:
144
160
  except:
145
161
  raise GNExceptions.ConnectionError.dns.connection
146
162
 
147
- async def getGNDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
163
+ async def getGNDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
148
164
  if use_cache:
149
165
  resuilt = self._dns_cache.get(domain)
150
166
  if resuilt is not None:
@@ -160,8 +176,8 @@ class AsyncClient:
160
176
  if self.__dns_client is None:
161
177
  self.__dns_client = AsyncClient()
162
178
 
163
- if token is not None:
164
- payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(token)}}
179
+ if self.__server_key is not None:
180
+ payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(self.__server_key)}}
165
181
  else:
166
182
  payload = None
167
183
 
@@ -187,11 +203,11 @@ class AsyncClient:
187
203
  except:
188
204
  raise GNExceptions.ConnectionError.dns.connection
189
205
 
190
- async def getDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False):
206
+ async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False):
191
207
  if domain.endswith(('.core', '.gw', '.gn', '.cdn', '.sys', '.gwis', '.abs')):
192
208
  return await self.getCoreDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
193
209
  else:
194
- return await self.getGNDNS(domain=domain, token=token, use_cache=use_cache, keep_alive=keep_alive)
210
+ return await self.getGNDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
195
211
 
196
212
  def addRequestCallback(self, callback: Callable, name: str):
197
213
  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.34
4
4
  Summary: GNServer
5
5
  Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
6
6
  Author: KeyisB
@@ -0,0 +1,9 @@
1
+ GNServer/__init__.py,sha256=RCYh6f0lwh-Xh-5fv0jZvbUE6x7l8xYJhbn-o8_ITlE,1551
2
+ GNServer/_app.py,sha256=77g8nGa1-5faslltJeffpU585T9xZKf7D7wm8EjBMyU,27610
3
+ GNServer/_client.py,sha256=fq-n322jWQZSYj1IR4UjDlmf9sMDYExVGMMIgtlMiAw,30123
4
+ GNServer/_crt.py,sha256=SOmyX7zBiCY9EhVSekksQtBHgTIZVvdqNZ8Ni-E5Zow,1390
5
+ gnserver-0.0.0.0.34.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
6
+ gnserver-0.0.0.0.34.dist-info/METADATA,sha256=83WIyIrJaW3uyTn2DWrUIxTqQpatFS6VEoATt2DOXvQ,830
7
+ gnserver-0.0.0.0.34.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ gnserver-0.0.0.0.34.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
9
+ gnserver-0.0.0.0.34.dist-info/RECORD,,
@@ -1,9 +0,0 @@
1
- GNServer/__init__.py,sha256=-iS5bld8zmaFjLCN5VW6T1CBbACHoGUPttdRdLPrUkw,1550
2
- GNServer/_app.py,sha256=77g8nGa1-5faslltJeffpU585T9xZKf7D7wm8EjBMyU,27610
3
- GNServer/_client.py,sha256=5kPQF1M6YriCKaCsleoasAaoZrf9YI428iG1RhCoufY,29474
4
- GNServer/_crt.py,sha256=SOmyX7zBiCY9EhVSekksQtBHgTIZVvdqNZ8Ni-E5Zow,1390
5
- gnserver-0.0.0.0.33.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
6
- gnserver-0.0.0.0.33.dist-info/METADATA,sha256=Iob6tpV7SrWMGAFv9Fhc3HhxURF2qt4zdLtnAoHqnqU,830
7
- gnserver-0.0.0.0.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- gnserver-0.0.0.0.33.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
9
- gnserver-0.0.0.0.33.dist-info/RECORD,,