3 گa.@s dZddlZddlmZddlmZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z dd l mZdd l mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZeje 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 eed.d 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)0 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||tj|j|_|jji|_d|_d|_dS)NF) super__init__r ZReverterconfigrecovery_routineenvsubsequent_dns_challengesubsequent_any_challenge)selfrr) __class__/usr/lib/python3.6/manual.pyras  zAuthenticator.__init__.)addrcCs*|ddd|dddtj|dddS)Nz auth-hookz8Path or command to execute for the authentication script)helpz 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)rcCs6|jjr*|jd r*tjdj|jd|jdS)Nz auth-hookzdAn authentication script must be provided with --{0} when using the manual plugin non-interactively.)rZnoninteractive_modeconfr Z PluginErrorformat option_name_validate_hooks)r r"r"r#prepareqs zAuthenticator.preparecCsP|jjrLxBdD]:}|j|}|dk r|j|dtd }tj||qWdS)N auth-hook cleanup-hookz-hook)r-r.)rZvalidate_hooksr(r*lenrZ validate_hook)r namehookZ hook_prefixr"r"r#r+ys   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_achallsrcsfddtj}tjdtjdtjdi}djtfdd|jD}|jd rpd jt j ||rhd nd d Sdj||r~dnd dSdS)NcstfddDS)Nc3s|]}t|jVqdS)N) isinstancechall).0achall)r&r"r# sz...)any)r&)r3)r&r#sz)Authenticator.auth_hint..zDNS TXT recordszchallenge fileszTLS-ALPN certificatesz and csg|]\}}|r|qSr"r")r6kv) has_challr"r# sz+Authenticator.auth_hint..z auth-hookzThe 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)rArB) r DNS01HTTP01Z TLSALPN01joinsorteditemsr(r)rZ cli_command)r r3Zhas_dnsZresource_namesrAr")r3r=r# auth_hints     zAuthenticator.auth_hint)domainrcCs tjtjgS)N)r rDrC)r rIr"r"r#get_chall_prefszAuthenticator.get_chall_pref)achallsrcCsg}d}x&t|D]\}}t|jtjr|}qWxNt|D]B\}}|jdrZ|j||n|j|||k|j|j |j q:W|S)Nrz auth-hook) enumerater4r5r rCr(_perform_achall_with_script_perform_achall_manuallyappendZresponse account_key)r rKZ responseslast_dns_achallir7r"r"r#performs zAuthenticator.perform)r7rKrcCst|j|j|jdjdd|Dtt||j|dd}t|j t j r`|j j d|d<nt jjddt jj||jd|j\}}|j|d <||j|<dS) N,css|] }|jVqdS)N)rI)r6Z one_achallr"r"r#r8sz.)ZCERTBOT_DOMAINZCERTBOT_VALIDATIONZCERTBOT_ALL_DOMAINSZCERTBOT_REMAINING_CHALLENGEStoken CERTBOT_TOKENz auth-hookZCERTBOT_AUTH_OUTPUT)dictrI validationrPrEstrr/indexr4r5r rDencoderenvironpopupdate _execute_hookstripr)r r7rKr_outr"r"r#rMs   z)Authenticator._perform_achall_with_scriptF)r7rQrcCs|j|j}t|jtjrH|jj||jjd|j j |jj |j |d}n|j j|j|j |d}t|jtjr|jr||j7}n|jr||j7}d|_|r||jj|j|j d7}n|jr||j7}tj|dddd|_dS)NrV)r7Z encoded_tokenZporturirY)rIrYT)rIF)ZwrapZforce_interactive)rYrPr4r5r rD_HTTP_INSTRUCTIONSr)r\rZ http01_portrdrI_DNS_INSTRUCTIONSZvalidation_domain_namerCr&_SUBSEQUENT_DNS_CHALLENGE_INSTRUCTIONSr"_SUBSEQUENT_CHALLENGE_INSTRUCTIONS_DNS_VERIFY_INSTRUCTIONS display_utilZ notification)r r7rQrYmsgr"r"r#rNs,      z&Authenticator._perform_achall_manuallycCsb|jdrTxH|D]@}|jj|}d|kr6tjjddtjj||jd|jqW|jj dS)Nz cleanup-hookrW) r(rr^rr]r_r`rIr r)r rKr7rr"r"r#cleanups    zAuthenticator.cleanup) hook_name achall_domainrcCsJtj|j||j|tjd\}}}tjd|d||||||fS)N)rzHook '--manual-z' for )rZexecute_command_statusr*r(rZenv_no_snap_for_external_calls display_opsZreport_executed_command)r rmrn returncodeerrrcr"r"r#r`s zAuthenticator._execute_hook).N)F)'__name__ __module__ __qualname____doc__ descriptionZhiddenZlong_descriptionrfrirerhrgrr classmethodrr'r,r+rZr2rr ZAnnotatedChallengerHrr Z ChallengerJrZChallengeResponserSrMboolrNrlrr` __classcell__r"r")r!r#rs0 $ r)$ruZloggingZtypingrrrrrrrZacmer r@r r r r rZcertbot._internalrZcertbot._internal.clirZcertbot.compatrrZcertbot.displayrrorjZcertbot.pluginsrZ getLoggerrrZloggerZPluginrr"r"r"r#s.