a }|gp>@sdZddlZddlZddlZddlZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z dd lm Z dd lm Z dd lmZdd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z!ddl"m#Z#ddl"m Z ddl$m%Z%e&e'Z(dZ)ddgZ*Gddde#j+ej,Z,Gdd d ej-Z.Gd!d"d"ej-Z/e0e0d#d$d%Z1dS)&zWebroot plugin.N)Any)Callable) DefaultDict)Dict)Iterable)List)Optional)Sequence)Set)Type)Union) challenges) crypto_util)errors) interfaces)cli)AnnotatedChallenge) filesystem)os)ops)util)common) safe_opena! Z@20c5ca1bd58fa8ad5f07a2f1be8b7cbb707c20fcb607a8fc8db9393952846a97Z@8d31383d3a079d2098a9d0c0921f4ab87e708b9868dc3f314d54094c2fe70336csTeZdZdZdZdZedddZee ddd d d Z e e ed d dZ eeeejdddZeeddfdd ZddddZe e e ejdddZee ddddZee eeedddZee eeeddd Zd/eeeed"d#d$Zddd%d&Zee ed'd(d)Ze ejd*d+d,Z e e ddd-d.Z!Z"S)0 AuthenticatorzWebroot Authenticator.zSaves the necessary validation files to a .well-known/acme-challenge/ directory within the nominated webroot path. A separate HTTP server must be running and serving files from the webroot path. HTTP challenge only (wildcards not supported).zAuthenticator plugin that performs http-01 challenge by saving necessary validation resources to appropriate paths on the file system. It expects that there is some other HTTP server configured to serve all files under specified web root ({0}).)returncCs|j|dS)Npath) MORE_INFOformatconfselfr!E/usr/lib/python3.9/site-packages/certbot/_internal/plugins/webroot.py more_infoFszAuthenticator.more_info).NN)addrcCs&|ddgtdd|ditdddS)Nrz-wapublic_html / webroot path. This can be specified multiple times to handle different domains; each domain will have the webroot path that preceded it. For instance: `-w /var/www/example -d example.com -d www.example.com -w /var/www/thing -d thing.net -d m.thing.net` (default: Ask))defaultactionhelpmapaJSON dictionary mapping domains to webroot paths; this implies -d for each entry. You may need to escape this from your shell. E.g.: --webroot-map '{"eg1.is,m.eg1.is":"/www/eg1/", "eg2.is":"/www/eg2"}' This option is merged with, but takes precedence over, -w / -d entries. At present, if you put webroot-map in a config file, it needs to be on a single line, like: webroot-map = {"example.com":"/var/www"}.)_WebrootPathAction_WebrootMapAction)clsr$r!r!r"add_parser_argumentsIs  z"Authenticator.add_parser_arguments)failed_achallsrcCsdS)NzThe Certificate Authority failed to download the temporary challenge files created by Certbot. Ensure that the listed domains serve their content from the provided --webroot-path/-w and that files created there can be downloaded from the internet.r!)r r-r!r!r" auth_hint[szAuthenticator.auth_hint)domainrcCstjgSN)r HTTP01)r r/r!r!r"get_chall_prefaszAuthenticator.get_chall_prefargskwargsrcs.tj|i|i|_tt|_g|_dSr0)super__init__ full_roots collections defaultdictset performed _created_dirsr r4r5 __class__r!r"r7es zAuthenticator.__init__cCsdSr0r!rr!r!r"preparelszAuthenticator.prepare)achallsrcs$|fdd|DS)Ncsg|]}|qSr!)_perform_single).0achallrr!r" tz)Authenticator.perform..) _set_webroots_create_challenge_dirs)r rBr!rr"performos zAuthenticator.performc Cs|drD|dd}td||D]}|d|j|q(n|tt|d}|D]`}|j|dvr^||j|}z| |Wnt yYn0| d|||d|j<q^dS)Nrz4Using the webroot path %s for all unmatched domains.r(r) rloggerinfo setdefaultr/listr;values_prompt_for_webrootremove ValueErrorinsert)r rB webroot_pathrEknown_webrootsZ new_webrootr!r!r"rHvs&   zAuthenticator._set_webroots)r/rVrcCsBd}|dur>|r0|||}|dur<||}q||d}q|S)NT)_prompt_with_webroot_list_prompt_for_new_webroot)r r/rVwebrootr!r!r"rQs  z!Authenticator._prompt_for_webrootcCs\d|d}tjd|dg||dd\}}|tjkrDtd|dkrPdS||d S) Nz--rzSelect the webroot for {0}:zEnter a new webrootT)Zcli_flagforce_interactiveIEvery requested domain must have a webroot when using the webroot plugin.r)Z option_name display_utilZmenurCANCELr PluginError)r r/rVZ path_flagcodeindexr!r!r"rWs  z'Authenticator._prompt_with_webroot_listF)r/ allowraisercCs>tjtd|dd\}}|tjkr6|s,dStdt|S)NzInput the webroot for {0}:T)rZr[)rZvalidated_directory_validate_webrootrr]r^rr_)r r/rbr`rYr!r!r"rXs  z%Authenticator._prompt_for_new_webrootc Cs|d}|std|D]\}}tj|tjtj j |j |<t d|j |tdtt|j |ddtdD]}tj|rqzvt|d|j|ztj||dddd Wn@ttfy }z"t d t d |WYd}~n d}~00WqtyH}ztd ||WYd}~qd}~00qWdn1sb0Ytjs tj|j |d }tj|rt d|j |q t d|j |t |ddd}|!t"Wdq 1s0Yq dS)Nr(zMissing parts of webroot configuration; please set either --webroot-path and --domains, or --webroot-map. Run with --help webroot for examples.z-Creating root challenges validation dir at %srK)keyiT)Z copy_userZ copy_groupz3Unable to change owner and uid of webroot directory Error was: %sz=Couldn't create root for {0} http-01 challenge responses: {1} web.configzPA web.config file has not been created in %s because another one already exists.zGCreating a web.config file in %s to allow IIS to serve challenge files.wmodechmod)#rrr_itemsrrjoinnormcaser r1Z URI_ROOT_PATHr8rLdebugr temp_umasksortedrZ get_prefixeslenisdirmkdirr=appendZcopy_ownership_and_apply_modeOSErrorAttributeErrorZwarningr POSIX_MODEexistsrMrwrite_WEB_CONFIG_CONTENT)r Zpath_mapnamerprefix exceptionweb_config_pathZ web_configr!r!r"rIsX   $     &<z$Authenticator._create_challenge_dirs) root_pathrErcCstj||jdS)Ntoken)rrrnZchallencode)r rrEr!r!r"_get_validation_pathsz"Authenticator._get_validation_path)rErc Cs|\}}|j|j}|||}td|tdLt|ddd}| | Wdn1sn0YWdn1s0Y|j | ||S)Nz#Attempting to save validation to %srdwbrirj) Zresponse_and_validationr8r/rrLrprrqrr{rr<r$)r rEZresponseZ validationrvalidation_pathZvalidation_filer!r!r"rCs     JzAuthenticator._perform_singlec Cs0|D]}|j|jd}|dur|||}td|t||j||t j stj |d}tj |rt|}|tvrtd|t|qtd|qg}|jr|j}zt|Wqty} z0|d|td|td| WYd} ~ qd} ~ 00q||_tddS) Nz Removing %srgz4Cleaning web.config file generated by Certbot in %s.zQNot cleaning up the web.config file in %s because it is not generated by Certbot.rz3Challenge directory %s was not empty, didn't removerfzAll challenges cleaned up)r8getr/rrLrprrRr<rryrrnrzr sha256sum_WEB_CONFIG_SHA256SUMSrMr=poprmdirrwrT) r rBrErrrrZ not_removedrexcr!r!r"cleanups<         $zAuthenticator.cleanup)F)#__name__ __module__ __qualname____doc__ descriptionrstrr# classmethodrr,rrr.rr r Z Challenger2rr7rAZChallengeResponserJrHrrQrWboolrXrIrrCr __classcell__r!r!r?r"r8s*  7rc@s>eZdZdZdejejeee e dfe eddddZ dS)r*z%Action class for parsing webroot_map.N)parser namespace webroot_map option_stringrcsV|dur dStt|D]2\}t|jfddt||DqdS)Nc3s|]}|fVqdSr0r!)rDdrUr!r" ,sz-_WebrootMapAction.__call__..) jsonloadsrrmrcrupdaterZ add_domains)r rrrrdomainsr!rr"__call__%s z_WebrootMapAction.__call__)N) rrrrargparseArgumentParser Namespacer rr rrrr!r!r!r"r*"s  r*csXeZdZdZeeddfdd Zd ejeje e e edfe e ddddZ ZS) r)z&Action class for parsing webroot_path.Nr3cstj|i|d|_dS)NF)r6r7_domain_before_webrootr>r?r!r"r73sz_WebrootPathAction.__init__)rrrUrrcCsl|dur dS|jrtd|jrH|jd}|jD]}|j||q2n |jrTd|_|jtt |dS)NzPIf you specify multiple webroot paths, one of them must precede all domain flagsrKT) rrr_rUrrrNrvrcr)r rrrUrZ prev_webrootr/r!r!r"r7s  z_WebrootPathAction.__call__)N)rrrrrr7rrrr rr rrrr!r!r?r"r)0s r))rUrcCs&tj|st|dtj|S)zValidates and returns the absolute path of webroot_path. :param str webroot_path: path to the webroot directory :returns: absolute path of webroot_path :rtype: str z% does not exist or is not a directory)rrrtrr_abspathrr!r!r"rcMs rc)2rrr9rZloggingtypingrrrrrrrr r r r Zacmer ZcertbotrrrZcertbot._internalrZcertbot.achallengesrZcertbot.compatrrZcertbot.displayrrr]Zcertbot.pluginsrZ certbot.utilrZ getLoggerrrLr|rZPluginrActionr*r)rrcr!r!r!r"sL                         k