Your IP : 216.73.216.31


Current Path : /lib/python3/dist-packages/cloudinit/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/cloudinit/__pycache__/gpg.cpython-38.pyc

U

�AdH�@svdZddlZddlmZddlmZe�e�Zddddd	gZ	d
d�Z
dd
�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
CsZztjddd|gdd�\}}Wn6tjk
rT}zt�d||�d}W5d}~XYnX|S)z*Export gpg key, armoured key gets returnedrz--exportz--armourT�Zcapture�&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)r
rrr�dearmor'srFcCsNg}|�t�|s|�d�|�|�tj|dd�\}}|rJt�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)Zkey_fileZhuman_output�cmdr�stderrrrr�list/s


r��rc	
Cs�t�d||�ddd|d|g}|dkr,g}d}d}t|�}|d7}z$tj|d	d
�t�d|||�WdStjk
r�}z|}W5d}~XYnXz&t|�}t�d|j|�t�|�Wq<t	k
r�}zt
d
||||f�|�W5d}~XYq<Xq<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-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-keysNrrTrz/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)rr	�iterrr�nextZ	exit_code�time�sleep�
StopIteration�
ValueError)	r
�	keyserverZretriesrZtrynumr
Zsleeps�eZnaplenrrr�recv_keyBsF��
���r&c
CsTztjdddd|gdd�Wn2tjk
rN}zt�d||�W5d}~XYnXdS)	z0Delete the specified key from the local gpg ringrz--batchz--yesz
--delete-keysTrzFailed delete key "%s": %sN)rrrr)r
r
rrr�
delete_keyss�
r'�keyserver.ubuntu.comcCs\t|�}|sXz@zt||d�t|�}Wn"tk
rHt�d|��YnXW5t|�X|S)zget gpg keyid from keyserver)r$zFailed to obtain gpg key %s)rr'r&r#rZ	exception)Zkeyidr$rrrr�
getkeybyid}s
r))F)r)r()�__doc__r Z	cloudinitrZloggingrZ	getLogger�__name__rrrrrr&r'r)rrrr�<module>s 
�	


1