shell bypass 403

Cubjrnet7 Shell


name : gpg.cpython-39.opt-1.pyc
a

'�Dg��@stdZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZe�
e�ZdZGdd�d�ZdS)	z0gpg.py - Collection of gpg key related functions�N)�TemporaryDirectory)�Dict�Optional)�subpZ	GNUPGHOMEc@s�eZdZdd�Zdd�Zeeeefd�dd��Zdd	�Z	d
d�dd�Z
eeed
�dd�Zeed
�dd�Z
d"eed�dd�Zd#eed
d�dd�Zed
d
�dd�Zd$eeeed�dd�Zd
d�d d!�Zd
S)%�GPGcCsd|_i|_t�|_dS)NF)�gpg_started�_envr�temp_dir��self�r�1/usr/lib/python3.9/site-packages/cloudinit/gpg.py�__init__szGPG.__init__cCs|S�Nrr
rrr
�	__enter__sz
GPG.__enter__)�returncCs&|jr|jSd|_t|jji|_|jS)awhen this env property gets invoked, set up our temporary
        directory, and also set gpg_started to tell the cleanup()
        method whether or not

        why put this here and not in __init__? pytest seems unhappy
        and it's not obvious how to work around it
        T)rr�HOMEr	�namer
rrr
�env"s
	zGPG.envcCs|��dSr)�cleanup)rZexc_typ�	exc_value�	tracebackrrr
�__exit__1szGPG.__exit__NcCs,|��|jr(tj�|jj�r(|j��dS)z0cleanup the gpg temporary directory and kill gpgN)�kill_gpgr	�os�path�isdirrrr
rrr
r4szGPG.cleanup)�keyrc
CsXztjddd|gd|jd�jWStjyR}zt�d||�WYd}~n
d}~00dS)z*Export gpg key, armoured key gets returned�gpgz--exportz--armourT��capture�
update_env�&Failed to export armoured key "%s": %sN)rr�stdout�ProcessExecutionError�LOG�debug�rr�errorrrr
�
export_armour:s
�
$zGPG.export_armourcCstjddg|d|jd�jS)z�Dearmor gpg key, dearmored key gets returned

        note: man gpg(1) makes no mention of an --armour spelling, only --armor
        rz	--dearmorF)�data�decoder!)rrr#)rrrrr
�dearmorGs�zGPG.dearmorF)�key_filercCsLgd�}|s|�d�|�|�tj||jdd�\}}|rHt�d||�|S)z�List keys from a keyring with fingerprints. Default to a
        stable machine parseable format.

        @param key_file: a string containing a filepath to a key
        @param human_output: return output intended for human parsing
        )rz--no-optionsz--with-fingerprintz--no-default-keyringz--list-keysz	--keyringz
--with-colonsT)r!r r")�appendrrr%�warning)rr-Zhuman_output�cmdr#�stderrrrr
�	list_keysPs

�z
GPG.list_keys��r4)r�	keyserverrc	
Cs�t�d||�d}d}t|pg�}|d7}z6tjddd|d|gd	|jd
�t�d|||�WdStjy�}z|}WYd}~n
d}~00z&t|�}t�d|j|�t�	|�Wq"t
y�}z"td
||||f�|�WYd}~q"d}~00q"dS)a�Receive gpg key from the specified keyserver.

        Retries are done by default because keyservers can be unreliable.
        Additionally, there is no way to determine the difference between
        a non-existent key and a failure.  In both cases gpg (at least 2.2.4)
        exits with status 2 and stderr: "keyserver receive failed: No data"
        It is assumed that a key provided to cloud-init exists on the keyserver
        so re-trying makes better sense than failing.

        @param key: a string key fingerprint (as passed to gpg --recv-keys).
        @param keyserver: the keyserver to request keys from.
        @param retries: an iterable of sleep lengths for retries.
        Use None to indicate no retries.z&Importing key '%s' from keyserver '%s'rNr4rz--no-ttyz--keyserver=%sz--recv-keysTrz/Imported key '%s' from keyserver '%s' on try %dz6Import failed with exit code %d, will try again in %ssz@Failed to import key '%s' from keyserver '%s' after %d tries: %s)r%r&�iterrrr$�nextZ	exit_code�time�sleep�
StopIteration�
ValueError)	rrr5ZretriesZtrynumr(Zsleeps�eZnaplenrrr
�recv_keyjsR����
���zGPG.recv_keyc
CsZz tjdddd|gd|jd�Wn4tjyT}zt�d||�WYd}~n
d}~00dS)	z0Delete the specified key from the local gpg ringrz--batchz--yesz
--delete-keysTrzFailed delete key "%s": %sN)rrr$r%r/r'rrr
�
delete_key�s�
zGPG.delete_key�keyserver.ubuntu.com)�keyidr5rc	Csl|�|�}|shzLz|j||d�|�|�}Wn tyLt�d|��Yn0W|�|�n|�|�0|S)zget gpg keyid from keyserver)r5zFailed to obtain gpg key %s)r)r=r;r%�	exceptionr>)rr@r5Zarmourrrr
�
getkeybyid�s

zGPG.getkeybyidc
Cs�z�|jsWdSt�d�r2tjgd�d|jd�j}n\tjgd�dddgd	�j}t�d
|�}dd�|D�}|rvt�d
|�|D]}t	�
|tj�qzWn2tj
y�}zt�d|�WYd}~n
d}~00dS)akilling with gpgconf is best practice, but when it isn't available
        failover is possible

        GH: 4344 - stop gpg-agent/dirmgr daemons spawned by gpg
        key imports. Daemons spawned by cloud-config.service on systemd
        v253 report (running)
        N�gpgconf)rCz--kill�allTr)	Zpsz-ozppid,pid�-CZkeyboxdrEZdirmngrrEz	gpg-agentrr4)r Zrcsz(?P<ppid>\d+)\s+(?P<pid>\d+)cSs$g|]}|ddkrt|d��qS)r�1r4)�int)�.0�pidrrr
�
<listcomp>�sz GPG.kill_gpg.<locals>.<listcomp>z&Killing gpg-agent and dirmngr pids: %sz"Failed to clean up gpg process: %s)rr�whichrr#�re�findallr%r&r�kill�signal�SIGKILLr$r/)rZgpg_process_outZgpg_pidsZ
root_gpg_pidsZgpg_pidr<rrr
r�s8
�
����zGPG.kill_gpg)F)r3)r?)�__name__�
__module__�__qualname__rr�propertyr�strrrrrr)r,r2r=r>rBrrrrr
rs"
	7��r)�__doc__ZloggingrrLrOr8Ztempfiler�typingrrZ	cloudinitrZ	getLoggerrQr%rrrrrr
�<module>s


© 2025 Cubjrnet7