AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/uaclient/entitlements/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/uaclient/entitlements/__pycache__/livepatch.cpython-310.pyc
o

F��c-5�	@s$ddlZddlZddlmZmZmZmZmZddlm	Z	m
Z
mZmZm
Z
mZmZddlmZmZddlmZddlmZddgZd	Zd
Zddd
�ZdZe
��Z	ddedeeeddfdd�Z 			d deedeedeeeddfdd�Z!dedeefdd�Z"Gdd�de�Z#dd�Z$dS)!�N)�Any�Dict�List�Optional�Tuple)�apt�event_logger�
exceptions�messages�snap�system�util)�IncompatibleService�
UAEntitlement)�ApplicationStatus)�StaticAffordanceg�?g�?z
http-proxyzhttps-proxyz)Invalid Auth-Token provided to livepatch.z2Your running kernel is not supported by Livepatch.)zUnknown Auth-Tokenzunsupported kernelz/snap/bin/canonical-livepatch�
protocol_type�retry_sleeps�returncCs,t�t�sdStjtdd�|�g|d�dS)a�
    Unset livepatch configuration settings for http and https proxies.

    :param protocol_type: String either http or https
    :param retry_sleeps: Optional list of sleep lengths to apply between
        retries. Specifying a list of [0.5, 1] tells subp to retry twice
        on failure; sleeping half a second before the first retry and 1 second
        before the second retry.
    N�configz	{}-proxy=�r)r�which�
LIVEPATCH_CMD�subp�format)rr�r�A/usr/lib/python3/dist-packages/uaclient/entitlements/livepatch.py�unconfigure_livepatch_proxy s

�r�
http_proxy�https_proxycCsb|s|rt�tjjtjd��|rtjt	dd�|�g|d�|r/tjt	dd�|�g|d�dSdS)a�
    Configure livepatch to use http and https proxies.

    :param http_proxy: http proxy to be used by livepatch. If None, it will
                       not be configured
    :param https_proxy: https proxy to be used by livepatch. If None, it will
                        not be configured
    :@param retry_sleeps: Optional list of sleep lengths to apply between
                               snap calls
    )�servicerz
http-proxy={}rzhttps-proxy={}N)
�event�infor
�SETTING_SERVICE_PROXYr�LivepatchEntitlement�titlerrr�rrrrrr�configure_livepatch_proxy4s"���
��r'�keycCs\t�tdg�\}}t�d�|�|tj�}|r|�d�nd}|r&t�dd|�}|r,|�	�SdS)z�
    Gets the config value from livepatch.
    :param protocol: can be any valid livepatch config option
    :return: the value of the livepatch config option, or None if not set
    rz
^{}: (.*)$�Nz\"(.*)\"z\g<1>)
rrr�re�searchr�	MULTILINE�group�sub�strip)r(�out�_�match�valuerrr�get_config_option_valueWsr4c	s�eZdZdZdZdZdZedee	dffdd��Z
edeedffd	d
��Zdde
de
fd
d�Z	dde
de
de
fdd�Zddd�Zdeeeejffdd�Z	ddeeefdeeefde
de
f�fdd�
Z�ZS)r$z%https://ubuntu.com/security/livepatch�	livepatch�	LivepatchzCanonical Livepatch servicer.cCs0ddlm}ddlm}t|tj�t|tj�fS)Nr��FIPSEntitlement)�RealtimeKernelEntitlement)�uaclient.entitlements.fipsr8�uaclient.entitlements.realtimer9rr
�LIVEPATCH_INVALIDATES_FIPS�REALTIME_LIVEPATCH_INCOMPATIBLE)�selfr8r9rrr�incompatible_servicesms���z*LivepatchEntitlement.incompatible_servicescsPddlm}||j�}t|��dtjk��tjdd�dftj	�fdd�dffS)Nrr7cSst��S�N)r�is_containerrrrr�<lambda>�sz9LivepatchEntitlement.static_affordances.<locals>.<lambda>Fcs�Sr@rr��is_fips_enabledrrrB�s)
r:r8�cfg�bool�application_statusr�ENABLEDr
�$LIVEPATCH_ERROR_INSTALL_ON_CONTAINER�!LIVEPATCH_ERROR_WHEN_FIPS_ENABLED)r>r8�fips_entrrCr�static_affordances|s
��
��z'LivepatchEntitlement.static_affordancesF�silentc
Cs�t�tj�sLt�d�t�tj�zt�	�Wnt
jy2}zt�
dt|��WYd}~nd}~wwztjgd�tjd�Wnt
jyKt
���wt��sYt
jtj|jd��ztjtjddd	gd
d�Wn%t
jy�}zt�dt|����r�t�tj�n�WYd}~nd}~wwt�d
|jjtj�}t�d|jj tj!�}tj"||tj#d�t�t$�s�t�d�ztjtjddgd
tj#d�Wnt
jy�}zt
j%t|�d��d}~wwt&||�|j'd
d
d�S)zYEnable specific entitlement.

        @return: True on success, False otherwise.
        zInstalling snapdz<Trying to install snapd. Ignoring apt-get update failure: %sN)zapt-get�installz--assume-yes�snapdr)�snap_cmdr �waitrzseed.loadedT��capturezunknown command .*wait�http�httpsr&z#Installing canonical-livepatch snaprNzcanonical-livepatch)rSr)�	error_msg��process_directives�
process_token)(rrr�SNAP_CMDr!r"r
�APT_UPDATING_LISTSr�run_apt_update_commandr	�UserFacingError�logging�debug�strr�APT_RETRIES�ProcessExecutionError�CannotInstallSnapdError�is_installed�SnapdNotProperlyInstalledErrorr%r*r+�lower�warning�SNAPD_DOES_NOT_HAVE_WAIT_CMDr
�validate_proxyrEr�PROXY_VALIDATION_SNAP_HTTP_URLr�PROXY_VALIDATION_SNAP_HTTPS_URL�configure_snap_proxy�SNAP_INSTALL_RETRIESr�ErrorInstallingLivepatchr'�setup_livepatch_config)r>rM�errrrr�_perform_enable�s|
���
���
�������



���
�z$LivepatchEntitlement._perform_enableTrXrYc
Cs�|jjj�|j�}|r6zt|�Wn$tjy5}zdt|�}t	�
|�t�|�WYd}~dSd}~ww|r�|�d�}|sLt�
d|j�|jjd}|��\}}|tjkr�t�
d|j�z	t�tdg�Wntjy�}zt�t|��WYd}~dSd}~wwztjtd	|gd
d�Wn:tjy�}z-d}t��D]\}	}
|	t|�vr�||
7}nq�|dkr�|t|�7}t	�
|�WYd}~dSd}~wwt	�
d
�d
S)aProcesss configuration setup for livepatch directives.

        :param process_directives: Boolean set True when directives should be
            processsed.
        :param process_token: Boolean set True when token should be
            processsed.
        zUnable to configure Livepatch: NF�
resourceTokenzHNo specific resourceToken present. Using machine token as %s credentials�machineTokenz.Disabling %s prior to re-attach with new token�disable�enableTrRzUnable to enable Livepatch: zCanonical livepatch enabled.)rE�machine_token_file�entitlements�get�name�process_config_directivesr	rbr`r!r"r^�errorr_r%�
machine_tokenrGr�DISABLEDrrr�
ERROR_MSG_MAP�items)r>rXrY�entitlement_cfgrp�msg�livepatch_tokenrG�_details�
error_message�
print_messagerrrro�sj

�

��
�
���

��
��

z+LivepatchEntitlement.setup_livepatch_configcCs$t�t�sdStjtdgdd�dS)zYDisable specific entitlement

        @return: True on success, False otherwise.
        TrtrR)rrrr)r>rMrrr�_perform_disables
z%LivepatchEntitlement._perform_disablec
Cs�tjdf}t�t�stjtjfSztjtdgt	d�W|St
jyC}zt�
dt|��tjtjdt|�d�fWYd}~Sd}~ww)N�statusrzLivepatch not enabled. %s�)ryr�)rrHrrrr}r
�LIVEPATCH_NOT_ENABLEDr�LIVEPATCH_RETRIESr	rbr^r_r`�NamedMessage)r>r�rprrrrGs

�
����z'LivepatchEntitlement.application_status�orig_access�deltas�allow_enablec
s�t��|||�r
dS|�di�}|�di��dd�}|r$|��\}}|S|��\}}|tjkr1dS|�di�}	tddg�}
t|
�	|	��}t|�d	d��}t
||g�r`t�d
|j
�|j||d�SdS)a1Process any contract access deltas for this entitlement.

        :param orig_access: Dictionary containing the original
            resourceEntitlement access details.
        :param deltas: Dictionary which contains only the changed access keys
        and values.
        :param allow_enable: Boolean set True if allowed to perform the enable
            operation. When False, a message will be logged to inform the user
            about the recommended enabled service.

        :return: True when delta operations are processed; False when noop.
        T�entitlement�obligations�enabledByDefaultF�
directives�caCerts�remoteServerrrz$Updating '%s' on changed directives.rW)�super�process_contract_deltasrxrurGrr}�setrF�intersection�anyr^r"ryro)
r>r�r�r��delta_entitlement�process_enable_default�enable_successr1rG�delta_directives�supported_deltasrXrY��	__class__rrr�1s2�
��z,LivepatchEntitlement.process_contract_deltas)F)TT)�__name__�
__module__�__qualname__�help_doc_urlryr%�description�propertyrrr?rrLrFrqror�rrr
r�rGrr`rr��
__classcell__rrr�rr$fs@E���
�
:

��
�
���r$cCs�|sdS|�di��di�}|�d�}|r"tjtdd�|�gdd�|�d	d
�}|�d�r3|dd�}|rDtjtdd
�|�gdd�dSdS)a�Process livepatch configuration directives.

    We process caCerts before remoteServer because changing remote-server
    in the canonical-livepatch CLI performs a PUT against the new server name.
    If new caCerts were required for the new remoteServer, this
    canonical-livepatch client PUT could fail on unmatched old caCerts.

    @raises: ProcessExecutionError if unable to configure livepatch.
    Nr�r�r�rzca-certs={}TrRr�r��/���zremote-server={})rxrrrr�endswith)rEr��ca_certs�
remote_serverrrrrzas*

�
�
��rzr@)NNN)%r^r*�typingrrrrr�uaclientrrr	r
rrr
�uaclient.entitlements.baserr�(uaclient.entitlements.entitlement_statusr�uaclient.typesrr��HTTP_PROXY_OPTION�HTTPS_PROXY_OPTIONr~r�get_event_loggerr!r`�floatrr'r4r$rzrrrr�<module>sN$	���
�
����
�
�#|

Anon7 - 2022
AnonSec Team