Spade
Mini Shell
| Directory:~$ /proc/self/root/lib/python2.7/site-packages/certbot/_internal/ |
| [Home] [System Details] [Kill Me] |
�
���_c@s\dZddlZddlZddlZddlmZddlmZddlZ ddl
Z
ddlZddl
mZddl
mZddl
mZddl
mZdd lmZdd
lmZddlZddlmZddlmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlm
Z
ddlm!Z!ddlm"Z"ddl#m$Z%ddl&m'Z'ddl(m)Z*ej+e,�Z-e.d�Z/d�Z0d�Z1de2fd��YZ3d�Z4e.d�Z5d�Z6de2fd
��YZ7e.d!�Z8d"�Z9d#�Z:d$�Z;dS(%sCertbot client
API.i����N(tdefault_backend(tgenerate_private_key(tclient(tcrypto_util(terrors(tmessages(tList(tOptional(t
interfaces(tutil(taccount(tauth_handler(tcli(t constants(teff(t
error_handler(tstorage(t selection(tos(topsc CsAtj|d|d|jdt|��}tj|||j�S(s
Wrangle ACME client constructionR
t
verify_sslt
user_agent(tacme_clientt
ClientNetworkt
no_verify_ssltdetermine_user_agenttBackwardsCompatibleClientV2tserver(tconfigtkeytregrtnet((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytacme_from_config_key&scCs�|jd kr�d}tjjd�dkrBd}d}d}n!tj}tj�}t j
�}|jtj
|||j|j|jt|�||jr�d|jnd� }n |j}|S(
s�
Set a user_agent string in the config based on the choice of plugins.
(this wasn't knowable at construction time)
:returns: the client's User-Agent string
:rtype: `str`
s\CertbotACMEClient/{0} ({1}; {2}{8}) Authenticator/{3} Installer/{4}
({5}; flags: {6}) Py/{7}tCERTBOT_DOCSt1scertbot(-auto)sOS_NAME
OS_VERSIONsmajor.minor.patchlevels;
tN(RtNoneRtenvirontgetRtcli_commandR tget_os_info_uatplatformtpython_versiontformattcertbott__version__t
authenticatort installertverbtua_flagstuser_agent_comment(RtuaR'tos_infoR*((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR.s " cCs�t|t�rdSg}|jr2|jd�n|jrK|jd�n|jrd|jd�n|jr}|jd�nd}g|D]}t||d�^q�}t|�r�|jd�nd
j |�S(s@Turn
some very important CLI flags into clues in the user
agent.tFLAGStduptfrntasntntpretposttrenewtmanual_authtmanual_cleanupt_hookthookt
(R:R;R<R=R>(
t
isinstancetDummyConfigt duplicatetappendtrenew_by_defaulttallow_subset_of_namestnoninteractive_modetgetattrtanytjoin(Rtflagst
hook_namesththooks((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR1Ms
&RCcBs
eZdZd�Zd�ZRS(s'Shim for computing a sample user
agent.cCs(d|_d|_d|_d|_dS(NtXXXtYYYt
SUBCOMMAND(R.R/R$RR0(tself((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyt__init__bs cCsdS(s-Any
config properties we might have are
None.N(R$(RStname((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyt__getattr__hs(t__name__t
__module__t__doc__RTRV(((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyRC`s cCs
tt��S(s<Document
what this Certbot's user agent string will be
like.(RRC(((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytsample_user_agentlsc Cs)|j�r"tjd|j�n|jd kr{|js_d}tj|�tj |��n|j
s{tjd�q{n|j
r�d |_ntddd|j
dt��}tjdtj|��}t||�}t|||�}tj||�}|j||�tj||�||fS(
s�Register new account with an ACME CA.
This function takes care of generating fresh private key,
registering the account, optionally accepting CA Terms of Service
and finally saving the account. It should be called prior to
initialization of `Client`, unless account has already been created.
:param .IConfig config: Client configuration.
:param .AccountStorage account_storage: Account storage where newly
registered account will be saved to. Save happens only after TOS
acceptance step, so any account private keys or
`.RegistrationResource` will not be persisted if `tos_cb`
returns ``False``.
:param tos_cb: If ACME CA requires the user to accept a Terms of
Service before registering account, client action is
necessary. For example, a CLI tool would prompt the user
acceptance. `tos_cb` must be a callable that should accept
`.RegistrationResource` and return a `bool`: ``True`` iff the
Terms of Service present in the contained
`.Registration.terms_of_service` is accepted by the client, and
``False`` otherwise. ``tos_cb`` will be called only if the
client action is necessary, i.e. when ``terms_of_service is not
None``. This argument is optional, if not supplied it will
default to automatic acceptance!
:raises certbot.errors.Error: In case of any client problems, in
particular registration failure, or unaccepted Terms of Service.
:raises acme.errors.Error: In case of any protocol problems.
:returns: Newly registered and saved account, as well as protocol
API handle (should be used in `Client` initialization).
:rtype: `tuple` of `.Account` and `acme.client.Client`
s*There are already existing accounts for %ssLNo email was provided and
--register-unsafely-without-email was not present.sRegistering without
email!tpublic_exponentitkey_sizetbackendRN(tfind_alltloggertinfoRtemailR$tregister_unsafely_without_emailtwarningRtErrortdry_runtdebugRtrsa_key_sizeRtjosetJWKRSAtComparableRSAKeyR
tperform_registrationR
tAccounttsaveRtprepare_subscription( Rtaccount_storagettos_cbtmsgtrsa_keyRtacmeRtacc((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytregisterrs,&
c
CsS|jo|j}|rc|jjjj�}tjjd|d|jd|jd|jj �}nd}|j�r�|s�d}tj
|��q�ny2tjjd|jd|�}|j||�SWn�tj
k
rN}|jdks�|jd krH|jr#d
|j}tj
|��ntjdt�|_t|||�S�nXdS(
sj
Actually register new account, trying repeatedly if there are email
problems
:param acme.client.Client client: ACME client object.
:param .IConfig config: Client configuration.
:param Callable tos_cb: a callback to handle Term of Service agreement.
:returns: Registration Resource.
:rtype: `acme.messages.RegistrationResource`
taccount_public_keytkidthmac_keyt directorysRServer requires
external account binding. Please use --eab-kid and
--eab-hmac-key.Ratexternal_account_bindingtinvalidEmailtinvalidContactszThe
ACME server believes %s is an invalid email address. Please ensure it is a
valid email and attempt registration
again.tinvalidN(teab_kidteab_hmac_keyRRRt
public_keyRtExternalAccountBindingt from_dataRyR$texternal_account_requiredRRdtNewRegistrationRatnew_account_and_tostcodeRHtdisplay_opst get_emailtTrueRk( RsRRpteab_credentials_suppliedRvteabRqtnewregte((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyRk�s2
tClientcBs�eZdZd
d�Zd
d�Zd
d�Zd�Zd�Zd�Z d�Z
d�Zed �Z
d
d
�Zd�Zd�ZRS(sqCertbot's client.
:ivar .IConfig config: Client configuration.
:ivar .Account account: Account registered with `register`.
:ivar .AuthHandler auth_handler: Authorizations handler that will
dispatch DV challenges to appropriate authenticators
(providing `.IAuthenticator` interface).
:ivar .IAuthenticator auth: Prepared (`.IAuthenticator.prepare`)
authenticator that can solve ACME challenges.
:ivar .IInstaller installer: Installer.
:ivar acme.client.BackwardsCompatibleClientV2 acme: Optional ACME
client API handle. You might already have one from `register`.
cCs�||_||_||_||_|dkr`|jdk r`t||jj|jj�}n||_|dk r�t j
||j|j|jj�|_ n d|_ dS(sInitialize a client.N(RR
tauthR/R$R
RRRsRtAuthHandlertpref_challs(RSRtaccount_R�R/Rs((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyRT�s ! $c CsM|jdkr4d}tj|�tj|��n|jjdkrXtjd��ntjd|�|dkr�|j |j
dt�}ntjj
�tjdd�}|jjdk }|jj||d|�}|j}|r"|jr"tj|g|j|jj|jj�}ntj|�\}}|j�|j�fS( sWObtain
certificate.
:param .util.CSR csr: PEM-encoded Certificate Signing
Request. The key used to generate this CSR can be different
than `authkey`.
:param acme.messages.OrderResource orderr: contains authzrs
:returns: certificate and chain as PEM byte strings
:rtype: tuple
s>Unable to obtain certificate because authenticator is not
set.s+Please register with the ACME server first.sCSR:
%stbest_efforttsecondsiZtfetch_alternative_chainsN(RR$R_RcRRdR
RRft_get_order_and_authorizationstdatatFalsetdatetimetnowt timedeltaRtpreferred_chainRstfinalize_ordert
fullchain_pemtalternative_fullchains_pemRtfind_chain_with_issuerRetcert_and_chain_from_fullchaintencode( RStcsrtorderrRqtdeadlinetget_alt_chainst fullchaintcerttchain((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytobtain_certificate_from_csrs*
cCs�|dk rat|d��}|}|j�}WdQXtjd|d|�}tjd|�nd}|jj}d}t |jj
t�r�|jj
d|j_
n|jjr�|jj
dkr�|jj}d|j_
d |j_d
|j_n3|jjr+|jj
j�dkr+|jj}n|jjr�|pptjdddtjd|d
|d|jj
��}tjdddddtj|j||jj��} nQ|p�tjd|d|jjd|jj
d
|�}tj|||jj�} |j| j|jj�}
|
j
}t!d�|D��}g|D]}
|
|kr>|
^q>}|jjr�||kr�|jjs�t"j#|j$�t"j#| j$�n|j%|�S|j&| |
�\}}|||| fSdS(s�Obtains a certificate from the ACME server.
`.register` must be called before `.obtain_certificate`
:param list domains: domains to get a certificate
:returns: certificate as PEM string, chain as PEM string,
newly generated private key (`.util.Key`), and DER-encoded
Certificate Signing Request (`.util.CSR`).
:rtype: tuple
trbNtfiletpems%Reusing existing private key from
%s.itecdsas./chain-ecdsa.pems./cert-ecdsa.pems./key-ecdsa.pemtrsatbitstelliptic_curvetkey_typetformR�R\tkey_dircss|]}|jjjVqdS(N(tbodyt
identifiertvalue(t.0ta((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pys <genexpr>xs('R$topentreadR tKeyR_R`RRgRBR�tlistR�tauth_chain_pathtauth_cert_pathtkey_pathtlowerReRtmake_keytCSRtacme_crypto_utiltmake_csrR�tmust_staplet
init_save_keyR�t
init_save_csrtcsr_dirR�R�RGtauthorizationstsetRtremoveR�tobtain_certificateR�(RStdomainstold_keypathtftkeypathtkeypemRR\R�R�R�tauthzrtauth_domainstdtsuccessful_domainsR�R�((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR�.sZ$ %
cCs�y|jj|�}Wn#tjk
r;tjd��nX|r�|jjr�|jj |�\}}|r�t
jd�|jj|�}n|r�t
jd�q�n|jj
||�}|jd|�S(s`Request a new order and
complete its authorizations.
:param str csr_pem: A CSR in PEM format.
:param bool best_effort: True if failing to complete all
authorizations should not raise an exception
:returns: order resource containing its completed authorizations
:rtype: acme.messages.OrderResource
sWThe currently selected ACME CA endpoint does not support issuing
wildcard certificates.s*Recreating order after authz deactivationssCertbot
was unable to obtain fresh authorizations for every domain. The dry run
will continue, but results may not be
accurate.R�(Rst new_ordertacme_errorstWildcardUnsupportedErrorRRdRReRtdeactivate_valid_authorizationsR_RfRcthandle_authorizationstupdate(RStcsr_pemR�R�tdeactivatedtfailedR�((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR��s
cCs�|j|�\}}}}|jjtjdksM|jjtjdkr]tjd�n|j||�}|jj r�tj
d|�dStj
j|||j||j�S(s{Obtain and enroll certificate.
Get a new certificate for the specified domains using the specified
authenticator and installer, and then create a new renewable
lineage
containing it.
:param domains: domains to request a certificate for
:type domains: `list` of `str`
:param certname: requested name of lineage
:type certname: `str` or `None`
:returns: A new :class:`certbot._internal.storage.RenewableCert`
instance
referred to the enrolled cert lineage, False if the cert could
not
be obtained, or None if doing a successful dry run.
t
config_dirtwork_dirsdNon-standard path(s), might not work with crontab
installed by your operating system package managers-Dry run: Skipping
creating new lineage for
%sN(R�RR�R
tCLI_DEFAULTSR�R_R`t_choose_lineagenameReRfR$Rt
RenewableCerttnew_lineageR�(RSR�tcertnameR�R�Rt_tnew_name((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytobtain_and_enroll_certificate�s
cCs1|r
|Stj|d�r)|ddS|dS(s/Chooses a name for the new lineage.
:param domains: domains in certificate request
:type domains: `list` of `str`
:param certname: requested name of lineage
:type certname: `str` or `None`
:returns: lineage name that should be used
:rtype: str
ii(R tis_wildcard_domain(RSR�R�((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR��s
c
Cs�x<|||fD]+}tjtjj|�d|jj�qWtd|�\}}z|j|�Wd|j �Xt
jd|�td|�\} }
td|�\}}t|| �t|||�||
|fS(s Saves the certificate received from the ACME server.
:param str cert_pem:
:param str chain_pem:
:param str cert_path: Candidate path to a certificate.
:param str chain_path: Candidate path to a certificate chain.
:param str fullchain_path: Candidate path to a full cert chain.
:returns: cert_path, chain_path, and fullchain_path as absolute
paths to the actual files
:rtype: `tuple` of `str`
:raises IOError: If unable to find room to write the cert files
i�t cert_pathNs4Server issued certificate; certificate written
to %st
chain_pathtfullchain_path(
R tmake_or_verify_dirRtpathtdirnameRtstrict_permissionst_open_pem_filetwritetcloseR_R`t_save_chain(
RStcert_pemt chain_pemR�R�R�R�t cert_filet
abs_cert_patht
chain_filetabs_chain_pathtfullchain_filetabs_fullchain_path((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytsave_certificate�s)
cCs|jd
kr.tjd�tjd��n|d
kr@d
ntjj|�}d}t j
|j|��vx^|D]V}|jjd|dtjj|�dtjj|�d|d|�|jj
�quW|jj
d �Wd
QXd}t j
|j|��|jj�Wd
QXd
S(sInstall certificate
:param list domains: list of domains to install the certificate
:param str privkey_path: path to certificate private key
:param str cert_path: certificate file path (optional)
:param str chain_path: chain file path
sANo installer specified, client is unable to deploythe
certificatesNo installer availables!Unable to install the
certificatetdomainR�R�R�R�sDeployed ACME CertificateNsuWe were
unable to install your certificate, however, we successfully restored your
server to its prior
configuration.(R/R$R_RcRRdRR�tabspathRtErrorHandlert_recovery_routine_with_msgtdeploy_certRmt_rollback_and_restarttrestart(RSR�tprivkey_pathR�R�R�Rqtdom((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytdeploy_certificates"
$
cCs1|jd
kr.tjd�tjd��nt}dddd|fdf}|jj�}x�|D]�\}}} t|j |�}
||kr�|dkr�|
d
kr�|}
n|
r�|j
||| �t}q�qe|
retjd|�qeqeWd}|r-tj
|j|��|jj�Wd
QXnd
S(sfEnhance
the configuration.
:param list domains: list of domains to configure
:param chain_path: chain file path
:type chain_path: `str` or `None`
:param redirect_default: boolean value that the
"redirect" flag should default to
:raises .errors.Error: if no installer is specified in the
client.
sDNo installer is specified, there isn't any configuration to
enhance.sNo installer
availablethstssensure-http-headersStrict-Transport-Securitytredirecttstaplesstaple-ocsptuirsUpgrade-Insecure-RequestssKOption
%s is not supported by the selected installer. Skipping enhancement.s$We
were unable to restart web
serverN(R sensure-http-headersStrict-Transport-Security(R
R
N(Rsensure-http-headersUpgrade-Insecure-Requests(R/R$R_RcRRdR�tsupported_enhancementsRIRtapply_enhancementR�RRRR(RSR�R�tredirect_defaulttenhancedtenhancement_infot supportedtconfig_nametenhancement_nametoptiontconfig_valueRq((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytenhance_config+s2
c
Cs�d|}tj|j|���x�|D]�}y|jj|||�Wq'tjk
r�|dkrytjd|�q�tjd|�q'tj k
r�tjd||��q'Xq'W|jj
d|�WdQXdS(s�Applies an enhancement on all domains.
:param list domains: list of ssl_vhosts (as strings)
:param str enhancement: name of enhancement, e.g.
ensure-http-header
:param str options: options to enhancement, e.g.
Strict-Transport-Security
.. note:: When more `options` are needed, make options a list.
:raises .errors.PluginError: If Enhancement is not supported, or if
there is any other problem with the enhancement.
smWe were unable to set up enhancement %s for your server, however,
we successfully installed your
certificate.sensure-http-headersEnhancement %s was already set.s#Unable
to set enhancement %s for %ssAdd enhancement
%sN(RRRR/tenhanceRtPluginEnhancementAlreadyPresentR_RctPluginErrorRm(RSR�tenhancementtoptionsRqR((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyRVs"
cCs9|jj�tjjtj�}|j||j�dS(s�Calls the
installer's recovery routine and prints success_msg
:param str success_msg: message to show on successful recovery
N( R/trecovery_routinetzopet componentt
getUtilityRt IReportertadd_messaget
HIGH_PRIORITY(RStsuccess_msgtreporter((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyRys
cCswtjd�tjjtj�}y|jj�|jj �Wn|j
d|j��nX|j
||j�dS(s�Rollback the most recent checkpoint and restart the
webserver
:param str success_msg: message to show on successful rollback
s0Rolling back to previous server configuration...s�An error
occurred and we failed to restore your config and restart your server.
Please post to https://community.letsencrypt.org/c/help with details about
your configuration and this error you received.N(R_tcriticalRRR
RR!R/trollback_checkpointsRR"R#(RSR$R%((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR�s
N(RWRXRYR$RTR�R�R�R�R�R�RR�RRRR(((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR��s&[ $ ( $+#
cCs|jr.tj|j�r.tjd��n|r|jdkr�tjjtjj |j
�}tjjtjj|�}t
j|j|d�}n|j
r�tj|j
�r�tjd��n|j
r|jrtj|j
|j�stjd��qqndS(s�Validate Key and CSR files.
Verifies that the client key and csr arguments are valid and correspond
to
one another. This does not currently check the names in the CSR due to
the inability to read SANs from CSRs in python crypto libraries.
If csr is left as None, only the key will be validated.
:param privkey: Key associated with CSR
:type privkey: :class:`certbot.util.Key`
:param .util.CSR csr: CSR
:raises .errors.Error: when validation fails
s#The provided key is not a valid keytderR�s#The provided CSR is not
a valid CSRsThe key and CSR do not
matchN(R�Rt
valid_privkeyRRdR�tOpenSSLtcryptotload_certificate_requestt
FILETYPE_ASN1R�tdump_certificate_requesttFILETYPE_PEMR R�R�t valid_csrtcsr_matches_pubkey(tprivkeyR�tcsr_objtcert_buffer((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytvalidate_key_csr�s cCsEtj|||dd�}|dk rA|j|�|j�ndS(s�Revert
configuration the specified number of checkpoints.
:param int checkpoints: Number of checkpoints to revert.
:param config: Configuration.
:type config: :class:`certbot.interfaces.IConfig`
tquestions,Which installer should be used for
rollback?N(tplugin_selectiontpick_installerR$R'R(tdefault_installertcheckpointsRtpluginsR/((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pytrollback�s
cCsmtj|�r:tj|dddd�tjj|�fStj|dd�}|dtjj|d�fS(s'Open
a pem file.
If cli_arg_path was set by the client, open that.
Otherwise, uniquify the file path.
:param str cli_arg_path: the cli arg name, e.g. cert_path
:param str pem_path: the pem file path to open
:returns: a tuple of file object and its absolute file path
tchmodi�tmodetwbii(Rt
set_by_cliR t safe_openRR�Rtunique_file(tcli_arg_pathtpem_pathtuniq((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR��s
cCs6z|j|�Wd|j�Xtjd|j�dS(s�Saves
chain_pem at a unique path based on chain_path.
:param str chain_pem: certificate chain in PEM format
:param str chain_file: chain file object
NsCert chain written to
%s(R�R�R_R`RU(R�R�((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyR��s(<RYR�tloggingR)tcryptography.hazmat.backendsRt-cryptography.hazmat.primitives.asymmetric.rsaRtjosepyRhR*tzope.componentRRsRRRR�RR�Rtacme.magic_typingRRR,RR tcertbot._internalR
RRR
RRRtcertbot._internal.pluginsRR7tcertbot.compatRtcertbot.displayRR�t getLoggerRWR_R$R
RR1tobjectRCRZRuRkR�R5R<R�R�(((s</usr/lib/python2.7/site-packages/certbot/_internal/client.pyt<module>sV G -��.