a }|gy.@s dZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z dd l mZdd l mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZee Z!Gdddej"ej#Z#dS)zManual authenticator pluginN)Any)Callable)Dict)Iterable)List)Tuple)Type) challenges) achallenges)errors) interfaces)reverter)util)hooks) cli_constants)misc)os)ops)commoncs8eZdZdZdZdZdZdZdZdZ dZ d Z e e d d fd d Z eedd dddZd dddZd dddZedddZeejedddZeeeejdddZeejeejdd d!Zejeejd d"d#d$Z d.eje!d d&d'd(Z"eejd dd)d*Z#eee$eefd+d,d-Z%Z&S)/ AuthenticatorzManual authenticator This plugin allows the user to perform the domain validation challenge(s) themselves. This either be done manually by the user or through shell scripts provided to Certbot. z2Manual configuration or run your own shell scriptsTaAuthenticate through manual configuration or custom shell scripts. When using shell scripts, an authenticator script must be provided. The environment variables available to this script depend on the type of challenge. $CERTBOT_DOMAIN will always contain the domain being authenticated. For HTTP-01 and DNS-01, $CERTBOT_VALIDATION is the validation string, and $CERTBOT_TOKEN is the filename of the resource requested when performing an HTTP-01 challenge. An additional cleanup script can also be provided and can use the additional variable $CERTBOT_AUTH_OUTPUT which contains the stdout output from the auth script. For both authenticator and cleanup script, on HTTP-01 and DNS-01 challenges, $CERTBOT_REMAINING_CHALLENGES will be equal to the number of challenges that remain after the current one, and $CERTBOT_ALL_DOMAINS contains a comma-separated list of all domains that are challenged for the current certificate.zcPlease deploy a DNS TXT record under the name: {domain}. with the following value: {validation} a Before continuing, verify the TXT record has been deployed. Depending on the DNS provider, this may take some time, from a few seconds to multiple minutes. You can check if it has finished deploying with aid of online tools, such as the Google Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/{domain}. Look for one or more bolded line(s) below the line ';ANSWER'. It should show the value(s) you've just added. zuCreate a file containing just this data: {validation} And make it available on your web server at this URL: {uri} z (This must be set up in addition to the previous challenges; do not remove, replace, or undo the previous challenge tasks yet.) z (This must be set up in addition to the previous challenges; do not remove, replace, or undo the previous challenge tasks yet. Note that you might be asked to create multiple distinct TXT records with the same name. This is permitted by DNS standards.) N)argskwargsreturncs@tj|i|t|j|_|ji|_d|_d|_dS)NF) super__init__r ZReverterconfigrecovery_routineenvsubsequent_dns_challengesubsequent_any_challenge)selfrr __class__D/usr/lib/python3.9/site-packages/certbot/_internal/plugins/manual.pyras  zAuthenticator.__init__).N)addrcCs|ddd|ddddS)N auth-hookz8Path or command to execute for the authentication script)help cleanup-hookz1Path or command to execute for the cleanup scriptr#)clsr%r#r#r$add_parser_argumentsis z"Authenticator.add_parser_arguments)rcCs4|jjr(|ds(td|d|dS)Nr&zdAn authentication script must be provided with --{0} when using the manual plugin non-interactively.)rZnoninteractive_modeconfr Z PluginErrorformat option_name_validate_hooksr r#r#r$preparepszAuthenticator.preparecCsL|jjrHdD]:}||}|dur ||dtd }t||q dS)N)r&r(z-hook)rZvalidate_hooksr+r-lenrZ validate_hook)r namehookZ hook_prefixr#r#r$r.xs  zAuthenticator._validate_hookscCsdS)NzThis plugin allows the user to customize setup for domain validation challenges either through shell scripts provided by the user or by performing the setup manually.r#r/r#r#r$ more_infoszAuthenticator.more_info)failed_achallsrcsttjtdfdd tj}tjdtjdtjdi}dtfdd | D}| d r~d j t j ||rvd nd dSdj ||rdnd dSdS)N)r)rcstfddDS)Nc3s|]}t|jVqdSN) isinstancechall).0achallr)r#r$ z=Authenticator.auth_hint..has_chall..)anyr;)r5r;r$ has_challsz*Authenticator.auth_hint..has_challzDNS TXT recordszchallenge fileszTLS-ALPN certificatesz and csg|]\}}|r|qSr#r#)r9kv)r?r#r$ r=z+Authenticator.auth_hint..r&zThe Certificate Authority failed to verify the {resources} created by the --manual-auth-hook. Ensure that this hook is functioning correctly{dns_hint}. Refer to "{certbot} --help manual" and the Certbot User Guide.zD and that it waits a sufficient duration of time for DNS propagation)certbot resourcesdns_hintzThe Certificate Authority failed to verify the manually created {resources}. Ensure that you created these in the correct location{dns_hint}.z?, or try waiting longer for DNS propagation on the next attempt)rErF)rr ChallengeboolDNS01HTTP01Z TLSALPN01joinsorteditemsr+r,rZ cli_command)r r5Zhas_dnsZresource_namesrEr#)r5r?r$ auth_hints6   zAuthenticator.auth_hint)domainrcCs tjtjgSr6)r rJrI)r rOr#r#r$get_chall_prefszAuthenticator.get_chall_pref)achallsrcCs|g}d}t|D]\}}t|jtjr|}qt|D]B\}}|drT|||n||||k|| |j q4|S)Nrr&) enumerater7r8r rIr+_perform_achall_with_script_perform_achall_manuallyappendZresponse account_key)r rQZ responseslast_dns_achallir:r#r#r$performs zAuthenticator.perform)r:rQrcCs|j||jddd|Dtt|||dd}t|jt j r^|j d|d<nt j ddt j ||d|j\}}||d <||j|<dS) N,css|] }|jVqdSr6rO)r9Z one_achallr#r#r$r<r=z.)ZCERTBOT_DOMAINZCERTBOT_VALIDATIONZCERTBOT_ALL_DOMAINSZCERTBOT_REMAINING_CHALLENGEStoken CERTBOT_TOKENr&ZCERTBOT_AUTH_OUTPUT)rO validationrVrKstrr1indexr7r8r rJencoderenvironpopupdate _execute_hookstripr)r r:rQr_outr#r#r$rSs   z)Authenticator._perform_achall_with_scriptF)r:rWrcCs||j}t|jtjrH|jj||jd|j j |j |j |d}n|j j||j |d}t|jtjr|jr||j7}n|jr||j7}d|_|r||jj||j d7}n|jr||j7}tj|dddd|_dS)Nr])r:Z encoded_tokenporturir_)rOr_Tr[F)wrapZforce_interactive)r_rVr7r8r rJ_HTTP_INSTRUCTIONSr,rbrZ http01_portrkrO_DNS_INSTRUCTIONSZvalidation_domain_namerIr&_SUBSEQUENT_DNS_CHALLENGE_INSTRUCTIONSr"_SUBSEQUENT_CHALLENGE_INSTRUCTIONS_DNS_VERIFY_INSTRUCTIONS display_utilZ notification)r r:rWr_msgr#r#r$rTs2       z&Authenticator._perform_achall_manuallycCs^|drP|D]@}|j|}d|vr4tjddtj||d|jq|j dS)Nr(r^) r+rrdrrcrerfrOr r)r rQr:rr#r#r$cleanups   zAuthenticator.cleanup) hook_name achall_domainrcCsJtj||||td\}}}td|d||||||fS)N)rzHook '--manual-z' for )rZexecute_command_statusr-r+rZenv_no_snap_for_external_calls display_opsZreport_executed_command)r rurv returncodeerrrir#r#r$rfs zAuthenticator._execute_hook)F)'__name__ __module__ __qualname____doc__ descriptionZhiddenZlong_descriptionrnrqrmrprorr classmethodrr*r0r.r`r4rr ZAnnotatedChallengerNrr rGrPrZChallengeResponserYrSrHrTrtrrf __classcell__r#r#r!r$rs<  %    r)$r}ZloggingtypingrrrrrrrZacmer rDr r r r rZcertbot._internalrZcertbot._internal.clirZcertbot.compatrrZcertbot.displayrrwrrZcertbot.pluginsrZ getLoggerrzloggerZPluginrr#r#r#r$s.