46
46
from .stream import RfbClientStream
47
47
48
48
49
+ # =====
50
+ class _SecurityError (Exception ):
51
+ pass
52
+
53
+
49
54
# =====
50
55
class RfbClient (RfbClientStream ): # pylint: disable=too-many-instance-attributes
51
56
# https://github.com/rfbproto/rfbproto/blob/master/rfbproto.rst
@@ -94,6 +99,8 @@ def __init__( # pylint: disable=too-many-arguments
94
99
self .__fb_cont_updates = False
95
100
self .__fb_reset_h264 = False
96
101
102
+ self .__authorized = False
103
+
97
104
self .__lock = asyncio .Lock ()
98
105
99
106
# =====
@@ -134,6 +141,8 @@ async def __wrapper(self, name: str, coro: Coroutine) -> None:
134
141
async def __main_task_loop (self ) -> None :
135
142
await self .__handshake_version ()
136
143
await self .__handshake_security ()
144
+ if not self .__authorized :
145
+ raise _SecurityError ()
137
146
await self .__handshake_init ()
138
147
await self .__main_loop ()
139
148
@@ -385,6 +394,7 @@ async def __handshake_security_send_result(self, allow: bool, allow_msg: str, de
385
394
if allow :
386
395
get_logger (0 ).info ("%s [main]: %s" , self ._remote , allow_msg )
387
396
await self ._write_struct ("access OK" , "L" , 0 )
397
+ self .__authorized = True
388
398
else :
389
399
await self ._write_struct ("access denial flag" , "L" , 1 , drain = (self .__rfb_version < 8 ))
390
400
if self .__rfb_version >= 8 :
@@ -394,6 +404,9 @@ async def __handshake_security_send_result(self, allow: bool, allow_msg: str, de
394
404
# =====
395
405
396
406
async def __handshake_init (self ) -> None :
407
+ if not self .__authorized :
408
+ raise _SecurityError ()
409
+
397
410
await self ._read_number ("initial shared flag" , "B" ) # Shared flag, ignored
398
411
399
412
await self ._write_struct ("initial FB size" , "HH" , self ._width , self ._height , drain = False )
@@ -417,6 +430,8 @@ async def __handshake_init(self) -> None:
417
430
# =====
418
431
419
432
async def __main_loop (self ) -> None :
433
+ if not self .__authorized :
434
+ raise _SecurityError ()
420
435
handlers = {
421
436
0 : self .__handle_set_pixel_format ,
422
437
2 : self .__handle_set_encodings ,
0 commit comments