+
    -pÐj/  ã                  ó  a € 0 t $ R t^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIH	t	 ^ RI
HtHt ]P                  ! ]4      tRsR]R&   R R ltR	 R
 lt/ tR]R&   ]P*                  ! 4       tR R ltRR R lltR R ltRRRRRR/R R lltR# )u@  TLS trust for Hermes. One authority, one trust source.

Trust comes from the platform verifier via ``truststore``: CryptoAPI on
Windows, Security.framework on macOS, and OpenSSL's own store (with a
distro candidate sweep) on Linux. That is the machine's real answer to
"is this chain valid", so a corporate MITM root installed by MDM, an
internal CA, and a locked-down NixOS box all work with no configuration.

``install_truststore()`` runs once at process start and patches
``ssl.SSLContext`` process-wide, so every stack that builds a default
context inherits it â€” httpx, requests/urllib3, aiohttp, AND the stdlib
``urllib.request`` call sites (the llama.cpp engine download among them)
that a certifi-only or requests-only approach never reached.

An exported ``SSL_CERT_FILE`` bundle is trusted ON TOP of the platform
store; only EXPLICIT PER-PROVIDER CONFIG replaces that trust:
``ssl_ca_cert`` (a self-signed or internal endpoint's bundle) and
``ssl_verify: false`` (local development). Those are deliberate
statements about one endpoint, not an ambient guess about the machine.
)ÚannotationsN)ÚPath)ÚAnyÚOptionalzbool | NoneÚ
_installedc               ó   € V ^8„  d   QhRR/# )é   ÚreturnÚbool© )Úformats   "Ú/opt/hermes/agent/ssl_verify.pyÚ__annotate__r   $   s   € ÷ ñ ˜Dñ ó    c                 óì   € \         e   \         #  ^ RIp V P                  4        Rs \        P	                  R4       \         #   \
         d(   pRs \        P                  RT4        Rp?\         # Rp?ii ; i)al  Point every default SSLContext at the OS trust store. Idempotent.

Returns True when the platform verifier is in force. A False return
means truststore could not load (an unsupported platform, or a
stripped payload); TLS still works off OpenSSL's compiled-in paths,
it just won't see certificates the OS trusts.

Call before the first HTTPS client is constructed.
NTz&TLS trust: platform store (truststore)Fu­   truststore unavailable (%s); falling back to OpenSSL's default trust paths. Certificates trusted only by the OS store â€” a corporate root, for instance â€” will not verify.)r   Ú
truststoreÚinject_into_sslÚloggerÚdebugÚ	ExceptionÚwarning)r   Úexcs     r   Úinstall_truststorer   $   sy   € ô ÒÜÐð
Ûà×"Ñ"Ô$Øˆ
Ü�‰Ð=Ô>ô Ðøô ô 
Øˆ
Ü�‰ð@ð ÷		
ð 	
ô Ðûð
ús   �+A ÁA3ÁA.Á.A3c               ó    € V ^8„  d   QhRRRR/# )r   Ú
ssl_verifyr   r	   r
   r   )r   s   "r   r   r   B   s   € ÷ ñ  ð ¨ñ r   c                óŒ   € V R J d   R# \        V \        4      '       d&   V P                  4       P                  4       R9   d   R# R # )FT>   Ú0ÚnoÚoffÚfalse)Ú
isinstanceÚstrÚstripÚlower)r   s   &r   Ú_coerce_insecurer$   B   s:   € Ø�UÓÙÜ�*œc×"Ò" z×'7Ñ'7Ó'9×'?Ñ'?Ó'AÐE`Ô'`ÙÙr   z-dict[tuple[str | None, bool], ssl.SSLContext]Ú_CA_CONTEXTSc               ó   € V ^8„  d   QhRR/# )r   r	   ztype[ssl.SSLContext]r   )r   s   "r   r   r   N   s   € ÷  ñ  Ð#7ñ  r   c                 óp   € \         P                  P                  R8X  d   \         P                  # ^ RIHp  V # )u  The un-injected stdlib ``ssl.SSLContext``.

An explicit bundle must REPLACE OS trust, and truststore's context falls
back to the OS verifier whenever the loaded bundle rejects a chain â€” so
the bundle context has to be built from the stdlib class. Once injected
(here, or by pm.launch/pm.worker before this module loads) the only
handle on it is truststore's own saved reference; when nothing is
injected â€” truststore absent or not installed â€” ``ssl.SSLContext`` is
already the stdlib class and truststore must not be imported at all.
Ússl©Ú_original_SSLContext)r(   Ú
SSLContextÚ
__module__Útruststore._ssl_constantsr*   r)   s    r   Ú_stdlib_ssl_context_classr.   N   s)   € ô ‡~�~× Ñ  EÔ)Ü�~‰~ÐÝ>àÐr   c               ó$   € V ^8„  d   QhRRRRRR/# )r   Úca_pathz
str | NoneÚunionr
   r	   ússl.SSLContextr   )r   s   "r   r   r   `   s!   € ÷ ñ ˜Zð °ð Àñ r   c                óª  € \         ;_uu_ 4        \        P                  W34      pVfŒ   V e(   V'       g    \        4       ! \        P
                  4      pM@\        P                  ! \        P
                  4      p\        '       g   VP                  4        V e   VP                  V R7       V\        W3&   VuuRRR4       #   + '       g   i     R# ; i)zÓA stable context identity lets clients reuse the existing transport pool.

``union`` adds ``ca_path`` to the platform store (the ``SSL_CERT_FILE``
contract) instead of replacing it (a provider ``ssl_ca_cert``).
N)Úcafile)
Ú_CA_CONTEXTS_LOCKr%   Úgetr.   r(   ÚPROTOCOL_TLS_CLIENTr+   r   Úload_default_certsÚload_verify_locations)r0   r1   Úctxs   && r   Ú_shared_contextr;   `   sš   € ÷ 
Ö	Ü×Ñ Ð/Ó0ˆØŠ;ØÒ"¯5ô 0Ô1´#×2IÑ2IÓJ‘ä—n’n¤S×%<Ñ%<Ó=�ß!“zØ×*Ñ*Ô,ØÒ"Ø×)Ñ)°Ð)Ô9Ø-0ŒL˜'Ð)Ñ*Ø÷ 
×	×	Ó	ús   �&C¶ACÂ1CÃC	c               ó   € V ^8„  d   QhRR/# )r   r	   r2   r   )r   s   "r   r   r   w   s   € ÷ !ñ !˜nñ !r   c                 ó0  € \        4        \        P                  P                  RR4      P	                  4       p V '       dM   \        V 4      P                  4       '       d.   \        \        \        V 4      P                  4       4      RR7      # \        R4      # )zòThe process-wide client context (cheap after the first call).

An existing ``SSL_CERT_FILE`` bundle is trusted ON TOP of the platform store,
as it was for httpx ``verify=True``; a missing or stale path falls back to
the platform store alone.
ÚSSL_CERT_FILEÚ T)r1   N)
r   ÚosÚenvironr6   r"   r   Úis_filer;   r!   Úresolve)Úcas    r   Úplatform_ssl_contextrE   w   sf   € ô ÔÜ	�‰�‰˜¨Ó	,×	2Ñ	2Ó	4€Bß	Œd�2‹h×Ñ× Ò Üœs¤4¨£8×#3Ñ#3Ó#5Ó6¸dÔCÐCÜ˜4Ó Ð r   Ú	ca_bundler   Úbase_urlr?   c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r   rF   zOptional[str]r   r   rG   r!   r	   zbool | ssl.SSLContextr   )r   s   "r   r   r   …   s2   € ÷ )ñ )àð)ð ð)ð ð	)ð
 ñ)r   c                ó<  € \        4        \        V4      '       d#   \        P                  RT;'       g    R4       R# T ;'       g    RP	                  4       pV'       dh   \        V4      P                  4       pVP                  4       '       d#   \        \        VP                  4       4      4      # \        P                  RV4       \        P                  P                  R4      '       g&   \        P                  P                  R4      '       d   \        R4      # R	# )
u”  Resolve ``verify`` for an HTTP client.

1. ``ssl_verify: false`` â€” verification off (local development only)
2. explicit ``ca_bundle`` (the provider's ``ssl_ca_cert``) â€” that
   bundle INSTEAD of the platform store, for an endpoint whose chain
   the machine has no reason to trust
3. ``True`` â€” the platform store, via the process-wide install

``base_url`` only labels the insecure-mode warning.
u§   TLS certificate verification DISABLED (ssl_verify: false) for %s â€” this is intended for local development only and is unsafe on any network you do not fully control.za custom provider endpointFr?   uH   ssl_ca_cert path does not exist: %s â€” using the OS trust store insteadr>   ÚSSL_CERT_DIRNT)r   r$   r   r   r"   r   Ú
expanduserrB   r;   r!   rC   r@   rA   r6   )rF   r   rG   Úeffective_caÚpaths   $$$  r   Úresolve_httpx_verifyrN   …   sË   € ô  Ôä˜
×#Ò#Ü�‰ð0ð ×4Ð4Ð4ô		
ñ à—O�O ×*Ñ*Ó,€LßÜ�LÓ!×,Ñ,Ó.ˆØ�<‰<�>Š>Ü"¤3 t§|¡|£~Ó#6Ó7Ð7Ü�‰ØVØô	
ô 
‡z�z‡~�~�o×&Ò&¬"¯*©*¯.©.¸×*HÒ*HÜ˜tÓ$Ð$Ùr   )F)Ú__conditional_annotations__Ú__doc__Ú
__future__r   Úloggingr@   r(   Ú	threadingÚpathlibr   Útypingr   r   Ú	getLoggerÚ__name__r   r   Ú__annotations__r   r$   r%   ÚLockr5   r.   r;   rE   rN   )rO   s   @r   Ú<module>rZ      s–   øðôõ* #ã Û 	Û 
Û Ý ß  à	×	Ò	˜8Ó	$€à€
ˆKÓ õõ<ð ?A€Ð;Ó @Ø—N’NÓ$Ð õ ÷$õ.!ð)à#ð)ð ð)ð ÷	)ñ )r   