a ‚oe¾.ã@s dZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z dd l mZdd l mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZe e ¡Z!Gdd„dej"ej#ƒZ#dS)zManual authenticator pluginéN)Ú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 dœdd„ƒZd dœdd„Zd dœdd„Zedœdd„Zeejedœdd„Zeeeejdœdd„Zeejeejdœd d!„Zejeejd d"œd#d$„Z d.eje!d d&œd'd(„Z"eejd dœd)d*„Z#eee$eefd+œd,d-„Z%‡Z&S)/Ú AuthenticatorzÔManual 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 scriptsTašAuthenticate 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)ÚargsÚkwargsÚreturncs@tƒj|i|¤Žt |j¡|_|j ¡i|_d|_d|_dS)NF) ÚsuperÚ__init__r ZReverterÚconfigÚrecovery_routineÚenvÚsubsequent_dns_challengeÚsubsequent_any_challenge)Úselfrr©Ú __class__©úAC:\Program Files\Certbot\pkgs\certbot\_internal\plugins\manual.pyras  zAuthenticator.__init__).N)ÚaddrcCs*|ddd�|ddd�t |dd¡dS)Nú auth-hookz8Path or command to execute for the authentication script)Úhelpú cleanup-hookz1Path or command to execute for the cleanup scriptzpublic-ip-logging-okr)rZadd_deprecated_argument)Úclsr%r#r#r$Úadd_parser_argumentsisÿÿz"Authenticator.add_parser_arguments)rcCs4|jjr(| d¡s(t d | d¡¡¡‚| ¡dS)Nr&zdAn authentication script must be provided with --{0} when using the manual plugin non-interactively.)rZnoninteractive_modeÚconfr Z PluginErrorÚformatÚ option_nameÚ_validate_hooks©r r#r#r$ÚprepareqsþÿzAuthenticator.preparecCsL|jjrHdD]:}| |¡}|dur | |¡dtdƒ …}t ||¡q dS)N)r&r(z-hook)rZvalidate_hooksr+r-ÚlenrZ validate_hook)r ÚnameÚhookZ hook_prefixr#r#r$r.ys  zAuthenticator._validate_hookscCsdS)Nz¦This 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_info�sÿzAuthenticator.more_info)Úfailed_achallsrcs˜ttjtdœ‡fdd„ ‰ˆtjƒ}tjdtjdtjdi}d t‡fdd „|  ¡Dƒƒ¡}|  d ¡r~d j t j ||rvd nd d�Sdj ||rŒdnd d�SdS)N)r)rcst‡fdd„ˆDƒƒS)Nc3s|]}t|jˆƒVqdS©N)Ú isinstanceÚchall)Ú.0Úachall©r)r#r$Ú ‰óz=Authenticator.auth_hint..has_chall..)Úanyr;)r5r;r$Ú has_challˆsz*Authenticator.auth_hint..has_challzDNS TXT recordszchallenge fileszTLS-ALPN certificatesz and csg|]\}}ˆ|ƒr|‘qSr#r#)r9ÚkÚv)r?r#r$Ú ‘r=z+Authenticator.auth_hint..r&zÖThe 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Ú resourcesÚdns_hintz�The 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 Ú ChallengeÚboolÚDNS01ÚHTTP01Z TLSALPN01ÚjoinÚsortedÚitemsr+r,rZ cli_command)r r5Zhas_dnsZresource_namesrEr#)r5r?r$Ú auth_hint‡s6 ý  þÿøÿþÿúÿzAuthenticator.auth_hint)ÚdomainrcCs tjtjgSr6)r rJrI)r rOr#r#r$Úget_chall_pref¬szAuthenticator.get_chall_pref)ÚachallsrcCs|g}d}t|ƒD]\}}t|jtjƒr|}qt|ƒD]B\}}| d¡rT| ||¡n| |||k¡| |  |j ¡¡q4|S)Nrr&) Ú enumerater7r8r rIr+Ú_perform_achall_with_scriptÚ_perform_achall_manuallyÚappendZresponseÚ account_key)r rQZ responsesÚlast_dns_achallÚir:r#r#r$Úperform°s zAuthenticator.perform)r:rQrcCs¤|j| |j¡d dd„|Dƒ¡tt|ƒ| |¡dƒdœ}t|jt j ƒr^|j  d¡|d<nt j  dd¡t j  |¡| d|j¡\}}| ¡|d <||j|<dS) Nú,css|] }|jVqdSr6©rO)r9Z one_achallr#r#r$r<Är=z.é)ZCERTBOT_DOMAINZCERTBOT_VALIDATIONZCERTBOT_ALL_DOMAINSZCERTBOT_REMAINING_CHALLENGESÚtokenÚ CERTBOT_TOKENr&ZCERTBOT_AUTH_OUTPUT)rOÚ validationrVrKÚstrr1Úindexr7r8r rJÚencoderÚenvironÚpopÚupdateÚ _execute_hookÚstripr)r r:rQrÚ_Úoutr#r#r$rS¿s ü  z)Authenticator._perform_achall_with_scriptF)r:rWrcCsò| |j¡}t|jtjƒrH|jj||j d¡|j j |j  |j ¡|d�}n*t|jtj ƒsZJ‚|jj| |j ¡|d�}t|jtj ƒrÈ|jr’||j7}n|jr¢||j7}d|_|rØ||jj| |j ¡d�7}n|jrØ||j7}tj|ddd�d|_dS)Nr])r:Z encoded_tokenÚportÚurir_)rOr_Tr[F)ÚwrapZforce_interactive)r_rVr7r8r rJÚ_HTTP_INSTRUCTIONSr,rbrZ http01_portrkrOrIÚ_DNS_INSTRUCTIONSZvalidation_domain_namerÚ&_SUBSEQUENT_DNS_CHALLENGE_INSTRUCTIONSrÚ"_SUBSEQUENT_CHALLENGE_INSTRUCTIONSÚ_DNS_VERIFY_INSTRUCTIONSÚ display_utilZ notification)r r:rWr_Úmsgr#r#r$rTÐs4  ý þ   ÿ  z&Authenticator._perform_achall_manuallycCs^| d¡rP|D]@}|j |¡}d|vr4tj dd¡tj |¡| d|j¡q|j  ¡dS)Nr(r^) r+rrdrrcrerfrOr r)r rQr:rr#r#r$Úcleanupðs   zAuthenticator.cleanup)Ú hook_nameÚ achall_domainrcCsJtj| |¡| |¡t ¡d�\}}}t d|›d|›�|||¡||fS)N)rzHook '--manual-z' for )rZexecute_command_statusr-r+rZenv_no_snap_for_external_callsÚ display_opsZreport_executed_command)r rurvÚ returncodeÚerrrir#r#r$rfúsþ ÿzAuthenticator._execute_hook)F)'Ú__name__Ú __module__Ú __qualname__Ú__doc__Ú descriptionZhiddenZlong_descriptionrnrqrmrprorrÚ classmethodrr*r0r.r`r4rr ZAnnotatedChallengerNrr rGrPrZChallengeResponserYrSrHrTrtrrfÚ __classcell__r#r#r!r$rs<ÿ  %ÿ  ÿ ÿÿ  r)$r}ZloggingÚtypingrrrrrrrZacmer rDr r r r rZcertbot._internalrZcertbot._internal.clirZcertbot.compatrrZcertbot.displayrrwrrZcertbot.pluginsrZ getLoggerrzÚloggerZPluginrr#r#r#r$Ús.