%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/cloudinit/__pycache__/gpg.cpython-312.pyc

�

���f����dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZeje�ZdZGd�d�Zy)	z0gpg.py - Collection of gpg key related functions�N)�TemporaryDirectory)�Dict�Optional)�subp�	GNUPGHOMEc���eZdZd�Zd�Zedeeeffd��Zd�Z	dd�Z
dedeefd	�Zdedefd
�Z
ddedefd�Zdded
eddfd�Zdeddfd�Z	dded
edeefd�Zdd�Zy)�GPGc�>�d|_i|_t�|_y)NF)�gpg_started�_envr�temp_dir��selfs �//usr/lib/python3/dist-packages/cloudinit/gpg.py�__init__zGPG.__init__s�� �����	�*�,��
�c��|S�N�rs r�	__enter__z
GPG.__enter__s���r�returnc��|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)rr�HOMEr
�namers r�envzGPG.env"s=���9�9��9�9������4�=�=�-�-�.��	��y�y�rc�$�|j�yr)�cleanup)r�exc_typ�	exc_value�	tracebacks    r�__exit__zGPG.__exit__1s�����rNc���|j�|jrOtjj	|jj
�r|jj
�yyy)z0cleanup the gpg temporary directory and kill gpgN)�kill_gpgr
�os�path�isdirrrrs rrzGPG.cleanup4sB���
�
���=�=�R�W�W�]�]�4�=�=�+=�+=�>��M�M�!�!�#�?�=r�keyc���	tjddd|gd|j��jS#tj$r!}tjd||�Yd}~yd}~wwxYw)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'�errors   r�
export_armourzGPG.export_armour:sg��	L��9�9��
�J��4���8�8���f�	
��
�)�)�	L��I�I�>��U�K�K���	L�s�/2�A&�A!�!A&c�`�tjddg|d|j��jS)z�Dearmor gpg key, dearmored key gets returned

        note: man gpg(1) makes no mention of an --armour spelling, only --armor
        r)z	--dearmorF)�data�decoder,)rrr.)rr's  r�dearmorzGPG.dearmorGs,��
�y�y�
�K� �s�5�T�X�X�
�
�&�	r�key_filec���gd�}|s|jd�|j|�tj||jd��\}}|rtj	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
        )r)z--no-optionsz--with-fingerprintz--no-default-keyringz--list-keysz	--keyringz
--with-colonsT)r,r+r-)�appendrrr0�warning)rr9�human_output�cmdr.�stderrs      r�	list_keysz
GPG.list_keysPs]��
����J�J��'��
�
�8�����3�4�8�8�T�J������K�K�8�(�F�
��
r�	keyserverc��tjd||�d}d}t|xsg�}	|dz
}	tjddd|zd	|gd|j�
�tjd|||�y#tj
$r}|}Yd}~nd}~wwxYw	t
|�}tjd|j|�tj|�n$#t$r}td
||||fz�|�d}~wwxYw��)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'rNT�r)z--no-ttyz--keyserver=%sz--recv-keysr*z/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)r0r1�iterrrr/�next�	exit_code�time�sleep�
StopIteration�
ValueError)	rr'rA�retries�trynumr3�sleeps�e�naplens	         r�recv_keyzGPG.recv_keyjs��	�	�	�:�C��K������g�m��$����a�K�F�
��	�	��"�(�9�4�%���!�#�x�x�
��	�	�E����	����-�-�
����
��
��f����	�	�L��O�O���
�
�
�6�"�� �
� �)�,/��F�E�+J�K�����
��?s1�AA5�5B�B�B�AC�	C;�#C6�6C;c���	tjdddd|gd|j��y#tj$r!}tj	d||�Yd}~yd}~wwxYw)	z0Delete the specified key from the local gpg ringr)z--batchz--yesz
--delete-keysTr*zFailed delete key "%s": %sN)rrr/r0r<r2s   r�
delete_keyzGPG.delete_key�sZ��	B��I�I��	�7�O�S�A���8�8�
��
�)�)�	B��K�K�4�c�5�A�A��	B�s�'*�A�A�A�keyidc��|j|�}|s9	|j||��|j|�}	|j|�|S|S#t$rtj	d|��wxYw#|j|�wxYw)zget gpg keyid from keyserver)rAzFailed to obtain gpg key %s)r4rPrJr0�	exceptionrR)rrSrA�armours    r�
getkeybyidzGPG.getkeybyid�s����#�#�E�*���	
'��
�
�e�y�
�9��+�+�E�2������&��
�v�
���
��
�
�;�U�C��
������&�s�$A�!A0�0A3�3Bc�d�	|jsytjd�r/tjgd�d|j��j}ytjgd�dddg�	�j}tjd
|�}|D�cgc]}|ddk(s�t|d���}}|rtjd|�|D]&}tj|tj��(ycc}w#tj$r }tjd
|�Yd}~yd}~wwxYw)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)rYz--kill�allTr*)	�psz-ozppid,pid�-C�keyboxdr\�dirmngrr\z	gpg-agentrrC)r+�rcsz(?P<ppid>\d+)\s+(?P<pid>\d+)�1z&Killing gpg-agent and dirmngr pids: %sz"Failed to clean up gpg process: %s)rr�whichrr.�re�findall�intr0r1r$�kill�signal�SIGKILLr/r<)r�gpg_process_out�gpg_pids�pid�
root_gpg_pids�gpg_pidrNs       rr#zGPG.kill_gpg�s��&	A��#�#���z�z�)�$�"&�)�)�0� �#�x�x�#��&�	 �#'�)�)�
�!��A��#��&� ��:�:�3�_���,4�!�$'�s�1�v��}�C��A��K�!�
�!�!��I�I�@�-�� -�5�G��G�G�G�V�^�^�4�5��!���)�)�	A��K�K�<�a�@�@��	A�s=�C<�AC<�AC<�
C7�!C7�1AC<�7C<�<D/�D*�*D/)rN)F))rCrC)zkeyserver.ubuntu.com)�__name__�
__module__�__qualname__rr�propertyr�strrr!rrr4r8r@rPrRrWr#rrrr	r	s���-�
���T�#�s�(�^�����$�����#����3��3���#��c��45�C�5�C�5�D�5�n	B�c�	B�d�	B�,B����%(��	�#���$.Arr	)�__doc__�loggingr$rbrfrG�tempfiler�typingrr�	cloudinitr�	getLoggerrmr0rr	rrr�<module>rxsG��7��	�	�
��'�!���g����!����SA�SAr

Zerion Mini Shell 1.0