JFIF$        dd7 

Viewing File: /usr/lib/python3.9/site-packages/certbot/_internal/__pycache__/auth_handler.cpython-39.opt-1.pyc

a

}|�gPR�@s�dZddlZddlZddlZddlmZddlmZddlmZddlmZddlm	Z	ddlm
Z
dd	lmZddlZdd
l
mZddlmZddlmZdd
lmZddlmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddl m!Z"e�#e$�Z%Gdd�d�Z&ej'ej(e)ej*d�dd�Z+eej'eeej,e
e-dfd�dd�Z.eej'ej/d�d d!�Z0eej*e)d"�d#d$�Z1dS)%zACME AuthHandler.�N)�Dict)�Iterable)�List)�Optional)�Sequence)�Tuple)�Type)�Response)�
challenges)�client)�errors)�messages)�achallenges)�
configuration)�
interfaces)�
error_handler)�Account)�util)�commonc@s*eZdZdZejeejee	e
edd�dd�Zd#e
jejeeee
e
jd�d	d
�Ze
jee
e
fd�dd
�Ze
e
jeeedd�dd�Zee
je
ejd�dd�Zee
eejd�dd�Z e
ejdd�dd�Z!e
je"ee
ejd�dd�Z#e
e
jdd�dd�Z$e
ejejed �d!d"�Z%dS)$�AuthHandlera�ACME Authorization Handler for a client.

    :ivar auth: Authenticator capable of solving
        :class:`~acme.challenges.Challenge` types
    :type auth: certbot.interfaces.Authenticator

    :ivar acme.client.ClientV2 acme_client: ACME client API.

    :ivar account: Client's Account
    :type account: :class:`certbot._internal.account.Account`

    :ivar list pref_challs: sorted user specified preferred challenges
        type strings with the most preferred challenge listed first

    N)�auth�acme_client�account�pref_challs�returncCs||_||_||_||_dS�N)r�acmerr)�selfrrrr�r�B/usr/lib/python3.9/site-packages/certbot/_internal/auth_handler.py�__init__0szAuthHandler.__init__F�)�orderr�config�best_effort�max_retries�
max_time_minsrc
CsL|jdd�}|st�d��|js,t�d��|�|�}|s>|St�|j|���z0|j	�
|�}|jr|tj
d|�||�dd�Wn>tjy�}	z$t�d�t�d�|	�WYd}	~	n
d}	~	00t||�D]\}
}|j�|
j|�q�t�d	�|�||||�d
d�|D�}|�st�d��|Wd�S1�s40Yt�d
��dS)a
        Retrieve all authorizations, perform all challenges required to validate
        these authorizations, then poll and wait for the authorization to be checked.
        :param acme.messages.OrderResource orderr: must have authorizations filled in
        :param certbot.configuration.NamespaceConfig config: current Certbot configuration
        :param bool best_effort: if True, not all authorizations need to be validated (eg. renew)
        :param int max_retries: maximum number of retries to poll authorizations
        :param float max_time_mins: maximum time (in minutes) to poll authorizations
        :returns: list of all validated authorizations
        :rtype: List

        :raises .AuthorizationError: If unable to retrieve all authorizations
        NzNo authorization to handle.z9No ACME client defined, authorizations cannot be handled.z3Challenges loaded. Press continue to submit to CA.
T)�pausez!Failure in setting up challenges.z0Attempting to clean up outstanding challenges...zWaiting for verification...cSsg|]}|jjtjkr|�qSr��body�statusr
ZSTATUS_VALID��.0�authzrrrr�
<listcomp>os�z5AuthHandler.handle_authorizations.<locals>.<listcomp>zAll challenges have failed.z?An unexpected error occurred while handling the authorizations.)�authorizationsr�AuthorizationErrorr�Error�_choose_challengesrZExitHandler�_cleanup_challengesrZperformZdebug_challenges�display_utilZnotification�_debug_challenges_msg�logger�critical�info�zipZanswer_challenge�challb�_poll_authorizations)
rr"r#r$r%r&�authzrs�achallsZresps�error�achall�respZauthzrs_validatedrrr�handle_authorizations8s>



��




$z!AuthHandler.handle_authorizations)r"rcCs�|jst�d��dd�|jD�}g}g}|D]`}z|j�|�}|�|�Wq,tjy�}z&|�|�t�d|j	|�WYd}~q,d}~00q,||fS)a~
        Deactivate all `valid` authorizations in the order, so that they cannot be re-used
        in subsequent orders.
        :param messages.OrderResource orderr: must have authorizations filled in
        :returns: tuple of list of successfully deactivated authorizations, and
                  list of unsuccessfully deactivated authorizations.
        :rtype: tuple
        z?No ACME client defined, cannot deactivate valid authorizations.cSsg|]}|jjtjkr|�qSrr(r+rrrr.�s�z?AuthHandler.deactivate_valid_authorizations.<locals>.<listcomp>z)Failed to deactivate authorization %s: %sN)
rrr1r/Zdeactivate_authorization�append�acme_errorsr6�debug�uri)rr"Z
to_deactivateZdeactivatedZfailedr-�errr�deactivate_valid_authorizationsxs	

(z+AuthHandler.deactivate_valid_authorizations)r<r%�deadline_minutesr$rcs`�jst�d��dd�t|�D�}g}tj��tj|d�}d}t|�D]�}	|dkr^t�	|��fdd�|�
�D�}|�
�D]\}
\}}	|||
<q|dd	�|��D�}|D]}
t�
d
|
jjj�q�|�|�dd�|�
�D�}|r�tj��|kr��q,t�fdd
�|��D��}t||�}|tj����}qH|�rL��|�|�sLt�d��|�r\t�d��dS)a#
        Poll the ACME CA server, to wait for confirmation that authorizations have their challenges
        all verified. The poll may occur several times, until all authorizations are checked
        (valid or invalid), or a maximum of retries, or the polling deadline is reached.
        z3No ACME client defined, cannot poll authorizations.cSsi|]\}}||df�qSrr)r,�indexr-rrr�
<dictcomp>�s�z4AuthHandler._poll_authorizations.<locals>.<dictcomp>)Zminutes�rcs"i|]\}\}}|�j�|��qSr)rZpoll)r,rIr-�_�rrrrJ��cSs"g|]\}}|jjtjkr|�qSr)r)r*r
ZSTATUS_INVALID)r,r-rLrrrr.�s�z4AuthHandler._poll_authorizations.<locals>.<listcomp>zChallenge failed for domain %scSs,i|]$\}\}}|jjtjkr|||f�qSr)r)r*r
ZSTATUS_PENDING)r,rIr-r@rrrrJ�s�c3s(|] \}}|dur�j�|d�VqdS)N�)r�retry_after)r,rLr@rMrr�	<genexpr>�s�z3AuthHandler._poll_authorizations.<locals>.<genexpr>zSome challenges have failed.z0All authorizations were not finalized by the CA.N)rrr1�	enumerate�datetimeZnowZ	timedelta�range�time�sleep�items�valuesr6r8r)�
identifier�value�extend�max�minZ
total_seconds�_report_failed_authzrsr0)rr<r%rHr$Zauthzrs_to_checkZauthzrs_failed_to_reportZdeadlineZ
sleep_secondsrLrIr-Zauthzrs_failedZ
authzr_failedrPrrMrr;�sN
��

�
�
��


z AuthHandler._poll_authorizations)r<rcCsn|jst�d��dd�|D�}g}|r0t�d�|D]4}|jj}t||�|jj	j
��}|�|�||��q4|S)z�
        Retrieve necessary and pending challenges to satisfy server.
        NB: Necessary and already validated challenges are not retrieved,
        as they can be reused for a certificate issuance.
        z5No ACME client defined, cannot choose the challenges.cSsg|]}|jjtjkr|�qSrr(r+rrrr.�s�z2AuthHandler._choose_challenges.<locals>.<listcomp>z$Performing the following challenges:)
rrr1r6r8r)r
�gen_challenge_path�_get_chall_prefrYrZr[�_challenge_factory)rr<Zpending_authzrsr=r-Zauthzr_challenges�pathrrrr2�s

�zAuthHandler._choose_challenges)�domainrcCsjg}|j�|�}|jr\dd�|D�}|jD]}||vr*|�tjj|�q*|rR|St�d��|�	|�|S)z{Return list of challenge preferences.

        :param str domain: domain for which you are requesting preferences

        cSsh|]
}|j�qSr)�typ)r,�challrrr�	<setcomp>�rNz.AuthHandler._get_chall_pref.<locals>.<setcomp>zENone of the preferred challenges are supported by the selected plugin)
rZget_chall_prefrrBr
�	ChallengeZTYPESrr0r[)rrcZchall_prefsZplugin_prefZplugin_pref_typesrdrrrr`�s
�
zAuthHandler._get_chall_pref)r=rcCst�d�|j�|�dS)z�Cleanup challenges.

        :param achalls: annotated challenges to cleanup
        :type achalls: `list` of :class:`certbot.achallenges.AnnotatedChallenge`

        zCleaning up challengesN)r6r8rZcleanup)rr=rrrr3
s
zAuthHandler._cleanup_challenges)r-rbrcCsJ|jst�d��g}|D],}|jj|}|�t||jj|jjj	��q|S)atConstruct Namedtuple Challenges

        :param messages.AuthorizationResource authzr: authorization

        :param list path: List of indices from `challenges`.

        :returns: achalls, list of challenge type
            :class:`certbot.achallenges.AnnotatedChallenge`
        :rtype: list

        :raises .errors.Error: if challenge type is not recognized

        �Account is not set.)
rrr1r)r
rB�challb_to_achall�keyrYrZ)rr-rbr=rIr:rrrras
�zAuthHandler._challenge_factory)�failed_authzrsrcs��jst�d��i}�fdd�|D�}|D]}|�|jjg��|�q*d�jj�d�g}t	|�
�dd�d�D]\}}|�t|��ql|r�t�jt
j�r�|�d	�j�|��d
��t�d�|��dS)
z.Notifies the user about failed authorizations.rhcs6g|].}|jjD] }|jrt|�jj|jjj��qqSr)r)r
r>rirrjrYrZ)r,r-r:rMrrr.3s�z6AuthHandler._report_failed_authzrs.<locals>.<listcomp>z=
Certbot failed to authenticate some domains (authenticator: z5). The Certificate Authority reported these problems:cSs|dS)Nrr)�itemrrr�<lambda>>rNz4AuthHandler._report_failed_authzrs.<locals>.<lambda>)rjz
Hint: �
�N)rrr1�
setdefaultr>rdrBr�name�sortedrW�_generate_failed_chall_msg�
isinstance�
plugin_commonZPluginZ	auth_hintr4�notify�join)rrkZproblems�failed_achallsr?�msgrLr=rrMrr^.s 

��
z"AuthHandler._report_failed_authzrs)r=r#rcCs�|jdkr�g}i}i}|D]Z}t|jtj�rJ|�|j�d||j�|j�<t|jtj	�r|�|j�d||�
|j�<q|r�|�d�|��D]\}}|�d|�d|���q�|r�|�d�|��D]\}	}
|�d|	�d|
���q�dd�
|�SdSd	S)
aEConstruct message for debug challenges prompt

        :param list achalls: A list of
            :class:`certbot.achallenges.AnnotatedChallenge`.
        :param certbot.configuration.NamespaceConfig config: current Certbot configuration
        :returns: Message containing challenge debug info
        :rtype: str

        rrnzZThe following URLs should be accessible from the internet and return the value mentioned:
zURL: z
Expected value: zRThe following FQDNs should return a TXT resource record with the value mentioned:
zFQDN: z)Pass "-v" for more info about challenges.N)Z
verbose_countrtrer
ZHTTP01Z
validation�account_keyrErc�DNS01Zvalidation_domain_namerBrWrw)rr=r#ryZhttp01_achallsZ
dns01_achallsr?rEZ	key_authzZfqdnZkey_authz_hashrrrr5Hs*
��

z!AuthHandler._debug_challenges_msg)Fr!r!)&�__name__�
__module__�__qualname__�__doc__rZ
AuthenticatorrrZClientV2rr�strr r
Z
OrderResourcerZNamespaceConfig�bool�int�floatZAuthorizationResourcerArrGr;rr�AnnotatedChallenger2rr
rgr`r3rrar^r5rrrrr s8�	�
�@
�G�
��r)r:rzrcrcCs^|j}t�d|j|�t|tj�r2tj|||d�St|tj	�rLtj	||d�Stj
||d�SdS)a:Converts a ChallengeBody object to an AnnotatedChallenge.

    :param .ChallengeBody challb: ChallengeBody
    :param .JWK account_key: Authorized Account Key
    :param str domain: Domain of the challb

    :returns: Appropriate AnnotatedChallenge
    :rtype: :class:`certbot.achallenges.AnnotatedChallenge`

    z%s challenge for %s)r:rcrz)r:rcN)rer6r8rdrtr
ZKeyAuthorizationChallengerZ"KeyAuthorizationAnnotatedChallengeZDNSZOther)r:rzrcrerrrrios�ri.)�challbs�preferencesrcCs�i}d}t|�D]\}}|||<||7}qd}|}tdd�tt|��D��}d}	|D]:}
|
D]}|	|�||jj|�7}	q\|	|kr�|
}|	}d}	qT|s�t|��|S)a�Generate a plan to get authority over the identity.

    :param tuple challbs: A tuple of challenges
        (:class:`acme.messages.Challenge`) from
        :class:`acme.messages.AuthorizationResource` to be
        fulfilled by the client in order to prove possession of the
        identifier.

    :param list preferences: List of challenge preferences for domain
        (:class:`acme.challenges.Challenge` subclasses)

    :returns: list of indices from ``challenges``.
    :rtype: list

    :raises certbot.errors.AuthorizationError: If a
        path cannot be created that satisfies the CA given the preferences and
        combinations.

    rKNcss|]}|fVqdSrr)r,�irrrrQ�rNz%gen_challenge_path.<locals>.<genexpr>r)rR�tuplerT�len�getre�	__class__�_report_no_chall_path)r�r�Z
chall_costZmax_costr�Z	chall_clsZ
best_comboZbest_combo_cost�combinationsZcombo_totalZcomboZchallenge_indexrrrr_�s.
��r_)r�rcCs>d}t|�dkr*t|djtj�r*|d7}t�|�t�|�S)z�Logs and return a raisable error reporting that no satisfiable chall path exists.

    :param challbs: challenges from the authorization that can't be satisfied

    :returns: An authorization error
    :rtype: certbot.errors.AuthorizationError

    zyClient with the currently selected authenticator does not support any combination of challenges that will satisfy the CA.rKrzM You may need to use an authenticator plugin that can do challenges over DNS.)	r�rtrer
r{r6r7rr0)r�ryrrrr��s	�
r�)rxrcCsR|dj}|j}t�|�r |j}g}|D]}|�d|j||jjf�q(d�|�S)aCreates a user friendly error message about failed challenges.

    :param list failed_achalls: A list of failed
        :class:`certbot.achallenges.AnnotatedChallenge` with the same error
        type.
    :returns: A formatted error message for the client.
    :rtype: str

    rz(
  Domain: %s
  Type:   %s
  Detail: %s
ro)	r>rdr
Z
is_acme_error�coderBrcZdetailrw)rxr>rdryr?rrrrs�s


�
rs)2rrSZloggingrU�typingrrrrrrrZjosepyZrequests.modelsr	rr
rrrCr
ZcertbotrrrZcertbot._internalrZcertbot._internal.accountrZcertbot.displayrr4Zcertbot.pluginsrruZ	getLoggerr|r6rZ
ChallengeBodyZJWKr�r�rirgr�r_r0r�rsrrrr�<module>sH
Q��5
Back to Directory  nL+D550H?Mx ,D"v]qv;6*Zqn)ZP0!1 A "#a$2Qr D8 a Ri[f\mIykIw0cuFcRı?lO7к_f˓[C$殷WF<_W ԣsKcëIzyQy/_LKℂ;C",pFA:/]=H  ~,ls/9ć:[=/#f;)x{ٛEQ )~ =𘙲r*2~ a _V=' kumFD}KYYC)({ *g&f`툪ry`=^cJ.I](*`wq1dđ#̩͑0;H]u搂@:~וKL Nsh}OIR*8:2 !lDJVo(3=M(zȰ+i*NAr6KnSl)!JJӁ* %݉?|D}d5:eP0R;{$X'xF@.ÊB {,WJuQɲRI;9QE琯62fT.DUJ;*cP A\ILNj!J۱+O\͔]ޒS߼Jȧc%ANolՎprULZԛerE2=XDXgVQeӓk yP7U*omQIs,K`)6\G3t?pgjrmۛجwluGtfh9uyP0D;Uڽ"OXlif$)&|ML0Zrm1[HXPlPR0'G=i2N+0e2]]9VTPO׮7h(F*癈'=QVZDF,d߬~TX G[`le69CR(!S2!P <0x<!1AQ "Raq02Br#SCTb ?Ζ"]mH5WR7k.ۛ!}Q~+yԏz|@T20S~Kek *zFf^2X*(@8r?CIuI|֓>^ExLgNUY+{.RѪ τV׸YTD I62'8Y27'\TP.6d&˦@Vqi|8-OΕ]ʔ U=TL8=;6c| !qfF3aů&~$l}'NWUs$Uk^SV:U# 6w++s&r+nڐ{@29 gL u"TÙM=6(^"7r}=6YݾlCuhquympǦ GjhsǜNlɻ}o7#S6aw4!OSrD57%|?x>L |/nD6?/8w#[)L7+6〼T ATg!%5MmZ/c-{1_Je"|^$'O&ޱմTrb$w)R$& N1EtdU3Uȉ1pM"N*(DNyd96.(jQ)X 5cQɎMyW?Q*!R>6=7)Xj5`J]e8%t!+'!1Q5 !1 AQaqё#2"0BRb?Gt^## .llQT $v,,m㵜5ubV =sY+@d{N! dnO<.-B;_wJt6;QJd.Qc%p{ 1,sNDdFHI0ГoXшe黅XۢF:)[FGXƹ/w_cMeD,ʡcc.WDtA$j@:) -# u c1<@ۗ9F)KJ-hpP]_x[qBlbpʖw q"LFGdƶ*s+ډ_Zc"?%t[IP 6J]#=ɺVvvCGsGh1 >)6|ey?Lӣm,4GWUi`]uJVoVDG< SB6ϏQ@ TiUlyOU0kfV~~}SZ@*WUUi##; s/[=!7}"WN]'(L! ~y5g9T̅JkbM' +s:S +B)v@Mj e Cf jE 0Y\QnzG1д~Wo{T9?`Rmyhsy3!HAD]mc1~2LSu7xT;j$`}4->L#vzŏILS ֭T{rjGKC;bpU=-`BsK.SFw4Mq]ZdHS0)tLg