+
    ]f)  c                   s   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt] P                  ! ]4      t ! R R4      t	 ! R R]	4      t
 ! R R]
4      t ! R R	]	4      t ! R
 R]	4      t ! R R]4      t ! R R]	4      t ! R R]	4      t ! R R]	4      tR# )    Nc                   s,   a  ] tR t^t o R tR tRtV tR# )
BasePluginc                s    Wn         R # Nsource)selfsrc   &&=/usr/lib/python3.14/site-packages/websockify/token_plugins.py__init__ZBasePlugin.__init__   s        c                s    R # r    r   tokenr   r   lookupZBasePlugin.lookup   s    r
   r   N)__name__
__module____qualname____firstlineno__r	   r   __static_attributes____classdictcell____classdict__   @r   r   r      s      r
   r   c                   s>   a a ] tR t^t oV 3R ltR tR tRtVtV ;t	# )ReadOnlyTokenFilec                s6   < \         SV `  ! V/ VB  R V n        R # r   )superr	   _targetsr   ZargsZkwargs	__class__   &*,r   r	   ZReadOnlyTokenFile.__init__   s    $)&)r
   c                s0   \         P                  P                  V P                  4      '       dY   \         P                  ! V P                  4       Uu. uF-  p\         P                  P                  V P                  V4      NK/  	  ppMV P                  .p/ V n        ^pV F  p\        V4      P                  4        Uu. uF  qDP                  4       NK  	  up Fr  pV'       d_   VP                  R4      '       gH    \        P                  ! RV4      w  rgVP                  4       P                  R^4      V P                  V&   V^,          pKt  	  K  	  R# u upi u upi   \         d,    \        P!                  RT P                  T3,          4        LRi ; i)i   Z#z:\s:zSyntax error in %s on line %dN)ospathisdirr   Zlistdirjoinr   openZ	readlinesstrip
startswithresplitZrsplit
ValueErrorloggererror)r   ZfZ	cfg_filesZindexZlZlineZtokZtargets   &       r   _load_targetsZReadOnlyTokenFile._load_targets   s:   77==%% jj575 dkk155  7I IA,0G,=,=,?@,?q,?@ 4 4]&(hhud&;-3\\^-B-B3-Jc* 
 A 7 A
 & ]%DUZG[%[\]s   3E>E<AE3FFc                s    V P                   f   V P                  4        WP                   9   d   V P                   V,          # R # r   )r   r+   r   r   r   r   ZReadOnlyTokenFile.lookup.   s4    ==  MM!==''r
   )r   )
r   r   r   r   r	   r+   r   r   r   __classcell__r   r      @@r   r   r      s     & r
   r   c                   s2   a a ] tR t^;t oV 3R ltRtVtV ;t# )	TokenFilec                sB   < V P                  4        \        SV `	  V4      # r   )r+   r   r   )r   r   r      &&r   r   ZTokenFile.lookup?   s    w~e$$r
   r   )r   r   r   r   r   r   r   r,   r-   r.   r   r/   r/   ;   s     % %r
   r/   c                   s8   a a ] tR t^Dt oV 3R ltR tRtVtV ;t# )TokenFileNamec                s   < \         SV `  V4       \        P                  P	                  V4      '       g   \        R 4      hR# )z)TokenFileName plugin requires a directoryN)r   r	   r   r    r!   	Exception)r   r   r   r0   r   r	   ZTokenFileName.__init__H   s4    ww}}S!!GHH "r
   c                sN   \         P                  P                  V4      p\         P                  P                  V P                  V4      p\         P                  P                  V4      '       d7   \        V4      P                  4       P                  4       P                  R 4      # R# )r   N)
r   r    Zbasenamer"   r   existsr#   readr$   r'   )r   r   r       && r   r   ZTokenFileName.lookupM   si      'ww||DKK/77>>$:??$**,22377r
   r   	r   r   r   r   r	   r   r   r   r,   r-   r.   r   r1   r1   D   s     I
 r
   r1   c                   s,   a  ] tR t^Vt o R tR tRtV tR# )BaseTokenAPIc                sf    VP                   P                  R 4      w  r#VP                  RR4      pW#.# )r   ZasciiZignore)Ztextr'   Zencode)r   resphostport   &&  r   process_resultZBaseTokenAPI.process_result]   s.    YY__S)
{{78,~r
   c                s    ^ RI pVP                  V P                  V,          4      pVP                  '       d   V P	                  V4      # R# )r    N)requestsgetr   Zokr<   )r   r   r=   r8   r;   r   r   ZBaseTokenAPI.lookupb   s9    ||DKK%/0777&&t,,r
   r   N)r   r   r   r   r<   r   r   r   r   r   r   r7   r7   V   s     
 r
   r7   c                   s&   a  ] tR t^mt o R tRtV tR# )JSONTokenApic                sF    VP                  4       pVR ,          VR,          3# )r9   r:   )json)r   r8   Z	resp_jsonr5   r   r<   ZJSONTokenApi.process_resultq   s"    IIK	&!9V#455r
   r   N)r   r   r   r   r<   r   r   r   r   r   r?   r?   m   s     6 6r
   r?   c                   s&   a  ] tR t^vt o R tRtV tR# )JWTTokenApic                s    ^ RI HpHp ^ RIpVP	                  4       p \        V P                  R4      ;_uu_ 4       pVP                  4       pRRR4        TP                  X4        TP                  YQR	7      pTP                   ! TP"                  4      p	R
T	9   d   TP                  YQP$                  R	7      pTP                   ! TP$                  4      p
RT
9   d9   \&        P&                  ! 4       T
R,          8  d   \        P)                  R4       R# RT
9   d9   \&        P&                  ! 4       T
R,          8  d   \        P)                  R4       R# T
R,          T
R,          3#   + '       g   i     EL!; i  \         d1   p\        P                  R\        T4      ,          4        Rp?R# Rp?ii ; i    TP                  XP                  R4      RR7        ELx   \        P                  R4         R# ; i; i  \         d1   p\        P                  R\        T4      ,          4        Rp?R# Rp?ii ; i  \*         d    \        P                  R4        R# i ; i)r    )jwtjwkNZrbzError loading key file: %sutf-8Zoct)ZkZktyz#Failed to correctly parse key data!)keyrB   ZencZnbfzToken can not be used yet!ZexpzToken has expired!r9   r:   zFailed to parse token: %szGpackage jwcrypto not found, are you sure you've installed it correctly?)ZjwcryptorB   rC   r@   ZJWKr#   r   r4   r2   r)   r*   strZimport_from_pemZ
import_keydecodeZJWTloadsZheaderZclaimstimeZwarningImportError)r   r   rB   rC   r@   rE   Zkey_fileZkey_dataeZparsed_headerZparseds   &&         r   r   ZJWTTokenApi.lookupz   s   2	)'')C$++t,,'}}H - ##H-C3 $

5<< 8M)GGG>EELL1F?yy{VE]2'CD#F?yy{VE]2';<#vv77K -,, 9CFBC  NNX__W%=%NH LL!FG2  83q6AB  	LLbc	s   H? E: E&E: F8 )B*H =H H &E7	1E: 5H? 7E: :F5%F0*H? 0F55H? 8G>;"G H?  G;7G>8H? ;G>>H? H<%H71H? 7H<<H? ? I#"I#r   N)r   r   r   r   r   r   r   r   r   r   rA   rA   v   s     3 3r
   rA   c                   s0   a  ] tR t^t o RtR tR tRtV tR# )
TokenRedisa2  Token plugin based on the Redis in-memory data store.

The token source is in the format:

    host[:port[:db[:password]]]

where port, db and password are optional. If port or db are left empty
they will take its default value, ie. 6379 and 0 respectively.

If your redis server is using the default port (6379) then you can use:

    my-redis-host

In case you need to authenticate with the redis server and you are using
the default database and port you can use:

    my-redis-host:::verysecretpass

In the more general case you will use:

    my-redis-host:6380:1:verysecretpass

The TokenRedis plugin expects the format of the target in one of these two
formats:

- JSON

    {"host": "target-host:target-port"}

- Plain text

    target-host:target-port

Prepare data with:

    redis-cli set my-token '{"host": "127.0.0.1:5000"}'

Verify with:

    redis-cli --raw get my-token

Spawn a test "server" using netcat

    nc -l 5000 -v

Note: This Token Plugin depends on the 'redis' module, so you have
to install it before using this plugin:

      pip install redis
c                s    ^ RI pRV n        ^ V n        RV n         VP                  R4      p\        V4      ^8X  d   V^ ,          V n        EM\        V4      ^8X  d*   Vw  V n        V n        V P                  '       g   RV n        M\        V4      ^8X  dI   Vw  V n        V n        V n        V P                  '       g   RV n        V P                  '       g   ^ V n        M}\        V4      ^8X  dh   Vw  V n        V n        V n        V n        V P                  '       g   RV n        V P                  '       g   ^ V n        V P                  '       g   RV n        M\        h\        V P                  4      V n        \        V P                  4      V n        \        P                  RV P                  : RV P                  : R24       R#   \         d/    \        P                  R4       \        P
                  ! 4         ELi ; i  \         d6    \        P                  RT,          4       \        P
                  ! 4         R# i ; i)r    NzUnable to load redis modulei  r   zTokenRedis backend initilized (Z)zbThe provided --token-source='%s' is not in the expected format <host>[:<port>[:<db>[:<password>]]])redisrJ   r)   r*   sysexit_port_db	_passwordr'   Zlen_serverr(   Zintinfo)r   r   rM   Zfieldsr;   r   r	   ZTokenRedis.__init__   s   	
 
 	YYs^F6{a%ayV!+1(djzzz!%DJV!5;2dj$(zzz!%DJxxx DHV!EKBdj$(DNzzz!%DJxxx DH~~~%)DN  TZZDJ488}DHKK<<- .C  	LL67HHJ	F  	LL O  HHJ		sI   G A!G? >>G? =G? AG? G? 4G? A4G? 5G<;G<?<H?>H?c                s    ^ RI p\        P                  RV,          4       XP                  V P                  V P                  V P                  V P                  R7      pVP                  V4      pVf   R# VP                  R4      P                  4       p\        P                  RV,          4       VP!                  R4      '       d3    \"        P$                  ! V4      pVR,          P'                  R	4      w  rxMO\,        P.                  ! RV4      '       d   VP'                  R	4      w  rxM\        P                  RV,          4       R# \        P                  RV: RV: 24       Wx.#   \         d/    \        P                  R4       \        P
                  ! 4         ELi ; i  \(         d!    \        P                  R
T,          4        R# \*         d!    \        P                  RT,          4        R# i ; i)r    NzFpackage redis not found, are you sure you've installed them correctly?zresolving token '%s')r9   r:   ZdbZpasswordrD   zresponse from redis : %sZ{r9   r   zUnable to decode JSON token: %sz+Unable to find 'host' key in JSON token: %sz\S+:\S+zUnable to parse token: %szhost: z, port: )rM   rJ   r)   r*   rN   rO   rT   ZRedisrS   rP   rQ   rR   r>   rG   r$   Zdebugr%   r@   rH   r'   r(   ZKeyErrorr&   Zmatch)	r   r   rM   ZclientZstuffZresponseStrZcombor9   r:   s	   &&       r   r   ZTokenRedis.lookup  s   	
 	*U23$,,TZZ $4>>  C

5!=,,w/557KLL3kAB%%c**
  JJ{3E!&v!4!4S!9JD$ *k22(..s3
d8;FGLLt<=<?  	LLabHHJ	" "  LL!B!,"- .  LL!N!,"- . s/   E) 	0F% )5F"!F"%'G9G9G98G9)rQ   rR   rP   rS   N)	r   r   r   r   Z__doc__r	   r   r   r   r   r   r   rL   rL      s     1d*X"  " r
   rL   c                   s8   a a ] tR tRt oV 3R ltR tRtVtV ;t# )UnixDomainSocketDirectoryi4  c                s   < \         SV `  ! V/ VB  \        P                  P	                  V P
                  4      V n        R # r   )r   r	   r   r    abspathr   	_dir_pathr   r   r   r	   Z"UnixDomainSocketDirectory.__init__5  s-    $)&)5r
   c                s    ^ RI p\        P                  P                  V P                  4      '       g   R# \        P                  P                  \        P                  P                  V P                  V4      4      pVP                  V P                  4      '       g   R# \        P                  P                  V4      '       g   R# VP                  \        P                   ! V4      P                  4      '       g   R# RV.#   \         d1   p\        P                  R\        T4      ,          4        Rp?R# Rp?ii ; i)r    NZunix_socketz$Error finding unix domain socket: %s)statr   r    r!   rW   rV   r"   r%   r3   ZS_ISSOCKZst_moder2   r)   r*   rF   )r   r   rX   Zuds_pathrK   s   &&   r   r   Z UnixDomainSocketDirectory.lookup9  s    	77==00wwrww||DNNE'JKH&&t~~6677>>(++==!2!:!:;;"H.. 	Cc!fLM	s/   2D A'D !$D 4D ?D D>%D99D>)rW   r6   r-   r.   r   rU   rU   4  s     6 r
   rU   )Zloggingr   rN   rI   r&   r@   Z	getLoggerr   r)   r   r   r/   r1   r7   r?   rA   rL   rU   r   r
   r   <module>rY      s     	 
  	 			8	$ "
 "P%! %J $: .6< 67* 7tA  A H
 r
   