HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-10-0-8-47 6.8.0-1021-aws #23~22.04.1-Ubuntu SMP Tue Dec 10 16:31:58 UTC 2024 aarch64
User: ubuntu (1000)
PHP: 8.1.2-1ubuntu2.22
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3/dist-packages/cloudinit/__pycache__/gpg.cpython-310.pyc
o

�AdH�@spdZddlZddlmZddlmZe�e�Zgd�Z	dd�Z
dd	�Zddd�Zddd�Z
dd�Zddd�ZdS)z0gpg.py - Collection of gpg key related functions�N)�log)�subp)�gpgz--with-fingerprintz--no-default-keyringz--list-keysz	--keyringc
Cs\ztjddd|gdd�\}}W|Stjy-}zt�d||�d}WYd}~|Sd}~ww)z*Export gpg key, armoured key gets returnedrz--exportz--armourT��capture�&Failed to export armoured key "%s": %sN)r�ProcessExecutionError�LOG�debug)�key�armour�_�error�r�//usr/lib/python3/dist-packages/cloudinit/gpg.py�
export_armours����rcCstjddg|dd�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�decode)r�stdout)rrrr�dearmor'srFcCsNg}|�t�|s|�d�|�|�tj|dd�\}}|r%t�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
    z
--with-colonsTrr)�extend�GPG_LIST�appendrr	�warning)�key_file�human_output�cmdr�stderrrrr�list/s


r��r c	
Cs�t�d||�ddd|d|g}|durg}d}d}t|�}	|d	7}ztj|dd
�t�d|||�WdStjyJ}z|}WYd}~nd}~wwzt|�}t�d|j|�t�|�Wnt	yu}zt
d
||||f�|�d}~wwq)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-existant 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'rz--no-ttyz--keyserver=%sz--recv-keysNrTr rz/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
�iterrr�next�	exit_code�time�sleep�
StopIteration�
ValueError)	r�	keyserver�retriesr�trynumr�sleeps�e�naplenrrr�recv_keyBsR����
������r.c
CsVztjdddd|gdd�WdStjy*}zt�d||�WYd}~dSd}~ww)	z0Delete the specified key from the local gpg ringrz--batchz--yesz
--delete-keysTrzFailed delete key "%s": %sN)rrr	r)rrrrr�
delete_keyss���r/�keyserver.ubuntu.comcCs`t|�}|s.z"zt||d�t|�}Wnty!t�d|��wWt|�|St|�w|S)zget gpg keyid from keyserver)r(zFailed to obtain gpg key %s)rr.r'r	�	exceptionr/)�keyidr(rrrr�
getkeybyid}s��
�r3)F)r)r0)�__doc__r$�	cloudinitr�loggingr�	getLogger�__name__r	rrrrr.r/r3rrrr�<module>s
	

1