
    x[h"              
          % S r SSKrSSKrSSKJrJrJr  SSKJr  SSK	J
r
  SSKJr  SSKJr  \R                  " \5      rSSS	S
S/S.rSSSSS/S.SSSSS/S.SSSSS/S.SSSSS/S.SSSSS/S.S.rS H  r\S   \\'   M     S H  r\S   \\'   M     / SQrS\\S S!/S".r\\S#'   S$ rS% rS& rS' rS( rS) rS*\S+\
S,\S-\S.S4
S/ jr g)0zCA Certs: Add ca certificates.    N)	lifecyclesubputil)Cloud)Config)
MetaSchema)PER_INSTANCEz!/usr/local/share/ca-certificates/z#cloud-init-ca-cert-{cert_index}.crtz/etc/ca-certificates.confzupdate-ca-certificates)ca_cert_pathca_cert_local_pathca_cert_filenameca_cert_configca_cert_update_cmdz/etc/ssl/certs/z#cloud-init-ca-cert-{cert_index}.pemz+/etc/ca-certificates/conf.d/cloud-init.confzupdate-ca-bundlez/etc/pki/ca-trust/z/usr/share/pki/ca-trust-source/z+anchors/cloud-init-ca-cert-{cert_index}.crtzupdate-ca-trustz/etc/pki/trust/z/usr/share/pki/trust/z/etc/pki/tls/certs/zrehash_ca_certificates.sh)aoscfedorarhelopensusephoton)opensuse-microosopensuse-tumbleweedopensuse-leapsle_hpc	sle-microslesr   )	almalinux
cloudlinuxr   )r   r   r   alpinedebianr   r   r   r   r   r   r   r   r   ubuntur   cc_ca_certsca_certsca-certs)iddistros	frequencyactivate_by_schema_keysmetac                     [         R                  U [        5      n[        R                  R                  US   US   5      US'   U$ )zReturn a distro-specific ca_certs config dictionary

@param distro_name: String providing the distro class name.
@returns: Dict of distro configurations for ca_cert.
r   r   ca_cert_full_path)DISTRO_OVERRIDESgetDEFAULT_CONFIGospathjoin)distro_namecfgs     >/usr/lib/python3/dist-packages/cloudinit/config/cc_ca_certs.py_distro_ca_certs_configsr2   j   sF     

{N
;C!ww|| !3'9#: C J    c                 4    [         R                   " U S   SS9  g)z
Updates the CA certificate cache on the current machine.

@param distro_cfg: A hash providing _distro_ca_certs_configs function.
r   F)captureN)r   
distro_cfgs    r1   update_ca_certsr8   w   s     	IIj-.>r3   c                     U(       d  g[        US5       H7  u  p#[        U5      nU S   R                  US9n[        R                  " XTSS9  M9     g)a  
Adds certificates to the system. To actually apply the new certificates
you must also call the appropriate distro-specific utility such as
L{update_ca_certs}.

@param distro_cfg: A hash providing _distro_ca_certs_configs function.
@param certs: A list of certificate strings.
N   r(   )
cert_indexi  )mode)	enumeratestrformatr   
write_file)r7   certsr;   ccert_file_contentscert_file_names         r1   add_ca_certsrE      sV     "5!,
 V#$78??! @ 
 	G -r3   c                     U S;   a  [        U5        gU S;   a*  [        U5        U S;   a  Sn[        R                  " SUS9  ggg)a  
Disables all default trusted CA certificates. For Alpine, Debian and
Ubuntu to actually apply the changes you must also call
L{update_ca_certs}.

@param distro_name: String providing the distro class name.
@param distro_cfg: A hash providing _distro_ca_certs_configs function.
)r   r   )r   r   r   r   )r   r   z8ca-certificates ca-certificates/trust_new_crts select no)zdebconf-set-selections-)dataN)remove_default_ca_certsdisable_system_ca_certsr   )r/   r7   debconf_sels      r1   disable_default_ca_certsrL      sR     ((
+	>	>
+..O  II5KH	 / 
?r3   c                 <   U S   nU(       a$  [         R                  R                  U5      (       d  gSnSn[         R                  " U5      R                  (       a  [
        R                  " U5      n/ nUR                  5        Hm  nXb:X  a  SnUR                  U5        M  US:X  d	  US   S;   a  UR                  U5        M?  U(       d  UR                  U5        SnUR                  S	U-   5        Mo     [
        R                  " US
R                  U5      S
-   SS9  gg)z
For every entry in the CA_CERT_CONFIG file prefix the entry with a "!"
in order to disable it.

@param distro_cfg: A hash providing _distro_ca_certs_configs function.
r   Nz;# Modified by cloud-init to deselect certs due to user-dataFT r   )#!rP   
wb)omode)r,   r-   existsstatst_sizer   load_text_file
splitlinesappendr@   r.   )r7   ca_cert_cfg_fnheader_commentadded_headerorig	out_lineslines          r1   rJ   rJ      s       01N!?!? 	F  L	ww~&&"">2	OO%D%#  &tAw*4  &#$$^4#'L  t, & 	DIIi047t	
 'r3   c                     U S   c  g[         R                  S5        [        R                  " U S   5        [        R                  " U S   5        g)z
Removes all default trusted CA certificates from the system.

@param distro_cfg: A hash providing _distro_ca_certs_configs function.
r
   NzDeleting system CA certificatesr   )LOGdebugr   delete_dir_contentsr6   s    r1   rI   rI      sF     .!)II/0Z78Z(<=>r3   namer0   cloudargsreturnc                    SU;   a  [         R                  " SSSS9  OSU;  a  [        R                  SU 5        gSU;   a  SU;   a  [        R	                  S	5        UR                  SUR                  S5      5      n[        UR                  R                  5      nS
U;   a  [         R                  " SSSS9  UR                  SUR                  S
S5      5      (       a5  [        R                  S5        [        UR                  R                  U5        SU;   aH  [        R                  " US5      nU(       a*  [        R                  S[        U5      5        [        XV5        [        R                  S5        [        U5        g)aY  
Call to handle ca_cert sections in cloud-config file.

@param name: The module name "ca_cert" from cloud.cfg
@param cfg: A nested dict containing the entire cloud config contents.
@param cloud: The L{CloudInit} object in use.
@param log: Pre-initialized Python logger object to use for logging.
@param args: Any module arguments from cloud.cfg
r!   zKey 'ca-certs'z22.1zUse 'ca_certs' instead.)
deprecateddeprecated_versionextra_messager    z<Skipping module named %s, no 'ca_certs' key in configurationNzMFound both ca-certs (deprecated) and ca_certs config keys. Ignoring ca-certs.zremove-defaultszKey 'remove-defaults'zUse 'remove_defaults' instead.remove_defaultsFz'Disabling/removing default certificatestrustedzAdding %d certificateszUpdating certificates)r   	deprecatera   rb   warningr*   r2   distrord   rL   r   get_cfg_option_listlenrE   r8   )rd   r0   re   rf   ca_cert_cfgr7   trusted_certss          r1   handleru      sM    S'%3	

 
3			J	
 	SZ3."	
 ''*cggj&9:K)%,,*;*;<J K'.%:	

 ;??+<eD  			;< !2!2J? K00iHII.M0BC3 II%&Jr3   )!__doc__loggingr,   	cloudinitr   r   r   cloudinit.cloudr   cloudinit.configr   cloudinit.config.schemar   cloudinit.settingsr	   	getLogger__name__ra   r+   r)   rp   r#   r&   __annotations__r2   r8   rE   rL   rJ   rI   r>   listru    r3   r1   <module>r      s  
 %  	 + + ! # . +! ==134 */AG12 -?I01 -?I01 *5I78 ./A:;;$ LF  0
;VF  07V	(  *J7	j 
?H*I*$
N?6  6 6 6 % 6 t 6  6 r3   