Ë
    H~éj¾  ã                  óø  — d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ ddlZddlmZ ddlmZmZmZmZmZmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)  ejT                  d«      Z+ G d	„ d
e,«      Z- ej\                  dddd¬«      Z/dZ0dZ1dZ2d5d„Z3da4d6d„Z5d7d8d„Z6	 	 	 d9	 	 	 	 	 	 	 d:d„Z7d;d<d„Z8d=d„Z9	 	 	 d9	 	 	 	 	 	 	 	 	 d>d„Z:d?d„Z;d@d„Z<d;dAd„Z=dBd„Z>d;dCd„Z?dDd„Z@d;dEd„ZAdFd „ZBdGd!„ZCd;dHd"„ZD	 d;	 	 	 	 	 	 	 dId#„ZEdJd$„ZFdJd%„ZGdKd&„ZHdLd'„ZIdMd(„ZJdMd)„ZKd6d*„ZL	 	 dN	 	 	 	 	 dOd+„ZMdPd,„ZN	 d;	 	 	 	 	 dQd-„ZOdRd.„ZPdPd/„ZQdSd0„ZR	 d;	 	 	 	 	 dTd1„ZSdaTd6d2„ZUd6d3„ZVd6d4„ZWy)Uz½Binary download and cache management for cloakbrowser.

Downloads the patched Chromium binary on first use, caches it locally.
Similar to how Playwright downloads its own bundled Chromium.
é    )ÚannotationsN)ÚPathé   )Ú__version__)ÚBINARY_SIGNING_PUBKEYSÚCHROMIUM_VERSIONÚDOWNLOAD_BASE_URLÚGITHUB_API_URLÚGITHUB_DOWNLOAD_BASE_URLÚ_version_newerÚcheck_platform_availableÚget_archive_extÚget_archive_nameÚget_binary_dirÚget_binary_pathÚget_cache_dirÚget_chromium_versionÚget_download_urlÚget_effective_versionÚget_fallback_download_urlÚget_local_binary_overrideÚget_platform_tagÚnormalize_release_channelÚnormalize_requested_versionÚcloakbrowserc                  ó   — e Zd ZdZy)ÚBinaryVerificationErrora~  A downloaded binary could not be authenticated (bad/missing signature,
    version mismatch, or checksum failure).

    Distinct from transient download/network errors: a verification failure is
    a tampering signal and MUST surface, never silently fall back to another
    binary. The Pro routing in ensure_binary re-raises this rather than
    downgrading to the free tier.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úL/home/boxd/.venv-cloak/lib/python3.12/site-packages/cloakbrowser/download.pyr   r   4   s   „ òr#   r   ç      $@g      N@)ÚconnectÚreadÚwriteÚpooli  i€Q Ú150c                óà   — | j                  «       sy|ry	 t        | j                  «       j                  «       «      }t        j                  «       |z
  t        k\  S # t        t
        f$ r Y yw xY w)a	  Whether the welcome banner should be shown now.

    Pro: once ever (only when the marker is absent). Free: re-show when the
    marker is absent or its timestamp is older than WELCOME_FREE_INTERVAL.
    Unreadable or legacy empty markers count as stale (due).
    TF)ÚexistsÚintÚ	read_textÚstripÚOSErrorÚ
ValueErrorÚtimeÚWELCOME_FREE_INTERVAL)ÚmarkerÚproÚlasts      r$   Ú_welcome_duer7   P   si   € ð �=‰=Œ?ØÙ
ØðÜ�6×#Ñ#Ó%×+Ñ+Ó-Ó.ˆô �I‰I‹K˜$ÑÔ#8Ñ8Ð8øô ”ZÐ ò Ùðús   –'A ÁA-Á,A-Fc                 ól   — t         ryda t        j                  j                  dt	        «       › d�«       y)z�Tell the user, once per process, that a requested Preview build does not
    exist for this platform and the Stable build is being used instead.NTzP[cloakbrowser] Preview channel requested, but no preview build is available for z; using the stable build.
)Ú_preview_fallback_warnedÚsysÚstderrr(   r   r"   r#   r$   Ú_warn_preview_fallbackr<   e   s;   € õ  ØØ#Ðô ‡J�J×Ñð	Ü)Ó+Ð,Ð,Gð	Iõr#   c                ó¨  — t        «       dz  }t        || dk(  ¬«      syt        j                  j	                  d«       t        j                  j	                  d«       t        j                  j	                  d«       t        j                  j	                  d«       | dk(  rGt        j                  j	                  dt
        › d	�«       t        j                  j	                  d
«       nÌ| dk(  rGt        j                  j	                  dt
        › d�«       t        j                  j	                  d«       n€t        j                  d«      d   }t        j                  j	                  d|› dt
        › d�«       t        j                  j	                  d«       t        j                  j	                  d«       t        j                  j	                  d«       t        j                  j	                  d«       	 |j                  j                  dd¬«       |j                  t        t        t        j                  «       «      «      «       y# t        $ r Y yw xY w)uª  Show welcome message on launch. A marker file gates the cadence: a paid
    (Pro) key shows once ever; free (keyless or a free GitHub key) re-shows every
    WELCOME_FREE_INTERVAL.

    tier:
      "pro"     â€” a paid license key (Pro banner + support address)
      "free"    â€” a free GitHub key (latest binary, one concurrent session)
      "keyless" â€” no key, running the older free binary (invite the free login)
    z.welcome_shownr5   ©r5   Nú
u3     CloakBrowser â€” stealth Chromium for automation
z*  https://github.com/CloakHQ/CloakBrowser
z  CloakBrowser Pro active (vu%   ) â€” latest binary, newest patches.
u+     Pro support â†’ support@cloakbrowser.dev
Úfreez  CloakBrowser free (vz,): the latest binary, 1 concurrent session.
uD     For more than one concurrent session â†’ https://cloakbrowser.dev
ú.r   z  Running the free binary (vz). The latest binary (vz*) is free too, with 1 concurrent session.
zP  Get your key: run  cloakbrowser login  or visit https://cloakbrowser.dev/free
z.  Star us if CloakBrowser helps your project!
T©ÚparentsÚexist_ok)r   r7   r:   r;   r(   Ú	PRO_MAJORr   ÚsplitÚparentÚmkdirÚ
write_textÚstrr-   r2   r0   )Útierr4   Ú
free_majors      r$   Ú_show_welcomerM   t   sÈ  € ô ‹_Ð/Ñ/€FÜ˜ T¨U¡]Õ4ØÜ‡J�J×Ñ�TÔÜ‡J�J×ÑÐKÔLÜ‡J�J×ÑÐBÔCÜ‡J�J×Ñ�TÔØˆu‚}Ü�
‰
×ÑØ*¬9¨+Ð5[Ð\ô	
ô 	�
‰
×ÑÐGÕHØ	�ŠÜ�
‰
×ÑØ$¤Y KÐ/\Ð]ô	
ô 	�
‰
×ÑØSõ	
ô &×+Ñ+¨CÓ0°Ñ3ˆ
Ü�
‰
×ÑØ*¨:¨,ð 7#Ü#, +Ð-XðZô	
ô 	�
‰
×ÑØ_ô	
ô 	�
‰
×ÑØSô	
ô ‡J�J×ÑÐFÔGÜ‡J�J×Ñ�TÔðØ�‰×Ñ D°4ÐÔ8Ø×Ñœ#œc¤$§)¡)£+Ó.Ó/Õ0øÜò Ùðús   Ç2AI É	IÉIc                óX  — t        «       }|rKt        |«      }|j                  «       st        d|› d�«      ‚t        j                  d|«       t        |«      S t        |«      }ddlm	}m
}  || «      }t        j                  j                  d«      rd}|ry ||«      }	|	r7|	j                  r+|	j                  dk(  rd}	 t!        |||	j                  |¬	«      S |	r!t        j)                  d|	j                  «       nt        j)                  d«       t+        «        |r»t-        |«      }|j                  «       r7t/        |«      r,t        j1                  d||«       t3        «        t        |«      S t        j                  d|t5        «       «       t7        |«       |j                  «       rt/        |«      st'        d|› d�«      ‚t3        «        t        |«      S t9        «       }t-        |«      }|j                  «       rAt/        |«      r6t        j1                  d||«       t3        «        t;        «        t        |«      S t=        «       }||k7  rPt-        «       }|j                  «       r6t/        |«      r+t        j1                  d|«       t;        «        t        |«      S t        j                  d|t5        «       «       t7        «        t-        «       }|j                  «       st'        d|› d�«      ‚t;        «        t        |«      S # t"        $ r ‚ t$        $ r}
t'        d
|
› d�«      |
‚d}
~
ww xY w)aÒ  Ensure the stealth Chromium binary is available. Download if needed.

    Returns the path to the chrome executable as a string.

    Args:
        license_key: Pro license key. Also reads from CLOAKBROWSER_LICENSE_KEY env var.
        browser_version: Exact Chromium version pin. Also reads from CLOAKBROWSER_VERSION.
        release_channel: Stable (default) or Preview binary channel.

    Set CLOAKBROWSER_BINARY_PATH to skip download and use a local build.
    z!CLOAKBROWSER_BINARY_PATH set to 'z' but file does not existzUsing local binary override: %sr   )Úresolve_license_keyÚvalidate_licenseÚCLOAKBROWSER_DOWNLOAD_URLNr@   )Úrequested_versionÚplanÚrelease_channelzPro binary unavailable: z . Your license is valid but the Pro binary could not be downloaded right now. Retry in a moment. To use the free binary instead, unset CLOAKBROWSER_LICENSE_KEY.z4License validation failed (plan=%s), using free tierz/License validation unavailable, using free tierz-Pinned binary found in cache: %s (version %s)z4Stealth Chromium %s not found. Downloading for %s...zAPinned download completed but binary not found at expected path: zf. This may indicate a packaging issue. Please report at https://github.com/CloakHQ/cloakbrowser/issuesz&Binary found in cache: %s (version %s)zBinary found in cache: %sz:Download completed but binary not found at expected path: )r   r   r,   ÚFileNotFoundErrorÚloggerÚinforJ   r   ÚlicenserO   rP   ÚosÚenvironÚgetÚvalidrS   Ú_ensure_pro_binaryr   Ú	ExceptionÚRuntimeErrorÚwarningr   r   Ú_is_executableÚdebugrM   r   Ú_download_and_extractr   Ú_maybe_trigger_update_checkr   )Úlicense_keyÚbrowser_versionrT   Úlocal_overrideÚpathrR   rO   rP   ÚkeyrW   ÚeÚbinary_pathÚ	effectiveÚplatform_versionÚfallback_paths                  r$   Úensure_binaryro   ¦   s   € ô" /Ó0€NÙÜ�NÓ#ˆØ�{‰{Œ}Ü#Ø3°NÐ3CÐC\Ð]óð ô 	�‰Ð5°~ÔFÜ�4‹yÐä3°OÓDÐ÷ ?á
˜kÓ
*€CÜ	‡z�z‡~�~Ð1Ô2Øˆá
Ù Ó$ˆÙ�D—J’Jð
 �y‰y˜FÒ"Ø$(Ð!ð
Ü)ØØ&7ØŸ™Ø$3ô	ð ñ$ Ü�N‰NØFÈÏ	É	õô �N‰NÐLÔMô ÔáÜ%Ð&7Ó8ˆØ×ÑÔ¤N°;Ô$?Ü�L‰LØ?ØØ!ôô
 ŒOÜ�{Ó#Ð#ä�‰ØBØÜÓô	
ô
 	Ð/Ô0à×"Ñ"Ô$¬¸Ô)DÜØSÐT_ÐS`ð aAð Bóð ô
 	ŒÜ�;ÓÐô &Ó'€IÜ! )Ó,€Kà×ÑÔ¤¨{Ô ;Ü�‰Ð=¸{ÈIÔVÜŒÜ#Ô%Ü�;ÓÐô ,Ó-ÐØÐ$Ò$Ü'Ó)ˆØ×ÑÔ!¤n°]Ô&CÜ�L‰LÐ4°mÔDÜ'Ô)Ü�}Ó%Ð%ô ‡K�KØ>ØÜÓôô
 Ôä!Ó#€KØ×ÑÔÜØHÈÈð V=ð >ó
ð 	
ô  Ô!Üˆ{ÓÐøôk +ò àÜò ô #Ø.¨q¨cð 20ð 1óð
 ðûðús   Â>L ÌL)ÌL$Ì$L)c                óŒ  — t        | «      }t        | «      }t        | «      }t        | «      }|j                  j                  dd¬«       t        j                  t        «       d¬«      5 }t        |j                  «      }ddd«       	 	 t        |«       t%        || «       t'        |||«       t)        «        |j+                  d¬«       y# 1 sw Y   ŒMxY w# t        $ rL}t        j                  j                  d«      r‚ t         j#                  d|«       t        |«       Y d}~Œ’d}~ww xY w# j+                  d¬«       w xY w)	a  Download the binary archive and extract to cache directory.

    Tries the primary server (cloakbrowser.dev) first, falls back to
    GitHub Releases if the primary is unreachable or returns an error.
    Verifies SHA-256 checksum before extraction when available.
    TrB   F©ÚsuffixÚdeleteNrQ   z7Primary download failed (%s), trying GitHub Releases...©Ú
missing_ok)r   r   r   r   rG   rH   ÚtempfileÚNamedTemporaryFiler   r   ÚnameÚ_download_filer^   rY   rZ   r[   rV   r`   Ú_verify_download_checksumÚ_extract_archiverM   Úunlink)ÚversionÚprimary_urlÚfallback_urlÚ
binary_dirrk   ÚtmpÚtmp_pathÚprimary_errs           r$   rc   rc   6  s  € ô # 7Ó+€KÜ,¨WÓ5€LÜ Ó(€JÜ! 'Ó*€Kð ×Ñ×Ñ D°4ÐÔ8ô 
×	$Ñ	$¬OÓ,=ÀeÔ	Lð "ÐPSÜ˜Ÿ™“>ˆ÷"ð)ð		3Ü˜;¨Ô1ô 	" (¨GÔ4ä˜ :¨{Ô;ÜŒð 	�‰ 4ˆÕ(÷5"ð "ûô ò 	3Ü�z‰z�~‰~Ð9Ô:ØÜ�N‰NØIØôô ˜<¨×2Ñ2ûð	3ûð& 	�‰ 4ˆÕ(ús=   Á)CÂ	C Â#D/ ÃCÃ	D,Ã AD'Ä"D/ Ä'D,Ä,D/ Ä/Ec                ó\   — | syt        | d¬«      }|j                  «       xr t        |«      S )zATrue when a cached, executable Pro binary exists for ``version``.FTr>   )r   r,   ra   )r}   rh   s     r$   Ú_pro_binary_readyr…   c  s*   € áØÜ˜7¨Ô-€DØ�;‰;‹=Ò1œ^¨DÓ1Ð1r#   c                óê  — ddl m}m} |dk(  rdnd}|r±t        |«      r:t	        |d¬«      }t
        j                  d||«       t        |«       t        |«      S t
        j                  d|t        «       «       t        || «       t	        |d¬«      }|j                  «       st        d	|› �«      ‚t        |«       t        |«      S t        d|¬
«      }t        j                   j#                  dd«      j%                  «       dk(  }	|	rBt        |«      r7t
        j                  d|«       t        |«       t        t	        |d¬«      «      S  ||«      }
t'        |«      dk(  r  ||«      }|�|j(                  r
t+        «        |
r|�t        |«      rt-        |
|«      r|
}n|}|€t        d«      ‚t        |«      rLt	        |d¬«      }||k7  r	 t/        ||«       t
        j                  d||«       t        |«       t        |«      S 	 t
        j                  d|t        «       «       t        || «       t	        |d¬«      }|j                  «       st        d	|› �«      ‚	 t/        ||«       t        |«       t        |«      S # t0        $ r Y Œ²w xY w# t2        $ r ‚ t4        $ rG t        |«      r:t
        j7                  d||«       t        |«       t        t	        |d¬«      «      cY S ‚ w xY w# t0        $ r Y ŒŒw xY w)u†  Ensure the latest (keyed) binary is downloaded and cached. Returns its path.

    Used for both free-tier GitHub keys (plan="free") and paid keys â€” both fetch
    the same latest build; the server enforces the concurrency cap. A valid key
    NEVER falls back to the older free binary: if the latest build cannot be
    resolved or downloaded and none is cached, the error is raised.
    r   )Úget_pro_latest_releaseÚget_pro_latest_versionr@   r5   Tr>   z1Pinned Pro binary found in cache: %s (version %s)z%Downloading Pro Chromium %s for %s...ú0Pro download completed but binary not found at: ©r5   rT   ÚCLOAKBROWSER_AUTO_UPDATEÚ Úfalsez)Pro auto-update disabled; using cached %sÚpreviewz2Could not determine latest Pro version from serverz*Pro binary found in cache: %s (version %s)z7Pro update to %s failed; launching cached Pro binary %s)rX   r‡   rˆ   r…   r   rV   rb   rM   rJ   rW   r   Ú_download_pro_binaryr,   r_   r   rY   rZ   r[   Úlowerr   Úfallbackr<   r   Ú_write_pro_version_markerr0   r   r^   r`   )re   rR   rS   rT   r‡   rˆ   Úwelcome_tierrk   rl   ÚfrozenÚlatestÚreleaser}   s                r$   r]   r]   k  sò  € ÷ Hð " Vš^‘6°€Lñ ÜÐ.Ô/Ü)Ð*;ÀÔFˆKÜ�L‰LØCØØ!ôô
 ˜,Ô'Ü�{Ó#Ð#Ü�‰Ø3Ð5FÔHXÓHZô	
ô 	Ð.°Ô<Ü%Ð&7¸TÔBˆØ×!Ñ!Ô#ÜØBÀ;À-ÐPóð ô 	�lÔ#Ü�;ÓÐô &¨$ÀÔP€Iô �Z‰Z�^‰^Ð6¸Ó;×AÑAÓCÀwÑN€FÙÔ# IÔ.Ü�‰Ð@À)ÔLÜ�lÔ#Ü”? 9°$Ô7Ó8Ð8ñ
 $ OÓ4€Fô ! Ó1°YÒ>Ù(¨Ó9ˆØÐ 7×#3Ò#3Ü"Ô$ñ ØÐÜ  Ô+Ü˜& )Ô,à$‰àˆà€ô ÐOÓPÐPä˜Ô!Ü% g°4Ô8ˆð �iÒðÜ)¨'°?ÔCô 	�‰ÐAÀ;ÐPWÔXÜ�lÔ#Ü�;ÓÐðÜ�‰Ø3°WÔ>NÓ>Pô	
ô 	˜W kÔ2ô  " '¨tÔ4€KØ×ÑÔÜØ>¸{¸mÐLó
ð 	
ð
Ü! '¨?Ô;ô �,ÔÜˆ{ÓÐøôS ò Ùðûô #ò ð 	Üò 	Ü˜YÔ'Ü�N‰NØIØØôô
 ˜,Ô'Ü” y°dÔ;Ó<Ò<Øð	ûô( ò Ùðús7   ÇI; È+J
 ÉK& É;	JÊJÊ
AK#Ë!K#Ë&	K2Ë1K2c                óÜ  — t         › d| › �}t        | d¬«      }t        | d¬«      }t        «       }|j                  j                  dd¬«       t        j                  t        «       d¬«      5 }t        |j                  «      }ddd«       	 t        |d|› �|d	œ¬
«       t        || «       t        |||«       |j                  d¬«       y# 1 sw Y   ŒJxY w# j                  d¬«       w xY w)zÂDownload a Pro binary from cloakbrowser.dev with license key auth.

    Requests the explicit version so the served archive matches the signed
    manifest verified in _verify_pro_download.
    z/api/download/Tr>   rB   Frq   NzBearer )ÚAuthorizationz
X-Platform)Úheadersrt   )r	   r   r   r   rG   rH   rv   rw   r   r   rx   ry   Ú_verify_pro_downloadr{   r|   )r}   re   Údownload_urlr€   rk   Úplatform_tagr�   r‚   s           r$   r�   r�   ô  sâ   € ô (Ð(¨°w°iÐ@€LÜ ¨TÔ2€JÜ! '¨tÔ4€KÜ#Ó%€Là×Ñ×Ñ D°4ÐÔ8ä	×	$Ñ	$¬OÓ,=ÀeÔ	Lð "ÐPSÜ˜Ÿ™“>ˆ÷"ð)ÜØØà#*¨;¨-Ð!8Ø*ñõ	
ô 	˜X wÔ/ä˜ :¨{Ô;à�‰ 4ˆÕ(÷-"ð "ûð, 	�‰ 4ˆÕ(ús   Á,CÂ-C ÃCÃC+c                óà  — t         › d|› �}	 t        j                  |› d�dd¬«      }|j                  «        t        j                  |› d�dd¬«      }|j                  «        |j                  }	 t        ||j                  «       |j                  d«      }t        |«      }||k7  rt        d|› d|xs d› d�«      ‚t        «       }	t        |«      j                  |	«      }
|
€t        d|	› d�«      ‚	 t        | |
«       y
# t        $ r}t        d|› d|› d	�«      |‚d
}~ww xY w# t
        $ r}t        t        |«      «      |‚d
}~ww xY w# t
        $ r}t        t        |«      «      |‚d
}~ww xY w)uU  Verify a Pro archive with the same non-bypassable Ed25519 signature check
    as official free downloads.

    Pro binaries are served from cloakbrowser.dev (same origin as the free
    tier), so a tampered same-origin SHA256SUMS could otherwise certify a
    tampered binary (M1, #308). Fetch the Pro SHA256SUMS + detached
    SHA256SUMS.sig, verify the signature against the pinned keys FIRST, bind the
    manifest to the requested version, then verify the archive's SHA-256.

    An invalid signature, checksum, or version mismatch raises
    BinaryVerificationError (a tampering signal the router surfaces verbatim);
    CLOAKBROWSER_SKIP_CHECKSUM cannot bypass it. A failed manifest FETCH is
    transient â€” nothing was validated â€” and raises a plain RuntimeError. A
    valid-license user is never silently downgraded to the free binary.
    z/releases/pro/chromium-vú/SHA256SUMSTr%   ©Úfollow_redirectsÚtimeoutú/SHA256SUMS.sigz.Could not fetch the signed SHA256SUMS for Pro z (ú)Núutf-8z5Version mismatch in signed Pro SHA256SUMS: requested ú, manifest declares Únoneú . Refusing (possible downgrade).z3Signature-verified Pro SHA256SUMS has no entry for õ%    â€” cannot confirm binary integrity.)r	   Úhttpxr[   Úraise_for_statusr^   r_   ÚcontentÚ_verify_signaturer   rJ   ÚdecodeÚ_parse_manifest_versionr   Ú_parse_checksumsÚ_verify_checksum)Ú	file_pathr}   ÚbaseÚmanifest_respÚsig_respÚexcÚmanifest_bytesÚmanifest_textÚdeclaredÚtarball_nameÚexpecteds              r$   rš   rš     s³  € ô   Ð Ð 8¸¸	ÐB€DðÜŸ	™	Øˆf�KÐ °4Àô
ˆð 	×&Ñ&Ô(Ü—9‘9Øˆf�OÐ$°tÀTô
ˆð 	×!Ñ!Ô#ð #×*Ñ*€Nð9Ü˜.¨(×*:Ñ*:Ô;ð #×)Ñ)¨'Ó2€Mô ' }Ó5€HØ�7ÒÜ%ØCÀGÀ9ð M!Ø!)Ò!3¨VÐ 4Ð4TðVó
ð 	
ô
 $Ó%€LÜ Ó.×2Ñ2°<Ó@€HØÐÜ%ØAÀ,Àð P/ð 0ó
ð 	
ð9Ü˜ HÕ-øôE ò ô Ø<¸W¸IÀRÈÀuÈAÐNó
àð	ûð	ûô ò 9Ü%¤c¨#£hÓ/°SÐ8ûð9ûô* ò 9Ü%¤c¨#£hÓ/°SÐ8ûð9úsH   �AD  Á0D$ Ã3E
 Ä 	D!Ä	DÄD!Ä$	EÄ-EÅEÅ
	E-ÅE(Å(E-c                óæ  — t        «       }t        j                  j                  d«      r¡t        j                  j                  dd«      j	                  «       dk(  rt
        j                  d«       yt        |«      }|€t
        j                  d«       y|j                  |«      }|€t
        j                  d|«       yt        | |«       yt        |«      }|€t        d	«      ‚|\  }}t        ||«       |j                  d
«      }|xs
 t        «       }	t        |«      }
|
|	k7  rt        d|	› d|
xs d› d�«      ‚t        |«      }|j                  |«      }|€t        d|› d�«      ‚t        | |«       y)uœ  Verify the downloaded archive's integrity and authenticity.

    Official path (cloakbrowser.dev / GitHub Releases): fetch SHA256SUMS plus
    its detached Ed25519 signature SHA256SUMS.sig, verify the signature against
    the pinned public keys FIRST, then verify the archive's SHA-256 against the
    now-authenticated manifest. Mandatory and non-bypassable â€” a same-origin
    manifest can no longer certify a tampered binary (#308).

    Custom self-hosted path (CLOAKBROWSER_DOWNLOAD_URL set): the pinned keys do
    not apply to a third-party server, so fall back to the plain same-origin
    SHA256SUMS check, which CLOAKBROWSER_SKIP_CHECKSUM may bypass.
    rQ   ÚCLOAKBROWSER_SKIP_CHECKSUMrŒ   ÚtrueuP   CLOAKBROWSER_SKIP_CHECKSUM set â€” skipping verification for custom download URLNuK   SHA256SUMS not available from custom URL â€” skipping checksum verificationu>   SHA256SUMS found but no entry for %s â€” skipping verificationu¿   Could not fetch a signed SHA256SUMS (SHA256SUMS + SHA256SUMS.sig) for this release â€” refusing to use an unverified binary. Retry, or report at https://github.com/CloakHQ/cloakbrowser/issuesr¤   z1Version mismatch in signed SHA256SUMS: requested r¥   r¦   r§   z/Signature-verified SHA256SUMS has no entry for r¨   )r   rY   rZ   r[   r�   rV   r`   Ú_fetch_checksumsr°   Ú_fetch_signed_manifestr_   r¬   r­   r   r®   r¯   )r±   r}   r¹   Ú	checksumsrº   Úmanifestr¶   Ú	sig_bytesr·   Ú	requestedr¸   s              r$   rz   rz   [  s–  € ô $Ó%€Lä	‡z�z‡~�~Ð1Ô2ô �:‰:�>‰>Ð6¸Ó;×AÑAÓCÀvÒMÜ�N‰NØbôð Ü$ WÓ-ˆ	ØÐÜ�N‰NØ]ôð Ø—=‘= Ó.ˆØÐÜ�N‰NØPØôð Ü˜ HÔ-Øô & gÓ.€HØÐÜðQó
ð 	
ð
 !)Ñ€N�IÜ�n iÔ0Ø"×)Ñ)¨'Ó2€Mð Ò1Ô/Ó1€IÜ& }Ó5€HØ�9ÒÜØ?À	¸{ð K!Ø!)Ò!3¨VÐ 4Ð4TðVó
ð 	
ô
 ! Ó/€IØ�}‰}˜\Ó*€HØÐÜØ=¸l¸^ð L/ð 0ó
ð 	
ô �Y Õ)r#   c                ó¬   — | j                  «       D ]A  }|j                  «       }|j                  d«      sŒ%|t        d«      d j                  «       c S  y)zÔRead the 'version=<v>' line from a signed manifest. None if absent.

    The line has no internal whitespace so older wrappers' SHA256SUMS parsers
    ignore it (they only accept '<hash>  <filename>' lines).
    zversion=N)Ú
splitlinesr/   Ú
startswithÚlen)ÚtextÚlines     r$   r®   r®   ¤  sQ   € ð —‘Ó!ò 3ˆØ�z‰z‹|ˆØ�?‰?˜:Õ&Øœ˜J›Ð)Ð*×0Ñ0Ó2Ò2ð3ð r#   c                óX  — | xs
 t        «       }t        › d|› �t        › d|› �g}|D ]r  }	 t        j                  |› d�dd¬«      }|j                  «        t        j                  |› d�dd¬«      }|j                  «        |j                  |j                  fc S  y# t        $ r Y Œ�w xY w)a|  Fetch (SHA256SUMS, SHA256SUMS.sig) raw bytes for a version, or None.

    Both files are fetched from the SAME origin so the signature always matches
    the exact manifest bytes it certifies. The primary origin is tried first,
    then the GitHub Releases mirror. follow_redirects mirrors _fetch_checksums:
    cloakbrowser.dev 301-redirects /chromium-v* to GitHub Releases.
    ú/chromium-vrž   Tr%   rŸ   r¢   N)r   r	   r   r©   r[   rª   r«   r^   )r}   ÚvÚbasesr²   r³   r´   s         r$   r¿   r¿   ±  sÑ   € ð 	Ò)Ô'Ó)€AäÐ
˜[¨¨Ð,Ü#Ð
$ K°¨sÐ3ð€Eð ò ˆð	Ü!ŸI™IØ�&˜Ð$°tÀTôˆMð ×*Ñ*Ô,Ü—y‘yØ�&˜Ð(¸4ÈôˆHð ×%Ñ%Ô'Ø ×(Ñ(¨(×*:Ñ*:Ð:Ò:ðð øô ò 	Ùð	ús   «A-BÂ	B)Â(B)c                ó–  — ddl }ddlm} 	 |j                  |j	                  «       d¬«      }t        D ]L  }	 |j                  |j                  |«      «      }	 |j                  || «       t        j                  d«        y t        d«      ‚# t
        $ r}t        d|› �«      |‚d}~ww xY w# t
        $ r Y Œ…w xY w# t
        $ r Y Œ”w xY w)	a#  Verify a detached Ed25519 signature over the raw manifest bytes.

    sig_b64 is the base64 of the 64-byte raw signature. Tries each pinned key
    in BINARY_SIGNING_PUBKEYS; succeeds if any validates. Raises RuntimeError
    if the signature is malformed or no pinned key validates it.
    r   N)ÚEd25519PublicKeyT)Úvalidatez-Malformed SHA256SUMS.sig (not valid base64): z)SHA256SUMS signature verified: Ed25519 OKu½   SHA256SUMS signature verification failed â€” no pinned key validated the manifest. The binary's authenticity could not be confirmed. Report at https://github.com/CloakHQ/cloakbrowser/issues)Úbase64Ú1cryptography.hazmat.primitives.asymmetric.ed25519rÏ   Ú	b64decoder/   r^   r_   r   Úfrom_public_bytesÚverifyrV   rW   )r¶   Úsig_b64rÑ   rÏ   Ú	signaturerµ   Ú
pubkey_b64Úpubs           r$   r¬   r¬   Î  sé   € ó åRðØ×$Ñ$ W§]¡]£_¸tÐ$ÓDˆ	ô -ò ˆ
ð	Ø"×4Ñ4°V×5EÑ5EÀjÓ5QÓRˆCð
	Ø�J‰J�y .Ô1Ü�K‰KÐCÔDÙðô" ð	Cóð øô- ò ÜØ;¸C¸5ÐAó
àð	ûðûô ò 	ñ ð	ûô ò 	ñ ð		ús:   Œ!B · B-Á'B<Â	B*ÂB%Â%B*Â-	B9Â8B9Â<	CÃCc                ó\  — | xs
 t        «       }t        j                  j                  d«      }t        › d|› d�g}|s|j                  t        › d|› d�«       |D ]A  }	 t        j                  |dd¬«      }|j                  «        t        |j                  «      c S  y# t        $ r Y ŒPw xY w)zFFetch SHA256SUMS file for a version. Returns {filename: hash} or None.rQ   rË   rž   Tr%   rŸ   N)r   rY   rZ   r[   r	   Úappendr   r©   rª   r¯   rÈ   r^   )r}   rÌ   Úhas_custom_urlÚurlsÚurlÚresps         r$   r¾   r¾   ø  s³   € àÒ)Ô'Ó)€AÜ—Z‘Z—^‘^Ð$?Ó@€Nô !Ð! ¨Q¨C¨{Ð;Ð<€DÙØ�‰Ô/Ð0°¸A¸3¸kÐJÔKàò ˆð	Ü—9‘9˜S°4ÀÔFˆDØ×!Ñ!Ô#Ü# D§I¡IÓ.Ò.ð	ð øô ò 	Ùð	ús   Á<BÂ	B+Â*B+c                óB  — i }| j                  «       j                  «       D ]{  }|j                  «       j                  dd«      }t        |«      dk7  rŒ2|\  }}|j	                  «       }t        |«      dk7  st        d„ |D «       «      rŒh|||j                  d«      <   Œ} |S )zðParse SHA256SUMS format: '<64-hex sha256>  filename' per line.

    Only lines whose first token is a 64-character hex digest are accepted
    (matches the JS parser); blank lines, the version= line, and any other
    junk are ignored.
    Nr   é   é@   c              3  ó$   K  — | ]  }|d v–— Œ
 y­w)Ú0123456789abcdefNr"   )Ú.0Úcs     r$   ú	<genexpr>z#_parse_checksums.<locals>.<genexpr>  s   è ø€ Ò%TÀa aÐ/AÔ&AÑ%Tùs   ‚Ú*)r/   rÅ   rF   rÇ   r�   ÚanyÚlstrip)rÈ   ÚresultrÉ   ÚpartsÚhash_valÚfilenames         r$   r¯   r¯     s™   € ð €FØ—
‘
“×'Ñ'Ó)ò 0ˆØ—
‘
“×"Ñ" 4¨Ó+ˆÜˆu‹:˜Š?ØØ"Ñˆ�(Ø—>‘>Ó#ˆÜˆx‹=˜BÒ¤#Ñ%TÈ8Ô%TÔ"TØØ'/ˆˆx�‰˜sÓ#Ò$ð0ð €Mr#   c                óš  ‡— t        j                  «       }	 t        | d«      5 Št        ˆfd„d«      D ]  }|j	                  |«       Œ 	 ddd«       |j                  «       j                  «       }||k7  rt        d|› d|› d�«      ‚t        j                  d	«       y# 1 sw Y   ŒTxY w# t
        $ r t        j                  d| «       ‚ w xY w)
z:Verify SHA-256 of a file. Raises RuntimeError on mismatch.Úrbc                 ó&   •— ‰ j                  d«      S )Né    )r'   )Úfs   €r$   ú<lambda>z"_verify_checksum.<locals>.<lambda>%  s   ø€  a§f¡f¨T£l€ r#   r#   Nz/Failed to read downloaded file for checksum: %sz*Checksum verification failed!
  Expected: z
  Got:      zs
  File may be corrupted or tampered with. Please retry or report at https://github.com/CloakHQ/cloakbrowser/issueszChecksum verified: SHA-256 OK)ÚhashlibÚsha256ÚopenÚiterÚupdater0   rV   ÚerrorÚ	hexdigestr�   r_   rW   )r±   Úexpected_hashrö   ÚchunkÚactualró   s        @r$   r°   r°      s×   ø€ ä�^‰^Ó€FðÜ�)˜TÓ"ð 	% aÜÓ2°CÓ8ò %�Ø—‘˜eÕ$ñ%÷	%ð ×ÑÓ×%Ñ%Ó'€FØ�ÒÜðØ(˜/ð *Ø!˜(ð #WðXó
ð 	
ô ‡K�KÐ/Õ0÷	%ð 	%ûô ò Ü�‰ÐFÈ	ÔRØðús"   —B) £&BÁ
B) ÂB&Â"B) Â)!C
c           
     ó
  — t         j                  d| «       t        j                  d| dt        |xs i ¬«      5 }|j                  «        	 t        |j                  j                  dd«      «      }d}d}	 t        |d«      5 }|j                  d	¬
«      D ]X  }|j                  |«       |t        |«      z  }|dkD  sŒ(|dz  |z  }	|	|dz   k\  sŒ9|	}t         j                  d|	|dz  |dz  «       ŒZ 	 ddd«       ddd«       t         j                  d|j#                  «       j$                  dz  «       y# t        t        f$ r d}Y ŒÕw xY w# 1 sw Y   ŒZxY w# t        $ r t         j!                  d|«       ‚ w xY w# 1 sw Y   Œ‚xY w)z&Download a file with progress logging.zDownloading from %sÚGETT)r    r¡   r™   zcontent-lengthr   éÿÿÿÿÚwbrò   )Ú
chunk_sizeéd   é
   z"Download progress: %d%% (%d/%d MB)i   Nz#Failed to write downloaded file: %szDownload complete: %d MB)rV   rW   r©   ÚstreamÚDOWNLOAD_TIMEOUTrª   r-   r™   r[   Ú	TypeErrorr1   r÷   Ú
iter_bytesr(   rÇ   r0   rú   ÚstatÚst_size)
rÞ   Údestr™   ÚresponseÚtotalÚ
downloadedÚlast_logged_pctró   rý   Úpcts
             r$   ry   ry   6  sŒ  € ä
‡K�KÐ% sÔ+ä	�‰ØØØÜ Ø’˜2ô
ð #ð 
Ø×!Ñ!Ô#ð	Ü˜×(Ñ(×,Ñ,Ð-=¸qÓAÓBˆEð ˆ
Øˆð	Ü�d˜DÓ!ð  QØ%×0Ñ0¸DÐ0ÓAò �EØ—G‘G˜E”NØ¤# e£*Ñ,�Jà˜q“yØ(¨3Ñ.°%Ñ7˜à /°BÑ"6Ó6Ø.1˜OÜ"ŸK™KØ DØ #Ø *¨{Ñ ;Ø %¨+Ñ 6õ	ñ÷÷##ôJ ‡K�KÐ*¨D¯I©I«K×,?Ñ,?ÀKÑ,PÕQøô5 œ:Ð&ò 	ØŠEð	ú÷ð ûô  ò 	Ü�L‰LÐ>ÀÔEØð	ú÷C#ð #úse   ¹E9Á%D2Á0E9Á5EÂ:E	Â<E	Ã"E	Ã0EÄ2EÅE9ÅEÅE9Å	E	ÅEÅ!E6Å6E9Å9Fc                óJ  — t         j                  d|«       |j                  «       r	 t        j                  |«       |j                  dd¬«       t        | «      j                  d«      rt        | |«       nt        | |«       t        |«       |xs
 t        «       }|j                  «       rt        |«       t        j                   «       dk(  rt#        |«       |j                  «       rt         j                  d|«       yy# t
        $ r t         j                  d|«       ‚ w xY w)	z7Extract tar.gz or zip archive to destination directory.zExtracting to %sz1Failed to remove partial extraction directory: %sTrB   z.zipÚDarwinzBinary ready: %sN)rV   rW   r,   ÚshutilÚrmtreer0   rú   rH   rJ   ÚendswithÚ_extract_zipÚ_extract_tarÚ_flatten_single_subdirr   Ú_make_executableÚplatformÚsystemÚ_remove_quarantine)Úarchive_pathÚdest_dirrk   Úbps       r$   r{   r{   b  sì   € ô ‡K�KÐ" HÔ-ð ‡�Ôð	Ü�M‰M˜(Ô#ð
 ‡N�N˜4¨$€NÔ/ä
ˆ<Ó×!Ñ! &Ô)Ü�\ 8Õ,ä�\ 8Ô,ô
 ˜8Ô$ð 
Ò	)œÓ)€BØ	‡y�y„{Ü˜Ôô ‡�Ó˜HÒ$Ü˜8Ô$à	‡y�y„{Ü�‰Ð&¨Õ+ð øô3 ò 	Ü�L‰LÐLÈhÔWØð	ús   ¨D Ä!D"c                óœ  — t        j                  | d«      5 }g }|j                  «       D ]ù  }|j                  «       s|j	                  «       r`|j
                  }t        j                  j                  |«      sd|j                  d«      v rˆt        j                  d|j                  |«       Œƒ||j                  z  j                  «       }t        |«      j                  t        |j                  «       «      «      st!        d|j                  › �«      ‚|j#                  |«       Œû |j%                  ||¬«       ddd«       y# 1 sw Y   yxY w)z6Extract tar.gz archive with path traversal protection.zr:gzz..ú/z%Skipping suspicious symlink: %s -> %sú!Archive contains path traversal: )ÚmembersN)Útarfiler÷   Ú
getmembersÚissymÚislnkÚlinknamerY   rh   ÚisabsrF   rV   r`   rx   ÚresolverJ   rÆ   r_   rÛ   Ú
extractall)r  r  ÚtarÚsafe_membersÚmemberÚlink_targetÚmember_paths          r$   r  r  ‰  s  € ä	�‰�l FÓ	+ð 7¨sØˆØ—n‘nÓ&ò 	(ˆFà�|‰|Œ~ §¡¤Ø$Ÿo™o�Ü—7‘7—=‘= Ô-°¸×9JÑ9JÈ3Ó9OÑ1OÜ—N‘NØ?ØŸ™Ø#ôð
 à'¨&¯+©+Ñ5×>Ñ>Ó@�Ü˜;Ó'×2Ñ2´3°x×7GÑ7GÓ7IÓ3JÔKÜ&Ø;¸F¿K¹K¸=ÐIóð ð ×Ñ Õ'ð#	(ð& 	�‰�x¨ˆÔ6÷+7÷ 7ñ 7ús   —D"EÅEc                ór  — ddl }|j                  | d«      5 }|j                  «       D ]h  }||j                  z  j	                  «       }t        |«      j                  t        |j	                  «       «      «      rŒRt        d|j                  › �«      ‚ |j                  |«       ddd«       y# 1 sw Y   yxY w)z3Extract zip archive with path traversal protection.r   NÚrr#  )	ÚzipfileÚZipFileÚinfolistrî   r+  rJ   rÆ   r_   r,  )r  r  r4  ÚzfrW   r1  s         r$   r  r  £  sž   € ãà	�‰˜ sÓ	+ð  ¨rØ—K‘K“Mò 	XˆDØ# d§m¡mÑ3×<Ñ<Ó>ˆKÜ�{Ó#×.Ñ.¬s°8×3CÑ3CÓ3EÓ/FÕGÜ"Ð%FÀtÇ}Á}ÀoÐ#VÓWÐWð	Xð 	�‰�hÔ÷ ÷  ñ  ús   —A"B-Á:*B-Â-B6c                ó<  — t        | j                  «       «      }t        |«      dk(  rÑ|d   j                  «       r½|d   }|j                  j                  d«      r!t        j                  d|j                  «       yt        j                  d|j                  «       	 |j                  «       D ]7  }t        j                  t        |«      t        | |j                  z  «      «       Œ9 |j                  «        yyy# t        $ r t        j                  d|«       ‚ w xY w)zÛIf extraction created a single subdirectory, move its contents up.

    Many tar archives wrap files in a top-level directory (e.g.
    fingerprint-chromium-142-custom-v2/chrome). We want chrome at dest_dir/chrome.
    r   r   z.appzKeeping .app bundle intact: %sNz"Flattening single subdirectory: %sz)Failed to flatten extracted directory: %s)ÚlistÚiterdirrÇ   Úis_dirrx   r  rV   rb   r  ÚmoverJ   Úrmdirr0   rú   )r  ÚentriesÚsubdirÚitems       r$   r  r  ¯  sç   € ô �8×#Ñ#Ó%Ó&€GÜ
ˆ7ƒ|�qÒ˜W Q™Z×.Ñ.Ô0Ø˜‘ˆà�;‰;×Ñ Ô'Ü�L‰LÐ9¸6¿;¹;ÔGØÜ�‰Ð9¸6¿;¹;ÔGð	ØŸ™Ó(ò B�Ü—‘œC ›I¤s¨8°d·i±iÑ+?Ó'@ÕAðBà�L‰L�Nð 1Ðøô ò 	Ü�L‰LÐDÀfÔMØð	ús   ÂAC: Ã:!Dc                ó–   — 	 t        j                  | t         j                  «      S # t        $ r t        j                  d| «       Y yw xY w)zCheck if a file is executable.z*Failed to check executable permissions: %sF)rY   ÚaccessÚX_OKr0   rV   rú   ©rh   s    r$   ra   ra   Æ  s=   € ðÜ�y‰y˜œrŸw™wÓ'Ð'øÜò Ü�‰ÐAÀ4ÔHÙðús   ‚#& ¦AÁAc                óð   — t        j                  «       dk(  ry| j                  «       j                  }| j	                  |t        j
                  z  t        j                  z  t        j                  z  «       y)zMMake a file executable (chmod +x). Skipped on Windows (no-op / AV lock risk).ÚWindowsN)r  r  r
  Úst_modeÚchmodÚS_IXUSRÚS_IXGRPÚS_IXOTH)rh   Úcurrents     r$   r  r  Ï  sL   € ä‡�Ó˜IÒ%ØØ�i‰i‹k×!Ñ!€GØ‡J�JˆwœŸ™Ñ%¬¯©Ñ4´t·|±|ÑCÕDr#   c                óÆ   — 	 t        j                  ddt        | «      gdd¬«       t        j	                  d| «       y	# t
        $ r t        j	                  dd¬«       Y y	w xY w)
zQRemove macOS quarantine/provenance xattrs so Gatekeeper doesn't block the binary.Úxattrz-crTé   )Úcapture_outputr¡   z%Removed quarantine attributes from %sz&Failed to remove quarantine attributes©Úexc_infoN)Ú
subprocessÚrunrJ   rV   rb   r^   rD  s    r$   r  r  ×  s[   € ðNÜ�‰Ø�eœS ›YÐ'ØØõ	
ô
 	�‰Ð<¸dÕCøÜò NÜ�‰Ð=ÈˆÖMðNús   ‚:= ½ A ÁA c                 óà   — ddl m}   | «       }|j                  «       r-	 t        j                  |«       t        j                  d|«       yy# t
        $ r t        j                  d|«       ‚ w xY w)z>Remove all cached binaries. Forces re-download on next launch.r   )r   zFailed to clear cache: %szCache cleared: %sN)	Úconfigr   r,   r  r  r0   rV   rú   rW   )r   Ú	cache_dirs     r$   Úclear_cacherX  ä  sb   € å%á“€IØ×ÑÔð	Ü�M‰M˜)Ô$ô 	�‰Ð'¨Õ3ð øô ò 	Ü�L‰LÐ4°iÔ@Øð	ús   ŸA Á!A-c                ó†  — t        | «      }|xs t        d|¬«      }t        |«      }|r|}t        |d¬«      }n|xs
 t        «       }t        |«      }|rt        › d�}t        |«      dk(  r|dz  }nt        |«      }||rdndt        t        «       t        |«      |j                  «       t        t        ||¬«      «      |d	œS )
uÑ  Return info about the current binary installation.

    tier reflects what is actually installed on disk, not merely whether a
    license is cached â€” a cached license with no Pro binary downloaded yet is
    still effectively running the free binary, and the active key may differ
    from the cached one.

    browser_version (or CLOAKBROWSER_VERSION) pins the reported version so the
    info matches what a pinned launch actually runs, instead of latest.
    TrŠ   r>   z/api/download/latestrŽ   z?channel=previewr5   r@   )r}   rK   Úbundled_versionr  rk   Ú	installedrW  r›   )r   r   r…   r   r	   r   r   r   r   rJ   r,   r   )rf   rT   rÃ   Úpro_versionr5   rl   rk   r›   s           r$   Úbinary_infor]  ò  sÕ   € ô ,¨OÓ<€Ið ò Ô4Ø /ô €Kô ˜KÓ
(€Cá
Øˆ	Ü% k°tÔ<‰àÒ8Ô!6Ó!8ˆ	Ü% iÓ0ˆÙ
Ü+Ð,Ð,@ÐAˆÜ$ _Ó5¸ÒBØÐ.Ñ.‰Lä'¨	Ó2ˆàÙ‘ &Ü+Ü$Ó&Ü˜;Ó'Ø ×'Ñ'Ó)Üœ¨	°sÔ;Ó<Ø$ñ	ð 	r#   c                 óô   — t        «       } | €yt        | t        «       «      syt        | «      }|j	                  «       rt        | «       | S t        j                  d| «       t        | ¬«       t        | «       | S )zÚManually check for a newer Chromium version. Returns new version or None.

    This is the public API for triggering an update check. Unlike the
    background check in ensure_binary(), this blocks until complete.
    NzDownloading Chromium %s...©r}   )	Ú_get_latest_chromium_versionr   r   r   r,   Ú_write_version_markerrV   rW   rc   )r•   r€   s     r$   Úcheck_for_updaterb  %  sl   € ô *Ó+€FØ€~ØÜ˜&Ô"6Ó"8Ô9Øä Ó'€JØ×ÑÔä˜fÔ%Øˆä
‡K�KÐ,¨fÔ5Ü &Õ)Ü˜&Ô!Ø€Mr#   c                ó>  — ddl m}  ||«      }|syt        d|¬«      }|rt        ||«      st	        |«      ryt	        |«      sMt
        j                  d|«       t        || «       t        |d¬«      }|j                  «       st        d|› �«      ‚t        ||«       |S )	a.  Move a Pro install to the selected channel's latest. Blocks until complete.

    Returns the new version when a newer Pro build is downloaded or an
    already-cached newer build is activated, else None (already up to date or the
    server could not be reached). Requires a valid Pro license key.
    r   )rˆ   NTrŠ   zDownloading Pro Chromium %s...r>   r‰   )rX   rˆ   r   r   r…   rV   rW   r�   r   r,   r_   r’   )re   rT   rˆ   r•   rl   rk   s         r$   Úcheck_for_pro_updaterd  =  s¡   € õ 0á# OÓ4€FÙØä%¨$ÀÔP€IÙœ¨°	Ô:Ô?PØô@ð ä˜VÔ$Ü�‰Ð4°fÔ=Ü˜V [Ô1Ü% f°$Ô7ˆØ×!Ñ!Ô#ÜØBÀ;À-ÐPóð ô ˜f oÔ6Ø€Mr#   c                 ó´  — t         j                  j                  dd«      j                  «       dk(  ryt	        «       ryt         j                  j                  d«      ryt        «       dz  } | j                  «       rI	 t        | j                  «       j                  «       «      }t        j                  «       |z
  t        k  ry	 yy# t        t        f$ r Y yw xY w)z?Check if auto-update is enabled and rate limit hasn't been hit.r‹   rŒ   r�   FrQ   ú.last_update_checkT)rY   rZ   r[   r�   r   r   r,   Úfloatr.   r/   r2   ÚUPDATE_CHECK_INTERVALr1   r0   )Ú
check_fileÚ
last_checks     r$   Ú_should_check_for_updaterk  `  s»   € ä	‡z�z‡~�~Ð0°"Ó5×;Ñ;Ó=ÀÒHØÜ Ô"ØÜ	‡z�z‡~�~Ð1Ô2Øä“Ð#7Ñ7€JØ×ÑÔð	Ü˜z×3Ñ3Ó5×;Ñ;Ó=Ó>ˆJÜ�y‰y‹{˜ZÑ'Ô*?Ò?Øð @ñ øô œGÐ$ò 	ØØð	ús   Á<AC ÃCÃCc                 óÔ  — 	 t        j                  t        ddid¬«      } | j                  «        t	        «       }| j                  «       D ]q  }|j                  dd«      }|j                  d«      sŒ'|j                  d«      rŒ9|j                  d	g «      D �ch c]  }|d
   ’Œ	 }}||v sŒ`|j                  d«      c S  yc c}w # t        $ r t        j                  dd¬«       Y yw xY w)zØHit GitHub Releases API, return latest chromium-v* version for this platform.

    Checks that the release has a binary asset for the current platform,
    so Linux-only releases won't be offered to macOS users.
    Úper_pager  r%   )Úparamsr¡   Útag_namerŒ   z
chromium-vÚdraftÚassetsrx   NzAuto-update check failedTrQ  )r©   r[   r
   rª   r   ÚjsonrÆ   Úremoveprefixr^   rV   rb   )rß   Úplatform_tarballr–   ÚtagÚaÚasset_namess         r$   r`  r`  t  sÚ   € ðÜ�y‰yœ°¸RÐ0@È$ÔOˆØ×ÑÔÜ+Ó-ÐØ—y‘y“{ò 	:ˆGØ—+‘+˜j¨"Ó-ˆCØ�~‰~˜lÕ+°G·K±KÀÕ4HØ29·+±+¸hÈÓ2KÖL¨Q˜q ›yÐL�ÐLØ# {Ò2Ø×+Ñ+¨LÓ9Ò9ð	:ð ùò Møô ò Ü�‰Ð/¸$ˆÔ?Ùðús<   ‚A.C Á1C ÂC ÂB?Â#C Â*C Â=C Â?C Ã C'Ã&C'c                óÄ   — t        «       }|j                  dd¬«       |dt        «       › �z  }|j                  d«      }|j	                  | «       |j                  |«       y)z?Write the latest version marker for this platform to cache dir.TrB   Úlatest_version_ú.tmpN)r   rH   r   Úwith_suffixrI   Úrename)r}   rW  r4   r�   s       r$   ra  ra  Š  sW   € ä“€IØ‡O�O˜D¨4€OÔ0Ø˜?Ô+;Ó+=Ð*>Ð?Ñ?€Fà
×
Ñ
˜VÓ
$€CØ‡N�N�7ÔØ‡J�JˆvÕr#   c                ó  — t        «       }|j                  dd¬«       t        |«      }|dk(  rdnd}||› dt        «       › �z  }|j	                  d«      }|j                  | «       t        j                  t        |«      t        |«      «       y)	z;Atomically write the selected channel's Pro version marker.TrB   rŽ   Úlatest_pro_version_previewÚlatest_pro_versionÚ_rz  N)	r   rH   r   r   r{  rI   rY   ÚreplacerJ   )r}   rT   rW  ÚchannelÚmarker_prefixr4   r�   s          r$   r’   r’   •  sŠ   € ô “€IØ‡O�O˜D¨4€OÔ0Ü'¨Ó8€Gð �iÒñ 	%à!ð ð
 ˜M˜?¨!Ô,<Ó,>Ð+?Ð@Ñ@€FØ
×
Ñ
˜VÓ
$€CØ‡N�N�7ÔÜ‡J�JŒs�3‹xœ˜V›Õ%r#   c                 óÚ  — t         ryda t        j                  j                  dd«      j	                  «       dk(  ryt        j                  j                  d«      ry	 t        j                  dd¬	«      } | j                  «        | j                  «       d
   d   }t        |t        «      rt        j                  dt        |«       yy# t        $ r t        j                  dd¬«       Y yw xY w)z>Check PyPI for a newer wrapper version. Runs once per process.NTr‹   rŒ   r�   rQ   z'https://pypi.org/pypi/cloakbrowser/jsong      @)r¡   rW   r}   uQ   Update available: cloakbrowser %s â†’ %s. Run: pip install --upgrade cloakbrowserzWrapper update check failedrQ  )Ú_wrapper_update_checkedrY   rZ   r[   r�   r©   rª   rr  r   Ú_wrapper_versionrV   r`   r^   rb   )rß   r•   s     r$   Ú_check_wrapper_updater‡  ª  sÐ   € õ ØØ"ÐÜ	‡z�z‡~�~Ð0°"Ó5×;Ñ;Ó=ÀÒHØÜ	‡z�z‡~�~Ð1Ô2ØðCÜ�y‰yØ5Øô
ˆð 	×ÑÔØ—‘“˜VÑ$ YÑ/ˆÜ˜&Ô"2Ô3Ü�N‰Nð:ä Øõ	ð 4øô ò CÜ�‰Ð2¸TˆÖBðCús   ÁA(C Ã C*Ã)C*c                 ó  — 	 t        «       dz  } | j                  j                  dd¬«       | j                  t	        t        j
                  «       «      «       t        «       }t        «       }|€yt        ||«      syt        |«      j                  «       rt        |«       yt        j                  d||«       t        |¬«       t        |«       t        j                  d|«       y# t        $ r t        j!                  dd¬	«       Y yw xY w)
z?Background task: check for newer binary, download if available.rf  TrB   NzHNewer Chromium available: %s (current: %s). Downloading in background...r_  zGBackground update complete: Chromium %s ready. Will use on next launch.zBackground update failedrQ  )r   rG   rH   rI   rJ   r2   r   r`  r   r   r,   ra  rV   rW   rc   r^   rb   )ri  rm   r•   s      r$   Ú_check_and_download_updater‰  Æ  sé   € ð@ä"“_Ð';Ñ;ˆ
Ø×Ñ×Ñ¨°tÐÔ<Ø×Ñœc¤$§)¡)£+Ó.Ô/ä/Ó1ÐÜ-Ó/ˆØˆ>ØÜ˜fÐ&6Ô7Øô ˜&Ó!×(Ñ(Ô*Ü! &Ô)Øä�‰ØVØØô	
ô
 	 fÕ-Ü˜fÔ%Ü�‰ØUØõ	
øô ò @Ü�‰Ð/¸$ˆÖ?ð@ús%   ‚A,C& Á/C& Á<$C& Â!AC& Ã& D	ÄD	c                 óÒ   — t         s+t        j                  t        d¬«      } | j	                  «        t        «       syt        j                  t        d¬«      } | j	                  «        y)z0Fire-and-forget update check in a daemon thread.T)ÚtargetÚdaemonN)r…  Ú	threadingÚThreadr‡  Ústartrk  r‰  )Úts    r$   rd   rd   é  sJ   € õ #Ü×ÑÔ$9À$ÔGˆØ	�‰Œ	ô $Ô%ØÜ×ÑÔ :À4ÔH€AØ‡G�G…Ir#   )r4   r   r5   ÚboolÚreturnr‘  )r’  ÚNone)Úkeyless)rK   rJ   r’  r“  )NNN)re   ú
str | Nonerf   r•  rT   r•  r’  rJ   )N)r}   r•  r’  r“  )r}   r•  r’  r‘  )
re   rJ   rR   r•  rS   r•  rT   r•  r’  rJ   )r}   rJ   re   rJ   r’  r“  )r±   r   r}   rJ   r’  r“  )r±   r   r}   r•  r’  r“  )rÈ   rJ   r’  r•  )r}   r•  r’  ztuple[bytes, bytes] | None)r¶   ÚbytesrÖ   r–  r’  r“  )r}   r•  r’  údict[str, str] | None)rÈ   rJ   r’  zdict[str, str])r±   r   rü   rJ   r’  r“  )rÞ   rJ   r  r   r™   r—  r’  r“  )r  r   r  r   rk   zPath | Noner’  r“  )r  r   r  r   r’  r“  )r  r   r’  r“  )rh   r   r’  r‘  )rh   r   r’  r“  )NN)rf   r•  rT   r•  r’  Údict)r’  r•  )re   rJ   rT   r•  r’  r•  )r’  r‘  )r}   rJ   r’  r“  )r}   rJ   rT   r•  r’  r“  )Xr!   Ú
__future__r   rõ   ÚloggingrY   r  r  r
  rS  r:   r%  rv   r�  r2   Úpathlibr   r©   Ú_versionr   r†  rV  r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Ú	getLoggerrV   r_   r   ÚTimeoutr  rh  r3   rE   r7   r9   r<   rM   ro   rc   r…   r]   r�   rš   rz   r®   r¿   r¬   r¾   r¯   r°   ry   r{   r  r  r  ra   r  r  rX  r]  rb  rd  rk  r`  ra  r’   r…  r‡  r‰  rd   r"   r#   r$   ú<module>rŸ     sr  ðñõ #ã Û Û 	Û Û Û Û Û 
Û Û Û Û Ý ã å 5÷÷ ÷ ÷ ÷ ó ð. 
ˆ×	Ñ	˜>Ó	*€ô˜lô ð !�5—=‘=¨°DÀÈ4ÔPÐ ð Ð ð
 "Ð ð
 €	ó9ð$ !Ð óô/ðf #Ø"&Ø"&ðMØðMàðMð  ðMð 	ó	Mô`*)óZ2ð %)ØØ"&ð	FØðFà!ðFð ðFð  ð	Fð
 	óFóR#)óL>9ôBF*óR
ôó:'ôTó(ó(1ô,)RðZ DHð$,Øð$,Ø"&ð$,Ø5@ð$,à	ó$,óN7ó4	 óó.óEó
Nó4ð #'Ø"&ð+Øð+àð+ð 
ó+ófð2 59ð Øð Ø'1ð àó óFó(ó,ð 15ð&Øð&Ø#-ð&à	ó&ð$  Ð óCó8 @ôFr#   