HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/cloudinit/config/__pycache__/cc_ca_certs.cpython-38.pyc
U

Ӈg�"�@s�UdZddlZddlZddlmZmZmZddlmZddl	m
Z
ddlmZddl
mZe�e�Zddd	d
dgd�Zd
d
dddgd�dddddgd�dddddgd�dddddgd�dd
dddgd�d�ZdD]Zedee<q�dD]Zedee<q�ddd d!d"d#ddd$d%d&d'd(d)d*d+gZd,eed-d.gd/�Zeed0<d1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Zee
eedd=�d>d?�Z dS)@zCA 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.confzupdate-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.confzupdate-ca-bundlez/etc/pki/ca-trust/z/usr/share/pki/ca-trust-source/z+anchors/cloud-init-ca-cert-{cert_index}.crtzupdate-ca-trustz/etc/pki/trust/z/usr/share/pki/trust/z/etc/pki/tls/certs/zrehash_ca_certificates.sh)�aosc�fedora�rhel�opensuse�photon)�opensuse-microos�opensuse-tumbleweed�
opensuse-leap�sle_hpc�	sle-micro�slesr)�	almalinux�
cloudlinuxrrrr�alpine�debianrrrrrrr�ubunturZcc_ca_certs�ca_certs�ca-certs)�id�distrosZ	frequencyZactivate_by_schema_keys�metacCs*t�|t�}tj�|d|d�|d<|S)z�Return 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�cfg�r,�>/usr/lib/python3/dist-packages/cloudinit/config/cc_ca_certs.py�_distro_ca_certs_configsjs�r.cCstj|ddd�dS)z�
    Updates the CA certificate cache on the current machine.

    @param distro_cfg: A hash providing _distro_ca_certs_configs function.
    r
F)ZcaptureN)r��
distro_cfgr,r,r-�update_ca_certswsr1cCsH|sdSt|d�D]0\}}t|�}|dj|d�}tj||dd�qdS)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)r0Zcertsr3�cZcert_file_contentsZcert_file_namer,r,r-�add_ca_certs�s	�r:cCs@|dkrt|�n*|dkr<t|�|dkr<d}tjd|d�dS)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.
    )rr)rrrr)rrz8ca-certificates ca-certificates/trust_new_crts select no)zdebconf-set-selections�-)�dataN)�remove_default_ca_certs�disable_system_ca_certsr)r*r0Zdebconf_selr,r,r-�disable_default_ca_certs�s	
�r?cCs�|d}|rtj�|�sdSd}d}t�|�jr�t�|�}g}|��D]\}||krbd}|�|�qF|dksv|ddkr�|�|�qF|s�|�|�d}|�d	|�qFtj	|d
�
|�d
dd�dS)
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)�#�!rB�
�wb)Zomode)r'r(�exists�stat�st_sizerZload_text_file�
splitlines�appendr8r))r0Zca_cert_cfg_fnZheader_commentZadded_headerZorigZ	out_lines�liner,r,r-r>�s0�

�r>cCs:|ddkrdSt�d�t�|d�t�|d�dS)z�
    Removes all default trusted CA certificates from the system.

    @param distro_cfg: A hash providing _distro_ca_certs_configs function.
    r	NzDeleting system CA certificatesr
)�LOG�debugrZdelete_dir_contentsr/r,r,r-r=�s

r=)�namer+�cloud�args�returncCs�d|krtjdddd�nd|kr2t�d|�dSd|krLd|krLt�d	�|�d|�d��}t|jj�}d
|kr�tjdddd�|�d
|�d
d��r�t�d�t	|jj|�d|kr�t
�|d�}|r�t�dt|��t
||�t�d�t|�dS)au
    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
    rzKey 'ca-certs'z22.1zUse 'ca_certs' instead.)Z
deprecatedZdeprecated_versionZ
extra_messagerz<Skipping module named %s, no 'ca_certs' key in configurationNzMFound both ca-certs (deprecated) and ca_certs config keys. Ignoring ca-certs.zremove-defaultszKey 'remove-defaults'zUse 'remove_defaults' instead.Zremove_defaultsFz'Disabling/removing default certificatesZtrustedzAdding %d certificateszUpdating certificates)rZ	deprecaterKrLZwarningr%r.�distrorMr?rZget_cfg_option_list�lenr:r1)rMr+rNrOZca_cert_cfgr0Z
trusted_certsr,r,r-�handle�sJ
����
�


rS)!�__doc__Zloggingr'Z	cloudinitrrrZcloudinit.cloudrZcloudinit.configrZcloudinit.config.schemarZcloudinit.settingsrZ	getLogger�__name__rKr&r$rQr!r"�__annotations__r.r1r:r?r>r=r6�listrSr,r,r,r-�<module>s�
�	������&��
	'